Submission #954483

# Submission time Handle Problem Language Result Execution time Memory
954483 2024-03-28T03:32:42 Z GrandTiger1729 Netrpeljivost (COI23_netrpeljivost) C++17
27 / 100
1500 ms 6228 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));
    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]);
                    }
                }
            }
        }
    };
    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 1 ms 348 KB Output is correct
3 Correct 0 ms 464 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 352 KB Output is correct
6 Correct 0 ms 356 KB Output is correct
7 Correct 0 ms 600 KB Output is correct
8 Correct 1 ms 464 KB Output is correct
9 Correct 1 ms 352 KB Output is correct
10 Correct 0 ms 352 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 352 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 464 KB Output is correct
15 Correct 0 ms 352 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 352 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 596 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 1 ms 348 KB Output is correct
3 Correct 0 ms 464 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 352 KB Output is correct
6 Correct 0 ms 356 KB Output is correct
7 Correct 0 ms 600 KB Output is correct
8 Correct 1 ms 464 KB Output is correct
9 Correct 1 ms 352 KB Output is correct
10 Correct 0 ms 352 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 352 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 464 KB Output is correct
15 Correct 0 ms 352 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 352 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 596 KB Output is correct
20 Correct 1 ms 356 KB Output is correct
21 Correct 9 ms 604 KB Output is correct
22 Correct 9 ms 860 KB Output is correct
23 Correct 9 ms 604 KB Output is correct
24 Correct 1 ms 612 KB Output is correct
25 Correct 1 ms 352 KB Output is correct
26 Correct 10 ms 828 KB Output is correct
27 Correct 10 ms 724 KB Output is correct
28 Correct 10 ms 612 KB Output is correct
29 Correct 10 ms 760 KB Output is correct
30 Correct 9 ms 644 KB Output is correct
31 Correct 9 ms 604 KB Output is correct
32 Correct 12 ms 828 KB Output is correct
33 Correct 11 ms 600 KB Output is correct
34 Correct 9 ms 604 KB Output is correct
35 Correct 9 ms 680 KB Output is correct
36 Correct 13 ms 604 KB Output is correct
37 Correct 9 ms 600 KB Output is correct
38 Correct 9 ms 636 KB Output is correct
39 Correct 9 ms 604 KB Output is correct
40 Correct 9 ms 692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 464 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 352 KB Output is correct
6 Correct 0 ms 356 KB Output is correct
7 Correct 0 ms 600 KB Output is correct
8 Correct 1 ms 464 KB Output is correct
9 Correct 1 ms 352 KB Output is correct
10 Correct 0 ms 352 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 352 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 464 KB Output is correct
15 Correct 0 ms 352 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 352 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 596 KB Output is correct
20 Correct 1 ms 356 KB Output is correct
21 Correct 9 ms 604 KB Output is correct
22 Correct 9 ms 860 KB Output is correct
23 Correct 9 ms 604 KB Output is correct
24 Correct 1 ms 612 KB Output is correct
25 Correct 1 ms 352 KB Output is correct
26 Correct 10 ms 828 KB Output is correct
27 Correct 10 ms 724 KB Output is correct
28 Correct 10 ms 612 KB Output is correct
29 Correct 10 ms 760 KB Output is correct
30 Correct 9 ms 644 KB Output is correct
31 Correct 9 ms 604 KB Output is correct
32 Correct 12 ms 828 KB Output is correct
33 Correct 11 ms 600 KB Output is correct
34 Correct 9 ms 604 KB Output is correct
35 Correct 9 ms 680 KB Output is correct
36 Correct 13 ms 604 KB Output is correct
37 Correct 9 ms 600 KB Output is correct
38 Correct 9 ms 636 KB Output is correct
39 Correct 9 ms 604 KB Output is correct
40 Correct 9 ms 692 KB Output is correct
41 Execution timed out 1519 ms 6228 KB Time limit exceeded
42 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 464 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 352 KB Output is correct
6 Correct 0 ms 356 KB Output is correct
7 Correct 0 ms 600 KB Output is correct
8 Correct 1 ms 464 KB Output is correct
9 Correct 1 ms 352 KB Output is correct
10 Correct 0 ms 352 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 352 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 464 KB Output is correct
15 Correct 0 ms 352 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 352 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 596 KB Output is correct
20 Correct 1 ms 356 KB Output is correct
21 Correct 9 ms 604 KB Output is correct
22 Correct 9 ms 860 KB Output is correct
23 Correct 9 ms 604 KB Output is correct
24 Correct 1 ms 612 KB Output is correct
25 Correct 1 ms 352 KB Output is correct
26 Correct 10 ms 828 KB Output is correct
27 Correct 10 ms 724 KB Output is correct
28 Correct 10 ms 612 KB Output is correct
29 Correct 10 ms 760 KB Output is correct
30 Correct 9 ms 644 KB Output is correct
31 Correct 9 ms 604 KB Output is correct
32 Correct 12 ms 828 KB Output is correct
33 Correct 11 ms 600 KB Output is correct
34 Correct 9 ms 604 KB Output is correct
35 Correct 9 ms 680 KB Output is correct
36 Correct 13 ms 604 KB Output is correct
37 Correct 9 ms 600 KB Output is correct
38 Correct 9 ms 636 KB Output is correct
39 Correct 9 ms 604 KB Output is correct
40 Correct 9 ms 692 KB Output is correct
41 Execution timed out 1519 ms 6228 KB Time limit exceeded
42 Halted 0 ms 0 KB -