# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
879498 | amin_2008 | Raisins (IOI09_raisins) | C++17 | 45 ms | 131072 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.
#pragma GCC optimize ("O3")
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
// author: amin_2008
#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll long long
#define vi vector<int>
#define vs vector<string>
#define vc vector<char>
#define vl vector<ll>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb push_back
#define bpc __builtin_popcount
#define pii pair<int, int>
#define pll pair<ll, ll>
#define piii pair<pii, int>
#define vpii vector<pii>
#define vpll vector<pll>
#define vvpii vector<vpii>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define ins insert
#define ts to_string
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define ld long double
#define ull unsigned long long
#define endl '\n'
#define int ll
using namespace std;
using namespace __gnu_pbds;
using namespace __cxx11;
template<class T> using ordered_set = tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int inf = 1e9;
const int mod = 1e9+7;
const int sz = 100;
const int N = 100005;
const int logg = 18;
const int P = 40000005;
const int M = 5e5+5;
int a[sz];
int dp[sz][sz][sz][sz], pref[sz][sz], cost[sz][sz][sz][sz], mat[sz][sz];
int n, m;
int COST(int x, int xx, int y, int yy)
{
if ( x ) pref[xx][yy] -= pref[x-1][yy];
if ( y ) pref[xx][yy] -= pref[xx][y-1];
if ( x and y ) pref[xx][yy] += pref[x-1][y-1];
return pref[xx][yy];
}
int wannabeDP(int x, int y, int xx, int yy)
{
if ( x == xx and xx == yy ) return 0;
if ( dp[x][xx][y][yy] != -1 ) return dp[x][xx][y][yy];
int res = 0x3f3f3f3f;
for(int i = x; i <= xx; i++)
res = min(res, wannabeDP(x, i, y, yy) + wannabeDP(i+1, xx, y, yy));
for(int i = y; i <= yy; i++)
res = min(res, wannabeDP(x, xx, y, i) + wannabeDP(x, xx, i+1, yy));
return dp[x][xx][y][yy] = res + cost[x][xx][y][yy];
}
void solve()
{
memset(dp, -1, sizeof(dp));
cin >> n >> m;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
cin >> mat[i][j];
for(int i = 0; i < n; i++)
{
int cur = 0;
for(int j = 0; j < m; j++)
{
cur += mat[i][j];
pref[i][j] = cur;
if ( i )
pref[i][j] += pref[i-1][j];
}
}
for(int i = 0; i < n; i++)
{
for(int j = i; j < n; j++)
{
for(int k = 0; k < m; k++)
{
for(int g = k; g < m; g++)
{
cost[i][j][k][g] = COST(i, j, k, g);
}
}
}
}
cout << wannabeDP(0, n - 1, 0, m - 1) << endl;
}
signed main()
{
ios;
//precompute();
int t = 1;
//cin >> t;
while(t--){
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |