Add validated scripts
This commit is contained in:
parent
36e6b70570
commit
7af4a4864a
31
04-03-24/d.py
Normal file
31
04-03-24/d.py
Normal file
@ -0,0 +1,31 @@
|
||||
[n, p] = [int(a) for a in input().split()]
|
||||
aset = set([int(a) for a in input().split()])
|
||||
|
||||
for a in aset.copy():
|
||||
initial_a = a
|
||||
while a > 0:
|
||||
if a%2 == 1:
|
||||
a = (a-1)//2
|
||||
elif a%4 == 0:
|
||||
a = a//4
|
||||
else:
|
||||
break
|
||||
if a in aset:
|
||||
aset.discard(initial_a)
|
||||
break
|
||||
|
||||
t={i:0 for i in range(p+2)}
|
||||
n=0
|
||||
modval = (10**9 +7)
|
||||
|
||||
for e in aset:
|
||||
i=e.bit_length()-1 # Log2 plus efficace
|
||||
if i<p:
|
||||
t[i]+=1
|
||||
|
||||
for i in range(p):
|
||||
t[i+1] = (t[i]+t[i+1])%modval
|
||||
t[i+2] = (t[i]+t[i+2])%modval
|
||||
n=(t[i]+n)%modval
|
||||
|
||||
print(n%modval)
|
57
11-03-24/a.py
Normal file
57
11-03-24/a.py
Normal file
@ -0,0 +1,57 @@
|
||||
import sys
|
||||
from types import GeneratorType
|
||||
|
||||
|
||||
def bootstrap(f, stack=[]):
|
||||
def wrappedfunc(*args, **kwargs):
|
||||
if stack:
|
||||
return f(*args, **kwargs)
|
||||
to = f(*args, **kwargs)
|
||||
while True:
|
||||
if type(to) is GeneratorType:
|
||||
stack.append(to)
|
||||
to = next(to)
|
||||
else:
|
||||
stack.pop()
|
||||
if not stack:
|
||||
break
|
||||
to = stack[-1].send(to)
|
||||
return to
|
||||
|
||||
return wrappedfunc
|
||||
|
||||
|
||||
|
||||
global vus
|
||||
vus = set()
|
||||
|
||||
@bootstrap
|
||||
def dfs(voisins, r, cc):
|
||||
cc.add(r)
|
||||
vus.add(r)
|
||||
for v in voisins[r]:
|
||||
if v not in vus:
|
||||
yield dfs(voisins, v, cc)
|
||||
yield cc
|
||||
|
||||
def main():
|
||||
[n, k] = [int(i) for i in input().split()]
|
||||
a = [int(i) for i in input().split()]
|
||||
|
||||
couples = [[int(i) for i in input().split()] for _ in range(k)]
|
||||
couples += [(j, i) for (i, j) in couples]
|
||||
|
||||
# On créé les set() d'arêtes
|
||||
voisins = {
|
||||
i: set() for i in range(1, n+1)
|
||||
}
|
||||
for (i, j) in couples:
|
||||
voisins[i].add(j)
|
||||
voisins[j].add(i)
|
||||
|
||||
|
||||
ccs = [dfs(voisins, i, set()) for i in range(1, n+1) if i not in vus]
|
||||
return sum([min([a[i-1] for i in cc]) for cc in ccs])
|
||||
|
||||
|
||||
print(main())
|
Loading…
Reference in New Issue
Block a user