Submission #72012722


Source Code Expand

#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int n,a[N];
stack<int> st;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=1;i<=n;i++){
		if(st.size()>=3){
			int k1=st.top();st.pop();
			int k2=st.top();st.pop();
			int k3=st.top();st.pop();
			if(k1==k2&&k3==a[i]&&k1==k3)continue;
			st.push(k3),st.push(k2),st.push(k1),st.push(a[i]);
		}else st.push(a[i]);
	}
	cout<<st.size();
	return 0;
}

Submission Info

Submission Time
Task C - 1D puyopuyo
User kac17
Language C++23 (GCC 15.2.0)
Score 300
Code Size 505 Byte
Status AC
Exec Time 9 ms
Memory 4988 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 3
AC × 21
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3592 KiB
00_sample_01.txt AC 1 ms 3468 KiB
00_sample_02.txt AC 1 ms 3588 KiB
01_random_00.txt AC 1 ms 3592 KiB
01_random_01.txt AC 9 ms 4560 KiB
01_random_02.txt AC 8 ms 4704 KiB
01_random_03.txt AC 8 ms 4772 KiB
01_random_04.txt AC 8 ms 4628 KiB
01_random_05.txt AC 8 ms 4504 KiB
01_random_06.txt AC 9 ms 4744 KiB
01_random_07.txt AC 9 ms 4712 KiB
01_random_08.txt AC 9 ms 4724 KiB
01_random_09.txt AC 8 ms 4712 KiB
01_random_10.txt AC 8 ms 4668 KiB
01_random_11.txt AC 8 ms 4584 KiB
01_random_12.txt AC 7 ms 4516 KiB
01_random_13.txt AC 7 ms 4488 KiB
01_random_14.txt AC 7 ms 4324 KiB
01_random_15.txt AC 7 ms 4364 KiB
01_random_16.txt AC 9 ms 4988 KiB
01_random_17.txt AC 8 ms 4644 KiB