solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const int N = 1e6 + 5;
int p[1005];
bool vis[1005];
int dfs(int u) {
if (vis[u]) return u;
vis[u] = true;
return dfs(p[u]);
}
int main() {
int n, i;
cin >> n;
for (i = 1; i <= n; i++) {
cin >> p[i];
}
for (i = 1; i <= n; i++) {
... | 2 |
#include <bits/stdc++.h>
long long ans[100][20][2];
long long w[20];
long long ans1[20];
long long m, ttt, anss, low, anst;
long long a[10];
long long nowmax;
long long dp(long long p, long long pos, bool pre0, bool limit) {
if (p < 0) return 0;
if (pos < 1) return p == 0 && !pre0;
if (!limit && ans[p][pos][pre0]... | 11 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool uax(T &x, T y) {
return (y > x) ? x = y, true : false;
}
template <typename T>
inline bool uin(T &x, T y) {
return (y < x) ? x = y, true : false;
}
void err(istream_iterator<string>) {}
template <typename T1, typename T2>
ostream &opera... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char* argv[]) {
int a, b;
cin >> a;
cin >> b;
int wins[3] = {0, 0, 0};
for (int i = 1; i < 7; ++i) {
if (abs(a - i) < abs(b - i)) ++wins[0];
if (abs(a - i) == abs(b - i)) ++wins[1];
if (abs(a - i) > abs(b - i)) ++wins[2];
}
cout ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, m;
cin >> n >> m;
long long int a[m + 1][4];
long long int flag[n + 1];
long long int i, j;
for (i = 1; i <= n; i++) flag[i] = 0;
long long int cnt = 1;
for (i = 0; i < m; i++) {
for (j = 0; j < 3; j++) cin >> a[i][j];
}
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int x[100 + 10], y[190];
int z[1000][1000];
int main() {
int n, m;
cin >> n >> m;
for (int j = 0; j < n; j++) {
cin >> x[j];
}
for (int k = 0; k < m; k += 1) {
cin >> y[k];
}
for (int j = 0; j < 30; j++) {
int xx = 0, yy = 0;
for (int k = 0; k ... | 10 |
#include <bits/stdc++.h>
using namespace std;
int a, s, f, g, h, j, k, l, i, n, o;
pair<int, int> M[100002];
int main() {
cin >> n >> k;
cin >> g >> h;
for (i = 0; i < n; i++) {
cin >> j >> l;
M[i].first = j * g + h * l;
M[i].second = i + 1;
}
sort(M, M + n);
for (i = 0; i < n; i++) {
k = k ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long t, a;
scanf("%ld", &t);
for (int i = 0; i < t; i++) {
scanf("%ld", &a);
long ans = 0;
while (a) {
if (a & 1) ans++;
a >>= 1;
}
printf("%ld\n", (long)1 << ans);
}
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a, b;
cin >> a >> b;
printf("%.09f", a * pow(1.000000011, b));
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int r1, r2, c1, c2, d1, d2;
int a, b, c, d;
scanf("%d %d %d %d %d %d", &r1, &r2, &c1, &c2, &d1, &d2);
for (int a = 1; a <= 9; a++)
for (int b = 1; b <= 9; b++) {
if (a == b) continue;
for (int c = 1; c <= 9; c++) {
if (a == c || ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a, b, c;
scanf("%lld%lld%lld", &a, &b, &c);
if (a == 0 && b == 0 && c == 0)
printf("%d", -1);
else if (a == 0 && b == 0 && c != 0)
printf("%d", 0);
else if (a == 0 && b != 0)
printf("1\n%.10lf", -double(c) / b);
else {
if (... | 12 |
#include <bits/stdc++.h>
using namespace std;
vector<string> vs;
int n, m;
int calc(int x, int n) {
if (n == 1) return x % 1000003;
if (n == 0) return 1;
int t = calc(x, n / 2);
t = 1ll * t * t % 1000003;
if (n & 1) return (t * x) % 1000003;
return t;
}
int check() {
for (int i = 0; i < (vs.size()); ++i) ... | 14 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long INF = mod * mod;
const long double eps = 1e-12;
const long double pi = acos(-1.0);
long long mod_pow(long long a, long long n, long long m = mod) {
long long res = 1;
while (n) {
if (n & 1) res = res * a % m;
a =... | 18 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(T& a) {
char c = getchar();
int f = 1;
for (; c > '9' || c < '0'; c = getchar())
if (c == '-') f = -1;
for (a = 0; c <= '9' && c >= '0'; c = getchar()) a = a * 10 + c - 48;
a *= f;
}
inline int Max(int a, int b) { return a >... | 19 |
#include <bits/stdc++.h>
using namespace std;
static const int OO = 0x3f3f3f3f, N = 150;
static const long long OOL = 0x3f3f3f3f3f3f3f3fLL;
string second;
long long comp(string a) {
long long ans = 0, x = 1;
for (int i = 0; i < ((int)(a).size()); ++i) {
if (a[i] == '1') ans += x;
x *= 2;
}
return ans;
}... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int k, n;
map<int, int> mp;
int solve(int n) {
if (n == 0) return 0;
if (n == 1 || n == 3) return 1;
if (n & 1) return 0;
if (mp.count(n)) return mp[n];
int vis[5] = {0};
vis[solve(n - 1)] = 1;
if (n % 2 == 0) {
int x = n / 2;
... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int M = 1200000;
const int inf = 0x3f3f3f3f;
long long dp[50][2][2];
long long thr[50];
int u, v;
long long dfs(int p, bool a, bool b) {
if (p == -1) return 1;
if (a + b == 0) return thr[p];
if (dp[p][a][b] != -1) return dp[p][a][b];
long long ret = 0;
int n... | 15 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
int n, a[200100], num[2000100], ans;
int main() {
int k, i, j, l, r;
scanf("%d", &n);
for (i = 1; i <= n; i++) scanf("%d", &a[i]);
sort(a + 1, a + n + 1);
n = unique(a + 1, a + n + 1) - a - 1;
for (i = 1, j = 0; i <= 2000000; i++) {... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 7;
const int logMAXN = 20;
int LCA[logMAXN][MAXN], parent[MAXN], subtree_sum[MAXN], edge_val[MAXN],
depth[MAXN];
bool visited[MAXN];
vector<int> graph[MAXN], edge_idx[MAXN];
void generateParents(int, int);
void calculateEdgeValues(int);
void preco... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
long long n, sz[N], ans[N];
vector<int> adj[N];
vector<int> vec;
long long Size, tmp1, tmp2;
long long mxch[N];
bool mark[N];
void DFS(int v, int p = 0) {
sz[v] = 1;
mxch[v] = 0;
for (auto u : adj[v]) {
if (u != p && mark[u] != true) {
... | 13 |
#include <bits/stdc++.h>
using namespace std;
//-(smallstar))---- :]
#define int long long
#define ll long long
#define mp make_pair
#define vi vector<ll>
#define pb push_back
#define all(o) (o).begin(), (o).end()
#define rall(o) (o).rbegin(), (o).rend()
#define nl cout << "\n"
//debug start
#define debug(a) \... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long MAX = 1e14 + 8;
const long long MAXN = 1e5 + 8;
const long long eps = 1e-4;
using namespace std;
long long a[15];
long long siz(string s) {
if (s == "S") return 0;
if (s == "M") return 1;
if (s == "L") return 2;
if (s =... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long t;
cin >> t;
while (t--) {
string s;
cin >> s;
unordered_map<char, int> mp(s.size());
for (long long i = 0; i < s.size(); i++) {
mp[s[i]] = i + 1;
}
string ss;
... | 0 |
#include <bits/stdc++.h>
const int MAXD = 10;
int A[MAXD]{};
char buff[MAXD]{};
bool lead[MAXD]{};
int sum[MAXD]{};
int N, ret = 1E9;
int main() {
scanf("%d", &N);
for (int i = 0; i < N; ++i) {
scanf(" %s", buff);
for (int j = strlen(buff) - 1, t = 1; j >= 0; --j, t *= MAXD)
sum[buff[j] - 'a'] += t;
... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
bool was;
int main() {
cin >> n;
if (n < 4) {
cout << "NO\n";
return 0;
}
cout << "YES\n";
while (n > 7) {
if (was == true) cout << n << " + " << 0 << " = " << n << endl;
cout << n << " - " << n - 1 << " = " << 1 << endl;
cout << n - ... | 7 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const long long MAXN = 6e5 + 7;
const long long MAXM = 1e5 + 7;
const long long MOD = 1e9 + 7;
const double eps = 1e-6;
const double pi = acos(-1.0);
int pos[MAXN], c[MAXN];
int n;
int mi[MAXN], ma[MAXN];
int lowbit(int x) { return ... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int nn = 3e5 + 8;
vector<int> G[nn];
int n, m;
int R[nn], pa[nn];
int trv[nn];
long long sum[nn];
void dfs(int u) {
trv[u] = 1;
for (int v : G[u]) {
if (v == pa[u]) continue;
if (!trv[v]) {
pa[v] = u;
dfs(v);
} else if (trv[v] == 1) {
... | 15 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k = 0;
char s[51][51];
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int dfs(int i, int j) {
int ans = 1;
s[i][j] = 'x';
for (int w = 0; w < 4; w++)
if (s[i + dx[w]][j + dy[w]] == '#') ans += dfs(i + dx[w], j + dy[w]);
return ans;
}
int main() ... | 9 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
T next_int() {
T x = 0, p = 1;
char ch;
do {
ch = getchar();
} while (ch <= ' ');
if (ch == '-') {
p = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + (ch - '0');
ch = getchar();
}
return p * x;... | 15 |
#include <bits/stdc++.h>
using namespace std;
int N;
long long slime[500010];
long long ans, zero;
vector<long long> p, m;
int main() {
scanf("%d", &N);
if (N == 1) {
scanf("%lld", &slime[0]);
printf("%lld", slime[0]);
return 0;
}
for (int i = 0; i < N; i++) {
scanf("%lld", &slime[i]);
if (s... | 10 |
#include <bits/stdc++.h>
using namespace std;
struct Node {
int to, w, next;
bool operator<(const Node &a) const { return a.w < w; }
} Edge[200005], S, Next;
int head[200005], num;
int dist[200005];
bool a[405][405], vis[200005];
int n, m;
void init() {
for (int i = 0; i <= n; i++) {
head[i] = -1;
}
num =... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); }
vector<long long int> v[300005];
bool vis[300005];
void solve() {
long long n, q;
cin >> n >> q;
long long x, y, c = ... | 8 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
const long long maxn = 1e6;
long long n, d, m;
cin >> n >> d >> m;
vector<long long> hi(maxn), lo(maxn);
long long locnt = 0, hicnt = 0, sum = 0;
for (int i = 0; i < n; i++) {
long long a;
cin >> a;
sum += a;
if (a > m)
hi[++... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 1505;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
if (n == 0) {
cout << "YES\n";
cout << 1 << '\n' << 1 << '\n' << 3 << '\n' << 3;
return 0;
}
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int max_n = (int)1e5;
const int max_val = (int)1e4 + 1;
const int k = 1000;
int gadd[max_n / k], a[max_n], cnt[max_n / k][max_val];
int n, m, l, r, d;
char cmd[100];
bool lucky[max_val];
bool check(int x) {
if (!x) return false;
while (x) {
if ((x % 10 != 4) &... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int MAXK = 10, MAXN = 1000;
char s1[MAXN + 1], s2[MAXN + 1];
int p, n, m, len[MAXN + 1][MAXN + 1];
long long dp[MAXN + 1][MAXN + 1][MAXK + 1][2];
long long maxll(long long a, long long b) {
if (a > b) return a;
return b;
}
int main() {
cin >> n >> m >> p;
for ... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int arr[5] = {0}, cnt = 0;
for (int i = 1; i < 5; i++) cin >> arr[i];
string str;
cin >> str;
int len = str.length();
for (int i = 0; i < len; i++) {
cnt += arr[str[i] - '0'];
}
cout << cnt;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, i = 1, j = 0, c = 1, f = 000000000, l, k, x = 0, y, z, m, b,
d, h, u;
string s, w = "", s1;
deque<int> qul, qur;
map<char, int> ch;
vector<pair<int, int>> vect;
cin >> n;
for (i = 0; i < n; i++) {
cin >> x >... | 5 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3", "unroll-loops", "omit-frame-pointer", "inline")
#pragma GCC option("arch=native", "tune=native", "no-zeroupper")
#pragma GCC target("avx", "popcnt")
using namespace std;
const long long int INF = (long long int)1e17 + 5;
const unsigned long long int MOD = 1e9 + 7;
int... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, cnt = 1, ind = 1;
scanf("%d", &n);
for (int i = 1; i < n; i++) {
ind += cnt;
while (ind > n) {
ind -= n;
}
printf("%d ", ind);
cnt++;
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int n, i, a[22], j, x[22][2], k = 0, s[11], b[5][5], s0 = 0;
int rec(int x0, int y0) {
if (!((x0 == n - 1) && (y0 == n))) {
if (y0 == n) {
y0 = x0;
x0++;
}
if (x0 == n) {
y0++;
x0 = y0;
}
for (int i = 0; i < k; i++) {
if (... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n, c0, c1, h;
string s;
void solve() {
cin >> n >> c0 >> c1 >> h;
cin >> s;
int count0 = 0;
int count1 = 0;
for (int i = 0; i < n; i++) {
if (s[i] == '0') {
count0++;
}
}
count1 = n - count0;
int sum = 0;
if (c0 > c1 && h < c0) {
int ... | 0 |
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
template <typename T>
inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
constexpr int B = 210;
void solve() {
int n;
cin >> n;
vect... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, Hech = 0;
string s;
while (getline(cin, s)) {
for (i = 0; i < s.length(); i++)
if (s[i] != ' ') break;
if (i == s.length() || s[i] != '#') {
if (Hech == 2) cout << endl;
for (i = 0; i < s.length(); i++)
if (s[i] !=... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s[n];
for (int i = 0; i < n; i++) {
cin >> s[i];
}
for (int i = 0; i < n; i++) {
for (int j = i; j < n; j++) {
if (s[i].size() > s[j].size()) {
swap(s[i], s[j]);
}
}
}
for (int i = 0; i < n... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 2005;
int n;
int t[MAX][MAX];
long long diag1[2 * MAX], diag2[2 * MAX];
int main() {
scanf(" %d", &n);
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) scanf(" %d", &t[i][j]);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long infll = 0x3f3f3f3f3f3f3f3fLL;
inline long long read() {
long long x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x ... | 13 |
#include <bits/stdc++.h>
using namespace std;
int n, s, c[3], w[3], pt[3], ans = 0x7f7f7f7f;
void exgcd(int a, int b, int &GCD, int &x, int &y) {
if (!b) {
GCD = a, x = 1, y = 0;
} else
exgcd(b, a % b, GCD, y, x), y -= a / b * x;
}
void checkmin() {
int tmp = abs(w[0] * c[0] - w[1] * c[1]) + abs(w[1] * c[... | 16 |
#include <bits/stdc++.h>
using namespace std;
vector<long long> p;
int main() {
long long n;
cin >> n;
p.push_back(1);
for (int i = 0; i < 80; i++) {
p.push_back(p.back() * 3LL);
}
int ind = 0;
while (p[ind] <= n) ind++;
for (int i = 0; i < 80; i++) {
if (n % p[i] != 0) {
long long ans = n... | 8 |
#include <bits/stdc++.h>
using namespace std;
int ntest = 0, test = 0;
inline void init();
inline void run();
inline void stop() { ntest = test - 1; }
int main() {
init();
while (++test <= ntest) {
run();
}
return 0;
}
const int INF = (int)1E9 + 5;
const long double EPS = 1E-6;
const long long MOD = (long l... | 12 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
using v2d = vector<vector<T> >;
template <class T>
bool uin(T &a, T b) {
return a > b ? (a = b, true) : false;
}
template <class T>
bool uax(T &a, T b) {
return a < b ? (a = b, true) : false;
}
mt19937 rng(chrono::system_clock::now().time_since_epoch(... | 16 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
T inline SQR(const T& a) {
return a * a;
}
template <typename T>
T inline ABS(const T& a) {
return a < 0 ? -a : a;
}
template <typename T>
T inline MIN(const T& a, const T& b) {
if (a < b) return a;
return b;
}
template <typename T>
T inline MA... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
long long f[510][510], res, ans[510];
int main() {
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; i++) f[0][i] = 1;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
for (int k = 1; k <= min(i, j); k++)
f[i][j] = (f[i][j] + f[i - k]... | 13 |
#include <bits/stdc++.h>
using namespace std;
int n, i, a[200000];
int mod(int a, int b) { return ((a % b) + b) % b; }
bool solve() {
map<int, bool> m;
scanf("%d", &n);
for (i = 0; i < n; i++) scanf("%d", &a[i]);
for (i = 0; i < n; i++) {
if (m[mod(i + a[i], n)]) return 0;
m[mod(i + a[i], n)] = 1;
}
... | 8 |
#include <bits/stdc++.h>
using namespace std;
using ii = pair<int, int>;
using ll = long long;
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
os << "[ ";
for (auto e : v) os << e << " ";
return os << "]";
}
template <typename T, typename V>
ostream& operator<<(ostream& os, set<T, V> v) {
... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, j;
int n;
cin >> n;
vector<int> a;
for (i = 0; i < n; i++) {
int x;
cin >> x;
a.push_back(x);
}
stack<int> in;
stack<int> dec;
int flag = 1;
for (i = 0; i < n; i++) {
if (in.empty())
in.push(i);
else {
... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int N = 500000;
int a[N];
bool vis[N];
int main() {
int n, m;
cin >> n >> m;
int mn = min((m - 1), (n - m));
cout << (n + 1) + n + ((n - 1) + mn);
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
bool is_pal_del(vector<int> v, int ch) {
v[ch]--;
bool nchet = false;
for (int i = 0; i < 26; i++) {
if (v[i] % 2 != 0 && nchet) {
return false;
}
if (v[i] % 2 != 0) nchet = true;
}
return true;
}
bool is_pal(vector<int> v) {
int col = 0;
for... | 5 |
#include <bits/stdc++.h>
int main() {
long n;
scanf("%ld", &n);
std::map<long, long> m;
for (long p = 0; p < n; p++) {
long x;
scanf("%ld", &x);
++m[x];
}
std::vector<long> keys, values;
for (std::map<long, long>::iterator it = m.begin(); it != m.end(); it++) {
keys.push_back(it->first);
... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int inf = numeric_limits<int>::max();
const long long linf = numeric_limits<long long>::max();
const int max_n = 51;
int n, a[max_n], sm[max_n][max_n];
bool comp(pair<int, pair<int, int>> a, pair<int, pair<int, int>> b) {
if (a.first == b.first) {
if (b.second.s... | 11 |
#include <bits/stdc++.h>
#pragma GCC optimize("-O2")
using namespace std;
void err(istream_iterator<string> it) { cerr << endl; }
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << "\t";
err(++it, args...);
}
template <typename T1, typenam... | 11 |
#include <bits/stdc++.h>
using namespace std;
unordered_map<int, int> P[100100];
set<int> C[100100];
vector<int> L[100100];
map<pair<int, int>, int> ans;
int find(int c, int x) {
if (P[c].find(x) == P[c].end()) {
P[c][x] = x;
return x;
}
if (P[c][x] == x) return x;
P[c][x] = find(c, P[c][x]);
return P... | 16 |
#include <bits/stdc++.h>
using namespace std;
set<pair<double, double> > s;
long long a[310];
long long bb[310];
long long c[310];
bool bet(double x, long long a1, long long a2) {
if (a1 >= a2) {
if (x >= a2 && x <= a1) return true;
} else if (x <= a2 && x >= a1)
return true;
return false;
}
int main() {
... | 9 |
#include <iostream>
#include <fstream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <cassert>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll inf = 1e15;
int main() {
//srand(static_cast<unsigned int>(time(nullptr)));
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n = 0;
cin >> n;
int gran = 0;
string data[n];
for (int i = 0; i < n; i++) {
cin >> data[i];
if (data[i] == "Icosahedron") {
gran += 20;
} else if (data[i] == "Cube") {
gran += 6;
} else if (data[i] == "Tetrahedron") {
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + 51;
int cnt, k, tmp;
int num[MAXN];
inline int read() {
register int num = 0, neg = 1;
register char ch = getchar();
while (!isdigit(ch) && ch != '-') {
ch = getchar();
}
if (ch == '-') {
neg = -1;
ch = getchar();
}
while (is... | 12 |
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
while (b) {
a %= b;
swap(a, b);
}
return a;
}
int lca(int a, int b) { return a / gcd(a, b) * b; }
bool play(char l, char r) {
return (l == 'R' && r == 'S') || (l == 'S' && r == 'P') ||
(l == 'P' && r == 'R');
}
int main() {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n;
int arr[N], old[N];
vector<int> adj[N];
bool vis[N];
int ans;
vector<vector<int>> vv;
vector<int> s;
void DFS(int i) {
if (vis[i]) {
return;
}
vis[i] = 1;
s.push_back(i);
for (int x = 0; x < adj[i].size(); ++x) DFS(adj[i][x]);
}
i... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6;
int n, a[N], ans = 2e9, bound[N], val[N];
vector<pair<int, int>> in[N], out[N];
multiset<int> st;
set<int> id;
struct node {
int mn[2];
node(int a = 2e9, int b = 2e9) {
mn[0] = a;
mn[1] = b;
}
node operator+(const node &a) {
node ret;
... | 21 |
#include <bits/stdc++.h>
using namespace std;
struct box {
int len;
int special;
};
bool operator<(box a, box b) {
if (a.special && !b.special)
return false;
else if (!a.special && b.special)
return true;
else if (!a.special && !b.special)
return a.len < b.len;
else
return a.len > b.len;
}
c... | 19 |
#include <bits/stdc++.h>
using namespace std;
int n, k, x = 0, c = 0;
int main() {
cin >> n >> k;
int a = 96;
while (true) {
++a;
if (c % k == 0) a = 97;
if (a == 123) {
a = 97;
}
cout << (char)a;
++x;
if (x == n) break;
++c;
}
return 0;
}
| 0 |
#include<bits/stdc++.h>
#define int long long
using namespace std;
int a[200005];
int n,k;
int is_poss(int x)
{vector<int> v;
for(int i=0;i<n;i++)
{if(a[i]>=x){v.push_back(1);}
else{v.push_back(-1);}
}
int pref[n];
pref[0]=v[0];
for(int i=1;i<n;i++)
{pref[i]=pref[i-1]+v[i];
}
int maxa=-1e12;
for(in... | 13 |
#include <bits/stdc++.h>
int n, k, m;
long long l;
long long a[100010];
bool vis[100010];
using namespace std;
long long solve() {
if (a[n] - a[1] > l) return 0;
long long tot = 0, mark, left;
left = n;
for (int i = 1; i <= m; i++)
if (a[i] - a[1] > l) {
mark = i - 1;
break;
}
for (int i =... | 7 |
/*Bismillahir Rahmanir Rahim*/
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define forn(i, n) for(int i = 0; i < n; i++)
#define rforn(i, n) for(int i = n-1; i >= 0; i--)
#defin... | 8 |
#include <bits/stdc++.h>
using namespace std;
char s[705];
int tmp[705];
int match[705];
long long dp[705][705][3][3];
void getmatch(int len) {
int p = 0;
for (int i = 0; i < len; i++) {
if (s[i] == '(')
tmp[p++] = i;
else {
match[i] = tmp[p - 1];
match[tmp[p - 1]] = i;
p--;
}
... | 11 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int res = 0;
int neg;
while (true) {
char ch = getchar();
if (ch >= '0' && ch <= '9' || ch == '-') {
if (ch == '-')
neg = -1;
else
neg = 1, res = ch - '0';
break;
}
}
while (true) {
char ch = ge... | 14 |
#include <bits/stdc++.h>
#pragma GCC optimize(3)
using namespace std;
double p[5000 + 1], dp[5000 + 1][5000 + 1], sum[5000 + 2];
int t[5000 + 1];
double power(double x, int y) {
double res = 1.0;
while (y) {
if (y & 1) res *= x;
x *= x;
y >>= 1;
}
return res;
}
int main() {
int n, m, i, j;
scanf... | 16 |
#include <bits/stdc++.h>
using namespace std;
int n, res, a;
int main() {
res = 0;
vector<int> v;
cin >> n;
if (n == 1) {
cin >> a;
cout << a << endl;
return 0;
}
for (int i = 0; i < n; ++i) {
cin >> a;
v.push_back(a);
}
for (int i = 0; i < v.size(); ++i) {
int xp = 0;
for (i... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, Log[200005], p = 1;
long long ans;
char s[200005];
inline int read() {
int s = 0, f = 0;
char ch = getchar();
while (ch < 48 || ch > 57) f |= (ch == '-'), ch = getchar();
while (ch > 47 && ch < 58)
s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
re... | 26 |
#include <bits/stdc++.h>
using namespace std;
const int maxa = 1 << 16;
const int base = 16;
const int mod = maxa - 1;
const int maxn = 1e5 + 10;
int a[maxn], tmp[maxn];
int c[maxa];
void Sort1();
void Sort2();
int n, m;
int main() {
scanf("%d%d", &m, &n);
for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
Sort1();... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int mm = 1007;
int mp[mm][mm];
int n;
int main() {
while (cin >> n) {
n--;
memset(mp, 0, sizeof(mp));
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) mp[i][j] = (i + j) % n + 1;
for (int i = 0; i < n; i++) mp[i][n] = mp[n][i] = mp[i][i]... | 13 |
#include <bits/stdc++.h>
struct quest {
double prob;
double w;
double prod;
double get(double x) { return prob * x + prod; }
} q[100003];
long long int t;
int n;
double maxw;
bool cmp1(const quest &a, const quest &b) {
return a.prob < b.prob || (a.prob == b.prob && a.w < b.w);
}
bool cmp(double k1, double b1,... | 23 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
string s, t;
cin >> n;
cin >> s >> t;
int ct[27];
memset(ct, 0, sizeof(ct));
for (int i = 0; i < s.size(); ++i) {
ct[s[i] - 'a']++;
ct[t[i] - 'a']++;
}
bool invalid = fa... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int ans[N];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, k;
cin >> n >> k;
if (n < 3 * k) {
cout << -1 << '\n';
return 0;
}
if (k % 2 == 0) {
for (int i = 1; i <= 3 * k; i += 6) {
ans[i] = ans[i + 1] =... | 7 |
#include <bits/stdc++.h>
int main() {
long long n, a, b;
long long re;
re = 0;
long long num[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};
scanf("%lld %lld", &a, &b);
long long f, g, h, j, k, l, m;
for (n = a; n <= b; n++) {
m = n / 1000000;
f = (n - m * 1000000) / 100000;
g = (n - m * 1000000 - f * 1... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> v(n);
vector<int> s(n + 1);
for (int i = 0; i < n; i++) {
cin >> v[i];
s[v[i]]++;
}
int k ... | 7 |
#include <bits/stdc++.h>
using namespace std;
vector<int> e[100010];
int p[100010][11], sz[100010];
void gg(int val, int u) {
sz[u] = 0;
int q = sqrt(val + .5);
for (int i = 2; i <= q; ++i) {
if (val % i == 0) {
p[u][sz[u]++] = i;
while (val % i == 0) val /= i;
}
}
if (val != 1) p[u][sz[u]... | 13 |
#include <bits/stdc++.h>
using namespace std;
int n, x, y, a[101000];
bool flag;
int main() {
scanf("%d%d%d", &n, &x, &y);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
for (int i = 1; i <= n; i++) {
flag = 1;
for (int j = max(1, i - x); j <= min(i + y, n); j++) {
if (a[j] < a[i]) {
flag ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int Alp = 20;
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int test;
cin >> test;
while (test--) {
int len;
string a, b;
cin >> len >> a >> b;
vector<int> adj(Alp);
vector<vector<int>> G(Alp);
for (int i = 0; i < len; ++i)
... | 23 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
struct node1 {
int f, ti;
long long c;
} a[N];
struct node2 {
int to, ti;
long long c;
} b[N];
bool cmp1(node1 a, node1 b) { return a.ti < b.ti; };
bool cmp2(node2 a, node2 b) { return a.ti > b.ti; };
bool vis[N];
long long pre[N];
long long ... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, l, c, d, p, nl, np;
cin >> n >> k >> l >> c >> d >> p >> nl >> np;
int x, y, z;
x = (k * l) / nl;
y = (c * d);
z = p / np;
cout << min(min(x, y), z) / n;
return 0;
}
| 0 |
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
int dx[] = {0, 0, 1, -1, 1, -1, 1, -1};
int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};
int ddx[] = {-1, 0, 1};
const double pi = acos(-1), eps = 1e-9;
const int OO = 0x3f3f3f3f, N = 1e6 + 5, mod = 1e9 + ... | 12 |
#include <bits/stdc++.h>
using namespace std;
void doRoutine() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
srand(322179);
}
template <typename T>
ostream &operator<<(ostream &out, vector<T> a) {
out << "[";
for (int i = 0; i + 1 < a.size(); ++i) {
out << a[i] << ", ";
}
if (!a.empty... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int64_t mod = 1e9 + 7;
const int64_t inf = 1e16 + 7;
void Solve() {
string s;
cin >> s;
stack<int64_t> st;
for (int64_t i = s.size() - 1; i >= 0; --i) {
if (s[i] == ')') {
st.push(i);
}
}
int64_t ans = 0;
for (int64_t i = 0; i < s.size(); +... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, pre, n;
int flag = 0;
cin >> n;
cin >> a >> b;
if (a != b) flag = 1;
pre = a;
while (--n) {
cin >> a >> b;
if (a != b) flag = 1;
if (flag != 1 && pre < a) flag = -1;
pre = a;
}
switch (flag) {
case 1:
cout <... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int A = 26;
int main() {
int n;
cin >> n;
string l;
cin >> l;
vector<vector<int>> left(A);
vector<int> wl;
for (int i = 0; i < int(n); i++)
if (l[i] != '?')
left[l[i] - 'a'].push_back(i);
else
wl.push_back(i);
string r;
cin >> r;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
long double r, x, y, x2, y2;
int main() {
cin >> r >> x >> y >> x2 >> y2;
long double d = sqrt((x - x2) * (x - x2) + (y - y2) * (y - y2));
long double k = d / (2 * r);
long double k2 = (long double)(int)(k);
if (k > k2) k += 1.0;
long double k3 = k;
cout << ((... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
const long long inf = 1ll << 60;
const int mod = 1000000007;
const double eps = 1e-8;
long long l, r;
int k;
int bit(long long x) {
int res = 0;
long long tp = 1;
while (tp * 2 <= x) {
res++;
tp *= 2;
}
return res;
}
void sol() {
... | 15 |
#include <bits/stdc++.h>
int dx[4] = {0, -1, 0, 1};
int dy[4] = {1, 0, -1, 0};
using namespace std;
int n;
int x[123456], y[123456];
map<pair<int, int>, int> id;
int get(int x, int y) {
if (id.find({x, y}) == id.end()) return -1;
return id[{x, y}];
}
set<int> up[123456], down[123456];
set<int> stable;
void del(int ... | 13 |
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1000 + 10, inf = 1e18, mod = 1e9 + 7;
struct que {
long long a[maxn];
long long s = 0, f = 0;
void clear() { s = f = 0; }
void push(long long x) { a[f++] = x; }
void pop() { s++; }
long long back() { return a[s]; }
long long front() { re... | 18 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.