QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#116163#6659. 외곽 순환 도로 2Laurie#8 68ms22460kbC++144.1kb2023-06-28 11:11:392024-08-26 15:49:35

Judging History

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

  • [2024-08-26 15:49:35]
  • 管理员手动重测本题所有提交记录
  • 测评结果:8
  • 用时:68ms
  • 内存:22460kb
  • [2024-05-31 18:19:13]
  • 评测
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-28 11:11:39]
  • 提交

answer

#include <iostream>
#include <iomanip>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <climits>
#include <functional>
#include <cstring>
#include <string>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <complex>
#include <random>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ms multiset
#define F(i,a,b) for(register int i=a,i##end=b;i<=i##end;++i)
#define UF(i,a,b) for(register int i=a,i##end=b;i>=i##end;--i)
#define re register
#define ri re int
#define il inline
#define pii pair<int,int>
#define cp complex<double>
#define vi vector<int>
#define ull unsigned long long
#define mem0(x) memset(x,0,sizeof(x))
#define mem0x3f(x) memset(x,0x2f,sizeof(x))
#define int long long
using namespace std;
int f[100002][11],nxt[11],v[100002],w[100002],n,m,sz[100002];
vector<int>c[100002];
inline int r(int x){
	if(x==2)return 2;
	return x^1;
}
vector<pii >g[8];
int d[8],col[8],now;
inline void e(int x,int y,int z){
	g[x].push_back(make_pair(y,z));
	g[y].push_back(make_pair(x,z));
}
int T[2][2][11][11];bool FF;
inline bool dfs(int pos){
	col[pos]=now;if(FF)cerr<<pos<<endl;
	for(pii ii:g[pos]){int i=ii.first;
		if(!d[i]){
			d[i]=d[pos]+ii.second;
			if(!dfs(i))return false;//dfs(i);
		}else if((d[i]^d[pos]^ii.second)&1)return false;
	}
	return true;
}
inline int trans(int a,int b,bool cy,bool cw){
	F(i,1,7)g[i].clear(),d[i]=0;now=0;
	if(a==9)e(1,2,1);
	else if(a==10)e(1,2,0);
	else{
		if(a%3==0)e(1,3,0);
		else if(a%3==1)e(1,3,1);
		if(a/3==0)e(2,3,0);
		else if(a/3==1)e(2,3,1);
	}
	if(b==9)e(4,5,1);
	else if(b==10)e(4,5,0);
	else{
		if(b%3==0)e(4,6,0);
		else if(b%3==1)e(4,6,1);
		if(b/3==0)e(5,6,0);
		else if(b/3==1)e(5,6,1);
	}
	e(3,7,0);
	if(!cy)e(6,7,1);
	if(!cw)e(2,4,1);
	if(a==1&&b==1&&cy==1&&cw==0){
	//	FF=true;
	//	F(i,1,7)for(auto j:g[i])if(j.first>i)cerr<<i<<" "<<j.first<<" "<<j.second<<endl;
	}else FF=false;
	F(i,1,7)if(!d[i]){
		++now;d[i]=1;
		if(!dfs(i))return -1;
	}
	int res=0;
	if(col[1]==col[7]){
		if((d[1]^d[7])&1)res+=1;
	}else res+=2;
	if(col[5]==col[7]){
		if((d[5]^d[7])&1)res+=3;
	}else res+=6;
	if(res==8&&col[1]==col[5]){
		res=10;
		if((d[1]^d[5])&1)--res;
	}
	return res;
}
inline void dfs(int pos,int l,int r){
	if(c[pos].empty()){
		f[pos][0]=0;
		return;
	}
	int now=l;
	bool flag=true;
	for(int i:c[pos]){//cerr<<pos<<" "<<i<<endl;
		dfs(i,now,now+sz[i]-1);
		if(flag){
			F(x,0,10){
				int y=x;
				if(y<9){
					if(y%3==1)--y;
					else if(y%3==0)++y;
					if(y>=3&&y<=5)y-=3;
					else if(y<3)y+=3;
				}
				f[pos][x]=f[i][y];
			}
			F(x,0,10){
				if(x%3<=1&&x<=5){
					f[pos][9+(x%3==x/3)]=min(f[pos][9+(x%3==x/3)],f[i][x]+v[i]);
				}else f[pos][8]=min(f[pos][8],f[i][x]+v[i]);
			}
			flag=false;
		}else{
			mem0x3f(nxt);
			F(cy,0,1)F(cw,0,1){
				int co=cy*v[i]+cw*w[now-1];
				F(x,0,10)F(y,0,10)if(~T[cy][cw][x][y]){
					nxt[T[cy][cw][x][y]]=min(nxt[T[cy][cw][x][y]],f[pos][x]+f[i][y]+co);
				}
			}
			memcpy(f[pos],nxt,sizeof(nxt));
			
		}
//	if(pos==1)F(j,0,10)cerr<<f[pos][j]<<" "<<endl;cerr<<endl;
		now+=sz[i];
	}
}
long long place_police(vector<signed> P, vector<long long> C, vector<long long> W){
	F(i,0,10)F(j,0,10)F(y,0,1)F(z,0,1)T[y][z][i][j]=trans(i,j,y,z);//cerr<<"K";
//	cerr<<T[1][0][1][1]<<endl;
//	F(i,0,10)F(j,0,10)F(y,1,1)F(z,0,1)cerr<<T[y][z][i][j]<<endl;
	mem0x3f(f);
	n=P.size()+1;
	F(i,2,n)c[P[i-2]+1].push_back(i),v[i]=C[i-2];//cerr<<c[10].size()<<endl;
	m=W.size();
	F(i,1,m)w[i]=W[i-1];
	UF(i,n,1){
		for(int j:c[i])sz[i]+=sz[j];
		sz[i]=max(sz[i],1ll);
	}
	dfs(1,1,m);
	int ans=LLONG_MAX;
	F(i,0,8){
		if(i%3==2||i>=6)ans=min(ans,f[1][i]);
		if(i%3!=i/3)ans=min(ans,f[1][i]);
	}
	ans=min(ans,f[1][9]);
    return ans;
}
/*
4
0 9
0 8
0 0
9 9 9




0 1 9
0 2 8
2 3 0
3 4 7
3 5 1
2 6 6
0 7 0
7 8 7
7 9 1
9 10 6

1 4
4 5
5 6
6 8
8 10
*/







Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 6
Accepted
time: 0ms
memory: 17312kb

