-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #139 from wooseokCho/kiiiiv
.
- Loading branch information
Showing
12 changed files
with
279 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,19 @@ | ||
n,m = list(map(int, input().split(' '))) | ||
array = list(map(int, input().split())) | ||
|
||
start = 0 | ||
end = max(array) | ||
|
||
result = 0 | ||
while (start< end): | ||
total = 0 | ||
mid = (start+end)//2 | ||
for x in array: | ||
if x > mid: | ||
total += x - mid | ||
if total <m: | ||
end = mid-1 | ||
else: | ||
result = mid | ||
start = mid+1 | ||
print(result) |
Empty file.
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,18 @@ | ||
n, m =list(map(int, input().split(' '))) | ||
array = list(map(int, input().split())) | ||
|
||
start = 0 | ||
end=max(array) | ||
result = 0 | ||
while(start<=end): | ||
total = 0 | ||
mid = (start+end) //2 | ||
for x in array: | ||
if x >mid: | ||
total+=x-mid | ||
if total < m: | ||
end = mid -1 | ||
else: | ||
result = mid | ||
start = mid+1 | ||
print(result) |
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,35 @@ | ||
import sys | ||
from collections import deque | ||
input = sys.stdin.readline | ||
|
||
n = int(input()) | ||
for i in range(n): | ||
a = input().strip() | ||
m = int(input()) | ||
flag = 1 | ||
arr = input().strip() | ||
dq = deque(arr[1:-1].split(",")) | ||
if m == 0: | ||
dq = deque() | ||
rev_count = 0 | ||
for i in range(len(a)): | ||
if a[i] == "R": | ||
rev_count+=1 | ||
elif a[i] == "D": | ||
if len(dq) == 0: | ||
print("error") | ||
flag = 0 | ||
break | ||
else: | ||
if rev_count%2 == 0: | ||
dq.popleft() | ||
else: | ||
dq.pop() | ||
if flag == 0: #에러가 난 경우 다음으로 | ||
continue | ||
else: | ||
if rev_count%2 == 0: | ||
print("["+",".join(dq)+"]") | ||
else: | ||
dq.reverse() | ||
print("["+",".join(dq)+"]") |
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,37 @@ | ||
import sys | ||
from collections import deque | ||
input = sys.stdin.readline | ||
|
||
n = int(input()) | ||
for i in range(n): | ||
func = input().strip() | ||
m = int(input()) | ||
flag = 1 | ||
arr = input().strip() | ||
dq = deque(arr[1:-1].split(",")) | ||
if m == 0: | ||
dq = deque() | ||
rev_count = 0 #true | ||
|
||
for i in range(len(func)): | ||
if func[i] == "R": | ||
rev_count +=1 | ||
elif func[i] == "D": | ||
if len(dq) == 0: | ||
print("error") | ||
flag = 0 | ||
break | ||
|
||
if rev_count%2 == 0: | ||
dq.popleft() | ||
else: | ||
dq.pop() | ||
if flag == 0: | ||
continue | ||
else: | ||
if rev_count%2 == 0: | ||
print("[" + ",".join(dq) + "]") | ||
else: | ||
dq.reverse() | ||
print("[" + ",".join(dq) + "]") | ||
|
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,35 @@ | ||
import sys | ||
from collections import deque | ||
input = sys.stdin.readline | ||
n = int(input()) | ||
for i in range(n): | ||
a = input().strip() | ||
m = int(input()) | ||
flag = 1 | ||
arr = input.strip() | ||
dq = deque[arr[1:-1].split(",")] | ||
if m ==0: | ||
dq = deque() | ||
R = 0 #reverse하는 횟수 | ||
for i in range(len(a)): | ||
if a[i] == "R": | ||
R+=1 | ||
elif a[i] == "D": | ||
if len(dq) == 0: | ||
print("error") | ||
flag = 0 | ||
break | ||
else: | ||
if R%2 == 0: | ||
dq.popleft() | ||
else: | ||
dq.pop | ||
if flag == 0: | ||
continue | ||
else: | ||
if R%2 == 0: | ||
print("["+",".join(dq)+"]") | ||
|
||
else: | ||
dq.reverse() | ||
print("["+",".join(dq)+"]") |
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,16 @@ | ||
n = int(input()) | ||
m = int(input()) | ||
s = input() | ||
|
||
cursor, count, result = 0,0,0 | ||
while cursor < (m-1): | ||
if s[cursor:cursor+3] == "IOI": | ||
count+=1 | ||
cursor+=2 | ||
if count == n: | ||
result+=1 | ||
count-=1 | ||
else: | ||
cursor+=1 | ||
count = 0 | ||
print(result) |
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,15 @@ | ||
n = int(input()) | ||
m = int(input()) | ||
s=input() | ||
cursor, count, result = 0,0,0 | ||
while cursor <(m-1): | ||
if s[cursor:cursor+3] == "IOI": | ||
cursor+=2 | ||
count+=1 | ||
if count == n: | ||
result+=1 | ||
count-=1 | ||
else: | ||
count = 0 | ||
cursor+=1 | ||
print(result) |
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,16 @@ | ||
n = int(input()) #IOI만들어주는 개수 | ||
m = int(input()) | ||
s = input() | ||
cursor, count, result = 0,0,0 | ||
while cursor < (m-1): | ||
if s[cursor:cursor+3] == "IOI": | ||
count+=1 | ||
cursor+=2 | ||
if count == n: | ||
result+=1 | ||
count-=1 | ||
else: #"IOI"가 아니면 | ||
cursor+=1 | ||
count = 0 | ||
print(result) | ||
|
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,12 @@ | ||
import sys | ||
def calculate(m,n,x,y): | ||
k = x | ||
while k<= m*n: | ||
if (k-x)%m == 0 and (k-y)%n == 0: | ||
return k | ||
k+=m | ||
return -1 | ||
t = int(input()) | ||
for _ in range(t): | ||
m,n,x,y = map(int, sys.stdin.readline().split()) | ||
print(calculate(m,n,x,y)) |
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,29 @@ | ||
import sys | ||
input = sys.stdin.readline | ||
def gcd(a,b): | ||
while b!=0: | ||
a,b =b, a%b | ||
return a | ||
def lcm(a,b): | ||
return a*b // gcd(a,b) | ||
t= int(input()) | ||
for _ in range(t): | ||
m,n,x,y = map(int, input().split(' ')) | ||
lcm_val = lcm(m,n) | ||
count = 0 | ||
lcm_m = int(lcm_val/m) | ||
lcm_n = int(lcm_val/n) #5 | ||
i,j = 0,0 | ||
while (i < lcm_m and j < lcm_n): | ||
val_a = m*i+x | ||
val_b = n*j+y | ||
if val_a > val_b: | ||
j+=1 | ||
elif val_a < val_b: | ||
i+=1 | ||
elif val_a == val_b: | ||
print(val_a) | ||
count+=1 | ||
break | ||
if count == 0: | ||
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,47 @@ | ||
import sys | ||
from collections import deque | ||
input = sys.stdin.readline | ||
m,n,h = map(int, input().split()) | ||
matrix = [[list(map(int, input().split())) for _ in range(n)] for _ in range(h)] | ||
|
||
#상,하,좌,우,아래, 위 | ||
dx = [-1,1,0,0,0,0] | ||
dy = [0,0,-1,1,0,0] | ||
dz = [0,0,0,0,-1,1] | ||
queue = deque() | ||
|
||
def bfs(): | ||
while queue: | ||
z, x, y = queue.popleft() | ||
|
||
for i in range(6): | ||
nx = x+dx[i] | ||
ny = y+dy[i] | ||
nz = z+dz[i] | ||
if 0<=nx<n and 0<=ny<m and 0<=nz<h: | ||
if matrix[nz][nx][ny] == 0: | ||
queue.append((nz, nx, ny)) | ||
matrix[nz][nx][ny] = matrix[z][x][y]+1 | ||
|
||
for a in range(h): | ||
for b in range(n): | ||
for c in range(m): | ||
if matrix[a][b][c] ==1: | ||
queue.append((a,b,c)) | ||
bfs() | ||
|
||
not_complete = False | ||
day = 0 | ||
for i in range(h): | ||
for j in range(n): | ||
for k in range(m): | ||
if matrix[i][j][k] == 0: | ||
not_complete = True | ||
day = max(day, matrix[i][j][k]) | ||
if not_complete: | ||
print(-1) | ||
else: | ||
print(day-1) | ||
|
||
|
||
|