QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#751962#9745. 递增序列clear_teaWA 120ms3608kbC++201.8kb2024-11-15 21:25:302024-11-15 21:25:31

Judging History

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

  • [2024-11-15 21:25:31]
  • 评测
  • 测评结果:WA
  • 用时:120ms
  • 内存:3608kb
  • [2024-11-15 21:25:30]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
#define int long long

int ans;
vector<int> pos(70, -1);

void dfs(int k, int p) {
    if (p == -1) {
        ans++;
        return;
    }

    if (((k >> p) & 1) && pos[p] == -1) { //这位是1,那么可以选0,下一位开始任选
        int t = 1;
        for (int i = p - 1; i >= 0; i--) {
            if (pos[i] == -1) {
                t *= 2;
            }
        }
        ans += t;
    } else if (((k >> p) & 1) && pos[p] == 0) {
        int t = 1;
        for (int i = p - 1; i >= 0; i--) {
            if (pos[i] == -1) {
                t *= 2;
            }
        }
        ans += t;
        return;
    } else if (!((k >> p) & 1) && pos[p] == 1) {
        return;
    }
    // 这位是0,没得选,往下
    dfs(k, p - 1);
}

void solve() {
    int n, k;
    cin >> n >> k;
    ans = 0;
    vector<int> a(n + 1);
    for (int i = 0; i < 70; i++) {
        pos[i] = -1;
    }
    for (int i = 1; i <= n; i++) cin >> a[i];

    // 相邻判断某位上是否一定为某数,如果冲突直接输出0
    // 最后考虑k的范围

    for (int i = 2; i <= n; i++) {
        for (int j = 59; j >= 0; j--) {
            if (((a[i] >> j) & 1) != ((a[i - 1] >> j) & 1)) {
                if (pos[j] == -1) {
                    pos[j] = ((a[i - 1] >> j) & 1);
                    break;
                } else if (pos[j] != ((a[i - 1] >> j) & 1)) {
                    cout << "0\n";
                    return;
                }
            }
        }
    }

    dfs(k, 59);

    cout << ans << '\n';
}

signed main() {
#ifdef ONLINE_JUDGE
#else
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    int t = 1;
    cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3604kb

input:

1
4 17
3 2 5 16

output:

4

result:

ok single line: '4'

Test #2:

score: -100
Wrong Answer
time: 120ms
memory: 3608kb

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
0
114457959388827198
0
0
0
91540211282631659
0
694703231769895640
144115188075855872
0
0
0
0
432345564227567616
65333152962117911
753346372609875093
0
0
364589864498708058
0
...

result:

wrong answer 16th lines differ - expected: '36028797018963968', found: '0'