Submission #1018748

# Submission time Handle Problem Language Result Execution time Memory
1018748 2024-07-10T09:18:19 Z MarwenElarbi Netrpeljivost (COI23_netrpeljivost) C++17
59 / 100
1500 ms 122784 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define se second
#define fi first
const int nax=2050;
int cost [nax][nax];
long long dp1[nax][nax];
long long dp[nax][nax];
void solve(int l,int r){
    if(l+1==r){
        dp[l][r]=dp[r][l]=cost[l][r];
        return;
    }
    int mid=(r+l)/2;
    solve(l,mid);
    solve(mid+1,r);
    for (int i = l; i <= mid; ++i)
    {
        for (int j1 = mid+1; j1 <= (mid+1+r)/2; ++j1)
        {
            for (int j2 = (mid+1+r)/2+1; j2 <= r; ++j2)
            {
                dp1[i][j1]=min(dp1[i][j1],dp[j1][j2]+cost[i][j2]);
                dp1[i][j2]=min(dp1[i][j2],dp[j1][j2]+cost[i][j1]);
            }
        }
    }
    for (int i1 = l; i1 <= (l+mid)/2; ++i1)
    {
        for (int i2 = (l+mid)/2+1; i2 <= mid; ++i2)
        {
            for (int j = mid+1; j <= r; ++j)
            {
                dp[i1][j]=min(dp[i1][j],dp1[i2][j]+dp[i1][i2]);
                dp[i2][j]=min(dp[i2][j],dp1[i1][j]+dp[i1][i2]);
            }
        }
    }
    for (int i = l; i <= mid; ++i)
    {
        for (int j = mid+1; j <= r; ++j)
        {
            dp[j][i]=dp[i][j];
        }
    }
}
int main() {/*
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif*/
    int n;
    cin>>n;
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < n; ++j)
        {
            dp[i][j]=dp1[i][j]=1e18;
        }
    }
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < n; ++j)
        {
            cin>>cost[i][j];
        }
    }
    long long ans=1e18;
    solve(0,n-1);
    for (int i = 0; i <= (n-1)/2; ++i)
    {
        for (int j = (n-1)/2+1; j <= n-1; ++j)
        {
            ans=min(ans,min(dp[i][j],dp[j][i]));
        }
    }
    cout <<ans<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 0 ms 428 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 0 ms 604 KB Output is correct
