Submission #898276

#TimeUsernameProblemLanguageResultExecution timeMemory
898276vjudge1Red-blue table (IZhO19_stones)C++17
0 / 100
548 ms3428 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1e3; int t, n, m, ans, r[N], c[N]; char a[2][N][N]; 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[1][i][j] == '+') r[i]++; else c[j]++; } } int y = 0; for (int i = 0; i < n; i++) { y += (r[i] > m/2); } for (int i = 0; i < m; i++) { y += (c[i] > n/2); } return y; } signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> t; while (t--) { cin >> n >> m; ans = 0; if (n > m) { string b[3]; b[0].clear(); b[0].resize(n, '+'); for (int i = 0; i <= n/2; i++) { b[0][i] = '-'; } b[1].clear(); b[1].resize(n, '+'); for (int i = 0; i <= n/2; i++) { b[1][n-1-i] = '-'; } b[2].clear(); b[2].resize(n, '+'); for (int i = 0; i <= n/4; i++) { b[2][i] = '-'; b[2][n-1-i] = '-'; } int x = (m-1)/4 * 3; for (int i = 0; i <= n; i++) { for (int j = 0; j < m-x; j++) { a[1][i][j] = '+'; } int curr = 0; for (int j = m-x; j < m; j++) { a[1][i][j] = b[curr][i]; curr = (curr+1) % 3; } } x = f(1); if (x > ans) { ans = x; swap(a[0], a[1]); } } else { string b[3]; b[0].clear(); b[0].resize(m, '-'); for (int i = 0; i <= m/2; i++) { b[0][i] = '+'; } b[1].clear(); b[1].resize(m, '-'); for (int i = 0; i <= m/2; i++) { b[1][m-1-i] = '+'; } b[2].clear(); b[2].resize(m, '-'); for (int i = 0; i <= m/4; i++) { b[2][i] = '+'; b[2][m-1-i] = '+'; } int x = (n-1)/4 * 3; for (int j = 0; j <= m; j++) { for (int i = 0; i < n-x; i++) { a[1][i][j] = '-'; } int curr = 0; for (int i = n-x; i < n; i++) { a[1][i][j] = b[curr][j]; curr = (curr+1) % 3; } } x = f(1); if (x > ans) { ans = x; swap(a[0], a[1]); } } cout << ans << "\n"; for (int i = 0; i <= n; i++) { for (int j = 0; j < m; j++) { cout << a[0][i][j]; } cout << "\n"; } /* if (n%2 == 0 && m%2 == 0) { } else if (n%2 == 0 && m%2 == 1) { } else if (n%2 == 1 && m%2 == 0) { } else if (n%2 == 1 && m%2 == 1) { } */ } } /* --++++ ++--++ ++++-- ------ ------ --++++ ----++ ------ ++---- ++++-- */
#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...