Submission #224784

#TimeUsernameProblemLanguageResultExecution timeMemory
224784AbelyanLongest beautiful sequence (IZhO17_subsequence)C++14
0 / 100
566 ms65656 KiB
#include <iostream> #include <algorithm> #include <vector> #include <cassert> using namespace std; const int N = 1e5 + 6,MSK=1030; int a[N],k[N]; int dp[MSK][22][MSK], cnt[MSK], mx[N], nax[N],ind[MSK][22][MSK]; int count(int k){ int ans = 0; for (int i = 0; i < 10; i++){ if ((1 << i)&k)ans++; } return ans; } int main(){ ios_base::sync_with_stdio(false); freopen("subsequence.in","r",stdin); freopen("subsequence.out","w",stdout); int n; cin >> n; for (int i = 0; i < 1024; i++){ cnt[i] = count(i); } for (int i = 0; i < n; i++){ cin >> a[i]; nax[i] = -1; } //assert(n == 4 && a[0] == 1 && a[1] == 2 && a[2] == 3 && a[3] == 4); int ans=0, ansind; for (int i = 0; i < n; i++){ cin >> k[i]; int fr = a[i] / 1024; int sc = a[i] % 1024; mx[i] = 1; for (int ms = 0; ms < 1024; ms++){ //mx[i] = max(mx[i], dp[fr][k[i] - cnt[sc&ms]][ms]); if (k[i]<cnt[sc&ms])continue; int arj=dp[fr][k[i] - cnt[sc&ms]][ms]; //cout<<dp[fr][k[i] - cnt[sc&ms]][ms]<<endl; if (mx[i] < arj+1){ nax[i] = ind[fr][k[i] - cnt[sc&ms]][ms]; mx[i] = arj+1; } } for (int ms = 0; ms < 1024; ms++){ if (mx[i]>dp[ms][cnt[ms&fr]][sc]){ ind[ms][cnt[ms&fr]][sc] = i; dp[ms][cnt[ms&fr]][sc] = mx[i]; } } //cout<<mx[i]<<endl; if (mx[i] > ans){ ans = mx[i]; ansind = i; } } //assert(ans == 4); cout << ans<< endl; int tv = ansind; vector<int> v; while (tv != -1){ v.push_back(tv + 1); tv = nax[tv]; } reverse(v.begin(), v.end()); for (int i = 0; i < v.size(); i++){ if (i == v.size() - 1){ cout << v[i]; } else cout << v[i] << " "; } cout << endl; return 0; }

Compilation message (stderr)

subsequence.cpp: In function 'int main()':
subsequence.cpp:71:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < v.size(); i++){
                  ~~^~~~~~~~~~
subsequence.cpp:72:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (i == v.size() - 1){
       ~~^~~~~~~~~~~~~~~
subsequence.cpp:21:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
  freopen("subsequence.in","r",stdin);
  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
subsequence.cpp:22:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
  freopen("subsequence.out","w",stdout);
  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
subsequence.cpp:67:18: warning: 'ansind' may be used uninitialized in this function [-Wmaybe-uninitialized]
   v.push_back(tv + 1);
               ~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...