#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] = {};
int l = 1, i = 1, cnt = n / 2 + 1, cur = 0;
while(i <= m){
if (arr[l] < (m - 1) / 2){
a[l][i] = '-'; arr[l]++; cur++;
}else break;
if (cur % cnt == 0)i++;
if (l == n)l = 1;
else l++;
}
}else {
for (int i = 1; i <= n; i++){
for (int j = 1; j <= m; j++){
a[i][j] = '-';
}
}
int arr[m + 1] = {};
int l = 1, i = 1, cnt = m / 2 + 1, cur = 0;
while(i <= n){
if (arr[l] < (n - 1) / 2){
a[i][l] = '+'; arr[l]++; cur++;
}else break;
if (cur % cnt == 0)i++;
if (l == m)l = 1;
else l++;
}
}
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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
1392 KB |
Output is correct |
2 |
Correct |
23 ms |
1880 KB |
Output is correct |
3 |
Correct |
18 ms |
1884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
1332 KB |
Output is correct |
2 |
Correct |
23 ms |
1520 KB |
Output is correct |
3 |
Correct |
24 ms |
1372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
348 KB |
Output is correct |
5 |
Correct |
27 ms |
1392 KB |
Output is correct |
6 |
Correct |
23 ms |
1880 KB |
Output is correct |
7 |
Correct |
18 ms |
1884 KB |
Output is correct |
8 |
Correct |
24 ms |
1332 KB |
Output is correct |
9 |
Correct |
23 ms |
1520 KB |
Output is correct |
10 |
Correct |
24 ms |
1372 KB |
Output is correct |
11 |
Correct |
5 ms |
604 KB |
Output is correct |
12 |
Correct |
19 ms |
1728 KB |
Output is correct |
13 |
Correct |
17 ms |
1372 KB |
Output is correct |
14 |
Correct |
14 ms |
1116 KB |
Output is correct |
15 |
Correct |
24 ms |
2204 KB |
Output is correct |
16 |
Correct |
16 ms |
1852 KB |
Output is correct |
17 |
Correct |
11 ms |
856 KB |
Output is correct |