//-------------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) {
A = 0, B = 0;
for (int i = 1;i <= n;i++) {
for (int j = 1;j <= m;j++) {
a[i][j] = '0';
ans[i][j] = '0';
}
}
dfs(1, 1, '+');
dfs(1, 1, '-');
cout << A + B << '\n';
for (int i = 1;i <= n;i++) {
for (int j = 1;j <= m;j++) {
cout << ans[i][j];
}
cout << '\n';
}
}
else if (min(n, m) <= 4) {
assert(min(n, m) == 4);
if (n < m) {
if (n == 1) {
cout << m << '\n';
for (int i = 1;i <= m;i++) cout << '-';
cout << '\n';
}
else if (n == 2) {
cout << m << '\n';
for (int i = 1;i <= n;i++) {
for (int j = 1;j <= m;j++) {
cout << '-';
}
cout << '\n';
}
}
else {
cout << m + 1 << '\n';
for (int i = 1;i <= m;i++) cout << '+';
cout << '\n';
for (int i = 1;i <= 2;i++) {
for (int j = 1;j <= m;j++) {
cout << '-';
}
cout << '\n';
}
}
}
else {
if (m == 1) {
cout << n << '\n';
for (int i = 1;i <= n;i++) cout << "+\n";
}
else if (m == 2) {
cout << n << '\n';
for (int i = 1;i <= n;i++) {
for (int j = 1;j <= m;j++) {
cout << '+';
}
cout << '\n';
}
}
else {
cout << n + 1 << '\n';
for (int i = 1;i <= n;i++) {
for (int j = 1;j <= m;j++) {
if (j < m) cout << '+';
else cout << '-';
}
cout << '\n';
}
}
}
}
else {
}
}
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 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
510 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
510 ms |
344 KB |
Output is correct |
3 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 6 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
503 ms |
448 KB |
Wrong answer |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
510 ms |
344 KB |
Output is correct |
3 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 6 |
4 |
Halted |
0 ms |
0 KB |
- |