Search is not available for this dataset
name stringlengths 2 112 | description stringlengths 29 13k | source int64 1 7 | difficulty int64 0 25 | solution stringlengths 7 983k | language stringclasses 4
values |
|---|---|---|---|---|---|
1016_B. Segment Occurrences | 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 that b[i..i... | 2 | 8 | import os, sys
from io import BytesIO, IOBase
def main():
n, m, q = rints()
s, t, cum = rstr(), rstr(), [0] * (n + 1)
for i in range(m - 1, n):
ix, cum[i] = m - 1, cum[i] + cum[i - 1]
for j in range(i, i - m, -1):
if s[j] != t[ix]:
break
ix -= 1
... | PYTHON3 |
1016_B. Segment Occurrences | 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 that b[i..i... | 2 | 8 |
n,m,q = map(int,raw_input().split())
s=raw_input()
t=raw_input()
"""
#n,m,q = 10,3,1
#s='codeforfor'
#t='for'
n,m,q=15,2, 1
s='abacabadabacaba'
t='ba'
"""
ct=[[0 for i in range(n+m)] for j in range(n+m)]
for i in range(n):
if t==s[i:i+m]:
ct[i][i]=1
for k in range(1,n):
for i in range(n-k):
j... | PYTHON |
1016_B. Segment Occurrences | 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 that b[i..i... | 2 | 8 | #!/usr/bin/env python3
from sys import stdin, stdout
def rint():
return map(int, stdin.readline().split())
#lines = stdin.readlines()
n, m, q = rint()
s = input()
t = input()
occur_in_s =[0]*(n+1)
for i in range(n-1, -1, -1):
if i + m > n:
occur_in_s[i] = occur_in_s[i+1]
continue
if s[i... | PYTHON3 |
1016_B. Segment Occurrences | 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 that b[i..i... | 2 | 8 | #include <bits/stdc++.h>
int pi[1002];
void pi_function(char temp[], int len) {
int k = 0;
for (int q = 2; q < len + 1; q++) {
while (k > 0 && temp[k] != temp[q - 1]) k = pi[k];
if (temp[k] == temp[q - 1]) k++;
pi[q] = k;
}
return;
}
int main() {
int n, m, q;
scanf("%d%d%d", &n, &m, &q);
char ... | CPP |
1016_B. Segment Occurrences | 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 that b[i..i... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m, q;
cin >> n >> m >> q;
string s, t;
cin >> s >> t;
vector<int> v(n);
for (int i = 0; i <= n - m; i++) {
bool flag = 0;
for (int j = 0; j < m; j++) {
if (t[j] != s[i + j]) {... | CPP |
1016_B. Segment Occurrences | 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 that b[i..i... | 2 | 8 | n,m,q=list(map(int,input().split()))
s=input()
t=input()
ans=[]
counter=0
dec=[]
for i in range(0,n-m+1):
type(i)
if s[i:i+m]==t:
ans.append(1)
else:ans.append(0)
for i in range(q):
start,stop=list(map(int,input().split()))
slice=ans[start-1:stop-m+1]
if stop-start+1<m:
dec.appen... | PYTHON3 |
1016_B. Segment Occurrences | 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 that b[i..i... | 2 | 8 | def main():
n, m, q = map(int, input().split())
s = input()
t = input()
matrix = [[0 for i in range(n)] for i in range(n)]
for l in range(n):
for r in range(l + m - 1, n):
if s[r - m + 1:r + 1] == t:
matrix[l... | PYTHON3 |
1016_B. Segment Occurrences | 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 that b[i..i... | 2 | 8 | //codeforces_1016_B
//dp version: O(n)
import java.io.*;
import java.util.*;
import static java.lang.Math.*;
import java.math.*;
public class acm {
public static void main(String[] args) throws IOException {
BufferedReader gi = new BufferedReader(new InputStreamReader(System.in));
PrintWriter ... | JAVA |
1016_B. Segment Occurrences | 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 that b[i..i... | 2 | 8 | from bisect import bisect_left, bisect_right
def main():
n, m, q = map(int, input().split(' '))
s = input()
t = input()
ps = []
for i in range(n-m+1):
if t == s[i:i+m]:
ps.append(i)
ans = []
for _ in range(q):
l, r = map(int, input().split(' '))
... | PYTHON3 |
1016_B. Segment Occurrences | 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 that b[i..i... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
inline int read() {
char c = getchar();
int x = 0, f = 1;
for (; !isdigit(c); c = getchar())
if (c == '-') f = -1;
for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
return x * f;
}
const int MAXN = 1e5 + 5;
char s[MAXN], t[MAXN];
int nxt[MAXN], sum[MAXN]... | CPP |
1016_B. Segment Occurrences | 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 that b[i..i... | 2 | 8 | import java.io.*;
import java.util.*;
public class CFB {
BufferedReader br;
PrintWriter out;
StringTokenizer st;
boolean eof;
private static final long MOD = 1000L * 1000L * 1000L + 7;
private static final int[] dx = {0, -1, 0, 1};
private static final int[] dy = {1, 0, -1, 0};
private... | JAVA |
1016_B. Segment Occurrences | 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 that b[i..i... | 2 | 8 | def coun(s, t):
d = 0
for i in range(len(s) - len(t) + 1):
if s[i:i + len(t)] == t:
d += 1
return(d)
n, m, q = list(map(int, input().split()))
s = input()
t = input()
x = [0]
for j in range(n):
x.append(coun(s[:j + 1], t))
for i in range(q):
l, r = map(int, input().split())
... | PYTHON3 |
1016_B. Segment Occurrences | 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 that b[i..i... | 2 | 8 | M = 10000000007
b = 29
a = ord('a') - 1
n, m, q = map(int, input().split())
s = list(input())
t = list(input())
hs = [0] * (n + 1)
ps = [1] * (n + 1)
for i in range(n):
hs[i + 1] = (hs[i] * b + ord(s[i]) - a) % M
ps[i + 1] = (ps[i] * b) % M
h = 0
for i in range(m):
h = (h * b + ord(t[i]) - a) % M
ans = [0] ... | PYTHON3 |
1016_B. Segment Occurrences | 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 that b[i..i... | 2 | 8 | n,m,q=map(int,input().split())
s,t,l=input(),input(),[0]*(n+5)
for i in range(n-m+1):
if t==s[i:i+m]:l[i+1]=1
for i in range(1,n + 3):l[i]+=l[i-1]
for i in range(q):
a,b=map(int,input().split())
print(0if int(b-a+1<m)else l[b-m+1]-l[a-1]) | PYTHON3 |
1016_B. Segment Occurrences | 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 that b[i..i... | 2 | 8 | n,m,q=map(int,input().split())
s=input()
t=input()
check=''
for i in range(n):
if s[i:i+m]==t:
check+='1'
else:
check+='0'
#print(check)
for xx in range(q):
l,r=map(int,input().split())
print(check[l-1:r-m+1].count('1') if (r-l+1)>=m else 0)
| PYTHON3 |
1016_B. Segment Occurrences | 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 that b[i..i... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 9;
int n, m, q;
string s, t;
int a[N], b[N];
void check(int i) {
for (int j = 1; j <= m; ++j)
if (t[j] != s[j + i - 1]) return;
a[i + m - 1] = 1;
return;
}
int main() {
cin >> n >> m >> q;
cin >> s;
s = "#" + s;
cin >> t;
t = "@" + t;... | CPP |
1016_B. Segment Occurrences | 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 that b[i..i... | 2 | 8 | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.StringTokenizer;
public class B {
public static void main(String args[])throws Exception{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
... | JAVA |
1016_B. Segment Occurrences | 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 that b[i..i... | 2 | 8 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException{
BufferedReader sc=new BufferedReader(new InputStreamReader(System.in));
String[] ss=sc.readLine().split(" ");
int n=Inte... | JAVA |
1016_B. Segment Occurrences | 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 that b[i..i... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, t;
cin >> n >> m >> t;
string a, b;
cin >> a >> b;
std::vector<int> v(n, 0);
int cnt = 0;
int p = 1, index = 0, flag = 0;
for (int i = 0; i <= n - m; ++i) v[i + 1] = v[i] + (a.substr(i, m) == b);
while (t--) {
int l, r;
cin >... | CPP |
1016_B. Segment Occurrences | 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 that b[i..i... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
vector<int> v[1003];
string text, pat;
vector<int> vv;
int main() {
int n, m, q;
cin >> n >> m >> q;
cin >> text >> pat;
for (int i = 0; i < n; i++) {
int x = 0;
for (int j = 0; j < m; j++) {
if ((j + i) < n && text[j + i] == pat[j]) {
x++;
... | CPP |
1016_B. Segment Occurrences | 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 that b[i..i... | 2 | 8 | 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:
... | PYTHON3 |
1016_B. Segment Occurrences | 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 that b[i..i... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
string a, b;
int n, m, q;
int pos[1005];
int main() {
cin >> n >> m >> q;
cin >> a;
cin >> b;
for (int i = 0; i <= n - m; i++) {
if (a.substr(i, m) == b) {
pos[i] = 1;
}
}
while (q--) {
int x, y, ans = 0;
cin >> x >> y;
for (int i = x -... | CPP |
1016_B. Segment Occurrences | 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 that b[i..i... | 2 | 8 | n,m,q=map(int,input().split())
s=input()
t=input()
st=[]
en=[]
def check(i):
if i>(n-m):
return False
for j in range(i,i+m):
if(s[j]!=t[j-i]):
return False
return True
for i in range(n):
st.append(0)
en.append(0)
for i in range(n):
if(check(i)):
st[i]=1
... | PYTHON3 |
1016_B. Segment Occurrences | 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 that b[i..i... | 2 | 8 | import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class SegmentOccurences {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String[] str = sc.nextLine().split(" ");
int n = Integer.parseInt(str[0]);
int m = Integer.parseInt(str[1]);
... | JAVA |
1016_B. Segment Occurrences | 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 that b[i..i... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 10;
int n, m, q, l, r, pr[maxn];
bool ok[maxn], flag;
string s, t;
int main() {
cin >> n >> m >> q;
cin >> s >> t;
pr[0] = 0;
for (int i = 0; i < n - m + 1; i++) {
flag = true;
for (int j = 0; j < m; j++)
if (s[i + j] != t[j]) {
... | CPP |
1016_B. Segment Occurrences | 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 that b[i..i... | 2 | 8 | import sys
line1 = sys.stdin.readline().strip('\n')
line2 = sys.stdin.readline().strip('\n')
line3 = sys.stdin.readline().strip('\n')
a,b,n = list(map(int, line1.split()))
sum = [0]*(len(line3))
for i in range(len(line2)):
if line2[i:i+len(line3)] == line3:
sum.append(1)
else:
sum.append(0)
for i in range(len(su... | PYTHON3 |
1016_B. Segment Occurrences | 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 that b[i..i... | 2 | 8 | n, m, q = map(int, input().split())
s = input()
t = input()
flag = [0]*(1007)
prefix = [0]*(1007)
for i in range(n-m+1):
f = 1
for j in range(m):
if s[i+j] != t[j]:
f = 0
flag[i]= f
prefix[i+1]= prefix[i]+flag[i]
for i in range(max(0,n-m+1), n):
prefix[i+1] = prefix[i]
for _ in... | PYTHON3 |
1016_B. Segment Occurrences | 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 that b[i..i... | 2 | 8 | """
Author : thekushalghosh
Team : CodeDiggers
"""
import sys,math
input = sys.stdin.readline
############ ---- USER DEFINED INPUT FUNCTIONS ---- ############
def inp():
return(int(input()))
def inlt():
return(list(map(int,input().split())))
def insr():
s = input()
return(s[:len(s) - 1])
def i... | PYTHON3 |
1016_B. Segment Occurrences | 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 that b[i..i... | 2 | 8 | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in... | JAVA |
1016_B. Segment Occurrences | 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 that b[i..i... | 2 | 8 | import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class EducationalRound48B {
public static void main(String[] args) {
// TODO Auto-generated method stub
out=new PrintWriter(new BufferedOutput... | JAVA |
1016_B. Segment Occurrences | 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 that b[i..i... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int n, m, q;
string str1, str2;
int ans[1005];
int main() {
scanf("%d %d %d", &n, &m, &q);
cin >> str1 >> str2;
int f[1005];
str1 = " " + str1;
str2 = " " + str2;
for (int i = 1; i <= n - m + 1; i++) {
f[i] = 1;
for (int j = 0; j < m; j++) {
if (st... | CPP |
1016_B. Segment Occurrences | 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 that b[i..i... | 2 | 8 | 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);
int n = reader.nextInt();
int m = reader.nextInt();
int q = reader.nextInt();
//sample
char[] s = reader.ne... | JAVA |
1016_B. Segment Occurrences | 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 that b[i..i... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
const int desll[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
const long long mod = 1e9 + 7;
const int maxn = 1e6 + 7;
const int maxm = 1e8 + 7;
const double eps = 1e-4;
int m, n;
int ar[maxn];
char ch1[maxn], ch2[maxn];
int main() {
scanf("%d", &n);
scanf("%d", &m);
in... | CPP |
1016_B. Segment Occurrences | 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 that b[i..i... | 2 | 8 | #include <bits/stdc++.h>
const double EPS = 0.00000001;
const long long mod = 1000000000 + 7;
using namespace std;
string s, t;
int a[2000], sum[2000];
int main() {
cout.sync_with_stdio(0);
int n, m, q;
cin >> n >> m >> q >> s >> t;
for (int i = 0; i < n; i++) {
int is = 1;
for (int j = 0; j < m; j++) {... | CPP |
1016_B. Segment Occurrences | 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 that b[i..i... | 2 | 8 | import java.io.*;
import java.util.*;
public class Mainn {
FastReader scn;
PrintWriter out;
String INPUT = "";
void solve() {
int n = scn.nextInt(), m = scn.nextInt(), q = scn.nextInt(), ind = 0;
String str = scn.next(), s = scn.next();
int[] arr = new int[n], bit = new int[n + 1];
while(str.indexOf(s, in... | JAVA |
1016_B. Segment Occurrences | 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 that b[i..i... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 10;
char s1[maxn], s2[maxn];
int nxt[maxn];
int n, m, q;
void getFail(char *P, int *f) {
f[0] = 0;
f[1] = 0;
for (int i = 1; i < m; i++) {
int j = f[i];
while (j && P[i] != P[j]) j = f[j];
f[i + 1] = P[i] == P[j] ? j + 1 : 0;
}
}
i... | CPP |
1016_B. Segment Occurrences | 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 that b[i..i... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
string st, subSt;
int lenSt, lenSubSt, queries;
vector<int> positions;
int main() {
ios::sync_with_stdio(0);
cin >> lenSt >> lenSubSt >> queries;
cin >> st;
cin >> subSt;
bool found;
for (int i = 0; i < lenSt - (lenSubSt - 1); i++) {
found = true;
for (i... | CPP |
1016_B. Segment Occurrences | 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 that b[i..i... | 2 | 8 | def read():
return int(input())
def readlist():
return list(map(int, input().split()))
def readmap():
return map(int, input().split())
n, m, q = readmap()
S = input()
T = input()
L = []
R = []
for _ in range(q):
l, r = readmap()
L.append(l)
R.append(r)
left = [0] * n
right = [0] * n
for ... | PYTHON3 |
1016_B. Segment Occurrences | 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 that b[i..i... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int match[1000 + 1];
int psum[1000 + 1];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m, q;
cin >> n >> m >> q;
string s, t;
cin >> s >> t;
memset(match, false, sizeof match);
for (int i = 0; i + m - 1 < n; i++) ... | CPP |
1016_B. Segment Occurrences | 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 that b[i..i... | 2 | 8 | tmp=input().split()
n=int(tmp[0])
m=int(tmp[1])
q=int(tmp[2])
arr1=[]
arr2=[]
tmp=input()
for i in tmp:
arr1.append(i)
tmp=input()
for i in tmp:
arr2.append(i)
hash=[0 for i in range(n+10)]
for i in range(n-m+1):
if(arr2==arr1[i:i+m:1]):
hash[i+1]=1
for i in range(1,n+2,1):
hash[i]+=hash[i-1]
for i in range(q):
... | PYTHON3 |
1016_B. Segment Occurrences | 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 that b[i..i... | 2 | 8 | import java.util.*;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Scanner;
import java.util.StringTokenizer;
public class temp {
int lower(ArrayList<Integer> a,int x)
{
int l = 0,r =... | JAVA |
1016_B. Segment Occurrences | 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 that b[i..i... | 2 | 8 | n, m, q = map(int, input().split())
s = input(); t = input()
dictworks = [0]*n
for start in range(n-m+1):
works = True
for i in range(m):
if s[start+i] != t[i]:
works = False
dictworks[start] = works^0
#print(dictworks)
for tc in range(q):
l, r = map(int, input().split())
... | PYTHON3 |
1016_B. Segment Occurrences | 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 that b[i..i... | 2 | 8 | 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 Jenish
*/
public class Ma... | JAVA |
1016_B. Segment Occurrences | 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 that b[i..i... | 2 | 8 | #include <bits/stdc++.h>
const int inf = 1000000005;
const long long INF = 3e18;
const double pi = 2 * acos(0.0);
using namespace std;
int gcd(int a, int b) {
a = abs(a);
b = abs(b);
while (b) {
a = a % b;
swap(a, b);
}
return a;
}
int modInverse(int a, int m) {
int m0 = m;
int y = 0, x = 1;
if ... | CPP |
1016_B. Segment Occurrences | 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 that b[i..i... | 2 | 8 |
n,m,q=map(int,raw_input().split())
s=raw_input()
t=raw_input()
lps=[0]*m
i,l=1,0
while(i<m):
if t[i]==t[l]:
l+=1
lps[i]=l
i+=1
else:
if l==0:
lps[i]=0
i+=1
else: l=lps[l-1]
j=0
ans=[0]*n
pre=[0]*(n+1)
i=0
while i<n:
if t[j]==s[i]:
j+=1... | PYTHON |
1016_B. Segment Occurrences | 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 that b[i..i... | 2 | 8 |
import java.util.*;
public class test
{
/*
private static class IntegerPair implements Comparable
{
public Integer first;
public Integer second;
public IntegerPair(Integer f, Integer s) {
first = f;
second = s;
}
public int compareTo(Object obj)
{
if (!this.first.equals( ((Inte... | JAVA |
1016_B. Segment Occurrences | 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 that b[i..i... | 2 | 8 | //Author: Patel Rag
//Java version "1.8.0_211"
import java.util.*;
import java.io.*;
public class Main
{
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader(){ br = new BufferedReader(new InputStreamReader(System.in)); }
String next()
{
while (st == null |... | JAVA |
1016_B. Segment Occurrences | 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 that b[i..i... | 2 | 8 | # n=int(input())
# ns=[int(x) for x in input().split()]
# dp=[None]*n
# def greater(i,num):
# return ns[i]+ns[i+1]>=num
# def biSearch(t,l,r):
# if r-l<=1:
# return l
# m=(l+r)//2
# if greater(m,t)
#
#
# def update(t):
# l=ns[t]
n,m,q=[int(x)for x in input().split()]
sn=input()
sm=input()
... | PYTHON3 |
1016_B. Segment Occurrences | 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 that b[i..i... | 2 | 8 | import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
public class b{
static void solve(){
int n = ni(), m=ni(), q=ni();
String s = ns(), t=ns();
int[] cnt = new int[n];
for(int i=0;i+m<=n;++i){
for(int j=i;j<i+m;++j){
if(s.charAt(j)!=t.charAt(j-i))break;
if(j==i... | JAVA |
1016_B. Segment Occurrences | 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 that b[i..i... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int main() {
string s, t;
int n, m, q, l, r, f[1010] = {0};
cin >> n >> m >> q;
cin >> s >> t;
for (int i = 0; i < n; i++) {
if (s.substr(i, m) == t) f[i] = 1;
}
for (int T = 0; T < q; T++) {
cin >> l >> r;
int c = 0;
for (int i = l - 1; i <= (... | CPP |
1016_B. Segment Occurrences | 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 that b[i..i... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
const int precision = 16;
const int modulo = 1000000007;
using ll = long long;
const double EPS = 1e-9;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cout.precision(precision);
cout.setf(ios_base::fixed);
int n, m, q;
cin ... | CPP |
1016_B. Segment Occurrences | 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 that b[i..i... | 2 | 8 |
import java.util.Scanner;
public class B {
public static void main(String args[])
{
Scanner scan=new Scanner(System.in);
int n=scan.nextInt();
int m=scan.nextInt();
int q=scan.nextInt();
String s=scan.next();
String t=scan.next();
boolean sad[]=new boolean[n];
int dp[]=new int[n+1];
for(int i=... | JAVA |
1016_B. Segment Occurrences | 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 that b[i..i... | 2 | 8 | //package codeforces.div2;
import java.util.Scanner;
public class SegmentOccurrences {
int dp[];
public void compute(String s, String y) {
dp = new int[s.length() + 1];
for(int i = 1; i <=s.length(); i++) {
String sub = "";
if((i-y.length())>=0) {
sub... | JAVA |
1016_B. Segment Occurrences | 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 that b[i..i... | 2 | 8 | import java.util.*;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int m=sc.nextInt();
int q=sc.nextInt();
int flag[]=new int[1050];
String str1=sc.next();
... | JAVA |
1016_B. Segment Occurrences | 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 that b[i..i... | 2 | 8 | from collections import defaultdict
from math import sqrt,factorial,gcd,log2,inf,ceil
# map(int,input().split())
n,m,q = map(int,input().split())
pref = [0]*(n+1)
s = input()
s1 = input()
for i in range(n):
z = s[i:i+m]
if z == s1:
pref[i+1] = 1
# print(pref)
for i in range(q):
a,b = map(int,input(... | PYTHON3 |
1016_B. Segment Occurrences | 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 that b[i..i... | 2 | 8 | from sys import stdin, stdout
n,m,q=map(int,input().split())
s=input()
t=input()
x=0
dp1=[]
while x<n:
if s[x-m+1:x+1]==t:
dp1.append(1)
else:
dp1.append(0)
x+=1
dp=[[0 for i in range(n)] for j in range(n)]
for i in range(n):
acum=0
for j in range(i,n):
if dp1[j]!=0 and j-m+1... | PYTHON3 |
1016_B. Segment Occurrences | 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 that b[i..i... | 2 | 8 |
import java.util.*;
public class Main {
static int n, m, q, a, b;
static char[] uno, dos;
static int sum[];
static String buffer;
public static void main(String[] args) {
Scanner l = new Scanner(System.in);
n = l.nextInt();
m = l.nextInt();
q = l.nextInt();
... | JAVA |
1016_B. Segment Occurrences | 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 that b[i..i... | 2 | 8 | n,m,q = map(int,input().split())
s = input()
t = input()
len_t = len(t)
len_s = len(s)
ans = ''
for i in range(len_s):
if(s[i:len_t+i] == t):
ans += '1'
else:
ans += '0'
for i in range(q):
l,r = map(int,input().split())
r-=len_t
l-=1
r+=1
r=max(0,r)
l = max(0,l)
if(... | PYTHON3 |
1016_B. Segment Occurrences | 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 that b[i..i... | 2 | 8 | import sys
import itertools
input = sys.stdin.readline
def main():
N, M, Q = [int(x) for x in input().split()]
S = input().strip()
T = input().strip()
LR = [[int(x) for x in input().split()] for _ in range(Q)]
ans = [0] * (N + 1)
for i in range(N):
if S[i:i + M] == T:
ans[... | PYTHON3 |
1016_B. Segment Occurrences | 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 that b[i..i... | 2 | 8 | import java.io.*;
import java.lang.reflect.Array;
import java.util.*;
public class Main {
static int[] z_function (String s) {
int n = (int) s.length();
int[] z = new int[n];
for (int i=1, l=0, r=0; i<n; ++i) {
if (i <= r)
z[i] = Math.min(r-i+1, z[i-l]);
... | JAVA |
103_B. Cthulhu | ...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu...
Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
vector<int> v[102];
bool par[102][102];
bool vis[102];
int cyc = 0;
void dfs(int nd, int p) {
vis[nd] = true;
int z = v[nd].size();
int nx;
for (int i = 0; i < z; i++) {
nx = v[nd][i];
if (vis[nx]) {
if (nx != p && p != 0) {
if (par[nx][nd] || ... | CPP |
103_B. Cthulhu | ...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu...
Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
const long long maxx = 1e6 + 5;
bool dd[maxx], check, d1[maxx];
long long tr[maxx], val[maxx];
long long b, n, m, k, q, a[maxx], c, f[maxx], x, y, tong = 0;
long long bs(long long v) {
long long l1 = 1, h1 = n, m1;
while (l1 <= h1) {
m1 = (l1 + h1) / 2;
if (a[m1... | CPP |
103_B. Cthulhu | ...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu...
Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super... | 2 | 8 | //package algoEx;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.Stack;
public class Cthulhu {
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
// int t = sc.nextInt();
// for(int tc=0;tc<t;tc++)
// {
int n = sc.nextInt();
int m = sc.nextInt();
in... | JAVA |
103_B. Cthulhu | ...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu...
Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int P[100001];
void CreateSet(int x) { P[x] = x; }
int FindSet(int x) {
if (x != P[x]) P[x] = FindSet(P[x]);
return P[x];
}
int MergeSets(int x, int y) {
int PX = FindSet(x);
int PY = FindSet(y);
if (PX == PY) return 0;
P[PX] = PY;
return 1;
}
int main() {
i... | CPP |
103_B. Cthulhu | ...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu...
Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super... | 2 | 8 |
inp = input().split()
n = int(inp[0])
m = int(inp[1])
def dfs(x):
visited.add(x)
for y in e[x]:
if not y in visited:
dfs(y)
if n >= 3 and n == m:
visited = set()
e = [[] for i in range(n + 1)]
for i in range(m):
x, y = map(int, input().split())
... | PYTHON3 |
103_B. Cthulhu | ...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu...
Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super... | 2 | 8 | import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
static ArrayList<ArrayList<Integer> > g = null;
static boolean[] was = null;
static void dfs(int u, int p) {
was[u] = true;
... | JAVA |
103_B. Cthulhu | ...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu...
Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super... | 2 | 8 | import java.io.*;
import java.util.*;
public class C {
String s = null;
String[] ss = null;
String F = "FHTAGN!";
String N = "NO";
int n;
int m;
List<Integer>[] edges = null;
public void run() throws Exception{
BufferedReader br = null;
File file = new File("input.txt");
if(file.exists()){
... | JAVA |
103_B. Cthulhu | ...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu...
Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super... | 2 | 8 | //package codeforcesnew;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
//prob 103B
public class Cthhulhu {
int n;
int m;
int[] visited;
boolean[][] graph;
ArrayList<Integer> list;
Scanner input;
boolean flag;
public Cthhulhu(){
list = new ArrayList<>();
input = new Sca... | JAVA |
103_B. Cthulhu | ...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu...
Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super... | 2 | 8 | /*
ID: govind.3, GhpS, govindpatel
LANG: JAVA
TASK: Main
*/
import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class Main {
/**
* Min segment Tree takes the minimum number at the root
*/
class MinSegmentTree {
/**
* root: Tree root, balance: input array... | JAVA |
103_B. Cthulhu | ...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu...
Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super... | 2 | 8 | from collections import *
from sys import stdin
def arr_inp(n):
if n == 1:
return [int(x) for x in stdin.readline().split()]
elif n == 2:
return [float(x) for x in stdin.readline().split()]
else:
return list(stdin.readline()[:-1])
class disjointset:
def __init__(self, n):
... | PYTHON3 |
103_B. Cthulhu | ...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu...
Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
const long long LINF = 1e18;
const int INF = 1e9;
const long double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int N = 105;
vector<int> adj[N];
bitset<N> vis;
int cycle;
void dfs(int v) {
vis[v] = 1;
for (int& u : adj[v]) {
if (vis[u] == 0) dfs(u);
}
}
int main() ... | CPP |
103_B. Cthulhu | ...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu...
Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super... | 2 | 8 | import java.io.*;
import java.util.*;
public class Graph
{
static Graph graph[];
long cost;
int vis;
int val;
ArrayList<Graph> adj;
static long cos=Long.MAX_VALUE;
Graph(int v)
{
vis=0;
val=v;
cost=0;
adj=new ArrayList<>();
}
public static void ad... | JAVA |
103_B. Cthulhu | ...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu...
Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super... | 2 | 8 | # #include <iostream>
# #include <vector>
# #define N 101
# using namespace std;
# int n, m;
# vector<int> g[N];
# bool vst[N];
# bool dfs(int node){
# if(vst[node]){
# return false;
# }
# }
# int main(){
# ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
# cin >> n >> m;
# int a,... | PYTHON3 |
103_B. Cthulhu | ...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu...
Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super... | 2 | 8 | [n, m] = map(lambda x: int(x), raw_input().split())
verts = []
vertss = {}
count = 0
for i in range(n):
verts.append([])
vertss[i] = 1
#creating adjacency list
for i in range(m):
[a,b] = map(lambda x: int(x) - 1, raw_input().split())
verts[a].append(b)
verts[b].append(a)
arr = [0]
par = [0]
ind =... | PYTHON |
103_B. Cthulhu | ...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu...
Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
const double pi = 2 * acos(0.0);
const int inf = 0x3f3f3f3f;
const double infd = 1.0 / 0.0;
long long power(long long x, long long y, long long MOD) {
long long res = 1;
x = x % MOD;
while (y > 0) {
if (y & 1) res = (res * x) % MOD;
y = y >> 1;
x = (x * x)... | CPP |
103_B. Cthulhu | ...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu...
Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super... | 2 | 8 | import java.util.*;
public class cycledfs
{
public static void main(String ar[])
{
Scanner in=new Scanner(System.in);
int V=in.nextInt();
GraphDFS obj=new GraphDFS(V);
int E = in.nextInt();
for (int i = 0; i < E; i++)
{
int v = in.nextInt();
int w = in.nextInt();
obj.addEdge(v-1, w-1);
... | JAVA |
103_B. Cthulhu | ...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu...
Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int fp(int abc, int parent[]) {
if (parent[abc] == abc) return abc;
int def = fp(parent[abc], parent);
parent[abc] = def;
return def;
}
void cycledmerge(vector<int> hub[], int n, int parent[]) {
stack<int> urutan;
for (int i = 0; i < n; i++) parent[i] = i;
sta... | CPP |
103_B. Cthulhu | ...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu...
Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
const int N = 110;
vector<int> G[N];
int vis[N];
void DFS(int cur) {
vis[cur]++;
int sz = G[cur].size();
int v;
for (int i = 0; i < sz; i++) {
v = G[cur][i];
if (!vis[v]) DFS(v);
}
}
int main() {
int n, m, u, v;
cin >> n >> m;
for (int i = 0; i < m; ... | CPP |
103_B. Cthulhu | ...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu...
Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int n, m, a, b, ciclos, vertice_visited;
int pai[110], vis[110];
vector<int> adj[110];
void dfs(int v) {
vis[v] = 1;
vertice_visited++;
for (int i = 0; i < adj[v].size(); i++) {
int x = adj[v][i];
if (vis[x]) {
if (pai[v] != x) ciclos++;
continue;
... | CPP |
103_B. Cthulhu | ...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu...
Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super... | 2 | 8 | n,m=map(int,input().split())
t=[]
l=[]
l.append(1)
def hambandi(q):
for k in t[q]:
if(not(k in l)):
l.append(k)
hambandi(k)
if(n!=m):
print('NO')
else:
for i in range(n+1):
t.append([])
for kl in range(m):
a,b=map(int,input().split())... | PYTHON3 |
103_B. Cthulhu | ...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu...
Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super... | 2 | 8 | from collections import defaultdict
d=defaultdict(list)
n,m=map(int,input().split())
for i in range(m):
a,b=map(int,input().split())
a-=1
b-=1
d[a].append(b)
d[b].append(a)
vis=[0]*n
q=[0]
vis[0]=1
while q:
t=q.pop(0)
for i in d[t]:
if not vis[i]:
vis[i]=1
... | PYTHON3 |
103_B. Cthulhu | ...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu...
Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
long long power(long long x, unsigned long long y) {
long long temp;
if (y == 0) return 1;
temp = power(x, y / 2);
if (y % 2 == 0)
return temp * temp;
else
return x * temp * temp;
}
long long modpow(long long x, unsigned int y, long long p) {
long long r... | CPP |
103_B. Cthulhu | ...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu...
Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super... | 2 | 8 |
inp = input().split()
n = int(inp[0])
m = int(inp[1])
def dfs(x):
visited.add(x)
for y in e[x]:
if not y in visited:
dfs(y)
if n >= 3 and n == m:
e, visited = [[] for i in range(n + 1)], set()
for j in range(m):
x, y = map(int, input().split())
... | PYTHON3 |
103_B. Cthulhu | ...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu...
Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
vector<int> v[105];
int visit[105];
int c;
void dfs(int i) {
visit[i] = 1;
vector<int>::iterator it;
for (it = v[i].begin(); it != v[i].end(); it++) {
if (visit[(*it)] == 0) {
c++;
dfs((*it));
}
}
}
int main() {
ios_base::sync_with_stdio(0);
... | CPP |
103_B. Cthulhu | ...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu...
Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super... | 2 | 8 | import java.util.Scanner;
public class main {
public static final int MAX = 100;
public static Scanner input = new Scanner(System.in);
static boolean[] arrFlag = new boolean[MAX+1];
static boolean[][] matBool = new boolean[MAX+1][MAX+1];
static int intN = input.nextInt();
static int intM = in... | JAVA |
103_B. Cthulhu | ...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu...
Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 111;
int N, M;
int cnt = 0;
vector<int> node[MAXN];
int visited[MAXN];
void dfs(int cur) {
if (visited[cur]) return;
visited[cur] = true;
cnt++;
for (int i = 0; i < node[cur].size(); i++) dfs(node[cur][i]);
}
int main() {
cin >> N >> M;
for (int... | CPP |
103_B. Cthulhu | ...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu...
Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super... | 2 | 8 | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Vector;
import java.util.Scanner;
import java.util.Stack;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] ar... | JAVA |
103_B. Cthulhu | ...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu...
Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super... | 2 | 8 | #include <bits/stdc++.h>
int N, M;
using namespace std;
int cont = 0;
long long parents[101];
long long find(long long n) {
if (n == parents[n]) {
return n;
}
long long aux = find(parents[n]);
parents[n] = aux;
return find(parents[n]);
}
long long Union(long long n1, long long n2) {
long long p1 = find(... | CPP |
103_B. Cthulhu | ...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu...
Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int maxn = 1e2 + 10;
const double eps = 1e-9;
int mp[maxn][maxn];
int deg[maxn];
int vis[maxn];
int n, m;
void dfs(int u) {
vis[u] = 1;
for (int i = 1; i <= n; i++) {
if (!vis[i] && mp[u][i]) {
dfs(i);... | CPP |
103_B. Cthulhu | ...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu...
Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super... | 2 | 8 | #!/usr/bin/env python3
n, m = map(int, input().rstrip().split())
adj = [[] for i in range(n+1)]
for i in range(m):
u, v = map(int, input().rstrip().split())
adj[u].append(v)
adj[v].append(u)
vis = [False for i in range(n+1)]
ring = [None for i in range(n+1)]
ring_start = None
vis_cnt = 0
def dfs(cur, p... | PYTHON3 |
103_B. Cthulhu | ...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu...
Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
const int N = 200;
int n, m;
int used[N];
vector<int> g[N];
void travel(int u) {
used[u] = 1;
for (auto to : g[u]) {
if (!used[to]) travel(to);
}
}
int cycle_st = -1, cycle_ed = -1;
int p[N];
int dfs(int u, int pr = -1) {
used[u] = 1;
for (auto to : g[u]) {
... | CPP |
103_B. Cthulhu | ...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu...
Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int par[105];
int getpar(int x) {
if (x == par[x]) return par[x];
par[x] = getpar(par[x]);
return par[x];
}
int main() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; ++i) par[i] = i;
for (int i = 1; i <= m; ++i) {
int a, b;
cin >> a >> b;
int p... | CPP |
103_B. Cthulhu | ...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu...
Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int n, m;
int parent[110];
int ranks[110];
int visit[110];
int cycle = 0;
int Findset(int i) {
int root = i;
while (root != parent[root]) root = parent[root];
while (i != root) {
int newp = parent[i];
parent[i] = root;
i = newp;
}
return root;
}
void U... | CPP |
103_B. Cthulhu | ...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu...
Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super... | 2 | 8 | class Nodo:
def __init__(self, value):
self.value = value
self.neighbors = []
def addNeighbor(self, neighbor):
self.neighbors.append(neighbor)
n, m = [int(x) for x in input().split()]
vertices = [None] * (n+1)
for i in range(m):
node1, node2 = [int(x) for x in input().split()]
i... | PYTHON3 |
103_B. Cthulhu | ...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu...
Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super... | 2 | 8 | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.StringTokenizer;
public class Lunes30E
{
static class Sc... | JAVA |
103_B. Cthulhu | ...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu...
Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
vector<int> e[101];
bool used[101];
int cou, d[101];
void dfs(int x, int y, int last) {
d[y] = x;
cou++;
used[x] = 1;
for (int i = 0; i < e[x].size(); i++) {
if (e[x][i] == last) continue;
if (used[e[x][i]]) continue;
dfs(e[x][i], y + 1, x);
}
}
int ma... | CPP |
103_B. Cthulhu | ...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu...
Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super... | 2 | 8 | #include <bits/stdc++.h>
int N, M, lv[105], flg = 0, cnt = 0;
struct EDGE {
int s, f, nxt;
EDGE() {}
EDGE(int a, int b, int c) : s(a), f(b), nxt(c) {}
} edge[105 * 105];
int head[105], pE;
void addedge(int s, int f) {
edge[pE] = EDGE(s, f, head[s]);
head[s] = pE++;
edge[pE] = EDGE(f, s, head[f]);
head[f] ... | CPP |
103_B. Cthulhu | ...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu...
Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super... | 2 | 8 | n, m = map(int, raw_input().split())
f = range(n)
def root(f, u):
r = u
while f[r] != r: r = f[r]
while f[u] != r: f[u], u = r, f[u]
return r
cir = 0
for i in xrange(m):
u, v = map(int, raw_input().split())
u, v = root(f, u - 1), root(f, v - 1)
if u == v:
cir += 1
else:
f[u] = v
conn = set([... | PYTHON |
103_B. Cthulhu | ...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu...
Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super... | 2 | 8 |
import java.util.Scanner;
public class C {
static boolean[] visited;
static int count = 0;
static int n;
static boolean[][] E;
public static void dfs(int x) {
if (visited[x])
return;
visited[x] = true;
count++;
for (int i = 0; i < n; i++)
i... | JAVA |
103_B. Cthulhu | ...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu...
Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int cnt, n, mx, p = 0, parent[101];
void Make_set(int v) { parent[v] = v; }
int Find_set(int v) {
if (parent[v] == v) return v;
return Find_set(parent[v]);
}
void Union_sets(int a, int b) {
a = Find_set(a);
b = Find_set(b);
if (a != b)
parent[b] = a;
else
... | CPP |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.