Submission #94852

# Submission time Handle Problem Language Result Execution time Memory
94852 2019-01-24T12:43:53 Z easrui Pinball (JOI14_pinball) C++14
51 / 100
52 ms 16248 KB
#include <bits/stdc++.h>
using namespace std;
const int MaxM = 1010;
const long long INF = 1e15;
int M,N;
long long ans=INF,cnt,DL[MaxM][MaxM],DR[MaxM][MaxM];
struct Pin {
    int A,B,C,D;
} P[MaxM];
vector<int> pos;
int main()
{
    //freopen("input.txt","r",stdin);
    ios_base::sync_with_stdio(0),cin.tie(0);
    cin >> M >> N;
    for(int i=1; i<=M; i++) {
        cin >> P[i].A >> P[i].B >> P[i].C >> P[i].D;
        pos.push_back(P[i].C);
    }
    pos.push_back(1);
    pos.push_back(N);
    sort(pos.begin(),pos.end());
    pos.erase(unique(pos.begin(),pos.end()),pos.end());
    for(int i=1; i<=M; i++) {
        P[i].A = lower_bound(pos.begin(),pos.end(),P[i].A)-pos.begin();
        P[i].B = upper_bound(pos.begin(),pos.end(),P[i].B)-pos.begin()-1;
        P[i].C = lower_bound(pos.begin(),pos.end(),P[i].C)-pos.begin();
    }
    int sz = pos.size();
    for(int i=0; i<=M; i++) {
        for(int l=0; l<sz; l++)
            DL[l][i] = INF;
        for(int r=0; r<sz; r++)
            DR[r][i] = INF;
    }
    DL[0][0] = 0;
    DR[sz-1][0] = 0;
    for(int i=0; i<M; i++) {
        for(int l=sz-1; l>=0; l--) {
            if(l<sz-1)
                DL[l][i] = min(DL[l][i],DL[l+1][i]);
            DL[l][i+1] = min(DL[l][i+1],DL[l][i]);
            bool left = P[i+1].A<=l && l<P[i+1].C;
            if(left)
                DL[P[i+1].C][i+1] = min(DL[P[i+1].C][i+1],DL[l][i]+P[i+1].D);
        }
        for(int r=0; r<sz; r++) {
            if(r>0)
                DR[r][i] = min(DR[r][i],DR[r-1][i]);
            DR[r][i+1] = min(DR[r][i+1],DR[r][i]);
            bool right = P[i+1].B>=r && r>P[i+1].C;
            if(right)
                DR[P[i+1].C][i+1] = min(DR[P[i+1].C][i+1],DR[r][i]+P[i+1].D);
        }
    }
    for(int i=1; i<=M; i++)
        ans = min(ans,DL[P[i].A][i-1]+DR[P[i].B][i-1]+P[i].D);
    if(ans==INF)
        cout << -1;
    else
        cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 760 KB Output is correct
10 Correct 3 ms 1528 KB Output is correct
11 Correct 3 ms 1784 KB Output is correct
12 Correct 4 ms 2680 KB Output is correct
13 Correct 4 ms 2680 KB Output is correct
14 Correct 4 ms 2552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 760 KB Output is correct
10 Correct 3 ms 1528 KB Output is correct
11 Correct 3 ms 1784 KB Output is correct
12 Correct 4 ms 2680 KB Output is correct
13 Correct 4 ms 2680 KB Output is correct
14 Correct 4 ms 2552 KB Output is correct
15 Correct 2 ms 760 KB Output is correct
16 Correct 5 ms 3576 KB Output is correct
17 Correct 28 ms 10104 KB Output is correct
18 Correct 3 ms 1012 KB Output is correct
19 Correct 48 ms 14840 KB Output is correct
20 Correct 16 ms 8060 KB Output is correct
21 Correct 11 ms 8312 KB Output is correct
22 Correct 52 ms 16248 KB Output is correct
23 Correct 45 ms 16248 KB Output is correct
24 Correct 46 ms 16244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 760 KB Output is correct
10 Correct 3 ms 1528 KB Output is correct
11 Correct 3 ms 1784 KB Output is correct
12 Correct 4 ms 2680 KB Output is correct
13 Correct 4 ms 2680 KB Output is correct
14 Correct 4 ms 2552 KB Output is correct
15 Correct 2 ms 760 KB Output is correct
16 Correct 5 ms 3576 KB Output is correct
17 Correct 28 ms 10104 KB Output is correct
18 Correct 3 ms 1012 KB Output is correct
19 Correct 48 ms 14840 KB Output is correct
20 Correct 16 ms 8060 KB Output is correct
21 Correct 11 ms 8312 KB Output is correct
22 Correct 52 ms 16248 KB Output is correct
23 Correct 45 ms 16248 KB Output is correct
24 Correct 46 ms 16244 KB Output is correct
25 Runtime error 25 ms 9592 KB Execution killed with signal 11 (could be triggered by violating memory limits)
26 Halted 0 ms 0 KB -