Dataset Viewer
Auto-converted to Parquet Duplicate
prompt
string
response
string
Problem: This is a very simple problem. Given the value of N and K, you need to tell us the value of the binomial coefficient C(N,K). You may rest assured that K ≤ N and the maximum value of N is 1,000,000,000,000,000. Since the value may be very large, you need to compute the result modulo 1009. Input The first line ...
memo = {} def C(n, r, p): ''' {n choose r} modulo p (p is prime) ''' if r < 0 or r > n: return 0 if r == 0 or r == n: return 1 if n >= p: # Lucas theorem return C(n/p, r/p, p) * C(n%p, r%p, p) % p if (n, r, p) not in memo: memo[n, r, p] = (C(n-1, r-1, p) + C(n-1, r, p...
Problem: Little johny was working on the co-ordinate plane.As he is still a novice he calculates the distance between two points P1 and P2 in the wrong way.He calculates the distance between P1(x1,y1) and P2(x2,y2) as : D(P1,P2) = |x1 - x2| + |y1 - y2| His teacher gave him a homework to calculate the area of a circle o...
t=int(raw_input()) for asd in range(t): n=int(raw_input()) print 2*n*n
Problem: Little johny was working on the co-ordinate plane.As he is still a novice he calculates the distance between two points P1 and P2 in the wrong way.He calculates the distance between P1(x1,y1) and P2(x2,y2) as : D(P1,P2) = |x1 - x2| + |y1 - y2| His teacher gave him a homework to calculate the area of a circle o...
# your code goes here t=int(raw_input()) for _ in range(0,t): r=int(raw_input()) print 2*r**2
Problem: Little johny was working on the co-ordinate plane.As he is still a novice he calculates the distance between two points P1 and P2 in the wrong way.He calculates the distance between P1(x1,y1) and P2(x2,y2) as : D(P1,P2) = |x1 - x2| + |y1 - y2| His teacher gave him a homework to calculate the area of a circle o...
t=int(input()) while(t>0): n=int(input()) print 2*n*n t-=1
Problem: Presti Digitator, the world-famous magician, is highly dissatisfied with his way of shuffling cards. Just yesterday, a perky guy in the audience demanded that he shuffle the cards once again, and he was aghast to see that the bottom card had not changed. Even though Mr. Digitator pacified the crowd with a few ...
shuffle_list=[0,0,1] for i in xrange(3,21): shuffle_list.append((i-1)*(shuffle_list[-1]+shuffle_list[-2])) for i in xrange(input()): print shuffle_list[input()]
Problem: Harish has decided to go to Arya's hotel this morning. We all know he is crazy for masala dosas. And as usual he is always hungry. He decided to order all the masala dosas at once. But then he realised that he did not have enough money to buy all of them. So he decided to share the amount with his friend Ozil....
# python3 if __name__ == "__main__": t = int(raw_input()) l = [] i = 0 while(i < t and t <= 10**6): ch = int(raw_input()) if(ch <= 10**18): l.append(ch) i = i + 1 for i in l: if(i % 2 == 0): print "YES" else: print "NO"
Problem: Shrija's brother Vaibhav is a very mischievous boy . He has messed a lot of books of Shrija on floor . Now Shrija is very angry . Seeing her sister angry he promises to arrange them on N empty stacks numbered from 1 to N . Shrija also felt that she should help her brother in arranging the books. So she gives V...
n,m=map(int,raw_input().split()) a=[0]*(n+2) #print a for i in range(m): left,right=map(int,raw_input().split()) a[left]+=1 a[right+1]-=1 for j in range(1,n+1): a[j]+=a[j-1] a=a[:n+1] a.sort() #print a print a[(n/2)+1]
Problem: Problem Statement Chef Diablo has set up a stall for selling his famous Modaks in the Trinity fest. He wants to earn as much profit as he can. So he has bought a chemical that increases the taste level of the Modaks. The tastier the Modaks the higher he can price them. This chemical is very costly hence he a...
T=input() while T: T-=1 tl,n=[int(x) for x in raw_input().split()] if n==0: n=1 print pow(tl,n,pow(10,9)+7)
Problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a string b is a position i (1 ≤ i ≤ |b| - |a| + 1) such th...
ch=input() l=list(map(int,ch.split())) m=l[0] n=l[1] p=l[2] s=input() t=input() l1=[] for i in range(p): ch=input() l1.append(ch) res=0 l2=[0] for i in range (len(t)-1): l2.append(0) for i in range ((len(t)-1),len(s)): if s[(i-len(t)+1):(i+1)]==t: res+=1 l2.append(re...
Problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a string b is a position i (1 ≤ i ≤ |b| - |a| + 1) such th...
import java.util.*; import java.io.*; public class Q1{ public static void main(String[] args) throws Exception{ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); PrintWriter w=new PrintWriter(System.out); int i,j,k1,k2,n,m,q,c=0,temp; long sum=0; String ...
Problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a string b is a position i (1 ≤ i ≤ |b| - |a| + 1) such th...
#include <bits/stdc++.h> using namespace std; void qmax(int &x, int y) { if (x < y) x = y; } void qmin(long long &x, long long y) { if (x > y) x = y; } inline long long read() { char s; long long k = 0, base = 1; while ((s = getchar()) != '-' && s != EOF && !(isdigit(s))) ; if (s == EOF) exit(0); if (...
Problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a string b is a position i (1 ≤ i ≤ |b| - |a| + 1) such th...
#include <bits/stdc++.h> using namespace std; int N, M, Q; string S, T; int ok[1010]; void solve() { int i, j, k, l, r, x, y; string s; cin >> N >> M >> Q >> S >> T; for (i = 0; i < (N); i++) { ok[i + 1] = ok[i]; if (i + M <= N) { x = 1; for (j = 0; j < (M); j++) if (S[i + j] != T[j]...
Problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a string b is a position i (1 ≤ i ≤ |b| - |a| + 1) such th...
#include <bits/stdc++.h> using namespace std; int main() { string s, t; int n, m, q, l, r; cin >> n >> m >> q; cin >> s >> t; int arr[10000] = {0}; for (int i = 0; i <= n - m; ++i) { arr[i + 1] = arr[i] + (s.substr(i, m) == t); } while (q--) { cin >> l >> r; if (r - l + 1 < m) cout << ...
Problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a string b is a position i (1 ≤ i ≤ |b| - |a| + 1) such th...
def subamount(l, r): if r - l < m - 1: return 0 elif m + l - 2 < 0: return pr[r] - 0 return pr[r] - pr[m + l - 2] n, m, q = map(int, input().split()) s = input() t = input() pr = [0] * n if m <= n: pr[m - 1] = int(t == s[:m]) for i in range(m, n): pr[i] = pr[i - 1] + (t ==...
Problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a string b is a position i (1 ≤ i ≤ |b| - |a| + 1) such th...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual soluti...
Problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a string b is a position i (1 ≤ i ≤ |b| - |a| + 1) such th...
string = "" array = [] n, m, q = map(int, input().split()) s = input() t = input() for i in range(0, n - m + 1) : if s[ i : i + m] == t : string += '1' else : string += '0' for i in range(0, q) : a, b = map(int, input().split()) if b - a + 1 >= m : array.append((string...
Problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a string b is a position i (1 ≤ i ≤ |b| - |a| + 1) such th...
#list_int 並べて出力 print (' '.join(map(str,ans_li))) #list_str 並べて出力 print (' '.join(list)) # 2進数 format(10, 'b') # '1010' ''' 二次元配列を一列ずつ for i in ans: print(*i) ''' ''' heapq queue = [] heapq.heapify(queue) #heapqの作成 heapq.heappush(queue,num) #numのpush(値の追加) pop = heapq.heappop(queue) #numのpop(最小値の出力) pop = heapq.heap...
Problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a string b is a position i (1 ≤ i ≤ |b| - |a| + 1) such th...
import java.awt.List; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.math.BigDecimal; import java.math.BigInteger; import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java...
Problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a string b is a position i (1 ≤ i ≤ |b| - |a| + 1) such th...
#include <bits/stdc++.h> using namespace std; int n, m, pre[2005], q; char s[2005], t[2005]; int main() { scanf("%d%d%d", &n, &m, &q); scanf("%s%s", s, t); for (int i = 0; i < n - m + 1; i++) { int flag = 1; for (int j = 0; j < m; j++) if (s[i + j] != t[j]) { flag = 0; break; }...
Problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a string b is a position i (1 ≤ i ≤ |b| - |a| + 1) such th...
//package que_a; import java.io.*; import java.util.*; import java.math.*; public class utkarsh { InputStream is; PrintWriter out; long mod = (long) (1e9 + 7); boolean SHOW_TIME; void solve() { //Enter code here utkarsh //SHOW_TIME = true; int n = ni(), m = ni()...
Problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a string b is a position i (1 ≤ i ≤ |b| - |a| + 1) such th...
import java.util.*; import java.io.*; public class B1016{ public static void main(String args[])throws IOException{ Scanner sc=new Scanner(new BufferedReader(new InputStreamReader(System.in))); PrintWriter pw=new PrintWriter(System.out); int n=sc.nextInt(); int m=sc.nextInt(); int q=sc.nextInt(); String ...
Problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a string b is a position i (1 ≤ i ≤ |b| - |a| + 1) such th...
import java.util.*; import java.io.*; public class Main { public static void main(String[] args) { FastReader reader = new FastReader(); PrintWriter writer = new PrintWriter(System.out); //ifieverknew int n = reader.nextInt(); int m = reader.nextInt(); int q = reader.nextInt(); char[] s = read...
Problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a string b is a position i (1 ≤ i ≤ |b| - |a| + 1) such th...
#include <bits/stdc++.h> using namespace std; int n, m, Q, cnt = 0; int a[1010], L[1010]; char s[1010], t[1010]; int main() { scanf("%d%d%d", &n, &m, &Q); scanf("%s%s", s, t); for (int i = 0; i < n; i++) { if (s[i] == t[0]) { bool bo = 0; for (int j = 1; j < m; j++) { if (s[i + j] != t[j])...
Problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a string b is a position i (1 ≤ i ≤ |b| - |a| + 1) such th...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n, m, q; string s, t; cin >> n >> m >> q >> s >> t; map<long long, long long> d; long long cont = 0; for (long long i = (0); i < (long long)(n); i++) { if (s.substr(i, m) == t...
Problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a string b is a position i (1 ≤ i ≤ |b| - |a| + 1) such th...
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; public class Main { public static void main(String[] args) { new Main().run(); } private IO io = new IO(); private String text; private String pattern; private int[] pos = new int[10000]; private int n...
Problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a string b is a position i (1 ≤ i ≤ |b| - |a| + 1) such th...
def binary_search(array, target): lower = 0 upper = len(array) while lower < upper: # use < instead of <= x = lower + (upper - lower) // 2 val = array[x] if target == val: return x elif target > val: if lower == x: # these two are the actual lines ...
Problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a string b is a position i (1 ≤ i ≤ |b| - |a| + 1) such th...
'''input 3 5 2 aaa baaab 1 3 1 1 ''' from bisect import bisect_left, bisect_right n, m, q = map(int, input().split()) s, t = input(), input() x = [] for i in range(len(s) - len(t) + 1): if s[i:i+len(t)] == t: x.append(i) sx = set(x) for _ in range(q): l, r = map(int, input().split()) if r - l + 1 < len(t): prin...
Problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a string b is a position i (1 ≤ i ≤ |b| - |a| + 1) such th...
def z_algorithm(s): n = len(s) Z = [0]*n Z[0] = n i = 1 j = 0 while i < n: while i+j < n and s[j] == s[i+j]: j += 1 Z[i] = j if j == 0: i += 1 continue k = 1 while i+k < n and k+Z[k] < j: Z[i+k] = Z[k] ...
Problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a string b is a position i (1 ≤ i ≤ |b| - |a| + 1) such th...
def main(): [n,m,q] = list(map(int, input().split(" "))) s = input() t = input() queries = [] for _ in range(q): queries.append(list(map(int, input().split(" ")))) #toss the obvious if len(s) < len(t): for _ in range(q): print(0) else: ref = [0] for i in range(len(s)-len(t)+1): ...
Problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a string b is a position i (1 ≤ i ≤ |b| - |a| + 1) such th...
#coding:utf-8 tmp = raw_input() n = int(tmp.split()[0]) m = int(tmp.split()[1]) q = int(tmp.split()[2]) s = raw_input() t = raw_input() st = [0]*n for i in range(n-m+1): if t == s[i:i+m]: st[i] += 1 data = [] res = [] for i in range(q): da = [int(i) for i in raw_input().split()] # data.append(da) # print(st) # fo...
Problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a string b is a position i (1 ≤ i ≤ |b| - |a| + 1) such th...
#include <bits/stdc++.h> using namespace std; int fx[] = {-1, 1, 0, 0}; int fy[] = {0, 0, -1, 1}; int dx[] = {1, 1, 0, -1, -1, -1, 0, 1}; int dy[] = {0, 1, 1, 1, 0, -1, -1, -1}; int kx[] = {1, 1, -1, -1, 2, 2, -2, -2}; int ky[] = {2, -2, 2, -2, 1, -1, 1, -1}; bool cmp(const pair<int, int> &a, const pair<int, int> &b) {...
Problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a string b is a position i (1 ≤ i ≤ |b| - |a| + 1) such th...
import java.io.BufferedInputStream; import java.util.ArrayList; import java.util.Deque; import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Scanner; import java.util.Set; import java.util.Stack; /** * */ public class SegmentOccurrences { public static void main(Strin...
Problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a string b is a position i (1 ≤ i ≤ |b| - |a| + 1) such th...
from sys import stdin, stdout n,m,q = stdin.readline().split() s = stdin.readline().rstrip() sub = stdin.readline().rstrip() def countSubtrings(s,sub): resp = [0]*len(s) sum = 1 for x in range(len(s)-len(sub)+1): if len(sub) == 1 and s[x] == sub: resp[x] = 1 continue ...
Problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a string b is a position i (1 ≤ i ≤ |b| - |a| + 1) such th...
n, m, q = map(int, input().split()) s = input() t = input() k = [0] * (n + 1) cntr = 0 for i in range(1, n+1): k[i] = k[i-1] if s[i - 1:i + m - 1] == t: k[i] += 1 for i in range(q): l, r = map(int, input().split()) print(k[max(l-1, r-m+1)]-k[l-1])
Problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a string b is a position i (1 ≤ i ≤ |b| - |a| + 1) such th...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; int main() { int n, m, q; cin >> n >> m >> q; string a, b; cin >> a >> b; int mark[1000]; memset(mark, 0, sizeof(mark)); for (int i = 0; i < n; i++) { if (a[i] == b[0]) { int flag = 1, j; for (j = 1; j < m && i + j <...
Problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a string b is a position i (1 ≤ i ≤ |b| - |a| + 1) such th...
while True: try: def failur(p, m): failr = [0]*(m+2) failr[0]= failr[1] = 0 i = 2 while i <= m: j = failr[i-1] while True: if p[i-1] == p[j]: failr[i] = j+1 break if j == 0: failr[i] = j break j = failr[j] i += 1 return failr def matches(t, p, ...
Problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a string b is a position i (1 ≤ i ≤ |b| - |a| + 1) such th...
import java.io.BufferedReader; import java.io.IOException; import java.util.*; import java.io.BufferedWriter; import java.io.InputStream; import java.io.OutputStream; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.Writer; public class B1016 { static ...
Problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a string b is a position i (1 ≤ i ≤ |b| - |a| + 1) such th...
import sys n,m,t=map(int,input().split()) s1=list(input()) s2=list(input()) d={} for i in range(n): inc=0 j=0 while i+inc<n and j<m and s1[i+inc]==s2[j]: inc+=1 j+=1 if inc==m: d[i+m]=d.get(i+m,0)+1 #print(d) #d[0]=-1 s=0 for i in range(0,1001): d[i]=d.get...
Problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a string b is a position i (1 ≤ i ≤ |b| - |a| + 1) such th...
import java.util.*; import java.io.*; public class A { public static void main(String[] args) { FastScanner fs=new FastScanner(); int n=fs.nextInt(); int m=fs.nextInt(); int q=fs.nextInt(); char[] first=fs.next().toCharArray(), second=fs.next().toCharArray(); if (m>n) { for (int i=0; i<q; i++) System...
Problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a string b is a position i (1 ≤ i ≤ |b| - |a| + 1) such th...
import java.io.*; import java.util.*; public class B implements Runnable{ public static void main (String[] args) {new Thread(null, new B(), "_cf", 1 << 28).start();} public void run() { FastScanner fs = new FastScanner(); PrintWriter out = new PrintWriter(System.out); System.err.println("Go!"); int n = fs...
Problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a string b is a position i (1 ≤ i ≤ |b| - |a| + 1) such th...
import sys def get_array(): return list(map(int, sys.stdin.readline().split())) def get_ints(): return map(int, sys.stdin.readline().split()) def input(): return sys.stdin.readline().strip('\n') n , m , q = get_ints() s = input() p = input() ans = [] i = 0 count = 0 while True: si = s.find(p,i) if si != -1: ...
Problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a string b is a position i (1 ≤ i ≤ |b| - |a| + 1) such th...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.List; import java.util.InputMismatchException; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; /** * Built using CHelper plug-in Actual solution is at t...
Problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a string b is a position i (1 ≤ i ≤ |b| - |a| + 1) such th...
import sys n,m,q=map(int,input().split()) s=input() t=input() A=[None]*q for i in range(q): A[i]=list(map(int,input().split())) if m>n: for i in range(q): print(0) sys.exit() score=[0 for i in range(n-m+1)] for i in range(n-m+1): if t==s[i:i+m]: score[i]=1 SUM=[0 for i in range(n-m+...
Problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a string b is a position i (1 ≤ i ≤ |b| - |a| + 1) such th...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e3 + 5; char a[maxn], b[maxn]; int sum[maxn]; int n, m, q; void solve() { for (int i = 0; i < n; i++) { int flag = 1; for (int j = 0; j < m; j++) if (a[i + j] != b[j]) { flag = 0; break; } if (flag) sum[i + 1]++; ...
Problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a string b is a position i (1 ≤ i ≤ |b| - |a| + 1) such th...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public final class SegmentOccurencesCF { public static void main(String[] args) throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); S...
Problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a string b is a position i (1 ≤ i ≤ |b| - |a| + 1) such th...
#include <bits/stdc++.h> using namespace std; int n, m, q; int ans[1005]; int main() { while (scanf("%d%d%d", &n, &m, &q) != EOF) { string s1, s2; cin >> s1 >> s2; for (int i = 0; i + m <= n; i++) { if (s1.substr(i, m) == s2) ans[i + 1]++; } for (int i = 2; i <= n; i++) ans[i] += ans[i - 1];...
Problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a string b is a position i (1 ≤ i ≤ |b| - |a| + 1) such th...
import java.util.*; import java.io.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); int q = sc.nextInt(); List<Integer> arr = new ArrayList<Integer>(); String str = sc.next(); String cpy = sc.next(); for(int...
Problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a string b is a position i (1 ≤ i ≤ |b| - |a| + 1) such th...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual soluti...
Problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a string b is a position i (1 ≤ i ≤ |b| - |a| + 1) such th...
n, m, q = map(int, input().split()) s = input() t = input() arr = [0]*1008 arr2 = [0]*1008 for i in range(n - m + 1): fl = 1 for j in range(m): if s[i+j] != t[j]: fl = 0 arr2[i] = fl arr[i+1] = arr[i] + arr2[i] for i in range(max(0, n - m + 1), n): arr[i+1] = arr[i] for i in rang...
Problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a string b is a position i (1 ≤ i ≤ |b| - |a| + 1) such th...
#include <bits/stdc++.h> using namespace std; char s[1002], t[1002]; int v[1002]; int main() { int n, m, q, l, r, sol, i, ok, j; cin >> n >> m >> q; cin.get(); cin.getline(s, 1001); cin.getline(t, 1001); for (i = 0; i < n - m + 1; i++) { ok = 1; for (j = i; j <= i + m - 1; j++) if (t[j - i] !=...
Problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a string b is a position i (1 ≤ i ≤ |b| - |a| + 1) such th...
#include <bits/stdc++.h> using namespace std; const int inf = 1e9 + 7; const long long INF = 1LL << 60; const long long mod = 1e9 + 7; const long double eps = 1e-8; const long double pi = acos(-1.0); template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template <cl...
Problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a string b is a position i (1 ≤ i ≤ |b| - |a| + 1) such th...
#include <bits/stdc++.h> using namespace std; void z_function(string &s, vector<int> &z) { int n = s.length(), l = -1, r = -1; z.clear(); z.resize(n, 0); z[0] = n; for (int i = 0; i < n; i++) { if (i <= r) z[i] = min(r - i + 1, z[i - l]); while (z[i] + i < n && s[z[i]] == s[z[i] + i]) z[i]++; if (...
Problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a string b is a position i (1 ≤ i ≤ |b| - |a| + 1) such th...
#!/usr/bin/python3 def calc(l, r, layers, li): if r - l == 1: return layers[li][l] xl = l if l % 2 == 1: xl -= 1 xr = r if r % 2 == 1: xr += 1 ans = calc(xl // 2, xr // 2, layers, li + 1) if xl != l: ans -= layers[li][xl] if xr != r: ans -= laye...
Problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a string b is a position i (1 ≤ i ≤ |b| - |a| + 1) such th...
import java.util.*; import java.io.*; import java.math.*; public class loser { static class InputReader { public BufferedReader br; public StringTokenizer token; public InputReader(InputStream stream) { br=new BufferedReader(new InputStreamReader(stream),32768); ...
Problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a string b is a position i (1 ≤ i ≤ |b| - |a| + 1) such th...
R=lambda:map(int,input().split()) n,m,q=R() s,t=input(),input() a=[0,0] b=0 for i in range(n):b+=s[i:i+m]==t;a+=[b] for _ in[0]*q:l,r=R();print(a[max(l,r-m+2)]-a[l])
Problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a string b is a position i (1 ≤ i ≤ |b| - |a| + 1) such th...
a,b,c=map(int,input().split()) s1=input();s2=input() coun=[0 for i in range(a+5)] if a>=b: for i in range(a-b+1): coun[i+1]=coun[i]+(s1[i:i+b] == s2) for i in range(a-b+1,a+5): if coun[i]==0: coun[i]=coun[i-1] for i in range(c): x,y=map(int,input().split()) if...
Problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a string b is a position i (1 ≤ i ≤ |b| - |a| + 1) such th...
//import java.lang.*; import java.util.*; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); // length of string s int m = scanner.nextInt(); // length of string t int q = scanner.nextInt(); // number of queries String s = scann...
Problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a string b is a position i (1 ≤ i ≤ |b| - |a| + 1) such th...
#E48_B ln = [int(i) for i in input().split(" ")] n = ln[0] m = ln[1] q = ln[2] s = input() t = input() def runAns(s, t): ss = 0 sso = [0] * (len(t) - 1) for i in range(0, n - len(t) + 1): f = True for j in range(0, n - i): if j >= len(t): break if ...
Problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a string b is a position i (1 ≤ i ≤ |b| - |a| + 1) such th...
#include <bits/stdc++.h> using namespace std; const int MX = 1e3; int sum[MX + 2]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n, m, q, l, r; string str, str2; cin >> n >> m >> q; cin >> str >> str2; for (long long i = 0; i < n - m + 1; i++) { sum[i] = (str.substr(i, m) == ...
Problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a string b is a position i (1 ≤ i ≤ |b| - |a| + 1) such th...
#include <bits/stdc++.h> using namespace std; vector<int> vet; int p[201010]; void kmp(string &s, int sz) { p[0] = 0; int idx = 0, n = (int)s.size(); for (int i = 1; i < n; i++) { while (s[idx] != s[i] && idx > 0) idx = p[idx - 1]; if (s[idx] == s[i]) idx++; p[i] = idx; if (p[i] == sz) { vet...
Problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a string b is a position i (1 ≤ i ≤ |b| - |a| + 1) such th...
import sys FILE_IO = False if FILE_IO: input_stream = open('input_test.txt') sys.stdout = open('current_output.txt', 'w') else: input_stream = sys.stdin n, m, q = map(int, input_stream.readline().split()) s = input_stream.readline().split()[0] t = input_stream.readline().split()[0] dp = [[0] * (n + 1) f...
Problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a string b is a position i (1 ≤ i ≤ |b| - |a| + 1) such th...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.FilterInputStream; import java.io.BufferedInputStream; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author nirav */ public class Mai...
Problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a string b is a position i (1 ≤ i ≤ |b| - |a| + 1) such th...
#include <bits/stdc++.h> #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize(4) using namespace std; const int N = 1e3 + 5; int sum[N]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; int n, m, q, l, r; string s, t; cin >> n >> m >> q; cin >> s >> t; for (int i = ...
Problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a string b is a position i (1 ≤ i ≤ |b| - |a| + 1) such th...
import java.io.*; import java.util.*; public class Asd { static PrintWriter w=new PrintWriter(System.out); static FastScanner s=new FastScanner(); public static void main(String[] args) { //int t=s.nextInt(); int t=1; while(t-->0) { solve(); } w.close(); } ...
Problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a string b is a position i (1 ≤ i ≤ |b| - |a| + 1) such th...
n, m, q = [int(i) for i in input().split()] s = input() t = input() positions = '' for i in range(n-m+1): if s[i:i + m] == t: positions += '1' else: positions += '0' for i in range(q): l,r = map(int, input().split()) if r - l + 1 >= m: print (positions[l-1:r-m+1].count('1')) ...
Problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a string b is a position i (1 ≤ i ≤ |b| - |a| + 1) such th...
from sys import stdin,stdout from collections import Counter import math I=lambda: map(int,stdin.readline().split()) I1=lambda: stdin.readline() n,m,q=I() s,t=I1().strip(),I1().strip() a=[0]*(n+1) for i in range(n): if i+m<=n and s[i:i+m]==t: a[i+1]+=a[i]+1 else: a[i+1]+=a[i] for i in range(q)...
Problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a string b is a position i (1 ≤ i ≤ |b| - |a| + 1) such th...
#include <bits/stdc++.h> using namespace std; const double PI = 2 * acos(0.0), EPS = 1e-9; const int INF = 1e9, NINF = -1e9, MOD = 1e9 + 7; void GO() { cout << fixed << setprecision(10); } int main() { GO(); int n, m, q, r, l, c, a[1001] = {}; string second, t; cin >> n >> m >> q >> second >> t; for (int i = ...
Problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a string b is a position i (1 ≤ i ≤ |b| - |a| + 1) such th...
n, m, q = (int(x) for x in input().split()) s = input() t = input() X = set() for i in range(len(s) - len(t) + 1): if s[i:i + len(t)] == t: X.add(i) Y = [0] for i in range(len(s)): tm = Y[-1] if i in X: tm += 1 Y.append(tm) for _ in range(q): l, r = (int(x) for x in input().split(...
End of preview. Expand in Data Studio
README.md exists but content is empty.
Downloads last month
12