AtCoder Regular Contest 070

Submission #1352599

Source codeソースコード

#include <bits/stdc++.h>
using namespace std;

const int DIM = 5e3 + 5;

int arr[DIM], dp1[DIM][DIM], dp2[DIM][DIM];

int main( void ) {
    
    int n, k;
    cin >> n >> k;
    
    for( int i = 1; i <= n; i ++ )
        cin >> arr[i];
    
    dp1[0][0] = 1;
    for( int i = 1; i <= n; i ++ ) {
        for( int j = 0; j <= k; j ++ ) {
            dp1[i][j] = dp1[i - 1][j];
            
            if( j >= arr[i] )
                dp1[i][j] |= dp1[i - 1][j - arr[i]];
        }
    }
    
    dp2[n + 1][0] = 1;
    for( int i = n; i >= 1; i -- ) {
        for( int j = 0; j <= k; j ++ ) {
            dp2[i][j] = dp2[i + 1][j];
            
            if( j >= arr[i] )
                dp2[i][j] |= dp2[i + 1][j - arr[i]];
        }
    }
    
    int ans = n;
    for( int i = 1; i <= n; i ++ ) {
        for( int j = 1; j <= k; j ++ )
            dp2[i + 1][j] += dp2[i + 1][j - 1];
        
        for( int j = 0; j < k; j ++ ) {
            if( dp1[i - 1][j] == 0 )
                continue;
            
            int cnt = dp2[i + 1][k - j - 1];
            if( k - j - arr[i] >= 1 )
                cnt -= dp2[i + 1][k - j - arr[i] - 1];
            
            if( cnt != 0 ) {
                ans --;
                break;
            }
        }
    }
    
    cout << ans << endl;
    return 0;
}

Submission

Task問題 D - No Need
User nameユーザ名 EmanuelNrx
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 AC
Score得点 600
Source lengthソースコード長 1378 Byte
File nameファイル名
Exec time実行時間 196 ms
Memory usageメモリ使用量 195840 KB

Test case

Set

Set name Score得点 / Max score Cases
Sample - 0_000.txt,0_001.txt,0_002.txt
Subtask 300 / 300 0_000.txt,0_001.txt,0_002.txt,1_003.txt,1_004.txt,1_005.txt,1_006.txt,1_007.txt,1_008.txt,1_009.txt,1_010.txt,1_011.txt,1_012.txt,1_013.txt,1_014.txt,1_015.txt,1_016.txt,1_017.txt,1_018.txt,1_019.txt,1_020.txt,1_021.txt,1_022.txt,1_023.txt,1_024.txt,1_025.txt
All 300 / 300 0_000.txt,0_001.txt,0_002.txt,1_003.txt,1_004.txt,1_005.txt,1_006.txt,1_007.txt,1_008.txt,1_009.txt,1_010.txt,1_011.txt,1_012.txt,1_013.txt,1_014.txt,1_015.txt,1_016.txt,1_017.txt,1_018.txt,1_019.txt,1_020.txt,1_021.txt,1_022.txt,1_023.txt,1_024.txt,1_025.txt,2_026.txt,2_027.txt,2_028.txt,2_029.txt,2_030.txt,2_031.txt,2_032.txt,2_033.txt,2_034.txt,2_035.txt,2_036.txt,2_037.txt,2_038.txt,2_039.txt,2_040.txt,2_041.txt,2_042.txt,2_043.txt,2_044.txt,2_045.txt,2_046.txt,2_047.txt,2_048.txt,2_049.txt,2_050.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
0_000.txt AC 2 ms 2304 KB
0_001.txt AC 2 ms 2304 KB
0_002.txt AC 2 ms 2304 KB
1_003.txt AC 2 ms 2304 KB
1_004.txt AC 2 ms 2304 KB
1_005.txt AC 2 ms 2304 KB
1_006.txt AC 2 ms 2432 KB
1_007.txt AC 2 ms 2432 KB
1_008.txt AC 6 ms 17280 KB
1_009.txt AC 6 ms 17152 KB
1_010.txt AC 6 ms 17152 KB
1_011.txt AC 5 ms 17024 KB
1_012.txt AC 6 ms 17152 KB
1_013.txt AC 5 ms 17024 KB
1_014.txt AC 5 ms 17024 KB
1_015.txt AC 6 ms 17280 KB
1_016.txt AC 2 ms 2304 KB
1_017.txt AC 2 ms 2304 KB
1_018.txt AC 2 ms 2304 KB
1_019.txt AC 6 ms 17152 KB
1_020.txt AC 5 ms 17024 KB
1_021.txt AC 6 ms 17152 KB
1_022.txt AC 4 ms 8960 KB
1_023.txt AC 3 ms 8832 KB
1_024.txt AC 6 ms 17152 KB
1_025.txt AC 6 ms 17152 KB
2_026.txt AC 2 ms 2304 KB
2_027.txt AC 2 ms 2432 KB
2_028.txt AC 2 ms 2432 KB
2_029.txt AC 188 ms 195840 KB
2_030.txt AC 196 ms 195840 KB
2_031.txt AC 137 ms 195840 KB
2_032.txt AC 45 ms 193408 KB
2_033.txt AC 137 ms 195840 KB
2_034.txt AC 44 ms 193408 KB
2_035.txt AC 44 ms 193408 KB
2_036.txt AC 151 ms 195840 KB
2_037.txt AC 2 ms 2560 KB
2_038.txt AC 2 ms 2560 KB
2_039.txt AC 2 ms 2560 KB
2_040.txt AC 120 ms 195840 KB
2_041.txt AC 101 ms 195072 KB
2_042.txt AC 131 ms 195840 KB
2_043.txt AC 81 ms 125184 KB
2_044.txt AC 96 ms 169856 KB
2_045.txt AC 66 ms 161024 KB
2_046.txt AC 105 ms 194944 KB
2_047.txt AC 137 ms 195712 KB
2_048.txt AC 164 ms 195840 KB
2_049.txt AC 158 ms 195840 KB
2_050.txt AC 154 ms 195840 KB