solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <iostream>
#include <algorithm>
#include <cstring>
typedef long long ll;
const ll MOD = 1000000007ll;
int N, L;
int X[5000], A[5000];
ll BIT[2][5001];
inline void add(int k, ll v, ll (&bit)[5001]){
k += 1;
while(k <= L){
bit[k] = (bit[k] + v) % MOD;
k += k & -k;
}
}
inline ll s... | 0 |
#include <cstdio>
#include <cctype>
#include <utility>
#include <vector>
#include <tuple>
#include <algorithm>
using namespace std;
#define gcu getchar_unlocked
#define pcu putchar_unlocked
#define _T template <typename T>
#define _HT template <typename H, typename... T>
#define _il inline
#define _in _il int in
#defi... | 0 |
#include <bits/stdc++.h>
using namespace std;
int sum( int n, int s, int x ) {
if( n == 0 ) {
return s == 0;
}
int result = 0;
for( int i = x; i <= 9; ++i ) {
result += sum( n-1, s-i, i+1 );
}
return result;
}
int main() {
ios_base::sync_with_stdio( false );
int n, s;
while( cin >> n >> s ) {
if( n... | 0 |
#include <stdio.h>
#include <queue>
using namespace std;
int main(){
int temp;
priority_queue<int> q;
char a[1000];
while(1){
scanf("%s",a);
if(a[2]=='d')return 0;
scanf("%d",&temp);
if(a[2]=='s'){
q.push(temp);
}
if(a[2]=='t'){
printf("%d\n",q.top());
q.pop();
}
}
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const long mod=1e9+7;
int main() {
long K,A,B;
cin >> K >> A >> B;
if(A>=B-2)cout << K+1;
else cout << (K-A+1)/2*(B-A)+(K-A+1)%2+A;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main () {
ll n;
cin >> n;
int sol = 0;
for (ll i = 2; i * i <= n; i++) {
if (n % i) continue;
int cur = 0;
while (n % i == 0) {
cur++;
n /= i;
}
for (int j = 1; j <= cur; j++) {
cur -= j;
sol++;
}
}
sol += (n > ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
vector<long> v(n + 1);
v[0] = 0;
for (int i = 1; i <= n; i++) {
cin >> v[i];
}
sort(v.begin(), v.end());
long x, y;
if (n < k) {
cout << -1;
return 0;
}
x = v[n - k];
y = x;
x++;
cout << x << " " ... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long cost[100005], INVv[100005];
vector<long long> v[100005];
map<string, long long> mp;
string str[100005];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n, k, m, sum = 0;
cin >> n >> k >> m;
for (long long i = 1; i <= n; i++) ci... | 2 |
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-12;
const long long SZ = 55, SSZ = 21, APB = 52, one = 11;
const long long INF = 0x7f7f7f7f, mod = 1000000007;
long long n, m;
char ch[SZ][SSZ];
bool vst[1LL << 20], ok[1LL << 20];
vector<long long> vct;
long long core[1LL << 20], same[SZ][SSZ];
double... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, h;
int a[200005], b[200005];
int ans, cur, cnt = 1;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(0);
cin >> n >> h;
for (int i = 1; i <= n; ++i) cin >> a[i] >> b[i];
ans = b[1] - a[1];
for (int i = 2; i <= n; ++i) {
cur += a[i] ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5;
const long long mod = 1e9 + 7;
int r, g;
long long f[maxn + 10];
int main() {
scanf("%d%d", &r, &g);
int h = 0;
while ((h + 1) * (h + 2) <= 2 * (r + g)) ++h;
f[0] = 1;
for (int i = 1; i <= h; ++i) {
for (int j = r; j >= i; --j)
f[j]... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
char a[100010], b[100010];
long long expmod(long long a, long long b, long long mod) {
long long rlt = 1;
for (a %= mod; b; a = a * a % mod, b >>= 1)
if (b & 1) rlt = rlt * a % mod;
return rlt;
}
int eval(int x, int P, vector<int>& w) {
int rlt = 0;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long fac[500005];
map<long long, long long> prime;
long long power(long long x, long long y, long long p) {
long long res = 1;
x = x % p;
while (y > 0) {
if (y & 1) res = ((res % p) * (x % p)) % p;
y = y >> 1;
x = ((x % p) * (x % p)) % p;
}
return... | 3 |
#include<stdio.h>
int a[200000];
int main()
{
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
int minl=a[1];
int maxl=-1000000000;
for(int i=2;i<=n;i++)
{
if((a[i]-minl)>maxl)
{
maxl=a[i]-minl;
}
if(a[i]<minl)
{
minl=a[i];
}
}
printf("%d\n",maxl);
return 0;
} | 0 |
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
typedef long long int lli;
const lli maxn = lli(1e5)+5;
lli x[maxn], v[maxn], suff[maxn], pref[maxn];
int main(void)
{
lli n, c;
scanf("%lld%lld", &n, &c);
for(lli i = 1;i <= n;i++) scanf("%lld%lld", &x[i], &v[i]);
lli vsum = 0, res =... | 0 |
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
... | 0 |
#include <bits/stdc++.h>
using namespace std;
vector<int> bt;
int par[305];
queue<int> pos;
stack<int> sta;
int cnt[305][305];
bool valid;
vector<int> hasil, adj[305];
void bfs(int S, int T) {
memset(par, -1, sizeof(par));
while (!pos.empty()) pos.pop();
pos.push(S);
par[S] = 0;
while (!pos.empty()) {
int... | 4 |
#include <cstdio>
#include <algorithm>
int main() {
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
printf("%d\n", std::min({a+b, b+c, c+a}));
} | 0 |
#include <bits/stdc++.h>
long long a[200009], prefix[2 * 200009];
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL), cout.tie(NULL);
int t;
cin >> t;
while (t--) {
long long n, k, i;
cin >> n >> k;
for (i = 1; i <= n; i++) cin >> a[i];
memset(prefix, 0, sizeof(prefix... | 2 |
#include <bits/stdc++.h>
using namespace std;
void preprocess(void) { return; }
map<int, int> mm;
void take() {
int k;
cin >> k;
mm.clear();
for (auto i = (0); i < k; i++) {
string st;
cin >> st;
for (auto j = (0); j < st.length(); j++) {
mm[(st[j] - '0')] = i;
}
}
}
bool check() {
if ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long long N = (long long)2e5 + 5;
const long long mod = (long long)1e9 + 7;
int main() {
long long n, k, cur;
cin >> n >> k >> cur;
long long res = 0;
for (long long i = 1, x; i < n; i++) {
cin >> x;
long long y = cur % k;
if (y > 0) y = k - y;
... | 4 |
#include <iostream>
#include <algorithm>
#include <sstream>
using namespace std;
string itos (int n )
{
stringstream ss;
ss << n;
return ss.str();
}
void x2n (string & s, int n )
{
string cn = itos (n );
while (s.find ('X' ) != string::npos )
s = s.replace(s.find('X'), 1, cn );
}
string longlongadd (string... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5 + 5;
const int MAX_LG = 20;
namespace DSU {
int p[MAX_N], r[MAX_N];
void init(int n) {
iota(p, p + n + 1, 0);
fill_n(r, n + 1, 0);
}
int find(int x) { return x == p[x] ? x : (p[x] = find(p[x])); }
bool union_(int x, int y) {
x = find(x), y = find... | 5 |
#include<bits/stdc++.h>
using namespace std;
const int P=998244353;
const int N=2e4+5;
int n,m,k,len,r[N];
long long ans,Inv,f[N],g[N],h[N],fac[N],inv[N];
long long fsp(long long x,int y){
long long ans=1;
while(y){
if(y&1) ans=ans*x%P;
y>>=1,x=x*x%P;
}
return ans;
}
void NTT(long long *d,int f){
for(int i=1;i... | 0 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
bool cmpx(const pll& a, const pll& b) { return a.first < b.first; }
bool cmpy(const pll& a, const pll& b) { return a.second < b.second; }
ll sq(const ll& first) { return first * first; }
ll dis(const pll& a, const pll& b) {
... | 4 |
#include <bits/stdc++.h>
inline int read() {
int s = 0, w = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') w = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
return s * w;
}
using namespace std;
long long dp[5003][5003];
signed main... | 2 |
#include <bits/stdc++.h>
int main()
{
std::string s1, s2;
std::cin >> s1 >> s2;
using vi = std::vector<int>;
std::vector<vi> dp(s1.size() + 1, (vi(s2.size() + 1)));
for (int i{}; i <= (int)s1.size(); i++)
dp[i][0] = i;
for (int i{}; i <= (int)s2.size(); i++)
dp[0][i] = i;
for (int i{1}; i <= (int)s1.size();... | 0 |
#include <bits/stdc++.h>
using namespace std;
void update(long long &a, long long b) {
if (b > a) a = b;
}
long long qmin(long long a, long long b) { return (a < b) ? a : b; }
int T;
int n;
pair<int, long long> a[5050];
long long dp[2][5050];
int main() {
scanf("%d", &T);
while (T--) {
scanf("%d", &n);
fo... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, i, j, cnt = 0;
cin >> n;
set<char> s;
for (i = 0; i < 26; i++) s.insert(i + 'a');
for (i = 0; i < n - 1; i++) {
char c;
string str;
cin >> c >> str;
if (c == '!') {
... | 3 |
#include<iostream>
using namespace std ;
int main(){
long long r,d,x ;
cin >> r >> d >> x ;
for(int i=0;i<10;i++){
x = x*r-d ;
cout << x << endl ;
}
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int tmp;
cin >> tmp;
char c;
set<long long> s;
long long a;
string t;
map<long long, int> mp;
map<string, int> res;
while (tmp--) {
cin >> c;
if (c == '+') {
cin >> a;
if... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, i, j;
int q[100], s[100], r[100];
int p[201][100];
int up, down;
bool trouveup = false, trouvedown = false, trivial = true, ok;
scanf("%d %d\n", &n, &k);
for (i = 0; i < n; i++) {
scanf("%d", &q[i]);
q[i]--;
r[q[i]] = i;
}
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int X,Y,Z;
int main () {
cin >> X >> Y>> Z;
cout << (X-Z)/(Y+Z) << endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n, k;
cin >> n >> k;
priority_queue<pair<int, int> > p;
set<int> s;
for (int i = 1; i <= n; i++) {
int in;
cin >> in;
p.push({in, i});
s.insert(i + k);
}
long long ans = 0;
vector<int> v(n);
while (p.size()) {
int c =... | 3 |
#include <bits/stdc++.h>
using namespace std;
char symbol;
int a[50][50];
int n, m, answer;
bool Satisfy(int i1, int j1, int i2, int j2) {
int square;
square = a[i2][j2] - a[i1 - 1][j2] - a[i2][j1 - 1] + a[i1 - 1][j1 - 1];
return !square;
}
int main() {
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; i++) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
struct FBS {
int n, m;
vector<int> father;
void init(int n) {
this->n = n;
father.resize(n + 2);
for (int i = 1; i <= n; i++) father[i] = -1;
}
int find(int x) {
int p = x;
while (father[p] > 0) p = father[p];
while (x != p) {
int t =... | 4 |
#include <bits/stdc++.h>
using namespace std;
vector<int> vec;
long long n, w;
int ar[int(2e5) + 5];
long long calc() {
if (w % 2 == 1) {
return w / 2 + 1;
}
return w / 2;
}
int main() {
int T;
cin >> T;
while (T--) {
cin >> n >> w;
vec.clear();
for (int i = 0; i < n; i++) {
cin >> ar[... | 1 |
#include <bits/stdc++.h>
int main() {
int n;
std::vector<int> A;
std::vector<int> B;
std::vector<int> actions;
std::cin >> n;
for (int i = 0; i < n; i++) {
int t;
std::cin >> t;
A.push_back(t);
}
for (int i = 0; i < n; i++) {
int t;
std::cin >> t;
B.push_back(t);
}
for (int i... | 4 |
#include <iostream>
using namespace std;
int k,x;
int main()
{
cin>>k>>x;
for(int i=x-k+1;i<=x+k-1;i++)
cout<<i<<" ";
cout<<endl;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int n;
int arr[100010];
int gd(int str) {
int cnt = 0;
if (arr[str] == 0) {
for (int i = str + 1; i < n; i++)
if (arr[i] != 0) cnt++;
return min(cnt, 2);
}
for (int i = str + 1; i + 1 < n && cnt < 2; i++) {
if (arr[str] * arr[i + 1] != arr[str + 1]... | 4 |
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
int main(){
ios_base::sync_with_stdio(false);
ll n, m, k;
cin >> n >> m >> k;
vector<ll> p;
const ll init = n % 10;
ll x = init;
do {
p.push_back(x);
x = (x * init) % 10;
} while(x != in... | 0 |
#include<iostream>
#include<string>
using namespace std;
int main(){
int N;
string S;
cin >> N >> S;
int a=-1;
int b=-1;
int c=-1;
int count=0;
for(int i=1000;i<2000;i++){
int j=i%10;
int k=((i-j)/10)%10;
int l=(i-1000)/100;
int c[3];
c[0]=l;c[1]=k;c[2]=j;
int f=0;
for(int m=... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
int n, m, k;
map<string, int> mp;
string Key[1005];
string GerStr() {
string res = "", s = "";
char c;
while ((c = getchar()) != '(')
if (c != ' ') res += c;
res += '|';
while ((c = getchar()) != '\n') {
if (isalnum(c))
s += c;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
bool check(long long x, long long pos) { return (x & (1LL << pos)); }
int main() {
long long s, xr, nd;
cin >> s >> xr;
if ((s - xr) % 2) {
cout << "0\n";
return 0;
}
nd = (s - xr) / 2;
long long ans = 1;
bool no = false;
for (long long i = 0; i < 63... | 1 |
#include <bits/stdc++.h>
using namespace std;
bool accept(long long u);
long long n, k, a[100010], b[100010], dau, cuoi, mid;
int main() {
ios::sync_with_stdio(0);
cin >> n >> k;
for (long long i = (1), _b = (n); i <= _b; i++) cin >> a[i];
for (long long i = (1), _b = (n); i <= _b; i++) cin >> b[i];
dau = 0;
... | 4 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;
int main() {
int x, y, z, k;
cin >> x >> y >> z >> k;
vector<ll> a(x), b(y), c(z);
rep(i, x) cin >> a[i];
rep(i, y) cin >> b[i];
rep(i, z) cin... | 0 |
#include <bits/stdc++.h>
using namespace std;
int dp[100010][3];
vector<int> v;
int n;
int solve(int i, int op, int last) {
if (i == n) {
return 0;
}
if (dp[i][op] != -1) {
return dp[i][op];
}
int ans = 0x3f3f3f3f;
int aux = op;
if (aux == 2) {
aux = -1;
}
int aux2 = last;
if (aux2 == 2)... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return a ? gcd(b % a, a) : b; }
int main() {
long long n, m, k;
cin >> n >> m >> k;
bool isEven = k % 2 == 0;
long long p = n * m;
if (isEven) k /= 2;
if (p % k != 0) {
cout << "NO" << endl;
return 0;
}
long ... | 4 |
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2002;
pair<int,int> arr[N];
int dp[N][N];
int solve(int i,int l,int r)
{
if(l > r) return 0;
int & ans = dp[l][r];
if(ans != -1) return ans;
ans = 0;
// place at left
ans = arr[i].first*abs(l - arr[i].second) ... | 0 |
#include <bits/stdc++.h>
using namespace std;
string s1, s2;
long long int x = 0, y = 0;
bool check() {
if (x > y) {
y = x - 1;
if (s2[y + 1] != '\0') {
if (s1[x] == '0' && s2[y] == '0' && s2[y + 1] == '0') {
s1[x] = '-';
s2[y] = '-';
s2[y + 1] = '-';
return true;
}... | 4 |
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
vector<int> path[100005];
int t[100005];
int s[100005];
queue<int> q1;
int main(){
int n,m;
int i,j,k;
int a,b;
cin>>n>>m;
for(i=0;i<n-1+m;i++){
cin>>a>>b;
a--,b--;
t[b]++;
path[a].push_back(b);
}
for(i=0;i<n;i++){
if(t[i]==0){a=i... | 0 |
#include <bits/stdc++.h>
long long num_items(long long num_pairs) {
double delta_sqrt_float = sqrt(1 + 8 * num_pairs);
long long delta_sqrt = (long long)delta_sqrt_float;
if (delta_sqrt_float - delta_sqrt != 0) return -1;
long long result;
long long result_1 = (1 + delta_sqrt);
long long result_2 = (1 - del... | 2 |
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
char c=getchar();bool f=0;x=0;
while(!isdigit(c)) f|=c=='-',c=getchar();
while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
if(f) x=-x;return x;
}
template<class t> inline void write(t x){
if(x<0) putchar('-'),write(-x);
else{... | 0 |
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
#define int long long
#define inf 1000000007
#define mp make_pair
#define pb push_back
#define ppa pair<int,pair<int,int>>
using namespace std;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int a,b,c,d;
int yar... | 0 |
#include <bits/stdc++.h>
using namespace std;
bool gg[2000];
int sz[2000], par[2000];
char s[100][2000];
int dp[2000][2000];
int C(int n, int m) {
if (n < m || m < 0) return 0;
if (n == 0 || n == m) return 1;
if (dp[n][m]) return dp[n][m];
if (n - m < m) return dp[n][m] = C(n, n - m);
return dp[n][m] = (C(n -... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n;
long double p, q;
long double a[N], b[N];
inline long double F(long double x) {
long double y = 1e130;
for (int i = 1; i <= n; i++) y = min(y, (1.0 - a[i] * x) / b[i]);
return p * x + q * y;
}
int main() {
double _p, _q, _a, _b;
scanf(... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = numeric_limits<long long>::max();
const long long nax = (long long)(100001);
const long long mod = 1e9 + 7;
template <class X, class Y>
bool maximize(X& x, const Y y) {
if (y > x) {
x = y;
return true;
}
return false;
}
template <class X,... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string k;
cin >> k;
int st = 0;
while (st < (int)k.length() && k[st] == 'a' && 1) {
st++;
}
if (st == (int)k.length()) {
k[k.length() - 1] = 'z';
cout << k << endl;
return 0;
}
int se = st + 1;
while (se < (int)k.length() && k[... | 3 |
#include <iostream>
using namespace std;
int main()
{
int a, b, c;
cin >> a >> b >> c;
if (a+b+c <=21)
cout << "win";
else
cout << "bust";
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000 * 1000 + 5;
int a[MAXN], b[MAXN];
int main() {
ios_base::sync_with_stdio(false);
string s;
cin >> s;
int st = 0, k = 0, prev = -1;
for (size_t i = 0; i < s.length(); i++) {
if (st == 0) {
if ('a' <= s[i] && s[i] <= 'z')
a[k]... | 5 |
#include <bits/stdc++.h>
using namespace std;
int a[105];
int main() {
int n, k;
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int ans = 0;
for (int i = 0; i < k; i++) {
int cnt1 = 0, cnt2 = 0;
for (int j = 0; j < n / k; j++) {
if (a[i + j * k] == 1)
cnt1++;
els... | 1 |
#include <bits/stdc++.h>
using namespace std;
long double dis(double x, double y, double x1, double y1) {
return sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1));
}
double PI = 3.14159265;
double e = 2.718281828;
void EnGz() {
ios::sync_with_stdio(0);
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
}
long... | 3 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = long unsigned long;
using ld = double long;
template <class T = int, class F = plus<T>>
struct segtree {
int maxn;
vector<T> a;
T e;
F f;
segtree(int n, T e = T(), F f = F(), T v = T()) : e(e), f(f) {
maxn = 1;
while (maxn... | 5 |
#include <bits/stdc++.h>
using namespace std;
char a[100100], b[100100];
int cnt[15];
int main() {
scanf("%s%s", &a, &b);
int m = strlen(b);
int n = strlen(a);
for (int i = (0); i < (m); ++i) cnt[b[i] - '0']++;
int cur = 9;
for (int i = (0); i < (n); ++i) {
while ((cur >= 0) && (cnt[cur] == 0)) cur--;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 6, nBits = 2e8 + 5, MM = (1 << 16), MAX = 1111,
OO = 0x3f3f3f3f, MOD = 1e9 + 7, inf = 1 << 30;
const long long INF = (long long)1e18;
long long GCD(long long a, long long b) { return !b ? a : GCD(b, a % b); }
long long LCM(long long x, long lon... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, m, p, total, belong[222], sum[222], v[222], len[222], to[222][22],
f[2][222][222][555];
vector<int> record, l, r, st[222], data[1000050];
int Rand() { return (rand() << 15) | rand(); }
int Solve(vector<int> ask) {
int len = ask.size(), answer, i, j, k, digit, n... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
string s;
int i, dep = 0, h, np = 1, last, n = 0, af = 0;
cin >> s;
for (i = 0; i < s.length(); i++) {
switch (s[i]) {
case '(': {
dep++;
break;
}
case ')': {
dep--;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxi = 54321;
int papa[maxi];
int from[maxi], to[maxi];
int range[maxi];
bool visited[maxi];
void init(int n) {
for (int i = 0; i <= n; i++) {
papa[i] = i;
}
}
int get(int x) { return (x == papa[x] ? x : papa[x] = get(papa[x])); }
int main() {
int n, m;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
void pairsort(long long int a[], long long int b[], long long int n) {
pair<long long int, long long int> pairt[n];
for (long long int i = 0; i < n; i++) {
pairt[i].first = a[i];
pairt[i].second = b[i];
}
sort(pairt, pairt + n);
for (long long int i = 0; i... | 3 |
#include <bits/stdc++.h>
using namespace std;
bool sortbysec(const pair<long long, long long> &a,
const pair<long long, long long> &b) {
return (a.second < b.second);
}
long long nod(long long n) {
string s = to_string(n);
return (long long)s.length();
}
long long modexp(long long x, long long y) {... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T &x) {
x = 0;
int first = 1;
char c = getchar();
for (; !isdigit(c); c = getchar())
if (c == '-') first = -first;
for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
x *= first;
}
int n;
const int MAXN = 888;
int ans[MAXN... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int q, l, r, res;
cin >> q;
vector<int> ans;
for (int i = 0; i < q; i++) {
cin >> l >> r;
if (l % 2 == 1) {
res = (r - l + 1) / 2;
if (r % 2 == 1) {
res = res - r;
}
}... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, counta = 0, countd = 0;
cin >> t;
char s[1000000];
for (int i = 0; i < t; i++) {
cin >> s[i];
if (s[i] == 'A')
counta++;
else
countd++;
}
if (counta > countd)
cout << "Anton";
else if (counta < countd)
cout <... | 1 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
vector<int> cnt(32, 0);
for (int i = 0; i < n; i++) {
int bit = __builtin_clz(a[i]);
cnt[bit] += 1;
}
long long ans = 0;
for (int bit = 0; bit < 32; bit++) {... | 2 |
#include <bits/stdc++.h>
using namespace std;
using INT = long long;
using pii = pair<int, int>;
vector<int> b[200100];
int a[200100];
void update(int u, int x) {
for (; u < 200100; u += u & -u) b[u].push_back(x);
}
int calc(int u, int x, int ans = 0) {
for (; u; u -= u & -u) {
int id = lower_bound(b[u].begin()... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(T& num) {
bool start = false, neg = false;
char c;
num = 0;
while ((c = getchar()) != EOF) {
if (c == '-')
start = neg = true;
else if (c >= '0' && c <= '9') {
start = true;
num = num * 10 + c - '0';
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int N;
const int SIZE = 100005;
int A[SIZE];
int gcd(int a, int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int gd;
bool sat(int n) {
while (!(n % 2)) n /= 2;
while (!(n % 3)) n /= 3;
if (n == 1) return true;
return false;
}
bool solve() {
for (int i = ... | 3 |
//#include "bits/stdc++.h"
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <util... | 0 |
#include <bits/stdc++.h>
const long long int MOD = 1e9 + 7;
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1, -1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
using namespace std;
void vok() {
ios_base::sync_with_stdio(false);
cout.tie(NULL);
cin.tie(NULL);
}
long long int gcd... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, r1, r2;
vector<int> rel[112345];
int path[112345];
bool vis[112345];
void dfs(int i) {
vis[i] = true;
for (int j = 0; j < rel[i].size(); j++) {
if (!vis[rel[i][j]]) {
path[rel[i][j]] = i;
dfs(rel[i][j]);
}
}
}
int main() {
cin >> n >> r1 >... | 4 |
#pragma GCC optimize("O2")
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007LL
#define eps 1e-8
using namespace std;
ll a[100005];
int main()
{
cin.tie(0),ios::sync_with_stdio(0);
ll n,m,v,p; cin>>n>>m>>v>>p;
for(int i=0;i<n;i++) cin>>a[i];
sort(a,a+n);
int l=0,r=n-p,k;
while(l<r){
k=(l+r)>... | 0 |
#include <bits/stdc++.h>
using namespace std;
string a, b, c, d, s;
int main() {
cin >> a >> b;
int m1 = 0, m2 = 0;
for (int i = 0; i < (int)a.size(); i++) m1 += (a[i] == '1');
for (int i = 0; i < (int)b.size(); i++) m2 += (b[i] == '1');
if (m1 & 1) m1++;
if (m1 >= m2)
puts("YES");
else
puts("NO")... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 100;
const double eps = 1e-6;
long long n, l, r, c;
vector<pair<long long, long long> > V[maxn];
map<long long, int> H, H2;
int tot = 0, tot2;
long long gcd(long long x, long long y) {
return x % y == 0 ? y : gcd(y, x % y);
}
int main() {
scanf("%... | 3 |
#include <cstdio>
int main()
{
// freopen("AGC015-D.in", "r", stdin);
long long l, r;
scanf("%lld%lld", &l, &r);
if (l == r)
{
puts("1");
return 0;
}
auto k = l ^ r;
while (k != (k & -k))
k ^= k & -k;
l &= k * 2 - 1;
r &= k - 1;
while (r != (r & -r))
r ^= r & -r;
if (r)
r = r * 2 - 1;
printf("%l... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<string> ss;
string s;
cin >> s;
string t;
cin >> t;
int x1 = s[0] - 'a' + 1, y1 = s[1] - '0';
int x2 = t[0] - 'a' + 1, y2 = t[1] - '0';
if (x1 != x2 && y1 != y2) {
string a = "RU", b = "LU", c = "RD", d = "LD";
string ans;
if ... | 1 |
#include <bits/stdc++.h>
using namespace std;
vector<long long int> adj[100005], d[100005];
vector<long long int> sum[100005];
long long int hasComp[100005], dist[100005], sz[100005];
long long int n, m, q, u, v;
pair<int, int> x;
long long int getfar(long long int i, long long int mark) {
queue<pair<int, int> > q;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int ma = 0;
int ct = 0;
for (int i = 0; i < n; i++) {
ma = max(ma, a[i]);
if (ma == i + 1) {
ct++;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 123;
const int mod = 1000000000 + 7;
using LL = long long;
char digits[maxn];
int n, k;
int fact[maxn];
int rfact[maxn];
int bigmod(int a, int b) {
if (b == 0) return 1;
int ta(bigmod(a, b >> 1));
ta = (LL)ta * ta % mod;
if (b & 1) return (... | 3 |
#include <bits/stdc++.h>
using namespace std;
int ans(int a, int b) {
int answer;
int c = abs(a - b);
if (c % 10 == 0) {
answer = c / 10;
} else {
answer = c / 10 + 1;
}
return answer;
}
int main() {
int t;
cin >> t;
int a[t], b[t];
for (int i = 0; i < t; i++) {
cin >> a[i] >> b[i];
}
... | 1 |
#include <bits/stdc++.h>
using namespace std;
long double eps = 1e-7;
const int N = 1e5 + 10;
long long dp[N][36], mn[N][36], sum[N][36];
long long n, k;
pair<long long, long long> mnAndSum(int node) {
long long sum1 = 0, mn1 = 2e18, k1 = k;
for (long long i = 34; i >= 0; i--)
if ((1LL << i) <= k1)
k1 -= ... | 5 |
#include <bits/stdc++.h>
int main() {
int n, i, d = 0, a = 0;
scanf("%d", &n);
char x;
for (i = 0; i <= n; i++) {
scanf("%c", &x);
if (x == 'D')
d++;
else if (x == 'A')
a++;
}
if (d > a)
printf("Danik");
else if (a > d)
printf("Anton");
else
printf("Friendship");
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
struct SAM_node {
int minlen, maxlen, slink;
int trans[4];
inline void reset(int _minlen, int _maxlen, int _slink, int *_trans) {
minlen = _minlen, maxlen = _maxlen, slink = _slink;
for (int i = 0; i < 4; i++) trans[i] = _trans[i];
return;
}
};
struct ma... | 5 |
#include <bits/stdc++.h>
int main() {
int n, a[400][400], h, i, j, cnt = 1;
scanf("%d", &n);
for (h = 0; 2 * n >= h * (h + 1); h++) {
}
h--;
printf("%d\n", h + 1);
for (i = 0; i < h; i++) {
for (j = i; j < h; j++) {
a[i][j] = cnt;
a[j + 1][i] = cnt;
cnt++;
}
}
for (i = 0; i <... | 3 |
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <tuple>
#include <functional>
using namespace std;
#define rep(i,n) for(int i = 0;i < n;i++)
#define int long long
const int INF = 1e9;
int dx[2][7] =... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxl = 2 * 1000 * 10 + 5;
const int maxm = 10 + 5;
bool adj[maxl][maxm];
int n, m, k;
int grp[maxm], node[maxl];
int main() {
cin >> n >> m >> k;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) cin >> adj[i][j];
for (int i = 0; i < k; i++) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
if (c == 1) {
for (int i = 0; i <= 9; i++) {
if ((10 * a + i) % b == 0) {
cout << 10 * a + i << endl;
return 0;
}
}
cout << -1 << endl;
} else {
if (b == 10) {
cout << a;... | 1 |
#include <bits/stdc++.h>
using namespace std;
vector<int> adj[1000000 + 1];
string x[1000000 + 1];
int val[1000000 + 1];
int siaip[1000000 + 1];
void dfs(int i) {
for (int j : adj[i]) dfs(j);
if (x[i] == "IN") {
siaip[i] = val[i];
}
if (x[i] == "AND") {
siaip[i] = siaip[adj[i][0]] & siaip[adj[i][1]];
... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long const M = 100 + 10, M2 = 1e7 + 10, mod = 1e9 + 7, inf = 1e18 + 10;
long long a[M];
bool mark[M][M];
long long lis[M], n, t;
struct mat {
long long dp[M][M];
mat(long long x) {
for (long long i = 1; i < M - 5; i++) {
for (long long j = 1; j < M - 5; j... | 4 |
#include <bits/stdc++.h>
using namespace std;
inline int add(int a, int b, int m = 1000000007) {
a += b;
if (a >= m) a -= m;
return a;
}
inline int mul(int a, int b, int m = 1000000007) {
return (int)(((long long)a * (long long)b) % m);
}
inline int norm(int x, int m = 1000000007) {
if (x >= m) x %= m;
if (... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100100;
vector<pair<int,int> > e[maxn];
int ans[maxn];
void dfs(int u, int p){
for(auto ee : e[u]){
int to = ee.first;
if(to == p) continue;
int k = ee.second % 2;
ans[to] = ans[u] ^ k;
dfs(to, u);
}
}
int main(){
int n; cin >> n;
for(int i = ... | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.