fork download
  1. typedef int lli;
  2. const lli mod=1e9+7;
  3. class Solution {
  4. public:
  5. int swapcol(lli i,lli j,lli n,vector<vector<int> > &a)
  6. {
  7. lli k;
  8. for(k=0;k<n;k++)
  9. {
  10. swap(a[k][j],a[k][i]);
  11. }
  12. return 0;
  13. }
  14. int swaprow(lli i,lli j,lli n,vector<vector<int> > &a)
  15. {
  16. lli k;
  17. for(k=0;k<n;k++)
  18. {
  19. swap(a[j][k],a[i][k]);
  20. }
  21. return 0;
  22. }
  23. lli solve(lli n,vector<vector<int> > &a,vector<vector<int> > &b)
  24. {
  25. lli cnt=0;
  26. lli i,j;
  27. for(i=0;i<n;i++)
  28. {
  29. if(a[0][i]!=b[0][i])
  30. {
  31. for(j=i+1;j<n;j++)
  32. {
  33. if(a[0][j]==b[0][i])
  34. {
  35. cnt++;
  36. swapcol(i,j,n,a);
  37. break;
  38. }
  39. }
  40. }
  41. }
  42. for(i=0;i<n;i++)
  43. {
  44. if(a[i][0]!=b[i][0])
  45. {
  46. for(j=i+1;j<n;j++)
  47. {
  48. if(a[j][0]==b[i][0])
  49. {
  50. swaprow(i,j,n,a);
  51. cnt++;
  52. break;
  53. }
  54. }
  55. }
  56. }
  57. lli flag=0;
  58. for(i=0;i<n;i++)
  59. {
  60. for(j=0;j<n;j++)
  61. {
  62. if(a[i][j]!=b[i][j])
  63. flag=1;
  64. }
  65. }
  66. if(flag)
  67. return mod;
  68. return cnt;
  69. }
  70. int movesToChessboard(vector<vector<int>>& boards) {
  71. vector<vector<int>> a=boards;
  72. int n=a[0].size();
  73. lli i,j;
  74. bool flag=0;
  75. for(i=0;i<n;i++)
  76. {
  77. lli cnt[2]={0};
  78. for(j=0;j<n;j++)
  79. {
  80. cin>>a[i][j];
  81. cnt[a[i][j]]++;
  82. }
  83. if(n%2==0)
  84. {
  85. if(cnt[1]!=cnt[0])
  86. return -1;
  87. }
  88. if(n%2==1)
  89. {
  90. if(abs(cnt[1]-cnt[0])!=1)
  91. return -1;
  92. }
  93.  
  94. }
  95. for(i=0;i<n;i++)
  96. {
  97. lli cnt[2]={0};
  98. for(j=0;j<n;j++)
  99. {
  100. cnt[a[j][i]]++;
  101. }
  102. if(n%2==0)
  103. {
  104. if(cnt[1]!=cnt[0])
  105. return -1;
  106. }
  107. if(n%2==1)
  108. {
  109. if(abs(cnt[1]-cnt[0])!=1)
  110. return -1;
  111. }
  112. }
  113. lli flag1=0;
  114. vector<vector<int> > b;
  115. for(i=0;i<n;i++)
  116. {
  117. vector<int> v;
  118. for(j=0;j<n;j++)
  119. {
  120. v.push_back((i+j)%2);
  121. }
  122. b.push_back(v);
  123. }
  124. vector<vector<int> > c=a;
  125. lli ans=solve(n,a,b);
  126.  
  127. for(i=0;i<n;i++)
  128. {
  129. for(j=0;j<n;j++)
  130. {
  131. b[i][j]^=1;
  132. a[i][j]=c[i][j];
  133. }
  134. }
  135. ans=min(ans,solve(n,a,b));
  136. if(ans==mod)
  137. return -1;
  138. else
  139. return ans;
  140. }
  141. };
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:5:35: error: ‘vector’ has not been declared
     int swapcol(lli i,lli j,lli n,vector<vector<int> > &a)
                                   ^~~~~~
prog.cpp:5:41: error: expected ‘,’ or ‘...’ before ‘<’ token
     int swapcol(lli i,lli j,lli n,vector<vector<int> > &a)
                                         ^
prog.cpp:14:35: error: ‘vector’ has not been declared
     int swaprow(lli i,lli j,lli n,vector<vector<int> > &a)
                                   ^~~~~~
prog.cpp:14:41: error: expected ‘,’ or ‘...’ before ‘<’ token
     int swaprow(lli i,lli j,lli n,vector<vector<int> > &a)
                                         ^
prog.cpp:23:21: error: ‘vector’ has not been declared
     lli solve(lli n,vector<vector<int> > &a,vector<vector<int> > &b)
                     ^~~~~~
prog.cpp:23:27: error: expected ‘,’ or ‘...’ before ‘<’ token
     lli solve(lli n,vector<vector<int> > &a,vector<vector<int> > &b)
                           ^
prog.cpp:70:27: error: ‘vector’ has not been declared
     int movesToChessboard(vector<vector<int>>& boards) {
                           ^~~~~~
prog.cpp:70:33: error: expected ‘,’ or ‘...’ before ‘<’ token
     int movesToChessboard(vector<vector<int>>& boards) {
                                 ^
prog.cpp: In member function ‘int Solution::swapcol(lli, lli, lli, int)’:
prog.cpp:10:18: error: ‘a’ was not declared in this scope
             swap(a[k][j],a[k][i]);
                  ^
prog.cpp:10:13: error: ‘swap’ was not declared in this scope
             swap(a[k][j],a[k][i]);
             ^~~~
prog.cpp:10:13: note: suggested alternative: ‘swapcol’
             swap(a[k][j],a[k][i]);
             ^~~~
             swapcol
prog.cpp: In member function ‘int Solution::swaprow(lli, lli, lli, int)’:
prog.cpp:19:18: error: ‘a’ was not declared in this scope
             swap(a[j][k],a[i][k]);
                  ^
prog.cpp:19:13: error: ‘swap’ was not declared in this scope
             swap(a[j][k],a[i][k]);
             ^~~~
prog.cpp:19:13: note: suggested alternative: ‘swapcol’
             swap(a[j][k],a[i][k]);
             ^~~~
             swapcol
prog.cpp: In member function ‘lli Solution::solve(lli, int)’:
prog.cpp:29:16: error: ‘a’ was not declared in this scope
             if(a[0][i]!=b[0][i])
                ^
prog.cpp:29:25: error: ‘b’ was not declared in this scope
             if(a[0][i]!=b[0][i])
                         ^
prog.cpp:44:16: error: ‘a’ was not declared in this scope
             if(a[i][0]!=b[i][0])
                ^
prog.cpp:44:25: error: ‘b’ was not declared in this scope
             if(a[i][0]!=b[i][0])
                         ^
prog.cpp:62:20: error: ‘a’ was not declared in this scope
                 if(a[i][j]!=b[i][j])
                    ^
prog.cpp:62:29: error: ‘b’ was not declared in this scope
                 if(a[i][j]!=b[i][j])
                             ^
prog.cpp: In member function ‘int Solution::movesToChessboard(int)’:
prog.cpp:71:9: error: ‘vector’ was not declared in this scope
         vector<vector<int>> a=boards;
         ^~~~~~
prog.cpp:71:23: error: expected primary-expression before ‘int’
         vector<vector<int>> a=boards;
                       ^~~
prog.cpp:72:15: error: ‘a’ was not declared in this scope
         int n=a[0].size();
               ^
prog.cpp:80:17: error: ‘cin’ was not declared in this scope
                 cin>>a[i][j];
                 ^~~
prog.cpp:90:20: error: ‘abs’ was not declared in this scope
                 if(abs(cnt[1]-cnt[0])!=1)
                    ^~~
prog.cpp:109:20: error: ‘abs’ was not declared in this scope
                 if(abs(cnt[1]-cnt[0])!=1)
                    ^~~
prog.cpp:114:23: error: expected primary-expression before ‘int’
         vector<vector<int> > b;
                       ^~~
prog.cpp:117:20: error: expected primary-expression before ‘int’
             vector<int> v;
                    ^~~
prog.cpp:120:17: error: ‘v’ was not declared in this scope
                 v.push_back((i+j)%2);
                 ^
prog.cpp:122:13: error: ‘b’ was not declared in this scope
             b.push_back(v);
             ^
prog.cpp:122:25: error: ‘v’ was not declared in this scope
             b.push_back(v);
                         ^
prog.cpp:124:23: error: expected primary-expression before ‘int’
         vector<vector<int> > c=a;
                       ^~~
prog.cpp:125:27: error: ‘b’ was not declared in this scope
         lli ans=solve(n,a,b);
                           ^
prog.cpp:132:25: error: ‘c’ was not declared in this scope
                 a[i][j]=c[i][j];
                         ^
prog.cpp:135:13: error: ‘min’ was not declared in this scope
         ans=min(ans,solve(n,a,b));
             ^~~
stdout
Standard output is empty