답안 #48846

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
48846 2018-05-19T10:27:19 Z model_code 새 집 (APIO18_new_home) C++17
12 / 100
5000 ms 49044 KB
#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1.01e9;

void print(vector<int> v) {
    for (int x : v) printf("%d\n", x);
}

struct Shop {
    int x, type, a, b;
};

struct Query {
    int x, time;
};

vector<int> slow(vector<Shop> a, int k, vector<Query> b) {
    vector<int> ans(b.size());
    struct Event {
        int time, type, id;
        bool operator< (const Event &ev) const {
            return make_pair(time, -type) < make_pair(ev.time, -ev.type);
        }
    };
    vector<Event> events;
    for (int i = 0; i < (int)a.size(); i++) {
        events.push_back({a[i].a, +1, i});
        events.push_back({a[i].b, -1, i});
    }
    for (int i = 0; i < (int)b.size(); i++) {
        events.push_back({b[i].time, 0, i});
    }
    sort(events.begin(), events.end());
    vector<multiset<int>> st(1);
    st[0].insert(-INF);
    st[0].insert(+INF);
    st.assign(k, st[0]);
    for (auto ev: events) {
        if (ev.type == +1) {
            st[a[ev.id].type].insert(a[ev.id].x);
        }
        if (ev.type == 0) {
            int cur = 0;
            for (int i = 0; i < k; i++) {
                auto it = st[i].lower_bound(b[ev.id].x);
                int ccur = INF;
                ccur = min(ccur, abs(*it - b[ev.id].x));
                it--;
                ccur = min(ccur, abs(*it - b[ev.id].x));
                cur = max(cur, ccur);
            }
            if (cur >= INF / 2) cur = -1;
            ans[ev.id] = cur;
        }
        if (ev.type == -1) {
            st[a[ev.id].type].erase(st[a[ev.id].type].find(a[ev.id].x));
        }
    }
    return ans;
}

int main() {
    int n, k, q;
    scanf("%d%d%d", &n, &k, &q);
    vector<Shop> a(n);
    for (int i = 0; i < n; i++) {
        scanf("%d%d%d%d", &a[i].x, &a[i].type, &a[i].a, &a[i].b);
        a[i].type--;
    }
    vector<Query> b(q);
    for (int i = 0; i < q; i++) scanf("%d%d", &b[i].x, &b[i].time);

    print(slow(a, k, b));
}

Compilation message

new_home.cpp: In function 'int main()':
new_home.cpp:64:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d", &n, &k, &q);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~
new_home.cpp:67:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d%d", &a[i].x, &a[i].type, &a[i].a, &a[i].b);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
new_home.cpp:71:38: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for (int i = 0; i < q; i++) scanf("%d%d", &b[i].x, &b[i].time);
                                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 2 ms 484 KB Output is correct
