Submission #15959

#TimeUsernameProblemLanguageResultExecution timeMemory
15959myungwooSequence (BOI14_sequence)C++14
9 / 100
1000 ms11204 KiB
#include <bits/stdc++.h> using namespace std; #define MAXN 100005 #define pb push_back #define sz(v) ((int)(v).size()) #define all(v) (v).begin(), (v).end() typedef long long lld; int N; int A[MAXN]; lld ans = 12345678900000; void dfs(lld n, lld v, vector<int> &arr) { if (arr.empty() && ans > v){ ans = v; return; } if (v+n >= ans) return; vector <int> nxt[10]; for (int i=0;i<10;i++){ lld m = v + i*n; for (int p: arr){ lld now = m + p; bool sw = 0; for (lld tmp=now;tmp;tmp/=10) if (tmp%10 == A[p]){ sw = 1; break; } if (!sw) nxt[i].pb(p); } } vector <int> tmp; for (int i=0;i<10;i++) tmp.pb(i); sort(all(tmp), [nxt](const int &a, const int &b){ return sz(nxt[a]) < sz(nxt[b]); }); for (int d: tmp){ dfs(n*10, v + d*n, nxt[d]); } } int main() { scanf("%d", &N); for (int i=0;i<N;i++) scanf("%d", A+i); vector <int> tmp; for (int i=0;i<N;i++) tmp.pb(i); dfs(1, 0, tmp); printf("%lld\n", ans); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...