Submission #954486

# Submission time Handle Problem Language Result Execution time Memory
954486 2024-03-28T03:40:02 Z GrandTiger1729 Netrpeljivost (COI23_netrpeljivost) C++17
59 / 100
1500 ms 123168 KB
#include <bits/stdc++.h>
using namespace std;

const long long INF = 1e18;
int main()
{
    cin.tie(0)->sync_with_stdio(0);
    int n;
    cin >> n;
    vector<vector<int>> a(n, vector<int>(n));
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            cin >> a[i][j];
        }
    }
    if (n == 1)
    {
        cout << 0 << '\n';
        return 0;
    }
    vector<vector<long long>> dp(n, vector<long long>(n, INF)),
                             dp2(n, vector<long long>(n, INF));
    function<void(int, int)> solve = [&](int l, int r)
    {
        if (l + 2 == r)
        {
            dp[l][r - 1] = dp[r - 1][l] = a[l][r - 1];
            return;
        }
        int mid = (l + r) / 2;
        solve(l, mid);
        solve(mid, r);
        // for (int i1 = l; i1 < (l + mid) / 2; i1++)
        // {
        //     for (int j1 = (l + mid) / 2; j1 < mid; j1++)
        //     {
        //         for (int i2 = mid; i2 < (mid + r) / 2; i2++)
        //         {
        //             for (int j2 = (mid + r) / 2; j2 < r; j2++)
        //             {
        //                 dp[i1][i2] = min(dp[i1][i2], dp[i1][j1] + a[j1][j2] + dp[j2][i2]);
        //                 dp[i2][i1] = min(dp[i2][i1], dp[i1][i2]);
        //                 dp[i1][j2] = min(dp[i1][j2], dp[i1][j1] + a[j1][i2] + dp[i2][j2]);
        //                 dp[j2][i1] = min(dp[j2][i1], dp[i1][j2]);
        //                 dp[j1][i2] = min(dp[j1][i2], dp[j1][i1] + a[i1][j2] + dp[j2][i2]);
        //                 dp[i2][j1] = min(dp[i2][j1], dp[j1][i2]);
        //                 dp[j1][j2] = min(dp[j1][j2], dp[j1][i1] + a[i1][i2] + dp[i2][j2]);
        //                 dp[j2][j1] = min(dp[j2][j1], dp[j1][j2]);
        //             }
        //         }
        //     }
        // }
        for (int i = l; i < (l + mid) / 2; i++)
        {
            for (int j = (l + mid) / 2; j < mid; j++)
            {
                for (int k = mid; k < r; k++)
                {
                    dp2[i][k] = min(dp2[i][k], dp[i][j] + a[j][k]);
                    dp2[j][k] = min(dp2[j][k], dp[j][i] + a[i][k]);
                }
            }
        }
        for (int i = l; i < mid; i++)
        {
            for (int j = mid; j < (mid + r) / 2; j++)
            {
                for (int k = (mid + r) / 2; k < r; k++)
                {
                    dp[i][k] = min(dp[i][k], dp2[i][j] + dp[j][k]);
                    dp[i][j] = min(dp[i][j], dp2[i][k] + dp[k][j]);
                }
            }
        }
        for (int i = l; i < mid; i++)
        {
            for (int j = mid; j < r; j++)
            {
                dp[j][i] = min(dp[j][i], dp[i][j]);
            }
        }
    };
    solve(0, n);
    long long ans = INF;
    for (int i = 0; i < n / 2; i++)
    {
        for (int j = n / 2; j < n; j++)
        {
            ans = min(ans, dp[i][j]);
            ans = min(ans, dp[j][i]);
        }
    }
    cout << ans << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 352 KB Output is correct
