Submission #703223

# Submission time Handle Problem Language Result Execution time Memory
703223 2023-02-26T15:26:53 Z guagua0407 Olympic Bus (JOI20_ho_t4) C++17
37 / 100
1000 ms 3428 KB
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define f first
#define s second
#define all(x) x.begin(),x.end() 
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

void setIO(string s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}

struct edge{
    int a,b,c,d;
};

const int mxn=205;
vector<tuple<int,int,int>> adj[2][mxn];
int n,m;
ll dist[5][mxn];
vector<int> from[4][mxn];

void dijk(int type,int rot,int st,int en){
    dist[type][st]=0;
    priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>> pq;
    pq.push({0,st});
    while(!pq.empty()){
        auto tmp=pq.top();
        pq.pop();
        ll len=tmp.f;
        int v=tmp.s;
        if(len!=dist[type][v]) continue;
        for(auto u:adj[rot][v]){
            int nxt,w,id;
            tie(nxt,w,id)=u;
            if(dist[type][v]+1ll*w<dist[type][nxt]){
                dist[type][nxt]=dist[type][v]+1ll*w;
                from[type][nxt]=from[type][v];
                from[type][nxt].push_back(id);
                pq.push({dist[type][nxt],nxt});
            }
        }
    }
    sort(all(from[type][en]));
}

ll dijk2(int type,int rot,int st,int en,int ban){
    for(int j=1;j<=n;j++){
        dist[type][j]=0x3f3f3f3f3f3f3f3f;
    }
    dist[type][st]=0;
    priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>> pq;
    pq.push({0,st});
    while(!pq.empty()){
        auto tmp=pq.top();
        pq.pop();
        ll len=tmp.f;
        int v=tmp.s;
        if(len!=dist[type][v]) continue;
        for(auto u:adj[rot][v]){
            int nxt,w,id;
            tie(nxt,w,id)=u;
            if(id==ban) continue;
            if(dist[type][v]+1ll*w<dist[type][nxt]){
                dist[type][nxt]=dist[type][v]+1ll*w;
                pq.push({dist[type][nxt],nxt});
            }
        }
    }
    return dist[type][en];
}

int main() {_
    //setIO("wayne");
    cin>>n>>m;
    edge E[m];
    for(int i=0;i<m;i++){
        int a,b,c,d;
        cin>>a>>b>>c>>d;
        E[i]={a,b,c,d};
        adj[0][a].push_back({b,c,i});
        adj[1][b].push_back({a,c,i});
    }
    memset(dist,0x3f3f3f3f,sizeof(dist));
    dijk(0,0,1,n);
    dijk(1,1,1,n);
    dijk(2,0,n,1);
    dijk(3,1,n,1);
    ll ans=dist[0][n]+dist[2][1];
    for(int i=0;i<m;i++){
        ll a,b,c,d;
        a=E[i].a,b=E[i].b,c=E[i].c,d=E[i].d;
        ll ans1;
        ll ans2;
        {
            if(upper_bound(all(from[0][n]),i)-lower_bound(all(from[0][n]),i)>=1){
                ans1=min(dijk2(4,0,1,b,i)+c+dijk2(4,1,n,a,i),dijk2(4,0,1,n,i));
            }
            else{
                ans1=min(dist[0][b]+c+dist[3][a],dist[0][n]);
            }
        }
        {
            if(upper_bound(all(from[2][1]),i)-lower_bound(all(from[2][1]),i)>=1){
                ans2=min(dijk2(4,0,n,b,i)+c+dijk2(4,1,1,a,i),dijk2(4,0,n,1,i));
            }
            else{
                ans2=min(dist[2][b]+c+dist[1][a],dist[2][1]);
            }
        }
        ans=min(ans,ans1+ans2+d);
    }
    cout<<(ans>=0x3f3f3f3f3f3f3f3f?-1:ans);
    return 0;
}
//maybe its multiset not set

Compilation message

ho_t4.cpp: In function 'void setIO(std::string)':
ho_t4.cpp:12:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ho_t4.cpp:13:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |     freopen((s + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 468 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 3 ms 340 KB Output is correct
4 Correct 4 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 40 ms 980 KB Output is correct
11 Correct 40 ms 1008 KB Output is correct
12 Correct 39 ms 980 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 3 ms 428 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
16 Correct 3 ms 448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 3152 KB Output is correct
2 Correct 23 ms 3184 KB Output is correct
3 Correct 23 ms 3132 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 18 ms 3008 KB Output is correct
10 Correct 19 ms 3052 KB Output is correct
11 Correct 26 ms 3156 KB Output is correct
12 Correct 31 ms 3008 KB Output is correct
13 Correct 31 ms 3136 KB Output is correct
14 Correct 23 ms 3284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 15 ms 2312 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 22 ms 2980 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 17 ms 2960 KB Output is correct
9 Correct 17 ms 3060 KB Output is correct
10 Correct 18 ms 3028 KB Output is correct
11 Correct 22 ms 3100 KB Output is correct
12 Correct 18 ms 3060 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 20 ms 3156 KB Output is correct
20 Correct 18 ms 3108 KB Output is correct
21 Correct 18 ms 3028 KB Output is correct
22 Correct 18 ms 3028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 468 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 3 ms 340 KB Output is correct
4 Correct 4 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 40 ms 980 KB Output is correct
11 Correct 40 ms 1008 KB Output is correct
12 Correct 39 ms 980 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 3 ms 428 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
16 Correct 3 ms 448 KB Output is correct
17 Correct 24 ms 3152 KB Output is correct
18 Correct 23 ms 3184 KB Output is correct
19 Correct 23 ms 3132 KB Output is correct
20 Correct 2 ms 468 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 18 ms 3008 KB Output is correct
26 Correct 19 ms 3052 KB Output is correct
27 Correct 26 ms 3156 KB Output is correct
28 Correct 31 ms 3008 KB Output is correct
29 Correct 31 ms 3136 KB Output is correct
30 Correct 23 ms 3284 KB Output is correct
31 Correct 2 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 15 ms 2312 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 22 ms 2980 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 0 ms 340 KB Output is correct
38 Correct 17 ms 2960 KB Output is correct
39 Correct 17 ms 3060 KB Output is correct
40 Correct 18 ms 3028 KB Output is correct
41 Correct 22 ms 3100 KB Output is correct
42 Correct 18 ms 3060 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 0 ms 340 KB Output is correct
45 Correct 0 ms 340 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 0 ms 340 KB Output is correct
48 Correct 0 ms 340 KB Output is correct
49 Correct 20 ms 3156 KB Output is correct
50 Correct 18 ms 3108 KB Output is correct
51 Correct 18 ms 3028 KB Output is correct
52 Correct 18 ms 3028 KB Output is correct
53 Correct 26 ms 3004 KB Output is correct
54 Correct 25 ms 3120 KB Output is correct
55 Correct 23 ms 3016 KB Output is correct
56 Correct 2 ms 340 KB Output is correct
57 Correct 2 ms 340 KB Output is correct
58 Correct 176 ms 2860 KB Output is correct
59 Correct 239 ms 2808 KB Output is correct
60 Correct 199 ms 2844 KB Output is correct
61 Correct 135 ms 2748 KB Output is correct
62 Correct 182 ms 2872 KB Output is correct
63 Correct 221 ms 2772 KB Output is correct
64 Execution timed out 1087 ms 3428 KB Time limit exceeded
65 Halted 0 ms 0 KB -