답안 #1042386

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1042386 2024-08-03T03:24:37 Z baldwinhuang1 Shortcut (IOI16_shortcut) C++14
0 / 100
2000 ms 2140 KB
#include <bits/stdc++.h>

using namespace std;

vector< vector<int> > nodes;
vector< vector<int> > weights;

const long long INF = 1e18;


long long dist[1000][1000] ;// Voy a hacer subtask 1, el 1000 es para estar seguro

void floydWarshall(int n)
{
    int i, j, k;

    for (int i = 0; i < (n); i++) {
        for (int j = 0; j < (n + n); j++) {
            dist[i][j] = INF;
        }
    }

    for (int i = 0; i < (n); i++) {
        for (int j = 0; j < (n); j++) {
            if (i == j) {
                dist[i][j] = 0;
            }
            else if (nodes[i][j] == true) {
                dist[i][j] = min(dist[i][j], (long long)weights[i][j]);
            }
        }
    }

    for (k = 0; k < (n); k++) {
        for (i = 0; i < (n); i++) {
            for (j = 0; j < (n); j++) {
                if (dist[i][j] > (dist[i][k] + dist[k][j])
                    && (dist[k][j] != INF
                        && dist[i][k] != INF))
                    dist[i][j] = dist[i][k] + dist[k][j];
            }
        }
    }
}

long long find_shortcut(int n, vector <int> l, vector <int> d, int c) {

    for (auto &i: d) {
        if (i != 0) {
            n++;
        }
    }
 
    nodes = vector< vector<int> >(n, vector<int>(n));
    weights = vector< vector<int> >(n, vector<int>(n));
 
    // cout << n << '\n';
 
    for (int i = 0; i < l.size(); i++) {
        // cout << i << '\n';
        nodes[i][i + 1] = true;
        nodes[i + 1][i] = true;
        weights[i][i + 1] = l[i];
        weights[i + 1][i] = l[i];
    }
 
    int j = l.size() + 1;
    for (int i = 0; i < d.size(); i++) {
        if (d[i] != 0) {
            // cout << i << ' ' << j << '\n';
            nodes[i][j] = true;
            nodes[j][i] = true;
            weights[i][j] = d[i];
            weights[j][i] = d[i];    
            j++;
        }
 
    }

    floydWarshall(n);

    // for (int i = 0; i < (n); i++) {
    //     for (int j = 0; j < (n); j++) {
    //         cout << dist[i][j] << ' ';
    //     }
    //     cout << '\n';
    // }

    long long minimo = 1e18;
    for (int i = 0; i < (n - 1); i++) {
        for (int j = (i + 1); j < n; j++) {
            if (i != j && i <= l.size() && j <= l.size()) {
                // cout << "############" << '\n';
                int node1 = nodes[i][j];
                int node2 = nodes[j][i];
                int weight1 = weights[i][j];
                int weight2 = weights[j][i];
                nodes[i][j] = true;
                nodes[j][i] = true;
                if (weights[i][j] != 0) {
                    weights[i][j] = min(weights[i][j], c);
                }
                else {
                    weights[i][j] = c;
                }
                if (weights[j][i] != 0) {
                    weights[j][i] = min(weights[j][i], c);
                }
                else {
                    weights[j][i] = c;
                }
                floydWarshall(n);
                long long ans = 0;
                for (int i = 0; i < (n); i++) {
                    for (int j = 0; j < (n); j++) {
                        ans = max(ans, dist[i][j]);
                    }
                }
                // cout << ans << ' ' << i << ' ' << j << '\n';
                minimo = min(ans, minimo);
                nodes[i][j] = node1;
                nodes[j][i] = node2;
                weights[i][j] = weight1;
                weights[j][i] = weight2;
            }
        }
    }
    return minimo;
}

Compilation message

