# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
344085 | Nurlykhan | Red-blue table (IZhO19_stones) | C++17 | 81 ms | 2412 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int N = 1024;
int t;
int n, m;
bool a[N][N], ans[N][N];
int cnt() {
int res = 0;
for (int i = 0; i < n; i++) {
int s = 0;
for (int j = 0; j < m; j++) {
if (a[i][j]) s++;
else s--;
}
if (s > 0) res++;
}
for (int j = 0; j < m; j++) {
int s = 0;
for (int i = 0; i < n; i++) {
if (a[i][j]) s++;
else s--;
}
if (s < 0) res++;
}
return res;
}
void solve() {
int mx = 0;
for (int mask = 0; mask < (1 << (n * m)); mask++) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if ((mask >> (i * m + j)) % 2) {
a[i][j] = 1;
} else {
a[i][j] = 0;
}
}
}
int cur = cnt();
if (cur > mx) {
mx = cur;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
ans[i][j] = a[i][j];
}
}
}
}
printf("%d\n", mx);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (ans[i][j])
printf("+");
else
printf("-");
}
printf("\n");
}
}
int s[N];
void tupo() {
bool boo = 0;
if (n > m) {
swap(n, m);
boo = 1;
}
int ans = m;
for (int j = 0; j < m; j++) {
s[j] = -n;
}
for (int i = 0; i < n; i++) {
vector<pair<int, int> > v;
for (int j = 0; j < m; j++) {
a[i][j] = 0;
v.push_back(make_pair(s[j], j));
}
sort(v.begin(), v.end());
bool ok = 1;
for (int j = 0; j < m / 2 + 1; j++) {
if (v[j].first + 2 >= 0) ok = 0;
}
if (ok) {
ans++;
for (int j = 0; j < m / 2 + 1; j++) {
s[v[j].second] += 2;
a[i][v[j].second] = 1;
}
}
}
printf("%d\n", ans);
if (boo) {
for (int j = 0; j < m; j++) {
for (int i = 0; i < n; i++) {
if (!a[i][j]) printf("+");
else printf("-");
}
printf("\n");
}
} else {
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (a[i][j]) printf("+");
else printf("-");
}
printf("\n");
}
}
}
int main() {
scanf("%d", &t);
while (t--) {
scanf("%d%d", &n, &m);
tupo();
}
return 0;
}
Compilation message (stderr)
# | 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... |