Submission #6637966


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();
	cout << ans << endl;
}

Submission Info

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

Judge Result

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