Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0b46201

Browse files
committed
Today ps
1 parent 9f9d6e2 commit 0b46201

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

‎Baekjoon/Python/15683.py‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import sys
2+
import copy
3+
input = sys.stdin.readline
4+
5+
DX = [0, 1, 0, -1]
6+
DY = [-1, 0, 1, 0]
7+
MOVE = [
8+
[[0], [1], [2], [3]],
9+
[[0, 2], [1, 3]],
10+
[[0, 1], [1, 2], [2, 3], [3, 0]],
11+
[[0, 1, 2], [1, 2, 3], [2, 3, 0], [3, 0, 1]],
12+
[[0, 1, 2, 3]],
13+
]
14+
15+
n, m = map(int, input().split())
16+
arr = []
17+
cctv = []
18+
answer = n * m + 1
19+
for y in range(n):
20+
sub_arr = list(map(int, input().split()))
21+
arr.append(sub_arr)
22+
for x in range(m):
23+
if arr[y][x] not in [0, 6]:
24+
cctv.append((y, x))
25+
26+
def watch(dir, y, x):
27+
if not (x >= 0 and x < m and y >= 0 and y < n) or arr[y][x] == 6:
28+
return
29+
elif arr[y][x] == 0:
30+
arr[y][x] = 7
31+
watch(dir, y + DY[dir], x + DX[dir])
32+
33+
def get_score():
34+
score = 0
35+
for y in range(n):
36+
for x in range(m):
37+
score += int(arr[y][x] == 0)
38+
return score
39+
40+
def decide(idx):
41+
if idx == len(cctv):
42+
global answer
43+
answer = min(answer, get_score())
44+
return
45+
y, x = cctv[idx]
46+
global arr
47+
id = arr[y][x] - 1
48+
for dirs in MOVE[id]:
49+
capture = copy.deepcopy(arr)
50+
for dir in dirs:
51+
watch(dir, y, x)
52+
decide(idx + 1)
53+
arr = capture
54+
55+
decide(0)
56+
print(answer)

‎Baekjoon/Python/2109.py‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import sys
2+
input = sys.stdin.readline
3+
4+
que = []
5+
last = 0
6+
score = 0
7+
arr = [[] for _ in range(10000)]
8+
n = int(input())
9+
for _ in range(n):
10+
w, d = map(int, input().split())
11+
arr[d - 1].append(w)
12+
last = max(last, d)
13+
for d in range(last - 1, -1, -1):
14+
for w in arr[d]:
15+
que.append(w)
16+
if len(arr[d]) > 0:
17+
que.sort()
18+
if len(que) > 0:
19+
score += que.pop()
20+
print(score)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /