#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);
int n, m;
inline int getAns(vector<vector<bool>> &a) {
int ans = 0;
for (int i = 0; i < n; i++) {
int diff = 0;
for (int j = 0; j < m; j++) {
if (a[i][j])
diff++;
else
diff--;
}
if (diff > 0)
ans++;
}
for (int j = 0; j < m; j++) {
int diff = 0;
for (int i = 0; i < n; i++) {
if (a[i][j])
diff--;
else
diff++;
}
if (diff > 0)
ans++;
}
return ans;
}
signed main() {
fast_io;
int tests;
cin >> tests;
while(tests--) {
cin >> n >> 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--;
}
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Wrong answer in test 1 3: 2 < 3 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
376 KB |
Wrong answer in test 3 45: 36 < 46 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Wrong answer in test 1 3: 2 < 3 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
70 ms |
1528 KB |
Wrong answer in test 23 57: 76 < 78 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
70 ms |
1304 KB |
Output is correct |
2 |
Correct |
63 ms |
1256 KB |
Output is correct |
3 |
Correct |
57 ms |
1144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Wrong answer in test 1 3: 2 < 3 |
2 |
Halted |
0 ms |
0 KB |
- |