#include <bits/stdc++.h>
/*
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("-O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/
#define mp make_pair
#define ll long long
#define ld long double
#define pb push_back
#define fast_io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fs first
#define sc second
#define getfiles ifstream cin("input.txt"); ofstream cout("output.txt");
#define endl '\n'
#define con continue
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
const int INF = 2000000005;
const ll BIG_INF = 2000000000000000005;
const int mod = 1000000007;
const int P = 31;
const ld PI = 3.141592653589793238462643;
const double eps = 1e-9;
using namespace std;
vector< pair<int, int> > dir = {
{
-1, 0
},
{
0, 1
},
{
1, 0
},
{
0, -1
}
};
bool valid(int x, int y, int n, int m) {
return x >= 0 && y >= 0 && x < n && y < m;
}
mt19937 rng(1999999973);
inline int getAns(vector<vector<bool>> &a) {
int ans = 0;
for (int i = 0; i < a.size(); i++) {
int diff = 0;
for (int j = 0; j < a[0].size(); j++) {
if (a[i][j])
diff++;
else
diff--;
}
if (diff > 0)
ans++;
}
for (int j = 0; j < a[0].size(); j++) {
int diff = 0;
for (int i = 0; i < a.size(); i++) {
if (a[i][j])
diff--;
else
diff++;
}
if (diff > 0)
ans++;
}
return ans;
}
vector< vector<bool> > solve(int n, int m) {
vector< vector<bool> > a(n, vector<bool>(m, true));
int mxad = (m + 1) / 2 - 1, req = n - ((n + 1) / 2 - 1);
priority_queue<pii> q;
for (int i = 0; i < n; i++)
q.push(mp(mxad, i));
int cur_column = m - 1;
while(true) {
vector<pii> cur;
cur.reserve(req);
bool good = true;
for (int i = 0; i < req; i++) {
pii v = q.top();
if (v.fs == 0) {
good = false;
break;
}
cur.pb(v);
q.pop();
}
if (!good)
break;
for (int i = 0; i < req; i++) {
a[cur[i].sc][cur_column] = false;
q.push(mp(cur[i].fs - 1, cur[i].sc));
}
cur_column--;
}
return a;
}
signed main() {
fast_io;
int tests;
cin >> tests;
while(tests--) {
int n, m;
cin >> n >> m;
vector<vector<bool>> a(n, vector<bool>(m, true));
if (n >= m)
a = solve(n, m);
else {
vector< vector<bool> > b(m, vector<bool>(n, true));
b = solve(m, n);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
a[i][j] = !b[j][i];
}
}
}
cout << getAns(a) << endl;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cout << (a[i][j] ? '+' : '-');
}
cout << endl;
}
}
return 0;
}
Compilation message
stones.cpp: In function 'int getAns(std::vector<std::vector<bool> >&)':
stones.cpp:55:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < a.size(); i++) {
~~^~~~~~~~~~
stones.cpp:57:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 0; j < a[0].size(); j++) {
~~^~~~~~~~~~~~~
stones.cpp:66:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 0; j < a[0].size(); j++) {
~~^~~~~~~~~~~~~
stones.cpp:68:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < a.size(); i++) {
~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
7 ms |
404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
77 ms |
1400 KB |
Output is correct |
2 |
Correct |
72 ms |
1516 KB |
Output is correct |
3 |
Correct |
66 ms |
1448 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
71 ms |
1336 KB |
Output is correct |
2 |
Correct |
62 ms |
1360 KB |
Output is correct |
3 |
Correct |
57 ms |
1272 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
7 ms |
404 KB |
Output is correct |
5 |
Correct |
77 ms |
1400 KB |
Output is correct |
6 |
Correct |
72 ms |
1516 KB |
Output is correct |
7 |
Correct |
66 ms |
1448 KB |
Output is correct |
8 |
Correct |
71 ms |
1336 KB |
Output is correct |
9 |
Correct |
62 ms |
1360 KB |
Output is correct |
10 |
Correct |
57 ms |
1272 KB |
Output is correct |
11 |
Correct |
21 ms |
632 KB |
Output is correct |
12 |
Correct |
60 ms |
1372 KB |
Output is correct |
13 |
Correct |
65 ms |
1356 KB |
Output is correct |
14 |
Correct |
49 ms |
1064 KB |
Output is correct |
15 |
Correct |
80 ms |
1680 KB |
Output is correct |
16 |
Correct |
60 ms |
1528 KB |
Output is correct |
17 |
Correct |
27 ms |
888 KB |
Output is correct |