# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
344072 | Nurlykhan | Red-blue table (IZhO19_stones) | C++17 | 45 ms | 1388 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");
}
}
void tupo() {
if (n <= m) {
bool boo = 1;
int ans = m + 1;
if (n <= 2) {
boo = 0;
ans = m;
}
printf("%d\n", ans);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (boo && i == 0 && j <= m / 2) printf("+");
else printf("-");
}
printf("\n");
}
} else {
bool boo = 1;
int ans = n + 1;
if (m <= 2) {
boo = 0;
ans = n;
}
printf("%d\n", ans);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (boo && i == n - 1 && j <= m / 2) printf("-");
else printf("+");
}
printf("\n");
}
}
}
int main() {
scanf("%d", &t);
while (t--) {
scanf("%d%d", &n, &m);
// printf("Slow:\n");
// solve();
// printf("Tupo:\n");
tupo();
// printf("\n-------------\n");
}
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... |