#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld; // typedef double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<ld> vd;
typedef vector<vd> vvd;
typedef complex<ld> cd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef string str;
#define int ll
template<class A, class B>
inline bool mmin(A& a, B b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
template<class A, class B>
inline bool mmax(A& a, B b) {
if (b > a) {
a = b;
return 1;
}
return 0;
}
ld nxt_ld() {
string s;
cin >> s;
return stold(s);
}
#define x first
#define y second
#define pb push_back
#define eb emplace_back
#define pf push_front
#define ef emplace_front
#define ppb pop_back
#define ppf pop_front
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
int getans(vvc a) {
int n = sz(a), m = sz(a[0]);
int ans = 0;
for (int i = 0; i < n; i++) {
int bal = 0;
for (int j = 0; j < m; j++) {
if (a[i][j] == '+') bal++; else bal--;
}
if (bal > 0) ans++;
}
for (int j = 0; j < m; j++) {
int bal = 0;
for (int i = 0; i < n; i++) {
if (a[i][j] == '-') bal++; else bal--;
}
if (bal > 0) ans++;
}
return ans;
}
signed main() {
/*freopen("cbarn.in", "r", stdin);
freopen("cbran.out", "w", stdout);*/
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
if ((n & 1) && (m & 1)) {
vvc a(n, vc(m, '-'));
for (int i = 1; i < n; i += 2) fill(all(a[i]), '+');
vvc b(n, vc(m, '+'));
for (int j = 1; j < m; j += 2) {
for (int i = 0; i < n; i++) b[i][j] = '-';
}
vvc ans = getans(a) > getans(b) ? a : b;
cout << getans(ans) << '\n';
for (auto x : ans) {
for (auto y : x) cout << y;
cout << '\n';
}
} else {
vvc ans(n, vc(m, '+'));
for (int mask = 0; mask < (1 << (n * m)); mask++) {
vvc q(n, vc(m));
int z = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) q[i][j] = ((mask >> z++) & 1) ? '+' : '-';
}
if (getans(q) > getans(ans)) ans = q;
}
cout << getans(ans) << '\n';
for (auto x : ans) {
for (auto y : x) cout << y;
cout << '\n';
}
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
64 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2085 ms |
384 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
64 ms |
384 KB |
Output is correct |
3 |
Execution timed out |
2085 ms |
384 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
48 ms |
1400 KB |
Wrong answer in test 97 21: 107 < 116 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2083 ms |
308 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
64 ms |
384 KB |
Output is correct |
3 |
Execution timed out |
2085 ms |
384 KB |
Time limit exceeded |