답안 #524470

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
524470 2022-02-09T09:01:49 Z alirezasamimi100 Wild Boar (JOI18_wild_boar) C++17
47 / 100
18000 ms 932 KB
/*#pragma GCC optimize("Ofast,unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma,tune=native")*/
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,fma")
#include <bits/stdc++.h>
using namespace std;
using ll=long long int;
using ld=long double;
using pll=pair<ll,ll>;
using pii=pair<int,int>;
using point=complex<double>;
#define F first
#define S second
//#define X real()
//#define Y imag()
#define pb push_back
#define mp make_pair
#define lc v<<1
#define rc v<<1|1
#define fast_io ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define kill(x) cout << x << '\n';exit(0)
#define killshayan kill("done!")
#define killmashtali kill("Hello, World!")
const int N=2e3+10,LN=19,M=1e5+10,SQ=450,BS=737,inf=1e9,NSQ=N/SQ+1;
const ll INF=1e16;
const double pi=acos(-1);
const ld ep=1e-7;
const int MH=1000696969,MD=998244353,MOD=1000000007;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<pii, null_type,greater<pii>, rb_tree_tag,tree_order_statistics_node_update>
ll pow(ll x, ll y, ll mod){
    ll ans=1;
    while (y != 0) {
        if (y & 1) ans = ans * x % mod;
        y >>= 1;
        x = x * x % mod;
    }
    return ans;
}
int n,m,q,k,w[N],x[M];
ll dp[2][N*2],ans;
int ed[N*2];
vector<int> adj[N];
priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>> pq;
int main(){
    fast_io;
    cin >> n >> m >> q >> k;
    if(q>1) return 0;
    for(int i=1; i<=m; i++){
        int v,u;
        cin >> v >> u >> w[i];
        ed[i*2]=u;
        ed[i*2+1]=v;
        adj[v].pb(i*2);
        adj[u].pb(i*2+1);
    }
    for(int i=1; i<=k; i++) cin >> x[i];
    int P,Q;
    cin >> P >> Q;
    x[P]=Q;
    ed[1]=x[1];
    for(ll i=0; i<m*2+2; i++) dp[0][i]=dp[1][i]=INF;
    dp[0][1]=0;
    for(int t=1; t<k; t++){
        for(int i=1; i<m*2+2; i++){
            if(dp[0][i]<INF){
                pq.push({dp[0][i],i});
            }
        }
        while(!pq.empty()){
            int id=pq.top().S;
            ll c=pq.top().F;
            pq.pop();
            if(dp[0][id]!=c) continue;
            int v=ed[id];
            for(ll i : adj[v]){
                if((i^1)==id) continue;
                int u=ed[i],f=w[i/2];
                if(dp[0][i]>f+c){
                    dp[0][i]=f+c;
                    pq.push({dp[0][i],i});
                }
                if(u==x[t+1] && dp[1][i]>f+c) dp[1][i]=f+c;
            }
        }
        for(int i=1; i<m*2+2; i++){
            dp[0][i]=dp[1][i];
            dp[1][i]=INF;
        }
    }
    ans=INF;
    for(int i=1; i<m*2+2; i++) if(dp[0][i]<ans) ans=dp[0][i];
    if(ans>=INF) ans=-1;
    cout << ans << '\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 352 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 1 ms 276 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 352 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 1 ms 276 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 30 ms 716 KB Output is correct
28 Correct 44 ms 716 KB Output is correct
29 Correct 7094 ms 792 KB Output is correct
30 Correct 7795 ms 784 KB Output is correct
31 Correct 8866 ms 788 KB Output is correct
32 Correct 8854 ms 788 KB Output is correct
33 Correct 6424 ms 792 KB Output is correct
34 Correct 6393 ms 792 KB Output is correct
35 Correct 6975 ms 784 KB Output is correct
36 Correct 7470 ms 784 KB Output is correct
37 Correct 6379 ms 792 KB Output is correct
38 Correct 5949 ms 784 KB Output is correct
39 Correct 6060 ms 780 KB Output is correct
40 Correct 5705 ms 784 KB Output is correct
41 Correct 5718 ms 788 KB Output is correct
42 Correct 4527 ms 784 KB Output is correct
43 Correct 4797 ms 780 KB Output is correct
44 Correct 4895 ms 780 KB Output is correct
45 Correct 1820 ms 776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 352 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 1 ms 276 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 30 ms 716 KB Output is correct
28 Correct 44 ms 716 KB Output is correct
29 Correct 7094 ms 792 KB Output is correct
30 Correct 7795 ms 784 KB Output is correct
31 Correct 8866 ms 788 KB Output is correct
32 Correct 8854 ms 788 KB Output is correct
33 Correct 6424 ms 792 KB Output is correct
34 Correct 6393 ms 792 KB Output is correct
35 Correct 6975 ms 784 KB Output is correct
36 Correct 7470 ms 784 KB Output is correct
37 Correct 6379 ms 792 KB Output is correct
38 Correct 5949 ms 784 KB Output is correct
39 Correct 6060 ms 780 KB Output is correct
40 Correct 5705 ms 784 KB Output is correct
41 Correct 5718 ms 788 KB Output is correct
42 Correct 4527 ms 784 KB Output is correct
43 Correct 4797 ms 780 KB Output is correct
44 Correct 4895 ms 780 KB Output is correct
45 Correct 1820 ms 776 KB Output is correct
46 Correct 9 ms 332 KB Output is correct
47 Execution timed out 18029 ms 932 KB Time limit exceeded
48 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 352 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 1 ms 276 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 30 ms 716 KB Output is correct
28 Correct 44 ms 716 KB Output is correct
29 Correct 7094 ms 792 KB Output is correct
30 Correct 7795 ms 784 KB Output is correct
31 Correct 8866 ms 788 KB Output is correct
32 Correct 8854 ms 788 KB Output is correct
33 Correct 6424 ms 792 KB Output is correct
34 Correct 6393 ms 792 KB Output is correct
35 Correct 6975 ms 784 KB Output is correct
36 Correct 7470 ms 784 KB Output is correct
37 Correct 6379 ms 792 KB Output is correct
38 Correct 5949 ms 784 KB Output is correct
39 Correct 6060 ms 780 KB Output is correct
40 Correct 5705 ms 784 KB Output is correct
41 Correct 5718 ms 788 KB Output is correct
42 Correct 4527 ms 784 KB Output is correct
43 Correct 4797 ms 780 KB Output is correct
44 Correct 4895 ms 780 KB Output is correct
45 Correct 1820 ms 776 KB Output is correct
46 Correct 9 ms 332 KB Output is correct
47 Execution timed out 18029 ms 932 KB Time limit exceeded
48 Halted 0 ms 0 KB -