Submission #894728

# Submission time Handle Problem Language Result Execution time Memory
894728 2023-12-28T20:09:07 Z box Hamburg Steak (JOI20_hamburg) C++17
5 / 100
3000 ms 860 KB
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

#define ar array
#define sz(v) int(std::size(v))
using i64 = long long;

const int MAXN = 2e3;

int N, K;
// int L[MAXN], R[MAXN], U[MAXN], D[MAXN];
ar<int, 4> V[MAXN];
int order[MAXN];
vector<int> breaks;
bool done[MAXN];
// vector<int> X, Y;
ar<int, 2> solutions[4];

ar<int, 4> operator+(const ar<int, 4> one, const ar<int, 4> two) {
    if (one[0] == -1 || two[0] == -1 || max(one[0], two[0]) > min(one[1], two[1]) || max(one[2], two[2]) > min(one[3], two[3])) return {-1, -1, -1, -1};
    return {max(one[0], two[0]), min(one[1], two[1]), max(one[2], two[2]), min(one[3], two[3])};
}

mt19937 rng(1234);

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N >> K;
    for (int i = 0; i < N; i++) {
        int l, r, u, d;
        cin >> l >> d >> r >> u;
        V[i] = {l, r, d, u};
        // cin >> L[i] >> R[i] >> U[i] >> D[i];
        /*
        X.push_back(L[i]);
        X.push_back(R[i]);
        Y.push_back(U[i]);
        Y.push_back(D[i]);
        */
        order[i] = i;
    }
    /*
    sort(begin(X), end(X));
    X.erase(unique(begin(X), end(X)), end(X));
    sort(begin(Y), end(Y));
    Y.erase(unique(begin(Y), end(Y)), end(Y));
    */
    while (1) {
        for (int i = 0; i < N; i++) swap(order[i], order[rng() % (i + 1)]);
        fill(done, done + N, false);
        int i = 0;
        for (int rep = 0; rep < K; rep++) {
            while (i < N && done[i]) i++;
            if (i == N) {
                while (rep < K)
                    solutions[rep++] = {1, 1};
                break;
            }
            done[i] = 1;
            auto v = V[order[i]];
            for (int j = i + 1; j < N; j++) if (!done[j] && (v + V[order[j]])[0] != -1) {
                v = v + V[order[j]];
                done[j] = 1;
            }
            solutions[rep] = {v[0], v[2]};
        }
        if (!count(done, done + N, false)) {
            for (int i = 0; i < K; i++)
                cout << solutions[i][0] << " " << solutions[i][1] << '\n';
            break;
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 2 ms 480 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 584 KB Output is correct
2 Correct 3 ms 348 KB Output is correct
3 Correct 5 ms 588 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 2 ms 580 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 552 KB Output is correct
8 Correct 5 ms 484 KB Output is correct
9 Correct 4 ms 344 KB Output is correct
10 Correct 393 ms 576 KB Output is correct
11 Correct 11 ms 348 KB Output is correct
12 Correct 29 ms 556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 8 ms 348 KB Output is correct
5 Correct 7 ms 344 KB Output is correct
6 Correct 2 ms 560 KB Output is correct
7 Correct 79 ms 344 KB Output is correct
8 Correct 45 ms 576 KB Output is correct
9 Correct 38 ms 348 KB Output is correct
10 Correct 47 ms 348 KB Output is correct
11 Correct 1974 ms 556 KB Output is correct
12 Correct 3 ms 348 KB Output is correct
13 Execution timed out 3022 ms 344 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Runtime error 1 ms 856 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 2 ms 480 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Runtime error 1 ms 860 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 584 KB Output is correct
2 Correct 3 ms 348 KB Output is correct
3 Correct 5 ms 588 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 2 ms 580 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 552 KB Output is correct
8 Correct 5 ms 484 KB Output is correct
9 Correct 4 ms 344 KB Output is correct
10 Correct 393 ms 576 KB Output is correct
11 Correct 11 ms 348 KB Output is correct
12 Correct 29 ms 556 KB Output is correct
13 Runtime error 1 ms 860 KB Execution killed with signal 11
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 8 ms 348 KB Output is correct
5 Correct 7 ms 344 KB Output is correct
6 Correct 2 ms 560 KB Output is correct
7 Correct 79 ms 344 KB Output is correct
8 Correct 45 ms 576 KB Output is correct
9 Correct 38 ms 348 KB Output is correct
10 Correct 47 ms 348 KB Output is correct
11 Correct 1974 ms 556 KB Output is correct
12 Correct 3 ms 348 KB Output is correct
13 Execution timed out 3022 ms 344 KB Time limit exceeded
14 Halted 0 ms 0 KB -