solution stringlengths 53 181k | difficulty int64 0 13 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000;
int n;
int deg[maxn], par[maxn], dist[maxn];
vector<int> path;
vector<int> graph[maxn];
int diam(int c) {
int ret = c;
for (int i : graph[c]) {
if (i == par[c]) continue;
par[i] = c, dist[i] = dist[c] + 1;
int temp = diam(i);
if ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n;
long long a[111111];
int c[66], cn, d[66][111111], x[111111], res[111111];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; ++i) scanf("%lld", &a[i]);
for (int t = 0; t < 2; ++t) {
for (int j = 60; j >= 0; --j) {
int cnt = 0;
for (int i = 0;... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int MX = 300005;
long long n, m, k;
struct node {
int id;
long long pos;
long long dir;
} no[MX];
int now[MX];
int ans[MX];
bool cmp(node a, node b) {
if (a.pos < b.pos) return true;
return false;
}
int main() {
char ss[5];
scanf("%I64d%I64d%I64d", &n, &... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a[200001], i, k = 1, n, ans = 0;
cin >> n;
for (i = 1; i <= n; i++) cin >> a[i];
sort(a + 1, a + n + 1);
for (i = 1; i <= n; i++) {
if (a[i] >= k) {
ans++;
k++;
}
}
cout << ans;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
char s[N];
bool isLetter(char c) {
if (c >= 'a' && c <= 'z') return true;
if (c >= 'A' && c <= 'Z') return true;
return false;
}
int main() {
scanf("%s", s);
int n = strlen(s);
long long ans = 0;
for (int i = 0; i < n; i++) {
if (s[i... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int dx[] = {0, 0, 1, 1}, dy[] = {0, 1, 0, 1};
vector<string> F;
void flip(int x, int y, int t) {
for (int k = 0; k < 4; k++)
if (k ^ t) F[x + dx[k]][y + dy[k]] ^= 1;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
((void)0);
... | 5 |
#include <bits/stdc++.h>
using namespace std;
inline int gi() {
int data = 0, m = 1;
char ch = 0;
while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
if (ch == '-') {
m = 0;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
data = (data << 1) + (data << 3) + (ch ^ 48);
ch = getchar(... | 10 |
#include <cstdio>
#include <iostream>
#include <cstring>
const int Max=2e5+5;
int t, cream, a[Max], b[Max], n;
int main(){
// freopen("data.in", "r", stdin);
scanf("%d", &t);
for(int casenum=0; casenum<t; casenum++){
memset(b, 0, sizeof(b));
cream=0;
scanf("%d", &n);
for(int i=0; i<n; i++){
scanf("%d", ... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXN = 300000;
int n;
int a[MAXN];
int nxt[MAXN + 1];
map<int, int> mp[MAXN + 1];
int mpidx[MAXN + 1];
int len[MAXN + 1];
long long solve() {
nxt[n] = -1;
mpidx[n] = n, mp[n].clear(... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a[1000], count = 0, s = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
s += a[i];
}
for (int i = 0; i < n; i++) {
if ((s - a[i]) % 2 == 0) count++;
}
cout << count;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int o = 0, f = 0;
string s;
cin >> s;
stack<int> stk;
for (int i = 0; i < s.size(); i++) {
stk.push(s[i]);
if (s[i] == '(') {
o += 1;
}
if (s[i] == ')' && o == 0) {
f += 1;
stk.pop();
}
if (s[i] == ')' && o !=... | 3 |
#include <bits/stdc++.h>
using namespace std;
int N, M, K, SN, SM, SK, Q;
priority_queue<long long int, vector<long long int>, greater<long long int> >
heap;
struct node {
long long int x, y;
} ar[100007];
bool operator<(const node &a, const node &b) { return a.x < b.x; }
void oku() {
scanf("%d %d %d", &N, &M, ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
int n, m, w[100000];
int i;
scanf("%d%d", &n, &m);
for (i = 0; i < m; i++) scanf("%*d%d", &w[i]);
sort(w, w + m, greater<int>());
int qtde = 1;
long long need;
for (i = m; i > 0; i--) {
if (i & 1)
need = 0;
else
need = (i... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char input[101];
scanf("%s", input);
char temp[11];
map<string, int> mp;
for (int i = 0; i < 10; ++i) {
scanf("%s", temp);
mp[temp] = i;
}
string s;
for (int i = 0; input[i]; ++i) {
s += input[i];
if (s.size() == 10) {
prin... | 0 |
#include <bits/stdc++.h>
int main() {
int n, now = 0;
scanf("%d", &n);
for (int x, y, res, i = 1; i <= n; i++) {
scanf("%d %d", &x, &y);
if (x > now)
now = x;
else {
res = (now - x) % y;
now += (y - res);
}
}
printf("%d\n", now);
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
int n, l0;
vector<int> x, l;
scanf("%d", &n);
int *a = new int[n + 1];
for (int i = 1; i <= n; i++) scanf("%d", a + i);
for (int i = 1; i <= n - 2; i++) {
if (a[i] == 1) {
l0 = 1;
for (int j = 2; j <= (n - i) / 2; ++j) {
... | 9 |
#include <bits/stdc++.h>
using namespace std;
void print(vector<int> v) {
for (int i = 0; i < v.size(); i++) {
cout << v[i] << " ";
}
cout << endl;
}
void solve() {
int n, k;
cin >> n >> k;
if (n == k) {
cout << -1 << endl;
} else {
for (int i = 1; i <= n - k - 1; i++) {
cout << i + 1 <<... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e6 + 50;
const long long mod = 1e9 + 7;
string s;
long long n, cnt;
long long dp[4];
inline long long fpow(long long a, long long p) {
long long res = 1;
for (; p; p >>= 1, a *= a, a %= mod)
if (p & 1) res *= a, res %= mod;
return res;
}
si... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
vector<pair<int, int>> ta;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
for (int i = 0; i < n / 2; ++i) {
for (int j = 0; j < m; ++j) {
cout << i + 1 << ' ' << j + 1 << '\n';
cout << n... | 5 |
#include <bits/stdc++.h>
using namespace std;
struct UnionFind {
vector<int> size;
vector<int> par;
public:
UnionFind(int n) : size(n, 1), par(n) {
for (int i = 0; i < n; i++) par[i] = i;
}
void unite(int x, int y) {
x = find(x), y = find(y);
if (x == y) return;
if (size[x] < size[y]) {
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
int a[430] = {
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37,
41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89,
97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151,
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int32_t INFint = 1e9;
const long long INFll = 1e18;
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
int n, k;
cin >> n >> k;
string arr;
cin >> arr;
int hash[26];
for (int i = 0; i < 26; i++) hash[i] = 0;
int count = 0;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
char s[110000];
struct node {
char c;
int ind;
};
int mark[110000];
stack<node> sk;
int main() {
int n, m, i, j;
node u, v;
while (scanf("%s", s) != EOF) {
int len = strlen(s);
memset(mark, 0, sizeof(mark));
while (!sk.empty()) sk.pop();
for (i = 0... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 5e5 + 10, mod = 998244353;
long long bexp(long long a, long long b) {
a %= mod;
long long res = 1;
while (b) {
if (b & 1) res = res * a % mod;
a = a * a % mod;
b >>= 1;
}
return res;
}
long long inv(long long x) { return bexp(x, mod... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 50;
const int iinf = INT_MAX / 2;
const long long linf = LONG_MAX / 2;
const int MOD = 1e9 + 7;
inline int read() {
int X = 0, w = 0;
char ch = 0;
while (!isdigit(ch)) {
w |= ch == '-';
ch = getchar();
}
while (isdigit(ch)) X = (X << 3) + (X ... | 9 |
#include <bits/stdc++.h>
int i, n, d[200010];
long long s, A, j, k;
int main() {
scanf("%d%I64d", &n, &A);
for (i = 0; i < n; i++) {
scanf("%d", &d[i]);
s += d[i];
}
for (i = 0; i < n; i++) {
j = n - 1 - A + d[i];
k = A - 1 - s + d[i];
printf("%I64d%c", (j > 0 ? j : 0) + (k > 0 ? k : 0),
... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
inline void chmin(A &a, B b) {
if (a > b) a = b;
}
template <typename A, typename B>
inline void chmax(A &a, B b) {
if (a < b) a = b;
}
signed main() {
long long N;
cin >> N;
vector<long long> cnt(5);
long long sum = 0;
for (l... | 6 |
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:400000000")
int n, a[200010], b[200010], f[200010];
int main() {
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++) {
int x;
cin >> x;
f[x - 1] = i;
}
for (int i = 0; i < n; i++) b[i] = f[a[i]... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
struct matrix {
int M[4][4];
matrix() { memset(M, 0, sizeof(M)); }
};
matrix one, stand;
matrix operator*(matrix M1, matrix M2) {
matrix M3;
for (int i = 0; i < 4; ++i)
for (int j = 0; j < 4; ++j)
for (int k = 0; k < 4; ++k)
... | 8 |
#include <bits/stdc++.h>
char Input[500020];
using namespace std;
struct Edge {
int to, next;
} E[500020 << 1];
int In[500020], qaq;
int T, N, head[500020], A, qwq, B, i, j, ans, cnt;
inline void Add(int u, int v) {
E[++cnt].to = v, In[v]++;
E[cnt].next = head[u], head[u] = cnt;
E[++cnt].to = u, In[u]++;
E[cn... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
set<pair<long, long> > s;
vector<pair<long, long> > v;
set<pair<long, long> >::iterator itr;
pair<long, long> p;
long n, m;
cin >> n >> m;
long a, b;
cin >> a >> b;
for (int i = 1; i <= n; i++) {
long x, y;
cin >> x >> y;
long num ... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long n;
const long long N = 1e6 + 5;
long long Tree[4 * N];
long long query(long long x, long long l, long long r, long long k) {
if (l == r) {
return l;
}
long long mid = (l + r) / 2;
if (Tree[2 * x] >= k) {
return query(2 * x, l, mid, k);
} else {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
long long b, d, s;
cin >> b >> d >> s;
if ((b == 0 && d == 0 && s == 0) || (b == 1 && d == 0 && s == 0) ||
(b == 0 && d == 1 && s == 0) || (b == 0 && d == 0 && s == 1)) {
cout << 0;
return 0;
}
if (b >... | 2 |
#include <bits/stdc++.h>
using namespace std;
inline int re_ad() {
int x = 0, f = 1;
char ch = getchar();
while (ch > '9' || ch < '0') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') x = x * 10 + (ch ^ 48), ch = getchar();
return x * f;
}
int n, k, q;
int a[200010], b[20001... | 12 |
#include <bits/stdc++.h>
using namespace std;
template <typename S, typename T>
void fill_(S& buf, T x) {
fill(reinterpret_cast<T*>(&buf),
reinterpret_cast<T*>(&buf) + sizeof(buf) / sizeof(T), x);
}
template <typename T, int N>
inline int countof(const T (&)[N]) {
return N;
}
template <typename T>
inline vec... | 5 |
#include <bits/stdc++.h>
using namespace std;
static inline void canhazfast() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
}
template <typename T>
T gcd(T a, T b) {
return b == 0 ? a : gcd(b, a % b);
}
template <typename T>
T extgcd(T a, T b, T &x, T &y) {
T x0 = 1, y0 = 0, x1 = 0,... | 4 |
#include <bits/stdc++.h>
using namespace std;
using ld = double;
const ld eps = 1e-9;
int n , d , b[100010] , c[100010] , traceid[100010][11] , tracemd[100010][11];
ld a[100010] , dp[100010][11];
bool greate(ld a , ld b) {
return a - b > eps;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(... | 6 |
#include <bits/stdc++.h>
using namespace std;
inline int mod(int n) { return (n % 1000000007); }
int cnt[112345] = {0};
int v[112345];
int n, m;
struct query {
int id, l, r, ans;
bool operator<(const query& b) const {
return l / (int)sqrt(n) < b.l / (int)sqrt(n) ||
l / (int)sqrt(n) == b.l / (int)sqrt... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 100;
int sx, sy;
int main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int n;
cin >> n;
cin >> sx >> sy;
int l = 0, r = 0, u = 0, d = 0;
for (int i = 1, x, y; i <= n; ++i) {
cin >> x >> y;
if (x < sx) ++l;
if (x > sx... | 2 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int f = 1, x = 0;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
inline void write(int x... | 7 |
#include <bits/stdc++.h>
using namespace std;
typedef struct node {
int l;
int r;
int id;
} ss;
int __an = 0;
ss ans[1000006];
int ak[1000006];
int bit[1000006];
map<int, int> my;
int a[1000006];
int b[1000006];
bool cmp(node p, node q) { return p.r < q.r; }
int sum(int i) {
int ask = 0;
while (i > 0) {
a... | 6 |
#include <bits/stdc++.h>
using namespace std;
class BIT {
std::vector<int> bit;
public:
BIT(int size) : bit(size + 1, 0) {}
void add(int i, int x) {
i++;
while (i < (int)bit.size()) {
bit[i] += x;
i += i & -i;
}
}
int sum(int a) {
a++;
int res = 0;
while (0 < a) {
r... | 3 |
#include <bits/stdc++.h>
using namespace std;
struct node {
long long v;
bool c;
} arr[12000];
bool comparator(node a, node b) { return a.v < b.v; }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long i, j, p, v, l, n = 0, a, ans = 0;
cin >> a;
string s;
cin >> s;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios ::sync_with_stdio(false);
ll n;
cin >> n;
if (n % 3 != 0) {
cout << "0\n";
return 0;
}
n /= 3;
int ans = 0;
vector<ll> divs;
for (ll i = 1; i * i <= n; i++)
if (n % i == 0) divs.push_back(i);
int m = div... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, c = 0;
cin >> n;
string s;
cin >> s;
for (int i = 0; i < s.length(); i++)
if (s[i] == '1') c++;
int ans = n + c;
for (int i = 0; i < s.length(); i++) {
if (s[i] == '1') {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const int M = 1e6 + 10;
const int mod = 1e9 + 7;
long long phi[N], vis[N], prime[N];
vector<int> vv[N];
int cnt;
void init() {
phi[1] = 1;
for (int i = 2; i < N; i++)
if (!phi[i]) {
for (int j = i; j < N; j += i) {
if (!phi[j]) ... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long len[100005];
long long rem[100005];
long long dif[100005];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
for (int i = (1); i <= (n); i += (1)) cin >> len[i];
string S;
cin >> S;
long long sta = 0, tme = 0;
bool water = 0,... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string str;
cin >> str;
int dp[n];
map<int, int> firstocc;
dp[0] = str[0] == '0' ? -1 : 1;
firstocc[dp[0]] = 0;
firstocc[0] = -1;
int ans = 0;
for (int i = 1; i < n; i++) {
dp[i] = str[i] == '0' ? dp[i - 1] - 1 : dp[i ... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100000;
const long long INF = 1000000000000000;
int a[N];
int main() {
int t;
cin >> t;
for (int q = 0; q < t; q++) {
int n, k;
cin >> n >> k;
for (int j = 0; j < n; j++) {
cin >> a[j];
}
long long answer = -INF;
for (long l... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
int evn = 0, odd = 0;
while (n--) {
int x;
cin >> x;
if (x % 2)
odd++;
else
evn++;
}
if (odd % 2)
cout << odd;
else
cout << evn;
return 0;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int arr[200];
int main() {
cin >> n >> m;
for (int i = 0; i < m; i++) cin >> arr[i];
if (m < n)
cout << 0;
else if (m == n)
cout << 1;
else {
vector<int> v;
for (int i = 0; i < m; i++) {
bool ok = true;
for (int j = 0; j < v.s... | 2 |
#include <bits/stdc++.h>
int main() {
int testcase, num;
scanf("%d", &testcase);
for (int a = 0; a < testcase; a++) {
scanf("%d", &num);
int arr[num], total = 0;
for (int b = 0; b < num; b++) {
scanf("%d", &arr[b]);
}
int flag = 1;
for (int c = 1; c < num; c++) {
if (arr[c] != ... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <typename S, typename T>
ostream& operator<<(ostream& out, pair<S, T> const& p) {
out << '(' << p.first << ", " << p.second << ')';
return out;
}
template <typename T>
ostream& operator<<(ostream& out, vector<T> const& v) {
long long l = v.size();
for (long... | 6 |
#include <bits/stdc++.h>
using namespace std;
bool found;
int n, x, nums[1000];
void Greedy() {
int median = (n + 1) / 2;
sort(nums, nums + n);
if (nums[--median] == x) {
printf("0");
return;
}
int smaller, larger;
if (found) {
int index = -1;
for (int i = 0; nums[i] <= x && i < n; i++)
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 26, MOD = 1e9 + 7;
int a[N][N], tmp[N], mx[N], sum[N], dp[1 << (N - 6)];
string s[N];
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
memset(dp, 63, sizeof(dp));
dp[0] = 0;
int n, m;
cin >> n >> m;
for (int i = 0; i ... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 100005;
int son[MAX];
double ans[MAX];
double fact[MAX];
vector<int> graph[MAX], ng[MAX];
int getSon(int u, int dad) {
son[u] = 1;
for (int i = 0; i < graph[u].size(); i++) {
int v = graph[u][i];
if (v == dad) continue;
ng[u].push_back(v);
... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long n, q;
const long long nax = 2e5 + 4;
vector<long long> cnt;
long long a[nax];
void solve() {
cin >> n >> q;
cnt.resize(43);
for (long long i = 1; i <= n; ++i) {
cin >> a[i];
cnt[__builtin_ctz(a[i])]++;
}
sort(a + 1, a + n + 1);
for (long long i... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, n, a[201], i, k = 0, s = 0, j;
cin >> t;
for (i = 1; i <= t; i++) {
cin >> n;
for (j = 0; j <= n - 1; j++) {
cin >> a[j];
s = s + a[j];
}
for (j = 0; j <= n - 1; j++) {
if (a[j] == 0) {
k++;
}
}
... | 0 |
#include <bits/stdc++.h>
int main() {
short int q;
scanf("%hi", &q);
while (q--) {
short int n;
scanf("%hi", &n);
short int Cnt[2049] = {0};
for (short int i = 0; i < n; i++) {
int a;
scanf("%i", &a);
if (a < 2049) Cnt[a]++;
}
for (short int i = 1; i < 1025; i *= 2) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
namespace Fast {
template <typename __VariableName>
inline __VariableName read() {
__VariableName __X = 0, __W = 1;
char __c = getchar();
while (__c < '0' || __c > '9') {
if (__c == '-') __W = -1;
__c = getchar();
}
while (__c >= '0' && __c <= '9') __X = _... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int c=200002;
int w, n, d[c], ml[c], maxi, msp;
vector<int> sz[c];
bool v[c];
void dfs(int a) {
int ert=n;
v[a]=true;
if (sz[a].size()==1) {
ert=d[a];
}
for (int x:sz[a]) {
if (!v[x]) {
d[x]=d[a]+1;
dfs(x);
... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int M = 2000010;
const int INF = 1e6;
int n, k, x;
vector<int> v[2];
int f[2][M];
bool flag = false;
inline void Min(int &x, int y) {
if (y < x) x = y;
}
bool pd[1010];
int main() {
scanf("%d%d", &n, &k);
for (int i = 0; i < k; i++) {
scanf("%d", &x);
if... | 7 |
#include <bits/stdc++.h>
int main() {
int a, b, r;
scanf("%d %d %d", &a, &b, &r);
r *= 2;
if (r > a || r > b) {
printf("Second\n");
return 0;
}
printf("First\n");
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2000;
const int INF = 0x3f3f3f3f;
const int MOD = 1000003;
template <class T>
void Read(T &x) {
x = 0;
char c = getchar();
bool flag = 0;
while (c < '0' || '9' < c) {
if (c == '-') flag = 1;
c = getchar();
}
while ('0' <= c && c <= '9') ... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long d[200001];
int main() {
int n;
cin >> n;
if (n == 1)
cout << 1;
else {
for (int i = 2; i <= n; i++) cout << i << " ";
cout << 1;
}
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string a, b, c, d;
cin >> a >> b >> c >> d;
int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
if ((a.size() - 2) >= (b.size() - 2) * 2 &&
(a.size() - 2) >= (c.size() - 2) * 2 &&
(a.size() - 2) >= (d.size() - 2) * 2) {
c1 = 1;
} else if ((a.size() - ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 2, M = 2e5 + 2;
int a[N], lj[M], nxt[M], fir[N], dfn[N], top[N], hc[N], siz[N], f[N], dep[N],
st[N];
int n, m, q, i, x, y, c, bs, tp, ance, ans;
inline void read(int &x) {
c = getchar();
while ((c < 48) || (c > 57)) c = getchar();
x = c ^ 48;
... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n;
cin >> n;
long long c = 0;
while (n > 0) {
n = n >> 1;
c++;
}
cout << c;
return 0;
}
| 2 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
const int maxN = 1100000;
int d[maxN];
int n, m;
int main() {
scanf("%d%d", &n, &m);
for (int i = 0; i < m; ++i) {
int u, v;
scanf("%d%d", &u, &v);
++d[u];
++d[v];
}
long long N = n;
long long total = N *... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long n, m = 0, k = 0, ds;
bool test = false, test1 = false;
long long const N = 1e5 + 7;
long long const oo = 1000000007;
long long nChoosek(long long n, long long k) {
if (k > n) return 0;
if (k * 2 > n) k = n - k;
if (k == 0) return 1;
long long result = n;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-6;
inline int dcmp(double first) {
if (fabs(first) < eps)
return 0;
else
return first < 0 ? -1 : 1;
}
struct Point {
double first, second;
Point(double first = 0, double second = 0) : first(first), second(second) {}
void read() { scan... | 6 |
#include <bits/stdc++.h>
int main() {
int m, n;
int a, b;
int ans = 0;
scanf("%d%d", &n, &m);
a = 0;
while (a * a <= m) {
b = m - a * a;
if (b * b + a == n) ans++;
a++;
}
printf("%d", ans);
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int n, m, c, Q, sl, fh, fa[100010];
set<pair<int, int> > ex[100010];
set<int> edge[100010];
int rd() {
sl = 0;
fh = 1;
char ch = getchar();
while (ch < '0' || '9' < ch) {
if (ch == '-') fh = -1;
ch = getchar();
}
while ('0' <= ch && ch <= '9') sl = sl * ... | 8 |
#include <bits/stdc++.h>
using namespace std;
const double ep = 1e-12;
const double pi = acos(-1);
struct pnt {
double x, y;
pnt(double x = 0, double y = 0) : x(x), y(y) {}
inline pnt operator-(const pnt &a) const { return pnt(x - a.x, y - a.y); }
inline pnt operator+(const pnt &a) const { return pnt(x + a.x, y... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 110;
long long a[N];
int n;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%I64d", a + i);
}
long long ans = 0;
for (int i = 1; i <= n; ++i) {
ans += (a[i] - 1) * i + 1;
}
printf("%I64d\n", ans);
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
map<int, int> m;
long long k, b, n, ans0, ans, x, sum[1000001], cnt[1000001];
int main() {
cin >> k >> b >> n;
if (!b) {
for (long long i = 1; i <= n; i++) {
cin >> x;
cnt[0] = (!x) ? (cnt[0] + 1) : 0;
ans += cnt[0];
}
cout << ans << endl;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, count = 1;
cin >> n;
int x;
for (int i = 1; i <= n; i++) {
if (i == 1) {
cin >> x;
continue;
}
int y;
cin >> y;
if (y != x) count++;
x = y;
}
cout << count;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int c, d, n, m, k;
int dp[10010];
int cal(int rem) {
if (rem <= 0) return 0;
int &ret = dp[rem];
if (ret != -1) return ret;
ret = min(c + cal(rem - n), d + cal(rem - 1));
return ret;
}
int main() {
cin >> c >> d >> n >> m >> k;
for (int i = 0; i <= n * m; i++)... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 211111;
const long long mod = 998244353;
long long n, m, a[maxn], b[maxn], lst[maxn], res = 1;
map<long long, long long> mm;
int main() {
memset(lst, -1, sizeof(lst));
scanf("%lld%lld", &n, &m);
for (long long i = 0; i < n; i++) scanf("%lld", &a[i]);
... | 6 |
#include <bits/stdc++.h>
int g[105][105], n, m, a, b, ans = 3000, Max, Min;
int down(int ii, int jj, int a, int b) {
int an = 0;
for (int i = ii; i <= ii + a; i++)
for (int j = jj; j <= jj + b; j++)
if (g[i][j]) an++;
return an;
}
int main() {
for (int i = 1; i <= 100; i++)
for (int j = 1; j <= 10... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, m;
cin >> n >> m;
map<long long int, long long int> mp;
for (long long int i = 0; i < m; i++) {
long long int h[4] = {0};
long long int x, y, z;
cin >> x >> y >> z;
if (i == 0) {
mp[x] = 1;
mp[y] = 2;
m... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long ans;
int a[100005];
int c[100005];
int d[100005];
int e[100005];
vector<int> b[100005];
int main() {
int n;
cin >> n;
int i;
for (i = 1; i <= n; i++) scanf("%d", &a[i]), b[a[i]].push_back(i);
a[0] = n + 1;
a[n + 1] = n + 1;
for (i = 1; i <= n; i++) {... | 6 |
#include <bits/stdc++.h>
long long permutation[6][3] = {{0, 1, 2}, {0, 2, 1}, {1, 0, 2},
{1, 2, 0}, {2, 0, 1}, {2, 1, 0}};
long long coord[8][3];
long long coord2[8][3];
bool chosen[8];
bool chosen2[8];
long long position[8];
bool recur3() {
for (long long k = 4; k < 8; ++k) {
chose... | 6 |
#include <bits/stdc++.h>
using namespace std;
vector<string> Vect;
int main() {
ios::sync_with_stdio(0);
long long n;
cin >> n;
string s;
for (int i = 0; i < n; ++i) {
cin >> s;
Vect.push_back(s);
}
string res;
int size = Vect[0].size();
for (int j = 0; j < size; ++j) {
char d = '#';
f... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int v[10] = {2, 7, 2, 3, 3, 4, 2, 5, 1, 2};
int x, y, z;
while (cin >> z) {
x = z / 10;
y = z % 10;
cout << v[x] * v[y] << '\n';
}
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 19;
long long dp[1 << N][N], ans[N][N];
long long sum;
int n, m;
bool adj[N][N];
int main() {
cin >> n >> m;
for (int i = 0; i < m; i++) {
int u, v;
cin >> u >> v;
u--, v--;
adj[u][v] = adj[v][u] = true;
}
for (int num = 1; num < (1 << ... | 7 |
#include <bits/stdc++.h>
using namespace std;
bool combPossible(int n, int k, vector<int> group) {
int total4seaters = n;
int total2seaters = n * 2;
int singleSoilders = 0;
int fourSeatCount = 0;
for (int i = 0; i < k; i++) {
while (group[i] >= 4) {
total4seaters--;
group[i] -= 4;
}
if... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long max(long long a, long long b) { return (a > b) ? a : b; }
long long min(long long a, long long b) { return (a < b) ? a : b; }
long long gcd(long long a, long long b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
int main() {
ios_base::sync_wit... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
long long int x, y;
cin >> x >> y;
long long int a, b;
cin >> a >> b;
long long int ans1 = b * min(x, y) + a * abs(x - y);
long long int ans2 = a * (x + y);
if (ans1 < ans2)
cout << ans1 << ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
int n, m, c[maxn], w[maxn];
pair<int, int> ans[maxn];
struct node {
long long first;
int second;
node() {}
node(long long a, int b) { first = a, second = b; }
bool operator<(const node& a) const { return first > a.first; }
};
priority_queu... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, m, ch[13][13], a[13][13], ans;
const int w[4][3][3] = {{{1, 1, 1}, {0, 1, 0}, {0, 1, 0}},
{{0, 1, 0}, {0, 1, 0}, {1, 1, 1}},
{{1, 0, 0}, {1, 1, 1}, {1, 0, 0}},
{{0, 0, 1}, {1, 1, 1}, {0, 0, 1}}};... | 7 |
#include <bits/stdc++.h>
using namespace std;
const long long int inf = 1000000000;
const long long int mod = 1000000000 + 7;
inline void IO() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
inline int dcmp(long double x) { return x < -1e-12 ? -1 : (x > 1e-12); }
template <class T>
inline int CHECK(T M... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a = 0, b;
cin >> n;
while (n > 0) {
if (n % 8 == 1) {
a++;
}
n /= 8;
}
cout << a;
return 0;
}
| 6 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
long long power(long long a, long long b) {
long long ret = 1;
while (b) {
if (b & 1) ret *= a;
a *= a;
if (ret >= MOD) ret %= MOD;
if (a >= MOD) a %= MOD;
b >>= 1;
}
return ret;
}
long long invmod(long long x) { re... | 2 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 100005;
int main(){
int t;
scanf("%d",&t);
while(t--){
ll a,b,c;
scanf("%lld%lld%lld",&a,&b,&c);
if(a+b+c<7){
printf("NO\n");
continue;
}
ll m = min(a,min(b,c));
ll s = a+b+c;
if(s%9==0&&s/9<=m){
printf("YES... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2010;
const int maxm = 5e5 + 10;
int n, m, a[maxm], b[maxm];
bitset<maxn> g[maxn], C[maxn];
int main() {
int i, j;
scanf("%d%d", &n, &m);
for (i = 1; i <= m; i++) {
scanf("%d%d", &a[i], &b[i]);
g[a[i]].set(b[i]);
}
for (i = 1; i <= n; i++)... | 10 |
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const int MN = 200005, MM = 3005, mod = 998244353;
int n, m, a[MN], w[MN], dp[MM];
int inv(int u) { return u == 1 ? 1 : LL(mod - mod / u) * inv(mod % u) % mod; }
int main() {
ios::sync_with_stdio(false);
cout.tie(nullptr);
cin >> n >> m;
int S ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int d[65005];
int main() {
int n;
cin >> n;
string str;
cin >> str;
int answer = 0;
for (int i = 1; i <= n; i++) {
if ((str[i - 1] - '0') % 2 == 0) {
answer += i;
}
}
cout << answer;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(0.0) * 2.0;
const long double eps = 1e-10;
const int step[8][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1},
{-1, 1}, {1, 1}, {1, -1}, {-1, -1}};
template <class T>
inline T abs1(T a) {
return a < 0 ? -a : a;
}
template <typename t,... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long n, x, y, nn;
void egcd(long long a, long long b, long long &i, long long &j, long long &d) {
if (b == 0)
d = a, i = 1, j = 0;
else {
egcd(b, a % b, j, i, d);
j -= a / b * i;
}
}
int main() {
scanf("%lld", &n);
nn = n;
for (long long i = 2; ... | 5 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.