Submission #168813

# Submission time Handle Problem Language Result Execution time Memory
168813 2019-12-16T15:00:59 Z abil Red-blue table (IZhO19_stones) C++14
0 / 100
2000 ms 1144 KB
#include <bits/stdc++.h>

#define fr first
#define sc second
#define pb push_back
#define mk make_pair
#define all(s) s.begin(),s.end()
//#define int long long

using namespace std;

const int N = (1e4 + 12);
const int mod = (1e9 + 7);
const int INF = (0x3f3f3f3f);

int ar[N][N], mx[N][N], curans;
int n, m;

void solve(int x, int y){
	if(x - 1 == n && y == m || y - 1 == m && x == n){
		int ans = 0;
		for(int i = 1;i <= n; i++){
			int minus = 0, plus = 0;
			for(int j = 1;j <= m; j++){
				if(ar[i][j] == 2){
					minus++;
				}
				else{
					plus++;
				}
			}
			if(plus > minus){
				ans++;
			}
		}
		for(int i = 1;i <= m; i++){
			int minus = 0, plus = 0;
			for(int j = 1;j <= n; j++){
				if(ar[j][i] == 2){
					minus++;
				}
				else{
					plus++;
				}
			}
			if(plus < minus){
				ans++;
			}
		}
		//cout << ans << endl;
		//for(int i = 1;i <= n; i++){
			//for(int j  = 1;j <= m; j++){
				//if(ar[i][j] == 2){
					//cout << "-";
				//}
				//else{
					//cout << "+";
				//}
			//}
			//cout << endl;
		//}
		//cout << endl;
		if(curans < ans){
			curans = ans;
			for(int i = 1;i <= n; i++){
				for(int j = 1;j <= m; j++){
					mx[i][j] = ar[i][j];
				}
			}
		}
	}
	if(x <= n && y <= m){
		ar[x][y] = 1;
		solve(x + 1, y);
		solve(x, y + 1);
		ar[x][y] = 2;
		solve(x + 1, y);
		solve(x, y + 1);
		ar[x][y] = 0;
	}
}
main()
{
	int t;
	cin >> t;
	while(t--){
		cin >> n >> m;
		solve(1, 1);
		cout << curans << endl;
		for(int i = 1;i <= n; i++){
			for(int j = 1;j <= m; j++){
				if(mx[i][j] == 2){
					cout << "-";
				}
				else{
					cout << "+";
				}
			}
			cout << endl;
		}
	}
}

Compilation message

stones.cpp: In function 'void solve(int, int)':
stones.cpp:20:16: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
  if(x - 1 == n && y == m || y - 1 == m && x == n){
     ~~~~~~~~~~~^~~~~~~~~
stones.cpp: At global scope:
stones.cpp:82:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 3 ms 376 KB in the table A+B is not equal to 4
# Verdict Execution time Memory Grader output
1 Execution timed out 2039 ms 376 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 3 ms 376 KB in the table A+B is not equal to 4
# Verdict Execution time Memory Grader output
1 Execution timed out 2037 ms 1144 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2058 ms 504 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 3 ms 376 KB in the table A+B is not equal to 4