input:

5
0 452912
0 820899
0 79369
0 232463
1000000000000 1000000000000 1000000000000 1000000000000

output:

532281

result:

ok single line: '532281'

Test #2:

score: 6
Accepted
time: 0ms
memory: 17064kb

input:

6
0 581451
0 68556
0 918465
0 661406
0 41816
1000000000000 1000000000000 1000000000000 1000000000000 1000000000000

output:

1000000110372

result:

ok single line: '1000000110372'

Test #3:

score: 6
Accepted
time: 0ms
memory: 17080kb

input:

4
0 0
0 0
0 0
0 0 0

output:

0

result:

ok single line: '0'

Test #4:

score: 0
Wrong Answer
time: 0ms
memory: 17356kb

input:

5
0 938777585449
0 576051802364
0 418735407836
0 823692221300
233950071687 338912182863 866023804654 680391493800

output:

1357512993285

result:

wrong answer 1st lines differ - expected: '1333076973323', found: '1357512993285'

Subtask #2:

score: 8
Accepted

Test #28:

score: 8
Accepted
time: 68ms
memory: 22224kb

input:

99997
0 122727
0 267270
0 846212
0 454122
0 805668
0 614161
0 7805
0 173284
0 684707
0 269129
0 930945
0 1101
0 992427
0 297412
0 759787
0 227130
0 120418
0 90914
0 333684
0 46144
0 519912
0 171490
0 823586
0 121787
0 674177
0 560254
0 753090
0 853359
0 465464
0 655527
0 631303
0 919012
0 597126
0 1...

output:

24980330181

result:

ok single line: '24980330181'

Test #29:

score: 8
Accepted
time: 63ms
memory: 22332kb

input:

99997
0 122727
0 267270
0 846212
0 454122
0 805668
0 614161
0 7805
0 173284
0 684707
0 269129
0 930945
0 1101
0 992427
0 297412
0 759787
0 227130
0 120418
0 90914
0 333684
0 46144
0 519912
0 171490
0 823586
0 121787
0 674177
0 560254
0 753090
0 853359
0 465464
0 655527
0 631303
0 919012
0 597126
0 1...

output:

24980330181

result:

ok single line: '24980330181'

Test #30:

score: 8
Accepted
time: 63ms
memory: 22208kb

input:

