# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
395743 | ly20 | Red-blue table (IZhO19_stones) | C++17 | 69 ms | 1844 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 MAXN = 1123;
int tb[MAXN][MAXN];
int sl[MAXN], sc[MAXN];
int n, m;
bool teste(int a, int b) {
if(a > n || b > m) return false;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
tb[i][j] = 0;
sl[i] = m;
sc[j] = 0;
}
}
bool ok = true;
for(int i = n; i > n - a; i--) {
for(int j = 1; j <= m; j++) {
tb[i][j] = 1;
sl[i]--;
sc[j]++;
}
}
for(int j = m; j > m - a; j--) {
for(int i = n; i >= 1; i--) {
tb[i][j] = 0;
sl[i]++;
sc[j]--;
}
}
int l = n - a, c = m - b;
int liml = m / 2 + 1, limc = n / 2 + 1;
if(l == 0 || c == 0) return true;
for(int i = 1; i <= l; i++) {
int qtdisp = sl[i] - liml;
for(int j = 1; j <= c; j++) {
if(qtdisp > 0 && sc[j] < limc) {
qtdisp--;
sc[j]++;
tb[i][j] = 1;
sl[i]--;
}
}
}
for(int i = 1; i <= c; i++) if(sc[i] < limc) ok = false;
return ok;
}
int main() {
int t;
scanf("%d", &t);
while(t--) {
scanf("%d %d", &n, &m);
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
tb[i][j] = 0;
sl[i] = m;
sc[j] = 0;
}
}
if(n == 1) {
printf("%d\n", m);
for(int i = 0; i < m; i++) printf("-");
printf("\n");
continue;
}
else if(m == 1) {
printf("%d\n", n);
for(int i = 0; i < n; i++) printf("+\n");
continue;
}
bool ok = false;
int resp = 0;
for(int i = 1; i < 5; i++) {
for(int j = 0; j <= i; j++) {
if(ok) continue;
ok = teste(j, i - j);
if(ok) resp = i;
}
}
printf("%d\n", m + n - resp);
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
if(tb[i][j] == 0) printf("+");
else printf("-");
}
printf("\n");
}
}
}
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... |