답안 #54034

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
54034 2018-07-02T08:42:46 Z bogdan10bos 새 집 (APIO18_new_home) C++14
12 / 100
5000 ms 44420 KB
#include <bits/stdc++.h>

using namespace std;

//#define FILE_IO

typedef long long LL;

int N, K, Q;
LL sol[300005];

struct store
{
    int x, t, st, dr;

    store(int _x, int _t, int _st, int _dr) { x = _x, t = _t, st = _st, dr = _dr; }
};
vector<store> stores, ersStores;

struct query
{
    int x, tm, id;

    query(int _x, int _tm, int _id) { x = _x, tm = _tm, id = _id; }
};
vector<query> queries;

multiset<int> str[300005];

int main()
{
    #ifdef FILE_IO
    freopen("1.in", "r", stdin);
    freopen("1.out", "w", stdout);
    #endif

    scanf("%d%d%d", &N, &K, &Q);

    for(int i = 1; i <= N; i++)
    {
        int x, t, st, dr;
        scanf("%d%d%d%d", &x, &t, &st, &dr);
        stores.push_back(store(x, t, st, dr));
    }
    ersStores = stores;
    sort(stores.begin(), stores.end(),
         [](store a, store b) { return a.st < b.st; });
    sort(ersStores.begin(), ersStores.end(),
         [](store a, store b) { return a.dr < b.dr; });

    for(int i = 1; i <= Q; i++)
    {
        int x, tm;
        scanf("%d%d", &x, &tm);
        queries.push_back(query(x, tm, i));
    }

    sort(queries.begin(), queries.end(),
         [](query a, query b) { return a.tm < b.tm; });

    int pi = 0;
    int pe = 0;
    for(auto &q: queries)
    {
        int pos = q.x;
        int t = q.tm;

        /// Insert stores
        while(pi < stores.size() && stores[pi].st <= t)
        {
            str[ stores[pi].t ].insert(stores[pi].x);
            pi++;
        }

        /// Erase stores
        while(pe < ersStores.size() && ersStores[pe].dr < t)
        {
            int tt = ersStores[pe].t;
            str[tt].erase( str[tt].find(ersStores[pe].x) );
            pe++;
        }

        /// Answer
        int ans = -1;
        for(int i = 1; i <= K; i++)
        {
            if(str[i].empty())
            {
                ans = -1;
                break;
            }

            auto it = str[i].lower_bound(pos);
            int mn = 1 << 30;
            if(it != str[i].end())  mn = abs((*it) - pos);
            if(it != str[i].begin())    it--;
            if(it != str[i].end())  mn = min(mn, abs((*it) - pos));

            ans = max(ans, mn);
        }
        sol[q.id] = ans;
    }

    for(int i = 1; i <= Q; i++)
        printf("%lld\n", sol[i]);

    return 0;
}

Compilation message

new_home.cpp: In function 'int main()':
new_home.cpp:69:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         while(pi < stores.size() && stores[pi].st <= t)
               ~~~^~~~~~~~~~~~~~~
new_home.cpp:76:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         while(pe < ersStores.size() && ersStores[pe].dr < t)
               ~~~^~~~~~~~~~~~~~~~~~
new_home.cpp:37: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:42:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d%d", &x, &t, &st, &dr);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
new_home.cpp:54:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &x, &tm);
         ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 14456 KB Output is correct
