QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#572921#2178. Robotisirazeev0 43ms15744kbC++202.6kb2024-09-18 16:49:542024-09-18 16:49:54

Judging History

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

  • [2024-09-18 16:49:54]
  • 评测
  • 测评结果:0
  • 用时:43ms
  • 内存:15744kb
  • [2024-09-18 16:49:54]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
#define int long long

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    int n, m;
    cin >> n >> m;
    int c[m], p[m], dp[n], last[n], a[m], b[m], ind[n];
    vector<int> g[n];
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v >> c[i] >> p[i];
        u--, v--;
        a[i] = u, b[i] = v;
        g[u].emplace_back(i);
        g[v].emplace_back(i);
    }
    for (int i = 0; i < n; i++) dp[i] = last[i] = (int) 1e18, ind[i] = 0;
    dp[0] = 0;
    set<pair<int, int>> st;
    map<int, int> cnt[n];
    for (int i = 0; i < n; i++) {
        for (auto u: g[i])
            cnt[i][c[u]] += p[u];
    }
    st.insert({dp[0], 0});
    while (!st.empty()) {
        int v = st.begin()->second;
        st.erase(st.begin());
        for (auto i: g[v]) {
            if (c[i] != last[v]) {
                if (cnt[v][c[i]] == p[i] && dp[a[i] + b[i] - v] > dp[v]) {
                    st.erase({dp[a[i] + b[i] - v], a[i] + b[i] - v});
                    dp[a[i] + b[i] - v] = dp[v];
                    last[a[i] + b[i] - v] = c[i];
                    ind[a[i] + b[i] - v] = i;
                    st.insert({dp[a[i] + b[i] - v], a[i] + b[i] - v});
                } else if (dp[a[i] + b[i] - v] > dp[v] + min(p[i], cnt[v][c[i]] - p[i])) {
                    st.erase({dp[a[i] + b[i] - v], a[i] + b[i] - v});
                    dp[a[i] + b[i] - v] = dp[v] + min(p[i], cnt[v][c[i]] - p[i]);
                    if (dp[a[i] + b[i] - v] == dp[v] + p[i])
                        last[a[i] + b[i] - v] = (int) 1e18;
                    else last[a[i] + b[i] - v] = c[i], ind[a[i] + b[i] - v] = i;
                    st.insert({dp[a[i] + b[i] - v], a[i] + b[i] - v});
                }
            } else {
                if (ind[v] != i)
                    cnt[v][c[i]] -= p[ind[v]];
                if (dp[a[i] + b[i] - v] > dp[v] + min(p[i], cnt[v][c[i]] - p[i])) {
                    st.erase({dp[a[i] + b[i] - v], a[i] + b[i] - v});
                    dp[a[i] + b[i] - v] = dp[v] + min(p[i], cnt[v][c[i]] - p[i]);
                    if (dp[a[i] + b[i] - v] == dp[v] + p[i] - p[i])
                        last[a[i] + b[i] - v] = (int) 1e18;
                    else last[a[i] + b[i] - v] = c[i], ind[a[i] + b[i] - v] = i;
                    st.insert({dp[a[i] + b[i] - v], a[i] + b[i] - v});
                }
                if (ind[v] != i)
                    cnt[v][c[i]] += p[ind[v]];
            }
        }
    }
    cout << (dp[n - 1] == (int) 1e18 ? -1 : dp[n - 1]);
    return 0;
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 34
Accepted
time: 0ms
memory: 3584kb

input:

2 1
1 2 1 10

output:

0

result:

ok single line: '0'

Test #2:

score: 34
Accepted
time: 0ms
memory: 3844kb

input:

8 1
5 6 1 7

output:

-1

result:

ok single line: '-1'

Test #3:

score: 34
Accepted
time: 0ms
memory: 3644kb

input:

8 19
4 8 15 5
7 8 15 6
1 4 15 6
3 4 2 10
2 7 15 10
5 6 2 10
1 7 2 3
4 5 15 7
1 6 15 6
2 5 2 6
1 8 15 2
1 2 15 9
5 7 2 5
3 8 2 5
4 7 2 6
6 7 15 8
3 7 15 6
2 8 2 1
5 8 15 6

output:

2

result:

ok single line: '2'

Test #4:

score: 34
Accepted
time: 0ms
memory: 3872kb

input:

4 6
1 2 1 7
3 4 1 10
2 3 2 5
2 4 1 4
1 4 6 2
1 3 1 2

output:

0

result:

ok single line: '0'

Test #5:

score: 34
Accepted
time: 0ms
memory: 3676kb

input:

