#include "bits/stdc++.h"
using namespace std;
// #define endl '\n'
// #define double long double
// #define int long long
// int MOD = 1000 * 1000 * 1000 + 7;
// int MOD = 998244353;
int n, m;
int score(vector<vector<bool> > a) {
int col[m], row[n];
memset(col, 0, sizeof col);
memset(row, 0, sizeof row);
for (int i=0; i<n; i++) {
for (int j=0; j<m; j++) {
if (a[i][j]) {
row[i]++;
col[j]--;
}
else {
row[i]--;
col[j]++;
}
}
}
int ans = 0;
for (int i=0; i<m; i++) {
if (col[i] > 0) ans++;
}
for (int i=0; i<n; i++) {
if (row[i] > 0) ans++;
}
return ans;
}
void show(vector<vector<bool> > a) {
for (int i=0; i<n; i++) {
for (int j=0; j<m; j++) {
cout << (a[i][j] ? '+' : '-');
}
cout << endl;
}
}
void solve() {
cin >> n >> m;
int rfill = (m + 1) / 2;
int cfill = (n + 1) / 2;
vector<vector<bool> > grid1(n, vector<bool>(m, 0)); // allrows
vector<vector<bool> > grid2(n, vector<bool>(m, 1)); // allcols
// true is +, false is -
for (int i=0; i<n; i++) {
// all rows
if (i % 2 == 0) {
for (int j=0; j<rfill; j++) {
grid1[i][j] = true;
}
}
else {
int k = m - 1;
for (int j=0; j<rfill; j++, k--) {
grid1[i][k] = true;
}
}
}
for (int i=0; i<m; i++) {
// all cols
if (i % 2 == 0) {
for (int j=0; j<cfill; j++) {
grid2[j][i] = false;
}
}
else {
int k = n - 1;
for (int j=0; j<cfill; j++, k--) {
grid2[k][i] = false;
}
}
}
int asc = score(grid1);
int bsc = score(grid2);
if (asc > bsc) {
cout << asc << endl;
show(grid1);
}
else {
cout << bsc << endl;
show(grid2);
}
}
signed main() {
int t;
cin >> t;
while (t--) solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Incorrect |
4 ms |
256 KB |
Wrong answer in test 2 4: 0 < 4 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
15 ms |
384 KB |
Wrong answer in test 20 2: 0 < 20 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Incorrect |
4 ms |
256 KB |
Wrong answer in test 2 4: 0 < 4 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
100 ms |
1400 KB |
Wrong answer in test 97 21: 107 < 116 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
78 ms |
1476 KB |
Wrong answer in test 24 24: 0 < 44 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Incorrect |
4 ms |
256 KB |
Wrong answer in test 2 4: 0 < 4 |