답안 #678911

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
678911 2023-01-06T22:17:06 Z YENGOYAN Money (IZhO17_money) C++17
0 / 100
3 ms 4180 KB
/*
	//\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\\
	\\                                    //
	//  271828___182845__904523__53602__  \\
	\\  87___47____13______52____66__24_  //
	//  97___75____72______47____09___36  \\
	\\  999595_____74______96____69___67  //
	//  62___77____24______07____66__30_  \\
	\\  35___35____47______59____45713__  //
	//                                    \\
	\\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\//
												*/

#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_map>
#include <cmath>
#include <climits>
#include <algorithm>
#include <random>
#include <queue>
#include <deque>
#include <iomanip>
#include <string>
#include <tuple>
#include <bitset>
#include <chrono>
#include <ctime>
#include <fstream>
#include <stack>
#include <cstdio>

using namespace std;
using ll = long long;
const int N = 3e5 + 5;
const ll mod = 1e9 + 7, inf = 1e12;

void solve() {
	// start time : 01:42
	int n; cin >> n;
	vector<int> v(n);
	for (int i = 0; i < n; ++i) cin >> v[i];
	vector<int> t = v;
	sort(t.begin(), t.end());
	vector<int> nxt(1e6 + 5, -1);
	map<int, int> cnt;
	++cnt[t[0]];
	for (int i = 1; i < n; ++i) {
		nxt[t[i - 1]] = t[i];
		++cnt[t[i]];
	}
	vector<int> dp(n + 1);
	dp[1] = 1;
	nxt[t.back()] = -1;
	map<int, bool> mp;
	int c = 1;
	for (int i = 2; i <= n; ++i) {
		if (v[i - 1] == nxt[v[i - 2]] && !mp[v[i - 2]]) {
			if (c == cnt[v[i - 2]]) dp[i] = dp[i - 1];
			else dp[i] = dp[i - 1] + 1;
			c = 1;
			mp[v[i - 2]] = 1;
		}
		else {
			if (v[i - 1] == v[i - 2]) {
				++c;
				dp[i] = dp[i - 1];
			}
			else {
				c = 1;
				dp[i] = dp[i - 1] + 1;
			}
		}
	}
	int cc = 1;
	int lst = -1;
	for (int i = 1; i < n; ++i) {
		if (v[i] < v[i - 1]) {
			lst = v[i - 1];
			++cc;
		}
		else if (v[i] > lst && lst != -1) {
			lst = v[i];
			++cc;
		}
	}
	cout << cc << "\n";
	return;
	cout << dp[n];
	// 3 6 3 6
	// dp[i] = {min_seg_cnt, last_segment_length};
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	//int t; cin >> t; 
	//while(t--) 
		solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4180 KB Output is correct
2 Incorrect 3 ms 4164 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4180 KB Output is correct
2 Incorrect 3 ms 4164 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4180 KB Output is correct
2 Incorrect 3 ms 4164 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4180 KB Output is correct
2 Incorrect 3 ms 4164 KB Output isn't correct
3 Halted 0 ms 0 KB -