Submission #330836

#TimeUsernameProblemLanguageResultExecution timeMemory
330836vitkishloh228Red-blue table (IZhO19_stones)C++14
0 / 100
58 ms1644 KiB
#include<iostream> #include<vector> #include<algorithm> using namespace std; int n, m; int calc(vector<vector<int>>& a) { int cur = 0; for (int i = 0; i < n; ++i) { int x = 0; for (int j = 0; j < m; ++j) { if (a[i][j]) x++; else x--; } if (x > 0) cur++; } for (int j = 0; j < m; ++j) { int x = 0; for (int i = 0; i < n; ++i) { if (a[i][j]) x++; else x--; } if (x < 0) cur++; } return cur; } int main() { int tt; cin >> tt; while (tt--) { cin >> n >> m; if (n == 1) { cout << m << '\n'; for (int i = 0; i < m; ++i) { cout << "-"; } cout << '\n'; continue; } if (m == 1) { cout << n << '\n'; for (int i = 0; i < n; ++i) { cout << "+\n"; } cout << '\n'; continue; } // cout << (n + m - 2 - (1 - n % 2) - (1 - m % 2)) << '\n'; int l; if (m % 2 == 0) l = (m + 2) / 2; else l = (m + 1) / 2; int it = 0; vector<vector<int>> ans(n, vector<int>(m)); vector<int> cnt(m); for (int i = 0; i < n; ++i) { int max1 = 0; for (int j = 0; j < m; ++j) { max1 = max(max1, cnt[j]); } if (n % 2 == 1) { if (max1 >= (n - 1) / 2) break; } else if (max1 >= (n-2) / 2) break; for (int j = 0; j < l; ++j) { ans[i][it] = 1; cnt[it]++; it = (it + 1) % m; } max1 = 0; for (int j = 0; j < m; ++j) { max1 = max(max1, cnt[j]); } if (n % 2 == 1) { if (max1 >= (n - 1) / 2) break; } else if (max1 >= (n-2) / 2) break; } cout << calc(ans) << '\n'; for (auto e : ans) { for (auto u : e) { if (u) cout << "+"; else 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...