solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
int r;
int a[100000];
int z = 0;
int k = 0;
int c = 0;
int d = 0;
cin >> r;
for (int i = 0; i < r; i++) {
cin >> a[i];
}
for (int i = 0; i < r; i++) {
if (a[i] == 3) c++;
}
for (int i = 0; i < r; i++) {
if (a[i] == 1) d++;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> G[500005];
int parent[500005];
int dp[500005][2][2], dp2[500005][2][2];
int tdp[500005][2][2], ldp[500005][2][2], rdp[500005][2][2];
int& get(int u, int v, int i, int j) {
if (parent[u] == v) return dp2[u][i][j];
return dp[v][i][j];
}
void dfs(int ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100001;
vector<long long int> v;
long long int ar[N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int n, m, k;
cin >> n >> m;
multiset<long long int> st;
for (int i = 0; i < n; i++) cin >> ar[i];
sort... | 1 |
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int s=0,n,a[222];
cin>>n;
for(int i=0;i<n*2;i++)cin>>a[i];
sort(a,a+n*2);
for(int i=0;i<n;i++)
{
s+=min(a[i*2],a[i*2+1]);
}
cout<<s<<endl;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, v, c, x, z, a[1000001], s, d, f, g, h, j, k, b[100001], i, p, y,
p1, q;
int main() {
long long t;
cin >> t;
while (t--) {
cin >> n;
s = 0;
k = 8;
for (long long i = 1; i <= n / 2; i++) {
s += k * i * i;
}
cout << s << ... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int arr[N];
class Bit {
int tree[N];
public:
Bit() { memset(tree, 0, sizeof tree); }
int query(int idx) {
int sum = 0;
while (idx > 0) {
sum += tree[idx];
idx -= (idx & -idx);
}
return sum;
}
void update(int idx... | 4 |
#include <iostream>
using namespace std;
int p;
int a[3000], s[3000], t[3000], b[3000];
int main()
{
cin >> p;
for (int i = 0; i < p; i++)
cin >> a[i];
for (int i = 0; i < p; i++)
b[i] = 0;
s[0] = 1;
t[0] = 1;
for (int i = 1; i < p; i++) {
s[i] = s[i - 1] * i % p;
int j = s[i], k = 1;
while (k <... | 0 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,k;
cin>>n>>k;
int s=k;
for(int i=2;i<=n;i++){
s*=k-1;
}
cout<<s;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int x;
long long w = 0, b = 0;
for (int i = 0; i < n; ++i) {
cin >> x;
if (x % 2 == 0) {
w += x / 2;
b += x / 2;
} else if (i % 2) {
w += x / 2;
b += x / 2 + 1;
} else {
w += x / 2 + 1;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, sm = 0, SM = 0;
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
sm += x;
}
for (int i = 0; i < n; i++) {
int x;
cin >> x;
SM += x;
}
if (sm < SM)
cout << "No";
else
cout << "Yes";
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
const int INF = 100000000;
int main(void) {
int m;
cin >> m;
for(int i=0; i<m; i++){
string s;
cin >> s;
set<string> sset;
string sr = s;
reverse(s.begin(), s.end());
for(int i=0; i<s.size() - 1; i++){
string s1 = s.substr(0... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long modulo(long long base, long long exp, long long m);
long long powerr(long long base, long long exp, long long m);
long long inverse(long long a, long long m);
const long long nax = 1e5 + 10;
vector<long long> tree(4 * nax);
void update(long long node, long long st... | 3 |
#include<bits/stdc++.h>
using namespace std;
const int64_t mod=1000000007;
int64_t powermod(int k,int d){
int64_t m=1;
for(int i=0;i<k;i++){
m=m*d%mod;
}
return m;
}
int main(){
int n;
cin >> n;
int64_t ans=powermod(n,10)-powermod(n,9)-powermod(n,9)+powermod(n,8);
ans%=mod;
ans=(ans+mod)%mod;
co... | 0 |
// ???
#include<iostream>
using namespace std;
typedef long long ll;
int main(){
int m, n;
cin >> m >> n;
int a[n];
for(int i = 0; i < n; i++) cin >> a[i];
if(m == 2){
int ret = 1<<30;
for(int i = 1; i <= 2; i++){
int x = i;
int tmp = 0;
for(int ... | 0 |
#include <bits/stdc++.h>
using namespace std;
pair<int, int> dir[] = {{1, 0}, {0, 1}, {0, -1}, {-1, 0}};
int ex[15];
int ans[15];
int gr[1009][1009];
queue<pair<pair<int, int>, int>> q[15];
int cnt;
int main() {
int n, m, p;
cin >> n >> m >> p;
for (int i = 1; i <= p; ++i) cin >> ex[i];
for (int i = 0; i < n; +... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 88;
char str[N];
int vis[33];
int main() {
int T;
char op[5];
for (int i = 0; i < 26; ++i) vis[i] = 3;
int remain = 26, ans = 0;
scanf("%d", &T);
for (int tt = 1; tt < T; ++tt) {
scanf("%s %s", op, str);
if (remain == 1) {
if (o... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 114;
long long n, k, w, f;
inline long long read() {
long long num = 0;
char g = getchar();
while (g < 48 || 57 < g) g = getchar();
while (47 < g && g < 58)
num = (num << 1) + (num << 3) + g - 48, g = getchar();
return num;
}
inline long long get... | 4 |
#include<bits/stdc++.h>
using namespace std;
int main(){
string s;
int n;
while(cin>>s){
for(int i=0; i<(int)s.size(); i++){
if(s[i]!='@')cout << s[i];
else{
i++;
n = s[i]-'0';
i++;
for(int j=0; j<n; j++)cout<<s[i];
}
}
cout << endl;
}
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
long long n, k;
cin >> n >> k;
auto s = 0LL;
for (int i = 0; i < n && s < 3 * k; ++i) s += 1LL << (2 * i);
if (k > s || (n < 3 && k == 3)) {
cout << "NO" << endl;
continue;
}
while (k ... | 4 |
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;
typedef pair<int, int> P;
struct BIT {
vector<ll> bit;
int n;
BIT(int n) :n(n) {
bit = vector<ll>(n + 1, 0);
}
ll sum(int i) {
... | 0 |
#include <cassert>
#include <iostream>
#include <limits>
#include <vector>
using VI = std::vector<int>;
using VVI = std::vector<VI>;
using uint = unsigned;
struct Sparse {
VVI arr;
VI src;
// does not initialize, just sets src.size()
Sparse(int n)
:arr {},
src { VI(n) }
{}
int best(int p, int ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int read() {
int s = 0, bj = 0;
char ch = getchar();
while (ch < '0' || ch > '9') bj |= (ch == '-'), ch = getchar();
while (ch >= '0' && ch <= '9')
s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
return bj ? -s : s;
}
void printnum(int x) {
if (x > 9) p... | 4 |
#include <bits/stdc++.h>
int n, i;
int a[100];
int main() {
scanf("%d", &n);
if (n == 1) {
printf("1\n");
return 0;
}
if (n == 2) {
printf("3\n");
return 0;
}
if (n == 3) {
printf("5\n");
return 0;
}
a[1] = 1;
a[2] = 5;
a[3] = 13;
for (i = 4; a[i] <= 100; i++) a[i] = 2 * i ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const double PI = 3.14159265358979323846264338327950288419716939937510582;
int t;
int n;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> t;
while (t--) {
cin >> n;
cout << fixed << setprecision(20) << cos(PI / (4 * n)) / sin(... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long MOD;
struct mat {
long long ma[2][2];
mat() { ma[0][0] = ma[0][1] = ma[1][0] = ma[1][1] = 0; }
};
mat MatMul(mat m1, mat m2) {
mat res;
for (int i = 0; i < 2; ++i)
for (int j = 0; j < 2; ++j)
for (int k = 0; k < 2; ++k)
res.ma[i][k] = (re... | 4 |
#include <bits/stdc++.h>
using namespace std;
int f[100][3][2];
int main() {
int n;
scanf("%d", &n);
for (int i = (1); i <= (n); ++i) {
int x;
scanf("%d", &x);
if (x == 0) {
f[i][1][0] = max(max(max(f[i - 1][1][1], f[i - 1][1][0]), f[i - 1][2][0]),
f[i - 1][2][1]);
f... | 3 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
ll mod_pow(ll a, ll b, ll m) {
ll res = 1;
while (b) {
if (b & 1) {
res = (res * a) % m;
}
a = (a * a) % m;
b >>= 1;
}
return res;
}
ll mod_inverse(long long int a, long long int m) {
return mod_p... | 4 |
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define popb pop_back
#define all(A) A.begin(),A.end()
#define mod 1000000007
using namespace std;
int main() {
int n;
ll a=0,b=0,k;
cin>>n>>k;
vector<int> arr(n);
for(int i=0;i<n;i++) cin>>arr[i];
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
... | 0 |
// O(nlogn) - O(1) LCA
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int,int>;
#define mp make_pair
const int maxn = 200200;
vector <int> e[maxn];
int dep[maxn], dfs_seq[maxn * 2], idx, L[maxn], Log[maxn * 2], st[20][maxn * 2];
struct node {
int x, y, id;
bool operator < (const node & a) const ... | 6 |
#include <iostream>
#include <string>
using namespace std;
int main(){
string str;
while (cin >> str) {
int J = 0, I = 0;
for (int i = 1; i < str.size() - 1; i++) {
if (str[i] == 'O' && str[i + 1] == 'I') {
if (str[i - 1] == 'J') J++;
if (str[i - 1] == 'I') I++;
}
}
cout << J << endl;
cout... | 0 |
#include <bits/stdc++.h>
using namespace std;
const double PI = 2.0 * acos(0.0);
const double EPS = 1e-7;
int main() {
int n;
scanf("%d", &n);
double ans = 0.0;
double e = 1.0;
while (n--) {
double p;
scanf("%lf", &p);
ans += e * p;
e = 1.0 + (e + 1.0) * p;
}
printf("%.6lf\n", ans);
retu... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, n, k;
for (cin >> t; t-- > 0; cout << n - max(0, n % k - k / 2) << '\n')
cin >> n >> k;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int b, g, n;
cin >> b >> g >> n;
if (b >= n && g >= n) {
cout << n + 1 << endl;
} else if (b < n && g >= n) {
cout << b + 1 << endl;
} else if (b >= n && g < n) {
cout << g + 1 << endl;
} else... | 2 |
#include <bits/stdc++.h>
using namespace std;
string s;
int n, k, p, q;
bool ok;
int main() {
scanf("%d%d", &n, &k);
cin >> s;
for (int i = 0; i < s.size(); ++i) {
if (s[i] == 'G') p = i;
if (s[i] == 'T') q = i;
}
if (p > q) {
if ((p - q) % k == 0) {
ok = 0;
while (p != q) {
if... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string x;
cin >> x;
int len = x.size();
int cnt = 0, ok = 0;
for (int i = 0; i < len - 1; i++) {
if (x[i] == x[i + 1] && x[i] != '?' && x[i + 1] != '?') {
cout << "No" << endl;
return 0;
}
if (x[i] == '?') ... | 1 |
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm> // require sort next_permutation count __gcd reverse etc.
#include <cstdlib> // require abs exit atof atoi
#include <cstdio> // require scanf printf
#include <f... | 0 |
#include <bits/stdc++.h>
using namespace std;
void _print(long long t) { cerr << t; }
void _print(string t) { cerr << t; }
void _print(char t) { cerr << t; }
void _print(long double t) { cerr << t; }
void _print(double t) { cerr << t; }
void _print(unsigned long long t) { cerr << t; }
template <class T, class V>
void _... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int flag = 1;
int mx = INT_MIN;
long long index = 0;
vector<int> vec(n);
for (int i = 0; i < n; i++) {
int temp;
cin >> temp;
vec[i] = temp;
if (temp > mx)... | 3 |
#include <bits/stdc++.h>
using namespace std;
map<int, int> mp;
int main() {
int n, i;
string a[300], mx1, mx2, pr;
int num = 0;
scanf("%d", &n);
for (i = 0; i < 2 * n - 2; i++) {
cin >> a[i];
if (a[i].size() == n - 1) {
if (mx1.size() == 0)
mx1 = a[i];
else
mx2 = a[i];
... | 3 |
#include <bits/stdc++.h>
using namespace std;
char s[2510];
long long n, m, k, r, a[2510][2510], u[2510][2510];
long long ss(long long x1, long long x2, long long y1, long long y2) {
return a[x2][y2] - a[x1][y2] - a[x2][y1] + a[x1][y1];
}
void dfs(long long x1, long long x2, long long y1, long long y2, long long t) {... | 5 |
#include <bits/stdc++.h>
using namespace std;
;
struct _dbg {
template <class T>
_dbg& operator,(const T& v) {
cerr << v << " ";
return *this;
};
};
_dbg _d;
int a[1000], N, Q;
string r;
int main() {
ios_base::sync_with_stdio(0);
cin >> N;
for (int i = 0, _i = (N); i < _i; ++i)
for (int j = 0, _... | 1 |
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
struct data{
int bit,x,y;
data(){}
data(int bb,int yy,int xx){
bit=bb;
x=xx;
y=yy;
}
bool operator<(const data &d)const{
return bit<d.bit;
}
};
int h,w;
string str[20];
int fie[19][15];
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
string s;
int n;
cin >> s >> n;
map<string, int> M;
for (int i = 0; i < n; ++i) {
string a, b, c, aux;
cin >> a >> b;
if (b == "posted") {
cin >> aux >> c >> aux;
c = c.substr(0, c.size(... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100050;
int gi() {
int x = 0, flag = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') flag = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
return x * flag;
}
int a[N], b[N],... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1.1e6 + 5;
const int inv2 = 499122177;
int wn[MAXN], wnn[MAXN], fac[MAXN], facn[MAXN], f[MAXN], g[MAXN];
int n, m, k, Inv[MAXN], rev[MAXN], a[MAXN], b[MAXN], e[MAXN], d[MAXN], c[MAXN],
A[MAXN], B[MAXN], D[MAXN], G[MAXN], AA[MAXN], BB[MAXN], AAA[MAXN],
... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, a[1005][1005], s1[1005][1005], s2[1005][1005], s3[1005][1005],
s4[1005][1005];
vector<pair<long long, pair<long long, long long> > > res;
bool fre[1005][1005];
void trace(long long u, long long v, long long k) {
fre[u][v] = true;
for (int i = 1; i <=... | 5 |
#include <bits/stdc++.h>
using namespace std;
string s;
void init() {}
void input() { cin >> s; }
void solve() {
long long res = 1;
int use = 10;
bool used[10];
for (int i = (0); i < (10); i++) used[i] = false;
int zero = 0;
if (s[0] == '?') res *= 9;
if ('A' <= s[0] && s[0] <= 'J') res *= 9, use--, used[... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, k, x;
vector<int> g[1111];
int dp[1111], o, p, a[1111], cn;
bool w[1111], ok;
vector<int> q;
void dfs(int v) {
w[v] = 1;
for (int i = 0; i < ((int)(g[v]).size()); i++) {
int to = g[v][i];
if (!w[to]) dfs(to);
}
q.push_back(v);
}
void dfs2(int v) {
w... | 2 |
#include <iostream>
using namespace std;
int main(){
int faces[1+6];
for(int i = 1; i <= 6; i++){
cin >> faces[i];
}
int f, tmp;
char direction;
while(cin >> direction){
switch(direction){
case 'N':
f = 5;
break;
case 'E':
f = 3;
break;
case 'S':
f = 2;
break;
case 'W':
f = 4;... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<string> s;
string o = "halfplus";
int n, p;
cin >> n >> p;
for (int i = 0; i < n; i++) {
string y;
cin >> y;
s.push_back(y);
}
reverse(s.begin(), s.end());
long long ans = 0, r = 0;
for (int i = 0; i < s.size(); i++) {
a... | 1 |
#include <bits/stdc++.h>
using namespace std;
const char nl = '\n';
const int MAX_N = 100011;
const long long INF = (1 << 29) + 123;
const long long MOD = 998244353;
const long double PI = 4 * atan((long double)1);
template <typename T>
bool ckmin(T& a, const T& b) {
return a > b ? a = b, 1 : 0;
}
template <typename ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
if (a < b) swap(a, b);
if (b == 0) return a;
while ((a = a % b) != 0) {
swap(a, b);
}
return b;
}
long long modpow(long long x, int y) {
long long res = 1;
while (y > 0) {
if (y & 1) res = res * x % 1000000007;
y = y >> 1;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;
#define eps (1e-10)
struct Point{
double x,y;
Point(){}
Point(double x,double y):x(x),y(y){}
Point operator+(... | 0 |
#include <bits/stdc++.h>
using namespace std;
static const double EPS = 1e-8;
int main() {
istream &fin = cin;
ostream &fout = cout;
FILE *fpin = stdin;
FILE *fpout = stdout;
int N, K;
fin >> N >> K;
string P, occ;
fin >> P >> occ;
bool ok = true;
string res(N, ' ');
for (int i = 0; i < (int)occ.s... | 4 |
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#includ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
long long ans = 0;
for (int i = (0); i < (n); ++i) {
long long t, T, x, cost;
cin >> t >> T >> x >> cost;
if (t >= T) {
ans += cost + m * x;
continue;
}
long long aux1 = cost;
if (m > (T - t))... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long DP[11][65][1 << 10][2];
int a[65], len;
long long getdp(int base, int i, int mask, int zero, int eq) {
if (i == 0) return !mask && !zero;
if (!eq && ~DP[base][i][mask][zero]) return DP[base][i][mask][zero];
long long ret = 0;
int up = (eq ? a[i] : base - 1... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int delta = (int)1e9 + 7;
int x, y, z, ans;
int gcd(int a, int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int lca(int a, int b) { return (a * b) / gcd(a, b); }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> x >> y >> z;
x = lca(x... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
long long n;
long long t1(0), t2(0);
long long mn = 0, mx = 0;
cin >> n;
vector<long> vec(n, 0);
for (long i = 0; i < n; i++) {
cin >> vec[i];
}
sort(vec.begin(), vec.end());
mn = vec[0];
mx = vec[n - 1];
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
int32_t main() {
ios::sync_with_stdio(0), cin.tie(0);
int n;
cin >> n;
vector<int> arr(2 * n + 1);
int cur = 1;
for (int i = 1; i < n; i += 2, cur++) {
int pos = n - i + cur;
arr[cur] = arr[pos] = i;
}
cur = n + 1;
fo... | 4 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll a, b, c;
vector<pair<double, double>> gen(ll x, ll y) {
vector<pair<double, double>> p;
p.push_back({x, double(-c - a * x) / b});
p.push_back({double(-c - b * y) / a, y});
return p;
}
double dst(double xa, double ya, double xb, double yb) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
bool vis[10][10][10];
char grid[10][10][10];
struct Point {
int x, y, step;
friend bool operator<(const Point a, const Point b) {
return a.step > b.step;
}
} p, newp, sta, des;
priority_queue<Point> q;
int dx[8] = {0, 0, 1, -1, 1, -1, -1, 1};
int dy[8] = {1, -1, 0... | 1 |
#include <bits/stdc++.h>
using namespace std;
int overall = 0, n, m, visited[300009];
vector<int> adj[300009];
set<pair<int, int> > s;
int c[4];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> m;
for (int i = 1; i <= m; i++) {
int u, v;
cin >> u >> v;
s.in... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int M = 25;
const int N = 1e5 + 20;
int n, q, tot, cnt;
int a[N], lg[N], ans[N];
struct node {
int l, x, id;
bool operator<(const node& a) const {
if (l != a.l) return l < a.l;
return x < a.x;
}
} b[N];
int xxj[M + 5];
void getxx... | 6 |
#include <bits/stdc++.h>
using namespace std;
int N, M;
void solve() {
cin >> N;
vector<int> A(N);
for (int i = 0; i < N; i++) cin >> A[i];
cin >> M;
vector<int> B(M);
for (int i = 0; i < M; i++) cin >> B[i];
sort(A.begin(), A.end());
sort(B.begin(), B.end());
int sA = N * 3;
int sB = M * 3;
int m... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long MODULO = 1000000007;
void ftime() {}
void print_arr(int n, bool arr[]) {
for (int i = 0; i < n; i++) {
cout << arr[i] << " ";
}
cout << "\n";
}
void print_arr(int n, int arr[]) {
for (int i = 0; i < n; i++) {
cout << arr[i] << " ";
}
cout... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, f = 0;
cin >> n;
for (int i = 0; i < n; i++) {
f = 0;
string s, t;
cin >> s >> t;
for (int j = 0; j < s.size(); j++)
for (int h = 0; h < s.size(); h++)
if (s... | 2 |
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
template<typename V> class segtree{
private:
int n,sz; vector<V> node, lazy;
public:
segtree(vector... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n;
int a[50000];
long long cnt = 0;
long long how(int ind, int level) {
if (level > n) return 0;
long long ch1 = how(2 * ind, level + 1);
long long ch2 = how(2 * ind + 1, level + 1);
cnt += abs(ch1 - ch2);
a[ind] += max(ch1, ch2);
return a[ind];
}
int main()... | 2 |
#include <bits/stdc++.h>
using namespace std;
#define INF (1<<29)
int N,M;
int bfs(int s,int g){
queue<int> Q;
Q.push(s);
int d[1<<N];
fill(d,d+(1<<N),INF);
d[s] = 0;
while(!Q.empty()){
int S = Q.front(); Q.pop();
if(S == g) return d[S];
for(int i = 0 ; i < N-1 ; i++){
int nS =... | 0 |
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
int k;
cin>>k;
int N=50;
cout<<N<<endl;
int a[N];
for(int i=0;i<N;i++) a[i]=N-1;
int p=k/50;
for(int i=0;i<N;i++) a[i]+=p;
int q=k%50;
for(int i=0;i<q;i++) a[i]+=N-(q-1);
for(int i=q;i<N;i++) a[i]-=q;
for(int i=0;i... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
for (int q = 0; q < t; q++) {
int n;
cin >> n;
long long fs[n];
for (int i = 0; i < n; i++) {
cin >> fs[i];
}
sort(fs, fs + n);
long long maybe = fs[n - 1] * fs[0];
vector<int> facts;
for (int i =... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, a[100002];
pair<int, int> nxt[20][100002];
vector<pair<int, int>> st;
void prec() {
int nxt[2] = {-1, -1};
for (int i = n - 1; i >= 0; --i)
::nxt[0][i].first = nxt[0], ::nxt[0][i].second = nxt[1], nxt[a[i]] = i;
for (int d = 1; d < 20; ++d)
for (int i =... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MaxN = 200005;
const long long Base = 127;
const long long Mod1 = 1000000007;
const long long Mod2 = 1000000009;
long long power_base1[MaxN], power_base2[MaxN];
struct Hash {
int len;
vector<long long> Val1, Val2;
void init(string &s) {
len = s.length();... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long Maxn = 200020;
struct edge {
long long t, nxt;
};
edge road[500005];
long long cnt;
long long head[Maxn];
void add(long long u, long long v) {
cnt++;
road[cnt].t = v;
road[cnt].nxt = head[u];
head[u] = cnt;
return;
}
long long s[Maxn], d[Maxn];
l... | 5 |
#include <bits/stdc++.h>
int nod(int x, int y) {
int i, j, m, t;
t = 0;
if (x < y) i = x + 1;
if (x >= y) i = y + 1;
while (t == 0) {
i = i - 1;
if (((x % i) == 0) && ((y % i) == 0)) t = 1;
}
return i;
}
int main(void) {
int x, y, s, t, l1, k;
long int a, b;
scanf("%d", &x);
scanf("%d", &y... | 1 |
#include <bits/stdc++.h>
using namespace std;
const double pi = 3.14159265359;
int counter[100001];
int main() {
int t, n, most_freq, num_or_most_freq, x;
cin >> t;
while (t--) {
cin >> n;
most_freq = 0;
memset(counter, 0, sizeof(counter));
for (int i = 0; i < (int)(n); ++i) {
cin >> x;
... | 3 |
#include <iostream>
using namespace std;
int main() {
string s;
cin >> s;
cout << ((s[0] != s[1] && s[1] != s[2] && s[2] != s[0])? "Yes" : "No") << endl;
return 0;
} | 0 |
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include... | 0 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=1e6+10,mod=1e9+7,inf=0x3f3f3f3f3f3f3f3f;
struct sc
{
ll id,dis;
bool operator<(const sc &a)const
{
return a.dis<dis;
}
}p[N];
vector<sc>link1[N],link2[N];
ll n,m,val1[N],val2[N],dis1[N],dis2[N],vis[N],a[N],b[N],c[N];
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
int n, m, q;
int f[N * 2];
int find(int x) { return f[x] == x ? x : f[x] = find(f[x]); }
int main() {
scanf("%d%d%d", &n, &m, &q);
iota(f + 1, f + n + m + 1, 1);
int cnt = n + m - 1;
while (q--) {
int a, b;
scanf("%d%d", &a, &b);
b ... | 2 |
#include <bits/stdc++.h>
int main() {
int n, alice = 0, bob = 0, i, j, bar[100005];
scanf("%d", &n);
for (i = 0; i < n; i++) scanf("%d", &bar[i]);
for (i = 0, j = n - 1; i < j;) {
if (alice == bob)
alice += bar[i++], bob += bar[j--];
else if (alice > bob)
bob += bar[j--];
else
alic... | 3 |
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+7;
long long dp[N], x[N], premin[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m, T;
cin>>n>>m>>T;
premin[0] = 1e18;
for (int i=1; i<=n; i++) {
cin>>x[i];
premin[i] = min(dp[i-1]-2*x[i], premin[... | 0 |
#include <iostream>
using namespace std;
int N,a[100010];
int main(){
cin >> N;
int i;
for (i=1; i<=N; i++) cin >> a[i];
int ans=0;
for (i=1; i<=N; i++)
if (a[a[i]]==i) ans++;
cout << ans/2 << "\n";
return 0;
}
| 0 |
#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
void qread(int &x) {
int neg = 1;
x = 0;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') neg = -1;
c = getchar();
}
while (c >= '0' && c <= '9') x = 10 * x + c - '0', c = getchar();
x *= neg;
}
const int maxn = 20... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
long long bin = 2, cur, f = 4, s = 0;
while (n -= 2) {
(bin <<= 1) %= 1000000009;
cur = (bin + 1000000009 - 3) % 1000000009;
(f *= cur) %= 1000000009;
(s += f) %= 1000000009;
}
long long ans = (s * s * 2 + 8 * s + 10... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
cin.tie(NULL);
ios_base::sync_with_stdio(false);
int k, n, c = 0, f = 0;
string str;
cin >> str >> k;
n = str.size();
for (int i = n - 1; i >= 0 && k != 0; i--) {
if (str[i] == '0') {
k--;
f = 1;
continu... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, nxt[200005], at, to;
long long k, p;
long long x[200005], y[200005];
long long ans;
int main() {
scanf("%d%lld", &n, &k);
for (int i = 0; i < n; i++) {
scanf("%lld", x + i);
y[i + 1] = y[i] + x[i];
}
nxt[n] = n;
for (int i = n - 1; i >= 0; i--)
... | 4 |
#include <bits/stdc++.h>
void no() {
printf("NO");
exit(0);
}
void yes() {
printf("YES");
exit(0);
}
int main(int argc, char *argv[]) {
int aa = 0, ba = 0, ca = 0;
char str[5015];
for (int i = 0; i < 5015; i++) str[i] = '\0';
scanf("%s", str);
for (int i = 0; str[i] != '\0'; i++) {
if (aa == 0 && ... | 1 |
#include <iostream>
#include <memory>
#include <memory.h>
#include <cmath>
#include <fstream>
#include <cmath>
#include <numeric>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <sstream>
#include <cstdlib>
#include <cassert>
#include <cstdio>
#include <map>
#include <iomanip>
#include <l... | 0 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("avx")
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-function"
using namespace std;
inline int read_char() {
static char buf[1 << 16], *ptr = buf, *end_ptr = buf;
if (ptr == end_p... | 5 |
#include <bits/stdc++.h>
using namespace std;
int num[33], p, n, cnt = 0, a[33], ans[33];
unsigned short dp[33][33][50000 + 5], pre[33][33][50000 + 5];
int w(int x) { return x >= 10 ? 100 : 10; }
void update(int x, int y, int z, int k, bool flag) {
if (!dp[x][y][z]) dp[x][y][z] = flag ? 2 : 1, pre[x][y][z] = k;
}
voi... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <class A, class B>
inline bool mina(A &first, B second) {
return (first > second) ? (first = second, 1) : 0;
}
template <class A, class B>
inline bool maxa(A &first, B second) {
return (first < second) ? (first = second, 1) : 0;
}
const int MAXN = 1005;
int N, ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int mo = 1000000007;
long long n, ans[40], Ans, nn;
int K, h2[40];
struct O {
long long a[40][40];
} E, A[40], B[70], C;
O operator*(const O &A, const O &B) {
for (int i = 0; i <= K; ++i)
for (int j = 0; j <= K; ++j) {
C.a[i][j] = 0;
for (int k = 0... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void read(T& x) {
char c = getchar();
T p = 1, n = 0;
while (c < '0' || c > '9') {
if (c == '-') p = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
n = n * 10 + c - '0';
c = getchar();
}
x = p * n;
}
template <class T, c... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 1e5 + 100;
inline int read() {
int X = 0;
bool flag = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') flag = 0;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
X = (X << 1) + (X << 3)... | 2 |
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
const int INF = 0x3f3f3f3f, N = 2e6 + 5, MOD = 1e9 + 7;
long long qpow(long long a, long long b) {
long long res = 1;
for (; b; b >>= 1, a = a * a % MOD)
if (b & 1) res = res * a % MOD;
return res;
}
class Tree {
public:
int n, siz[N]... | 6 |
#include<bits/stdc++.h>
using namespace std;
int n,a,b,f[5005];
long long dp[5005][5005];
int main()
{
scanf("%d%d%d",&n,&a,&b);
for(int i=1;i<=n;i++)
{
int x;
scanf("%d",&x);
f[x]=i;
}
for(int i=1;i<=n;i++)
{
int pos=f[i];
long long t=1e18;
for(in... | 0 |
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
const long long big = 1000000007ll;
const long long big2 = 1000000009ll;
long long n, m, k, q, w, h;
string vows = "aeiou";
string s;
bool vow[30] = {0};
int main() {
long long a, b, c, d, e;
for (long long c1 = 0; c1 < 5; c1++) {
vow[vo... | 1 |
#include <bits/stdc++.h>
using namespace std;
struct item {
int u, w;
} a[100005];
vector<int> vc[100005];
int f[100005], n, m;
double sum[100005];
bool vis[100005];
int find(int u) {
if (f[u] == u)
return f[u];
else
return f[u] = find(f[u]);
}
int cmp(item a, item b) { return a.w > b.w; }
int main() {
... | 4 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.