답안 #541134

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
541134 2022-03-22T10:28:11 Z PixelCat Olympic Bus (JOI20_ho_t4) C++14
100 / 100
600 ms 4228 KB
/* code by the cute ~~Dengdualang~~ PixelCat owo */
/*     as cute as nacho neko (aka. my wife)!     */

/*     Nhade stay for a night here               */
/*     183234 deng deng deng pixelcat oops       */
/*     (yang wang yesu)*2                        */
/*     ^ some weird stuff. nvm =w=               */

#pragma GCC optimize("O4,unroll-loops,no-stack-protector")
#include <bits/stdc++.h>
#define int LL  //__int128
#define double long double
using namespace std;
using LL = long long;
using LLL = __int128_t;
using uLL = unsigned long long;
using pii = pair<int, int>;

#define For(i, a, b) for (int i = a; i <= b; i++)
#define Fors(i, a, b, s) for (int i = a; i <= b; i += s)
#define Forr(i, a, b) for (int i = a; i >= b; i--)
#define F first
#define S second
#define L(id) (id * 2 + 1)
#define R(id) (id * 2 + 2)
#define LO(x) (x & (-x))

#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) ((int)x.size())
#define mkp make_pair

#define MOD (int)(998244353)
// #define MOD (int)((LL)1e9 + 7)
#define INF (int)(4e18)
// #define INF 1e9
#define EPS (1e-6)

#ifdef NYAOWO
#include "library/debug.hpp"
inline void USACO(const string &s) {
    cerr << "USACO: " << s << "\n";
}

#else
#define debug(...)
inline void timer() {}
inline void USACO(const string &s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}

#endif

inline void NYA() {
    ios::sync_with_stdio(false);
    cin.tie(0);
}
inline int gcd(int a, int b) {
    return __gcd(a, b);
}
inline int lcm(int a, int b) {
    return a / gcd(a, b) * b;
}
int fpow(int b, int p, const int &mod) {
    int ans = 1;
    while (p) {
        if (p & 1) ans = ans * b % mod;
        p >>= 1;
        b = b * b % mod;
    }
    return ans;
}
int fpow(int b, int p) {
    return fpow(b, p, MOD);
}
template <typename T>
inline void chmin(T &_a, const T &_b) {
    if (_b < _a) _a = _b;
}
template <typename T>
inline void chmax(T &_a, const T &_b) {
    if (_b > _a) _a = _b;
}
// mt19937_64 rng(
//     chrono::steady_clock::now().time_since_epoch().count());

struct Edge{
    int s,t,c,d;
}ed[50050];
int tag[50050];

vector<int> adj[210];
int ad[210][210];

int dist[210];
int src[210];
int dijk(int s,int t,int nope,int tg){
    // debug(s,t);

    if(nope>0){
        ed[0]=ed[nope];
        swap(ed[0].s,ed[0].t);
        adj[ed[0].s].eb(0);
    }

    memset(dist,0x3f3f3f3f,sizeof(dist));
    priority_queue<pii,vector<pii>,greater<pii>> pq;
    pq.emplace(0,s);
    dist[s]=0;
    while(!pq.empty()){
        int d=pq.top().F;
        int now=pq.top().S;
        pq.pop();
        if(dist[now]<d) continue;
        for(auto &eid:adj[now]) if(eid!=nope){
            auto &e=ed[eid];
            if(dist[e.t]>d+e.c){
                dist[e.t]=d+e.c;
                pq.emplace(d+e.c,e.t);
                src[e.t]=eid;
            }
        }
    }
    if(nope>0){
        adj[ed[0].s].pop_back();
    }

    if(dist[t]>=INF) return INF;

    if(tg){
        int now=t;
        while(now!=s){
            tag[src[now]]^=tg;
            now=ed[src[now]].s;
        }
    }

    return dist[t];
}

