-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
12e1c3b
commit 8d23faf
Showing
6 changed files
with
134 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
N = input() | ||
if sum(map(lambda x: int(x), N)) % 3: | ||
print(-1) | ||
exit() | ||
|
||
answer = list(sorted(N, reverse=True)) | ||
if answer[-1] == '0': | ||
print(*answer, sep='') | ||
else: | ||
print(-1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import sys | ||
def input(): return sys.stdin.readline().strip() | ||
|
||
M = int(input()) | ||
s = 0 | ||
for _ in range(M): | ||
query, *arr = input().split() | ||
arr = list(map(int, arr)) | ||
|
||
if query == "add": | ||
s = s | (1 << arr[0]) | ||
if query == "remove": | ||
s = s & ~(1 << arr[0]) | ||
if query == "check": | ||
print((s >> arr[0]) & 1) | ||
if query == "toggle": | ||
s = s ^ (1 << arr[0]) | ||
if query == "all": | ||
s = 0x1fffff | ||
if query == "empty": | ||
s = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from itertools import combinations | ||
import sys | ||
def input(): return sys.stdin.readline().strip() | ||
|
||
N, M = map(int, input().split()) | ||
for arr in combinations(range(1, N + 1), M): | ||
print(*arr) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import sys | ||
def input(): return sys.stdin.readline().strip() | ||
|
||
def index(ch): return ord(ch) - ord('A') | ||
|
||
T = int(input()) | ||
M = int(input()) | ||
data = [[0] * 4 for _ in range(4)] | ||
for _ in range(M): | ||
a, b, p = input().split() | ||
data[index(a)][index(b)] = float(p) | ||
|
||
answer = [25] * 4 | ||
for _ in range(T): | ||
next_answer = [0] * 4 | ||
for i in range(4): | ||
for j in range(4): | ||
next_answer[i] += answer[j] * data[j][i] | ||
answer = next_answer | ||
for i in range(4): | ||
print(f"{answer[i]:.2f}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from collections import deque | ||
import sys | ||
def input(): return sys.stdin.readline().strip() | ||
|
||
darr = [(1, 0), (-1, 0), (0, 1), (0, -1)] | ||
|
||
M, N, K = map(int, input().split()) | ||
data = [list(map(int, input().split())) for _ in range(K)] | ||
board = [[False] * N for _ in range(M)] | ||
|
||
for x1, y1, x2, y2 in data: | ||
for x in range(x1, x2): | ||
for y in range(y1, y2): | ||
board[y][x] = True | ||
|
||
answer = [] | ||
for i in range(N * M): | ||
sy, sx = divmod(i, N) | ||
if board[sy][sx] == True: | ||
continue | ||
|
||
queue = deque([(sx, sy)]) | ||
board[sy][sx] = True | ||
cnt = 1 | ||
while queue: | ||
x, y = queue.popleft() | ||
for dx, dy in darr: | ||
nx, ny = x + dx, y + dy | ||
|
||
if not 0 <= nx < N or not 0 <= ny < M: | ||
continue | ||
if board[ny][nx]: | ||
continue | ||
|
||
board[ny][nx] = True | ||
cnt += 1 | ||
queue.append((nx, ny)) | ||
answer.append(cnt) | ||
|
||
print(len(answer)) | ||
print(*sorted(answer)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from collections import deque | ||
import sys | ||
def input(): return sys.stdin.readline().strip() | ||
|
||
darr = [(0, 1), (0, -1), (1, 0), (-1, 0)] | ||
|
||
N = int(input()) | ||
data = [list(input()) for _ in range(N)] | ||
|
||
answer = [] | ||
for i in range(N ** 2): | ||
sy, sx = divmod(i, N) | ||
if data[sy][sx] =='0': | ||
continue | ||
|
||
result = 0 | ||
queue = deque([(sx, sy)]) | ||
data[sy][sx] = '0' | ||
while queue: | ||
x, y = queue.popleft() | ||
result += 1 | ||
|
||
for dx, dy in darr: | ||
nx, ny = x + dx, y + dy | ||
if not 0 <= nx < N or not 0 <= ny < N: | ||
continue | ||
if data[ny][nx] == '0': | ||
continue | ||
data[ny][nx] = '0' | ||
queue.append((nx, ny)) | ||
answer.append(result) | ||
print(len(answer)) | ||
answer.sort() | ||
print(*answer, sep='\n') |