Common BoardTime limit in "Strange Dialog" Total length of all strings is no more then 10^7 characters. Simple programm reads such file 4-6 seconds!!! Time limit 2 seconds! Re: Time limit in > > Simple programm reads such file 4-6 seconds!!! > Time limit 2 seconds! > Judge system doesn't count time of reading or writing. Re: Time limit in > Total length of all strings is no more then 10^7 characters. > > Simple programm reads such file 4-6 seconds!!! > Time limit 2 seconds! > You are absolutely wrong, modern hard disks read 30-40 megs per second! Just use the following schema, like I did: #define BUFSZ 16384 int pos=BUFSZ; char buf[BUFSZ]; void getnextchar(char&c) { if(pos==BUFSZ) { pos=0; for(int i=0;i<BUFSZ;++i) buf[i]='\n'; fread(buf,BUFSZ,1,stdin); } c=buf[pos++]; } Time limit > Judge system doesn't count time of reading or writing. Really? Hm.. :) I wonder how i can find out the time my program works, if i'm reading and processing data in series? I also got Time Limit, though algorithm is surely a primitive o(n)! Even when i make a buffer of 255 bytes. I think the bad thing is: this program is made for being solved on C, not on Pascal. Because you can make the buffer of any length on C and work with stdin as with any binary file, that means read the amount of bytes you want. But in Pascal and OP, Input is a TEXT FILE!!! And you can't read more, than 255 bytes at a time. How could some people wrote it on Pascal and have it accepted, i wonder? Hey, guys! How did you read the input???? And another thing i do not like here is: time limits are counted in non-standart manner. Common ACM rules say all problems are judged on 386-586, so people can freely evaluate the estimate work time, even if they write programs on different machines (it is so, usually!). So, it would be good, if somebody would show us some information about the judge system. I mean the work-time of empty cycle from 1 to 10^6, work-time of reading 10^6 bytes, etc. Because there were some problems, that i hadn't submitted, because they hadn't met the desired time on my machine. And i lost too much time invain, trying to improve the algorithm, but finally got "accepted" without any hope to! the template for 1102 - any comments? Var ... k,i:integer; Buf:string[255]; Buflen:integer; BEGIN Readln(n); ... for i:=1 to n do begin ... k:=0; read(buf); buflen:=length(buf); if buf='' then begin Writeln('YES'); continue; end; repeat inc(k); .... {here i process one char buf[k] in CONSTANT time!!!} .... if k=buflen then begin read(buf); buflen:=length(buf); k:=0; end; until (buf=''); ... while buf<>'' do read(buf); readln; end END. So, i process data in series of 255 bytes - and still, it works too slow... :( The reading is too slow! Re: the template for 1102 - any comments? var BUF : array [1..buf_size] of char; buft, bufp : longint; tmp : word; fin : file; procedure getchar(var c : char); begin if bufp > buft then begin bufp := 1; {$IFDEF BP} blockread(fin, BUF, buf_size, tmp); buft := tmp; {$ELSE} blockread(fin, BUF, buf_size, buft); {$ENDIF} if buft = 0 then begin c := #10; exit; end; end; c := BUF[bufp]; inc(bufp); if c = #13 then getchar(c); end; It seems that blockread is fast enough. Btw I think the bigest speedup comes when you skip the chars till the end of the line when you are sure the dialog is incorrect. Also if you are using blockread you would have to read n char by char (parse it), and note that delphi insists that the variable where it returns the chars read is longint, while BP7.0 wants it to be word(i got some compile errors that way). Re: the template for 1102 - any comments? Yeah, thanks for help, but i knew quite well, that it would be fast with blockread, but the problem is: we do not read from the file, we read from INPUT. "BlockRead(f,.." doesn't work with INPUT, because the type of INPUT is TEXT. Perhaps i just do not know something, but what do you do to assign your FIN:FILE to INPUT? I would appreciate that part of help Re: the template for 1102 - any comments? Don't you know that the file name '' refers to standard input or output? So just do this : var fin : file; begin assign(fin, ''); reset(fin, 1) {1 is important for blockread} ............. ............. close(fin); end. You may use the same technique to write to stdout with blockwrite (if you reset '' means stdin if you rewrite it means stdout). Re: the template for 1102 - any comments? WWWWHHHHAAAATTTT???????? I THOUGHT AS MUCH!! Thanks, now everything's clear - i'll do it in an hour... Thanks thanks and thakns again. I do think now, that every problem has simple, fast and right solution... :))))) Re: Time limit > > Judge system doesn't count time of reading or writing. > > Really? Yes. The judge counts only so called "User Time" on NT system. This make it less dependent on harddisk speed. > Hm.. :) > I wonder how i can find out the time my program works, if > i'm reading and processing data in series? > I also got Time Limit, though algorithm is surely a > primitive o(n)! Even when i make a buffer of 255 bytes. Let's count. Input size is 10^7. It contains 1000 lines. So, there is line with at least 10^7/1000 = 10000 characters. May be longer. Why are you using any buffers?
> I think the bad thing is: this program is made for being > solved on C, not on Pascal. Author of this problem understands difference between C and Pascal. All problems are solvable on any language. > And another thing i do not like here is: time limits are > counted in non-standart manner. Common ACM rules say all > problems are judged on 386-586, so people can freely > evaluate the estimate work time, even if they write > programs on different machines (it is so, usually!). > > So, it would be good, if somebody would show us some > information about the judge system. I mean the work-time of > empty cycle from 1 to 10^6, work-time of reading 10^6 > bytes, etc. Thank you. You say wise things. We'll work on it. > Because there were some problems, that i hadn't submitted, > because they hadn't met the desired time on my machine. It's hard enough to predict worktime on our judge, because of my first answer. You should try. |