QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#145335#6645. 百合qzez#TL 0ms0kbC++141.7kb2023-08-22 08:23:592023-08-22 08:24:00

Judging History

你现在查看的是最新测评结果

  • [2023-08-22 08:24:00]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2023-08-22 08:23:59]
  • 提交

answer

#include<bits/stdc++.h>
#define Gc() getchar() 
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;using LL=__int128;
const int N=(1<<17)+5,M=N*4+5,K=31650,mod=998244353,Mod=mod-1;const db eps=1e-9;const int INF=1e9+7;mt19937 rnd(time(0));
int n,m,k,s,A[N];ll f[N],g[N][18];
vector<pii> S[N];
void Solve(){
	int i,j;scanf("%d%d%d",&k,&m,&s);n=(1<<k);
	for(i=1;i<=k;i++) scanf("%d",&A[i]);
	while(m--){int x,y,z;scanf("%d%d%d",&x,&y,&z),S[x].emplace_back(y,z);S[y].emplace_back(x,z);}
	Me(f,0x3f);f[s]=0;
	// for(i=1;i<=k;i++) cerr<<A[i]<<'\n';
	while(1){
		int flag=0;
		for(i=1;i<=k;i++) for(j=1;j<=k;j++) if(i^j&&A[j]>A[i]+A[abs(j-i)]) A[j]=A[i]+A[abs(j-i)],flag=1;
		if(!flag) break;
	}
	for(i=1;i<=k+1;i++){
		priority_queue<pair<ll,int> > q;
		for(j=0;j<n;j++) q.emplace(-f[j],j);
		while(!q.empty()){
			auto p=q.top();q.pop();p.fi*=-1;if(p.fi^f[p.se]) continue;
			// cerr<<p.fi<<' '<<p.se<<'\n';
			for(auto j:S[p.se]) if(f[j.fi]>j.se+p.fi) f[j.fi]=j.se+p.fi,q.emplace(-f[j.fi],j.fi);
		}
		Me(g,0x3f);
		for(j=0;j<n;j++) g[j][0]=f[j];
		for(j=0;j<k;j++){
			for(int y=j;~y;y--) for(int x=0;x<n;x++) g[x^(1<<j)][y+1]=min(g[x^(1<<j)][y+1],g[x][y]);
		}
		for(j=0;j<n;j++) for(int y=1;y<=k;y++) f[j]=min(f[j],g[j][y]+A[y]);
		// for(j=0;j<n;j++) cerr<<f[j]<<' ';cerr<<'\n';
	}
	for(i=0;i<n;i++) printf("%lld ",f[i]);
}
int main(){
	int t;
	// scanf("%d",&t);
	t=1;
	while(t--) Solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

17 176734 32035
174241040 312806717 869838047 1051792036 618192507 729602782 144984364 904057367 922632751 676477964 651564213 314995751 370303789 14711019 7843270 941966995 532030000
50422 32035 12218
70235 32035 1913
84994 70235 27964
94874 84994 3469
32802 50422 6989
18176 32802 17541
91233 50422...

output:

104839 7871804 62870 66963 79027 7868957 77164 7858869 7869592 7863873 7863873 64039 51115 104082 70150 72482 57864 60745 69433 62907 88618 7858789 7881299 7872044 51092 68271 7855529 7881281 94531 87056 7877506 59789 80215 7863790 87126 74831 74335 62096 51671 68573 7863873 44764 7875532 7860660 78...

result: