# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
542927 |
2022-03-28T13:16:35 Z |
Sho10 |
Raisins (IOI09_raisins) |
C++17 |
|
53 ms |
30708 KB |
#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho
using ll=long long;
using ld=long double;
int const INF=1000000005;
ll const LINF=1000000000000000005;
ll const mod=1000000007;
ld const PI=3.14159265359;
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define endl '\n'
#define CODE_START ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll n,m,dp[55][55][55][55],a[55][55];
void solve(ll xl,ll xr,ll yl,ll yr){
if(xl==xr&&yl==yr){
dp[xl][xr][yl][yr]=0;
return;
}
if(dp[xl][xr][yl][yr]!=LINF){
return;
}
ll sum=0;
for(ll i=xl;i<=xr;i++)
{
for(ll j=yl;j<=yr;j++)
{
sum+=a[i][j];
}
}
for(ll i=xl+1;i<=xr;i++)
{
solve(xl,i-1,yl,yr);
solve(i,xr,yl,yr);
dp[xl][xr][yl][yr]=min(dp[xl][xr][yl][yr],dp[xl][i-1][yl][yr]+dp[i][xr][yl][yr]+sum);
}
for(ll i=yl+1;i<=yr;i++)
{
solve(xl,xr,yl,i-1);
solve(xr,xr,i,yr);
dp[xl][xr][yl][yr]=min(dp[xl][xr][yl][yr],dp[xl][xr][yl][i-1]+dp[xl][xr][i][yr]+sum);
}
}
int32_t main(){
CODE_START;
cin>>n>>m;
for(ll i=1;i<=n;i++)
{
for(ll j=1;j<=m;j++)
{
cin>>a[i][j];
}
}
for(ll i=1;i<=n;i++)
{
for(ll j=1;j<=m;j++)
{
for(ll i1=i;i1<=n;i1++)
for(ll j1=j;j1<=m;j1++)
{
dp[i][i1][j][j1]=LINF;
}
}
}
solve(1,n,1,m);
cout<<dp[1][n][1][m]<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
6 |
Correct |
1 ms |
724 KB |
Output is correct |
7 |
Incorrect |
2 ms |
1228 KB |
Output isn't correct |
8 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
9 |
Incorrect |
3 ms |
4308 KB |
Output isn't correct |
10 |
Incorrect |
4 ms |
5076 KB |
Output isn't correct |
11 |
Incorrect |
3 ms |
3796 KB |
Output isn't correct |
12 |
Correct |
9 ms |
9428 KB |
Output is correct |
13 |
Incorrect |
13 ms |
12328 KB |
Output isn't correct |
14 |
Incorrect |
5 ms |
4564 KB |
Output isn't correct |
15 |
Incorrect |
16 ms |
14028 KB |
Output isn't correct |
16 |
Incorrect |
5 ms |
6952 KB |
Output isn't correct |
17 |
Incorrect |
11 ms |
11860 KB |
Output isn't correct |
18 |
Incorrect |
42 ms |
24732 KB |
Output isn't correct |
19 |
Correct |
53 ms |
28332 KB |
Output is correct |
20 |
Incorrect |
46 ms |
30708 KB |
Output isn't correct |