QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#765684#9745. 递增序列mhwWA 274ms3576kbC++232.4kb2024-11-20 15:00:052024-11-20 15:00:06

Judging History

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

  • [2024-11-20 15:00:06]
  • 评测
  • 测评结果:WA
  • 用时:274ms
  • 内存:3576kb
  • [2024-11-20 15:00:05]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
const i64 P = 998244353;
#define int long long

int ans0[100], ans1[100];
int dp[70][2], num[70];
int dfs(int pos, int pre, int lim)
{
    if (pos < 1) return 1;
    if (!lim && dp[pos][pre] != -1) return dp[pos][pre];
    int top = lim ? num[pos] : 1;
    int ans = 0;
    for (int i = 0; i <= top; i++)
    {
        // 计数
        if (i == 0 && ans0[pos]) ans += dfs(pos - 1, i, lim && i == top);
        else if (i == 1 && ans1[pos]) ans += dfs(pos - 1, i, lim && i == top);
    }
    if (!lim) dp[pos][pre] = ans;
    return ans;
}

int col(int x)
{
    memset(dp, -1, sizeof dp);
    memset(num, 0, sizeof num);
    int t = 0;
    while (x)
    {
        num[++t] = x % 2;
        x /= 2;
    }
    return dfs(t, 0, 1);
}

void solve() {
    i64 n, k;
    cin >> n >> k;
    vector<i64> a(n);
    memset(ans0, 0, sizeof ans0);
    memset(ans1, 0, sizeof ans1);

    for (int i = 0; i < n; i++) cin >> a[i];
    vector<int> pos;
    pos.push_back(0);
    pos.push_back(n);
    for (int x = 63; x >= 0; x--) {
        bool f0 = true, f1 = true;
        vector<int> npos;
        for (int i = 0; i < (int)pos.size() - 1; i++) {
            int l = pos[i], r = pos[i + 1];
            npos.push_back(l);
            vector<int> tmp;
            int p01 = -1, p10 = -1;
            for (int j = l; j < r; j++) {
                tmp.push_back(a[j] >> x & 1);
            }
            for (int j = 0; j < (int)tmp.size() - 1; j++) {
                if (tmp[j] == 0 && tmp[j + 1] == 1) p01 = j + 1;
                if (tmp[j] == 1 && tmp[j + 1] == 0) p10 = j + 1;
            }
            if (p01 != -1 && p10 != -1) {
                cout << 0 << '\n';
                return ;
            } else if (p01 == -1 && p10 != -1) {
                f1 = false;
                npos.push_back(l + p10);
            } else if (p10 == -1 && p01 != -1) {
                f0 = false;
                npos.push_back(l + p01);
            }
        }
        npos.push_back(n);
        if (!f0 && !f1) {
            cout << 0 << '\n';
            return ;
        }
        ans0[x + 1] = f1, ans1[x + 1] = f0;
        pos = npos;
    }
    
    cout << col(k) << '\n';
}
main() {
    ios::sync_with_stdio(0); cin.tie(0), cout.tie(0);
    int t = 1; 
    cin >> t;
    while(t--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3508kb

input:

1
4 17
3 2 5 16

output:

4

result:

ok single line: '4'

Test #2:

score: -100
Wrong Answer
time: 274ms
memory: 3576kb

input:

36156
2 732025001343805266
563399128172323734 55283226774627822
7 388099190813067712
564150557919527813 457487771983557281 332055400678110195 760833651510929158 785768483273197875 690506113272551236 463276585748519124
2 798714574862593347
426890163990834364 434764725667883272
1 414708220571820990
42...

output:

288230376151711744
0
432345564227567616
414708220571820991
716398192192370638
0
1949654914769744
0
0
0
811009189367843523
0
0
288230376151711744
114457959388827198
36028797018963968
144115188075855872
0
91540211282631659
0
694703231769895640
144115188075855872
0
0
0
0
432345564227567616
653331529621...

result:

wrong answer 14th lines differ - expected: '0', found: '288230376151711744'