CF1143A.The Doors
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Three years have passes and nothing changed. It is still raining in London, and Mr. Black has to close all the doors in his home in order to not be flooded. Once, however, Mr. Black became so nervous that he opened one door, then another, then one more and so on until he opened all the doors in his house.
There are exactly two exits from Mr. Black's house, let's name them left and right exits. There are several doors in each of the exits, so each door in Mr. Black's house is located either in the left or in the right exit. You know where each door is located. Initially all the doors are closed. Mr. Black can exit the house if and only if all doors in at least one of the exits is open. You are given a sequence in which Mr. Black opened the doors, please find the smallest index k such that Mr. Black can exit the house after opening the first k doors.
We have to note that Mr. Black opened each door at most once, and in the end all doors became open.
三年过去了,一切都没有改变。伦敦仍在下雨,布莱克先生不得不关上家中所有的门,以免房屋被淹。然而有一次,布莱克先生变得异常紧张,于是他先打开了一扇门,接着又打开一扇,再打开一扇……如此持续下去,直到他打开了家中所有的门。
布莱克先生的住宅恰好有两个出口,我们将其命名为“左出口”和“右出口”。每个出口中都设有若干扇门,因此布莱克先生家中的每一扇门都位于左出口或右出口之中。已知每扇门所在的出口。初始时,所有门均处于关闭状态。当且仅当至少一个出口中的所有门均被打开时,布莱克先生才能离开住宅。现给出布莱克先生开门的顺序,请找出最小的下标 k,使得在打开前 k 扇门后,布莱克先生即可离开住宅。
需要注意的是:布莱克先生每扇门至多打开一次,且最终所有门均被打开。
输入格式
The first line contains integer n (2≤n≤200000) — the number of doors.
The next line contains n integers: the sequence in which Mr. Black opened the doors. The i-th of these integers is equal to 0 in case the i-th opened door is located in the left exit, and it is equal to 1 in case it is in the right exit.
It is guaranteed that there is at least one door located in the left exit and there is at least one door located in the right exit.
第一行包含一个整数 n(2≤n≤200000)—— 表示门的数量。
第二行包含 n 个整数:表示 Mr. Black 开门的顺序。其中第 i 个整数为 0 表示第 i 个被打开的门位于左侧出口,为 1 表示其位于右侧出口。
保证至少存在一扇门位于左侧出口,且至少存在一扇门位于右侧出口。
输出格式
Print the smallest integer k such that after Mr. Black opened the first k doors, he was able to exit the house.
输出最小的整数 k,使得在布莱克先生打开前 k 扇门后,他能够离开房屋。
输入输出样例
输入#1
5 0 0 1 0 0
输出#1
3
输入#2
4 1 0 0 1
输出#2
3
说明/提示
In the first example the first two doors are from the left exit, so when Mr. Black opened both of them only, there were two more closed door in the left exit and one closed door in the right exit. So Mr. Black wasn't able to exit at that moment.
When he opened the third door, all doors from the right exit became open, so Mr. Black was able to exit the house.
In the second example when the first two doors were opened, there was open closed door in each of the exit.
With three doors opened Mr. Black was able to use the left exit.
在第一个例子中,最左侧的两扇门属于左出口,因此当布莱克先生仅打开这两扇门时,左出口还有两扇关闭的门,右出口还有一扇关闭的门。此时布莱克先生尚无法离开房屋。
当他打开第三扇门后,右出口的所有门均变为开启状态,因此布莱克先生得以离开房屋。
在第二个例子中,当打开前两扇门时,每个出口均各有一扇已开启的门和一扇关闭的门。
当打开三扇门后,布莱克先生便可以使用左出口离开。
输入解题思路,AI测评打分。不知道怎么写?