fork(3) download
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<math.h>
  4. #include<string.h>
  5. #include<assert.h>
  6. #define REP(i,a,b) for(i=a;i<b;i++)
  7. #define rep(i,n) REP(i,0,n)
  8.  
  9. int main(){
  10. int T;
  11. int i, j, k, in[120][120];
  12. int same[120][120];
  13. int res, cnt = 0;
  14. char buf[10];
  15.  
  16. assert( scanf("%d",&T)==1 );
  17. rep(i,T) rep(j,T){
  18. assert( scanf("%s",buf)==1 );
  19. if(strcmp(buf,"YES")==0) in[i][j] = 1;
  20. else if(strcmp(buf,"NO") ==0) in[i][j] = 0;
  21. else assert(0);
  22. }
  23.  
  24. rep(i,T){
  25. k = 0;
  26. rep(j,T) if(in[i][j]==1) k++;
  27. if(k==0) break;
  28. }
  29. if(i==T) res=-1, cnt++; /* All "NO" is a valid output */
  30.  
  31. rep(i,T) rep(j,T){
  32. same[i][j] = 1;
  33. rep(k,T) if(in[i][k]!=in[j][k]){ same[i][j]=0; break; }
  34. }
  35.  
  36. rep(i,T){
  37. REP(j,i+1,T) if(same[i][j]) break;
  38. if(j<T) continue;
  39.  
  40. rep(j,T) if(in[i][j] != same[i][j]) break;
  41. if(j==T) res = i, cnt++; /* It is a valid output that is the same as the i-th input */
  42. }
  43.  
  44. assert(cnt==1); /* output should be determined uniquely */
  45.  
  46. if(res==-1){
  47. rep(i,T) puts("NO");
  48. } else {
  49. rep(i,T) if(in[res][i]) puts("YES"); else puts("NO");
  50. }
  51.  
  52. return 0;
  53. }
Runtime error #stdin #stdout 0.02s 2856KB
stdin
2
NO
NO
NO
NO
stdout
Standard output is empty