99998
0 792854
0 622829
0 836127
0 847372
0 71732
0 241096
0 487224
0 696890
0 899047
0 845614
0 27226
0 270985
0 698890
0 64699
0 856738
0 685434
0 766150
0 540443
0 802763
0 874879
0 250532
0 834015
0 616087
0 771638
0 262098
0 458015
0 959723
0 408130
0 880649
0 456673
0 923653
0 969100
0 439032
...

output:

1025006589524

result:

ok single line: '1025006589524'

Test #31:

score: 8
Accepted
time: 66ms
memory: 22372kb

input:

99998
0 792854
0 622829
0 836127
0 847372
0 71732
0 241096
0 487224
0 696890
0 899047
0 845614
0 27226
0 270985
0 698890
0 64699
0 856738
0 685434
0 766150
0 540443
0 802763
0 874879
0 250532
0 834015
0 616087
0 771638
0 262098
0 458015
0 959723
0 408130
0 880649
0 456673
0 923653
0 969100
0 439032
...

output:

1025006589524

result:

ok single line: '1025006589524'

Test #32:

score: 8
Accepted
time: 68ms
memory: 22136kb

input:

99997
0 111160315429
0 355167263283
0 846519401525
0 697515481745
0 653176944193
0 975281743723
0 947695822588
0 443385029699
0 86490619914
0 542182758068
0 140914234365
0 453333219458
0 484226894553
0 930883160414
0 961277575066
0 392480084360
0 638524603170
0 806648354769
0 552428035490
0 99450464...

output:

18302944415585093

result:

ok single line: '18302944415585093'

Test #33:

score: 8
Accepted
time: 62ms
memory: 22460kb

input:

99998
0 111160315429
0 355167263283
0 846519401525
0 697515481745
0 653176944193
0 975281743723
0 947695822588
0 443385029699
0 86490619914
0 542182758068
0 140914234365
0 453333219458
0 484226894553
0 930883160414
0 961277575066
0 392480084360
0 638524603170
0 806648354769
0 552428035490
0 99450464...

output:

18289278171456444

result:

ok single line: '18289278171456444'

Test #34:

score: 8
Accepted
time: 68ms
memory: 22268kb

input:

99997
0 111160315429
0 355167263283
0 846519401525
0 697515481745
0 653176944193
0 975281743723
0 947695822588
0 443385029699
0 86490619914
0 542182758068
0 140914234365
0 453333219458
0 484226894553
0 930883160414
0 961277575066
0 392480084360
0 638524603170
0 806648354769
0 552428035490
0 99450464...

output:

18302944415585093

result:

ok single line: '18302944415585093'

Test #35:

score: 8
Accepted
time: 68ms
memory: 22216kb

input:

99998
0 111160315429
0 355167263283
0 846519401525
0 697515481745
0 653176944193
0 975281743723
0 947695822588
0 443385029699
0 86490619914
0 542182758068
0 140914234365
0 453333219458
0 484226894553
0 930883160414
0 961277575066
0 392480084360
0 638524603170
0 806648354769
0 552428035490
0 99450464...

output:

18289278171456444

result:

ok single line: '18289278171456444'

Subtask #3:

score: 0
Wrong Answer

Test #36:

score: 5
Accepted
time: 0ms
memory: 17024kb

input:

11
0 9
0 8
2 0
3 7
3 1
2 6
0 0
7 7
7 1
9 6
1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000

output:

1

result:

ok single line: '1'

Test #37:

score: 0
Wrong Answer
time: 13ms
memory: 19476kb

input:

50311
0 630582
1 458618
2 300543
3 566041
4 306718
5 134260
6 736322
7 458543
8 609374
9 355623
10 706939
11 48588
12 455725
13 105118
14 71071
15 528699
16 423538
17 471781
18 98063
19 169099
20 657181
21 295537
22 49937
23 306612
24 186582
25 505763
26 831500
27 406268
28 294626
29 128111
30 42115...

output:

565088

result:

wrong answer 1st lines differ - expected: '813491', found: '565088'

Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Wrong Answer

Test #77:

score: 0
Wrong Answer
time: 14ms
memory: 19512kb

input:

50311
0 962897543825
1 887020369743
2 363658802934
3 481009844166
4 1099712574
5 858320882162
6 521927434762
7 379344260539
8 73024776148
9 634183458545
10 869560347910
11 81581323331
12 750044298516
13 307013017409
14 306226274039
15 423923546601
16 482114694167
17 849292461119
18 299993045938
19 7...

output:

847934277507

result:

wrong answer 1st lines differ - expected: '939418184213', found: '847934277507'

Subtask #6:

score: 0
Skipped

Dependency #1:

0%