#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))
template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }
void solve(){
int n, m;
cin >> n >> m;
int ans = n; //do the rows
vi cn(n, 0); //capacity of each row
rep(i, n) cn[i] = (m - 1) / 2;
char res[n + 1][m + 1];
rep(i, n) rep(j, m) res[i][j] = '+';
rep(j, m){
int need = (n + 2) / 2; //how many need to be changed
rep(i, n){
if(!need) break;
else if(cn[i]) cn[i]--, need--, res[i][j] = '-';
}
if(!need) ans++;
else break;
}
int ans1 = m;
vi cn1(m, 0);
rep(i, m) cn1[i] = (n - 1) / 2;
char res1[n + 1][m + 1];
rep(i, n) rep(j, m) res1[i][j] = '-';
rep(i, n){
int need = (m + 2) / 2; //how many need to be changed
rep(j, m){
if(!need) break;
else if(cn1[j]) cn1[j]--, need--, res1[i][j] = '+';
}
if(!need) ans1++;
else break;
}
if(ans > ans1){
cout << ans << endl;
rep(i, n){
rep(j, m) cout << res[i][j];
cout << endl;
}
}
else{
cout << ans1 << endl;
rep(i, n){
rep(j, m) cout << res1[i][j];
cout << endl;
}
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
//freopen("input.in", "r", stdin);
//freopen("output.out", "w", stdout);
int t;
cin >> t;
while(t--) solve();
return 0;
}
/*
Things to look out for:
- Integer overflows
- Array bounds
- Special cases
Be careful!
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
14 ms |
280 KB |
Output is correct |
4 |
Incorrect |
20 ms |
384 KB |
Wrong answer in test 5 29: 31 < 32 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
69 ms |
1400 KB |
Wrong answer in test 97 21: 107 < 116 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
49 ms |
1400 KB |
Wrong answer in test 24 24: 35 < 44 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
14 ms |
280 KB |
Output is correct |
4 |
Incorrect |
20 ms |
384 KB |
Wrong answer in test 5 29: 31 < 32 |