제출 #173778

#제출 시각아이디문제언어결과실행 시간메모리
173778emil_physmathRed-blue table (IZhO19_stones)C++17
27 / 100
14 ms1400 KiB
#include <algorithm> #include <iostream> #include <vector> #include <string> using namespace std; void Solve12(int n, int m) { if (m <= 2 && n > m) { cout << n << '\n'; for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) cout << "+"; cout << '\n'; } } else if (n <= 2) { cout << m << '\n'; for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) cout << "-"; cout << '\n'; } } } int Value(const vector<string>& a) { int n = a.size(); int m = a[0].length(); int res = 0; for (int i = 0; i < n; ++i) if (2 * count(a[i].begin(), a[i].end(), '+') > m) ++res; for (int j = 0; j < m; ++j) { int cnt = 0; for (int i = 0; i < n; ++i) if (a[i][j] == '-') ++cnt; if (2 * cnt > n) ++res; } return res; } bool SolveEvens(int n, int m) { bool f = n < m; if (f) swap(n, m); vector<string> a(n, string(m, '-')); for (int i = 0; i < n; ++i) for (int j = m - 3; j < m; ++j) a[i][j] = '+'; int block = (m / 2 + 1 - 3); int j = m - 4; for (int i = n - 1; i >= 0; --i) { for (int cnt = 0; cnt < block; ++cnt) a[i][(j - cnt + m - 3) % (m - 3)] = '+'; j = (j - block + m - 3) % (m - 3); } if (f) { for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) a[i][j] = (a[i][j] == '-' ? '+' : '-'); swap(n, m); vector<string> temp(m, string(m, '-')); for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) temp[i][j] = a[j][i]; a.swap(temp); } int value; if ((value = Value(a)) < n + m - 4) return false; cout << Value(a) << '\n'; for (int i = 0; i < n; ++i) cout << a[i] << '\n'; cout << flush; return true; } void SolveUpTo5(int n, int m) { vector<string> a(n, string(m, '-')); if (m <= 5 && n > m) { for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) a[i][j] = (j < m / 2 ? '-' : '+'); // a[i][1] = a[i][2] = '+'; } else { for (int j = 0; j < m; ++j) { for (int i = 0; i < n; ++i) a[i][j] = (i < n / 2 ? '+' : '-'); // a[1][j] = a[2][j] = '-'; } } cout << Value(a) << '\n'; for (int i = 0; i < n; ++i) cout << a[i] << '\n'; cout << flush; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int t; cin >> t; while (t--) { int n, m; cin >> n >> m; if (min(n, m) <= 2) { Solve12(n, m); continue; } if (n % 2 == 0 && m % 2 == 0) if (SolveEvens(n, m)) continue; if (n == 3 || n == 5 || m == 3 || m == 5) { SolveUpTo5(n, m); continue; } vector<string> a(n, string(m, '+')); for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) a[i][j] = ((i + j) % 2 ? '+' : '-'); for (int i = 0; i < n; ++i) for (int j = m - 1 - (m + 1) % 2; j < m; ++j) a[i][j] = '+'; for (int j = 0; j < m; ++j) for (int i = n - 1 - (n + 1) % 2; i < n; ++i) a[i][j] = '-'; cout << Value(a) << '\n'; for (int i = 0; i < n; ++i) cout << a[i] << '\n'; cout << flush; } }
#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...