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;
typedef long long lo;
#define fi first
#define se second
#define endl "\n"
#define pb push_back
#define int long long
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)
#define _ << " " <<
const lo inf = 1000000000000000000;
const lo li = 2050;
const lo mod = 1000000007;
int n,m,a[li][li],k,flag,t,p[li],l[li],r[li];
int cev;
string s;
vector<int> v;
inline void dfs(int node,int start,int end){
if(start==end){return ;}
dfs(node*2,start,mid),dfs(node*2+1,mid+1,end);
//~ if(a[r[node*2]][l[node*2+1]]>a[l[node*2]][r[node*2+1]]){
//~ swap(l[node*2+1],l[node*2]);
//~ swap(r[node*2+1],r[node*2]);
//~ }
if(rand()%2==1){
swap(l[node*2+1],l[node*2]);
swap(r[node*2+1],r[node*2]);
}
//~ cout<<l[node*2+1] _ r[node*2] _ node _ start _ end<<endl;
cev+=a[l[node*2+1]][r[node*2]];
l[node]=l[node*2];
r[node]=r[node*2+1];
}
int32_t main(void){
fio();
cin>>n;
srand(time(NULL));
FOR{
for(int j=1;j<=n;j++)cin>>a[i][j];
l[i+n-1]=i,r[i+n-1]=i;
}
int mn=inf;
for(int i=1;i<=10000;i++){cev=0;dfs(1,1,n);mn=min(mn,cev);}
cout<<mn<<endl;
return 0;
}
# | 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... |