답안 #48848

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
48848 2018-05-19T10:27:39 Z model_code 새 집 (APIO18_new_home) C++17
12 / 100
5000 ms 43776 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<int> sum(k);
    vector<multiset<int>> st(k);

    int empty = k;
    for (auto ev : events) {        
        if (ev.type == +1) {
            int tp = a[ev.id].type;
            st[tp].insert(a[ev.id].x);
            empty -= sum[tp]++ == 0;
        }
        if (ev.type == 0) {
            int cur = 0;
            if (empty) cur = INF;
            for (int i = 0; i < k; i++) {
                int ccur = INF;
                auto it = st[i].lower_bound(b[ev.id].x);
                if (it != st[i].end()) ccur = min(ccur, abs(*it - b[ev.id].x));
                if (it != st[i].begin()) {
                    it--;
                    ccur = min(ccur, abs(*it - b[ev.id].x));
                }
                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;
            st[a[ev.id].type].erase(st[a[ev.id].type].find(a[ev.id].x));
            empty += --sum[tp] == 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:74: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:77: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:81: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 356 KB Output is correct
3 Correct 2 ms 356 KB Output is correct
4 Correct 3 ms 560 KB Output is correct
5 Correct 3 ms 560 KB Output is correct
6 Correct 3 ms 688 KB Output is correct
7 Correct 4 ms 688 KB Output is correct
8 Correct 3 ms 688 KB Output is correct
9 Correct 3 ms 688 KB Output is correct
10 Correct 3 ms 688 KB Output is correct
11 Correct 4 ms 688 KB Output is correct
12 Correct 3 ms 688 KB Output is correct
13 Correct 3 ms 688 KB Output is correct
14 Correct 3 ms 688 KB Output is correct
15 Correct 3 ms 688 KB Output is correct
16 Correct 4 ms 688 KB Output is correct
17 Correct 3 ms 688 KB Output is correct
18 Correct 3 ms 688 KB Output is correct
19 Correct 3 ms 688 KB Output is correct
20 Correct 3 ms 688 KB Output is correct
21 Correct 5 ms 688 KB Output is correct
22 Correct 3 ms 688 KB Output is correct
23 Correct 3 ms 688 KB Output is correct
24 Correct 3 ms 688 KB Output is correct
25 Correct 4 ms 688 KB Output is correct
26 Correct 2 ms 688 KB Output is correct
27 Correct 3 ms 688 KB Output is correct
28 Correct 3 ms 688 KB Output is correct
29 Correct 3 ms 688 KB Output is correct
30 Correct 3 ms 688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 356 KB Output is correct
4 Correct 3 ms 560 KB Output is correct
5 Correct 3 ms 560 KB Output is correct
6 Correct 3 ms 688 KB Output is correct
7 Correct 4 ms 688 KB Output is correct
8 Correct 3 ms 688 KB Output is correct
9 Correct 3 ms 688 KB Output is correct
10 Correct 3 ms 688 KB Output is correct
11 Correct 4 ms 688 KB Output is correct
12 Correct 3 ms 688 KB Output is correct
13 Correct 3 ms 688 KB Output is correct
14 Correct 3 ms 688 KB Output is correct
15 Correct 3 ms 688 KB Output is correct
16 Correct 4 ms 688 KB Output is correct
17 Correct 3 ms 688 KB Output is correct
18 Correct 3 ms 688 KB Output is correct
19 Correct 3 ms 688 KB Output is correct
20 Correct 3 ms 688 KB Output is correct
21 Correct 5 ms 688 KB Output is correct
22 Correct 3 ms 688 KB Output is correct
23 Correct 3 ms 688 KB Output is correct
24 Correct 3 ms 688 KB Output is correct
25 Correct 4 ms 688 KB Output is correct
26 Correct 2 ms 688 KB Output is correct
27 Correct 3 ms 688 KB Output is correct
28 Correct 3 ms 688 KB Output is correct
29 Correct 3 ms 688 KB Output is correct
30 Correct 3 ms 688 KB Output is correct
31 Correct 3455 ms 8712 KB Output is correct
32 Correct 129 ms 8712 KB Output is correct
33 Correct 245 ms 8712 KB Output is correct
34 Correct 2278 ms 8712 KB Output is correct
35 Correct 1320 ms 8716 KB Output is correct
36 Correct 298 ms 8716 KB Output is correct
37 Correct 207 ms 8716 KB Output is correct
38 Correct 135 ms 8716 KB Output is correct
39 Correct 111 ms 8716 KB Output is correct
40 Correct 125 ms 8716 KB Output is correct
41 Correct 435 ms 8716 KB Output is correct
42 Correct 404 ms 8716 KB Output is correct
43 Correct 675 ms 8784 KB Output is correct
44 Correct 310 ms 8784 KB Output is correct
45 Correct 163 ms 8784 KB Output is correct
46 Correct 120 ms 8784 KB Output is correct
47 Correct 98 ms 8784 KB Output is correct
48 Correct 89 ms 8784 KB Output is correct
49 Correct 100 ms 8784 KB Output is correct
50 Correct 194 ms 8784 KB Output is correct
51 Correct 108 ms 8784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5016 ms 43776 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5096 ms 43776 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 356 KB Output is correct
3 Correct 2 ms 356 KB Output is correct
4 Correct 3 ms 560 KB Output is correct
5 Correct 3 ms 560 KB Output is correct
6 Correct 3 ms 688 KB Output is correct
7 Correct 4 ms 688 KB Output is correct
8 Correct 3 ms 688 KB Output is correct
9 Correct 3 ms 688 KB Output is correct
10 Correct 3 ms 688 KB Output is correct
11 Correct 4 ms 688 KB Output is correct
12 Correct 3 ms 688 KB Output is correct
13 Correct 3 ms 688 KB Output is correct
14 Correct 3 ms 688 KB Output is correct
15 Correct 3 ms 688 KB Output is correct
16 Correct 4 ms 688 KB Output is correct
17 Correct 3 ms 688 KB Output is correct
18 Correct 3 ms 688 KB Output is correct
19 Correct 3 ms 688 KB Output is correct
20 Correct 3 ms 688 KB Output is correct
21 Correct 5 ms 688 KB Output is correct
22 Correct 3 ms 688 KB Output is correct
23 Correct 3 ms 688 KB Output is correct
24 Correct 3 ms 688 KB Output is correct
25 Correct 4 ms 688 KB Output is correct
26 Correct 2 ms 688 KB Output is correct
27 Correct 3 ms 688 KB Output is correct
28 Correct 3 ms 688 KB Output is correct
29 Correct 3 ms 688 KB Output is correct
30 Correct 3 ms 688 KB Output is correct
31 Correct 3455 ms 8712 KB Output is correct
32 Correct 129 ms 8712 KB Output is correct
33 Correct 245 ms 8712 KB Output is correct
34 Correct 2278 ms 8712 KB Output is correct
35 Correct 1320 ms 8716 KB Output is correct
36 Correct 298 ms 8716 KB Output is correct
37 Correct 207 ms 8716 KB Output is correct
38 Correct 135 ms 8716 KB Output is correct
39 Correct 111 ms 8716 KB Output is correct
40 Correct 125 ms 8716 KB Output is correct
41 Correct 435 ms 8716 KB Output is correct
42 Correct 404 ms 8716 KB Output is correct
43 Correct 675 ms 8784 KB Output is correct
44 Correct 310 ms 8784 KB Output is correct
45 Correct 163 ms 8784 KB Output is correct
46 Correct 120 ms 8784 KB Output is correct
47 Correct 98 ms 8784 KB Output is correct
48 Correct 89 ms 8784 KB Output is correct
49 Correct 100 ms 8784 KB Output is correct
50 Correct 194 ms 8784 KB Output is correct
51 Correct 108 ms 8784 KB Output is correct
52 Correct 151 ms 43776 KB Output is correct
53 Correct 188 ms 43776 KB Output is correct
54 Correct 145 ms 43776 KB Output is correct
55 Execution timed out 5094 ms 43776 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 356 KB Output is correct
3 Correct 2 ms 356 KB Output is correct
4 Correct 3 ms 560 KB Output is correct
5 Correct 3 ms 560 KB Output is correct
6 Correct 3 ms 688 KB Output is correct
7 Correct 4 ms 688 KB Output is correct
8 Correct 3 ms 688 KB Output is correct
9 Correct 3 ms 688 KB Output is correct
10 Correct 3 ms 688 KB Output is correct
11 Correct 4 ms 688 KB Output is correct
12 Correct 3 ms 688 KB Output is correct
13 Correct 3 ms 688 KB Output is correct
14 Correct 3 ms 688 KB Output is correct
15 Correct 3 ms 688 KB Output is correct
16 Correct 4 ms 688 KB Output is correct
17 Correct 3 ms 688 KB Output is correct
18 Correct 3 ms 688 KB Output is correct
19 Correct 3 ms 688 KB Output is correct
20 Correct 3 ms 688 KB Output is correct
21 Correct 5 ms 688 KB Output is correct
22 Correct 3 ms 688 KB Output is correct
23 Correct 3 ms 688 KB Output is correct
24 Correct 3 ms 688 KB Output is correct
25 Correct 4 ms 688 KB Output is correct
26 Correct 2 ms 688 KB Output is correct
27 Correct 3 ms 688 KB Output is correct
28 Correct 3 ms 688 KB Output is correct
29 Correct 3 ms 688 KB Output is correct
30 Correct 3 ms 688 KB Output is correct
31 Correct 3455 ms 8712 KB Output is correct
32 Correct 129 ms 8712 KB Output is correct
33 Correct 245 ms 8712 KB Output is correct
34 Correct 2278 ms 8712 KB Output is correct
35 Correct 1320 ms 8716 KB Output is correct
36 Correct 298 ms 8716 KB Output is correct
37 Correct 207 ms 8716 KB Output is correct
38 Correct 135 ms 8716 KB Output is correct
39 Correct 111 ms 8716 KB Output is correct
40 Correct 125 ms 8716 KB Output is correct
41 Correct 435 ms 8716 KB Output is correct
42 Correct 404 ms 8716 KB Output is correct
43 Correct 675 ms 8784 KB Output is correct
44 Correct 310 ms 8784 KB Output is correct
45 Correct 163 ms 8784 KB Output is correct
46 Correct 120 ms 8784 KB Output is correct
47 Correct 98 ms 8784 KB Output is correct
48 Correct 89 ms 8784 KB Output is correct
49 Correct 100 ms 8784 KB Output is correct
50 Correct 194 ms 8784 KB Output is correct
51 Correct 108 ms 8784 KB Output is correct
52 Execution timed out 5016 ms 43776 KB Time limit exceeded
53 Halted 0 ms 0 KB -