solution stringlengths 53 181k | difficulty int64 0 13 |
|---|---|
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
int mod = 1e9 + 7;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, inf = 0x3f3f3f3f;
vector<int> e[N];
bool vis[N];
int dep[N], fa[N];
int n, m, k;
void dfs(int u, int f, int d) {
dep[u] = d, fa[u] = f;
for (auto v : e[u]) {
if (!dep[v])
dfs(v, u, d + 1);
else {
int len = dep[u] - dep[v] + 1;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int maxB = 10;
int n, x, y, diff, first;
int main() {
cin >> n >> x >> y;
int piv = -1;
for (int i = 0; i < maxB; i++) {
vector<int> v;
for (int j = 1; j <= n; j++)
if (j >> i & 1) v.push_back(j);
if ((int)v.size() == 0) continue;
cout << "... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m;
cin >> n;
m = ceil(n / 2) + 1;
cout << m << endl;
for (long long i = 1; i <= m; i++)
cout << i << " "
<< "1" << endl;
for (long long i = 2; i <= n - m + 1; i++) cout << m << " " << i << endl;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
int main() {
int n;
string s;
cin >> n;
cin.ignore();
getline(cin, s);
int largest = 0;
int first;
int last = -1;
for (int i = 0; i < s.size(); i++)
if (s[i] == '.' || s[i] == '?' || s[i] == '!') {
while (s[last + 1]... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 50, M = (1 << 23) + 10;
int fa[N], sz[N];
int find_father(int x) {
if (x == fa[x]) return x;
return fa[x] = find_father(fa[x]);
}
void Merge(int x, int y) {
int f1 = find_father(x), f2 = find_father(y);
if (f1 == f2) return;
sz[f2] += sz[f1];
fa[f1... | 11 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pi = pair<ll, ll>;
const int mod = 1000000007;
const ll inf = 1e18;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxn = 1e5 + 55;
void norm(int &x) {
if (x < 0) x... | 9 |
#include <bits/stdc++.h>
using namespace std;
struct node {
double x, y;
} p[400010];
int n;
long long k;
double pf(double x) { return x * x; }
double dist(node a, node b) { return sqrt(pf(a.x - b.x) + pf(a.y - b.y)); }
double pi;
double angle[400010], agl[400010], ll[400010], rr[400010];
double sz[400010];
struct no... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100 + 5;
int a[maxn][maxn];
int main() {
int n, m, k;
scanf("%d%d%d", &n, &m, &k);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
scanf("%d", &a[i][j]);
}
}
int ans1 = 0, ans2 = 0;
for (int j = 0; j < m; j++) {
int... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long dp[55][55];
int main() {
int n, m, t;
cin >> n >> m >> t;
dp[0][0] = 1;
for (int i = 1; i <= 31; ++i)
for (int j = 1; j <= 31; ++j) dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j];
long long sol = 0;
for (int i = 4; i <= n; ++i)
for (int j = 1; j <=... | 3 |
#include <bits/stdc++.h>
long long dx[8] = {0, 1, 0, -1, 1, 1, -1, -1};
long long dy[8] = {1, 0, -1, 0, -1, 1, 1, -1};
using namespace std;
class pa3 {
public:
long long x;
long long y, z;
pa3(long long x = 0, long long y = 0, long long z = 0) : x(x), y(y), z(z) {}
bool operator<(const pa3 &p) const {
if (... | 5 |
#include <bits/stdc++.h>
using namespace std;
struct P {
int x, y;
void read() { scanf("%d%d", &x, &y); }
} p[100010];
struct Rec {
int x1, y1, x2, y2, z;
Rec() {}
Rec(P q) : x1(q.x), y1(q.y), x2(q.x), y2(q.y) {}
void read() { scanf("%d%d%d%d%d", &x1, &x2, &y1, &y2, &z); }
bool cover(Rec r) {
return x... | 8 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
struct frac {
T num, denom;
T gcd(T a, T b) {
while (b > 0) {
T t = b;
b = a % b;
a = t;
}
return a;
}
void simplify() {
if (denom < 0) {
num *= -1;
denom *= -1;
}
T gc = gcd(num, denom);
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, k, kol, ans;
string s;
char pred;
int main() {
cin >> n >> k;
cin >> s;
sort(s.begin(), s.end());
pred = 'a' - 2;
for (int i = 0; i < n; ++i) {
if (s[i] >= pred + 2) {
pred = s[i];
ans += s[i] - 'a' + 1;
kol++;
if (kol == k) {
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
const int n_ = 1e5 + 5;
int n, m, arr[n_], ans, cnt, need;
int main() {
scanf("%d %d", &n, &m);
for (int i = 0; i < m; i++) scanf("%d %d", &arr[i], &arr[i]);
sort(arr, arr + m, greater<int>());
for (; ans <= m + 1; ++ans) {
need = ans... | 6 |
#include <bits/stdc++.h>
int main() {
int n, x;
scanf("%d %d", &n, &x);
int e;
int l = 0;
int h = 0;
int s = 0;
for (int i = 0; i < n; ++i) {
scanf("%d ", &e);
if (e < x) {
++l;
} else if (e > x) {
++h;
} else {
++s;
}
}
int half = (n + 1) / 2;
if (l < half) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
struct TreeNode {
int val;
TreeNode* left;
TreeNode* right;
TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};
struct ListNode {
int val;
ListNode* next;
ListNode(int x) : val(x), next(NULL) {}
};
int nxt() {
int x;
cin >> x;
return x;
}
long long n... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n;
vector<int> v1, v2;
string str;
cin >> str;
for (int i = 0; i < 2 * n; i++) {
m = str[i] - '0';
if (i < n)
v1.push_back(m);
else
v2.push_back(m);
}
sort(v1.begin(), v1.end());
sort(v2.begin(), v2.end... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, z;
string s1, s2;
cin >> s1 >> s2;
cin >> n;
string s3, s4;
cout << s1 << ' ' << s2 << endl;
for (int i = 0; i < n; i++) {
cin >> s3 >> s4;
if (s3 == s1) {
s1 = s4;
cout << s1 << ' ' << s2 << endl;
} else {
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n;
void panduan(char c1, char c2) {
if (c1 == '^') {
if (c2 == '>') {
if (n % 4 == 1) {
printf("cw\n");
return;
} else if (n % 4 == 3) {
printf("ccw\n");
return;
}
} else if (c2 == '<') {
if (n % 4 == 3) ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int a[100009];
void solve() {
int n, m, k;
cin >> n >> m >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
if (k > m - 1) k = m - 1;
int Ans = 0;
for (int i = 0; i <= k; i++) {
int fr = i, ls = k - i;
int ans = 1e9;
for (int j = 0; j <= m - 1... | 4 |
#include <bits/stdc++.h>
using namespace std;
constexpr int64_t mod = 1e9 + 7;
constexpr int64_t mxn = 101;
int64_t d[mxn][mxn];
vector<int64_t> adj[mxn];
void dfs(int64_t u, int64_t p, int64_t l, int64_t r) {
d[r][l]++;
for (auto& v : adj[u]) {
if (v != p) {
dfs(v, u, l + 1, r);
}
}
}
int64_t dp[mx... | 7 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long add(long long x, long long y) {
x += y;
if (x >= mod) return x - mod;
return x;
}
long long sub(long long x, long long y) {
x -= y;
if (x < 0) return x + mod;
return x;
}
long long mult(long long x, long long y) { return ... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long d, k, a, b, t;
long long calc(long long num) {
long long all = d, used = 0;
all -= num * k;
used += num * (k * a + t);
long long car = min(k, all);
used += a * car;
all -= car;
return used + all * b;
}
int main() {
cin >> d >> k >> a >> b >> t;
l... | 5 |
#include <bits/stdc++.h>
using namespace std;
bool check(string s) {
string a[11] = {"ABSINTH", "BEER", "BRANDY", "CHAMPAGNE", "GIN", "RUM",
"SAKE", "TEQUILA", "VODKA", "WHISKEY", "WINE"};
for (int i = 0; i < 11; ++i) {
if (a[i] == s) return 1;
}
return 0;
}
int main() {
int c(0... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3010;
int n, m, ans, node[4];
vector<int> G[maxn];
int d[maxn][maxn];
bool vis[maxn];
pair<int, int> s[maxn][3], e[maxn][3];
void updateS(int u, int v) {
s[u][2] = s[u][1];
s[u][1] = s[u][0];
s[u][0] = make_pair(v, d[u][v]);
}
void updateE(int u, int ... | 6 |
#include <bits/stdc++.h>
using namespace std;
typedef struct practise2 {
int on, off;
} bulb;
int main() {
int n, m;
cin >> n >> m;
vector<int> v;
v.push_back(0);
for (int i = 0; i < n; i++) {
int x;
cin >> x;
v.push_back(x);
}
v.push_back(m);
int ans = 0;
vector<bulb> li(n + 5);
for (... | 3 |
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s;
int t;
cin>>t;
while(t--)
{
cin>>s;
int tot=s.size();
while(tot)
{
if(s[0]=='a'+tot-1)s.erase(0,1);
else if(s[tot-1]=='a'+tot-1)s.erase(tot-1,1);
tot--;
}
if(s=="")cout<<"YES\n";
else cout<<"NO\n";
}
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char str[5][5] = {{'a', 'e', 'i', 'o', 'u'},
{'e', 'i', 'o', 'u', 'a'},
{'i', 'o', 'u', 'a', 'e'},
{'o', 'u', 'a', 'e', 'i'},
{'u', 'a', 'e', 'i', 'o'}};
int l, n, m;
bool noP... | 1 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "unroll-loops", "omit-frame-pointer", "inline")
#pragma GCC option("arch=native", "tune=native", "no-zero-upper")
#pragma GCC target("avx2")
using namespace std;
template <typename T>
void maxtt(T &t1, T t2) {
t1 = max(t1, t2);
}
template <typename T>
void mintt(... | 12 |
#include <bits/stdc++.h>
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 5e1 + 5;
const double eps = 1e-9;
using namespace std;
int a[MAXN], w[MAXN][MAXN], dp[MAXN][MAXN][MAXN][MAXN];
int dfs(int i, int j, int l, int r) {
if (j > r || i + j - 1 < l || l > r) return dp[i]... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long global = 0;
void test_case(long long);
int main() {
clock_t begin, end;
begin = clock();
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long t;
int yes = 1;
if (yes)
cin >> t;
else
t = 1;
for (long long(T) = 0; (T) < t; (T)++) test... | 3 |
#include <bits/stdc++.h>
using namespace std;
inline int iseven(int x) { return x & 1 ? 0 : 1; }
inline bool is_double(double x) {
double y = x - (int)x;
return (y == x ? true : false);
}
int main() {
ios_base::sync_with_stdio(false);
int n;
cin >> n;
long long a[n];
for (int i = 0; i < n; i++) cin >> a[i... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
int i, n, k, a[500], b[500], c[500];
while (scanf("%d%d", &n, &k) != EOF) {
for (i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
int l, r, j, x, y;
int m = -200100;
for (l = 1; l <= n; l++) {
for (r = l; r <= n; r++) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 10;
const int maxf = 10000 + 10;
int ls[maxn * 60], rs[maxn * 60], rt[maxn * 60], tot;
long long sumv[maxn * 60];
void push_up(int n) { sumv[n] = sumv[ls[n]] + sumv[rs[n]]; }
void update(int p, int v, int l, int r, int& n) {
if (!n) n = ++tot;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d;
cin >> a >> b >> c >> d;
cout << max(abs(a - c), abs(b - d));
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
string a, b, c;
cin >> a;
cin >> b;
cin >> c;
int n = a.size();
bool ok = true;
int cont = 0;
bool tudo = false;
for (int i = 0; i <... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k;
char s[500011], t[500011], mod[500011 << 1];
int z1[500011 << 1], z2[500011 << 1], t1[500011], t2[500011];
vector<int> v1[500011], v2[500011];
template <class T>
struct BIT {
int c[500011], inf, n;
T op;
void init(int x = 0) {
inf = x;
for (int i ... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n, deg[8005], bl[8005], siz[8005];
bool g[8005][8005];
long long ans;
inline int get_val(char c) { return isdigit(c) ? c - '0' : 10 + c - 'A'; }
char s[8005];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%s", s + 1);
for (int j = 1, tm... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int x = 0;
while (n--) {
int c;
cin >> c;
x += c;
}
if (x < 0) x = -x;
if (x > m) {
if (x % m != 0)
cout << x / m + 1 << endl;
else
cout << x / m << endl;
} else if (x == 0)
cout << 0 ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int N, K, allP, a[5009], dp[5009][5009], coef[5009];
const int mod = 1e9 + 7;
int add(int x, int y) {
int ans = x + y;
if (ans >= mod) ans -= mod;
return ans;
}
int subtract(int x, int y) {
if (x >= y) return x - y;
return x - y + mod;
}
int mul(int x, int y) { re... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a;
auto mn = 0;
vector<int> p, pp;
map<int, int> m;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &a);
p.push_back(a);
m[a]++;
mn = max(mn, a);
}
cout << mn << " ";
int mx = 0;
for (int i = 0; i < p.size()... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string s;
cin >> s;
long long n = s.length();
vector<long long> primes;
set<long long> prime;
bool mark[n + 1];
memset(mark, 0, sizeof(mark));
for (long long i = 2; i <= n; i... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 55;
char a[N][N];
int x, y, cnt2;
bool was[N][N];
void dfs(int vx, int vy) {
was[vx][vy] = 1;
cnt2++;
for (int dx = -1; dx <= 1; dx++)
for (int dy = -1; dy <= 1; dy++) {
if (dx * dy == 0 && abs(dx + dy) == 1) {
if (a[vx + dx][vy + dy] =... | 4 |
#include<bits/stdc++.h>
#include<algorithm>
#include<cmath>
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
using namespace std;
#define deb(x) cout << #x << " " << x << endl
#define deb1(x,y) cout<<#x<<" "<<x<<" , "<<#y<<" "<<y<<endl
#define deb2(x,y,z) cout<<#x<<" "<<x<<" , "<<#y<<" "<<y<<" , "<<#z... | 1 |
#include <bits/stdc++.h>
const int MAXN = 4001;
int n, v[MAXN], p[MAXN], d[MAXN], state[MAXN], q[MAXN], answer[MAXN];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d%d%d", v + i, d + i, p + i);
state[i] = 1;
}
int counter = 0;
for (int i = 1; i <= n; i++) {
if (state[i] == 2... | 5 |
#include <bits/stdc++.h>
const long double eps = 1e-25;
int j, a, b, x, y, n;
long double min = 1e20, s;
void calc(int j, int i) {
if (j < 0) return;
s = fabs(static_cast<long double>(j) / i - static_cast<long double>(x) / y);
if (s < min - eps) {
min = s;
a = j;
b = i;
} else if (fabs(s - min) <= e... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int p = 1000000007;
struct matrix {
int a[105][105];
} b;
int tot, st, a[105], ans[105];
int read() {
char c = getchar();
int x = 0, f = 1;
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = x... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n, Pos;
long long a[500005], Out;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
long long x;
scanf("%I64d", &x);
while (Pos > 1 && a[Pos - 1] >= a[Pos] && a[Pos] <= x) {
Out += min(x, a[Pos - 1]);
Pos--;
}
a[++Pos] = x;... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long a[500006];
long long dp[500006];
long long vis[500006];
vector<long long> v[500006];
long long on;
long long n, d, che;
void dfs(long long root, long long parent) {
vis[root] = 1;
dp[root] = 1;
for (auto it : v[root]) {
if (!vis[it]) {
dfs(it, root... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
int cur = 0;
long long ans = 0;
for (auto(i) = (0); (i) < (n); (i)++) {
int asdf;
scanf("%d", &asdf);
ans += (abs(cur - asdf));
cur = asdf;
}
cout << ans << endl;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 7;
template <typename X>
inline X abs(const X &a) {
return a < 0 ? -a : a;
}
template <typename X>
inline X sqr(const X &a) {
return a * a;
}
bool rev(pair<long long int, long long int> &a,
pair<long long int, long long int> &b) ... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long MX = 22, INF = 1e16, INF2 = -1e12, D = 1e9 + 7;
long long n;
pair<long long, long long> mat[MX];
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
cin >> n;
for (long long i = 0; i < n; i++) {
cin >> mat[i].first;
mat[i... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long fast_pow(int a, int b) {
if (b == 0) return 1;
if (b % 2 == 1) return (fast_pow(a, b - 1) * a) % 1000000007;
long long tmp = fast_pow(a, b / 2);
return (tmp * tmp) % 1000000007;
}
long long upper_bound_power(int b) {
int tmp = 1, i = 0;
while (tmp <= b... | 1 |
#include <bits/stdc++.h>
using namespace std;
struct abc {
bool lr;
int coor, index, coor2;
};
bool comp(abc a, abc b) {
if (a.coor != b.coor) return a.coor < b.coor;
if (a.lr != b.lr) return a.lr < b.lr;
if (a.coor2 != b.coor2) return a.coor2 > b.coor2;
return a.index < b.index;
}
signed main() {
int n, ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1000001;
long long arr[MAXN];
long long idx[MAXN];
long long cnt = 0;
long long n, m;
signed main() {
ios::sync_with_stdio(false);
long long T;
cin >> T;
while (T--) {
cin >> n >> m;
cnt = 0;
for (long long i = 1; i <= n; i++) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void umax(T &a, T b) {
if (a < b) a = b;
}
template <class T>
inline void umin(T &a, T b) {
if (a > b) a = b;
}
template <class T>
inline T abs(T a) {
return a > 0 ? a : -a;
}
template <class T>
inline T gcd(T a, T b) {
return __gcd(a, b);
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int x, k = 0;
cin >> x;
if (x < 0) {
while (x < -360) {
x %= 360;
k = abs(x);
}
if (x < 0) {
k = x + 360;
}
} else if (x < 360)
k = x;
while (x > 360) {
x %= 360;
k = x;
}
if (k >= 315)
c... | 5 |
#include <bits/stdc++.h>
using namespace std;
int MyLog(int value) {
int res = 0;
int x = 1;
while (x <= value) {
x *= 2;
++res;
}
return res - 1;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
multiset<int> fishes[30];
int64_t sum[30] = {0};
int q;
cin >> q;
while (q--) {
... | 10 |
#include <bits/stdc++.h>
int mod = 1000000007;
int dp[510][510];
int dpb[510][510];
char a[510][510];
char b[1010][510];
int n, m;
int main() {
int i, j, k;
scanf("%d%d", &n, &m);
for (i = 0; i < n; i++) {
scanf("%s", &a[i]);
}
if (n < m) {
k = n;
n = m;
m = k;
for (i = 0; i < n; i++) {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T &a) {
T x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = (x << 1) + (x << 3) + (ch ^ 48);
ch = getchar();
}
a = x *... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(!cin.tie(0));
int t;
cin >> t;
while (t--) {
long long x, c = 0;
cin >> x;
for (long long s = 1;; s = 2 * s + 1) {
long long z = s * (s + 1) / 2;
if (z <= x) {
c++;
x -= z;
} else {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, m, q;
const int nax = 300005;
int par[nax];
int wynik[nax];
vector<int> e[nax];
int ans = 0;
int Find(int x) {
if (par[x] != x) par[x] = Find(par[x]);
return par[x];
}
void Union(int x, int y) {
x = Find(x);
y = Find(y);
if (x == y) return;
int xx = wynik... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, const char* argv[]) {
int cases;
cin >> cases;
while (cases--) {
int num;
scanf("%d", &num);
vector<pair<int, int> > coords;
pair<int, int> z(0, 0);
coords.push_back(z);
for (int i = 0; i < num; ++i) {
int x, y;
s... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long read() {
long long ret = 0;
char c = getchar();
while (c < '0' || c > '9') c = getchar();
while (c >= '0' && c <= '9') ret = ret * 10 + c - '0', c = getchar();
return ret;
}
int N, M, K;
long long a[55][20005], s[55][20005], dp[55][20005], ans, max1[55][... | 7 |
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define arin(x,n) for(int i=0;i<n;i++)cin>>x[i]
#define debug(x,n) for(int i=0;i<n;i++)cout<<x[i]<<" "
#define pb push_back
#define all(c) begin(c), end(c)
#define isAll(c) (int)(c).size()
typedef long long int ll;
using namesp... | 5 |
#include <bits/stdc++.h>
int n, d[100005], ans, f[100005], l[100005];
int main() {
int i, j;
while (~scanf("%d", &n)) {
ans = 1;
for (i = 1; i <= n; i++) scanf("%d", &d[i]);
for (i = 1; i <= n; i++) {
f[i] = i;
l[i] = i;
}
for (i = 2; i <= n; i++)
if (d[i] > d[i - 1]) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
if (a % b == 0) return b;
return gcd(b, a % b);
}
long long int poww(long long int a, long long int n) {
if (n == 0) return 1;
long long int p = poww(a, n / 2);
p = (p * p) % 1000000007;
if (n % 2) p = (a * p... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long Mod = 1e9 + 7;
int main() {
long long a, b;
cin >> a >> b;
long long ans = 0;
ans += (((((((a * (a + 1)) / 2) % Mod) * b) + a) % Mod) *
(((b * (b - 1)) / 2) % Mod)) %
Mod;
ans %= Mod;
cout << ans;
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
long long n, d, dp[569][569], ps[2][569][569], dv = 998244353;
int main() {
long long i, j, z = 0;
scanf("%lld%lld", &n, &d);
dp[0][0] = 1;
for (i = 0; i <= n; i++) {
ps[0][0][i] = 1;
}
for (i = 1; i <= n; i++) {
for (j = 1; j <= n; j++) {
if (j <=... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, sum = 0;
cin >> n;
bool isLR = false;
char a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] == 'L' || a[i] == 'R') isLR = true;
}
bool flag = false;
int count = 0;
for (int i = 0; i < n; i++) {
if (a[i] == '.' && fl... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long q, s, a, b, c, num, t;
scanf("%lld", &q);
while (q--) {
scanf("%lld %lld %lld %lld", &s, &a, &b, &c);
num = s / c;
t = num / a;
printf("%lld\n", num + (t * b));
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
string debug(long long x) {
if (x == 0) cout << 0;
stack<int> q;
while (x != 0) {
q.push(x % 2);
x /= 2;
}
while (!q.empty()) {
cout << q.top();
q.pop();
}
return "";
}
int cmp(int x, int y) {
if (x > y) return 1;
if (x < y) return -1;
re... | 6 |
#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];
}
int pos = 0;
while (a[pos] == 0) pos++;
int res = 0;
for (int i = pos; i < n; i++) {
res++;
int j = i + 1;
while (a[j] == 0 && j < n) j++;
if (... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, k;
cin >> n >> m >> k;
char p = (k % 2 == 0 ? 'R' : 'L');
int r = 1, c = 1, sum = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
sum += 2;
if (sum >= k) {
r = i;
c = j;
break;
}... | 0 |
#include <bits/stdc++.h>
using namespace std;
using ld = long double;
using ul = unsigned long long;
using db = double;
using pi = pair<int, int>;
using pl = pair<long long, long long>;
using pd = pair<ld, ld>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<long long>>;
using vi = vector<int>;
using vb = ve... | 10 |
#include <bits/stdc++.h>
int main() {
std::ios::sync_with_stdio(0);
std::cin.tie(0);
int number;
std::cin >> number;
std::vector<unsigned> values(number);
for (auto& it : values) std::cin >> it;
int result = 0;
for (int bit = 0; bit < 27; ++bit) {
auto modded = values;
auto const mod = 1u << (bi... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
int n, m, sz[N], dp[2][N];
map<string, int> mp;
int main(void) {
string str;
cin >> str;
vector<string> v;
dp[0][str.size() - 1] = 1, dp[1][str.size() - 1] = 1;
for (int i = str.size() - 3; i >= 6; i--) {
string p = "", p1 = "", p2 = "", ... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long n, m;
char a[1000003];
char b[1000003];
int ca[1000003][26];
int cb[1000003][26];
int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }
int main() {
int i, j;
cin >> n >> m;
scanf("%s%s", a, b);
int lena = strlen(a);
int lenb = strlen(b);
int gcdd =... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
int tot = 0, ans = -1;
string lx, Ans;
struct op {
int l, r;
char ch;
};
set<string> all;
set<int> pd;
vector<string> ot;
vector<op> pt;
map<int, string> mk, to;
map<string, int> ys;
map<pair<pair<int, int>, char>, int> ds;
string zh(int x) {
strin... | 9 |
#include <bits/stdc++.h>
using ll = long long;
int const N = 1e3 + 5;
int const K = 504;
ll dp[K][K][3];
ll binom[N][N];
ll fact[N];
ll res[N];
ll atres[N];
int n, k;
int const P = 1e9 + 7;
void calc_bin(int n) {
for (int i = 0; i <= n; i++) {
binom[i][0] = 1;
for (int j = 1; j <= i; j++) {
binom[i][j] ... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long max(long long a, long long b) {
if (a >= b)
return a;
else
return b;
}
long long min(long long a, long long b) {
if (a <= b)
return a;
else
return b;
}
long long diff(long long a, long long b) {
if (a >= b)
return a - b;
else
re... | 3 |
#include <bits/stdc++.h>
using namespace std;
int vf[10000];
string s1, s2, s3;
int main() {
cin >> s1 >> s2;
for (int i = 0; i < s1.size(); i++) {
vf[s1[i]] = i;
vf[s1[i] - 'a' + 'A'] = i;
}
cin >> s3;
for (int i = 0; i < s3.size(); i++) {
if (s3[i] >= 'A' && s3[i] <= 'Z') {
cout << (char)(... | 0 |
#include <bits/stdc++.h>
using namespace std;
string a, ans, jie;
int la, lh, lq, h, q, lans, wei[1000001];
int main() {
cin >> a;
la = a.size();
for (int i = 0; i < la; i++) {
if (a[i] == 'H')
lh++;
else {
lq++;
wei[lq] = i;
}
}
q = sqrt(lq);
if (q * q != lq) {
cout << "No... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string a, b;
cin >> a >> b;
int n, l = 26, inf = (int)1e9;
cin >> n;
int w[l][l];
for (int i = 0; i < l; i++) {
for (int j = 0; j < l; j++) w[i][j] = inf;
w[i][i] = 0;
}
while (n--) {
char a, b;
int cost;
cin >> a >> b >> cos... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, x;
cin >> n >> x;
int odd[n + 1], even[n + 1], k = 0, l = 0;
for (int i = 0; i < n; i++) {
int f;
cin >> f;
if (f % 2 == 0) {
even[k] = f;
k++;
} else {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, f = 1, c = getchar();
while (!isdigit(c)) {
if (c == '-') f = -1;
c = getchar();
}
while (isdigit(c)) {
x = (x << 1) + (x << 3) + (c ^ 48);
c = getchar();
}
return f == 1 ? x : -x;
}
const int N = 2e5 + 4;
int n, Q,... | 13 |
#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 2e3 + 10;
const long long INF = 1e12 + 10;
long long a[MAXN];
long long dp[MAXN];
long long n, k;
long long f(long long t) {
long long res = 0;
for (long long i = 1; i <= n; i++) {
dp[i] = 1;
for (long long j = i - 1; j >= 1; j--) {
... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int Inf = 0x3f3f3f3f;
int N, fav[303][303], pfav[303], choose[303][303], pr[303];
int main() {
cin >> N;
for (int i = 0; i < N; ++i)
for (int j = 0; j < N; ++j) {
cin >> fav[i][j];
--fav[i][j];
}
for (int i = 0; i < N; ++i) {
cin >> pfav[... | 5 |
#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;
if (n % 2 == 0) {
cout << n / 2;
return 0;
}
long long int d;
d = n;
long long int sq = sqrt(n);
for (long long int i = 3; i <= sq; i++) {
... | 2 |
#include <bits/stdc++.h>
int main() {
int m, n, i, c, d, j, store = 0, res = 0;
scanf("%d%d", &m, &n);
int a[m];
for (i = 0; i < m; i++) {
scanf("%d", &a[i]);
}
for (i = 0; i < n; i++) {
store = 0;
scanf("%d%d", &c, &d);
for (j = c - 1; j < d; j++) {
store = store + a[j];
}
if ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
int lVote;
cin >> n;
priority_queue<int> M;
for (int i = 0; i < n; i++) {
if (i == 0) {
cin >> lVote;
continue;
}
int temp;
cin >> temp;
M.push(temp);
}
int answer = 0;
while (!M.empty()) {
int a = M.to... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int lw[110], rw[110], ls[110], rs[110];
memset(lw, 0, sizeof(lw));
memset(rw, 0, sizeof(rw));
memset(ls, 0, sizeof(ls));
memset(rs, 0, sizeof(rs));
int n, m;
scanf("%d%d", &n, &m);
int k = 1;
int i = 0;
for (; k <= m; k++) {
lw[i] = k;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const double EPS = 1e-9;
const long long MOD = (long long)(1e9 + 7);
const long long MAXV = (long long)(2e5 + 10);
const long long MAXE = (long long)(1e6 + 10);
long long seg[MAXV * 4];
long long lazy[MAXV * 4];
long long A[MAXV * 4];
void build(... | 5 |
#include <bits/stdc++.h>
using namespace std;
bool checker(vector<pair<int, int>> x, vector<pair<int, int>> z, int t) {
for (int i = 0; i < (int)z.size(); i++) {
for (int j = 0; j < (int)x.size(); j++) {
int tempzf = z[i].first + t;
int tempzs = z[i].second + t;
if (tempzf <= x[j].second && x[j]... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int oo = 100;
int i, j, k, n, m, s, t, ans;
char c[100005];
int a[100005];
int stk[100005];
int Min[100005];
int top;
int main() {
scanf("%s", c + 1);
n = strlen(c + 1);
for (int i = 1; i <= n; i++) a[i] = c[i] - 'a';
Min[n] = oo;
for (int i = n - 1; i >= 1;... | 4 |
#include <bits/stdc++.h>
using namespace std;
int a, b, c;
int main() {
cin >> a >> b >> c;
if (!c)
puts(a == b ? "YES" : "NO");
else if (c > 0)
puts(a > b || (b - a) % c ? "NO" : "YES");
else
puts(b > a || (a - b) % c ? "NO" : "YES");
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int p[3005];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, i, j, z = 0;
cin >> n;
for (i = 0; i < n; i++) cin >> p[i];
for (i = 0; i < n; i++)
for (j = i + 1; j < n; j++)
if (p[i] > p[j]) z++;
cout << z * 2 - z % 2;
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
long long n;
set<long long> S;
int main() {
int n;
cin >> n;
int ans;
for (long long i = 1; i * i <= n; i++) {
if (n % i == 0) {
long long a = n / i;
long long b = a + a * (a - 1) / 2 * i;
S.insert(b);
long long k = n / i;
a = n / k... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f, maxn = 200007;
const long long MOD = 1004535809;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long P = 19260817;
char nc() {
static char buf[100000], *p1 = buf, *p2 = buf;
return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000,... | 2 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.