QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#754987#9745. 递增序列wcyQwQ#WA 44ms3728kbC++141.2kb2024-11-16 16:11:412024-11-16 16:11:43

Judging History

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

  • [2024-11-16 16:11:43]
  • 评测
  • 测评结果:WA
  • 用时:44ms
  • 内存:3728kb
  • [2024-11-16 16:11:41]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using LL = long long;

const int N = 2e5 + 10, M = 64;
LL a[N], f[M];
int d[M];

int dfs(LL k, int x, int lim) {
  if (x == -1) return 1;
  if (!lim && ~f[x]) return f[x];
  int up = !lim ? 1 : (k >> x & 1);
  LL ans = 0;
  for (int i = 0; i <= up; i++) {
    if (d[x] != -1 && i != d[x]) continue;
    (ans += dfs(k, x - 1, lim && i == up));
  }
  if (!lim) f[x] = ans;
  return ans;
} 

void solve() {
  int n;
  LL k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i];
  memset(d, -1, sizeof d);
  for (int i = 1; i < n; i++) {
    for (int j = 63; j >= 0; j--) {
      if ((a[i] >> j & 1) ^ (a[i + 1] >> j & 1)) {
        if (a[i] >> j & 1) {
          if (d[j] == 0) {
            cout << 0 << '\n';
            return;
          }
          d[j] = 1;
        }
        else {
          if (d[j] == 1) {
            cout << 0 << '\n';
            return;
          }
          d[j] = 0;
        }
        break;
      }
    }
  }
  memset(f, -1, sizeof f);
  cout << dfs(k, 63, 1) << '\n';
}

int main() {
  cin.tie(0)->sync_with_stdio(0);
  int T;
  cin >> T;
  while (T--) solve();
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

1
4 17
3 2 5 16

output:

4

result:

ok single line: '4'

Test #2:

score: -100
Wrong Answer
time: 44ms
memory: 3728kb

input:

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

output:

0
0
0
-325180481
861648846
0
1755390800
0
0
0
-1848046909
0
0
0
1528188478
0
0
0
1344953323
0
-1711938856
0
0
0
0
0
0
240976151
-734159723
0
0
-769180070
0
1530537702
0
0
0
0
0
-1837191549
0
0
0
0
-447377492
0
0
0
-426202533
700698651
0
0
0
0
118577689
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0...

result:

wrong answer 1st lines differ - expected: '288230376151711744', found: '0'