# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
344085 | 2021-01-05T06:25:12 Z | Nurlykhan | Red-blue table (IZhO19_stones) | C++17 | 81 ms | 2412 KB |
#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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 364 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 2 ms | 364 KB | Output is correct |
4 | Correct | 4 ms | 364 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 81 ms | 1516 KB | Output is correct |
2 | Correct | 70 ms | 2028 KB | Output is correct |
3 | Correct | 66 ms | 2028 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 70 ms | 1536 KB | Output is correct |
2 | Correct | 69 ms | 1900 KB | Output is correct |
3 | Correct | 58 ms | 1772 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 2 ms | 364 KB | Output is correct |
4 | Correct | 4 ms | 364 KB | Output is correct |
5 | Correct | 81 ms | 1516 KB | Output is correct |
6 | Correct | 70 ms | 2028 KB | Output is correct |
7 | Correct | 66 ms | 2028 KB | Output is correct |
8 | Correct | 70 ms | 1536 KB | Output is correct |
9 | Correct | 69 ms | 1900 KB | Output is correct |
10 | Correct | 58 ms | 1772 KB | Output is correct |
11 | Correct | 17 ms | 748 KB | Output is correct |
12 | Correct | 59 ms | 1644 KB | Output is correct |
13 | Correct | 62 ms | 1644 KB | Output is correct |
14 | Correct | 48 ms | 1388 KB | Output is correct |
15 | Correct | 80 ms | 2412 KB | Output is correct |
16 | Correct | 68 ms | 1900 KB | Output is correct |
17 | Correct | 25 ms | 1132 KB | Output is correct |