Submission #1013596

# Submission time Handle Problem Language Result Execution time Memory
1013596 2024-07-03T17:15:38 Z amine_aroua Netrpeljivost (COI23_netrpeljivost) C++17
10 / 100
1500 ms 600 KB
#include<bits/stdc++.h>
using namespace std;
#define intt long long
#define pb push_back
vector<vector<int>> mat;
int n ;
const intt INF = 1e18;
intt solve(int node ,int fr , int bk ,int l , int r)
{
    if(l + 1 == r)
    {
        return mat[fr][bk];
    }
    int m = (l + r)/2;
    intt ans = INF;
    if(l <= fr && fr <= m && m + 1 <= bk && bk <= r)
    {
        for(int v1 = l ; v1 <= m ;v1++)
        {
            if(v1 == fr)
                continue;
            for(int v2 = m + 1; v2 <= r ; v2++)
            {
                if(v2 == bk)
                    continue;
                ans = min(ans , solve(2*node , fr , v1 , l , m) + solve(2*node + 1 , v2 , bk , m + 1 , r) + mat[v1][v2]);
            }
        }
    }
    else if(l <= bk && bk <= m && m + 1 <= fr && fr <= r)
    {
        for(int v1 = l ; v1 <= m ; v1++)
        {
            if(v1 == bk)
                continue;
            for(int v2 = m + 1 ; v2 <= r ; v2++)
            {
                if(v2 == fr)
                    continue;
                ans = min(ans , solve(2*node , v1 , bk , l , m) + solve(2*node + 1 , fr , v2 , m + 1 , r) + mat[v1][v2]);
            }
        }
    }
    return ans;
}
int main()
{
    cin>>n;
    mat = vector<vector<int>> (n , vector<int>(n));
    for(int i = 0 ; i < n ; i++)
    {
        for(int j = 0 ; j < n ; j++)
        {
            cin>>mat[i][j];
        }
    }
    if(n == 1)
    {
        cout<<0<<'\n';
        return 0;
    }
    intt ans = LLONG_MAX;
    int l = 0 , r = n - 1;
    int m = (l  + r)/2;
    for(int fr = l ; fr <= m ; fr++)
    {
        for(int bk = m + 1 ; bk <= r ; bk++)
        {
            ans = min({ans , solve(1 , fr , bk , l , r) , solve(1 , bk , fr , l , r)});
        }
    }
    cout<<ans<<'\n';
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 2 ms 344 KB Output is correct
4 Correct 2 ms 436 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 2 ms 344 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 2 ms 348 KB Output is correct
20 Correct 2 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 2 ms 344 KB Output is correct
4 Correct 2 ms 436 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 2 ms 344 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 2 ms 348 KB Output is correct
20 Correct 2 ms 348 KB Output is correct
21 Execution timed out 1567 ms 600 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 2 ms 344 KB Output is correct
4 Correct 2 ms 436 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 2 ms 344 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 2 ms 348 KB Output is correct
20 Correct 2 ms 348 KB Output is correct
21 Execution timed out 1567 ms 600 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 2 ms 344 KB Output is correct
4 Correct 2 ms 436 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 2 ms 344 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 2 ms 348 KB Output is correct
20 Correct 2 ms 348 KB Output is correct
21 Execution timed out 1567 ms 600 KB Time limit exceeded
22 Halted 0 ms 0 KB -