# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
599038 | Plurm | Red-blue table (IZhO19_stones) | C++11 | 6 ms | 1492 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;
char table[1024][1024];
void build(int n, int m) {
if (n % 2 == 0) {
for (int i = 0; i <= n / 2; i++) {
for (int j = 0; j < m; j++) {
table[i][j] = '-';
}
table[i][m] = '\0';
}
for (int i = n / 2 + 1; i < n; i++) {
for (int j = 0; j < m; j++) {
table[i][j] = '+';
}
table[i][m] = '\0';
}
return;
} else if (m % 2 == 0) {
for (int i = 0; i < n; i++) {
for (int j = 0; j <= m / 2; j++) {
table[i][j] = '+';
}
for (int j = m / 2; j < m; j++) {
table[i][j] = '-';
}
table[i][m] = '\0';
}
return;
}
for (int i = 0; i < n / 2; i++) {
for (int j = 0; j < m - 1; j++) {
table[i][j] = j < (m - 1) / 2 ? '-' : '+';
}
table[i][m - 1] = '+';
table[i][m] = '\0';
}
for (int i = n / 2; i < n - 1; i++) {
for (int j = 0; j < m - 1; j++) {
table[i][j] = j < (m - 1) / 2 ? '+' : '-';
}
table[i][m - 1] = '+';
table[i][m] = '\0';
}
for (int j = 0; j < m - 1; j++)
table[n - 1][j] = '-';
table[n - 1][m - 1] = '+';
table[n - 1][m] = '\0';
}
char tmp[1024][1024];
void transpose(int n, int m) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
tmp[j][i] = '+' ^ '-' ^ table[i][j];
}
}
for (int j = 0; j < m; j++)
tmp[j][n] = '\0';
for (int i = 0; i < m; i++) {
strcpy(table[i], tmp[i]);
}
}
int count(int n, int m) {
int cc = 0;
for (int i = 0; i < n; i++) {
int uc = 0;
for (int j = 0; j < m; j++) {
if (table[i][j] == '+')
uc++;
}
if (uc > m - uc)
cc++;
}
for (int j = 0; j < m; j++) {
int uc = 0;
for (int i = 0; i < n; i++) {
if (table[i][j] == '-')
uc++;
}
if (uc > n - uc)
cc++;
}
return cc;
}
int main() {
int t;
scanf("%d", &t);
while (t--) {
int n, m;
scanf("%d%d", &n, &m);
if (n > m) {
build(m, n);
transpose(m, n);
} else {
build(n, m);
}
printf("%d\n", count(n, m));
for (int i = 0; i < n; i++) {
printf("%s\n", table[i]);
}
}
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... |