solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
struct Move {
int x1, y1;
int x2, y2;
int x3, y3;
Move(int _x1, int _y1, int _x2, int _y2, int _x3, int _y3) {
x1 = _x1;
x2 = _x2;
x3 = _x3;
y1 = _y1;
y2 = _y2;
y3 = _y3;
}
};
vector<Move> solution[4][4][512];
vector<Move> ans;
string f[200... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, n;
cin >> a >> b >> n;
a *= 10;
int aa = (a % b);
aa = ((b - aa) % b + b) % b;
if (aa <= 9) {
a += aa;
cout << a;
for (int i = 1; i <= n - 1; i++) putchar('0');
} else
cout << -1 << endl;
}
| 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string str;
string word = "hello";
int k = 0;
cin >> str;
for (int idx = 0; idx < str.size(); idx++) {
if (str[idx] == word[k]) {
k++;
}
}
if (k == 5) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
return 0;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
pair<int, int> s[100001];
long long dp[100001];
int main() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= m; ++i) {
scanf("%d%d", &s[i].first, &s[i].second);
}
sort(s + 1, s + m + 1, [](pair<int, int> a, pair<int, int> b) {
ret... | 9 |
#include <bits/stdc++.h>
using namespace std;
int m, n;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> m >> n;
string s, t;
cin >> s;
cin >> t;
int wildcard = -1;
int yes = 1;
for (int i = 0; i < m; ++i)
if (s[i] == '*') wildcard = i;
if (!~wildcard && s != t) yes = 0;
for (int i... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 100;
int x[MAXN], y[MAXN];
int main() {
int n;
cin >> n;
map<int, int> mx, my;
map<pair<int, int>, int> mps;
for (int i = 0; i < n; ++i) {
scanf("%d%d", &x[i], &y[i]);
if (!mx.count(x[i]))
mx[x[i]] = 1;
else
mx[x[i]]+... | 6 |
#include <bits/stdc++.h>
using namespace std;
bool Q;
struct Line {
mutable long long k, m, p;
bool operator<(const Line& o) const { return Q ? p < o.p : k < o.k; }
};
struct LineContainer : multiset<Line> {
const long long inf = LLONG_MAX;
long long div(long long a, long long b) {
return a / b - ((a ^ b) <... | 16 |
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> vals;
int main() {
int a, b, c, d, u, v, w, k;
scanf("%d%d%d%d%d%d", &n, &k, &a, &b, &c, &d);
if (n == 4 || k < n + 1) {
printf("-1\n");
return 0;
}
for (int i = 1; i <= n; i++) {
if (i != a && i != b && i != c && i != d) vals.push_b... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s, s1;
map<string, int> mp;
mp["monday"] = 1;
mp["tuesday"] = 2;
mp["wednesday"] = 3;
mp["thursday"] = 4;
mp["friday"] = 5;
mp["saturday"] = 6;
mp["sunday"] = 7;
cin >> s >> s1;
int temp = mp[s1] - mp[s];
if (temp >= 0) {
if (... | 2 |
#include <bits/stdc++.h>
const double eps = 1e-10;
using namespace std;
int zzz = 0;
const int NN = 100022;
vector<pair<long long, long long>> cr;
map<pair<int, int>, int> mp;
int N, M, L;
long long answ;
set<int> st;
bool isOn(int x, int y) { return mp.count({x, y}) && mp[{x, y}] != -1; }
bool check(int x, int y) {
... | 13 |
#include <bits/stdc++.h>
using namespace std;
constexpr int MOD = 1e9 + 7;
constexpr int INF = INT32_MAX;
constexpr int MAXN = 2e6 + 10;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
using Vec = vector<int>;
template <class T>
void Min(T &a, T &b) {
if (b < a) a = b;
}
template <class T>... | 17 |
#include <bits/stdc++.h>
using namespace std;
long long num[100002];
set<long long> s;
int main() {
long long n, k;
cin >> n >> k;
for (int i = 0; i < n; i++) cin >> num[i];
sort(num, num + n, greater<long long>());
for (int i = 0; i < n; i++) {
long long x = num[i];
if (s.find(x * k) == s.end()) s.in... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
int x[110], y[110], s[110];
long long c[1100][1100];
long long dp[110][1100];
int n, p;
inline void upd(long long &x, long long y) {
y %= mod;
x += y;
x %= mod;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", x ... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, k, l, n, m;
char b[1100], c;
while (~scanf("%d%d", &n, &m)) {
cin >> b;
l = 0;
int a[1100] = {0};
for (i = 0; i < strlen(b); ++i) {
++a[b[i]];
if (a[b[i]] > m) {
l = 1;
break;
}
}
if (l =... | 1 |
#include <bits/stdc++.h>
template <class T>
inline void rd(T &x) {
char c = getchar(), f = 0;
x = 0;
while (!isdigit(c)) f = (c == '-'), c = getchar();
while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
x = f ? -x : x;
}
const int MAXN = 1e5 + 7;
int n, a, b, ts;
int f[MAXN], g[MAXN], fa[MAXN][20], dfn[M... | 22 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
int a[n], b[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
b[i] = a[i];
}
sort(b, b + n);
int c = 0;
for (int i = 0; i < n; i++) {
if (a[i] != b[i]) {
c++;
}
}
i... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
long long n, k;
long long f(long long n) {
if (n == 1) return 1;
long long res = n;
for (long long m = 2; m * m <= n; ++m)
if (n % m == 0) {
res = res / m * (m - 1);
while (n % m == 0) n /= m;
}
if (n > 1) res = res / n *... | 13 |
#include <bits/stdc++.h>
using namespace std;
int Set(int N, int pos) { return N = N | (1 << pos); }
int reset(int N, int pos) { return N = N & ~(1 << pos); }
bool check(int N, int pos) { return (bool)(N & (1 << pos)); }
int cas = 1;
int dxx[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dyy[] = {-1, 0, 1, -1, 1, -1, 0, 1};
int ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 2e9 + 5, N = 2e5 + 5, mod = 1e9 + 7, M = 1e6 + 5;
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int n;
cin >> n;
int a[n + 1];
map<int, int> cnt;
for (int i = 1; i <= n; i++) {
cin >> a[i];
cnt[a[i]]++;
}
i... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000010;
int p[N], a[N], ll[N], lr[N], rr[N], f[N];
int ta, tp, n;
char s[N];
void spe() {
int t1 = 0, t2 = 0;
for (int i = 1; i <= ta; ++i)
if (a[i] < p[1])
++t1;
else
++t2;
if (t1 > t2 || (t1 == t2 && p[1] - a[1] < a[ta] - p[1]))
... | 17 |
#include <bits/stdc++.h>
int main() {
int x;
while (scanf("%d", &x) != EOF) {
printf("%d\n", (x / 2) * ((x + 1) / 2));
for (int i = 1; i <= x / 2; i++)
for (int j = 1 + x / 2; j <= x; j++) printf("%d %d\n", i, j);
}
return 0;
}
| 11 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "unroll-loops", "omit-frame-pointer", "inline")
#pragma GCC option("arch=native", "tune=native", "no-zero-upper")
#pragma GCC target("avx2")
using namespace std;
const long long INF = 2e9, INFLL = 1e18, MOD = 1e9 + 7;
vector<long long> t;
void update(long long x, l... | 16 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int64_t n;
cin >> n;
int64_t a[n], b[n];
for (auto& xy : a) cin >> xy;
for (auto& xy : b) cin >> xy;
vector<pair<int64_t, int64_t>> v;
for (int64_t i = 0; i < n; ++i) {
if (a[i] != b[i]) {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int deg[maxn], mn[maxn], MN[maxn];
vector<int> adj[maxn];
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
fill(mn, mn + n, n);
fill(MN, MN + n, n);
for (int i = 0; i < m; i++) {
int v, u;
cin... | 18 |
#include <bits/stdc++.h>
const int N = 105;
int n, m, x, y;
long long k, pos[N][N];
using namespace std;
int main() {
cin >> n >> m >> k >> x >> y;
int i, j;
if (n == 1) {
for (j = 1; j <= m; j++) pos[1][j] = k / m;
k %= m;
for (j = 1; j <= m && k; j++) pos[1][j]++, k--;
} else {
for (i = 1; i <... | 9 |
#include <bits/stdc++.h>
using namespace std;
struct lvl {
int on, tw;
int number;
bool operator<(const lvl &a) const { return tw < a.tw; }
};
struct SumKMin {
set<pair<int, int> > kmin;
set<pair<int, int> > other;
int k = 0;
long long sm = 0;
void insert(const pair<int, int> &d) {
if (((int)kmin.si... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
int mp[8][8];
map<string, int> f;
int main() {
int n, i, j, k, a, b, c;
f["Anka"] = 1;
f["Chapay"] = 2;
f["Cleo"] = 3;
f["Troll"] = 4;
f["Dracul"] = 5;
f["Snowy"] = 6;
f["Hexadecimal"] = 0;
int mind, maxp;
while (cin >> n) {
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, b, c, d;
long long ans = 0;
cin >> n >> a >> b >> c >> d;
for (int x = 1; x <= n; ++x) {
int k = a + x - d;
int z = c + k - b;
int y = z + d - a;
if (k > 0 && k <= n && z > 0 && z <= n && y > 0 && y <= n) ans = ans + n;
}
c... | 6 |
#include <bits/stdc++.h>
using namespace std;
string x;
bool check(int a) {
if (a < 10) {
if (x.find(char(a + '0')) != -1) return true;
return false;
} else if (a < 100) {
int f = x.find(char(a / 10 + '0'));
if (f == -1) return false;
int s = x.find(char(a % 10 + '0'), f + 1);
if (s == -1) r... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, k;
cin >> n >> k;
int arr[n];
for (int i = 0; i < n; i++) cin >> arr[i];
int peeks[n];
peeks[0] = 0;
int sumOfPeeks = 0;
for (int i = 1; i < n - 1; i++) {
if (arr[i] > arr[i - 1] ... | 5 |
#include <bits/stdc++.h>
const long double eps = 0.0000000001;
using namespace std;
long double f[5000 + 5][205][2], ans;
struct Tank {
int hp;
int dt;
int l, r;
double p;
inline long long readLL() {
long long x = 0;
int zf = 1;
char ch = ' ';
while (ch != '-' && (ch < '0' || ch > '9')) ch = g... | 16 |
#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... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
long long memo[112345][3];
long long solve(int x, int rep) {
if (x == 0) return 1;
long long& p = memo[x][rep];
if (p + 1) return p;
if (rep == 1)
p = solve(x - 1, 0);
else if (rep == 0)
p = solve(x - 1, 0) + solve(x - 1, 1);... | 9 |
#include <bits/stdc++.h>
int main(void) {
int n, s;
scanf("%d %d", &n, &s);
int ara[n], big = 0, total = 0, i;
for (i = 0; i < n; i++) {
scanf("%d", &ara[i]);
total = total + ara[i];
if (ara[i] > big) {
big = ara[i];
}
}
if ((total - big) > s) {
printf("NO");
} else {
printf(... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e3 + 5;
const int INF = INT_MAX / 3;
long long bit[MAX][MAX];
void update(int x, int y, long long val) {
x++;
y++;
for (; x < MAX; x += x & -x)
for (int ty = y; ty < MAX; ty += ty & -ty) bit[x][ty] += val;
}
long long get(int x, int y) {
x++;
... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long int t, x, y, xm, ym;
char c;
cin >> t;
cin >> c >> x >> y;
if (y > x) swap(x, y);
xm = x;
ym = y;
t--;
while (t--) {
cin >> c >> x >> y;
if (y > x) swap(x, y);
if (c... | 7 |
#include <bits/stdc++.h>
using namespace std;
int arr[5002];
int xorr[5002][5002], dp[5002][5002];
int main() {
int n, i, j, q, l, r;
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
while (cin >> n) {
for (i = 0; i < n; i++) cin >> arr[i];
for (i = 0; i < n; i++) xorr[i][i] = arr[i];
for (i = 0; i <... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long FloorSqrt(long long x) {
long long L = 1, R = 708, M;
while ((L + 1) ^ R) {
M = (L + R) >> 1;
if (M * M <= x)
L = M;
else
R = M;
}
return L;
}
struct Node {
long long A[710];
long long B[710];
long long Add, N;
void Sort() {... | 17 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using PP = pair<ll, P>;
const ll n_ = 2e5 + 100, inf = 1e18 + 1, mod = 1e9 + 7, sqrtN = 333, p = 27;
ll dy[4] = {-1, 0, 1, 0}, dx[4] = {0, 1, 0, -1};
ll n, m, k, tc = 1, a, b, c, sum, x, y, z, w, base, ans;
ll gcd(ll x, ll y) {
... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int Mod = 1000000007;
char s[2005], e[2005];
long long dp[100005][2];
int len, k;
bool judge(int st, int ed) {
for (int i = st, j = 1; i <= ed; i++, j++) {
if (s[i] != e[j]) return 0;
}
return 1;
}
int main() {
memset(dp, 0, sizeof(dp));
scanf("%s%s%d", ... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string str;
cin >> str;
int space = 0;
for (int i = 1; i < str.length(); i += 3) {
if (str[i] != '/') {
for (int i = 0; i < space; i++) cout << " ";
cout << "<" << str[i] << ">\n";
space += 2;
} else {
space -= 2;
f... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2002;
int n, k, ans;
char ch[N];
int sumR[N][N], sumC[N][N];
int eR[N][N], eC[N][N];
int ansR[N][N], ansC[N][N];
void read(int& x) {
x = 0;
bool y = 1;
char ch = getchar();
if (ch == '-') y = 0;
while (!(ch >= '0' && ch <= '9')) {
ch = getchar();... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
long long a = 0, b = 1;
long ans = 0;
while (1) {
long long c = a + b;
if (c > n) break;
ans++;
a = b;
b = c;
}
printf("%lld\n", ans - 1);
}
| 8 |
#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void ZZ(const char* name, Arg1&& arg1) {
std::cerr << name << " = " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void ZZ(const char* names, Arg1&& arg1, Args&&... args) {
const char* comma = strchr(names + 1, ',');
std::cerr.w... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, m, x[1005];
double f[1005][1005], ans;
int ta, tb;
int main() {
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++) scanf("%d", x + i);
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) f[i][j] = x[i] < x[j];
while (m--) {
scanf("%d%d", &ta, &tb)... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int Maxn = 1000005;
int dep[Maxn], maxi[Maxn][23], anc[Maxn][23], cnt, head[Maxn], n, m, fa[Maxn];
bool choose[Maxn];
int get_fa(int x) { return x == fa[x] ? x : fa[x] = get_fa(fa[x]); }
void merge(int x, int y) {
int a = get_fa(x), b = get_fa(y);
fa[a] = b;
}
str... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5;
int main() {
char s[1000];
gets(s);
int len = strlen(s);
int i;
for (i = 0; i < len; i++)
if (s[i] == '1') break;
int sum = 0;
for (int j = i + 1; j < len; j++) {
if (s[j] == '0') sum++;
if (sum >= 6) break;
}
if (sum >= ... | 2 |
#include <bits/stdc++.h>
const long long mod = 1e9 + 7;
using namespace std;
int main() {
long long m, n;
cin >> n >> m;
long long temp = 1, sum = m * 2 % mod;
for (int i = 2; i <= n; i++) {
temp = temp * m % mod;
sum = (sum * (2 * m - 1) % mod + temp + mod) % mod;
}
cout << sum << endl;
return 0;... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int a[maxn];
int dp[105][maxn];
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int n, k, p;
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int k = 1; k <= 100; k++) {
for (int p = n; p >= 1; p--) {
if (a[p] + p... | 12 |
#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1e3 + 33;
vector<long long> adj[MAXN];
long long szt[MAXN], mark[MAXN], c[MAXN];
vector<pair<long long, long long> > ve[2];
long long n, m, k, ans = -1, cnt = 0;
inline void dfs(long long u) {
mark[u] = true;
szt[u] = 1;
for (__typeof((adj[u]).b... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
vector<int> v(n, -1);
int curr = 1;
int currelement = 0;
vector<string> vs(n);
for (int i = int(0); i <= int(n - k); i++) {
cin >> vs[i];
}
for (int i = int(0); i <= int(k - 1); i++) {
v[currelement++] = curr++... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long int fast_exp(long long int a, long long int b) {
if (a == 0) return 0;
if (b == 0) return 1;
if (b == 1) return a;
if (b % 2 == 0) {
return fast_exp(((a % 1000000007) * (a % 1000000007)) % 1000000007, b / 2) %
1000000007;
}
return ((a % ... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
int n;
char l[N];
char r[N];
int pw10[N];
struct data {
int ans;
int lft;
int rgt;
int cnt;
int sum;
bool pos;
data(bool _pos = 0) {
ans = 0;
lft = 0;
rgt = 0;
sum = 0;
cnt = _pos;
pos = _... | 20 |
#include <bits/stdc++.h>
using namespace std;
long long sum_mod(long long a, long long b) { return (a + b) % 1000000007; }
long long subtract_mod(long long a, long long b) {
return (a % 1000000007 - b % 1000000007 + 1000000007) % 1000000007;
}
long long multiply_mod(long long a, long long b) {
return (a % 100000000... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
std::string NumberToString(T Number) {
std::ostringstream ss;
ss << Number;
return ss.str();
}
long long StringToNumber(string ch) {
stringstream ss(ch);
long long f;
ss >> f;
return f;
}
long long power(int x, int y) {
if (y == 0) retu... | 2 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long int a, b, c;
cin >> a >> b >> c;
long long int x = ceil(a * c * 1.0 / 100);
x -= b;
if (x < 0) x = 0;
cout << x << endl;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
;
long long int t;
solve();
return 0;
}
| 1 |
#include <bits/stdc++.h>
const int N = 1e5 + 10;
using namespace std;
map<string, int> f;
vector<string> vec[N];
int d[N], _count[N];
string a[N];
int n;
vector<pair<int, int> > res;
string make_hash(int m) {
string ret;
for (int i = 0; i < m - 1; i++) {
ret += a[i];
ret += ",";
}
ret += a[m - 1];
ret... | 16 |
#include <bits/stdc++.h>
using namespace std;
const long double eps = 1e-7;
const long long int m = 1000000007;
void solve() {
int n;
cin >> n;
vector<int> v(n);
for (int i = 0; i < n; i++) cin >> v[i];
sort(v.begin(), v.end());
for (int i = 0; i < n - 1; i++) {
if ((v[i + 1] - v[i]) % 2 == 0)
con... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
long long int i, j, k, n, m;
vector<long long int> a(4);
for (i = 0; i < 4; i++) {
cin >> a[i];
}
sort(a.begin(), a.end());
cout << a[3] - a[0] << " " << a[3] - a[1] << " " << a[3] - a[... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long sqr(long long x) { return x * x; }
int mysqrt(long long x) {
int l = 0, r = 1e9 + 1;
while (r - l > 1) {
int m = (l + r) / 2;
if (m * (long long)m <= x)
l = m;
else
r = m;
}
return l;
}
mt19937 rnd(1227);
mt19937_64 rndll(12365);
lo... | 25 |
#include <bits/stdc++.h>
using namespace std;
map<int, int> memo;
int recur(int n) {
if (n < 5) return memo[n];
if (n % 2 == 1) return 0;
if (memo[n]) return memo[n];
if (recur(n / 2) == 1) return memo[n] = 2;
return memo[n] = 1;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
memo[0] = 0;
mem... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
double x[101], t[101];
int n;
int pos;
double xu, yu, vb, vs, min;
cin >> n >> vb >> vs;
for (int i = 1; i <= n; i++) cin >> x[i];
cin >> xu >> yu;
for (int i = 1; i <= n; i++)
t[i] = x[i] / vb + sqrt((x[i] - xu) * (x[i] - xu) + yu * yu) / v... | 4 |
#include <bits/stdc++.h>
using namespace std;
int d2x[] = {1, -1, 0, 0, 1, -1, 1, -1};
int d2y[] = {0, 0, 1, -1, 1, -1, -1, 1};
int d3x[] = {1, -1, 0, 0, 0, 0};
int d3y[] = {0, 0, 1, -1, 0, 0};
int d3z[] = {0, 0, 0, 0, 1, -1};
struct edge {
int from, to, w;
edge(int from, int to, int w) : from(from), to(to), w(w) {... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5.1e5;
const int MOD = (int)(1e9) + 7;
long long C[MAXN];
map<long long, vector<vector<int>>> graphs;
map<long long, int> cnt_of;
map<long long, unordered_map<int, int>> compress;
void dfs(vector<vector<int>>& graph, int node, vector<bool>& vis) {
if (vis... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
list<int> adj_list[n + 1];
bool vis[n + 1];
for (int i = 1; i <= n; i++) vis[i] = false;
int level[n + 1];
int num[n + 1];
for (int i = 1; i <= n; i++) num[i] = 0;
for (int ... | 7 |
#include <bits/stdc++.h>
int A[40][40][40][40];
int main() {
int n, m, q;
while (scanf("%d%d%d", &n, &m, &q) == 3) {
for (int i = 0; i < 40; i++) {
for (int j = 0; j < 40; j++) {
for (int k = 0; k < 40; k++) {
for (int p = 0; p < 40; p++) {
A[i][j][k][p] = -1;
}
... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 2020202020;
vector<vector<int>> G;
void bridge_dfs(int now, int from, vector<pair<int, int>> &bridge,
vector<vector<int>> &bicomp, stack<int> &roots, stack<int> &S,
vector<bool> &inS, vector<int> &preord, int &pre_ct) {
preo... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
string str;
cin >> str;
int j = 0;
while (k) {
if (j == n - 1) break;
if (str[j] != '4' || str[j + 1] != '7') {
++j;
continue;
}
if (j != n - 2 && str[j + 2] == '7' && k >= 2 && (j % 2 == 0)) {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n, s;
struct seg {
int v, t, x1, y1, x2, y2;
} a[101][101];
int gs[101];
int ans = 0;
int tt[1001], tgs = 0;
int main() {
int i, j, k, ii, jj;
scanf("%d%d", &n, &s);
for (i = 1; i <= n; i++) {
scanf("%d", &gs[i]);
for (k = 1; k <= gs[i]; k++) {
sca... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> v(n);
vector<int> v1(n);
for (int i = 0; i < n; ++i) {
cin >> v[i];
v1[i] = v[i];
}
sort(v.begin(), v.end());
int res = 0;
for (int i = 0; i < n; ++i) {
if (v1[i] != v[i]) {
++res;
}
}
if ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a[200005], b[200005];
int n, i, s = 1, x;
cin >> n;
for (i = 1; i <= n; i++) {
cin >> x;
a[x]++;
b[a[x]]++;
if (a[x] * b[a[x]] == i && i != n)
s = i + 1;
else if (a[x] * b[a[x]] == i - 1)
s = i;
}
cout << s << end... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, b;
cin >> n >> b;
++b;
queue<long long> q;
vector<long long> t(n);
vector<long long> d(n);
for (int i = 0; i < n; ++i) {
cin >> t[i] >> d[i];
}
for (int i = 0; i < n; ++i) {
while (q.size() && q.front() <= t[i]) {
q.pop();... | 9 |
#include <bits/stdc++.h>
using namespace std;
int dfs(int i, int ar[], int visited[]) {
visited[i] = 1;
if (visited[ar[i]] != 1)
return dfs(ar[i], ar, visited);
else
return ar[i];
}
int main() {
int n;
cin >> n;
int ar[n + 1];
for (int i = 0; i < n; ++i) cin >> ar[i + 1];
int visited[n + 1];
f... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int T;
scanf("%d", &T);
for (int tt = 0; tt < (T); ++tt) {
long long n, k, d1, d2;
cin >> n, cin >> k, cin >> d1, cin >> d2;
long long cur;
bool ok = false;
cur = 2 * d1 + d2;
if (k - cur >= 0 and (k - cur) % 3 == 0) {
long l... | 9 |
#include <bits/stdc++.h>
using namespace std;
string second;
int n;
bool check(string second) {
for (int i = 0; i < (int((second).size())); i++) {
if (second[i] != second[(int((second).size())) - i - 1]) return 0;
}
return 1;
}
int ans;
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> n >> se... | 5 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const int maxn = 100010, P = 998244353;
int n, m, q, a[maxn], cnt[maxn], ans[maxn], occ[maxn], mul[maxn], tmp[200010];
struct query {
int l, r, id;
};
vector<query> Q[maxn];
vector<int> val[maxn], inv[maxn];
int qp(int x, int y) {
int z = 1... | 25 |
#include <bits/stdc++.h>
using namespace std;
const int offset = 5001;
const int MAXN = 5005;
struct hSegment {
int index;
int y;
int x1, x2;
hSegment() {}
hSegment(int x1, int x2, int y, int index) {
this->y = y;
this->x1 = x1;
this->x2 = x2;
this->index = index;
}
};
struct vSegment {
in... | 14 |
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 5e5 + 7;
const long long mod = 1e9 + 7;
const long long INF = 1e9 + 7;
const long long mlog = 20;
const long long SQ = 400;
const long long base = 727;
long long n;
long long ans;
long long hsh[3][maxn];
long long pw[maxn];
string st[3];
long long sz[... | 16 |
#include <bits/stdc++.h>
using namespace std;
int fa[75], deg[75], n, m, num;
pair<int, int> ans[2500];
int find(int x) {
if (fa[x] != x) fa[x] = find(fa[x]);
return fa[x];
}
int main() {
int x, y;
scanf("%d%d", &n, &m);
if (m > n) {
printf("NO");
return 0;
}
for (int i = 1; i <= n; i++) fa[i] = i... | 15 |
#include <bits/stdc++.h>
using namespace std;
template <int POS, class TUPLE>
void deploy(std::ostream &os, const TUPLE &tuple) {}
template <int POS, class TUPLE, class H, class... Ts>
void deploy(std::ostream &os, const TUPLE &t) {
os << (POS == 0 ? "" : ", ") << get<POS>(t);
deploy<POS + 1, TUPLE, Ts...>(os, t);
... | 12 |
#include <bits/stdc++.h>
using namespace std;
template <class A, class B>
ostream& operator<<(ostream& out, const pair<A, B>& a) {
return out << "(" << a.first << ", " << a.second << ")";
}
template <class A>
ostream& operator<<(ostream& out, const vector<A>& a) {
out << "[";
for (auto it = a.begin(); it != a.end... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 69, mod = 998244353;
long long n, m, mx, ind, ans, len, x, y;
long long fix[N], A[N], inv[N];
vector<long long> v[N];
long long binpow(long long a, long long b) {
long long ans = 1;
while (b > 0) {
if (b & 1) ans *= a, ans %= mod;
a *= a;
... | 16 |
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
const double PI = acos(-1.0);
const int MOD = 1000 * 1000 * 1000 + 7;
const int INF = 2000 * 1000 * 1000;
template <typename T>
inline T sqr(T n) {
return n * n;
}
vector<int> mapping[10] = {{}, {}, {2}, {3}, {3, 2, 2},
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, q, t, m, tot;
double trans[15][205][205], go1[205], go2[205];
bool vis[205];
struct node {
double x, y;
} p[205];
struct node2 {
double a, b, c;
int pass[205], cnt;
} line[40050];
double Abs(double x) { return x > 0 ? x : -x; }
void calcline(double &a, double &... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = (int)1e5 + 10;
const int BUBEN = 25;
int n, m;
long long t;
int s;
int f[maxN];
int par[maxN];
pair<int, int> now[maxN];
int val_sq[maxN];
int get_par(int i) {
if (i == par[i]) return i;
par[i] = get_par(par[i]);
return par[i];
}
int sub(int a, int b)... | 21 |
#include <bits/stdc++.h>
using namespace std;
char a[3];
int cs[3] = {0, 0, 0};
int x, y;
int main() {
for (int i = 0; i < 3; i++) {
cin >> a;
x = a[0] - 'A';
y = a[2] - 'A';
if (a[1] == '>')
cs[x]++;
else
cs[y]++;
}
if ((cs[0] != cs[1]) && (cs[1] != cs[2])) {
a[cs[0]] = 'A';
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
long long dp[maxn];
void solve() {
int n, m;
cin >> n >> m;
memset(dp, 0x3f, sizeof(dp));
dp[0] = 0;
for (int i = 1; i <= n; ++i) {
char c;
cin >> c;
dp[i] = min(dp[i], dp[i - 1] + i);
if (c == '1') {
for (int j = m... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> v(10, 0);
for (int i = 0; i < n; i++) {
char c;
cin >> c;
if (c == 'L') {
for (int j = 0; j < 10; j++) {
if (v[j] == 0) {
v[j] = 1;
break;
}
}
} else if (c == '... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <typename Tp>
void read(Tp &x) {
x = 0;
long long f = 1;
char c = getchar();
while (c > '9' || c < '0') {
if (c == '-') {
f = -1;
}
c = getchar();
}
while (c >= '0' && c <= '9') {
x = (x << 1) + (x << 3) + (c ^ 48);
c = getchar... | 15 |
#include <bits/stdc++.h>
#pragma GCC optimize(3, "Ofast", "inline")
using namespace std;
bool Finish_read;
template <class T>
inline void read(T &x) {
Finish_read = 0;
x = 0;
int f = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') f = -1;
if (ch == EOF) return;
ch = getchar();
}
... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long A[303030];
long long B[303030];
long long D[303030];
int N;
int main() {
int T;
scanf("%d", &T);
while (T--) {
scanf("%d", &N);
for (int i = 0; i < N; i++) scanf("%lld%lld", &A[i], &B[i]);
long long s = 0;
for (int i = 0; i < N; i++) {
... | 8 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0;
int ch = getchar(), f = 0;
while (ch < '0' || ch > '9') {
f |= ch == '-';
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return f ? -x : x;
}
const int kcz = 1000000007... | 17 |
#include <bits/stdc++.h>
using namespace std;
int i, j, n, k, a[5005], rs, diff[1000005], sum, last[1000005], now, used;
vector<pair<int, int>> pdif;
int main() {
ios_base::sync_with_stdio(0);
cin >> n >> k;
if (n <= k || n == 1) return cout << "1\n", 0;
for (i = 1, rs = n - k; i <= n; ++i) cin >> a[i];
sort(... | 16 |
#include <bits/stdc++.h>
using namespace std;
double PI = acos(-1);
double EPS = 1e-7;
int INF = 1000000000;
long long INFLL = 1000000000000000000LL;
int mx[8] = {-1, 1, 0, 0, -1, -1, 1, 1};
int my[8] = {0, 0, -1, 1, -1, 1, -1, 1};
int dp[5005];
int pre[5005];
int mod = 1000000007;
int main() {
int n, x, y, k;
scan... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int n, k, i;
cin >> n >> k;
char a[400005], b[400005];
string s;
cin >> s;
for (i = 0; i < n; i++) {
a[i] = s[i];
b[i] = s[i];
}
sort(a, a + n);
long long... | 4 |
#include <bits/stdc++.h>
using namespace std;
char str[1100000];
int is_num(char c) {
if (c >= '0' && c <= '9') return 1;
return 0;
}
int is_let(char c) {
if (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z') {
return 1;
}
return 0;
}
int is_let_num(char c) {
if (is_let(c) || is_num(c)) return 1;
return 0... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 17;
int a, b;
bool in[maxn];
bool check(int x) {
int rem = a;
long long all = (long long)x * (x + 1) / 2;
memset(in, 0, sizeof in);
for (int i = x; i > 0; i--)
if (rem >= i) all -= i, rem -= i, in[i] = 1;
if (all <= b) return 1;
rem = ... | 8 |
#include <cstdio>
#include <cctype>
#include <vector>
#include <cmath>
using namespace std;
const int MAXN = 400005;
int n, dest[MAXN];
bool vis[MAXN];
vector<pair<int, int>> ans;
inline int read()
{
int x = 0, f = 1; char ch = getchar();
while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); }
while (is... | 20 |
#include <bits/stdc++.h>
using namespace std;
int n, k, ans, c[2001];
struct node {
int x;
int s;
} a[2001];
bool cmp(node p, node q) { return p.s > q.s; }
int main() {
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i].s);
a[i].x = i;
}
sort(a + 1, a + 1 + n, cmp);
for (int i... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, m, mx, chk[111];
vector<int> v[111], mxn;
int f(int s, int e) {
if (s == e) return 0;
if (e < s) return f(s, n) + f(1, e) + 1;
return e - s;
}
int main() {
scanf("%d %d", &n, &m);
for (int i = 1; i <= m; i++) {
int a, b;
scanf("%d %d", &a, &b);
... | 9 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.