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
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
from collections import Counter import sys input = sys.stdin.readline s = list(input().rstrip()) t = input().rstrip() cnt1 = Counter(s) cnt2 = Counter(t) if cnt1['?'] == 0: print(*s, sep='') exit() ok, ng = 0, 10**9 while abs(ok - ng) > 1: mid = (ok + ng) // 2 hatena = cnt1['?'] for k, v in cnt2....
PYTHON3
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Scanner; public class RobinKarp { public static void main(String[] args) throws IOException { Scanner in = new Scanner(System.in); char[] org = in.n...
JAVA
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
import java.io.*; import java.util.StringTokenizer; /** * * @author Altynbek */ public class D { Scanner in; PrintWriter out; public void solve() throws Exception { char[] s = in.next().toCharArray(); char[] t = in.next().toCharArray(); int[] cnt = new int[26]; ...
JAVA
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
#include <bits/stdc++.h> using namespace std; string s; unsigned int last_q = 1000010; long long free_space = 0; unsigned int t_lenght = 0; unsigned int got['z' + 1]; unsigned int required['z' + 1]; unsigned int nextlast() { unsigned int i = last_q + 1; while (i < s.size()) { if (s[i] == '?') break; e...
CPP
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
#include <bits/stdc++.h> using namespace std; int main() { string s, t; cin >> s >> t; int n = s.length(), m = t.length(); long long x[26] = {}, y[26] = {}, qu = 0; for (int i = 0; i < m; ++i) { x[t[i] - 'a']++; } for (int i = 0; i < n; ++i) { if (s[i] == '?') qu++; else y[s[i] - '...
CPP
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
//package TIM2; import java.io.*; import java.util.*; public class Main { static Scanner input = new Scanner(System.in); static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); static PrintWriter pw = new PrintWriter(System.out); public static void main(String[] args) throws...
JAVA
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 5; const int maxn2 = 30; char s[maxn], s2[maxn]; int cnt1[maxn2]{0}, cnt2[maxn2]{0}, cnt3 = 0; bool check(long long cur) { int lft = cnt3; for (int i = 0; i < 26; ++i) { if (cnt2[i] * cur <= cnt1[i]) continue; lft -= cnt2[i] * cur - cnt1[i...
CPP
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
//package cf.edu25; import java.util.*; public class D { public static void main(String[] args) { Scanner in = new Scanner(System.in); String s = in.nextLine(); String t = in.nextLine(); Map<Character, Integer> existing = new HashMap<>(); for (char ch : s.toCharArray()) ...
JAVA
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; import java.util.InputMismatchException; import java.util.Queue; import java.util.Stack; ...
JAVA
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); string s, t; map<char, int> cn; int x = 0; cin >> s >> t; int n = s.size(); for (int i = 0; i < n; i++) { if (s[i] != '?') { cn[s[i]]++; } else x++; } int in = 0; vector<char> v; w...
CPP
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
import java.util.*; import java.io.*; public class lp1{ static boolean ok(int cs[],int ct[],int mid,int hah) { for(int i=0;i<26;i++) { if(ct[i]*mid<=cs[i]) continue; int rem = ct[i]*mid-cs[i]; if(hah>=rem) hah=hah...
JAVA
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.Random; import java.util.Scanner; public class Main { static class Solver { public void solve() { Scanner in = new Scanner(System.in); String A = in.next...
JAVA
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
#include <bits/stdc++.h> using namespace std; const long long M = (long long)1e9 + 7; int main() { string s, t; cin >> s >> t; vector<long long> fs(26), ft(26); long long q = 0; for (long long i = 0; i < s.size(); i++) if (s[i] == '?') q++; else fs[s[i] - 'a']++; for (long long i = 0; i ...
CPP
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
# @oj: codeforces # @id: hitwanyang # @email: 296866643@qq.com # @date: 2020-11-18 19:10 # @url:https://codeforc.es/contest/825/problem/D import sys,os from io import BytesIO, IOBase import collections,itertools,bisect,heapq,math,string from decimal import * # region fastio BUFSIZE = 8192 BUFSIZE = 8192 class FastIO...
PYTHON3
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
import java.util.*; import java.io.*; import java.text.*; public class T{ static final long p = (long)163577857; static final int MAX = (int)1e5+1; static final double eps = 1e-9; static FastReader in; public static void main(String[] args){ in = new FastReader(); String s = n()...
JAVA
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
import java.util.Scanner; public class Main { static char[][] field; public static void main(String[] args) { Scanner sc = new Scanner(System.in); StringBuilder s = new StringBuilder(sc.nextLine()); String l = sc.nextLine(); int[] sChars = new int[28]; int[] lChars = new int[28]; int questions = 0; char...
JAVA
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual soluti...
JAVA
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
#include <bits/stdc++.h> using namespace std; const long long INF = 1000000000000000; bool cmp(pair<string, long long>& a, pair<string, long long>& b) { return a.second < b.second; } long long gcd(long long a, long long b) { if (a == 0) { return b; } return gcd(b % a, a); } long long factorial(long long n) ...
CPP
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
#include <bits/stdc++.h> using namespace std; signed main() { string s, t; cin >> s >> t; std::vector<long long> tc(26, 0), sc(26, 0); long long qc = count(s.begin(), s.end(), '?'); for (auto i : t) tc[i - 'a']++; for (auto i : s) { if (i != '?') sc[i - 'a']++; } long long l = 0, r = 1e8, f = 0; w...
CPP
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
#include <bits/stdc++.h> using namespace std; const int maxn = 1000006; char s[maxn], t[maxn]; int num[300]; int main() { scanf("%s%s", &s, &t); int ls = strlen(s); int lt = strlen(t); for (int i = 0; i < ls; i++) { if (s[i] != '?') num[s[i] - 'a']++; } int z = 0; for (int i = 0; i < ls; i++) { if...
CPP
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class D { public static void main(String[] args){ FastScanner scan = new FastScanner(); PrintWriter out = new PrintWriter(System.out); char[] s = sca...
JAVA
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
#include <bits/stdc++.h> using namespace std; const int N = int(5e5) + 5; const int inf = (int)1e9 + 7; string a, b; int cnt[99], need[27]; int ok(int val) { long long e = 0; for (int i = 0; i < 26; ++i) { e += max(0ll, need[i] * 1ll * val - cnt[i]); if (e > cnt[98]) { return 0; } } return e <...
CPP
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
#include <bits/stdc++.h> using namespace std; char temp[1000005]; int qtds[256]; int qtdt[256]; int main() { scanf("%s", temp); string s = temp; scanf("%s", temp); string t = temp; priority_queue<pair<int, char>> prox; for (int i = 0; i < s.size(); i++) { qtds[s[i]]++; } for (int i = 0; i < t.size()...
CPP
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; const int oo = 1e9; string s, t; int freq[26], freq2[26], q; int nf[26]; int main() { cin >> s >> t; for (int i = 0; i < s.size(); i++) if (s[i] != '?') freq[s[i] - 'a']++; else q++; for (int i = 0; i < t.size(); i++) freq2[...
CPP
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
#include <bits/stdc++.h> using namespace std; int INF = 0x3f3f3f3f; char s[1000005], s1[1000005]; map<char, int> mp, vis, mp1; struct ss { char c; int hx, m, nn; bool operator<(const ss& a) const { if (hx != a.hx) return a.hx < hx; return a.m < m; } }; int main() { scanf("%s%s", s, s1); int n = strl...
CPP
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
s=list(input()) t=input() L=[0]*27 for i in range(len(s)): if s[i]!='?': L[ord(s[i])-ord('a')]+=1 count=0 i=0 while i<len(s): if s[i]=='?': count+=1 if L[ord(t[count%len(t)])-ord('a')]>0: L[ord(t[count%len(t)])-ord('a')]-=1 i-=1 else: s[i]=t[count%len(t)] i=i+1 print(''.join(s...
PYTHON3
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
#include <bits/stdc++.h> using namespace std; long long n, q, freq[26], freq2[26]; char s[1001000]; string str, str2; bool ok(long long suit) { long long desired, quest = q; for (int i = 0; i < 26; i++) { desired = freq2[i] * suit; quest -= max(0LL, (desired - freq[i])); } return quest >= 0; } void fill...
CPP
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
//package cf.edu25; import java.util.*; public class D { public static void main(String[] args) { Scanner in = new Scanner(System.in); String s = in.nextLine(); String t = in.nextLine(); Map<Character, Integer> existing = new HashMap<>(); for (char ch : s.toCharArray()) ...
JAVA
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
#!/usr/local/bin/python3 from itertools import cycle from collections import defaultdict s = defaultdict(int) init = input() for digit in init: s[digit] += 1 t = input() token_gen = cycle(t) questions = [] while True: next_token = next(token_gen) if s.get(next_token, -1) > 0: s[next_token] -=...
PYTHON3
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
#include <bits/stdc++.h> using namespace std; template <class T> void dbs(string str, T t) { cerr << str << " : " << t << "\n"; } template <class T, class... S> void dbs(string str, T t, S... s) { int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ","; dbs(str.substr(idx + 1), s...); } templat...
CPP
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
import java.util.*; import java.lang.*; import java.io.*; import java.math.*; public class Prac{ static class InputReader { private final InputStream stream; private final byte[] buf = new byte[8192]; private int curChar, snumChars; public InputReader(InputStream st) { ...
JAVA
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
import os import sys from io import BytesIO, IOBase import math from queue import Queue import collections import itertools import bisect import heapq # sys.setrecursionlimit(100000) # ^^^TAKE CARE FOR MEMORY LIMIT^^^ import random def main(): pass BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 de...
PYTHON3
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
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
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
#include <bits/stdc++.h> using namespace std; char s[1000005], t[1000005]; int at[(int)'z' + 1], as[(int)'z' + 1]; long long r[(int)'z' + 1], R[(int)'z' + 1]; vector<char> vc; int main() { int i, step, mask, x, ok; long long q; char c; cin >> s >> t; for (i = 0; t[i] != '\0'; ++i) { at[(int)t[i]]++; } ...
CPP
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); string s, t; long long int a[26] = {}, b[26] = {}, c = 0; cin >> s >> t; for (int i = 0; i < s.length(); i++) { if (s[i] == '?') c++; else a[s[i] - 'a']++; } for (int i = 0; i < t.length(); i++) b[t...
CPP
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
#include <bits/stdc++.h> using namespace std; #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx") using llong = long long; using ld = long double; using ii = pair<int, int>; using ull = unsigned long long; using pll = pair<llong, llong>; using vi = vector<int>; const llong over999 = 1e14; const ld eps = 1e-9;...
CPP
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
#include <bits/stdc++.h> using namespace std; string s, t; int a[30], b[30], k, l; int main() { cin >> s >> t; for (int i = 0; i < s.size(); i++) { if (s[i] == '?') k++; else a[s[i] - 96]++; } for (int i = 0; i < t.size(); i++) b[t[i] - 96]++; for (int i = 1; i <= 26; i++) b[i] *= 1000; ...
CPP
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return a == 0 ? b : gcd(b % a, a); } long long pow(long long a, long long b, long long M) { long long t = 1; for (a %= M; b; b >>= 1) { if (b & 1) t = t * a % M; a = a * a % M; } return t; } const int N = 1e6 + 5; ch...
CPP
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
#include <bits/stdc++.h> using namespace std; int main() { string s, t; cin >> s >> t; vector<int> p; int a[27] = {0}; for (int i = 0; i < s.size(); i++) { if (s[i] == '?') { p.push_back(i); } else { a[int(s[i]) - 96]++; } } if (p.size() == 0) { cout << s; return 0; } i...
CPP
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
#include <bits/stdc++.h> using namespace std; const int mx = 1e6 + 777; int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); string s, t; cin >> s >> t; int q = 0; vector<int> cs(26), ct(26); for (auto c : s) if (isalpha(c)) cs[c - 'a']++; else q++; for (auto c : t) ...
CPP
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
#include <bits/stdc++.h> using namespace std; const int MaxN = 1000003; char A[MaxN], B[MaxN]; int la, lb, cntA[26], cntB[26], cntq; inline void put_char(const char& x) { static int p = 0; if (cntq == 0) return; while (A[p] != '?') p++; A[p] = x; cntA[x - 'a']++; cntq--; p++; } int main() { scanf("%s%s"...
CPP
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
#include <bits/stdc++.h> using namespace std; ifstream fin("input.txt"); ofstream fout("output.txt"); bool isPrime(long long int x) { if (x <= 4 || x % 2 == 0 || x % 3 == 0) return x == 2 || x == 3; for (int i = 5; i * i <= x; i += 6) if (x % i == 0 || x % (i + 2) == 0) return 0; return 1; } void primeFactors...
CPP
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
#include <bits/stdc++.h> using namespace std; vector<bool> visited(100005, false); vector<long long> adj[100005]; vector<long long> parent(100005, -1); long long ans1 = 0; long long expo(long long x, long long n, long long M) { if (n == 0) return 1; else if (n % 2 == 0) return (expo((x * x) % M, n / 2, M)) ...
CPP
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
import java.util.*; import java.io.*; public class D { void solve(BufferedReader in) throws Exception { String s = in.readLine(), t = in.readLine(); char[] out = new char[s.length()]; int[] chars = new int[26]; int[] sorig = new int[26]; int[] chart = new int[26]; int...
JAVA
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
import java.io.*; import java.util.*; public class MyClass { static class node { boolean can = false; int[] count = new int[26]; } static PrintWriter pw = new PrintWriter(System.out); static String s , t; static int[] countS = new int[26]; static int[] countT = ne...
JAVA
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.io.PrintStream; import java.util.HashMap; import java.util.Map; import java.util.StringTokenizer; /...
JAVA
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 100; char s[N], t[N]; int ovo[26], kk[26]; struct d { char nam; int oo; int kkk; bool operator<(const d o) const { return oo * 1.0 / kkk > o.oo * 1.0 / o.kkk; } } qwq; priority_queue<d> Q; int main() { cin >> s; cin >> t; int len = st...
CPP
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList; import java.io.InputStream; /** * Built using CHel...
JAVA
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList; import java.io.InputStream; /** * Built using CHelper plug-in * Actual soluti...
JAVA
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
#include <bits/stdc++.h> using namespace std; int main() { string s, t; cin >> s >> t; vector<int> a(26, 0); for (int i = 0; i < s.size(); i++) if (s[i] != '?') a[s[i] - 'a']++; int j = 0; for (int i = 0; i < s.size(); i++) { if (j >= t.size()) j -= t.size(); while (a[t[j] - 'a']) { a[t[j]...
CPP
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
#include <bits/stdc++.h> using namespace std; int freq[30], output[30]; int freq2[30]; int main() { int a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q; string A, B, C; cin >> A >> B; memset(freq, 0, sizeof(freq)); c = 0; for (i = 0; i < A.length(); i++) { if (A[i] == '?') c++; else fr...
CPP
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
#include <bits/stdc++.h> using namespace std; const double PI = atan(1) * 4; const int mod = 1e9 + 7; int dx[] = {1, 0, -1, 0, 1, -1, -1, 1, 0}; int dy[] = {0, 1, 0, -1, 1, 1, -1, -1, 0}; int n, k; long long a[100009], b[100009], sum; bool check(double mid) { double sum = mid + k; for (int i = 0; i < n - 1; i++) { ...
CPP
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
import java.io.* ; import java.util.* ; import java.util.stream.* ; import java.text.* ; import java.math.* ; public class Codeshefcode{ public static void main(String[] args) throws IOException{ Solver Machine = new Solver() ; Machine.Solve() ; Machine.Finish(); } } class Mod{ static long mod=1000000007 ; ...
JAVA
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
import java.io.*; public class competetive { public static void main(String[] args) throws java.lang.Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(java.io.FileDescript...
JAVA
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
#include <bits/stdc++.h> using namespace std; const int MAX_N = 1000000; const int INF = 0x3f3f3f3f; char s[MAX_N + 10], t[MAX_N + 10]; int cnt_s[30], cnt_t[30]; int main() { scanf("%s%s", s, t); int n = strlen(s), m = strlen(t); memset(cnt_s, 0, sizeof(cnt_s)); memset(cnt_t, 0, sizeof(cnt_t)); int w = 0; f...
CPP
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
import java.io.IOException; import java.io.InputStream; import java.util.NoSuchElementException; public class Main { private static FastScanner sc = new FastScanner(); public static void main(String[] args) { char[] s = sc.next().toCharArray(); char[] t = sc.next().toCharArray(); int[] schar = new int[26...
JAVA
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << '\n'; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); cerr.write(nam...
CPP
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
import string source = {i:0 for i in string.ascii_lowercase} q = 0 stra = input() for i in stra: if i == '?': q += 1 else: source[i] += 1 pack = {i:0 for i in string.ascii_lowercase} strb = input() for i in strb: pack[i] += 1 def check(source, pack, q, pkcount): for i in pack: i...
PYTHON3
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
#!/usr/bin/env python3 def solve(): s = list(get(str)) t = get(str) smap = collections.Counter(s) tmap = collections.Counter(t) alphabet = set(tmap) suit = min(smap[a] // tmap[a] for a in alphabet if tmap[a] > 0) for a in alphabet: smap[a] -= suit * tmap[a] def getchar(): ...
PYTHON3
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
#include <bits/stdc++.h> using namespace std; char s[1000010], t[1000010]; int a[30], b[30]; int ls, lt; int idx(char c) { return c - 'a'; } int pos[1000010], len = 0; void init() { for (int i = 0; i < ls; i++) { if (s[i] != '?') a[idx(s[i])]++; else pos[len++] = i; } for (int i = 0; i < lt; i...
CPP
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
import java.io.*; import java.lang.reflect.Array; import java.math.BigInteger; import java.util.*; public class q5 { public static void main(String[] args) throws IOException { Reader.init(System.in); PrintWriter out=new PrintWriter(System.out); StringBuffer output=new StringBuffer(""); String s1=...
JAVA
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
import java.io.*; import java.lang.*; import java.math.*; import java.util.*; public class Main { static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader (InputStream stream) { reader = new BufferedReader (new InputStreamRead...
JAVA
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
#include <bits/stdc++.h> using namespace std; const int MAX = 1e6 + 65; char s[MAX], t[MAX]; int app_s[256], app_t[256]; vector<char> all; int f = 0; inline bool good(int occ) { long long tmp_f = f; for (auto &each : all) { long long need = 1LL * app_t[each] * occ; long long has = app_s[each]; long long...
CPP
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
#include <bits/stdc++.h> using namespace std; string s, t; map<char, int> used, needed; inline bool check() { for (map<char, int>::iterator it = used.begin(); it != used.end(); it++) { if (it->second < needed[it->first]) { return false; } } for (map<char, int>::iterator it = used.begin(); it != used...
CPP
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
# Enter your code here. Read input from STDIN. Print output to STDOUT import sys from sys import stdin, stdout s=list(stdin.readline().strip()) t=stdin.readline().strip() S=[0 for i in range(26)] T=[0 for i in range(26)] Q=0 for i in range(len(s)): if s[i]!='?': S[ord(s[i])-97]+=1 else: Q+=1 ...
PYTHON
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
#include <bits/stdc++.h> using namespace std; bool solve(int schar[250], int tchar[250], long long int q, long long int mid) { for (char a = 'a'; a <= 'z'; a++) { int d = a; if (schar[d] < tchar[d] * mid) { q -= tchar[d] * mid - schar[d]; } } if (q < 0) return false; return true; } int main() ...
CPP
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual soluti...
JAVA
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Aman Kumar Singh */ public class Main { public static void main...
JAVA
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList; import java.io.InputStream; /** * Built using CHel...
JAVA
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
#include <bits/stdc++.h> using namespace std; int main() { string s, t; int cnt1[256] = {}, cnt2[256] = {}, toReplace[256] = {}; cin >> s >> t; for (char c : s) ++cnt1[c]; for (char c : t) ++cnt2[c]; priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq; ...
CPP
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
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
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
#include <bits/stdc++.h> using namespace std; int a[220], d = 1; vector<int> p; int main() { string k, e; cin >> k >> e; for (int i = 0; i < k.length(); ++i) { if (k[i] == '?') p.push_back(i); a[k[i]]++; } while (d) for (char x : e) if (a[x]) a[x]--; else if (int y = p.size()) ...
CPP
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
a, b = input(), input() i = 0 j = len(a) // len(b) e = a.count('?') from collections import Counter ca, cb = Counter(a), Counter(b) while i <= j: m = (i + j) // 2 if sum(cb[x] * m - min(cb[x] * m, ca[x]) for x in set(b)) <= e: i = m + 1 else: j = m - 1 r = [] for i in set(b): r.extend([*i * max(0, cb[i] * j...
PYTHON3
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual soluti...
JAVA
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
#include <bits/stdc++.h> using namespace std; int main() { string s, t; cin >> s >> t; int n = s.size(); int m = t.size(); vector<int> occint(26, 0); vector<int> occins(26, 0); int count = 0; for (int i = 0; i < n; i++) { if (s.at(i) != '?') { occins[s.at(i) - 'a']++; } else { count+...
CPP
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
import java.util.*; import java.io.*; import java.math.*; import java.util.regex.*; public class Main4 { public static void main(String[] args)throws Exception { Reader reader = new Reader(); reader.readLine(); int special = 0; String s = reader.readString(0); int freq[][] = new int[4][26]; for...
JAVA
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
#include <bits/stdc++.h> using namespace std; long long b[200], c[200], q[200]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); string s, a; cin >> s >> a; long long i, j, ss = s.size(), aa = a.size(); for (i = 0; i < s.size(); i++) b[s[i]]++; for (i = 0; i < a.size(); i++) c[a[i...
CPP
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
#include <bits/stdc++.h> const int N = 1000005; char s[N], t[N], q[N]; int main() { int count[27] = {0}; scanf("%s", s); scanf("%s", t); int n = strlen(s); for (int i = 0; i < n; i++) { if (s[i] == '?') count[0]++; else count[s[i] - 96]++; } int m = strlen(t); bool flag = true; int...
CPP
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
#include <bits/stdc++.h> using namespace std; int A[27], An[27], At[27], tt, hur; string s, t; int main() { cin >> s; for (int i = 0; i < s.length(); i++) if (int(s[i]) == 63) tt++; else A[int(s[i]) - 96]++; cin >> t; for (int i = 0; i < t.length(); i++) At[int(t[i]) - 96]++; while (tt > 0...
CPP
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; import java.util.List; public class Main { public static void main(String args...
JAVA
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
#include <bits/stdc++.h> using namespace std; int dx[8] = {0, 0, 1, 1, 1, -1, -1, -1}; int dy[8] = {1, -1, -1, 0, 1, -1, 0, 1}; const long long N = 1000006; long long q, h[26], h1[26], h2[26], cnt; bool possible(long long c) { long long cnt1 = cnt; for (long long i = 0; i <= 25; i++) { long long req = h[i] * c;...
CPP
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
#include <bits/stdc++.h> using namespace std; int sx[256], tx[256]; int dx[256]; int main() { string s, t; cin >> s >> t; for (char x : s) { sx[x]++; } for (char x : t) { tx[x]++; } int broj = 0; while (1) { int fali = 0; for (char x = 'a'; x <= 'z'; x++) { int f = tx[x] * broj - s...
CPP
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
import java.io.*; import java.lang.reflect.Array; import java.util.*; import java.util.regex.Matcher; public class Main { public static void main(String[] args) throws Exception { MyReader reader = new MyReader(System.in); MyWriter writer = new MyWriter(System.out); new Main().run(reader,...
JAVA
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
import sys from sys import stdin,stderr,stdout s=list(stdin.readline().strip()) t=stdin.readline().strip() Ss=[0 for i in range(26)] question=0 Ts=[0 for i in range(26)] for i in range(len(t)): Ts[ord(t[i])-97]+=1 for i in range(len(s)): if s[i]!='?': Ss[ord(s[i])-97]+=1 else: question+=1 c...
PYTHON
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const int N = 1000000 + 5; const int K = 26 + 5; char s[N], t[N]; int ns[K], nt[K], ans[K]; int main() { scanf("%s %s", s, t); for (int i = 0; t[i]; ++i) { nt[t[i] - 'a']++; } int cnt = 0; for (int i = 0; s[i]; ++i) { if (...
CPP
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
#include <bits/stdc++.h> using namespace std; int char_count[26]; int main() { cin.sync_with_stdio(false); cin.tie(0); string s, t; vector<int> q; cin >> s >> t; int n = s.length(); int m = t.length(); for (int i = 0; i < n; i++) { if (s[i] != '?') char_count[s[i] - 'a']++; else q.pu...
CPP
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Vaibhav Pulastya */ public...
JAVA
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
// Nice question I Like it import java.util.*; import java.io.*; public class lp1{ static boolean ok(int cs[],int ct[],int mid,int hah) { for(int i=0;i<26;i++) { if(ct[i]*mid<=cs[i]) continue; int rem = ct[i]*mid-cs[i]; if(hah>=r...
JAVA
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
#include <bits/stdc++.h> using namespace std; int main() { string s, t; int i, j, hash[26] = {0}, z = 0; cin >> s >> t; for (i = 0; i < s.size(); i++) { hash[s[i] - 'a']++; } for (i = 0; i < s.size(); i++) { if (s[i] == '?') { z++; z %= t.size(); if (hash[t[z] - 'a'] > 0) { ...
CPP
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
import java.io.FileInputStream; public class AB { static class Scan { final private int BUF_SIZE = 1 << 16; private int cur_size = 0; private int pointer = 0; private java.io.DataInputStream in; private byte buffer[] = new byte[BUF_SIZE]; Scan(java.io.InputStrea...
JAVA
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
#include <bits/stdc++.h> using namespace std; int a[30]; stack<char> dit; int main() { string s1, s2; cin >> s1 >> s2; int sum = 0, len = s1.size(); for (int i = 0; i < len; i++) { if (s1[i] == '?') sum++; else a[int(s1[i] - 'a')]++; } len = s2.size(); while (sum > 0) for (int i = ...
CPP
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
#include <bits/stdc++.h> using namespace std; const long long MAXA = 26 + 13; long long salph[MAXA], talph[MAXA]; queue<long long> que; set<pair<pair<long long, long long>, long long> > need; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); string s, t; cin >> s >> t; for (long long i = 0;...
CPP
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
import java.io.*; import java.util.*; public class D implements Runnable{ public static void main (String[] args) {new Thread(null, new D(), "_cf", 1 << 28).start();} public void run() { FastScanner fs = new FastScanner(); PrintWriter out = new PrintWriter(System.out); System.err.println("Go!"); char[] str...
JAVA
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
#include <bits/stdc++.h> using namespace std; char s[1000006]; char t[1000006]; int a[50]; int b[50]; queue<char> plu; int main() { scanf("%s", s); scanf("%s", t); int ls = strlen(s); int lt = strlen(t); for (int i = 0; i < ls; i++) { if (s[i] == '?') { a[0]++; } else { a[s[i] - 'a' + 1]++...
CPP
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.io.BufferedWriter; import java.util.InputMismatchException; import java.io.IOException; import java.util.AbstractCollection; import java.io.Writer; import java.io.Out...
JAVA
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
##################################### import atexit, io, sys, collections, math, heapq buffer = io.BytesIO() sys.stdout = buffer @atexit.register def write(): sys.__stdout__.write(buffer.getvalue()) ##################################### s = list(raw_input()) cc = collections.Counter(s) t = raw_input() q = collecti...
PYTHON
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
import java.io.*; import java.util.*; import java.math.*; public class Main { static int m,mod=998244353,maxn=1000000,q,n,k; static long INF=(long)1e18,cnt=0; static String s,t; static long[] freq,wnted; void solve(PrintWriter out, Reader in) throws IOException{ s = in.next(); ...
JAVA
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
#Bhargey Mehta (Sophomore) #DA-IICT, Gandhinagar import sys, math, queue, bisect #sys.stdin = open("input.txt", "r") MOD = 10**9+7 sys.setrecursionlimit(1000000) def can(x): rem = ops for k in need: rem -= max(0, x*need[k]-have[k]) return rem >= 0 s = list(input()) t = input() need, have = {}, {} ...
PYTHON3
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
#include <bits/stdc++.h> using namespace std; char fi[10][10]; int dx[] = {1, -1, 0, 0, 1, -1, -1, 1}; int dy[] = {0, 0, 1, -1, 1, -1, 1, -1}; int dfs(int x, int y, int i) { int nx = x + dx[i]; int ny = y + dy[i]; if (0 <= nx && nx < 10 && 0 <= ny && ny < 10 && fi[nx][ny] == 'X') { return dfs(nx, ny, i) + 1; ...
CPP
825_D. Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulti...
2
10
import java.io.*; import java.util.Arrays; public class Main { private static myScanner sc; private static PrintWriter pw; private static final boolean defaultInAndOutPut = true; private static final int numberOfTests = 1; private static final String nameOfInAndOutFile = ""; private static ...
JAVA