Submission #879523

# Submission time Handle Problem Language Result Execution time Memory
879523 2023-11-27T15:22:27 Z amin_2008 Raisins (IOI09_raisins) C++17
10 / 100
271 ms 84244 KB
#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 = 50;
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], memo[sz][sz][sz][sz];
int pref[sz+1][sz+1];

int get(int a, int b, int c, int d)
{
    a++;
    b++;
    c++;
    d++;
    return pref[c][d] - pref[c][b-1] - pref[a-1][d] - pref[a-1][b-1];
}

void wannabeDP(int a, int b, int c, int d)
{
    if ( memo[a][b][c][d] )     return;
    memo[a][b][c][d] = 1;
    for(int i = a; i < c; i++)
        wannabeDP(a, b, i, d),
        wannabeDP(i+1, b, c, d),
        dp[a][b][c][d] = min(dp[a][b][c][d], dp[a][b][i][d] + dp[i+1][b][c][d]);
    for(int i = b; i < d; i++)
        wannabeDP(a, b, c, i),
        wannabeDP(a, i+1, c, d),
        dp[a][b][c][d] = min(dp[a][b][c][d], dp[a][b][c][i] + dp[a][i+1][c][d]);
    dp[a][b][c][d] += get(a, b, c, d);
}

void solve()
{
    int n, m;
    cin >> n >> m;
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < m; j++)
        {
            for(int k = 0; k < n; k++)
            {
                for(int t = 0; t < m; t++)
                {
                    dp[i][j][k][t] = 1e15;
                }
            }
        }
    }
    for(int i = 0; i < n; i++)
        for(int j = 0; j < m; j++)
            dp[i][j][i][j] = 0;
    for(int i = 0; i < n; i++)
        for(int j = 0; j < m; j++)
            memo[i][j][i][j] = 1;
    for(int i = 0; i < n; i++)
        for(int j = 0, x; j < m; j++)
            cin >> x,
            pref[i+1][j+1] = pref[i+1][j] + pref[i][j+1] - pref[i][j] + x;
    wannabeDP(0, 0, n - 1, m - 1);
    cout << dp[0][0][n-1][m-1] << endl;
}

signed main()
{
    ios;
    //precompute();
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Incorrect 1 ms 10588 KB Output isn't correct
4 Incorrect 1 ms 6620 KB Output isn't correct
5 Incorrect 2 ms 14684 KB Output isn't correct
6 Incorrect 3 ms 22876 KB Output isn't correct
7 Incorrect 4 ms 31276 KB Output isn't correct
8 Incorrect 9 ms 39512 KB Output isn't correct
9 Incorrect 11 ms 49756 KB Output isn't correct
10 Incorrect 12 ms 51804 KB Output isn't correct
11 Incorrect 10 ms 43616 KB Output isn't correct
12 Incorrect 25 ms 58972 KB Output isn't correct
13 Incorrect 40 ms 58460 KB Output isn't correct
14 Incorrect 13 ms 43608 KB Output isn't correct
15 Incorrect 49 ms 60504 KB Output isn't correct
16 Incorrect 10 ms 57944 KB Output isn't correct
17 Incorrect 24 ms 61704 KB Output isn't correct
18 Incorrect 144 ms 75348 KB Output isn't correct
19 Incorrect 247 ms 80516 KB Output isn't correct
20 Incorrect 271 ms 84244 KB Output isn't correct