fork download
  1. #include "bits/stdc++.h"
  2. using namespace std;
  3.  
  4.  
  5. const int N = 1005;
  6.  
  7. int B[N][N], n, m, r, c;
  8. int a[N][N];
  9.  
  10.  
  11. void upd(int x, int y, int v) {
  12. for(int i = x ; i <= n ; i += (i&-i)) {
  13. for(int j = y ; j <= m ; j += (j&-j)) {
  14. B[i][j] += v;
  15. }
  16. }
  17. }
  18. int sum(int x, int y) {
  19. int ans = 0;
  20. for(int i = x ; i > 0 ; i -= (i&-i)) {
  21. for(int j = y ; j > 0 ; j -= (j&-j)) {
  22. ans += B[i][j];
  23. }
  24. }
  25. return ans;
  26. }
  27. int update(int x1, int y1, int x2, int y2, int v) {
  28. upd(x2 + 1, y2 + 1, v);
  29. upd(x1, y1, v);
  30. upd(x1, y2 + 1, -v);
  31. upd(x2 + 1, y1, -v);
  32. }
  33.  
  34.  
  35. int main() {
  36. ios_base::sync_with_stdio(false);
  37. cin.tie(0);cout.tie(0);
  38. int t; cin>>t;
  39. while(t -- ) {
  40. cin>>n>>m>>r>>c;
  41. for(int i = 0; i<=n; i++) for(int j = 0; j<=m; j++) B[i][j] = 0;
  42. for(int i = 1 ; i <= n ; i++) {
  43. for(int j = 1 ; j <= m ; j++) {
  44. char ai; cin>>ai;
  45. if(ai == '1') a[i][j] = 1;
  46. else a[i][j] = 0;
  47. upd(i, j, a[i][j] + a[i-1][j-1] - a[i-1][j] - a[i][j-1]);
  48. }
  49. }
  50. int ans = 0;
  51. for(int i = 1 ; i <= n ; i++) {
  52. for(int j = 1 ; j <= m ; j++) {
  53. int get = sum(i, j);
  54. if(get & 1) {
  55. if(i + r - 1 > n || j + c - 1 > m) {
  56. continue;
  57. }
  58. // cout<<i<<" "<<j<<" "<<i+r-1<<" "<<j+c-1<<" "<<get<<"\n";
  59. ans ++;
  60. update(i, j, i + r - 1, j + c - 1, 1);
  61. }
  62. }
  63. }
  64. bool ok = 1;
  65. for(int i = 1; i<=n; i++) {
  66. for(int j = 1; j<=m; j++) {
  67. int get = sum(i, j);
  68. if(get & 1) {
  69. ok = 0;
  70. break;
  71. }
  72. }
  73. if(!ok) break;
  74. }
  75. if(ok) {
  76. cout<<ans<<"\n";
  77. } else {
  78. cout<<"-1\n";
  79. }
  80. }
  81. return 0;
  82. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:1: error: illegal character: '#'
#include "bits/stdc++.h"
^
Main.java:1: error: class, interface, or enum expected
#include "bits/stdc++.h"
         ^
Main.java:5: error: class, interface, or enum expected
const int N = 1005;
^
Main.java:7: error: class, interface, or enum expected
int B[N][N], n, m, r, c;
^
Main.java:8: error: class, interface, or enum expected
int a[N][N];
^
Main.java:11: error: class, interface, or enum expected
void upd(int x, int y, int v) {
^
Main.java:12: error: class, interface, or enum expected
  for(int i = x ; i <= n ; i += (i&-i)) {
                  ^
Main.java:12: error: class, interface, or enum expected
  for(int i = x ; i <= n ; i += (i&-i)) {
                           ^
Main.java:13: error: class, interface, or enum expected
    for(int j = y ; j <= m ; j += (j&-j)) {
                    ^
Main.java:13: error: class, interface, or enum expected
    for(int j = y ; j <= m ; j += (j&-j)) {
                             ^
Main.java:15: error: class, interface, or enum expected
    }
    ^
Main.java:20: error: class, interface, or enum expected
  for(int i = x ; i > 0 ; i -= (i&-i)) {
  ^
Main.java:20: error: class, interface, or enum expected
  for(int i = x ; i > 0 ; i -= (i&-i)) {
                  ^
Main.java:20: error: class, interface, or enum expected
  for(int i = x ; i > 0 ; i -= (i&-i)) {
                          ^
Main.java:21: error: class, interface, or enum expected
    for(int j = y ; j > 0 ; j -= (j&-j)) {
                    ^
Main.java:21: error: class, interface, or enum expected
    for(int j = y ; j > 0 ; j -= (j&-j)) {
                            ^
Main.java:23: error: class, interface, or enum expected
    }
    ^
Main.java:26: error: class, interface, or enum expected
}
^
Main.java:29: error: class, interface, or enum expected
  upd(x1, y1, v);
  ^
Main.java:30: error: class, interface, or enum expected
  upd(x1, y2 + 1, -v);
  ^
Main.java:31: error: class, interface, or enum expected
  upd(x2 + 1, y1, -v);
  ^
Main.java:32: error: class, interface, or enum expected
}
^
Main.java:37: error: class, interface, or enum expected
    cin.tie(0);cout.tie(0); 
    ^
Main.java:37: error: class, interface, or enum expected
    cin.tie(0);cout.tie(0); 
               ^
Main.java:38: error: class, interface, or enum expected
	int t; cin>>t;
	^
Main.java:38: error: class, interface, or enum expected
	int t; cin>>t;
	       ^
Main.java:39: error: class, interface, or enum expected
	while(t -- ) {
	^
Main.java:41: error: class, interface, or enum expected
		for(int i = 0; i<=n; i++) for(int j = 0; j<=m; j++) B[i][j] = 0;
		^
Main.java:41: error: class, interface, or enum expected
		for(int i = 0; i<=n; i++) for(int j = 0; j<=m; j++) B[i][j] = 0;
		               ^
Main.java:41: error: class, interface, or enum expected
		for(int i = 0; i<=n; i++) for(int j = 0; j<=m; j++) B[i][j] = 0;
		                     ^
Main.java:41: error: class, interface, or enum expected
		for(int i = 0; i<=n; i++) for(int j = 0; j<=m; j++) B[i][j] = 0;
		                                         ^
Main.java:41: error: class, interface, or enum expected
		for(int i = 0; i<=n; i++) for(int j = 0; j<=m; j++) B[i][j] = 0;
		                                               ^
Main.java:42: error: class, interface, or enum expected
		for(int i = 1 ; i <= n ; i++) {
		^
Main.java:42: error: class, interface, or enum expected
		for(int i = 1 ; i <= n ; i++) {
		                ^
Main.java:42: error: class, interface, or enum expected
		for(int i = 1 ; i <= n ; i++) {
		                         ^
Main.java:43: error: class, interface, or enum expected
		    for(int j = 1 ; j <= m ; j++) {
		                    ^
Main.java:43: error: class, interface, or enum expected
		    for(int j = 1 ; j <= m ; j++) {
		                             ^
Main.java:44: error: class, interface, or enum expected
		    	char ai; cin>>ai;
		    	         ^
Main.java:45: error: class, interface, or enum expected
		    	if(ai == '1') a[i][j] = 1;
		    	^
Main.java:46: error: class, interface, or enum expected
		    	else a[i][j] = 0;
		    	^
Main.java:47: error: class, interface, or enum expected
				upd(i, j, a[i][j] + a[i-1][j-1] - a[i-1][j] - a[i][j-1]);
				^
Main.java:48: error: class, interface, or enum expected
		    }
		    ^
Main.java:51: error: class, interface, or enum expected
		for(int i = 1 ; i <= n ; i++) {
		^
Main.java:51: error: class, interface, or enum expected
		for(int i = 1 ; i <= n ; i++) {
		                ^
Main.java:51: error: class, interface, or enum expected
		for(int i = 1 ; i <= n ; i++) {
		                         ^
Main.java:52: error: class, interface, or enum expected
		    for(int j = 1 ; j <= m ; j++) {
		                    ^
Main.java:52: error: class, interface, or enum expected
		    for(int j = 1 ; j <= m ; j++) {
		                             ^
Main.java:54: error: class, interface, or enum expected
		    	if(get & 1) {
		    	^
Main.java:57: error: class, interface, or enum expected
					}
					^
Main.java:60: error: class, interface, or enum expected
		    		update(i, j, i + r - 1, j + c - 1, 1);
		    		^
Main.java:61: error: class, interface, or enum expected
				}
				^
Main.java:65: error: class, interface, or enum expected
		for(int i = 1; i<=n; i++) {
		^
Main.java:65: error: class, interface, or enum expected
		for(int i = 1; i<=n; i++) {
		               ^
Main.java:65: error: class, interface, or enum expected
		for(int i = 1; i<=n; i++) {
		                     ^
Main.java:66: error: class, interface, or enum expected
			for(int j = 1; j<=m; j++) {
			               ^
Main.java:66: error: class, interface, or enum expected
			for(int j = 1; j<=m; j++) {
			                     ^
Main.java:68: error: class, interface, or enum expected
				if(get & 1) {
				^
Main.java:70: error: class, interface, or enum expected
					break;
					^
Main.java:71: error: class, interface, or enum expected
				}
				^
Main.java:74: error: class, interface, or enum expected
		}
		^
Main.java:77: error: class, interface, or enum expected
		} else {
		^
Main.java:79: error: class, interface, or enum expected
		}
		^
Main.java:82: error: class, interface, or enum expected
}     
^
63 errors
stdout
Standard output is empty