#pragma GCC optimize("Ofast")
#pragma GCC target ("sse4")
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <vector>
#include <iomanip>
#include <cstring>
#include <limits.h>
#include <iostream>
#include <string.h>
#include <algorithm>
using namespace std;
#define ff first
#define sc second
#define pb push_back
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define ull unsigned long long
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll wmod = 998244353;
#define int long long
void solve(){
int n, m;
cin >> n >> m;
char a[n + 1][m + 1];
if (n >= m){
for (int i = 1; i <= n; i++){
for (int j = 1; j <= m; j++){
a[i][j] = '+';
}
}
int arr[n + 1] = {};
for (int j = 1; j <= m; j++){
int cnt = 0;
for (int i = 1; i <= n; i++)
if (arr[i] < m - arr[i] - 1)cnt++;
if (cnt < n / 2 + 1)break;
cnt = n / 2 + 1;
for (int i = 1; i <= n; i++){
if (arr[i] > m - arr[i])continue;
else if (cnt) {a[i][j] = '-'; arr[i]++; cnt--;}
}
}
}else {
for (int i = 1; i <= n; i++){
for (int j = 1; j <= m; j++){
a[i][j] = '-';
}
}
int arr[m + 1] = {};
for (int i = 1; i <= n; i++){
int cnt = 0;
for (int j = 1; j <= m; j++)
if (arr[j] < n - arr[j] - 1)cnt++;
if (cnt < m / 2 + 1)break;
cnt = m / 2 + 1;
for (int j = 1; j <= m; j++){
if (arr[j] > n - arr[j])continue;
else if (cnt) {a[i][j] = '+'; arr[j]++; cnt--;}
}
}
}
int ans = 0;
for (int i = 1; i <= n; i++){
int cnt = 0;
for (int j = 1; j <= m; j++){
cnt += (a[i][j] == '+');
}
if (cnt > m - cnt)ans++;
}
for (int j = 1; j <= m; j++){
int cnt = 0;
for (int i = 1; i <= n; i++){
cnt += (a[i][j] == '-');
}
if (cnt > n - cnt)ans++;
}
cout << ans << '\n';
for (int i = 1; i <= n; i++){
for (int j = 1; j <= m; j++){
cout << a[i][j];
}cout << '\n';
}
/*
+++++
+++++
+++++
+++++
+++++
+++++
+++++
*/
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
ll T = 1;
cin >> T;
while(T--){
solve();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Wrong answer in test 2 4: 2 < 4 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
352 KB |
Wrong answer in test 20 2: 10 < 20 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Wrong answer in test 2 4: 2 < 4 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
27 ms |
1540 KB |
Wrong answer in test 97 21: 107 < 116 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
19 ms |
1220 KB |
Wrong answer in test 24 24: 23 < 44 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Wrong answer in test 2 4: 2 < 4 |
3 |
Halted |
0 ms |
0 KB |
- |