code_file1
stringlengths 87
4k
| code_file2
stringlengths 82
4k
|
---|---|
//Author:RingweEH
#include <cstdio>
#include <algorithm>
#include <cstring>
#define ll long long
#define db double
using namespace std;
int min( int a,int b ) { return (a<b) ? a : b; }
int max( int a,int b ) { return (a>b) ? a : b; }
void bmin( int &a,int b ) { a=(a<b) ? a : b; }
void bmax( int &a,int b ) { a=(a>b) ? a : b; }
int read()
{
int x=0,w=1; char ch=getchar();
while ( ch>'9' || ch<'0' ) { if ( ch=='-' ) w=-1; ch=getchar(); }
while ( ch<='9' && ch>='0' ) { x=x*10+ch-'0'; ch=getchar(); }
return x*w;
}
int n,k;
int calc( int x )
{
int res=0;
for ( ; x; x-=((x)&(-x)) ) res++;
return res;
}
int main()
{
//freopen( "exam.in","r",stdin );
n=read(); int cnt=1<<n;
printf( "%d\n",cnt-1 );
for ( int i=1; i<cnt; i++ )
{
for ( int j=0; j<cnt; j++ )
if ( calc(i&j)&1 ) printf( "B" );
else printf( "A" );
printf( "\n" );
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)
template<class T1, class T2> inline bool chmax(T1 &a, const T2 &b) {if (a<b) { a=b; return 1;} return 0;}
template<class T1, class T2> inline bool chmin(T1 &a, const T2 &b) {if (b<a) { a=b; return 1;} return 0;}
struct init{init(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}}init_;
#ifdef DEBUG
template <class T> void verr(const set<T> &st) { repa(a, st) cerr << a << " "; cerr << endl; }
template <class S, class T> void verr(const map<S, T> &mp) { repa(a, mp) cerr << "{" << a.first << ", " << a.second << "} "; cerr << endl; }
template <class S, class T, class N> void verr(const vector<pair<S,T>>& a, const N& n) { rep(i, n) cerr << "{" << a[i].first << ", " << a[i].second << "} "; cerr << endl; }
template <class T, class N> void verr(const vector<T>& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << endl; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << endl; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif
const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
// Binary Indexed Tree (Fenwick Tree)
template <typename T>
struct BIT {
ll n;
vector<T> d;
BIT(ll n = 0) : n(n), d(n + 1) {}
void add(ll i, T x = 1) {
for (i++; i <= n; i += i & -i) {
d[i] += x;
}
}
T sum(ll i) {
T x = 0;
for (i++; i; i -= i & -i) {
x += d[i];
}
return x;
}
};
int main() {
ll N;
cin >> N;
vl A(N);
rep(i, N) cin >> A[i];
ll ans = 0;
BIT<ll> bt(N);
rep(i, N){
bt.add(A[i]);
ans += bt.sum(N - 1) - bt.sum(A[i]);
}
cout << ans << '\n';
rep(i, N - 1){
ans += N - 1 - A[i] * 2;
cout << ans << '\n';
}
} |
#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 ll;
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class A> ostream& operator<<(ostream &cout, vector<A> const &v) {cout << "["; for(int i = 0; i < (int)v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]";};
template<class A, class B> ostream& operator<<(ostream &cout, const pair<A,B> &x) {return cout << "(" <<x.first << ", " << x.second << ")";};
template<class T> void pv(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;}cerr << "]\n";}
void _print() {cerr << "]\n";}
template<class T, class... V> void _print(T t, V... v) {cerr << t; if (sizeof...(v)) cerr << ", "; _print(v...);}
#define debug(x...) cerr << "[" << #x << "] = [", _print(x)
#define fi first
#define se second
#define SZ(x) (int)((x).size())
#define pii pair<int,int>
#define uid(x,y) uniform_int_distribution<int>(x,y)(rng)
vector<array<int,2>> qu[25];
vector<int> msk[25];
ll dp[25][1<<20];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n,m;
cin >> n >> m;
for (int q = 0; q < m; q++) {
int x,y,z;
cin >> x >> y >> z;
y--;
qu[x].push_back({y,z});
}
for (int q = 1; q < (1<<20); q++) msk[__builtin_popcount(q)].push_back(q);
dp[0][0] = 1;
for (int q = 1; q <= n; q++) {
for (int w : msk[q]) {
bool ok = true;
for (array<int,2> a : qu[q]) {
int y = (1<<(a[0]+1))-1;
if (__builtin_popcount(y&w) > a[1]) ok = false;
}
if (ok) {
for (int e = 0; e < n; e++) {
if ((w>>e)&1) dp[q][w] += dp[q-1][w^(1<<e)];
}
}
}
}
cout << dp[n][(1<<n)-1] << '\n';
return 0;
}
| #include<fstream>
#include<iostream>
#include<sstream>
#include<vector>
#include<stack>
#include<string>
#include<algorithm>
#include<cmath>
#include<map>
#include<queue>
#include<tuple>
#include<iomanip>
#include<bitset>
#include<stdio.h>
#include<set>
#include<array>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using graph = vector<vector<long long>>;
const long long MOD = 1000000007;
const long long INF = 1e18;
using ll = long long;
using P = pair<int,int>;
void chmin(int &x,int y){ x = min(x,y); }
int digit(ll x){
int count = 1;
while(x/10>0){
count ++;
x /= 10;
}
return count;
}
bool prime(ll x){
if(x==1) return false;
for(ll i=2;i*i<=x;i++){
if(x%i==0) return false;
}
return true;
}
void decom(ll x,map<ll,int> &hatano){
for(ll i=2;i*i<=x;i++){
if(x%i==0&&prime(i)){
while(x%i==0){
x /= i;
hatano[i] ++;
}
}
}
if(x!=1) hatano[x] ++;
}
ll speedpow(ll x,ll y){
ll res = 1;
ll test = x;
for(int i=0;i<31;i++){
if(y&(1<<i)) res *= test;
res = res%MOD;
test = (test*test)%MOD;
}
return res;
}
ll combination(ll x,ll y){
ll test = 1;
ll test1 = 1;
for(ll i=0;i<y;i++){
test = (test*(x-i))%MOD;
test1 = (test1*(i+1LL))%MOD;
}
return (test * speedpow(test1,MOD-2))%MOD ;
}
int euclid(int x,int y){
if(y==0) return x;
return euclid(y,x%y);
}
int main(){
int n,m;cin >> n >> m;
int x[m],y[m],z[m];
rep(i,m) cin >> x[i] >> y[i] >> z[i];
ll k = (1LL<<n);
vector<ll> dp(k,0);
dp[0] = 1;
for(ll bit=0;bit<k;bit++){
rep(j,n){
if(bit&(1LL<<j)) continue;
bool ara = true;
ll test = (bit|(1LL<<j));
rep(l,m){
int p = __builtin_popcount(test);
if(x[l]!=p) continue;
int count = 0;
rep(m,n){
if((test&(1LL<<m))&&(m+1<=y[l])) count ++;
// if(j+1<=y[l]) count ++;
}
if(count>z[l]) ara = false;
// cout << p << " " << x[l] << " " << bit <<endl;
}
if(ara) dp[bit|(1LL<<j)] += dp[bit];
}
}
//cout << pow(2,18)*18*100 << endl;
cout << dp[k-1] << endl;
}
|
#include<iostream>
using namespace std;
int main()
{
int v,t,s,d,s1,s2;
cin>>v>>t>>s>>d;
s1=t*v;
s2=v*s;
if(d>=s1&&d<=s2)
cout<<"No";
else
cout<<"Yes";
return 0;
}
| #include <iostream>
using namespace std;
int main()
{
int a[4];
char flag = 0;
cin >> a[0] >> a[1] >> a[2] >> a[3];
int sum = 0;
for (int i = 0; i < 4; i++) {
sum += a[i];
}
bool find = false;
if (sum % 2 == 0)
{
for (int i = 0; i < 8; i++)
{
int sub = a[3];
if ((i & (1 << 0)) != 0)
sub += a[0];
if ((i & (1 << 1)) != 0)
sub += a[1];
if ((i & (1 << 2)) != 0)
sub += a[2];
if (sub * 2 == sum)
find = true;
if (find)break;
}
}
if (find)
{
cout << "Yes";
}
else
{
cout << "No";
}
return 0;
} |
#include <bits/stdc++.h>
// #include <atcoder/all>
// #include "icld.cpp"
using namespace std;
using ll = long long int;
using vi = vector<int>;
using si = set<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using ss = string;
using db = double;
template<typename T> using minpq = priority_queue <T,vector<T>,greater<T>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
#define V vector
#define P pair<int,int>
#define PLL pair<ll,ll>
#define rep(i,s,n) for(int i=(s);i<(int)(n);i++)
#define rev(i,s,n) for(int i=(s);i>=(int)(n);i--)
#define reciv(v,n) vi (v)((n)); rep(i,0,(n))cin>>v[i]
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define ci(x) cin >> x
#define cii(x) ll x;cin >> x
#define cci(x,y) ll x,y;cin >> x >> y
#define co(x) cout << x << endl
#define pb push_back
#define eb emplace_back
#define rz resize
#define pu push
#define sz(x) int(x.size())
#define vij v[i][j]
// ll p = 1e9+7;
// ll p = 998244353;
#define yn cout<<"Yes"<<endl;else cout<<"No"<<endl
#define YN cout<<"YES"<<endl;else cout<<"NO"<<endl
template<class T>void chmax(T &x,T y){x=max(x,y);}
template<class T>void chmin(T &x,T y){x=min(x,y);}
ll g(ll n, int now){
ss s=to_string(n);
if(now==0)sort(all(s));
else sort(rall(s));
ll x=stoll(s);
return x;
}
ll f(ll n){
return g(n,1)-g(n,0);
}
int main(){
cci(n,k);
while(k--)n=f(n);
co(n);
} | #include<stdio.h>
#include<bits/stdc++.h>
#include<math.h>
#include<stdlib.h>
#include<stdbool.h>
#include<vector>
#define ll long long
#define pb push_back
#define inp(x) scanf("%d",&x);
#define input(x) scanf("%lld",&x);
#define tc int t;scanf("%d",&t);while(t--)
using namespace std;
//Functions
int MaxNum(int num)
{
int count[10] = {0};
string str = to_string(num);
for (int i=0; i<str.length(); i++)
count[str[i]-'0']++;
int result = 0, multiplier = 1;
for (int i = 0; i <= 9; i++)
{
while (count[i] > 0)
{
result = result + (i * multiplier);
count[i]--;
multiplier = multiplier * 10;
}
}
return result;
}
int MinNum(int num)
{
int count[10] = {0};
string str = to_string(num);
for (int i=0; i<str.length(); i++)
count[str[i]-'0']++;
int result = 0, multiplier = 1;
for (int i = 9; i >= 0; i--)
{
while (count[i] > 0)
{
result = result + (i * multiplier);
count[i]--;
multiplier = multiplier * 10;
}
}
return result;
}
int main()
{
int n,k;
cin >> n >>k;
int temp = n;
while(k--)
{
temp = MaxNum(temp) - MinNum(temp);
if(temp == 0) break;
}
cout << temp;
} |
/*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(n);
ll cnt=0;
reps(i,1,n+1){
if(2*n<i*i+1){
//out(i);
break;
}
if((2*n)%i==0){
if(((2*n)/i+1-i)%2==0)cnt++;
}
}
out(cnt*2);
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;
using P = pair<ll, ll>;
const ll INF = 1001001001;
int main() {
ll N; cin >> N;
vector<vector<ll>> C(N, vector<ll>(N));
vector<ll> A(N), B(N);
// (最小値, 最小値が含まれる行数) を表す Pair
P min_val(INF, 0);
rep(i, N) rep(j, N) {
ll val;
cin >> val;
if (min_val.first > val) {
min_val = make_pair(val, i);
}
C[i][j] = val;
}
bool ok = true;
A[min_val.second] = min_val.first;
for (ll i = 0; i < N; i++) {
B[i] = C[min_val.second][i] - A[min_val.second];
}
for (ll i = 0; i < N; i++) {
A[i] = C[i][0] - B[0];
}
rep(i, N) rep(j, N) {
if (C[i][j] != A[i] + B[j]) ok = false;
// if (A[i] < 0 || B[j] < 0) ok = false;
}
if (ok) {
cout << "Yes" << endl;
rep(i, N) cout << A[i] << endl;
rep(i, N) cout << B[i] << endl;
}
else cout << "No" << endl;
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define debug(x) cerr << #x << ": " << x << "\n";
int N;
vector<int> P, iP;
bool solve(int left, vector<int> &res){
if(res.size() == N-1){
rep(i, N){
if(P[i] != i){
return false;
}
}
return true;
}
if(iP[left] <= left){
return false;
}
for(int j = iP[left]; j > left; j--){
res.push_back(j);
swap(P[j], P[j-1]);
}
for(int j = left; j < iP[left]; j++){
if(P[j] != j){
return false;
}
}
return solve(iP[left], res);
}
int main(){
cin>>N;
P.resize(N);
iP.resize(N);
rep(i, N){
cin>>P[i], P[i]--, iP[P[i]] = i;
}
vector<int> res;
if(!(solve(0, res))){
cout<<-1<<endl;
}else{
for(auto r : res){
cout<<r<<endl;
}
}
return 0;
} | #include<iostream>
#include<bits/stdc++.h>
#define mod 1000000007
#define int long long
#define pii pair<int,int>
#define pb(x) push_back(x)
#define lbound lower_bound
#define ubound upper_bound
#define gcd(a,b) __gcd(a,b)
#define all(v) v.begin(),v.end()
#define bits(x) __builtin_popcountll(x)
#define heap_min priority_queue<int,vector<int>,greater<int>>
#define heap_max priority_queue<int>
#define precision(x) cout << setprecision(x) << fixed;
#define printv(v) for(auto p : v) cout << p << " ";
#define printa(a,n) for(int i = 0 ; i < n ; i++) cout << a[i] << " ";
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
void solve()
{
int n;
cin >> n;
if(n%2){
cout << "Black";
}
else{
cout << "White";
}
}
int32_t main()
{
fast;
#ifndef ONLINE_JUDGE
freopen("goodluckin.txt","r",stdin);
freopen("goodluckout.txt","w",stdout);
#endif
clock_t beg = clock();
solve();
clock_t end = clock();
fprintf(stderr, "Time taken : %.3f sec\n", double(end - beg) / CLOCKS_PER_SEC , 184);
return 0;
}
|
#include <iostream>
#include <set>
#include <iterator>
#include <bitset>
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod=1000000007;
int main() {
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int t;
cin>>t;
while(t--){
int n;
cin>>n;
string s;
for(int i=0;i<3;i++ )
{
cin>>s;
}
string ans;
for(int i=0;i<n;i++)
ans.push_back('0');
for(int i=0;i<n;i++)
ans.push_back('1');
ans.push_back('0');
cout<<ans<<endl;
}
return 0;
}
| #pragma GCC optimize ("Ofast")
#pragma GCC optimization ("unroll-loops, no-stack-protector")
#pragma GCC target ("avx")
#pragma GCC target ("avx2")
#pragma GCC target ("fma")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define pll pair <ll, ll>
#define pci pair <char, int>
#define pld pair <ld, ld>
#define ppld pair <pld, pld>
#define ppll pair <pll, pll>
#define pldl pair <ld, ll>
#define vll vector <ll>
#define vvll vector <vll>
#define vpll vector <pll>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define mll map <ll, ll>
#define fastmap gp_hash_table
#define cd complex <double>
#define vcd vector <cd>
#define PI 3.14159265358979
#define ordered_set tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update>
#pragma 03
using namespace std;
using namespace __gnu_pbds;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
void solve(){
ll n; cin >> n;
string s1, s2, s3; cin >> s1 >> s2 >> s3;
string ans; ans.resize(2 * n + 1);
ans[0] = '1';
for (ll i = 1; i <= n; i++) ans[i] = '0';
for (ll i = n + 1; i <= 2 * n; i++) ans[i] = '1';
cout << ans << "\n";
}
int main(){
fastio;
ll t; cin >> t;
while (t--) solve();
} |
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <cassert>
#include <stack>
#include <numeric>
typedef int64_t ll;
typedef std::pair<int, int> Pii;
typedef std::pair<ll, ll> Pll;
typedef std::pair<double, double> Pdd;
#define rip(i, n, _s) for (int i = (_s);i < (int)( n ); i++)
#define all(_l) _l.begin(), _l.end()
#define rall(_l) _l.rbegin(), _l.rend()
#define MM << " " <<
template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template<typename T>
inline bool chmax(T &_l, const T b) {
if (_l < b) {
_l = b;
return true;
}
return false;
}
template<typename T>
inline bool chmin(T &_l, const T b) {
if (_l > b) {
_l = b;
return true;
}
return false;
}
# ifdef LOCAL_DEBUG
template<typename T>
void vdeb(const std::vector<T> &bb) {
for (unsigned int i = 0;i < bb.size();i++) {
if (i == bb.size() - 1) std::cout << bb[i];
else std::cout << bb[i] << ' ';
}
std::cout << '\n';
}
template<typename T>
void vdeb(const std::vector<std::vector<T>> &bb) {
for (unsigned int i = 0;i < bb.size();i++) {
std::cout << i << ' ';
vdeb(bb[i]);
}
std::cout << '\n';
}
# endif
using namespace std;
void bfs(vector<vector<int>> &da, vector<int> &ans, vector<int> &c,int from) {
int n = da.size();
vector<int> used(n, -1);
queue<Pii> q;
q.push({from, 0});
while(!q.empty()) {
Pii now = q.front(); q.pop();
if(used[now.first] != -1) {
continue;
}
used[now.first] = now.second;
rip(i,da[now.first].size(),0) {
q.push({da[now.first][i], now.second+1});
}
}
rip(i,c.size(),0) ans[i] = used[c[i]];
return;
}
int main() {
int n, m; cin >> n >> m;
vector<vector<int>> da(n, vector<int>(0));
rip(i,m,0) {
int a, b; cin >> a >> b;
--a;--b;
da[a].push_back(b);
da[b].push_back(a);
}
int k; cin >> k;
vector<int> c(k);
rip(i,k,0) {
cin>> c[i];
c[i]--;
}
vector<vector<int>> dist(k, vector<int>(k, -1));
rip(i, k, 0) bfs(da, dist[i], c, c[i]);
rip(i,k,0) {
rip(j,k,0) {
if(dist[i][j] == -1) {
cout << -1 << endl;
return 0;
}
}
}
vector<vector<int>> dp(1<<k, vector<int>(k, INT_MAX/2));
rip(i,k,0) {
dp[1<<i][i] = 0;
}
rip(i,1<<k,0) {
rip(j,k,0) {
if((i>>j)&1) {
rip(l,k,0) {
if((i>>l)&1) {
chmin(dp[i][j], dp[i^(1<<j)][l] + dist[l][j]);
}
}
}
}
}
int ans = INT_MAX;
rip(i,k,0) {
chmin(ans, dp.back()[i]);
}
// vdeb(dp);
cout << ans+1 << endl;
} | #include "bits/stdc++.h"
using namespace std;
#ifdef LOCAL
#include "debug.h"
#define input freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#else
#define debug(...) 4
#define input 4
#endif
using ll = long long;
//const int mod = 998244353;
const int mod = 1e9 + 7;
const int N = 2e5 + 5;
struct DSU {
int par[N];
int sz[N];
int find(int x) {
return x == par[x] ? x : par[x] = find(par[x]);
} //path compression(logn)
void merge(int a, int b) {
a = find(a);
b = find(b);
if(a == b) return;
if(sz[a] < sz[b])
swap(a, b);
sz[a] += sz[b];
par[b] = a;
}
void init(int n) {
for(int i = 0; i <= n; i++)
par[i] = i, sz[i] = 1;
}
};
DSU d;
vector<int> g[N];
vector<int> dist[N];
int a[N];
void bfs(vector<int> &dist, int src) {
queue<int> q;
q.push(src);
dist[src] = 0;
while(q.size()) {
int at = q.front();
q.pop();
for(int j : g[at]) {
if(dist[j] == -1) {
dist[j] = dist[at] + 1;
q.push(j);
}
}
}
}
int dp[1 << 18][18];
int k;
int solve(int mask, int last) {
if(mask == (1 << k) - 1) {
return 0;
}
if(~dp[mask][last])
return dp[mask][last];
int ans = 1e9;
for(int j = 0; j < k; j++) {
if(mask & (1 << j))
continue;
ans = min(ans, dist[last][a[j]] + solve(mask ^ (1 << j), j));
}
return dp[mask][last] = ans;
}
signed main() {
input;
cin.tie(nullptr) -> sync_with_stdio(false);
int t = 1;
// cin >> t;
while(t--) {
int n, m;
cin >> n >> m;
d.init(n + 1);
for(int i = 0; i < m; i++) {
int x, y;
cin >> x >> y;
g[x].push_back(y);
g[y].push_back(x);
d.merge(x, y);
}
cin >> k;
set<int> s;
for(int i = 0; i < k; i++) {
cin >> a[i];
s.insert(d.find(a[i]));
}
if(s.size() > 1) {
cout << "-1\n";
return 0;
}
for(int i = 0; i < k; i++) {
vector<int> temp(n + 1, -1);
bfs(temp, a[i]);
dist[i] = temp;
}
int ans = 1e9;
for(int i = 0; i < k; i++) {
memset(dp, -1, sizeof dp);
ans = min(ans, solve(1 << i, i));
}
cout << ans + 1;
}
}
|
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <algorithm>
#include <set>
using namespace std;
#define rep(i,s,N) for(unsigned int i=s;i<N;i++)
typedef long long int lli;
int main(void)
{
int N, S, D; cin >> N >> S >> D;
vector<int> X(N), Y(N);
rep(i, 0, N)cin >> X[i] >> Y[i];
string ans = "No";
rep(i, 0, N) {
if (X[i]<S && Y[i]>D) {
ans = "Yes";
break;
}
}
cout << ans << endl;
return 0;
} | //
#include<bits/stdc++.h>
using namespace std;
#define PB push_back
#define f first
#define s second
#define what_is(x) cerr << #x << " is " << x << endl;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
const int INF = 1000000007;
const ll MOD = 1000000007;
vector<pii> graph[301];
int dist[301];
bool seen[301];
void dijkstra(int src)
{
for(int i=0; i<300; i++)
{
dist[i] = INF;
}
dist[src] = 0;
priority_queue<pair<int, int>> pq;
pq.push({0, src});
while(!pq.empty())
{
int u = pq.top().s;
pq.pop();
for(int i=0; i<graph[u].size(); i++)
{
int v = graph[u][i].f;
int w = graph[u][i].s;
if(dist[v] > dist[u] + w)
{
dist[v] = dist[u] + w;
if(!seen[v])
pq.push({-dist[v], v});
}
}
}
}
void solve_test()
{
int a, b, x, y;
cin >> a >> b >> x >> y;
for(int i=1; i<=100; i++)
{
graph[i].PB({i+100, x});
graph[i+100].PB({i, x});
if(i<100)
{
graph[i+1].PB({i, y});
graph[i].PB({i+1, y});
graph[i+101].PB({i+100, y});
graph[i+100].PB({i+101, y});
}
if(i>1)
{
graph[i].PB({i+99, x});
graph[i+99].PB({i, x});
}
}
dijkstra(a);
cout << dist[b+100];
}
signed main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
int tests;
tests = 1;
//cin >> tests;
while(tests--)
{
solve_test();
}
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
int A,B,C;
cin >> A >> B >> C;
if (A < 0 && C%2 == 0)
{
A *= (-1);
}
if(B < 0 && C%2 == 0)
{
B *= (-1);
}
if(A < B)
{
cout << "<" << endl;
}
else if(A > B)
{
cout << ">" << endl;
}
else if (A == B)
{
cout << "=" << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, a, n) for (int i = (a); i < (int) (n); ++i)
#define MOD 1000000007
int main() {
ll A, B, C;
cin >> A >> B >> C;
char ans;
if(C % 2 == 0) {
A = abs(A);
B = abs(B);
}
if(A == B) ans = '=';
else if(A > B) ans = '>';
else if(A < B) ans = '<';
cout << ans << endl;
return 0;
} |
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
using namespace std;
void dfs(int v, int other, vector<vector<pair<int, int>>>& Graph, vector<bool> &seen, vector<int> &color, int N) {
if (v == 0) {
if (Graph[v].size() > 0) color[0] = Graph[v][0].second;
}
else if (color[v] == -1) {
color[v] = (other + 1) % N;
}
for (int i = 0; i < Graph[v].size(); i++) {
if (seen[Graph[v][i].first]) continue;
if (Graph[v][i].second == color[v]) {
seen[Graph[v][i].first] = true;
dfs(Graph[v][i].first, Graph[v][i].second, Graph, seen, color, N);
}
else {
seen[Graph[v][i].first] = true;
color[Graph[v][i].first] = Graph[v][i].second;
dfs(Graph[v][i].first, N, Graph, seen, color, N);
}
}
}
int main() {
int N, M;
cin >> N >> M;
vector<vector<pair<int, int>>> Graph(N);
for (int i = 0; i < M; i++) {
int u, v, c;
cin >> u >> v >> c;
u--; v--; c--;
Graph[u].push_back(make_pair(v, c));
Graph[v].push_back(make_pair(u, c));
}
vector<bool> seen(N, false);
seen[0] = true;
vector<int> color(N, -1);
dfs(0, N, Graph, seen, color, N);
for (int i = 0; i < N; i++) {
cout << color[i] + 1 << endl;
}
} | #include <bits/stdc++.h>
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define RI register int
typedef long long LL;
#define FILEIO(name) freopen(name".in", "r", stdin), freopen(name".out", "w", stdout);
using namespace std;
namespace IO {
char buf[1000000], *p1 = buf, *p2 = buf;
inline char gc() {
if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin);
return p1 == p2 ? EOF : *(p1++);
}
template <class T> inline void read(T &n) {
n = 0; RI ch = gc(), f;
while ((ch < '0' || ch > '9') && ch != '-') ch = gc();
f = (ch == '-' ? ch = gc(), -1 : 1);
while (ch >= '0' && ch <= '9') n = n * 10 + (ch ^ 48), ch = gc();
n *= f;
}
char Of[105], *O1 = Of, *O2 = Of;
template <class T> inline void print(T n, char ch = '\n') {
if (n < 0) putchar('-'), n = -n;
if (n == 0) putchar('0');
while (n) *(O1++) = (n % 10) ^ 48, n /= 10;
while (O1 != O2) putchar(*(--O1));
putchar(ch);
}
}
using IO :: read;
using IO :: print;
int const MAXN = 2e5 + 5;
struct Edges { int to, next, val; } e[MAXN << 1];
int vis[MAXN], a[MAXN];
int head[MAXN], tot;
int n, m;
inline void addedge(int from, int to, int val) {
e[++tot] = (Edges){to, head[from], val};
head[from] = tot;
e[++tot] = (Edges){from, head[to], val};
head[to] = tot;
}
void Dfs(int now) {
vis[now] = 1;
for (RI i = head[now]; i; i = e[i].next)
if (!vis[e[i].to]) {
if (a[now] == e[i].val)
a[e[i].to] = n + 1 - e[i].val;
else
a[e[i].to] = e[i].val;
Dfs(e[i].to);
}
}
int main() {
#ifdef LOCAL
FILEIO("a");
#endif
read(n), read(m);
for (RI i = 1, x, y, z; i <= m; ++i)
read(x), read(y), read(z), addedge(x, y, z);
a[1] = 1;
Dfs(1);
for (RI i = 1; i <= n; ++i)
if (!vis[i])
return puts("No"), 0;
for (RI i = 1; i <= n; ++i)
printf("%d\n", a[i]);
return 0;
}
// created by Daniel yuan
/*
________
/ \
/ / \ \
/ / \ \
\ /
\ ______ /
\________/
*/
|
#include <cstdio>
#include <algorithm>
const int Maxn=200000;
int n;
std::pair<int,int> a[Maxn<<1|5];
bool col[Maxn<<1|5];
int main(){
scanf("%d",&n);
for(int i=1;i<=(n<<1);i++){
scanf("%d",&a[i].first);
a[i].second=i;
}
std::sort(a+1,a+1+(n<<1));
for(int i=1;i<=n;i++){
col[a[i].second]=1;
}
int num=0;
for(int i=1;i<=(n<<1);i++){
if(col[i]){
if(num>=0){
num++;
putchar('(');
}
else{
num++;
putchar(')');
}
}
else{
if(num<=0){
num--;
putchar('(');
}
else{
num--;
putchar(')');
}
}
}
putchar('\n');
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[200050];
const int mod =998244353;
ll l[200050];
ll in[200050];
ll sum[200050];
ll pow_mod(ll a, ll n, ll m)
{
long long ans = 1;
while(n){
if(n&1){
ans = (ans * a) % m;
}
a = (a * a) % m;
n >>= 1;
}
return ans;
}
void run()
{
ll n;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
sort(a+1,a+1+n);
ll ans=0ll;
in[0]=1ll;
in[1]=1ll;
sum[0]=0;
ll x=1;
for(int i =1;i<=n;i++)
{
sum[i]=sum[i-1]+x*a[i]%mod;
sum[i]%=mod;
x =x*2;
x%=mod;
}
ll inv = pow_mod(2,mod-2,mod);
ll y =inv;
for(int i=1;i<=n;i++)
{
ans+= a[i]*(sum[n]-sum[i]+mod)%mod*y%mod;
ans%=mod;
y*=inv;
y%=mod;
}
for(int i=1;i<=n;i++)
ans=(ans+a[i]*a[i]%mod)%mod;
cout<<ans<<endl;
}
int main()
{
int t=1;
while(t--)
run();
}
|
#include<iostream>
#include<vector>
int main(){
int N, K;
std::cin >> N >> K;
std::vector<long long> sum(2*N+2,0);
for(int a=1; a<=N; a++){
sum[a+1] += 1;
sum[a+N+1] -= 1;
}
for(int i=0; i<2*N+1; i++){
sum[i+1] += sum[i];
}
long long ans = 0;
if (K < 0) K *= -1;
for(int i=0; i<2*N+1; i++){
if (i+K > 2*N) break;
ans += sum[i] * sum[i + K];
}
std::cout << ans << std::endl;
}
| #include <iostream>
using namespace std;
int main(void){
// Your code here!
long long n;
cin>>n;
int k;
cin>>k;
for(int i=0;i<k;i++){
if(n%200==0) n/=200;
else{
n*=1000;
n+=200;
}
}
cout<<n<<endl;
return 0;
}
|
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,abm,mmx,avx,avx2")
#pragma GCC optimize("unroll-loops")
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define req(i,a,b) for(int i=(a);i>=(b);--i)
#define rep_(i,a,b) for(int i=(a);i<(b).size();++i)
#define F(a) rep(a,1,n)
#define M(a,b) memset(a,b,sizeof a)
#define DC int T;cin>>T;while(T--)
#define ll long long
#define Z(a,b) sort(a+1,a+b+1)
using namespace std;
const unsigned _mod=998244353;
const unsigned mod=1e9+7;
const ll infi=0x3f3f3f3f3f3f3fll;
const int inf=0x3f3f3f3f;
void rd(auto &x){x=0;int f=1;char ch=getchar();while(ch<48||ch>57){if(ch==45)f=-1;ch=getchar();}while(ch>=48&&ch<=57)x=x*10+ch-48,ch=getchar();x*=f;}
ll ksm(ll x,ll y=mod-2,ll m=mod){ll ret=1;while(y){if(y&1)ret=ret*x%m;y>>=1ll;x=x*x%m;}return ret;}
ll qpow(ll x,ll y){ll ret=1;while(y){if(y&1ll)ret=ret*x;y>>=1ll;x=x*x;}return ret;}
/*
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
*/
ll n,a[110],dp[110][110][110],x,ans=1e18+17;
int main()
{
cin>>n>>x;
F(i) rd(a[i]);
F(i)
{
ll p=x%i;
rep(j1,0,109) rep(j2,0,109) rep(j3,0,109) dp[j1][j2][j3]=-infi;
dp[0][0][0]=0;
F(j)
{
F(__) rep(_,0,i-1) if (dp[j-1][__-1][_]!=-infi) if (dp[j-1][__-1][_]+a[j]<=x) dp[j][__][(_+a[j])%i]=max(dp[j][__][(_+a[j])%i],dp[j-1][__-1][_]+a[j]);
F(__) rep(_,0,i-1) if (dp[j][__][_]!=-infi) dp[j+1][__][_]=max(dp[j+1][__][_],dp[j][__][_]);
}
if (dp[n][i][p]!=-infi) ans=min(ans,(x-dp[n][i][p])/i);
//cerr<<dp[n][i][p]<<'\n';
}
cout<<ans<<'\n';
return 0;
} | #pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
#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 N, X;
cin >> N >> X;
ll A[100];
rep(i, N) cin >> A[i];
ll kotae = 2e18;
rep1(s, N) {
ll wari = X / s;
ll amari = X % s;
ll dp[101][101] = {};
rep(i, s + 1) rep(j, s + 1) dp[i][j] = -1;
dp[0][0] = 0;
rep(i, N) {
for (int j = min(i, s); j >= 0; j--) rep(k, s) if(dp[j][k] >= 0) {
chmax(dp[j + 1][(k + A[i]) % s], dp[j][k] + (k + A[i]) / s);
}
}
if (dp[s][amari] >= 0) {
chmin(kotae, wari - dp[s][amari]);
}
}
co(kotae);
Would you please return 0;
} |
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<algorithm>
using namespace std;
int main(){
int N;
std::cin >> N;
vector<string> S_list(N);
for(int i= 0; i < N; i++){
std::cin >> S_list[i];
}
vector<long long> t_list(N+1), f_list(N+1);
t_list[0] = 1;
f_list[0] = 1;
for(int i = 0; i < N; i++){
if(S_list[i] == "OR"){
t_list[i+1] = 2 * t_list[i] + f_list[i];
f_list[i+1] = f_list[i];
}else{
t_list[i+1] = t_list[i];
f_list[i+1] = t_list[i] + 2 * f_list[i];
}
}
std::cout << t_list[N];
}
| #include<bits/stdc++.h>
#define ll long long
#define fl(i,n) for(i=0;i<n;i++)
#define fld(i,a,b) for(i=a;i>b;i--)
#define fli(i,a,n) for(i=a;i<n;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define mod 1000000007
#define all(x) x.begin(),x.end()
#define speedup ios_base::sync_with_stdio(false),cin.tie(0)
#define N 1000005
using namespace std;
ll power(ll x, ll y){ll out = 1;while (y > 0){if (y & 1) out=(out*x);y = y>>1;x = (x*x);}return out;}
ll inverse(ll a){return power(a,mod-2)%mod;}
void comp() {
ll i,j,k,m,n;
cin>>n;
vector<string>v1;
string s;
fl(i,n) {
cin>>s;
v1.pb(s);
}
reverse(v1.begin(),v1.end());
ll ans = 1;
fl(i,n) {
if(v1[i] == "OR") {
ans += power(2,n-i);
}
}
cout<<ans<<"\n";
}
int32_t main() {
speedup;
ll i=0,t;
t=1;
//cin>>t;
while(t--) {
comp();
}
return 0;
} |
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
ll gcd(ll x, ll y) {
if(y == 0) {
return x;
}
return gcd(y, x%y);
}
// nの約数を昇順に列挙したvectorを返す。計算量はO(√n)
vector<ll> yakusu(ll n) {
vl res;
for(ll i = 1; i*i <= n; i++) {
if(n%i == 0) {
res.pb(i);
if(i != n/i) {
res.pb(n/i);
}
}
}
sort(all(res));
return res;
}
int main() {
ll n;
cin >> n;
ll mi = INF;
map<ll, ll> mp;
rep(i, n) {
ll a;
cin >> a;
chmin(mi, a);
vl v = yakusu(a);
for(ll d : v) {
mp[d] = gcd(a, mp[d]);
}
}
ll ans = 0;
for(auto p : mp) {
if(p.first > mi) {
break;
}
if(p.first == p.second) {
ans++;
}
}
out(ans);
re0;
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n,m) for(int i=n;i<m;i++)
void solve(){
priority_queue<int>pq;
rep(i,0,3){
int a;
cin>>a;
// cout<<a;
pq.push(a);
}
int sum=0;
sum+=pq.top();
pq.pop();
sum+=pq.top();
cout<<sum<<endl;
return;
}
int32_t main()
{
int t;
t=1;
while(t--){
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long int LL;
typedef pair<int,int> II;
typedef priority_queue<int> pqD;//降順
typedef priority_queue<int,vector<int>,greater<int>> pqU;//昇順
LL MOD=1000000007;
LL MO2=998244353;
LL INF=1000000000000;
#define SP(x) cout<<setprecision(x)
#define RP(i,n) for(i=0;i<n;i++)
#define RPU(i,n,x) for(i=x;i<n+x;i++)
#define RPD(i,n) for(i=n-1;i<=0;i++)
#define RPDU(i,n,x) for(i=n+x-1;i<=x;i++)
int main(void){
LL n,i,j,ans=0;
LL a[4];
RP(i,4)cin>>a[i];
sort(a,a+4);
cout<<a[0]<<endl;
}
| #include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
/* alias */
using ull = unsigned long long;
using ll = long long;
/* define short */
#define all(obj) (obj).begin(), (obj).end()
#define YESNO(bool) if(bool){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(bool) if(bool){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(bool) if(bool){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
/* REP macro */
#define reps(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define rep(i, n) reps(i, 0, n)
#define rrep(i, n) reps(i, 1, n + 1)
#define repd(i,n) for(ll i=n-1;i>=0;i--)
#define rrepd(i,n) for(ll i=n;i>=1;i--)
int main() {
ll N,K,first,second;
vector<pair<ll, ll>> AB;
cin>>N>>K;
rep(i,N){
cin>>first>>second;
AB.push_back({first,second});
}
sort(all(AB));
rep(i,N){
if(K<AB[i].first){
break;
}
K += AB[i].second;
}
cout<<K<<endl;
return 0;
} |
#include<iostream>
#include<iomanip>
#include<cmath>
#include<algorithm>
#include<numeric>
#include<vector>
#include<string>
#include<set>
#include<map>
//#include<atcoder/all>
#define fi first
#define se second
#define pb(x) emplace_back(x)
using namespace std;
using ll = long long;
using v_ll = vector <ll>;
bool IS_TEST=false;
ll INF = ll(1e17);
ll max(ll x,ll y){return x>y?x:y;}
ll min(ll x,ll y){return x<y?x:y;}
template<class T> bool chmax(T& x,const T& y){ if (x>=y) return false; x=y; return true;}
template<class T> bool chmin(T& x,const T& y){ if (x<=y) return false; x=y; return true;}
template<class T> void quit(T x){std::cout << x << "\n"; exit(0);}
template<typename T> void vshow(T x){for(auto itr = x.begin();itr!=x.end();itr++){std::cerr << *itr << " ";} std::cerr << "\n";}
template<typename T> void vvshow(T x){for(auto itr = x.begin();itr!=x.end();itr++){vshow(*itr);} std::cerr << "\n";}
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
ll N,M;
cin >> N >> M;
v_ll X(M,0),Y(M,0),Z(M,0);
for(ll i=0;i<M;i++) cin >> X[i] >> Y[i] >> Z[i];
v_ll ans(1LL<<N,0);
ans[0]=1;
for(ll i=1;i<(1LL<<N);i++){
ll c=0,ii=i;
v_ll cnt(N+1,0);
for(ll k=1;k<=N;k++){
cnt[k]=cnt[k-1];
if (ii&1){c++;cnt[k]++;}
ii>>=1;
}
ll flg = true;
for(ll j=0;j<M;j++){
if (c!=Y[j]) continue;
if (cnt[X[j]]>Z[j])flg = false;
}
if (flg){
ll p=0;
for(ll j=0;j<N;j++){
p+=ans[i&(-1-(1LL<<j))];
}
ans[i]=p;
}
}
cout << ans[(1LL<<N)-1] <<"\n";
}
| #include <iostream>
#include <cmath>
#include <stdio.h>
#include <string.h>
#include <bits/stdc++.h>
#include <vector>
#include <array>
#include <tuple>
#include <algorithm>
#include <functional>
#include <numeric>
using namespace std;
typedef long long ll;
int main() {
int N, p, t;
cin >> N;
ll l[N], r[N], y, z;
ll ans;
ans=0;
for (int i=0; i<N; i++){
cin >> t >> y >> z;
if (t==1){
l[i]=2*y;
r[i]=2*z;
}
if (t==2){
l[i]=2*y;
r[i]=2*z-1;
}
if (t==3){
l[i]=2*y+1;
r[i]=2*z;
}
if (t==4){
l[i]=2*y+1;
r[i]=2*z-1;
}
}
for (int i=0; i<N-1; i++){
for (int j=i+1; j<N; j++){
p=1;
if (r[i]<l[j]){
p=0;
}
if (r[j]<l[i]){
p=0;
}
ans+=p;
}
}
cout << ans << endl;
} |
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(ll i=1;i<=n;i++)
#define LOOP(i,n) for(ll i=0;i<n;i++)
#define loop(a,b) for(ll i=a;i<=b;i++)
#define sci(n) scanf("%d",&n)
#define scl(n) scanf("%lld",&n)
#define scl3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c);
#define scl2(a,b) scanf("%lld%lld",&a,&b)
#define scd(n) scanf("%lf",&n)
#define pf(n) printf("%lld\n",n)
#define srt(g) sort(g.begin(),g.end())
#define rvs(g) reverse(g.begin(),g.end())
#define pl pair<long long,long long>
#define pll pair<long long,pair<long long,long long>>
#define ll long long
#define pb push_back
#define mp make_pair
#define pi acos(-1.0)
#define f first
#define s second
int main()
{
ll n,m;
scl2(n,m);
vector<ll>a;
ll x;
if(m==0)
{
cout << "1\n";
return 0;
}
LOOP(i,m)
{
scl(x);
a.pb(x);
}
srt(a);
ll mn=INT_MAX;
vector<ll>v;
if(a[0]!=1)
{
v.pb(a[0]-1);
mn=min(mn,a[0]-1);
}
for(ll i=0;i<m-1;i++)
{
x=a[i+1]-a[i]-1;
if(x!=0)
{
mn=min(mn,x);
v.pb(x);
}
}
if(a[m-1]!=n)
{
v.pb(n-a[m-1]);
mn=min(mn,n-a[m-1]);
}
ll ans=0;
if(v.size()==0)
{
cout << "0\n";
return 0;
}
for(auto x:v)
{
//cout << "x" << "\n";
ll y=x/mn;
if(x%mn)y++;
ans=ans+y;
}
pf(ans);
}
| #include <bits/stdc++.h>
using namespace std;
vector<int> seen;
vector<vector<int>> g;
vector<int> a, b;
void dfs(int node, int64_t& sum) {
seen[node] = 1;
sum += a[node];
sum -= b[node];
for (auto v : g[node])
if (not seen[v])
dfs(v, sum);
}
int main() {
int n, m; cin >> n >> m;
a = vector<int> (n, 0);
b = vector<int> (n, 0);
for (int i = 0; i < n; i += 1)
cin >> a[i];
for (int i = 0; i < n; i += 1)
cin >> b[i];
g = vector<vector<int>> (n);
for (int i = 0; i < m; i += 1) {
int c, d; cin >> c >> d;
c -= 1, d -= 1;
g[c].push_back(d);
g[d].push_back(c);
}
seen = vector<int> (n, 0);
for (int i = 0; i < n; i += 1) {
if (not seen[i]) {
int64_t tot = 0;
dfs(i, tot);
if (tot != 0) {
cout << "No\n";
return 0;
}
}
}
cout << "Yes\n";
} |
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//
int main() {
ll S, P;
cin >> S >> P;
puts([&] {
for (ll i = 1; i * i <= P; ++i) {
ll n = i, m = S - i;
if (n > 0 && m > 0 && n * m == P) return true;
}
return false;
}() ? "Yes": "No");
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define asort(a,n) sort(a,a+n)
#define vsort(v) sort(v.begin(),v.end())
#define all(v) v.begin(),v.end()
#define run ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0);
#define mod 1000000007
#define endl "\n"
#define LL_MAX LLONG_MAX
#define yes cout<<"Yes"<<endl
#define no cout<<"No"<<endl
//********************************* mekch ************************************//
ll gcd(ll a, ll b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
ll binExp(ll x,ll n)
{
ll res=1;
while(n)
{
if(n&1) res=(res*x)%mod;
x=(x*x)%mod;
n>>=1;
}
return res;
}
bool isPerfectSquare(long double x)
{
long double sr = sqrt(x);
return ((sr - floor(sr)) == 0);
}
int main()
{
run;
ll t;
// ALWAYS UES LL_MAX
long double n,i,x,y,ok=0,sum=0,ans=0,res;
ll res1,res2,res3,res4;
cin>>x>>y;
res=x*x-4*y;
if (isPerfectSquare(res))
{
res1=sqrt(res);
res2=x+res1;
res3=x-res1;
// cout<<"jdc";
if(res2%2==0)
res2=res2/2;
else
res2=-1;
if(res3%2==0)
res3=res3/2;
else
res3=-1;
if(res2>0||res3>0)
{
if(res2>0)
res4=x-res2;
else
res4=x-res3;
if(res4>0)
yes;
else
no;
}
else
no;
}
else
no;
} |
#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
/*---------macro---------*/
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = s; i < (int)(n); ++i)
#define Clear(a) a = decltype(a)()
#define all(a) begin(a),end(a)
#define rall(a) rbegin(a),rend(a)
#define bit(i,j) ((i>>j)&1)
/*---------type/const---------*/
typedef long long ll;
typedef unsigned long long ull;
typedef string::const_iterator state; //構文解析
const ll big=1000000007;
//const ll big=998244353;
const double PI=acos(-1);
const double EPS=1e-8;//適宜変える
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const char newl='\n';
struct{
constexpr operator int(){return -int(1e9)-1;}
constexpr operator ll(){return -ll(1e18)-1;}
}neginf;
struct{
constexpr operator int(){return int(1e9)+1;}
constexpr operator ll(){return ll(1e18)+1;}
constexpr auto operator -(){return neginf;}
}inf;
/*---------debug---------*/
#ifdef LOGX
#include <template/debug.hpp>
#define _GLIBCXX_DEBUG
#else
#define dbg(x) ;
#define prt(x) ;
#define _prt(x) ;
#endif
/*---------function---------*/
template<typename T,typename U> T max(const T x,const U y){if(x>y)return x;else return y;}
template<typename T,typename U> T min(const T x,const U y){if(x<y)return x;else return y;}
template<typename T> T max(const vector<T> &a){T ans=a[0];for(T elem:a){ans=max(ans,elem);}return ans;}
template<typename T> T min(const vector<T> &a){T ans=a[0];for(T elem:a){ans=min(ans,elem);}return ans;}
template<typename T,typename U> bool chmin(T &a,const U b){if(a>b){a=b;return true;}return false;}
template<typename T,typename U> bool chmax(T &a,const U b){if(a<b){a=b;return true;}return false;}
bool valid(int i,int j,int h,int w){return (i>=0 && j>=0 && i<h && j<w);}
template<typename T,typename U>
T expm(T x,U y,const ll mod=big){
T res=1;
while(y){
if(y&1)(res*=x)%=mod;
(x*=x)%=mod;
y>>=1;
}
return res;
}
template<typename T,typename U>
T exp(T x,U y){
T res=1;
while(y){
if(y&1)res*=x;
x*=x;
y>>=1;
}
return res;
}
int n;
vector<int> p;
vector<vector<int>> g;//g[i][0]がiの親.
vector<vector<bool>> notmy;
vector<int> ans;
//「自分」「相手」の辺を決定する.
bool dfs(int i){
if(i!=0 && g[i].size()==1)return true;
bool res=false;
rep2(j,int(i!=0),g[i].size()){
res^=(notmy[i][j]=dfs(g[i][j]));
}
return !res;
}
//その頂点「に」移動させることを選択した人がどれだけ獲得するか?
int calc(int i){
if(g[i].size()==1 && i!=0){
return ans[i]=-1;
}
vector<int> mine;
vector<int> ene;
rep2(j,int(i!=0),g[i].size()){
if(notmy[i][j])ene.emplace_back(calc(g[i][j]));
else mine.emplace_back(calc(g[i][j]));
}
sort(rall(mine));
sort(rall(ene));
int res=-1;
//「ene」の個数が偶数個なら, mineは全て自分でとることになる.
if(ene.size()%2==0){
for(auto &e:mine)res+=e;
rep(j,ene.size()){
if(j%2==0)res+=ene[j];
else res-=ene[j];
}
}
else{
for(auto &e:mine)res+=abs(e);
rep(j,ene.size()){
if(j%2==0)res+=ene[j];
else res-=ene[j];
}
}
return ans[i]=res;
}
int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
cout.precision(10);
/*--------------------------------*/
cin >> n;
p.resize(n);
g.resize(n);
rep(i,n-1){
cin >> p[i+1];
p[i+1]--;
g[i+1].emplace_back(p[i+1]);
g[p[i+1]].emplace_back(i+1);
}
notmy.resize(n);
rep(i,n){
notmy[i].resize(g[i].size());
}
ans.resize(n,0);
dfs(0);
dbg(notmy);
calc(0);
dbg(ans);
cout << (n-ans.front())/2 << newl;
} | //For higher stack size use g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456 a.cpp -o a.exe in cmd
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define ll long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define pb push_back
#define f first
#define s second
using namespace std;
int main()
{
std::ios::sync_with_stdio(false);
int T;
T=1;
// cin.ignore(); must be there when using getline(cin, s)
while(T--)
{
ll l,i,j,k;
cin>>l;
ll dp[l+1][13];
for(i=0;i<=l;++i)
{
for(j=0;j<=12;++j)
dp[i][j]=0;
}
for(i=1;i<=l;++i)
{
dp[i][1]=1;
for(j=2;j<=12;++j)
{
for(k=i-1;k>=1;--k)
{
dp[i][j]=dp[i][j]+dp[k][j-1];
}
// cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
}
}
cout<<dp[l][12]<<endl;
}
return 0;
}
|
// #pragma GCC optimize("Ofast,unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#include <bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define forn(i, s, n) for(ll i=(ll)s; i<(ll)(n); i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define pll pair<long long int, long long int>
#define pii pair<int, int>
#define pss pair<string, string>
#define ull unsigned long long int
#define lld long double
#define F first
#define S second
#define PI 3.141592653589793238
#define prec(n) fixed<<setprecision(n)
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define itsval(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); itval(_it, args); }
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
void itval(istream_iterator<string> it) {}
template<typename T, typename... Args>
void itval(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << endl;
itval(++it, args...);
}
const ll MOD = 1e9 + 7;
template <typename T>
inline void print(T x) {cout << x << "\n";}
template <typename T>
inline void printvec(T x) {for (auto a : x) cout << a << ' '; cout << '\n';}
// -----------------------------------------------------------------------
struct custom {
bool operator()(const pair<int, string> &p1, const pair<int, string> &p2)const {
if (p1.F == p2.F)
return p1.S < p2.S;
return p1.F > p2.F;
}
};
// Calculate a^b % MOD -------------------------------------------------
ll get_pow(ll a, ll b, ll M = MOD) {
ll res = 1;
while (b) {
if (b & 1) res = (res * a) % M;
a = (a * a) % M;
b >>= 1;
}
return res;
}
// ---------------------------------------------------------------------
const ll N = 1e5 + 5, inf = 2e18;
ll n, m, X, Y;
std::vector<std::vector<pair<ll, pll>>> adj(N); // u, t,k
void bfs()
{
vll dist(n, inf);
dist[X] = 0;
priority_queue<pll, std::vector<pll> , greater<pll>> s;
s.push({0, X});
while (!s.empty())
{
auto t = s.top();
s.pop();
if (t.F > dist[t.S])
continue;
for (auto x : adj[t.S])
{
ll to = x.F;
ll m = (x.S.S - t.F % x.S.S) % x.S.S;
if (dist[to] > t.F + m + x.S.F)
{
dist[to] = t.F + m + x.S.F;
s.push({dist[to], to});
}
}
}
if (dist[Y] == inf)
cout << -1;
else
cout << dist[Y];
}
void solve()
{
cin >> n >> m >> X >> Y;
X--; Y--;
ll x, y, t, k;
forn(i, 0, m)
{
cin >> x >> y >> t >> k;
x--; y--;
adj[x].pb({y, {t, k}});
adj[y].pb({x, {t, k}});
}
bfs();
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output1.txt", "w", stdout);
#endif
int test = 1;
//cin >> test;
clock_t z = clock();
forn(tes, 0, test)
{
solve();
}
debug("Total Time:%.4f\n", (double)(clock() - z) / CLOCKS_PER_SEC);
return 0;
} | #include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;
constexpr int P = 1000000007;
ll powmod(ll n, ll k) {
ll r = 1, t = n % P;
for (; k != 0; k /= 2) {
if (k & 1) r = r * t % P;
t = t * t % P;
}
return r;
}
ll modinv(ll n) {
return powmod(n, P - 2);
}
int main() {
int n;
cin >> n;
//char aa, ab, ba, bb;
//cin >> aa >> ab >> ba >> bb;
constexpr int M = 4;
char c[M];
for (int i = 0; i < M; i++) {
cin >> c[i];
c[i] -= 'A';
}
if (c[1] == 1) {
for (int i = 0; i < M; i++) {
c[i] ^= 1;
}
swap(c[0], c[3]);
}
if (c[0] == 0 || n <= 3) {
cout << 1 << endl;
quick_exit(0);
}
//10??
n -= 3;
if (c[2] == 0) {
ll dp[1000][2];
dp[0][0] = 1;
dp[0][1] = 0;
for (int i = 0; i < n + 1; i++) {
dp[i + 1][0] = (dp[i][0] + dp[i][1]) % P;
dp[i + 1][1] = dp[i][0];
}
cout << dp[n + 1][0] << endl;
} else {
cout << powmod(2, n) << endl;
}
/*
* 挿入していくだけなのでA[AB]*Bの形
* 難しいのはAABからABABになったあと BAがBのときBも好きなだけ伸ばせる(お尻のBは1個のまま)
* BAがAのときBは1個のまま Aは好きな長さ
*/
return 0;
} |
#ifdef __LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b) {if(a<b) {a=b; return true;} return false;}
template<typename T> bool chmin(T &a,T b) {if(a>b) {a=b; return true;} return false;}
#define itn int
#define fi first
#define se second
#define intmax numeric_limits<int>::max()
#define llmax numeric_limits<ll>::max()
#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>=1;i--)
#define all(vec) vec.begin(),vec.end()
#define sortt(vec) sort((vec).begin(),(vec).end())
#define rsort(vec) sort((vec).rbegin(), (vec).rend())
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;
const ll lnf=1ll<<60;
int main(){
vector<int> cnt(2000000,0);
ll n,m; cin >> n >> m;
vector<ll> a(n);
rep(i,n){
cin >> a[i];
cnt[a[i]]++;
}
ll ans=inf;
rep(i,2e6){
if(cnt[i]==0){
ans=i;
break;
}
}
map<ll,vector<ll> > mp;
rep(i,n){
mp[a[i]].push_back(i);
}
for(auto c:mp)if(c.fi<ans){
auto v=c.se;
rep(i,v.size()){
if(i==0&&v[i]-(-1)>m){
cout << c.fi << endl;
return 0;
}
if(i==v.size()-1&&n-v[i]>m){
cout << c.fi << endl;
return 0;
}
if(i!=v.size()-1&&v[i+1]-v[i]>m){
cout << c.fi << endl;
return 0;
}
}
}
cout << ans << endl;
} | #include<bits/stdc++.h>
using namespace std;
int h[1600000] = { 0 };
int num[1600000] = { 0 };
int main()
{
int n;
cin >> n;
int size;
cin >> size;
for (int i = 1;i <= n;i++)
{
cin >> h[i];
if (i <= size)num[h[i]]++;
}
int mina;
for (int i = 0;;i++)
{
if (num[i] == 0)
{
mina = i;
break;
}
}
for (int i = 2;i <= n - size + 1;i++)
{
if (num[h[i - 1]] == 1 && h[i - 1] < mina&&h[i+size-1]!=h[i-1])
{
mina = h[i - 1];
}
num[h[i - 1]] = 0;
num[h[i + size - 1]]++;
}
cout << mina<< endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main()
{
int a,b;
cin>>b>>a;
cout<<b*2+100-a<<endl;
return 0;
}
| #include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
int n,m;
int main(){
scanf("%d%d",&n,&m);
printf("%d",2*n+100-m);
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll MOD=1000000007;
const ll MODA=998244353;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
long long gcd(long long a,long long b){
ll gcdmax=max(a,b);
ll gcdmin=min(a,b);
while(true){
if(gcdmax%gcdmin==0)break;
else gcdmax%=gcdmin;
swap(gcdmin,gcdmax);
}
return gcdmin;
}
ll powerup(ll N,ll P,ll M){
if(P==0)return 1;
else if(P%2==0){
ll t=powerup(N,P/2,M);
return t*t%M;
}
else return N*powerup(N,P-1,M)%M;
}
vector<ll> find_divisor(ll N){
ll k=1;
while(k*k<=N){
k++;
}
vector<ll> A(1);
rep(i,k){
if(i==1)A.at(0)=1;
else if(i>=2){
if(N%i==0)A.push_back(i);
}
}
ll t=0;
t=A.size();
rep(i,t){
if(A.at(t-i-1)*A.at(t-i-1)!=N)A.push_back(N/A.at(t-1-i));
}
return A;
}
vector<ll> fac;
vector<ll> finv;
vector<ll> inv;
void COMinit(ll N,ll P){
rep(i,N+1){
if(i==0){
fac.push_back(1);
finv.push_back(1);
inv.push_back(1);
}
else if(i==1){
fac.push_back(1);
finv.push_back(1);
inv.push_back(1);
}
else{
fac.push_back(fac.at(i-1)*i%P);
inv.push_back(P-inv.at(P%i)*(P/i)%P);
finv.push_back(finv.at(i-1)*inv.at(i)%P);
}
}
}
ll COM(ll n,ll k,ll P){
if(n<k)return 0;
if(n<0||k<0)return 0;
return fac.at(n)*(finv.at(k)*finv.at(n-k)%P)%P;
}
struct UnionFind {
vector<ll> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2
UnionFind(ll N) : par(N) { //最初は全てが根であるとして初期化
for(ll i = 0; i < N; i++) par[i] = i;
}
ll root(ll x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根}
if (par[x] == x) return x;
return par[x] = root(par[x]);
}
void unite(ll x, ll y) { // xとyの木を併合
ll rx = root(x); //xの根をrx
ll ry = root(y); //yの根をry
if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける
}
bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す
ll rx = root(x);
ll ry = root(y);
return rx == ry;
}
};
int main(){
ll N,W;
ll time=400000;
vector<ll> A(time);
cin>>N>>W;
ll wmax=0;
rep(i,N){
ll S,T,P;
cin>>S>>T>>P;
A.at(S)+=P;
A.at(T)-=P;
}
rep(i,time){
if(i>0){
A.at(i)+=A.at(i-1);
}
wmax=max(A.at(i),wmax);
}
if(W>=wmax)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
} | /*
Ashraful Islam Paran
11-April-2021
18:14:49
*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define f(n) for (int i = 0; i < n; i++)
#define show(x, y) cout << x << " " << y << "\n"
#define fo(i, x, n) for (int i = x; i < n; i++)
#define fb(i, x, n) for (int i = n - 1; i >= x; i--)
#define w(t) \
int t; \
cin >> t; \
while (t--)
#define dbg(args...) \
do \
{ \
cerr << #args << " : "; \
faltu(args); \
} while (0)
clock_t tStart = clock();
#define timeStamp dbg("Execution Time: ", (double)(clock() - tStart) / CLOCKS_PER_SEC)
void faltu()
{
cerr << endl;
}
template <typename T>
void faltu(T a[], int n)
{
for (int i = 0; i < n; ++i)
cerr << a[i] << ' ';
cerr << endl;
}
template <typename T, typename... hello>
void faltu(T arg, const hello &... rest)
{
cerr << arg << ' ';
faltu(rest...);
}
typedef unsigned long long ull;
typedef vector<long long> vi;
#define msi map<string, long long>
#define mii map<long long, long long>
const int MX = 2e5 + 5;
const int INF = 1e18;
const int mod = 1e9 + 7;
#define pb push_back
#define endl "\n"
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
inline void normal(int &a)
{
if (a >= mod)
a %= mod;
(a < 0) && (a += mod);
}
inline int modMul(int a, int b)
{
normal(a), normal(b);
return (a * b) % mod;
}
inline int modAdd(int a, int b)
{
normal(a), normal(b);
return (a + b) % mod;
}
inline int modSub(int a, int b)
{
normal(a), normal(b);
a -= b;
normal(a);
return a;
}
inline int modPow(int b, int p)
{
int r = 1;
while (p)
{
if (p & 1)
r = modMul(r, b);
b = modMul(b, b);
p >>= 1;
}
return r;
}
inline int modInverse(int a) { return modPow(a, mod - 2); }
inline int modDiv(int a, int b) { return modMul(a, modInverse(b)); }
void print(int a[], int n)
{
for (int i = 0; i < n; i++)
{
cout << a[i] << " ";
}
cout << endl;
}
void print(vi &v)
{
f(v.size())
{
cout << v[i] << " ";
}
cout << endl;
}
bool sortbysec(const pair<int, int> &a,
const pair<int, int> &b)
{
//return (a.second < b.second);
if (a.first == b.first)
{
return (a.second > b.second);
}
else
{
return (a.ff < b.ff);
}
}
int32_t main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
freopen("error.txt", "w", stderr);
#else
// online submission
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int r, x, y;
cin >> r >> x >> y;
double a = (sqrt(x * x + y * y));
// int b=a;
// dbg(b);
double b = r;
// cout<<(b+r-1)/r<<endl;
dbg(a);
double c = (a + 0) / b;
// dbg(c);
double ans = ceil(c);
int cnt = ans;
if (a < r)
{
cnt++;
// dbg(1);
}
cout << cnt << endl;
cerr << "Time : " << 1.0 * clock() / CLOCKS_PER_SEC << "s\n";
return 0;
} |
#include<iostream>
#include<string>
using namespace std;
int main() {
int T,N;
cin >> T;
string s1,s2,s3;
int i,j;
for(i=0;i<T;i++) {
cin >> N >> s1 >> s2 >> s3;
if(min(s1[0],s1[2*N-1]) == '0' && min(s2[0],s2[2*N-1]) == '0' && min(s3[0],s3[2*N-1]) == '0') {
for(j=0;j<N;j++)cout << "1";
cout << "0";
for(j=0;j<N;j++)cout << "1";
cout << endl;
}
else if(max(s1[0],s1[2*N-1]) == '1' && max(s2[0],s2[2*N-1]) == '1' && max(s3[0],s3[2*N-1]) == '1') {
for(j=0;j<N;j++)cout << "0";
cout << "1";
for(j=0;j<N;j++)cout << "0";
cout << endl;
}
else if(s1[0]+s2[0]+s3[0]-3*'0' > 1) {
cout << "1";
for(j=0;j<N;j++)cout << "0";
for(j=0;j<N;j++)cout << "1";
cout << endl;
}
else {
cout << "0";
for(j=0;j<N;j++)cout << "1";
for(j=0;j<N;j++)cout << "0";
cout << endl;
}
}
} | //#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <climits>
#include <functional>
#include <cstring>
#include <string>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <complex>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define itn int
#define nit int
#define ll long long
#define ms multiset
#define F(i,a,b) for(register int i=a,i##end=b;i<=i##end;++i)
#define UF(i,a,b) for(register int i=a,i##end=b;i>=i##end;--i)
#define re register
#define ri re int
#define il inline
#define pii pair<int,int>
#define cp complex<double>
//#pra gma G CC opti mize(3)
using namespace std;
using std::bitset;
//using namespace __gnu_pbds;
const double Pi=acos(-1);
namespace fastIO {
template<class T>
inline void read(T &x) {
x=0;
bool fu=0;
char ch=0;
while(ch>'9'||ch<'0') {
ch=getchar();
if(ch=='-')fu=1;
}
while(ch<='9'&&ch>='0') x=(x*10-48+ch),ch=getchar();
if(fu)x=-x;
}
inline int read() {
int x=0;
bool fu=0;
char ch=0;
while(ch>'9'||ch<'0') {
ch=getchar();
if(ch=='-')fu=1;
}
while(ch<='9'&&ch>='0') x=(x*10-48+ch),ch=getchar();
return fu?-x:x;
}
char _n_u_m_[40];
template<class T>
inline void write(T x ) {
if(x==0) {
putchar('0');
return;
}
T tmp = x > 0 ? x : -x ;
if( x < 0 ) putchar('-') ;
register int cnt = 0 ;
while( tmp > 0 ) {
_n_u_m_[ cnt ++ ] = tmp % 10 + '0' ;
tmp /= 10 ;
}
while( cnt > 0 ) putchar(_n_u_m_[ -- cnt ]) ;
}
template<class T>
inline void write(T x ,char ch) {
write(x);
putchar(ch);
}
}
using namespace fastIO;
string s[4];
int p0[4][200002],p1[4][200002];
int n,t1,t2;
char inv[10002];
int main() {
inv['0']='1';
inv['1']='0';
F(qwqwq,1,read()) {
cin>>n;
cin>>s[1]>>s[2]>>s[3];
F(i,1,n)putchar('0');F(i,1,n)putchar('1');puts("0");continue;
F(i,1,3)s[i].insert(0,"F");
F(i,1,3) {
t1=t2=0;
F(j,1,n+n) {
if(s[i][j]=='0')p0[i][++t1]=j;
else p1[i][++t2]=j;
}
}
F(i,1,n) {
if(p0[1][i]-p0[1][i-1]>1&&p0[2][i]-p0[2][i-1]>1&&p0[3][i]-p0[3][i-1]>1) {
F(ii,1,n)putchar('1');
F(ii,2,i)putchar('0');
putchar('1');
F(ii,i,n)putchar('0');
goto ak;
}
}
F(i,1,n) {
if(p1[1][i]-p1[1][i-1]>1&&p1[2][i]-p1[2][i-1]>1&&p1[3][i]-p1[3][i-1]>1) {
F(ii,1,n)putchar('0');
F(ii,2,i)putchar('1');
putchar('0');
F(ii,i,n)putchar('1');
goto ak;
}
}
F(i,1,3)s[i]+=s[i];
F(i,1,3)p0[i][n+n+1]=p1[i][n+n+1]=4*n+1;
F(i,1,3) {
t1=t2=n;
F(j,1,n+n) {
if(s[i][j]=='0')p0[i][++t1]=j+n+n;
else p1[i][++t2]=j+n+n;
}
}
F(i,1,n+n+1) {
if(p0[1][i]-p0[1][i-1]>1&&p0[2][i]-p0[2][i-1]>1&&p0[3][i]-p0[3][i-1]>1) {
F(ii,2,i)putchar('0');
putchar('1');
F(ii,i,n+n)putchar('0');
goto ak;
}
}
F(i,1,n+n+1) {
if(p1[1][i]-p1[1][i-1]>1&&p1[2][i]-p1[2][i-1]>1&&p1[3][i]-p1[3][i-1]>1) {
F(ii,2,i)putchar('1');
putchar('0');
F(ii,i,n+n)putchar('1');
goto ak;
}
}
if((p0[1][n]!=n+n||p1[1][1]==1)&&(p0[2][n]!=n+n||p1[2][1]==1)&&(p0[3][n]!=n+n||p1[3][1]==1)) {
F(ii,1,n)putchar('0');
putchar('1');
F(ii,1,n)putchar('0');
goto ak;
}
if((p1[1][n]!=n+n||p0[1][1]==1)&&(p1[2][n]!=n+n||p0[2][1]==1)&&(p1[3][n]!=n+n||p0[3][1]==1)) {
F(ii,1,n)putchar('1');
putchar('0');
F(ii,1,n)putchar('1');
goto ak;
}
ak:
;
putchar('\n');
}
return 0;
}
|
// 霽れを待つ
#include <bits/stdc++.h>
#define forn(i,s,t) for(register int i=(s);i<=(t);++i)
using namespace std;
const int N = 2e5 + 3;
struct Lst {int dir, nxt;}E[N<<1];
int G[N], cnt;
inline void Add(int u, int v) {
E[++cnt].dir = v, E[cnt].nxt = G[u], G[u] = cnt;
}
int P, len;
void Pre_dfs(int u, int lst, int d) {
(d > len) && (len = d, P = u);
for(register int i=G[u];i;i=E[i].nxt) {
int v = E[i].dir;
if(v == lst) continue ;
Pre_dfs(v, u, d + 1);
}
}
int son[N], res[N];
int dfs(int u, int lst, int d) {
int Mxd = d;
for(register int i=G[u];i;i=E[i].nxt) {
int v = E[i].dir;
if(v == lst) continue ;
int Mxv = dfs(v, u, d + 1);
if(Mxv > Mxd) Mxd = Mxv, son[u] = v;
}
return Mxd;
}
int tot = 1;
void Fin_dfs(int u, int lst) {
res[u] = tot;
for(register int i=G[u];i;i=E[i].nxt) {
int v = E[i].dir;
if(v == lst || v == son[u]) continue ;
tot ++ ;
Fin_dfs(v, u);
tot ++ ;
}
(son[u]) && (tot++, Fin_dfs(son[u], u), tot++);
}
int n;
int main() {
scanf("%d", &n);
forn(i,2,n) {
static int u, v;
scanf("%d%d", &u, &v);
Add(u, v), Add(v, u);
}
Pre_dfs(1, -1, 0);
dfs(P, -1, 1);
Fin_dfs(P, -1);
forn(i,1,n) printf("%d%c", res[i], " \n"[i == 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 <queue>
#include <bitset>
#include <stack>
#include <functional>
// AtCoder
// #include <atcoder/all>
// using namespace atcoder;
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...)
#endif
#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b)-1, i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).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 (b < a) { a = b; return 1; } return 0; }
#define fls(x) (64 - __builtin_clzll(x))
#define pcnt(x) __builtin_popcountll(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
int main (void)
{
cin.tie(0);
ios::sync_with_stdio(false);
ll h, w; cin >> h >> w;
vector<string> s(h); rep (i, h) cin >> s[i];
ll ans = 0;
rep (i, h - 1) rep (j, w - 1) {
int x = 0;
rep (p, 2) rep (q, 2) x += (s[i + p][j + q] == '#');
if (x == 1 || x == 3) ans++;
}
cout << ans << "\n";
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define lld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define f first
#define s second
#define mk make_pair
/*----------------------DEBUGGER---------------------------*/
#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x <<" "; _print(x); cerr << endl;
#else
#define debug(x)
#endif
void _print(ll t) {cerr << t;}
void _print(int t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(lld t) {cerr << t;}
void _print(double t) {cerr << t;}
void _print(ull t) {cerr << t;}
template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.f); cerr << ","; _print(p.s); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}
/*----------------------DEBUGGER---------------------------*/
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
freopen("error.txt", "w", stderr);
#endif
int t = 1;
//cin >> t;
while (t--)
{
int n;
cin >> n;
cout << 6 << " " << 15 << " " << 10 << " ";
int cnt = 0;
for (int i = 2; i <= 10000; i++)
{
if (i == 6 || i == 15 || i == 10)
continue;
if (cnt == n - 3)
break;
if (__gcd(i, 6) > 1 && __gcd(i, 15) > 1 && __gcd(i, 10) > 1) {
cout << i << " ";
cnt++;
}
}
}//while
}//main | #include <bits/stdc++.h>
#define MONKE 0
#define vt(x) vector < x >
#define p(x, y) pair < x, y >
#define M 1000000007
#define fl(i, a, b) for(int i = a; i < b; ++i)
#define fld(i, a, b) for(int i = a; i >= b; --i)
typedef long long ll;
typedef long double ld;
using namespace std;
int main() {
ios_base::sync_with_stdio(MONKE); //unsync uWu
cin.tie(MONKE); //cin-cout unsync uWu
int n;
cin >> n;
vector < int > ans(n);
ans[0] = 6;
ans[1] = 10;
ans[2] = 15;
int num = 18;
for (int i = 3; i < n; ++i) {
while ((num % 6) && (num % 10) && (num % 15)) num++;
ans[i] = num++;
}
for (int i = 0; i < n; ++i) cout << ans[i] << " ";
return MONKE;
} |
#include <bits/stdc++.h>
// #include<iomanip>
using namespace std;
#define int long long int
typedef pair<int, int> pii;
#define f(i,a,b) for(int i=a;i<b;i++)
#define fo(i,a,b) for(int i = a; i<=b;i+=1)
// #define Vector vector
#define rf(i,a,b) for(int i=a;i>=b;i--)
#define vll vector<int>
#define sz(a) int(a.size())
#define all(v) v.begin(), v.end()
#define pb push_back
#define pf push_front
#define MAXN 100010
#define MOD 1000000007
#define mod 998244353
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define debug(x) cout << '>' << #x << ':' << x << " ";
#define nl '\n'
#define MS(x,y) fill_n(*x, sizeof x / sizeof **x, y);
#define mem(x,y) memset(x,y,sizeof(x));
#define INF 1000000000000000000
#define IO \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
void solve(){
int n;
cin >> n;
string s;
cin >> s;
stack<char> stk;
char prev = '*', prevprev = '*';
for(int i = 0; i < n; i++){
if(stk.empty()){
stk.push(s[i]);
}
else {
if(s[i] == 'x' and stk.size() >= 2){
prev = stk.top();
stk.pop();
prevprev = stk.top();
stk.pop();
if(prev == 'o' and prevprev == 'f'){
}
else {
stk.push(prevprev);
stk.push(prev);
stk.push(s[i]);
}
}
else {
stk.push(s[i]);
}
}
}
cout << stk.size() << nl;
return ;
}
main()
{
IO;
int T = 1;
// cin >> T;
for(int c=1; c <= T; c++){
solve();
// cout<<"Case #"<<c<<": ";
}
return 0;
} | #include <bits/stdc++.h>
#define ll long long
#define map unordered_map
#define set unordered_set
#define l_l pair<ll, ll>
#define P pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>
#define mp make_pair
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rev(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define revs(i, n) for (int i = ((int)(n)); i > 0; --i)
// 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; }
using namespace std;
const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);
// template <class T> void plus_mod(T &a, const T &b) {a = (a + b) % MOD;}
int main() {
// std::cout << std::fixed << std::setprecision(10);
ll r1, c1;
scanf("%lld %lld", &r1, &c1);
ll r2, c2;
scanf("%lld %lld", &r2, &c2);
ll dist = abs(r2 - r1) + abs(c2 - c1);
if (dist <= 0) {
cout << (0) << endl;
return 0;
}
if (dist <= 3) {
cout << (1) << endl;
return 0;
}
ll sr = abs(r2 - r1);
ll sc = abs(c2 - c1);
if (abs(sr - sc) == 0) {
// 1ワープ
cout << (1) << endl;
return 0;
} else if (abs(sr - sc) <= 3) {
// 1ワープ+徒歩
cout << (2) << endl;
return 0;
} else {
if (dist % 2 == 0) {
// 2ワープ
cout << (2) << endl;
return 0;
} else {
// 2ワープ+徒歩
if (dist <= 6) {
cout << (2) << endl;
return 0;
}
cout << (3) << endl;
return 0;
}
}
}
|
// E - White Pawn
#include <bits/stdc++.h>
using namespace std;
int main(){
int N, M; cin>>N>>M;
map<int,vector<int>> D;
while(M--){
int x, y; cin>>x>>y;
D[x].push_back(y);
}
set<int> S({N});
for(auto&[x, Y]:D){
vector<int> A;
for(int&y:Y)
if(S.count(y-1) || S.count(y+1)) A.push_back(y);
for(int&y:Y) if(S.count(y)) S.erase(y);
for(int&y:A) S.insert(y);
}
cout<< S.size() <<endl;
}
| //#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep2(a,i,n) for(ll i=(a);i<(n);i++)
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define cinf(x,n) for(ll i=0;i<(n);i++)cin>>x[i];
#define coutf(x,n) for(ll i=0;i<(n);i++)cout<<x[i]<<endl;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using namespace std;
int main(){
//ios::sync_with_stdio(false);
//cin.tie(nullptr);
//cout<<fixed<<setprecision(20);
vector<int> a(3);
cinf(a,3);
sort(a.begin(),a.end());
cout << a[1]+a[2] << endl;
} |
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define rf(i,n,a) for(int i=n ; i>=a ; i--)
#define F first
#define S second
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
const int inf = 1e9;
const int inf64 = 1e18;
const int MOD = inf + 7;
void solve(){
int n;
cin >> n;
int m;
cin >> m;
int a[m+2];
f(i,0,m) cin >> a[i];
a[m] = 0;
a[m+1] = n+1;
sort(a, a+m+2);
int gc = n;
f(i,0,m+1) if(a[i+1] != a[i] + 1) gc = min(gc, a[i+1] - a[i] - 1);
int ans = 0;
f(i,0,m+1) ans += (a[i+1] - a[i] - 1 + gc - 1)/gc;
cout << ans << "\n";
}
int32_t main(){
fast;
int t = 1;
// cin >> t;
while(t--) solve();
}
| /*****************************************JAI SHREE RAM***************************************************/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define rep1(i,n) for((i)=1;(i)<=(n);(i)++)
int main()
{
ll n, k;
cin >> n >> k;
int ans;
while(k--)
{
string s = to_string(n);
sort(s.begin(),s.end());
ll e = stoll(s);
reverse(s.begin(),s.end());
ll f = stoll(s);
n = f - e;
if(n==0)
break;
}
cout << n;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef pair<string,string> Pstring;
typedef pair<double,double> Pdouble;
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define Precision13 cout << fixed << setprecision(13)
const double PI=3.14159265358979323846;
const int MAX = 510000;
const int MOD = 1000000007;
const int INF = 1<<29;
using Graph = vector<vector<int>>;
int main(){
ll n;
cin >> n;
ll i = 1;
ll sum = 0;
while(true){
sum += i;
if(sum>=n){
cout << i <<endl;
return 0;
}
i++;
}
}
| #include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
using namespace std;
#define MAXN 500005
#define lowbit(x) (x&-x)
#define reg register
typedef long long LL;
typedef unsigned long long uLL;
typedef unsigned int uint;
typedef pair<int,int> pii;
const int INF=0x7f7f7f7f;
const int mo=998244353;
const double PI=acos(-1.0);
template<typename _T>
_T Fabs(_T x){return x<0?-x:x;}
template<typename _T>
void read(_T &x){
_T f=1;x=0;char s=getchar();
while(s>'9'||s<'0'){if(s=='-')f=-1;s=getchar();}
while('0'<=s&&s<='9'){x=(x<<3)+(x<<1)+(s^48);s=getchar();}
x*=f;
}
char str[MAXN],ans[MAXN<<2],sta[MAXN];int n,head,tail,stak;
signed main(){
scanf("%s",str+1);n=(int)strlen(str+1);head=tail=2*n;
for(int i=1;i<=n;i++){
if(str[i]=='R'){
if(head!=tail){
swap(head,tail);
if(head<tail)head++,tail++;
else head--,tail--;
}
}
else{
if(head<=tail)ans[tail]=str[i],tail++;
else ans[tail]=str[i],tail--;
}
//printf("%d %d:%c\n",head,tail,ans[i]);
//if(head<tail)for(int i=head;i<tail;i++)putchar(ans[i]);
//else for(int i=head;i>tail;i--)putchar(ans[i]);puts("");
}
if(head<tail)
for(int i=head;i<tail;i++)
if(sta[stak]==ans[i])stak--;
else sta[++stak]=ans[i];
else
for(int i=head;i>tail;i--)
if(sta[stak]==ans[i])stak--;
else sta[++stak]=ans[i];
for(int i=1;i<=stak;i++)putchar(sta[i]);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
int sum = 0;
for (int i = 0; i < N; i++) {
int nuts;
cin >> nuts;
if (nuts > 10) {
sum += (nuts - 10);
}
else {
}
}
cout << sum << endl;
} | /* dont stick to an approach */
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <algorithm>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <bitset>
using namespace std;
typedef long long ll;
typedef unsigned long long int ull;
typedef long double ldb;
#define PB push_back
#define For(i, n) for (ll i = 0; i < n; i++)
#define trav(a,x) for (auto& a : x)
#define PYES cout<<"YES\n"
#define PNO cout<<"NO\n"
#define PYes cout<<"Yes\n"
#define PNo cout<<"No\n"
#define endl '\n'
#define sq(x) (x*x)
#define vll vector<ll>
#define pll pair<ll,ll>
#define ff first
#define ss second
#define rev(v) reverse(v.begin(),v.end())
#define srt(v) sort(v.begin(),v.end())
#define grtsrt(v) sort(v.begin(),v.end(),greater<int>())
#define mnv(v) *min_element(v.begin(),v.end())
#define mxv(v) *max_element(v.begin(),v.end())
#define all(v) v.begin(),v.end()
#define ACC(v) accumulate(v.begin(),v.end(),0ll)
#define Fas ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
//--------------------------------------------functions-------------------------------------------------//
ll power(ll a,ll b){ll result=1;while(b>0){if(b%2 == 1){result *= a;} a *= a;b /= 2;}return result;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
ll countSetBits(ll x){ll Count=0;while(x>0){if(x&1) Count++;x=x>>1;}return Count;}
bool isPerfectSquare(ll n){ll sr = sqrt(n);if (sr * sr == n)return true;else return false;}
ll mod(ll x,ll M){return ((x%M + M)%M);}
ll add(ll a, ll b,ll M){return mod(mod(a,M)+mod(b,M),M);}
ll mul(ll a, ll b,ll M){return mod(mod(a,M)*mod(b,M),M);}
ll powerM(ll a,ll b,ll M){
ll res=1ll;
while(b){
if(b%2ll==1ll){
res=mul(a,res,M);
}
a=mul(a,a,M);b/=2ll;
}
return res;
}
//------------------------------------sieve of erantothenes-----------------------------------------------//
//ll MAXN=2*1e5+100;
//vector<ll> fact(MAXN);
//void sieve_of_erantothenes()
//{
// fact[1] = 1;
// for (ll i = 2; i <= MAXN; i++)
// fact[i] = i;
// for (ll i = 4; i <= MAXN; i += 2)
// fact[i] = 2;
// for (ll i = 3; i * i <= MAXN; i++){
// if (fact[i] == i){
// for (ll j = i * i; j <= MAXN; j += i)
// if (fact[j] == j)
// fact[j] = i;
// }
// }
//}
//----------------------------------------nCr mod------------------------------------------------------//
ll nCr(ll n, ll k){
if(n<k) return 0;
if(k==0) return 1;
ll res = 1;
if (k > n - k) k = n - k;
for(ll i = 0; i < k; ++i){
res *= (n - i);
res /= (i + 1);
}
return res;
}
ll modInverse(ll n,ll M){
return powerM(n,M-2,M);
}
ll nCrM(ll n,ll r,ll M){
if(n<r) return 0;
if(r==0) return 1;
vector<ll> fact(n+1);
fact[0]=1;
for(ll i=1;i<=n;i++){
fact[i]=mul(fact[i-1],i,M);
}
return mul(mul(fact[n],modInverse(fact[r],M),M),modInverse(fact[n-r],M),M);
}
//-----------------------------------------------solve-----------------------------------------------------//
void solve(){
ll n;cin>>n;
cout<<ceil((ldb)(n)/100)<<endl;
}
int main(){
Fas;
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
// ll t=0;
// cin>>t;
// while(t--)
solve();
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vll vector<ll>
const int maxn = 2e5 + 5;
const int mod = 1e9 + 7;
int a[maxn];
ll dp[maxn][17];
int states;
int main()
{
ios::sync_with_stdio(false);
string b; cin >> b;
int n = b.size();
int t; cin >> t;
for (int i = 1 ; i <= n ; i++){
if (isdigit(b[i - 1])) a[i] = b[i - 1] - '0';
else a[i] = b[i - 1] - 'A' + 10;
}
for (int i = 0 ; i < n ; i++){
for (int j = 1 ; j <= 16 ; j++){
dp[i + 1][j] = (dp[i + 1][j] + dp[i][j] * j%mod)%mod;
dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i][j] * (16 - j)%mod)%mod;
}
// 0
dp[i + 1][0] = (dp[i + 1][0] + dp[i][0])%mod;
dp[i + 1][1] = (dp[i + 1][1] + dp[i][0] * 15 % mod) % mod;
for (int j = 0 ; j < a[i + 1] ; j++){
int ns = states;
// i = 0 , j = 0 只会发生在填第一位的时候,要特判
if (i || j) ns |= (1 << j);
dp[i + 1][__builtin_popcount(ns)] += 1;
}
states |= (1 << a[i + 1]);
}
cout << dp[n][t] + (t == __builtin_popcount(states)) << endl;
return 0;
}
| #include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
template<typename T>
struct UnionFind {
vector<int> d;
//コンストラクタ
UnionFind(int n = 0) : d(n, -1) {}
//根の探索と張り替え
int find(int x) {
if (d[x] < 0) return x;
//根のはりかえ
return d[x] = find(d[x]);
}
//根の結合
bool unite(int x, int y) {
x = find(x);
y = find(y);
if (x == y) return false;
//大きい方に小さい方をくっつける
if (x < y) swap(x, y);
//サイズの更新
d[x] += d[y];
//結合
d[y] = x;
return true;
}
//サイズの取得
int size(int x) { return -d[find(x)]; }
//同じ集合に属しているか
bool same(int x, int y) { return (find(x) == find(y)); }
};
const int top = 100;
const int bottom = -100;
double dist(int x1, int x2, int y1, int y2)
{
double dx = (double) x1-x2;
double dy = (double) y1-y2;
return dx*dx+dy*dy;
}
int main()
{
int n; cin >> n;
vector<int> x(n);
vector<int> y(n);
rep(i,n) cin >> x[i] >> y[i];
double up = 200, low = 0;
rep(bi,80)
{
double mid = (up+low)/2;
UnionFind<int> uf(n+2);
//壁同士の判定
if(top-mid < bottom + mid) uf.unite(n,n+1);
//上下の壁との判定
rep(i,n)
{
if(y[i] + mid > top - mid) uf.unite(i,n);
if(y[i] - mid < bottom + mid) uf.unite(i,n+1);
}
//釘同士の判定
rep(i,n)rep(j,n)
{
if(i > j) continue;
if(dist(x[i],x[j],y[i],y[j]) < 4*mid*mid) uf.unite(i,j);
}
if(uf.same(n,n+1)) up = mid;
else low = mid;
}
cout << setprecision(7) <<endl;
cout << low << endl;
} |
#include <bits/stdc++.h>
#define rep(i,l,r) for(int i=l,i##_end=r;i<i##_end;++i)
#define all(v) v.begin(), v.end()
#define sz(x) ((int)(x).size())
#define uniera(v) v.erase(unique(all(v)), v.end())
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(){
int n, k;
cin >> n >> k;
int sum = 0;
rep(i, 1, n + 1){
rep(j, 1, k + 1){
sum += i * 100 + j;
}
}
cout << sum << endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define int long long
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
signed main()
{
fast;
int n,k;
cin>>n>>k;
int sum=(k*(k+1))/2;
sum*=n;
int ans=(n*(n+1))/2;
ans*=100;
ans*=k;
ans+=sum;
cout<<ans<<"\n";
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<int> vi;
typedef vector<ll> vl;
const int MAX = 55;
const ll MOD = 998'244'353;
// input
int N, K;
vector<vi> A, B;
ll perm[MAX];
void input() {
cin >> N >> K;
A = B = vector<vi>(N, vi(N));
rep(i, N) rep(j, N) {
cin >> A[i][j];
B[j][i] = A[i][j];
}
}
struct UnionFind {
vector<int> par;
map<int, int> groups;
UnionFind(int n) : par(n) {
rep(i, n) par[i] = i;
rep(i, n) groups[i] = 1;
}
int root(int x) {
if (par[x] == x) return x;
return par[x] = root(par[x]);
}
void unite(int x, int y) {
int rx = root(x);
int ry = root(y);
if (rx == ry) return;
if (groups[rx] < groups[ry]) swap(rx, ry);
groups[rx] += groups[ry];
groups.erase(ry);
par[ry] = rx;
}
bool same(int x, int y) {
int rx = root(x);
int ry = root(y);
return rx == ry;
}
};
bool swap_ok(vector<vi> &w, int a, int b) {
rep(i, N) {
if (w[a][i] + w[b][i] > K) return false;
}
return true;
}
vector<P> link(vector<vi> w) {
vector<P> ret;
rep(a, N) {
for (int b = a + 1; b < N; b++) {
if (swap_ok(w, a, b)) ret.push_back(P(a, b));
}
}
return ret;
}
ll f(vector<P> &l) {
UnionFind uf(N);
for (P p : l) {
uf.unite(p.first, p.second);
}
ll ret = 1;
for (auto p : uf.groups) {
ret *= perm[p.second];
ret %= MOD;
}
return ret;
}
int main() {
input();
perm[0] = 1;
for (int i = 1; i < MAX; i++) perm[i] = i * perm[i - 1] % MOD;
vector<P> row_link = link(A);
vector<P> col_link = link(B);
ll ans = f(row_link) * f(col_link) % MOD;
cout << ans << endl;
}
| #include <bits/extc++.h>
using namespace std;
using namespace __gnu_cxx;
template<typename T>
int ex(T p){
T a = 1;
if(p == 0){
return a;
}
else{
for(T i = 1; i <= p; i++){
a = a*i%1000000007;
}
return a;
}
}
template<typename T>
int eq(T p, T q){
T r,s = 0,nextp,prevp = 0,prev2p = 1;
if(q != 1){
while(s != 1){
r = p/q; s = p%q;
nextp = prevp;
prevp = prev2p - r * prevp;
prev2p = nextp;
p = q; q = s;
}
return prevp;
}
else{
return 0;
}
}
template<typename T>
int com(T p,T q){
T a,b,c,mod = 1000000007;
a = ex(p);
b = ex(q);
for(T i = 1; i <= p-q; i++){
b = b*i%mod;
}
if(b != 1){
c = ((1 - eq(mod,b)*mod )/b + mod) %mod;
}
else{
c = 1;
}
return a*c%mod;
}
template<typename T>
int gcd(T p,T q){
T s;
while(q != 0){
s = p%q;
p = q; q = s;
}
return p;
}
int main() {
string S;
cin >> S;
cout << S[1] << S[2] << S[0] << endl;
} |
#include <bits/stdc++.h>
using namespace std;
int main(){
int pass;
int ans=0;
string s;
for(int i=0; i<10; i++){
cin >> s ;
}
for(int i=0; i<10000; i++){
vector<int>a(10);
pass=i;
for(int j=0; j<4; j++){
a.at(pass%10)=1;
pass/=10;
}
bool ok=true;
for(int k=0; k<10; k++){
if(s[k]=='o' && a.at(k)!=1) ok=false;
if(s[k]=='x' && a.at(k)!=0) ok=false;
}
if(ok) ans++;
}
cout << ans << endl;
} | #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>;
map<int, int> mp;
void prime_factor(int x) {
for (int i = 2; i * i <= x; i++) {
if (x % i != 0) continue;
while (x % i == 0) x /= i;
mp[i]++;
}
if (x != 1) mp[x]++;
return;
}
int main() {
int n;
cin >> n;
vector<int> a(n);
rep(i, n) cin >> a[i];
rep(i, n) prime_factor(a[i]);
int ans = 0;
int temp = 0;
for (auto x : mp) {
temp = max(temp, x.second);
if (temp == x.second) ans = x.first;
}
cout << ans << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
string s;
cin>>n>>s;
vector<int>dp(n,1e9);
vector<vector<int> >diff(26);
for(int i=0;i<26;i++)
for(int j=0;j<n;j++)
if(s[j]!=i+'a') diff[i].push_back(j);
vector<priority_queue<int> >pq(26);
for(int i=1;i<n;i++) {
if(pq[s[i]-'a'].empty()) {
for(int j=0;j<diff[s[i]-'a'].size()&&diff[s[i]-'a'][j]<i;j++)
dp[i]=min(dp[i],(diff[s[i]-'a'][j]?dp[diff[s[i]-'a'][j]-1]:0)+1);
pq[s[i]-'a'].push(-dp[i]);
}
else dp[i]=-pq[s[i]-'a'].top();
}
if(dp[n-1]>=1e9) cout<<-1;
else cout<<dp[n-1];
return 0;
} | #pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,sse4,fma")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
using vl = vector<ll>;
using vi = vector<int>;
using vb = vector<bool>;
using pll = pair<ll, ll>;
using pii = pair<int, int>;
using vpi = vector<pii>;
using rng = default_random_engine;
template <typename T>
using minpq = priority_queue<T, vector<T>, greater<T>>;
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define np next_permutation
#define sz(v) int(v.size())
#define all(v) begin(v), end(v)
#define popcnt __builtin_popcount
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
const int INF = 2000069420;
const int M1 = 1'000'000'007;
const int M2 = 998'244'353;
const int maxn = 1'000'005;
const int maxg = 2'005;
inline ull absul(ull a, ull b) {
return a < b ? b-a : a-b;
}
char ch;
int mp[256];
vector<ull> b[3];
void solve() {
mp['R'] = 0;
mp['G'] = 1;
mp['B'] = 2;
int n; cin >> n;
for (ull a; cin >> a >> ch;)
b[mp[ch]].push_back(a);
vi ext;
for (int i = 0; i < 3; ++i) {
sort(all(b[i]));
if (sz(b[i]) & 1)
ext.push_back(i);
}
if (!sz(ext)) {
cout << "0\n";
return void();
}
assert(sz(ext) == 2);
int i = ext[0], j = ext[1];
ull mn = 18e18;
// try combining two dogs from clans i and j
for (const ull &v: b[i]) {
auto it1 = lb(all(b[j]), v);
auto it2 = ub(all(b[j]), v);
if (it1 == b[j].end())--it1;
if (it2 != b[j].begin())--it2;
mn = min({mn, absul(*it1,v), absul(*it2,v)});
}
// Try combining two extra dogs to the third clan
int k = 3-i-j;
cerr << "mn = " << mn << '\n';
if (!sz(b[k])) {
cout << mn << '\n';
return void();
}
ull mn1 = 18e18, mn2 = 18e18;
for (const ull &v: b[i]) {
auto it1 = lb(all(b[k]), v);
auto it2 = ub(all(b[k]), v);
if (it1 == b[k].end())--it1;
if (it2 != b[k].begin())--it2;
mn1 = min({mn1, absul(*it1,v), absul(*it2,v)});
}
for (const ull &v: b[j]) {
auto it1 = lb(all(b[k]), v);
auto it2 = ub(all(b[k]), v);
if (it1 == b[k].end())--it1;
if (it2 != b[k].begin())--it2;
mn2 = min({mn2, absul(*it1,v), absul(*it2,v)});
}
cerr << "mn1 = " << mn1 << '\n';
cerr << "mn2 = " << mn2 << '\n';
cerr << "mn1+mn2 = " << mn1+mn2 << '\n';
cout << min(mn, mn1+mn2) << '\n';
}
int main() {
cin.tie(nullptr) ->
sync_with_stdio(false);
int T = 1; // cin >> T;
while (T--) solve();
} |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;
typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ll MOD = 1000000007;
template <typename T>
void fin(T a)
{
cout << a << endl;
exit(0);
}
void Main(void)
{
vll deri(4); rep(i, 4) cin >> deri[i];
ll bit = pow(2, 4);
for(ll i = 1;i < bit - 1;i++)
{
ll a = 0, b = 0;
ll tmp = i, count = 0;
while(tmp)
{
if(tmp % 2) a += deri[count];
else b += deri[count];
tmp /= 2;
count++;
}
if(a == b) fin("Yes");
}
fin("No");
return;
}
int main(void)
{
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(12); //高精度少数表示
Main();
return 0;
} | /*
Over Again
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define sz(v) ((int)(v).size())
#define all(v) ((v).begin()),((v).end())
#define allr(v) ((v).rbegin()),((v).rend())
#define pb push_back
#define mp make_pair
#define clr(v,d) memset( v, d ,sizeof(v))
#define lcm(a,b) ((a*b)/(__gcd(a,b)))
#define PI acos(-1)
#define vec(a,b) ((b)-(a))
#define length(a) hypot( (a.imag()),(a.real()) )
#define normalize(a) (a)/(length(a))
#define point complex<double>
#define dp(a,b) (((conj(a))*(b)).real())
#define same(p1,p2) ( dp( vec(p1,p2),vec(p1,p2)) < eps )
#define rotate0( a,ang) ((a)*exp( point(0,ang) ))
#define rotateA(about,p,ang) (rotate0(vec(about,p),ang)+about)
typedef long long ll ;
typedef unsigned long long ull;
const double eps= (1e-9);
using namespace std;
using namespace __gnu_pbds;
int dcmp(double a,double b){ return fabs(a-b)<=eps ? 0: (a>b)? 1:-1 ;}
int getBit(ll num, int idx) {return ((num >> idx) & 1ll) == 1;}
int setBit1(int num, int idx) {return num | (1<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}
void GO(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
int countNumBit1(int mask) {int ret=0; while (mask) {mask &= (mask-1);++ret; }return ret;}
const ll N=100000+5,mod=1000000007,sh=201,inf=2000000000;
typedef tree<
pair<ll,ll> ,
null_type,
less<pair<ll,ll> >,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
int main(){
GO();
int T=1;
//cin>>T;
while(T--){
int a,b,c;
cin>>a>>b>>c;
cout<<max(a+b,max(a+c,b+c))<<"\n";
}
}
|
#include <iostream>
#include <string>
#include <stdio.h>
#include <math.h>
#include <queue>
#include <algorithm>
#include <utility>
#include <vector>
#include <tuple>
#include <numeric>
using namespace std;
int main(int argc, char* argv[]){
int N,M;
cin >> N >> M;
vector<long long> A(N);
vector<long long> B(N);
vector <pair<int,int>> P(M);
long long sum_a = 0;
long long sum_b = 0;
for(int i=0;i<N;i++){
cin >> A[i];
sum_a += A[i];
}
for(int i=0;i<N;i++){
cin >> B[i];
sum_b += B[i];
}
vector<int> num(N,0);
for(int i=0;i<M;i++){
int c,d, tmp;
cin >> c >> d;
if(c>d){
tmp = c;
c = d;
d = tmp;
}
num[c-1]++;
num[d-1]++;
P[i] = make_pair(c, d);
}
bool flag = true;
for(int i=0; i<N; i++){
if(num[i]==0 && A[i]!=B[i]){
flag = false;
}
}
if(sum_a != sum_b || flag==false){
cout << "No" << endl;
}else{
cout << "Yes" << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vpii> vvpii;
typedef vector<vpll> vvpll;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define fi first
#define se second
template<class T> bool ckmin(T &a, const T &b) {return a > b ? a = b, 1 : 0;}
template<class T> bool ckmax(T &a, const T &b) {return a < b ? a = b, 1 : 0;}
void __print(int x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for(auto z : x) cerr << (f++ ? "," : ""), __print(z); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if(sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef ljuba
#define dbg(x...) cerr << "LINE(" << __LINE__ << ") -> " << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
const char nl = '\n';
void solve() {
vi v(4);
for(auto &z : v)
cin >> z;
int sumica = accumulate(all(v), 0);
for(int i = 1; i < (1<<4); ++i) {
int suma = 0;
for(int j = 0; j < 4; ++j) {
if((i>>j)&1) {
suma += v[j];
}
}
if(suma * 2 == sumica) {
cout << "Yes" << nl;
return;
}
}
cout << "No" << nl;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int testCases = 1;
//cin >> testCases;
while(testCases--)
solve();
}
|
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
const int MOD = 1000000007;
const int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;
class UnionFind {
public:
vector <int> par; // 各元の親を表す配列
vector <int> siz; // 素集合のサイズを表す配列(1 で初期化)
// Constructor
UnionFind(int sz_): par(sz_), siz(sz_, (int)1) {
for (int i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
}
void init(int sz_) {
par.resize(sz_);
siz.assign(sz_, (int)1);
for (int i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
}
// Member Function
// Find
int root(int x) { // 根の検索
while (par[x] != x) {
x = par[x] = par[par[x]]; // x の親の親を x の親とする
}
return x;
}
// Union(Unite, Merge)
bool merge(int x, int y) {
x = root(x);
y = root(y);
if (x == y) return false;
// merge technique(データ構造をマージするテク.小を大にくっつける)
if (siz[x] < siz[y]) swap(x, y);
siz[x] += siz[y];
par[y] = x;
return true;
}
bool issame(int x, int y) { // 連結判定
return root(x) == root(y);
}
int size(int x) { // 素集合のサイズ
return siz[root(x)];
}
};
signed main() {
int N;
cin >> N;
int A[N], B[N];
UnionFind uf(400010);
bool ok[400010]{};
rep(i,N){
cin >> A[i] >> B[i];
if(uf.issame(A[i], B[i]) || A[i] == B[i]){
ok[A[i]] = true;
}
else uf.merge(A[i], B[i]);
}
rep(i,400005){
if(ok[i]){
ok[uf.root(i)] = true;
}
}
int ans = 0;
rep(i,400005){
if(ok[i] && uf.size(i) == 1) ++ans;
else if(uf.size(i) == 1) continue;
else if(uf.root(i) != i) continue;
else if(ok[i]) ans += uf.size(i);
else ans += uf.size(i) - 1;
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
//#define int long long
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define all(x) (x).begin(),(x).end()
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define sz(x) (int)((x).size())
#define fr first
#define sc second
#define pii pair<int,int>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define mem1(a) memset(a,-1,sizeof(a))
#define mem0(a) memset(a,0,sizeof(a))
#define ppc __builtin_popcount
#define ppcll __builtin_popcountll
//#define rep(i, n) for (int i = 0; i < (int)(n); i++)
//template<typename T1,typename T2>istream& opertor>>(istream& in,pair<T1,T2> &a){in>>a.fr>>
//template<typename T1,typename T2>istream& opertor<<(ostream& out,pair<T1,T2> a){out<<a.fr<<
template<typename T,typename T1>T amax(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T amin(T &a,T1 b){if(b<a)a=b;return a;}
//template<class T> void chmin(T& a, T b){if(a>b)a=b;}
//template<class T> void chmax(T& a, T b){if(a<b)a=b;}
const long long INF=1e18;
const int32_t M=1e9+7;
const int32_t MM=998244353;
void out_vec_with_space(vector<auto> &v){
for ( int i = 0; i < v.size(); i++ ){
cout << ( i ? " " : "" ) << v[i];
}
}
int main() {
int A,B;
cin >> A >> B;
vector<int> E_plus(A),E_minus(B);
rep(i,0,A) {
E_plus[i] = i+1;
}
rep(i,0,B) {
E_minus[i] = -i-1;
}
if(A<B){
ll sum_B = 0;
rep(i,A-1,B){
sum_B += E_minus[i];
}
E_plus[A-1] = -sum_B;
}else if(B<A){
ll sum_A = 0;
rep(i,B-1,A){
sum_A += E_plus[i];
}
E_minus[B-1] = -sum_A;
}
out_vec_with_space(E_minus);
cout << " ";
out_vec_with_space(E_plus);
cout << endl;
} |
/////home/mohammed/.config/sublime-text-3/Packages/User
/*input
*/
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <sstream>
#include <iterator>
#include <cstdlib>
#include <unordered_map>
#include <map>
#include <list>
#include <set>
using namespace std;
using bin = std::bitset<8>;
#define endl ("\n")
#define pi (3.141592653589)
#define mod 1000000007
#define int int64_t
#define float double
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(c) c.begin(), c.end()
#define min3(a, b, c) min({a,b,c})
#define max3(a, b, c) max({a,b,c})
#define min4(a, b, c, d) min({a,b,c,d})
#define max4(a, b, c, d) max({a,b,c,d})
#define rrep(i, n) for(int i=n-1;i>=0;i--)
#define rep(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
#define ld long double
#define scanArray(a,n) for(int i = 0; i < n; i++){cin >> a[i];}
#define coutArray(a,n) for(int i = 0; i < n; i++){cout << a[i] << " ";};cout << endl;
#define input(type, n) type n; cin>>n;
struct debugger
{
template<typename T> debugger& operator , (const T& v)
{
cerr << v << " ";
return *this;
}
} dbg;
bool check_key(map<int, int> m, int key)
{
if (m.find(key) == m.end())
return false;
return true;
}
vector<int> SieveOfEratosthenes(int n)
{
bool prime[n + 1];
memset(prime, true, sizeof(prime));
vector<int> res;
for (int p = 2; p * p <= n; p++)
{
if (prime[p] == true)
{
for (int i = p * p; i <= n; i += p)
prime[i] = false;
}
}
for (int p = 2; p <= n; p++)
if (prime[p])
res.push_back(p);
//cout << p << " ";
return res;
}
// function to convert decimal to binary
bin decToBinary(int n)
{
// array to store binary number
int binaryNum[32];
// counter for binary array
int i = 0;
while (n > 0) {
// storing remainder in binary array
binaryNum[i] = n % 2;
n = n / 2;
i++;
}
string x = "";
// printing binary array in reverse order
for (int j = i - 1; j >= 0; j--) {
x += to_string(binaryNum[j]);
}
bin result{x};
return result;
}
// for example:
// bin result = decToBinary(2);
// bin result2 = decToBinary(10);
// bin z = result xor result2;
// cout << z;
// return 0;
int convertBinaryToDecimal(long long n)
{
int decimalNumber = 0, i = 0, remainder;
while (n != 0)
{
remainder = n % 10;
n /= 10;
decimalNumber += remainder * pow(2, i);
++i;
}
return decimalNumber;
}
int factorial(int n) {
long long res = 1;
for (int i = 1; i <= n; i++) {
res = ((res * i) % mod + mod) % mod ;
}
return res;
}
int32_t main()
{
fast;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
input(string, s);
rep(i, s.size()) {
if (s[i] == '.') {
return 0;
}
cout << s[i];
}
} | #pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<cstdint>
#include<cstddef>
#include<vector>
#include<iomanip>
#include<cstring>
//#include<atcoder/all>
//using namespace atcoder;
using namespace std;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using f64 = long double;
using usize = uint_fast64_t;
template<typename T>
using vec = vector<T>;
#define rep(i, n) for (i64 i = 0; i < (i64)(n); ++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using P = pair<i64,i64>;
i64 a,b,c;
i64 sum;
f64 dp[101][101][101];
f64 solve(i64 x,i64 y,i64 z){
if(dp[x][y][z])return dp[x][y][z];
if(x == 100 || y == 100 || z == 100)return 0;
f64 res = 0;
res += x * (solve(x + 1, y,z) + 1) / (x + y + z);
res += y * (solve(x,y + 1,z) + 1) / (x + y + z);
res += z * (solve(x,y,z + 1) + 1) / (x + y + z);
return dp[x][y][z] = res;
}
int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
cin >> a>> b >> c;
cout << fixed << setprecision(10) << solve(a,b,c) << endl;
}
|
#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int MOD = 998244353;
const int INF = 1e18;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
signed main(){
string S;
cin >> S;
int N = (int)S.size();
vector<pair<int, int>> ok;
for (int bit = 0; bit < (1<<N); ++bit) {
int now = 0;
int cnt = 0;
for (int i = 0; i < N; ++i) {
if (bit & (1<<i)) { // i番目のbitが立っていれば
int A = S[i]-'0';
now = now*10 + A;
cnt++;
}
}
if( now == 0 ) continue;
if( now%3 == 0 ){
ok.push_back(make_pair(N-cnt, now));
}
}
if( ok.size() == 0 ){
cout << -1 << endl;
}else{
sort(ok.begin(), ok.end());
cout << ok[0].first << endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> A(pow(2, N));
for (int i = 0; i < pow(2, N); i++) cin >> A.at(i);
int max1 = A.at(0), max2 = A.at(pow(2, N - 1));
for (int i = 0; i < pow(2, N - 1); i++) {
if (A.at(i) > max1) max1 = A.at(i);
if (A.at(pow(2, N - 1) + i) > max2) max2 = A.at(pow(2, N - 1) + i);
}
int secondprize = min(max1, max2);
for (int i = 0; i < pow(2, N); i++) {
if (A.at(i) == secondprize) cout << i + 1 << endl;
}
}
|
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define one(x) __builtin_popcountll(x)
#define zero(x) __builtin_ctzll(x)
#define pp pair<ll,ll>
#define all(x) (x).begin(), (x).end()
#define removeDuplicates(a) a.resize(unique(all(a))-a.begin())
template<class T> using oset =tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update> ;
typedef long long int ll;
const int mxn = 2e6 + 10;
ll b[mxn];
ll a[mxn];
array<ll, 2> arr[mxn];
void subMain(){
double x, y, z;
cin >> x >> y >> z;
//cout<<fixed<<setprecision(6);
double ans=(y*1.00000)/x;
ans=ans-0.000010;
ans*=z;
cout<<(int)(ans)<<"\n";
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
/*int t, i = 0;
cin >> t;
while(t--){
//cout << "Case #" << i+1 << ": ";
subMain();
//i++;
}*/
subMain();
cerr<<"Time : "<<1000*((double)clock())/(double)CLOCKS_PER_SEC<<"ms\n";
return 0;
}
| /* dont stick to an approach */
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <algorithm>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <vector>
#include <numeric>
#include <cstdlib>
using namespace std;
typedef long long ll;
typedef unsigned long long int ull;
typedef long double ldb;
#define PB push_back
#define For(i, n) for (ll i = 0; i < n; i++)
#define trav(a,x) for (auto& a : x)
#define PYES cout<<"YES\n"
#define PNO cout<<"NO\n"
#define PYes cout<<"Yes\n"
#define PNo cout<<"No\n"
#define endl '\n'
#define sq(x) (x*x)
#define vll vector<ll>
#define rev(v) reverse(v.begin(),v.end())
#define srt(v) sort(v.begin(),v.end())
#define grtsrt(v) sort(v.begin(),v.end(),greater<int>())
#define mnv(v) *min_element(v.begin(),v.end())
#define mxv(v) *max_element(v.begin(),v.end())
#define all(v) v.begin(),v.end()
#define Fas ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
//--------------------------------------------functions-------------------------------------------------//
ll power(ll a,ll b){ll result=1;while(b>0){if(b%2 == 1){result *= a;} a *= a;b /= 2;}return result;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
ll countSetBits(ll x){ll Count=0;while(x>0){if(x&1) Count++;x=x>>1;}return Count;}
bool isPerfectSquare(ll n){ll sr = sqrt(n);if (sr * sr == n)return true;else return false;}
ll mod(ll x,ll M){return ((x%M + M)%M);}
ll add(ll a, ll b,ll M){return mod(mod(a,M)+mod(b,M),M);}
ll mul(ll a, ll b,ll M){return mod(mod(a,M)*mod(b,M),M);}
ll powerM(ll a,ll b,ll M){
ll res=1ll;
while(b){
if(b%2ll==1ll){
res=mul(a,res,M);
}
a=mul(a,a,M);b/=2ll;
}
return res;
}
//------------------------------------sieve of erantothenes-----------------------------------------------//
//ll MAXN=1e7+100;
//vector<ll> fact(MAXN);
//void sieve_of_erantothenes()
//{
// fact[1] = 1;
// for (ll i = 2; i <= MAXN; i++)
// fact[i] = i;
// for (ll i = 4; i <= MAXN; i += 2)
// fact[i] = 2;
// for (ll i = 3; i * i <= MAXN; i++){
// if (fact[i] == i){
// for (ll j = i * i; j <= MAXN; j += i)
// if (fact[j] == j)
// fact[j] = i;
// }
// }
//}
//----------------------------------------nCr mod------------------------------------------------------//
ll modInverse(ll n,ll M){
return powerM(n,M-2,M);
}
ll nCrM(ll n,ll r,ll M){
if(n<r) return 0;
if(r==0) return 1;
vector<ll> fact(n+1);
fact[0]=1;
for(ll i=1;i<=n;i++){
fact[i]=mul(fact[i-1],i,M);
}
return mul(mul(fact[n],modInverse(fact[r],M),M),modInverse(fact[n-r],M),M);
}
//-----------------------------------------------solve-----------------------------------------------------//
void solve(){
ldb x,y,z;cin>>x>>y>>z;
for(ll i=1000008;i>=0;i--){
if(x*i<y*z){
cout<<i<<endl;
return;
}
}
}
int main(){
Fas;
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
// ll t=0;
// cin>>t;
// while(t--)
solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, n) for (int i = 0; i < (int)(n); ++ i)
int dp[3005][3005];
int main() {
int n, k;
cin >> n >> k;
const int mod = 998244353;
dp[0][k] = 1;
rep(i, n + 1) rep(j, n + 1) if (i || j > k)
dp[i][j] = (
(i ? dp[i - 1][j + 1] : 0) +
(j & 1 ? 0 : dp[i][j / 2])) % mod;
cout << dp[n][0] << endl;
return 0;
}
| #include <iostream>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <utility>
#include <vector>
#define ll long long
using namespace std;
int main() {
int arr[3]={0,0,0};
int x, y;
cin >> x >> y;
arr[x]++;
arr[y]++;
if(x==y){cout << x;}
else{
if(arr[0]==0){cout << "0";}
else if(arr[1]==0){cout << "1";}
else if(arr[2]==0){cout << "2";}
}
} |
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
// please, read the question correctly (do you need set or multiset)???
const int N=200010; //check the limits, dummy
int a[N];
int n, m, md;
int mem[101][101][101];
int dp(int x, int rm, int nm){
if(nm==m){
if(rm == md){
return 0;
}
else{
return -2e9;
}
}
if(x>=n){
return -2e9;
}
if(mem[x][rm][nm]!=-1){
return mem[x][rm][nm];
}
ll res;
res = max(dp(x+1, rm, nm), a[x]+dp(x+1, (rm+a[x])%m, nm+1));
mem[x][rm][nm]=res;
return res;
}
int main(){
ll x;
scanf("%d%lld",&n,&x);
for(int i=0; i<n; ++i){
scanf("%d",a+i);
}
ll ans = 10+1e18, tmp;
for(ll i=1; i<=n; ++i){
m = i;
md = x%i;
memset(mem, -1, sizeof mem);
tmp = dp(0, 0, 0);
if(tmp>=0){
ans = min(ans, (x-tmp)/i);
}
}
cout<<ans<<endl;
} | #pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline")
#pragma GCC option("arch=native","tune=native","no-zero-upper")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define infL (1LL<<60)
#define inf (1<<30)
#define inf9 (1000000000)
#define MOD 1000000007//998244353//1000000007
#define EPS 1e-9
#define Gr 9.8
#define PI acos(-1)
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REQ(i,n) for(int (i)=1;(i)<=(int)(n);(i)++)
#define lch (rt<<1)
#define rch (rt<<1|1)
#define readmp(n) for(int i=0,u,v;i<n;i++) {scanf("%d%d",&u,&v); mp[u].push_back(v); mp[v].push_back(u);}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef ll ValType;
template<typename T> void maxtt(T& t1, T t2) {
t1=max(t1,t2);
}
template<typename T> void mintt(T& t1, T t2) {
t1=min(t1,t2);
}
#define MAX (135)
bool debug = 0;
int n,m,k;
int dx[4] = {0,1,0,-1}, dy[4] = {1,0,-1,0};
string direc="RDLU";
const ll MOD2 = (ll)MOD * (ll)MOD;
ll ln, lk, lm;
void etp(bool f = 0) {
puts(f ?"YES" : "NO");
exit(0);
}
void addmod(int &x, int y, int mod = MOD){
x+=y; if (x>=mod) x-=mod;
if(x<0) x+=mod;
assert(x>=0 && x<mod);
}
void et(int x=-1) {
printf("%d\n", x); exit(0);
}
ll fastPow(ll x, ll y, int mod=MOD) {
ll ans = 1;
while(y>0) {
if(y&1) ans = (x * ans)%mod;
x = x*x%mod;
y>>=1;
}
return ans;
}
ll gcd1(ll x, ll y) {
return y?gcd1(y,x%y):x;
}
void fmain(int tid) {
scanf("%d%lld", &n,&lk);
vector<int> a(n+1, 0);
REQ(i,n) scanf("%d", &a[i]);
ll ans=infL;
REQ(c, n) {
vector<vector<vector<int>>> dp(n+1, vector<vector<int>>(c+1, vector<int>(c+1,-1)));
dp[0][0][0]=0;
REQ(i,n) {
for(int j=0;j<=c;j++) REP(z,c) if (dp[i-1][j][z]!=-1) {
maxtt(dp[i][j][z], dp[i-1][j][z]);
if(j<c) maxtt(dp[i][j+1][(z+a[i])%c], dp[i-1][j][z] + a[i]);
}
}
int z=lk%c;
if (dp[n][c][z] != -1){
ll tt= lk-dp[n][c][z];
assert(tt%c==0);
mintt(ans, tt/c);
}
}
printf("%lld\n", ans);
}
int main() {
int t=1;
// init();
// scanf("%d", &t);
REQ(i,t) {
fmain(i);
}
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
const long long mod=998244353,INF=1e18;
#define ll long long
#define line cout<<"\n";
#define flush cout<<endl;
#define pll pair<ll,ll>
#define x first
#define y second
#define p_all(arr) for(auto i:arr){cout<<i<<" ";}cout<<"\n";
ll k,n;
vector<vector<ll> > tree;
ll cnt=0;
ll dfs(ll u,ll pa,ll num)
{
ll ma1=0,ma2=0,mi=0;
for(auto v:tree[u])
{
if(v!=pa)
{
ll temp=1LL+dfs(v,u,num);
ma2=max(ma2,temp);
mi=min(mi,temp);
if(ma2>ma1)
{
swap(ma2,ma1);
}
}
}
if(mi<0&&abs(mi+1)>=ma1)
{
return mi;
}
if(ma1==num)
{
cnt++;
ma1=-num-1;
}
else if(pa==-1)
{
if(ma1>=0)
cnt++;
}
return ma1;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);
ll t=1;
// cin>>t;
for(ll test=1;test<=t;test++)
{
cin>>n>>k;
tree.resize(n);
for(int i=0;i<n-1;i++)
{
ll u,v;
cin>>u>>v;
u--,v--;
tree[u].push_back(v);
tree[v].push_back(u);
}
ll l=1,r=n;
while(l<r)
{
ll m=(l+r)/2;
cnt=0;
ll count1=dfs(0,-1,m);
if(cnt<=k)
{
r=m;
}
else
{
l=m+1;
}
}
cout<<l<<"\n";
}
return 0;
}
| #include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
//#define puts sdf
using std::vector;
//using std::cout;
//using std::endl;
using std::sort;
using std::swap;
using std::min;
using std::max;
int read(){//int 无负数
int h=0;char c=getchar();
while(c<'0'||c>'9')c=getchar();
while(c>='0'&&c<='9')h=(h<<1)+(h<<3)+c-'0',c=getchar();
return h;
}
const int MAXN=200100;
int K,n;
struct Edge{
int to;
int nxt;
}edge[MAXN<<1];
int frm[MAXN];
int cnt_e;
void insert_e(int u,int v){
cnt_e++;
edge[cnt_e].to=v;
edge[cnt_e].nxt=frm[u];
frm[u]=cnt_e;
}
int Fa[MAXN];
int Rt,mns,S;
int siz[MAXN];
bool vis[MAXN];
void get_rt(int x,int ff){
siz[x]=1;int mxs=0;
for(int i=frm[x];i;i=edge[i].nxt){
int v=edge[i].to;if(v==ff||vis[v])continue;
get_rt(v,x);
siz[x]+=siz[v];
mxs=max(mxs,siz[v]);
}
mxs=max(mxs,S-siz[x]);
if(mxs<mns)Rt=x,mns=mxs;
}
int Dt[MAXN];//点分树上的深度
int dis[MAXN][21]; //x到点分树上深度为D的那个祖先的距离
int mndis[MAXN];//距离他最近的点
void get_dis1(int U,int x,int ff,int dep,int D){
dis[x][D]=dep;
for(int i=frm[x];i;i=edge[i].nxt){
int v=edge[i].to;if(v==ff||vis[v])continue;
get_dis1(U,v,x,dep+1,D);
}
}
void divide(int x,int D){//D是点分树上的深度
vis[x]=true;
Dt[x]=D;
get_dis1(x,x,x,0,D);
for(int i=frm[x];i;i=edge[i].nxt){
int v=edge[i].to;if(vis[v])continue;
S=siz[v],mns=siz[v],get_rt(v,v);
Fa[Rt]=x;divide(Rt,D+1);
}
}
void Modify(int x){
int rt=x;
for(;rt;rt=Fa[rt]){
mndis[rt]=min(mndis[rt],dis[x][Dt[rt]]);
// cout<<"MODIFY"<<x<<" "<<rt<<" "<<mndis[rt]<<endl;
}
}
bool Query(int x,int mid){
int rt=x;
for(;rt;rt=Fa[rt]){
// cout<<"QUERY "<<x<<' '<<rt<<" "<<mndis[rt]<<' '<<dis[x][Dt[rt]]<<endl;
if(mndis[rt]+dis[x][Dt[rt]]<=mid)return true;
}
return false;
}
int fa[MAXN][19];
int dep[MAXN];
int qwq[MAXN];//按深度排序
bool cmp(int x,int y){
return dep[x]>dep[y];
}
void pre_dfs(int x,int ff){
fa[x][0]=ff;dep[x]=dep[ff]+1;
for(int i=1;i<=18;i++)fa[x][i]=fa[fa[x][i-1]][i-1];
for(int i=frm[x];i;i=edge[i].nxt){
int v=edge[i].to;if(v==ff)continue;
pre_dfs(v,x);
}
}
int get_fa(int x,int k){
int nw=x;
for(int i=0;i<=18;i++){
if(k&(1<<i))nw=fa[nw][i];
}
return nw;
}
bool ch_ck(int mid){
// cout<<"MID"<<':'<<mid<<endl;
memset(mndis,0x3f,sizeof(mndis));
// for(int i=1;i<=n;i++)mndis[i]=-0x3f3f3f3f;
int cnt=0;
for(int i=1;i<=n;i++){
int x=qwq[i];
if(Query(x,mid))continue;
int fk=get_fa(x,mid);
cnt++;Modify(fk);
// cout<<"WORK"<<x<<" "<<fk<<endl;
if(cnt>K)return false;
}
return true;
}
int get_ans(){
int l=0,r=n;
while(l+1<r){
int mid=(l+r)>>1;
if(ch_ck(mid)){
r=mid;
}
else l=mid+1;
}
if(l==r)return r;
if(ch_ck(l))return l;
return r;
}
int main(){
n=read(),K=read();
for(int i=1;i<=n-1;i++){
int u=read(),v=read();
insert_e(u,v),insert_e(v,u);
}
S=n,mns=n,get_rt(1,1);
divide(Rt,0);
pre_dfs(1,1);
for(int i=1;i<=n;i++)qwq[i]=i;sort(qwq+1,qwq+n+1,cmp);
// for(int i=1;i<=n;i++)cout<<qwq[i]<<" ";puts("");
// for(int i=1;i<=n;i++){
// for(int j=0;j<=18;j++)cout<<fa[i][j]<<" ";puts("");
// }
printf("%d\n",get_ans());
return 0;
} |
#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;
vi X,Y,ind1,ind2;
bool comp1(int i, int j){
return X[i] < X[j];
}
bool comp2(int i, int j){
return Y[i] < Y[j];
}
set<ll> S;
vi nums;
void f(int i, int j){
if(i == j)return;
if(i > j)swap(i, j);
if(S.find(ll(i)*MAXN + ll(j)) != S.end())return;
S.insert(ll(i)*MAXN + ll(j));
nums.push_back(max(abs(X[i]-X[j]), abs(Y[i]-Y[j])));
}
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,n){
cin >> a >> b;
X.push_back(a);
Y.push_back(b);
ind1.push_back(c1);
ind2.push_back(c1);
}
sort(all(ind1), comp1);
sort(all(ind2), comp2);
rep(c1,0,n){
f(ind1[0], c1);
f(ind2[0], c1);
f(ind1[n-1], c1);
f(ind2[n-1], c1);
}
sort(all(nums));
cout << nums[sz(nums)-2] << "\n";
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
#define N 200005
int n,x[N],y[N],i,p1,p2,ans,f1[N],f2[N];
int main(){
cin>>n;
for(i=1;i<=n;++i)cin>>x[i]>>y[i],f1[i]=x[i],f2[i]=y[i];
sort(x+1,x+n+1);sort(y+1,y+n+1);
if(x[n]-x[1]>y[n]-y[1]){
for(i=1;i<=n;++i)swap(x[i],y[i]),swap(f1[i],f2[i]);
}
ans=max(y[n]-y[2],y[n-1]-y[1]);
ans=max(ans,max(x[n]-x[2],x[n-1]-x[1]));
for(i=1;i<=n;++i){
if(f2[i]==y[n])p1=i;
if(f2[i]==y[1])p2=i;
}
if(abs(f1[p1]-f1[p2])!=x[n]-x[1])ans=max(ans,x[n]-x[1]);
cout<<ans;
} |
#include <bits/stdc++.h>
using namespace std;
#define M1 1000000007
#define M3 1000000009
#define M2 998244353
#define ll long long
#define ld long double
#define pll pair<ll,ll>
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=b-1;i>=a;i--)
#define forr(i,n) for(ll i=0;i<n;i++)
#define F first
#define S second
#define pb push_back
#define DB pop_back
#define mp make_pair
#define MT make_tuple
#define V(a) vector<a>
#define vi vector<ll>
#define endl '\n'
#define ce(ele) cout<<ele<<' '
#define cs(ele) cout<<ele<<'\n'
#define csv(v) for(int i=0;i<v.size();i++)cout<<v[i]<<' '
#define yep cout<<"YES"<<'\n'
#define nope cout<<"NO"<<'\n'
#define CASE(te) ll te; cin>>te; while(te--)
#define sor(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
void FAST() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
vi arr[2001];
int vis[2001];
void dfs(int node)
{
vis[node]=1;
for(auto x:arr[node])
{
if(vis[x]==0)
{
dfs(x);
}
}
}
int main()
{
FAST();
ll n,m;
cin>>n>>m;
forr(i,m)
{
ll a,b;
cin>>a>>b;
arr[a].push_back(b);
}
ll ans=0;
for(int i=1;i<=n;i++)
{
dfs(i);
ll c=0;
for(int j=1;j<=n;j++)
if(vis[j]==1)
{
c++;
vis[j]=0;
}
ans+=c;
}
cs(ans);
} | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pll;
#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(40)
const ll MOD = 1000000007;
const ll INF = (ll) 1e15;
struct Vertex {
vector<pll> node;
};
Vertex V[2005];
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll N, M;
cin >> N >> M;
REP(i, M) {
ll a, b, c;
cin >> a >> b >> c;
a--;
b--;
V[a].node.push_back(pll(b, c));
}
REP(i, N) {
vector<ll> dist(N, INF);
priority_queue<pll, vector<pll>, function<bool(pll, pll)>> q([](pll a, pll b) { return a.second > b.second; });
q.push(pll(i, 0));
while (!q.empty()) {
pll t = q.top();
q.pop();
if(dist[t.first]<t.second)continue;
for (auto &v : V[t.first].node) {
ll nxt = v.first;
ll cost = t.second + v.second;
if (dist[nxt] <= cost)
continue;
dist[nxt] = cost;
q.push(pll(nxt, cost));
}
}
ll ret = dist[i];
if (ret == INF)
ret = -1;
cout << ret << endl;
}
return 0;
} |
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,fma,abm,mmx,avx,avx2")
#pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
template <typename T = long long, const int sz = 5 * 10000000> struct IO {
char reader[sz], writer[sz];
char *now, *now2 = writer;
IO() {
reader[fread(reader, sizeof(char), sizeof(char) * sz, stdin)];
now = reader;
}
inline T read() {
while(*now && *now <= 32) now++;
if(*now == '-') {
now++;
T res = 0;
while('0' <= *now and *now <= '9') { res = res * 10 + *now++ - '0'; }
return -res;
} else {
T res = 0;
while('0' <= *now and *now <= '9') { res = res * 10 + *now++ - '0'; }
return res;
}
}
inline void read(T &res) {
while(*now && *now <= 32) now++;
if(*now == '-') {
now++;
res = 0;
while('0' <= *now and *now <= '9') { res = res * 10 + *now++ - '0'; }
res = -res;
} else {
res = 0;
while('0' <= *now and *now <= '9') { res = res * 10 + *now++ - '0'; }
}
}
inline string read_str() {
string res;
while(*now and *now != '\n' and *now != ' ') res += *now++;
now++;
return res;
}
inline void write(T x, char margin = ' ') {
if(x == 0) {
putchar('0');
putchar(margin);
return;
}
if(x < 0) {
putchar('-');
x = -x;
}
while(x) {
*now2 = '0' + x % 10;
now2++;
x /= 10;
}
do {
now2--;
putchar(*now2);
} while(now2 != writer);
putchar(margin);
}
inline void write_str(string s, char margin = ' ') {
for(auto c : s) putchar(c);
putchar(margin);
}
};
IO<uint64_t> io;
inline uint64_t read() { return io.read(); }
inline void write(uint64_t x) { io.write(x); }
int n, q;
uint64_t a[100010], k;
int main() {
n = read(), q = read();
for(int i = 0; i < n; i++) a[i] = read() - i;
a[n] = 1LL << 63;
n++;
while(q--) {
k = read();
if(a[n - 2] <= k) {
write(k + n - 1);
continue;
}
for(int i = 0; i < n; i++) {
if(a[i] > k) {
write(k + i);
break;
}
}
}
} | #include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
template <typename X, typename Y> istream& operator>>(istream& is, pair<X, Y>& p) { return is >> p.first >> p.second; }
template <bool Directed, typename TEdge, bool Index> struct graph {
using EType = TEdge;
vector<TEdge> edges;
vector<vector<int>> adj;
graph(int n) : adj(n + Index) {}
graph(int n, int m) : graph(n) { edges.reserve(m << not Directed); }
TEdge& operator()(int e) { return edges[e]; }
vector<int>& operator[](int u) { return adj[u]; }
int size() { return adj.size() - Index; }
void append(int u, const TEdge& e) {
adj[u].push_back(edges.size());
edges.push_back(e);
}
void add_edge(const TEdge& e) {
append(e.u, e);
if(not Directed) append(e.v, e.reverse());
}
};
template <typename T> using f = function<T>;
template <typename TEdge> struct dfs_params {
f<void(int)> pre_node = [](int) -> void {};
f<void(int)> pos_node = [](int) -> void {};
f<void(TEdge&)> pre_edge = [](TEdge&) -> void {};
f<void(TEdge&)> pos_edge = [](TEdge&) -> void {};
int root = 0;
};
template <bool Directed, typename TEdge, bool Index, typename TParamsetter = f<void(dfs_params<TEdge>&)>>
vector<int> dfs(graph<Directed, TEdge, Index>& g, const TParamsetter& psetter = [](dfs_params<TEdge>&) {}) {
static_assert(is_convertible<decltype(psetter), f<void(dfs_params<TEdge>&)>>::value, "psetter must be void(dfs_params<TEdge>&)");
dfs_params<TEdge> params;
psetter(params);
vector<int> component(g.adj.size());
function<void(int, int)> dfs = [&](int u, int c) {
component[u] = c;
params.pre_node(u);
for(int e : g[u]) if(not component[g(e).v]) {
params.pre_edge(g(e)), dfs(g(e).v, c), params.pos_edge(g(e));
}
params.pos_node(u);
};
if(params.root) {
dfs(params.root, 1);
} else {
for(int u = Index, c = 0; u < g.adj.size(); u++) if(not component[u]) {
dfs(u, ++c);
}
}
return component;
}
struct edge {
int u, v;
edge reverse() const { return {v, u}; }
friend ostream& operator<<(ostream& os, const edge& e) {
return os << "{u: " << e.u << ", v: " << e.v << "}";
}
};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> c(n + 1);
for(int i = 1; i <= n; i++) {
cin >> c[i];
}
graph<0, edge, 1> g(n, n - 1);
for(int i = 0; i < n - 1; i++) {
int u, v;
cin >> u >> v;
g.add_edge({u, v});
}
vector<int> counter(100'000 + 1), good(n + 1);
dfs(g, [&](auto& p) {
p.pre_node = [&](int u) {
counter[c[u]] += 1;
};
p.pos_node = [&](int u) {
counter[c[u]] -= 1;
good[u] = counter[c[u]] == 0;
};
});
for(int i = 1; i <= n; i++) {
if(good[i]) {
cout << i << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,int> P;
typedef tuple<int,int,int> tii;
typedef vector<int> vec;
typedef vector<vec> mat;
#define rep(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define bit(n,k) (n>>k&1)
ll INFL = 1e18+5;
int INF = 1001001001;
const int M = 1e9+7;
int dx[4] = {-1,1,0,0};
int dy[4] = {0,0,1,-1};
int h,w;
string field[2005];
int main(){
cin >> h >> w;
rep(i,0,h) cin >> field[i];
vector<vector<ll>> x(h+1,vector<ll>(w+1,0));
vector<vector<ll>> y(h+1,vector<ll>(w+1,0));
vector<vector<ll>> z(h+1,vector<ll>(w+1,0));
vector<vector<ll>> dp(h+1,vector<ll>(w+1,0));
dp[1][1] = 1;
for(int i=1;i<=h;i++){
for(int j=1;j<=w;j++){
if(field[i-1][j-1]=='#'){
x[i][j] = 0;
y[i][j] = 0;
z[i][j] = 0;
dp[i][j] = 0;
continue;
}
x[i][j] = (x[i][j-1] + dp[i][j-1])%M;
y[i][j] = (y[i-1][j] + dp[i-1][j])%M;
z[i][j] = (z[i-1][j-1] + dp[i-1][j-1])%M;
dp[i][j] += (x[i][j] + y[i][j] + z[i][j])%M;
}
}
cout << dp[h][w]%M << endl;
}
| #include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std;
void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
int mod = 1000000007;
int add(int x, int y) { return (x += y) >= mod ? x - mod : x; }
template<class... T> int add(int x, T... y) { return add(x, add(y...)); }
int mul(int x, int y) { return 1LL * x * y % mod; }
template<class... T> int mul(int x, T... y) { return mul(x, mul(y...)); }
int sub(int x, int y) { return add(x, mod - y); }
int modpow(int a, long long b) {
int ret = 1; while (b > 0) {
if (b & 1) ret = 1LL * ret * a % mod; a = 1LL * a * a % mod; b >>= 1;
} return ret;
}
int modinv(int a) { return modpow(a, mod - 2); }
void chadd(int& x, int y) { x = add(x, y); }
void chsub(int& x, int y) { x = sub(x, y); }
void chmul(int& x, int y) { x = mul(x, y); }
/*---------------------------------------------------------------------------------------------------
∧_∧
∧_∧ (´<_` ) Welcome to My Coding Space!
( ´_ゝ`) / ⌒i @hamayanhamayan0
/ \ | |
/ / ̄ ̄ ̄ ̄/ |
__(__ニつ/ _/ .| .|____
\/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/
int N, K, M;
const int MA = 251010;
int dp[101][MA];
//---------------------------------------------------------------------------------------------------
deque<int> que[101];
int tot[101];
void _main() {
cin >> N >> K >> mod;
dp[0][0] = 1;
rep(i, 0, 100) {
rep(m, 0, i + 1) {
que[m].clear();
tot[m] = 0;
}
rep(sm, 0, MA) {
if (que[sm % (i + 1)].size() == K + 1) {
int tp = que[sm % (i + 1)].front(); que[sm % (i + 1)].pop_front();
chsub(tot[sm % (i + 1)], tp);
}
que[sm % (i + 1)].push_back(dp[i][sm]);
chadd(tot[sm % (i + 1)], dp[i][sm]);
chadd(dp[i + 1][sm], tot[sm % (i + 1)]);
}
}
rep(x, 1, N + 1) {
int lft = x - 1, rht = N - x;
int ans = 0;
rep(sm, 0, MA) chadd(ans, mul(dp[lft][sm], dp[rht][sm], K + 1));
chsub(ans, 1);
printf("%d\n", ans);
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string X;
cin >> X;
int s;
for (int i = 0; i < (int)X.size(); i++) {
if (X.at(i) == '.') {
s = X.size();
for (int j = 0; j < s - i; j++) {
X.pop_back();
}
}
}
cout << X << endl;
} | #include<bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define sz(x) (ll)x.size()
#define debug(x) cout << #x << ':' << x << endl;
#define rep(i,n) for(long long i = 0; i < n ; i++)
#define reps(i,n) for(long long i = 1; i <= n ; i++)
#define make_unique(v) sort(all(v));v.erase(unique(all(v)), v.end());
#define REMOVE(v,a) v.erase(remove(v.begin(),v.end(), a), v.end());
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define endl '\n'
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
bool cmp(ll X, ll Y) {return X > Y;}
const ll MOD = 1e9 + 7;
ll gcd(ll a, ll b) {return !b ? a : gcd(b, a % b);}
ll lcm(ll a, ll b) {return (a / gcd(a, b)) * b;}
ll modpow(ll a, ll b, ll m=MOD){a %= m; ll res = 1; while (b) {if (b & 1)res = (res * a) % m; a = (a * a) % m; b >>= 1;} return res;}
ll bpow(ll a, ll b){if(b<0){return 0;}ll res = 1; while (b) {if (b & 1)res = res * a; a = a * a; b >>= 1;} return res;}
ll modinv(ll a, ll m = MOD) {return modpow(a, m - 2, m);}
const int N = 2e7+2;
const double EPS = (1e-10);
int dcp(double A, double B){return fabs(A-B)<=EPS ? 0 : A<B ? -1:1;}
map<ll,ll>cnt;
ll spf[N];
void sieve(){
for(ll i=2;i<N;i++){
if(!spf[i]){
for(ll j=i;j<N;j+=i){
spf[j]++;
}
}
}
}
ll solve(char c){
return (c-'a');
}
int main(){ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
string s;cin>>s;
string ans = "";
for(ll i = 0;i<s.length();i++){
if(s[i] == '.'){break;}
ans+=(s[i]);
}
cout<<ans;
}
|
#include<iostream>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
const int maxT=2*100010;
int main(){
int N,W;
cin >> N >> W;
int S[N], T[N], P[N];
ll as[maxT];
rep(i,maxT) as[i]=0;
rep(i,N){
cin >> S[i] >> T[i] >> P[i];
as[S[i]] += P[i];
as[T[i]] -= P[i];
}
ll sum[maxT];
rep(i,maxT) sum[i]=0;
sum[0]=0;
for(int i=0;i<=2*100000;i++){
sum[i+1] = sum[i] + as[i];
}
ll m=0;
rep(i,2*100000+2){
m = max(m, sum[i]);
}
if(m<=W) cout << "Yes" << endl;
else cout << "No" << endl;
return 0;
} | #include <bits/stdc++.h>
#define ll long long
using namespace std;
ll n,w;
ll arr[200005];
int main() {
cin >> n >> w;
for(int i=0; i<n; i++){
ll s,t,p;
cin >> s >> t >> p;
arr[s] += p;
arr[t]-=p;
}
ll sum=0;
bool flag=1;
for(int i=0; i<n; i++){
sum+=arr[i];
if(sum>w){
flag=0;
break;
}
}
if(flag==1) cout << "Yes";
else cout << "No";
return 0;
} |
#include <string>
#include <iostream>
#include <stack>
#include <queue> // priority_queue も入ってる
#include <set> // 要素数は size() で取得 multisetもある
#include <map>
#include <array> // sizeはコンパイル時定数で固定
#include <vector>
#include <numeric> // accumulate, gcd
#include <algorithm> // count_ifに必要
#include <iomanip> // cout << setprecision(15) << x で小数の出力精度を指定
#include <tuple>
#include <utility> //pair
#include <cmath>
#include <random>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); ++i)
// 小さい順(昇順)で約数をすべて列挙します。
vector<ll> allDivisors(ll n)
{
vector<ll> result;
for (ll i = 1; i <= n / i; ++i)
{
if (n % i == 0)
{
result.push_back(i);
if (n / i != i)
{
result.push_back(n / i);
}
}
}
sort(result.begin(), result.end());
return result;
}
int main()
{
ll n;
cin >> n;
n *= 2;
vector<ll> alld = allDivisors(n);
ll count = 0;
for (ll k : alld)
{
ll e = n / k;
if ((e - k + 1) % 2 == 0)
{
count++;
}
}
cout << count << endl;
return 0;
} | #include<bits/stdc++.h>
#define rep(i,n) for (int i=0; i<n; i++)
#define REP(i,x,n) for (int i=x; i<n; i++)
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
#define P pair<ll,ll>
#define T tuple<int, int, int>
#define PP pair<P,P>
#define ALL(a) a.begin(), a.end()
int main(){
int n;
cin >> n;
vi ans(n);
ans[0] = 1;
REP(i,1,n){
int MAX = 0;
i++;
for (int j=1; j*j<=i; j++){
if (i % j == 0){
MAX = max(MAX, ans[j-1]);
MAX = max(MAX, ans[i/j-1]);
}
}
i--;
ans[i] = MAX + 1;
}
rep(i,n){
cout << ans[i];
if (i < n - 1) cout << " ";
else cout << endl;
}
} |
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>
#include<map>
#include<cassert>
using namespace std;
#define ll long long
#define reps(i, a, b) for(int i = a; i < b; i++)
#define rreps(i, a, b) for(int i = a-1; i >= b; i--)
#define rep(i, n) reps(i, 0, n)
#define rrep(i, n) rreps(i, n, 0)
#define P pair<ll, ll>
#define vec vector<int>
#define mat vector<vec>
const ll mod = 1000000007;
const int INF = 1001001001;
int main(){
ll n;
cin >> n;
vector<ll> fb;
fb.push_back(0);
fb.push_back(1);
while(fb.back() < n){
fb.push_back(fb[fb.size()-1] + fb[fb.size()-2]);
}
// cout << fb.size() << endl;
// rep(i, fb.size()){
// cout << fb[i] << " ";
// }cout << endl;
vector<P> f;
int t = 0;
if(n != 1){
t = upper_bound(fb.begin(), fb.end(), n)-fb.begin();
n -= fb[t-1];
f.push_back(P(fb[t-1], 0));
}
while(n > 1){
int idx = upper_bound(fb.begin(), fb.end(), n)-fb.begin();
idx--;
ll num = fb[idx];
n -= num;
f.push_back(P(num, t-idx-1));
}
vec ans;
int now = 0;
// x, y, x, y...
if(t % 2 == 1){
rep(i, t-2){
while(now < f.size() && f[now].second == i){
if(i % 2 == 1){
ans.push_back(1);
}else{
ans.push_back(2);
}
now++;
}
if(i % 2 == 0){
ans.push_back(3);
}else{
ans.push_back(4);
}
}
}else{
rep(i, t-2){
while(now < f.size() && f[now].second == i){
if(i % 2 == 1){
ans.push_back(2);
}else{
ans.push_back(1);
}
now++;
}
if(i % 2 == 0){
ans.push_back(4);
}else{
ans.push_back(3);
}
}
}
if(n == 1) ans.push_back(1);
// cout << "t = " << t << endl;
// cout << f.size() << endl;
// rep(i, f.size()){
// cout << f[i].first << ":" << f[i].second << " ";
// }cout << endl;
// ll x = 0, y = 0;
// rep(i, ans.size()){
// if(ans[i] == 1){
// x++;
// }else if(ans[i] == 2){
// y++;
// }else if(ans[i] == 3){
// x += y;
// }else{
// y += x;
// }
// // cout << x << " " << y << endl;
// }
// cout << x << " " << y << endl;
cout << ans.size() << endl;
rep(i, ans.size()){
cout << ans[i] << endl;
}
} | #include<bits/stdc++.h>
using namespace std;
int n;
double f[200001];
int main()
{
cin>>n;
for(int i=n-1;i>=1;i--)
{
f[i]=1.0*((n-i)*(f[i+1]+1)+i)/(n-i);
}
printf("%.6lf",f[1]);
return 0;
} |
/*
NAME : RISHABH SINGH
INSTITUTION : DELHI TECHNOLOGICAL UNIVERSITY
*/
#include "bits/stdc++.h"
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define int long long
#define pii pair<int, int>
#define bi __builtin_inf()
#define ll long long
#define mp make_pair
#define ss second
#define pb push_back
#define ff first
#define speed_cubing ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define um unordered_map
#define us unordered_set
#define bp __builtin_popcount
#define ld long double
#define rep(n) for (int i = 0; i < n; i++)
#define pll pair<ll, ll>
#define mx = 1e18;
#define lb(v, val) (lower_bound(v.begin(), v.end(), val) - v.begin())
#define ub(v, val) (upper_bound(v.begin(), v.end(), val) - v.begin())
#define PI 3.1415926535
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> pbds;
ll powmod(ll base,ll exp,ll MOD){ll res=1;while(exp>0){if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return (res%MOD);}
#define sz(v) (int)v.size()
#define endl '\n'
const int mod = 1e9+7;
ll mul_inv(ll a,ll b = mod) {ll t1=a,t2=b,t3,v1=1,v2=0,v3;while(t2!=1){ll x=t1/t2;t3=t1-x*t2;v3=v1-x*v2;t1=t2,t2=t3;v1=v2,v2=v3;}return(v2+b)%b;}
const int N = 5e5+5;
int32_t main(){
speed_cubing
char s,t;
cin>>s>>t;
if(s=='Y'){
cout<<char(t-'a'+'A');
}
else
cout<<t;
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
using namespace std;
int main() {
string t;
char s;
cin >> s >> t;
if (s == 'Y') {
for (int i = 0; i < t.size(); ++i) {
t[i] = t[i] - 32;
}
cout << t << endl;
return 0;
} else {
cout << t << endl;
return 0;
}
} |
#include<bits/stdc++.h>
using namespace std;
int fa[400050],ring[400050],xd[400050];
int n,a,b,ans;
int find(int x){return x==fa[x]?x:fa[x]=find(fa[x]);}
inline int read()
{
int x=0,f=1;
char c=getchar();
while(c<'0'||c>'9')
{
if(c=='-') f=-f;
c=getchar();
}
while(c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
return x*f;
}
void merge(int x,int y)
{
int p=find(x),q=find(y);
if(p==q)
{
ring[p]=1;
return;
}
else
{
ring[p]=ring[q]=ring[p]|ring[q];
fa[p]=q;
xd[q]+=xd[p];
xd[p]=0;
}
return;
}
int vis[400050];
int main()
{
cin>>n;
for(int i=1;i<=400000;i++) fa[i]=i,xd[i]=1;
for(int i=1;i<=n;i++)
{
a=read();b=read();
if(a>b) swap(a,b);
merge(a,b);
}
for(int i=1;i<=400000;i++)
{
int p=find(i);
if(ring[p]&&vis[p]==0) ans+=xd[p],vis[p]=1;
else if(ring[p]==0&&vis[p]==0) ans+=xd[p]-1,vis[p]=1;
}
cout<<ans<<endl;
} | // **************************** Prajwal ********************************
#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<T>, rb_tree_tag, tree_order_statistics_node_update>;
// ordered_set <int> s;
// s.find_by_order(k); // returns the (k+1)th smallest element
// s.order_of_key(k); //returns the number of elements in s strictly less than k
// numbers
#define MOD (1000000007)
//const int N=200000;
const long long int INF=1000000000000;
//shortforms
#define fast ios::sync_with_stdio(0); cin.tie(0);cout.tie(0)
#define sz(v) int(v.size())
#define ff first
#define ss second
#define pb push_back
#define pob() pop_back()
#define pf(a) push_front((a))
#define pof() pop_front()
#define nl '\n'
#define all(v) v.begin(),v.end()
//max and min and sum
#define maxv(a) *max_element(all(a))
#define minv(a) *min_element(all(a))
#define sumv(A,a) accumulate(all(A),a)
//for loops
#define fof(i,a,n) for(ll i=a;i<(n);i++)
#define fob(i,n,a) for(ll i=n;i>=a;i--)
//sorting
#define rev(a) reverse(all(a))
#define as(all,A) sort((A).begin(),(A).end())
#define ds(all,A,x) sort((A).begin(),(A).end(),greater<x>())
//permutations
#define nxtp(a,b) next_permutation(a,b);
//input
#define input(A,n) fof(i,0,n){cin>>A[i];}
#define mk_pair(x,y,a,b) insert(pair<x,y >(a,b))
#define mp(x,y) make_pair(x,y)
//output
#define de(a) cerr<<a<<" ";
#define dispve(A,a,n) fof(i,a,n){cout<<A[i]<<" ";}
#define dismp(m) for(auto x : m){ cout<<x.ff<<" "<<x.ss<<"\n"; }
// shortforms
typedef long long int ll;
#define int ll
//code begins
int n,m;
void solve(int c)
{
cin>>n;
if(n%2==1){
cout<<"Odd";
return;
}
else if(n%4!=0){
cout<<"Same";
}
else{
cout<<"Even";
}
}
signed main()
{
fast;
int T=1;
cin >> T;
//cout<< fixed << setprecision(10);
int cnt = 1;
while(T--){
solve(cnt);
cnt++;
cout<<nl;
}
return 0;
}
|
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("fast-math")
#pragma GCC optimize("trapv")
#pragma GCC target("sse4")
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> pi;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef long long int ll;
typedef unsigned long long int ull;
typedef priority_queue<ll> mxhpl;
typedef priority_queue<int> mxhpi;
typedef priority_queue<ll, vector<ll>, greater<ll>> mnhpl;
typedef priority_queue<int, vector<int>, greater<int>> mnhpi;
#define rep(i,start,end) for(ll i = start; i <= end; ++i)
#define rrep(i,end,start) for(ll i = end; i >= start; --i)
#define parr(a,n) rep(i,0,n-1){cout << a[i] << " ";}cout<<"\n"
#define sarr(a,n) rep(i,0,n-1)cin >> a[i]
#define pb push_back
#define F first
#define S second
#define all(a) a.begin(),a.end()
#define mset(a,x) memset(a, x, sizeof(a))
#define ps(x,y) fixed<<setprecision(y)<<x //cout << ps(ans, decimal places);
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
// DEBUGGING
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char* x) { cerr << '\"' << x << '\"'; }
void __print(const string& x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template<typename T, typename V>
void __print(const pair<T, V>& x) { cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}'; }
template<typename T>
void __print(const T& x) { int f = 0; cerr << '{'; for (auto& i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}"; }
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); }
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
// Fast IO
void IO() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
}
#define MOD 1000000007
//CODE
/*******************************************************/
#define MX 100000
ll n;
vvl gr(400001,vl());
bool vis[400001];
bool cycle = false;
int dfs(int i, int p = -1) {
if (vis[i]) {
cycle = true;
return 0;
}
vis[i] = 1;
int ans = 1;
ll cntP = 0;
for (auto j: gr[i]) {
if (j == p && !cntP) {
cntP++;
continue;
}
ans += dfs(j,i);
}
return ans;
}
void solve() {
cin >> n;
// vector<pll> vp(n);
ll u,v;
mset(vis,0);
rep(i, 0, n - 1) {
cin >> u >> v;
gr[u].pb(v);
gr[v].pb(u);
}
ll ans = 0;
rep(i,0,400000) {
if (gr[i].size() == 0 || vis[i]) {
continue;
}
cycle = false;
ans += dfs(i);
// debug(ans, cycle);
if (!cycle) ans--;
}
cout << ans << "\n";
}
int main() {
IO();
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
}
/*******************************************************/
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"
template<class T> void chmax(T &a, const T b){ a = max(a, b); }
template<class T> void chmin(T &a, const T b){ a = min(a, b); }
long long gcd(long long a, long long b) { return (a % b) ? gcd(b, a % b) : b; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
// ifstream in("input.txt");
// cin.rdbuf(in.rdbuf());
ll n;
cin >> n;
vector<ll> a(n), b(n);
map<ll, set<ll>> num;
rep(i, n) {
cin >> a[i] >> b[i];
num[a[i]].insert(i);
num[b[i]].insert(i);
}
queue<ll> q;
for(auto x : num) {
if (sz(x.second) == 1) {
q.push(x.first);
}
}
while(!q.empty()) {
ll val = q.front(); q.pop();
if (sz(num[val]) != 1) continue;
ll idx = *num[val].begin();
if (a[idx] != b[idx]) {
ll nv = (a[idx] == val) ? b[idx] : a[idx];
num[nv].erase(idx);
if (sz(num[nv]) == 1) q.push(nv);
}
}
ll ans = 0;
for(auto x : num) {
if (sz(x.second) > 0) ans++;
}
cout << ans << endl;
return 0;
}
|
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<vector>
#define rg register
template<typename T>void read(rg T &x){
x=0;rg int fh=1;
rg char ch=getchar();
while(ch<'0' || ch>'9'){
if(ch=='-') fh=-1;
ch=getchar();
}
while(ch>='0' && ch<='9'){
x=(x<<1)+(x<<3)+(ch^48);
ch=getchar();
}
x*=fh;
}
long long n,ans;
int main(){
read(n);
rg long long now=1;
rg int cnt=0,num=0;
while(1){
if(n>=now*10-1){
ans+=1LL*num*(now*10-now);
} else {
ans+=1LL*num*(n-now+1);
break;
}
cnt++;
now*=10;
if(cnt%3==0) num++;
}
printf("%lld\n",ans);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=double;
using vll=vector<ll>;
using vvll=vector<vector<ll>>;
#define FOR(i,a,b) for(ll i=a;i<(ll)b;++i)
#define F(n) FOR(i,0,n)
#define FF(n) FOR(j,0,n)
#define aa first
#define bb second
#define PB push_back
#define EQ(a,b) (fabs(a-b)<=(fabs(a+b)*EPS))
#define MOD ((ll)(1e9+7))
#define dbg cerr
#define out(n) cout << n << '\n'
//#define dbg if(0)cerr
int main(){
ios::sync_with_stdio(0);cin.tie(0);
vector<pair<ll,ll>> a = {{1e3 - 1, 0},{1e6 - 1, 1},{1e9 - 1, 2},{1e12 - 1, 3},{1e15 - 1,4},{1e18 - 1, 5}};
ll n;
cin>>n;
ll res = 0;
for (int i = 0; i < a.size(); ++ i) {
res += min(a[i].aa,n) * a[i].bb;
if (i > 0) res -= min(a[i-1].aa,n) * a[i].bb;
if (a[i].aa > n) break;
}
out(res);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using iPair = pair<int,int>;
using lPair = pair<ll, ll>;
using ivector = vector<int>;
using lvector = vector<ll>;
using istack = stack<int>;
using iqueue = queue<int>;
using ivv = vector<vector<int>>;
using lvv = vector<vector<ll>>;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
vector<iPair> dir = {{1,0}, {-1,0}, {0,1}, {0,-1}};
#define dump(x) cout << #x << " = " << (x) << endl
#define ALL(x) begin(x),end(x)
#define rep(i,s,e) for(ll i=(s), i_stop=(e); i<i_stop; ++i)
#define repRev(i,s,e) for(ll i=(e)-1, i_stop=(s); i>=i_stop; --i)
#define range(i,s,n) for(ll i=(s), i_stop=(s)+(n); i<i_stop; ++i)
#define rangeRev(i,s,n) for(ll i=(s), i_stop=(s)-(n); i>i_stop; --i)
#define foreach(x,container) for(auto &&x:container)
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;}
template<typename T> void printArr(vector<T> &arr){
for(auto &x:arr) {cout << x << " ";} cout << endl;
}
// =====================================================>
/*
*/
void solve() {
int n; cin>>n;
ivector cnt(n+1, 0);
ivector a(n+1);
range(i, 0, n) {cin>>a[i]; ++cnt[a[i]];}
for(int i = 1; i <= n; ++i) {
if(cnt[i] == 0) {cout<<"No"<<endl; return;}
}
cout << "Yes" << endl;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
solve();
return 0;
} | //Saptak_Roy_Turja
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
string s;
cin>>s;
if(s[0]==s[1]&&s[0]==s[2]){
cout<<"Won"<<endl;
}
else {
cout<<"Lost"<<endl;
}
}
|
#include <iostream>
#include <vector>
#include <set>
#include <map>
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;
}
int main(int argc, char **argv)
{
int n, m, q;
std::cin.tie(0);
std::ios_base::sync_with_stdio(false);
std::cin >> n >> m >> q;
std::set<int> s = { 0 };
std::vector<int> ta(q), xa(q), ya(q);
for (int i = 0; i < q; i++) {
std::cin >> ta[i] >> xa[i] >> ya[i];
xa[i]--;
s.insert(ya[i]);
}
std::vector<int> arr(s.begin(), s.end());
std::map<int, int> map;
int ll = s.size();
for (int i = 0; i < ll; i++) map.emplace(arr[i], i);
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);
std::cout << sum << std::endl;
}
return 0;
} | // give up
#include <bitset>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <list>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <valarray>
// alias, using declaration
using llint = long long; using ldouble = long double;
template <class T = llint> using vector = std::vector<T>;
template <class T = llint> using deque = std::deque<T>;
template <class T = llint> using list = std::list<T>;
template <class T = llint, class U = llint> using umap = std::unordered_map<T, U>;
template <class T = llint, class U = llint> using ummap = std::unordered_multimap<T, U>;
template <class T = llint> using uset = std::unordered_set<T>;
template <class T = llint> using umset = std::unordered_multiset<T>;
template <class T = llint, class U = T> using pair = std::pair<T, U>;
template <class T = llint> using varray = std::valarray<T>;
template <class T = llint, class U = vector<T>, class V = std::less<class U::value_type>> using pqueue = std::priority_queue<T, U, V>;
using std::array; using std::bitset; using std::string; using std::tuple;
// constant
constexpr llint INF = 0x7FFFFFFFFFFFFFFF;
constexpr llint INVALID = 0x8000000000000000;
namespace io {
// in
template <class... T, size_t... S> auto in(std::index_sequence<S...>) {tuple<T...> t; (..., (std::cin >> std::get<S>(t))); return t;}
template <class... T, size_t... S> auto in(std::index_sequence<S...>, size_t n) {tuple<vector<T>...> t{vector<T>(n)...}; for (size_t i = 0; i < n; i++) (..., (std::cin >> std::get<S>(t)[i])); return t;}
template <size_t N, class T = llint, class... U> auto in() {static_assert(N >= 1); if constexpr (N > 1) return in<N - 1, T, T, U...>(); else return in<T, U...>(std::index_sequence_for<T, U...>());}
template <size_t N, class T = llint, class... U> auto in(size_t n) {static_assert(N >= 1); if constexpr (N > 1) return in<N - 1, T, T, U...>(n); else return in<T, U...>(std::index_sequence_for<T, U...>(), n);}
template <size_t N, class T = llint> auto in(size_t n, size_t m) {static_assert(N == 1); vector<vector<T>> v(n, vector<T>(m)); for (auto&& vi : v) for (auto&& vij : vi) std::cin >> vij; return std::make_tuple(v);}
// out
template <class T, class... U> void out(const T& a, const U&... b) {std::cout << a << (sizeof...(b) ? " " : "\n"); if constexpr (sizeof...(b)) out(b...);}
template <class T, class U = const char*> void out(const vector<T>& a, U d = " ") {for (auto&& b : a) std::cout << b << (&b != &a.back() ? d : "\n");}
}
int main() {
// input
auto [N, M, Q] = io::in<3>();
auto [T, X, Y] = io::in<3>(Q);
// solve
vector<> a(N + 1), b(M + 1);
umap<> Z;
{
Z.emplace(0, 0);
vector<> Y_ = Y;
std::sort(Y_.begin(), Y_.end());
for (llint i = 0; i < Q; i++) Z.emplace(Y_.at(i), i + 1);
}
constexpr llint ST_SIZE = 1 << 19;
vector<pair<>> st_a(ST_SIZE), st_b(ST_SIZE);
auto update = [&Z](vector<pair<>>& st, llint v, llint n) {
for (llint i = (ST_SIZE >> 1) + Z.at(v); i > 0; i >>= 1) {
st.at(i).first += n;
st.at(i).second += v * n;
}
};
auto culc_line = [&Z](const vector<pair<>>& st, llint v) {
llint r = st.at((ST_SIZE >> 1) + Z.at(v)).second;
for (llint i = (ST_SIZE >> 1) + Z.at(v); i > 1; i >>= 1) {
r += i & 1 ? st.at(i ^ 1).first * v : st.at(i ^ 1).second;
}
return r;
};
update(st_a, 0, N);
update(st_b, 0, M);
vector<> result(Q);
for (llint i = 0; i < Q; i++) {
auto& t = (T.at(i) == 1 ? a : b).at(X.at(i));
auto& st_x = T.at(i) == 1 ? st_a : st_b;
auto& st_y = T.at(i) == 1 ? st_b : st_a;
update(st_x, t, -1);
result.at(i) = -culc_line(st_y, t);
t = Y.at(i);
update(st_x, t, 1);
result.at(i) += culc_line(st_y, t);
}
for (llint i = 1; i < Q; i++) result.at(i) += result.at(i - 1);
// output
io::out(result, "\n");
} |
#include <bits/stdc++.h>
#define ll long long int
#define db double
#define pb push_back
#define mpr make_pair
#define andl "\n"
#define f first
#define s second
#define mset(x,y) memset(x,y,sizeof(x))
#define fr(i,n) for(long long int i=0;i<n;i++)
#define trace(it,x) for(auto it = (x).begin(); it != (x).end(); it++)
#define mod 1000000007
#define fastio ios::sync_with_stdio (false); cin.tie (0); cout.tie (0);
#define runtime cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n" ;
using namespace std;
// convert number to string to_string(x);
// convert string to number stoi();
// ll mulmod(ll x,ll y)
// {
// return ((x%mod)*(y%mod))%mod;
// }
// ll ModInv(ll x, ll y)
// {
// ll z = 1;
// while(y > 0)
// {
// if(y % 2 == 1)
// z = mulmod(z, x);
// x = mulmod(x, x);
// y /= 2;
// }
// return z;
// }
// ll ncr(ll n,ll r)
// {
// return mulmod(fact[n],ModInv(mulmod(fact[n-r],fact[r]),mod-2));
// }
// ll pwr(ll n,ll m)
// {
// if(n==1 || m==0)
// return 1;
// ll x=pwr(n,m/2);
// if(m%2==0)
// return x*x;
// else
// return n*x*x;
// }
// ll pwr(ll n,ll m,ll b)
// {
// if(n==1 || m==0)
// return 1;
// ll x=pwr(n,m/2,b);
// if(m%2==0)
// return ((x%b)*(x%b))%b;
// else
// return ((n%b)*(((x%b)*(x%b))%b))%b;
// }
void solve()
{
ll a,b,k;
cin >> a >> b >> k;
ll dp[31][31];
fr(i,31)
fr(j,31)
{
if(i==0 || j==0)
dp[i][j]=1;
else
dp[i][j]=dp[i-1][j]+dp[i][j-1];
}
string s;
while(a>0 && b>0)
{
if(dp[a-1][b]>=k)
a--,s+='a';
else
{
k-=dp[a-1][b];
b--;
s+='b';
}
}
while(a--)
s+='a';
while(b--)
s+='b';
cout << s;
return ;
}
int main()
{
fastio
ll t=1;
// cin >> t;
while(t--)
solve();
runtime
} | #include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
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<class V, int ME> class BIT {
public:
V bit[1<<ME];
V operator()(int e) {if(e<0) return 0;V s=0;e++;while(e) s+=bit[e-1],e-=e&-e; return s;}
void add(int e,V v) { e++; while(e<=1<<ME) bit[e-1]+=v,e+=e&-e;}
};
BIT<ll,21> bt;
int N;
int A[606060];
void solve() {
int i,j,k,l,r,x,y; string s;
cin>>N;
ll ret=0;
FOR(i,N) {
cin>>A[i];
ret+=bt(N)-bt(A[i]);
bt.add(A[i],1);
}
FOR(i,N) {
cout<<ret<<endl;
ret-=A[i];
ret+=N-1-A[i];
}
}
int main(int argc,char** argv){
string s;int i;
if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
cout.tie(0); solve(); return 0;
}
|
#include <bits/stdc++.h>
#define ff first
#define ss second
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
#define all(x) x.begin(), x.end()
const int inf = 1e4;
void solve() {
int n, m, u, v;
cin >> n >> m;
vector <vector <bool>> adj(n + 1, vector <bool> (n + 1));
vector <int> dp(1 << n, n + 1);
dp[0] = 0;
for (int i = 0; i < m; i++) {
cin >> u >> v;
adj[u][v] = true;
adj[v][u] = true;
}
for (int k = 1; k < (1 << n); k++) {
dp[k] = 1;
for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++) {
if ((k >> i) & (k >> j) & 1)
if (adj[i + 1][j + 1] == false)
dp[k] = inf;
}
}
for (int i = 0; i < (1 << n); i++) {
for (int j = i; j > 0; j = (j - 1) & i) {
dp[i] = min(dp[i], dp[j] + dp[i ^ j]);
}
}
cout << dp[(1 << n) - 1] << '\n';
}
int main() {
#ifndef ONLINE_JUDGE
freopen("E:\\inp.txt", "r", stdin); freopen("E:\\outp.txt", "w", stdout);
#endif
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
solve();
return 0;
} | #include<bits/stdc++.h>
using namespace std;
template<typename T>inline bool read(T&x){
x=0;char c=getchar();int f=1;while(!isdigit(c)&&(c!='-')&&(c!=EOF))c=getchar();
if(c==EOF)return 0;if(c=='-')f=-1,c=getchar();
while(isdigit(c)){x=(x<<1)+(x<<3)+(c&15);c=getchar();}x*=f;return 1;
}template<typename T,typename...Args>inline bool read(T&x,Args&...args){bool res=1;res&=read(x);res&=read(args...);return res;}
typedef long long LL;typedef unsigned long long u64;typedef unsigned u32;typedef long double LD;
#define il inline
#define pln putchar('\n')
#define For(i,a,b) for(int i=(a),(i##i)=(b);i<=(i##i);++i)
#define Rep(i,n) for(int i=0,(i##i)=(n);i<(i##i);++i)
#define Fodn(i,a,b) for(int i=(a),(i##i)=(b);i>=(i##i);--i)
const int M=1000000007,INF=0x3f3f3f3f;const long long INFLL=0x3f3f3f3f3f3f3f3fLL;
const int N=111;
/*********************数论*********************/
inline LL mul(LL a,LL b,LL p){const LL res=a*b-((LL)((LD)a*b/p)*p);return res<0?res+p:(res<p?res:res-p);}
inline LL fp(LL a,LL b,LL Mod){LL res=(Mod!=1);for(;b;b>>=1,a=a*a%Mod)if(b&1)res=res*a%Mod;return res;}
inline LL fpl(LL a,LL b,LL Mod){LL res=(Mod!=1);for(;b;b>>=1,a=mul(a,a,Mod))if(b&1)res=mul(res,a,Mod);return res;}
template<typename T>inline T gcd(T a,T b){while(b){T t=b;b=a%b;a=t;}return a;}template<typename T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
template<typename T>inline T exgcd(T a,T b,T&x,T&y){T m=0,n=1,t;x=1,y=0;while(b){t=m,m=x-a/b*m,x=t;t=n,n=y-a/b*n,y=t;t=b,b=a%b,a=t;}return a;}
inline LL Crt(LL a1,LL a2,LL mod1,LL mod2){LL u,v;const LL g=exgcd(mod1,mod2,u,v);if((a2-a1)%g)return -1;
const LL m12=abs(lcm(mod1,mod2)),res=(mul(mod1,mul(u,((a2-a1)/g),m12),m12)+a1)%m12;return res<=0?res+m12:res;/*求最小正数解还是非负解*/}
/*********************数论*********************/
LL n,m,k,d[N];
struct Mat{
LL a[N][N];
Mat(){memset(a,0,sizeof a);}
void set(){for(int i=1;i<=n;++i)a[i][i]=1;}
Mat operator*(const Mat&b)const{
Mat res;
for(int i=1;i<=n;++i)for(int k=1;k<=n;++k)for(int j=1;j<=n;++j)res.a[i][j]=(res.a[i][j]+(a[i][k]*b.a[k][j])%M)%M;
return res;
}
Mat pow(LL b)const{
Mat a=(*this),res;
for(res.set();b;b>>=1,a=a*a)if(b&1)res=res*a;
return res;
}
};
LL a[N],mp[N][N];
LL im;
inline void init(){
read(n,m,k);im=fpl(2ll*m,M-2,M);
For(i,1,n)read(a[i]);
For(i,1,m){
int u,v;read(u,v);mp[u][v]=1;mp[v][u]=1;++d[u];++d[v];
}
For(i,1,n)mp[i][i]=mul((2ll*m-d[i]),im,M);
For(i,1,n)For(j,1,i-1){
if(mp[i][j]==0)continue;
mp[i][j]=mp[j][i]=im;
}
}
LL ans[N];
inline void solve(){
Mat f;
For(i,1,n)For(j,1,n)f.a[i][j]=mp[i][j];
f=f.pow(k);
For(i,1,n)For(j,1,n)ans[i]=(ans[i]+mul(a[j],f.a[j][i],M))%M;
For(i,1,n)ans[i]=(ans[i]+M)%M;
For(i,1,n)printf("%lld\n",ans[i]);
}
signed main(){
init();solve();
return 0;
} |
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;
int h, w;
string s[2000];
int a[2000][2000];
bool used[2000][2000];
int dp[2000][2000];
int INF = 1e+6;
//高橋君 - 青木君
int dfs(int y, int x) {
if (y == h - 1 && x == w - 1) return 0;
if (used[y][x]) return dp[y][x];
int res;
int mul = (y + x) % 2 ? -1 : 1;
int ret = (mul == 1) ? -INF : INF;
if (x < w - 1) {
res = mul * a[y][x + 1] + dfs(y, x + 1);
if (mul == 1) ret = max(res, ret);
else ret = min(res, ret);
}
if (y < h - 1) {
res = mul * a[y + 1][x] + dfs(y + 1, x);
if (mul == 1) ret = max(res, ret);
else ret = min(res, ret);
}
used[y][x] = true;
return dp[y][x] = ret;
}
signed main() {
int i, j;
cin >> h >> w;
rep(i, h) cin >> s[i];
rep(i, h) rep(j, w) dp[i][j] = -1;
rep(i, h) {
rep(j, w) {
if (s[i][j] == '-') a[i][j] = -1;
else a[i][j] = 1;
}
}
int res = dfs(0, 0);
//cout << "res = " << res << endl;
if (res > 0) cout << "Takahashi" << endl;
else if (res == 0) cout << "Draw" << endl;
else cout << "Aoki" << endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define lld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define f first
#define s second
#define mk make_pair
/*----------------------DEBUGGER---------------------------*/
#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x <<" "; _print(x); cerr << endl;
#else
#define debug(x)
#endif
void _print(ll t) {cerr << t;}
void _print(int t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(lld t) {cerr << t;}
void _print(double t) {cerr << t;}
void _print(ull t) {cerr << t;}
template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.f); cerr << ","; _print(p.s); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}
/*----------------------DEBUGGER---------------------------*/
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
freopen("error.txt", "w", stderr);
#endif
int tt = 1;
//cin >> tt;
while (tt--)
{
int n;
cin >> n;
ll a[n];
for (int i = 0; i < n; i++)
cin >> a[i];
if (n == 1) {
cout << a[0];
return 0;
}
ll dp[n][2];
ll num[n][2];
memset(dp, 0, sizeof(dp));
memset(num, 0, sizeof(num));
ll mod = 1e9 + 7;
dp[1][0] = (a[0] + a[1]) % mod;
dp[1][1] = (a[0] - a[1] + mod) % mod;
num[1][0] = 1;
num[1][1] = 1;
for (int i = 2; i < n; i++)
{
dp[i][0] = (dp[i - 1][0] + (num[i - 1][0] * a[i]) % mod + dp[i - 1][1] + (num[i - 1][1] * a[i]) % mod) % mod;
dp[i][1] = (dp[i - 1][0] - (num[i - 1][0] * a[i]) % mod + mod) % mod;
num[i][0] = (num[i - 1][0] + num[i - 1][1]) % mod;
num[i][1] = num[i - 1][0];
}
for (int i = 1; i < n; i++)
{
debug(dp[i][0]);
debug(dp[i][1]);
}
cout << (dp[n - 1][0] + dp[n - 1][1]) % mod;
}//while
}//main |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;
void Main(){
int n; cin >> n;
set<int> st;
rep3(i, 0, 200005) st.insert(i);
rep(i, n){
int p; cin >> p;
if(st.find(p) != st.end()) st.erase(p);
cout << *st.begin() << endl;
}
return;
}
int main(){
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(15);
Main();
return 0;
} | // Best practice
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define pf emplace_front
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pii pair<int,int>
#define psi pair<string,int>
#define vi vector<int>
#define vpii vector<pii>
#define vvi vector<vi>
#define sz(x) (int)(x).size()
#define x first
#define y second
#define endl '\n'
#define tezz ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MOD 1000000007
#define hell 998244353
#define prec(n) fixed<<setprecision(n)
#define ini(a, i) memset(a, i, sizeof(a))
#define output(x) cout << (x ? "YES" : "NO")<<endl;
using namespace std;
#define debug(vec) cout<<(#vec)<<" : [ "; for (auto& i: vec) cout<<i<<" "; cout<< "]" << endl
#define trace(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);cout << endl; }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cout << "[" << *it << ": " << a << "]\t";
err(++it, args...);
}
// const int dx[4] = { -1, 1, 0, 0};
// const int dy[4] = {0, 0, -1, 1};
// int dX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
// int dY[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
// Code from Here -------------------------------------------------------------------------------
void solver(){
int n, p;
cin >> n;
int c = 0;
map<int,int> mp;
for(int i=0; i<n; i++){
cin >> p;
mp[p]++;
while(mp[c]){
c++;
}
cout << c << endl;
}
}
signed main() {
tezz
int t=1;
// cin >> t;
while(t--){
solver();
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int main(){
int64_t a,b,c,d;
cin>>a>>b>>c>>d;
if(a==c&&b==d){cout<<0<<endl;}
else if(a+b==c+d||a-b==c-d||abs(a-c)+abs(b-d)<=3){cout<<1<<endl;}
else if((a+b-c-d)%2==0||abs(a-c)+abs(b-d)<=6||abs(a+b-c-d)<=3||abs(a-b-c+d)<=3)
{cout<<2<<endl;}
else{cout<<3<<endl;}
} | #include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define REPA(x, v) for(auto&& x:v)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(v.rbegin(),v.rend())
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " " ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> void pr_vec(vector<T> &v, char ep=' '){int n=v.size();REP(ni,n){cout<<v[ni];if(ni!=n-1)cout<<ep;}cout<<endl;};
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
int main(void)
{
ll r1,c1,r2,c2;
cin >> r1 >> c1 >> r2 >> c2;
r2 -= r1;
c2 -= c1;
ll rc = abs(c2 - r2);
ll cr = abs(r2 - c2);
if(r2 == 0 && c2 == 0){
pr(0);
return 0;
}else if((abs(r2)+abs(c2)<=3) || (abs(r2)==abs(c2))){
pr(1);
return 0;
}else{
if((abs(r2)+abs(c2)<=6) || ((abs(r2)+abs(c2))%2)==0){
pr(2);
return 0;
}
for(int i = -3; i <=3 ; i++) for(int j = -3; j <=3 ; j++){
if(abs(i)+abs(j) > 3) continue;
ll tr = r2 - i;
ll tc = c2 - j;
if(abs(tr)==abs(tc)){
pr(2);
return 0;
}
}
}
pr(3);
} |
#include <bits/stdc++.h>
using namespace std;
const int P = 998244353;
//const int P = 1e9 + 7;
//const int P = 1e9 + 9;
int mul(const int &x, const int &y) { return 1ll * x * y % P; }
int qpow(int x, int y) {
if (y < 0) {
y += P - 1;
}
int r = 1;
while (y) {
if (y & 1) {
r = mul(r, x);
}
x = mul(x, x);
y /= 2;
}
return r;
}
int inc(const int &x, const int &y) {
if (x + y >= P) {
return x + y - P;
} else {
return x + y;
}
}
int sub(const int &x, const int &y) {
if (x < y) {
return x - y + P;
} else {
return x - y;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
std::string s;
cin >> s;
int n = (int)s.size();
std::string t = "atcoder";
if (s > t) {
cout << 0 << '\n';
continue;
}
bool flag = true;
for (int i = 0; i < n; i++) {
if (s[i] != 'a') {
flag = false;
}
}
if (flag) {
cout << -1 << '\n';
continue;
}
int ans = n + 1;
for (int i = 0; i < n; i++) {
int cnt = 0;
std::string temp = s;
for (int j = i; j >= 1; j--) {
swap(temp[j], temp[j - 1]);
++cnt;
if (cnt >= ans) {
break;
}
if (temp > t) {
ans = cnt;
break;
}
}
cnt = 0;
temp = s;
for (int j = i; j < n - 1; j++) {
swap(temp[j], temp[j + 1]);
++cnt;
if (cnt >= ans) {
break;
}
if (temp > t) {
ans = cnt;
break;
}
}
}
cout << ans << '\n';
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#pragma region DEBUG
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef
tree<
pair<int,int>,
null_type,
less<pair<int,int>>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#pragma endregion DEBUG
#define MOD 1000000007
#define MAX 500005
#define endl "\n"
vector <lli> fact(MAX,1);
vector <lli> invfact(MAX,1);
lli n;
vector <lli> arr;
lli dp[3005][3005];
map <lli, vector<vector<lli> >> adj;
vector <lli> pre;
lli ctr = 0;
lli f(lli idx, lli head){
if(head > n)
return 0;
if(idx == n+1)
return 1;
// debug("Yeet");
if(dp[idx][head] != -1)
return dp[idx][head];
lli ans = 0;
lli sum = 0;
lli prefsum = pre[idx-1]%head;
for(auto i : adj[head][prefsum]){
if(i >= idx){
if(i+1 == n+1){
ans += 1;
}
else{
ans += f(i+1,head+1);
ans += f(i+1,head);
}
break;
}
}
ans %= MOD;
//debug(idx,head,ans);
//debug(ans);
return dp[idx][head] = ans;
}
void solve(){
cin>>n;
arr.resize(n);
pre.resize(n+1,0);
for(lli i = 0; i<=n+1; i++){
for(lli j = 0; j<=n+1; j++){
dp[i][j] = -1;
}
}
for(lli i = 0; i<n; i++){
cin>>arr[i];
pre[i+1] = pre[i] + arr[i];
}
for(lli head = 1; head <=n; head++){
adj[head].resize(head);
lli sum = 0;
adj[head][0].push_back(0);
for(lli i = 0; i<n; i++){
sum += arr[i];
sum %= head;
adj[head][sum].push_back(i+1);
}
}
// debug("Yoot");
//debug(adj[1]);
lli valx = f(1,1);
cout<<valx<<endl;
}
int main(){
/* freopen("input.txt", "r", stdin);
freopen("output1.txt", "w", stdout); */
ios_base::sync_with_stdio(false);
cin.tie(NULL);
/* for(lli i = 1; i<MAX-5; i++){
fact[i] = i*fact[i-1]%MOD;
invfact[i] = binpow(fact[i],MOD-2);
} */
lli t;
t = 1;
//cin>>t;
lli p = 0;
while(t--){
p++;
solve();
}
} |
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<ll(n);i++)
#define YESNO(T) if(T){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(T) if(T){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
const double pi = 3.14159265358979;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
ll a,b;
cin >> a >> b;
cout << (a+b)/2 << " " << (a-b)/2 << endl;
} | #include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <regex>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using dl = long double;
using P = pair<int, int>;
int main() {
int n;
cin >> n;
vector<ll> v(n);
ll sum = 0;
rep(i, n) {
ll a, b;
cin >> a >> b;
sum += a;
v[i] = a + a + b;
}
sort(v.begin(), v.end());
int ans = 0;
while (sum >= 0) {
sum -= v.back();
v.pop_back();
ans++;
}
cout << ans << endl;
} |
#include <bits/stdc++.h>
#include <math.h>
#define REP(i,a,b) for (int i=a; i<b; i++)
#define ALL(v) (v).begin(), (v).end()
#define FORE(i,a) for(auto &i:a)
using namespace std;
typedef long long ll;
const ll infl = 1LL << 60;
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; }
//#pragma GCC optimize ("-O3")
void _main(); int main() {cin.tie(0); ios::sync_with_stdio(false); _main(); }
void _main() {
ll N;
cin >> N;
vector<ll> A(N);
REP(i,0,N) cin >> A[i];
ll ans = 0;
ll every_sum = 0;
ll sq_sum = 0;
REP(i,0,N) {
every_sum += A[i]*A[i];
sq_sum += A[i];
}
ans = N*every_sum - sq_sum*sq_sum;
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int main() {
ll N;
cin >> N;
vector<string> vec(N);
rep(i, N) {
cin >> vec.at(i);
if(vec.at(i).at(0) != '!') {
vec.at(i) = "!" + vec.at(i) + "&";
}
}
ll co = -1;
sort(vec.begin(), vec.end());
rep(i, N - 1) {
if(vec.at(i) != vec.at(i+1) && vec.at(i) + "&" == vec.at(i+1)) {
co = i;
break;
}
}
if(co == -1) {
cout << "satisfiable";
}
else {
cout << vec.at(co).substr(1);
}
} |
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, k, n) for (int i = k; i < (int)(n); i++)
#define repd(i, n) for (int i = n-1; i >= 0; i--)
#define rrepd(i, k, n) for (int i = n-1; i >= (int)(k); i--)
#define all(x) (x).begin(),(x).end()
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define F first //pairの一つ目の要素 //遅延セグ木使うときは注意
#define S second //pairの二つ目の要素 //遅延セグ木使うときは注意
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
//V,Pは大文字i,l,bは小文字
using ll = long long;
using Vi = vector<int>;
using VVi = vector<Vi>;
using Vl = vector<ll>;
using VVl = vector<Vl>;
using Vb = vector<bool>;
using VVb = vector<Vb>;
using P = pair<int,int>;
using Pl = pair<ll, ll>;
using Vs = vector<string>;
const ll mod = 1000000007;
const ll inf = 1000000000000000000;//10の18乗
#define yn {puts("Yes");}else{puts("No");}
#define dame { puts("-1"); return 0;}
int main() {
ll a,b;
cin >> a >> b;
long double x=a;
x*=b;
x/=100;
cout << fixed << setprecision(15);
cout << x << endl;
}
| #include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using Graph = vector<vector<int>>;
int main() {
float a, b;
cin >> a >> b;
float ret = b / 100 * a;
cout << ret << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<ll, ll> Pair;
typedef vector<Pair> VP;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define all(a) (a).begin(),(a).end()
#define VEC(n, x) VI n; n.resize(x); rep(i, x) cin >> n[i];
#define MAT(m, x, y) VVI m; m.resize(x); rep(i, x) m[i].resize(y);
#define out(x) cout << (x) << endl;
int main () {
int N; cin >> N;
VI x(N), y(N); rep(i, N) cin >> x[i] >> y[i];
rep(i, N) rep(j, N) rep(k, N) {
if (i == j || i == k || j == k) continue;
if ((x[i] == x[j] && x[i] == x[k]) || (y[i] == y[j] && y[i] == y[k])) {
out("Yes")
return 0;
}
double a = (y[j] - y[i]) * (x[k] - x[i]) / (double)(x[j] - x[i]) + y[i];;
if ((double)y[k] == a) {
out("Yes")
return 0;
}
}
out("No");
return 0;
} | #include<bits/stdc++.h>
using namespace std;
int n; vector<int> ans;
const int MAX=5e2+7;
int s[MAX],p[MAX];
void opt (int pos) {
swap(p[s[pos]],p[s[pos+1]]);
swap(s[pos],s[pos+1]);
ans.push_back(pos);
return;
}
void solve (int p1,int p2,int p3) {
while (!(s[p1]<s[p2]&&s[p2]<s[p3])) {
if (ans.size()%2==p1%2) opt(p2);
else opt(p1);
} return;
}
void solve () {
scanf("%d",&n); ans.clear();
for (int i=1;i<=n;i++)
scanf("%d",&s[i]),p[s[i]]=i;
if (n==1) { puts("0"); return; }
if (n==2) {
if (s[1]>s[2]) puts("1"),puts("1");
else puts("0");
return;
}
if (n==3) solve(1,2,3);
const int odd=n&1?n-2:n-1;
const int eve=n&1?n-1:n-2;
for (int i=1;i<=n-3;i++) {
rst:
if (p[i]&1) {
if (ans.size()%2==0)
{ opt(odd); goto rst; }
for (int t=p[i]-1;t>=i;t--)
opt(t);
} else {
if (ans.size()%2==1)
{ opt(eve); goto rst; }
for (int t=p[i]-1;t>=i;t--)
opt(t);
}
}
solve(n-2,n-1,n);
printf("%d\n",ans.size());
for (auto cur:ans)
printf("%d ",cur);
printf("\n");
return;
}
int main () {
int T; scanf("%d",&T);
while (T--) solve();
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int main(){
string s; cin >> s;
int n = s.size();
int ans = 0;
for(int i = 1; i <= (n-1)/2; i++){
ans += 9*pow(10,i-1);
}
if(n%2 == 0){
string sl = s.substr(0,n/2);
string sr = s.substr(n/2);
ans += stoi(sl)-pow(10,n/2-1)+1;
if(sl > sr) ans--;
}
cout << ans << endl;
} | #include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;
void solve()
{
ull MAX = 1e18;//((ull)1)<<60;
//cerr<<MAX<<endl;
ull n;
cin>>n;
vector<ull> P3, P5;
ull z = 3;
while(z<MAX) {
P3.push_back(z);
z*=3;
}
z = 5;
while(z<MAX) {
P5.push_back(z);
z*=5;
}
for(int i=0; i<P3.size(); ++i)
for(int j=0; j<P5.size(); ++j)
if(P3[i]+P5[j] == n){
cout<<(i+1)<<" "<<(j+1)<<endl;
return;
}
cout<<-1<<endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int T = 1;
//cin>>T;
while(T--)
solve();
return 0;
} |
#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>;
using Graph = vector<vector<int>>;
// 二次元幾何は複素数で考えると楽になるかもしれない
using C = complex<double>;
C inC() {
double x, y;
cin >> x >> y;
return C(x, y);
}
int main() {
int n;
cin >> n;
C s = inC();
C t = inC();
C o = (s + t) / 2.0;
double PI = acos(-1);
double rad = 2 * PI / n;
C r(cos(rad), sin(rad));
C ans = o + (s - o) * r;
printf("%.10f %.10f\n", ans.real(), ans.imag());
return 0;
} | #include <iostream>
using namespace std;
int main()
{
int a,b,temp1[3],temp[3];
cin>>a>>b;
temp[0]=a%10;
a=a/10;
temp[0]+=a%10;
a=a/10;
temp[0]+=a%10;
a=temp[0];
temp[1]=b%10;
b=b/10;
temp[1]+=b%10;
b=b/10;
temp[1]+=b%10;
b=temp[1];
if(a>=b)
cout<<a;
else if(b>a)
cout<<b;
}
|
#include<iostream>
#define FAST ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
typedef long long ll;
const int MAXN=1e5+5;
int ok(int n, int base) {
while(n) {
if(n%base == 7) return 0;
n/=base;
}
return 1;
}
int main() {
FAST;
int n; cin>>n;
int ans=0;
for(int i=1;i<=n;++i) {
if(ok(i, 8) && ok(i, 10)) ++ans;
}
cout<<ans<<endl;
} | #include <bits/stdc++.h>
using namespace std;
int main(){
int N;
cin >> N;
cout << N - 1;
} |
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;
void solve(){
ll s,p;
cin>>s>>p;
for(ll i = 1;i*i<=p;i++){
if(p % i == 0){
if(i + p/i == s){
cout<<"Yes";
return;
}
}
}
cout<<"No";
}
int main(){
int t = 1;
while(t--)
solve();
return 0;
} | #include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cerr<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;
int main() {
ll s,p;cin >> s >> p;
if(1+p == s){
cout << "Yes" << endl;
return 0;
}
bool isok = false;
for(ll n=1;n*n<=p; n++){
if(p%n == 0){
ll m = p/n;
if(n+m == s) isok = true;
}
}
if(isok) cout << "Yes" << endl;
else cout << "No" << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve() {
int h, w;
cin>>h>>w;
vector<string> grid(h);
for(auto &i : grid) {
cin>>i;
}
vector<vector<int>> dp(h, vector<int> (w, -1e9));
for(int i=h-1; i>=0; i--) {
for(int j=w-1; j>=0; j--) {
if(i+1<h) {
int option=-dp[i+1][j];
if(grid[i+1][j]=='+') {
option++;
} else {
option--;
}
dp[i][j]=max(dp[i][j], option);
}
if(j+1<w) {
int option=-dp[i][j+1];
if(grid[i][j+1]=='+') {
option++;
} else {
option--;
}
dp[i][j]=max(dp[i][j], option);
}
if(i==h-1 && j==w-1) {
dp[i][j]=0;
}
}
}
string ans="Takahashi";
if(dp[0][0]<0) {
ans="Aoki";
} else if(dp[0][0]==0) {
ans="Draw";
}
cout<<ans<<endl;
return;
}
int main() {
#ifdef bipinpathak
(void)!freopen("input.txt", "r", stdin);
(void)!freopen("output.txt", "w", stdout);
#endif
ios::sync_with_stdio(false);
cin.tie(NULL);
auto start=clock();
int t = 1;
//cin>>t;
for(int i=0; i<t; i++) {
//cout<<"Case #"<<i+1<<": ";
solve();
}
double used= (double) (clock()-start);
used=(used*1000)/CLOCKS_PER_SEC;
cerr<<fixed<<setprecision(2)<<used<<" ms"<<endl;
return 0;
}
| #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int inf = 1e12;
#define D long double
#define NeedForSpeed ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int MOD = 1000000007;
#define fi first
#define se second
#define endl '\n'
// random_device rd;
// mt19937 rng(rd());
// int getRand(int l,int r){ // get random number in the range [l,r]
// uniform_int_distribution<int> uid(l,r);
// return uid(rng);
// }
const int N = 1e5 + 10;
int n , m ;
vector<string> a;
int dp[2001][2001][2]={0};
bool vis[2001][2001][2] = {0};
int rec(int i , int j , int z){
if(i==n-1 && j==m-1)return 0;
int & ans = dp[i][j][z];
if(vis[i][j][z])return ans;
vis[i][j][z] = 1;
if(z==0){
ans = -inf;
if(j+1 < m) ans = max(ans,rec(i,j+1,1)+(a[i][j+1]=='+')-(a[i][j+1]=='-'));
if(i+1 < n) ans = max(ans,rec(i+1,j,1)+(a[i+1][j]=='+')-(a[i+1][j]=='-'));
}else{
ans = inf;
if(j+1 < m) ans = min(ans,rec(i,j+1,0)-(a[i][j+1]=='+')+(a[i][j+1]=='-'));
if(i+1 < n) ans = min(ans,rec(i+1,j,0)-(a[i+1][j]=='+')+(a[i+1][j]=='-'));
}
return ans;
}
void go(){
cin >> n >> m ;
a.resize(n);
for(int i = 0 ; i < n ; i++)cin >> a[i];
memset(dp,-1,sizeof(dp));
int ans = rec(0,0,0);
if(ans > 0)cout << "Takahashi" << endl;
else if(ans < 0)cout << "Aoki" << endl;
else cout << "Draw" << endl;
}
signed main() {
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
NeedForSpeed
int t = 1;
cout << fixed << setprecision(12) ;
// cin >> t;
while(t--){
// cout << "Case #" << cases << ": ";
go();
}
} |
#include <bits/stdc++.h>
#define MOD (long long)(1E9+7)
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
int main(){
int n,m;
cin >> n;
vector<vector<int>> x(n);
rep(i, n){
rep(j, n) {
cin >> m;
x[i].push_back(m);
}
}
if(n==1) {
cout << "Yes" << endl;
cout << x[0][0] << endl << 0 << endl;
return 0;
}
vector<int> hor(n-1);
vector<int> ver(n-1);
long long a=0, b=0, minA=0, minB=0;
rep(i, n-1) {
hor[i] = x[0][i+1] - x[0][i];
ver[i] = x[i+1][0] - x[i][0];
a += hor[i];
b += ver[i];
if(a<minA) minA=a;
if(b<minB) minB=b;
}
rep(i, n-1) {
rep(j, n-1) {
if(x[i+1][j+1] - x[i+1][j] != hor[j]) {
cout << "No" << endl;
return 0;
}
if(x[i+1][j+1] - x[i][j+1] != ver[i]) {
cout << "No" << endl;
return 0;
}
}
}
cout << "Yes" << endl;
int A, B;
if(minB<0 && minB < minA) {
A = -minB;
B = x[0][0] - A;
} else if(minA<0) {
B = -minA;
A = x[0][0] - B;
} else {
A = x[0][0]/2;
B = x[0][0] - A;
}
cout << A;
rep(i, n-1) {
A += ver[i];
cout << " " << A;
}
cout << endl << B;
rep(i, n-1) {
B += hor[i];
cout << " " << B;
}
cout << endl;
} | /**
* author: said_v15
**/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
typedef long long ll;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn for(int i=0;i<n;i++)
#define pb push_back
#define sc second
#define f first
#define kek cout<<"\n";
#define fla cout<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define all(v) ((v).begin()), ((v).end())
// #define int ll
const ll MOD = 1e9 + 7;
const ll MOD1 = 998244353;
const int MAXN = 200100;
const int INF = 1e8;
const ll LL_INF=1e18;
const double pi=3.1415926535;
int divide(int a, int b)
{
return (a+b-1)/b;
}
int32_t main()
{
#if defined(_DEBUG)
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
fast;
// cout << fixed << setprecision(12) << ans;
// string al = "abcdefghijklmnopqrstuvwxyz";
int questions=1;
// cin>>questions;
while(questions--)
{
string s;
cin>>s;
int ans=INF;
int n=s.size();
for(int i=0;i<(1<<n);i++)
{
int sum=0;
int cnt=0;
bool ok=false;
for(int j=0;j<n;j++)
{
if(i&(1<<j))
{
sum+=(s[j]-'0');
cnt++;
ok=true;
}
}
if(ok && sum%3==0)
{
ans=min(ans, n-cnt);
}
}
if(ans==INF) cout<<-1;
else cout<<ans;
}
// !!! LOOK AT NUMBER OF QUESTIONS IN A PROBLEM !!! (cin>>questions)
// cout <<"Runtime is:"<<clock() * 1.0 / CLOCKS_PER_SEC <<endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int a[100010], b[100010];
map <int, vector <int> > all;
map <int, int> cnt, sum;
int main () {
int n, L; scanf("%d%d", &n, &L);
a[0] = 0, a[n + 1] = L + 1;
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
for (int i = 0; i <= n + 1; i++) {
all[a[i] - i].push_back(i);
}
long long ans = 0;
for (int i = 1; i <= n; i++) {
scanf("%d", &b[i]);
b[i] -= i;
if (!all.count(b[i])) {
printf("-1\n");
return 0;
}
vector <int> &tmp = all[b[i]];
int pos = lower_bound(tmp.begin(), tmp.end(), i) - tmp.begin();
int p = 0x3f3f3f3f;
if (pos != tmp.size()) {
if (abs(p - i) > abs(tmp[pos] - i)) p = tmp[pos];
}
if (pos) {
pos--;
if (abs(p - i) > abs(tmp[pos] - i)) p = tmp[pos];
}
if (p > i) cnt[b[i] * 2]++, sum[b[i] * 2] = max(sum[b[i] * 2], abs(p - i));
else if (p < i) cnt[b[i] * 2 + 1]++, sum[b[i] * 2 + 1] = max(sum[b[i] * 2 + 1], abs(p - i));
}
for (map <int, int> :: iterator it = cnt.begin(); it != cnt.end(); it++) {
int x = it->first;
ans += sum[x];
}
printf("%lld\n", ans);
return 0;
}
| /*
* @Author: zhl
* @LastEditTime: 2021-02-13 22:14:39
*/
#include<bits/stdc++.h>
using namespace std;
const int N = 2e3 + 10;
typedef long long ll;
char mp[N][N];
int n,m;
vector<int>G[N];
int fa[N];
int find(int a){
return a == fa[a] ? a : fa[a] = find(fa[a]);
}
void merge(int a,int b){
a = find(a);b = find(b);
if(a != b)fa[a] = b;
}
int main(){
scanf("%d%d",&n,&m);
for(int i = 1;i <= n;i++)scanf("%s",mp[i] + 1),fa[i] = i;
merge(1,n);
for(int j = 1;j <= m;j++){
for(int i = 1;i <= n;i++){
if(mp[i][j] == '#')G[j].push_back(i);
}
int sz = G[j].size();
if(G[j].empty())continue;
for(int ii = 1;ii < sz;ii++){
merge(G[j][ii], G[j][0]);
}
if(j == 1 or j == m)merge(G[j][0],1);
}
set<int>rt;
for(int i = 1;i <= n;i++)rt.insert(find(i));
int ans = rt.size() - 1;
for(int i = 1;i <= m;i++)fa[i] = i;
merge(1,m);
for(int i = 1;i <= n;i++){
G[i].clear();
for(int j = 1;j <= m;j++){
if(mp[i][j] == '#')G[i].push_back(j);
}
int sz = G[i].size();
if(G[i].empty())continue;
for(int ii = 1;ii < sz;ii++){
merge(G[i][ii], G[i][0]);
}
if(i == 1 or i == n)merge(G[i][0],1);
}
rt.clear();
for(int i = 1;i <= m;i++)rt.insert(find(i));
cout << min(ans,int(rt.size()) - 1) << endl;
} |
// abc203_c
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../../debug_util/cxx-prettyprint/prettyprint.hpp"
#include "../../debug_util/rng.hpp"
#include "../../debug_util/timer.hpp"
#endif
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
#define REP(i, n) for (int i = 0 ; i < (int)(n) ; ++i)
#define REPN(i, m, n) for (int i = m ; i < (int)(n) ; ++i)
#define REP_REV(i, n) for (int i = (int)(n) - 1 ; i >= 0 ; --i)
#define REPN_REV(i, m, n) for (int i = (int)(n) - 1 ; i >= m ; --i)
#define ALL(x) x.begin(), x.end()
#define INF (ll)(1e15)
#define MOD (1000000007)
#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int idx=0;idx<(n-1);idx++) cout << (vec)[idx] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << "\n";}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;
int main() {
#ifdef LOCAL
ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif
ll N, K;
cin >> N >> K;
vector<P> AB(N);
REP(i, N) cin >> AB[i].first >> AB[i].second;
sort(ALL(AB));
ll now = 0;
REP(i, N){
ll d = AB[i].first - now;
if (K >= d){
K += AB[i].second - d;
now += d;
} else {
now += K;
K = 0;
break;
}
}
now += K;
print(now);
return 0;
}
| /* code by savagecarol */
#include <bits/stdc++.h>
using namespace std;
/* predefined value */
#define yes() cout << "YES"
#define no() cout << "NO"
#define one() cout << "1"
#define zero() cout << "0"
#define ll long long int
#define mp make_pair
#define fi first
#define se second
#define pb push_back
/* loops */
#define inp(i,n,arr) for(ll i=0 ; i<n ; i++) cin >> arr[i]
#define out(i,n,arr) for(ll i=0 ; i<n ; i++) cout << arr[i] << " "
#define loop(i,n) for(ll i=0;i<n;i++)
#define arrs(i,n,arr,sum) for(ll i = 0 ; i < n ; i++) sum = sum + arr[i];
#define arrmax(i , n , arr , maxx) for(ll i = 1 ; i < n;i++) maxx = max(maxx , arr[i]);
#define arrmin(i , n , arr , minn) for(ll i = 0 ; i < n;i++) minn = min(minn , arr[i]);
/* typedef */
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll mod = 1e9 + 7;
/* power function */
long long binpow(long long a, long long b) {
long long res = 1;
while (b > 0) {
if (b & 1)
res = res * a;
a = a * a;
b >>= 1;
}
return res;
}
int countSetBits(int n){
unsigned int count = 0;
while (n) {
n &= (n - 1);
count++;
}
return count;
}
int powerOfTwo(int n){
return n && (!(n & (n-1)));
}
/*code*/
void solve()
{
ll n , k;
cin >> n >> k;
vector<pair<ll , ll>> a;
ll x, y;
for(ll i = 0 ; i < n;i++)
{
cin >> x >> y;
a.push_back({x , y});
}
sort(a.begin(), a.end());
ll i = 0;
while(i < n)
{
if(k>=a[i].first)
{
k=k+a[i].second;
i++;
}
else break;
}
cout << k;
}
int main()
{
solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int N, max = 0;
bool sin = true;
cin >> N;
int a[N];
for (int i=0; i<N; i++){
cin >> a[i];
if (max < a[i])
max = a[i];
if (i>0 && a[i-1] != a[i])
sin = false;
}
if (sin){
cout << a[0] << endl;
return 0;
}
int k = max / 2;
int count = 0;
while(true){
for (int i=0; i<N; i++){
if (a[i] % k != 0){
count += 1;
break;
}
}
if (count == 0){
cout << k << endl;
return 0;
}
k -= 1;
count = 0;
}
} | #include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//(double)clock() / CLOCKS_PER_SEC;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin>>n;
set<int> s;
for(int i=1; i<=n; i++)
{
int x;
cin>>x;
s.insert(x);
}
while(s.size()>1)
{
auto it=s.end();
it--;
int v=(*it);
int mini=*(s.begin());
s.erase(v);
s.insert(v-mini);
}
cout<<(*s.begin())<<endl;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
int a,b,c;
int main()
{
cin>>a>>b>>c;
if(c%2==0)
{
if(abs(a)>abs(b)) cout<<">";
if(abs(a)==abs(b)) cout<<"=";
if(abs(a)<abs(b)) cout<<"<";
}
else
{
if(a>b) cout<<">";
if(a==b) cout<<"=";
if(a<b) cout<<"<";
}
return 0;
} | /*
author : aryan57
created : 13-June-2021 17:33:20 IST
*/
#include <bits/stdc++.h>
using namespace std;
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#ifndef ONLINE_JUDGE
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif
#define int long long
#define X first
#define Y second
#define pb push_back
#define sz(a) ((int)(a).size())
#define all(a) (a).begin(), (a).end()
#define F(i, a, b) for (int i = a; i <= b; i++)
#define RF(i, a, b) for (int i = a; i >= b; i--)
const int mxn = 1e5;
const long long INF = 2e18;
const int32_t M = 1000000007;
// const int32_t M = 998244353;
const long double pie = acos(-1);
void solve_LOG()
{
int a,b,c;
cin>>a>>b>>c;
if(c%2==0)
{
if(abs(a)==abs(b))
{
cout<<"=";
return;
}
if(abs(a)>abs(b))
{
cout<<">";
return;
}
if(abs(a)<abs(b))
{
cout<<"<";
return;
}
}
if(a<0 && b>=0)
{
cout<<"<";
return;
}
if(a<0 && b<0)
{
if(abs(a)==abs(b))
{
cout<<"=";
return;
}
if(abs(a)>abs(b))
{
cout<<"<";
return;
}
if(abs(a)<abs(b))
{
cout<<">";
return;
}
}
if(a>=0 && b>=0)
{
if(abs(a)==abs(b))
{
cout<<"=";
return;
}
if(abs(a)>abs(b))
{
cout<<">";
return;
}
if(abs(a)<abs(b))
{
cout<<"<";
return;
}
}
if(a>=0 && b<0)
{
cout<<">";
return;
}
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
#ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
#endif
#ifdef ARYAN_SIEVE
sieve();
#endif
#ifdef ARYAN_SEG_SIEVE
segmented_sieve();
#endif
#ifdef ARYAN_FACT
fact_init();
#endif
// cout<<fixed<<setprecision(10);
int _t=1;
// cin>>_t;
for (int i=1;i<=_t;i++)
{
// cout<<"Case #"<<i<<": ";
solve_LOG();
}
return 0;
}
// parsed : 13-June-2021 17:33:16 IST |
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
//template
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(v) (v).begin(),(v).end()
using ll=long long int;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
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;}
//end
void solve(int _rot){
// printf("Case #%d: ",_rot);
int n;
cin>>n;
vector<int> a(n);
rep(i,0,n)cin>>a[i];
if(n==2){
if(a[0]!=1){
puts("1\n1");
}
else{
puts("0");
}
return;
}
map<int,int> pos;
rep(i,0,n)pos[a[i]]=i;
vector<int> res;
auto process=[&](int i){
res.push_back(i+1);
swap(a[i],a[i+1]);
swap(pos[a[i]],pos[a[i+1]]);
};
bool flip=1;
rep(i,0,n-3){
int from=pos[i+1];
if(flip+(from&1)==1){ //not match
int to;
if(from>=n-2){
to=i/2*2;
if(!flip)to++;
if(to<i)to+=2;
if(to==from or to==from-1)to+=2;
}
else{
to=n/2*2;
if(!flip)to++;
while(to>=n-1)to-=2;
if(to==from or to==from-1)to-=2;
}
process(to);
flip^=1;
}
{
while(from>i){
process(from-1);
from--;
flip^=1;
}
}
}
for(;;){
int from;
if(flip)from=n/2*2-2;
else from=n/2*2-1;
if(from==n-1)from-=2;
process(from);
if(a[n-3]==n-2 and a[n-2]==n-1 and a[n-1]==n)break;
flip^=1;
}
cout<<res.size()<<'\n';
for(auto& x:res)cout<<x<<'\n';
}
int main(){
int t; scanf("%d",&t);
rep(rot,0,t)solve(rot+1);
return 0;
} | #include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
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;
}
int main(){
int n;
cin >> n;
vector<int> a(n);
rep(i,n){
cin >> a[i];
a[i]--;
}
vector<int> inv(n);
rep(i,n){
inv[a[i]] = i;
}
vector<int> res;
int k = 0;
rep(i,n){
while(k!=n&&inv[k]==k){
k++;
}
if(k==n)break;
res.push_back(inv[k]-1);
int id = inv[k]-1;
swap(a[id],a[id+1]);
inv[a[id]] = id;
inv[a[id+1]] = id+1;
}
bool ok = 1;
rep(i,n){
if(a[i]!=i)ok = 0;
}
if(ok&&(int)res.size()==n-1){
rep(i,n-1){
cout << res[i]+1 << "\n";
}
}else{
cout << -1 << endl;
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 100010;
int a[N], b[N], c[N], d[N];
int n, l;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> l;
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; i++) {
c[i] = a[i + 1] - a[i] - 1;
d[i] = b[i + 1] - b[i] - 1;
}
LL ans = 0;
for (int i = 0, j = 0; i <= n; i++) {
if (d[i]) {
while (j <= n && c[j] == 0) j++;
int l = j, s = 0;
while (j <= n && s < d[i])
s += c[j++];
if (s != d[i]) {
puts("-1");
return 0;
}
ans += max(i - l, 0) + max(j - 1 - i, 0);
}
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define eb emplace_back
using ll = long long;
const int inf = 1e9+5;
const ll INF = 1e18+5;
const int nax = 2e5+500;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int h, w;
cin >> h >> w;
vector<vector<int>> g(h+1, vector<int> (w+1));
for(int i=1;i<=h;i++) {
for(int j=1;j<=w;j++) {
char ch;
cin >> ch;
g[i][j] = (ch == '+'?1:-1);
}
}
vector<vector<int>> dp(h+2, vector<int> (w+2));
for(int i=h;i>=1;--i) {
for(int j=w;j>=1;--j) {
if(i == h && j == w) dp[i][j] = 0;
else if((i + j) % 2 == 0) {
dp[i][j] = -(1 << 30);
if(i + 1 <= h) dp[i][j] = max(dp[i][j], dp[i+1][j] + g[i+1][j]);
if(j + 1 <= w) dp[i][j] = max(dp[i][j], dp[i][j+1] + g[i][j+1]);
} else {
dp[i][j] = (1 << 30);
if(i+1 <= h) dp[i][j] = min(dp[i][j], dp[i+1][j] - g[i+1][j]);
if(j+1 <= w) dp[i][j] = min(dp[i][j], dp[i][j+1] - g[i][j+1]);
}
}
}
if((h == 1 && w == 1) || dp[1][1] == 0) cout << "Draw";
else cout << (dp[1][1] > 0 ? "Takahashi":"Aoki");
}
|
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//turn on extra precision
//#pragma GCC target("fpmath=387")
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef string str;
typedef pair <int,int> pii;
typedef pair <ll,ll> pll;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_multiset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'
#define fbo find_by_order
#define ook order_of_key
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(),x.rend()
#define watch(x) cout << (#x) << " is : " << (x) << newl
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
vi dirx = {0,0,1,-1};
vi diry = {1,-1,0,0};
char to_upper (char x){
if( 97 <= int(x) && int(x) <= 122) return char(x-32);
if( 65 <= int(x) && int(x) <= 90) return x;
return -1;
}
char to_lower (char x){
if( 97 <= int(x) && int(x) <= 122) return x;
if( 65 <= int(x) && int(x) <= 90) return char(x+32);
return -1;
}
int numerize (char x){
if(48 <= int(x) && int(x) <= 57) return int(x-'0');
if(97 <= int(x) && int(x) <= 122) return int(x-96);
if(65 <= int(x) && int(x) <= 90) return int(x-64);
return -1;
}
bool isect (int l1, int r1, int l2, int r2){ return max(l1,l2) <= min(r1,r2); }
ll quickpow (ll num1, ll num2, ll MOD){
if(num2==0)return 1%MOD;
else if(num2==1)return num1%MOD;
else{
ll temp = quickpow (num1,num2>>1LL,MOD); ll res = ((temp%MOD) * (temp%MOD))%MOD;
if(num2&1) res = ((res%MOD)*(num1%MOD))%MOD; return res;
}
}
ll invmod (ll num, ll MOD){return quickpow (num,MOD-2,MOD);}
ll gcd (ll num1, ll num2){
if(num1 < num2) swap(num1,num2); ll num3 = num1 % num2 ;
while(num3 > 0){ num1 = num2; num2 = num3; num3 = num1 % num2;}
return num2;
}
ll lcm (ll num1 , ll num2){return (ll) (num1/__gcd(num1,num2))*num2;}
// end of Template
int main(){
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string s; cin >> s;
string res = "";
for(auto i : s) {
if(i == '.') break;
res += i;
}
cout << res << newl;
return 0;
}
| #include <bits/stdc++.h>
#define Vanya Unstoppable
#define int long long
#define pb push_back
#define ll long long
#define pii pair<int, int>
#define all(a) a.begin(), a.end()
#define TESTS 0
typedef long double ld;
using namespace std;
void solve() {
string a;
cin >> a;
int n = a.size();
for (int i = 0; i < n; ++i) {
if (a[i] == '.') break;
cout << a[i];
}
// int pos = n;
// for (int i = 0; i < n; ++i) {
// if (a[i] == '.') pos = i;
// }
// int to = pos - 1;
// int ans = 0, t = 1;
// while (to >= 0) {
// ans += (a[to] - '0') * t;
// t *= 10; --to;
// }
// bool f = false;
// for (int i = pos + 1; i < n; ++i) {
// int to = a[i] - '0';
// int del = 5 - to;
// if (del == 1) {
// f = true;
// } else {
// if (del >= 0) {
// ++ans;
// break;
// } else {
// break;
// }
// }
// }
}
signed main() {
std::ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
int q = 1;
#if TESTS
cin >> q;
#endif
while (q--) {
solve();
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main(){
int n, ans = 0;
cin >> n;
int sum = 0;
for(int i = 1; 1;++i){
if(sum >= n){
ans = i - 1;break;
}
sum+=i;
}
cout << ans << '\n';
}
| #include<bits/stdc++.h>
using namespace std;
int n;
int main(){
scanf("%d",&n);
for(int i=1;i;++i)if(i*(i+1)/2>=n){printf("%d",i);return 0;}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define co(n) cout<<n<<endl;
const double eps=1e-10,pi=3.1415926535898;
const int mod=1e9+7,maxn=410;
int T,n,m,k,x,y;
long long dp[maxn][maxn];
void init() {
for (int i=0;i<maxn;++i) {
dp[i][0] = dp[i][i] = 1;
}
for (int i=2;i<maxn;++i) {
for (int j=1;j<i;++j) {
dp[i][j] = dp[i-1][j]+dp[i-1][j-1];
}
}
}
int main(int argc, char const *argv[]) {
init();
T = 1;
//scanf("%d", &T);
for (int _=1;_<=T;++_) {
long long ans=0;
scanf("%d", &n);
printf("%lld\n", dp[n-1][11]);
}
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")
clock_t clk;
clk = clock();
if(clock() - clk > CLOCKS_PER_SEC * 0.9)
T
W L
A C M E R
E L E
E
*/ | #include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll; typedef pair<int,int>pint;
using vll=vector<ll>; using vs=vector<string>;
#define b2e(v)v.begin(),v.end()
#define p2a(v, p) v[p.first][p.second]
class var { public: ll min,max,ct,sum,dif,result; };
int main() {
const ll cut=11;
ll l; cin>>l;
ll val, sum = 1;
for (ll i = 1; i <= cut; i++) {
sum *= l-i;
sum /= i;
}
cout << sum << endl;
}
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll maxn=200005;
const ll mod=998244353;
const ll INF64 = ll(1e18);
const ll max2=10500000;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
vector<ll> adj_row[52],adj_column[52];
ll vis_r[52],vis_c[52];
ll dfs(ll p,vector<ll> adj[],ll vis[])
{
vis[p]=1;
ll i;
ll x=1;
for(i=0;i<adj[p].size();++i)
{
if(vis[adj[p][i]]==0)
{
x+=dfs(adj[p][i],adj,vis);
}
}
return(x);
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
//long long tt = clock();
#endif
ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
ll n,c,i,j,k;
cin>>n>>c;
ll a[n][n];
for(i=0;i<n;++i)
{
for(j=0;j<n;++j)
cin>>a[i][j];
}
ll fact[52];
fact[0]=1;
for(i=1;i<=n;++i)
{
fact[i]=(fact[i-1]*i)%mod;
}
for(i=0;i<n;++i)
{
for(j=i+1;j<n;++j)
{ll sum=0;
for(k=0;k<n;++k)
sum+=(a[i][k]+a[j][k]<=c);
if(sum==n)
{
adj_column[i].push_back(j);
adj_column[j].push_back(i);
}
}
}
for(i=0;i<n;++i)
{
for(j=i+1;j<n;++j)
{ll sum=0;
for(k=0;k<n;++k)
sum+=(a[k][i]+a[k][j]<=c);
if(sum==n)
{//cout<<i<<" "<<j<<"\n";
adj_row[i].push_back(j);
adj_row[j].push_back(i);
}
}
}
//return(0);
ll ans=1;
for(i=0;i<n;++i)
{
if(vis_c[i]==0)
{
ll x=dfs(i,adj_column,vis_c);
ans=(ans*fact[x])%mod;
}
if(vis_r[i]==0)
{ll x=dfs(i,adj_row,vis_r);
//cout<<x<<" "<<i<<"\n";
//return(0);
ans=(ans*fact[x])%mod;
}
}
cout<<ans;
return(0);
} | #include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define Pii pair<int,int>
#define Pll pair<long long,long long>
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
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;}
//vector<vector<ll>> dp(n,vector<ll>(n))
//2-dim:vector<vector<Type>> vv(n, vector<Type>(m, d));
//3-dim:vector<vector<vector<Type>>> vvv(n, vector<vector<Type>>(m, vector<Type>(l, d)));
using namespace std;
constexpr ll MOD = 1e9+7;
long long powmod(long long x,long long n){
long long ret=1;
while(n>0){
if(n&1){
ret*=x;
ret%=MOD;
n-=1;
}else{
x*=x;
x%=MOD;
n>>=1;
}
}
return ret;
}
signed main(){
std::cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
ll n; cin >> n;
ll m; cin >> m;
vector<ll> a(n);
ll sum = 0;
rep(i,n){
cin >> a[i];
sum += a[i];
}
ll ans = 1;
for(ll i=1;i<=n+sum;i++){
ans *= (n+m+1-i)%MOD;
ans %= MOD;
ans *= powmod(i,MOD-2);
ans %= MOD;
}
cout << ans << endl;
return 0;
}
// g++ main.cpp -o a.out && ./a.out |
#line 1 "main.cpp"
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
using namespace std;
using lint = long long;
void solve() {
int n, m;
cin >> n >> m;
vector<lint> cnt(2, 0);
while (n--) {
string s;
cin >> s;
++cnt[count(s.begin(), s.end(), '1') % 2];
}
cout << cnt[0] * cnt[1] << "\n";
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
solve();
return 0;
}
| #define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i,s,n) for(int i = s; i < (int)(n); i++)
#define Rep(i,s,n) for(int i = n; i >= (int)(s); i--)
int main(){
int n;
cin >> n;
vector<ll>r, g, b;
rep(i, 0, 2 * n) {
ll a;
char c;
cin >> a >> c;
if (c == 'R') r.push_back(a);
else if (c == 'G') g.push_back(a);
else b.push_back(a);
}
sort(r.begin(), r.end());
sort(g.begin(), g.end());
sort(b.begin(), b.end());
ll rg = 1e16, rb = 1e16, bg= 1e16;
if (g.size() != 0) {
rep(i, 0, r.size()) {
ll v = r[i];
int pos = lower_bound(g.begin(), g.end(), v) - g.begin();
if(pos != g.size())rg = min(rg, abs(v - g[pos]));
if (pos != 0) rg = min(rg, abs(v - g[pos - 1]));
}
}
if (b.size() != 0) {
rep(i, 0, r.size()) {
ll v = r[i];
int pos = lower_bound(b.begin(), b.end(), v) - b.begin();
if(pos != b.size())rb = min(rb, abs(v - b[pos]));
if (pos != 0) rb = min(rb, abs(v - b[pos - 1]));
}
}
if (g.size() != 0) {
rep(i, 0, b.size()) {
ll v = b[i];
int pos = lower_bound(g.begin(), g.end(), v) - g.begin();
if(pos != g.size())bg = min(bg, abs(v - g[pos]));
if (pos != 0) bg = min(bg, abs(v - g[pos - 1]));
}
}
if (r.size() % 2 == 0 && g.size() % 2 == 0 && b.size() % 2 == 0) cout << 0 << endl;
else if (r.size() % 2 == 0) {
ll ans = min(bg, rg + rb);
cout << ans << endl;
}
else if (g.size() % 2 == 0) {
ll ans = min(rb, rg + bg);
cout << ans << endl;
}
else {
ll ans = min(rg, rb + bg);
cout << ans << endl;
}
} |
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define P pair<int,int>
//#define LOCAL_TEST
#define init_val 2500
template<class T>int chmin(T&a,const T&b){if(b<a){a=b;return 1;}return 0;}
//----------def struct st----------
struct st
{
int fif;
int fis;
int se;
bool operator<(const st&st1)const{return se<st1.se;};
bool operator>(const st&st1)const{return se>st1.se;};
};
//----------global args----------
int si,sj,ti,tj,A;double E;
vector<vector<vector<st>>>G(30,vector<vector<st>>(30));
//----------def input----------
#ifdef LOCAL_TEST
void input()
{
int h,v;
rep(i,30)rep(j,29)
{
cin>>h;
G[i][j].push_back(st{i,j+1,init_val});
G[i][j+1].push_back(st{i,j,init_val});
}
rep(i,29)rep(j,30)
{
cin>>v;
G[i][j].push_back(st{i+1,j,init_val});
G[i+1][j].push_back(st{i,j,init_val});
}
}
#else
void input()
{
rep(i,30)rep(j,29){G[i][j].push_back(st{i,j+1,init_val});G[i][j+1].push_back(st{i,j,init_val});}
rep(i,29)rep(j,30){G[i][j].push_back(st{i+1,j,init_val});G[i+1][j].push_back(st{i,j,init_val});}
}
#endif
//----------def solve----------
#ifdef LOCAL_TEST
void in_a_e(){cin>>A>>E;}
#else
void in_a_e(){cin>>A;}
#endif
void solve()
{
cin>>si>>sj>>ti>>tj;
vector<vector<int>>dist(30,vector<int>(30,1LL<<60));dist[si][sj]=0;
vector<vector<P>>prev(30,vector<P>(30,{-1,-1}));
priority_queue<st,vector<st>,greater<st>>pq;
pq.push(st{0,si,sj});
while(!pq.empty())
{
auto[d,v1,v2]=pq.top();
pq.pop();
if(d>dist[v1][v2])continue;
for(auto e:G[v1][v2])if(chmin(dist[e.fif][e.fis],dist[v1][v2]+e.se))
{
prev[e.fif][e.fis]={v1,v2};
pq.push(st{dist[e.fif][e.fis],e.fif,e.fis});
}
}
vector<P>keiro;
for(P cur={ti,tj};cur!=(P){-1,-1};cur=prev[cur.first][cur.second])keiro.push_back(cur);
reverse(keiro.begin(),keiro.end());
int keirosize=keiro.size();
for(int i=1;i<keirosize;i++)
{
if(keiro[i-1].first-keiro[i].first<0)cout<<'D';
else if(keiro[i-1].first-keiro[i].first>0)cout<<'U';
if(keiro[i-1].second-keiro[i].second<0)cout<<'R';
else if(keiro[i-1].second-keiro[i].second>0)cout<<'L';
}
cout<<endl;
in_a_e();
for(int i=1;i<keirosize;i++)
{
for(auto&it:G[keiro[i].first][keiro[i].second])
{
if(it.fif==keiro[i+1].first&&it.fis==keiro[i+1].second)
{
if(it.se==init_val)it.se=A/keirosize;
else it.se=(it.se+A/keirosize)/2;
}
}
}
}
//-----------main-----------
main()
{
input();
rep(i,1000)solve();
} | #include<bits/stdc++.h>
using namespace std;
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')';}
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) {os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
template<typename T> void dbg_a(const T *a,int l,int r){cerr<<" {";for(int i = l;i<r;i++) cerr<<a[i]<<", ";cerr<<a[r]<<"}"<<endl;}
typedef long long ll;
//#define int long long
#define mst(a,b) memset(a,b,sizeof(a))
#define For(i,a,b) for(int i = a;i<=b;i++)
#define For_(i,a,b) for(int i = a;i>=b;i--)
#define rep(i,a) for(int i = 0;i<(int)a;i++)
#define All(x) x.begin(),x.end()
#define all(x) x.begin() + 1,x.end()
//const ll INF = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const int N = 2e5 + 6,M = 1<<18 + 6;
const int mod = 1e9 + 7;
void solve(){
int n; cin>>n;
ll lb = -INF,ub = INF,add = 0;
For(i,1,n){
ll a,t;
cin>>a>>t;
if(t == 1) {
lb += a;
ub += a;
add += a;
}
else if(t == 2){
lb = max(lb,a);
ub = max(ub,a);
}
else{
lb = min(lb,a);
ub = min(ub,a);
}
}
auto clamp = [&](ll val,ll mi,ll mx)->ll{
if(val < mi) return mi;
if(val > mx) return mx;
return val;
};
int q; cin>>q;
while(q--){
ll x; cin>>x;
cout<<clamp(x + add,lb,ub)<<"\n";
}
}
signed main(){
ios::sync_with_stdio(0),cin.tie(0);
solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
using ll = long long;
using P = pair<int, int>;
const ll INF = 1LL << 60;
const int MAX = 200001;
int main() {
ll n, w;
cin >> n >> w;
bool flag = false;
vector<ll> a(MAX, 0);
rep(i, n){
ll s, t, p;
cin >> s >> t >> p;
a[s] += p;
a[t] -= p;
}
rep(i, MAX){
a[i+1] += a[i];
if(a[i] > w) flag = true;
}
if(flag) cout << "No" << endl;
else cout << "Yes" << endl;
} | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
ll b,c;
scanf("%lld%lld",&b,&c);
ll cnt=0;
if(b<=0){
cnt=c+1;
c--;
if(b==0)cnt--;
if(c>0&&b<0)cnt+=min(-2*b-1,c-1);
}else {
cnt=c+(c==1?1:0);
cnt+=min(2*b-1,c-1);
}printf("%lld\n",cnt);
} |
/**
* Dont raise your voice, improve your argument.
* --Desmond Tutu
*/
#include <bits/stdc++.h>
using namespace std;
const bool ready = [](){
ios_base::sync_with_stdio(false); cin.tie(0);
cout << fixed << setprecision(12);
return true;
}();
using ld=long double;
const ld PI = acos((ld)-1);
using ll= long long;
#define int ll
#define all(v) (v).begin(), (v).end()
#define fori(n) for(int i=0; i<int(n); i++)
#define cini(i) int i; cin>>i;
#define cins(s) string s; cin>>s;
#define cind(d) ld d; cin>>d;
#define cinai(a,n) vi a(n); fori(n) { cin>>a[i]; }
#define cinas(s,n) vs s(n); fori(n) { cin>>s[i]; }
#define cinad(a,n) vd a(n); fori(n) { cin>>a[i]; }
using pii= pair<int, int>;
using pdd= pair<ld, ld>;
using vd= vector<ld>;
using vb= vector<bool>;
using vi= vector<int>;
using vvi= vector<vi>;
using vs= vector<string>;
#define endl "\n"
/** faster solution */
const int MAXN = 70;
ll C[MAXN + 1][MAXN + 1];
const bool init_nCr=[]() {
C[0][0] = 1;
for (int n = 1; n <= MAXN; ++n) {
C[n][0] = C[n][n] = 1;
for (int k = 1; k < n; ++k)
C[n][k] = C[n - 1][k - 1] + C[n - 1][k];
}
return true;
}();
ll nCr(int n, int k) {
return C[n][k];
}
/* aaaabbbb
* aaababbb
* aaabbabb
* ...
* aabaabbb
* aabababb
* ...
* aababbba
* Number of strings of len x with A 'a' is nCr(x,A)
* So we check the prefixes until we found the right one.
*/
void solve() {
cini(a);
cini(b);
cini(k);
int cnt=a+b;
string ans;
for(int i=0; i<cnt; i++) {
int num=nCr(a+b-1, a-1); /* consider first letter a */
if(b>0 && (a==0 || num<k)) {
k-=num;
ans.push_back('b');
b--;
} else {
ans.push_back('a');
a--;
}
}
cout<<ans<<endl;
}
signed main() {
solve();
} | /*
{
######################
# Author #
# Gary #
# 2021 #
######################
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
#define check_min(a,b) a=min(a,b)
#define check_max(a,b) a=max(a,b)
using namespace std;
//inline int read(){
// int x=0;
// char ch=getchar();
// while(ch<'0'||ch>'9'){
// ch=getchar();
// }
// while(ch>='0'&&ch<='9'){
// x=(x<<1)+(x<<3)+(ch^48);
// ch=getchar();
// }
// return x;
//}
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
/*}
*/
const int MAXN=200000+233;
vector<int> g[MAXN];
int n;
mp fr;
int depth[MAXN],rest[MAXN],cnt;
void dfs(int now,int dis=0,int pre=0){
check_max(fr,II(dis,now));
for(auto it:g[now]) if(it!=pre){
dfs(it,dis+1,now);
}
}
void dfs2(int now,int pre=0){
for(auto it:g[now]) if(it!=pre){
depth[it]=depth[now]+1;
dfs2(it,now);
}
for(auto it:g[now]) if(it!=pre){
check_max(depth[now],depth[it]);
}
}
bool cmp(int A,int B){
return depth[A]<depth[B];
}
void dfs3(int now,int pre=0){
rest[now]=++cnt;
vector<int> ord;
for(auto it:g[now]) if(it!=pre) ord.PB(it);
sort(ALL(ord),cmp);
for(auto it:ord) dfs3(it,now),++cnt;
}
int main(){
scanf("%d",&n);
rb(i,1,n-1){
int u,v;
scanf("%d%d",&u,&v);
g[u].PB(v);
g[v].PB(u);
}
fr=II(-1,-1);
dfs(1);
int tmp=fr.SEC;
fr=II(-1,-1);
dfs(tmp);
int root=fr.SEC;
dfs2(root);
dfs3(root);
rb(i,1,n) printf("%d ",rest[i]);
return 0;
} |
#include <bits/stdc++.h>
//#include <atcoder/all>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_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;
}
const long long INF = 1e18;
//const ll mod = 1000000007;
ll num[10];
bool ok = false;
bool f(int a, int b, int c) {
if((100*a+10*b+c) % 8 != 0) return false;
bool ret = true;
num[a]--;
num[b]--;
num[c]--;
for(int i = 1; i <= 9; i++) {
if(num[i] < 0) ret = false;
}
num[a]++;
num[b]++;
num[c]++;
return ret;
}
string S;
void solve() {
sort(S.begin(), S.end());
do {
ll tmp = stoll(S);
ok |= (tmp % 8 == 0);
} while(next_permutation(S.begin(), S.end()));
if(ok) cout << "Yes" << endl;
else cout << "No" << endl;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> S;
if(S.size() <= 3) {
solve();
return 0;
}
for(auto c : S) {
num[(int)(c - '0')]++;
}
for(int i = 1; i <= 9; i++) {
for(int j = 1; j <= 9; j++) {
for(int k = 1; k <= 9; k++) {
ok |= f(i, j, k);
}
}
}
if(ok) cout << "Yes" << endl;
else cout << "No" << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout << fixed
#define endl '\n'
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
void solve(istream& cin, ostream& cout) {
int n;
cin >> n;
map<int, bool> mp;
priority_queue<int, vector<int>, greater<int>> q1, q2;
FOR(i, 0, 200000) {
q1.push(i);
}
REP(i, n) {
int p;
cin >> p;
if (!mp[p]) q2.push(p);
mp[p] = true;
while(q1.top() == q2.top()) {
q1.pop(), q2.pop();
}
cout << q1.top() << endl;
}
}
#ifndef TEST
int main() {
OPTIMIZE_STDIO;
solve(cin, cout);
return 0;
}
#endif
|
/**
* code generated by JHelper
* More info: https://github.com/AlexeyDmitriev/JHelper
* @author
*/
#include <iostream>
#include <fstream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
inline int inint(istream& in) {int x; in >> x; return x;}
inline ll inll(istream& in) {ll x; in >> x; return x;}
inline string instr(istream& in) {string x; in >> x; return x;}
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)
class ARockPaperScissors {
public:
void solve(std::istream& in, std::ostream& out) {
int x = inint(in);
int y = inint(in);
if(x == y){
out << x << endl;
return;
}
if(x + y == 1){
out << 2 << endl;
return;
}
if(x + y == 2){
out << 1 << endl;
return;
}
if(x + y == 3){
out << 0 << endl;
return;
}
}
};
int main() {
ARockPaperScissors solver;
std::istream& in(std::cin);
std::ostream& out(std::cout);
solver.solve(in, out);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
// using mint = long double;
// using mint = modint998244353;
// using mint = modint1000000007;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> T;
typedef pair<ll, vector<ll>> Pd;
const ll INF = 1e18;
const ll fact_table = 820000;
priority_queue<ll> pql;
priority_queue<P> pqp;
// big priority queue
priority_queue<ll, vector<ll>, greater<ll>> pqls;
priority_queue<P, vector<P>, greater<P>> pqps;
// small priority queue
// top pop
ll dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
ll dy[8] = {0, 1, 0, -1, -1, 1, 1, -1};
//↓,→,↑,←
#define p(x) cout << x << "\n";
#define el cout << "\n";
#define pe(x) cout << x << " ";
#define ps(x) cout << fixed << setprecision(25) << x << endl;
#define pu(x) cout << (x);
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define pc(x) cout << x << ",";
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = a; i <= (b); i++)
#define rep3(i, a, b) for (ll i = a; i >= (b); i--)
#define all(c) begin(c), end(c)
#define sorti(v) sort(all(v))
#define sortd(v) \
sort(all(v)); \
reverse(all(v));
#define SUM(v) accumulate(all(v), 0LL)
#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;
// vec v(n) -> 長さnのベクトルを宣言
// mat dp(h, vec(w)) -> h * w の行列を宣言
const ll mod = 1000000007ll;
// const ll mod = 998244353ll;
ll mypow(ll a, ll b, ll m = mod) {
ll x = 1;
while (b) {
while (!(b & 1)) {
(a *= a) %= m;
b >>= 1;
}
(x *= a) %= m;
b--;
}
return x;
}
vec rv(ll read) {
vec res(read);
for (int i = 0; i < read; i++) {
cin >> res[i];
}
return res;
}
/*
ll fact[fact_table + 5], rfact[fact_table + 5];
void c3_init() {
fact[0] = rfact[0] = 1;
for (ll i = 1; i <= fact_table; i++) {
fact[i] = (fact[i - 1] * i) % mod;
}
rfact[fact_table] = mypow(fact[fact_table], mod - 2, mod);
for (ll i = fact_table; i >= 1; i--) {
rfact[i - 1] = rfact[i] * i;
rfact[i - 1] %= mod;
}
return;
}
ll c3(ll n, ll r) {
return (((fact[n] * rfact[r]) % mod) * rfact[n - r]) % mod;
}
*/
bool icpc = false;
bool multicase = false;
bool solve() {
ll a, b;
cin >> a >> b;
if (a == b) {
p(a);
} else {
p(3 - a - b);
}
return true;
}
/*
*/
int main() {
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
if (icpc) {
while (solve())
;
return 0;
}
ll q, testcase = 1;
if (multicase) {
cin >> q;
} else {
q = 1;
}
while (q--) {
// cout << "Case #" << testcase << ": ";
solve();
testcase++;
}
// solve();
return 0;
} |
#include<iostream>
#define ll long long
using namespace std;
ll T,X,Y,P,Q,a,b,c,k1,k2,tans;
ll exgcd(ll a,ll b,ll &x,ll &y) {
if(!b) {
x=1,y=0;
return a;
}
int t=exgcd(b,a%b,y,x);
y-=a/b*x;
return t;
}
int main() {
cin>>T;
while(T--) {
cin>>X>>Y>>P>>Q;
a=2*X+2*Y,b=P+Q;
tans=5e18;
for(int q=0; q<Q; q++) {
for(int y=0; y<Y; y++) {
c=P+q-X-y;
int t=exgcd(a,b,k1,k2);
if(c%t)continue;
k1=k1*c/t;
k1=(k1%(b/t)+(b/t))%(b/t);
tans=min(tans,a*k1+y+X);
}
}
if(tans==5e18)cout<<"infinity\n";
else cout<<tans<<endl;
}
} | //#include <atcoder/maxflow.hpp>
#include <memory>
#include <iostream>
#include <map>
#include <list>
#include <set>
#include <algorithm>
#include <vector>
#include <sstream>
#include <string>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <limits>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <fstream>
#include <iterator>
#include <random>
#include <chrono>
#include <complex>
#include <thread>
#include <bitset>
#include <assert.h>
#define forr(i,start,count) for (int i = (start); i < (start)+(count); ++i)
#define set_map_includes(set, elt) (set.find((elt)) != set.end())
#define readint(i) int i; cin >> i
#define readll(i) ll i; cin >> i
#define readdouble(i) double i; cin >> i
#define readstring(s) string s; cin >> s
typedef long long ll;
using namespace std;
//using namespace atcoder;
ll modd = (1000LL * 1000LL * 1000LL + 7LL);
//ll modd = 998244353;
ll gcd(ll a, ll b, ll& x, ll& y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
ll x1, y1;
ll d = gcd(b, a % b, x1, y1);
x = y1;
y = x1 - y1 * (a / b);
return d;
}
bool find_any_solution(ll a, ll b, ll c, ll &x0, ll &y0, ll &g) {
g = gcd(abs(a), abs(b), x0, y0);
if (c % g) {
return false;
}
x0 *= c / g;
y0 *= c / g;
if (a < 0) x0 = -x0;
if (b < 0) y0 = -y0;
return true;
}
int main(int argc, char *argv[]) {
// ios_base::sync_with_stdio(false);
// cin.tie(NULL);
cout.precision(17);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_int_distribution<int> rand_gen(0, modd); // rand_gen(rng) gets the rand no
uniform_real_distribution<double> ff(-1,1);
// auto start = chrono::steady_clock::now();
readint(test_cases);
// int test_cases = 1;
forr(t, 1, test_cases) {
readll(x); readll(y); readll(p); readll(q);
ll per_train = 2*x+2*y, per_sleep = p+q;
set<ll> solutions;
forr(i,0,y) {
forr(j,0,q) {
ll a = per_train, b = -per_sleep, c = p+j-x-i, x0,y0,g;
if (find_any_solution(a,b,c,x0,y0,g)) {
ll x_shift = -b/g, y_shift = a/g;
if (x0<0) {
ll k = abs(x0)/x_shift+4;
x0 += k * x_shift;
y0 += k * y_shift;
}
ll k = x0/x_shift;
x0 -= k * x_shift;
y0 -= k * y_shift;
solutions.insert(p+j+y0*per_sleep);
}
}
}
if (solutions.empty()) {
cout << "infinity" << endl;
} else {
cout << *solutions.begin() << endl;
}
}
// auto stop = chrono::steady_clock::now();
// auto duration = chrono::duration_cast<chrono::milliseconds>(stop - start);
// cout << "Duration: " << duration.count() << endl;
return 0;
}
|
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
//#define mod 998244353
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
template<class T> using V=vector<T>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
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; }
template<class T> inline void out(T a){ cout << a << '\n'; }
void YN(bool ok){if(ok) cout << "Yes" << endl; else cout << "No" << endl;}
//void YN(bool ok){if(ok) cout << "YES" << endl; else cout << "NO" << endl;}
const ll INF=1e18;
const int mx=200005;
ll dp[102][102][102];
int main(){
//オーバーフローは大丈夫ですか??
cin.tie(0);ios::sync_with_stdio(false);
ll n,x;
cin>>n>>x;
V<ll> a(n);
cinf(n,a);
ll ans=INF;
for(ll cnt=1;cnt<=n;cnt++){
rep(i,n+1){
rep(j,n+1){
rep(k,n+1) dp[i][j][k]=-INF;
}
}
dp[0][0][0]=0;
rep(i,n){
rep(j,n){
for(ll k=0;k<cnt;k++){
chmax(dp[i+1][j][k],dp[i][j][k]);
if(dp[i][j][k]!=-INF){
ll y=(k+a[i])%cnt;
if(dp[i][j][k]+a[i]<=x){
chmax(dp[i+1][j+1][y],dp[i][j][k]+a[i]);
}
}
}
}
}
if(dp[n][cnt][x%cnt]!=-INF){
chmin(ans,(x-dp[n][cnt][x%cnt])/cnt);
}
}
out(ans);
}
//ペナルティ出しても焦らない ACできると信じろ!!!
//どうしてもわからないときはサンプルで実験 何か見えてくるかも
//頭で考えてダメなら紙におこせ!! | /*
* @author: codancer
* @createTime: 2020-12-05, 19:52:03
*/
#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;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9+7;
#define pb push_back
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define fep(i,a,b) for(int i=(a);i>=(b);i--)
#define deb(x) cerr<<#x<<" = "<<(x)<<"\n"
typedef vector<int> VI;
typedef vector<ll> VII;
typedef pair<int,int> pii;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll Rand(ll B) {
return (ull)rng() % B;
}
char win(char a,char b){
if(a==b) return a;
if(a=='R'&&b=='S'||a=='S'&&b=='R') return 'R';
if(a=='R'&&b=='P'||a=='P'&&b=='R') return 'P';
if(a=='S'&&b=='P'||a=='P'&&b=='S') return 'S';
}
const int N = 102;
int n,k;
string s;
ll pw[101];
char solve(ll l,ll r){
// cout<<"dad"<<endl;
if(l==r){
return s[l%n];
}
ll mid=(l+r)/2;
return win(solve(l,mid),solve(mid+1,r));
}
int main(){
pw[0]=1;
for(int i=1;i<=25;i++) pw[i]=pw[i-1]*2;
// cout<<"oo"<<endl;
cin>>n>>k;
cin>>s;
cout<<solve(0,pw[min(k,25)]-1)<<endl;
return 0;
}
//
//1 2 3 4 |
#include <bits/stdc++.h>
using namespace std;
mt19937_64 llrand((int) chrono::steady_clock::now().time_since_epoch().count());
#define st first
#define nd second
#define pb push_back
#ifndef ONLINE_JUDGE
#define db(x) cerr << #x << " == " << x << endl
#define dbs(x) cerr << x << endl
#define _ << ", " <<
#else
#define db(x) ((void)0)
#define dbs(x) ((void)0)
#endif
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
const int INF = 0x3f3f3f3f, MOD = 1e9+7;
const int N = 2e5+5;
int n;
bool used[N];
int pos[N];
int a[N];
vector<int> ans;
bool prob;
void change(int i, int j) {
swap(a[i], a[j]);
swap(pos[a[i]], pos[a[j]]);
used[i] = true;
ans.push_back(i);
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> n;
for(int i = 1; i <= n; i++) {
cin >> a[i];
pos[a[i]] = i;
}
for(int i = 1; i <= n; i++) {
while(pos[i] != i) {
if(used[pos[i] - 1]) {
prob = true;
break;
}
change(pos[i] - 1, pos[i]);
}
if(prob) break;
}
for(int i = 1; i < n; i++) if(!used[i]) prob = true;
if(prob) cout << -1 << "\n";
else {
for(auto x : ans) cout << x << "\n";
}
}
| #include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>
//#include<atcoder/all>
using namespace std;
//using namespace atcoder;
typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.12f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e18;
const ll MAX_N = 1010101;
//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX_N; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(ll n, ll k) {
if (n < k) return 0;
if (n < 0 || k < 0) return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// mod.m での a の逆元 a^ { -1 } を計算する
long long modinv(long long a, long long m) {
long long b = m, u = 1, v = 0;
while (b) {
long long 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 gcd(ll x, ll y) {
return y ? gcd(y, x % y) : x;
}
ll lcm(ll x, ll y) {
if (x == 0 || y == 0)return 0;
return (x / gcd(x, y) * y);
}
//union-find木について
//サイズによる更新をしている
ll par[201010];
ll rank2[201010];
void init(ll n) {
rep(i, n) {
par[i] = i;
rank2[i] = 1;
}
}
ll find(ll x) {
if (par[x] == x) {
return x;
}
else {
return par[x] = find(par[x]);
}
}
void unite(ll x, ll y) {
x = find(x);
y = find(y);
if (x == y)return;
if (rank2[x] < rank2[y]) {
par[x] = y;
rank2[y] += rank2[x];
}
else {
par[y] = x;
rank2[x] += rank2[y];
}
}
ll dx[4] = { 1,-1,0,0 };
ll dy[4] = { 0,0,1,-1 };
//long longしか使わない
//素数は1より大きい
//lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
//upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
ll n;
cin >> n;
vector<ll>a(n), p(n), ans;
rep(i, n) {
cin >> a[i];
a[i]--;
p[a[i]] = i;
}
rep(i, n) {
for (ll j = p[i];j > i;j--) {
swap(a[j], a[j - 1]);
ans.push_back(j);
p[a[j - 1]]++;
}
if (ans.size() >= n) {
cout << -1 << endl;
return 0;
}
}
rep(i, n) {
if (a[i] != i) {
cout << -1 << endl;
return 0;
}
}
if (ans.size() != n - 1) {
cout << -1 << endl;
return 0;
}
rep(i, n - 1) {
cout << ans[i] << endl;
}
return 0;
} |
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
/*coment
*/
int main () {
using ll = long long int ;
using p = pair<int,int>;
int a,b,x,y;
cin >> a >> b >> x >> y;
// a + 1 = b// a = b
int t = 0;
if (a - 1 == b) {
cout << x << endl;
}
else {
if (a > b) {
if (x * 2 < y) {
cout << x * (1 + 2 * (a-b-1)) << endl;
}
else {
cout << x + y * (a - b-1) << endl;
}
}
else {
if (x * 2 < y) {
cout << x * (1 + 2 *(b-a)) << endl;
}
else {
cout << x + y * (b-a) << endl;
}
}
}
} | //nik
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("Ofast")
#define reg register
#define FOR(a, b, c) for (a = b; a <=c; a++)
#define rFOR(a, b, c) for (a = b;a >= c; a--)
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define SORT(x) sort(all(x))
#define all(x) x.begin(), x.end()
#define newl "\n"
#define alls(x) x.begin(), x.end(), x.begin()
#define umap(v, t1, t2) unordered_map<t1, t2> v
#define uset(v,t1) unordered_set<t1> v
#define IOF ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
using UL = unsigned long int;
using UI = unsigned int;
using ULL = unsigned long long int;
using LI = long int;
using LL = long long;
using LF = double;
using LLF = long double;
const int MOD1 = 1000000007;
/*const int MOD2 = */
/* Combinatorics Start */
int binoMax = 10000;
vector<LL> numInv(binoMax + 1), factNumInv(binoMax + 1), fact(binoMax + 1);
inline void generate_ncrp(LL p)
{ int i;numInv[0] = numInv[1] = 1;
FOR(i, 2, binoMax)
{ numInv[i] = numInv[p % i] * (p - p / i) % p;
} factNumInv[0] = factNumInv[1] = 1;
FOR(i, 2, binoMax)
{ factNumInv[i] = (numInv[i] * factNumInv[i - 1]) % p;
}
fact[0] = 1;
FOR(i, 1, binoMax)
{ fact[i] = (fact[i - 1] * i) % p;
}
}
LL ncrmodp(LL n, LL r, LL p)
{ LL ans = ((fact[n] * factNumInv[r]) % p * factNumInv[n - r]) % p;
return ans;
}
/* Combinatorics End */
LL expmodp(LL x, LL y, LL p)
{ LL res = 1;
while (y > 0)
{ if (y & 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}return res;
}
/* Matrix Operations Start */
struct Matrix{
int row,col;
vector<vector<LL> > a;
Matrix(int r,int c){
row=r;col=c;
a.resize(row,vector<LL>(col,0));
; }
static Matrix IDM(LL n){
Matrix res(n,n);
for(int i=0;i<n;i++)res.a[i][i]=1;
return res;
}
};
Matrix Matmult(Matrix A,Matrix B){
Matrix res(A.row,B.col);
LL i,j,k;
FOR(i,0,A.row-1){
FOR(j,0,B.col-1){
FOR(k,0,A.col-1){
res.a[i][j]=(res.a[i][j]+A.a[i][k]*B.a[k][j])%MOD1;
}
}
}
return res;
}
Matrix BinExp(Matrix X,LL n){
Matrix res=Matrix::IDM(X.row);
while(n>0){
if(n&1){
res=Matmult(X,res);
}
X=Matmult(X,X);
n>>=1;
}
return res;
}
/* Matrix Operations End */
int main()
{
IOF
LL i,j,k,n,tc,tp1,tp2,tp3;
LL a,b,x,y;
cin>>a>>b>>x>>y;
if(a==b){
cout<<x;
}
else if(a<b){
int dpa[101],dpb[101];
memset(dpa,0,sizeof(dpa));
memset(dpb,0,sizeof(dpb));
dpb[a]=x;
for(i=min(a,b)+1;i<=max(a,b);i++){
dpb[i]=min(min(x+y,3*x)+dpa[i-1],min(y,2*x)+dpb[i-1]);
dpa[i]=min(min(2*x,y)+dpa[i-1],dpb[i-1]+x);
}
cout<<dpb[b];
}
else{
int dpa[101],dpb[101];
memset(dpa,0,sizeof(dpa));
memset(dpb,0,sizeof(dpb));
dpb[a]=x;
for(i=max(a,b)-1;i>=min(a,b);i--){
dpb[i]=min(dpa[i+1]+x,dpb[i+1]+min(y,2*x));
dpa[i]=min(dpa[i+1]+min(2*x,y),dpb[i+1]+min(3*x,x+y));
}
cout<<dpb[b];
}
} |
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
#define re register
#define pb push_back
#define cl clear
#define MAXN 100005
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
inline int read(){
int x = 0, f = 1;
char ch = getchar();
while(ch<'0'||ch>'9'){
if(ch=='-')
f = -1;
ch = getchar();
}
while(ch>='0'&&ch<='9'){
x=(x<<1)+(x<<3)+(ch^48);
ch = getchar();
}
return x*f;
}
ll n, l, A[MAXN], B[MAXN], ans;
void solve(){
n = read();
l = read();
A[n+1] = B[n+1] = l + 1;
for(re int i = 1 ; i <= n ; ++i)
A[i] = read();
for(re int i = 1 ; i <= n ; ++i)
B[i] = read();
for(re int i = n + 1 ; i >= 1 ; --i){
A[i] = A[i] - A[i-1] - 1;
B[i] = B[i] - B[i-1] - 1;
}
int cnt = 1;
for(re int i = 1 ; i <= n + 1 ; ++i){
if(!B[i]) continue;
while(!A[cnt]) ++cnt;
ll sum = 0, st = cnt, ed;
while(sum<B[i]&&cnt<=n+1){
sum += A[cnt++];
//printf("i = %d cnt = %d sum = %d\n",i,cnt,sum);
}
if(sum!=B[i]){
printf("-1\n");
return ;
}
ed = cnt - 1;
ans += max(0ll,i-st) + max(0ll,ed-i);
}
printf("%lld\n",ans);
}
int main(){
int t = 1;
//t = read();
while(t--) solve();
return 0;
}
| #include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string>
#include <vector>
#include <cstdlib>
using namespace std;
int main(){
int N,M,tmp,cnt,ANS_size;
vector<int>vec,ANS_vec;
cin>>N>>M;
for(int i = 1;i<=N+M;i++){
cin>>tmp;
vec.push_back(tmp);
}
for(int i=1;i<=pow(10,3);i++){
cnt = 0;
for(int j=0;j<N+M;j++){
if(vec[j] == i){
cnt++;
}
}
if(cnt == 1){
ANS_vec.push_back(i);
};
}
ANS_size = ANS_vec.size();
for(int i=0;i<ANS_size;i++){
cout<<ANS_vec[i]<<" ";
}
cout<<endl;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long; // 2^31-1
using P = pair<string, int>; // 2変数を一括でつかえる 2重にすれば3,4変数同時も.
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repi(i, s, n) for (int i = (s); i <= (n); i++)
#define all(v) v.begin(),v.end()
#define INF32 2147483647 // 32bit max
#define INF64 9223372036854775807 // 64bit max
// max, reverse, sort(a,a+n), greater<int>()
int main()
{
ll n,k;
cin >> n >> k;
vector<pair<ll,ll> > x(n);
rep(i,n) cin >> x[i].first >> x[i].second;
sort(all(x));
ll money=k,loc=0;
rep(i,n){
ll cost=x[i].first-loc;
if(loc==x[i].first){
money+=x[i].second;
}
else if(money>=cost){
money-=cost;
loc=x[i].first;
money+=x[i].second;
}else{
break;
}
}
cout << loc+money << endl;
return 0;
} | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define endl '\n'
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define fi first
#define se second
#define int long long
typedef long long ll;
typedef long double ld;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sz(x) ((long long)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define frev(a,b,c) for(int a=c; a>=b; a--)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define trav(a,x) for(auto &a:x)
#define all(con) con.begin(),con.end()
#define done(x) {cout << x << endl;return;}
#define mini(x,y) x=min(x,y)
#define maxi(x,y) x=max(x,y)
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
//const int mod = 998244353;
const int mod = 1e9 + 7;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<int>> vvi;
typedef vector<pair<int, int>> vpii;
typedef map<int, int> mii;
typedef set<int> si;
typedef set<pair<int,int>> spii;
typedef queue<int> qi;
uniform_int_distribution<int> rng(0,1e9);
//DEBUG FUNCTIONS START
#define cerr cout
void __print(int x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define deb(x...) _print(x)
#else
#define deb(x...)
#endif
// DEBUG FUNCTIONS END
const int N = 2e5 + 5;
int powm(int a, int b){
int res = 1;
while (b) {
if (b & 1)
res = res * a % mod;
a = a * a % mod;
b >>= 1;
}
return res;
}
void solve(){
int n, p;
cin >> n >> p;
cout << (p-1) * powm(p-2, n-1) % mod << endl;
}
signed main() {
#ifndef ONLINE_JUDGE
(void)!freopen("input.txt","r",stdin);
(void)!freopen ("output.txt","w",stdout);
#endif
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cout << fixed << setprecision(15);
int t = 1;
//cin >> t;
while (t--)
solve();
return 0;
}
int divide(int a, int b) {
return (a % mod) * powm(b % mod, mod - 2) % mod;
} |
#include<bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define pb push_back
#define vec vector<ll>
#define pii pair<ll,ll>
#define pr_que priority_queue<pii,vector<pii>,greater<pii> >
#define itr(i,x,y) for(ll i=x;i<y;i++)
#define mod 1000000007
const long long N=200001,INF=1000000000000000000;
const double err=1e-9;
int main()
{
IOS;
int n;
cin >> n;
int a[n][5];
itr(i,0,n)
{
itr(j,0,5)
{
cin >> a[i][j];
}
}
int lo=1,hi=1e9,mid;
while(lo<hi)
{
mid=lo+(hi-lo+1)/2;
bool v[1<<5];
itr(i,0,1<<5) v[i]=false;
itr(i,0,n)
{
int mask=0;
itr(j,0,5)
{
if(a[i][j]>=mid)
{
mask=mask^(1<<j);
}
}
v[mask]=true;
}
bool c=false;
itr(i,0,1<<5)
{
if(!v[i]) continue;
itr(j,0,1<<5)
{
if(!v[j]) continue;
itr(k,0,1<<5)
{
if(!v[k]) continue;
if((i|j|k) == (1<<5)-1)
{
c=true;
}
}
}
}
if(c==true) lo=mid;
else hi=mid-1;
}
cout << lo << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const long long MOD = 1000000007;
const long long INF = 9999999999999999;
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; }
ll A[3020][5];
ll N;
bool isOK(ll key){
vector<ll> aup(32);
rep(i,N){
ll temp = 0;
rep(k,5){
if(A[i][k]>=key){
temp+=pow(2,k);
}
}
aup[temp]++;
}
bool aru = 0;
rep(i,32){
rep(k,32){
rep(t,32){
if((i|k|t) == 31){
if(aup[i]>0&&aup[k]>0&&aup[t]>0){
//cout << i << k << t << endl;
aru = 1;
}
}
}
}
}
return aru;
}
int main(){
cin>>N;
rep(i,N){
cin>>A[i][0]>>A[i][1]>>A[i][2]>>A[i][3]>>A[i][4];
}
ll right = MOD;
ll left = -1;
while((right-left)>1){
ll mid=left+(right-left)/2;
if(isOK(mid)){
left = mid;
}
else{
right = mid;
}
}
cout << left << endl;
return 0;
} |
Subsets and Splits