//-------------dilanyan------------\\
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
//------------------KarginDefines--------------------\\
#define ll long long
#define pb push_back
#define all(u) (u).begin(), (u).end()
#define pqueue priority_queue
#define upper upper_bound
#define lower lower_bound
#define umap unordered_map
#define uset unordered_set
#define Kargin ios_base::sync_with_stdio(false);cin.tie(NULL);
#define Usaco freopen(".in", "r", stdin); freopen(".out", "w", stdout);
//-------------------KarginConstants------------------\\
const ll mod = 1000000007;
const ll inf = 2e9;
//-------------------KarginCode------------------------\\
const int N = 1005;
char a[N][N], ans[N][N];
int cnt = 0;
int dx[4] = { 1,-1,0,0 };
int dy[4] = { 0,0,1,-1 };
int n, m;
int A = 0, B = 0;
void dfs(int sx, int sy,char c) {
a[sx][sy] = c;
cnt++;
for (int i = 0;i < 4;i++) {
int x = sx + dx[i], y = sy + dy[i];
if (x >= 1 && x <= n && y >= 1 && y <= m) {
if (a[x][y] == '0') {
dfs(x, y, '+');
dfs(x, y, '-');
}
}
}
if (cnt == n * m) {
int ax = 0, bx = 0;
for (int i = 1;i <= n;i++) {
int r = 0, b = 0;
for (int j = 1;j <= m;j++) {
if (a[i][j] == '+') r++;
else b++;
}
if (r > b) ax++;
}
for (int i = 1;i <= m;i++) {
int r = 0, b = 0;
for (int j = 1;j <= n;j++) {
if (a[j][i] == '+') r++;
else b++;
}
if (b > r) bx++;
}
if (ax + bx > A + B) {
A = ax, B = bx;
for (int i = 1;i <= n;i++) {
for (int j = 1;j <= m;j++) {
ans[i][j] = a[i][j];
}
}
}
}
a[sx][sy] = '0';
cnt--;
}
void KarginSolve() {
cin >> n >> m;
if (n <= 4 && m <= 4) {
for (int i = 1;i <= n;i++) {
for (int j = 1;j <= m;j++) {
a[i][j] = '0';
}
}
dfs(1, 1, '+');
dfs(1, 1, '-');
for (int i = 1;i <= n;i++) {
for (int j = 1;j <= m;j++) {
cout << ans[i][j];
}
cout << '\n';
}
}
}
int main() {
//Usaco
Kargin;
int test = 1;
cin >> test;
while (test--) {
KarginSolve();
}
return 0;
}
Compilation message
stones.cpp:1:1: warning: multi-line comment [-Wcomment]
1 | //-------------dilanyan------------\\
| ^
stones.cpp:8:1: warning: multi-line comment [-Wcomment]
8 | //------------------KarginDefines--------------------\\
| ^
stones.cpp:22:1: warning: multi-line comment [-Wcomment]
22 | //-------------------KarginConstants------------------\\
| ^
stones.cpp:27:1: warning: multi-line comment [-Wcomment]
27 | //-------------------KarginCode------------------------\\
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Expected integer, but "---" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
22 ms |
348 KB |
Expected integer, but "+" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Expected integer, but "---" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Expected integer, but "+++" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
509 ms |
444 KB |
Expected integer, but "+" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Expected integer, but "---" found |
2 |
Halted |
0 ms |
0 KB |
- |