제출 #568175

#제출 시각아이디문제언어결과실행 시간메모리
568175nafis_shifatRed-blue table (IZhO19_stones)C++14
17 / 100
2083 ms444 KiB
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
using namespace std;
const int mxn=1e5+5;
const int inf=1e9;
void solve() {
	int n, m;
	cin >> n >> m;
	int b[n][m], res = 0;
	for(int i = 0; i < (1 << (n * m)); i++) {
		int a[n][m];
		for(int j = 0; j < n; j++) {
			for(int k = 0; k < m; k++) {
				a[j][k] = (i >> (j * m + k)) & 1;
			}
		}

		int ans = 0;
		for(int j = 0; j < n; j++) {
			int c = 0;
			for(int k = 0; k < m; k++) c += a[j][k];

			if(c > m / 2) ans++;
		}

		for(int j = 0; j < m; j++) {
			int c = 0;
			for(int k = 0; k < n; k++) {
				c += 1 - a[k][j];
			}

			if(c > n / 2) ans++;
		}


		if(ans > res) {
			res = ans;
			for(int j = 0; j < n; j++) for(int k = 0; k < m; k++) b[j][k] = a[j][k];

		}



	}

	cout<<res<<endl;


	for(int i = 0; i < n; i++) {
		for(int j = 0; j < m; j++) {
			if(b[i][j]) cout<<"+";
			else cout<<"-";
		}
		cout<<endl;
	}
}

int main() {
	int t;
	cin >> t;
	while(t--) solve();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...