Submission #11690462


Source Code Expand

Copy
#include<bits/stdc++.h>

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define ull unsigned long long
#define rep(n) for(ll i = 0 ; i<n ; i++) 
#define rep2(n) for(ll j=0 ; j<n ; ++j )
#define repd(n) for(ll i = n-1 ; i>=0 ; i--)
#define MOD 1000000007
#define pii pair<ll,ll>
#define vll vector<ll>
#define ff first
#define ss second
#define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0); 
#define nl "\n"
#define INF 1e18
#define sz(a) a.size() 
#define all(a) a.begin(),a.end()
#define M 998244353
#define limit 100000000


void solve() {
	ll n, p  ; cin >> n >> p ;
	string s ; cin >> s; 
	ll arr[p]={} ;

	ll sm=0 ,cnt =0 , ten =10;
	for(ll i=n-1;i>=0;--i) {
		ll curr = (s[i]-'0')*ten;
		curr%=p;
		sm += curr;
		sm %= p;
		cnt += arr[sm] ;
		if(sm==0) ++cnt; 
		arr[sm%p]++ ;
		ten*=10; 
		ten%=p;
	}
	cout << cnt ;
}

int main() {

    fast;
	ll t=1;
	// cin>>t;
	rep(t) {
		solve() ;
	}
	return 0;
}

Submission Info

Submission Time
Task E - Divisible Substring
User Jo3kerR
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1080 Byte
Status
Exec Time 12 ms
Memory 720 KB

Judge Result

Set Name Score / Max Score Test Cases
Sample 0 / 0 s1.txt, s2.txt, s3.txt
All 0 / 500 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, s1.txt, s2.txt, s3.txt
Case Name Status Exec Time Memory
01.txt 1 ms 256 KB
02.txt 1 ms 256 KB
03.txt 1 ms 256 KB
04.txt 1 ms 256 KB
05.txt 1 ms 256 KB
06.txt 1 ms 256 KB
07.txt 1 ms 256 KB
08.txt 1 ms 256 KB
09.txt 1 ms 256 KB
10.txt 1 ms 256 KB
11.txt 1 ms 256 KB
12.txt 1 ms 256 KB
13.txt 1 ms 256 KB
14.txt 1 ms 256 KB
15.txt 1 ms 256 KB
16.txt 1 ms 256 KB
17.txt 1 ms 384 KB
18.txt 1 ms 256 KB
19.txt 1 ms 384 KB
20.txt 1 ms 256 KB
21.txt 11 ms 720 KB
22.txt 11 ms 720 KB
23.txt 11 ms 720 KB
24.txt 11 ms 720 KB
25.txt 11 ms 720 KB
26.txt 11 ms 720 KB
27.txt 11 ms 720 KB
28.txt 11 ms 720 KB
29.txt 11 ms 720 KB
30.txt 11 ms 720 KB
31.txt 11 ms 720 KB
32.txt 11 ms 720 KB
33.txt 12 ms 720 KB
34.txt 11 ms 720 KB
35.txt 11 ms 720 KB
36.txt 11 ms 720 KB
37.txt 11 ms 720 KB
38.txt 11 ms 720 KB
39.txt 11 ms 720 KB
40.txt 11 ms 720 KB
41.txt 1 ms 256 KB
s1.txt 1 ms 256 KB
s2.txt 1 ms 256 KB
s3.txt 1 ms 256 KB