solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const int N = 200007;
const int inf = 1e9 + 7;
std::vector<int> adj[N];
int n;
long long lt[N];
long long L[N];
long long R[N];
map<int, pair<int, int>> dp[N];
int d[N];
int nxt[N], f[N];
int num[N];
int mxDepth[N];
int st[N], top;
pair<int, int> calc(int h) {
L[0... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <int mod>
class INT {
public:
template <class P1, class P2>
static P1 ppow(P1 a, P2 b) {
P1 res = 1LL;
while (b) {
if ((b & 1LL)) {
res *= a;
}
a *= a;
b >>= 1;
}
return res;
}
long long int NUM;
INT(long l... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, m = 0, k = 0;
int main() {
cin >> n;
while (m <= n) {
k = k + 1;
m = (k * (k + 1) / 2) + m;
}
cout << k - 1 << endl;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l, int r) { return l + rng() % (r - l + 1); }
int pr[18] = {2, 3, 5, 7, 11, 13, 17, 19, 23,
29, 31, 37, 41, 43, 47, 53, 59, 61};
int f[110][(1 << 17) + 3], p[110], b[110][(1 <... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int cr = 0, cl = 0, j = 0;
string ch, w;
cin >> ch;
int req = ch.length();
for (int i = 0; s[i] != '|'; i++) {
cr++;
}
string st = s.substr(0, cr);
for (int i = cr + 1; i < s.length(); i++) {
cl++;
}
string st... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long h, line[40];
bool use[100010];
int ntc, nQuery, k, nLine;
struct TreasureCell {
long long id;
int value;
bool Can;
} cell[100010];
struct Node_Graph {
long long dis;
int id;
friend bool operator<(const Node_Graph &a, const Node_Graph &b) {
return a... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, a[100005], cntA, cntB;
int Alice[100005], Bob[100005];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
for (int i = 1; i <= n; i++) {
Alice[i] = Alice[i - 1] + a[i];
}
for (int i = n; i >= 1; i--) {
Bob[i] = Bob[i + 1]... | 3 |
#include <iostream>
using namespace std;
int f(int x){
return x*x;
}
int main(void){
int d;
while(cin >> d){
int s=0;
for(int i=0;i<600;i+=d){
s += f(i)*d;
}
cout << s <<"\n";
}
return 0;
} | 0 |
#include<iostream>
#include<queue>
using namespace std;
queue<int>Q[3]; int p, q;
void solve(int a) {
for (int i = 0; i < 1000; i++) {
if (Q[i % 2].size() < a) {
while (!Q[i % 2].empty()) { Q[2].push(Q[i % 2].front()); Q[i % 2].pop(); }
}
else {
for (int j = 0; j < a;j++){ Q[2].push(Q[i % 2].front()); Q[i ... | 0 |
#include<bits/stdc++.h>
using namespace std;
bool ok(int i, string s1, string s2)
{
for (int j = 0; j < s2.size(); j++)
if (s1[i+j] != s2[j])
return false;
return true;
}
int main()
{
string s1, s2; cin >> s1 >> s2;
for (int i = 0; i < s1.size(); i++) {
if (ok(i, s1, s2))
cout << i << endl... | 0 |
#include "bits/stdc++.h"
using namespace std;
int main() {
string s;
cin >> s;
vector< int> v(26, 0);
for (char c : s) v[c - 'a'] ^= 1;
if (accumulate(v.begin(), v.end(), 0)) puts("No");
else puts("Yes");
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
int n;
cin >> n;
string s;
cin >> s;
bool found = false;
for (int len = 1; len <= s.length() / 4; len++) {
for (int start = 0; start + 4 * len < s.length(); start++) {
bool poss = true;
for (int kk = 0; kk <= 4; kk++) {
i... | 1 |
#include<bits/stdc++.h>
using namespace std;
int dist[105],n,m,a,b,c,d;
priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > Q;
vector<pair<int,int> >x[105];
void add_edge(int a1,int a2,int a3){
x[a1].push_back(make_pair(a2,a3));
x[a2].push_back(make_pair(a1,a3));
}
int solve(int b1,int... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
struct node {
int k, a;
int num;
} lcm[N];
int n;
int cmp(struct node a, struct node b) { return a.k < b.k; }
int main() {
int i;
while (scanf("%d", &n) != EOF) {
for (i = 1; i <= n; i++) {
scanf("%d%d", &lcm[i].k, &lcm[i].a);
l... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000 + 86;
struct card {
long long t, y;
card(int _t = 0, long long _y = 0) : t(_t), y(_y) {}
bool operator<(const card &a) const {
if (t != a.t) return t < a.t;
return y < a.y;
}
void read() {
char s[5];
cin >> s >> y;
t = !... | 2 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void pv(T a, T b) {
for (T i = a; i != b; ++i) cout << *i << " ";
cout << endl;
}
const int mod = 1e9 + 7;
long long bin[555][555];
long long g[555];
int n, k;
long long f[333][333];
long long f2[333][333];
long long go2(int turn, int ja) {
if (turn... | 5 |
#include<iostream>
using namespace std;
int main(){
int a,b;
char op;
while(true){
cin >> a >> op >> b;
if(op == '+') {
cout << a+b<<endl;} else if(op == '-') {
cout << a-b<<endl;} else if(op == '*') {
cout << a*b<<endl;} else if(op == '/') {
cout << a/b<<endl;} else {break;}
}
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
double N;
int T;
cin >> N >> T;
double A = 1.000000011;
while (T) {
if (T & 1) N *= A;
T >>= 1;
A *= A;
}
cout << fixed << setprecision(16) << N << endl;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
inline void wait(double seconds) {
double endtime = clock() + (seconds * CLOCKS_PER_SEC);
while (clock() < endtime) {
;
}
}
template <class T>
inline T fastIn() {
register char c = 0;
register T a = 0;
bool neg = false;
while (c < 33) c = getchar();
whil... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long x[200005];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
long long n;
cin >> n;
map<long long, long long> m;
long long mx = 0;
for (long long i = 0; i < n; i++) {
cin >> x[i];
m[x[i]] = i + 1;
mx = max(mx, x[i]);
}
sort(x, x +... | 4 |
#include <bits/stdc++.h>
using namespace std;
void Print() { cout << endl; }
template <typename T1, typename... T>
void Print(const T1 &t1, const T &...t) {
cout << t1 << " ";
Print(t...);
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
os << "(" << p.first << ", " ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int M = 500 + 10;
int a[M][M];
int pre[M][M];
int numinrow[M];
int rsum[M][M];
int premax[M][M];
int prenum[M][M];
int sufmax[M][M];
int sufnum[M][M];
int dis[2 * M];
int main() {
time_t t_start, t_end;
t_start = clock();
int n, m;
cin >> n >> m;
int r;
ci... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
const int maxn = 1000000 + 5;
int n, ch[maxn][2], ans[maxn], a[maxn];
char tp[maxn];
int dfs(int u) {
if (tp[u] == 'I') return a[u];
if (tp[u] == 'N') return a[u] = (dfs(ch[u][0]) ^ 1);
if (tp[u] == 'A') return a[u] = (dfs(ch[u][0]) & dfs(ch... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long LINF = 2e16;
const long long INF = 2e9;
const long long magic = 348;
const double eps = 1e-10;
const double pi = acos(-1);
inline long long getint() {
char ch;
long long res;
bool f;
while (!isdigit(ch = getchar()) && c... | 5 |
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=200010;
char s[N];
int nxt[N];
LL l,r;
LL f[100][27];
LL sum[100],ans[27];
int mx=90;
void getnext()
{
int n=strlen(s+1)/2,j=0;
for(int i=2;i<=n;i++)
{
while(j&&s[i]!=s[j+1]) j=nxt[j];
if(s[i]==s[j+1]) j++;
nxt[i]=j;
}
}
void in... | 0 |
#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];
sort(a, a + n);
vector<int> vec;
vec.push_back(a[0]);
map<int, int> cnt;
for (int i = 1; i < n; i++)
if (a[i] != a[i - 1]) vec.push_back(a[i]);
for (int i = 0; i < n; i+... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5 * 1e5 + 10;
long long INF = 1e9 + 10;
long long MOD = 998244353;
int n;
int a[MAXN];
void add(int x) {
for (int i = 2; i <= x && i * x <= n; i++) a[x * i] = max(a[x * i], x);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
... | 6 |
#include <bits/stdc++.h>
using namespace std;
bool app[1005];
map<int, int> vis;
int main() {
int n, k;
scanf("%d%d", &n, &k);
for (int i = 0; i < k; i++) {
int x;
scanf("%d", &x);
app[x] = true;
}
queue<int> que;
que.push(0);
while (!que.empty()) {
int u = que.front();
que.pop();
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n;
const int MAXN = 2e5 + 10;
struct node {
int u;
int v, next;
long long w, s;
} e[MAXN << 1];
int head[MAXN];
int tot;
void addedge(int u, int v, int w, int p) {
e[tot].u = u;
e[tot].v = v;
e[tot].s = p;
e[tot].w = w;
e[tot].next = head[u];
head[u] =... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
long a, x, y;
cin >> a;
if (a % 2 == 0) {
x = 4;
y = a - x;
cout << x << " " << y << endl;
} else {
x = 9;
y = a - x;
cout << x << " " << y << endl;
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
struct Node {
int l, r;
int loA, hiB;
bool good;
};
Node seg[1000000];
int N, M, Q;
set<int> stA[200005], stB[200005];
set<pair<int, int>> st;
void build(int l, int r, int idx) {
seg[idx].good = 1;
seg[idx].l = l;
seg[idx].r = r;
seg[idx].hiB = 1e9;
if (l ==... | 6 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void pp(T v) {
for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); ++it)
cout << *it << ' ';
cout << endl;
}
template <class T>
void pp(T v, int n) {
for (int i = 0; i < (int)n; i++) cout << v[i] << ' ';
cout << endl;
}
template <cla... | 3 |
#include <bits/stdc++.h>
const int MN = 1e3 + 10;
const int K = 20;
int N, M, T, id[MN], t[MN], ctr, m[1 << K];
bool conn[MN][MN];
char s[10];
std::vector<int> a[MN], on[K + 1];
struct Mod {
public:
char c;
int a, b;
void out() const { printf("%c %d %d\n", c, a, b); }
};
std::vector<Mod> f;
void flip(int a, int ... | 6 |
#include <bits/stdc++.h>
int dx[] = {0, -1, 0, 1, -1, 1, -1, 1};
int dy[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int N = 2e5 + 5, mod = 1e9 + 7;
using namespace std;
vector<int> g[N];
map<pair<int, int>, int> adj;
int r, w, ans;
pair<int, int> arr[N];
void dfs(int node, int par) {
for (auto child : g[node]) {
if (c... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long n, r, avg, sum, x, y, ans, m;
int main() {
cin >> n >> r >> avg;
vector<pair<long long, long long> > a;
for (int i = 0; i < n; i++) cin >> x >> y, a.push_back({y, x}), sum += x;
sort(a.begin(), a.end());
for (int i = 0; i < n; i++) swap(a[i].second, a[i]... | 3 |
#include <bits/stdc++.h>
using namespace std;
double t[1000005];
double dp[205][205][405];
int C = 400;
double p[10005];
int a[10005];
int main() {
int n, x, y, d, m, k, i, j;
scanf("%d%d%d", &n, &m, &k);
dp[0][0][k + C] = 1;
for (i = 1; i <= n; i++) {
scanf("%lf", &p[i - 1]);
p[i - 1] /= 100;
}
for... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = (long long)(1e9 + 17);
const long long mod = (long long)(1e9 + 7);
int n, k;
string s, t;
int dp[201][201][201];
int recurse(int idx, int tot, int ct) {
if (tot > k) {
return -inf;
}
if (idx == n) {
if (tot > k) return -inf;
return 0;... | 6 |
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include... | 0 |
#include <bits/stdc++.h>
int a[100000];
using namespace std;
int main() {
int n, c, j = 0;
cin >> n >> c;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] - a[i - 1] <= c) {
j++;
} else
j = 1;
}
cout << j;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
void init_ios() {
ios_base::sync_with_stdio(0);
cin.tie(0);
}
int ile[30], x;
int main() {
init_ios();
int n;
string a;
cin >> n >> a;
for (int i = 0; i < n; ++i) {
if (a[i] >= 'A' && a[i] <= 'Z')
x = a[i] - 'A';
else
x = a[i] - 'a';
++... | 1 |
#include <bits/stdc++.h>
using namespace std;
class compare {
public:
bool operator()(pair<long long, long long> a, pair<long long, long long> b) {
if (a.first > b.first) return true;
return false;
}
};
bool comp(long long a, long long b) { return a > b; }
long long power(long long a, long long b) {
long... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, m, z, x, y, o, w;
unsigned int f[2][100005];
char s[100005];
int main() {
scanf("%d\n", &n);
scanf("%s", s + 1);
f[0][0] = 1;
for (int i = 1; i <= n; ++i) {
o = i & 1;
w = (i + 1) & 1;
x = min(i, n - i);
if (o == 0)
y = 2;
else
... | 5 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const long double eps = 1e-7;
const int inf = 1000000010;
const long long INF = 10000000000000010LL;
const int mod = 1000000007;
... | 4 |
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<string, string> P;
const ll MOD = 1000000007LL;
ll sum_r[100001];
int main() {
int N;
cin >> N;
vector<int> vl, vr;
for (int i = 0; i < N; i++) {
int L, R;
cin >> L >> R;
vl.push_back(L * 2);
vr.push_back(-R * 2);
}
sort(vl.r... | 0 |
#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 (... | 4 |
#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;
int MOD = 1e9 + 7;
const int N = 500000;
int parent[N];
int rnk[N];
list<pair<int, int> > gr2[N];
void make_set(int v, vector<pair<int, int> > a) ... | 5 |
#include "bits/stdc++.h"
using ll = long long;
using namespace std;
int main() {
cin.tie(0);
cin.sync_with_stdio(0);
int t;
cin >> t;
while(t--) {
ll n;
cin >> n;
auto m = n;
// prime factor
vector<pair<int, ll>> primes;
for(ll i = 2; i * i <= n; ++i) {
int cnt = 0;
wh... | 4 |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("B.in");
ofstream fout("B.out");
vector<pair<int, int> > v;
int n, m;
int t[5001], r[5001], l[5001], mm[5001], d[5001], a[5001];
int main() {
cin >> n >> m;
for (int i = 1; i <= n; ++i) a[i] = 100000000;
for (int i = 1; i <= m; ++i) {
cin >> t[i] >> l... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, k;
cin >> n >> m >> k;
vector<vector<int> > a;
vector<int> v, u;
a.resize(n + 1);
v.resize(n + 1);
u.resize(m + 1);
for (int i = 1; i <= n; ++i) {
a[i].resize(m + 1);
for (int j = 1; j <= m; ++j) {
cin >> a[i][j];
}
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long bin(long long a, long long b) {
if (b == 0) return 1;
if (b & 1) return (a * bin((a * a) % mod, b / 2)) % mod;
return (1 * bin((a * a) % mod, b / 2)) % mod;
}
void I_m_Beast() {
int n, a;
cin >> n;
int A[n + 1];
for (in... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<pair<long long, long long> > m;
long long a, b;
for (int i = 0; i < n; i++) {
cin >> a >> b;
m.push_back(make_pair(a, b));
}
sort(m.begin(), m.end());
long long p[n];
p[0] = m[0].second;
for (long i = 1; i < n... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 5000;
int p[maxN];
int used[maxN];
pair<int, int> x[maxN];
int pr[maxN];
pair<int, int> print_max_pair(set<pair<int, int>>& rems) {
auto tp = *rems.begin();
rems.erase(rems.begin());
if (p[tp.first] > p[tp.second]) {
cout << tp.first + 1 << endl;
... | 3 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll md=1e9+7;
ll pl(int x,int y){//Axy
if(y==0)
return 1;
ll ans=1;
for(ll i=1;i<=y;i++){
ans*=(x-i+1);
ans%=md;
}
return ans%md;
}
int main(){
ll n,m;
cin>>n>>m;
ll a,b;
a=max(n,m);
b=min(n,m);
if(b<a-1){
cout<<"0"<<endl;
return 0;
}
... | 0 |
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n;i++)
using namespace std;
using ll = long long;
#define int ll
int INF=1000000000000000;
signed main(){
int n; cin>>n;
vector<vector<int>>d(n,vector<int>(n,INF));
rep(i,n)rep(j,n){
int cost; cin>>cost;
d[i][j]=cost;
}
rep(k,n)... | 0 |
#include <iostream>
#include <vector>
using namespace std;
const int ma = 1e7;
int main()
{
vector< bool > is_prime(ma,1);
is_prime[0] = is_prime[1] = 0;
for( int i = 0; i < ma; i++ )
{
if( is_prime[i] )
{
for( int j = 2; i*j < ma; j++ )
{
is_prime... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 7;
int n, dp[N], l, r;
struct node {
int v, tp;
} a[N];
int main() {
ios::sync_with_stdio(false);
cin >> n >> l >> r;
int sum = 0;
for (int i = 1; i <= n; i++) cin >> a[i].v, sum += a[i].v;
for (int i = 1; i <= n; i++) cin >> a[i].tp;
sort(... | 5 |
#include <bits/stdc++.h>
using namespace std;
int prime[1000000];
vector<int> pr;
void calculateprime() {
prime[0] = prime[1] = 1;
for (int i = 2; i <= 1000000; i++) {
if (prime[i] == 0) {
pr.push_back(i);
for (long long j = i * 2; j <= 1000000; j += i) {
prime[j] = 1;
}
}
}
}
vo... | 4 |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
const ll MOD = 1e9 + 7;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--){
ll attack, health, n;
cin>>attack>>health>>n;
pair<l... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e4;
int n, m;
string s;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> s >> m;
n = ((int(s.size())));
for (int i = 0; i < m; i++) {
int l, r, k, x;
char t[MAXN + 5];
cin >> l >> r >> k;
l--, x = r... | 2 |
#include <bits/stdc++.h>
using namespace std;
char s[7][1001], *p;
int main() {
int n, i;
cin >> n;
for (i = 1; i <= n; i++) {
cin >> s[1] >> s[2];
if (strcmp(s[2], "rat") == 0) {
strcat(s[3], s[1]);
strcat(s[3], " ");
} else if (strcmp(s[2], "woman") == 0 || strcmp(s[2], "child") == 0) {
... | 1 |
#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 << " " << to_string(H);
debug_out(T...);
}
long long modPow(long long a, long long b) {
long long res = 1;
a %= 998244353;
assert(b >= 0);
for ... | 5 |
#include <bits/stdc++.h>
using namespace std;
class trio {
public:
long long first, second, third;
};
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
long long n, k;
cin >> n >> k;
string second;
cin >> second;
long long a[n + 2][2];
memset(a, 0, sizeof(a));
... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long ha = 1000000000 + 7;
long long n = 1, a[100004], k;
long long pow2(long long a, long long b) {
long long ans = 1, base = a, h = b;
base %= ha;
while (h) {
if (h & 1) ans = ans * base % ha;
h >>= 1;
base = base * base % ha;
}
return ans;
}
int... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const double PI = 3.14159265359;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<vector<int>> graph(n + 1);
while (m--) {
int x, y;
cin >> x >> y;
graph[x].push_back(y);
graph[y].pus... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e6 + 10;
struct order {
long long num, a, b;
} f[maxn];
bool cmp(order x, order y) {
if (x.b != y.b) return x.b < y.b;
return x.a > y.a;
}
map<long long, long long> ms;
priority_queue<long long, vector<long long>, greater<long long>> st;
int main() {... | 3 |
#include <iostream>
struct Vec {
double x;
double y;
double operator*(Vec& vec)
{
return (x * vec.y - y * vec.x);
}
};
int sgn(double x);
int main()
{
double x1, y1, x2, y2, x3, y3, x4, y4;
char ch;
while (std::cin >> x1 >> ch >> y1 >> ch >> x2 >> ch >> y2 >> ch
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e09 + 5e3;
const long long linf = 2e18 + 5e3;
const int mxn = 1e5;
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int n;
long long a[mxn + 5];
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
long long out = 0;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
void ga(int N, int *A) {
for (int i(0); i < N; i++) scanf("%d", A + i);
}
int X[(1 << 18)] = {-1}, C[(1 << 18)], N, Q, a;
bool tst(int I) {
int S = N, J = N + 1;
while (S) {
J = X[J - 1];
if (J <= I && I < S) {
S -= I, I = -6, ++J;
continue;
}
... | 5 |
#include <bits/stdc++.h>
using namespace std;
inline int readint() {
int a = 0, c = getchar(), f = 1;
for (; '0' > c || c > '9'; c = getchar())
if (c == '-') f = -f;
for (; '0' <= c && c <= '9'; c = getchar())
a = (a << 3) + (a << 1) + (c ^ 48);
return a * f;
}
void writeUnsigned(const unsigned &x) {
... | 1 |
#include <bits/stdc++.h>
const unsigned long long P = 239017, MaxN = 2100000, INF = 100000000;
using namespace std;
bool f;
vector<int> ans;
int m[501][501], n, m1, clr[501], used[501], have[101][101];
void dfs(int v, int c) {
if (f) return;
used[v] = 1;
clr[v] = c;
for (int i = 1; i <= n && !f; ++i) {
if (... | 5 |
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define str string
typedef vector <bool> vb;
typedef vector <ll> vll;
typedef vector <vector<ll>> vvll;
typedef vector <ld> vld;
typedef vector <str> vs;
typedef vector <char> vc;
#define fastio ios_base:... | 1 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
T sqr(T x) {
return x * x;
}
template <typename T>
T abs(T x) {
return x < 0 ? -x : x;
}
template <typename T>
T gcd(T a, T b) {
return b ? gcd(b, a % b) : a;
}
const int MOD = (int)1e+9 + 7;
void addmod(int& x, int d) {
x += d;
if (x >= MOD)... | 6 |
#include <iostream>
using namespace std;
void func(int a){
}
int main(){
int n,a[10];
cin>>n;
int x=1,y=1;
for (int i=0; i<n; i++){
cin>>a[i];
x*=3;
if(a[i]%2==0)y*=2;
}
cout<<x-y<<endl;
return 0;
} | 0 |
#include <bits/stdc++.h>
int n,
ans[] = {0, 1, 0, 18, 0, 1800, 0, 670320, 0,
734832000, 0, 890786230, 0, 695720788, 0, 150347555, 0};
int main() {
scanf("%d", &n);
printf("%d\n", ans[n]);
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
int t, n;
int x[100010], y[100010], total[100010], ans[10];
pair<int, int> vet[100010];
void solve(int b) {
int mn, mx;
mn = mx = vet[0].second;
total[mn] += 2;
for (int i = 1; i < n; i++) {
if (vet[i].first != vet[i - 1].first) {
total[mn]--;
total[... | 5 |
#include <bits/stdc++.h>
using namespace std;
unsigned long long t;
int main() {
const int INF = 2147483647;
cin >> t;
for (unsigned long long i = 0; i < t; ++i) {
unsigned long long n, x;
cin >> n >> x;
cout << 2 * x << endl;
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int inf = 1e8;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, k;
cin >> n >> k;
vector<int> a(n);
long long ans = 0;
int l = 0;
map<vector<pair<int, int> >, int> mp;
for (int i = 0; i < n; i++) {
cin >> a[i];
vector<pair<in... | 4 |
#include <bits/stdc++.h>
using namespace std;
struct debugger {
template <typename T>
debugger &operator,(const T &v) {
cerr << v << " ";
return *this;
}
} dbg;
template <typename T>
istream &operator>>(istream &input, vector<T> &arr) {
for (auto &e : arr) {
input >> e;
}
return input;
}
templat... | 3 |
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<map>
#define N 200005
#define M 1000005
using namespace std;
int n,tep[30],Cnt[30];
int Length[N],id[N];
int tree[M][27],siz[M];
int num[M][27],cnt=1;
long long ans;
string input[N];
map<string,int> inputnum;
inline void solve(string inp... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main ()
{
double n,m,d;
cin >> n >>m >> d;
if (d == 0) cout << fixed << setprecision(12) << (m-1)*(n-d)/n/n << endl;
else cout << fixed << setprecision(12) << (m-1)*2*(n-d)/n/n << endl;
}
| 0 |
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;
int main() {
int it = 0;
int n;
string str; int a, b, c;
while (cin >> n) {
if (n == 0) break;
if (it++ != 0) cout << endl;
vector< pair<pair<int, int>, string> > data(n);
for (i... | 0 |
#include <bits/stdc++.h>
using namespace std;
map<int, int> dic[160010];
int a[410][410], dp[410][410];
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) scanf("%d", &a[i][j]);
for (int i = 1; i <= m; i++)
for (int j = 1; j <= m; j++) dp[i][j] = 1;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
char a[2005];
cin >> n;
cin >> a;
int ans = 0;
int l = strlen(a);
for (int i = 0; i < l; i += n) {
if (i >= 4) {
if (a[i - 1] == a[i - 2] && a[i - 2] == a[i - 3]) {
ans++;
}
}
}
cout << ans << endl;
}
| 1 |
#include <bits/stdc++.h>
int main() {
long long n, i, j = 0, x = 1;
scanf("%lld", &n);
for (i = 1, j = 1; i < n; i++, j++) {
x += j;
if (x > n) {
x = x % n;
printf("%lld ", x);
} else
printf("%lld ", x);
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int N = 5 * 1e5 + 1;
int t[3 * N];
int b[N];
pair<long long, int> a[N];
pair<long long, int> qi[N];
void build(int v, int tl, int tr) {
if (tl == tr)
t[v] = b[tl];
else {
int tm = (tl + tr) / 2;
build(v * 2, tl, tm);
buil... | 4 |
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
int n,m,a;
long long ans;
priority_queue<int> qu;
int main(){
scanf("%d%d", &n, &m);
rep(i,n){
scanf("%d", &a);
qu.push(a);
}
rep(i,m){
a = qu.top(); qu.pop();
qu.push(a/2);
}
while(!qu.empty()){
ans += qu.top(); qu.p... | 0 |
#include <bits/stdc++.h>
using namespace std;
int prime[16252330], cnt;
bitset<300000010> vis;
void init(int n) {
for (int i = 2; i <= n; i++) {
if (!vis[i]) {
prime[cnt++] = i;
}
for (int j = 0; j < cnt; j++) {
if (1ll * i * prime[j] > n) {
break;
}
vis[i * prime[j]] = tru... | 3 |
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
void solve() {
int n, m;
cin >> n >> m;
set<int> se;
while (n) {
int dig = n % m;
if (se.count(dig)) {
cout << "NO" << '\n';
return;
}
se.insert(dig);
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const long long inf = 1e9 + 7;
long long dp[N][3], cnt[3];
int n, l, r;
int main() {
scanf("%d%d%d", &n, &l, &r);
memset(dp, 0, sizeof(dp));
memset(cnt, 0, sizeof(cnt));
dp[0][0] = 1;
int l_l = l / 3 * 3, r_l = r / 3 * 3;
cnt[0] = cnt[1] =... | 3 |
#include <bits/stdc++.h>
using namespace std;
int const inf = 1000 * 1000 * 1000;
long long const inf64 = 1ll * inf * inf;
int const MAXN = 400005;
int n, m;
pair<int, int> edge[MAXN];
vector<pair<int, int> > g[MAXN];
bool br[MAXN];
int timer = 0;
int tin[MAXN];
int fup[MAXN];
bool used[MAXN];
void dfs(int v, int par =... | 6 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int d;
cin >> d;
int n = (1 << d) - 2;
if (n == 2) return cout << "2\n1 2\n", 0;
vector<vector<int>> g(n);
vector<int> deg(n, 0);
for (int i = 1; i < n; i++) {
... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long mod = pow(10, 9) + 7;
const double pi = 3.141592653589793238;
long long countdivisors(long long n) {
long long count = 0;
for (long long i = 1; i <= sqrt(n); i++) {
if (n % i == 0) {
if (n / i == i) {
count++;
} else {
count = ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = (int)1e5 + 10;
int wut[MAXN];
int dp[MAXN];
int doit(const vector<int>& ar) {
int n = (int)(ar).size();
memset(wut, 127, (n + 1) * 4);
memset(dp, 0, n * 4);
wut[0] = -1;
int res = 0;
for (int(i) = 0; (i) < (int)(n); (i)++) {
auto it = lower_... | 5 |
#include <bits/stdc++.h>
using namespace std;
float l, h;
int main() {
cin >> h >> l;
float kq = (l * l - h * h) / (2 * h);
printf("%06f", kq);
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
n-=400;
cout << 8-n/200 << endl;
} | 0 |
#include<bits/stdc++.h>
using namespace std;
map<pair<char, int>, int > var;
map<char, int> arrSize;
char array_name(string& line, int& idx){
return line[idx++];
}
int number(string& line, int& idx){
char c = line[idx];
if(c == '0'){
idx++;
return 0;
}else{
int ans = 0;
c = line[idx];
while('0' <= c &&... | 0 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=998244353;
const int N=200005;
ll val[N<<2],inc[N<<2],pre[N],rp[N];
void push_up(int u,int len) {
val[u]=(val[u<<1]+val[u<<1|1]*rp[len])%mod;
// if (u==1) printf("{%d: %lld %lld %lld %d}\n",u,val[u],val[u<<1],val[u<<1|1],len);
}
void push_... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 5;
struct edge {
int v, nxt;
} e[maxn << 1];
int head[maxn], kt, dep[maxn], fa[maxn], dfn[maxn], cnt, siz[maxn], son[maxn],
top[maxn], n, m;
struct Node {
int l, r;
mutable int col;
Node(int l = 0, int r = 0, int col = 0) : l(l), r(r), col... | 4 |
#include <iostream>
using namespace std;
int main() {
int d;
while (cin >> d) {
int area = 0;
for (int x = 0; x < 600; x+=d) {
area += d*x*x;
}
cout << area << endl;
}
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(T &x) {
x = 0;
int f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
x = x * f;
}
... | 2 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.