#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x) cerr<< #x <<" = "<< x<<endl;
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
const int N=1e3+4;
char res[N][N];
int main(){
//freopen("file.in", "r", stdin);
int t=1;
scanf("%d",&t);
while(t--){
int n,m;
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
res[i][j]='-';
int ans=m,x=(m-1)/2,y=n/2+1,a=0,b=m;
for(int A=1;A<=n;A++){
if(y-(n-A)>0){
int B=(A*x)/(y-(n-A));
if(umax(ans,A+B))
a=A,b=B;
//printf("%d %d\n",A,B);
}
else{
ans=A+m;
a=A;b=m;
}
}
printf("%d\n",ans);
priority_queue<PII>q;
for(int i=1;i<=b;i++)
q.push(mp((n-1)/2,i));
for(int i=b+1;i<=m;i++)
q.push(mp(n,i));
for(int i=1;i<=a;i++)
for(int j=0;j<=m/2;j++){
PII nd=q.top();q.pop();
assert(nd.ff>0);
res[i][nd.ss]='+';
q.push(mp(nd.ff-1,nd.ss));
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++)
printf("%c",res[i][j]);
puts("");
}
}
return 0;
}
Compilation message
stones.cpp: In function 'int main()':
stones.cpp:25:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
25 | scanf("%d",&t);
| ~~~~~^~~~~~~~~
stones.cpp:28:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
28 | scanf("%d%d",&n,&m);
| ~~~~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
364 KB |
in the table A+B is not equal to 28 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Incorrect |
2 ms |
364 KB |
in the table A+B is not equal to 28 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
89 ms |
1516 KB |
in the table A+B is not equal to 539 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
88 ms |
1644 KB |
in the table A+B is not equal to 144 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Incorrect |
2 ms |
364 KB |
in the table A+B is not equal to 28 |