# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
119154 | songc | Sequence (BOI14_sequence) | C++14 | 110 ms | 1408 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define INF 1234567890123456ll
using namespace std;
typedef long long LL;
int N;
LL f(vector<int> A, int lv){
if (lv > 15) return INF;
LL ans = INF;
bool tf = true;
for (int i=0; i<(int)A.size(); i++) if (A[i]) tf = false;
if (tf) return 0;
if (A.size() == 1){
LL ret=0;
if (A[0] == 1) return 10;
for (int i=1; i<10; i++) if (A[0] & (1<<i)){
ret = ret*10 + i;
if (A[0] & 1) ret = ret*10, A[0] ^= 1;
}
return ret;
}
for (int i=0; i<10; i++){
vector<int> B((i+A.size()+9)/10);
for (int j=0; j<(int)A.size(); j++) B[(i+j)/10] |= A[j] & ~(1<<((i+j)%10));
if (A == B) continue;
LL ret = f(B, lv+1);
if (ret == INF) continue;
if (ret == 0 && i == 0) ans = min(ans, 10ll);
else ans = min(ans, ret*10 + i);
}
return ans;
}
int main(){
scanf("%d", &N);
vector<int> A(N);
for (int i=0; i<N; i++) {
scanf("%d", &A[i]);
A[i] = 1 << A[i];
}
printf("%lld\n", f(A, 1));
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |