solution stringlengths 53 181k | difficulty int64 0 13 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
struct edge {
int v, f, w, id;
};
vector<pair<long long, long long>> path;
struct MinCost {
int n;
vector<vector<edge>> e;
void init(int _n) {
n = _n;
e.resize(n + 1);
}
void add(int x, int y, int c, int w) {
e[x].push_back((edge... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int mod = (int)1e9 + 7;
set<int> buy, add, hz;
int n;
int mult(int a, int b) { return (1LL * a * b) % mod; }
int main() {
srand(time(0));
ios_base::sync_with_stdio(false);
int cnt = 1;
cin >> n;
for (int i = 1; i <= n; i++) {
string s;
int x;
cin... | 6 |
#include <bits/stdc++.h>
using namespace std;
bool debug = false;
int n, m, k;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
long long ln, lk, lm;
long long dp[35][1005], tmp[1005];
int cnt = 0;
void init() {
dp[0][0] = 1;
tmp[0] = 1;
for (int i = 1; i <= 30; i++) {
dp[i][0] = 1;
for (int j = 1; j <= ... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int base = 1000000000;
const int base_digits = 9;
struct bigint {
std::vector<int> z;
int sign;
bigint() : sign(1) {}
bigint(long long v) { *this = v; }
bigint(const std::string &s) { read(s); }
void operator=(const bigint &v) {
sign = v.sign;
z = ... | 12 |
#include <bits/stdc++.h>
using namespace std;
const long double PI = 2 * acos(0.0);
const int stdLength = 25;
const long long max_number = 1048575;
void print(vector<bool> &a) {
for (bool i : a) {
cout << i << " ";
}
cout << "\n";
}
void print(vector<int> &a) {
for (int i : a) {
cout << i << " ";
}
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int absolute(int a, int b) { return max(a, b) - min(a, b); }
class Union_Find {
vector<long long> rank;
vector<long long> parent;
long long size;
public:
int find_set(long long i) {
return (parent[i] == i) ? i : parent[i] = find_set(parent[i]);
}
bool is_s... | 3 |
#include <bits/stdc++.h>
using namespace std;
int a[10];
int main() {
int n, mv, mi, least = 1e9, leasti = -1;
scanf("%d", &n);
for (int i = 1; i <= 9; i++) {
scanf("%d", &a[i]);
if (least >= a[i]) least = a[i];
}
int average = n / least;
if (n >= least) {
for (int i = 9; i > 0; i--)
while... | 4 |
#include <bits/stdc++.h>
#define forn(i,s,t) for(register int i=(s);i<=(t);++i)
using namespace std;
const int N = 5e2 + 10;
int t, n, m; char mp[N][N];
int main() {
scanf("%d", &t);
while(t--) {
scanf("%d%d", &n, &m);
forn(i,0,n + 1) forn(j,0,m + 1) mp[i][j] = 0;
forn(i,1,n) scanf("%s", mp[i] + 1);
int lst =... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long n, p, w, d;
long long exgcd(long long a, long long b, long long &x1, long long &y1) {
if (!b) {
x1 = 1, y1 = 0;
return a;
}
long long x2, y2;
long long d = exgcd(b, a % b, x2, y2);
x1 = y2, y1 = x2 - (a / b) * y2;
return d;
}
int main() {
ios... | 6 |
#include <bits/stdc++.h>
using namespace std;
int i, j, n, m, t, k, it, res, f[60050];
vector<int> v[30050];
struct sb {
int x, y, z;
bool operator<(const sb a) const { return z < a.z; }
} s[105];
int main() {
scanf("%d%d", &n, &m);
for (i = 1; i <= n; i++) {
scanf("%d%d", &j, &k);
if (k >= 0) {
v... | 7 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const double pi = acos(-1);
const long long inf = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const int MAX = 2e5 + 10;
const long long mod = 1e9 + 7;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
char c[3] = {'R', 'G... | 3 |
#include <bits/stdc++.h>
using namespace std;
map<string, string> m;
int main() {
long long n, m = 1000000001, i, x, y(0);
cin >> n;
for (i = 0; i < n; i++) {
cin >> x;
y = y + x;
if (x % 2 == 1 && m > x) m = x;
}
if (y % 2 == 1) y = y - m;
cout << y;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 3020;
int t, n, m, bro[maxn], son[maxn], f[maxn][maxn], x[maxn], y[maxn], d;
long long ans, t1, t2;
long long qui(long long a, long long b) {
long long s = 1;
while (b) {
if (b & 1LL) s = s * a % mod;
a = a * a % mod;
... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int k;
cin >> k;
long long int sum = k + 2000;
vector<long long int> v;
v.push_back(-1);
for (int i = 1; i < 2000; i++) {
if (sum == 0)
v.push_back(0);
else {
long long int x = min(sum, 1000000 * 1ll);
sum -= x;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005, maxk = 105, maxe = 200005;
int n, m, K, S, a[maxn], f[maxn][maxk], INF = 1e9;
int fir[maxn], nxt[maxe], son[maxe], tot;
int q[maxn];
void add(int x, int y) {
son[++tot] = y;
nxt[tot] = fir[x];
fir[x] = tot;
}
void Solve(int p) {
for (int i =... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
int ans = 0;
for (int i = 1; i <= a; ++i) {
if (2 * i <= b and 4 * i <= c) ans = i + 2 * i + 4 * i;
}
cout << ans << "\n";
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using db = double;
using str = string;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pd = pair<db, db>;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<ll>;
using vd = vector<db>;
using vs = vector... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int INT_INF = 0x3f3f3f3f;
const long long LL_INF = 0x3f3f3f3f3f3f3f3f;
const long double PI = acos((long double)-1);
const int xd[4] = {1, 0, -1, 0}, yd[4] = {0, 1, 0, -1};
const int MN = 14;
int N, g[MN][MN];
long long ans[1 << MN];
vector... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, k;
cin >> n >> k;
int arr[n];
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
vector<pair<char, pair<int, int>>> ans;
int l = 0;
int mini = INT_MAX;
for (int i = ... | 3 |
#include <bits/stdc++.h>
using namespace std;
void prepare() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
vector<int> result;
int a[2005];
int main() {
prepare();
int n, p;
int begs = 0;
int ends = 0;
cin >> n >> p;
memset(a, 0, sizeof(a));
for (int i = 1; i <= n; i++) {
int temp;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const long long int INF = 1e18;
const double EPSILON = 0.001;
const int N = 1e5 + 5;
int main() {
cin.tie(NULL), cout.sync_with_stdio(true);
string s;
cin >> s;
int _up = 1, _down = 1;
for (auto c : s) {
if (c == '0') {
cout << 1... | 3 |
#include <bits/stdc++.h>
using ul = std::uint32_t;
using li = std::int32_t;
using ull = std::uint64_t;
using ll = std::int64_t;
using llf = long double;
ul n, m, k;
const ul maxn = 2e5;
const ul base = 998244353;
ul plus(ul a, ul b) { return a + b < base ? a + b : a + b - base; }
ul plus(ul a, ul b, ul c) { return plus... | 7 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n;
cin >> n;
long double d = (double)n / 10;
if (lround(d) != 0)
cout << lround(d) << "0";
else
cout << lround(d);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
solve();
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100 + 23;
int N;
int data[MAXN];
inline void swap(int &a, int &b) {
int t = a;
a = b;
b = t;
}
int main() {
cin >> N;
for (int i = 0; i < N; ++i) cin >> data[i];
for (int i = 0; i < N; ++i)
for (int j = 0; j < N - 1; ++j)
if (data[j] >... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, k, i, s;
pair<int, int> a[105];
vector<int> sol;
int main() {
cin.sync_with_stdio(false);
cin >> n >> k;
for (i = 1; i <= n; i++) {
cin >> a[i].first;
a[i].second = i;
}
sort(a + 1, a + n + 1);
for (i = 1; i <= n; i++) {
s += a[i].first;
i... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 707406378;
const int maxn = 1.5e7 + 10;
void read(long long &x) {
char ch;
bool flag = 0;
for (ch = getchar(); !isdigit(ch) && ((flag |= (ch == '-')) || 1);
ch = getchar())
;
for (x = 0; isdigit(ch); x = (x << 1) + (x << 3) + ch - 48... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, x, a = 1;
cin >> n >> x;
if (n == 1 || n == 2)
cout << a << endl;
else {
int res = n - 2;
if (res % x == 0) {
cout << res / x + 1 << endl;
} else {
cout << res /... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 255;
int dp[MAXN][MAXN][MAXN];
void init() {
for (int i = 0; i < MAXN; ++i) {
for (int j = 0; j < MAXN; ++j) {
for (int q = 0; q < MAXN; ++q) dp[i][j][q] = int(1e9);
}
}
dp[0][0][0] = -1;
}
void solve() {
int n, q;
cin >> n >> q;
s... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n, k, ans, a[2000];
int main() {
cin >> n >> k;
ans = k;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++)
for (int j = i + 1; j < n; j++) ans = max(ans, k / a[i] * a[j] + k % a[i]);
cout << ans;
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
int a[100001];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
if (n == 1) {
if (a[0] == 1)
puts("NO");
else {
puts("YES");
cout << a[0] << "\n";
}
} else if (n == 2) {
if (a[0] == 1 && a[1] == 0) ... | 7 |
#include <bits/stdc++.h>
using namespace std;
inline int min(const int &x, const int &y) { return x < y ? x : y; }
inline long long min(const long long &x, const long long &y) {
return x < y ? x : y;
}
inline double min(const double &x, const double &y) { return x < y ? x : y; }
inline int max(const int &x, const int... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n;
long long r1, r2, r3, d;
const int MAXN = 1e6 + 10;
long long cnt[MAXN], dp[MAXN][2];
long long solve(int pos, int f) {
if (pos == n) {
if (!f) return -d;
return min({r1, r2, r3}) + d;
}
long long &r = dp[pos][f];
if (r != -1) return r;
r = 1e18;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int now = 1, t = 0, n, x, y, c;
scanf("%d%d%d%d", &n, &x, &y, &c);
while (now < c) {
int l = min(x - 1, ++t);
now += max(l - max((y + t - n), 0) + 1, 0) +
max(l - max((t - y + 1), 0) + 1, 0) - (l == t);
l = min(n - x, t);
now +=... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, res;
cin >> n;
res = n / 5;
if (n % 5 != 0) res++;
cout << res;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6;
long double pmin[maxn];
long double pmax[maxn];
long double A[maxn];
long double B[maxn];
bool solve() {
int n;
if (cin >> n) {
for (int i = 0; i < n; i++) {
cin >> pmax[i];
if (i) {
pmax[i] += pmax[i - 1];
}
}
... | 8 |
#include <bits/stdc++.h>
using namespace std;
vector<int> v[100100];
int v1[100100];
int v2[100100];
int color[100100];
bool in_cycle[100100];
int getnext(int s, int eid) {
if (v1[eid] == s)
return v2[eid];
else
return v1[eid];
}
vector<vector<int> > cycles;
int stcnt = 0;
int st[100100];
int vis[100100];
m... | 8 |
#include <bits/stdc++.h>
using namespace std;
const char lend = '\n';
int n, k;
string str, res;
int add(int p) {
for (int i = p + 1; i < n; ++i) str[i] = 'a';
int c = 1;
for (int i = p; i >= 0 && c; --i) {
str[i] += c;
c = 0;
if (str[i] == 'a' + k) c = 1, str[i] = 'a';
}
if (c) return 0;
return... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 100, mod = 1e9 + 7;
struct matrix {
int n, m, a[3][3];
matrix() {
n = m = 1;
memset(a, 0, sizeof a);
}
matrix(int first, int second) {
n = first, m = second;
memset(a, 0, sizeof a);
}
matrix(int first, int second, vector<in... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
set<int> m;
int q;
for (int i = (0); i < (n); ++i) {
cin >> q;
m.insert(q);
}
bool flag = true;
while (flag) {
int k = *m.rbegin() / 2;
while (m.find(k) != m.end()) {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int h = 31;
int n, len[100005];
long long ans, inc, cst[100005], bef[100005][30];
unsigned long long hsh[100005], mix[100005];
int sum[30][100005];
char s[100005];
bool pef[100005][16 + 5];
unsigned long long Sub(int l, int r) {
return hsh[r] - hsh[l - 1] * mix[r - ... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, val = 0, mx = 0;
cin >> n;
bool flag = true;
for (long long i = 1, j = n; i <= j;) {
if (flag) {
cout << i << " ";
flag = false;
i++;
} else if (!flag) {
cout << j << " ";
j--;
flag = true;
}
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int T;
scanf("%d", &T);
while (T--) {
int n;
scanf("%d", &n);
vector<int> p(n + 1);
for (int i = 1; i <= n; ++i) {
scanf("%d", &p[i]);
}
auto rbound = [&p](int i) { return i + p[i]; };
vector<int> dp(n + 1), plan(n + 1, -1), sufmax;
vect... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const long long inf = 5e18;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
;
int t;
cin >> t;
while (t--) {
int n, m, k;
cin >> n >> m >> k;
if (k > m - 1) {
k = m - 1;
}
int a[n + 1... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long n, i, j, L, m, k, t, sum = 0, cnt, a[100009], d, rem, mod, mx, mn, v,
r, l;
string s, s1;
map<long long, long long> _mp;
vector<long long> v1, v2, v3;
vector<long long> v4[51];
set<long long> st;
set<long long>::iterator it;
int main... | 1 |
#include <bits/stdc++.h>
using namespace std;
mt19937 Rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
template <typename T>
inline void chkmax(T &x, T y) {
if (x < y) x = y;
}
template <typename T>
inline void chkmin(T &x, T y) {
if (x > y) x = y;
}
inline int read() {
int x = 0;
char c = ... | 10 |
#include <bits/stdc++.h>
using namespace std;
int a[101];
int main() {
int n, res = 0;
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", a + i);
int check;
if (a[0] == 1)
check = 1;
else
check = 0;
for (int i = 1; i < n; i++) {
if (a[i] == 1 && check == 0) {
check = 1;
} else ... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 10;
int n;
long long a[MAXN], ans;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%lld", &a[i]);
}
int i = 1;
while (i <= n) {
ans++;
if (i == n) break;
long long x = 0, y = 0;
long long pre1 = 0, pre... | 8 |
#include <bits/stdc++.h>
using namespace std;
int primes[10000010];
int p;
int low[10000010];
void ciur();
set<int> s;
int main() {
ciur();
int n, x, c;
cin >> n >> x;
while (n--) {
cin >> c;
s.insert(c);
}
if (x == 2) {
cout << 0;
return 0;
}
if (s.find(1) != s.end()) {
cout << 1;
... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long int mod = 998244353;
long long int dx[] = {0, 0, 1, -1};
long long int dy[] = {1, -1, 0, 0};
long long int m = 0, n, res = 0, k;
string s2, ch = "", s, s1 = "";
vector<pair<string, long long int> > vm;
vector<pair<pair<long long int, long long int>, long long int>... | 3 |
#include <bits/stdc++.h>
using namespace std;
char s[110000];
int main() {
scanf("%s", s);
int n = strlen(s);
int v = 0;
for (int i = 0; i < n; i++) {
if (s[i] > 'a') {
v = 1;
s[i]--;
} else {
if (v) break;
}
}
if (!v) {
s[n - 1] = 'z';
}
printf("%s\n", s);
return 0;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
using vv = vector<vector<T>>;
template <class T>
ostream &operator<<(ostream &os, const vector<T> &t) {
os << "{";
for (int(i) = 0; (i) < (t.size()); ++(i)) {
os << t[i] << ",";
}
os << "}" << endl;
return os;
}
template <class S, class T>
o... | 5 |
#include <bits/stdc++.h>
int comp(const void* a, const void* b) { return (*(int*)a - *(int*)b); }
int main() {
int t, n, i, a[1000005], k, c = 1, m, j;
scanf("%ld", &t);
for (i = 1; i <= t; i++) {
scanf("%d", &n);
for (j = 0; j < n; j++) {
scanf("%d", &a[j]);
}
qsort(a, n, sizeof(int), comp)... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
struct node {
int p, c;
bool operator<(const node &u) const { return p > u.p; }
} a[maxn], b[maxn];
int ta, tb;
char ch[5];
int u, v;
int main() {
int n, c, d;
cin >> n >> c >> d;
ta = ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int A[1001];
bool cmp(pair<int, int> a, pair<int, int> b) {
if (a.first != b.first) return a.first > b.first;
return a.second < b.second;
}
int32_t main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int n;
cin >> n;
int a, b;
cin >> a >> b;
int ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long testcase;
cin >> testcase;
while (testcase--) {
long long n;
cin >> n;
set<long long> st;
long long val;
for (long long i = 0; i < n; i++) {
cin >> val;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10, maxsq = 32000, inf = 1e6 + 1;
int a[maxn];
vector<int> pr;
struct Dinic {
int n, s, t;
vector<int> level;
struct Edge {
int to, rev, cap;
Edge() {}
Edge(int a, int b, int c) : to(a), cap(b), rev(c) {}
};
vector<Edge> G[maxn];... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long N = 1e6 + 5;
const long long inf = 1e18;
long long powermod(long long x, long long y, long long p) {
long long res = 1;
x = x % p;
while (y > 0) {
if (y & 1) res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n, l[200010], r[200010], id[200010], ans, minn = -2147480000;
bool cmp(int x, int y) { return r[x] == r[y] ? l[x] < l[y] : r[x] < r[y]; }
int main() {
scanf("%d", &n);
for (int x, y, i = 1; i <= n; i++) {
scanf("%d%d", &x, &y);
l[i] = x - y;
r[i] = x + y... | 5 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
long long n;
cin >> n;
vector<long long> tpa[6], tpb[4];
long long amt[6];
fill(amt, amt + 6, 0);
for (long long i = 0; i < n; ++i) {
long long a, b, c;
cin >> a >> b >> c;
--a;
--c;
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e6;
unsigned long long arr[N] = {}, arr2[N] = {}, n, ans = 0, a, b, sum = 0;
int main() {
cin >> n;
if (n % 2 == 0)
cout << n / 2;
else
cout << "-" << ((n + 1) / 2);
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
double a[100010];
double b[100010];
double t[100010];
int main() {
long long ax, ay, bx, by, tx, ty;
cin >> ax >> ay >> bx >> by >> tx >> ty;
int n;
cin >> n;
long long x, y;
for (int i = 0; i < n; i++) {
cin >> x >> y;
a[i] = sqrt((double)((x - ax) * (x... | 5 |
#include <bits/stdc++.h>
using namespace std;
stringstream ss;
long long mod = 1000000007LL;
int f(int *a, int n) {
int ans = 0;
for (int i = 0; i < n; i++)
for (int j = i; j < n; j++) ans += *min_element(a + i, a + j + 1);
return ans;
}
int main() {
long long n, m;
cin >> n >> m;
int a[] = {1, 2, 3, 4,... | 3 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename T>
using vec = vector<T>;
template <typename T>
using Prior = priority_queue<T>;
template <typename T>
using prior = priority_queue<T, vec<T>, greater<T>>;
const int INF = 1e9;
co... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> v;
int n, c, t1 = 0, t2 = 0, t3 = 0, w, count = 0, count_w = 0;
cin >> n;
while (n--) {
cin >> c;
v.push_back(c);
if (c == 1)
t1++;
else if (c == 2)
t2++;
else
t3++;
}
if (t1 != 0 && t2 != 0 && t3 !=... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
int c, n, k, r = 0;
cin >> n >> k;
vector<int64_t> A(n);
for (auto& a : A) cin >> a;
sort(A.begin(), A.end());
for (int i = 0; i < n; ++i) {
c = k + A[i];
if (c <= 5) r++;
}
cout << r / 3;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int day[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int f[3], v[3];
char c;
bool yes = false;
bool check() {
if (v[1] > 12) return false;
if (v[0] > day[v[1] - 1] + (v[1] == 2 && v[2] % 4 == 0 ? 1 : 0)) return false;
if (v[2] >= f[2]) return false;
i... | 4 |
#include <bits/stdc++.h>
using namespace std;
vector<string> vec_splitter(string s) {
s += ',';
vector<string> res;
while (!s.empty()) {
res.push_back(s.substr(0, s.find(',')));
s = s.substr(s.find(',') + 1);
}
return res;
}
void debug_out(vector<string> __attribute__((unused)) args,
__... | 6 |
#include<bits/stdc++.h>
#define re register
using namespace std;
typedef long long ll;
ll rd(){
ll x = 0;
char ch = getchar();
while(ch < '0' || ch > '9') {
ch = getchar();
}
while(ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x;
}
const int MOD = 998244353;
void add(int &a,... | 7 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int a, b, n;
cin >> n >> a >> b;
vector<int> A(n);
for (int &x : A) cin >> x;
sort(A.begin(), A.end());
if (A[b] - A[b - 1] == 0) {
cout << "0\n";
return;
}
cout << A[b] - A[b - 1] << "\n";
}
int main() {
ios_base::sync_with_stdio(0)... | 0 |
#include <bits/stdc++.h>
std::map<int, int> track_points;
std::vector<std::vector<std::pair<int, std::pair<int, int> > > >
graph_of_tracks;
const int MAX = 1001;
const int MAXINT = 1000000001;
void Dijcstra(int start_p = 0, int end_p = -1) {
if (end_p == -1) {
end_p = graph_of_tracks.size();
}
std::set<st... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 30000 + 10;
const int maxm = 600000 + 10;
const int P = 1e7 + 19;
const int Q = 1e9 + 7;
struct Edge {
int next, v;
Edge() {}
Edge(int next, int v) : next(next), v(v) {}
} e[maxm];
struct Exhibit {
int l, r, v, w;
Exhibit() {
l = 1;
r = 10... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string n, m;
cin >> n >> m;
int cn[26] = {0}, cm[26] = {0};
for (int i = 0; i < n.size(); i++) cn[n[i] - 'a']++;
for (int i = 0; i < m.size(); i++) cm[m[i] - 'a']++;
int res = 0;... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, flag = 1;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 1; i < n; i++) {
if (a[i - 1] <= a[i]) {
cout << "YES" << endl;
flag = 0;
break;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)1e5 + 10;
int ans[maxn], cnt, data[maxn];
vector<int> son[maxn];
void dfs(int u, int fa, int now, int next) {
if (now) data[u] ^= 1;
if (data[u]) {
ans[cnt++] = u;
now ^= 1;
}
for (vector<int>::iterator it = son[u].begin(); it != son[u]... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 605;
const int M = 605;
int n, m, k;
int a[M], b[M];
int deg[N];
vector<int> edges_matched_to_vertex[N];
int col[M];
const int INF = 1000000000;
struct Edge {
int from, to, cap, flow, index;
Edge(int from, int to, int cap, int flow, int index)
: from... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long n, x, y;
long long dp[30000050];
long long minn(long long a, long long b) {
if (a > b) return b;
return a;
}
int main() {
cin >> n >> x >> y;
memset(dp, 0x3f, sizeof(dp));
dp[0] = 0;
dp[1] = x;
for (int i = 2; i <= n; i++) {
if (i % 2) {
dp... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
int n, k, d;
int dem = 0, a[200005], mi = 1000000, i;
vector<int> cou;
for (i = 0; i < 1000003; i++) cou.push_back(0);
cin >> n >> k >> d;
t--;
for (i = 0; i < n; i++) {
cin >> a[i];
if (cou[a[i]] == 0) {
cou[a[i... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
cin >> s;
map<char, int> mmap;
for (int i = 0; i < s.size(); i++) {
mmap[s[i]]++;
}
int a = 0, b = 0;
for (int i = 0; i <= s.size(); i++) {
if (mmap['z'] == i and mmap['r'] == i) {
int x = mmap['e'] - m... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
int n;
cin >> n;
int a[n], g[n];
int sa = 0, sg = 0;
char ans[n];
for (int i = 0; i < n; ++i) {
cin >> a[i] >> g[i];
}
for (int i = 0; i < n; ++i) {
sa += a[i];
if (sa <= 500) {
ans[i] = 'A';... | 3 |
#include <bits/stdc++.h>
int main(void) {
int n, i;
scanf("%d", &n);
for (i = 1; i <= n * 2 / 3; i++) printf("0 %d\n", i);
for (i = 1; i <= n - n * 2 / 3; i++) printf("3 %d\n", i * 2);
return 0;
}
| 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int arr[100005];
int n, k;
cin >> n >> k;
for (int i = 0; i < n; cin >> arr[i++])
;
int ass[260];
for (int i = 0; i < 260; ass[i++] = -1)
;
if (arr[0] == 0) ass[0] = 0;
for (int i = 0; i < n; i++) {
if (ass[arr[i]] == -1) {
for... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, c = 0;
cin >> t;
for (int i = 0; i < t; i++) {
int a, b;
cin >> a >> b;
if (a != b) {
c++;
}
}
if (c) {
cout << "Happy Alex";
} else {
cout << "Poor Alex";
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
using namespace std;
namespace ywy {
inline int get() {
int n = 0;
char c;
while ((c = getchar()) || 23333) {
if (c >= '0' && c <= '9') break;
if (c == '-') goto s;
}
n = c - '0';
while ((c = getch... | 7 |
#include <bits/stdc++.h>
using namespace std;
int a[1000000];
vector<int> m;
int main() {
for (int i = 1; i <= 200000; i++) a[i] = -1000000;
int n;
cin >> n;
for (int step = 1; step <= n; step++) {
int x, y;
cin >> x >> y;
m.clear();
int k = 0;
for (int i = 1; i * i <= x; i++)
if ((x %... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long oo = 100000000000000000LL;
const double eps = 1e-9;
const int maxn = 100000 + 10;
bool compare(pair<int, int> a, pair<int, int> b) {
if (a.first == b.first) return a.second > b.second;
return a.first < b.first;
}
struct edge {
pair<int, int> u, v;
};
v... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string s;
cin >> s;
swap(s[1], s[4]);
swap(s[1], s[2]);
int n = stoi(s);
long long ans = 1;
for (int i = 0; i < 5; i++) {
ans *= n;
ans %= 100000;
}
cout << setfill... | 3 |
#include <bits/stdc++.h>
using namespace std;
void Genawy() {
std::ios_base::sync_with_stdio(0);
cin.tie(NULL);
}
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int n, cost[305];
int length[305];
map<pair<int, int>, int> dp;
int solve(int ind, int gc) {
if (ind == n) return gc == 1 ? 0 : 1e9;
if (... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 5;
const int mod = 1e9 + 7;
int n, m;
int c[maxn];
int lowbit(int x) { return x & (-x); }
void add(int pos, int x) {
while (pos <= n) {
c[pos] += x;
pos += lowbit(pos);
}
}
void update(int l, int r) { add(l, 1), add(r + 1, -1); }
int ge... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
string p[n], e[m];
if (n > m) cout << "YES";
if (n < m) cout << "NO";
if (n == m) {
for (int i = 0; i < n; i++) cin >> p[i];
for (int i = 0; i < n; i++) cin >> e[i];
int t = 0;
for (int i = 0; i < n; i++) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int a[200005], b[200005];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", a + i);
}
vector<pair<int, int> > v;
for (int i = 0; i < n; i++) {
scanf("%d", b + i);
v.push_back(make_pair(b[i], i));
}
sort(v.begin(), v.e... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long readi() {
long long input = 0;
char c = ' ';
while (c < '-') {
c = getchar();
}
bool negative = false;
if (c == '-') {
negative = true;
c = getchar();
}
while (c >= '0') {
input = 10 * input + (c - '0');
c = getchar();
}
if ... | 9 |
#include <bits/stdc++.h>
int main() {
int arr1[5][5], i, m, t, q, n, j, sum = 0;
for (i = 0; i < 5; i++) {
for (j = 0; j < 5; j++) {
scanf("%d", &arr1[i][j]);
}
}
for (i = 0; i < 5; i++) {
for (j = 0; j < 5; j++) {
if (arr1[i][j] == 1) {
t = i;
q = j;
}
}
}
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 500005;
int n, m, t1, t2, t3, lim;
int dep[N], vis[N], fg[N];
vector<int> g[N];
vector<int> sta;
void dfs1(int p) {
sta.push_back(p);
vis[p] = 1;
for (int q : g[p]) {
if (!vis[q]) {
dep[q] = dep[p] + 1;
dfs1(q);
} else {
if (dep... | 8 |
#include <bits/stdc++.h>
using namespace std;
int dcmp(double a, double b) {
return fabs(a - b) <= 0.00000000000001 ? 0 : (a > b) ? 1 : -1;
}
int p[1000000 + 9], dp[1000009];
int maxi = 1000009;
int main() {
int i, n, no, b;
cin >> n;
for (i = 0; i < n; i++) {
cin >> no >> b;
p[no] = b;
}
if (p[0] >... | 4 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> my;
struct state {
int len, link;
int nexto[28];
};
const int MAXLEN = 2005000;
state st[MAXLEN];
int vis[MAXLEN], cnt[MAXLEN], casio = 1;
int sz = 0, last = 0;
void sa_init() {
sz = last = 0;
st[0].len = 0;
st[0].link = -1;
for (int i = 0... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, cnt = 0, j, x;
double c;
cin >> n;
for (i = 1; i <= n; i++) {
for (j = i; j <= n; j++) {
c = sqrt(i * i + j * j);
x = (int)c;
if (x > n) break;
if (x == c) cnt++;
}
}
cout << cnt << endl;
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
long long read() {
register long long x = 0, w = 1;
register char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') w = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = (x << 3) + (x << 1) + ch - '0';
ch = getchar();
}
ret... | 8 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
const int inf = (int)1e9;
const int mod = inf + 7;
const double eps = 1e-9;
const double pi = acos(-1.0);
string second, tmp;
int n, m;
string name[5050];
vector<string> v[5050];
vector<int> g[5050];
map<string, int> id;
int val[50... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, count1 = 0, count2 = 0;
cin >> n >> m;
int a[n], b[m];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < m; i++) {
cin >> b[i];
}
sort(a, a + n);
sort(b, b + m);
for (int i = 0; i < n; i++) {
for (int j =... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 19999999;
int pos = 0, neg = 0;
int total = 0, mini = inf;
int n;
int main() {
scanf("%d", &n);
int a;
for (int i = 1; i < n * 2; i++) {
scanf("%d", &a);
if (a < 0) {
neg++;
a = -a;
} else
pos++;
total += a;
mini =... | 5 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.