답안 #13678

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
13678 2015-02-27T13:22:32 Z gs14004 Pinball (JOI14_pinball) C++14
51 / 100
1000 ms 25028 KB
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long lint;

struct sti{int s,e,d,x;}a[100005];
struct sti2{int end, dest, cost, hi;};

bool cmp(sti2 a, sti2 b){return a.hi < b.hi;}

vector<int> v;
vector<sti2> pan[300005];
vector<lint> dp_low[300005], dp_high[300005];

int n,m;

void input(){
    scanf("%d %d",&n,&m);
    v.push_back(1);
    v.push_back(m);
    for (int i=1; i<=n; i++) {
        scanf("%d %d %d %d",&a[i].s,&a[i].e,&a[i].d,&a[i].x);
        v.push_back(a[i].s);
        v.push_back(a[i].e);
        v.push_back(a[i].d);
    }
    sort(v.begin(),v.end());
    v.resize(unique(v.begin(),v.end()) - v.begin());
    for (int i=1; i<=n; i++) {
        a[i].s = (int)(lower_bound(v.begin(),v.end(),a[i].s) - v.begin());
        a[i].e = (int)(lower_bound(v.begin(),v.end(),a[i].e) - v.begin());
        a[i].d = (int)(lower_bound(v.begin(),v.end(),a[i].d) - v.begin());
    }
    pan[0].push_back({0,0,0,0});
    pan[v.size()-1].push_back({(int)v.size()-1,(int)v.size()-1,0,0});
    for (int i=1; i<=n; i++) {
        pan[a[i].s].push_back({a[i].e,a[i].d,a[i].x,i});
    }
    for (int i=0; i<v.size(); i++) {
        sort(pan[i].begin(),pan[i].end(),cmp);
        dp_low[i].resize(pan[i].size());
        dp_high[i].resize(pan[i].size());
    }
}

int main(){
    input();
    int l = (int)v.size();
    for (int i=l-1; i>=0; i--) {
        for (int j=0; j<pan[i].size(); j++) {
            dp_high[i][j] = 1e18;
            if(i == l-1 && j == 0){
                dp_high[i][j] = 0;
            }
            for (int k=i; k<l; k++) {
                for (int m=0; m<pan[k].size(); m++) {
                    if(pan[k][m].hi >= pan[i][j].hi) continue;
                    if(pan[k][m].dest > pan[i][j].end) continue;
                    dp_high[i][j] = min(dp_high[i][j],dp_high[k][m]);
                }
            }
            dp_high[i][j] += pan[i][j].cost;
        }
    }
    for (int i=l-1; i>=0; i--) {
        for (int j=(int)pan[i].size()-1; j>=0; j--) {
            dp_low[i][j] = 1e18;
            for (int k=i; k<l; k++) {
                for (int m=0; m<pan[k].size(); m++) {
                    if(pan[k][m].hi <= pan[i][j].hi) continue;
                    if(k <= pan[i][j].dest && pan[i][j].dest <= pan[k][m].end){
                        dp_low[i][j] = min(dp_low[i][j],dp_low[k][m]);
                    }
                }
            }
            dp_low[i][j] += pan[i][j].cost;
            dp_low[i][j] = min(dp_low[i][j],dp_high[i][j]);
        }
    }
    if(dp_low[0][0] >= 1e18) puts("-1");
    else printf("%lld",dp_low[0][0]);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 24240 KB Output is correct
2 Correct 0 ms 24240 KB Output is correct
3 Correct 0 ms 24240 KB Output is correct
4 Correct 3 ms 24240 KB Output is correct
5 Correct 0 ms 24240 KB Output is correct
6 Correct 0 ms 24240 KB Output is correct
7 Correct 0 ms 24240 KB Output is correct
8 Correct 0 ms 24240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 24240 KB Output is correct
2 Correct 4 ms 24240 KB Output is correct
3 Correct 0 ms 24240 KB Output is correct
4 Correct 4 ms 24240 KB Output is correct
5 Correct 3 ms 24240 KB Output is correct
6 Correct 4 ms 24240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 24240 KB Output is correct
2 Correct 4 ms 24240 KB Output is correct
3 Correct 17 ms 24240 KB Output is correct
4 Correct 12 ms 24240 KB Output is correct
5 Correct 19 ms 24240 KB Output is correct
6 Correct 16 ms 24240 KB Output is correct
7 Correct 11 ms 24240 KB Output is correct
8 Correct 19 ms 24240 KB Output is correct
9 Correct 14 ms 24240 KB Output is correct
10 Correct 21 ms 24240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1000 ms 25028 KB Program timed out
2 Halted 0 ms 0 KB -