solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <cstdio>
using namespace std;
int main(){
double a,b,c,d,e,f;
double x,y;
while(scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f) != EOF){
y = (f - (d * c) / a) / ((d * -1 * b) / a + e);
x = (c - b * y) / a;
printf("%.3f %.3f\n",x,y);
}
return(0);
} | 0 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void printvec(vector<T>& x, int a, int b) {
for (int i = (a); i <= (b); i++) cout << x[i] << " ";
cout << "\n";
}
const double PI = acos((double)-1);
const double EPSILON = 1e-7;
const int N = 1e6 + 1;
const int NN = 1e3 + 1;
const long long MOD = 1e9... | 4 |
#include <bits/stdc++.h>
using namespace std;
int solve(int a, int b) {
if (a - b == 0) return printf("infinity\n");
if (a - b < 0 || b > a - b) return printf("0\n");
int i = 2, n = a - b, res = 1;
while (i < n && i * i <= (a - b) && n > 1) {
int rr = 0;
while (n % i == 0) {
rr++;
n /= i;
... | 2 |
#include <bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
using namespace std;
const int maxn = 1000 + 5;
const int mod = 998244353;
int dp[maxn][maxn], a[maxn], ans, n, k;
int main() {
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; i++) scanf("%d", a + i);
sort(a + 1,... | 6 |
#include <bits/stdc++.h>
using namespace std;
int64_t n, a, b, da, db, c, d;
vector<int> v[100005];
bool dis(int x, int p, int d) {
if (x == b) return d <= da;
bool ans = false;
for (auto i : v[x])
if (i != p) ans |= dis(i, x, d + 1);
return ans;
}
int maxDis(int x, int p) {
int d = 0;
for (auto i : v[x... | 2 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
const long long sz = 3e5 + 10;
pair<long long, long long> ara[sz], lim;
multiset<long long> lst;
int main() {
long long n;
cin >> n;
for (long long i = 1; i <= n; i++) {
if (i == 1) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
ostream cnull(NULL);
template <class TH>
void _dbg(const char *sdbg, TH h) {
cnull << sdbg << "=" << h << "\n";
}
template <class TH, class... TA>
void _dbg(const char *sdbg, TH h, TA... a) {
while (*sdbg != ',') cnull << *sdbg++;
cnull << "=" << h << ",";
_dbg(sdbg... | 6 |
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>
using nam... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n;
int box[101];
int aox[101];
int minn = 2147480000;
int maxn = -1;
int gcd(int a, int b) {
while (b != 0) {
int r = b;
b = a % b;
a = r;
}
return a;
}
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> box[i];
maxn = max(box[i],... | 1 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T &x) {
x = 0;
char c = getchar();
int sgn = 1;
while (c < '0' || c > '9') {
if (c == '-') sgn = -1;
c = getchar();
}
while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
x *= sgn;
}
template <typename T>
vo... | 3 |
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
static const ll mod=998244353;
ll modpow(ll x,ll y){
if(y==0)
return 1;
else if(y%2==0){
ll z=modpow(x,y/2);
return (z*z)%mod;
}else{
ll z=modpow(x,y/2);
return (x*((z*z)%mod))%mod;
}
}
ll N;
ll fac[10000005];
ll rev[10000005];
ll inf... | 0 |
#include <bits/stdc++.h>
using namespace std;
struct Query {
int a, t, x, n;
Query() {}
bool operator<(const Query &b) const { return x < b.x; }
};
int n;
vector<Query> queries;
vector<int> ans;
int ft[100005];
void add(int i, int a) {
for (; i < n; i |= i + 1) ft[i] += a;
}
int sum(int i) {
int ret = 0;
fo... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long n, k[111], c[111], t, p[111];
pair<long long, long long> q[111];
int main() {
cin >> n;
for (int i = 0; i < n; i++) cin >> q[i].second >> q[i].first;
cin >> t;
for (int i = 0; i < t; i++) cin >> p[i];
sort(q, q + n);
p[t] = 1000000007LL * 1000000007LL;... | 3 |
#include <bits/stdc++.h>
using namespace std;
namespace io {
const int __SIZE = (1 << 21) + 1;
char ibuf[__SIZE], *iS, *iT, obuf[__SIZE], *oS = obuf, *oT = oS + __SIZE - 1,
__c, qu[55];
int __f, qr, _eof;
inline void flush() { fwrite(obuf, 1, oS - obuf, stdout), oS = obuf; }
i... | 4 |
#include <bits/stdc++.h>
using namespace std;
using ii = long long;
using pi = pair<int, int>;
int main() {
int t;
cin >> t;
while (t--) {
int a, b, c;
cin >> c >> a >> b;
int x, y;
cin >> x >> y;
pi A = {x, a};
pi B = {y, b};
if (B > A) swap(A, B);
int r = 0;
r += A.first * mi... | 1 |
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define vii vector<pair<int, int> >
#define fi first
#define se second
int x[100005];
int sps[100005][20];
signed main()
{
int n, q, L;
cin>>n;
for(int i=1; i<=n; i++)
{
cin>>x[i];
// for(int d=0; d<=19; d++) sps[i][d]=n+1;
}
cin>>L>>q;
int p... | 0 |
#include <bits/stdc++.h>
using namespace std;
int const mod = (1e9) + 7;
int const N = (1e5) + 5;
long long power(long long a, long long deg) {
long long res = 1;
while (deg) {
if (deg % 2 == 0) {
a = (a * a) % mod;
deg /= 2;
} else {
res = (res * a) % mod;
deg--;
}
}
return ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
struct P {
long long int x, y, z;
};
void solve() {
long long int n;
cin >> n;
vector<P> v(n);
vector<bool> flag(n);
for (long long int i = 0; i < n; i++) {
cin >> v[i].x >> v[i].y >> v[i].z;
}
for (long long int i = 0;... | 3 |
#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
void ckmin(T1 &a, T2 b) {
if (a > b) a = b;
}
template <typename T1, typename T2>
void ckmax(T1 &a, T2 b) {
if (a < b) a = b;
}
int read() {
int x = 0, f = 0;
char ch = getchar();
while (!isdigit(ch)) f |= ch == '-', ch = getcha... | 1 |
#include <bits/stdc++.h>
using namespace std;
struct UnionFind {
vector<int> par;
UnionFind(int n) : par(n) {
for (int i = 0; i < n; i++) par[i] = i;
}
int root(int x) {
if (par[x] == x) return x;
return par[x] = root(par[x]);
}
void unite(int x, int y) {
if (root(x) == root(y)) return;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(x) cerr << "[(" << __LINE__ << ") " << #x << "]: " << (x) << endl;
int sz;
void upd(vector<int>& seg, int l, int r, int val) {
for (l+=sz, r+=sz; l<r; l/=2, r/=2) {
if (l&1) seg[l] = min(seg[l], val), l++;
if (r&1) -... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long int M = 998244353;
long long int power(long long int x, long long int y, long long int p) {
long long int res = 1;
x = x % p;
while (y > 0) {
if (y & 1) res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res % p;
}
long long int... | 4 |
#include <bits/stdc++.h>
#define base 950527
#define base2 1777771
#define N 1001
using namespace std;
typedef unsigned long long ull;
ull a[N][N],b[N][N],A[N][N],tmp[N][N],ans;
void Reverse(int p){for(int i=0;i<p;i++)reverse(b[i],b[i]+p);}
void rol_90(int p){
for(int i=0;i<p;i++)
for(int j=0;j<p;j++) tmp[p-j-... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n;
int A[300005], P[300005];
int idx = 1;
int Path[300005 * 30 + 5][2];
int Count[300005 * 30 + 5];
void insert(int v) {
int cur = 1;
Count[cur]++;
for (int i = 29; i >= 0; i--) {
int p = (v >> i) & 1;
if (Path[cur][p] == 0) {
Path[cur][p] = ++idx;
... | 3 |
#include <iostream>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll N,x;
ll A[2001];
ll C[2001][2001];
P D[2001][2001];
int main(){
cin >> N >> x;
for(int i=0;i<N;i++){
cin >> A[i];
C[0][i] = A[i];
}
for(int k=1;k<N;k++){
for(int i=0;i<N;i++){
C[k][i] = min(A[(i-k+N)... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long int mod = 1e9 + 7;
long long int dp[101000][3];
long long int n;
map<long long int, long long int> mp;
long long int rec(long long int k, long long int par, long long int ct) {
if (k == 0) {
if (par == 1) {
return 1;
}
return 0;
}
if (dp[k]... | 2 |
#include <bits/stdc++.h>
using namespace std;
void _print(long long int t) { cerr << t; }
void _print(string t) { cerr << t; }
void _print(char t) { cerr << t; }
void _print(long double t) { cerr << t; }
void _print(double t) { cerr << t; }
void _print(unsigned long long t) { cerr << t; }
template <class T, class V>
vo... | 2 |
#include <bits/stdc++.h>
using namespace std;
class N {
public:
long id, value;
N(long _id, long _value);
};
N::N(long _id, long _value) {
id = _id;
value = _value;
}
class H {
private:
vector<N> elem;
void swap(long a, long b);
public:
bool empty();
H();
void modify(long value);
void pop();
N... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long x[105], k[105], dp[1 << 21], ind[105];
int pb[105];
bool comp(int id1, int id2) { return k[id1] > k[id2]; }
int main() {
int n, m;
long long b;
cin >> n >> m >> b;
for (int i = 0; i < n; i++) {
int mp;
cin >> x[i] >> k[i] >> mp;
ind[i] = i;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m, k;
cin >> n >> m >> k;
if (k <= n - 1) {
cout << 1 + k << " " << 1;
return 0;
}
long long magic = m - 1;
k -= n - 1;
if (k == 1) {
cout << n << " " << 2;
return 0;
}
k -= 1;
long long mg = k % magic;
long lo... | 2 |
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
struct BiMatch{
Int n;
vector<vector<Int> > G;
vector<Int> match,used;
BiMatch(){}
BiMatch(Int sz):n(sz),G(sz),match(sz),used(sz){}
void add_edge(Int u,Int v){
G[u].push_back(v);
G[v].push_back(u);
}
bool dfs(Int v){
... | 0 |
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
int mem[3005][3005];
pair<int,int> arr[3005];
int n,t;
int go(int x,int y)
{
if(y>=t) return 0;
if(x>=n) return 0;
if(mem[x][y]!=-1) return mem[x][y];
return mem[x][y]=max(go(x+1,y),arr[x].S+go(x+1,y+arr[x].F));
}
int main()
{
cin >... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
for (int i = 0; i < 10; i++) {
cout << i << endl;
string r;
getline(cin, r);
if (r == "terrible" || r == "worse" || r == "no way" ||
r == "are you serious" || r == "do die in a hole") {
cout << "grumpy";
return 0;
}
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100100, INFTY = 0x3f3f3f3f;
int A[MAXN], B[MAXN];
vector<int> p[MAXN];
int posb[330];
int resp[330];
int main() {
int N, M, S, E;
posb[0] = 0;
resp[0] = 0;
for (int i = 1; i <= 300; i++) {
posb[i] = MAXN;
resp[i] = INFTY;
}
for (int i = ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m;
scanf("%lld%lld", &n, &m);
long long npair = n / 5;
long long mpair = m / 5;
long long nextra = n % 5;
long long mext = m % 5;
long long solve = npair * mpair * 5 + nextra * mpair + mext * npair;
if (nextra + mext > 4) solve += (... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
const long long LLINF = 9223372036854775807LL;
struct state {
int pos[3];
int who[3];
bool candrop[3], canmove[3], canpick[3];
};
bool operator<(const state &s1, const state &s2) {
int i = 0;
while (i < 3 && s1.pos[i] == s2.pos[i]) ++i;... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100 * 1000 + 5;
int a[N];
int get(int x, int y) { return (x >> y) & 1; }
bool pal(string s) {
for (int i = 0; i < s.size(); i++) {
if (s[i] != s[s.size() - i - 1]) {
return false;
}
}
return true;
}
bool lucky(int x) {
while (x) {
if ... | 1 |
#include <bits/stdc++.h>
using namespace std;
using cd = complex<double>;
const double pi = acos(-1);
vector<long long> ft(1, 1LL);
vector<long long> graph[500005];
void solve() {
long long n, m;
cin >> n >> m;
vector<pair<long long, long long> > x(n);
for (long long i = 0; i < m; i++) {
long long node1, no... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, m, tot;
map<int, int> id;
multiset<int> to[2 * 100000 + 5];
int ans[10 * 100000 + 5], tp, d[2 * 100000 + 5], cnt, p[10 * 100000 + 5];
int b[100000 + 5], c[100000 + 5], val[2 * 100000 + 5];
void dfs(int u) {
for (auto i = to[u].begin(); i != to[u].end(); i = to[u].b... | 5 |
#include <bits/stdc++.h>
using namespace std;
string s;
int now, ans;
int main() {
cin >> s;
for (int i = 0; i < s.length(); i++)
if (s[i] == '(')
now++;
else if (s[i] == ')' && now > 0)
now--, ans += 2;
cout << ans;
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a[] = {0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};
int x, y;
scanf("%d%d", &x, &y);
cout << (a[x]==a[y]? "Yes" : "No") << endl;
return 0;
} | 0 |
#include<bits/stdc++.h>
#define F(i,a,b) for(int i=(a);i<=(b);++i)
#define F2(i,a,b) for(int i=(a);i<(b);++i)
#define dF(i,a,b) for(int i=(a);i>=(b);--i)
#define dF2(i,a,b) for(int i=(a);i>(b);--i)
#define dF3(i,a,b) for(int i=(a)-1;i>=(b);--i)
using namespace std;typedef long long ll;typedef double ld;int INF=0x3f3f3f... | 0 |
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
int main(){
int n,p;
while(cin>>n>>p, n!=0 || p!=0){
int A[n];
memset(A, 0, sizeof(A));
int t=0;
while(1){
if(p==0){
p=A[t];
A[t]=0;
} else {
p-=1;
A[t]+=1;
}
... | 0 |
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> e[200005];
vector<int> pick[200005];
int pre[200005];
int dp[200005][2];
void dfs(int u, int fa) {
for (auto v : e[u]) {
if (v == fa) continue;
dfs(v, u);
}
// dp[i][0] root i is not on side
//... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, m, r, c;
scanf("%lld%lld", &n, &m);
if (n % 2 == 0) {
r = 1;
c = 1;
while (r != n / 2 + 1 || c != 1) {
printf("%lld %lld\n", r, c);
if (r <= n / 2) {
r = n - r + 1;
c = m - c + 1;
} else if (c... | 4 |
#include <bits/stdc++.h>
using namespace std;
map<int, int> segs;
int main() {
int n, k, a;
scanf("%d %d %d", &n, &k, &a);
segs[0] = n;
int s = (n + 1) / (a + 1);
int m;
scanf("%d", &m);
for (int i = 0; i < m; i++) {
int x;
scanf("%d", &x);
x--;
map<int, int>::iterator t = segs.upper_bound... | 4 |
#include <iostream>
int main() {
int n;
std::cin >> n;
std::cout << ((n%2==0) ? n/2 : n/2+1) << "\n";
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000 * 1000 * 1000;
const long long INF64 = 1000LL * 1000LL * 1000LL * 1000LL * 1000LL * 1000LL;
string s;
int n;
void Load() {
cin >> s;
n = (int)s.size();
}
int dp[2100][2100];
const int MOD = 1000 * 1000 + 3;
int rec(int pos, int br) {
if (br < 0) r... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
int main() {
cin >> n;
if (n % 2 == 0) cout << n * n / 2 << endl;
if (n % 2 == 1) cout << n * (n - 1) / 2 + n / 2 + 1 << endl;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if ((i + j) % 2 == 0) {
cout << "C";
} else {... | 1 |
#include <iostream>
using namespace std;
int main(){
int A, B, C;
cin >> A >> B >> C;
if(A==B)
cout<< C;
else if(A==C)
cout << B;
else cout << A;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
char ch;
int flag = 0;
cin >> s;
int count = 0;
for (int i = 0; i < s.size(); i++) {
if (isupper(s[i])) {
if (i == 0) {
flag = 1;
}
count++;
}
}
if (flag == 0 && count == s.size() - 1) {
for (int i... | 1 |
#include <bits/stdc++.h>
void solve() {
long long n;
std::cin >> n;
std::cout << -1 * (n - 1) << " " << n << "\n";
}
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
long long t = 0;
std::cin >> t;
while (t--) {
solve();
}
}
| 1 |
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
#define EPS (1e-10)
#define equals(a,b) (fabs((a)-(b)) < EPS)
#define PI 3.141592653589793238
// COUNTER CLOCKWISE
static const Int CCW_COUNTER_CLOCKWISE = 1;
static const Int CCW_CLOCKWISE = -1;
static const Int CCW_ONLINE_BACK = 2;
static const I... | 0 |
#include <bits/stdc++.h>
using namespace std;
ifstream putin;
struct point {
int x, y;
};
int n, i, k;
vector<point> a;
int main() {
cin >> n;
a.resize(n);
for (i = 0; i < n; i++) cin >> a[i].x >> a[i].y;
for (i = 0; i < n; i++) {
if (a[(i + 1) % n].x == a[i].x)
if (a[(i + 1) % n].y > a[i].y) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int tab[10000];
bool Perfect(int a) {
int sum = 0;
while (a > 0) {
sum = sum + a % 10;
a = a / 10;
if (sum > 10) break;
}
if (sum == 10) return (true);
return (false);
}
int main() {
tab[0] = 19;
int k;
cin >> k;
bool found = false;
int count... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long int power(long long int x, long long int y, long long int p) {
long long int res = 1;
x = x % p;
if (x == 0) return 0;
while (y > 0) {
if (y & 1) res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
int main() {
ios_base::syn... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long long int sz = 100005;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long int t = 1;
while (t--) {
long long int n, k;
cin >> n >> k;
if (n == 1) {
cout << "0";
return 0;
}
long long int val = ((... | 2 |
#include <bits/stdc++.h>
using namespace std;
string get_only_alpha(string s) {
string res = "";
for (int i = 0; i < s.length(); i++)
if (isalpha(s[i])) res += s[i];
return res;
}
pair<int, pair<string, string> > parse_it(string s, int t) {
int st = -1, ed = -1;
for (int i = 0; i < s.length(); i++)
if... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
pair<int, int> fib(int n) {
if (n == 0) return {0, 1};
auto p = fib(n >> 1);
int c = p.first * (2 * p.second - p.first);
int d = p.first * p.first + p.second * p.second;... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long n, k;
long long fac[1000007];
long long inv[1000007];
long long fastpow(long long a, long long x) {
long long r = 1;
while (x != 0) {
if (x % 2 == 0) {
a = (a * a) % 1000003;
x /= 2;
} else {
r = (r * a) % 1000003;
x--;
}
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2100;
int n, fa[N], s[N], root, size[N], ans[N];
vector<int> to[N], a[N];
template <class T>
inline void read(T &x) {
x = 0;
char ch = getchar(), w = 0;
while (!isdigit(ch)) w = (ch == '-'), ch = getchar();
while (isdigit(ch)) x = (x << 1) + (x << 3) +... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n, b, d;
cin >> n >> b >> d;
long long a[n + 3], tm = 0, cnt = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] > b) continue;
tm = tm + a[i];
if (tm > d) {
cnt++... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6;
vector<vector<int>> G(N);
int odw[N];
char odp[N];
int rozm[N];
int centroid;
void dfs(int start, int przodek = 0) {
rozm[start] = 1;
for (auto u : G[start])
if (odw[u] == 0 && u != przodek) {
dfs(u, start);
rozm[start] += rozm[u];
... | 3 |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
long long Hashimoto = 0;
bool Kanna = 1;
char I_Love = getchar();
while (I_Love < '0' || I_Love > '9') {
if (I_Love == '-') Kanna = 0;
I_Love = getchar();
}
while (I_Love >= '0' && I_Love <= '9') {
Hashimoto = Hashimoto * 10... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int mx;
vector<int> G[N];
vector<pair<int, int>> ans;
void dfs(int u, int fa, int t) {
ans.push_back({u, t});
int tmp = t;
int cnt = G[u].size();
if (u != 1) cnt--;
for (int v : G[u]) {
if (v == fa) continue;
if (t == mx) {
ans.... | 4 |
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <math.h>
#include <stdbool.h>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
class Point {
public:
double x, y;
Point(double x = 0, double y = 0): x(x), y(y) {}
Point operator + (Point p) ... | 0 |
#include "bits/stdc++.h"
using namespace std;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
using pii=pair<int, int>;
using Weight =int;
struct Edge {
int s, d;
Weight w;
Edge() {};
Edge(int s, int d, Weight w) :s(s), d(d), w(w) {};
};
using Array=vector<Weight>;
using Edges = vector<Edge>;
using Graph = vector<Edge... | 0 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
std::vector<long long> arr(4);
long long a, b;
for (int i = 0; i < 4; ++i) {
cin >> arr[i];
}
cin >> a >> b;
sort(arr.begin(), arr.end());
if (arr[0] > a) {
cout << min(arr[0] - a, b - a + 1) << endl;
} else {
cout << 0 << endl;
... | 1 |
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()
using namespace std;
int main()
{
vector <int> n2;
for (int i = 1; i <= 10000; i++ ){
n2.push_back (i*i );
} // end for
int n;
while (cin >> n && n ){
vector <int> m (n-1, 0 )... | 0 |
#include <bits/stdc++.h>
using namespace std;
void IO() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
}
int32_t main() {
IO();
long long int t = 1;
while (t--) {
string s;
cin >> s;
string ans = "";
long long int n = s.size(), ct = 0;
for (long long int i = 0; i < n; i++) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, m, t, head[100005];
int getHead(int p) {
if (head[p] == p) return p;
return head[p] = getHead(head[p]);
}
int main() {
scanf("%d%d", &n, &m);
for (int i = 0; i < n; ++i) head[i] = i;
for (int i = 0, a, b; i < m; ++i) {
scanf("%d%d", &a, &b), --a, --b;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string s;
cin >> s;
long long int len = s.length();
long long int cnt = 0;
for (long long int i = 0; i < len; ++i) {
if (s[i] == '1') {
cnt++;
}
}
long long int p... | 1 |
#include <cstdio>
#include <cctype>
#include <cstring>
#include <algorithm>
#include <vector>
#define debug(...) fprintf(stderr, __VA_ARGS__)
#ifndef AT_HOME
#define getchar() IO::myGetchar()
#define putchar(x) IO::myPutchar(x)
#endif
namespace IO {
static const int IN_BUF = 1 << 23, OUT_BUF = 1 << 23;
inline cha... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <int __>
struct ia {
int a[__], n;
ia(int n = 0) : n(n) {}
void rev() { reverse(a + 1, a + n + 1); }
void hp() { make_heap(a + 1, a + n + 1); }
int& operator[](int x) { return a[x]; }
void sf() {
for (int i = (1); i <= (n); i++) scanf("%d", a + i);
... | 2 |
#include <bits/stdc++.h>
using namespace std;
#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n)-1;i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(b)-1;i>=(a);--i)
#define ALL(a) a.begin(),a.end()
#define DUMP(x) cer... | 0 |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
char ch;
while (!isdigit(ch = getchar()))
;
long long sum = ch ^ 48;
while (isdigit(ch = getchar())) sum = (sum << 1) + (sum << 3) + (ch ^ 48);
return sum;
}
int n, m, d_in[610], d_ou[610];
int tops, fst[610], to[100010], nxt[100010];... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int OO = (int)2e9;
const double eps = 1e-9;
int daysInMonths[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int di[] = {-1, 0, 1, 0};
int dj[] = {0, 1, 0, -1};
int main() {
std::ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, m, OO = 1e8;
int dp[100001];
int solve(int x) {
if (x <= 0 || x > 1e5) return OO;
if (x == m) return 0;
int &ret = dp[x];
if (ret != -1) return ret;
ret = OO;
if (x > m)
ret = min(ret, 1 + solve(x - 1));
else {
ret = min(ret, 1 + solve(x * 2));
... | 2 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops")
using namespace std;
const int N = 1e5 + 2;
map<int, pair<long long, long long> > vec;
vector<int> v;
int a[N], b[N];
void add(int p, int i, int j) {
pair<long long, long long> &x = vec[p];
x = pair<long long, long long>(x.first | (1LL << i), x.sec... | 5 |
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define N 100009
using namespace std;
int n,a[N],fst[N],nxt[N],dgr[N],vis[N],num[N],f[N];
int main(){
scanf("%d",&n);
int i,j,k,sz,tmp,rst;
for (i=1; i<=n; i++){
scanf("%d",&a[i]);
nxt[i]=fst[a[i]]; fst[a[i]]=i; dgr[a[i]]++;
}
int ans=1; bool... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
long long n, m;
cin >> n >> m;
long long arr[n][m];
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
cin >> arr[i][j];
}
}
long long a[n][m], b[n][m], c[n][m... | 4 |
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <climits>
using namespace std;
#define N 8 //メリーゴーランドの台数
int M[N] = {4, 1, 4, 1, 2, 1, 2, 1};
int check_M[N] = {41412121, 14121214, 41212141, 12121414, 21214141,12141412, 21414121, 14141212};
int main(void) {
int p[N]; //客の人数
int min; //乗り損ねた客の最小人数
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int TESTS = 1;
cin >> TESTS;
while (TESTS--) {
int n;
cin >> n;
set<long long int> s;
for (int i = 0, a; i < n; i++) {
cin >> a;
s.insert(a);
}
cout << s.... | 2 |
#include <bits/stdc++.h>
#pragma GCC optimize("O2,unroll-loops")
using namespace std;
const int MAXN = 100010;
struct Node {
int mn = 0, cnt = 0, sz = 0;
};
Node Merge(Node x, Node y) {
Node z;
z.mn = min(x.mn, y.mn);
if (z.mn == x.mn) z.cnt ^= x.cnt;
if (z.mn == y.mn) z.cnt ^= y.cnt;
z.sz = (x.sz ^ y.sz);
... | 5 |
#include <bits/stdc++.h>
const double pi = 3.1415926535897932384626433832795;
double EPS = 10e-6;
const int INF = 2000000000;
long long gcd(long long a, long long b) {
if (a == 0) return b;
return gcd(b % a, a);
}
using namespace std;
void ifd() {}
void tme() {}
int xx, yy, ans, cur_x = 350, cur_y = 350, cur_d = 0,... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1 + 2e5;
long long low[MAXN], num[MAXN], id[MAXN], vis[MAXN], vtime, nscc, n, m, f[MAXN],
ans, x, sz[MAXN], sum[MAXN], dp[MAXN][2], res, kt;
stack<int> s;
vector<int> g[MAXN], p[MAXN];
long long dfs(int u) {
vis[u] = 1;
low[u] = num[u] = ++vtime;
... | 5 |
#include<stdio.h>
int main(){
int n=0, x;
scanf("%d", &x);
for(n=0;n<x;n+=1000){
n;
}
printf("%d", n-x);
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, l;
scanf("%d", &n);
stack<int> s;
for (int i = 1; i <= n; i++) {
scanf("%d", &l);
while (!s.empty() && s.top() >= i - l) s.pop();
s.push(i);
}
printf("%d", s.size());
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(0) * 2;
template <class T>
inline T abs1(T a) {
return a < 0 ? -a : a;
}
template <class T>
inline T max1(T a, T b) {
return a > b ? a : b;
}
template <class T>
inline T min1(T a, T b) {
return a < b ? a : b;
}
template <class T>
inline T gcd1(T... | 3 |
#include <bits/stdc++.h>
using namespace std;
void execution();
int main() {
ios_base::sync_with_stdio(0);
execution();
return 0;
}
void execution() {
long long n, m, sum = 0;
cin >> n >> m;
vector<long long> a(n);
for (int i = 0; i < n; i++) cin >> a[i], sum += a[i];
if (sum < m) {
cout << -1;
... | 4 |
#include <cstdio>
using namespace std;
int v,k;
int main(){
scanf("%d", &v);
if(v==0) return 0;
for(int i=0;i<9;i++){
scanf("%d", &k);
v -= k;
}
printf("%d\n", v);
int main();
} | 0 |
#include <bits/stdc++.h>
using namespace std;
long long dp[2][20][48][2520];
int id[2521], totid;
int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); }
int lcm(int a, int b) {
if (b == 0) return a;
return a * b / gcd(a, b);
}
char l[20];
int len;
long long DP(int pos, int u, int lcmnow, int left) {
if (p... | 4 |
#include <bits/stdc++.h>
using namespace std;
double log2(double n) { return log(n) / log(2); }
double ln(double n) { return log(n) / log(2.71828182846); }
void Heap(signed long long int A[], signed long long int n,
signed long long int l, signed long long int r) {
signed long long int x, i, j;
x = A[l];
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double EPS = 1e-11;
int main() {
int N, M;
int a, b, r, si, ei, ti;
scanf("%d %d", &N, &M);
for (int i = 0; i < N; i++) {
scanf("%d %d %d", &si, &ei, &ti);
si--;
ei--;
if (si == ei) {
printf("%d\n", ti);
... | 1 |
#include <bits/stdc++.h>
using namespace std;
char s[1000005];
int n = 0, m;
char s1[2000005];
int nex[1000005];
struct node {
int ch[26], pre, l;
} t[2000005];
int ndtot = 1;
int num[2000005] = {0};
int cnt[1000005] = {0}, seq[2000005];
int rt = 1, las = 1;
void add(int c) {
int p = las, np = ++ndtot;
las = np;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
struct abc {
long long int x, y;
};
bool compare(abc a1, abc a2) {
if (a1.x == a2.x) return a1.y < a2.y;
return a1.x < a2.x;
}
const long long int mod = 1e9;
long long int a[100005];
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL... | 2 |
#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
inline T1 max(T1 a, T2 b) {
return a < b ? b : a;
}
template <typename T1, typename T2>
inline T1 min(T1 a, T2 b) {
return a < b ? a : b;
}
const char lf = '\n';
namespace ae86 {
const int bufl = 1 << 15;
char buf[bufl], *s = buf, *t ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int MX = 5e5 + 5;
const long long INF = 1e18;
const long double PI = 4 * atan((long double)1);
template <class T>
bool ckmin(T& a, const T& b) {
return a > b ? a = b, 1 : 0;
}
template <class T>
bool ckmax(T& a, const T& b) {
return a < b ... | 5 |
#include<stdio.h>
const int maxn=1000005;
int i,j,k,m,n,l,r;
int a[maxn];
int check(int x){
for(int i=n,j=n;i>1&&j<m;i--,j++){
if((a[i]<=x&&a[i-1]<=x)||(a[j]<=x&&a[j+1]<=x))
return 1;
if((a[i]>x&&a[i-1]>x)||(a[j]>x&&a[j+1]>x))
return 0;
}
return a[1]<=x;
}
int main(){
scanf("%d",&n);
m=(n<<1)-1;
for(i=1... | 0 |
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#i... | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.