公式
A - 投票の行方 / The Fate of the Vote 解説
by
A - 投票の行方 / The Fate of the Vote 解説
by
sounansya
AtCoder をはじめたばかりで何をしたらよいか分からない方は、まずは practice contest の問題 A「Welcome to AtCoder」を解いてみてください。基本的な入出力の方法が載っています。
また、プログラミングコンテストの問題に慣れていない方は、AtCoder Beginners Selection の問題をいくつか解いてみることをおすすめします。
各演説では、青木くんを支持する人は必ず \(1\) 人増えるか減るかのいずれかです。
今青木君を支持している人が何人かを保持しつつ、青木君を支持している人が \(0\) 人または \(N\) 人になったタイミングがいつかを出力すれば良いです。
n, m = map(int, input().split())
s = input()
a = [s[i] == "T" for i in range(n)]
cnt = a.count(True)
for i in range(m):
r = int(input()) - 1
cnt -= a[r]
a[r] ^= True
cnt += a[r]
if cnt == 0 or cnt == n:
print(i + 1)
break
else:
print(-1)
投稿日時:
最終更新:
