#include <bits/stdc++.h>
using namespace std;
bool possible(int i, int n, int m, int mid){
int total = (n-i)*mid + i*min(mid, m-(m/2+1));
return total >= mid*(n/2+1);
}
int find_can(int i, int n, int m){
int l = 0, r = m, ans = 0;
while(l <= r){
int mid = (l+r)/2;
if (!possible(i, n, m, mid)) r = mid-1;
else{
ans = mid;
l = mid+1;
}
}
return ans;
}
int main(){
int t;
cin >> t;
while(t--){
int n, m;
cin >> n >> m;
int opt = 0, can = -1;
for (int i = 0; i <= n; i++){
int new_can = find_can(i, n, m);
if (new_can+i > opt+can) opt = i, can = new_can;
}
vector<int> count(m, 0);
vector<vector<char> > grid(n, vector<char>(m));
cout << can + opt << endl;
for (int i = 0; i < n; i++){
int row_need = m/2 + 1;
for (int j = 0; j < m; j++){
if (i < n-opt) grid[i][j] = '-', count[j]++;
else{
if (row_need == m - j || j >= can || count[j] == n/2+1){
grid[i][j] = '+';
row_need--;
}
else{
grid[i][j] = '-';
count[j]++;
}
}
}
}
for (int i = 0; i < n; i++){
for (int j = 0; j < m; j++) cout << grid[i][j];
cout << endl;
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
304 KB |
Output is correct |
2 |
Correct |
1 ms |
300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
304 KB |
Output is correct |
2 |
Correct |
1 ms |
300 KB |
Output is correct |
3 |
Correct |
5 ms |
340 KB |
Output is correct |
4 |
Incorrect |
9 ms |
340 KB |
in the table A+B is not equal to 41 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
45 ms |
1256 KB |
in the table A+B is not equal to 78 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
34 ms |
1236 KB |
in the table A+B is not equal to 44 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
304 KB |
Output is correct |
2 |
Correct |
1 ms |
300 KB |
Output is correct |
3 |
Correct |
5 ms |
340 KB |
Output is correct |
4 |
Incorrect |
9 ms |
340 KB |
in the table A+B is not equal to 41 |
5 |
Halted |
0 ms |
0 KB |
- |