Skip to content

Commit 6090478

Browse files
author
IsHYuhi
committed
init ARC
1 parent 654a944 commit 6090478

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

ABC/ABC111/C.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from collections import Counter
2+
n = int(input())
3+
v = list(map(int, input().split()))
4+
5+
v1_c = Counter(v[::2])
6+
v2_c = Counter(v[1::2])
7+
v1_c = sorted(list(v1_c.items()), key=lambda x: x[1])
8+
v2_c = sorted(list(v2_c.items()), key=lambda x: x[1])
9+
10+
v1 = v1_c
11+
v2 = v2_c
12+
13+
ans_1 = 0
14+
15+
if v1[-1][0]==v2[-1][0]:
16+
ans_1 += v1[-1][1]
17+
v1 = v1[:-1]
18+
19+
if len(v1)>=2:
20+
for i, j in v1[:-1]:
21+
ans_1 += j
22+
23+
if len(v2)>=2:
24+
for i, j in v2[:-1]:
25+
ans_1 += j
26+
27+
v1 = v1_c
28+
v2 = v2_c
29+
30+
ans_2 = 0
31+
32+
if v1[-1][0]==v2[-1][0]:
33+
ans_2 += v2[-1][1]
34+
v2 = v2[:-1]
35+
36+
if len(v2)>=2:
37+
for i, j in v2[:-1]:
38+
ans_2 += j
39+
40+
if len(v1)>=2:
41+
for i, j in v1[:-1]:
42+
ans_2 += j
43+
44+
print(min(ans_1, ans_2))

ABC/ABC128/C.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from itertools import combinations
2+
n, m = map(int, input().split())
3+
ksm = [list(map(int, input().split())) for _ in range(m)]
4+
p = list(map(int, input().split()))
5+
6+
onoff = [0]*n
7+
total = 0
8+
9+
def dfs(i, onoff):
10+
global total
11+
if i == n:
12+
flag = True
13+
for idx, j in enumerate(ksm):
14+
count = 0
15+
for k in j[1:]:
16+
count += onoff[k-1]
17+
if count%2 != p[idx]:
18+
flag = False
19+
if flag:
20+
total += 1
21+
return
22+
dfs(i+1, onoff[:])
23+
dfs(i+1, onoff[:i]+[1]+onoff[i+1:])
24+
25+
dfs(0, onoff)
26+
print(total)

0 commit comments

Comments
 (0)