#include<bits/stdc++.h>
using namespace std;
#define N 1005
int board[N][N],cnt[N];
priority_queue<pair<int,int>> q;
void sol(){
int n,m,nn,mm,ma,ans,a,i,j,cou,flag=false;
scanf("%d %d",&n,&m);
if(n<m)swap(n,m),flag=true;
nn=n/2+1;
mm=m/2+1;
ans=0,ma=a=n;
for(i=1;i<=n;i++){
for(j=1;j<=m;j++)board[i][j]=0;
cnt[i]=m;
}
for(i=1;i<=m;i++){
for(j=1;j<=n;j++){
q.push({cnt[j],j});
}
cou=nn;
while(!q.empty()&&cou>0){
auto [x,y]=q.top();
q.pop();
if(cnt[y]--==mm)a--;
board[y][i]=1;
cou--;
}
if(a+i>ma)ma=a+i,ans=i;
while(!q.empty())q.pop();
}
printf("%d\n",ma);
if(!flag){
for(i=1;i<=n;i++){
for(j=1;j<=m;j++){
if(j<=ans)printf("%c",board[i][j]?'-':'+');
else printf("+");
}
printf("\n");
}
}
else{
for(i=1;i<=m;i++){
for(j=1;j<=n;j++){
if(i<=ans)printf("%c",board[j][i]?'+':'-');
else printf("-");
}
printf("\n");
}
}
}
int main(){
int t;
scanf("%d",&t);
while(t--)sol();
return 0;
}
Compilation message
stones.cpp: In function 'void sol()':
stones.cpp:10:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
10 | scanf("%d %d",&n,&m);
| ~~~~~^~~~~~~~~~~~~~~
stones.cpp: In function 'int main()':
stones.cpp:57:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
57 | scanf("%d",&t);
| ~~~~~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
468 KB |
Output is correct |
4 |
Correct |
4 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
101 ms |
1652 KB |
Output is correct |
2 |
Correct |
125 ms |
4640 KB |
Output is correct |
3 |
Correct |
118 ms |
4872 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
100 ms |
1808 KB |
Output is correct |
2 |
Correct |
102 ms |
3896 KB |
Output is correct |
3 |
Correct |
94 ms |
3236 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
468 KB |
Output is correct |
4 |
Correct |
4 ms |
468 KB |
Output is correct |
5 |
Correct |
101 ms |
1652 KB |
Output is correct |
6 |
Correct |
125 ms |
4640 KB |
Output is correct |
7 |
Correct |
118 ms |
4872 KB |
Output is correct |
8 |
Correct |
100 ms |
1808 KB |
Output is correct |
9 |
Correct |
102 ms |
3896 KB |
Output is correct |
10 |
Correct |
94 ms |
3236 KB |
Output is correct |
11 |
Correct |
27 ms |
616 KB |
Output is correct |
12 |
Correct |
105 ms |
4112 KB |
Output is correct |
13 |
Correct |
122 ms |
4580 KB |
Output is correct |
14 |
Correct |
75 ms |
3892 KB |
Output is correct |
15 |
Correct |
121 ms |
5252 KB |
Output is correct |
16 |
Correct |
90 ms |
4548 KB |
Output is correct |
17 |
Correct |
40 ms |
3240 KB |
Output is correct |