code_file1
stringlengths 87
4k
| code_file2
stringlengths 85
4k
|
---|---|
#include <bits/stdc++.h>
using namespace std;
#define SZ(a) ((int)(a).size())
typedef long long int64;
int main() {
#ifdef LOCAL
freopen(".a.in", "r", stdin);
#endif
ios_base::sync_with_stdio(false);
cout.tie(0);
cin.tie(0);
string s, t;
cin >> s >> t;
if (s[0] == 'Y') {
if (t[0] >= 'A' && t[0] <= 'Z')
cout << char(t[0]);
else
cout << char(t[0] - 'a' + 'A');
} else {
cout <<char( t[0]) << "\n";
}
return 0;
}
//10.10.2020 20:00:47 CST
| #include<bits/stdc++.h>
using namespace std;
int main()
{
char S,T;
cin >> S >> T;
if(S=='Y')
{
if(T=='a')
{
cout<<'A'<<endl;
return 0;
}
if(T=='b')
{
cout<<'B'<<endl;
return 0;
}
if(T=='c')
{
cout<<'C'<<endl;
return 0;
}
}
else
{
cout<<T<< endl;
}
} |
#include<iostream>
#include<vector>
#include<string>
using namespace std;
vector<string> f(int n){
if(n == 1) return vector<string>{"AB"};
vector<string> ans = f(n - 1);
int sz = ans.size();
for(int t = 0; t < sz; ++t){
ans[t] = ans[t] + ans[t];
string s = ans[t];
int siz = s.size();
for(int i = siz / 2; i < siz; ++i) s[i] = "AB"[s[i] == 'A'];
ans.emplace_back(s);
}
string s(1 << (n - 1), 'A'), ss(1 << (n - 1), 'B');
ans.emplace_back(s + ss);
return ans;
}
int n;
int main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n;
vector<string> s = f(n);
cout << s.size() << "\n";
for(auto &v : s) cout << v << "\n";
return 0;
} | #include <iostream>
#include <string>
using namespace std;
using ll = long long;
int main(){
ll N;
cin >> N;
for(ll i = 1; ; i++) if(stoll(to_string(i) + to_string(i)) > N){
cout << i - 1 << endl;
return 0;
}
}
|
#include<iostream>
#include<cstdio>
using namespace std;
#define M 100009
#define endl "\n"
#define pb push_back
#define ll long long int
#define mod7 1000000009
int main()
{
/*
#ifndef inout
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
*/
int n;
cin >> n;
if (n % 2 == 0)
{
cout << "White" << endl;
}
else cout << "Black" << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
long long solve(long long N){
vector<int>A;
while(N){
A.push_back(N%10);
N/=10;
}
const int INF=1<<29;
int res=INF;
for(int bit=0;bit<(1<<A.size())-1;bit++){
int sum=0,con=0;
for(int i=0;i<A.size();i++){
if(bit&(1<<i)){
con++;
}
else sum += A[i];
}
if(sum%3==0){
res=min(res,con);
}
}
return(res<INF?res:-1);
}
int main() {
long long N;
cin >> N;
cout << solve(N) << endl;
} |
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define ll long long
#define rep(i,n) for(ll i = 0; i < (n); ++i)
#define REP(i,x,n) for(ll i = (x); i < (n); ++i)
#define P pair<ll,ll>
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1);
//const ll mod = 998244353;
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; }
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
vector<ll> fa;
ll find(ll x){
return fa[x] == x ? x : fa[x] = find(fa[x]);
}
int main(void)
{
ll n, m;
cin >> n >> m;
vector<ll> a(n), b(n);
rep(i,n) cin >> a[i];
rep(i,n) cin >> b[i];
fa = vector<ll>(n);
rep(i,n) fa[i] = i;
rep(i,m){
ll c, d;
cin >> c >> d;
c--; d--;
c = find(c);
d = find(d);
if(c != d) fa[c] = d;
}
vector<ll> l(n), r(n);
rep(i,n){
l[find(i)] += a[i];
r[find(i)] += b[i];
}
rep(i,n){
if(l[i] != r[i]){
puts("No");
return 0;
}
}
puts("Yes");
return 0;
} | #include <iostream>
#include <string>
#include <map>
#include<vector>
#include <cmath>
using namespace std;
#define ll long long
vector<int> in;
vector<int> adj[200001];
bool visited[200001];
void dfs(int x) {
visited[x] = true;
in.push_back(x);
for(int next : adj[x]) {
if(!visited[next]) dfs(next);
}
}
int main(){
int n,m;
cin >> n >> m;
int v[n], a[n], b[n];
for(int i=0;i<n;i++) cin >> a[i];
for(int i=0;i<n;i++) cin >> b[i];
for(int i=0;i<n;i++) v[i] = a[i]-b[i];
for(int i=0;i<m;i++) {
int c,d;
cin >> c >> d;
--c, --d;
adj[c].push_back(d), adj[d].push_back(c);
}
bool work = true;
for(int i=0;i<n && work;i++) {
if(!visited[i]) {
in.clear();
dfs(i);
ll sum = 0;
for(auto &it : in) sum+=v[it];
if(sum!=0) work = false;
}
}
if(!work) cout << "No" << endl;
else cout << "Yes" << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, m;
int f[105][105], pw[105];
char s[105];
inline int get(char ch)
{
if(ch == 'P') return 0;
if(ch == 'R') return 1;
return 2;
}
inline int check(int a, int b)
{
if(a == 0) return b == 2 ? 2 : 0;
if(a == 1) return b == 0 ? 0 : 1;
return b == 1 ? 1 : 2;
}
int main()
{
scanf("%d %d", &n, &m);
scanf("%s", s + 1);
pw[0] = 1;
for(int i = 1; i <= m; i++) pw[i] = 2ll * pw[i - 1] % n;
for(int i = 1; i <= n; i++) f[i][0] = get(s[i]);
for(int j = 1; j <= m; j++)
for(int i = 1; i <= n; i++)
f[i][j] = check(f[i][j - 1], f[ (i - 1 + pw[j - 1]) % n + 1 ][j - 1]);
if(f[1][m] == 0) puts("P");
if(f[1][m] == 1) puts("R");
if(f[1][m] == 2) puts("S");
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,k;
char str[205],tmp[205];
char F(char x,char y){
if(x==y)return x;
if(x=='S'&&y=='P')return x;
if(x=='P'&&y=='R')return x;
if(x=='R'&&y=='S')return x;
return y;
}
int main(){
cin>>n>>k>>str+1;
for(int j=1;j<=n;j++)str[j+n]=str[j];
for(int i=1;i<=k;i++){
for(int j=1;j<=n;j++)tmp[j]=F(str[2*j-1],str[2*j]);
for(int j=1;j<=n;j++)str[j]=str[j+n]=tmp[j];
//for(int j=1;j<=n;j++)cout<<str[j];cout<<endl;
}
cout<<str[1];
return 0;
}
/**/ |
#include<bits/stdc++.h>
using namespace std;
# define ll long long
# define read read1<ll>()
# define Type template<typename T>
Type T read1(){
T t=0;
char k;
bool vis=0;
do (k=getchar())=='-'&&(vis=1);while('0'>k||k>'9');
while('0'<=k&&k<='9')t=(t<<3)+(t<<1)+(k^'0'),k=getchar();
return vis?-t:t;
}
# define fre(k) freopen(k".in","r",stdin);freopen(k".out","w",stdout)
int s,k,a[805][805],b[805][805];
vector<int>ve;
bool judge(int x){
for(int i=1;i<=s;++i)
for(int j=1;j<=s;++j)
b[i][j]=b[i-1][j]+b[i][j-1]-b[i-1][j-1]+(a[i][j]>x);
for(int i=k;i<=s;++i)
for(int j=k;j<=s;++j)
if(b[i][j]-b[i-k][j]-b[i][j-k]+b[i-k][j-k]<=(k*k>>1))
return 1;
return 0;
}
int main(){
s=read,k=read;
for(int i=1;i<=s;++i)
for(int j=1;j<=s;++j)
a[i][j]=read,ve.push_back(a[i][j]);
sort(ve.begin(),ve.end());
int l=0,r=ve.size()-1,mid,ans=0;
while(l<=r)judge(ve[mid=l+r>>1])?r=(ans=mid)-1:l=mid+1;
cout<<ve[ans];
return 0;
} | #include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; using ll = long long; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;
int main() {
int N, K;
cin >> N >> K;
vv<int> A = vvec(N, N, 0);
rep(i, N) rep(j, N) cin >> A[i][j];
int low = -1, high = 1e9;
vv<int> B = vvec(N + 1, N + 1, 0);
while (high - low > 1) {
int mid = (low + high) / 2;
rep(i, N) rep(j, N) {
B[i + 1][j + 1] = B[i + 1][j] + B[i][j + 1] - B[i][j] + (A[i][j] > mid);
}
bool ok = false;
int border = K * K / 2 + 1;
rep(i, 0, N - K + 1) rep(j, 0, N - K + 1) {
int c = B[i + K][j + K] - B[i + K][j] - B[i][j + K] + B[i][j];
if (c < border) ok = true;
}
if (ok) high = mid;
else low = mid;
}
write(high);
} |
//红太阳zhouakngyang txdy!
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#include<bits/stdc++.h>
#define Macesuted cout<<"kawaii"<<endl
#define MatrixCascade cout<<"npsl"<<endl
#define Karry5307 cout<<"nmsl"<<endl
using namespace std;
#define int long long
inline int read()
{
int sum=0,nega=1;char ch=getchar();
while(ch>'9'||ch<'0'){if(ch=='-')nega=-1;ch=getchar();}
while(ch<='9'&&ch>='0')sum=sum*10+ch-'0',ch=getchar();
return sum*nega;
}
const int N=2e5+9,mod=998244353,M=4e5+9;
int n,a[N],b[N],ans,c[M];
struct point
{
int x,pos;
}ax[N],bx[N];
map <int,int> mp;
int tim;
vector<int> pa[N],pb[N];
inline int lowbit(int x)
{
return x&(-x);
}
inline void add(int x,int k)
{
while(x<=M)
{
c[x]+=k;x+=lowbit(x);
}
}
inline int query(int x)
{
int res=0;
while(x!=0)
{
res+=c[x];x-=lowbit(x);
}
return res;
}
signed main()
{
n=read();
for(int i=1;i<=n;i++)a[i]=read(),ax[i].x=a[i]+i-1,ax[i].pos=i;
for(int i=1;i<=n;i++)b[i]=read(),bx[i].x=b[i]+i-1,bx[i].pos=i;
for(int i=1;i<=n;i++)
if(!mp[ax[i].x])mp[ax[i].x]=++tim;
for(int i=1;i<=n;i++)pa[mp[ax[i].x]].push_back(i);
for(int i=1;i<=n;i++)
{
if(!mp[bx[i].x])
{
puts("-1");return 0;
}
pb[mp[bx[i].x]].push_back(i);
}
for(int i=1;i<=tim;i++)
{
if(pa[i].size()!=pb[i].size())
{
puts("-1");return 0;
}
for(int j=0;j<pa[i].size();j++)
{
a[pa[i][j]]=pb[i][j];
}
}
// for(int i=1;i<=n;i++)cout<<a[i]<<" ";cout<<endl;
for(int i=1;i<=n;i++)
{
ans+=(i-1-query(a[i]));
add(a[i],1);
// cout<<ans<<endl;
}
cout<<ans<<endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;
int N=1<<18;
class StarrySkyTree{
public:
ll Mi[555555],A[555555];
void init(){memset(Mi,0,sizeof(Mi)),memset(A,0,sizeof(A));}
void add(int a,int b,ll x,int k=0,int l=0,int r=N) {
if(r<=a||b<=l) return;
if(a<=l&&r<=b){
A[k]+=x;
while(k){
k=(k-1)/2;
Mi[k]=min(Mi[k*2+1]+A[k*2+1],Mi[k*2+2]+A[k*2+2]);
}
return;
}
add(a,b,x,k*2+1,l,(l+r)/2);
add(a,b,x,k*2+2,(l+r)/2,r);
}
ll getMin(int a,int b,int k=0,int l=0,int r=N) {
if(r<=a||b<=l)return MAXL;if(a<=l&&r<=b)return Mi[k]+A[k];
ll left=getMin(a,b,k*2+1,l,(l+r)/2),right=getMin(a,b,k*2+2,(l+r)/2,r);
return min(left,right)+A[k];
}
};
StarrySkyTree t;
void Main() {
ll n;
R n;
ll a[n],b[n];
rep(i,n) R a[i];
rep(i,n) R b[i];
ll s1=0,s2=0;
rep(i,n) {
s1+=a[i];
s2+=b[i];
}
if(s1!=s2) {
pr(-1);
return;
}
rep(i,n) {
a[i]+=i;
b[i]+=i;
}
t.init();
map<ll,queue<ll> > m;
rep(i,n) m[a[i]].push(i);
ll ans=0;
rep(i,n) {
if(m[b[i]].empty()) {
pr(-1);
return;
}
ll k=m[b[i]].front();m[b[i]].pop();
ll x=k+t.getMin(k,k+1);
ans+=x-i;
t.add(0,k,1);
}
pr(ans);
}
int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<typename T> using v2 = vector<vector<T>>;
template<typename T> inline v2<T> fill(int r, int c, const T& t){
return v2<T>(r, vector<T>(c, t));
}
#define F first
#define S second
void solve(){
ll n;
cin >> n;
ll lo = 0;
ll hi = 2e9;
ll highest = -1;
while(lo <= hi){
ll mid = (lo+hi)/2;
ll sum = (mid*(mid+1))/2;
if(sum <= n+1){
highest = mid;
lo = mid+1;
}
else{
hi = mid-1;
}
}
assert(highest != -1);
ll ans = n - highest + 1;
cout << ans << "\n";
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
return 0;
} | // Author: rifatrraazz
// Time: 2021-05-10 10:25:19
// Problem: A - Century
// TL: 2000ms ML: 1024MB
// URL: https://atcoder.jp/contests/abc200/tasks/abc200_a
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define yes cout << "Yes\n"
#define no cout << "No\n"
#define Case(i) cout << "Case " << int(i) << ": "
#define dbg(x) cout << #x << " = " << x << endl
#define dbg2(x, y) cout << #x << " = " << x << "\t" << #y << " = " << y << endl
#define lop(n) for (int i = 0; i < n; i++)
#define lopj(n) for (int j = 0; j < n; j++)
#define mem0(a) memset(a, 0, sizeof a)
#define mem1(a) memset(a, -1, sizeof a)
#define all(x) x.begin(), x.end()
#define sorta(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.rbegin(), x.rend())
#define bitcount(x) __builtin_popcount(x)
#define vin vector<int>
#define vll vector<ll>
#define vst vector<string>
#define pll pair<ll, ll>
#define pii pair<int, int>
#define vpll vector<pll>
#define vpii vector<pii>
#define fread freopen("input.txt", "r", stdin)
#define fwrite freopen("output.txt", "w", stdout)
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI acos(-1.0)
using namespace std;
int main()
{
fastio;
int n; cin >> n;
cout << (n + 99) / 100;
return 0;
}
/* int dr[] = {1,-1,0,0}
int dc[] = {0,0,1,-1}; */
// 4 Direction
/* int dr[] = {1,-1,0,0,1,1,-1,-1}
int dc[] = {0,0,1,-1,1,-1,1,-1}; */
// 8 Direction
/* int dr[] = {1,-1,1,-1,2,2,-2,-2}
int dc[] = {2,2,-2,-2,1,-1,1,-1}; */
// Knight Direction
/* int dr[] = {2,-2,1,1,-1,-1}
int dc[] = {0,0,1,-1,1,-1}; */
// Hexagonal Direction
// bitmask operations
/*
int Set(int n, int pos) { return n = n | (1 << pos); }
int reset(int n, int pos) { return n = n & ~(1 << pos); }
bool check(int n, int pos) { return (bool)(n & (1 << pos)); }
*/
|
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
vector<pair<int,int>>ans(n+1);
for(int i=1;i<=n;i++){
ans[i].first=i*2%n;
ans[i].second=(i*2+1)%n;
}
for(int i=1;i<=n;i++)cout<<ans[i].first+1<<' '<<ans[i].second+1<<'\n';
} | #include<iostream>
using namespace std;
int n,i;
int main(){
cin>>n;
for(i=1;i<=n;++i){
cout<<((i+1)>>1)<<" "<<((i+n+1)>>1)<<endl;
}
} |
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int p=1e9+7;
int n,ans,f[3010][3010],sum[3010];
ll a[3010],s[3010];
int main(){
scanf("%d",&n);
int i,j;
for(i=1;i<=n;i++)scanf("%lld",&a[i]),s[i]=s[i-1]+a[i];
f[0][0]=1;
for(j=1;j<=n;j++){
for(i=0;i<j;i++)sum[i]=0;
for(i=0;i<=n;i++){
f[i][j]=sum[s[i]%(ll)j];
sum[s[i]%(ll)j]=(sum[s[i]%(ll)j]+f[i][j-1])%p;
}
}
for(j=1;j<=n;j++)ans=(ans+f[n][j])%p;
cout<<ans;
return 0;
} | /*input
12
5 2
5 6
1 2
9 7
2 7
5 5
4 2
6 7
2 2
7 8
9 7
1 8
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
typedef long long int ll;
#define ld double
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
const ll maxn=4e5+5;
const ll maxlg=__lg(maxn)+2;
const ll INF64=4e18;
const int INF=0x3f3f3f3f;
const ll MOD=(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
ll mult(ll a,ll b){
return (a*b)%MOD;
}
ll mypow(ll a,ll b){
if(b<=0) return 1;
a%=MOD;
ll res=1LL;
while(b){
if(b&1) res=mult(res,a);
a=mult(a,a);
b>>=1;
}
return res;
}
vector<int> v[maxn];
bool vis[maxn];
int cnt=0;
int num=0;
void dfs(int u){
vis[u]=1;
num++;
for(int x:v[u]){
if(!vis[x]){
++cnt;
dfs(x);
}
else ++cnt;
}
}
int main(){
ios::sync_with_stdio(false),cin.tie(0);
int n;
cin>>n;
set<int> s;
REP(i,n){
int a,b;
cin>>a>>b;
--a;
--b;
s.insert(a),s.insert(b);
v[a].pb(b);
v[b].pb(a);
}
int ans=sz(s);
for(auto x:s){
if(!vis[x]){
cnt=num=0;
dfs(x);
if(cnt==2*(num-1)) --ans;
}
}
cout<<ans;
} |
// {{{ by unolight
#include <bits/stdc++.h>
#include <unistd.h>
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-function"
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x),end(x)
#define RALL(x) rbegin(x),rend(x)
#define REP(i,n) for ( int i=0; i<int(n); i++ )
#define REP1(i,a,b) for ( int i=(a); i<=int(b); i++ )
#define MP make_pair
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef pair<int,int> PII;
typedef vector<int> VI;
namespace { namespace unolight {
// Read Input
template<class T> void _R( T &x ) { cin>>x; }
void _R( int &x ) { scanf("%d",&x); }
void _R( int64_t &x ) { scanf("%" PRId64,&x); }
void _R( double &x ) { scanf("%lf",&x); }
void _R( char &x ) { scanf(" %c",&x); }
void _R( char *x ) { scanf("%s",x); }
void R() {}
template<class T, class... U> void R( T& head, U&... tail ) { _R(head); R(tail...); }
// Write Output
template<class T> void _W( const T &x ) { cout<<x; }
void _W( const int &x ) { printf("%d",x); }
void _W( const int64_t &x ) { printf("%" PRId64,x); }
void _W( const double &x ) { printf("%.16f",x); }
void _W( const char &x ) { putchar(x); }
void _W( const char *x ) { printf("%s",x); }
template<class T> void _W( const vector<T> &x ) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W( const T& head, const U&... tail ) { _W(head); putchar(sizeof...(tail)?' ':'\n'); W(tail...); }
#ifdef UNOLIGHT
#include "dump.hpp"
#else
#define dump(...)
#endif
template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
sort(begin(v),end(v),f);
v.resize(unique(begin(v),end(v))-begin(v));
}
// }}}
void main() {
int n;
R(n);
W((n-1)/100+1);
}
// {{{ main
}}
int main() { unolight::main(); return 0; }
// }}}
| #include <cstdio>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define len(v) (int) v.size()
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define gauss(n) ((n) * ((n) + 1)) / 2
#ifdef LOCAL
#include "debugger.h"
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int N; cin >> N;
int c = 1;
for(int i = 1; i <= 3000;i += 100,++c) {
int j = i + 99;
if(N >= i && N <= j) {
cout << c << endl;
break;
}
}
return 0;
}
|
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
template<typename T>
using vec = vector<T>;
template<typename T>
using mat = vector<vector<T>>;
bool debugflag = true;
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
for (int i = 0; i < (int)v.size(); ++i) {
os << v[i] << " ";
}
return os;
}
template<typename T>
istream& operator>>(istream& is, vector<T>& v) {
for (T& in : v) is >> in;
return is;
}
void debug(){
cout << endl;
}
template<class Head, class... Tail>
void debug(Head&& head, Tail&&... tail) {
if (!debugflag) return;
cout << head << " ";
debug(forward<Tail>(tail)...);
}
int main() {
ll K, N, M; cin >> K >> N >> M;
vec<ll> A(K); cin >> A;
vec<ll> B(K, 0); ll m = 0;
vec<double> b(K, 0);
vec<pair<ll, ll>> diff;
for (int i = 0; i < K; ++i) {
B[i] = (ll)((double)A[i] / N * M);
b[i] = (double)A[i] / N * M;
m += B[i];
diff.emplace_back(B[i] * N - A[i] * M, i);
}
sort(diff.begin(), diff.end());
for (int i = 0; i < M - m; ++i) ++B[(int)diff[i].second];
cout << B << endl;
} | /*
Author: Zhikun Wang
Date: 2021/05/29
*/
#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>string to_string(pair<A, B> p);template <typename A, typename B, typename C>string to_string(tuple<A, B, C> p);template <typename A, typename B, typename C, typename D>string to_string(tuple<A, B, C, D> p);string to_string(const string& s) { return '"' + s + '"';}string to_string(const char* s) { return to_string((string) s);}string to_string(bool b) { return (b ? "true" : "false");}string to_string(vector<bool> v) { bool first = true; string res = "{"; for (int i = 0; i < static_cast<int>(v.size()); i++) { if (!first) { res += ", "; } first = false; res += to_string(v[i]); } res += "}"; return res;}template <size_t N>string to_string(bitset<N> v) { string res = ""; for (size_t i = 0; i < N; i++) { res += static_cast<char>('0' + v[i]); } return res;}template <typename A>string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res;}template <typename A, typename B>string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}template <typename A, typename B, typename C>string to_string(tuple<A, B, C> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";}template <typename A, typename B, typename C, typename D>string to_string(tuple<A, B, C, D> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";}void debug_out() { cerr << endl; }template <typename Head, typename... Tail>void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...);}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
#define set0(x) memset(x,0,sizeof(x))
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
template<typename T> void read(T &x){
x = 0;char ch = getchar();ll f = 1;
while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}
template<typename T, typename... Args> void read(T &first, Args& ... args) {
read(first);
read(args...);
}
int T;
int n,p[555];
int c = n-1;
vi ans;
bool sorted(){
int ans = 1;
for(int i=1;i<=n;i++)if(p[i]!=i)ans= 0;
return ans;
}
void solve(){
read(n);
for(int i=1;i<=n;i++)read(p[i]);
int cc = 1;
for(int i=1;i<=n-3;i++){
while(p[i]!=i){
int cp = 0;
for(int j = i;j<=n;j++){
if(p[j] == i) cp = j;
}
if((cp-1)%2 == cc%2){
swap(p[cp-1],p[cp]);
ans.PB(cp-1);
}else{
int c = n-1;
while(c%2!=cc%2)c-=1;
swap(p[c],p[c+1]);
ans.PB(c);
}
cc+=1;
}
}
while(!sorted()){
int c = n-1;
while(c%2!=cc%2)c-=1;
swap(p[c],p[c+1]);
ans.PB(c);
cc+=1;
}
cout<<ans.size()<<"\n";
for(auto ct:ans)cout<<ct<<' ';
cout<<"\n";
ans.clear();
}
int main(){
read(T);
while(T--){
solve();
}
return 0;
} |
#include <cstdio>
#define abs(x) ((x) < 0 ? -(x) : (x))
int main() {
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
if (c & 1) {
if (a == b) puts("=");
else if (a < b) puts("<");
else puts(">");
}
else {
a = abs(a), b = abs(b);
if (a == b) puts("=");
else if (a > b) puts(">");
else puts("<");
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
string s; cin>>s;
int n = s.size();
bool ok = 1;
for(int i = 0; i<n; i++){
if(i&1 && s[i]>='a' && s[i]<='z') ok = 0;
else if(i&1^1 && s[i]>='A' && s[i]<='Z') ok = 0;
}
cout<<(ok?"Yes\n":"No\n");
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
double PI=acos(-1.0);
#define ll long long
#define ull unsigned long long
#define pii pair<ll,ll>
const ll mod=3;
ll nn;
ll fac[mod+105],inv[mod+105];
void getInv()
{
fac[0]=fac[1]=inv[1]=1;
for(int i=2;i<mod;i++)
{
fac[i]=fac[i-1]*i%mod;
inv[i]=(mod-mod/i)*inv[mod%i]%mod;
}
}
ll C(ll n,ll m)
{
if(m>n) return 0;
return fac[n]*inv[fac[m]*fac[n-m]%mod]%mod;
}
ll Lucas(ll n,ll m)
{
if(m>n) return 0;
if(n<mod && m<mod)return C(n,m);
return Lucas(n/mod,m/mod)*C(n%mod,m%mod)%mod;
}
map<char,ll>m;
int main()
{
ios::sync_with_stdio(0);
getInv();
m['B']=0;
m['W']=1;
m['R']=2;
ll n;
cin>>n;
ll ans=0;
for(int i=0;i<n;i++)
{
char op;
cin>>op;
ll d=m[op];
ans=(ans+d*Lucas(n-1,i))%mod;
}
if(n%2==0)
ans=(3-ans)%3;
if(ans==0)
{
cout<<"B"<<endl;
}
else if(ans==1)
{
cout<<"W"<<endl;
}
else if(ans==2)
{
cout<<"R"<<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--)
int lower_three(int x){
int a=1;
while(3*a<x){
a*=3;
}
return a;
}
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;
while(n>1){
a=lower_three(n-1);
fr(i,n-a){
c[i]=change(c[i],c[i+a]);
}
n-=a;
}
cout << c[0] << endl;
} |
#include <bits/stdc++.h>
#define clr(x) memset((x), 0, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define For(i, st, en) for(int i=(st); i<=(int)(en); i++)
#define Ford(i, st, en) for(int i=(st); i>=(int)(en); i--)
#define forn(i,m,n) for(int i=m; i<(int)(n); i++)
#define forn2(i, n) for(int i=0; i<=(int)(n); i++)
#define ford(i, n) for(int i=(n)-1; i>=0; i--)
#define fori(it, x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define in(x) int (x); input((x));
#define x first
#define y second
#define less(a,b) ((a) < (b) - EPS)
#define more(a,b) ((a) > (b) + EPS)
#define eq(a,b) (fabs((a) - (b)) < EPS)
#define remax(a, b) ((a) = (b) > (a) ? (b) : (a))
#define remin(a, b) ((a) = (b) < (a) ? (b) : (a))
#define salfinal(x) cout<<x<<endl;
using namespace std;
const int MAX =1e5+1;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
/*
freopen("s.txt","r",stdin);
freopen("sa.txt","w",stdout);
*/
int v,s,t,d;
cin>>v>>t>>s>>d;
if(d<v*t || d>v*s)cout<<"Yes\n";
else cout<<"No\n";
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int V, T, S, D;
cin >> V >> T >> S >> D;
if(D < V*T || V*S < D){cout << "Yes" << endl;}
else{cout << "No" << endl;}
} |
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
using ll = long long;
using ld = long double;
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
#define mp make_pair
int p = 1e9 + 7;
int mul(int a, int b) {
return (1LL * a * b) % p;
}
int add(int a, int b) {
int s = (a+b);
if (s>=p) s-=p;
return s;
}
int sub(int a, int b) {
int s = (a+p-b);
if (s>=p) s-=p;
return s;
}
int po(int a, ll deg)
{
if (deg==0) return 1;
if (deg%2==1) return mul(a, po(a, deg-1));
int t = po(a, deg/2);
return mul(t, t);
}
int inv(int n)
{
return po(n, p-2);
}
mt19937 rnd(time(0));
/*
const int N = 1e6 + 5;
vector<int> facs(N), invfacs(N);
void init()
{
facs[0] = 1;
for (int i = 1; i<N; i++) facs[i] = mul(facs[i-1], i);
invfacs[N-1] = inv(facs[N-1]);
for (int i = N-2; i>=0; i--) invfacs[i] = mul(invfacs[i+1], i+1);
}
int C(int n, int k)
{
if (n<k) return 0;
if (n<0 || k<0) return 0;
return mul(facs[n], mul(invfacs[k], invfacs[n-k]));
}*/
/*struct DSU
{
vector<int> sz;
vector<int> parent;
vector<int> value;
void make_set(int v) {
parent[v] = v;
sz[v] = 1;
value[v] = 0;
}
int find_set(int v) {
if (v == parent[v])
return v;
else
{
auto par = find_set(parent[v]);
value[v]^=value[parent[v]];
parent[v] = par;
return par;
}
}
void union_sets(int a, int b, int w) {
find_set(a);
find_set(b);
w^=value[a]; w^=value[b];
a = find_set(a);
b = find_set(b);
if (a != b) {
if (sz[a] < sz[b])
swap(a, b);
parent[b] = a;
value[b] = w;
sz[a] += sz[b];
}
}
int val(int v)
{
find_set(v); return value[v];
}
DSU (int n)
{
parent.resize(n);
sz.resize(n);
value.resize(n);
for (int i = 0; i<n; i++) make_set(i);
}
};*/
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(nullptr);
int a, b, c;
cin>>a>>b>>c;
p = 4;
b = po(b, c); if (b==0) b = 4;
p = 10;
cout<<po(a, b);
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll mod_pow(ll base, ll exp, ll modulus) {
base %= modulus;
ll result = 1;
while (exp > 0) {
if (exp & 1) result = (result * base) % modulus;
base = (base * base) % modulus;
exp >>= 1;
}
return result;
}
void solve(long long A, long long B, long long C) {
cout << mod_pow(A, mod_pow(B, C, 4) + 4, 10) << endl;
}
int main() {
long long A;
scanf("%lld", &A);
long long B;
scanf("%lld", &B);
long long C;
scanf("%lld", &C);
solve(A, B, C);
return 0;
}
|
#line 1 "/workspaces/compro/lib/template.hpp"
#line 1 "/workspaces/compro/lib/io/vector.hpp"
#include <iostream>
#include <vector>
#ifndef IO_VECTOR
#define IO_VECTOR
template <class T> std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
int size = v.size();
for (int i = 0; i < size; i++) {
std::cout << v[i];
if (i != size - 1)
std::cout << " ";
}
return out;
}
template <class T> std::istream &operator>>(std::istream &in, std::vector<T> &v) {
for (auto &el : v) {
std::cin >> el;
}
return in;
}
#endif
#line 4 "/workspaces/compro/lib/template.hpp"
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
#define MM << " " <<
using namespace std;
template <class T> void chmin(T &a, T b) {
if (a > b)
a = b;
}
template <class T> void chmax(T &a, T b) {
if (a < b)
a = b;
}
// 重複を消す。計算量はO(NlogN)
template <class T> void unique(std::vector<T> &v) {
std::sort(v.begin(), v.end());
v.erase(std::unique(v.begin(), v.end()), v.end());
}
#line 2 "main.cpp"
long long solve(int N, int M, const std::vector<int> &A, const std::vector<int> &B) {
int ans = 0;
vector<vi> g(N);
REP(i, M) { g[A[i]].push_back(B[i]); }
auto f = [&](auto self, int cur, vector<bool> &visited) -> void {
visited[cur] = true;
for (const auto v : g[cur]) {
if (!visited[v]) {
ans++;
self(self, v, visited);
}
}
};
REP(i, N) {
vector<bool> visited(N, false);
f(f, i, visited);
}
return ans + N;
}
// generated by online-judge-template-generator v4.7.1 (https://github.com/online-judge-tools/template-generator)
int main() {
int N, M;
std::cin >> N >> M;
std::vector<int> A(M), B(M);
for (int i = 0; i < M; ++i) {
std::cin >> A[i] >> B[i];
A[i]--;
B[i]--;
}
auto ans = solve(N, M, A, B);
std::cout << ans << std::endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ull unsigned long long int
const int mod=1e9+7;
const int mxx=1e5+10;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ff first
#define ss second
vector<int> adj[2222];
bool vis[2222];
int cnt;
void dfs(int u){
vis[u]=1;
for(auto v:adj[u]){
if(!vis[v]){
cnt++;
dfs(v);
}
}
}
int main(){
IOS;
ll t=1,i;
while(t--){
int n,m;
cin>>n>>m;
for(i=0;i<m;i++){
int u,v;
cin>>u>>v;
adj[u].push_back(v);
}
int ans=0;
for(i=1;i<=n;i++){
memset(vis,0,sizeof(vis));
cnt=1;
dfs(i);
ans+=cnt;
}
cout<<ans;
}
} |
#include <iostream>
#include <vector>
using namespace std;
vector< pair< long long, long long > > prime_factorize(long long N) {
vector< pair< long long, long long > > res;
for(long long a = 2; a * a <= N; ++a) {
if(N % a != 0)
continue;
long long ex = 0;
while(N % a == 0) {
++ex;
N /= a;
}
res.push_back({a, ex});
}
if(N != 1)
res.push_back({N, 1});
return res;
}
int main() {
unsigned long long N;
cin >> N;
int res = 2;
N /= (N & -N);
for(const auto &p : prime_factorize(N)) {
res *= (p.second + 1);
}
cout << res << endl;
} | #include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define rep(i,n) for(ll i=0;i<ll(n);i++)
#define REP(i,k,n) for(ll i=k;i<ll(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define UNIQUE(a) sort(all(a));a.erase(unique(all(a)),a.end())
#define decimal cout<<fixed<<setprecision(10)
using ll=long long;
using P=pair<ll,ll>;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
constexpr ll inf=1001001001001001;
constexpr int INF=1001001001;
constexpr int mod=1000000007;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
void YesNo(bool b){if(b)out("Yes");else out("No");}
void yesno(bool b){if(b)out("yes");else out("no");}
void YESNO(bool b){if(b)out("YES");else out("NO");}
ll modpow(ll a,ll b){ll c=1;while(b>0){if(b&1){c=a*c%mod;}a=a*a%mod;b>>=1;}return c;}
vi calc(ll x){vi v;while(x>0){v.eb(x%10);x/=10;}reverse(all(v));return v;}
struct UnionFind{
vi d;
UnionFind(ll n=0):d(n,-1){}
ll find(ll x){
if(d[x]<0) return x;
return d[x]=find(d[x]);
}
bool unite(ll x,ll y){
x=find(x); y=find(y);
if(x==y) return false;
if(d[x]>d[y]) swap(x,y);
d[x]+=d[y];
d[y]=x;
return true;
}
bool same(ll x,ll y){return find(x)==find(y);}
ll size(ll x){return -d[find(x)];}
};
int main(){
ll n; cin>>n;
vi a(n);
rep(i,n) cin>>a[i];
ll m=200005;
UnionFind uf(m);
rep(i,n){
uf.unite(a[i]-1,a[n-i-1]-1);
}
vi v(m,0);
rep(i,m){
v[uf.find(i)]=uf.size(i);
}
ll ans=0;
rep(i,m){
if(v[i]>0) ans+=v[i]-1;
}
out(ans);
//outv(v);
} |
//#include <atcoder/maxflow.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#include <iostream>
#include <map>
#include <list>
#include <set>
#include <algorithm>
#include <vector>
#include <string>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <iterator>
#include <random>
#include <chrono>
#include <complex>
#include <bitset>
#include <fstream>
#define forr(i,start,count) for (int i = (start); i < (start)+(count); ++i)
#define set_map_includes(set, elt) (set.find((elt)) != set.end())
#define readint(i) int i; cin >> i
#define readll(i) ll i; cin >> i
#define readdouble(i) double i; cin >> i
#define readstring(s) string s; cin >> s
typedef long long ll;
//using namespace __gnu_pbds;
//using namespace atcoder;
using namespace std;
const ll modd = (1000LL * 1000LL * 1000LL + 7LL);
//const ll modd = 998244353;
template<class T>
T fastpower(T x, ll pw, T id = 1) {
T w = x, res = id;
while (pw>0) {
if (pw&1) {
res = (res * w) % modd;
}
pw >>= 1;
w = (w * w) % modd;
}
return res;
}
int main(int argc, char *argv[]) {
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_int_distribution<int> rand_gen(0, modd); // rand_gen(rng) gets the rand no
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.precision(12);
// readint(test_cases);
int test_cases = 1;
forr(t, 1, test_cases) {
readll(n);
readll(p);
cout << ((p-1)*fastpower(p-2,n-1)) % modd << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PP;
#define MOD 1000000007
//#define MOD 998244353
#define INF 2305843009213693951
//#define INF 810114514
#define PI 3.141592653589
#define setdouble setprecision
#define REP(i,n) for(ll i=0;i<(n);++i)
#define OREP(i,n) for(ll i=1;i<=(n);++i)
#define RREP(i,n) for(ll i=(n)-1;i>=0;--i)
#define all1(i) begin(i),end(i)
#define GOODBYE do { cout << "-1" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug true
#define debug2 false
long long power(long long b,long long e){
/*
Copyright (c) 2021 0214sh7
https://github.com/0214sh7/library/
*/
long long r=1;
while(e){
if(e&1){
r=(r*b)%MOD;
}
b=(b*b)%MOD;
e >>=1;
}
return r;
}
int main(void){
ll N,P;
cin >> N >> P;
ll Ans = power(P-2,N-1);
Ans = (Ans*(P-1))%MOD;
cout << Ans << endl;
return 0;
}
|
#include <stdint.h>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
#define FOR_N(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define FOR_R(i, b, e) for (int64_t i = int64_t(b); i < (int64_t)(e); i++)
int main() {
int64_t N, C;
cin >> N >> C;
vector<pair<int64_t, int64_t>> P(N * 2);
FOR_N(i, N) {
int64_t a, b, c;
cin >> a >> b >> c;
P[2 * i + 0] = make_pair(a, c);
P[2 * i + 1] = make_pair(b + 1, -c);
}
std::sort(P.begin(), P.end(), [](auto& a, auto& b) { return a.first < b.first; });
int64_t i = 0, cost = 0, paid = 0;
while (i < P.size()) {
const int64_t now = P[i].first;
while (i < P.size() && P[i].first <= now) {
cost += P[i++].second;
}
if (i < P.size()) {
paid += std::min(cost, C) * (P[i].first - now);
}
}
cout << paid << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define mnto(x, y) x = min(x, (__typeof__(x)) y)
#define mxto(x, y) x = max(x, (__typeof__(x)) y)
#define REP(i, s, e) for (int i = s; i < e; i++)
#define RREP(i, s, e) for (int i = s; i >= e; i--)
typedef long long ll;
typedef long double ld;
#define MP make_pair
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
#define MT make_tuple
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define pb emplace_back
typedef vector<int> vi;
typedef vector<ii> vii;
#define INF 1000000005
#define LINF 1000000000000000005
#define MOD 1000000007
#define MAXN 200005
int k, n, m;
ll a[MAXN], b[MAXN];
priority_queue<pll> pq;
int main() {
scanf("%d%d%d", &k, &n, &m);
REP (i, 0, k) {
scanf("%lld", &a[i]);
a[i] *= m;
}
int sum = 0;
REP (i, 0, k) {
b[i] = a[i] / n;
sum += b[i];
pq.push(MP(a[i] - b[i] * n, i));
}
int rem = m - sum;
REP (i, 0, rem) {
assert(!pq.empty());
auto [_, id] = pq.top(); pq.pop();
b[id]++;
}
REP (i, 0, k) {
printf("%lld ", b[i]);
}
printf("\n");
return 0;
}
|
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <cmath>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using P = pair<int,int>;
#define INF 1001001001
#define LINF (1LL<<60)
#define F first
#define S second
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<pair<double, double>> d(n);
double t;
rep(i, n) {
cin >> t >> d[i].first >> d[i].second;
if (t == 1) {
}
else if (t == 2) {
d[i].second -= 0.1;
}
else if (t == 3) {
d[i].first += 0.1;
}
else if (t == 4) {
d[i].first += 0.1;
d[i].second -= 0.1;
}
}
int ans = 0;
rep(i, n) {
rep(j, i) {
if (max(d[i].first, d[j].first) < min(d[i].second, d[j].second)+0.01) {
ans++;
}
}
}
cout << ans << endl;
}
| #include <iostream>
#include <cstdio>
#include <stdio.h>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <utility>
#include <numeric>
#define pb push_back
#define mk make_pair
#define endl "\n"
#define mod 1000000007
#define mod1 29996224275833
#define mul 31
#define PI 3.14159265358979323846264
//#include bits/stdc++.h
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
typedef long long int lli;
typedef long double ld;
typedef pair<lli,lli> ii;
//priority_queue <lli, vector<lli>, greater<lli> > ti;
//priority_queue<pair<lli,pair<lli,lli>>>e;
vector <lli> p[300005],f(300005),q[300005];
lli d[205];
//vector<set<lli>>s(200005);
//set<pair<lli,lli>>s;
//vector<vector<lli>> dp(200005,vector<lli>(25,0));
//vector<lli>f(10000005);
//lli b[1000005],l[1000005];
//vector<vector<lli>> d(300005,vector<lli>(18,0));
//vector<pair<lli,ii>>p[300005];
//map<pair<lli,lli>,lli>mp,np;
//vector<pair<pair<lli, lli>,lli> > st;
//queue<lli> qy;
//freopen("codecoder.in", "r", stdin);
//freopen("codecoder.out", "w", stdout);
lli gcd(lli a, lli b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
lli bpow(lli a, lli b) {
lli res = 1;
while (b > 0) {
if (b & 1)
res = (res * a)%mod;
a = (a * a)%mod;
//cout<<res<<" "<<a<<endl;
b >>= 1;
}
return res%mod;
}
void fact(lli i)
{
f[0]=1;
for(lli k=1;k<=i;k++)
{
(f[k]=f[k-1]*k)%=mod;
}
}
lli isprime(lli n)
{
if(n==1)
return 0;
for(lli i=2;i<=sqrt(n);i++)
if(n%i==0)
return 0;
return 1;
}
lli find(lli x)
{
if(f[x]==x)
return x;
else
return f[x]=find(f[x]);
}
bool cmp(lli x,lli y)
{
return x<y;
}
void check()
{
cout<<"HI"<<endl;
}
lli comb(lli i,lli j)
{
if(j>i)return 0;
lli k=f[i];
lli g=(f[j]*(f[i-j]))%mod;
lli h=bpow(g,mod-2);
return (k*h)%mod;
}
pair<ld,ld>az(ld a,ld b,ld c,ld d,ld u)
{
ld x1=(a-c)*cos(u)-(b-d)*sin(u)+c;
ld y1=(a-c)*sin(u)+(b-d)*cos(u)+d;
return {x1,y1};
}
/*void sieve()
{
for(lli i=2;i<=sqrt(10000000);i++)
{
if(b[i]==0)
{
k.pb(i);
for(lli j=2;i*j<=sqrt(10000000);j++)
{
b[i*j]=1;
}
}
}
}*/
int main ()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
lli t;t=1;
while(t--)
{
lli n;cin>>n;
vector<pair<ld,ld>>v;
for(lli i=1;i<=n;i++)
{
lli z;ld x,y;
cin>>z>>x>>y;
if(z==2)
{
y-=0.001;
}
else if(z==3)
{
x+=0.001;
}
else if(z==4)
{
x+=0.001;y-=0.001;
}
v.pb({x,y});
}
lli ans=0;
for(lli i=0;i<n;i++)
{
for(lli j=i+1;j<n;j++)
{
if((v[j].first<=v[i].second && v[j].first>=v[i].first)or (v[i].first<=v[j].second && v[i].first>=v[j].first) )
{
ans++;
}
}
}
cout<<ans<<endl;
}
}
|
#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<ll, ll>;
// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; debug_print(__VA_ARGS__); } while(false)
template<typename T, typename... Ts> void debug_print(const T &t, const Ts &...ts) { cerr << t; ((cerr << ", " << ts), ...); cerr << endl; }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, const T& b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, const T& b) { if (a < b) {a = b; return true; } return false; }
template<typename T, typename... Ts> void print(const T& t, const Ts&... ts) { cout << t; ((cout << ' ' << ts), ...); cout << '\n'; }
template<typename... Ts> void input(Ts&... ts) { (cin >> ... >> ts); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on
template<ll MOD = 1000000007>
class ModInt {
ll n;
ModInt constexpr inverse() const {
return ModInt::pow(*this, MOD - 2);
}
public:
ModInt() : n(0) {}
ModInt(ll _n) : n(((_n % MOD) + MOD) % MOD) {}
ModInt operator+=(const ModInt &m) {
n += m.n;
if (n >= MOD) n -= MOD;
return *this;
}
ModInt operator-=(const ModInt &m) {
n -= m.n;
if (n < 0) n += MOD;
return *this;
}
ModInt operator*=(const ModInt &m) {
n *= m.n;
if (n >= MOD) n %= MOD;
return *this;
}
ModInt operator/=(const ModInt &m) {
(*this) *= m.inverse();
return *this;
}
friend ModInt operator+(ModInt t, const ModInt &m) {
return t += m;
}
friend ModInt operator-(ModInt t, const ModInt &m) {
return t -= m;
}
friend ModInt operator*(ModInt t, const ModInt &m) {
return t *= m;
}
friend ModInt operator/(ModInt t, const ModInt &m) {
return t /= m;
}
ModInt operator=(const ll l) {
n = l % MOD;
if (n < 0) n += MOD;
return *this;
}
friend ostream &operator<<(ostream &out, const ModInt &m) {
out << m.n;
return out;
}
friend istream &operator>>(istream &in, ModInt &m) {
ll l;
in >> l;
m = l;
return in;
}
static constexpr ModInt pow(const ModInt x, ll p) {
ModInt<MOD> ans = 1;
for (ModInt<MOD> m = x; p > 0; p /= 2, m *= m) {
if (p % 2) ans *= m;
}
return ans;
}
};
using mint = ModInt<998244353>;
mint operator"" _m(unsigned long long m) {
return mint(m);
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n, m;
input(n, m);
mint ans = mint::pow(m, n) * n;
vector<mint> memo(n, 0);
vector<bool> used(n, false);
rep(i, 0, n) {
rep(j, 0, i) {
mint t = 0;
if (used[i - j - 1]) {
t = memo[i - j - 1];
} else {
rep(k, 0, m) {
t += mint::pow(m - k - 1, i - j - 1);
}
used[i - j - 1] = true;
memo[i - j - 1] = t;
}
ans -= t * mint::pow(m, n - (i - j) - 1);
}
}
print(ans);
return 0;
}
| #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long int ;
using P = pair<ll,ll>;
using Graph= vector<vector<ll>>;
struct edge{ll to ; ll cost ;} ;
using graph =vector<vector<edge>> ;
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
#define fi first
#define se second
#define set20 cout<<fixed<<setprecision(20) ;
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
long double pi=acos(-1) ;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
ll dx[4] {1,0,-1,0} ;
ll dy[4] {0,1,0,-1} ;
int main(){
ios::sync_with_stdio(false) ;
cin.tie(nullptr) ;
vector<string> A(3) ;
rep(i,3) cin>>A[i] ;
map<char,vector<P>> mp ;
rep(i,3){
string x= A[i] ;
ll k= x.size() ;
rep(j,k){
mp[A[i][j]].pb(mpa(i,j)) ;
}
}
ll cnt=mp.size() ;
vector<vector<P>> B(cnt) ;
ll i=0 ;
for(auto u :mp){
for(auto v:u.se){
B[i].pb(v) ;
}
i++ ;
}
if(cnt>10){
cout<<"UNSOLVABLE"<<endl ;
return 0;
}
vector<ll> now(10) ;
rep(i,10) now[i]=i ;
do{
ll d[3][15] ;
rep(a,3)rep(b,15) d[a][b]=-1 ;
rep(i,cnt){
for(auto x:B[i]){
d[x.fi][x.se]=now[i] ;
}
}
if(d[0][0]==0 || d[1][0]==0 ||d[2][0]==0) continue ;
vector<ll> e(3) ;
rep(ww,3){
ll num=0 ;
rep(pp,15){
if(d[ww][pp]==-1) break ;
num*=10ll ;
num+=d[ww][pp] ;
}
e[ww]=num ;
}
if(e[0]+e[1]==e[2]){
rep(unti,3){
cout<<e[unti]<<endl ;
}
return 0;
}
}while(next_permutation(now.begin(),now.end())) ;
cout<<"UNSOLVABLE"<<endl ;
return 0 ;
}
|
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <complex>
#define ll long long
#define inf 1e9 + 6
#define sinf 1e15 + 500
#define ld long double
#define ull unsigned long long
#define poll complex<double>
#define line pair<poll, poll>
#define pi acos(-1)
#define lp(a, b, c, d) for (ll a = b; a < c; a += d)
#define endl '\n'
#define EPS 1e-12
#define IO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL); \
// freopen("sum.in", "r", stdin);
#define mod 998244353
using namespace std;
const ll N = 2e5 + 5, SEG = (1 << 14);
int n;
vector<pair<int,int>>v;
vector<pair<int,int>>loc;
ll dp[N][2];
ll solve(int las,bool w)
{
if(las==loc.size()-1)
{
if(w)return abs(v[loc[las].second].first);
else return abs(v[loc[las].first].first);
}
ll &ret=dp[las][w];
if(ret!=-1)return ret;
ll x;
if(w)x=v[loc[las].second].first;
else x=v[loc[las].first].first;
return ret=min(solve(las+1,0)+abs(v[loc[las+1].second].first-x)+abs(v[loc[las+1].second].first-v[loc[las+1].first].first) ,
solve(las+1,1)+abs(v[loc[las+1].first].first-x)+abs(v[loc[las+1].second].first-v[loc[las+1].first].first)
);
}
int main()
{
IO
cin>>n;
int a,b;
memset(dp,-1,sizeof(dp));
for(int i=0;i<n;i++)
{
cin>>a>>b;
v.push_back({a,b});
}
sort(v.begin(),v.end(),[](pair<int,int>a,pair<int,int>c){
if(a.second==c.second)return a.first<c.first;
else return a.second<c.second;
});
v.insert(v.begin(),{0,0});
loc.push_back({0,0});
for(int i=1;i<v.size();i++)
{
if(v[i].second!=v[i-1].second)
{
loc.push_back({i,i});
}
else loc.back().second=i;
}
cout<<solve(0,0)<<endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long int
#define rep(i, a, b) for (int i = a; i < b; i++)
#define revrep(i, a, b) for (int i = a; i >= b; i--)
#define pb push_back
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
const int INF = 1e18;
const int mod = 1e9+7;
ostream &operator<<( ostream &output, const pii &p ) { output << p.first << " " << p.second;return output; }
istream &operator>>( istream &input, pii &p ) { input >> p.first >> p.second;return input; }
template<typename T>
void inline println(vector<T> args){ for(T i: args)cout<<i<<" ";cout<<endl; }
int power(int a, int b) {
if (b == 0)
return 1;
int res = power(a, b / 2);
if (b % 2)
return (res * res * a);
else
return (res * res);
}
void solve() {
int h, w, n, m; cin>>h>>w>>n>>m;
set<int> row[h+1], col[w+1];
rep(i, 1, h+1) {
row[i].insert(0);
row[i].insert(w+1);
}
rep(i, 1, w+1) {
col[i].insert(0);
col[i].insert(h+1);
}
vii bulbs(n);
rep(i, 0, n) cin>>bulbs[i];
rep(i, 0, m) {
int x, y; cin>>x>>y;
row[x].insert(y);
col[y].insert(x);
}
int preRow[h+2][w+2] = {};
int preCol[h+2][w+2] = {};
int mat[h+2][w+2] = {};
for(auto bulb: bulbs) {
int x = bulb.first;
int y = bulb.second;
auto temp = col[y].upper_bound(x);
int greaterRow = *temp;
int lesserRow = *prev(temp);
temp = row[x].upper_bound(y);
int greaterCol = *temp;
// for(int i: col[x]) cout<<i<<" ";
// cout<<endl;
int lesserCol = *prev(temp);
preCol[lesserRow+1][y] ++;
preCol[greaterRow][y] --;
preRow[x][lesserCol+1] ++;
preRow[x][greaterCol] --;
}
rep(j, 0, w+1) {
rep(i, 0, h+1) {
if(i-1 >= 0)
preCol[i][j] += preCol[i-1][j];
mat[i][j] += preCol[i][j];
}
}
rep(i, 0, h+1) {
rep(j, 0, w+1) {
if(j-1 >= 0)
preRow[i][j] += preRow[i][j-1];
mat[i][j] += preRow[i][j];
}
}
int ans = 0;
rep(i, 0, h+2) {
rep(j, 0, w+2)
if(mat[i][j]) ans++;
}
cout<<ans<<endl;
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
// cin >> t;
while (t--)
{
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define fr(i,n) for(int i = 0; i<n; i++)
#define sz(v) (int)(v.size())
#define prin(a) cout << #a << " = " << a << endl
#define prinv(v) cout << #v << " = "; for(auto it : v) cout << it << ", "; cout << endl
#define all(v) (v).begin(),(v).end()
typedef long long ll;
#define rmin(a,b) a = min<ll>(a,b)
#define rmax(a,b) a = max<ll>(a,b)
#define fi first
#define se second
template <class T>
T fp(T x, long long e) {
T ans(1);
for(; e > 0; e /= 2) {
if(e & 1) ans = ans * x;
x = x * x;
}
return ans;
}
const ll mod = round(1e9)+7;
struct mb {
mb(int v = 0) : val(v < 0 ? v + mod : v) {}
mb(ll v){ val = (v%mod+mod)%mod; }
int val;
void operator += (mb o) { *this = *this + o; }
void operator -= (mb o) { *this = *this - o; }
void operator *= (mb o) { *this = *this * o; }
mb operator * (mb o) { return (int)((long long) val * o.val % mod); }
mb operator / (mb o) { return *this * fp(o, mod - 2); }
//bool operator == (mb o) { return val==o.val; } //usar soh para hashes
mb operator + (mb o) { return val + o.val >= mod ? val + o.val - mod : val + o.val; }
mb operator - (mb o) { return val - o.val < 0 ? val - o.val + mod : val - o.val; }
};
const int NFAT = 20;
mb fat[NFAT], invfat[NFAT];
mb nck(int n, int k){
assert(n>=k);
return fat[n]*invfat[k]*invfat[n-k];
}
const int N = 2e5+10;
int v[N];
mb pot[20][N];
int n;
int va[N];
ll ans_brute = 0;
ll K;
bool check(){
ll soma = 0;
fr(i,n) soma+=va[i];
if(!soma) return 0;
fr(i,n){
if(va[i]!=v[i]){
if(va[i]<v[i]) break;
return 0;
}
}
set<int> st;
int i = 0;
while(i<n and va[i]==0) i++;
for(;i<n; i++) st.insert(va[i]);
return sz(st)==K;
}
void go(int i){
if(i==n){
if(check()) ans_brute++;
return;
}
int minv = 16;
if(i==0) minv = v[i]+1;
fr(val,minv){
va[i] = val;
go(i+1);
}
}
int ton(char c){
if(c>='0' and c<='9') return c-'0';
return 10+c-'A';
}
int vis[20][20][N];
mb dp[20][20][N];
mb rec(int ja_usei, int need_usar, int n){
int delt = need_usar-ja_usei;
if(delt>n) return 0;
if(n==0) return delt==0;
mb &ans = dp[ja_usei][need_usar][n];
if(vis[ja_usei][need_usar][n]) return ans;
vis[ja_usei][need_usar][n] = 1;
if(ja_usei) ans += rec(ja_usei,need_usar,n-1)*ja_usei;
if(ja_usei<need_usar) ans += rec(ja_usei+1,need_usar,n-1)*(need_usar-ja_usei);
return ans;
}
mb ways_use(ll k, ll n){
return rec(0,k,n);
assert(vis[0][k][n]);
return dp[0][k][n];
if(k==0){
if(n==0) return 1;
return 0;
}
if(k>n) return 0;
assert(k>=1 and k<=16);
return pot[k][n]-pot[k-1][n]*k;
}
int main(){
ios::sync_with_stdio(0); cin.tie(0);
fat[0] = invfat[0] = mb(1);
for(int i = 1; i<NFAT; i++){
fat[i] = mb(i)*fat[i-1];
invfat[i] = mb(1)/fat[i]; //fp(fat[i],MOD-2);
}
for(ll val = 1; val<=16; val++){
pot[val][0] = 1;
for(int i = 1; i<N; i++) pot[val][i] = pot[val][i-1]*val;
}
string s; cin >> s;
cin >> K;
n = sz(s);
//prin(n);
fr(i,sz(s)) v[i] = ton(s[i]);
mb ans = 0;
vector<int> freq(16);
int ndif = 0;
mb aux = 0;
fr(i,n){
//prin(i);
//prin(v[i]);
mb cur = 0;
fr(val,16){
if(val==0 and i==0) continue;
if(val>=v[i]) break;
ll nrest = n-i-1;
int curdif = ndif;
if(!freq[val]) curdif++;
if(curdif>K) continue;
//prin(val);
ll need_add = K-curdif;
for(ll add = need_add; add<=K; add++){
ans += nck(16-curdif,need_add)*nck(curdif,add-need_add)*ways_use(add,nrest);
}
//return 0;
}
//prin(cur.val);
//prin(ans.val);
freq[v[i]]++;
if(freq[v[i]]==1) ndif++;
if(ndif>K) break;
}
//prin(aux.val);
if(ndif==K) ans += 1;
if(n>=2){
for(int i = 1; i<n; i++){
fr(val,16){
if(val==0) continue;
ll nrest = n-i-1;
int curdif = 1;
if(curdif>K) continue;
ll need_add = K-curdif;
for(ll add = max<ll>(0,need_add); add<=K; add++){
ans += nck(16-curdif,need_add)*nck(curdif,add-need_add)*ways_use(add,nrest);
}
}
}
}
//prin(ans.val);
cout << ans.val << "\n";
} | #include<bits/stdc++.h>
#define int long long
#define double long double
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define x first
#define y second
using namespace std;
using pi = pair<int,int>;
const int inf = 0x3f3f3f3f3f3f3f3f;
const int minf = 0xc0c0c0c0c0c0c0c0;
const int mod = 1e9+7;
int A[200200];
int dp[200200][20];
int c2i(char c) {
if (c >= '0' && c <= '9') return c-'0';
return c-'A'+10;
}
void add(int &ref, int val) {
ref = (ref+val)%mod;
}
signed main() {
ios::sync_with_stdio(0); cin.tie(0);
cout<<fixed<<setprecision(10);
string s; int k; cin>>s>>k;
int n = sz(s);
for (int i=0; i<n; i++) {
A[i] = c2i(s[i]);
}
dp[0][1] = A[0] - 1;
int bit = 1<<A[0];
for (int i=1; i<n; i++) {
for (int j=1; j<=16; j++) {
add(dp[i][j], dp[i-1][j]*j);
add(dp[i][j+1], dp[i-1][j]*(16-j));
}
add(dp[i][1], 15);
for (int j=0; j<A[i]; j++) {
add(dp[i][__builtin_popcountll(bit|(1<<j))], 1);
}
bit |= 1<<A[i];
}
if (__builtin_popcountll(bit) == k) add(dp[n-1][k], 1);
cout<<dp[n-1][k]<<'\n';
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e3 + 10;
int n, x[MAXN], y[MAXN], ans;
int read()
{
int sum = 0, fh = 1; char ch = getchar();
while (ch < '0' || ch > '9') {if (ch == '-') fh = -1; ch = getchar();}
while (ch >= '0' && ch <= '9') {sum = (sum << 3) + (sum << 1) + (ch ^ 48); ch = getchar();}
return sum * fh;
}
int main()
{
n = read();
for (int i = 1; i <= n; ++i) x[i] = read(), y[i] = read();
for (int i = 1; i <= n; ++i)
for (int j = i + 1; j <= n; ++j)
{
if ((double)(y[j] - y[i]) / (x[j] - x[i]) >= -1 && (double)(y[j] - y[i]) / (x[j] - x[i]) <= 1) ans++;
}
cout << ans << "\n";
return 0;
} | #include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <numeric>
#include <iomanip>
#include <algorithm>
using namespace std;
int main(void) {
double n, d, h,nd,nh,rus;
rus = 0.0;
cin >> n >> d >> h;
for (int i = 0;i < n;i++) {
cin >> nd >> nh;
if (((h - nh)*(-1.0)*nd / (d - nd)) + nh >= rus) {
rus = ((h - nh)*(-1.0)*nd / (d - nd)) + nh;
}
}
cout << fixed << setprecision(10) << rus << endl;
} |
#include <bits/stdc++.h>
#ifndef ONLINE_JUDGE
#define debug(x) cout << #x << ": " << (x) << endl
#else
#define debug(x)
#endif
using namespace std;
typedef long long ll;
typedef vector<int> vi;
const int maxn=1e6+7,inf=0x3f3f3f3f,mod=1e9+7;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
ll b,c;
cin>>b>>c;
ll pmx,pmi,nmx,nmi;
if(b<0)
{
nmi=b-c/2;
pmi=(-b)-(c-1)/2;
pmx=max(-b+c/4+(c%4>=3),-nmi-((c%2)?0:1));
nmx=max(b+(c-1)/4+((c-1)%4>=3),-pmi-(((c-1)%2)?0:1));
}
else if(b>0)
{
nmi=-b-(c-1)/2;
pmi=b-(c)/2;
pmx=max(b+(c-1)/4+((c-1)%4>=3),-nmi-(((c-1)%2)?0:1));
nmx=max(-b+c/4+(c%4>=3),-pmi-((c%2)?0:1));
}
else if(b==0)
{
nmi=-b-(c)/2;
pmi=0;
pmx=-nmi-(((c)%2)?0:1);
nmx=0;
}
cout<<pmx-pmi+1+nmx-nmi+1-max(0ll,nmx-pmi+1);
return 0;
}
| /*#include<bits/stdc++.h>
using namespace std;
long long b,c,sub,ans;
int main()
{
scanf("%lld%lld",&b,&c);
sub=c/2;
if(c&1)
{
ans=(sub+1)*2ll;
if(b-sub<=0&&0<=b) ans--;
}
else
{
ans=sub*2ll+1;
if(b-(sub-1)<=0&&0<=b) ans--;
}
if(b>0&&b-sub<0) ans-=min(b,sub-b);//max(abs(b),abs(b-sub))-min(abs(b),abs(b-sub));
printf("%lld\n",ans);
return 0;
}*/
#include<bits/stdc++.h>
using namespace std;
long long b,c,sub,ans;
long long l[5],r[5];
int main()
{
scanf("%lld%lld",&b,&c);
sub=c/2;
l[1]=b-sub;r[1]=b;
if(c&1) l[2]=-b,r[2]=sub-b;
else l[2]=-b,r[2]=sub-b-1;
if(c&1) l[3]=-b-sub,r[3]=-b;
else l[3]=-b-sub+1,r[3]=-b;
l[4]=b,r[4]=b+sub-1;
//for(int i=1;i<=4;i++) printf("%lld %lld\n",l[i],r[i]);
for(int i=3;i>=1;i--)
for(int j=i+1;j<=4;j++)
{
if(l[i]<=l[j]&&l[j]<=r[i]&&r[i]<=r[j])
r[i]=r[j],l[j]=0,r[j]=-1;
else if(l[j]<=l[i]&&l[i]<=r[j]&&r[j]<=r[i])
l[i]=l[j],l[j]=0,r[j]=-1;
else if(l[i]<=l[j]&&l[j]<=r[j]&&r[j]<=r[i])
l[j]=0,r[j]=-1;
else if(l[j]<=l[i]&&l[i]<=r[i]&&r[i]<=r[j])
l[i]=l[j],r[i]=r[j],l[j]=0,r[j]=-1;
}
//for(int i=1;i<=4;i++) printf("%lld %lld\n",l[i],r[i]);
for(int i=1;i<=4;i++) ans+=r[i]-l[i]+1;
printf("%lld\n",ans);
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
void Main();
using i8 = int8_t; /* -128 ~ 127 */
using u8 = uint8_t; /* 0 ~ 255 */
using i16 = int16_t; /* -32,768 ~ 32,767 */
using u16 = uint16_t; /* 0 ~ 65,535 */
using i32 = int32_t; /* -2,147,483,648 ~ 2,147,483,647 */
using u32 = uint32_t; /* 0 ~ 4,294,967,295 */
using i64 = int64_t; /* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */
using u64 = uint64_t; /* 0 ~ 18,446,744,073,709,551,615 */
using f32 = float; /* (-3.4 * 10^38) ~ (3.4 * 10^38) */
using f64 = double; /* (-1.7 * 10^308) ~ (1.7 * 10^308) */
using f80 = __float80;
template <class T> using Vec = vector<T>;
constexpr i64 INF = 1010000000000000017;
constexpr i64 MOD = 1e9 + 7;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define ALL(v) v.begin(), v.end()
#define YN(a, b, c) ((c)? a : b)
#define GCD(a, b) __gcd(a, b) /* 最大公約数 */
#define LCM(a, b) (i64)(a / (f64)__gcd(a, b) * b) /* 最小公倍数 */
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(15);
Main();
return 0;
}
void Main() {
i32 N;
string S;
cin >> N >> S;
i32 ans = 0;
Vec<char> t;
for (i32 i = 0; i < N; i++) {
t.push_back(S[i]);
i32 n = t.size();
if (n >= 3 && t[n - 1] == 'x' && t[n - 2] == 'o' && t[n - 3] == 'f') {
ans++;
t.pop_back();
t.pop_back();
t.pop_back();
}
}
cout << t.size() << endl;
}
| #include <bits/stdc++.h>
#define debug(x) cerr << #x << " = " << x << endl
using namespace std;
typedef long long LL;
const int MAXN = 2E5 + 5;
const int MOD = 1E9 + 7;
string t;
int n;
stack<int> s;
template <class T>
void read(T& x) {
x = 0;
T f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') f = (ch == '-' ? -1 : 1), ch = getchar();
while (ch >= '0' && ch <= '9') x = x * 10 + ch - 48, ch = getchar();
x *= f;
}
template <class T, class... Args>
void read(T& x, Args&... args) {
read(x), read(args...);
}
template <class T>
void write(T x) {
if (x < 0) putchar('-'), x = -x;
if (x > 9) write(x / 10);
putchar(x % 10 + '0');
}
LL qpow(LL a, LL b, LL MOD) {
LL ans = 1, base = a;
while (b) {
if (b & 1) ans = ans * base % MOD;
b >>= 1, base = base * base % MOD;
}
return ans;
}
void solve(int testNum) {
// type your code here
read(n);
cin >> t;
for (int i = 0; i < t.size(); i++) {
if (t[i] == 'x') {
if (s.size() >= 2) {
int fir = s.top();
s.pop();
int sec = s.top();
s.pop();
if (t[sec] != 'f' || t[fir] != 'o')
s.push(sec), s.push(fir), s.push(i);
} else
s.push(i);
}else s.push(i);
}
cout << s.size();
}
signed main() {
// freopen("1.in", "r", stdin);
int testCase = 1;
// read(testCase);
for (int i = 1; i <= testCase; i++) solve(i);
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int N,i=0,a;
cin>>N;
a=log10(i)+1;
while(i+i*pow(10,a)<=N){
i++;
a=log10(i)+1;
}
cout<<i-1<<endl;
}
| #include<bits/stdc++.h>
using namespace std;
string a;
int main()
{
cin>>a;
for(int i=0;i<a.size();i++)
{
if(a[i]!='.') cout<<a[i];
else break;
}
return 0;
} |
//#pragma GCC optimize ("O2")
//#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
#include<cstdio>
#include<cstring>
#include<algorithm>
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 b = 8;
int A[100000];
int tmp[100001];
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 (*ci++ == '0') {
tmp = tmp * 10;
ci++;
}
}
}
return tmp;
}
void okuri() {
if (ci - owa > 0) {
memcpy(cn, owa, CL);
ci -= CM;
fread(cn + CL, 1, CM, stdin);
}
ll tmp = *(ll*)ci;
if ((tmp & ma0) ^ ma0) {
ci += 4 + __builtin_ctzll((tmp & ma0) ^ ma0) >> 3;
}
else {
ci += 8;
tmp = *(ll*)ci;
ci += 4 + __builtin_ctzll((tmp & ma0) ^ ma0) >> 3;
}
}
const int dm = 1 << 17;
char dn[dm], * di = dn;
const char f[10] = "First\n";
const char s[10] = "Second\n";
int main() {
//cin.tie(0);
//ios::sync_with_stdio(false);
int T = getint();
int are = 1 << 14;
int owa = are;
rep(t, T) {
int N = getint();
if (N % 2) {
rep(i, N) okuri();
memcpy(di, s, 7);
di += 7;
}
else {
rep(i, N) A[i] = getint();
if (N > 256) {
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];
}
}
else sort(A, A + N);
int mae = 0, k = 0;
rep(i, N) {
if (mae == A[i]) k++;
else {
if (k & 1) break;
k = 1;
mae = A[i];
}
}
if (k & 1) {
memcpy(di, f, 6);
di += 6;
}
else {
memcpy(di, s, 7);
di += 7;
}
}
if (t > owa) {
owa += are;
fwrite(dn, 1, di - dn, stdout);
di = dn;
}
}
fwrite(dn, 1, di - dn, stdout);
Would you please return 0;
} | #include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define mod 1000000007
#define ad(a,b) a=(a+b)%mod;
#define X 5010
ll po(ll x,ll y){
ll res=1;
for(;y;y>>=1){
if(y&1)res=res*x%mod;
x=x*x%mod;
}
return res;
}
ll fac[X],ivf[X];
void init(){
fac[0]=1;
for(ll i=1;i<X;i++)fac[i]=fac[i-1]*i%mod;
for(ll i=0;i<X;i++)ivf[i]=po(fac[i],mod-2);
}
ll C(ll n,ll k){
return fac[n]*ivf[n-k]%mod*ivf[k]%mod;
}
ll gcd(ll a,ll b){
return (b?gcd(b,a%b):a);
}
ll n,a[100010];
void solve(){
cin>>n;
rep(i,n)cin>>a[i];
sort(a,a+n);
bool ok=1;
if(n%2==1)ok=0;
else{
rep(i,n/2)ok&=(a[i*2]==a[i*2+1]);
}
if(n%2==0)ok^=1;
cout<<(ok?"First":"Second")<<endl;
}
int main(){
cin.tie(0);
ios::sync_with_stdio(0);
ll t;
cin>>t;
while(t--)solve();
}
|
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
if(n%2 == 0) {
cout << "White" << endl;
} else {
cout << "Black" << endl;
}
return 0;
} | #include <iostream>
#include <string>
#include <algorithm>
#include <deque>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(void){
int n;
cin >> n;
cout << (n-1)/100+1 << endl;
} |
#include <bits/stdc++.h>
#define INF 1e9
#define INFLL 1ull<<60u
using namespace std;
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a) (a).begin(),(a).end()
#define endl "\n"
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
typedef long long ll;
using vi = vector<int>;
using vvi = vector<vi>;
using vpii = vector<pair<int,int>>;
class UnionFind {
public:
vector <ll> par; // 各元の親を表す配列
vector <map<int,int>> siz; // 素集合のサイズを表す配列(1 で初期化)
// Constructor
UnionFind(ll sz_): par(sz_), siz(sz_,map<int,int>()) {
for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
}
void init(const vector<int>& classes) {
REP(i,classes.size()) {
siz[i][classes[i]] = 1;
}
}
// Member Function
// Find
ll root(ll x) { // 根の検索
while (par[x] != x) {
x = par[x] = par[par[x]]; // x の親の親を x の親とする
}
return x;
}
// Union(Unite, Merge)
bool merge(ll x, ll y) {
x = root(x);
y = root(y);
if (x == y) return false;
// merge technique(データ構造をマージするテク.小を大にくっつける)
if (siz[x].size() < siz[y].size()) swap(x, y);
for(const auto &p: siz[y]) {
auto [v,cnt] = p;
siz[x][v] += cnt;
}
par[y] = x;
return true;
}
bool issame(ll x, ll y) { // 連結判定
return root(x) == root(y);
}
// 生徒、クラス
ll size(ll x,int y) { // 素集合のサイズ
return siz[root(x)][y];
}
};
void solve() {
int N,Q; cin >> N >> Q;
UnionFind uf(N);
vector<int> css(N);
REP(i,N) cin >> css[i];
uf.init(css);
REP(_,Q) {
int a,b,c; cin >> a >> b >> c;
if (a == 1) {
b--; c--;
uf.merge(b,c);
} else {
b--;
cout << uf.size(b,c) << endl;
}
}
}
int main() {
solve();
return 0;
} | #include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <time.h>
#include <queue>
#include <stdarg.h>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <stack>
#include <iostream>
#include <numeric>
#include <set>
#define ll long long
using namespace std;
ll
getColor(vector<ll> & color, ll i) {
ll end = i;
while (color[end] != end) end = color[end];
ll mid = i;
while (color[mid] != end) {
ll temp = color[mid];
color[mid] = end;
mid = temp;
}
return end;
}
void
solve() {
ll n, q;
cin>>n>>q;
ll c;
vector<ll> color(n + 1);
map<ll, ll> current[200005];
for (ll i=1; i<=n; i++) {
cin>>c;
color[i] = i;
current[i][c] = 1;
}
ll x, y, z;
for (ll i=0; i<q; i++) {
cin>>x>>y>>z;
if (x == 1) {
ll left = getColor(color, y);
ll right = getColor(color, z);
if (left != right) {
if (current[left].size() > current[right].size()) {
color[right] = left;
for (auto & p : current[right]) current[left][p.first] += p.second;
}
else {
color[left] = right;
for (auto & p : current[left]) current[right][p.first] += p.second;
}
}
}
else {
ll end = getColor(color, y);
cout<<current[end][z]<<endl;
}
}
}
int
main() {
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
int t = 1;
//cin>>t;
while (t > 0) {
t--;
solve();
}
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
inline int Read() {
int x = 0, f = 1; char ch = getchar();
while(!isdigit(ch)) {if(ch == '-') f = -1; ch = getchar();}
while(isdigit(ch)) {x = (x << 3) + (x << 1) + ch - '0'; ch = getchar();}
return x * f;
}
double f[105][105][105];
signed main() {
for(int i = 99; i >= 0; i--)
for(int j = 99; j >= 0; j--)
for(int k = 99; k >= 0; k--) {
f[i][j][k] += i * 1.0 / (i + j + k) * f[i + 1][j][k];
f[i][j][k] += j * 1.0 / (i + j + k) * f[i][j + 1][k];
f[i][j][k] += k * 1.0 / (i + j + k) * f[i][j][k + 1];
f[i][j][k] = f[i][j][k] + 1;
}
int a = Read(), b = Read(), c = Read();
printf("%.9lf\n", f[a][b][c]);
return 0;
} | #include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl '\n'
#define all(A) (A).begin(),(A).end()
#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 traceA(A,x) cerr<<#A<<": ";for(int i = 0; i < (x) ; ++i) cerr<<A[i]<<' ';cerr<<endl
#define traceV(A) cerr<<#A<<": ";for(auto i:A)cerr<<i<<' ';cerr<<endl
#define traceM(A,n,m) cerr<<#A<<": "<<endl;for(int i = 0; i < (n) ; ++i){for(int j = 0; j < (m) ; ++j) cerr << A[i][j] << ' ';cerr << endl;}
typedef long long int ll;
typedef long double ld;
using namespace std;
const int N = 2e5 + 77;
int A[N];
void sol(){
int a , b , c ; cin >> a >> b >> c ;
if(a*a + b*b < c*c) cout << "Yes" << endl;
else cout << "No" << endl;
}
int32_t main(){
fast;
int t = 1;
// cin >> t;
while(t--) sol();
return 0;
} |
//Bismillahir Rahmanir Rahim
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<int, int>> vpi;
#define pb push_back
#define pf push_front
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define ff first
#define ss second
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define Tcase() int tcc; cin >> tcc; while(tcc--)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define F0R(i, a) FOR(i, 0, a)
const ll MOD = 998244353;
const ll INF = 9e18;
const int MX = 2e5 + 5;
const ld PI = acos((ld) -1);
const int dx[8] = {0, 1, 0, -1, 1, -1, 1, -1};
const int dy[8] = {1, 0, -1, 0, 1, -1, -1, 1};
void setIO(string name = "") {
ios_base::sync_with_stdio(0); cin.tie(0);
if(sz(name)){
freopen((name+".in").c_str(), "r", stdin);
freopen((name+".out").c_str(), "w", stdout);
}
}
int main(){
setIO();
int a, b, c, d;
cin >> a >> b >> c >> d;
cout << min({a, b, c, d});
}
| #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define cases() ll t;cin>>t;while(t--)
#define pb push_back
#define ff first
#define ss second
#define light ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const ll MAX = 1e5+5;
const ll INF = 1e18;
const ll MOD = 1e9+7 ;
int main()
{
vector<int> a(4);
int i;
for(i=0;i<4;i++)
cin >> a[i];
cout << *min_element(a.begin(),a.end());
} |
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
constexpr int DEBUG = 0;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int num_cases;
cin >> num_cases;
for (int case_id = 0; case_id < num_cases; case_id++) {
int64 l, r;
cin >> l >> r;
int64 base_count = r - l - l + 1;
if (base_count < 0) {
cout << 0 << endl;
} else {
cout << base_count * (base_count + 1) / 2 << endl;
}
}
} | #include <bits/stdc++.h>
using namespace std;
template <int mod = (int)(1e9 + 7)>
struct ModInt {
int x;
constexpr ModInt() : x(0) {}
constexpr ModInt(int64_t y)
: x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
constexpr ModInt &operator+=(const ModInt &p) noexcept {
if ((x += p.x) >= mod) x -= mod;
return *this;
}
constexpr ModInt &operator-=(const ModInt &p) noexcept {
if ((x += mod - p.x) >= mod) x -= mod;
return *this;
}
constexpr ModInt &operator*=(const ModInt &p) noexcept {
x = (int)(1LL * x * p.x % mod);
return *this;
}
constexpr ModInt &operator/=(const ModInt &p) noexcept {
*this *= p.inverse();
return *this;
}
constexpr ModInt operator-() const { return ModInt(-x); }
constexpr ModInt operator+(const ModInt &p) const noexcept {
return ModInt(*this) += p;
}
constexpr ModInt operator-(const ModInt &p) const noexcept {
return ModInt(*this) -= p;
}
constexpr ModInt operator*(const ModInt &p) const noexcept {
return ModInt(*this) *= p;
}
constexpr ModInt operator/(const ModInt &p) const noexcept {
return ModInt(*this) /= p;
}
constexpr bool operator==(const ModInt &p) const noexcept { return x == p.x; }
constexpr bool operator!=(const ModInt &p) const noexcept { return x != p.x; }
constexpr ModInt inverse() const noexcept {
int a = x, b = mod, u = 1, v = 0, t = 0;
while (b > 0) {
t = a / b;
swap(a -= t * b, b);
swap(u -= t * v, v);
}
return ModInt(u);
}
constexpr ModInt pow(int64_t n) const {
ModInt res(1), mul(x);
while (n) {
if (n & 1) res *= mul;
mul *= mul;
n >>= 1;
}
return res;
}
friend constexpr ostream &operator<<(ostream &os, const ModInt &p) noexcept {
return os << p.x;
}
friend constexpr istream &operator>>(istream &is, ModInt &a) noexcept {
int64_t t = 0;
is >> t;
a = ModInt<mod>(t);
return (is);
}
constexpr int get_mod() { return mod; }
};
int main() {
int t;
cin >> t;
while (t--) {
long long n, a, b;
cin >> n >> a >> b;
if (a > b) swap(a, b);
ModInt<> aall = (n - a + 1), ball = (n - b + 1), cross = 0, res = 0;
res = aall.pow(2) * ball.pow(2);
cross = (b - a + 1) * (n - b + 1);
long long l = b + 1, r = min(n, a + b - 1);
auto sum = [](long long x) { return x * (1 + x) / 2; };
if (l <= r) cross += (sum(n - l + 1) - sum(n - r)) * 2;
res -= cross * cross;
cout << res << endl;
}
return 0;
} |
#include <bits/stdc++.h>
#define F first
#define S second
#define MAX 10000003
using namespace std;
#define ll long long int
#include<fstream>
#define fast ios_base::sync_with_stdio(false);
#define io cin.tie(NULL);
#define inp(arr,n) for(ll i=0;i<n;i++){cin>>arr[i];}
#define print(arr,n) for(ll i=0;i<n;i++){cout<<arr[i]<<" ";}
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define MOD 1000000007
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;
}
int main()
{
ll t;
t=1;
while(t--)
{
ll a,b;
cin>>a>>b;
if(a>=b)
{
for(ll i=1;i<=a;i++)
cout<<i<<" ";
for(ll i=1;i<=b-1;i++)
cout<<-i<<" ";
ll sum=0;
for(ll i=b;i<=a;i++)
sum+=i;
cout<<-sum<<endl;
}
if(a<b)
{
for(ll i=1;i<=b;i++)
cout<<-i<<" ";
for(ll i=1;i<=a-1;i++)
cout<<i<<" ";
ll sum=0;
for(ll i=a;i<=b;i++)
sum+=i;
cout<<sum<<endl;
}
}
return 0;
}
| #include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <set>
//#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define all(v) v.begin(), v.end()
#define front(v) *v.begin()
#define back(v) *(--v.end())
#define len(v) v.size()
#define int long long
using longl = long long;
using longd = long double;
const longl INF = 1e9;
const longl LINF = 1e18;
const longl mod = 1e9 + 7;
const double PI = acos(-1);
//------------------------------------------------------------------------------------------------
longl divup(longl a, longl b){
return (a + b - 1) / b;
}
longl bin_pow(longl a, longl b){
longl res = 1;
while (b > 0){
if (b % 2)
res = res * a % mod;
a = a * a % mod;
b /= 2;
}
return res;
}
//------------------------------------------------------------------------------------------------
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int a, b;
cin >> a >> b;
int n;
int k;
if (a > b) {
n = a;
k = 1;
}
else {
n = b;
k = -1;
}
int sum = 0;
int sum2 = 0;
vector<int> tmp;
for (int i = 0; i < n; i++){
cout << (i + 1) * k << ' ';
sum += (i + 1) * k;
if (i < min(a, b) - 1){
cout << -((i + 1) * k) << ' ';
}
else {
sum2 += (i + 1) * k;
}
}
cout << -sum2;
return 0;
} |
#include <bits/stdc++.h>
#define LL long long
#define ULL unsigned long long
#define pb push_back
#define st first
#define nd second
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
template <class T> T read(T &a) {
a=0;char x=getchar();bool f=0;
for(;x<'0'||x>'9';x=getchar())f|=x=='-';
for(;x>='0'&&x<='9';x=getchar())a=(a<<3)+(a<<1)+x-'0';
if(f)a=-a;
return a;
}
using namespace std;
const int N = 2e5 + 5, MOD = 998244353;
LL pre[N << 1], apre[N << 1];
int n, m;
LL qpow(LL a, LL b = MOD - 2) {
LL ans = 1;
while (b) {
if (b & 1) {
ans = ans * a % MOD;
}
a = a * a % MOD;
b >>= 1;
}
return ans;
}
void init() {
pre[0] = 1;
apre[0] = qpow(pre[0]);
for (int i = 1; i <= N * 2; ++i) {
pre[i] = pre[i - 1] * i % MOD;
apre[i] = qpow(pre[i]);
}
}
LL C(int a, int b) {
return (pre[a] * apre[b] % MOD) * apre[a - b] % MOD;
}
int main() {
init();
read(n), read(m);
LL ans = 0;
for (int i = 1; i <= m; ++i) {
LL val = i, now = 1;
for (int j = 2; j * j <= val; ++j) {
int cnt = 0;
while (val % j == 0) {
val /= j;
cnt++;
}
now = now * C(n + cnt - 1, n - 1) % MOD;
}
if (val != 1) {
now = now * C(n, n - 1) % MOD;
}
ans += now;
ans %= MOD;
}
printf("%lld\n", ans);
return 0;
}
| #include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <bitset>
using namespace std;
typedef long long ll;
const ll INF = 1000000000000000000 + 1;
const int MAX_N = 20 + 10;
ll A[MAX_N];
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int N;
cin >> N;
for (int i = 0; i < N; i++) cin >> A[i];
ll ans = INF;
for (int i = 0; i < (1<<N); i++) {
ll res;
int bit;
res = A[0];
if((i & 1) == 1) bit = 1;
else bit = 0;
vector<ll> v;
for (int j = 1; j < N; j++) {
if( ((i >> j) & 1) == bit){
res |= A[j];
}
else {
bit = (i>>j) & 1;
v.push_back(res);
res = A[j];
}
}
v.push_back(res);
ll xorval = v[0];
for (int j = 1; j < v.size(); j++) {
xorval ^= v[j];
}
ans = min(ans, xorval);
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long f[100];
int main() {
f[0] = 0;
f[1] = 1;
for (int i = 2; i < 100; ++i) {
f[i] = f[i - 2] + f[i - 1];
}
long long n;
scanf("%lld", &n);
queue<int> Q;
while (n) {
int x = upper_bound(f + 1, f + 93, n) - f - 1;
Q.push(x);
n -= f[x];
}
int lmt = Q.front();
vector<int> ans;
for (int i = 1; i <= lmt; ++i) {
if (i != 1) {
if ((i & 1) ^ (lmt & 1)) ans.push_back(4);
else ans.push_back(3);
}
while (!Q.empty() && lmt - Q.front() + 1 == i) {
Q.pop();
if ((i & 1) ^ (lmt & 1)) ans.push_back(2);
else ans.push_back(1);
}
}
printf("%d\n", (int)ans.size());
for (int it : ans) {
printf("%d\n", it);
}
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
#define N 100005
#define mod 1000000007
#define ll long long
vector<int>v;
int ans[N];
ll n,a[N];
void add(int x,int p){
for(int i=ans[0];i>x;i--)ans[i+1]=ans[i];
ans[0]++,ans[x+1]=p;
}
int main(){
scanf("%lld",&n);
a[0]=a[1]=1;
for(int i=2;i<=90;i++)a[i]=a[i-1]+a[i-2];
for(int i=90;i;i--)
if (n>=a[i]){
n-=a[i];
v.push_back(i);
}
add(ans[0],1);
for(int i=1;i<=v[0];i++)add(ans[0],3+(i&1));
for(int i=1;i<v.size();i++)add(ans[0]-v[i],5-ans[ans[0]-v[i]+1]);
ans[ans[0]]=3;
for(int i=0;i<=ans[0];i++)printf("%d\n",ans[i]);
} |
#include <string>
#include <iostream>
using namespace std;
int main()
{
double n;
cin >> n;
n *= 1.08;
n = (int)(n);
if (n == 206)
cout << "so-so" << endl;
else if(n < 206)
cout << "Yay!" << endl;
else
cout << ":(" << endl;
} | #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rrep(i,n) for(int i = (n-1);i>=0;--i)
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
const int INF=1<<30;
//const ll INF=1LL<<60;
int main() {
int n;
cin >> n;
double ans = (double)n*1.08;
int k = ans;
if(k<206) cout<<"Yay!"<<endl;
else if(k==206) cout<<"so-so"<<endl;
else cout<<":("<<endl;
return 0;
} |
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
typedef long long ll;
typedef long double ld;
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define REPR(i,a,b) for(int i = b; i >= a; i--)
#define all(a) a.begin(), a.end()
#define alln(a, n) (a, a+n)
#define sz(x) (int)(x).size()
#define MAX 10000007
#define MIN -10000007
#define pi pair<int,int>
#define pl pair<ll,ll>
#define mii map<int,int>
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define inf 1e18
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef set<int> si;
const int MOD=1e9+7;
ll lcm(ll a,ll b){return (a * b) / __gcd(a,b);}
ll gcd(ll a,ll b){return __gcd(a,b);}
ll power(ll a,ll b,ll MOD){if(b == 0)return 1;if(b == 1)return a;ll ans = power(a,b/2,MOD) % MOD;ans *= ans;ans %= MOD;if(b % 2 == 1)ans *= a;return ans%MOD;}
ll inverse(ll x){x%=MOD;return power(x,MOD-2,MOD);}
ll fact[1],inv[1];
void factorial(ll n){
fact[0]=1;
for(ll i=1;i<=n;i++){
fact[i]=fact[i-1]*i;
if(fact[i]>=MOD)
fact[i]%=MOD;
}
}
ll ncr(ll n,ll r){
if(n<r||n<0||r<0)
return 0;
ll b=inv[n-r];
ll c=inv[r];
ll a=fact[n]*b;
if(a>=MOD)
a%=MOD;
a*=c;
if(a>=MOD)
a%=MOD;
return a;
}
vector<char> is_prime(100001, true);
void sieve(ll n){
is_prime[0] = is_prime[1] = false;
for (int i = 2; i <= n; i++) {
if (is_prime[i] && (long long)i * i <= n) {
for (int j = i * i; j <= n; j += i)
is_prime[j] = false;
}
}
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int t;
t=1;
cout<<fixed<<setprecision(0);
// cin>>t;
while(t--){
ll n;
cin>>n;
ll a[n];
set<ll>s;
REP(i,0,n-1) cin>>a[i];
ll j=0;
REP(i,0,n-1){
s.insert(a[i]);
while(s.count(j)) j++;
cout<<j<<"\n";
}
}
cerr<<"Time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
return 0;
}
| // https://atcoder.jp/contests/abc201/tasks/abc201_d
// if we reach i,j with different path then still the subproblem remain same.
#include<bits/stdc++.h>
#define M_PI 3.14159265358979323846
#define Speed_UP ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#warning Remember to change t
inline void setIO();
using namespace std;
typedef long long ll;
typedef long double ld;
ll const MX = 2e3+7;
ll const inf = MX*MX + 7;
ll dp[MX][MX];
char grid[MX][MX];
ll h,w;
// ll f(ll i,ll j){
// // if(i>w||j>h){
// // return -inf;
// // }
// return ;
// }
ll cost(ll i ,ll j){
if(i==h&&j==w){
return 0;
}
if(dp[i][j]!=inf){
return dp[i][j];
}
ll a,b;
if(((i+j)%2)==0){
a = -inf;
b = -inf;
if(i<=h-1){
a = cost(i+1,j)+(grid[i+1][j]=='+'?1:0);
}
if(j<=w-1){
b = cost(i,j+1)+(grid[i][j+1]=='+'?1:0);
}
dp[i][j] = max(a,b);
return dp[i][j];
}else{
a = inf;
if(i<=h-1){
a = cost(i+1,j)-(grid[i+1][j]=='+'?1:0);
}
if(j<=w-1){
b = cost(i,j+1)-(grid[i][j+1]=='+'?1:0);
}
dp[i][j] = min(a,b);
return dp[i][j];
}
}
int solve(){
cin >> h >> w;
// cout << h << w << "\n";
for(int i=1;i<=h;i++){
for(int j=1;j<=w;j++){
cin >> grid[i][j];
dp[i][j]=inf;
}
}
ll ans = cost(1,1);
// for(int i=1;i<=h;i++){
// for(int j=1;j<=w;j++){
// cout << dp[i][j]<<" ";
// }
// cout<<"\n";
// }
if(ans>0){
cout<<"Takahashi";
}else if (ans==0){
cout<<"Draw";
}else{
cout << "Aoki";
}
return 0;
}
int main(){
Speed_UP
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
ll t = 1;
while(t--){
solve();
}
}
inline void setIO(string name="") {
#ifndef ONLINE_JUDGE
freopen((name+".in").c_str(), "r", stdin);
freopen((name+".out").c_str(), "w", stdout);
#endif
}
|
#include <bits/stdc++.h>
constexpr int DEBUG = 0;
using namespace std;
using int64 = long long;
struct Edge {
int s, t;
Edge(int s, int t) : s(s), t(t) {}
};
vector<vector<Edge>> ReadUndirectedGraph(int n, int m, int offset) {
vector<vector<Edge>> graph(n);
for (int i = 0; i < m; i++) {
int v1, v2; cin >> v1 >> v2; v1 -= offset; v2 -= offset;
graph[v1].push_back(Edge(v1, v2)); graph[v2].push_back(Edge(v2, v1));
}
return graph;
}
class FF {
private:
int64 x_;
void Normalize() {
if (0 <= x_ && x_ < P) { return; } x_ %= P; if (x_ < 0) { x_ += P; }
}
public:
// static constexpr int P = 998244353;
static constexpr int P = 1000000007;
FF(int64 x) : x_(x) { Normalize(); }
FF() : x_(0) {}
int64 Value() const { return x_; }
FF operator+(FF o) const { FF r(*this); r += o; return r; }
FF operator-(FF o) const { FF r(*this); r -= o; return r; }
FF operator* (FF o) const { FF r(*this); r *= o; return r; }
FF operator/ (FF o) const { return (*this) * o.Power(P - 2); }
bool operator== (FF o) const { return x_ == o.x_; }
void operator+= (FF o) { x_ += o.x_; if (x_ >= P) x_ -= P; }
void operator-= (FF o) { x_ -= o.x_; if (x_ < 0) x_ += P; }
void operator*= (FF o) { x_ = (x_ * o.x_) % P; }
FF Power(int64 p) const {
if (p < 0) { return FF(1) / Power(-p); } FF x(*this), r(1);
while (p) { if (p % 2) { r *= x; } x *= x; p /= 2; } return r;
}
};
ostream& operator<<(ostream& s, const FF& x) { s << x.Value(); return s; }
template<typename T>
vector<vector<T>> Make2D(int d1, int d2, T default_value) {
return vector<vector<T>>(d1, vector<T>(d2, default_value));
}
vector<vector<FF>> Id(int n) {
auto a = Make2D(n, n, FF(0));
for (int i = 0; i < n; i++) { a[i][i] = 1; }
return a;
}
vector<vector<FF>> Multiply(vector<vector<FF>> a, vector<vector<FF>> b) {
int n = a.size();
auto c = Make2D(n, n, FF(0));
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
for (int k = 0; k < n; k++) {
c[i][j] += a[i][k] * b[k][j];
}
}
}
return c;
}
vector<vector<FF>> Power(vector<vector<FF>> a, int p) {
int n = a.size();
vector<vector<FF>> r = Id(n);
// while (p) { if (p % 2) { r *= x; } x *= x; p /= 2; } return r;
while (p) {
if (p % 2) {
r = Multiply(r, a);
}
a = Multiply(a, a);
p /= 2;
}
return r;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m, k; cin >> n >> m >> k;
vector<FF> xs(n);
for (int i = 0; i < n; i++) {
int x; cin >> x;
xs[i] = x;
}
auto graph = ReadUndirectedGraph(n, m, 1);
auto a = Make2D(n, n, FF(0));
for (int i = 0; i < n; i++) {
a[i][i] = 1;
}
for (int i = 0; i < n; i++) {
for (const auto& e : graph[i]) {
a[i][e.t] += FF(1) / FF(2 * m);
a[i][i] -= FF(1) / FF(2 * m);
}
}
// for (int i = 0; i < n; i++) {
// for (int j = 0; j < n; j++) {
// cout << a[i][j] * 4 << " ";
// }
// cout << endl;
// }
a = Power(a, k);
// for (int i = 0; i < n; i++) {
// for (int j = 0; j < n; j++) {
// cout << a[i][j] << " ";
// }
// cout << endl;
// }
for (int i = 0; i < n; i++) {
FF e = 0;
for (int j = 0; j < n; j++) {
e += a[i][j] * xs[j];
}
cout << e << endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define IN(x,c) (find(c.begin(),c.end(),x) != (c).end())
#define REP(i,n) for (int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for (int i=(a);i<=(b);i++)
#define INIT(a,v) memset(a,v,sizeof(a))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
template<class A, class B> A cvt(B x) { stringstream ss; ss<<x; A y; ss>>y; return y; }
#define SPC << " " <<
#define DEBUG(x) cerr << #x << " = "; cerr << x << endl;
#define DEBUG_ITER(x) cerr << #x << " = "; for (auto _ : x) cerr << _ << ' '; cerr << endl;
typedef pair<int,int> PII;
typedef long long int64;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef vector<double> VD;
#define MOD 1000000007
/* Matrix operations */
typedef int64 Element;
typedef vector<Element> Row;
typedef vector<Row> Matrix;
Matrix zeros(int h, int w) {
return Matrix(h, Row(w));
}
Matrix identity(int n) {
Matrix c = zeros(n,n);
REP (i,n) c[i][i]=1;
return c;
}
Matrix transpose(const Matrix &a) {
int h=a[0].size(), w=a.size();
Matrix t = zeros(h, w);
REP (i,h) REP (j,w) t[i][j]=a[j][i];
return t;
}
Matrix operator+(const Matrix &a, const Matrix &b) {
int h=a.size(), w=a[0].size();
assert(a.size()==b.size() && a[0].size()==b[0].size());
Matrix c = zeros(h,w);
REP (i,h) REP (j,w) {
c[i][j]=a[i][j]+b[i][j];
c[i][j]%=MOD;
}
return c;
}
Matrix operator+(const Matrix &a, Element k) {
int h=a.size(), w=a[0].size();
Matrix c = a;
REP (i,h) REP (j,w) {
c[i][j]+=k;
c[i][j]%=MOD;
}
return c;
}
Matrix operator*(Element k, const Matrix &a) {
int h=a.size(), w=a[0].size();
Matrix c = a;
REP (i,h) REP (j,w) {
c[i][j]*=k;
c[i][j]%=MOD;
}
return c;
}
Matrix operator*(const Matrix &a, const Matrix &b) {
int h=a.size(), w=b[0].size();
assert(a[0].size()==b.size());
Matrix c = zeros(h,w);
REP (i,h) REP (j,w) {
REP (k,a[0].size()) {
c[i][j]+=a[i][k]*b[k][j];
c[i][j]%=MOD;
}
}
return c;
}
Matrix operator+(Element k, const Matrix &a) {
return a+k;
}
Matrix operator*(const Matrix &a, Element k) {
return k*a;
}
Matrix operator-(const Matrix &a, const Matrix &b) {
return a+(-1)*b;
}
Matrix mat_pow(const Matrix &a, int k) {
assert(a.size()==a[0].size());
if (k==0) return identity(a.size());
if (k%2==0) {
Matrix c=mat_pow(a,k/2);
return c*c;
} else {
Matrix c=mat_pow(a,k-1);
return c*a;
}
}
void mat_print(const Matrix &a) {
REP (i,a.size()) {
REP (j,a[i].size()) {
if (j!=0) cout << " ";
cout << a[i][j];
}
cout << endl;
}
}
int modPow(int a, int k, int m) {
if (k==0) return 1;
else if (k%2==0) {
int64 b=modPow(a,k/2,m);
return (b*b)%m;
} else {
int64 b=modPow(a,k-1,m);
return (a*b)%m;
}
}
int n,m,k;
int a[100];
int deg[100];
vector<int> adj[100];
int main() {
//freopen("test.in","r",stdin);
cin >> n >> m >> k;
REP (i,n) cin >> a[i];
Matrix A = zeros(n,n);
REP (i,m) {
int x,y;
cin >> x >> y;
x--; y--;
adj[x].PB(y); adj[y].PB(x);
deg[x]++; deg[y]++;
}
int64 inv_2m=modPow(2*m,MOD-2,MOD);
int64 inv_m=modPow(m,MOD-2,MOD);
REP (i,n) {
for (int j : adj[i]) {
A[i][j]=inv_2m; //1.0/(2*m);
A[i][i]=(A[i][i]+inv_2m)%MOD; //+=1.0/(2*m);
}
A[i][i]=(A[i][i]+(m-deg[i])*inv_m)%MOD;
}
Matrix v = zeros(n,1);
REP (i,n) v[i][0]=a[i];
Matrix Ak = mat_pow(A,k);
Matrix vk = Ak*v;
REP (i,n) {
cout << vk[i][0] << endl;
}
return 0;
}
|
#pragma GCC optimize ("O2")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
int kotae = 0;
rep(i, N) {
int a;
cin >> a;
if (a >= 10) kotae += a - 10;
}
co(kotae);
Would you please return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define ll long long
//ll a[10000007];
// ll binpow(ll a, ll b) {
// ll res = 1;
// while (b > 0) {
// if (b & 1)
// res = res * a;
// a = a * a;
// b >>= 1;
// }
// return res;
// }
// 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] == true)
// {
// 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 << " ";*/
// }
int main()
{
ios_base::sync_with_stdio(false);cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("error.txt", "w", stderr);
freopen("output.txt", "w", stdout);
#endif
int n,i,sum=0;
cin>>n;
int a[n];
for(i=0;i<n;i++){
cin>>a[i];
if(a[i]>10){
sum+=a[i]-10;
}
}
cout<<sum;
cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
return 0;
}
|
#pragma GCC optimize("O3")
#include "bits/stdc++.h"
#define sz(x) (int)(x).size()
using namespace std;
const int64_t INV = int64_t(332748118);
const int64_t MOD = int64_t(998244353);
const int mxN = int(5e3) + 5;
int64_t dp[mxN][mxN];
char arr[mxN][mxN];
int h,w,k;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> h >> w >> k;
for(int i=0; i<k; i++) {
int r,c; char val;
cin >> r >> c >> val;
arr[r][c] = val;
}
dp[1][1] = 1;
for(int i=1; i<=h; i++)
arr[i][0] = 'X';
for(int j=1; j<=w; j++)
arr[0][j] = 'X';
for(int i=1; i<=h; i++) {
for(int j=1; j<=w; j++) {
if(i==1 && j==1) continue;
switch(arr[i-1][j]) {
case 0:
dp[i][j] += (2 * INV * dp[i-1][j]) % MOD;
break;
case 'X':
case 'D':
dp[i][j] += dp[i-1][j];
break;
}
switch(arr[i][j-1]) {
case 0:
dp[i][j] += (2 * INV * dp[i][j-1]) % MOD;
break;
case 'X':
case 'R':
dp[i][j] += dp[i][j-1];
break;
}
}
}
int times = h * w - k;
int64_t mul = 1;
while(times--) {
mul *= 3;
mul %= MOD;
}
cout << (dp[h][w] * mul) % MOD << "\n";
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mii map <int, int>
#define mll map <ll, ll>
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vd vector <double>
#define vll vector <ll>
#define fi first
#define se second
#define si set <int>
#define sll set <ll>
#define spii set <pii>
#define vs vector <string>
#define vpii vector <pair <int, int> >
#define vpll vector <pair <long long, long long> >
#define vvi vector <vector <int> >
#define vvpii vector <vector <pii > >
#define vb vector <bool>
#define vvb vector <vb>
#define mp make_pair
#define vvll vector <vll>
#define vsi vector <si>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define MANX MAXN
#define itn int
#define dbg(x); {cout << #x << "=" << x << ", ";}
#define in(x); { for (auto &to : x) cin >> to;}
#define out(x); { for (auto &to : x) cout << to << " "; cout << '\n'; }
const ll INFLL = 1e18;
const int MAXN = 3e5+100;
const ll INF = 1e9;
const int mod1 = 998244353;
const int mod2 = 1e9+21;
int add(int a,int b)
{
a+=b;
if (a>=mod1)
return a-mod1;
return a;
}
int mult(int a,int b)
{
return 1ll*a*b%mod1;
}
void ad(int &x,int y)
{
x=add(x,y);
}
int sub(int a,int b)
{
a-=b;
if (a<0)
return a+mod1;
return a;
}
int bin_pow(int base,ll deg)
{
if (deg==0)
return 1;
int t=bin_pow(base,deg/2);
if (deg&1)
return 1ll*t*t%mod1*base%mod1;
else
return 1ll*t*t%mod1;
}
void solve()
{
int h,w,k;
cin>>h>>w>>k;
vector <vector <char> > c(h,vector <char>(w,'1'));
while (k--)
{
int x,y;
cin>>x>>y;
x--,y--;
cin>>c[x][y];
}
vector <int> pows(MAXN);
pows[0]=1;
for (int i=1;i<MAXN;i++)
pows[i]=mult(3,pows[i-1]);
vector <vector <int> > pref(h+1,vi(w+1));
for (int i=1;i<=h;i++)
{
for (int j=1;j<=w;j++)
pref[i][j]=pref[i][j-1]+(c[i-1][j-1]=='1'?1:0);
}
for (int j=1;j<=w;j++)
{
for (int i=1;i<=h;i++)
pref[i][j]+=pref[i-1][j];
}
auto get = [&](int x,int y,int x1,int y1)
{
x++,y++,x1++,y1++;
if (x>h||y>w)
return 1;
int ans=pref[x1][y1];
ans+=pref[x-1][y-1];
ans-=pref[x1][y-1];
ans-=pref[x-1][y1];
return pows[ans];
};
vector <vector <int> > dp(h,vi(w));
dp[0][0]=1;
for (int i=0;i<h;i++){
for (int j=0;j<w;j++)
{
if (c[i][j]=='1')
{
if (i+1<h)
ad(dp[i+1][j],mult(mult(2,get(i,j+1,i,w-1)),dp[i][j]));
if (j+1<w)
ad(dp[i][j+1],mult(mult(2,get(i+1,j,h-1,j)),dp[i][j]));
}
else if (c[i][j]=='R')
{
if (j+1<w)
ad(dp[i][j+1],mult(mult(1,get(i+1,j,h-1,j)),dp[i][j]));
} else if (c[i][j]=='D')
{
if (i+1<h)
ad(dp[i+1][j],mult(mult(1,get(i,j+1,i,w-1)),dp[i][j]));
}
else{
if (j+1<w)
ad(dp[i][j+1],mult(mult(1,get(i+1,j,h-1,j)),dp[i][j]));
if (i+1<h)
ad(dp[i+1][j],mult(mult(1,get(i,j+1,i,w-1)),dp[i][j]));
}
}
}
cout<<mult(dp[h-1][w-1],c[h-1][w-1]=='1'?3:1);
// X?
// RR
}
int main() {
#ifdef Mip182
freopen("a.in", "r", stdin);
#else
ios_base::sync_with_stdio(0);
cin.tie(0);
#endif
int _t;
_t=1;
// cin>>_t;
while (_t--)
solve();
#ifdef Mip182
cout<<'\n'<<"Time : "<<(double)(clock())/CLOCKS_PER_SEC<<'\n';
#endif
}
|
#include <bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,n) for(int i=0,i_len=n; i<i_len; ++i)
template<typename T1,typename T2> bool chmax(T1 &a, T2 b) { if (a<b) { a=b; return 1; } return 0; }
template<typename T1,typename T2> bool chmin(T1 &a, T2 b) { if (b<a) { a=b; return 1; } return 0; }
int n, k;
vector<vector<int> > g;
vector<int> d; // d[v]: 頂点vと葉の最大距離
void dfs(int cur, int pre, int x, int& cnt){
d[cur] = 0;
for(auto& nxt : g[cur]){
if(nxt == pre) continue;
dfs(nxt, cur, x, cnt);
if(d[nxt]+1 > x) cnt++; // cur-nxtを切る
else if(d[cur]+d[nxt]+1 > x){ // curの最長の部分木かnxtのいずれかを切る
cnt++;
chmin(d[cur], d[nxt]+1);
}else{
chmax(d[cur], d[nxt]+1);
}
}
}
// k個以下の直径がx以下の木に分解できるか
bool check(int x){
int cnt = 1;
dfs(0, -1, x, cnt);
return cnt <= k;
}
int solve(){
cin >> n >> k;
g.resize(n);
d.resize(n);
REP(i,n-1){
int u, v;
cin >> u >> v;
u--;v--;
g[u].push_back(v);
g[v].push_back(u);
}
// 直径がx*2+1 <=> 任意の頂点への距離がx以下である頂点が存在する
int ok = n, ng = -1;
while(abs(ok-ng)>1){
int mid = (ok+ng)/2;
if(check(mid)){
ok = mid;
}else{
ng = mid;
}
}
cout << (ok+1)/2 << endl;
return 0;
}
int main(){
cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
solve();
return 0;
} | #include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
using ll = long long;
using ld = long double;
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
#define mp make_pair
const int MOD = 998244353;
int mul(int a, int b) {
return (1LL * a * b) % MOD;
}
int add(int a, int b) {
int s = (a+b);
if (s>=MOD) s-=MOD;
return s;
}
int sub(int a, int b) {
int s = (a+MOD-b);
if (s>=MOD) s-=MOD;
return s;
}
int po(int a, ll deg)
{
if (deg==0) return 1;
if (deg%2==1) return mul(a, po(a, deg-1));
int t = po(a, deg/2);
return mul(t, t);
}
int inv(int n)
{
return po(n, MOD-2);
}
mt19937 rnd(time(0));
/*
const int LIM = 3e5 + 5;
vector<int> facs(LIM), invfacs(LIM);
void init()
{
facs[0] = 1;
for (int i = 1; i<LIM; i++) facs[i] = mul(facs[i-1], i);
invfacs[LIM-1] = inv(facs[LIM-1]);
for (int i = LIM-2; i>=0; i--) invfacs[i] = mul(invfacs[i+1], i+1);
}
int C(int n, int k)
{
if (n<k) return 0;
if (n<0 || k<0) return 0;
return mul(facs[n], mul(invfacs[k], invfacs[n-k]));
}*/
/*struct DSU
{
vector<int> sz;
vector<int> parent;
void make_set(int v) {
parent[v] = v;
sz[v] = 1;
}
int find_set(int v) {
if (v == parent[v])
return v;
return find_set(parent[v]);
}
void union_sets(int a, int b) {
find_set(a);
find_set(b);
a = find_set(a);
b = find_set(b);
if (a != b) {
if (sz[a] < sz[b])
swap(a, b);
parent[b] = a;
sz[a] += sz[b];
};
}
DSU (int n)
{
parent.resize(n);
sz.resize(n);
for (int i = 0; i<n; i++) make_set(i);
}
};*/
vector<vector<int>> G;
int n, k;
vector<int> parent;
vector<int> depth;
vector<vector<int>> children;
void dfs(int v, int par = -1)
{
for (auto it: G[v]) if (it!=par)
{
children[v].push_back(it);
depth[it] = depth[v] + 1;
parent[it] = v;
dfs(it, v);
}
}
set<pair<int, int>> worst;
vector<bool> deleted;
vector<int> deleting;
void del(int v, int dist)
{
if (!deleted[v])
{
worst.erase(mp(depth[v], v)); deleted[v] = true;
}
if (dist<=deleting[v]) return;
deleting[v] = dist;
if (dist==0) return;
for (auto it: G[v]) del(it, dist-1);
}
bool check(int d)
{
worst.clear();
for (int i = 0; i<n; i++) worst.insert(mp(depth[i], i));
deleted.clear(); deleted.resize(n);
deleting.clear(); deleting.resize(n);
int cnt = 0;
while (!worst.empty())
{
cnt++;
//cout<<"Iter "<<cnt<<": "<<endl;
//for (auto it: worst) cout<<it.first<<' '<<it.second<<endl;
auto it = *prev(worst.end());
if (it.first<=d)
{
return (cnt<=k);
}
int deleting = it.second;
for (int i = 0; i<d; i++) deleting = parent[deleting];
//cout<<"Deleting: "<<deleting<<endl;
del(deleting, d);
}
if (worst.empty()) return (cnt<=k);
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(nullptr);
cin>>n>>k;
G.resize(n);
for (int i = 0; i<n-1; i++)
{
int u, v; cin>>u>>v; u--; v--;
G[u].push_back(v); G[v].push_back(u);
}
parent.resize(n); depth.resize(n); children.resize(n);
parent[0] = -1;
dfs(0);
int L = 0; int R = n;
while (R-L>1)
{
int mid = (L+R)/2;
if (check(mid)) R = mid; else L = mid;
}
cout<<R<<endl;
}
|
#include <bits/stdc++.h>
/*#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <cstring>
#include <string>*/
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn=2e5+10;
const int mod=998244353;
const int inf=0x3f3f3f3f;
int n,T,a[maxn],m;
double k[maxn],b[maxn],sumk,sumb;
int main()
{
cin>>n>>m>>T;
int cnt=1;
int jb=T;
while(T--)
{
int y;
cin>>y;
a[y]=1;
if(a[y-1]==1)
cnt++;
else
{
if(cnt>=m)
{
printf("-1");
return 0;
}
cnt=1;
}
}
if(cnt>=m&&jb!=0)
{
printf("-1");
return 0;
}
for(int i=n-1;i>=0;i--)
{
sumk=sumk+k[i+1]-k[i+m+1];
sumb=sumb-b[i+m+1]+b[i+1];
if(a[i]==1)
{
k[i]=1;
continue;
}
k[i]=sumk;
b[i]=sumb;
b[i]/=(double)m;
k[i]/=(double)m;
b[i]++;
// printf("%d %lf %lf\n",i,k[i],b[i]);
}
if(k[0]==1)
printf("-1");
else
printf("%.4lf",(-b[0])/(k[0]-1));
return 0;
}
| //Code By CXY07
#include<bits/stdc++.h>
using namespace std;
//#define FILE
#define int long long
#define debug(x) cout << #x << " = " << x << endl
#define file(FILENAME) freopen(FILENAME".in", "r", stdin), freopen(FILENAME".out", "w", stdout)
#define LINE() cout << "LINE = " << __LINE__ << endl
#define LL long long
#define ull unsigned long long
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define fst first
#define scd second
#define inv(x) qpow((x),mod - 2)
#define lowbit(x) ((x) & (-(x)))
#define abs(x) ((x) < 0 ? (-(x)) : (x))
#define randint(l, r) (rand() % ((r) - (l) + 1) + (l))
#define vec vector
const int MAXN = 510;
const int INF = 2e11;
const double PI = acos(-1);
const double eps = 1e-6;
//const int mod = 1e9 + 7;
//const int mod = 998244353;
//const int G = 3;
//const int base = 131;
int n, m;
int c[MAXN][MAXN], tmp[MAXN][MAXN];
int a[MAXN], b[MAXN], sum;
template<typename T> inline bool read(T &a) {
a = 0; char c = getchar(); int f = 1;
while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
while(c >= '0' && c <= '9') {a = a * 10 + (c ^ 48); c = getchar();}
a *= f;
return 1;
}
template<typename A, typename ...B>
inline bool read(A &x, B &...y) {return read(x) && read(y...);}
signed main () {
#ifdef FILE
freopen(".in","r",stdin);
freopen(".out","w",stdout);
#endif
read(n);
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= n; ++j)
read(c[i][j]);
b[1] = c[1][1];
for(int i = 2; i <= n; ++i)
b[i] = b[i - 1] + c[1][i] - c[1][i - 1];
for(int i = 1; i <= n; ++i)
a[i] = c[i][i] - b[i];
sum = INF;
for(int i = 1; i <= n; ++i) sum = min(sum, b[i]);
for(int i = 1; i <= n; ++i) {
a[i] += sum, b[i] -= sum;
if(a[i] < 0 || b[i] < 0) return puts("No"), 0;
}
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= n; ++j)
if(a[i] + b[j] != c[i][j]) return puts("No"), 0;
puts("Yes");
for(int i = 1; i <= n; ++i) cout << a[i] << ' ';
cout << endl;
for(int i = 1; i <= n; ++i) cout << b[i] << ' ';
cout << endl;
return 0;
}
|
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
long long solve(int N, int M, vector<int> A)
{
A.push_back(0);
A.push_back(N + 1);
sort(A.begin(), A.end());
vector<int> B;
for (int i = 1; i <= M + 1; ++i) {
int D = A[i] - A[i - 1] - 1;
if (D != 0) {
B.push_back(D);
}
}
if (B.empty()) {
return 0;
}
long long k = *min_element(B.begin(), B.end());
long long ans = 0;
for (auto y : B) {
ans += (y + k - 1) / k;
}
return ans;
}
int main()
{
int N, M;
cin >> N >> M;
vector<int> A(M);
for (auto& x : A) {
cin >> x;
}
cout << solve(N, M, A) << endl;
}
| // Template
#include "bits/stdc++.h"
#define rep_override(x, y, z, name, ...) name
#define rep2(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep3(i, l, r) for (int i = (int)(l); i < (int)(r); ++i)
#define rep(...) rep_override(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003LL;
template <typename T>
inline bool chmin(T &x, const T &y) {
if (x > y) {
x = y;
return true;
}
return false;
}
template <typename T>
inline bool chmax(T &x, const T &y) {
if (x < y) {
x = y;
return true;
}
return false;
}
struct IOSET {
IOSET() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
}
} ioset;
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
for (T &element : vec) is >> element;
return is;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
for (int i = 0, vec_len = (int)vec.size(); i < vec_len; ++i) {
os << vec[i] << (i + 1 == vec_len ? "" : " ");
}
return os;
}
// Main
int main() {
int n, m;
cin >> n >> m;
vector<int> a(m);
cin >> a;
if (m == 0) {
cout << "1\n";
return 0;
}
sort(all(a));
vector<int> vec;
rep(i, m) {
if (i == 0 && a[i] != 1) vec.push_back(a[i] - 1);
else if (a[i] - a[i - 1] != 1) vec.push_back(a[i] - a[i - 1] - 1);
}
if (a[m - 1] != n) vec.push_back(n - a[m - 1]);
if (vec.empty()) {
cout << "0\n";
return 0;
}
int k = *min_element(all(vec));
int ans = 0;
for (int x : vec) ans += (x + k - 1) / k;
cout << ans << "\n";
}
|
/**
* author:
* created: 15.11.2020 00:57:15
**/
#pragma region Macros
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
using P = pair<int,int>;
using ll = long long;
const int INF = 1001001001;
const int di[] = {-1,0,1,0}, dj[] = {0,-1,0,1};
typedef vector<int> vi;
typedef vector<vi> vvi;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repn(i,n) for(int i = 1; i <= (n); i++)
#define pb push_back
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cout << H << " ";
debug_out(T...);
}
#ifdef LOCAL
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
template<class T>
inline bool chmax(T &a, T b) {
if(a < b) {
a = b;
return true;
}
return false;
}
template<class T>
inline bool chmin(T &a, T b) {
if(a > b) {
a = b;
return true;
}
return false;
}
const double PI = acos(-1);
const int mod = 1000000007;
class mint {
long long x;
public:
mint(long long x=0) : x((x%mod+mod)%mod) {}
mint operator-() const {
return mint(-x);
}
mint& operator+=(const mint& a) {
if ((x += a.x) >= mod) x -= mod;
return *this;
}
mint& operator-=(const mint& a) {
if ((x += mod-a.x) >= mod) x -= mod;
return *this;
}
mint& operator*=(const mint& a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint& a) const {
mint res(*this);
return res+=a;
}
mint operator-(const mint& a) const {
mint res(*this);
return res-=a;
}
mint operator*(const mint& a) const {
mint res(*this);
return res*=a;
}
mint pow(ll t) const {
if (!t) return 1;
mint a = pow(t>>1);
a *= a;
return a;
}
// for prime mod
mint inv() const {
return pow(mod-2);
}
mint& operator/=(const mint& a) {
return (*this) *= a.inv();
}
mint operator/(const mint& a) const {
mint res(*this);
return res/=a;
}
friend ostream& operator<<(ostream& os, const mint& m){
os << m.x;
return os;
}
};
#pragma endregion
void fail(){
cout << "-1\n";
exit(0);
}
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
int n;
cin >> n;
string s,t;
cin >> s >> t;
reverse(s.begin(), s.end());
reverse(t.begin(), t.end());
ll ans = 0;
vector<int> stk;
for(int i = 0; i < n; ++i){
if(s[i] == '1') stk.pb(i);
if(t[i] == '1'){
if(stk.empty()) fail();
ans += i - stk.back();
stk.pop_back();
}
}
if(stk.size() & 1) fail();
while(stk.size()){
ll r = stk.back();
stk.pop_back();
ans += r - stk.back();
stk.pop_back();
}
cout << ans << "\n";
return 0;
} | #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <assert.h>
#include <sys/time.h>
#include <fstream>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define all(vec) (vec).begin(),(vec).end()
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define deb(x) cerr << #x << " = " << (x) << " , ";
#define debl cerr << " (L" << __LINE__ << ")"<< endl;
#define clr(a) memset((a),0,sizeof(a))
#define nclr(a) memset((a),-1,sizeof(a))
#define pb push_back
#define INRANGE(x,s,e) ((s)<=(x) && (x)<(e))
#define MP(x,y) make_pair((x),(y))
#define sz(v) ((ll)(v).size())
#define bit(n) (1LL<<n)
double pi=3.14159265358979323846;
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ll,double> pld;
typedef pair<double,ll> pdl;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
template<typename T,typename U> std::ostream& operator<<(std::ostream& os, const pair<T,U>& z){
return ( os << "(" << z.first << ", " << z.second << ",)" );
}
template<typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& z){
os << "[ ";
rep(i,z.size())os << z[i] << ", " ;
return ( os << "]" << endl);
}
template<typename T> std::ostream& operator<<(std::ostream& os, const set<T>& z){
os << "set( ";
for(T p:z)os << p << ", " ;
//each(p,z)os << (*p) << ", " ;
return ( os << ")" << endl);
}
template<typename T,typename U> std::ostream& operator<<(std::ostream& os, const map<T,U>& z){
os << "{ ";
//each(p,z)os << (p->first) << ": " << (p->second) << ", " ;
for(auto p:z)os << (p.first) << ": " << (p.second) << ", " ;
return ( os << "}" << endl);
}
double get_time(){
struct timeval tv;
gettimeofday(&tv, NULL);
return tv.tv_sec + tv.tv_usec*1e-6;
}
ll mod = 1000000007;
vl X,Y;
ll cal(){
//debug(X);
//debug(Y);
ll ret = 0;
int ix = 0, iy=0;
while(ix<X.size()){
if(iy<Y.size() && X[ix]>=Y[iy]){
ret += X[ix] - Y[iy];
ix += 1;
iy += 1;
}
else{
if(ix+1>=X.size()){
return -1;
}
ret += X[ix+1] - X[ix];
ix += 2;
}
}
if(iy==Y.size())return ret;
return -1;
}
void _main(istream &inp){
string s,t;
ll N;
inp >> N >> s >> t;
rep(i,s.size()){
if(s[i]=='1'){
X.push_back(i);
}
if(t[i]=='1'){
Y.push_back(i);
}
}
cout << cal() << endl;
}
int main(){
if(0){
ifstream ifs("test.txt");
_main(ifs);
}
else{
_main(cin);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
cout << n - 1 << endl;
} | // IN THE NAME OF GOD
// https://serhatgiydiren.github.io
// 2021/05/13 14:07:26
#include <bits/stdc++.h>
using namespace std;
using namespace chrono;
class timer:high_resolution_clock
{
const time_point start_time;
public:
timer(): start_time(now()) {}
rep elapsed_time() const { return duration_cast<milliseconds>(now()-start_time).count();}
};
int time_limit=2000;
timer ttt;
#ifdef LOCAL
#include "debug.h"
#else
#define D(...) 404
#endif
mt19937 rng(steady_clock::now().time_since_epoch().count());
void solve(const int &test_id)
{
int n;
cin >> n;
cout << n-1 << endl;
}
void solve_cases()
{
int test_cases = 1;
//cin >> test_cases;
for(int i = 1; i <= test_cases; i++) { solve(i); D(i,ttt.elapsed_time()); }
}
void fast_io()
{
ios::sync_with_stdio(false);
srand(time(NULL));
cin.tie(0);
cout.tie(0);
cout << fixed << setprecision(15);
cerr << fixed << setprecision(15);
}
int main()
{
fast_io();
solve_cases();
return EXIT_SUCCESS;
}
|
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,m;
cin>>n>>m;
char a[n][m];
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
cin>>a[i][j];
}
}
int even=0,odd=0;
for(int i=0;i<n;i++)
{
int k=0;
for(int j=0;j<m;j++)
{
if(a[i][j]=='1')
{
k++;
}
}
if(k%2)
{
odd++;
}
else
{
even++;
}
}
cout<<even*odd;
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 "./Lib/debug_VC.hpp"
#include "./Lib/Timer.hpp"
#include "./Lib/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() {
ll n, m;
cin >> n >> m;
ll c0 = 0, c1 = 0;
REP(_, n) {
string s;
cin >> s;
ll cnt = 0;
REPC(c, s)if (c == '0') { ++cnt; }
++((cnt & 1) ? c0 : c1);
}
cout << c0 * c1 << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<bool> vbl;
typedef vector<vector<bool>> vvbl;
void INX(){}
template<typename Head, typename... Tail>
void INX(Head&& head, Tail&&... tail)
{
cin >> head;
INX(forward<Tail>(tail)...);
}
void OUTX(){}
template<typename Head, typename... Tail>
void OUTX(Head&& head, Tail&&... tail)
{
cout << head << endl;
OUTX(forward<Tail>(tail)...);
}
void OUTX2(){cout << endl;}
template<typename Head, typename... Tail>
void OUTX2(Head&& head, Tail&&... tail)
{
cout << head << ' ';
OUTX2(forward<Tail>(tail)...);
}
#define ADD emplace_back
#define MP make_pair
#define __LONG_LONG_MIN__ (-__LONG_LONG_MAX__ - 1)
//#define MOD 1000000007 // 10^9 + 7
//setprecision(10)
ll abmodn(ll a, ll b, ll n)
{
if(n == 1) return 0;
if(b == 0) return 1;
if(a % n == 0) return 0;
vbl chk(n, false);
vll v;
ll m = a;
ll loop = 0;
for (; loop <= n; loop++)
{
m %= n;
if(chk[m]) break;
chk[m] = true;
v.ADD(m);
m *= a;
}
ll startloop = 0;
while(v[startloop] != m) startloop++;
ll looplen = loop - startloop;
b--;
if(b > startloop)
{
b -= startloop;
b %= looplen;
b += startloop;
}
return v[b];
}
int main()
{
ll N, M;
INX(N, M);
ll M2 = M * M;
ll n10modm = abmodn(10, N, M2);
ll result = (n10modm / M) % M;
OUTX(result);
return 0;
}
| #include<bits/stdc++.h>
#define int long long
using namespace std;
typedef long long ll;
const int N=100050;
int a[N],b[N],c[N];
int n,m,k;
int ans;
bool check(int x)
{
int l=0,r=0;
for(int i=1;i<=k;i++)
{
l+=(m*a[i]-x+n-1)/n;
r+=(m*a[i]+x)/n;
}
if(l<=m&&m<=r) return true;
else return false;
}
void construct()
{
int sum=0;
for(int i=1;i<=k;i++)
{
b[i]=(m*a[i]-ans+n-1)/n;
sum+=b[i];
c[i]=(m*a[i]+ans)/n;
}
for(int i=1;i<=k;i++)
{
int temp=min(m-sum,c[i]-b[i]);
b[i]+=temp;
sum+=temp;
}
}
signed main()
{
cin>>k>>n>>m;
for(int i=1;i<=k;i++) cin>>a[i];
int l=-1,r=n*m;
while(r-l>1)
{
int mid=(r+l)>>1;
if(check(mid)) r=mid;
else l=mid;
}
ans=r;
construct();
for(int i=1;i<=k;i++) cout<<b[i]<<" ";
} |
#include <bits/stdc++.h>
#define VA_NUM_ARGS(...) VA_NUM_ARGS_IMPL_((0,__VA_ARGS__, 5,4,3,2,1))
#define VA_NUM_ARGS_IMPL_(tuple) VA_NUM_ARGS_IMPL tuple
#define VA_NUM_ARGS_IMPL(_0,_1,_2,_3,_4,_5,N,...) N
#define macro_dispatcher(macro,...) macro_dispatcher_(macro, VA_NUM_ARGS(__VA_ARGS__))
#define macro_dispatcher_(macro,nargs) macro_dispatcher__(macro, nargs)
#define macro_dispatcher__(macro,nargs) macro_dispatcher___(macro, nargs)
#define macro_dispatcher___(macro,nargs) macro ## nargs
#define DBN(...) macro_dispatcher(DBN, __VA_ARGS__)(__VA_ARGS__)
#define DBN1(a) cerr<<#a<<"="<<(a)<<"\n"
#define DBN2(a,b) cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"
#define DBN3(a,b,c) cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define DBN4(a,b,c,d) cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"
#define DBN5(a,b,c,d,e) cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<"\n"
#define endl '\n'
#define DBN1D(x) cerr<<#x<<endl;for(auto _:x){cerr<<_<<" ";}cerr<<endl
#define DBN2D(x) cerr<<#x<<endl;for(auto _:x){for(auto __:_){cerr<<__<<" ";}cerr<<endl;}cerr<<"------"<<endl
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mp(x,y) make_pair(x,y)
#define mpp(w,x,y,z) mp(mp(w,x),mp(y,z))
using namespace std;
typedef long long loli;
typedef vector<loli> vl;
typedef vector<vl> vvl;
typedef pair<loli,loli> pll;
typedef pair<pll,pll> pllll;
vl in,out,depth;
vvl edge,din;
int cnt=0;
int bs(vl&arr,int n,loli t,int l,int u){
if(l==u){
assert(u==0);
return -1;
}
// DBN("l",t,l,u);
int mid=(l+u)/2;
if(u-l==1){
if(arr[l]>=t)
return l;
return u;
}
if(arr[mid]<t)
return bs(arr,n,t,mid,u);
else
return bs(arr,n,t,l,mid);
}
void dfs(loli x){
in[x]=++cnt;
din[depth[x]].push_back(in[x]);
for(auto v:edge[x]){
depth[v]=depth[x]+1;
dfs(v);
}
out[x]=++cnt;
}
void solve(){
int n;
cin>>n;
edge.assign(n+1,vl());
depth.resize(n+1,0);
din.resize(n);
in.resize(n+1);
out=in;
for(int i=2;i<=n;++i){
int p;
cin>>p;
edge[p].push_back(i);
}
dfs(1);
// DBN2D(din);
int q;
cin>>q;
for(auto x:vl(q)){
int u,d;
cin>>u>>d;
if(depth[u]==d){
cout<<1<<endl;
}else if(depth[u]>d){
cout<<0<<endl;
}else{
// DBN(u,d);
// DBN1D(in);
// DBN1D(out);
// DBN1D(din[d]);
int l=bs(din[d],din[d].size(),in[u],0,din[d].size());
int r=bs(din[d],din[d].size(),out[u],0,din[d].size());
// DBN(l,r,r-l);
cout<<r-l<<endl;
}
}
}
int main(){
sync;
solve();
return 0;
} | #include <bits/stdc++.h>
long long func(std::vector<std::pair<long long, long long>> &vw, std::vector<long long> &boxsize, int l, int r) {
std::vector<long long> box;
for (int i = 0; i < (int)boxsize.size(); ++i) {
if (i < l || i > r) box.push_back(boxsize[i]);
}
std::vector<bool> used(box.size(), false);
std::sort(box.begin(), box.end());
long long res = 0LL;
for (int i = 0; i < (int)vw.size(); ++i) {
long long value = vw[i].first;
long long weight = vw[i].second;
int index = std::lower_bound(box.begin(), box.end(), weight) - box.begin();
while (index < (int)box.size() && used[index]) ++index;
if (index < (int)box.size()) { used[index] = true; res += value; }
}
return res;
}
int main() {
int n, m, q;
std::cin >> n >> m >> q;
std::vector<std::pair<long long, long long>> vw(n);
for (int i = 0; i < n; ++i) std::cin >> vw[i].second >> vw[i].first;
std::vector<long long> boxsize(m);
for (int i = 0; i < m; ++i) std::cin >> boxsize[i];
std::sort(vw.begin(), vw.end(), std::greater<std::pair<long long, long long>>());
std::vector<long long> res;
for (int i = 0; i < q; ++i) {
int l, r;
std::cin >> l >> r;
--l; --r;
res.push_back(func(vw, boxsize, l, r));
}
for (long long ans : res) std::cout << ans << std::endl;
return 0;
}
|
#include<iostream>
#include<algorithm>
#include<cstring>
#define debug(a) cout<<#a<<" = "<<a<<endl
using namespace std;
typedef long long ll;
const int N = 5010;
const int MOD = 998244353;
int n , m;
ll C[N];
ll f[N];
ll Q_power(ll a ,ll b){
ll res = 1;
while(b){
if(b & 1) res = res * a % MOD;
b >>= 1;
a = a*a % MOD;
}
return res;
}
ll X_1(ll a){ return Q_power(a ,MOD - 2) ;}
void init(){
C[0] = 1;
for(int i = 1 ; i <= n ; i ++){
C[i] = C[i - 1] * (n - i + 1) % MOD * X_1(i) % MOD;
}
}
ll F(int m){
if(!(~f[m])){
f[m] = 0;
if(!(m & 1))
for(int i = 0 ; i * 2ll <= m ; i ++){
f[m] = (f[m] + C[i * 2] * F(m / 2 - i) % MOD) % MOD;
}
}
return f[m];
}
int main(){
cin >> n >> m;
memset(f,0xff,sizeof f);
init(); f[0] = 1;
cout << F(m) << endl;
return 0;
}
| #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(5)<<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;
}
void Main() {
ll ans = 0;
LCIN(N, M);
COMB c;
vl ttt(M + 10);
for(int i = 0; i < M + 10; i++) {
ttt.at(i) = i;
}
// VECCOUT(ttt);
c.init_nCk(10000);
/*
vvl dp(6000, vl(15, 0));
dp.at(M).at(15) = 1;
*/
vl dp(M + 10, 0);
dp.at(M) = 1;
for(int i2 = 15; i2 >= 0; i2--) {
ll n = 1 << i2;
for(int j = 0; j < M + 3; j++) {
if(dp.at(j) && j/n/2) {
ll t = j/n/2;
// dump(j);
for(int i = 1; i <= t; i++) {
if(j - i*2*n >= 0 && i*2 <= N) {
dp.at(j - i*2*n) += dp.at(j)*c.nCk(N, i*2)%MOD;
dp.at(j - i*2*n) %= MOD;
}
}
// dump(j);
}
}
// VECCOUT(dp);
}
// VECCOUT(dp);
cout << dp.at(0) << endl;
}
int main() {
cout << fixed << setprecision(15);
Main();
return 0;
} |
#include <iostream>
using namespace std;
typedef long long ll;
const int MOD = 998244353;
struct Modint {
ll val;
Modint (ll _val = 0)
: val(_val % MOD) {}
Modint operator+ (Modint other) const {
return Modint(val + other.val);
}
void operator+= (Modint other) {
val += other.val;
val %= MOD;
}
Modint operator- () const {
return Modint(MOD - val);
}
Modint operator- (Modint other) const {
return Modint(val + MOD - other.val);
}
void operator-= (Modint other) {
val += MOD - other.val;
val %= MOD;
}
Modint operator* (Modint other) const {
return Modint(val * other.val);
}
void operator*= (Modint other) {
val *= other.val;
val %= MOD;
}
bool operator== (Modint other) const {
return val == other.val;
}
bool operator!= (Modint other) const {
return val != other.val;
}
};
Modint exp (Modint a, int k) {
if (k == 0) {
return Modint(1);
} else if (k % 2 == 0) {
Modint half = exp(a, k / 2);
return half * half;
} else {
return a * exp(a, k - 1);
}
}
Modint inv (Modint a) {
return exp(a, MOD - 2);
}
ostream& operator<< (ostream& out, Modint p) {
out << p.val;
return out;
}
const int MAX_N = 2e5 + 5;
const int MAX_LG = 20;
Modint dp [MAX_LG][MAX_N]; // dp[k][i] is # of ways to write i as a product of k non-1 divisors
Modint fact [MAX_N];
Modint ifact [MAX_N];
Modint choose (int n, int k) {
return fact[n] * ifact[k] * ifact[n - k];
}
int main () {
fact[0] = Modint(1);
for (int i = 1; i < MAX_N; i++) {
fact[i] = fact[i - 1] * Modint(i);
}
for (int i = 0; i < MAX_N; i++) {
ifact[i] = inv(fact[i]);
}
int n, m;
cin >> n >> m;
dp[0][1] = Modint(1);
for (int k = 0; k < MAX_LG - 1; k++) {
for (int i = 1; i <= m; i++) {
for (int j = 2 * i; j <= m; j += i) {
dp[k + 1][j] += dp[k][i];
}
}
}
Modint ans (0);
for (int i = 1; i <= m; i++) {
for (int k = 0; k < MAX_LG; k++) {
// k nonones, n - k ones
if (n - k < 0) {
continue;
}
ans += choose(n, k) * dp[k][i];
}
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;
ll MOD=998244353;
ll add(ll x, ll y)
{
x += y;
if (x >= MOD)
return x - MOD;
return x;
}
ll sub(ll x, ll y)
{
x -= y;
if (x < 0)
return x + MOD;
return x;
}
ll mult(ll x, ll y)
{
return (x * y) % MOD;
}
ll bin_pow(ll x, ll p)
{
if (p == 0)
return 1;
if (p & 1)
return mult(x, bin_pow(x, p - 1));
return bin_pow(mult(x, x), p / 2);
}
const int MAX = 510000;
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(int n, int k)
{
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n,m;
cin>>n>>m;
COMinit();
int ans=0;
/*vector<int>pre(30);
for (int i = 0; i <= 30; i++)
{
int cnt=0;
for(int j=n;j>=1; j--){
cnt+=bin_pow(j,i);
cnt%=MOD;
}
pre[i]=cnt;
}
*/
for (int i = 1; i <= m; i++)
{
int N = i;
int c=2;
int cnt=0;
int res=1;
map<int,int>mp;
while(c*c<=N){
if(N%c==0){
mp[c]++;
cnt++;
N/=c;
}
else{
//if(cnt>0) res *= COM(n-1+cnt, cnt);
res%=MOD;
c++;
cnt=0;
}
}
if(N!=1) {
mp[N]++;
cnt++;
}
for(auto &u : mp){
int x =u.second;
res*=COM(n-1+x,x);
res%=MOD;
}
//if(cnt>0) res*=COM(n-1+cnt, cnt);
res%=MOD;
//cerr<<i<<" "<<res<<endl;
ans+=res;
ans%=MOD;
}
cout<<(ans)%MOD<<endl;
return 0;
} |
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;
int main() {
ll T, N; cin >> T >> N;
ll ans = (N * 100 + T - 1) / T + N - 1;
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vc = vector<T>;
template<class T> using vvc = vc<vc<T>>;
template<class T> using vvvc = vc<vvc<T>>;
template<class T> using vvvvc = vvc<vvc<T>>;
template<class T> using PQ = priority_queue<T>;
template<class T> using invPQ = priority_queue<T, vector<T>, greater<T>>;
using IP = pair<int, int>;
using LP = pair<ll, ll>;
#define all(x) begin(x), end(x)
#define rep(i, n) for (int i = 0; (i) < (int)(n); i++)
#define rep3(i, m, n) for (int i = (m); (i) < (int)(n); i++)
#define repr(i, n) for (int i = (n) - 1; (i) >= 0; i--)
#define rep3r(i, m, n) for (int i = (n) - 1; (i) >= (int)(m); i--)
template<class T> inline bool chmax(T & a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T & a, T b) { if (a > b) { a = b; return 1; } return 0; }
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t, N;
cin >> t >> N;
auto isok = [&] (ll x) -> bool {
if (x - (x+1)*100/(100+t) < N) return true;
else return false;
};
ll ok = 0, ng = 1000000000000;
while (abs(ok - ng) > 1) {
ll mid = (ok + ng) / 2;
if (isok(mid)) ok = mid;
else ng = mid;
}
if ((ng+1)*100/(100+t) * (100+t)/100 == ng) cout << ok << endl;
else cout << ng << endl;
} |
/* include c++ libraries */
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <map>
#include <queue>
#include <set>
#include <bitset>
#include <tuple>
/* include c-lang libraries */
#include <climits>
#include <cmath>
#include <cassert>
/* include my libraries */
//#include <show_vec.hh>
using namespace std;
#define LINE DEBUG{ printf("LINE : %d\n", __LINE__); }
#define DEBUG if(false)
using ll = long long;
template<class T> using vec = vector<T>;
template<class T>void sort(vector<T> &v){
sort(v.begin(), v.end());
return;
}
template<class T>void rsort(vector<T> &v){
sort(v.begin(), v.end(), std::greater<T>());
return;
}
const int MOD = 1000000007;
int main(int argc, char* argv[]){
int N;
cin >> N;
vec<bool> A(N, false);
for(int i = 0; i < N; i++){
int tmp;
cin >> tmp;
A[tmp-1] = true;
}
string Ans = "Yes";
for(int i = 0; i < N; i++){
if(A[i] == false){
Ans = "No";
break;
}
}
cout << Ans << endl;
return 0;
}
| #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
//#include <atcoder/all>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
int main(){
int N; cin >> N;
vector<int> A(N); rep(i,N) cin >> A[i];
vector<int> B(N);
rep(i,N) B[i]=i+1;
sort(all(A));
sort(all(B));
if(A==B){
cout << "Yes" << endl;
}
else cout << "No" << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define pii pair<ll,ll>
#define inf 1000000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define autoitr(x,it) for(auto it = x.rbegin(); it != x.rend(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)
#define hmap gp_hash_table<ll, ll>
#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>
using namespace std;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
int main()
{
FAST/**/
ll n;
cin>>n;
ll arr[n];
map<ll,ll> ma;
rep(n)
cin>>arr[i], ma[arr[i]] = 1;
ma[0] = 1;
vector<ll> v;
autoit(ma,it)
{
v.pb(it->ff);
}
ll ans = 1;
for(ll i=1;i<v.size();i++)
ans = (ans * (v[i]-v[i-1]+1))%mod;
cout<<ans<<"\n";
return 0;
}
| #include <bits/stdc++.h>
# define INF32 2147483647
# define INF64 9223372036854775807
# define rep(i,l,n) for(int i=l,i##_end=n;i<i##_end;++i)
# define rrep(i,n,l) for(int i=((int)(n)-1),i##_end=l;i>=i##_end;--i)
# define erep(i,n) for(auto &i : n)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define _f_ first
# define _s_ second
using namespace std;
using ll = long long;
using ull = unsigned long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int main() {
// 1. input
ll N,X;
cin>>N>>X;
// 2.
// 3. output
rep(i,0,N){
ll a = 0;
cin>>a;
if(a == X) continue;
cout << a << endl;
}
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e6+10;
const double eps = 0.01;
inline ll read()
{
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
inline ll pt(ll ans,ll f){
printf("%lld",ans);
if(f==1) putchar(' ');
else putchar('\n');
}
ll n,k,m,tot;
ll a[N],c[N],vis[N],mi=1e10;
void dfs(int x,ll now){
if(x==n+1) mi=min(mi,now);
ll res=0;
for(int i=x;i<=n;i++){
res|=a[i];
dfs(i+1,res^now);
}
}
int main()
{
// freopen("../in.in","r",stdin);
ll _;
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
}
dfs(1,0);
cout<<mi<<endl;
return 0;
} |
// Problem : C - ORXOR
// Contest : AtCoder - AtCoder Beginner Contest 197(Sponsored by Panasonic)
// URL : https://atcoder.jp/contests/abc197/tasks/abc197_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
// Delete the dynamically allocated memory
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define pr pair<long long,long long>
#define mp(a,b) make_pair(a,b)
#define vr vector<long long>
#define mod1 1000000007
#define mod2 998244353
#define inf 1e18
#define ps(x,y) fixed<<setprecision(y)<<x
#define fill(a,b) memset(a, b, sizeof(a))
#define mk(arr,n,type) type *arr=new type[n];
#define ll long long
#define ld long double
#define w(x) int x; cin>>x; while(x--)
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll n;
cin>>n;
mk(a,n,ll)
for(ll i=0;i<n;i++){
cin>>a[i];
}
ll ans=inf;
for(ll i=0;i<(1<<(n-1));i++){
vr c;
ll sum=a[0];
for(ll j=1;j<n;j++){
if((i&(1<<(j-1)))){
c.pb(sum);
sum=a[j];
}else{
sum|=a[j];
}
}
c.pb(sum);
// for(ll j=0;j<c.size();j++){
// cout<<c[j]<<" ";
// }
// cout<<"\n";
ll x=0;
for(ll j=0;j<c.size();j++){
x^=c[j];
}
ans=min(ans,x);
}
cout<<ans<<"\n";
delete[] a;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll solve() {
ll N;
cin >> N;
vector<ll> X(N);
for ( int i = 0; i < N; i++ ) cin >> X[i];
// 素因数分解 O(x^(1/2))
auto PrimeFactor = [](ll x) {
map<ll, ll> pr;
for ( ll k = 2; k * k <= x; k++ ) {
while ( x % k == 0 ) {
pr[k]++;
x /= k;
}
}
if ( x > 1 ) pr[x]++;
return pr;
};
set<ll> s, sp;
s.insert(1);
for ( int i = 0; i < N; i++ ) {
swap(s,sp);
s.clear();
auto ps = PrimeFactor(X[i]);
for ( auto p : ps ) {
for ( ll x : sp ) {
if ( x % p.first != 0 ) {
s.insert(x*p.first);
} else {
s.insert(x);
}
}
}
}
return *s.begin();
}
int main() {
auto ans = solve();
cout << ans << "\n";
return 0;
} | #include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;
using Graph = vector<vector<long long>>;
template<class T> void chmin(T& a, T b) {
if (a > b) {
a = b;
}
}
const long long INF = 1LL << 60;
int N;
double func (double x, const vector<double> &a) {
double res = 0;
for (int i = 0; i < N; ++i) {
res += x + a[i] - min(2 * x, a[i]);
}
return res;
}
int main() {
cin >> N;
vector<double> a(N);
for (int i = 0; i < N; ++i) {
cin >> a[i];
}
sort(a.begin(), a.end());
double left = 0, right = 1e12;
while (right - left > 1e-6) {
double h1 = left + (right - left) / 3;
double h2 = right - (right - left) / 3;
if (func(h1, a) < func(h2, a)) {
right = h2;
} else {
left = h1;
}
}
double ans = func(left, a) / N;
cout << setprecision(12) << ans << endl;
return 0;
} |
/*Rabbi Zidni Ilma*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define scl(n) scanf("%lld",&n)
#define scll(n,m) scanf("%lld %lld",&n,&m)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define mod 1000000007
#define read freopen("input.txt","r",stdin)
#define write freopen("output.txt","w",stdout)
int main()
{
ll n,w,ans;
scll(n,w);
ans=n/w;
printf("%lld\n",ans);
}
| #include<bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define endl '\n'
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, w;
cin >> n >> w;
cout << n / w << endl;
return 0;
}
|
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef long double ld;
//#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rev(i,b,a) for (ll i = b - 1; i >= a; i--)
#define all(v) (v).begin(), (v).end()
#define maxe(v) *max_element(v.begin(), v.end())
#define mine(v) *min_element(v.begin(), v.end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define FF first
#define SS second
#define REM 1000000007
#define cont continue
#define PI 3.141592653589793238462643383279502
//#define debug(n1) cout<<"debug... "<<n1<<"\n"
//const ll INF=(1ll<<60)-1;//ll ans = 3e18 + 5;
//const int N=2e5+10;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool isprime(ll n){
if(n%2==0 && n!=2)return false;
for(ll i=3;i*i<=n;i+=2){
if(n%i==0)return false;
}
return true;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int tc=1;
//cin>>tc;
while(tc--){
ll n;
cin>>n;
ll a[n],b[n];
rep(i,0,n){cin>>a[i];}
rep(i,0,n){cin>>b[i];}
ll sum=0;
rep(i,0,n){
sum+=(a[i]*b[i]);
}
if(sum==0){cout<<"Yes\n";}
else{cout<<"No\n";}
}
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
#define ll long long
ll pwr(ll a, ll b){
ll res=1;
while(b>0){
if(b&1)
res=res*a;
a*=a;
b>>=1;
}
return res;
}
int main()
{
ll n;
cin>>n;
ll a[n],b[n];
ll sum=0;
for(int i=0;i<n;i++)
{
cin>>a[i];
}
for(int i=0;i<n;i++)
{
cin>>b[i];
}
for(int i=0;i<n;i++)
{
sum+=a[i]*b[i];
}
if(sum==0)
cout<<"Yes\n";
else cout<<"No\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int arr[801][801], prefix[801][801];
int n, k;
bool check(int m){
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
if(arr[i][j] <= m) prefix[i][j] = 1;
else prefix[i][j] = 0;
prefix[i][j] += prefix[i - 1][j] + prefix[i][j - 1] - prefix[i - 1][j - 1];
}
}
int maxx = 0;
for(int i = k; i <= n; i++){
for(int j = k; j <= n; j++){
maxx = max(maxx, prefix[i][j] - prefix[i - k][j] - prefix[i][j - k] + prefix[i - k][j - k]);
}
}
if(maxx >= k * k - k * k / 2) return true;
else return false;
}
int main(){
cin >> n >> k;
int minn = 2e9, maxx = 0;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
cin >> arr[i][j];
minn = min(minn, arr[i][j]);
maxx = max(maxx, arr[i][j]);
}
}
int l = minn, r = maxx;
while(r - l > 0){
int m = (l + r) / 2;
if(check(m)) r = m;
else l = m + 1;
}
cout << l << '\n';
} | #include <bits/stdc++.h>
using namespace std;
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
struct position {
int x, y;
};
int main() {
int h, w;
cin >> h >> w;
position g = {0, 0};
vector<string> a(h);
vector<vector<int>> c(h, vector<int>(w, 1 << 30));
vector<vector<position>> t(26);
vector<bool> init(26, true);
queue<position> q;
for (auto i = 0; i < h; i++) cin >> a[i];
for (auto i = 0; i < h; i++) {
for (auto j = 0; j < w; j++) {
if (a[i][j] == 'S') q.push({i, j}), c[i][j] = 0;
if (a[i][j] == 'G') g = {i, j};
if (a[i][j] - 'a' >= 0 and a[i][j] - 'a' < 26)
t[a[i][j] - 'a'].push_back({i, j});
}
}
while (not q.empty()) {
auto p = q.front();
q.pop();
for (auto i = 0; i < 4; i++) {
position n = {p.x + dx[i], p.y + dy[i]};
if (n.x < 0 or n.x >= h or n.y < 0 or n.y >= w)
continue;
if (a[n.x][n.y] == '#') continue;
if (c[n.x][n.y] <= c[p.x][p.y] + 1) continue;
c[n.x][n.y] = c[p.x][p.y] + 1;
if (a[n.x][n.y] != 'G') q.push(n);
}
auto index = a[p.x][p.y] - 'a';
if (index >= 0 and index < 26 and init[index]) {
init[index] = false;
for (auto& elm : t[index]) {
if (elm.x == p.x and elm.y == p.y) continue;
if (c[elm.x][elm.y] <= c[p.x][p.y] + 1)
continue;
c[elm.x][elm.y] = c[p.x][p.y] + 1;
q.push(elm);
}
}
}
if (c[g.x][g.y] == 1 << 30) c[g.x][g.y] = -1;
cout << c[g.x][g.y] << 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()
using i64=int64_t;
int main() {
int n;
cin>>n;
vector<int> x(n),y(n),r(n);
rep(i,n) {
cin>>x[i]>>y[i]>>r[i];
}
vector<int> a(n),b(n),c(n),d(n);
rep(i,n-5) {
a[i]=i;
b[i]=i;
c[i]=i+1;
d[i]=i+1;
cout << a[i] << " " << b[i] << " " << c[i] << " " << d[i] << endl;
}
cout << n-5 << " " << n-5 << " " << "1000" << " " << "1000" << endl;
cout << "1000" << " " << "1000" << " " << "2000" << " " << "2000" << endl;
cout << "2000" << " " << "2000" << " " << "3000" << " " << "3000" << endl;
cout << "3000" << " " << "3000" << " " << "4000" << " " << "4000" << endl;
cout << "4000" << " " << "4000" << " " << "10000" << " " << "10000" << endl;
} | #include <bits/stdc++.h>
using namespace std;
const int maxn = 1000 + 50;
const int inf = 1e9;
inline int lowbit(const int & x) { return x & (-x);}
int n, rt;
int ls[maxn], rs[maxn];
int a[maxn][maxn];
void check()
{
for(int i = 1; i <= n; ++i) for(int j = 1; j <= n; ++j) a[i][j] = (i == j) ? 0 : inf;
for(int i = 1; i <= n; ++i) a[i][ls[i]] = a[i][rs[i]] = 1;
for(int k = 1; k <= n; ++k)
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= n; ++j)
a[i][j] = min(a[i][k] + a[k][j], a[i][j]);
for(int i = 1; i <= n; ++i)
{
for(int j = 1; j <= n; ++j)
printf("%d ", a[i][j]);
puts("");
}
}
int main()
{
scanf("%d", &n);
for(int i = 0; i < n; ++i)
{
ls[i] = (i << 1) % n + 1;
rs[i] = (i << 1 | 1) % n + 1;
printf("%d %d\n", ls[i], rs[i]);
}
//check();
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
int main()
{
ll b,c;
cin>>b>>c;
if(b==0)
cout<<c;
else
{
ll ans=0;
if(c%2)
{
ans+=c-1;
if(b>0&&c>1)
ans-=1;
ans+=2;
ans+=2*min(abs(b),c/2);
if(c/2>=abs(b))ans--;
}
else
{
/*ans+=c;
ans--;
ans+=2;
c--;
ans+=2*min(abs(b),c/2);
if(c/2>=abs(b))ans--;*/
if(b<0)
{
ans+=c;
ans--;
ans+=2;
c--;
ans+=2*min(abs(b),c/2);
if(c/2>=abs(b))ans--;
}
else
{
ans+=c;
ans-=2;
ans+=2;
ans+=2*min(b,c/2);
ans--;
}
}
cout<<ans<<endl;
}
} | #include <bits/stdc++.h>
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define ALL(v) (v).begin(), (v).end()
#define LLA(v) (v).rbegin(), (v).rend()
#define SZ(v) (v).size()
#define INT(...) \
int __VA_ARGS__; \
read(__VA_ARGS__)
#define LL(...) \
ll __VA_ARGS__; \
read(__VA_ARGS__)
#define DOUBLE(...) \
double __VA_ARGS__; \
read(__VA_ARGS__)
#define CHAR(...) \
char __VA_ARGS__; \
read(__VA_ARGS__)
#define STRING(...) \
string __VA_ARGS__; \
read(__VA_ARGS__)
#define VEC(type, name, size) \
vector<type> name(size); \
read(name)
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
template <typename T> struct edge {
int to;
T cost;
edge(int t, T c) : to(t), cost(c) {}
};
template <typename T> using WGraph = vector<vector<edge<T>>>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;
template <class T> inline vector<T> make_vec(size_t a, T val) {
return vector<T>(a, val);
}
template <class... Ts> inline auto make_vec(size_t a, Ts... ts) {
return vector<decltype(make_vec(ts...))>(a, make_vec(ts...));
}
void read() {}
template <class T> inline void read(T &a) { cin >> a; }
template <class T, class S> inline void read(pair<T, S> &p) {
read(p.first), read(p.second);
}
template <class T> inline void read(vector<T> &v) {
for(auto &a : v)
read(a);
}
template <class Head, class... Tail>
inline void read(Head &head, Tail &...tail) {
read(head), read(tail...);
}
template <class T> inline void chmax(T &a, T b) { (a < b ? a = b : a); }
template <class T> inline void chmin(T &a, T b) { (a > b ? a = b : a); }
ll mod_pow(ll x, ll n, ll mod) {
if(n == 0)
return 1;
ll res = mod_pow(x * x % mod, n / 2, mod);
if(n & 1)
res = res * x % mod;
return res;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
LL(n, m);
cout << mod_pow(10, n, m * m) / m << endl;
} |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < int(n); i++)
using ll = long long;
using P = pair<int, int>;
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
int n, m;
cin >> n >> m;
vector<int> a(n), b(m);
rep(i, n) cin >> a[i];
rep(i, m) cin >> b[i];
vector<int> ans;
rep(i, n) {
bool ok = true;
rep(j, m) {
if(a[i] == b[j]) ok = false;
}
if(ok) ans.push_back(a[i]);
}
rep(i, m) {
bool ok = true;
rep(j, n) {
if(b[i] == a[j]) ok = false;
}
if(ok) ans.push_back(b[i]);
}
sort(ans.begin(), ans.end());
rep(i, ans.size()) {
cout << ans[i] << " ";
}
cout << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main()
{
int N, M;
cin >> N >> M;
vector<int> A(N), B(M);
for (auto &Ai : A)
cin >> Ai;
for (auto &Bi : B)
cin >> Bi;
set<int> XOR;
for (auto Ai : A)
XOR.insert(Ai);
for (auto Bi : B) {
if (XOR.count(Bi))
XOR.erase(Bi);
else
XOR.insert(Bi);
}
bool is_head = true;
for (auto XORi : XOR) {
if (!is_head)
cout << ' ';
cout << XORi;
is_head = false;
}
cout << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
using graph = vector<VI>;
template<class T = ll> using w_graph = vector<vector<pair<int, T>>>;
#define FOR(i,a,n) for(int i=(a);i<(n);++i)
#define eFOR(i,a,n) for(int i=(a);i<=(n);++i)
#define rFOR(i,a,n) for(int i=(n)-1;i>=(a);--i)
#define erFOR(i,a,n) for(int i=(n);i>=(a);--i)
#define SORT(a) sort(a.begin(),a.end())
#define rSORT(a) sort(a.rbegin(),a.rend())
#define fSORT(a,f) sort(a.begin(),a.end(),f)
#define all(a) a.begin(),a.end()
#define out(y,x) ((y)<0||h<=(y)||(x)<0||w<=(x))
#define tp(a,i) get<i>(a)
#ifdef _DEBUG
#define line cout << "-----------------------------\n"
#define stop system("pause")
#endif
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, const 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); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }
template<class T>inline void print(const T& a) { cout << a << "\n"; }
template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); }
template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); }
template<class T>inline void print(const vector<vector<T>>& v) { for (auto& a : v)print(a); }
inline string reversed(const string& s) { string t = s; reverse(all(t)); return t; }
template<class T>inline T sum(const vector<T>& a, int l, int r) { return a[r] - (l == 0 ? 0 : a[l - 1]); }
template<class T>inline void END(T s) { print(s); exit(0); }
void END() { exit(0); }
int main() {
init();
int n; cin >> n;
auto c = vec<ll>(n, n); cin >> c;
VL a(n), b(n);
FOR(i, 1, n)a[i] = a[i - 1] + (c[i][0] - c[i - 1][0]);
ll base = *min_element(all(a));
FOR(i, 0, n)a[i] -= base;
FOR(i, 0, n)b[i] = c[0][i] - a[0];
if (*min_element(all(a)) < 0 || *min_element(all(b)) < 0)END("No");
FOR(i, 0, n)FOR(j, 0, n)if (a[i] + b[j] != c[i][j])END("No");
print("Yes");
print(a);
print(b);
return 0;
} | #include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#pragma GCC optimize ("-O3")
#define int long long
#define ld long double
#define endl "\n"
#define rep(i,begin,end) for (__typeof(end) i=begin-(begin>end); i!=(end)-(begin>end); i+=1-2*(begin>end))
#define umap unordered_map
#define pq priority_queue
#define pb push_back
#define mp make_pair
#define fs first
#define sec second
#define lb lower_bound
#define ub upper_bound
#define mii map<int,int>
#define pii pair<int,int>
#define vc vector
#define vi vc<int>
#define vvi vc<vi>
#define all(v) v.begin(),v.end()
#define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper);
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define remax(a,b) a = max(a,b)
#define remin(a,b) a = min(a,b)
#define w(t) int t; cin>>t; rep(tc,0,t)
#define clr(a,x) memset(a,x,sizeof a)
#define chkbit(x,i) ((x)&(1LL<<(i)))
#define setbit(x,i) ((x)|(1LL<<(i)))
#define setbits(x) __builtin_popcountll(x)
#define zerobits(x) __builtin_ctzll(x)
#define ps(x,y) fixed<<setprecision(y)<<x
#define print(a, n) rep(i,0,n) cout<<a[i]<<" "; cout<<endl;
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
const int mod = 1e9+7;
const int mod2 = 998244353;
const int N = 2e5;
const int inf = 1e18;
const ld PI = 3.141592653589793;
//=====================================================
template<typename... T>
void in(T&... args) {((cin>>args), ...);}
template<typename... T>
void out(T&&... args) {((cout<<args<<" "), ...);}
template<typename... T>
void outln(T&&... args) {((cout<<args<<" "), ...); cout<<endl;}
int nxt(){int x;cin>>x;return x;}
int add(int a,int b,int mod){int res=(a+b)%mod;return (res<0)?res+mod:res;}
int mul(int a,int b,int mod){int res=(a*1LL*b)%mod;return (res<0)?res+mod:res;}
int range(int x,int y,int z) {return (x >= y && x <= z);}
struct customCompare {
bool operator () (int x, int y) {
return x>y;
}
};
//=====================================================
int calc(int x){
return ((x*(x+1))/2)%mod2;
}
void solve() {
int a,b,c;
in(a,b,c);
int ans = calc(a);
ans = mul(ans, calc(b), mod2);
ans = mul(ans, calc(c), mod2);
cout << ans << endl;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
solve();
// int t; cin >> t;
// for (int tc = 1; tc <= t; tc++) {
// cout << "Case #" << tc << ": ";
// solve();
// }
// printclock;
return 0;
} |
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>
#include <cassert>
#include <random>
#include <chrono>
/* #include <atcoder/all> */
/* using namespace atcoder; */
using namespace std;
void debug_out(){ cout << "\n"; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cout << H << " ";
debug_out(T...);
}
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
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 int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const ll MOD = 1000000007;
/* const ll MOD = 998244353; */
const ll INF = (1<<30)-1;
const ll INFLL = 1ll<<60;
const double PI = acos(-1);
struct INIT { INIT(){
cin.tie(0); ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
}}INIT;
signed main() {
int sx, sy, gx, gy;
cin >> sx >> sy >> gx >> gy;
if(sx == gx) cout << sx << "\n";
else{
int x = gx-sx;
int y = sy+gy;
ld t = (ld)x/y;
cout << t*sy+sx << "\n";
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ll long long
template <typename T>
bool PN(T x){ if (x <= 1) return false; if (x == 2) return true; for (int i = 2; i < sqrt(x) + 1; i++) if (x % i == 0) return false; return true;}
const ll MOD = 1e9+7;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
long long Comb(ll n, ll i){long long ans = 1; if(i>n || i < 0) return 0; if(i == 0 || i == n) return 1; else {for(int j = 1; j <= i; ++j){ans *=(n+1-j); ans /= j;} }return ans;}
template<typename T> T gcd(T a, T b){if(b == 0) return a;else return gcd(b, a%b);}
template<typename T> T lcm(T a, T b){if(b > a) swap(a, b); T g = gcd(a, b);return a / g * b;}
void solve(){
int n; cin >> n;
vector<pair<double, double>> inter;
rep(i, n) {
double t, a, b;
cin >> t >> a >> b;
if(t == 1) inter.push_back(make_pair(a, b));
else if(t == 2) inter.push_back(make_pair(a, b-0.1));
else if(t == 3) inter.push_back(make_pair(a+0.1, b));
else inter.push_back(make_pair(a+0.1, b-0.1));
}
sort(inter.begin(), inter.end());
int ans = 0;
for(int i = 0; i < n-1; ++i) {
//if(inter[i].first > inter[i].second) continue;
double end = inter[i].second;
for(int j = i + 1; j < n; ++j) {
//if(inter[j].first > inter[j].second) continue;
double start = inter[j].first;
if(start <= end) {
ans++;
//cout << i << " " << j << endl;
}
}
}
cout << ans << endl;
}
int main(void){
solve();
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
string s;
cin >> s;
int x = 0, o = 0, q = 0;
for (auto &i : s)
{
if (i == 'x')
x++;
else if (i == 'o')
o++;
else
q++;
}
if (o > 4 or o + q == 0)
cout << 0 << endl;
else
{
q += o;
int ans = q * q * q * q;
auto c = [](int n, int r)
{
if (r == 1)
return n;
if (r == 2)
return n * (n - 1) / 2;
if (r == 3)
return n * (n - 1) * (n - 2) / 6;
return n * (n - 1) * (n - 2) * (n - 3) / 24;
};
for (int i = 1; i <= o; i++)
{
ans -= (i & 1 ? 1 : -1) * pow(q - i, 4) * c(o, i);
}
cout << ans << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int res = 0;
for (int i = 0; i < 10000; i++) {
int n = i;
vector<int> d(4);
for (int j = 0; j < 4; j++) {
d.at(j) = n%10;
n /= 10;
}
bool check = true;
for (int j = 0; j < 4; j++) {
if (s.at(d.at(j)) == 'x') {
check = false;
break;
}
}
if (!check) {
continue;
}
for (int k = 0; k < 10; k++) {
if (s.at(k) == 'o') {
if (d.at(0) != k && d.at(1) != k && d.at(2) != k && d.at(3) != k) {
check = false;
break;
}
}
}
if (check) {
res++;
}
}
cout << res << endl;
} |
#include <iostream>
using namespace std;
int main(void) {
/* code */
/* A,Tの数、C,Gの数がそれぞれ等しい*/
/* 1文字ずつ足していき、最後の文字を含めた部分文字列のみを捜索するDP法 */
int N;
string S;
int answer = 0;
std::cin >> N >> S;
for (int i = 0; i < N; i++)
{
int c1 = 0;
int c2 = 0;
for (int j = i; j < N; j++)
{
switch(S[j])
{
case 'A':
c1++;
break;
case 'T':
c1--;
break;
case 'G':
c2++;
break;
case 'C':
c2--;
break;
}
if (c1 == 0 && c2 == 0)
{
answer++;
}
}
}
std::cout << answer << '\n';
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define FILL0(x) memset(x,0,sizeof(x))
#define FILL1(x) memset(x,-1,sizeof(x))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(20);
int a, b;
cin >> a >> b;
cout << (a+b)/2 << " " << (a-b)/2 << endl;
return 0;
}
|
//
// Created by Kushagra on 30-01-2021.
//
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<ll> vll;
typedef set<int> si;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define INF 1e18+5
#define MOD 1e9+7
#define TEST(i, a, t) for (int i=a; i<=t; i++)
#define FORn(i, a, b) for (int i=a; i>=b; i--)
#define all(v) v.begin(), v.end()
#define allR(v) v.rbegin(), v.rend()
#define FRIO freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int main()
{
FIO;
int n,s,d;
cin>>n>>s>>d;
int x,y;
int c=0;
TEST(i,1,n)
{
cin>>x>>y;
if(x<s && y>d)
{
c++;
}
}
if(c>0)
{
cout<<"Yes";
}
else
{
cout<<"No";
}
return 0;
} | #include <iostream>
int main(){
int N, S, D;
std::cin >> N >> S >> D;
int X, Y;
long long ans = 0;
for(int i=0; i<N; ++i){
std::cin >> X >> Y;
if(X<S && Y>D) ans += Y;
}
std::cout << (ans>0 ? "Yes" : "No") << std::endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll, ll> pl;
struct edge {
ll to; // 辺の行き先
ll weight; // 辺の重み
edge(ll t, ll w) : to(t), weight(w) { }
};
typedef vector<vector<ll> > Graph;
typedef vector<vector<edge> > WGraph;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define pb push_back
#define vout(v) for(int i=0; i < v.size(); i++) cout<<v[i]<<' '
#define blank_row cout<<endl
const ll MOD = 1e9 + 7;
const ll INF = MOD*MOD+1;
void dfs(const Graph &G, ll v, vector<bool> &seen, ll &ver, ll &edg){
seen[v] = true;
ver++;
edg += G[v].size();
for(auto next_v:G[v]){
if(seen[next_v]) continue;
dfs(G, next_v, seen, ver, edg);
}
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll n;
cin >> n;
Graph G(400000);
rep(i,n){
ll a,b;
cin >> a >> b;
a--; b--;
G[a].pb(b);
G[b].pb(a);
}
vector<bool> seen(400000);
ll ans = 0;
rep(v, 400000){
ll ver = 0, edg = 0;
if(seen[v]) continue;
dfs(G, v, seen, ver, edg);
ans += min(ver, edg/2);
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const long long N=200005;
vector<long long> edge[N];
long long tinggi[N];
long long isi[N];
long long berat[N];
long long a[N];
long long b[N];
void cari(long long a,long long harga,long long par){
berat[a]=isi[a]+harga;
int banyak=edge[a].size();
for(int i=0;i<banyak;i++){
if(edge[a][i]==par)continue;
cari(edge[a][i],berat[a],a);
}
return;
}
void jalanin(long long a,long long b,long long par){
tinggi[a]=b;
int banyak=edge[a].size();
for(int i=0;i<banyak;i++){
if(edge[a][i]==par)continue;
jalanin(edge[a][i],b+1,a);
}
return;
}
int main(){
long long i,n,hasil,jum,depan,tambah,harga,levelA,levelB;
int stat,urutan,tc;
scanf("%lld", &n);
getchar();
for(i=1;i<n;i++){
scanf("%lld %lld", &a[i], &b[i]);
getchar();
edge[a[i]].push_back(b[i]);
edge[b[i]].push_back(a[i]);
}
jalanin(1,0,-1);
scanf("%d", &tc);
getchar();
tambah=0;
for(i=0;i<tc;i++){
scanf("%d %d %lld", &stat,&urutan, &harga);
getchar();
if(stat==1){
levelA=tinggi[a[urutan]];
levelB=tinggi[b[urutan]];
if(levelA<levelB){
// cout<<"lili"<<endl;
isi[b[urutan]]-=harga;
tambah+=harga;
}
else{
//cout<<"lala"<<endl;
isi[a[urutan]]+=harga;
}
}
else{
levelA=tinggi[a[urutan]];
levelB=tinggi[b[urutan]];
if(levelA<levelB){
isi[b[urutan]]+=harga;
}
else{
isi[a[urutan]]-=harga;
tambah+=harga;
}
}
}
cari(1,0,-1);
for(i=1;i<=n;i++){
// cout<<tinggi[i]<<"--"<<endl;
printf("%lld\n",berat[i]+tambah);
}
return 0;
} |
#define DEBUG
#define OPTIMIZE
//#define PBDS
//#define INTERACTIVE
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e3;
const int INF = 0x3f3f3f3f, MOD = 1000000007;
const long long LINF = LONG_LONG_MAX;
#define INIT(arr, val) fill(arr, arr+(int)(sizeof(arr)/sizeof(arr[0])), val)
#define REP(i, lb, rb, inc) for(int i = (lb); i < (rb); i += inc)
#define RREP(i, rb, lb, dec) for(int i = (rb)-1; i >= (lb); i -= dec)
typedef long long ll;
typedef queue<int> QI;
typedef vector<int> VI;
#define pb push_back
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
#define X real()
#define Y imag()
#define ALL(x) x.begin(), x.end()
#define OUT(x) {x; cout<<endl;}
#define READ(a, t) t a; cin >> a
#define println(x) cout << (x); cout << endl
#define READARR(arr, n) REP(___i, 0, (n), 1) cin >> arr[___i]
#define PRINTARR(arr, n) REP(___i, 0, (n), 1) cout << arr[___i] << " ";
#ifdef INTERACTIVE
# define IOS()
#else
# define endl '\n'
# define IOS() cin.tie(0); cout.sync_with_stdio(0); cout.tie(0)
#endif
#ifdef DEBUG
# define dbg(x) x
#else
# define dbg(x)
#endif
#ifdef OPTIMIZE
# pragma GCC optimize("unroll-loops")
# pragma GCC optimize("O3")
# pragma GCC optimize("Ofast")
#endif
#ifdef PBDS
# include <bits/extc++.h>
using namespace __gbu_pbds;
#endif
void NO() { cout << "-1\n"; exit(0); }
set<string> a;
vector<string> v;
signed main() {
IOS();
READ(n, int);
REP(i, 0, n, 1) {
READ(str, string);
if (str[0] == '!') {
a.insert(str);
} else {
v.pb(str);
}
}
for(string str : v) {
str = "!"+str;
if (a.find(str) != a.end()) {
cout << str.substr(1, str.size()-1) << endl;
exit(0);
}
}
cout << "satisfiable" << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
int main()
{
SPEED
int n;
cin >> n;
vector<string> clean;
unordered_map<string, int> mp;
for (int i = 0; i < n; ++i)
{
string s;
cin >> s;
if (s[0] == '!')
{
string s2 = "";
for (int i = 1; i < s.size(); ++i)
{
s2 += s[i];
}
mp[s2]++;
}
else
{
clean.push_back(s);
}
}
for (int i = 0; i < clean.size(); ++i)
{
if (mp.count(clean[i]))
{
cout << clean[i];
return 0;
}
}
cout << "satisfiable";
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int long long
#define pb push_back
#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(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x,y) cout<<setprecision(y)<<x
#define mk(arr,n,type) type *arr=new type[n];
#define w(x) int x; cin>>x; while(x--)
#define pw(b,p) pow(b,p) + 0.1
#define endl "\n"
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void __print(int32_t x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
void fastIO()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
void solve()
{
int n;
cin>>n;
int ar[n];
for(int i=0;i<n;i++)
{
cin>>ar[i];
}
vector<pii> ans;
ans.pb({0,ar[0]});
for(int j=1;j<n;j++)
{
int sz = ans.size();
for(int i=0;i<sz;i++)
{
ans.pb({ans[i].ff^ans[i].ss,ar[j]});
//.//debug(ans[i]);
ans[i].ss=ans[i].ss|ar[j];
///debug(ans[i]);
}
//debug(ans);
}
int ret = inf;
for(pii i: ans)
{
//debug(i);
ret = min(ret, i.ff^i.ss);
}
cout<<ret;
}
int32_t main()
{
fastIO();
//w(t)
{
solve();
cout<<endl;
}
return 0;
} | #include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define mod 1000000000000007
#define ff first
#define int long long
#define pb push_back
void c_p_c()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
int arr[21];
int orr[21][21];
void make_or(int n)
{
for (int i = 0; i <= n; i++)
for (int j = 0; j <= n; j++)
orr[i][j] = 0;
for (int i = 0; i < n; i++)
{
int ans = 0;
for (int j = i; j < n; j++)
{
ans = ans | arr[j];
orr[i][j] = ans;
}
}
return;
}
int32_t main()
{
c_p_c();
int n;
cin >> n;
for (int i = 0; i < n; i++)
cin >> arr[i];
make_or(n);
int finland = mod;
int val = pow(2, n) - 1;
for (int rrr = 1; rrr <= val; rrr++)
{
int l = 0;
int ans = 0;
for (int i = 0; i < n; i++)
{
if (rrr & (1 << i))
{
ans ^= orr[l][i];
l = i + 1;
}
}
if (l < n)
ans ^= orr[l][n - 1];
finland = min(finland, ans);
}
cout << finland << endl;
return 0;
}
|
#line 2 "/Users/kaage/Desktop/ProgrammingWorkspace/library/other/template.hpp"
#define _CRT_SECURE_NO_WARNINGS
#pragma target("avx2")
#pragma optimize("O3")
#pragma optimize("unroll-loops")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define all(V) V.begin(),V.end()
typedef unsigned int uint;
typedef long long lint;
typedef unsigned long long ulint;
typedef std::pair<int, int> P;
typedef std::pair<lint, lint> LP;
constexpr int INF = INT_MAX/2;
constexpr lint LINF = LLONG_MAX/2;
constexpr double eps = DBL_EPSILON;
constexpr double PI=3.141592653589793238462643383279;
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
if (lhs < rhs) {
lhs = rhs;
return 1;
}
return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
if (lhs > rhs) {
lhs = rhs;
return 1;
}
return 0;
}
inline lint gcd(lint a, lint b) {
while (b) {
lint c = a;
a = b; b = c % b;
}
return a;
}
inline lint lcm(lint a, lint b) {
return a / gcd(a, b) * b;
}
bool isprime(lint n) {
if (n == 1)return false;
for (int i = 2; i * i <= n; i++) {
if (n % i == 0)return false;
}
return true;
}
template<typename T>
T mypow(T a, lint b) {
T res(1);
while(b){
if(b&1)res*=a;
a*=a;
b>>=1;
}
return res;
}
lint modpow(lint a, lint b, lint m) {
lint res(1);
while(b){
if(b&1){
res*=a;res%=m;
}
a*=a;a%=m;
b>>=1;
}
return res;
}
template<typename T>
void printArray(std::vector<T>& vec) {
rep(i, vec.size()){
std::cout << vec[i];
std::cout<<(i==(int)vec.size()-1?"\n":" ");
}
}
template<typename T>
void printArray(T l, T r) {
T rprev = std::prev(r);
for (T i = l; i != rprev; i++) {
std::cout << *i << " ";
}
std::cout << *rprev << std::endl;
}
LP extGcd(lint a,lint b) {
if(b==0)return {1,0};
LP s=extGcd(b,a%b);
std::swap(s.first,s.second);
s.second-=a/b*s.first;
return s;
}
LP ChineseRem(const lint& b1,const lint& m1,const lint& b2,const lint& m2) {
lint p=extGcd(m1,m2).first;
lint tmp=(b2-b1)*p%m2;
lint r=(b1+m1*tmp+m1*m2)%(m1*m2);
return std::make_pair(r,m1*m2);
}
template<typename F>
inline constexpr decltype(auto) lambda_fix(F&& f){
return [f=std::forward<F>(f)](auto&&... args){
return f(f,std::forward<decltype(args)>(args)...);
};
}
#line 2 "main.cpp"
int N,M,w[8],l[100010],v[100010];
std::vector<P> vec;
int main(){
std::cin>>N>>M;
rep(i,N)std::cin>>w[i];
rep(i,M){
std::cin>>l[i]>>v[i];
vec.emplace_back(v[i],l[i]);
}
if(*std::min_element(v,v+M)<*std::max_element(w,w+N)){
puts("-1");
return 0;
}
vec.emplace_back(0,0);
std::sort(all(vec));
rep(i,M)chmax(vec[i+1].second,vec[i].second);
std::vector<int> pm(N);
std::iota(all(pm),0);
int ans=INF;
do{
std::vector<int> dp(N);
rep(i,N-1){
int weight=w[pm[i]];
for(int j=i+1;j<N;j++){
weight+=w[pm[j]];
chmax(dp[j],dp[i]+std::prev(std::lower_bound(all(vec),P{weight,0}))->second);
}
}
chmin(ans,dp[N-1]);
}while(std::next_permutation(all(pm)));
std::cout<<ans<<std::endl;
return 0;
} | #include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <cmath>
using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF
constexpr int INTINF {1000000000};//int = 2*INTINF
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t; ++i)
template<typename T>
void maxs(T& x, T&& y) {
x=std::max(x,y);
}
template<typename T>
void maxs(T& x, T& y) {
x=std::max(x,y);
}
template<typename T>
void mins(T& x, T&& y) {
x=std::min(x,y);
}
template<typename T>
void mins(T& x, T& y) {
x=std::min(x,y);
}
int main() {
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
ll n; cin >> n;
const std::string S {"110"};
std::string T; cin >> T;
constexpr ll const_n {30000000000};
//constexpr ll const_n {3};
ll ans {};
rep(i, 3) {
bool is_find {true};
rep(j, n) {
if (T[j] != S[(i+j)%3]) {
is_find = false;
break;
}
}
if (is_find == true) {
ans += (const_n - n- i) / S.size() + 1;
}
}
cout << ans << '\n';
}
|
#include<iostream>
using namespace std;
int main()
{
int m, h;
cin >> m >> h;
if(h % m == 0)
cout << "Yes";
else
cout << "No";
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define int long long
#define pb push_back
#define mp make_pair
#define for0(i,n) for(int i=0;i<n;i++)
#define for1(i,n) for(int i=1;i<=n;i++)
#define w(x) int x;cin>>x;while(x--)
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pair<int,int>>
#define vvi vector<vector<int>>
#define precision(x,k) fixed<<setprecision(k)<<x
#define inf 1e16
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>ordered_set;
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
int m,k;
cin>>m>>k;
if(k%m==0)
cout<<"Yes\n";
else
cout<<"No\n";
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(){
int a,b;
cin >> a >> b;
cout << (double)(a-b)/a*100;
} | #include<bits/stdc++.h>
using namespace std;
int main() {
double a , b; cin>>a>>b;
scanf("%lf%lf" , &a,&b);
double ans = (a - b)/a;
ans = (ans * 100.0);
printf("%.7f" , ans);
} |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<pair<int,int>> vpi;
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define pb push_back
#define rev(i,a,b) for(int i=a;i<b;i++)
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
const ll mod=1e9+7;//cout<<fixed<<setprecision(15);
ll exp(ll x,ll y){;ll res=1;while(y){if(y &1)res=res*x;x=x*x;y>>=1;}return res;}
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(ll n){if(n<2)return 0;for(int i=2;i*i<=n;i++)if(n%i==0)return 0;return 1;}
int main()
{
fast;
int T=1;
//cin>>T;
while(T--)
{
ll n;
cin>>n;
int s=log2(n);
ll ans=1e18;
for(ll b=s;b>=0;b--)
{
ll a=n/exp(2,b);
ll c=n-a*exp(2,b);
ans=min(ans,a+b+c);
}
cout<<ans<<endl;
}
}
| // D - Circle Lattice Points
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using dbl = long double;
ll MAX = 2e9, scale = 1e4;
ll X, Y, R;
ll in(){
dbl x; cin>>x;
return round(x*scale);
}
ll lo_bin(ll dy2){
ll ok = X;
ll ng = -(MAX + 1);
while(ok - ng > 1){
ll x = (ok + ng) / 2;
ll dx = x - X;
if(dy2 + dx*dx <= R*R) ok = x;
else ng = x;
}
// cout<<" ok "<<ok<<"\n";
return ok;
}
ll hi_bin(ll dy2){
ll ok = X;
ll ng = MAX + 1;
while(ng - ok > 1){
ll x = (ok + ng) / 2;
ll dx = x - X;
if(dy2 + dx*dx <= R*R) ok = x;
else ng = x;
}
return ok;
}
int main(){
X = in(), Y = in(), R = in();
ll ans = 0;
for(ll y=-MAX; y<=MAX; y+=scale){
ll dy = y - Y;
ll dy2 = dy*dy;
if(R*R - dy2 < 0) continue;
ans += floor(hi_bin(dy2) / (dbl)scale)
- ceil(lo_bin(dy2) / (dbl)scale) + 1;
}
cout<< ans <<endl;
}
|
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
return (ull)rng() % B;
}
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n,m; cin >> n >> m;
vector<vector<pair<int,int>>> g(n);
vector<int> c(m),d(m);
for(int i=0;i<m;i++){
int x,y; cin >> x >> y;
x--,y--;
g[x].push_back({y,i});
g[y].push_back({x,i});
cin >> c[i] >> d[i];
}
vector<ll> dp(n,1e18);
dp[0]=0;
priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>> pq;
pq.push({0,0});
auto cost=[&](int j,ll ti)->ll{
ll res=d[j]/(ti+1);
ll p=sqrt(d[j]);
for(ll T=max(ti,p-15);T<=p+15;T++){
res=min(res,T-ti+d[j]/(T+1));
}
return res+c[j];
};
while(pq.size()){
auto p=pq.top(); pq.pop();
if(dp[p.second]!=p.first)continue;
int s=p.second;
for(auto to:g[s]){
ll c=cost(to.second,p.first);
int t=to.first;
if(dp[t]>c+p.first){
dp[t]=c+p.first;
pq.push({dp[t],t});
}
}
}
if(dp[n-1]==1e18)dp[n-1]=-1;
cout << dp.back() << endl;
} | #include <bits/stdc++.h>
#define REP(i, nn ) for(int i = 0 ; i < (int) nn; i++)
#define REPS(i, ss, nn ) for(int i = ss ; i < (int) nn; i++)
#define REV(i, ss, nn ) for(int i = ss ; i >= nn; i--)
#define deb(x) std::cout << #x << " " << x << endl;
#define debl(x) std::cout << #x << " " << x << " ";
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
namespace std{
template<class Fun>
class y_combinator_result{
Fun fun_;
public:
template<class T>
explicit y_combinator_result(T &&fun) : fun_(std::forward<T>(fun)){}
template<class ...Args>
decltype(auto) operator()(Args&&...args){
return fun_(std::ref(*this), std::forward<Args>(args)...);
}
};
template<class Fun>
decltype(auto) y_combinator(Fun && fun){
return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun));
}
};
template<typename T>
bool umax(T& a, T b){
bool ret = a < b;
if(ret) a = b;
return ret;
}
template<typename T>
bool umin(T& a, T b){
bool ret = a > b;
if(ret) a = b;
return ret;
}
struct edge{
int to; ll cost;
int from;
edge(){ edge(0,0);}
edge(int to_, ll cost_) : to(to_), cost(cost_){}
edge(int to_, int from_, ll cost_) : to(to_), cost(cost_), from(from_){}
};
template<typename... T>
void read(T& ... a){
((cin >> a),...);
}
template<typename... T>
void write(T... a){
((cout << a),...);
}
template<typename T>
vector<T> read_array(int sz){
vector<T> ret(sz);
for(auto & x : ret) cin >> x;
return ret;
}
int m, n;
constexpr int mxN = 1e5;
vector<array<ll,3>> adj[mxN];
ll dist[mxN];
ll f(ll d, ll t0, ll x){
return t0 + x + d / (t0 + 1 + x);
}
ll best_time(ll d, ll t0){
ll left = ceil(sqrtl(d));
ll ans = f(d, t0, 0);
for(ll x = max(0ll, left - 10) ; x <= left + 10; x++){
umin(ans, f(d, t0, x));
}
return ans;
}
void solve(){
read(n, m);
REP(i, m){
ll a, b, c, d;
read(a, b, c, d);
a--; b--;
// if(a == b) continue;
adj[a].push_back({b, c, d});
adj[b].push_back({a, c, d});
}
ll INF = 3e14;
REP(i, n) dist[i] = INF;
dist[0] = 0;
set<pair<ll,ll>> st;
st.insert({dist[0], 0});
while(st.size()){
auto [t, idx] = *st.begin();
st.erase(st.begin());
if(dist[idx] < t) continue;
// debl(idx) deb(t)
for(auto edge : adj[idx]){
auto [nxt, c, d] = edge;
ll best = best_time(d, t);
best += c;
if(best < dist[nxt]){
dist[nxt] = best;
st.insert({dist[nxt], nxt});
}
}
}
if(dist[n-1] >= INF){
write(-1);
return;
}
write(dist[n-1]);
}
int main()
{
//making data IO Fast
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
/****************************/
int T = 1;
// cin >> T;
while(T--)
solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int v, t, s, d;
int main() {
cin >> v >> t >> s >> d;
if (d >= v * t && d <= v * s) puts("No");
else puts("Yes");
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ll a,b,c,d;
cin >> a >> b >> c>>d;
cout << min({a,b,c,d}) << endl;
}
|
#include <bits/stdc++.h>
#define ll long long int
#define pii pair<ll,ll>
#define vi vector<ll>
#define mii map<ll,ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mod 1000000007
#define inf 1e18
#define endl "\n"
#define ps(x,y) fixed<<setprecision(y)<<x
#define all(x) (x).begin(),(x).end()
#define FOR(i, j, k, in) for (ll i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (ll i=j ; i>k ; i-=in)
using namespace std;
bool bysec(const pair<string,ll> &a, const pair<string,ll> &b)
{
return (a.second < b.second);
}
bool rev(ll a, ll b)
{
return a > b;
}
void solve()
{
ll a[3];
cin>>a[0]>>a[1]>>a[2];
sort(a,a+3);
cout<<a[1]+a[2];
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t = 1;
//cin>>t;
while(t--)
solve();
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define vi vector<int>
#define vc vector<char>
bool cmp(ll a,ll b)
{
return a>b;
}
ll lcm(ll n,ll m)
{
return (n*m)/__gcd(n,m);
}
bool status[10000+ 1];
vi v,vp;
void siv()
{
ll N= 10000;
for (int i = 2; i*i <= N; i++)
{
if (status[i] == 0)
{
for (int j = i * i; j <= N; j += i)
status[j] = 1;
}
}
status[1] = 1;
for(int i=2; i<=N; i++)
{
if(status[i]==0)
v.pb(i);
}
}
int main()
{
int t,i,n,k,y,j,c1,c2,h,q,l,m,r,x,c;
cin>>h>>q>>y;
ll s=0;
s+=h;
s+=q;
s+=y;
s-=min(h,min(q,y));
cout<<s;
} |
#include <bits/stdc++.h>
#define int int
#define maxn 800005
#define mod 3
using namespace std;
int n;
char r[maxn];
char get_char(){
char ch = getchar();
while(ch != 'W' && ch != 'B' && ch != 'R') ch = getchar();
return ch;
}
int jc[maxn], inv[maxn];
int qpow(int a, int b, int p){
if(b == 0) return 1;
int tmp = qpow(a, b / 2, p);
tmp = (tmp * tmp) % p;
if(b & 1) tmp = (tmp * a) % p;
return tmp;
}
void get_jc(){
jc[0] = 1;
for(int i = 1; i <= n; i++)
jc[i] = (jc[i - 1] * i);
}
int C(int a, int b, int p) {
if (b < a) return 0;
int s = jc[a] * jc[b - a] % p;
return jc[b] * qpow(s, p - 2, p) % p;
}
int lucas(int x, int y, int p) {
if (x == 0) return 1;
return lucas(x / p, y / p, p) * C(x % p, y % p, p) % p;
}
int tra(char ch){
//putchar(ch);
if(ch == 'B') return 1;
if(ch == 'W') return 2;
if(ch == 'R') return 0;
return -1;
}
signed main(void)
{
scanf("%lld", &n);
for(int i = 1; i <= n; i++)
r[i] = get_char();
get_jc();
int res = 0;
for(int i = 0; i <= n - 1; i++)
{
res = (res + tra(r[i + 1]) * lucas(i, n - 1, mod)) % mod;
//printf("%d\n", res);
}
if((n + 1) & 1)
res = -res;
res = ((res % mod) + mod) % mod;
if(res == 1)
printf("B\n");
else if(res == 2)
printf("W\n");
else
printf("R\n");
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
using ll=long long;
ll fac3[400005];
ll fac[400005];
ll N;
string s;
void init_(){
fac3[0]=0;fac[0]=1;
for(ll i=1;i<400005;i++){
ll x=0;ll I=i;
while(I%3==0){
I/=3;x++;
}fac3[i]=fac3[i-1]+x;
fac[i]=(fac[i-1]*I)%3;
}
}
int main(){
cin>>N>>s;
ll sum=0;init_();
for(ll i=0;i<N;i++){
if(fac3[N-1]-fac3[i]-fac3[N-1-i]!=0)
continue;
ll x=(fac[N-1]*fac[i]*fac[N-1-i])%3;
if(s[i]=='W')x=0;
else if(s[i]=='R'){}else x=(2*x)%3;
if(N%2==0)x=(3-x)%3;
sum=(sum+x)%3;
}if(sum==0)cout<<"W"<<endl;
else if(sum==1)cout<<"R"<<endl;
else cout<<"B"<<endl;
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
const double phi=(1+sqrt(5))/2;
int main(){
long long N;
cin>>N;
long long T=(long long)(N/(1+phi)-500000);
for(int ttt=0;ttt<1000000;ttt++){
if(T+ttt<0)continue;
vector<array<long long,2>>A(1);
A[0]={N,T+ttt};
for(int i=0;i<130;i++){
if(A[i][0]<A[i][1]){
A.push_back({A[i][0],A[i][1]-A[i][0]});
}else if(A[i][0]>A[i][1]){
A.push_back({A[i][0]-A[i][1],A[i][1]});
}else if(A[i][0]==0||A[i][1]==0){
break;
}else if(A[i][0]<=9){
A.push_back({A[i][0],0});
break;
}else{
double x=A[i][0]/(1+phi)*phi;
while(A[i][0]>x){
if(i>130)break;
A.push_back({A[i][0]-1,A[i][1]});
i++;
}
i--;
}
}
if(A.size()+max(A.back()[0],A.back()[1])>130)continue;
reverse(A.begin(),A.end());
cout<<A.size()-1+max(A[0][0],A[0][1])<<'\n';
if(A[0][0]>0){
for(int i=0;i<A[0][0];i++)cout<<"1\n";
}else{
for(int i=0;i<A[0][1];i++)cout<<"2\n";
}
for(int i=1;i<A.size();i++){
if(A[i][0]==A[i-1][0]+A[i-1][1]&&A[i][1]==A[i-1][1]){
cout<<"3\n";
}else if(A[i][1]==A[i-1][0]+A[i-1][1]&&A[i][0]==A[i-1][0]){
cout<<"4\n";
}else if(A[i][0]==A[i-1][0]+1){
cout<<"1\n";
}else{
cout<<"2\n";
}
}
return 0;
}
}
| #include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <functional>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <bitset>
#include <math.h>
#include <random>
#include <chrono>
#include <assert.h>
using namespace std ;
using ll = long long ;
using ld = long double ;
template<class T> using V = vector<T> ;
template<class T> using VV = V<V<T>> ;
using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end()
ll mod = 1000000007 ;
long double pie = acos(-1) ;
ll INF = 1e18 ;
void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
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 ;
}
void fix_cout(){cout << fixed << setprecision(20) ;}
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(){
ll n ; cin >> n ;
V<pair<ll,ll>> f(88) ;
f[0] = {0,0} ;
f[1] = {1,0} ;
for(int i=2;i<88;i++){
f[i].first = f[i-1].first+f[i-1].second ;
f[i].second = f[i-1].first ;
}
V<bool> use(88,false) ;
ll m = n ;
for(int i=87;i>0;i--){
if(m>=f[i].first){
use[i] = true ;
m -= f[i].first ;
}
}
int t = 0 ;
V<int> ans ;
pair<ll,ll> cur(0,0) ;
while(cur.first!=n){
if(use[87-t]){
if(t&1){
ans.push_back(2) ;
cur.second++ ;
}else{
ans.push_back(1) ;
cur.first++ ;
}
}
if(t&1){
ans.push_back(4) ;
cur.second += cur.first ;
}else{
ans.push_back(3) ;
cur.first += cur.second ;
}
t++ ;
}
reverse(all(ans)) ;
for(int i=(int)ans.size()-1;i>=0;i--){
if(ans[i]<=2) break ;
ans.pop_back() ;
}
reverse(all(ans)) ;
cout << ans.size() << endl ;
for(auto i:ans) cout << i << endl ;
} |
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using llu = unsigned long long;
using ld = long double;
#define CEIL(x, y) (ll)ceil((ld)(x) / (ld)(y))
#define dbgPR(ds) cout << ds.first << ' ' << ds.second
#define dbgLST(ds) for(auto it : ds) cout << it << ' '
#define dbgMP(ds) for(auto it : ds) cout << it.first << ' ' << it.second << '\n'
const double PI = acos(-1.0), g = 9.80665;
const bool unseen = 0;
const ll inf = 1e18 + 505, ninf = -1e18 - 505;
const int MOD = 1000000007;
void solve(void)
{
ll n, k;
cin >> n >> k;
map<ll, ll> mp;
for(int i = 0; i < n; i++) {
ll a, b;
cin >> a >> b;
mp[a] += b;
}
ll ans = k;
for(auto it : mp) {
if(ans >= it.first) {
ans += it.second;
}
else break;
}
cout << ans;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int testcase = 1;
// cin >> testcase;
while(testcase--) {
solve();
}
return 0;
} | #include <iostream>
#include <vector>
#include <numeric>
#include<cstdlib>
#include <map>
#include <algorithm> // std::random_shuffle
#define INF (1<<30)
#define ll long long
using namespace std;
int main() {
int N;
cin>>N;
ll K;
cin>>K;
vector<pair<ll,ll>> AB;
for(int i=1;i<=N;i++) {
AB.push_back({-1,-1});
cin>>AB.back().first>>AB.back().second;
}
sort(AB.begin(),AB.end());
ll curr = 0;
for(int i=0;i<AB.size();i++) {
ll id = AB[i].first;
ll B = AB[i].second;
if (id - curr <= K) {
K -= id-curr;
K += B;
curr = id;
} else {
break;
}
}
curr += K;
cout << curr << endl;
} |
#include<bits/stdc++.h>
#define LL long long
#define dl double
template <class T>
void rd(T &x){
x=0;T f=1;char ch=getchar();
while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch<='9' && ch>='0'){x=x*10+ch-'0';ch=getchar();}x*=f;
}
using namespace std;
int main(){
// freopen("in.txt","r",stdin);
// freopen("o.txt","w",stdout);
LL n;
rd(n);
LL l = 1,r = n + 1;
while(l != r){
LL mid = (l + r) / 2 + 1;
__int128 a1 = 1;
a1 = a1 * (n + 1 - mid + 1) * (mid + n + 1) / 2;
__int128 a2 = 1;
a2 = a2 * n * (n + 1) / 2;
if(a1 < a2)r = mid - 1;
else l = mid;
}
cout << n + 1 - l + 1 << endl;
return 0;
}
/**/ | #include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
using ll = long long;
using P = pair<int,int>;
using mp = map<int,int>;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
int main(){
int k;
cin >> k;
ll ans = 0;
for(int i = 1; i <= k; i++){
for(int j = 1; j <= k / i; j++){
//cout << i << " " << j << " " << (int)(k / (i * j)) << "\n";
int tmp = k / (i * j);
ans += tmp;
}
}
cout << ans << "\n";
return 0;
}
|
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define debug(x) cerr << #x << " = "<< x << "\n"
#define shaman ios::sync_with_stdio(0),cin.tie(0);
using namespace std;
constexpr int inf=1e18,N=400010;
vector<int> v[N];
bool vis[N],ok;
int DFS(int now,int pre){
int tmp=1;
vis[now]=1;
for(auto x:v[now]){
if(x==pre) continue;
if(vis[x]) {
ok=true;
continue;
}
tmp+=DFS(x,now);
}
return tmp;
}
signed main(){shaman
int n,a,b;
cin >> n;
set<pii> st,st2;
set<int> num;
for(int i=0;i<n;i++){
cin >> a >> b;
if(a>b) swap(a,b);
if(st.find({a,b})!=st.end()) continue;
st.insert({a,b});
num.insert(a);
num.insert(b);
v[a].pb(b);
v[b].pb(a);
}
int ans=0;
for(auto x:num){
ok=false;
if(vis[x]) continue;
ans+=DFS(x,-1);
if(!ok) ans--;
}
cout << ans << "\n";
}
| #include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define pi pair<int,int>
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define sz(x) ((int)x.size())
#define ln(x) ((int)x.length())
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define dbg(x) cout << #x << ": " << x << endl
#define clr(x,v) memset(x, v, sizeof(x))
#define dblout(x) cout << setprecision(x) << fixed;
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
const double eps = 1e-9;
const double PI = acos(-1.0);
const ll mod = 1e9 + 7;
const int MAXN = 100 + 5;
/*
Consider a fixed diameter D
This circle must pass through all the gaps between some points to start from left and end up on the right
when can it not pass through?
Let us join all points with a line which have distance < D
Also consider points (i, 100) and (i, -100) as well
When the top boundary (y = 100) and bottom boundary (y = -100)
are connected by some sequence of lines something like this
--------------------------------
|
/
/
/
|
---------------------------------
Then no circle can pass through from the left to the right
We can use DSU/BFS/DFS anything really to check if we can go from some (i, 100) to (j, -100)
Used DSU here
*/
int dcmp(double a, double b)
{
return (fabs(a - b) < eps) ? 0 : (a < b ? -1 : +1);
}
double length(pi a, pi b)
{
return sqrt((a.ff - b.ff) * 1.0 * (a.ff - b.ff) + (a.ss - b.ss) * 1.0 * (a.ss - b.ss));
}
int parent[10 * MAXN], sz[10 * MAXN];
void make_set(int n)
{
iota(parent, parent + n, 0);
fill(sz, sz + n, 1);
}
int find_set(int v)
{
if(v == parent[v])
return v;
else
return parent[v] = find_set(parent[v]);
}
bool union_set(int a, int b)
{
a = find_set(a), b = find_set(b);
if(sz[a] < sz[b])
swap(a, b);
if(a != b)
parent[b] = a, sz[a] += sz[b];
return a != b;
}
void cp()
{
int n;
cin >> n;
vector<pi> arr;
for(int i = 0; i < n; i++)
{
int x, y;
cin >> x >> y;
arr.pb({x, y});
}
// [n, n + 200]
for(int i = -100; i <= 100; i++)
arr.pb({i, 100});
// [n + 201, n + 401]
for(int i = -100; i <= 100; i++)
arr.pb({i, -100});
double lo = 0, hi = 200;
for(int itr = 0; itr < 50; itr++)
{
double mid = (lo + hi) / 2;
make_set(sz(arr));
for(int i = 0; i < sz(arr); i++)
for(int j = i + 1; j < sz(arr); j++)
if(dcmp(length(arr[i], arr[j]), mid) < 0)
union_set(i, j);
bool ok = true;
vector<bool> par(sz(arr));
for(int i = n; i <= n + 200; i++)
par[find_set(i)] = 1;
for(int i = n + 201; i <= n + 401; i++)
ok &= !par[find_set(i)];
if(ok)
lo = mid;
else
hi = mid;
}
dblout(20);
cout << lo / 2 << endl;
}
int main()
{
FASTIO;
int t;
t = 1;
// cin >> t;
while(t--)
{
cp();
}
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int inf = 0x3f3f3f3f;
const int N = 4e5 + 10;
const int mod = 1e9 + 7;
bool vis[N], flag;
vector<int> e[N];
int cnt1 = 0, cnt2, idx = 0;
int a[N], b[N], c[N];
int find(int x) {
return lower_bound(c + 1, c + 1 + idx, x) - c;
}
void dfs(int u) {
vis[u] = true;
cnt1++;
for(auto v : e[u]) {
cnt2++;
if(vis[v]) continue;
dfs(v);
}
}
void solve() {
int n;
scanf("%d", &n);
idx = 0;
for(int i = 1; i <= n; i++) {
scanf("%d%d", &a[i], &b[i]);
c[++idx] = a[i];
c[++idx] = b[i];
}
sort(c + 1, c + 1 + idx);
idx = unique(c + 1, c + 1 + idx) - c - 1;
for(int i = 1; i <= n; i++) {
int u = find(a[i]), v = find(b[i]);
e[u].push_back(v);
e[v].push_back(u);
}
int res = 0;
for(int i = 1; i <= idx; i++) {
cnt1 = cnt2 = 0;
if(!vis[i]) {
dfs(i);
cnt2 /= 2;
res += min(cnt1, cnt2);
}
}
printf("%d\n", res);
}
int main() {
// freopen("in.txt", "r", stdin);
// int t; cin >> t; while(t--)
solve();
return 0;
} | #include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC loop-opt(on)
#define rep(i, a, b) for(int i = a; i <= b; i++)
#define rrep(i, a, b) for(int i = b; i >= a; i--)
#define print(x) cout << #x <<" = " << x <<"\n"
#define pprint(x) cout << #x <<" = (" << x.first <<", " << x.second <<")\n"
#define all(x) x.begin(), x.end()
#define ceil(a, b) ((a + b - 1) / (b))
#define INF 1000000000000000000
#define MAXN 1000005
#define MOD 1000000007
#define eps (1e-9)
#define int long long int
#define lld long double
#define pii pair<int, int>
#define random mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count())
using namespace std;
int n, cur;
vector<int> a[2], match, vis;
bool dfs(int x) {
// print(x);
rep(i, 0, 1) {
int aa = a[i][x];
// print(aa), print(match[aa]);
if(vis[aa] == cur) continue;
vis[aa] = cur;
if(match[aa] == -1 || dfs(match[aa])) {
match[aa] = x;
return true;
}
}
return false;
}
int matching() {
int ans = 0; cur = 0;
match.assign(MAXN, -1);
vis.assign(MAXN, 0);
rep(i, 1, n) {
cur ++, ans += dfs(i);
}
return ans;
}
signed main() {
ios::sync_with_stdio(false), cin.tie(0);
cin >> n;
a[0].assign(n + 1, 0);
a[1].assign(n + 1, 0);
rep(i, 1, n) cin >> a[0][i] >> a[1][i];
// cout <<"yes\n";
cout << matching() <<"\n";
return 0;
} |
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define REP(i,a,b) for(int i=int(a);i<(int)b;++i)
#define irep(i,a,b) for(int i=int(a);i<(int)b;++i)
#define rrep(i,a,b) for(int i=int(a);i>=(int)b;--i)
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vp vector<pair<ll,ll>>
#define pb push_back
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
const ll INF = 1e18;
const double PI = acos(-1);
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;
}
const ll mod = 1e9 + 7; //998244353;
ll modpow(ll a,ll b){
if(b == 0){
return 1;
}
if(b%2 == 0){
ll tmp = modpow(a,b/2);
return tmp*tmp%mod;
}else{
return modpow(a,b-1)*a%mod;
}
}
struct UnionFind{
vector<int> d;
UnionFind(int n = 0) : d(n,-1){}
int find(int x) {
if(d[x] < 0)return x;
return d[x] = find(d[x]);
}
bool unite(int x,int y){
x = find(x);y = find(y);
if(x == y)return false;
if(d[x] > d[y])swap(x,y);
d[x] += d[y];
d[y] = x;
return true;
}
bool same(int x,int y){
return find(x) == find(y);
}
int size(int x){
return -d[find(x)];
}
int operator[](int x){return find(x);}
int operator()(int x){return size(x);}
};
double dp[105][105][105];
int main(void){
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
int a,b,c;
cin >> a >> b >> c;
dp[a][b][c] =1;
irep(i,a,101){
irep(j,b,101){
irep(k,c,101){
if(i-a > 0 && j != 100 && k != 100)dp[i][j][k] += (i-1)*dp[i-1][j][k]/(double)(i+j+k-1);
if(j-b > 0 && i != 100 && k != 100) dp[i][j][k] += (j-1)*dp[i][j-1][k]/(double)(i+j+k-1);
if(k-c > 0 && i != 100 && j != 100)dp[i][j][k] += (k-1)*dp[i][j][k-1]/(double)(i+j+k-1);
}
}
}
double ans = 0;
irep(i,a,100){
irep(j,b,100){
double cnt = i-a + j-b+100-c;
ans += cnt*dp[i][j][100];
}
}
//cerr << ans << endl;
irep(i,b,100){
irep(j,c,100){
double cnt = i-b + j-c+100-a;
//cerr << cnt << endl;
ans += cnt*dp[100][i][j];
}
}
//cerr << ans << endl;
irep(i,c,100){
irep(j,a,100){
double cnt = i-c + j-a+100-b;
ans += cnt*dp[j][100][i];
//cerr << ans << endl;
}
}
//cerr << dp[a][b][c+1] << endl;
cout << setprecision(10) << ans << endl;
return 0;
} | #include<bits/stdc++.h>
#define int ll
#define sz(x) int((x).size())
#define all(x) (x).begin(),(x).end()
#define x first
#define y second
using namespace std;
using ll = long long;
using pi = pair<int,int>;
const int inf = 0x3f3f3f3f3f3f3f3f;
const int minf = 0xc0c0c0c0c0c0c0c0;
signed main() {
ios::sync_with_stdio(0); cin.tie(0);
int a,b,c; cin>>a>>b>>c;
cout<<(a*a+b*b<c*c ? "Yes" : "No")<<'\n';
return 0;
} |
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
using namespace std;
using ll = long long int;
using pii = pair<ll, ll>;
using vi = vector<ll>;
template <typename T> void out(const T& t) {cout << t << '\n';}
vi vin(int n) {vi res(n); for(auto&i:res)cin>>i; return res;}
ll in() {ll x; cin>>x; return x;}
const ll MOD = 998244353;
const int N = 2e5 + 5;
ll two[N];
ll twoinv = 499122177;
ll mmod(ll x, ll y) {
if (x >= 0LL)
return x % y;
else
return (y - (-x) % y) % y;
}
int lp[N+1], cnt[N+1][18];
ll facts[N+1], invfacts[N+1];
vector<int> pr;
ll binpow(ll x, ll n) {
ll ans=1; ll cur=x;
for (;n;n>>=1) {
if (n&1) ans=ans*cur%MOD;
cur=cur*cur%MOD;
}
return ans;
}
ll C(ll n, ll k) {
if (n < 0 || k < 0) return 0;
if (k > n) return 0;
return facts[n] * invfacts[k] % MOD * invfacts[n - k] % MOD;
}
void solve() {
facts[0]=1;
for (int i = 1; i <= N; ++i) facts[i] = i * facts[i - 1] % MOD;
for (int i = 0; i <= N; ++i) invfacts[i] = binpow(facts[i], MOD-2);
for (int i = 0; i <= N; ++i) cnt[i][0]=1;
for (int i=2; i<=N; ++i) {
if (lp[i] == 0) {
lp[i] = i;
pr.push_back (i);
}
for (int j=0; j<(int)pr.size() && pr[j]<=lp[i] && i*pr[j]<=N; ++j) {
lp[i * pr[j]] = pr[j];
}
}
for (int i = 2; i <= N; ++i) {
cnt[i][1] = 1;
for (int j = 2; j * j <= i; ++j) {
if (i % j == 0) {
for (int k = 1; k <= 17; ++k) {
cnt[i][k] = (cnt[i][k] + cnt[i / j][k - 1]) % MOD;
if (i / j != j) cnt[i][k] = (cnt[i][k] + cnt[j][k - 1]) % MOD;
}
}
}
}
ll ans = 0;
int n = in(), m = in();
for (int i = 1; i <= m; ++i) {
ans;
for (int j = 0; j <= 17; ++j) {
ans = (ans + cnt[i][j]%MOD * C(n - 1, j)) % MOD;
}
}
out(ans);
}
int main() {
ios::sync_with_stdio(false);cin.tie(0);
int t=1;;while(t--)solve();return 0;
}
| #include<bits/stdc++.h>
using namespace std;
const long mod=998244353;
const long Beneath=300000;
vector<long> fac(Beneath+1),ifac(Beneath+1);
long mpow(long x,long n){
long ans=1;
while(n!=0){
if(n&1) ans=ans*x%mod;
x=x*x%mod;
n= n>>1;
}
return ans;
};
long comb(long a,long b){
if(a==0 && b==0) return 1;
if(a<b || a<0) return 0;
long tmp=ifac.at(a-b)*ifac.at(b)%mod;
return tmp*fac.at(a)%mod;
};
long perm(long a,long b){
if(a==0 && b==0) return 1;
if(a<b || a<0) return 0;
return fac.at(a)*ifac.at(a-b)%mod;
};
void fermat(){
fac.at(0)=1;ifac.at(0)=1;
for(long i=1;i<Beneath+1;i++){
fac.at(i)=fac.at(i-1)*i%mod;
ifac.at(i)=ifac.at(i-1)*mpow(i,mod-2)%mod;
}
};
vector<int> Eratosthenes(int N){
vector<bool> prime(N+1,true);
vector<int> P;
for(int i=2;i<=N;i++){
if(prime.at(i)){
for(int j=i*2;j<=N;j+=i) prime.at(j)=false;
P.push_back(i);//素数ならif内でPに追加され、vector:prime内の倍数はfalseとなる
}
}
return P;
}
int main(){
int N,M;cin>>N>>M;
fermat();
vector<int> E=Eratosthenes(500);
queue<int> q;
vector<long> X(M+1,1);
int k,cnt;long ret;
for(int i=2;i<=M;i++){
k=i;
for(int e:E){
if(k%e) continue;
cnt=0;
while(k%e==0){
cnt++;
k/=e;
}
q.push(cnt);
if(k==1) break;
}
if(k!=1) q.push(1);
ret=1;
while(!q.empty()){
k=q.front();q.pop();
ret*=comb(N+k-1,k);
ret%=mod;
}
X[i]=X[i-1]+ret;
X[i]%=mod;
//cout<<X[i]<<endl;
}
cout<<X[M]<<endl;
} |
#include <bits/stdc++.h>
using namespace std;
#define REP(i,x,n) for(int i=x;i<(int)n;i++)
#define rep(i,n) REP(i,0,n)
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define UNIQ(a) unique(all(a))
#define UNIQNUM(a) UNIQ(a)-a.begin()
#define UNIQIT(a) a.erase(UNIQ(a), a.end());
#define VOUT(v,i) rep(i,v.size())cout<<v[i]<<(i==v.size()-1?"\n":" ");
#define vout(v) VOUT(v,z);
#define vdbg(v,i) cout<<#v<<": ";for(int i=0;i<(int)v.size();i++){cout<<v[i]<<" ";}cout<<"\n";
#define vmin(v) *min_element(all(v))
#define vmax(v) *max_element(all(v))
#define vsum(v) accumulate(all(v), 0LL)
#define MOUT(m,r,c) rep(i,r){rep(j,c){cout<<m[i][j]<<" ";}cout<<endl;}
#define mout(m) MOUT(m,m.size(),m[0].size())
#define DBG 1
#define debg(a) if(DBG) cout<<#a<<": "<<a<<endl;
#define out(a) debg(a);
#define aout(a) for(auto&e:a)cout<<e<<" ";
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define digit(a) to_string(a).length();
// template<class T>inline int out(const T &t){ print(t); putchar('\n'); return 0; }
// template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
// template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
bool is_palindrome(string s){return s == string(s.rbegin(),s.rend());}
#define popcount __builtin_popcount
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef vector<ll> V;
typedef vector<vector<ll>> VV;
// const long long MOD=1000000007;
const long long INF = 1e18;
#define EPS (1e-7)
#define PI (acos(-1))
template<class T>
inline bool chmax(T &a, T b) {
if(a < b) { a = b; return true; }
return false;
}
template<class T>
inline bool chmin(T &a, T b) {
if(a > b) { a = b; return true; }
return false;
}
int main(){
long long X;
scanf("%lld",&X);
long long Y;
scanf("%lld",&Y);
long long A;
scanf("%lld",&A);
long long B;
scanf("%lld",&B);
// while(X<Y){
// ll kako=X*A;
// ll atco=X+B;
// if(kako>atco){
// X=atco;
// }else{
// X=kako;
// }
// if(X>=Y) break;
// cnt++;
// }
ld border = B*1.0/A;
ll kakocnt=0;
ll ex = X;
while(border>ex){
if(ex >= Y / A) break;
ex*=A;
kakocnt++;
}
// out(ex);
// out(kakocnt);
ll atccnt=0;
if((Y-ex)>0){
atccnt=(Y-ex-1)/B;
// if((Y-ex)%B==0) atccnt--;
}
cout << kakocnt + atccnt << endl;
return 0;
}
| #include<bits/stdc++.h>
#define LL long long
#define ull unsigned long long
#define F(i,j,k) for(int i=(j);i<=(k);i++)
#define DF(i,j,k) for(int i=(j);i>=(k);i--)
#define P pair
#define dui priority_queue
using namespace std;
template<typename T>inline void read(T &n){
T w=1;n=0;char ch=getchar();
while(!isdigit(ch)&&ch!=EOF){if(ch=='-')w=-1;ch=getchar();}
while(isdigit(ch)&&ch!=EOF){n=(n<<1)+(n<<3)+(ch^48);ch=getchar();}
n*=w;
}
template<typename T>inline void write(T x){
ull y=0;
T l=0;
if(x<0){x=-x;putchar('-');}
if(!x){putchar(48);return;}
while(x){y=y*10+x%10;x/=10;l++;}
while(l){putchar(y%10+48);y/=10;l--;}
}
template<typename T>inline void writeln(T x){
write(x);
puts("");
}
template<typename T>inline void writes(T x){
write(x);
putchar(' ');
}
template<typename T>inline void checkmax(T &a,T b){a=a>b?a:b;}
template<typename T>inline void checkmin(T &a,T b){a=a<b?a:b;}
int main(){
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
LL x,y,a,b,ans=0;read(x);read(y);read(a);read(b);
while(x*a<x+b&&x*a<y){
if(x*1.0>y/a*1.0)break;
ans++;
x*=a;
}
ans+=(y-x)/b-((y-x)%b==0);
writeln(ans);
return 0;
}
|
#include <iostream>
#include <vector>
#include <limits>
#include <cstring>
#include <time.h>
#include <math.h>
#include <algorithm>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vi;
typedef pair<ll, ll> pii;
typedef vector<pii > vii;
typedef vector<vector<ll> > vvi;
typedef vector<vvi > vvvi;
typedef vector<vector<pair<ll, ll> > > vvii;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,s,e) for(ll i=(s);i<(e);++i)
#define repr(i,s,e) for(ll i=(e);i>(s);--i)
#define io ios::sync_with_stdio(false)
#define prv(v) \
do \
{ \
for(auto it = (v).begin(); it != (v).end(); ++it) cerr << *it << " "; \
cerr << endl; \
} while (0);
#define prm(m) \
do \
{ \
for (auto it = (m).begin(); it != (m).end(); ++it) \
cerr << it->first << " -> " << it->second << endl; \
} while (0);
const ll MOD = 1e9+7;
const ll INF = 100;
const ll TE3 = 1005;
const ll TE5 = 300005;
const string YN[2] = {"NO", "YES"};
using namespace std;
ll n, m;
ll f(vi &dp,vi &s,ll x,ll m) {
if(binary_search(s.begin(), s.end(), x)) {
return 1;
}
if(dp[x]!=-1) {
return dp[x];
}
ll y = x;
ll ans = INF;
ll q = s.size();
for (ll i = m-1; i >= 0;--i) {
if((s[i]&y)==y) {
ans = min(ans, 1 + f(dp, s, y-s[i], i-1));
}
}
return dp[x] = ans;
}
int main()
{
io;
cin >> n >> m;
vvi a(n, vi(n, 0));
rep(i, 0, m)
{
ll x, y;
cin >> x >> y;
--x;
--y;
a[x][y] = 1;
a[y][x] = 1;
}
ll z = 1ll << n;
vi dp(z,n);
rep(i, 0, z)
{
dp[i] = __builtin_popcount(i);
ll j = i;
vi o;
ll c = 0;
while (j)
{
if(j&1) {
o.pb(c);
}
j = j >> 1;
++c;
}
bool sc = true;
for (ll t1 : o)
{
for(ll t2: o) {
if(t1==t2||a[t1][t2]) {
} else {
sc = false;
break;
}
}
if(!sc) {
break;
}
}
if(sc && o.size()) {
dp[i] = 1;
}
}
rep(i,0,z) {
for (ll t = i; t > 0;t=(t-1)&i) {
dp[i] = min(dp[i], dp[t] + dp[i ^ t]);
}
}
cout << dp[z-1] << endl;
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
int n,m,e[25][25],f[1<<19];
vector<int> v;
int main()
{
int x,y;
scanf("%d %d",&n,&m);
for(int i=1;i<=m;i++)
{
scanf("%d %d",&x,&y);
e[x][y]=e[y][x]=1;
}
memset(f,0x3f,sizeof(f));
for(int i=1;i<(1<<n);i++)
{
v.clear();
for(int j=1;j<=n;j++)if(i&(1<<(j-1)))v.push_back(j);
f[i]=1;
for(int j=0;j<v.size();j++)
{
for(int k=j+1;k<v.size();k++)if(!e[v[j]][v[k]])f[i]=f[0];
}
}
for(int i=1;i<(1<<n);i++)
{
for(int j=i;j;j=(j-1)&i)f[i]=min(f[i],f[j]+f[i^j]);
}
printf("%d\n",f[(1<<n)-1]);
return 0;
} |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a)
#define dumparr(a,n)
#endif
#define FOR(i, a, b) for(ll i = (ll)a;i < (ll)b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = (ll)b-1LL;i >= (ll)a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))
typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;
typedef long double ld;
typedef pair<ld,ld> pdd;
pll operator+(pll a,pll b){
return pll(a.first+b.first,a.second+b.second);
}
pll operator-(pll a,pll b){
return pll(a.first-b.first,a.second-b.second);
}
pll operator*(ll a,pll b){
return pll(b.first*a,b.second*a);
}
const ll INF=(1LL<<60);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
a=abs(a);
b=abs(b);
if(a==0)return b;
if(b==0)return a;
if(a < b) return gcd(b, a);
ll r;
while ((r=a%b)) {
a = b;
b = r;
}
return b;
}
#endif
template<class T>
bool chmax(T& a,const T& b){
if(a<b){
a=b;
return true;
}
return false;
}
template<class T>
bool chmin(T& a,const T& b){
if(a>b){
a=b;
return true;
}
return false;
}
template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
os << "(" << a.first << "," << a.second << ")";
return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
os << "[ ";
REP(a.size()){
os<< a[i] << " ";
}
os<< " ]";
return os;
}
inline long long LSB(long long a){
return a & -a;
}
class BIT{
std::vector<long long> bit;
int n;
public:
BIT(int n):n(n){
bit=std::vector<long long>(n,0);
}
void add(int a,long long b){
a++;
for(long long i = a; i <= n; i+=LSB(i)){
bit[i-1]+=b;
}
}
void set(int a,long long b){
ll prev = this->get(a);
a++;
for(long long i = a; i <= n; i+=LSB(i)){
bit[i-1]+=b-prev;
}
}
long long sum(int a){
if(a<0)return 0;
if(a>=n)a=n-1;
a++;
long long ret=0;
for(long long i = a; i > 0; i-=LSB(i)){
ret+=bit[i-1];
}
return ret;
}
long long sum(int a,int b){
// [a,b)
--b;
if(a==0)return sum(b);
return sum(b)-sum(a-1);
}
long long get(int a){
if(a==0)return sum(0);
return sum(a)-sum(a-1);
}
};
void solve(long long H, long long W, long long M, std::vector<long long> X, std::vector<long long> Y){
ll rt=W,lb=H;
vector<pll> XY(M);
REP(M){
XY[i]=pll(X[i],Y[i]);
}
vector<ll> mh(H,W),mw(W,H);
REP(M){
if(X[i]==0){
chmin(rt,Y[i]);
}
chmin(mh[X[i]],Y[i]);
if(Y[i]==0){
chmin(lb,X[i]);
}
chmin(mw[Y[i]],X[i]);
}
if(rt==1&&lb==1){
cout<<1<<endl;
return;
}
BIT wl(W),hl(H);
ll ans=0;
sort(XY.begin(),XY.end());
ll idx=0;
REP(lb){
while(idx<XY.size()&&XY[idx].first==i){
wl.set(XY[idx].second,1);
++idx;
}
ans+=mh[i]+max(0LL,(rt-mh[i]-wl.sum(mh[i],rt)));
}
REP(rt){
if(mw[i]>=lb){
ans+=mw[i]-lb;
}
}
cout<<ans<<endl;
}
int main(){
cout<<setprecision(1000);
long long H;
scanf("%lld",&H);
long long W;
scanf("%lld",&W);
long long M;
scanf("%lld",&M);
std::vector<long long> X(M);
std::vector<long long> Y(M);
for(int i = 0 ; i < M ; i++){
scanf("%lld",&X[i]);
scanf("%lld",&Y[i]);
--X[i];--Y[i];
}
solve(H, W, M, std::move(X), std::move(Y));
return 0;
}
| #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define SORT_REVERSE(x) SORT(x);reverse(all(x))
double calc_score(int direction, const int &ci, const int &cj, int base) {
bool isUpperSide = ci < 25;
bool isLeftSide = cj < 25;
random_device rd;
mt19937 eng(rd());
uniform_int_distribution<int> distr(2, 15);
int border = distr(eng);
if (ci < border || cj < border || ci >= 50 - border || cj >= 50 - border) {
return base;
}
switch (direction) {
case 0:
if (isUpperSide) {
return 0;
} else {
return base * base;
}
case 1:
if (!isLeftSide) {
return 0;
} else {
return base * base;
}
case 2:
if (!isUpperSide) {
return 0;
} else {
return base * base;
}
case 3:
if (isLeftSide) {
return 0;
} else {
return base * base;
}
default:
return base;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
const vector<int> di = {-1, 0, 1, 0};
const vector<int> dj = {0, 1, 0, -1};
const vector<char> direction = {'U', 'R', 'D', 'L'};
int si;
cin >> si;
int sj;
cin >> sj;
vector<vector<int>> tiles(50, vector<int>(50));
vector<vector<int>> board(50, vector<int>(50));
rep(i, 50) rep(j, 50) cin >> tiles.at(i).at(j);
rep(i, 50) rep(j, 50) cin >> board.at(i).at(j);
set<int> history = {};
history.insert(tiles[si][sj]);
string route;
ll step = 1;
int ci = si, cj = sj;
while (true) {
// label, direction, tile, nextI, nextJ
vector<tuple<double, char, int, int, int>> list;
int current_tile = tiles[ci][cj];
rep(k, 4) {
int next_i = ci + di[k];
int next_j = cj + dj[k];
if (next_i < 0 || next_i >= 50 || next_j < 0 || next_j >= 50) {
continue;
}
int next_tile = tiles[next_i][next_j];
if (current_tile != next_tile) {
if (history.find(next_tile) == history.end()) {
double score = calc_score(k, ci, cj, board[next_i][next_j]);
list.emplace_back(score, direction[k], next_tile, next_i, next_j);
}
}
}
if (list.empty()) {
break;
} else {
SORT_REVERSE(list);
int label, tile, ni, nj;
char next;
tie(label, next, tile, ni, nj) = list.front();
route += next;
history.insert(tile);
ci = ni;
cj = nj;
step++;
}
}
cout << route << endl;
}
|
#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;
} | /**
template for testing/using the algorithms
import(copy-paste the methods ;v) algorithm/s and use here
**/
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
///------------------- algorithm function/s to be placed here start -------------------///
bool isEqual(double a, double b){
double EPS = 1e-9;
return abs(a-b) <= EPS;
}
double slope(double x1, double y1, double x2, double y2){
if((x2-x1)==0) return -1;
return (y2-y1)/(x2-x1);
}
bool isOnTheSameLine(int x1, int y1, int x2, int y2, int x3, int y3){
return (x1-x2)*(y1-y3) == (y1-y2)*(x1-x3);
}
///------------------- algorithm function/s to be placed here end -------------------///
void simulate(){
// simulate input to test the algorithm being implemented
}
int getRandomNumberInRange(int lower, int upper){
// generate a random number in the range- ['lower', 'upper']
srand(time(0));
return rand()%(upper-lower+1)+lower;
}
void exec(int T){
// execute the algorithm
int n;
cin>>n;
vector<pair<int, int>> points;
while(n--){
int a,b;
cin>>a>>b;
points.push_back({a,b});
}
bool yes = false;
for(int i=0;i<points.size();i++){
for(int j=i+1;j<points.size();j++){
pair<int, int> p1=points[i],p2=points[j];
for(int k=j+1;k<points.size();k++){
pair<int, int> p3 = points[k];
if( isOnTheSameLine(p1.first, p1.second, p2.first, p2.second, p3.first, p3.second) ){
yes=true;
break;
}
}
/*
slopeCnt[ slopeP1P2 ]++;
if(slopeCnt[slopeP1P2]>=2){
yes = true;
break;
*/
}
if(yes) break;
}
if(yes) cout<<"Yes\n";
else cout<<"No\n";
}
int main()
{
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
int t=1;
//cin>>t;
for(int T=1;T<=t;T++){
exec(T);
}
return 0;
}
|
#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; }
ll inv(ll a, ll m) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll garner(vector<ll> r, vector<ll> m) {
ll N = r.size();
ll prod = 1, res = 0, rem = 0;
rep(i,N) {
ll g = gcd(prod,m[i]);
if (abs(r[i]-res)%g) { return -1; }
rem = res%g; prod /= g; m[i] /= g; res /= g; r[i] /= g;
ll t = ((r[i]-res)*inv(prod,m[i])%m[i]+m[i])%m[i];
res = (res+t*prod)*g + rem;
prod *= m[i] * g;
}
return res;
}
int main() {
ll T; cin >> T;
rep(_,T) {
ll X, Y, P, Q; cin >> X >> Y >> P >> Q;
ll m1 = 2*(X+Y), m2 = P+Q;
ll result = LLINF;
repr(i,X,X+Y) repr(j,P,P+Q) {
ll res = garner({i,j},{m1,m2});
if (res!=-1) result = min(result,res);
}
if (result==LLINF) cout << "infinity" << endl;
else cout << result << endl;
}
return 0;
} | // R SAI KRISHNA
#include <bits/stdc++.h>
#define for0(i, n) for (int i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (ll)(n); ++i)
#define forc(i, l, r) for (int i = (ll)(l); i <= (ll)(r); ++i)
#define forr0(i, n) for (int i = (ll)(n) - 1; i >= 0; --i)
#define forr1(i, n) for (int i = (ll)(n); i >= 1; --i)
#define pb push_back
#define fi first
#define debug(x) cout << #x << " -> " << x << endl;
#define endl '\n'
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin, (x).rend()
#define tr(c,i) for(__typeof__((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define sz(a) ll((a).size())
#define mod 1000000007
using namespace std;
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 debug_vec(vector<ll>&v){
cout << '[';
for(auto i:v)cout << i << ", "; cout << "]";
cout << "\n";
}
void debug_set(set<ll>&st){
cout << "{";
for(auto i:st)cout << i << ", ";
cout << "}";
cout << "\n";
}
void fast()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
bool prime[1000001];
void sieve()
{
memset(prime, true, sizeof(prime));
prime[1]=false;
for (int p=2; p*p<=1000000; p++)
{
if (prime[p] == true)
{
for (int i=p*p; i<=1000000; i += p)
prime[i] = false;
}
}
}
void print(bool f){
if(f)cout << "YES\n";
else cout << "NO\n";
}
void google(int x){
cout << "Case #" << x << ": " ;
}
void solve()
{
ll n;
cin >> n;
ll temp = 6;
set<ll>st;
st.insert(6);
st.insert(10);
st.insert(15);
while(st.size() < n && temp < 10000){
temp += 6;
if(temp <= 10000)
st.insert(temp);
}
temp = 10;
while(st.size()<n && temp<10000){
temp += 10;
if(temp <= 10000)
st.insert(temp);
}
temp = 15;
while(st.size() < n && temp<10000){
temp += 15;
if(temp <= 10000)
st.insert(temp);
}
for(auto i:st)cout << i << ' ';
cout << endl;
}
int main()
{
fast();
/*ll t;
cin >> t;
for(int tt = 1;tt <= t ;tt++)*/
solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) ((x).begin()), ((x).end())
#define READ(x) (cin >> (x))
#define WRITE_N(x) (cout << (x) << endl)
#define WRITE(x) (cout << (x))
#define WRITE_YESNO(x) (WRITE_N((x) ? "Yes" : "No"))
#define PRECISE_COUT std::cout << std::setprecision(15) << std::fixed
bool xor_logic(bool x, bool y) { return (x && y) || (!x && !y); }
int main() {
// get values from input
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
std::vector<int> p(N, 0);
for (size_t i = 0; i < N; i++) {
cin >> p[i];
}
// main procedure
set<int> rs; // remain_setN
for (size_t i = 0; i <= N + 1; i++) {
rs.insert(i);
}
std::vector<int> ans(N, 0);
for (size_t i = 0; i < N; i++) {
rs.erase(p[i]);
ans[i] = *(rs.begin());
}
// output
for (size_t i = 0; i < N; i++) {
cout << ans[i] << endl;
}
return 0;
} | #include <iostream>
#include <vector>
using namespace std;
int main() {
int n;
cin >> n;
vector<bool> a(n, false);
int r = 0;
for (int i = 0; i < n; i++) {
int p;
cin >> p;
if (p >= 0 && p < n) {
a[p] = true;
}
while (r < n && a[r]) {
r++;
}
cout << r << endl;
}
}
|
/*Author-Nilesh Chandra(isocyanide7)*/
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define dd double
#define pb push_back
#define ff first
#define ss second
#define Mp make_pair
const ll Mod=1000000007;
const ll INF=999999999999999999;
const ll NN=(ll)(1e6+5);
ll min(ll x,ll y){if(x<y) return x;return y;}
ll max(ll x,ll y){if(x>y) return x;return y;}
ll power(ll x,unsigned ll y)
{
if (y==0)
return 1;
else if (y%2==0)
return power(x,y/2)*power(x,y/2);
else
return x*power(x,y/2)*power(x,y/2);
}
ll hcf(ll a,ll b)
{
if(b==0)
return a;
return hcf(b,a%b);
}
int main()
{
fio;
/*#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
freopen("error.txt", "w", stderr);
#endif*/
ll TT=1;
//cin>>TT;
while(TT--)
{
dd a,b,c,d;
cin>>a>>b>>c>>d;
dd ans=(dd)(a*d+b*c)/(dd)(b+d);
cout<<fixed<<setprecision(10)<<ans;
}
} | #include <bits/stdc++.h>
using namespace std;
int main(){
cout << fixed << setprecision(15);
double sx, sy, gx, gy;
cin >> sx >> sy >> gx >> gy;
gy = -gy;
double a = (gy - sy) / (gx - sx);
double b = sy - a * sx;
double x = -b / a;
cout << x << endl;
} |
#include <bits/stdc++.h>
#define rep(i, x, y) for (int i = x; i <= y; i++)
#define per(i, x, y) for (int i = x; i >= y; i--)
#define vi vector<int>
#define pb push_back
#define mkp make_pair
#define fi first
#define se second
#define gc getchar
#define db double
#define int long long
#define bs bitset
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define clr(x) memset(x, 0, sizeof(x))
#define lbit(x) ((x) & (-(x)))
#define Go(i, x, v) for (int i = 0, x = (i == v.size() ? 0 : v[i]); i < v.size(); i++, x = (i == v.size() ? 0 : v[i]))
using namespace std;
template <class T> void rd(T &x) {
x = 0; char ch = gc(); int f = 1;
for (; !isdigit(ch); ch = gc()) if (ch == '-') f = -1;
for (; isdigit(ch); ch = gc()) x = (x << 1) + (x << 3) + ch - '0';
x *= f;
}
template <class T> void cmin(T &x, T y) { x = min(x, y); }
template <class T> void cmax(T &x, T y) { x = max(x, y); }
const int mod = 1e9 + 7;
int add(int x, int y) { return x + y >= mod ? x + y - mod : x + y; }
int sub(int x, int y) { return x - y < 0 ? x - y + mod : x - y; }
int mul(int x, int y) { return 1ll * x * y % mod; }
void Add(int &x, int y) { x = (x + y >= mod ? x + y - mod : x + y); }
void Sub(int &x, int y) { x = (x - y < 0 ? x - y + mod : x - y); }
void Mul(int &x, int y) { x = 1ll * x * y % mod; }
int qpow(int a, int b) { int ret = 1; for (; b; b >>= 1, Mul(a, a)) if (b & 1) Mul(ret, a); return ret; }
/* ============ Header Template ============ */
const int N = 1e5 + 10;
int k, n, m, a[N], _l[N], _r[N], b[N];
bool chk(ll lim) {
ll L = 0, R = 0;
rep(i, 1, k) {
ll l = max(0.0, ceil(1.0 * (m * a[i] - lim) / n)), r = (m * a[i] + lim) / n;
if (l > r) return 0;
L += l, R += r;
_l[i] = l, _r[i] = r;
}
if (m < L || m > R) return 0;
return 1;
}
signed main() {
rd(k), rd(n), rd(m);
rep(i, 1, k) {
rd(a[i]);
}
ll l = 0, r = n * m, ans = r;
while (l <= r) {
ll mid = (l + r) >> 1;
if (chk(mid)) ans = mid, r = mid - 1;
else l = mid + 1;
}
chk(ans);
rep(i, 1, k) {
m -= _l[i];
b[i] = _l[i];
}
rep(i, 1, k) {
ll t = min(_r[i] - b[i], m);
b[i] += t, m -= t;
if (!m) break;
}
rep(i, 1, k) {
printf("%lld ", b[i]);
} puts("");
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define pii pair<ll,ll>
bool mycomp(pii a,pii b)
{
if(a.first==b.first) return a.second>b.second;
return a.first<b.first;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll k,n,m,sum=0;
cin>>k>>n>>m;
ll a[k],b[k];
vector<pii> sub,add;
for(int i=0;i<k;i++)
{
cin>>a[i];
a[i]*=m;
b[i]=a[i];
ll p=a[i]%n;
ll q=n-p;
sub.pb({p,i});
add.pb({q,i});
}
sort(sub.begin(),sub.end(),greater<pii>());
sort(add.begin(),add.end(),mycomp);
int i=0,j=k-1;
while(i<j){
if(add[i].first>sub[j].first){
b[sub[j].second]-=sub[j].first;
b[add[i].second]+=sub[j].first;
add[i].first-=sub[j].first;
j--;
}
else{
b[add[i].second]+=add[i].first;
b[sub[j].second]-=add[i].first;
sub[j].first-=add[i].first;
i++;
}
}
for(int i=0;i<k;i++)
cout<<(b[i]/n)<<" ";
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;
#define rep(i,n) for(int i=0;i<int(n);i++)
#define INF 1e18
#define MOD 1000000007
#define MAXR 100005
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int dx[8]={1,0,-1,0,1,1,-1,-1};
const int dy[8]={0,1,0,-1,1,-1,-1,1};
struct Edge{
int to;
int time;
int k;
};
vector<Edge>G[100005];
void dijkstra(int x,vector<ll>&dist){
dist[x]=0;
priority_queue<P,vector<P>,greater<P> >Q;
Q.push(make_pair(0,x));
while(!Q.empty()){
auto p=Q.top();
Q.pop();
int from =p.second;
if(dist[from]<p.first) continue;
for(int i=0;i<G[from].size();i++){
Edge e =G[from][i];
ll next = 0;
if (p.first % e.k == 0){
next = p.first + e.time;
}
else{
next = p.first + e.time + e.k - p.first%e.k;
}
if(dist[e.to]>next){
dist[e.to]=next;
Q.push(make_pair(dist[e.to],e.to));
}
}
}
}
int main(){
int n,m,x,y;
cin >>n>>m>>x>>y;
x--;y--;
rep(i,m){
int a,b,t,k;
cin >>a>>b>>t>>k;
a--;b--;
G[a].push_back((Edge){b,t,k});
G[b].push_back((Edge){a,t,k});
}
vector<ll>dist(n,INF);
dijkstra(x,dist);
if(dist[y]==INF) cout <<-1<<endl;
else cout <<dist[y]<<endl;
return 0;
} | #include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
// using namespace __gnu_pbds;
#define lli long long int
#define llu unsigned long long int
#define pb push_back
#define rt return 0
#define endln "\n"
#define all(x) x.begin(), x.end()
#define sz(x) (lli)(x.size())
#define len(x) (lli)(x.length())
const lli MOD = 1e9 + 7;
const double PI = 2 * acos(0.0);
// cout << fixed << setprecision(0) << pi <<endl;
// typedef tree<int, null_type, less<int>, rb_tree_tag,
// tree_order_statistics_node_update>
// new_data_set;
// for multiset
// typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
// tree_order_statistics_node_update>
// new_data_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)
struct edg {
lli des, t, k;
};
void solve() {
lli n, m, a, b, t, k, x, y;
cin >> n >> m >> x >> y;
vector<vector<struct edg>> adj(n + 2);
for (lli i = 0; i < m; i++) {
cin >> a >> b >> t >> k;
struct edg edg1, edg2;
edg1.des = b, edg1.t = t, edg1.k = k;
edg2.des = a, edg2.t = t, edg2.k = k;
adj[a].pb(edg1);
adj[b].pb(edg2);
}
lli inf = -1;
vector<lli> dis(n + 2, inf);
set<pair<lli, lli>> st;
dis[x] = 0;
st.insert({dis[x], x});
while (!st.empty()) {
auto it = st.begin();
lli d = it->first;
lli a = it->second;
// cout << d << " " << a << endl;
st.erase(it);
for (lli i = 0; i < adj[a].size(); i++) {
lli des = adj[a][i].des;
lli cost = adj[a][i].t;
lli wait_time = 0;
if (d % adj[a][i].k != 0) {
lli p = d / adj[a][i].k;
p++;
// if (des == 3) {
// cout << p << endl;
// }
wait_time = p * adj[a][i].k - d;
}
lli final_cost = d + cost + wait_time;
if (dis[des] == inf) {
dis[des] = final_cost;
st.insert({dis[des], des});
} else if (dis[des] > final_cost) {
dis[des] = final_cost;
st.insert({dis[des], des});
}
}
}
lli ans = dis[y];
cout << ans << endl;
}
int main(void) {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// lli t; cin >> t; while(t--)
solve();
rt;
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)
template<class T1, class T2> inline bool chmax(T1 &a, const T2 &b) {if (a<b) { a=b; return 1;} return 0;}
template<class T1, class T2> inline bool chmin(T1 &a, const T2 &b) {if (b<a) { a=b; return 1;} return 0;}
struct init{init(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);cerr<<fixed<<setprecision(15);}}init_;
#ifdef DEBUG
template <class T> void verr(const set<T> &st) { repa(a, st) cerr << a << " "; cerr << endl; }
template <class S, class T> void verr(const map<S, T> &mp) { repa(a, mp) cerr << "{" << a.first << ", " << a.second << "} "; cerr << endl; }
template <class S, class T, class N> void verr(const vector<pair<S,T>>& a, const N& n) { rep(i, n) cerr << "{" << a[i].first << ", " << a[i].second << "} "; cerr << endl; }
template <class T, class N> void verr(const vector<T>& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << endl; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << endl; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif
const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
int main() {
ll N, M;
cin >> N >> M;
vvc<ll> adj(N, vl(N));
vc<vvc<ll>> G(N, vvc<ll>(26));
rep(i, M){
ll a, b;
char c;
cin >> a >> b >> c, a--, b--;
ll ci = c - 'a';
G[a][ci].eb(b);
G[b][ci].eb(a);
adj[a][b] = adj[b][a] = true;
}
map<pair<ll, ll>, ll> mp;
mp[{0, N - 1}] = 0;
queue<pair<ll, ll>> q;
q.emplace(0, N - 1);
ll ans = INF;
while(!q.empty()){
auto [s, t] = q.front();
ll cost = mp[{s, t}];
q.pop();
if(adj[s][t]){
cout << cost + 1 << endl;
return 0;
}
rep(c, 26){
repa(tos, G[s][c]){
repa(tot, G[t][c]){
if (mp.count({tos, tot})) continue;
mp[{tos, tot}] = cost + 2;
if(tos == tot){
cout << mp[{tos, tot}] << endl;
return 0;
}else{
q.emplace(tos, tot);
}
}
}
}
}
cout << -1 << endl;
} | #include <bits/stdc++.h>
using namespace std;
int a[200100], pos[200100];
int main(){
int i, j, N, ans1 = 0, ans2 = 0; cin>>N;
for(i=1; i<=N; i++) {
scanf("%d", &a[i]); pos[a[i]] = i;
if(a[i] > i) ans2 += a[i] - i;
if(a[i] == i) { cout<<-1; return 0; }
if(a[i] < i) ans1 += i - a[i];
}
if(ans1 != N-1 || ans2 != N-1) { cout<<-1; return 0; }
for(i=1; i<=N; i++) {
if(pos[i] != i) {
for(j=pos[i]-1; j>=i; j--){
swap(a[j], a[j+1]);
pos[a[j]] = j; pos[a[j+1]] = j+1;
printf("%d\n", j);
}
}
}
}
|
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
string c = "White";
if(n%2==0){
c = "White";
}
else{
c = "Black";
}
cout << c <<endl;
} | #include <iostream>
#include <memory.h>
#include <cmath>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
char a, b, c;
cin >> a >> b >> c;
cout << ((a==b && b==c) ? "Won" : "Lost") << "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void fast(){
cin.tie();
cin.sync_with_stdio();
}
int main()
{
fast();
int n;
cin>>n;
if(n==1)
cout<<"0";
else if(n==2)
cout<<"1";
else if(n>2)
cout<<n-1;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define rep(i,j,n) for(int64_t i=j;i<n;i++)
#define all(v) (v).begin(), (v).end()
#define sz(v) ((int)v.size())
#define br '\n'
void resp(int tc) {
int x; cin >> x;
cout << max(0, x) << br;
}
int main() {
int tc=1;
// cin >> tc;
while(tc--) resp(tc);
return 0;
} |
// Problem: D - Shipping Center
// Contest: AtCoder - Panasonic Programming Contest (AtCoder Beginner Contest 195)
// URL: https://atcoder.jp/contests/abc195/tasks/abc195_d
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Parsed on: 13-03-2021 18:36:40 IST (UTC+05:30)
// Author: Kapil Choudhary
// ********************************************************************
// कर्मण्येवाधिकारस्ते मा फलेषु कदाचन |
// मा कर्मफलहेतुर्भूर्मा ते सङ्गोऽस्त्वकर्मणि || १.४७ ||
// ********************************************************************
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define PI 3.1415926535897932384626
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << ", " << #y << "=" << y << endl
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vull> vvull;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
uniform_int_distribution<int> uid(0,lim-1);
return uid(rang);
}
const int INF = 0x3f3f3f3f;
const int mod = 1e9+7;
void solve()
{
int n, m, q;
cin >> n >> m >> q;
vpii v(n);
for(int i = 0; i < n; i++) {
cin >> v[i].F >> v[i].S;
}
vi t(m);
for(int i = 0; i < m; i++) cin >> t[i];
//cout << n << " " << m << " " << q << endl;
//for(auto x: v) cout << x.F << " " << x.S << endl;
//for(auto x: t) cout << x << " "; cout << endl;
while(q--) {
int L, R; cin >> L >> R;
L -= 1, R -= 1;
//deb2(L, R);
vi boxes;
for(int i = 0; i < L; i++) boxes.pb(t[i]);
for(int i = R + 1; i < m; i++) boxes.pb(t[i]);
//for(auto x: boxes) cout << x << " "; cout << endl;
sort(boxes.begin(), boxes.end());
vector<bool> taken(n, 0);
ll mx = 0LL;
for(int i = 0; i < (int)boxes.size(); i++) {
int idx = -1;
ll tmp = LLONG_MIN;
for(int j = 0; j < n; j++) {
if(!taken[j] and v[j].F <= boxes[i]) {
if(tmp < v[j].S) {
tmp = v[j].S;
idx = j;
}
}
}
if(tmp != LLONG_MIN) {
mx += tmp;
taken[idx] = 1;
}
}
cout << mx << "\n";
}
}
int main()
{
ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
srand(chrono::high_resolution_clock::now().time_since_epoch().count());
// #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 <bits/stdc++.h>
using namespace std;
#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 PB push_back
#define ar2 array<int, 2>
typedef long long LL;
const LL P = 1e9 + 7;
const LL INF = 1e9;
const int N = 2e5 + 5;
mt19937 rng(time(0));
int T, n, m;
char s1[N], s2[N], s3[N], res[N];
int main() {
ios::sync_with_stdio(false), cin.tie(0);
cin >> T;
rep(cas, 1, T) {
cin >> n;
cin >> (s1 + 1) >> (s2 + 1) >> (s3 + 1);
int j = 0;
rep(i, 1, (n + 1) / 2) res[++j] = '0';
rep(i, 1, n) res[++j] = '1';
rep(i, 1, n / 2 + 1) res[++j] = '0';
res[++j] = 0;
cout << (res + 1) << endl;
}
return 0;
}
|
//Radhe Radhe
#include<bits/stdc++.h>
#define FASTIO_ ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define mod 1000000007
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define itr(i,n) for(ll i=0; i<n; i++)
#define itr_ab(i,a,b) for(ll i=a; i<=b; i++)
#define itrV(i,n) for(ll i=0; i<v.size(); i++)
#define fixed cout.setf(ios::fixed);
#define precise cout.precision(15);
#define yes cout<<"Yes"<<'\n'
#define no cout<<"No"<<'\n'
#define en '\n'
#define Dont_Quit int main(void)
#define Avada_Kedavra return 0;
using namespace std;
bool cmp(const pair<string,ll>&a,const pair<string,ll>&b)
{
if(a.se>b.se)
return 1;
else
return 0;
}
Dont_Quit
{
FASTIO_
ll tc,n,m,x,i,j,d;
string s;
tc=1;
while(tc--)
{
cin>>n;
vector<pair<string,ll>>v;
itr(i,n)
{
cin>>s>>x;
v.pb(mp(s,x));
}
sort(v.begin(),v.end(),cmp);
cout<<v[1].fi<<en;
}
Avada_Kedavra
}
| #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)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
//最大公約数
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;
}
template <typename X, typename M>
struct SegTreeLazy {
using FX = function<X(X, X)>;
using FA = function<X(X, M)>;
using FM = function<M(M, M)>;
int n;
FX fx;
FA fa;
FM fm;
const X ex;
const M em;
vector<X> dat;
vector<M> lazy;
SegTreeLazy(int n_, FX fx_, FA fa_, FM fm_, X ex_, M em_)
: n(), fx(fx_), fa(fa_), fm(fm_), ex(ex_), em(em_), dat(n_ * 4, ex), lazy(n_ * 4, em) {
int x = 1;
while (n_ > x) x *= 2;
n = x;
}
void set(int i, X x) { dat[i + n - 1] = x; }
void build() {
for (int k = n - 2; k >= 0; k--) dat[k] = fx(dat[2 * k + 1], dat[2 * k + 2]);
}
/* lazy eval */
void eval(int k) {
if (lazy[k] == em) return; // 更新するものが無ければ終了
if (k < n - 1) { // 葉でなければ子に伝搬
lazy[k * 2 + 1] = fm(lazy[k * 2 + 1], lazy[k]);
lazy[k * 2 + 2] = fm(lazy[k * 2 + 2], lazy[k]);
}
// 自身を更新
dat[k] = fa(dat[k], lazy[k]);
lazy[k] = em;
}
void update(int a, int b, M x, int k, int l, int r) {
eval(k);
if (a <= l && r <= b) { // 完全に内側の時
lazy[k] = fm(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); // 右の子
dat[k] = fx(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
void update(int a, int b, M x) { update(a, b, x, 0, 0, n); }
X query_sub(int a, int b, int k, int l, int r) {
eval(k);
if (r <= a || b <= l) { // 完全に外側の時
return ex;
} else if (a <= l && r <= b) { // 完全に内側の時
return dat[k];
} else { // 一部区間が被る時
X vl = query_sub(a, b, k * 2 + 1, l, (l + r) / 2);
X vr = query_sub(a, b, k * 2 + 2, (l + r) / 2, r);
return fx(vl, vr);
}
}
X query(int a, int b) { return query_sub(a, b, 0, 0, n); }
};
bool isLarger(string s,string t){
/*SのほうがTより大きければtrue*/
rep(i,min(s.length(),t.length())){
if(s[i]>t[i]){
return true;
}
if(s[i]<t[i]){
return false;
}
}
if(s.length()>t.length()){
return true;
}
else{
return false;
}
}
int main(void) {
ll n;
cin>>n;
vector<vector<ll>>v(n,vector<ll>(2));
rep(i,n){
cin>>v[i][0]>>v[i][1];
}
rep(i,n){
rep(j,n){
rep(k,n){
if(i==j||k==i||j==k){
continue;
}
ll x1=v[i][0]-v[j][0];
ll y1=v[i][1]-v[j][1];
ll x2=v[i][0]-v[k][0];
ll y2=v[i][1]-v[k][1];
if(x1*y2==x2*y1){
cout<<"Yes";
return 0;
}
}
}
}
cout<<"No";
}
/*
*/
|