제출 #898287

#제출 시각아이디문제언어결과실행 시간메모리
898287vjudge1Red-blue table (IZhO19_stones)C++17
54 / 100
1272 ms3372 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]; string b[3]; int f() { 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; 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) / 2 / 2 * 3 + ((m-1)/2 % 2 ? 1 : 0); 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(); if (x > ans) { ans = x; swap(a[0], a[1]); } 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] = '+'; } x = (n-1) / 2 / 2 * 3 + ((n-1)/2 % 2 ? 1 : 0); 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(); if (x > ans) { ans = x; swap(a[0], a[1]); } for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { a[1][i][j] = '+'; } } 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[1][i][j] = '-'; } } x = f(); if (x > ans) { ans = x; swap(a[0], a[1]); } for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { a[1][i][j] = '+'; } } 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[1][i][j] = '+'; } } x = f(); 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...