Submission #299680

#TimeUsernameProblemLanguageResultExecution timeMemory
299680BeanZLongest beautiful sequence (IZhO17_subsequence)C++14
23 / 100
103 ms18936 KiB
// I_LOVE_LPL #include <bits/stdc++.h> using namespace std; #define ll long long #define endl '\n' const int N = 1e5 + 5; ll a[N], k[N], dp[N], par[5005][5005]; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); if (fopen("A.inp", "r")){ freopen("test.inp", "r", stdin); freopen("test.ans", "w", stdout); } ll n; cin >> n; ll ans = 0; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) cin >> k[i]; for (int i = 1; i <= n; i++) dp[i] = 1; for (int i = 1; i <= n; i++){ for (int j = 1; j < i; j++){ ll x = a[i] & a[j]; if (__builtin_popcount(x) == k[i]){ dp[i] = max(dp[i], dp[j] + 1); par[i][dp[j] + 1] = j; } } ans = max(ans, dp[i]); } cout << ans << endl; ll cur = -1; for (int i = 1; i <= n; i++) if (dp[i] == ans && cur == -1) cur = i; vector<ll> mem; mem.push_back(cur); while (ans > 1){ cur = par[cur][ans]; mem.push_back(cur); ans--; } reverse(mem.begin(), mem.end()); for (auto j : mem) cout << j << " "; } /* 5 5 3 5 3 5 10 1 20 1 20 4 1 2 3 4 10 0 1 0 2 8 9 20 0 */

Compilation message (stderr)

subsequence.cpp: In function 'int main()':
subsequence.cpp:14:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   14 |                 freopen("test.inp", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
subsequence.cpp:15:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   15 |                 freopen("test.ans", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...