답안 #660620

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
660620 2022-11-22T16:48:24 Z Ronin13 Pinball (JOI14_pinball) C++14
100 / 100
578 ms 33564 KB
#include <bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
#define ull unsigned ll
using namespace std;
const int nmax = 3e5 + 1;
const ll linf = 1e18 + 1;

vector <ll> t(4 * nmax, linf);

void update(int v, int l, int r, int pos, ll val){
    if(l > pos || r < pos) return;
    if(l == r){
        t[v] = val;
        return;
    }
    int m = (l + r) / 2;
    update(2 * v, l, m, pos, val);
    update(2 * v + 1, m + 1, r, pos, val);
    t[v] = min(t[2 * v], t[2 * v + 1]);
}

ll get(int v, int l, int r, int st, int fin){
    if(l > fin || r < st) return linf;
    if(l >= st && r <= fin){
        return t[v];
    }
    int m = (l + r) / 2;
    return min(get(2 * v, l, m, st, fin),
               get(2 * v + 1, m + 1, r, st, fin));
}

int main(){
    #ifndef ONLINE_JUDGE
    //freopen("in.txt", "r", stdin);
   // freopen("out.txt", "w", stdout);
    #endif // ONLINE_JUDGE
    int m, n; cin >> m >> n;
    vector <int> cmp;
    map <int,int> mp;
    ll a[m + 1], b[m + 1], c[m + 1], d[m + 1];
    for(int i = 1; i <= m; i++){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        cmp.pb(a[i]);
        cmp.pb(b[i]);
        cmp.pb(c[i]);
    }
    cmp.pb(1);
    cmp.pb(n);
    sort(cmp.begin(), cmp.end());
    for(int i = 0; i < cmp.size(); i++){
        mp[cmp[i]] = i + 1;
    }
    for(int i = 1; i <= m; i++){
        a[i] = mp[a[i]];
        b[i] = mp[b[i]];
        c[i] = mp[c[i]];
    }
    int last = mp[n], f = mp[1];
    for(int i = 1; i <= last; i++)
        update(1, 1, last, i, linf);
    update(1, 1, last, f, 0);
    ll DP[m + 1], dp[m + 1];
    fill(DP + 1, DP + m + 1, linf);
    fill(dp + 1, dp + m + 1, linf);
    for(int i = 1; i <= m; i++){
        ll v = get(1, 1, last, a[i], b[i]);
        dp[i] = v + d[i];
        dp[i] = min(dp[i], linf);
        ll u = get(1, 1, last, c[i], c[i]);
        if(u > dp[i])update(1, 1, last,  c[i], dp[i]);
    }

    for(int i = 1; i <= last; i++)
        update(1, 1, last, i, linf);
    update(1, 1, last, last, 0);

    for(int i = 1; i <= m; i++){
        ll v = get(1, 1, last, a[i], b[i]);
        DP[i] = v + d[i];
        DP[i] = min(DP[i], linf);
        ll u = get(1, 1, last, c[i], c[i]);
        if(u > DP[i])update(1, 1,  last, c[i], DP[i]);
    }
    ll ans = linf;
    for(int i = 1; i <= m; i++){
        ans = min(ans, dp[i] + DP[i] - d[i]);
    }
    for(int i = 1; i <= m; i++){
        if(dp[i] == linf) dp[i] = -1;
        if(DP[i] == linf) DP[i] = -1;
        //cout << dp[i] << ' ' << DP[i] << "\n";
    }
    if(ans == linf)
        cout << -1;
    else cout << ans;
}

Compilation message

