Hello. It's chewy and chewy. We will solve the introduction to AOJ's algorithms and data structures. It's easy to keep a record of what you've learned.
It's been less than half a year since I started programming myself AtCoder is green, so I'm not a strong man. Let's work hard together.
make it possible with Pai-chan
This time PART3: Basic data structure. I want to do my best and do it to the end.
ALDS1_3_A: Stack ALDS1_3_B: Queue ALDS1_3_C: Bidirectional linked list ALDS1_3_D : Areas on the Cross-Section Diagram
stack~
a = list(map(str,input().split()))
l = []
for i in a:
if i=="+":
a1 = l.pop()
a2 = l.pop()
a3 = a1+a2
l.append(a3)
elif i=="-":
a1 = l.pop()
a2 = l.pop()
a3 = a2-a1
l.append(a3)
elif i=="*":
a1 = l.pop()
a2 = l.pop()
a3 = a1*a2
l.append(a3)
else:
l.append(int(i))
print(l[0])
Let's use deque
from collections import deque
n,q = map(int,input().split())
l = [list(map(str,input().split())) for _ in range(n)]
time = 0
dq = deque(l)
while dq:
a,b = dq.popleft()
if int(b)<= q:
time += int(b)
print(a,time)
else:
time += q
b = int(b) - q
dq.append([a,b])
Basically calculated with deque In Python, if you do not do the following two points, it will be TLE ・ It is faster to define input by yourself ・ If you don't need index, for a in d: is faster
from collections import deque
import sys
input = sys.stdin.readline
n = int(input())
d = deque([])
for _ in range(n):
a = list(map(str,input().split()))
if a[0]=="insert":
d.appendleft(a[1])
elif a[0]=="delete":
if a[1] in d:
d.remove(a[1])
elif a[0]=="deleteFirst":
s = d.popleft()
elif a[0]=="deleteLast":
s = d.pop()
print(*d)
ALDS1_3_D : Areas on the Cross-Section Diagram
It hasn't melted yet ... Pien
I will update it when D melts. I will not smoke