Submission #972399

#TimeUsernameProblemLanguageResultExecution timeMemory
972399colossal_pepeRed-blue table (IZhO19_stones)C++17
100 / 100
633 ms1768 KiB
#include <bits/stdc++.h> using namespace std; int t, n, m; void rotate(vector<vector<bool>> &v) { int nv = v.size(), mv = v[0].size(); vector<vector<bool>> vp(mv, vector<bool>(nv)); for (int i = 0; i < nv; i++) { for (int j = 0; j < mv; j++) { vp[j][i] = !v[i][j]; } } v = vp; } int solve(int nv, int mv, vector<vector<bool>> &v) { auto ok = [nv, mv, &v](int save) { vector<int> cnt(save, nv); priority_queue<pair<int, int>> pq; for (int i = 0; i < save; i++) { pq.push(make_pair(cnt[i], i)); } int plus = (mv / 2) + 1 - (mv - save); for (int i = 0; i < nv; i++) { for (int j = 0; j < mv; j++) { v[i][j] = (j >= save); } for (int _ = 1; _ <= plus; _++) { auto [__, j] = pq.top(); pq.pop(); v[i][j] = 1; pq.push(make_pair(--cnt[j], j)); } } bool ret = 1; for (int x : cnt) { ret &= (x > nv / 2); } return ret; }; int lo = 0, hi = mv; while (hi - lo > 1) { int mid = (lo + hi) / 2; if (ok(mid)) lo = mid; else hi = mid - 1; } if (ok(hi)) return nv + hi; ok(lo); return nv + lo; } int main() { cin >> t; while (t--) { cin >> n >> m; vector<vector<bool>> org(n, vector<bool>(m)); int goodA = solve(n, m, org); vector<vector<bool>> alt(m, vector<bool>(n)); int goodB = solve(m, n, alt); if (goodA < goodB) { swap(goodA, goodB); rotate(alt); swap(alt, org); } cout << goodA << '\n'; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cout << (org[i][j] ? '+' : '-'); } cout << '\n'; } } return 0; }
#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...