solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n, d;
cin >> n >> d;
vector<std::pair<int, int> > v;
long long m, s;
for (int i = 0; i < (n); ++i) {
cin >> m >> s;
v.push_back(make_pair(m, s));
}
sort(v.begin(), v.end());
long long maxm = v[0].second, sum = 0, prev = v[0].... | 2 |
#include <bits/stdc++.h>
using namespace std;
inline long long in() {
long long ret = 0, c = getchar(), b = 1;
while (!isdigit(c)) {
b = c == '-' ? -1 : 1, c = getchar();
}
while (isdigit(c)) {
ret = ret * 10 + c - '0', c = getchar();
}
return ret * b;
}
long long n, p[300005], L[300005], R[300005],... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<pair<long double, int>> points;
points.reserve(n);
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
long double angle = atan2(y, x);
points.push_back({angle, i});
... | 3 |
#include <bits/stdc++.h>
using namespace std;
inline void pisz(int n) { printf("%d\n", n); }
template <typename T, typename TT>
ostream &operator<<(ostream &s, pair<T, TT> t) {
return s << "(" << t.first << "," << t.second << ")";
}
template <typename T>
ostream &operator<<(ostream &s, vector<T> t) {
for (int i = 0... | 1 |
#include <bits/stdc++.h>
using namespace std;
int a[300005];
int ans[300005];
vector<pair<int, int> > v;
int last = 0;
int n;
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
v.push_back(make_pair(a[i], i));
}
sort(v.begin(), v.end());
for (int i = 0; i < n; i++) {
i... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 102, M = 5107;
int p[N], f1[N][M], f2[N][M];
inline void solve(int l, int r, int ql, int qr, int a, int b, bool rev) {
if (l == r) {
p[ql] = l;
return;
}
if (f2[a][b] == 1) {
int g[N];
g[0] = 0;
if (rev == 0)
for (int i = 1; i <... | 6 |
#include <bits/stdc++.h>
using namespace std;
template <class T1>
void deb(T1 e1) {
cout << e1 << endl;
}
template <class T1, class T2>
void deb(T1 e1, T2 e2) {
cout << e1 << " " << e2 << endl;
}
template <class T1, class T2, class T3>
void deb(T1 e1, T2 e2, T3 e3) {
cout << e1 << " " << e2 << " " << e3 << endl;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int dp[(1<<13)+5][2],X,Y,x,o,te;
int C(int x,int y) {return ((x>>y)&1);}
int dq(int tt,int o)
{
if ((tt&X)==X) return 1;
if ((tt&Y)==Y) return 0;
if (dp[tt][o]>-1) return dp[tt][o];
if (o==0)
{
bool kt=false;int kq=0;
for (int i=0;i<13;++... | 0 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
const int INF = ((1 << 31) - 1);
const long long LLINF = (((1LL << 63) - 1LL));
const double eps = 1e-9;
const double PI = 3.14159265358979323846;
const int maxN = 201;
double max_sum[maxN][maxN][maxN];
double calc[maxN][maxN][maxN... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 7;
int le[N], ri[N];
long long n, k;
char s[N];
int main() {
scanf("%lld%lld", &n, &k);
scanf("%s", s + 1);
le[1] = s[1] - '0';
for (int i = 2; i <= n; i++) {
if (le[i - 1] != s[i] - '0')
le[i] = 2;
else
le[i] = le[i - 1... | 3 |
#include <stdio.h>
#include <algorithm>
using namespace std;
int main(void)
{
char c[5];
int i, j;
int sum[14];
int max, max2;
while (scanf("%d, %d, %d, %d, %d", &c[0], &c[1], &c[2], &c[3], &c[4]) != EOF){
for (i = 0; i < 14; i++){
sum[i] = 0;
}
for (i = 0; i < 5; i++){
sum[c[i]-1]++;
}
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, s[2000100];
bool vis[2000100];
char t[2000100];
int sa[2000100], rnk[2000100], tmp[2000100], cnt[2000100];
void build(char *s) {
int n = strlen(s) + 1, m = 256;
int *x = rnk, *y = tmp, *z;
for (int i = 0; i < m; i++) cnt[i] = 0;
for (int i = 0; i < n; i++) cn... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 9;
const int MOD = 1e9 + 7;
int R, n, m;
pair<int, int> head[205], tail[205];
int dis[205][205];
int dp[205][205];
int mark[205][205];
bool cycle;
queue<pair<int, int> > q;
int dfs(pair<int, int> v) {
int vh = v.first;
int vt = v.second;
if (vh +... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n;
int mod = 998244353;
long long fac[2123456], ifac[2123456];
long long powermod(long long a, long long b) {
if (b == 0) return 1;
long long t = powermod(a, b / 2);
t = (t * t) % mod;
if (b % 2 == 1) t = (t * a) % mod;
return t;
}
void prepare() {
fac[0] = ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
int a[600], st;
cin >> n >> k;
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
int ans = a[0];
st = 0;
for (int i = 1; i < n; i++) {
if (st >= k) {
cout << ans << endl;
return 0;
}
if (ans > a[i]) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
long long x = 0;
char ch = getchar();
bool d = 1;
for (; !isdigit(ch); ch = getchar())
if (ch == '-') d = 0;
for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
return d ? x : -x;
}
inline void write(long long x) {
if (x < ... | 2 |
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
using namespace std;
const int N = 50;
const double EPS = 1e-8;
int n;
vector<pair<double, int> > data;
bool equals(double a, double b){ return abs(a - b) < EPS; }
int solve(){
pair<double, double> dist[N];
int round[N],... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long strtoint(string str);
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
long long b, n = 0, k;
cin >> b >> k;
b %= 2;
for (auto i = 0; i < k; ++i) {
long long x;
cin >> x;
long long tmp = x * pow(b, k - 1 - i);
t... | 1 |
#include<bits/stdc++.h>
using namespace std;
int main()
{
int x,y;cin>>x>>y;
if(x*2<=y && x*4>=y && y%2==0)cout<<"Yes";
else cout<<"No";
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
struct task {
int t, k, d;
int id;
bool operator<(const task& b) const { return t < b.t; }
} p[maxn];
struct sever {
int id, t;
bool operator<(const sever& b) const { return t > b.t; }
sever(int _id, int _t) : id(_id), t(_t) {}
};
struc... | 3 |
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>
#include... | 0 |
//Try until you reach your goal
#include <bits/stdc++.h>
using namespace std;
# define ll long long
# define endl "\n"
# define str string
# define vll vector<ll>
# define pb push_back
# define mll map<ll,ll>
# define mp make_pair
# define ff first
# define ss second
# define pll pair<ll,ll>
# define f(x,y) for(int x=0... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
int c, v0, v1, a, l;
while (cin >> c >> v0 >> v1 >> a >> l) {
int k = 0, sum = 0, inc = v0;
while (true) {
k++, sum += inc;
if (sum >= c) break;
sum -= l;
inc += a;
if (inc >= v1) inc = v1... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }
int n;
long long p, q, b;
int main() {
scanf("%d", &n);
while (n--) {
scanf("%I64d%I64d%I64d", &p, &q, &b);
q /= gcd(p, q);
while (true) {
b = gcd(q, b);
if (b == 1) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int dap = 0;
int a[200010];
int dp[100010], dp1[100010];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
for (int i = 1; i <= n; i++) {
dp[i] = min(dp[i - 1] + 1, a[i]);
}
for (int i = n; i >= 1; i--) dp1[i] = min(dp1[i ... | 2 |
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
int a[N],vis[N];
int main()
{
int n,x;scanf("%d%d",&n,&x);
if(x==1||x==2*n-1){printf("No\n");return 0;}
printf("Yes\n");
if(n==2){printf("1\n2\n3\n");return 0;}
if(x==2*n-2)a[n-1]=x-2,a[n]=x,a[n+1]=x+1,a[n+2]=x-1,vis[x-2]=1;
else a[... | 0 |
#include<cstdio>
#include<vector>
#include<algorithm>
#include<utility>
#include<numeric>
#include<iostream>
#include<array>
#include<string>
#include<sstream>
#include<stack>
#include<queue>
#include<list>
#include<functional>
#define _USE_MATH_DEFINES
#include<math.h>
#include<map>
#define SENTINEL 1000000001
#def... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
const long long INF = 1000000000;
int main() {
long long t;
cin >> t;
while (t--) {
long long n, m;
cin >> n >> m;
long long mx = m, mn = m, prev = 0;
bool flag = true;
while (n--) {
long long low, up, k;
cin... | 3 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN=2e5+10;
int ti[MAXN];
int main(){
int n,t;
while(cin>>n>>t){
for(int i=1;i<=n;i++) cin>>ti[i];
ll sum=0;
sum+=t;
for(int i=2;i<=n;i++){
sum+=min(t,ti[i]-ti[i-1]);
}
cout<<sum<<endl;
}
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
long long fact[20], n, k, anss;
vector<int> vec, vec2;
long long num(int a) {
int j = 0;
for (int i = 31; i >= 0; i--)
if ((a >> i) & 1) {
j = i;
break;
}
long long ans = 0;
for (int i = j - 1; i >= 0; i--) {
ans *= 10;
if ((a >> i) & 1)
... | 5 |
#include<bits/stdc++.h>
using namespace std;
int n,nw,ans,a[100005];
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
if(i>1 && a[i]>a[i-1]){
ans=max(ans,nw);
nw=0;
}
nw++;
}
ans=max(ans,nw);
cout<<ans-1;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <class T>
int size(T &&a) {
return (int)(a.size());
}
ostream &operator<<(ostream &os, string str) {
for (char c : str) os << c;
return os;
}
template <class A, class B>
ostream &operator<<(ostream &os, const ... | 5 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
const long double pi = 3.14159265358979323846;
const long long int inf = (long long int)1ll << 50;
const int ss = (int)1e6 + 3;
const long long int base = inf;
bool pred(const pair<int, int>& i, const pair<int, int>& j) {
if (i.f... | 1 |
#include <bits/stdc++.h>
using namespace std;
int a[100010];
int s[100010];
int query(int l, int r) { return s[r] - s[l - 1]; }
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
s[i] = a[i] + s[i - 1];
}
int ans = 0;
for (int i = 1; i < n; i++) {
if (query(1, i) == query(... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f, mod = 1000000007;
const double pi = 3.1415926535897932, eps = 1e-6;
int T, n, k, a[200005], ans, p;
void solve() {
scanf("%d%d", &n, &k);
for (int(i) = (1); (i) <= (n); (i)++) scanf("%d", a + i);
ans = inf;
for (int(i) = (1); (i) <= (n - ... | 3 |
// #pragma GCC optimize("Ofast,unroll-loops")
// #pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define dd double
#define ld long double
#define sl(n) scanf("%lld", &n)
#define si(n) scanf("%d", &n)
#define sd(n) scanf("%lf", &n)
#d... | 5 |
#include <bits/stdc++.h>
using namespace std;
//#define DEBUG 1
#define pii pair<int,int>
#define ff first
#define ss second
#define pb push_back
const int N = 2e3+100;
const int D = 10;
char mat[N][N];
int minH[D][N],maxH[D][N],minV[D][N],maxV[D][N];
int64_t ans[D];
int n;
int main(){
ios::sync_with_stdio(fal... | 3 |
#include <bits/stdc++.h>
using namespace std;
struct Point {
int x, w;
Point() {}
Point(int _x, int _w) { x = _x, w = _w; }
bool operator<(const Point& other) const { return x - w < other.x - other.w; }
};
Point p[200005];
int dp[200005];
int main() {
int n;
int x, w;
while (cin >> n) {
for (int i = 0... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 300004;
const int maxx = 30 * maxn;
int sz;
int trie[maxx][2], s[maxx];
int a[maxn], p[maxn];
void insert(int n) {
int v = 0;
for (int i = 29; i >= 0; i--) {
int val = (n >> i) & 1;
if (!trie[v][val]) trie[v][val] = ++sz;
v = trie[v][val];
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 5e3 + 10, mod = 998244353;
long long n;
long long fac[N], ifac[N], a[N], lim[N], dp[N];
inline long long pw(long long x, long long y) {
long long res = 1;
for (; y; x = x * x % mod, y >>= 1)
if (y & 1) res = res * x % mod;
return res;
}
void in... | 6 |
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < n; i++)
#define int long long
signed main(signed argc, char* argv[]) {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n,q;
cin>>n>>q;
vector<int> a(n);
rep(i,n)cin>>a[i];
sort(a.... | 0 |
#include <bits/stdc++.h>
using namespace std;
const double pi = 2 * acos(0);
const long long N = 1e9 + 5;
long long j, t, i, n, x, y;
int main() {
cin >> x;
vector<long long> v(x);
for (int i = 0; i < x; i++) {
cin >> v[i];
}
if (is_sorted(v.begin(), v.end())) {
cout << "yes"
<< "\n"
... | 2 |
#include <bits/stdc++.h>
using namespace std;
template <typename TH>
void _dbg(const char* sdbg, TH h) {
cerr << sdbg << "=" << h << "\n";
}
template <typename TH, typename... TA>
void _dbg(const char* sdbg, TH h, TA... t) {
while (*sdbg != ',') cerr << *sdbg++;
cerr << "=" << h << ",";
_dbg(sdbg + 1, t...);
}
... | 4 |
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include ... | 0 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
template<typenam... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long suf(long long a) { return (a * (a + 1)) / 2; }
int dx[]{1, -1, 0, 0};
int dy[]{0, 0, 1, -1};
int dx8[]{1, -1, 0, 0, 1, -1, 1, -1};
int dy8[]{0, 0, 1, -1, 1, -1, -1, 1};
const long long OO = 1e9 + 7;
int main() {
int n;
cin >> n;
string s, ans = "";
cin >> ... | 2 |
#include <bits/stdc++.h>
#define fastIO ios_base::sync_with_stdio(false); cout.tie(0)
#define endl '\n'
#define FORI(start, end) for(int i = start; i < end; i++)
#define FORJ(start, end) for(int j = start; j < end; j++)
#define FORK(start, end) for(int k = start; k < end; k++)
using namespace std;
typedef long... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
const int N = 2e5 + 5;
int t, n, k, a[N], b[N], posA[N], posB[N];
int main() {
scanf("%d", &t);
while (t--) {
scanf("%d %d", &n, &k);
for (int i = 1; i <= n; ++i) {
posA[i] = 0;
posB[i] = 0;
scanf("%d", &a[i]);
}
... | 2 |
#include<iostream>
#include<algorithm>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
int main(){
int N;
while( cin >> N, N ){
int pos[200][2] = {};
for(int i=1; i<N; i++){
int n, d;
cin >> n >> d;
pos[i][0] = pos[n][0];
pos[i][1] = pos[n][1];
pos[i][d%2] += (d<2 ? -1 : 1);
}
in... | 0 |
#include <bits/stdc++.h>
using namespace std;
int a[5004];
int main() {
ios ::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= n; i++) {
if (a[a[a[i]]] == i) {
cout << "YES" << endl;
return 0;
}
}
... | 1 |
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
const int MAXN = 2e5 + 10;
bool a[MAXN], dl[MAXN];
int n, m, deg[MAXN][2];
vector<int> Mat[MAXN];
queue<int> del;
void ers(int v) {
for (int i = 0; i < Mat[v].size(); i++) {
if (dl[Mat[v][i]])
continue;
deg[Mat[v][i]][a[v]]--;
if (d... | 0 |
#include <bits/stdc++.h>
using namespace std;
int y, c = 1;
vector<int> a;
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> y;
a.push_back(y);
}
sort(a.begin(), a.end());
for (int i = 0; i < n - 1; i++) {
if (a[i + 1] > a[i] && a[i] != 0) {
c++;
}
}
cout << c;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long long int inf = 1e15;
const long long int mod = 1000000007;
const int infInt = 1e9;
const double PI = acos(-1.00);
const double eps = 1e-6;
long long int nCars, nGas, len, Time;
pair<long long int, long long int> cars[200010];
long long int stations[200010];
long ... | 3 |
#include <bits/stdc++.h>
#define REP(i, a, n) for (ll i = ((ll) a); i < ((ll) n); i++)
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
struct state {
ll v, z, d;
bool operator<(const state &s) const {
return d > s.d;
}
};
int main(void) {
for (ll N, M, C; cin >> N >> M >> C, N && M &... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long A[2][2];
long long C[2];
char out[2000000];
int main() {
for (int i = 0; i < (2); ++i)
for (int j = 0; j < (2); ++j) cin >> A[i][j];
for (int i = 0; i < (2); ++i)
while (C[i] * (C[i] - 1) / 2 < A[i][i]) ++C[i];
bool ok = true;
for (int i = 0; i < (... | 2 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:100000000000")
using namespace std;
int64_t n, m, k;
int32_t q;
int main() {
scanf("%d\n", &q);
for (int32_t i = (0); i < (q); ++i) {
cin >> n >> m >> k;
auto mn = min(n, m);
auto mx = max(n, m);
if (mx > k) {
printf("%d", -1);
} els... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> ans;
int idx = 1;
while (n >= idx) {
ans.push_back(idx);
n -= idx;
idx++;
}
ans[ans.size() - 1] += n;
n = 0;
cout << ans.size() << endl;
for (auto x : ans) cout << x << " ";
}
| 1 |
//
// main.cpp
// OrangeMadness
//
// Created by Panagiotis Chadjicostas on 2021/01/2021
// Copyright © 2021 Panagiotis Hadjicostas. All rights reserved.
//
#include <iostream>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iterator>
#incl... | 1 |
#include <bits/stdc++.h>
using namespace std;
int k;
char M[5][7];
int C[256];
int main() {
scanf("%d", &k);
for (int i = (0); i < (5); ++i) {
scanf("%s", &M[i]);
for (int j = (0); j < (5); ++j) C[M[i][j]]++;
}
for (int i = ('1'); i < ('9' + 1); ++i)
if (C[i] > 2 * k) {
printf("NO\n");
r... | 1 |
#include <bits/stdc++.h>
using namespace std;
vector<int> adj[666666];
int n, h, ans = 0;
void upd(int x) {
if (adj[x].size() || ans) return;
printf("? %d\n", x);
fflush(stdout);
int k;
scanf("%d", &k);
if (k == 2) ans = x;
adj[x].resize(k);
for (int i = 0; i < k; i++) scanf("%d", &adj[x][i]);
}
void pr... | 6 |
#include<iostream>
#include<cmath>
using namespace std;
int main(){
int A,B,C;
cin>>A>>B>>C;
int K;
cin>>K;
cout<<A+B+C-max(A,max(B,C))+max(A,max(B,C))*pow(2,K);
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
typedef struct _Bus {
double v, t;
_Bus(double v, double t) {
this->v = v;
this->t = t;
}
_Bus() {}
} Bus;
int n;
double a, d;
Bus bus[100100];
double getMaxSpeedWhen(Bus b) { return b.v / a; }
double lengthWhenMaxSpeed(Bus b) {
double t = getMaxSpeedWhen(... | 3 |
#include <cstdio>
#define N 100001
using namespace std;
int a[N], p[N], n, m, r = 0;
int f(int x) { return p[x] = p[x] == x ? x : f(p[x]); }
void u(int x, int y) { p[f(x)] = f(y); }
int main() {
scanf("%d%d", &n, &m);
for(int i = 1; i <= n; i++)
scanf("%d", a + i)... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 3e5 + 5;
long long n, m, arr[N][9], Mask[1 << 8];
pair<long long, long long> ans;
bool cool(long long x) {
memset(Mask, -1, sizeof(Mask));
for (long long i = 0; i < n; i++) {
long long mask = 0;
for (long long w = 0; w < m; w++) {
if (a... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MN = 101010, MVAL = 1010101010;
int dp[MN];
int t[MN];
int main() {
int n, pre, cost, i;
scanf("%d", &n);
for (i = 0; i < n; ++i) scanf("%d", t + i);
for (i = 0; i < n; ++i) dp[i] = MVAL;
for (i = 0; i < n; ++i) {
cost = 20;
if (i != 0) cost += d... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main()
{
int a,b,h,m;
cin>>a>>b>>h>>m;
float hour=30.0*h+(m/2.0);
float min=m*6;
float diff=min-hour;
//cout<<diff<<"\n";
cout<<setprecision(12)<<sqrt(a*a+b*b-2*a*b*cos((M_PI*diff)/180.0));
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string x, y, z;
cin >> x;
cin >> z;
for (int i = 0; i < x.size(); ++i) {
if (x[i] == z[i])
y.push_back(x[i]);
else if (z[i] > x[i]) {
cout << -1 << endl;
return 0;
} else
y.push_back(z[i]);
}
cout << y << endl;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int p, n, m, x, y, res = 1, plates[12][12][12];
int solve(int a, int b, int c) {
if (plates[a][b][c] != -2) {
if (plates[a - 1][b][c] == 1) {
res++;
plates[a - 1][b][c] = -1;
}
if (plates[a + 1][b][c] == 1) {
res++;
plates[a + 1][b][c] ... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long power(long long x, long long y, long long p) {
long long 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;
}
void solve() {
long long n;
cin >> n;
stri... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 5, maxlen = 5e5 + 5;
const int inf = 3e6 + 5;
int n, x[maxn], y[maxn];
char s[maxlen];
int ansb, ansn;
bool check(int mid, int ty) {
int xmin = 0, xmax = inf, ymin = 0, ymax = inf, dmin = -inf, dmax = inf;
for (int i = 1; i <= n; i++) {
xmin =... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 1;
void solve() {
int n;
cin >> n;
int l[n], r[n];
int mil = INF, mar = -INF;
for (int i = 0; i < n; i++) {
cin >> l[i] >> r[i];
if (mil > r[i]) mil = r[i];
if (mar < l[i]) mar = l[i];
}
if (mar < mil)
cout << 0;
else
... | 1 |
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define pb push_back
#define rep(i,a,b) for(i=a;i<=b;i++)
using namespace std;
const int N=100010;
int a[N];
int n,K;
int ans;
int dep[N];
vector<int> vec[N];
void dfs(int x){
int i,y;
rep(i,0,(int)vec[x].size()-1){
y=vec[x][i];
dfs(y);
if... | 0 |
#include <bits/stdc++.h>
using namespace std;
int tilecnt[1111111];
int dp[2][9][9];
int main(void) {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) {
int x = 0;
cin >> x;
tilecnt[x]++;
}
int ans = 0;
for (int i = 1; i <= m; i++) {
whi... | 4 |
#include <bits/stdc++.h>
char A[105][105], str[105];
int n;
void swapp(int a, int b) {
char t[105];
strcpy(t, A[a]);
strcpy(A[a], A[b]);
strcpy(A[b], t);
}
bool isMax(int a, int b) { return (strcmp(A[a], A[b]) > 0); }
void sort() {
int i, j;
for (i = 0; i < n; i++) {
for (j = 0; j < n - i - 1; j++) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int N;
vector<int> L, T, R, B;
vector<int> X, Y;
vector<vector<ll>> field;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
void compress(vector<int> &X){
sort(X.begin(), X.end());
X.erase(unique(X.begin(), X.end()), X.end());
}
void dfs... | 0 |
#include <iostream>
using namespace std;
int card[50];
int buffer[50];
int main()
{
int n,r;
while(cin>>n>>r,n!=0){
for(int i=0;i<n;i++)card[i]=n-i;
for(int i=0;i<r;i++){
int p,c;
cin>>p>>c;
for(int j=0;j<p-1;j++)
buffer[j]=card[j];
for(int j=0;j<c;j++)
card[j]=card[j+p-1];
for(int j=0;j<p-... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, k, maxx, idx, max1, s;
int main(int argc, char *argv[]) {
pair<int, int> a[10000];
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i].first;
a[i].second = 0;
}
maxx = 0;
max1 = 0;
for (int i = 0; i < n; i++) {
if (a[i].first > maxx) {
... | 1 |
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,m,f[100100],val[100100],s[100100],a,b,ff[100100],d[100100],cnt;
vector<int>v[100100];
inline int sf(int x){return f[x]==x?x:f[x]=sf(f[x]);}
inline void dfs(int x,int fa,int wh){
s[x]=val[x]=wh;ff[x]=fa;
for(int i=0;i<v[x].size();i++)
if(v[x][... | 0 |
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;
ll Pmod(ll n,ll k){
ll r=k,ret=1;
while(true){
if(n==0)break;
if(n%2==1){
ret=ret*r%mod;
}
n/=2;
r=r*r%mod;
}
return ret;
}
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, m, a[200], b, kol, j, ost, vid;
int main() {
scanf("%d %d", &n, &m);
for (int i = 0; i < n; i++) {
scanf("%d", &b);
if (a[b - 1] == 0) {
vid++;
}
a[b - 1]++;
j++;
}
for (int i = 0; i < 101; i++) {
for (int j = 0; j < 101; j++) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
void solve(void) {
int n;
cin >> n;
vector<pair<int, string>> ps(n), ans;
for (auto &p : ps) {
cin >> p.second >> p.first;
}
sort(ps.begin(), ps.end());
int h = 3000;
for (const auto &p : ps) {
auto pos = ans.begin() + p.first;
if (pos > ans.end(... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (a == 0) return b;
return gcd(b % a, a);
}
long long powm(long long base, long long exp, long long mod = 1000000007) {
base %= mod;
long long ans = 1;
while (exp) {
if (exp & 1LL) ans = (ans * base) % mod;
exp >... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a[100010], i, x, val;
cin >> n >> x;
int cnt[100010] = {0};
int cnt2[100010] = {0};
for (i = 0; i < n; i++) {
cin >> a[i];
cnt[a[i]]++;
}
for (i = 0; i < 100010; i++) {
if (cnt[i] > 1) {
cout << "0\n";
return 0;
... | 2 |
#define NDEBUG
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <cassert>
using namespace std;
typedef long long ll;
struct LCTree {
typedef int D;
static const int INF = 1LL<<25;
static const int DF... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 50005;
long long one[19] = {0, 1};
void init() {
for (int i = (2); i <= (16); i++) one[i] = one[i - 1] * 10 + 1;
}
long long dfs(long long sum, long long n) {
if (n == 1) return sum;
long long k1 = sum / one[n];
long long k2 = k1 + 1;
long long r1 = ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
bool transp = false;
if (n > m) {
transp = true;
swap(n, m);
}
if (m == 2 or (n != 3 and m == 3))
cout << "NO" << endl;
else {
cout << "YES" << endl;
vector<vect... | 2 |
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
inline int read()
{
int f = 1, x = 0;
char ch;
do{
ch = getchar();
if (ch == '-')
f = -1;
}while(ch < '0' || ch > '9');
do{
x = x * 10 + ch - '0';
ch = getchar();
}while(ch >= '0' && ch <=... | 3 |
#include "bits/stdc++.h"
using namespace std;
#define long int64_t
struct Solver {
void solve() {
unsigned x;
cin >> x;
bitset<32> b( x );
cout << b << '\n'
<< ~b << '\n'
<< (b << 1) << '\n'
<< (b >> 1) << endl;
}
};
int main() {
ios::sync_with_stdio( false );
cout << fixed << setprecision( 10 )... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const long long MAXN = 2e5 + 100;
const long long MOD = 1000000007;
struct ele {
long long pos, ty;
bool operator<(const ele &a) const { return pos < a.pos; }
} ax[MAXN];
int main(int argc, char const *argv[]) {
long long a[2], b[2], c[2];
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string s;
cin >> n >> s;
map<pair<string, string>, long> m;
for (int i = 0; i < 1 << n; i++) {
string t1, t2;
for (int j = 0; j < n; j++) {
if (i & 1 << j) t1 += s[j];
else t2 += s[j];
}
m[make_pair(t1, t2)]++;
}
long r = 0;
for (... | 0 |
// In the name of God
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
vector<int> pt(3);
int n;
cin >> n >> pt[0] >> pt[1] >> pt[2];
vector<pair<int,int>> q;
for(int i = 0; i < n; i++) {
string s;
cin >> s;
if(s == "AB") q.push_back(make_pair(0, 1... | 0 |
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
using names... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long a[5][200005];
long long fact[200005];
long long POW(long long b, long long p) {
if (p == 0LL) {
return 1LL;
}
long long x = POW(b, p / 2);
x *= x;
x %= 1000000007;
if (p % 2) {
x *= b;
x %= 1000000007;
}
return x;
}
long long INV(long l... | 2 |
#include<iostream>
using namespace std;
int main()
{
long long n,d;
cin>>n>>d;
int counter=0;
while(n--)
{
long long x,y;
cin>>x>>y;
if(x*x+y*y<=d*d)
counter++;
}
cout<<counter<<endl;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int n;
int dis[605][2];
int dp[605][605];
int pre[605][605];
void print(int a, int b) {
if (a == b) {
printf("()");
return;
}
if (dp[a][b] == 2) {
printf("(");
print(a + 1, b);
printf(")");
} else if (dp[a][b] == 1) {
... | 5 |
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cstring>
#include<iostream>
#include<cstdio>
#include<cstdio>
using namespace std;
#define N 1000000
#define INF 0x3f3f3f3f
#define MOD 998244353
#define LL long long
int rd()
{
LL x=0,f=1;char c=getchar();
while(c<'0'||c>'9'){if(c=='-')f=-1; c=getchar();... | 0 |
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <memory.h>
#include <list>
#include <numeric>
#include <functional>
#include <comple... | 1 |
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#in... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long o = 1e4 + 1;
long long n, m, q, a[o], b[o];
long long qwq(long long x) {
long long s = 0;
for (long long i = 1; i <= n; i++) {
if (1.0 * x * a[i] > b[i] * (m + 100)) return m + 1000;
s += 1 + x * a[i] / b[i];
}
return s;
}
signed main() {
i... | 5 |
#include <bits/stdc++.h>
using namespace std;
int const mx = 200001;
int tmp[mx];
struct node {
int sum, high;
} tree[3 * mx];
int fwt[mx];
int p[mx] = {0};
void init(int node, int b, int e) {
if (b == e) {
tree[node].sum = 1;
tree[node].high = tmp[b];
return;
}
int left = node * 2;
int right = no... | 2 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.