답안 #879498

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
879498 2023-11-27T14:48:32 Z amin_2008 건포도 (IOI09_raisins) C++17
0 / 100
45 ms 131072 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 = 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();
    }
}

# 결과 실행 시간 메모리 Grader output
1 Runtime error 41 ms 131072 KB Execution killed with signal 9
2 Runtime error 20 ms 131072 KB Execution killed with signal 9
3 Runtime error 21 ms 131072 KB Execution killed with signal 9
4 Runtime error 20 ms 131072 KB Execution killed with signal 9
5 Runtime error 21 ms 131072 KB Execution killed with signal 9
6 Runtime error 22 ms 131072 KB Execution killed with signal 9
7 Runtime error 22 ms 131072 KB Execution killed with signal 9
8 Runtime error 20 ms 131072 KB Execution killed with signal 9
9 Runtime error 19 ms 131072 KB Execution killed with signal 9
10 Runtime error 21 ms 131072 KB Execution killed with signal 9
11 Runtime error 20 ms 131072 KB Execution killed with signal 9
12 Runtime error 18 ms 131072 KB Execution killed with signal 9
13 Runtime error 21 ms 131072 KB Execution killed with signal 9
14 Runtime error 20 ms 131072 KB Execution killed with signal 9
15 Runtime error 19 ms 131072 KB Execution killed with signal 9
16 Runtime error 20 ms 131072 KB Execution killed with signal 9
17 Runtime error 45 ms 131072 KB Execution killed with signal 9
18 Runtime error 45 ms 131072 KB Execution killed with signal 9
19 Runtime error 21 ms 131072 KB Execution killed with signal 9
20 Runtime error 44 ms 131072 KB Execution killed with signal 9