AOJ 0527 Setting Go Stones

地道にシミュレーションする。
時間ギリギリだった

#include <cstdio>
#include <algorithm>
using namespace std;

int main(){
	int N;
	while(scanf("%d",&N) && N!=0){
		int stone[N];
		for(int i=1; i<=N; i++){
			int t;
			scanf("%d", &t);
			if(i%2==1) stone[i-1] = t;
			else{
				for(int m=i-2; m>=0; m--){
					if(stone[m]==t) break;
					stone[m]=t;
				}
				stone[i-1] = t;
			}
		}
		int ans = 0;
		for(int i=0;i<N;i++)
			ans+=(stone[i]==0)?1:0;
		printf("%d\n", ans);
	}
	return 0;
}