제출 #758087

#제출 시각아이디문제언어결과실행 시간메모리
758087vjudge1Money (IZhO17_money)C++17
0 / 100
1 ms468 KiB
#include"bits/stdc++.h" using namespace std; #define ll long long const ll mod = 1000000007; int b[1000001]; signed main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); int n; cin >> n; int a[n]; for(int i = 0; i < n; i++) cin >> a[i]; int ans = n; for(int i = 0; i < (1 << n); i++) { b[1] = 1e6; set<int> s; s.insert(-1); bool bad = 0; int cur = 0; for(int j = 0; j < n; j++) { int l = j, r; for(int k = j; k < n; k++) { r = k; if(k - 1 >= j && a[k] < a[k - 1]) bad = 1; if(i & (1 << k)) break; } int g = *s.lower_bound(-a[j]) * -1; if(a[r] > b[g]) bad = 1; if(bad) break; b[a[r]] = b[g]; b[g] = a[l]; s.insert(-a[r]); s.insert(-g); for(int k = l; k < r; k++) { b[a[k]] = a[k + 1]; s.insert(-a[k]); } cur++; j = r; } if(!bad) ans = min(ans, cur); while(s.size()) { b[*s.begin()] = 0; s.erase(s.begin()); } } cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...