code_file1
stringlengths 87
4k
| code_file2
stringlengths 82
4k
|
---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int a, b;
cin >> a >> b;
cout << 2 * a + 100 - b << "\n";
return 0;
} | #include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
using ll = long long ;
#define rep(i,n) for (int i=0; i < (n); ++i)
int main() {
int a,b ;
cin >> a >> b ;
cout << max((2*a+100)-b,0) << endl ;
return 0 ;
}
|
#include <bits/stdc++.h>
using namespace std;
const uint64_t seed = std::chrono::system_clock::now().time_since_epoch().count();
mt19937_64 rnd(seed);
const int MOD = 998244353;
#ifdef VIPJML_LOCAL
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
os << "{";
for (typename vector<T>::const_iterator vi = v.begin(); vi != v.end(); ++vi)
{
if (vi != v.begin())
os << ", ";
os << *vi;
}
os << "}";
return os;
}
template <typename A, typename B>
ostream &operator<<(ostream &os, const vector<pair<A, B>> &v)
{
os << "{";
for (typename vector<pair<A, B>>::const_iterator vi = v.begin(); vi != v.end(); ++vi)
{
if (vi != v.begin())
os << ", ";
os << '(' << vi->first << " " << vi->second << ")";
}
os << "}";
return os;
}
template <typename A, typename B>
ostream &operator<<(ostream &os, const pair<A, B> &p)
{
os << '(' << p.first << ", " << p.second << ')';
return os;
}
void dbg_out() { cerr << endl; }
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T)
{
cerr << ' ' << H;
dbg_out(T...);
}
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif
using LL = long long;
void solve(int caseNum)
{
LL N, M, T;
cin >> N >> M >> T;
LL cnt = N;
bool f = true;
LL t = 0;
for (int i = 0; i < M; i++)
{
LL A, B;
cin >> A >> B;
cnt -= A - t;
if (cnt <= 0)
f = false;
cnt += B - A;
if (cnt > N)
cnt = N;
t = B;
}
cnt -= T - t;
if (cnt <= 0)
f = false;
cout << (f ? "Yes" : "No") << endl;
}
int main()
{
std::ios::sync_with_stdio(false);
cin.tie(NULL);
cout.precision(10);
int T = 1;
//cin >> T;
for (int i = 1; i <= T; i++)
{
solve(i);
}
cout.flush();
return 0;
}
| //#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
//vector string deque break continue
#define forn(i, s, f) for (int i = (int)s; i < (int)f; i++)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define fs first
#define sc second
#define pf push_front
#define pb push_back
#define pop_f pop_front
#define pop_b pop_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#ifdef DEBUG
#else
#define cerr if (false) cerr
#endif
template <typename T> istream& operator>>(istream& in, vector <T>& a) {for (auto& i : a) in >> i; return in;}
template <typename T> ostream& operator<<(ostream& out, vector <T>& a) {for (auto& i : a) out << i << " "; return out;}
template <typename T, typename U> void chkmin(T& a, U b) {if (a > b) a = b;}
template <typename T, typename U> void chkmax(T& a, U b) {if (a < b) a = b;}
void no() {
cout << "No";
exit(0);
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int n, m, t;
cin >> n >> m >> t;
int cur = n;
vector <pii> c(m);
forn (i, 0, m)
cin >> c[i].fs >> c[i].sc;
int prev = 0;
forn (i, 0, m) {
int a, b;
tie(a, b) = c[i];
cur -= (a - prev);
if (cur <= 0)
no();
cerr << cur << " ";
cur = min(n, cur + (b - a));
prev = b;
cerr << cur << "\n";
}
cur -= (t - prev);
if (cur <= 0)
no();
cout << "Yes";
return 0;
}
|
#pragma GCC optimize ("O2")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please
const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
if (ci - owa > 0) {
memcpy(cn, owa, CL);
ci -= CM;
fread(cn + CL, 1, CM, stdin);
}
ll tmp = *(ll*)ci;
if ((tmp & ma0) ^ ma0) {
int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
tmp = tmp << dig & ma1;
tmp = tmp * 10 + (tmp >> 8) & ma2;
tmp = tmp * 100 + (tmp >> 16) & ma3;
tmp = tmp * 10000 + (tmp >> 32) & ma4;
ci += (72 - dig >> 3);
}
else {
tmp = tmp & ma1;
tmp = tmp * 10 + (tmp >> 8) & ma2;
tmp = tmp * 100 + (tmp >> 16) & ma3;
tmp = tmp * 10000 + (tmp >> 32) & ma4;
ci += 8;
if ((ct = *ci++) >= '0') {
tmp = tmp * 10 + ct - '0';
if ((ct = *ci++) >= '0') {
tmp = tmp * 10 + ct - '0';
ci++;
}
}
}
return tmp;
}
ll tmp[200001];
void pakuri_sort(int N, ll A[]) {
const int b = 8;
rep(k, 4) {
int kazu[1 << b] = {}, kazu2[1 << b] = {};
rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++;
rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];
for (int i = N - 1; i >= 0; i--) tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i];
k++;
rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++;
rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];
for (int i = N - 1; i >= 0; i--) A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i];
}
}
bitset<400010> ST;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N = getint(), M = getint();
ll XY[200000];
int k = 0;
int nm1 = N - M, nm2 = N + M;
rep(i, M) {
int x = getint();
int y = getint();
if (y < nm1 | y > nm2) continue;
XY[k++] = x | (ll)(y - N + 200001) << 32;
}
M = k;
pakuri_sort(M, XY);
ST[200001] = 1;
const ll ma = (1ll << 32) - 1;
int m = 0;
while (m < M) {
int m0 = m;
int x = (XY[m] & ma);
while (m < M && (XY[m] & ma) == x) {
int y = (XY[m] >> 32);
if (ST[y - 1] | ST[y + 1]) XY[m] |= 1ll;
else if (ST[y]) XY[m] &= (~1ll);
else XY[m] = 0;
m++;
}
for (int p = m0; p < m; p++) {
int y = (XY[p] >> 32);
if (XY[p] & 1) ST[y] = 1;
else if (XY[p]) ST[y] = 0;
}
}
int kotae = ST.count();
printf("%d\n", kotae);
Would you please return 0;
} | #include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#define dout cout
#define debug() if (true)
#define dvout(v) vout(v)
#else
#define dout if (false) cout
#define debug() if (false)
#define dvout(v) if(false) vout(v)
#endif
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define vout(v) \
for (auto &i : v) \
{ \
cout << i << " "; \
} \
cout << "\n"; //配列出力
#define vec(v, n) vector<int> v(n, 0);
#define vecll(v, n) vector<ll> v(n, 0);
#define vecvec(v,n,m) vector<vector<int>> v(n, vector<int>(m));
#define vin(v) \
for (auto &i : v) \
cin >> i; //配列入力
#define mod (ll)(1e9+7)
typedef long long ll;
typedef unsigned long long ull;
#define next asdnext
#define prev asdprev
#define _n "\n"
#define _n2 "\n\n"
#define _t "\t"
// LLONG_MAX 9.2*1e18 9223372036854775807LL = (2^63)-1
// INT_MAX 2.1*1e9 2147483647 = (2^31)-1
// O(1e8) 1.2sec
void test(ull,ull,ull);
//#define FOR_CODEFORCES
void Main()
{
string S;
cin>>S;
if(S.size()==1){
if(S[0]=='8')cout<<"Yes"<<endl;
else cout<<"No"<<endl;
return;
}
if(S.size()==2){
int a=(S[0]-'0')*10 + (S[1]-'0');
int b=(S[1]-'0')*10 + (S[0]-'0');
if(a%8==0 || b%8==0)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
return;
}
if(S.size()==3){
int a=S[0]-'0';
int b=S[1]-'0';
int c=S[2]-'0';
int nums[6];
nums[0]=a*100+b*10+c;
nums[1]=a*100+c*10+b;
nums[2]=b*100+a*10+c;
nums[3]=b*100+c*10+a;
nums[4]=c*100+b*10+a;
nums[5]=c*100+a*10+b;
rep(i,6){
if(nums[i]%8==0){
cout<<"Yes"<<endl;
return;
}
}
cout<<"No"<<endl;
return;
}
int flags[10]={};
rep(i,S.size()){
flags[S[i]-'0']++;
}
for(int i=0; i<1000; i+=8){
int a,b,c;
a=i/100;
b=(i%100)/10;
c=(i%10);
int flags2[10]={};
flags2[a]++;
flags2[b]++;
flags2[c]++;
bool isOK=true;
rep(j,10){
isOK &= (flags[j]>=flags2[j]);
}
if(isOK){
cout<<"Yes"<<endl;
return;
}
}
cout<<"No"<<endl;
}
void test(){
}
int main()
{
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << std::fixed << std::setprecision(15);
#ifdef FOR_CODEFORCES
int t=0;
cin>>t;
rep(i,t)Main();
#else
Main();
#endif
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(),(x).end
#define rall(x) (x).rbegin(),(x).rend
const int MOD=(int)1e9+7;
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
//freopen("teamwork.in","r",stdin);
//freopen("teamwork.out","w",stdout);
int n;
cin>>n;
int a[n+1],pref[n+1]={};
for(int i=1;i<=n;i++){
cin>>a[i];
pref[i]=a[i]+pref[i-1];
}
int sum1=0,sum2=0;
for(int i=1;i<=n;i++) sum1+=(a[i]*a[i]);
sum1*=n-1;
for(int i=1;i<=n;i++){
sum2+=a[i]*(pref[n]-pref[i]);
}
sum2*=(-2);
cout<<sum1+sum2;
}
| #include<cstdio>
#include<set>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<cstdlib>
#include<time.h>
#include<string>
#include<stack>
#include<cmath>
#include<iostream>
#include<cstring>
#include<complex>
#include<tr1/unordered_set>
#include<tr1/unordered_map>
#include <chrono>
#include <iomanip>
using namespace std;
using namespace tr1;
#define FOR(i,j,k) for(int i=j;i<k;i++)
#define FORD(i,j,k) for(int i=j;i>=k;i--)
#define ll long long
//Make sure no overflow problems
#define pii pair<int, int>
#define vi vector<int >
#define pb push_back
#define mp make_pair
#define fffirst
#define ss second
#define VAR(i,n) __typeof(n) i = (n)
#define FOREACH(i,c) for(VAR(i,(c).begin());i!=(c).end();i++)
#define FORDEACH(i,c) for( VAR(i,(c).rbegin()),i!=(c).rend();i++)
#define REP(i,n) FOR(i,0,n)
#define ld long double
const int INF = 1000000009;
const long long INFLL = (ll)INF * (ll)INF;
const ld EPS = 10e-9;
///////////////////////////////////////////////////////////////
#define curr_time std::chrono::high_resolution_clock::now()
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
int n;
cin>>n;
map<int,ll> freq;
int val;
for(int i=0;i<n;i++){
cin>>val;
freq[val]++;
}
ll ans=0;
for(int i=-200;i<=200;i++){
for(int j=i+1;j<=200;j++){
ans+=freq[i]*freq[j]*abs(i-j)*abs(i-j);
}
}
cout<<ans;
return 0;
} |
/*
********************
** MEET SHAH **
** DA-IICT **
** decoder_0712 **
********************
*/
#include <bits/stdc++.h>
using namespace std;
//#include <time.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define setpre(x,d) fixed<<setprecision(d)<<x
//#define fill(a,x) memset(a,x,sizeof(a));
#define inarr(a,n) for(int i=0;i<n;i++) cin>>a[i];
#define outarr(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl;
#define maxa(a,n) *max_element(a,a+n)
#define mina(a,n) *min_element(a,a+n)
#define fr(i,s,e) for(ll i=s;i<e;i++)
#define rf(i,s,e) for(ll i=s-1;i>=e;i--)
#define deb1(x) cout<<#x<<" : "<<x<<endl;
#define deb2(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<endl;
#define deb3(x,y,z) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;
#define deb4(x,y,z,w) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<"\t"<<#w<<" : "<<w<<endl;
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
#define sz size()
#define len length()
#define all(v) v.begin(),v.end()
#define PI 3.141592653589793
#define MOD 1000000007
#define NN (const int)5e5+10
#define ub upper_bound
typedef long long int ll;
typedef long double lld;
typedef pair<long long,long long> pll;
typedef vector<long long> vll;
typedef vector<pair<long long,long long> > vpll;
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b) { return (a.second < b.second); }
// void fileio() { freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); }
// vll fact(NN),invfact(NN);
// void EE(ll a,ll b,ll &x,ll &y) { if(b==0) { x=1,y=0; return ; } EE(b,a%b,x,y); ll temp=x; x=y; y=temp-(a/b)*y; }
// ll inverse(ll a,ll mod) { ll x,y; EE(a,mod,x,y); return (x+mod)%mod; }
// void build() { fact[0]=1; fr(i,1,NN) fact[i]=(fact[i-1]*i)%MOD; invfact[NN-1]=inverse(fact[NN-1],MOD); rf(i,NN-1,0) invfact[i]=(invfact[i+1]*(i+1))%MOD; }
// ll ncr(ll n,ll r) { if(n<0 || r<0 || r>n) return 0; return (fact[n]*((invfact[n-r]*invfact[r])%MOD))%MOD; }
// ll choose(ll n,ll k) { if(k==0) return 1; return (n* choose(n-1,k-1))/k; }
ll logy(ll x,ll y) { return ceil((lld)(log(x)/log(y))); }
ll powe(ll a,ll b) { ll re=1; while(b){ if(b&1) re=(re*a)%MOD; a=(a*a)%MOD; b=b>>1;} return re; }
/*
ll i,j,x,y,k,z,cnt;
vector<vector<ll> > a(100005);
vector<ll> vis(100005,0),visited(100005,0);
void dfs(int u)
{
visited[u]=1;
vector<ll>::iterator it;
for(it=a[u].begin();it!=a[u].end();it++)
{
if(visited[*it]==0)
{
dfs(*it);
}
}
}
*/
bool flag=0,flag1=0,flag2=0;
int main()
{
IOS
ll a,b,c,d,ans;
cin>>a>>b>>c>>d;
ll t1=a-c;
ll t2=a-d;
ll t3=b-c;
ll t4=b-d;
ll mx1=max(t1,t2);
ll mx2=max(t3,t4);
cout<<max(mx1,mx2)<<endl;
return 0;
} | #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;}
//-------------------------------------------------------
int N;
string S;
int A[10101];
int L[101],R[101],B[101];
pair<int,int> P[101];
int ret[101][10101];
int hoge(int v) {
int i,j;
int lef[101];
if(v>=10001) return 0;
FOR(j,N+1) {
int sum=0;
FOR(i,v) {
ret[j][i]=A[j]/v+(i<A[j]%v);
sum+=ret[j][i];
}
assert(sum==A[j]);
}
FOR(i,N) {
FOR(j,v) {
if(S[i]=='<' && ret[i][j]>=ret[i+1][j]) return 0;
if(S[i]=='>' && ret[i][j]<=ret[i+1][j]) return 0;
}
}
return 1;
}
void solve() {
int i,j,k,l,r,x,y; string s;
cin>>N>>S;
FOR(i,N+1) cin>>A[i];
FOR(i,N) {
if(S[i]=='<') L[i+1]=L[i]+1;
else L[i+1]=0;
}
for(i=N-1;i>=0;i--) {
if(S[i]=='>') R[i]=R[i+1]+1;
else R[i]=0;
}
FOR(i,N+1) {
B[i]=max(L[i],R[i]);
P[i]={-B[i],i};
}
sort(P,P+N+1);
int re=1;
for(i=15;i>=0;i--) if(hoge(re+(1<<i))) re+=1<<i;
assert(hoge(re));
cout<<re<<endl;
FOR(i,re) {
FOR(j,N+1) cout<<ret[j][i]<<" ";
FOR(j,N) {
if(S[j]=='<') assert(ret[j][i]<ret[j+1][i]);
if(S[j]=='>') assert(ret[j][i]>ret[j+1][i]);
}
cout<<endl;
}
}
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>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long int
#define mp(a,b) make_pair(a,b)
#define vi vector<int>
#define mii map<int,int>
#define mpi map<pair<int,int>,int>
#define msi map<string,int>
#define vp vector<pair<int,int> >
#define pb(a) push_back(a)
#define fr(i,n) for(i=0;i<n;i++)
#define rep(i,a,n) for(i=a;i<n;i++)
#define F first
#define S second
#define endl "\n"
#define Endl "\n"
#define fast std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define dom 998244353
#define sl(a) (int)a.length()
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define mini 2000000000000000000
#define time_taken 1.0 * clock() / CLOCKS_PER_SEC
//const long long INF=1e15;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//auto dist=uniform_int_distribution<int>(0,INF);
//const long double pi = acos(-1);
//primes for hashing 937, 1013
typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
template<typename T, typename U> static inline void amin(T &x, U y)
{
if (y < x)
x = y;
}
template<typename T, typename U> static inline void amax(T &x, U y)
{
if (x < y)
x = y;
}
void shikhar7s(int cas)
{
int n,i;
cin>>n;
vp v;
int x,y;
fr(i,n)
{
cin>>x>>y;
v.pb(mp(y,x));
}
sort(all(v));
vi a,b,aa,ba;
i=0;
int l=mini,r=-mini;
while(i<n&&v[i].F==v[0].F)
{
a.pb(v[i].S);
l=min(l,v[i].S);
r=max(r,v[i].S);
i++;
}
sort(all(a));
aa.resize(sz(a));
int j;
fr(j,sz(a))
{
if(l>=0)
aa[j]=2*r-a[j];
else if(a[j]>0)
aa[j]=2*(r-l)-a[j];
else if(r>0)
aa[j]=2*(r-l)+a[j];
else
aa[j]=a[j]-2*l;
}
rep(i,i,n)
{
int j=i,l=mini,r=-mini;
while(j<n&&v[j].F==v[i].F)
{
b.pb(v[j].S);
l=min(l,v[j].S);
r=max(r,v[j].S);
j++;
}
i=j-1;
sort(all(b));
ba.resize(sz(b),mini);
fr(j,sz(b))
{
int k=lower_bound(all(a),r)-a.begin();
if(k<sz(a))
ba[j]=min(ba[j],aa[k]+a[k]+b[j]-2*l);
k--;
if(k>=0)
ba[j]=min(ba[j],aa[k]+2*(r-l)+b[j]-a[k]);
k=lower_bound(all(a),l)-a.begin();
if(k<sz(a))
ba[j]=min(ba[j],aa[k]+2*(r-l)+a[k]-b[j]);
k--;
if(k>=0)
ba[j]=min(ba[j],aa[k]+2*r-a[k]-b[j]);
// cout<<b[j]<<" "<<ba[j]<<endl;
}
a=b;
aa=ba;
b.clear();
ba.clear();
}
int ans=mini;
fr(i,sz(a))
{
ans=min(ans,aa[i]+abs(a[i]));
}
cout<<ans;
}
signed main()
{
fast;
//freopen("input.txt", "rt", stdin);
//freopen("output.txt", "wt", stdout);
int t=1;
//cin>>t;
int cas=1;
while(cas<=t)
{
//cout<<"Case #"<<cas<<": ";
shikhar7s(cas);
cas++;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define N 200000
int main(){
int a, b;
cin >> a >> b;
if( a >= b ){
for( int i = 1; i <= a; i++ ){
cout << i << " ";
}
for( int i = 1; i <= b-1; i++ ){
cout << -i << " ";
}
cout << -(((a+1)*a)/2 - (b-1+1)*(b-1)/2) << endl;
}else{
for( int i = 1; i <= b; i++ ){
cout << -i << " ";
}
for( int i = 1; i <= a-1; i++ ){
cout << i << endl;
}
cout << (1+b)*b/2 - (a-1+1)*(a-1)/2 << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
#define mp(a,b) make_pair(a,b)
#define ff first
#define setp(a) setprecision(a)<<fixed
#define ss second
#define fori(v) for(ll i=0; i<v; i++)
#define forj(v) for(ll j=0; j<v; j++)
#define fork(v) for(ll k=0; k<v; k++)
#define forl(v) for(ll l=0; l<v; l++)
#define fort(v) for(ll t=0; t<v; t++)
#define forz(v) for(ll z=0; z<v; z++)
#define forx(v) for(ll x=0; x<v; x++)
#define fory(v) for(ll y=0; y<v; y++)
#define ll long long
#define ld long double
#define MAX (int)(pow(10,6) + 10)
#define pb(a) push_back(a)
const ll INF = 0x3f3f3f3f;
const ll inf = pow(10,18);
ll modulo = pow(10,9)+7;
struct p3d{ ld x,y,z;
p3d(ld a, ld b, ld c): x(a), y(b), z(c){}
friend ostream& operator<< (ostream& os, const p3d& p) {
return os << "(" << p.x << "," << p.y << "," << p.z << ")"; } };
ld abs(const p3d &v){ return sqrt(v.x*v.x + v.y*v.y + v.z*v.z); }
p3d operator+(const p3d& a, const p3d& b) {
return {a.x+b.x,a.y+b.y,a.z+b.z}; }
p3d operator-(const p3d& a, const p3d& b) {
return {a.x-b.x,a.y-b.y,a.z-b.z}; }
p3d operator*(const ld &s, const p3d &v){ return {s*v.x,s*v.y,s*v.z}; }
p3d operator/(const p3d&v, const ld &s){ return {v.x/s, v.y/s, v.z/s}; }
inline ld dot(const p3d &a, const p3d &b){
return a.x*b.x + a.y*b.y + a.z*b.z; }
inline p3d cross(const p3d &a, const p3d &b){
return {a.y*b.z - a.z*b.y, a.z*b.x - a.x*b.z, a.x*b.y - a.y*b.x}; }
p3d rotate(const p3d& p/*pt*/, const p3d& u/*axis*/, const ld& angle) {
ld c = cos(angle), s = sin(angle), t = 1 - cos(angle); return {
p.x*(t*u.x*u.x + c)+p.y*(t*u.x*u.y - s*u.z)+p.z*(t*u.x*u.z + s*u.y),
p.x*(t*u.x*u.y + s*u.z)+p.y*(t*u.y*u.y + c)+p.z*(t*u.y*u.z - s*u.x),
p.x*(t*u.x*u.z - s*u.y)+p.y*(t*u.y*u.z + s*u.x)+p.z*(t*u.z*u.z + c)
}; } // hash: 3f78e3
void deal(){
ld n, x1, y1, xn, yn;
cin>>n>>x1>>y1>>xn>>yn;
ld angle = M_PI/(n/2.0);
p3d center((x1+xn)/2.0, (y1+yn)/2.0, (ld)0);
p3d a(x1,y1,0);
p3d aRelative = a-center;
p3d axis(0, 0, 1.0);
// cout<<"a relative "<<aRelative.x<<" "<<aRelative.y<<endl;
aRelative = rotate(aRelative, axis, angle);
// cout<<"a relative after rotation "<<aRelative.x<<" "<<aRelative.y<<endl;
aRelative = aRelative + center;
cout<<setp(10)<<aRelative.x<<' '<<aRelative.y;
}
int main(){
cin.tie(0);
ios_base::sync_with_stdio(0);
deal();
}
| #include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld long double
#define mod 1000000007ll
#define md 998244353ll
#define e1 1e-9
#define v vector< long long >
#define vp vector< pair < long long,long long > >
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ft first
#define sd second
#define all(x) x.begin() , x.end()
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define test \
ll tt{0}; \
cin>>tt; \
while(tt--)
using namespace std;
bool prime(ll n) {
if (n < 2)return false;
for (ll x = 2; x * x <= n; x++) {
if (n % x == 0)return false;
}
return true;
}
vector<ll> Seiveprime(ll n)
{
vector<bool> isPrime(n, true);
for (int i = 2; i * i < n; i++)
{
if (isPrime[i])
{
for (int j = i * i; j < n; j += i)
isPrime[j] = false;
}
}
vector<ll> prime;
prime.push_back(2);
for (int i = 3; i < n; i += 2)
if (isPrime[i])
prime.push_back(i);
return prime;
}
vector<ll> factors(ll n) {
vector<ll> f;
for (ll x = 2; x*x <= n; x++) {
while (n%x == 0) {
f.pb(x);
n /= x;
}
}
if (n > 1) f.pb(n);
return f;
}
vp pri_fact(ll n) {
v x = factors(n);
vp y;
y.eb(x[0], 1);
for (ll i = 1; i < x.size(); i++) {
if (x[i] == x[i - 1]) {
y.back().second++;
} else {
y.eb(x[i], 1);
}
}
return y;
}
ll lcm(ll a,ll b) {
return (a * b) / __gcd(a, b);
}
tuple<int,int,int> gcd(int a, int b) {
if (b == 0) {
return {1,0,a};
} else {
int x,y,g;
tie(x,y,g) = gcd(b,a%b);
return {y,x-(a/b)*y,g};
}
}
ll mult(ll x,ll y,ll m) {
return (x * y) % m;
}
//returns x^n (mod m)
ll bin_pow(ll x,ll n,ll m) {
if (n == 0)return 1;
if (n & 1)return mult(x, bin_pow(x, n - 1, m), m);
return bin_pow(mult(x, x, m), n / 2, m);
}
ll ind_of_2(ll x) {
ll i = 0;
while (x / (1 << i) != 1)
i++;
return i;
}
ll add(ll x,ll y)
{
x+=y;
if(x>=md)return x-md;
return x;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
ll n{0},d{0},h{0};
cin>>n>>d>>h;
v dd(n),hh(n);
loop(i,0,n)cin>>dd[i]>>hh[i];
ld temp{0};
loop(i,0,n){
ld x=1.0*(d*hh[i] - h*dd[i])/(d-dd[i]);
if(x>=0)temp=max(temp, x);
}
cout<<fixed<<setprecision(15)<<temp;
return 0;
} |
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
#include <random>
#include <cassert>
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using namespace std;
#define int long long
#define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define REPE(i, n) for (int (i)=0; (i) <= (n); (i)++)
#define CONTAINS_MAP(m, a) ((m).find((a)) != m.end())
#define CONTAINS_SET(m, a) ((m).find((a)) != m.end())
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; exit(0); }
void Yes() { cout << "Yes" << endl; exit(0); }
void No() { cout << "No" << endl; exit(0); }
int N;
string S;
int A[110];
int _m[110];
signed main()
{
cin >> N;
cin >> S;
REP(i, N + 1) cin >> A[i];
int k = INT_MAX;
for (int i = 0; i < N; i++)
{
int diff = abs(A[i] - A[i + 1]);
k = min(diff, k);
}
for (int i = 0; i < N + 1; i++)
{
_m[i] = A[i] % k;
}
cout << k << endl;
for (int i = 0; i < k; i++)
{
for (int i = 0; i < N + 1; i++)
{
int m = _m[i] > 0 ? 1 : 0;
cout << A[i] / k + m << " ";
_m[i]--;
}
cout << endl;
}
}
| /*
author: Kamal Kant Bhardwaj
date:
*/
#include<bits/stdc++.h>
using namespace std;
#define N 3005
#define ff first
#define ss second
#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define vi vector<int>
#define mii map<int,int>
#define pqb priority_queue<int>
#define pqs priority_queue<int,vi,greater<int> >
#define setbits(newx) __builtin_popcountll(newx)
#define zrobits(newx) __builtin_ctzll(newx)
#define mod 1000000007
#define inf 1e18
#define ps(newx,y) finewxed<<setprecision(y)<<newx
#define mk(arr,n,type) type *arr=new type[n];
#define w(newx) int newx; cin>>newx; while(newx--)
void c_p_c()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
int mat[10005][103];
int32_t main()
{
c_p_c();
int n; cin >> n; string s; cin >> s;
int a[103];
for (int i = 0; i <= n; i++)
cin >> a[i];
int maxi = mod;
for (int i = 1; i <= n; i++)
{
maxi = min(maxi, abs(a[i] - a[i - 1]));
}
int sum = 0;
for (int i = 0; i < 10005; i++)
for (int j = 0; j < 103; j++)
mat[i][j] = 0;
int div = a[0] / maxi;
int rem = a[0] % maxi;
for (int j = 0; j < maxi; j++)
{
mat[j][0] = div ;
if (rem > 0)
{
mat[j][0] += 1;
}
rem--;
sum += mat[j][0];
}
for (int i = 1; i <= n; i++)
{
// int newsum = 0;
// int diff = abs(a[i] - sum);
int div = a[i] / maxi;
int rem = a[i] % maxi;
// cout << div << " " << rem << endl;
for (int j = 0; j < maxi; j++)
{
mat[j][i] = div;
if (rem > 0)
mat[j][i] += 1;
rem--;
}
}
cout << maxi << endl;
for (int j = 0; j < maxi; j++)
{
for (int i = 0; i <= n; i++)
{
cout << mat[j][i] << " ";
}
cout << endl;
}
return 0;
} |
#include <bits/stdc++.h>
# define rep0(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define ALL(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
int N;
int main() {
// 1. input
cin>>N;
vector<int> A(N),B(N);
rep0(i,N) cin >> A[i];
rep0(i,N) cin >>B[i];
// 2.
int ans = max(0, *min_element(ALL(B)) - *max_element(ALL(A)) +1);
// 3. output
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define forin(in ,n) for(ll i=0; i<n; i++) cin>>in[i]
#define forout(out) for(ll i=0; i<(ll)out.size(); i++) cout<<out[i]<<endl
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep_up(i, a, n) for (ll i = a; i < n; ++i)
#define rep_down(i, a, n) for (ll i = a; i >= n; --i)
#define P pair<ll, ll>
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define vvvll vector<vector<vector<ll>>>
#define vvll vector<vector<ll>>
#define vll vector<ll>
#define pqll priority_queue<ll>
#define pqllg priority_queue<ll, vector<ll>, greater<ll>>
constexpr ll INF = (1ll << 60);
constexpr ll mod = 1000000007;
//constexpr ll mod = 998244353;
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <typename T>
inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <typename T>
void pt(T val) {
cout << val << "\n";
}
template <typename T>
void pt_vll(vector<T> &v) {
ll vs = v.size();
rep(i, vs) {
cout << v[i];
if (i == vs - 1)
cout << "\n";
else
cout << " ";
}
}
ll mypow(ll a, ll n) {
ll ret = 1;
if(n==0) return 1;
if(a==0) return 0;
rep(i, n) {
if (ret > (ll)(9e18 + 10) / a) return -1;
ret *= a;
}
return ret;
}
long long modpow(long long a, long long n, long long mod) {
long long res = 1;
while (n > 0) {
if (n & 1) res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
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 digsum(ll n) {
ll res = 0;
while(n > 0) {
res += n%10;
n /= 10;
}
return res;
}
struct UnionFind {
vector<ll> par,size;
UnionFind(ll N) : par(N) { //最初はすべてが根であるとして初期化
size.resize(N,1);
for(ll i=0;i<N;i++) par[i] = i;
}
ll root(ll 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);
ll ry = root(y);
if(rx == ry) return; //同じ木にあるときはそのまま
if(size[rx]>size[ry]){
par[ry]=rx;
size[rx] += size[ry];
}else{
par[rx] = ry;
size[ry] += size[rx];
}
return;
}
bool same(ll x, ll y){ //2つのデータx,yが属する木が同じならtrue
ll rx = root(x);
ll ry = root(y);
return rx == ry;
}
ll treesize(ll x){return size[root(x)];}
};
int main() {
ll n,m,t=0,x=0,y=INF,q,k,ans=0;
cin>>n;
vll a(n);
vll b(n);
rep(i,n){
cin>>a[i];
chmax(x,a[i]);
}
rep(i,n){
cin>>b[i];
chmin(y,b[i]);
}
ans=y-x+1;
if(ans<0) ans=0;
cout<<ans<<endl;
} |
#include<bits/stdc++.h>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define repk(i,a,n) for(int i=a;i<=(n);i++)
#define pb push_back
#define ppb pop_back
#define all(k) k.begin(),k.end()
#define eb emplace_back
#define mp make_pair
#define ll long long
#define pl pair<ll,ll>
#define vc vector<char>
#define vl vector<ll>
#define vvl vector<vl>
#define vi vector<int>
#define vvi vector<vi>
#define vc vector<char>
#define vpi vector<pi>
#define vpl vector<pl>
#define vvc vector<vc>
#define mi map<int,int>
#define ml map<ll,ll>
template<typename T, typename U> inline bool mn(T& m, U x) { if (m > x) { m = x; return true; } return false; }
#define umap unordered_map<int,int>
using namespace std;
void sol() {
int n; cin >> n;
vl ar(n);
rep(i, 0, n)cin >> ar[i];
ll cnt = -1, res = *min_element(all(ar));
while (cnt != res) {
cnt = res;
rep(i, 0, n) {
if (!(ar[i] % res))mn(res, res);
else
mn(res, ar[i] % res);
}
}
cout << res;
}
int main() {
int t = 1; //cin >> t;
while (t--)sol();
return 0;
} | #include <iostream>
#include <vector>
#include <algorithm>
int main() {
int N;
long T, T1 = 0, T2 = 0;
std::string S, S1, S2;
std::cin >> N;
while(N--) {
std::cin >> S >> T;
if(T > T1) {
T2 = T1;
S2 = S1;
T1 = T;
S1 = S;
} else {
if(T > T2) {
T2 = T;
S2 = S;
}
}
}
std::cout << S2 << std::endl;
} |
#include<iostream>
using namespace std;
bool check(int n, int a) {
while (n > 0) {
if (n % a == 7)
return false;
n /= a;
}
return true;
}
int main() {
int n, res;
res = 0;
cin >> n;
for (int i = 1; i <= n; i++) {
if (check(i, 8) && check(i, 10))
res++;
}
cout << res << "\n";
return 0;
} | #include<bits/stdc++.h>
using namespace std;
int main()
{
string a;
cin >> a;
for(int i =0;i<a.length();i++)
{
if(a[i] == '.')
break;
cout<< a[i];
}
} |
#include <bits/stdc++.h>
using namespace std;
// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e9+10;
const ll MOD = 1e9+7;
const ll LINF = 1e18;
char G[105][105];
signed main()
{
cin.tie( 0 ); ios::sync_with_stdio( false );
ll h,w; cin>>h>>w;
rep(i,h) rep(j,w) cin>>G[i][j];
ll ans=0;
rep(i,h){
rep(j,w){
if(G[i][j]=='.' && G[i][j+1]=='.') ans++;
if(G[i][j]=='.' && G[i+1][j]=='.') ans++;
}
}
cout<<ans<<endl;
} | // *********************************************************************************
// * MURTAZA MUSTAFA KHUMUSI *
// * NIT-DGP,CSE - 2019-2023 *
// *********************************************************************************
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007;
#define loop(i, a, n) for (int i = a; i < n; i++)
#define loop1(i, b, n) for (int i = b; i <= n; i++)
#define loopit(a) for (auto it = a.begin(); it != a.end(); it++)
#define ms(a, b) memset(a, b, sizeof(a))
#define pb(a) push_back(a)
#define MP make_pair
#define pi pair<int, int>
#define ff first
#define ss second
#define bloop(i, a, b) for (int i = a; i > b; i--)
#define bloop1(i, a, b) for (int i = a; i >= b; i--)
#define PQ priority_queue<int> pq;
#define vi vector<int>
#define si set<int>
#define MPQ priority_queue<pi, vector<int>, greater<pi>> mpq;
#define io \
ios_base::sync_with_stdio(0); \
cin.tie(NULL);
const int maxm = 100001;
ll m = pow(1e9, 2);
vector<vi> adj;
vi h;
vi sz;
vi in;
//NOT FOR NEGATIVE NUMBERS
// void sc(int &number)
// {
// register long long c;
// number = 0;
// c = getchar();
// for (; (c>47 && c<58); c=getchar())
// number = number *10 + c - 48;
// }
// void dis(vi &a)
// {
// cout << "\n....Display starts...\n";
// loop(i, 0, a.size())
// {
// cout << a[i] << " ";
// }
// cout << "\n....Display ends...\n";
// }
ll fe(ll base, ll exp)
{
ll res = 1;
while (exp > 0)
{
if (exp % 2 == 1)
res = (res * base) % MOD;
base = (base * base) % MOD;
exp /= 2;
}
return res % MOD;
}
void dfs_h_sz(int cur, int par)
{
h[cur] = h[par] + 1;
sz[cur]++;
for (const auto &v : adj[cur])
{
if (v == par)
continue;
dfs_h_sz(v, cur);
sz[cur] += sz[v];
}
}
void buildGraph(int n, int m)
{
adj = vector<vi>(n + 1);
h = vector<int>(n + 1);
sz = vector<int>(n + 1);
in = vector<int>(n + 1);
loop(i, 0, m)
{
int a, b;
cin >> a >> b;
adj[a].pb(b);
adj[b].pb(a);
}
dfs_h_sz(1, 0);
}
struct cmp
{
bool operator()(const pi &a, const pi &b)
{
return a.ff < b.ff;
}
};
ll add(ll a, ll b)
{
return ((a % m) + (b % m)) % m;
}
ll mul(ll a, ll b)
{
return ((a % m) * (b % m)) % m;
}
ll sub(ll a, ll b)
{
return ((a % m) - (b % m) + m) % m;
}
ll ipt(ll cur){
ll k = cur;
ll ret = 0;
while (cur != 1)
{
if (cur % 3 == 0)
{
cur /= 3;
ret++;
}else
{
return -1;
}
}
return (ret ? ret :-1);
}
void solve()
{
ll n;
cin >> n;
ll ini = 5;
int v1 = 1;
while (ini < n)
{
ll cur = n - ini;
ll ret = ipt(cur);
if (ret!=-1)
{
cout<<ret<<" "<<v1<<"\n";
return;
}
ini *= 5;
v1++;
}
cout << -1 << "\n";
}
int main()
{
io;
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int test;
// cin >> test;
test = 1;
while (test--)
{
solve();
}
return 0;
}
|
#include <bits/stdc++.h> // This will work only for g++ compiler.
#define for0(i, n) for (int i = 0; i < (int)(n); ++i) // 0 based indexing
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i) // 1 based indexing
#define forc(i, l, r) for (int i = (int)(l); i <= (int)(r); ++i) // closed interver from l to r r inclusive
#define forr0(i, n) for (int i = (int)(n) - 1; i >= 0; --i) // reverse 0 based.
#define forr1(i, n) for (int i = (int)(n); i >= 1; --i) // reverse 1 based
//short hand for usual tokens
#define pb push_back
#define fi first
#define se second
// to be used with algorithms that processes a container Eg: find(all(c),42)
#define all(x) (x).begin(), (x).end() //Forward traversal
#define rall(x) (x).rbegin, (x).rend() //reverse traversal
// traversal function to avoid long template definition. Now with C++11 auto alleviates the pain.
#define tr(c,i) for(__typeof__((c)).begin() i = (c).begin(); i != (c).end(); i++)
// find if a given value is present in a container. Container version. Runs in log(n) for set and map
#define present(c,x) ((c).find(x) != (c).end())
//find version works for all containers. This is present in std namespace.
#define cpresent(c,x) (find(all(c),x) != (c).end())
// Avoiding wrap around of size()-1 where size is a unsigned int.
#define sz(a) int((a).size())
using namespace std;
// Shorthand for commonly used types
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef double ld;
void solve()
{
ll arr[3];
for(ll i=0;i<3;i++)
{
cin >> arr[i];
}
sort(arr,arr+3);
cout<<arr[1]+arr[2];
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.precision(10);
cout << fixed;
// ll t;
// cin>>t;
// while(t--)
solve();
return 0;
} | #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
typedef long long ll;
inline int read()
{
int a=0,f=1;
char ch=getchar();
for(;!isdigit(ch);ch=getchar())
if(ch=='-')f=-1;
for(;isdigit(ch);ch=getchar())
a=(a<<3)+(a<<1)+ch-'0';
return a*f;
}
const int mod=1e9+7;
const int N=1e6+5;
const int inf=0x3f3f3f3f;
const int INF=2147483647;
const double PI=acos(-1);
int a,b,c,ans;
signed main()
{
a=read();b=read();c=read();
ans=a+c;
ans=max(ans,a+b);
ans=max(ans,b+c);
printf("%d\n",ans);
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define float double
#define pb push_back
#define lp(i,j,n) for( i=j;i<n;i++)
#define lop(j,k,n)for( j=k;j<n;j++)
#define m_p make_pair
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define minheap priority_queue<int,vector<int>,greater<int>>
#define maxheap priority_queue<int>
#define kickstart cout<<"Case #"<<cc<<": "
#define pair_pq priority_queue<pii,vector<pii>>
#define ff first
#define ss second
#define pff pair<float,float>
#define piii pair<int,pii>
#define all(x)x.begin(),x.end()
const int MAX = 5e2+5 ,N = 2e3 + 5;
const int MOD=1e9 + 7 ,mod=1e9 + 7;
const string digits = "0123456789";
map<string , int>mp;
void solve(){
int i=0 , j = 0, n , m , x = 0 , y = 0 ,r,k,f ,p;
cin >> n ;
int a = 0 , b = 0 ,tt=0;
vector<pii>v;
lp(i , 0 ,n){
cin >> x >> y ;
v.pb({2*x + y , i});
a+=x;
}
sort(all(v));
reverse(all(v));
int ans = 0 ;
for(int i = 0 ; i < n ;i++){
b+=(v[i].ff);
++ans;
int rem = tt - b ;
if(b > a)break;
}
cout << ans <<endl;
}
signed main()
{
fastio
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int T = 1 ;
//cin >> T;
while( T-- )
solve();
return 0;
}
| #include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<algorithm>
#include<ctime>
#include<vector>
using namespace std;
int read()
{
int kkk=0,x=1;
char c=getchar();
while((c<'0' || c>'9') && c!='-') c=getchar();
if(c=='-') c=getchar(),x=-1;
while(c>='0' && c<='9') kkk=kkk*10+(c-'0'),c=getchar();
return kkk*x;
}
int n;
vector<int> a1,a2,a3,a4;
int main()
{
n=read();
for(int i=1;i<=10000;++i)
{
if(i%2==0 && i%3==0 && i%5) a1.push_back(i);
if(i%2==0 && i%3 && i%5==0) a2.push_back(i);
if(i%2 && i%3==0 && i%5==0) a3.push_back(i);
if(i%2==0 && i%3==0 && i%5==0) a4.push_back(i);
}
//cout<<a1.size()+a2.size()+a3.size()+a4.size()<<endl;
printf("%d %d %d",a1[0],a2[0],a3[0]);
int N=3;
for(int i=1;i<a1.size();++i) if(N<n) printf(" %d",a1[i]),++N;
for(int i=1;i<a2.size();++i) if(N<n) printf(" %d",a2[i]),++N;
for(int i=1;i<a3.size();++i) if(N<n) printf(" %d",a3[i]),++N;
for(int i=0;i<a4.size();++i) if(N<n) printf(" %d",a4[i]),++N;
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
template<typename T>
ostream& operator<<(ostream &os, vector<T> &v){
string sep = " ";
if(v.size()) os << v[0];
for(int i=1; i<v.size(); i++) os << sep << v[i];
return os;
}
template<typename T>
istream& operator>>(istream &is, vector<T> &v){
for(int i=0; i<v.size(); i++) is >> v[i];
return is;
}
#ifdef DBG
void debug_(){ cout << endl; }
template<typename T, typename... Args>
void debug_(T&& x, Args&&... xs){
cout << x << " "; debug_(forward<Args>(xs)...);
}
#define dbg(...) debug_(__VA_ARGS__)
#else
#define dbg(...)
#endif
int main() {
ios_base::sync_with_stdio(false);
cout << setprecision(20) << fixed;
vector<int> a(3);
cin >> a;
sort(a.begin(), a.end());
cout << (a[2]-a[1]==a[1]-a[0]?"Yes":"No") << 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 = 1 ; 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;
map<string,int>mp;
string s;
set<string>ss;
cin >> n;
for(int i = 0 ; i < n ; i++){
cin >> s;
if(s[0]=='!'){
mp[s] = 1;
}
else{
ss.insert(s);
}
}
string ans = "*";
for(auto p : ss){
if(mp["!"+p] == 1){
ans = p;
break;
}
}
if(ans == "*"){
cout << "satisfiable";
return;
}
cout << ans;
}
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<bits/stdc++.h>
using namespace std;
double dp[101][101][101];
double solve( int a, int b, int c)
{
//if(a == 0 || b == 0 || c == 0)return 0;
if(dp[a][b][c])return dp[a][b][c];
if(a==100 || b == 100 || c == 100)return 0;
double sum=a+b+c;
return dp[a][b][c] = 1 + solve(a+1,b,c)*a/sum + solve(a,b+1,c)*b/sum + solve(a,b,c+1)*c/sum;
}
int main()
{
double a,b,c;
cin>>a>>b>>c;
cout<<setprecision(10);
cout<<solve(a,b,c)<<endl;
return 0;
} | #include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define drep(i,j,n) for(int i=0;i<(int)(n-1);i++)for(int j=i+1;j<(int)(n);j++)
#define trep(i,j,k,n) for(int i=0;i<(int)(n-2);i++)for(int j=i+1;j<(int)(n-1);j++)for(int k=j+1;k<(int)(n);k++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yes(ans) if(ans)printf("yes\n");else printf("no\n")
#define Yes(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YES(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector1d(type,name,...) vector<type>name(__VA_ARGS__)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define vector3d(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
const int MOD2=998244353;
const int INF=1<<30;
const ll INF2=(ll)1<<60;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T,class L>void scan(pair<T, L>& p){scan(p.first);scan(p.second);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T,class L>void print(const pair<T, L>& p){print(p.first);putchar(' ');print(p.second);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll updivide(ll a,ll b){if(a%b==0) return a/b;else return (a/b)+1;}
template<class T> void chmax(T &a,const T b){if(b>a)a=b;}
template<class T> void chmin(T &a,const T b){if(b<a)a=b;}
vector3d(double,dp,101,101,101,-1);
double sai(int a,int b,int c){
if(a==100||b==100||c==100){
return dp[a][b][c]=0;
}else if(dp[a][b][c]!=-1){
return dp[a][b][c];
}else{
double N=a+b+c;
dp[a][b][c]=(a*sai(a+1,b,c)+b*sai(a,b+1,c)+c*sai(a,b,c+1))/N+1;
return dp[a][b][c];
}
}
int main(){
INT(a,b,c);
out(sai(a,b,c));
} |
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pop_b pop_back
#define pf push_front
#define pop_f pop_front
#define mt make_tuple
#define eb emplace_back
#define sf(x) sizeof(x)
#define len(x) x.length()
#define sz(x) x.size()
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define LB(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define UB(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
typedef long long ll;
typedef pair<ll,ll> ii;
typedef long double ld;
typedef vector<int> vi;
typedef vector<set<ll>> vset;
typedef vector<ll> vl;
typedef vector<ld> vd;
typedef deque<ll> dql;
typedef deque<int> dqi;
typedef unsigned long long ull;
typedef tuple<int,int,int> State;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << ", ";
err(++it, args...);
cout<<"\n";
}
#define vmax(type) std::numeric_limits<type>::max()
#define vmin(type) std::numeric_limits<type>::min()
#define each(a,x) for( auto &a:(x))
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rep2(i, l, r) for (ll i = (l); i < (r); i++)
#define rep2r(i, l, r) for (ll i = (r) - 1; i >= (l); i--)
#define range(a) a.begin(), a.end()
#define deb(x) cout<<#x<<" "<<x<<endl;
#define cinai(a, n) vi a(n); rep(i, n) { cin>>a[i]; }
#define cinal(a, n) vl a(n); rep(i, n) { cin>>a[i]; }
#define coutai(a, n) rep(i, n) { cout<<a[i]<<" "; } ent;
#define coutal(a, n) rep(i, n) { cout<<a[i]<<" "; } ent;
#define ent cout<<endl;
#define resize_vec(a) a.resize(unique(a.begin(), a.end()) - a.begin());
#define ms(dp, x) memset(dp, x, sf(dp))
#define endl '\n'
ll powm(ll a, ll b, ll mod) {
ll res=1;
while(b) {
if(b&1)
res=(res*a)%mod;
a=(a*a)%mod;
b>>=1;
}
return res;
}
const ll mod = 998244353;
const ll N = 1000005;
const ll inf = 1e9;
void solve()
{
ll a, b, c;
cin>>a>>b>>c;
ll ans = ((a * (a + 1) / 2) % mod) * ((b * (b + 1) / 2) % mod) % mod * ((c * (c + 1) / 2) % mod) % mod;
cout<<ans<<endl;
}
// #define _DEBUG
// #define testCases
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cout << fixed << setprecision(15);
int tc = 1;
#ifdef testCases
cin>>tc;
#endif
for(int t = 1; t <= tc; t++)
{
#ifdef _DEBUG
int tt = clock();
#endif
// cout<<"Case #"<<t<<": ";
solve();
#ifdef _DEBUG
cerr << "TIME = " << clock() - tt << endl;
tt = clock();
#endif
}
return 0;
}
|
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=
998244353, INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
int main() {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
ll a, b, c;
cin >> a >> b >> c;
a = a*(a+1) / 2;
b = b*(b+1) / 2;
c = c*(c+1) / 2;
a %= mod;
b %= mod;
c %= mod;
a *= b;
a %= mod;
a *= c;
cout << a % mod << endl;
return 0;
}
|
#include "bits/stdc++.h"
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define endl '\n'
#define all(V) (V).begin(), (V).end()
using namespace std;
typedef long long ll;
const ll mod = 998244353;
int main() {fio;
int n, m;
cin >> n >> m;
vector <string> a(n);
vector <set <char> > oh(n + m);
for(int i = 0; i < n; i++) {
cin >> a[i];
for(int j = 0; j < a[i].size(); j++) {
if(a[i][j] != '.') {
oh[i + j].insert(a[i][j]);
}
}
}
ll ans = 1;
for(int i = 0; i <= n + m - 2; i++) {
if(oh[i].size() == 2) {
cout << 0;
return 0;
}
if(oh[i].size() == 1) {
continue;
}
ans = (ans * 2) % mod;
}
cout << ans << endl;
return 0;
} | //region TEMPLATE
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
#define fastio ios_base::sync_with_stdio(0);cin.tie(NULL);
#define endl "\n"
#define pb push_back
#define all(X) begin((X)), end((X))
#define sz(X) (int)(X).size()
#define fi first
#define se second
#define fv(X) for(auto&_:(X))cin>>_
#define fv2(X) for(auto&__:(X))fv(__)
#define lboundi(X, n) (lower_bound(all(X), n) - begin(X))
#define uboundi(X, n) (upper_bound(all(X), n) - begin(X))
#define maxi(X) max_element(all(X)) - begin(X)
#define maxe(X) *max_element(all(X))
#define mini(X) min_element(all(X)) - begin(X)
#define mine(X) *min_element(all(X))
#define acc(X) accumulate(all(X), 0LL)
#ifdef LOCAL
template<size_t S>
string to_string(const bitset<S> &x) { return x.to_string(); }
string to_string(const string &x) { return '"' + x + '"'; }
string to_string(char x) { return string{'\'', x, '\''}; }
string to_string(bool x) { return x ? "true" : "false"; }
template<typename Head, typename Tail>
string to_string(const pair<Head, Tail> &x) { return "(" + to_string(x.first) + ", " + to_string(x.second) + ")"; }
template<class T>
string to_string(T x) {
string ret = "[";
for (const auto &i: x)
ret += to_string(i) + ", ";
if (sz(ret) > 1)
ret = ret.substr(0, sz(ret) - 2);
return ret += "]";
}
string to_string(const char *x) { return string(x); }
string to_string() { return ""; }
template<typename Head, typename... Tail>
string to_string(Head H, Tail... T) { return to_string(H) + ", " + to_string(T...); }
#define debug(...) sizeof( (char[]){#__VA_ARGS__} ) == 1 ? cerr << endl \
: cerr << "[" << #__VA_ARGS__ << "]: " << to_string(__VA_ARGS__) << endl
#define nr() cerr << endl
#else
#define debug(...) 1
#endif
// endregion
const ll mod = 998244353;
void solve() {
int Y, X;
cin >> Y >> X;
vs board(Y);
fv(board);
ll ret = 0;
// 무조건 Y + X - 1 칸을 밟아야 함
// Y + X - 1 개의 대각선 색을 조절
// 그중 하나라도 조절 못하는 것이 있다면 정답은 0
// 0 -> 둘다 가능, 1 -> 하나만 가능
vi color(X + Y - 1);
int sy = 0, sx = 0;
for (int i = 0; i < X + Y - 1; i++) {
bool r = false, b = false;
int y = sy, x = sx;
while (y >= 0 && x < X) {
if (board[y][x] == 'R') {
r = true;
}
if (board[y][x] == 'B')
b = true;
if (r && b) {
cout << 0;
return;
}
y--;
x++;
}
if (!r && !b) {
color[i] = 0;
} else {
color[i] = 1;
}
if (sy < Y - 1)
sy++;
else
sx++;
}
int controllable = count(all(color), 0);
ret = 1;
while (controllable--) {
ret *= 2;
ret %= mod;
}
cout << ret;
}
// .A.
// B..
// ...
int main() {
fastio
solve();
return 0;
} |
#include <cstdio>
#include <cstring>
#include <algorithm>
#define N 100010
using namespace std;
int n;
typedef long long ll;
struct node{
ll a, c;
}f[2*N];
ll sl[3];
ll dis[2*N][3];
ll ma[3];
ll jl;
ll mi[3], ans;
bool cmp(node x, node y){
return x.a<y.a;
}
int main(){
// freopen("funny.in", "r", stdin);
scanf("%d", &n);
for (int i=1; i<=2*n; i++){
char ch;
scanf("%lld", &f[i].a);
while ((ch=getchar())!='R' && ch!='B' && ch!='G');
if (ch=='R') sl[0]++, f[i].c=0;
else if (ch=='B') sl[1]++, f[i].c=1;
else if (ch=='G') sl[2]++, f[i].c=2;
}
if (sl[0]%2==0 && sl[1]%2==0 && sl[2]%2==0){
printf("0");
return 0;
}
if (sl[0]%2==0) jl=0;
else if (sl[1]%2==0) jl=1;
else jl=2;
sort(f+1, f+2*n+1, cmp);
ma[0]=(ll)-2e15;
ma[1]=(ll)-2e15;
ma[2]=(ll)-2e15;
for (int i=1; i<=2*n; i++){
if (f[i].c==jl) f[i].c=0;
else if (f[i].c==0) f[i].c=jl;
ma[f[i].c]=f[i].a;
for (int j=0; j<=2; j++) dis[i][j]=f[i].a-ma[j];
}
ma[0]=(ll)2e15;
ma[1]=(ll)2e15;
ma[2]=(ll)2e15;
ans=(ll)2e15;
for (int i=2*n; i; i--){
ma[f[i].c]=f[i].a;
for (int j=0; j<=2; j++) dis[i][j]=min(dis[i][j], ma[j]-f[i].a);
if (f[i].c) ans=min(ans, dis[i][3^f[i].c]);
}
mi[1]=(ll)2e15;
mi[2]=(ll)2e15;
for (int i=1; i<=2*n; i++){
if (f[i].c==0){
ans=min(dis[i][1]+mi[2], ans);
ans=min(dis[i][2]+mi[1], ans);
mi[1]=min(dis[i][1], mi[1]);
mi[2]=min(dis[i][2], mi[2]);
}
}
printf("%lld", ans);
return 0;
} | #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)
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; }
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>
#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 ins insert
#define debug(a) cerr<<(a)<<endl
#define dbrep(a,n) rep(_i,n) cerr<<(a[_i])<<" "; cerr<<endl
#define dbrep2(a,n,m) rep(_i,n){rep(_j,m) cerr<<(a[_i][_j])<<" "; cerr<<endl;}
using namespace std;
template<class A, class B>
ostream &operator<<(ostream &os, const pair<A,B> &p){return os<<"("<<p.fi<<","<<p.se<<")";}
template<class A, class B>
istream &operator>>(istream &is, pair<A,B> &p){return is>>p.fi>>p.se;}
bool alla(const string &S)
{
for(auto e:S){
if (e!='a') return false;
}
return true;
}
bool cmp(const string &S, const string &T)
{
int N = min(S.size(),T.size());
rep(i,N){
if (S[i]>T[i]) return true;
else if(S[i]<T[i]) return false;
}
return S.size()>T.size();
}
//-------------------------------------------------
const string str = "atcoder";
int main(void)
{
cin.tie(0);
ios::sync_with_stdio(false);
int t; cin>>t;
while(t--){
string S; cin>>S;
int N = S.size();
if (alla(S)){
cout<<"-1\n";
continue;
}
if (cmp(S,str)){
cout<<"0\n";
continue;
}
int ans=(int)1e9;
rep(i,2){
int j=i;
while(j<N && S[j]<=str[i]) j++;
if (j<N) chmin(ans,j-i);
}
cout<<ans<<endl;
}
return 0;
}
|
// editorial
#include<iostream>
#include<vector>
#include<numeric>
using namespace std;
typedef long long ll;
const ll mod = 998244353;
ll modpow(ll a, ll b, ll p = 1e9+7){
if(b == 0) return 1;
if(b % 2 == 0){
ll d = modpow(a, b/2, p);
return (d*d) % p;
}else{
return (a%p * modpow(a, b-1, p)) % p;
}
}
int main(){
int n, k;
cin >> n >> k;
vector<ll> v(n);
for(int i = 0; i < n; i++) cin >> v[i];
vector<ll> fact(k+1, 1);
for(int i = 1; i <= k; i++) fact[i] = fact[i-1]*i%mod;
vector<ll> invf(k+1, 1);
for(int i = 1; i <= k; i++) invf[i] = modpow(fact[i], mod-2, mod);
vector<ll> sum(k+1, 0);
sum[0] = n;
vector<ll> powers(n, 1);
for(int i = 1; i <= k; i++){
for(int j = 0; j < n; j++){
powers[j] = powers[j]*v[j]%mod;
(sum[i] += powers[j]*invf[i]%mod) %= mod;
}
}
const ll invtwo = modpow(2, mod-2, mod);
vector<ll> fpowers(n, 1);
for(int i = 1; i <= k; i++){
ll tmp = 0, sub = 0;
for(int j = 0; j <= i; j++){
(tmp += sum[j]*sum[i-j]%mod) %= mod;
}
(tmp *= fact[i]) %= mod;
for(int j = 0; j < n; j++){
fpowers[j] = fpowers[j]*2*v[j]%mod;
(sub += fpowers[j]) %= mod;
}
cout << (tmp-sub+mod)*invtwo%mod << endl;
}
return 0;
} | #include <iostream>
using namespace std;
using LL = long long;
const int kM = 1e9 + 7;
const int kB = 16, kMaxN = 2e5 + 1;
string s;
LL f[kMaxN][kB + 1], g[kMaxN][kB + 1];
int c[kB];
int n, k, t, ans;
void check() {
f[1][1] = kB - 1;
for (int i = 1; i < n; i++) {
for (int j = 1; j <= k; j++) {
f[i][j] = (f[i][j] + f[i - 1][j] * j + f[i - 1][j - 1] * (kB - j + 1)) % kM;
}
ans = (ans + f[i][k]) % kM;
}
}
void chick() {
g[1][1] = -1;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= k; j++) {
g[i][j] = (g[i][j] + g[i - 1][j] * j + g[i - 1][j - 1] * (kB - j + 1)) % kM;
}
for (int j = 0; j < s[i - 1]; j++) {
int tmp = t + !c[j];
g[i][tmp] = (g[i][tmp] + 1) % kM;
}
t += !(c[s[i - 1]]++);
}
ans = (ans + g[n][k] + (t == k)) % kM;
}
int main() {
cin >> s >> k;
n = s.length();
for (int i = 0; i < n; i++) {
s[i] -= s[i] <= '9' ? '0' : 'A' - 10;
}
check(), chick();
cout << ans;
return 0;
} |
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int N,M;
cin>>N>>M;
vector<int> A(M),B(M);
rep(i,M) cin>>A[i]>>B[i];
vector<int> C(N);
rep(i,N) cin>>C[i];
rep(i,M){
A[i]--;B[i]--;
}
vector<set<int>> gs(N);
rep(i,M){
if(C[A[i]]!=C[B[i]]) continue;
gs[A[i]].insert(B[i]);
gs[B[i]].insert(A[i]);
}
map<pair<int,int>,int> mp;
rep(i,M) mp[mkp(A[i],B[i])]=i;
vector<int> ans(M,-1);
rep(i,M){
if(C[A[i]]<C[B[i]]) ans[i]=0;
if(C[A[i]]>C[B[i]]) ans[i]=1;
}
auto dfs = [&](auto &&dfs,int now) -> void{
while(!gs[now].empty()){
int nex=*(gs[now].begin());
gs[now].erase(nex);
gs[nex].erase(now);
if(mp.count(mkp(now,nex))) ans[mp[mkp(now,nex)]]=1;
else ans[mp[mkp(nex,now)]]=0;
dfs(dfs,nex);
}
};
rep(i,N) dfs(dfs,i);
rep(i,M){
if(ans[i]==1) cout<<"->"<<"\n";
else cout<<"<-"<<"\n";
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
const int M = 102;
int U[M*M],V[M*M];
vector<int> vtr[M];
bool f[M*M],vis[M];
int arr[M],c[M],t=0;
int adj(int u,int e)
{
if(U[e]==u)
return V[e];
return U[e];
}
int dfs(int x,int edge, int p)
{
vis[x]=1;
arr[x] = arr[p] + 1;
int mn=arr[x];
for(auto e: vtr[x])
{
if(e == edge)
continue;
int u = adj(x, e);
if(arr[u] > arr[x])
continue;
if(vis[u])
mn = min(mn, arr[u]);
else
mn = min(mn, dfs(u, e, x));
// x->u
if(U[e] == x)
f[e] = 0;
else
f[e] = 1;
}
return mn;
}
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int n,m;
cin>>n>>m;
for(int i=1;i<=m;i++)
cin>>U[i]>>V[i];
for(int i=1;i<=n;i++)
cin>>c[i];
for(int i=1;i<=m;i++)
{
int u = U[i], v = V[i];
if(c[u] > c[v])
f[i] = 0;
if(c[u] < c[v])
f[i] = 1;
if(c[u] == c[v])
{
vtr[u].pb(i);
vtr[v].pb(i);
}
}
for(int i=1;i<=n;i++)
if(vis[i] == 0)
dfs(i, -1, 0);
for(int i=1;i<=m;i++)
{
if(f[i] == 0)
cout<<"->\n";
else
cout<<"<-\n";
}
return 0;
} |
#include<iostream>
using namespace std;
int main()
{
int A[4];
for(int i=0; i<4; i++)
cin >> A[i];
cout << (A[3]*A[0]) - (A[1]*A[2]) << endl;
return 0;
} | //ATC001B
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // long long64_t, long long*_t
#include <cstdio> // prlong longf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip> //setprecision
#include <limits>
#include <sstream> //istringstream
#include <stdlib.h>
#include <list>
#include <iterator>//std::advance()
using namespace std;
int main(){
double a,b;
cin >> a >> b;
cout << (a-b)*100/a << endl;
}
|
//#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
//#define endl '\n'
llo dp[1001];
llo mod=1e9+7;
llo n;
llo aa[2][2];
llo pre[2001];
llo pre2[2001];
llo ee(llo aa,llo bb){
if(bb==0){
return 1;
}
llo ac=ee(aa,bb/2);
ac=(ac*ac)%mod;
if(bb%2==1){
ac=(ac*aa)%mod;
}
return ac;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n;
for(llo i=0;i<2;i++){
for(llo j=0;j<2;j++){
string s;
cin>>s;
aa[i][j]=s[0]-'A';
}
}
pre[0]=1;
for(llo i=1;i<=2*n;i++){
pre[i]=(pre[i-1]*i)%mod;
}
for(llo i=0;i<=2*n;i++){
pre2[i]=ee(pre[i],mod-2);
}
if(aa[0][1]==1 and aa[1][1]==1){
cout<<1<<endl;
return 0;
}
if(aa[0][1]==0 and aa[0][0]==0){
cout<<1<<endl;
return 0;
}
if(n==2){
cout<<1<<endl;
return 0;
}
if(aa[0][1]==0){
if(aa[1][0]==1){
llo ans=1;
for(llo i=0;i<n-3;i++){
ans=(ans*2)%mod;
}
cout<<ans<<endl;
return 0;
}
else{
llo ans=0;
for(llo i=1;i<=n-1;i++){
llo le=n-i-1;
if(le<=i-1){
llo cot=pre[i-1]*pre2[le];
cot%=mod;
cot=(cot*pre2[i-1-le])%mod;
ans=(ans+cot)%mod;
}
}
cout<<ans<<endl;
}
}
else{
if(aa[1][0]==0){
llo ans=1;
for(llo i=0;i<n-3;i++){
ans=(ans*2)%mod;
}
cout<<ans<<endl;
return 0;
}
else{
llo ans=0;
for(llo i=1;i<=n-1;i++){
llo le=n-i-1;
if(le<=i-1){
llo cot=pre[i-1]*pre2[le];
cot%=mod;
cot=(cot*pre2[i-1-le])%mod;
ans=(ans+cot)%mod;
}
}
cout<<ans<<endl;
}
}
/*dp[2][2]=1;
for(llo i=2;i<=n-1;i++){
for(llo j=1;j<=i;j++){
if(dp[i][j]==0){
break;
}
llo x=j/2;
}
}
llo ans=0;
for(llo i=1;i<=n;i++){
ans=(ans+dp[n][i])%mod;
}
cout<<ans<<endl;*/
/*for(llo i=1;i<n;i++){
for(llo k=0;k<2;k++){
for(llo j=0;j<i;j++){
llo st=0;
if(i==n-1 and k==1){
st=1;
}
if(aa[k][k]==)
}
}
}
cout<<dp[0]
*/
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;
/*
実行時MODint :
template <int& MOD = 1000000007>
static int MOD;
cin >> MOD;
*/
template <int MOD = 1000000007>
struct Mint {
int x;
constexpr Mint() : x(0) {}
constexpr Mint(long long t)
: x(t >= 0 ? (t % MOD) : (MOD - (-t) % MOD) % MOD) {}
Mint pow(int n) {
Mint res(1), t(x);
while (n > 0) {
if (n & 1) res *= t;
t *= t;
n >>= 1;
}
return res;
}
Mint inv() const {
int a = x, b = MOD, u = 1, v = 0, t;
while (b > 0) {
t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
return Mint(u);
}
Mint &operator+=(Mint a) {
x += a.x;
if (x >= MOD) x -= MOD;
return *this;
}
Mint &operator-=(Mint a) {
x += MOD - a.x;
if (x >= MOD) x -= MOD;
return *this;
}
Mint &operator*=(Mint a) {
x = int(1LL * x * a.x % MOD);
return *this;
}
Mint &operator/=(Mint a) {
return (*this) *= a.inv();
}
Mint operator+(Mint a) const {
return Mint(x) += a;
}
Mint operator-(Mint a) const {
return Mint(x) -= a;
}
Mint operator*(Mint a) const {
return Mint(x) *= a;
}
Mint operator/(Mint a) const {
return Mint(x) /= a;
}
Mint operator-() const {
return Mint(-x);
}
bool operator==(const Mint a) {
return x == a.x;
}
bool operator!=(const Mint a) {
return x != a.x;
}
bool operator<(const Mint a) {
return x < a.x;
}
friend ostream &operator<<(ostream &os, const Mint &a) {
return os << a.x;
}
friend istream &operator>>(istream &is, Mint &a) {
int t;
is >> t;
a = Mint<MOD>(t);
return (is);
}
};
signed main() {
int n;
cin >> n;
char caa, cab, cba, cbb;
cin >> caa >> cab >> cba >> cbb;
if (n <= 3) {
cout << 1 << endl;
return 0;
}
if ((cab == 'A' && caa == 'A') || (cab == 'B' && cbb == 'B')) {
cout << 1 << endl;
return 0;
}
if ((cab == 'A' && caa == 'B' && cba == 'A') ||
(cab == 'B' && cbb == 'A' && cba == 'B')) {
Mint<> dp[n][2];
dp[0][0] = 1;
rep(i, n - 1) {
dp[i + 1][0] += dp[i][1];
dp[i + 1][1] += (dp[i][0] + dp[i][1]);
}
cout << dp[n - 1][1] << endl;
return 0;
}
cout << Mint<>(2).pow(n - 3) << endl;
return 0;
} |
#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<int, int>
#define vec vector<int>
#define mat vector<vector<int> >
const ll mod = 1000000007;
const int INF = 1001001001;
int n;
vec c;
mat g;
map<int, int> path;
vec ans;
void dfs(int node, int old){
rep(i, g[node].size()){
int nx = g[node][i];
if(old == nx) continue;
if(path.find(c[nx]) == path.end()) {
path[c[nx]] = 1;
ans.push_back(nx);
}else path[c[nx]]++;
dfs(nx, node);
if(path[c[nx]] == 1) path.erase(c[nx]);
else path[c[nx]]--;
}
}
int main(){
cin >> n;
c = vec(n);
rep(i, n) cin >> c[i];
g = mat(n);
rep(i, n-1) {
int a, b;
cin >> a >> b;
a--; b--;
g[a].push_back(b);
g[b].push_back(a);
}
path[c[0]] = 1;
dfs(0, -1);
sort(ans.begin(), ans.end());
cout << 1 << endl;
rep(i, ans.size()){
cout << ans[i] + 1 << endl;
}
} | #include<bits/stdc++.h>
using namespace std;
#define intt long long int
#define intu unsigned long long int
#define vi vector<int>
#define ii pair<int,int>
#define pb push_back
//#define mp make_pair
#define ff first
#define ss second
#define fast_io ios::sync_with_stdio(0);cin.tie(NULL);std::cout.tie(NULL);
# define PI 3.14159265358979323846
#define all(a) a.begin(),a.end()
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define tc(t) int t; cin >> t; while (t--)
int mod = 1000000007;
int gcd(int a, int b) {return b ? gcd(b, a % b) : a;}
int lcm(int a, int b) {return a * b / gcd(a, b); }
intt bpow(intt a,intt b)
{
intt res = 1;
while (b > 0) {
if (b & 1)res = ((res%mod) * (a%mod))%mod;
a = ((a%mod) * (a%mod))%mod;
b >>= 1;
}
return res;
}
intt fact(intt n) {
if ((n==0)||(n==1))
return 1;
else
return n*fact(n-1);
}
void go()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
freopen("OUt.txt","w",stdout);
#endif
}
bool isValid(int i,int j,int n,int m){
if(i<=0 || j<=0 || i==n+1 || j==m+1)
return 0;
return 1;
}
int dx[4]={0,0,-1,1};
int dy[4]={1,-1,0,0};
char v[1001][1001]={};
int vis[1001][1001]={};
int p[100001]={};
int ans=0,n,m,k;
void dfs(int x,int y,int i){
vis[x][y]=i;
for(int h=0;h<4;h++){
int nx=x+dx[h];
int ny=y+dy[h];
if(isValid(nx,ny,n,m) && v[nx][ny]=='*')
ans++;
else if(isValid(nx,ny,n,m) && v[nx][ny]=='.' && !vis[nx][ny])
dfs(nx,ny,i);
}
}
int main()
{
fast_io
go();
int n,x,sum=0,v,p,i;
cin>>n>>x;
x=x*100;
for(i=0;i<n;i++)
{
cin>>v>>p;
sum=sum+(v*p);
if(sum>x)
{
cout<<i+1<<endl;
break;
}
}
if(i==n)
{
cout<<"-1";
}
return 0;
}
/*!
You are under no obligation to be the same person you were a minute ago,
You have the right to grow !
*/
|
#include <bits/stdc++.h>
using namespace std;
#define repr(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
#define mod 1000000007
ll gcd(ll x,ll y) {return y ? gcd(y,x%y) : x;}
ll lcm(ll x,ll y) {return x/gcd(x,y)*y;}
int main(){
ll n,ans;
cin >> n;
vector<ll> a(n);
rep(i,n) cin >> a[i];
ans=a[0];
rep(i,n){
ans=gcd(ans,a[i]);
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
int N;
cin >> N;
vector<int> A(N);
for (int i = 0; i < N; ++i) cin >> A[i];
sort(A.begin(), A.end());
A.erase(unique(A.begin(), A.end()), A.end());
while (A.size() > 1) {
int v = A[0];
for (int i = 1; i < A.size(); ++i) {
if (A[i] % A[0]) v = min(v, A[i] % A[0]);
else A[i] = A[0];
}
if (v) A.push_back(v);
sort(A.begin(), A.end());
A.erase(unique(A.begin(), A.end()), A.end());
}
cout << A[0] << endl;
}
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mx = 2e5 + 9;
int par[mx];
ll ans;
int find_parent(int x) {
if (x == par[x]) return x;
return par[x] = find_parent(par[x]);
}
void join(int u, int v) {
int p_u = find_parent(u), p_v = find_parent(v);
if (p_u == p_v) return;
ans++;
par[p_u] = p_v;
return;
}
int main() {
ll n; cin >> n;
for (int i = 0; i < mx; i++) {
par[i] = i;
}
ll a[n + 2];
for(ll i = 0; i < n; i++) {
cin >> a[i];
}
for(ll i = 0; i < n; i++) {
ll b = a[i];
ll c = a[n - i - 1];
join(b, c);
}
cout << ans << '\n';
}
| #include <bits/stdc++.h>
#define ll long long
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
#define vl vector<long long>
#define pii pair<int, int>
#define REP(i,a) for (int i = 0; i < (a); i++)
#define add push_back
using namespace std;
template<typename T>
using minpq = priority_queue<T, vector<T>, greater<T>>;
const ll MOD = 1000000007LL;
//const ll MOD = 998244353LL;
int ni() {
int x; cin >> x;
return x;
}
ll nl() {
ll x; cin >> x;
return x;
}
double nd() {
double x; cin >> x;
return x;
}
string next() {
string x; cin >> x;
return x;
}
struct DisjointSetUnion {
vi parent;
vi weight;
int count; //number of components
DisjointSetUnion(int N) {
count = N;
parent.assign(N,0);
REP(i,N) parent[i] = i;
weight.assign(N,1);
}
//"find"
int root(int p) {
if (p==parent[p])
return p;
int r = root(parent[p]);
parent[p] = r;
return r;
}
//"union"
void connect(int p, int q) {
p = root(p);
q = root(q);
if (p==q) return;
if (weight[p]<weight[q]) {
parent[p] = q;
weight[q] += weight[p];
} else {
parent[q] = p;
weight[p] += weight[q];
}
count--;
}
bool connected(int p, int q) {
return root(p)==root(q);
}
};
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
ios::sync_with_stdio(false);
cin.tie(0);
int N = ni();
vi nums(N);
REP(i,N) {
nums[i] = ni()-1;
}
DisjointSetUnion dsu(200000);
for (int i = 0; i < N; i++)
dsu.connect(nums[i],nums[N-1-i]);
cout << 200000-dsu.count;
} |
#include<bits/stdc++.h>
#define ll long long
#define re register
#define INF 2147483647
using namespace std;
inline int read()
{
int f=1,x=0;char s=getchar();
while(s<'0'||s>'9')
{
if(s=='-') f=-1;
s=getchar();
}
while(s>='0'&&s<='9')
{
x=x*10+s-48;
s=getchar();
}
return f*x;
}
int pri[20]={0,2,3,5,7,11,13,17,19,23,29,31,37,41,43,47},tot=15;
int a[60],n;
ll ans=1ll<<62;
ll gcd(ll a,ll b)
{
return !b?a:gcd(b,a%b);
}
void dfs(int x,ll s)
{
if(s>ans) return;
if(x>tot)
{
int flag=1;
for(int i=1;i<=n;i++)
if(gcd(s,a[i])==1)
{
flag=0;
break;
}
if(flag) ans=s;
return;
}
dfs(x+1,s*pri[x]);
dfs(x+1,s);
}
int main()
{
n=read();
for(int i=1;i<=n;i++) a[i]=read();
dfs(1,1);
cout<<ans<<endl;
return 0;
} | #pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define DEBUG
#ifdef DEBUG
inline void debug_print() { cerr << endl; }
template <typename T1, typename... T2> void debug_print(const T1 a, const T2 &... b) { cerr << a << ' '; debug_print(b...); }
#define debug(...) cerr << __LINE__ << ": [" << #__VA_ARGS__ << "] = " , debug_print(__VA_ARGS__);
#else
#define debug(...) true
#endif
inline void print() { cout << '\n'; }
template <typename T1, typename... T2> void print(const T1 a, const T2 &... b) { cout << a << ' '; print(b...); }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; }
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto e : v) os << e << ' '; return os; }
template <typename T> ostream &operator<<(ostream &os, const set<T> &v) { for (auto e : v) os << e << ' '; return os; }
template <typename T> ostream &operator<<(ostream &os, const multiset<T> &v) { for (auto e : v) os << e << ' '; return os; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &mp) { for (auto e : mp) os << e << ' '; return os; }
template <typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } else return false; }
template <typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } else return false; }
//-------------------------- Libraries --------------------------//
vector<long long> sieve(long long N) {
vector<long long> res;
vector<long long> is_prime(N+1, true);
is_prime[0] = is_prime[1] = false;
for (long long i = 2; i <= N; i++) {
if (is_prime[i]) {
res.push_back(i);
for (long long j = 2 * i; j <= N; j+=i) {
is_prime[j] = false;
}
}
}
return res;
}
//---------------------------- Solve ----------------------------//
void solve() {
int N;
cin >> N;
vector<int> X(N);
int ma = 0;
for (int i = 0; i < N; i++) {
cin >> X[i];
chmax(ma, X[i]);
}
auto primes = sieve(ma);
int n = primes.size();
long long ans = 1LL<<60;
for (int bit = 0; bit < 1<<n; bit++) {
long long tmp = 1;
vector<int> v;
for (int i = 0; i < n; i++) {
if (bit & 1<<i) {
tmp *= primes[i];
v.push_back(primes[i]);
}
}
bool flag = true;
for (int i = 0; i < N; i++) {
bool flag2 = false;
for (auto &&prime : v) {
if (X[i] % prime == 0) flag2 = true;
}
if (!flag2) flag = false;
}
if (flag) chmin(ans, tmp);
}
cout << ans << '\n';
}
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(20);
int t = 1;
//cin >> t;
while (t--) solve();
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(ll i=0;i<n;++i)
#define ocut cout
#define ouct cout
#define itn int
struct Union{
vector<ll> par;
Union(ll a){
par=vector<ll>(a,-1);
}
ll find(ll a){
if(par[a]<0){
return a;
}
else{
return par[a]=find(par[a]);
}
}
bool same(ll a,ll b){
return (find(a)==find(b));
}
ll size(ll a){
return -par[find(a)];
}
void unite(ll a,ll b){
ll c=find(a),d=find(b);
if(c==d)
return;
if(size(c)<size(d)){
swap(c,d);
}
par[c]+=par[d];
par[d]=c;
}
};
ll euclidean_gcd(ll a, ll b) {
if(a < b) return euclidean_gcd(b, a);
ll r;
while ((r=a%b)) {
a = b;
b = r;
}
return b;
}
ll euclidean_lcm(ll a, ll b) {
return a/euclidean_gcd(a,b)*b;
}
class smart_sieve {
intmax_t L, R, M;
std::vector<int> small; // 小さい篩
std::vector<std::vector<intmax_t>> large; // 大きい篩
std::vector<intmax_t> aux; // aux[i] := large[i] の素因数の積
public:
smart_sieve(intmax_t L, intmax_t R): L(L), R(R), M(sqrt(R)+1) {
small.resize(M);
std::iota(small.begin(), small.end(), 0);
large.resize(R-L);
aux.assign(R-L, 1);
for (intmax_t i = 2; i*i < R; ++i) {
if (small[i] < i) continue;
small[i] = i;
for (intmax_t j = i*i; j < M; j += i)
if (small[j] == j) small[j] = i;
for (intmax_t j = (L+i-1)/i*i; j < R; j += i) {
intmax_t k = j;
do {
// aux[j-L] > M で判定した方がいいかも?
// j / aux[j-L] < M の方がいい?(割り算したくない)
if (aux[j-L] * aux[j-L] > R) break;
large[j-L].push_back(i);
aux[j-L] *= i;
k /= i;
} while (k % i == 0);
}
}
}
std::vector<intmax_t> factor(intmax_t n) {
assert(L <= n && n < R);
std::vector<intmax_t> res = large[n-L];
n /= aux[n-L];
if (n >= M) {
// この場合,n は素数となることが示せる(はず)
// n*n >= R だとオーバーフローしそう?
res.push_back(n);
return res;
}
while (n > 1) {
res.push_back(small[n]);
n /= small[n];
}
return res;
}
};
int main(void){
ll x,y,z;
cin >> x >> y >> z;
if(y*z%x==0)cout << y*z/x-1;
else cout << y*z/x;
} | #include "bits/stdc++.h"
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
long double a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, m = 0, n = 0, p = 0, q = 0, mod = 1000000007, pi = 3.1415926535;
string s;
char moji;
cin >> a >> b >> c;
d=floor(c*(b/a));
cout << (d/c==b/a?d-1:d);
return 0;
} |
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
using namespace std;
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353
typedef long long ll;
typedef pair<ll,ll> P;
ll my_pow(ll a, ll b) {
ll ret = 1;
ll kake = a;
REP(i, 30) {
if(b & (1 << i))ret = ret * kake % MOD;
kake = kake * kake % MOD;
}
return ret;
}
int main(){
cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
ll N, M, K;cin >> N >> M >> K;
if(N == 1 && M == 1) {
cout << K << endl;
return 0;
}
if(N == 1) {
cout << my_pow(K, M) << endl;
return 0;
}
if(M == 1) {
cout << my_pow(K, N) << endl;
return 0;
}
ll ans = 0;
for (ll i = 1;i <= K;i++) {
ll A = my_pow(K - i + 1, N);
ll B = (MOD + my_pow(i, M) - my_pow(i - 1, M)) % MOD;
ans = (ans + A * B % MOD) % MOD;
}
cout << ans << endl;
return 0;
}
| /**
* author: avoas
* created: 10.05.2021 23:38:11
**/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr double EPS = 1e-12;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
long long r, x, y;
cin >> r >> x >> y;
long long diff2 = x*x + y*y;
double diff = sqrt(diff2);
int ans = 1;
while(ans*r < diff)
{
++ans;
}
if(diff2 == r*r)
{
ans = 1;
}
if(diff2 < r*r)
{
ans = 2;
}
cout << ans << endl;
return 0;
} |
#include<bits/stdc++.h>
using namespace std ;
#define MAXN 200007
#define MOD 998244353
int n , m ;
vector < int > divs[ MAXN ] ;
long long dp[ 21 ][ MAXN ] ;
long long fac[ MAXN ] ;
long long inv[ MAXN ] ;
long long fastpow ( long long x , long long pw ) {
long long ret = 1 ;
while ( pw > 0 ) {
if ( ( pw % 2 ) == 0 ) {
x = ( x * x ) % MOD ;
pw /= 2 ;
}
else {
ret = ( ret * x ) % MOD ;
-- pw ;
}
}
return ret ;
}
void input ( ) {
scanf ( "%d%d" , &n , &m ) ;
fac[ 0 ] = 1 ;
for ( int i = 1 ; i <= n ; ++ i ) {
fac[ i ] = ( fac[ i - 1 ] * i ) % MOD ;
}
inv[ n ] = fastpow ( fac[ n ] , MOD - 2 ) ;
for ( int i = n - 1 ; i >= 0 ; -- i ) {
inv[ i ] = ( inv[ i + 1 ] * ( i + 1 ) ) % MOD ;
}
for ( int i = 2 ; i <= m ; ++ i ) {
for ( int j = 2 * i ; j <= m ; j += i ) {
divs[ j ].push_back ( i ) ;
}
}
}
void solve ( ) {
for ( int i = 2 ; i <= m ; ++ i ) {
dp[ 1 ][ i ] = 1 ;
}
for ( int i = 1 ; i <= 20 ; ++ i ) {
for ( int j = 2 ; j <= m ; ++ j ) {
for ( auto x : divs[ j ] ) {
dp[ i ][ j ] += dp[ i - 1 ][ x ] ;
if ( dp[ i ][ j ] >= MOD ) { dp[ i ][ j ] -= MOD ; }
}
}
}
long long ans = 1 ;
for ( int i = 1 ; i <= 20 ; ++ i ) {
long long aux = 0 ;
for ( int j = 2 ; j <= m ; ++ j ) {
aux += dp[ i ][ j ] ;
if ( aux >= MOD ) { aux -= MOD ; }
}
if ( i > n ) { break ; }
aux = ( aux * fac[ n ] ) % MOD ;
aux = ( aux * inv[ i ] ) % MOD ;
aux = ( aux * inv[ n - i ] ) % MOD ;
ans += aux ;
if ( ans >= MOD ) { ans -= MOD ; }
}
printf ( "%lld\n" , ans ) ;
}
int main ( ) {
ios_base :: sync_with_stdio ( false ) ;
cin.tie ( NULL ) ;
int t ;
t = 1 ;
// cin >> t ;
// scanf ( "%d" , &t ) ;
while ( t -- ) {
input ( ) ;
solve ( ) ;
}
return 0 ;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)//iをaからn
#define per(i,n,a) for (int i=a-1;i>=n;i--)//iをnからa
#define db(x) cout << #x << " = " << x << endl//デバッグ用
#define db2(x, y) cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n"; //デバッグ用
#define all(x) (x).begin(), (x).end()
#define INF32 2147483647 //2.147483647×10^{9}:32bit整数のinf
#define INF64 9223372036854775807 //9.223372036854775807×10^{18}:64bit整数のinf
#define MOD 998244353 //10^9+7:合同式の法
#define pb push_back
#define F first
#define S second
typedef long long ll;
//sort(all(a)); ソート
//sort(all(a),greater<int>()); 逆順ソート
//a.erase(unique(all(a)), a.end()); ソート後に重複を削除
//cout<< std::fixed << std::setprecision(15)<<0.000001<<endl; 小数点以下を表示させる
//vector<vector<int>> data(3, vector<int>(4)); int型の2次元配列(3×4要素の)の宣言
//PNch[i]:=(iを割り切る最大の素数)
//但し,iが素数の時はPNch[i]=1,i=0,1の時はPNch[i]=0
vector<ll> PNch;
//n:=素因数分解したい中で最大の値(2以上)
void ES(ll n){
//素数として初期化
PNch.assign(n+1,1);
PNch[0]=0;PNch[1]=0;
ll l=sqrt(n);
rep(i,2,l){
//ある素数の倍数ならばその素数で割り切れる
if(PNch[i]==1){
rep(j,i,n/i)PNch[j*i]=i;
}
}
}
class PFmap{
public:
//PNs:=(素因数分解出てくる素数を(昇順に)格納したmap)
map<ll,ll> PNs;
PFmap(ll n){PF(n);}
void PF(ll n){
if(n<=1) return;
//nが素数の時
if(PNch[n]==1){PNs[n]++;return;}
//マークされている数は素数
PNs[PNch[n]]++;
//マークされている数でnを割った数
PF(n/PNch[n]);
}
};
const int MAX = 300000;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; 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;
}
int main() {
ll N,M;
cin >> N >>M;
ll ans=1;
if(M==1){
cout<<ans;
return 0;
}
if(N==1){
cout<<M;
return 0;
}
COMinit();
ES(400000);
rep(i,2,M+1){
ll nowans=1;
auto so=PFmap(i);
//db(so.PNs.size());
auto begin = so.PNs.begin(), end = so.PNs.end();
//if(i==200000)db(so.PNs.size());
for (auto iter = begin; iter != end; iter++) {
ll aaa=iter->second;
if(aaa == 1){
nowans*=N;
nowans%=MOD;
}else{
nowans*=COM(N+aaa-1,aaa);
nowans%=MOD;
}
}
//db(nowans);
ans+=nowans;
ans%=MOD;
}
cout<<ans;
//cout<<ans<<endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using ll = long long;
using Graph = vector<vector<int>>;
const long long INF = 1LL << 60;
const int SINF = 1LL << 29;
const ll mod = 1000000000+7;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int main() {
int n;
cin >> n;
vector<ll> a(n);
rep(i, n) cin >> a[i];
ll max_place = 0, max_start = 0;
ll place = 0, start = 0;
ll ans = 0;
rep(i, n) {
place += a[i];
chmax(max_place, place);
chmax(ans, max_place + start);
start += place;
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
long long int N;
cin >> N;
vector<long long int> A(N), cumsum(N, 0);
for(int i = 0; i < N; ++i) cin >> A.at(i);
if(N == 1) {
if(A.at(0) > 0) cout << A.at(0) << endl;
else cout << 0 << endl;
return 0;
}
cumsum.at(0) = A.at(0);
for(int i = 1; i < N; ++i) {
cumsum.at(i) = cumsum.at(i-1) + A.at(i);
}
// どのloop回数で最大化を探す
long long int sum = A.at(0), candi = 0, candsum = A.at(0);
vector<long long int> offset(N);
offset.at(0) = A.at(0);
// if(sum > 0) candi = 0;
for(int i = 1; i < N; ++i) {
candsum += cumsum.at(i);
offset.at(i) = candsum;
if(candsum > sum) {
sum = candsum; // update
candi = i;
}
// cout << offset.at(i) << endl;
}
long long int ans = offset.at(candi);
// candsum = sum;
for(int i = candi; i >= 0; --i) {
sum -= A.at(i);
ans = max(sum, ans);
}
sum = offset.at(candi);
if(candi < N-1) {
for(int i = 0; i <= candi+1; ++i) {
sum += A.at(i);
ans = max(sum, ans);
}
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
const ll mod=1e9+7;
int main(void){
ll n;cin>>n;
vector<vector<ll>> dp(n+100,vector<ll>(n+100,0)); //i番目までのAをj番目のBに切り分ける組み合わせ
vector<ll> a(n),c(n+1); //cはaの累積和
rep(i,n){
cin>>a[i];
c[i+1]=c[i]+a[i];
}
ll res=0;
dp[1][0]=1;
rep(i,n){
for(ll j=n;j>=1;j--){
dp[j+1][c[i+1]%(j+1)]=(dp[j+1][c[i+1]%(j+1)]+dp[j][c[i+1]%j])%mod;
if(i==n-1){
res+=dp[j][c[i+1]%j];
res%=mod;
}
}
}
cout<<res<<endl;
}
| #include<bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define ini(x, y) memset(x, y, sizeof(x));
#define pb push_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int MOD = (int)1e9 + 7;
const int MAX = (int)2e9;
const double PI = acos(-1);
int n;
ll a[3030], psum[3030][3030];
ll dp[3030][3030];
vector<int> v[3030][3030];
int main(void) {
ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
psum[i][j] = psum[i][j - 1] + a[j];
psum[i][j] %= i;
}
for (int j = 1; j <= n; j++) {
v[i][psum[i][j]].pb(j);
}
}
for (int i = 1; i <= n; i++) dp[1][i] = 1;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (dp[i][j] == 0) continue;
auto& vec = v[i + 1][psum[i + 1][j]];
for (auto it = upper_bound(all(vec), j); it != vec.end(); ++it) {
dp[i + 1][*it] += dp[i][j];
if (dp[i + 1][*it] >= MOD) dp[i + 1][*it] -= MOD;
}
}
}
ll ans = 0;
for (int i = 1; i <= n; i++) {
ans += dp[i][n];
}
cout << ans % MOD;
} |
#include <bits/stdc++.h>
const long long INF = 1e9;
const long long MOD = 1e9 + 7;
//const long long MOD = 998244353;
const long long LINF = 1e18;
using namespace std;
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE" ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible" ) << endl
#define dump(x) cout << #x << " = " << (x) << endl
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define COUT(x) cout<<(x)<<endl
#define SCOUT(x) cout<<(x)<<" "
#define VECCOUT(x) for(auto&youso_: (x) )cout<<right<<setw(10)<<youso_<<" ";cout<<endl
#define ENDL cout<<endl
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) long long __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define mp make_pair
#define PQ priority_queue<long long>
#define PQG priority_queue<long long,V,greater<long long>>
typedef long long ll;
typedef vector<long long> vl;
typedef vector<long long> vi;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<vb> vvb;
typedef vector<vc> vvc;
typedef pair<long long, long long> pll;
#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
cin>>head;
CINT(move(tail)...);
}
template<class T>
void mod(T &x) {
x %= MOD;
x += MOD;
x %= MOD;
}
ll GCD(ll a, ll b) {
if(b == 0) return a;
else return GCD(b, a%b);
}
struct COMB{
vl fact, fact_inv, inv;
void init_nCk(long long SIZE) {
fact.resize(SIZE + 5);
fact_inv.resize(SIZE + 5);
inv.resize(SIZE + 5);
fact.at(0) = fact.at(1) = fact_inv.at(0) = fact_inv.at(1) = inv.at(1) = 1;
for(long long i = 2; i < SIZE + 5; i++) {
fact.at(i) = fact.at(i - 1)*i%MOD;
inv.at(i) = MOD - inv.at(MOD%i)*(MOD/i)%MOD;
fact_inv.at(i) = fact_inv.at(i - 1)*inv.at(i)%MOD;
}
}
long long nCk (long long n, long long k) {
assert(!(n < k));
assert(!(n < 0 || k < 0));
return fact.at(n)*(fact_inv.at(k)*fact_inv.at(n - k)%MOD)%MOD;
}
};
ll extGCD(ll a, ll b, ll &x, ll &y) {
if(b == 0) {
x = 1;
y = 0;
return a;
}
ll d = extGCD(b, a%b, y, x);
y -= a/b*x;
return d;
}
string solve(string s) {
string res;
sort(s.begin(),s.end());
string memo = s;
reverse(s.begin(),s.end());
res = to_string(abs(stoi(s) - stoi(memo)));
// cout << res << endl;
return res;
}
void Main() {
LCIN(N, K);
string S = to_string(N);
for(int i = 0; i < K; i++) {
S = solve(S);
}
cout << S << endl;
}
int main() {
cout << fixed << setprecision(15);
Main();
return 0;
} | #pragma comment(linker, "/STACK:1000000000")
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <memory.h>
#include <cassert>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <ctime>
#include <random>
#include <bitset>
#include <limits.h>
#include <fstream>
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define pll pair <ll, ll>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef long double ld;
#define uint unsigned int
#define mp make_pair
const int maxn = 110;
vector <int> ed[maxn];
bool used[maxn];
int dfs(int v) {
if (used[v]) {
return 0;
}
int ans = 1;
used[v] = true;
for (int u : ed[v]) {
ans += dfs(u);
}
return ans;
}
int main() {
int n;
cin >> n;
string s;
for (int i = 0; i < n; i++) {
cin >> s;
for (int j = 0; j < n; j++) {
if (s[j] == '1') {
ed[j].push_back(i);
}
}
}
ld ans = 0;
for (int i = 0; i < n; i++) {
memset(used, 0, sizeof used);
ld num = dfs(i);
ans += 1. / num;
}
printf("%.10lf\n", (double)ans);
} |
#include <bits/stdc++.h>
// clang-format off
using namespace std; using ll = long long; using ull = unsigned long long; using pll = pair<ll,ll>; const ll INF = 4e18;
void print0() {}
template<typename Head,typename... Tail> void print0(Head head,Tail... tail){cout<<fixed<<setprecision(15)<<head;print0(tail...);}
void print() { print0("\n"); }
template<typename Head,typename... Tail>void print(Head head,Tail... tail){print0(head);if(sizeof...(Tail)>0)print0(" ");print(tail...);}
// clang-format on
ll gcdf(ll a, ll b) {
if (b == 0) {
return a;
}
return gcdf(b, a % b);
}
vector<ll> divisor(ll n) {
vector<ll> res;
for (ll i = 1; i * i <= n; i++) {
if (n % i == 0) {
res.push_back(i);
if (i != n / i) {
res.push_back(n / i);
}
}
}
return res;
}
int main() {
ll N;
cin >> N;
vector<ll> a(N);
ll allmin = INF;
for (ll i = 0; i < N; i++) {
cin >> a[i];
allmin = min(a[i], allmin);
}
unordered_map<ll, ll> curgcd;
for (auto ai : a) {
vector<ll> succeeded;
for (auto d : divisor(ai)) {
if (d > allmin) continue;
if (curgcd.count(d)) {
curgcd[d] = gcdf(curgcd[d], ai);
} else {
curgcd[d] = ai;
}
}
}
ll ans = 0;
for (auto x : curgcd) {
ans += (x.first == x.second);
}
print(ans);
}
| #pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define mod 1000000007
#define pi 3.1415926535898
#define eps 1e-9
#define fast ios::sync_with_stdio(0); cin.tie(0);cout.tie(0)
#define vt vector
#define ar array
#define fs first
#define sc second
#define pb push_back
#define sp printf(" ")
#define nl '\n'
#define all(a) a.begin(),a.end()
#define unique(c) (c).resize(unique(all(c)) - (c).begin())
#define sz(x) (int)(x).size()
#define revsort(x) sort(all(x));reverse(all(x))
#define set0(a) memset(a,0,sizeof(a))
#define setneg(a) memset(a,-1,sizeof(a))
#define setinf(a) memset(a,126,sizeof(a))
#define REP(i,start,end) for (int i = start; i <=end; i++)
#define RREP(i,end,start) for (int i=end; i>=start ;i--)
#define EACH(x, a) for (auto& x: a)
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<LL> vll;
typedef vector<double> vd;
typedef vector<vector<LL> > matrix;
typedef vector<vector<int> > graph;
template<class A> void read(vt<A>& v);
template<class A, size_t S> void read(ar<A, S>& a);
template<class T> void read(T& x) {
cin >> x;
}
void read(double& d) {
string t;
read(t);
d=stod(t);
}
void read(long double& d) {
string t;
read(t);
d=stold(t);
}
template<class H, class... T> void read(H& h, T&... t) {
read(h);
read(t...);
}
template<class A> void read(vt<A>& x) {
EACH(a, x)
read(a);
}
template<class A, size_t S> void read(array<A, S>& x) {
EACH(a, x)
read(a);
}
int add (LL var1, LL var2) {
return ( (var1 % mod) + (var2 % mod) + mod) % mod;
}
int mul (LL var1, LL var2) {
return (var1*var2) % mod;
}
int powm (LL x, LL y) {
int ans = 1;
while (y) {
if (y & 1) {
ans = mul(ans, x);
}
x = mul(x, x);
y /= 2;
}
return ans;
}
int inv(LL x) {
return powm(x, mod-2);
}
LL INF=1e9;
void solve() {
LL r, c, m;
read(r,c,m);
vector <set <int> > rows(r);
vector <set <int> > cols(c);
REP (i, 1, m) {
int x, y;
read(x,y);
x--;
y--;
rows[x].insert(y);
cols[y].insert(x);
}
REP(i,0,r-1) rows[i].insert(c);
REP(i,0,c-1) cols[i].insert(r);
LL down = *cols[0].begin();
LL right = *rows[0].begin();
LL ans = 0;
REP (i, 0, down-1)
{
LL mxr = *rows[i].begin();
ans += mxr;
}
ordered_set<int> done;
REP (i, down, r-1) {
done.insert(i);
}
REP (j, 0, right-1) {
ans += done.order_of_key(*cols[j].begin());
for (auto x : cols[j]) {
done.insert(x);
}
}
cout << ans << nl;
}
int main() {
fast;
solve();
}
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define Pint pair<int,int>
#define Pll pair<ll,ll>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000;
constexpr ll llINF=1000000000000000000;
constexpr int mod=1000000007;
constexpr double eps=1e-8;
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int Random(int mi,int ma){
random_device rnd;
mt19937 mt(rnd());//32bit
//[mi,ma]
uniform_int_distribution<int>engine(mi,ma);
return engine(mt);
}
ll gcd(ll a,ll b){
if(b==0)return a;
return gcd(b,a%b);
}
ll lcm(ll a,ll b){
return a/gcd(a,b)*b;
}
bool prime(int a){
if(a==1)return false;
for(int i=2;i*i<=a;i++){
if(a%i==0)return false;
}
return true;
}
ll modpow(ll a,ll b){
if(b==0)return 1;
if(b%2)return modpow(a,b-1)*a%mod;
ll memo=modpow(a,b/2);
return memo*memo%mod;
}
vector<ll>kaijo,invkaijo;
void init_fact(int n){
kaijo.resize(n+1);
invkaijo.resize(n+1);
kaijo[0]=1;
for(ll i=1;i<=n;i++){
kaijo[i]=kaijo[i-1]*i;
kaijo[i]%=mod;
}
rep(i,n+1)invkaijo[i]=modpow(kaijo[i],mod-2);
}
vector<vector<ll>>C,sC;
void init_comb(int n,int m){
C.resize(n+1,vector<ll>(m+1,0));
sC.resize(n+1,vector<ll>(m+1,0));
C[0][0]=1;
for(int i=1;i<=n;i++){
C[i][0]=1;
for(int j=1;j<=m;j++){
C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
}
}
rep(i,n+1){
rep(j,m){
sC[i][j+1]=(sC[i][j]+C[i][j])%mod;
}
}
}
ll comb(int a,int b){
if(a<b)return 0;
if(a<0)return 0;
return kaijo[a]*invkaijo[a-b]%mod*invkaijo[b]%mod;
}
ll inv(ll x){
x=modpow(x,mod-2);
return x;
}
int n,a[2121];
ll m;
int main(){
cin>>n>>m;
ll s=0;
rep(i,n){
cin>>a[i];
s+=a[i];
}
int x=n+m;
int y=s+n;
ll ans=1;
for(int i=x;i>x-y;i--){
ans*=i;
ans%=mod;
}
for(int i=1;i<=y;i++){
ans*=inv(i);
ans%=mod;
}
cout<<ans<<endl;
return 0;
} | //DUEL
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define x first
#define y second
#define pii pair<int,int>
#define pb push_back
#define eb emplace_back
#pragma GCC optimize("unroll-loops")
#define shandom_ruffle(a, b) shuffle(a, b, rng)
#define vi vector<int>
#define vl vector<ll>
#define popcnt __builtin_popcount
#define popcntll __builtin_popcountll
#define all(a) begin(a),end(a)
using namespace std;
using namespace __gnu_pbds;
using ll=long long;
using ull=unsigned long long;
using ld=long double;
const int MOD=1000000007;
vector<int> bases;
const ll LLINF=1ll<<60;
const char en='\n';
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void yes() {cout<<"YES"<<en; exit(0);}
void no() {cout<<"NO"<<en; exit(0);}
inline int rund() {int x576363482791fuweh=rng();return abs(x576363482791fuweh)%RAND_MAX;}
template<class T>
void prVec(vector<T> w,bool fl=false)
{
cout<<w.size()<<en;
for (int i=0;i<int(w.size())-1;++i) cout<<w[i]<<' ';
if (w.size()) cout<<w[w.size()-1]<<en;
if (fl) cout<<flush;
}
ll raand()
{
ll a=rund();
a*=RAND_MAX;
a+=rund();
return a;
}
#define rand raand
ll raaand()
{
return raand()*(MOD-7)+raand();
}
void compress(vi&v)
{
set<int> s;
for (auto a: v) s.insert(a);
vi o(all(s));
for (auto&a: v) a=lower_bound(all(o),a)-o.begin();
}
void compress(vl&v)
{
set<ll> s;
for (auto a: v) s.insert(a);
vl o(all(s));
for (auto&a: v) a=lower_bound(all(o),a)-o.begin();
}
string to_upper(string a)
{
for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A';
return a;
}
string to_lower(string a)
{
for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A';
return a;
}
ll sti(string a,int base=10)
{
ll k=0;
for (int i=0;i<(int)a.size();++i)
{
k*=base;
k+=a[i]-'0';
}
return k;
}
template<class T>
void eras(vector<T>& a,T b)
{
a.erase(find(a.begin(),a.end(),b));
}
string its(ll k,int base=10)
{
if (k==0) return "0";
string a;
while (k)
{
a.push_back((k%base)+'0');
k/=base;
}
reverse(a.begin(),a.end());
return a;
}
ll min(ll a,int b)
{
if (a<b) return a;
return b;
}
ll min(int a,ll b)
{
if (a<b) return a;
return b;
}
ll max(ll a,int b)
{
if (a>b) return a;
return b;
}
ll max(int a,ll b)
{
if (a>b) return a;
return b;
}
ll gcd(ll a,ll b)
{
if (b==0) return a;
return gcd(b,a%b);
}
ll lcm(ll a,ll b)
{
return a/gcd(a,b)*b;
}
template<class T,class K>
pair<T,K> mp(T a,K b)
{
return make_pair(a,b);
}
inline int mult(ll a,ll b)
{
return (a*b)%MOD;
}
inline int pot(int n,int k)
{
if (k==0) return 1;
ll a=pot(n,k/2);
a=mult(a,a);
if (k%2) return mult(a,n);
else return a;
}
int divide(int a,int b)
{
return mult(a,pot(b,MOD-2));
}
inline int sub(int a,int b)
{
if (a-b>=0) return a-b;
return a-b+MOD;
}
inline int add(int a,int b)
{
if (a+b>=MOD) return a+b-MOD;
return a+b;
}
bool prime(ll a)
{
if (a==1) return 0;
for (int i=2;i<=round(sqrt(a));++i)
{
if (a%i==0) return 0;
}
return 1;
}
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
const int N=300010;
int n,m;
ll co(int a,int b)
{
ll re=1;
for (int i=a;i>a-b;--i)
{
re=mult(re,i);
re=divide(re,a+1-i);
}
return re;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
for (int i=0;i<10;++i) bases.push_back(rand()%(MOD-13893829*2)+13893829);
cin>>n>>m;
ll s=0;
for (int i=0;i<n;++i)
{
int a;
cin>>a;
s+=a;
}
cout<<co(m+n,s+n)<<en;
}
|
#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>P;
const ll MOD=1000000007;
//~ const int MOD=998244353;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
int a[200000];
int main(){
int T;cin>>T;
rep(Case,T){
int n;scanf("%d",&n);
map<int,int>mp;
rep(i,n)scanf("%d",&a[i]),mp[a[i]]++;
bool ok=true;
for(auto&p:mp){
if(p.second%2!=0)ok=false;
}
if(n%2==1){
puts("Second");
}
else{
if(ok)puts("Second");
else puts("First");
}
}
} | #include<bits/stdc++.h>
#define lint long long
#define st first
#define nd second
#define INF 0x3f3f3f3f
using namespace std;
int t;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
cin>>t;
while(t--){
int n; cin>>n;
vector<lint> a(n);
map<int,int> cont;
for(auto &x:a) cin>>x, cont[x]++;
lint xo = a[0];
bool Grone = false;
if(a[0] > 1) Grone = true;
for(int i=1; i<n;i++){
xo ^= a[i];
if(a[i] > 1) Grone = true;
}
if(n%2 == 0){
string win = "Second\n";
for(auto &e:cont) if(e.nd%2) win = "First\n";
cout<<win;
} else{
cout<<"Second\n";
}
}
return 0;
}
/*
num par de dishes:
quero forçar xor de todo mundo != 0
nd -> me imita
st -> não me imita
num ímpar de dishes:
quero forçar xor de todo mundo == 0
n == 2
1 1 ->> 2 0
1 2 -> 1 2
1 1 2 2 -> 2 2
carinha mau força
*/ |
#include<bits/stdc++.h>
// Program showing a policy-based data structure.
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less
using namespace std;
using namespace __gnu_pbds;
typedef long long int ll;
// GNU link : https://goo.gl/WVDL6g
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
tree_order_statistics_node_update>
new_data_set;
#define READ freopen("in.txt", "r", stdin);
#define WRITE freopen("out.txt", "w", stdout);
#define optimize ios::sync_with_stdio(0);cin.tie(0);
#define RESET(a, b) memset(a, b, sizeof(a))
#define gcd(a, b) __gcd(a, b)
#define MX 300005
#define MOD 1000000007
#define inf ll(1e18)
#define PI acos(-1.0)
#define eps 1e-9
ll LCM(ll a, ll b)
{
return (a / __gcd(a, b)) * b;
}
int main(void)
{
optimize
ll n,x;
cin>>n;
ll lcm=1;
for(ll j=2;j<=30;j++)
{
lcm=LCM(lcm,j);
}
lcm++;
cout<<lcm<<endl;
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ll n;
cin>>n;
if(n==30)
n--;
ll ans=1;
for(ll i=n;i>=2;i--)
{
if(ans%i!=0){
ans*=i;
}
}
cout<<ans+1;
}
// 23 4 5 |
#pragma GCC optimize("Ofast") //Comment optimisations for interactive problems (use endl)
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define fastio ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
#define randomINIT mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define all(x) (x).begin(),(x).end()
#define mset(x,val) memset(x,val,sizeof(x))
#define endl "\n"
#define pb push_back
#define sym(s) s="#"+s+"#";
#define mp make_pair
#define s second
#define f first
#define dline cerr<<"///REACHED///\n";
#define debv(a) for(auto it: a)cout<<it<<" ";cout<<endl;
#define deb1(a) cout<<a<<endl;
#define deb2(a,b) cout<<a<<" "<<b<<endl;
#define deb3(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl;
#define deb4(a,b,c,d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
#define uniq(a) a.resize(unique(a.begin(), a.end()) - a.begin());
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
const ll MOD = 1e+9+7;
const ll INF = 0x7f7f7f7f7f7f7f7f;
const int INFi = 0x7f7f7f7f;
const ll N = 3e+5+7;
vll adj[N];ll vis[N]={};
int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1};
int dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};
//<<-----Declare Variable Here------->>//
int t=1;
ll n,a[N],q;
//<<-----Implement Functions Here---->>//
//input-array from which segtree(tree) is formed
//here example shown is min range query change as needed
//make 1 indexe input,so use build(1,1,n) etc
ll tree[4*N+8];
ll merge(ll a,ll b){
return a^b;
}
void build(ll node, ll start, ll end){
if(start == end){
tree[node] = a[start];
}
else
{
ll mid = (start + end) / 2;
build(2*node, start, mid);
build(2*node+1, mid+1, end);
tree[node] = merge(tree[2*node],tree[2*node+1]);
}
}
void update(ll node, ll start, ll end, ll pos, ll val){
if(start == end){
tree[node] = tree[node]^val;
}
else
{
ll mid = (start + end) / 2;
if(pos <= mid)
update(2*node, start, mid, pos, val);
else
update(2*node+1, mid+1, end, pos, val);
tree[node] = merge(tree[2*node],tree[2*node+1]);
}
}
ll query(ll node, ll start, ll end, ll l, ll r){
if(start > end or start > r or end < l)
return 0;
if(l <= start and end <= r)
return tree[node];
ll mid = (start + end)/2;
ll p1 = query(2*node, start, mid, l, r);
ll p2 = query(2*node+1, mid+1, end, l, r);
return merge(p1,p2);
}
//<<-----Start of Main--------------->>//
void MAIN(){
cin>>n>>q;
for(ll i=1;i<=n;i++)cin>>a[i];
build(1,1,n);
while(q--){
ll ch,x,y;
cin>>ch>>x>>y;
if(ch==1){
update(1,1,n,x,y);
}
else cout<<query(1,1,n,x,y)<<endl;
}
}
int main(){
fastio;randomINIT;
//cin>>t;
while(t--){
MAIN();
}
#ifndef ONLINE_JUDGE
cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
#endif
} | #include <iostream>
#include <algorithm>
#include <unordered_set>
#include <set>
#include <vector>
#include <queue>
#include <map>
#include <numeric>
#include <math.h>
using namespace std;
#define rep(i, n) for (long long int i = 0; i < (long long int)(n); i++)
#define irep(i, n) for (long long int i = 1; i <= (long long int)(n); i++)
#define drep(i, n, diff) for (long long int i = 0; i < (long long int)(n); i += diff)
#define mod 1000000007
#define cdeb(val) cout << #val << ":" << val << endl;
#define pdeb(val) printf("%s : %lld\n", #val, val);
typedef long long int ll;
typedef pair<ll, ll> P;
struct BIT {
ll n;
vector<ll> b;
BIT(ll idx) : n(idx+1), b(n, 0) {}
void init(vector<ll> a) {
for(ll i = 0; i < a.size(); i++) {
add(i+1, a[i]);
}
}
// sum: b[1] ~ b[i];
ll sum(ll i) {
ll ret = 0;
while(i > 0) {
ret ^= b[i];
i -= i & -i;
}
return ret;
}
// sum: b[x] ~ b[y];
ll range_sum(ll x, ll y) {
return sum(y) ^ sum(x-1);
}
void add(ll i, ll x) {
while(i <= n) {
b[i] ^= x;
i += i & -i;
}
}
};
int main(){
ll n, q;
cin >> n >> q;
vector<ll> a(n);
rep(i, n) {
cin >> a[i];
}
BIT b(n);
b.init(a);
vector<ll> ans;
rep(i, q) {
ll t, x, y;
cin >> t >> x >> y;
if (t == 1) {
b.add(x, y);
} else {
ans.push_back(b.range_sum(x, y));
}
}
for(auto v: ans) {
cout << v << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define f1 first
#define s2 second
#define fastio ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug(x...) cerr << "[" << #x << "]: " << x << "\n";
using ll = long long;
using ld = long double;
using ii = pair<int, int>;
using pl = pair<ll, ll>;
ld const PI = 4*atan((ld)1);
int main()
{
fastio;
set<ll> st;
ll n;
cin >> n;
for (ll a = 2; a*a <= n; ++a)
{
for (ll x = a*a; x <= n; x *= a)
st.insert(x);
}
cout << n - st.size() << '\n';
return 0;
}
| //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,avx512f")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <stack>
#include <queue>
#include <bitset>
#include <numeric>
#include <cassert>
#include <memory>
#include <random>
#include <functional>
#include <complex>
#include <immintrin.h>
#ifdef DEBUG
#include "./CompetitiveProgrammingCpp/debug_VC.hpp"
#include "./CompetitiveProgrammingCpp/Timer.hpp"
#include "./CompetitiveProgrammingCpp/sample.hpp"
#else
#define dump(...)
#endif
/* macro */
#define FOR(i, b, e) for(ll i = (ll)(b); i < (ll)(e); ++i)
#define RFOR(i, b, e) for(ll i = (ll)(e-1); i >= (ll)(b); --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define REPC(x,c) for(const auto& x:(c))
#define REPI2(it,b,e) for(auto it = (b); it != (e); ++it)
#define REPI(it,c) REPI2(it, (c).begin(), (c).end())
#define RREPI(it,c) REPI2(it, (c).rbegin(), (c).rend())
#define REPI_ERACE2(it, b, e) for(auto it = (b); it != (e);)
#define REPI_ERACE(it, c) REPI_ERACE2(it, (c).begin(), (c).end())
#define ALL(x) (x).begin(),(x).end()
#define cauto const auto&
/* macro func */
template<class T>
inline auto sort(T& t) { std::sort(ALL(t)); }
template<class T>
inline auto rsort(T& t) { std::sort((t).rbegin(), (t).rend()); }
template<class T>
inline auto unique(T& t) { (t).erase(unique((t).begin(), (t).end()), (t).end()); }
template<class T, class S>
inline auto chmax(T& t, const S& s) { if (s > t) { t = s; return true; } return false; }
template<class T, class S>
inline auto chmin(T& t, const S& s) { if (s < t) { t = s; return true; } return false; }
inline auto BR() { std::cout << "\n"; }
/* type define */
using ll = long long;
using PAIR = std::pair<ll, ll>;
using VS = std::vector<std::string>;
using VL = std::vector<long long>;
using VVL = std::vector<VL>;
using VVVL = std::vector<VVL>;
using VD = std::vector<double>;
template<class T>
using V = std::vector<T>;
/* using std */
using std::cout;
constexpr char endl = '\n';
using std::cin;
using std::pair;
using std::string;
using std::stack;
using std::queue;
using std::vector;
using std::list;
using std::map;
using std::unordered_map;
using std::multimap;
using std::unordered_multimap;
using std::set;
using std::unordered_set;
using std::unordered_multiset;
using std::multiset;
using std::bitset;
using std::priority_queue;
/* Initial processing */
struct Preprocessing { Preprocessing() { std::cin.tie(0); std::ios::sync_with_stdio(0); }; }_Preprocessing;
/* Remove the source of the bug */
signed pow(signed, signed) { assert(false); return -1; }
/* define hash */
namespace std {
template <> class hash<std::pair<ll, ll>> { public: size_t operator()(const std::pair<ll, ll>& x) const { return hash<ll>()(1000000000 * x.first + x.second); } };
}
/* input */
template<class T> std::istream& operator >> (std::istream& is, vector<T>& vec) { for (T& x : vec) is >> x; return is; }
/* constant value */
constexpr ll MOD = 1000000007;
//constexpr ll MOD = 998244353;
//=============================================================================================
signed main() {
double n;
cin >> n;
double ans = 0.0;
REP(i, n - 1) {
ans += (n / static_cast<double>(i + 1));
}
cout << std::setprecision(12) << std::fixed <<
ans << endl;
}
|
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
long long a, b, w;
int main()
{
scanf("%lld%lld%lld", &a, &b, &w);
w *= 1000;
long long cc = w / a;
long long dd = w % a;
if (dd > (b - a) * cc)
{
printf("UNSATISFIABLE");
return 0;
}
long long ans2 = 0;
cc = w / b;
dd = w % b;
if (!dd)
{
ans2 = cc;
}
else
{
ans2 = cc + 1;
}
printf("%lld %lld", ans2, w / a);
return 0;
}
| #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<stack>
#include<vector>
using namespace std;
#define fori(i,a,b) for(int i=(a);i<(b);i++)
#define ford(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define mem(a,b) memset((a),(b),sizeof(a));
#define all(x) (x).begin(),(x).end()
template<class T, class T2>bool ckmax(T& a, T2 b) { return a < b ? a = b, 1 : 0; }
template<class T, class T2>bool ckmin(T& a, T2 b) { return a > b ? a = b, 1 : 0; }
typedef long long ll;
const int maxn = 2e6 + 5;
int arr[maxn], ans[maxn];
int main(void)
{
string cant = "UNSATISFIABLE";
int a, b, c;
int aa, bb;
cin >> a >> b >> c;
c *= 1000;
aa = c / a;
bb = (c+b-1) / b;
if (aa < bb) cout << cant;
else cout << bb << ' ' << aa;
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<ll,ll>;
int main() {
int N;
cin >> N;
vector<P> vec(N);
rep(i,N) cin >> vec.at(i).first >> vec.at(i).second;
ll answer=0;
rep(i,N) {
answer += (vec.at(i).second-vec.at(i).first+1)*(vec.at(i).first+vec.at(i).second)/2;
}
cout << answer << endl;
} | /*
SpoilerAlert_DumbledoreDead
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int main()
{
fast;
ll t=1;
while(t--)
{
ll n,sum=0;
cin>>n;
for(ll i=0; i<n; i++)
{
ll a,b;
cin>>b>>a;
b-=1;
sum+=((a*(a+1))/2);
sum-=((b*(b+1))/2);
}
cout<<sum<<endl;
}
}
|
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
#include <cassert>
#include <deque>
#include <map>
#include <queue>
#include <climits>
#include <set>
#include <stack>
#include <cmath>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define ll long long
#define MAX 100000
#define MAX1 10000
#define MAX2 100000
#define inf 1000000000
#define eps 1e-12
#define MOD 1000000007
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
int n;
cin >> n;
int a[n + 5], i, pos = n - 1;
for (i = 1; i <= n; ++i) {
cin >> a[i];
}
vector<int> ans;
for (i = n - 1; i >= 1; --i) {
if (a[i] == i) {
break;
}
if (a[i] < i) {
continue;
}
if (a[i] - 1 == pos) {
for (int j = i; j <= pos; ++j) {
swap(a[j], a[j + 1]);
ans.push_back(j);
}
pos = i - 1;
} else {
break;
}
}
for (i = 1; i <= n; ++i) {
if (a[i] != i) {
break;
}
}
if (i == n + 1 and pos == 0) {
for (i = 0; i < n - 1; ++i) {
cout << ans[i] << "\n";
}
} else {
cout << "-1";
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
int main(void)
{
int N;
cin >> N;
vector<int> p(N,0);
vector<bool> used(N,false);
vector<int> ans;
rep(i, N){
cin >> p[i];
--p[i];
}
int cc = 0;
for(int i = 0; i < N-1; ++i)
{
while(1)
{
if((p[cc]-cc)*(p[cc+1]-cc-1) < 0)
{
if(used[cc])
{
cout << -1 << endl;
return 0;
}
ans.push_back(cc);
used[cc] = false;
iter_swap(p.begin()+cc, p.begin()+cc+1);
--cc;
break;
}
else
{
++cc;
if(cc == N-1)
{
cout << -1 << endl;
return 0;
}
}
}
}
bool ok = true;
rep(i,N)
{
if(i != p[i]) ok = false;
}
if(ok) rep(i, N-1) cout << ans[i]+1 << endl;
else cout << -1 << endl;
return 0;
}
|
#include <iostream>
int a[100];
int b[100];
int used[200];
int main() {
int n;
std::cin >> n;
for (int i = 0; i < n; ++i) {
std::cin >> a[i] >> b[i];
if (a[i] != -1) ++used[a[i] - 1];
if (b[i] != -1) ++used[b[i] - 1];
if (a[i] != -1 and b[i] != -1 and a[i] >= b[i]) {
std::cout << "No\n";
return 0;
}
if (a[i] != -1 and used[a[i] - 1] == 2) {
std::cout << "No\n";
return 0;
}
if (b[i] != -1 and used[b[i] - 1] == 2) {
std::cout << "No\n";
return 0;
}
}
int ilen, jlen, idx, j;
for (int i = 1; i < n; ++i) {
j = i - 1;
if (a[i] == -1 or b[i] == -1) continue;
if (a[i] <= a[j] and a[j] <= b[i] and a[i] <= b[j] and b[j] <= b[i]) {
std::cout << "No\n";
return 0;
}
if (b[j] != -1) {
if (a[i] <= a[j] and a[j] <= b[i]) {
ilen = b[i] - a[i] + 1;
jlen = b[j] - a[j] + 1;
if (ilen != jlen) {
std::cout << "No\n";
return 0;
}
}
} else {
if (a[i] <= a[j] and a[j] <= b[i]) {
ilen = b[i] - a[i];
idx = a[j] + ilen - 1;
if (idx < 0 or 2 * n <= idx or used[idx] == 1) {
std::cout << "No\n";
return 0;
}
}
}
if (a[j] != -1) {
if (a[i] <= b[j] and b[j] <= b[i]) {
ilen = b[i] - a[i] + 1;
jlen = b[j] - a[j] + 1;
if (ilen != jlen) {
std::cout << "No\n";
return 0;
}
}
} else {
if (a[i] <= b[j] and b[j] <= b[i]) {
ilen = b[i] - a[i];
idx = b[j] - ilen - 1;
if (idx < 0 or 2 * n <= idx or used[idx] == 1) {
std::cout << "No\n";
return 0;
}
}
}
}
for (int i = 0; i < n; ++i) {
for (int j = i; j < n; ++j) {
if (i == j) continue;
if (a[i] == -1 or b[i] == -1) continue;
if (a[i] <= a[j] and a[j] <= b[i] and a[i] <= b[j] and b[j] <= b[i]) {
std::cout << "No\n";
return 0;
}
if (b[j] != -1) {
if (a[i] <= a[j] and a[j] <= b[i]) {
ilen = b[i] - a[i] + 1;
jlen = b[j] - a[j] + 1;
if (ilen != jlen) {
std::cout << "No\n";
return 0;
}
}
} else {
if (a[i] <= a[j] and a[j] <= b[i]) {
ilen = b[i] - a[i];
idx = a[j] + ilen - 1;
if (idx < 0 or 2 * n <= idx or used[idx] == 1) {
std::cout << "No\n";
return 0;
}
}
}
if (a[j] != -1) {
if (a[i] <= b[j] and b[j] <= b[i]) {
ilen = b[i] - a[i] + 1;
jlen = b[j] - a[j] + 1;
if (ilen != jlen) {
std::cout << "No\n";
return 0;
}
}
} else {
if (a[i] <= b[j] and b[j] <= b[i]) {
ilen = b[i] - a[i];
idx = b[j] - ilen - 1;
if (idx < 0 or 2 * n <= idx or used[idx] == 1) {
std::cout << "No\n";
return 0;
}
}
}
}
}
std::cout << "Yes\n";
} | #include <bits/stdc++.h>
#include<random>
using namespace std; typedef unsigned long long _ulong; typedef long long int lint; typedef pair<lint, lint> plint; typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define endk '\n'
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; }
const lint MOD = 1e9 + 7, INF = 1e18;
lint dx[8] = { 0, -1, 1, 0, 1, -1, 1, -1 }, dy[8] = { 1, 0, 0, -1, -1, -1, 1, 1 };
typedef pair<long double, lint> Pa;
typedef pair<lint, plint> tlint;
struct edge {
lint cost;
lint u, v;
};
lint N, A[100], B[100];
vector<plint> ok;
lint now[200];
bool used[200];
bool dfs(lint curr, lint cnt) {
if (cnt <= 0) return true;
bool ans = false;
IFOR(i, 1, cnt + 1) {
bool _can = true;
REP(j, i) {
if (now[curr + j] < 2 * N && now[curr + j] >= N) _can = false;
if (now[curr + j + i] < N) _can = false;
if (now[curr + j] != 2 * N && now[curr + j + i] != 2 * N) {
if (now[curr + j] + N != now[curr + i + j]) _can = false;
}
bool change = false;
if (now[curr + j] < N) {
if (used[now[curr + j]]) _can = false;
used[now[curr + j]] = true;
change = true;
}
if (now[curr + j + i] < 2 * N && now[curr + j + i] >= N) {
if (!change && used[now[curr + j + i] - N]) _can = false;
used[now[curr + j + i] - N] = true;
}
}
if (!ans && _can) ans |= dfs(curr + i * 2, cnt - i);
REP(j, i) {
if (now[curr + j] < N) {
used[now[curr + j]] = false;
}
if (now[curr + j + i] < 2 * N && now[curr + j + i] >= N) {
used[now[curr + j + i] - N] = false;
}
}
}
return ans;
}
int main() {
cin >> N;
bool flag = true;
REP(i, N * 2) {
now[i] = N * 2;
}
REP(i, N) {
cin >> A[i] >> B[i]; A[i]--; B[i]--;
if (A[i] != -2) {
if (now[A[i]] != N * 2) flag = false;
now[A[i]] = i;
}
if (B[i] != -2) {
if (now[B[i]] != N * 2) flag = false;
now[B[i]] = i + N;
}
if (A[i] != -2 && B[i] != -2) {
if (A[i] >= B[i]) {
flag = false;
}
}
used[i] = false;
}
if (flag && dfs(0, N)) cout << "Yes" << endk;
else cout << "No" << endk;
}
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m; i >= n; --i)
#define ALL(v) (v).begin(),(v).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; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
const int nmax=3000005;
ll fac[nmax],finv[nmax],inv[nmax];
void COMinit(){
fac[0]=fac[1]=1;
finv[0]=finv[1]=1;
inv[1]=1;
for(int i=2;i<nmax;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;
}
}
ll com(int n,int k){
if(n<k||n<0||k<0){
return 0;
}
return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
COMinit();
ll n,m,k;cin >> n >> m >> k;
ll ans;
if(n<=m+k) ans=com(n+m,m)+mod-com(n+m,m+k+1);
else ans=0;
ans%=mod;
cout << ans << endl;
} | #include <iostream>
#include <cmath>
using namespace std;
int main() {
double x, y, r;
scanf("%lf %lf %lf", &x, &y, &r);
long long sr = static_cast<long long>(round(r * 10000)) * static_cast<long long>(round(r * 10000));
long long ans = 0;
for (int i = static_cast<int>(ceil(x - r)); i <= static_cast<int>(floor(x + r)); i++) {
int lower, upper;
long long dx = i * 10000 - static_cast<int>(round(x * 10000));
long long sdx = 1LL * dx * dx;
int left = static_cast<int>(floor(y - r)), right = static_cast<int>(ceil(y));
while (left < right) {
int mid = (left + right) >> 1;
long long dy = mid * 10000 - static_cast<int>(round(y * 10000));
long long sdy = 1LL * dy * dy;
if (sdx + sdy > sr)
left = mid + 1;
else
right = mid;
}
lower = left;
left = static_cast<int>(floor(y)), right = static_cast<int>(ceil(y + r));
while (left < right) {
int mid = (left + right + 1) >> 1;
long long dy = mid * 10000 - static_cast<int>(round(y * 10000));
long long sdy = 1LL * dy * dy;
if (sdx + sdy > sr)
right = mid - 1;
else
left = mid;
}
upper = left;
if (lower <= upper)
ans += (upper - lower + 1);
}
printf("%lld\n", ans);
return 0;
} |
#include <bits/stdc++.h>
using namespace std ;
const int MAX = 1e5 + 10 ;
int a[MAX] , b[MAX] ;
int arr[MAX] ;
int n , m , q ;
vector< pair<int , int> >vp ;
multiset<int>s ;
int main()
{
ios_base::sync_with_stdio(0) ;
cin.tie(0) ;
cin>>n>>m>>q ;
for(int i = 0 ; i < n ; ++i)
{
cin>>a[i]>>b[i] ;
vp.emplace_back(b[i] , a[i]) ;
}
for(int i = 0 ; i < m ; ++i)
cin>>arr[i] ;
sort(vp.begin() , vp.end()) ;
reverse(vp.begin() , vp.end()) ;
while(q--)
{
s.clear() ;
int l , r ;
cin>>l>>r ;
l-- , r-- ;
for(int i = 0 ; i < m ; ++i)
{
if(i >= l && i <= r)
continue ;
s.insert(arr[i]) ;
}
int ans = 0 ;
for(auto &p : vp)
{
if(!s.size())
break ;
auto it = s.lower_bound(p.second) ;
if(it == s.end())
continue ;
ans += p.first , s.erase(it) ;
}
cout<<ans<<"\n" ;
}
return 0 ;
} | #include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define ina(n,a) cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev coyhhhhhhyoc
#define next sdNNNmNNNNNNNmds
#define y0 hNNNNy_yNNNNNN_sNh
#define y1 mNNNNNdtdNNNNNNtsNNm
#define yn mNNNNNNNNy___smNNNms
#define tm oooooosyysooooot
#define read tyhyt
#define rank ytmNmo
#define index yyy
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#define rall(x,a) for(auto x : a)
#define MOD 1000000007
#define endl "\n"
typedef long long ll;
using namespace std;
const int N = 222222;
vector<int> graph[N];
int a[N], maxi[N];
int n, m;
int solve() {
cin >> n >> m;
rep(u, 1, n) {
cin >> a[u];
}
rep(i, 1, m) {
int u, v;
cin >> u >> v;
graph[u].pb(v);
}
int ans = -1e9 - 19;
rrep(u, 1, n) {
maxi[u] = -1e9 - 19;
rall(v, graph[u]) {
int ne = max(maxi[v], a[v]);
maxi[u] = max(maxi[u], ne);
}
ans = max(ans, maxi[u] - a[u]);
}
cout << ans << endl;
return 0;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int t = 1;
while(t--) {
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define F(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define R(i,b,a) for(int i=(int)(b);i>=(int)(a);i--)
#define endl "\n"
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define pii pair<int,int>
#define pb push_back
#define all(v) v.begin(),v.end()
#define I first
#define S second
const int N=105;
int n,x[N],y[N],id[N],off=1e12;
int root(int x){
while(x!=id[x]){
id[x]=id[id[x]];
x=id[x];
}
return x;
}
void uni(int x,int y){
int p=root(x);
int q=root(y);
if(p==q) return;
id[q]=id[p];
}
bool slv(int x1,int y1,int x2,int y2,int r){
int dis=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
dis*=off;
return (dis<4*r*r);
}
bool chk(int r){
F(i,1,n+2) id[i]=i;
F(i,1,n){
F(j,i+1,n){
if(slv(x[i],y[i],x[j],y[j],r)) uni(i,j);
}
}
F(i,1,n){
int d1=abs(100-y[i])*(1e6);
int d2=abs(y[i]+100)*(1e6);
if(d1<2*r) uni(n+1,i);
if(d2<2*r) uni(n+2,i);
}
return (root(n+1)!=root(n+2));
}
int32_t main(){
ios;
cin>>n;
F(i,1,n) cin>>x[i]>>y[i];
int l=0,r=1e8,mid;
while(l<=r){
mid=l+r>>1;
if(chk(mid)) l=mid+1;
else r=mid-1;
}
l--;
cout<<setprecision(9)<<double(l)/1e6<<endl;
}
| #include<bits/stdc++.h>
using namespace std;
const int inf=1<<29;
const double eps=1e-8;
const int maxn=220;
int n,ans=0;
double l=0,r=100,mid=50;
int sqr(int x){return x*x;}
struct point{int x,y;}p[maxn];
struct mgset{
int tp[maxn],siz[maxn];
mgset(){for(int i=0;i<=n+3;i++)tp[i]=i,siz[i]=1;}
void pre(){for(int i=0;i<=n+3;i++)tp[i]=i,siz[i]=1;}
int get(int x){return x==tp[x]?x:tp[x]=get(tp[x]);}
void mg(int x,int y){
x=get(x),y=get(y);
if(x==y)return;
if(siz[x]<siz[y])swap(x,y);
siz[x]+=siz[y],tp[y]=x;
}
bool judge(int x,int y){return get(x)==get(y);}
int ask(int x){return siz[get(x)];}
}s;
bool check(int a,int b,double r){return sqrt(sqr(p[a].x-p[b].x)+sqr(p[a].y-p[b].y))<=r*2;}
bool judge(double r){
s.pre();
for(int i=1;i<=n;i++)for(int j=i+1;j<=n;j++)if(check(i,j,r))s.mg(i,j);
for(int i=1;i<=n;i++)if(abs(p[i].y+100)<=r*2)s.mg(i,n+1);
for(int i=1;i<=n;i++)if(abs(p[i].y-100)<=r*2)s.mg(i,n+2);
return !s.judge(n+1,n+2);
}
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++)scanf("%d%d",&p[i].x,&p[i].y);
l=0,r=100,mid=(l+r)/2;
while(r-l>=eps){
mid=(l+r)/2;
if(judge(mid))l=mid;
else r=mid;
}
printf("%.4lf",l);
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#ifndef aa
#define trace(...)
#define endl '\n'
#endif
#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 pdd pair<double,double>
#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;
//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...) cerr << "[" << #x << "] = "; _print(x)
#else
#define deb(x...)
#endif
// DEBUG FUNCTIONS END
const int N = 3e3+5;
int dp[N][N];
void solve(){
int n, k;
cin>>n>>k;
dp[0][0] = 1;
fr(i,1,n){
frev(j,0,n){
if(j)
dp[i][j] = dp[i-1][j-1];
(dp[i][j] += (2*j>i ? 0 : dp[i][2*j]))%=mod;
}
}
cout<<dp[n][k];
}
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
//srand(chrono::high_resolution_clock::now().time_since_epoch().count());
cout << fixed << setprecision(15);
int t = 1;
//cin >> t;
while (t--)
solve();
#ifdef aa
cout << endl << endl << endl << endl << "Time elapsed: " << (double)(clock() - clk) / CLOCKS_PER_SEC << endl;
#endif
return 0;
}
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;
}
int divide(int a, int b) {
return (a % mod) * powm(b, mod - 2) % mod;
}
int norm(int a) {
while (a >= mod) a -= mod;
while (a < 0) a += mod;
return a;
} | #include<bits/stdc++.h>
typedef int LL;
typedef double dl;
#define opt operator
#define pb push_back
const LL maxn=6e3+9,mod=998244353,inf=0x3f3f3f3f;
LL Read(){
LL x(0),f(1); char c=getchar();
while(c<'0' || c>'9'){
if(c=='-') f=-1; c=getchar();
}
while(c>='0' && c<='9'){
x=(x<<3ll)+(x<<1ll)+c-'0'; c=getchar();
}return x*f;
}
void Chkmin(LL &x,LL y){
if(y<x) x=y;
}
void Chkmax(LL &x,LL y){
if(y>x) x=y;
}
LL add(LL x,LL y){
return x+=y,x>=mod?x-mod:x;
}
LL dec(LL x,LL y){
return x-=y,x<0?x+mod:x;
}
LL mul(LL x,LL y){
return 1ll*x*y%mod;
}
LL Pow(LL base,LL b){
LL ret(1); while(b){
if(b&1) ret=mul(ret,base); base=mul(base,base); b>>=1;
}return ret;
}
LL n,K;
LL f[maxn][maxn];
int main(){
n=Read(); K=Read();
if(n==1 && K==1){
puts("1"); return 0;
}
for(LL i=2;i<=n;i+=2) f[0][i]=1;
for(LL i=0;i<=n;++i){
if(i){
for(LL j=1;j<=n;++j){
f[i][j]=add(f[i][j-1],f[i][j]);
}
}
for(LL j=0;j<=n;++j) {
if(j&1) continue;
if(!j) continue;
LL x(f[i][j]);
LL l(j/2);
f[i+l][l]=add(f[i+l][l],x);
}
}
// printf("%d\n",f[1][2]);
// printf("%d\n",f[2][2]);
// printf("%d\n",f[3][1]);
printf("%d\n",f[n-K][K]);
return 0;
LL ret(0);
// printf("%d\n",f[4][2]);
for(LL i=0;i<=K;++i){
ret=add(ret,f[n-(K-i)][K-i]);
}
printf("%d\n",ret);
// printf("%d\n",f[n-K][n]);
return 0;
}
|
# include <cstdio>
namespace Main {
namespace Source {
typedef unsigned int uint;
static inline const uint qpow(uint b, uint e, const uint mod) {
uint r(1);
while (e) {
if (e bitand 1) r = 1ull * r * b % mod;
b = 1ull * b * b % mod, e >>= 1;
}
return r;
}
}
using namespace Source;
static const uint P(998244353);
static uint n, m, k;
static uint ans;
static inline const void main() {
scanf("%u%u%u", &n, &m, &k);
if (n == 1 and m == 1) return (const void)printf("%u\n", k);
if (n == 1) {
for (register uint i(1); i <= k; ++i)
ans =
(ans + (qpow(k - i + 1, m, P) + P - qpow(k - i, m, P))) % P;
goto end;
}
if (m == 1) {
for (register uint i(1); i <= k; ++i)
ans =
(ans + (qpow(i, n, P) + P - qpow(i - 1, n, P))) % P;
goto end;
}
for (register uint i(1); i <= k; ++i)
ans = (ans + 1ull * (qpow(i, n, P) + P - qpow(i - 1, n, P)) * qpow(k - i + 1, m, P)) % P;
end:printf("%u\n", ans);
}
}
signed int main() { Main::main(); return 0; } | #include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <string>
#include <map>
#include <iostream>
#include <vector>
#include <queue>
#include <unordered_map>
#include <random>
#include <stack>
#include <set>
#include <list>
#include <unordered_set>
//#include <atcoder/convolution>
//#include <atcoder/modint>
#define bug(x) cout<<"zdongdebug1: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug2: "<<x<<" "<<y<<endl;
#define bug3(x, y, z) cout<<"zdongdebug3: "<<x<<" "<<y<<" "<<z<<endl;
using namespace std;
//using Modint = atcoder::modint998244353;
typedef long long ll;
void ex_gcd(ll a,ll b, ll& d,ll& x,ll& y){
if(!b) {d=a;x=1;y=0;}
else { ex_gcd(b,a%b,d,y,x); y-=a/b*x;}
}
ll inv(ll a,ll n) {
ll d,x,y; ex_gcd(a,n,d,x,y);
return d==1?(x%n+n)%(n/d):-1;
}
ll gcd(ll x, ll y){
if(y==0)return x;
return gcd(y, x%y);
}
const int maxn = 5005;
const int mod = 998244353;
ll p[maxn];
ll cal(int x, int y){
if(x<y)return 0;
return p[x]*inv(p[y]*p[x-y]%mod, mod)%mod;
}
ll f[13][maxn];
int main() {
#ifdef suiyuan2009
freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
//freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
p[0] = 1;
for(int i=1;i<maxn;i++)p[i] = p[i-1]*i%mod;
int n,m;
cin>>n>>m;
for(int i=0;i<=m;i+=2)f[0][i] = cal(n, i);
for(int i=0;i+1<13;i++)
for(int j=0;j<=m;j++){
if(f[i][j]==0)continue;
for(int k=0;j+k*(1<<(i+1))<=m;k+=2){
f[i+1][j+k*(1<<(i+1))] = (f[i+1][j+k*(1<<(i+1))] + f[i][j]*cal(n,k)%mod)%mod;
}
}
cout<<f[12][m]<<endl;
return 0;
} |
#include "bits/stdc++.h"
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second
#define cbr cerr<<"hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x,y) (lower_bound(all(x),y)-x.begin())
#define ubd(x,y) (upper_bound(all(x),y)-x.begin())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return rng() % (y+1-x) + x; } //inclusivesss
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }
using ll=long long;
using ld=long double;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
using pi=pair<ll,ll>; using spi=pair<ll,pi>; using dpi=pair<pi,pi>;
long long LLINF = 1e18;
int INF = 1e9+1e6;
#define MAXN (106)
int n, m, C[MAXN], ok[MAXN*MAXN];
pi E[MAXN*MAXN];
bitset<MAXN> vis;
vector<pi> v[MAXN];
int main() {
FAST
cin>>n>>m;
FOR(i,1,m){
cin>>E[i].f>>E[i].s;
}
FOR(i,1,n) cin>>C[i];
FOR(i,1,m) {
int a=E[i].f, b=E[i].s;
if(C[a] > C[b]) {
v[a].eb(b, 0), ok[i]=a;
} else if(C[a] < C[b]) {
v[b].eb(a, 0), ok[i]=b;
} else {
v[a].eb(b, i), v[b].eb(a, i);
}
}
function<void(ll)>dfs=[&](ll x){
if(vis[x]) return;
vis[x]=1;
for(auto i:v[x]) {
if(i.s) {
ok[i.s] = x;
}
dfs(i.f);
}
};
FOR(i,1,n) dfs(i);
FOR(i,1,m) {
assert(ok[i]==E[i].f||ok[i]==E[i].s);
if(ok[i] == E[i].f) cout<<"->\n";
else cout<<"<-\n";
}
}
| #define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main () {
std::ios::sync_with_stdio(false); std::cin.tie(0);
int n, m;
cin >> n >> m;
vector<int> a(n);
for (auto& x : a) cin >> x;
multiset<int> have;
set<int> st;
for (int i = 0; i <= n; i++) st.emplace(i);
int ans = 1 << 30;
for (int i = 0; i < n; i++) {
have.emplace(a[i]);
if (st.count(a[i])) st.erase(a[i]);
if (i - m >= 0) {
have.erase(have.find(a[i - m]));
if (have.find(a[i - m]) == have.end()) st.emplace(a[i - m]);
}
if (i >= m - 1) {
if (!st.empty()) ans = min(ans, *st.begin());
}
}
cout << ans << endl;
}
|
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <random>
#include <set>
#include <stack>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define SORTR(x) sort(x.begin(),x.end(),greater<int>())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
using namespace std;
using ll = long long;
using LL = long long;
using comp = complex<double>;
typedef std::pair<int, int> pii;
typedef std::pair<int, double> pid;
typedef std::vector<int> vi;
typedef std::vector<pii> vii;
const double PI = 3.14159265358979323846264338327950L;
const int mod = 1e9+7;
const ll INF = 1LL<<60;
comp inC(){
double x,y;
cin >> x >> y;
return {x,y};
}
struct container {
int bottom, top, id;
container(int id, int bottom, int top) : top(top), bottom(bottom), id(id) {
}
};
struct Edge {
ll to, from, cost;
Edge(ll to, ll from, ll cost) :to(to), from(from), cost(cost) {}
Edge(): to(-1), from(-1), cost(0){}
};
struct Data {
ll cost,val;
Data(ll cost=0, ll val=0) : cost(cost), val(val){}
bool operator<(const Data& a) const {
return cost > a.cost;
}
};
struct edge{
int a,b,c;
edge(int a = -1,int b = -1, int c = -1):a(a),b(b),c(c){}
bool operator<(const edge& a) const {
return c > a.c;
}
};
void solveA(){
ll n;
cin >> n;
if (n==2){
cout << "Same" << endl;
return;
}
if (n%2==1){
cout << "Odd" << endl;
return;
}
if ((n/2)%2==1){
cout << "Same" << endl;
}
else cout << "Even" << endl;
}
void solve(){
int n;
cin >> n;
vector<ll> a(n);
rep(i,n) cin >> a[i];
int m = 998244353;
ll cursum = 0;
ll prevadd = 0;
ll ans = 0;
SORT(a);
rep(i,n){
ll add = a[i];
cursum *= 2LL;
cursum += prevadd;
cursum %= m;
ll mult = (cursum + add)%m;
ll p = mult*add;
p%=m;
ans += p;
ans %= m;
prevadd = add;
}
cout << ans;
}
int main() {
int T = 1;
// cin >> T;
while (T--) {
solve();
// cout << endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
ll mod1= 998244353;
ll pow_mod(ll a,ll b)
{
ll res=1;
while(b!=0)
{
if(b&1)
{
res=(res*a)%mod1;
}
a=(a*a)%mod1;
b/=2;
}
return res;
}
ll inv_mod(ll x){
return pow_mod(x,mod1-2);
}
int main()
{
int t=1;
//cin>>t;
while(t-->0){
int n;
cin>>n;
ll a[n];
ll sum=0;
ll dp[n];
dp[0]=1;
for(int i=1;i<n;i++){
dp[i]=2*dp[i-1];
dp[i]%=mod1;
}
for(int i=0;i<n;i++){
cin>>a[i];
sum=(sum+(a[i]*a[i])%mod1)%mod1;
//sum%=mod1;
}
sort(a,a+n);
ll prev[n+1];
prev[n]=0;
for(int i=n-1;i>=1;i--){
prev[i]=(prev[i+1]+((a[i]*a[0])%mod1*(dp[i-1]%mod1))%mod1)%mod1;
//prev[i]%=mod1;
}
sum=(sum+prev[1])%mod1;
for(int i=2;i<=n-1;i++){
prev[i]=(prev[i]*inv_mod(dp[i-1]))%mod1;
prev[i]=(prev[i]*inv_mod(a[0]))%mod1;
//prev[i]/=a[0];
prev[i]*=a[i-1];
prev[i]%=mod1;
sum=(sum+prev[i])%mod1;
}
cout<<sum;
}
return 0;
} |
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <vector>
//#define ENVIRONMENT_LINKED_BOOST
#ifdef ENVIRONMENT_LINKED_BOOST
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
#endif
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#define REP(i, a, b) for (int i = a; i < b; ++i)
#define ALL(v) v.begin(), v.end()
template <typename A, typename B>
void chmin(A &a, const B &b) {
a = min(a, static_cast<A>(b));
};
template <typename A, typename B>
void chmax(A &a, const B &b) {
a = max(a, static_cast<A>(b));
};
int main() {
ll N, K, M;
cin >> N >> K >> M;
ll smax = N * (N - 1) * K / 2;
vector<vector<ll>> dp(N, vector<ll>(smax + 1, 0));
dp[0][0] = 1;
REP(i, 0, N - 1) {
REP(j, 0, smax + 1) {
dp[i][j] %= M;
if (dp[i][j] == 0) continue;
REP(k, 0, K + 1) {
int tmp = j + (i + 1) * k;
dp[i + 1][tmp] += dp[i][j];
}
}
}
for (ll &x : dp[N - 1]) x %= M;
REP(i, 1, N + 1) {
ll p = N - i;
ll m = i - 1;
ll ans = K;
REP(j, 1, smax + 1) {
ans += dp[p][j] * dp[m][j] % M * (K + 1) % M;
ans %= M;
}
cout << ans << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(a,b,c) for(int a=(b);a<=(c);a++)
#define per(a,b,c) for(int a=(b);a>=(c);a--)
#define pb push_back
const int N=5e5+5e4+5;
template<class T>inline void read(T &x) {
T f=1;x=0;char s=getchar();
while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
while(s>='0'&&s<='9'){x=x*10+s-'0';s=getchar();}
x*=f;
}
int n,k,p,f[101][N],ans,g[N],sum;
inline void solve() {
read(n); read(k); read(p);
f[0][0]=1;
rep(i,1,n) {
sum+=i*k;
rep(j,0,sum) g[j]=(f[i-1][j]+((j>=i)?(g[j-i]):(0)))%p;
rep(j,0,sum) f[i][j]=(p+g[j]-(((j-(k+1)*i)>=0)?(g[j-(k+1)*i]):(0)))%p;
}
rep(i,1,n) {
ans=0;
rep(sm,0,sum) (ans+=1ll*f[n-i][sm]*f[i-1][sm]%p)%=p;
printf("%d\n",(1ll*ans*(k+1)-1)%p);
}
}
int main() {
//int TEST; read(TEST); while(TEST--)
solve();
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;
template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (ll i=(ll)N-1; i>=0; i--)
#define popcount __builtin_popcount
const ll LLINF = pow(2,61)-1;
const ll INF = pow(2,30)-1;
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }
void check(vector<ll> result) {
ll x = 0, y = 0;
for (auto r: result) {
if (r==1) x++;
else if (r==2) y++;
else if (r==3) x+=y;
else if (r==4) y+=x;
}
cout << x << endl;
}
int main() {
ll N; cin >> N;
ll X = 87, tn = N;
// ll X = 15, tn = N;
vector<ll> fib(X); rep(i,X) fib[i] = i<=1 ? 1 : fib[i-1] + fib[i-2];
// debug(all(fib));
vector<bool> used(X);
ll top = -1;
per(i,X) {
if (tn>=fib[i]) {
used[i] = true;
tn -= fib[i];
if (top==-1) top = i;
}
}
// debug(all(used));
// cout << top << endl;
vector<ll> result;
for (ll i=top; i>0; i--) {
if (used[i]) result.push_back(i%2==0?1:2);
result.push_back(i%2==0?4:3);
}
cout << result.size() << endl;
debug(all(result));
// check(result);
return 0;
} | #include <iostream>
using namespace std;
typedef long long LL;
LL f[110];
int ans[150], cnt;
void ins(int x) {
ans[cnt ++] = x;
}
int main() {
f[0] = f[1] = 1;
for (int i = 2; ; i ++) {
f[i] = f[i - 1] + f[i - 2];
if(f[i] > 1e18) {
break;
}
}
LL n, tem = 0;
cin >> n;
if (tem + f[86] <= n) {
tem += f[86];
ins(1);
}
for (int i = 1; i <= 86; i ++) {
if (i & 1) ins(4);
else ins(3);
if (tem + f[86 - i] <= n) {
tem += f[86 - i];
if (i & 1) ins(2);
else ins(1);
}
}
cout << cnt << endl;
for (int i = 0; i < cnt; i ++) cout << ans[i] << endl ;
}
|
#include<bits/stdc++.h>
#define R register
using namespace std;
inline int read(){
int x=0,d=1; char y=getchar();
while(y<'0'||y>'9'){if(y=='-')d=-1;y=getchar();}
while(y>='0'&&y<='9'){x=(x<<3)+(x<<1)+(y^'0');y=getchar();}
return x*d;
}
int n,k,p,l,a[10010];
int main(){
n=read();
while(n--){
k=l=read();
p=sqrt(k)+1;
for(R int i=2;i<=l;i++)
if(k%i==0)++a[i];
}
int maxn=0,id=0;
for(R int i=2;i<=1000;i++)
if(a[i]>maxn){
maxn=a[i];
id=i;
}
printf("%d\n",id);
return 0;
} | #include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#include<bitset>
#include<functional>
#include <fstream>
//#include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define rep(i, x) for(ll i = 0; i < x; i++)
#define rep2(i, x) for(ll i = 1; i <= x; i++)
#define rep3(i, x, y) for(ll i = x; i < y; i++)
#define rep4(i, x) for(ll i = x; i >= 0; i--)
#define all(a) (a).begin(),(a).end()
#define puts(x) cout << (x) << "\n"
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 1000000000000000000;
const int intINF = 1000000000;
const ll mod = 1000000007;
const ll MOD = 998244353;
const ld pi = 3.141592653589793238;
//const ld EPS = 1e-9;
bool isprime(int p) {
if (p == 1) return false;
for (int i = 2; i < p; i++) {
if (p % i == 0) return false;
}
return true;
}
ll gcd(ll a, ll b) {
if (a < b)swap(a, b);
if (a % b == 0)return b;
return gcd(b, a % b);
}
// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
//main関数内に extGCD(a, b, x, y); でx, yに解が格納
ll extGCD(ll a, ll b, ll& x, ll& y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
ll d = extGCD(b, a % b, y, x);
y -= a / b * x;
return d;
}
ll lcm(ll a, ll b) {
return a / gcd(a, b) * b;
}
ll keta(ll n) {
ll res = 0;
while (n >= 1) {
res += n % 10; n /= 10;
}
return res;
}
ll modpow(ll x, ll y, ll m) {
ll res = 1;
while (y) {
if (y % 2) { res *= x; res %= m; }
x = x * x % m; y /= 2;
}
return res;
}
ll kaijyo[600005];
void nCkinit(ll n, ll m) {
ll cnt = 1; kaijyo[0] = 1;
for (int h = 1; h <= n; h++) { cnt *= h; cnt %= m; kaijyo[h] = cnt; }
}
ll nCk(ll n, ll k, ll m) {
/*ll a = 1, b = 1;
for (int h = 1; h <= n; h++) { a *= h; a %= m; }
for (int h = 1; h <= k; h++) { b *= h; b %= m; }
for (int h = 1; h <= n - k; h++) { b *= h; b %= m; }*/
ll a = kaijyo[n], b = kaijyo[k] * kaijyo[n - k] % m;
return a * modpow(b, m - 2, m) % m;
}
//printf("%.10f\n", n);
typedef pair <ll, ll> P;
typedef pair <char, ll> pp;
ll dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
struct edge { ll to, cost; };
struct status {
ll v; //今の頂点
ll cost; //今までのコスト
ll ondo; //今の温度(0,1,2)
ll time; //今の温度になってから何分経ったか
bool operator<(const status& rhs) const { return cost < rhs.cost; };
bool operator>(const status& rhs) const { return cost > rhs.cost; };
};
int main() {
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
//cout << fixed << setprecision(15);
//input
ll n; cin >> n;
vector<vector<ll>>a(6, vector<ll>(n));
rep(i, n) {
cin >> a[0][i] >> a[1][i] >> a[2][i] >> a[3][i] >> a[4][i];
}
vector<ll> stand(40);
rep(k, n) {
for (int i = 0; i < (1 << 5); i++) {
ll cnt = INF;
for (int j = 0; j <= 5 - 1; j++) {
if ((i & (1 << j)) > 0) {
cnt = min(cnt, a[j][k]);
}
}
stand[i] = max(cnt, stand[i]);//cout<<i<<' '<<stand[i]<<endl;
}
}
ll ok = 0, ng = mod, mid = (ok + ng) / 2;
while (ng - ok > 1) {
bool flag = false;
rep(i, n) {
for (int j = i + 1; j < n; j++) {
ll cnt = 0;
rep(k, 5) {
if (max(a[k][i], a[k][j]) < mid) {
cnt += pow(2, k);
}
}
if (stand[cnt] >= mid) { flag = true; }
}
}
if (flag) { ok = mid; }
else { ng = mid; }
mid = (ok + ng) / 2;
}
cout << ok << endl;
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define frfr freopen("input.text","r",stdin); //freopen("output.text","w",stdout)
#define ll long long int
#define wh int T;cin >> T;while(T--)
#define foro(i,n) for(int i=0;i<n;i++)
void solve(){
int n,x;
cin >> n >> x;
string s;
cin >> s;
for(int i : s){
if(i == 'o'){
x++;
}else{
if(x != 0) x--;
}
}
cout << x << endl;
}
int main()
{
solve();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = (n-1); i >= 0; i--)
#define Rep(n) for (ll _ = 0; _ < (ll)(n); _++)
template <class S>S sum(vector<S>& a) {return accumulate(all(a), S());}
template <class S>S max(vector<S>& a) {return *max_element(all(a));}
template <class S>S min(vector<S>& a) {return *min_element(all(a));}
ll max(int a, ll b) { return max((ll)a, b); } ll max(ll a, int b) { return max(a, (ll)b); }
ll min(int a, ll b) { return min((ll)a, b); } ll min(ll a, int b) { return min(a, (ll)b); }
void Main();
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(20);
Main();
return 0;
}
void Main(){
int n,x; cin >> n >> x;
string s; cin >> s;
for(char a: s){
if(a == 'o'){
x++;
}else{
x = max(0, x-1);
}
}
cout << x << endl;
}
|
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
int n,m,k;
long double f[210001][2],sum[210000][2];
int main()
{
cin>>n>>m>>k;
for(int i=1;i<=k;i++)
{
int x;
cin>>x;
f[x][1]=1;
}
for(int x=n-1;x>=0;x--)
{
if(f[x][1])
{
sum[x][1]=sum[x+1][1]+f[x][1];
sum[x][0]=sum[x+1][0];
continue;
}
f[x][1]+=(sum[x+1][1]-sum[x+m+1][1])/m;
sum[x][1]=sum[x+1][1]+f[x][1];
f[x][0]+=(sum[x+1][0]-sum[x+m+1][0])/m+1;
sum[x][0]=sum[x+1][0]+f[x][0];
}
//cout<<f[0][0]<<' '<<f[0][1]<<endl;
if(fabs(f[0][1]-1.0)<1e-7)cout<<-1;
else cout<<fixed<<showpoint<<setprecision(10)<<f[0][0]/(1-f[0][1]);
return 0;
} | #include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second
const int N = 2e5 + 5;
const int INF = 2e9;
const ll LINF = 9e18;
struct query {
ll T, X, Y;
};
ll n, m, q;
ll a[N], b[N];
ll tree[4][N << 2];
// 0 = Sum_A, 1 = Sum_B, 2 = Freq_A, 3 = Freq_B
void update(int idx, int l, int r, int pos, int val, int d) {
if(l > pos || r < pos) return;
if(l == r) {
tree[d][idx] += val;
return;
}
int mid = l + r >> 1;
update(idx << 1, l, mid, pos, val, d);
update(idx << 1 | 1, mid + 1, r, pos, val, d);
tree[d][idx] = tree[d][idx << 1] + tree[d][idx << 1 | 1];
}
ll rangeSum(int idx, int l, int r, int from, int to, int d) {
if(l > to || r < from) return 0;
if(from <= l && r <= to) return tree[d][idx];
int mid = l + r >> 1;
return (
rangeSum(idx << 1, l, mid, from, to, d) +
rangeSum(idx << 1 | 1, mid + 1, r, from, to, d)
);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m >> q;
vector<query> Q;
set<int> distinct;
distinct.insert(0);
while(q--) {
int t, x, y; cin >> t >> x >> y;
Q.push_back({t, x, y});
distinct.insert(y);
}
int cnt = 0;
map<int, int> idx;
for(int u : distinct) {
idx[u] = ++cnt;
}
int s = distinct.size();
update(1, 1, s, idx[0], n, 2);
update(1, 1, s, idx[0], m, 3);
ll ans = 0;
for(query u : Q) {
if(u.T == 1) {
int prv = idx[a[u.X]];
int nxt = idx[u.Y];
ans -= rangeSum(1, 1, s, 1, prv, 3) * a[u.X];
ans += rangeSum(1, 1, s, 1, prv, 1);
ans -= rangeSum(1, 1, s, 1, nxt, 1);
ans += rangeSum(1, 1, s, 1, nxt, 3) * u.Y;
update(1, 1, s, prv, -a[u.X], 0);
update(1, 1, s, nxt, u.Y, 0);
update(1, 1, s, prv, -1, 2);
update(1, 1, s, nxt, 1, 2);
a[u.X] = u.Y;
} else {
int prv = idx[b[u.X]];
int nxt = idx[u.Y];
ans -= rangeSum(1, 1, s, 1, prv, 2) * b[u.X];
ans += rangeSum(1, 1, s, 1, prv, 0);
ans -= rangeSum(1, 1, s, 1, nxt, 0);
ans += rangeSum(1, 1, s, 1, nxt, 2) * u.Y;
update(1, 1, s, prv, -b[u.X], 1);
update(1, 1, s, nxt, u.Y, 1);
update(1, 1, s, prv, -1, 3);
update(1, 1, s, nxt, 1, 3);
b[u.X] = u.Y;
}
cout << ans << "\n";
}
}
|
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL)
#define endl '\n'
#define mod 1000000007
#define inf 1e18
#define int long long
#define fr(i,a,b) for( int i=a;i<b;i++)
typedef vector<int> vi;typedef vector<vi> vvi;
typedef pair<int,int> pi;typedef vector<pi> vpi;
#define sz(x) (int)(x).size()
#define all(v) (v).begin(), (v).end()
#define ar array
#define pb push_back
void ingraph(vi graph[], int m){int x, y;fr(i,0,m){cin>>x>>y;x--, y--;graph[x].pb(y);graph[y].pb(x);}}
int32_t main()
{
fast;
int n;
cin>>n;
string s[n];
map<string,bool>mp;
fr(i,0,n)
{
cin>>s[i];
if(s[i][0]=='!')
{
mp[s[i].substr(1,sz(s[i])-1)]=true;
}
}
string ans="";
fr(i,0,n)
{
if(s[i][0]!='!')
{
if(mp[s[i]])
{
ans=s[i];
break;
}
}
}
if(sz(ans)!=0)
{
cout<<ans<<"\n";
}
else cout<<"satisfiable\n";
//cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
return 0;
} | #include <iostream>
#include <map>
#include <unordered_map>
#include <string>
int main() {
size_t n_string;
std::cin >> n_string;
std::unordered_map<std::string, bool> map;
std::string s;
for (size_t i = 0; i < n_string; i++) {
std::cin >> s;
bool if_exclamation;
if (s[0] == '!') {
s = s.substr(1);
if_exclamation = true;
} else {
if_exclamation = false;
}
auto find = map.find(s);
if (find != map.end()) {
if (if_exclamation != find->second) {
std::cout << s << std::endl;
return 0;
}
} else {
map[s] = if_exclamation;
}
}
std::cout << "satisfiable" << std::endl;
}
|
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse4")
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define SZ(a) (int)((a).size())
#define ALL(a) a.begin(), a.end()
typedef long long LL;
typedef pair<int, int> PII;
const int MAX = 51;
bool p[MAX];
LL a[MAX];
int main()
{
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
FOR(i, 2, MAX)
p[i] = true;
vector<int> primes;
FOR(i, 2, MAX)
if(p[i])
{
for(int j = 2 * i; j < MAX; j += i)
p[j] = false;
primes.push_back(i);
}
int n;
cin >> n;
FOR(i, 0, n)
cin >> a[i];
LL ans = LONG_LONG_MAX;
FOR(mask, 0, 1 << SZ(primes))
{
LL cur = 1;
FOR(i, 0, SZ(primes))
if((mask >> i) & 1)
cur *= primes[i];
bool ok = true;
FOR(i, 0, n)
ok &= __gcd(cur, a[i]) > 1;
if(ok)
ans = min(ans, cur);
}
cout << ans << "\n";
return 0;
}
| # include <bits/stdc++.h>
using namespace std;
const int maxn=330;
vector<int> vec[maxn];
int n;
int a[maxn];
int tot;
int tmp[maxn];
int main(){;
cin>>n;
for(int i=0;i<n;i++) cin>>a[i],a[i]%=200;
int up=min(8,n),fl=0;
for(int p=0;p<(1<<up)&&fl==0;p++){
int cur=0;
tot=0;
for(int i=0;i<up;i++){
if((p>>i)&1) cur=(cur+a[i])%200,tmp[tot++]=i;
}
if(vec[cur].size()){
cout<<"YES";
cout<<"\n"<<(int)vec[cur].size();
for(int i=0;i<vec[cur].size();i++) cout<<" "<<vec[cur][i]+1;
cout<<"\n"<<tot;
for(int i=0;i<tot;i++) cout<<" "<<tmp[i]+1;
fl=1;
}
else {
for(int i=0;i<tot;i++) vec[cur].push_back(tmp[i]);
}
}
if(!fl) cout<<"NO\n";
return 0;
}
|
#include<cstdio>
int main()
{
int a,b;
scanf("%d%d",&a,&b);
printf("%d %d",(a+b)/2,(a-b)/2);
} | #pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read()
{
bool flag=1;
int x=0;
char c=getchar();
while(c<'0'||c>'9')
{
if(c=='-')
flag=0;
c=getchar();
}
while(c>='0'&&c<='9')
{
x=(x<<1)+(x<<3)+c-'0';
c=getchar();
}
return (flag?x:~(x-1));
}
int n;
double d,h,ans;
signed main()
{
n=read();
cin>>d>>h;
for(int i=1;i<=n;i++)
{
double x,y;
cin>>x>>y;
ans=max(ans,y-(h-y)/(d-x)*x);
}
cout<<ans;
return 0;
}
|
#include<bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i) < (n);(i)++)
#define repsec(i,m,n) for(int (i)=(m);(i) < (n);(i)++)
#define ll long long
#define mod 998244353
#define MOD 1000000007
using namespace std;
int main(){
ll a[4];
cin >> a[0] >> a[1] >> a[2] >> a[3];
ll S = a[0] + a[1] + a[2] + a[3];
bool flag = false;
for(int mask=0;mask < 16;mask++){
ll sum = 0;
for(int i=0;i < 4;i++){
if((mask >> i)&1) sum += a[i];
}
if(S-sum == sum) flag = true;
}
if(flag) cout << "Yes" << endl;
else cout << "No" << endl;
return 0;
} | #include <iostream>
using namespace std;
int main() {
long long A, B, C, D;
cin >> A >> B >> C >> D;
long long N = A + B + C + D;
if (2 * A == N){
cout << "Yes" << endl;
}
else if (2 * B == N){
cout << "Yes" << endl;
}
else if (2 * C == N){
cout << "Yes" << endl;
}
else if (2 * D == N){
cout << "Yes" << endl;
}
else if (2 * (A + B) == N){
cout << "Yes" << endl;
}
else if (2 * (A + C) == N){
cout << "Yes" << endl;
}
else if (2 * (A + D) == N){
cout << "Yes" << endl;
}
else cout << "No" << endl;
} |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main()
{
fast_io
string s,p;
cin>>s;
p.push_back(' ');
ll n = s.length();
for(ll i=0; i<n;i++)
p.push_back(s[i]);
ll flag=0;
for(ll i=1;i<=n;i++)
{
if(i%2!=0)
{
if(isupper(p[i]))
flag =1;
}
else
{
if(islower(p[i]))
flag=1;
}
}
if(flag ==1)
cout<<"No\n";
else
cout<<"Yes\n";
} | //#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
#define FOR(i, a, b) for(ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, n) FOR(i, 0, n)
#define rFOR(i, a, b) for(ll i = (ll)(a - 1); i >= (ll)(b); i--)
#define rrep(i, a) rFOR(i, a, 0)
#define pb push_back
using namespace std;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<char> vc;
typedef vector<vc> vvc;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ld PI = acos(-1);
const ll INF = 1e18;
struct edge{ll to, cost;};
template <typename T>
bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T>
bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T;
cin >> T;
while(T--){
int N;
cin >> N;
vl A(N);
rep(i,N){
cin >> A[i];
}
sort(A.begin(),A.end());
if(N%2==1){
cout << "Second" << endl;
}
else{
bool ok=true;
rep(i,N/2){
if(A[2*i]!=A[2*i+1]){
ok=false;
}
}
cout << (ok ? "Second" : "First") << endl;
}
}
} |
#include <bits/stdc++.h>
int ri() {
int n;
scanf("%d", &n);
return n;
}
int main() {
int n = ri();
int m = ri();
int t = ri();
int last_time = 0;
int cur = n;
bool res = true;
for (int i = 0; i <= m; i++) {
int a = i < m ? ri() : t;
int b = i < m ? ri() : t;
cur -= a - last_time;
if (cur <= 0) res = false;
cur = std::min(n, cur + b - a);
last_time = b;
}
puts(res ? "Yes" : "No");
return 0;
}
| #include <iostream>
#include <algorithm>
using namespace std;
int a[100009];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int tc; cin >> tc;
for (int ti = 0; ti < tc; ti++) {
int n; cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
if (n % 2 == 1) {
cout << "Second" << '\n';
continue;
}
sort(a, a + n);
bool f = true;
for (int i = 0; i < n; i += 2)
if (a[i] != a[i + 1]) {
f = false;
break;
}
if (f) cout << "Second" << '\n';
else cout << "First" << '\n';
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pll = pair<ll, ll>;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, m, n) for(ll i = m; i > n; i--)
#define Rep(i, m, n) for(ll i = m; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define lmax(x, y) max<ll>(x, y)
#define lmin(x, y) min<ll>(x, y)
#define tmax(x, y, z) lmax((x), lmax((y), (z)))
#define tmin(x, y, z) lmin((x), lmin((y), (z)))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define ZERO(a) memset(a, 0, sizeof(a))
const ll INF = 1LL << 60;
const ll MM = 1000000000; const ll MOD = MM + 7; const ll MMM=9223372036854775807;//2^63 -1
#define ADD(a,b) a = (a + ll(b)) % MOD
#define MUL(a,b) a = (a * ll(b)) % MOD
ll GCD(ll x, ll y){ if(y == 0) return x; else return GCD(y, x % y);}
ll LCM(ll x, ll y){ return x / GCD(x, y) * y;}
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<typename A, size_t N, typename T> void FILL(A (&array)[N], const T &val){ fill( (T*)array, (T*)(array+N), val );}
// struct edge{ ll from, to, cost; };
// struct edge{ ll to, cost; };
// using Graph = vector<vector<ll>>; // 重み無し
// using Graph = vector<edge>; // 辺
// using Graph = vector<vector<edge>>; // 重み付き
ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
ll ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1}, ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
ll table[1010];
map<ll, ll> prime_factor(ll n){
map<ll, ll> res;
for(ll i=2; i*i<=n; i++){
while(n%i == 0){
++res[i];
n /= i;
}
}
if(n != 1) res[n] = 1;
return res;
}
int main(){
FILL(table, 0);
ll n; cin >> n;
rep(i, n){
ll a; cin >> a;
auto mp = prime_factor(a);
for(auto p: mp){
table[p.first] += 1;
// cout << p.first << ' ' << p.second << endl;
}
}
ll res, ans = -1;
rep(i, 1002){
// if(table[i] != 0) cout << table[i] << endl;
if(chmax(ans, table[i])) res = i;
}
cout << res << endl;
}
| #include<bits/stdc++.h>
using namespace std;
int main(){
int n,i,j;
cin>>n;
int a[n],cnt,maxm=0,ans;
for(i=0;i<n;i++){
cin>>a[i];
}
for(i=2;i<a[0];i++){
cnt=0;
for(j=0;j<n;j++){
if(a[j]%i==0){
cnt++;
}
}
if(cnt>maxm){
maxm=cnt;
ans=i;
}
}
for(i=0;i<n;i++){
cnt=0;
for(j=i;j<n;j++){
if(a[j]%a[i]==0){
cnt++;
}
}
if(cnt>maxm){
maxm=cnt;
ans=a[i];
}
}
cout<<ans<<endl;
return 0;
} |
#include <iostream>
#include <vector>
//#include <string>
//#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>
// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>
typedef long long LL;
//typedef long double LD;
//typedef pair<LL, LL> P;
using namespace std;
//using Graph = vector<vector<LL>>;
//const LL MOD=1000000007;
//const LL MOD=998244353;
//const LL MAX=100100;
//const LL NIL=-1;
//const LL INF=2000000000000000000;
//const LL SEG_VAL = 1 << 19;
int main(){
cin.tie(0);
ios::sync_with_stdio(0);
LL a;
LL b;
cin >> a >> b;
LL sum=0;
LL cur;
vector<LL> anum(a);
vector<LL> bnum(b);
if(a>=b){
for(LL i=0; i<a; i++){
anum[i]=i+1;
sum+=anum[i];
}
cur=-1;
for(LL i=0; i<b; i++){
if(i==0){
sum+=cur;
bnum[i]=cur;
}else{
if(bnum[i-1]==cur){
cur--;
}
if(sum+cur<0){
anum[a-1]-=(sum+cur);
bnum[i]=cur;
sum=0;
cur--;
}else{
bnum[i]=cur;
sum+=cur;
cur--;
}
}
if(i==b-1){
if(sum>0){
bnum[i]-=sum;
}
}
}
}else{
for(LL i=0; i<b; i++){
bnum[i]=-i-1;
sum+=bnum[i];
}
cur=1;
for(LL i=0; i<a; i++){
if(i==0){
sum+=cur;
anum[i]=cur;
}else{
if(anum[i-1]==cur){
cur++;
}
if(sum+cur>0){
bnum[a-1]-=(sum+cur);
anum[i]=cur;
sum=0;
cur++;
}else{
anum[i]=cur;
sum+=cur;
cur++;
}
}
if(i==a-1){
if(sum<0){
anum[i]-=sum;
}
}
}
}
for(LL i=0; i<a; i++){
cout << anum[i] << " ";
}
for(LL i=0; i<b; i++){
cout << bnum[i] << " ";
}
cout << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define irep(n) for (int i=0; i < (n); ++i)
#define irepf1(n) for (int i=1; i <= (n); ++i)
#define jrep(n) for (int j=0; j < (n); ++j)
#define jrepf1(n) for (int j=1; j <= (n); ++j)
#define krep(n) for (int k=0; k < (n); ++k)
#define krepf1(n) for (int k=1; k <= (n); ++k)
#define REP(i,s,e) for (int (i)=(s); (i)<(e);(i)++)
#define PI 3.14159265358979323846264338327950288
#define mod 1000000007
#define eps 0.00000001
#define Find(V,X) find(V.begin(),V.end(),X)
#define Sort(V) sort((V).begin(),(V).end())
#define Reverse(V) sort((V).begin(),(V).end()),reverse((V).begin(),(V).end())
#define Greater(V) sort((V).begin(),(V).end(),greater<int>())
//fixed << setprecision(10) <<
int main() {
int A,B;
cin >>A >>B;
vector<int> V(A+B);
ll sum=0;
int Max=max(A,B);
int Min=A+B-Max;
irepf1 (Max) {
V[i-1]=i;
sum+=i;
}
//cout<<sum<<endl;
V[A+B-1]=-1*sum;
irepf1(Min-1) {
V[i+Max-1]=-1*i;
V[A+B-1]+=i;
}
if (A>=B) {
irep (A+B-1) cout<<V[i]<<" ";
cout<<V[A+B-1]<<endl;
}
else {
irep (A+B-1) cout<<-1*V[i]<<" ";
cout<<-1*V[A+B-1]<<endl;
}
} |
/*
ID: aravcha1
TASK: gift1
LANG: C++
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using str = string;
using vi = vector<int>;
using pi = pair<int,int>;
using vpi = vector<pi>;
using si = set<int>;
#define f first
#define s second
#define sz(x) (int)(x).size()
#define pb push_back
#define all(x) begin(x), end(x)
#define sor(x) sort(all(x))
#define Trav(a,x) for (auto& a: x)
#define For(i,a,b) for (int i = (a); i < (b); ++i)
void setIO(string name = "") { // name is nonempty for USACO file I/O
ios_base::sync_with_stdio(0); cin.tie(0); // see Fast Input & Output
if(sz(name)){
freopen((name+".in").c_str(), "r", stdin); // see Input & Output
freopen((name+".out").c_str(), "w", stdout);
}
}
/*
angry cows - 2016 jan
bull in a china shop - us open 2016
field reduction - us open 2016
modern art - 2017 us open
milk measurement - 2017 dec
hoofball - 2018 feb
taming the herd - 2018 feb
milking order - 2018 us open
the bucket list - 2018 dec
back and forth - 2018 dec
sleepy cow sorting - 2019 jan
the great revegetation - 2019 feb
milk factory - 2019 us open
cow evolution - 2019 us open
race - 2020 jan
swapity swap - 2020 feb
all of us open 2020
STUCK IN A RUT - 2020 dec (oi oi oi)
DONE
~boring ~simple ~skipped blocked billboard || - 2018 jan
~boring ~simple ~skipped measuring traffic - 2019 feb
~i know too much already guess the animal - 2019 jan
*/
// rect \/\/\/\/
//{
// struct Rect {
// int x1,y1,x2,y2;
// int area() { return (y2-y1)*(x2-x1); }
// };
//
// int intersect(Rect p, Rect q){
// int xOverlap = max(0,min(p.x2,q.x2)-max(p.x1,q.x1));
// int yOverlap = max(0,min(p.y2,q.y2)-max(p.y1,q.y1));
// return xOverlap*yOverlap;
// }
//}
int main() {
//setIO("");
int n; cin >>n;
str in1;
set<string> ex, notEx;
for(int i=0; i < n;i++){
cin >> in1;
if(in1[0] == '!'){
if(notEx.count(in1.substr(1))){
cout << in1.substr(1);
return 0;
}
ex.insert(in1);
} else {
if(ex.count("!" + in1)){
cout << in1;
return 0;
}
notEx.insert(in1);
}
}
cout <<"satisfiable";
}
| #pragma GCC optimize("O2") //guess I shouldn't use this in an offline contest
#include <bits/stdc++.h> //this as well
using namespace std;
#define long long long
#define oo INT_MAX
#define OO LLONG_MAX
#define fi first
#define se second
#define el << "\n"
#define coutf(n) cout << setprecision(n) << fixed
#define mp make_pair
#define pf push_front
#define pb push_back
#define popf pop_front
#define popb pop_back
#define lb lower_bound
#define ub upper_bound
#define maxr *max_element
#define minr *min_element
#define swapr swap_ranges
#define nextp next_permutation
#define prevp prev_permutation
#define lcomp lexicographical_compare
#define pqueue priority_queue
#define uset unordered_set //c++11
#define umap unordered_map //c++11
using str = string;
using ii = pair<int, int>;
using ll = pair<long, long>;
using vi = vector<int>;
using vl = vector<long>;
using vs = vector<str>;
using vvi = vector<vi>;
using vii = vector<ii>;
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define rev(i, n) for (int i = int(n - 1); i >= 0; --i)
#define fr(x, a) for (auto x : a) //c++11
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define gcd(a, b) abs(__gcd(a, b))
#define lcm(a, b) abs(a / gcd(a, b) * b)
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
long mod(long n) {return n >= 1000000007ll ? n % 1000000007ll : n;}
const int N = 2e5 + 5, M = 2e5 + 5;
const double pi = acos(-1);
void io(string name = "") {
if (name.size()) {
freopen((name + ".in").c_str(), "r", stdin);
freopen((name + ".out").c_str(), "w", stdout);
}
else {
#ifndef ONLINE_JUDGE
freopen("i.in", "r", stdin);
freopen("o.out", "w", stdout);
freopen("e.out", "w", stderr);
#endif
} return;
}
void bruh() {
map<str, int> a;
int n; cin >> n;
rep(i, n) {
str s; cin >> s;
a[s]++;
if (s[0] == '!') { if (a[s.substr(1, s.length())]) { cout << s.substr(1, s.length()); return; } }
else if (a["!" + s]) { cout << s; return; }
}
cout << "satisfiable";
}
int main() {
ios_base::sync_with_stdio(true); cin.tie(nullptr);
io();
int t = 1;
//cin >> t; //just need to comment this lol
while (t--) {
bruh();
if (t) cout el; //case sensitive? no problem ;)
}
cerr << (double)clock() / CLOCKS_PER_SEC << " seconds bruh bruh lmao";
} |
// (: --Saurabh Mishra-- :) //
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,n) for(ll i=0;i<n;i++)
#define loopn(i,j,n) for(ll i=j;i<n;i++)
#define m_arr(arr, n) vector<ll>arr(n)
#define m_arre(arr) vector<ll>arr
#define m_set(sat) set<ll>sat
#define ppn(name) pair<ll,ll>name
#define pp pair<ll,ll>
#define sort_all(arr) sort(arr.begin(), arr.end())
#define pi 3.141592653589793238
#define mod 1000000007
#define inf 1000000000000000000
ll gcd(ll a, ll b){if(a==0)return b;if(b==0)return a;return gcd(b%a, a);}
ll power(ll a, ll b)
{
ll res=1;
while(b>0)
{
if(b%2!=0)
res = (res*1ll*a);
b/=2;
a=(a*1ll*a);
}
return res;
}
ll fact(ll n)
{
ll res=1;
while(n>1)
{
res = (res*1ll*n)%mod;
n--;
}
return res;
}
ll ncr(ll n, ll r)
{
ll num = fact(n);
ll denum = fact(n-r);
denum = (denum*1ll*fact(r))%mod;
denum = power(denum, mod-2);
num = (num * 1ll * denum)%mod;
return num;
}
void solve()
{
ll n;
cin>>n;
ll maxx = inf;
ll cnt=0;
for(int i=0;i<61;i++)
{
ll x = power(2, i);
cnt = n%x + n/x + i;
if(maxx>cnt)
maxx = cnt;
}
cout<<maxx<<endl;
return;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//ll t;cin>>t;while(t--)
solve();
return 0;
}
| #include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
char In[1 << 20], *ss = In, *tt = In;
#define getchar() (ss == tt && (tt = (ss = In) + fread(In, 1, 1 << 20, stdin), ss == tt) ? EOF : *ss++)
ll read() {
ll x = 0, f = 1; char ch = getchar();
for(; ch < '0' || ch > '9'; ch = getchar()) if(ch == '-') f = -1;
for(; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + int(ch - '0');
return x * f;
}
const ll INF = 0x3f3f3f3f3f3f3f3fll;
ll N;
ll ans;
int main() {
N = read(); ans = INF;
for(int k = 0; (1ll << k) <= N; k++)
ans = min(ans, k + (N >> k) + (N & ((1ll << k) - 1)));
printf("%lld\n", ans);
return 0;
}
|
#include <iostream>
using namespace std;
int main(void)
{
int N, W;
cin >> N >> W;
cout << N / W << endl;
} | #include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x) cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
int main(void)
{
cin.tie(0);
ios::sync_with_stdio(false);
int N, W;
cin >> N >> W;
cout << N/ W << endl;
return 0;
}
|
// #define _GLIBCXX_DEBUG
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
// #include <atcoder>
// using namespace atcoder;
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
random_device seed;
mt19937 engine(seed());
int query = 1000;
vector<ll> sp;
while (query--) {
ll si, sj, ti, tj;
cin >> si >> sj >> ti >> tj;
ll x = abs(si - ti);
ll y = abs(sj - tj);
string path;
if (si < ti) {
for (int i = 0; i < x; i++) {
path.push_back('D');
}
} else {
for (int i = 0; i < x; i++) {
path.push_back('U');
}
}
if (sj < tj) {
for (int i = 0; i < y; i++) {
path.push_back('R');
}
} else {
for (int i = 0; i < y; i++) {
path.push_back('L');
}
}
cout << path << endl;
ll shortest_path;
cin >> shortest_path;
sp.emplace_back(shortest_path);
}
return 0;
} | #include <cstdio>
#include <string>
#include <iostream>
using namespace std;
int a[107][107];
int n,m,x,y,disx[4]={0,1,0,-1},disy[4]={1,0,-1,0};
int main(){
scanf("%d%d%d%d",&n,&m,&x,&y);
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
char t;
scanf(" %c",&t);
a[i][j]=(t=='#');
}
}
int ans=0;
for (int i = 0; i < 4; ++i) {
int nx=x+disx[i],ny=y+disy[i];
while(!a[nx][ny]){
if(nx<1 || ny<1 || nx>n || ny>m) break;
ans++;
nx+=disx[i];
ny+=disy[i];
}
}
printf("%d",ans+1);
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define cs const
#define fr first
#define se second
#define ls (now<<1)
#define rs (now<<1|1)
#define mid ((l+r)>>1)
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define low(i) (i&(-i))
#define par pair<int,int>
#define cn(x) memset(x, 0, sizeof(x))
#define rep(i, x, y) for(int i=x; i<=y; ++i)
#define sep(i, x, y) for(int i=x; i>=y; --i)
#define fore(i, x) for(int i=fir[x]; i; i=nex[i])
cs int G = 3;
cs int ff = 2e6 + 1;
cs int inf = 1e18 + 1;
cs int base = 2333;
cs int M = 1e9 + 7;
int ksm(int a, int b) { return (b % 2 == 1 ? a : 1) * (b ? ksm(a * a % M, b / 2) : 1) % M; }
int x, y, a[2333][2333], b[2333][3333], l[ff], r[ff], Ans, ss;
char s;
void init()
{
cin >> x >> y;
rep(i, 1, x)
rep(j, 1, y)
cin >> s, a[i][j] = (s != '#'), ss += a[i][j];
rep(i, 1, x)
{
int las = 0, s = 0;
rep(j, 1, y)
{
if(a[i][j]) b[i][j] += s, s ++;
else s = 0;
}
s = 0;
sep(j, y, 1)
{
if(a[i][j]) b[i][j] += s, s ++;
else s = 0;
}
}
// rep(i, 1, x) rep(j, 1, y) cout <<b[i][j] << " "; cout << "\n";
rep(i, 1, y)
{
int las = 0, s = 0;
rep(j, 1, x)
{
// cout << j << " " << i << " " <<s << "\n";
if(a[j][i]) b[j][i] += s, s ++;
else s = 0;
//
}
s = 0;
sep(j, x, 1)
{
if(a[j][i]) b[j][i] += s, s ++;
else s = 0;
// cout <<b[j][i] << "\n";
}
}
rep(i, 1, x)
rep(j, 1, y)
{
if(!a[i][j]) continue;
// cout <<b[i][j] << " ";
int sum = b[i][j] + a[i][j];
// cout << sum <<"\n";
Ans = Ans + ksm(2, ss) - ksm(2, ss - sum);
Ans = (Ans % M + M) % M;
}
cout << Ans;
}
signed main()
{
// freopen("1.out", "w", stdout);
int Ts = 1;
// cin >> Ts;
while(Ts--)
init();
}
| #include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ff first
#define ss second
typedef long long ll;
ll power(ll a, ll b){//a^b
ll res=1;
a=a%MOD;
while(b>0){
if(b&1){res=(res*a)%MOD;b--;}
a=(a*a)%MOD;
b>>=1;
}
return res;
}
ll fermat_inv(ll y){return power(y,MOD-2);}
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
ll calc[4000001];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t=1;
calc[0]=1ll;
for(int i=1;i<=4000000;i++)
calc[i]=(calc[i-1]*2ll)%MOD;
//cin>>t;
while(t--){
int h,w;
cin>>h>>w;
string s[h];
for(int i=0;i<h;i++)
cin>>s[i];
int k=0;
int dp[h][w];
int dp1[h][w];
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
if(s[i][j]=='.'){
int l=j;
while(l<w&&s[i][l]=='.')
l++;
for(int p=j;p<l;p++)
dp[i][p]=l-j;
k+=l-j;
j=l-1;
}
}
}
for(int j=0;j<w;j++){
for(int i=0;i<h;i++){
if(s[i][j]=='.'){
int l=i;
while(l<h&&s[l][j]=='.')
l++;
for(int p=i;p<l;p++)
dp1[p][j]=l-i;
i=l-1;
}
}
}
ll ans=0ll;
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
if(s[i][j]=='.'){
int val=dp[i][j]+dp1[i][j]-1;
ans=(ans+((calc[k]-calc[k-val]+MOD)%MOD))%MOD;
}
}
}
cout<<ans<<"\n";
}
return 0;
} |
#include<bits/stdc++.h>
//#include<atcoder/all>
using namespace std;
//using namespace atcoder;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rrep(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr ll INF = (ll)1e9;
constexpr ll mod = (ll)1e9 + 7;
constexpr double PI = 3.1415926535897932;
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;
}
inline void init() {
cin.tie(nullptr); cout.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
}
int main() {
init();
int N; cin >> N;
vector<ll>x(N);
rep(i, 0, N)cin >> x[i];
ll ans = 0;
rep(i, 0, N) {
ans += abs(x[i]);
}
cout << ans << "\n";
ans = 0;
rep(i, 0, N) {
ans += abs(x[i]) * abs(x[i]);
}
cout << sqrt(ans) << "\n";
ans = 0;
rep(i, 0, N)chmax(ans, abs(x[i]));
cout << ans << "\n";
return 0;
} | #pragma GCC optimize(3)
#include <bits/stdc++.h>
#define debug(x) cout<<#x<<":"<<x<<endl;
#define dl(x) printf("%lld\n",x);
#define di(x) printf("%d\n",x);
#define _CRT_SECURE_NO_WARNINGS
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef vector<int> VI;
const int INF = 0x3f3f3f3f;
const int N = 2e5 + 10;
const ll mod = 1000000007;
const double eps = 1e-9;
const double PI = acos(-1);
template<typename T>inline void read(T &a) {
char c = getchar(); T x = 0, f = 1; while (!isdigit(c)) {if (c == '-')f = -1; c = getchar();}
while (isdigit(c)) {x = (x << 1) + (x << 3) + c - '0'; c = getchar();} a = f * x;
}
int gcd(int a, int b) {return (b > 0) ? gcd(b, a % b) : a;}
map<char,char> M;
int main() {
M['9'] = '6';
M['6'] = '9';
char str[N];
cin >> str;
for(int i = strlen(str) - 1;i >= 0;i--){
if(str[i] == '6' || str[i] == '9') str[i] = M[str[i]];
cout << str[i];
}
return 0;
}
/**
* ┏┓ ┏┓+ +
* ┏┛┻━━━┛┻┓ + +
* ┃ ┃
* ┃ ━ ┃ ++ + + +
* ████━████+
* ◥██◤ ◥██◤ +
* ┃ ┻ ┃
* ┃ ┃ + +
* ┗━┓ ┏━┛
* ┃ ┃ + + + +Code is far away from
* ┃ ┃ + bug with the animal protecting
* ┃ ┗━━━┓ 神兽保佑,代码无bug
* ┃ ┣┓
* ┃ ┏┛
* ┗┓┓┏━┳┓┏┛ + + + +
* ┃┫┫ ┃┫┫
* ┗┻┛ ┗┻┛+ + + +
*/
|
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif
#define sz(x) ((int) (x).size())
#define TASK "text"
const int inf = (int) 1.01e9;
const long long infll = (long long) 1.01e18;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);
#ifdef DEBUG
mt19937 mrand(300);
#else
mt19937 mrand(chrono::steady_clock::now().time_since_epoch().count());
#endif
int rnd(int x) {
return mrand() % x;
}
void precalc() {
}
const int maxn = (int) 4e5 + 5;
int n;
int a[maxn];
bool read() {
if (scanf("%d", &n) < 1) {
return false;
}
for (int i = 0; i < 2 * n; ++i) {
scanf("%d", &a[i]);
}
return true;
}
priority_queue<int> pq;
void solve() {
while (!pq.empty()) {
pq.pop();
}
long long res = 0;
for (int i = 0; i < n; ++i) {
pq.push(a[i]);
pq.push(a[2 * n - 1 - i]);
res += pq.top();
pq.pop();
}
printf("%lld\n", res);
}
int main() {
precalc();
#ifdef DEBUG
assert(freopen(TASK ".in", "r", stdin));
assert(freopen(TASK ".out", "w", stdout));
#endif
while (read()) {
solve();
#ifdef DEBUG
eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
}
return 0;
}
| #include<bits/stdc++.h>
#define int long long
#define N 400015
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n;i>=a;i--)
#define inf 0x3f3f3f3f
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define fi first
#define se second
#define lowbit(i) ((i)&(-i))
#define VI vector<int>
#define all(x) x.begin(),x.end()
#define SZ(x) ((int)x.size())
using namespace std;
int n,a[N],ans;
multiset<int> S;
signed main(){
// freopen("53B.in","r",stdin);
// freopen("mine.out","w",stdout);
scanf("%lld",&n);
rep(i,1,2*n) scanf("%lld",&a[i]);
rep(i,1,n){
S.insert(-a[i]); S.insert(-a[2*n-i+1]);
// printf("%d\n",*S.begin());
ans += *S.begin(); S.erase(S.begin());
}
printf("%lld\n", -ans);
return 0;
}
/*
4
1 2 3 4 4 3 2 1
*/ |
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
long long int a[n],b[n];
long long int l[n];
for(int i=0;i<n;i++)
{
cin>>a[i];
}
for(int i=0;i<n;i++)
{
cin>>b[i];
}
int maxa[n],maxb[n];
maxa[0] = a[0];
maxb[0] = b[0];
for(int i=1;i<n;i++)
{
maxa[i] = maxa[i-1];
if(a[i]>maxa[i])
{
maxa[i] = a[i];
}
}
l[0] = a[0]*b[0];
for(int i=1;i<n;i++)
{
l[i] = l[i-1];
if(maxa[i] * b[i] > l[i-1])
{
l[i] = maxa[i] * b[i];
}
}
for(int i=0;i<n;i++)
{
cout<<l[i]<<endl;
}
}
| #include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
#ifdef TEST
chrono::system_clock::time_point start, end;
start = chrono::system_clock::now();
#endif
long N;
cin >> N;
vector<ll> x(N);
for(size_t i=0;i<N; i++)
{
cin >> x[i];
}
ll ans_a=0;
double ans_b=0;
ll ans_c = 0;
for(size_t i=0;i<N; i++)
{
ans_a+=abs(x[i]);
ans_b += x[i]*x[i];
ans_c = max(ans_c, abs(x[i]));
}
cout << ans_a << endl;
cout << fixed << setprecision(10) << sqrt(ans_b) << endl;
cout << ans_c << endl;
#ifdef TEST
end = chrono::system_clock::now();
cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int, int>pi;
typedef pair<long long, long long>pl;
#define F first
#define S second
#define pb push_back
#define all(x) x.begin() , x.end()
#define mod 1000000007
#define FOR(i,a,b) for(i=a;i<=b;i++)
#define mem(a) memset(a , 0 ,sizeof a)
#define memn(a) memset(a , -1 ,sizeof a)
vector<int>g[10003];
int main()
{
int t = 1, fac = 1;
// scanf("%d", &t);
while (t--)
{
int n,i,x,y,j,f=0;
string s;
cin>>n>>s;
if(s[0]!=s[n-1]) cout<<"1"<<endl;
else {
for(i=1;i<n-1;i++)
{
if(s[0]!=s[i]&&s[i+1]!=s[n-1])
{
f=1;
}
}
if(f) cout<<"2"<<endl;
else cout<<"-1"<<endl;
}
}
} | #include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define fill0(a) memset(a,0,sizeof(a))
#define fill1(a) memset(a,-1,sizeof(a))
#define fillbig(a) memset(a,63,sizeof(a))
#define pb push_back
#define ppb pop_back
#define mp make_pair
template<typename T1,typename T2> void chkmin(T1 &x,T2 y){if(x>y) x=y;}
template<typename T1,typename T2> void chkmax(T1 &x,T2 y){if(x<y) x=y;}
typedef pair<int,int> pii;
typedef long long ll;
typedef unsigned int u32;
typedef unsigned long long u64;
namespace fastio{
#define FILE_SIZE 1<<23
char rbuf[FILE_SIZE],*p1=rbuf,*p2=rbuf,wbuf[FILE_SIZE],*p3=wbuf;
inline char getc(){return p1==p2&&(p2=(p1=rbuf)+fread(rbuf,1,FILE_SIZE,stdin),p1==p2)?-1:*p1++;}
inline void putc(char x){(*p3++=x);}
template<typename T> void read(T &x){
x=0;char c=getchar();T neg=0;
while(!isdigit(c)) neg|=!(c^'-'),c=getchar();
while(isdigit(c)) x=(x<<3)+(x<<1)+(c^48),c=getchar();
if(neg) x=(~x)+1;
}
template<typename T> void recursive_print(T x){if(!x) return;recursive_print(x/10);putc(x%10^48);}
template<typename T> void print(T x){if(!x) putc('0');if(x<0) putc('-'),x=~x+1;recursive_print(x);}
void print_final(){fwrite(wbuf,1,p3-wbuf,stdout);}
}
const int MAXN=1e5;
int n;char s[MAXN+5];
int main(){
scanf("%d%s",&n,s+1);
if(s[1]^s[n]) return puts("1")&0;
for(int i=1;i<n;i++) if((s[1]^s[i])&&(s[i+1]^s[n]))
return puts("2")&0;
puts("-1");
return 0;
} |
#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> P;
int main()
{
int N;
cin >> N;
vector<pair<int, string> > vec;
rep(i,N)
{
string s;
int t;
cin >> s >> t;
vec.push_back(make_pair(t,s));
}
sort(vec.begin(), vec.end());
reverse(vec.begin(), vec.end());
cout << vec[1].second << endl;
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>;
int main() {
int n;
cin >> n;
vector<int> a(n);
int maxA=0;
rep (i,n) {
cin >> a[i];
maxA=max(maxA,a[i]);
}
// 与えられたai から最大の 積和を作る
// 以下で(l,r) は全てなめている。
ll maxAns = 0;
rep(l,n) {
int x = a[l]; // <- ここと
for(int r=l;r<n;r++) {
x = min(x,a[r]);// <- ここが不安なのはなぜか?
// (l,r)区間内の最小のai を求める-> tle に成るここで工夫が必要
// for (int i=l;i<=r;i++){
// minA = min(minA,a[i]);
// }
ll ans = (r - l + 1)*x;
maxAns = max(maxAns, ans);
}
}
cout << maxAns << endl;
return 0;
}
|
#include<bits/stdc++.h>
#define mod ((long)(1e9+7))
using namespace std;
int main(int argc, char const *argcv[])
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int h,w;
cin>>h;
cin>>w;
string s[h];
for(int i=0;i<h;i++)
cin>>s[i];
int g[h+1][w+1];
int u[h+1][w+1];
int l[h+1][w+1];
int d[h+1][w+1];
int r[h+1][w+1];
long p2[h*w+4];
p2[0]=1;
for(int i=1;i<(h*w+4);i++)
p2[i]=(p2[i-1]*2ll)%mod;
int k=0;
for(int i=0;i<h;i++)
for(int j=0;j<w;j++)
{
u[i][j]=0;
l[i][j]=0;
g[i][j]=0;
if(s[i][j]=='.')
{
g[i][j]=1;
k++;
if(i>0)
u[i][j]+=u[i-1][j];
if(j>0)
l[i][j]+=l[i][j-1];
u[i][j]++;
l[i][j]++;
}
}
long long ans=0;
for(int i=h-1;i>=0;i--)
for(int j=w-1;j>=0;j--)
{
d[i][j]=0;
r[i][j]=0;
if(g[i][j]==1)
{
if(i+1<h)
d[i][j]+=d[i+1][j];
if(j+1<w)
r[i][j]+=r[i][j+1];
d[i][j]++;
r[i][j]++;
int cnum=0;
cnum=cnum+u[i][j];
cnum=cnum+l[i][j];
cnum=cnum+r[i][j];
cnum=cnum+d[i][j];
cnum=cnum-3;
if(k-cnum<0)
cout<<"Wrong"<<endl;
ans=(ans+(p2[k]*1ll+mod*1ll-p2[k-cnum]*1ll)%mod)%mod;
}
}
cout<<ans<<endl;
} | #include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repp(i, n, m) for(int (i) = (n); (i) < (m); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define ldou long double
#define fi first
#define se second
#define setpre(x) std::cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)
inline void logger(){ std::cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
cout << a << " , "; logger(b...);
}
typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 100005;
/* ...o(^-^)o... */
const lint mod = MOD;
class mint{
public:
long long x;
constexpr mint(long long _x = 0) : x((_x%mod+mod)%mod) {}
constexpr mint operator-() const{
return mint(-x);
}
constexpr mint& operator+=(const mint& a){
if((x += a.x) >= mod) x -= mod;
return *this;
}
constexpr mint& operator-=(const mint& a){
if((x += mod-a.x) >= mod) x -= mod;
return *this;
}
constexpr mint& operator*=(const mint& a){
(x *= a.x) %= mod;
return *this;
}
constexpr mint operator+(const mint& a) const{
mint res(*this);
return res+=a;
}
constexpr mint operator-(const mint& a) const{
mint res(*this);
return res-=a;
}
constexpr mint operator*(const mint& a) const{
mint res(*this);
return res*=a;
}
constexpr mint pow(long long x) const{
if(!x) return 1;
mint a = pow(x>>1);
a *= a;
if(x&1) a *= *this;
return a;
}
constexpr mint inv() const{
return pow(mod-2);
}
constexpr mint& operator/=(const mint& a){
return (*this) *= a.inv();
}
constexpr mint operator/(const mint& a) const{
mint res(*this);
return res/=a;
}
friend istream& operator>>(istream& is, mint& m){
long long x; is >> x; m = x;
return is;
}
friend ostream& operator<<(ostream& os, const mint& m){
os << m.x; return os;
}
};
int main(){
int h, w; cin >> h >> w;
vector<string> s(h);
rep(i, h) cin >> s[i];
vector<vector<int>> hor(h, vector<int>(w, 1)), ver(h, vector<int>(w, 1));
rep(i, h){
rep(j, w){
if(j == 0 || s[i][j] == '#') continue;
if(s[i][j-1] == '.') hor[i][j] = hor[i][j-1] + 1;
}
repr(j, w){
if(j == w-1 || s[i][j] == '#') continue;
if(s[i][j+1] == '.') hor[i][j] = hor[i][j+1];
}
}
rep(j, w){
rep(i, h){
if(i == 0 || s[i][j] == '#') continue;
if(s[i-1][j] == '.') ver[i][j] = ver[i-1][j] + 1;
}
repr(i, h){
if(i == h-1 || s[i][j] == '#') continue;
if(s[i+1][j] == '.') ver[i][j] = ver[i+1][j];
}
}
vector<vector<int>> p(h, vector<int>(w));
lint k = 0;
rep(i, h) rep(j, w){
if(s[i][j] == '#') continue;
p[i][j] = hor[i][j] + ver[i][j] - 1;
k += 1;
}
mint ans = mint(2).pow(k) * k;
rep(i, h) rep(j, w){
if(s[i][j] == '#') continue;
ans -= mint(2).pow(k - p[i][j]);
}
out(ans);
} |
#include <bits/stdc++.h>
using namespace std;
int main()
{
char a, b, c;
cin >> a >> b >> c;
if(a != b)
{
cout << "Lost" << endl;
return 0;
}
if(a != c)
{
cout << "Lost" << endl;
return 0;
}
if(b != c)
{
cout << "Lost" << endl;
return 0;
}
cout << "Won" << endl;
return 0;
} | //In the name of Almighty Allah
//Alhamdulillah
#include<bits/stdc++.h>
using namespace std ;
int main ()
{
string s;
cin >> s;
if(s[0]==s[1] && s[1]==s[2])
{
cout << "Won\n";
}
else
{
cout << "Lost\n";
}
return 0;
} |
#include <bits/stdc++.h>
#define ll long long
#define ALL(x) x.begin(),x.end()
#define MOD (1000000000+7)
using namespace std;
#define PI 3.14159265359
#define tMOD 998244353
#define mkpr(x,y) make_pair(x,y)
int main(){
ll H,W,N,M;
cin>>H>>W>>N>>M;
ll grid[1501][1501]={0};
ll tmp,tmp1;
for(ll i=0;i<N;i++){
cin>>tmp>>tmp1;
tmp--;tmp1--;
grid[tmp][tmp1]=1;
}
for(ll i=0;i<M;i++){
cin>>tmp>>tmp1;
tmp--;tmp1--;
grid[tmp][tmp1]=2;
}
//h,w
ll ans=0;
for(ll h=0;h<H;h++){
for(ll w=0;w<W;w++){
ll tmp=0;ll nh=h,nw=w;
//(h,w)
//ue
nh=h,nw=w;
for(ll i=h;i>=0;i--){
if(grid[i][nw]==1){
tmp++;
break;
}
else if(grid[i][nw]==2){
break;
}
}
//sita
nh=h,nw=w;
for(ll i=h;i<H;i++){
if(grid[i][nw]==1){
tmp++;
break;
}
else if(grid[i][nw]==2){
break;
}
}
//hidari
nh=h,nw=w;
for(ll i=w;i>=0;i--){
if(grid[nh][i]==1){
tmp++;
break;
}
else if(grid[nh][i]==2){
break;
}
}
//migi
nh=h,nw=w;
for(ll i=w;i<W;i++){
if(grid[nh][i]==1){
tmp++;
break;
}
else if(grid[nh][i]==2){
break;
}
}
if(tmp>0){
ans++;
}
}
}
cout<<ans<<endl;
}
| #include <bits/stdc++.h>
using namespace std;
char str[4][30],q[20];
int cnt;
int mymap[30];
bool st[30];
bool jdg[20];
long long temp[10];
bool dfs(int s){
if(s>cnt){
for(int i=1;i<=3;i++){
if(mymap[str[i][1]-'a']==0) return false;
}
temp[1]=temp[2]=temp[3]=0;
for(int i=1;i<=3;i++){
for(int j=1;str[i][j];j++){
temp[i]=temp[i]*10+mymap[str[i][j]-'a'];
}
}
return temp[1]+temp[2]==temp[3];
}
for(int i=0;i<=9;i++){
if(!jdg[i]){
mymap[q[s]-'a']=i;
jdg[i]=true;
if(dfs(s+1)) return true;
jdg[i]=false;
}
}
return false;
}
int main(){
for(int i=1;i<=3;i++) scanf("%s",str[i]+1);
for(int i=1;i<=3;i++){
for(int j=1;str[i][j];j++){
if(!st[str[i][j]-'a']){
st[str[i][j]-'a']=true;
q[++cnt]=str[i][j];
}
}
}
if(cnt>10) puts("UNSOLVABLE");
else{
if(dfs(1)){
for(int i=1;i<=3;i++) cout<<temp[i]<<endl;
}
else puts("UNSOLVABLE");
}
return 0;
} |
#include <bits/stdc++.h>
#ifdef LOCAL
#include "C:\Users\15328\Desktop\isaunoya.hpp"
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
using namespace std;
long long fib[100];
bool book[100];
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
fib[0] = 1;
fib[1] = 1;
for (int i = 2; i < 87; i++) {
fib[i] = fib[i - 1] + fib[i - 2];
}
long long n;
cin >> n;
for (int i = 86; i >= 0; i--) {
if (n >= fib[i]) {
n -= fib[i];
book[i] = true;
}
}
vector<int> ans;
for (int i = 0; i < 87; i++) {
if (i % 2 == 0) {
if (book[i]) {
ans.emplace_back(1);
}
ans.emplace_back(3);
} else {
if (book[i]) {
ans.emplace_back(2);
}
ans.emplace_back(4);
}
}
reverse(begin(ans), end(ans));
cout << ans.size() << "\n";
for (int i = 0; i < int(ans.size()); i++) {
cout << ans[i] << "\n";
}
}
| #include <bits/stdc++.h>
#define FASTIO
using namespace std;
using ll = long long;
using Vi = std::vector<int>;
using Vl = std::vector<ll>;
using Pii = std::pair<int, int>;
using Pll = std::pair<ll, ll>;
constexpr int I_INF = std::numeric_limits<int>::max();
constexpr ll L_INF = std::numeric_limits<ll>::max();
template <typename T1, typename T2>
inline bool chmin(T1& a, const T2& b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <typename T1, typename T2>
inline bool chmax(T1& a, const T2& b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <std::ostream& os = std::cout>
class Prints {
private:
class __Prints {
public:
__Prints(const char* sep, const char* term) : sep(sep), term(term) {}
template <class... Args>
#if __cplusplus >= 201703L
auto operator()(const Args&... args) const -> decltype((os << ... << std::declval<Args>()), void()) {
#else
void operator()(const Args&... args) const {
#endif
print(args...);
}
template <typename T>
#if __cplusplus >= 201703L
auto pvec(const T& vec, size_t sz) const -> decltype(os << std::declval<decltype(std::declval<T>()[0])>(), void()) {
#else
void pvec(const T& vec, size_t sz) const {
#endif
for (size_t i = 0; i < sz; i++)
os << vec[i] << (i == sz - 1 ? term : sep);
}
template <typename T>
#if __cplusplus >= 201703L
auto pmat(const T& mat, size_t h, size_t w) const -> decltype(os << std::declval<decltype(std::declval<T>()[0][0])>(), void()) {
#else
void pmat(const T& mat, size_t h, size_t w) const {
#endif
for (size_t i = 0; i < h; i++)
for (size_t j = 0; j < w; j++)
os << mat[i][j] << (j == w - 1 ? term : sep);
}
private:
const char *sep, *term;
void print() const { os << term; }
void print_rest() const { os << term; }
template <class T, class... Tail>
void print(const T& head, const Tail&... tail) const { os << head, print_rest(tail...); }
template <class T, class... Tail>
void print_rest(const T& head, const Tail&... tail) const { os << sep << head, print_rest(tail...); }
};
public:
Prints() {}
__Prints operator()(const char* sep = " ", const char* term = "\n") const { return __Prints(sep, term); }
};
Prints<> prints;
Prints<std::cerr> prints_err;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void solve() {
ll N;
cin >> N;
Vl fib;
fib.emplace_back(1);
fib.emplace_back(1);
while (true) {
ll sz = (ll)fib.size();
ll t = fib[sz - 1] + fib[sz - 2];
if (t <= N) {
fib.emplace_back(t);
} else {
break;
}
}
ll sz = (ll)fib.size();
Vi ans;
for (ll i = 0; i < sz; i++) {
if ((sz - 1 - i) % 2 == 0) {
if (N >= fib[sz - 1 - i]) {
ans.emplace_back(1);
N -= fib[sz - 1 - i];
}
ans.emplace_back(4);
} else {
if (N >= fib[sz - 1 - i]) {
ans.emplace_back(2);
N -= fib[sz - 1 - i];
}
ans.emplace_back(3);
}
}
prints()(ans.size());
for (auto x : ans) {
prints()(x);
}
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
int main() {
#ifdef FASTIO
std::cin.tie(nullptr), std::cout.tie(nullptr);
std::ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
std::ifstream ifs("./in_out/input.txt");
std::cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
std::ofstream ofs("./in_out/output.txt");
std::cout.rdbuf(ofs.rdbuf());
#endif
std::cout << std::setprecision(18) << std::fixed;
solve();
std::cout << std::flush;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
double D,H;
cin >> N >> D >> H;
double ans=0;
for(int i=0;i<N;i++){
double d,h;
cin >> d >> h;
ans=max(ans,(H-(H-h)*D/(D-d)));
}
cout << ans <<endl;
} | #include <bits/stdc++.h>
using namespace std;
int main(){
double x, y, z;
cin >> x >> y >> z;
double a = y / x;
for(int i = 0;;i++){
if(a <= (double)i / z){
cout << i - 1;
break;
}
}
return 0;
} |
#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define mod 1000000007
#define pb push_back
using namespace std;
ll ans,n,m;
map<ll,ll> vis,dp;
ll recur(ll x)
{
if(vis[x]) return dp[x];
vis[x]=1;
dp[x]=abs(x-n);
if(x==n) {return dp[x];}
if(x%2==0) dp[x]=min(dp[x],1+recur(x/2));
else
{
dp[x]=min({dp[x],1+recur(x-1),1+recur(x+1)});
}
return dp[x];
}
void solve()
{
cin>>n>>m;
ans=abs(n-m);
//cout<<ans<<" ";
cout<<recur(m);
}
int main()
{
ll t=1;
// cin>>t;
while(t--)
solve();
}
| #include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define endl "\n"
#define all(v) v.begin(),v.end()
#define double long double
#define trace1(x) cerr<<#x<<": "<<x<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e) cerr<<#a<<": "<<a<<" | "<<#b<< ": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define cases int testcases;cin>>testcases; while(testcases--)
const int N = 200005;
#define rep(i, x, y) for (__typeof(x) i = x; i <= y; i ++)
#define repi(i, x, y) for (__typeof(x) i = x; i >= y; i --)
int x;
map<int,int> dp;
int rec(int curr)
{
if(curr <= x)return x-curr;
if(dp.find(curr) != dp.end())return dp[curr];
int ans = curr-x;
if(curr%2 == 0)
{
if(curr/2 > x)ans = min(ans,1 + rec(curr/2));
else ans = min(ans, 1 + x - curr/2);
}
else if(curr + 1 == x or curr - 1 == x)return 1;
else
{
ans = min({ans,2 + rec((curr+1)/2),2 + rec((curr-1)/2)});
}
return dp[curr] = ans;
}
int32_t main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
IOS
int y;
cin >> x >> y;
cout << rec(y);
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>;
using Graph = vector<vector<int>>;
template<class T> void chmax(T& a, T b){
if(a < b){
a = b;
}
}
template<class T> void chmin(T& a, T b){
if(a > b){
a = b;
}
}
int main()
{
int n;
cin >> n;
cout << n-1 << endl;
return 0;
} | //𝓬𝓮𝓭𝓮𝓼𝓲𝓸𝓷😎
#include<bits/stdc++.h>
using namespace std;
/*--------------------------*defines*-----------------------------*/
#define endl "\n"
#define int long long
#define mp make_pair
#define pb push_back
#define vi vector<int>
#define cedesion signed main
#define inf INT_MAX
#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 all(v) v.begin(),v.end()
#define dall(v) v.begin(),v.end(),greater<int>()
/*--------------------------*defines*-----------------------------*/
/*--------------------------*functions*---------------------------*/
bool perfectSquare(long double x){
long double sr = sqrt(x);return ((sr - floor(sr)) == 0);
}
long long modexp(long long n,long long p,long long c){
if(p == 0)return 1;
long long ans = 1;
if(p%2)ans = n%c;
return ((ans)*(modexp((n*n)%c,p/2,c)%c))%c;
}
/*--------------------------*functions*---------------------------*/
/*------------------------*work space*----------------------------*/
void test_case()
{
int n;
cin>>n;
cout<<n-1<<endl;
}
cedesion()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//#ifndef ONLINE_JUDGE
//for getting input from input.txt
//freopen("input.txt", "r", stdin);
//for writing output in output.txt
//freopen("output.txt", "w", stdout);
//#endif
int t=1;
// cin>>t;
while(t--)
{
test_case();
}
return 0;
} |
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (ll)(n); i++)
#define rrep(i,a,b) for (ll i = (a); i < (ll)(b); i++)
#define rng(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define fr first
#define sc second
using namespace std;
template <class T, class S> inline bool chmax(T &a, const S &b) { return (a < b ? a = b, 1 : 0); }
template <class T, class S> inline bool chmin(T &a, const S &b) { return (a > b ? a = b, 1 : 0); }
template <class T> using vc = vector<T>;
template <class T> using vv = vc<vc<T>>;
template <class T> using vvv = vc<vv<T>>;
template <class T> using PQ = priority_queue<T, vc<T>, greater<T>>;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;
using ti3 = tuple<int, int, int>;
using tl3 = tuple<ll, ll, ll>;
using vi = vc<int>;
using vl = vc<ll>;
using vvi = vv<int>;
using vvl = vv<ll>;
const ld pi = 3.141592653589793;
const ll linf = 1001001001001001001LL;
const int inf = 1001001001;
int main() {
vc<string> s(3);
rep(i,3) cin >> s[i];
set<char> st;
rep(i,3)rep(j,s[i].size()) st.insert(s[i][j]);
if (st.size() > 10) {
cout << "UNSOLVABLE" << endl;
return 0;
}
int m = st.size();
vc<char> mp(10, '.');
int idx = 0;
for (auto c : st) mp[idx++] = c;
vi imp(26, -1);
rep(i,10) if (mp[i] != '.') imp[mp[i]-'a'] = i;
vi ord(10);
rep(i,10) ord[i] = i;
do {
vc<string> t(3);
rep(i,3) {
rep(j,s[i].size()) {
t[i].pb((char)(ord[imp[s[i][j]-'a']]+'0'));
}
}
bool ok = true;
rep(i,3) if (t[i][0] == '0') ok = false;
if (!ok) continue;
vl N(3);
rep(i,3) N[i] = stoll(t[i]);
if (N[0]+N[1] == N[2]) {
rep(i,3) cout << N[i] << endl;
return 0;
}
} while (next_permutation(rng(ord)));
cout << "UNSOLVABLE" << endl;
} | #include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define si(v) int(v.size())
#define len(v) int(v.length())
#define lob(v,n) lower_bound(all(v),n)
#define lobi(v,n) lower_bound(all(v),n) - v.begin()
#define upb(v,n) upper_bound(all(v),n)
#define upbi(v,n) upper_bound(all(v),n) - v.begin()
#define mod 1000000007
#define infi 1010000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin >> N;
vi A(N),B(N),Q(N);
in(N,A);
in(N,B);
in(N,Q);
ve<int> hab(N);
rep(i,N) Q[i]--, hab[Q[i]] = i;
pq2<pii> que;
rep(i,N) que.push({B[i],i});
int f = 1;
ve<pii> ans;
//outve(Q);
rep(i,N){
pii q = que.top();
que.pop();
int who = hab[q.se];
if(q.se == who) continue;
if(A[who] <= q.fi){
f = 0;
break;
}
int swapwho = q.se;
if(A[swapwho] <= B[Q[swapwho]]){
f = 0;
break;
}
ans.pb({who+1, swapwho+1});
swap(hab[Q[who]], hab[Q[swapwho]]);
swap(Q[who], Q[swapwho]);
//outve(Q);
}
if(f == 0) cout << -1 << endl;
else{
cout << si(ans) << endl;
rep(i,si(ans)) cout << ans[i].fi csp ans[i].se << endl;
}
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fr(i,n) for(int i=0;i<n;i++)
#define fro(i,j,n) for(int i=j;i<n;i++)
#define ifr(i,n) for(int i=n-1;i>=0;i--)
char change(char x,char y){
char list[3]={'R','W','B'};
if(x==y)return x;
else{
fr(i,3){
if(x!=list[i]&&y!=list[i]) return list[i];
}
}
}
int main() {
int n;
cin >> n;
string c;
cin >> c;
int a=1;
while(a<n-1){
a*=3;
}
while(n>1){
while(a>n-1){a/=3;}
fr(i,n-a){
c[i]=change(c[i],c[i+a]);
}
n-=a;
}
cout << c[0] << endl;
} | #include<bits/stdc++.h>
#define REP(i,b,e) for(int i=b; i<e; i++)
struct binom_mod3 {
std::vector<int> quo, rem;
binom_mod3(int n): quo(n), rem(n) {
quo[0] = 0;
rem[0] = 1;
for(int i=1; i<n; i++){
int m = i, cnt = 0;
while(m%3==0){
m /= 3;
cnt++;
}
quo[i] = quo[i-1] + cnt;
rem[i] = rem[i-1] * m % 3;
}
}
int eval(int n, int k){
assert(n < quo.size());
if(n<0 || k<0 || n<k) return 0;
if(quo[n] > quo[k] + quo[n-k]) return 0;
int num = rem[n], den = rem[k] * rem[n-k] % 3;
return num * den % 3;
}
};
int main(){
int n;
scanf("%d", &n);
getchar();
binom_mod3 bi3(5e5);
int m = 0;
REP(i, 0, n){
char c = getchar();
int a = (c=='B')? 0: (c=='W')? 1:2;
m += a * bi3.eval(n-1, i) % 3;
m %= 3;
}
if(n%2==0) m = (3 - m) % 3;
printf("%c\n", "BWR"[m%3]);
return 0;
}
|
#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 req(i,n) for(int i = 1;i <=n;i++)
#define pai 3.14159265358979323846
const long long INF = 1e18;;
typedef long long ll;
bool punched[3][3];
//using Graph = vector<vector<int> >;
const int MOD = 1000000007;
typedef pair<int,int> P;
//最大公約数
ll gcd(ll a,ll b){
if (a%b == 0){
return b;
}
else{
return gcd(b,a%b);
}
}
//最小公倍数
ll lcm(ll a,ll b){
return a /gcd(a,b) * b;
}
//素数判定
bool is_prime(long long N) {
if (N == 1) return false;
for (long long i = 2; i * i <= N; ++i) {
if (N % i == 0) return false;
}
return true;
}
// 素因数分解
vector<pair<long long, long long> > prime_factorize(long long n) {
vector<pair<long long, long long> > res;
for (long long p = 2; p * p <= n; ++p) {
if (n % p != 0) continue;
int num = 0;
while (n % p == 0) { ++num; n /= p; }
res.push_back(make_pair(p, num));
}
if (n != 1) res.push_back(make_pair(n, 1));
return res;
}
// 10進数から2進数
int binary(int bina){
int ans = 0;
for (int i = 0; bina>0 ; i++)
{
ans = ans+(bina%2)*pow(10,i);
bina = bina/2;
}
return ans;
}
//Union-Find
struct UnionFind {
vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2
UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
for(int i = 0; i < N; i++) par[i] = i;
}
int root(int x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根}
if (par[x] == x) return x;
return par[x] = root(par[x]);
}
void unite(int x, int y) { // xとyの木を併合
int rx = root(x); //xの根をrx
int ry = root(y); //yの根をry
if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける
}
bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
int rx = root(x);
int ry = root(y);
return rx == ry;
}
};
bool ok(int v, int b) {
while (v) {
if (v % b == 7) return false;
v /= b;
}
return true;
}
struct zahyou{
int h;
int w;
};
ll digit(ll x) {
ll cnt = 0;
while(x > 0) {
x /= 10;
cnt++;
}
return cnt;
}
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
int main(){
int x,y;
cin >> x >>y;
if (x == y) cout << x << endl;
else cout << 3 - x - y << endl;
}
| #include <bits/stdc++.h>
#define nl "\n"
#define ll long long
#define vii(N,M,x) vector<vector<long long>> x(N,vector<long long>(M))
#define pb push_back
#define ii pair<int,int>
#define ft first
#define sd second
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
const int INF=1e9+5;
const int MOD=1e9+7;
using namespace std;
void solve(/*int caseN*/)
{
int x,y; cin>>x>>y;
if(x==y)
{
cout<<x;
}
else
{
int ans=-1;
for(int i=0;i<3;i++)
{
if(i!=x && i!=y)
{
ans=i;
}
}
cout<<ans;
}
}
int main()
{
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//int T; cin>>T;
//while(T--)
solve(/*T*/);
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define f(i,a,n) for (int i = a; i < n; i++)
#define fr(i,a,n) for (int i = n; i >=a; i--)
#define mod9 1000000009
#define mod7 1000000007
#define INF 1e18
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
#define zerobits(x) __builtin_ctzll(x)
#define ff first
#define ss second
#define pii pair<int, int>
#define mii map<int, int>
#define mkp make_pair
#define pb push_back
#define fast std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
signed main()
{
int x,y;
cin>>x>>y;
int c0=0,c1=0,c2=0;
if(x==0 || y==0)
c0++;
if(x==1 || y==1)
c1++;
if(x==2 || y==2)
c2++;
//cout<<c0<<" "<<c1<<" "<<c2<<endl;
if(x==y)
cout<<x<<endl;
else
{
if(c0==0)
cout<<"0"<<endl;
else if(c1==0)
cout<<"1"<<endl;
else if(c2==0)
cout<<"2"<<endl;
}
} | #include <bits/stdc++.h>
using namespace std;
int main(){
int x, y;
cin >> x >> y;
cout << (x==y ? x : 3-x-y) << endl;
}
|
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll = long long;
ll MOD = 998244353;
int H,W;
vector<vector<int>> M;
int main() {
cin >> H >> W;
M.assign(H + 1, vector<int>(W + 1, 0));
for (int i = 1; i <= H; i++) {
for (int j = 1; j <= W; j++) {
char a;
cin >> a;
if (a == 'R')M[i][j] = 1;
else if (a == 'B')M[i][j] = -1;
}
}
ll ans = 1;
for (int i = H + W; i >= 2; i--) {
int k = 0;
for (int j = max(i - H, 1); j <= min(W,i-1); j++) {
if (M[i - j][j] != 0) {
if (k == 0) {
k = M[i - j][j];
}
else if (k != M[i - j][j]) {
ans = 0;
goto SKIP;
}
}
}
if (k == 0) {
ans *= 2;
ans %= MOD;
}
}
SKIP:
cout << ans;
} | #ifdef __LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
#pragma region macros
using str=string;
using ll=long long;
using vl=vector<ll>;
using vc=vector<char>;
using pl=pair<ll,ll>;
using ml=map<ll,ll>;
using sl=set<ll>;
template<class T> using V=vector<T>;
template<class T,class U> using P=pair<T,U>;
#define FOR(n) for(ll i=0;i<n;i++)
#define rep(i,n) for(ll i=0;i<n;i++)
#define reps(i,n) for(ll i=1;i<n;i++)
#define REP(i,m,n) for(ll i=m;i<n;i++)
#define drep(i,n) for(ll i=n-1;i>=0;i--)
#define fore(n) for(auto&& i:n)
#define fors(n) for(auto&&[i,j]:n)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define sor(v) sort(all(v))
#define rsor(v) sort(rall(v))
#define rev(v) reverse(all(v))
#define low(v,x) lower_bound(all(v),x)-v.begin()
#define up(v,x) upper_bound(all(v),x)-v.begin()
#define acc(v) accumulate(all(v),0LL)
#define ef(x) emplace_front(x)
#define eb(x) emplace_back(x)
#define pf() pop_front()
#define pb() pop_back()
#define mp(a,b) make_pair(a,b)
#define ceil(a,b) (a+b-1)/b
#define bit(n) (1LL<<n)
#define fi first
#define se second
#define fr front()
#define ba back()
#define be begin()
#define en end()
#define br break
#define cn continue
#define wh while
#define el else if
#define re return
const ll inf=1LL<<60;
const ll mod=1000000007;
const ll MOD=998244353;
const double pi=3.1415926535;
const double eps=1e-10;
const ll dx[4]={1,0,-1,0};
const ll dy[4]={0,1,0,-1};
void input(){}
void inputs(){}
void output(){}
template<class T,class...U> void input(T& x,U&...y){cin>>x;input(y...);}
template<class...T> void in(T&...x){input(x...);}
template<class T> void inputs(const ll t,T& x){cin>>x[t];}
template<class T,class...U> void inputs(const ll t,T& x,U&...y){cin>>x[t];inputs(t,y...);}
template<class T,class...U> void inputs(T& x,U&...y){rep(t,size(x))inputs(t,x,y...);}
template<class...T> void ins(T&...x){inputs(x...);}
template<class T,class...U> void output(T x,U...y){cout<<x<<"\n";output(y...);}
template<class...T> void out(T...x){output(x...);}
template<class...T> void fin(T...x){out(x...);exit(0);}
template<class T> istream&operator>>(istream& i,V<T>& v){for(T& x:v)i>>x;re i;}
template<class T,class U> istream&operator>>(istream& i,P<T,U>& p){re i>>p.fi>>p.se;}
template<class T> ostream&operator<<(ostream& o,V<T>& v){for(T& x:v)o<<x<<" ";re o;}
template<class T,class U> ostream&operator<<(ostream& o,P<T,U>& p){re o<<p.fi<<" "<<p.se;}
void yn(bool b){fin((b?"Yes":"No"));}
void YN(bool b){fin((b?"YES":"NO"));}
void pos(bool b){fin((b?"POSSIBLE":"IMPOSSIBLE"));}
template<class T,class U> void chmax(T& a,U b){if(a<b)a=b;}
template<class T,class U> void chmin(T& a,U b){if(a>b)a=b;}
template<class T,class U> auto max(T a,U b){re a>b?a:b;}
template<class T,class U> auto min(T a,U b){re a<b?a:b;}
ll qp(ll x,ll n){ll r=1;wh(n>0){if(n&1)r*=x;x*=x;n>>=1;}re r;}
ll mdp(ll x,ll n){ll r=1;wh(n>0){if(n&1)r=r*x%mod;x=x*x%mod;n>>=1;}re r;}
ll MDp(ll x,ll n){ll r=1;wh(n>0){if(n&1)r=r*x%MOD;x=x*x%MOD;n>>=1;}re r;}
struct UnionFind{
vl par,sz;
UnionFind(ll n):par(n),sz(n,1){rep(i,n) par[i]=i;}
ll rot(ll x){
if(par[x]==x) re x;
re par[x]=rot(par[x]);
}
void uni(ll x,ll y){
x=rot(x),y=rot(y);
if(x==y) re;
if(sz[x]<sz[y]) swap(x,y);
sz[x]+=sz[y];
par[y]=x;
}
bool eql(ll x,ll y){re rot(x)==rot(y);}
ll siz(ll x){re sz[rot(x)];}
};
struct IOSetup{
IOSetup(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout<<fixed<<setprecision(10);
}
}iosetup;
#pragma endregion
signed main(){
ll h,w; in(h,w);
V<str> s(h); in(s);
ll ans=1;
V<vc> v(h+w-1);
rep(i,h) rep(j,w) v[i+j].eb(s[i][j]);
rep(j,h+w-1){
bool a=0,b=0;
fore(v[j]){
if(i=='R') a=1;
if(i=='B') b=1;
}
if(a&&b) fin(0);
if(!a&&!b){
ans*=2;
ans%=MOD;
}
}
out(ans);
} |
#include<bits/stdc++.h>
#define x first
#define y second
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mem(x,val) memset(x,val,sizeof x)
#define pii pair<int,int>
#define pb emplace_back
#define ar array
#define int long long
#define wopen(x) freopen((x),"w",stdout)
#define ropen(x) freopen((x),"r",stdin)
using namespace std;
const int N = 2e5 + 5;
int h, w, m, ans, xmn[N], ymn[N], bit[N];
bitset<N> b;
vector<int> v[N];
void add(int i){
for(; i <= h; i += (i&-i)) bit[i]++;
}
int query(int i){
int res = 0;
for(; i > 0; i -= (i&-i)) res += bit[i];
return res;
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> h >> w >> m;
for(int i = 1; i <= h; i++) xmn[i] = w + 1;
for(int j = 1; j <= w; j++) ymn[j] = h + 1;
while(m--){
int x, y;
cin >> x >> y;
xmn[x] = min(xmn[x], y);
ymn[y] = min(ymn[y], x);
v[y].pb(x);
}
for(int i = 1; i < ymn[1]; i++){
ans += xmn[i] - 1;
}
for(int i = ymn[1]; i <= h; i++)
add(i), b[i] = 1;
for(int i = 2; i < xmn[1]; i++){
ans += query(ymn[i] - 1);
for(int j : v[i])
if(!b[j]) b[j] = 1, add(j);
}
cout << ans;
}
| #include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//optimal subsequences-2 technocup round-3 2020
using namespace std;
using namespace __gnu_pbds;
const int N=2e5+10;
//#define d double
#define F first
#define S second
#define ll long long int
#define FastIO ios_base::sync_with_stdio(false),cin.tie(0)
#define fix std::fixed<<setprecision(6)
const int M=1e9+7;
//const int M=998244353;
#define f(n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define vi vector<int>
#define pb push_back
//#define si set<int>
#define cl(n,m) (ceil(double(n)/double(m)))
#define T() int t; cin>>t; while(t--)
#define pi pair<ll,ll>
//int MOD=998244353;
//const int MOD=1e9+7;
#define endl "\n"
const double PI = 3.141592653589793238460;
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
//ll d1=304933,d2=4395853;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//bitset<N>bs;
//bitset<512>bb[512];
//vector<vector<int>>arr;
//#ifndef ONLINE_JUDGE
//freopen("input.txt", "r" , stdin);
//freopen("output.txt", "w", stdout);
//#endif
ll MOD;
ll power(ll a,ll b)
{
ll res=1;
if(a==1)return 1;
for(;b>0;b>>=1)
{
if(b&1)res=(res*a);
if(res>MOD)res%=MOD;
a=(a*a);
if(a>MOD)a=a%MOD;
}
return res;
}
bool isPrime[3000000+1];
vector<ll>prime;
vector<int>divisor;
void seive2(int limit)
{
divisor=vector<int>(limit+1,0);
for(int i=2;i<=limit;i++)
{
if(divisor[i]==0)
{
divisor[i]=i;
if(i*1ll*i<=limit)
for(int j=i*i;j<=limit;j+=i)divisor[j]=i;
}
}
}
void seive(int limit)
{
isPrime[0]=isPrime[1]=1;
for(int i=2;i*i<=limit;i++)
{
if(!isPrime[i])
for(int j=i*i;j<=limit;j+=i)
{
isPrime[j]=1;
}
}
for(int i=2;i<=limit;i++)if(!isPrime[i])prime.pb(i);
}
#define pii pair<ll,pi>
ll pt[200010],sz[200010],wt[200010];
int finds(int x)
{
while(pt[x]!=x)
{
pt[x]=pt[pt[x]];
x=pt[x];
}
return pt[x];
}
bool unions(int x,int y)
{
int px=finds(x),py=finds(y);
if(px==py)return 0;
if(sz[px]>sz[py])swap(px,py);
pt[px]=py;
sz[py]+=sz[px];
wt[py]+=wt[px];
return 1;
}
ll bit[200100];
ll query(ll bit[],int x)
{
ll ans=0;
for(int i=x;i>0;i-=(i&(-i))){
ans+=bit[i];
}
return ans;
}
void update(ll bit[],int x,ll val)
{
for(int i=x;i>0;i-=(i&(-i)))
bit[i]+=val;
}
void update2(ll bit[],int x,ll val)
{
for(int i=x;i<=600005;i+=(i&(-i)))
bit[i]+=val;
}
ll query2(ll sum[],int x)
{
ll ans=0;
for(int i=x;i<=200005;i+=(i&(-i)))
ans+=sum[i];
return ans;
}
void dfs(int s,vector<int>&v,vector<int>&P,int visited[])
{
visited[s]=1;
v.pb(s);
int x=P[s];
if(!visited[x])
{
dfs(x,v,P,visited);
}
}
void solve()
{
ll k,n,m;
cin>>k>>n>>m;
ll a[k+1];
f(k)cin>>a[i+1];
vector<ll>v;
ll sum=0;
f(k)
{
ll x=(a[i+1]*m+n-1)/n;
v.pb(x);
sum+=x;
}
set<pi>s;
f(k)
{
ll b=v[i]-1;
ll d=b*n-a[i+1]*m;
s.insert({abs(d),i});
}
ll d=sum-m;
while(d)
{
auto it=*s.begin();
s.erase(it);
int id=it.S;
v[id]--;
d--;
}
for(int x:v)cout<<x<<' ';
}
int main()
{
//FastIO;
int t=1;
// cin>>t;
for(int i=1;i<=t;i++)
{
// cout<<"Case #"<<i<<": ";
solve();
//if(i!=t)cout<<endl;
}
return 0;
}
|
// Username: WillTheBill
// Time of creation: 2020-11-22 12:48
// Original filename: m.cp.cpp
#include<bits/stdc++.h>
using namespace std;
// shortcuts
#define pb push_back
#define fi first
#define se second
#define all(_v) _v.begin(),_v.end()
#define ll long long
// IO
#define multitest signed __T; cin >> __T; while(__T--)
template<typename T>
void _read(T& t);
template<typename T>
void _read(vector<T>&v);
template<typename T1, typename T2>
void _read(pair<T1,T2>&p);
template<typename T>
void _read(T& t){cin >> t;}
template<typename T>
void _read(vector<T>&v){for(unsigned _i=0;_i<v.size();_i++)_read(v[_i]);}
template<typename T1, typename T2>
void _read(pair<T1,T2>&p){_read(p.first);_read(p.second);}
void _masterread(){}
template<typename T,typename... V>
void _masterread(T& t, V&... v){_read(t);_masterread(v...);}
#define re(...)_masterread(__VA_ARGS__)
template<typename T>
void _print(T t);
template<typename T>
void _print(vector<T>&v);
template<typename T1, typename T2>
void _print(pair<T1,T2>&p);
template<typename T>
void _print(T t){cout<<t;}
template<typename T>
void _print(vector<T>&v){for(unsigned _i=0;_i<v.size();_i++)_print(v[_i]),cout<<(_i==v.size()-1?"":" ");}
template<typename T1, typename T2>
void _print(pair<T1,T2>&p){_print(p.first);cout<<" ";_print(p.second);}
void _masterprint(){cout<<endl;}
template<typename T,typename... V>
void _masterprint(T t, V... v){_print(t);if(sizeof...(v))cout<<" ";_masterprint(v...);}
#define pr(...)_masterprint(__VA_ARGS__)
// DEBUG
// colored output???
template <typename T> // start forward declaration
void _debug(T t);
template<typename T1,typename T2>
void _debug(pair<T1,T2> p);
template<typename T>
void _debug(vector<T>v);
template <typename T> // end forward declaration
void _debug(T t){cerr<<t;}
template<typename T1,typename T2>
void _debug(pair<T1,T2> p){cerr<<"{";_debug(p.first);cerr<<", ";_debug(p.second);cerr<<"}";}
template<typename T>
void _debug(vector<T>v){cerr<<"(";for(unsigned _i=0;_i<v.size();_i++)_debug(v[_i]),cerr<<(_i==v.size()-1?"":", ");cerr << ")";}
void _masterdebug(){cerr<<"]\n";}
template<typename T,typename... V>
void _masterdebug(T t,V... v){_debug(t);if(sizeof...(v))cerr<<", ";_masterdebug(v...);}
#ifdef __local__
#define debug(...) cerr<<"["<<#__VA_ARGS__<<"] = [";_masterdebug(__VA_ARGS__)
#else
#define debug(...)
#endif
// TYPES
// #define int long long
signed main(){
ios_base::sync_with_stdio(false); cin.tie(NULL);
int a,b,c,d; re(a,b,c,d);
pr(a * d - b * c);
}
| #include"bits/stdc++.h"
#define rep(i,n) for(ll i=0;i<n;++i)
#define ALL(x) x.begin(),x.end()
#define MOD 1000000007
#define INF INT_MAX
#define FLOAT_ANS setprecision(10)
using namespace std;
typedef long long ll;
//最大公約数
template<typename T>
T gcd(T a, T b) {
if (a % b == 0) {
return(b);
}
else {
return(gcd(b, a % b));
}
}
//最小公倍数
template<typename T>
T lcm(T a, T b) {
return a / gcd(a, b) * b;
}
//Segment Tree(遅延評価)
template<typename T>
class SegTreeLazy {
//参照:https://algo-logic.info/segment-tree/
public:
//変数定義
ll N; //長さ
T e; //単位元
vector<T>seg; //基本
vector<T>lazy; //遅延用
function<T(T, T)> f; //比較用
SegTreeLazy(ll n, ll e_, function<T(T, T)> f_) {
//サイズ・単位元・比較用の関数
e = e_;
f = f_;
//サイズnのSegTreeに必要な要素数
ll x = 1;
while (n > x) {
x *= 2;
}
N = x;
seg.resize(2 * N - 1, e);
lazy.resize(2 * N - 1, e);
}
T get(ll i){
return seg[i+N-1];
}
void eval(ll k) {
//lazyから更新情報を取得、segに反映
if (lazy[k] == e) return; //更新情報がなければ終了
if (k < N - 1) { //自身が葉でないのなら子にも伝搬させる(zipを解凍)
lazy[k * 2 + 1] = lazy[k];
lazy[k * 2 + 2] = lazy[k];
}
//最後に、自身を更新
seg[k] = lazy[k];
//もう更新情報に用はないので、初期化
lazy[k] = e;
}
void update(ll a, ll b, T x, ll k, ll l, ll r) {
// a・b:全体の範囲
// k・l:現在更新するn層目の範囲
// x:更新する値
// k:セグ木の配列における位置
eval(k); //まずは更新(sudo apt update と同じ感じ?)
if (a <= l && r <= b) {// 内部にある(端でない)
//現在の層についてのみ更新させる
lazy[k] = x;
eval(k);
}
else if (a < r && l < b) {// 一部区間がかぶる
update(a, b, x, k * 2 + 1, l, (l + r) / 2); //右の子に伝搬
update(a, b, x, k * 2 + 2, (l + r) / 2, r); //左の子に伝搬
seg[k] = f(seg[k * 2 + 1], seg[k * 2 + 2]);
}
}
void update(ll a, ll b, T x) {
//(a)-(b-1)の範囲をxに更新
update(a, b, x, 0, 0, N);
}
void update(ll a, T x) {
//aをxに更新
update(a, a + 1, x, 0, 0, N);
}
T query_sub(ll a, ll b, ll k, ll l, ll r) {
eval(k);
if (r <= a || b <= l) { //完全に外部
return e;
}
else if (a <= l && r <= b) { //完全に内部
return seg[k];
}
else {
T vl = query_sub(a, b, k * 2 + 1, l, (l + r) / 2);
T vr = query_sub(a, b, k * 2 + 2, (l + r) / 2, r);
return f(vl, vr); //右の子と左の子の小さい方
}
}
T query(int a, int b) {
return query_sub(a, b, 0, 0, N);
}
};
int main(void) {
ll n;
cin>>n;
vector<ll>p(n);
vector<bool>dp(200010,false);
ll ans=0;
rep(i,n){
cin>>p[i];
dp[p[i]]=true;
while(dp[ans]){
++ans;
}
cout<<ans<<endl;
}
}
/*
*/
|
#include <bits/stdc++.h>
using ll = long long int;
using P = std::pair<int, int>;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rag(con) std::begin(con), std::end(con)
constexpr ll mod = 998244353;
ll pow(ll x, ll m)
{
ll re = 1, y = 1;
for (int i = 0; i < 60; ++i)
{
if (m & y)
re = re * x % mod;
x = x * x % mod;
y *= 2;
}
return re;
}
ll inv(ll x)
{
return pow(x, mod - 2);
}
class mint
{
ll num = 0;
public:
mint(ll x = 0) : num(x) {}
mint operator+(const mint &rhs) const
{
return (num + rhs.num) % mod;
}
mint operator*(const mint &rhs) const
{
return num * rhs.num % mod;
}
mint operator-(const mint &rhs) const
{
return (num - rhs.num + mod) % mod;
}
mint operator/(const mint &rhs) const
{
return num * inv(rhs.num) % mod;
}
mint operator+=(const mint &rhs)
{
return *this = *this + rhs;
}
mint operator*=(const mint &rhs)
{
return *this = *this * rhs;
}
mint operator-=(const mint &rhs)
{
return *this = *this - rhs;
}
mint operator/=(const mint &rhs)
{
return *this = *this / rhs;
}
friend std::ostream &operator<<(std::ostream &os, const mint &rhs);
friend std::istream &operator>>(std::istream &is, const mint &rhs);
};
std::ostream &operator<<(std::ostream &os, const mint &rhs)
{
os << rhs.num;
return os;
}
/*std::istream &operator>>(std::istream &is, const mint &rhs)
{
is >> rhs.num;
return is;
}*/
constexpr int MAX = 2 * 1e5 + 10;
mint s[MAX], b[MAX], a[MAX];
mint fact[MAX];
mint comb(ll x, ll y)
{
return fact[x] / fact[x - y] / fact[y];
}
int main()
{
int n, K;
std::cin >> n >> K;
rep(i, n)
{
ll in;
std::cin >> in;
b[i] = a[i] = in;
}
fact[0] = 1;
for (int i = 1; i <= K; ++i)
fact[i] = fact[i - 1] * i;
s[0] = 1;
for (int i = 1; i <= K; ++i)
{
rep(j, n)
s[i] += b[j];
rep(j, n)
b[j] *= a[j];
}
mint p2 = 1;
for (int x = 1; x <= K; ++x)
{
mint ans = (mint(n - 1) - p2) * s[x];
mint res = 0;
for (int i = 0; i <= x; ++i)
{
res += comb(x, i) * s[x - i] * s[i];
}
res /= 2;
ans += res;
std::cout << ans << std::endl;
p2 *= 2;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(a) (a).begin(), (a).end()
#define uniq(a) (a).erase(unique(all(a)), (a).end())
#define bit(n) (1LL << (n))
#define dump(a) cerr << #a " = " << (a) << endl
#define fin(a) \
cout << (a) << endl; \
return 0
using vint = vector<int>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template <typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double PI = 3.1415926535897932384626433832795028;
constexpr int DY[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
constexpr int DX[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
int sign(int a) {
return (a > 0) - (a < 0);
}
int cdiv(int a, int b) {
return (a - 1 + b) / b;
}
template <typename T> T sq(T a) {
return a * a;
}
template <typename T, typename U> bool chmax(T &a, const U &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T, typename U> bool chmin(T &a, const U &b) {
if (b < a) {
a = b;
return true;
}
return false;
}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &a) {
os << "(" << a.first << ", " << a.second << ")";
return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &a) {
os << "(";
for (auto itr = a.begin(); itr != a.end(); itr++) {
os << *itr << (next(itr) != a.end() ? ", " : "");
}
os << ")";
return os;
}
template <typename T> ostream &operator<<(ostream &os, const deque<T> &a) {
os << "(";
for (auto itr = a.begin(); itr != a.end(); itr++) {
os << *itr << (next(itr) != a.end() ? ", " : "");
}
os << ")";
return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &a) {
os << "{";
for (auto itr = a.begin(); itr != a.end(); itr++) {
os << *itr << (next(itr) != a.end() ? ", " : "");
}
os << "}";
return os;
}
template <typename T> ostream &operator<<(ostream &os, const multiset<T> &a) {
os << "{";
for (auto itr = a.begin(); itr != a.end(); itr++) {
os << *itr << (next(itr) != a.end() ? ", " : "");
}
os << "}";
return os;
}
template <typename T, typename U> ostream &operator<<(ostream &os, const map<T, U> &a) {
os << "{";
for (auto itr = a.begin(); itr != a.end(); itr++) {
os << *itr << (next(itr) != a.end() ? ", " : "");
}
os << "}";
return os;
}
struct setup {
static constexpr int PREC = 20;
setup() {
cout << fixed << setprecision(PREC);
cerr << fixed << setprecision(PREC);
};
} setup;
signed main() {
int a, b;
cin >> a >> b;
int ans = 1;
reps(i, 220000) {
int x = cdiv(a, i) * i;
int y = x + i;
if (a <= x && y <= b) {
chmax(ans, i);
}
}
cout << ans << endl;
} |
#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<bitset>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef long long LL;
typedef double DB;
const int N = 555;
const int MO = 998244353;
int n,m,a[N][N],b[N*2][3];
char s[N];
int main()
{
int i,j,x;
scanf("%d%d",&n,&m);
for(i=1;i<=n;i++){
scanf("%s",s+1);
for(j=1;j<=m;j++){
if(s[j]=='.')
a[i][j]=0;
else{
if(s[j]=='B')
a[i][j]=1;
else
a[i][j]=2;
}
b[i+j][a[i][j]]++;
}
}
x=1;
for(i=2;i<=n+m;i++){
if(b[i][1]&&b[i][2])
x=0;
else{
if(b[i][1]||b[i][2])
;
else
x=x*2%MO;
}
}
cout<<x;
return 0;
} | #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...); }
#define int long long
template<typename T>
void dbg_a(T *a,int l,int r){cout<<" {";for(int i = l;i<r;i++) cout<<a[i]<<", ";cout<<a[r]<<"}"<<endl;}
typedef long long ll;
template<typename T = int>
inline T read(){
T f = 1,r = 0;
char c = getchar();
while(c<'0'||c>'9'){if(c == '-') f = -1; c = getchar();}
while(c>='0'&&c<='9'){ r = (r<<1) + (r<<3) + c - '0';c = getchar();}
return f*r;
}
typedef pair<int,int> PII;
#define fi first
#define se second
#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 _for(i,a) for(int i = 0;i<a;i++)
#define All(x) x.begin(),x.end()
// For(i,1,n) For(j,1,m) printf("f[%lld][%lld] = %lld\n",a,b,c);
const int N = 2e5 + 5,M = N*8 + 10,INF = 1e18;
const int mod = 1e9 + 7;
int n,m;
void solve(){
int x = read(),y = read();
if(y <= x){
cout<<(x - y)<<"\n";
return ;
}
queue<PII> q;
set<int> s;
q.push({y,0});
s.insert(y);
int ans = INF;
while(q.size()){
auto [t,d] = q.front();
q.pop();
if(d > ans) continue;
ans = min(ans,abs(t - x) + d);
if(t % 2 == 0){
if(!s.count(t/2)){
q.push({t/2,d+1});
s.insert(t/2);
}
}
else{
if(!s.count(t + 1)){
q.push({t + 1,d + 1});
s.insert(t + 1);
}
if(!s.count(t - 1)){
q.push({t - 1,d + 1});
s.insert(t - 1);
}
}
}
cout<<ans<<"\n";
}
signed main(){
int T = 1;
//T = read();
while(T--) solve();
system("pause");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define endl ("\n")
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define vi vector<lli>
#define ff first
#define ss second
#define rep(i, a, b) for (lli i = a; i < b; i++)
#define repr(i, a, b) for (int i = a; i > b; i--)
#define mod 1000000007
#define all(s) s.begin(), s.end()
int main() {
fast
lli tt, a, b, k;
tt = 1;
// cin>>tt;
while (tt--) {
cin>>a>>b>>k;
lli ncr[61][61], n = a + b;
string ans = "";
ncr[0][0] = 1;
rep (i, 1, 61) {
ncr[i][0] = 1;
rep (j, 1, i + 1) {
ncr[i][j] = ncr[i - 1][j] + ncr[i- 1][j - 1];
}
}
rep (i, 0, n) {
if (ncr[a - 1 + b][b] >= k) ans += 'a', a--;
else ans += 'b', k -= ncr[a - 1 + b][b], b--;
}
cout<<ans;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__)
#else
#define DEBUG(...) 6
#endif
template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {for (int i=0, b=0; i<(int)s.size(); i++) if (s[i] == '(' || s[i] == '{') b++; else
if (s[i] == ')' || s[i] == '}') b--; else if (s[i] == ',' && b == 0) {cerr << s.substr(0, i) << " = " << x << " | "; debug(s.substr(s.find_first_not_of(' ', i + 1)), args...); break;}}
const int MAX = 65;
long long choose[MAX][MAX];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
for (int i=0; i<MAX; i++)
choose[i][0] = 1;
for (int i=1; i<MAX; i++)
for (int j=1; j<MAX; j++)
choose[i][j] = choose[i-1][j] + choose[i-1][j-1];
int a, b;
long long k;
cin >> a >> b >> k;
int n = a + b;
for (int i=0; i<n; i++) {
if (a == 0) {
cout << 'b';
b--;
continue;
}
if (k <= choose[a+b-1][b]) {
cout << 'a';
a--;
} else {
k -= choose[a+b-1][b];
cout << 'b';
b--;
}
}
cout << "\n";
return 0;
}
|
#include <cstdio>
#include <cstdlib>
using namespace std;
#define ll long long
const ll MAXN = 400011;
struct fhqTreap {
ll tot, rt;
ll val[MAXN], sum[MAXN], sz[MAXN], ls[MAXN], rs[MAXN], rd[MAXN];
void pushup(ll u) {sz[u] = sz[ls[u]] + sz[rs[u]] + 1; sum[u] = sum[ls[u]] + sum[rs[u]] + val[u];}
void split(ll u, ll k, ll &x, ll &y) {
if(!u) {x = y = 0; return;}
if(val[u] <= k) x = u, split(rs[u], k, rs[u], y);
else y = u, split(ls[u], k, x, ls[u]);
pushup(u);
}
ll merge(ll u, ll v) {
if(!u || !v) return u | v;
if(rd[u] < rd[v]) {rs[u] = merge(rs[u], v); pushup(u); return u;}
else {ls[v] = merge(u, ls[v]); pushup(v); return v;}
}
ll add(ll k) {
rd[++tot] = rand();
sz[tot] = 1;
val[tot] = sum[tot] = k;
return tot;
}
void insert(ll k) {
ll x, y;
split(rt, k, x, y);
rt = merge(merge(x, add(k)), y);
}
ll cb(ll k) {
ll x, y;
split(rt, k, x, y);
ll ans = sz[x] * k + sum[y];
rt = merge(x, y);
return ans;
}
void delet(ll k) {
ll x, y, z;
split(rt, k, x, z);
split(x, k - 1, x, y);
y = merge(ls[y], rs[y]);
rt = merge(merge(x, y), z);
}
} t[2];
ll q;
ll len[2];
ll w[2][MAXN];
ll read() {
ll X = 0, F = 1; char C = getchar();
while(C < '0' || C > '9') {if(C == '-')F=-1; C = getchar();}
while(C >= '0' && C <= '9') {X = X*10+C-'0'; C = getchar();}
return X * F;
}
int main() {
ll ans = 0;
len[1] = read(); len[0] = read(); q = read();
for(ll i = 0; i < 2; ++i)
for(ll j = 1; j <= len[i]; ++j)
t[i].rt = t[i].merge(t[i].rt, t[i].add(0));
for(ll i = 1, opt, x, y; i <= q; ++i) {
opt = (read() & 1); x = read(); y = read();
t[opt].delet(w[opt][x]);
t[opt].insert(y);
ans -= t[opt^1].cb(w[opt][x]);
w[opt][x] = y;
ans += t[opt^1].cb(w[opt][x]);
printf("%lld\n", ans);
}
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, s, n) for (int i = (s); i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
int a, b;
cin >> a >> b;
int sum = 0;
if (a >= b) {
rep2(i, 1, a + 1) {
cout << i << " ";
sum += i;
}
rep2(i, 1, b) {
cout << -1 * i << " ";
sum -= i;
}
cout << -1 * sum << endl;
} else {
rep2(i, 1, b + 1) {
cout << -1 * i << " ";
sum += i;
}
rep2(i, 1, a) {
cout << i << " ";
sum -= i;
}
cout << sum << endl;
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define x first
#define y second
#define FOR(i, m, n) for (ll i(m); i < n; i++)
#define DWN(i, m, n) for (ll i(m); i >= n; i--)
#define REP(i, n) FOR(i, 0, n)
#define DW(i, n) DWN(i, n, 0)
#define F(n) REP(i, n)
#define FF(n) REP(j, n)
#define D(n) DW(i, n)
#define DD(n) DW(j, n)
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using tll = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vpll = vector<pll>;
using vtll = vector<tll>;
using gr = vector<vll>;
using wgr = vector<vpll>;
void add_edge(gr&g,ll x, ll y){ g[x].pb(y);g[y].pb(x); }
void add_edge(wgr&g,ll x, ll y, ll z){ g[x].eb(y,z);g[y].eb(x,z); }
template<typename T,typename U>
ostream& operator<<(ostream& os, const pair<T,U>& p) {
cerr << ' ' << p.x << ',' << p.y; return os; }
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
for(auto x: v) os << ' ' << x; return os; }
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v) {
for(auto x: v) os << ' ' << x; return os; }
template<typename T,typename U>
ostream& operator<<(ostream& os, const map<T,U>& v) {
for(auto x: v) os << ' ' << x; return os; }
struct d_ {
template<typename T> d_& operator,(const T& x) {
cerr << ' ' << x; return *this;}
} d_t;
#define dbg(args ...) { d_t,"|",__LINE__,"|",":",args,"\n"; }
#define deb(X ...) dbg(#X, "=", X);
#define EPS (1e-10)
#define INF (1LL<<61)
#define YES(x) cout << (x ? "YES" : "NO") << endl;
#define CL(A,I) (memset(A,I,sizeof(A)))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const ll MOD = 1e9+7;
ll mod(ll a, ll b = MOD) {
return ((a%b)+b)%b;
}
ll extended_euclid(ll a, ll b, ll &x, ll &y) {
if (a == 0) { x=0; y=1; return b;}
ll x1,y1;
ll d = extended_euclid(b%a, a, x1, y1);
x = y1-(b/a)*x1; y = x1;
return d;
}
ll mod_inverse(ll a, ll m=MOD) {
ll x, y;
ll d = extended_euclid(a, m, x, y);
if (d > 1) return -1;
return mod(x, m);
}
ll mod_power(ll a, ll p, ll m=MOD) {
ll res = mod(1,m), x=mod(a,m);
while ( p ) {
if ( p & 1 ) res = ( res * x ) % m;
x = ( x * x ) % m; p >>= 1;
}
return res;
}
struct Mt {
ll x = 0;
Mt(){}
Mt(ll y):x(mod(y)){}
bool operator==(Mt &y){return x==y.x;}
Mt operator+(Mt y){return mod(x+y.x);}
Mt operator-(){return mod(-x);}
Mt operator-(Mt y){return mod(x-y.x);}
Mt operator*(Mt y){return mod(x*y.x);}
Mt operator/(Mt y){return mod(x*mod_inverse(y.x));}
Mt operator^(ll y){return mod_power(x, y);}
Mt operator+=(Mt y){return x=(*this+y).x;}
Mt operator-=(Mt y){return x=(*this-y).x;}
Mt operator*=(Mt y){return x=(*this*y).x;}
Mt operator/=(Mt y){return x=(*this/y).x;}
Mt operator^=(ll y){return x=(*this^y).x;}
};
ostream& operator<<(ostream& os, const Mt&m){
os << m.x; return os;
}
const ll N = 3e3+7;
ll n;
ll a[N];
ll sm[N];
Mt dp[N][N];
// dp(i,j): how many ways to partition a[0:i] into j blocks
// = sum(dp(k,j-1) if sum(a[k:i])%j == 0
// = 1 if j==1
Mt m[N];
// m[x] = sum of dp[k][j-1] s.t. sm[i]%j == x and k<i
int main(void) {
ios_base::sync_with_stdio(false);
cin >> n;
F(n) cin >> a[i];
F(n) sm[i] = a[i] + (i?sm[i-1]:0);
F(n) dp[i][1] = 1;
FOR(j,2,n+1) {
CL(m,0);
F(n) {
dp[i][j] = m[sm[i]%j];
m[sm[i]%j] += dp[i][j-1];
}
}
Mt ret = 0;
FOR(j,1,n+1) ret += dp[n-1][j];
cout << ret << endl;
return 0;
}
| #include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define vll vector<ll>
#define all(x) (x).begin() , (x).end()
void dbg(){
cerr << endl;
}
template<typename Head , typename... Tail>
void dbg(Head h , Tail... t){
cerr << h << " ";
dbg(t...);
}
#ifdef EMBI_DEBUG
#define debug(...) cerr << "(" << #__VA_ARGS__ << "): ", dbg(__VA_ARGS__)
#else
#define debug(...)
#endif
const int max_n = 1e5 + 9;
const int inf = 1e9;
const int mod = 1e9 + 7;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a , ll b)
{
ll prod = 1;
while(b)
{
if(b&1)
prod = (prod*a)%mod;
a = (a*a)%mod;
b >>= 1;
}
return prod;
}
void solve(){
int n;
cin >> n;
vll a(n);
for(int i = 0 ; i < n ; i++) {
cin >> a[i];
}
ll sum = 1;
ll dp[n][n+1];
memset(dp , 0 , sizeof(dp));
for(int i = 0 ; i < n ; i++) {
dp[i][1] = 1;
}
for(int j = 2 ; j <= n ; j++) {
int b[n] , dp1[n];
memset(dp1, 0 , sizeof(dp1));
for(int i = 0 ; i < n ; i++) {
b[i] = a[i] % j;
}
int curr_rem = 0;
for(int i = 0 ; i < n ; i++) {
curr_rem += b[i];
curr_rem %= j;
dp[i][j] = dp1[curr_rem];
dp1[curr_rem] += dp[i][j-1];
dp1[curr_rem] %= mod;
}
sum += dp[n-1][j];
sum %= mod;
}
cout << sum << "\n";
}
signed main(){
int t = 1;
// cin >> t;
for(int i = 1 ; i <= t ; i++){
solve();
}
} |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using pii = pair<int, int>;
int k, n, m;
vector<int> a;
bool isOK(ll x){
vector<ll> l(k), r(k);
ll ls = 0, rs = 0;
rep(i,k){
l[i] = (((ll)m*a[i] - x) + n - 1) / n;
r[i] = ((ll)m*a[i] + x) / n;
// if(l[i]>r[i]) return false;
l[i] = max(l[i], 0ll);
r[i] = min(r[i], (ll)m);
ls += l[i];
rs += r[i];
}
if (ls <= m && m <= rs) return true;
return false;
}
void output(ll x){
vector<ll> l(k), r(k);
ll tot = 0;
rep(i,k){
l[i] = (((ll)m*a[i] - x) + n - 1) / n;
r[i] = ((ll)m*a[i] + x) / n;
tot += l[i];
}
rep(i,k){
ll nb=l[i];
if(tot < m){
while(nb<r[i] && tot<m){
nb++;
tot++;
}
}
cout << nb << " ";
}
cout << endl;
}
int main(){
// int k, n, m;
cin >> k >> n >> m;
// vector<int> a(k);
a.resize(k);
rep (i,k) cin >> a[i];
ll l=-1, r=(ll)n*m+1;
while(l+1 < r){
ll c = (l+r) / 2;
if(isOK(c)) r = c;
else l = c;
}
output(r);
} | #include<bits/stdc++.h>
using namespace std;
int main(){
long long k, n, m, bsum = 0;
cin >> k >> n >> m;
vector<long long> a(k), b(k);
for(int i = 0; i < k; ++i){cin >> a[i];}
for(int i = 0; i < k; ++i){b[i] = (m*a[i])/n; bsum += b[i];}
vector<pair<long long, long long>> minsearch(k);
for(long long i = 0; i < k; ++i){minsearch[i] = make_pair(n*b[i] - m*a[i], i);}
sort(minsearch.begin(), minsearch.end());
for(long long i = 0; i < m - bsum; ++i){
b[minsearch[i].second] += 1;
}
for(int i = 0; i < k; ++i){cout << b[i] << " ";}cout << endl;
} |
#include <stdlib.h>
#include <cmath>
#include <cstdio>
#include <cstdint>
#include <string>
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
using namespace std;
using ll = long long;
#define A_MAX 1000000000000000000
int main(){
ll N,K;
cin >> N >> K;
map<ll,ll> A;
ll a,b;
for(int i=0;i<N;++i){
cin >> a >> b;
--a;
A[a]+=b;
}
ll now=0;
for(auto p: A){
ll index=p.first;
ll k=p.second;
if(K<=index){
cout << K << endl;
return 0;
}
K+=k;
}
cout << K << endl;
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define fi first
#define se second
const int maxn=2e5+5;
struct fri
{
ll pos,val;
}f[maxn];
int n;
ll k;
bool cmp(fri aa,fri bb)
{
return aa.pos<bb.pos;
}
int main()
{
scanf("%d%lld",&n,&k);
for(int i=1;i<=n;i++)
scanf("%lld%lld",&f[i].pos,&f[i].val);
sort(f+1,f+n+1,cmp);
ll now=0;
for(int i=1;i<=n;i++)
{
if(now+k>=f[i].pos)
{
k-=f[i].pos-now;
now=f[i].pos;
k+=f[i].val;
}
else break;
}
now+=k;
printf("%lld",now);
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#define en '\n'
#define endl '\n'
#define ll long long int
#define pb push_back
#define append push_back
#define all(v) (v).begin(),(v).end()
#define FOR(i,a,b,k) for(int i=a; k>0?i<b:i>b; i+=k)
#define fori(a) for(int i=0; i<a; i++)
#define forj(a) for(int j=0; j<a; j++)
#define fork(a) for(int k=0; k<a; k++)
#define MOD 1000000007
#define MAX 1000005
#define mset(a,s,k) memset(a,k,s*sizeof(a[0]))
#define ff first
#define ss second
#define __ <<" "<<
ll pow_(ll a,ll e,ll m=MOD){ll r=1;while(e){if(e&1)r=r*a%m;a=a*a%m;e>>=1;}return r;}
int inv(ll a) {return pow_(a,MOD-2,MOD);}int add(ll a, ll b){return (a+b+MOD)%MOD;} int mul(ll a, ll b)
{return (MOD+a*b%MOD)%MOD;}int di(ll a, ll b){return mul(a,inv(b));}ll ceil(ll a,ll b){return a/b+(a%b!=0);}
void print(vector<int>a){fori(a.size())cout<<a[i]<<" ";cout<<en;}void print(ll a,ll b,char k='\n'){cout<<a<<" "<<b<<k;}
void print(vector<int> *a,int n){fori(n)print(a[i]);}void print(int *a,int n){fori(n)cout<<a[i]<<" "; cout<<en;}
#define vi vector<int>
#define tp pair<ll,ll>
int arr[MAX]; ll N,K;
ll get(ll x){
// cout<<x<<en;
if(x>N) return 2*N-x+1;
return x-1;
}
// 4-> 5+3 4+4 3+5
int solve(){
cin>>N>>K;
ll R=0;
fori(2*N+1){
if(i==0) continue;
ll X=K+i;
if(X<=0 || X>2*N) continue;
R+=get(X)*get(i);
}
cout<<R;
return 0;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t=1;
// cin>>t;
while(t--){
solve();
// cout<<solve()<<en;
// cout<<(solve()?"Yes":"No")<<endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main (){
int a, b;
cin >> a >> b;
int a2=a/100+a%100/10+a%10;
int b2=b/100+b%100/10+b%10;
if(a2>=b2){
cout << a2;
}
else{
cout << b2;
}
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
int main(){
cin.tie(0);
ios_base::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int n;
cin >> n;
vector<int> v(2*n);
for(int i = 0; i < 2*n; ++i){
cin >> v[i];
}
multiset<int> s;
int l = 0;
int r = 2*n -1;
i64 ans = 0;
while(l<r){
s.insert(v[l]);
s.insert(v[r]);
auto it = prev(s.end());
ans += *it;
s.erase(it);
l += 1;
r -= 1;
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
const int N = 200000;
int v[2*N + 5], n;
int main() {
scanf("%d", &n); for(int i=1;i<=(n<<1);i++) scanf("%d", &v[i]);
long long sum = 0;
std::priority_queue<int>que;
for(int i=n;i>=1;i--) {
que.push(v[n - i + 1]), que.push(v[n + i]);
sum += que.top(), que.pop();
}
printf("%lld\n", sum);
} |
#include<iostream>
#include<vector>
#include<bits/stdc++.h>
#define mod 1000000007
#define pi 3.14159265358979
#define PRE(x,p) cout<<setprecision(x)<<p;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define endl "\n"
#define high INT_MAX
#define low INT_MIN
#define ll long long int
using namespace std;
void showa(ll a[],ll n){ for(ll i=1;i<=n;i++) cout<<a[i]<<' '; cout<<endl; }
void showv(vector<ll>v){ for(ll i=0;i<v.size();i++) cout<<v[i]<<' '; cout<<endl;}
void solve()
{
ll n;
cin>>n;
ll p=1;
ll b=0;
ll ans=high;
while(p<=n)
{
ll a=n/p;
ll c=n%p;
p=p*2;
ans=min(ans,a+b+c);
b++;
}
cout<<ans;
}
int main()
{
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll t=1;
// cin>>t;
for(ll test=1;test<=t;test++)
{
// cout<<"CASE #"<<test<<": ";
solve();
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
long long int N;
cin>>N;
long long int a;
long long int b;
long long int c;
long long int z;
vector<long long int> vec(1000);
if(N==1){cout<<1<<endl;}
else {
for(long long int i=0;std::pow(2,i)<N;i++)
{z=std::pow(2,i);
a=N/z;
b=i;
c=N%z;
vec.at(i)=a+b+c;
};
sort(vec.begin(), vec.end());
for(long long int x=0;x<1000;x++)
{
if(vec.at(x)!=0){cout<<vec.at(x)<<endl;
break;}
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<long long>>;
const long long INF = 1LL <<60;
const long long Mo=1000000007;
vector<long long> seen;
void dfs(const Graph &G, int v, long long cnt) {
seen[v] = cnt; //判定だけならcntをboolに
// v から行ける各頂点 next_v について
for (auto next_v : G[v]) {
if (seen[next_v]>=0) continue; // next_v が探索済だったらスルー
dfs(G, next_v, cnt); // 再帰的に探索
}
}
long long gcn(long long x,long long y){
if(x%y==0){
return y;
}
else{
return gcn(y,x%y);
}
}
long long modpow(long long a, long long n, long long mod) {
long long res = 1;
while (n > 0) {
if (n & 1) res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
int main(void){
long long tmp=0;
long long i,j,k,t;
double sx,sy,gx,gy;
double res;
cin>>sx>>sy>>gx>>gy;
res=sx+(gx-sx)*sy/(sy+gy);
cout<<setprecision(15)<<res<<endl;
//cout<<res<<endl;
return 0;
}
/*
Graph G(n);
seen.assign(n,-1);
for(i=0; i<m; i++) {
cin>>tmp1>>tmp2;
tmp1--;
tmp2--;
G[tmp1].push_back(tmp2);
G[tmp2].push_back(tmp1);
}
*/ | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
int main() {
int sx, sy, gx, gy;
cin >> sx >> sy >> gx >> gy;
if(sx == gx) {
cout << sx << endl;
}
else {
printf("%lf", sx - sy * ((double)(sx - gx) / (double)(sy + gy)));
}
} |
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
#include <cstdint>
#include <string>
#include <sstream>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long ll;
using P=pair<ll,ll>;
const ll INF=1e18;
const int mod=1e9+7;
struct edge{
int to;
ll w,k;
edge(int to,ll w,ll k):to(to),w(w),k(k){}
};
using Graph=vector<vector<edge>>;
ll n,m,x,y;
void dijkstra(int s,Graph G,vector<ll>& dist){
dist.resize(n,INF);
dist[s]=0;
priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>>q;
q.push({dist[s],s});
while(!q.empty()){
int v=q.top().second;
ll d=q.top().first;
q.pop();
if(d>dist[v]){continue;}
for(auto e:G[v]){
if(chmin(dist[e.to],dist[v]+e.w)){
q.push({dist[e.to],e.to});
}
}
}
}
int main() {
cin>>n>>m>>x>>y;
x--;y--;
Graph G(n);
rep(i,m){
ll a,b,t,k,c;cin>>a>>b>>t>>c;
a--;b--;
G[a].push_back(edge(b,t,c));
G[b].push_back(edge(a,t,c));
}
vector<ll>dist(n,INF);
dist[x]=0;
priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>>q;
q.push({0ll,x});
while(!q.empty()){
int v=q.top().second,d=q.top().first;q.pop();
if(d>dist[v]){continue;}
for(auto e:G[v]){
ll cost=(e.k-dist[v]%e.k)%e.k+e.w;
if(chmin(dist[e.to],dist[v]+cost)){q.push({dist[e.to],e.to});}
}
}
cout<<(dist[y]==INF?-1:dist[y])<<endl;
return 0;
} | #pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("inline")
#include<bits/stdc++.h>
using namespace std;
inline int my_getchar_unlocked(){
static char buf[1048576];
static int s = 1048576;
static int e = 1048576;
if(s == e && e == 1048576){
e = fread_unlocked(buf, 1, 1048576, stdin);
s = 0;
}
if(s == e){
return EOF;
}
return buf[s++];
}
inline void rd(int &x){
int k;
int m=0;
x=0;
for(;;){
k = my_getchar_unlocked();
if(k=='-'){
m=1;
break;
}
if('0'<=k&&k<='9'){
x=k-'0';
break;
}
}
for(;;){
k = my_getchar_unlocked();
if(k<'0'||k>'9'){
break;
}
x=x*10+k-'0';
}
if(m){
x=-x;
}
}
inline void rd(long long &x){
int k;
int m=0;
x=0;
for(;;){
k = my_getchar_unlocked();
if(k=='-'){
m=1;
break;
}
if('0'<=k&&k<='9'){
x=k-'0';
break;
}
}
for(;;){
k = my_getchar_unlocked();
if(k<'0'||k>'9'){
break;
}
x=x*10+k-'0';
}
if(m){
x=-x;
}
}
struct MY_WRITER{
char buf[1048576];
int s;
int e;
MY_WRITER(){
s = 0;
e = 1048576;
}
~MY_WRITER(){
if(s){
fwrite_unlocked(buf, 1, s, stdout);
}
}
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
MY_WRITER_VAR.s = 0;
}
MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
my_putchar_unlocked(a);
}
inline void wt_L(const char c[]){
int i=0;
for(i=0;c[i]!='\0';i++){
my_putchar_unlocked(c[i]);
}
}
int A;
int B;
long long K;
long long c[61][61];
int main(){
int WYIGIcGE, ao_dF3pO, i;
for(i=(0);i<(61);i++){
c[i][0] = 1;
}
for(i=(1);i<(61);i++){
int j;
for(j=(1);j<(61);j++){
c[i][j] = c[i-1][j-1] + c[i-1][j];
}
}
rd(A);
rd(B);
rd(K);K += (-1);
while(A && B){
if(K < c[A+B-1][A-1]){
wt_L('a');
A--;
}
else{
K -= c[A+B-1][A-1];
wt_L('b');
B--;
}
}
for(WYIGIcGE=(0);WYIGIcGE<(A);WYIGIcGE++){
wt_L('a');
}
for(ao_dF3pO=(0);ao_dF3pO<(B);ao_dF3pO++){
wt_L('b');
}
wt_L("");
wt_L('\n');
return 0;
}
// cLay version 20210524-1
// --- original code ---
// int A, B; ll K;
// ll c[61][61];
// {
// rep(i,61) c[i][0] = 1;
// rep(i,1,61) rep(j,1,61) c[i][j] = c[i-1][j-1] + c[i-1][j];
// rd(A,B,K--);
// while(A && B){
// if(K < c[A+B-1][A-1]){
// wtN('a');
// A--;
// } else {
// K -= c[A+B-1][A-1];
// wtN('b');
// B--;
// }
// }
// rep(A) wtN('a');
// rep(B) wtN('b');
// wt("");
// }
|
#include <iostream>
#include<bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define vi vector<int>
#define vii vector<pair<int,int>>
#define pb push_back
using namespace std;
using ll = long long;
const ll mod = 1e9+7;
ll fac[1000001];
void pre(){
fac[0]=fac[1]=1;
for(int i=2;i<=1000001;i++)
{
fac[i]=(fac[i-1]*1LL*i)%mod;
}
}
ll binpower(ll a,ll n){
ll res=1;
while(n){
if(n%2)
res = (res*1LL*a)%mod;
n/=2;
a=(a*1LL*a)%mod;
}
return res;
}
ll nCrmod(ll n,ll r){
ll res= fac[n];
res = (res*1LL*binpower(fac[r],mod-2))%mod;
res= (res*1LL*binpower(fac[n-r],mod-2))%mod;
return res;
}
long long ncr(int n, int r) {
if(r > n - r) r = n - r; // because C(n, r) == C(n, n - r)
long long ans = 1;
int i;
for(i = 1; i <= r; i++) {
ans *= n - r + i;
ans /= i;
}
return ans;
}
ll modexp(ll a,ll b,ll m){
if(b==0)return 1;
if(b%2==0){
ll y = modexp(a,b/2,m);
return (y*y)%m;
}
else{
return ((a%m)*modexp(a,b-1,m))%m;
}
}
ll modinv(ll a,ll m){
return modexp(a,m-2,m);
//works only for prime m.
//else calculate phi(m)-1.
}
void SieveOfEratosthenes(ll n)
{
// Create a boolean array "prime[0..n]" and initialize
// all entries it as true. A value in prime[i] will
// finally be false if i is Not a prime, else true.
bool prime[n+1];
memset(prime, true, sizeof(prime));
for (ll p=2; p*p<=n; p++)
{
// If prime[p] is not changed, then it is a prime
if (prime[p] == true)
{
// Update all multiples of p greater than or
// equal to the square of it
// numbers which are multiple of p and are
// less than p^2 are already been marked.
for (ll i=p*p; i<=n; i += p)
prime[i] = false;
}
}
// Print all prime numbers
for (ll p=2; p<=n; p++)
if (prime[p])
cout << p << " ";
}
vector<int> Centroid(vector<int>g[],int n) {
vector<int> centroid;
vector<int> sz(n+1);
function<void (int, int)> dfs = [&](int u, int prev) {
sz[u] = 1;
bool is_centroid = true;
for (auto v : g[u]) if (v != prev) {
dfs(v, u);
sz[u] += sz[v];
if (sz[v] > n / 2) is_centroid = false;
}
if (n - sz[u] > n / 2) is_centroid = false;
if (is_centroid) centroid.push_back(u);
};
dfs(1, 0);
return centroid;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long double a,b;
cin>>a>>b;
long double p = (a-b)/a;
cout<<fixed<<setprecision(6)<<p*100.0<<endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define int ll
const int N = 50 + 7;
int n;
int y;
int a[N];
int b[N];
int valuey[N];
int dp[N][2];
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> y;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
a[n + 1] = (int) 3e18 / a[n] * a[n];
for (int i = 1; i <= n; i++) {
b[i] = a[i + 1] / a[i];
}
for (int i = n; i >= 1; i--) {
valuey[i] = y / a[i];
y %= a[i];
}
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= 1; j++) {
dp[i][valuey[i] + j >= b[i]] += dp[i - 1][j];
int value = dp[i - 1][j];
int x = b[i] - j - valuey[i];
if (1 <= x && x < b[i]) {
dp[i][(x + j + valuey[i]) >= b[i]] += value;
}
}
}
cout << dp[n][0] << "\n";
}
|
Subsets and Splits