14 Correct 0 ms 604 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 0 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 0 ms 428 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 0 ms 604 KB Output is correct
14 Correct 0 ms 604 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 0 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 5 ms 2140 KB Output is correct
22 Correct 9 ms 2244 KB Output is correct
23 Correct 5 ms 2140 KB Output is correct
24 Correct 2 ms 1116 KB Output is correct
25 Correct 3 ms 1116 KB Output is correct
26 Correct 5 ms 2136 KB Output is correct
27 Correct 5 ms 2140 KB Output is correct
28 Correct 5 ms 2140 KB Output is correct
29 Correct 5 ms 2240 KB Output is correct
30 Correct 6 ms 2140 KB Output is correct
31 Correct 9 ms 2252 KB Output is correct
32 Correct 9 ms 2344 KB Output is correct
33 Correct 5 ms 2376 KB Output is correct
34 Correct 6 ms 2140 KB Output is correct
35 Correct 5 ms 2140 KB Output is correct
36 Correct 5 ms 2140 KB Output is correct
37 Correct 6 ms 2184 KB Output is correct
38 Correct 9 ms 2140 KB Output is correct
39 Correct 10 ms 2364 KB Output is correct
40 Correct 6 ms 2136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 0 ms 428 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 0 ms 604 KB Output is correct
14 Correct 0 ms 604 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 0 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 5 ms 2140 KB Output is correct
22 Correct 9 ms 2244 KB Output is correct
23 Correct 5 ms 2140 KB Output is correct
24 Correct 2 ms 1116 KB Output is correct
25 Correct 3 ms 1116 KB Output is correct
26 Correct 5 ms 2136 KB Output is correct
27 Correct 5 ms 2140 KB Output is correct
28 Correct 5 ms 2140 KB Output is correct
29 Correct 5 ms 2240 KB Output is correct
30 Correct 6 ms 2140 KB Output is correct
31 Correct 9 ms 2252 KB Output is correct
32 Correct 9 ms 2344 KB Output is correct
33 Correct 5 ms 2376 KB Output is correct
34 Correct 6 ms 2140 KB Output is correct
35 Correct 5 ms 2140 KB Output is correct
36 Correct 5 ms 2140 KB Output is correct
37 Correct 6 ms 2184 KB Output is correct
38 Correct 9 ms 2140 KB Output is correct
39 Correct 10 ms 2364 KB Output is correct
40 Correct 6 ms 2136 KB Output is correct
41 Correct 82 ms 14416 KB Output is correct
42 Correct 84 ms 17204 KB Output is correct
43 Correct 81 ms 14028 KB Output is correct
44 Correct 81 ms 14160 KB Output is correct
45 Correct 119 ms 14160 KB Output is correct
46 Correct 115 ms 14072 KB Output is correct
47 Correct 84 ms 14052 KB Output is correct
48 Correct 93 ms 14176 KB Output is correct
49 Correct 80 ms 14000 KB Output is correct
50 Correct 82 ms 14160 KB Output is correct
51 Correct 82 ms 14272 KB Output is correct
52 Correct 124 ms 16104 KB Output is correct
53 Correct 84 ms 16212 KB Output is correct
54 Correct 87 ms 16104 KB Output is correct
55 Correct 83 ms 17232 KB Output is correct
56 Correct 90 ms 16144 KB Output is correct
57 Correct 81 ms 16068 KB Output is correct
58 Correct 82 ms 17232 KB Output is correct
59 Correct 84 ms 16208 KB Output is correct
60 Correct 83 ms 16132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 0 ms 428 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 0 ms 604 KB Output is correct
14 Correct 0 ms 604 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 0 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 5 ms 2140 KB Output is correct
22 Correct 9 ms 2244 KB Output is correct
23 Correct 5 ms 2140 KB Output is correct
24 Correct 2 ms 1116 KB Output is correct
25 Correct 3 ms 1116 KB Output is correct
26 Correct 5 ms 2136 KB Output is correct
27 Correct 5 ms 2140 KB Output is correct
28 Correct 5 ms 2140 KB Output is correct
29 Correct 5 ms 2240 KB Output is correct
30 Correct 6 ms 2140 KB Output is correct
31 Correct 9 ms 2252 KB Output is correct
32 Correct 9 ms 2344 KB Output is correct
33 Correct 5 ms 2376 KB Output is correct
34 Correct 6 ms 2140 KB Output is correct
35 Correct 5 ms 2140 KB Output is correct
36 Correct 5 ms 2140 KB Output is correct
37 Correct 6 ms 2184 KB Output is correct
38 Correct 9 ms 2140 KB Output is correct
39 Correct 10 ms 2364 KB Output is correct
40 Correct 6 ms 2136 KB Output is correct
41 Correct 82 ms 14416 KB Output is correct
42 Correct 84 ms 17204 KB Output is correct
43 Correct 81 ms 14028 KB Output is correct
44 Correct 81 ms 14160 KB Output is correct
45 Correct 119 ms 14160 KB Output is correct
46 Correct 115 ms 14072 KB Output is correct
47 Correct 84 ms 14052 KB Output is correct
48 Correct 93 ms 14176 KB Output is correct
49 Correct 80 ms 14000 KB Output is correct
50 Correct 82 ms 14160 KB Output is correct
51 Correct 82 ms 14272 KB Output is correct
52 Correct 124 ms 16104 KB Output is correct
53 Correct 84 ms 16212 KB Output is correct
54 Correct 87 ms 16104 KB Output is correct
55 Correct 83 ms 17232 KB Output is correct
56 Correct 90 ms 16144 KB Output is correct
57 Correct 81 ms 16068 KB Output is correct
58 Correct 82 ms 17232 KB Output is correct
59 Correct 84 ms 16208 KB Output is correct
60 Correct 83 ms 16132 KB Output is correct
61 Execution timed out 1550 ms 122784 KB Time limit exceeded
62 Halted 0 ms 0 KB -