fork(1) download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. #include <cassert>
  5.  
  6. using namespace std;
  7.  
  8. #define FOR(i,n) for(int i=0;i<(n);i++)
  9.  
  10. int a[128][128];
  11.  
  12. int main() {
  13. int T;
  14. cin >> T;
  15. FOR(i,T) FOR(j,T) {
  16. string inp;
  17. cin >> inp;
  18. a[i][j] = (inp == "YES");
  19. }
  20. int pos = 0, res;
  21. int az = false;
  22. FOR(i,T) {
  23. bool _az = true;
  24. FOR(j,T) _az = (_az && !a[i][j]);
  25. az = (az || _az);
  26. }
  27. if(!az) {
  28. pos++;
  29. res = -1;
  30. }
  31. FOR(i,T) if(a[i][i]) {
  32. int iso = 0;
  33. FOR(j,i) if(a[i][j]) iso = 1;
  34. if(iso) continue;
  35. bool f = true;
  36. FOR(j,T) if(f) {
  37. if(a[i][j]) FOR(k,T) f = (f && (a[i][k] == a[j][k]));
  38. else {
  39. bool m = true;
  40. FOR(k,T) m = (m && (a[i][k] == a[j][k]));
  41. if(m) f = false;
  42. }
  43. }
  44. if(f) {
  45. pos++;
  46. res = i;
  47. }
  48. }
  49.  
  50. // lets verify there is no other valid output!
  51. assert(pos == 1);
  52. FOR(i,T) cout << (res==-1?"NO":(a[res][i]?"YES":"NO")) << endl;
  53. return 0;
  54. }
Runtime error #stdin #stdout 0.01s 2876KB
stdin
2
NO
NO
NO
NO
stdout
Standard output is empty