This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define pii pair <int, int>
#define fi first
#define se second
#define mp make_pair
const int NM = 1000;
int T, N, M, ans;
char a[NM+5][NM+5];
priority_queue <pii> Q;
vector <pii> v;
void build(int k, int l){
for (int i = 1; i <= N; i++)
for (int j = 1; j <= M; j++){
if (i <= k) a[i][j] = '+'; else a[i][j] = '-';
}
while (!Q.empty()) Q.pop();
for (int i = 1; i <= l; i++) Q.push(mp((N+2)/2-N+k, i));
for (int i = l+1; i <= N; i++) Q.push(mp(-1, i));
for (int i = 1; i <= k; i++){
v.clear();
for (int j = 1; j <= M-(M+2)/2; j++){
v.push_back(Q.top());
Q.pop();
}
for (pii P : v) a[i][P.se] = '-';
for (pii P : v){
Q.push(mp(P.fi-1, P.se));
}
}
}
void solve(){
cin >> N >> M;
int bestk = -1, bestl = -1;
for (int k = 0; k <= N; k++){
int num = k*(M-(M+2)/2), den = (N+2)/2-N+k, l;
if (den <= 0) l = M; else l = min(num/den, M);
if (k+l > bestk+bestl){
bestk = k;
bestl = l;
}
}
cout << bestk+bestl << '\n';
build(bestk, bestl);
for (int i = 1; i <= N; i++){
for (int j = 1; j <= M; j++) cout << a[i][j];
cout << '\n';
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> T;
while (T--){
solve();
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |