solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
inline int SG(double x) { return x > -1E-8 ? x < 1E-8 ? 0 : 1 : -1; }
long long gcd(long long a, long long b) {
while ((a %= b) && (b %= a))
;
return a + b;
}
int main() {
long long a, b, i, j, d, sa;
scanf("%I64d %I64d", &a, &b);
d = a * b / gcd(a, b);
sa =... | 7 |
#include <bits/stdc++.h>
using namespace std;
vector<unsigned long long> a, b;
int main() {
unsigned long long n, ap, m = 0, k, j = 0;
cin >> n;
for (unsigned long long i = 0; i < n; i++) {
cin >> ap;
a.push_back(ap);
}
for (unsigned long long i = 0; i < n; i++) {
cin >> ap;
b.push_back(ap);
... | 5 |
#include <bits/stdc++.h>
const int maxn = 2000002;
int a[maxn + 1];
int main() {
int n, q, res = 0;
scanf("%d", &n);
while (n--) {
scanf("%d", &q);
a[q]++;
}
for (int i = 0; i < maxn; i++) {
a[i + 1] += a[i] >> 1;
a[i] &= 1;
if (a[i]) res++;
}
printf("%d\n", res);
return 0;
}
| 7 |
#include <bits/stdc++.h>
using namespace std;
vector<int> v;
void div_p(int n) {
int i, sq, j;
sq = sqrt(n);
for (i = 1; i <= sq; i++) {
if (n % i == 0) {
if ((n / i) == i)
v.push_back(i);
else {
v.push_back(i);
if ((n / i)) v.push_back(n / i);
}
}
}
sort(v.be... | 5 |
#include <bits/stdc++.h>
using namespace std;
char s[4004000];
int main() {
scanf("%s", s);
long long n = strlen(s);
long long res = n * (n - 1) / 2;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
bool ok = 1;
for (int k = i; k < j; k++) {
if (s[j] == s[k]) {
i... | 11 |
#include <bits/stdc++.h>
#pragma G++ optimize "O2"
#pragma GCC optimize "O2"
#pragma G++ optimize "O3"
#pragma GCC optimize "O3"
#pragma G++ optimize "Ofast"
#pragma GCC optimize "Ofast"
using namespace std;
int T;
int K;
const int maxn = 1000010;
char S[maxn], a[maxn], b[maxn];
char mp[30];
int len;
char nowstr[maxn];... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const double eps = 1e-8;
long long int n, k, p;
long long int a[10005], b[10005];
bool used[10005];
bool check(long long int t) {
memset(used, 0, sizeof(used));
int lo = 0;
int cnt = 0;
for (int i = 0; i < n; ++i) {
while (lo < k) {
... | 10 |
#include <bits/stdc++.h>
using namespace std;
string str[] = {"S", "M", "L", "XL", "XXL"};
int main() {
int size[5], k;
int v[5][5] = {{0, 1, 2, 3, 4},
{1, 2, 0, 3, 4},
{2, 3, 1, 4, 0},
{3, 4, 2, 1, 0},
{4, 3, 2, 1, 0}};
for (int i = 0; i < 5; i+... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000010;
int _w;
int n, m, nid = 1;
vector<pair<int, int> > a[N];
namespace DSU {
int pa[N];
void init() {
for (int i = 1; i < nid; ++i) pa[i] = i;
}
int find(int u) { return u == pa[u] ? u : pa[u] = find(pa[u]); }
void link(int u, int v) {
u = find(u), v ... | 14 |
#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
template <class T>
using Table = vector<vector<T>>;
const ld eps = 1e-9;
template <class S, class T>
ostream &operator<<(ostream &os, const pair<S, T> v) {
os << "( " << v.first << ", " << v.second << ")";
return o... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
const int MAXK = 1e4 + 10;
const long long INF = 1e18;
long long h, k;
int n, m;
long long Min[MAXK];
bool used[MAXK];
vector<long long> Edges;
vector<pair<long long, int> > mod[MAXK];
set<pair<long long, int> > Set;
bool mrk[MAXN];
bool done[MAXN... | 17 |
#include <bits/stdc++.h>
using namespace std;
template <class A, class B>
ostream& operator<<(ostream& out, const pair<A, B>& a) {
return out << "(" << a.first << "," << a.second << ")";
}
template <class A>
ostream& operator<<(ostream& out, const vector<A>& a) {
out << "";
for (auto it = a.begin(); it != a.end()... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long INF = 9223372036854775807;
int md = 100000000;
const int WHITE = 0;
const int BLACK = 1;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int l = 0, r = 1e9;
int n = 0;
string color;
int START = 0;
cin >> n;
cout << l << " " <<... | 11 |
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
using namespace std;
const long long MAX_SIZE = 100001;
vector<long long> isprime(MAX_SIZE, true);
vector<long long> prime;
vector<long long> SPF(MAX_SIZE);
int getSetBitsFromOneToN(int N) {
int... | 0 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:33554432")
using namespace std;
const double PI = 2 * acos(0.0);
const double EPS = 1e-8;
const int INF = (1 << 30) - 1;
struct func {
string name;
vector<string> partypes;
};
int n, tc;
func f[1000];
map<string, int> name2f;
map<string, string> var2type;
cha... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 6005;
bool u[MAXN * MAXN / 2];
int prm[MAXN * MAXN / 10], top = 0;
int n;
int ans[MAXN];
void prepare() {
u[1] = true;
for (int i = 2; i <= n * (n + 1) / 2; i++) {
if (!u[i]) prm[++top] = i;
for (int j = 1; j <= top && prm[j] * i <= n * (n + 1) ... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long int power(long long int x, long long int y) {
if (y == 0) return 1;
long long int d = power(x, y / 2) % 1000000007;
if (y % 2 == 0)
return (d * d) % 1000000007;
else
return (((x * d) % 1000000007) * d) % 1000000007;
}
int bit[8];
int vis[8];
int tm... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> val(n);
for (int i = 0; i < n; i++) {
cin >> val[i];
}
sort(val.begin(), val.end());
for (int i = val.size() - 1; i >= 0; i--) cout << val[i] << ' ';
cout <<... | 2 |
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename S>
ostream &operator<<(ostream &os, const pair<T, S> &p) {
return os << "(" << p.first << ", " << p.second << ")";
}
template <typename C, typename T = decay<decltype(*begin(declval<C>()))>,
typename enable_if<!is_same<C, string>::... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int sz = 3e5 + 100, inf = -1e9 - 100;
vector<int> a, sum, g[sz];
int dfs(int v, int p, int d) {
int curres = inf;
for (int i = 0; i < g[v].size(); i++)
if (g[v][i] != p) curres = max(dfs(g[v][i], v, d + 1), curres);
if (d >= 2)
return max(curres, a[v] + ... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long int mod_print(long long int x) {
if (x < 0) {
while (x < 0) x += 1000000007;
return x % 1000000007;
}
return x % 1000000007;
}
long long int pairs(long long int x) { return (x * (x - 1)) / 2; }
int main() {
ios_base::sync_with_stdio(false);
cin.t... | 3 |
#include <bits/stdc++.h>
using namespace std;
char atlas[2010][2010];
int d[4][2] = {0, 1, 0, -1, 1, 0, -1, 0};
char tag[4] = {'>', '<', 'v', '^'};
int deg[2010][2010];
queue<pair<int, int> > q;
inline bool judge(int i, int j, int n, int m) {
return i >= 0 && i < n && j >= 0 && j < m && atlas[i][j] == '.';
}
void MAI... | 12 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast", "unroll-loops")
const int MAXN = 1e6 * 2;
bool us[MAXN];
vector<int> arr;
int n, a, b;
int dp[1 << 6];
int main() {
ios_base::sync_with_stdio(false);
cin >> n >> a >> b;
vector<int> c = {a, a, a, a, b, b};
for (int i = 1; i < (1 << 6); ... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long read() {
long long s = 0, w = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') w = -w;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
s = (s << 1) + (s << 3) + (ch ^ '0');
ch = getchar();
}
return s * w;
}
lon... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, i, j, k;
string s, t;
vector<int> ans;
bool solved = true;
cin >> n >> s >> t;
for (i = 0; i < n; i++) {
bool matched = false;
for (j = i; j < n; j++) {
if (s[j] == t[i]) {
ma... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int k;
cin >> k;
string s;
cin >> s;
string temp = s;
for (int i = 1; i < k; i++) s += temp;
int t;
cin >> t;
map<char, vector<int> > myMap;
for (int i = 0; i < s.length(); i++) myMap[s[i]].push_back(i);
while (t--) {
int x;
char c... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long i, n, x0, a, b, p1 = 1000000009, p2;
int main() {
cin >> n >> x0;
for (i = 1; i <= n; i++) {
cin >> a >> b;
if (b < a) swap(a, b);
p1 = min(p1, b);
p2 = max(p2, a);
}
if (p1 < p2) {
cout << "-1" << endl;
return 0;
}
if (p1 >= x0... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
long long n, x, k;
cin >> n >> x >> k;
vector<long long> a(n);
for (auto& ai : a) cin >> ai;
sort(begin(a), end(a));
auto get = [&](long long from, long long to) -> int {
if (from > to) return 0;
... | 9 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6 + 10;
const long long MOD = 1e9 + 7;
long long n, k;
bool isPrime[N];
vector<long long> primes;
void buildSieve() {
for (long long i = 2; i < N; i++) isPrime[i] = 1;
for (long long i = 2; i * i < N; i++) {
if (not isPrime[i]) continue;
fo... | 13 |
#include <bits/stdc++.h>
using namespace std;
long long n, a[100003], ans = 0, sum = 0, k = 0, r = 0;
signed main() {
cin >> n;
for (long long i = 1; i <= n; i++) {
cin >> a[i];
sum += a[i];
}
if (sum % 3 != 0) {
cout << 0;
return 0;
} else
sum /= 3;
for (long long i = 1; i <= n - 1; i++... | 4 |
#include <bits/stdc++.h>
using namespace std;
int norton(int n) {
for (int i = 0; i <= n / 4; ++i) {
if ((n - i * 4) % 7 == 0) {
return i;
}
}
return -1;
}
int main() {
int n, p;
cin >> n;
p = norton(n);
if (p == -1) {
puts("-1");
} else {
for (int i = 0; i < p; ++i) {
putcha... | 2 |
#include <bits/stdc++.h>
using namespace std;
int mcount(char mychar, char c) {
int next, prev;
next = max(mychar, c) - min(mychar, c);
prev = (min(mychar, c) - max(mychar, c)) + 26;
return min(prev, next);
}
int main() {
int n;
string s;
cin >> n >> s;
int mini = 1000;
for (int i = 0; i < n - 3; i++)... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 70;
const int maxk = 1e3 + 10;
int n, m, r, a, s, t, k;
int d[maxn][maxn][maxn];
int dp[maxk][maxn][maxn];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
memset(dp, 63, sizeof(dp));
cin >> n >> m >> r;
for (int i = 1; i <= m... | 10 |
#include <bits/stdc++.h>
long long a, b, c, l;
long long all;
inline long long min(long long a, long long b) { return a < b ? a : b; }
inline long long max(long long a, long long b) { return a > b ? a : b; }
long long calc(long long a, long long b, long long c) {
long long res = 0;
for (long long i = max(0, b + c -... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
int ans;
int arr[4] = {1, 2, 3, 5};
cout << k * (5 + 6 * (n - 1)) << endl;
for (int i = 0; i < n; i++) {
for (int j = 0; j < 4; j++) {
cout << k * (arr[j] + 6 * i) << ' ';
}
cout << endl;
}
}
| 11 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
int n, m, a[370009], v[370009][5];
class dual {
public:
int a, b;
dual() { b = rand(); }
};
int operator<(const dual& s, const dual& d) {
return ((s.a < d.a) || (s.a == d.a) && (s.b < d.b));
}
void peres(int i) {
int j = ... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, minm = 0, siz = 0, j = 0;
scanf("%d%d", &n, &k);
int z;
int arr[n];
set<int> st;
for (int i = 0; i < n; i++) {
scanf("%d", &z);
st.insert(z);
if (siz < st.size()) {
siz++;
arr[j++] = z;
}
}
sort(arr, arr + j... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, a[2], b[2], i;
int main() {
cin >> n;
while (a[0] * a[1] < 2) {
cin >> n;
b[n % 2] = ++i;
a[n % 2] += 1 - a[n % 2] / 2;
}
cout << b[a[0] - 1];
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int x, y;
bool operator<(const node &A) const { return x > A.x; }
} ans[100005];
int x[100005], y[100005];
priority_queue<node> Q[100005 << 1];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
int x, y;
scanf("%d %d", &x, &... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int T;
scanf("%d", &T);
while (T--) {
int x1, y1, x2, y2;
scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
int ans = abs(x1 - x2) + abs(y1 - y2);
if (x1 == x2 || y1 == y2) {
printf("%d\n", abs(x1 - x2) + abs(y1 - y2));
} else {
print... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const long long LINF = 1e18;
const int WOW = 40000;
const int NIL = 0;
const int dy[8] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dx[8] = {0, 1, 0, -1, 1, -1, 1, -1};
const double PI = 2 * acos(0);
const int MAXN = 1005;
double me... | 12 |
#include <bits/stdc++.h>
using namespace std;
int n, m, l[65], r[65], pos[65 * 65], f[40005][255], t = 0;
bitset<125> s[40005];
inline bool cmp(int x, int y) { return f[x][0] > f[y][0]; }
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) scanf("%d", &l[i]), l[i] += 10000;
for (int i = 1; i <= m; i+... | 13 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = (long long)(1e18);
int main() {
long long x, y, l, r;
cin >> x >> y >> l >> r;
vector<long long> res;
res.push_back(l - 1);
res.push_back(r + 1);
vector<long long> arr_deg_x;
vector<long long> arr_deg_y;
long long deg_x = 1;
long long... | 10 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long int n, M;
cin >> n >> M;
vector<long long int> a(n);
vector<vector<long long int> > v;
long long int c = 1, sum = 0;
for (long long int i = 0; i <= n - 1; i++) {
cin >> a[i];
if (i > 0) {
v.push_back({c, a[i] - a[i - 1]});
... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
int dp1[4010][4010] = {0};
int dp2[4010] = {0};
int main() {
int n, a[100100], dp1[100100] = {0}, visited[100100] = {0};
priority_queue<pair<int, int>, vector<pair<int, int> >,
greater<pair<int, int> > >
Q;
scanf("%d"... | 8 |
#include <bits/stdc++.h>
using namespace std;
int N, M, S, T, out_degree[1000001], dp[1000001];
vector<int> in[1000001];
int main() {
scanf("%d%d", &N, &M);
for (int i = 0; i < (M); ++i) {
int a, b;
scanf("%d%d", &a, &b);
in[b].push_back(a);
++out_degree[a];
}
scanf("%d%d", &S, &T);
fill(dp, d... | 18 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using D = double;
using uint = unsigned int;
template <typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937 rng(chrono::steady_clock::now().time_since_epo... | 15 |
#include <bits/stdc++.h>
using namespace std;
vector<long long> v;
set<pair<int, int> > S;
const int sz = 100010;
int cowbells[sz];
int main() {
int n, k, res, st;
cin >> n >> k;
for (int i = 1; i <= n; ++i) {
cin >> cowbells[i];
}
res = 0;
while (2 * k != n && n) {
res = max(res, cowbells[n]);
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int vis[1000], q[1000], node[1000], n, a[1000][1000], m;
long double ans = 0;
void solve(int u) {
int l = 0, r = 1;
q[r] = u;
int to = 0;
long double maxn = 0;
for (int i = 1; i <= n; i++)
if (a[i][u]) {
if ((double)(node[u] + node[i] * 1.0) / (double)a[... | 8 |
#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n, k;
long long int s, t;
cin >> n >> k >> s >> t;
vector<int> c(n), v(n);
for (int i = 0; i < n; i++) {
cin >> c[i] >> v[i];
}
vector<long long int> d(k);
... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int di[] = {0, 0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {0, 1, 0, -1, 0, 1, -1, -1, 1};
char maze[10][10][10];
bool doMagic(int m = 0, int i = 8, int j = 1) {
if (m == 8) return (true);
for (int k = 0; k < 9; k++) {
int i1 = i + di[k];
int j1 = j + dj[... | 7 |
#include <bits/stdc++.h>
#define int long long
#define ff first
#define ss second
#define mod 1000000007
#define sz(a) (long long)((a).size())
#define pb push_back
#define all(c) c.begin(),c.end()... | 0 |
#include <bits/stdc++.h>
using namespace std;
int ans;
map<string, int> M;
stack<string> S;
int main() {
char ch = getchar();
for (;;) {
string s;
if (ch == ':' || ch == ',') {
ch = getchar();
continue;
}
if (ch == '\n' || ch == '\r') break;
if (ch == '.') {
M[S.top()]--, S.pop... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, c = 0;
string s1 = "Tetrahedron", s2 = "Cube", s3 = "Octahedron",
s4 = "Dodecahedron", s5 = "Icosahedron";
cin >> t;
while (t--) {
string s;
cin >> s;
if (s.compare(s1) == 0)
c = c + 4;
else if (s.compare(s2) == 0)
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
long long s[N], a[N];
void solve() {
int n;
cin >> n;
long long sum = 0;
for (int i = 0; i < n; i++) {
cin >> s[i];
sum += s[i];
}
long long c = 1LL * n * (n + 1) / 2;
if (sum % c) {
cout << "NO\n";
return;
}
sum /= c... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
const long long MOD = 1e9 + 7;
pair<int, int> p;
int main() {
int n, k;
cin >> n >> k;
string s;
cin >> s;
int c1 = 0;
int c2 = 0;
for (int i = 0; i < n;) {
if (s[i] == 'N') {
int j = i;
while (j < n && s[j] == 'N') j+... | 12 |
#include <bits/stdc++.h>
using namespace std;
vector<int> v, r;
int n, e;
int p2[32];
int main() {
scanf("%d", &n);
scanf("%d", &e);
v.push_back(e);
for (int i = 1; i < n; i++) {
scanf("%d", &e);
if (e == v[i - 1]) continue;
v.push_back(e);
}
sort(v.begin(), v.end());
reverse(v.begin(), v.end(... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
long long ans = 0;
cin >> n;
for (long long i = 3; i <= n; i++) {
ans += i * (i - 1);
}
cout << ans;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000009;
long long po(long long a, long long b) {
long long tot = 1, d = 1, w = a;
while (d <= b) {
if (d & b) tot *= w;
tot %= mod;
w *= w;
w %= mod;
d *= 2;
}
return tot;
}
int main() {
long long n, m, k;
cin >> n >> m >>... | 8 |
#include <bits/stdc++.h>
using namespace std;
map<long long, long long> ct;
long long a[100010];
long long power[1000];
long long check_count(long long cumsumj, int powcount) {
long long ans = 0;
for (int i = 0; i < powcount; i++) {
long long temp = cumsumj - power[i];
ans += ct[temp];
}
return ans;
}
l... | 10 |
#include <bits/stdc++.h>
using namespace std;
int st[(1 << 18) + 1][2], num[100010];
void update(int i, int L, int R, int u) {
int curr = 1;
while (L < R) {
int m = ((L + R) >> 1);
if (i <= m) {
R = m;
curr = (curr << 1);
} else {
L = m + 1;
curr = ((curr << 1) | 1);
}
}
... | 14 |
#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 0, 1, -1, 1, -1, 1, -1}, dy[] = {1, -1, 0, 0, 1, -1, -1, 1};
inline void cn(long& n) {
n = 0;
long ch = getchar();
int sign = 1;
while (ch < '0' || ch > '9') {
if (ch == '-') sign = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
... | 10 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-4;
const int maxn = 1e3 + 7;
char ch[maxn][maxn];
char cnt[maxn];
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++) {
scanf("%s", ch[i]);
}
for (int i = 0; i < m; i++) {
int mx = '0';
for (int j = 0; j < n;... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string a = {};
string s = {};
cin >> a >> s;
sort(s.begin(), s.end());
for (int i = 0; i < a.length(); i++) {
if (a[i] >= s[s.length() - 1]) {
cout << a[i];
} else if (a[i] < s[s.length() - 1]) {
cout << s[s.length() - 1];
s.... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int e[25][25], to[25], vis[25];
int n, f[1 << 20 | 5];
char s[N], t[N];
void dfs(int x) {
vis[x] = 1;
for (int i = (int)(0); i <= (int)(19); i++)
if (!vis[i] && e[x][i]) dfs(i);
}
void solve() {
memset(e, 0, sizeof(e));
memset(to, 0, sizeof... | 23 |
#include <bits/stdc++.h>
int main() {
int q;
std::cin >> q;
std::cin.get();
int i, j;
for (i = 0; i < q; ++i) {
std::string s;
std::cin >> s;
std::cin.get();
int n_l = 0, n_r = 0, n_u = 0, n_d = 0;
for (auto c : s) {
if (c == 'L') {
++n_l;
} else if (c == 'R') {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int DEBUG = 0;
int compare_inc(const void *a, const void *b) {
int64_t x = *(int64_t *)a;
int64_t y = *(int64_t *)b;
if (x > y)
return 1;
else if (x < y)
return -1;
else
return 0;
}
const int MAXN = 1000010;
const int64_t MULT = 3;
int64_t hashBase[MAX... | 15 |
#include <bits/stdc++.h>
using namespace std;
long long n, i, j, k, c, cont;
char p;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
long long col[n], fil[n];
for (i = 0; i < n; i++) {
col[i] = 0;
fil[i] = 0;
}
for (i = 0; i < n; i++) {
for (j = 0; j <... | 0 |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
register long long x = 0;
char zf = 1;
char ch;
while (ch != '-' && !isdigit(ch)) ch = getchar();
if (ch == '-') zf = -1, ch = getchar();
while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
return x * zf;
}
int i, j, k, m, n, x... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios ::sync_with_stdio(false);
cin.tie(0);
string s, p;
cin >> p >> s;
sort(s.begin(), s.end());
int i = 0, j = s.size() - 1;
while (i < p.size() && j >= 0) {
if (p[i] < s[j]) {
p[i] = s[j];
i++;
j--;
} else {
i++;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
int n, m, q, x, y;
unordered_map<int, unordered_map<int, int> > state;
template <class T>
void read(T& x, T f = 1, char ch = getchar()) {
x = 0;
while (ch < '0' || ch > '9') f = (ch == '-' ? -1 : 1), ch = getchar();
while (ch >= '0' && ch <= ... | 19 |
#include <bits/stdc++.h>
using namespace std;
long long int arr[1000001];
long long int dp[2003][2003];
long long int solve(long long int n, long long int k, long long int i,
long long int cnt) {
if (i > n) return 0;
if (cnt == k) return 1;
if (dp[i][cnt] != -1) return dp[i][cnt];
long long ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 10005;
const long long base[2] = {31, 37};
const long long Mod[2] = {998244353, 1000000007};
int dp[MAXN], pre[MAXN];
unordered_map<long long, int> mp;
string dic[100005];
void output(int now) {
if (now == 0) return;
output(now - (int)dic[pre[now]].leng... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long power(long long paye, int tavan) {
if (paye == 0) return 1;
long long ans = paye;
for (int i = 1; i < tavan; i++) ans = (ans * paye) % 1000000007;
return ans;
}
int a[10];
bool accept(int n) {
for (int i = 1; i <= n; i++) {
int j = 0;
int t = a[i... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
vector<int> G[N];
vector<int> ind[N];
vector<int> stk;
bool vis[N];
int deep[N];
int sq;
void dfs(int u, int fa, int dp) {
vis[u] = true;
stk.push_back(u);
ind[dp % (sq - 1)].push_back(u);
deep[u] = dp;
for (int v : G[u]) {
if (v != fa) ... | 17 |
#include <bits/stdc++.h>
using namespace std;
unordered_map<long long, unordered_set<long long> > adj;
vector<long long> vis1, lft, par;
long long c = 1;
void mark(long long loc, long long till) {
long long mx = max(loc, till);
long long mn = min(loc, till);
while (loc != till) {
loc = par[loc];
mx = max(... | 15 |
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
typedef long long ll;
typedef long double ld;
typedef complex... | 20 |
#include <bits/stdc++.h>
using namespace std;
struct edge {
int u, v, c, d = 0;
edge(int _u, int _v, int _c) : u(_u), v(_v), c(_c){};
};
vector<int> f, vis;
vector<edge> edges;
vector<vector<int>> g;
int main() {
ios::sync_with_stdio(false);
cout.tie(nullptr);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
... | 13 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fs first
#define sc second
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
int x, y;
int SOLVE() {
scanf("%d%d", &x, &y);
// x가 무한대라면
// special은 [0,1,2,3,4,5,6...] 으로 증가
... | 9 |
#include <bits/stdc++.h>
int st[1000000], n, m, q, a, b, c, d, h[100], ans, sum;
char map[100][100];
int main() {
scanf("%d%d%d\n", &n, &m, &q);
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) scanf("%c", &map[i][j]);
scanf("\n");
}
while (q--) {
scanf("%d%d%d%d\n", &a, &b, &c, &d);
... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
const int MOD = 1e9 + 7;
const int SEED = 29;
long long int p[N];
long long int h[N];
std::vector<pair<int, int> > v;
map<long long int, long long int> mp;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
int n, m;
c... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<pair<int, int> > a(n);
vector<int> dif1(2001, 0);
vector<int> dif2(2001, 0);
for (int i = 0; i < n; i++) {
cin >> a[i].first;
cin >> a[i].second;
dif1[a[i].f... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, q;
scanf("%d%d", &n, &q);
int t0 = 0, t1 = 1;
for (int i = 0; i < q; i++) {
int t;
scanf("%d", &t);
if (t == 1) {
int d;
scanf("%d", &d);
t0 += d;
t1 += d;
t0 = (t0 + n) % n;
t1 = (t1 + n) % n;
... | 10 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll gcd(const ll a, const ll b) { return b == 0 ? a : gcd(b, a % b); }
pair<ll, ll> bezout(const ll m1, const ll m2) {
if (m2 == 0)
return {1, 0};
else {
ll a1, a2;
tie(a1, a2) = bezout(m2, m1 % m2);
return {a2, a1 - a2 * (m1 / m2)};... | 21 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
const int maxt = 1 << 17;
int n, q;
long long d[maxn], h[maxn];
long long allc;
struct Node {
long long lmx, rmx, mx;
Node() {}
Node(long long a, long long b, long long c) : lmx(a), rmx(b), mx(c) {}
} tree[maxt * 2];
Node merge(Node &x, Node... | 15 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 998244353, n, m, x, y, ans, l, r;
map<int, int> mapa1, mapa2;
map<pair<int, int>, int> mapa;
inline long long fuctorial(long long n) {
long long res = 1;
for (int i = 1; i <= n; i++) {
res *= i;
res %= mod;
}
return res;
}
int main() {
ios_... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const long long int inf = 2e18;
const long double eps = 1e-9;
const int NN = 1e5 + 2;
vector<vector<int> > adj;
int u[NN];
int curr[NN];
bool vis[NN];
vector<vector<int> > scc;
stack<int> STACK;
void DFS(int source, bool second_DFS) {
vis[source] ... | 11 |
#include <bits/stdc++.h>
using namespace std;
int mod;
vector<int> v;
map<int, vector<int> > Map;
int mul(int x, int y) { return (int)((long long int)x * y % mod); }
int main() {
int n, x;
scanf("%d", &n);
for (int j = 0; j < 2; j++)
for (int i = 0; i < n; i++) {
scanf("%d", &x);
Map[x].push_back(... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char a[1000];
long long int i, b, co = 0;
cin >> a;
for (i = 0; i < strlen(a); i++) {
cin >> a[i];
if (a[i] <= 'Z') {
co++;
}
}
if (co == strlen(a)) {
for (i = 0; i < strlen(a); ++i) {
cout << char(tolower(a[i]));
}
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000 * 1000 + 10;
const int maxn5 = 5 * 1000 * 100 + 10;
const int maxn3 = 1000 + 10;
const long long mod = 1000 * 1000 * 1000 + 7;
const long long inf = 1LL * 2 * 1000 * 1000 * 1000 * 1000 * 1000 * 1000 + 10;
set<pair<long long, int>> av;
bool mark[maxn5];... | 10 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 10;
long long A[2][N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.precision(10);
cout << fixed;
long long n, x;
cin >> n;
for (long long i = 1; i <= 2 * n; i++) {
cin >> x;
if (A[0][x] == 0) {
A[0... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N, cnt = 0, p = 2;
scanf("%d", &N);
char CV[56];
vector<char> CV2;
scanf("%s", CV);
for (int i = 0; i < N; i++) {
if (i >= cnt) {
CV2.push_back(CV[i]);
cnt += p++;
}
}
for (int i = 0; i < CV2.size(); i++) printf("%c", CV2... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int M = (int)(1e9 + 7);
int dp[2005][2005];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, k;
cin >> n >> k;
for (int i = 1; i <= n; ++i) {
dp[1][i] = 1;
}
for (int i = 1; i < k; ++i) {
for (int j = 1; j <= n; ++j) {
for (int ... | 6 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool upmin(T &x, T y) {
return y < x ? x = y, 1 : 0;
}
template <typename T>
inline bool upmax(T &x, T y) {
return x < y ? x = y, 1 : 0;
}
const long double eps = 1e-9;
const long double pi = acos(-1);
const int oo = 1 << 30;
const long long... | 20 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
char str[10][10];
int a[10], ans, p[10];
int main() {
cin >> n >> k;
for (int i = 0; i < n; ++i) cin >> str[i];
for (int i = 0; i < k; ++i) a[i] = i;
ans = ~0U >> 3;
do {
memset(p, 0, sizeof(p));
for (int i = 0; i < n; ++i)
for (int j = 0; ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
const int maxn5 = 5e5 + 10;
const int maxnt = 1.2e6 + 10;
const int maxn3 = 1e3 + 10;
const long long mod = 1e9 + 7;
const long long inf = 2e18;
string s, t, r;
long long n, k;
bool same(int ind) {
r = "";
for (int i = ind; i < n; i++) r.push_... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int n;
int a[maxn];
int cnt[maxn];
int inc[maxn], d[maxn];
int cnt_inc, cnt_d;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
cnt[a[i]]++;
if (cnt[a[i]] == 3) {
printf("NO\n");
return 0... | 2 |
#include <bits/stdc++.h>
using namespace std;
void dummy() {}
int n;
long long data[500];
long long gr[500];
void fill(long long v) {
memset(gr, 0, sizeof(gr));
int i = 0;
while (v) {
while (data[i] > v) i++;
long long c = v / data[i];
gr[i] += c;
v %= data[i];
}
}
int main() {
cin >> n;
for... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int MAX = 1e6;
vector<pair<int, int> > adj[MAX];
bool prime[MAX];
int prime_numbers[9999999], pos;
void sieve() {
prime[0] = 1;
prime[1] = 1;
for (int i = 4; i <= MAX; i += 2) prime[i] = 1;
int root = sqrt(MAX);
for (int i = 3; ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, m, d;
int a[1200000];
int ws(int n) {
int ans = 0;
while (n) {
ans++;
n >>= 1;
}
return ans;
}
int main() {
while (cin >> n) {
for (int i = 0; i <= n; i++) a[i] = 0;
int newl = n, nn;
while (newl > 0) {
int l = ws(newl);
int ... | 9 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.