Skip to content

Commit 6105872

Browse files
committed
全部
1 parent a43bc89 commit 6105872

File tree

304 files changed

+31460
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

304 files changed

+31460
-0
lines changed

cf784a.py

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
print(30-int(input()))
2+
# print(27)

cf784e.py

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
v1,v2,v3,v4=int(input()),int(input()),int(input()),int(input())
2+
print( ( (v1|v2)&(v3^v4) )|( (v2&v3)^(v1|v4) ) )

cf784f.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
s = input()
2+
l = s.split()[0]
3+
ns = s.split()[1:]
4+
# print(l,ns)
5+
print(' '.join(sorted(ns)))

cf784g.py

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
def shift(s,n=1):
2+
ret = ''
3+
ret += '>' * (s-1)
4+
for i in range(10):
5+
ret += '{}[-]{}[<+>-]'.format('<'*n, '>'*n)
6+
ret += '>'
7+
ret += '<'*10
8+
ret += '<' * (s-1)
9+
return ret
10+
11+
exp = input()
12+
nums = []
13+
ops = []
14+
for c in exp:
15+
if c in '0123456789':
16+
nums.append(int(c))
17+
else:
18+
ops.append(c)
19+
lg = len(nums)
20+
21+
ret = ''
22+
for n in nums:
23+
ret += '+' * n
24+
ret += '>'
25+
ret += '\n'
26+
ret += '<'*lg
27+
ret += '\n'
28+
29+
pos = 1
30+
for op in ops:
31+
if op == '-':
32+
ret += '>[-<->]'
33+
elif op == '+':
34+
ret += '>[-<+>]'
35+
pos += 1
36+
ret += '<'*(pos-1)
37+
ret += shift(pos+1)
38+
ret += '>'*(pos-1)
39+
ret += '\n'
40+
ret += '.'
41+
print(ret)
42+
43+
44+
45+
46+
def ope(op, idx1, val1, idx2, val2, ridx):
47+
ret = ''
48+
if op == '+':
49+
ret += '>' * ridx
50+
ret += '+' * (val1+val2)
51+
ret += '<' * ridx
52+
elif op == '-':
53+
ret += '>' * ridx
54+
ret += '-'
55+
56+
57+
def move(sidx, eidx):
58+
if sidx <= eidx:
59+
raise Exception
60+
ret = ''
61+
ret += '>' * (eidx - 1)
62+
ret += '[-]'
63+
ret += '>' * (sidx - eidx)
64+
ret += '[-{}+{}]'.format('<'*(sidx-eidx),'>'*(sidx-eidx))
65+
ret += '<' * (sidx-1)
66+
return ret

cf784g_2.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
exp = input()
2+
ans = str(eval(exp))
3+
4+
l=len(ans)
5+
print('>'*l+'++++++++')
6+
print('[', end='')
7+
for i in range(l):
8+
print('<++++++', end='')
9+
print('>'*l+'-]')
10+
print('<'*l)
11+
12+
num = 48
13+
num = 0
14+
for c in ans:
15+
print('+'*(num+int(c))+'.>')
16+
# print('+'*ans+'.')

codefes2016_a/a.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
s = input()
2+
3+
print(s[:4] + ' ' + s[4:])

codefes2016_a/b.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
N = int(input())
2+
As = list(map(int, input().split()))
3+
As.insert(0,-1)
4+
cnt = 0
5+
for i in range(N+1):
6+
j = As[i]
7+
if j <= i:
8+
continue
9+
if As[j] == i:
10+
cnt += 1
11+
print(cnt)

codefes2016_a/c.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
s = input()
2+
K = int(input())
3+
4+
def cord(c):
5+
return ord(c)-97
6+
7+
def cchr(n):
8+
return chr(n+97)
9+
10+
def smcheck(c, k):
11+
return 26-cord(c) <= k
12+
13+
def smcnt(c, k):
14+
return 26-cord(c)
15+
16+
ans = ''
17+
for c in s:
18+
sc = smcnt(c, K)
19+
if sc <= K and sc < 26:
20+
K -= sc
21+
ans += cchr((cord(c) + sc)%26)
22+
# print(K,ans)
23+
else:
24+
ans += c
25+
if K>26:
26+
K = K%26
27+
if K>0:
28+
lc = ans[-1]
29+
ans = ans[:-1]
30+
ans += cchr((cord(lc)+K)%26)
31+
32+
print(ans)

