Submission #36063085


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using ld = long double;
using pll = pair<ll, ll>;
// and so on
int arr[3001];
const int INF = 987654321;
int dp[3001][3001][2];
bool vis[3001][3001][2];
int N, M;
int sol(int x, int s, int m) {
    // given arr[x..N], make s
    if (x == N) {
        return s == 0 ? 0 : INF;
    } else if (s < 0)
        return INF;
    if (vis[x][s][m]) return dp[x][s][m];
    int ret = min({INF, sol(x + 1, s - (m ? 0 : arr[x]), m),
                   1 + sol(x + 1, s - (((!m) ? 0 : arr[x])), !m)});
    vis[x][s][m] = true;
    return dp[x][s][m] = ret;
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> N >> M;
    for (int i = 0; i < N; i++) {
        cin >> arr[i];
    }
    for (int i = 1; i <= M; i++) {
        int ans = sol(0, i, 0);
        cout << (ans == INF ? -1 : (ans+1)/2) << '\n';
    }
}

Submission Info

Submission Time
Task F - Erase Subarrays
User jame0313
Language C++ (GCC 9.2.1)
Score 500
Code Size 953 Byte
Status AC
Exec Time 710 ms
Memory 91896 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 38
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_oneone_00.txt, 01_oneone_01.txt, 02_srnd_00.txt, 02_srnd_01.txt, 02_srnd_02.txt, 02_srnd_03.txt, 02_srnd_04.txt, 02_srnd_05.txt, 02_srnd_06.txt, 02_srnd_07.txt, 03_rnd_00.txt, 03_rnd_01.txt, 03_rnd_02.txt, 03_rnd_03.txt, 03_rnd_04.txt, 03_rnd_05.txt, 03_rnd_06.txt, 03_rnd_07.txt, 04_gcd_00.txt, 04_gcd_01.txt, 04_gcd_02.txt, 04_gcd_03.txt, 05_max_00.txt, 05_max_01.txt, 05_max_02.txt, 06_two_00.txt, 06_two_01.txt, 06_two_02.txt, 06_two_03.txt, 06_two_04.txt, 06_two_05.txt, 07_pow_00.txt, 07_pow_01.txt, 07_pow_02.txt, 07_pow_03.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 8 ms 3536 KiB
00_sample_01.txt AC 2 ms 3592 KiB
00_sample_02.txt AC 2 ms 3624 KiB
01_oneone_00.txt AC 2 ms 3564 KiB
01_oneone_01.txt AC 2 ms 3464 KiB
02_srnd_00.txt AC 4 ms 3632 KiB
02_srnd_01.txt AC 2 ms 3732 KiB
02_srnd_02.txt AC 5 ms 3820 KiB
02_srnd_03.txt AC 9 ms 4040 KiB
02_srnd_04.txt AC 8 ms 4456 KiB
02_srnd_05.txt AC 13 ms 5464 KiB
02_srnd_06.txt AC 20 ms 7280 KiB
02_srnd_07.txt AC 40 ms 11036 KiB
03_rnd_00.txt AC 557 ms 91856 KiB
03_rnd_01.txt AC 560 ms 91800 KiB
03_rnd_02.txt AC 560 ms 91704 KiB
03_rnd_03.txt AC 552 ms 91712 KiB
03_rnd_04.txt AC 556 ms 91684 KiB
03_rnd_05.txt AC 556 ms 91612 KiB
03_rnd_06.txt AC 560 ms 91604 KiB
03_rnd_07.txt AC 554 ms 91580 KiB
04_gcd_00.txt AC 680 ms 91772 KiB
04_gcd_01.txt AC 706 ms 91836 KiB
04_gcd_02.txt AC 710 ms 91716 KiB
04_gcd_03.txt AC 705 ms 91616 KiB
05_max_00.txt AC 358 ms 91856 KiB
05_max_01.txt AC 359 ms 91800 KiB
05_max_02.txt AC 361 ms 91768 KiB
06_two_00.txt AC 411 ms 91852 KiB
06_two_01.txt AC 596 ms 91728 KiB
06_two_02.txt AC 573 ms 91832 KiB
06_two_03.txt AC 482 ms 91896 KiB
06_two_04.txt AC 581 ms 91796 KiB
06_two_05.txt AC 592 ms 91832 KiB
07_pow_00.txt AC 592 ms 91680 KiB
07_pow_01.txt AC 581 ms 91704 KiB
07_pow_02.txt AC 588 ms 91796 KiB
07_pow_03.txt AC 592 ms 91748 KiB