QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#182585#5036. 卑鄙的下毒人Code_AC0 0ms0kbC++142.1kb2023-09-18 09:48:342023-09-18 09:48:34

Judging History

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

  • [2023-09-18 09:48:34]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2023-09-18 09:48:34]
  • 提交

answer

#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int MAXN=4e6+5;
const int N=5e5+5;
const ll INF=1e18;

struct edge
{
    int to,nxt;
    ll flow,len;
}e[MAXN];

int head[N],cnt=1;

inline void add(int x,int y,int f,int z)
{
    e[++cnt].to=y;
    e[cnt].flow=f;
    e[cnt].len=z;
    e[cnt].nxt=head[x];
    head[x]=cnt;
    return;
}

inline void addn(int x,int y,int f,int z)
{
    add(x,y,f,z),add(y,x,0,-z);
    return;
}

int n,m,k,s,t;
ll dis[N],Dis[N];
int dep[N],pre[N];
bool vis[N];

inline bool dij()
{
    for(int i=0;i<=t;i++) Dis[i]+=dis[i];
    priority_queue<pair<ll,int>,vector<pair<ll,int> >,greater<> >q;
    memset(dis,0x3f,sizeof dis);
    q.push({0,s}); dis[s]=0;
    while(!q.empty())
    {
        pair<ll,int> tmp=q.top(); q.pop();
        int x=tmp.second,now=tmp.first;
        if(now!=dis[x])continue;
        for(int i=head[x];i;i=e[i].nxt)
        {
            int y=e[i].to,f=e[i].flow,z=e[i].len;
            if(f && dis[y]+Dis[y]>dis[x]+Dis[x]+z)
            {
                dis[y]=dis[x]+Dis[x]-Dis[y]+z;
                q.push({dis[y],y});
                pre[y]=(i^1);
            }
        }
    }
    return dis[t]!=dis[t+1];
}

ll ans,flow;

inline void dinic()
{
    while(dij())
    {
        for(int i=t;i;i=e[pre[i]].to)
        {
            e[pre[i]].flow++;
            e[pre[i]^1].flow--;
            ans+=e[pre[i]^1].len;
        }
    }
    return;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    cin>>n>>m>>k; s=0,t=n+1;
    addn(s,1,100,0),addn(n,t,k,0);
    for(int i=2;i<=n;i++) add(i-1,i,100,0);
    for(int i=1;i<=m;i++)
    {
        int l,r,a; cin>>l>>r>>a;
        addn(l-1,r,1,-a);
    }
    memset(Dis,0x3f,sizeof(Dis));
    Dis[s]=0;
    for(int i=s;i<=t;i++)
        for(int j=head[i];j;j=e[j].nxt)
        {
            int y=e[j].to,z=e[j].len,f=e[j].flow;
            if(f) Dis[y]=min(Dis[y],Dis[i]+z);
        }
    dinic();
    printf("%lld\n",-ans);
    return 0;
}

詳細信息

Subtask #1:

score: 0
Time Limit Exceeded

Test #1:

score: 0
Time Limit Exceeded

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:


result:


Subtask #2:

score: 0
Time Limit Exceeded

Test #11:

score: 0
Time Limit Exceeded

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:


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: