Submission #74105805


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<int,char> pic;
typedef vector<int> vi;
typedef vector<ll> vll;
#define SZ(x) ((int)x.size())
ll ksm(ll a,ll b,ll p){if (p == 1)return 0;if (b == 0)return 1%p;
ll ans = 1;	a %= p;while (b > 0){if (b&1){ans = ans*a%p;}a = (a*a)
%p;b >>= 1;}return ans;}
const int mod = 1e9+7;
const int P = 998244353;
const ll inf = (1LL << 50LL);
const ll N = 1010;

int n,l,r;
ll ans = 0;
char s[500010];
int table[200][500010];
int main(){
	scanf("%d%d%d",&n,&l,&r);
	scanf("%s",s+1);
	for (int i = 1;i <= n;i++){
		for (int j = 'a';j <= 'z';j++){
			if (s[i] == j){
				table[j][i] = table[j][i-1]+1;
			}
			else {
				table[j][i] = table[j][i-1];
			}
		}
	}
	for (int i = 'a';i <= 'z';i++){
		int a = 1,b = 1,c = 1;
		for (;a <= n;a++){
			if (s[a] != i){
				continue;
			}
			b = a+l;
			if (b > n){
				break;
			}
			c = min(a+r,n);
			ans += table[i][c]-table[i][b-1];
			//printf("%c %d %d %d %d\n",i,ans,a,b,c);
		}
	}
	printf("%lld",ans);

		
    return 0;
}

Submission Info

Submission Time
Task C - Comfortable Distance
User wuqize
Language C++23 (GCC 15.2.0)
Score 300
Code Size 1160 Byte
Status AC
Exec Time 43 ms
Memory 55236 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 3
AC × 23
Set Name Test Cases
Sample sample00.txt, sample01.txt, sample02.txt
All sample00.txt, sample01.txt, sample02.txt, testcase00.txt, testcase01.txt, testcase02.txt, testcase03.txt, testcase04.txt, testcase05.txt, testcase06.txt, testcase07.txt, testcase08.txt, testcase09.txt, testcase10.txt, testcase11.txt, testcase12.txt, testcase13.txt, testcase14.txt, testcase15.txt, testcase16.txt, testcase17.txt, testcase18.txt, testcase19.txt
Case Name Status Exec Time Memory
sample00.txt AC 1 ms 3912 KiB
sample01.txt AC 1 ms 3896 KiB
sample02.txt AC 1 ms 3892 KiB
testcase00.txt AC 1 ms 3800 KiB
testcase01.txt AC 1 ms 3868 KiB
testcase02.txt AC 8 ms 11372 KiB
testcase03.txt AC 30 ms 51588 KiB
testcase04.txt AC 15 ms 22832 KiB
testcase05.txt AC 20 ms 32716 KiB
testcase06.txt AC 11 ms 17076 KiB
testcase07.txt AC 43 ms 55216 KiB
testcase08.txt AC 42 ms 55236 KiB
testcase09.txt AC 35 ms 55096 KiB
testcase10.txt AC 42 ms 55068 KiB
testcase11.txt AC 36 ms 55216 KiB
testcase12.txt AC 38 ms 55052 KiB
testcase13.txt AC 36 ms 55148 KiB
testcase14.txt AC 34 ms 55144 KiB
testcase15.txt AC 36 ms 55112 KiB
testcase16.txt AC 32 ms 55092 KiB
testcase17.txt AC 32 ms 55096 KiB
testcase18.txt AC 26 ms 55036 KiB
testcase19.txt AC 31 ms 55064 KiB