#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define dbg(x) cerr << #x << " " << x << "\n"
typedef long long ll;
const int N = 1000;
int row[1 + N], col[1 + N], grid[1 + N][1 + N];
void upd (int l, int c, int x) {
grid[l][c] = max (0, x);
row[l] += x;
col[c] += x;
}
int main () {
ios::sync_with_stdio (false);
cin.tie (0); cout.tie (0);
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
grid[i][j] = row[i] = col[j] = 0;
if (n <= m) {
for (int i = 1; i <= n; i++) {
vector <pair <int, int>> v;
for (int j = 1; j <= m; j++) {
if (2 * (col[j] + 1) < n)
v.pb ({col[j], j});
}
if (v.size () <= m / 2)
break;
sort (v.begin (), v.end ());
for (int j = 0; j <= m / 2; j++)
upd (i, v[j].second, 1);
}
}
else {
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
upd (i, j, 1);
for (int i = 1; i <= m; i++) {
vector <pair <int, int>> v;
for (int j = 1; j <= n; j++) {
if (2 * (row[j] + 1) < m)
v.pb ({row[j], j});
}
if (v.size () <= n / 2)
break;
sort (v.begin (), v.end ());
for (int j = 0; j <= n / 2; j++)
upd (v[j].second, i, -1);
}
}
int ans = 0;
for (int i = 1; i <= n; i++)
if (row[i] * 2 >= m)
ans++;
for (int i = 1; i <= m; i++)
if (col[i] * 2 >= n)
ans++;
cout << ans << "\n";
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++)
if (grid[i][j])
cout << "+";
else
cout << "-";
cout << "\n";
}
}
return 0;
}
Compilation message
stones.cpp: In function 'int main()':
stones.cpp:35:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (v.size () <= m / 2)
~~~~~~~~~~^~~~~~~~
stones.cpp:53:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (v.size () <= n / 2)
~~~~~~~~~~^~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
in the table A+B is not equal to 0 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
632 KB |
in the table A+B is not equal to 1 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
in the table A+B is not equal to 0 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
51 ms |
1784 KB |
in the table A+B is not equal to 118 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
64 ms |
1968 KB |
in the table A+B is not equal to 20 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
in the table A+B is not equal to 0 |
2 |
Halted |
0 ms |
0 KB |
- |