#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC opimize(-O3)
//#pragma GCC opimize(Ofast)
//#pragma GCC opimize(unroll-loops)
//#pragma GCC target("avx,avx2,popcnt,sse,sse2,sse3,sse4,abm,tune=native")
#define m_p make_pair
#define vec vector
#define all(x) x.begin(),x.end()
#define pb push_back
#define sz(x) (int)x.size()
#define pw(x) (1LL<<x)
#define f first
#define s second
using namespace std;
using namespace __gnu_pbds;
typedef long double ld;
typedef pair<int,int> pii;
int getneed(int x){
int w=x/2;
return w+1;
}
pair<vec<vec<char>>,int>solve(int n,int m){
vec<vec<char>>a(n,vec<char>(m,'-'));
int ans=n;
vec<pii>st;
for(int i=0;i<n;i++){
if(m-getneed(m))st.pb({m-getneed(m),i});
}
for(int i=0;i<m;i++){
vec<pii>del;
int ok=1;
for(int j=0;j<getneed(n);j++){
if(!sz(st)){
ok=0;
break;
}
pii w=st.back();st.pop_back();
a[w.s][i]='+';
w.f--;
if(w.f) del.pb(w);
}
for(auto &z : del) st.pb(z);
sort(all(st));
ans+=ok;
}
return {a,ans};
}
map<char,int>op;
signed main()
{
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int t;
cin>>t;
op['+']='-';
op['-']='+';
while(t--){
int n,m;
cin>>n>>m;
// vec<vec<char>>a(n,vec<char>(m,'+'));
auto f=solve(n,m),s=solve(m,n);
// cerr<<f.s<<' '<<s.s<<endl;
cout<<max(f.s,s.s)<<'\n';
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(f.s>s.s)
cout<<(char)op[f.f[i][j]];
else
cout<<s.f[j][i];
}
cout<<'\n';
}
}
return 0;
}
/*
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
6 ms |
396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
83 ms |
1348 KB |
Output is correct |
2 |
Correct |
81 ms |
2956 KB |
Output is correct |
3 |
Correct |
77 ms |
3392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
90 ms |
1444 KB |
Output is correct |
2 |
Correct |
84 ms |
2500 KB |
Output is correct |
3 |
Correct |
81 ms |
1924 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
6 ms |
396 KB |
Output is correct |
5 |
Correct |
83 ms |
1348 KB |
Output is correct |
6 |
Correct |
81 ms |
2956 KB |
Output is correct |
7 |
Correct |
77 ms |
3392 KB |
Output is correct |
8 |
Correct |
90 ms |
1444 KB |
Output is correct |
9 |
Correct |
84 ms |
2500 KB |
Output is correct |
10 |
Correct |
81 ms |
1924 KB |
Output is correct |
11 |
Correct |
19 ms |
588 KB |
Output is correct |
12 |
Correct |
68 ms |
2388 KB |
Output is correct |
13 |
Correct |
81 ms |
1840 KB |
Output is correct |
14 |
Correct |
64 ms |
1300 KB |
Output is correct |
15 |
Correct |
132 ms |
4292 KB |
Output is correct |
16 |
Correct |
97 ms |
3244 KB |
Output is correct |
17 |
Correct |
35 ms |
1604 KB |
Output is correct |