제출 #15954

#제출 시각아이디문제언어결과실행 시간메모리
15954myungwooSequence (BOI14_sequence)C++14
0 / 100
1000 ms2588 KiB
#include <bits/stdc++.h> using namespace std; #define MAXN 100005 #define pb push_back 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; return; } if (v+n >= ans) return; for (int i=9;i>=0;i--){ lld m = v + n*i; if (m >= ans) continue; vector <int> nxt; 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.pb(p); } dfs(n*10, m, nxt); } } 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...