solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
const int N = 1000 + 10;
struct tnode {
int x, y;
long long val;
tnode() {}
tnode(int _x, int _y, long long _val) {
x = _x;
y = _y;
val = _val;
}
};
int n, m, r, c;
int a[N][N], b[N][N], f[N][N];
long long sum[N][N];
int Q[N], head, tail;
std::vector<tnode> ans, out;
bool ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int ta[1000], ya[1000], t[1000], n, m, k, a[1000][1000];
int main() {
cin >> n >> m >> k;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> a[i][j];
}
}
for (int j = 1; j <= m; j++) {
for (int i = 0; i <= k; i++) {
t[i] = 0... | 2 |
#include <bits/stdc++.h>
void answer(unsigned x, unsigned y) {
std::cout << x << '\n';
std::cout << y << '\n';
}
void solve(std::string& a, std::string& b) {
const size_t n = a.length();
std::sort(a.begin(), a.end());
std::sort(b.begin(), b.end());
unsigned x = 0;
for (size_t i = 0, j = 0; i < n; ++i, ++j... | 2 |
#include <iostream>
#include <algorithm>
using namespace std;
int x,y,i;
int main(){
while(cin>>x>>y&&x+y){
if(y>x)swap(x,y);
i=0;
for(;y;i++){
x%=y;
swap(x,y);
}
cout<<x<<" "<<i<<endl;
}
} | 0 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void PVecPrint(vector<T> &v) {
for (int i = 0; i < (int)v.size(); i++)
cout << v[i].first << "," << v[i].second << ' ';
cout << '\n';
}
template <class T>
void VecPrint(vector<T> &v) {
for (int i = 0; i < v.size(); i++) cout << v[i] << ' ';
co... | 3 |
#include <bits/stdc++.h>
const int N = 310;
const long long inf = 0x3f3f3f3f;
using namespace std;
const long long mod = (long long)1e9 + 7;
int num[N][N];
int main() {
int t;
scanf("%d", &t);
;
while (t--) {
int n, m;
scanf("%d", &n);
;
scanf("%d", &m);
;
int flag = 0;
for (int i = ... | 2 |
#include <bits/stdc++.h>
using namespace std;
;
const long long maxn = 1e5 + 7;
const long double pi = 3.14159265358979323846;
struct pirog {
long long r;
long long h;
long long i;
};
long long V[4 * maxn];
pirog A[maxn];
vector<pirog> C;
void update(long long v, long long tl, long long tr, long long i,
... | 4 |
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int d[4];
string in;
int data[10000];
void solve(){
bool f = true;
for(int i=1;i<4;i++) if(in[0] != in[i]) f = false;
if(f) cout << "NA" << endl;
else{
int ans = 0;
for(int i=0;i<4;i++) d[i] = in[i] - '0';
while(1){
... | 0 |
#include <iostream>
#include <string>
using namespace std;
int number(string s) {
int n=0,a=1;
for(int i=0; i<s.size(); i++) {
if(s[i]>='0' && s[i]<='9') {
a=(int)s[i]-48;
continue;
}
if(s[i]=='m') n+=a*1000;
else if(s[i]=='c') n+=a*100;
else if(s[i]=='x') n+=a*10;
else n+=a;
... | 0 |
#include <iostream>
using namespace std;
int a, b;
int main() {
cin>>a>>b;
if(a==b) cout<<2*a;
else cout<<2*max(a,b) - 1;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int t;
int main() {
scanf("%d", &t);
while (t--) {
int n, k;
int x[1000] = {0};
int tap[1000];
scanf("%d%d", &n, &k);
for (int i = 1; i <= k; i++) {
scanf("%d", &tap[i]);
x[tap[i]]++;
}
if (n == k) {
printf("1\n");
con... | 1 |
#include <bits/stdc++.h>
long long gi() {
long long x = 0, f = 1;
char ch = getchar();
while (!isdigit(ch)) f ^= ch == '-', ch = getchar();
while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
return f ? x : -x;
}
struct node {
int x, y;
};
int n, D;
long long m;
bool operator<(const node& a, const no... | 6 |
#include<bits/stdc++.h>
using namespace std;
int fa[100005],k[100005];
int f(int u)
{
if(u==fa[u])
return u;
else
{
int t=f(fa[u]);
k[u]+=k[fa[u]];
return fa[u]=t;
}
}
int main()
{
int i,l,r,d,p,q,n,m;
cin>>n>>m;
for(i=1;i<=n;i++)
{
fa[i]=i;
k[i]=0;
}
for(i=1;i<=m;i++)
{
cin>>l>>r>>d;
if(f(l... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
int n, t, a[2010], to[2010], dp[2010][2010][2], num[2010][2010][2],
tot = 1e9, Nxt[2010], Lst[2010];
pair<pair<short, short>, pair<short, short> > lst[2010][2010][2];
vector<int> vv, v[2010], ans;
map<int, int> mp;
vector<pair<pair<int, in... | 6 |
#include <bits/stdc++.h>
using namespace std;
int counter[1005][5];
int main() {
int n, m;
scanf("%d %d", &n, &m);
while (n--) {
char tmp;
for (int i = 0; i < m; i++) {
scanf(" %c", &tmp);
counter[i][tmp - 'A'] += 1;
}
}
int tpoints = 0, mpoints = 0;
for (int i = 0; i < m; i++) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
long long n, m;
cin >> n >> m;
while ((n * (n + 1) / 2) <= m) m -= n * (n + 1) / 2;
for (long long i = 1; i <= n; i++) {
if (m >= i)
m -= i;
else
break;
}
cout << m;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long int p, k;
long long fastpow(long long x, long long y) {
if (y == 1) return x;
if (y == 0) {
return 1;
}
long long a = fastpow(x, y / 2);
a %= (long long)1000000007;
if (y % 2 == 0) {
return ((a * a) % 1000000007);
} else {
return ((((a * ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
while (scanf("%d%d", &n, &m) >= 1) {
vector<int> tys(n);
for (int i = 0; i < n; i++) scanf("%d", &tys[i]);
vector<vector<int> > es(n), rves(n);
for (int i = 0; i < m; i++) {
int a, b;
scanf("%d%d", &a, &b), a--, b--;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 205;
int c[MAX];
bool adj[MAX][MAX];
int deg[MAX];
int tmp[MAX];
int N;
bool mark[MAX];
int solve(int s) {
memset(mark, 0, sizeof mark);
memcpy(tmp, deg, sizeof deg);
int ret = 0;
int n = 0;
for (int i = s; n < N; i = (i + 1) % 3) {
bool enter;... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t;
cin >> t;
for (int i = 0; i < t; ++i) {
int n, r, y;
cin >> n >> r;
for (int i = 0; i + 1 < n; ++i) {
cin >> y;
r += (n - y);
}
r %= n;
... | 1 |
#include <bits/stdc++.h>
char b[3][32], c[12];
int i, j, n;
int main() {
gets(c + 1);
n = strlen(c + 1);
for (i = 1; i <= n; i++) switch (c[i] - 48) {
case 1:
b[1][2 * i - 1] = 1, b[1][2 * i] = 0, b[2][2 * i - 1] = 0,
b[2][2 * i] = 0;
break;
case 2:
b[1][2 ... | 4 |
#include<cstdio>
int main(){
int n;
scanf("%d",&n);
if(n==3){
puts("2 5 63");
return 0;
}
int a=n%3?n-2:n-4;
if(a>15000) a=n%2?14999:15000;
for(int i=1;i<=a;i++) printf("%d ",i*2);
for(int i=0;i<n-a;i++) printf("%d ",i*6+3);
} | 0 |
#include "bits/stdc++.h"
using namespace std;
const long long INF = 1e18;
using ll = long long;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define chmin(x,y) x = min(x,y);
long long dp[20][20];
using P = pair<int,int>;
vector<ll> calc(vector<P>& a) {
int n = a.size();
sort(a.begin(), a.end());
rep(i, n + 1)rep(... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int N = 1e6 + 5;
int read() {
int s = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
s = s * 10 + c - '0';
c = getchar();
}
retu... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, h, a, b, k;
cin >> n >> h >> a >> b >> k;
for (int i = 0; i < (int)(k); i++) {
int ta, fa, tb, fb;
cin >> ta >> fa >> tb >> fb;
if (ta == tb) {
cout << abs(fa - fb) << endl;
} else if (... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int T = 2 * 1e5 + 10, N = 1010, mod = 1e9 + 7, K = 50;
int dp[N][N][K], c[N][N];
long long fact[N];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
c[0][0] = 1;
for (int i = 1; i < N; i++) {
c[0][i] = 1;
c[i][i] = 1;
for (int ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n;
long long cnt, g;
double w[200005], rt, r, l[200005], t[200005], tt, mt;
bool ok = true;
queue<double> mq;
int main() {
scanf("%d%lf", &n, &r);
for (int i = 0; i < n; i++) scanf("%lf", &l[i]);
for (int i = 0; i < n; i++) {
scanf("%lf", &t[i]);
if (t[i] ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int n, k, arr[5005], sm = 0, ans = -1;
cin >> n >> k;
for(int i = 0; i < n; i++){
cin >> arr[i];
}
sort(arr, arr + n, greater<int> ());
for(int i = 0; i < n; i++){
sm = 0;
for(int j = i; j < n; j++){
if(sm + arr[j] < k){
sm += arr[j];
c... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long mx = 0, mn = 1e9 + 7;
bool bysec(const pair<long long, long long> &a,
const pair<long long, long long> &b) {
return a.second < b.second;
}
string inst(string s) {
char ch[100000];
scanf("%s", ch);
s = ch;
return s;
}
void pfst(string s) {
lo... | 1 |
#include <bits/stdc++.h>
using namespace std;
void solutionA();
int main() {
ios_base::sync_with_stdio(false);
solutionA();
return EXIT_SUCCESS;
}
long long lca(long long a, long long b) {
map<long long, long long> used;
while (a != 0) {
used[a] = 1;
a >>= 1;
}
while (!used[b] && b != 0) b >>= 1;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main(){
long long k,t;
cin >> k >> t;
long long total=0;
long long a[t];
for(int i=0;i<t;i++){
cin >> a[i];
total+=a[i];
}
sort(a,a+t);
total-=a[t-1];
cout << max(0LL,a[t-1]-total-1) << endl;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int mx = 1001, n;
int vis[1001];
int dp[1001][1001];
vector<int> v;
long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }
void solve(int ind, int lc) {
if (ind > n || lc > n) retu... | 1 |
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v)... | 0 |
#include <bits/stdc++.h>
using namespace std;
vector<int> used;
vector<vector<int>> a;
int sum = 0;
void DFS(int b, int k) {
for (int i = 0; i < a[b].size(); i++) {
if (used[a[b][i]] == 0 && k == 1) {
sum++;
}
if (k == 0) {
DFS(a[b][i], k + 1);
}
}
}
int main() {
int n;
cin >> n;
a... | 6 |
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<list>
#include<string>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<ctime>
using namespace std;
typedef long long ll;
const int NIL = -1;
const int MAX = 2147483647;
const int NUM = 100000... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)3e6;
const int N = 4194304;
int n, w;
pair<pair<int, int>, int> a[maxn];
pair<int, int> b[maxn];
int co[maxn];
int bn;
struct sta {
int T[N * 2 + 1];
long long sum[N * 2 + 1];
int an;
int a[N * 2];
sta() { an = 0; }
void init() {
memset... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int node[300100 << 2];
int q[300100];
void update(int L, int R, int val, int l, int r, int rt) {
if (L > R) return;
if (L <= l && r <= R) {
node[rt] = val;
return;
}
if (node[rt] != 0) {
node[(rt << 1)] = node[(rt << 1 | 1)] = node[rt];
nod... | 1 |
#include <bits/stdc++.h>
using namespace std;
long a[200005];
long n;
long mid;
long x, top, bottom;
int main() {
scanf("%d", &n);
scanf("%d", &mid);
a[100001] = 1;
top = 100001;
bottom = 100001;
for (int i = 2; i <= n; i++) {
scanf("%d", &x);
if (abs(x - mid) >= 100001 - 1) {
printf("NO\n");
... | 4 |
#include <bits/stdc++.h>
using namespace std;
char s[30];
int p[30];
int a, b;
int main() {
scanf("%s", s);
for (int i = 0; i < 27; i++) {
if (p[s[i] - 'A']) {
a = p[s[i] - 'A'];
b = i + 1;
break;
}
p[s[i] - 'A'] = i + 1;
}
if (a + 1 == b) {
printf("Impossible\n");
return 0... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
scanf("%lld", &n);
;
vector<long long> vc;
for (long long i = 0; i < n; i++) {
long long x;
scanf("%lld", &x);
vc.push_back(x);
}
sort(vc.begin(), vc.end());
long long g = vc[0];
for (long long i = 0; i < n; i++) {
... | 3 |
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pl;
const double EPS = 1e-9;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
int... | 0 |
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, i, tree[2097160], j, x = 0, k, b[100009], kol[100009], z = 1;
struct Pair {
int i;
int j;
};
Pair a[100009];
bool cmp1(Pair p1, Pair p2) { return p1.i < p2.i; }
bool cmp2(Pair p1, Pair p2) { return p1.j < p2.j; }
int main() {
scanf("%d%d\n", &n, &k);
for (i =... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int T;
cin >> T;
while (T--) {
int n;
cin >> n;
vector<vector<long long int>> arr(n + 1, vector<long long int>(2, 0));
for (int i = 1; i <= n; i++) cin >> arr[i][0];
for (int i = 1; i <= n; i++) cin >> arr[i][1];
sort(arr.begin(), ... | 3 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long int k;
cin >> k;
string s;
cin >> s;
char c;
long long int flag = 0;
vector<char> v;
for (long long int i = 0; i < k; i++) {
if (s[i] != '2' && s[i] != '3' && s[i] != '5' && s[i] != '7') {
c = s[i];
flag = 1;
br... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long int fact[100100 * 10];
vector<long long int> v[100100 * 10];
void facto(long long int m) {
fact[0] = 1;
for (long long int i = 1; i <= m; i++) {
fact[i] = (fact[i - 1] * i) % 1000000007;
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
long lo... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main(){
string s, t;
cin >> s >> t;
int n1 = s.size(), n2 = t.size();
int ans = 100000;
for(int i=0; i<=n1-n2; ++i){
int cnt = 0;
for(int j=0; j<n2; ++j){
if(s[i+j] != t[j]) ++cnt;
}
ans = min(ans, cnt);
}
cout << ans << endl;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
inline int add(int a, int b) {
a += b;
if (a >= 1000000007) a -= 1000000007;
return a;
}
inline int sub(int a, int b) {
a -= b;
if (a < 0) a += 1000000007;
return a;
}
inline int mul(int a, int b) { return (a * 1ll * b) % 1000000007; }
inline int power(int a, in... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char a[1233455];
cin >> a;
long long int i, n, j = 1, k;
for (n = 0; a[n] != '\0'; n++)
;
k = 0;
for (i = 0; i < n; i++) {
if (a[i] == 'a')
k++;
else if (a[i] == 'b') {
j = (j * (k + 1)) % 1000000007;
k = 0;
}
}
... | 3 |
#include <bits/stdc++.h>
using namespace std;
double a;
int main(){
cin >> a;
printf("%.10lf",a*a*a/27);
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 3e5 + 5;
long long n, m, k, t, a[N], l, r, mid, sum;
inline long long read() {
char ch;
long long f = 1;
while (!isdigit(ch = getchar()))
if (ch == '-') f = -1;
long long x = ch - '0';
while (isdigit(ch = getchar())) x = x * 10 + ch - '0';
... | 1 |
#include<iostream>
using namespace std;int a,b,c;int main() {return cout<<((cin>>a>>b>>c&&b-a==c-b)?"YES":"NO")<<endl,0;} | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, m, c, c_, refc[10];
char mp[25][25];
int p[25][25];
int val[10], px[10], py[10], sx, sy;
int dx[5] = {0, 1, 0, -1, 0}, dy[5] = {0, 0, -1, 0, 1};
int dp[25][25][1 << 8], sum[1 << 8], ans;
struct state {
int x, y, st;
};
int cross(int a, int b, int c, int d, int k) {... | 3 |
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
std::pair<T, U> operator+(const std::pair<T, U>& l, const std::pair<T, U>& r) {
return {l.first + r.first, l.second + r.second};
}
typedef void (*callback_function)(void);
const long long INF64 = 1e18;
const long long INF32 = 1e9;
int mai... | 3 |
#include <bits/stdc++.h>
using namespace std;
int mp[100005][3] = {0};
int main() {
string s;
cin >> s;
int n = s.size();
for (int i = 1; i <= n; i++) {
mp[i][s[i - 1] - 'x']++;
for (int j = 0; j < 3; j++) {
mp[i][j] += mp[i - 1][j];
}
}
int q;
cin >> q;
while (q--) {
int l, r;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, k, mini, a, b, i;
cin >> n >> k;
mini = k;
for (i = 0; i < n; i++) {
cin >> a >> b;
if (a + b > mini) {
mini = a + b;
}
}
cout << mini;
return 0;
}
| 1 |
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <tuple>
#ifdef _MSC_VER
#include <agents... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
if (n % 4 == 0) {
for (int i = 0; i < n / 4; i++) cout << "abcd";
return 0;
} else if (n % 4 == 1) {
for (int i = 0; i < n / 4; i++) cout << "abcd";
cout << "a";
return 0;
} else if (n % 4 == 2) {
for (int i = ... | 2 |
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:225450978")
#pragma GCC optimize("Ofast")
using namespace std;
const long long Mod = 1000000007LL, INF = 1e9, LINF = 1e18;
const long double Pi = 3.141592653589793116, EPS = 1e-9,
Gold = ((1 + sqrt(5)) / 2);
long long keymod[] = {1000000007LL, 1... | 2 |
#include <bits/stdc++.h>
using namespace std;
double Fib(double x, double z);
string BinDec(unsigned long long x);
string StringInt(long long x);
unsigned long long StringInt(string x);
unsigned long long BinDec(string x);
unsigned long long POWMOD(unsigned long long x, unsigned long long y,
u... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1000000007ll;
long long int c[4151][4151], dp0[4151], dp1[4151];
int n;
int sol(int uuu) {
printf("%I64d\n", dp1[n]);
return 1;
}
int main() {
for (int i = 0; i < (4151); i++) {
c[i][0] = c[i][i] = 1;
for (int j = 0; j < (i); j++)
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int N, K;
int x, y, z;
int solve(int l, int r) {
if (l == r) {
return l;
}
int mid = (l + r) / 2;
cout << 1 << ' ' << mid << ' ' << mid + 1 << endl;
string res;
cin >> res;
if (res[0] == 'N') {
return solve(mid + 1, r);
} else {
return solve(l, m... | 2 |
#include <bits/stdc++.h>
using namespace std;
string s;
int n, pre[505];
void Solve() {
for (int i = 0; i < n; i++) {
if (s[i] == '(') {
pre[i + 1] = pre[i] + 1;
} else {
pre[i + 1] = pre[i] - 1;
}
}
if (pre[n] != 0) {
printf("0\n1 1");
return;
}
memset(pre, 0, sizeof(pre));
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 4 * 1e5;
int n, numb, degIn[N], degOut[N], start[N];
vector<pair<int, int> > g[N];
vector<int> res;
string subs[N], s[N];
map<string, int> mp;
void addEdge(int u, int v) {
degOut[u]++;
degIn[v]++;
g[u].push_back(make_pair(v, 1));
}
bool checkEulerPath() ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> G[200005];
long long ans = 1;
long long fact[200005];
void dfs(int v, int p) {
int len = G[v].size();
ans = ans * fact[len] % 998244353LL;
for (int i = 0; i < G[v].size(); i++) {
if (G[v][i] == p) continue;
dfs(G[v][i], v);
}
}
int main(vo... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long c[200006];
vector<pair<long long, long long>> sum;
long long pre[200006];
long long a[200006];
vector<long long> ans;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
long long n;
cin >> n;
for (long long i = 1; i <= n / 2; i++) cin >... | 1 |
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-10;
int main() {
bool is_prime[1024];
fill(is_prime, is_prime + 1024, true);
is_prime[0] = is_prime[1] = false;
for (int i = 2; i < 1024; ++i) {
if (is_prime[i]) {
for (int j = i * 2; j < 1024; j += i) is_prime[j] = false;
}
}
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 100;
struct State {
int link, len;
long long cnt;
map<char, int> next;
State(int link, int len, long long cnt) : link(link), len(len), cnt(cnt) {}
State() : State(0, 0, 0) {}
};
State st[2 * N];
int size, last;
void Init() {
for (int _n(2 * N... | 6 |
#include <bits/stdc++.h>
using namespace std;
int prime[2000010], tp;
int isp[2000010];
int ai[2000010];
int n, m;
void prime_cal() {
tp = 0;
memset(isp, 0, sizeof(isp));
for (int i = 2; i < 2000010; ++i) {
if (!isp[i]) prime[tp++] = i;
for (int j = 0; j < tp && (long long)prime[j] * i < 2000010; ++j) {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
void init() {
cin.tie(0);
cin.sync_with_stdio(0);
}
int main() {
init();
int n, zeros = 0, ones = 1023, andd = 1023, orr = 0, xorr = 0;
cin >> n;
int commands[n][2];
for (int i = 0; i < n; i++) {
char c;
int x;
cin >> c >> x;
if (c == '^') {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
struct dot {
int value, i, j;
};
bool operator<(dot a, dot b) { return a.value < b.value; }
int main() {
int t;
scanf("%d", &t);
while (t--) {
int n, m;
scanf("%d %d", &n, &m);
int num[n][m];
priority_queue<dot> pq;
for (int i = 0; i < n; ++i) {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n = 1, len1, len2, ans;
int operation[N];
bool book[N];
char s1[N], s2[N];
vector<int> num;
bool check(int x) {
num.clear();
for (register int i = x + 1; i <= n; i++)
if (book[s1[operation[i]]]) num.push_back(operation[i]);
sort(num.begi... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
map<char, char> hash;
string s1, s2, s3;
long long int i, x;
cin >> s1;
cin >> s2;
for (i = 0; i < s1.length(); i++) hash[s1[i]] = s2[i];
cin >> s3;
x = s3.length();
char s4[x];
for (i = 0; i < x; i++) {
if (isupper(s3[i])) {
s4[i]... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long int mod = 1e9 + 7;
using namespace std::chrono;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int n;
cin >> n;
string s;
cin >> s;
long long int a[26];
for (int i = 0; i < 26; i++) cin >> a[i];
long long int maxx = -1, l... | 3 |
#include <iostream>
using namespace std;
int main() {
string s;
int K;
cin >> s >> K;
for (char& c : s) {
if (c == 'a') continue;
if ('z' - c + 1 <= K) {
K -= 'z' - c + 1;
c = 'a';
}
}
K %= 26;
while (K > 0) {
s.back() = (s.back() == 'z' ? 'a' : s.back() + 1);
K--;
}
cout << s << endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
pair<int, int> pi[500005];
int a, b, ans = 1, n, x;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a >> b;
pi[i] = make_pair(a, b);
}
sort(pi, pi + n);
x = pi[0].second;
for (int i = 1; i < n; i++) {
if (x < pi[i].first) {
ans+... | 2 |
#include <bits/stdc++.h>
using namespace std;
pair<int, int> tab[100010];
int n, m;
bool czy = false;
bool algo() {
vector<int> v;
for (int i = 1; i <= n; i++) {
v.push_back(i);
}
random_shuffle(v.begin(), v.end());
for (int i = 0; i < m; i++) {
if (tab[v[i]].first == v[(i + 1) % n]) return false;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int dp[4][20000];
int main() {
string s;
cin >> s;
int n = (int)s.size();
set<string> ans;
dp[2][n] = dp[3][n] = 1;
for (int i = n - 2; i >= 5; i--) {
if (dp[3][i + 2] ||
(dp[2][i + 2] && s.substr(i, 2) != s.substr(i + 2, 2))) {
dp[2][i] = 1;
... | 3 |
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
string a;
cin >> a;
int n = a.size();
set< pair<int, int> > st;
for(int i = 0; i < n; i++){
string s = a.substr(0, i);
string t = a.substr(i);
if(s.size() != 1 && s[0] == '0') continue;
if(t.size() != 1 && t[0] =... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m;
cin >> n >> m;
if (n > m) swap(n, m);
long long ans = 0;
if (n == 1)
ans = m / 6 * 6 + max(0ll, m % 6 - 3) * 2;
else if (n == 2) {
ans = n * m;
if (m == 2) ans = 0;
if (m == 3 || m == 7) ans -= 2;
} else
ans = n... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long cs = 100000;
int main() {
int n, j;
long long a[110];
long long i, k, res, d, maxd, qq;
cin >> n >> k;
for (i = 1; i <= n; i++) cin >> a[i];
maxd = 1;
qq = maxd;
for (i = 1; i <= cs; i++) {
d = i * 1000000;
res = 0;
for (j = 1; j <= n; ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin>>N;
int s=N%10;
if(s==3) cout<<"bon"<<endl;
else if(s==0||s==1||s==6||s==8) cout<<"pon"<<endl;
else cout<<"hon"<<endl;
}
| 0 |
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:64000000")
using namespace std;
template <typename first>
inline first abs(const first& a) {
return a < 0 ? -a : a;
}
template <typename first>
inline first sqr(const first& a) {
return a * a;
}
const long double PI = 3.1415926535897932384626433832795;
const ... | 2 |
#include <bits/stdc++.h>
using namespace std;
bool debug;
const int inf = 1e9 + 5;
const int nax = 6405;
namespace MinCost {
struct Edge {
int w, c, v, rev;
Edge(int _w, int _c, int _v, int _rev) : w(_w), c(_c), v(_v), rev(_rev) {}
};
int odl[nax], pot[nax], pop[nax], pop_kraw[nax];
int q[nax], qbeg, qend;
vector<E... | 3 |
#include <bits/stdc++.h>
using namespace std;
int a[20];
int main() {
int n;
int ans = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
ans = max(ans, a[i]);
}
cout << (ans ^ a[n - 1]) << endl;
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
string s[50];
int main() {
long long n, p;
cin >> n >> p;
for (int i = 0; i < n; i++) {
cin >> s[i];
}
long long res = 0;
for (int i = n - 1; i >= 0; i--) {
res = res * 2 + (s[i] == "halfplus");
}
double ans = 0;
while (res > 0) {
ans += res / ... | 1 |
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
using namespace std;
const long double eps = 1e-7;
const int inf = 1000000010;
const long long INF = 10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 1000010, LOG = 20;
long long n, m, k, u, v, x, y, t, a, b, ans;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n, k;
cin >> n >> k;
if (k > n) {
long long ans = k % 2 ? k / 2 : k / 2 - 1;
long long p = k - n;
ans = (ans - p + 1);
if (ans < 0) ans = 0;
cout << ans;
} else {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int d = (n % 10);
if (d <= 5)
d = n - (n % 10);
else
d = n + 10 - (n % 10);
cout << d;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(vector<T> &v) {
for (auto &a : v) cin >> a;
}
int main() {
ios_base::sync_with_stdio(false);
int n, m;
cin >> n >> m;
vector<int> v(m), u(101, 0);
read(v);
for (auto x : v) u[x]++;
for (int i = 1; i <= 100; i++) {
int flag... | 2 |
#include <bits/stdc++.h>
#include <queue>
using namespace std;
int main(){
int Q; cin >> Q;
long long int ans = 0;
priority_queue<long long> Small;
priority_queue<long long, vector<long long>, greater<long long>> Large;
for(int q = 0; q < Q; q++){
int r;
cin >> r;
if(q == 0){
long long int a, b;... | 0 |
#include <iostream>
#include <cstdio>
#include <queue>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define ALL(c) (c).begin(),(c).end()
int parent[17][100000],depth[100000];
vector<int> G[100000];
void dfs(int v,int p,int d){
parent[0][v]=p;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[200], c[200], last[200];
struct edge {
int to, nxt, f, c;
} e[(200 * 5)];
int edgenum = 0;
int lin[400];
void add(int a, int b, int f, int c) {
e[edgenum] = (edge){b, lin[a], f, c};
lin[a] = edgenum++;
e[edgenum] = (edge){a, lin[b], 0, -c};
lin[b] ... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int black[maxn];
vector<int> nex[maxn];
int dp[maxn];
void dfs1(int now, int fa) {
dp[now] = black[now] ? -1 : 1;
for (auto x : nex[now]) {
if (x == fa) continue;
dfs1(x, now);
if (dp[x] >= 0) dp[now] += dp[x];
}
}
int ans[maxn];
... | 6 |
#include <bits/stdc++.h>
using namespace std;
struct BSTNode {
string element;
int altura;
BSTNode *left;
BSTNode *right;
};
struct BST {
BSTNode *root;
int count;
};
BST *create_bst() {
BST *a = new BST();
a->root = NULL;
a->count = 0;
return a;
}
BSTNode *create_node(string a) {
BSTNode *c = new... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-6;
template <class T>
T gcd(T a, T b) {
if (!b) return a;
return gcd(b, a % b);
}
const int maxn = 2e5 + 10;
priority_queue<long long, vector<long long>, greater<long long>... | 4 |
#include<iostream>
#include<algorithm>
int main(){
int a, b, c, d, e;
std::cin >> a >> b >> c >> d >> e;
int pasta = std::min(a, std::min(b, c));
int juice = std::min(d, e);
std::cout << pasta + juice - 50 << std::endl;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
long long n, k;
cin >> n >> k;
if (k >= n / 2)
cout << n * (n - 1) / 2;
else
cout << n * (n - 1) / 2 - (n - 2 * k) * (n - 2 * k - 1) / 2;
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 10;
int a[MAX];
int main() {
int n;
cin >> n;
map<int, int> mp;
int ok = 1;
for (int i = 1; i <= n; i++) {
cin >> a[i];
mp[a[i]]++;
ok &= (mp[a[i]] < 3);
}
int cnt = 0;
for (auto it : mp) {
if (it.second >= 2) cnt++;
}... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long n, ans;
long long A[1000 * 1000 + 10];
long long t[1000 * 1000 + 10];
stack<long long> st;
int main() {
ios_base::sync_with_stdio(false);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> A[i];
t[i] = 1;
while (!st.empty() && A[i] > A[st.top()]) {
... | 2 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.