solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include<bits/stdc++.h>
#define endl enjoy_codeforces
int main(){
int n;std::cin>>n;
std::vector<int>sz={n/3,(n+2)/3,(n+1)/3};
std::vector<std::vector<int>>g(n);
for(int i=0;i<n-1;i++){
int u,v;std::cin>>u>>v;u--,v--;
g.at(u).push_back(v);
g.at(v).push_back(u);
}
std::vec... | 0 |
#include<iostream>
#include<cstdio>
using namespace std;
int ans,cov[222222],n,m,x,y,a[222222],cnt[222222],pos;
int main()
{
scanf("%d%d",&n,&m);
ans=n;
for (int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
cnt[a[i]]++;
}
for (int i=1;i<=n;i++)
{
pos=i-cnt[i]+1;
if (pos<=0) pos=1;
for (int j=pos;j<=i;j++)
{
... | 0 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:667772160")
using namespace std;
struct __isoff {
__isoff() {
if (0) freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
ios_base::sync_with_stdio(0);
srand(time(0));
}
~__isoff() {}
} __osafwf;
const unsigned long long p1 = 13... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1000001;
int main() {
int t, n, k;
long long int a[1001];
cin >> t;
while (t--) {
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
long long int s = a[0];
long long int r = 0, ans = 0;
for ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, sum;
int main() {
cin >> n;
int a[n];
cin >> a[0];
sum = (2 * n) - 1 + a[0];
for (int i = 1; i < n; i++) {
cin >> a[i];
sum += abs(a[i] - a[i - 1]);
}
cout << sum;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
string a;
int n;
int main() {
cin >> a;
cin >> n;
for (int i = 0; i < a.size(); i++) {
a[i] = tolower(a[i]);
if (a[i] < 97 + n) a[i] = toupper(a[i]);
}
cout << a << endl;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, c, t, count = 0;
cin >> n >> t >> c;
long long int a[n];
for (long long int i = 0; i < n; ++i) {
cin >> a[i];
}
bool flag = true;
long long int l = 0;
for (long long int i = 0; i < n; i++) {
if (a[i] <= t) {
l++;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
mt19937 eng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 2e5 + 4;
int n, q;
int a[N];
pii pos[N];
bool here;
void read() {
cin >> n >> q;
for (i... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
{
ios ::sync_with_stdio(false);
cin.tie(0);
};
;
long long n, k;
cin >> n >> k;
if (n >= k) {
if (k % 2 == 0) {
cout << (k / 2) - 1;
return 0;
} else {
cout << k / 2;
return 0;
}
} else {
if (k % 2 =... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 1000;
const int mod = 1000000000 + 7;
char s[maxn];
int n;
int a[5];
long long ans;
long long pow_q(long long x, int n) {
ans = 1;
while (n) {
if (n & 1) ans = (ans * x) % mod;
x = (x * x) % mod;
n = n >> 1;
}
return ans;
}
int ... | 3 |
#include <bits/stdc++.h>
using namespace std;
double Dist(double x, double y) { return x * x + y * y; }
bool Inside(long long x1, long long y1, long long x2, long long y2, long long x,
long long y) {
return x >= min(x1, x2) && x <= max(x1, x2) && y >= min(y1, y2) &&
y <= max(y1, y2);
}
double Nea... | 1 |
#include<bits/stdc++.h>
using namespace std;
string a,b,c,d;
int i=0,j=0,k=0,l=0,x,y;
void reada(){
if(i>=a.size()) return;
c="";
while(i<a.size()&&a[i]!='['){
if(a[i]=='(') k++;
if(a[i]==')') k--;
c+=a[i];
i++;
}
i++;x=0;
if(i>=a.size()) return;
while(a[i]!=']') x=x*10+a[i]-'0',i++;
i++... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n], b[n];
int t = 0;
for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
t = min(a[0], b[0]) + 1;
if (n >= 2) {
for (int i = 1; i < n; i++)
if (a[i] != a[i - 1] || b[i] != b[i - 1]) {
if (a[i - 1] != b[i - 1])... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long po[300010];
int arr[300010];
int main(void) {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", &arr[i]);
sort(arr, arr + n);
vector<int> v;
for (int i = 0; i < n - 1; i++) {
v.push_back(arr[i + 1] - arr[i]);
}
po[0] = 1;
for (i... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long double epsilon = 1e-9;
int mat2[1 << 18];
int idx2[1 << 18];
int minm[1 << 18];
int maxm[1 << 18];
int main() {
int h, m, n;
cin >> h >> m >> n;
memset(minm, -1, sizeof(minm));
memset(maxm, -1, sizeof(maxm));
int idx = 0;
for (int i = 0; i < h; i++) {... | 3 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int a,b,c;
cin >> a >> b >> c;
if(a*b*c==175){
cout << "YES" << endl;
}else{
cout << "NO" << endl;
}
} | 0 |
#include <bits/stdc++.h>
using namespace std;
struct task {
long long intime;
long long starttime;
long long runtime;
long long endtime;
};
int main() {
long long i = 0, b, n, currtime = 0, stoptime = -1;
queue<long long> z;
bool runflg = 0;
cin >> n >> b;
vector<task> all(n);
for (i = 0; i < n; i++... | 2 |
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>
// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#inc... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int arr[n + 1];
for (int i = 1; i <= n; ++i) cin >> arr[i];
pair<int, int> p[m + 1];
for (int i = 1; i <= m; ++i) {
cin >> p[i].first >> p[i].second;
}
int maxm = -1e9;
vector<int> dmh;
for (int i = 1; i <= n; ++... | 5 |
#include <bits/stdc++.h>
using namespace std;
double x[2], y[2], R[2], r[2];
double dis(double a, double b, double c, double d) {
return sqrt((a - c) * (a - c) + (b - d) * (b - d));
}
int doit(int flag) {
double d = dis(x[flag], y[flag], x[!flag], y[!flag]);
double d1, d2;
int ans = 0;
if (r[flag] >= d + R[!f... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base ::sync_with_stdio(false);
cin.tie(0);
long long t;
cin >> t;
for (long long i = 1; i <= t; i++) {
long long n, k;
cin >> n >> k;
string s;
cin >> s;
long long w = 0, z = 0;
bool flag = false;
for (long long i = 0; ... | 1 |
#include<iostream>
#include<cstdio>
#define N 12345
#define ll long long
using namespace std;
ll n,a[N],b[N],sum1,sum2;
int main()
{
scanf("%lld",&n);
for(ll i=1;i<=n;i++) scanf("%lld",a+i);
for(ll i=1;i<=n;i++) scanf("%lld",b+i);
for(ll i=1;i<=n;i++)
{
if(a[i] > b[i]) sum1 += (a[i] - b[i]);
if(a[i] < b[i]) su... | 0 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 0x3f3f3f3f;
const int MAXN = 2e3 + 5;
const int MOD = 1e9 + 7;
int n, m;
long long dp[MAXN][MAXN][2];
long long sumdp[MAXN][MAXN][2];
int sum[MAXN][MAXN][2];
char s[MAXN];
int Binsearch(int i, int j, int... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int ms = 100 + 10;
long long dp[ms][ms], sum[ms];
pair<long long, long long> a[ms], b[ms];
int n, re[ms];
bool cmp(const pair<long long, long long>& l,
const pair<long long, long long>& r) {
return l.first < r.first || (l.first == r.first && l.second > r.se... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, dist[200002], p[200002], m, k;
vector<int> G[200002];
vector<int> G1[200002];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for (int i = 1; i <= m; i++) {
int x, y;
cin >> x >> y;
G1[y].push_back(x);
... | 4 |
#include <bits/stdc++.h>
using namespace std;
string query(long long m) {
cout << m << " 1" << endl;
fflush(stdout);
string s;
cin >> s;
return s;
}
int main() {
int n;
cin >> n;
long long l = 0, r = 1e9;
string s = query(l);
for (int i = 0; i < n - 1; i++) {
long long m = (l + r) / 2;
strin... | 3 |
#include <bits/stdc++.h>
template <class T1, class T2>
inline bool cmin(T1 &a, const T2 &b) {
return b < a ? (a = b, true) : false;
}
template <class T1, class T2>
inline bool cmax(T1 &a, const T2 &b) {
return a < b ? (a = b, true) : false;
}
template <class Type>
Type read() {
Type a;
bool b;
unsigned char c... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
string s;
cin >> s;
int a[s.size() + 5];
a[0] = 1;
int tmp = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] == 'N') tmp++;
}
if (tmp == 1)
cout << "NO\n";
else
cout << ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n;
struct bit {
int v[200000];
bit() { memset(v, 0, sizeof v); }
int query(int p) {
int resp = 0;
for (int i = p; i > 0; i -= (i & (-i))) resp = max(resp, v[i]);
return resp;
}
void set(int p, int val) {
for (int i = p; i < 200000; i += (i & (-... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
long long ans = 1LL * n * (n - 1) * (n - 2) * (n - 3) * (n - 4) / 120;
long long a = 1LL * ans * (n - 5) / 6;
long long b = 1LL * a * (n - 6) / 7;
ans += a + b;
cout << ans << endl;
}
| 6 |
#include <bits/stdc++.h>
using namespace std;
bool myfn(int x, int y) { return x > y; }
int main() {
int n;
scanf("%d", &n);
int arr[n];
int dp[n];
stack<int> stk;
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}
sort(arr, arr + n);
stk.push(-1);
int j = 0;
for (int i = 0; i < n; i++) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int base = 100003;
const long long MM = 1ll * 1000000007 * 1000000007;
const int maxc = 2e9;
int n, p, k, a[200001], dp[200001];
void Solve() {
int test;
cin >> test;
while (test--) {
cin >> n >> p >> k;
for (int i = 1; i <= n; ++i) cin >> a[i];
sort... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
long long a[2][N];
long long lt[2][N], rt[2][N], both[2][N];
void fun() {}
int main() {
fun();
ios_base ::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
int k;
cin >> n >> k;
int mdarray[k];
memset(mdarray, 0, sizeof(m... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
typedef struct node2 {
int d[60 + 1];
} node1;
node1 tree[400001];
int a[100001];
void initialise(int node, int b, int e) {
if (b > e) {
return;
} else if (b == e) {
for (int(i) = (0); (i) < (60); ++(i)) {
tree[node].d[i] = 0;... | 4 |
#include<bits/stdc++.h>
using namespace std;
signed main(){
int a,b,c,d; cin>>a>>b>>c>>d;
cout << (a!=c) << endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> a, p;
int n, k = 0, n1, ans = 0;
cin >> n;
n1 = n;
while (n1 != 0) {
if (n1 % 10 == 4)
a.push_back(0);
else
a.push_back(1);
n1 /= 10;
k++;
}
p.push_back(1);
for (int i = 0; i < k; i++) p.push_back(p.back()... | 2 |
#include<iostream>
#include<vector>
using namespace std;
int main()
{
long long int t,n,m,sum=0,c=0,x,mn,mx=0,i;
cin>>t;
while(t--)
{
cin>>n>>x;
vector<int> V(n);
for(int i=0;i<n;i++)
{
cin>>V[i];
sum+=V[i];
}
mn=sum%x ? sum/x+1 : sum/x;
for(i=0;i<n;i... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
struct Pair {
int a;
int b;
};
Pair p[N];
long long pref[N];
long long ans;
int n, m, i, L, R, mid, mx;
bool cmp(Pair x, Pair y) { return x.a > y.a; }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T;
cin >> T... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100500;
bool one(int mask, int i) { return (mask & (1ll << i)); }
int n, a[N], k = 0, ans[N], first[N], res = 0, b[N];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int pw = 30; pw >= 0; --pw) {
bool ok = 1;
res ... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
inline long long read() {
bool f = false;
char ch = getchar();
long long res = 0;
while (ch < '0' || '9' < ch) f |= (ch == '-'), ch = getchar();
while ('0' <= ch && ch <= '9') res = 10 * res + ch - '0', ch = getchar();
return f ? -... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main(){
string s;
cin >> s;
long long int a=0,b=0;
for(int i=0;i<s.size();i++){
if(s[i]=='0')a++;
else b++;
}
cout << min(a,b)*2 <<endl;
} | 0 |
#include<iostream>
using namespace std;
int main() {
int b[3];
cin >> b[0] >> b[1] >> b[2];
if (b[0] + b[1] * 2 + b[2] * 3 >= 3)cout << "Open" << endl;
else cout << "Close" << endl;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
struct point {
int x, y;
point() {}
point(int x_, int y_) {
x = x_;
y = y_;
}
bool operator<(const point& b) const { return x != b.x ? x < b.x : y < b.y; }
point operator-(const point& b) const { return point(x - b.x, y - b.y); }
long long operator*(co... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long ans = 0;
string str;
int n;
int main() {
ios::sync_with_stdio(false);
cin >> n;
cin >> str;
for (int i = 0; i < n; ++i) ans += (str[i] - '0') & 1 ? 0 : i + 1;
cout << ans << endl;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
long long mx[5], mi[5];
long long X[5][2], f[7], MX = 1e18;
long long get(long long x, long long y) {
return x / 2 + y / 2 + (x % 2 + y % 2) / 2;
}
int pd(long long x) {
f[3] = max(X[1][0] - x, X[2][0] + x);
f[4] = min(X[1][1] - x, X[2][1] + x);
f[5] = max(X[3][0] -... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long int arr[200050];
void swap(long long int *a, long long int *b) {
long long int temp = *a;
*a = *b;
*b = temp;
}
long long int rev(long long int i, long long int j) {
long long int k;
long long int temp2 = j;
for (k = i; k <= (i + j) / 2; k++) {
swa... | 2 |
#include <stdio.h>
#include <string.h>
#define NUM 1000
char hitohude_error(char s[])
{
int i,j,k;
char error=0;
for(j=0;s[j+1] != '\n';j++) {
if(s[j] == s[j+1]) {
error = 1; break;
}
}
for(j=0; s[j+1] != '\n';j++) {
if(s[j] == 'A') {
if(s[j+1] != 'B' && s[j+1] != 'D') {
error = 1; break;
}
}... | 0 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:65777216")
using namespace std;
int n, m;
int x[1111], y[1111], z[1111];
pair<double, double> p[1111];
const double eps = 1e-6;
void parse(int A, int B, int C, double &x, double &y, double &z) {
double t = (A * x + B * y + C * z) / (A * A + B * B + C * C);
x ... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long digitsum(long long r, long long m = 10) {
long long ret = 0;
for (long long x = 1; x <= r; x *= m) {
long long dig = (r / x) % m;
long long le = (r / x) / m;
long long ri = r % x;
long long cur = 0;
for (int i = 1; i < dig; ++i) cur += i;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 55;
int n, m;
char a[N][N];
vector<int> row[N];
vector<int> col[N];
bool possible;
bool checked[N];
bool same(int idx1, int idx2) {
if (row[idx1].size() != row[idx2].size()) return false;
for (int i = 0; i < row[idx1].size(); i++)
if (row[idx1][i] != r... | 1 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.);
vector<pair<long long, char> > s, t, temp, temp1;
pair<long long, char> p;
int n, m;
const int MAX_N = 200010;
long long b[MAX_N];
void kmpPreprocess() {
int i = 0, j = -1;
b[0] = -1;
while (i < temp.size()) {
while (j >= 0 && temp[i] ... | 4 |
#include <bits/stdc++.h>
using namespace std;
vector<char> vec[500005];
int res[500005];
int main() {
int n;
cin >> n;
getchar();
for (int i = 0; i < n; i++) {
char x;
while (scanf("%c", &x) && (x != '\n')) {
vec[i].push_back(x);
}
}
for (int i = n - 1; i > 0; i--) {
int tmp1 = vec[i].... | 4 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const long long maxn = 4e5;
const long long mod = 1e9 + 7;
const long double PI = acos((long double)-1);
long long pw(long long a, long long b, long long md = mod) {
long long res = 1;
while (b) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
long long a[N], u;
int n;
long double solve() {
long double ans = -1;
for (int i = 1; i <= n - 2; i++) {
long double ei = (long double)a[i], ej = (long double)a[i + 1];
int idx = -1;
int l = i + 2, r = n;
while (l <= r) {
int... | 3 |
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <b... | 5 |
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
using namespace std;
void show(vector<int> &v, string s = "") {
if (s.size() > 0) {
cout << s << endl;
}
for (auto e : v) {
cout << e << " ";
}
cout << endl;
}
int main() {
int n, m, q;
scanf("%... | 0 |
#include <bits/stdc++.h>
using namespace std;
set<long long> dp[55][55];
long long pre[55];
long long arr[55];
int main() {
int n, k;
cin >> n >> k;
for (int i = 1; i <= n; i++) {
scanf("%I64d", &arr[i]);
pre[i] = pre[i - 1] + arr[i];
}
for (int i = 1; i <= k; i++) {
if (i == 1) {
for (int j... | 4 |
#include<bits/stdc++.h>
#define int long long
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1e6+3;
typedef long long ll;
int modpow(int x,int y,int md=mod){if(y==0)return 1;int ret=modpow(x,y>>1,md);ret=(ll)ret... | 0 |
#include <bits/stdc++.h>
using namespace std;
struct cmp {
bool operator()(pair<int, int> a, pair<int, int> b) {
return a.second > b.second;
}
};
long long modpow(long long base, long long exp, long long mod) {
base %= 1000000007;
long long result = 1;
while (exp > 0) {
if (exp & 1) result = (result *... | 3 |
#include <bits/stdc++.h>
int main() {
int s = 0, n, m, a, b;
scanf("%d %d %d %d", &n, &m, &a, &b);
if (a * m > b) {
s = (n / m) * b + (n % m) * a;
if (a > b) {
if (n % m != 0) s = ((n / m) + 1) * b;
}
} else {
s += a * n;
}
if (s > b && m > n) s = b;
printf("%d\n", s);
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
vector<int> copy1;
vector<int> data_1[(int)3e5];
int data_2[(int)3e5];
int n, m, total;
int func(int day) {
vector<int> remaining = copy1;
int t = total;
int money = day, cur_money = day;
for (int i = day; i >= 1; i--)
for (int j = 0; j < data_1[i].size(); j++) ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 20005;
int n, m;
vector<pair<int, int> > ver[MAXN];
int fa[MAXN][15], dep[MAXN], id[MAXN][15], lg[MAXN];
void dfs(int u) {
for (pair<int, int> v : ver[u])
if (v.first != fa[u][0]) {
fa[v.first][0] = u;
dep[v.first] = dep[u] + 1;
id[v... | 5 |
#include <bits/stdc++.h>
using namespace std;
int tot;
long long n, m, len;
map<long long, long long> cnt;
int main() {
scanf("%I64d%I64d", &n, &m);
if (m <= 2) {
printf("%I64d\n", m == 1 ? 1LL : n);
return 0;
}
m -= 2;
cnt[n - 2] = 1;
while (1) {
long long nxt = (cnt.rbegin()->first - 1) >> 1, ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
char in[MAXN];
long long wynik, wag[26], s[MAXN];
int n;
map<long long, long long> pocz[26];
int main() {
for (int i = 0; i < 26; i++) scanf("%I64d", &wag[i]);
scanf("%s", in + 1);
n = strlen(in + 1);
for (int i = 1; i <= n; i++) s[i] = s[i... | 4 |
#include <bits/stdc++.h>
using namespace std;
void fast() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
long long int vis[200005] = {0};
vector<int> v[4005];
vector<set<long long int>> myset(200005);
vector<long long int> put;
long long int par[200005] = {0};
long long int sz[200005] = {0};
int a[400... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b[6], c, d, e[6], f, g, h;
for (a = 0; a < 6; a++) cin >> b[a];
for (a = 0; a < 6; a++) {
d = 0;
for (c = 0; c < 6; c++) {
if (b[a] == b[c]) d = d + 1;
}
e[a] = d;
}
f = g = d = h = 0;
for (a = 0; a < 6; a++) {
if (e... | 1 |
#include <bits/stdc++.h>
#define FI(i,a,b) for(int i=(a);i<=(b);i++)
#define FD(i,a,b) for(int i=(a);i>=(b);i--)
#define LL long long
#define Ldouble long double
#define PI 3.1415926535897932384626
#define PII pair<int,int>
#define PLL pair<LL,LL>
#define mp make_pair
#define fi first
#define se second
using namesp... | 0 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
template <typename T>
T sqr(T x) {
return x * x;
}
const int maxn = (int)(1e5) + 10;
int n, m, p, q;
vector<pair<int, int> > g[maxn];
vector<int> comp[maxn];
long long len[maxn];
bool used[maxn];
int curC, Size[maxn];
void dfs(in... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3010;
long long dis[N * N], x[N], y[N];
bool g[N][N];
bitset<N> bit[N];
int main() {
int n, i, j, m = 0;
cin >> n;
for (i = 0; i < n; i++) cin >> x[i] >> y[i];
for (i = 0; i < n; i++)
for (j = i + 1; j < n; j++) {
dis[m] = ((x[i] - x[j]) * (x... | 5 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n;
cin >> n;
long long row = 0, col = 0;
vector<pair<long long, long long>> ans;
for (long long i = 0; i <= n; i++) {
ans.push_back({row, col});
ans.push_back({row + 1, ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int visited[100001] = {0};
int main() {
int n, m, ans = 0;
cin >> n >> m;
if (m >= n) {
queue<pair<int, int>> q;
q.push({n, 0});
pair<int, int> t;
visited[n] = 1;
while (q.size()) {
t = q.front();
q.pop();
if (t.first == m) {
... | 2 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
mt19937 rnd(time(0));
const int MAXN = 3 * 100 * 1000 + 17;
int n, a[MAXN], q;
vector<int> w[MAXN];
int main() {
ios_base::sync_with... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5005, mod = 998244353;
int qp(int a, int b) {
int ans = 1;
while (b) {
if (b & 1) ans = 1ll * ans * a % mod;
a = 1ll * a * a % mod;
b >>= 1;
}
return ans;
}
int n, m, k, f[N][N], ans;
int main() {
scanf("%d%d%d", &n, &m, &k);
f[0][0] = ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int a, l[100009], r[100009], z[100009 * 10], b, c;
long long sm;
vector<int> v;
int main() {
cin >> a;
for (int i = 1; i <= a; i++) cin >> l[i] >> r[i], z[l[i]]++, z[r[i]]--;
for (int i = 1; i <= 1000000; i++) z[i] += z[i - 1];
for (int i = 1; i <= 1000000; i++) {
... | 3 |
#include<bits/stdc++.h>
using namespace std;
const int N = 12345;
int n, a[N], b[N];
vector<int> adj[N];
bool visit[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 1, x, y; i < n; ++i) {
cin >> x >> y;
adj[x].push_back(y);
adj[y].push_back(x);
}
... | 0 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
int n, p[505][505], q, x, y, ans, dx[] = {0,0,1,-1}, dy[] = {1,-1,0,0}, used[505][505];
void dfs(int x, int y){
p[x][y]--;
rep(i,4){
int nx = x + dx[i], ny = y + dy[i];
if(p[nx][ny] + used[nx][ny] == p[x][y] + 2) dfs(nx,ny);
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, m, u, v, vk = 0, vv = 0;
long long res = 0, se = 0;
int visited[1000000], selfE[1000000];
vector<vector<int> > G(1000000, vector<int>());
void dfs(int i) {
if (visited[i]) return;
visited[i] = 1;
vk++;
for (int u : G[i]) {
dfs(u);
}
}
void solve() {
s... | 4 |
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define N 1000000007
int main()
{
long long n, m, k,cost=0,t=1;
cin >> n >> m >> k;
for (long long i = 0; i < n; i++) cost = (cost + (1 + i) * i / 2 * m % N * m % N) % N;
for (long long i = 0; i < m; i++) cost = (cost + (1 + i) * i / ... | 0 |
#include<bits/stdc++.h>
using namespace std;
int n,k,q;
int a[2009],b[2009];
int main(){
cin >> n>>k>>q;
for(int i = 1; i <= n; i++){
cin >> a[i];
}
int ans = 1e9;
for(int i = 1; i <= n; i++){
int l = 0, x = a[i];
vector<int> VV;
for(int j = 1; j <= n+1; j++){
... | 0 |
#include <bits/stdc++.h>
using namespace std;
void usaco(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
template <class T>
void umin(T &a, T b) {
if (b < a) a = b;
}
template <class T>
void umax(T &a, T b) {
if (a < b) a = b;
}
int rec(vector<int> &v, int bit... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long a, b, w, x, c;
int main() {
scanf("%I64d%I64d%I64d%I64d%I64d", &a, &b, &w, &x, &c);
long long dif = c - a;
if (dif <= 0)
printf("0\n");
else {
double k = double(dif * x - b) / double(w - x);
long long result = dif + ceil(k);
printf("%I64d\n... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a, b, xx, yy, xx1, yy1, xx2, yy2;
cin >> a >> b;
for (long long i = 1; i < a; i++) {
long long y = a * a - i * i;
y = sqrt(y);
if (i * i + y * y == a * a) {
xx = i;
yy = y;
xx1 = -y * b;
yy1 = i * b;
if ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int a,b,c;
cin >> a >> b >> c;
cout << ((a+b)*c)/2;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
std::istream& operator>>(std::istream& i, pair<T, U>& p) {
i >> p.first >> p.second;
return i;
}
template <typename T>
std::istream& operator>>(std::istream& i, vector<T>& t) {
for (auto& v : t) {
i >> v;
}
return i;
}
templat... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int MX = 2e5;
set<int> adj[MX + 1];
vector<int> leaf;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
for (int i = 0; i < n - 1; ++i) {
int u, v;
cin >> u >> v;
adj[u].insert(v);
adj[v].insert(u);
}
for (int i = 1;... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, b[N];
long long m, a[N], tot;
pair<long long, int> s[N];
int cnt;
long long f(long long x, long long y) { return y - 1 - 3 * x * (x - 1); }
int calc(long long x, long long t) {
int l = 1, r = x + 1, mid;
while (l < r) {
mid = l + r >> ... | 6 |
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
typedef pair<int,int> P;
using ll... | 0 |
#include <iostream>
using namespace std;
int a[10];
bool dfs(int i,int l,int r){
if(i>=10)return 1;
if(l>a[i]&&r>a[i])return 0;
if(l<a[i]){
if(dfs(i+1,a[i],r))return 1;
}
if(r<a[i]){
return dfs(i+1,l,a[i]);
}
return 0;
}
int main(){
int T;cin>>T;
while(T--){
for(int i=0;i<10;i++)cin>>a[i];
if(dfs(0,0... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long int powmod(long long int a, int b, int n) {
long long int rm = 1;
while (b) {
if (b % 2) {
rm = (rm * a) % n;
}
a = (a * a) % n;
b /= 2;
}
return rm;
}
int dp[int(1e5 + 10)] = {0}, uni[int(1e5 + 10)] = {0}, b[int(1e5 + 10)],
... | 4 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int ck(string& s, int i, int j, char c) {
if (i == j) {
if (s[i] == c)
return 0;
else
return 1;
}
int mid = i + (j - i) / 2;
int cnt = 0, cnt1 = 0, cnt2 = 0, cnt3 = 0;
for (int ii = i; ii <= mid; ii++) {
if (s[ii] == c... | 4 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5,M=505,mod=998244353;
ll base1=1,base2=0,p[N];
int n,m,tot,vis[N],head[N],nex[N<<1],to[N<<1];
void add(int u,int v){to[++tot]=v;nex[tot]=head[u];head[u]=tot;}
vector<ll>res[3];
void solve(int flag)
{
tot=0;memset(head,0,sizeof(head)... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, a[100005], dp[100005][20], g[100005][20], lg2[200005];
int pos[100005];
void init() {
int i, j;
lg2[1] = 0;
for (i = 2; i <= n; i++) lg2[i] = lg2[i - 1] + (i & (i - 1) ? 0 : 1);
for (i = 1; i <= n; i++) dp[i][0] = a[i], g[i][0] = a[i];
for (j = 1; j <= lg2[... | 2 |
#include <iostream>
using namespace std;
#define int long long
int N, M;
int P[100100];
int A[100100];
int B[100100];
int C[100100];
int visit[100100];
signed main() {
cin >> N >> M;
for (int i=0; i<M; i++) cin >> P[i];
for (int i=0; i<N-1; i++) cin >> A[i] >> B[i] >> C[i];
for (int i=1; i<M; i++) {
i... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const double pi = acos(-1.0);
int n, i, k;
long long pl, pr, vl, vr, minp, maxp, minv, maxv;
long long lucky[2000];
long long numerator, denumerator;
void generate_lucky(long long me) {
lucky[++n] = me;
if (me * 10 + 4 <= 1000000000) ge... | 4 |
#include <iostream>
#include <map>
#include <cstring>
using namespace std;
int main()
{
map<char, map<char, string> > data;
data['1']['T'] = "a"; data['1']['L'] = "i"; data['1']['U'] = "u"; data['1']['R'] = "e"; data['1']['D'] = "o";
data['2']['T'] = "ka"; data['2']['L'] = "ki"; data['2']['U'] = "ku"; data... | 0 |
#include <stdio.h>
#include <string.h>
#define ROW_BLOCK 4
#define COL_BLOCK 4
#define ROW_NUM (ROW_BLOCK + 2) * 2 - 1
#define COL_NUM (COL_BLOCK + 2) * 2 - 1
#define UP 0
#define RIGHT 1
#define DOWN 2
#define LEFT 3
const char command[5] = "URDL";
const int dy[4] = {-1,0,1,0}, dx[4] = {0,1,0,-1};
const int gy = 1, g... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, u, v, D, B, a[100009];
long long c[100009];
void ins(int x, int y) {
for (; x <= n; x += x & -x) c[x] += y;
}
long long getsum(int x) {
long long y = 0;
for (; x; x ^= x & -x) y += c[x];
return y;
}
void update() {
for (; u <= n && !a[u]; u++)
;
for (... | 6 |
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
bool cmax(T& a, const U& b) {
return a < b ? a = b, 1 : 0;
}
template <class T, class U>
bool cmin(T& a, const U& b) {
return b < a ? a = b, 1 : 0;
}
void _BG(const char* s) { cerr << s << endl; }
template <class T, class... TT>
void _BG(cons... | 3 |
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long int M = 4e3 + 5, LG = 30, inf = 1e18, mod = 1e9 + 7;
string s;
long long int f(string t) {
long long int cnt = 0;
for (int i = 0; i < ((long long int)s.size()) - ((long long int)t.size()) + 1;
i++) {
for (int j = 0; j < ((long long int)t.size(... | 1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.