답안 #48845

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
48845 2018-05-19T10:27:02 Z model_code 새 집 (APIO18_new_home) C++17
12 / 100
5000 ms 30976 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) {
    int n = a.size(), m = b.size();
    vector<int> ans(m);
    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<vector<int>> vct(k);
    int empty = k;
    for (auto ev : events) {
        if (ev.type == +1) {
            int tp = a[ev.id].type;
            int id = lower_bound(vct[tp].begin(), vct[tp].end(), a[ev.id].x) - vct[tp].begin();
            empty -= vct[tp].size() == 0;
            vct[tp].insert(vct[tp].begin() + id, a[ev.id].x);
        }
        if (ev.type == 0) {
            int cur = 0;
            if (empty) cur = INF;
            for (int i = 0; i < k; i++) {
                int id = lower_bound(vct[i].begin(), vct[i].end(), b[ev.id].x) - vct[i].begin();
                int ccur = INF;
                if (id < (int)vct[i].size()) ccur = min(ccur, abs(b[ev.id].x - vct[i][id]));
                if (id > 0) ccur = min(ccur, abs(b[ev.id].x - vct[i][id - 1]));
                cur = max(cur, ccur);
                if (cur >= INF / 2) break;
            }
            if (cur >= INF / 2) cur = -1;
            ans[ev.id] = cur;
        }
        if (ev.type == -1) {
            int tp = a[ev.id].type;
            int id = lower_bound(vct[tp].begin(), vct[tp].end(), a[ev.id].x) - vct[tp].begin();
            vct[tp].erase(vct[tp].begin() + id);
            empty += vct[tp].size() == 0;
        }
    }
    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 'std::vector<int> slow(std::vector<Shop>, int, std::vector<Query>)':
new_home.cpp:18:9: warning: unused variable 'n' [-Wunused-variable]
     int n = a.size(), m = b.size();
         ^
new_home.cpp: In function 'int main()':
new_home.cpp:70: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:73: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:77: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 360 KB Output is correct
3 Correct 2 ms 432 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 516 KB Output is correct
6 Correct 3 ms 516 KB Output is correct
7 Correct 3 ms 536 KB Output is correct
8 Correct 4 ms 536 KB Output is correct
9 Correct 4 ms 544 KB Output is correct
10 Correct 3 ms 616 KB Output is correct
11 Correct 3 ms 616 KB Output is correct
12 Correct 3 ms 616 KB Output is correct
13 Correct 3 ms 616 KB Output is correct
14 Correct 3 ms 616 KB Output is correct
15 Correct 4 ms 720 KB Output is correct
16 Correct 4 ms 720 KB Output is correct
17 Correct 4 ms 720 KB Output is correct
18 Correct 3 ms 720 KB Output is correct
19 Correct 3 ms 720 KB Output is correct
20 Correct 3 ms 720 KB Output is correct
21 Correct 3 ms 720 KB Output is correct
22 Correct 3 ms 720 KB Output is correct
23 Correct 5 ms 720 KB Output is correct
24 Correct 4 ms 720 KB Output is correct
25 Correct 3 ms 720 KB Output is correct
26 Correct 3 ms 720 KB Output is correct
27 Correct 2 ms 720 KB Output is correct
28 Correct 3 ms 720 KB Output is correct
29 Correct 3 ms 720 KB Output is correct
30 Correct 3 ms 720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 360 KB Output is correct
3 Correct 2 ms 432 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 516 KB Output is correct
6 Correct 3 ms 516 KB Output is correct
7 Correct 3 ms 536 KB Output is correct
8 Correct 4 ms 536 KB Output is correct
9 Correct 4 ms 544 KB Output is correct
10 Correct 3 ms 616 KB Output is correct
11 Correct 3 ms 616 KB Output is correct
12 Correct 3 ms 616 KB Output is correct
13 Correct 3 ms 616 KB Output is correct
14 Correct 3 ms 616 KB Output is correct
15 Correct 4 ms 720 KB Output is correct
16 Correct 4 ms 720 KB Output is correct
17 Correct 4 ms 720 KB Output is correct
18 Correct 3 ms 720 KB Output is correct
19 Correct 3 ms 720 KB Output is correct
20 Correct 3 ms 720 KB Output is correct
21 Correct 3 ms 720 KB Output is correct
22 Correct 3 ms 720 KB Output is correct
23 Correct 5 ms 720 KB Output is correct
24 Correct 4 ms 720 KB Output is correct
25 Correct 3 ms 720 KB Output is correct
26 Correct 3 ms 720 KB Output is correct
27 Correct 2 ms 720 KB Output is correct
28 Correct 3 ms 720 KB Output is correct
29 Correct 3 ms 720 KB Output is correct
30 Correct 3 ms 720 KB Output is correct
31 Correct 1102 ms 6872 KB Output is correct
32 Correct 108 ms 6872 KB Output is correct
33 Correct 181 ms 6904 KB Output is correct
34 Correct 887 ms 6904 KB Output is correct
35 Correct 553 ms 6928 KB Output is correct
36 Correct 209 ms 6928 KB Output is correct
37 Correct 171 ms 6928 KB Output is correct
38 Correct 125 ms 6944 KB Output is correct
39 Correct 109 ms 6948 KB Output is correct
40 Correct 113 ms 7040 KB Output is correct
41 Correct 309 ms 7040 KB Output is correct
42 Correct 239 ms 7040 KB Output is correct
43 Correct 439 ms 7040 KB Output is correct
44 Correct 332 ms 7040 KB Output is correct
45 Correct 145 ms 7040 KB Output is correct
46 Correct 103 ms 7040 KB Output is correct
47 Correct 88 ms 7040 KB Output is correct
48 Correct 86 ms 7040 KB Output is correct
49 Correct 106 ms 7040 KB Output is correct
50 Correct 164 ms 7040 KB Output is correct
51 Correct 97 ms 7040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5089 ms 30976 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5005 ms 30976 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 360 KB Output is correct
3 Correct 2 ms 432 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 516 KB Output is correct
6 Correct 3 ms 516 KB Output is correct
7 Correct 3 ms 536 KB Output is correct
8 Correct 4 ms 536 KB Output is correct
9 Correct 4 ms 544 KB Output is correct
10 Correct 3 ms 616 KB Output is correct
11 Correct 3 ms 616 KB Output is correct
12 Correct 3 ms 616 KB Output is correct
13 Correct 3 ms 616 KB Output is correct
14 Correct 3 ms 616 KB Output is correct
15 Correct 4 ms 720 KB Output is correct
16 Correct 4 ms 720 KB Output is correct
17 Correct 4 ms 720 KB Output is correct
18 Correct 3 ms 720 KB Output is correct
19 Correct 3 ms 720 KB Output is correct
20 Correct 3 ms 720 KB Output is correct
21 Correct 3 ms 720 KB Output is correct
22 Correct 3 ms 720 KB Output is correct
23 Correct 5 ms 720 KB Output is correct
24 Correct 4 ms 720 KB Output is correct
25 Correct 3 ms 720 KB Output is correct
26 Correct 3 ms 720 KB Output is correct
27 Correct 2 ms 720 KB Output is correct
28 Correct 3 ms 720 KB Output is correct
29 Correct 3 ms 720 KB Output is correct
30 Correct 3 ms 720 KB Output is correct
31 Correct 1102 ms 6872 KB Output is correct
32 Correct 108 ms 6872 KB Output is correct
33 Correct 181 ms 6904 KB Output is correct
34 Correct 887 ms 6904 KB Output is correct
35 Correct 553 ms 6928 KB Output is correct
36 Correct 209 ms 6928 KB Output is correct
37 Correct 171 ms 6928 KB Output is correct
38 Correct 125 ms 6944 KB Output is correct
39 Correct 109 ms 6948 KB Output is correct
40 Correct 113 ms 7040 KB Output is correct
41 Correct 309 ms 7040 KB Output is correct
42 Correct 239 ms 7040 KB Output is correct
43 Correct 439 ms 7040 KB Output is correct
44 Correct 332 ms 7040 KB Output is correct
45 Correct 145 ms 7040 KB Output is correct
46 Correct 103 ms 7040 KB Output is correct
47 Correct 88 ms 7040 KB Output is correct
48 Correct 86 ms 7040 KB Output is correct
49 Correct 106 ms 7040 KB Output is correct
50 Correct 164 ms 7040 KB Output is correct
51 Correct 97 ms 7040 KB Output is correct
52 Correct 130 ms 30976 KB Output is correct
53 Correct 111 ms 30976 KB Output is correct
54 Correct 123 ms 30976 KB Output is correct
55 Execution timed out 5038 ms 30976 KB Time limit exceeded
56 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 360 KB Output is correct
3 Correct 2 ms 432 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 516 KB Output is correct
6 Correct 3 ms 516 KB Output is correct
7 Correct 3 ms 536 KB Output is correct
8 Correct 4 ms 536 KB Output is correct
9 Correct 4 ms 544 KB Output is correct
10 Correct 3 ms 616 KB Output is correct
11 Correct 3 ms 616 KB Output is correct
12 Correct 3 ms 616 KB Output is correct
13 Correct 3 ms 616 KB Output is correct
14 Correct 3 ms 616 KB Output is correct
15 Correct 4 ms 720 KB Output is correct
16 Correct 4 ms 720 KB Output is correct
17 Correct 4 ms 720 KB Output is correct
18 Correct 3 ms 720 KB Output is correct
19 Correct 3 ms 720 KB Output is correct
20 Correct 3 ms 720 KB Output is correct
21 Correct 3 ms 720 KB Output is correct
22 Correct 3 ms 720 KB Output is correct
23 Correct 5 ms 720 KB Output is correct
24 Correct 4 ms 720 KB Output is correct
25 Correct 3 ms 720 KB Output is correct
26 Correct 3 ms 720 KB Output is correct
27 Correct 2 ms 720 KB Output is correct
28 Correct 3 ms 720 KB Output is correct
29 Correct 3 ms 720 KB Output is correct
30 Correct 3 ms 720 KB Output is correct
31 Correct 1102 ms 6872 KB Output is correct
32 Correct 108 ms 6872 KB Output is correct
33 Correct 181 ms 6904 KB Output is correct
34 Correct 887 ms 6904 KB Output is correct
35 Correct 553 ms 6928 KB Output is correct
36 Correct 209 ms 6928 KB Output is correct
37 Correct 171 ms 6928 KB Output is correct
38 Correct 125 ms 6944 KB Output is correct
39 Correct 109 ms 6948 KB Output is correct
40 Correct 113 ms 7040 KB Output is correct
41 Correct 309 ms 7040 KB Output is correct
42 Correct 239 ms 7040 KB Output is correct
43 Correct 439 ms 7040 KB Output is correct
44 Correct 332 ms 7040 KB Output is correct
45 Correct 145 ms 7040 KB Output is correct
46 Correct 103 ms 7040 KB Output is correct
47 Correct 88 ms 7040 KB Output is correct
48 Correct 86 ms 7040 KB Output is correct
49 Correct 106 ms 7040 KB Output is correct
50 Correct 164 ms 7040 KB Output is correct
51 Correct 97 ms 7040 KB Output is correct
52 Execution timed out 5089 ms 30976 KB Time limit exceeded
53 Halted 0 ms 0 KB -