solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
const int maxn = 110;
int main() {
int n, d;
int a[maxn], x[maxn], y[maxn];
int dist[maxn][maxn], cost[maxn][maxn];
scanf("%d%d", &n, &d);
a[1] = a[n] = 0;
for (int i = 2; i < n; i++) scanf("%d", &a[i]);
... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, k;
string s, s1;
cin >> s;
cin >> s1;
map<int, int> m;
for (i = 0; i <= 9; i++) m[i] = 0;
for (i = 0; i < s1.size(); i++) m[(int)(s1[i]) - 48]++;
for (i = 0; i < s.size(); i++) {
for (j = 9; j >= 0; j--) {
if (j > ((int)(s[i]... | 3 |
#include <bits/stdc++.h>
using namespace std;
namespace io {
const int L = (1 << 22) + 1;
char ibuf[L], *iS, *iT, obuf[L], *oS = obuf, *oT = obuf + L - 1, c, qu[55];
int f, qr;
inline void flush() {
fwrite(obuf, 1, oS - obuf, stdout);
oS = obuf;
}
inline void pc(char x) {
*oS++ = x;
if (oS == oT) flush();
}
tem... | 22 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
int b[200005];
long long dp[200005][18][2][2];
int main() {
cin >> n >> k;
memset(b, false, sizeof(b));
for (int i = 1; i <= k; ++i) {
int a;
cin >> a;
b[a] = true;
}
memset(dp, -1, sizeof(dp));
for (int i = 1; i <= n; ++i) {
for (int j... | 17 |
#include <bits/stdc++.h>
using namespace std;
long long funtion(long long n) {
if (n < 50) {
return pow(2, n);
} else
return ((funtion(n / 2 + (n % 2)) % 1000000007) *
(funtion(n / 2) % 1000000007)) %
1000000007;
}
int main() {
long long r, c, i, j, k, l;
cin >> r >> c;
long lon... | 6 |
#include <bits/stdc++.h>
using namespace std;
template <typename _T>
inline void read(_T &f) {
f = 0;
_T fu = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') {
fu = -1;
}
c = getchar();
}
while (c >= '0' && c <= '9') {
f = (f << 3) + (f << 1) + (c & 15);
c = getch... | 20 |
#include <bits/stdc++.h>
using namespace std;
const int N = 10010;
int n, m, dsu[N];
int find(int x) { return x == dsu[x] ? x : dsu[x] = find(dsu[x]); }
bool Union(int u, int v) {
u = find(u);
v = find(v);
if (u == v) return false;
dsu[u] = v;
return true;
}
int main() {
ios_base::sync_with_stdio(false);
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d;
cin >> a >> b >> c >> d;
int m = max(3 * (a / 10), a - ((a / 250) * c));
int v = max(3 * (b / 10), b - ((b / 250) * d));
if (m > v)
cout << "Misha";
else if (m == v)
cout << "Tie";
else
cout << "Vasya";
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
int t;
cin >> t;
int n, x;
long long sum;
while (t--) {
cin >> n >> x;
sum = 0;
int arr[n + 5], ans = -1;
for (int i = 1; i <= n; i++) {
cin >> arr[i];
sum ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string a;
cin >> a;
map<int, pair<int, int> > m;
map<pair<int, int>, int> m1;
for (int i = -7; i <= 7; i++) {
for (int j = -7; j <= 7; j++) {
m1[{i, j}] = -1;
}
}
m1[{1, 1}] = 1;
m1[{2, 1}] = 2;
m1[{3, 1}] = ... | 6 |
#include <bits/stdc++.h>
using namespace std;
vector<int> To[100], iTo[100];
bool u[100];
long long dp[1 << 17];
int a[100], order[100];
long long Calc(int mask, int n, int fr) {
int cur = __builtin_popcount(mask);
if (cur == n) return 1;
long long &ans = dp[mask];
if (ans != -1) return ans;
ans = 0;
for (i... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int s, n, i, j;
cin >> s >> n;
int ara[n][2];
for (i = 0; i < n; i++) {
for (j = 0; j < 2; j++) {
cin >> ara[i][j];
}
}
int c = 0;
for (i = 0; i < n; i++) {
int p = 0;
for (j = 0; j < n; j++) {
if (ara[j][0] < s) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string a, b;
cin >> a >> b;
int l = a.size(), ll = b.size();
if (l != ll) {
cout << "NO\n";
return 0;
}
int one = 0, zero = 0;
for (int i = 0; i < l; i++) {
if (a[i] == '1') {
one++;
}
if (b[i] == '1') zero++;
}
if (o... | 7 |
#include <bits/stdc++.h>
using namespace std;
int read() {
char ch = '!';
int res = 0, f = 0;
while (!isdigit(ch)) {
ch = getchar();
if (ch == '-') f = 1;
}
while (isdigit(ch)) res = res * 10 + ch - '0', ch = getchar();
return f ? -res : res;
}
const int N = 2e5 + 100;
int n, Q, K, R, ty[N], tot, mn... | 25 |
#include <bits/stdc++.h>
using namespace std;
int NWD(int a, int b) { return (b == 0) ? (a) : (NWD(b, a % b)); }
char s[100007];
int n;
int k[100007];
vector<int> t[100007];
int m = 1000000007;
char pom[100007];
int w[11];
int l[11];
int main() {
ios_base::sync_with_stdio(0);
cin >> s;
cin >> n;
for (int i = 0;... | 13 |
#include <bits/stdc++.h>
using namespace std;
double m[6], w[6], kol[6], hs, hu, ans;
int i;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
for (i = 1; i <= 5; i++) cin >> m[i];
for (i = 1; i <= 5; i++) cin >> w[i];
cin >> hs >> hu;
kol[1] = 500;
kol[2] = 1000;
kol[3] = 1500;
kol[4] = 2000;
kol[5... | 2 |
#include <bits/stdc++.h>
using namespace std;
const unsigned long long int MOD = 1e11 + 7;
void solve() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
unsigned long long int n;
cin >> n;
vector<string> v;
unsigned long long int a = 1, b = 0;
string ans;
for (unsigned long long int i = 0; i <... | 2 |
#include <bits/stdc++.h>
using namespace std;
double n, h, f, x[511], y[511], ans;
double calc(double x, double y) {
if (x == 0 || y == 0) return 0;
if (x > y) swap(x, y);
if (x < 0 && y > 0) return x * ((f + h) / (f - h) + 1) * h;
if (x < 0 && y < 0) swap(x, y), x = -x, y = -y;
if (x * (f + h) / (f - h) < y)... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 55;
float n, c, l, p, q;
int main() {
scanf("%f%f%f", &n, &p, &q);
printf("%.10f", n * p / (p + q));
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int a[2010];
int main() {
int k;
scanf("%d", &k);
a[0] = -1;
int ans = 1;
for (int i = 2; i <= 2000; i++) {
int tmp = (k + i) / (i - 1);
int t1 = k + i - tmp * (i - 1) + tmp;
if (tmp <= int(1e6) && tmp >= 1 && t1 <= int(1e6)) {
ans = i;
bre... | 12 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
ll sum = 0;
vector<vector<ll>> dp(n);
vector<ll> v(n);
for (ll i = 0; i < n; ++i) {
cin >> v[i];
sum += v[i] * ((i + 1) % 2);
dp[i].push_back(0... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<string> v;
unordered_map<char, int> p;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
v.push_back(s);
}
for (int i = 0; i < v.size(); i++) {
stri... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k, x, y, a, b, i, j, d[2001][2001];
bool occupied[2001][2001];
bool found(int x, int y, int z) {
int l = max(x - z, 1), r = min(x + z, n), i, t;
for (i = l; i <= r; i++) {
t = z - abs(i - x);
if (y - t > 0 && !occupied[i][y - t]) {
a = i;
b... | 16 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << end... | 16 |
#include <bits/stdc++.h>
using namespace std;
int N, D;
int main() {
int i, a, b, res = 0;
scanf("%d%d", &N, &D);
scanf("%d", &a);
for (i = 1; i < N; i++) {
scanf("%d", &b);
if (b <= a) {
int d = (a - b) / D + 1;
b += d * D;
res += d;
}
a = b;
}
printf("%d", res);
return ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int a[n + 1];
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
int sum = 0;
for (int i = 0; i < m; ++i) {
int x, y;
cin >> x >> y;
sum = min(a[x], a[y]) + sum;
}
cout << sum;
}
| 6 |
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
static inline void amin(T &x, U y) {
if (y < x) x = y;
}
template <typename T, typename U>
static inline void amax(T &x, U y) {
if (x < y) x = y;
}
const int N = 1e7;
const long long int mod = 1e9 + 7;
void solve() {
long long int n, ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char t[] = "qwertyuiopasdfghjkl;zxcvbnm,./";
int n = strlen(t);
char c;
string x;
cin >> c >> x;
for (int i = 0; i < x.size(); ++i) {
for (int j = 0; j < n; ++j) {
if (t[j] == x[i]) {
x[i] = (c == 'L') ? t[j + 1] : t[j - 1];
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2010;
int n, m, ans;
string a[MAXN];
bool t[MAXN], ok;
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int p = 0; p < m; p++) {
ok = true;
for (int i = 1; i < n; i++)
if (!t[i] && a[i][p] > a[i + 1][p]) ok = fa... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2000 + 10;
int top, indegree[maxn], n, money[maxn];
struct Edge {
int to;
Edge* next;
} * head[maxn], e[maxn];
void Addedge(int from, int to) {
Edge* p = &e[top++];
p->to = to, p->next = head[from], head[from] = p;
}
void Topsort() {
queue<int> Q;... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, dp[505][505][11], s[505][11], tt, k, cnt[505], dep[505];
char ch[505];
int Dp(int u, int d, int lk) {
if (dp[u][d][lk] != -1) return dp[u][d][lk];
int tmp[11], bb[11], tmpx[11];
memset(bb, 0, sizeof(bb));
for (int i = 0; i < 10; i++)
if (s[u][i]) {
... | 20 |
#include <bits/stdc++.h>
using namespace std;
string brain(char a) {
if (a == '>') return "1000";
if (a == '<') return "1001";
if (a == '+') return "1010";
if (a == '-') return "1011";
if (a == '.') return "1100";
if (a == ',') return "1101";
if (a == '[') return "1110";
return "1111";
}
long long dec(s... | 4 |
#include <bits/stdc++.h>
using namespace std;
int a[100005], b[100005], id[100005];
bool cmp(int &x, int &y) { return a[x] > a[y]; }
int main() {
int n;
vector<int> re;
while (scanf("%d", &n) != EOF) {
re.clear();
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
id[i] = i;
}
for (int... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e6;
const long long mod = 1e9 + 7;
int m, k, n;
char s[maxn + 5];
int pre[26];
long long dp[maxn + 5];
int main() {
cin >> m >> k;
scanf("%s", s + 1);
n = strlen(s + 1);
dp[0] = 1;
for (int i = 1; i <= n; ++i) {
if (pre[s[i] - 'a'] == 0)
... | 14 |
#include <bits/stdc++.h>
int main() {
int t, n, m;
scanf("%d", &t);
while (t--) {
scanf("%d%d", &n, &m);
if (n == 1)
printf("0\n");
else if (n == 2)
printf("%d\n", m);
else
printf("%d\n", 2 * m);
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int T, n, maxb, t, a[100100], f[100100];
int main() {
cin >> T >> n >> maxb >> t;
t = min(t, n);
while (T--) {
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
memset(f, 0, sizeof(f));
int ans = 0;
for (int i = 1; i <= t; i++)
for (int j = 1; j <... | 18 |
#include <bits/stdc++.h>
using namespace std;
long long a, b, c, d, i, n;
long long x[100002];
int main() {
cin >> n;
for (i = 0; i < n; i++) {
cin >> x[i];
}
for (i = 0; i < n; i++) {
a = x[i + 1] - x[i];
b = x[i] - x[i - 1];
c = x[i] - x[0];
d = x[n - 1] - x[i];
if (i == 0) {
cou... | 1 |
#include<bits/stdc++.h>
#define int long long int
#define endl "\n"
#define mod 1000000007
#define inf 1e18
using namespace std;
void solve() {
int n;
cin >> n;
string s;
cin >> s;
vector<int> dpl(n + 1, 0), dpr(n + 1, 0);
for(int i = 0; i < n + 1; i++) {
if(i == 0) {
... | 9 |
#include <bits/stdc++.h>
using namespace std;
vector<int> g[500011];
vector<int> ret;
int visited[500011];
bool flag = true;
void dfs(int v) {
visited[v] = 1;
for (auto nv : g[v]) {
if (visited[nv] == 1) {
flag = false;
} else if (visited[nv] == 0) {
dfs(nv);
}
}
ret.push_back(v);
visi... | 14 |
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &item) {
out << '(' << i... | 25 |
#include <bits/stdc++.h>
using namespace std;
const long double eps = 1e-9;
const int inf = (1 << 30) - 1;
const long long inf64 = ((long long)1 << 62) - 1;
const long double pi = acos(-1);
template <class T>
T sqr(T x) {
return x * x;
}
template <class T>
T abs(T x) {
return x < 0 ? -x : x;
}
string s, t;
int main... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, m, l[152], h[152];
char s[152][152];
int main(int argc, char **argv) {
for (int i = 0; i <= 151; ++i) l[i] = 500, h[i] = -1;
scanf("%d%d", &n, &m);
for (int i = 0; i < n; ++i) {
scanf("%s", s[i]);
for (int j = 0; j < m; ++j)
if (s[i][j] == 'W') l[... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long f(long long x, long long y) {
long long h = 1;
long long g = 1;
for (long long i = x; i > x - y; i--) h *= i;
for (long long i = y; i >= 1; i--) g *= i;
return h / g;
}
signed main() {
long long n, k;
cin >> n >> k;
if (k == 4) {
cout << f(n, 4... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long a[111][111];
int main() {
long long n, m, k, x, y;
cin >> n >> m >> k >> x >> y;
long long sum = m;
if (n > 1) {
sum += m;
}
if (n > 2) {
sum += m * (n - 2) * 2;
}
long long MAX = 0;
long long MIN = 0;
long long me = 0;
if (n == 1) {
... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long n, k, a[55], cum[55];
set<long long> dp[55][55];
set<long long> maxand(long long i, long long k) {
if (k == 1) {
return {cum[n] - cum[i]};
}
if (dp[i][k].empty() == false) {
return dp[i][k];
}
set<long long> ret, t;
for (int x = i + 1; x <= n -... | 11 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
template <class T>
bool ckmin(T& a, const T& b) {
return b < a ? a = b, 1 : 0;
}
template <class T>
bool ckmax(T& a, const T& b) {
return a < b ? a = b, 1 : 0;
}
mt19937 rng(chrono::steady_clock::now().time_since_epo... | 2 |
#include <bits/stdc++.h>
const long long q = 20;
using namespace std;
long long n, ans, a[100], x;
int main() {
cin >> n;
for (int i = 0; i < n; i++) cin >> x, a[x + q]++;
for (int i = -10; i < 0; i++) {
x = a[i + q] * a[i + q + 2 * abs(i)];
ans += x;
}
ans += (a[q] * (a[q] - 1)) / 2;
cout << ans;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
vector<int> h(n);
for (int i = 0; i < n; ++i) scanf("%d", &h[i]);
stack<int> up, down;
vector<vector<int>> g(n);
auto addEdge = [&](int u, int v) {
if (u > v) swap(u, v);
g[u].push_back(v);
};
for (int i = 0; i ... | 14 |
#include <bits/stdc++.h>
using namespace std;
int a[4][4];
int main() {
ios::sync_with_stdio(0);
int n;
cin >> n;
for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++) cin >> a[i][j];
for (int i = 0; i < 4; i++) {
if (min(a[i][0], a[i][1]) + min(a[i][2], a[i][3]) <= n) {
cout << i + 1 << " " <... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
for (int i = 1; i <= n; i++) {
if (k) {
cout << 2 * i << " " << 2 * i - 1 << " ";
k--;
} else {
cout << 2 * i - 1 << " " << 2 * i << " ";
}
}
}
| 6 |
#include <bits/stdc++.h>
using namespace std;
const long long MAX = 1000000000000LL;
long long n;
long long POW(long long x, long long y) {
long long tmp = 1;
if (y == 1) return x;
if (y % 2) tmp = x;
long long ans = POW(x, y / 2);
if (ans >= MAX) return MAX;
return ans * ans * tmp > MAX ? MAX : ans * ans *... | 12 |
#include <bits/stdc++.h>
using namespace std;
const double PI = 3.141592654;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL), cout.tie(NULL);
int x, t;
cin >> x;
vector<int> v(x);
vector<int> ss;
for (int i = 1; i * i <= x; i++) {
if (x % i == 0) t = i;
}
cout << t << " " << x / t << endl... | 0 |
#include <bits/stdc++.h>
using namespace std;
int max_vis;
vector<int> vis;
vector<vector<int> > adj;
void dfs(int u, int g) {
vis[u] = g;
max_vis = max(max_vis, u);
for (int v : adj[u]) {
if (vis[v] != -1) continue;
dfs(v, g);
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m, u... | 9 |
#include <bits/stdc++.h>
using namespace std;
void add(vector<pair<int, int> > &ans, int pos1, int pos2) {
pos1 <<= 2;
pos2 <<= 2;
for (int k = 0; k < 4; k++)
for (int i = 0; i < 4; i++)
ans.push_back(pair<int, int>(pos1 + i, pos2 + (i ^ k)));
}
int dx[] = {0, 0, 1, 0, 1, 2}, dy[] = {1, 2, 3, 3, 2, 3};
... | 23 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, n, val;
vector<int> v;
cin >> t;
for (int i = 0; i < t; i++) {
cin >> n;
for (int j = 0; j < n; j++) {
cin >> val;
v.push_back(val);
}
if (v[0] + v[1] > v[n - 1]) {
cout << -1 << endl;
} else {
cout << ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int ans = 0;
struct node {
node *next[26];
int strings;
bool end;
node() {
for (int i = 0; i < 26; i++) {
next[i] = nullptr;
}
strings = 0;
end = false;
}
};
node *root = new node();
void add(const string &s) {
node *cur_v = root;
for (in... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 300100;
char s[MAXN];
long long n, sol, x;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> s;
n = strlen(s);
for (int i = 0; i < n; i++) s[i] -= '0';
for (int i = 0; i < n; i++) {
if (s[i] % 4 == 0) sol++;
if (i > 0) {
... | 5 |
#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;
}
long long N;
vector<long long> G[222222];
bool centroid[222222];
long long subtree_size[222222];
lon... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
int n, who[N], a[N][N];
bool ban[N][N];
deque<int> pref[N];
void GG() { puts("-1"), exit(0); }
void clip(int k1) {
while (((int)(pref[k1]).size()) && ban[k1][pref[k1].front()])
pref[k1].pop_front();
while (((int)(pref[k1]).size()) && ban[k1][pref... | 27 |
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
int n;
cin >> n;
vector<vector<pair<int, int>>> tree(n);
for (int i = 0; i < n - 1; ++i) {
int x, y;
cin >> x >> y;
--x;
--y;
tree[x].emplace_back(y, tree[y].size());
tree[y].empl... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int M = 605;
int read() {
int x = 0, f = 1;
char c;
while ((c = getchar()) < '0' || c > '9') {
if (c == '-') f = -1;
}
while (c >= '0' && c <= '9') {
x = (x << 3) + (x << 1) + (c ^ 48);
c = getchar();
}
return x * f;
}
int n, b[M], a[M][M], l... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
if (a % 2 == 0 && b % 2 == 0 || a % 2 != 0 && b % 2 != 0) {
int x = abs((b - a) / 2);
int ans = 2 * ((x * (x + 1)) / 2);
cout << ans;
} else {
int x = abs(a - b) / 2;
int ans1 = (x * (x + 1)) / 2;
int ans... | 0 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const int MAXN = 100000 + 7;
const pair<int, int> bad = make_pair(-1, -1);
class RMQ2 {
public:
pair<int, int> t[4 * MAXN];
RMQ2() {
for (int i = (0); i < (MAXN * 4); ++i) t[i] = bad;
}
void push(int v) {
if (t[v] != bad) {
... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int a, b;
cin >> a >> b;
int x = b - a;
if (a == b)
cout << 0 << endl;
else if (x < 0 && (-x) & 1)
cout << 2 << endl;
else if (x < 0 && (-x) % 2 == 0)
cout << 1 << endl;
else if ... | 0 |
#include <bits/stdc++.h>
using namespace std;
char S[100005], a[100005];
int N, f[100005], g[100005], h[100005], r[100005];
int main() {
scanf("%s", S + 1), N = strlen(S + 1), S[0] = 1;
for (int i = 1; i <= N; i++) a[i] = S[N - i + 1];
for (int i = 1, p = 0, q = 0; i <= N; i++) {
r[i] = q > i ? min(r[2 * p - ... | 20 |
#include <bits/stdc++.h>
using namespace std;
vector<int> g[10];
bool vis[10];
int val[10];
int n, m, sum, ans, x, y;
set<pair<int, int>> s;
vector<pair<int, int>> edge;
void dfs(int v) {
vis[v] = true;
for (auto u : g[v]) {
if (vis[u] == false) {
int val1 = min(val[u], val[v]);
int val2 = max(val[u... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int n;
cin >> n;
long long int a[n];
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
long long int ans = 0;
long long int l = 0, r = 2;
if (n == 1) {
cout << "... | 3 |
#include <bits/stdc++.h>
using namespace std;
const double EPS = 0.0000001;
const double PI = acos(-1);
const long long INFLL = 0x7FFFFFFFFFFFFFFF;
const int INF = 0x7FFFFFFF;
template <typename T>
inline void next(T &num) {
char c;
num = 0;
do {
c = getchar_unlocked();
} while (c != EOF && c == ' ' && c ==... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
string str;
string req;
cin >> str;
cin >> req;
int lstr = str.length();
int lreq = req.length();
for (int i = 0; i < lreq; ++i) {
str = "X" + str;
}
for (int i = 0; i < lreq; ++i) {
str += "X";
}
in... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int N = 500005;
int n, a[N];
char c[N];
int main() {
ios::sync_with_stdio(false);
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> c[i] >> a[i];
}
int x, y, z;
z = 1023, x = y = 0;
for (int i = 0; i < 10; ++i) {
int pos = -1;
bool t = 0;
fo... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2000 + 10, maxm = 2000 + 10;
struct P {
int x, y, n;
P(int _x, int _y, int _n) : x(_x), y(_y), n(_n) {}
bool operator<(const P &A) const { return n > A.n; }
};
int G[maxn][maxn], n, m, t;
char Ans[maxn][maxn], pos[maxn][maxn];
int dx[] = {1, -1, 0, 0}... | 12 |
#include <bits/stdc++.h>
using namespace std;
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "RDLU";
long long ln, lk, lm;
void etp(bool f = 0) {
puts(f ? "YES" : "Hungry");
exit(0);
}
void addmod(int &x, int y, int mod = 1000000007) {
assert(y >= 0);
x += y;
if ... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; ++i) cin >> a[i];
sort(a.rbegin(), a.rend());
bool ok = false;
if (a.back() == 0) {
int sum = accumulate(a.begin(), a.end(), 0);
int mod = sum % 3;
if (mod == 0) {
if (sum... | 8 |
#include <bits/stdc++.h>
using namespace std;
vector<long long> adj[200000];
vector<long long> res;
vector<pair<long long, long long> > inp;
long long deg[200000];
bool visited[200000];
set<long long> s;
set<long long>::iterator it;
map<long long, long long> mp, inv_mp;
void dfs(long long node) {
if (visited[node]) r... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
map<int, int> mp;
int main() {
cin >> n >> m;
while (m--) {
mp.clear();
int k;
cin >> k;
bool can = true;
for (int i = 1; i <= k; ++i) {
int x;
cin >> x;
if (mp[-x]) {
can = false;
}
++mp[x];
}
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e6 + 7, INF = 1e9;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
long long tt;
cin >> tt;
while (tt--) {
long long n;
cin >> n;
if (n < 4)
cout << "-1\n";
else {
for (lon... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x20202020;
const long long linf = (((long long)1) << 60) - 1;
const long long mod = 1000000007;
const double eps = 1e-9;
const double pi = 3.1415926535897932384626;
const int DX[] = {1, 0, -1, 0}, DY[] = {0, 1, 0, -1};
long long powmod(long long a, long lon... | 13 |
#include <bits/stdc++.h>
using namespace std;
constexpr int MAX_N = 200000;
int N, M, S, D;
int X[MAX_N + 10];
int DP[MAX_N + 1] = {0};
stack<string> OPS;
void run(int x) {
if (x == 0) return;
std::ostringstream os;
os << "RUN " << x;
OPS.push(os.str());
}
void jump(int x) {
assert(x > 0);
std::ostringstrea... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int Inf = 0x7fffffff;
const int maxn = 1e5 + 5;
const double eps = 1e-10;
int n;
int main() {
while (cin >> n) {
int a, b, c, d;
cout << "YES" << endl;
for (int i = 0; i < n; i++) {
cin >> a >> b >> c >> d;
cout << 2 * (a & 1) + (b & 1) + 1 <... | 13 |
#include <bits/stdc++.h>
using namespace std;
long long power(long long x, long long y) {
long long r = 1, z = x;
while (y) {
if (y & 1) r *= z;
z *= z;
y = y >> 1;
}
return r;
}
long long powerm(long long x, long long y, long long p) {
long long r = 1;
while (y) {
if (y & 1) r = (r * x) % p... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 110;
int n, m, cnt[N][26], num[26];
char s[N], ans[N];
map<string, int> mp;
string ss, dat[N];
int main() {
scanf("%d", &n);
m = (n + 1) / 2;
if (m > 1) {
printf("? %d %d\n", 1, m - 1);
cout.flush();
for (int i = 1; i <= m * (m - 1) / 2; i++)... | 20 |
#include <bits/stdc++.h>
using namespace std;
bool comp(long long int x, long long int y) { return x > y; }
bool is_square(long long int n) {
if (pow((long long int)sqrt(n), 2) == n) return true;
return false;
}
long long int logd(long long int x, long long int y) {
return ceil((long double)log(x) / (long double)... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int ar[2 * n];
if (n % 2 == 0)
cout << "NO" << endl;
else {
cout << "YES" << endl;
int i = 0;
int od = 1;
while (i < n) {
ar[i] = od;
i += 2;
od += 4;
}
od -= 2 + 4;
while (i < 2 * n) ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-10, INFTY = 1e10;
long long DD_from1to[105];
long long DD_toNfrom[105];
long long NN_from1to[105];
long long NN_toNfrom[105];
queue<int> Q;
int N;
int M;
bool visited[105];
vector<int> adiac[105];
void bfs(int from, long long *array_NN, long long *arra... | 11 |
#include <bits/stdc++.h>
using namespace std;
inline void inp(int &n) {
n = 0;
int ch = getchar();
int sign = 1;
while (ch < '0' || ch > '9') {
if (ch == '-') sign = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
n = (n << 3) + (n << 1) + ch - '0', ch = getchar();
n = n * sign;
}
long lo... | 9 |
#include <bits/stdc++.h>
using namespace ::std;
template <class T1, class T2>
istream& operator>>(istream& I, pair<T1, T2>& p) {
return I >> p.first >> p.second;
}
template <class T1, class T2>
ostream& operator<<(ostream& O, const pair<T1, T2>& p) {
return O << '(' << p.first << ' ' << p.second << ')';
}
template ... | 9 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast", "unroll-loops")
const int MAXN = 1e5 * 2;
int mp[(int)1e6 + 42];
int main() {
ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
int n;
cin >> n;
int t = 0;
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dc[] = {0, 1, 0, -1, 1, -1, -1, 1};
const double eps = 1e-9;
const int INF = 0x7FFFFFFF;
const long long INFLL = 0x7FFFFFFFFFFFFFFFLL;
const double pi = acos(-1);
template <class T>
T take(queue<T> &O) {
T tmp = O.fr... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 7, M = 2 * N;
int edge[M], succ[M], ver[N], idx, ID[M];
int d[N], all, have, fa[N], vis[N];
vector<int> ans;
void add(int u, int v, int id) {
edge[idx] = v;
succ[idx] = ver[u];
ID[idx] = id;
ver[u] = idx++;
}
void dfs1(int u) {
vis[u] = 1;
if... | 13 |
#include <bits/stdc++.h>
using namespace std;
using ll = int_fast64_t;
constexpr int mod = 1e9 + 7;
constexpr int inf = (1 << 30) - 1;
constexpr ll infll = (1LL << 61) - 1;
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
template <typename A, typename B>
string to_string(pair<... | 3 |
#include <bits/stdc++.h>
using namespace std;
bool maze[305][305] = {0};
char mov[105];
int main() {
scanf("%s", &mov);
bool bug = 0;
int r = 150, c = 150, len = strlen(mov);
maze[r][c] = 1;
for (int i = 0; i < len; ++i) {
int nr = r, nc = c;
switch (mov[i]) {
case 'U':
nr--;
bre... | 6 |
#include <bits/stdc++.h>
using namespace std;
bool prime[1000005];
void sieve(int n) {
for (int i = 0; i < n; i++) prime[i] = true;
prime[0] = false, prime[1] = false;
for (int i = 2; i * i <= n; i++) {
if (prime[i] == true) {
for (int j = i * i; j <= n; j += i) prime[j] = false;
}
}
}
int main() ... | 0 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve(){
map<int,int>ma; //key可能为负,所以不数组
int n; cin>>n;
ll ans = 0;
for(int i=0; i<n; i++){
int x; cin>>x; x-=i;
ans+=ma[x]; ma[x]++; //即使第一次,ma[x]为0
}
cout<<ans<<endl;
}
int main(){
ios::sync_with_stdio(false); cin.tie(0); cout.tie... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a[1003], min, x, y;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
min = abs(a[0] - a[n - 1]);
x = 1;
y = n;
for (int i = 0; i < n - 1; i++) {
if (abs(a[i] - a[i + 1]) < min) {
min = abs(a[i] - a[i + 1]);
x = i... | 0 |
#include <bits/stdc++.h>
using namespace std;
int arr[2000];
int main() {
int test, m, c = 0, sum1 = 0, i, j, a;
cin >> test >> m;
for (int i = 1; i <= test; i++) {
cin >> a;
arr[a]++;
}
long long sum = 0;
for (i = 1; i <= m; i++)
for (j = i + 1; j <= m; j++) sum += 1LL * arr[i] * arr[j];
cout... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 5;
int n, Q;
int pre[N], nxt[N], lst[N], cnt[N], pi[N], a[N];
struct node {
int l, r, id;
} q[N];
int tr[N], ans[N];
void add(int x, int k) {
while (x <= n + 1) {
tr[x] += k;
x += x & -x;
}
}
int find(int x) {
int ans = 0;
while (x) {
... | 10 |
#include <bits/stdc++.h>
using namespace std;
char pan[10][10];
int main() {
std::ios::sync_with_stdio(false);
long long n, m;
cin >> n >> m;
vector<long long> v(n + 1), pre(n + 1, 0);
for (long long i = 1; i <= n; i++) {
cin >> v[i];
pre[i] = pre[i - 1] + v[i];
}
long long ans = 0;
long long va... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int board[31][31] = {0};
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++) cin >> board[i][j];
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++) board[i][0] += board[i][j];
for (int j = 1; j <= n; j++)
fo... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 3e5 + 5;
void solve() {
int n;
cin >> n;
vector<pair<long long int, long long int> > v(2 * n + 5);
vector<long long int> cost(2 * n + 5, 0);
for (int i = 0; i < n; i++) {
cin >> v[i].first >> v[i].second;
v[n + i] = v[i];
}
long long i... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 1e5 + 10;
const int inf = 2e9;
const double eps = 1e-7;
const long long INF = (long long)1e18;
int n;
int m;
int a[N];
vector<int> ans;
int main() {
scanf("%d%d", &(n), &(m));
for (int i = 0; i < (n); ++i) scanf("%d", &(a[i]));
s... | 4 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.