#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
sortbooks.cpp:49:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main(){
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
12 ms |
8568 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
11 ms |
8440 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |