답안 #879623

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
879623 2023-11-27T18:42:51 Z alex_2008 Money (IZhO17_money) C++14
0 / 100
2 ms 6492 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <unordered_set>
#include <cstdlib>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <bitset>
#include <queue>
#include <unordered_map>
#include <fstream>
#include <random>
typedef unsigned long long ull;
typedef long long ll;
using namespace std;
const int N = 1e6 + 10;
int a[N], dp[N], down[N];
int f[N];
int main() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	dp[0] = 0;
	dp[1] = 1;
	down[1] = 1;
	for (int i = 2; i <= n; i++) {
		down[i] = (a[i] < a[i - 1]) ? i : down[i - 1];
	}
	set <int> ms;
	for (int i = 1; i <= n; i++) {
		auto it = ms.upper_bound(a[i]);
		if (it == ms.end()) {
			f[i] = 10000000;
		}
		else f[i] = *it;
	}
	for (int i = 2; i <= n; i++) {
		int l = down[i], r = i;
		while (l <= r) {
			int mid = (l + r) / 2;			
			bool check = true;
			int R = 10000000;
			if (f[mid] < a[i]) check = false;
			if (check) {
				dp[i] = dp[mid - 1] + 1;
				r = mid - 1;
			}
			else l = mid + 1;
		}
	}
	cout << dp[n] << "\n";
}

Compilation message

money.cpp: In function 'int main()':
money.cpp:48:8: warning: unused variable 'R' [-Wunused-variable]
   48 |    int R = 10000000;
      |        ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Incorrect 1 ms 6492 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Incorrect 1 ms 6492 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Incorrect 1 ms 6492 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Incorrect 1 ms 6492 KB Output isn't correct
3 Halted 0 ms 0 KB -