4 Correct 0 ms 352 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 352 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 352 KB Output is correct
12 Correct 0 ms 352 KB Output is correct
13 Correct 0 ms 352 KB Output is correct
14 Correct 0 ms 504 KB Output is correct
15 Correct 0 ms 356 KB Output is correct
16 Correct 1 ms 356 KB Output is correct
17 Correct 0 ms 356 KB Output is correct
18 Correct 1 ms 356 KB Output is correct
19 Correct 0 ms 356 KB Output is correct
20 Correct 1 ms 356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 352 KB Output is correct
4 Correct 0 ms 352 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 352 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 352 KB Output is correct
12 Correct 0 ms 352 KB Output is correct
13 Correct 0 ms 352 KB Output is correct
14 Correct 0 ms 504 KB Output is correct
15 Correct 0 ms 356 KB Output is correct
16 Correct 1 ms 356 KB Output is correct
17 Correct 0 ms 356 KB Output is correct
18 Correct 1 ms 356 KB Output is correct
19 Correct 0 ms 356 KB Output is correct
20 Correct 1 ms 356 KB Output is correct
21 Correct 2 ms 604 KB Output is correct
22 Correct 2 ms 604 KB Output is correct
23 Correct 3 ms 604 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 2 ms 604 KB Output is correct
27 Correct 2 ms 600 KB Output is correct
28 Correct 2 ms 604 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 2 ms 604 KB Output is correct
31 Correct 2 ms 604 KB Output is correct
32 Correct 2 ms 604 KB Output is correct
33 Correct 2 ms 604 KB Output is correct
34 Correct 2 ms 604 KB Output is correct
35 Correct 2 ms 604 KB Output is correct
36 Correct 2 ms 604 KB Output is correct
37 Correct 2 ms 604 KB Output is correct
38 Correct 2 ms 604 KB Output is correct
39 Correct 2 ms 600 KB Output is correct
40 Correct 2 ms 612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 352 KB Output is correct
4 Correct 0 ms 352 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 352 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 352 KB Output is correct
12 Correct 0 ms 352 KB Output is correct
13 Correct 0 ms 352 KB Output is correct
14 Correct 0 ms 504 KB Output is correct
15 Correct 0 ms 356 KB Output is correct
16 Correct 1 ms 356 KB Output is correct
17 Correct 0 ms 356 KB Output is correct
18 Correct 1 ms 356 KB Output is correct
19 Correct 0 ms 356 KB Output is correct
20 Correct 1 ms 356 KB Output is correct
21 Correct 2 ms 604 KB Output is correct
22 Correct 2 ms 604 KB Output is correct
23 Correct 3 ms 604 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 2 ms 604 KB Output is correct
27 Correct 2 ms 600 KB Output is correct
28 Correct 2 ms 604 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 2 ms 604 KB Output is correct
31 Correct 2 ms 604 KB Output is correct
32 Correct 2 ms 604 KB Output is correct
33 Correct 2 ms 604 KB Output is correct
34 Correct 2 ms 604 KB Output is correct
35 Correct 2 ms 604 KB Output is correct
36 Correct 2 ms 604 KB Output is correct
37 Correct 2 ms 604 KB Output is correct
38 Correct 2 ms 604 KB Output is correct
39 Correct 2 ms 600 KB Output is correct
40 Correct 2 ms 612 KB Output is correct
41 Correct 40 ms 5472 KB Output is correct
42 Correct 41 ms 8172 KB Output is correct
43 Correct 41 ms 8032 KB Output is correct
44 Correct 41 ms 8036 KB Output is correct
45 Correct 45 ms 8288 KB Output is correct
46 Correct 40 ms 8032 KB Output is correct
47 Correct 40 ms 8024 KB Output is correct
48 Correct 41 ms 8028 KB Output is correct
49 Correct 43 ms 8024 KB Output is correct
50 Correct 41 ms 8164 KB Output is correct
51 Correct 40 ms 8144 KB Output is correct
52 Correct 43 ms 8024 KB Output is correct
53 Correct 40 ms 8176 KB Output is correct
54 Correct 42 ms 8028 KB Output is correct
55 Correct 44 ms 8028 KB Output is correct
56 Correct 44 ms 8284 KB Output is correct
57 Correct 41 ms 8208 KB Output is correct
58 Correct 44 ms 8032 KB Output is correct
59 Correct 40 ms 8156 KB Output is correct
60 Correct 41 ms 8148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 352 KB Output is correct
4 Correct 0 ms 352 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 352 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 352 KB Output is correct
12 Correct 0 ms 352 KB Output is correct
13 Correct 0 ms 352 KB Output is correct
14 Correct 0 ms 504 KB Output is correct
15 Correct 0 ms 356 KB Output is correct
16 Correct 1 ms 356 KB Output is correct
17 Correct 0 ms 356 KB Output is correct
18 Correct 1 ms 356 KB Output is correct
19 Correct 0 ms 356 KB Output is correct
20 Correct 1 ms 356 KB Output is correct
21 Correct 2 ms 604 KB Output is correct
22 Correct 2 ms 604 KB Output is correct
23 Correct 3 ms 604 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 2 ms 604 KB Output is correct
27 Correct 2 ms 600 KB Output is correct
28 Correct 2 ms 604 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 2 ms 604 KB Output is correct
31 Correct 2 ms 604 KB Output is correct
32 Correct 2 ms 604 KB Output is correct
33 Correct 2 ms 604 KB Output is correct
34 Correct 2 ms 604 KB Output is correct
35 Correct 2 ms 604 KB Output is correct
36 Correct 2 ms 604 KB Output is correct
37 Correct 2 ms 604 KB Output is correct
38 Correct 2 ms 604 KB Output is correct
39 Correct 2 ms 600 KB Output is correct
40 Correct 2 ms 612 KB Output is correct
41 Correct 40 ms 5472 KB Output is correct
42 Correct 41 ms 8172 KB Output is correct
43 Correct 41 ms 8032 KB Output is correct
44 Correct 41 ms 8036 KB Output is correct
45 Correct 45 ms 8288 KB Output is correct
46 Correct 40 ms 8032 KB Output is correct
47 Correct 40 ms 8024 KB Output is correct
48 Correct 41 ms 8028 KB Output is correct
49 Correct 43 ms 8024 KB Output is correct
50 Correct 41 ms 8164 KB Output is correct
51 Correct 40 ms 8144 KB Output is correct
52 Correct 43 ms 8024 KB Output is correct
53 Correct 40 ms 8176 KB Output is correct
54 Correct 42 ms 8028 KB Output is correct
55 Correct 44 ms 8028 KB Output is correct
56 Correct 44 ms 8284 KB Output is correct
57 Correct 41 ms 8208 KB Output is correct
58 Correct 44 ms 8032 KB Output is correct
59 Correct 40 ms 8156 KB Output is correct
60 Correct 41 ms 8148 KB Output is correct
61 Execution timed out 1566 ms 123168 KB Time limit exceeded
62 Halted 0 ms 0 KB -