Submission #599050

#TimeUsernameProblemLanguageResultExecution timeMemory
599050JomnoiRed-blue table (IZhO19_stones)C++17
100 / 100
65 ms5160 KiB
#include <bits/stdc++.h> using namespace std; const int MAX_N = 1005; int cnt1[MAX_N]; int b[MAX_N][MAX_N]; // 1 '+' red // 0 '-' blue void solve(int N, int M) { if(N >= M) { for(int i = 0; i < N; i++) { for(int j = 0; j < M; j++) { b[i][j] = 1; } cnt1[i] = M; } int A = N, maxab = N, to = -1; for(int j = 0; j < M; j++) { priority_queue <pair <int, int>> pq; for(int i = 0; i < N; i++) { pq.emplace(cnt1[i], i); } int cnt = N / 2 + 1; while(cnt--) { auto [cn, i] = pq.top(); pq.pop(); if(cnt1[i]-- == M / 2 + 1) { A--; } b[i][j] = 0; } if(maxab < A + j + 1) { maxab = A + j + 1; to = j; } } cout << maxab << '\n'; for(int i = 0; i < N; i++) { for(int j = 0; j < M; j++) { if(j <= to) { cout << (b[i][j] == 1 ? '+' : '-'); } else { cout << '+'; } } cout << '\n'; } } else { for(int i = 0; i < N; i++) { for(int j = 0; j < M; j++) { b[i][j] = 1; cnt1[j] = N; } } int B = M, maxab = M, to = -1; for(int i = 0; i < N; i++) { priority_queue <pair <int, int>> pq; for(int j = 0; j < M; j++) { pq.emplace(cnt1[j], j); } int cnt = M / 2 + 1; while(cnt--) { auto [cn, j] = pq.top(); pq.pop(); if(cnt1[j]-- == N / 2 + 1) { B--; } b[i][j] = 0; } if(maxab < B + i + 1) { maxab = B + i + 1; to = i; } } cout << maxab << '\n'; for(int i = 0; i < N; i++) { for(int j = 0; j < M; j++) { if(i <= to) { cout << (b[i][j] == 1 ? '-' : '+'); } else { cout << '-'; } } cout << '\n'; } } } int main() { cin.tie(nullptr)->sync_with_stdio(false); int T; cin >> T; while(T--) { int N, M; cin >> N >> M; solve(N, M); } 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...