Submission #255886

#TimeUsernameProblemLanguageResultExecution timeMemory
255886karmaRed-blue table (IZhO19_stones)C++14
15 / 100
96 ms3084 KiB
#include <bits/stdc++.h> #define pb emplace_back #define ll long long #define fi first #define se second #define mp make_pair //#define int int64_t using namespace std; const int N = int(1e3) + 7; const int inf = 1e9 + 1; typedef pair<ll, ll> pii; int cnt[N], n, m; void solve() { cin >> n >> m; vector<vector<int>> ans(n, vector<int>(m, 0)); priority_queue<pii, vector<pii>, greater<pii>> pq; /// column -, row + fill(cnt, cnt + m, 0); for(int i = 0; i < m; ++i) pq.emplace(0, i); int res = m, num = 0; for(int i = 1; i <= n; ++i) { for(int j = 1; j * 2 <= m; ++j) { auto top = pq.top(); pq.pop(); ++cnt[top.se]; pq.emplace(top.fi + 1, top.se); } auto top = pq.top(); pq.pop(); ++cnt[top.se]; pq.emplace(top.fi + 1, top.se); int tmp = 0; for(int j = 0; j < m; ++j) if(cnt[j] * 2 < n) ++tmp; if(tmp + i > res) res = tmp + i, num = i; } cout << res << '\n'; fill(cnt, cnt + m, 0); for(int i = 0; i < m; ++i) pq.emplace(0, i); for(int i = 0; i < num; ++i) { for(int j = 1; j * 2 <= m; ++j) { auto top = pq.top(); pq.pop(); ++cnt[top.se]; ans[i][top.se] = 1; pq.emplace(top.fi + 1, top.se); } auto top = pq.top(); pq.pop(); ++cnt[top.se]; ans[i][top.se] = 1; pq.emplace(top.fi + 1, top.se); } for(int i = 0; i < n; ++i) { for(int j = 0; j < m; ++j) { cout << (ans[i][j] == 0? '-': '+'); } cout << '\n'; } } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); #define Task "test" if(fopen(Task".inp", "r")) { freopen(Task".inp", "r", stdin); freopen(Task".out", "w", stdout); } int T; cin >> T; while(T --) solve(); }

Compilation message (stderr)

stones.cpp: In function 'int32_t main()':
stones.cpp:66:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen(Task".inp", "r", stdin);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
stones.cpp:67:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen(Task".out", "w", stdout);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...