Submission #86887

# Submission time Handle Problem Language Result Execution time Memory
86887 2018-11-28T08:45:41 Z Scayre Money (IZhO17_money) C++14
0 / 100
2 ms 508 KB
///////////////////////////
//         INFO          //
//                       //
//    Handle -> Scayre   //
//                       //
//   Template vers. 1.1  //
//                       //
//   It'll be accepted   //
//                       //
///////////////////////////

//████╗████████╗██╗███████╗══███╗═══███╗████████╗════//
//═██╔╝═══██╔══╝╚█║██╔════╝══████╗═████║██╔═════╝═══//
//═██║════██║════╚╝███████╗══██╔████╔██║█████╗══════//
//═██║════██║══════╚════██║══██║╚██╔╝██║██╔══╝══════//
//████╗═══██║══════███████║══██║═╚═╝═██║███████╗═════//


#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <complex>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>

#define ll long long
#define ld long double
#define ull unsigned ll
#define ioi exit(0);

#define f first
#define s second

#define inf (int)1e9 + 7

#define NFS ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);

#define mp(x,y) make_pair(x,y)

#define lb(x) lower_bound(x)
#define ub(x) upper_bound(x)

#define pb push_back
#define ppb pop_back

#define bitcoin __builtin_popcount

#define endl "\n"

#define in(x) insert(x)

#define sz(x) (int)x.size()

#define all(x) x.begin(),x.end()

#define pw2(x) (1<<x) //2^x

#define forit(it,v) for (typeof(v.begin()) it = v.begin(); it != v.end(); ++it)

#define sqr(x) ((x) * 1ll * (x))

#define UpdateRandom srand (time(NULL));

using namespace std;

const int N = (int)5e5 + 7, MOD = (int)1e9 + 7;

int n;

int a[N];

bool u[N];

map <int,int> m;

int ans;

set<int> s;

bool ok=0;

void calc(int l,int r){
	int cnt=0;
	if(abs(l-r)==1)return;
	for(int i=l+1;i<r-1;i++){
		if(u[i]==1){
			ok=1;
			break;
		}
		if(abs(m[i]-m[i+1])>1)cnt++;
	}
	if(ok==1)return;
	for(int i=l;i<r;i++){
		u[i]=1;
	}
	ans+=cnt+1;
}

int main(){

	#ifdef IOI2019
		freopen ("in.txt", "r", stdin);
	#endif

	NFS

	cin >> n;

	for(int i=1;i<=n;i++){
		cin >> a[i];
		m[a[i]]=i;
	}

	for(int i=1;i<=n;i++){
		//cout << i << " NOW " << ans << endl;
		if(i==n){
			ans++;
			break;
		}
		if(u[a[i]]==1){
			continue;
		}
		if(u[a[i]]==0 && u[a[i]]!=0){
			u[a[i]]=1;
			ans++;
			i++;
			continue;
		}
		if(a[i]<a[i+1]){
			ok=0;
			//cout << "was " << ans << ' ' << i << endl;
			calc(a[i],a[i+1]);
			if(ok==1){
				ans++;
				continue;
			}
			//cout << ans << endl;
		}
		if(a[i]>a[i+1]){
			u[a[i]]=1;
			ans++;
			continue;
		}
	}

	cout << ans << endl;

	#ifdef IOI2019
		cout << "\nTime Elapsed : " << clock () * 1.0 / CLOCKS_PER_SEC << endl;
	#endif

	ioi
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 508 KB Output is correct
3 Incorrect 2 ms 508 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 508 KB Output is correct
3 Incorrect 2 ms 508 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 508 KB Output is correct
3 Incorrect 2 ms 508 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 508 KB Output is correct
3 Incorrect 2 ms 508 KB Output isn't correct
4 Halted 0 ms 0 KB -