# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
444808 | FEDIKUS | Raisins (IOI09_raisins) | C++17 | 288 ms | 24772 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>
#define mp make_pair
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define xx first
#define yy second
#define srt(a) sort(a.begin(),a.end());
#define srtg(a,int) sort(a.begin(),a.end(),greater<int>())
#define lb(a,x) lower_bound(a.begin(),a.end(),x)
#define up(a,x) upper_bound(a.begin(),a.end(),x)
#define fnd(a,x) find(a.begin(),a.end(),x)
#define vstart auto startt=chrono::system_clock::now()
#define vend auto endd=chrono::system_clock::now()
#define vvreme chrono::duration<double> vremee=endd-startt
#define ios ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef string str;
const int maxn=60;
int r[maxn][maxn];
int pref[maxn][maxn];
int memo[maxn][maxn][maxn][maxn];
inline int vr(int i,int j){
if(i<0 || j<0) return 0;
return pref[i][j];
}
inline int koliko(int i1,int j1,int i2,int j2){
return vr(i2,j2)-vr(i2,j1-1)-vr(i1-1,j2)+vr(i1-1,j1-1);
}
int resi(int i1,int j1,int i2,int j2){
if(i1==i2 && j1==j2) return 0;
if(memo[i1][j1][i2][j2]!=0) return memo[i1][j1][i2][j2];
int ret=INT_MAX;
for(int i=i1;i<i2;i++){
ret=min(ret,resi(i1,j1,i,j2)+resi(i+1,j1,i2,j2));
}
for(int j=j1;j<j2;j++){
ret=min(ret,resi(i1,j1,i2,j)+resi(i1,j+1,i2,j2));
}
ret+=koliko(i1,j1,i2,j2);
memo[i1][j1][i2][j2]=ret;
return ret;
}
void solve(){
int n,m;
cin>>n>>m;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++) cin>>r[i][j];
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
pref[i][j]=r[i][j];
if(i!=0 || j!=0) pref[i][j]+=vr(i-1,j)+vr(i,j-1)-vr(i-1,j-1);
}
}
cout<<resi(0,0,n-1,m-1);
}
int main(){
ios;
int t=1;
//cin>>t;
while(t--) solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |