https://www.acmicpc.net/problem/23291

 

23291번: 어항 정리

마법사 상어는 그동안 배운 마법을 이용해 어항을 정리하려고 한다. 어항은 정육면체 모양이고, 한 변의 길이는 모두 1이다. 상어가 가지고 있는 어항은 N개이고, 가장 처음에 어항은 일렬로 바

www.acmicpc.net

내가 볼려고 쓰는글 가독성 0

 </p

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import sys
from collections import deque
N, K = map(int, input().split())
fish_input = list(map(int, input().split()))
fishbowl = deque([deque([fish_input[i]]) for i in range(N)])
 
def push_least_fish():
    min_value = min(fishbowl)[0]
    for index in range(N):
        if min_value == fishbowl[index][0]:
            fishbowl[index][0+= 1
 
def left_fishbowl_push():
    fishbowl[1].extend(fishbowl[0])
    fishbowl[0].pop()
 
def fly_upper2():
    while True:
        left_pop_count = 0
        fly_count = 0
        stack_len = 0
        for i in range(len(fishbowl)):
            if len(fishbowl[i]) == 0:
                left_pop_count += 1
            elif len(fishbowl[i]) >= 2:
                stack_len = max(len(fishbowl[i]),stack_len)
                fly_count += 1
        fly = deque()
        for _ in range(left_pop_count):
            fishbowl.popleft()
        if stack_len > len(fishbowl) - fly_count:
            break
        for _ in range(fly_count):
            fly.append(fishbowl.popleft())
        while len(fly) != 0:
            pop_value = fly.pop()
            for _, value in enumerate(pop_value):
                fishbowl[_].append(value)
 
def fish_split():
    dx = [0,1,0,-1]
    dy = [1,0,-1,0]
    new_fish_bowl = deque()
    make_map = [[0 for i in range(len(fishbowl[0]))] for j in range(len(fishbowl))]
 
    for i in range(len(fishbowl)):
        for j in range(len(fishbowl[i])):
            make_map[i][j] = fishbowl[i][j]
    value_info = []
    # print(fishbowl)
    for i in range(len(fishbowl)):
        for j in range(len(fishbowl[i])):
            total_count = 0
            for dx_,dy_ in zip(dx,dy):
                new_x = i + dx_
                new_y = j + dy_
                if new_x >= 0 and new_y >= 0 and new_x < len(fishbowl) and new_y < len(fishbowl[0]) and make_map[new_x][new_y] != 0:
                    minus = abs(make_map[new_x][new_y] - make_map[i][j])
                    # print(i,j,new_x,new_y)
                    # print(make_map[i][j],minus,minus // 5)
                    if make_map[new_x][new_y] > make_map[i][j]:
                        total_count += minus // 5
                    else:
                        total_count -= minus // 5
            value_info.append(total_count)
    index = 0
    for i in range(len(fishbowl)):
        for j in range(len(fishbowl[i])):
            fishbowl[i][j] += value_info[index]
            index += 1
 
def make_line():
    global fishbowl
    new_fish_bowl = deque()
    for index in range(len(fishbowl)):
        for _ in fishbowl[index]:
            dq = deque()
            dq.append(_)
            new_fish_bowl.append(dq)
    fishbowl = new_fish_bowl
 
def repeat_upper():
    number = N
    number = number // 2
    for i in range(number):
        fishbowl[-1 - i].append(fishbowl.popleft()[0])
    number = number // 2
    for i in range(number):
        value = fishbowl.popleft()
        fishbowl[-1 - i].append(value[1])
        fishbowl[-1 - i].append(value[0])
 
answer = 0
while True:
    answer += 1
    push_least_fish()
    left_fishbowl_push()
    fly_upper2()
    fish_split()
    make_line()
    repeat_upper()
    fish_split()
    make_line()
    if max(fishbowl)[0- min(fishbowl)[0<= K:
        print(answer)
        break
cs

+ Recent posts