shortcut.cpp: In function 'long long int find_shortcut(int, std::vector<int>, std::vector<int>, int)':
shortcut.cpp:59:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |     for (int i = 0; i < l.size(); i++) {
      |                     ~~^~~~~~~~~~
shortcut.cpp:68:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |     for (int i = 0; i < d.size(); i++) {
      |                     ~~^~~~~~~~~~
shortcut.cpp:92:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   92 |             if (i != j && i <= l.size() && j <= l.size()) {
      |                           ~~^~~~~~~~~~~
shortcut.cpp:92:46: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   92 |             if (i != j && i <= l.size() && j <= l.size()) {
      |                                            ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB n = 4, 80 is a correct answer
2 Correct 0 ms 348 KB n = 9, 110 is a correct answer
3 Correct 0 ms 344 KB n = 4, 21 is a correct answer
4 Correct 1 ms 344 KB n = 3, 4 is a correct answer
5 Correct 0 ms 348 KB n = 2, 62 is a correct answer
6 Correct 0 ms 348 KB n = 2, 3 is a correct answer
7 Correct 0 ms 348 KB n = 3, 29 is a correct answer
8 Correct 0 ms 348 KB n = 2, 3 is a correct answer
9 Correct 0 ms 348 KB n = 2, 3 is a correct answer
10 Correct 1 ms 348 KB n = 2, 2000000001 is a correct answer
11 Correct 0 ms 348 KB n = 2, 3000000000 is a correct answer
12 Correct 0 ms 344 KB n = 3, 3000000000 is a correct answer
13 Correct 0 ms 348 KB n = 3, 3000000000 is a correct answer
14 Correct 0 ms 348 KB n = 4, 3000000001 is a correct answer
15 Correct 1 ms 348 KB n = 4, 4000000000 is a correct answer
16 Correct 0 ms 444 KB n = 5, 4000000000 is a correct answer
17 Correct 1 ms 348 KB n = 10, 1000000343 is a correct answer
18 Correct 1 ms 348 KB n = 10, 3189 is a correct answer
19 Correct 1 ms 532 KB n = 10, 7000000000 is a correct answer
20 Correct 0 ms 348 KB n = 5, 12 is a correct answer
21 Correct 1 ms 348 KB n = 5, 25 is a correct answer
22 Correct 1 ms 348 KB n = 2, 122 is a correct answer
23 Correct 1 ms 348 KB n = 10, 117 is a correct answer
24 Correct 1 ms 348 KB n = 10, 336 is a correct answer
25 Correct 0 ms 348 KB n = 10, 438 is a correct answer
26 Correct 0 ms 348 KB n = 10, 206 is a correct answer
27 Correct 1 ms 348 KB n = 10, 636 is a correct answer
28 Correct 0 ms 348 KB n = 4, 2399 is a correct answer
29 Correct 1 ms 532 KB n = 10, 10992 is a correct answer
30 Correct 1 ms 348 KB n = 10, 3112 is a correct answer
31 Execution timed out 2095 ms 2140 KB Time limit exceeded
32 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB n = 4, 80 is a correct answer
2 Correct 0 ms 348 KB n = 9, 110 is a correct answer
3 Correct 0 ms 344 KB n = 4, 21 is a correct answer
4 Correct 1 ms 344 KB n = 3, 4 is a correct answer
5 Correct 0 ms 348 KB n = 2, 62 is a correct answer
6 Correct 0 ms 348 KB n = 2, 3 is a correct answer
7 Correct 0 ms 348 KB n = 3, 29 is a correct answer
8 Correct 0 ms 348 KB n = 2, 3 is a correct answer
9 Correct 0 ms 348 KB n = 2, 3 is a correct answer
10 Correct 1 ms 348 KB n = 2, 2000000001 is a correct answer
11 Correct 0 ms 348 KB n = 2, 3000000000 is a correct answer
12 Correct 0 ms 344 KB n = 3, 3000000000 is a correct answer
13 Correct 0 ms 348 KB n = 3, 3000000000 is a correct answer
14 Correct 0 ms 348 KB n = 4, 3000000001 is a correct answer
15 Correct 1 ms 348 KB n = 4, 4000000000 is a correct answer
16 Correct 0 ms 444 KB n = 5, 4000000000 is a correct answer
17 Correct 1 ms 348 KB n = 10, 1000000343 is a correct answer
18 Correct 1 ms 348 KB n = 10, 3189 is a correct answer
19 Correct 1 ms 532 KB n = 10, 7000000000 is a correct answer
20 Correct 0 ms 348 KB n = 5, 12 is a correct answer
21 Correct 1 ms 348 KB n = 5, 25 is a correct answer
22 Correct 1 ms 348 KB n = 2, 122 is a correct answer
23 Correct 1 ms 348 KB n = 10, 117 is a correct answer
24 Correct 1 ms 348 KB n = 10, 336 is a correct answer
25 Correct 0 ms 348 KB n = 10, 438 is a correct answer
26 Correct 0 ms 348 KB n = 10, 206 is a correct answer
27 Correct 1 ms 348 KB n = 10, 636 is a correct answer
28 Correct 0 ms 348 KB n = 4, 2399 is a correct answer
29 Correct 1 ms 532 KB n = 10, 10992 is a correct answer
30 Correct 1 ms 348 KB n = 10, 3112 is a correct answer
31 Execution timed out 2095 ms 2140 KB Time limit exceeded
32 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB n = 4, 80 is a correct answer
2 Correct 0 ms 348 KB n = 9, 110 is a correct answer
3 Correct 0 ms 344 KB n = 4, 21 is a correct answer
4 Correct 1 ms 344 KB n = 3, 4 is a correct answer
5 Correct 0 ms 348 KB n = 2, 62 is a correct answer
6 Correct 0 ms 348 KB n = 2, 3 is a correct answer
7 Correct 0 ms 348 KB n = 3, 29 is a correct answer
8 Correct 0 ms 348 KB n = 2, 3 is a correct answer
9 Correct 0 ms 348 KB n = 2, 3 is a correct answer
10 Correct 1 ms 348 KB n = 2, 2000000001 is a correct answer
11 Correct 0 ms 348 KB n = 2, 3000000000 is a correct answer
12 Correct 0 ms 344 KB n = 3, 3000000000 is a correct answer
13 Correct 0 ms 348 KB n = 3, 3000000000 is a correct answer
14 Correct 0 ms 348 KB n = 4, 3000000001 is a correct answer
15 Correct 1 ms 348 KB n = 4, 4000000000 is a correct answer
16 Correct 0 ms 444 KB n = 5, 4000000000 is a correct answer
17 Correct 1 ms 348 KB n = 10, 1000000343 is a correct answer
18 Correct 1 ms 348 KB n = 10, 3189 is a correct answer
19 Correct 1 ms 532 KB n = 10, 7000000000 is a correct answer
20 Correct 0 ms 348 KB n = 5, 12 is a correct answer
21 Correct 1 ms 348 KB n = 5, 25 is a correct answer
22 Correct 1 ms 348 KB n = 2, 122 is a correct answer
23 Correct 1 ms 348 KB n = 10, 117 is a correct answer
24 Correct 1 ms 348 KB n = 10, 336 is a correct answer
25 Correct 0 ms 348 KB n = 10, 438 is a correct answer
26 Correct 0 ms 348 KB n = 10, 206 is a correct answer
27 Correct 1 ms 348 KB n = 10, 636 is a correct answer
28 Correct 0 ms 348 KB n = 4, 2399 is a correct answer
29 Correct 1 ms 532 KB n = 10, 10992 is a correct answer
30 Correct 1 ms 348 KB n = 10, 3112 is a correct answer
31 Execution timed out 2095 ms 2140 KB Time limit exceeded
32 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB n = 4, 80 is a correct answer
2 Correct 0 ms 348 KB n = 9, 110 is a correct answer
3 Correct 0 ms 344 KB n = 4, 21 is a correct answer
4 Correct 1 ms 344 KB n = 3, 4 is a correct answer
5 Correct 0 ms 348 KB n = 2, 62 is a correct answer
6 Correct 0 ms 348 KB n = 2, 3 is a correct answer
7 Correct 0 ms 348 KB n = 3, 29 is a correct answer
8 Correct 0 ms 348 KB n = 2, 3 is a correct answer
9 Correct 0 ms 348 KB n = 2, 3 is a correct answer
10 Correct 1 ms 348 KB n = 2, 2000000001 is a correct answer
11 Correct 0 ms 348 KB n = 2, 3000000000 is a correct answer
12 Correct 0 ms 344 KB n = 3, 3000000000 is a correct answer
13 Correct 0 ms 348 KB n = 3, 3000000000 is a correct answer
14 Correct 0 ms 348 KB n = 4, 3000000001 is a correct answer
15 Correct 1 ms 348 KB n = 4, 4000000000 is a correct answer
16 Correct 0 ms 444 KB n = 5, 4000000000 is a correct answer
17 Correct 1 ms 348 KB n = 10, 1000000343 is a correct answer
18 Correct 1 ms 348 KB n = 10, 3189 is a correct answer
19 Correct 1 ms 532 KB n = 10, 7000000000 is a correct answer
20 Correct 0 ms 348 KB n = 5, 12 is a correct answer
21 Correct 1 ms 348 KB n = 5, 25 is a correct answer
22 Correct 1 ms 348 KB n = 2, 122 is a correct answer
23 Correct 1 ms 348 KB n = 10, 117 is a correct answer
24 Correct 1 ms 348 KB n = 10, 336 is a correct answer
25 Correct 0 ms 348 KB n = 10, 438 is a correct answer
26 Correct 0 ms 348 KB n = 10, 206 is a correct answer
27 Correct 1 ms 348 KB n = 10, 636 is a correct answer
28 Correct 0 ms 348 KB n = 4, 2399 is a correct answer
29 Correct 1 ms 532 KB n = 10, 10992 is a correct answer
30 Correct 1 ms 348 KB n = 10, 3112 is a correct answer
31 Execution timed out 2095 ms 2140 KB Time limit exceeded
32 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB n = 4, 80 is a correct answer
2 Correct 0 ms 348 KB n = 9, 110 is a correct answer
3 Correct 0 ms 344 KB n = 4, 21 is a correct answer
4 Correct 1 ms 344 KB n = 3, 4 is a correct answer
5 Correct 0 ms 348 KB n = 2, 62 is a correct answer
6 Correct 0 ms 348 KB n = 2, 3 is a correct answer
7 Correct 0 ms 348 KB n = 3, 29 is a correct answer
8 Correct 0 ms 348 KB n = 2, 3 is a correct answer
9 Correct 0 ms 348 KB n = 2, 3 is a correct answer
10 Correct 1 ms 348 KB n = 2, 2000000001 is a correct answer
11 Correct 0 ms 348 KB n = 2, 3000000000 is a correct answer
12 Correct 0 ms 344 KB n = 3, 3000000000 is a correct answer
13 Correct 0 ms 348 KB n = 3, 3000000000 is a correct answer
14 Correct 0 ms 348 KB n = 4, 3000000001 is a correct answer
15 Correct 1 ms 348 KB n = 4, 4000000000 is a correct answer
16 Correct 0 ms 444 KB n = 5, 4000000000 is a correct answer
17 Correct 1 ms 348 KB n = 10, 1000000343 is a correct answer
18 Correct 1 ms 348 KB n = 10, 3189 is a correct answer
19 Correct 1 ms 532 KB n = 10, 7000000000 is a correct answer
20 Correct 0 ms 348 KB n = 5, 12 is a correct answer
21 Correct 1 ms 348 KB n = 5, 25 is a correct answer
22 Correct 1 ms 348 KB n = 2, 122 is a correct answer
23 Correct 1 ms 348 KB n = 10, 117 is a correct answer
24 Correct 1 ms 348 KB n = 10, 336 is a correct answer
25 Correct 0 ms 348 KB n = 10, 438 is a correct answer
26 Correct 0 ms 348 KB n = 10, 206 is a correct answer
27 Correct 1 ms 348 KB n = 10, 636 is a correct answer
28 Correct 0 ms 348 KB n = 4, 2399 is a correct answer
29 Correct 1 ms 532 KB n = 10, 10992 is a correct answer
30 Correct 1 ms 348 KB n = 10, 3112 is a correct answer
31 Execution timed out 2095 ms 2140 KB Time limit exceeded
32 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB n = 4, 80 is a correct answer
2 Correct 0 ms 348 KB n = 9, 110 is a correct answer
3 Correct 0 ms 344 KB n = 4, 21 is a correct answer
4 Correct 1 ms 344 KB n = 3, 4 is a correct answer
5 Correct 0 ms 348 KB n = 2, 62 is a correct answer
6 Correct 0 ms 348 KB n = 2, 3 is a correct answer
7 Correct 0 ms 348 KB n = 3, 29 is a correct answer
8 Correct 0 ms 348 KB n = 2, 3 is a correct answer
9 Correct 0 ms 348 KB n = 2, 3 is a correct answer
10 Correct 1 ms 348 KB n = 2, 2000000001 is a correct answer
11 Correct 0 ms 348 KB n = 2, 3000000000 is a correct answer
12 Correct 0 ms 344 KB n = 3, 3000000000 is a correct answer
13 Correct 0 ms 348 KB n = 3, 3000000000 is a correct answer
14 Correct 0 ms 348 KB n = 4, 3000000001 is a correct answer
15 Correct 1 ms 348 KB n = 4, 4000000000 is a correct answer
16 Correct 0 ms 444 KB n = 5, 4000000000 is a correct answer
17 Correct 1 ms 348 KB n = 10, 1000000343 is a correct answer
18 Correct 1 ms 348 KB n = 10, 3189 is a correct answer
19 Correct 1 ms 532 KB n = 10, 7000000000 is a correct answer
20 Correct 0 ms 348 KB n = 5, 12 is a correct answer
21 Correct 1 ms 348 KB n = 5, 25 is a correct answer
22 Correct 1 ms 348 KB n = 2, 122 is a correct answer
23 Correct 1 ms 348 KB n = 10, 117 is a correct answer
24 Correct 1 ms 348 KB n = 10, 336 is a correct answer
25 Correct 0 ms 348 KB n = 10, 438 is a correct answer
26 Correct 0 ms 348 KB n = 10, 206 is a correct answer
27 Correct 1 ms 348 KB n = 10, 636 is a correct answer
28 Correct 0 ms 348 KB n = 4, 2399 is a correct answer
29 Correct 1 ms 532 KB n = 10, 10992 is a correct answer
30 Correct 1 ms 348 KB n = 10, 3112 is a correct answer
31 Execution timed out 2095 ms 2140 KB Time limit exceeded
32 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB n = 4, 80 is a correct answer
2 Correct 0 ms 348 KB n = 9, 110 is a correct answer
3 Correct 0 ms 344 KB n = 4, 21 is a correct answer
4 Correct 1 ms 344 KB n = 3, 4 is a correct answer
5 Correct 0 ms 348 KB n = 2, 62 is a correct answer
6 Correct 0 ms 348 KB n = 2, 3 is a correct answer
7 Correct 0 ms 348 KB n = 3, 29 is a correct answer
8 Correct 0 ms 348 KB n = 2, 3 is a correct answer
9 Correct 0 ms 348 KB n = 2, 3 is a correct answer
10 Correct 1 ms 348 KB n = 2, 2000000001 is a correct answer
11 Correct 0 ms 348 KB n = 2, 3000000000 is a correct answer
12 Correct 0 ms 344 KB n = 3, 3000000000 is a correct answer
13 Correct 0 ms 348 KB n = 3, 3000000000 is a correct answer
14 Correct 0 ms 348 KB n = 4, 3000000001 is a correct answer
15 Correct 1 ms 348 KB n = 4, 4000000000 is a correct answer
16 Correct 0 ms 444 KB n = 5, 4000000000 is a correct answer
17 Correct 1 ms 348 KB n = 10, 1000000343 is a correct answer
18 Correct 1 ms 348 KB n = 10, 3189 is a correct answer
19 Correct 1 ms 532 KB n = 10, 7000000000 is a correct answer
20 Correct 0 ms 348 KB n = 5, 12 is a correct answer
21 Correct 1 ms 348 KB n = 5, 25 is a correct answer
22 Correct 1 ms 348 KB n = 2, 122 is a correct answer
23 Correct 1 ms 348 KB n = 10, 117 is a correct answer
24 Correct 1 ms 348 KB n = 10, 336 is a correct answer
25 Correct 0 ms 348 KB n = 10, 438 is a correct answer
26 Correct 0 ms 348 KB n = 10, 206 is a correct answer
27 Correct 1 ms 348 KB n = 10, 636 is a correct answer
28 Correct 0 ms 348 KB n = 4, 2399 is a correct answer
29 Correct 1 ms 532 KB n = 10, 10992 is a correct answer
30 Correct 1 ms 348 KB n = 10, 3112 is a correct answer
31 Execution timed out 2095 ms 2140 KB Time limit exceeded
32 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB n = 4, 80 is a correct answer
2 Correct 0 ms 348 KB n = 9, 110 is a correct answer
3 Correct 0 ms 344 KB n = 4, 21 is a correct answer
4 Correct 1 ms 344 KB n = 3, 4 is a correct answer
5 Correct 0 ms 348 KB n = 2, 62 is a correct answer
6 Correct 0 ms 348 KB n = 2, 3 is a correct answer
7 Correct 0 ms 348 KB n = 3, 29 is a correct answer
8 Correct 0 ms 348 KB n = 2, 3 is a correct answer
9 Correct 0 ms 348 KB n = 2, 3 is a correct answer
10 Correct 1 ms 348 KB n = 2, 2000000001 is a correct answer
11 Correct 0 ms 348 KB n = 2, 3000000000 is a correct answer
12 Correct 0 ms 344 KB n = 3, 3000000000 is a correct answer
13 Correct 0 ms 348 KB n = 3, 3000000000 is a correct answer
14 Correct 0 ms 348 KB n = 4, 3000000001 is a correct answer
15 Correct 1 ms 348 KB n = 4, 4000000000 is a correct answer
16 Correct 0 ms 444 KB n = 5, 4000000000 is a correct answer
17 Correct 1 ms 348 KB n = 10, 1000000343 is a correct answer
18 Correct 1 ms 348 KB n = 10, 3189 is a correct answer
19 Correct 1 ms 532 KB n = 10, 7000000000 is a correct answer
20 Correct 0 ms 348 KB n = 5, 12 is a correct answer
21 Correct 1 ms 348 KB n = 5, 25 is a correct answer
22 Correct 1 ms 348 KB n = 2, 122 is a correct answer
23 Correct 1 ms 348 KB n = 10, 117 is a correct answer
24 Correct 1 ms 348 KB n = 10, 336 is a correct answer
25 Correct 0 ms 348 KB n = 10, 438 is a correct answer
26 Correct 0 ms 348 KB n = 10, 206 is a correct answer
27 Correct 1 ms 348 KB n = 10, 636 is a correct answer
28 Correct 0 ms 348 KB n = 4, 2399 is a correct answer
29 Correct 1 ms 532 KB n = 10, 10992 is a correct answer
30 Correct 1 ms 348 KB n = 10, 3112 is a correct answer
31 Execution timed out 2095 ms 2140 KB Time limit exceeded
32 Halted 0 ms 0 KB -