Submission #1092473

#TimeUsernameProblemLanguageResultExecution timeMemory
1092473juicyRed-blue table (IZhO19_stones)C++17
0 / 100
32 ms1436 KiB
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "debug.h" #else #define debug(...) 42 #endif int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; while (t--) { int n, m; cin >> n >> m; array<int, 2> res{m, 0}; vector<int> cnt(m), ord(m); iota(ord.begin(), ord.end(), 0); int cur = m; auto cmp = [&](int a, int b) -> bool { if (cnt[a] >= n / 2 + 1 && cnt[b] >= n / 2 + 1) { return a < b; } if (cnt[a] >= n / 2 + 1) { return 1; } if (cnt[b] >= n / 2 + 1) { return 0; } return cnt[a] < cnt[b]; }; for (int i = 0; i < n; ++i) { sort(ord.begin(), ord.end(), cmp); for (int j = 0, k = 0; j < m / 2 + 1; ++j) { while (cnt[ord[k]] == n) { ++k; } cur -= ++cnt[ord[k++]] == n / 2 + 1; } res = max(res, {cur + i + 1, i + 1}); } fill(cnt.begin(), cnt.end(), 0); vector a(n, vector<char>(m, '-')); for (int i = 0; i < res[1]; ++i) { sort(ord.begin(), ord.end(), cmp); for (int j = 0, k = 0; j < m / 2 + 1; ++j) { while (cnt[ord[k]] == n) { ++k; } ++cnt[ord[k]]; a[i][ord[k++]] = '+'; } } cout << res[0] << "\n"; for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { cout << a[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...