이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define sz(x) (int)((x).size())
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fr first
#define sc second
#define pw(x) (1ll << x)
#define bcnt(x) (__builtin_popcountll(x))
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
template <typename T> inline bool umax (T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool umin (T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
pair <int, vector <int>> bst;
int N, M;
inline int cost (vector <int> a) {
int res = 0;
for (int i = 0; i < N; ++i) {
int s = 0;
for (int j = 0; j < M; ++j) s += ((a[i] >> j & 1) ? +1 : -1);
res += s > 0;
}
for (int i = 0; i < M; ++i) {
int s = 0;
for (int j = 0; j < N; ++j) s += ((a[j] >> i & 1) ? +1 : -1);
res += s < 0;
}
return res;
}
inline void brute (int n, int m, vector <int> a) {
if (!~n) return void(umax(bst, {cost(a), a}));
for (int j = 0; j < pw(m); ++j) {
a.pb(j); brute(n - 1, m, a);
a.pop_back();
}
}
inline void solve () {
cin >> N >> M;
if (N <= 4 && M <= 4) {
bst.fr = -1;
brute(N, M, vector <int> ());
cout << bst.fr << endl;
for (int i = 0; i < N; ++i) {
for (int j = 0; j < M; ++j) {
cout << ((bst.sc[i] >> j & 1) ? '+' : '-');
}
cout << endl;
}
}
if (N == M) {
cout << N + 1 << endl;
cout << string(N, '+') << endl;
for (int i = 1; i < N; ++i) {
cout << '-' << string(N - 1, '+') << endl;
}
}
}
signed main ()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif // LOCAL
int t = 1; cin >> t;
while (t--) solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |