Submission #398959

#TimeUsernameProblemLanguageResultExecution timeMemory
398959faresbasbsSequence (BOI14_sequence)C++14
67 / 100
1088 ms10632 KiB
#include <bits/stdc++.h> using namespace std; long long mini = 1000000000000000000; bool ok[1000001][10],num[10]; int n,arr[100001]; int func(int a , int b){ while(a){ if(a%10 == b){ return true; } a /= 10; } return false; } bool ok2(int val){ for(int i = 0 ; i < n ; i += 1){ if(!func(val+i,arr[i])){ return 0; } } return 1; } int main(){ for(int i = 1 ; i <= 1000000 ; i += 1){ int j = i; while(j){ ok[i][j%10] = 1; j /= 10; } } cin >> n; set<int> st; for(int i = 0 ; i < n ; i += 1){ cin >> arr[i]; st.insert(arr[i]); } if(st.size() == 1){ int val = max(arr[0],1); while(true){ if(arr[0] == 9){ int v2 = 0 , vv = val; while(vv){ v2 = (10*v2+8); vv /= 10; } v2 += 1; if(ok2(v2)){ cout << v2 << endl; return 0; } } if(ok2(val)){ cout << val << endl; return 0; } val *= 10; } } for(int i = 1 ; i <= 100000 ; i += 1){ int k = 1; for(int j = 0 ; j < n ; j += 1){ if(!ok[i+j][arr[j]]){ k = 0; break; } } if(k){ cout << i << endl; return 0; } } for(int i = 1 ; i <= 100000 ; i += 1){ memset(num,0,sizeof num); for(int j = 0 ; j < n ; j += 1){ if(!ok[i+j][arr[j]]){ num[arr[j]] = 1; } } vector<int> v,v2; for(int j = 0 ; j < 10 ; j += 1){ if(num[j]){ v.push_back(j); } } sort(v.begin(),v.end()); if(v.size() == 1 && v[0] == 0){ continue; } int k = i; for(int j = 0 ; j < 5 ; j += 1){ v2.push_back(k%10); k /= 10; } reverse(v2.begin(),v2.end()); for(int j : v2){ v.push_back(j); } if(v[0] == 0){ swap(v[0],v[1]); } long long val = 0; for(int j : v){ val = (10*val+j); } mini = min(mini,val); } cout << mini << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...