Submission #147744

# Submission time Handle Problem Language Result Execution time Memory
147744 2019-08-30T14:09:27 Z theboatman Red-blue table (IZhO19_stones) C++17
100 / 100
77 ms 2424 KB
#include <bits/stdc++.h>

#define y1 theboatman
#define make_struct(args...) {args}

using namespace std;

typedef long long ll;

const long long INF = 1e18 + 10;
const int inf = 1e9 + 10;
const int N = 1e6 + 10;

void solve1(int n, int m) {
    vector <vector <char> > ans(n, vector <char> (m, '-'));

    int res;
    if (n <= m) {
        vector <int> used(m);

        res = m;
        for(int i = 0; i < n; i++) {
            vector <pair <int, int> > pos;
            for(int j = 0; j < m; j++) {
                if (used[j] < (n - 1) / 2) {
                    pos.push_back(make_pair(used[j], j));
                }
            }

            if (pos.size() < (m / 2) + 1) {
                break;
            }
            else {
                sort(pos.begin(), pos.end());

                for(int j = 0; j < (m / 2) + 1; j++) {
                    used[pos[j].second]++;
                    ans[i][pos[j].second] = '+';
                }
            }

            res++;
        }
    }
    else {
        ans.assign(n, vector <char> (m, '+'));
        vector <int> used(n);

        res = n;
        for(int i = 0; i < m; i++) {
            vector <pair <int, int> > pos;
            for(int j = 0; j < n; j++) {
                if (used[j] < (m - 1) / 2) {
                    pos.push_back(make_pair(used[j], j));
                }
            }

            if (pos.size() < (n / 2) + 1) {
                break;
            }
            else {
                sort(pos.begin(), pos.end());

                for(int j = 0; j < (n / 2) + 1; j++) {
                    used[pos[j].second]++;
                    ans[pos[j].second][i] = '-';
                }
            }

            res++;
        }
    }

    cout << res << "\n";
    for(auto i : ans) {
        for(auto j : i) {
            cout << j;
        }
        cout << "\n";
    }
}

void solve() {
    int n, m;
    cin >> n >> m;

    solve1(n, m);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);

    int test;
    cin >> test;

    while(test--) {
        solve();
    }

    return 0;
}

/*
*/

Compilation message

stones.cpp: In function 'void solve1(int, int)':
stones.cpp:30:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if (pos.size() < (m / 2) + 1) {
                 ~~~~~~~~~~~^~~~~~~~~~~~~
stones.cpp:58:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if (pos.size() < (n / 2) + 1) {
                 ~~~~~~~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 4 ms 376 KB Output is correct
4 Correct 5 ms 380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 69 ms 1376 KB Output is correct
2 Correct 66 ms 1752 KB Output is correct
3 Correct 65 ms 2040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 69 ms 1400 KB Output is correct
2 Correct 60 ms 1556 KB Output is correct
3 Correct 55 ms 1332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 4 ms 376 KB Output is correct
4 Correct 5 ms 380 KB Output is correct
5 Correct 69 ms 1376 KB Output is correct
6 Correct 66 ms 1752 KB Output is correct
7 Correct 65 ms 2040 KB Output is correct
8 Correct 69 ms 1400 KB Output is correct
9 Correct 60 ms 1556 KB Output is correct
10 Correct 55 ms 1332 KB Output is correct
11 Correct 18 ms 632 KB Output is correct
12 Correct 57 ms 1600 KB Output is correct
13 Correct 65 ms 1320 KB Output is correct
14 Correct 47 ms 1112 KB Output is correct
15 Correct 77 ms 2424 KB Output is correct
16 Correct 55 ms 1784 KB Output is correct
17 Correct 25 ms 1016 KB Output is correct