Submission #336725

# Submission time Handle Problem Language Result Execution time Memory
336725 2020-12-16T14:51:59 Z camnguyenmeow Relay Marathon (NOI20_relaymarathon) C++14
17 / 100
777 ms 384628 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define fr first
#define sc second
#define pow2(i) (1<<i)
#define eb emplace_back
#define mp make_pair
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define FOR(_i, _s, _n) 	for (int _i = _s; _i <= _n; ++_i)
#define FOD(_i, _s, _n)	    for (int _i = _s; _i >= _n; --_i)
#define firstbit(_mask)     __builtin_ctz(_mask)
#define lastbit(_mask)      __builtin_clz(_mask)
#define countbit(_mask)     __builtin_popcount(_mask)
int getbit(int mask, int i) {
    return (mask >> i) & 1;
}
void flipbit(int &mask, int i) {
    mask ^= (1 << i);
}
void setbit(int &mask, int i) {
    mask |= (1 << i);
}
template <typename T> inline void read(T &x) {
    x = 0; char c;
    while (!isdigit(c = getchar()));
    do x = x*10 + c - '0';
    while (isdigit(c = getchar()));
}
template <typename T> inline void write(T x) {
    if (x > 9) write(x/10);
    putchar(x % 10 + 48);
}
const int dd[4]={-1, 0, 1, 0}, dc[4]={0, 1, 0, -1};
//#define PROBLEMS            "RELAYMARATHON"
#ifdef PROBLEMS
    #define cin fi
    #define cout fo
    ifstream fi (PROBLEMS".inp");
    ofstream fo (PROBLEMS".out");
