-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added AceptaElReto (ada byron) problems
- Loading branch information
1 parent
2761c34
commit 3e93c83
Showing
16 changed files
with
573 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,28 @@ | ||
#Soluciones por Pablo Moreno Moreu, Arnau Neches Vila, Carlos Fernandez-LLebrez Acedo | ||
|
||
def lee_numero(): | ||
return int(input()) | ||
|
||
def lee_numeros(): | ||
return list(map(int, input().split())) | ||
|
||
def solve(ls:list): | ||
ant = ls[0] | ||
for e in ls[1:]: | ||
if e <= ant: | ||
print("NO") | ||
return | ||
else: | ||
ant = e | ||
print("SI") | ||
|
||
def main(): | ||
n = lee_numero() | ||
while n != 0: | ||
solve(lee_numeros()) | ||
n = lee_numero() | ||
|
||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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,23 @@ | ||
#Soluciones por Pablo Moreno Moreu, Arnau Neches Vila, Carlos Fernandez-LLebrez Acedo | ||
def lee_numero(): | ||
return int(input()) | ||
|
||
def lee_numeros(): | ||
return list(map(int, input().split())) | ||
|
||
def solve(ls:list): | ||
ls = ls+ls #No tiene sentido pegarla mas de dos veces por que el ciclo es neto negativo | ||
curr = best = 0 | ||
for e in ls: | ||
curr = max(curr+e, 0) | ||
best=max(best, curr) | ||
print(best) | ||
|
||
def main(): | ||
n = lee_numero() | ||
while n != 0: | ||
solve(lee_numeros()) | ||
n = lee_numero() | ||
|
||
if __name__ == "__main__": | ||
main() |
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 @@ | ||
#Soluciones por Pablo Moreno Moreu, Arnau Neches Vila, Carlos Fernandez-LLebrez Acedo | ||
from collections import defaultdict | ||
def lee_numero(): | ||
return int(input()) | ||
|
||
def lee_numeros(): | ||
return list(map(int, input().split())) | ||
|
||
def solve(n:int, ls:list): | ||
#Hay hasta un millon de sacos, pero solo 20000 numeros posibles. Nos interesa mas separarlos por pesos que mirar mucho la lista | ||
currMax = 0 | ||
weightDict = defaultdict(lambda :0) | ||
for e in ls: | ||
weightDict[e] +=1 | ||
if weightDict[e]==2: | ||
currMax+=1 | ||
weightDict[e]=0 | ||
if currMax > n: | ||
break | ||
print(min(currMax, n)) | ||
|
||
|
||
def main(): | ||
n = lee_numero() | ||
while n != 0: | ||
solve(lee_numeros()[0], lee_numeros()) | ||
n -=1 | ||
|
||
if __name__ == "__main__": | ||
main() |
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 @@ | ||
#Soluciones por Pablo Moreno Moreu, Arnau Neches Vila, Carlos Fernandez-LLebrez Acedo | ||
from collections import defaultdict | ||
def lee_numero(): | ||
return int(input()) | ||
|
||
def lee_numeros(): | ||
return list(map(int, input().split())) | ||
|
||
def solve(ls:list): | ||
innitSum = sum(ls) | ||
best = innitSum | ||
leftSum = 0 | ||
rightSum = innitSum | ||
day = 0 | ||
bestDay = 0 | ||
while day < len(ls): | ||
leftSum+=ls[day] | ||
rightSum-=ls[day] | ||
if abs(rightSum-leftSum)<best: | ||
best = abs(rightSum-leftSum) | ||
bestDay=day+1 | ||
day+=1 | ||
if best == innitSum: | ||
print(0) | ||
else: | ||
print(bestDay) | ||
|
||
def main(): | ||
n = lee_numero() | ||
while n != 0: | ||
solve(lee_numeros()) | ||
n=lee_numero() | ||
|
||
if __name__ == "__main__": | ||
main() |
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,34 @@ | ||
#Soluciones por Pablo Moreno Moreu, Arnau Neches Vila, Carlos Fernandez-LLebrez Acedo | ||
def lee_numero(): | ||
return int(input()) | ||
|
||
def lee_numeros(): | ||
return list(map(int, input().split())) | ||
|
||
def solve(nMax: int, ls:list): | ||
#posibles precios distintos: hay que hacer todas las sumas posibles de hasta nMax monedas | ||
#RECURSIVOOOOO | ||
#Si esto no es muy eficiente (que no lo es): se puede añadir memoria | ||
resSet = set() | ||
solveRes(nMax, ls, resSet, 0) | ||
print(len(resSet)) | ||
|
||
|
||
#Como añadir memoria, que estoy vago como pa escribirlo: quitamos el ls+[0] y añadimos siempre a resSet. Metemos tuplas con el | ||
#numero y paso de nMax. Si ya estaba esa tupla, cortamos la rama. Al final casi solo se exploran tantas ramas como soluciones hay, eficiencia maxima!!! | ||
def solveRes(nMax: int, ls: list, resSet: set, currSum: int): | ||
if nMax == 1: | ||
for e in ls: | ||
resSet.add(e+currSum) | ||
else: | ||
for e in ls + [0]: #para conseguir soluciones con menos de nMax monedas | ||
solveRes(nMax-1,ls,resSet,currSum+e) | ||
|
||
def main(): | ||
n = lee_numero() | ||
while n != 0: | ||
solve(lee_numeros()[1], lee_numeros()) | ||
n-=1 | ||
|
||
if __name__ == "__main__": | ||
main() |
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 @@ | ||
#Soluciones por Pablo Moreno Moreu, Arnau Neches Vila, Carlos Fernandez-LLebrez Acedo | ||
def lee(): | ||
return input() | ||
|
||
def solve(line: str): | ||
line = str.lower(line) | ||
line = str.replace(line, ' ', '') | ||
for i in range(len(line)): | ||
if line[i] != line[-(i+1)]: | ||
print("NO") | ||
return | ||
print("SI") | ||
|
||
def main(): | ||
line = lee() | ||
while line != "XXX": | ||
solve(line) | ||
line = lee() | ||
|
||
if __name__ == "__main__": | ||
main() |
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,50 @@ | ||
#Soluciones por Pablo Moreno Moreu, Arnau Neches Vila, Carlos Fernandez-LLebrez Acedo | ||
#Este es el primero graciosillo | ||
#Esto huele a grafo dirigido, pero dijkstra me parece to feo. | ||
def lee_numero(): | ||
return int(input()) | ||
|
||
def lee_numeros(): | ||
return list(map(int, input().split())) | ||
|
||
def solve(n:int, k:int, serpientes: list, escaleras:list): | ||
meta = n*n | ||
currPos = (1, 0) #posicion, numero de tiradas | ||
visited = set() | ||
pile = [currPos] | ||
while len(pile)>0: | ||
currPos = pile.pop(0) | ||
for tirada in range(1, k+1): | ||
alcanzada = currPos[0]+tirada | ||
if alcanzada >= meta: | ||
print(currPos[1]+1) | ||
return | ||
for sStart, sEnd in serpientes: #Hay formas mas eficientes de hacer esto | ||
if sStart == alcanzada: | ||
alcanzada = sEnd | ||
break | ||
for eStart, eEnd in escaleras: | ||
if eStart == alcanzada: | ||
alcanzada = eEnd | ||
break | ||
if alcanzada not in visited: | ||
pile.append((alcanzada, currPos[1]+1)) | ||
visited.add(alcanzada) | ||
|
||
|
||
|
||
def main(): | ||
info = lee_numeros() | ||
n = info[0] | ||
k = info[1] | ||
serpientes = [] | ||
for e in range(info[2]): | ||
serpientes.append(lee_numeros()) | ||
escaleras = [] | ||
for e in range(info[3]): | ||
escaleras.append(lee_numeros()) | ||
lee_numeros() | ||
solve(n, k, serpientes, escaleras) | ||
|
||
if __name__ == "__main__": | ||
main() |
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 @@ | ||
#Soluciones por Pablo Moreno Moreu, Arnau Neches Vila, Carlos Fernandez-LLebrez Acedo | ||
def lee_numero(): | ||
return int(input()) | ||
|
||
def lee_numeros(): | ||
return list(map(int, input().split())) | ||
|
||
#Lo primero que se me ocurre es ordenar las dos listas y calcular la suma de diferencias. Se puede mejorar seguro | ||
def solve(n: int, pers: list, esquis: list): | ||
pers.sort() | ||
esquis.sort() | ||
ac = 0 | ||
for i in range(n): | ||
if (pers[i] < esquis[i]): | ||
ac += esquis[i] - pers[i] | ||
else: | ||
ac += pers[i] - esquis[i] | ||
print(ac) | ||
|
||
def main(): | ||
n = -1 | ||
while(n != 0): | ||
n = lee_numero() | ||
pers = lee_numeros() | ||
esquis = lee_numeros() | ||
solve(n, pers, esquis) | ||
|
||
if __name__ == "__main__": | ||
main() | ||
|
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,36 @@ | ||
#Soluciones por Pablo Moreno Moreu, Arnau Neches Vila, Carlos Fernandez-LLebrez Acedo | ||
#recibe cadenas y hay que indicar la longitud de la subcadena palindroma mas larga | ||
|
||
def solution(cad: str): | ||
res = 0 | ||
l_act = 0 | ||
for i in range(len(cad)): | ||
#primero contemos la subcadena formada por letras iguales | ||
l_act = 1 | ||
k = 1 | ||
while i+k<len(cad) and cad[i] == cad[i+k]: | ||
l_act+=1 | ||
k+=1 | ||
|
||
k-=1 #cuando sale del bucle de arriba la k ya esta en la siguiente letra a la subcadena de letras iguales | ||
j=1 | ||
while i-j>=0 and i+k+j<len(cad): | ||
#vamos comprobando si podemos prolongar el palindromo | ||
if cad[i-j] == cad[i+k+j]: | ||
l_act+=2 | ||
j+=1 | ||
else: break | ||
|
||
if l_act>res: | ||
res = l_act | ||
print(res) | ||
|
||
def main(): | ||
while True: | ||
cad = str(input()) | ||
if cad != "": | ||
solution(cad) | ||
else: break | ||
|
||
if __name__ == "__main__": | ||
main() |
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,80 @@ | ||
#Soluciones por Pablo Moreno Moreu, Arnau Neches Vila, Carlos Fernandez-LLebrez Acedo | ||
def lee_linea(): | ||
return list(input().split()) | ||
|
||
def solution(data: list): | ||
a = data[0] | ||
b = data[1] | ||
c = data[2] | ||
res = "" | ||
if (len(a) == len(b) and len(a) == len(c)): | ||
for i in range(len(a)): | ||
if(a[i] == b[i] or a[i] == c[i]): | ||
res+=(a[i]) | ||
elif(b[i] == c[i]): | ||
res+=(b[i]) | ||
else: | ||
res = "RUIDO COSMICO" | ||
break | ||
|
||
elif (len(a)>len(b)): #b es mas corto | ||
ins = False #no se ha insertado b | ||
for i in range(len(a)): | ||
if(a[i] == c[i]): | ||
res+=(a[i]) | ||
elif(not ins): | ||
res+=(b) | ||
if res[i] != a[i] and res[i] != b[i]: | ||
res = "RUIDO COSMICO" | ||
break | ||
ins = True | ||
else: | ||
if res[i] != a[i] and res[i] != c[i]: | ||
res = "RUIDO COSMICO" | ||
break | ||
|
||
|
||
elif (len(a)>len(c)): #c es mas corto | ||
ins = False #no se ha insertado c | ||
for i in range(len(a)): | ||
if(a[i] == b[i]): | ||
res+=(a[i]) | ||
elif(not ins): | ||
res+=(c) | ||
if res[i] != a[i] and res[i] != b[i]: | ||
res = "RUIDO COSMICO" | ||
break | ||
ins = True | ||
else: | ||
if res[i] != a[i] and res[i] != b[i]: | ||
res = "RUIDO COSMICO" | ||
break | ||
|
||
else: #a es mas corto | ||
ins = False #no se ha insertado a | ||
for i in range(len(b)): | ||
if(c[i] == b[i]): | ||
res+=(b[i]) | ||
elif(not ins): | ||
res+=(a) | ||
if res[i] != a[i] and res[i] != b[i]: | ||
res = "RUIDO COSMICO" | ||
break | ||
ins = True | ||
else: | ||
if res[i] != c[i] and res[i] != b[i]: | ||
res = "RUIDO COSMICO" | ||
break | ||
|
||
print(res) | ||
|
||
def main(): | ||
while True: | ||
datos = lee_linea() | ||
if len(datos) == 3: | ||
solution(datos) | ||
else: | ||
break | ||
|
||
if __name__ == "__main__": | ||
main() |
Oops, something went wrong.