# include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
using namespace std;
const int N = 1005;
int t,n,m,a[N][N],ans,rem,cur[N],canrow,val,val1,all;
main() {
//std::ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cin>>t;
// t = 1;
while (t--) {
cin>>n>>m;
ans = max(n,m);
for (int i = 1; i <= n; i++) {
all = i*((m+2)/2);
canrow = min(n - (n+2)/2, i);
// if (i == 5)cout<<canrow<<"\n";
for (int j = 0; j < m; j++) {
if ((m-j)*canrow >= all) {
if (i + (m - j) > ans) {
val = i;
val1 = j;
}
ans = max(ans,i + (m - j));
}
all -= i;
}
}
cout<<ans<<endl;
// cout<<ans<<" "<<val<<" "<<val1<<endl;
if (ans == m) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <=m ;j++) {
cout<<"-";
}
cout<<"\n";
}
continue;
}
if (ans == n) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cout<<"+";
}
}
cout<<"\n";
}
for (int i = 1; i <= val; i++) {
canrow = min(n-(n+2)/2,i);
for (int j = 1; j <= val1; j++) {
a[i][j] = 1;
}
rem = (m+1)/2;
vector < pair <int, int > > v;
v.clear();
for (int j = 1; j <= m; j++) {
v.pb({cur[j],j});
/*if (cur[j] < canrow && rem) {
cur[j]++;
rem--;
a[i][j] = 1;
}*/
}
sort(v.begin(),v.end());
for (int j = 0; j < rem; j++) {
a[i][v[j].s] = 1;
cur[v[j].s]++;
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {cur[j] = 0;
if (a[i][j] == 1) cout<<"+";
else cout<<"-";
}
cout<<"\n";
}
}
}
Compilation message
stones.cpp:8:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
8 | main() {
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
204 KB |
Wrong answer |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
460 KB |
Wrong answer |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
204 KB |
Wrong answer |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
59 ms |
1604 KB |
in the table A+B is not equal to 116 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
57 ms |
1748 KB |
in the table A+B is not equal to 44 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
204 KB |
Wrong answer |