AtCoder Regular Contest 070

Submission #1354282

Source codeソースコード

n, k = map(int, raw_input().split())
a = map(int, raw_input().split())

dpl = [[0] * (k + 1) for _ in xrange(n)]
dpr = [[0] * (k + 1) for _ in xrange(n)]
for i in xrange(n):
    dpl[i][0] = 1
    dpr[i][0] = 1
dpl[0][min(k, a[0])] = 1
dpr[n - 1][min(k, a[n - 1])] = 1

for i in xrange(1, n):
    if a[i] > k:
        dpl[i][k] = 1
    for j in xrange(k + 1):
        if j - a[i] < 0:
            dpl[i][j] = min(1, dpl[i][j] + dpl[i - 1][j])
        else:
            dpl[i][j] = min(1, dpl[i - 1][j] + dpl[i - 1][j - a[i]])
for i in xrange(n):
    for j in xrange(k):
        dpl[i][j + 1] += dpl[i][j]

for i in xrange(n - 2, -1, -1):
    if a[i] > k:
        dpr[i][k] = 1
    for j in xrange(k + 1):
        if j - a[i] < 0:
            dpr[i][j] = min(1, dpr[i][j] + dpr[i + 1][j])
        else:
            dpr[i][j] = min(1, dpr[i + 1][j] + dpr[i + 1][j - a[i]])
for i in xrange(n - 1, -1, -1):
    for j in xrange(k):
        dpr[i][j + 1] += dpr[i][j]

ans = 0
for i in xrange(1, n - 1):
    ok = False
    if a[i] >= k: continue
    for j in xrange(k):
        if (j != 0) and (dpl[i - 1][j]  - dpl[i - 1][j - 1] == 0): continue
        lnum = j
        if lnum + a[i] >=k:
            ok=True
            break
        if dpr[i + 1][k - lnum -1] - dpr[i + 1][k - 1 - a[i] - lnum] > 0:
            ok =True
            break
    if ok: continue
    ans += 1
if a[0] < k:
    if dpr[1][k - 1] - dpr[1][k - a[0] - 1] == 0:
        ans += 1
if a[n - 1] < k:
    if dpl[n - 2][k - 1] - dpl[n - 2][k - a[n - 1] - 1] == 0:
        ans += 1
print ans

Submission

Task問題 D - No Need
User nameユーザ名 roto_37
Created time投稿日時
Language言語 PyPy2 (5.6.0)
Status状態 MLE
Score得点 300
Source lengthソースコード長 1611 Byte
File nameファイル名
Exec time実行時間 ms
Memory usageメモリ使用量 -

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 0 / 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 36 ms 29164 KB
0_001.txt AC 50 ms 32748 KB
0_002.txt AC 35 ms 28524 KB
1_003.txt AC 34 ms 29036 KB
1_004.txt AC 34 ms 28396 KB
1_005.txt AC 35 ms 28908 KB
1_006.txt AC 59 ms 32620 KB
1_007.txt AC 55 ms 32492 KB
1_008.txt AC 79 ms 35308 KB
1_009.txt AC 84 ms 35436 KB
1_010.txt AC 64 ms 35308 KB
1_011.txt AC 39 ms 28780 KB
1_012.txt AC 65 ms 35180 KB
1_013.txt AC 39 ms 29420 KB
1_014.txt AC 39 ms 29676 KB
1_015.txt AC 85 ms 35308 KB
1_016.txt AC 56 ms 32492 KB
1_017.txt AC 53 ms 32492 KB
1_018.txt AC 56 ms 32620 KB
1_019.txt AC 81 ms 34284 KB
1_020.txt AC 58 ms 32492 KB
1_021.txt AC 81 ms 34156 KB
1_022.txt AC 68 ms 33004 KB
1_023.txt AC 56 ms 32620 KB
1_024.txt AC 91 ms 34540 KB
1_025.txt AC 90 ms 34668 KB
2_026.txt AC 38 ms 30700 KB
2_027.txt AC 67 ms 33004 KB
2_028.txt AC 66 ms 33004 KB
2_029.txt MLE
2_030.txt MLE
2_031.txt MLE
2_032.txt AC 68 ms 33644 KB
2_033.txt MLE
2_034.txt AC 69 ms 33180 KB
2_035.txt AC 69 ms 33180 KB
2_036.txt MLE
2_037.txt AC 74 ms 33644 KB
2_038.txt AC 75 ms 33644 KB
2_039.txt AC 78 ms 33772 KB
2_040.txt MLE
2_041.txt MLE
2_042.txt MLE
2_043.txt AC 1010 ms 224156 KB
2_044.txt MLE
2_045.txt AC 596 ms 138268 KB
2_046.txt MLE
2_047.txt MLE
2_048.txt MLE
2_049.txt MLE
2_050.txt MLE