Submission #7863322


Source Code Expand

Copy
#include <iostream>
#include <string>
#include <vector>
using namespace std;

string S; int N;
long long power[200009], dp[200009], mod = 998244353;

void init() {
	power[0] = 1;
	for (int i = 1; i <= 200000; i++) power[i] = (2LL * power[i - 1]) % mod;
}

long long find_value(long long K) {
	string V1 = S.substr(0, S.size() / K);
	string V2 = V1; for (int i = 0; i < V2.size(); i++) { if (V2[i] == '0') V2[i] = '1'; else V2[i] = '0'; }

	string V = "";
	for (int i = 0; i < K; i++) {
		if (i % 2 == 0) V += V1;
		else V += V2;
	}

	long long val = 0;
	for (int i = 0; i < V1.size(); i++) {
		if (V1[i] == '1') val += power[V1.size() - 1 - i];
		val %= mod;
	}

	if (V <= S) return (val + 1LL) % mod;
	return val;
}

int main() {
	cin >> N >> S; init();

	vector<long long> R;
	for (int i = 1; i <= N; i += 2) {
		if (N%i != 0) continue;
		R.push_back(i);
	}

	for (int i = (int)R.size() - 1; i >= 0; i--) {
		dp[i] = find_value(R[i]);
		for (int j = i + 1; j < (int)R.size(); j++) {
			if (R[j] % R[i] == 0) { dp[i] -= dp[j]; dp[i] += mod; dp[i] %= mod; }
		}
	}

	long long ans = 0;
	for (int i = 0; i < R.size(); i++) {
		long long c1 = ((2LL * N) / R[i]);
		long long c2 = dp[i];
		ans += c1 * c2;
		ans %= mod;
	}
	cout << ans << endl;
	return 0;
}

Submission Info

Submission Time
Task C - Division by Two with Something
User E869120
Language C++14 (GCC 5.4.1)
Score 800
Code Size 1312 Byte
Status AC
Exec Time 31 ms
Memory 2660 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 800 / 800
Status
AC × 3
AC × 49
Set Name Test Cases
Sample s1.txt, s2.txt, s3.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt, 40.txt, 41.txt, 42.txt, 43.txt, 44.txt, 45.txt, 46.txt, s1.txt, s2.txt, s3.txt
Case Name Status Exec Time Memory
01.txt AC 23 ms 2572 KB
02.txt AC 16 ms 2616 KB
03.txt AC 14 ms 2468 KB
04.txt AC 28 ms 2660 KB
05.txt AC 18 ms 2540 KB
06.txt AC 19 ms 2440 KB
07.txt AC 15 ms 2440 KB
08.txt AC 13 ms 2308 KB
09.txt AC 16 ms 2628 KB
10.txt AC 22 ms 2412 KB
11.txt AC 25 ms 2572 KB
12.txt AC 17 ms 2616 KB
13.txt AC 15 ms 2468 KB
14.txt AC 31 ms 2660 KB
15.txt AC 19 ms 2540 KB
16.txt AC 21 ms 2440 KB
17.txt AC 16 ms 2440 KB
18.txt AC 14 ms 2308 KB
19.txt AC 17 ms 2628 KB
20.txt AC 24 ms 2412 KB
21.txt AC 22 ms 2572 KB
22.txt AC 16 ms 2616 KB
23.txt AC 14 ms 2468 KB
24.txt AC 28 ms 2660 KB
25.txt AC 18 ms 2540 KB
26.txt AC 19 ms 2440 KB
27.txt AC 14 ms 2440 KB
28.txt AC 13 ms 2308 KB
29.txt AC 16 ms 2628 KB
30.txt AC 23 ms 2392 KB
31.txt AC 23 ms 2572 KB
32.txt AC 16 ms 2616 KB
33.txt AC 14 ms 2468 KB
34.txt AC 28 ms 2660 KB
35.txt AC 18 ms 2540 KB
36.txt AC 19 ms 2440 KB
37.txt AC 14 ms 2440 KB
38.txt AC 13 ms 2308 KB
39.txt AC 16 ms 2628 KB
40.txt AC 23 ms 2392 KB
41.txt AC 22 ms 2572 KB
42.txt AC 15 ms 2616 KB
43.txt AC 5 ms 1792 KB
44.txt AC 5 ms 1792 KB
45.txt AC 5 ms 1792 KB
46.txt AC 5 ms 1792 KB
s1.txt AC 5 ms 1792 KB
s2.txt AC 5 ms 1792 KB
s3.txt AC 5 ms 1792 KB