Submission #21303

# Submission time Handle Problem Language Result Execution time Memory
21303 2017-04-12T18:42:58 Z Ushio Cultivation (JOI17_cultivation) C++14
30 / 100
763 ms 262144 KB
#include <algorithm>
#include <iostream>
#include <vector>
#define SZ(x) ((int) (x).size())
using namespace std;

typedef long long i64;

const int INF = 0x3f3f3f3f;

struct Cell {
    int x, y;
    Cell() = default;
    Cell(int _x, int _y):
        x(_x), y(_y) {}
};

int main() {
    #ifdef LOCAL_RUN
    freopen("task.in", "r", stdin);
    freopen("task.out", "w", stdout);
    //freopen("task.err", "w", stderr);
    #endif // ONLINE_JUDGE
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, m, k;
    cin >> n >> m >> k;

    vector<Cell> cells(k);
    for (int i = 0; i < k; ++i) {
        cin >> cells[i].x >> cells[i].y;
        cells[i].x--; cells[i].y--;
    }
    int64_t ans = 1LL << 62;
    for (int lenUp = 0; lenUp <= n; ++lenUp) {
        for (int lenDown = 0; lenDown <= n; ++lenDown) {
            vector<vector<int>> cols(n);
            for (const Cell& c: cells) {
                for (int i = 0; i <= lenUp && c.x - i >= 0; ++i) {
                    cols[c.x - i].push_back(c.y);
                }
                for (int i = 0; i <= lenDown && c.x + i < n; ++i) {
                    cols[c.x + i].push_back(c.y);
                }
            }
            bool ok = true;
            int lenLeft = 0, lenRight = 0;
            for (vector<int>& ccols: cols) {
                if (SZ(ccols) == 0) {
                    ok = false;
                    break;
                }
                sort(ccols.begin(), ccols.end());
                ccols.erase(unique(ccols.begin(), ccols.end()), ccols.end());
                lenLeft = max(lenLeft, ccols.front());
                lenRight = max(lenRight, m - 1 - ccols.back());
            }
            if (!ok) {
                continue;
            }
            int64_t cans = lenUp + lenDown + lenLeft + lenRight;
            int add = 0;
            for (const vector<int>& ccols: cols) {
                for (int i = 1; i < SZ(ccols); ++i) {
                    add = max(add,
                        (ccols[i] - lenLeft) - (ccols[i - 1] + lenRight) - 1);
                }
            }
            cans += add;
            ans = min(ans, cans);
        }
    }
    cout << ans << '\n';
}

Compilation message


