QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#96739#5036. 卑鄙的下毒人Watware10 26ms78844kbC++142.5kb2023-04-15 15:46:422023-04-15 15:46:45

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-15 15:46:45]
  • 评测
  • 测评结果:10
  • 用时:26ms
  • 内存:78844kb
  • [2023-04-15 15:46:42]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
const int N = 501000, M = 4000100;
int head[N], cur[N], to[M], nxt[M], n, m, s, t, tot = 2, u, v;
i64 cap[M], cost[M], a, b, dis[M], h[M];
bool in[N], vis[N];
inline void add(int u, int v, i64 a, i64 b) {
    to[tot] = v, nxt[tot] = head[u], cap[tot] = a, cost[tot] = b, head[u] = tot++;
    to[tot] = u, nxt[tot] = head[v], cap[tot] = 0, cost[tot] = -b, head[v] = tot++;
}
inline bool dijkstra() {
    using dit = pair<int, int>;
    for (int i = 0; i <= t; i++) h[i] += dis[i];
    priority_queue<dit> q;
    memset(dis, 0x3f, sizeof(dis)), dis[s] = 0, q.push(make_pair(0, s)), memcpy(cur, head, sizeof(cur));
    while (!q.empty()) {
        dit p = q.top();
        q.pop();
        if (p.first != dis[p.second]) continue;
        int o = p.second;
        for (int i = head[o]; i; i = nxt[i])
            if (cap[i] && dis[to[i]] > dis[o] + cost[i] + h[o] - h[to[i]])
                dis[to[i]] = dis[o] + cost[i] + h[o] - h[to[i]], q.push({dis[to[i]], to[i]});
    }
    // printf("dijkstra debug :\n");
    // for (int i = s; i <= t; i++) printf("%d : %lld %lld\n", i, dis[i], dis[i] + h[i]);
    return dis[t] != dis[t + 1];
}
i64 mincost, maxflow;
bool dfs(int n) {
    // printf("dfs %d\n", n);
    vis[n] = 1;
    if (n == t) return vis[n] = 0, true;
    for (int &i = cur[n]; i; i = nxt[i])
        if (!vis[to[i]] && dis[to[i]] + h[to[i]] == dis[n] + h[n] + cost[i] && cap[i]) {
            bool t = dfs(to[i]);
            if (!t) continue;
            return cap[i] -= 1, cap[i ^ 1] += 1, mincost += cost[i], vis[n] = 0, true;
        }
    return vis[n] = 0, false;
}
void dinic() {
    while (dijkstra()) dfs(s); // printf("%d\n", flow);
}
int k;
int main() {
    // freopen("debug", "w", stdout);
    scanf("%d%d%d", &n, &m, &k);
    s = 0, t = n + 1;
    add(s, 1, 100, 0), add(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;
        scanf("%d%d%d", &l, &r, &a);
        add(l - 1, r, 1, -a);
    }
    memset(h, 0x3f, sizeof(h)), h[s] = 0;
    while (true) {
        bool flag = false;
        for (int i = 0; i <= n + 1; i++)
            for (int j = head[i]; j; j = nxt[j])
                if (cap[j] && h[to[j]] > h[i] + cost[j]) flag = true, h[to[j]] = h[i] + cost[j];
        if (!flag) break;
    }
    // for (int i = 0; i <= n + 1; i++) printf("%d : %d\n", i, h[i]);
    dinic();
    printf("%lld\n", -mincost);
    return 0;
}

詳細信息

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 23ms
memory: 75888kb

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: 20ms
memory: 77820kb

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: 26ms
memory: 76168kb

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: 21ms
memory: 76796kb

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: 22ms
memory: 77836kb

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: 18ms
memory: 75772kb

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: 8ms
memory: 75768kb

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: 24ms
memory: 76380kb

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: 16ms
memory: 75672kb

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: 24ms
memory: 76204kb

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
Wrong Answer

Test #11:

score: 0
Wrong Answer
time: 19ms
memory: 78844kb

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:

48112533211

result:

wrong answer 1st words differ - expected: '136716114929', found: '48112533211'

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: