#include <bits/stdc++.h>
//#define int long long
#define pii pair<int, int>
#define fr first
#define sc second
#define all(s) s.begin(), s.end()
#define szof(s) (int)s.size()
#define Ok puts("Ok")
using namespace std;
const int N = (int)1e3 + 5;
const int INF = 0x3f3f3f3f;
const int MOD = (int)1e9 + 9;
int tests = 1;
int n, m, ans;
char a[N][N], c[N][N];
bool can(int i, int j) {
return (i >= 1 && i <= n && j >= 1 && j <= m);
}
void show() {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cout << c[i][j];
}puts("");
}
}
void solve() {
int n, m, ans = 0;
cin >> n >> m;
vector <pair<int, int>> row, col;
if (m >= n) {
ans = m;
int can = n - (n / 2 + 1);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
c[i][j] = '-';
}
}
for (int j = 1; j <= m; j++) {
col.push_back({j, can});
}
int need = m / 2 + 1;
for (int i = 1; i <= n; i++) {
int cnt = 0;
sort (all(col), [&](pii A, pii B) {
return A.sc > B.sc;
});
for (int j = 0; j < need; j++) {
if (col[j].sc) {
cnt++;
}
}
if (cnt == need) {
ans++;
for (int j = 0; j < need; j++) {
c[i][col[j].fr] = '+';
col[j].sc--;
}
} else {
break;
}
}
}
else {
ans = n;
int can = m - (m / 2 + 1);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
c[i][j] = '+';
}
}
for (int i = 1; i <= n; i++) {
row.push_back({i, can});
}
int need = n / 2 + 1;
for (int j = 1; j <= m; j++) {
int cnt = 0;
sort (all(row), [&](pii A, pii B) {
return A.sc > B.sc;
});
for (int i = 0; i < need; j++) {
if (row[i].sc) {
cnt++;
}
}
if (cnt == need) {
ans++;
for (int i = 0; i < need; i++) {
c[col[i].fr][j] = '-';
row[j].sc--;
}
} else {
break;
}
}
}
cout << ans << endl;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cout << c[i][j];
}cout << endl;
}
}
main() {
cin >> tests;
while (tests--) {
solve();
}
}
Compilation message
stones.cpp:117:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main() {
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
420 KB |
Output is correct |
2 |
Execution timed out |
2040 ms |
256 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2035 ms |
376 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
420 KB |
Output is correct |
2 |
Execution timed out |
2040 ms |
256 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2016 ms |
380 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
78 ms |
1484 KB |
Output is correct |
2 |
Correct |
49 ms |
1912 KB |
Output is correct |
3 |
Correct |
45 ms |
1656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
420 KB |
Output is correct |
2 |
Execution timed out |
2040 ms |
256 KB |
Time limit exceeded |