solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const double PI = acos(-1);
long long power(long long x, long long y) {
if (y == 0)
return 1;
else if (y == 1)
return x;
long long r = power(x, y / 2);
if (y % 2 == 0)
return (r * r);
else
return (r * r * x);
}
vector... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long n, b, x, k, a[105], input[50005], mod = 1000000007, ass[105];
long long go(long long base, long long po) {
if (po == 1) return base % x;
if (po == 0) return 1;
if (po % 2 == 0) {
long long p = go(base, po / 2) % x;
return (p * p) % x;
} else {
... | 12 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define F first
#define S second
void solve () {
int n;
cin >> n;
vector < pair<int, int> > v;
for (int i = n; i > 2;){
for (int k = i - 1; k>ceil (sqrt(i));k--)
v.pb({k... | 9 |
#include <bits/stdc++.h>
int main(void) {
int n, p1, p2, p3, t1, t2;
int l, r, w = 0;
int now = 0;
scanf("%d %d %d %d %d %d", &n, &p1, &p2, &p3, &t1, &t2);
scanf("%d %d", &l, &r);
w += p1 * (r - l);
now = r;
for (; n > 1; n--) {
scanf("%d %d", &l, &r);
if ((l - now) > (t1 + t2)) {
w += p1 ... | 1 |
#include <bits/stdc++.h>
int main() {
long long n, ans, minn = 100000000000, i;
scanf("%I64d", &n);
long long a, b, c, d, k, s, l = 0, m = 1, t, q, r, sum = 0;
for (i = 1; i < 165; i++) {
l = 0;
m = 1;
a = -i;
b = i * i;
c = 4 * n;
d = b + c;
if (d >= 0) {
k = sqrt(d);
if... | 6 |
#include <bits/stdc++.h>
using namespace std;
struct Segment {
int d, x, y;
Segment() {}
Segment(int _d, int _x, int _y) : d(_d), x(_x), y(_y) {}
bool operator<(const Segment& other) const {
return (y < other.y) || (y == other.y && x > other.x);
}
};
struct Event {
int time, pos, type;
Event() {}
Ev... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
int n, vis[N], ans[N];
vector<int> vec;
struct pos {
int bh, sbh;
long long x, y;
} p[N], st[N], tmp;
bool cmp(pos a, pos b) { return (a.x == b.x) ? a.y > b.y : a.x > b.x; }
double check(pos a, pos b) {
return (double)a.x * b.x * (b.y - a.y) / (b... | 18 |
#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define pk push_back
#define pii pair<int,int>
#define mk make_pair
#define fi first
#define se second
#define sz(x) ((int)x.size())
#define vt vector<string>
const int maxn=2e5+5;
using namespace std;
int rd(){
int x=0,f=1;char c=getchar();
... | 22 |
#include <bits/stdc++.h>
using namespace std;
const long long MAX_N = 40 + 24, INF = 1e9 + 24;
int n, m, q, dp1[MAX_N][MAX_N][MAX_N][MAX_N], dp2[MAX_N][MAX_N][MAX_N][MAX_N];
bool a[MAX_N][MAX_N], mark[MAX_N][MAX_N][MAX_N][MAX_N];
string s;
int main() {
cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
cin >> n ... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 10005;
set<string> words;
bool memo[4][MAX], visit[4][MAX];
string s;
int n;
bool solve(int idx, int tam) {
if (idx + tam == n) {
string A = s.substr(idx, tam);
reverse(A.begin(), A.end());
words.insert(A);
return true;
}
if (idx + tam ... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
ios::sync_with_stdio(false);
int n;
char s[105];
cin >> n >> s;
int ans = 0, cnt;
for (int i = 0; i < n; ++i) {
if (s[i] == '-')
cnt = -1;
else
cnt = 1;
ans += cnt;
if (ans < 0) ans = 0;
}
cout << ans << '\n';
r... | 0 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n, i, t, p;
t = 0;
cin >> n;
set<long long> st;
for (i = 0; i < n; i++) {
cin >> t;
if (t != 0) {
st.insert(t);
}
}
cout << st.size();
}
int main() {
long long t, i;
solve();
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int number, j = 0;
cin >> number;
string str[number][2], order[number];
for (int i = 0; i < number; i++) {
cin >> str[i][0] >> str[i][1];
}
for (int i = 0; i < number; i++) {
if (str[i][1] == "rat") {
order[j] = str[i][0];
j++;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
long long n;
cin >> n;
long long a[n], b[n];
for (long long i = 0; i < n; i++) {
cin >> a[i];
a[i] = a[i] * (i + 1) * (n - i);
}
for (long long i = 0; i < n; i++) cin >> b[i];
sort(a, a + n);
sort(b, b + n);
reverse(b, b + n);
lon... | 8 |
#include <bits/stdc++.h>
using namespace std;
bool check(string &s, int n) {
int tam = n / 4;
int array[] = {0, 0, 0, 0};
for (int i = 0; i < s.size(); i++) {
if (s[i] == 'A') {
array[0]++;
if (array[0] > tam) {
return false;
}
} else if (s[i] == 'C') {
array[1]++;
if... | 1 |
#include <bits/stdc++.h>
using namespace std;
using LL = int64_t;
using pii = pair<int, int>;
const double PI = 2 * asin(1);
struct Edge {
int w, id, flag;
Edge(int w = 0, int id = 0, int flag = 0) : w(w), id(id), flag(flag) {}
bool operator<(const Edge &e) const {
if (w == e.w) return flag > e.flag;
retu... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
long long a[n][n];
for (long long i = 0; i < n; i++) {
for (long long j = 0; j < n; j++) cin >> a[i][j];
}
long long s = 0;
for (long long i = 0; i < n; i++) {
s += a[i][i];
a[i][i] = 0;
}
for (long long i = ... | 0 |
#include <bits/stdc++.h>
using namespace std;
class Solution {
private:
int n;
public:
int maxminDistance(const vector<unordered_map<int, int>>& g, int k,
int sumD) {
n = g.size();
assert(n > 0);
vector<int> degrees(n, 0);
for (int i = 0; i < n; i++) degrees[i] = g[i].size();... | 16 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target( \
"avx,avx2,fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
long long MOD = 1e9 + 7;
const int N = 200000;
vector<long long> gr[N];
long long sz[N];
long long st(long long t, long long id, long long mod) {
... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) cin >> a[i];
map<int, int> m;
for (int i = 0; i < n; i++) {
m[a[i]]++;
if (m[a[i]] == 3) {
cout << "NO";
return 0;
}
}
cout << "YES" << endl;
vector<int> increase;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int ir[2000000], u[2000000], v[2000000], n, r, d[2000000], l, am;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for (int i = 1; i <= n; i++) cin >> d[i];
for (int i = 1; i <= n; i++) ir[d[i]] = true;
while (d[n] > r) {
do {
fo... | 17 |
#include <bits/stdc++.h>
using namespace std;
vector<int> v;
vector<char> vc;
vector<string> vs;
map<string, int> sm;
map<int, int> mp;
map<char, int> cm;
using namespace std;
double string_to_int(string s) {
stringstream x(s);
double a = 0;
x >> a;
return a;
}
long long int gcd(long long int a, long long int b... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long double eps = 1e-9;
const long double pi = acos(-1.0);
const long long inf = 1e+9;
#pragma comment(linker, "/STACK:36777216")
template <typename T>
istream &operator>>(istream &, vector<T> &);
template <typename T>
ostream &operator<<(ostream &, const vector<T> &)... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long int lim = 2e5 + 1;
template <typename T>
T gcd(T a, T b) {
if (a == 0) return b;
return gcd(b % a, a);
}
template <typename T>
T pow(T a, T b, long long int m) {
T ans = 1;
while (b > 0) {
if (b % 2 == 1) ans = (ans * a) % m;
b /= 2;
a = ... | 13 |
#include <bits/stdc++.h>
using namespace std;
long long a[200005], n, m;
string t, p;
bool check(long long x) {
string temp = t, f;
for (long long i = 0; i < x; i++) temp[a[i] - 1] = '/';
for (long long i = 0; i < n; i++)
if (temp[i] != '/') f.push_back(temp[i]);
for (int i = 0, j = 0; i < (long long)f.size... | 9 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
T read1() {
T t = 0;
char k;
bool v = 0;
do (k = getchar()) == '-' && (v = 1);
while ('0' > k || k > '9');
while ('0' <= k && k <= '9')
t = (t << 3) + (t << 1) + (k ^ '0'), k = getchar();
return v ? -t : t;
}
long long qkpow(long long... | 15 |
#include <bits/stdc++.h>
using namespace std;
int cnt[1000];
long long int bis(long long int l, long long int r, long long int x,
long double cyc) {
if (l == r || r - l == 1) {
if (r - l == 1 && r * cyc <= x) return r;
return l;
}
long long int mid = (l + r) / 2, p;
if (mid * cyc <= x)... | 9 |
#include <bits/stdc++.h>
using namespace std;
int f(string s1, string s2) {
int posa, posc;
swap(s2[0], s2[1]);
string ns = s1 + s2;
int a = 0;
for (int i = 0; i < 4; i++) {
if (ns[i] == 'X') continue;
if (ns[i] == 'A') posa = a;
if (ns[i] == 'C') posc = a;
a++;
}
if (posc == posa + 1 || p... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, r, Ans;
vector<pair<int, int>> vP;
vector<pair<int, int>> vN;
int dp[101][30001];
bool Comp(const pair<int, int> &a, const pair<int, int> &b) {
return (a.first + a.second > b.first + b.second);
}
int Solve(int i, int r) {
if (r < 0) return -1;
if (i == vN.size(... | 13 |
#include <bits/stdc++.h>
using namespace std;
char chaine[200005];
double comp(int n, double angle, double l, double curr_angle) {
double pi = 3.14159265358979323846;
double high_x = 0.0;
double low_x = 0.0;
double high_y = 0.0;
double low_y = 0.0;
for (int i = 0; i < 2 * n; i++) {
curr_angle += angle;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string x;
cin >> x;
for (int i = 0; i < x.length(); i++) {
if (x[i] == '.') {
cout << "0";
}
if (x[i] == '-' && x[i + 1] == '.') {
cout << "1";
i++;
} else if (x[i] == '-' && x[i + 1] == '-') {
cout << "2";
i+... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t, cnt = 0, sum = 0, flag = 0;
cin >> t;
char c;
while (t--) {
cin >> c;
flag = 0;
if (cnt < 0) flag = 1;
if (c == '(')
cnt++;
else
cnt--;
if ((flag == 1 && cnt == 0) || cnt < 0) sum++;
}
if (cnt == 0)
... | 5 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimization("unroll-loops")
#pragma GCC optimize("O2")
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr long long INF = 1999999999999999997;
constexpr int inf = INT_MAX;
con... | 5 |
#include <bits/stdc++.h>
using namespace std;
int a[1000000];
deque<int> b;
map<int, bool> mp;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, k, cnt = 0, i;
cin >> n >> k;
k = min(n, k);
for (i = 0; i < n; i++) {
cin >> a[i];
}
for (i = 0; i < n; i++) {
if (mp[a[i]] == 0) {... | 2 |
#include <bits/stdc++.h>
int main() {
char s[9][9];
while (scanf("%s", s[0]) != EOF) {
int i, j;
for (i = 1; i < 8; ++i) scanf("%s", s[i]);
for (i = 0; i < 8; ++i) {
for (j = 1; j < 8; ++j) {
if (s[i][j] == s[i][j - 1]) break;
}
if (j < 8) break;
}
printf("%s\n", i < 8 ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100 * 500 + 10;
int c[maxn][30], sz = 1, dep[maxn], n, K, len, danger[maxn], f[maxn][210];
char op[505];
void insert() {
int now = 1;
for (int i = 0; i < len; i++) {
int v = op[i] - 'a' + 1;
if (!c[now][v]) c[now][v] = ++sz;
now = c[now][v];... | 14 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long maxn = 3e6 + 7;
inline long long read() {
long long res = 0, tmp = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') tmp = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
res = (re... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int m = 1000000007;
int main() {
int n, l, a;
cin >> n >> l;
string str;
map<string, vector<int> > mapi, same;
for (int i = 0; i < n; i++) {
cin >> str >> a;
string temp(str);
reverse(temp.begin(), temp.end());
if (temp == str) {
same[s... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
struct Tree {
int l, r, mx, laz;
} t[maxn << 2];
struct Node {
int v, next;
} e[maxn << 1];
int head[maxn], dfn[maxn], siz[maxn], tot, num;
int sta[maxn], top;
long long a[maxn];
void Add(int x, int y) {
e[++tot].v = y;
e[tot].next = head[... | 16 |
#include <bits/stdc++.h>
using namespace std;
long long n;
long long arr[1000003];
void read() {
cin >> n;
for (long long i = 1; i <= n; i++) cin >> arr[i];
}
vector<long long> v;
map<long long, long long> mp;
long long first[1000003], second[1000003];
void update1(long long pos, long long val) {
for (pos; pos <=... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
char arr[n][m];
vector<vector<bool> > g(n, vector<bool>(m, false));
int sx, sy, tx, ty;
for (int i = 0; i < n; ++i)
for (int j = 0; j < m; ++j) {
cin >> arr[i][j];
if (arr[i][j] == 'S') {
sx = i;
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 8;
int t, n, m, k;
string a;
char c[70];
long long ans[N], b[66];
long long sum, temp;
int main() {
scanf("%d", &t);
b[0] = 1;
for (int i = 1; i <= 60; i++) b[i] = b[i - 1] * 2;
while (t--) {
scanf("%d%d", &n, &m);
k = 0;
memset(c, '0... | 13 |
#include <bits/stdc++.h>
long long int a[10000010], i, j, k, m, n, x, y, z, ans;
int main() {
while (scanf("%I64d", &n) == 1) {
if (n % 3 != 0) {
printf("0\n");
continue;
}
n /= 3;
k = 0;
for (i = 2; i * i <= n; i++) {
if (n % i == 0) {
a[k] = i;
k++;
}
... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, r, mx = -1, cnt = 0;
cin >> n >> r;
int a[n];
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++) {
if (i > mx) {
int p = i - r + 1, q = i + r - 1, fl = 0;
if (p < 0) p = 0;
if (q > n - 1) q = n - 1;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, i, j, f = 1;
string s;
cin >> n >> s;
for (i = 0, j = n - 1; i < n / 2; i++, j--) {
if (abs(s[i] - s[j]) > 2 || abs(s[i] - s[j]) == 1) {
cout << "NO\n";
f = 0;
break;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100004, M = 304;
int a[M], b[M], v[M], in[M], nxt[M], n, m, p = 0, tot;
int f[N], mod = 1000000007;
int main() {
int x, y;
scanf("%d %d %d", &n, &m, &tot);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
for (int i = 1; i <= m; i++) {
scanf("%d %d... | 13 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef long double ld;
#define F first
#define S second
const int MOD = 1e9 + 7;// XXX
const int C = 26;// XXX
void add(int &x, int y){
x += y;
while (x >= MOD) x -= MOD;
while (x < 0) x += MOD;
}
int fix(int ... | 15 |
#include <bits/stdc++.h>
using namespace std;
int X[101];
int N, a, ans, t, MAXN;
bool found;
int main() {
scanf("%d", &N);
int i, j;
for (i = 0; i < N; i++) {
scanf("%d", &a);
X[a] += 1;
if (a > MAXN) MAXN = a;
}
found = true;
while (found) {
found = false;
for (i = 1; i <= MAXN; i++) {... | 2 |
#include <bits/stdc++.h>
using namespace std;
template <class c>
struct rge {
c b, e;
};
template <class c>
rge<c> range(c i, c j) {
return {i, j};
}
struct printer {
~printer() { cerr << endl; }
template <class c>
printer& operator,(c x) {
cerr << boolalpha << x;
return *this;
}
printer& operator... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, t;
cin >> n;
cin >> t;
int first = INT_MAX;
int bus = -1;
for (int i = 0; i < n; i++) {
int s, d;
cin >> s;
cin >> d;
if (s >= t) {
if (first > s) {
first = s;
bus = i + 1;
}
} else if (s < t) {... | 2 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
int64_t n, m;
cin >> n >> m;
vector<int64_t> h1(m, 1);
vector<unsigned long long> h2(m, 1);
vector<int64_t> last(m, -1);
int64_t mod1 = 1000000007;
int64_t mod2 = 1000000009;
vector<int64_t> pow1(100001);
pow1[0] = 1;
vector<unsigned long... | 11 |
#include <bits/stdc++.h>
using namespace std;
int v1[200005], v2[200005];
vector<int> g1[200005], g2[200005];
unsigned long long aux[20], s[200005], rasp[200005];
int main() {
int n, m;
unsigned long long a, b, c, ans = 0;
int i, x, y, j;
scanf("%d%d%llu%llu%llu", &n, &m, &a, &b, &c);
for (i = 1; i <= m; i++)... | 19 |
#include <bits/stdc++.h>
using namespace std;
int f(int x) {
if (x > 0) return x;
return -x;
}
int main() {
int i;
int n, s;
cin >> n >> s;
int p[s + 1], t[s + 1];
int x, y, ans;
ans = 0;
for (i = 0; i < s + 1; i++) p[i] = t[i] = 0;
for (i = 0; i < n; i++) {
cin >> x >> y;
p[x] = 1;
t[x]... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
inline int add(int a, int b) {
if ((a += b) >= mod) a -= mod;
return a;
}
inline int dec(int a, int b) {
if ((a -= b) < 0) a += mod;
return a;
}
inline int mult(int a, int b) {
long long t = 1ll * a * b;
if (t >= mod) t %= mod;
retu... | 20 |
#include <bits/stdc++.h>
using namespace std;
const int N = 111;
const long long MOD = 1000000007;
long long C[N][N];
int a[N];
long long dp1[N], dp2[N];
void init() {
int i, j;
for (i = 0; i <= 100; ++i) {
C[i][0] = 1;
for (j = 1; j <= i; ++j) C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % MOD;
}
}
int main... | 11 |
#include <bits/stdc++.h>
using namespace std;
struct node {
double x, y;
} a, b, c;
int main() {
cin >> a.x;
cin >> a.y;
cin >> b.x;
cin >> b.y;
cin >> c.x;
cin >> c.y;
double area;
area = a.x * (b.y - c.y) + b.x * (c.y - a.y) + c.x * (a.y - b.y);
if (area == 0) {
cout << "TOWARDS" << endl;
} ... | 5 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long a, b;
cin >> a >> b;
if (a < b) swap(a, b);
assert(a >= b);
if (a % b != 0) {
cout << -1 << endl;
return;
}
long long needed = a / b;
int ans = 0;
while (needed % 8 == 0) {
ans++;
needed /= 8;
}
while (needed % ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, m, s, t, lim, ans, Go[1000 + 5][1000 + 5], q[1000 + 5], Dis[2][1000 + 5];
bool Map[1000 + 5][1000 + 5];
void BFS(int st, int *dis) {
for (int i = 1; i <= n; i++) dis[i] = n + 1;
int l = 1, r = 0;
q[++r] = st, dis[st] = 0;
while (l <= r) {
int z = q[l++];
... | 8 |
#include <bits/stdc++.h>
using namespace std;
unsigned long long gcd(unsigned long long a, unsigned long long b) {
return a ? gcd(b % a, a) : b;
}
bool myfunction(int i, int j) { return (i > j); }
list<int> ls[400001];
int nx[400001];
int main() {
int n, k;
vector<int> vec;
scanf("%d%d", &n, &k);
for (int i =... | 10 |
#include <bits/stdc++.h>
using namespace std;
int s[100] = {0}, x[100] = {0};
int main() {
int n, m;
int l;
int sum = 0;
cin >> n >> m;
int a, b;
cin >> a;
for (int i = 0; i < a; i++) {
cin >> l;
s[l] = 1;
}
cin >> b;
for (int i = 0; i < b; i++) {
cin >> l;
x[l] = 1;
}
for (int i... | 23 |
#include <bits/stdc++.h>
using namespace std;
inline long long rd() {
long long _x = 0;
int _ch = getchar(), _f = 1;
for (; !isdigit(_ch) && (_ch != '-') && (_ch != EOF); _ch = getchar())
;
if (_ch == '-') {
_f = -1;
_ch = getchar();
}
for (; isdigit(_ch); _ch = getchar()) _x = _x * 10 + _ch - '... | 23 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INFLL = 0x3f3f3f3f3f3f3f3fLL;
inline long long read() {
long long x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int bus[1001][1001];
int main() {
long long int n, k, d, o = 1, p, i, j, g, ar;
bool check = true;
cin >> n >> k >> d;
for (i = 0; i < d + 1; i++) {
ar = 0;
for (j = 0; j < n; j++) {
if (j % o == 0 && j != 0) ar = (ar + 1) % k;
bus[i][j] = ar;
... | 11 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const int MAXH = 7;
const int MAXS = 200;
int S = 1 << 7;
long long trans[MAXS][MAXS];
long long res[MAXS][MAXS];
long long tmp[MAXS][MAXS];
void mult(long long a[MAXS][MAXS], long long b[MAXS][MAXS]) {
for (int i = 0; i < S; i++) {
for ... | 19 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
template <class T>
using pq = priority_queue<T>;
template <class T>
using pqg = priority_queue<T, vector<T>, greater<T>>;
int scan() { return getchar(); }
template <class T>
void scan(T a) {
cin >> a;
}
void scan(int &a) { cin >> a; }
void scan(... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5001;
short int dp[N][N][3];
short int n, q;
pair<short int, short int> ara[N];
short int Max(short int A, short int B) {
if (A > B)
return A;
else
return B;
}
short int call(short int pos, short int done, short int miss) {
if (miss > 2) return -... | 9 |
#include <bits/stdc++.h>
using namespace std;
const long long M = 1e9 + 7;
const long long N = 1e5 + 10;
const long long IM = 1e15 + 37;
const long double PI = 3.1415926535897932384;
inline void PP(long long n) { cout << n << " "; }
void PV(vector<long long> v) {
for (long long i = 0; i < v.size(); i++) cout << v[i] ... | 7 |
#include <bits/stdc++.h>
long long f[2005][2005];
long long k[2005][2005];
long long C[4005][4005];
int main() {
int n, m;
scanf("%d %d", &n, &m);
for (register int i = 0; i <= n; ++i)
for (register int j = 0; j <= m; ++j) {
if (i == 0)
k[i][j] = 1;
else if (j == 0)
k[i][j] = 0;
... | 15 |
#include <bits/stdc++.h>
using namespace std;
unsigned long long ans, s[201000], n, pre[201000], last[201000], other[201000],
p, q, tot;
void add(unsigned long long p, unsigned long long q) {
pre[++tot] = last[p];
last[p] = tot;
other[tot] = q;
}
void dfs(unsigned long long x, unsigned long long f) {
s[x] =... | 16 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
const int maxn = 300007;
vector<int> edge[maxn];
int n, k;
int co[maxn];
int ltk[maxn];
long long dp[maxn][2];
int cnt[maxn];
inline void multi_mod(long long a, long long &b) {
b = b * a;
b = b - b / mod * mod;
}
inline long long fpow(lo... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 25;
const int MAXM = 100005;
const long long INF = 0x3f3f3f3f3f3f3f3f;
int n, m, N;
int val[MAXN][MAXM];
long long a[1 << 20], b[1 << 20], ans = INF;
int Read() {
int x = 0, f = 1;
char c = getchar();
while (c > '9' || c < '0') {
if (c == '-') f =... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 210;
const int INF = 0x3f3f3f3f;
int table[4][4] = {0, 0, 0, 0, 0, 0, 1, 2, 0, 2, 0, 1, 0, 1, 2, 0};
int pos[MAXN];
int n;
vector<int> G[MAXN];
int deg[MAXN];
int ideg[MAXN];
int vis[MAXN];
void bfs() {
int ans = INF;
for (int d = 1; d <= 3; d++) {
... | 9 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int T;
cin >> T;
while (T--) {
int n, m;
cin >> n >> m;
vector<int> a(n), b(m);
for (auto &e : a) cin >> e;
for (aut... | 0 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<vector<pair<int, int>>> g;
vector<int> col, comp;
void dfs(int v, bool &valid) {
comp.push_back(v);
for (auto [u, t] : g[v]) {
if (col[u] == -1) {
col[u] = col[v] ^ t;
dfs(u, valid);
} else {
valid &= (col[u] == col... | 15 |
#include <bits/stdc++.h>
using namespace std;
long long int n, k, A[100010], x;
vector<pair<long long int, long long int> > v, in;
int main() {
cin >> n >> k;
for (long long int i = 1; i <= n; i++) {
cin >> A[i];
in.push_back(make_pair(A[i], i - 1));
}
for (long long int i = 1; i <= n; i++) {
cin >>... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long n, a[100001], s1, s2;
int main() {
cin >> n;
for (long long i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
long long l = 0, r = n - 1;
if (n == 1) s1 = a[0];
while (l < r) {
s1 += a[l];
s2 += a[r];
l++;
r--;
if (l == r) s2 += a[r];... | 1 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxn = 22;
char s[maxn], t[maxn];
int lst[12], n;
int ans;
ll get(char *s) {
ll res = 0;
for (int i = 0; s[i]; i++) res = res * 10 + s[i] - '0';
return res;
}
void check(int x, int y) {
if (!lst[x] || !lst[y]) return;
int cnt = 0;
... | 13 |
#include <bits/stdc++.h>
using namespace std;
int a[51][20001], pre[51][20001], dp[51][20001];
inline int sum(int i, int jl, int jr) { return pre[i][jr + 1] - pre[i][jl]; }
int main() {
int n, m, k;
cin >> n >> m >> k;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) cin >> a[i][j];
}
for (int i ... | 16 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
long long power(long long x, long long y) {
long long res = 1;
while (y) {
if (y & 1) res = (res * x) % 998244353;
y ... | 18 |
#include <bits/stdc++.h>
using namespace std;
class p {
public:
int l, r, c;
p(int l, int r, int c) : l(l), r(r), c(c) {}
};
bool cmp(const p &i, const p &j) { return i.l < j.l; }
int a[200002], n;
vector<p> v;
int l[100001], r[100001];
int d[6][100001];
int f(int h, int k) {
if (k < 0) return 1;
if (d[h][k] >... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
long i;
if (n != 1) {
bool flag = false;
int firstno, a;
cin >> firstno;
if (firstno) {
flag = true;
}
for (i = 1; i < n; ++i) {
cin >> a;
if (a != firstno) {
break;
}
}
... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
long long n, m;
int lca(int x, int y) {
while (x != y) {
if (x < y) swap(x, y);
x /= 2;
}
return x;
}
pair<int, int> norm(pair<int, int> p) {
if (p.first > p.second) swap(p.first, p.second);
return p;
}
vector<pair<int, int> > g... | 20 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int *a = new long long int[4];
long long int max = 2;
long long int pos = 0;
for (long long int i = 0; i < 4; ++i) {
cin >> a[i];
if (a[i] > max) {
max = a[i];
pos = i;
}
}
for (long long int i = 0; i < 4; ++i) {
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int a[50002][6];
int n, m;
int main() {
cin >> n >> m;
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= m; ++j) cin >> a[i][j];
for (int j = 1; j <= m; ++j)
for (int i = 1; i <= n; ++i) a[i][j] += max(a[i - 1][j], a[i][j - 1]);
for (int i = 1; i <= n; ++i) ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 120;
const int MOd = 1e9 + 9;
const int N = 17;
int a, ar[maxn], ic[maxn], dn[maxn][(1 << N) + 20], tut[maxn][(1 << N) + 20];
int asal[20] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59};
int f(int n, int used) {
if (n == a + 1) return ... | 12 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long maxn = 300005;
const long long inf = 1ll << 50;
int ans = 0;
bool init[maxn];
int par[maxn], sz[maxn], cnt[maxn][2], col[maxn];
vector<int> vec[maxn];
int find(int x) {
if (par[x] == x) {
return x;
}
int tmp = find... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, i, j, ans = 0;
cin >> n;
i = 0;
while (1) {
i++;
if (3 * (i * (i + 1) / 2) > n + i) break;
if ((n + i) % 3 == 0) ans++;
}
cout << ans;
}
| 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<int> a(m, 0);
for (int i = 0; i < n; i++) {
int ni;
cin >> ni;
for (int j = 0; j < ni; j++) {
int mi;
cin >> mi;
a[mi - 1] = 1;
}
}
int flag = 1;
for (int i = 0; i < m; i++)
if ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x, a, d;
cin >> n;
vector<int> v(n);
cin >> a;
v[0] = a;
cin >> x;
v[1] = x;
d = x - a;
char ans = 'y';
for (int i = 2; i < n; i++) {
cin >> x;
v[i] = x;
if (d != v[i] - v[i - 1]) {
ans = 'n';
}
}
if (ans == ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int N, arr[105];
multiset<int> s;
int main() {
cin >> N;
for (int i = 0; i < N; i++) {
cin >> arr[i];
if (i > 0) s.insert(arr[i]);
}
int ans = 0;
while (arr[0] <= *--s.end()) {
ans++;
int val = *--s.end() - 1;
s.erase(--s.end());
s.insert(v... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long LLINF = 1e18 + 7;
long long best = LLINF;
int n;
int tab[1000009];
void check(int p) {
long long s = 0, res = 0;
for (int i = 0; i < n; i++) {
s = (s + tab[i]) % p;
res += min(s, p - s);
}
best = min(best, res);... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000005;
bool a[N];
int main() {
ios::sync_with_stdio(false);
string s;
cin >> s;
int len = s.length(), top = 1;
a[1] = true;
for (int i = 1; i < len; i++)
if (s[i] != s[i - 1])
a[++top] = true;
else
a[top] = false;
if (s.fron... | 14 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct vertex {
long long l, r, val;
vertex() {
l = r = -1;
val = 0;
}
};
vector<vertex> tre;
void get_new(long long &x) {
x = tre.size();
tre.emplace_back();
}
void combine(long long n) ... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5000;
pair<int, int> arr[MAXN + 10];
int ans[MAXN + 10];
map<int, int> mp;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, k;
cin >> n >> k;
int maxi = 0;
for (int i = 0; i < n; i++) {
cin >> arr[i].first;
arr[i].second... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long a, b, c, d, e, sum;
int main() {
cin >> a >> b >> c >> d >> e;
while (a >= 1 && b >= 1 && c >= 2 && d >= 7 && e >= 4) {
sum++;
a -= 1;
b -= 1;
c -= 2;
d -= 7;
e -= 4;
}
cout << sum;
return 0;
}
| 9 |
#include <bits/stdc++.h>
using namespace std;
const int N = 512;
namespace PQ {
const int P = -1, Q = -2;
enum col { White = 0, Gray, Black };
struct node {
int v;
node *son, *bro;
col c;
inline node() {}
inline node(int v, node *son, node *bro, col c)
: v(v), son(son), bro(bro), c(c) {}
} pool[N << 2],... | 22 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n;
cin >> n;
vector<long long> arr(n);
for (auto &zz : arr) cin >> zz;
vector<long long> ans(600, LLONG_MAX / 2);
ans[0] = 0;
for (long long i = 0; i < n; i++) {
for (long long j =... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a;
cin >> a;
if (a < 13)
cout << setprecision(20) << pow(2, a);
else
cout << setprecision(20) << 8092 * pow(2, a - 13);
return 0;
}
| 11 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const long long LL_INF = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
inline void cmin(int &x, int y) {
if (y < x) x = y;
}
inline void cmax(int &x, int y) {
if (y > x) x = y;
}
const int B = 30000;
pair<int, int> tmp[B];
int id[B], val[B];
i... | 19 |
#include <bits/stdc++.h>
using namespace std;
int delta[4][2] = {{-1, -0}, {0, 1}, {1, 0}, {0, -1}};
long long calc_pow(long long a, long long p, long long m = 1000000007) {
long long res = 1;
while (p > 0) {
if (p & 1) res = (res * a) % m;
a = (a * a) % m;
p >>= 1;
}
return res;
}
long long calc_po... | 8 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.