solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const int maxn = 10001005;
int p[maxn / 10], cnt;
int a[500005], b[500005];
bool vis[maxn];
void init() {
cnt = 0;
for (int i = 2; i < maxn; i++) {
if (!vis[i]) {
p[cnt++] = i;
}
for (int j = 0; j < cnt; j++) {
i... | 4 |
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int n,q;
string s;
vector<pair<char,bool> >a;
int main()
{
cin>>n>>q>>s;
for(int i=0;i<q;i++)
{
char t,d;cin>>t>>d;
a.push_back(make_pair(t,d=='R'));
}
int L=0;
for(int i=q;L<n&&i--;)
{
if(a[i].second)
{
if(L>0&&a[i].first==s... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
const int MOD = 1e9 + 7;
int v[N], fr[N];
int calc(int x, int p, int y) {
if (p == 1) {
return x;
}
int ans = 1;
for (int i = 1; i <= y; i++) {
if (1LL * ans * p > N) {
return -1;
}
ans *= p;
}
if (1LL * x * ans > N) ... | 5 |
#include <bits/stdc++.h>
int main() {
int n;
scanf("%d", &n);
float b = n;
if (n == 1) {
printf("YES");
} else {
while (b > 1.00) {
b = b / 2.00;
}
if (b == 1.00) {
printf("YES");
} else {
printf("NO");
}
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
constexpr int MAXN = 1e6 + 6;
constexpr ll INF = 1e18;
int n, m, k;
int last[MAXN];
int a[MAXN];
int score(int len) {
int p = 0;
int hops = 0;
while (p < n) {
p = p + len;
++hops;
if... | 5 |
#include <iostream>
#include <string>
#include <regex>
using namespace std;
int main() {
string s;
getline(cin, s);
string suffix = s;
smatch m;
for (auto i = s.cbegin();
regex_search(i, s.cend(), m, regex("apple|peach"));
i = m[0].second) {
cout << m.prefix() << (m.str()[0] == 'a' ? "peach" : "apple");
... | 0 |
#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... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 7;
const long long linf = 1e15;
mt19937 orz(time(0) ^ clock());
int rt[N], ch[N][2], key[N], val[N], siz[N], tot;
long long sum[N];
int newn(int w) {
++tot, val[tot] = w, sum[tot] = w, key[tot] = orz(), siz[tot] = 1;
return tot;
}
void upd(int x) {
... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
long long binpow(long long a, long long b) {
long long res = 1;
while (b) {
if (b & 1) res = (res * a) % MOD;
a = (a * a) % MOD;
b >>= 1;
}
return res;
}
long long mod... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t, n;
cin >> t;
while (t--) {
cin >> n;
cout << n / 2 << "\n";
}
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
bool ok(string s) {
int l = 0, r = (int)s.size() - 1;
while (l < r) {
if (s[l] != s[r]) return false;
++l, --r;
}
return true;
}
void solve() {
string s;
cin >> s;
int n = (int)s.size();
int i = 0, j = n - 1;
string t = "",... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long n;
long long A[20];
long long dfs(long long x, long long k) {
if (x == 0) return 0;
if (x % A[k] == 0) return x / A[k] * k;
long long a = dfs(x % A[k], k - 1) + x / A[k] * k;
long long b = dfs(A[k] - x % A[k], k - 1) + (x / A[k] + 1) * k;
return min(a, b... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int MXN = int(1e6) + 9;
const int MOD = 998244353, inv2 = MOD - MOD / 2;
long long n, m, a, ans = 1;
long long b[MXN];
long long powm(long long x, long long n = MOD - 2) {
long long r = 1;
for (; n; n >>= 1, x = x * x % MOD)
if (n & 1) {
r = r * x % MOD;... | 5 |
#include <bits/stdc++.h>
using namespace std;
char s[10][10];
int x, y;
bool kt = false;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
for (int i = 1; i <= 9; ++i)
for (int j = 1; j <= 9; ++j) cin >> s[i][j];
cin >> x >> y;
while (x > 3) x -= 3;
while (y > 3) y -= 3;
for (i... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, i, timer, x, res[100005];
stack<int> v;
int main() {
scanf("%d", &n);
for (i = 1; i <= (n << 1); i++) {
char ch;
cin >> ch;
if (ch == '+')
v.push(timer++);
else {
if (v.empty()) return puts("NO"), 0;
scanf("%d", &x);
if (x ... | 4 |
#include <bits/stdc++.h>
int n, a[400200], p[400200], m, fl[400200];
long long ans;
int gcd(int x, int y) { return !y ? x : gcd(y, x % y); }
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", a + i);
for (int i = 1; i * i <= n; i++) {
if (n % i == 0) {
p[m++] = i;
if (i * i != n... | 5 |
#include <bits/stdc++.h>
using namespace std;
string a2, a1, b2, b1;
void f() {
if (a1[0] == 'X')
swap(a1[0], a2[0]);
else if (a2[0] == 'X')
swap(a2[0], a2[1]);
else if (a2[1] == 'X')
swap(a2[1], a1[1]);
else if (a1[1] == 'X')
swap(a1[1], a1[0]);
}
int main() {
int i, j;
cin >> a1 >> a2 >> b... | 1 |
#include <bits/stdc++.h>
using namespace std;
int m, n, j, k, l, i, o, p, __t, A[10], cnt;
char ch;
void read(int &a) {
for (ch = getchar(); (ch < '0' || ch > '9') && (ch != '-'); ch = getchar())
;
if (ch == '-')
a = 0, __t = -1;
else
a = ch - '0', __t = 1;
for (ch = getchar(); ch >= '0' && ch <= '9... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 7;
char z[maxn];
int pos = 0, len, record = -1;
vector<string> keke[maxn >> 1];
string read_string() {
int t = pos;
while (z[pos] != ',' && z[pos] != '\0') pos++;
string k(z + t, z + pos);
pos++;
return k;
}
int read_number() {
int sum = 0... | 5 |
#include <iostream>
using namespace std;
int main(){
long long x, ans;
cin >> x;
ans = x / 11 * 2;
x %= 11;
ans += !!x + (x > 6);
cout << ans << endl;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T SQR(T a) {
return a * a;
}
template <class T>
inline T gcd(T a, T b) {
a = abs(a);
b = abs(b);
if (!b) return a;
return gcd(b, a % b);
}
template <class T>
inline T lcm(T a, T b) {
a = abs(a);
b = abs(b);
return (a / _gcd(a, b)) *... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXN = 200000;
const int MAXQ = 200000;
typedef struct Q {
int lx, ly, hx, hy;
} Q;
typedef struct Z {
int x, y, i, j;
} Z;
bool operator<(const Z &a, const Z &b) { return a.x < b.x... | 3 |
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;
LL inv(LL x, LL m) { return x > 1 ? inv(m % x, m) * (m - m / x) % m : x; }
LL powmod(LL a, LL k, LL m) {
LL res = 1;
for (a %= m; k; k >>= 1, a = a * a % m)
if (k & 1) res = res * a % m;
return res;
}
int main() {
... | 5 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
template <class C>
void mini(C &a4, C b4) {
a4 = min(a4, b4);
}
template <class C>
void maxi(C &a4, C b4) {
a4 = max(a4, b4);
}
template <class TH>
void _dbg(const char *sdbg, TH h) {
cerr << sdbg << '=' << h << endl;
}
template <class TH, c... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 8005;
char ibuf[1 << 24], *ih = ibuf;
inline void read(int& x) {
for (; !isdigit(*ih); ++ih)
;
for (x = 0; isdigit(*ih); x = x * 10 + *ih++ - 48)
;
}
int n, i, j, k, x, ind[N];
bitset<N> b[N];
bool bb[N];
int main() {
scanf("%d", &n);
fread(ibu... | 5 |
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... U> void assign(V<T>& v, int n, const U&... u... | 0 |
#include<iostream>
#include<cstring>
using namespace std;
int n, m;
int scene[100][100], pict[50][50];
int x, y;
bool check0(int si, int sj){
bool first = true;
for(int i = 0; i < m; i++){
for(int j = 0; j < m; j++){
if(pict[i][j] == -1) continue;
if(pict[i][j] == scene[si+... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5, LOGMX = 19;
int n, T;
int target[N], pre[N], last[N], tot = 0;
int f[N][20], dep[N];
void add(int u, int v) {
target[++tot] = v;
pre[tot] = last[u];
last[u] = tot;
}
void dfs(int u, int fa) {
f[u][0] = fa;
dep[u] = dep[fa] + 1;
for (int i ... | 4 |
#include <bits/stdc++.h>
using namespace std;
string pta[] = {"S", "M", "L", "XL", "XXL", "XXXL"};
int32_t main() {
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
long long a[6];
for (long long i = 0; i < 6; i++) cin >> a[i];
map<string, long long> m{{"S", 0}, {"M", 1}, {"L", 2},
... | 4 |
#include <bits/stdc++.h>
using namespace std;
string s;
void solve(string k, long long sum, long long i) {}
int32_t main() {
ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
long long t = 1;
while (t--) {
cin >> s;
long long n = s.length();
vector<long long> v(n);
for (long l... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int Mod = 1e9 + 7;
int p, k;
char str[1010];
int len;
int s[1010], t[3400];
int n;
int work() {
while (len >= 0 && !s[len]) len--;
if (len < 0) return -1;
static int r[1010];
for (int i = 0; i <= len; i++) r[i] = 0;
long long res = 0;
for (int i = len; i >... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
long long t;
cin >> t;
while (t--) {
int n;
string a, b;
cin >> n >> a >> b;
vector<int> res;
for (int i = 0; i < n; i++) {
if (a[i] != b[i]) {
if (i != 0) res.p... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long n, maxQSize;
queue<pair<long long, long long> > q;
vector<pair<long long, long long> > v;
vector<long long> res;
int main() {
while (cin >> n >> maxQSize) {
res = vector<long long>(n);
v = vector<pair<long long, long long> >(n);
for (int i = 0; i < n... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1LL << 30;
vector<bool> s;
int n, r;
int main() {
ios::sync_with_stdio(false);
s.resize(1000 * 1000);
cin >> n >> r;
int res = INF, x;
for (int i = 0; i <= r; i++) {
int moveNum = 0, wMove = 0, a = i, b = r;
while (a != 0 && wMove < res) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
void solve(int N) {
vector<int> v(401);
int max_len = 0;
for (int i = 0; i < N * (N-1) / 2; i++) {
int j; cin >> j; v[j]++;
max_len = max(max_len, j);
}
set<vector<int>> ans;
for (int i = 0; i < (1<<(N-1)); i++) {
vect... | 0 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pi = pair<int, int>;
ll n, arr[5050], fac[5050];
ll ncr(ll N, ll R) {
ll temp = 1;
for (ll i = 0; i < R; i++) temp *= N - i;
return temp / fac[R];
}
int main() {
fac[0] = fac[1] = 1;
for (int i = 2; i <= 5000; i++) fac[i] = fac[i - 1] *... | 5 |
#include <bits/stdc++.h>
using namespace std;
struct target {
int x;
int y;
long long int t;
long double p;
};
target make(int x, int y, long long int t, long double p) {
target tg;
tg.x = x;
tg.y = y;
tg.t = t;
tg.p = p;
return tg;
}
int dist2(target a, target b) {
return (a.x - b.x) * (a.x - b.x... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 5;
int prime[maxn];
bool vis[maxn];
int sieve(int n) {
int m = sqrt(n + 0.5);
for (int i = 2; i <= m; i++)
if (!vis[i]) {
for (int j = i * i; j <= n; j += i) vis[j] = true;
}
int c = 0;
for (int i = 2; i <= n; i++)
if (!vis[i... | 1 |
#include<iostream>
using namespace std;
int main()
{
long long int sum,a,b,c,k;
cin>>a>>b>>c>>k;
if(k<=a) sum=k;
else
{
if(k-a<=b) sum=a;
else sum=2*a-k+b;
}
cout<<sum;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
long long a[60], b[60];
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 0; i < n; ++i) scanf("%lld", &a[i]);
for (int i = 0; i < m; ++i) scanf("%lld", &b[i]);
long long _max = -1000000000000000001, max_ = -1000000000000000001, maxi = 0;
for (int i = 0... | 1 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int f = 1, res = 0, ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') res = res * 10 + ch - 48, ch = getchar();
return f * res;
}
int _sta[1 << 8];
inline void write(i... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, cnt = 0;
cin >> n;
vector<long long> v(n);
unordered_map<long long, long long> m;
for (int i = 0; i < n; i++) {
cin >> v[i];
m[v[i]]++;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j <= 30; j++) {
if (m[pow(2, j) ... | 3 |
#include <bits/stdc++.h>
using namespace std;
void SieveOfEratosthenes(long long int n);
long long int fastpowMOD(long long int a, long long int p, long long int MOD);
const int LIM = 1e5 + 5, MOD = 1e9 + 7;
long long int fastpowMOD(long long int a, long long int p, long long int MOD) {
if (p == 0) return 1;
a %= M... | 4 |
#include <bits/stdc++.h>
const int inf = 0x3f3f3f3f;
using namespace std;
int h, t, R, n, m;
pair<int, int> a[210], b[210];
int dis[210][210], vis[210][210];
bool sk[210][210];
int dfs(int x, int y) {
if (x + y > R) return 0;
if (vis[x][y] && sk[x][y])
return 1;
else if (vis[x][y])
return 0;
vis[x][y] =... | 5 |
/*
* b.cc:
*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functi... | 0 |
#include <bits/stdc++.h>
using namespace std;
char _;
vector<long long> dfs(int cur, vector<vector<int> > &adj, int n,
vector<long long> &people) {
vector<long long> res = {0, 0, 0};
if (adj[cur].size() == 0) return {people[cur], 0, 1};
vector<pair<long long, long long> > nodes;
long long ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
int n, m, i, num = 0, mx = INT_MIN;
cin >> n >> m;
int a[n];
for (i = 0; i < n; i++) {
cin >> num;
if (num % m != 0)
a[i] = num / m + 1;
else
a[i] = num / m;
}
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int inf = 1e6;
const int N = 1e5 + 5;
int n;
long long T, sumT[N];
long long x[N], t[N], s[40 * N], total[40 * N];
struct Edge {
int num;
int next;
long long c;
} edge[2 * N];
int tot, last[N];
long long val[N];
long long dp[N], f[N];
void Add(int i, int j) {
tot++;... | 6 |
#include<bits/stdc++.h>
using namespace std;
struct Dice{
array<int,6> face;
Dice(){
fill(face.begin(),face.end(),0);
}
};
bool isValid(Dice x){
bool res=true;
int cnt=0;
for(int i=0;i<6;i++){
if(x.face[i]==1){
if(i%3!=0) cnt++;
if(i>=3) res=!res;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int t;
int A[3];
int main() {
scanf("%d", &t);
int ans = 0, n;
long long a;
while (t--) {
A[0] = A[1] = A[2] = 0;
ans = 0;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%I64d", &a);
A[a % 3]++;
}
ans += A[0];
int x = m... | 2 |
#include <bits/stdc++.h>
using namespace std;
int thien, n, tt, h;
string s;
int main() {
cin >> tt;
for (int ii = 1; ii <= tt; ii++) {
cin >> n;
thien = 0;
h = 0;
for (int i = 1; i <= n; i++) {
cin >> s;
if (s.length() % 2 != 0) thien++;
for (int j = 0; j < s.length(); j++)
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 5;
const long long lim = (long long)3e16;
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
const long long oo = 1e18 + 5;
int t;
void solve() {
long long n;
int m;
cin >> n >> m;
long long sum = 0;
vector<int> bits(100);
for (int i = 0; i < ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int r[10], iiiii, i, a, ii;
bool sukses = false;
int main() {
while (iiiii < 6) {
cin >> a;
r[a]++;
iiiii++;
}
for (i = 1; i <= 9; i++) {
if (r[i] >= 4) {
for (ii = 1; ii <= 9; ii++) {
if (r[ii] == 2 || r[ii] == 6) {
cout << "El... | 1 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+50;
int a[N];
int main(){
int T;cin>>T;
while(T--){
string s;cin>>s;
int ans=0;
for(int i=0;s[i];i++){
if(s[i]=='*') continue;
if(i+2<s.size() && s[i]==s[i+2]){
++an... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int N,a,b;
long K,sum=0;
cin>>N>>K;
map<int,long> A;
for(int i=0;i<N;i++){
cin>>a>>b;
A[a]+=b;
}
for(auto itr=A.begin();itr!=A.end();itr++){
sum+=itr->second;
if(sum>=K){
cout<<itr->first<<endl;
break;
}
}
} | 0 |
#include<cstdio>
int main(){
double t;
scanf("%lf", &t);
double max = t, min = t;
while(~scanf("%lf", &t)){
if(max < t){
max = t;
}
if(min > t){
min = t;
}
}
printf("%lf", max - min);
} | 0 |
#include <bits/stdc++.h>
using namespace std;
struct gt {
int g, m, sl;
gt(int _g = 0, int _m = 0, int _sl = 0) {
g = _g;
m = _m;
sl = _sl;
}
};
const int N = 100005;
gt it[4 * N];
int a[N];
int n;
int gcd(int a, int b) {
while (a) {
int r = b % a;
b = a;
a = r;
}
return b;
}
void bu... | 6 |
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <iostream>
#include <vector>
#include <map>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
struct Node;
struct Fun;
int h, w, cr, cc;
char scr[512][512];
Node *lnk[512][512];
Fun *evt[512][512];
map<string, vector<pair<stri... | 0 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#pragma GCC optimize("unroll-loops")
using namespace std;
using ll = long long;
using ld = long double;
using db = double;
using str = string;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pd = ... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 3e5 + 5;
struct node {
int v;
long long w;
};
vector<node> edge[maxn];
long long dis[maxn];
long long mx_dis[maxn];
long long sz[maxn];
int vis[maxn];
long long ans = 0;
int n, m;
long long tmp = -1;
long long sta_cnt = 0;
long long end_cnt = 0;
l... | 6 |
#include <bits/stdc++.h>
long long xp[2200];
long long yp[2200];
int used[2200];
char str[2200];
long long cross(long long x1, long long y1, long long x2, long long y2) {
return (x1 * y2) - (x2 * y1);
};
int main(void) {
int start = -1;
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%lld %ll... | 6 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n, m;
scanf("%d %d", &n, &m);
int g[n + 1][m + 1], r[n + 1], c[m + 1];
memset(g, 0, sizeof g);
memset(r, 0, sizeof r);
memset(c, 0, sizeof c);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
char x;
cin >> x;
... | 2 |
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int N=1e4;
int n,m,ans;
vector <pair <int, pair <int, int> > > g;
vector <pair <int, int> > MST;
int parent [N];
int root (int a){
if(parent[a] ==a)
return a;
parent[a]=root(parent[a]);
return root(parent[a]);
... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void _R(T &x) {
cin >> x;
}
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template <class ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[200500], b[400500];
int t[800500];
void update(int x, int delta, int l = 1, int r = n, int i = 1) {
if (r < l) return;
if (l == r) {
t[i] += delta;
return;
}
int m = (l + r) / 2;
if (x <= m)
update(x, delta, l, m, i * 2);
else
upd... | 5 |
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)
int main(){
int x;
cin>>x;
cout<<"ai1333"<<string(x/100,'3')<<endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int f(vector<int> a, vector<int> b) {
vector<int> x[2], y[2];
for(int i = 0; i < a.size(); ++i) x[a[i]].push_back(i);
for(int i = 0; i < b.size(); ++i) y[b[i]].push_back(i);
if(x[0].size() != y[0].size() || x[1].size() != y[1].size()) return INT_MAX;
int ret = 0;
for... | 0 |
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void out(T x) {
cout << x << endl;
exit(0);
}
const long long mod = 1e9 + 7;
const int maxn = 1e6 + 5;
int n, m;
vector<int> g[maxn];
bool ok[maxn];
int subtree[maxn];
void dfs(int at, int p) {
subtree[at] = ok[at];
for (int to : g[at]) {
i... | 4 |
#include <bits/stdc++.h>
using namespace std;
int t, a, b, c, ans;
int main() {
cin >> t;
for (int i = 1; i <= t; i++) {
cin >> a >> b >> c;
ans = 0;
if (b < c) swap(b, c);
if (a - 1 >= 0) {
ans++;
a--;
}
if (b - 1 >= 0) {
ans++;
b--;
}
if (c - 1 >= 0) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
vector<int> p[3];
long long int calc(long long int x, long long int y, long long int z) {
return (x - y) * (x - y) + (x - z) * (x - z) + (y - z) * (y - z);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
long long int t, r, g, b, x;
cin >> t;
while (t--)... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long n, k;
const long long mod = 1e9 + 7;
long long p[9], used[9];
vector<long long> r[9];
long long tt = 0;
bool check() {
for (long long i = 1; i <= k; i++) r[i].clear();
for (long long i = 1; i <= k; i++) r[p[i]].push_back(i);
for (long long i = 1; i <= k; i++... | 2 |
#include <bits/stdc++.h>
using namespace std;
int const MAXN = 2e5 + 10;
int topo;
char S[MAXN], P[MAXN];
int main() {
scanf(" %s", P);
for (int i = 0; P[i] != '\0'; i++) {
S[topo + 1] = P[i];
topo++;
if (topo != 1) {
if (S[topo] == S[topo - 1]) topo -= 2;
}
}
for (int i = 1; i <= topo; i+... | 1 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void Int(T &n) {
n = 0;
int f = 1;
register int ch = getchar();
for (; !isdigit(ch); ch = getchar())
if (ch == '-') f = -1;
for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';
n = n * f;
}
template <typename T... | 5 |
#include <bits/stdc++.h>
using namespace std;
static const int N = 100;
char s[N + 1];
bool funk(int pos, int val) {
for (int i = 0; i < 5; i++) {
if (s[pos] == '.') return 0;
pos += val;
}
return 1;
}
int main() {
int n;
scanf("%i", &n);
scanf("%s", &s);
for (int i = 1; 4 * i <= n; i++) {
for... | 1 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > G[100010];
long long qp(long long a, long long p, long long m) {
long long ans = 1;
for (; p; p >>= 1, a = a * a % m)
if (p & 1) ans = ans * a % m;
return ans;
}
long long x, mod, k;
long long pw[100010], ipw[100010];
long long v[100010];
v... | 5 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<long long> > g;
vector<long long> dist, _sz;
void dfs1(long long v, long long p = -1) {
_sz[v] = 1;
for (long long i = 0; i < g[v].size(); i++) {
long long to = g[v][i];
if (to != p) {
dfs1(to, v);
_sz[v] += _sz[to];
}
}
}
long lo... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void maxtt(T& t1, T t2) {
t1 = max(t1, t2);
}
template <typename T>
void mintt(T& t1, T t2) {
t1 = min(t1, t2);
}
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "URDL";
long long ln, lk, lm;
void etp(b... | 4 |
#include <bits/stdc++.h>
using namespace std;
static const int INF = 0x3f3f3f3f;
static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
template <typename T>
T mulmod(T a, T b, T m) {
long long int q =
(long long int)(((long double)a * (long double)b) / (long double)m);
long long int r = a * b - q * m;
if (r >... | 5 |
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define MOD 1000000007
#define rep(i,n)for(int i=0;i<n; i++)
typedef long long ll;
using namespace std;
int main(){
ll mod = 1000000007;
int n, m;
cin >> n >> m;
ll a=0, b=0;
// x axis
rep(i,n){
ll x;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long a[210000];
int main() {
int N, i, j, k;
long long K, cur, tmp;
scanf("%d%I64d", &N, &K);
for (i = 0; i < N; i++) scanf("%I64d", &a[i]);
cur = 0;
for (i = j = k = 0; i < N; i++) {
tmp = cur - a[i] * j * (N - i - 1);
if (tmp < K) {
printf("... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 10000001;
vector<int> v;
int temp;
int main() {
string str;
cin >> str;
for (int i = 0; i < (int)str.size(); ++i) {
if (str[i] == '+' || str[i] == '=') {
v.push_back(temp);
temp = 0;
} else
++temp;
}
v.push_back(temp);
if ... | 1 |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("test.in");
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
vo... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int p = 1000000007;
int n, m, k;
int dp[1005][1005];
int main() {
cin >> n >> m >> k;
for (int i = 0; i < 1005; i++) dp[0][i] = 1;
for (int i = 1; i < 1005; i++) {
int sum = 0;
int sum2 = 0;
for (int j = 2; j < 1005; j++) {
sum = (sum + dp[i - ... | 5 |
#include<bits/stdc++.h>
#define ll long long int
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
int main()
{
fast;
ll n;
cin>>n;
ll p[n],x,ans=0;
for(ll i=0;i<n;i++)
{
cin>>x;
x--;
p[x]=i;
}
multiset<ll> s;
s.inser... | 0 |
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
struct st {
char a;
int b, c;
};
int main() {
int n;
while (cin >> n, n) {
vector<st>v;
rep(i, n) {
char t; int a = 0, b = 0;
cin >> t;
rep(j, n - 1) {
int r; cin >> r;
if (!r)a++;
if (r... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
if (n > 1)
printf("%d %d", 3 * n, 2 * n);
else
printf("9 8");
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
int main(){
int v, e; cin >> v >> e;
Graph G(v);
vector<int> indegree(v);
for(int i = 0; i < e; i++){
int a, b; cin >> a >> b;
G[a].push_back(b);
indegree[b]++;
}
queue<int> que;
for(int... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
const long long sz = 2e6 + 5;
vector<long long> fac, ifac;
vector<int> prime;
long long mpow(long long a, long long b = mod - 2, long long m = mod) {
long long res = 1;
a %= m;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1) res ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int r, g, b;
scanf("%lld %lld %lld", &r, &g, &b);
if (r > 2 * (g + b))
r = (2 * (g + b));
else if (g > (2 * (r + b)))
g = (2 * (r + b));
else if (b > (2 * (g + r)))
b = (2 * (g + r));
cout << (r + g + b) / 3;
return 0;
}
| 3 |
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;
// ref... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int n, m, k;
struct node {
int t, a, b;
} a[maxn];
int main() {
int _;
scanf("%d", &_);
while (_--) {
scanf("%d", &n);
if (n % 2 == 1) {
printf("%d\n", n / 2 + 1);
} else {
printf("%d\n", n / 2);
}
}
return ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
const long long LLINF = 9223372036854775807LL;
const int ST = 100010;
const int ST1 = 1000010;
const long long MOD = 1000000007;
long long ABS(long long a) {
if (a < 0)
return a * (-1);
else
return a;
}
int main() {
long long n, m, ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main()
{
int N, M;
vector<int> A, B, Ans;
cin >> N;
A.resize(N);
for(int i = 0; i < N; ++i)
cin >> A[i];
cin >> M;
B.resize(M);
for(int i = 0; i < M; ++i)
cin >> B[i];
set_intersection(A.begin... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long int power(long long int x, long long int n) {
long long int res = 1;
while (n > 0) {
if (n % 2 == 1) {
res = res * x;
}
x = x * x;
n = n / 2;
}
return res;
}
long long int powm(long long int a, long long int b) {
long long int res =... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int Max_N = 9 + (int)5e5;
pair<int, int> c[Max_N], b[Max_N];
int K[Max_N], res[Max_N];
set<int> st, Q;
map<int, int> has;
vector<pair<int, int> > que[Max_N], sing[Max_N];
vector<int> use[Max_N];
int main() {
int n, m;
scanf("%d", &n);
for (int i = 0, u, v; i < n... | 3 |
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
int h;
int n;
cin>>n;
for(h=0;h<n;h++){
int x=0,y=0;
pair<int,pair<int,int> > a;
a=make_pair(0,make_pair(0,0));
int p,q;
while(cin>>p>>q&&p+q){
x... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
int n;
int x[N], y[N], cnty[N], cntx[N];
int last[N];
int ans;
int type[100005];
int m1[100005], m2[100005];
void updatex(int i) {
type[ans] = 1;
m1[ans] = i + 2;
m2[ans] = x[i];
for (int i = 0; i < n - 1; i++) {
if (x[i] == m1[ans])
x[... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1e6 + 69, MOD = 1e9 + 7;
long long t;
vector<long long> vect[2];
void solve() {
long long n, col, ip, ans = 0;
cin >> n;
for (long long it = 0; it < ceil(log2(n)); it++) {
col = 0;
vect[0].clear(), vect[1].clear();
for (long long i =... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, a, max, x;
cin >> n;
vector<int> v;
long long temp;
max = 1;
while (n-- > 0) {
cin >> temp;
v.push_back(temp);
}
for (auto x : v) {
a = count(v.begin(), v.end(), x);
if (a > max) {
max = a;
}
}
cout << ... | 1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.