# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1029269 | berr | Netrpeljivost (COI23_netrpeljivost) | C++17 | 402 ms | 107272 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
void f(){
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
}
int dp[1<<11][(1<<11)+1];
int d[(1<<11)+1][(1<<11)+1];
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
//f();
int n; cin >> n;
for(int i=0; i<=n; i++){
for(int j=0; j<n; j++){
dp[j][i]=1e18;
}
dp[0][i]=0;
}
for(int i=0; i<n; i++){
for(int l=0; l<n; l++)
cin >> d[i][l];
}
for(int i=1; i<n; i++){
int c=0, val=i;
int f=0;
for(int h=0; h<11; h++){
if(val&(1<<h)){
c=h;
break;
}
}
for(int h=c; h<=11; h++){
f+=(1<<h);
}
for(int g=0; g<n; g++){
if(g&(1<<c)){
int h = g^(1<<c);
h&=f;
for(int l=0; l<(1<<c); l++){
dp[i][h+l]=min(dp[i][h+l], dp[i-1][g]+d[g][h+l]);
}
}
else{
int h = g^(1<<c);
h&=f;
for(int l=0; l<(1<<c); l++){
dp[i][h+l]=min(dp[i][h+l], dp[i-1][g]+d[g][h+l]);
}
}
}
}
int mi=1e18;
for(int l=0; l<n; l++) mi=min(mi, dp[n-1][l]);
cout<<mi;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |