fork download
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. #include <ext/pb_ds/tree_policy.hpp>
  4.  
  5. using namespace std;
  6. using namespace __gnu_pbds;
  7.  
  8. #define fi first
  9. #define se second
  10. #define mp make_pair
  11. #define pb push_back
  12. #define fbo find_by_order
  13. #define ook order_of_key
  14.  
  15. typedef long long ll;
  16. typedef pair<int,int> ii;
  17. typedef vector<int> vi;
  18. typedef long double ld;
  19. typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
  20. typedef set<int>::iterator sit;
  21. typedef map<int,int>::iterator mit;
  22. typedef vector<int>::iterator vit;
  23.  
  24. int a[1001][1001];
  25. int ans[1001];
  26. const int LG = 31;
  27. int n;
  28.  
  29. void processbit(int z)
  30. {
  31. for(int i = 0; i < n; i++)
  32. {
  33. for(int j = 0; j < n; j++)
  34. {
  35. if(a[i][j]==-1) continue;
  36. if(a[i][j]&(1<<z))
  37. {
  38.  
  39. }
  40. else
  41. {
  42. if(ans[i]&(1<<z)) ans[i]^=(1<<z);
  43. if(ans[j]&(1<<z)) ans[j]^=(1<<z);
  44. }
  45. }
  46. }
  47. }
  48.  
  49. bool checkans()
  50. {
  51. for(int i = 0; i < n; i++)
  52. {
  53. for(int j = 0; j < n; j++)
  54. {
  55. if(a[i][j]==-1) continue;
  56. if((ans[i]|ans[j])==a[i][j])
  57. {
  58.  
  59. }
  60. else
  61. {
  62. return false;
  63. }
  64. }
  65. }
  66. return true;
  67. }
  68. int main()
  69. {
  70. ios_base::sync_with_stdio(0); cin.tie(0);
  71. cin >> n;
  72. for(int i = 0; i < n; i++)
  73. {
  74. for(int j = 0; j < n; j++)
  75. {
  76. cin>>a[i][j];
  77. }
  78. ans[i] = INT_MAX;
  79. }
  80. for(int i = 0; i < LG; i++) processbit(i);
  81. if(!checkans())
  82. {
  83. cout<<"NO\n";
  84. }
  85. else
  86. {
  87. for(int i = 0; i < n; i++) cout<<ans[i]<<' ';
  88. }
  89. }
  90.  
Success #stdin #stdout 0s 19152KB
stdin
Standard input is empty
stdout
Standard output is empty