Submission #243971

#TimeUsernameProblemLanguageResultExecution timeMemory
243971TadijaSebezSequence (BOI14_sequence)C++11
100 / 100
241 ms1520 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back ll Solve(vector<int> v,int sub=0){ if(v.size()==1){ if(v[0]==0)return 0; ll ans=0; for(int i=1;i<=9;i++){ if(v[0]>>i&1){ ans=ans*10+i; if(v[0]&1)ans*=10,v[0]--; } } if(v[0]&1)ans=10; return ans; }else{ ll ans=1e18; for(int las=0;las<=9-sub;las++){ vector<int> tmp; int all=0,zr=0; for(int i=0,j=las;i<v.size();i++,j=(j+1)%10){ if(i&&!j)tmp.pb(all),all=0; if(!j&&(v[i]&1))zr=1; all|=v[i]&(~(1<<j)); } tmp.pb(all); ll now=Solve(tmp,v.size()<=2&&las==9)*10+las; if(zr&&!now)now=10; ans=min(ans,now); } return ans; } } int main(){ int n;scanf("%i",&n); vector<int> v; for(int i=1,j;i<=n;i++)scanf("%i",&j),v.pb(1<<j); printf("%lld\n",Solve(v)); return 0; }

Compilation message (stderr)

sequence.cpp: In function 'long long int Solve(std::vector<int>, int)':
sequence.cpp:22:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int i=0,j=las;i<v.size();i++,j=(j+1)%10){
                      ~^~~~~~~~~
sequence.cpp: In function 'int main()':
sequence.cpp:36:13: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  int n;scanf("%i",&n);
        ~~~~~^~~~~~~~~
sequence.cpp:38:39: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1,j;i<=n;i++)scanf("%i",&j),v.pb(1<<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...