Codeforces Round #390 (Div. 2), problem: (B) Ilya and tic-tac-toe game Solution in C/C++

#include<stdio.h> #include<stdlib.h> typedef unsigned u; char S[4][4];u x,o; void chk(u r,u c,u dr,u dc,u s,u l) { if(!(dr|dc))dr=-(dc=1); if(r>3||c>3){x=o=0;return;} if(l)x=o=0; if(S[r][c]=='x')++x; if(S[r][c]=='o')++o; if(s)chk(r+dr,c+dc,dr,dc,s-1,0); return; } int main() { u i,j,k; scanf("%s%s%s%s",S[0],S[1],S[2],S[3]); for(i=-1;++i<4;)for(j=-1;++j<4;)for(k=-1;++k<4;) { chk(i,j,k>>1,k&1,2,1); if(x==2&&o==0){printf("YES\n");return 0;} } printf("NO\n"); return 0; }