5 Correct 2 ms 484 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 5 ms 532 KB Output is correct
8 Correct 3 ms 532 KB Output is correct
9 Correct 6 ms 572 KB Output is correct
10 Correct 3 ms 572 KB Output is correct
11 Correct 3 ms 612 KB Output is correct
12 Correct 3 ms 612 KB Output is correct
13 Correct 3 ms 612 KB Output is correct
14 Correct 2 ms 612 KB Output is correct
15 Correct 4 ms 740 KB Output is correct
16 Correct 3 ms 740 KB Output is correct
17 Correct 3 ms 740 KB Output is correct
18 Correct 3 ms 740 KB Output is correct
19 Correct 4 ms 740 KB Output is correct
20 Correct 3 ms 740 KB Output is correct
21 Correct 4 ms 740 KB Output is correct
22 Correct 5 ms 740 KB Output is correct
23 Correct 4 ms 740 KB Output is correct
24 Correct 4 ms 740 KB Output is correct
25 Correct 4 ms 748 KB Output is correct
26 Correct 3 ms 748 KB Output is correct
27 Correct 3 ms 748 KB Output is correct
28 Correct 3 ms 748 KB Output is correct
29 Correct 3 ms 748 KB Output is correct
30 Correct 3 ms 748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 2 ms 484 KB Output is correct
5 Correct 2 ms 484 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 5 ms 532 KB Output is correct
8 Correct 3 ms 532 KB Output is correct
9 Correct 6 ms 572 KB Output is correct
10 Correct 3 ms 572 KB Output is correct
11 Correct 3 ms 612 KB Output is correct
12 Correct 3 ms 612 KB Output is correct
13 Correct 3 ms 612 KB Output is correct
14 Correct 2 ms 612 KB Output is correct
15 Correct 4 ms 740 KB Output is correct
16 Correct 3 ms 740 KB Output is correct
17 Correct 3 ms 740 KB Output is correct
18 Correct 3 ms 740 KB Output is correct
19 Correct 4 ms 740 KB Output is correct
20 Correct 3 ms 740 KB Output is correct
21 Correct 4 ms 740 KB Output is correct
22 Correct 5 ms 740 KB Output is correct
23 Correct 4 ms 740 KB Output is correct
24 Correct 4 ms 740 KB Output is correct
25 Correct 4 ms 748 KB Output is correct
26 Correct 3 ms 748 KB Output is correct
27 Correct 3 ms 748 KB Output is correct
28 Correct 3 ms 748 KB Output is correct
29 Correct 3 ms 748 KB Output is correct
30 Correct 3 ms 748 KB Output is correct
31 Correct 3294 ms 8752 KB Output is correct
32 Correct 149 ms 8752 KB Output is correct
33 Correct 271 ms 8752 KB Output is correct
34 Correct 2513 ms 8752 KB Output is correct
35 Correct 1475 ms 8752 KB Output is correct
36 Correct 305 ms 8752 KB Output is correct
37 Correct 214 ms 8752 KB Output is correct
38 Correct 138 ms 8752 KB Output is correct
39 Correct 127 ms 8752 KB Output is correct
40 Correct 124 ms 8752 KB Output is correct
41 Correct 419 ms 8752 KB Output is correct
42 Correct 547 ms 8752 KB Output is correct
43 Correct 703 ms 8752 KB Output is correct
44 Correct 341 ms 8752 KB Output is correct
45 Correct 185 ms 8752 KB Output is correct
46 Correct 111 ms 8752 KB Output is correct
47 Correct 101 ms 8752 KB Output is correct
48 Correct 94 ms 8752 KB Output is correct
49 Correct 117 ms 8752 KB Output is correct
50 Correct 315 ms 8752 KB Output is correct
51 Correct 127 ms 8752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5018 ms 49044 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5035 ms 49044 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 2 ms 484 KB Output is correct
5 Correct 2 ms 484 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 5 ms 532 KB Output is correct
8 Correct 3 ms 532 KB Output is correct
9 Correct 6 ms 572 KB Output is correct
10 Correct 3 ms 572 KB Output is correct
11 Correct 3 ms 612 KB Output is correct
12 Correct 3 ms 612 KB Output is correct
13 Correct 3 ms 612 KB Output is correct
14 Correct 2 ms 612 KB Output is correct
15 Correct 4 ms 740 KB Output is correct
16 Correct 3 ms 740 KB Output is correct
17 Correct 3 ms 740 KB Output is correct
18 Correct 3 ms 740 KB Output is correct
19 Correct 4 ms 740 KB Output is correct
20 Correct 3 ms 740 KB Output is correct
21 Correct 4 ms 740 KB Output is correct
22 Correct 5 ms 740 KB Output is correct
23 Correct 4 ms 740 KB Output is correct
24 Correct 4 ms 740 KB Output is correct
25 Correct 4 ms 748 KB Output is correct
26 Correct 3 ms 748 KB Output is correct
27 Correct 3 ms 748 KB Output is correct
28 Correct 3 ms 748 KB Output is correct
29 Correct 3 ms 748 KB Output is correct
30 Correct 3 ms 748 KB Output is correct
31 Correct 3294 ms 8752 KB Output is correct
32 Correct 149 ms 8752 KB Output is correct
33 Correct 271 ms 8752 KB Output is correct
34 Correct 2513 ms 8752 KB Output is correct
35 Correct 1475 ms 8752 KB Output is correct
36 Correct 305 ms 8752 KB Output is correct
37 Correct 214 ms 8752 KB Output is correct
38 Correct 138 ms 8752 KB Output is correct
39 Correct 127 ms 8752 KB Output is correct
40 Correct 124 ms 8752 KB Output is correct
41 Correct 419 ms 8752 KB Output is correct
42 Correct 547 ms 8752 KB Output is correct
43 Correct 703 ms 8752 KB Output is correct
44 Correct 341 ms 8752 KB Output is correct
45 Correct 185 ms 8752 KB Output is correct
46 Correct 111 ms 8752 KB Output is correct
47 Correct 101 ms 8752 KB Output is correct
48 Correct 94 ms 8752 KB Output is correct
49 Correct 117 ms 8752 KB Output is correct
50 Correct 315 ms 8752 KB Output is correct
51 Correct 127 ms 8752 KB Output is correct
52 Execution timed out 5016 ms 49044 KB Time limit exceeded
53 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 2 ms 484 KB Output is correct
5 Correct 2 ms 484 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 5 ms 532 KB Output is correct
8 Correct 3 ms 532 KB Output is correct
9 Correct 6 ms 572 KB Output is correct
10 Correct 3 ms 572 KB Output is correct
11 Correct 3 ms 612 KB Output is correct
12 Correct 3 ms 612 KB Output is correct
13 Correct 3 ms 612 KB Output is correct
14 Correct 2 ms 612 KB Output is correct
15 Correct 4 ms 740 KB Output is correct
16 Correct 3 ms 740 KB Output is correct
17 Correct 3 ms 740 KB Output is correct
18 Correct 3 ms 740 KB Output is correct
19 Correct 4 ms 740 KB Output is correct
20 Correct 3 ms 740 KB Output is correct
21 Correct 4 ms 740 KB Output is correct
22 Correct 5 ms 740 KB Output is correct
23 Correct 4 ms 740 KB Output is correct
24 Correct 4 ms 740 KB Output is correct
25 Correct 4 ms 748 KB Output is correct
26 Correct 3 ms 748 KB Output is correct
27 Correct 3 ms 748 KB Output is correct
28 Correct 3 ms 748 KB Output is correct
29 Correct 3 ms 748 KB Output is correct
30 Correct 3 ms 748 KB Output is correct
31 Correct 3294 ms 8752 KB Output is correct
32 Correct 149 ms 8752 KB Output is correct
33 Correct 271 ms 8752 KB Output is correct
34 Correct 2513 ms 8752 KB Output is correct
35 Correct 1475 ms 8752 KB Output is correct
36 Correct 305 ms 8752 KB Output is correct
37 Correct 214 ms 8752 KB Output is correct
38 Correct 138 ms 8752 KB Output is correct
39 Correct 127 ms 8752 KB Output is correct
40 Correct 124 ms 8752 KB Output is correct
41 Correct 419 ms 8752 KB Output is correct
42 Correct 547 ms 8752 KB Output is correct
43 Correct 703 ms 8752 KB Output is correct
44 Correct 341 ms 8752 KB Output is correct
45 Correct 185 ms 8752 KB Output is correct
46 Correct 111 ms 8752 KB Output is correct
47 Correct 101 ms 8752 KB Output is correct
48 Correct 94 ms 8752 KB Output is correct
49 Correct 117 ms 8752 KB Output is correct
50 Correct 315 ms 8752 KB Output is correct
51 Correct 127 ms 8752 KB Output is correct
52 Execution timed out 5018 ms 49044 KB Time limit exceeded
53 Halted 0 ms 0 KB -