# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
39389 | 2018-01-13T11:51:48 Z | Extazy | Money (IZhO17_money) | C++14 | 0 ms | 13896 KB |
#include <bits/stdc++.h> #define endl '\n' using namespace std; const int N = 1000007; int n,a[N],from[N]; multiset < int > s; int dp[N]; multiset < int >::iterator prev(multiset < int >::iterator it) { --it; return it; } bool are_consecutive(int v1, int v2) { if(v1>v2) return false; if(v1==v2) return true; return *prev(s.lower_bound(v2))==v1; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int i,j; scanf("%d", &n); for(i=1;i<=n;i++) { scanf("%d", &a[i]); } s.insert(a[1]); from[1]=1; for(i=2;i<=n;i++) { s.insert(a[i]); if(are_consecutive(a[i-1],a[i])) from[i]=from[i-1]; else from[i]=i; } for(i=1;i<=n;i++) { dp[i]=1000007; for(j=from[i];j<=i;j++) { dp[i]=min(dp[i],dp[j-1]+1); } } printf("%d\n", dp[n]); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 13896 KB | Output is correct |
2 | Correct | 0 ms | 13896 KB | Output is correct |
3 | Correct | 0 ms | 13896 KB | Output is correct |
4 | Correct | 0 ms | 13896 KB | Output is correct |
5 | Correct | 0 ms | 13896 KB | Output is correct |
6 | Correct | 0 ms | 13896 KB | Output is correct |
7 | Correct | 0 ms | 13896 KB | Output is correct |
8 | Correct | 0 ms | 13896 KB | Output is correct |
9 | Correct | 0 ms | 13896 KB | Output is correct |
10 | Correct | 0 ms | 13896 KB | Output is correct |
11 | Correct | 0 ms | 13896 KB | Output is correct |
12 | Incorrect | 0 ms | 13896 KB | Output isn't correct |
13 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 13896 KB | Output is correct |
2 | Correct | 0 ms | 13896 KB | Output is correct |
3 | Correct | 0 ms | 13896 KB | Output is correct |
4 | Correct | 0 ms | 13896 KB | Output is correct |
5 | Correct | 0 ms | 13896 KB | Output is correct |
6 | Correct | 0 ms | 13896 KB | Output is correct |
7 | Correct | 0 ms | 13896 KB | Output is correct |
8 | Correct | 0 ms | 13896 KB | Output is correct |
9 | Correct | 0 ms | 13896 KB | Output is correct |
10 | Correct | 0 ms | 13896 KB | Output is correct |
11 | Correct | 0 ms | 13896 KB | Output is correct |
12 | Incorrect | 0 ms | 13896 KB | Output isn't correct |
13 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 13896 KB | Output is correct |
2 | Correct | 0 ms | 13896 KB | Output is correct |
3 | Correct | 0 ms | 13896 KB | Output is correct |
4 | Correct | 0 ms | 13896 KB | Output is correct |
5 | Correct | 0 ms | 13896 KB | Output is correct |
6 | Correct | 0 ms | 13896 KB | Output is correct |
7 | Correct | 0 ms | 13896 KB | Output is correct |
8 | Correct | 0 ms | 13896 KB | Output is correct |
9 | Correct | 0 ms | 13896 KB | Output is correct |
10 | Correct | 0 ms | 13896 KB | Output is correct |
11 | Correct | 0 ms | 13896 KB | Output is correct |
12 | Incorrect | 0 ms | 13896 KB | Output isn't correct |
13 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 13896 KB | Output is correct |
2 | Correct | 0 ms | 13896 KB | Output is correct |
3 | Correct | 0 ms | 13896 KB | Output is correct |
4 | Correct | 0 ms | 13896 KB | Output is correct |
5 | Correct | 0 ms | 13896 KB | Output is correct |
6 | Correct | 0 ms | 13896 KB | Output is correct |
7 | Correct | 0 ms | 13896 KB | Output is correct |
8 | Correct | 0 ms | 13896 KB | Output is correct |
9 | Correct | 0 ms | 13896 KB | Output is correct |
10 | Correct | 0 ms | 13896 KB | Output is correct |
11 | Correct | 0 ms | 13896 KB | Output is correct |
12 | Incorrect | 0 ms | 13896 KB | Output isn't correct |
13 | Halted | 0 ms | 0 KB | - |