pinball.cpp: In function 'int main()':
pinball.cpp:56:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |     for(int i = 0; i < cmp.size(); i++){
      |                    ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 9684 KB Output is correct
2 Correct 4 ms 9712 KB Output is correct
3 Correct 4 ms 9684 KB Output is correct
4 Correct 4 ms 9712 KB Output is correct
5 Correct 5 ms 9684 KB Output is correct
6 Correct 4 ms 9684 KB Output is correct
7 Correct 4 ms 9684 KB Output is correct
8 Correct 5 ms 9632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 9684 KB Output is correct
2 Correct 4 ms 9712 KB Output is correct
3 Correct 4 ms 9684 KB Output is correct
4 Correct 4 ms 9712 KB Output is correct
5 Correct 5 ms 9684 KB Output is correct
6 Correct 4 ms 9684 KB Output is correct
7 Correct 4 ms 9684 KB Output is correct
8 Correct 5 ms 9632 KB Output is correct
9 Correct 5 ms 9684 KB Output is correct
10 Correct 5 ms 9684 KB Output is correct
11 Correct 5 ms 9684 KB Output is correct
12 Correct 5 ms 9684 KB Output is correct
13 Correct 5 ms 9708 KB Output is correct
14 Correct 5 ms 9716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 9684 KB Output is correct
2 Correct 4 ms 9712 KB Output is correct
3 Correct 4 ms 9684 KB Output is correct
4 Correct 4 ms 9712 KB Output is correct
5 Correct 5 ms 9684 KB Output is correct
6 Correct 4 ms 9684 KB Output is correct
7 Correct 4 ms 9684 KB Output is correct
8 Correct 5 ms 9632 KB Output is correct
9 Correct 5 ms 9684 KB Output is correct
10 Correct 5 ms 9684 KB Output is correct
11 Correct 5 ms 9684 KB Output is correct
12 Correct 5 ms 9684 KB Output is correct
13 Correct 5 ms 9708 KB Output is correct
14 Correct 5 ms 9716 KB Output is correct
15 Correct 5 ms 9684 KB Output is correct
16 Correct 5 ms 9684 KB Output is correct
17 Correct 8 ms 9848 KB Output is correct
18 Correct 7 ms 9812 KB Output is correct
19 Correct 8 ms 9812 KB Output is correct
20 Correct 8 ms 9848 KB Output is correct
21 Correct 6 ms 9812 KB Output is correct
22 Correct 8 ms 9848 KB Output is correct
23 Correct 7 ms 9844 KB Output is correct
24 Correct 10 ms 9940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 9684 KB Output is correct
2 Correct 4 ms 9712 KB Output is correct
3 Correct 4 ms 9684 KB Output is correct
4 Correct 4 ms 9712 KB Output is correct
5 Correct 5 ms 9684 KB Output is correct
6 Correct 4 ms 9684 KB Output is correct
7 Correct 4 ms 9684 KB Output is correct
8 Correct 5 ms 9632 KB Output is correct
9 Correct 5 ms 9684 KB Output is correct
10 Correct 5 ms 9684 KB Output is correct
11 Correct 5 ms 9684 KB Output is correct
12 Correct 5 ms 9684 KB Output is correct
13 Correct 5 ms 9708 KB Output is correct
14 Correct 5 ms 9716 KB Output is correct
15 Correct 5 ms 9684 KB Output is correct
16 Correct 5 ms 9684 KB Output is correct
17 Correct 8 ms 9848 KB Output is correct
18 Correct 7 ms 9812 KB Output is correct
19 Correct 8 ms 9812 KB Output is correct
20 Correct 8 ms 9848 KB Output is correct
21 Correct 6 ms 9812 KB Output is correct
22 Correct 8 ms 9848 KB Output is correct
23 Correct 7 ms 9844 KB Output is correct
24 Correct 10 ms 9940 KB Output is correct
25 Correct 44 ms 11272 KB Output is correct
26 Correct 123 ms 14652 KB Output is correct
27 Correct 341 ms 21092 KB Output is correct
28 Correct 386 ms 19452 KB Output is correct
29 Correct 257 ms 18752 KB Output is correct
30 Correct 461 ms 20380 KB Output is correct
31 Correct 521 ms 27324 KB Output is correct
32 Correct 516 ms 25132 KB Output is correct
33 Correct 77 ms 14284 KB Output is correct
34 Correct 236 ms 21556 KB Output is correct
35 Correct 430 ms 33564 KB Output is correct
36 Correct 578 ms 33512 KB Output is correct
37 Correct 502 ms 33516 KB Output is correct
38 Correct 492 ms 33420 KB Output is correct