1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
| #include <stdio.h> #include <stdlib.h> short N, K, sangsung[10][10], uses[10], wincount[3], kroutine[20], kcount, mroutine[20], mcount; void game(int player){ if(wincount[0]==K) {printf("1"); exit(0);} if(wincount[1]==K||wincount[2]==K) return; if(player==3){ for(int i = 1; i <= 9; ++i){ if(uses[i]) continue; uses[i] = 1; if(sangsung[i][kroutine[kcount]]==2){ ++wincount[0]; ++kcount; game(5); --wincount[0]; --kcount; } else{ ++wincount[1]; ++kcount; game(6); --kcount; --wincount[1]; } uses[i] = 0; } } if(player==5){ for(int i = 1; i <= 9; ++i){ if(uses[i]) continue; uses[i] = 1; if(sangsung[i][mroutine[mcount]]==2){ ++wincount[0]; ++mcount; game(3); --wincount[0]; --mcount; } else{ ++wincount[2]; ++mcount; game(6); --mcount; --wincount[2]; } uses[i] = 0; } } if(player==6){ if(sangsung[kroutine[kcount]][mroutine[mcount]]==2){ ++wincount[1]; ++kcount; ++mcount; game(3); --wincount[1]; --mcount; --kcount; } else{ ++wincount[2]; ++kcount; ++mcount; game(5); --wincount[2]; --kcount; --mcount; } } } int main(){ scanf("%d %d",&N, &K); for(int i = 1; i <= N; ++i) for(int j = 1; j <= N; ++j) scanf("%d",&sangsung[i][j]); for(int i = 0; i < 20; ++i) scanf("%d",kroutine+i); for(int i = 0; i < 20; ++i) scanf("%d",mroutine+i); if(N>=K) game(3); printf("0"); }
|