solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int N, M, W;
double a[55][55];
int t[55][55], k[55];
int main(int argc, char *argv[]) {
scanf("%d%d%d", &N, &W, &M);
int i, pos = 0;
double fill = 0, e = (double)W * N / M, rem;
for (i = 0; i < N; i++) {
if (fill + 0.000000001 > e) {
pos++;
fill = 0;... | 2 |
#include <bits/stdc++.h>
using namespace std;
vector<int> v;
int months[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int n, m, head;
string s;
int input(string temp) {
int val;
stringstream sin;
sin << temp;
sin >> val;
return val;
}
int main() {
ios::sync_with_stdio(0);
cin >> n >> m;
getlin... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const int MOD = 1e9 + 7;
const int N = 3000000;
string s;
int n, prev_0[N], prev_1[N], dp[N][2][2][2], dp1[N][2][2][2], k;
void calc() {
prev_0[0] = -1;
prev_1[0] = -1;
if (s[0] == 'B') prev_0[0] = 0;
if (s[0] == 'W') prev_1[0] = 0;
for (int i... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, i, x;
cin >> n >> m;
x = m + n - 1;
cout << x << endl;
for (i = 1; i <= n; i++) cout << i << " " << 1 << endl;
for (i = 2; i <= m; i++) cout << 1 << " " << i << endl;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin>>s;
sort(s.begin(),s.end());
if(s[0]==s[1] && s[1]!=s[2] && s[2]==s[3]){
cout<<"Yes"<<endl;
}
else cout<<"No"<<endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int absol(int x);
int main() {
int n, C, left, right, top, bot;
char c;
int xy[10][2] = {{1, 3}, {0, 0}, {1, 0}, {2, 0}, {0, 1},
{1, 1}, {2, 1}, {0, 2}, {1, 2}, {2, 2}};
cin >> n;
cin >> c;
C = c;
C -= 48;
left = C;
right = C;
top = C;... | 1 |
#include<bits/stdc++.h>
using namespace std;
const int HMAX=100,WMAX=100;
const int m[4][2]={{-1,0},{0,-1},{0,1},{1,0}};
bool p[HMAX][WMAX];
char a[HMAX][WMAX];
int h,w;
void dfs(int x,int y,char l)
{
if(x<0||x>=h)return;
if(y<0||y>=w)return;
if(a[x][y]!=l)return;
if(p[x][y])return;
p[x][y]=true;
for(int i=0;i<... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(NULL);
int n, cnt = 0, ans = 0;
string s;
cin >> n >> s;
for (int i = 0; i < n; i++) {
if (s[i] != '4' and s[i] != '7') {
cout << "NO";
return 0;
} else if (i < n / 2) {
cnt += int(s[i]);
} else ... | 1 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > ans;
void add(int a, int b, int c, int d) { ans.push_back({4, a, b, c, d}); }
void add(int a, int b, int c) { ans.push_back({3, a, b, c}); }
void f(int n) {
if (n == 3) {
add(1, 2, 3);
add(1, 2, 3);
return;
}
if (n == 4) {
add(1, 2... | 5 |
#include <bits/stdc++.h>
using namespace std;
struct vertex {
int zn;
int coun;
int p1;
int sl[10];
int prev;
};
struct number {
int coun;
int ss;
};
int n;
vector<vertex> y(10);
vector<vector<number> > v(70000, vector<number>(9));
vector<vector<int> > res(70000, {-1});
int ost = 0;
int u = 0;
void pruf()... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 10000000000000ll;
typedef pair<long long, int> pa;
int V, E, R;
long long dist[100000];
struct edge{ int s, t, d; };
vector<edge> graph[100000];
int main(){
cin >> V >> E >> R;
for(int i = 0; i < E; i++){
edge e;
cin >> e.s >... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, a[200200];
int main() {
int i, j;
scanf("%d", &n);
for (i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
for (i = 1; i < n; i++) {
if (a[i] % 2) {
a[i] = 1;
if (a[i + 1] == 0) {
cout << "NO";
return 0;
} else {
a... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main(void){
long long A,B,K;
cin >> A >> B >>K;
cout << max(0LL,A - K) <<" "<<max(0LL,B - max(0LL,K - A))<<endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
map<string,int>mp;
map<string,int>::iterator it;
int n,x,y=0,count = 0;
cin>>n;
for(int i=0;i<n;i++)
{
cin>>s>>x;
count+=x;
mp[s]=count;
}
cin>>s;
it=mp.find(s);
if(it!=mp.end()) y = it->second;
cout<<count-y<<endl;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int cond = 1;
const int max_n = 1011;
int f[2][max_n];
pair<string, int> s[2][max_n];
int pos[2][max_n];
int key[2][max_n];
int r[2][max_n];
pair<int, int> t[max_n];
int find(int id, int a) {
if (f[id][a] != a) f[id][a] = find(id, f[id][a]);
return f[id][a];
}
void link... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long int mod = 1000000007;
long long int z = 1000000000;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
long long int n, x;
cin >> n;
vector<long long int> a(n + 1);
long long int ans = -1;
for (int i = 1; i <= (n + 1) / 2; i++) {
cin >> a[i];... | 5 |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pi (3.141592653589)
#define mod 1000000007
#define float double
#define pb push_back
#define sz(x) (int)(x).size()
#define ff first
#define ss second
#define lb lower_bound
#define pq_max priority_queue<int>
#define pq_min priority_queue<int,... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1000005 * 5;
const double eps = 1e-9;
const int INF = 0x3f3f3f3f;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
int kx[] = {1, 1, 2, 2, -1, -1, -2, -2};
int ky[] = {2, -2, 1, -1, 2, -2, 1, -1};
int num[MAX], sum[MAX];
void gen() {
for (int i = 1; i <... | 4 |
#include <bits/stdc++.h>
using namespace std;
int power[] = {0, 2, 3, 5, 7, 13,
17, 19, 31, 61, 89, 107,
127, 521, 607, 1279, 2203, 2281,
3217, 4253, 4423, 9689, 9941, 11213,
... | 5 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
ll a,b,n; cin >> a >> b >> n;
cout << min(n,b-1)*a/b << endl;
} | 0 |
#include <bits/stdc++.h>
int flag;
bool flag2;
int main(void) {
int n;
int num;
char ch;
char* p;
scanf("%d", &n);
getchar();
while (n--) {
flag = 0;
num = 0;
flag2 = 0;
while ((ch = getchar()) != '\n') {
num += ch - '0';
if (flag < 2 && (ch - '0' & 1) == 0) flag++;
if (!... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2010;
int n, m, k, x, y, nx, ny, ans, rot;
int l[N][N], r[N][N];
int _l(int x, int y) {
if (l[x][y] == y) return y;
return l[x][y] = _l(x, l[x][y]);
}
int _r(int x, int y) {
if (r[x][y] == y) return y;
return r[x][y] = _r(x, r[x][y]);
}
void go(int x, ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9;
inline long long read() {
long long X = 0, w = 0;
char ch = 0;
while (!isdigit(ch)) {
w |= ch == '-';
ch = getchar();
}
while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
return w ? -X : X;
}
long long hsh... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
const char* comma = strchr(names + 1, ',');
cerr.write(nam... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
T cross(complex<T> a, complex<T> b) {
return imag(a * conj(b));
}
template <class T>
T min(T a, T b, T c) {
return min(a, min(b, c));
}
template <class T>
T max(T a, T b, T c) {
return max(a, max(b, c));
}
template <class T>
void setmin(T &a, T b) {... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, key[100000];
vector<int> tree[100000];
int l_min[100000], l_max[100000], r_min[100000], r_max[100000];
void dfs1(int u) {
if (tree[u].empty()) {
l_min[u] = l_max[u] = r_min[u] = r_max[u] = key[u];
return;
}
int vl = tree[u][0];
dfs1(vl);
int vr = tr... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 4e6 + 2;
const int inf = 1e9;
int n, m;
pair<int, int> a[maxn];
vector<vector<int> > b;
vector<int> tree[maxn];
int c[maxn];
void build(int v, int ll, int rr) {
if (ll + 1 == rr) {
tree[v].push_back(a[ll].second);
return;
}
build(v * 2 + 1, ll... | 5 |
#include <bits/stdc++.h>
char s1[1000];
char s2[1000];
int len;
int i;
char get(char *s, int i) {
if (s[i] == '[' && s[i + 1] == ']') return 'B';
if (s[i] == '(' && s[i + 1] == ')') return 'K';
if (s[i] == '8' && s[i + 1] == '<') return 'N';
}
int main() {
scanf("%s", s1);
scanf("%s", s2);
len = strlen(s1);... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int weight[100005];
class edge {
public:
int left, right, weight;
edge();
edge(int l, int r, int w) : left(l), right(r), weight(w){};
bool operator<(const edge &a) const { return this->weight > a.weight; }
};
class union_find {
public:
vector<double> p... | 4 |
#include <bits/stdc++.h>
const int mod = 1000000007;
const int maxn = 1000005;
int n;
int prime[maxn], minpf[maxn], minpfpw[maxn], tot = 0;
bool flag[maxn];
int ind[maxn], ind2[maxn];
int cnt[maxn];
int fac[maxn];
int a[maxn];
int ans = 1;
int pos[maxn], pos2[maxn], maxpf[maxn];
void work() {
fac[0] = 1;
for (int i... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int tot[100000];
int cnt = 0;
for (int i = 0; i <= 100; i++) {
for (int j = 0; j <= 100; j++) {
tot[cnt++] = 3 * i + 7 * j;
}
}
while (n--) {
int a;
cin >> a;
int flag = 0;
for (int i = 0; i < cnt; i+... | 1 |
#include <bits/stdc++.h>
using namespace std;
int counter = 0;
int main() {
int a[3][4];
for (int i = 1; i <= 2; i++)
for (int j = 1; j <= 3; ++j) cin >> a[i][j];
for (int i = 1; i <= 3; i++)
if (a[1][i] == a[2][i]) counter++;
if (counter >= 1)
cout << "YES" << endl;
else
cout << "NO" << endl;... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, x, b, y, sum, i, j;
bool flag = false;
scanf("%d %d %d %d %d", &n, &a, &x, &b, &y);
j = b;
for (i = a; i != x && j != y;) {
if (i < n)
i++;
else
i = 1;
if (j > 1)
j--;
else
j = n;
if (i == j) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int n, m, cnt, fa[maxn], sum[maxn], dep[maxn], top[maxn], son[maxn], size[maxn],
tid[maxn << 1], head[maxn], nxt[maxn << 1], to[maxn << 1];
void addline(int u, int v) { nxt[++cnt] = head[u], head[u] = cnt, to[cnt] = v; }
int dfs1(int u, int f)... | 3 |
#include <bits/stdc++.h>
using namespace std;
int acc1[100009];
int acc2[100009];
vector<pair<int, int> > v1, v2;
int n1, n2;
int main() {
int n, v, a, b;
scanf("%d%d", &n, &v);
for (int i = 0; i < n; i++) {
scanf("%d%d", &a, &b);
if (a == 1)
v1.push_back(make_pair(b, i + 1));
else
v2.push... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, c2 = 0, c3 = 0;
cin >> n >> m;
if (n == m)
cout << "0" << endl;
else if (m % n != 0)
cout << "-1" << endl;
else {
m /= n;
while (m > 1) {
if (m % 2 == 0) {
c2++;
m /= 2;
} else
break;
}... | 1 |
#include <iostream>
using namespace std;
int main() {
int n, a, b;
int p[100002] = {};
int res = 0;
cin >> n;
for (int i=0; i<n; i++) {
cin >> a >> b;
p[a]++;
p[b+1]--;
}
for (int i=1; i<100002; i++) {
p[i] += p[i-1];
}
res = 1;
for (int i=1; i<10... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) {
int s, f, t;
cin >> s >> f >> t;
int x = t % (2 * (m - 1));
int y = t - x;
int ans = 0;
if (s == f) {
ans = t;
} else if (s < f) {
if (x <= s - 1) {
ans... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, l, k, a[210], p[210];
bool u[210][210][410];
double d[210][210][410];
double go(int pos, int won, int freeplace) {
freeplace = min(freeplace, 200);
if (pos == n) {
return won >= l && freeplace >= 0 ? 1.0 : 0.0;
}
if (u[pos][won][freeplace + 200]) {
re... | 2 |
#include <bits/stdc++.h>
using namespace std;
double sy, a, b;
double fencel[200005];
double fencer[200005];
double pre[200005];
int main() {
scanf("%lf%lf%lf", &sy, &a, &b);
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%lf%lf", &fencel[i], &fencer[i]);
pre[i + 1] = pre[i] + (fencer[i] -... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, dist[111];
int next(int src) {
if (src == n)
return 1;
else
return src + 1;
}
int get(int s, int t) {
int res = 0, cur = s;
while (1) {
if (cur == t) break;
res += dist[cur];
cur = next(cur);
}
return res;
}
int main(void) {
int s, t... | 1 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
bool get_int(T &x) {
char t = getchar();
bool neg = false;
x = 0;
for (; (t > '9' || t < '0') && t != '-' && t != EOF; t = getchar())
;
if (t == '-') neg = true, t = getchar();
if (t == EOF) return false;
for (; t <= '9' && t >= '0'; ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 500;
const long long mod = 1e9 + 7;
const long long INF = 1LL << 57;
const int M = 1e6 + 500;
const long long int ths = 1LL << 40;
void solve() {
long long int n;
cin >> n;
string s;
cin >> s;
long long int c1 = 0, c2 = 0;
for (int i = 0; i <... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
int n;
cin >> n;
string s;
for (int _ = 0; _ < (int)(n); _++) {
cin >> s;
int len = s.size() - 4;
int t = atoi(s.substr(4).c_str());
int k = 10;
int wow = 0;
for (int p = 1; p < len; p++) {
w... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
int a, x, y;
cin >> a >> x >> y;
if (y % a == 0) {
cout << "-1";
return 0;
}
int h = a / 2;
if (a % 2 == 0) h--;
if (y <= 2 * a) {
if (-h <= x && x <= h) {
if (y > a)
cout << "2";
else
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, u, v;
int val[2000010];
pair<int, int> l[2000010];
int fa[2000010];
bool spe[2000010];
int maxv[2000010], secv[2000010];
int c[5];
int get_fa(int x) {
if (fa[x] == 0) return x;
fa[x] = get_fa(fa[x]);
return fa[x];
}
bool merge(int u, int v) {
u = get_fa(u);
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int pa[400005];
int find(int x) { return !pa[x] ? x : pa[x] = find(pa[x]); }
bool uni(int x, int y) {
int i = find(x), j = find(y);
if (i == j)
return false;
else {
pa[i] = j;
}
return true;
}
int a[400005];
bool b[400005];
int main() {
memset(a, 0, size... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
std::ios_base::sync_with_stdio(0);
cin.tie(NULL);
double vp, vd, t, f, c;
cin >> vp >> vd >> t >> f >> c;
if (vp > vd) {
cout << "0" << endl;
return 0;
}
double i = vp * t;
double baki = c - i;
int cnt = 0;
while (1) {
double tem... | 2 |
#include <bits/stdc++.h>
using namespace std;
char buf[1 << 21], *p1 = buf, *p2 = buf;
inline int read() {
char ch;
bool flag = 0;
int res;
while (!isdigit(
ch = (p1 == p2 &&
(p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)
? EOF
: *p1++)))
... | 2 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
using namespace std;
inline long long in() {
long long x;
scanf("%lld", &x);
return x;
}
long long n;
const long long N = 1e5 + 4;
long long a[N];
long long mn[N];
int32_t main() {
n = in();
for... | 2 |
#include<bits/stdc++.h>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define EPS (1e-7)
#define COUNTER_CLOCKWISE 1
#define CLOCKWISE -1
#define ONLINE_BACK 2
#define ONLINE_FRONT -2
#define ON_SEGMENT 0
#define equals(a,b) (fabs((a)-(b)) < EPS)
using namespace std;
class Point{
public:
dou... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k[15], dif[15];
char s[15][40];
string tmp = "0000000000000000000000000000000000000000";
map<string, int> mp;
void dfs(int p, char c) {
if (p == n + 1) {
for (int i = 1; i <= m; ++i)
if (dif[i] != k[i]) return;
mp[tmp] = 1;
return;
}
if (c ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 4, oo = 1e9 + 7;
int m, n;
pair<int, int> a[N];
struct Interval_Tree {
int node[4 * N], lazy[4 * N];
void Build(int i, int l, int r) {
node[i] = lazy[i] = oo;
if (l == r) return;
int mid = (l + r) / 2;
Build(2 * i, l, mid);
Build(... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<int> v(51, true);
v[0] = false;
v[1] = false;
for (int i = 2; i <= 50; i++) {
for (int j = i * i; j <= 50; j += i) {
v[j] = false;
}
}
for (int i = n + 1; i <= 50; i++) {
if (v[i] && i == m) {
... | 1 |
#include <stdio.h>
int main() {
int H, W, N;
scanf("%d %d %d", &H, &W, &N);
(H > W) ? printf("%d",(N+H-1)/H) : printf("%d",(N+W-1)/W);
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
vector<bool> bb(26, false);
vector<bool> ur(26, false);
vector<bool> id(26, false);
vector<int> v;
string ki = "";
bool im = false;
vector<vector<int> > s(26, v);
void bejar(int x) {
id[x] = bb[x] = true;
for (int i = 0; i < s[x].size(); i++) {
if (id[s[x][i]]) im =... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
int i;
for (i = n; i > n - k; i--) {
cout << i << " ";
}
for (int j = 1; j <= i; j++) {
cout << j << " ";
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
const double EPS = 1e-9;
const int INT_INF = 0x7FFFFFFF;
const long long I64_INF = 0x7FFFFFFFFFFFFFFF;
const double PI = acos(-1.0);
using namespace std;
int n, k;
int a[100500];
long long sum[100500];
long long getsum(int l, int r) { return sum[r + 1] - sum[l]; }
bool can(int l, int r, int val... | 3 |
#include <bits/stdc++.h>
using namespace std;
struct Fenwick {
vector<int> t;
int n;
void init(int nn) {
n = nn;
t.assign(n, 0);
}
int sum(int r) {
int result = 0;
for (; r >= 0; r = (r & (r + 1)) - 1) result += t[r];
return result;
}
void inc(int i, int delta) {
for (; i < n; i = ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 1;
int n, pr[maxn], nx[maxn], sz;
long long a[maxn], res[maxn];
void Enter() {
cin >> n;
for (int i = 1; i <= n; ++i) cin >> a[i];
}
void Init() {
sort(a + 1, a + n + 1);
sz = res[0] = pr[0] = nx[0] = 0;
}
bool GetBit(long long s, int bit) { r... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, n, m, i, x;
x = 0;
scanf("%d%d", &n, &m);
for (i = 0; i < n; i++) {
scanf("%d%d", &a, &b);
if (x >= a && x < b) x = b;
}
if (x >= m)
printf("YES\n");
else
printf("NO\n");
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a1, b1, a2, b2, p1, p2, tp1, tp2;
cin >> a1 >> b1 >> a2 >> b2;
p1 = a1 * b1;
p2 = a2 * b2;
int p31 = 0, p32 = 0, ans = 0;
tp1 = p1;
while (tp1 % 3 == 0) p31 += 1, tp1 /= 3;
tp2 = p2;
while (tp2 % 3 == 0) p32 += 1, tp2 /= 3;
ans += ... | 4 |
#include<bits/stdc++.h>
using namespace std;
int main() {
int n; cin >> n;
int a[n];
for (int i = 0; i < n; i++)
{
cin >> a[i];
a[i]--;
}
int res = 0;
for (int i = 0; i < n; i++)
{
if(a[a[i]] == i) res++;
}
cout << res / 2 << endl;
return 0;
}
| 0 |
#include<iostream>
#include<cstdio>
#define MN 200000
using namespace std;
inline int read()
{
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int n,T,a[MN+5],f[MN+5],pos[MN+5];
bool Check(int a,int b,int c){retur... | 0 |
#include<bits/stdc++.h>
using namespace std;
int main()
{
char a,b,c;
scanf("%c %c %c",&a,&b,&c);
if(a!=b&&a!=c&&b!=c)
printf("Yes");
else
printf("No");
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
vector<pair<int, int>> v;
priority_queue<int, vector<int>, greater<int>> pq;
long long int sm = 0;
void add(int x) {
pq.push(x);
sm += x;
if (pq.size() <= k) {
return;
} else {
while (pq.size() > k) {
sm -= pq.top();
pq.pop();
}
}... | 3 |
#include <bits/stdc++.h>
using namespace std;
int m, t, r, j, tot, s, a[310], b[310];
int main() {
cin >> m >> t >> r;
for (int i = 0; i < m; i++) {
cin >> a[i];
while (a[j] + t < a[i]) {
tot -= b[j++];
}
tot += b[i] = !i ? r : max(0, r - tot + max(0, b[j] - a[j] + a[i] - t));
s += b[i];
... | 3 |
#include<iostream>
#include<iomanip>
//#include<cstdio>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
const int Nmax = 1e5;
const int P = 1e9+7;
int N, X;
int S[Nmax];
int main(){
cin >> N >> X;
for(int i=0; i<N; i++) c... | 0 |
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
#define MAXN 55
#define EPS 1e-6
#define g 9.8
#define PI acos(-1)
struct Obstacle
{
int l;
int r;
int t;
int b;
} ob[MAXN];
int n,v,tx,ty;
double a,b,c;
void getabc(double angle)
{
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
const long long LLINF = 9223372036854775807;
const int maxn = 100010;
int xors[maxn] = {0};
int grundy[maxn] = {0};
bool mex[maxn] = {0};
int tres[maxn] = {0};
bool calc(int d1, int d2, pair<int, int> &r) {
int b = d1 + d2 - 1;
if (b & 1) ret... | 3 |
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);
#define int long long
#define endl '\n'
const int mod = 1e9 + 7;
const int inf = 1e18 + 9;
const int N = 1e7 + 5;
bool isPrime[N];
vector<int> primes;
void sieve() {
memset(isPrime, true, sizeof isPrime);
isPrime[1... | 2 |
#include <bits/stdc++.h>
const int lim = 10000000;
int p[lim];
int cont[lim];
int n, k, inp;
int main() {
for (int i = 2; i * i < lim; i++) {
if (!p[i]) {
for (int x = i * i; x < lim; x += i) {
p[x] = 1;
}
}
}
scanf("%d %d", &n, &k);
for (int i = 0; i < n; i++) {
scanf("%d", &inp... | 5 |
#include <bits/stdc++.h>
using namespace std;
bool anagram(char *s1, char *s2) {
long long int count[256];
memset(count, 0, sizeof(count));
long long int i;
for (i = 0; s1[i] && s2[i]; i++) {
count[s1[i]]++;
count[s2[i]]--;
}
if (s1[i] || s2[i]) {
return false;
}
for (long long int i = 0; i ... | 4 |
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
template<typename A,typename B>inline ... | 0 |
#include <bits/stdc++.h>
using namespace std;
vector<int> par[4010];
pair<int, int> ver[4020];
bool f[4010];
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
for (int i = 0; i < (m); i++) {
int a, b;
cin >> a >> b;
a--;
b--;
par[a].push_back(b);
par[b].pus... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c;
while (scanf("%d%d%d", &a, &b, &c) != EOF) {
int d = b - a;
if (d == 0) {
printf("YES\n");
} else if (d > 0) {
if (c > 0) {
if (d % c == 0)
printf("YES\n");
else
printf("NO\n");
... | 1 |
#include<bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,(n))
typedef long long ll;
using namespace std;
int h, w, dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
string s[400];
bool visited[400][400];
ll ans, bk, wt;
void dfs(int sy, int sx, bool isWhite) {
visited[sy][sx] ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<pair<string, string> > p;
string s1, s2;
int i, j, n;
bool t;
cin >> n;
for (i = 1; i <= n; i++) {
t = true;
cin >> s1 >> s2;
for (j = 0; j < p.size(); j++) {
if (p[j].second == s1) {
t = false;
p[j].second =... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k;
int s[1000005];
long long a[1000005];
int head[1000005];
int main() {
memset(s, 0, sizeof(s));
memset(a, 0, sizeof(a));
scanf("%d%d%d", &n, &m, &k);
int tmp;
for (int i = 1; i <= m; i++) {
scanf("%d", &tmp);
s[tmp] = 1;
}
for (int i = 1; i... | 5 |
#include <bits/stdc++.h>
using namespace std;
vector<int> G[200005];
bool V[200006] = {0};
int S[200006] = {0};
int n;
long long d = 0, mx = 0;
void dfs(int p) {
V[p] = 1;
d++;
int u = 0;
for (int i = 0; i < G[p].size(); i++) {
int cp = G[p][i];
if (!V[cp]) {
dfs(cp);
u++;
}
}
if (!u... | 3 |
#include<bits/stdc++.h>
using namespace std;
int f(vector<vector<int> > &e, int u, int d, int l, int r){
int res = 0;
int hight = 10;
for(int i = u; i <= d; i++){
hight = min(hight, e[i][l]);
hight = min(hight, e[i][r]);
}
for(int j = l; j <= r; j++){
hight = min(hight, e[... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long mM(long long a, long long b, long long mod) {
long long res = 0;
a %= mod;
while (b) {
if (b & 1) res = (res + a) % mod;
a = (2 * a) % mod;
b >>= 1;
}
return res;
}
long long fpow(long long first, long long second, long long p = 1000000007) {... | 3 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("arch=sandybridge")
#pragma GCC target("popcnt")
#pragma comment(linker, "/STACK:16777216")
const long double pi = 3.14159265;
const long long MOD = 1e9 + 7;
const long long INF = LLONG_MAX;
long long gcd(long long a, long long b) {
if (b == 0) return a... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
scanf("%d%d", &(n), &(m));
--n, --m;
int l1 = 0, l2 = 0, n1 = n, n2 = m;
while (n1) {
n1 /= 7;
++l1;
}
l1 = max(l1, 1);
while (n2) {
n2 /= 7;
++l2;
}
l2 = max(l2, 1);
if (l1 + l2 > 7) {
printf("0\n");
retu... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, *dp[5001], *sum[5001];
char s[5001];
int fun(int pos, int level) {
if (dp[pos][level]) return dp[pos][level];
if (pos == n) {
dp[pos][level] = 1;
return 1;
}
int ans = 0;
if (s[pos] == 'f')
ans = fun(pos + 1, level + 1);
else
ans = sum[pos... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e2 + 5;
const int M = 1e3 + 5;
const int mod = 1e9 + 7;
int n, m, a[N], now, tot;
double dp[2][N * M], sum[N * M], kk, ans = 1;
inline int read() {
int x = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getc... | 3 |
#include <bits/stdc++.h>
int h, w, k, x1, yy1, x2, y2, d[4] = {1,-1}, mp[3000005], qu[1000005], b, e, inf=1e9;
int main(){
scanf("%d%d%d", &h, &w, &k); w++;
scanf("%d%d%d%d", &x1, &yy1, &x2, &y2);
memset(mp,-1,sizeof(mp));
for(int i=0; i<h*w; i++) if(getchar() == '.') mp[i+w] = inf;
mp[qu[e++] = x1*w+yy1] = 0;
d[... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main(){
long long N;
cin >> N;
vector<long long> A(N);
for(int i=0;i<N;i++) cin >> A[i];
map<long long,long long> M;
long long ans=0;
for(int i=0;i<N;i++){
ans += M[i-A[i]];
M[i+A[i]]++;
}
cout << ans << endl;
return 0;
}
| 0 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int read(){
int r=0,f=1;
char c=getchar();
while(c<48||c>57){if(c=='-')f=-1;c=getchar();}
while(c>=48&&c<=57)r=r*10+(c&15),c=getchar();
return r*f;
}
const int N=1e5+10;
int n,m,k,mt,tot;
char a[5];
int c[N*4][27],ed[N*4],d[N],q[N];
bool fl... | 5 |
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
while(1) {
string a, str;
cin >> a;
if(a=="#")break;
for(int i=0;i<a.size();i++)
if(a[i] == 'w' || a[i] == 'n' ) str += a[i];
int size = str.size();
int ans = 0;
for(int i=0;i<size;i++)
... | 0 |
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
using namespace std;
#define FOR(i,k,n) for(int i=(k); i<(int)n; +... | 0 |
#include <bits/stdc++.h>
using namespace std;
struct Rect {
int x1, y1, x2, y2;
long long area() { return (long long)(x2 - x1) * (y2 - y1); }
};
long long intersect(const Rect&, const Rect&);
Rect intersectingRect(const Rect&, const Rect&);
int main() {
Rect white, black1, black2, b1Inside, b2Inside;
long long ... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long md = 1e9 + 7;
long long n, a[4];
long long pow(long long a, long long b) {
return b ? (pow((a * a) % md, b / 2) * (b % 2 ? a : 1)) % md : 1;
}
int main() {
cin >> n;
string s;
cin >> s;
for (int i = 0; i < n; i++) {
if (s[i] == 'A')
a[0]+... | 3 |
#include <bits/stdc++.h>
using namespace std;
char c[1005][1005];
int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0}, d[1005][1005],
vis[1005][1005];
int main() {
int n, m, x, y, a, b;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> c[i][j];
if (c[i][j] == 'E'... | 2 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int i,j,k,n,m,t;
ll a[400500],res,sb;
int main(){
scanf("%d",&t);
while(t--){
res=0;
scanf("%d",&n);
for(i=1;i<=n;i++){
scanf("%lld",&a[i]);
}
a[n+1]=0;
for(i=1;i<=n;i++){
sb=max(a[i-1],a[i+1]);
if(sb<=a[i]){
res+=a[i]-sb;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int query(int x, int y) {
if (x == -1) return 0;
cout << 1 << ' ' << x << ' ' << y << endl;
fflush(stdout);
string ret;
cin >> ret;
return ("TAK" == ret);
}
int get(int l, int r) {
if (l > r) return -1;
while (l < r) {
int m = (l + r) / 2;
if (query(... | 2 |
#include <bits/stdc++.h>
const int inf = 1 << 30;
const long long llinf = 1ll << 60;
using namespace std;
const int MAXN = 100000 + 5;
const int MAXE = MAXN * 2;
int n, m;
int to[MAXE], nxt[MAXE], head[MAXN], ne = 0;
int col[MAXN];
void inline ae(int f, int t) {
to[++ne] = t;
nxt[ne] = head[f];
head[f] = ne;
}
bo... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 1;
long long int power(long long int x, long long int y, long long int p) {
long long int temp;
if (y <= 0) return 1;
temp = power(x, y / 2, p);
if (y % 2 == 0) {
return (temp * temp) % p;
} else {
return (((x * temp) % p) * temp) % p;
... | 2 |
#include <iostream>
using namespace std;
int a, b, c;
int gcd(int x, int y){
int t;
if( x < y ){
t = y;
y = x;
x = t;
}
while( y ){
t = x%y;
x = y;
y = t;
}
return x;
}
int abs(int x){
return x<0?-x:x;
}
int main(){
cin >> a >> b >> c;
... | 0 |
#include<stdio.h>
#include<algorithm>
#include<functional>
using namespace std;
int main(void)
{
int n,i,e,h[65000];
unsigned int x,z,a,w;
while(1){
w=0;
scanf("%d",&n);
if(n==0) break;
for(i=0;i<n;i++){
scanf("%d",&e);
w+=e;
}
for(i=0;i<n-1;i++){
scanf("%d",&h[i]);
}
sort(h,h+n-1,greater<... | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.