Submission #1312802

#TimeUsernameProblemLanguageResultExecution timeMemory
1312802syanvuNetrpeljivost (COI23_netrpeljivost)C++20
100 / 100
390 ms66184 KiB
#pragma optimize ("g",on)
#pragma GCC optimize ("inline")
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("03")
#include <bits/stdc++.h>

#define pb push_back
#define SS ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
#define int long long
#define all(v) v.begin(),v.end()
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int N = 1e5 + 1, inf = 1e18, mod = 998244353;

void solve(){
    int n;
    cin >> n;
    int a[n][n];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            cin >> a[i][j];
        }
    }
    vector<vector<int>> dp(n, vector<int>(n, inf));
    for(int i = 0; i < n; i++){
        dp[0][i] = 0;
    }
    for(int i = 0; i < n - 1; i++){
        int sz = 0, cur = i + 1;
        for(int j = 0; j < 20; j++){
            if(cur & 1){
                sz = (1ll << j);
                break;
            }
            cur >>= 1;
        }
        for(int x = 0; x < n; x++){
            if(dp[i][x] >= inf) continue;
            int y = (x ^ sz);
            y -= y & (sz - 1);
            for(int j = 0; j < sz; j++){
                dp[i + 1][y] = min(dp[i + 1][y], dp[i][x] + a[x][y]);
                y++;
            }
        }
    }
    int ans = inf;
    for(int i = 0; i < n; i++){
        ans = min(ans, dp[n - 1][i]);
    }
    cout << ans;
}

signed main(){
    SS
    // freopen("trains.in", "r", stdin);
    // freopen("trains.out", "w", stdout);

    int t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...