#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> bool chkmax(T &x,T y){return x<y?x=y,1:0;}
template<typename T> bool chkmin(T &x,T y){return x>y?x=y,1:0;}
int n,m,row[1000005],ord[1000005];
void solve(){
scanf("%d%d",&n,&m);
int bst=n,ty=0;
vector<vector<char>> ans(n+1,vector<char>(m+1,'+'));
vector<vector<char>> tmp(n+1,vector<char>(m+1,'+'));
for(int i=1;i<=n;i++)row[i]=m;
for(int j=1;j<=m;j++){
for(int i=1;i<=n;i++)ord[i]=i;
sort(ord+1,ord+n+1,[&](int x,int y){
bool isx=(row[x]<=m-row[x]);
bool isy=(row[y]<=m-row[y]);
return isx>isy||(isx==isy&&row[x]>row[y]);
});
int tc=n/2+1;
for(int i=1;i<=tc;i++)tmp[ord[i]][j]='-',row[ord[i]]--;
int cur=j;
for(int i=1;i<=n;i++)if(row[i]>m-row[i])cur++;
if(cur>bst){
for(int r=ty+1;r<=j;r++)for(int i=1;i<=n;i++)ans[i][r]=tmp[i][r];
bst=cur,ty=j;
}
}
printf("%d\n",bst);
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++)printf("%c",ans[i][j]);
printf("\n");
}
}
int main(){
int T;
scanf("%d",&T);
while(T--)solve();
return 0;
}
Compilation message
stones.cpp: In function 'void solve()':
stones.cpp:21:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
21 | scanf("%d%d",&n,&m);
| ~~~~~^~~~~~~~~~~~~~
stones.cpp: In function 'int main()':
stones.cpp:51:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
51 | scanf("%d",&T);
| ~~~~~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Incorrect |
4 ms |
340 KB |
Wrong answer in test 5 29: 31 < 32 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
65 ms |
1356 KB |
Wrong answer in test 23 57: 76 < 78 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
62 ms |
1480 KB |
Output is correct |
2 |
Correct |
63 ms |
1880 KB |
Output is correct |
3 |
Correct |
47 ms |
1652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Incorrect |
4 ms |
340 KB |
Wrong answer in test 5 29: 31 < 32 |
5 |
Halted |
0 ms |
0 KB |
- |