이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define ii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vii vector<ii>
#define vll vector<ll>
#define vpll vector<pll>
#define msi multiset<int>
#define si set<int>
#define PB push_back
#define PF push_front
#define PPB pop_back
#define PPF pop_front
#define X first
#define Y second
#define MP make_pair
#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
const int mod = 1e9 + 7;
const int MOD = 998244353;
const int inf = mod;
const ll INF = 1e18;
const int MAXN = 2049;
const int logo = 11;
const int off = 1 << logo;
const int trsz = off << 1;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
ll c[MAXN][MAXN], dp[MAXN][MAXN];
void solve(){
int n;
cin >> n;
for(int i=0; i<n; i++){
for(int j=0; j<n; j++) cin >> c[i][j];
}
for(int p=1; p<n; p++){
int sz = p & (-p);
int psz = sz * 2;
for(int tr=0; tr<n; tr++){
int bl = tr / psz * psz;
int ls = bl + psz - 1;
int mi = (bl + ls) / 2;
int pr = bl;
if(tr <= mi){
pr = mi + 1;
}
dp[p][tr] = INF;
for(int k=0; k<sz; k++){
dp[p][tr] = min(dp[p][tr], dp[p - 1][pr + k] + c[pr + k][tr]);
}
}
}
ll ans = INF;
for(int i=0; i<n; i++) ans = min(ans, dp[n - 1][i]);
cout << ans << "\n";
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t = 1;
//cin >> t;
while(t--) solve();
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... |