solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int num[] = {0, 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1,
14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1,
51, 1, 2, 1, 14, 1, 2, 2, 14, 1, 6, 1, 4, 2, 2, 1,
52, 2, 5, 1, 5, 1, 15, 2, 13, 2, 2, 1, 13, 1, 2, 4... | 11 |
#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
template <class T>
inline void chkmin(T &a, T b) {
if (a > b) a = b;
}
template <class T>
inline void chkmax(T &a, T b) {
if (a < b) a = b;
}
const int MOD = 1e9 + 7;
const int MAXN = 1 << 18;
int a[MAXN];
long long w[MAXN + MAXN];
int wa... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e3 + 10;
const int MOD = 51123987;
char str[MAXN];
char s[MAXN];
int dp[200][53][53][53];
int nex[200][3];
int main() {
int n;
while (scanf("%d", &n) != EOF) {
memset(dp, 0, sizeof(dp));
scanf("%s", str);
int k = 0;
s[k++] = str[0];
... | 17 |
#include <bits/stdc++.h>
using namespace std;
struct Team {
int score, goals, miss, matches;
};
int get(int x1, int x2) {
if (x1 > x2) return 3;
if (x1 == x2) return 1;
return 0;
}
struct Cmp {
bool operator()(const pair<string, Team> &p1, const pair<string, Team> &p2) {
if (p1.second.score != p2.second.s... | 10 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
const long long inf = 0x7f7f7f7f7f7f7f7f;
int T;
int n;
int b[200010];
map<int, int> mp;
int main() {
scanf("%d", &T);
while (T--) {
mp.clear();
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &b[i]), mp[b[i]]++;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int Maxn = 200005;
char A[Maxn], B[Maxn];
int slen;
bool Less(char A[], int i1, int j1, char B[], int i2, int j2) {
int len = j1 - i1 + 1;
for (int i = 0; i < len; i++)
if (A[i1 + i] != B[i2 + i]) return A[i1 + i] < B[i2 + i];
return false;
}
void Fix(char A... | 9 |
#include <iostream>
#include <vector>
#include <string>
int get_ans(std::vector< std::string > & map, int x, int y, int n, int m)
{
int ans = 0;
if (map[x][y] == '*') ans = 1;
if ((x + 1 == n) && (y + 1 == m)) return ans;
if ((x + 1 == n) || ((y < m - 1) && (map[x][y + 1] == '*' || map[x + 1][y] =... | 10 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18 + 1e17;
const int mod = 998244353;
const long long int N = 600032LL;
long long int fac[N + 2];
long long int inv[N + 2];
long long int add(long long int a, long long int b) {
a += b;
if (a >= mod) a -= mod;
if (a < 0) a += mod;
return a;
}... | 8 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
const int N = 1e5 + 1;
using namespace std;
int a[N];
int ans;
int n, x;
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n;
for (int i = 0; i < n; i++)
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int dx[4] = {0, -1, 0, 1};
int dy[4] = {1, 0, -1, 0};
long long MOD = 1e9 + 7;
void solve() {
int n;
cin >> n;
int ax, ay;
cin >> ax >> ay;
int bx, by;
cin >> bx >> by;
int cx, cy;
cin >> cx >> cy;
if (((ax > bx && ax > cx) || (ax < bx && ax < cx)) &&
... | 2 |
#include <bits/stdc++.h>
using namespace std;
template <typename T, size_t N>
int SIZE(const T (&t)[N]) {
return N;
}
template <typename T>
int SIZE(const T &t) {
return t.size();
}
string to_string(const string s, int x1 = 0, int x2 = 1e9) {
return '"' + ((x1 < s.size()) ? s.substr(x1, x2 - x1 + 1) : "") + '"';
... | 8 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, f = 1;
char c = getchar();
for (; !isdigit(c); c = getchar())
if (c == '-') f = -1;
for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
return x * f;
}
const int MAXN = 100010;
const int INF = 2147483600;
int N;
int a[MAXN + ... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
int k, n, arr[501], i, ans = 0;
scanf("%d %d", &n, &k);
for (i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}
for (i = 1; i < n; i++) {
if (arr[i] + arr[i - 1] < k) {
ans += k - arr[i] - arr[i - 1];
arr[i] = k - arr[i - 1];
}
... | 2 |
#include <bits/stdc++.h>
class Edge {
public:
Edge(int node, char color) : node(node), color(color) {}
void print_node() {
std::cout << "node=" << node << ", color=" << color << std::endl;
}
void print_corresponding() {
std::cout << "node=" << corresponding->node
<< ", color=" << correspo... | 14 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
long long int t, m, k;
cin >> t >> m >> k;
long long int a[t];
long long int mx = 0;
long long int n = t;
for (long long int i = 0; i < t; i++) {
cin >> a[i];
}
sort(a, a + n);
if (m <= k)
cout << m * a[n - 1] << endl;
else {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int dx[] = {1, 1, 0, -1, -1, -1, 0, 1, 0};
int dy[] = {0, -1, -1, -1, 0, 1, 1, 1, 0};
int sx, sy;
int ex, ey;
char M[8][9];
int main() {
int x, y, nx, ny;
for (int i = 0; i < 8; ++i) {
cin >> M[i];
}
sx = 7;
sy = 0;
ex = 0;
ey = 7;
M[sx][sy] = M[ex][ey] ... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int fx[] = {+1, -1, +0, +0};
const int fy[] = {+0, +0, +1, -1};
const int fx8[] = {+0, +0, +1, -1, -1, +1, -1, +1};
const int fy8[] = {-1, +1, +0, +0, +1, +1, -1, -1};
const int kx[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int ky[] = {-1, 1, -2, 2, -2, 2, -1, 1};
bool i... | 2 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<long long> > vect(500000);
long long counter = 1;
pair<long long, long long> range[500000];
void bfs(long long parent, long long node) {
range[node].first = counter;
for (auto &child : vect[node]) {
if (child != parent) {
bfs(node, child);
}
... | 13 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
double D[1000003], B[1000003], A[1000003];
long long C[2003][2003];
string S;
int main() {
long long T, i, j, k, l, r, s, a, b, c, d, x, y, z, m, n, t, p, q, curr, sum,
ans, pos, val, countA;
cin >> S;
A[0] = 0;
for (i = 1; i < 1... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, k, m;
cin >> n >> k >> m;
map<string, int> mp;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
mp[s] = i;
}
long long a[n];
for (int i = 0; i < n; i++) {
cin >> ... | 4 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:10000000000")
using namespace std;
const int MAX_SIZE = 2e5 + 5, INF = 2 * 1e9;
const long long SuperINF = 1e12, MOD = 1e9;
const double eps = 0.5, PI = 20 / 7;
void files() {
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
}
void solve(... | 8 |
#include <bits/stdc++.h>
inline void swap(int &a, int &b) {
int tmp = a;
a = b;
b = tmp;
}
inline void swap(long long &a, long long &b) {
long long tmp = a;
a = b;
b = tmp;
}
inline void swap(long double &a, long double &b) {
long double tmp = a;
a = b;
b = tmp;
}
inline long double ABS(const long dou... | 15 |
#include <bits/stdc++.h>
using namespace std;
int length[4];
bool check(int a, int b, int c, bool &flag) {
if (c > b) swap(b, c);
if (b > a) swap(a, b);
if (a == b + c) flag = true;
return a < b + c;
}
int main() {
for (int i = 0; i < 4; ++i) cin >> length[i];
bool segment = false;
for (int i = 0; i < 4; ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5;
int S[N];
int main() {
int n, m, h;
scanf("%d %d %d", &n, &m, &h);
int sum = 0;
for (int i = 1; i <= m; i++) {
scanf("%d", &S[i]);
sum += S[i];
}
if (sum < n) {
printf("-1\n");
return 0;
}
sum -= S[h];
n--;
double a... | 8 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T &x) {
x = 0;
char ch = getchar();
bool f = 0;
while (ch < '0' || ch > '9') {
if (ch == '-') f = 1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
x = (x << 1) + (x << 3) + ch - '0', ch = getchar();
x = f ? -x : x... | 14 |
#include <bits/stdc++.h>
using namespace std;
int N, M, t[100005], ti[100005], stack1[100005], stack2[100005], head[100005],
tov[100005], nxt[100005];
int main() {
int tot = 0;
scanf("%d%d", &N, &M);
for (int i = 1; i <= N; i++) scanf("%d", &t[i]);
for (int i = 1; i <= M; i++) {
int x, y;
scanf("%d%... | 11 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > graph;
vector<int> visited;
int distance(int u, int v) {
visited[u] = true;
if (u == v) {
return 0;
} else {
int k;
for (auto i : graph[u]) {
if (!visited[i]) {
k = distance(i, v);
if (k != -1) {
return ... | 11 |
#include <bits/stdc++.h>
using namespace std;
bool kt(long long xx) {
long long ii, jj;
jj = int(sqrt(xx));
for (ii = 3; ii <= jj; ii = ii + 2)
if ((xx % ii) == 0) {
return false;
}
return true;
}
int main() {
long kq, dkq, f[12000];
int n, m, i, j, p, q, i1, i2, i3, i4, i5, i6, i7, i8, i9, de... | 8 |
#include <bits/stdc++.h>
using namespace std;
int a, b, c;
void solve() {
int m, n, o;
m = a + b - c;
n = b + c - a;
o = a + c - b;
if (m < 0 || n < 0 || o < 0 || m % 2 != 0 || n % 2 != 0 && o % 2 != 0) {
cout << "Impossible\n";
return;
}
cout << m / 2 << " " << n / 2 << " " << o / 2 << endl;
}
vo... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long modn = 1000000007;
inline long long mod(long long x) { return x % modn; }
template <class num>
inline void rd(num &x) {
char c;
while (isspace(c = getchar()))
;
bool neg = false;
if (!isdigit(c))
neg = (c == '-'), x = 0;
else
x = c - '0... | 22 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, b[5], a[100005], dp[100005][5];
cin >> n >> b[1] >> b[2] >> b[3];
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 0; i <= n; i++) {
dp[i][0] = 0;
for (int j = 1; j <= 3; j++) dp[i][j] = -0x3f3f3f3f3f3f3f3f;
}
for (int i =... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long n, w, b, f[2][4005], C[4005][4005], ans;
long long calcmod(long long k) {
long long i, res;
for (i = res = 1; i <= k; i++) res = res * i % 1000000009;
return res;
}
int main() {
long long i, j;
scanf("%I64d%I64d%I64d", &n, &w, &b);
memset(C, 0, sizeof(... | 13 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
T BigMod(T b, T p, T m) {
if (p == 0) return 1;
if (p % 2 == 0) {
T s = BigMod(b, p / 2, m);
return ((s % m) * (s % m)) % m;
}
return ((b % m) * (BigMod(b, p - 1, m) % m)) % m;
}
template <typename T>
T ModInv(T b, T m) {
return BigMo... | 5 |
#include <bits/stdc++.h>
using namespace std;
void ga(int N, int *A) {
for (int i(0); i < N; i++) scanf("%d", A + i);
}
long long f[5005] = {1, 1}, I[5005] = {1, 1}, J[5005] = {1, 1};
void pre() {
for (int k(2); k < 5005; k++)
f[k] = f[k - 1] * k % (1000000007),
J[k] =
-(1000000007) / k * J[(1000000... | 16 |
#include <bits/stdc++.h>
using namespace std;
inline void read(int &first) {
first = 0;
while (1) {
char ch = getchar();
if (ch == ' ' || ch == '\n') break;
first = first * 10 + ch - '0';
}
}
inline void write(int first) {
char wr[12];
int k = 0;
if (!first) ++k, wr[k] = '0';
while (first) {
... | 11 |
#include <bits/stdc++.h>
using namespace std;
void faster(void) {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
long long arr[150009];
int32_t main() {
long long test;
scanf("%lld", &test);
while (test--) {
long long n;
scanf("%lld", &n);
for (long long i = 1; i <= n; i++) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
namespace {
using uint = unsigned int;
using edge = tuple<uint, uint>;
using edgecol = vector<edge>;
inline tuple<size_t, size_t> ordtuple(size_t left, size_t right) {
left = min(left, static_cast<size_t>(2));
right = min(right, static_cast<size_t>(2));
if (left <= ri... | 19 |
#include <bits/stdc++.h>
using namespace std;
long long t;
long long X, Y, x1, x2;
long long mxbit(long long x) {
long long cnt = 0;
while (x > 0) {
cnt++;
x >>= 1;
}
return cnt - 1;
}
long long rev(long long x) {
long long k = mxbit(x), re = 0;
for (long long i = 0; i <= k; i++) {
re |= (1LL <<... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
long long n;
cin >> n;
map<long long, long long> m;
long long((a)[(n)]);
for (long long i = 0; i < (n); i++) cin >> ((a)[i]);
long long sum = 0;
for (long long(i) = 0; (i) < (n); (i)++) {
while (a[i] > 0 && m[a[i... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, x;
cin >> n >> k;
map<int, long long> M[4];
for (int i = 0; i < n; i++) {
cin >> x;
if (x % k == 0) {
M[3][x] += M[2][x / k];
M[2][x] += M[1][x / k];
}
M[1][x]++;
}
long long sum = 0;
for (map<int, long long>:... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x, x1, x2, z = 0;
cin >> x;
x1 = 8;
x2 = x - x1;
for (int i = 2; i < x2 - 1; i++) {
if (x2 % i == 0) {
z++;
}
}
if (z == 0) {
x2 = x2 - 1;
x1 = x1 + 1;
}
cout << x1 << endl << x2 << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int L, R;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> L >> R;
if (L == R)
cout << L << endl;
else
cout << 2 << endl;
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
const long double PI = 3.14159265358979323;
long long int linf = (long long int)2e18;
const int inf = 1011111111;
const int N = 205;
int n, k;
int dp[N][N][N];
string str1, str2;
void input() {
cin >> n >> k >> str1 >>... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int N = 64;
const int M = 1900;
struct RecordType {
int b, c;
} rec[N][32][M];
int dp[N][32][M];
int n;
int arr[N];
bool mydp[M], ans[N][N];
inline bool DP(int x) {
for (int i = 1; i <= x; i++) memset(dp, 0, sizeof(dp));
;
dp[0][0][0] = 1;
int Minlose, tmp, ... | 20 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int tt;
cin >> tt;
while (tt--) {
int n;
cin >> n;
map<long long, bool> d;
for (int i = 0; i < n; i++) {
long long a;
cin >> a;
d[a] = 1;
}
int ans = 0;... | 4 |
#include <bits/stdc++.h>
using namespace std;
struct Op {
int id;
string lhs, rhs;
int lhsid, rhsid;
string op;
};
class TaskE {
public:
void solve(istream& in, ostream& out) {
int n, m;
in >> n >> m;
map<string, int> name_id;
name_id["?"] = n;
vector<Op> v(n);
for (int i = 0; i < n; ... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int v[10];
v[0] = 2;
v[1] = 7;
v[2] = 2;
v[3] = 3;
v[4] = 3;
v[5] = 4;
v[6] = 2;
v[7] = 5;
v[8] = 1;
v[9] = 2;
char a, b;
cin >> a >> b;
cout << v[(int)a - '0'] * v[(int)b - '0'] << endl;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int main() {
cin >> n >> m;
vector<vector<int> > bubbles = vector<vector<int> >(n, vector<int>(m, 0));
for (int i = 0; i < n; ++i)
for (int j = 0; j < m; ++j) {
cin >> bubbles[i][j];
}
long long ans1 = 0;
for (int p = 0; p < 16; ++p) {
... | 12 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n;
cin >> n;
vector<pair<long long, long long> > a(n);
for (long long i = 0; i < n; ++i) {
cin >> a[i].first;
--a[i].first;
a[i].second = i;
}
sort(a.begin(), a.end());
long long mx = -1, mn = n + 1;
for (long long i = 0;... | 5 |
#include <bits/stdc++.h>
using namespace std;
vector<int> S[110000];
int n, m, q, i, j;
long long a[110000];
long long ans = 0;
vector<int> nums;
long long add[110000];
long long addd[110000];
int per[110000][500];
long long rez[110000];
int r;
int z[110000];
int IN[110000];
const int C = 300;
int main() {
cin >> n >... | 17 |
///STOP DOING SILLY MISTAKES
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define ii insert
#define ld long double
#define sz(x) (int)x.size()... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
vector<int> depth;
vector<int> recolor;
vector<vector<int>> g;
vector<vector<int>> ng;
vector<vector<long long>> dp;
vector<vector<int>> par;
void dfs(int node, int parent) {
par[node][0] = parent;
if (parent == -1)
depth[node] = 0;
else... | 19 |
#include <bits/stdc++.h>
using namespace std;
bitset<100010> bs;
vector<int> primes;
void sieve(long long size) {
bs.set();
bs[0] = bs[1] = 0;
for (long long i = 2; i <= size; i++)
if (bs[i]) {
for (long long j = i * i; j <= size; j += i) bs[j] = 0;
primes.push_back((int)i);
}
}
bool isPrime(l... | 6 |
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using ii = pair<int, int>;
using ld = long double;
struct DSU {
vi par, rank, sz;
stack<tuple<int, int, bool>> undo;
DSU(int n) : par(n), rank(n), sz(n, 1) {
iota((par).begin(), (par).end(), 0);
}
void merge(int u, int v) {
u = find... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
for (int k = 0; k < t; k++) {
int n;
cin >> n;
long long int a[n], b[n];
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++) b[i] = a[i];
for (int i = 1; i < n; i++) {
if (a[i - 1] > a[i]) a[... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
long long sy, a, b;
long long n, q;
long long fenl[N], fenr[N];
long long sum[N];
struct point {
long long x, y;
} p[N];
int main() {
scanf("%lld%lld%lld", &sy, &a, &b);
scanf("%lld", &n);
for (int i = 1; i <= n; i++) {
scanf("%lld%lld", &... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0), cin.tie(nullptr);
int n, n1, n2;
cin >> n >> n1 >> n2;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
sort(a.rbegin(), a.rend());
int k1 = 0, k2 = 0;
long double s1 = 0, s2 = 0;
if (n1 > n2) ... | 3 |
#include <bits/stdc++.h>
const long long inf = 1e10;
const long long mod = 1e9 + 7;
const long long zero = 0;
const long long maxn = 2e3 + 5;
using namespace std;
long long mat[5][maxn], n, k, cnt;
vector<pair<pair<long long, long long>, long long> > v;
long long dif(long long a, long long b) { return abs(a - b); }
pai... | 13 |
#include <bits/stdc++.h>
int t[101], n, b, aux, i;
int main() {
scanf("%d", &n);
for (i = 1; i <= n; i++) {
scanf("%d", &t[i]);
}
do {
b = 0;
for (i = 1; i <= n - 1; i++) {
if (t[i] > t[i + 1]) {
aux = t[i];
t[i] = t[i + 1];
t[i + 1] = aux;
b++;
}
}
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5;
int n, m, ans;
int dr[4] = {-1, 0, 1, 0};
int dc[4] = {0, 1, 0, -1};
int dist[N][N];
char ar[N][N];
bool inRange(int x, int y) {
return ((x >= 1) && (x <= n) && (y >= 1) && (y <= m));
}
int main() {
cin >> n >> m;
pair<int, int> s, me;
for (in... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
int cnt(int a, int b) {
if (!a || !b) return INF;
if (a == 1 && b == 1) return 0;
if (a > b) return cnt(a - b, b) + 1;
return cnt(a, b - a) + 1;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
int k ... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1e9 + 7;
struct Edge {
int from, to, cap, flow;
Edge(int x = 0, int y = 0, int z = 0, int t = 0)
: from(x), to(y), cap(z), flow(t) {}
};
struct Dinic {
int n;
vector<vector<int> > g;
vector<Edge> e;
vector<int> dist;
vector<int> pos;... | 21 |
#include <bits/stdc++.h>
using namespace std;
long long a[2222][103];
long long b[2222][103];
long long w[2222][103];
int vis[2222];
long long tmp[2222];
long long kmp[103];
int N;
int main() {
string d;
scanf("%d", &N);
for (int i = 0; i < N; ++i) {
cin >> d;
int k = d.size();
for (int j = 0; j < k; ... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e6 + 5;
const int LIM = 4e6 + 5;
int arr[MAX];
int seg[LIM][2];
int combine(int &a, int &b, int x) {
if (x) {
if (arr[a] > arr[b]) return b;
return a;
}
if (arr[a] > arr[b]) return a;
return b;
}
void build(int t, int i, int j) {
if (i == ... | 11 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef pair<int ,int> pii;
typedef pair<ll, ll> pll;
typedef double rl;
typedef pii int2;
typedef tuple<int, int, int> int3;
typedef tuple<int, int, int, int> int4;
typedef tupl... | 11 |
#include <bits/stdc++.h>
using namespace std;
using namespace std;
int main() {
long long int n;
cin >> n;
if (n % 2 != 0) {
cout << 0 << endl;
} else {
cout << (1 << n / 2) << endl;
}
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
cout << (n / 100) + ((n % 100) / 20) + (((n % 100) % 20) / 10) +
((((n % 100) % 20) % 10) / 5) + ((((n % 100) % 20) % 10) % 5)
<< endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define all(x) x.begin() , x.end()
#define ld long double
const long long inf = 1e18 + 5LL;
const int mod = 1e9 + 7LL; //998244353 ;
void solve();
void ITO();
int32_t main() {
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 128;
vector<int> adj[MAX_N];
void ask(int u) {
cout << "? " << u << endl;
int k;
cin >> k;
adj[u] = vector<int>(k);
for (int i = 0; i < k; i++) {
cin >> adj[u][i];
}
}
void report(int u) { cout << "! " << u << endl; }
bool root(int u) { ret... | 20 |
#include <bits/stdc++.h>
using namespace std;
double PI = acos(-1);
double cal(double h, double w, double a) {
double ans = sin(a) * cos(a);
ans *= ((h * (1 + cos(a)) - w * sin(a)) /
((1 + cos(a)) * (1 + cos(a)) - sin(a) * sin(a))) *
((h * (1 + cos(a)) - w * sin(a)) /
((1 + cos(a)) * (1... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e3 + 10;
const long long inf = 1e18;
vector<int> g[maxn];
pair<long long, long long> dp[maxn][maxn], pre[maxn];
int N, M;
long long B[maxn], W[maxn], tsize[maxn];
void DFS(int x, int p) {
tsize[x] = 1;
dp[x][1] = make_pair(0, W[x] - B[x]);
for (int y... | 17 |
#include <bits/stdc++.h>
using namespace std;
int a[100007];
int pref[100007], suff[100007];
struct data {
int l, r, id;
bool operator<(const data& p) const {
if (l / 317 == p.l / 317) return r < p.r;
return l / 317 < p.l / 317;
}
};
data qr[100007];
long long ans[100007];
long long p[4000007], s[4000007]... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string s;
cin >> s;
vector<int> seen(10, 0);
int cnts = INT_MAX;
for (int i = 0; i < s.length(); ++i) {
seen[s[i] - '0']++;
}
string temp = s;
if (seen[5] && seen[2]) {
int counts = 0;... | 13 |
#include <bits/stdc++.h>
using namespace std;
long long readll() {
bool minus = false;
long long result = 0;
char ch;
ch = getchar();
while (true) {
if (ch == '-') break;
if (ch >= '0' && ch <= '9') break;
ch = getchar();
}
if (ch == '-')
minus = true;
else
result = ch - '0';
while... | 9 |
#include <bits/stdc++.h>
using namespace std;
int mas[1001], nxt[1001];
bool dp[1002][1002];
vector<int> len;
void go(int sum, int cur) {
if (dp[sum][cur]) return;
dp[sum][cur] = true;
if (cur == len.size()) return;
for (int i = cur; i < len.size(); i++) go(sum + len[i], i + 1);
}
int main() {
int n, x;
cin... | 7 |
#include <bits/stdc++.h>
using namespace std;
mt19937_64 rang(
chrono::high_resolution_clock::now().time_since_epoch().count());
long long power(long long x, long long y) {
long long v = 1;
while (y > 0) {
if (y & 1) v = v * x;
y = y >> 1;
x = x * x;
}
return v;
}
bool isPowerOfTwo(long long x) ... | 6 |
#include <bits/stdc++.h>
using namespace std;
using ii = pair<int, int>;
using item = pair<int, ii>;
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
int i, n, m;
cin >> n >> m;
vector<int> x(n);
vector<int> rest;
queue<item> dist;
for (i = 0; i < n; i++) cin >> x[i];
sort(x.begin(), x.end());
dist.... | 10 |
//#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <set>
#include <bitset>
#include <queue>
#include <tuple>
#include <map>
#include <random>
#include <chrono>
using namespace std;
#define fastInp cin.tie(0); cout.tie(0);
#define sq... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
a = abs(a), b = abs(b);
if (a < b) swap(a, b);
return b ? gcd(b, a % b) : a;
}
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
long long fast_pow(long long x, long long exp, long long mod) {
long long r... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
int a, b;
cin >> n;
int c = 0;
while (n--) {
cin >> a >> b;
if (b - a >= 2) ++c;
}
cout << c << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long k, a, b, c, t, ans = 0;
cin >> t;
while (t--) {
ans = 0;
cin >> a >> b >> k;
c = k / 2;
k -= c;
ans += k * a;
ans -= c * b;
cout << ans << endl;
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
bool chmin(int &x, int y) { return y < x ? x = y, true : false; }
const int maxN = 500 + 5;
const int maxK = 10 + 2;
int n, k;
int a[maxN], ch[maxN][maxK], f[maxN][maxN][maxK], cnt = 1;
int g[maxN][maxK];
void dp(int u, int dep) {
for (int c = 0; c < 10; ++c)
if (ch[u... | 20 |
#include <bits/stdc++.h>
using namespace std;
int arr[100001];
int ans[100001];
void si() {
arr[1] = 1;
for (int z = 2; z < 100001; z++)
if (!arr[z])
for (int j = z; j < 100001; j += z) arr[j] = (!arr[j] ? z : arr[j]);
}
char c;
int x, tmp;
bool k;
void act() {
if (x == 1) {
if (ans[x]) {
k = ... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 300000;
int a[MAX + 10];
int main() {
int n, m;
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; ++i) scanf("%d", a + i);
int l = 0, r = m;
while (l < r) {
int mid = (l + r) >> 1;
int minn = 0;
bool f = true;
for (int i = 1; i <= n; ... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int a = 0;
bool o = false;
for (int i = 0; i < s.size(); ++i) {
if (s[i] == '1') o = true;
if (o && s[i] == '0') ++a;
}
cout << (a >= 6 ? "yes" : "no") << endl;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int fastMax(int x, int y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ y; }
int fastMin(int x, int y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ x; }
const long long int MAXN = 1e5 + 10;
const long long int LOG_A = 21;
struct basis {
long long int basis_v[LOG_A];
long... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int mxn = 1e5 + 3;
vector<pair<int, int> > g;
int ans[mxn * 2], n;
map<int, int> mat;
int main() {
scanf("%d", &n);
for (int(i) = (int)(0); (i) < (int)(n); ++(i)) {
int u, v;
scanf("%d%d", &u, &v);
g.push_back(make_pair(u, v));
mat[u] = v;
mat[... | 18 |
#include <bits/stdc++.h>
int min(int a, int b) {
if (a < b) return a;
return b;
}
int dist[60][60];
int MAX[100];
int MIN[100];
long long f[60][60];
int a;
int main() {
int n, m;
scanf("%d%d", &n, &m);
memset(dist, 50, sizeof(dist));
for (int i = 0; i < m; i++) {
int v, u, c;
scanf("%d%d%d", &v, &u,... | 16 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1E9 + 9;
long long process(string &str, int x, int y) {
if (x > y) return 0;
stringstream ss;
ss << str;
long long ret = 0;
stack<long long> st;
char ch;
while (ss >> ch) {
if (ch == '+') {
long long d;
ss >> d;
st.p... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
n = 180 - n;
if (360 % n == 0)
cout << "YES";
else
cout << "NO";
cout << endl;
}
}
| 3 |
#include <bits/stdc++.h>
const long double EPS = 1e-9;
const long double PI = 3.1415926535897932384626434;
using namespace std;
int n, m;
int a[15], b[15];
int x[15], y[15];
set<int> v1[100][100];
set<int> v2[100][100];
set<int> pos1, pos2;
int main() {
ios::sync_with_stdio(0);
cin >> n >> m;
for (int i = 0; i < ... | 11 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool cmin(T& a, const T& b) {
return a > b ? a = b, 1 : 0;
}
template <typename T>
inline bool cmax(T& a, const T& b) {
return a < b ? a = b, 1 : 0;
}
int read() {
int x = 0, f = 1;
char ch;
for (ch = getchar(); !isdigit(ch); ch = getc... | 21 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
int n, m, sx, sy;
int main() {
cin >> n >> m >> sx >> sy;
int cnt = 0;
for (int i = sx; i < n + 1; ++i) {
if (i == sx) {
for (int j = sy; j <= m; ++j) {
cout << i << " " << j << endl;
}
for (int j = sy - 1; j > 0; -... | 3 |
#include <bits/stdc++.h>
using namespace std;
float glass[11][11];
int n, t;
int ans = 0;
int main() {
cin >> n >> t;
glass[0][0] = t;
for (int i = 0; i < n; i++) {
for (int j = 0; j <= i; j++) {
if (glass[i][j] >= 1) {
float out = (glass[i][j] - 1) / 2;
glass[i + 1][j] += out;
g... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, l, r;
cin >> n >> l >> r;
long long b = 0;
long long a = 0;
for (int i = 0; i < l; i++) {
a += pow(2, i);
}
std::cout << std::setprecision(20) << (n - l) + a << " ";
for (int i = 0; i < r; i++) {
b += pow(2, i);
}
std::c... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
long long t;
if (a > b) {
t = a;
a = b;
b = t;
}
while (a % b != 0) {
t = b;
b = a % b;
a = t;
}
return b;
}
long long a[200020];
int n;
int main() {
scanf("%d", &n);
long long cd;
for (int ... | 9 |
#include <bits/stdc++.h>
using namespace std;
int N, R, f[51], s[51], p[51];
double dp[52][5002], low = 1, high = 10000000000000000;
int main() {
cout << fixed << setprecision(16);
cin >> N >> R;
for (int i = 1; i <= N; ++i) {
cin >> f[i] >> s[i] >> p[i];
}
for (int i = 0; i < 80; ++i) {
double mid = ... | 16 |
#include <bits/stdc++.h>
int n, max_num;
int qcnt;
bool chk[1000010];
int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
int main() {
srand(time(NULL));
int ret;
scanf("%d", &n);
if (n <= 60) {
int min_num = 1000000000;
for (int i = 1; i <= n; ++i) {
printf("? %d\n", i);
fflush(stdout);... | 14 |
#include <bits/stdc++.h>
using namespace std;
struct punct {
long long int x, y;
punct(long long int x = 0, long long int y = 0) : x(x), y(y) {}
};
struct punct2 {
punct a[4];
} v[4][105];
long long int dist(const punct &a, const punct &b) {
return ((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
bool... | 12 |
#include <bits/stdc++.h>
using namespace std;
long long P[2000005], flag[2000005];
long long cntP[2000005], cntQ[2000005];
bool isPalin(long long num) {
string st = "";
while (num > 0) {
long long temp = num % 10;
st = st + char(temp + 48);
num = num / 10;
}
int N = st.length();
int i = N / 2;
w... | 8 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.