Submission #6637990


Source Code Expand

Copy
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/














int N, A[101010];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N;
	rep(i, 0, N) cin >> A[i];

	stack<int> st;
	rep(i, 0, N) {
		if (1 <= st.size() and st.top() == A[i]) continue;

		if (st.size() < 2) st.push(A[i]);
		else {
			int top = st.top(); st.pop();
			int second = st.top(); st.pop();

			if (second < top and top <= A[i]) {
				st.push(second);
				st.push(A[i]);
			}
			else if (second > top and top >= A[i]) {
				st.push(second);
				st.push(A[i]);
			}
			else {
				st.push(second);
				st.push(top);
				st.push(A[i]);
			}
		}
	}
	int ans = st.size();
	if (ans == 1) ans = 0;
	cout << ans << endl;
}

Submission Info

Submission Time
Task D - スキップ
User hamayanhamayan
Language C++14 (GCC 5.4.1)
Score 300
Code Size 2006 Byte
Status AC
Exec Time 13 ms
Memory 896 KB

Judge Result

Set Name Sample Subtask1
Score / Max Score 0 / 0 300 / 300
Status
AC × 2
AC × 41
Set Name Test Cases
Sample Sample01.txt, Sample02.txt
Subtask1 Sample01.txt, Sample02.txt, rand01.txt, rand02.txt, rand03.txt, rand04.txt, rand05.txt, rand06.txt, rand07.txt, rand08.txt, rand09.txt, rand10.txt, rand11.txt, rand12.txt, rand13.txt, rand14.txt, rand15.txt, rand16.txt, rand17.txt, rand18.txt, rand19.txt, rand20.txt, rand21.txt, rand22.txt, rand23.txt, rand24.txt, rand25.txt, rand26.txt, rand27.txt, rand28.txt, rand29.txt, rand30.txt, hand01.txt, hand02.txt, hand03.txt, hand04.txt, hand05.txt, hand06.txt, hand07.txt, hand08.txt, hand09.txt
Case Name Status Exec Time Memory
Sample01.txt AC 1 ms 256 KB
Sample02.txt AC 1 ms 256 KB
hand01.txt AC 1 ms 256 KB
hand02.txt AC 1 ms 256 KB
hand03.txt AC 1 ms 256 KB
hand04.txt AC 1 ms 256 KB
hand05.txt AC 1 ms 256 KB
hand06.txt AC 1 ms 256 KB
hand07.txt AC 1 ms 256 KB
hand08.txt AC 1 ms 256 KB
hand09.txt AC 1 ms 256 KB
max01.txt AC 13 ms 896 KB
max02.txt AC 12 ms 640 KB
max03.txt AC 12 ms 640 KB
max04.txt AC 7 ms 640 KB
rand01.txt AC 12 ms 896 KB
rand02.txt AC 10 ms 768 KB
rand03.txt AC 11 ms 896 KB
rand04.txt AC 8 ms 640 KB
rand05.txt AC 12 ms 896 KB
rand06.txt AC 3 ms 384 KB
rand07.txt AC 4 ms 384 KB
rand08.txt AC 12 ms 896 KB
rand09.txt AC 12 ms 896 KB
rand10.txt AC 10 ms 768 KB
rand11.txt AC 6 ms 512 KB
rand12.txt AC 4 ms 384 KB
rand13.txt AC 4 ms 512 KB
rand14.txt AC 12 ms 896 KB
rand15.txt AC 5 ms 512 KB
rand16.txt AC 11 ms 896 KB
rand17.txt AC 6 ms 512 KB
rand18.txt AC 2 ms 384 KB
rand19.txt AC 10 ms 768 KB
rand20.txt AC 9 ms 640 KB
rand21.txt AC 10 ms 768 KB
rand22.txt AC 9 ms 768 KB
rand23.txt AC 10 ms 768 KB
rand24.txt AC 9 ms 640 KB
rand25.txt AC 11 ms 768 KB
rand26.txt AC 11 ms 768 KB
rand27.txt AC 11 ms 768 KB
rand28.txt AC 3 ms 384 KB
rand29.txt AC 3 ms 384 KB
rand30.txt AC 7 ms 512 KB