Submission #761457

#TimeUsernameProblemLanguageResultExecution timeMemory
761457NK_Red-blue table (IZhO19_stones)C++17
100 / 100
46 ms2524 KiB
// Success consists of going from failure to failure without loss of enthusiasm #include <bits/stdc++.h> using namespace std; #define nl '\n' template<class T> using V = vector<T>; using str = string; void solve() { int N, M; cin >> N >> M; bool SWAP = 0; if (N < M) { swap(N, M); SWAP = 1; } // WLOG N > M int have = (M - 1) / 2; int need = (N / 2) + 1; // cout << N << " : " << M << endl; // cout << have << " - " << need << endl; int can = (have * N) / need; // cout << have * N << " - " << need << endl; int ans = min(M, can) + N; //?????? V<str> A(N, str(M, '+')); set<pair<int, int>> S; for(int i = 0; i < N; i++) S.insert(make_pair(have, i)); for(int c = 0; c < can; c++) { V<pair<int, int>> add; for(int t = 0; t < need; t++) { if (size(S) == 0) assert(false); int amt, i; tie(amt, i) = *rbegin(S); // cout << amt << " " << i << endl; S.erase(prev(end(S))); A[i][c] = '-'; amt--; if (amt > 0) add.push_back(make_pair(amt, i)); } for(auto p : add) S.insert(p); } // for(auto x : A) cout << x << nl; if (SWAP) { V<str> B(M, str(N, '_')); for(int r = 0; r < N; r++) for(int c = 0; c < M; c++) { B[c][r] = '+' + '-' - A[r][c]; } A.swap(B); swap(N, M); } cout << ans << nl; for(auto x : A) cout << x << nl; auto checker = [&]() { int ANS = 0; for(int r = 0; r < N; r++) { int x = 0; for(int c = 0; c < M; c++) x += (A[r][c] == '+'); if (x > (M - x)) ANS++; } for(int c = 0; c < M; c++) { int x = 0; for(int r = 0; r < N; r++) x += (A[r][c] == '-'); if (x > (N - x)) ANS++; } // cout << ANS << endl; if (ANS != ans) { cout << N << " <--> " << M << endl; assert(false); } assert(ANS == ans); }; checker(); } int main() { cin.tie(0)->sync_with_stdio(0); int T; cin >> T; while(T--) solve(); 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...