답안 #954488

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
954488 2024-03-28T03:40:42 Z GrandTiger1729 Netrpeljivost (COI23_netrpeljivost) C++17
59 / 100
1500 ms 82732 KB
#pragma GCC optimize("O3")
#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 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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 500 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 600 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 504 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 512 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 500 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 600 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 504 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 512 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 2 ms 604 KB Output is correct
22 Correct 2 ms 604 KB Output is correct
23 Correct 2 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 600 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 3 ms 1012 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 604 KB Output is correct
40 Correct 2 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 500 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 600 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 504 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 512 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 2 ms 604 KB Output is correct
22 Correct 2 ms 604 KB Output is correct
23 Correct 2 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 600 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 3 ms 1012 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 604 KB Output is correct
40 Correct 2 ms 604 KB Output is correct
41 Correct 39 ms 5628 KB Output is correct
42 Correct 39 ms 5460 KB Output is correct
43 Correct 40 ms 5460 KB Output is correct
44 Correct 43 ms 5596 KB Output is correct
45 Correct 39 ms 5632 KB Output is correct
46 Correct 39 ms 5468 KB Output is correct
47 Correct 41 ms 5632 KB Output is correct
48 Correct 39 ms 5628 KB Output is correct
49 Correct 40 ms 5588 KB Output is correct
50 Correct 39 ms 5468 KB Output is correct
51 Correct 42 ms 5724 KB Output is correct
52 Correct 39 ms 5468 KB Output is correct
53 Correct 39 ms 5592 KB Output is correct
54 Correct 38 ms 5468 KB Output is correct
55 Correct 38 ms 5716 KB Output is correct
56 Correct 41 ms 5628 KB Output is correct
57 Correct 41 ms 5628 KB Output is correct
58 Correct 38 ms 5468 KB Output is correct
59 Correct 38 ms 5468 KB Output is correct
60 Correct 40 ms 5468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 500 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 600 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 504 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 512 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 2 ms 604 KB Output is correct
22 Correct 2 ms 604 KB Output is correct
23 Correct 2 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 600 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 3 ms 1012 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 604 KB Output is correct
40 Correct 2 ms 604 KB Output is correct
41 Correct 39 ms 5628 KB Output is correct
42 Correct 39 ms 5460 KB Output is correct
43 Correct 40 ms 5460 KB Output is correct
44 Correct 43 ms 5596 KB Output is correct
45 Correct 39 ms 5632 KB Output is correct
46 Correct 39 ms 5468 KB Output is correct
47 Correct 41 ms 5632 KB Output is correct
48 Correct 39 ms 5628 KB Output is correct
49 Correct 40 ms 5588 KB Output is correct
50 Correct 39 ms 5468 KB Output is correct
51 Correct 42 ms 5724 KB Output is correct
52 Correct 39 ms 5468 KB Output is correct
53 Correct 39 ms 5592 KB Output is correct
54 Correct 38 ms 5468 KB Output is correct
55 Correct 38 ms 5716 KB Output is correct
56 Correct 41 ms 5628 KB Output is correct
57 Correct 41 ms 5628 KB Output is correct
58 Correct 38 ms 5468 KB Output is correct
59 Correct 38 ms 5468 KB Output is correct
60 Correct 40 ms 5468 KB Output is correct
61 Execution timed out 1522 ms 82732 KB Time limit exceeded
62 Halted 0 ms 0 KB -