solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
struct BitTree {
int t[N];
void init() { memset(t, 0, sizeof t); }
void add(int p, int x) {
for (; p < N; p += p & -p) t[p] += x;
}
int sum(int p) {
int res = 0;
for (; p; p -= p & -p) res += t[p];
return res;
}
} b[4][11][... | 13 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
bool node[1000000];
long long n, m;
cin >> n >> m;
for (long long i = (long long)1; i < (long long)m + 1; i++) {
long long x, y;
cin >> x >> y;
node[x] = node[y] = true;
}
long long center;
for (long long i = (long long)1; i < (long ... | 5 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const long long int maxn = 5e5 + 1;
void solve() {
long long int n;
cin >> n;
long long int a[n], len[11];
memset(len, 0, sizeof(len));
for (long long int i = 0; i < n; i++) {
cin >> a[i];
long long int d = a[i];
long long... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e5 + 10;
int ft[maxN];
int L[maxN], R[maxN];
int n, m;
int cnt[maxN];
void upd(int pos, int v) {
pos += 1;
while (pos < maxN) {
ft[pos] = max(ft[pos], v);
pos += pos & -pos;
}
}
int qry(int pos) {
pos += 1;
int ans = 0;
while (pos > 0) ... | 11 |
#include <bits/stdc++.h>
int debugnum = 0;
using namespace std;
const int MAXN = 1e6 + 50;
vector<int> arc[MAXN];
int DFS(int K, int pos, int &depth, int &score1, int &score2) {
if (arc[pos].size() == 0) {
depth = score1 = score2 = 1;
return 0;
}
depth = INT_MAX >> 1;
score1 = 0;
score2 = 0;
for (in... | 17 |
#include <bits/stdc++.h>
using namespace std;
vector<int> adj;
vector<int> vis;
int dfs(int x) {
int y = adj[x];
vis[adj[x]]++;
if (vis[y] == 2) return y + 1;
dfs(y);
}
int main() {
int t = 1;
int n, a, b, c = 0, l;
string s;
cin >> n;
adj.resize(n);
vis.resize(n);
for (int i = 0; i < n; i++) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cer... | 10 |
#include <bits/stdc++.h>
const int MAXN = 3e5 + 10;
typedef struct node {
int u;
int v;
int nxt;
int mode;
char ans;
bool ex;
bool fina;
} node;
node edge[MAXN * 2];
int head[MAXN], cnt;
void addedge(int a, int b, int c, int flag) {
edge[cnt].u = a;
edge[cnt].v = b;
edge[cnt].mode = c;
edge[cnt].f... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long n, x, y, t;
long long a[110000], h[110000];
struct edge {
long long y, nxt, w;
} e[110000];
void add(long long i) {
t++;
e[t].y = i;
e[t].nxt = h[x];
e[t].w = y;
h[x] = t;
}
void dfs(long long k, long long x, long long s) {
for (long long i = h[k]; i... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e4 + 15;
const int inf = 1e9;
struct Edge {
int v, cap, rev;
Edge() {}
Edge(int v, int cap, int rev) : v(v), cap(cap), rev(rev) {}
};
vector<Edge> vt[N];
void addEdge(int s, int e, int c) {
vt[s].push_back(Edge(e, c, (int)vt[e].size()));
vt[e].push_... | 16 |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
long long x = 0, f = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') f = -f;
ch = getchar();
}
while (isdigit(ch)) {
x = (x << 1) + (x << 3) + (ch ^ 48);
ch = getchar();
}
return x * f;
}
inline void writ... | 19 |
#include <bits/stdc++.h>
using namespace std;
long long power(long long base, long long exp) {
long long res = 1;
while (exp > 0) {
if (exp % 2 == 1) res = (res * base);
base = (base * base);
exp /= 2;
}
return res;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string s;
ci... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const int INF = 2e9;
const int MAX_LOG = 21;
const int MAX_N = 12800;
string rep(string &s, int k, int n) {
string news;
int len = s.length();
while (news.length() < n - len) {
news.append(s);
}
for (char ch : s) {
news.inser... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n;
int color[105];
int num[105];
int bit(int i) { return 1 << i; }
int bitCount(int x) { return x == 0 ? 0 : bitCount(x / 2) + (x & 1); }
int judge(int x) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (color[i] == color[j]) {
if ... | 9 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, f = 1, ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = (x << 3) + (x << 1) + (ch - '0');
ch = getchar();
}
return f == 1 ? x : -x;
}
inlin... | 20 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int l = log2(m);
if (l < n)
cout << m;
else
cout << (m % (int)pow(2, n));
}
| 1 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
double pi = 3.1415926535898;
const long long M = 1e9 + 7;
const int N = 50500;
const int inf = INT_MAX;
const double eps = 1e-6;
map<string, int> mp1;
map<int, vector<string>> mp2;
set<string> st;
int point[300];
int main() {
string name, s, s1,... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n, b[255][255], c[255][255], m, dp[255], F[255][2];
char a[4 * 255][4 * 255];
void up(int &F, int x) { F = (F + x) % 1000000007; }
int main() {
scanf("%d%d\n", &n, &m);
for (int i = 1; i <= 4 * n + 1; i++) {
for (int j = 1; j <= 4 * m + 1; j++) scanf("%c", &a[i]... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 201000;
int b[MAX_N], x[MAX_N], a[MAX_N];
int main(void) {
int n, i;
scanf("%d", &n);
for (i = 1; i <= n; i++) scanf("%d", &b[i]);
for (i = 1; i <= n; i++) {
x[i] = max(x[i - 1], a[i - 1]);
a[i] = b[i] + x[i];
}
for (i = 1; i <= n; i++)... | 1 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const long long infLL = 9000000000000000000;
int dx[] = {0, 0, +1, -1};
int dy[] = {+1, -1, 0, 0};
template <typename first, typename second>
ostream &operator<<(ostream &os, const pair<first, ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
while (~scanf("%d", &n)) {
if (n == 1 || n == 2) {
printf("-1\n");
} else {
for (int i = n; i >= 1; i--) {
printf("%d ", i);
}
printf("\n");
}
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 5143;
const long long Linf = 1e18 + 5413;
const double eps = 1e-10;
const double pi = acos(-1);
template <class T>
inline void umax(T &a, T b) {
if (a < b) a = b;
}
template <class T>
inline void umin(T &a, T b) {
if (a > b) a = b;
}
template <clas... | 10 |
#include <bits/stdc++.h>
using namespace std;
template <typename TH>
void _dbg(const char* sdbg, TH h) {
cerr << sdbg << "=" << h << "\n";
}
template <typename TH, typename... TA>
void _dbg(const char* sdbg, TH h, TA... t) {
while (*sdbg != ',') cerr << *sdbg++;
cerr << "=" << h << ",";
_dbg(sdbg + 1, t...);
}
... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long power(long long a, long long b, long long md) {
return (!b ? 1
: (b & 1 ? a * power(a * a % md, b / 2, md) % md
: power(a * a % md, b / 2, md) % md));
}
const int xn = 1e6 + 10;
const int xm = 1e1 + 16;
const int sq = 320;
cons... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int N = 110;
char a[N][N];
int str[N], sto[N];
int main() {
int n, m;
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> a[i][j];
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
const int MOD = 1000000007;
int N, Q;
char c[MAXN];
int S[MAXN];
long long modpow(long long base, long long expo) {
base %= MOD;
long long res = 1;
while (expo > 0) {
if (expo & 1) res = res * base % MOD;
base = base * base % MOD;
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 505;
multiset<long long> a[maxn * 2], b[maxn * 2];
int main() {
int n, m, x;
cin >> n >> m;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) cin >> x, a[i + j].insert(x);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) cin... | 7 |
#include <bits/stdc++.h>
using namespace std;
int q, n;
long long num, x, a, y, b, k;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> q;
while (q--) {
cin >> n;
vector<long long> tix(n);
for (long long& t : tix) cin >> t;
cin >> x >> a >> y >> b >> k;
if (x < y) {
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 100;
bool generated;
int n;
int a[N], nxt[N];
vector<int> v[N];
int query(int value, int i, int j) {
if (v[value].empty()) return -1;
int pos = lower_bound(v[value].begin(), v[value].end(), i) - v[value].begin();
if (pos >= v[value].size()) return ... | 13 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void chkmax(T &a, T b) {
if (a < b) a = b;
}
template <class T>
void chkmin(T &a, T b) {
if (a > b) a = b;
}
const int inf = 0x3f3f3f3f;
char s[5005];
vector<int> v[30];
int n, g[30], h[30], mx[30];
int main() {
scanf("%s", s);
int d;
int len = ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int pr[100005], bt[100005], mbt[100005];
int process(vector<pair<int, int> > &b, int c) {
sort(b.begin(), b.end());
int n = b.size();
for (int i = 0; i < n; i++) {
pr[i] = b[i].first;
bt[i] = b[i].second;
if (i != 0)
mbt[i] = max(bt[i], mbt[i - 1]);
... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, count = 1;
cin >> n;
int a[n];
for (i = 0; i < n; i++) {
cin >> a[i];
}
for (i = 0; i < n - 1; i++) {
if (a[i] != a[i + 1]) {
count++;
}
}
cout << count;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
bool check(string s) {
int N = (s).size();
sort((s).begin(), (s).end());
for (int i = 1; i < N; i++) {
if (s[i] == s[i - 1]) {
return false;
}
}
return true;
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int l, r, ans = -1... | 0 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n, m;
cin >> n >> m;
int A[n][m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
char c;
cin >> c;
if (c == '1') {
A[i][j] = 1;
} else {
A[i][j] = 0;
}
}
}
int B[n][m];
for (... | 4 |
#include <bits/stdc++.h>
using namespace std;
static constexpr uint_fast8_t R = 26;
static uint_fast16_t n;
static uint_fast32_t e[R] = {1};
struct Command {
uint_fast8_t x;
uint_fast8_t y;
uint_fast8_t k;
uint_fast8_t z;
};
static vector<Command> m;
static vector<Command> p;
static void s(const uint_fast8_t f)... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int NN = 111111;
int f[NN];
struct Q {
int x, pos;
} q[NN * 10];
int main() {
int n, pos = 0;
cin >> n;
for (int i = 1; i <= n; i++) cin >> f[i];
for (int i = 2; i <= n; i++)
if (f[i] < f[i - 1]) {
pos = i;
break;
}
if (pos == 0) {
... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, i;
cin >> n >> k;
string a;
cin >> a;
if (k > (n / 2)) {
for (i = 0; i < n - k; i++) {
cout << "RIGHT" << endl;
}
for (i = n - 1; i >= 0; i--) {
cout << "PRINT " << a[i] << endl;
if (i == 0) {
break;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using pi = pair<int, int>;
const int mod = 1e9 + 7;
const ll inf = ll(1e18);
const double PI = acos(-1), eps = 1e-9;
const int mxa = 1e3;
const int mxn = 5e3, mxm = 2e5, mxk = 18;
int n, a[mxn];
int calc(int l, int r, int h) {
... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
int n, m;
int arr[N], b[N];
int ans = 1e7;
int main() {
cin >> n >> m;
for (int i = 0; i < n; i++) cin >> arr[i];
arr[n] = 1e9;
sort(arr, arr + n);
int x = 0;
for (int i = 0; i < m; i++) {
int x1, x2, y;
cin >> x1 >> x2 >> y;
i... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 * 4;
inline int g() {
int x;
cin >> x;
return x;
}
inline long long gl() {
long long x;
cin >> x;
return x;
}
inline char gc() {
char x;
cin >> x;
return x;
}
inline string gs() {
string s;
cin >> s;
return s;
}
template <typenam... | 6 |
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
const double PI = acos(-1.0);
const int MOD = 1000 * 1000 * 1000 + 7;
const int INF = 2000 * 1000 * 1000;
template <typename T>
inline T sqr(T n) {
return n * n;
}
char s[10][10];
char name[6] = {'Q', 'R', 'B', 'N', 'P', 'K'};
char weight[6] = {9,... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5;
int n, k, a[N], len[N];
map<int, int> freq[11];
int main(int argc, char **argv) {
scanf("%d%d", &n, &k);
for (int i = 0; i < n; ++i) {
scanf("%d", &a[i]);
for (int b = a[i]; b != 0; b /= 10) ++len[i];
++freq[len[i]][a[i] % k];
}
long l... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 500005;
struct iii {
int a, b, c;
bool operator>(iii other) const {
return tie(a, b, c) > tie(other.a, other.b, other.c);
}
};
int N, par[2 * MAXN];
int find(int n) { return par[n] = par[n] == n ? n : find(par[n]); }
bool merge(int a, int b) {
i... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const double PI = 3.14159265359;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
long long n, k, ans = 0;
cin >> n >> k;
vector<long long> v(n);
for (auto& i : v) cin >> i;
vector<int> oneEnd(n);
int r = 0;
for (int i = 0; i... | 13 |
#include <bits/stdc++.h>
using namespace std;
int a[1000015];
int b[1000015];
int n, m;
int check;
int dfs1(int x, int y) {
if (x == n && y == m) {
check = 0;
b[y + (x - 1) * m] = 0;
return 0;
}
int k1, k2;
k1 = x + 1;
k2 = y;
if (k1 <= n && k2 <= m && a[k2 + (k1 - 1) * m] == 1 && check == 1 &&
... | 11 |
#include <bits/stdc++.h>
using namespace std;
int a[100010];
int n;
int gcd(int x, int y) { return y == 0 ? x : gcd(y, x % y); }
int main() {
int i, max = 0;
cin >> n;
for (i = 0; i < n; i++) {
cin >> a[i];
if (max < a[i]) max = a[i];
}
int t = gcd(a[0], a[1]);
for (i = 1; i < n; i++) t = gcd(t, a[i... | 8 |
#include <bits/stdc++.h>
using namespace std;
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
inline int gcd(int a, int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
template <typename T>
string to_str(T str) {
stringstream stream;
stream << str;
return stream.str();
}
template <typenam... | 8 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int TESTS = 1;
while (TESTS--) {
long long n;
cin >> n;
string s[2 * n];
for (long long i = 0; i < 2 * n; i++) {
for (long long j = 0; j < 2 * n; j++) {
s[i].p... | 6 |
#include <bits/stdc++.h>
using namespace std;
void getint(int &v) {
char ch, fu = 0;
for (ch = '*'; (ch < '0' || ch > '9') && ch != '-'; ch = getchar())
;
if (ch == '-') fu = 1, ch = getchar();
for (v = 0; ch >= '0' && ch <= '9'; ch = getchar()) v = v * 10 + ch - '0';
if (fu) v = -v;
}
int n, m, tt, tot, ... | 21 |
#include <bits/stdc++.h>
void nop();
using namespace std;
const int inf = (int)1e9;
const long long infl = (long long)2e18;
const int mod = 1000000007;
struct V {
int count = 0;
int n[2] = {-1, -1};
int p = -1;
};
int main() {
int n;
cin >> n;
vector<int> a(n), p(n);
for (int &ai : a) {
cin >> ai;
}... | 10 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k;
long long a[200004], s[200004];
int p[200004];
long long f[200004];
int main() {
scanf("%d%d%d", &n, &m, &k);
a[0] = 0;
for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
memset(p, 0, sizeof(p));
for (int i = 1; i <= m; i++) {
int x, y;
scanf(... | 13 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long n, m, a[401], f[1 << 15][71], g[1 << 15], fa[10001], in[1001],
c[201][201];
long long peach[1 << 15], ans = 1, hd = 0;
vector<long long> vec[101], Vec;
long long g_fa(long long x) {
if (fa[x] == x)
return x;
else
retu... | 27 |
#include <bits/stdc++.h>
using namespace std;
template <typename num_t>
inline void add_mod(num_t& a, const long long& b, const int& m) {
a = (a + b) % m;
if (a < 0) a += m;
}
template <typename num_t>
inline bool update_max(num_t& a, const num_t& b) {
return a < b ? a = b, true : false;
}
template <typename num_... | 17 |
#include <bits/stdc++.h>
char in[10][10];
char temp[10][10];
int ans = INT_MAX;
int mindiff(int n) {
int i, j, max = INT_MIN, diff;
if (n == 1) return 0;
for (i = 0; i < n; i++)
for (j = i + 1; j < n; j++) {
diff = abs(atoi(temp[i]) - atoi(temp[j]));
if (diff > max) max = diff;
}
return max;... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long i, j, n, k, a[6], b[6], ans = 0, s, m;
int main() {
cin >> n >> m;
while (n % 2 == 0) {
n /= 2;
a[2]++;
}
while (m % 2 == 0) {
m /= 2;
b[2]++;
}
while (n % 3 == 0) {
n /= 3;
a[3]++;
}
while (m % 3 == 0) {
m /= 3;
b[3... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n;
inline int lowbit(int x) { return x & -x; }
int c[N];
bool vis[N];
void add(int pos) {
if (vis[pos]) return;
vis[pos] = 1;
while (pos <= n) {
c[pos]++;
pos += lowbit(pos);
}
}
int sum(int pos) {
int ret = 0;
while (pos) {
... | 12 |
#include <bits/stdc++.h>
int T, i, j, n, q[20];
long long A, B, C, a, b, c, M, MA, ans, v, p[20];
void cal(int s, long long now) {
if (now > M) return;
if (s > n) {
if (now < a) return;
b = now, c = v / a / b;
if (a * b + a * c + b * c < ans)
ans = a * b + a * c + b * c, A = a, B = b, C = c;
r... | 21 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char s[200][150];
int n, m, i, c, p;
while (cin >> n) {
for (i = 1; i <= n; i++) {
cin >> s[i];
}
p = 0;
c = 0;
for (i = 1; i <= n; i++) {
if (s[i][0] == 'O' && s[i][1] == 'O') {
p = 1;
s[i][0] = '+';
... | 0 |
#include <bits/stdc++.h>
using namespace std;
char A[52][52];
bool res = false;
char dif = 'a' - 'A';
int d;
void f(char c, int x, int y) {
if (A[x][y] != c) return;
A[x][y] += dif;
if (d != 1 && A[x - 1][y] == c + dif) {
res = true;
return;
}
if (d != 2 && A[x + 1][y] == c + dif) {
res = true;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int a[100001];
int f[100001];
int s[301];
inline int find(int l, int r, int x) {
while (l <= r) {
int mid = (l + r) / 2;
if (x >= f[mid])
l = mid + 1;
else
r = mid - 1;
}
return r;
}
int main() {
int n, T;
scanf("%d%d", &n, &T);
int i, j;... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
string x;
for (int i = 0; i < n; i++) {
cin >> x;
for (int y = 0; y < m; y++) {
if (x[y] == '.') {
if (y % 2 == i % 2)
x[y] = 'W';
else
x[y] = 'B';
}
}
cout << x <<... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = (2e5 + 10) * 4;
int s[maxn], lmx[maxn], rmx[maxn], lmn[maxn], rmn[maxn], lv[maxn], rv[maxn],
mv[maxn], mm[maxn];
void Pushup(int k) {
s[k] = s[k << 1] + s[k << 1 | 1];
lmx[k] = max(lmx[k << 1], s[k << 1] + lmx[k << 1 | 1]);
rmx[k] = max(rmx[k << 1... | 19 |
#include <bits/stdc++.h>
using namespace std;
int a[205];
int n;
int dp[205][405];
int f(int T, int i) {
if (i == n) {
return 0;
}
if (dp[i][T] != -1) return dp[i][T];
if (T > a[i]) {
dp[i][T] = abs(T - a[i]) + f(T + 1, i + 1);
} else {
dp[i][T] = min(f(T + 1, i), abs(T - a[i]) + f(T + 1, i + 1));... | 10 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> alice;
vector<vector<int>> bob;
vector<vector<int>> used(3, vector<int>(3, 0));
int startA, startB;
long long k, scoreA, scoreB;
void input() {
cin >> k;
cin >> startA;
cin >> startB;
startA--;
startB--;
int num;
for (int i = 0; i < 3; i++)... | 10 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
double fRand(double fMin, double fMax) {
double f = (double)rand() / RAND_MAX;
return fMin + f * (fMax - fMin);
}
template <class T>
T min(T a, T b, T c) {
return min(a, min(b, c));
}
template <class T>
T max(T a, T b, T c) {
return max... | 12 |
#include <bits/stdc++.h>
using namespace std;
int n = 0;
long long A, B, C, L;
int main() {
ios_base::sync_with_stdio(false);
cin >> A >> B >> C >> L;
long long T = (L + 1) * (L + 2) * (L + 3);
T /= 6;
for (int l = 0; l <= L; ++l) {
if (A + l >= (B + C)) {
long long x = min(A - B - C + l, L - l);
... | 13 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = ((long long)1) << 40;
string s;
int n;
int main() {
cin >> s;
n = s.length();
if (n % 2 != 0) {
cout << "No" << endl;
return 0;
}
int i = 0;
while (true) {
n = s.length();
if (s.empty() || (!s.empty() && i == n - 1)) break;
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int m, n;
int a, b, c;
int main() {
while (scanf("%d%d%d", &a, &b, &c) != EOF) {
int ha = a * c;
int ha1 = b * c;
int ha2 = (ha - ha1) / b;
if ((ha - ha1) % b != 0) ha2++;
cout << ha2 << endl;
}
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(T &x) {
x = 0;
char c = getchar();
int f = 1;
while (!isdigit(c)) {
if (c == '-') f = -1;
c = getchar();
}
while (isdigit(c)) {
x = x * 10 + c - '0';
c = getchar();
}
x *= f;
}
template <class T>
inline voi... | 15 |
#include <bits/stdc++.h>
using namespace std;
int a[100005];
int b[100005];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
b[n] = a[n];
for (int i = n - 1; i >= 1; i--) {
b[i] = a[i] + a[i + 1];
}
for (int i = 1; i <= n; i++) {
cout << b[i];
if (i == n)
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int N, M;
int vis[55];
vector<int> qwq[40];
long long Right[45], cntRight[1 << 20];
long long Onl() {
long long ans = 0;
for (int i = 0; i < N; i++)
if (qwq[i].size() == 0) ans++;
return ans;
}
void dfs(int Now, int x) {
if (vis[Now]) return;
vis[Now] = x;
f... | 21 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
cout << a + b;
return 0;
}
| 7 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k, p[110], num, g[110];
int find(int x) { return x == p[x] ? x : p[x] = find(p[x]); }
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) p[i] = i, g[i] = 1;
int a;
int b;
int ans = 0;
for (int i = 1; i <= m; i++) {
scanf("%d%d", &a, &... | 9 |
#include <bits/stdc++.h>
using namespace std;
int t, n, m;
int store[100005];
long long int gift[100005];
int main() {
cin >> t;
while (t--) {
cin >> m >> n;
vector<vector<long long int>> g(m, vector<long long int>(n, 0));
for (int i = 0; i < m; i++)
for (int j = 0; j < n; j++) cin >> g[i][j];
... | 10 |
#include <bits/stdc++.h>
using namespace std;
struct point {
long long x[2];
point() {}
point(long long a, long long b) {
x[0] = a;
x[1] = b;
}
long long& operator[](long long a) { return x[a]; }
long long operator*(point a) { return x[0] * a.x[1] - x[1] * a.x[0]; }
point operator+(point a) { retu... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int N = 4e5 + 5;
vector<int> vec[N];
bool visited[N];
void dfs(int node) {
if (visited[node]) return;
visited[node] = true;
for (auto to : vec[node]) {
if (!visited[to]) dfs(to);
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
char m[2005][2005];
int mk[2005][2005];
int p[2005][2005];
struct node {
int x, y;
};
int getid(int x, int y) { return (x - 1) * (n + 1) + y; }
vector<int> vec, que;
unordered_set<int> s;
string ans = "";
int main() {
cin >> n >> k;
for (int i = 1; i <= n; i... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long W(long long x, long long y) {
return ((x == 3 and y == 2) or (x == 2 and y == 1) or (x == 1 and y == 3));
}
int main() {
long long k, a, b, k1, al[4][4], bo[4][4], x;
cin >> k1 >> a >> b;
k = k1;
for (int i = 0; i < (3); i++)
for (int j = 0; j < (3);... | 10 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18 + 10, MAX = 2e5 + 1e4, MOD = 1e9 + 7, MAXL = 25;
void OUT(long double o, int x) {
cout << fixed << setprecision(x) << o;
return;
}
long long a[MAX];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n, mi = INF, ... | 6 |
#include <bits/stdc++.h>
using namespace std;
map<int, int> mp;
vector<int> vec, ans;
int main() {
int n, k, a, b, c, d;
cin >> n >> k;
cin >> a >> b >> c >> d;
if (a != c && a != d && b != c && b != d) {
if (n == 4) {
cout << -1 << endl;
return 0;
}
if (n + 1 > k)
cout << -1 << en... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, k, tw;
int w[200020];
int main() {
cin >> n >> k;
for (int i = 1; i <= n; i++) {
scanf("%d", &w[i]);
}
sort(w + 1, w + n + 1);
int lim, sum = 0;
for (lim = 1; w[lim] <= k && lim <= n; lim++)
;
for (int i = lim; i <= n; i++) {
while (w[i] > 0... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int Max = 1e6 + 5;
const int Mod = 998244353;
long long n, a[Max];
long long fp(long long x, long long p) {
if (!p) return 1;
long long y = fp(x, p >> 1);
y = y * y % Mod;
if (p & 1) y = y * x % Mod;
return y;
}
int main() {
ios::sync_with_stdio(0), cin.ti... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005;
const int MAX = 1000006;
int a[maxn];
int n;
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
sort(a, a + n);
n = unique(a, a + n) - a;
int ans = 0;
for (int i = 0; i < n; i++) {
for (int j = 2 * a[i]; j ... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long int t;
cin >> t;
while (t--) {
long long int a, b, c, d;
cin >> a >> b >> c >> d;
long long int x = a + b;
long long int y = c + d;
cout << max(x, y) << endl;
}
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, c(0);
cin >> n;
pair<int, int> a[2005];
for (int i = 0; cin >> a[i].first; i++) a[i].second = i;
sort(a, a + n);
for (int i = 0; i + 1 < n; i++) {
if (a[i].first == a[i + 1].first) c++;
if (c == 2) {
cout << "YES" << endl;
... | 5 |
#include <bits/stdc++.h>
int a[200010], b[200010];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
int k = 1;
for (int i = 1; i <= n; i++) {
scanf("%d", &b[i]);
if (b[i] == a[k]) k++;
}
printf("%d\n", n - k + 1);
return 0;
}
| 7 |
#include <bits/stdc++.h>
using namespace std;
long long n, tmp, a[100005], ans, x;
deque<long long> dq;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
sort(a + 1, a + n + 1);
for (int i = 1; i <= n; i++) {
if (a[i] != a... | 12 |
#include <bits/stdc++.h>
using namespace std;
int n, d[200010];
int main() {
int sum = 0, cnt = 0;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &d[i]);
sum += d[i];
}
if (sum % n == 0) {
sum /= n;
for (int i = 1; i <= n; i++)
if (d[i] == sum) cnt++;
printf("%d\n", cnt)... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int T;
cin >> T;
while (T--) {
int n, x, y;
cin >> n >> x >> y;
vector<int> a(n, 0), b(n, 0);
vector<vector<int>> idx(n + 2), cnt(n + 1);
for (int i = 0; i < n; ++i) {
cin >> b[i];
... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int T, x, y, k;
int cost = 0;
int n, a, b;
cin >> n >> a >> b;
int c[n];
for (int i = 0; i < n; i++) {
cin >> c[i];
}
int i, j;
for (i = 0, j = n - 1; i < j; i++, j--) {
if (c[i] == c[j]) {
if (c[i] == 2) {
cost += (2 * m... | 2 |
#include <bits/stdc++.h>
using namespace std;
int m, n, v[50][4];
vector<int> comp(int o) {
vector<int> x;
for (int i = 0; i < n; ++i) {
x.push_back(v[i][o] - 1);
x.push_back(v[i][o]);
x.push_back(v[i][o + 2]);
}
sort(x.begin(), x.end());
x.resize(unique(x.begin(), x.end()) - x.begin());
for (in... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.sync_with_stdio(0);
cout.sync_with_stdio(0);
string a, d;
int b;
getline(cin >> ws, a, '.');
getline(cin >> ws, d, 'e');
cin >> b;
if (d == "0") d.pop_back();
reverse(d.begin(), d.end());
while (!d.empty() and b-- > 0) {
a += d.back(... | 6 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
char ch = getchar();
bool f = 0;
int x = 0;
for (; !isdigit(ch); ch = getchar())
if (ch == '-') f = 1;
for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ 48);
if (f == 1) x = -x;
return x;
}
int lowbit(int x) { return x... | 16 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const int maxn = ((1 << 20) + 1000);
int dp[21][((1 << 20) + 1000)], n, ans, len;
int a[((1 << 20) + 1000)];
char str[21 + 10];
int main() {
scanf("%d", &n);
len = 0;
for (int i = 1; i <= n; ++i) {
scanf("%s", str);
if (len == 0) ... | 20 |
#include <bits/stdc++.h>
using namespace std;
void test() {
int n, m;
cin >> n >> m;
int a[m];
for (int i = 0; i < m; i++) cin >> a[i];
sort(a, a + m);
int ans = a[n - 1] - a[0];
for (int i = n; i < m; i++) {
ans = min(ans, a[i] - a[i - n + 1]);
}
cout << ans << "\n";
}
int main() {
int tests = ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
for (int i = ceil(n / 2.0); i <= n; i++) {
if (i % m == 0) {
cout << i;
return 0;
}
}
cout << "-1";
return 0;
}
| 2 |
#include <bits/stdc++.h>
#define endl '\n'
#define LL long long
#define LD long double
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define debug(x) cerr << #x << " is " << x << endl;
using namespace std;
int const MAXN = 2e6 + 9;
set<pair<int,int... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
int n, k, p;
cin >> n >> k >> p;
vector<long long> a(n);
for (auto &i : a) cin >> i;
vector<long long> b(k);
for (auto &j : b) cin >> j;
sort(a.begin(), a.end());
sort(b.begin(), b.end());
long long ans = INT_MA... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
long int n, i, j;
cin >> n;
long long a[n];
for (i = 0; i < n; i++) cin >> a[i];
long int p = 0;
long long temp;
for (i = 0, j = n - 1; i < j; i++, j--) {
if (p % 2 == 0) {
temp = a[i];
a[i] = a[... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long d[300005], c[300005], mx[300005][19], mi[300005][19], p[300005];
long long sta[300005][2], L[300005], R[300005];
long long read() {
char c = getchar();
long long x = 0, f = 1;
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
wh... | 16 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.