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;
int f[1009][1009];
int g[1009];
void solve(int n, int m){
for(int i = 0; i < n; i++)
for(int j = 0; j < m; j++)
f[i][j]= 0;
int aa = 0, bb = 0;
for(int a= 0; a <= n; a++){
for(int b = 0; b <= m; b++){
int t= max(0, (m/2 + 1) - (m - b));
if(t && a && b && a - (a * t + b - 1)/ b + n - a < (n / 2 + 1)) continue;
if(a + b > aa + bb) aa = a, bb = b;
}
}
cout << aa + bb << endl;
for(int i = 0; i < aa; i++){
for(int j = bb; j < m; j++){
f[i][j] = 1;
}
}
int t = (m / 2 + 1) - (m - bb);
if(t > 0){
priority_queue<pair<int,int> > q;
for(int i = 0; i < bb; i++)
q.push({0, i}), g[i] = 0;
for(int i = 0; i < aa; i++){
vector<int> v;
for(int j = 0; j < t; j++){
v.push_back(q.top().second);
q.pop();
}
for(int j = 0; j < t; j++){
f[i][v[j]] = 1;
g[v[j]] --;
q.push({g[v[j]], v[j]});
}
}
}
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
if(f[i][j] == 1) cout <<'+';
else cout <<'-';
}
cout << endl;
}
}
main(){
int t;
cin >> t;
while(t--){
int n, m;
cin >> n >> m;
solve(n, m);
}
}
Compilation message (stderr)
sortbooks.cpp:49:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main(){
^
# | 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... |