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
757_C. Felicity is Coming!
It's that time of the year, Felicity is around the corner and you can see people celebrating all around the Himalayan region. The Himalayan region has n gyms. The i-th gym has gi Pokemon in it. There are m distinct Pokemon types in the Himalayan region numbered from 1 to m. There is a special evolution camp set up in t...
2
9
#include <bits/stdc++.h> using namespace std; long long MOD = 1000000007; long long fact[1000005]; int blobId[1000005], lastFreeBlobId = 1; set<int> blob[1000005]; queue<int> freeBlob; void calculateFacts() { fact[0] = 1; for (__typeof(1) i = 1; i < 1000005; i += 1) fact[i] = (fact[i - 1] * i) % MOD; } int getF...
CPP
757_C. Felicity is Coming!
It's that time of the year, Felicity is around the corner and you can see people celebrating all around the Himalayan region. The Himalayan region has n gyms. The i-th gym has gi Pokemon in it. There are m distinct Pokemon types in the Himalayan region numbered from 1 to m. There is a special evolution camp set up in t...
2
9
#include <bits/stdc++.h> using namespace std; long long fact[1000006]; int main() { long long n, m; cin >> n >> m; string str[m + 5]; fact[0] = 1; long long md = 1e9 + 7; str[0] = "0"; for (long long i = 1; i <= m; i++) { str[i] = "0"; fact[i] = fact[i - 1] * i; fact[i] %= md; } for (int i...
CPP
757_C. Felicity is Coming!
It's that time of the year, Felicity is around the corner and you can see people celebrating all around the Himalayan region. The Himalayan region has n gyms. The i-th gym has gi Pokemon in it. There are m distinct Pokemon types in the Himalayan region numbered from 1 to m. There is a special evolution camp set up in t...
2
9
import java.io.IOException; import java.util.*; public class Test { int readInt() { int ans = 0; boolean neg = false; try { boolean start = false; for (int c = 0; (c = System.in.read()) != -1; ) { if (c == '-') { start = true; ...
JAVA
757_C. Felicity is Coming!
It's that time of the year, Felicity is around the corner and you can see people celebrating all around the Himalayan region. The Himalayan region has n gyms. The i-th gym has gi Pokemon in it. There are m distinct Pokemon types in the Himalayan region numbered from 1 to m. There is a special evolution camp set up in t...
2
9
import java.io.IOException; import java.util.*; public class Test { int readInt() { int ans = 0; boolean neg = false; try { boolean start = false; for (int c = 0; (c = System.in.read()) != -1; ) { if (c == '-') { start = true; ...
JAVA
757_C. Felicity is Coming!
It's that time of the year, Felicity is around the corner and you can see people celebrating all around the Himalayan region. The Himalayan region has n gyms. The i-th gym has gi Pokemon in it. There are m distinct Pokemon types in the Himalayan region numbered from 1 to m. There is a special evolution camp set up in t...
2
9
#include <bits/stdc++.h> using namespace std; int n, m; set<int> se[1000001]; int where[1000001]; int sz = 1; int cnt; int a[500005]; pair<int, int> b[500005]; int bc; vector<int> cur; inline bool cmp(const int &lhs, const int &rhs) { return where[lhs] < where[rhs]; } void update() { sort(cur.begin(), cur.end(), cm...
CPP
757_C. Felicity is Coming!
It's that time of the year, Felicity is around the corner and you can see people celebrating all around the Himalayan region. The Himalayan region has n gyms. The i-th gym has gi Pokemon in it. There are m distinct Pokemon types in the Himalayan region numbered from 1 to m. There is a special evolution camp set up in t...
2
9
import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; import java.lang.*; public class C{ static long mod=1000000007; //static ArrayList<Integer>ar[]; public static void main(String[] args) throws Exception{ InputReader in = new InputReader(Sy...
JAVA
757_C. Felicity is Coming!
It's that time of the year, Felicity is around the corner and you can see people celebrating all around the Himalayan region. The Himalayan region has n gyms. The i-th gym has gi Pokemon in it. There are m distinct Pokemon types in the Himalayan region numbered from 1 to m. There is a special evolution camp set up in t...
2
9
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 15, mod = 1e9 + 7; multiset<int> se[N]; int main() { int n, m, i, k, u, x; long long ret = 1, t = 1; cin >> n >> m; for (i = 0; i < n; ++i) { scanf("%d", &u); for (k = 0; k < u; ++k) scanf("%d", &x), se[x].insert(i); } sort(se + 1, se...
CPP
757_C. Felicity is Coming!
It's that time of the year, Felicity is around the corner and you can see people celebrating all around the Himalayan region. The Himalayan region has n gyms. The i-th gym has gi Pokemon in it. There are m distinct Pokemon types in the Himalayan region numbered from 1 to m. There is a special evolution camp set up in t...
2
9
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); PrintWriter o...
JAVA
757_C. Felicity is Coming!
It's that time of the year, Felicity is around the corner and you can see people celebrating all around the Himalayan region. The Himalayan region has n gyms. The i-th gym has gi Pokemon in it. There are m distinct Pokemon types in the Himalayan region numbered from 1 to m. There is a special evolution camp set up in t...
2
9
/* * Code Author: Akshay Miterani * DA-IICT */ import java.io.*; import java.math.BigInteger; import java.util.*; public class Main { InputReader in; PrintWriter out; Main() throws IOException { in = new InputReader(System.in); out = new PrintWriter(System.out); solve(); out.close(); } public stat...
JAVA
757_C. Felicity is Coming!
It's that time of the year, Felicity is around the corner and you can see people celebrating all around the Himalayan region. The Himalayan region has n gyms. The i-th gym has gi Pokemon in it. There are m distinct Pokemon types in the Himalayan region numbered from 1 to m. There is a special evolution camp set up in t...
2
9
#include <bits/stdc++.h> using namespace std; const int N = 1e6; const int mod = 1e9 + 7; vector<int> nhom[N + 2]; map<vector<int>, int> mp; int main() { int n, m, t, k; scanf("%d%d", &n, &m); for (int j = 0; j < (n); j++) { scanf("%d", &t); for (int i = 0; i < (t); i++) { scanf("%d", &k); nho...
CPP
757_C. Felicity is Coming!
It's that time of the year, Felicity is around the corner and you can see people celebrating all around the Himalayan region. The Himalayan region has n gyms. The i-th gym has gi Pokemon in it. There are m distinct Pokemon types in the Himalayan region numbered from 1 to m. There is a special evolution camp set up in t...
2
9
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.HashMap; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import java.util.StringTokenizer; import java.util.Map; import java....
JAVA
757_C. Felicity is Coming!
It's that time of the year, Felicity is around the corner and you can see people celebrating all around the Himalayan region. The Himalayan region has n gyms. The i-th gym has gi Pokemon in it. There are m distinct Pokemon types in the Himalayan region numbered from 1 to m. There is a special evolution camp set up in t...
2
9
import java.io.*; import java.math.BigInteger; import java.util.*; public class Main { static InputReader in = new InputReader(System.in); static PrintWriter out = new PrintWriter(System.out); static int oo = (int)1e9; // static long oo = (long)1e15; static int mod = 1_000_000_007; // static int mod = 998...
JAVA
757_C. Felicity is Coming!
It's that time of the year, Felicity is around the corner and you can see people celebrating all around the Himalayan region. The Himalayan region has n gyms. The i-th gym has gi Pokemon in it. There are m distinct Pokemon types in the Himalayan region numbered from 1 to m. There is a special evolution camp set up in t...
2
9
from collections import Counter import sys input = sys.stdin.readline n, m = map(int, input().split()) adj = [[] for i in range(m)] arr = [list(map(int, input().split()))[1:] for _ in range(n)] for i in range(n): for t in arr[i]: adj[t-1].append(i) res = 1 mod = int(1e9+7) for e in Counter(list(map(str...
PYTHON3
757_C. Felicity is Coming!
It's that time of the year, Felicity is around the corner and you can see people celebrating all around the Himalayan region. The Himalayan region has n gyms. The i-th gym has gi Pokemon in it. There are m distinct Pokemon types in the Himalayan region numbered from 1 to m. There is a special evolution camp set up in t...
2
9
#include <bits/stdc++.h> using namespace std; const long long base[] = {126859, 145807}; const long long mod = 1000000007; int n, m; int a[100005], c[1000005]; pair<long long, long long> code[1000005]; long long fac[1000005]; int main() { fac[0] = 1; for (int i = 1; i <= 1000000; i++) fac[i] = (fac[i - 1] * i) % mo...
CPP
757_C. Felicity is Coming!
It's that time of the year, Felicity is around the corner and you can see people celebrating all around the Himalayan region. The Himalayan region has n gyms. The i-th gym has gi Pokemon in it. There are m distinct Pokemon types in the Himalayan region numbered from 1 to m. There is a special evolution camp set up in t...
2
9
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 100; int p[N]; int sz[N]; bool mk[N]; vector<pair<int, int> > DP[N]; int n, m; const long long MOD = 1e9 + 7; const long long P1 = 1e6 + 1; const long long P2 = 10000019; long long fact[N]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); ...
CPP
757_C. Felicity is Coming!
It's that time of the year, Felicity is around the corner and you can see people celebrating all around the Himalayan region. The Himalayan region has n gyms. The i-th gym has gi Pokemon in it. There are m distinct Pokemon types in the Himalayan region numbered from 1 to m. There is a special evolution camp set up in t...
2
9
import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.StreamTokenizer; import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Arrays; import java...
JAVA
757_C. Felicity is Coming!
It's that time of the year, Felicity is around the corner and you can see people celebrating all around the Himalayan region. The Himalayan region has n gyms. The i-th gym has gi Pokemon in it. There are m distinct Pokemon types in the Himalayan region numbered from 1 to m. There is a special evolution camp set up in t...
2
9
#include <bits/stdc++.h> using namespace std; const long long MOD = (1e9) + 7; int n, m; long long ans = 1, f[1000001]; int main() { f[1] = 1; for (int i = 2; i <= 1e6; i++) f[i] = (f[i - 1] * i) % MOD; scanf("%d%d", &n, &m); vector<vector<int> > a(m + 1); for (int i = 0; i < n; i++) { int gi; scanf("...
CPP
757_C. Felicity is Coming!
It's that time of the year, Felicity is around the corner and you can see people celebrating all around the Himalayan region. The Himalayan region has n gyms. The i-th gym has gi Pokemon in it. There are m distinct Pokemon types in the Himalayan region numbered from 1 to m. There is a special evolution camp set up in t...
2
9
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; import java.util.stream.Collectors; import java.util.stream.IntStream; public class Main4 { static long ...
JAVA
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> char s[1000][1010], t[1010]; int dp[1010][1001], a[1000], p[1000], f[1000], c[20], n; bool b[1001]; int len[1000], l; inline int cost(int i, int j, int x) { return x || j < len[i] || j < l ? c[x] : 0; } inline void umax(int& m, int u) { u > m && (m = u); } void sort(int d) { static int b[10...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> const int inf = 1e9; std::string b[1010]; std::string s; int f[1010][1010], h[1010][1010][12], g[1010][1010][12], rank[1010][1010], sa[1010], len[1010]; int L, n, tmp_d, cost[20]; void rlxx(int &x, int y) { if (x < y) x = y; } void trans(int i, int c) { for (int k = 1; k <= n + 1; ++k) ...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; char s[1010]; int pos, n, m, l, f[1010][1010], la, p[1010], b[1010][1010], a[1010], cost[1010], tree[11], rk[1010][1010]; bool cmp(int x, int y) { return b[x][pos] == b[y][pos] ? p[x] < p[y] : b[x][pos] > b[y][pos]; } void update(int x, int v) { for (; x <= 10; x +=...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; const int maxN = 1005, INF = 1e9; int n, len; int w[10], f[maxN + 1][maxN + 1]; int id[maxN + 1], l[maxN + 1]; char A[maxN + 1], B[maxN + 1][maxN + 1]; vector<int> num[10]; int main() { scanf("%s", A + 1); l[0] = strlen(A + 1); len = max(len, l[0]); scanf("%d", &n);...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; char tmp[1010]; int B[1010][1010], A[1010]; const int L = 1001; int dp[1010][1010], c[1010], len[1010]; int change(int i, int j, int add) { int a0 = (B[i][j] + add) % 10, a1 = (B[i][j] + add + 1) % 10; if (j < len[i]) { return -c[a0] + c[a1]; } else { return c...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; char A[1010]; int D[1010][1010]; char B[1010][1010]; int n, m; int cost[10]; int lenB[1010]; void solve() { scanf("%s", A + 1); n = (int)strlen(A + 1); reverse(A + 1, A + 1 + n); scanf("%d", &m); for (int i = 1; i <= m; i++) { scanf("%s", B[i] + 1); lenB[i...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; const int N = 1e3 + 5; struct num { int x[N], sz; friend istream& operator>>(istream& get, num& n) { string s; get >> s, n.sz = s.size(); for (int i = 0; i < n.sz; i++) n.x[n.sz - i - 1] = (s[i] ^ '?' ? s[i] - '0' : -1); return get; } } a, b[N]; ...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; int n; int N = 1015; vector<int> A, B[1050]; int dp[1050][1050]; int cost[10]; char inp[1150]; int SA[1050]; int now; int RA[1050]; int maxlen[1050]; vector<int> getInput2() { vector<int> res; for (int i = 0; i < 999; i++) res.push_back(0); res.push_back(1); return ...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; const int N = 1e3 + 4; int n; char inp[N + 3]; int val[N + 3][N + 3]; int sz[N + 3]; int cnt[N + 3][N + 3][13]; int c[13]; int pri[N + 3][N + 3][13]; int inv[N + 3][N + 3]; int p[N + 3][N + 3]; long long int memo[N + 3][N + 3]; void printa(int i, int k) { for (; k < N; k+...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; int n, m, c[15], pn = 1002, dp[1055][1005], p[1005], tmp[1005], f[15]; char a[1055], b[1005][1055]; inline int F(int x) { if (x >= '0' && x <= '9') return x - '0'; return 0; } int main() { memset(dp, 0xc0, sizeof(dp)); scanf("%s%d", a + 1, &n); m = strlen(a + 1); ...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; const int N = 1005; char A[N + 7]; int n; char B[N + 7]; int tab[N + 7][N + 7]; int wei[17]; int st[N + 7]; int dpo[N + 7]; int dp[N + 7]; int kolo[N + 7]; int kolor[N + 7]; int kol[N + 7]; int kolr[N + 7]; int inf = 1e9; int zabr = 0; int ile[17]; int ile2[17]; int pmx[17]...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> int L, n, l[1010], p[1010], c[1010], tot; int v[1010][11][1010], nine[1010][1010], r[1010][1010], ur[1010][1010], f[1010][1010]; char A[1010], B[1010][1010], D[1010], K[1010]; bool o[1010][11][1010], vis[1010]; int cmpd; namespace bf { int ans; void dfs(int u) { if (u > tot) { int tmp...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; template <class X, class Y> void minimize(X &x, const Y &y) { if (x > y) x = y; } template <class X, class Y> void maximize(X &x, const Y &y) { if (x < y) x = y; } template <class T> T Abs(const T &x) { return (x < 0 ? -x : x); } int n, addLen, numLen[1010]; int digit...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; const int kMaxN = 1010; const int M = 1001; char a[kMaxN]; int m; int n; int len[kMaxN]; char b[kMaxN][kMaxN]; int cost[10]; long long dp[kMaxN][kMaxN]; pair<int, int> vec[kMaxN]; int val[kMaxN], max_len[kMaxN]; void ReadInput() { scanf("%s", a); m = strlen(a); revers...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; struct node { int y, nex; } e[1100]; int n, m, a[1100], b[1100][1100], c[10], f[1100][1100], sa1[1100], sa2[1100], pos[10], fir[10]; int len, rk[1100], w[1100], g[10], ap, mx[1100]; char s[1100][1100]; void init() { scanf("%s", s[0] + 1); m = strlen(s[0] + 1); i...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; const int N = (int)2e3 + 5, mod = (int)0; string b[N]; int n, cnt[N], cost[N], dp[N], odp[N], lord[N], ord[N], c[N], tmp[N]; char ch[N]; void radix_sort(int len) { memset(c, 0, sizeof c); for (int j = 0; j < n; ++j) { ch[j] = (b[lord[j]].size() < len ? '0' :...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; const int N = 1000 + 2; const int A = 10; int suffix[N][A]; int prefix[N][A]; int value[N][N]; int cost[N]; string b[N]; string read() { string s; cin >> s; reverse(s.begin(), s.end()); for (auto &i : s) { i -= i == '?' ? 0 : '0'; } return s; } int main() { ...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:251700000") using namespace std; const long long LINF = 9e18; const int INF = 2e9; const int M = 1e3 + 5; int n; string a, b[M]; int c[M], dp[M][M], zz[M], cc[M][M], pr[M][M], kok[10]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ci...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; const int N = 1e3 + 5; int dp[N][N], n, m, x, y; string s[N], chg; int A[N][N], C[N]; int d[10]; void doit(string &s, int *A) { for (int i = 0; i < (int)s.size(); ++i) { if (s[i] == '?') { A[s.size() - 1 - i] = -1; continue; } A[s.size() - 1 - i] =...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; const int Imx = 2147483647; char s[1011], ss[1011]; int id[1011], a[1011][1011], sz[1011]; int n, m, w[12], nw[1011], cw[1011]; int dp[1011], ndp[1011], pos[12], cnt[12], it[12]; vector<int> v[10]; int main() { scanf("%s", s); n = strlen(s); reverse(s, s + n); scanf...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; char A[1010], B[1010][1010]; int n, m, len[1010], cost[10], dp[1010][1010]; int val[1010], ml[1010]; pair<int, int> lab[1010]; const int N = 1005; int main() { scanf("%s", A); m = strlen(A); reverse(A, A + m); for (int i = m; i <= N; i++) A[i] = '0'; scanf("%d", &...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("avx2") using namespace std; int dp[2000][2000], need; vector<string> B; vector<int> bask[10]; int cost[1000], c[1000], p[1000], p1[1000], p2[1000]; signed main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); for (int i = 0; i <= 1...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; const int maxn = 1010, inf = 1e9; char s[maxn][maxn]; int len[maxn], n, a[maxn][maxn], m, f[maxn][maxn], val[10], rk[maxn], tong[12], num[maxn], ans = -inf; void paixu(int pos) { memset(tong, 0, sizeof(tong)); for (int i = 1; i <= m; i++) tong[a[i][pos]]++; for (i...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; inline int read() { int sum = 0; char c = getchar(); bool f = 0; while (c < '0' || c > '9') { if (c == '-') f = 1; c = getchar(); } while (c >= '0' && c <= '9') { sum = sum * 10 + c - '0'; c = getchar(); } if (f) return -sum; return sum; } ...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; void getre() { int x = 0; printf("%d\n", 1 / x); } void gettle() { int res = 1; while (1) res <<= 1; printf("%d\n", res); } template <typename T, typename S> inline bool upmin(T &a, const S &b) { return a > b ? a = b, 1 : 0; } template <typename T, typename S> i...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; const int N = 1015; int b[N][N]; char c[N]; int n; char a[N]; int w[15]; int len = 0; int sa[N], rk[N]; int tsa[N], trk[N]; int sum[15]; int f[2][N]; int cost[N][12][2]; int dj[11][N]; int lp[N]; int dp() { for (int i = (int)1; i <= (int)n; i++) sa[i] = i; for (int i = ...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; const int N = 1005; int dp[N][N], n, m, k; int f[N], g[N], a[N], lth[N], b[N][N], cnt[10], val[10]; char s[N]; void sort(int x) { for (int i = 0; i < 10; i++) cnt[i] = 0; for (int i = 1; i <= m; i++) cnt[b[i][x]]++; for (int i = 1; i < 10; i++) cnt[i] += cnt[i - 1]; ...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> const int N = 1005; int b[N][N], cnt[N], t[N], rank[N], a[N], v[15], w, n, nw; long long dp[N][N], ans; char s[N]; void Sort(int x) { memset(cnt, 0, sizeof(cnt)); for (int i = 1; i <= n; i++) cnt[b[i][x]]++; for (int i = 9; i >= 0; i--) cnt[i] += cnt[i + 1]; for (int i = n; i >= 1; i--)...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; int n, m, f[1005][1005], ans, a[1005], b[1005], c[25], cnt[10], vis[1005], clk; char st[1005]; struct num { int v[1005], len; void read() { int i; scanf("%s", st + 1); len = strlen(st + 1); for (i = 1; i <= len; i++) if (st[len - i + 1] >= '0' && s...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at ...
JAVA
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; const int N = (int)2e3 + 5, mod = (int)0; string b[N]; int n, cnt[N], cost[N], dp[N], odp[N], lord[N], ord[N], c[N], tmp[N]; char ch[N]; void radix_sort(int len) { memset(c, 0, sizeof c); for (int j = 0; j < n; ++j) { ch[j] = (b[lord[j]].size() < len ? '0' :...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; mt19937_64 mrand(chrono::steady_clock::now().time_since_epoch().count()); char a[1005], b[1005][1005]; int dp[1005][1005], l[1005]; int d[10]; const int K = 1001; int main() { scanf("%s", a); int len = strlen(a), first = K - len; reverse(a, a + len); for (int i = 0;...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; const long long LOG = 22, N = 2010, INF = 2e9; pair<int, int> ord[N]; int dp[N][N]; char a[N], b[N][N]; int len[N]; int val[N], mxlen[N]; int c[11]; int n, m, p = 1006; int main() { cin >> a; m = strlen(a); reverse(a, a + m); for (int i = m; i <= p; i++) a[i] = '0';...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; int n, m, c[10], l[1010], r[1010], dp[1010][1010]; char s[1010]; struct BigInt { int n, v[1010]; void init(char s[]) { n = strlen(s + 1); memset(v, 0, sizeof(v)); for (int i = 1; i <= n; i++) s[n - i + 1] == '?' ? r[i] = 9 : v[i] = s[n - i + 1] - '0'; ...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; bool debug = 0; int n, m, k; int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; string direc = "RDLU"; long long ln, lk, lm; void etp(bool f = 0) { puts(f ? "YES" : "NO"); exit(0); } void addmod(int &x, int y, int mod = 1000000007) { x += y; if (x >= mod) x -= mod; ...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; const int N = 1005; int a[N]; int dig[N][N]; bool has[N][N]; int cost[10]; int dp[N + 1][N]; int ord[N + 1][N]; int idx[N + 1][N]; int vl[N]; vector<pair<int, int> > gg[10]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> int n; char a[1010]; int al; char b[1010][1010]; int bl[1010]; char tmp[1010]; int dp[1010][1010]; int pord[1010]; int pup[1010]; int npord[1010]; int val[12]; int rev(char *s) { int l; for (l = 0; s[l]; l++) ; for (int i = 0; i < l; i++) { tmp[i] = s[i]; } for (int i = 0; i <...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; const int N = 2005; int n, len, cnt, rnk[N], rk[N], h[N], num[N], dp[N][N], c[15], ans, a[N], b[N][N], l[N], ss[N]; char s[N]; void solve(int pos, int vv) { int mx = 0, sum = 0; for (int i = 1; i <= n; i++) { num[i] = b[i][pos] + vv; if (num[i] >= 10) mx = m...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; string b[1010]; string s; int f[1010][1010], h[1010][1010][12], g[1010][1010][12], R[1010][1010], sa[1010], len[1010]; int L, n, tmp_d, cost[20]; void rlxx(int &x, int y) { if (x < y) x = y; } void trans(int i, int c) { for (int k = 1; k <= n + ...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; vector<int> sais(vector<int> vec) { if (vec.empty()) { vector<int> v; return v; } vector<int> dat; dat.resize(vec.size()); dat[vec.size() - 1] = 0; for (int i = vec.size() - 2; i >= 0; i--) { if (vec[i] > vec[i + 1]) dat[i] = 1; else if (ve...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; const int N = 1007; const int G = 19491001; const int mod = 1019260817; const int mxlen = 1001; void Min(int &x, int y) { if (x > y) x = y; } void Max(int &x, int y) { if (x < y) x = y; } string s[N], now; int n, len[N], Len, w[N], has[N][N], dp[N][N], p[N], Pow[N], hz[...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; char a[1001 + 5], b[1001 + 5][1001 + 5], s[1001 + 5]; int l[1001 + 5], f[1001 + 5][1001 + 5], g[1001 + 5][1001 + 5], sa[1001 + 5][1001 + 5], c[1001 + 5], ss[10]; void read(char* a, int p) { scanf("%s", s); while (s[l[p]]) ++l[p]; for (int i = 0; s[i]; ++i) a[l[p] ...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; char s[3010][3010]; int p[3010][3010], f[3010][3010], c[10], wd[3010]; int n, m, A[3010][3010], lw[3010], up[3010], B[3010][3010], ans, nw[3010], rk[3010], hd[3010], al; inline void Init() { scanf("%s%d", s[0], &n); m = strlen(s[0]); for (int i = 1; i <= n; i++) {...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> const int inf = 1 << 30; char A[1010], B[1010][1010]; int n, lA, lB[1010], m, c[10], f[1010][1010], las[1010], cur[1010], d[1010], tmp[10][1010], cnt[10], to[10], sum[10]; void cmax(int& a, int b) { b > a ? a = b : 1; } int main() { scanf("%s%d", A, &n); lA = strlen(A); cmax(m, lA); ...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; const int N = 1005; char s[N]; int len[N], val[15]; int n, a[N][N], f[N][N]; int rk[N], nrk[N], pos[N], v[N]; void input(int id) { scanf("%s", s + 1); len[id] = strlen(s + 1); reverse(s + 1, s + len[id] + 1); for (int i = (int)(1); i <= (int)(len[id]); i++) a[id...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; int cst[1010], a[1010][1010], mx, sorted[1010][1010], n, pos[1010][1010], mem[1010][1010], cc[1010], szs[1010], szc; char c[1010], s[1010][1010]; void srt() { for (int i = 0; i < n; ++i) { sorted[0][i] = i; } for (int x = 1; x <= mx; ++x) { vector<int> v[1...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; const int max_n = 1011, inf = 1011111111; int n, cost[11], k[111], dp[max_n][max_n], pos[max_n], q[max_n][10], all[max_n], cntx[12], sum[12]; int last[max_n], is_finish[max_n], sum_finish[max_n]; pair<int, pair<int, int> > p[max_n]; char s[max_n]; string a, x[max_n]; st...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> long long dp[1010][1010]; char a[1010], b[1010][1010]; int val[1010], cost[1010], len[1010], ml[1010]; std::pair<int, int> lab[1010]; int n, m, l; int main() { scanf("%s", a); m = strlen(a); std::reverse(a, a + m); for (int i = m; i < 1002 + 1; ++i) { a[i] = '0'; } scanf("%d", &...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; inline long long rd() { long long x = 0; int ch = getchar(), f = 1; while (!isdigit(ch) && (ch != '-') && (ch != EOF)) ch = getchar(); if (ch == '-') { f = -1; ch = getchar(); } while (isdigit(ch)) { x = (x << 1) + (x << 3) + ch - '0'; ch = getch...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; const int N = 1010; char s[N][N], a[N]; int len[N], n, mx, len1; inline void Max(int &a, int b) { if (b > a) a = b; } inline void Max(long long &a, long long b) { if (b > a) a = b; } int c[10], Rank[N], Rank2[N], h[N], C[10]; long long f[N], ...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; const int maxN = 1005, N = 1001; array<array<int, maxN>, maxN> dp; array<string, maxN> B; array<int, 10> c; vector<vector<int>> p(maxN); array<bool, maxN> beg; string A; int n, ax; int input(string &A) { cin >> A; int a = A.size(); reverse(A.begin(), A.end()); while...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; const int N = 1e6; const int M = 123; const long double Pi = acos(-1); const long long Inf = 1e18; const int inf = 1e9; const int mod = 1000200013; const long double eps = 1e-9; void add(int &a, int b) { a += b; if (a >= mod) a -= mod; } int mult(int a, int b) { return ...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; const int N = 1007; char a[N], b[N][N]; int c[13], u[N], v[N], x[N], y[N], t[13]; int main() { int n, i, j, k, l, o, w, m = 0, *f = u, *g = v, *p = x, *q = y; scanf("%s%d", a + 1, &n), reverse(a + 1, a + (l = strlen(a + 1)) + 1), m = max(m, l), memset(f + 1, -63, ...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; const int maxn = 1010; const int M = 1002; long long f[maxn][maxn]; char a[maxn]; char b[maxn][maxn]; int val[maxn]; int cost[maxn]; int len[maxn]; int ml[maxn]; pair<int, int> lab[maxn]; int n, m, l; int main() { scanf("%s", a); m = strlen(a); reverse(a, a + m); fo...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; const int MN = 1010; void radix_sort(int *A, int *B, int *C, int N, int M) { vector<int> D(M, 0); for (int i = 0; i < N; i++) D[B[A[i]]]++; for (int i = 1; i < M; i++) D[i] += D[i - 1]; for (int i = N - 1; i >= 0; i--) C[--D[B[A[i]]]] = A[i]; } int N; string A, B[MN...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; string A, num[1005]; int n, m, Alen, c[10], f[1005][1005]; int a[1005][1005], b[1005], cnt[10], len[1005], ans; pair<int, int> g[1005][1005]; bool flag[1005]; string make(string X) { return X + string(m - X.length(), '0'); } int calc(int x) { int tot = 0; for (int i = 1...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; namespace TYC { const int N = 1000 + 5, DIGIT = 10, INF = 0x3f3f3f3f; int n, len, F[N][N], Val[DIGIT], Cnt[DIGIT], Sum[DIGIT], B[N][N], Id[N], Bask[DIGIT], Q[N], T[N], OK[N][DIGIT], L[N]; char S[N]; inline int ctoi(int *v) { int t = strlen(S + 1); reverse(S + 1, S +...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; const int N = 1024; char s[N]; char a[N][N]; int len[N]; int d[10]; int o[N][N], w[N][N], f[N][N]; int n, m; int main() { scanf("%s%d ", s, &n); int l = strlen(s); reverse(s, s + l); for (int i = 0; i < n; ++i) { scanf("%s ", a[i]); len[i] = strlen(a[i]); ...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; int main() { string a; getline(cin, a); int n; int m = a.size(); reverse((a).begin(), (a).end()); std::vector<int> c(10); scanf("%d\n", &n); std::vector<string> b(n); for (int i = 0; i < n; i++) { getline(cin, b[i]); ...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; const int MOD = (int)1e9 + 7; const int MAXN = (int)1003; const int LOG = (int)11; const int infint = (int)1e9 + 3; const long long inf = (long long)1e12; string A, B[MAXN]; int cost[MAXN], dp[MAXN][MAXN], last[MAXN], n, mx, sza; pair<int, int> radix[MAXN]; void build() { ...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.util.stream.IntStream; import java.util.Arrays; import java.io.BufferedWriter; import java.util.InputMismatchException; import java.io.IOException; import java.util.s...
JAVA
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; const int DIM = 1005; int dp[DIM][DIM], pos[DIM][DIM]; int num[DIM][DIM], ord[DIM][DIM]; int cst[10], dig[DIM]; char str[DIM]; struct Struct { int a, b, id; Struct(int _a = 0, int _b = 0, int _id = 0) : a(_a), b(_b), id(_id) {} } aux[DIM]; void process(int v[DIM], char ...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; template <typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; } template <typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } const int oo = 0x3f3f3f3f; const int maxn = 1010, maxm = 1010; int an; int n; int a[ma...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; const int Maxn = 1005; int n, len, s[Maxn], buc[Maxn], tmp_ord[Maxn], val[Maxn], ord[Maxn], bel[Maxn], f[Maxn][Maxn]; string str, T[Maxn]; void work(int x, int w) { int cost = 0, cnt = 0; for (int i = 1; i <= n; i++) { int now = T[ord[i]][1001 - x] - '0'; if...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; const int N = 1e3 + 5; struct number { int x[N], sz; friend istream &operator>>(istream &stream, number &n) { string s; stream >> s; n.sz = s.size(); for (int i = 0; i < n.sz; i++) n.x[n.sz - i - 1] = (s[i] ^ '?' ? s[i] - '0' : -1); return stre...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; const int MOD = (int)1e9 + 7; const int MAXN = (int)1003; const int LOG = (int)11; const int infint = (int)1e9 + 3; const long long inf = (long long)1e12; string A, B[MAXN]; int cost[MAXN], dp[MAXN][MAXN], last[MAXN], n, mx, sza; pair<int, int> radix[MAXN]; void build() { ...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; const int N = 1e3 + 5; struct num { int x[N], sz; friend istream &operator>>(istream &get, num &n) { string s; get >> s, n.sz = s.size(); for (int i = 0; i < n.sz; i++) n.x[n.sz - i - 1] = (s[i] ^ '?' ? s[i] - '0' : -1); return get; } } a, b[N]; ...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; const int N = 1e3 + 5; struct num { int x[N], sz; friend istream &operator>>(istream &get, num &n) { string s; get >> s, n.sz = s.size(); for (int i = 0; i < n.sz; i++) n.x[n.sz - i - 1] = (s[i] ^ '?' ? s[i] - '0' : -1); return get; } } a, b[N]; ...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> long long dp[1010][1010]; char a[1010], b[1010][1010]; int val[1010], cost[1010], len[1010], ml[1010]; std::pair<int, int> lab[1010]; int n, m, l; int main() { scanf("%s", a); m = strlen(a); std::reverse(a, a + m); for (int i = m; i < 1002 + 1; ++i) { a[i] = '0'; } scanf("%d", &...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; string s[1005]; long long ss[1005]; string q; long long n, qs; long long digits[10]; long long gg[50], gg2[50]; long long LIM = 1005; long long dp[1005], dp2[1005]; long long cmpIdx; bool mycomp(long long a, long long b) { return s[a][cmpIdx] > s[b][cmpIdx]; } void solve() ...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> int a[1010], m, n, b[1010][1010], len[1010], cnt[10], d[10]; int f[1010][1010], g[1010][1010], c[1010][1010]; inline void sort(int i) { memset(cnt, 0, sizeof(cnt)); for (int j = 1; j <= n; j++) cnt[b[j][i]]++; for (int j = 9; j >= 1; j--) cnt[j - 1] += cnt[j]; for (int j = n; j >= 1; j-...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; const int MAXN = 1005; const int INF = 1e9; template <typename T> void chkmax(T &x, T y) { x = max(x, y); } template <typename T> void chkmin(T &x, T y) { x = min(x, y); } template <typename T> void read(T &x) { x = 0; int f = 1; char c = getchar(); for (; !isdi...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> long long dp[1010][1010]; char a[1010], b[1010][1010]; int val[1010], cost[1010], len[1010], ml[1010]; std::pair<int, int> lab[1010]; int n, m, l; int main() { scanf("%s", a); m = strlen(a); std::reverse(a, a + m); for (int i = m; i < 1002 + 1; ++i) { a[i] = '0'; } scanf("%d", &...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> inline void chkmin(T1 &x, T2 y) { if (x > y) x = y; } template <typename T1, typename T2> inline void chkmax(T1 &x, T2 y) { if (x < y) x = y; } inline int readChar(); template <class T = int> inline T readInt(); template <class T> inl...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; long long powmod(long long a, long long b) { long long res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1) res = res * a % mod; a = a * a % mod; } return res; } const int N = 1010, M = 1002; long long dp[N...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; int A[1002], LA; int B[1000][1002], LB[1000]; int C[10]; int M, N; int T[6][1002]; constexpr auto Z = sizeof(T[0]); void Read(int *D, int &L) { static char H[1001]; scanf("%s", H); int m = (int)strlen(H); for (int i = 0; i < m; ++i) D[m - i - 1] = H[i] == '?' ? -1 :...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> const int maxn = 1002, maxm = 1003; int n, m, C[10], dp[maxm][maxn], len[maxn], od[maxn], tmp[maxn]; char A[maxm], B[maxn][maxm]; void fillRev(char *k, int l) { for (int i = 0; i * 2 < l; ++i) std::swap(k[i], k[l - i - 1]); for (int i = 0; i < maxm; ++i) if (!k[i]) k[i] = '0'; } void in...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e3; int n, beg, val[11], sec[MAXN], sc[MAXN], cc[11], gg[50]; string s[MAXN + 5], t; long long d[MAXN + 5][MAXN + 5]; string gen(int x) { string ret; while (x--) ret += '0'; return ret; } void smax(long long &x, long long y) { x = max(x, y); } int ma...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; int n, m, b[1200 + 5][1200 + 5], f[1200 + 5][1200 + 5], g[1200 + 5][1200 + 5], cost[12], cnt[12], c[1200 + 5][1200 + 5]; char s[1200 + 5], a[1200 + 5]; int getnum(int x, int y) { return b[x][y]; } int getval(int x, int y) { return (y > b[x][0] && y > m && g[x][y] == 0...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; inline int getint() { int c, l = 0, x; for (; !isdigit(c = getchar()); l = c) if (c == EOF) return 1 << 31; for (x = c - '0'; isdigit(c = getchar()); x = x * 10 + c - '0') if (c == EOF) break; return l == '-' ? -x : x; } const int N = 1200; char B[N][N], A[N...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; const int N = 1005; char A[N], B[N][N]; int c[10], g[N], b[N][N], l[N], f[N][N], sa[N][N], ss[N]; int gao(int x, int y) { if (y > max(l[x], l[0]) && !g[x]) return 0; return c[g[x]]; } int main() { scanf("%s", A + 1); l[0] = strlen(A + 1); reverse(A + 1, A + l[0] +...
CPP
778_E. Selling Numbers
Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the max...
2
11
#include <bits/stdc++.h> using namespace std; int n, len, Max, ans, C[10], Len[1000 + 5], Dp[1000 + 5][1000 + 5], Rank[1000 + 5][1000 + 5], Ord[1000 + 5][1000 + 5]; char s[1000 + 5], A[1000 + 5][1000 + 5]; int main() { scanf("%s%d", s, &n); Max = len = strlen(s); reverse(s, s + len); for (int i = 1; i <= n;...
CPP