We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
https://www.acmicpc.net/problem/1021
in: 3 3 1 2 3 out: 0 explain: 1,2,3 2,3 3 in: 3 3 2 3 1 out: 1 explain: 1,2,3 2,3,1* 3,1 1 in: 10 3 2 9 5 out: 8 explain: 1,2,3,4,5,6,7,8,9,10 2,3,4,5,6,7,8,9,10,1 (1) 3,4,5,6,7,8,9,10,1 (3 or 6, len=9) 9,10,1,3,4,5,6,7,8 (3 or 6, len=9) 10,1,3,4,5,6,7,8 5,6,7,8,10,1,3,4 (4, len=8) 6,7,8,10,1,3,4
from collections import deque import sys readl = sys.stdin.readline n, m = [int(i) for i in readl().split()] nums = [int(i) for i in readl().split()] que = deque(range(1, n+1)) cnt_total = 0 for num in nums: cnt = 0 while que[0] != num: que.append(que.popleft()) cnt += 1 cnt_total += min(cnt, len(que)-cnt) que.popleft() print(cnt_total)
The text was updated successfully, but these errors were encountered:
No branches or pull requests
https://www.acmicpc.net/problem/1021
Impl plan
Impl
The text was updated successfully, but these errors were encountered: