제출 #898085

#제출 시각아이디문제언어결과실행 시간메모리
898085vjudge1Red-blue table (IZhO19_stones)C++17
38 / 100
769 ms37644 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1e3, X = 24; mt19937 rng(time(nullptr)); int t, n, m, ans, idx, r[N], c[N]; vector<string> a[X*2]; bool bn, bm; int f(int x) { for (int i = 0; i < n; i++) { r[i] = 0; } for (int i = 0; i < m; i++) { c[i] = 0; } for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (a[x][i][j] == '+') r[i]++; else c[j]++; } } int y = 0; for (int i = 0; i < n; i++) { if (bm) y += (r[i] + bm > (m+1)/2); else y += (r[i] > m/2); } for (int i = 0; i < m; i++) { if (bn) y += (c[i] + bn > (n+1)/2); else y += (c[i] > n/2); } return y; } /* void debug(int x) { cout << f(x) << "\n"; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cout << a[x][i][j]; } cout << "\n"; } cout << "\n"; } */ signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> t; while (t--) { bn = bm = 0; cin >> n >> m; ans = 0; // mis 4 construcciones a[0].clear(); a[0].resize(n, string(m, '-')); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (j <= m/2) a[0][i][j] = '+'; } } int y = f(0); if (y > ans) { ans = y; idx = 0; } // --- a[1].clear(); a[1].resize(n, string(m, '+')); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (i <= n/2) a[1][i][j] = '-'; } } y = f(1); if (y > ans) { ans = y; idx = 1; } // --- a[2].clear(); a[2].resize(n, string(m, '+')); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if ((i <= n/2 && j < m/2) || (i >= n/2 && j > m/2)) a[2][i][j] = '-'; } } y = f(2); if (y > ans) { ans = y; idx = 2; } // --- a[3].clear(); a[3].resize(n, string(m, '-')); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if ((i < n/2 && j <= m/2) || (i > n/2 && j >= m/2)) a[3][i][j] = '+'; } } y = f(3); if (y > ans) { ans = y; idx = 3; } // X construcciones random for (int x = 0; x+4 < X; x++) { a[x+4].clear(); a[x+4].resize(n, string(m, '+')); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (rng() % 2) a[x+4][i][j] = '-'; } } int y = f(x+4); if (y > ans) { ans = y; idx = x+4; } } // CASO 2 if (n > 1 && n%2 == 0) { n--; bn = 1; } if (m > 1 && m%2 == 0) { m--; bm = 1; } a[X].clear(); a[X].resize(n, string(m, '-')); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (j <= m/2) a[X][i][j] = '+'; } } y = f(X); if (y > ans) { ans = y; idx = X; } // --- a[X+1].clear(); a[X+1].resize(n, string(m, '+')); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (i <= n/2) a[X+1][i][j] = '-'; } } y = f(X+1); if (y > ans) { ans = y; idx = X+1; } // --- a[X+2].clear(); a[X+2].resize(n, string(m, '+')); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if ((i <= n/2 && j < m/2) || (i >= n/2 && j > m/2)) a[X+2][i][j] = '-'; } } y = f(X+2); if (y > ans) { ans = y; idx = X+2; } // --- a[X+3].clear(); a[X+3].resize(n, string(m, '-')); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if ((i < n/2 && j <= m/2) || (i > n/2 && j >= m/2)) a[X+3][i][j] = '+'; } } y = f(X+3); if (y > ans) { ans = y; idx = X+3; } // X construcciones random for (int x = 0; x+4 < X; x++) { a[X+x+4].clear(); a[X+x+4].resize(n, string(m, '+')); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (rng() % 2) a[X+x+4][i][j] = '-'; } } int y = f(X+x+4); if (y > ans) { ans = y; idx = X+x+4; } } cout << ans << "\n"; for (int i = 0; i < n + (idx < X && bn); i++) { for (int j = 0; j < m + (idx < X && bm); j++) { cout << a[idx][i][j]; } if (bm && idx >= X) cout << '+'; cout << "\n"; } if (bn && idx >= X) { for (int i = 0; i <= m; i++) { cout << '-'; } cout << "\n"; } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...