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
156_A. Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string s and cut out som...
2
7
#include <bits/stdc++.h> using namespace std; char a[5005], b[5005]; int lena, lenb; int data[5005][5005]; int main() { scanf("%s", a + 1); lena = strlen(a + 1); scanf("%s", b + 1); lenb = strlen(b + 1); for (int i = 1; i <= lena; i++) a[i + 2000] = a[i]; for (int i = 1; i <= 2000; i++) a[i] = '@'; int an...
CPP
156_A. Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string s and cut out som...
2
7
s = raw_input() t = raw_input() lt = len(t) ls = len(s) s = "A"*lt + s + "A"*lt m = len(t) for i in xrange(0, lt + ls): m = min(m, sum(1 for a,b in zip(t,s[i:i+lt]) if a!=b)) print m
PYTHON
156_A. Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string s and cut out som...
2
7
#include <bits/stdc++.h> using namespace std; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); string str1, str2; cin >> str1 >> str2; long long len1 = str1.length(); long long len2 = str2.length(); vector<vector<long long>> dp(len1 + 1, vector<long long>(len2 + 1)); long long ans = 0; for (long ...
CPP
156_A. Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string s and cut out som...
2
7
#include <bits/stdc++.h> using namespace std; const long long N = 100001; void solve() { string s, u; cin >> s >> u; long long n = s.length(), m = u.length(), ans = u.length(); for (long long i = 0; i < m + 1; i++) s = '.' + s + '.'; n = s.length(); for (long long i = 0; i < n - m; i++) { long long num ...
CPP
156_A. Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string s and cut out som...
2
7
#include <bits/stdc++.h> using namespace std; int a, t, u, i, j, n; int main() { string s, p; cin >> s >> p; for (u = a = p.size(), t = s.size(); i < u + t; i++, a = min(a, n)) for (n = j = 0; j < u; ++j) n += (((i + j >= u) && (i + j < u + t)) ? (s[i + j - u] != p[j]) : 1); cout << a << endl; }
CPP
156_A. Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string s and cut out som...
2
7
#include <bits/stdc++.h> using namespace std; string s1, s2; int ans = 10000000; int main() { ios_base::sync_with_stdio(0); cin.tie(nullptr); cin >> s1 >> s2; reverse(s1.begin(), s1.end()); for (register int i = 0; i < 2000; i++) s1 += "0"; reverse(s1.begin(), s1.end()); for (register int i = 0; i < s1.si...
CPP
156_A. Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string s and cut out som...
2
7
#include <bits/stdc++.h> using namespace std; int main() { string a, b; cin >> a >> b; int s1 = a.size(); int s2 = b.size(); int ans = 2010; int ss = s2; for (int i = 1; i < s2; i++) { int num = 0; for (int k = i, j = 0; k < s2 && j < s1; k++, j++) { if (b[k] == a[j]) num++; } ans = ...
CPP
156_A. Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string s and cut out som...
2
7
import javax.print.attribute.standard.PrintQuality; import java.awt.*; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.math.BigInteger; import java.util.*; import java.util.List; public class Main { static int mod = (int) 1e9 + 7;...
JAVA
156_A. Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string s and cut out som...
2
7
import java.awt.*; import java.awt.geom.*; import java.io.*; import java.math.*; import java.text.*; import java.util.*; /* br = new BufferedReader(new FileReader("input.txt")); pw = new PrintWriter(new BufferedWriter(new FileWriter("output.txt"))); br = new BufferedReader(new InputStreamReader(System.in)); pw = ...
JAVA
156_A. Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string s and cut out som...
2
7
#include <bits/stdc++.h> const int MAX_LEN = 1010; using namespace std; template <typename U, typename V> string to_string(pair<U, V>); string to_string(const string& e_) { return "\"" + e_ + "\""; } string to_string(char e_) { return "\'" + string(1, e_) + "\'"; } string to_string(bool e_) { return e_ ? "true" : "fals...
CPP
156_A. Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string s and cut out som...
2
7
// practice with kaiboy import java.io.*; import java.util.*; public class CF157C extends PrintWriter { CF157C() { super(System.out, true); } Scanner sc = new Scanner(System.in); public static void main(String[] $) { CF157C o = new CF157C(); o.main(); o.flush(); } void main() { byte[] aa = sc.next().getBytes...
JAVA
156_A. Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string s and cut out som...
2
7
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper...
JAVA
156_A. Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string s and cut out som...
2
7
#include <bits/stdc++.h> using namespace std; int main() { string s, t; string r; cin >> s >> t; r = t; for (int i = 0; i < t.length(); i++) { r[i] = '.'; } s = r + s + r; int mn = 10000000; for (int i = 0; i + t.length() - 1 < s.length(); i++) { int count = 0; for (int j = 0; j < t.length...
CPP
156_A. Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string s and cut out som...
2
7
#include <bits/stdc++.h> using namespace std; string a, b; int res; int main() { cin >> a >> b; a = string(b.length(), '.') + a + string(b.length(), '.'); res = b.length(); for (int i = 0; i + b.length() <= a.length(); i++) { int cand = 0; for (int j = 0; j < b.length(); j++) cand += a[i + j] != b[j]; ...
CPP
156_A. Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string s and cut out som...
2
7
#include <bits/stdc++.h> using namespace std; const int maxs = 2e3 + 5; int lengthStr, lengthW; string str, wanted; int main() { cin >> str; cin >> wanted; lengthW = wanted.length(); int cnt = lengthW; for (int i = 0; i < lengthW; i++) str = '#' + str; for (int i = 0; i < lengthW; i++) str += '#'; lengthS...
CPP
156_A. Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string s and cut out som...
2
7
#include <bits/stdc++.h> using namespace std; string s1, s2; int main() { cin >> s1 >> s2; int ans = 100000, len = s2.size(); s1 = string(len, '+') + s1 + string(len, '+'); for (int i = 0; i <= s1.size() - s2.size(); i++) { int tmp = 0; for (int j = 0; j < s2.size(); j++) if (s2[j] != s1[i + j]) t...
CPP
156_A. Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string s and cut out som...
2
7
#include <bits/stdc++.h> using namespace std; const int MAX = 2005; char s[MAX], t[MAX]; int ret, l1, l2, dp[MAX][MAX]; int main() { scanf("%s%s", s + 1, t + 1); l1 = strlen(s + 1), l2 = strlen(t + 1); for (int i = 1; i <= (l1); i++) for (int j = 1; j <= (l2); j++) dp[i][j] = max(dp[i][j], dp[i - 1][j -...
CPP
156_A. Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string s and cut out som...
2
7
#include <bits/stdc++.h> char a[2005], b[2005]; int main() { int n, m; int i, j; int cur, ans; scanf("%s%s", a, b); n = (int)strlen(a); m = (int)strlen(b); ans = m; for (i = -m - 1; i < n; i++) { cur = 0; for (j = 0; j < m; j++) { if (i + j < 0 || i + j >= n) { ++cur; } else ...
CPP
156_A. Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string s and cut out som...
2
7
import java.util.*; import java.math.*; public class Main{ public static void main(String [] args) { Scanner scan=new Scanner(System.in); String s=scan.next(); String t=scan.next(); int n=t.length(); for(int i=0; i< n ; i++) s = " " + s; for(...
JAVA
156_A. Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string s and cut out som...
2
7
#include <bits/stdc++.h> template <typename T> T inline SQR(const T &a) { return a * a; } template <typename T> T inline ABS(const T &a) { return a < 0 ? -a : a; } const double EPS = 1e-9; inline int SGN(double a) { return ((a > EPS) ? (1) : ((a < -EPS) ? (-1) : (0))); } inline int CMP(double a, double b) { retur...
CPP
156_A. Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string s and cut out som...
2
7
import java.util.Scanner; public class Problem157 { public static void main(String[] args) { new Problem157().solve(); } public void solve() { int minChanges = uStr.length(); for (int i = 0; i < sStr.length() + uStr.length() - 1; i++) { int curChanges = computeChanges(i); if (curChanges < minChanges) {...
JAVA
156_A. Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string s and cut out som...
2
7
#include <bits/stdc++.h> using namespace std; string s1, s2; int n, m; int memo[2222][2222][2]; int cal(int i, int j, bool dx) { if (memo[i][j][dx] != -1) return memo[i][j][dx]; if (j == m) return memo[i][j][dx] = 0; if (i == n) return memo[i][j][dx] = m - j; if (s1[i] != s2[j]) { if (dx) { return mem...
CPP
156_A. Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string s and cut out som...
2
7
#include <bits/stdc++.h> int main() { char a[5000]; char b[5000]; int i, j, k; while (~scanf("%s %s", a, b)) { int len1 = strlen(a); int len2 = strlen(b); int len = 0; for (i = 0; i < len1; i++) { int cut = 0; for (j = 0; j < len2; j++) { if (a[i + j] == b[j]) { cut...
CPP
156_A. Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string s and cut out som...
2
7
import sys import re import time time.sleep(3) s = raw_input() u = raw_input() s = '.'*(len(u)-1)+s+'.'*(len(u)-1) def diff(src, pat): k = 0 for i in xrange(len(src)): if src[i]!=pat[i] or src[i] == '.': k+=1 return k ml = len(u) for i in xrange(len(s)-len(u)+1): tl = diff(s[i:i+len(u)], u) if tl...
PYTHON
156_A. Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string s and cut out som...
2
7
#include <bits/stdc++.h> using namespace std; const int INF = 2147483647; const long long LLINF = 9223372036854775807LL; int main() { string s, u; cin >> s >> u; string t = ""; for (int i = 0; i < (int)u.length() - 1; ++i) t += "#"; s = t + s + t; int best = INF; for (int i = 0; i + u.length() <= s.length...
CPP
156_A. Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string s and cut out som...
2
7
import java.util.Scanner; public class C { public static void main(String[] args) { Scanner myScanner = new Scanner(System.in); String s = myScanner.next(), u = myScanner.next(); for (int i = 0; i < u.length(); i++) s = 'A' + s + 'A'; String sub = ""; int min = ...
JAVA
156_A. Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string s and cut out som...
2
7
/** * User: Sergey Epifanov * Date: 07.05.12 */ import java.io.*; import java.util.Scanner; public class E157CMessage { public static void main(String args[]) throws IOException { new E157CMessage().run(); } private Scanner in; private PrintWriter out; private void run() throws IOExc...
JAVA
156_A. Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string s and cut out som...
2
7
import java.util.*; import java.io.*; public class Message { public static void main(String[] args) throws Exception{ // TODO Auto-generated method stub BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out); int max = Integer.MIN_VALUE; ...
JAVA
156_A. Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string s and cut out som...
2
7
x,y=input(),input() res=[0]*len(x) dicc ={i:[] for i in "abcdefghijklmnopqrstuvwxyz"} for i,j in enumerate(x): dicc[j].append(i) for i in y: for j in dicc[i]: res[j]+=1 res=[0]+res print(len(y)-max(res))
PYTHON3
156_A. Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string s and cut out som...
2
7
#include <bits/stdc++.h> using namespace std; string s, t; int ans = 30000; int main() { cin >> s; cin >> t; for (int i = 0; i < 2000; i++) s = '#' + s; for (int i = 0; i < 2000; i++) s = s + '#'; for (int i = 0; i < s.size() - t.size() + 1; i++) { string str = ""; for (int j = 0; j < t.size(); j++) s...
CPP
156_A. Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string s and cut out som...
2
7
#include <bits/stdc++.h> using namespace std; const int N = (int)1e5 + 123; const int INF = (int)1e9 + 123; const double eps = 1e-6; int diff, mn = INF; string s, u; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cin >> s; cin >> u; for (int i = 0; i < u.size(); i++) { s = "$" + s; } for (i...
CPP
156_A. Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string s and cut out som...
2
7
import java.util.Scanner; public class Prob156A { public static void main(String[] Args) { Scanner in = new Scanner(System.in); String s1 = in.next(); String s2 = in.next(); int[][] dp = new int[s1.length()][s2.length()]; for (int i = 0; i < s2.length(); i++) dp[0][i] = i; for (int i = 0; i < s1.len...
JAVA
156_A. Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string s and cut out som...
2
7
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class Message { public static void main(String[] args) throws IOException { br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out ...
JAVA
156_A. Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string s and cut out som...
2
7
import java.util.*; import java.io.*; public class Solution implements Runnable { final static int INF = 1000000000; public void run() { try { in = new BufferedReader(new InputStreamReader(System.in)); st = new StringTokenizer(""); char[] a = next().toCharArray(); ...
JAVA
156_A. Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string s and cut out som...
2
7
#include <bits/stdc++.h> int dp[2010][2010]; int len1, len2; char s1[2010], s2[2010]; int cal(int ind1, int ind2); int mini(int a, int b) { if (a < b) return a; return b; } int main() { int i, j, k, l, test, t = 1; scanf("%s", s1 + 1); scanf("%s", s2 + 1); len1 = strlen(s1 + 1); len2 = strlen(s2 + 1); m...
CPP
156_A. Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string s and cut out som...
2
7
#include <bits/stdc++.h> using namespace std; int main() { int l1, l2, i, j, x, c; string s1, s2; cin >> s1; cin >> s2; l1 = s1.length(); l2 = s2.length(); x = l2; for (i = -l2; i < l1; i++) { c = 0; for (j = 0; j < l2; j++) { if (c > x) break; if ((i + j < 0) || (i + j >= l1) || (s1...
CPP
156_A. Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string s and cut out som...
2
7
import java.util.*; public class Problem0156a { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String s = sc.next(); String u = sc.next(); int min = u.length(); for (int i = -(u.length()-1); i < s.length(); i++) { int ans = u.length(...
JAVA
156_A. Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string s and cut out som...
2
7
#include <bits/stdc++.h> using namespace std; int main() { string x, s, u; int ans = 2001; cin >> s >> u; for (int i = 0; i < u.length(); i++) x += '*'; s = x + s + x; for (int i = 0; i < s.length(); i++) { int temp = u.length(); for (int j = 0; j < u.length() && i + j < s.length(); j++) { if ...
CPP
156_A. Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string s and cut out som...
2
7
#include <bits/stdc++.h> using namespace std; using namespace std; int pd[2010][2010]; char s[2010], t[2010]; int main() { string s, t; int maxi = 0; cin >> s >> t; for (int i = int(0); i <= int(s.size() - 1); i++) for (int j = int(0); j <= int(t.size() - 1); j++) { if (!i || !j) pd[i][j] = s[...
CPP
156_A. Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string s and cut out som...
2
7
import java.util.Scanner; public class C_110C { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String a = sc.next(); String b = sc.next(); for (int i = 0; i < b.length(); i++) { a +="#"; } for (int i = 0; i < b.length(); i++) { a ="#"+a; } int ans = Integer.MAX_...
JAVA
156_A. Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string s and cut out som...
2
7
; import java.io.*; import java.util.*; public class Abc { public static void main(String[] args) throws IOException { FastReader sc = new FastReader(); String ss=sc.next(),uu=sc.next(); int max=0; for (int i=0;i< ss.length();i++){ int cnt=0; for (int j=0;j<u...
JAVA
156_A. Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string s and cut out som...
2
7
#include <bits/stdc++.h> using namespace std; string s, t; long dp[2005][2005]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> s >> t; long L = t.size(), ans = 0; for (long i = s.size() - 1; i >= 0; i--) for (long j = L - 1; j >= 0; j--) { ans = max(ans, dp[i][j] = (s[i...
CPP
156_A. Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string s and cut out som...
2
7
import java.util.Scanner; import java.util.Vector; public class Main { public static void main(String[] args) { Scanner sc = new Scanner (System.in); String s1 = sc.next(); String s2 = sc.next(); Vector <Integer> anss = new Vector <Integer>(); for (int i = -s2.len...
JAVA
156_A. Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string s and cut out som...
2
7
import java.util.*; public class Solution { public static void main(String[] args) { Scanner ssc = new Scanner(System.in); String s = ssc.nextLine(); String u = ssc.nextLine(); String u2=u; int sl = s.length(); int ul = u.length(); int k = 0; int MaxSame=0; while(k < sl) { int same = ...
JAVA
156_A. Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string s and cut out som...
2
7
import java.util.Arrays; import java.util.Scanner; import java.util.regex.*; import java.math.*; public class problem{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); String s1=sc.nextLine(); String s2=sc.nextLine(); String s3=""; for (int i=0;i<2100;i++) ...
JAVA
156_A. Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string s and cut out som...
2
7
from sys import stdin first = stdin.readline().strip() second = stdin.readline().strip() minChange = 2001 first = '@' * (len(second) - 1) + first + '@' * (len(second) - 1) diff = len(first) - len(second) for i in range(0, diff + 1): line = '@' * i + second + '@' * (diff - i) result = 0 for i in range(i,...
PYTHON3
156_A. Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string s and cut out som...
2
7
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 10; const long long inf = -1e18; const long long INF = 1e18; const long long mod = 1e9 + 7; const double PI = acos(-1); string a, b; int l, r, f, ans = 80000, cnt, z[5010]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL), cout.tie(...
CPP
156_A. Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string s and cut out som...
2
7
#include <bits/stdc++.h> using namespace std; const int MAXL = 2000 + 1; string s1, s2; int l1, l2, sol = 0, cu, ci; int main(int argc, char const *argv[]) { cin >> s1 >> s2; l1 = s1.length(); l2 = s2.length(); for (int i = 0; i < l1 + l2 - 1; i++) { cu = 0; for (int j = 0; j < l1; j++) { ci = j +...
CPP
156_A. Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string s and cut out som...
2
7
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); string s, t; cin >> s >> t; int n = s.size(), m = t.size(); int ans = 1e5; for (int i = 0; i < n; i++) { int ct = 0; for (int j = 0; j < m and i + j < n; j++) { if (s...
CPP
156_A. Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string s and cut out som...
2
7
import java.io.*; import java.util.LinkedList; import java.util.List; /** * Author: Vasiliy Homutov - vasiliy.homutov@gmail.com * Date: 02.05.12 * See: http://codeforces.ru/problemset/problem/157/C */ public class Message { public static class MessageHelper { private static String iterateChar(char ...
JAVA
156_A. Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string s and cut out som...
2
7
import java.util.Arrays; import java.util.Scanner; /** * Alexandra Mikhaylova mikhaylova@yandex-team.ru */ public class E { private final static int MAX_MSG_SIZE = 2000; private static String BAD_SYMBOLS = getBadSymbols(); private static String getBadSymbols() { char[] badSymbols = new char[MAX_...
JAVA
156_A. Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string s and cut out som...
2
7
#include <bits/stdc++.h> using namespace std; const int N = 2002; const int MOD = 1e9 + 7; string s, s1; int dp[N][N]; int go(int idx, int idx1) { if (idx == s.size() || idx1 == s1.size()) { return s1.size() - idx1; } if (dp[idx][idx1] != -1) return dp[idx][idx1]; int x; if (s[idx] == s1[idx1]) { x = ...
CPP
156_A. Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string s and cut out som...
2
7
#include <bits/stdc++.h> using namespace std; const int MAX_N = 7 + 2000; char str[MAX_N]; char des[MAX_N]; int main() { scanf(" %s", str); int strn = strlen(str); scanf(" %s", des); int desn = strlen(des); int ans = 0; for (int i = (0); i < (strn); i++) { int tmp = 0; for (int j = (0); j < (desn); ...
CPP
156_A. Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string s and cut out som...
2
7
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Scanner; public class Task157C { public static void main(String[] args) throws IOException { new Task157C().run(); } public void run() throws IOException { ...
JAVA
156_A. Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string s and cut out som...
2
7
#include <bits/stdc++.h> using namespace std; const int DX[8] = {1, -1, 0, 0, 1, 1, -1, -1}; const int DY[8] = {0, 0, 1, -1, 1, -1, 1, -1}; char s1[5005], s2[5005]; int main() { memset(s1, 0, sizeof(s1)); memset(s2, 0, sizeof(s2)); scanf("%s%s", s1, s2); int l1 = strlen(s1); int l2 = strlen(s2); int ans = 1...
CPP
156_A. Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string s and cut out som...
2
7
import java.io.BufferedReader; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.io.StreamTokenizer; import java.util.ArrayList; public class Main { public static void main(String[] args) throws Exception { ...
JAVA
156_A. Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string s and cut out som...
2
7
import javafx.geometry.Pos; import javafx.util.Pair; import java.io.*; import java.lang.reflect.Array; import java.math.BigInteger; import java.security.cert.PolicyNode; import java.util.*; import java.util.jar.Pack200; public class Solution { BufferedReader in; PrintWriter out; StringTokenizer st; S...
JAVA
156_A. Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string s and cut out som...
2
7
import java.util.*; import java.io.*; import java.math.*; public class Main { static class Reader { private InputStream mIs;private byte[] buf = new byte[1024];private int curChar,numChars;public Reader() { this(System.in); }public Reader(InputStream is) { mIs = is;} public int read() {if (nu...
JAVA
156_A. Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string s and cut out som...
2
7
s, u = raw_input(), raw_input() t = [0] * len(s) p = {i: [] for i in 'abcdefghijklmnopqrstuvwxyz'} for i, j in enumerate(s): p[j].append(i) for j in u: for i in p[j]: t[i] += 1 t = [0] + t print len(u) - max(t)
PYTHON
156_A. Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string s and cut out som...
2
7
#include <bits/stdc++.h> using namespace std; string A, B; int ans; int main() { cin >> A >> B; ans = ((int)(B).size()); for (int i = -((int)(B).size()); i < ((int)(A).size()); ++i) { int dif = 0; for (int j = 0; j < ((int)(B).size()); ++j) { if (i + j >= 0 && i + j < ((int)(A).size())) { if...
CPP
156_A. Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string s and cut out som...
2
7
import java.util.Arrays; import java.util.Scanner; public class C { static String s; static String t; static int tLength; public static void main(String[] args) { // TODO Auto-generated method stub Scanner scanner = new Scanner(System.in); s = scanner.next(); t = scanner.next(); tLength = t.leng...
JAVA
156_A. Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string s and cut out som...
2
7
#include <bits/stdc++.h> using namespace std; void divideByZero(const char *error) { printf(error); fclose(stdout); int a = 234; a = a / (a - a); } long parseLong() { long temp; scanf("%ld", &temp); return temp; } char s[3000], u[3000]; int main() { scanf("%s", &s); scanf("%s", &u); long n = strlen(...
CPP
156_A. Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string s and cut out som...
2
7
#include <bits/stdc++.h> using namespace std; string second, T; int main() { cin >> second >> T; int res = 0, i; for (int a = 0, b = ((int)T.size()) - 1; a < ((int)second.size()); b <= 0 ? a++ : b--) { int cnt = 0; for (i = 0; a + i < ((int)second.size()) && b + i < ((int)T.size()); i++) { if...
CPP
156_A. Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string s and cut out som...
2
7
def get_similarity(str1, str2): str_len = len(str1) str_len = str_len if str_len < len(str2) else len(str2) similarity = 0 for i in range(str_len): if str1[i] == str2[i]: similarity += 1 return similarity s = input() u = input() cnt = 0 s_len = len(s) u_len = len(u) simila...
PYTHON3
177_E2. Space Voyage
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet. The Smart Beaver is going to bring som...
2
11
#include <bits/stdc++.h> using namespace std; const int MaxN = 10005; int a[MaxN], b[MaxN]; int N, C; long long sol(long long d, long long C) { long long ret = 0; for (int i = 0; i < N; i++) { ret += a[i] * d / b[i]; if (ret > C) return C + 1; } return ret; } long long getA(long long C) { long long L ...
CPP
177_E2. Space Voyage
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet. The Smart Beaver is going to bring som...
2
11
import java.io.*; import java.math.*; import java.util.*; public class SpaceVoyage { private static final long X_MAX = 1010101010101010101L; private static final long INF = 1234567890987654321L; public static void solve(FastIO io) { int N = io.nextInt(); long C = io.nextLong(); lo...
JAVA
177_E2. Space Voyage
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet. The Smart Beaver is going to bring som...
2
11
#include <bits/stdc++.h> using namespace std; long long n, c, a[100005], b[100005]; int i; long long check(long long x) { int i; long long sum = 0; for (i = 1; i <= n; ++i) { if (1. * x * a[i] / b[i] > c + 1) return c + 1; sum += 1ll * x * a[i] / b[i] + 1; if (sum > c) return c + 1; } return sum; ...
CPP
177_E2. Space Voyage
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet. The Smart Beaver is going to bring som...
2
11
#include <bits/stdc++.h> using namespace std; int n; long long c; vector<long long> a, b; long long f(long long x) { long long s = 0; for (int i = 0; i < n; ++i) { if (a[i] > 0 && x > (c + 1) * b[i] / a[i]) return c + 1; s += a[i] * x / b[i]; } return s; } int main() { cin >> n >> c; c -= n; if (c...
CPP
177_E2. Space Voyage
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet. The Smart Beaver is going to bring som...
2
11
#include <bits/stdc++.h> using namespace std; long long a, b, c, d, e, f, ki, ka, mid, ma; long long zz[10005], zz2[10005]; int main() { ma = 1; scanf("%I64d %I64d", &a, &b); for (c = 1; c <= a; c++) { scanf("%I64d %I64d", &zz[c], &zz2[c]); if (zz[c] > ma) ma = zz[c]; } ki = 1; ka = 1000000000000000...
CPP
177_E2. Space Voyage
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet. The Smart Beaver is going to bring som...
2
11
#!/usr/bin/env python2 def read_ints(): return map(int, raw_input().split()) n, c = read_ints() a = [0] * n b = [0] * n for i in xrange(n): a[i], b[i] = read_ints() def calc_days(x): res = 0 for i in range(n): res += 1 res += a[i] * x / b[i] return res const = 10 ** 20 #lower bound l = 1 r = const whil...
PYTHON
177_E2. Space Voyage
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet. The Smart Beaver is going to bring som...
2
11
#include <bits/stdc++.h> using namespace std; long long BigMod(long long B, long long P, long long M) { long long R = 1; while (P > 0) { if (P % 2 == 1) { R = (R * B) % M; } P /= 2; B = (B * B) % M; } return R; } long long n, c; vector<pair<long long, long long> > v; long long valid(long l...
CPP
177_E2. Space Voyage
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet. The Smart Beaver is going to bring som...
2
11
import java.util.*; import java.io.*; import java.math.*; public class Main implements Runnable { final int MAXN = 1 << 17; final BigInteger INF = new BigInteger("100000000000000000000"); int N; BigInteger C; BigInteger[] a = new BigInteger[MAXN]; BigInteger[] b = new BigInteger[MAXN]; BigInteger getSum...
JAVA
177_E2. Space Voyage
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet. The Smart Beaver is going to bring som...
2
11
import java.io.IOException; import java.math.BigDecimal; import java.util.Scanner; public class Main { //177/E2 public static void main(String[] zzz) throws IOException { try (Scanner in = new Scanner(System.in)) { int[] args = toIntArray(in.nextLine(), 2); int planetsCount = ar...
JAVA
177_E2. Space Voyage
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet. The Smart Beaver is going to bring som...
2
11
# by the authority of GOD author: manhar singh sachdev # import os,sys from io import BytesIO, IOBase def check(a,b,tar,x): ans = 0 for i in range(len(a)): ans += (a[i]*x)//b[i] if ans == tar: return 0 elif ans > tar: return 1 else: return -1 def main(): n,c ...
PYTHON3
177_E2. Space Voyage
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet. The Smart Beaver is going to bring som...
2
11
I=lambda:map(int,input().split()) n,c=I() a,b=[],[] for _ in range(n):x,y=I();a.append(x);b.append(y) if max(a)==0:print([0,-1][n==c]);exit() def f(x): r=0 for i in range(n): r+=1+a[i]*x//b[i] if r>c:break return r l=-1 r=10**18 while l<r-1: m=(l+r)//2 if f(m)<c:l=m else:r=m L=r l=-1 r=10**18 while l<r-1: m=...
PYTHON3
177_E2. Space Voyage
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet. The Smart Beaver is going to bring som...
2
11
import java.util.*; import java.math.*; public class e { int N; BigInteger C; BigInteger as[] = new BigInteger[10009]; BigInteger bs[] = new BigInteger[10009]; int check(BigInteger x) { BigInteger alc = BigInteger.ZERO; for(int i = 1; i <= N; i++) { alc = al...
JAVA
177_E2. Space Voyage
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet. The Smart Beaver is going to bring som...
2
11
import java.util.*; import java.io.*; public class Main implements Runnable { public void solve() throws IOException { int N = nextInt(); int D = nextInt(); D -= N; if(D < 0){ System.out.println(0); return; ...
JAVA
177_E2. Space Voyage
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet. The Smart Beaver is going to bring som...
2
11
#include <bits/stdc++.h> using namespace std; const int N = 1e4 + 1; int n, a[N], b[N]; long long get(long long mid) { long long sum = 0; for (int i = 0; i < n; i++) sum += 1 + 1LL * mid * a[i] / b[i]; return sum; } int main() { int c; cin >> n >> c; for (int i = 0; i < n; i++) cin >> a[i] >> b[i]; long l...
CPP
177_E2. Space Voyage
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet. The Smart Beaver is going to bring som...
2
11
#include <bits/stdc++.h> using namespace std; long long n, m, c, a[10003], b[10003], l, r, lans, rans; long long check(long long x) { long long ret = n; for (int i = 1; i <= n; i++) { ret += (a[i] * x) / b[i]; if (ret > c) break; } if (ret < 0) ret = c + 1; return ret; } int main() { scanf("%I64d%I6...
CPP
177_E2. Space Voyage
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet. The Smart Beaver is going to bring som...
2
11
#include <bits/stdc++.h> using namespace std; const int inf = 1000000000; const int MOD = 1000000007; unsigned long long a[10005], b[10007]; unsigned long long n, c; unsigned long long ok(unsigned long long x) { unsigned long long cnt = n; for (int i = 1; i <= n; ++i) { if (a[i] && x / b[i] + cnt > c) return c ...
CPP
177_E2. Space Voyage
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet. The Smart Beaver is going to bring som...
2
11
//package abbyy2.easy; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; public class EL { InputStream is; PrintWriter out; String INPUT = ""; void solve() { int n = ni(), c = ni(); int[] a = new int[n]; int[] ...
JAVA
177_E2. Space Voyage
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet. The Smart Beaver is going to bring som...
2
11
#include <bits/stdc++.h> using namespace std; inline int rdi() { int d; scanf("%d", &d); return d; } inline char rdc() { scanf(" "); return getchar(); } inline string rds() { string s; cin >> s; return s; } inline double rddb() { double d; scanf("%lf", &d); return d; } template <class T> inline bo...
CPP
177_E2. Space Voyage
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet. The Smart Beaver is going to bring som...
2
11
n, c = map(int, input().split()) a = [] b = [] for i in range(n): aa, bb = map(int, input().split()) a.append(aa) b.append(bb) def all_zero(): for aa in a: if aa > 0: return False return True def days(x): c = 0 for aa, bb in zip(a, b): c += 1 + aa*x//bb return c def ru...
PYTHON3
177_E2. Space Voyage
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet. The Smart Beaver is going to bring som...
2
11
#include <bits/stdc++.h> using namespace std; const int N = 10005; int a[N], b[N], n; long long k; double eps = 1e-6; bool check(long long x) { long long res = 0; for (int i = 0; i < n; i++) { if ((double)a[i] * x / b[i] - k >= 1000) return 1; if (res >= k - a[i] * x / b[i]) return 1; res += a[i] * x / ...
CPP
177_E2. Space Voyage
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet. The Smart Beaver is going to bring som...
2
11
#include <bits/stdc++.h> using namespace std; long long l, r, mid, ans; int n, c, a[220000], b[220000], i; long long check(long long mid) { long long res = 0; for (int i = 1; i <= n; ++i) { if (a[i] != 0 && mid / b[i] > c / a[i]) return 1e10; res += mid * a[i] / b[i]; } return res; } int main() { scan...
CPP
177_E2. Space Voyage
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet. The Smart Beaver is going to bring som...
2
11
#include <bits/stdc++.h> using namespace std; unsigned long long ans[2], *A, *B; int n; unsigned long long check(unsigned long long x) { unsigned long long res = n; for (int i = 0; i < n; i++) { res += A[i] * x / B[i]; } return res; } int main() { unsigned long long c; cin >> n >> c; A = new unsigned ...
CPP
177_E2. Space Voyage
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet. The Smart Beaver is going to bring som...
2
11
#include <bits/stdc++.h> using namespace std; template <class t, class u> void chmax(t& first, u second) { if (first < second) first = second; } template <class t, class u> void chmin(t& first, u second) { if (second < first) first = second; } vector<unsigned long long int> ai, bi; int n; unsigned long long int c; ...
CPP
177_E2. Space Voyage
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet. The Smart Beaver is going to bring som...
2
11
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const double eps = 1e-6; const int INF = 1000000000; const int mod = 1e9 + 7; const int maxn = 2e5 + 5; vector<unsigned long long> v1(maxn); vector<unsigned long long> v2(maxn); unsigned long long n, c; const unsigned long long oo = 10000000000...
CPP
177_E2. Space Voyage
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet. The Smart Beaver is going to bring som...
2
11
import java.io.*; import java.util.*; import java.math.*; public class JSolution { static Scanner in; static PrintWriter out; static int n; static long c; static long[] a, b; public static void main(String[] args) throws Throwable { //in = new Scanner(new FileInputStream("input.txt"))...
JAVA
177_E2. Space Voyage
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet. The Smart Beaver is going to bring som...
2
11
import java.util.Comparator; import java.io.OutputStream; import java.io.PrintWriter; import java.util.AbstractList; import java.io.Writer; import java.util.Collection; import java.util.List; import java.io.IOException; import java.util.InputMismatchException; import java.util.ArrayList; import java.math.BigInteger; im...
JAVA
177_E2. Space Voyage
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet. The Smart Beaver is going to bring som...
2
11
#include <bits/stdc++.h> const long long high2 = 9223372036854775804; using namespace std; int i, n, m, x, y, xa = 0, sum, cnt = 0; vector<unsigned long long> a, b; long long l, r, avg, res1, res2, o, c; unsigned long long xy; long long go2(long long z) { xy = 0; unsigned long long xold = 0; long double xtr = 0; ...
CPP
177_E2. Space Voyage
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet. The Smart Beaver is going to bring som...
2
11
#include <bits/stdc++.h> using namespace std; int a[10010], b[10010]; int n, m; int check(long long x) { long long s = n; int i; for (i = 1; i <= n; i++) { if (a[i] != 0 && x / b[i] > m / a[i]) return 1; s = s + x * a[i] / b[i]; } if (s > m) return 1; else if (s < m) return -1; else if (s ...
CPP
177_E2. Space Voyage
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet. The Smart Beaver is going to bring som...
2
11
import java.awt.Point; import java.io.*; import java.math.BigInteger; import java.util.*; import static java.lang.Math.*; public class E implements Runnable{ final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null; BufferedReader in; PrintWriter out; StringTokenizer tok = n...
JAVA
177_E2. Space Voyage
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet. The Smart Beaver is going to bring som...
2
11
import java.io.BufferedReader; import java.io.InputStreamReader; import java.math.BigInteger; public class CF177E { static int n; static long c; static long[] a, b; static int cmp(BigInteger x) { BigInteger sum = BigInteger.ZERO; for (int i = 0; i < n; i++) { BigInteger ai...
JAVA
177_E2. Space Voyage
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet. The Smart Beaver is going to bring som...
2
11
#include <bits/stdc++.h> using namespace std; const int MAX = 2e4 + 9; long long l, r, mid, ans, n, c, a[MAX], b[MAX], i, ql, qr; long long check(long long mid) { long long res = 0; for (int i = 1; i <= n; i++) { if (a[i] != 0 && mid / b[i] > c / a[i]) return 1e10; res += mid * a[i] / b[i]; } return res...
CPP
177_E2. Space Voyage
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet. The Smart Beaver is going to bring som...
2
11
#include <bits/stdc++.h> using namespace std; const int MAX_N = 11111; int n, c; long long a[MAX_N], b[MAX_N]; long long cal(long long x) { long long sum = n; for (int i = int(1); i <= int(n); ++i) { if (a[i] && x / b[i] > c / a[i]) return c + 1; sum += (x * a[i]) / b[i]; if (sum > c) return c + 1; } ...
CPP
177_E2. Space Voyage
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet. The Smart Beaver is going to bring som...
2
11
#include <bits/stdc++.h> using namespace std; const int N = 1e4 + 5; int a[N], b[N], c, n; int check(long long M) { long long ret = 0; for (int i = 0; i < n; i++) { if (ret > c) return c + 1; if (a[i] >= b[i] && M > c) return c + 1; ret = ret + (M / b[i]) * a[i] + (M % b[i]) * a[i] / b[i] + 1; } if ...
CPP
177_E2. Space Voyage
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet. The Smart Beaver is going to bring som...
2
11
#include <bits/stdc++.h> using namespace std; const int N = 1e4 + 7; const long long BIG = 1e18; int n, c; int a[N], b[N]; void input() { scanf("%d %d", &n, &c); for (int i = (0); i < (n); i++) { scanf("%d %d", &a[i], &b[i]); } } int comp(long long M) { long long sum = 0; for (int i = (0); i < (n); i++) {...
CPP
177_E2. Space Voyage
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet. The Smart Beaver is going to bring som...
2
11
#include <bits/stdc++.h> int main() { int n, c; int a[10000]; int b[10000]; int v(0); long long t, w, k, s, e; long long r[] = {-1, -1}; std::scanf("%d%d", &n, &c); for (int i(0); i < n; ++i) { std::scanf("%d%d", a + i, b + i); v += a[i] == 0; } c -= n; if (c < 0) { std::puts("0"); ...
CPP
177_E2. Space Voyage
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet. The Smart Beaver is going to bring som...
2
11
#include <bits/stdc++.h> const long long high = 9223372036854775807; using namespace std; int i, n, m, x, y, xa = 0, sum, cnt = 0; vector<int> a, b; long long l, r, avg, res1, res2, o, c; unsigned long long xy; long long go2(long long z) { xy = 0; unsigned long long xold = 0; long double xtr = 0; for (i = 0; i ...
CPP