2 Correct 18 ms 14540 KB Output is correct
3 Correct 17 ms 14540 KB Output is correct
4 Correct 13 ms 14564 KB Output is correct
5 Correct 13 ms 14692 KB Output is correct
6 Correct 14 ms 14692 KB Output is correct
7 Correct 15 ms 14692 KB Output is correct
8 Correct 14 ms 14692 KB Output is correct
9 Correct 14 ms 14840 KB Output is correct
10 Correct 14 ms 14840 KB Output is correct
11 Correct 13 ms 14840 KB Output is correct
12 Correct 14 ms 14840 KB Output is correct
13 Correct 14 ms 14840 KB Output is correct
14 Correct 14 ms 14840 KB Output is correct
15 Correct 13 ms 14840 KB Output is correct
16 Correct 14 ms 14840 KB Output is correct
17 Correct 13 ms 14840 KB Output is correct
18 Correct 14 ms 14840 KB Output is correct
19 Correct 13 ms 14840 KB Output is correct
20 Correct 14 ms 14840 KB Output is correct
21 Correct 14 ms 14840 KB Output is correct
22 Correct 14 ms 14840 KB Output is correct
23 Correct 14 ms 14840 KB Output is correct
24 Correct 14 ms 14840 KB Output is correct
25 Correct 13 ms 14840 KB Output is correct
26 Correct 13 ms 14840 KB Output is correct
27 Correct 14 ms 14840 KB Output is correct
28 Correct 14 ms 14840 KB Output is correct
29 Correct 14 ms 14840 KB Output is correct
30 Correct 13 ms 14840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 14456 KB Output is correct
2 Correct 18 ms 14540 KB Output is correct
3 Correct 17 ms 14540 KB Output is correct
4 Correct 13 ms 14564 KB Output is correct
5 Correct 13 ms 14692 KB Output is correct
6 Correct 14 ms 14692 KB Output is correct
7 Correct 15 ms 14692 KB Output is correct
8 Correct 14 ms 14692 KB Output is correct
9 Correct 14 ms 14840 KB Output is correct
10 Correct 14 ms 14840 KB Output is correct
11 Correct 13 ms 14840 KB Output is correct
12 Correct 14 ms 14840 KB Output is correct
13 Correct 14 ms 14840 KB Output is correct
14 Correct 14 ms 14840 KB Output is correct
15 Correct 13 ms 14840 KB Output is correct
16 Correct 14 ms 14840 KB Output is correct
17 Correct 13 ms 14840 KB Output is correct
18 Correct 14 ms 14840 KB Output is correct
19 Correct 13 ms 14840 KB Output is correct
20 Correct 14 ms 14840 KB Output is correct
21 Correct 14 ms 14840 KB Output is correct
22 Correct 14 ms 14840 KB Output is correct
23 Correct 14 ms 14840 KB Output is correct
24 Correct 14 ms 14840 KB Output is correct
25 Correct 13 ms 14840 KB Output is correct
26 Correct 13 ms 14840 KB Output is correct
27 Correct 14 ms 14840 KB Output is correct
28 Correct 14 ms 14840 KB Output is correct
29 Correct 14 ms 14840 KB Output is correct
30 Correct 13 ms 14840 KB Output is correct
31 Correct 2972 ms 21136 KB Output is correct
32 Correct 113 ms 21136 KB Output is correct
33 Correct 260 ms 21136 KB Output is correct
34 Correct 2316 ms 21136 KB Output is correct
35 Correct 1704 ms 21168 KB Output is correct
36 Correct 263 ms 21168 KB Output is correct
37 Correct 195 ms 21168 KB Output is correct
38 Correct 135 ms 21168 KB Output is correct
39 Correct 147 ms 21168 KB Output is correct
40 Correct 109 ms 21168 KB Output is correct
41 Correct 313 ms 21168 KB Output is correct
42 Correct 284 ms 21168 KB Output is correct
43 Correct 430 ms 21292 KB Output is correct
44 Correct 277 ms 21292 KB Output is correct
45 Correct 153 ms 21292 KB Output is correct
46 Correct 116 ms 21292 KB Output is correct
47 Correct 90 ms 21292 KB Output is correct
48 Correct 90 ms 21292 KB Output is correct
49 Correct 147 ms 21292 KB Output is correct
50 Correct 300 ms 21292 KB Output is correct
51 Correct 96 ms 21292 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5033 ms 43540 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5071 ms 44420 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 14456 KB Output is correct
2 Correct 18 ms 14540 KB Output is correct
3 Correct 17 ms 14540 KB Output is correct
4 Correct 13 ms 14564 KB Output is correct
5 Correct 13 ms 14692 KB Output is correct
6 Correct 14 ms 14692 KB Output is correct
7 Correct 15 ms 14692 KB Output is correct
8 Correct 14 ms 14692 KB Output is correct
9 Correct 14 ms 14840 KB Output is correct
10 Correct 14 ms 14840 KB Output is correct
11 Correct 13 ms 14840 KB Output is correct
12 Correct 14 ms 14840 KB Output is correct
13 Correct 14 ms 14840 KB Output is correct
14 Correct 14 ms 14840 KB Output is correct
15 Correct 13 ms 14840 KB Output is correct
16 Correct 14 ms 14840 KB Output is correct
17 Correct 13 ms 14840 KB Output is correct
18 Correct 14 ms 14840 KB Output is correct
19 Correct 13 ms 14840 KB Output is correct
20 Correct 14 ms 14840 KB Output is correct
21 Correct 14 ms 14840 KB Output is correct
22 Correct 14 ms 14840 KB Output is correct
23 Correct 14 ms 14840 KB Output is correct
24 Correct 14 ms 14840 KB Output is correct
25 Correct 13 ms 14840 KB Output is correct
26 Correct 13 ms 14840 KB Output is correct
27 Correct 14 ms 14840 KB Output is correct
28 Correct 14 ms 14840 KB Output is correct
29 Correct 14 ms 14840 KB Output is correct
30 Correct 13 ms 14840 KB Output is correct
31 Correct 2972 ms 21136 KB Output is correct
32 Correct 113 ms 21136 KB Output is correct
33 Correct 260 ms 21136 KB Output is correct
34 Correct 2316 ms 21136 KB Output is correct
35 Correct 1704 ms 21168 KB Output is correct
36 Correct 263 ms 21168 KB Output is correct
37 Correct 195 ms 21168 KB Output is correct
38 Correct 135 ms 21168 KB Output is correct
39 Correct 147 ms 21168 KB Output is correct
40 Correct 109 ms 21168 KB Output is correct
41 Correct 313 ms 21168 KB Output is correct
42 Correct 284 ms 21168 KB Output is correct
43 Correct 430 ms 21292 KB Output is correct
44 Correct 277 ms 21292 KB Output is correct
45 Correct 153 ms 21292 KB Output is correct
46 Correct 116 ms 21292 KB Output is correct
47 Correct 90 ms 21292 KB Output is correct
48 Correct 90 ms 21292 KB Output is correct
49 Correct 147 ms 21292 KB Output is correct
50 Correct 300 ms 21292 KB Output is correct
51 Correct 96 ms 21292 KB Output is correct
52 Correct 121 ms 44420 KB Output is correct
53 Correct 118 ms 44420 KB Output is correct
54 Correct 212 ms 44420 KB Output is correct
55 Execution timed out 5045 ms 44420 KB Time limit exceeded
56 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 14456 KB Output is correct
2 Correct 18 ms 14540 KB Output is correct
3 Correct 17 ms 14540 KB Output is correct
4 Correct 13 ms 14564 KB Output is correct
5 Correct 13 ms 14692 KB Output is correct
6 Correct 14 ms 14692 KB Output is correct
7 Correct 15 ms 14692 KB Output is correct
8 Correct 14 ms 14692 KB Output is correct
9 Correct 14 ms 14840 KB Output is correct
10 Correct 14 ms 14840 KB Output is correct
11 Correct 13 ms 14840 KB Output is correct
12 Correct 14 ms 14840 KB Output is correct
13 Correct 14 ms 14840 KB Output is correct
14 Correct 14 ms 14840 KB Output is correct
15 Correct 13 ms 14840 KB Output is correct
16 Correct 14 ms 14840 KB Output is correct
17 Correct 13 ms 14840 KB Output is correct
18 Correct 14 ms 14840 KB Output is correct
19 Correct 13 ms 14840 KB Output is correct
20 Correct 14 ms 14840 KB Output is correct
21 Correct 14 ms 14840 KB Output is correct
22 Correct 14 ms 14840 KB Output is correct
23 Correct 14 ms 14840 KB Output is correct
24 Correct 14 ms 14840 KB Output is correct
25 Correct 13 ms 14840 KB Output is correct
26 Correct 13 ms 14840 KB Output is correct
27 Correct 14 ms 14840 KB Output is correct
28 Correct 14 ms 14840 KB Output is correct
29 Correct 14 ms 14840 KB Output is correct
30 Correct 13 ms 14840 KB Output is correct
31 Correct 2972 ms 21136 KB Output is correct
32 Correct 113 ms 21136 KB Output is correct
33 Correct 260 ms 21136 KB Output is correct
34 Correct 2316 ms 21136 KB Output is correct
35 Correct 1704 ms 21168 KB Output is correct
36 Correct 263 ms 21168 KB Output is correct
37 Correct 195 ms 21168 KB Output is correct
38 Correct 135 ms 21168 KB Output is correct
39 Correct 147 ms 21168 KB Output is correct
40 Correct 109 ms 21168 KB Output is correct
41 Correct 313 ms 21168 KB Output is correct
42 Correct 284 ms 21168 KB Output is correct
43 Correct 430 ms 21292 KB Output is correct
44 Correct 277 ms 21292 KB Output is correct
45 Correct 153 ms 21292 KB Output is correct
46 Correct 116 ms 21292 KB Output is correct
47 Correct 90 ms 21292 KB Output is correct
48 Correct 90 ms 21292 KB Output is correct
49 Correct 147 ms 21292 KB Output is correct
50 Correct 300 ms 21292 KB Output is correct
51 Correct 96 ms 21292 KB Output is correct
52 Execution timed out 5033 ms 43540 KB Time limit exceeded
53 Halted 0 ms 0 KB -