Submission #879623

#TimeUsernameProblemLanguageResultExecution timeMemory
879623alex_2008Money (IZhO17_money)C++14
0 / 100
2 ms6492 KiB
#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 (stderr)

money.cpp: In function 'int main()':
money.cpp:48:8: warning: unused variable 'R' [-Wunused-variable]
   48 |    int R = 10000000;
      |        ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...