#endif
#define camnguyenmeow ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
/*   /\_/\
    (= ._.)
    / >?  \>$
*/
int n, m, k, firstnear[5001], secondnear[5001], a[5001];
ll c[5001][5001];
bool sp[5001];
int main()
{
    camnguyenmeow;
    memset(c, 0x3f, sizeof(c));
    cin >> n >> m >> k;
    int x, y;
    ll z;
    FOR(i, 1, m) {
        cin >> x >> y >> z;
        c[x][y] = c[y][x] = z;
    }
    FOR(i, 1, k) {
        cin >> a[i];
        sp[a[i]] = true;
    }
    FOR(i, 1, n)
        FOR(u, 1, n)
            FOR(v, 1, n) {
                c[u][v] = min(c[u][v], c[u][i] + c[i][v]);
                if (sp[v] && sp[u] && v != u) {
                    if (c[u][firstnear[u]] > c[u][v]) {
                        secondnear[u] = firstnear[u];
                        firstnear[u] = v;
                    }
                    else if (v != firstnear[u] && c[u][secondnear[u]] > c[u][v])
                        secondnear[u] = v;
                }
            }
    ll ans = LONG_MAX;
    FOR(i, 1, k)
        FOR(j, 1, k) {
            if (i == j) continue;
            int fn = firstnear[a[j]], sn = secondnear[a[j]];
            FOR(z, 1, k) {
                if (z == i || z == j) continue;
                if (fn && fn != a[i] && fn != a[z])
                    ans = min(ans, c[a[i]][a[z]] + c[a[j]][fn]);
                else if (sn && sn != a[i] && sn != a[z])
                    ans = min(ans, c[a[i]][a[z]] + c[a[j]][sn]);
            }
        }
    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 101 ms 196076 KB Output is correct
2 Correct 100 ms 196076 KB Output is correct
3 Correct 100 ms 196076 KB Output is correct
4 Correct 98 ms 196076 KB Output is correct
5 Correct 99 ms 196156 KB Output is correct
6 Correct 99 ms 196096 KB Output is correct
7 Correct 102 ms 196204 KB Output is correct
8 Correct 99 ms 196076 KB Output is correct
9 Correct 100 ms 196204 KB Output is correct
10 Correct 104 ms 196076 KB Output is correct
11 Correct 99 ms 196096 KB Output is correct
12 Correct 101 ms 196204 KB Output is correct
13 Correct 101 ms 196076 KB Output is correct
14 Correct 101 ms 196076 KB Output is correct
15 Correct 103 ms 196224 KB Output is correct
16 Correct 100 ms 196076 KB Output is correct
17 Correct 101 ms 196076 KB Output is correct
18 Correct 101 ms 196076 KB Output is correct
19 Correct 101 ms 196076 KB Output is correct
20 Correct 99 ms 196076 KB Output is correct
21 Correct 100 ms 196076 KB Output is correct
22 Correct 100 ms 196272 KB Output is correct
23 Correct 103 ms 196076 KB Output is correct
24 Correct 99 ms 196076 KB Output is correct
25 Correct 99 ms 196076 KB Output is correct
26 Correct 109 ms 196076 KB Output is correct
27 Correct 102 ms 196076 KB Output is correct
28 Correct 101 ms 196076 KB Output is correct
29 Correct 100 ms 196076 KB Output is correct
30 Correct 100 ms 196076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 101 ms 196076 KB Output is correct
2 Correct 100 ms 196076 KB Output is correct
3 Correct 100 ms 196076 KB Output is correct
4 Correct 98 ms 196076 KB Output is correct
5 Correct 99 ms 196156 KB Output is correct
6 Correct 99 ms 196096 KB Output is correct
7 Correct 102 ms 196204 KB Output is correct
8 Correct 99 ms 196076 KB Output is correct
9 Correct 100 ms 196204 KB Output is correct
10 Correct 104 ms 196076 KB Output is correct
11 Correct 99 ms 196096 KB Output is correct
12 Correct 101 ms 196204 KB Output is correct
13 Correct 101 ms 196076 KB Output is correct
14 Correct 101 ms 196076 KB Output is correct
15 Correct 103 ms 196224 KB Output is correct
16 Correct 100 ms 196076 KB Output is correct
17 Correct 101 ms 196076 KB Output is correct
18 Correct 101 ms 196076 KB Output is correct
19 Correct 101 ms 196076 KB Output is correct
20 Correct 99 ms 196076 KB Output is correct
21 Correct 100 ms 196076 KB Output is correct
22 Correct 100 ms 196272 KB Output is correct
23 Correct 103 ms 196076 KB Output is correct
24 Correct 99 ms 196076 KB Output is correct
25 Correct 99 ms 196076 KB Output is correct
26 Correct 109 ms 196076 KB Output is correct
27 Correct 102 ms 196076 KB Output is correct
28 Correct 101 ms 196076 KB Output is correct
29 Correct 100 ms 196076 KB Output is correct
30 Correct 100 ms 196076 KB Output is correct
31 Correct 333 ms 196204 KB Output is correct
32 Correct 337 ms 196204 KB Output is correct
33 Correct 323 ms 196204 KB Output is correct
34 Correct 323 ms 196336 KB Output is correct
35 Correct 316 ms 196332 KB Output is correct
36 Correct 602 ms 196332 KB Output is correct
37 Correct 777 ms 196332 KB Output is correct
38 Correct 349 ms 196208 KB Output is correct
39 Correct 416 ms 197228 KB Output is correct
40 Correct 594 ms 196460 KB Output is correct
41 Correct 345 ms 196076 KB Output is correct
42 Correct 703 ms 196332 KB Output is correct
43 Correct 574 ms 196204 KB Output is correct
44 Correct 319 ms 196076 KB Output is correct
45 Correct 341 ms 196076 KB Output is correct
46 Correct 754 ms 197404 KB Output is correct
47 Correct 593 ms 196332 KB Output is correct
48 Correct 486 ms 197100 KB Output is correct
49 Correct 598 ms 197100 KB Output is correct
50 Correct 340 ms 196136 KB Output is correct
51 Correct 627 ms 196200 KB Output is correct
52 Correct 347 ms 196204 KB Output is correct
53 Correct 480 ms 196716 KB Output is correct
54 Correct 462 ms 197228 KB Output is correct
55 Correct 359 ms 196204 KB Output is correct
56 Correct 323 ms 196204 KB Output is correct
57 Correct 359 ms 196076 KB Output is correct
58 Correct 544 ms 197612 KB Output is correct
59 Correct 329 ms 196076 KB Output is correct
60 Correct 634 ms 196204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 432 ms 384628 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 101 ms 196076 KB Output is correct
2 Correct 100 ms 196076 KB Output is correct
3 Correct 100 ms 196076 KB Output is correct
4 Correct 98 ms 196076 KB Output is correct
5 Correct 99 ms 196156 KB Output is correct
6 Correct 99 ms 196096 KB Output is correct
7 Correct 102 ms 196204 KB Output is correct
8 Correct 99 ms 196076 KB Output is correct
9 Correct 100 ms 196204 KB Output is correct
10 Correct 104 ms 196076 KB Output is correct
11 Correct 99 ms 196096 KB Output is correct
12 Correct 101 ms 196204 KB Output is correct
13 Correct 101 ms 196076 KB Output is correct
14 Correct 101 ms 196076 KB Output is correct
15 Correct 103 ms 196224 KB Output is correct
16 Correct 100 ms 196076 KB Output is correct
17 Correct 101 ms 196076 KB Output is correct
18 Correct 101 ms 196076 KB Output is correct
19 Correct 101 ms 196076 KB Output is correct
20 Correct 99 ms 196076 KB Output is correct
21 Correct 100 ms 196076 KB Output is correct
22 Correct 100 ms 196272 KB Output is correct
23 Correct 103 ms 196076 KB Output is correct
24 Correct 99 ms 196076 KB Output is correct
25 Correct 99 ms 196076 KB Output is correct
26 Correct 109 ms 196076 KB Output is correct
27 Correct 102 ms 196076 KB Output is correct
28 Correct 101 ms 196076 KB Output is correct
29 Correct 100 ms 196076 KB Output is correct
30 Correct 100 ms 196076 KB Output is correct
31 Correct 333 ms 196204 KB Output is correct
32 Correct 337 ms 196204 KB Output is correct
33 Correct 323 ms 196204 KB Output is correct
34 Correct 323 ms 196336 KB Output is correct
35 Correct 316 ms 196332 KB Output is correct
36 Correct 602 ms 196332 KB Output is correct
37 Correct 777 ms 196332 KB Output is correct
38 Correct 349 ms 196208 KB Output is correct
39 Correct 416 ms 197228 KB Output is correct
40 Correct 594 ms 196460 KB Output is correct
41 Correct 345 ms 196076 KB Output is correct
42 Correct 703 ms 196332 KB Output is correct
43 Correct 574 ms 196204 KB Output is correct
44 Correct 319 ms 196076 KB Output is correct
45 Correct 341 ms 196076 KB Output is correct
46 Correct 754 ms 197404 KB Output is correct
47 Correct 593 ms 196332 KB Output is correct
48 Correct 486 ms 197100 KB Output is correct
49 Correct 598 ms 197100 KB Output is correct
50 Correct 340 ms 196136 KB Output is correct
51 Correct 627 ms 196200 KB Output is correct
52 Correct 347 ms 196204 KB Output is correct
53 Correct 480 ms 196716 KB Output is correct
54 Correct 462 ms 197228 KB Output is correct
55 Correct 359 ms 196204 KB Output is correct
56 Correct 323 ms 196204 KB Output is correct
57 Correct 359 ms 196076 KB Output is correct
58 Correct 544 ms 197612 KB Output is correct
59 Correct 329 ms 196076 KB Output is correct
60 Correct 634 ms 196204 KB Output is correct
61 Runtime error 432 ms 384628 KB Execution killed with signal 11 (could be triggered by violating memory limits)
62 Halted 0 ms 0 KB -