QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#574611 | #9315. Rainbow Bracket Sequence | qlwpc | TL | 1ms | 3972kb | C++14 | 2.4kb | 2024-09-18 23:14:09 | 2024-09-18 23:14:10 |
Judging History
answer
#include<cstdio>
#include<cstring>
#include<iostream>
const int M = 1020;
const int N = 350;
using ll = long long;
const ll INF = 0x3f3f3f3f3f3f3f3f;
struct node{
int fr,to,next,res,dis;
}q[M];
int head[N],ss,S,T,lst[N],que[N*M],flow[N];
ll dis[N],minc,maxf;bool inq[N];
void addedge(int x,int y,int v,int f)
{
q[++ss]=(node){x,y,head[x],f, v};head[x]=ss;
q[++ss]=(node){y,x,head[y],0,-v};head[y]=ss;
}
bool spfa()
{
memset(flow,0x3f,sizeof(flow));
memset(dis,0x3f,sizeof(dis));
int f=1,e=0;
dis[S]=0;
que[++e]=S;
while(f<=e)
{
int u=que[f++];inq[u]=false;
for (int j=head[u];~j;j=q[j].next)
{
int t=q[j].to;
if (q[j].res&&dis[t]>dis[u]+q[j].dis)
{
dis[t]=dis[u]+q[j].dis;
flow[t]=std::min(flow[u],q[j].res);
lst[t]=j;
if (!inq[t]) que[++e]=t,inq[t]=true;
}
}
}
return dis[T]!=INF;
}
void mcmf()
{
while(spfa())
{
minc += flow[T]*dis[T];
maxf += flow[T];
for (int i=T;i!=S;i=q[lst[i]].fr)
{
int j=lst[i];
q[j].res-=flow[T];
q[j^1].res+=flow[T];
}
}
}
int l[N],c[N],v[N],cnt[N];
int main()
{
memset(head,-1,sizeof(head));ss=-1;
int TT;
scanf("%d",&TT);
while(TT--)
{
int n,m;
ll tot = 0;
scanf("%d%d",&n,&m);
for (int i=1;i<=m;++i) scanf("%d",&l[i]);
for (int i=1;i<=2*n;++i) scanf("%d",&c[i]);
for (int i=1;i<=2*n;++i) scanf("%d",&v[i]);
for (int i=1;i<=2*n;++i) cnt[c[i]]++;
S=0;
for (int i=1;i<=m;++i)
{
if (cnt[i]<l[i])
{
printf("-1\n");
goto GG;
}
addedge(S,i,0,cnt[i]-l[i]);
}
for (int j=1;j<=2*n;++j)
addedge(c[j], m+j, v[j], 1);
for (int i=2;i<=2*n;++i)
addedge(m+i, m+i+1, 0, i/2);
T = m+2*n+1;
for (int i=1;i<=2*n;++i) tot += v[i];
mcmf();
if (maxf!=n) printf("-1\n");
else
printf("%lld\n",tot-minc);
GG:
for (int i=S;i<=T;++i) head[i]=-1;
for (int i=1;i<=m;++i) cnt[i]=0;
ss=-1;minc=0;maxf=0;
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3792kb
input:
2 3 2 1 2 1 2 2 2 1 2 3 1 4 2 2 1 3 2 2 2 1 2 2 2 1 2 3 1 4 2 2 1
output:
9 -1
result:
ok 2 number(s): "9 -1"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3972kb
input:
50 8 6 0 2 2 0 3 1 3 5 1 1 5 3 5 2 3 2 2 1 2 2 4 6 998133227 879226371 59632864 356493387 62611196 827258251 296576565 204244054 812713672 780267148 614679390 447700005 102067050 544546349 116002772 761999375 1 1 1 1 1 343766215 374461155 3 1 2 1 1 1 1 1 1 796323508 303640854 701432076 853325162 610...
output:
-1 343766215 2351080746 3426965219 -1 -1 1351561190 2539318868 1013080942 4656646546 -1 -1 2231197660 2719131728 3983627641 4712174168 -1 1046749330 6115214757 3920988203 -1 3902088946 -1 2566553992 5268471900 5977120748 7505501534 -1 5054275471 1467678317 883992368 1044562986 -1 4024634503 -1 14472...
result:
ok 50 numbers
Test #3:
score: 0
Accepted
time: 1ms
memory: 3932kb
input:
25 20 4 0 0 0 1 2 2 2 2 4 4 4 1 2 2 2 1 3 4 1 3 4 4 3 1 3 2 1 4 2 2 4 1 2 2 3 3 4 1 3 1 4 1 2 1 569363376 821862673 89663213 862407789 442940149 823902948 903631686 838830270 645793571 397350060 806574247 373166844 448916252 435880456 969841293 998227951 276194969 654967687 396909705 696186514 16992...
output:
16418796680 10558213381 -1 1502390329 8534183652 13571062458 8007768610 12656453595 3378659874 8410746077 12352187024 5743130624 5952844559 2285684441 4242613506 836778846 4838639494 8586807028 8535185475 8089358175 5627473863 14399529671 -1 11483578919 4919631490
result:
ok 25 numbers
Test #4:
score: 0
Accepted
time: 1ms
memory: 3796kb
input:
83 6 5 1 0 1 1 0 2 4 4 5 3 2 4 5 3 3 3 3 597659626 649040970 33207011 223207847 960704874 418600362 658594226 417168695 767527655 622701955 867509363 235369723 6 2 0 0 1 1 2 2 2 2 1 1 1 2 2 1 405752009 976807343 267881918 26193206 947664189 555835767 587219021 231445627 755417826 541362608 846129246...
output:
-1 4518989634 3550182642 4529809699 4042429510 4145000717 -1 3635082691 -1 -1 3476472607 3732904849 3631909633 4479534795 3586223781 3380039505 2946284506 3615784040 -1 -1 -1 4940773463 3195952843 4073152216 4177883697 3398540362 3578975642 4308395607 -1 3078447178 3069102942 3135294474 5256676097 -...
result:
ok 83 numbers
Test #5:
score: 0
Accepted
time: 1ms
memory: 3912kb
input:
71 7 4 0 1 0 4 3 4 1 1 4 4 2 4 1 1 1 4 4 4 580852652 638740575 585501313 439482552 637837864 335796176 447934224 259084035 778210267 469729886 908657968 750731414 508195022 701461051 7 6 0 1 1 0 0 1 3 2 4 3 5 3 1 1 5 4 3 1 6 1 198076752 601490845 123074777 392892100 148645775 938575995 355185760 558...
output:
4300550873 4711297430 -1 4468072610 4652801753 4661069155 5134971483 4367382968 4983190626 3065242360 -1 -1 4834379200 4355918462 -1 3592789392 3058869770 -1 3825913893 -1 4785350296 -1 4759459279 5342744097 4716826205 4873131448 5329193547 4821943641 3777324532 4115469556 -1 -1 -1 5061832610 520025...
result:
ok 71 numbers
Test #6:
score: 0
Accepted
time: 1ms
memory: 3920kb
input:
62 8 3 0 2 0 3 3 3 1 1 1 3 2 1 2 2 1 1 2 1 1 222368048 906033133 8623893 807375696 461796409 362923880 194114590 733391789 137574156 670510137 237249112 673135534 595041001 875171159 112263159 649035661 8 6 2 1 0 0 0 0 3 5 2 2 1 3 3 3 6 4 5 5 1 2 5 4 28938721 556768926 23366504 887715271 624732370 3...
output:
5349781905 4269103485 4384563617 5171071054 4895598910 4667548481 -1 4157414045 -1 3927911942 -1 5127481462 5534185037 6071114899 4515756162 5965926191 -1 5617252300 5920664214 5826871785 5730385164 5947153970 5426721265 5820040011 5677486289 5193366586 6129016249 5739984903 5993708705 5520537026 54...
result:
ok 62 numbers
Test #7:
score: -100
Time Limit Exceeded
input:
55 9 9 2 2 0 0 0 0 0 2 0 6 2 3 9 5 4 2 4 1 1 4 7 1 4 5 8 6 2 907208811 754008138 161288468 562810007 149992530 997421612 144383292 832081887 228097972 446662965 77258752 375836694 743196568 527846851 580675905 438791943 977960026 39388076 9 6 0 1 0 0 0 0 5 3 3 4 3 6 5 4 6 5 2 5 6 5 5 1 2 2 861149655...