My program was skipping only empty lines, and I was getting WA7. When I started skipping lines consisting only of spaces, I got AC. goto if if: print 123 not bad Edited by author 17.07.2021 18:23 try this test: label: a = 1 goto label I had WA4 because of this: AnD <=> and, NOt <=> not, etc. I had WA9 because of this: empty strings (only spaces) - this is not a command)) I had TLE 13 because of this: we should ignore as a command lines has only a label) Cool problem)) Good Luck) Edited by author 07.04.2008 12:41 Well, now you don't have AC :) I can also add that you should do some pre calculations to get access to the variables' values and labels' positions with constant time. Logarithmic complexity isn't enough to pass TL. >Well, now you don't have AC :) Test 14 was added by me recently, which is why~ The only hint i can give for it is that the code prevented TL #13, but did it in not exactly a proper way. Took some time to rewrite that crap and retake AC :) Still don't know what was wrong in TL 14 of the previous solution though. A nice task for implementation, but the description is quite tricky sometimes. What if Program Counter went out of last instruction? - it is ok, you can think about it as normal termination by END command Is NOP count towards overall operations count? - no, empty lines and only-label lines do not contribute to the overall number of executed commands Are labels case sensitive? - no Are operands case sensitive? - no Are variable names case sensitive? - yes What about int32 overflow? - guaranteed that there are no overflows What about % operation? - the result of A % B operation is such C that 0 <= C < B and exist some integer Q: A = Q * B + C What if 10_000_000th command is END command? - The end command terminates the program Can variable name start from digit? - no there is a line which isn't token "end" and has no ':' character and there is only one nonempty token.. I use OLE test it must be wrong test... it is not include in the description so admin please fix problem description or delete this test problem description is incorrect there are far more than 2000 lines, and one token is far more than 50 characters.... I set condition to terminate program: while (!halt) { //bla bla bla executed++;
if (executed > MAX_EXECUTED) terminate_program(); } to while (executed < MAX_EXECUTED && !halt) { //bla bla bla executed++; } if (executed >= MAX_EXECUTED && !halt) terminate_program(); It helps me and I got AC :) Edited by author 16.07.2016 19:03 Edited by author 16.07.2016 19:04 Edited by author 16.07.2016 19:05 . Edited by author 13.06.2016 15:16 Hi I have OLE on #4 test Please, give me some test P.S. Sorry for my english :( i also had tried forward and backward labels, i think my program work correct I had OLE #4, and it turned out to be a minor slip in my code. That is, for commands of type «if smth1 <operator> smth2 goto label, i was searching smth1 and smth2 indices in my variable indices array; label i should have searched in my goto indices array, but i accidentally was searching a label index in variable array too; as a result, it returned 0 (which it returned in case if the needed element was the first one, and if the element wasn't found, which shouldn't be happening). So it jumped to the first label and continued from there. Example: label1: A = 10 print 100 label2: goto label2 Due to a mistake, "label2" has been looked for in variables array, which only had "A" in there. It was not found, it returned 0, it jumped to label1, tons of print commands were executed. After mistake is fixed, "label2" is looked for inside labels array, and correctly returns 1. I can't say for sure you have the very same mistake, but still it is likely just a minor slip like this one. Change while (getline(cin, s)) { //... } to while (getline(cin, s)) { if (s == "") continue; //... } Test case: goto Main END: end MAIN: print 1 if 1 == 2 goto end print 2 if 1 == 2 goto end Edited by author 22.05.2016 14:25 What was pretty interesting problem. Ty Edited by author 26.03.2016 17:18 If you have problems with test 10, ensure that you determine command type correctly. For instance: ifi = 10 printer = 20 gotoend = ifi + printer print gotoend Tokenization with finite state machine Edited by author 26.03.2016 17:19 input x= 5 print x In 1st line('x = 5') delete one space Test 5: you should output the list of _initialized_to_this_moment_ variables and their values Pheeew, finally AC! After WA #3, which had a test like print 5 end , i added 4 lines to fix that, and immediately got WA5. Thanks to Fyodor, i immediately understood what i missed, in case like a = 1 goto x b = 2 x: goto x i initially printed Program terminated. Variables state: a: 1 b: 0 So, i fixed that too, and only printed out a: 1, but still was having WA5! Curiously enough, after a fix, which i didn't think would help, i finally got AC. In my program, i had this chunk of code: writeln('Program terminated. Variables state:'); { for i:=1 to vsz do if initialized[i] = 1 then writeln(vnames[i], ': ', vars[i]); } for i:=1 to vsz do begin val(vnames[i], j, xcode); if xcode <> 0 then begin if initialized[i] = 1 then writeln(vnames[i], ': ', vars[i]); end; end; The thing is, i threw everything into variable array, both constants and variables, like if i met A = 4 + -3, i throw A, 4, -3 into that array. Then, i go through every variable "name" and use standard val procedure to attempt to convert string into integer. "A" isn't a number, so it remains 0 initially, but "4" and "-3" successfully convert into numbers, so i give them values of 4 and -3 initially. But if i write in my program 4 = 100, then later on something like "A = A + 4" would actually add 100 to A. Soooo... Using that lower uncommented chunk, i go through variable names again, and convert them into numbers, to see, if they're supposed to be constants. If they are, i ignore them, and if they aren't, i check if they're initialized, and if they are, i print them. That gave me WA5. Test like 4 = 5 x: goto x would give Program terminated. Variables state: Then, i commented that lower chunk, and uncommented the upper chunk, so that no matter if "variable"'s name can be converted to number or not, i print it out anyway if it's initialized. So for test like 4 = 5 x: goto x it now gives Program terminated. Variables state: 4: 5 And that fix got me AC! Either stuff like 4 = 5 is present in 5th test, or i'm missing anything else... Well, that was fun to discover, haha~ I also implemented support for variable names equal to keywords, so things like "not = not not" or "not: not = not or not" or "print: print print" would be parsed adequately, but seems it wasn't really needed. P. S. In the end, it turned out that the Val function converts not only decimal, but also hexadecimal numbers, which is why i encountered this problem. Edited by author 22.10.2015 15:12 I wa on it After hours and hours of struggle, i finally found out that test 3 is as simple as something like print 5 end No variables, no operations, just printing a number. Also, it was actually runtime error (out of bounds) for me, it's a sad thing it gave me WA instead... Edited by author 16.10.2015 06:43 Why? My code works correctly when it is no "end" in the end and with != Can variables have names "or", "and", "xor", "not", "print", "if", "goto", "end"? I've changed input reading method from "read line by line" to "read word by word", and got AC because of it. Which seems strange. Probably, test 9 is incorrect. Check your div and mod operations. int div(int a, int b) { return a / b; } int mod(int a, int b) { int r = a % b; if (r < 0) r += abs(b); return r; } The first test where token != used. And the first test where the program flow ends not by 'end' command. Like here: a = 1 <no end command here> My program works perfectly on any of my tests, on any tests from this task's discussion, even if there is no 'end' command and if there is "!=" token, but i got WA#6. Is in this test anything unusual or wrong? Should I, for example, add an 'end' command, as Ludovic did? http://acm.timus.ru/forum/thread.aspx?id=13124&upd=632835406669279530 And about limit of commands of 10_000_000 : "The if ... goto command works just as the goto command if the condition after if is true". Should I count an "if..goto" command, if condition was wrong? I just have no ideas, what can be wrong in my algo. Sorry for my bad English. any hint please ? I was also stunned by this test, now I have AC. i = 0 j = 0 loop1: loop2: j = j + 1 if j < i goto loop2 j = 0 i = i + 1 if i < 100 goto loop1 (Consecutive labels) Good luck. Edited by author 12.08.2006 12:28 I think that your program incorrectly interprets input program. For example, there are cycle in which there are print operation and your program incorrectly works with this cycle. Maybe your program enters in infinite cycle in that case. (The cycle is 'label' and 'goto label') I advise you examine work with labels. check for backward and forward links x = 1 goto lab x = 10 lab: x = x + 1 if x < 3 goto lab print x Why Value and ValueA is 3 ? Remainder of -2499999 divided by 6 or -6 is -3 in both cases! -2499999 / 6 = -416666 -2499999 - (-416666 * 6) = -3 and same for -6. Please correct tests or describe in task the way to find quotient and remainder of division Edited by author 11.09.2010 03:13 Got AC using this: Rem := A mod B; if Rem < 0 then Inc(Rem, Abs(B)); But I still thinking this is not correct, because A = -123456 B = 321 D = A / B R = A % B X = D * B X = X + R print A print X this both should be the same |
|