Submission #255886

# Submission time Handle Problem Language Result Execution time Memory
255886 2020-08-02T04:01:38 Z karma Red-blue table (IZhO19_stones) C++14
15 / 100
96 ms 3084 KB
#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

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 time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Incorrect 0 ms 384 KB Wrong answer in test 4 3: 4 < 5
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB Wrong answer in test 4 3: 4 < 5
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Incorrect 0 ms 384 KB Wrong answer in test 4 3: 4 < 5
# Verdict Execution time Memory Grader output
1 Incorrect 96 ms 1400 KB Wrong answer in test 97 21: 112 < 116
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 93 ms 1448 KB Output is correct
2 Correct 91 ms 3084 KB Output is correct
3 Correct 83 ms 2252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Incorrect 0 ms 384 KB Wrong answer in test 4 3: 4 < 5