TICTACTO - Editorial

This is the same pattern of this binary search problem.

It’s because this block:

 if (zz == 1)
        {
            continue;
        }

prevents you reading the rest of the testcase input when you think you know the answer, so it gets left in the stdin buffer, so the next testcase is read in incorrectly.

Just move it down to just after the cin>>t1>>t2; line.

1 Like

Thanks for pointing out the error. :slight_smile:

1 Like

thanks for considering the subtask and giving the solution for that also

i wrote the exact same code for second subtask but still getting TLE on second subtask
help

Why my solution is giving TLE . I have done the same thing
https://www.codechef.com/viewsolution/48385136

Their loss :slightly_smiling_face:

Consider the test input:

2
3 4 2
1 1
3 1
1 2
2 3
2 1
2 4
3 2
3 4
1 3
3 3
2 2
1 4
3 4 2
1 1
3 1
1 2
2 3
2 1
2 4
3 2
3 4
1 3
3 3
2 2
1 4
1 Like

Great Editorial. I must say, CC’s Editorails are better than CF’s in some rated contests.
Kudos !!!

1 Like

what is its output

It’s just the sample input from the Problem Statement, repeated, so:

Bob
Bob

and what should be the correct output for this

Alice
Win at turn # 33 for: Alice: 
 B B A A A A B 
 B B A A A B A 
 B B A[A]A B B 
 B A B B A B . 
 . A B A B A A 

can someone explain why I am getting runtime error.

Oh sorry

https://www.codechef.com/viewsolution/50157148

Please check it.

No problem; thanks!

Edit:

Out-of-bounds access on the sample test input:

[simon@simon-laptop][17:59:46]
[~/devel/hackerrank/otherpeoples]>./compile-latest-cpp.sh 
Compiling maxistein-TICTACTO.cpp
+ g++ -std=c++14 maxistein-TICTACTO.cpp -O3 -g3 -Wall -Wextra -Wconversion -DONLINE_JUDGE -D_GLIBCXX_DEBUG -fsanitize=undefined -ftrapv -fno-sanitize-recover
maxistein-TICTACTO.cpp: In function ‘Triplet gcdExtended(long long int, long long int)’:
maxistein-TICTACTO.cpp:33:36: warning: conversion to ‘__gnu_cxx::__enable_if<true, double>::__type {aka double}’ from ‘long long int’ may alter its value [-Wconversion]
     myans.y=ans.x - floor(a/b)*ans.y;
                                ~~~~^
maxistein-TICTACTO.cpp:33:17: warning: conversion to ‘__gnu_cxx::__enable_if<true, double>::__type {aka double}’ from ‘long long int’ may alter its value [-Wconversion]
     myans.y=ans.x - floor(a/b)*ans.y;
             ~~~~^
maxistein-TICTACTO.cpp:33:19: warning: conversion to ‘long long int’ from ‘__gnu_cxx::__enable_if<true, double>::__type {aka double}’ may alter its value [-Wfloat-conversion]
     myans.y=ans.x - floor(a/b)*ans.y;
             ~~~~~~^~~~~~~~~~~~~~~~~~
maxistein-TICTACTO.cpp: In function ‘int gcd(long long int, long long int)’:
maxistein-TICTACTO.cpp:38:12: warning: conversion to ‘int’ from ‘long long int’ may alter its value [-Wconversion]
     return a;
            ^
+ set +x
Successful
[simon@simon-laptop][17:59:51]
[~/devel/hackerrank/otherpeoples]>echo "1                                                       
3 4 2
1 1
3 1
1 2
2 3
2 1
2 4
3 2
3 4
1 3
3 3
2 2
1 4" | ./a.out
maxistein-TICTACTO.cpp:81:46: runtime error: index 4 out of bounds for type 'int [*]'

Edit2:

Also, potentially, this:

int temp[n+1][n+1];

See e.g. c - Getting a stack overflow exception when declaring a large array - Stack Overflow

(but I’d fix the out-of-bounds access and re-submit before changing this bit - it might be a non-issue).

1 Like

Oh, thank you so much !!!

1 Like

Explained 2d prefix sum & 3d prefix sum