//-------------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 (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 = 2;i <= n;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 / 2 - (m % 2 == 0)) cout << '-';
// else cout << '+';
// }
// cout << '\n';
// }
// }
// }
// }
// else if (min(n, m) <= 5) {
// assert(min(n, m) == 5);
// if (n < m) {
// if (m & 1) {
// for (int i = 1;i <= m / 2 + 1;i++) ans[1][i] = '+';
// for (int i = m / 2 + 2;i <= m;i++) ans[1][i] = '-';
// for (int i = 1;i <= m / 2;i++) ans[2][i] = '-';
// for (int i = m / 2 + 1;i <= m;i++) ans[2][i] = '+';
// for (int i = 1;i <= m / 2;i++) ans[3][i] = '+';
// ans[3][m / 2 + 1] = '-', ans[3][m / 2 + 2] = '+';
// for (int i = m / 2 + 3;i <= m;i++) ans[3][i] = '-';
// for (int i = 4;i <= n;i++) {
// for (int j = 1;j <= m;j++) {
// ans[i][j] = '-';
// }
// }
// }
// else {
// for (int i = 1;i <= m / 2 + 1;i++) ans[1][i] = '+';
// for (int i = m / 2 + 2;i <= m;i++) ans[1][i] = '-';
// for (int i = 1;i < m / 2;i++) ans[2][i] = '-';
// for (int i = m / 2;i <= m;i++) ans[2][i] = '+';
// for (int i = 1;i < m / 2;i++) ans[3][i] = '+';
// ans[3][m / 2] = '-', ans[3][m / 2 + 1] = '-';
// ans[3][m / 2 + 2] = '+', ans[3][m / 2 + 3] = '+';
// for (int i = m / 2 + 4;i <= m;i++) ans[3][i] = '-';
// for (int i = 4;i <= n;i++) {
// for (int j = 1;j <= m;j++) {
// ans[i][j] = '-';
// }
// }
// }
// cout << m + 3 << '\n';
// for (int i = 1;i <= n;i++) {
// for (int j = 1;j <= m;j++) {
// cout << ans[i][j];
// }
// cout << '\n';
// }
// }
// else {
// if (n & 1) {
// for (int i = 1;i <= n / 2 + 1;i++) ans[i][1] = '-';
// for (int i = n / 2 + 2;i <= n;i++)ans[i][1] = '+';
// for (int i = 1;i <= n / 2;i++) ans[i][2] = '+';
// for (int i = n / 2 + 1;i <= n;i++) ans[i][2] = '-';
// for (int i = 1;i <= n / 2;i++) ans[i][3] = '-';
// ans[n / 2 + 1][3] = '+', ans[n / 2 + 2][3] = '-';
// for (int i = n / 2 + 3;i <= n;i++) ans[i][3] = '+';
// for (int i = 4;i <= m;i++) {
// for (int j = 1;j <= n;j++) {
// ans[j][i] = '+';
// }
// }
// }
// else {
// for (int i = 1;i <= n / 2 + 1;i++) ans[i][1] = '-';
// for (int i = n / 2 + 2;i <= n;i++)ans[i][1] = '+';
// for (int i = 1;i < n / 2;i++) ans[i][2] = '+';
// for (int i = n / 2;i <= n;i++) ans[i][2] = '-';
// for (int i = 1;i < n / 2;i++) ans[i][3] = '-';
// ans[n / 2][3] = '+', ans[n / 2 + 1][3] = '+';
// ans[n / 2 + 2][3] = '-', ans[n / 2 + 3][3] = '-';
// for (int i = n / 2 + 4;i <= n;i++) ans[i][3] = '+';
// for (int i = 4;i <= m;i++) {
// for (int j = 1;j <= n;j++) {
// ans[j][i] = '+';
// }
// }
// }
// cout << n + 3 << '\n';
// for (int i = 1;i <= n;i++) {
// for (int j = 1;j <= m;j++) {
// cout << ans[i][j];
// }
// cout << '\n';
// }
// }
// }
// else if (n % 2 && m % 2) {
if (n < m) {
vector<int> col(m + 1);
int answ = m;
for (int i = 1;i <= n;i++) {
int row = 0;
for (int j = 1;j <= m;j++) {
if (col[j] + 1 <= n / 2 && row <= m / 2) {
col[j]++, row++;
ans[i][j] = '+';
}
else ans[i][j] = '-';
}
if (row > m / 2) answ++;
}
cout << answ << '\n';
for (int i = 1;i <= n;i++) {
for (int j = 1;j <= m;j++) {
cout << ans[i][j];
}
cout << '\n';
}
}
else {
vector<int> row(n + 1);
int answ = n;
for (int i = 1;i <= m;i++) {
int col = 0;
for (int j = 1;j <= n;j++) {
if (row[j] + 1 <= m / 2 && col <= n / 2) {
row[j]++, col++;
ans[j][i] = '-';
}
else ans[j][i] = '+';
}
if (col > n / 2) answ++;
}
cout << answ << '\n';
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 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
in the table A+B is not equal to 5 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
in the table A+B is not equal to 21 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
in the table A+B is not equal to 5 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
18 ms |
1368 KB |
Wrong answer in test 97 21: 107 < 116 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
17 ms |
1368 KB |
in the table A+B is not equal to 36 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
in the table A+B is not equal to 5 |
3 |
Halted |
0 ms |
0 KB |
- |