Submission #308778

#TimeUsernameProblemLanguageResultExecution timeMemory
308778nikatamlianiRed-blue table (IZhO19_stones)C++14
27 / 100
103 ms1328 KiB
#include <bits/stdc++.h> using namespace std; int main() { int T = 1; cin >> T; while(T--) { int n, m; cin >> n >> m; bool swapped = 0; if(n < m) { swap(n, m); swapped = true; } bool ans[n + 1][m + 1]; memset(ans, 0, sizeof ans); set < pair < int, int > > counts; vector < int > good; for(int i = 1; i <= m; ++i) counts.insert({0, i}); for(int i = 1; i <= n; ++i) { int cnt = m / 2 + 1; for(int j : good) { if(cnt == 0)break; cnt--; ans[i][j] = 1; } while(cnt > 0) { auto [x, y] = *counts.begin(); counts.erase(counts.begin()); ++x; if(n - x <= x) { good.push_back(y); } else { counts.insert({x, y}); } ans[i][y] = 1; cnt--; } } vector < int > row(n + 1), col(m + 1); for(int i = 1; i <= n; ++i) { for(int j = 1; j <= m; ++j) { if(ans[i][j]) { ++row[i], --col[j]; } else { --row[i], ++col[j]; } } } int best = 0; for(int i = 1; i <= n; ++i) best += row[i] > 0; for(int i = 1; i <= m; ++i) best += col[i] > 0; cout << best << '\n'; if(!swapped) { for(int i = 1; i <= n; ++i) { for(int j = 1; j <= m; ++j) { cout << (ans[i][j] ? '+' : '-'); } cout << '\n'; } } else { for(int i = 1; i <= m; ++i) { for(int j = 1; j <= n; ++j) { cout << (ans[j][i] ? '-' : '+'); } cout << '\n'; } } } }

Compilation message (stderr)

stones.cpp: In function 'int main()':
stones.cpp:27:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   27 |                 auto [x, y] = *counts.begin();
      |                      ^
#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...