solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 5;
int a[maxn], b[maxn], d[maxn], n, cnt, ans, k;
struct nod {
int c, id;
} p[maxn];
inline bool cmp(const nod &A, const nod &B) { return A.c < B.c; }
bool vis[maxn];
int main() {
while (~scanf("%d", &n)) {
for (int i = 1; i <= n; ++i) scanf("... | 8 |
#include <bits/stdc++.h>
template <typename Arg1>
void ZZ(const char* name, Arg1&& arg1) {
std::cout << name << " = " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void ZZ(const char* names, Arg1&& arg1, Args&&... args) {
const char* comma = strchr(names + 1, ',');
std::cout.write(names, comm... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n, m, arr[100005];
int coun = 0;
int visited[100005];
vector<int> v[100005];
void dfs(int node, int f, int parent) {
visited[node] = 1;
if (arr[node]) f++;
if (f > m)
return;
else {
int len = v[node].size();
if (len == 1 && parent == v[node][0]) {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int car[1001][1001];
long long si[1001] = {0}, sj[1001] = {0};
int main() {
int n, m, li, lj;
long long sumx, sumy;
scanf("%d %d", &n, &m);
for (int j = 1; j <= n; j++) {
for (int i = 1; i <= m; i++) {
scanf("%d", &car[j][i]);
si[i] += car[j][i];
... | 10 |
#include <bits/stdc++.h>
const int maxn = 2e5 + 10;
const int N = 2e5 + 10;
using namespace std;
long long gcd(long long p, long long q) { return q == 0 ? p : gcd(q, p % q); }
long long qmul(long long p, long long q, long long mo) {
long long f = 0;
while (q) {
if (q & 1) f = (f + p) % mo;
p = (p + p) % mo;... | 12 |
#include<cstdio>
#include<iostream>
#include<queue>
#include<algorithm>
#include<cstring>
#include<set>
#include<vector>
#include<cmath>
#define PII pair<int,int>
#define pb push_back
#define ep emplace_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
inline int read(){
int x=0,f=1;cha... | 19 |
#include <bits/stdc++.h>
using namespace std;
void __print(long long first) { cerr << first; }
void __print(long first) { cerr << first; }
void __print(unsigned first) { cerr << first; }
void __print(unsigned long first) { cerr << first; }
void __print(unsigned long long first) { cerr << first; }
void __print(float fir... | 3 |
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
ostream& operator<<(ostream& os, const pair<T, U>& _p) {
return os << "(" << _p.first << "," << _p.second << ")";
}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& _V) {
bool f = true;
os << "[";
for (auto v ... | 16 |
#include <bits/stdc++.h>
using namespace std;
int n, c;
int l[1000010], r[1000010], e[1000010];
bool mark[1000010];
void print(int idx) {
for (int i = idx + 1; i <= l[idx];) {
print(i);
i = e[i] + 1;
}
cout << idx + 1 << ' ';
for (int i = l[idx] + 1; i <= e[idx];) {
print(i);
i = e[i] + 1;
}
}... | 18 |
#include <bits/stdc++.h>
using namespace std;
namespace io {
const int __SIZE = (1 << 21) + 1;
char ibuf[__SIZE], *iS, *iT, obuf[__SIZE], *oS = obuf, *oT = oS + __SIZE - 1,
__c, qu[55];
int __f, qr, _eof;
inline void flush() { fwrite(obuf, 1, oS - obuf, stdout), oS = obuf; }
i... | 23 |
#include <bits/stdc++.h>
using namespace std;
int c[1001000];
int main() {
int a[100010], a2[100010];
int b[100100], b2[100100], n, m;
while (cin >> n) {
int i;
for (i = 0; i < n; i++) {
cin >> a[i];
if (i == 0)
a2[i] = a[i];
else
a2[i] = a[i] + a2[i - 1];
}
cin >... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t, n, k, x, y, m;
cin >> t;
while (t--) {
cin >> n >> k;
cin >> x;
m = x;
k--;
while (k--) {
cin >> y;
m = max(m, (y - x) / 2 + 1);
x = y;
}
... | 2 |
#include <bits/stdc++.h>
using namespace std;
void file_open() {
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
}
int main() {
char a[200] = {}, result1[200] = {}, result2[200] = {};
scanf("%s", a);
int n = strlen(a);
int k, l;
k = n;
l = 0;
for (int i = 0; i < n; ++i) {
if ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int maxi[101][101];
int v[101];
int r[101];
int main() {
int n, m, x, t = 0;
char c;
cin >> n >> m;
for (int i = 0; i < n; i++) {
r[i] = 0;
}
for (int i = 0; i < m; i++) {
v[i] = 0;
}
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
long long n;
cin >> n;
int q = sqrt(n);
for (int(i) = (2); (i) <= (q); (i)++) {
if (n % i == 0) {
while (n % i == 0) n /= i;
n *= i;
}
}
cout << n;
return 0;
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
string a, b;
cin >> a >> b;
int cost = 0;
for (int i = 0; i < n - 1; i++) {
if (a[i] == b[i]) continue;
if (a[i] != b[i] && a[i + 1] != b[i + 1] && a[i] != a[i + 1]) {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int score;
string name;
int operator<(const node &o) const {
return score > o.score || score == o.score && name < o.name;
}
};
int c[101010], fa[101010], ans;
int z[101010];
int n, m, cur, now, x, y, N;
pair<int, string> b[101010];
node a[101010];
... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100000 + 10;
const int M = 1000000007;
const double eps = 1e-9;
const double PI = acos(-1);
const int oo = 1000000000;
int R, C, rr[3001][3001], ll[3001][3001], dd[3001][3001], fen[3001], l, r;
vector<int> k;
vector<pair<int, int> > v;
char g[3001][3001];
void... | 15 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
using namespace std;
vector<int> g[20][10004];
int vis[10004], p;
int mat[10004];
inline bool kuhn(int x, int now) {
if (vis[x] == now) return 0;
... | 11 |
#include <bits/stdc++.h>
const int mn = 1050;
long long t[2][2] = {{1, 1}, {1, 0}};
long long v, mo, f[2][2], c[2][2], x[2][2];
long long s[mn], s1[mn], h, L, ans;
int n, m, i, j, k;
long long S(long long a, long long b) {
long long res = 0, L = 1LL << 60;
while (L) {
res = res * 2 % mo;
if ((b & L) != 0) r... | 21 |
#include <bits/stdc++.h>
using namespace std;
long long S[1200008];
long long A[300002];
int n;
void add(int l, int r, int num, int id = 1, int sl = 0, int sr = n + 1) {
if (r <= sl or sr <= l) return;
if (l <= sl and sr <= r) {
S[id] += num;
return;
}
int mid = (sl + sr) / 2;
S[2 * id] += S[id];
S[... | 17 |
#include <bits/stdc++.h>
using namespace std;
int N;
int arr[2004];
int cnt[2004], acnt, val;
vector<int> vc;
int ans;
int main() {
scanf("%d", &N);
for (int i = 1; i <= N; ++i) {
scanf("%d", arr + i);
vc.push_back(arr[i]);
}
sort(vc.begin(), vc.end());
vc.erase(unique(vc.begin(), vc.end()), vc.end())... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 500010;
char s[N], t[N], S[N];
int fail[N];
int main() {
int n, m, i, j;
scanf("%s%s", s, t);
n = strlen(s), m = strlen(t);
int cnt0 = 0, cnt1 = 0;
for (i = 0; i < n; i++) {
if (s[i] == '0') {
cnt0++;
} else {
cnt1++;
}
}
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-10;
const double Pi = acos(-1.0);
int main() {
int n, ss[maxn];
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &ss[i]);
}
sort(ss, ss + n);
for (i... | 2 |
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:1024000000,1024000000")
int cao;
struct node {
node *f, *next[26];
int len;
int id;
node() {}
node(int x) {
f = 0;
id = 1;
len = x;
memset(next, 0, sizeof(next));
}
} v[500005];
node *now;
node *root;
node *newnode... | 13 |
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int T;
cin>>T;
for(int t=0;t<T;t++)
{
int n;
cin>>n;
vector<long long int>A,B;
for(int i=0;i<n;i++)
{
int x;cin>>x;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, k;
cin >> n >> k;
string s;
cin >> s;
set<char> st;
char m;
while (k--) {
cin >> m;
st.insert(m);
}
long long c = 0, ans = 0;
for (long long i = 0; i < s.size(); i++) {
if (st.find(s[i]) != st.end()) {
c++;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int a0[200100], a1[200100], b0[200100], b1[200100];
int main() {
long long ans = 0;
string a, b, c;
int n;
cin >> a >> b;
n = b.size() - a.size() + 1;
if (n > 1) {
a0[0] = b0[0] = a1[0] = b1[0] = 0;
for (int i = 1; i <= b.size(); i++) {
if (b[i - 1... | 7 |
#include <bits/stdc++.h>
using namespace std;
int memo[500][26][26];
int son[500][26][26];
int cambios[500][26][26];
string A[500];
int m, n;
void solve(int x, int y, int z) {
for (int row = 0; row < x; row++)
for (int a = 0; a < y; a++)
for (int b = 0; b < z; b++) {
int &res = memo[row][a][b];
... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5;
int cnt[N * 2], mp[N * 2], arr[N], arr1[N], ans[N];
int main() {
int n, m, p;
cin >> n >> m >> p;
for (int i = 0; i < n; i++) cin >> arr[i], mp[i] = arr[i];
for (int i = 0; i < m; i++) cin >> arr1[i], mp[i + n] = arr1[i];
sort(mp, mp + n + m);
... | 11 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void maxtt(T& t1, T t2) {
t1 = max(t1, t2);
}
template <typename T>
void mintt(T& t1, T t2) {
t1 = min(t1, t2);
}
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "RDLU";
long long ln, lk, lm;
void etp(b... | 26 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
vector<pair<int, int> > ord;
for (int i = 0; i < n; i++) {
ord.push_back(make_pair(a[i], -i));
}
sort(or... | 16 |
#include <bits/stdc++.h>
using namespace std;
int k[3];
int t[3];
int f[3];
deque<int> q[3];
priority_queue<pair<long long, long long>, vector<pair<long long, long long> >,
greater<pair<long long, long long> > >
Q;
int stage[100010];
int inn[100010];
int main() {
{ scanf("%d%d%d", &k[0], &k[1], &k[... | 10 |
/*
Powered by C++11.
Author : Alex_Wei.
*/
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize(3)
//using int = long long
//using i128 = __int128;
#define fi first
#define se second
#define pb emplace_back
#define all(x) (x).begin(),(x).end()
#define sor(x) sort(all(x))
#define rev(x) reverse(all... | 17 |
#include <bits/stdc++.h>
using namespace std;
long long dp[400005];
long long cost[5][400005];
long long cnt[3];
long long use[400005][3];
bool cmp(long long a, long long b) { return a > b; }
int main(int argc, char const *argv[]) {
int n, m;
cin >> n >> m;
int weight;
for (int i = 0; i < n; ++i) {
cin >> w... | 15 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, k, x, t;
string s, ans[1011], pri, cur, s1;
bool bo = true;
void calc() {
s1 = "9999";
for (int i = 0; i < 4; i++) {
for (char j = '0'; j <= '9'; j++) {
cur = s;
cur[i] = j;
if (cur < "1000" || cur > "2011") continue;
if (cur ... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n;
char buf[5];
vector<string> v;
vector<pair<int, int> > ind[62][62];
int conv(char &a) {
if (islower(a)) {
return a - 'a';
}
if (isupper(a)) {
return 26 + (a - 'A');
}
if (isdigit(a)) {
return 52 + (a - '0');
}
}
int deg[2];
int belong[62 * 62]... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5;
int A[MAXN + 10], B[MAXN + 10];
int n, t;
map<int, int> p;
int main() {
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", &A[n - i - 1]);
for (int i = 0; i < n; i++) scanf("%d", &B[i]);
int s = ... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long n, k, op[100];
int main() {
for (int i = 1; i <= 31; i++) op[i] = op[i - 1] * 4LL + 1LL;
int t;
scanf("%d", &t);
while (t--) {
scanf("%I64d%I64d", &n, &k);
if (n > 31) {
printf("YES %I64d\n", n - 1);
continue;
}
long long tot = ... | 12 |
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 2e5 + 7;
const long long mod = 1e9 + 9;
const long long INF = 1e9 + 7;
const long long mlog = 21;
const long long SQ = 400;
char a[maxn];
long long f[maxn], sz[maxn];
vector<pair<long long, long long> > adj[maxn];
long long mark[maxn], h[maxn];
long l... | 11 |
#include <bits/stdc++.h>
#pragma GCC optimize("-O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
const long long inf = 1e18;
const double eps = 1e-6;
const long long mod = 1e9 + 7;
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
bool on_board(int x, int y, int n, int m)... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int ans[10];
memset(ans, 0, sizeof ans);
int x;
int sum = 0;
for (int i = 0; i < n; i++) {
cin >> x;
ans[x]++;
sum += x;
}
if (ans[0] == 0) {
cout << -1 << endl;
return 0;
}
if (sum % 3 == 1) {
if (... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000000 + 10;
const int LOG = 20 + 1;
const int MOD = (int)1e9 + 7;
int n, k;
vector<pair<int, int> > adj[N];
int tag[N];
int depth[N], dir[N];
int father[N][LOG];
long long cost[N];
int dfsOrd[N], tot;
void dfs(int u, int f) {
dfsOrd[tot++] = u;
father[u]... | 14 |
#include <bits/stdc++.h>
using namespace std;
int a[2005];
int c;
void root(int x) {
c++;
if (a[x] == -2) return;
root(a[x]);
}
int main() {
int n, maxm = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
a[i] -= 1;
}
for (int i = 0; i < n; i++) {
c = 0;
root(i);
maxm = max(max... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1035;
int n, t, K;
namespace Real {
bool ask(int u) {
cout << "? " << u << endl;
cout.flush();
string s;
cin >> s;
return s == "N";
}
void R() {
cout << "R" << endl;
cout.flush();
}
} // namespace Real
namespace Fake {
int cntask, cntR;
int a... | 22 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x, y;
int n, s;
cin >> n >> s;
s *= 100;
int ans = -100;
for (int i = 0; i < n; ++i) {
cin >> x >> y;
y += x * 100;
if (y > s) continue;
int m = (s - y) % 100;
ans = max(ans, m);
}
(ans < 0) ? puts("-1") : printf("%d\n", ... | 4 |
#include <bits/stdc++.h>
using namespace std;
using LINT = long long int;
using PII = pair<int, int>;
int n;
int nums[150007];
set<int> errs;
bool check(int si) {
if (si % 2 == 0) {
if (si - 1 >= 0)
if (nums[si - 1] <= nums[si]) return false;
if (si + 1 < n)
if (nums[si + 1] <= nums[si]) return fa... | 11 |
#include <bits/stdc++.h>
long long mod = 1000000007;
long long mod2 = 998244353;
long long OO = 1e18;
using namespace std;
long long n, m;
char a[220][220];
long long res[220];
int main() {
long long i, j;
;
cin >> n >> m;
for (i = 1; i <= n; i++)
for (j = 1; j <= m; j++) cin >> a[i][j];
for (i = n + 1; i... | 7 |
#include <bits/stdc++.h>
inline int pidorand() { return ((rand() & 32767) << 15) | (rand() & 32767); }
using namespace std;
inline int nxt() {
int x;
scanf("%d", &x);
return x;
}
const int K = 42;
int cnts[K];
int needed[K];
int main() {
ios_base::sync_with_stdio(0);
int n;
cin >> n;
vector<long long> a(n... | 14 |
#include <bits/stdc++.h>
using namespace std;
const long long int N = 1e5 + 1;
void solve() {
int n, m, k, p = 0, q = 0, s = 0, c = 0, i, j;
int a, b, d;
cin >> a >> b >> c >> d;
int z[3] = {a, b, c};
sort(z, z + 3);
a = z[0], b = z[1], c = z[2];
cout << max(0, d - (b - a)) + max(0, d - (c - b));
return... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long dp[2][7010], k[2], jmp[2][7010], wn[2][7010];
pair<long, long> t[20010];
int main() {
long long n;
cin >> n;
for (int i = 0; i < 2; i++) {
cin >> k[i];
for (int j = 0; j < k[i]; j++) {
cin >> jmp[i][j];
}
}
for (int i = 0; i < 2; i++) {... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, x, y;
cin >> n >> x >> y;
set<double> v;
for (long long i = 0; i < n; i++) {
long long a, b;
cin >> a >> b;
if ((a - x) == 0)
v.insert(9000000);
else {
double slope2 = 1.0 * ((b - y)) / ((a - x));
v.insert(... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7, M = 1e6 + 7;
struct data {
int to, next, v;
} e[N << 1];
int head[N], cnt, n, i, j, k, ls[N * 60], rs[N * 60], xx[N], tt[N], root, sz;
long long T, sum[N * 60], w[N * 60], dp[N][2], ans[N];
void ins(int u, int v, int w) {
e[++cnt].to = v;
e[cnt]... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n;
cin >> n;
int ans = n / 2 + 1;
cout << ans << '\n';
for (int i = 1; i <= ans; ++i) cout << 1 << ' ' << i << '\n';
for (int i = 2; i <= n - ans + 1; ++i) cout << ans << ' ' << i << '\n';
return 0;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int SIZE = 100005;
vector<int> mp[SIZE];
long long var[SIZE], a[SIZE], b[SIZE];
int n;
void result(int p, int f) {
for (int i = 0; i < mp[p].size(); i++) {
int u = mp[p][i];
if (u == f) continue;
result(u, p);
a[p] = max(a... | 10 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
const int N = 1000005;
char s[N];
int n, m, p;
struct Node {
string str;
int d;
} a[N];
void dfs(int d) {
string tmp = "";
while (s[p] != ',') tmp += s[p++];
++p;
int son = 0;
while (s[p] != ',') {
so... | 9 |
#include <bits/stdc++.h>
using namespace std;
const long long maxm = 1e3 + 5;
const long long mod = 1e9 + 7;
long long d[maxm][maxm];
long long k, pa, pb;
long long A, B;
long long C;
long long ppow(long long a, long long b, long long mod) {
long long ans = 1 % mod;
a %= mod;
while (b) {
if (b & 1) ans = ans ... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, q, i, j;
int a[150009];
vector<pair<int, int> > v;
cin >> n >> k >> q;
int x;
for (i = 1; i <= n; i++) {
cin >> x;
a[i] = x;
}
int type, fr;
while (q--) {
cin >> type >> fr;
if (type == 1) {
v.push_back(make_pai... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
if (n == 1) {
cout << "a" << endl << "a" << endl << "b" << endl << "b";
} else if (n == 2) {
cout << "aa" << endl << "bb" << endl << "cc" << endl << "dd";
} else {
for (int i = 0; i < n / 2; i++)
if (i % 2 == 0) {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int r, x, y, x1, y1;
cin >> r >> x >> y >> x1 >> y1;
double dis = sqrt(float(pow(abs(x1 - x), 2)) + pow(abs(y1 - y), 2));
cout << ceil(dis / (2 * r));
}
| 6 |
#include <bits/stdc++.h>
using namespace std;
long long pas[35][35];
void calcTriangle() {
for (int i = 0; i < 35; i++) pas[i][i] = pas[i][0] = 1;
for (int i = 1; i < 35; i++) pas[0][i] = 0;
for (int i = 1; i < 35; i++)
for (int j = 1; j < i; j++) pas[i][j] = pas[i - 1][j] + pas[i - 1][j - 1];
}
int main() {
... | 6 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
int n, m;
cin >> n >> m;
int a[n], b[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] == 1) {
cout << "-1\n";
return 0;
}
}
for (int i = 0; i < n; i++) {
cin >> b[i];
if (b[i] == 1) {
... | 7 |
#include <bits/stdc++.h>
const int maxn = 1e5 + 100, mod = 1e9 + 7;
using namespace std;
int get_diff(int j1, int j2) {
if (j1 > j2)
return j1 - j2;
else
return j2 - j1;
}
int main() {
int n, j1, j2, res = 0, diff;
string ini, reqd;
cin >> n;
cin >> ini >> reqd;
for (int(i) = (0); (i) < (n); ++(i)... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
int n, sum[1000006], ans, mn[1000006];
string s;
int main() {
cin >> n >> s;
for (int i = 0; i < n; i++) {
if (s[i] == '(')
sum[i]++;
else
sum[i]--;
sum[i] += sum[i - 1];
}
if (sum[n - 1] != 2 && sum[n - 1] != -2) {
... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long mul(long long x, long long y) { return (x * y) % 1000000007; }
long long add(long long x, long long y) { return (x + y) % 1000000007; }
long long power(long long a, long long b) {
long long res = 1;
a = a % 1000000007;
while (b > 0) {
if (b & 1) {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long int n;
cin >> n;
vector<long long int> arr(n);
vector<long long int> a;
long long int pre[n + 1], pre2[n + 1];
pre[0] = 0, pre2[0] = 0;
for (long long int i = 0; i < n; i++) {
cin >> arr[i];
}
a = arr;
sort(a.begin(), a.end()... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long int INF = (long long int)(8e18);
const long long int MOD = 1e9 + 7;
int a[5010], ans[5010];
int freq[5010];
int main() {
ios ::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i... | 7 |
#include <bits/stdc++.h>
using namespace std;
int i, j, n, k, l, m, x, y, tot, flag, h, r, ans, koko;
int a[1000500];
long long to_push[1005000];
string s;
struct fib {
int x, y;
fib() {
x = 0;
y = 1;
}
fib(int x, int y) {
this->x = x;
this->y = y;
}
};
fib t[400500];
fib add(fib x, fib y) {
... | 15 |
#include <bits/stdc++.h>
int main() {
int n, x;
std::cin >> n;
for (int i = 0; i < n; i++) {
std::cin >> x;
bool flag = false;
for (int i = 0; i <= x / 7; i++)
if ((x - 7 * i) % 3 == 0) {
std::cout << "YES" << std::endl;
flag = true;
break;
}
if (!flag) std::cou... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
cin >> s;
int res = 10000;
for (int i = 0; i <= 100; ++i) {
int x = i;
bool ok = true;
for (auto c : s) {
if (c == '-') {
x--;
if (x < 0) ok = false;
} else {
x++;
}
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int K;
int lf[5];
int rg[5];
double DIV;
double f(int t) {
int i, j, v, l;
long long s = 0;
long long E[5];
long long U[5];
long long D[5];
long long temp;
for (i = 0; i < K; ++i) {
if (lf[i] <= t && t <= rg[i])
E[i] = 1;
else
E[i] = 0;
... | 12 |
#include <bits/stdc++.h>
inline long long read() {
char c, _c;
long long x;
for (c = _c = getchar(); !isdigit(c); c = getchar()) {
_c = c;
}
for (x = 0; isdigit(c); c = getchar()) {
x = x * 10 + c - '0';
}
return _c == '-' ? -x : x;
}
const int N = 1e5 + 5, M = 505;
int n, m, num, ans = 1e9, p[N],... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3fffffff, M = (int)(2e3 + 100);
int a, d, n;
int main(void) {
while (~scanf("%d%d%d", &n, &a, &d)) {
double pre = double(0);
while (n--) {
double anst;
double x, y;
scanf("%lf%lf", &x, &y);
double t = (y / a);
if (t ... | 8 |
#include <bits/stdc++.h>
int main(void) {
int n;
long double h1, h2, l, l1, l2;
l = 2 * 10 * cos(36 * M_PI / 180);
h1 = 10 * sin(36 * M_PI / 180);
h2 = 10 * sin(72 * M_PI / 180);
l1 = 10 * cos(72 * M_PI / 180);
l2 = l - l1;
while (scanf("%d", &n) != EOF) {
int i;
printf("%d\n", 4 * n + 1);
f... | 15 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
template <typename T, typename TT>
inline ostream &operator<<(ostream &os, const pair<T, TT> &t) {
return os << t.first << " " << t.second;
}
template <typename T>
inline ostream &operator<<(ostream &os, const vector<T> &t) {
for (auto i : ... | 10 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void _Print(T &&x) {
cerr << x << ")"
<< "\n";
}
template <class T, class... S>
void _Print(T &&x, S &&...y) {
cerr << x << ", ";
_Print(y...);
}
template <class T>
class compare {
public:
bool operator()(pair<T, T> &x, pair<T, T> &y) {
... | 14 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long t = 1;
while (t--) {
long long n, m;
cin >> n >> m;
long long ans = 0;
while (m > n) {
if (m % 2) {
ans++;
m++;
}
m /= 2;
ans++;
}... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
long long a[N];
int n, k;
string s;
bool calc(int mid) {
for (int i = mid; i <= n; i++) {
if (a[i] - a[i - mid] <= k) return 1;
if (mid - (a[i] - a[i - mid]) <= k) return 1;
}
return 0;
}
int main() {
ios_base ::sync_with_stdio(false);... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 100;
long long e[N], s[N];
bool w[N], l[N];
int n;
bool Win(long long s, long long e) {
if ((e & 1)) {
if (s & 1) return 0;
return 1;
}
if (s > e) return 1;
if (s * 2 > e) return (bool)(s & 1);
if (s * 4 > e) return 1;
return Win(s, e... | 19 |
#include <bits/stdc++.h>
using namespace std;
int n;
const long long INF = 1LL << 60;
long long dp[100000 + 1];
long long a[100000], b[100000];
int deq[100000 + 1];
long long f(int j, long long x) { return b[j] * x + dp[j]; }
bool check(int f1, int f2, int f3) {
long double a1 = b[f1], b1 = dp[f1];
long double a2 =... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N, K, P, X, Y;
cin >> N >> K >> P >> X >> Y;
vector<int> marks(N, 1 << 30);
int total = 0;
int lessMedian = 0;
for (int i = 0; i < K; i++) {
cin >> marks[i];
total += marks[i];
if (marks[i] < Y) lessMedian += 1;
}
if (lessMedian ... | 9 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+100;
const ll inf=1e18;
int main()
{
int T,n,l,r,pos,p,mid;
//int flag,T,n,x;
//freopen("text.in","r",stdin);
scanf("%d",&n);
printf("? %d %d\n",1,n);
fflush(stdout);
scanf("%d",&p);
if (p!=n) {printf(... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a(n + 1), last(n + 1);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
set<int> s;
for (int i = 1; i <= n; i++) s.insert(-i), last[i] = i + 1;
int steps = 0;
while (!s.empty()) {
for (set<int>::iterator it = s.b... | 11 |
#include <bits/stdc++.h>
using namespace std;
pair<int, int> edge[200000 + 324];
vector<int> adj[200000 + 324];
set<int> degree[200000 + 324];
set<int> friends;
int ans[200000 + 324];
int k;
void rem(int x) {
set<int> elem_to_remove;
for (auto bc : degree[x]) {
elem_to_remove.insert(bc);
degree[bc].erase(x)... | 14 |
#include <bits/stdc++.h>
const int md = 998244353;
const long long inf = 1e12;
const long long hs = 199;
const long double eps = 1e-9, pi = acos(-1);
using namespace std;
int n;
vector<vector<int>> g;
vector<long long> w;
int dfs(int v, int prev) {
int rtn = 1;
for (const auto &i : g[v])
if (i != prev) rtn = ma... | 17 |
#include <bits/stdc++.h>
using namespace std;
long long n, m;
map<string, string> ipton;
vector<pair<string, string>> comm;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
string name, ip;
cin >> name >> ip;
ipton[ip] = name;
}
for (int... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int n, a, b, ans;
int w[N], h[N];
int main() {
scanf("%d%d%d", &n, &a, &b);
for (int i = 1; i <= n; i++) {
scanf("%d%d", &w[i], &h[i]);
}
ans = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (i == j) continue;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
inline void chkmin(T1 &x, T2 y) {
if (x > y) x = y;
}
template <typename T1, typename T2>
inline void chkmax(T1 &x, T2 y) {
if (x < y) x = y;
}
using ll = long long;
using ld = long double;
const string FILENAME = "input";
const int M... | 12 |
#include <bits/stdc++.h>
using namespace std;
int pr[200010], a[200010], n, sum, b[200010];
int get_pr(int x) {
if (pr[x] == 0)
return x;
else
return pr[x] = get_pr(pr[x]);
}
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
b[i] = x;
int u = get_pr(i);
int v = g... | 9 |
#include <bits/stdc++.h>
using namespace std;
int k;
char s1[10010], s2[10010], s3[10010], s4[10010];
bool equals(char a[], char b[], int lena, int lenb) {
int cnt = 0;
for (int i = lena - 1, j = lenb - 1; i >= 0 && j >= 0; i--, j--) {
if (a[i] != b[j]) return 0;
if (a[i] == 'a' || a[i] == 'e' || a[i] == 'i... | 8 |
#include <bits/stdc++.h>
using namespace std;
bool debug = 0;
double eps = 1e-15;
const double pi = 3.1415926535898;
long long P = 998244853;
long long f[234567];
long long mul_mod(long long a, long long b, long long p) {
if (b < 1) return 0;
long long c = mul_mod(a, b / 2, p);
c += c;
if (b & 1) c += a;
retu... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, a, b, x = 0, y = 0;
cin >> n;
for (long long i = 0; i < n; i++) {
cin >> a >> b;
x += a;
y += b;
}
for (long long i = 0; i < n; i++) {
cin >> a >> b;
x += a;
y += b;
}
cout << x / n << ' ' << y / n << '\n';
r... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int n, m;
char s[N];
vector<int> a[N], tran;
int dp[N][(1 << 4) + 5], full;
int cnt[1 << 4];
void Init() {
cnt[0] = 0;
for (int i = 1; i < (1 << 4); i++) cnt[i] = cnt[i / 2] + (i & 1);
return;
}
void solve1() {
int s1 = 0, s2 = 0;
for (int ... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cout.precision(10);
cout << fixed;
int n;
cin >> n;
int sum = 0;
for (int i = 2; i < n; i++) {
sum += i * (i + 1);
}
cout << sum;
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long q;
cin >> q;
while (q--) {
long long n;
cin >> n;
vector<long long> v;
while (n) {
v.push_back(n % 3);
n /= 3;
}
long long res = 0;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n1, n2, k1, k2;
cin >> n1 >> n2 >> k1 >> k2;
if (n1 > n2)
cout << "First" << endl;
else
cout << "Second" << endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const int mod = 1e9 + 7;
int a[3005];
int main() {
int n;
while (cin >> n) {
int flag = 0;
for (int i = 1; i <= 1000; i++) {
if (i < 10) {
flag++;
} else if (i < 100) {
flag += 2;
} else
flag += 3;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
string a;
string f(int i) {
string b = a;
b[i]++;
if (b[i] == b[i - 1] or b[i] == b[i - 2]) b[i]++;
if (b[i] == b[i - 1] or b[i] == b[i - 2]) b[i]++;
if (b[i] - 'a' + 1 > k) return "$";
while (++i <= n + 1) {
b[i] = 'a';
if (b[i] == b[i - 1] or... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
set<int> s;
cin >> n;
long long int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
s.insert(a[i]);
}
cout << s.size();
cout << endl;
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
string s;
int main() {
int k;
while (cin >> s >> k) {
int n = s.size();
if (k > (long long)n * (n + 1) / 2) {
cout << "No such line." << endl;
} else {
vector<int> candidate(s.size());
for (int i = 0; i < s.size(); i++) {
candidate[... | 13 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.