Submission #1230878

#TimeUsernameProblemLanguageResultExecution timeMemory
1230878djsksbrbfRed-blue table (IZhO19_stones)C++20
27 / 100
26 ms1352 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
#define fi first
#define se second
#define pb push_back
const int MOD = 1e9 + 7;
const int MAX = 2e5 + 5;
#define int ll

signed main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int tc; cin >> tc;
	while(tc--){
		int n, m; cin >> n >> m;
		char a[n][m];
		for(int i = 0 ; i < n ; i++){
			for(int j = 0 ; j < m ; j++)a[i][j] = '+';
		}
		
		bool swit = 0;
		if(n < m){
			swap(n, m);
			swit = 1;
		}
		
		vector <int> cnt(n, m);
		bool cont = 1;
		int r =0, c = 0;
		ll ans = n;
		
		while(cont){
			int tmp = r;
			for(int i = 1 ; i <= n / 2 + 1 ; i++){
				cnt[tmp]--;
				tmp++;
				if(tmp >= n)tmp = 0;
			}
			
			tmp = r;
			for(int i = 1 ; i <= n / 2 + 1 ; i++){
				if(cnt[tmp] <= m / 2)cont = 0;
				tmp++;
				if(tmp >= n)tmp = 0;
			}
			
			if(!cont)break;
			ans++;
			
			for(int i = 1 ; i <= n ; i++){
				if(swit)a[c][r] = '-';
				else a[r][c] = '-';
				
				r++;
				if(r >= n)r = 0;
			}
			
			c++;
		}
		
		cout << ans << endl;
		
		if(swit){
			for(int i = 0 ; i < m ; i++){
				for(int j = 0 ; j < n ; j++){
					cout << (a[i][j] == '-' ? '+' : '-');
				}
				cout << endl;
			}
		}
		else{
			for(int i = 0 ; i < n ; i++){
				for(int j = 0 ; j < m ; j++){
					cout << a[i][j];
				}
				cout << endl;
			}
		}
	}
	
	return 0;
}
/*
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double

void solve() {
int N, M; cin >> N >> M;

vector<vector<char>> A(N, vector<char>(M, '+'));

bool rot = 0;
if(N < M) {
swap(N, M);
rot = 1;
}

vector<int> cnt(N, M);

bool can = 1;
int r = 0, c = 0, answer = N;
while(can) {
int it = r;
for(int i = 1; i <= N / 2 + 1; ++i) {
cnt[it]--;
it++; if(it >= N)it = 0;
}
it = r;
for(int i = 1; i <= N / 2 + 1; ++i) {
if(cnt[it] <= M / 2) {
can = 0;
}
it++; if(it >= N)it = 0;
}

if(!can) {
break;
}

answer++;

for(int i = 1; i <= N / 2 + 1; ++i) {
if(rot) {
A[c][r] = '-';
}
else {
A[r][c] = '-';
}
r++; if(r >= N)r = 0;
}

c++;
}

cout << answer << "\n";

if(rot) {
for(int i = 0; i < M; ++i) {
for(int j = 0; j < N; ++j) {
cout << (A[i][j] == '+' ? '-' : '+');
}
cout << "\n";
}
return;
}

for(int i = 0; i < N; ++i) {
for(int j = 0; j < M; ++j) {
cout << A[i][j];
}
cout << "\n";
}
}

int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int tc = 1; cin >> tc;

while(tc--) {
solve();
}

return 0;
}

*/
#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...