int32_t main() {
    NYA();
    // nyaacho >/////<
    // miku sama bless me >/////<
    int n,m; cin>>n>>m;
    memset(ad,0x3f3f3f3f,sizeof(ad));
    For(i,1,n) ad[i][i]=0;
    For(i,1,m){
        auto &e=ed[i];
        cin>>e.s>>e.t>>e.c>>e.d;
        adj[e.s].eb(i);
        chmin(ad[e.s][e.t],e.c);
    }
    For(k,1,n) For(i,1,n) For(j,1,n){
        chmin(ad[i][j],ad[i][k]+ad[k][j]);
    }
    int m1n=dijk(1,n,-1,1);
    int mn1=dijk(n,1,-1,2);
    int ans=m1n+mn1;
    For(eid,1,m){
        auto &e=ed[eid];
        int d1n,dn1;
        if(tag[eid]&1) d1n=dijk(1,n,eid,0);
        else d1n=min(m1n,ad[1][e.t]+ad[e.s][n]+e.c);
        if(tag[eid]&2) dn1=dijk(n,1,eid,0);
        else dn1=min(mn1,ad[n][e.t]+ad[e.s][1]+e.c);
        chmin(ans,d1n+dn1+e.d);
        // debug(eid,d1n,dn1);
    }
    if(ans>=INF) cout<<"-1\n";
    else cout<<ans<<"\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 724 KB Output is correct
2 Correct 7 ms 596 KB Output is correct
3 Correct 10 ms 724 KB Output is correct
4 Correct 10 ms 724 KB Output is correct
5 Correct 1 ms 724 KB Output is correct
6 Correct 7 ms 596 KB Output is correct
7 Correct 1 ms 592 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
9 Correct 1 ms 724 KB Output is correct
10 Correct 22 ms 732 KB Output is correct
11 Correct 21 ms 724 KB Output is correct
12 Correct 21 ms 748 KB Output is correct
13 Correct 9 ms 732 KB Output is correct
14 Correct 9 ms 736 KB Output is correct
15 Correct 10 ms 724 KB Output is correct
16 Correct 10 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 2900 KB Output is correct
2 Correct 30 ms 2996 KB Output is correct
3 Correct 30 ms 2900 KB Output is correct
4 Correct 10 ms 780 KB Output is correct
5 Correct 9 ms 724 KB Output is correct
6 Correct 9 ms 716 KB Output is correct
7 Correct 8 ms 596 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
9 Correct 28 ms 3280 KB Output is correct
10 Correct 27 ms 3200 KB Output is correct
11 Correct 28 ms 3272 KB Output is correct
12 Correct 33 ms 3276 KB Output is correct
13 Correct 30 ms 3248 KB Output is correct
14 Correct 35 ms 3328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 724 KB Output is correct
2 Correct 8 ms 596 KB Output is correct
3 Correct 21 ms 2692 KB Output is correct
4 Correct 8 ms 596 KB Output is correct
5 Correct 27 ms 3236 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 25 ms 3192 KB Output is correct
9 Correct 25 ms 3300 KB Output is correct
10 Correct 23 ms 3228 KB Output is correct
11 Correct 24 ms 3284 KB Output is correct
12 Correct 22 ms 3284 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 1 ms 596 KB Output is correct
16 Correct 1 ms 596 KB Output is correct
17 Correct 1 ms 592 KB Output is correct
18 Correct 1 ms 596 KB Output is correct
19 Correct 24 ms 3236 KB Output is correct
20 Correct 23 ms 3240 KB Output is correct
21 Correct 24 ms 3260 KB Output is correct
22 Correct 24 ms 3288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 724 KB Output is correct
2 Correct 7 ms 596 KB Output is correct
3 Correct 10 ms 724 KB Output is correct
4 Correct 10 ms 724 KB Output is correct
5 Correct 1 ms 724 KB Output is correct
6 Correct 7 ms 596 KB Output is correct
7 Correct 1 ms 592 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
9 Correct 1 ms 724 KB Output is correct
10 Correct 22 ms 732 KB Output is correct
11 Correct 21 ms 724 KB Output is correct
12 Correct 21 ms 748 KB Output is correct
13 Correct 9 ms 732 KB Output is correct
14 Correct 9 ms 736 KB Output is correct
15 Correct 10 ms 724 KB Output is correct
16 Correct 10 ms 724 KB Output is correct
17 Correct 28 ms 2900 KB Output is correct
18 Correct 30 ms 2996 KB Output is correct
19 Correct 30 ms 2900 KB Output is correct
20 Correct 10 ms 780 KB Output is correct
21 Correct 9 ms 724 KB Output is correct
22 Correct 9 ms 716 KB Output is correct
23 Correct 8 ms 596 KB Output is correct
24 Correct 1 ms 596 KB Output is correct
25 Correct 28 ms 3280 KB Output is correct
26 Correct 27 ms 3200 KB Output is correct
27 Correct 28 ms 3272 KB Output is correct
28 Correct 33 ms 3276 KB Output is correct
29 Correct 30 ms 3248 KB Output is correct
30 Correct 35 ms 3328 KB Output is correct
31 Correct 8 ms 724 KB Output is correct
32 Correct 8 ms 596 KB Output is correct
33 Correct 21 ms 2692 KB Output is correct
34 Correct 8 ms 596 KB Output is correct
35 Correct 27 ms 3236 KB Output is correct
36 Correct 1 ms 596 KB Output is correct
37 Correct 1 ms 596 KB Output is correct
38 Correct 25 ms 3192 KB Output is correct
39 Correct 25 ms 3300 KB Output is correct
40 Correct 23 ms 3228 KB Output is correct
41 Correct 24 ms 3284 KB Output is correct
42 Correct 22 ms 3284 KB Output is correct
43 Correct 1 ms 596 KB Output is correct
44 Correct 1 ms 596 KB Output is correct
45 Correct 1 ms 596 KB Output is correct
46 Correct 1 ms 596 KB Output is correct
47 Correct 1 ms 592 KB Output is correct
48 Correct 1 ms 596 KB Output is correct
49 Correct 24 ms 3236 KB Output is correct
50 Correct 23 ms 3240 KB Output is correct
51 Correct 24 ms 3260 KB Output is correct
52 Correct 24 ms 3288 KB Output is correct
53 Correct 28 ms 3244 KB Output is correct
54 Correct 30 ms 3292 KB Output is correct
55 Correct 30 ms 3284 KB Output is correct
56 Correct 10 ms 724 KB Output is correct
57 Correct 11 ms 724 KB Output is correct
58 Correct 100 ms 3128 KB Output is correct
59 Correct 109 ms 3412 KB Output is correct
60 Correct 112 ms 3560 KB Output is correct
61 Correct 81 ms 3540 KB Output is correct
62 Correct 112 ms 3488 KB Output is correct
63 Correct 107 ms 3548 KB Output is correct
64 Correct 600 ms 4228 KB Output is correct
65 Correct 547 ms 4136 KB Output is correct
66 Correct 529 ms 4160 KB Output is correct
67 Correct 13 ms 3160 KB Output is correct
68 Correct 28 ms 4044 KB Output is correct
69 Correct 27 ms 3992 KB Output is correct
70 Correct 29 ms 4064 KB Output is correct
71 Correct 31 ms 4048 KB Output is correct
72 Correct 28 ms 4044 KB Output is correct
73 Correct 30 ms 4176 KB Output is correct
74 Correct 29 ms 4100 KB Output is correct