QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#878128#9692. Currencyucup-team2818#WA 1ms3840kbC++142.3kb2025-02-01 13:40:382025-02-01 13:40:38

Judging History

This is the latest submission verdict.

  • [2025-02-01 13:40:38]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 3840kb
  • [2025-02-01 13:40:38]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int maxn = 1005;
const int maxm = 20005;
const ll inf = 2e13;
const ll INF = 4e18;

int rv[2][maxn], cv[maxn];

int s, t;
struct edge
{
	int v, next;
	ll flow;
}e[2 * maxm];
int head[maxn], tot;

inline void addedge(int u, int v, ll c)
{
	e[++tot] = (edge){v, head[u], c}; head[u] = tot;
	e[++tot] = (edge){u, head[v], 0}; head[v] = tot;
}

int d[maxn], cur[maxn];
bool bfs()
{
    for (int i = s; i <= t; i++) d[i] = 0, cur[i] = head[i];
    queue<int> q; q.push(s), d[s] = 1;
    while (q.size())
    {
        int u = q.front(); q.pop();
        for (int i = head[u]; ~i; i = e[i].next)
        {
            int v = e[i].v;
            if (!d[v] && e[i].flow)
            {
                d[v] = d[u] + 1;
                if (v == t) return true;
                q.push(v);
            }
        }
    }
    return false;
}

ll dfs(int u, ll flow)
{
    if (u == t || !flow) return flow;
    ll rest = flow;
    for (int &i = cur[u]; ~i; i = e[i].next)
    {
        int v = e[i].v;
        if (d[v] == d[u] + 1 && e[i].flow)
        {
            ll k = dfs(v, min(rest, e[i].flow));
            if (!k) d[v] = 0;
            e[i].flow -= k, e[i ^ 1].flow += k;
            if (!(rest -= k)) break;
        }
    }
    return flow - rest;
}

ll Dinic()
{
    ll maxflow = 0;
    while (bfs()) maxflow += dfs(s, INF);
    return maxflow;
}

int main()
{
    ios::sync_with_stdio(false), cin.tie(0);
    memset(head, -1, sizeof(head)), tot = -1;

    int n, m; cin >> n >> m;
    for (int i = 1; i < n; i++) cin >> rv[0][i];
    for (int i = 1; i <= n; i++) cin >> cv[i];
    for (int i = 1; i < n; i++) cin >> rv[1][i];
    if (n == 1) return cout << cv[1], 0;

    s = 0, t = 2 * n - 1;
    for (int i = 1; i < n; i++)
    {
        addedge(s, i, inf + rv[1][i] + (i == 1 ? cv[1] : 0));
        addedge(i + n - 1, t, inf + rv[0][i] + (i == n - 1 ? cv[n] : 0));
        addedge(i, i + n - 1, INF);
    }
    for (int i = 1; i < n - 1; i++) addedge(i, i + n, cv[i + 1]), addedge(i + n - 1, i + 1, cv[i + 1]);
    for (int i = 1; i <= m; i++)
    {
        int x, y, val; cin >> x >> y >> val;
        addedge(x, y + n - 1, val);
    }
    cout << Dinic() - inf * (n - 1);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3712kb

input:

5 2
2 3 5 2
6 1 2 1 1
1 2 4 2
1 4 4
2 3 1

output:

13

result:

ok 1 number(s): "13"

Test #2:

score: 0
Accepted
time: 1ms
memory: 3840kb

input:

6 1000
601450612 529194719 287622428 350370653 2490001
267842805 909540874 518481012 265798837 15815265 20879824
142543426 589509572 795333485 574202609 686307559
5 5 368241593
3 4 501344156
3 2 881313477
5 3 877155507
3 3 638857659
3 5 60427320
3 1 888140066
1 1 820913164
3 2 656494106
5 2 48265697...

output:

1792008237

result:

ok 1 number(s): "1792008237"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3840kb

input:

6 1000
939223353 592232256 204123592 697949032 283207645
247227259 860831362 710972139 170824074 510978702 280845746
896873779 377774668 7308887 326686740 179453061
2 3 997446049
2 3 519323074
4 1 939589279
2 5 98041599
4 4 869921378
3 3 558765317
1 2 483873583
5 1 33483163
3 3 270388480
4 4 5510784...

output:

2035324394

result:

ok 1 number(s): "2035324394"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3712kb

input:

6 1000
959730384 933307890 88544023 434800479 519026844
598287106 88518137 220336188 475197957 997211224 13754116
615549399 359488030 322300660 426429747 456751804
2 1 37534981
2 1 826968454
4 5 736905082
2 2 392058437
3 2 148710959
5 3 340405411
4 3 756316407
1 1 989545410
1 4 953888522
1 2 4208087...

output:

2778806746

result:

ok 1 number(s): "2778806746"

Test #5:

score: 0
Accepted
time: 1ms
memory: 3840kb

input:

6 1000
828474485 450284805 615710614 642827608 358927789
340890875 324511822 431939488 283505035 960286257 744621984
19345807 677774542 254789794 431703631 752285873
4 1 619213429
4 2 475954933
2 1 372220764
4 3 365954206
5 2 66701266
5 5 715874448
2 1 385795225
2 4 215024198
2 3 335608279
4 5 81229...

output:

2476790522

result:

ok 1 number(s): "2476790522"

Test #6:

score: 0
Accepted
time: 1ms
memory: 3712kb

input:

6 1000
773101001 64230554 596335108 570954044 371802052
672297875 609818176 210924742 474129815 637532288 845662045
381562818 836547701 790875625 459034073 816120888
3 4 171273656
2 2 669511947
1 5 99209262
4 1 393105839
4 2 161297430
3 2 175654558
4 4 895979780
2 1 380318119
2 3 438246899
2 2 61661...

output:

3222084804

result:

ok 1 number(s): "3222084804"

Test #7:

score: -100
Wrong Answer
time: 1ms
memory: 3840kb

input:

6 1000
786204681 325567741 53406367 432402436 442330564
1353889 4683275 528413577 555907196 568518211 61420817
117239404 703766279 710007531 852547435 543311026
1 1 830934334
2 3 981865567
3 2 439871419
3 2 377106611
1 1 849647504
2 4 590590318
5 5 333563280
3 4 908162812
1 3 384002897
4 4 701562502...

output:

1433721218

result:

wrong answer 1st numbers differ - expected: '1438404493', found: '1433721218'