# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
647591 | 2022-10-03T09:18:51 Z | ToroTN | Cities (BOI16_cities) | C++14 | 2544 ms | 44312 KB |
#include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define X first #define Y second ll n,num,m,city[5],u_i,v_i,w_i,u,pow_2[6],val,dp[100005],nxt; ll d[32][100005],some[32]; vector<pair<ll,ll> > g[100005]; vector<ll> bit[6]; priority_queue<pair<ll,ll> > pq; void dij(ll arr[]) { for(int i=1;i<=n;i++)pq.push({-arr[i],i}); while(!pq.empty()) { u=pq.top().Y; pq.pop(); for(auto [node,w]:g[u]) { if(arr[u]+w<arr[node]) { arr[node]=arr[u]+w; pq.push({-arr[node],node}); } } } } int main() { pow_2[0]=1; for(int i=1;i<=5;i++)pow_2[i]=pow_2[i-1]*2; scanf("%lld%lld%lld",&n,&num,&m); for(int i=0;i<=31;i++) { for(int j=1;j<=n;j++) { d[i][j]=1e18; } } for(int i=0;i<num;i++)scanf("%lld",&city[i]); for(int i=1;i<=m;i++) { scanf("%lld%lld%lld",&u_i,&v_i,&w_i); g[u_i].pb({v_i,w_i}); g[v_i].pb({u_i,w_i}); } for(int i=0;i<num;i++) { d[pow_2[i]][city[i]]=0; dij(d[pow_2[i]]); } for(int i=0;i<num-1;i++) { for(int j=i+1;j<num;j++) { val=(pow_2[i]|pow_2[j]); for(int k=1;k<=n;k++) { d[val][k]=d[pow_2[i]][k]+d[pow_2[j]][k]; } dij(d[val]); } } for(int i=1;i<pow_2[num];i++) { ll kmp=0; for(int j=0;j<num;j++) { if((i|pow_2[j])==i)++kmp; } some[i]=kmp; bit[kmp].pb(i); } for(int i=3;i<=num;i++) { for(auto j:bit[i]) { for(int k=1;k<=i/2;k++) { for(auto l:bit[k]) { if((j|l)==j) { nxt=(j^l); for(int c=1;c<=n;c++) { d[j][c]=min(d[j][c],d[l][c]+d[nxt][c]); } } } } dij(d[j]); } } ll ans=1e18; for(int i=1;i<=n;i++) { ans=min(ans,d[pow_2[num]-1][i]); } printf("%lld\n",ans); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2772 KB | Output is correct |
2 | Correct | 2 ms | 2772 KB | Output is correct |
3 | Correct | 1 ms | 2772 KB | Output is correct |
4 | Correct | 2 ms | 2772 KB | Output is correct |
5 | Correct | 2 ms | 2772 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 625 ms | 42188 KB | Output is correct |
2 | Correct | 597 ms | 41276 KB | Output is correct |
3 | Correct | 352 ms | 34976 KB | Output is correct |
4 | Correct | 81 ms | 12120 KB | Output is correct |
5 | Correct | 330 ms | 42172 KB | Output is correct |
6 | Correct | 82 ms | 12064 KB | Output is correct |
7 | Correct | 4 ms | 3156 KB | Output is correct |
8 | Correct | 3 ms | 3156 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 3156 KB | Output is correct |
2 | Correct | 6 ms | 3156 KB | Output is correct |
3 | Correct | 4 ms | 3156 KB | Output is correct |
4 | Correct | 5 ms | 3028 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1328 ms | 42180 KB | Output is correct |
2 | Correct | 1256 ms | 41304 KB | Output is correct |
3 | Correct | 796 ms | 35044 KB | Output is correct |
4 | Correct | 654 ms | 28020 KB | Output is correct |
5 | Correct | 198 ms | 15428 KB | Output is correct |
6 | Correct | 99 ms | 14260 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2544 ms | 42200 KB | Output is correct |
2 | Correct | 2491 ms | 44312 KB | Output is correct |
3 | Correct | 2321 ms | 43320 KB | Output is correct |
4 | Correct | 1579 ms | 36020 KB | Output is correct |
5 | Correct | 1380 ms | 30024 KB | Output is correct |
6 | Correct | 394 ms | 17316 KB | Output is correct |
7 | Correct | 124 ms | 15632 KB | Output is correct |