QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#182358#5036. 卑鄙的下毒人yzh_Error40410 977ms73504kbC++142.1kb2023-09-17 19:48:352023-09-17 19:48:36

Judging History

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

  • [2023-09-17 19:48:36]
  • 评测
  • 测评结果:10
  • 用时:977ms
  • 内存:73504kb
  • [2023-09-17 19:48:35]
  • 提交

answer

#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int MAXN=4e6+5;
const int INF=0x3f3f3f3f;
struct node
{
    int to,nxt;
    ll flow,cost;
}e[MAXN];
int head[MAXN],cnt=1;
inline void adde(int x,int y,ll f,ll c)
{
    e[++cnt].to=y;
    e[cnt].cost=c;
    e[cnt].flow=f;
    e[cnt].nxt=head[x];
    head[x]=cnt;
}
inline void add(int x,int y,int f,int c)
{
    // cout<<x<<" "<<y<<" "<<f<<endl;
    adde(x,y,f,c);
    adde(y,x,0,-c);
}
int n,m,s,t,k;
ll dis[MAXN],h[MAXN];
int pre[MAXN];
bitset<MAXN>vis;
inline bool bfs()
{
    for(register int i=0;i<=t;i++)
        h[i]+=dis[i];
    priority_queue<pair<ll,int> >q;
    memset(dis,0x3f,sizeof dis);
    q.push({0,s});
    dis[s]=0;
    while(!q.empty())
    {
        pair<ll,int>now=q.top();
        int x=now.second;
        q.pop();
        if(now.first!=dis[x])continue;
        for(register int i=head[x];i;i=e[i].nxt)
        {
            int y=e[i].to,f=e[i].flow,c=e[i].cost;
            if(f&&dis[y]+h[y]>dis[x]+h[x]+c)
            {
                assert(h[x]-h[y]+c>=0);
                dis[y]=dis[x]+h[x]-h[y]+c;
                q.push({dis[y],y});
                pre[y]=(i^1);
            }
        }
    }
    return dis[t]!=dis[t+1];
}
ll cost,flow;
inline void dinic()
{
    while(bfs())
    {
        for(register int i=t;i;i=e[pre[i]].to)
        {
            e[pre[i]].flow++;
            e[pre[i]^1].flow--;
            cost+=e[pre[i]^1].cost;
        }
    }
}
int main()
{
    scanf("%d%d%d",&n,&m,&k);
    s=0,t=n+1;
    add(s,1,INF,0);
    add(n,t,k,0);
    for(register int i=2;i<=n;i++)
        add(i-1,i,INF,0);
    for(register int i=1;i<=m;i++)
    {
        int l,r,a;
        scanf("%d%d%d",&l,&r,&a);
        add(l-1,r,1,-a);
    }
    memset(h,0x3f,sizeof h);
    h[s]=0;
    for(register int i=s;i<=t;i++)
        for(register int j=head[i];j;j=e[j].nxt)
        {
            int y=e[j].to,f=e[j].flow,c=e[j].cost;
            if(f)h[y]=min(h[y],h[i]+c);
        }
    dinic();
    printf("%lld",-cost);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 6ms
memory: 69308kb

input:

7 20 5
3 4 1
1 1 1
2 7 1
3 7 1
2 2 1
3 7 1
4 6 1
7 7 1
5 5 1
1 6 1
3 4 1
1 4 1
3 6 1
3 3 1
2 5 1
1 1 1
5 5 1
1 1 1
6 7 1
2 2 1

output:

15

result:

ok "15"

Test #2:

score: 0
Accepted
time: 7ms
memory: 73424kb

input:

12 20 5
5 5 1
8 12 1
4 10 1
10 12 1
2 11 1
3 6 1
6 12 1
1 10 1
4 9 1
7 10 1
4 12 1
2 10 1
1 12 1
4 5 1
4 9 1
7 9 1
3 9 1
10 11 1
6 12 1
4 10 1

output:

10

result:

ok "10"

Test #3:

score: 0
Accepted
time: 11ms
memory: 69344kb

input:

7 20 5
2 7 1
6 6 1
3 6 1
3 3 1
2 5 1
6 6 1
2 6 1
2 7 1
4 6 1
3 3 1
2 2 1
5 5 1
1 4 1
1 5 1
2 5 1
4 4 1
2 7 1
3 4 1
2 4 1
1 2 1

output:

12

result:

ok "12"

Test #4:

score: 0
Accepted
time: 8ms
memory: 73504kb

input:

11 20 5
1 8 1
1 10 1
10 11 1
7 11 1
3 10 1
3 8 1
1 8 1
4 5 1
4 5 1
1 7 1
3 4 1
3 7 1
5 6 1
2 6 1
4 9 1
4 10 1
4 4 1
1 11 1
7 10 1
4 8 1

output:

9

result:

ok "9"

Test #5:

score: 0
Accepted
time: 8ms
memory: 69332kb

input:

8 20 5
6 7 1
4 5 1
1 7 1
3 7 1
1 6 1
3 8 1
1 1 1
2 2 1
1 7 1
3 4 1
6 6 1
1 7 1
1 1 1
1 3 1
4 4 1
8 8 1
3 4 1
1 6 1
6 6 1
2 8 1

output:

13

result:

ok "13"

Test #6:

score: 0
Accepted
time: 7ms
memory: 69308kb

input:

20 20 1
3 14 1
1 17 1
3 18 1
14 20 1
15 17 1
9 17 1
10 12 1
6 20 1
11 16 1
3 17 1
1 2 1
6 19 1
17 18 1
4 18 1
4 9 1
3 7 1
4 13 1
17 19 1
7 12 1
10 14 1

output:

4

result:

ok "4"

Test #7:

score: 0
Accepted
time: 3ms
memory: 69308kb

input:

20 20 2
10 20 1
8 9 1
1 8 1
12 17 1
3 20 1
7 18 1
6 10 1
3 5 1
5 9 1
3 6 1
1 3 1
2 6 1
9 11 1
2 11 1
3 15 1
1 7 1
5 7 1
6 11 1
15 18 1
8 10 1

output:

7

result:

ok "7"

Test #8:

score: 0
Accepted
time: 8ms
memory: 71444kb

input:

20 20 3
3 16 1
6 17 1
8 17 1
11 19 1
5 7 1
3 13 1
16 19 1
6 8 1
3 14 1
7 10 1
6 13 1
1 5 1
4 20 1
16 16 1
8 17 1
7 19 1
12 16 1
5 14 1
10 18 1
10 16 1

output:

7

result:

ok "7"

Test #9:

score: 0
Accepted
time: 10ms
memory: 69340kb

input:

20 20 4
8 19 1
15 19 1
10 20 1
5 11 1
1 2 1
12 15 1
5 7 1
10 14 1
3 6 1
13 19 1
5 10 1
6 7 1
7 7 1
1 19 1
9 16 1
3 16 1
1 2 1
4 20 1
15 16 1
7 11 1

output:

12

result:

ok "12"

Test #10:

score: 0
Accepted
time: 12ms
memory: 69340kb

input:

20 20 5
10 18 1
5 9 1
1 17 1
12 19 1
12 13 1
11 17 1
7 10 1
2 10 1
8 13 1
4 6 1
12 13 1
13 13 1
14 20 1
1 9 1
19 19 1
5 8 1
16 16 1
1 6 1
5 16 1
2 4 1

output:

15

result:

ok "15"

Subtask #2:

score: 0
Time Limit Exceeded

Test #11:

score: 20
Accepted
time: 903ms
memory: 69320kb

input:

1794 5000 5
419 430 46802829
1071 1140 167141363
1154 1554 366136993
735 1265 152210166
387 1104 646459531
1073 1637 525871859
1340 1729 44303243
1221 1574 588158235
91 478 922877048
1117 1268 460323230
315 1103 378106915
272 1071 784282054
1147 1469 220209516
281 375 514585737
677 1031 231082599
55...

output:

136716114929

result:

ok "136716114929"

Test #12:

score: 0
Accepted
time: 977ms
memory: 71372kb

input:

2230 5000 5
953 1373 769239749
1047 1661 462345610
303 2066 576160818
120 397 923490418
534 2140 430136299
1643 1673 257239112
161 881 468971965
500 1294 252402949
832 920 980969457
441 836 27310687
975 1362 566048899
1490 2033 444708762
14 1801 675115178
1054 2171 58928071
1372 1372 276209072
743 1...

output:

135024690658

result:

ok "135024690658"

Test #13:

score: -20
Time Limit Exceeded

input:

2491 4792 5
1244 1262 126130420
502 503 181548261
1087 1095 228548479
704 705 954511272
476 489 702154010
235 237 326120418
1281 1285 234352273
731 743 265589174
14 16 560099243
371 374 933553321
1760 1808 742608005
232 242 538815461
371 372 460405162
492 525 233200462
317 338 464746636
1810 1852 43...

output:


result:


Subtask #3:

score: 0
Time Limit Exceeded

Test #31:

score: 0
Time Limit Exceeded

input:

322675 500000 1
162058 177924 125740423
72321 188693 51206015
73706 159883 238256306
223634 241332 292316893
8164 94217 879196279
232892 319246 624760769
67688 195525 319652781
70831 92026 394982900
68675 156743 598333126
107804 308096 843245966
57077 248406 291662171
12794 193657 560389007
105560 2...

output:


result:


Subtask #4:

score: 0
Time Limit Exceeded

Test #51:

score: 0
Time Limit Exceeded

input:

194181 500000 5
22921 38709 1
103611 130117 1
33044 135246 1
25161 106036 1
13484 183424 1
129622 133239 1
103905 105727 1
8418 141108 1
5951 145648 1
61392 105830 1
139975 149309 1
47361 59947 1
91598 172246 1
32303 43094 1
72490 170121 1
68502 168603 1
56051 91019 1
106112 129606 1
70776 177996 1
...

output:


result:


Subtask #5:

score: 0
Time Limit Exceeded

Test #66:

score: 0
Time Limit Exceeded

input:

265199 500000 5
51732 151507 196279569
1147 251097 325871693
79410 120618 539045634
209514 221950 912376813
44813 147573 616444800
53619 134328 533306546
94940 108466 186490362
42483 236958 489649490
127349 167018 943263893
103970 193784 202963780
197001 221033 210521750
5815 113674 152090319
129972...

output:


result: