Submission #1288614

#TimeUsernameProblemLanguageResultExecution timeMemory
1288614azamuraiRed-blue table (IZhO19_stones)C++20
42 / 100
141 ms11584 KiB
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define mp make_pair #define pb push_back #define Sz(x) (int)x.size() const int N = 1005; const int ogr = 50; int n, m, cnt[N], used[N]; char a[N][N]; int calc() { int res = 0; for (int i = 1; i <= n; i++) { int blue = 0, red = 0; for (int j = 1; j <= m; j++) { if (a[i][j] == '-') blue++; else red++; } if (red > blue) res++; } for (int j = 1; j <= m; j++) { int blue = 0, red = 0; for (int i = 1; i <= n; i++) { if (a[i][j] == '-') blue++; else red++; } if (blue > red) res++; } return res; } void solve() { cin >> n >> m; int mx = 0; vector <pair<int,pair<int,int>>> maybe; for (int cntx = 0; cntx <= n; cntx++) { for (int cnty = 0; cnty <= m; cnty++) { int red = cntx * ((m + 2) / 2); int blue = cnty * ((n + 2) / 2); if (red + blue <= n * m) { maybe.push_back(mp(cntx + cnty, mp(cntx, cnty))); } } } sort(maybe.begin(), maybe.end()); reverse(maybe.begin(), maybe.end()); int need_y = (n + 2) / 2; int need_x = (m + 2) / 2; for (int i = 0; i < min(Sz(maybe), ogr); i++) { pair <int,int> to = maybe[i].se; int Cntx = to.fi; int Cnty = to.se; int predict = maybe[i].fi; for (int i = 1; i <= n; i++ ) { for (int j = 1; j <= m; j++) { a[i][j] = '0'; cnt[j] = 0; used[j] = 0; } } for (int i = 1; i <= Cntx; i++) { int amount = 0; for (int j = 1; j <= m; j++) { used[j] = 0; } for (int j = 1; j <= m; j++) { if (amount == need_x) break; if ((n - cnt[j]) < need_y) { amount++; cnt[j]++; used[j] = 1; a[i][j] = '+'; } } if (amount == need_x) continue; vector <pair<int,int>> save; for (int j = 1; j <= m; j++) { if (used[j] || (n - cnt[j]) <= need_y) continue; save.push_back(mp(cnt[j], j)); } sort(save.begin(), save.end()); for (auto to : save) { if (amount == need_x) break; amount++; cnt[to.se]++; used[to.se] = 1; a[i][to.se] = '+'; } if (amount == need_x) continue; for (int j = 1; j <= m; j++) { if (used[j] || (n - cnt[j]) != need_y || amount == need_x) continue; amount++; cnt[j]++; used[j] = 1; a[i][j] = '+'; } } for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (a[i][j] == '0') a[i][j] = '-'; } } if (calc() == predict) { cout << predict << '\n'; break; } } for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { cout << a[i][j]; } cout << '\n'; } } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); int t = 1; cin >> t; for (int T = 1; T <= t; T++) { solve(); //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...