solution stringlengths 53 181k | difficulty int64 0 13 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 3;
int main() {
int n, k;
cin >> n >> k;
long long ans = 0;
int cnt = 2 * n - 3;
for (int i = 0; i < min(k, n / 2); i++) {
ans += cnt;
cnt -= 4;
}
cout << ans;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
struct cliente {
long long orden;
long long M;
};
bool compara(cliente A, cliente B) { return (A.M < B.M); }
int main(void) {
int n;
long long d;
int a, b, x, y;
scanf("%d %lli", &n, &d);
cliente cli[n];
int pija[n];
scanf("%d %d", &a, &b);
for (int i = ... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int32_t Mod = 1e9 + 7;
const int mod = pow(10, 9) + 7;
bool compare(pair<int, int> p1, pair<int, int> p2) {
return p1.second < p2.first;
}
void open_file() {}
void fast_io() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
}
int pr(int ... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long d, n, m;
pair<long long, long long> v[200005];
int main() {
scanf("%I64d %I64d %I64d", &d, &n, &m);
for (int i = 0; i < m; i++) scanf("%I64d %I64d", &v[i].first, &v[i].second);
sort(v, v + m);
priority_queue<pair<long long, long long> > inside_range, outsi... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, c = 0;
scanf("%d%d", &n, &m);
while (n--) {
int a;
scanf("%d", &a);
c += a;
printf("%d ", c / m);
c %= m;
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
string str;
cin >> str;
bool flag = false;
for (int i = 0; i < str.size(); i++) {
if (str[i] == 'H' || str[i] == 'Q' || str[i] == '9') {
flag = true;
break;
}
}
if (flag)
cout << "YES\n";
else... | 0 |
#include <bits/stdc++.h>
using namespace std;
vector<int> g[510000], color, ans;
void solve() {
cin.tie(0);
cout.tie(0);
cin.sync_with_stdio(0);
int n, m;
cin >> n >> m;
vector<pair<int, int>> blogs;
map<int, int> them;
for (int i = 0; i < m; i++) {
int x, y;
cin >> x >> y;
x--;
y--;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 25, S = (1 << 22) + 10;
int g[N], conn[S];
int main() {
int n, m;
cin >> n >> m;
while (m--) {
int u, v;
cin >> u >> v;
g[u] |= (1 << (v - 1));
g[v] |= (1 << (u - 1));
}
int subsets = (1 << n);
int need = 0;
for (int i = 1; i <= n... | 8 |
#include <bits/stdc++.h>
using namespace std;
int A, B, C;
int a[205], b[205], c[205];
int dp[201][201][201];
inline void chmax(int &aa, int xx) {
if (xx > aa) aa = xx;
}
int main() {
ios::sync_with_stdio(false);
cin >> A >> B >> C;
for (int i = 1; i <= A; ++i) cin >> a[i];
for (int i = 1; i <= B; ++i) cin >>... | 5 |
#include <bits/stdc++.h>
int n, m, t;
int main() {
scanf("%d%d", &n, &m);
if (m == 3) {
if (n == 3) {
printf("0 0\n0 1\n1 0\n");
return 0;
}
if (n == 4) {
printf("0 0\n0 10\n10 0\n1 1\n");
return 0;
}
printf("-1\n");
return 0;
} else {
int c(0);
for (int i =... | 7 |
#include <bits/stdc++.h>
using namespace std;
bool solve(int n, int s) {
long long sum = n * 1ll * (n + 1) / 2;
if (sum < s) return false;
return sum % 2 == s % 2;
}
int main() {
int t;
cin >> t;
while (t--) {
int a, b;
cin >> a >> b;
int d = abs(a - b);
if (d == 0) {
cout << "0\n";
... | 3 |
#include <bits/stdc++.h>
const int mod = 998244353;
const int maxn = 1e5 + 5;
const int inf = 1e9;
const long long onf = 1e18;
using namespace std;
void work() {
int n, t;
scanf("%d%d", &n, &t);
int ans = 0, tim = inf;
for (int i = 1; i <= n; i++) {
int x, y;
scanf("%d%d", &x, &y);
int temp = x;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int x1, x2, x3, y, y2, y3;
bool z = 0;
vector<pair<int, pair<int, char> > > x;
void check() {
if (x2 == x3 && y2 + y3 == x1 && x2 + y == x1) {
z = 1;
cout << x1 << endl;
for (int i = 1; i <= x1; i++) {
for (int j = 1; j <= x1; j++) {
if (i > y) {... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = LLONG_MAX;
const long double PI = 3.141592653589793238463;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long T;
cin >> T;
while (T--) {
long long n;
cin >> n;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long n, t, i, j, k, a[7], res[7];
long long b[6][6] = {2, 1, 1, 1, 0, 0, 1, 2, 1, 1, 0, 0, 1, 0, 1, 0, 0, 0,
0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1};
long long c[6][6], d[6][6];
void m(long long A[][6], long long B[][6]) {
for (long... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int M = 2e2 + 5;
const int inf = 0x3f3f3f3f;
const long long linf = 0x3f3f3f3f3f3f3f3f;
long long n, k;
char a[M];
long long dp[M][M];
long long pre[M];
long long tmp, ans;
int main() {
ios::sync_with_stdio(false);
cin >> n >> k;
cin >> a + 1;
dp[0][0] = 1;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long m, n;
cin >> m >> n;
vector<vector<long long>> arr(m, vector<long long>(n));
vector<long long> adj(n, -1);
for (long long i = 0; i < m; i++) {
for (long long j = 0; j < n; j++) {
cin >> arr[i][j];
adj[j] = max(adj[j], arr[i... | 5 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class t, class u>
void chmax(t& first, u second) {
if (first < second) first = second;
}
template <class t, class u>
void chmin(t& first, u second) {
if (second < first) first = second;
}
template <class t>
using vc = vector<t>;
template ... | 11 |
#include <bits/stdc++.h>
using namespace std;
string str[5] = {"Danil", "Olya", "Slava", "Ann", "Nikita"};
string S;
int main() {
while (cin >> S) {
int num = 0;
for (int i = 0; i < 5; i++) {
for (int j = 0; j < S.size(); j++) {
if (S.substr(j, str[i].size()) == str[i]) num++;
}
}
... | 1 |
#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;
const int MAXN = 100010;
template <typename T>
inline T sqr(T n) {
return n * n;
}
int n, m;
pair<int, int> edge[MAXN];
vector<int> out[MAXN]... | 5 |
#include <bits/stdc++.h>
using namespace std;
vector<int> z_function(string s) {
int n = (int)s.length();
vector<int> z(n);
for (int i = 1, l = 0, r = 0; i < n; ++i) {
if (i <= r) z[i] = min(r - i + 1, z[i - l]);
while (i + z[i] < n && s[z[i]] == s[i + z[i]]) ++z[i];
if (i + z[i] - 1 > r) {
l = ... | 2 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void input(vector<T> &arr, long long int n) {
T temp;
for (long long int i = 0; i < n; i++) cin >> temp, arr.push_back(temp);
}
template <typename T>
void output(vector<T> arr) {
T temp;
for (auto x : arr) cout << x << " ";
cout << endl;
}
te... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, a1, b1, a2, b2;
cin >> t;
while (t--) {
cin >> a1 >> b1;
cin >> a2 >> b2;
if (a1 > b1) swap(a1, b1);
if (a2 > b2) swap(a2, b2);
if (b1 == b2 && a1 + a2 == b1)
cout << "YES" << endl;
else
cout << "NO" << endl;
}... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1005;
const int INF = INT_MAX / 3;
const int MAXLOG = 20;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
long long n, d, m, l;
cin >> n >> d >> m >> l;
long long pos = 0;
for (int i = 1; i <= n; i++) {
long long f = (i - 1ll) * m, t =... | 4 |
#include <bits/stdc++.h>
using namespace std;
void print(int n, int m, int a, int b) {
int ans[n][m];
memset(ans, 0, sizeof(ans));
int jump = 1;
while (jump < m) {
if ((jump * n) % m == 0) break;
jump++;
}
int k = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < a; j++) {
ans[i][(j +... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int INF = int(1e9);
int n, w, k;
int a[200005];
int t[200005];
struct Cmp {
inline bool operator()(const int &lhs, const int &rhs) const {
if (t[lhs] != t[rhs]) return t[lhs] > t[rhs];
return lhs < rhs;
}
};
struct Cmp2 {
inline bool operator()(const int... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
k = 240 - k;
int sum = 0, ans = 0;
for (int i = 1; i <= n; i++) {
sum += i * 5;
if (sum > k) break;
ans++;
}
cout << ans << endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
char s[1005];
long long ans = 0, x = 0, flag = 1;
int main() {
cin >> s;
int len = strlen(s);
for (int i = 0; i < len; i++) {
if (s[i] < '0' || s[i] > '9') {
ans += x * flag;
x = 0;
flag = s[i] == '+' ? 1 : -1;
x = x * 10 + s[i] - '0';
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 7;
long long n, m, k;
void Main() {
scanf("%lld%lld%lld", &n, &m, &k);
if (n > m) swap(n, m);
if (k < m)
return puts("-1"), void();
else {
int flag1 = (k - n) % 2, flag2 = (m - n) % 2;
if (flag1 == 0 && flag2 == 0) printf("%lld\n", k)... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long const N = 312312;
long long const INF = 1e9 + 7;
long long n, a[N], d;
long long ne[N], pre[N], pos[N], dp[N], par[N];
pair<long long, long long> t[4 * N];
pair<long long, long long> get(long long v, long long tl, long long tr,
long ... | 6 |
#include <bits/stdc++.h>
using namespace std;
void islam() {
std::ios::sync_with_stdio(false);
cin.tie(NULL);
}
int main() {
islam();
int g[10][10];
for (int i = 0; i < 5; ++i)
for (int j = 0; j < 5; ++j) cin >> g[i][j];
int ans = -1, tmp;
int p[6] = {0, 1, 2, 3, 4};
int i = 0;
tmp = g[p[0]][p[1]]... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
scanf("%d %d", &n, &k);
int n2 = n;
n /= 2;
if (k == 0 && n2 == 1) {
printf("%d", 1);
return 0;
}
if (n > k || !n) {
cout << -1;
return 0;
}
int aux = 1;
if (k > n) {
n--;
n2 -= 2;
aux = k - n;
print... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 10;
const int inf = 0xfffffff;
const int mod = 1e9 + 7;
const double pi = acos(-1);
int a[maxn], vis[maxn];
int rMax;
int n, k, d;
inline void open(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}... | 6 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long n, k, p, i, j;
cin >> n >> k >> p;
long long a[n], b[k];
for (i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
for (j = 0; j < k; j++) {
cin >> b[j];
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int prime = 999983;
const int INF = 0x7FFFFFFF;
const long long INFF = 0x7FFFFFFFFFFFFFFF;
const double pi = acos(-1.0);
const double inf = 1e18;
const double eps = 1e-6;
const long long mod = 1e9 + 7;
long long qpow(long long a, long long b) {
long long s = 1;
wh... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<char> v;
char c = 'a';
for (int i = 0; i < 26; i++) {
v.push_back(c);
c++;
}
string out = "";
for (int i = 0; i < m; i++) {
out += v[i];
}
for (int i = 0; i < n; i++) cout << out[i % m];
return 0... | 0 |
#include <bits/stdc++.h>
using namespace std;
int niz[100005];
int res;
int n;
void prb(int x) {
for (int j = 1; j <= x; j++) {
int tren = 0;
for (int i = j; i <= n; i += x) {
tren += niz[i];
}
res = max(res, tren);
}
}
int main() {
ios_base::sync_with_stdio(false);
cout.precision(10);
c... | 2 |
#include <bits/stdc++.h>
using namespace std;
int value(vector<int> v) {
int val = 0, i, j, n = v.size();
for (i = 0; i < n; i++) {
for (j = i; j < n; j++)
val += *min_element(v.begin() + i, v.begin() + j + 1);
}
return val;
}
int main() {
ios_base::sync_with_stdio(0);
;
cin.tie(0);
cout.tie(0... | 5 |
#include <bits/stdc++.h>
using namespace std;
char grid[1001][1001];
int visited[1001][1001];
int arr[1000001];
int N, M, num = 0;
void recur(int r, int c, int n) {
if (r < 0 || c < 0 || r >= N || c >= M || grid[r][c] != '.') {
arr[n] = num;
return;
}
grid[r][c] = '!';
visited[r][c] = n;
if (grid[r - ... | 4 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll getrnd(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rng); }
template <typename T1, ... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int MAXn = 100 * 1000 + 17;
int n;
long long arr[MAXn];
vector<int> adj[MAXn];
long long dp[MAXn];
bool mark[MAXn];
long long sum;
long long GCD(long long a, long long b) {
if (a < b) swap(a, b);
while (b != 0) {
a = a % b;
swap(a, b);
}
return a;
}
lo... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n;
int bit[500000 + 1];
void add(int a, int w) {
for (int x = a; x <= n; x += x & (-x)) bit[x] += w;
}
int sum(int a) {
int ret = 0;
for (int x = a; x > 0; x -= x & (-x)) ret += bit[x];
return ret;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
st... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n;
double x[1005], y[1005];
struct P {
double k, b;
} val[1000005];
bool cmp(P u, P v) {
if (u.k == v.k) return u.b < v.b;
return u.k < v.k;
}
int main() {
scanf(" %d", &n);
for (int i = 1; i <= n; i++) scanf(" %lf %lf", &x[i], &y[i]);
int cnt = 0;
for (in... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, i, j, cnt = 0;
cin >> n >> m;
string s[n];
for (i = 0; i < n; i++) {
cin >> s[i];
}
for (i = 0; i < n - 1; i++) {
for (j = 0; j < m - 1; j++) {
if (((s[i][j] * s[i + 1][j]) * (s[i][j + 1]) * (s[i + 1][j + 1]) ==
((... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e3 + 5;
struct edge {
int from, to, id, cost;
};
int N, M, s, t;
vector<edge> G[MAXN];
bool vis[MAXN], found;
vector<edge> path;
void dfs1(int u, int id = -1) {
if (u == t) return void(found = true);
vis[u] = true;
for (int i = 0; i < G[u].size(); ... | 9 |
#include <bits/stdc++.h>
using namespace std;
typedef long SMatrix[50][50];
typedef long BMatrix[100][100];
void getMatrix(long n, SMatrix m) {
for (int i = 0; i < n; i++) {
string str;
cin >> str;
for (long j = 0; j < n; j++) {
string substr = str.substr(j, 1);
if (substr == "o") m[i][j] = 2;... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long a[1000003];
int main(int argc, char const *argv[]) {
ios_base::sync_with_stdio(false);
cin.tie(NULL), cout.tie(NULL);
long long n, c;
cin >> n;
c = 0;
for (int i = 0; i < n; ++i) {
cin >> a[i];
if (a[i] == 1) {
++c;
}
}
if (c == n... | 2 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
vector<long long> a(n);
for (long long i = 0; i < n; i++) cin >> a[i];
long long x = 0, ans = 0;
for (long long i = 0; i < n; i++) {
if (a[i] >= 0) {
x +... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, x, y;
vector<int> vec[2 * 100005];
pair<int, int> hz[100005];
int viz[2 * 100005];
void dfs(int nod, int col) {
viz[nod] = col;
for (auto it : vec[nod]) {
if (viz[it] == col) {
cout << "-1";
exit(0);
}
if (!viz[it]) dfs(it, 3 - col);
}
}... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int OO = 0x3f3f3f3f;
const int _OO = -1 * OO;
const double EPS = (1e-9);
const double pi = 3.14159265;
using namespace std;
int dcmp(double x, double y) { return fabs(x - y) <= EPS ? 0 : x < y ? -1 : 1; }
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, -1, 1};
int dx8[8] ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int i = 0;
int sum = 0;
while (n > sum) {
sum += i;
if (n < sum) break;
i++;
n -= sum;
}
cout << i - 1;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
char c;
while (getline(cin, s)) {
for (int i = s.size() - 1; i >= 0; i--) {
if (isalpha(s[i])) {
c = s[i];
break;
}
}
if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y' ||
c =... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string a, b, c;
cin >> a >> b >> c;
int i = 0, j = 0;
while (i == 0) {
if (c.find(a[i]) != string::npos) {
c.erase(c.find(a[i]), 1);
a.erase(i, 1);
} else
i++;
}
while (j == 0) {
if (c.find(b[j]) != string::npos) {
... | 0 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("-ffloat-store")
using namespace std;
clock_t time_p = clock();
void aryanc403() {}
const long long int INF = 0xFFFFFFFFFFFFFFFL;
long long int seed;
mt19937 rng(seed... | 5 |
#include <bits/stdc++.h>
using namespace std;
namespace IO {
const int sz = 1 << 15;
char inbuf[sz], outbuf[sz];
char *pinbuf = inbuf + sz;
char *poutbuf = outbuf;
inline char _getchar() {
if (pinbuf == inbuf + sz) fread(inbuf, 1, sz, stdin), pinbuf = inbuf;
return *(pinbuf++);
}
inline void _putchar(char x) {
if... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
T sqr(T x) {
return x * x;
}
int n;
char a[5001][5001];
int met[301];
bool was[301];
int dif = 0;
int main() {
srand(time(NULL));
ios_base::sync_with_stdio(0);
cin >> n;
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j) {
cin >... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
int k, i, b, j, ans = 0;
cin >> k;
map<string, vector<string> > sl;
map<string, int> kolv;
vector<string> ch(k);
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int a[2005];
pair<int, int> b[2005];
int main() {
int n, k;
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
b[i] = pair<int, int>(-a[i], i);
}
sort(b + 1, b + 1 + n);
vector<int> v;
int ans = 0;
for (int i = 1; i <= k; i++) ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 300 + 10;
const int maxm = maxn * 4 + 10;
const int inf = 1e8;
const long long mod = 1e9 + 7;
int getint() {
char c;
while ((c = getchar()) && !(c >= '0' && c <= '9') && c != '-')
;
int ret = c - '0', sgn = 0;
if (c == '-') sgn = 1, ret = 0;
w... | 5 |
#include <bits/stdc++.h>
using namespace std;
vector<int> answer;
string str;
int pre[5000];
int f(int i, int j) {
if (i >= j) return 0;
if (str[i] == '(') {
answer.push_back(f(i + 1, pre[i] - 1));
return 0;
}
if (str[i] == '[') {
int cnt = 0;
while (i < j) {
cnt += f(i + 1, pre[i] - 1);
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long INF = 9e18;
const int inf = 2147483647;
long long phi(long long n) {
long long ans = n;
for (long long i = 2; i * i <= n; i++) {
if (n % i == 0) {
ans = ans / i * (i - 1);
while (n % i == 0) n /= i;
}
... | 7 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
long long int mod = 1000000007;
double PI = 3.14159265358979323846264338327950288;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void _... | 2 |
#include <bits/stdc++.h>
using namespace std;
int const N = 1010;
int a[N];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= (n * 2); ++i) scanf("%d", &a[i]);
int ans = 0;
for (int i = 1; i < n * 2; i += 2) {
if (a[i] == a[i + 1]) continue;
for (int j = i + 1; j <= n * 2; ++j) {
if (a[j... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
vector<int> a, b;
long long ans;
long long bs(long long st, long long en) {
long long mid;
if (st < en) {
mid = st + ((en - st) / 2);
long long tmp;
for (int i = 0; i < n; ++i) {
long long e = (mid * a[i]) - b[i];
e = e < 0 ? 0 : e;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
stack<int> s[300005];
priority_queue<int> w;
int main() {
int n, q, x, y, maxt = 0, cnt = 0, read = 0;
scanf("%d %d", &n, &q);
for (int i = 0; i < q; i++) {
scanf("%d %d", &x, &y);
if (x == 1) {
cnt++;
s[y].push(cnt);
} else if (x == 2) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x1, y1, x2, y2;
scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
int ans = max(abs(y1 - y2), abs(x1 - x2));
printf("%d\n", ans);
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << ' ' << H;
debug_out(T...);
}
const int INF = 1e9;
const long long MOD = 1e9 + 7;
const int N = 1e5 + 5, MO = 320, SQ = 600;
int n, q, A[N], QL[N], Q... | 11 |
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
struct Function {
string name;
vector<string> types;
} f[1011], cur;
bool operator==(const Function &a, const Function &b) {
if (a.name != b.name) return false;
if (a.types.size() != b.types.size()) return false;
for (int i = 0, _a = (a... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long read() {
long long x = 0, y = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') y = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = (x << 1) + (x << 3) + c - '0';
c = getchar();
}
return x * y;
}
long long t, n... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t[3], h, m, s, t1, t2;
cin >> h >> m >> s >> t1 >> t2;
t[0] = 60 * 60 * h + 60 * m + s;
t[1] = 12 * 60 * m + 12 * s;
t[2] = 12 * 60 * s;
t1 *= 60 * 60;
t2 *= 60 * 60;
sort(t, t + 3);
if (t[0] < t1 && t1 < t[1]) {
if (t[0] < t2 && t2 < ... | 3 |
#include <bits/stdc++.h>
using namespace std;
void sciar(int a[], int n) {
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
}
vector<int> graph[100];
vector<int> node;
int wtf = 0;
void mk_nd(string a, string b) {
int sz = min(a.size(), b.size());
for (int i = 0; i < sz; i++) {
if (a[i] != b[i]) {
int u ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, S;
struct Parcel {
int in, out, w, s, v;
bool operator<(const Parcel &other) const {
if (out != other.out) return out < other.out;
return in > other.in;
}
} parcel[505];
int dp[1005];
int val[505][1005];
int main() {
scanf("%d%d", &n, &S);
for (int ... | 9 |
#include <bits/stdc++.h>
char a[3000005], b[3000005];
char s[3000005];
int fix[30], map[30], used[30];
int doEqual(int k, int n) {
for (int i = 1; i <= k; i++) {
map[i] = fix[i] = used[i] = 0;
}
for (int i = 1; i <= n; i++) {
int u = s[i] - 'a' + 1;
int v = a[i] - 'a' + 1;
if (fix[u]) {
if (... | 7 |
#include <bits/stdc++.h>
using namespace std;
double hi;
double b_h(double hi2, double b1) {
double b2, ret;
b2 = (hi2 / hi) * (b1 / 2);
ret = b1 - 2 * b2;
return ret;
}
int main() {
double base, area, seg, ang, ans;
int i, j, k, n;
cin >> n >> hi;
vector<double> ara;
base = 1.0;
area = hi * 0.5;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
string s;
cin >> s;
int k;
cin >> k;
int a[26], mx = 0;
for (int i = 0; i < 26; ++i) {
cin >> a[i];
mx = max(mx, a[i]);
}
long long int w = 0;
for (int i = 0; i < s.length(); ++i) w += (i + 1) * a[s[i] - 'a'];
for (int i = s.length... | 1 |
#include <bits/stdc++.h>
using namespace std;
map<int, bool> mp;
int main() {
int n;
cin >> n;
if (n % 2 == 0) {
int ans = n / 2;
ans *= n;
cout << ans << endl;
for (int i = 1; i <= n; i++) {
bool test;
if (i % 2 != 0)
test = true;
else
test = false;
for (in... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int P = 1e9 + 7;
const int N = 505;
char str[N];
int cnt;
int f[N][1 << 16];
void updata(int &x, int y) {
x += y;
if (x >= P) x -= P;
}
void gett(int ch, int f[]) {
int pos, x;
if (isupper(ch)) {
pos = ch - 'A', x = 1;
} else {
pos = ch - 'a', x = 0;... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long int mod = 1000000007;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int n, m, a, b, ans = 0;
cin >> n >> m;
for (long long int i = 0; i < n; i++) {
for (long long int j = 0; j < m; j++) {
cin >> a... | 0 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll, ll>
#define umap unordered_map
#define Ff(i, x, y) for(ll i=x;i<y;i++)
#define Fr(i, x, y) for(ll i=x;i>=y;i--)
#define Ffit(it, x) for(auto it=x.begin();it != x.end();it++)
#define Frit(it, x) for(auto it=x.rbegin();it != x.rend(... | 0 |
#include <bits/stdc++.h>
std::mt19937 rng(
(int)std::chrono::steady_clock::now().time_since_epoch().count());
const int ms = 250500;
std::queue<int> q;
bool got[ms];
long long p[ms], r[ms], dist[ms], mass[ms];
template <class T = long long>
struct FenwickTree {
public:
FenwickTree(std::vector<T> pts) {
std::... | 8 |
#include <bits/stdc++.h>
using namespace std;
int a, b, n, ans;
long long read() {
long long x = 0, F = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') F = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = x * 10 + c - '0';
c = getchar();
}
return x * F;
}
int main(... | 9 |
#include <bits/stdc++.h>
int main() {
int tests;
std::cin >> tests;
for (int t = 0; t < tests; ++t) {
int n, k;
std::cin >> n >> k;
std::vector<std::vector<int>> sets(k);
for (int i = 0; i < k; ++i) {
int c;
std::cin >> c;
sets[i].resize(c);
for (int& j : sets[i]) std::cin ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<long> a;
vector<long> b;
int nA, nB;
cin >> nA >> nB;
int k, m;
cin >> k >> m;
for (int i = 1; i <= nA; i++) {
int x;
cin >> x;
a.push_back(x);
}
for (int i = 1; i <= nB; i++) {
int x;
cin >> x;
b.push_back(x);
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
struct SegTree {
int n, M;
vector<int> lz, tr;
SegTree() {}
SegTree(int n, int M, int *a) : n(n), M(M), lz(4 * n), tr(4 * n) {
build(1, 1, n, a);
}
int combine(int left, int right) {
int ans = left + right;
if (ans >= M) ans -=... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
const int mo = 1e9 + 9;
const int S = 383008016;
const int S_inv = 276601605;
const int A = 691504013;
const int B = 308495997;
int n, m, v[N], pA[N], pB[N];
namespace cipolla {
const int mo = 1e9 + 9;
int a, t;
struct Node {
int x, y;
Node opera... | 8 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int N = 1200031;
int n, ar[N], w[N];
int gcd(int a, int b) {
while (a && b) a > b ? a %= b : b %= a;
return a + b;
}
vector<pair<int, int> > edges;
vector<int> entries[N];
int sz[N];
long long ANS[N];
vector<int> interesting;
long long c... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 100;
long long ST[4 * N];
long long st[4 * N], label[4 * N];
long long ct[15][N];
inline int LC(int i) { return 2 * i + 1; }
inline int RC(int i) { return 2 * i + 2; }
long long mod = 1e9 + 9;
long long pow(long long a, int p) {
long long ans = 1ll, tm... | 8 |
#include <bits/stdc++.h>
using namespace std;
int read() {
char ch = getchar();
int x = 0, y = 1;
while (!isdigit(ch) && ch != '-') ch = getchar();
if (ch == '-') {
y = -1;
ch = getchar();
}
while (isdigit(ch)) {
x = (x << 1) + (x << 3) + ch - '0';
ch = getchar();
}
return x * y;
}
const... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, a[100000];
cin >> n;
map<long long int, long long int> s;
map<long long int, long long int> used;
map<long long int, long long int> start;
map<long long int, long long int> ans;
map<long long int, long long int> last;
for (long ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
int mod = 1e9 + 7;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long powmod(long long a, long long b) {
long long res = 1;
if (a >= mod) a %= mod;
for (; b; b >>= 1) {
if (b & 1) res = res * a;
... | 2 |
#include<bits/stdc++.h>
using namespace std ;
const int maxn = 6e5 + 10 ;
const int inf = 0x3f3f3f3f ;
struct Dinic
{
int tot ;
int Next[maxn],last[maxn],to[maxn],flow[maxn],q[maxn],dis[maxn],S,T;
void init()
{
tot = 1 ;
memset(last , 0 , sizeof(last)) ;
}
void add(int x,int y,in... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 3, P = 998244353;
int fc[N], ifc[N];
int qp(int a, int b) {
int r = 1;
for (; b; b >>= 1, a = a * 1ll * a % P)
if (b & 1) r = r * 1ll * a % P;
return r;
}
int main() {
int n, m = 0, i, j, k, l, o, s = 0;
scanf("%d%d%d", &n, &k, &o), l = o, ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n;
int l[200005], r[200005];
long long fact[200005];
vector<int> c[200005];
long long dfs(int x, int pre) {
long long ans = 1, tmp = 0;
for (int i = 0; i < c[x].size(); i++) {
if (c[x][i] != pre) {
ans *= dfs(c[x][i], x);
ans %= 998244353;
tmp+... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long M = 105;
const long long INF = 1e15 + 5;
const long long MOD = 1e9 + 7;
const long long N = 1e5 + 5;
const double PI = 3.14159265358979323846264338327950288419716939937510;
long long n, k, q[M], s[M], temp[M], p[M], f[M], g[M];
bool eq() {
long long flag =... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 100;
int n, m, s, t, in[N], out[N], nrl[N], d[N], vi[N], a[N];
int tot, first[N], nxt[N], point[N], data[N];
inline int read() {
int f = 1, x = 0;
char s = getchar();
while (s < '0' || s > '9') {
if (s == '-') f = -1;
s = getchar();
}
w... | 9 |
#include <bits/stdc++.h>
using namespace std;
int a[200], b[200];
int main() {
int n, j, i, L, c = 0, m, bl = 0;
cin >> n >> L;
for (i = 0; i < n; i++) cin >> a[i];
for (i = 0; i < n; i++) cin >> b[i];
for (i = 1; i <= L; i++) {
c = 0;
for (j = 0; j < n; j++) {
if (a[j] == b[j]) c++;
a[j] ... | 2 |
#include <bits/stdc++.h>
using namespace std;
string s;
int n;
int main(int argc, char* argv[]) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> s;
int n1 = 0, n0 = 0, n2 = 0;
for (int i = 0; i < n; i++) {
if (s[i] == '0') {
n0++;
} else if (s[i] == '1') {
n1++;
} else {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string n, k;
cin >> n >> k;
bool check = false;
int j = 0;
for (int i = 0; i < k.length(); i++) {
if (k[i] == n[j]) {
j++;
if (j == n.length()) {
k = k.substr(i + 1);
check = true;
break;
}
}
}
if ... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, k;
long long f(long long mid) {
long long i;
long long ans = 0;
for (i = 1; i <= n; i++) {
ans += min((mid) / i, m);
}
if (ans >= k) return 1;
return 0;
}
long long f1(long long mid) {
long long i;
long long ans = 0;
for (i = 1; i <= n;... | 5 |
#include <bits/stdc++.h>
using namespace std;
vector<int> let[26];
int n;
const int maxn = 1e5;
int get_id[26][maxn];
string s;
void build() {
for (int i = 0; i < 26; ++i) {
int st = n, id = 0;
if (let[i].size()) st = let[i][0];
for (int j = 0; j < n; ++j) {
if (s[j] - 'a' == i) ++id;
if (id <... | 7 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.