codefes2016_a/d.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
R, C = list(map(int, input().split()))
2+
N = int(input())
3+
di = {}
4+
for i in range(N):
5+
ri, ci, ai = list(map(int, input().split()))
6+

codefes2016_b/a.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
s = input()
2+
cs = 'CODEFESTIVAL2016'
3+
cnt = 0
4+
5+
for i in range(len(cs)):
6+
if s[i]==cs[i]:
7+
continue
8+
else:
9+
cnt += 1
10+
print(cnt)

codefes2016_b/b.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
N, A, B = list(map(int, input().split()))
2+
S = input()
3+
a_cnt = 0
4+
b_cnt = 0
5+
ab_cnt = 0
6+
7+
for c in S:
8+
if c == 'a':
9+
if ab_cnt < A+B:
10+
print('Yes')
11+
a_cnt += 1
12+
ab_cnt += 1
13+
else:
14+
print('No')
15+
elif c == 'b':
16+
if ab_cnt < A+B and b_cnt < B:
17+
print('Yes')
18+
b_cnt += 1
19+
ab_cnt += 1
20+
else:
21+
print('No')
22+
else:
23+
print('No')

codefes2016_b/c.py

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
4+
import array
5+
import collections
6+
import heapq
7+
8+
9+
AdjacentVertex = collections.namedtuple("AdjacentVertex", "vertex cost")
10+
INF = 2 ** 31 - 1
11+
NO_VERTEX = -1
12+
13+
14+
# Prim法で頂点0からの最小全域木を求める
15+
def compute_mst_prim(max_v, adj_list):
16+
# pred[u]は頂点uの「ひとつ前」の頂点を表す
17+
pred = collections.defaultdict(lambda: NO_VERTEX)
18+
# uとpred[u]を結ぶ辺の重みがkey[u]に入る
19+
key = collections.defaultdict(lambda: INF)
20+
key[0] = 0
21+
# 二分ヒープを優先度付きキューとして用いる
22+
pq = [(key[v], v) for v in range(max_v)]
23+
heapq.heapify(pq)
24+
# 優先度付きキューに頂点が入っているかを示す配列
25+
in_pq = array.array("B", (True for _ in range(max_v)))
26+
while pq:
27+
_, u = heapq.heappop(pq)
28+
in_pq[u] = False
29+
for v, v_cost in adj_list[u]:
30+
if in_pq[v]:
31+
weight = v_cost
32+
if weight < key[v]:
33+
pred[v] = u
34+
key[v] = weight
35+
heapq.heappush(pq, (weight, v))
36+
in_pq[v] = True
37+
return (pred, key)
38+
39+
40+
def main():
41+
W, H = list(map(int, input().split()))
42+
# max_v, max_e = map(int, input().split())
43+
max_v = (W+1) * (H+1)
44+
max_e = (W+1)*H + (H+1)*W
45+
adjacency_list = collections.defaultdict(set)
46+
for _w in range(W):
47+
p = int(input())
48+
for _h in range(H):
49+
adjacency_list[_w*H+_h].add(AdjacentVertex((_w+1)*H+_h, p))
50+
adjacency_list[(_w+1)*H+_h].add(AdjacentVertex(_w*H+_h, p))
51+
for _h in range(H):
52+
q = int(input())
53+
for _w in range(W):
54+
adjacency_list[_w*H+_h].add(AdjacentVertex((_w+1)*H+_h, q))
55+
adjacency_list[(_w+1)*H+_h].add(AdjacentVertex(_w*H+_h, q))
56+
# for _ in range(max_e):
57+
# s, t, w = map(int, input().split())
58+
# adjacency_list[s].add(AdjacentVertex(t, w))
59+
# adjacency_list[t].add(AdjacentVertex(s, w))
60+
(_, key) = compute_mst_prim(max_v, adjacency_list)
61+
print(sum(key.values()))
62+
63+
64+
if __name__ == '__main__':
65+
main()
66+

