Submission #21872

#TimeUsernameProblemLanguageResultExecution timeMemory
21872petrpanSequence (BOI14_sequence)C++14
100 / 100
263 ms3004 KiB
#include <iostream> #include <vector> using namespace std; typedef vector<int> vii; long long n; long long back_track(vii a,int al=0) { long long m=2e18; if (a.size()==1) { if (!a[0]) return 0; long long x=0; for (int i=1;i<=9;i++) { if (a[0]&(1<<i)) x*=10,x+=i; if (x and a[0]&1) x*=10,a[0]^=1; } if (!x) x=1; if (a[0]&1) x*=10; return x; } for (int i=0;i<=9-al;i++) { vii b(1,0); int cur=i,z=0; for (int j=0;j<a.size();j++) { if (cur==10) b.push_back(0),cur=0; int tp=a[j]; if (a[j]&1 and cur==0) z=1; if (tp&(1<<cur)) tp^=1<<cur; b.back()|=tp; cur++; } long long tp=back_track(b,(a.size()<=2 and i==9))*10+i; if (!tp and z) tp=10; m=min(m,tp); } return m; } int main() { //freopen("input.txt","r",stdin); cin >> n; vii x(0); for (int i=1;i<=n;i++) { int d; cin >> d; x.push_back(1<<d); } cout << back_track(x); }

Compilation message (stderr)

sequence.cpp: In function 'long long int back_track(vii, int)':
sequence.cpp:30:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int j=0;j<a.size();j++)
                 ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...