답안 #330486

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
330486 2020-11-25T14:08:04 Z SnowFlake7 Pinball (JOI14_pinball) C++14
100 / 100
934 ms 33628 KB
#include <bits/stdc++.h>

using namespace std;

const long long MX_VAL = 1e18;
long long a[100005],b[100005],c[100005],d[100005];
long long aint[2000005],dp1[100005],dp2[100005];
map <int, int> mp;
vector <int> v;

void update(int nod, int st, int dr, int poz, long long val) {
    if (st == dr)
        aint[nod] = min(aint[nod], val);
    else {
        int md = (st + dr) / 2;
        if (poz <= md)
            update(2 * nod, st, md, poz, val);
        if (poz >= md + 1)
            update (2 * nod + 1, md + 1, dr, poz, val);
        aint[nod] = min(aint[2 * nod], aint[2 * nod + 1]);
    }
}
long long query(int nod, int st, int dr, int a, int b) {
    if (a <= st && dr <= b)
        return aint[nod];
    else {
        int md = (st + dr) / 2;
        long long ans = MX_VAL;
        if (a <= md)
        ans = min(ans, query(2 * nod, st, md, a, b));
        if (b >= md + 1)
            ans = min(ans, query(2 * nod + 1, md + 1, dr, a, b));
        return ans;
    }
}
int main ()
{
    long long n,m,nr = 0,ans = MX_VAL;
    cin >> m >> n;
    for (int i = 1;i <= m;i++) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        v.push_back(a[i]);
        v.push_back(b[i]);
        v.push_back(c[i]);
    }
    sort(v.begin(), v.end());
    for (int i = 0;i < v.size();i++) {
        if (!i || v[i] != v[i - 1])
            mp[v[i]] = ++nr;
    }
    for (int i = 1; i <= 4 * nr;i++)
        aint[i] = MX_VAL;
    for (int i = 1;i <= m;i++)
        dp1[i] = dp2[i] = MX_VAL;
    for (int i = 1;i <= m;i++) {
        if (a[i] == 1)
            dp1[i] = d[i];
        else
            dp1[i] = min(dp1[i], d[i] + query(1, 1, nr, mp[a[i]], mp[b[i]]));
        update(1, 1, nr, mp[c[i]], dp1[i]);
    }
    for (int i = 1;i <= 4 * nr;i++)
        aint[i] = MX_VAL;
    for (int i = 1;i <= m;i++) {
        if (b[i] == n)
            dp2[i] = d[i];
        else
            dp2[i] = min(dp2[i], d[i] + query(1, 1, nr, mp[a[i]], mp[b[i]]));
        update(1, 1, nr, mp[c[i]], dp2[i]);
    }
    for (int i = 1;i <= m;i++)
        ans = min(ans, dp1[i] + dp2[i] - d[i]);
    if (ans == MX_VAL)
        ans = -1;
    cout << ans;
    return 0;
}

Compilation message

pinball.cpp: In function 'int main()':
pinball.cpp:47:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |     for (int i = 0;i < v.size();i++) {
      |                    ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 2 ms 492 KB Output is correct
17 Correct 4 ms 620 KB Output is correct
18 Correct 3 ms 492 KB Output is correct
19 Correct 4 ms 620 KB Output is correct
20 Correct 4 ms 492 KB Output is correct
21 Correct 2 ms 492 KB Output is correct
22 Correct 4 ms 748 KB Output is correct
23 Correct 4 ms 748 KB Output is correct
24 Correct 4 ms 748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 2 ms 492 KB Output is correct
17 Correct 4 ms 620 KB Output is correct
18 Correct 3 ms 492 KB Output is correct
19 Correct 4 ms 620 KB Output is correct
20 Correct 4 ms 492 KB Output is correct
21 Correct 2 ms 492 KB Output is correct
22 Correct 4 ms 748 KB Output is correct
23 Correct 4 ms 748 KB Output is correct
24 Correct 4 ms 748 KB Output is correct
25 Correct 41 ms 2668 KB Output is correct
26 Correct 196 ms 7280 KB Output is correct
27 Correct 449 ms 14944 KB Output is correct
28 Correct 289 ms 10156 KB Output is correct
29 Correct 323 ms 12400 KB Output is correct
30 Correct 402 ms 11612 KB Output is correct
31 Correct 799 ms 23260 KB Output is correct
32 Correct 716 ms 19548 KB Output is correct
33 Correct 81 ms 6760 KB Output is correct
34 Correct 385 ms 17120 KB Output is correct
35 Correct 474 ms 33628 KB Output is correct
36 Correct 934 ms 33628 KB Output is correct
37 Correct 757 ms 33500 KB Output is correct
38 Correct 682 ms 33500 KB Output is correct