codefes2016_b/c2.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
W, H = list(map(int, input().split()))
2+
ps, qs = [], []
3+
for _ in range(W):
4+
ps.append(int(input()))
5+
for _ in range(H):
6+
qs.append(int(input()))
7+
8+
already = {}
9+
already.add('0,0')
10+

codefes2016_b/d.py

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
N = int(input())
2+
As = []
3+
for _ in range(N):
4+
As.append(int(input()))
5+
6+
ans = 0
7+
m_p = 1
8+
for idx,a in enumerate(As):
9+
if As[idx] <= m_p:
10+
continue
11+
while As[idx] > m_p:
12+
ans += 1
13+
As[idx] -= m_p
14+
m_p = max(m_p, As[idx]+1)
15+
print(ans)
16+
17+
18+
'''
19+
3 1-2
20+
1
21+
4 2-1
22+
1
23+
5 3-1
24+
9 3-2
25+
2
26+
6 4-1
27+
5 4-1
28+
3
29+
5 4-1
30+
8 4-1
31+
9 4-1
32+
7 5-1
33+
9 5-1
34+
'''

codefes2016_c/a.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
s = input()
2+
3+
if 'C' in s and 'F' in s and s.index('C') < s.rindex('F'):
4+
print('Yes')
5+
else:
6+
print('No')

codefes2016_c/b.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
K, T = list(map(int, input().split()))
2+
a = list(map(int, input().split()))
3+
4+
# def remax(seq):
5+
# m = max(seq)
6+
# for idx,i in enumerate(seq):
7+
# if m==i:
8+
# return (idx, m)
9+
#
10+
# lastK = -1
11+
# cnt = 0
12+
# for _k in range(K):
13+
# remax
14+
#
15+
16+
print(max(0,max(a)*2-sum(a)-1))

codefes2016_c/c.py

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
N = int(input())
2+
T = list(map(int, input().split()))
3+
A = list(map(int, input().split()))
4+
5+
fixed_peek_t = {}
6+
unfixed_peek_t = {}
7+
fixed_peek_a = {}
8+
unfixed_peek_a = {}
9+
10+
lp = 0
11+
for idx, height in enumerate(T):
12+
if lp < height:
13+
fixed_peek_t[idx] = height
14+
elif idx not in fixed_peek_t:
15+
unfixed_peek_t[idx] = height
16+
lp = height
17+
18+
lp = 0
19+
for _idx, height in enumerate(reversed(A)):
20+
idx = N-1 - _idx
21+
if lp < height:
22+
fixed_peek_a[idx] = height
23+
elif idx not in fixed_peek_a:
24+
unfixed_peek_a[idx] = height
25+
lp = height
26+
27+
# print(unfixed_peek_t)
28+
# print(fixed_peek_t)
29+
# print(unfixed_peek_a)
30+
# print(fixed_peek_a)
31+
32+
if max(A) != max(T):
33+
print(0)
34+
else:
35+
failflag = 0
36+
for k,v in fixed_peek_t.items():
37+
if k not in fixed_peek_a:
38+
continue
39+
if v != fixed_peek_a[k]:
40+
failflag = 1
41+
break
42+
if k in unfixed_peek_a and v > unfixed_peek_a[k]:
43+
failflag = 1
44+
break
45+
for k,v in unfixed_peek_t.items():
46+
if k not in fixed_peek_a:
47+
continue
48+
if v < fixed_peek_a[k]:
49+
failflag = 1
50+
break
51+
if failflag == 0:
52+
cnt = 1
53+
for k,v in unfixed_peek_t.items():
54+
if k not in unfixed_peek_a:
55+
continue
56+
cnt *= min(v, unfixed_peek_a[k])
57+
cnt %= 10**9 + 7
58+
59+
print(cnt)
60+
else:
61+
print(0)

0 commit comments

Comments
 (0)