Submission #1868492


Source Code Expand

import sys
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache, reduce
from operator import xor
INF = float("inf")
sys.setrecursionlimit(10**7)

# 4近傍(右, 下, 左, 上)
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]


def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    ans = 0
    d = {1: 0, 2: 0, 3: 0}
    for a in A:
        if a == 4:
            ans += 1
        elif a == 3:
            if d[1] > 0:
                d[1] -= 1
                ans += 1
            else:
                d[3] += 1
        elif a == 2:
            if d[2] > 0:
                d[2] -= 1
                ans += 1
            else:
                d[2] += 1
        elif a == 1:
            if d[3] > 0:
                d[3] -= 1
                ans += 1
            else:
                d[1] += 1
    ans += d[3]
    if d[2] > 0:
        d[1] = max(0, d[1] - 2)
        ans += 1
    ans += ceil(d[1], 4)
    print(ans)


if __name__ == '__main__':
    main()

Submission Info

Submission Time
Task C - スキーリフトの相乗り
User MitI_7
Language Python (3.4.3)
Score 400
Code Size 1422 Byte
Status AC
Exec Time 186 ms
Memory 4776 KB

Judge Result

Set Name All
Score / Max Score 400 / 400
Status
AC × 49
Set Name Test Cases
All 00_sample00, 00_sample01, 100_corner0000, 100_corner0001, 100_corner0002, 100_corner0003, 10_small-0000, 10_small-0001, 10_small-0002, 10_small-0003, 10_small-0004, 10_small-0005, 10_small-0006, 10_small-0007, 10_small-0008, 10_small-0009, 20_special-0000, 20_special-0001, 20_special-0002, 20_special-0003, 20_special-0004, 20_special-0005, 20_special-0006, 20_special-0007, 20_special-0008, 20_special-0009, 20_special-0010, 20_special-0011, 20_special-0012, 20_special-0013, 20_special-0014, 30_large-0000, 30_large-0001, 30_large-0002, 30_large-0003, 30_large-0004, 30_large-0005, 30_large-0006, 30_large-0007, 30_large-0008, 30_large-0009, 80_combination-type00, 80_combination-type01, 80_combination-type02, 80_combination-type03, 80_combination-type04, 80_combination-type05, 80_combination-type06, 90_tayama-killer00
Case Name Status Exec Time Memory
00_sample00 AC 26 ms 3944 KB
00_sample01 AC 26 ms 3952 KB
100_corner0000 AC 26 ms 3952 KB
100_corner0001 AC 26 ms 3944 KB
100_corner0002 AC 26 ms 3948 KB
100_corner0003 AC 26 ms 3948 KB
10_small-0000 AC 27 ms 3944 KB
10_small-0001 AC 26 ms 3948 KB
10_small-0002 AC 26 ms 3944 KB
10_small-0003 AC 26 ms 3952 KB
10_small-0004 AC 26 ms 3944 KB
10_small-0005 AC 26 ms 3952 KB
10_small-0006 AC 26 ms 3944 KB
10_small-0007 AC 26 ms 3952 KB
10_small-0008 AC 26 ms 3948 KB
10_small-0009 AC 26 ms 3944 KB
20_special-0000 AC 26 ms 3944 KB
20_special-0001 AC 28 ms 3952 KB
20_special-0002 AC 26 ms 3952 KB
20_special-0003 AC 26 ms 3948 KB
20_special-0004 AC 26 ms 3944 KB
20_special-0005 AC 26 ms 3948 KB
20_special-0006 AC 26 ms 3952 KB
20_special-0007 AC 26 ms 3952 KB
20_special-0008 AC 26 ms 3944 KB
20_special-0009 AC 26 ms 3944 KB
20_special-0010 AC 26 ms 3948 KB
20_special-0011 AC 26 ms 3952 KB
20_special-0012 AC 26 ms 3944 KB
20_special-0013 AC 26 ms 3948 KB
20_special-0014 AC 26 ms 3944 KB
30_large-0000 AC 184 ms 4776 KB
30_large-0001 AC 186 ms 4764 KB
30_large-0002 AC 184 ms 4772 KB
30_large-0003 AC 178 ms 4768 KB
30_large-0004 AC 186 ms 4764 KB
30_large-0005 AC 180 ms 4768 KB
30_large-0006 AC 180 ms 4764 KB
30_large-0007 AC 181 ms 4768 KB
30_large-0008 AC 180 ms 4764 KB
30_large-0009 AC 184 ms 4764 KB
80_combination-type00 AC 26 ms 3944 KB
80_combination-type01 AC 26 ms 3944 KB
80_combination-type02 AC 26 ms 3952 KB
80_combination-type03 AC 26 ms 3944 KB
80_combination-type04 AC 26 ms 3944 KB
80_combination-type05 AC 26 ms 3944 KB
80_combination-type06 AC 26 ms 3944 KB
90_tayama-killer00 AC 26 ms 3944 KB