QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#116196 | #6659. 외곽 순환 도로 2 | zhouhuanyi# | 6 | 157ms | 43608kb | C++11 | 5.2kb | 2023-06-28 11:57:37 | 2024-08-26 15:49:39 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#define N 100000
#define M 11
#define K 6
#define inf 1e18
using namespace std;
struct reads
{
int num;
long long data;
};
struct node
{
int rt[K+1];
bool operator < (const node &t)const
{
for (int i=1;i<=6;++i)
if (rt[i]!=t.rt[i])
return rt[i]<t.rt[i];
return 0;
}
};
node st,tong[N+1];
map<node,int>p;
int n,leng,lengs,length,rt[N+1],nt[N+1],l[N+1],r[N+1],num[N+1];
long long dp[N+1][M+1],DP[M+1],delta[N+1];
vector<reads>E[N+1];
void add(int x,int y,long long z)
{
E[x].push_back((reads){y,z});
return;
}
int find(int x)
{
if (rt[x]==x) return x;
return rt[x]=find(rt[x]);
}
void unionn(int x,int y)
{
if (find(x)!=find(y))
{
if (find(x)<find(y)) swap(x,y);
rt[find(x)]=find(y);
}
return;
}
int F(int x,int op)
{
return ((x-1)<<1)+op+1;
}
bool check(node d)
{
for (int i=1;i<=3;++i)
if (rt[F(i,0)]==rt[F(i,1)])
return 0;
return 1;
}
void dfs(int x)
{
long long res;
if (num[x])
{
for(int i=1;i<=6;++i) rt[i]=i;
unionn(F(1,0),F(2,0)),unionn(F(1,0),F(3,0)),unionn(F(1,1),F(2,1)),unionn(F(1,1),F(3,1));
for (int i=1;i<=6;++i) st.rt[i]=rt[i];
dp[x][p[st]]=0,l[x]=r[x]=num[x];
}
else
{
for (int i=0;i<E[x].size();++i)
{
dfs(E[x][i].num);
if (!i)
{
for (int j=0;j<=1;++j)
for (int k=1;k<=11;++k)
{
res=0;
for (int t=1;t<=8;++t) rt[t]=t;
if (tong[k].rt[F(1,0)]==tong[k].rt[F(2,0)]) unionn(F(4,0),F(2,0)),unionn(F(4,1),F(2,1));
if (tong[k].rt[F(1,0)]==tong[k].rt[F(3,0)]) unionn(F(4,0),F(3,0)),unionn(F(4,1),F(3,1));
if (tong[k].rt[F(2,0)]==tong[k].rt[F(3,0)]) unionn(F(2,0),F(3,0)),unionn(F(2,1),F(3,1));
if (tong[k].rt[F(1,0)]==tong[k].rt[F(2,1)]) unionn(F(4,0),F(2,1)),unionn(F(4,1),F(2,0));
if (tong[k].rt[F(1,0)]==tong[k].rt[F(3,1)]) unionn(F(4,0),F(3,1)),unionn(F(4,1),F(3,0));
if (tong[k].rt[F(2,0)]==tong[k].rt[F(3,1)]) unionn(F(2,0),F(3,1)),unionn(F(2,1),F(3,0));
if (!j) unionn(F(1,0),F(4,1)),unionn(F(1,1),F(4,0));
else res+=E[x][i].data;
for (int t=1;t<=6;++t) st.rt[t]=find(t);
if (check(st)) dp[x][p[st]]=min(dp[x][p[st]],dp[E[x][i].num][k]+res);
}
l[x]=l[E[x][i].num],r[x]=r[E[x][i].num];
}
else
{
for (int j=1;j<=11;++j) DP[j]=inf;
for (int j=0;j<=1;++j)
for (int k=0;k<=1;++k)
for (int s=1;s<=11;++s)
for (int w=1;w<=11;++w)
{
res=0;
for (int t=1;t<=12;++t) rt[t]=t;
if (tong[s].rt[F(1,0)]==tong[s].rt[F(2,0)]) unionn(F(1,0),F(2,0)),unionn(F(1,1),F(2,1));
if (tong[s].rt[F(1,0)]==tong[s].rt[F(3,0)]) unionn(F(1,0),F(4,0)),unionn(F(1,1),F(4,1));
if (tong[s].rt[F(2,0)]==tong[s].rt[F(3,0)]) unionn(F(2,0),F(4,0)),unionn(F(2,1),F(4,1));
if (tong[s].rt[F(1,0)]==tong[s].rt[F(2,1)]) unionn(F(1,0),F(2,1)),unionn(F(1,1),F(2,0));
if (tong[s].rt[F(1,0)]==tong[s].rt[F(3,1)]) unionn(F(1,0),F(4,1)),unionn(F(1,1),F(4,0));
if (tong[s].rt[F(2,0)]==tong[s].rt[F(3,1)]) unionn(F(2,0),F(4,1)),unionn(F(2,1),F(4,0));
if (tong[w].rt[F(1,0)]==tong[w].rt[F(2,0)]) unionn(F(5,0),F(6,0)),unionn(F(5,1),F(6,1));
if (tong[w].rt[F(1,0)]==tong[w].rt[F(3,0)]) unionn(F(5,0),F(3,0)),unionn(F(5,1),F(3,1));
if (tong[w].rt[F(2,0)]==tong[w].rt[F(3,0)]) unionn(F(6,0),F(3,0)),unionn(F(6,1),F(3,1));
if (tong[w].rt[F(1,0)]==tong[w].rt[F(2,1)]) unionn(F(5,0),F(6,1)),unionn(F(5,1),F(6,0));
if (tong[w].rt[F(1,0)]==tong[w].rt[F(3,1)]) unionn(F(5,0),F(3,1)),unionn(F(5,1),F(3,0));
if (tong[w].rt[F(2,0)]==tong[w].rt[F(3,1)]) unionn(F(6,0),F(3,1)),unionn(F(6,1),F(3,0));
if (!j) unionn(F(1,0),F(5,1)),unionn(F(1,1),F(5,0));
else res+=E[x][i].data;
if (!k) unionn(F(4,0),F(6,1)),unionn(F(4,1),F(6,0));
else res+=delta[r[x]];
for (int t=1;t<=6;++t) st.rt[t]=find(t);
if (check(st)) DP[p[st]]=min(DP[p[st]],dp[x][s]+dp[E[x][i].num][w]+res);
}
for (int j=1;j<=11;++j) dp[x][j]=DP[j];
r[x]=r[E[x][i].num];
}
}
}
return;
}
long long place_police(vector<int>P,vector<long long>C,vector<long long>W)
{
long long res,ans=inf;
n=P.size()+1;
for (int i=2;i<=n;++i) add(P[i-2]+1,i,C[i-2]);
for (int i=1;i<=n;++i)
if (E[i].empty())
num[i]=++leng,delta[leng]=W[leng-1];
for (int i=0;i<(1<<6);++i)
{
for (int j=1;j<=6;++j) rt[j]=j;
if (i&(1<<0)) unionn(F(1,0),F(2,0)),unionn(F(1,1),F(2,1));
if (i&(1<<1)) unionn(F(1,0),F(3,0)),unionn(F(1,1),F(3,1));
if (i&(1<<2)) unionn(F(2,0),F(3,0)),unionn(F(2,1),F(3,1));
if (i&(1<<3)) unionn(F(1,0),F(2,1)),unionn(F(1,1),F(2,0));
if (i&(1<<4)) unionn(F(1,0),F(3,1)),unionn(F(1,1),F(3,0));
if (i&(1<<5)) unionn(F(2,0),F(3,1)),unionn(F(2,1),F(3,0));
for (int j=1;j<=6;++j) st.rt[j]=find(j);
if (check(st)&&p.find(st)==p.end()) tong[++lengs]=st,p[st]=lengs;
}
for (int i=1;i<=n;++i)
for (int j=0;j<=11;++j)
dp[i][j]=inf;
dfs(1);
for (int i=0;i<=1;++i)
for (int j=1;j<=11;++j)
{
res=0;
for (int k=1;k<=6;++k) rt[k]=tong[j].rt[k];
if (!i) unionn(F(2,0),F(3,1)),unionn(F(2,1),F(3,0));
else res+=delta[leng];
for (int k=1;k<=6;++k) st.rt[k]=k;
if (check(st)) ans=min(ans,dp[1][j]+res);
}
return ans;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 6
Accepted
Test #1:
score: 6
Accepted
time: 0ms
memory: 11992kb
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: 12224kb
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: 11736kb
input:
4 0 0 0 0 0 0 0 0 0
output:
0
result:
ok single line: '0'
Test #4:
score: 6
Accepted
time: 0ms
memory: 12288kb
input:
5 0 938777585449 0 576051802364 0 418735407836 0 823692221300 233950071687 338912182863 866023804654 680391493800
output:
1333076973323
result:
ok single line: '1333076973323'
Test #5:
score: 6
Accepted
time: 3ms
memory: 13004kb
input:
6 0 938777585449 0 576051802364 0 418735407836 0 823692221300 0 233950071687 338912182863 866023804654 680391493800 876313612238 476765859230
output:
991597662386
result:
ok single line: '991597662386'
Test #6:
score: 6
Accepted
time: 141ms
memory: 35080kb
input:
99995 0 573954 1 101503 2 350026 3 832411 4 311022 5 583957 6 894954 7 223392 8 287704 9 259600 10 964702 11 24863 12 831166 13 754666 14 96743 15 606341 16 198920 17 262280 18 610409 19 193417 20 192417 21 194438 22 244016 23 680809 24 106449 25 249873 26 41805 27 375383 28 927874 29 148386 30 1354...
output:
3
result:
ok single line: '3'
Test #7:
score: 6
Accepted
time: 146ms
memory: 28772kb
input:
99995 0 573954 1 101503 2 350026 3 832411 4 311022 5 583957 6 894954 7 223392 8 287704 9 259600 10 964702 11 24863 12 831166 13 754666 14 96743 15 606341 16 198920 17 262280 18 610409 19 193417 20 192417 21 194438 22 244016 23 680809 24 106449 25 249873 26 41805 27 375383 28 927874 29 148386 30 1354...
output:
0
result:
ok single line: '0'
Test #8:
score: 6
Accepted
time: 151ms
memory: 34076kb
input:
99995 0 573954 1 101503 2 350026 3 832411 4 311022 5 583957 6 894954 7 223392 8 287704 9 259600 10 964702 11 24863 12 831166 13 754666 14 96743 15 606341 16 198920 17 262280 18 610409 19 193417 20 192417 21 194438 22 244016 23 680809 24 106449 25 249873 26 41805 27 375383 28 927874 29 148386 30 1354...
output:
3
result:
ok single line: '3'
Test #9:
score: 6
Accepted
time: 149ms
memory: 29612kb
input:
99995 0 573954 1 101503 2 350026 3 832411 4 311022 5 583957 6 894954 7 223392 8 287704 9 259600 10 964702 11 24863 12 831166 13 754666 14 96743 15 606341 16 198920 17 262280 18 610409 19 193417 20 192417 21 194438 22 244016 23 680809 24 106449 25 249873 26 41805 27 375383 28 927874 29 148386 30 1354...
output:
50
result:
ok single line: '50'
Test #10:
score: 6
Accepted
time: 0ms
memory: 11544kb
input:
7 0 1 1 1 0 1 0 1 4 1 0 1 1000000000000 1000000000000 1000000000000 1000000000000
output:
0
result:
ok single line: '0'
Test #11:
score: 6
Accepted
time: 154ms
memory: 30360kb
input:
99995 0 800351 1 590567 2 404564 3 601685 4 802526 5 784654 6 558749 7 760258 8 655714 9 864130 10 678664 11 983868 12 396629 13 637742 14 592018 15 810308 16 889529 17 914966 18 623197 19 97239 20 448357 21 67877 22 785864 23 177614 24 242659 25 301722 26 5175 27 418269 28 213547 29 417295 30 80595...
output:
1000000000000
result:
ok single line: '1000000000000'
Test #12:
score: 6
Accepted
time: 148ms
memory: 29348kb
input:
99995 0 800351 1 590567 2 404564 3 601685 4 802526 5 784654 6 558749 7 760258 8 655714 9 864130 10 678664 11 983868 12 396629 13 637742 14 592018 15 810308 16 889529 17 914966 18 623197 19 97239 20 448357 21 67877 22 785864 23 177614 24 242659 25 301722 26 5175 27 418269 28 213547 29 417295 30 80595...
output:
1000000000023
result:
ok single line: '1000000000023'
Test #13:
score: 6
Accepted
time: 150ms
memory: 31320kb
input:
99995 0 800351 1 590567 2 404564 3 601685 4 802526 5 784654 6 558749 7 760258 8 655714 9 864130 10 678664 11 983868 12 396629 13 637742 14 592018 15 810308 16 889529 17 914966 18 623197 19 97239 20 448357 21 67877 22 785864 23 177614 24 242659 25 301722 26 5175 27 418269 28 213547 29 417295 30 80595...
output:
1000000000000
result:
ok single line: '1000000000000'
Test #14:
score: 6
Accepted
time: 148ms
memory: 27952kb
input:
99995 0 800351 1 590567 2 404564 3 601685 4 802526 5 784654 6 558749 7 760258 8 655714 9 864130 10 678664 11 983868 12 396629 13 637742 14 592018 15 810308 16 889529 17 914966 18 623197 19 97239 20 448357 21 67877 22 785864 23 177614 24 242659 25 301722 26 5175 27 418269 28 213547 29 417295 30 80595...
output:
1000000000023
result:
ok single line: '1000000000023'
Test #15:
score: 6
Accepted
time: 151ms
memory: 41752kb
input:
99995 0 800351 1 590567 2 404564 3 601685 4 802526 5 784654 6 558749 7 760258 8 655714 9 864130 10 678664 11 983868 12 396629 13 637742 14 592018 15 810308 16 889529 17 914966 18 623197 19 97239 20 448357 21 67877 22 785864 23 177614 24 242659 25 301722 26 5175 27 418269 28 213547 29 417295 30 80595...
output:
23
result:
ok single line: '23'
Test #16:
score: 6
Accepted
time: 146ms
memory: 43600kb
input:
99995 0 800351 1 590567 2 404564 3 601685 4 802526 5 784654 6 558749 7 760258 8 655714 9 864130 10 678664 11 983868 12 396629 13 637742 14 592018 15 810308 16 889529 17 914966 18 623197 19 97239 20 448357 21 67877 22 785864 23 177614 24 242659 25 301722 26 5175 27 418269 28 213547 29 417295 30 80595...
output:
23
result:
ok single line: '23'
Test #17:
score: 6
Accepted
time: 157ms
memory: 35072kb
input:
99995 0 307516682495 1 677180705676 2 900093321878 3 855950595166 4 60373551204 5 97525179732 6 859433105930 7 470206852651 8 836315525302 9 68512632833 10 862923859868 11 74601760822 12 219027891391 13 839738396803 14 169708425659 15 592509244955 16 824764053219 17 619446917083 18 422190804040 19 8...
output:
3249113
result:
ok single line: '3249113'
Test #18:
score: 6
Accepted
time: 153ms
memory: 30596kb
input:
99995 0 307516682495 1 677180705676 2 900093321878 3 855950595166 4 60373551204 5 97525179732 6 859433105930 7 470206852651 8 836315525302 9 68512632833 10 862923859868 11 74601760822 12 219027891391 13 839738396803 14 169708425659 15 592509244955 16 824764053219 17 619446917083 18 422190804040 19 8...
output:
484857763484
result:
ok single line: '484857763484'
Test #19:
score: 6
Accepted
time: 144ms
memory: 29152kb
input:
99995 0 307516682495 1 677180705676 2 900093321878 3 855950595166 4 60373551204 5 97525179732 6 859433105930 7 470206852651 8 836315525302 9 68512632833 10 862923859868 11 74601760822 12 219027891391 13 839738396803 14 169708425659 15 592509244955 16 824764053219 17 619446917083 18 422190804040 19 8...
output:
0
result:
ok single line: '0'
Test #20:
score: 6
Accepted
time: 154ms
memory: 29652kb
input:
99995 0 307516682495 1 677180705676 2 900093321878 3 855950595166 4 60373551204 5 97525179732 6 859433105930 7 470206852651 8 836315525302 9 68512632833 10 862923859868 11 74601760822 12 219027891391 13 839738396803 14 169708425659 15 592509244955 16 824764053219 17 619446917083 18 422190804040 19 8...
output:
86963587131
result:
ok single line: '86963587131'
Test #21:
score: 6
Accepted
time: 151ms
memory: 33832kb
input:
99995 0 307516682495 1 677180705676 2 900093321878 3 855950595166 4 60373551204 5 97525179732 6 859433105930 7 470206852651 8 836315525302 9 68512632833 10 862923859868 11 74601760822 12 219027891391 13 839738396803 14 169708425659 15 592509244955 16 824764053219 17 619446917083 18 422190804040 19 8...
output:
3249113
result:
ok single line: '3249113'
Test #22:
score: 6
Accepted
time: 144ms
memory: 31668kb
input:
99995 0 307516682495 1 677180705676 2 900093321878 3 855950595166 4 60373551204 5 97525179732 6 859433105930 7 470206852651 8 836315525302 9 68512632833 10 862923859868 11 74601760822 12 219027891391 13 839738396803 14 169708425659 15 592509244955 16 824764053219 17 619446917083 18 422190804040 19 8...
output:
484861012597
result:
ok single line: '484861012597'
Test #23:
score: 6
Accepted
time: 141ms
memory: 29872kb
input:
99995 0 307516682495 1 677180705676 2 900093321878 3 855950595166 4 60373551204 5 97525179732 6 859433105930 7 470206852651 8 836315525302 9 68512632833 10 862923859868 11 74601760822 12 219027891391 13 839738396803 14 169708425659 15 592509244955 16 824764053219 17 619446917083 18 422190804040 19 8...
output:
72033520
result:
ok single line: '72033520'
Test #24:
score: 6
Accepted
time: 143ms
memory: 28816kb
input:
99995 0 307516682495 1 677180705676 2 900093321878 3 855950595166 4 60373551204 5 97525179732 6 859433105930 7 470206852651 8 836315525302 9 68512632833 10 862923859868 11 74601760822 12 219027891391 13 839738396803 14 169708425659 15 592509244955 16 824764053219 17 619446917083 18 422190804040 19 8...
output:
87023183814
result:
ok single line: '87023183814'
Test #25:
score: 6
Accepted
time: 140ms
memory: 42804kb
input:
99995 0 307516682495 1 677180705676 2 900093321878 3 855950595166 4 60373551204 5 97525179732 6 859433105930 7 470206852651 8 836315525302 9 68512632833 10 862923859868 11 74601760822 12 219027891391 13 839738396803 14 169708425659 15 592509244955 16 824764053219 17 619446917083 18 422190804040 19 8...
output:
3249113
result:
ok single line: '3249113'
Test #26:
score: 6
Accepted
time: 155ms
memory: 43608kb
input:
99995 0 307516682495 1 677180705676 2 900093321878 3 855950595166 4 60373551204 5 97525179732 6 859433105930 7 470206852651 8 836315525302 9 68512632833 10 862923859868 11 74601760822 12 219027891391 13 839738396803 14 169708425659 15 592509244955 16 824764053219 17 619446917083 18 422190804040 19 8...
output:
3249113
result:
ok single line: '3249113'
Test #27:
score: 6
Accepted
time: 0ms
memory: 11420kb
input:
4 0 9 0 8 0 0 9 9 9
output:
9
result:
ok single line: '9'
Subtask #2:
score: 0
Time Limit Exceeded
Test #28:
score: 0
Time Limit Exceeded
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:
Unauthorized output
result:
Subtask #3:
score: 0
Time Limit Exceeded
Test #36:
score: 5
Accepted
time: 2ms
memory: 10084kb
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: 5
Accepted
time: 93ms
memory: 19792kb
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:
813491
result:
ok single line: '813491'
Test #38:
score: 0
Time Limit Exceeded
input:
99992 0 630582 0 458618 2 300543 2 566041 4 306718 4 134260 6 736322 6 458543 8 609374 8 355623 10 706939 10 48588 12 455725 12 105118 14 71071 14 528699 16 423538 16 471781 18 98063 18 169099 20 657181 20 295537 22 49937 22 306612 24 186582 24 505763 26 831500 26 406268 28 294626 28 128111 30 42115...
output:
Unauthorized output
result:
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Time Limit Exceeded
Test #77:
score: 57
Accepted
time: 90ms
memory: 18960kb
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:
939418184213
result:
ok single line: '939418184213'
Test #78:
score: 57
Accepted
time: 91ms
memory: 18940kb
input:
50313 0 913618590767 1 732880223618 2 997602715655 3 358766408157 4 85067461936 5 794653506774 6 772102529374 7 816168833338 8 383565735786 9 8619949883 10 97913798635 11 177021054239 12 578459000358 13 106983856814 14 119986823990 15 578574399148 16 612351925617 17 907442966599 18 474072682126 19 9...
output:
1080406327850
result:
ok single line: '1080406327850'
Test #79:
score: 0
Time Limit Exceeded
input:
99992 0 962897543825 0 887020369743 2 363658802934 2 481009844166 4 1099712574 4 858320882162 6 521927434762 6 379344260539 8 73024776148 8 634183458545 10 869560347910 10 81581323331 12 750044298516 12 307013017409 14 306226274039 14 423923546601 16 482114694167 16 849292461119 18 299993045938 18 7...
output:
Unauthorized output
result:
Subtask #6:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%