# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
39390 | 2018-01-13T12:49:57 Z | Extazy | Money (IZhO17_money) | C++14 | 0 ms | 17804 KB |
#include <bits/stdc++.h> #define endl '\n' #define left lkahgljah #define prev qiyhtouqhkjq using namespace std; const int N = 1000007; int n,a[N],from[N]; multiset < int > s; int dp[N]; int left[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]); } for(i=n;i>=1;i--) { left[a[i]]=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]) && left[a[i]]>=from[i-1]) 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
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 17804 KB | Output is correct |
2 | Correct | 0 ms | 17804 KB | Output is correct |
3 | Correct | 0 ms | 17804 KB | Output is correct |
4 | Incorrect | 0 ms | 17804 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 17804 KB | Output is correct |
2 | Correct | 0 ms | 17804 KB | Output is correct |
3 | Correct | 0 ms | 17804 KB | Output is correct |
4 | Incorrect | 0 ms | 17804 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 17804 KB | Output is correct |
2 | Correct | 0 ms | 17804 KB | Output is correct |
3 | Correct | 0 ms | 17804 KB | Output is correct |
4 | Incorrect | 0 ms | 17804 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 17804 KB | Output is correct |
2 | Correct | 0 ms | 17804 KB | Output is correct |
3 | Correct | 0 ms | 17804 KB | Output is correct |
4 | Incorrect | 0 ms | 17804 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |