solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
long repeated_squaring(long base, long exp) {
long result = 1;
while (exp) {
if (exp % 2) {
result *= base;
}
base *= base;
exp = exp >> 1;
}
return result;
}
vector<int> int_to_vector(long long num) {
vector<int> v;
while (1) {
if (num... | 1 |
#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;
using poly = vector<int>;
poly kake(poly p) {
p.insert(p.begin(), 0);
return p;
}
poly tasu(poly p, poly p2) {
poly ans(max(p.size(), p2.size()));
for (int i = 0; i < ans.size(); ++i) {
... | 14 |
#include <bits/stdc++.h>
using namespace std;
unsigned long long q, n, k, f[100000 * 3];
string s1 = "What are you doing while sending *",
s2 = "*? Are you busy? Will you send *", s3 = "*?";
string fr =
"What are you doing at the end of the world? Are you busy? Will you save "
"us?";
inline char check(ch... | 9 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const int maxn = 4000 + 5;
long long C[maxn][maxn];
long long f[maxn][maxn];
long long eq[maxn];
int main() {
C[0][0] = 1;
for (int i = 1; i < maxn; i++)
for (int j = 0; j <= i; j++)
if (!j)
C[i][j] = 1;
else
... | 11 |
#include <bits/stdc++.h>
using namespace std;
char s1[100], s2[100];
int n, p1, p2, cnt, u;
double ans;
int walk(char x) { return x == '+' ? 1 : (x == '-' ? -1 : 0); }
void dfs(int u, int p) {
if (u == 0) {
cnt += (p == p1);
return;
}
dfs(u - 1, p - 1);
dfs(u - 1, p + 1);
}
int main() {
scanf("%s%s", ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
cout << "YES\n";
while (n--) {
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
cout << 2 * (x1 % 2 != 0) + (y1 % 2 != 0) + 1 << endl;
}
return 0;
}
| 13 |
#include <bits/stdc++.h>
using namespace std;
bool row[51];
bool col[51];
int main() {
memset(row, false, sizeof(row));
memset(col, false, sizeof(col));
int n;
cin >> n;
for (int i = 0; i < n * n; i++) {
int r, c;
cin >> r >> c;
if (row[r] == false && col[c] == false) {
cout << i + 1 << " ";... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, m, x, ans, cnt, cnt2;
vector<int> v, atk, def;
vector<pair<int, int> > all;
string s;
multiset<int> st;
int main() {
scanf("%d %d", &n, &m);
for (int i = 0; i < n; i++) {
cin >> s >> x;
if (s == "ATK") {
cnt += x;
atk.push_back(x);
all.p... | 11 |
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:512000000")
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(NULL));
ll const mod = 1e9 + 7;
namespace {
ll mul(ll a, ll b) {
ll val = a * b - (ll)((ld)a * b / mod) * mod;
if (val < 0) val ... | 10 |
#include <bits/stdc++.h>
using namespace std;
char* get_new_c_string(const char* a, const char* b) {
char* c_s = (char*)malloc((strlen(a) + strlen(b) + 1) * sizeof(char));
strcpy(c_s, a);
strcat(c_s, b);
return c_s;
}
int main(int argc, char** argv) {
int q, x, y;
scanf("%d %d\n", &q, &x);
vector<int> mod... | 8 |
#include <bits/stdc++.h>
using namespace std;
unordered_map<long double, int> mp;
int main() {
int n;
scanf("%d", &n);
long double sum = 0;
long double re = 0;
for (int i = 0; i < n; i++) {
long double x;
scanf("%LF", &x);
re += (i * x - sum) + mp[x + 1] - mp[x - 1];
sum += x;
mp[x]++;
}... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t = 0;
cin >> t;
while (t--) {
int a = 0, b = 0, c = 0, d = 0;
cin >> a >> b >> c >> d;
if (b > a) swap(a, b);
if (c < d) swap(c, d);
if ((a * a) - (a * b) == c * d && c == a) {
cout << "YES" << endl;
} else
cout <<... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
double t, s = 1;
for (t = 2; t <= n; t++) {
s = s + (1 / t);
}
cout << fixed << setprecision(12) << s;
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, f = 0;
cin >> n >> m;
vector<pair<int, int>> pr(n);
for (int i = 0; i < n; i++) {
cin >> pr[i].first >> pr[i].second;
}
if (pr[0].first != 0) {
cout << "NO";
return 0;
}
f = pr[0].second;
for (int i = 1; i < n; i++) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long mf(long long x, long long mod);
long long mi(long long x, long long mod);
long long C(long long x, long long y, long long mod);
long long bpow(long long x, long long y, long long mod);
long long mf(long long x, long long mod = 1000000007) {
if (x < 2) return 1;
... | 11 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using str = string;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vpi = vector<pair<int, int>>;
using vvi = vector<vi>;
int Bit(int mask, int b) { return (mask >> b) & 1... | 5 |
#include <bits/stdc++.h>
const int MAXN = 1e5 + 10;
using namespace std;
int N, K;
int A[MAXN][4];
struct xxx {
int a[4];
bool operator<(const xxx &T) const {
for (int c = 0; c < 3; c++)
if (a[c] != T.a[c]) return a[c] < T.a[c];
return a[3] < T.a[3];
}
};
map<xxx, int> M;
int main() {
scanf("%d %d... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, p;
cin >> n >> p;
string s;
cin >> s;
int ans = 0;
int first = -1, second = -1;
for (int i = 0; i < n / 2; i++) {
if (s[i] != s[n - i - 1]) {
if (first == -1) first = i;
second = i;
}
int diff = abs(s[i] - s[n - i - ... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
long long t;
cin >> t;
while (t--) {
long long n, p;
cin >> n >> p;
vector<long long> A(n), B(p);
long long i;
for (i = 0; i < n; i++) cin >> A[i];
for (i = 0; i < p; i++) {
cin >> B[i];
... | 4 |
#include <bits/stdc++.h>
using namespace std;
unordered_map<int, vector<int>> fre;
bool comp(pair<long long, long long> p1, pair<long long, long long> p2) {
return p1.second < p2.second;
}
string rev(string s) {
int n = s.length();
for (int i = 0; i < n / 2; i++) {
int temp = s[i];
s[i] = s[n - i - 1];
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, k;
cin >> n >> k;
int n1 = n - (k - 1);
if (n1 > 0 && n1 % 2 == 1) {
cout << "YES" << endl;
for (int i = 0; i < k - 1; ++i) cout << "1 ";
cout << n1 << endl;
continue;
}
... | 4 |
#include <bits/stdc++.h>
using namespace std;
template<class T> ostream& operator<<(ostream &os, vector<T> V) { os << "[ ";
for(auto v:V)os << v << " "; return os << "]";
}
template<class T> ostream& operator<<(ostream &os, set<T> S){ os << "{ ";
for(auto s:S) os<<s<<" "; return os<<"}";
}
template<class L, class... | 9 |
#include <bits/stdc++.h>
int main() {
int n, m;
scanf("%d%d", &n, &m);
if (m == 3 && n > 4) {
printf("-1\n");
return 0;
}
int i;
int x = -1e8;
int y = -1e8;
int add = 0;
for (i = 0; i < m; ++i) {
printf("%d %d\n", x + i, y + add);
y += add;
add++;
}
x = 1e8, y = -1e8, add = 0;
... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int N = 600005;
const int INF = 0x3f3f3f3f;
int n;
int fa[N] = {0};
int ch[2][N] = {0}, val[N] = {0}, mx[N], id[N], tag[N] = {0};
int s[N], si[N];
int stk[N], tp;
void pushup(int x) {
s[x] = (x <= n) + si[x] + s[ch[0][x]] + s[ch[1][x]];
id[x] = x;
mx[x] = val[x]... | 22 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, i, x;
cin >> n;
long long v[n];
x = 0;
for (i = 0; i < n; i++) {
cin >> v[i];
x += v[i];
}
sort(v, v + n);
x -= v[n - 1];
cout << v[n - 1] - x + 1;
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T getnum() {
T num = 0;
char c;
do {
c = getchar();
} while (c != EOF && c == ' ' && c == '\n' && c == '\t');
int sign = (c == '-' ? -1 : 1);
if (c != '-') num += (c - '0');
while ((c = getchar()) != EOF && c != '\n' && c != '\... | 16 |
#include <bits/stdc++.h>
using namespace std;
long long int m, n, c = 0, k = 0, a = 0, b = 0, temp, MAX = 0, MIN = 999999999,
sum = 0;
long long int i, j;
int main() {
string s;
string x;
cin >> s >> x;
for (i = 0, j = 0; i < x.size(); i++) {
if (s[j] == x[i]) j++;
}
cout << j + 1 <<... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 808, M = 5;
vector<int> v, g[M][N], wn[N];
bool fg[5];
int n, ch[2], p[N], p1[N], f[N], p3[N], p5[N], p8[N];
bool fl[N];
inline bool check() {
if (v.size() == 1) {
v.resize(0);
return 1;
}
if (v.size() == 0) return 0;
printf("? %d", v.size());
... | 26 |
#include <bits/stdc++.h>
using namespace std;
int row[1005], col[1005];
int main() {
int n, x, y, m;
scanf("%d%d", &n, &m);
for (int i = 0; i < m; i++) {
scanf("%d%d", &x, &y);
row[x] = col[y] = 1;
}
int res = 0;
for (int i = 2; i <= n - 1; i++) {
if (col[i] == 0) res++;
if (row[i] == 0) res... | 10 |
#include <bits/stdc++.h>
using namespace std;
int M[105][105];
int n, m;
int c[105];
int sum[105];
void init(int r, int countt) {
for (int i = 1; i <= countt; i++) {
sum[i] = sum[i - 1] + M[r][i];
}
for (int i = 1; i <= countt; i++) {
for (int j = 0; j <= i; j++) {
int k = i - j;
M[r][i] = max... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<vector<int> > m(N + 1, vector<int>());
vector<int> v(N + 1, 0);
for (int i = 0; i < N - 1; i++) {
int a, b;
cin >> a >> b;
m[a].push_back(b);
m[b].push_back(a);
v[a]++;
v[b]++;
}
char fin[101000] = {... | 13 |
#include <bits/stdc++.h>
using namespace std;
int const N = 1111;
int n, m, k, a[N];
int main() {
memset(a, 1, sizeof(a));
cin >> n >> m >> k;
for (int i = 0; i < n; i++) {
int aa, bb;
cin >> aa >> bb;
a[aa - 1] = min(a[aa - 1], bb);
}
int res = 0;
for (int i = 0; i < m; i++) {
assert(a[i] <... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int M = 2e5 + 5;
int main() {
ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
int n;
cin >> n;
string second;
cin >> second;
int first[10];
for (int i = 1; i < 10; i++) {
cin >> first[i];
}
int x;
bool ok = 0;
for (int i = 0;... | 5 |
#include <bits/stdc++.h>
using namespace std;
long n, m;
void xuli() {
long j;
j = m;
for (long i = 1; i <= m; i++) {
if (i == j) {
cout << n / 2 + 1 << " " << i << "\n";
return;
}
if (j < i) return;
cout << n / 2 + 1 << " " << i << "\n";
cout << n / 2 + 1 << " " << j << "\n";
... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int maxa = 1000005;
int a[maxa];
int b[maxa];
int main() {
int n, m, p, q;
while (cin >> n >> m >> p >> q) {
int u = 0, v = 0;
for (int i = 0; i < n; i++) {
a[u] = v;
u = (u + p) % n;
v = (v + q) % n;
}
int ansx, ansy;
int max... | 12 |
#include <bits/stdc++.h>
int main(void) {
int n, x, y, t, r;
while (scanf("%d%d%d", &n, &x, &y) != EOF) {
t = (int)(1.0 * n * y / 100);
r = t;
if (1.0 * n * y / 100 != (double)r) t++;
if (t >= x) {
printf("%d\n", t - x);
} else
printf("0\n");
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int a[maxn];
int main() {
int n, x, y;
cin >> n >> x >> y;
for (int i = 1; i <= n; i++) cin >> a[i];
int c, d;
int ans = 0;
for (int i = 1; i <= n; i++) {
int f = 0;
for (int j = max(1, i - x); j < i; j++)
if (a[j] < a[i])... | 2 |
#include <bits/stdc++.h>
const long long int mrx = 1e6 + 5, M = 1e9 + 7;
long long int mx = INT_MIN, mn = INT_MAX;
using namespace std;
long long int a[mrx], b[mrx], d, color[mrx], used[mrx];
vector<long long int> s[mrx];
map<pair<long long int, long long int>, long long int> m;
void dfs(long long int v, long long int ... | 18 |
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef pair<int,int> pi;
typedef pair<lld,lld> pl;
typedef pair<int,lld> pil;
typedef pair<lld,int> pli;
typedef vector<int> vit;
typedef vector<vit> vitt;
typedef vector<lld> vlt;
typedef vector<vlt> vltt;
typedef vector<pi> vpit;
typedef vector... | 9 |
#include <bits/stdc++.h>
using namespace std;
const long long L = 1ll << 32;
int main() {
long long a, b, c;
int who;
cin >> a >> b >> c;
cout << "First" << endl;
cout << L << endl;
cin >> who;
if (who == 1) {
a += L;
} else if (who == 2) {
b += L;
} else if (who == 3) {
c += L;
} else {... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int inf = ~0U >> 1;
const long long INF = ~0ULL >> 1;
template <class T>
inline void read(T &n) {
char c;
int flag = 1;
for (c = getchar(); !(c >= '0' && c <= '9' || c == '-'); c = getchar())
;
if (c == '-')
flag = -1, n = 0;
else
n = c - '0';
... | 17 |
#include <bits/stdc++.h>
using namespace std;
double const pi = 3.1415926536;
int main() {
long long n, k;
cin >> n >> k;
long long s = 1;
s = s << 60;
while (s > n) s /= 2;
if (k > 1)
cout << s + s - 1;
else
cout << n;
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
class Solution {
int n;
vector<int> offe;
vector<int> defe;
vector<int> constcnt;
bool check(int k) {
auto cnt = constcnt;
vector<int> score = vector<int>(5);
int dif = 0;
for (int i = 0; i < 5; i++) {
if (offe[i] >= 0) {
if (defe[i] ... | 12 |
#include <bits/stdc++.h>
using namespace std;
string str;
struct STR {
string name;
int cont;
int dep;
int id;
bool vis;
};
STR strche[1000006];
int cnt;
int maxdep;
void dfs(int step, int num) {
strche[num].vis = true;
strche[num].dep = step;
maxdep = max(maxdep, step);
if (strche[num].cont == 0) ret... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)(1e5) + 2;
const int mod = (int)(1e9) + 7;
int n, a[maxn], suff[maxn], pref[maxn];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
pref[i] = pref[i - 1] + a[i];
}
for ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, ss, res;
cin >> t;
while (t--) {
string s;
cin >> s, ss = s.size() - 4, res = 0;
for (int i = 4; i < ss + 4; i++) res *= 10, res += s[i] - '0';
printf("%d\n",
(ss == 1 ? (res == 9 ? 1989 : 1990 + res)
: (s... | 12 |
#include <bits/stdc++.h>
using namespace std;
double dp[109][109][109];
bool visit[109][109][109];
double dfs(int r, int s, int p) {
if (r == 0) return 0.0;
if (s == 0 && p == 0) return 1.0;
if (visit[r][s][p]) return dp[r][s][p];
visit[r][s][p] = 1;
int tot = r * s + r * p + s * p;
dp[r][s][p] = 0;
if (s... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m, k, l;
cin >> n >> m >> k >> l;
if ((n < m) || (k + l > n))
puts("-1");
else {
long long R = k + l;
long long u = (R % m) ? R / m + 1 : R / m;
if (u == 0) u++;
if (m * u <= n)
cout << u;
else
cout << -1... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 11;
int a[N][N];
int n = 10;
double dp[N][N][2];
double func(int x, int y, bool b) {
if (dp[x][y][b] != -1) return dp[x][y][b];
if (x == 0 && y == 0) return 0;
if (x == 0 && y <= 6) return 6;
double ret = 0;
if (x % 2 == 1) {
if (y <= 3) {
... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
struct Node {
double x, y;
Node operator-(Node A) { return (Node){x - A.x, y - A.y}; }
double operator*(Node A) { return x * A.y - y * A.x; }
double dis() { return sqrt(x * x + y * y); }
} O[N][N], t[N], E[N];
int n, yes[N][N];
double Or[N][N];
N... | 25 |
#include <bits/stdc++.h>
using namespace std;
multiset<int> wash, dry, fold;
int main() {
int k, n1, n2, n3, t1, t2, t3, i;
int ans, now;
while (scanf("%d %d %d %d %d %d %d", &k, &n1, &n2, &n3, &t1, &t2, &t3) !=
EOF) {
wash.clear(), dry.clear(), fold.clear();
for (i = 0; i < n1; ++i) wash.insert(... | 11 |
#include <bits/stdc++.h>
using namespace std;
int a[10004];
int main() {
int n, k;
cin >> n >> k;
int db = 2 * n, qt = n, sng = 0;
for (int i = 0; i < k; ++i) cin >> a[i];
sort(a, a + k);
reverse(a, a + k);
for (int i = 0; i < k; ++i) {
while (a[i] > 3 && qt > 0) {
a[i] -= 4;
qt--;
}
... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int Maxn = 105;
int n;
char neigh[Maxn][Maxn];
int a[Maxn];
vector<int> seq;
bool getZero(int &val) {
for (int i = 0; i < n; i++)
if (a[i] == 0) {
val = i;
return true;
}
return false;
}
int main() {
scanf("%d", &n);
for (int i = 0; i < n; ... | 15 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, k;
long long u[100005] = {0};
long long v[100005] = {0};
long long p[100005] = {0};
long long a[100005] = {0};
int main() {
long long i, j, z, x;
cin >> n >> m >> k;
for (i = 1; i <= m; i++) {
cin >> u[i] >> v[i] >> p[i];
}
if (k == 0) {
co... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long nm = 100007;
string s[nm], f[nm];
long p[nm], n;
int main() {
cin >> n;
for (int i = 0; i < n; i++) cin >> s[i] >> f[i];
for (int i = 0; i < n; i++) cin >> p[i];
string tmp;
for (int i = 0; i < n; i++)
if (s[i] > f[i]) {
tmp = s[i];
s[i]... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int n, m;
int from[maxn], to[maxn];
struct node {
int w, flag, id;
bool operator<(const node& a) const {
if (w != a.w) return w < a.w;
return flag > a.flag;
}
} edge[maxn];
bool solve() {
int cnt = 1;
int u = 1, v = 3;
for (int ... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e5 + 10;
long long a[MAXN], n;
bool check_min(long long x, long long k) {
long long cnt = upper_bound(a + 1, a + n + 1, x) - a;
for (int i = 1; i <= cnt - 1; ++i) {
k -= (x - a[i]);
if (k < 0) return false;
}
return true;
}
bool check_max(l... | 12 |
#include <bits/stdc++.h>
using namespace std;
int min(int x, int y) { return x < y ? x : y; }
int main() {
int n, r;
cin >> n;
r = n % 10;
cout << (r <= 10 - r ? n - r : n - r + 10) << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
string A, B;
int F[2 * N][2];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
for (int ks = 1; ks <= (int)(t); ++ks) {
cin >> A >> B;
for (int i = 1; i <= B.size(); i++) {
for (int j = 0; j < 2; j+... | 7 |
#include <bits/stdc++.h>
using namespace std;
int Stv[1 << 8];
inline int read() {
int f = 1, res = 0, ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') res = res * 10 + ch - 48, ch = getchar();
return f * res;
}
const int N = 200005... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int arr[n];
int v[n];
for (int i = 0; i < n; i++) cin >> arr[i];
for (int i = 0; i < n; i++) cin >> v[i];
map<int, int> mp;
vector<pair<int, int> > vi;
vector<pair<int, int> > vf;
for (int i = 0; i < n; i++) {
vi.push_ba... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long n, x;
long long tree[800005][6], add[400005], pan[400005], shu[400005];
long long num[800005];
char a[10];
map<long long, long long> id;
inline long long read() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1... | 15 |
#include <bits/stdc++.h>
using namespace std;
int mx = 100000;
int gcd(int a, int b) {
while (a && b) {
if (a >= b)
a %= b;
else
b %= a;
}
return a + b;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
if (n > m + 1) return cout << "Impossible", 0;
... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long MOD = 1e9 + 7 / 4;
long long INF = LLONG_MAX / 4;
vector<string> &split(const std::string &s, char delim, vector<string> &e) {
stringstream ss(s);
string item;
while (getline(ss, item, delim)) e.push_back(item);
return e;
}
long long Pow(long long a, long ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int n, P;
long long S;
int W[maxn], fa[maxn];
int is_leaf[maxn], vis[maxn];
void dfs(int x) {
if (!is_leaf[x]) return;
is_leaf[fa[x]] = false;
dfs(fa[x]);
}
int main() {
scanf("%d%d%lld", &n, &P, &S);
for (int i = 1; i <= n; i++) {
s... | 16 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
int m, q[100005], n, a[100005];
void solve() {
sort(q, q + m);
sort(a, a + n);
int sum = 0;
for (int i = n - 1, j = 0; i >= 0; j++) {
if (i + 1 >= q[0]) {
for (int k = 0; k < q[0] && i >= 0; k++, i--) {
sum += a[i];
... | 6 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK: 40000000")
using namespace std;
void fail() {
cout << "false" << endl;
exit(0);
}
string binstr(long long int v, long long int len) {
string res = "";
for (long long int i = 0; i < len; i++, v >>= 1) {
res = ((v & 1) ? "1" : "0") + res;
}
return ... | 8 |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
long long x = 0, fl = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') fl = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = x * 10 + c - '0';
c = getchar();
}
return x * fl;
}
const int N = 110... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, b, d, sum, count, i;
long long int A[123456];
cin >> n >> b >> d;
for (i = 0; i < n; i++) {
cin >> A[i];
}
sum = 0;
count = 0;
for (i = 0; i < n; i++) {
if (A[i] > b) {
continue;
} else {
sum = sum + A[i]... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long int k, n, i, p, x, y;
long long int ami[10000000];
long long int amina[5000000];
int main() {
while (cin >> n >> k) {
i = 1;
p = 0;
x = 0;
y = 0;
while (i * i <= n) {
if (n % i == 0) {
ami[x++] = i;
if (i != n / i) {
... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10;
int read() {
int ans = 0;
bool f = 0;
char ch = getchar();
while (ch < '0' or ch > '9') {
if (ch == '-') f = 1;
ch = getchar();
}
while (ch >= '0' and ch <= '9') {
ans = (ans << 1) + (ans << 3) + (ch ^ 48);
ch = getchar... | 12 |
#include <bits/stdc++.h>
using namespace std;
long long int fakulteta(long long int n) {
if (n <= 1) return 1;
return ((fakulteta(n - 1) * n));
}
long long int kombinacija(long long int n, long long int k) {
if (k < 0 || k > n) return 0;
long long int rez = 1;
for (int i = 1; i <= n; i++) {
rez *= n - i +... | 11 |
#include <bits/stdc++.h>
using namespace std;
const long double EPS = 1e-10;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
const long double PI = 3.1415926535897932384626433832795028841;
map<string, int> ssol;
void checkAdd(string vs) {
if (ssol.find(vs) != ssol.end()) {
return;
}
ssol[vs] = 1;
}... | 17 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> E[100000 + 5];
vector<int> ans;
bool vis[100000 + 5];
int tim[100000 + 5];
int cnt[100000 + 5];
void dfs(int x, int fa) {
ans.push_back(x);
vis[x] = 1;
cnt[x] ^= 1;
for (int y : E[x]) {
if (y != fa && !vis[y]) {
dfs(y, x);
ans.p... | 14 |
#include <bits/stdc++.h>
using namespace std;
int dp[80][80][80][3], len;
char str[80];
int solve(int V, int K, int EX, int lst) {
if (V + K + EX == len) return 0;
int &ret = dp[V][K][EX][lst];
if (ret != -1) return ret;
ret = 0x3f3f3f3f;
int cv = -1, ck = -1, cex = -1, c = 0, i, TV = V, TK = K, TEX = EX;
f... | 17 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
double m;
double v1, v2;
bool pass(double lim) {
int num = n;
double now = 0.0;
double tim = 0.0;
for (; num;) {
if (now + (lim - tim) * v1 >= m) return true;
if (now + (lim - tim) * v2 < m) return false;
num = max(num - k, 0);
double tmp =... | 11 |
#include <bits/stdc++.h>
double pi = 3.141592653589793;
using namespace std;
int N;
long long x[100100], y[100100], p, q;
double maxd = 0;
double mind = 1000000000000000;
int main() {
cin >> N >> p >> q;
for (int i = 0; i < N; ++i) {
cin >> x[i] >> y[i];
}
x[N] = x[0], y[N] = y[0];
for (int i = 0; i < N; ... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 10001;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
;
int n;
cin >> n;
if (n % 2 == 0) {
cout << -1;
return 0;
}
for (int i = 0; i < n; i++) cout << i << " ";
cout << '\n';
cout << n - 1 << " ";
for (int i = 0;... | 5 |
#include <bits/stdc++.h>
using namespace std;
int firstPossible[200000];
int lastPossible[200000];
string s, t;
int ans = 0;
int main() {
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
};
cin >> s >> t;
int charOfS = 0;
for (int charOn = 0; charOn < t.size(); charOn++) {
wh... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long unsigned int n;
cin >> n;
long long unsigned int sum = 1;
sum += 3 * n * n + 3 * n;
cout << sum;
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i;
vector<int> div;
cin >> n;
for (i = 1; i <= n; i++) {
if (n % i == 0) {
div.push_back(i);
}
}
string s;
cin >> s;
for (i = 0; i < div.size(); i++) {
reverse(s.begin(), s.begin() + div[i]);
}
cout << s << endl;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
class Solution {
public:
vector<vector<int>> resourceDistribution(int x1, int x2,
vector<int> resource) {
int n = resource.size();
vector<vector<int>> res(2);
vector<pair<int, int>> pv(n);
for (int i = 0; i < n; ... | 9 |
#include <bits/stdc++.h>
using namespace std;
struct node {
long long x, y, id;
} a[100010], b[100010];
long long n, p, k;
bool vis[100010];
bool cmp1(node x, node y) {
if (x.y == y.y) {
return x.x < y.x;
} else {
return x.y > y.y;
}
}
bool cmp2(node x, node y) {
if (x.x == y.x) {
return x.y > y.y... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long v[200100];
int main() {
int n, m;
cin >> n >> m;
set<pair<long long, long long> > ss;
for (int i = 0; i < n; i++) {
scanf("%lld", &v[i]);
ss.insert(pair<long long, long long>(-(v[i] % m), i));
}
long long count = 0;
for (int i = m - 1; i >= 0... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main(int argv, char *argc[]) {
int cases;
cin >> cases;
string str2, use = "RGB";
for (int i = 0; i < 2000; i++) str2.push_back(use[i % 3]);
while (cases--) {
int n, i, k, mini = INT_MAX, flag = false, min_till = INT_MAX;
cin >> n >> k;
string str;... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e9 + 5;
using namespace std;
int binomialCoeff(int n, int k) {
if (k > n) return 0;
if (k == 0 || k == n) return 1;
return binomialCoeff(n - 1, k - 1) + binomialCoeff(n - 1, k);
}
const int N = 1e6 + 5;
int main() {
ios::sync_with_stdio(0);
cin.t... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, m, f, a[100][100];
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> a[i][j];
if ((i == 1 || j == 1) && a[i][j] > 0) f = 1;
if ((i == n || j == m) && a[i][j] > 0) f = 1;
}
}
if (... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long c[250 * 2 + 6], a[250], b[250], n, m, k, ans[250 * 2 + 6],
va[250 * 2 + 6], vv[250 * 2 + 6];
void ml(long long *a, long long *d) {
for (long long i = 0; i < 2 * 250; i++) c[i] = 0;
for (long long i = 0; i < 250; i++)
for (long long j = 0; j < 250; j++)... | 25 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 3005, INF = 1e9;
int n, m, sol, d[MAX][MAX][2];
vector<int> g[MAX], gt[MAX], r;
queue<int> q;
set<pair<int, int> > s[MAX][2];
void bfs(int x, vector<int> *g, int b) {
for (int i = 1; i <= n; i++) d[x][i][b] = -1;
d[x][x][b] = 0;
q.push(x);
while (!q.... | 12 |
#include <bits/stdc++.h>
using namespace std;
int n, m, a[200010], cnt[400010];
long long solve(int x) {
memset(cnt, 0, sizeof(cnt));
long long ret = 0, add = 0;
cnt[n] = 1;
int pos = n;
for (int i = 1; i <= n; i++) {
if (a[i] <= x)
add += cnt[++pos];
else
add -= cnt[pos--];
cnt[pos]++... | 16 |
#include <bits/stdc++.h>
using namespace std;
int n;
double t[5001];
double x[5001], y[5001], z[5001];
int main() {
cin >> n;
cin >> x[0] >> y[0] >> z[0];
double res = 1e9;
for (int i = 1, _s = n; i < _s; ++i) {
cin >> x[i] >> y[i] >> z[i];
t[i] = sqrt((x[i] - x[0]) * (x[i] - x[0]) + (y[i] - y[0]) * (y[... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.precision(10);
cout << fixed;
int n, m;
cin >> n >> m;
int l = (n + m) * 6;
int ans = 0;
for (int i = 1; i <= l; i++) {
if (i % 2 == 0 && i % 3 == 0) {
if (n > m) {
n--;
} e... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
int n, t, S;
S = 1;
t = 0;
cin >> n;
while (t < n - 1) {
t++;
S += t;
if (S > n) S = S % n;
cout << S << " ";
}
return EXIT_SUCCESS;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000005;
int a[maxn], n;
int main() {
int i;
while (scanf("%d", &n) != EOF) {
int maxx = -1;
int k;
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
if (a[i] > maxx) {
k = i;
maxx = a[i];
}
}
for (i = 1... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int s, d;
cin >> s >> d;
int arr[d];
for (int i = 0; i < d; i++) scanf("%d", &arr[i]);
sort(arr, arr + d);
if (arr[0] == 1 || arr[d - 1] == s) {
cout << "NO";
return 0;
}
for (int i = 0, j = 1; i < d - 2;) {
if (arr[i] == j + 1 && ar... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
const int INF = 0x3f3f3f3f;
const int MAXN = 2000005;
const int maxn = 2000005;
vector<int> G[MAXN];
stack<int> Tar;
int dfn[maxn], low[maxn], idx = 0, Bcnt = 0;
;
bool instack[maxn];
int belong[MAXN];
void Tarjan(int i) {
dfn[i] = low[i] = ++idx;
instack[i] =... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
long long p[n], q[n];
for (long long i = 0; i < n; i++) {
cin >> p[i];
}
long long m = p[n - 1];
for (long long i = n - 2; i >= 0; i--) {
if (p[i] <= m) {
q[i] = (m - p[i]) + 1;
} else {
q[i] = 0;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
char s[2000000], s1[2000000];
int t[2000000], t1[2000000];
int n, m, T;
int f[2000000 * 2], g[2000000 * 2];
void build(char* S, int* f, int* t, int l, int r, int s) {
if (l == r) {
f[s] = (S[l] == 'B' || S[l] == 'C');
if (!f[s]) t[s] = 1;
return;
}
build(S... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, b;
cin >> n >> a >> b;
int na = ceil(1.0 * n / a), nb = 0;
while (true) {
if (na * a + nb * b == n) break;
if (na == 0 && nb * b > n) {
cout << -1;
return 0;
}
if (na * a + nb * b > n)
na--;
else if (na * ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
set<int> ms;
int main() {
ifstream myReadFile;
myReadFile.open("input.txt");
ofstream myfile;
myfile.open("output.txt");
int n;
myReadFile >> n;
cin >> n;
char str[200];
myReadFile >> str;
cin >> str;
int i = 0;
while (str[i] != '1' && i < ... | 5 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.