Submission #586435

#TimeUsernameProblemLanguageResultExecution timeMemory
586435blueRed-blue table (IZhO19_stones)C++17
100 / 100
23 ms2352 KiB
#include <iostream> #include <vector> #include <algorithm> using namespace std; using vi = vector<int>; using vvi = vector<vi>; vi ct; int main() { int T; cin >> T; for(int t = 1; t <= T; t++) { int N, M; cin >> N >> M; int A = 0, B = 0; // cerr << "1\n"; if(N > M) { A = N; } else B = M; for(int a = 1; a <= N; a++) { for(int b = 1; b <= M; b++) { int redperrow = M/2 + 1; int lostcols = M - b; int remred = max(0, redperrow - lostcols); int totalred = remred * a; int z = totalred/b + bool(totalred % b); // cerr << a << ' ' << b << " : " << redperrow << ' ' << lostcols << "\n"; if(z < N - z) { if(a+b > A+B) { A = a; B = b; } } } } // cerr << "2\n"; // cout << A << ' ' << B << '\n'; cout << A+B << '\n'; vector<string> res(N, string(M, '-')); int redperrow = M/2 + 1; ct = vi(M, 0); for(int a = 0; a < A; a++) { for(int x = 0; x < min(M - B, redperrow); x++) { res[a][x] = '+'; } int rem = redperrow - min(M - B, redperrow); vi I; for(int j = M - B; j < M; j++) I.push_back(j); sort(I.begin(), I.end(), [] (int u, int v) { return ct[u] < ct[v]; }); for(int q = 0; q < rem; q++) { ct[I[q]]++; res[a][I[q]] = '+'; } } for(int i = 0; i < N; i++) cout << res[i] << '\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...