solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
char s[200005], ans[30];
int main() {
int n, m, i, j, A, B;
char a, b;
scanf("%d %d", &n, &m);
getchar();
for (i = 1; i <= n; i++) scanf("%c", &s[i]);
for (i = 1; i <= 26; i++) ans[i] = i + 'a' - 1;
getchar();
for (i = 1; i <= m; i++) {
scanf("%c %c", &a... | 4 |
#include <bits/stdc++.h>
using namespace std;
int ans = -1;
int main() {
int t;
cin >> t;
while (t--) {
long long int n, k;
cin >> n >> k;
long long int a[n];
for (int i = 0; i < n; i++) cin >> a[i];
long long int mn = INT_MAX;
long long int pt = -1;
for (int i = 0; i < n; i++) {
... | 8 |
#include <bits/stdc++.h>
using namespace std;
void solveCP311() {
long long a, b, c, d;
cin >> a >> b >> c >> d;
long long x = max((3 * a) / 10, a - ((a * c) / 250));
long long y = max((3 * b) / 10, b - ((b * d) / 250));
if (x > y) {
cout << "Misha";
} else if (y > x) {
cout << "Vasya";
} else {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 100;
int n, m, a[N], fa[N], cnt, head[N], f[N][22], in[N], out[N], clk, dep[N], ans;
pair<int, int> t[N << 2], res;
struct edge {
int to, nxt;
} e[N];
void adde(int x, int y) {
e[++cnt].to = y;
e[cnt].nxt = head[x];
head[x] = cnt;
}
void dfs(int ... | 21 |
#include <bits/stdc++.h>
using namespace std;
void v(int &a, int &b, int &c) {
int d;
if (c < a) {
swap(a, c);
}
if (c < b) {
swap(b, c);
}
if (a > b) {
swap(a, b);
}
}
string s;
int main() {
int x, y, a[3], ans = 0;
cin >> x >> y;
a[0] = a[1] = a[2] = y;
while (a[0] != x || a[1] != x ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
string s;
cin >> n;
vector<int> sz(n);
for (int i = 0; i < n; i++) {
cin >> sz[i];
}
cin.get();
for (int i = 0; i < n; i++) {
getline(cin, s);
int cn = 0;
for (int j = 0; j < s... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
map<long long, long long> mp;
deque<long long> a;
long long n, k, d, m = 0;
cin >> n >> k;
for (auto i = 0; i < n; i++) {
cin >> d;
if (!mp[d]) {
mp[d] = 1;
... | 2 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:128000000")
using namespace std;
const long double PI = 3.14159265358979323846;
const long double gammama = 0.57721566490153286060;
const long double eps = 1e-5;
const int INF = 1000 * 1000;
int main() {
int tux;
cin >> tux;
int foo = 0, bar = 0, baz = 0, q... | 9 |
#include <bits/stdc++.h>
using namespace std;
string s[105];
bool cmp(string a, string b) {
if (a.size() == b.size()) {
return a < b;
} else
return a.size() < b.size();
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> s[i];
}... | 3 |
#include <bits/stdc++.h>
int a[100005], d[100005];
inline bool cmp(int a, int b) { return a > b; }
int main() {
int n, m, k;
scanf("%d %d %d", &n, &m, &k);
for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
long long s = a[n] - a[1] + 1;
for (int i = 1; i < n; ++i) d[i] = a[i + 1] - a[i] - 1;
std::sort(d + 1,... | 6 |
#include <iostream>
using namespace std;
int main(){
int t;
cin>>t;
for(int i=0;i<t;i++){
int n;
cin>>n;
int a[n];
for(int j=0;j<n;j++){
cin>>a[j];
}
if(a[0]!=a[1]){
if(a[2]==a[1]){
cout<<1<<endl;
conti... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 2e5 + 100;
const long long INF = 1e18;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
struct st {
long long len, pos;
bool operator<(const st &a) const { return len < a.len; }
} pl[MAXN];
long long blen[MAXN];
void ... | 9 |
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int main() {
long long t;
cin >> t;
while (t--) {
long long n, m;
cin >> n >> m;
string arr[n];
long long i, j, k = 0;
for (i = 0; i < n; i++) cin >> arr[i];
vector<long ... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 303000;
int n, m, dfn[maxn], dfs_clock;
vector<int> G[maxn], pa;
vector<pair<int, int> > cyc;
void dfs(int u, int fa) {
dfn[u] = ++dfs_clock;
pa.push_back(u);
for (auto v : G[u])
if (v != fa) {
if (dfn[v]) {
if (dfn[v] < dfn[u]) {
... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, arr[5] = {0}, res = 0;
cin >> n;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
arr[x]++;
}
res += arr[4];
res += min(arr[3], arr[1]);
int temp = min(arr[3], arr[1]);
arr[1] -= temp;
arr[3] -= temp;
res += arr[3];
res +=... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
pair<int, int> a[100001];
for (int i = 0; i <= n; i++) {
cin >> a[i].first >> a[i].second;
}
int count = 0;
if (a[1].second > a[0].second) {
for (int i = 1; i < n; i++) {
if (a[i].first > a[i - 1].first && a[i].secon... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, min = 100500, min1 = 100500, x;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> x;
if (x < min) {
min1 = min;
min = x;
} else if (x != min && x < min1) {
min1 = x;
}
}
if (min1 == 100500)
cout << "NO" << end... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 2010;
const long long inf = 1e12;
long long n, k, a[N], f[N];
long long abs_(long long x) { return x > 0 ? x : -x; }
long long min_(long long x, long long y) { return x < y ? x : y; }
bool check(long long x) {
for (long long i = 1; i <= n; i++) f[i] = ... | 12 |
#include <bits/stdc++.h>
using namespace std;
void call() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
void solve() {
long long n;
cin >> n;
long long x = 2 * n;
long long a[x];
for (long long i = 0; i < x; i++) cin >> a[i];
sort(a, a + 2 * n);
cout << abs(a[n] - a[n - 1]) << "\n";
}
i... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100500;
bool win[N], lose[N];
int trie[N][27];
int szT = 1, root;
void insert(string s) {
int v = 0;
for (int i = 0; i < s.size(); i++) {
if (trie[v][s[i] - 'a'] == 0) trie[v][s[i] - 'a'] = szT++;
v = trie[v][s[i] - 'a'];
}
}
void dfs(int u) {
... | 11 |
#include <bits/stdc++.h>
using namespace std;
struct debugger {
template <typename T>
debugger& operator,(const T& v) {
cout << v << " ";
return *this;
}
} dbg;
int dx[] = {-1, 1, 0, 0, -1, -1, 1, 1};
int dy[] = {0, 0, 1, -1, -1, 1, -1, 1};
int a[1000010];
int main() {
int t = 0, z = 0, len;
int n = 0... | 4 |
#include <bits/stdc++.h>
using namespace std;
struct Edge {
int to;
int id;
int next;
} edge[666666];
int head[666666];
int top;
void init() {
memset(head, -1, sizeof(head));
top = 0;
}
void add_edge(int a, int b, int id) {
edge[top].id = id;
edge[top].to = b;
edge[top].next = head[a];
head[a] = top++... | 13 |
#include <bits/stdc++.h>
using namespace std;
long long a[1111111], k, i, x, s, n;
int main() {
cin >> n >> k >> x;
for (i = 1; i <= n; i++) {
cin >> a[i];
if (i <= n - k) s += a[i];
}
s = s + k * x;
cout << s;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const long long inf = 0x3f3f3f3fll;
const long long mod = 998244353ll;
int n, m;
int a[N];
int main() {
ios::sync_with_stdio(0);
int i, j;
cin >> n;
for (i = 1; i <= n; i++) cin >> a[i];
sort(a + 1, a + n + 1);
int ans = 0;
a[0] = -1;
i... | 10 |
#include <bits/stdc++.h>
using namespace std;
int a[100005], b[100005];
int u[100005], v[100005];
int main() {
int n, m, x, y;
while (scanf("%d %d %d %d", &n, &m, &x, &y) == 4) {
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
for (int i = 0; i < m; i++) scanf("%d", &b[i]);
int p = 0, cnt = 0;
for (... | 5 |
#include <bits/stdc++.h>
using namespace std;
string a;
int main() {
cin >> a;
int sum = 0;
for (int i = 0; i <= a.length(); i++) {
char t = a[i];
if (t >= 'A' && t <= 'Z') {
sum += t - '@';
}
if (t >= 'a' && t <= 'z') {
sum -= t - '`';
}
}
cout << sum << endl;
return 0;
}
| 12 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60LL;
int n;
int m;
long long arr[1500][1500];
long long dp[1500][1500];
int main() {
scanf("%d%d", &n, &m);
for (int i = 0; i < n; ++i)
for (int j = 0; j < m; ++j) scanf("%I64d", &arr[i][j]);
for (int i = 0; i < m; ++i) {
dp[0][i]... | 11 |
#include <bits/stdc++.h>
using namespace std;
struct point {
long long int x, y;
point() {}
point(long long int inx, long long int iny) {
x = inx;
y = iny;
}
};
point leer() {
int x, y;
cin >> x >> y;
return point(x, y);
}
point operator-(point p1, point p2) {
p1.x -= p2.x;
p1.y -= p2.y;
ret... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, k;
scanf("%I64d %I64d", &n, &k);
long long a = (n / 2) / (k + 1);
long long b = k * a;
long long c = n - (a + b);
printf("%I64d %I64d %I64d\n", a, b, c);
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
void dbg_out() { cerr << "\b\b]\n"; }
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) {
cerr << H << ", ";
dbg_out(T...);
}
const int N = 1002;
vector<vector<int>> ans(N, vector<int>(N, -1));
int main() {
ios_base::sync_with_stdio(false);
... | 11 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int MOD = 1e9 + 7;
const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0};
const char dir[] = {'R', 'L', 'D', 'U'};
int add(int a, int b) {
a += b;
if (a >= MOD) {
a -= MOD;
}
return a;
}
int sub(in... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long base = 200010;
long long mod = ((long long)1 << (long long)55) - 55;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
vector<int> c[n];
for (int i = 0; i < n; i++) {
int cx;
cin >> cx;
c[i].resize(cx);
for ... | 12 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
long long n;
cin >> n;
vector<long long> v(n);
for (long long i = 0; i < n; i++) {
cin >> v[i];
}
vector<long long> b(100);
vector<vector<long long>> g(100);
for (long long i = 0; i < n; i++) {
long long c = 0;
long long d = v[i];... | 11 |
#include <bits/stdc++.h>
using namespace std;
inline long long input() {
long long n;
cin >> n;
return n;
}
long long pw(long long a, long long b) {
return (!b ? 1 : (b & 1 ? a * pw(a * a, b / 2) : pw(a * a, b / 2)));
}
const int maxn = 1e2 + 10, mod = 1e9 + 7;
bool check[maxn];
int n, m;
vector<int> adj[maxn];... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, b;
scanf("%d%d%d", &n, &a, &b);
int ans = min(n - a, b + 1);
printf("%d\n", ans);
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int MAX = 1e6;
int sum[200];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
string s;
cin >> s;
for (int i = 0; i <= 900; i++) {
int sum = 0, cnt = 0;
for (int j = 0; j < n; j++) {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
double EPS = 1e-9;
struct CIRCLE {
int x;
int y;
int r;
};
int x1, y1_, r1, R1;
int x2, y2_, r2, R2;
float dist(CIRCLE from, CIRCLE to) {
return sqrt(pow(from.x - to.x, 2) + pow(from.y - to.y, 2));
}
bool inter(CIRCLE A, CIRCLE B) {
if (dist(A, B) >= A.r + B.r) re... | 11 |
#include <bits/stdc++.h>
using namespace std;
long double dist(pair<long double, long double> a,
pair<long double, long double> b) {
return sqrt((a.first - b.first) * (a.first - b.first) +
(a.second - b.second) * (a.second - b.second));
}
int calc_min(const vector<pair<long double, long... | 10 |
#include <bits/stdc++.h>
int main() {
char a[400];
int i, j, length, out, in;
while (gets(a) != NULL) {
length = strlen(a);
out = in = 0;
for (i = 0; i < length; i++) {
if (a[i] == '+') {
in++;
if (out != 0) out--;
} else if (a[i] == '-') {
out++;
if (in != ... | 6 |
#include <bits/stdc++.h>
typedef struct node {
int x, y;
} p;
p a[200005];
int cmp1(const void* a, const void* b) {
p* c = (p*)a;
p* d = (p*)b;
return c->x - d->x;
}
int cmp2(const void* a, const void* b) {
p* c = (p*)a;
p* d = (p*)b;
if (c->y != d->y)
return c->y - d->y;
else
return d->x - c->x... | 6 |
#include <bits/stdc++.h>
using namespace std;
vector<int> a;
int n;
bool d(int v) {
int an = v;
while (v != 0) {
an += v % 10;
v /= 10;
}
if (an == n) return true;
return false;
}
int main() {
ios::sync_with_stdio(0);
cin >> n;
for (int i = max(n - 100, 0); i <= n; i++) {
if (d(i)) a.push_ba... | 4 |
#include <bits/stdc++.h>
using namespace std;
struct matrix {
int n, m;
double mat[128][128];
void init(int _n, int _m) {
n = _n;
m = _m;
for (int i = 0; i <= n; i++)
for (int j = 0; j <= m; j++) mat[i][j] = 0;
}
};
int n, x;
double p[200];
matrix F, m;
matrix nhan(matrix &a, matrix &b) {
ma... | 11 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > g(123456 + 5);
vector<bool> eny(123456 + 5);
vector<int> koleny(123456 + 5), deep(123456 + 5);
void dfs(int v, int p = -1) {
koleny[v] = 0;
if (eny[v]) koleny[v] = 1;
for (int i = 0; i < g[v].size(); i++) {
int to = g[v][i];
if (to == p) c... | 14 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
4;
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
string s;
cin >> s;
int i = 0, flag = -1;
int ans = 1;
int a[n];
queue<int> q0, q1;
while (i < n)... | 7 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define go_corona ios_base::sync_with_stdio(false)
#define corona_go cin.tie(NULL)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define rall(x)... | 6 |
#include <bits/stdc++.h>
using namespace std;
struct LCA {
int logn;
vector<int> depth;
vector<vector<int> > lca;
vector<vector<int> > *edges;
LCA(int n, vector<vector<int> > *edges) {
logn = log(n) / log(2) + 1;
depth.resize(n + 1, 0);
lca.resize(n + 1, vector<int>(logn, 0));
this->edges = ed... | 24 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
long long a[N], b[N], c[N], d[N];
int main() {
int n, m, k;
long long x, s;
scanf("%d%d%d", &n, &m, &k);
scanf("%I64d%I64d", &x, &s);
for (int i = 0; i < m; ++i) scanf("%I64d", a + i);
for (int i = 0; i < m; ++i) scanf("%I64d", b + i);
fo... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long Power(long long a, long long b) {
long long result = 1;
while (b) {
if (b % 2) {
result = (result * a) % 1000000007;
}
b = b >> 1;
a = (a * a) % 1000000007;
}
return result;
}
int main() {
std::ios_base::sync_with_stdio(false);
lo... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a1, a2, a3, a5, a6, a4, i, n, m, j;
while (scanf("%d%d%d%d%d%d", &a1, &a2, &a3, &a4, &a5, &a6) != EOF) {
printf("%d\n", (a1 * 2 + a2 + a6) * (a2 + a3) -
(a2 * a2 + a3 * a3 + a5 * a5 + a6 * a6) / 2);
}
return 0;
}
| 8 |
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void smin(T &a, const U &b) {
if (a > b) a = b;
}
template <typename T, typename U>
inline void smax(T &a, const U &b) {
if (a < b) a = b;
}
template <class T>
inline void gn(T &first) {
char c, sg = 0;
while (c = getchar(), ... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5;
const int INF = 0x3f3f3f3f;
int T, ret, now, p[maxn], q[maxn], f[maxn];
pair<int, int> a[maxn], b[maxn], ans[maxn];
map<int, bool> Mapx, Mapy;
inline void Fuck() {
int Minx = INF, Miny = INF, Maxx = -INF, Maxy = -INF;
for (int i = (1), _end_ = (4); i... | 22 |
#include <bits/stdc++.h>
using namespace std;
unsigned long long gcd(unsigned long long m, unsigned long long n) {
unsigned long long tmp;
while (n) {
tmp = n;
n = m % n;
m = tmp;
}
return m;
}
int main(void) {
int i, j, n, m, h;
unsigned long long g, nn, dn, num = 0LLU, den = 0LLU;
double ans... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int64_t MOD = 1e9 + 7;
string a;
int64_t k, temp = 1, ans = 0;
int64_t Pow(int64_t x, int64_t y) {
int64_t curr = 1;
while (y > 0) {
if (y % 2 != 0) curr = (curr * x) % MOD;
x = (x * x) % MOD;
y /= 2;
}
return curr;
}
int64_t sum() {
int64_t inv ... | 9 |
#include <bits/stdc++.h>
using namespace std;
const long double PI = 3.1415926535897932384626433832795L;
const long double eps = 1e-9;
const long long A = 911382323;
const long long B = 972663749;
const long long A2 = 972663749;
const long long B2 = 972663753;
const long long mod = 1e9 + 7;
const long long inf = 1e15;
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k = 0;
cin >> n;
vector<int> v(n), v1(n);
for (int i = 0; i < n; i++) cin >> v[i];
for (int i = 1; i < n - 1; i++) {
if (v[i] == 0 && v[i - 1] == 1 && v[i + 1] == 1) {
v1[k] = i + 1;
k++;
i = i + 1;
}
}
int count =... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 5;
const double eps = 0;
const int ms = 0;
const int md = 0;
const int mod = 1e9 + 9;
const int pi = 31, pii = 41;
const int base = 1e9;
const int N = 5e5 + 10;
const int NN = 1e5 + 5;
const int M = 1e5 + 5;
const int blocks = 600;
void readfile() {
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
vector<int> G[maxn];
int d[maxn], mx = -1, ans, d1[maxn], d2[maxn];
int n;
int v1, v2, v3;
void dfs(int u, int fa) {
if (d[u] > mx) {
mx = d[u];
ans = u;
}
for (auto v : G[u])
if (v != fa) {
d[v] = d[u] + 1;
dfs(v, u);... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int M = 1000000007;
const int MM = 998244353;
const long double PI = acos(-1);
long long power(long long b, long long e, long long m) {
if (e == 0) return 1;
if (e & 1) return b * power(b * b % m, e / 2, m) % m;
return power(b * b % m, e / 2, m);
}
long long pow... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long qpow(long long a, long long b, long long p) {
long long ret = 1;
for (a %= p; b; b >>= 1, a = a * a % p)
if (b & 1) ret = ret * a % p;
return ret;
}
long long qpow(long long a, long long b) {
long long ret = 1;
for (; b; b >>= 1, a *= a)
if (b & ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int N, M, x[100];
double dp[100001][100];
int main() {
scanf("%d%d", &N, &M);
int ts = 0;
for (int n = 0; n < int(N); n++) {
scanf("%d", x + n);
ts += x[n];
}
if (M == 1) {
puts("1");
return 0;
}
for (int i = 0; i < int(N); i++)
for (int ms... | 15 |
#include <bits/stdc++.h>
using namespace std;
int n, m, a, b, c, k;
string s;
int main() {
cin >> a >> b;
string mask;
k = b;
while (k > 0) {
if (k % 10 == 4 || k % 10 == 7) {
mask += (char)('0' + k % 10);
}
k /= 10;
}
while (mask != s) {
a++;
s = "";
k = a;
while (k > 0) {... | 5 |
#include <bits/stdc++.h>
using namespace std;
using vi = vector<long long>;
using ii = pair<long long, long long>;
using vii = vector<ii>;
using ld = long double;
template <typename Arg1>
void ZZ(const char* name, Arg1&& arg1) {
std::cerr << name << " = " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
... | 9 |
#include <bits/stdc++.h>
using namespace std;
int di[] = {1, 0, -1, 0};
int dj[] = {0, 1, 0, -1};
int n;
int a[100009];
int Next[100009];
int dp[100009];
int main(int argc, char *argv[]) {
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%d", a + i);
Next[i] = i;
}
set<pair<int, int> > st;
for (i... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9;
const int mod = inf + 7;
const double eps = 1e-9;
const double pi = acos(-1.0);
long long n, k, two[600], d[600][600];
long long dp[600][600];
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> n >> k;
dp[0][0] = two[0] = 1;
for ... | 17 |
#include <bits/stdc++.h>
using namespace std;
void inc(long long start, long long end, long long num) {
for (long long i = start; i <= end; i++) {
cout << i + 1 << " " << i + 2 << " ";
cout << num << " " << num + 1;
cout << "\n";
num++;
}
}
void dec(long long index, long long end, long long num) {
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const unsigned gen_seed =
std::chrono::system_clock::now().time_since_epoch().count();
std::mt19937_64 gen(gen_seed);
std::vector<int> x, y, z;
int dist(int i, int j) {
return abs(x[i] - x[j]) + abs(y[i] - y[j]) + abs(z[i] - z[j]);
}
... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
int B;
vector<int> counts;
vector<int> dp;
void mod_add(int& first, int second) {
first += second;
if (first >= mod) {
first -= mod;
}
}
struct Bucket {
int id;
int offset = 0;
vector<int> pref_sum;
Bucket(int _id) {
id = _id... | 21 |
#include <bits/stdc++.h>
using namespace std;
void solve(int n);
void floyd(int n);
const int INF = 0x3f3f3f3f;
const int MAX = 505;
int graph[MAX][MAX];
int dist[MAX][MAX];
int cnt[MAX][MAX], res[MAX][MAX];
int main() {
int n, m;
while (scanf("%d %d", &n, &m) != EOF) {
memset(graph, INF, sizeof(graph));
me... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t, n;
cin >> t;
while (t--) {
cin >> n;
vector<long long int> A;
vector<long long int> B;
int x;
long long int aSmallest;
cin >> aSmallest;
A.push_back(aSmallest);
for (int i = 1; i <= n - 1; i++) {
cin ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int dp[33][33][55];
void solve(int n, int m, int k) {
if (k == 0 || n * m == k)
dp[n][m][k] = 0;
else {
int ans1 = 0x3f3f3f3f, ans2 = 0x3f3f3f3f;
for (int i = 1; i < n; i++) {
for (int p = 0; p <= k; p++) {
ans1 = min(ans1, m * m + dp[i][m][p] ... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char str[10000];
cin >> str;
if (str[0] >= 97) str[0] -= 32;
cout << str;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
vector<int> vec, que[1 << 17];
int n, m, a[1 << 17], b[1 << 17], c[1 << 17], ans = 1, x;
int chk(int x) {
for (auto o : vec) x = min(x, x ^ o);
return x;
}
int main() {
cin >> n >> m;
for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
for (int i = 1; i <= m; ++i) sc... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
int ans = 0;
int pre = 0;
int x;
for (int i = 0; i < n; i++) {
scanf("%d", &x);
if (x == 1) {
if (pre == 0) ans++;
ans++;
}
pre = x;
}
if (ans > 0) ans--;
printf("%d\n", ans);
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T& x) {
char c = getchar();
bool f = false;
for (x = 0; !isdigit(c); c = getchar()) {
if (c == '-') {
f = true;
}
}
for (; isdigit(c); c = getchar()) {
x = x * 10 + c - '0';
}
if (f) {
x = -x;
}
}
... | 21 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, x = 0, i = 0;
char opt[3];
cin >> n;
if (n < 1 || n > 150) return 0;
while (i < n) {
cin >> opt;
if (strcmp(opt, "++X") == 0 || strcmp(opt, "X++") == 0)
x++;
else if (strcmp(opt, "X--") == 0 || strcmp(opt, "--X") == 0)
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
const int N = 1e5 + 10;
const long long INF = 1e15 + 7;
void solve() {
long long n, m;
cin >> n >> m;
vector<long long> v(n);
for (auto& x : v) cin >> x;
vector<string> s(n);
for (auto& x : s) cin >> x;
long long nax = 0;
vector<lo... | 14 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = (long long)1e9 * (long long)1e9;
const int T = 1e4 + 10, SQ = 32 * 1e6, N = 1e5 + 10;
long long n[T], k[T], dp[N];
int ans[T], q;
vector<int> cheat;
bitset<SQ> not_prime;
long long power(long long a, long long b, long long mod) {
if (b == 0) return 1... | 25 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3005;
const int mod = 998244353;
int n, m;
char s[N], t[N];
int dp[N][N];
int main() {
cin >> (s + 1) >> (t + 1);
n = strlen(s + 1), m = strlen(t + 1);
for (int len = 1; len <= n; len++) {
for (int l = 1, r = len; r <= n; l++, r++) {
if (l > m ... | 14 |
#include <bits/stdc++.h>
int main() {
int a[105][4], key, i, j, n, c[105], found = 0, min = 1005, ans;
scanf("%d", &n);
for (i = 0; i < n; i++) {
for (j = 0; j < 4; j++) {
scanf("%d", &a[i][j]);
}
}
for (i = 0; i < n; i++) {
j = 0;
found = 0;
key = i;
while (j < n && found == 0) ... | 2 |
#include <bits/stdc++.h>
using namespace std;
inline void open(const char *s) {}
inline int rd() {
static int x, f;
x = 0;
f = 1;
char ch = getchar();
for (; ch < '0' || ch > '9'; ch = getchar())
if (ch == '-') f = -1;
for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
return f > 0 ... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
int i, n, k, a[N], t = 0, ans[N], pos[N], take;
set<int> active;
cin >> n >> k;
for (i = 1; i <= n; i++) cin >> a[i], pos[a[i]] = i, active.insert(i);
for (i = n; i... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
set<pair<int, int> > s;
set<pair<int, int> >::iterator it;
int n, m;
int x[maxn];
int y[maxn];
char c[maxn];
int main() {
while (scanf("%d%d", &n, &m) != EOF) {
s.clear();
memset(x, 0, sizeof(x));
memset(y, 0, sizeof(y));
memset(... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
const long long mod = 998244353;
set<pair<int, int> > s[N];
long long add[N << 2], mul[N << 2], sum[N << 2];
long long ans;
void pushup(int rt) { sum[rt] = (sum[rt << 1] + sum[rt << 1 | 1]) % mod; }
void build(int rt, int l, int r) {
sum[rt] = add[... | 17 |
#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;
inline bool checkBit(long long n, int i) { return n & (1LL << i); }
inline long long setBit(long long n, int i) {
return n | (1LL << i);
;
}
inl... | 6 |
#include <bits/stdc++.h>
using namespace std;
struct Notebook {
int speed;
int ram;
int hdd;
int cost;
};
Notebook mass[101];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; ++i)
cin >> mass[i].speed >> mass[i].ram >> mass[i].hdd >> mass[i].cost;
for (int i = 0; i < n; ++i) {
for (int j = 0... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long A = 300;
long long a[4];
bool dp1[A + 1][A + 1][A + 1];
bool dp2[A + 1][A + 1][A + 1];
bool dp3[A + 1][A + 1][A + 1];
bool dp4[A + 1][A + 1][A + 1];
bool dp[A + 1][A + 1][A + 1];
int main() {
long long n;
cin >> n;
for (long long i = 1; i <= n; i++) {
... | 13 |
#include <bits/stdc++.h>
using namespace std;
long long max(long long A, long long b) {
if (A > b) return A;
return b;
}
long long min(long long A, long long b) {
if (A < b) return A;
return b;
}
using namespace std;
int main() {
long long q;
cin >> q;
while (q--) {
long long n;
cin >> n;
long... | 7 |
#include <bits/stdc++.h>
using namespace std;
char s1[310000];
char s2[310000];
char ans[310000];
bool cmp(char a, char b) { return a > b; }
int main() {
scanf("%s%s", s1, s2);
int len = strlen(s1);
sort(s1, s1 + len);
sort(s2, s2 + len, cmp);
int cnt = 0, t1 = 0, t2 = 0, flag = 1;
while (true) {
if (s2... | 10 |
#include <bits/stdc++.h>
using namespace std;
int a[101][101], b[101], n;
bool huan(int now, int last, int start, int step) {
if (now == start) {
if (step % 2 == 0)
return true;
else
return false;
}
for (int i = 1; i <= n; i++) {
if (a[i][now] == 1 && i != last && b[i] != 0) {
b[i] =... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
char s[maxn];
int nxt[maxn];
queue<int> q0, q1;
int q[maxn], qn;
int vis[maxn];
int n, cnt;
int main() {
scanf("%s", s + 1);
n = strlen(s + 1);
for (int i = 1; i <= n; i++) {
if (s[i] == '0') {
if (!q1.empty()) {
nxt[q1.fro... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cout << fixed << setprecision(15);
long n;
cin >> n;
vector<long> stack;
for (long long f = (long long)0; f <= (long long)n - 1; ++f) {
long x;
cin >> x;
stack.push_back(x);
... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
char y[11];
scanf("%d\n", &n);
while (n--) {
scanf("%s", y);
int len = strlen(y);
if (len == 5 && y[4] == '9')
puts("1989");
else if (len == 5)
printf("199%s\n", y + 4);
else if (len == 6 && y[4] == '9' && y[5] == ... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const long long INF = 1e9 + 10;
int a[N], b[N], n, c;
int check(long long x) {
long long second = 0;
for (int i = 0; i < n; i++) {
second += 1 + x * a[i] / b[i];
if (second > c) return 1;
}
if (second == c) return 0;
return -1;
}
int... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
const int mxn = (2e5) + 5;
vector<int> tr[mxn];
int p[mxn][20];
int dep[mxn];
int T;
int in[mxn];
int out[mxn];
void dfs(int v, int pa) {
++T;
in[v] = T;
for (int i = 0; i < tr[v].size(); ++i) {
int u = tr[v][i];
if (u == pa) continue;
dep[u] = d... | 16 |
#include <bits/stdc++.h>
using namespace std;
using namespace std;
template <typename T, typename U>
std::istream& operator>>(std::istream& i, pair<T, U>& p) {
i >> p.first >> p.second;
return i;
}
template <typename T>
std::istream& operator>>(std::istream& i, vector<T>& t) {
for (auto& v : t) {
i >> v;
}
... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string a;
cin >> a;
if (n == 0 || n == 1 || n % 2 != 0) cout << "";
int l = 0, r = 0;
for (int i = 0; i < n; i++) {
if (a[i] == '(') l++;
if (a[i] == ')') r++;
if (l > n / 2 || r > n / 2) {
cout << ":(" << endl;
... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
vector<int> skills;
int ahm;
scanf("%d", &n);
for (register int i = 0; i < n; ++i) {
scanf("%d", &ahm);
skills.push_back(ahm);
}
sort(skills.begin(), skills.end());
int pql = 0;
int team = 1;
int max_team = 0;
for (register ... | 4 |
// #pragma GCC optimize("Ofast,unroll-loops")
// #pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define dd double
#define ld long double
#define sl(n) scanf("%lld", &n)
#define si(n) scanf("%d", &n)
#define sd(n) scanf("%lf", &n)
#d... | 20 |
#include <bits/stdc++.h>
using namespace std;
typedef long long int64;
typedef unsigned long long uint64;
const double pi = acos(-1.0);
const double eps = 1e-11;
const int MAXI = 2 << 29;
int n, m, vi1[3005], vi2[3005], father[3005];
vector<int> p[3005], v[3005], ring;
int del(int x) {
if (v[x].size() == 1) {
int... | 8 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const long long INF = 1e9 + 47;
const long long LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 1 << 18;
int n;
int a[N];
int cnt[N];
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), ... | 13 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.