code_file1
stringlengths 87
4k
| code_file2
stringlengths 82
4k
|
---|---|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
std::fill( (T*)array, (T*)(array+N), val );
}
template<class T> inline bool chmax(T &a, T b){
if(a<b){
a = b;
return true;
}
return false;
}
template<class T> inline bool chmin(T &a, T b){
if(a>b){
a = b;
return true;
}
return false;
}
template<typename T>
T gcd(T a, T b)
{
return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a,T b)
{
return a / gcd(a,b) * b;
}
#define MAX_N 100005
vector<int> prime;
bool is_prime[MAX_N];
void sieve(int n){
for(int i=0;i<=n;i++){
is_prime[i] = true;
}
is_prime[0] = is_prime[1] = false;
for(int i=2;i<=n;i++){
if(is_prime[i]){
prime.push_back(i);
for(int j=2*i;j<=n;j+=i){
is_prime[j] = false;
}
}
}
}
int main(){
sieve(50);
int n;
cin >> n;
vector<ll> a(n);
rep(i,n) cin >> a[i];
int m = prime.size();
ll mi = (1LL<<60);
rep(i,(1<<m)){
ll X = 1;
rep(j,m){
if((i>>j)&1){
X *= prime[j];
}
}
bool ng = 0;
rep(i,n){
if(gcd(X,a[i])==1){
ng = 1;
break;
}
}
if(!ng){
chmin(mi,X);
}
}
cout << mi << endl;
return 0;
} | #include <bits/stdc++.h>
#define pb push_back
#define ss second
#define ff first
#define all(x) x.begin(), x.end()
#define INF 3000000000000001 // 3e15
#define ll_max 9000000000000000000
#define PI 3.14159265358979323846L
#define fill(a, n, x) for(int i = 0; i < n; i++) a[i] = x;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> pll;
const ll mod = 1000000007;
const ll N = 200110;
const ll M = log2(N) + 1;
struct point
{
ll x, y;
};
template<typename T>
T fast_exp(T x,T n)
{
if(n == 0) return 1;
T ans = 1;
if(n % 2 == 0)
{
ans = fast_exp(x, n / 2);
ans = ans * ans % mod;
}
else ans = fast_exp(x, n - 1) * x % mod;
return ans;
}
void update(ll BIT[], ll i, ll x, ll n)
{
if(i <= 0) return;
for(; i <= n; i += i & (-i))
BIT[i] += x;
}
ll query(ll BIT[], ll l, ll r)
{
l--;
ll sum = 0;
while(r > 0)
{
sum += BIT[r];
r = r & (r - 1);
}
while(l > 0)
{
sum -= BIT[l];
l = l & (l - 1);
}
return sum;
}
ll fact[2], infact[2];
void work()
{
fact[0] = fact[1] = infact[0] = infact[1] = 1;
for(ll i = 2; i < N; i++)
{
fact[i] = fact[i - 1] * i % mod;
infact[i] = fast_exp(fact[i], mod - 2);
}
}
ll ncr(ll n, ll r)
{
if(r > n || r < 0) return 0;
return fact[n] * infact[n - r] % mod * infact[r] % mod;
}
vector<int> p;
int smfactor[N + 1]; // smallest prime factor
void SoE(int n = N)
{
bool Primes[n + 1];
Primes[0] = Primes[1] = 0;
for(int i = 2; i < n + 1; i++)
Primes[i] = 1;
for(int i = 2; i <= n; i++)
{
if(Primes[i] == 1)
{
p.push_back(i);
for(int j = i; j <= n; j += i)
{
Primes[j] = 0;
if(smfactor[j] == 0)
smfactor[j] = i;
}
}
}
}
int main()
{
fast;
int _ = 1, test = 0;
SoE(50);
//cin >> _;
while(_--)
{
test++;
ll n, m = 0, x, y, ans = INF, k, q;
cin >> n;
m = p.size();
ll a[n + 1];
for(int i = 1; i <= n; i++)
{
cin >> a[i];
}
y = 1;
for(int j = 0; j < m; j++) y = y * p[j];
ans = y;
for(ll i = 0; i < (1ll << m); i++)
{
y = 1;
for(int j = 0; j < m; j++)
{
if(i & (1ll << j))
{
y = y * p[j];
}
}
bool flag = 1;
for(int j = 1; j <= n; j++)
{
if(__gcd(y, a[j]) == 1)
flag = 0;
}
if(flag)
ans = min(ans, y);
}
cout << ans << "\n";
}
return 0;
}
|
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__);fflush(stderr);
#else
#define eprintf(...) 42
#endif
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
template<typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
return (ull)rng() % B;
}
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
clock_t startTime;
double getCurrentTime() {
return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}
int main()
{
startTime = clock();
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int n, m;
scanf("%d%d", &n, &m);
if (n == 1) {
if (m != 0) {
printf("-1\n");
} else {
printf("1 2\n");
}
return 0;
}
if (m < 0 || m > n - 2) {
printf("-1\n");
return 0;
}
printf("1 10000000\n");
int x = 2;
int k = n - m - 2;
for (int i = 0; i < k + 1; i++)
printf("%d %d\n", x + i, x + k + 1 + i);
x += 2 * (k + 1);
for (int i = 0; i < m; i++) {
printf("%d %d\n", x, x + 1);
x += 2;
}
return 0;
}
| #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
const ll mod = 998244353;
long long modpow(long long a, long long n){
long long r = 1;
while (n) {
r = r * ( (n%2)?a:1 ) %mod;
a = a * a % mod;
n >>= 1;
}
return r;
}
int main(void){
ll n,m,k;cin>>n>>m>>k;
ll res=0;
if(m==1){
ll res=modpow(k,n);
cout<<res<<endl;
return 0;
}
else if(n==1){
ll res=modpow(k,m);
cout<<res<<endl;
return 0;
}
rep(i,k){
ll buf1=modpow(k-i,m),buf2=modpow(k-i-1,m);
ll buf3=modpow(i+1,n);
ll buf4=(((buf1-buf2+mod)%mod)*buf3)%mod;
res+=buf4;
res%=mod;
}
cout<<res<<endl;
} |
//https://atcoder.jp/contests/arc108/tasks/arc108_a
//A - Sum and Product
//从 1 到 sqrt(P) 中枚举是否存在 N 和 M。
#include <bits/stdc++.h>
using namespace std;
//如果提交到OJ,不要定义 __LOCAL
//#define __LOCAL
int main() {
#ifndef __LOCAL
//这部分代码需要提交到OJ,本地调试不使用
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
#endif
long long s,p;
cin>>s>>p;
long long t=sqrt(p);
for (long long i=1; i<=t; i++) {
long long n=i;
long long m=s-i;
if (n*m==p) {
cout<<"Yes\n";
return 0;
}
}
cout<<"No\n";
#ifdef __LOCAL
//这部分代码不需要提交到OJ,本地调试使用
system("pause");
#endif
return 0;
} | #include <iostream>
#include <cstdio>
#include <cstring>
#define int long long
using namespace std;
inline int read()
{
int res = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9')
{
if (c == '-')
f = -1;
c = getchar();
}
while (c >= '0' && c <= '9')
{
res = res * 10 + c - 48;
c = getchar();
}
return res * f;
}
int s, p;
signed main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
s = read(), p = read();
for (int i = 1; i * i <= p; ++ i)
{
if (p % i == 0)
{
if (i + p / i == s)
{
puts("Yes");
return 0;
}
}
}
puts("No");
return 0;
} |
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <deque>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <cassert>
#include <iostream>
#include <stdio.h>
#include <time.h>
using namespace std;
typedef long long ll;
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define MOD 1000000007
int main(){
ll n;
cin>>n;
ll b = 0;
vector<ll> v1,v2;
rep(i,0,n){
ll a;
cin>>a;
v1.pb(a);
}
rep(i,0,n){
ll a;
cin>>a;
v2.pb(a);
}
rep(i,0,n){
b += v1[i]*v2[i];
}
if(b==0){
cout << "Yes" << endl;
}
else{
cout << "No" << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n,k,m;
cin >> n >> k >> m;
int sum=0;
vector<int>a(n-1);
for(int i=0;i<n-1;i++) {
cin >> a.at(i);
sum+=a.at(i);
}
int x=m*n-sum;
if(x>k) {
cout << -1 << endl;}
else if (x<=k && x>=0) {
cout << x << endl;}
else {
cout << 0 << endl;}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main(){
int V, T, S, D;
cin >> V >> T >> S >> D;
string ans = "Yes";
if(V*T <= D){
if(V*S >= D){
ans = "No";
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<int> vi;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define mapi map<int, int>
#define mapl map<ll, ll>
#define pb push_back
#define fast_cin() \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define tsolve(t) \
int t; \
cin >> t; \
while (t--) \
{ \
solve(); \
}
void solve()
{
double v, t, s, d;
cin >> v >> t >> s >> d;
double tt = d / v;
//cout << tt << endl;
if (t <= tt && tt <= s)
{
cout << "No";
return;
}
cout << "Yes";
return;
}
int main()
{
fast_cin();
// tsolve(t)
solve();
return 0;
} |
#include <bits/stdc++.h>
#define int long long
#define MOD 1000000007
using namespace std;
vector<vector<int>> binoms(17,vector<int>(17,-1));
int binom(int n, int r){
if(binoms[n][r] != -1) return binoms[n][r];
int ans = 1;
for(int i = 0; i < r; i ++){
ans *= n-i;
ans /= i+1;
}
return binoms[n][r] = ans;
}
int powmod(int a, int n){
if(n == 0) return 1;
int s = powmod(a,n/2);
s = (s*s) % MOD;
if(n % 2) return (a*s) % MOD;
else return s;
}
int scent(int a, int k, int n){ //n digits, a already used
if(n == 0) return (a == k ? 1 : 0);
if(a > k) return 0;
int ans = 0;
int sign = 1;
for(int j = k; j >= a; j --){
ans = (ans + (sign*binom(k-a,j-a)*powmod(j,n)) % MOD + MOD) % MOD;
sign *= -1;
}
return ans*binom(16-a,k-a) % MOD;
}
signed main(){
string n; int k; cin >> n >> k;
int s = n.size();
vector<int> N(s); for(int i = 0; i < s; i ++) N[i] = (n[i] <= '9' ? n[i] - '0' : n[i] - 'A' + 10);
int ans = 0;
for(int i = 1; i < s; i ++){
ans = (ans + 15*scent(1,k,i-1)) % MOD;
//cout << scent(1,k,i-1) << " " << 1 << " " << k << " " << i-1 << "\n";
}
vector<bool> digs(16);
int counter = 0;
for(int i = 0; i < s; i ++){
for(int j = 0; j < N[i]; j ++){
if(i == 0 && j == 0) continue;
int curcounter = counter;
if(!digs[j]) curcounter ++;
ans = (ans + scent(curcounter,k,s-i-1)) % MOD;
//cout << scent(curcounter,k,s-i-1) << " " << curcounter << " " << k << " " << s-i-1 << "\n";
}
if(!digs[N[i]]) counter ++;
digs[N[i]] = true;
}
if(counter == k) ans ++;
cout << ans;
} | //in the name of god//
// SOBHET BEKHEIR JOOOOOOON E DEL
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mem(x,s) memset(x,s,sizeof(x))
#define all(x) x.begin(),x.end()
#define _ ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
#define F first
#define S second
#define endi return cout<<'\n',0
#define MP make_pair
#define pb push_back
#define ppb pop_back
#define pii pair<int,int>
#define pll pair<ll,ll>
const int maxn = 1e5 + 10;
const int maxn1 = 1e3 + 10;
const ll inf = 1e18;
map <ll,ll> dp;
ll f(ll a, ll b){
if(a >= b)
return a - b;
if(dp.count(b))
return dp[b];
else{
ll tmp = b - a;
if(b & 1)
tmp = min (tmp, min(f(a, (b + 1ll) / 2ll), f(a, (b - 1ll) / 2ll)) + 2ll);
else
tmp = min (tmp, f(a, b / 2) + 1);
return dp[b] = tmp;
}
}
int main(){
ll x, y;
cin >> x >> y;
cout << f(x, y) << '\n';
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using P = pair<int64_t, int64_t>;
int64_t my_abs(int64_t a) { return max(a, -a); }
int64_t gcd(int64_t a, int64_t b) {
while (b != 0) {
int64_t tmp = a % b;
a = b;
b = tmp;
}
return a;
}
P calc(int64_t a, int64_t b) {
int64_t aa = my_abs(a);
int64_t ab = my_abs(b);
int64_t ta = aa;
int64_t tb = ab;
map<int64_t, int64_t> m;
m[ta] = 1;
m[tb] = 0;
while (tb != 1) {
int64_t tmp = ta % tb;
m[tmp] = m.at(ta) - m.at(tb) * (ta / tb);
ta = tb;
tb = tmp;
}
int64_t x = m.at(1);
if (aa == -a) {
x *= -1;
}
int64_t y = (1 - x * a) / b;
return make_pair(x, y);
}
int64_t div_ceil(int64_t a, int64_t b) {
if (a >= 0) {
return (a + b - 1) / b;
} else {
return a / b;
}
}
int main() {
int T;
cin >> T;
for (int i = 0; i < T; i++) {
int64_t N, S, K;
cin >> N >> S >> K;
int64_t g = gcd(N, K);
if (S % g != 0) {
cout << -1 << endl;
continue;
}
int64_t n = N / g;
int64_t s = S / g;
int64_t k = K / g;
int64_t tx, ty;
tie(tx, ty) = calc(n, -k);
tx *= s;
ty *= s;
int64_t m = max(div_ceil(1 - tx, k), div_ceil(1 - ty, n));
cout << n * m + ty << endl;
}
return 0;
}
| #include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
#include<cassert>
#include<set>
#include<complex>
#include<numeric>
#include<functional>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;
void array_show(int *array,int array_n,char middle=' '){
for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
if(vec_n==-1)vec_n=vec_s.size();
for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
if(vec_n==-1)vec_n=vec_s.size();
for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void init(){
}
long long int gcd(long long int a,long long int b){
if(a<b)swap(a,b);
if(b==0)return a;
return gcd(b,a%b);
}
void solve(){
LL n,m;
int i,j,k;
LL a,b,c;
LL p,q;
const LL B=4e4;
cin>>n>>p>>q;
map<LL,LL> m1;
q%=n;
a=q*B%n,b=0;
for(i=0;i<B;i++,b-=a){
if(b<0)b+=n;
if(m1.find(b)!=m1.end())break;
m1[b]=i;
}
LL s=0;
a=p;
for(i=0;i<B;i++,a+=q){
if(a>=n)a%=n;
if(m1.find(a)!=m1.end()){
s=i+B*m1[a];
break;
}
}
if(i>=B){
cout<<-1<<endl;
return;
}
a=gcd(n,q);
s%=n/a;
cout<<s<<endl;
return;
}
int main(){
int n,i;
init();
cin>>n;
for(i=0;i<n;i++){
solve();
}
} |
//@formatter:off
#include<bits/stdc++.h>
#define overload4(_1,_2,_3,_4,name,...) name
#define rep1(i,n) for (ll i = 0; i < ll(n); ++i)
#define rep2(i,s,n) for (ll i = ll(s); i < ll(n); ++i)
#define rep3(i,s,n,d) for(ll i = ll(s); i < ll(n); i+=d)
#define rep(...) overload4(__VA_ARGS__,rep3,rep2,rep1)(__VA_ARGS__)
#define rrep(i,n) for (ll i = ll(n)-1; i >= 0; i--)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#ifdef __LOCAL
#define debug(...) { cout << #__VA_ARGS__; cout << ": "; print(__VA_ARGS__); cout << flush; }
#else
#define debug(...) void(0)
#endif
#define INT(...) int __VA_ARGS__;scan(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;scan(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;scan(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;scan(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;scan(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__;scan(__VA_ARGS__)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int,int>;
using LP = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vs = vector<string>;
using vc = vector<char>;
using vvc = vector<vector<char>>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vp = vector<P>;
using vvp = vector<vector<P>>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==int(v.size()-1)?"":","); return os<<']'; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
void scan(){}
template <class Head, class... Tail> void scan(Head& head, Tail&... tail){ cin >> head; scan(tail...); }
template<class T> void print(const T& t){ cout << t << '\n'; }
template <class Head, class... Tail> void print(const Head& head, const Tail&... tail){ cout<<head<<' '; print(tail...); }
template<class... T> void fin(const T&... a) { print(a...); exit(0); }
const string yes[] = {"no","yes"};
const string Yes[] = {"No","Yes"};
const string YES[] = {"NO","YES"};
const int inf = 1001001001;
const ll linf = 1001001001001001001;
//@formatter:on
double A[200010];
double B[200010];
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
INT(n, m, k);
vi a(k);
cin >> a;
if (m <= k) {
rep(i, k - m + 1) {
bool ok = true;
rep(j, m - 1) ok &= a[i + j] + 1 == a[i + j + 1];
if (ok) fin(-1);
}
}
cout << fixed << setprecision(10);
rrep(i, n) {
bool ok = true;
rep(j, k) if (i == a[j]) ok = false;
double na, nb;
if (ok) {
na = (A[i + 1] - A[i + m + 1]) / m;
nb = (B[i + 1] - B[i + m + 1]) / m + 1;
} else {
na = 1, nb = 0;
}
A[i] = A[i + 1] + na;
B[i] = B[i + 1] + nb;
}
double na = A[0] - A[1], nb = B[0] - B[1];
// X = na * X + nb
print(nb / (1 - na));
}
| #include <complex>
#include <iostream>
#include <vector>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
int main() {
int N, M, K;
cin >> N >> M >> K;
vector< complex< double > > means(N);
rep(i, K) {
int a;
cin >> a;
means[a].imag(1);
}
complex< double > acc = 0;
int l = 0;
int suc_mass = 0;
for(int k = N - 1; k >= 0; k--) {
if(means[k].imag() == 0) {
means[k] += M;
means[k] += acc;
means[k] /= M;
suc_mass = 0;
} else {
++suc_mass;
if(suc_mass >= M)
break;
}
acc += means[k];
++l;
if(l > M) {
acc -= means[k + M];
--l;
}
}
// cout << means[0].real() << ", " << means[0].imag() << endl;
if(suc_mass >= M) {
cout << -1 << endl;
} else {
double res = means[0].real();
res /= (1.0 - means[0].imag());
cout << res << endl;
}
} |
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
using P=pair<ll, ll>;
#define MAX 110
int gcd(int a, int b)
{
if (b == 0) return a;
return (gcd(b, a % b));
}
int a[MAX];
signed main(void)
{
int n, ans, max, cnt;
cin >> n;
rep(i, n) cin>>a[i];
max = 0;
ans = -1;
for (int g = 2; g <= 1000; g++)
{
cnt = 0;
rep(i, n)
{
if (g == gcd(g, a[i]))
cnt++;
}
if (max <= cnt)
{
ans = g;
max = cnt;
}
}
cout << ans << endl;
return 0;
}
| // includes
#include <bits/stdc++.h>
using namespace std;
// macros
#define pb emplace_back
#define mk make_pair
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)
#define irep(itr, st) for(auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for(auto itr = (st).rbegin(); itr != (st).rend(); ++itr)
#define whole(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define bit(n) (1LL<<(n))
#define F first
#define S second
// functions
template <typename T> void unique(T& c){c.erase(std::unique(c.begin(), c.end()), c.end());}
template <class T>bool chmax(T &a, const T &b){if(a < b){a = b; return 1;} return 0;}
template <class T>bool chmin(T &a, const T &b){if(a > b){a = b; return 1;} return 0;}
template <typename T> istream &operator>>(istream &is, vector<T> &vec){for(auto &v: vec)is >> v; return is;}
template <typename T> ostream &operator<<(ostream &os, const vector<T>& vec){for(int i = 0; i < vec.size(); i++){ os << vec[i]; if(i + 1 != vec.size())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p){os << "(" << p.first << ", " << p.second << ")"; return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << "(" << itr->first << ", " << itr->second << ")"; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const unordered_map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << "(" << itr->first << ", " << itr->second << ")"; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
// types
using ll = long long int;
using P = pair<int, int>;
// constants
const int inf = 1e9;
const ll linf = 1LL << 60;
const double EPS = 1e-10;
const int mod = 1000000007;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
// io
struct fast_io{
fast_io(){ios_base::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(20);}
} fast_io_;
int main(int argc, char const* argv[])
{
int n; cin >> n;
vector<ll> a(n); cin >> a;
int maxi = 0, res = 0;
for(int i = 2; i <= 1000; i++){
int tmp = 0;
rep(j, n){
if(a[j] % i == 0)++tmp;
}
if(chmax(maxi, tmp))res = i;
}
cout << res << endl;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> p2;
#define sz(a) ll(a.size())
char t[300005];
void solve(){
ll n;
string s;
cin>>n>>s;
if(s=="1"){
cout<<ll(2*pow(10,10));
return;
}
ll j=0;
while(j<300005){
if(j%3==2)
t[j]='0';
else
t[j]='1';
j++;
}
for(ll i=0;i<3;i++){
ll f=0;
for(ll j=i;j<i+n;j++)
if(s[j-i]!=t[j]){
f=1;
break;
}
if(!f){
cout<<ll(pow(10,10))-(n+i-1)/3;
return;
}
}
cout<<0;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r" , stdin);
freopen("output.txt", "w", stdout);
#endif
clock_t z=clock();
ll qc=1;
//cin>>qc;
for(ll i=1;i<=qc;i++)
solve();
debug("Total Time:%.4Lf\n",(ld)(clock()-z)/CLOCKS_PER_SEC);
} | // #pragma GCC optimize(2)
// #include <random>
// #include <windows.h>
// #include <ctime>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cctype>
#include <bitset>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
#define IO \
ios::sync_with_stdio(false); \
// cout.tie(0);
#define lson(x) (x << 1)
#define rson(x) (x << 1 | 1)
using namespace std;
// int dis[8][2] = {0, 1, 1, 0, 0, -1, -1, 0, 1, -1, 1, 1, -1, 1, -1, -1};
typedef unsigned long long ULL;
typedef long long LL;
typedef pair<int, int> P;
const int maxn = 2e5 + 10;
const int maxm = 1e7 + 10;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const LL mod = 998244353;
const double eps = 1e-8;
const double pi = acos(-1);
int dis[4][2] = {1, 0, 0, -1, 0, 1, -1, 0};
// int m[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
char s[maxn];
int main()
{
#ifdef WXY
freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
#endif
// IO;
int n;
// cin >> n;
scanf("%d", &n);
scanf("%s", s + 1);
LL temp = LL(pow(10, 10));
if (n == 1)
{
if (s[1] == '1')
cout << temp * 2;
else
cout << temp;
return 0;
}
else if (n == 2)
{
if (s[1] == '0' && s[2] == '0')
cout << 0;
else if (s[1] == '1' && s[2] == '1')
cout << temp;
else if (s[1] == '0' && s[2] == '1')
cout << temp - 1;
else
cout << temp;
return 0;
}
int p = -1;
for (int i = 1; i <= n; i++)
{
if (s[i] == '0')
{
p = i;
break;
}
}
if (p > 3 || (p == -1))
{
cout << 0;
return 0;
}
for (int i = p; i <= n; i++)
{
if (s[i] == '0')
{
if (i == n)
break;
else if (i + 3 <= n && s[i + 1] == '1' && s[i + 2] == '1' && s[i + 3] == '0')
continue;
else if (i + 2 == n && s[i + 1] == '1' && s[i + 2] == '1')
continue;
else if ((i + 1 == n && s[i + 1] == '1'))
break;
else
{
cout << 0;
return 0;
}
}
}
if (s[n - 1] == '0' && s[n] == '1')
n += 2;
else if (s[n - 1] == '1' && s[n] == '1')
n += 1;
if (p == 2)
n += 1;
if (p == 1)
n += 2;
LL cnt = n / 3;
cout << LL(pow(10, 10)) - cnt + 1;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
cin >> N;
vector<int> p(N);
for (int i = 0; i < N; i++){
cin >> p[i];
}
set<int> st;
for (int i = 0; i <= 200000; i++){
st.insert(i);
}
for (int i = 0; i < N; i++){
if (st.count(p[i])){
st.erase(p[i]);
}
cout << *st.begin() << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
// --------------------------------------------------------
template<class T> bool chmax(T& a, const T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, const T b) { if (b < a) { a = b; return 1; } return 0; }
#define FOR(i,l,r) for (int i = (l); i < (r); ++i)
#define RFOR(i,l,r) for (int i = (r)-1; (l) <= i; --i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define MIN(c) *min_element(ALL(c))
#define MAX(c) *max_element(ALL(c))
#define SUM(c) accumulate(ALL(c), 0)
#define SUMLL(c) accumulate(ALL(c), 0LL)
#define SZ(c) ((int)(c).size())
#define CIN(c) cin >> (c)
#define COUT(c) cout << (c) << '\n'
#define debug(x) cerr << #x << " = " << (x) << '\n';
using P = pair<int,int>;
using VP = vector<P>;
using VVP = vector<VP>;
using VS = vector<string>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<ll>;
using VVLL = vector<VLL>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
static const double EPS = 1e-10;
static const double PI = acos(-1.0);
static const ll MOD = 1000000007;
// static const ll MOD = 998244353;
static const int INF = (1 << 30) - 1; // 1073741824 - 1
// static const ll INF = (1LL << 62) - 1; // 4611686018427387904 - 1
// --------------------------------------------------------
// #include <atcoder/all>
// using namespace atcoder;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(15);
int N; cin >> N;
VI P(N); REP(i,N) cin >> P[i];
const int MAX_P = 2e5;
VB seen(MAX_P + 2, false);
int min = 0;
for (int p : P) {
seen[p] = true;
while (seen[min]) { min++; }
COUT(min);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long i64;
typedef unsigned long long ui64;
typedef vector<i64> vi;
typedef vector<vi> vvi;
typedef pair<i64, i64> pi;
#define pb push_back
#define sz(a) i64((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)
inline void RI(i64 &i) {scanf("%lld", &(i));}
inline void RVI(vi &v) { for(i64 i=0;i<sz(v);++i) { RI(v[i]); } }
inline void RVVI(vvi &vv) { for(i64 i=0;i<sz(vv);++i) { RVI(vv[i]); } }
inline void WI(const i64 &i) {printf("%lld\n", i);}
inline void WVI(const vi &v, char sep=' ') { for(i64 i=0;i<sz(v);++i) { if(i != 0){ printf("%c", sep); } printf("%lld", v[i]);} printf("\n"); }
inline void WS(const string &s) { printf("%s\n", s.c_str()); }
inline void WB(bool b, const string &yes, const string &no) { if(b){ WS(yes);} else { WS(no);} }
inline void YESNO(bool b) { WB(b, "YES", "NO"); }
inline void YesNo(bool b) { WB(b, "Yes", "No"); }
#define BUF_LENGTH 1000000
inline void RS(string &s) {static char buf[BUF_LENGTH]; scanf("%s", buf); s = buf;}
template<typename T> inline bool IN(T &S, const typename T::key_type &key) {
return S.find(key) != S.end();
}
template<typename T> inline bool ON(const T &b, i64 idx) {
return ((T(1) << idx) & b) != 0;
}
int main(int argc, char *argv[]) {
i64 i, j, k;
i64 T, t; RI(T);
REP(0, T, t) {
i64 N; RI(N);
vi p(N); RVI(p);
vi p0 = p;
for(auto &pp: p) {
--pp;
}
unordered_set<i64> pos[2];
REP(0, N-1, i) {
if(p[i] > p[i+1]) {
pos[i%2].insert(i);
}
}
#if 0
WVI(p);
cerr << "pos: ";
for(auto &pp: pos[0]) { cerr << pp << " "; }
for(auto &pp: pos[1]) { cerr << pp << " "; }
cerr << endl;
#endif
vi ans;
i64 cur = 0;
while(!pos[0].empty() || !pos[1].empty()) {
//cerr << endl;
i64 pr = -1;
if(pos[cur%2].empty()) {
pr = cur % 2;
}
else {
pr = *pos[cur%2].begin();
}
ans.pb(pr+1);
//cerr << "swap " << pr << " " << pr + 1 << endl;
swap(p[pr], p[pr+1]);
for(i64 i=pr-1;i<=pr+1;++i) {
if(0 <= i && i < N - 1) {
if(p[i] > p[i+1]) {
pos[i%2].insert(i);
}
else {
auto it = pos[i%2].find(i);
if(it != pos[i%2].end()) {
pos[i%2].erase(it);
}
}
}
}
++cur;
#if 0
WVI(p);
cerr << "pos: ";
for(auto &pp: pos[0]) { cerr << pp << " "; }
for(auto &pp: pos[1]) { cerr << pp << " "; }
cerr << endl;
#endif
}
REP(0, N, i) {
if(p[i] != i) {
WVI(p0);
WVI(p);
}
assert(p[i] == i);
}
assert(sz(ans) <= N * N);
WI(sz(ans));
WVI(ans);
}
return 0;
}
| #include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
long long arr[n][n];
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cin>>arr[i][j];
}
}
int dif[n];
int min=arr[0][0],minindex=0;
for(int i=1;i<n;i++){
if(arr[i][0]<min){
min=arr[i][0];
minindex=i;
}
}
for(int i=0;i<n;i++){
dif[i]=arr[i][0]-arr[minindex][0];
for(int j=0;j<n;j++){
if( ( arr[i][j] - arr[minindex][j] ) != dif[i] ){
cout<<"No"<<endl;
return 0;
}
}
}
cout<<"Yes"<<endl;
for(int i=0;i<n;i++){
cout<<dif[i]<<" ";
}
cout<<endl;
for(int i=0;i<n;i++){
cout<<arr[minindex][i]<<" ";
}
cout<<endl;
} |
#include<bits/stdc++.h>
using namespace std;
typedef double db;
int main()
{
int n,dm,hm;
cin>>n>>dm>>hm;
int d,h;
db ans=1.0*hm/dm;
while(n--)
{
scanf("%d %d",&d,&h);
ans=min(ans,1.0*(hm-h)/(dm-d));
}
printf("%.15lf",hm-dm*ans);
return 0;
} | // DeNsE - EcLiPsE //
// WHAT is DEAD may NEVER die //
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <unordered_map>
#include <cmath>
#include <iomanip>
#include <set>
#include <cstring>
#include <stack>
#include <sstream>
#include <queue>
#include <unordered_set>
#include <cstdlib>
using namespace std;
#define nitro ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define int long long
#define double long double
#define endl " \n"
const int inf = (1ll << 62) - 1;
const int mod = 1e9 + 7;
const int N = 1e5 + 5;
const double pi = 3.14159265358979323846;
int bPow(int a, int b){
int res = 1;
while(b) {
if (b & 1) {
res = (res * a) % mod;
}
b >>= 1;
a = (a * a) % mod;
}
return res % mod;
}
int gcd(int a, int b)
{
if(a < b)
swap(a, b);
if (b == 0)
return a;
return gcd(b, a % b);
}
vector<int> fact(N, 0ll);
void factorial(){
fact[0] = 1, fact[1] = 1;
for(int i = 2; i < N; i++){
fact[i] = (fact[i - 1] * i) % mod;
}
}
int ncr(int n, int r){
if(r > n)
return 0;
int ans = fact[n] % mod;
ans *= bPow(fact[r], mod - 2) % mod;
ans %= mod;
ans *= bPow(fact[n - r], mod - 2) % mod;
ans %= mod;
return ans;
}
vector<int> primes(N, -1);
void sieve(){
iota(primes.begin(), primes.end(), 0);
for (int i = 2; i * i <= N; ++i) {
if(primes[i] == i){
for (int j = 2 * i; j < N; j += i) {
primes[j] = i;
}
}
}
}
bool check(vector<pair<double, double> > a, double y1, double x2, double y2){
double slope = (double) (y2 - y1) / (double) x2;
for (auto & i : a) {
double x3 = i.first, y3 = i.second;
double temp = (double) (y3 - y1) / (double) x3;
if(temp >= slope){
return false;
}
}
return true;
}
void solve() {
int n;
double b, h;
cin >> n >> b >> h;
vector<pair<double, double>> obs;
for (int i = 0; i < n; ++i) {
double x, y;
cin >> x >> y;
obs.emplace_back(x, y);
}
double l = 0.0, r = 1000.0, ans = 0.0;
while (l < r){
double mid = (l + r) / 2.0;
if(check(obs, mid, b, h)){
ans = mid;
r = mid - 0.00001;
}else{
l = mid + 0.00001;
}
}
cout << ans << endl;
}
signed main(){
nitro
int tc = 1, test = 1;
//cin >> tc;
while(tc--){
//cout << "Case #" << test++ << ": ";
solve();
}
} |
#include<bits/stdc++.h>
using namespace std;
bool check(long long k, long long middle, vector<vector<long long>> &b){
if(k >= b[middle][2]){return (true);}
else{return (false);}
}
int main(){
int n, q; cin >> n >> q;
vector<long long> a(n+1), k(q);
for(int i = 0; i < n; ++i){cin >> a[i];}
a[n] = 1LL<<60;
vector<vector<long long>> b;
long long s = 1, ccount = 1;
for(int i = 0; i <= n; ++i){
long long e = a[i];
if(e - s == 0){s = e + 1;}
else{
vector<long long> tmp = {s, e-1, ccount};
ccount += e - s;
b.emplace_back(tmp);
s = e + 1;
}
}
for(int i = 0; i < q; ++i){
long long k; cin >> k;
long long bottom = 0, top = b.size(), middle;
while(top - bottom > 1){
middle = (bottom + top)/2;
if(check(k, middle, b) == true){bottom = middle;}
else{top = middle;}
}
int p = bottom;
cout << b[p][0] + k - b[p][2] << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
// https://www.geeksforgeeks.org/ordered-set-gnu-c-pbds/
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define rep(i,s,e) for(int i=s ; i < e ; i++)
#define rrep(i,s,e) for(int i=s ; i > e ; i--)
#define srep(i,s,e,j) for(int i=s ; i < e ; i+=j)
#define tr(i,x) for(auto i : x)
#define vinp(a) for(int i=0 ; i<a.size() ; i++)cin>>a[i]
#define ainp(a,n) for(int i=0; i<n; i++)cin>>a[i]
#define int long long
#define vi vector<int>
#define vs vector<string>
#define vb vector<bool>
#define vpi vector<pii>
#define maxpqi priority_queue<int>
#define minpqi priority_queue <int, vector<int>, greater<int> >
#define pii pair<int,int>
#define F first
#define S second
#define mk make_pair
#define pb push_back
#define pf push_front
#define endl '\n'
#define gcd(a,b) __gcd(a,b)
#define clr(x) memset(x,0,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define lb lower_bound
#define ub upper_bound
#define npos string::npos
#define all(x) x.begin(),x.end()
#define sayyes cout << "YES" << endl
#define sayno cout << "NO" << endl
string a="ALICE",b="BOB";
void solve(){
int n,q;cin>>n;cin>>q;
int a[n+1];a[0]=0;
int b[n+1];b[0]=0;
rep(i,1,n+1){
cin>>a[i];
b[i] = a[i]-i;
}
// int q;cin>>q;
while(q--){
int k;cin>>k;
// cout << "findng " << k << "th" << endl;
// auto it = lb(b, b+)
int pos = lb(b,b+n+1,k)-b;
// cout << "pos : " << pos << endl;
pos--;
// cout << "pos--" << endl;
// cout << "b[pos] : " << b[pos] << endl;
cout << a[pos]+k-b[pos] << endl;
// cout << "--> " << a[pos]+k-b[pos] << endl;
}
// cout<<endl;
}
int32_t main()
{
fastio
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < n; ++i)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int main(){
int n,w;
cin>>n>>w;
vector<ll> a(200005,0),b(200005,0);
rep(i,n){
int s,t,p;
cin>>s>>t>>p;
a[s]+=p;
a[t]-=p;
}
ll now=0;
bool ok=true;
rep(i,200005){
now+=a[i];
b[i]=now;
if(b[i]>w) ok=false;
}
if(ok) cout << "Yes" << endl;
else cout << "No" << endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ll n,w;
cin>>n>>w;
ll curr [200005];
memset( curr , 0 , sizeof(curr ) );
for(int i=0;i< n;i++)
{
ll s , t, p;
cin>>s>>t>>p;
curr[s] += p;
curr[t] += -p;
}
for(int i=0;i<200004;i++)
{
curr[i+1] +=curr[i];
if( curr[i] > w )
{
cout<<"No";
return 0;
}
}
cout<<"Yes";
} |
#include<bits/stdc++.h>
using namespace std;
#define int long long //delete if causing problems
#define F first
#define dbg(x) cout<<#x<<" "<<x<<endl;
#define S second
#define setbit(n) __builtin_popcount(n)
#define all(x) x.begin() , x.end()
#define clr(x) memset(x,0,sizeof(x))
#define fast ios_base::sync_with_stdio(0); cin.tie(0);
#define endl "\n" //delete if interactive
#define MOD 1000000007
const int inf = 1e18;
int power(int a, int b);
signed main()
{
fast
int t = 1;
//cin >> t;
while (t--)
{
int n;
cin >> n;
int a[n], b[n];
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++) cin >> b[i];
int sum = 0;
for (int i = 0; i < n; i++)
{
sum += (a[i] * b[i]);
}
if (sum == 0) cout << "Yes";
else cout << "No";
}
return 0;
}
int power(int a, int b)
{
int res = 1;
while (b)
{
if (b % 2) b-- , res = res * a;
else b = b / 2 , a *= a;
}
return res;
}
/*
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
*/
| #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
#define FOR(i, a, b) for(ll i=(a); i < (ll)(b); ++i)
template<class T> inline bool chmax(T& a, T b) { if(a < b){ a=b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if(a > b){ a=b; return 1; } return 0;}
ll GCD(ll a, ll b){
if(b==0) return a;
return GCD(b, a%b);
}
ll ext_gcd(ll a, ll b, ll &x, ll &y){
if(b==0){
x = 1;
y = 0;
return a;
}
ll d = ext_gcd(b, a%b, y, x);
y -= a/b * x;
return d;
}
void solve(){
ll n,s,k;
cin >> n >> s >> k;
ll x,y;
ll egcd = ext_gcd(n,k,x,y);
cerr << x <<" "<< y << endl;
if(s%egcd==0){
ll ans = -1*y*(s/egcd);
ll di = n/GCD(n,k);
cout << ((ans%di)+di)%di << endl;
}else{
cout << "-1\n";
}
}
int main(){
int t;
cin >> t;
while(t--){
solve();
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
int main() {
ll A, B;
cin >> A >> B;
vector<int> primes = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71};
int K = primes.size();
vector<ll> from(1<<K, 0), to(1<<K, 0);
from[0] = 1;
for (ll i = A; i <= B; i++) {
fill(to.begin(), to.end(), 0);
ll mask = 0;
for (int j = 0; j < K; j++) {
if (i%primes[j] == 0) mask |= (1<<j);
}
for (int j = 0; j < (1<<K); j++) {
to[j] += from[j];
if ((j&mask) == 0) to[j|mask] += from[j];
}
swap(from, to);
}
ll ans = 0;
for (ll n : from) ans += n;
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
template <class T> inline void read(T &x) {
x= 0;
char c= getchar();
while(!isdigit(c)) c= getchar();
while(isdigit(c)) x= x * 10 + (c & 15), c= getchar();
}
#define N 74
int n, prime[]= {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71}, p[N];
long long a, b, t[N], f[1 << 20], ans;
signed main() {
read(a), read(b);
for(long long i= a; i <= b; i++) t[++n]= i;
for(int i= 1; i <= n; i++)
for(int j= 0; j < 20; j++)
if(t[i] % prime[j] == 0) p[i]|= 1 << j;
f[0]= 1;
for(int j= 1; j <= n; j++)
for(int i= 0; i < (1 << 20); i++) {
if(i & p[j]) continue;
f[i | p[j]]+= f[i];
}
for(int i= 0; i < (1 << 20); i++) ans+= f[i];
printf("%lld", ans);
return 0;
} |
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int n,i,a=0,b=1001,t;
cin >> n;
for(i=0;i<n;i++){
cin >> t;
if(t>a) a=t;
}
for(i=0;i<n;i++){
cin >> t;
if(t<b) b=t;
}
cout << max(b-a+1,0) << endl;
return 0;
} | #include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define si short int
#define speed ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define pill pair<ll,ll>
#define f first
#define s second
#define pilc pair<ll,char>
#define all(a) (a).begin(),(a).end()
#define rep(s,e,step) for(int i = (s); i < (e) ; i += step)
#define vrep(s,e,step) for(int j = (s); j < (e) ; j += step)
#define ex exit(0)
#define sz(a) (a).size()
#define triple pair<pill, ll>
#define pinode pair<node*, node*>
#define quadra pair<pill, pill>
#define ld long double
using namespace std;
const ll N = 1e5 + 100;
const ll M = 3e5 + 101;
const ll big = 1e17;
const ll hsh2 = 1964325029 ;
const long long mod = 1e9 + 7;
const long double EPS = 1e-10;
const ll block = 1e7;
const ll shift = 2e3;
const ld pi = acos(-1.0);
ll n, a[N];
vector<ll> z;
int main() {
speed;
cin >> n;
for(int i = 1; i <= n; i++)
cin >> a[i], z.pb(a[i]);
sort(a + 1, a + n + 1);
ll ans = 1, lst = 0;
for(int i = 1; i <= n; i++) {
ans = (ans * ( a[i] - lst + 1)) % mod;
lst = a[i];
}
cout << ans << '\n';
}
/*
*/ |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define cin std::cin
#define cout std::cout
#define endl "\n"
#define mod 1000000007
#define pi 3.141592653589793238462643
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define ff first
#define ss second
#define rep(i,n) for(int i=0; i<n; ++i)
#define round(n,i) fixed<<setprecision(i)<<n
void solve(){
ll n; cin>>n;
if (n <= 100) cout<<1<<endl;
else if (n % 100 == 0)
cout << n/ 100 <<endl;
else
cout << n/ 100 + 1 <<endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
ll t=1;
// cin>>t;
for(ll i=1; i<=t; ++i){
solve();
}
}
| #include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
cout << n / 100 + (n % 100 != 0) << endl;
}
|
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)
int popcount(int a){
a = (a&0x55555555) + ((a>>1)&0x55555555);
a = (a&0x33333333) + ((a>>2)&0x33333333);
a = (a&0x0f0f0f0f) + ((a>>4)&0x0f0f0f0f);
a = (a&0x00ff00ff) + ((a>>8)&0x00ff00ff);
return (a & 0xffff) + (a>>16);
}
int N,M;
vector<vector<pair<int,int>>> Resteictions;
vector<ull> dp;
int main(){
scanf("%d%d",&N,&M);
Resteictions.resize(N+1);
rep(i,M){
int x,y,z; scanf("%d%d%d",&x,&y,&z);
Resteictions[y].push_back({(1<<x)-1,z});
}
dp.assign(1<<N,0);
dp[0] = 1;
rep(j,1<<N){
int c = popcount(j);
for(auto q : Resteictions[c]){
if(popcount(j & q.first) > q.second) dp[j] = 0;
}
rep(k,N){
if((j&(1<<k)) != 0) continue;
dp[j|(1<<k)] += dp[j];
}
}
printf("%llu\n",dp[(1<<N)-1]);
return 0;
}
| #include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define rrep1(i, n) for (int i = n; i >= 1; i--)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define eb emplace_back
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
typedef long long int ll;
typedef pair<int, int> P;
// typedef modint1000000007 mint;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return true;
}
return false;
}
void speedUpIO() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
}
/*--------------------------------------------------*/
void solve() {
int n, m;
cin >> n >> m;
V<int> a(n);
rep(i, n) cin >> a[i];
V<int> cnt(n + 1);
rep(i, m) cnt[a[i]]++;
int ans = n;
rep(i, n) {
if (cnt[i] == 0) {
ans = i;
break;
}
}
for (int i = 1; i <= n - m; i++) {
int l = i - 1;
int r = i + m - 1;
// if (cnt[a[l]] == 0) chmin(ans, a[l]);
cnt[a[l]]--;
cnt[a[r]]++;
if (cnt[a[l]] == 0) chmin(ans, a[l]);
}
rep(i, n) {
if (cnt[i] == 0) {
chmin(ans, i);
break;
}
}
cout << ans << "\n";
}
int main() {
speedUpIO();
solve();
return 0;
}
|
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<iomanip>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
int A, B;
double ans;
cin >> A >> B;
ans = (double)A * (double)B / 100;
cout << ans << endl;
} | #include <bits/stdc++.h>
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
using namespace std;
#define all(v) v.begin(), v.end()
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep_up(i, a, b) for (ll i = a; i < b; ++i)
#define rep_down(i, a, b) for (ll i = a; i > b; --i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
#define vvvvll vector<vector<vector<vector<ll>>>>
#define vvvll vector<vector<vector<ll>>>
#define vvll vector<vector<ll>>
#define vll vector<ll>
#define vvvvdo vector<vector<vector<vector<double>>>>
#define vvvdo vector<vector<vector<double>>>
#define vvdo vector<vector<double>>
#define vdo vector<double>
#define pqll priority_queue<ll>
#define pqllg priority_queue<ll, vector<ll>, greater<ll>>
constexpr ll INF = (1ll << 60);
// constexpr ll mod = 998244353;
// constexpr ll mod = 67280421310721;
// constexpr ll mod = 1e18+3;
constexpr ll mod = 1000000007;
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <typename T>
inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <typename T>
void pt(T val) {
cout << val << "\n";
}
template <typename T>
void pt_vll(vector<T> &v) {
ll vs = v.size();
rep(i, vs) {
cout << v[i];
if (i == vs - 1)
cout << "\n";
else
cout << " ";
}
}
template <typename T>
void pt_vvll(vector<vector<T>> &v) {
ll vs = v.size();
rep(i, vs) pt_vll(v[i]);
}
ll gcd(ll a, ll b) {
if (a % b == 0) return b;
return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll modinv(ll a, ll m) {
ll b = m, u = 1, v = 0;
while (b) {
ll t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0) u += m;
return u;
}
ll modpow(ll x, ll n, ll M) {
ll ret = 1;
while (n > 0) {
if (n & 1) ret = ret * x % M;
x = x * x % M;
n >>= 1;
}
return ret;
}
// ll minv(ll a, ll m) { return modpow(a, m - 2); }
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll N, M;
cin >> N >> M;
pt(modpow(10, N, M * M) / M);
return 0;
} |
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep1(i, n) for(int i = 1; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i > 0; --i);
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define RREP(i, a, b) for(int i = (int)(b) - 1; i >= (int)(a); --i)
template<typename T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } else return false; }
template<typename T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } else return false; }
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
int n, m;
cin >> n >> m;
vector<int> a(n), b(m);
set<int> sa, sb;
rep(i, n) {
cin >> a[i];
sa.insert(a[i]);
}
rep(i, m) {
cin >> b[i];
sb.insert(b[i]);
}
vector<int> ans;
rep(i, n) {
if (sb.count(a[i]) == 0) ans.push_back(a[i]);
}
rep(i, m) {
if (sa.count(b[i]) == 0) ans.push_back(b[i]);
}
sort(ans.begin(), ans.end());
for (int i : ans) cout << i << " ";
cout << endl;
} | #include <iostream>
#include <vector>
#include <utility>
#include<algorithm>
#include <string>
#include <map>
#include <cmath>
#include <random>
#include <tuple>
#include <set>
#define ll long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main(){
ll n;
ll m;
cin >> n;
cin >> m;
vector<ll> a(n);
vector<ll> b(m);
map<ll,int> c;
rep(i,n){
cin >> a[i];
c[a[i]] ++;
}
rep(i,m){
cin >> b[i];
c[b[i]]++;
}
for(auto x:c){
ll p = x.first;
ll q = x.second;
if(q == 1){
cout << p << ' ';
}
}
cout << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define N 214514
const ll mod = 1e9 + 7;
const ll inf = 1000000000000000000;
ll a[N], b[N];
ll par[N], num[N];
bool used[N];
int main() {
ll n;
cin >> n;
vector<vector<ll>> v(n + 1);
for (int i = 1; i < n; i++) {
cin >> a[i] >> b[i];
v[a[i]].push_back(b[i]);
v[b[i]].push_back(a[i]);
}
par[1] = -1;
used[1] = 1;
queue<ll> que;
que.push(1);
while (!que.empty()) {
ll x = que.front();
que.pop();
for (ll y : v[x]) {
if (used[y]) continue;
used[y] = 1;
par[y] = x;
que.push(y);
}
}
ll q;
cin >> q;
while (q--) {
ll t, e, x;
cin >> t >> e >> x;
if (t == 1) {
if (par[a[e]] == b[e])
num[a[e]] += x;
else {
num[1] += x;
num[b[e]] -= x;
}
} else {
if (par[b[e]] == a[e])
num[b[e]] += x;
else {
num[1] += x;
num[a[e]] -= x;
}
}
}
que.push(1);
for (int i = 2; i <= n; i++) used[i] = 0;
while (!que.empty()) {
ll x = que.front();
que.pop();
for (ll y : v[x]) {
if (used[y]) continue;
used[y] = 1;
num[y] += num[par[y]];
que.push(y);
}
}
for (int i = 1; i <= n; i++) cout << num[i] << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
//using namespace atcoder;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define pb push_back
#define fi first
#define se second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void chOut(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }
using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using v_bool = vector<bool>;
using v_Pii = vector<Pii>;
//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};
const int mod = 1000000007;
//const int mod = 998244353;
struct edge{int to, cost, id;};
class Graph
{
public:
int N;
vector<vector<edge>> G;
vec par, val;
int offset = 0;
Graph(int N): N(N){
G = vector<vector<edge>>(N, vector<edge>(0));
par = vec(N, -1);
val = vec(N, 0);
}
void add_Directed_edge(int from, int to, int cost = 1, int id = 0){
G[from].push_back(edge({to, cost, id}));
}
void add_Undirected_edge(int v1, int v2, int cost = 1, int id = 0){
add_Directed_edge(v1, v2, cost, id);
add_Directed_edge(v2, v1, cost, id);
}
void dfs1(int v, int p = -1){
par[v] = p;
for(auto e: G[v]) if(e.to != p) dfs1(e.to, v);
}
void dfs2(int v, int p = -1){
for(auto e: G[v]) if(e.to != p){
val[e.to] += val[v];
dfs2(e.to, v);
}
val[v] += offset;
}
};
signed main(){
int N; cin >> N;
vec a(N - 1), b(N - 1);
Graph G(N);
REP(i, N - 1){
cin >> a[i] >> b[i];
a[i]--; b[i]--;
G.add_Undirected_edge(a[i], b[i]);
}
G.dfs1(0);
int Q; cin >> Q;
REP(i, Q){
int t, e, x; cin >> t >> e >> x;
t--; e--;
int u = a[e], v = b[e];
if(G.par[v] != u){
swap(u, v);
t ^= 1;
}
if(t == 1) G.val[v] += x;
else{
G.offset += x;
G.val[v] -= x;
}
}
G.dfs2(0);
Out(G.val);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(ll i=a;(i)<(b);++(i))
#define RFOR(i,a,b) for(ll i=a;(i)>=(b);--(i))
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,n,0)
#define ALL(v) v.begin(), v.end()
#define UNIQ(v) sort(ALL(v)); v.erase(unique(ALL(v)), v.end())
#define BIT(n) (1LL<<(n))
#define DEBUG(a) cerr << #a << " = " << a << endl
const double PI = acos(-1);
const int inf = 1001001001;
const int mod = (int)1e9+7;
//const ll inf = 1e15;
//const ll mod = 1e9+7;
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
int main() {
int a, b;
cin >> a >> b;
int ans = 4;
if (a+b >= 15 && b >= 8) ans = 1;
else if (a+b >= 10 && b >= 3) ans = 2;
else if (a+b >= 3) ans = 3;
cout << ans << endl;
} | #include<iostream>
using namespace std;
int A, B;
int main(void){
cin >> A >> B;
if( A + B >= 15 ){
if( B >= 8 ){
cout << 1 << endl;
}
else if( B >= 3 ){
cout << 2 << endl;
}
else{
cout << 3 << endl;
}
}
else if( A + B >= 10){
if( B >= 3 ){
cout << 2 << endl;
}
else{
cout << 3 << endl;
}
}
else if( A + B >= 3){
cout << 3 << endl;
}
else{
cout << 4 << endl;
}
return(0);
} |
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x) << endl
typedef long long ll;
using P = pair<ll,ll>;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
int main(){
int a, b, c; cin >> a >> b >> c;
string ans;
if(c == 0){
if(a > b)ans = "Takahashi";
else ans = "Aoki";
}else{
if(a < b) ans = "Aoki";
else ans = "Takahashi";
}
print(ans);
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
ull INF = 1000000000000000001;
int main(){
int A, B, C;
cin >> A >> B >> C;
vector<vector<vector<double>>> dp(101, vector<vector<double>> (101, vector<double> (101, 0.0)));
double sum;
double pa, pb, pc;
double Am, Bm, Cm;
for(int a = 99; a >= 0; a--){
for(int b = 99; b >= 0; b--){
for(int c = 99; c >= 0; c--){
sum = a + b + c;
pa = a / sum;
pb = b / sum;
pc = c / sum;
Am = dp.at(a+1).at(b).at(c);
Bm = dp.at(a).at(b+1).at(c);
Cm = dp.at(a).at(b).at(c+1);
dp.at(a).at(b).at(c) += (Am + 1) * pa + (Bm + 1) * pb + (Cm + 1) * pc;
}
}
}
//cout << dp.at(A).at(B).at(C) << endl;
cout << fixed << setprecision(15) << dp.at(A).at(B).at(C) << endl;
}
|
#pragma region header
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define int ll
#define each(i, a) for (auto &&i : (a))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using vvs = vector<vs>;
using vd = vector<ld>;
using vvd = vector<vd>;
using vb = vector<bool>;
using vvb = vector<vb>;
using P = pair<int, int>;
using vp = vector<P>;
using int128 = __int128_t;//cin coutはできない
template <class T>
using greater_queue = priority_queue<T, vector<T>, greater<T>>;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a / gcd(a, b) * b;};
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
template <class T>
void CVEC(const T &v) {
int c = v.size() - 1;
for (int i = 0; i < c; i++) cout << v[i] << ' ';
if (c > -1) cout << v[c];
cout << '\n';
}
#pragma endregion header
signed main(){
int n; cin >> n;
vi a(n), b(n);
rep(i,n) cin >> a[i];
rep(i,n) cin >> b[i];
int mi = *max_element(ALL(a));
int mx = *min_element(ALL(b));
cout << max(mx - mi + 1, 0LL) << endl;
} | #include <bits/stdc++.h>
#include <vector>
#include<math.h>
#include<string.h>
using namespace std;
#define MAX 300005
#define MOD 1000000007
#define INF 1000000007
#define EPS 0.0000000001
#define CHAINS 18
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL)
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
int main()
{
int n,i;
scanf("%d",&n);
int a=0,b=1000;
for(i=0;i<n;i++)
{
int c;
scanf("%d",&c);
a=max(a,c);
}
for(i=0;i<n;i++)
{
int c;
scanf("%d",&c);
b=min(b,c);
}
if(b<a)
{
printf("0");
}
else
{
printf("%d",b-a+1);
}
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i, end) for (auto i = 0; i < end; ++i)
#define ALL(a) a.begin(), a.end()
using namespace std;
using ll = long long int;
const int MOD_NUM = 1e9 + 7;
vector<int> bits_to_indexes(const bitset<8>& bits) {
vector<int> indexes;
rep(i, 8) if (bits[i]) indexes.emplace_back(i);
return indexes;
}
int sum_by_indexes(const vector<int>& indexes, const vector<int>& A) {
int sum_a = 0;
for (int i : indexes) sum_a += A[i];
return sum_a;
}
void output_indexes(const vector<int>& indexes) {
cout << indexes.size();
for (int i : indexes) cout << ' ' << i + 1;
cout << endl;
}
int main() {
// Input
int N;
cin >> N;
vector<int> A(N);
rep(i, N) cin >> A[i];
// Process
rep(i, N) A[i] %= 200;
vector<int> bits_memory(200, 0);
bool judge = false;
int b, c;
rep(i, pow(2, N)) {
bitset<8> bits(i);
int sum_a = sum_by_indexes(bits_to_indexes(bits), A) % 200;
if (bits_memory[sum_a] == 0) {
bits_memory[sum_a] = i;
} else {
b = bits_memory[sum_a];
c = i;
judge = true;
break;
}
}
// Output
if (judge) {
cout << "Yes" << endl;
vector<int> B = bits_to_indexes((bitset<8>)b);
output_indexes(B);
vector<int> C = bits_to_indexes((bitset<8>)c);
output_indexes(C);
} else {
cout << "No" << endl;
}
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
int n,a[205];
int f[205][205],pre[205][205];
int main(){
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i],a[i]%=200;
for(int i=1;i<=n;i++){
f[i][a[i]]=1;
for(int j=0;j<=200;j++){
for(int k=1;k<i;k++){
if(f[k][(j-a[i]+200)%200]){
pre[i][j]=k;
f[i][j]=1;
}
}
}
}
for(int i=0;i<200;i++){
int cnt=0,a1=0,a2=0;
for(int j=1;j<=n;j++){
if(f[j][i]){
if(!a1) a1=j;
else if(!a2) a2=j;
cnt++;
}
}
if(cnt>=2){
puts("Yes");
vector<int> v1,v2;
int mod=i;
while(a1){
//cout<<a1<<endl;
v1.push_back(a1);
int t=a1;
a1=pre[a1][mod];
mod=(mod-a[t]+200)%200;
}
mod=i;
while(a2){
v2.push_back(a2);
int t=a2;
a2=pre[a2][mod];
mod=(mod-a[t]+200)%200;
}
reverse(v1.begin(),v1.end());
reverse(v2.begin(),v2.end());
cout<<v1.size()<<' ';
for(int k=0;k<v1.size();k++) cout<<v1[k]<<' ';
cout<<endl;
cout<<v2.size()<<' ';
for(int k=0;k<v2.size();k++) cout<<v2[k]<<' ';
return 0;
}
}
puts("No");
} |
#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(const string& s) {
return '"' + s + '"';
}
string to_string(const char* s) {
return to_string((string) s);
}
string to_string(bool b) {
return (b ? "true" : "false");
}
string to_string(vector<bool> v) {
bool first = true;
string res = "{";
for (int i = 0; i < static_cast<int>(v.size()); i++) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(v[i]);
}
res += "}";
return res;
}
template <size_t N>
string to_string(bitset<N> v) {
string res = "";
for (size_t i = 0; i < N; i++) {
res += static_cast<char>('0' + v[i]);
}
return res;
}
template <typename A>
string to_string(A v) {
bool first = true;
string res = "{";
for (const auto &x : v) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(x);
}
res += "}";
return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
#define fi first
#define se second
#define pb push_back
#define mod(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,a,b) for(int i = a; i < b; i++)
#define forr(i,a,b) for(int i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
const ll mod = 1e9+7;
ll mul(ll a,ll b){return ((a%mod)*(b%mod))%mod;}
ll sum(ll a,ll b){return ((a%mod)+(b%mod))%mod;}
ll sub(ll a,ll b){return ((a%mod)-(b%mod))%mod;}
ll power(ll a,ll b){
ll res = 1;
while(b){
if(b&1)res = mul(res,a);
b >>= 1;
a = mul(a,a);
}
return res;
}
const int maxn = 19;
const int oo = 1e9;
int N,M,memo[1<<maxn],seen[maxn][maxn],chido[1<<maxn];
int dp(int mask){
if(mask == (1<<N)-1)return 0;
int &res = memo[mask];
if(res != -1)return res;
res = oo;
int maskinv = 0;
forn(i,0,N)if(!(mask&(1<<i)))maskinv |= (1<<i);
for(int newmask = maskinv; newmask; newmask=(newmask-1)&maskinv){
int can = chido[newmask];
if(can)res = min(res,1+dp(newmask|mask));
}
return res;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
forn(i,0,(1<<maxn))memo[i] = -1;
cin >> N >> M;
forn(i,0,M){
int u,v; cin >> u >> v; u--; v--;
seen[u][v] = seen[v][u] = 1;
}
forn(i,0,(1<<N)){
vi act;
forn(j,0,N)if(i&(1<<j))act.pb(j);
int can = 1;
forn(j,0,(int)act.size()){
forn(k,j+1,(int)act.size()){
int u = act[j];
int v = act[k];
if(seen[u][v] || seen[v][u])continue;
can = 0;
}
}
chido[i] = can;
}
int res = dp(0);
cout << res << '\n';
return 0;
}
/*
__builtin_mul_overflow(x,y,&x)
-fsplit-stack
*/
| #include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
int H, W, N, M;
cin >> H >> W >> N >> M;
int mat[H][W];
rep(i, H) rep(j, W) {
mat[i][j] = 0;
}
vector<P> light;
rep(i, N) {
int p1, p2;
cin >> p1 >> p2;
light.push_back((P){p1-1, p2-1});
}
rep(i, M) {
int p1, p2;
cin >> p1 >> p2;
mat[p1-1][p2-1] = -1;
}
int count = 0;
for(auto p : light) {
if(mat[p.first][p.second] == 0) {
count++;
mat[p.first][p.second] = 1;
int i = 1;
while(p.first+i < H && mat[p.first+i][p.second] != -1) {
mat[p.first+i][p.second] = 1;
count++;
i++;
}
i = 1;
while(p.first-i >= 0 && mat[p.first-i][p.second] != -1) {
mat[p.first-i][p.second] = 1;
count++;
i++;
}
}
}
for(auto p : light) {
if(mat[p.first][p.second] == 2) continue;
int i = 1;
while(p.second+i < W && mat[p.first][p.second+i] != -1) {
if(mat[p.first][p.second+i] == 0) count++;
mat[p.first][p.second+i] = 2;
i++;
}
i = 1;
while(p.second-i >= 0 && mat[p.first][p.second-i] != -1) {
if(mat[p.first][p.second-i] == 0) count++;
mat[p.first][p.second-i] = 2;
i++;
}
}
cout << count << endl;
} |
#pragma GCC optimize("O2")
#pragma GCC target("avx")
#include <cstdio>
#include <functional>
#include <queue>
#include <tuple>
#include <vector>
using namespace std;
using ll = long long;
#define shift 30
inline int get_digit() {
int x = 0, f = 1;
char c = getchar();
while(c > '9' || c < '0') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
x = (x * 10) + (c ^ 48);
c = getchar();
}
return x * f;
}
int main() {
int R = get_digit(), C = get_digit();
int A[250000], B[250000];
int dist[500000], cost, pt, to_hide = R * C;
vector<ll> s;
s.reserve(2 * R * C);
priority_queue<ll, vector<ll>, greater<ll>> queue(s.begin(), s.end());
for(int i = 0; i < R * C; ++i) {
if(i % C != C - 1) A[i] = get_digit();
dist[i] = 0;
}
for(int i = 0; i < (R - 1) * C; ++i) B[i] = get_digit();
dist[0] = -10000000;
queue.push((ll)(-10000000) << shift);
while(queue.size()) {
pt = queue.top() & ((1 << shift) - 1);
if(pt == to_hide - 1) break;
cost = queue.top() >> shift;
queue.pop();
if(pt < to_hide) {
if(pt % C != C - 1 & cost + A[pt] < dist[pt + 1]) {
dist[pt + 1] = cost + A[pt];
queue.push(((ll)dist[pt + 1] << shift) | (pt + 1));
}
if(pt % C != 0 & cost + A[pt - 1] < dist[pt - 1]) {
dist[pt - 1] = cost + A[pt - 1];
queue.push(((ll)dist[pt - 1] << shift) | (pt - 1));
}
if(pt < to_hide - C & cost + B[pt] < dist[pt + C]) {
dist[pt + C] = cost + B[pt];
queue.push(((ll)dist[pt + C] << shift) | (pt + C));
}
if(cost + 1 < dist[pt + to_hide]) {
dist[pt + to_hide] = cost + 1;
queue.push(((ll)dist[pt + to_hide] << shift) | (pt + to_hide));
}
} else {
if(to_hide < pt - C && cost + 1 < dist[pt - C]) {
dist[pt - C] = cost + 1;
queue.push(((ll)(cost + 1) << shift) | (pt - C));
}
if(cost < dist[pt - to_hide]) {
dist[pt - to_hide] = cost;
queue.push(((ll)cost << shift) | (pt - to_hide));
}
}
}
printf("%d\n", dist[to_hide - 1] - dist[0]);
} | #include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mkp make_pair
#define pb push_back
#define sz(v) (int)(v).size()
typedef long long LL;
typedef double db;
template<class T>bool ckmax(T&x,T y){return x<y?x=y,1:0;}
template<class T>bool ckmin(T&x,T y){return x>y?x=y,1:0;}
#define rep(i,x,y) for(int i=x,i##end=y;i<=i##end;++i)
#define per(i,x,y) for(int i=x,i##end=y;i>=i##end;--i)
inline int read(){
int x=0,f=1;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=0;ch=getchar();}
while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
return f?x:-x;
}
const int V = 1005;
const int N = 500005;
const int M = 12 * V * V;
struct edge {
int nx, to, vl;
} e[M];
int hed[N], et;
inline void adde(int u, int v, int d) {
// cerr << u << ' ' << v << ' ' << d << '\n';
e[++et].nx = hed[u], e[et].to = v, e[et].vl = d, hed[u] = et;
}
int n, m, a[V][V], b[V][V], dis[N];
bool vis[N];
inline int id(int x, int y) {
return (x - 1) * m + y;
}
inline void Dij() {
priority_queue<pair<int, int> >pq;
memset(dis, 0x3f, sizeof dis);
pq.push(mkp(dis[1] = 0, 1));
while(!pq.empty()) {
int u = pq.top().se; pq.pop();
if(vis[u]) continue;
vis[u] = 1;
for(int i = hed[u]; i; i = e[i].nx) {
int v = e[i].to;
if(ckmin(dis[v], dis[u] + e[i].vl)) {
pq.push(mkp(-dis[v], v));
}
}
}
}
signed main() {
n = read(), m = read();
rep(i, 1, n) rep(j, 1, m - 1) a[i][j] = read();
rep(i, 1, n - 1) rep(j, 1, m) b[i][j] = read();
rep(i, 1, n) {
rep(j, 1, m - 1) {
adde(id(i, j), id(i, j + 1), a[i][j]);
}
rep(j, 2, m) {
adde(id(i, j), id(i, j - 1), a[i][j - 1]);
}
if(i < n) {
rep(j, 1, m) adde(id(i, j), id(i + 1, j), b[i][j]);
}
rep(j, 1, m) {
adde(id(i, j), id(i, j) + n * m, 1);
adde(id(i, j) + n * m, id(i, j), 0);
if(i > 1) adde(id(i, j) + n * m, id(i - 1, j) + n * m, 1);
}
}
Dij();
cout << dis[id(n, m)] << '\n';
} |
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std; //using namespace atcoder;
template<typename T> using ve=vector<T>;
using ll=long long; using ld=long double; using str=string; using pint=pair<ll,ll>;
using vll=ve<ll>; using vd=ve<ld>; using vs=ve<str>; using vll2=ve<ve<ll>>;
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#define b2e(v) v.begin(),v.end()
#define p2a(v, p) v[p.first][p.second]
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repi(i,n) for(ll i=(n-1);i>=0;i--)
#define repe(e,v) for(auto e:v)
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
const int MOD=1000000007;
//const int MOD=998244353;
ll divceil (ll x, ll div) { return (x/div) + (x%div>0); }
ll divfloor(ll x, ll div) { return (x/div) - (x%div<0); }
int main() {
ll kn; cin >> kn;
ll nn; cin >> nn;
ll mn; cin >> mn;
vll a1(kn);
rep(i,kn) {
ll x;
cin >> x; a1[i]=x;
}
// 1. 剰余なしの値を設定B=(floor(MA/N))
ll ct=0;
vll b1(kn);
ve<ld> lb1(kn, 0);
rep(i,kn) {
b1[i] =divfloor(mn*a1[i],nn);
if(a1[i]) lb1[i] =(ld)(mn*a1[i])/(ld)nn;
ct+=b1[i];
}
// 2. 誤差とidxのpairの配列を作成(floorなしB-B)
vector<pair<ld,ll>> vp1;
rep(i,kn) {
vp1.push_back({lb1[i]-(ld)b1[i],i});
}
// 3. 配列を誤差で降順ソート
sort( vp1.begin(), vp1.end(), greater<pair<ld,ll>>() );
// 4. 剰余分を更新
rep(i,mn-ct) {
b1[vp1[i].second]++;
}
rep(i,kn) {
cout << b1[i] << " ";
}
cout << endl;
}
| #include<iostream>
#include<cstring>
using namespace std;
int a,b;
int x[100010];
int main()
{
cin>>a>>b;
if(a==b)
{
for(int i=1;i<=a;i++) x[i]=i;
for(int i=1+a;i<=a+b;i++) x[i]=-(i-a);
}else if(a>b)
{
for(int i=1;i<=a;i++) x[i]=i;
for(int i=1+a;i<=a+b-1;i++) x[i]=-(i-a);
int sum=0;
for(int i=b;i<=a;i++)
{
sum+=-x[i];
}
x[a+b]=sum;
}else if(a<b)
{
for(int i=1;i<=b;i++) x[i]=-i;
for(int i=1+b;i<=a+b-1;i++) x[i]=(i-b);
int sum=0;
for(int i=a;i<=b;i++)
{
sum+=x[i];
}
x[a+b]=-sum;
}
for(int i=1;i<=a+b;i++) cout<<x[i]<<" ";
return 0;
}
|
/*ver 7*/
#include <bits/stdc++.h>
using namespace std;
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vd = vector<ld>;
using vs = vector<string>;
using vb = vector<bool>;
using vvl = vector<vector<ll>>;
using vvd = vector<vector<ld>>;
using vvs = vector<vector<string>>;
using vvb = vector<vector<bool>>;
using pll = pair<ll,ll>;
using mll = map<ll,ll>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
#define each(x,v) for(auto& x : v)
#define reps(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define mp make_pair
const ll INF = 1LL << 60;
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<=b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ) //被り削除
#define debug cout << "line : " << __LINE__ << " debug" << endl;
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ind(...) long double __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define inc(...) char __VA_ARGS__; in(__VA_ARGS__)
void in(){}
template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
template <typename T> void in1(T &s) {rep(i,s.size()){in(s[i]);}}
template <typename T> void in2(T &s,T &t) {rep(i,s.size()){in(s[i],t[i]);}}
template <typename T> void in3(T &s,T &t,T &u) {rep(i,s.size()){in(s[i],t[i],u[i]);}}
template <typename T> void in4(T &s,T &t,T &u,T &v) {rep(i,s.size()){in(s[i],t[i],u[i],v[i]);}}
template <typename T> void in5(T &s,T &t,T &u,T &v,T &w) {rep(i,s.size()){in(s[i],t[i],u[i],v[i],w[i]);}}
void out(){cout << endl;}
template <typename T,class... U> void out(const T &t,const U &...u){cout << t; if(sizeof...(u)) cout << " "; out(u...);}
void die(){cout << endl;exit(0);}
template <typename T,class... U> void die(const T &t,const U &...u){cout << t; if(sizeof...(u)) cout << " "; die(u...);}
template <typename T> void outv(T s) {rep(i,s.size()){if(i!=0)cout<<" ";cout<<s[i];}cout<<endl;}
template <typename T> void out1(T s) {rep(i,s.size()){out(s[i]);}}
template <typename T> void out2(T s,T t) {rep(i,s.size()){out(s[i],t[i]);}}
template <typename T> void out3(T s,T t,T u) {rep(i,s.size()){out(s[i],t[i],u[i]);}}
template <typename T> void out4(T s,T t,T u,T v) {rep(i,s.size()){out(s[i],t[i],u[i],v[i]);}}
template <typename T> void out5(T s,T t,T u,T v,T w) {rep(i,s.size()){out(s[i],t[i],u[i],v[i],w[i]);}}
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
template <typename T> T allSum(vector<T> a){T ans=T();each(it,a)ans+=it;return ans;}
ll ceilDiv(ll a,ll b) {return (a+b-1)/b;}
ld dist(pair<ld,ld> a, pair<ld,ld> b){return sqrt(abs(a.fi-b.fi)*abs(a.fi-b.fi)+abs(a.se-b.se)*abs(a.se-b.se));} // 2点間の距離
ll gcd(ll a, ll b) { return b != 0 ? gcd(b, a % b) : a; }
ll lcm(ll a,ll b){ return a / gcd(a,b) * b;}
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
#define YES(n) ((n) ? "YES" : "NO" )
#define Yes(n) ((n) ? "Yes" : "No" )
#define yes(n) ((n) ? "yes" : "no" )
int main(){
init();
inl(a,b);
out(100-(double)b/a*100);
return 0;
} | #pragma GCC optimize ("O2")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll F[140];
F[0] = 1;
F[1] = 1;
rep(i, 130) {
F[i + 2] = F[i] + F[i + 1];
}
rep(i, 130) {
cesp(i);
ce(F[i]);
}
ll N;
cin >> N;
int f[100] = {}, saisho = 0;
for (int i = 90; i >= 0; i--) {
if (N >= F[i]) {
f[i] = 1;
N -= F[i];
if (saisho == 0) saisho = i;
}
}
vector<int> kotae;
for (int i = saisho; i >= 1; i--) {
if (f[i]) kotae.pb(1 + (i % 2));
kotae.pb(4 - (i % 2));
}
co(kotae.size());
rep(i, kotae.size()) co(kotae[i]);
Would you please return 0;
} |
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#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,class ...A> inline void read(t &x,A &...a){
read(x);read(a...);
}
template<class t> inline void write(t x){
if(x<0) putchar('-'),write(-x);
else{if(x>9) write(x/10);putchar('0'+x%10);}
}
const int N=1e5+5;
int n,m,tp[N],a[N],b[N];
long long ans;
void GG(){
write(-1);
exit(0);
}
signed main(){
read(n,m);
for(int i=1;i<=n;i++) read(tp[i]),a[i]=tp[i]-tp[i-1]-1;a[n+1]=m-tp[n];
for(int i=1;i<=n;i++) read(tp[i]),b[i]=tp[i]-tp[i-1]-1;b[n+1]=m-tp[n];n++;
for(int i=1,j=1;i<=n;i++) if(b[i]){
while(!a[j]) j++;
int cur=0,l=j;
while(j<=n&&cur<b[i]) cur+=a[j++];
if(cur>b[i]) GG();
ans+=max(i-l,0)+max(j-1-i,0);
}
write(ans);
} | #include <bits/stdc++.h>
using namespace std;
using int64 = long long;
const int mod = 998244353;
const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;
struct IoSetup {
IoSetup() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
cerr << fixed << setprecision(10);
}
} iosetup;
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
os << p.first << " " << p.second;
return os;
}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
is >> p.first >> p.second;
return is;
}
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
for (int i = 0; i < (int) v.size(); i++) {
os << v[i] << (i + 1 != v.size() ? " " : "");
}
return os;
}
template<typename T>
istream &operator>>(istream &is, vector<T> &v) {
for (T &in : v) is >> in;
return is;
}
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T = int64>
vector<T> make_v(size_t a) {
return vector<T>(a);
}
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
t = v;
}
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
for (auto &e : t) fill_v(e, v);
}
template<typename F>
struct FixPoint : F {
FixPoint(F &&f) : F(forward<F>(f)) {}
template<typename... Args>
decltype(auto) operator()(Args &&... args) const {
return F::operator()(*this, forward<Args>(args)...);
}
};
template<typename F>
inline decltype(auto) MFP(F &&f) {
return FixPoint<F>{forward<F>(f)};
}
int main() {
int N, L;
cin >> N >> L;
vector< int > A(N + 2), B(N + 2);
for(int i = 1; i <= N; i++) cin >> A[i];
for(int i = 1; i <= N; i++) cin >> B[i];
A[N + 1] = L + 1;
B[N + 1] = L + 1;
for(int i = 0; i < N + 2; i++) A[i] -= i;
for(int i = 0; i < N + 2; i++) B[i] -= i;
map< int, int > ls, rs;
for(int i = 0, j; i < N + 2; i = j) {
for(j = i; j < N + 2 and A[i] == A[j]; j++) ;
ls[A[i]] = i;
rs[A[i]] = j;
}
int64 ret = 0;
for(int i = 0, j; i < N + 2; i = j) {
for(j = i; j < N + 2 and B[i] == B[j]; j++) ;
if(!ls.count(B[i])) {
cout << -1 << endl;
exit(0);
}
ret += max(ls[B[i]] - i, 0);
ret += max(j - rs[B[i]], 0);
}
cout << ret << endl;
}
|
/*
"An anomaly, I'm Muhammad Ali
Cause I know one day I'm gonna be the"
- Greatest, Eminem
*/
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long int ll;
#define ff first
#define Shazam ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ss second
#define all(c) c.begin(),c.end()
#define endl "\n"
#define test() int t; cin>>t; while(t--)
#define fl(i,a,b) for(int i = a ; i <b ;i++)
#define get(a) fl(i,0,a.size()) cin>>a[i];
#define pra(a) fl(i,0,a.size()) cout<<a[i]<<" "; cout<<endl;
#define pr(a,n) fl(i,0,n) cout<<a[i]<<" "; cout<<endl;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const ll INF = 2e18;
const int inf = 2e9;
const int mod1 = 1e9 + 7;
int main(){
Shazam;
long double a, b; cin >> a >> b;
cout << fixed << setprecision(10) << a * b / 100.0 << endl;
return 0;
} | //#define _GLIBCXX_DEBUG
//#include "atcoder/all"
//using namespace atcoder;
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
#define Dump(x) \
if (dbg) { \
cerr << #x << " = " << (x) << endl; \
}
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) (((n) >> (k)) & 1) /*nのk bit目*/
namespace mydef {
const int INF = 1ll << 60;
const int MOD = 1e9 + 7;
template <class T>
bool chmin(T& a, const T& b) {
if (a > b) {
a = b;
return 1;
} else
return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
if (a < b) {
a = b;
return 1;
} else
return 0;
}
void Yes(bool flag = true) {
if (flag)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
void No(bool flag = true) {
Yes(!flag);
}
void YES(bool flag = true) {
if (flag)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
void NO(bool flag = true) {
YES(!flag);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
std::fill((T*)array, (T*)(array + N), val);
}
bool dbg = true;
} // namespace mydef
using namespace mydef;
#define pb push_back
//#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<pair<int, int>>
#define vvp vector<vector<pair<int, int>>>
#define pi pair<int, int>
//#define P pair<int, int>
//#define V vector<int>
//#define S set<int>
#define asn ans
string S;
void solve() {
}
signed main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cin >> S;
int cnt[3] = {};
for (auto& c : S)
cnt[(c - '0') % 3]++;
int SUM = cnt[1] + cnt[2] * 2;
int ans = 0;
if (SUM % 3 == 0) {
ans = 0;
} else if (SUM % 3 == 1) {
if (cnt[1])
ans = 1;
else if (cnt[2] >= 2)
ans = 2;
else
ans = -1;
} else {
if (cnt[2])
ans = 1;
else if (cnt[1] >= 2)
ans = 2;
else
ans = -1;
}
if (ans == cnt[1] + cnt[2] + cnt[0])
ans = -1;
cout << ans << endl;
solve();
return 0;
}
|
// atcoder/arc106/B/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/
#include <bits/stdc++.h>
#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))
using namespace std;
template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }
template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }
using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;
constexpr array<int, 8> di({0, 1, -1, 0, 1, -1, 1, -1});
constexpr array<int, 8> dj({1, 0, 0, -1, 1, -1, -1, 1});
constexpr lli mod = 1e9 + 7;
class UnionFind {
public:
UnionFind(int n) {
r.resize(n, 0);
p.resize(n, -1);
}
void unite(int a, int b) {
a = find(a);
b = find(b);
if (a == b) return ;
if (r[a] > r[b]) {
p[a] += p[b];
p[b] = a;
} else {
p[b] += p[a];
p[a] = b;
if(r[a] == r[b]) r[b]++;
}
return ;
}
int find(int a) {
return (p[a] < 0) ? a : p[a] = find(p[a]);
}
bool same(int a, int b) {
return find(a) == find(b);
}
size_t size(int n) {
return -p.at(find(n));
}
private:
vector<int> r, p;
};
int main(int argc, char *argv[])
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.setf(ios_base::fixed);
cout.precision(15);
int n, m;
while (cin >> n >> m) {
vec<lli> a(n);
vec<lli> b(n);
cin >> a >> b;
UnionFind uf(n);
for (int i = 0; i < m; ++i) {
int x, y;
cin >> x >> y;
--x;
--y;
uf.unite(x, y);
}
for (int i = 0; i < n; ++i) {
uf.find(i);
}
map<int, lli> sum_a, sum_b;
for (int i = 0; i < n; ++i) {
sum_a[uf.find(i)] += a[i];
sum_b[uf.find(i)] += b[i];
}
bool f = true;
for (int i = 0; i < n; ++i) {
f = f && (sum_a[i] == sum_b[i]);
}
cout << (f ? "Yes" : "No") << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
int32_t main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, m; cin >> n >> m;
vector<int> initial(n), final(n);
for(int &i : initial) cin >> i;
for(int &i : final) cin >> i;
vector< vector<int> > adj(n);
for(int i = 0; i < m; i ++) {
int u, v; cin >> u >> v;
u --, v --;
adj[u].push_back(v);
adj[v].push_back(u);
}
vector<int> vis(n, false);
function<int (int)> dfs = [&] (int u) {
vis[u] = true;
int diff = final[u] - initial[u];
for(int v : adj[u]) {
if(!vis[v])
diff += dfs(v);
}
return diff;
};
bool ok = true;
for(int i = 0; i < n; i ++) {
if(!vis[i]) {
ok &= (!dfs(i));
}
}
if(ok) cout << "Yes" << endl;
else cout << "No" << endl;
return 0;
} |
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
const ll INF_L = 1LL << 60;
const int INF_I = 1 << 30;
const int MOD = (int)1e9 + 7;
const double PI = acos(-1);
int dx[] = {1, 0, -1, 0};
int dy[] = {0, -1, 0, 1};
int main()
{
int n;
cin >> n;
complex<double> a, b;
double x, y;
cin >> x >> y;
a = {x, y};
cin >> x >> y;
b = {x, y};
auto m = (a + b) / 2.0;
auto r = m + (a - m) * polar(1.0, PI * 2.0 / n);
printf("%.10f\n%.10f", r.real(), r.imag());
return 0;
}
| #include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#include <bitset>
#include <complex>
#define ll long long
#define INF 1000000000000000001
#define MOD 1000000007
#define MOD2 998244353
const double PI = 3.14159265359;
using namespace std;
int main(){
int N;
cin >> N;
double x0,y0, x2,y2;
cin >> x0 >> y0 >> x2 >> y2;
double xc = (x0+x2)/2;
double yc = (y0+y2)/2;
double theta = (2*PI)/N;
double xd = x0-xc;
double yd = y0-yc;
double x1, y1;
x1 = xd*cos(theta) - yd*sin(theta);
y1 = xd*sin(theta) + yd*cos(theta);
x1 += xc;
y1 += yc;
cout << fixed << setprecision(10) << x1 << " " << y1;
return 0;
}
|
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define endl "\n"
#define pb push_back
#define fi first
#define se second
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define rsz resize
#define ins insert
#define pqueue priority_queue
#define ar array
#define vt vector
#define for_base(i, a, b, x) for (int i=((a)<(b))?(a):(a)-1; ((a)<(b))?i<(b):i>=(b); ((a)<(b))?i+=(x):i-=(x))
#define FOR1(a) for_base(i, 0, a, 1)
#define FOR2(i, a) for_base(i, 0, a, 1)
#define FOR3(i, a, b) for_base(i, a, b, 1)
#define FOR4(i, a, b, x) for_base(i, a, b, x)
#define FIFTH(a, b, c, d, e, ...) e
#define FOR(...) FIFTH(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define trav(a, x) for (auto& a: x)
#define FIT(i, x) for (auto i=(x).begin(); i!=(x).end(); ++i)
#define RIT(i, x) for (auto i=(x).rbegin(); i!=(x).rend(); ++i)
#define finish(...) return void(print(__VA_ARGS__))
typedef long long ll;
typedef long double ld;
typedef string str;
template<class T> using mqueue = pqueue<T, vector<T>, greater<T>>;
template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T> bool umin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool umax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template<class T> void read(T& x) { cin >> x; }
template<class H, class T> void read(pair<H, T>& p) { cin >> p.f >> p.s; }
template<class A, size_t S> void read(array<A, S>& x) { trav(a, x) read(a); }
template<class T> void read(vector<T>& v) { trav(i, v) read(i); }
template<class H, class... T> void read(H& h, T&... t) { read(h); read(t...); }
template<class H, class T> ostream &operator<<(ostream &o, pair<H, T> &p) { o << p.fi << " " << p.se; return o; }
template<class H, class T> ostream &operator<<(ostream &o, vector<pair<H, T>> &v) { string s; trav(i, v) o << s << i, s = "\n"; return o; }
template<class T, size_t S> ostream &operator<<(ostream &o, array<T, S> &a) { string s; trav(i, a) o << s << i, s = " "; return o; }
template<class T, size_t S> ostream &operator<<(ostream &o, vector<array<T, S>> &v) { string s; trav(i, v) o << s << i, s = "\n"; return o; }
template<class T> ostream &operator<<(ostream &o, vector<T> &v) { string s; trav(i, v) o << s << i, s = " "; return o; }
template<class T> ostream &operator<<(ostream &o, vector<vector<T>> &v) { string s; trav(i, v) o << s << i, s = "\n"; return o; }
template<class T> void write(T x) { cout << x; }
template<class H, class... T> void write(const H &h, const T &...t) { write(h); write(t...); }
void print() { write('\n'); }
template<class H, class... T> void print(const H &h, const T &...t) { write(h); if (sizeof...(t)) write(' '); print(t...); }
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) { cerr << h; if(sizeof...(t)) cerr << ", "; DBG(t...); }
#ifdef local
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif
const int mod = 1e9 + 7;
const int dx[4] = {-1, 1, 0, 0}, dy[4] = {0, 0, -1, 1};
void solve() {
ll n;
read(n);
set<ll> ans;
for(ll i=1; i*i<=n; ++i) {
if(n%i==0) {
ans.ins(i);
ans.ins(n/i);
}
}
trav(x, ans)
print(x);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int T = 1;
/* read(T); */
for(int tc=1; tc<=T; ++tc) {
/* write("Case #", tc, ": "); */
solve();
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (long long i = 0; i < (n); i++)
using ll = long long;
int main() {
ll n; cin >> n;
vector<ll> a(n);
rep(i, n) cin >> a[i];
vector<ll> cnt(405);
rep(i, n) {
cnt[a[i]+200]++;
}
ll ans = 0;
for (int i = -200; i <= 200; i++) {
for (int j = i + 1; j <= 200; j++) {
ans += cnt[i + 200] * cnt[j + 200] * (i - j) * (i - j);
}
}
cout << ans << endl;
} |
#line 1 "main.cpp"
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
using namespace std;
void solve() {
int n;
cin >> n;
vector<int> xs(n), ys(n), ps(n);
for (auto& x : xs) cin >> x;
for (auto& y : ys) cin >> y;
for (auto& p : ps) {
cin >> p;
--p;
}
vector<int> prev(n);
for (int i = 0; i < n; ++i) prev[ps[i]] = i;
vector<int> is(n);
iota(is.begin(), is.end(), 0);
sort(is.begin(), is.end(),
[&](auto i, auto j) { return xs[i] < xs[j]; });
vector<pair<int, int>> ans;
for (auto i : is) {
if (ps[i] == i) continue;
if (ys[ps[i]] >= xs[i]) {
cout << "-1\n";
return;
}
int j = prev[i];
ans.emplace_back(i, j);
swap(prev[ps[i]], prev[ps[j]]);
swap(ps[i], ps[j]);
}
cout << ans.size() << "\n";
for (auto [i, j] : ans) {
cout << i + 1 << " " << j + 1 << "\n";
}
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
solve();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl
using ll = long long;
const int maxn = 1e6 + 5;
struct bit {
vector<ll> a;
int n;
void init(int _n) {
n = _n;
a.resize(n+10);
}
void upd(int i, ll dx) {
for (; i<=n; i+=i&-i) {
a[i] += dx;
}
}
ll qry(int i) {
ll res = 0;
for (; i; i-=i&-i) {
res += a[i];
}
return res;
}
};
ll invs(vector<int> a) {
int n = a.size();
ll res = 0;
bit bit;
bit.init(n);
for (int i=n-1; i>=0; i--) {
res += bit.qry(a[i]);
bit.upd(a[i],+1);
}
return res;
}
vector<int> rand_perm(int n, int index=1) {
assert(n>=1);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
vector<int> a(n);
iota(a.begin(), a.end(), index);
shuffle(a.begin(), a.end(), rng);
return a;
}
// needs to be 1 cycle, with n-1 inversions
bool check(vector<int> a) {
int n = a.size();
if (invs(a) != n-1) return false;
for (int i=0; i<n; i++) {
a[i] --;
}
vector<int> viz(n,0);
int len = 0;
int at = 0;
while (!viz[at]) {
len++;
viz[at]=1;
at=a[at];
}
return len==n;
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
/*auto p = rand_perm(10);
while (!check(p)) {
p = rand_perm(10);
}
for (int x: p) cout<<x<<" ";
cout<<endl;*/
int n;
cin>>n;
vector<int> a(n);
for (int i=0; i<n; i++) {
cin>>a[i];
}
if (!check(a)) out(-1);
for (int i=0; i<n; i++) {
a[i] --;
}
vector<int> ans;
for (int i=0; i<n; i++) {
if (i>a[i]) {
for (int j=i-1; j>=a[i]; j--) {
ans.push_back(j);
}
}
}
assert(int(ans.size()) == n-1);
for (int i: ans) {
cout<<i+1<<"\n";
swap(a[i],a[i+1]);
}
assert(is_sorted(a.begin(),a.end()));
return 0;
}
|
// Hail god Yato
#include <bits/stdc++.h>
using namespace std;
#define hs ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = 1e18;
const ll MAX = 100001;
//
//
void solve(){
int n;
cin>>n;
vector<ll> fst(n), snd(n);
for(int i = 0; i < n; i++)
cin>>fst[i];
for(int j = 0; j < n; j++)
cin>>snd[j];
ll last = 0, mx = 0;;
for(int i = 0; i < n; i++){
ll ans = 0;
mx = max(mx, fst[i]);
ans = mx*snd[i];
if(last < ans)
last = ans;
cout<<last<<"\n";
}
}
signed main(){
hs;
ll t;
t=1;
// cin>>t;
for (int i=1; i<=t; i++){
//cout<<"Case #"<<i<<": ";
solve();
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;using ll=long long;using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;using vb=vector<bool>;using vvb=vector<vb>;using vvl=vector<vl>;using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;using vpl=vector<PL>;
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
// cin and cout of a vector
template<class T>class iterable{static false_type c(string v);template<class U>static auto c(U v)->decltype(all(v),true_type());static false_type c(...);public:const static bool value=decltype(c(declval<T>()))::value;};
template<class T,enable_if_t<iterable<T>::value,int> =0>ostream&operator<<(ostream&o,const T&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}template<class T>vector<T>&operator<<(vector<T>&v,const T&t){v.push_back(t);return v;}
// for loop
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define revv(i, a, b) for (int i = (int)(b-1); i >= (int)(a); i--)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
// #define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
// #define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
// #define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
// #define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
// Yes/no
#define cho(n,a,b) cout<< ((n)?a:b)<<endl;
void YES(int n){cho(n,"YES","NO");}void Yes(int n){cho(n,"Yes","No");}void Poss(int n){cho(n,"Possible","Impossible");}
#define pb push_back
#define rsortv(v) sort((v).rbegin(), (v).rend())
#define sortv(v) sort((v).begin(), (v).end())
// max/min
template<class T, class U>bool chmax(T&a,const U&b){bool x=a<b;x?a=b:b;return x;}template<class T, class U>bool chmin(T&a,const U&b){bool x=a>b;x?a=b:b;return x;}
template<class T, class U>auto max(const T&a,const U&b){return a<b?b:a;}template<class T, class U>auto min(const T&a,const U&b){return a<b?a:b;}
//========================================
//========================================
//========================================
template<class T>auto minv(const T&a){return *min_element(all(a));}
template<class T>auto smod(T a, T b){a %= b; if (a < 0); a+= b; return a;}
template<class T>auto maxv(const T&a){return *max_element(all(a));}
template<class T>auto sumv(const T&a){ll sum = 0; for(auto x: a) sum+= x; return sum;}
template<class T>void pr(const T&a){cout << a << endl;}
template<class T>void pr_precise(const T&a){cout.precision(10); cout << fixed << a << endl;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
// ll M = 1000000007;
ll M = 998244353;
unordered_map <ll, ll> m;
int main() {
int cases = 1;
// cin >> cases;
rep(CASE, cases){
ll n;
cin >> n;
vl A(n);
cin >> A;
vl B(n);
cin >> B;
vl C(n);
ll mp = 0;
ll ma = 0;
rep(i, n){
chmax(ma, A[i]);
chmax(mp, ma*B[i]);
pr(mp);
}
// pr(A);
// pr(B);
// pr(C);
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int main(void){
// Your code here!
int n,k;
cin>>n>>k;
int town[n][n];
vector<int> v(n-1);
for(int i=0;i<n-1;i++) v[i] = i+1;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cin>>town[i][j];
}
}
int p = 0;
int ans = 0;
int cnt = 0;
do{
for(int n:v){
ans += town[p][n];
p = n;
}
ans += town[p][0];
if(ans == k) cnt++;
ans = 0;
p = 0;
}while(next_permutation(v.begin(), v.end()));
cout<<cnt<<endl;
}
| #include <bits/stdc++.h>
#define st first
#define nd second
#define PQ priority_queue
using ll = long long ;
using namespace std;
using pii = pair<int,int>;
const int N = 3e5 + 10;
const int MOD = 0;
int a[N];
int main(){
int n, k;
scanf("%d %d", &n, &k);
for(int i =1; i <= n;i ++){
int x;
scanf("%d", &x);
a[x] ++;
}
ll ans = 0;
for(int i = 0; i <= n; i++){
k = min(k, a[i]);
ans += k;
}
printf("%lld", ans);
} |
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define fi first
#define se second
#define mset(a, b) memset(a, b, sizeof(a))
#define DBG(x) cout << "[" << #x << "]: " << x << endl
using ll = long long;
using pii = pair<int, int>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
template<class Ty> Ty randint(Ty a, Ty b) { return uniform_int_distribution<Ty>(a, b)(rng); }
template<class num> inline void rd(num& x) {
char c, neg = 0; while(isspace(c = getchar_unlocked()));
if(!isdigit(c)) neg = (c == '-'), x = 0;
else x = c - '0';
while(isdigit(c = getchar_unlocked())) x = (x << 3) + (x << 1) + c - '0';
x = neg ? -x : x; }
template <class Ty, class... Args> inline void rd(Ty& x, Args&... args) { rd(x); rd(args...); }
const int MAXN = 2e5 + 5, INF = 0x3f3f3f3f;
ll get(ll n) {
return n * (n + 1) / 2;
}
int main() {
int n; rd(n);
ll ans = 0;
for (int i = 0; i < n; i++) {
ll l, r; rd(l, r);
ans += get(r) - get(l-1);
}
printf("%lld\n", ans);
}
| #include <iostream>
#include <stdio.h>
#include <vector>
#include <map>
#include <stack>
#include <cstring>
#include <set>
#include <utility>
#include <iostream>
#include <iomanip>
#include <list>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cctype>
//#include <boost/multiprecision/cpp_int.hpp>
#include <unordered_set>
#include <bitset>
#include <cassert>
#include <numeric>
#include <complex>
#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define SUM(v) accumulate(ALL(v),0ll)
using ll = long long;
const ll INF=1e24;
const ll eps=1;
const double pi=3.14159265359;
const ll mod=1e9+7;
using I32 = int32_t;
using I64 = int64_t;
using namespace std;
//Union Find テンプレ
struct UnionFind {
vector<int> par , siz;
UnionFind(int n) : par(n,-1) , siz(n,1) { }
int root(int x) {
if(par[x] == -1) return x;
else return par[x] = root(par[x]);
}
bool issame(int x, int y) {
return root(x) == root(y);
}
bool unite(int x, int y) {
x = root(x) ; y = root(y);
if(x == y) return false;
if(siz[x] < siz[y]) swap(x,y);
par[y] = x;
siz[x] += siz[y];
return true;
}
int size(int x) {
return siz[root(x)];
}
};
typedef pair<int,int> P;
int func(int a,int b)
{
if(b==0)return a;
return func(b,a%b);
}
int main()
{
ll n;
cin>>n;
ll ans=0;
ll a,b;
REP(i,n)
{
cin>>a>>b;
ans+=(a+b)*(b-a+1)/2;
}
cout<<ans<<endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0 ; i < (n) ; i++)
#define rep1(i,n) for(int i = 1 ; i <= (n) ; i++)
#define rrep(i,n) for(int i = (n) - 1 ; i >= 0 ; i--)
#define rrep1(i,n) for(int i = (n) ; i > 0 ; i--)
#define MOD 1000000007
using ll = int64_t;
using P = pair<int, int>;
using PL = pair<ll,ll>;
using PD = pair<double,double>;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vP = vector<P>;
using p_q = priority_queue<int, vi, greater<int>>;
const int INF = 1001001001;
const ll LINF = (1ll<<62) + ((1ll<<62)-1);
#define v(n) vector<n>
#define vv(n) vector<vector<n>>
#define vvv(n) vector<vector<vector<n>>>
#define p_q(n) priority_queue<(n), v(n), greater<n>>
#define line cout << "================================" << endl;
#define Yn(x) ((x) ? "Yes" : "No")
#define yn(x) ((x) ? "yes" : "no")
#define mmax(a,b) a = max(a,b)
#define mmin(a,b) a = min(a,b)
#define debug(x) cout << #x" : " << (x) << endl;
#define output(x) cout << (x) << endl;
#define outs(x) cout << #x << endl;
#define mod(n) %(n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
template <typename T> void chmin(T& a, T b){if(a>b)a=b;}
template <typename T> void chmax(T& a, T b){if(a<b)a=b;}
class alucrex{
public:
void vin(vi& a){rep(i,a.size())cin>>a[i];}
void vin1(vi& a){rep1(i,a.size())cin>>a[i];}
void vvin(vvi& a){rep(i,a.size())rep(j,a[i].size())cin>>a[i][j];}
void vvdes(vvi& a){rep(i,a.size()){rep(j,a[i].size()){
cout << a[i][j] << " ";}cout<<endl;
}}
void vinl(vl& a){rep(i,a.size())cin>>a[i];}
void vvinl(vvl& a){rep(i,a.size())rep(j,a[i].size())cin>>a[i][j];}
void vvdesl(vvl& a){rep(i,a.size()){rep(j,a[i].size()){
cout << a[i][j] << " ";}cout<<endl;
}}
void vpin(vP& a){for(auto& x:a)cin>>x.first>>x.second;}
template<typename T>
void vvd(vv(T)& a){rep(i,a.size()){rep(j,a[i].size()){
cout << a[i][j] << " ";}cout<<endl;
}}
};
#include <chrono>
using namespace chrono;
int main(){
alucrex al;
steady_clock::time_point start = steady_clock::now();
map<int, vi> mp;
int n, m; cin >> n >> m;
rep(i,m) {
int x, y; cin >> x >> y;
mp[x].push_back(y);
}
set<int> table;
table.insert(n);
for(auto i : mp) {
vi erase, add;
for(int j : i.second) {
int flag = 0;
if(table.count(j - 1) || table.count(j + 1)) add.push_back(j);
else if(table.count(j)) erase.push_back(j);
}
for(int j : add) table.insert(j);
for(int j : erase) table.erase(j);
}
cout << table.size() << endl;
steady_clock::time_point end = steady_clock::now();
auto res = end - start;
//cout << "実行時間:" << duration_cast<milliseconds>(res).count() << "ms" << endl;
} |
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
set<int> s;
s.emplace(n);
int m;
cin >> m;
map<int, vector<int>> mp;
for (int i = 0; i < m; ++i) {
int x, y;
cin >> x >> y;
mp[x].push_back(y);
}
for(auto [x, v] : mp) {
sort(v.begin(), v.end());
vector<int> add;
vector<int> er;
for(auto e : v) {
if(s.count(e)) {
if(!s.count(e - 1) and !s.count(e + 1)) er.push_back(e);
} else {
if(s.count(e - 1) or s.count(e + 1)) add.push_back(e);
}
}
for(auto e : add) s.emplace(e);
for(auto e : er) s.erase(e);
}
cout << s.size() << endl;
} |
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <cstdlib>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <unordered_map>
#include <memory.h>
#include <unordered_set>
#include <fstream>
using namespace std;
int main(void)
{
cin.tie(0);
ios::sync_with_stdio(false);
long long int n;
long long int res = 0;
cin >> n;
stringstream ss;
ss << n;
long long int val = 1;
int len = ss.str().length();
for (int i = 1; i < len; i++)
{
long long int x = ((i - 1) / 3);
res += ((x * (10 * val - val)));
val *= 10;
}
long long int x = ((len - 1) / 3);
res += ((x * (n - val + 1)));
cout << res << '\n';
return 0;
} | #include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> //Policy Based Data Structure
using namespace __gnu_pbds; //Policy Based Data Structure
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; //Policy Based Data Structure
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int> >
#define mk(arr,n,type) type *arr = new type[n]
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define int long long
#define ld long double
#define nn '\n'
#define w(t) cin>>tc; while(tc--)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x,y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define lb(v,x) lower_bound(v.begin(),v.end(),x) //returns address of number equal to or just greater than x ,else it is v.end() (i.e. not found)
#define ub(v,x) upper_bound(v.begin(),v.end(),x)
#define all(x) x.begin(), x.end()
#define fill(a, b) memset(a, b, sizeof(a))
#define sortall(x) sort(all(x))
#define tr(it,a) for(auto it = a.begin(); it != a.end(); it++)
#define ps(x,y) fixed<<setprecision(y)<<x
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define PI 3.1415926535897932384626
#define inf 1e18
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //Random Shuffler
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef map<int, int> mii;
typedef map<char, int> mci;
typedef map<string, int> msi;
int mpow(int base, int exp);
int lcm(int a, int b);
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
vi g[N];
// no of prime numbers in range : (70,19) , (1000,168) , (100000,1229) , (sqrt(10^9),3409)
//=======================
void sol()
{
int i, j, k, n, x, y, z, m, tc = 1;
string s;
// cin >> tc;
while (tc--)
{
cin >> n;
x = 1e9;
y = 1e6;
x *= y;
y = 1e3;
int ans = 0;
fo(i, 5)
{
z = n - x;
if (z >= 0)
{
int cnt = n - x + 1;
ans += (5ll - i) * cnt;
n -= cnt;
}
x /= y;
}
cout << ans << nn;
}
}
int32_t main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
sol();
return 0;
}
int mpow(int base, int exp) {
base %= mod;
int result = 1;
while (exp > 0) {
if (exp & 1) result = (result * base) % mod;
base = (base * base) % mod;
exp >>= 1;
}
return result;
}
int lcm(int a, int b)
{
int g = __gcd(a, b);
return a / g * b;
}
void ipgraph(int m) {
int i, u, v;
while (m--) {
cin >> u >> v;
g[u - 1].pb(v - 1);
g[v - 1].pb(u - 1);
}
}
void dfs(int u, int par) {
for (int v : g[u]) {
if (v == par) continue;
dfs(v, u);
}
}
|
#include<bits/stdc++.h>
using namespace std;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(),a.end()
#define SET(a,b) memset(a,b,sizeof(a))
#define off ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
typedef pair<int,int> II;
typedef vector< II > VII;
typedef vector<int> VI;
typedef vector< VI > VVI;
typedef long long int LL;
typedef vector<LL> VL;
#define si(n) cin>>n
#define dout(n) cout<<n<<"\n"
#define DRT() int t; si(t); while(t--)
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
//# define M_PI 3.14159265358979323846264338327950288
// DSU
void IO(){
#ifndef ONLINE_JUDGE
freopen("../input.txt", "r", stdin);
freopen("../output.txt", "w", stdout);
#endif
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
off;
}
LL n,m,q;
vector<pair<LL,LL>> arr;
int main(){
IO();
cin>>n>>m>>q;
arr.resize(n);
LL w,v;
rep(i,0,n){
cin>>w>>v;
arr[i].F = v;
arr[i].S = w;
}
VL brr(m);
rep(i,0,m){
cin>>brr[i];
}
sort(ALL(arr), greater<pair<LL, LL>>());
LL l, r;
rep(i,0,q){
cin>>l>>r;
l--;r--;
VL temp;
for(LL j=0;j<l;j++){
temp.PB(brr[j]);
}
for(LL j=r+1;j<m;j++){
temp.PB(brr[j]);
}
if(SZ(temp) == 0){
dout(0);
}
else{
LL ans = 0;
LL ss = SZ(temp);
sort(ALL(temp));
VL visited(ss, 0);
rep(j,0,n){
rep(k,0,ss){
if(!visited[k]){
if(temp[k] >= arr[j].S){
visited[k] = 1;
ans += arr[j].F;
break;
}
}
}
}
dout(ans);
}
}
return 0;
} | #include<bits/stdc++.h>
#define M 1005
typedef long long ll;
using namespace std;
int stp[M][M][27];
int n,m;
int to[2*M],nxt[2*M],hd[M][26],cnte;
void adde(int u,int v,int c){
to[++cnte]=v;
nxt[cnte]=hd[u][c];
hd[u][c]=cnte;
}
struct node{int x,y,c;};
queue<node> Q;
int BFS(){
int x,y,c;
while(!Q.empty()){
x=Q.front().x;
y=Q.front().y;
c=Q.front().c;
if((c==26)&&((x==1&&y==n)||(x==n&&y==1)))return stp[x][y][26];
Q.pop();
if(c==26){
for(int i=0;i<26;++i)
for(int j=hd[x][i],z;j;j=nxt[j]){
if(~stp[z=to[j]][y][i])continue;
stp[z][y][i]=stp[x][y][c]+1;
Q.push((node){z,y,i});
}
}else{
for(int j=hd[y][c],z;j;j=nxt[j]){
if(~stp[x][z=to[j]][26])continue;
stp[x][z][26]=stp[x][y][c]+1;
Q.push((node){x,z,26});
}
}
}
return -1;
}
int main(){
cin>>n>>m;
memset(stp,-1,sizeof(stp));
for(int i=1;i<=n;++i){
stp[i][i][26]=0;
Q.push((node){i,i,26});
}
int u,v;char c[5];
for(int i=1;i<=m;++i){
scanf("%d%d%s",&u,&v,c);
if(u>v)swap(u,v);
adde(u,v,c[0]-'a');
adde(v,u,c[0]-'a');
if(u==v)continue;
stp[u][v][26]=1;
stp[v][u][26]=1;
Q.push((node){u,v,26});
Q.push((node){v,u,26});
}
cout<<BFS();
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
// clang-format off
using ll = int64_t;
template <class T>
istream& operator>>(istream& is, vector<T>& v) {
for (auto& a : v) cin >> a;
return is;
}
template <class T>
istream& operator>>(istream& is, vector<pair<T, T>>& v) {
for (auto& a : v) cin >> a.first >> a.second;
return is;
}
template <class T>
istream& operator>>(istream& is, vector<tuple<T, T, T>>& v) {
for (auto& a : v) {
T a1, a2, a3;
cin >> a1 >> a2 >> a3;
a = {a1, a2, a3};
}
return is;
}
template <class T>
ostream& operator<<(ostream& os, vector<T>& v) {
for (auto& a : v) os << a << " ";
os << endl;
return os;
}
#define all(v) begin(v), end(v)
#define TRC1(a) cout << #a ":" << a
#define TRC2(a, b) TRC1(a); cout << " "; TRC1(b)
#define TRC3(a, b, c) TRC2(a, b); cout << " "; TRC1(c)
#define TRC4(a, b, c, d) TRC3(a, b, c); cout << " "; TRC1(d)
using veci = vector<int>;
using vecll = vector<ll>;
using Pi = pair<int, int>;
using Ti = tuple<int, int, int>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define fore(x, v) for (auto x : v)
const int IINF = INT32_MAX;
const ll LINF = INT64_MAX;
// cout << fixed << setprecision(15);
void solve();
int main() { cout << fixed << setprecision(15); solve(); return 0; }
// clang-format on
double dp[100][100][100];
double f(int x, int y, int z) {
if (x == 100 || y == 100 || z == 100) return 0;
if (dp[x][y][z] != 0) return dp[x][y][z];
int sum = x + y + z;
double res = (double)x / sum * (f(x + 1, y, z) + 1) +
(double)y / sum * (f(x, y + 1, z) + 1) +
(double)z / sum * (f(x, y, z + 1) + 1);
dp[x][y][z] = res;
return res;
}
void solve() {
double A, B, C;
cin >> A >> B >> C;
double ans = f(A, B, C);
cout << ans << endl;
}
| #include<iostream>
#include<iomanip>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
int A,B,C;
double f[105][105][105];
int main()
{
scanf("%d%d%d",&A,&B,&C);
f[A][B][C]=1;
for(int len=A+B+C;len<=300;len++)
{
for(int i=A;i<=99;i++)
for(int j=B;j<=99;j++)
{
int k=len-A-B;
if(k>=C&&k<=99)
{
if(i) f[i+1][j][k]+=f[i][j][k]*((double)i/(i+j+k));
if(j) f[i][j+1][k]+=f[i][j][k]*((double)j/(i+j+k));
if(k) f[i][j][k+1]+=f[i][j][k]*((double)k/(i+j+k));
}
}
}
double ans=0;
for(int i=0;i<=100;i++)
for(int j=0;j<=100;j++)
{
ans+=(100+i+j-A-B-C)*f[100][i][j];
ans+=(100+i+j-A-B-C)*f[i][100][j];
ans+=(100+i+j-A-B-C)*f[i][j][100];
}
printf("%0.8lf",ans);
} |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
using ll = long long;
const ll INF = 1e17;
int main(){
int n, m;
cin >> n >> m;
ll w[n], l[m], v[m], a[n];
rep(i,n) a[i] = i;
rep(i,n) cin >> w[i];
rep(i,m) cin >> l[i] >> v[i];
rep(i,n) {
rep(j,m) {
if(w[i] > v[j]) {
cout << -1 << endl;
return 0;
}
}
}
vector<ll> d(1<<n);
rep(i,1<<n) {
ll weight = 0, dist = 0;
rep(j,n) if(i & (1<<j)) weight += w[j];
rep(j,m) if(weight > v[j]) dist = max(dist,l[j]);
d[i] = dist;
}
ll ans = INF;
do {
vector<ll> dp(n);
for(int i = 1; i < n; i++) {
rep(j,i) {
int id = 0;
for(int k = j; k <= i; k++) id |= (1<<a[k]);
dp[i] = max(dp[i],dp[j]+d[id]);
}
}
ans = min(ans,dp[n-1]);
} while(next_permutation(a,a+n));
cout << ans << endl;
return 0;
}
| /**
* @FileName c.cpp
* @Author kanpurin
* @Created 2020.10.11 23:04:57
**/
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
template<typename T>
struct Bellman_Ford {
private:
struct edge { int to; T cost; };
int V;
vector<vector<edge>> G;
vector<T> d;
public:
const T inf = numeric_limits<T>::max();
Bellman_Ford(int V) : V(V){
G.resize(V);
d.resize(V);
}
void add_edge(int from, int to, T cost) {
G[from].push_back({to,cost});
}
bool build(int s) {
d.assign(V,inf);
d[s] = 0;
for (int i = 0; i < V; i++) {
for (int j = 0; j < V; j++) {
for (edge &e : G[j]) {
if (d[j] != inf && d[j] + e.cost < d[e.to]) {
d[e.to] = d[j] + e.cost;
if (i == V - 1) {
return false;
}
}
}
}
}
/*
REP(i, V) {
cout << s << " -> " << i << " = " << d[i] << endl;
}
*/
return true;
}
T dist(int v) {
return d[v];
}
};
int main() {
int n,m;cin >> n >> m;
vector<int> w(n);
int max_w = 0;
for (int i = 0; i < n; i++) {
cin >> w[i];
max_w = max(max_w,w[i]);
}
sort(w.begin(), w.end());
vector<pair<int,int>> p(m);
for (int i = 0; i < m; i++) {
cin >> p[i].second >> p[i].first;
if (p[i].first < max_w) {
cout << -1 << endl;
return 0;
}
}
sort(p.begin(), p.end());
for (int i = 1; i < m; i++) {
p[i].second = max(p[i].second,p[i-1].second);
}
constexpr long long LLINF = 1e18 + 1;
ll ans = LLINF;
do {
Bellman_Ford<ll> g(n);
for (int i = 0; i < n-1; i++) {
int sum = w[i];
for (int j = i+1; j < n; j++) {
sum += w[j];
auto t = lower_bound(p.begin(), p.end(), make_pair(sum,-1));
if (t == p.begin()) {
g.add_edge(i,j,0);
}
else {
t--;
g.add_edge(i,j,-(*t).second);
}
}
}
g.build(0);
ans = min(ans,-g.dist(n-1));
} while(next_permutation(w.begin(), w.end()));
cout << ans << endl;
return 0;
} |
#include <iostream>
int getNum(int x) {
return 7 - x;
}
int main() {
int a, b, c;
std::cin >> a >> b >> c;
int result = getNum(a) + getNum(b) + getNum(c);
std::cout << result << std::endl;
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,j,n) for(int i=j;i<n;i++)
#define readvec(v,n) for(int i=0;i<n;i++){cin>>v[i];}
#define MOD 1000000007
int main()
{
int a,b,c;
cin>>a>>b>>c;
cout<<21-(a+b+c)<<"\n";
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define fastIO std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0)
#define Local
#ifdef Local
#define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
void err() { std::cout << std::endl; }
template<typename T, typename...Args>
void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
template <template<typename...> class T, typename t, typename... A>
void err(const T <t> &arg, const A&... args) {
for (auto &v : arg) std::cout << v << ' '; err(args...); }
#else
#define dbg(...)
#endif
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
const ll mod = 1000000007;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
const int N = 2e5 + 10;
int n, a[N];
ll s[N], ss[N], ms[N];
// a1 a1 + a2 a1 + a2 + a3
// a1 2*a1 + a2 3*a1 + 2*a2 + a3
// 2 3 2
// -2 -3 -1 0 0
int main()
{
fastIO;
cin >> n;
rep (i,1,n + 1) {
cin >> a[i];
s[i] = s[i - 1] + a[i];
ss[i] = ss[i - 1] + s[i];
ms[i] = max(ms[i - 1], s[i]);
}
ll ans = 0;
rep (i,0,n) {
ans = max(ans, ss[i] + ms[i + 1]);
}
cout << ans << endl;
return 0;
} | #include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <climits>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
ull gcd (ull a, ull b) {
if(b == 0) return a;
return gcd(b, a % b);
}
ull lcm (ull a, ull b){
// バッファ溢れを抑えるために順番大事!!!
return a / gcd(a, b) * b;
}
ull calcDigitLength(ull n, int count) {
if(n < 10) return count + 1;
return calcDigitLength(n/10, count+1);
}
bool isPrime (ull a) {
if(a == 0 || a == 1) return false;
if(a == 2) return true;
if(a == 3) return true;
for(int i = 2; i * i <= a; i++) {
if(a % i == 0) {
return false;
}
}
return true;
}
int main () {
ll n;
cin >> n;
ll a;
// 距離
vector<ll> vec;
// 前回進んだ距離
vector<ll> susuda;
ll sum = 0;
ll currentMax = 0;
ll currentPoint = 0;
ll currentSumMax = 0;
for(ll i = 0; i < n; i++) {
cin >> a;
sum += a;
vec.push_back(a);
susuda.push_back(sum);
currentSumMax = max(sum, currentSumMax);
currentMax = max(max(currentMax, currentPoint + sum), currentPoint +currentSumMax);
currentPoint += sum;
}
cout << currentMax << endl;
}
|
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ub upper_bound
#define lb lower_bound
const int M=1e9L+7;
const ll k=1e12L+7;
const ll MM=1e18L;
unordered_set<ll>s;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll n;
cin>>n;
ll ans=0,a=0;
for(ll i=0;i<n;++i){
ll k;
cin>>k;
ans+=k*k;
a+=k;
}
cout<<n*ans-a*a<<"\n";
return 0;
} | #pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <complex>
#define ll long long
#define inf 1e9 + 8
#define sinf 1e17 + 500
#define ld long double
#define ull unsigned long long
#define poll complex<double>
#define line pair<poll, poll>
#define pi acos(-1)
#define lp(a, b, c, d) for (ll a = b; a < c; a += d)
#define endl '\n'
//#define EPS 1e-12
#define IO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL); \
// freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define mod 1000000007
using namespace std;
const ll N = 1e4 +6, SEG = (1 << 14);
ll gcd(ll a, ll b)
{
if(b==0)return a;
return gcd(b,a%b);
}
int main()
{
IO
ll n;
cin>>n;
ll arr[n];
map<ll,ll>cnt;
set<ll>st;
for(ll i=0;i<n;i++)
{
cin>>arr[i];
cnt[arr[i]]++;
st.insert(arr[i]);
}
vector<ll>v;
for(auto d:st)
{
v.push_back(d);
// cout<<d<<endl;
}
ll res=0;
for(ll i=0;i<v.size();i++)
{
ll tmp=0;
for(ll j=i+1;j<v.size();j++)
{
tmp+=(v[j]-v[i])*(v[j]-v[i])*cnt[v[j]];
}
res+=tmp*cnt[v[i]];
}
cout<<res<<endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define inf (int)1e18+7
signed main() {
ios_base :: sync_with_stdio(false);
cin.tie(0);
int a[3];
for (int i = 0; i < 3; i ++) {
cin >> a[i];
}
sort(a, a + 3);
if (a[0] == a[1]) cout << a[2] << endl;
else if (a[1] == a[2]) cout << a[0] << endl;
else cout << 0 << endl;
return 0;
} | #include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
void solve() {
int a, b, c;
cin >> a >> b >> c;
if (c & 1) {
if (a < 0 && b < 0) {
if (a < b) {
cout << ">\n";
} else if (a > b) {
cout << "<\n";
} else {
cout << "=\n";
}
}
else if (a < b) {
cout << "<\n";
} else if (a > b) {
cout << ">\n";
} else {
cout << "=\n";
}
} else {
a = abs(a);
b = abs(b);
if (a < b) {
cout << "<\n";
} else if (a > b) {
cout << ">\n";
} else {
cout << "=\n";
}
}
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
int _ = 1;
//cin >> _;
while (_--) {
solve();
}
}
|
#define IOS ios::sync_with_stdio(false);
#define rep(i, a, n) for(ll i=a;i<=n;i++)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl "\n"
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int N = 1e6 + 10;
ll n, m, t, k, ans, cnt, sum, flag;
ll arr[N], vis[N];
char s[N], c;
int main() {
IOS;
cin >> n >> m;
rep(i, 1, n) cin >> arr[i];
rep(i, 1, n) if (arr[i] != m) cout << arr[i] << " ";
cout<<endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
signed main(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int n;
cin >> n;
//string s[n];
set <string> s;
map <string,bool> m1,m2;
string ans = "satisfiable";
string a;
for(int i=0; i<n; i++){
cin >> a;
if(a[0]=='!'){
a = a.substr(1);
m2[a]=1;
}
else{
m1[a]=1;
}
s.insert(a);
}
auto it = s.begin();
while(it!=s.end()){
if(m1[*it] && m2[*it]){
ans = *it;
break;
}
it++;
}
cout << ans;
return 0;
} |
#pragma GCC target ("avx2")
//#pragma GCC optimize "trapv"
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define input(a,n) for(ll i1=0;i1<n;i1++)cin>>a[i1]
#define ll long long
#define pi 2 * acos(0.0)
#define usll uset<ll>
#define sll set<ll>
#define mll map<ll,ll>
#define pll pair<ll,ll>
#define vll vector<ll>
#define vpll vector<pll>
#define umll umap<ll,ll>
#define S second
#define sz size()
#define all(v) v.begin(),v.end()
#define Y cout<< "YES"<< "\n"
#define N cout<< "NO"<< "\n"
#define F first
#define pb push_back
#define pf push_front
#define ld long double
#define random(l,r,T) uniform_int_distribution<T>(l,r)(rng)
using namespace __gnu_pbds;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
// http://xorshift.di.unimi.it/splitmix64.c
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
template<class T, class H>using umap=unordered_map<T,H,custom_hash>;
template<class T>using uset=unordered_set<T,custom_hash>;
const ll mod = 1000000007;
ll ans=0;
void dfs(vll adj[],ll vis[],ll v){
vis[v]=1;
for(auto i:adj[v]){
if(vis[i])
continue;
ans++;
dfs(adj,vis,i);
}
}
int main()
{
clock_t clk = clock();
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
ll test=1;
//cin>>test;
for(ll tc=1;tc<=test;tc++)
{
ll n,m;
cin>>n>>m;
vll adj[n+1];
for(ll i=1;i<=m;i++){
ll x,y;
cin>>x>>y;
adj[x].pb(y);
}
ans+=n;
for(ll i=1;i<=n;i++){
ll vis[n+1]={0};
dfs(adj,vis,i);
}
cout<<ans;
//cout<< "Case #"<<tc<< ": "<<ans<< "\n";
}
// cerr << '\n'<<"Time (in s): " << double(clock() - clk) * 1.0 / CLOCKS_PER_SEC << '\n';
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define reps(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define all(a) (a).begin(), (a).end()
#define uniq(a) (a).erase(unique(all(a)), (a).end())
#define bit(n) (1LL << (n))
#define dump(a) cerr << #a " = " << (a) << endl
using vll = vector<ll>;
using pll = pair<ll, ll>;
template <typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double PI = 3.1415926535897932384626433832795028;
constexpr ll DY[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
constexpr ll DX[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
ll sign(ll a) { return (a > 0) - (a < 0); }
ll cdiv(ll a, ll b) { return (a - 1 + b) / b; }
template <typename T> T sq(T a) { return a * a; }
template <typename T, typename U> bool chmax(T &a, const U &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T, typename U> bool chmin(T &a, const U &b) {
if (b < a) {
a = b;
return true;
}
return false;
}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &a) {
os << "(" << a.first << ", " << a.second << ")";
return os;
}
template <typename T, typename U, typename V> ostream &operator<<(ostream &os, const tuple<T, U, V> &a) {
auto [t, u, v] = a;
os << "(" << t << ", " << u << ", " << v << ")";
return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &a) {
os << "(";
for (auto itr = a.begin(); itr != a.end(); itr++) { os << *itr << (next(itr) != a.end() ? ", " : ""); }
os << ")";
return os;
}
template <typename T> ostream &operator<<(ostream &os, const deque<T> &a) {
os << "(";
for (auto itr = a.begin(); itr != a.end(); itr++) { os << *itr << (next(itr) != a.end() ? ", " : ""); }
os << ")";
return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &a) {
os << "{";
for (auto itr = a.begin(); itr != a.end(); itr++) { os << *itr << (next(itr) != a.end() ? ", " : ""); }
os << "}";
return os;
}
template <typename T> ostream &operator<<(ostream &os, const multiset<T> &a) {
os << "{";
for (auto itr = a.begin(); itr != a.end(); itr++) { os << *itr << (next(itr) != a.end() ? ", " : ""); }
os << "}";
return os;
}
template <typename T, typename U> ostream &operator<<(ostream &os, const map<T, U> &a) {
os << "{";
for (auto itr = a.begin(); itr != a.end(); itr++) { os << *itr << (next(itr) != a.end() ? ", " : ""); }
os << "}";
return os;
}
struct setup {
static constexpr ll PREC = 20;
setup() {
cout << fixed << setprecision(PREC);
cerr << fixed << setprecision(PREC);
};
} setup;
int main() {
ll n;
cin >> n;
vll a(n);
rep(i, n) { cin >> a[i]; }
map<ll, ll> mp;
rep(i, n) mp[a[i]]++;
ll ans = n * (n - 1) / 2;
for (auto [_, k] : mp) { ans -= k * (k - 1) / 2; }
cout << ans << endl;
} |
#include <bits/stdc++.h>
#define rei register int
#define int long long
using namespace std;
const int N=2e3+100,mod=1e9+7;
int n,m,a[N];
inline int read(){
int sum=0,sign=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-') sign=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9'){
sum=(sum<<1)+(sum<<3)+(ch^48);
ch=getchar();
}
return sum*sign;
}
inline int Qpower(long long base, long long power) {
int result = 1;
base%=mod;
while (power > 0) {
if (power & 1) {
result = result * base%mod;
}
power >>= 1;
base = (base * base)%mod;
}
return result;
}
signed main(){
scanf("%lld%lld",&n,&m);
int sum=0;
for(rei i=1;i<=n;++i) sum+=read();
if(m<sum){
printf("0\n");
return 0;
}
//ans=(∑Ai+N)
// (M+N )
m+=n,sum+=n;
int ans=1;
for(rei i=1;i<=sum;++i){
ans=ans*Qpower(i,mod-2)%mod *(m-i+1) %mod;
}
printf("%lld\n",ans);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
long long pow_log(long long x,int y)
{
if (!y)
return 1;
long long ret=pow_log(x,y/2);
ret=(ret*ret)%mod;
if (y%2)
ret=(ret*x)%mod;
return ret;
}
int main()
{
int n,m;
scanf("%d%d",&n,&m);
m+=n;
int sum=n;
for (int i=0;i<n;i++)
{
int a;
scanf("%d",&a);
sum+=a;
}
long long ans=1;
for (int i=m-sum+1;i<=m;i++)
ans=(ans*i)%mod;
for (int i=1;i<=sum;i++)
ans=(ans*pow_log(i,mod-2))%mod;
printf("%lld",ans);
} |
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
ll fact[200005];
ll mod_pow(ll x,ll n){
ll res=1;
while(n>0LL){
if(n&1LL){
res=res*x%MOD;
}
x=x*x%MOD;
n>>=1LL;
}
return res;
}
ll extgcd(ll a,ll b,ll& x,ll& y){
ll d=a;
if(b!=0LL){
d=extgcd(b,a%b,y,x);
y-=(a/b)*x;
}else{
x=1;
y=0;
}
return d;
}
ll mod_inverse(ll a,ll m){
ll x,y;
extgcd(a,m,x,y);
return (m+x%m)%m;
}
ll mod_fact(ll n,ll p,ll& e){
e=0;
if(n==0)return 1;
ll res=mod_fact(n/p,p,e);
e+=n/p;
if(n/p%2!=0){
return res*(p-fact[n%p])%p;
}
return res*fact[n%p]%p;
}
ll mod_comb(ll n,ll k,ll p=MOD){
if(n<0 || k<0 || n<k)return 0;
ll e1,e2,e3;
ll a1=mod_fact(n,p,e1),a2=mod_fact(k,p,e2),a3=mod_fact(n-k,p,e3);
if(e1>e2+e3)return 0;
return a1*mod_inverse(a2*a3%p,p)%p;
}
int n;
string s;
int K;
int val[200005];
ll dp[200005][20];
int cnt[17];
ll ans;
int main(void){
fact[0]=1;
for(ll i=1;i<=200000;i++){
fact[i]=fact[i-1]*i%MOD;
}
cin >> s >> K;
n=s.size();
for(int i=0;i<n;i++){
if(s[i]>='0' && s[i]<='9'){
val[i]=(s[i]-'0');
}else{
val[i]=(s[i]-'A')+10;
}
}
int ct=0;
for(int i=0;i<n;i++){
for(int j=0;j<=15;j++){
if(i==0 && j==0)continue;
if(j<val[i]){
if(cnt[j]!=0)dp[i+1][ct]++;
else{
dp[i+1][ct+1]++;
}
}
}
cnt[val[i]]++;
if(cnt[val[i]]==1){
ct++;
}
}
if(ct==K){
ans++;
}
for(int i=1;i<n;i++){
dp[i][0]++;
for(int j=0;j<=K;j++){
if(dp[i][j]==0)continue;
if(j==0){
dp[i+1][1]+=dp[i][j]*15%MOD;
dp[i+1][1]%=MOD;
}else{
dp[i+1][j]+=dp[i][j]*j%MOD;
dp[i+1][j]%=MOD;
dp[i+1][j+1]+=dp[i][j]*(16-j)%MOD;
dp[i+1][j+1]%=MOD;
}
}
}
ans+=dp[n][K];
ans%=MOD;
printf("%lld\n",ans);
return 0;
}
| #include<bits/stdc++.h>
#define For(i,a,b) for(register int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(register int i=(a);i>=(b);--i)
//#define int long long
using namespace std;
inline int read()
{
char c=getchar();int x=0;bool f=0;
for(;!isdigit(c);c=getchar())f^=!(c^45);
for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
if(f)x=-x;return x;
}
#define mod 1000000007
struct modint{
int x;
modint(int o=0){x=o;}
modint &operator = (int o){return x=o,*this;}
modint &operator +=(modint o){return x=x+o.x>=mod?x+o.x-mod:x+o.x,*this;}
modint &operator -=(modint o){return x=x-o.x<0?x-o.x+mod:x-o.x,*this;}
modint &operator *=(modint o){return x=1ll*x*o.x%mod,*this;}
modint &operator ^=(int b){
modint a=*this,c=1;
for(;b;b>>=1,a*=a)if(b&1)c*=a;
return x=c.x,*this;
}
modint &operator /=(modint o){return *this *=o^=mod-2;}
modint &operator +=(int o){return x=x+o>=mod?x+o-mod:x+o,*this;}
modint &operator -=(int o){return x=x-o<0?x-o+mod:x-o,*this;}
modint &operator *=(int o){return x=1ll*x*o%mod,*this;}
modint &operator /=(int o){return *this *= ((modint(o))^=mod-2);}
template<class I>friend modint operator +(modint a,I b){return a+=b;}
template<class I>friend modint operator -(modint a,I b){return a-=b;}
template<class I>friend modint operator *(modint a,I b){return a*=b;}
template<class I>friend modint operator /(modint a,I b){return a/=b;}
friend modint operator ^(modint a,int b){return a^=b;}
friend bool operator ==(modint a,int b){return a.x==b;}
friend bool operator !=(modint a,int b){return a.x!=b;}
bool operator ! () {return !x;}
modint operator - () {return x?mod-x:0;}
};
inline modint qpow(modint a,int b){
return a^b;
}
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;
#define maxn 200005
#define inf 0x3f3f3f3f
char str[maxn];
int n,d[maxn],k;
modint cnt[maxn][23];
modint fac[44],ifac[44];
inline void prework(int n){
fac[0]=ifac[0]=1;
For(i,1,n)fac[i]=fac[i-1]*i,ifac[i]=ifac[i-1]/i;
}
inline modint C(int n,int m){
if(n<m||n<0||m<0)return 0;
return fac[n]*ifac[m]*ifac[n-m];
}
int c[1<<17];
modint dfs(int now,int st,bool lim,bool zero){
if(now==n+1) return
//cout<<"val "<<(c[st]==k)<<endl,
c[st]==k;
if(!lim && !zero) return
//cout<<n-now+1<<" "<<c[st]<<endl,
cnt[n-now+1][c[st]];
int r=lim?d[now]:15;
modint res=0;
For(i,0,r){
if(i||!zero)res+=dfs(now+1,st|(1<<i),lim&&(i==r),0);
else res+=dfs(now+1,st,lim&&(i==r),1);
}
return res;
}
modint pw[23][maxn];
signed main()
{
scanf("%s",str+1);
n=strlen(str+1);
prework(30);
For(i,1,n){
if(isdigit(str[i]))d[i]=str[i]-'0';
else d[i]=str[i]-'A'+10;
}
For(i,1,((1<<16)-1))
c[i]=c[i>>1]+(i&1);
// pw[i][j] = (i^j);
For(i,1,16){
pw[i][0]=1;
For(j,1,n)pw[i][j]=pw[i][j-1]*i;
}
k=read();
For(i,0,n)For(j,0,k) {
// 已有j个不同数,还要填i个
if(i<k-j)continue;
Rep(x,k-j,0){
if((x-(k-j))%2) cnt[i][j]-=C(k-j,x)*pw[x+j][i];
else cnt[i][j]+=C(k-j,x)*pw[x+j][i];
}
cnt[i][j]*=C(16-j,k-j);
}
//cout<<cnt[2][0].x<<endl;
//cnt[1][1]=15;
modint res=dfs(1,0,1,1);
cout<<res.x;
return 0;
} |
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <functional>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <unordered_map>
#include <cstdio>
#include <climits>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
ll gcd(ll x, ll y) {
if (y == 0)return x;
return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
return x / gcd(x, y)*y;
}
ll kai(ll x, ll y, ll m) {
ll res = 1;
for (ll i = x - y + 1; i <= x; i++) {
res *= i; res %= m;
}
return res;
}
ll mod_pow(ll x, ll y, ll m) {
ll res = 1;
while (y > 0) {
if (y & 1) {
res = res * x % m;
}
x = x * x % m;
y >>= 1;
}
return res;
}
ll comb(ll x, ll y, ll m) {
if (y > x)return 0;
return kai(x, y, m) * mod_pow(kai(y, y, m), m - 2, m) % m;
}
int n;
string s, t;
queue<int> que;
ll ans;
signed main() {
std::random_device rnd;
std::mt19937_64 mt(rnd());
cin >> n >> s >> t;
for (int i = 0; i < n; i++)if (s[i] == '1')que.push(i);
for (int i = 0; i < n; i++) {
if (!que.empty() && que.front() == i)que.pop();
if (s[i] == t[i])continue;
if (que.empty()) {
cout << -1 << endl;
return 0;
}
int p = que.front();
ans += p - i;
que.pop();
if (s[i] == '0')s[i] = '1', s[i + 1] = '0', s[p] = '0';
else s[i] = '0', s[i + 1] = '0', s[p] = '0';
}
cout << ans << endl;
} | #include<bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()
using ll=long long;
using ld=long double;
using pii=pair<int, int>;
using vi=vector<int>;
using vii=vector<vector<int>>;
const ll LINF=1LL<<60;
const int INF=1<<29;
const ll MOD=1e9+7;
template<typename T> bool chmax(T &a,const T b){if(a < b){a=b; return true;} return false;}
template<typename T> bool chmin(T &a,const T b){if(a > b){a=b; return true;} return false;}
int N;
ll ans=0;
string S, T;
vi cnt1(2, 0);
int solve(){
queue<int> que1, que2;
for(int i=0; i<N; i++){
if(S[i] == '1') que1.push(i);
if(T[i] == '1') que2.push(i);
}
while(!que1.empty() || !que2.empty()){
if(que1.empty()) return 0;
int a=que1.front(); que1.pop();
if(!que2.empty()){
int b=que2.front();
if(a >= b){
ans=ans+a-b;
que2.pop();
}
else{
if(que1.empty()) return 0;
int c=que1.front(); que1.pop();
ans=ans+c-a;
}
}
else{
if(que1.empty()) return 0;
int c=que1.front(); que1.pop();
ans=ans+c-a;
}
}
return 1;
}
int main(){
cin >> N;
cin >> S >> T;
if(solve()){
cout << ans << endl;
}
else cout << "-1" << endl;
return 0;
} |
#include <stdint.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <math.h>
using namespace std;
int main()
{
string s;
cin >> s;
for(auto i = 0; i < s.size() && s[i] != '.'; ++i) {
cout << s[i];
}
cout << endl;
return 0;
}
| // Jai Shree Ram
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define ll long long
#define int long long
#define pb push_back
#define all(v) v.begin(),v.end()
#define endl "\n"
#define x first
#define y second
#define gcd(a,b) __gcd(a,b)
#define mem1(a) memset(a,-1,sizeof(a))
#define mem0(a) memset(a,0,sizeof(a))
#define sz(a) (int)a.size()
#define pii pair<int,int>
#define hell 1000000007
#define elasped_time 1.0 * clock() / CLOCKS_PER_SEC
template<typename T1,typename T2>istream& operator>>(istream& in,pair<T1,T2> &a){in>>a.x>>a.y;return in;}
template<typename T1,typename T2>ostream& operator<<(ostream& out,pair<T1,T2> a){out<<a.x<<" "<<a.y;return out;}
template<typename T,typename T1>T maxs(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T mins(T &a,T1 b){if(b<a)a=b;return a;}
int solve(){
string s;cin>>s;
string t;
for(auto i:s){
if(i=='.')break;
t.push_back(i);
}
if(t.empty())t="0";
cout<<t<<endl;
return 0;
}
signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
#ifdef SIEVE
sieve();
#endif
#ifdef NCR
init();
#endif
int t=1;//cin>>t;
while(t--){
solve();
}
return 0;
}
|
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main () {
std::ios::sync_with_stdio(false); std::cin.tie(0);
int n;
cin >> n;
string s;
cin >> s;
string t;
cin >> t;
reverse(s.begin(), s.end());
reverse(t.begin(), t.end());
set<int> pre, cur;
cur.emplace(0);
int p = 1;
for (int i = 0; i < n; i++) {
pre = cur;
cur.clear();
if (t[i] == 'T') {
for (int x = 0; x < 7; x++) {
int v1 = x;
int v2 = x + (s[i] - '0') * p;
v2 %= 7;
if (pre.count(v1) || pre.count(v2)) cur.emplace(x);
}
} else {
for (int x = 0; x < 7; x++) {
int v1 = x;
int v2 = x + (s[i] - '0') * p;
v2 %= 7;
if (pre.count(v1) && pre.count(v2)) cur.emplace(x);
}
}
p *= 10;
p %= 7;
}
cout << (cur.count(0) ? "Takahashi" : "Aoki") << endl;
}
| #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
//#define int long long
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define s second
#define f first
typedef pair < long long, long long > pll;
typedef pair < int, int > pii;
typedef unsigned long long ull;
typedef vector < pii > vpii;
typedef vector < int > vi;
typedef long double ldb;
typedef long long ll;
typedef double db;
typedef tree < int, null_type, less < int >, rb_tree_tag, tree_order_statistics_node_update > ordered_set;
const int inf = 1e9, maxn = 2e5 + 48, mod = 1e9 + 7, N = 2e5 + 12;
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 300;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const db eps = 1e-12, pi = acos(-1);
const ll INF = 1e18;
int n, pw[N], dp[N][7];
string s, t;
int rec (int i, int j) {
int &res = dp[i][j];
if (res != -1)
return res;
if (i == n) {
if (!j)
return res = 1;
return res = 0;
}
int g1 = rec(i + 1, (j + pw[n - 1 - i] * (s[i] - '0')) % 7);
int g2 = rec(i + 1, j);
// cerr << i << ' ' << j << ' ' << pw[n - 1 - i] << ' ' << (s[i] - '0') << ' ' << g1 << ' ' << g2 << endl;
if ((t[i] == 'T' && (g1 || g2)) || (t[i] == 'A' && g1 && g2))
return res = 1;
return res = 0;
}
main () {
pw[0] = 1;
for (int i = 1; i < N; ++i)
pw[i] = pw[i - 1] * 10 % 7;
memset(dp, -1, sizeof(dp));
fastio
cin >> n >> s >> t;
puts(rec(0, 0) ? "Takahashi" : "Aoki");
} |
#include <iostream>
using namespace std;
int main()
{
int n;
double x;
cin >> n >> x;
x *= 100;
for (int i = 0; i < n; i++)
{
int v, p;
cin >> v >> p;
x -= v * p;
if (x < 0)
{
cout << i+1; return 0;
}
else {if (i == n-1)
{
cout << -1; return 0;
}}
}
}
| #include <cstdio>
#include <vector>
using namespace std;
int main(int argc, char** argv)
{
char c, s[200005];
int len = 0;
while((c = getchar()) != '\n');
while((c = getchar()) != '\n')
{
s[len++] = c;
if(len >= 3 && s[len - 3] == 'f'
&& s[len - 2] == 'o'
&& s[len - 1] == 'x')
len -= 3;
}
printf("%d\n", len);
return 0;
} |
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_set>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _rep(i, n) _rep2(i, 0, n)
#define _rep2(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(...) GET_MACRO(__VA_ARGS__, _rep2, _rep)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using i64 = long long;
template<class T, class U>
bool chmin(T& a, const U& b) { return (b < a) ? (a = b, true) : false; }
template<class T, class U>
bool chmax(T& a, const U& b) { return (b > a) ? (a = b, true) : false; }
template<typename T>istream& operator>>(istream&i,vector<T>&v){rep(j,v.size())i>>v[j];return i;}
template<typename T>string join(vector<T>&v){stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,vector<T>&v){if(v.size())o<<join(v);return o;}
template<typename T>string join(vector<vector<T>>&vv){string s="\n";rep(i,vv.size())s+=join(vv[i])+"\n";return s;}
template<typename T>ostream& operator<<(ostream&o,vector<vector<T>>&vv){if(vv.size())o<<join(vv);return o;}
int main(){
int n, q;
cin >> n >> q;
vector<i64> a(n);
cin >> a;
sort(all(a));
set<i64> s;
for (auto i: a) s.insert(i);
vector<i64> ans;
while (q--){
i64 k;
cin >> k;
i64 ok = 2e18, ng = 0;
while (ok - ng > 1){
i64 mid = (ok + ng) / 2;
auto x = upper_bound(all(a), mid) - a.begin();
if (mid - x >= k) ok = mid;
else ng = mid;
}
while (s.count(ok)) ok++;
ans.emplace_back(ok);
}
for (auto i: ans) cout << i << "\n";
} | #include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b;
cin>>a>>b;
int y=(a-b)/2;
cout<<b+y<<" "<<y;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using st = string;
using Pii = pair<int, int>;
#define rep2(i, m, n) for(int i = m; i < n; i++)
#define rep(i, n) rep2(i, 0, n)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define INF (ll)1e9
const int mod = 1e9 + 7;
const int di[4] = {0, 1, 0, -1};
const int dj[4] = {1, 0, -1, 0};
const int di2[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj2[8] = {1, 0, -1, 0, 1, -1, 1, -1};
bool get(int m, int h) {
if(h % m == 0) return true;
else return false;
}
int main() {
int m, h;
cin >> m >> h;
if(get(m, h)) cout << "Yes" << endl;
else cout << "No" << endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
int main()
{
int v,t,s,d,a,s1,flag=0;
cin>>v>>t>>s>>d;
a=v*t;
for(int i=t; i<=s; i++)
{
if((d>=(v*i)&&(d<=(v*s))))
{
flag=1;
break;
}
}
if(flag==1)
{
cout<<"No"<<endl;
}
else
{
cout<<"Yes"<<endl;
}
return 0;
}
|
#include<iostream>
using namespace std;
int main()
{
int a,b;
cin>>a>>b;
int x=(a+b)/2;
cout<<x<<" "<<a-x<<endl;
return 0;
} | #include <iostream>
using namespace std;
int main(void){
int a,b;
cin >> a >> b;
a = a / b;
cout << a << endl;
}
|
#include<bits/stdc++.h>
#define N 100005
#define ll long long
using namespace std;
template<class T>void read(T&x) {
T f=1;x=0;char c=getchar();
while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
while('0'<=c&&c<='9'){x=x*10+c-'0';c=getchar();}
x*=f;
}
template<class T>void print(T x,char c) {
if(x<0)putchar('-'),x=-x;int s[20],top=0;
while(s[++top]=x%10,x/=10);
while(top)putchar(s[top--]+'0');putchar(c);
}
int n;
int main() {
read(n);
for(int i=1; i<=n; ++i)if((i+1)*i/2 >= n)print(i,'\n'),exit(0);
} | #include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n ;
int sum = 0;
for(int i=0;;i++){
sum += i;
if(sum >= n){
cout << i << endl;
break;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
//vector <long long> v[1000001];
//stack <long long> s, s2;
//bbbbaaaa
//queue <long long> s, s2;
long long int z[1], x[1][3], y[1][2], m, szu, wy[100][100];
char s[10000000];
long long nwd(long long a, long long b)
{
while(a*b)
{
if(a>b)swap(a, b);
b%=a;
}
return(a+b);
}
int main()
{
long long int chu, d, e, f, i, j, q, t, k, a, n, b, c, w, p, aa, bb, cc, dd, nn, kk;
t=1;
//scanf("%lld", &t);
for(q=1; q<=t; q++)
{
scanf("%lld%lld", &n, &a);
for(i=1; i<n; i++)
{
scanf("%lld", &b);
a=nwd(a, b);
}
printf("%lld\n", a);
}
return(0);
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define F first
#define S second
#define PB push_back
#define MP make_pair
typedef vector<int> vi;
typedef pair<int,int> pi;
#define REP(i,a,b) for (int i = a; i <= b; i++)
void solve(){
int a,b,c;
cin>>a>>b;
if(a == b){cout<<a;return;}
if(a==0){
if(b == 1){
cout<<2;return;
}
cout<<1;return;
}
else if(a == 1){
if(b == 2){
cout<<0;return;
}
cout<<2;return;
}
else{
if(b == 1){
cout<<0;return;
}
cout<<1;return;
}
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n =1;
// cin>>n;
while(n--){
// cout<<n;
solve();
}
} |
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
constexpr int INF = 168430090;
int x[17], y[17], z[17], dist[17][17], dp[17][131072];
int main()
{
memset(dp, 10, sizeof(dp));
dp[0][1] = 0;
int N; scanf("%d", &N);
for(int i = 0; i < N; i++)scanf("%d%d%d", &x[i], &y[i], &z[i]);
int NUM = (1<<N);
for(int i = 0; i < N; i++) {
for(int j = 0; j < N; j++) {
dist[i][j] = abs(x[i] - x[j]) + abs(y[i] - y[j]) + max(0, z[j] - z[i]);
}
}
for(int bit = 1; bit < NUM; bit++) {
for(int i = 0; i < N; i++) {
if(!((1<<i) & bit) || dp[i][bit] == INF)continue;
for(int j = 0; j < N; j++) {
if((1<<j) & bit)continue;
dp[j][bit | (1<<j)] = min(dp[j][bit | (1<<j)], dp[i][bit] + dist[i][j]);
}
}
}
int ans = INF;
while(--N) {
ans = min(ans, dp[N][NUM - 1] + dist[N][0]);
}
printf("%d\n", ans);
} | #include<bits/stdc++.h>
using namespace std;
long int min=-1;
void find_min(long int m)
{
if(::min==-1)
{
::min=m;
return;
}
if(m<(::min))
::min=m;
}
int main()
{
long int n,**a,i;
cin>>n;
a=new long int*[n];
for(i=0;i<n;i++)
{
a[i]=new long int[3];
cin>>a[i][0]>>a[i][1]>>a[i][2];
if(a[i][2]-a[i][0]>0)
find_min(a[i][1]);
}
cout<<::min<<endl;
return 0;
} |
// #pragma GCC optimize("O3") // (code on steroids)
# include <bits/stdc++.h>
using namespace std;
typedef long long ll;
# define int ll
# define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
# define len(x) (ll((x).size()))
# define print(x) cout<<(x)<<"\n"
# define P0(x) cout<<(x)<<' '
# define P1(x) cout<<(x)<<"\n"
# define P2(x,y) cout<<(x)<<' '<<(y)<<"\n"
# define P3(x,y,z) cout<<(x)<<' '<<(y)<<' '<<(z)<<"\n"
# define P4(x,y,z,w) cout<<(x)<<' '<<(y)<<' '<<(z)<<' '<<(w)<<"\n"
// using auto in for
# define printv(v) {auto kjhg = v;for(auto idnphq : kjhg) cout<< idnphq << ' ';cout << "\n";}
# define printvv(v) {auto kjhg = v;for(auto idnphq : kjhg) {for(auto plinrw : idnphq) cout<< plinrw << ' ';cout << "\n";}}
# define prints(s) {auto kjhg = s;for(auto idnphq : kjhg) cout<< idnphq << ' ';cout << "\n";}
# define printm(m) {auto kjhg = m;for(auto idnphq : kjhg) cout<< idnphq.first << ':' << idnphq.second << ' ';cout << "\n";}
// for runtime errors (assertions and segmentation faults)
# define debug(x) {\
cout<<"all good "<<x<<"\n";\
exit(0);\
}
int isl(vector<int> a){
return(a[0]<=2);
}
int isr(vector<int> a){
return(a[0]%2);
}
int f(vector<int> a, vector<int> b){
// case 1 if left corrdinates are equal
if(b[1]==a[1]){
return(1);
}
// case two unequal
if(b[1]<a[1]) swap(a,b);// a is now the one with lesser left coordinate
if(a[2]>b[1]){
return(1);
}else if(a[2]==b[1]){
int fl = isr(a) && isl(b);
return(fl);
}else{
return(0);
}
}
int32_t main(){
fastio;
int n; cin>>n;
vector<vector<int>> a = {};
for(int i = 0; i<n ; i++){
vector<int> dat(3);
cin>>dat[0]>>dat[1]>>dat[2];
a.push_back(dat);
}
// printvv(a);
int cnt = 0;
for(int i = 0; i<n ; i++){
for( int j = i+1; j<n ; j++){
cnt+=f(a[i],a[j]);
// print(f(a[i],a[j]));
}
}
print(cnt);
return(0);
}
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ephsilon 1e-9
#define int long long int
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const long long mod = 1e9+7;
const long long mod1 = 998244353;
const int maxN = 2e5+1;
const int mx = 1e5+1;
int32_t main()
{
fastio;
int n;
double a,b;
cin>>n;
vector<pair<double,double>>v;
int t;
for(int i=0;i<n;i++)
{
cin>>t>>a>>b;
if(t==2)b-=.1;
else if(t==3)a+=.1;
else if(t==4)a+=.1,b-=.1;
v.push_back({a,b});
}
sort(v.begin(),v.end());
int ans=0;
for(int i=0;i<n-1;i++)
{
for(int j=i+1;j<n;j++)
{
double l1=v[i].first,r1=v[i].second;
double l2=v[j].first,r2=v[j].second;
if(l1>r2 || r1<l2)continue;
else ans++;
}
}
cout<<ans<<"\n";
return 0;
}
|
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <string>
#include <algorithm>
#include <tuple>
#include <array>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
typedef long long ll;
int main()
{
ll L;
cin >> L;
ll dp[L][12];
for (int i = 0; i < L; ++i) {
for (int j = 0; j < 12; ++j) {
if (i == 0 || j > i) {
dp[i][j] = 0;
} else if (j == 0 || i==j) {
dp[i][j] = 1;
} else {
dp[i][j] = dp[i-1][j-1] + dp[i-1][j];
}
}
}
cout << dp[L-1][11];
return 0;
} | #include<iostream>
#include<cmath>
using namespace std;
int main()
{
long long int n;
cin>>n;
long long int c=0,x=0;
long long int h=1e10,l=0;
long long int m=0;
while(h-l>1)
{
m=l+(h-l)/2;
if(m*(m+1)/2<=n+1)
{
l=m;
}
else
{
h=m;
}
}
//cout<<l<<" ";
cout<<n-l+1;
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ll k, n, m;
cin >> k >> n >> m;
vector<ll> a(k);
for (int i = 0; i < k; i++)
{
cin >> a[i];
}
vector<ll> b(k);
vector<pair<ll, ll>> d(k);
ll sum = 0;
for (int i = 0; i < k; i++)
{
b[i] = a[i] * m / n;
d[i].first = a[i] * m % n;
d[i].second = i;
sum += b[i];
}
// a[i] * m % n が大きい順に1足す
sort(d.begin(), d.end(), [](pair<ll, ll> a, pair<ll, ll> b) {
return a.first > b.first;
});
const ll addNum = m - sum;
for (ll i = 0; i < addNum; i++)
{
b[d[i].second]++;
}
for (auto const v : b)
{
cout << v << " ";
}
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000010
#define EPS 1e-9
#define F first
#define S second
#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"
typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;
template <typename T>
bool chmax(T &a, const T& b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T>
bool chmin(T &a, const T& b) {
if (a > b) {
a = b;
return true;
}
return false;
}
signed main(){
//cin.tie(0);
//ios::sync_with_stdio(false);
int k,n,m;
cin>>k>>n>>m;
int a[k];
rep(i,k){
cin>>a[i];
a[i]*=m;
}
int ans[k]={};
int sum=0;
priority_queue<PII> p;
rep(i,k){
ans[i]=((a[i]*2)+n)/(n*2);
//cout<<ans[i]<<" "<<a[i]<<endl;
sum+=ans[i];
//cout<<sum<<endl;
}
//cout<<sum<<endl;
if(sum<m){
rep(i,k){
p.push({((n+a[i]+((n)/2)))%n,i});
//cout<<-((n+a[i]-((n+1)/2)))%n<<endl;
}
while(sum<m){
PII now=p.top();
p.pop();
sum++;
ans[now.S]++;
now.F-=n;
p.push(now);
}
}
if(sum>m){
rep(i,k){
p.push({-(n+a[i]+((n)/2))%n,i});
//cout<<(a[i]+(n/2))%n<<endl;
}
while(sum>m){
PII now=p.top();
p.pop();
sum--;
ans[now.S]--;
now.F-=n;
p.push(now);
}
}
rep(i,k){
if(i) cout<<" ";
cout<<ans[i];
}
cout<<endl;
return 0;
}
|
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
#include <random>
#include <cassert>
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using namespace std;
#define int long long
#define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define REPE(i, n) for (int (i)=0; (i) <= (n); (i)++)
#define CONTAINS_MAP(m, a) ((m).find((a)) != m.end())
#define CONTAINS_SET(m, a) ((m).find((a)) != m.end())
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; exit(0); }
void Yes() { cout << "Yes" << endl; exit(0); }
void No() { cout << "No" << endl; exit(0); }
//---------- 1000000007 ----------
const int MOD = 998244353;
struct mint {
ll x; // typedef long long ll;
mint(ll x = 0) :x((x% MOD + MOD) % MOD) {}
mint operator-() const { return mint(-x); }
mint& operator+=(const mint a) {
if ((x += a.x) >= MOD) x -= MOD;
return *this;
}
mint& operator-=(const mint a) {
if ((x += MOD - a.x) >= MOD) x -= MOD;
return *this;
}
mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this; }
mint operator+(const mint a) const { return mint(*this) += a; }
mint operator-(const mint a) const { return mint(*this) -= a; }
mint operator*(const mint a) const { return mint(*this) *= a; }
mint pow(ll t) const {
if (!t) return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1) a *= *this;
return a;
}
// for prime mod
mint inv() const { return pow(MOD - 2); }
mint& operator/=(const mint a) { return *this *= a.inv(); }
mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }
mint m_comb(mint n, mint r)
{
int i;
mint p = 1;
for (i = 1; i <= r.x; i++)
{
p *= n - i + 1;
p /= i;
}
return p;
}
mint m_comb_with_rep(mint n, mint r)
{
return m_comb(n + r - 1, r);
}
mint m_perm(mint n, mint r)
{
mint a = 1;
for (int i = n.x; i > n.x - r.x; i--)
{
a *= i;
}
return a;
}
int N;
int A[200001];
signed main()
{
cin >> N;
REP(i, N) cin >> A[i];
ARY_SORT(A, N);
mint ans = 0;
mint sum = 0;
mint b = 1;
for (int i = 1; i < N; i++)
{
mint a = A[0] * A[i];
sum += a * b;
b *= 2;
}
ans = sum;
for (int i = 0; i < N - 1; i++)
{
sum -= (A[i] * A[i + 1]);
sum /= 2;
sum /= A[i];
sum *= A[i + 1];
ans += sum;
}
for (int i = 0; i < N; i++)
{
mint a = A[i] * A[i];
ans += a;
}
cout << ans << endl;
}
| #include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e6 + 1, inf = 1e9, mod = 998244353;
ll modpow(ll x, ll p){
ll ans = 1;
for (ll i = p; i; i >>= 1, x = x * x % mod) if (i & 1) ans = ans * x % mod;
return ans;
}
int main(){
ios::sync_with_stdio(0), cin.tie(0);
int n;
cin >> n;
ll a[n], pre[n], ans = 0;
for (ll &i : a) cin >> i;
sort(a, a + n);
for (int i = 0; i < n; i++) pre[i] = ((i ? pre[i - 1] : 0) + a[i] * modpow(2, i)) % mod;
for (int i = 0; i < n; i++){
ll tmp = a[i] * (pre[n - 1] - pre[i]) % mod;
tmp = tmp * modpow(modpow(2, i + 1), mod - 2) % mod;
ans = (ans + tmp + a[i] * a[i]) % mod;
}
cout << ans;
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
#define F(index,start,end) for(ll index=start;index<end;++index)
#define IA(array,size) F(index,0,size) cin >> array[index]
#define IA2(array,height,width) F(i,0,height) F(j,0,width) cin >> array[i][j]
#define PA(array,size) F(index,0,size) { cout << array[index]; if(index!=size-1) cout << " ";} cout << endl
#define PA2(array,height,width) F(i,0,height) {F(j,0,width) cout << array[i][j]; cout << endl;}
#define P(str) cout << str << endl
constexpr int32_t MOD=1000000007;
int main(){
ll n,m;
cin>>n>>m;
if(m==0){
cout << 1 << endl;
return 0;
}
ll a[m];
IA(a,m);
if(n==m){
cout << 0 << endl;
return 0;
}
sort(a,a+m);
vll d;
if(a[0]-1!=0) d.push_back(a[0]-1);
F(i,1,m){
if(a[i]-a[i-1]-1!=0) d.push_back(a[i]-a[i-1]-1);
}
if(n-a[m-1]!=0) d.push_back(n-a[m-1]);
sort(d.begin(),d.end());
ll sum=0;
for(auto dd:d){
sum+=ll(ceil(double(dd)/d[0]));
}
cout << sum << endl;
return 0;
} | #include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1001001001
#define LINF 1001001001001001001
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LLP;
int main() {
ll N, W;
cin >> N >> W;
vector<ll> S(N), T(N), P(N);
rep(i,N) cin >> S[i] >> T[i] >> P[i];
priority_queue<pair<ll, LLP>, vector<pair<ll, LLP>>, greater<pair<ll, LLP>>> wait;
priority_queue<LLP, vector<LLP>, greater<LLP>> now;
rep(i,N) {
pair<ll, LLP> k = make_pair(S[i], make_pair(T[i], P[i]));
wait.push(k);
}
ll demand = 0;
rep(i,200000) {
while (!wait.empty() && wait.top().first <= i) {
LLP next = wait.top().second; wait.pop();
now.push(next);
demand += next.second;
}
while (!now.empty() && now.top().first <= i) {
demand -= now.top().second;
now.pop();
}
if (demand > W) {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using ull = unsigned long long int;
using P = pair<int, int>;
using P3 = pair<int,P>;
using PP = pair<P, P>;
constexpr int INF32 = 1 << 29;
constexpr ll INF64 = 1LL << 61;
constexpr ll MOD = 1000000007;
// constexpr ll MOD = 998244353;
constexpr int di[] = {0, 1, 0, -1};
constexpr int dj[] = {1, 0, -1, 0};
constexpr int di8[] = {0, 1, 1, 1, 0, -1, -1, -1};
constexpr int dj8[] = {1, 1, 0, -1, -1, -1, 0, 1};
constexpr double EPS = 1e-10;
const double PI = acos(-1);
#define ALL(v) (v).begin(),(v).end()
#define REP(i,n) for(int i=0,i_len=n; i<i_len; ++i)
template<typename T1,typename T2> bool chmax(T1 &a, T2 b) { if (a<b) { a=b; return 1; } return 0; }
template<typename T1,typename T2> bool chmin(T1 &a, T2 b) { if (b<a) { a=b; return 1; } return 0; }
int main(){
string s;
cin >> s;
int ans = 0;
for(int i=0;i<10000;i++){
string t = to_string(i);
while(t.size() < 4) t.insert(t.begin(),'0');
bool valid = true;
for(int j=0;j<10;j++){
if(s[j]=='o'){
valid &= t.find('0'+j) != t.npos;
}
if(s[j]=='x'){
valid &= t.find('0'+j) == t.npos;
}
}
if(valid) ans++;
}
cout << ans << endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll cnt[3];
// ll solve(ll a, ll b, ll c){
// if (a>4) return 0;
// if (a==4) return 24;
// if (a==3){
// if (c==0) return 81-solve(1,b,1)-solve(1,b,2);
// else return solve(a,b,0)+24*c;
// }
// if (a==2){
// if (c==0) return 16-2;
// if (c==1) return solve(3,7,0)+solve(a,b,0);
// if (c==2) return solve(4,6,0)+solve(a,b,1);
// if (c==3) return 3*solve(4,6,0)
// }
// }
ll combi(ll a, ll b){
if (a==b) return 1;
if (2 * b > a) return combi(a, a-b);
ll ret = 1;
for(ll i=0; i<b; i++){
ret *= (a-i);
}
for(ll i=1; i<=b; i++){
ret /= i;
}
return ret;
}
// 4桁の数字をa個の文字を使って作る方法
ll make_four_digits(ll a){
if (a==4) return 24;
if (a==3) return 81-combi(3,2)*make_four_digits(2)-combi(3,1)*make_four_digits(1);
if (a==2) return 16-combi(2,1)*make_four_digits(1);
if (a==1) return 1;
else return 0;
}
ll solve(ll a, ll b, ll c){
if (a>4) return 0;
if (a==4) return make_four_digits(4);
if (a==3){
if (c==0) return make_four_digits(3);
if (c==1) return make_four_digits(3) + make_four_digits(4);
else return make_four_digits(3) + c*make_four_digits(4);
}else if (a==2){
if (c==0) return make_four_digits(2);
if (c==1) return make_four_digits(2) + make_four_digits(3);
else return make_four_digits(2) + combi(c,1)*make_four_digits(3) + combi(c,2)*make_four_digits(4);
}else if (a==1){
if (c==0) return 1;
if (c==1) return make_four_digits(1)+make_four_digits(2);
if (c==2) return make_four_digits(1) + combi(2,1)*make_four_digits(2) + combi(2,2)*make_four_digits(3);
else return make_four_digits(1) + combi(c,1)*make_four_digits(2) + combi(c,2)*make_four_digits(3) + combi(c,3)*make_four_digits(4);
}else{ // (a==0)
if (c==0) return 0;
if (c==1) return 1;
if (c==2) return combi(2,1)*make_four_digits(1) + combi(2,2)*make_four_digits(2);
if (c==3) return combi(3,1)*make_four_digits(1) + combi(3,2)*make_four_digits(2) + combi(3,3)*make_four_digits(3);
else return combi(c,1)*make_four_digits(1) + combi(c,2)*make_four_digits(2) + combi(c,3)*make_four_digits(3) + combi(c,4)*make_four_digits(4);
}
}
int main(){
string S;
cin >> S;
for(ll i=0; i<S.size(); i++){
if (S[i]=='o') cnt[0]++;
else if (S[i]=='x') cnt[1]++;
else cnt[2]++;
}
cout << solve(cnt[0], cnt[1], cnt[2]) << endl;
return 0;
} |
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;
long long calc_score(string s)
{
long long score = 0;
for (char c = '1'; c <= '9'; c++)
{
int cnt = 0;
rep(i, s.size())
{
if (c == s[i])
cnt++;
}
int tmp = (c - '0');
rep(j, cnt)
{
tmp *= 10;
}
score += tmp;
}
return score;
}
long long calc_cases(string s, string t, int K)
{
vector<int> rest(10, K);
rep(i, 4)
{
rest[s[i] - '0']--;
}
rep(i, 4)
{
rest[t[i] - '0']--;
}
long long cases = rest[s[4] - '0'];
rest[s[4] - '0']--;
cases *= rest[t[4] - '0'];
return cases;
}
int main()
{
int K;
cin >> K;
string S, T;
cin >> S >> T;
vector<int> rest(10, K);
rep(i, S.size())
{
rest[S[i] - '0']--;
}
rep(i, T.size())
{
rest[T[i] - '0']--;
}
double cases = 0;
for (char c = '1'; c <= '9'; c++)
{
if (rest[c - '0'] == 0)
continue;
string s = S;
s[4] = c;
for (char c2 = '1'; c2 <= '9'; c2++)
{
if (rest[c2 - '0'] == 0 || (c == c2 && rest[c2 - '0'] == 1))
continue;
string t = T;
t[4] = c2;
if (calc_score(s) > calc_score(t))
{
cases += calc_cases(s, t, K);
}
}
}
cout << std::fixed << std::setprecision(10) << cases / (K * 9 - 8) / (K * 9 - 8 - 1) << endl;
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int, int>pi;
typedef pair<long long, long long>pl;
#define F first
#define S second
#define pb push_back
#define all(x) x.begin() , x.end()
#define mp1 make_pair
#define REP(i,a,b) for(i=a;i<=b;i++)
#define mem(a) memset(a , 0 ,sizeof a)
#define memn(a) memset(a , -1 ,sizeof a)
int main()
{
int t = 1;
//cin >> t;
while (t--)
{
ll a,b,w,mn,mx;
cin>>a>>b>>w;
w=w*1000;
mx=w/a; mn=ceil(w/(b*1.00));
if(mn>mx) cout<<"UNSATISFIABLE"<<endl;
else cout<<mn<<" "<<mx<<endl;
}
}
|
#include <bits/stdc++.h>
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(),(x).end()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
using namespace std;
typedef double DB;
typedef long double LD;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<PII> VPII;
// head
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
LL n;int k;cin>>n>>k;
for(int i=1;i<=k;i++) {
if(n%200==0) n/=200;
else n=n*1000+200;
}
cout<<n<<'\n';
return 0;
} | /*Name-Dipesh
Location-Somewhere in interstellar
W/A is inevitable*/
#include <algorithm>
#include <array>
#include <cassert>
#include<bits/stdc++.h>
#include <chrono>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include<unordered_map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <vector>
#define Super_schnell ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define test() long long t; cin>>t; while(t--)
#define comp(v) v.begin(),v.end()
#define sortv(v) sort(comp(v))
#define vecfind(v,key) (find(all(v),key)!=v.end())
#define vecdelp(v,pos) v.erase(v.begin()+pos)
#define setfind(v,key) (v.find(key) != v.end())
#define mapfind(m,key) (mp.find(key) != mp.end())
#define print(i) cout<<i<<"\n"
#define veccount(v,key) (count(all(v),key))
#define setcount(s,key) (s.count(key))
#define bitcount(i) __builtin_popcount(i)
#define int long long
#define ull unsigned long long
#define db double
#define inf 1000000007
#define mod 1000000007
#define veci vector<long long>
#define vecs vector<string>
#define mp make_pair
#define pqueue priority_queue< long long >
#define pdqueue priority_queue< long long,vi ,greater< long long > >
#define pi 3.14159265358979323846
#define mem(x , v) memset((x) , (v) , sizeof(x))
using namespace std;
int gcd(int a,int b){
while(b){
a%=b;
swap(a,b);
}
return a;}
int square(int num)
{
if (num < 0) num = -num;
int result = 0, times = num;
while (times > 0)
{
int possibleShifts = 0, currTimes = 1;
while ((currTimes << 1) <= times)
{
currTimes = currTimes << 1;
++possibleShifts;
}
result = result + (num << possibleShifts);
times = times - currTimes;
}
return result;
}
char reVal(int num)
{
if (num >= 0 && num <= 9)
return (char)(num + '0');
else
return (char)(num - 10 + 'A');
}
int32_t main()
{
int n,k;
cin>>n>>k;
while(k--)
{
if(n%200==0)
{
n=n/200;
}
else
{
n=(n*1000)+200;
}
}
cout<<n;
} |
//The moment you giveup , is the moment you let someone else win!!!
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
#define PI (3.141592653589)
#define seal(x,y) ((x+y-1)/y)
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define all(x) x.begin(),x.end()
int digit_sum(int n){
int sum=0;
while(n)
sum+=(n%10),n/=10;
return sum;
}
//int digicnt_fact(int n)
//{
//if(n<0) return 0; //factorial doesn't exist
//if(n<=1) return 1; //base case
//double x=((n * log10(n / M_E) +log10(2 * M_PI * n) /2.0)); //Kamenetsky's formula
//return floor(x)+1;
//}
void solve(){
int n;cin>>n;
int a[n];
rep(i,n)
cin>>a[i];
int ans=0;
unordered_map<int,int> m;
for(int i=n-1;i>=0;i--)
{
ans+=(n-1-i-m[a[i]]);
m[a[i]]++;
}
cout<<ans;
}
int32_t main()
{
fast
int t=1;
//cin>>t;
while(t--){
solve();
}
return 0;
} | #include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <climits>
#include <queue>
#include <map>
#include<stack>
#include <cmath>
using namespace std;
char judge(string Input){
if(Input=="RP" || Input=="PR"||Input =="PP")return 'P';
if(Input=="RS" || Input=="SR"||Input =="RR")return 'R';
if(Input=="PS" || Input=="SP"||Input =="SS")return 'S';
}
void solve(){
int n,k;
scanf("%d %d",&n,&k);
string Input,Output="",temp="";
cin>>Input;
while(k>0){
Input = Input + Input;
Output="";
for(int i=0;i<Input.length();i+=2){
temp= "";
temp+=Input[i];
temp+=Input[i+1];
Output += judge(temp);
}
Input=Output;
k--;
}
cout<<Input[0]<<endl;
}
int main()
{
int t=1,i=1;
//scanf("%d",&t);
while(t--){
//cout<<"Case #"<<i<<":";
solve();
i++;
}
return 0;
} |
#include<iostream>
using namespace std;
int main(){
int n;cin>>n;
int xy[110][2]={0};
bool f=false;
for(int i=0;i<n;++i)cin>>xy[i][0]>>xy[i][1];
for(int i=0;i<n-1;++i){
for(int j=i+1;j<n-1;++j){
for(int k=j+1;k<n;++k){
int x1=xy[i][0]-xy[k][0];
int y1=xy[i][1]-xy[k][1];
int x2=xy[j][0]-xy[k][0];
int y2=xy[j][1]-xy[k][1];
if(x1*y2==x2*y1)f=true;
}
}
}
if(f)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
return 0;
} | #include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define pf printf
#define ff first
#define ss second
#define sef second.first
#define ses second.second
#define PI 3.14159265 /// tan inverse = atan(value)*(180/PI)
#define ms(a,b) memset(a, b, sizeof(a))
#define lp(i,a,b) for (int i = a; i <= b; i++)
#define pii pair <int,int>
#define SL(a) scanf("%I64d",&a)
#define SLL(a,b) scanf("%I64d %I64d",&a,&b)
#define PL(x) printf("%I64d\n",(x))
#define PLL(x,y) printf("%I64d %I64d\n",x,y)
#define S(a) scanf("%d",&a)
#define SS(a,b) scanf("%d %d",&a,&b)
#define P(x) printf("%d\n",(x))
#define PP(x,y) printf("%d %d\n",x,y)
using namespace std ;
typedef long long ll ;
const int imin = 1e9+100;
const ll maxx = 1e5+10,mod=1e9+7,imax=1e18+10;
int main()
{
ll n,a=0,b=mod ;
cin >> n ;
for(int i=1;i<=n;i++)
{
ll x ;
cin >> x ;
a = max(x,a);
}
for(int i=1;i<=n;i++)
{
ll x ;
cin >> x ;
b = min(x,b);
}
ll ans = max(0LL,b-a+1);
cout << ans << endl;
return 0 ;
}
|
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <limits>
#include <list>
#include <numeric>
#include <queue>
#include <stack>
#include <utility>
#include <array>
#include <random>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <assert.h>
using namespace std;
typedef long long ll;
#define dump(x) cerr << #x << " = " << (x) << " [" << __LINE__ << ":" << __FUNCTION__ << "] " << endl;
// vector出力
template < typename T >
ostream& operator<<(ostream& os, vector< T >& v) {
os << "{";
for (int i = 0; i < (int)v.size(); i++) {
os << v[i] << (i < v.size() - 1 ? ", " : "");
}
os << "}";
return os;
}
// pair出力
template < typename T, typename U >
ostream& operator<<(ostream& os, const pair< T, U >& p) {
return os << "(" << p.first << ", " << p.second << ")";
}
// map出力
template < typename T, typename U >
ostream& operator<<(ostream& os, const map< T, U >& map_var) {
os << "{";
for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
os << "(" << itr->first << ", " << itr->second << ")";
itr++;
if (itr != map_var.end()) os << ", ";
itr--;
}
os << "}";
return os;
}
// set 出力
template < typename T >
ostream& operator<<(ostream& os, const set< T >& set_var) {
os << "{";
for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
os << *itr;
++itr;
if (itr != set_var.end()) os << ", ";
itr--;
}
os << "}";
return os;
}
#pragma endregion
/////////////////////////////////////////
int main() {
int n;cin >> n;
vector<int> a(n);
ll sum = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
}
vector<int> x,y;
for (int i = 0; i < n; i++) {
int b;cin >> b;
if (i & 1) {
y.push_back(b-a[i]);
}
else {
x.push_back(b-a[i]);
}
}
sort(x.rbegin(), x.rend());
sort(y.rbegin(), y.rend());
for (int i = 0; i < x.size(); i++) {
if (x[i] + y[i] > 0) {
sum += x[i] + y[i];
}
}
cout << sum << endl;
return 0;
}
///////////////////////////////////////// | //#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define int long long
using namespace std;
typedef long long ll;
//template<class T>T ABS(T x) {return x<0?-x:x;}
//int ksm(int x,int y) {int r=1;while(y) y&1?r=1ll*r*x%mod:0,x=1ll*x*x%mod,y>>=1;return r;}
//char __buf[1<<20],*__p1,*__p2;
//#define getchar() (__p1==__p2?(__p2=__buf+fread(__p1=__buf,1,1<<20,stdin),__p1==__p2?EOF:*__p1++):*__p1++)
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<<3)+(s<<1)+(ch^48),ch=getchar();
return s*w;
}
const int maxn = 2e5+10;
//const int mod = ;
//struct Edge{int to,next;}a[maxn];int h[maxn],cnt;
//void add(int x,int y) {a[++cnt]=(Edge){y,h[x]},h[x]=cnt,a[++cnt]=(Edge){x,h[y]},h[y]=cnt;}
//vector<int>G[maxn];
//void add(int x,int y) {G[x].push_back(y),G[y].push_back(x);}
struct node{int x,y;
}a[maxn<<1];int n,k;
bool cmp(node x,node y) {return x.x<y.x;}
signed main() {
n=read(),k=read();
for(int i=1;i<=n;i++) a[i]=(node){read(),read()};
sort(a+1,a+1+n,cmp);
for(int i=1;i<=n;i++)
if(k>=a[i].x) {
k+=a[i].y;
}
else break;
cout<<k<<'\n';
return 0;
} |
//#define _GLIBCXX_DEBUG
//#include <atcoder/all>
#include <bits/stdc++.h>
#include <chrono>
#include <random>
using namespace std;
//using namespace atcoder;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
//const ll MOD=998244353;
//using mint = modint998244353;
//using mint = modint1000000007;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);
int dx[9] = {1, 0, -1, 0, 1, 1, -1, -1, 0};
int dy[9] = {0, 1, 0, -1, 1, -1, -1, 1, 0};
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
// cout << fixed << setprecision(15);
string G="atcoder";
ll T; cin>>T;
rep(_,T){
string S; cin>>S;
ll N=S.size();
auto MS=S;
sort(MS.rbegin(),MS.rend());
if(G>=MS) {cout<<-1<<'\n'; continue;}
ll ans=INF;
vector<ll> vec(7,-1);
rep(i,N){
rep(j,7){
if(S[i]==G[j]&&vec[j]==-1) vec[j]=i;
}
}
//for(auto v:vec) cout<<v<<'\n';
rep(i,8){
ll sans=0;
rep(j,i){
if(vec[j]==-1) goto OUT;
sans+=abs(vec[j]-j);
}
int piyo=0;
rep(j,N){
int hoge=0;
rep(k,i){
if(j==vec[k]) hoge=1;
}
if(hoge) continue;
if(S[j]>(i==7?'a'-1:G[i])){
sans+=abs(j-i);
piyo=1;
//cout<<i<<' '<<j<<'\n';
break;
}
}
//cout<<i<<' '<<sans<<'\n';
if(piyo) chmin(ans,sans);
}
OUT:;
cout<<ans<<'\n';
}
return 0;
}
| /*
Author : Xinyuan
*/
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef long long int ll;
const int INF = 1e9 + 7;
const int mod = 1e9 + 7;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int nxt() {int x;scanf("%d", &x);return x;}
int main(){
int w, x, y, z;
cin >> w >> x >> y >> z;
cout << w * z - x * y;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using pii = pair<int, int>;
ll f(ll n){
if (n % 200 == 0) n /= 200;
else n = n * 1000 + 200;
return n;
}
int main(){
ll n,k;
cin >> n >> k;
rep(i,k) n = f(n);
cout << n << endl;
} | #include <iostream>
#include <string>
#include <iomanip>
#include <sstream>
#include <istream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
int max(int, int);
int min(int, int);
int positiveNum(int);
unsigned long long factorial(int);
unsigned long long combination(int, int);
long long power(int, int);
bool between(int, int, int);
vector<string> split(string, char);
int digit_sum(int);
vector<long long> divisors(long long);
//cout << fixed << setprecision(15) << y << endl;
long long count_comb(long long, long long);
int main()
{
long long n, k;
cin >> n >> k;
long long count = 0;
for(long long i = 2; i <= 2 * n; i++)
{
if(count_comb(i, n) > 0 && count_comb(i + k, n) > 0)
{
count += count_comb(i, n) * count_comb(i + k, n);
}
}
cout << count << endl;
return 0;
}
long long count_comb(long long num, long long n)
{
if(num <= n + 1)
{
return num - 1;
}
else
{
long long ans = n - (num - (n + 1));
if(ans >= 0)
{
return ans;
}
else
{
return 0;
}
}
}
//2つの整数のうち大きい方を返す
int max(int a, int b)
{
if(a > b)
{
return a;
}
else
{
return b;
}
}
//2つの整数のうち小さい方を返す
int min(int a, int b)
{
if(a < b)
{
return a;
}
else
{
return b;
}
}
//入力が正ならその値,負なら0を返す
int positiveNum(int x)
{
if(x >= 0)
{
return x;
}
else
{
return 0;
}
}
//階乗
unsigned long long factorial(int n)
{
unsigned long long ans = 1;
for(int i = 1; i <= n; i++)
{
ans *= i;
}
return ans;
}
//mの中からn取る組み合わせの数
unsigned long long combination(int m, int n)
{
return factorial(m) / (factorial(m-n)*factorial(n));
}
//cがaとbの間にあるか
bool between(int a, int b, int c)
{
if(a > b)
{
int swap;
swap = a;
a = b;
b = swap;
}
if(a <= c && c <= b)
{
return true;
}
else
{
return false;
}
}
//累乗(long long版)
long long power(int x, int y)
{
long long num = 1;
for(int i = 0; i < y; i++)
{
num *= x;
}
return num;
}
//カンマ等で区切られた文字列を要素で分ける
vector<string> split(string s, char c)
{
vector<string> v;
stringstream ss{s};
string buf;
while(getline(ss, buf, c))
{
v.push_back(buf);
}
return v;
}
//各桁の和を求める
int digit_sum(int x)
{
int sum = 0;
while(x > 0)
{
sum += x % 10;
x /= 10;
}
return sum;
}
//Nの約数を求める
vector<long long> divisors(long long N)
{
vector<long long> a;
for (long long i = 1; i * i <= N; i++)
{
if (N % i == 0)
{
a.push_back(i);
if (N/i != i)
{
a.push_back(N/i);
}
}
}
sort(a.begin(), a.end());
return a;
} |
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
using namespace std;
using ll = long long int;
using P = pair<int, int>;
const ll INF_L = 1LL << 60;
const int INF_I = 1 << 30;
const int MOD = (int)1e9 + 7;
const double PI = acos(-1);
int dx[] = {1, 0, -1, 0};
int dy[] = {0, -1, 0, 1};
int main()
{
int n;
cin >> n;
complex<double> a, b;
rep(i, 2)
{
double x, y;
cin >> x >> y;
if (!i)
a = {x, y};
else
b = {x, y};
}
auto m = (a + b) / 2.0;
auto res = m + (a - m) * polar(1.0, 2.0 * PI / n);
printf("%.10f\n%.10f\n", res.real(), res.imag());
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
int main(){
int N;
cin >> N;
vector<int> x(3,0),y(3,0);
cin >> x[0] >> y[0];
cin >> x[2] >> y[2];
vector<double> O(2,0);
O[0] = (x[0]+x[2])/2.0;
O[1] = (y[0]+y[2])/2.0;
vector<double> xO(3,0),yO(3,0);
for(int i=0;i<3;i++) {
xO[i] = x[i] - O[0];
yO[i] = y[i] - O[1];
}
xO[1] = cos(2*M_PI/N)*xO[0]-sin(2*M_PI/N)*yO[0];
yO[1] = sin(2*M_PI/N)*xO[0]+cos(2*M_PI/N)*yO[0];
xO[1] = xO[1] + O[0];
yO[1] = yO[1] + O[1];
cout << xO[1] << " " << yO[1] << endl;
} |
#include <bits/stdc++.h>
#define ln '\n'
#define all(dat) dat.begin(), dat.end()
#define loop(i, to) for (int i = 0; i < to; ++i)
#define cont(i, to) for (int i = 1; i <= to; ++i)
#define circ(i, fm, to) for (int i = fm; i <= to; ++i)
#define foreach(i, dat) for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)
typedef long long num;
using namespace std;
const int nsz = 3e5;
int n, a[nsz + 5];
num ans, sum[nsz + 5];
map<num, int> cnt;
int main() {
scanf("%d", &n);
cont (i, n) scanf("%d", &a[i]);
for (int i = 2; i <= n; i += 2) a[i] = -a[i];
cnt[0] = 1;
cont (i, n) {
sum[i] = sum[i - 1] + a[i];
ans += cnt[sum[i]];
cnt[sum[i]] += 1;
}
printf("%lld\n", ans);
} | #pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
//#pragma warning(disable : 4996)
//#define ATCODER
#ifdef ATCODER
#include<atcoder/all>
using namespace atcoder;
#endif
#include <algorithm>
#include <utility>
#include <vector>
#include <limits.h>
#include <math.h>
#include <time.h>
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cassert>
#include <numeric>
#include <type_traits>
using namespace std;
#ifdef _MSC_VER
#include"stdafx.h"
#include <intrin.h>
#define __builtin_popcount __popcnt
#define __builtin_popcountll __popcnt64
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << " " << (H);
debug_out(T...);
}
#define DEBUG(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define DEBUG(...) 42
#endif
#define ll long long
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REPR(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define FOR(i, m, n) for (ll i = (m); i < (n); ++i)
#define VSORT(v) sort(v.begin(), v.end());
#define VREVERSE(v) reverse(v.begin(), v.end())
#define print(x) cout << (x) << '\n'
#define spa <<" "<<
#define lb(v, n) lower_bound(v.begin(), v.end(), (n))
#define ub(v, n) upper_bound(v.begin(), v.end(), (n))
#define int long long
//#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i, v.size()) cout << v[i] << " \n"[i==(int)v.size()-1]
template <typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template <typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
std::random_device rd;
std::mt19937 mt(rd());
constexpr ll MOD = 998244353;
constexpr int MAX = 300050;
const double pi = acos(-1);
constexpr double EPS = 1e-8;
constexpr ll LINF = 1e17 + 1;
constexpr int INF = 1e9 + 1;
struct UnionFind {
int N;
vector<int> siz;
vector<int> par;
vector<int> Rank;
UnionFind(int n) : siz(n, 1), par(n), Rank(n, 0) {
N = n;
for (int i = 0; i < N; i++) par[i] = i;
}
int find(int x) {
if (par[x] == x) {
return x;
}
else {
return par[x] = find(par[x]);
}
}
void unite(int x, int y) {
x = find(x);
y = find(y);
if (x == y) return;
if (Rank[x] < Rank[y]) {
par[x] = y;
siz[x] += siz[y];
siz[y] = siz[x];
}
else {
siz[y] += siz[x];
siz[x] = siz[y];
par[y] = x;
if (Rank[x] == Rank[y]) Rank[x]++;
}
}
bool same(int x, int y) { return find(x) == find(y); }
};
typedef complex<double> point;
void solve() {
int N; cin >> N;
//UnionFind uf(N + 2);
vector<point>ps;
REP(i, N) {
int x, y; cin >> x >> y;
ps.emplace_back(x, y);
}
double ans = 0;
double ok = 0, ng = 200;
REP(_, 50) {
double mid = (ok + ng) / 2;
UnionFind uf(N + 2);
REP(i, N)FOR(j, i + 1, N) {
if (abs(ps[i] - ps[j]) < 2 * mid)uf.unite(i, j);
}
REP(i, N) {
if (abs(100 - ps[i].imag()) < 2 * mid)uf.unite(i, N);
if (abs(-100 - ps[i].imag()) < 2 * mid)uf.unite(i, N + 1);
}
if (uf.same(N, N + 1))ng = mid;
else ok = mid;
}
cout << setprecision(10) << fixed << ok << endl;
}
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
//int q; cin >> q; while (q--)
solve();
} |
#include <iostream>
#include <math.h>
#include <vector>
#include <string>
#include <numeric>
#include <unordered_set>
using namespace std;
int main(){
int h,w; cin >> h >> w;
vector<vector<int> > block(h,vector<int>(w));
int min_block;
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
cin >> block[i][j];
min_block = min(min_block,block[i][j]);
}
}
int ans=0;
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
ans += block[i][j]-min_block;
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
template <class T>
bool chmin(T& a, T b)
{
if (a > b)
{
a = b;
return true;
}
else
return false;
}
int main()
{
int h, w;
cin >> h >> w;
int ans = 0;
int mx = 101;
rep(_, h * w) {
int a;
cin >> a;
chmin(mx, a);
ans += a;
}
ans -= mx * h * w;
cout << ans << "\n"s;
return 0;
}
|
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n";
#pragma GCC optimize "trapv"
#define sz(v) ((int)(v).size())
const int INF = 1e9;
const int mx =1e6+100;
const int mod =1e9+7;
#define MAX 100005
using namespace std;
typedef long long int ll;
// for policy based DS
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
// #define ordered_set tree<pair<int,int>, null_type,less<pair<int,int> >, rb_tree_tag,tree_order_statistics_node_update>
// #define os_find(k) find_by_order(k)
// #define os_order(k) order_of_key(k)
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
vector<int>special;
unordered_map<int,int>ump;
int main()
{
fast
int n;
cin>>n;
map<int,int>mp;
ll ans =0;
for(int i=0;i<n;i++)
{
int x;
cin>>x;
mp[x]++;
ans += (i+1)-mp[x];
}
cout<<ans<<endl;
return 0;
}
| #include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(void) {
int N;
cin >> N;
vector<string> S;
for (int i = 0; i < N; i++) {
string s;
cin >> s;
if (s[0] == '!') {
s = s.substr(1, s.size() - 1) + '!';
}
S.push_back(s);
}
sort(S.begin(), S.end());
for (int i = 1; i < N; i++) {
if (S[i][S[i].size() - 1] == '!' && S[i].substr(0, S[i].size() - 1) == S[i - 1]) {
cout << S[i - 1] << endl;
return 0;
}
}
cout << "satisfiable\n";
return 0;
} |
#include <bits/stdc++.h>
//#include <iostream>
//#include <vector>
//#include <string>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
const ll M = 998244353;
ll sum(ll mn, ll mx) {
return (mx - mn + 1)*(mn + mx) / 2;
}
int main() {
int t, l, r;
cin >> t;
rep(i, t) {
cin >> l >> r;
int mx;
mx = r - l - l + 1;
mx = max(mx, 0);
cout << sum(1, mx) << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int t; cin>> t;
for (int i=0; i<t; i++) {
long long l, r;
cin>> l >> r;
if (r >= 2*l) {
cout << (r + 2 - 2 * l) * (r + 1 - 2 * l) / 2 << endl;
}
else {
cout << 0 << endl;
}
}
return 0;
} |
//****************************Template Begins****************************//
// Header Files
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<utility>
#include<set>
#include<unordered_set>
#include<list>
#include<iterator>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<bitset>
#include<random>
#include<map>
#include<unordered_map>
#include<stdio.h>
#include<complex>
#include<math.h>
#include<cstring>
#include<chrono>
#include<string>
// Header Files End
using namespace std;
#define HARI ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define umap unordered_map
#define uset unordered_set
#define lb lower_bound
#define ub upper_bound
#define fo(i,a,b) for(i=a;i<=b;i++)
#define all(v) (v).begin(),(v).end()
#define all1(v) (v).begin()+1,(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define allr1(v) (v).rbegin()+1,(v).rend()
#define sort0(v) sort(all(v))
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
#define max3(a,b,c) max(max((a),(b)),(c))
#define max4(a,b,c,d) max(max((a),(b)),max((c),(d)))
#define min3(a,b,c) min(min((a),(b)),(c))
#define min4(a,b,c,d) min(min((a),(b)),min((c),(d)))
#define pb push_back
#define ppb pop_back
#define mkp make_pair
#define inf 9999999999999
const ll mod = 1e9 + 7;
ll inv(ll i) {if (i == 1) return 1; return (mod - ((mod / i) * inv(mod % i)) % mod) % mod;}
ll mod_mul(ll a, ll b) {a = a % mod; b = b % mod; return (((a * b) % mod) + mod) % mod;}
ll mod_add(ll a, ll b) {a = a % mod; b = b % mod; return (((a + b) % mod) + mod) % mod;}
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b);}
ll ceil_div(ll a, ll b) {return a % b == 0 ? a / b : a / b + 1;}
ll pwr(ll a, ll b) {a %= mod; ll res = 1; while (b > 0) {if (b & 1) res = res * a % mod; a = a * a % mod; b >>= 1;} return res;}
//****************************Template Ends*******************************//
int main() {
HARI;
#ifndef ONLINE_JUDGE
freopen("input.txt" , "r" , stdin);
freopen("output.txt", "w", stdout);
#endif
ll t, n, i, j, ans, temp, sum;
string sans;
t = 1;
// cin >> t;
while (t--)
{
sans = "NO";
ans = temp = sum = 0;
cin >> n;
vll a(n + 1, 0), b(n + 1, 0), c(n + 1, 0), freq(n + 1, 0);
fo(i, 1, n)
{
cin >> a[i];
}
fo(i, 1, n)
{
cin >> b[i];
}
fo(i, 1, n)
{
cin >> c[i];
}
fo(i, 1, n)
{
freq[b[c[i]]]++;
}
fo(i, 1, n)ans += freq[a[i]];
cout << ans;
}
return 0;
}
| #include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vpl = vector<pair<ll, ll>>;
using pll = pair<ll, ll>;
#define rep(i, k, n) for(ll i = k; i < n; i++)
#define pb push_back
#define mp make_pair
int main(){
string s; cin >> s;
vll v(10, 0);
rep(i, 0, s.size()){
v[s[i]-48]++;
}
if(s.size() < 2){
if(stoll(s) == 8) cout << "Yes" << endl;
else cout << "No" << endl;
}
else if(s.size() < 3){
ll x = stoll(s);
reverse(s.begin(), s.end());
ll y = stoll(s);
if(x % 8 == 0 || y % 8 == 0) cout << "Yes" << endl;
else cout << "No" << endl;
}
else{
bool f = false;
rep(i, 1, 10){
if(v[i] < 1) continue;
v[i]--;
rep(j, 1, 10){
if(v[j] < 1) continue;
v[j]--;
rep(k, 1, 10){
if(v[k] < 1) continue;
v[k]--;
if((100*i+10*j+k) % 8 == 0) f = true;
v[k]++;
}
v[j]++;
}
v[i]++;
}
if(f) cout << "Yes" << endl;
else cout << "No" << endl;
}
// rep(i, 1, 10){
// cout << i << " " << v[i] << endl;
// }
} |
#include <bits/stdc++.h>
using namespace std;
#define MS(a, b) memset(a, b, sizeof(a))
#define REP(a, b, c) for (register int a = b, _n = c; a <= _n; ++a)
#define DREP(a, b, c) for (register int a = b, _n = c; a >= _n; --a)
#define FOR(a, b, c) for (register int a = b, _n = c; a < _n; ++a)
#define EREP(a, b) for (register int a = head[b]; a; a = edge[a].nxt)
#define ll long long
inline int rd() {
int x = 0; char c = getchar(); bool f = 0;
while (c < '0' && c != '-') c = getchar();
if (c == '-') f = 1, c = getchar();
while (c >= '0') x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
return f ? -x : x;
}
const int SIZE = 1e5 + 100;
int n, m, t[3];
char Co[10];
vector<ll> V[3];
ll dp[SIZE], pre[SIZE], suf[SIZE];
void _main () {
n = rd();
REP (i, 1, 2 * n) {
ll x;
scanf ("%lld%s", &x, Co);
if (Co[0] == 'R') V[0].push_back(x);
else if (Co[0] == 'G') V[1].push_back(x);
else V[2].push_back(x);
}
FOR (i, 0, 3) sort(V[i].begin(), V[i].end());
int WTF = 0;
FOR (i, 0, 3) if (V[i].size() & 1)
t[WTF++] = i;
if (WTF == 0) puts("0");
else {
n = V[t[0]].size(), m = V[t[1]].size();
ll ans = 1e18;
int x = 0;
FOR (i, 0, n) {
if (x) ans = min(ans, llabs(V[t[0]][i] - V[t[1]][x - 1]));
while (x + 1 < m && V[t[1]][x] <= V[t[0]][i]) {
ans = min(ans, llabs(V[t[0]][i] - V[t[1]][x]));
++x;
}
ans = min(ans, llabs(V[t[0]][i] - V[t[1]][x]));
}
t[2] = 3 ^ t[0] ^ t[1];
int T = V[t[2]].size();
if (T) {
x = 0;
FOR (i, 0, T) {
dp[i] = 1e18;
if (x) dp[i] = min(dp[i], llabs(V[t[2]][i] - V[t[1]][x - 1]));
while (x + 1 < m && V[t[1]][x] <= V[t[2]][i]) {
dp[i] = min(dp[i], llabs(V[t[2]][i] - V[t[1]][x]));
++x;
}
dp[i] = min(dp[i], llabs(V[t[2]][i] - V[t[1]][x]));
}
pre[0] = dp[0];
FOR (i, 1, T) pre[i] = min(pre[i - 1], dp[i]);
suf[T - 1] = dp[T - 1];
DREP (i, T - 2, 0) suf[i] = min(suf[i + 1], dp[i]);
x = 0;
FOR (i, 0, T) {
dp[i] = 1e18;
if (x) dp[i] = min(dp[i], llabs(V[t[2]][i] - V[t[0]][x - 1]));
while (x + 1 < n && V[t[0]][x] <= V[t[2]][i]) {
dp[i] = min(dp[i], llabs(V[t[2]][i] - V[t[0]][x]));
++x;
}
dp[i] = min(dp[i], llabs(V[t[2]][i] - V[t[0]][x]));
if (i) ans = min(ans, dp[i] + pre[i - 1]);
if (i != T - 1) ans = min(ans, dp[i] + suf[i + 1]);
}
}
// 0 1 2;
printf ("%lld\n", ans);
}
}
int main () {
_main();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
#define rep(i, n) for(int i = 0, i##_len=(n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((int)(x).size())
void _cin() {} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail) { cin >> head; _cin(forward<Tail>(tail)...); }
#define cin(Type, ...) Type __VA_ARGS__; _cin(__VA_ARGS__)
#define cinv(Type, xs, n) vector<Type> xs(n); rep(i, n) cin >> xs[i]
#define cinv2(Type, xs, ys, n) vector<Type> xs(n), ys(n); rep(i, n) cin >> xs[i] >> ys[i]
#define cinv3(Type, xs, ys, zs, n) vector<Type> xs(n), ys(n), zs(n); rep(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define cinvv(Type, xs, h, w) vector<vector<Type>> xs(h, vector<Type>(w)); rep(i, h) rep(j, w) cin >> xs[i][j]
void print() { cout << endl; }
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) { cout << head; if (sizeof...(tail) != 0) cout << " "; print(forward<Tail>(tail)...); }
template <class Type> void print(vector<Type> &vec) { for (auto& a : vec) { cout << a; if (&a != &vec.back()) cout << " "; } cout << endl; }
template <class Type> void print(vector<vector<Type>> &df) { for (auto& vec : df) { print(vec); } }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void yesno(bool b) { cout << (b ? "yes" : "no") << endl; }
template<class Integer>bool chmax(Integer &a, const Integer &b) { if (a < b) { a = b; return 1; } return 0; }
template<class Integer>bool chmin(Integer &a, const Integer &b) { if (b < a) { a = b; return 1; } return 0; }
using ll = long long;
using P = pair<int, int>;
int fs = 10000;
int n;
vector<int> x(200), y(200), r(200), a(200), b(200), c(200), d(200);
vector<int> id(200);
void show() {
}
void mset(int i, int _a, int _b, int _c, int _d) { a[i] = _a; b[i] = _b; c[i] = _c; d[i] = _d; }
int area(int i) { return (c[i] - a[i])*(d[i] - b[i]); }
bool check() {
rep(i, n) {
if (a[i] < 0 || fs < c[i] || b[i] < 0 || fs < d[i])return false;
rep(j, n) {
if (i == j)continue;
if ((a[i] < c[j]) && (a[j] < c[i]) && (b[i] < d[j]) && (b[j] < d[i]))return false;
}
}
return true;
}
void Main() {
rep(i, n) {
int pc = c[id[i]], pd = d[id[i]];
int ok = 0, ng = fs;
while (ng - ok > 1) {
int wj = (ok + ng) / 2;
c[id[i]] = pc + wj;
d[id[i]] = pd + wj;
if (check())ok = wj;
else ng = wj;
}
c[id[i]] = pc + ok;
d[id[i]] = pd + ok;
if (r[id[i]] < area(id[i])) {
int s = (int)sqrt(r[id[i]]);
c[id[i]] = a[id[i]] + s;
d[id[i]] = b[id[i]] + s;
}
int pa = a[id[i]], pb = b[id[i]];
ok = 0, ng = fs;
while (ng - ok > 1) {
int wj = (ok + ng) / 2;
a[id[i]] = pa - wj;
b[id[i]] = pb - wj;
if (check())ok = wj;
else ng = wj;
}
a[id[i]] = pa - ok;
b[id[i]] = pb - ok;
if (r[id[i]] < area(id[i])) {
int s = (int)sqrt(r[id[i]]);
a[id[i]] = c[id[i]] - s;
b[id[i]] = d[id[i]] - s;
}
}
}
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
//cout << fixed << setprecision(16);
//int t; cin >> t; while (t--)
cin >> n;
vector<P> ri(n);
rep(i, n) cin >> x[i] >> y[i] >> ri[i].first;
rep(i, n)r[i] = ri[i].first;
rep(i, n) ri[i].second = i;
sort(ri.rbegin(), ri.rend());
rep(i, n)id[i] = ri[i].second;
rep(i, n) mset(i, x[i], y[i], x[i] + 1, y[i] + 1);
Main();
rep(i, n) {
print(a[i], b[i], c[i], d[i]);
}
show();
} |
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF ((1<<30)-1)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
struct TrieNode{
int n = 0;
long long sum = 0;
TrieNode* l = nullptr, * r = nullptr;
};
class Trie {
public:
Trie() { root = new TrieNode(); }
void insert(int x) {
TrieNode* t = root;
for (int i = 30; i >= 0; i--) {
t->n++;
t->sum += x;
if (x >> i &1) {
if (t->r == nullptr) t->r = new TrieNode;
t = t->r;
}
else {
if (t->l == nullptr) t->l = new TrieNode;
t = t->l;
}
}
t->n++;
t->sum += x;
}
void erase(int x) {
TrieNode* t = root;
for (int i = 30; i >= 0; i--) {
t->n--;
t->sum -= x;
if (x >> i & 1) {
t = t->r;
}
else {
t = t->l;
}
}
t->n--;
t->sum -= x;
}
pair<int, long long> query(int x) const{
pair<int, long long > ret(0, 0);
TrieNode* t = root;
for (int i = 30; i >= 0; i--) {
if (t == nullptr)break;
if (x >> i & 1) {
if (t->l) {
ret.first += t->l->n;
ret.second += t->l->sum;
}
t = t->r;
}
else {
t = t->l;
}
}
return ret;
}
private:
TrieNode* root;
};
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, m, q;
cin >> n >> m >> q;
vector<int> a(n, 0), b(m, 0);
Trie ta, tb;
rep(i, n) ta.insert(0);
rep(i, m)tb.insert(0);
long long ans = 0;
rep(_, q) {
int t, x, y;
cin >> t >> x >> y;
x--;
if (t == 1) {
auto p = tb.query(a[x]);
ans -= (long long)p.first * a[x];
ans += p.second;
p = tb.query(y);
ans += (long long)p.first * y;
ans -= p.second;
ta.erase(a[x]);
ta.insert(y);
a[x] = y;
}
else {
auto p = ta.query(b[x]);
ans -= (long long)p.first * b[x];
ans += p.second;
p = ta.query(y);
ans += (long long)p.first * y;
ans -= p.second;
tb.erase(b[x]);
tb.insert(y);
b[x] = y;
}
cout << ans << endl;
}
return 0;
}
| #include <vector>
#include <algorithm>
#include <map>
#include <cstdio>
#include <cstdlib>
template <class E> struct FenwickTree {
int _n;
std::vector<E> data;
FenwickTree(int n) : _n(n), data(n) { }
void add(int p, E x) {
++p;
while (p <= _n) {
data[p - 1] += x;
p += p & -p;
}
}
E sum(int r) const {
E s = 0;
while (r > 0) {
s += data[r - 1];
r -= r & -r;
}
return s;
}
E sum(int l, int r) const {
return sum(r) - sum(l);
}
};
long long proc(
std::vector<int> &cur,
int x,
int y,
FenwickTree<int> &ftcnt0,
FenwickTree<long long> &ftsum0,
const FenwickTree<int> &ftcnt1,
const FenwickTree<long long> &ftsum1,
const std::vector<int> &arr)
{
int v = cur[x];
long long dem = (long long)ftcnt1.sum(0, v) * arr[v];
long long cre = (long long)ftcnt1.sum(0, y) * arr[y];
long long adj = (long long)ftsum1.sum(y, v);
ftsum0.add(v, -arr[v]);
ftcnt0.add(v, -1);
cur[x] = y;
ftsum0.add(y, arr[y]);
ftcnt0.add(y, 1);
return cre + adj - dem;
}
static char buf[2000000];
int ptr = 0;
int len = 0;
void init()
{
len = fread(buf, 1, sizeof buf, stdin);
ptr = 0;
}
int myread()
{
int acc = 0;
if (len <= ptr) init();
while (buf[ptr] < '0' | buf[ptr] > '9') {
ptr++;
if (len <= ptr) init();
}
while (buf[ptr] >= '0' && buf[ptr] <= '9') {
acc = acc * 10 + buf[ptr] - '0';
ptr++;
if (len <= ptr) init();
}
return acc;
}
int main(int argc, char **argv)
{
int n = myread(), m = myread(), q = myread();
std::vector<int> ta(q), xa(q), ya(q), arr(q + 1);
for (int i = 0; i < q; i++) {
ta[i] = myread();
xa[i] = myread();
ya[i] = myread();
arr[i + 1] = ya[i];
xa[i]--;
}
std::sort(arr.begin(), arr.end());
std::map<int, int> map;
int ll = 0;
map.emplace(0, 0);
for (int ii = 1; ii <= q; ii++) {
if (arr[ii] != arr[ll]) {
++ll;
arr[ll] = arr[ii];
map.emplace(arr[ii], ll);
}
}
++ll;
FenwickTree<long long> ftsuma(ll);
FenwickTree<long long> ftsumb(ll);
FenwickTree<int> ftcnta(ll);
FenwickTree<int> ftcntb(ll);
std::vector<int> cura(n);
std::vector<int> curb(m);
ftcnta.add(0, n);
ftcntb.add(0, m);
long long sum = 0;
for (int i = 0; i < q; i++) {
int cy = map[ya[i]];
sum += (ta[i] == 1) ? proc(cura, xa[i], cy, ftcnta, ftsuma, ftcntb, ftsumb, arr)
: proc(curb, xa[i], cy, ftcntb, ftsumb, ftcnta, ftsuma, arr);
printf("%lld\n", sum);
}
return 0;
} |
#include<cstdio>
#include<algorithm>
const int Q=200005;
typedef long long ll;
#define rg register int
//char buf[1<<21],*p1=buf,*p2=buf;
//#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
#define gc() getchar()
inline bool ig(char c){return c>=48&&c<=57;}
inline void read(int &oi){char c;int f=1,res=0;while(c=gc(),(!ig(c))&&c^'-');c^'-'?res=(c^48):f=-1;while(c=gc(),ig(c))res=res*10+(c^48);oi=f*res;}
inline void print(int oi){if(oi<0)putchar('-'),oi=~oi+1;if(oi>9)print(oi/10);putchar(oi%10+48);}
inline void write(int oi,char c){print(oi);putchar(c);}
int n,m,col[Q],prt[Q],rt[Q];
namespace VSgt{
struct sgt{int ls,rs,sze;}t[Q<<5];int tot;
inline void update(int x){t[x].sze=t[t[x].ls].sze+t[t[x].rs].sze;}
inline void modify(int l,int r,int q,int &x){
if(q>r||l>q)return;if(!x)x=++tot;if(l==r)return void(++t[x].sze);int mid=l+r>>1;
modify(l,mid,q,t[x].ls);modify(mid+1,r,q,t[x].rs);update(x);
}
inline int merge(int x,int y,int l,int r){
if(!x||!y)return x|y;if(l==r){t[x].sze+=t[y].sze;return x;}
int mid=l+r>>1;t[x].ls=merge(t[x].ls,t[y].ls,l,mid);
t[x].rs=merge(t[x].rs,t[y].rs,mid+1,r);update(x);return x;
}
inline int query(int l,int r,int q,int x){
if(q>r||l>q||!x)return 0;if(l==r)return t[x].sze;int mid=l+r>>1;
return query(l,mid,q,t[x].ls)+query(mid+1,r,q,t[x].rs);
}
}using namespace VSgt;
inline int gfa(int x){return x^prt[x]?prt[x]=gfa(prt[x]):x;}
inline void merge(int x,int y){
x=gfa(x);y=gfa(y);if(x==y)return;prt[x]=y;rt[y]=merge(rt[y],rt[x],1,n);
}
inline int query(int x,int y){
x=gfa(x);return query(1,n,y,rt[x]);
}
int main(){
read(n);read(m);
for(rg i=1;i<=n;++i)read(col[i]);
for(rg i=1;i<=n;++i)prt[i]=i,modify(1,n,col[i],rt[i]);
for(rg i=1;i<=m;++i){
int opt,x,y;read(opt);read(x);read(y);
if(opt==1)merge(x,y);else write(query(x,y),'\n');
}
return 0;
} | #line 2 "/home/defineprogram/Desktop/Library/template/template.cpp"
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define REP(i,n) for(ll i=1;i<n;i++)
#define rev(i,n) for(ll i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<ll,ll>
#define len(s) (ll)s.size()
template<class T,class U> inline bool chmin(T &a, U b){
if(a>b){a=b;return true;}
return false;
}
template<class T,class U> inline bool chmax(T &a, U b){
if(a<b){a=b;return true;}
return false;
}
constexpr ll inf = 3e18;
#line 3 "/home/defineprogram/Desktop/Library/math/modint.cpp"
template<int MOD>
struct mint{
int32_t n;
mint():n(0){}
mint(ll x):n(x>=0?x%MOD:(MOD-(-x)%MOD)%MOD){}
mint &operator+=(const mint &p){
if((n+=p.n)>=MOD)n-=MOD;
return *this;
}
mint &operator-=(const mint &p){
if((n+=MOD-p.n)>=MOD)n-=MOD;
return *this;
}
mint &operator*=(const mint &p){
n=1ll*n*p.n%MOD;
return *this;
}
mint &operator/=(const mint &p){
*this*=p.inverse();
return *this;
}
mint operator-()const{return mint(-n);}
mint operator+(const mint &p)const{return mint(*this)+=p;}
mint operator-(const mint &p)const{return mint(*this)-=p;}
mint operator*(const mint &p)const{return mint(*this)*=p;}
mint operator/(const mint &p)const{return mint(*this)/=p;}
bool operator==(const mint &p)const{return n==p.n;}
bool operator!=(const mint &p)const{return n!=p.n;}
friend ostream &operator<<(ostream &os,const mint &p){
return os<<p.n;
}
friend istream &operator>>(istream &is,mint &p){
int x;is>>x;
p=mint(x);
return is;
}
mint pow(int64_t x)const{
mint res(1),mul(n);
while(x>0){
if(x&1)res*=mul;
mul*=mul;
x>>=1;
}
return res;
}
mint inverse()const{
return pow(MOD-2);
}
};
/*
@brief mod int
@docs docs/modint.md
*/
#line 3 "main.cpp"
int par[200005],siz[200005];
map<int,int>mp[200005];
int find(int x){
if(par[x]==x)return x;
return par[x]=find(par[x]);
}
void merge(int x,int y){
x=find(x),y=find(y);
if(x==y)return;
if(siz[x]<siz[y])swap(x,y);
for(auto i:mp[y])mp[x][i.first]+=i.second;
siz[x]+=siz[y];par[y]=x;
}
int N,Q;
int main(){
cin.tie(0);ios::sync_with_stdio(false);
cin>>N>>Q;
rep(i,N){
int a;cin>>a;mp[i][a]++;par[i]=i;siz[i]=1;
}
while(Q--){
int t;cin>>t;
if(t==1){
int a,b;cin>>a>>b;a--;b--;
merge(a,b);
}else {
int a,b;cin>>a>>b;a--;
cout<<mp[find(a)][b]<<"\n";
}
}
}
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(int i=(n);i<(k);i++)
#define ALL(a) (a).begin(),(a).end()
ll ans = 0;
void Main(){
using P = pair<int, int>;
int a, b, x, y;
cin >> a >> b >> x >> y;
a--;
b--;
vector<vector<P>> graph(200);
For(i,0,100){
graph[i].push_back({i + 100, x});
graph[i + 100].push_back({i , x});
}
For(i,0,99){
graph[i + 1].push_back({i + 100, x});
graph[i + 100].push_back({i + 1 , x});
}
For(i,0,99){
graph[i].push_back({i + 1, y});
graph[i + 1].push_back({i, y});
graph[i + 100].push_back({i + 101, y});
graph[i + 101].push_back({i + 100, y});
}
vector<int> dist(200, 1e9);
dist[a] = 0;
stack<P> st;
st.push({a , 0});
while(!st.empty()){
auto [now, d] = st.top();
st.pop();
for(auto to : graph[now]){
if(dist[to.first] > d + to.second){
dist[to.first] = d + to.second;
st.push({to.first, dist[to.first]});
}
}
}
cout << dist[b + 100] << endl;
}
int main(){
Main();
/*
東方風神録は神が出てくるので当然神ゲー
*/
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(), (a).end()
#define mk make_pair
#define pp pair<int, int>
ll MOD = 1000000007;
ll mod = 998244353;
int inf = 2000001000;
ll INF = 1e18 + 5;
int main() {
int n;
cin >> n;
vector<pair<ld,ld>> a(n);
rep(i,n){
ld f,g,h;
cin >> f >> g >> h;
if (f==1) a[i]=mk(g,h);
if (f==2) a[i]=mk(g,h-0.1);
if (f==3) a[i]=mk(g+0.1,h);
if (f==4) a[i]=mk(g+0.1,h-0.1);
}
int ans=0;
rep(i,n){
for (int j=i+1;j<n;j++){
if (!(a[i].first>a[j].second || a[i].second<a[j].first)) {ans++;}
}
}
cout << ans << endl;
}
|
#pragma warning (disable:4996)
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#define ll long long
#define REP(i, n) for(ll i = 0; i < n; i++)
#define SET(a) ll a = 0; (void)scanf("%lld", &a);
/*
ll cutLog(ll);
ll sum(ll);
*/
ll cutLogNew(ll);
int main() {
SET(n);
if (n == 1 || n == 2)printf("1");
else printf("%lld", n - cutLogNew(n) + 1);
return 0;
}
/*
ll cutLog(ll n) {
ll ans;
REP(i, n + 1) {
if (sum(i + 1) > n + 1) {
ans = i;
break;
}
}
return ans;
}
ll sum(ll n) {
ll sum = 0;
REP(i, n) {
sum += (i + 1);
}
return sum;
}
*/
ll cutLogNew(ll n) {
ll ans = 0;
ll m = n + 1;
REP(i, n) {
m -= (i + 1);
if (m < 0) {
ans = i;
break;
}
}
return ans;
} | #include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const long double PI = (acos(-1));
const long long MOD = 1000000007;
static const int MAX_INT = std::numeric_limits<int>::max(); // 2147483647 = 2^31-1
static const long MAX_LONG = std::numeric_limits<long>::max();
static const ll MAX_LL = std::numeric_limits<long long>::max();
static const int INF = (1 << 28);
#define rep(i,n) REP(i,0,n)
#define REP(i,x,n) for(int i=x;i<n;++i)
///////////////////////////////////////////////////
// ------------------- utils ------------------- //
///////////////////////////////////////////////////
// change min/max
template<class T> inline bool chMin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chMax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
ull sumN(const ull N) {
ull ans;
if (N % 2 == 0) {
ans = N /2;
ans *= (N+1);
}
else {
ans = (N+1) /2;
ans *= N;
}
return ans;
}
///////////////////////////////////////////////////
// ------------------- main -------------------- //
///////////////////////////////////////////////////
void Main() {
ull N; cin >> N;
ull ok = 0;
ull ng = 10e10;
while ((ng - ok) > 1) {
ull mid = (ok+ng) / 2;
ull sum = sumN(mid);
if (sum > (N + 1) ) {
ng = mid;
}
else
{
ok = mid;
}
}
cout << N + 1 - ok << endl;
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout << std::fixed << std::setprecision(15);
Main();
double tmp;
cin >> tmp;
return 0;
}
|
#include<iostream>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<cmath>
#include<map>
using namespace std;
#define rep(i,N) for(ll i=0;i<N;i++) //0から
typedef long long ll;
ll binary_search(vector<ll> a, ll n, ll key){
ll right = n, left = -1;
ll md = (right + left) / 2;
while(right - left > 1){
if(a[md] <= key){
right = md;
}else{
left = md;
}
md = (right + left) / 2;
}
if(left == -1) return -1; //無い場合
return right;
}
vector<ll> prime;
void Prime(ll n){ //線形篩,素数列挙
vector<ll> p(n,0);
p[0]=1;
p[1]=1;
for(ll i=2;i<n;i++){
if(p[i]==0){
prime.push_back(i);
p[i]=i;
}
ll k=prime.size();
for(ll j=0;j<k && i*prime[j]<n && prime[j]<=p[i];j++){
p[i*prime[j]]=prime[j];
}
}
}
ll gcd(ll a,ll b){
if(a<b){
swap(a,b);
}
//a>=b
ll r=a%b;
while(r!=0){
a=b;
b=r;
r=a%b;
}
return b;
}
ll modexp(ll x, ll a, ll m){ //x^a mod m
ll ret = 1;
while (a > 0) {
if (a & 1) ret = ret * x % m; // n の最下位bitが 1 ならば x^(2^i) をかける
x = x * x % m;
a >>= 1; // n を1bit 左にずらす
}
return ret;
}
ll modinv(ll a, ll m){ //a^{-1} mod m
ll b=m,u=1,v=0;
while(b){
ll t=a/b;
a-=t*b; swap(a,b);
u-=t*v; swap(u,v);
}
u=(u+m)%m;
return u;
}
#define MOD ((ll)1e+9 + 7)
ll dp[100][10000];
//cout<<fixed<<setprecision(10);
int main(){
int n,a,b;
cin>>n>>a>>b;
cout<<max(0,n-a+b)<<endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int N,A,B;
cin>>N>>A>>B;
cout<<N-A+B<<endl;
} |
// Problem: B - Special Subsets
// Contest: AtCoder - AtCoder Regular Contest 114
// URL: https://atcoder.jp/contests/arc114/tasks/arc114_b
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)
// By AmmarDab3an - Aleppo University
#include "bits/stdc++.h"
using namespace std;
//#define int int64_t
//#define lli int64_t
typedef unsigned int uint;
typedef long long int lli;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<lli, lli> pll;
typedef pair<int, pii> iii;
typedef pair<lli, pll> lll;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
#define endl '\n'
#define fastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define freopenI freopen("input.txt", "r", stdin);
#define freopenO freopen("output.txt", "w", stdout);
const int INF = 0x3f3f3f3f;
const lli INFLL = 0x3f3f3f3f3f3f3f3f;
const int MOD = 998244353;
const double EPS = 1e-9;
const double PI = acos(-1);
const int MAX = 2e5 + 10;
const int NMAX = 2e5 + 10;
const int MMAX = 2e5 + 10;
inline int add(int a, int b){
return ((lli) a + b + MOD + MOD) % MOD;
}
inline int mul(int a, int b){
return ((lli) a * b) % MOD;
}
int fast_pow(int n, int p){
if(!p) return 1;
if(p&1) return mul(n, fast_pow(n, p-1));
int tmp = fast_pow(n, p/2);
return mul(tmp, tmp);
}
int32_t main(){
fastIO;
#ifdef LOCAL
freopenI;
freopenO;
#endif
int n;
cin >> n;
vi vec(n);
for(auto &i : vec) cin >> i;
for(auto &i : vec) i--;
vi vis(n);
int vid = 1;
int cnt = 0;
for(int i = 0; i < n; i++) if(!vis[i]){
cnt++;
vid++;
int t = i;
while(true){
if(vis[t] == vid) break;
if(vis[t]){
cnt--;
break;
}
vis[t] = vid;
t = vec[t];
}
}
cout << add(fast_pow(2, cnt), -1) << endl;
}
| #pragma GCC optimize("O3") //
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, b, a) for(int i = b - 1; i >= a; i--)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef long double ld;
typedef unsigned long long ull;
unsigned seed = chrono::system_clock::now().time_since_epoch().count();
mt19937 eng(seed);
ll random2(){
return (1ll << 31ll)*eng()+eng();
}
ll n,m,k,q,T;
const ll big = 1000000007;
const ll big2 = 1000000009;
const ll mod = 998244353;
const int MAXN = 400001;
vector<int> prio = {0,1,2};
vector<vl> A(3, vl());
ll score(int i, int j){
vector<pll> hej;
trav(a, A[i]){
hej.push_back({a, 0});
}
trav(a, A[j]){
hej.push_back({a, 1});
}
sort(all(hej));
ll ans = big*big;
rep(c1,0,sz(hej)-1){
if(hej[c1].second != hej[c1+1].second){
ans = min(ans, hej[c1+1].first-hej[c1].first);
}
}
return ans;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
//freopen("fhc.txt","r",stdin);
//freopen("autput.txt","w",stdout);
ll a,b,c,d,e;
cin >> n;
rep(c1,0,2*n){
char ch;
cin >> a >> ch;
b = 0;
if(ch == 'G')b = 1;
if(ch == 'B')b = 2;
A[b].push_back(a);
}
ll ans = big*big;
rep(_,0,6){
ll F[3] = {0,0,0};
rep(c1,0,3){
F[c1] = sz(A[prio[c1]]);
}
ll temp = 0;
rep(c1,0,2){
if(F[c1]%2 == 1){
temp += score(prio[c1], prio[c1+1]);
F[c1+1]--;
}
}
ans = min(ans, temp);
next_permutation(all(prio));
}
cout << ans << "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
#define FORA(i,I) for(const auto& i:I)
#define ALL(x) x.begin(), x.end();
#define SIZE(x) ll(x.size())
#define CHMIN(x,y) x = min(x, (y))
#define CHMAX(x,y) x = max(x, (y))
#define YES(b) cout << ((b) ? "Yes" : "No") << endl
int main() {
int n, i = 1, save = 0;
cin >> n;
while (save < n) {
save +=i;
i++;
}
cout << --i << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main(){
int n;
int sum=0;
cin >> n;
for(int i=1; ;i++){
if(((i*i+i)/2)>= n){
cout << i<<endl;
break;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
#define fori(i , a ,b) for (int q = i ; q < a; q +=b )
#define vi vector<int>
typedef long long ll;
const int maxc = 1e9;
void solve() {
//ifstream fin("breedflip.in");
//ofstream fout("breedflip.out");
int a=0, b=0;
cin >> a >> b;
int aa =0, bb=0;
while (a>=10) {aa+=a%10;a/=10;}
while (b>=10) {bb+=b%10;b/=10;}
cout << max(aa+a,bb+b) << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
return 0;
} | #include <bits/stdc++.h>
using namespace std;
inline int S(string n) {
return (n[0] - '0') + (n[1] - '0') + (n[2] - '0');
}
int main() {
string A, B;
cin >> A >> B;
cout << max(S(A), S(B)) << '\n';
return 0;
}
|
#include<cstdio>
#include<algorithm>
#include<cctype>
#include<set>
using namespace std;
#define G getchar()
int read()
{
int x=0; char ch=G;
for (;!isdigit(ch);ch=G);
for (;isdigit(ch);ch=G) x=(x<<3)+(x<<1)+(ch^48);
return x;
}
#undef G
typedef long long ll;
int n,L; //[0,L]
int w[100010],t[100010];
set<int> st;
int que[100010],hd,tl;
ll ans;
int dir[100010];
int main()
{
n=read(),L=read()-n;
for (int i=1;i<=n;i++) w[i]=read()-i;
set<int>(w+1,w+n+1).swap(st);
st.insert(0); st.insert(L);
for (int i=1;i<=n;i++){
int x=t[i]=read()-i;
if (!st.count(x)) return puts("-1"),0;
}
// for (int i=1;i<=n;i++) printf("%d: %d %d\n",i,w[i],t[i]);
for (int i=1;i<=n;i++)
if (t[i]<w[i]) dir[i]=-1;
else if (t[i]>w[i]) dir[i]=1;
for (int i=1,j;i<=n;i=j+1){
for (j=i;j<n&&dir[j+1]==dir[j];j++);
// printf("solve %d %d: %d\n",i,j,dir[i]);
if (dir[i]==0) continue;
if (dir[i]==1){
hd=tl=0;
for (int u=i,v;u<=j;u=v+1){
for (v=u;v<j&&w[v+1]==w[v];v++);
for (int e=u;e<=v;e++) que[++tl]=e;
bool flg=0;
while (hd<tl&&t[que[hd+1]]==w[u]) flg=1,hd++;
if (flg) ans+=tl-hd;
else ans+=v-u+1;
}
}
else{
hd=tl=0;
for (int u=j,v;u>=i;u=v-1){
for (v=u;v>i&&w[v-1]==w[v];v--);
for (int e=u;e>=v;e--) que[++tl]=e;
bool flg=0;
while (hd<tl&&t[que[hd+1]]==w[u]) flg=1,hd++;
if (flg) ans+=tl-hd;
else ans+=u-v+1;
}
}
}
printf("%lld\n",ans);
return 0;
} | #include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#define ll long long int
#define ld long double
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define vpll vector<pair<ll,ll>>
#define prqueue priority_queue<ll,vector<ll>,greater<ll>>// top=small
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define f0(i,n) for(i=0;i<n;i++)
#define f1(i,n) for(i=1;i<=n;i++)
#define fab(i,a,b) for(i=a;i<=b;i++)
#define f0r(i,n) for(i=n-1;i>=0;i--)
#define f1r(i,n) for(i=n;i>=1;i--)
#define fabr(i,a,b) for(i=b;i>=a;i--)
#define memo(a,b) memset(a,b,sizeof(a))
#define display(x) {for(auto dsp:x)cout<<dsp<<" ";cout<<"\n";}
#define hi cout<<"hi\n"
#define yes cout<<"Yes\n"
#define no cout<<"No\n"
#define ln "\n"
using namespace std;
const ld pi=acos(-1);const ll mod=1e9+7;bool debug=false;
int main()
{FAST;ll t=1,n,i,j,k,len,x,y,z,c,f,flag,p,q,mx,mn,l,r,sum,ans,tmp,it,pos,avg,m,cnt;
string s;char ch;vll v;vpll vec;unordered_map<ll,ll> mappu;pair<ll,ll> pr;
// cin>>t;while(t--)
{
n=3;//3
f=0;sum=0;flag=0;ans=0;cnt=0;v.clear();mappu.clear();vec.clear();
ll a[n];
f0(i,n)
{
cin>>tmp;
a[i]=tmp;
// mappu[tmp]++;
}
sort(a,a+n);
if(a[2]-a[1]==a[1]-a[0]) yes;
else no;
// cout<<ans<<ln;
}
return 0;
}
// Either be on top or leave this crap.. |
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cmath>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}
class UnionFind {
private:
vector<int> parent_;
vector<int> node_rank_;
vector<int> sizes_;
public:
UnionFind(int node_num):
parent_(vector<int>(node_num)), node_rank_(vector<int>(node_num)), sizes_(vector<int>(node_num)) {
for (int i = 0; i < node_num; ++i) {
parent_[i] = i;
node_rank_[i] = 0;
sizes_[i] = 1;
}
}
int getRoot(int u) {
return parent_[u] == u ? u : parent_[u] = getRoot(parent_[u]);
}
bool isSame(int u, int v) {
return getRoot(u) == getRoot(v);
}
void unite(int u, int v) {
u = getRoot(u);
v = getRoot(v);
if (u == v) return;
if (node_rank_[u] < node_rank_[v]) {
parent_[u] = v;
sizes_[v] += sizes_[u];
}
else {
parent_[v] = u;
sizes_[u] += sizes_[v];
if (node_rank_[u] == node_rank_[v]) {
node_rank_[u]++;
}
}
}
int getSize(int u) {
return sizes_[getRoot(u)];
}
};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
vector<double> X(N), Y(N);
rep(i, 0, N) {
cin >> X[i] >> Y[i];
}
double l = 0, r = 101;
rep(_, 0, 100) {
double mid = (r + l) / 2;
UnionFind uf(N + 2);
rep(i, 0, N) {
if (Y[i] + mid > 100 - mid) {
uf.unite(i, N);
}
if (Y[i] - mid < -100 + mid) {
uf.unite(i, N + 1);
}
rep(j, i + 1, N) {
if (pow(X[i] - X[j], 2) + pow(Y[i] - Y[j], 2) < 4 * mid * mid) {
uf.unite(i, j);
}
}
}
if (uf.isSame(N, N + 1)) {
r = mid;
} else {
l = mid;
}
}
cout << fixed << setprecision(5) << l << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define LOCAL
#pragma region Macros
typedef long long ll;
#define ALL(x) (x).begin(),(x).end()
const long long MOD=1000000007;
// const long long MOD=998244353;
const int INF=1e9;
const long long IINF=1e18;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
const char dir[4]={'D','R','U','L'};
template<typename T>
istream &operator>>(istream &is,vector<T> &v){
for (T &x:v) is >> x;
return is;
}
template<typename T>
ostream &operator<<(ostream &os,const vector<T> &v){
for (int i=0;i<v.size();++i){
os << v[i] << (i+1==v.size()?"": " ");
}
return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const pair<T,U> &p){
os << '(' << p.first << ',' << p.second << ')';
return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const map<T,U> &m){
os << '{';
for (auto itr=m.begin();itr!=m.end();++itr){
os << '(' << itr->first << ',' << itr->second << ')';
if (++itr!=m.end()) os << ',';
--itr;
}
os << '}';
return os;
}
template<typename T>
ostream &operator<<(ostream &os,const set<T> &s){
os << '{';
for (auto itr=s.begin();itr!=s.end();++itr){
os << *itr;
if (++itr!=s.end()) os << ',';
--itr;
}
os << '}';
return os;
}
void debug_out(){cerr << '\n';}
template<class Head,class... Tail>
void debug_out(Head&& head,Tail&&... tail){
cerr << head;
if (sizeof...(Tail)>0) cerr << ", ";
debug_out(move(tail)...);
}
#ifdef LOCAL
#define debug(...) cerr << " ";\
cerr << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << '\n';\
cerr << " ";\
debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
template<typename T> T gcd(T x,T y){return y!=0?gcd(y,x%y):x;}
template<typename T> T lcm(T x,T y){return x/gcd(x,y)*y;}
template<class T1,class T2> inline bool chmin(T1 &a,T2 b){
if (a>b){a=b; return true;} return false;
}
template<class T1,class T2> inline bool chmax(T1 &a,T2 b){
if (a<b){a=b; return true;} return false;
}
#pragma endregion
struct UnionFind{
int num;
vector<int> par,rank;
UnionFind(int n):num(n),par(n),rank(n,1){
iota(par.begin(),par.end(),0);
}
int root(int x){
return (par[x]==x?x:par[x]=root(par[x]));
}
bool merge(int x, int y){
x=root(x); y=root(y);
if (x==y) return false;
if (rank[x]<rank[y]) swap(x,y);
par[y]=x;
rank[x]+=rank[y];
--num;
return true;
}
bool same(int x, int y){return root(x)==root(y);}
int size(int x){return rank[root(x)];}
int count(){return num;}
};
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
int N; cin >> N;
vector<pair<int,int>> pos;
for (int i=0;i<N;++i){
int x,y; cin >> x >> y;
pos.emplace_back(x,y);
}
auto d=[&](int i,int j){
return (pos[j].first-pos[i].first)*(pos[j].first-pos[i].first)+(pos[j].second-pos[i].second)*(pos[j].second-pos[i].second);
};
auto ud=[&](int i){
return 100-pos[i].second;
};
auto dd=[&](int i){
return pos[i].second+100;
};
auto check=[&](double r){
r*=2;
UnionFind UF(N+2);
for (int i=0;i<N;++i){
for (int j=i+1;j<N;++j){
if (r*r>d(i,j)){
UF.merge(i,j);
}
}
if (r>ud(i)) UF.merge(i,N);
if (r>dd(i)) UF.merge(i,N+1);
}
return !UF.same(N,N+1);
};
double lb=0,ub=100;
for (int _=0;_<300;++_){
double mid=(lb+ub)/2;
(check(mid)?lb:ub)=mid;
}
cout << lb << '\n';
} |
//Bismillah Hir Rehmanir Rahim
//Allah knows best
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#define gap ' '
#include <bitset>
#define mini -10000000000000000
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define endl '\n'
#define f(i, a, n) for( i=a; i<n;i++)
#define ll long long
#define pi 3.141592653589793
#define vi vector<ll>
#define si set<ll>
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rr return 0
#define ff first
#define in insert
#define ss second
ll hash58 = 288230376151711717;
ll hash32 = 1610612741;
#define erase_unique(st) st.erase(unique(st.begin(), st.end()),st.end())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define all(a) a.begin(), a.end()
typedef pair<ll, ll> pii;
#define setbits(x) __builtin_popcountll(x)
#define zrbits(x) __builtin_ctzll(x)
#define unset_bit(x,inx) x = (x & ~(1ll<<(inx)))
#define deb(x) cout << #x << " = " << x << endl
#define set_bit(x, idx) x = x|1LL<<idx
#define check_bit(x, idx) min(x&(1LL<<idx),1LL)
#define toggle_bit(x, idx) x = x^(1LL<<idx)
inline ll uceil(ll a,ll b) {return (a % b ? a / b + 1 : a / b);}
#define multi_ordered_set tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<int, null_type, greater<int>, rb_tree_tag, tree_order_statistics_node_update> rordered_set;
#ifdef DEBUG
#define ok cerr << __LINE__ <<"is done "<<endl;
#else
#define ok
#endif
#define ld long double
ll prm[2000006];
int main()
{
#ifndef DEBUG
ios
#endif
int t=1;
//cin>>t;
int ct=0;
while(t--)
{
ll l, r;
cin >> l >> r;
ll ans = 0;
for(ll i = 2; i <= r; i++)
{
if(prm[i] == 0)
{
for(ll j = i ; j <= r; j += i)
{
prm[j]++;
}
for(ll j = i*i ; j <= r; j += i*i)
{
prm[j] = -1000000007;
}
}
}
for(ll i = 2; i <= r; i++)
{
if(prm[i] < 0)
continue;
ll cc = (r/i) - ((l - 1)/i);
if(prm[i] % 2)
ans += (cc * (cc - 1))/2;
else
ans -= (cc * (cc - 1))/2;
}
for(long long i=max(2ll,l);i<=r;i++){ans -= (r/i-1);}
cout << 2 * ans << endl;
}
rr;
} | #include<bits/stdc++.h>
using namespace std;
int main(){
long long i, n;
cin>>i>>n;
int d=0;
int c=0;
long long r=(n*100)/i;
if((n*100)%i==0) r--;
r+=n;
cout<<r;
} |
/**So..a**/
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define B_ begin()
#define E_ end()
#define all(a) a.begin(), a.end()
#define NL_ "\n"
#define F first
#define S second
#define FF first.first
#define FS first.second
#define SF second.first
#define SS second.second
#define __lcm(a, b) (a/__gcd(a, b)*b)
#define PI acos(-1)
#define EXP 10e-6
#define what_is(x) cerr << #x << " is " << x << endl;
template<typename item>
item abs(item i)
{
if(i < 0) i= -i;
return i;
}
ll mod = 1000000000+7;
template<class typea>
typea POW(typea b, typea p)
{
typea res = 1;
while(p)
{
if(p&1)
{
res*=b;
res%=mod;
}
b*=b;
b%=mod;
p/=2;
}
return res;
}
int tc =0;
#define ull unsigned long long int
#define maxn 2*100000+10
ll arr[maxn];
char a[maxn], b[maxn];
ll n, m, ans;
int main()
{
string s;
cin >> s;
reverse(all(s));
for(auto &x: s) if(x=='9') x = '6'; else if(x=='6') x = '9';
cout <<s;
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
#define PI 3.1415926535
#define maxn 100005
#define all(x) x.begin(),x.end()
#define speedUp ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
void _SSGJ_()
{
string s;
cin>>s;
int n= s.length();
int cnt[26]={0};
int ans=0;
for(int i=n - 1,j=0;i > 0;i--,j++)
{
if(i < n - 1 && i && s[i] == s[i - 1] && s[i] != s[i + 1])
{
ans+=j - cnt[s[i] - 'a'];
for(int it=0;it<26;it++)
cnt[it]=0;
cnt[s[i] - 'a']=j;
}
cnt[s[i] - 'a']++;
}
cout<<ans<<"\n";
}
signed main()
{
speedUp
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
/* int t;
cin>>t;
while(t--)*/
_SSGJ_();
return 0;
} |
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
class Tarjan {
public:
int n;
vector<vector<int>> graph;
stack<int> S;
int clock;
vector<int> timestamp;
vector<int> low;
vector<bool> on_stack;
vector<vector<int>> blocks;
vector<int> belongs;
int n_blocks;
vector<vector<int>> block_graph;
void init(int n_) {
n = n_;
graph.resize(n);
for (int i = 0; i < n; ++i) {
graph[i].clear();
}
}
void add_edge(int u, int v) { graph[u].push_back(v); }
void dfs(int u) {
timestamp[u] = clock;
low[u] = clock;
++clock;
S.push(u);
on_stack[u] = true;
for (int v : graph[u]) {
if (timestamp[v] == -1) {
dfs(v);
low[u] = min(low[u], low[v]);
} else if (on_stack[v]) {
low[u] = min(low[u], timestamp[v]);
}
}
if (low[u] == timestamp[u]) {
vector<int> nodes;
for (;;) {
int w = S.top();
S.pop();
on_stack[w] = false;
nodes.push_back(w);
if (w == u) {
break;
}
}
blocks.push_back(nodes);
}
}
void calc_blocks() {
clock = 0;
timestamp.resize(n, -1);
low.resize(n, -1);
on_stack.resize(n, false);
blocks.clear();
for (int i = 0; i < n; ++i) {
if (timestamp[i] == -1) {
dfs(i);
}
}
}
void build_block_graph() {
n_blocks = blocks.size();
belongs.resize(n, -1);
for (int i = 0; i < n_blocks; ++i) {
for (int u : blocks[i]) {
belongs[u] = i;
}
}
vector<unordered_set<int>> uniq_edge_graph(n_blocks);
for (int u = 0; u < n; ++u) {
for (int v : graph[u]) {
if (belongs[u] != belongs[v]) {
uniq_edge_graph[belongs[u]].insert(belongs[v]);
}
}
}
block_graph.resize(n_blocks);
for (int i = 0; i < n_blocks; ++i) {
block_graph[i].clear();
for (int u : uniq_edge_graph[i]) {
block_graph[i].push_back(u);
}
}
}
long double topological_sort() {
vector<int> in_degree(n_blocks, 0);
vector<int> size(n_blocks, 0);
vector<bitset<100>> ancestors(n_blocks);
for (int u = 0; u < n_blocks; ++u) {
size[u] = blocks[u].size();
ancestors[u].reset();
for (int v : block_graph[u]) {
in_degree[v]++;
}
}
queue<int> Q;
for (int i = 0; i < n_blocks; ++i) {
if (in_degree[i] == 0) {
Q.push(i);
}
}
long double expected_val = 0;
while (!Q.empty()) {
int u = Q.front();
Q.pop();
int count = 0;
for (int i = 0; i < n_blocks; ++i) {
if (ancestors[u][i]) {
count += size[i];
}
}
expected_val += 1.0 * size[u] / (size[u] + count);
for (int v : block_graph[u]) {
ancestors[v] |= ancestors[u];
ancestors[v].set(u);
in_degree[v]--;
if (in_degree[v] == 0) {
Q.push(v);
}
}
}
return expected_val;
}
};
Tarjan tarjan;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << setprecision(20);
int n;
cin >> n;
vector<string> s(n);
for (int i = 0; i < n; ++i) {
cin >> s[i];
}
tarjan.init(n);
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (s[i][j] == '1') {
tarjan.add_edge(i, j);
}
}
}
tarjan.calc_blocks();
tarjan.build_block_graph();
cout << tarjan.topological_sort() << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const int max_n = 111, inf = 1000111222;
int n, f[max_n][max_n];
string s;
int main() {
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> s;
for (int j = 0; j < n; ++j) {
f[i][j] = s[j] - '0';
}
f[i][i] = 1;
}
for (int k = 0; k < n; ++k) {
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
f[i][j] |= f[i][k] & f[k][j];
}
}
}
long double ans = 0;
for (int i = 0; i < n; ++i) {
int cnt = 0;
for (int j = 0; j < n; ++j) {
cnt += f[j][i];
}
ans += 1.0l / cnt;
}
cout << fixed << setprecision(20) << ans << endl;
return 0;
}
|
/**
* created: 09/01/2021, 14:56:06
**/
#include <bits/stdc++.h>
using namespace std;
const int max_n = 111, inf = 1000111222;
const int max_m = max_n * max_n;
int n, m, a[max_n], from[max_m], to[max_m], ans[max_m];
vector<pair<int, int>> g[max_n];
int h[max_n];
void dfs(int v) {
for (auto p : g[v]) {
int id = p.first, tp = p.second;
const int nxt = v ^ from[id] ^ to[id];
if (h[nxt] == -1) {
ans[id] = 0 ^ tp;
h[nxt] = h[v] + 1;
dfs(nxt);
} else if (h[nxt] + 1 < h[v]) {
ans[id] = tp;
}
}
}
int main() {
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
cin >> n >> m;
for (int i = 0; i < m; ++i) {
cin >> from[i] >> to[i];
--from[i];
--to[i];
}
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
for (int i = 0; i < m; ++i) {
if (a[from[i]] != a[to[i]]) {
ans[i] = a[from[i]] < a[to[i]];
} else {
g[from[i]].push_back({i, 0});
g[to[i]].push_back({i, 1});
}
}
memset(h, -1, sizeof(h));
for (int i = 0; i < n; ++i) {
if (h[i] == -1) {
h[i] = 0;
dfs(i);
}
}
for (int i = 0; i < m; ++i) {
if (ans[i] == 0) {
cout << "->\n";
} else {
cout << "<-\n";
}
}
return 0;
}
| #include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC loop-opt(on)
#define rep(i, a, b) for(int i = a; i <= b; i++)
#define rrep(i, a, b) for(int i = b; i >= a; i--)
#define print(x) cout << #x <<" = " << x <<"\n"
#define pprint(x) cout << #x <<" = (" << x.first <<", " << x.second <<")\n"
#define all(x) x.begin(), x.end()
#define ceil(a, b) ((a + b - 1) / (b))
#define INF 1000000000000000000
#define MAXN 200
#define MOD 1000000007
#define eps (1e-9)
#define int long long int
#define lld long double
#define pii pair<int, int>
#define random mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count())
using namespace std;
int n, m, c[MAXN * MAXN], d[MAXN * MAXN];
int ans[MAXN*MAXN], v[MAXN*MAXN];
pii p[MAXN*MAXN];
int mp[MAXN][MAXN], timestamp, a, b;
void dfs(int x) {
d[x] = ++timestamp;
rep(i, 1, n) {
if(c[i] == c[x] && !d[i] && mp[i][x]) {
mp[x][i] = -1, mp[i][x] = -2;
dfs(i);
}
}
return;
}
void solve() {
timestamp = 0;
rep(i, 1, n) {
if(!d[i]) d[i] = 1, dfs(i);
}
rep(i, 1, m) {
tie(a, b) = p[i];
if(c[a] > c[b]) ans[i] = -1;
else if(c[b] > c[a]) ans[i] = -2;
else if(mp[a][b] < 0) ans[i] = mp[a][b];
else ans[i] = (d[a] > d[b] ? -1 : -2);
mp[a][b] = ans[i];
mp[b][a] = -3 - ans[i];
}
return ;
}
int dfs1(int x) {
int cnt = 1; v[x] = 1;
rep(i, 1, n) {
if(!v[i] && mp[x][i] == -1) cnt += dfs1(i);
}
return cnt;
}
bool check() {
rep(i, 1, n) {
memset(v, 0, sizeof(v));
if(dfs1(i) != c[i]) return false;
}
return true;
}
signed main() {
ios::sync_with_stdio(false), cin.tie(0);
cin >> n >> m;
rep(i, 1, m) {
cin >> a >> b;
p[i] = {a, b};
mp[a][b] = mp[b][a] = 1;
}
rep(i, 1, n) cin >> c[i];
solve();
assert(check());
rep(i, 1, m) {
if(ans[i] == -1) cout <<"->\n";
else cout <<"<-\n";
}
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do { cout << "\033[32;1m " << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
sort(v.begin(),v.end());
v.erase(unique(v.begin(),v.end()),v.end());
}
ll rand_int(ll l, ll r) //[l, r]
{
static mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());
return uniform_int_distribution<ll>(l, r)(gen);
}
template<class T>
void print(T x,int suc=1)
{
cout<<x;
if(suc==1) cout<<'\n';
else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
for(int i=0;i<v.size();i++)
print(v[i],i==(int)(v.size())-1?suc:2);
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll n;
cin>>n;
ll t=1000;
int cc=1;
ll ans=0;
while(t*1000<=n)
{
ans+=cc*(t*1000-t);
t*=1000;
cc++;
}
if(n>=t)
ans+=(n-t+1)*cc;
print(ans);
} | #include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a(pow(2, n) / 2);
vector<int> b(pow(2, n) / 2);
for (int i = 0; i < pow(2, n) / 2; i++) {
cin >> a[i];
}
for (int i = 0; i < pow(2, n) / 2; i++) {
cin >> b[i];
}
int maxElementA = *std::max_element(a.begin(), a.end());
int maxElementB = *std::max_element(b.begin(), b.end());
if(maxElementA > maxElementB) {
cout << max_element(b.begin(),b.end()) - b.begin() + a.size() + 1 << endl;
} else {
cout << max_element(a.begin(),a.end()) - a.begin() + 1 << endl;
}
} |
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main() {
int n;
long a[22];
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
long ans = 100000000007;
for (int i = 0; i < (1 << (n - 1)); i++) {
vector<long> vec;
long o = 0;
for (int j = 0; j < n; j++) {
o |= a[j];
if (i & (1 << j)) {
vec.emplace_back(o);
o = 0;
}
}
vec.emplace_back(o);
long co = 0;
for (int j = 0; j < vec.size(); j++) {
co ^= vec[j];
}
if (ans > co) {
ans = co;
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
int n,a[210],dp[210][210],pi[210][210];
void output(int n,int m,int len)
{
if(n==0)
{
cout<<len<<" ";
return;
}
output(pi[n][m],((m-a[n])%200+200)%200,len+1);
cout<<n<<" ";
}
bool check(int i)
{
for(int j=1;j<n;j++)
for(int k=j+1;k<=n;k++)
if(dp[j][i]&&dp[k][i])
{
cout<<"Yes"<<endl;
output(j,i,0);
cout<<endl;
output(k,i,0);
return 1;
}
return 0;
}
bool flag;
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i];
a[i]%=200;
}
dp[0][0]=1;
for(int i=1;i<=n;i++)
for(int j=0;j<200;j++)
for(int k=0;k<i;k++)
if(dp[k][((j-a[i])%200+200)%200])
{
dp[i][j]=1;
pi[i][j]=k;
break;
}
for(int i=0;i<200;i++)
if(check(i))
{
flag=1;
break;
}
if(!flag)
{
for(int i=1;i<n;i++)
if(dp[i][0])
{
cout<<"Yes"<<endl;
output(i,0,1);
cout<<i+1<<endl;
cout<<1<<" "<<i+1;
flag=1;
}
}
if(!flag)cout<<"No";
return 0;
} |
#include <bits/stdc++.h>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define reset(a,v) memset((a), v, sizeof(a))
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
const int N = 3002;
const int MOD = 998244353;
int n, k;
int dp[N][N];
void fillDP() {
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
for (int j = i; j > 0; j--) {
dp[i][j] = (dp[i-1][j-1] + dp[i][min(N-1, 2*j)]) % MOD;
}
}
}
int main() {
scanf("%d %d", &n, &k);
fillDP();
printf("%d\n", dp[n][k]);
return 0;
} | #include "bits/stdc++.h"
#define MOD 998244353
#define rep(i, n) for(ll i=0; i < (n); i++)
#define rrep(i, n) for(ll i=(n)-1; i >=0; i--)
#define ALL(v) v.begin(),v.end()
#define rALL(v) v.rbegin(),v.rend()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define debug_print(var) cerr << #var << "=" << var <<endl;
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" "
#define fi first
#define se second
using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge{ll x, c;};
ll mod(ll a, ll mod){
ll res = a%mod;
if(res<0)res=res + mod;
return res;
}
ll modpow(ll a, ll n, ll mod){
ll res=1;
while(n>0){
if(n&1) res=res*a%mod;
a=a*a%mod;
n>>=1;
}
return res;
}
ll modinv(ll a, ll mod){
ll b=mod, u=1, v=0;
while(b){
ll t=a/b;
a-=t*b; swap(a, b);
u-=t*v; swap(u, v);
}
u%=mod;
if(u<0)u+=mod;
return u;
}
ll gcd(ll a, ll b){
ll r = a%b;
if(r==0) return b;
else return gcd(b, a%b);
}
bool is_prime(ll n){
ll i = 2;
if(n==1)return false;
if(n==2)return true;
bool res = true;
while(i*i <n){
if(n%i==0){
res = false;
}
i = i+1;
}
//if(i==1)res = false;
if(n%i==0)res=false;
return res;
}
ll N, K;
vector<llvec> m;
ll f(ll n, ll k){
//cerr << n << " " << k << " ";
if(k<=0)return 0;
if(n<=0 or k<=0 or n<k){
m[n][k] = 0;
return 0;
}
if(n==k)m[n][k]=1;
if(m[n][k]>=0)return m[n][k];
ll tmp=0;
tmp = mod(f(n-1, k-1) + f(n, 2*k), MOD);
//cerr << tmp << endl;
m[n][k]=tmp;
return tmp;
}
/**************************************
** A main function starts from here **
***************************************/
int main(){
cin >> N >> K;
m = vector<llvec>(N+1, llvec(2*(N+1), -1));
cout << f(N, K);
return 0;
}
|
Subsets and Splits