#define wiwihorz
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma loop-opt(on)
#define rep(i, a, b) for(int i = a; i <= b; i ++)
#define rrep(i, a, b) for(int i = b; i >= a; i--)
#define all(x) x.begin(), x.end()
#define ceil(a, b) ((a + b - 1) / (b))
using namespace std;
#define INF 1000000000000000000
#define int long long int
#define pii pair<int, int>
#define random mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count())
#ifdef wiwihorz
#define print(a...) cerr << "Line " << __LINE__ << ": ", kout("[" + string(#a) + "] = ", a)
void vprint(auto L, auto R) { while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
void kout() { cerr << endl; }
template<class T1, class ... T2> void kout(T1 a, T2 ... e) { cerr << a << " ", kout(e...);}
#else
#define print(...) 0
#define vprint(...) 0
#endif
namespace solver {
int n, m, inv;
priority_queue<pii,vector<pii>, greater<pii>> pq;
vector<vector<int>> a;
void init_(int _n, int _m) {
n = _n, m = _m;
if(n > m) swap(n, m), inv = 1;
while(pq.size()) pq.pop();
a.assign(n + 1, vector<int>(m + 1, 0));
}
void solve() {
int mxn = n - n / 2 - 1, mxm = m / 2 + 1;
int ans = m;
rep(i, 1, m) pq.push({0, i});
rep(i, 1, n) {
bool done = 0;
rep(j, 1, mxm) {
pii p = pq.top(); pq.pop();
if(p.first == mxn) {
done = 1;
break;
}
p.first ++;
a[i][p.second] = 1;
pq.push(p);
}
if(done) break;
else ans ++;
}
cout << ans << "\n";
if(inv) rep(i, 1, m) rep(j, 1, n)
cout << (a[j][i] ? "-" : "+") << (j == n ? "\n" : "");
else rep(i, 1, n) rep(j, 1, m)
cout << (a[i][j] ? "+" : "-") << (j == m ? "\n" : "");
}
};
using namespace solver;
signed main() {
ios::sync_with_stdio(false), cin.tie(0);
int t; cin >> t;
while(t--) {
int n, m;
cin >> n >> m;
init_(n, m);
solve();
}
return 0;
}
Compilation message
stones.cpp:4: warning: ignoring '#pragma loop ' [-Wunknown-pragmas]
4 | #pragma loop-opt(on)
|
stones.cpp:20:13: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
20 | void vprint(auto L, auto R) { while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
| ^~~~
stones.cpp:20:21: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
20 | void vprint(auto L, auto R) { while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
0 ms |
204 KB |
Wrong answer |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
332 KB |
Wrong answer |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
0 ms |
204 KB |
Wrong answer |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
88 ms |
1500 KB |
Wrong answer |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
86 ms |
1640 KB |
Output is correct |
2 |
Correct |
77 ms |
5680 KB |
Output is correct |
3 |
Correct |
72 ms |
5700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
0 ms |
204 KB |
Wrong answer |