QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#789299#9745. 递增序列ValenciaTravis#WA 1ms3564kbC++201.8kb2024-11-27 19:49:272024-11-27 19:49:29

Judging History

你现在查看的是最新测评结果

  • [2024-11-27 19:49:29]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3564kb
  • [2024-11-27 19:49:27]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define MAXN 200005
#define ll long long
#define int long long

ll n, k, a[MAXN], dp[35];
bool b[35][2];

ll dfs(int pos, bool lim) {
    if(pos == -1) return 1;
    if(!lim && dp[pos] != -1) return dp[pos];
    ll ret = 0;
    int res = lim ? ((k >> pos) & 1) : 1;
    for(int i=0;i<=res;i++) {
        if(!b[pos][i]) continue;
        ret += dfs(pos-1, lim && (i == res));
    }
    if(!lim) dp[pos] = ret;
    return ret;
}

void solve(int l, int r, int t) {
    if(t == -1) return;
    // if(t <= 5) printf("solve(%d, %d, %d)\n", l, r, t);
    int cnt[2] = {0, 0};
    for(int i=l;i<=r;i++) {
        cnt[(a[i] >> t) & 1]++;
    }
    if(cnt[0] == 0 || cnt[1] == 0) {
        solve(l, r, t-1);
    }else {
        int tp = (a[l] >> t) & 1;
        bool flag = true;
        for(int i=l;i<l+cnt[tp];i++) flag &= ((a[i] >> t) & 1) == tp;
        if(!flag) b[t][0] = b[t][1] = false;
        else {
            b[t][!tp] = false;
            solve(l, l+cnt[tp]-1, t-1);
            solve(l+cnt[tp], r, t-1);
        }
    }
}

void work() {
    cin>>n>>k;
    for(int i=1;i<=n;i++) cin>>a[i];
    solve(1, n, 59);
    bool flag = false;
    for(int i=0;i<60;i++) if(!b[i][0] && !b[i][1]) flag = true;
    // for(int i=0;i<60;i++) {
    //     printf("b[%d] = %d, %d\n", i, (int)b[i][0], (int)b[i][1]);
    // }
    if(!flag) cout << dfs(59, 1) << '\n';
    else cout << 0 << '\n';
}
void clear() {
    for(int i=0;i<60;i++) b[i][0] = b[i][1] = true, dp[i] = -1;
}

signed main() {
    ios::sync_with_stdio(false), cin.tie(0);
    memset(dp, -1, sizeof(dp));
    for(int i=0;i<60;i++) b[i][0] = b[i][1] = true;
    int t;
    cin>>t;
    while(t--) work(), clear();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3564kb

input:

1
4 17
3 2 5 16

output:

144680345676153346

result:

wrong answer 1st lines differ - expected: '4', found: '144680345676153346'