Could anyone tell me please what could cause TLE error in "ESAb ATAd" 
problem? If we talk about regular problem of having a slow algorithm, this 
couldn't be the thing because my program takes *O(T * B)* which is *O(10^4)* 
on the hidden test set. Though the code doesn't pass neither Visible test 
set 1 nor the testing tool.
It works just fine on my computer so it makes me think the problem is with 
output buffer. But there is "*fflush(stdout);*" line after each "*prinf*" 
so I don't really understand what's the deal.
Also I used "*prinf/scanf*" to work faster with *I/O* but I also sent the 
same code with "cin/cout" and it didn't pass the tests too.

Here's my code:
#include <stdio.h>
int main() {
    short int T, B;
    char s[101], verd = 'Y';
    scanf("%hi%hi", &T, &B);
    for (short int t = 1; t <= T && verd == 'Y'; t++) {
        scanf("\n%s", s);
        bool comBoth_same = 0, comRev_dif = 0;
        short int iDif = -1, iSame = -1,
                  aDif, aSame;
        for (short int i = 0; (i < (B >> 1)) && (iDif == -1 || iSame == 
-1); i++) {
            if (s[i] == s[B - 1 - i] && iSame == -1) iSame = i;
            if (s[i] != s[B - 1 - i] && iDif == -1) iDif = i;
        }
        if (iSame != -1) {
            printf("%hi\n", 1 + iSame);
            fflush(stdout);
            scanf("%hi", &aSame);
            comBoth_same = (aSame != s[iSame] - '0');
        }
        if (iDif != -1) {
            printf("%hi\n", 1 + iDif);
            fflush(stdout);
            scanf("%hi", &aDif);
            comRev_dif = (aDif != s[iDif] - '0');
        }

        if (comBoth_same && comRev_dif) {
            for (short int i = 0; i < B; i++) {
                printf(s[i] == '1' ? "0" : "1");
            }
            printf("\n");
            fflush(stdout);
        }
        else if (comBoth_same && !comRev_dif) {
            for (short int i = B - 1; i >= 0; i--) {
                printf(s[i] == '1' ? "0" : "1");
            }
            printf("\n");
            fflush(stdout);
        }
        else if (!comBoth_same && comRev_dif) {
            for (short int i = B - 1; i >= 0; i--) {
                printf("%c", s[i]);
            }
            printf("\n");
            fflush(stdout);
        }
        else {
            printf("%s", s);
            printf("\n");
            fflush(stdout);
        }
        scanf("\n%c", &verd);
    }
    return 0;
}

Thanks in advance!

-- 
You received this message because you are subscribed to the Google Groups 
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/de7f3f6e-1094-4c3e-9db8-662fca5cdc38%40googlegroups.com.

Reply via email to