# Verdict Execution time Memory Grader output
1 Correct 0 ms 2180 KB Output is correct
2 Correct 0 ms 2180 KB Output is correct
3 Correct 0 ms 2180 KB Output is correct
4 Correct 0 ms 2180 KB Output is correct
5 Correct 0 ms 2180 KB Output is correct
6 Correct 0 ms 2180 KB Output is correct
7 Correct 0 ms 2180 KB Output is correct
8 Correct 0 ms 2180 KB Output is correct
9 Correct 0 ms 2180 KB Output is correct
10 Correct 0 ms 2180 KB Output is correct
11 Correct 0 ms 2180 KB Output is correct
12 Correct 0 ms 2180 KB Output is correct
13 Correct 0 ms 2180 KB Output is correct
14 Correct 0 ms 2180 KB Output is correct
15 Correct 0 ms 2180 KB Output is correct
16 Correct 0 ms 2180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2180 KB Output is correct
2 Correct 0 ms 2180 KB Output is correct
3 Correct 0 ms 2180 KB Output is correct
4 Correct 0 ms 2180 KB Output is correct
5 Correct 0 ms 2180 KB Output is correct
6 Correct 0 ms 2180 KB Output is correct
7 Correct 0 ms 2180 KB Output is correct
8 Correct 0 ms 2180 KB Output is correct
9 Correct 0 ms 2180 KB Output is correct
10 Correct 0 ms 2180 KB Output is correct
11 Correct 0 ms 2180 KB Output is correct
12 Correct 0 ms 2180 KB Output is correct
13 Correct 0 ms 2180 KB Output is correct
14 Correct 0 ms 2180 KB Output is correct
15 Correct 0 ms 2180 KB Output is correct
16 Correct 0 ms 2180 KB Output is correct
17 Correct 0 ms 2180 KB Output is correct
18 Correct 33 ms 2180 KB Output is correct
19 Correct 33 ms 2180 KB Output is correct
20 Correct 0 ms 2180 KB Output is correct
21 Correct 86 ms 2180 KB Output is correct
22 Correct 253 ms 2180 KB Output is correct
23 Correct 43 ms 2180 KB Output is correct
24 Correct 439 ms 2180 KB Output is correct
25 Correct 329 ms 2180 KB Output is correct
26 Correct 679 ms 2180 KB Output is correct
27 Correct 649 ms 2180 KB Output is correct
28 Correct 413 ms 2180 KB Output is correct
29 Correct 563 ms 2180 KB Output is correct
30 Correct 673 ms 2180 KB Output is correct
31 Correct 679 ms 2180 KB Output is correct
32 Correct 669 ms 2180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2180 KB Output is correct
2 Correct 0 ms 2180 KB Output is correct
3 Correct 0 ms 2180 KB Output is correct
4 Correct 0 ms 2180 KB Output is correct
5 Correct 0 ms 2180 KB Output is correct
6 Correct 0 ms 2180 KB Output is correct
7 Correct 0 ms 2180 KB Output is correct
8 Correct 0 ms 2180 KB Output is correct
9 Correct 0 ms 2180 KB Output is correct
10 Correct 0 ms 2180 KB Output is correct
11 Correct 0 ms 2180 KB Output is correct
12 Correct 0 ms 2180 KB Output is correct
13 Correct 0 ms 2180 KB Output is correct
14 Correct 0 ms 2180 KB Output is correct
15 Correct 0 ms 2180 KB Output is correct
16 Correct 0 ms 2180 KB Output is correct
17 Correct 0 ms 2180 KB Output is correct
18 Correct 33 ms 2180 KB Output is correct
19 Correct 33 ms 2180 KB Output is correct
20 Correct 0 ms 2180 KB Output is correct
21 Correct 86 ms 2180 KB Output is correct
22 Correct 253 ms 2180 KB Output is correct
23 Correct 43 ms 2180 KB Output is correct
24 Correct 439 ms 2180 KB Output is correct
25 Correct 329 ms 2180 KB Output is correct
26 Correct 679 ms 2180 KB Output is correct
27 Correct 649 ms 2180 KB Output is correct
28 Correct 413 ms 2180 KB Output is correct
29 Correct 563 ms 2180 KB Output is correct
30 Correct 673 ms 2180 KB Output is correct
31 Correct 679 ms 2180 KB Output is correct
32 Correct 669 ms 2180 KB Output is correct
33 Correct 0 ms 2180 KB Output is correct
34 Correct 686 ms 2180 KB Output is correct
35 Correct 709 ms 2180 KB Output is correct
36 Correct 719 ms 2180 KB Output is correct
37 Correct 483 ms 2180 KB Output is correct
38 Correct 709 ms 2180 KB Output is correct
39 Correct 676 ms 2180 KB Output is correct
40 Correct 703 ms 2180 KB Output is correct
41 Correct 493 ms 2180 KB Output is correct
42 Correct 596 ms 2180 KB Output is correct
43 Correct 646 ms 2180 KB Output is correct
44 Correct 763 ms 2312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Memory limit exceeded 0 ms 262144 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Memory limit exceeded 0 ms 262144 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2180 KB Output is correct
2 Correct 0 ms 2180 KB Output is correct
3 Correct 0 ms 2180 KB Output is correct
4 Correct 0 ms 2180 KB Output is correct
5 Correct 0 ms 2180 KB Output is correct
6 Correct 0 ms 2180 KB Output is correct
7 Correct 0 ms 2180 KB Output is correct
8 Correct 0 ms 2180 KB Output is correct
9 Correct 0 ms 2180 KB Output is correct
10 Correct 0 ms 2180 KB Output is correct
11 Correct 0 ms 2180 KB Output is correct
12 Correct 0 ms 2180 KB Output is correct
13 Correct 0 ms 2180 KB Output is correct
14 Correct 0 ms 2180 KB Output is correct
15 Correct 0 ms 2180 KB Output is correct
16 Correct 0 ms 2180 KB Output is correct
17 Correct 0 ms 2180 KB Output is correct
18 Correct 33 ms 2180 KB Output is correct
19 Correct 33 ms 2180 KB Output is correct
20 Correct 0 ms 2180 KB Output is correct
21 Correct 86 ms 2180 KB Output is correct
22 Correct 253 ms 2180 KB Output is correct
23 Correct 43 ms 2180 KB Output is correct
24 Correct 439 ms 2180 KB Output is correct
25 Correct 329 ms 2180 KB Output is correct
26 Correct 679 ms 2180 KB Output is correct
27 Correct 649 ms 2180 KB Output is correct
28 Correct 413 ms 2180 KB Output is correct
29 Correct 563 ms 2180 KB Output is correct
30 Correct 673 ms 2180 KB Output is correct
31 Correct 679 ms 2180 KB Output is correct
32 Correct 669 ms 2180 KB Output is correct
33 Correct 0 ms 2180 KB Output is correct
34 Correct 686 ms 2180 KB Output is correct
35 Correct 709 ms 2180 KB Output is correct
36 Correct 719 ms 2180 KB Output is correct
37 Correct 483 ms 2180 KB Output is correct
38 Correct 709 ms 2180 KB Output is correct
39 Correct 676 ms 2180 KB Output is correct
40 Correct 703 ms 2180 KB Output is correct
41 Correct 493 ms 2180 KB Output is correct
42 Correct 596 ms 2180 KB Output is correct
43 Correct 646 ms 2180 KB Output is correct
44 Correct 763 ms 2312 KB Output is correct
45 Memory limit exceeded 0 ms 262144 KB Memory limit exceeded
46 Halted 0 ms 0 KB -