//izho gold
#include <bits/stdc++.h>
using namespace std;
#define all(a) a.begin(),a.end()
#define pb push_back
#define vt vector
#define endl '\n'
#define Y second
#define X first
typedef long long ll;
typedef long double ld;
const ll mod=1e9+7;
const ll INF=1e18;
const int inf=1e9;
const int N=2e5+505;
const int M=1e3+10;
const int dx[]={0,0,1,-1};
const int dy[]={1,-1,0,0};
int n,m;
void solve(){
cin>>n>>m;
if(n<=m){
int nd=m/2+1;
char matrix[n+1][m+1];
int l=1;
vt<pair<int,int>>lst;
for(int i=1; i<=n; ++i)for(int j=1; j<=m; ++j)matrix[i][j]='-';
lst.pb({m,0});
for(int i=1; i<=n; ++i){
if(l+nd-1<=m) {
for(int j=l; j<=l+nd-1; ++j) matrix[i][j]='+';
l+=2;
if(l>m) l%=m;
}
if(l+nd-1>m){
for(int j=l; j<=m; ++j) matrix[i][j]='+';
l+=nd;
--l;
l%=m;
for(int j=1; j<=l; ++j)matrix[i][j]='+';
l+=2;
if(l>m)l%=m;
}int cnt=i;
int mn=inf;
for(int j=1; j<=m; ++j){
int cur=0;
for(int x=1; x<=n; ++x)if(matrix[x][j]=='-')++cur;
if(cur>=n/2+1)++cnt;
}lst.pb({cnt,i});
}l=1;
sort(all(lst));
for(int i=1; i<=n; ++i)for(int j=1; j<=m; ++j)matrix[i][j]='-';
for(int i=1; i<=lst.back().Y; ++i){
if(l+nd-1<=m) {
for(int j=l; j<=l+nd-1; ++j) matrix[i][j]='+';
l+=2;
if(l>m) l%=m;
}
if(l+nd-1>m){
for(int j=l; j<=m; ++j) matrix[i][j]='+';
l+=nd;
--l;
l%=m;
for(int j=1; j<=l; ++j)matrix[i][j]='+';
l+=2;
if(l>m)l%=m;
}
}cout<<lst.back().X<<endl;
for(int i=1; i<=n; ++i){
for(int j=1; j<=m; ++j){
cout<<matrix[i][j];
}cout<<endl;
}return;
}cout<<1/0;
}
int main(){
//srand(time(0));
//freopen("hotel.in","r",stdin);
//freopen("hotel.out","w",stdout);
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int tt=1,lolol=0;
cin>>tt;
while(tt--) {
//cout<<"Case "<<++lolol<<": ";
solve();
}
}
Compilation message
stones.cpp: In function 'void solve()':
stones.cpp:48:8: warning: unused variable 'mn' [-Wunused-variable]
48 | int mn=inf;
| ^~
stones.cpp:78:10: warning: division by zero [-Wdiv-by-zero]
78 | }cout<<1/0;
| ~^~
stones.cpp: In function 'int main()':
stones.cpp:86:11: warning: unused variable 'lolol' [-Wunused-variable]
86 | int tt=1,lolol=0;
| ^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
316 KB |
Output is correct |
2 |
Runtime error |
2 ms |
340 KB |
Execution killed with signal 4 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 4 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
316 KB |
Output is correct |
2 |
Runtime error |
2 ms |
340 KB |
Execution killed with signal 4 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
448 KB |
Execution killed with signal 4 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
139 ms |
1236 KB |
Wrong answer in test 24 24: 35 < 44 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
316 KB |
Output is correct |
2 |
Runtime error |
2 ms |
340 KB |
Execution killed with signal 4 |
3 |
Halted |
0 ms |
0 KB |
- |