Atcoder Grand Contest 039C (inclusion and exclusion, counter DP)

// each operation corresponds to the inverse of the least significant bit is added to the most significant bit (N ~ 1 bit)
#define HAVE_STRUCT_TIMESPEC
#include <bits / STDC ++ H.>
The using namespace STD;
char S [200007];
int MI2 of [200007], NUM [200007];
const int = MOD 998 244 353;
int main () {
iOS :: sync_with_stdio (to false);
cin.tie (NULL);
cout.tie (NULL);
int n-;
CIN >> >> n-S +. 1 ;
MI2 of [0] =. 1;
for (int I =. 1; I <= n-; I ++)
MI2 of [I] = 2LL * MI2 of [I-. 1] MOD%;
for (int I =. 1; I <= n; i + = 2) if (n% i == 0) {// i take the even cause frequency obtained through the operations it is not negated, (odd-numbered stages connected end to end to operations after frequency), any n after several operations will become its negation, the equivalent of each bit down again from back to front
int frequency = n / i; // descending half the number of enumeration, ie, after the frequency operations so that it becomes negated string, the number of long length can be bound to a short number, it contains a number of frequency but after a short length of several operating frequency due to meet the proposed answers to the count, by inclusion and exclusion in the calculation when the length of the short answer Save them in a long length in the answer To
bool flag = 1;
for (int J = 1; J <= n && In Flag; J ++) {
IF (S [J] == '1') {// This is a 1, then there must be a string of length n, is divided into frequency segments, adjacent segments of each segment is negated, and the characters of the former frequency than s large
if (j <= frequency || s [j-frequency] == '1') {// Laid sentenced to 0 at the beginning of a frequency the string is over s small
NUM [Frequency] = (NUM [Frequency] + (J <= Frequency MI2 of [Frequency-J]:. 1)?)% MOD;
}
}
iF (J> Frequency && s [J] == s [ j-frequency]) // Laid sentenced to a frequency at the beginning of the string is 0 smaller than s
in Flag = 0;
}
IF (in Flag) // If the string s frequency than 0 at the beginning of a small, can +1 sentence Laid As long as not to have to find a position spaced frequency two characters are '0'
NUM [frequency] = (NUM [frequency] + 1'd) MOD%;
COUT << NUM [frequency] << "\ n-";
}
int ANS = 0;
for (int I =. 1; I <= n-; ++ I) IF (n-% I == 0 && (n-/ I) &. 1 && NUM [I]) {// ascending enumeration length
ans = (ans + 2ll * num [i] * i)% mod;// After i becomes the original string operations need to go through the inverse operation i will not transition back to the original time series
for (int j = i * 2 ; j <= n; j + = i) // inclusion and exclusion, has been taken into account the shorter length of the digital subtracting a longer length in the answer
num [j] = ( NUM [J]-NUM MOD + [I]) MOD%;
}
COUT << ANS;
return 0;
}

Guess you like

Origin www.cnblogs.com/ldudxy/p/11666957.html