Submission #997350

# Submission time Handle Problem Language Result Execution time Memory
997350 2024-06-12T07:32:17 Z saddd Train (APIO24_train) C++17
5 / 100
84 ms 20852 KB
#include<bits/stdc++.h>
#include<fstream>
using namespace std;
#define sz(a) (int)a.size()
#define ALL(v) v.begin(), v.end()
#define ALLR(v) v.rbegin(), v.rend()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
#define mpp make_pair
const ld PI = 3.14159265359, prec = 1e-9;;
//using u128 = __uint128_t;
//const int x[4] = {1, 0, -1, 0};
//const int y[4] = {0, -1, 0, 1};
const ll mod = 1000003, pr = 31;
const int mxn = 3e5 + 5, mxq = 1e5 + 5, sq = 500, mxv = 5e4 + 1;
//const int base = (1 <<18);
const ll inf = 1e17 + 5, neg = -69420, inf2 = 1e14;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
// have fun!
#include "train.h"

#include <vector>


struct E{
    ll x, y, a, b, c;
    bool operator <(const E &other){
        return(a < other.a);
    }
};

int n, m, w;
vt<E>edge;
vt<pll>food;
vt<int>comp;
bool cmp(int a, int b){
    return(edge[a].b < edge[b].b);
}
ll mn[mxn + 1], t[mxn + 1], dp[mxn + 1];
ll solve(){
    sort(ALL(edge));  sort(ALL(comp), cmp); sort(ALL(food));
    int rp = 0;
    ll ans = inf;
    for(int i = 0; i < n; i++)mn[i] = inf;
    mn[0] = 0; 
    for(int i = 0; i < m; i++){
		
        while(rp < sz(comp) && edge[comp[rp]].b <= edge[i].a){
            if(dp[comp[rp]] == inf){
				rp++;
				continue;	
			}
            auto [x, y, a, b, c] = edge[comp[rp]];
            int id = lower_bound(ALL(food), mpp(b + 1, 1LL * -1)) - food.begin();
            mn[y] = min(mn[y], dp[comp[rp]] - t[y] * id);
            rp++;
        }
		
        auto [x, y, a, b, c] = edge[i];
        int id = lower_bound(ALL(food), mpp(a, 1LL * -1)) - food.begin() - 1;
        if(id != -1 && food[id].se >= a)id--;
        if(mn[x] == inf)dp[i] = inf;
        else dp[i] = mn[x] + 1LL * (id + 1) * t[x] + c;
        if(y == n - 1){
            int id = lower_bound(ALL(food), mpp(b + 1, 1LL * -1)) - food.begin();
            ans = min(ans, dp[i] + (w - id) * t[n - 1]);
        }
    }
    if(ans == inf)ans = -1;
    return(ans);
}
long long solve(int N, int M, int W, std::vector<int> T, std::vector<int> X, std::vector<int> Y,
                std::vector<int> A, std::vector<int> B, std::vector<int> C, std::vector<int> L,
                std::vector<int> R) {
    edge.clear(); food.clear(); comp.clear();
    n = N; m = M; w = W;
    for(int i = 0; i < n; i++)t[i] = T[i];
    for(int i = 0; i < m; i++){
        edge.pb({X[i], Y[i], A[i], B[i], C[i]}); comp.pb(i);
    }
    for(int i = 0; i < w; i++){
        food.pb(mpp(L[i], R[i]));
    }
	return(solve());
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4444 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 48 ms 15376 KB Correct.
2 Correct 57 ms 16240 KB Correct.
3 Correct 1 ms 4444 KB Correct.
4 Correct 7 ms 5204 KB Correct.
5 Correct 1 ms 4444 KB Correct.
6 Correct 47 ms 15356 KB Correct.
7 Correct 1 ms 4444 KB Correct.
8 Correct 46 ms 16080 KB Correct.
9 Correct 59 ms 16588 KB Correct.
# Verdict Execution time Memory Grader output
1 Correct 48 ms 15376 KB Correct.
2 Correct 57 ms 16240 KB Correct.
3 Correct 1 ms 4444 KB Correct.
4 Correct 7 ms 5204 KB Correct.
5 Correct 1 ms 4444 KB Correct.
6 Correct 47 ms 15356 KB Correct.
7 Correct 1 ms 4444 KB Correct.
8 Correct 46 ms 16080 KB Correct.
9 Correct 59 ms 16588 KB Correct.
10 Correct 75 ms 20688 KB Correct.
11 Incorrect 84 ms 20852 KB Wrong Answer.
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4444 KB Wrong Answer.
2 Halted 0 ms 0 KB -