ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Общий форум

Problem 1061 : not a tricky problem , I have tested it very carefully , but couldn't find the test that I was wrong !
Послано Nguyen Viet Bang 29 май 2002 08:38
  Please help me to find the test that I was wrong with it !!!
My source :
  CONST
     INP                =               '1061.inp';
     OUT                =               '1061.out';
     maxn               =               100001 ;

VAR
  min,n,k,sum,save,pfirst,count              :       longint ;
  num                                    :       array[0..maxn] of
char;



PROCEDURE               readinput;
  var
    i           :       longint ;
  begin
{    assign (input,inp);
    reset(input);}
    readln(n,k) ;
    for i:=1 to n do
      begin
        repeat
          read(num[i]) ;
        until num[i] in ['0'..'9','*'] ;
      end ;
{    close(input) ;}
  end;

PROCEDURE               check ;
  begin
    if count = 0 then
      begin
        if sum < min then
          begin
            min:=sum ;
            save:=pfirst ;
          end ;
      end;
  end;

PROCEDURE               recalc ( p :longint ) ;
  var
    i           :       longint ;
  begin
    sum := 0 ;
    for i:=1 to k do
      begin
        sum:=sum + ord(num[pfirst+i-1]) - 48 ;
      end ;
  end ;

PROCEDURE               initial ;
  var
    i           :       longint ;
  begin
    count:=0 ; sum:=0 ; min:=maxlongint; save:=0 ;
    for i:=1 to k do
      begin
        if num[i] = '*' then inc(count) ;
      end ;
    pfirst:=1 ;
    if count = 0 then recalc ( 1) ;
    check ;
  end ;

PROCEDURE               update ;
  var
    lcount       :       longint ;
  begin
    lcount:=count;
    if num[pfirst]='*' then dec(count) ;
    if num[pfirst+k] = '*' then inc(count) ;
    inc(pfirst) ;
    if (lcount > 0) and (count = 0) then
      begin recalc ( pfirst) ;
            check ;
            exit ;
      end ;
    if count = 0 then
      begin
        sum:=sum-ord(num[pfirst-1]) + ord(num[pfirst+k-1]);
        check ;
      end ;
  end ;

PROCEDURE               implement ;
  var
    i           :       longint ;
  begin
    initial ;
    for i:=1 to n-k do
      begin
        update ;
        check ;
      end ;
  end ;

PROCEDURE               writeoutput ;
  begin
{    assign( output,out);
    rewrite (output);}
    writeln(save) ;
{    close (output);}
  end;

PROCEDURE               test ;
  var
    e,i,d         :       longint ;
  begin
    randomize;
    n:=50000; k:=1000;
    assign (output,inp) ;
    rewrite (output) ;
    writeln(n,' ',k) ;
    for i:=1 to n do
      begin
        d:=random ( 10); e:=random(100) ;
        if e = 0 then writeln('*')
        else writeln(d) ;
      end ;
    close(output) ;
  end ;

BEGIN
{  test ;}
  readinput ;
  implement ;
  writeoutput ;
END.
:)Sorry I can only Give you a test
Послано ECUST Multistar 29 май 2002 08:51
First of all
I'll say sorry that you program was quite diffent of mine.
So I can't tell you where is your error.
But I find you program was error in this case

If there is a buffer longer than k.
You can't find the right answer.

For this case

10 4
1234023923

Your program give a answer of

2

???Do you think there is a buffer which value is 2??????

Good luck..
Hope you'll get AC soon .
Thanks for your care ! But your comment is wrong .
Послано Nguyen Viet Bang 30 май 2002 08:50
  Thanks , but your comment is wrong . Please read the problem
carefully , we must output the starter of the buffer , not the sum
value . So I passed your test .
  Finally I got AC . I failed when k > n (!!!!)