#include<bits/stdc++.h>
#define f first
//#define int long long
#define s second
#define pii pair<int,int>
using namespace std;
const int N=1e3+5,mod=1e9+7;
int t,n,m,red[N];
char a[N][N];
set<pii> s;
main(){
// t=1;
cin >> t;
while(t--){
cin>>n>>m;
for(int i=1;i<=m;i++) red[i] = 0;
int ans = m,B_=m,A_ = 0;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++) a[i][j]='-';
}
for(int i=1;i<=n;i++){
s.clear();
int all=i*(m/2+1);
int all1=all;
int l = 0, r=m/2+1,B=0;
while(l<=r){
int mid=(l+r)/2;
all=all1;
for(int j=1;j<=mid;j++) {
all -= i;
}
if((n-1)/2*(m-mid) >= all) r=mid-1,B=mid;
else l=mid+1;
}
if(i+m-B > ans) ans=i+m-B,A_=i,B_=m-B;
}
cout<<ans<<endl;
for(int i=1;i<=A_;i++) {
s.clear();
for(int j=m-B_+1;j<=m;j++) s.insert({red[j],j});
for(int j=1;j<=m-B_;j++) {
a[i][j]='+';
}
int c = m/2+1 - (m-B_);
for(int j=1;j<=c;j++){
pii c = *s.begin();
red[c.s] ++,a[i][c.s] = '+';
s.erase(c);
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++)
cout<<a[i][j];
cout<<endl;
}
}
}
Compilation message
stones.cpp:11:2: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
11 | main(){
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
9 ms |
332 KB |
Output is correct |
4 |
Correct |
15 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
165 ms |
1380 KB |
Output is correct |
2 |
Correct |
144 ms |
1852 KB |
Output is correct |
3 |
Correct |
133 ms |
2112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
156 ms |
1328 KB |
Output is correct |
2 |
Correct |
132 ms |
1784 KB |
Output is correct |
3 |
Correct |
119 ms |
1624 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
9 ms |
332 KB |
Output is correct |
4 |
Correct |
15 ms |
332 KB |
Output is correct |
5 |
Correct |
165 ms |
1380 KB |
Output is correct |
6 |
Correct |
144 ms |
1852 KB |
Output is correct |
7 |
Correct |
133 ms |
2112 KB |
Output is correct |
8 |
Correct |
156 ms |
1328 KB |
Output is correct |
9 |
Correct |
132 ms |
1784 KB |
Output is correct |
10 |
Correct |
119 ms |
1624 KB |
Output is correct |
11 |
Correct |
47 ms |
488 KB |
Output is correct |
12 |
Correct |
123 ms |
1852 KB |
Output is correct |
13 |
Correct |
136 ms |
2040 KB |
Output is correct |
14 |
Correct |
100 ms |
1676 KB |
Output is correct |
15 |
Correct |
166 ms |
2240 KB |
Output is correct |
16 |
Correct |
123 ms |
1760 KB |
Output is correct |
17 |
Correct |
50 ms |
1256 KB |
Output is correct |