QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#378131 | #1944. Circle of Friends | ohiostatescarlet | WA | 180ms | 57484kb | C++17 | 1.8kb | 2024-04-06 06:02:56 | 2024-04-06 06:02:57 |
Judging History
answer
#include"bits/stdc++.h"
using namespace std;
#define L long long
L MOD = 998244353;
void solve(vector<L>&nums, vector<L>&dp) {
int n = nums.size();
vector<vector<L>> andR(n);
for (int i = 0; i < n; i++) {
andR[i].push_back(nums[i]);
int j = 0;
int p = 1;
while (i-2*p+1 >= 0) {
andR[i].push_back(andR[i][j] & andR[i-p][j]);
j++;
p <<= 1;
}
}
dp.assign(n, 0);
dp[0] = 1;
vector<L> dpp(n+2, 0);
dp[0] = dpp[1] = 1;
dpp[2] = 2;
for (int i = 1; i < n; i++) {
L curr = nums[i];
int p = i;
int j = andR[i].size()-1;
while (j >= 0 && p > 0) {
if (curr & andR[p-1][j]) {
curr &= andR[p-1][j];
p -= (1 << j);
j = min(j, (int)andR[p].size());
}
j--;
}
// cout << i << " -> " << p << "\n";
dp[i] = (dpp[i+1] - dpp[p] + MOD) % MOD;
dpp[i+2] = (dp[i] + dpp[i+1]) % MOD;
}
// for (L v : dp) {
// cout << v << " ";
// }
// cout << '\n';
}
// g++ -std=c++17 -O2 -DLOCAL -o a a.cpp
int main() {
int n;
cin >> n;
vector<L> nums(n,0);
L all = -1;
for (int i = 0; i < n; i++) {
cin >> nums[i];
all &= nums[i];
}
vector<L> dp;
solve(nums, dp);
L res = dp[n-1];
if (all) {
cout << ((2 * res) % MOD - n + MOD) % MOD << '\n';
return 0;
}
while (nums.size()>2&&nums[0]) {
// cout << res << '\n';
while (nums.size()>2 && (nums.back()&nums[0])==nums[0]) {
nums.pop_back();
n--;
res = (res + dp[n-1]) % MOD;
}
nums[0] = nums[0]&nums.back();
nums.pop_back();
n--;
if (nums[0]) {
solve(nums, dp);
res = (res + dp[n-1]) % MOD;
}
}
cout << res << "\n";
}
/*
4
1 2 1 1
5
1 2 1 1 1
4
14 13 11 7
5
1 3 1 3 1
11
7 3 4 7 3 3 2 7 1 2 4
12
8 7 3 4 7 3 3 2 7 1 2 4
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3532kb
input:
1 1
output:
1
result:
ok single line: '1'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
1 1152921504606846975
output:
1
result:
ok single line: '1'
Test #3:
score: 0
Accepted
time: 73ms
memory: 57400kb
input:
200000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
output:
792053081
result:
ok single line: '792053081'
Test #4:
score: 0
Accepted
time: 135ms
memory: 57352kb
input:
200000 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606...
output:
792053081
result:
ok single line: '792053081'
Test #5:
score: -100
Wrong Answer
time: 180ms
memory: 57484kb
input:
200000 18031990763159554 108095195748368386 36029346783428610 184085739649376272 577639437895209218 72057594042191904 4508276314083330 9078671805521920 144255925580990466 432490704060547904 72059793094738017 562967269607456 26424786302976 68719476738 333275855713337352 11370333479109156 290271086772...
output:
594170968
result:
wrong answer 1st lines differ - expected: '697849429', found: '594170968'