64 106
7 46 100 641441921
4 22 92 909042053
27 46 100 185644091
52 54 100 333473988
21 41 69 747879553
23 45 24 121784836
16 23 69 538978180
15 42 92 403583091
49 60 69 112127397
44 48 21 733685727
18 40 92 287239281
3 30 48 498139743
21 25 24 281665265
13 24 69 315527284
12 35 21 100990101
33 56 10...

output:

-1

result:

ok single line: '-1'

Test #6:

score: 34
Accepted
time: 0ms
memory: 3884kb

input:

10 45
6 7 29 19322896
6 8 29 826842878
5 9 29 229755065
1 6 29 49301462
4 10 29 356862039
3 7 29 377906409
8 10 29 877820670
4 8 29 150486169
1 10 29 291057766
1 5 29 982043864
1 3 29 126557279
5 6 29 721959799
3 10 29 636909401
1 7 29 772752473
5 8 29 523364181
7 9 29 250673970
2 6 29 417264209
2 4...

output:

255671682

result:

ok single line: '255671682'

Test #7:

score: 34
Accepted
time: 1ms
memory: 3752kb

input:

71 788
5 24 146 614916874
56 61 567 467226384
16 44 275 490241032
14 25 567 779488700
19 42 262 524833651
6 19 567 912315689
8 21 774 326632848
46 62 675 296672130
27 32 715 104878301
13 47 675 546642528
18 68 675 349712771
8 43 146 305351688
13 58 567 776051722
49 63 601 454628166
30 43 715 7695855...

output:

46083838

result:

ok single line: '46083838'

Test #8:

score: 34
Accepted
time: 1ms
memory: 3852kb

input:

55 443
11 21 307 732223755
32 42 307 182136903
47 48 346 925071240
45 53 307 225221704
1 45 307 807617287
28 46 307 644657251
2 42 346 807672874
39 42 346 173126332
11 50 346 105073586
48 53 346 363756204
19 27 346 749462761
8 20 346 838034581
28 31 307 183749842
28 53 346 909041858
33 50 346 364806...

output:

342534314

result:

ok single line: '342534314'

Test #9:

score: 34
Accepted
time: 1ms
memory: 4052kb

input:

999 1988
153 528 1690 1
1 867 1158 1
481 785 1741 1
226 528 203 1
356 481 1957 1
278 481 716 1
168 528 612 1
1 140 489 1
528 533 446 1
4 528 1715 1
481 698 1350 1
35 528 1658 1
528 601 1345 1
24 481 559 1
524 528 88 1
1 606 1547 1
481 493 1017 1
165 528 1685 1
481 849 1847 1
528 711 1464 1
1 663 222...

output:

3

result:

ok single line: '3'

Test #10:

score: 0
Wrong Answer
time: 1ms
memory: 3960kb

input:

999 1988
328 983 1573 1
130 468 1140 1
44 983 210 1
15 983 1848 1
517 983 1451 1
1 131 563 1
1 209 182 1
130 793 1295 1
130 947 1295 1
130 680 1295 1
130 214 1295 1
584 983 567 1
726 983 1019 1
130 456 1295 1
198 575 1295 1
1 6 283 1
200 575 1295 1
205 575 1295 1
1 399 1128 1
130 589 1510 1
923 983 ...

output:

5

result:

wrong answer 1st lines differ - expected: '3', found: '5'

Subtask #2:

score: 0
Wrong Answer

Test #21:

score: 24
Accepted
time: 43ms
memory: 15744kb

input:

25437 78923
921 9998 30945 1
5452 13736 24464 1
11746 24238 24464 1
10875 12958 24464 1
12267 20617 30945 1
3738 16549 35589 1
16223 16940 35589 1
1303 23059 24464 1
12424 21853 24464 1
11198 20674 35589 1
15645 19099 30945 1
8860 9441 24464 1
3609 15160 35589 1
22638 23472 24464 1
766 8991 35589 1
...

output:

5

result:

ok single line: '5'

Test #22:

score: 0
Wrong Answer
time: 21ms
memory: 10116kb

input:

15761 34565
6553 7857 4268 1
1139 8149 4268 1
4136 9004 4268 1
3810 8194 27009 1
3005 10547 9061 1
3025 15018 27009 1
5735 6627 9061 1
2337 12263 9061 1
4260 8046 9061 1
12549 14043 4268 1
6992 11456 4268 1
833 4225 4268 1
1609 9603 4268 1
2588 9564 9061 1
2361 8162 27009 1
10250 10706 4268 1
6878 1...

output:

4

result:

wrong answer 1st lines differ - expected: '6', found: '4'

Subtask #3:

score: 0
Skipped

Dependency #1:

0%