Submission #1155703

#TimeUsernameProblemLanguageResultExecution timeMemory
1155703eudhsyfRound words (IZhO13_rowords)C++20
8 / 100
1 ms396 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define fi first
#define se second
#define pii pair<int, int>
#define pb push_back
#define eb emplace_back
#define task "file"
const int nmax = 1e5 + 5;
pii dp[(1 << 10) + 5][(1 << 10) + 5][25];
int a[nmax], b[nmax], pre[nmax], ma, pos, n;
signed main ()
{
    if(fopen(task".inp", "r"))
    {
        freopen(task".inp", "r", stdin);
        freopen(task".out", "w", stdout);
    }
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    for (int i = 1; i <= n; i++) {
        cin >> b[i];
    }
    for (int i = 1; i <= n; i++) {
        int l = (a[i] >> 10);
        int r = a[i] % (1 << 10);
        int lbs = 1;
        for (int mask = 0; mask < (1 << 10); mask ++) {
            int x = __builtin_popcount(l & mask);
            int need = b[i] - x;
            if(need < 0 || need > 10) {
                continue;
            }
            if(dp[mask][r][need].fi + 1 > lbs) {
                lbs = dp[mask][r][need].fi + 1;
                pre[i] = dp[mask][r][need].se;
            }
        }
        if(lbs > ma) {
            pos = i;
            ma = lbs;
        }
        for (int mask = 0; mask < (1 << 10); mask ++) {
            int x = __builtin_popcount(r & mask);
            if(dp[l][mask][x].fi < lbs) {
                dp[l][mask][x].fi = lbs;
                dp[l][mask][x].se = i;
            }
        }
    }
    vector<int> ans;
    while(pos != 0) {
        ans.emplace_back(pos);
        pos = pre[pos];
    }
    cout << ma << '\n';
    reverse(ans.begin(), ans.end());
    for (auto x : ans) {
        cout << x << ' ';
    }
    return 0;
}

Compilation message (stderr)

rowords.cpp: In function 'int main()':
rowords.cpp:20:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
rowords.cpp:21:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...