Submission #672231

#TimeUsernameProblemLanguageResultExecution timeMemory
672231YENGOYANRed-blue table (IZhO19_stones)C++17
38 / 100
64 ms3532 KiB
#include <bits/stdc++.h> using namespace std; int calc(vector<string> &v, int n, int m){ int cnt = 0; for(int i = 0; i < n; i++){ int a = 0, b= 0 ; for(int j = 0; j < m; j++){ if(v[i][j] == '+') a++; else b++; } cnt += (a > b); } for(int j = 0; j < m; j++){ int a = 0, b = 0; for(int i = 0; i < n; i++){ if(v[i][j] == '-') a++; else b++; } cnt += (a > b); } return cnt; } void printVec(vector<string> &v, int n, int m){ for(int i = 0; i < n; i++){ for(int j = 0; j < m; j++){ cout << v[i][j]; } cout << endl; } } vector<string> rev(vector<string> v, int n, int m){ vector<string> a(m); for(int i = 0; i < n; ++i){ for(int j = m - 1; j >= 0; --j){ if(v[i][j] == '+') a[m - j - 1].push_back('-'); else a[m - j - 1].push_back('+'); } } return a; } void GarniGeghard(int n, int m){ if (n + (m + 1) / 2 - 1 > m + (n + 1) / 2 - 1) { cout << n + (m + 1) / 2 - 1 << endl; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (j <= m / 2 + 1) cout << '+'; else cout << '-'; } cout << "\n"; } } else { cout << m + (n + 1) / 2 - 1 << endl; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (i <= n / 2 + 1) cout << '-'; else cout << '+'; } cout << "\n"; } } } void solve(){ int n, m; cin >> n >> m; bool r = 0; if (min(m, n) <= 3 || (n <= 4 && m <= 4)) { GarniGeghard(n, m); return; } if(n > m){ swap(n, m); r = 1; } vector<string> v(n); string s(m, '-'); v[0] = s; if(n % 2 == 0 && n > 1) v[1] = s; string a(m / 2 + 1, '+'), b(m - (m / 2 + 1), '-'); for(int i = 1 + (1 - (n % 2)); i < n; i++){ if(i % 2) v[i] = a + b; else v[i] = b + a; } if(r){ v = rev(v, n, m); swap(n, m); } int res = calc(v, n, m); if(res < max(n + (m + 1) / 2 - 1, m + (n + 1) / 2 - 1)){ GarniGeghard(n, m); return; } cout << calc(v, n, m) << endl; // if(!r) printVec(v, n, m); printVec(v, n, m); } int main(){ int t; cin >> t; while(t--) solve(); }
#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...