-
Notifications
You must be signed in to change notification settings - Fork 2
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
Showing
15 changed files
with
374 additions
and
1 deletion.
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
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,43 @@ | ||
#include <iostream> | ||
#include <stack> | ||
|
||
using namespace std; | ||
|
||
int main() { | ||
ios_base::sync_with_stdio(false); | ||
cin.tie(nullptr); | ||
|
||
int D, N; | ||
cin >> D >> N; | ||
|
||
stack<int> minOvens; | ||
int mn = 1087654321; | ||
|
||
while (D--) { | ||
int oven; | ||
cin >> oven; | ||
|
||
mn = min(mn, oven); | ||
minOvens.emplace(mn); | ||
} | ||
|
||
while (N--) { | ||
int pizza; | ||
cin >> pizza; | ||
|
||
while (!minOvens.empty() && minOvens.top() < pizza) { | ||
minOvens.pop(); | ||
} | ||
|
||
if (!minOvens.empty()) { | ||
minOvens.pop(); | ||
} else { | ||
cout << '0'; | ||
return 0; | ||
} | ||
} | ||
|
||
cout << minOvens.size() + 1; | ||
|
||
return 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,39 @@ | ||
#include <iostream> | ||
#include <unordered_set> | ||
|
||
using namespace std; | ||
|
||
int main() { | ||
ios_base::sync_with_stdio(false); | ||
cin.tie(nullptr); | ||
|
||
string s; | ||
cin >> s; | ||
|
||
if (unordered_set<char>(s.begin(), s.end()).size() == 1) { | ||
cout << "-1"; | ||
return 0; | ||
} | ||
|
||
auto isPalindrome = [](string &s) { | ||
int lo = 0; | ||
int hi = s.size() - 1; // NOLINT | ||
|
||
while (lo < hi) { | ||
if (s[lo] != s[hi]) return false; | ||
lo++; | ||
hi--; | ||
} | ||
|
||
return true; | ||
}; | ||
|
||
if (!isPalindrome(s)) { | ||
cout << s.size(); | ||
return 0; | ||
} | ||
|
||
cout << s.size() - 1; | ||
|
||
return 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,71 @@ | ||
from math import prod | ||
from collections import deque | ||
|
||
stdin = open(0) | ||
sizes = list(map(int, stdin.readline().split())) | ||
totalSize = prod(sizes) | ||
board = [] | ||
unripe = 0 | ||
index = 0 | ||
deq = deque() | ||
|
||
for line in stdin.read().splitlines(): | ||
for num in map(int, line.split()): | ||
board.append(num) | ||
|
||
if num == 0: | ||
unripe += 1 | ||
|
||
if num == 1: | ||
deq.append(index) | ||
|
||
index += 1 | ||
|
||
if unripe == 0: | ||
print('0') | ||
exit() | ||
|
||
def extract(x): | ||
answer = [0] * 11 | ||
divisor = totalSize | ||
|
||
for i in range(10, -1, -1): | ||
divisor //= sizes[i] | ||
answer[i] = x // divisor | ||
x %= divisor | ||
|
||
return answer | ||
|
||
def compress(ls): | ||
answer = 0 | ||
coefficient = 1 | ||
|
||
for i in range(0, 11): | ||
answer += ls[i] * coefficient | ||
coefficient *= sizes[i] | ||
|
||
return answer | ||
|
||
while deq: | ||
cur = deq.popleft() | ||
positions = extract(cur) | ||
|
||
for i in range(0, 11): | ||
for offset in (-1, 1): | ||
positions[i] += offset | ||
|
||
if 0 <= positions[i] < sizes[i]: | ||
next = compress(positions) | ||
|
||
if board[next] == 0: | ||
board[next] = board[cur] + 1 | ||
unripe -= 1 | ||
deq.append(next) | ||
|
||
positions[i] -= offset | ||
|
||
if unripe == 0: | ||
print(board[cur]) | ||
exit() | ||
|
||
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,22 @@ | ||
from itertools import permutations | ||
|
||
stdin = open(0) | ||
|
||
L, N = map(int, stdin.readline().split()) | ||
words = sorted(stdin.read().splitlines()) | ||
|
||
# ๋จ์ด ์์ด x๊ฐ ๋จ์ด ๋ง๋ฐฉ์ง์ธ์ง ํ์ธํ๋ ํจ์ | ||
def isValid(x): | ||
for i in range(L): | ||
for j in range(L): | ||
if x[i][j] != x[j][i]: return False | ||
|
||
return True | ||
|
||
for perm in permutations(words, L): | ||
if not isValid(perm): continue | ||
|
||
print(*perm, sep='\n') | ||
exit() | ||
|
||
print('NONE') |
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,31 @@ | ||
from sys import * | ||
from collections import * | ||
|
||
n, k = map(int, stdin.readline().strip().split()) | ||
|
||
max_idx = 100001 | ||
|
||
q = deque([(n, 0)]) | ||
visited = [False] * max_idx | ||
visited[n] = True | ||
|
||
while q: | ||
x, cost = q.popleft() | ||
if x == k: | ||
print(cost) | ||
break | ||
|
||
nx = x + x | ||
if nx < max_idx and not visited[nx]: | ||
visited[nx] = True | ||
q.appendleft((nx, cost)) | ||
|
||
nx = x - 1 | ||
if 0 <= nx and not visited[nx]: | ||
visited[nx] = True | ||
q.append((nx, cost + 1)) | ||
|
||
nx = x + 1 | ||
if nx < max_idx and not visited[nx]: | ||
visited[nx] = True | ||
q.append((nx, cost + 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
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 @@ | ||
from collections import Counter | ||
|
||
number, exchange_count = map(int,input().split()) | ||
|
||
number = list(str(number)) | ||
answer = "0" | ||
|
||
counter = Counter(number) | ||
same_number_flag = False | ||
|
||
for key, value in counter.items(): | ||
if value >=2: | ||
same_number_flag = True | ||
break | ||
|
||
def dfs(number, depth, remain_exchange_count, same_number_flag): | ||
global answer | ||
|
||
if remain_exchange_count == 0: | ||
answer = max(answer, "".join(number)) | ||
return | ||
|
||
flag = False | ||
for prev_idx in range(depth,len(number)): | ||
for next_idx in range(prev_idx+1, len(number)): | ||
if number[next_idx] >= number[prev_idx]: | ||
number[next_idx], number[prev_idx] = number[prev_idx], number[next_idx] | ||
dfs(number, depth+1, remain_exchange_count-1, same_number_flag) | ||
number[next_idx], number[prev_idx] = number[prev_idx], number[next_idx] | ||
flag = True | ||
|
||
if flag == False: | ||
if same_number_flag: dfs(number, depth+1, remain_exchange_count-1, same_number_flag) | ||
else: | ||
number[-1], number[-2] = number[-2], number[-1] | ||
dfs(number, depth+1, remain_exchange_count-1, same_number_flag) | ||
number[-1], number[-2] = number[-2], number[-1] | ||
|
||
if len(number) == 1 and exchange_count >= 1: | ||
print("-1") | ||
|
||
elif len(number) == 2 and "0" in number: | ||
print("-1") | ||
|
||
else: | ||
dfs(number,0, exchange_count, same_number_flag) | ||
print(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,16 @@ | ||
total_app_count, need_memory = map(int,input().split()) | ||
|
||
use_memory = list(map(int,input().split())) | ||
re_use_cost = list(map(int,input().split())) | ||
|
||
dp_table = [0 for _ in range(sum(re_use_cost)+1)] | ||
cost_sum = sum(re_use_cost) | ||
|
||
for memory, cost in zip(use_memory, re_use_cost): | ||
for idx in range(cost_sum,cost-1,-1): | ||
dp_table[idx] = max(dp_table[idx], dp_table[idx-cost] + memory) | ||
|
||
for idx, memory in enumerate(dp_table): | ||
if memory >= need_memory: | ||
print(idx) | ||
break |
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,30 @@ | ||
import sys | ||
|
||
remain_days, need_score = map(int,sys.stdin.readline().split()) | ||
volunteer_scores = [0] | ||
volunteer_scores.extend(list(map(int,sys.stdin.readline().split()))) | ||
|
||
blood_donation_score, blood_donation_break_time = map(int,sys.stdin.readline().split()) | ||
|
||
volunteer_scores.extend([0 for _ in range(blood_donation_break_time-1)]) | ||
maximum_blood_donation_count = (len(volunteer_scores)+blood_donation_break_time-1)//blood_donation_break_time+1 | ||
|
||
dp_table = [[0 for _ in range(maximum_blood_donation_count)] for _ in range(len(volunteer_scores))] | ||
|
||
for date in range(len(volunteer_scores)): | ||
if date >= blood_donation_break_time: | ||
for blood_donation_count in range(1,maximum_blood_donation_count): | ||
dp_table[date][blood_donation_count] = max(dp_table[date][blood_donation_count], | ||
dp_table[date-1][blood_donation_count] + volunteer_scores[date], | ||
dp_table[date-blood_donation_break_time][blood_donation_count-1] + blood_donation_score) | ||
|
||
dp_table[date][0] = dp_table[date-1][0] + volunteer_scores[date] | ||
|
||
print(dp_table) | ||
|
||
for count in range(len(dp_table[-1])): | ||
if dp_table[-1][count] >= need_score: | ||
print(count) | ||
break | ||
|
||
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,16 @@ | ||
target = int(input()) | ||
|
||
M = 1_000_000 | ||
period = 1_500_000 | ||
|
||
target %= period | ||
|
||
dp_table = [0 for _ in range(3)] | ||
dp_table[0] = 0 | ||
dp_table[1] = 1 | ||
|
||
for idx in range(2,target+1): | ||
idx %= 3 | ||
dp_table[idx] = dp_table[idx-1] % M + dp_table[idx-2] % M | ||
|
||
print(dp_table[target%3]%M) |
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
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 @@ | ||
cnt=0 | ||
def DFS(virus): | ||
global cnt | ||
visited[virus]=1 | ||
|
||
for i in network[virus]: | ||
if (visited[i]==0): | ||
DFS(i) | ||
cnt+=1 | ||
|
||
N= int(input()) | ||
link = int(input()) | ||
|
||
network = [[]*(N+1) for _ in range(N+1)] | ||
for i in range(link): | ||
a, b = map(int, input().split()) | ||
network[a].append(b) | ||
network[b].append(a) | ||
visited = [0]*(N+1) | ||
DFS(1) | ||
print(cnt) |
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
Oops, something went wrong.