답안 #91345

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
91345 2018-12-27T08:03:06 Z Atashka01 Money (IZhO17_money) C++11
0 / 100
4 ms 4376 KB
//Euzibillahiminesseytanirracim Bismillahirrahmanirrahim

/*
ID:
TASK:
LANG: C++
*/

#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define ff first
#define ss second
#define mp make_pair
#define PII pair<int,int>
#define inf 1000000001
using namespace std;

const int N = 1000006;

int k[N], a[N] , n, ans, r ;

void f(int x,int y){
	
	int z = x;
	
	while(x != y){
		
		if(k[x] == -1) break;
		
		x = x + k[x];
		
		x++;
		
	}
	
	if(x != y){
		
		k[y] = r - y;
		
		r = z - 1;
		
		ans++;
		
	}
	
}

int main()
{
	
	cin>>n;
	for(int i=1;i<=n;i++){
		
		cin>>a[i];
		
	}
	
	memset(k , -1 , sizeof(k));
	
	r = a[n];
	
	for(int i=n;i>1;i--){
		
		if(a[i] < a[i - 1]){
		
			ans++;
			
			k[a[i]] = r - a[i];
			
			r = a[i - 1];
			
		}
		else{
			
			if( a[i] != a[i - 1] + 1 ) f( a[i - 1] + 1 , a[i] );
			
		}
		
	}
	
	cout<<ans + 1;
	
}

/*
8
1 8 2 3 6 7 4 5
6
3 6 4 5 1 2
8
1 2 5 3 4 6 7 8
_________oBBBBB8o   oBBBBBBB8
_____o8BBBBBBBBBBB  BBBBBBBBB8        o88o
___o8BBBBBB**8BBBB  BBBBBBBBBB     oBBBBBBBo
__oBBBBBBB*   ***   BBBBBBBBBB     BBBBBBBBBBo
_8BBBBBBBBBBooooo   *BBBBBBB8      *BB* 8BBBBBBo
_8BBBBBBBBBBBBBBBB8ooBBBBBBB8           8BBBBBBB8
__*BBBBBBBBBBBBBBBBBBBBBBBBBB8 o88BB88BBBBBBBBBBBB
____*BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB8
______**8BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB*
___________*BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB8*
____________*BBBBBBBBBBBBBBBBBBBBBBBB8888**
_____________BBBBBBBBBBBBBBBBBBBBBBB*
_____________*BBBBBBBBBBBBBBBBBBBBB*
______________*BBBBBBBBBBBBBBBBBB8
_______________*BBBBBBBBBBBBBBBB*
________________8BBBBBBBBBBBBBBB8
_________________8BBBBBBBBBBBBBBBo
__________________BBBBBBBBBBBBBBB8
__________________BBBBBBBBBBBBBBBB
__________________8BBBBBBBBBBBBBBB8
__________________*BBBBBBBBBBBBBBBB
__________________8BBBBBBBBBBBBBBBB8
_________________oBBBBBBBBBBBBBBBBBB
________________oBBBBBBBBBBBBBBBBBBB
________________BBBBBBBBBBBBBBBBBBBB
_______________8BBBBBBBBBBBBBBBBBBB8
______________oBBBBBBBBB88BBBBBBBBB8
______________8BBBBBBBBB*8BBBBBBBBB*
______________BBBBBBBBB* BBBBBBBBB8
______________BBBBBBBB8 oBBBBBBBBB*
______________8BBBBBBB  oBBBBBBBB*
______________BBBBBBB*  8BBBBBBB*
_____________8BBBBBB*   BBBBBBB*
____________8BBBBBB8   oBBBBBB8
___________8BBBBBB8    8BBBBBB*
__________oBBBBBB8    BBBBBBB8
__________BBBBBBB8   BBBBBBBB*
_________oBBBBBBB8   BBBBBBBB
_________8BBBBBB8    BBBBBBB*
_________BBBBBB*     8BBBBB*
________oBBBB8       BBBBB*
________oBBB8        BBBB*
________BBBB8       8BBBBo
_______8BBBB*      oBBBBBBo
______8BBBB*       *BBBBBBBB8o
______BBBBB*            *88BBBo
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4216 KB Output is correct
2 Correct 4 ms 4216 KB Output is correct
3 Correct 4 ms 4248 KB Output is correct
4 Correct 4 ms 4376 KB Output is correct
5 Correct 4 ms 4376 KB Output is correct
6 Correct 4 ms 4376 KB Output is correct
7 Incorrect 4 ms 4376 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4216 KB Output is correct
2 Correct 4 ms 4216 KB Output is correct
3 Correct 4 ms 4248 KB Output is correct
4 Correct 4 ms 4376 KB Output is correct
5 Correct 4 ms 4376 KB Output is correct
6 Correct 4 ms 4376 KB Output is correct
7 Incorrect 4 ms 4376 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4216 KB Output is correct
2 Correct 4 ms 4216 KB Output is correct
3 Correct 4 ms 4248 KB Output is correct
4 Correct 4 ms 4376 KB Output is correct
5 Correct 4 ms 4376 KB Output is correct
6 Correct 4 ms 4376 KB Output is correct
7 Incorrect 4 ms 4376 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4216 KB Output is correct
2 Correct 4 ms 4216 KB Output is correct
3 Correct 4 ms 4248 KB Output is correct
4 Correct 4 ms 4376 KB Output is correct
5 Correct 4 ms 4376 KB Output is correct
6 Correct 4 ms 4376 KB Output is correct
7 Incorrect 4 ms 4376 KB Output isn't correct
8 Halted 0 ms 0 KB -