Submission #7874023


Source Code Expand

Copy
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
#define ll long long
#define ld long double
using namespace std;

ll mod=998244353;
int N;
string X;

ll calc(int num){
    int cyc=N/num;
    string g=X.substr(0, cyc), h;
    ll res=0, now=1;
    for(int i=cyc-1; i>=0; --i){
        if(g[i]=='1') res=(res+now)%mod;
        now=(now*2)%mod;
    }
    if(num==1){
        res=(res+1)%mod;
        return res;
    }
    for(int i=0; i<cyc; ++i){
        if(g[i]=='0') h += '1';
        else h += '0';
    }
    for(int i=1; i<num; ++i){
        string subs=X.substr(i*cyc, cyc);
        if(i%2==1){
            if(h!=subs){
                if(h<subs) res=(res+1)%mod;
                break;
            }
        }else{
            if(g!=subs){
                if(g<subs) res=(res+1)%mod;
                break;
            }
            if(i+1==num) res=(res+1)%mod;
        }
    }
    return res;
}

int main() {
	cin >> N >> X;
	vector<int> odd_div, corr;
	for(int i=1; i<=N; i += 2){
	    if(N%i==0){
	        odd_div.push_back(i);
	        corr.push_back(N/i);
	    }
	}
	vector<ll> benz(odd_div.size(), 0);
	for(int i=odd_div.size()-1; i>=0; --i){
	    benz[i]=calc(odd_div[i]);
	    for(int j=i+1; j<odd_div.size(); ++j){
	        if(odd_div[j]%odd_div[i]==0){
	            benz[i]=(benz[i]+mod-benz[j])%mod;
	        }
	    }
	}
	ll ans=0;
	for(int i=0; i<benz.size(); ++i){
	    ans=(ans+(benz[i]*2*corr[i])%mod)%mod;
	}
	cout << ans << endl;
	return 0;
}

Submission Info

Submission Time
Task C - Division by Two with Something
User ward1302
Language C++14 (GCC 5.4.1)
Score 800
Code Size 1690 Byte
Status AC
Exec Time 29 ms
Memory 784 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 17 ms 784 KB
02.txt AC 13 ms 756 KB
03.txt AC 10 ms 644 KB
04.txt AC 19 ms 760 KB
05.txt AC 13 ms 716 KB
06.txt AC 13 ms 640 KB
07.txt AC 10 ms 644 KB
08.txt AC 9 ms 512 KB
09.txt AC 12 ms 772 KB
10.txt AC 13 ms 640 KB
11.txt AC 17 ms 656 KB
12.txt AC 13 ms 756 KB
13.txt AC 10 ms 644 KB
14.txt AC 19 ms 756 KB
15.txt AC 13 ms 716 KB
16.txt AC 13 ms 640 KB
17.txt AC 10 ms 644 KB
18.txt AC 9 ms 512 KB
19.txt AC 12 ms 772 KB
20.txt AC 13 ms 640 KB
21.txt AC 15 ms 656 KB
22.txt AC 12 ms 756 KB
23.txt AC 10 ms 644 KB
24.txt AC 17 ms 760 KB
25.txt AC 12 ms 716 KB
26.txt AC 14 ms 640 KB
27.txt AC 11 ms 644 KB
28.txt AC 8 ms 512 KB
29.txt AC 12 ms 772 KB
30.txt AC 29 ms 640 KB
31.txt AC 15 ms 784 KB
32.txt AC 12 ms 756 KB
33.txt AC 9 ms 644 KB
34.txt AC 18 ms 756 KB
35.txt AC 25 ms 716 KB
36.txt AC 11 ms 640 KB
37.txt AC 11 ms 644 KB
38.txt AC 8 ms 512 KB
39.txt AC 12 ms 772 KB
40.txt AC 29 ms 640 KB
41.txt AC 14 ms 656 KB
42.txt AC 12 ms 756 KB
43.txt AC 1 ms 256 KB
44.txt AC 1 ms 256 KB
45.txt AC 1 ms 256 KB
46.txt AC 1 ms 256 KB
s1.txt AC 1 ms 256 KB
s2.txt AC 1 ms 256 KB
s3.txt AC 1 ms 256 KB