Submission #36172

#TimeUsernameProblemLanguageResultExecution timeMemory
36172UncleGrandpa925Longest beautiful sequence (IZhO17_subsequence)C++14
0 / 100
0 ms94080 KiB
/*input 4 1 2 3 4 10 0 1 0 5 5 3 5 3 5 10 1 20 1 20 */ #include <bits/stdc++.h> using namespace std; #define sp ' ' #define endl '\n' #define fi first #define se second #define mp make_pair #define N 100005 #define bit(x,y) ((x>>y)&1LL) #define na(x) (#x) << ":" << x ostream& operator << (ostream &os, vector<int>&x) { for (int i = 0; i < x.size(); i++) os << x[i] << sp; return os; } ostream& operator << (ostream &os, pair<int, int> x) { cout << x.fi << sp << x.se << sp; return os; } ostream& operator << (ostream &os, vector<pair<int, int> >&x) { for (int i = 0; i < x.size(); i++) os << x[i] << endl; return os; } int n; int a[N], b[N]; int cnt[N]; int dp[N], par[N]; int best[(1 << 10)][(1 << 10)][11]; int pbest[(1 << 10)][(1 << 10)][11]; vector<int> order; signed main() { #ifdef in1code freopen("1test.inp", "r", stdin); #endif scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i <= n; i++) scanf("%d", &b[i]); for (int i = 0; i < (1 << 20); i++) cnt[i] = __builtin_popcount(i); memset(best, 0, sizeof(best)); memset(pbest, 0, sizeof(pbest)); pair<int, int> ans = mp(1, 1); for (int i = 1; i <= n; i ++) { dp[i] = 1; int prefix = a[i] >> 10; int suffix = a[i] - (prefix << 10); for (int mask = 0; mask < (1 << 10); mask ++) { int curmask = mask & prefix; if (cnt[curmask] > b[i] || b[i] - cnt[curmask] > 10) continue; if (best[prefix][suffix][b[i] - cnt[curmask]] + 1 > dp[i]) { if (i == 4 && pbest[prefix][suffix][b[i]] == 2) { cout << "X"; } dp[i] = best[prefix][suffix][b[i] - cnt[curmask]] + 1; par[i] = pbest[prefix][suffix][b[i]]; } } if (dp[i] > ans.fi) ans = mp(dp[i], i); for (int mask = 0; mask < (1 << 10); mask ++) { if (best[prefix][mask][cnt[mask & suffix]] < dp[i]) { best[prefix][mask][cnt[mask & suffix]] = dp[i]; pbest[prefix][mask][cnt[mask & suffix]] = i; } } } while (ans.fi > 0) { order.push_back(ans.se); ans.se = par[ans.se]; ans.fi--; } reverse(order.begin(), order.end()); printf("%d\n", order.size()); for (int i = 0; i < order.size(); i++) printf("%d ", order[i]); }

Compilation message (stderr)

subsequence.cpp: In function 'std::ostream& operator<<(std::ostream&, std::vector<int>&)':
subsequence.cpp:21:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < x.size(); i++) os << x[i] << sp;
                    ^
subsequence.cpp: In function 'std::ostream& operator<<(std::ostream&, std::vector<std::pair<int, int> >&)':
subsequence.cpp:29:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < x.size(); i++) os << x[i] << endl;
                    ^
subsequence.cpp: In function 'int main()':
subsequence.cpp:79:29: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<int>::size_type {aka long unsigned int}' [-Wformat=]
  printf("%d\n", order.size());
                             ^
subsequence.cpp:80:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < order.size(); i++) printf("%d ", order[i]);
                    ^
subsequence.cpp:44:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
                 ^
subsequence.cpp:45:49: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
                                                 ^
subsequence.cpp:46:49: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
                                                 ^
subsequence.cpp:47:68: warning: iteration 100005u invokes undefined behavior [-Waggressive-loop-optimizations]
  for (int i = 0; i < (1 << 20); i++) cnt[i] = __builtin_popcount(i);
                                                                    ^
subsequence.cpp:47:20: note: containing loop
  for (int i = 0; i < (1 << 20); i++) cnt[i] = __builtin_popcount(i);
                    ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...