code_file1
stringlengths 87
4k
| code_file2
stringlengths 85
4k
|
---|---|
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}
ll gcd(ll a,ll b){
return b==0?a:gcd(b,a%b);
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
ll A,B;
cin>>A>>B;
vector<ll> v;
for(ll i=A;i<=B;i++) v.push_back(i);
int V=v.size();
vector<vector<int>> g(V);
rep(i,V){
for(int j=i+1;j<V;j++){
if(gcd(v[i],v[j])!=1){
g[i].push_back(j);
g[j].push_back(i);
}
}
}
ll ast=0,bst=0;
rep(k,V){
if(k<60) ast+=(1ll<<k);
else bst+=(1ll<<(k-60));
}
map<tuple<int,ll,ll>,ll> dp;
auto solve = [&](auto &&solve,int now,ll ast,ll bst)->ll{
if(dp.count(mkt(now,ast,bst))) return dp[mkt(now,ast,bst)];
if(now==V) return 1;
ll res=0;
{
ll nexast=ast,nexbst=bst;
if(now<60&&((1ll<<now)&ast)) nexast^=(1ll<<now);
if(now>=60&&((1ll<<(now-60))&bst)) nexbst^=(1ll<<(now-60));
res+=solve(solve,now+1,nexast,nexbst);
}
//res+=solve(solve,now+1,ast,bst);
if(now<60&&((1ll<<now)&ast)){
ll nexast=ast,nexbst=bst;
nexast^=(1ll<<now);
for(auto j:g[now]){
if(j<60&&(ast&(1ll<<j))) nexast^=(1ll<<j);
if(j>=60&&(bst&(1ll<<(j-60)))) nexbst^=(1ll<<(j-60));
}
res+=solve(solve,now+1,nexast,nexbst);
}
if(now>=60&&((1ll<<(now-60))&bst)){
ll nexast=ast,nexbst=bst;
nexbst^=(1ll<<(now-60));
for(auto j:g[now]){
if(j<60&&(ast&(1ll<<j))) nexast^=(1ll<<j);
if(j>=60&&(bst&(1ll<<(j-60)))) nexbst^=(1ll<<(j-60));
}
res+=solve(solve,now+1,nexast,nexbst);
}
return dp[mkt(now,ast,bst)]=res;
};
ll ans=solve(solve,0,ast,bst);
cout<<ans<<endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll p[20] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71};
vector< ll > nums;
ll dp[(1 << 20) + 10][73];
bool can(int i, int msk, int &sub){
auto num = nums[i];
for(int i = 0 ; i < 20 ; i++){
if(num % p[i] == 0){
int e = 1 << i;
if(msk & e){
return false;
}else{
sub |= e;
}
}
}
return true;
}
ll solve(int i, int msk) {
auto &ans = dp[msk][i];
if(ans != -1){
return ans;
}
// printf("aqui! %d %lu\n", i, nums.size());
if(i == nums.size()){
return ans = 1LL;
}
int sub = 0;
ans = 0;
if(can(i, msk, sub)){
ans += solve(i + 1, msk | sub);
}
ans += solve(i + 1, msk);
// printf("%d %lld\n", i, ans);
return ans;
}
int main(){
memset(dp, -1, sizeof dp);
ll a, b;
scanf("%lld %lld", &a, &b);
while(a <= b){
nums.push_back(a);
a++;
}
printf("%lld\n", solve(0, 0));
return 0;
} |
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define db double
#define pint pair<int,int>
#define mk make_pair
#define pb push_back
#define eb emplace_back
#define ins insert
#define fi first
#define se second
#define Rep(x,y,z) for(int x=y;x<=z;x++)
#define Red(x,y,z) for(int x=y;x>=z;x--)
using namespace std;
const int MAXN=5e5+5;
char buf[1<<12],*pp1=buf,*pp2=buf,nc;int ny;
//inline char gc() {return pp1==pp2&&(pp2=(pp1=buf)+fread(buf,1,1<<12,stdin),pp1==pp2)?EOF:*pp1++;}
inline char gc(){return getchar();}
inline int read(){
int x=0;ny=1;while(nc=gc(),(nc<48||nc>57)&&nc!=EOF)if(nc==45)ny=-1;if(nc<0)return nc;
x=nc-48;while(nc=gc(),47<nc&&nc<58&&nc!=EOF)x=(x<<3)+(x<<1)+(nc^48);return x*ny;
}
ll ans=0;
int n,pos1[MAXN],pos2[MAXN],cnt1,cnt2;char s[MAXN],t[MAXN];
int main(){
// freopen("std.in","r",stdin);
// freopen("std.out","w",stdout);
n=read(),scanf("%s%s",s+1,t+1);
Rep(i,1,n)if(s[i]=='1')pos1[++cnt1]=i;
Rep(i,1,n)if(t[i]=='1')pos2[++cnt2]=i;
int j=1;
Rep(i,1,cnt2){
while(pos1[j]<pos2[i]&&j<=cnt1)ans+=pos1[j+1]-pos1[j],j+=2;
if(j>cnt1)return puts("-1"),0;ans+=pos1[j]-pos2[i],j++;
}if((cnt1-j+1)%2)return puts("-1"),0;
for(;j<=cnt1;ans+=pos1[j+1]-pos1[j],j+=2);
cout<<ans<<"\n";
return 0;
}
| #include <cstdio>
#include <cmath>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <cassert>
#include <string>
#include <cstring>
#include <queue>
using namespace std;
#define rep(i,a,b) for(int i = a; i < b; i++)
#define S(x) scanf("%d",&x)
#define S2(x,y) scanf("%d%d",&x,&y)
#define P(x) printf("%d\n",x)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second
#define pb push_back
#define mp make_pair
typedef long long int LL;
typedef pair<int, int > pii;
typedef vector<int > vi;
const int N = 20;
int G[N][N];
int n;
int col[N];
int bit(int mask, int x) {
return (mask >> x) & 1;
}
bool singlecol(int mask) {
rep(i,0,n) if(bit(mask, i)) {
rep(j,i+1,n) if(bit(mask, j)) {
if(G[i][j]) return false;
}
}
return true;
}
bool dfs(int c, int mask, int cc) {
if(col[c] != -1) {
return col[c] == cc;
}
col[c] = cc;
bool res = true;
rep(i,0,n) if(bit(mask, i) && G[c][i]) {
res &= dfs(i, mask, cc ^ 1);
}
return res;
}
LL twocol(int mask) {
memset(col, -1, sizeof(col));
LL res = 1;
rep(i,0,n) if(bit(mask, i) && col[i] == -1) {
if(!dfs(i, mask, 0)) {
res = 0;
} else {
res *= 2;
}
}
return res;
}
int main() {
int m;
S2(n,m);
rep(i,0,m) {
int x,y;
S2(x,y);
x--; y--;
G[x][y] = G[y][x] = 1;
}
int mx = (1 << n) - 1;
LL ans = 0;
rep(i,0,1<<n) {
if(!(i & 1)) continue;
if(singlecol(i)) {
ans += twocol((~i) & mx);
// printf("%d %lld\n",i,ans);
}
}
ans *= 3;
cout << ans << "\n";
return 0;
}
|
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
typedef long int li;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define test ll t; cin >> t; while(t--)
#define print_tc(t, c) cout << "Case #" << t << ": " << c << "\n";
const long long int dx[4] = {0, 0, -1, 1}, dy[4] = {1, -1, 0, 0};
const long long int cons = 100005, ncr_cons = 2000005;
const long long int MOD = 1000000007; // const long long int MOD = 998244353;
const long long int const_INT_MAX = 1000000000000000000, const_INT_MIN = -1 * 1000000000000000000;
using namespace std;
bool sortinrev(const pair<ll,ll> &a, const pair<ll,ll> &b){return (a.first > b.first);}
bool sortbysec(const pair<ll,ll> &a, const pair<ll,ll> &b){return (a.second < b.second);}
bool sortbysecinrev(const pair<ll,ll> &a, const pair<ll,ll> &b){return (a.second > b.second);}
ll gcd(ll x, ll y){return (ll)(__gcd(x, y));}
ll lcm(ll x, ll y){return (ll)((x * y) / gcd(x, y));}
ll mod_expo(ll x, ll y, ll p){
if((x + p) % p == 0) return 0;
ll res = 1; x = (x + p) % p;
while (y > 0){
if(y & 1) res = (res*x + p) % p;
y = y>>1; x = (x*x + p) % p;
}
return res;
}
void usaco(string str = ""){
fastio;
if(str.size()){
freopen((str + ".in").c_str(), "r", stdin);
freopen((str + ".out").c_str(), "w", stdout);
}
}
ll invnum[ncr_cons], invfac[ncr_cons], fac[ncr_cons];
void pre_ncr(){ // add pre_ncr() in main
invnum[0] = invnum[1] = invfac[0] = invfac[1] = fac[0] = 1;
for(ll i=2;i<ncr_cons;i++){
invnum[i] = ((invnum[MOD % i] * (MOD - (MOD / i)) + MOD) % MOD);
}
for(ll i=2;i<ncr_cons;i++){
invfac[i] = ((invnum[i] * invfac[i-1] + MOD) % MOD);
}
for(ll i=1;i<ncr_cons;i++){
fac[i] = ((fac[i-1] * i + MOD) % MOD);
}
}
ll ncr(ll n, ll r){
ll ans = ((fac[n] * invfac[r] + MOD) % MOD) * ((invfac[n-r] + MOD) % MOD);
ans += MOD; ans %= MOD; return ans;
}
int main(){
usaco();
pre_ncr();
ll n, m, k; cin >> n >> m >> k;
if(n > m + k){
cout << 0 << "\n"; return 0;
}
ll ans = ncr(n + m, m);
if(m + k + 1 <= n + m) ans -= ncr(n + m, m + k + 1);
if(ans < 0) ans += MOD; ans %= MOD; cout << ans << "\n";
cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
}
| #include<bits/stdc++.h>
using namespace std;
#define ll long long
const int mod=1e9+7,N=3e6+5;
vector<ll> fact(N);
inline ll exp(ll x, ll n, ll m = mod) {
ll r = 1;
while(n) {
if(n & 1) r = r * x % m;
x = x * x % m, n >>= 1;
}
return r;
}
ll ncr(int n,int r){
if(n<r || r<0 || n<0)
return 0;
else if(r==0 || (n==r))
return 1;
return (((fact[n]*exp(fact[r],mod-2))%mod)*exp(fact[n-r],mod-2))%mod;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n,m,k;
cin>>n>>m>>k;
if(n>(m+k)){
cout<<0<<endl;
return 0;
}
fact[0]=fact[1]=1;
for(ll i=2;i<N;i++){
fact[i]=(fact[i-1]*i)%mod;
}
cout<<(ncr(n+m,n)+mod-ncr(n+m,n-k-1))%mod;
return 0;
} |
# include <algorithm>
# include <cstdio>
# include <cstring>
# include <vector>
using namespace std;
using LL = long long;
const int kMaxN = 2e5 + 21;
LL res = 0;
int n, m, k, flag;
vector<int> v[kMaxN];
int column[kMaxN], row[kMaxN], tr[kMaxN];
int LowBit(int x) { return x & -x; }
void Add(int x, int v) {
for (int i = x; i <= n; i += LowBit(i)) tr[i] += v;
}
int Query(int x) {
int res = 0;
for (int i = x; i; i -= LowBit(i)) {
res += tr[i];
}
return res;
}
int main() {
scanf("%d %d %d", &n, &m, &k);
for (int i = 1; i <= n; i++) {
row[i] = m + 1;
}
for (int i = 1; i <= m; i++) {
column[i] = n + 1;
}
for (int i = 1, a, b; i <= k; i++) {
scanf("%d %d", &a, &b);
column[b] = min(column[b], a);
row[a] = min(row[a], b);
}
for (int i = 1; i <= n; i++) {
if (flag == 1) {
row[i] = 1;
continue;
}
if (row[i] == 1) {
flag = 1;
continue;
}
res += row[i] - 1;
}
for (int i = 1; i <= n; i++) {
v[row[i]].push_back(i);
}
for (int i = 1; i <= m && column[i] != 1; i++) {
res += Query(column[i] - 1);
for (auto j : v[i]) {
Add(j, 1);
}
}
printf("%lld\n", res);
return 0;
}
| #include <cmath>
#include <cstdio>
#include <set>
#include <vector>
using namespace std;
int N, M;
vector<long> a;
vector<vector<int>> graph;
vector<bool> pass;
vector<int> record;
vector<bool> computedMax;
long min_ele = -999999999;
long res = min_ele;
long dfs(int x);
void init();
int main() {
#ifdef LOCAL
freopen("../data.in", "r", stdin);
// freopen("../data.out", "w", stdout);
#endif
init();
for (int i = 0; i < M; i++) {
int x, y;
scanf("%d %d", &x, &y);
graph[x].push_back(y);
}
// for (int i = 1; i <= N; i++) {
// printf("-------------- %d\n", i);
// for (int j = 0; j < graph[i].size(); j++) {
// printf("%d ", graph[i][j]);
// }
// printf("\n");
// }
for (int i = 1; i <= N; i++) {
dfs(i);
}
printf("%ld\n", res);
return 0;
}
long dfs(int x) {
pass[x] = true;
if (graph[x].size() == 0) return record[x];
long max_record = min_ele;
for (int y : graph[x]) {
if (!pass[y]) {
long t = dfs(y);
if (t-a[x] > res) res = t-a[x];
if (t > max_record) max_record = t;
} else {
if (record[y] > max_record) {
max_record = record[y];
}
if (record[y] - a[x] > res) res = record[y] - a[x];
}
}
if (record[x] > max_record) {
max_record = record[x];
}
record[x] = max_record;
return max_record;
}
void init() {
scanf("%d %d", &N, &M);
a.resize(N + 1);
pass.resize(N + 1, false);
computedMax.resize(N+1, false);
graph.resize(N + 1);
record.resize(N + 1);
for (int i = 1; i <= N; i++) {
scanf("%ld", &a[i]);
record[i] = a[i];
}
} |
#include<bits/stdc++.h>
using namespace std;
#define _ 0
const int maxn=1e6+5;
const int inf=0x3f3f3f3f;
const int mod=998244353;
int f[maxn],vis[maxn];
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
int n,ans=1;
cin>>n;
for(int i=1;i<=n;i++)
cin>>f[i];
for(int i=1;i<=n;i++)
{
int u=i;
while(!vis[u])
{
vis[u]=i;
u=f[u];
}
if(vis[u]==i)
ans=(ans<<1)%mod;
}
cout<<ans-1<<endl;
return ~~(0^_^0);
}
| #include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
#define int long long
const int MOD=1e9+7;
template<typename T>
void fin(T a){
cout<<a<<endl;
exit(0);
}
int pw(int n,int k){
assert(k>=0);
int res=1;
while(k){
if(k&1)(res*=n)%=MOD;
(n*=n)%=MOD;
k>>=1;
}
return res;
}
std::vector<int> Factorial(5e6),Finverse(5e6);
inline void Cinit(){
Factorial[0]=1;
for(int i=1;i<5e6;i++)Factorial[i]=(Factorial[i-1]*i)%MOD;
Finverse[4999999]=pw(Factorial[4999999],MOD-2);
for(int i=4999998;i>=0;i--)Finverse[i]=(i+1)*Finverse[i+1]%MOD;
}
int nCk(int n,int k){
if(n<k)return 0;if(k<0)return 0;
if(!Factorial[0])Cinit();
int res=Factorial[n];
(res*=Finverse[k])%=MOD;
(res*=Finverse[n-k])%=MOD;
return res;
}
char A='A',B='B';
signed main(){
int n;cin>>n;
if(n<=3)fin(1);
vector<char> c(4);//AA,AB,BA,BB
REP(i,4)cin>>c[i];
if(c[1]==A)swap(c[0],c[3]),swap(A,B);
if(c[3]==B)fin(1);
if(c[2]==B){
int ans=0;
for(int k=1;n-k-1>=k-1;k++)ans+=nCk(n-k-1,k-1);
fin(ans%MOD);
}
fin(pw(2,n-3));
}
|
#include<bits/stdc++.h>
using namespace std;
int main()
{
int A, B, C;
cin >> A >> B >> C;
if( A == B )
{
if( C == 0 )
cout << "Aoki" << endl;
else
cout << "Takahashi" << endl;
}
else if( A > B )
cout << "Takahashi" << endl;
else
cout << "Aoki" << endl;
return 0;
} | #include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define IT iterator
#define PB push_back
#define fi first
#define se second
#define all(a) a.begin(),a.end()
#define mid ((r+l)>>1)
#define lson p<<1,l,mid
#define rson p<<1|1,mid+1,r
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
#define debug cout << "dsdsdsdsd" << "\n";
#define y1 yzang
using namespace std;
const int maxn = 2e5 + 10;
int n,m;
int main() {
int c;
cin >> n >> m >> c;
if(c == 0) {
if(n >= m + 1) {
cout << "Takahashi" << "\n";
}
else {
cout << "Aoki" << "\n";
}
}
else {
if(n + 1 <= m) {
cout << "Aoki" << "\n";
}
else {
cout << "Takahashi" << "\n";
}
}
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define endl "\n"
#define print(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
const ll mod = 1e9 + 7;
// const ll mod = 998244353;
const ll sz = 2e5 + 1;
vector<ll> fac(sz, 1), ifac(sz);
vector<int> prime(sz);
ll mpow(ll a, ll b = mod-2, ll m = mod) {
ll res = 1; a %= m; assert(b >= 0);
for(; b; b >>= 1) { if(b & 1) res = res*a % m; a = a*a % m; }
return res;
}
void init() {
for (ll i = 2; i < sz; i++)
fac[i] = (fac[i-1] * i) % mod;
ifac[sz-1] = mpow(fac[sz-1]);
for (ll i = sz-2; i >= 0; i--)
ifac[i] = (ifac[i+1] * (i+1)) % mod;
for (int i = 2; i < sz; i++)
prime[i] = i;
for (ll i = 2; i*i < sz; i++) {
if (prime[i] != i) continue;
for (ll j = i*i; j < sz; j += i)
if (prime[j] == j) prime[j] = i;
}
}
ll nCr(ll n, ll r) {
if (n < r) return 0;
return (fac[n] * (ifac[r] * ifac[n-r] % mod)) % mod;
}
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; }
void solve() {
string s;
cin >> s;
int n = s.size();
if (n <= 3) {
cout << 0 << endl;
return ;
}
vector<ll> vals(n);
ll prod = 1, res = 0;
for (int i = n-1; i > 0; i--) {
ll pos = n - i - 1;
ll cnt = 9 * prod;
res += (cnt * (pos / 3));
prod *= 10;
vals[i] = prod;
}
for (int i = 0; i < n-1; i++) {
ll cnt;
if (i == 0) cnt = s[i] - '1';
else cnt = s[i] - '0';
ll val = cnt * vals[i+1];
res += (val * ((n-1)/3));
}
res += ((s[n-1]-'0' + 1) * ((n-1)/3));
cout << res<< endl;
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
// init();
int t = 1;
// cin >> t;
while(t--)
solve();
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args&&... args) {
const char *comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
#define pi 3.141592653589
#define MOD 1000000007
#define to() int tt; cin>>tt; while(tt--)
#define pb push_back
#define in insert
#define mp make_pair
#define ff first
#define ss second
#define si(s) s.size()
#define fori(it,v) for(it=v.begin();it!=v.end(); it++)
#define for1(i,low,high) for(int i=low;i<high;i++)
#define for2(i,low,high) for(int i=low;i<=high;i++)
#define rev(i,high,low) for(int i=high;i>=low ;i--)
#define all(x) x.begin(), x.end()
#define fil(x,i) memset(x,i,sizeof(x));
#define setbits(x) __builtin_popcount(x)
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define read freopen("input.txt","r",stdin)
#define write freopen("output.txt","w",stdout)
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
void i_o() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin) ;
freopen("output.txt", "w", stdout) ;
#endif
}
int main()
{
boost; i_o();
ll n; cin>>n;
ll ans=0;
ans+=max(0LL,min(999999-999LL,n-999));
ans+=max(0LL,min(999999999LL-999999,n-999999))*2LL;
ans+=max(0LL,min(999999999999LL-999999999,n-999999999LL))*3LL;
ans+=max(0LL,min(999999999999999L-999999999999LL,n-999999999999LL))*4LL;
ans+=max(0LL,min(999999999999999999L-999999999999999LL,n-999999999999999LL))*5LL;
cout<<ans<<endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = (n-1); i >= 0; i--)
#define Rep(n) for (ll _ = 0; _ < (ll)(n); _++)
template <class S>S sum(vector<S>& a) {return accumulate(all(a), S());}
template <class S>S max(vector<S>& a) {return *max_element(all(a));}
template <class S>S min(vector<S>& a) {return *min_element(all(a));}
ll max(int a, ll b) { return max((ll)a, b); } ll max(ll a, int b) { return max(a, (ll)b); }
ll min(int a, ll b) { return min((ll)a, b); } ll min(ll a, int b) { return min(a, (ll)b); }
void Main();
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(20);
Main();
return 0;
}
void Main(){
int a,b,c,d; cin>>a>>b>>c>>d;
int s = (a+b+c+d);
if(s % 2){
cout << "No\n";
return;
}else{
s /= 2;
if(a == s || b == s || c == s || d == s || a+b == s || a+c == s || a+d == s){
cout << "Yes\n";
}else{
cout << "No\n";
}
}
}
| #include <iostream>
#include <vector>
using namespace std;
int main(){
vector<int> a(4);
int sum = 0;
for(int i = 0; i < 4; i++){
cin >> a.at(i);
sum += a.at(i);
}
for(int bit = 0; bit < (1<<4); bit++){
int eat = 0;
for(int i = 0; i < 4; i++){
if(bit & (1<<i)){
eat += a.at(i);
}
}
if((sum-eat) == eat){
cout << "Yes" << endl;
return 0;
}
}
cout << "No" << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll calc(vector<ll> v) {
ll count = 0;
for (int i = 1; i <= 9; i++) {
count += i * pow(10, v.at(i - 1));
}
return count;
}
int main() {
int K;
cin >> K;
//場のカードを管理
vector<ll> card(9, K);
string S, T;
vector<ll> taka(9, 0), ao(9, 0);
cin >> S >> T;
for (char c : S) {
if (c != '#') {
taka.at(c - '1')++;
card.at(c - '1')--;
}
}
for (char c : T) {
if (c != '#') {
ao.at(c - '1')++;
card.at(c - '1')--;
}
}
// i:takaの5枚目
// j:aoの5枚目
double ans = 0;
for (int i = 1; i <= 9; i++) {
vector<ll> card2 = card;
vector<ll> taka2 = taka;
if (card2.at(i - 1) == 0) {
continue;
}
card2.at(i - 1)--;
taka2.at(i - 1)++;
for (int j = 1; j <= 9; j++) {
vector<ll> ao2 = ao;
if (card2.at(j - 1) == 0) {
continue;
}
card2.at(j - 1)--;
ao2.at(j - 1)++;
if (calc(taka2) > calc(ao2)) {
if (i != j) {
ans += (card2.at(i - 1) + 1) * (card2.at(j - 1) + 1);
} else {
ans += (card2.at(i - 1) + 2) * (card2.at(j - 1) + 1);
}
}
card2.at(j - 1)++;
}
}
ans /= (9 * K - 8);
ans /= (9 * K - 9);
cout << fixed << setprecision(9);
cout << ans << endl;
return 0;
} | #ifdef _DEBUG
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define all(v) v.begin(), v.end()
#define rep(i, begin, end) for(int i = begin; i < (int)(end); i++)
#define contains(v, x) (find(all(v), x) != v.end())
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> T roundup(T a, T b){ return (a + b - 1) / b; }
const double PI = 3.14159265359;
const vector<int> dy = {0, 1, 0, -1, 1, 1, -1, -1, 0};
const vector<int> dx = {1, 0, -1, 0, 1, -1, 1, -1, 0};
using ll = long long;
struct Edge{ int to; ll cost; Edge(int to, ll cost) : to(to), cost(cost) {} };
const ll MOD = (ll)1e9 + 7;
const ll INF = (ll)1e9;
using P = pair<ll, int>;
using Graph = vector<vector<int>>;
/*#include <atcoder/all>
using namespace atcoder;
using mint = modint;*/
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
//mint::set_mod(MOD);
int k;
string s, t;
cin >> k >> s >> t;
vector<int> cnta(10), cntb(10);
rep(i, 1, 10) cnta[i] = count(all(s), '0' + i);
rep(i, 1, 10) cntb[i] = count(all(t), '0' + i);
vector<ll> rem(10, k);
for(auto i : s) if(i > '0') rem[i - '0']--;
for(auto i : t) if(i > '0') rem[i - '0']--;
double ans = 0;
rep(a, 1, 10) rep(b, 1, 10){
if(rem[a] < 1 || rem[b] < 1) continue;
else if(a == b) if(rem[a] < 2) continue;
vector<int> tempa = cnta, tempb = cntb;
tempa[a]++, tempb[b]++;
ll sa = 0, sb = 0;
rep(i, 1, 10){
sa += i * (ll)pow(10, tempa[i]);
sb += i * (ll)pow(10, tempb[i]);
}
if(sa > sb){
if(a != b) ans += rem[a] * rem[b];
else ans += rem[a] * (rem[a] - 1);
}
}
cout << fixed << setprecision(10) << ans / (double)(9 * k - 8) / (9 * k - 9) << endl;
}
|
#include <iostream>
#include <string>
#include <vector>
struct Query {
int T;
int A;
int B;
};
std::istream& operator>>(std::istream& is, Query& q) {
return std::cin >> q.T >> q.A >> q.B;
}
int main() {
int N;
std::cin >> N;
std::string S;
std::cin >> S;
int Q;
std::cin >> Q;
std::vector<Query> queries(Q);
for (auto&& q : queries) {
std::cin >> q;
}
bool swapped = false;
for (auto&& q : queries) {
if (q.T == 1) {
if (swapped) {
const auto Ai = (q.A > N) ? (q.A - N) : q.A + N;
const auto Bi = (q.B > N) ? (q.B - N) : q.B + N;
std::swap(S[Ai - 1], S[Bi - 1]);
} else {
std::swap(S[q.A - 1], S[q.B - 1]);
}
} else {
swapped = !swapped;
}
}
if (swapped) {
for (int i = N; i < 2*N; ++i) {
std::cout << S[i];
}
for (int i = 0; i < N; ++i) {
std::cout << S[i];
}
std::cout << std::endl;
} else {
std::cout << S << std::endl;
}
} | #include<bits/stdc++.h>
using namespace std;
#define rep(i,m,n) for(int i=m;i<n;i++)
using ll=long long;
int main(){
ll n;
string s;
cin>>n>>s;
ll q;
cin>>q;
string sub1=s.substr(0,n);
string sub2=s.substr(n,n);
//cout<<sub1<<" "<<sub2<<endl;
ll tcount=0;
rep(i,0,q){
ll t;
ll a;
ll b;
cin>>t>>a>>b;
if(t==1){
if(tcount%2==0){
if(a<=n&&b<=n){
swap(sub1[a-1],sub1[b-1]);
}
else if(a<=n&&b>n){
swap(sub1[a-1],sub2[b-n-1]);
}
else swap(sub2[a-n-1],sub2[b-n-1]);
}
else{
if(a<=n&&b<=n){
swap(sub2[a-1],sub2[b-1]);
}
else if(a<=n&&b>n){
swap(sub2[a-1],sub1[b-n-1]);
}
else swap(sub1[a-n-1],sub1[b-n-1]);
}
}
else{
tcount++;
}
}
if(tcount%2==0){
cout<<sub1<<sub2<<endl;}
else cout<<sub2<<sub1<<endl;
} |
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int n,m;
int ans;
int a[500005];
int main()
{
cin>>n>>m;
for(int i=1;i<=m;i++)
cin>>a[i];
sort(a+1,a+m+1);
int k=1e9+7;
int lst=0;
a[++m]=n+1;
for(int i=1;i<=m;i++)
{
if(a[i]-lst-1!=0)
k=min(k,a[i]-lst-1);
lst=a[i];
}
lst=0;
for(int i=1;i<=m;i++)
{
if(a[i]-lst-1!=0)
ans+=(a[i]-lst-1+k-1)/k;
lst=a[i];
}
cout<<ans<<endl;
return 0;
} | #include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define Pii pair<int,int>
#define Pll pair<long long,long long>
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
//vector<vector<ll>> dp(n,vector<ll>(n))
//2-dim:vector<vector<Type>> vv(n, vector<Type>(m, d));
//3-dim:vector<vector<vector<Type>>> vvv(n, vector<vector<Type>>(m, vector<Type>(l, d)));
using namespace std;
signed main(){
std::cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
int n,m; cin >> n >> m;
vector<int> a(m+2);
a[0]=0;
rep(i,m) cin >> a[i+1];
if(m==0){
cout << 1 << endl;
return 0;
}
a[m+1]=n+1;
sort(ALL(a));
int mi=1e9;
rep(i,m+1){
if(a[i]+1!=a[i+1]&&a[i]!=a[i+1]) chmin(mi,a[i+1]-a[i]-1);
}
int ans=0;
rep(i,m+1){
ans += (a[i+1]-a[i]-1+mi-1)/mi;
//cout << (a[i+1]-a[i]-1+mi-1)/mi << endl;
}
cout << ans << endl;
return 0;
}
// g++ main.cpp -o main.out && ./main.out |
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define hcf __gcd
#define test cout<<"hello";
#define pie 3.14159265358979323846
#define maxa(v) *(max_element(all(v))
#define mina(v) *(min_element(all(v))
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mod 1000000007
#define ss second
#define ff first
#define inf (int)1e9
#define all(x) (x).begin(),(x).end()
#define unique(v) (v).erase(unique(all(v)),(v).end())
#define sz(x) (int)((x).size())
#define asort(v) sort(v.begin(),v.end())
#define dsort(v) sort(v.begin(),v.end(),greater<int>())
#define bs(v,k) binary_search(v.begin(),v.end(),k)
#define ub(v,k) (upper_bound(v.begin(),v.end(),k)-v.begin())
#define lb(v,k) (lower_bound(v.begin(),v.end(),k)-v.begin())
#define present(c,e) (c.find(e) != c.end())
#define cpresent(c,e) (find(all(c),e) != c.end())
#define tr(c,it) for(typeof(c.begin()) it = c.begin(); it != c.end(); it++)
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
inline int powMod(int a, int b) {int x = 1; while (b > 0) { if (b&1) x = (x*a) % mod; a = (a*a) % mod; b >>= 1; } return x; }
inline int multiply(int x, int y) { return ((x % mod) * (y % mod)) % mod; }
inline int divide(int x, int y) { return ((x % mod) * powMod(y % mod, mod-2)) % mod; }
inline int ceil(int a, int b) { return (a+b-1)/b; }
inline int log2(int x) { return 31 - __builtin_clz(x); }
int gcd (int a, int b) { while (b) { a %= b; swap(a, b); } return a; }
int lcm (int a, int b) { return a / gcd(a, b) * b; }
bool is_palindrome(const string &s) {
return equal(s.begin(), s.begin() + s.size() / 2, s.rbegin());
}
int binarysearch(int a[],int b,int l,int r){
int mid=(l+r)/2;
if(l>r) return (int)-1;
if(a[mid]==b||l==r) return mid;
if(a[mid]>b) return binarysearch(a,b,l,mid-1);
else return binarysearch(a,b,mid+1,r);
}
long long nCr(int n,int r){
if(n==r) return 1;
else if (r==0) return 1;
else return ((nCr(n-1,r-1)+nCr(n-1,r))%mod);
}
bool isPrime(ll n) {
if (n <= 1) return false;
if (n <= 3) return true;
if (n%2 == 0 || n%3 == 0) return false;
for (ll i=5; i*i<=n; i=i+6)
if (n%i == 0 || n%(i+2) == 0)
return false;
return true;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int tsc=1;
//cin>>tsc;
while(tsc--){
int a,b,c;
cin>>a>>b>>c;
if(a==0 and b==0){
cout<<'=';return 0;
}
if(c%2==1){
if(a>=0 and b>=0){
if(a==b){cout<<'=';}
else if(a>b){cout<<'>';}
else cout<<'<';
}
else if(a>=0 and b<0){
cout<<'>';
}
else if(a<0 and b>=0){
cout<<'<';
}
else{
if(a==b){cout<<'=';}
else if(a>b){cout<<'>';}
else cout<<'<';
}
}
else{
a=abs(a);b=abs(b);
if(a==b){cout<<'=';}
else if(a>b){cout<<'>';}
else cout<<'<';
}
cout<<endl;}return 0;}
| #include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#define ordered_set tree<int, null_type, less<int >,rb_tree_tag, tree_order_statistics_node_update>
//using namespace __gnu_pbds;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define ll long long
#define ld long double
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define vii vector<int>
#define vll vector<ll>
#define clr(v, d) memset(v,d,sizeof(v))
using namespace std;
const int N = 2e5 + 9;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
ll a,b,c;
cin>>a>>b>>c;
if(c&1){
if(a>b)cout<<">\n";
else if(b>a)cout<<"<\n";
else cout<<"=\n";
}
else{
a=abs(a);
b=abs(b);
if(a>b)cout<<">\n";
else if(b>a)cout<<"<\n";
else cout<<"=\n";
}
return 0;
} |
#include <iostream>
#include <string>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int main() {
int n, k;
cin >> n >> k;
int ans = 0;
rep(i, n)
rep(j, k)
ans += (100*(i + 1) + (j + 1));
cout << ans << endl;
} | #include <iostream>
using namespace std;
void solve() {
int n, k;
cin >> n >> k;
cout << n * k * (n * 100 + k + 101) / 2 << "\n";
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
solve();
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 ll long long
#define db double
#define el "\n"
#define ld long double
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n;i>=0;i--)
#define rep_a(i,a,n) for(int i=a;i<n;i++)
#define all(ds) ds.begin(), ds.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef vector< long long > vi;
typedef pair<long long, long long> ii;
typedef priority_queue <ll> pq;
#define o_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
const ll mod = 1000000007;
const ll INF = (ll)1e18;
const ll MAXN = 1000006;
ll po(ll x, ll n){
ll ans=1;
while(n>0){ if(n&1) ans=(ans*x)%mod; x=(x*x)%mod; n/=2;}
return ans;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T=1;
//cin >> T;
while(T--){
ll n;
cin>>n;
ll a[n];
rep(i,n) cin>>a[i];
ll mx = 0;
ll tmp = 0;
ll curr = 0;
rep(i,n){
mx = max(mx, a[i]);
tmp+=a[i];
curr+=tmp;
cout<<mx*(i+1)+curr<<el;
}
}
cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
return 0;
} | #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vll = vector<long long>;
using vb = vector<bool>;
using vd = vector<double>;
using vc = vector<char>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long>>;
using vvc = vector<vector<char>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using graph = vector<vector<pair<T, int>>>;// pair of weight and vertex
template<typename T> inline bool chmax(T& a, const T b){if(a < b){ a = b; return true; } return false; }
template<typename T> inline bool chmin(T& a, const T b){if(a > b){ a = b; return true; } return false; }
bool check(const vll& a, const ll n, const ll m, const ll val){
ll left = 0, right = 0;
for(const auto x: a){
left += ((m*x-val)+n-1)/n;
right += (m*x+val)/n;
}
return left <= m && m <= right;
}
vll rev(const vll& a, const ll n, const ll m, const ll val){
ll sum = 0;
for(const auto x: a){
const ll left = ((m*x-val)+n-1)/n;
sum += left;
}
vll b;
for(const auto x: a){
const ll left = ((m*x-val)+n-1)/n;
const ll right = (m*x+val)/n;
if(sum == m){
b.push_back(left);
}
else if(sum + right - left <= m){
sum += right - left;
b.push_back(right);
}else if(sum + right - left > m){
sum = m;
b.push_back(left + m - sum);
}
}
return b;
}
void my_answer(){
// binary search
ll k, n, m;
cin >> k >> n >> m;
vll a(k);
for(auto& x: a) cin >> x;
int ng = -1, ok = 1000000009;
while(ok - ng > 1){
const int mid = (ok + ng) / 2;
if(check(a, n, m, mid)) ok = mid;
else ng = mid;
}
vll b = rev(a, n, m, ok);
for(int i = 0; i < k; ++i){
if(i < k-1) cout << b[i] << " ";
else cout << b[i] << endl;
}
}
void best_answer(){
// greedy
ll k, n, m;
cin >> k >> n >> m;
vll a(k);
vll b(k);
vector<pll> c(k);
ll sum_l = 0;
for(int i = 0; i < k; ++i){
// l := a*m/n;
// |nb - ma| = |n(l + x) - ma| = |(nl-ma) + nx|
// x \in {0, 1}
// c := nl - ma;
// \sum_i l_i == M
cin >> a[i];
const ll l = a[i]*m/n;
b[i] = l;
sum_l += l;
c[i] = pll{n*l - m*a[i], i};
}
ll num_x = m - sum_l;
sort(c.begin(), c.end());
for(ll i = 0; i < num_x; ++i){
b[c[i].second] += 1;
}
for(int i = 0; i < k; ++i){
if(i < k-1) cout << b[i] << " ";
else cout << b[i] << endl;
}
}
int main(){
// my_answer();
best_answer();
}
|
#include<bits/stdc++.h>
using namespace std;
int main(){
double a,b;
cin>>a>>b;
cout<<(1-b/a)*100;
return 0;
} | #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(a) a.begin(),a.end()
using namespace std;
using ll=long long;
using P=pair<int,int>;
template<typename T>
using v=vector<T>;
template<typename T>
using vv=vector<v<T>>;
template<typename T>
using vvv=vector<vv<T>>;
int main(){
int n;
double D,H;
cin>>n>>D>>H;
double ret=0;
rep(i,n){
double d,h;
cin>>d>>h;
ret=max(ret,h-(H-h)*d/(D-d));
}
cout<<setprecision(16)<<ret<<endl;
}
|
#include<iostream>
#include<algorithm>
using namespace std;
const int N = 120;
int a[N][N];
int b[N];
int main()
{
int H,W,Minn=200;;
cin>>H>>W;
for(int i = 1;i<=H;++i){
for(int j = 1;j<=W;++j){
cin>>a[i][j];
if(a[i][j]<Minn) Minn = a[i][j];
}
}
int ans=0;
for(int i = 1;i<=H;++i){
for(int j = 1;j<=W;++j){
if(a[i][j]>Minn) ans+=(a[i][j]-Minn);
}
}
printf("%d",ans);
return 0;
} | /*#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
*/
#include<bits/stdc++.h>
using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define ll long long
#define f first
#define s second
#define Fast ios_base::sync_with_stdio(false);cin.tie(NULL);
typedef pair<ll , pair<ll, ll> > pi;
int pow(int x,int y){
int res=1;
while(y){
if(y&1) res*=x;
y>>=1;
x*=x;
}
return res;
}
struct Compare {
constexpr bool operator()(pi const & a,
pi const & b) const noexcept
{ return a.first < b.first || (a.first == b.first && a.second.first > b.second.first); }
};
void prefix_function( string s,ll arr[] )
{
long long border=0; arr[0]=0;
for(long long i=1;i<s.size();i++)
{
while(border>0 && s[i]!=s[border])
border=arr[border-1];
if(s[i]==s[border])
border++;
else
border=0;
arr[i]=border;
}
}//send mod-2 for a^-1 if mod is a prime number
ll mod=998244353;
ll add( ll a , ll b)
{
return (((a%mod)+(b%mod))%mod);
}
ll mul(ll a,ll b)
{
return (((a%mod)*(b%mod))%mod);
}
ll binpow(ll a, ll b) {
ll res = 1;
while (b) {
if (b & 1) res = mul(res, a);
a = mul(a, a);
b >>= 1;
}
return res;
}
ll subs(ll a,ll b)
{
return (((a%mod)-(b%mod)+mod)%mod);
}
ll dv(ll a,ll b)
{
ll inv=binpow(b,mod-2);
return mul(a,inv);
}
ll dsu_arr[100000];
ll dsu_sz[100000];
void dsu(ll n)
{
for(ll i=0;i<=n;i++)
{
dsu_arr[i]=i;
dsu_sz[i]=1;
}
}
ll find(ll x)
{
ll root=x;
while (root!=dsu_arr[root])
{
root=dsu_arr[root];
}
while(x!=dsu_arr[x])
{
dsu_arr[x]=root;
x=dsu_arr[x];
}
return root;
}
ll merge(ll x,ll y)
{
ll root1=find(x);
ll root2=find(y);
if(root1==root2)
return 0ll;
if(dsu_sz[x]>dsu_sz[y]){
dsu_arr[root2]=root1;
dsu_sz[root1]+=dsu_sz[root2];
}
else
{
dsu_sz[root2]+=dsu_sz[root1];
dsu_arr[root1]=root2;
}
return 1ll;
}
/*
vector<ll>adj[100005];
bool vis[100005];
ll dist[100005];
void bfs(ll c)
{
vis[c]=true;
dist[c]=0;
queue<ll>q;
q.push(c);
while(!q.empty())
{
ll x=q.front();
q.pop();
for(ll i=0;i<adj[x].size();i++)
{
ll y=adj[x][i];
if(!vis[y])
{
vis[y]=true;
dist[y]=dist[x]+1;
q.push(y);
}
}
}
}
*/
int main()
{
Fast
ll n,m;
cin>>n>>m;
vector<ll>sura;
ll mn=10000000000;
for(ll i=0;i<n*m;i++)
{
ll k;
cin>>k;
sura.push_back(k);
mn=min(mn,k);
}
ll ans=0;
for(ll i=0;i<n*m;i++)
{
ans+=(sura[i]-mn);
}
cout<<ans<<endl;
}
|
#include<bits/stdc++.h>
using namespace std;
int main(){
char ch1 = getchar();
char ch2 = getchar();
char ch3 = getchar();
if(ch1 == ch2 && ch2 == ch3)
puts("Won");
else
puts("Lost");
return 0;
} | #include<bits/stdc++.h>
using namespace std;
int main(){
string s;
cin >> s;
if(s[0]==s[1] && s[0]==s[2]){
cout << "Won" << endl;
}else{
cout << "Lost" << endl;
}
return(0);
} |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define PI acos(-1)
#define vi vector<int>
const int kMod = 1e9 + 7;
const int kInf = (~(1 << 31)) / 2 - 500;
const ll kInfL = (~(1LL << 63)) / 2 - 2000;
int main() {
int N, K;
cin >> N >> K;
vector<vector<int>> A(N, vector<int>(N));
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
cin >> A[i][j];
}
}
auto check = [&](ll mid) {
vector<vector<int>> cnt(N + 1, vector<int>(N + 1));
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
if (A[i][j] <= mid) {
cnt[i + 1][j + 1] = 1;
}
}
}
for (int i = 0; i <= N; ++i) {
for (int j = 1; j <= N; ++j) {
cnt[i][j] += cnt[i][j - 1];
}
}
for (int i = 0; i <= N; ++i) {
for (int j = 1; j <= N; ++j) {
cnt[j][i] += cnt[j - 1][i];
}
}
bool ret = false;
int mid_idx = (K * K) / 2;
if (K % 2 == 1) {
mid_idx = (K * K) / 2 + 1;
}
for (int i = K; i <= N; ++i) {
for (int j = K; j <= N; ++j) {
ll base = cnt[i][j] + cnt[i - K][j - K];
base -= cnt[i - K][j] + cnt[i][j - K];
if (base >= mid_idx) {
ret = true;
}
}
}
return ret;
};
int left = 0, right = kInf;
while (right - left > 1) {
int mid = left + (right - left) / 2;
if (check(mid)) {
right = mid;
} else {
left = mid;
}
}
if (check(left)) {
cout << left << endl;
return 0;
}
cout << right << endl;
return 0;
}
| #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
long long N, M; cin >> N >> M;
long long H[N], W[M];
for (int i = 0; i < N; i++) cin >> H[i];
for (int i = 0; i < M; i++) cin >> W[i];
long long dp[(N + 1) / 2][2];
for (int i = 0; i < (N + 1) / 2; i++) dp[i][0] = dp[i][1] = 0;
sort(H, H + N);
sort(W, W + M);
vector<int> Vec;
for (int i = 0; i < M; i++) Vec.push_back(W[i]);
sort(Vec.begin(), Vec.end());
long long now = 0;
for (long long i = 0; i < (N + 1) / 2; i++){
if (i == 0){
dp[0][0] = H[1] - H[0];
auto itr = lower_bound(Vec.begin(), Vec.end(), H[0]);
auto itr2 = itr - 1;
long long min_ = 1000000000000;
if ((itr - Vec.begin()) < M) min_ = min(min_, *itr - H[0]);
if ((itr2 - Vec.begin()) >= 0) min_ = min(min_, H[0] - *itr2);
dp[0][1] = min_;
continue;
}
if (i != (N - 1) / 2) dp[i][0] = dp[i - 1][0] + (H[i * 2 + 1] - H[i * 2]);
dp[i][1] = dp[i - 1][1] + (H[i * 2] - H[i * 2 - 1]);
auto itr = lower_bound(Vec.begin(), Vec.end(), H[i * 2]);
auto itr2 = itr - 1;
long long min_ = 1000000000000;
if ((itr - Vec.begin()) < M) min_ = min(min_, *itr - H[i * 2]);
if ((itr2 - Vec.begin()) >= 0) min_ = min(min_, H[i * 2] - *itr2);
dp[i][1] = min(dp[i][1], dp[i - 1][0] + min_);
}
cout << dp[(N - 1) / 2][1] << endl;
} |
#include<bits/stdc++.h>
using namespace std;
long long int mod=1e9+7;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin>>n;
map<long long int,long long int> mp1,mp2;
for(int i=0;i<n;i++)
{
int x;
cin>>x;
mp1[x]++;
}
long long int arr[n+1];
for(int i=1;i<=n;i++)
{
cin>>arr[i];
}
for(int i=0;i<n;i++)
{
int x;
cin>>x;
mp2[x]++;
}
long long int ans=0;
for(int i=1;i<=n;i++)
{
if(mp1.count(arr[i]))
{
if(mp2.count(i))
{
ans+=mp1[arr[i]]*mp2[i];
}
}
}
cout<<ans;
return(0);
} | #include<bits/stdc++.h>
using namespace std;
//#include <atcoder/modint>
//using namespace atcoder;
//using mint = modint998244353;
//using mint = modint1000000007;
#pragma region template
using ll = long long;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
#define overload4(_1,_2,_3,_4,name,...) name
#define overload3(_1,_2,_3,name,...) name
#define rep1(n) for(ll i=0;i<n;++i)
#define rep2(i,n) for(ll i=0;i<n;++i)
#define rep3(i,a,b) for(ll i=a;i<b;++i)
#define rep4(i,a,b,c) for(ll i=a;i<b;i+=c)
#define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#define rrep1(n) for(ll i=n;i--;)
#define rrep2(i,n) for(ll i=n;i--;)
#define rrep3(i,a,b) for(ll i=b;i-->(a);)
#define rrep(...) overload3(__VA_ARGS__,rrep3,rrep2,rrep1)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define debug(var) do{std::cerr << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cerr << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cerr << e << " "; } std::cerr << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){cerr << endl;int cnt = 0;for(const auto& v : vv){cerr << cnt << "th : "; view(v); cnt++;} cerr << endl;}
std::ostream &operator<<(std::ostream &dest, __int128_t value) {
std::ostream::sentry s(dest);
if (s) {
__uint128_t tmp = value < 0 ? -value : value;
char buffer[128];
char *d = std::end(buffer);
do {
--d;
*d = "0123456789"[tmp % 10];
tmp /= 10;
} while (tmp != 0);
if (value < 0) {
--d;
*d = '-';
}
int len = std::end(buffer) - d;
if (dest.rdbuf()->sputn(d, len) != len) {
dest.setstate(std::ios_base::badbit);
}
}
return dest;
}
template<class T, class K>bool chmax(T &a, const K b) { if (a<b) { a=b; return 1; } return 0; }
template<class T, class K>bool chmin(T &a, const K b) { if (b<a) { a=b; return 1; } return 0; }
const int inf = 1001001001;
const ll INF = 1001001001001001001ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll rddiv(ll a, ll b) { return a/b-((a^b)<0&&a%b); } // -20 / 3 == -7
ll power(ll a, ll p){ll ret = 1; while(p){if(p & 1){ret = ret * a;} a = a * a; p >>= 1;} return ret;}
ll modpow(ll a, ll p, ll mod){ll ret = 1; while(p){if(p & 1){ret = ret * a % mod;} a = a * a % mod; p >>= 1;} return ret;}
ll rudiv(ll a, ll b) { return a/b+((a^b)>0&&a%b); } // 20 / 3 == 7
#pragma endregion
// const double pi = acos(-1);
//const ll mod = 998244353;
const ll mod = 1000000007;
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
//cout << fixed << setprecision(20);
int n; cin >> n;
ll ans = 0;
V<int> cnt(n + 1);
V<int> a(n), b(n), c(n);
rep(i,n) cin >> a[i], cnt[a[i]]++;
rep(i,n) cin >> b[i];
rep(i,n) cin >> c[i];
rep(i,n) ans += cnt[b[c[i] - 1]];
cout << ans << endl;
} |
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
long double x,y,r; cin>>x>>y>>r; r = nextafter(r,INFINITY);
ll ans=0;
for(ll i=ceil(x-r);i<=floor(x+r);i++){
long double p = sqrt(pow(r,2) - pow(i-x,2));
ans += floor(y+p) - ceil(y-p) + 1;
}
cout << ans << endl;
} | #include <bits/stdc++.h>
#ifdef LILY
#include "./DebugOutput.h"
#else
#define dbg(...) (0)
#endif
using int32 = int;
using int64 = long long;
using namespace std;
class Solution
{
#define int int64
#define sfor(i, n) for (int i = 1; i <= n; ++i)
#define tfor(i, n) for (int i = 0; i < n; ++i)
int x, y, r, res = 0;
void SHURU()
{
double a, b, c;
cin >> a >> b >> c;
x = round(a * 10000);
y = round(b * 10000);
r = round(c * 10000);
}
void SHUCHU()
{
cout << res << endl;
}
bool inCircle(int dx, int dy)
{
return dx * dx + dy * dy <= r * r;
}
void CHULI()
{
x %= 10000;
y %= 10000;
int l = 0, r = 1;
for (int i = 1000100000; i >= 0; i -= 10000)
{
while (inCircle(x - l * 10000, y + i))
--l;
while (inCircle(x - r * 10000, y + i))
++r;
res += r - l - 1;
}
l = 0;
r = 1;
for (int i = 1000100000; i >= 10000; i -= 10000)
{
while (inCircle(x - l * 10000, y - i))
--l;
while (inCircle(x - r * 10000, y - i))
++r;
res += r - l - 1;
}
dbg(this->x, this->y, this->r);
}
public:
Solution()
{
SHURU();
CHULI();
SHUCHU();
}
#undef int
#undef tfor
#undef sfor
};
int32 main()
{
#ifdef LILY
while (1)
{
#endif
Solution();
#ifdef LILY
}
#endif
return 0;
}
|
/*
بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ
لَا إِلَٰهَ إِلَّا ٱللَّٰهُ مُحَمَّدٌ رَسُولُ ٱللَّٰهِ
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define sort(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define pb push_back
ll mod= 1000000007;
vector<ll>sv;
ll ar[1000000+9]= {0};
void seiv()
{
ll n=1000000,i,j;
ar[1]=1;
for(i=4; i<=n; i+=2)ar[i]=1;
for(i=3; i<=n; i+=2)
{
if(ar[i]==0)
{
for(j=i*i; j<=n; j+=i*2)ar[j]=1;
}
}
for(i=2; i<=n; i++)
{
if(ar[i]==0)sv.pb(i);
}
}
int main()
{
// seiv();
ll t;
// cin>>t;
// while(t--)
{
ll a,b,c=0,d=0,e=0,i,j=0,k=0,l=0;
cin>>a;
if(a%2)cout<<"Black";
else cout<<"White";
}
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
int n;
int f[100100],num[100100];
vector<int> qwq;
bool flag[100100];
void work1(){
for(int i=2;i<=n;i++){
if(flag[i]) continue;
qwq.push_back(i);
for(int j=i+i;j<=n;j+=i) flag[j]=1;
}
}
void work(int x){
for(int i=0;i<qwq.size();i++) {
if(x%qwq[i]==0){
num[x]=qwq[i];
return;
}
}
}
int main(){
cin>>n;
work1();
f[1]=1;
for(int i=2;i<=n;i++) work(i);
printf("%d",f[1]);
for(int i=2;i<=n;i++){
f[i]=f[i/num[i]]+1;
printf(" %d",f[i]);
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int n, m;
cin >> n >> m;
vector<pair<int, int>> cond(m);
for (auto &[a, b] : cond) cin >> a >> b;
int k;
cin >> k;
vector<pair<int, int>> choice(k);
for (auto &[c, d] : choice) cin >> c >> d;
int res = 0;
for (int mask = 0; mask < (1 << k); ++mask) {
vector<bool> ball(n);
for (int i = 0; i < k; ++i) {
auto &[c, d] = choice[i];
ball[(mask & (1 << i)) ? c : d] = true;
}
int cnt = 0;
for (auto &[a, b] : cond) {
if (ball[a] && ball[b]) cnt++;
}
res = max(res, cnt);
}
cout << res << endl;
}
| #include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;
int check(vector<vector<int>> pairs, vector<bool> put) {
int ans = 0;
for (int i = 0; i < pairs.size(); i++) {
if (put.at(pairs.at(i).at(0)-1) and put.at(pairs.at(i).at(1)-1)) {
ans++;
}
}
return ans;
}
int maxjoken(vector<vector<int>> pairs, vector<bool> put,vector<vector<int>> options,int rest,int N) {
if (rest == 0) {
return check(pairs, put);
}
vector<bool> a=put, b=put;
a.at(options.at(N - rest).at(0)-1) = true;
b.at(options.at(N - rest).at(1)-1) = true;
return max(maxjoken(pairs, a, options, rest - 1, N), maxjoken(pairs, b, options, rest - 1, N));
}
int main() {
int N, M;
cin >> N >> M;
vector<vector<int>> pairs(M, vector<int>(2));
for (int i = 0; i < M; i++) {
cin >> pairs.at(i).at(0);
cin >> pairs.at(i).at(1);
}
int K;
cin >> K;
vector<vector<int>> options(K,vector<int>(2));
for (int i = 0; i < K; i++) {
cin >> options.at(i).at(0) >> options.at(i).at(1);
}
vector<bool> put(N, false);
cout << maxjoken(pairs, put, options, K, K);
} |
#include <bits/stdc++.h>
#define ll long long
#define maxi(a, b) (a > b ? a : b)
#define mini(a, b) (a < b ? a : b)
#define MOD 1000000007
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
//freopen("test_input.txt","r",stdin);
ll t = 1;
//cin >> t;
while(t--) {
ll n, q, a, b, c;
cin >> n >> q;
set<ll> st;
for(ll i = 0; i < n; i++) {
ll e;
cin >> e;
st.insert(e);
}
vector<ll> lw, num;
ll prev = 0;
ll running = 0;
for(ll e : st) {
if(e > prev+1) {
lw.push_back(prev);
num.push_back(running+e-prev-1);
}
running = running+e-prev-1;
prev = e;
}
lw.push_back(prev);
num.push_back(LONG_LONG_MAX/2);
while(q--) {
ll k;
cin >> k;
ll idx = lower_bound(num.begin(), num.end(), k) - num.begin();
ll temp = idx > 0 ? num[idx-1] : 0;
ll res = lw[idx] + k-temp;
//cout << lw[idx] << " " << num[idx] << "\n";
cout << res << "\n";
}
}
return 0;
} | #include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#define ll long long
#define MAXN 200005
#define uns unsigned
#define MOD 998244353ll
#define INF 0x7f7f7f7f
using namespace std;
inline ll read(){
ll x=0;bool f=1;char s=getchar();
while((s<'0'||s>'9')&&s>0){if(s=='-')f^=1;s=getchar();}
while(s>='0'&&s<='9')x=(x<<1)+(x<<3)+s-'0',s=getchar();
return f?x:-x;
}
ll x,y,p,q;
inline ll ksm(ll a,ll b,ll mo){
ll res=1;
for(;b;b>>=1,a=a*a%mo)if(b&1)res=res*a%mo;
return res;
}
inline ll gcd(ll a,ll b){
return b==0?a:gcd(b,a%b);
}
inline ll exgcd(ll a,ll b,ll&x,ll&y){
if(b==0){x=1,y=0;return a;}
ll res=exgcd(b,a%b,y,x);
y-=a/b*x;return res;
}
signed main()
{
for(int T=read();T--;){
x=read(),y=read(),p=read(),q=read();
ll md=(x+y)<<1,lim=md*(p+q)+1,ans=lim;
for(ll i=x;i<x+y;i++){
ll b=p,a=p+q,c=((i-b)%md+md)%md;
ll k,f,g=exgcd(a,md,k,f);
if(c%g!=0)continue;
c/=g,k=(k*c%md+md)%md,f=md/g,k%=f;
a=p+q,b=p;
if((k*a+b)%md>=x&&(k*a+b)%md<x+y)ans=min(ans,k*a+b);
// printf(" %lld %lld %lld %lld\n",i,k,k*a+b,ans);
}
md=p+q;
for(ll i=p;i<p+q;i++){
ll b=x,a=(x+y)<<1,c=((i-b)%md+md)%md;
ll k,f,g=exgcd(a,md,k,f);
if(c%g!=0)continue;
c/=g,k=(k*c%md+md)%md,f=md/g,k%=f;
a=(x+y)<<1,b=x;
if((k*a+b)%md>=p&&(k*a+b)%md<p+q)ans=min(ans,k*a+b);
// printf(" %lld %lld %lld %lld\n",i,k,k*a+b,ans);
}
if(ans>=lim)printf("infinity\n");
else printf("%lld\n",ans);
}
return 0;
}
/*
1
93 5 52 8
292
*/ |
//雪花飄飄北風嘯嘯
//天地一片蒼茫
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define lb lower_bound
#define up upper_bound
#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
//change less to less_equal for non distinct pbds, but erase will bug
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
int n,m,k;
vector<int> al[100005];
int arr[20];
int mat[20][20];
int w[100005];
queue<int> q;
ll memo[132000][17];
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin.exceptions(ios::badbit | ios::failbit);
cin>>n>>m;
int a,b;
rep(x,0,m){
cin>>a>>b;
al[a].pub(b);
al[b].pub(a);
}
cin>>k;
rep(x,0,k) cin>>arr[x];
rep(x,0,k){
memset(w,63,sizeof(w));
w[arr[x]]=0;
q.push(arr[x]);
while (!q.empty()){
int node=q.front();
q.pop();
for (auto &it:al[node]){
if (w[it]>1e9){
w[it]=w[node]+1;
q.push(it);
}
}
}
rep(y,0,k){
mat[x][y]=w[arr[y]];
}
}
//rep(x,0,k) cout<<mat[0][x]<<" "; cout<<endl;
memset(memo,63,sizeof(memo));
rep(x,0,k){
memo[1<<x][x]=0;
}
rep(x,1,1<<k) rep(y,0,k){
rep(bit,0,k) if ((x&(1<<bit))==0){
memo[x|(1<<bit)][bit]=min(memo[x|(1<<bit)][bit],memo[x][y]+mat[y][bit]);
}
}
//rep(x,0,k) cout<<memo[(1<<k)-1][x]<<" "; cout<<endl;
ll ans=1e10;
rep(x,0,k) ans=min(ans,memo[(1<<k)-1][x]);
if (ans>1e9) cout<<"-1"<<endl;
else cout<<ans+1<<endl;
}
| #include <bits/stdc++.h>
//#include <atcoder/all>
#define rep(i, n) for (int i=0; i < (n); i++)
using namespace std;
//using namespace atcoder;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
const int INF = 1 << 30;
const ll LINF = 1LL << 61;
const int NIL = -1;
const int MAX = 10000;
const int MOD = 1000000007;
const double pi = 3.141592653589;
int main() {
int n, m;
cin >> n >> m;
vector<int> w(n);
rep(i,n)cin >> w[i];
sort(w.begin(), w.end());
vector<P> vl(m);
rep(i,m) cin >> vl[i].second >> vl[i].first;
sort(vl.begin(),vl.end());
rep(i,m-1){
vl[i+1].second = max(vl[i+1].second, vl[i].second); //lでマックスとっていく
}
vector<int> v(m);
rep(i,m) v[i] = vl[i].first;
int w_max = *max_element(w.begin(), w.end());
int v_min = *min_element(v.begin(), v.end());
if(w_max>v_min){
cout << -1 << endl;
return 0;
}
//順列全探索
ll ans = LINF;
do{
vector<int> sum_w(n+1, 0);
rep(i, n) sum_w[i+1] = sum_w[i] + w[i];
//ここから有向グラフ化
//i→j間は、i~jのラクダたちが含まれるので重さの総和でにぶたんして辺の長さを決める
vector<vector<P>> edge(n, vector<P>(0));
//i,jは1-indexed
for(int i=1;i<n;i++){
for(int j=i+1;j<=n;j++){
int weight = sum_w[j]-sum_w[i-1];
auto itr = lower_bound(vl.begin(), vl.end(), make_pair(weight, 0));
if(itr==vl.begin())
edge[i-1].emplace_back(j-1, 0); //edgeは0-indexed
else
edge[i-1].emplace_back(j-1,vl[itr-vl.begin()-1].second);
}
}
//bfsで距離調べる
queue<int> q;
q.push(0);
vector<int> dist(n, -1);
dist[0] = 0;
while(!q.empty()){
int p = q.front();
q.pop();
for(auto c :edge[p]){
if(dist[c.first]!=-1){
dist[c.first] = max(dist[c.first], dist[p] + c.second);
continue;
}
q.push(c.first);
dist[c.first] = dist[p] + c.second;
}
}
ll res = dist[n-1];
ans = min(ans, res);
}while(next_permutation(w.begin(), w.end()));
cout << ans << endl;
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
using ll = long long ;
ll a[4][3000006] ;
ll get(ll cnt , ll n) ;
int main() {
ios::sync_with_stdio(false) ;
cin.tie(0) ;
cin.tie(0) ;
ll n , k ;
cin >> n >> k ;
for(int i = 1 ; i <= n ; i++) a[1][i] = 1;
for(int i = 2 ;i <= 3 ; i++) {
for(int j = 1 ; j <= n * i ; j++) a[i-1][j] += a[i-1][j-1] ;
for(int j = i ; j <= i * n ; j++) {
if(j >= n + 1) a[i][j] += a[i-1][j-1] - a[i-1][j-n-1] ;
else a[i][j] += a[i-1][j-1] ;
}
}
ll x = 1, y = 1 , z = 1 ;
ll tar ;
for(int i = 3 ; i <= n * 3 ; i++) {
if(k <= a[3][i]) {tar = i ; break ;}
else k -= a[3][i] ;
}
ll i ;
for( i = 1 ; i <= n ; i++) {
if(tar - i > 2 * n) continue ;
ll x1 = get(tar - i , n) ;
if(k > x1) k -= x1 ;
else break ;
}
x = tar - i - 2 ;
if(z + x > n) {
x -= n - z ;
z = n ;
y += x ;
} else z += x ;
y += k - 1 ; z -= k - 1 ;
cout << i << ' ' << y << ' ' << z << endl ;
}
ll get(ll cnt , ll n) {
cnt -= 2 ;
ll i = 1 , j = 1 ;
if(cnt + 1 > n) {
cnt -= n - j ;
i += cnt ;
j = n ;
} else j += cnt ;
return min(n + 1 - i , j) ;
} | #include <iostream>
#include <vector>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
using ll=long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// union by size + path having
class UnionFind {
public:
vector <ll> par; // 各元の親を表す配列
vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)
// Constructor
UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
}
void init(ll sz_) {
par.resize(sz_);
siz.assign(sz_, 1LL); // resize だとなぜか初期化されなかった
for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
}
// 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] < siz[y]) swap(x, y);
siz[x] += siz[y];
par[y] = x;
return true;
}
bool same(ll x, ll y) { // 連結判定
return root(x) == root(y);
}
ll size(ll x) { // 素集合のサイズ
return siz[root(x)];
}
};
int main(){
long long n,x;
cin>>n>>x;
long long k=0;
long long X=x*100;
for(int i=1;i<=n;i++){
long long a,b;
cin>>a>>b;
k+=a*b;
if(k>X){
cout<<i;
break;
}
if(i==n && k<=X){
cout<<-1;
}
}
} |
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <unordered_map>
#include <set>
#include <algorithm>
#include <utility>
#include <cmath>
using namespace std;
typedef long long llong;
typedef unsigned long long ullong;
// -2.1e-9 <= int <= 2.1e9
// -9.2e-18 <= long long <= 9.2e18
// 0 <= unsigned int <= 4.2e9
// 0 <= unsigned long long <= 18.4e18
// cout << fixed << setprecision(10);
int main() {
vector<int> A(4);
int sum = 0;
for (auto &a: A) {
cin >> a;
sum += a;
}
for (size_t i = 0; i < A.size(); ++i) {
int slct = A[i];
int notSlct = sum - A[i];
if (slct == notSlct) {
cout << "Yes" << endl;
return 0;
}
for (size_t j = 0; j < A.size(); ++j) {
if (j == i) continue;
slct += A[j];
notSlct -= A[j];
if (slct == notSlct) {
cout << "Yes" << endl;
return 0;
}
for (size_t k = 0; k < A.size(); ++k) {
if ((k == i) || (k == j)) continue;
slct += A[k];
notSlct -= A[k];
if (slct == notSlct) {
cout << "Yes" << endl;
return 0;
}
}
}
}
cout << "No" << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define maxn 200010
const int MOD = 1000000007;
void solve() {
int n, m, t;
cin >> n >> m >> t;
int pre = 0, bat = n;
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
bat -= a - pre;
if (bat <= 0) {
cout << "No";
return;
}
bat += b - a;
bat = min(n, bat);
pre = b;
}
bat -= t - pre;
if (bat <= 0) {
cout << "No";
return;
}
cout << "Yes";
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
// cin >> t;
while (t--)
solve();
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse4")
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define SZ(a) (int)((a).size())
#define ALL(a) a.begin(), a.end()
typedef long long LL;
typedef pair<int, int> PII;
const int MAX = 5007;
const int mod = 998244353;
int add(int a, int b)
{
return a + b < mod ? a + b : a + b - mod;
}
int sub(int a, int b)
{
return a - b >= 0 ? a - b : a - b + mod;
}
void updAdd(int& x, int val)
{
x += val;
if(x >= mod)
x -= mod;
}
int mult(int a, int b)
{
return (LL)a * b % mod;
}
int binPow(int a, int n)
{
int res = 1;
while(n)
{
if(n & 1)
res = mult(res, a);
a = mult(a, a);
n >>= 1;
}
return res;
}
int main()
{
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int N, M;
cin >> N >> M;
vector<int> g(N + 1, 1);
g[0] = 0;
vector<int> g1(N + 1), g2(N + 1);
FOR(n, 0, N + 1)
{
g1[n] = mult(g[n], binPow(2, mod - n - 3));
g2[n] = mult(n, g1[n]);
}
FOR(m, 2, M + 1)
{
vector<int> ng(N + 1), ng1(N + 1), ng2(N + 1);
int invM = binPow(m + 1, mod - 2);
int s1 = 0, s2 = 0;
FOR(n, 3, N + 1)
{
updAdd(s1, g1[n - 2]);
updAdd(s2, g2[n - 2]);
ng[n] = sub(mult(n + 2 * m - 1, s1), s2);
}
int pw = mult(invM, invM), pwM = 1, pwMinus = 1;
FOR(n, 1, N + 1)
{
pw = mult(pw, invM);
pwM = mult(pwM, m);
pwMinus = mult(pwMinus, m - 1);
ng[n] = mult(ng[n], pwM);
updAdd(ng[n], add(add(g[n], mult(2, g[n - 1])), sub(pwM, pwMinus)));
ng1[n] = mult(ng[n], pw);
ng2[n] = mult(ng1[n], n);
}
g = ng;
g1 = ng1;
g2 = ng2;
}
cout << g[N] << "\n";
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9+7;
//const long long MOD = 998244353;
const long long INF_LL = 1e18+11; const int INF_int = 1e9+11;
#define ll long long
#define mp std::make_pair
#define rep(i,n) for(int i = 0;i<n;i++)
#define lrep(i,n) for(long long i = 0;i<n;i++)
#define All(a) a.begin(),a.end()
#define Debug_Output_ALL(a) for(auto x:a) cout << x << " ";cout << endl;
#define endl "\n"
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
void fast(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
}
int main(){
fast();
int now = 0;
int n;
cin >> n;
vector<int> vec(n);
rep(i,n) cin >> vec[i];
vector<int> ans(n);
set<int> st;
rep(i,n){
st.insert(vec[i]);
while(st.count(now)==1){
now++;
}
ans[i]=now;
}
rep(i,n) cout << ans[i] << endl;
} |
#include<iostream>
#include<vector>
#include<cstdio>
using namespace std;
int main(void)
{
int N,D,H; cin>>N>>D>>H;
vector<double> d(N),h(N);
double max=0;
double buf;
for(int i=0;i<N;i++){cin>>d[i]>>h[i];}
for(int i=0;i<N;i++){
buf=(H-h[i])/(D-d[i]);
buf=(H+h[i])-buf*D-buf*d[i];
buf/=2.0;
if(max<buf){max=buf;}
}
printf("%.13f\n",max);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main()
{
int n , s , d;
cin >> n >> s >> d;
int a[n][2];
bool b=0;
for(int i = 0 ; i<n ; i++){
cin >> a[i][0]>> a[i][1];
if(a[i][0]<s && a[i][1]>d)
{
b=1;
}
}
if(b==1){
cout << "Yes";
return 0;
}
cout << "No";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vll = vector<vl>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
const ll INF = 1LL << 60;
const double pi = acos(-1);
ll mod = 1000000007;
ll gcd(ll a, ll b){
if(a%b == 0){
return b;
}else{
return gcd(b,a%b);
}
}
ll lcm(ll a, ll b){
return a * b / gcd(a, b);
}
int main() {
int n; cin >> n;
string t; cin >> t;
ll ans = 0;
int zero = 0, one = 0, k = 0;
for(auto i : t){
if(i == '0') {
zero++;
one = 0;
}
if(i == '1') {
one++;
zero = 0;
}
if(k < n - 2){
if(t[k] == '0' && t[k+1] == '1' && t[k+2] == '0') {
cout << ans << endl;
return 0;
}else{
k++;
}
}
if(zero == 2 || one == 3){
cout << ans << endl;
return 0;
}
}
if(n == 1 && t[0] == '1'){
ans = 2 * (ll)1e10;
}else if(n == 1 && t[0] == '0'){
ans = (ll)1e10;
}else if(n == 2){
if(t[0] == '1' && t[1] == '1' || t[0] == '1' && t[1] == '0'){
ans = (ll)1e10;
}else{
ans = (ll)1e10 - 1;
}
}else if(n%3 == 0){
if(t[0] == '1' && t[1] == '1' && t[2] == '0'){
ans = (ll)1e10 - n / 3 + 1;
}else{
ans = (ll)1e10 - n / 3;
}
}else{
if(n%3==2 && t[0] == '0') ans = (ll)1e10 - n / 3 - 1;
else ans = (ll)1e10 - n / 3;
}
cout << ans << endl;
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define eps 1e-9
#define rep(i,l,r) for(int i=l;i<r;i++)
#define rrep(i,r,l) for(int i=r-1;i>=l;i--)
typedef long long ll;
const int maxn=2e5+5;
int n;
char t[maxn];
void solve()
{
if(n==1){
if(t[0]=='1') printf("20000000000\n");
else printf("10000000000\n");
return ;
}
ll ans=0;
bool ok=true;
int l=0,r=n-1,x=0;;
while(l<n&&t[l]!='0') ++l;
while(r>=0&&t[r]!='0') --r;
if(l<n) ++l;
++r;
if(l>3||r<n-2) ok=false;
if(ok){
rep(i,l,r){
if(t[i]=='0'){
if(x==2) x=0,++ans;
else {
ok=false;
break;
}
}
else ++x;
}
}
if(x) ok=false;
if(r!=n&&r>=l) ++ans;
printf("%lld\n",ok?10000000000-ans:0);
}
int main()
{
scanf("%d %s",&n,t);
solve();
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
const int MOD=998244353;
const int INF=1e18;
void io(string s1="input.txt",string s2="output.txt"){freopen(s1.c_str(), "r", stdin);freopen(s2.c_str(), "w", stdout);}
signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int n;cin>>n;
n=(1LL<<n);
vi v(n);
map<int,int> id;
for(int i=0;i<n;i++){
cin>>v[i];
id[v[i]]=i+1;
}
while(v.size()!=2){
vi tmp;
for(int i=0;i<v.size();i+=2){
tmp.push_back(max(v[i],v[i+1]));
}
v=tmp;
}
cout<<id[min(v[0],v[1])];
} | #include <bits/stdc++.h>
using namespace std;
int a, b, c, d, x, y;
int main(){
cin >> a >> b >> c >> d ;
x = max({a, b});
y = min({c, d}) ;
cout << x - y;
}
|
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
int a,b,c;
cin>>a>>b>>c;
cout<<21-a-b-c<<endl;
} | #include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
using namespace std;
typedef long long ll;
int main() {
int a,b,c;cin>>a>>b>>c;
if(c%2==0){
if(fabs(a)> fabs(b)) cout<<">"<<endl;
else if(fabs(a)< fabs(b)) cout<<"<"<<endl;
else cout<<"="<<endl;
}else{
if(a==b) cout<<"="<<endl;
else if(a>b) cout<<">"<<endl;
else cout<<"<"<<endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long LINF = 1LL << 60;
const long long LMINF = 1LL << 63;
const int INF = 1 << 30;
#define REP(i,n) for(int i = 0;i < n;++i)
#define REPS(i,x) for(int i = 1;i <= (int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i >= 0;i--)
#define RREPS(i,x) for(int i=((int)(x));i > 0;i--)
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define ALL(obj) (obj).begin(),(obj).end()
#define debug(x) cout << #x << ": " << x << "\n"
#define out(x) cout << x << endl
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int main(){
ios::sync_with_stdio(false);cin.tie(0);
ll n;
cin >> n;
vector<ll> a(n);
REP(i,n)cin >> a[i];
if (n == 1) {
cout << a[0] << endl;
return 0;
}
ll min = LINF;
int num = a.size() - 1;
for (int bit = 1; bit < (1 << num); ++bit)
{
int j = 1;
ll orp = a[0];
vector<ll> xorp;
for(int i = 0;i < num;i++){
bool f = (bit & (1 << i)) ;
if(f == 0){
orp |= a[j];
}else if(f == 1){
xorp.emplace_back(orp);
orp = a[j];
}
j++;
}
xorp.emplace_back(orp);
ll xorpp = xorp[0];
for(int i = 1;i<xorp.size();i++){
xorpp ^= xorp[i];
}
chmin(min,xorpp);
if(min == 0)break;
}
cout << min << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std ;
#define int long long
int n, a[21] ;
int fun(int idx, int orr, int xr) {
if (idx > n) {
return (xr^orr) ;
}
int cur = fun(idx+1, orr|a[idx], xr) ;
cur = min(cur, fun(idx+1, a[idx], xr^orr)) ;
return cur ;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n ;
for (int i=1;i<=n;++i) cin >> a[i] ;
int ans = fun(1, 0, 0) ;
cout << ans << endl ;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=105;
const int mod=998244353;
int n,ans;
int w[maxn];
ll fac[maxn];
const int B=15000;
const int Q=40000;
int main() {
fac[0]=1ll;
for(ll i=1;i<=100;i++) fac[i]=fac[i-1]*i%mod;
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++)
cin>>w[i];
vector<vector<int> > lst(n+5,vector<int>(Q,0));
lst[0][B]=1;
for(int i=1;i<=n;i++) {
vector<vector<int> > now(n+5,vector<int>(Q,0));
for(int j=1;j<=i;j++)
for(int k=-10000;k<=10000;k++) {
now[j][k+B]+=lst[j-1][k-w[i]+B];
now[j][k+B]%=mod;
}
for(int j=0;j<=i;j++)
for(int k=-10000;k<=10000;k++) {
now[j][k+B]+=lst[j][k+w[i]+B];
now[j][k+B]%=mod;
}
lst=now;
}
for(int i=0;i<=n;i++) {
ans+=ll(lst[i][B])*fac[i]%mod*fac[n-i]%mod;
ans%=mod;
}
cout<<ans<<endl;
return 0;
} | /*
problem :
algorithm :
created : Programmer_juruo
*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define N 2000005
#define M 2005
#define lowbit(x) x & (-x)
#define F1(i, n) for(int i = 1; i <= n; i++)
#define F(i, a, n) for(int i = a; i <= n; i++)
#define F0(i, n) for(int i = 0; i < n; i++)
#define dbg(x) cout << #x << ":" << x << endl;
#define Se second
#define Fi first
#define y1 juruo
#define Mp make_pair
#define Pb push_back
#define arr vector<int>
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)
typedef pair <int, int> pii;
typedef priority_queue <int> pq;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int p = 107;
const int P = 100007;
const int Mod = 1e9+7;
int n, m;
void work() {
cin >> n;
arr x(n+1);
for(int i = 1; i <= n; i++) {
cin >> x[i];
}
sort(x.begin()+1, x.end());
int Ans = 1, cnt = 0;
for(int i = 1; i < x.size(); i++) {
Ans *= (x[i] - x[i-1] +1);
Ans %= Mod;
}
cout << Ans << endl;
}
signed main() {
//freopen("1.in", "r", stdin);
//freopen("1.out", "w", stdout);
int T = 1;
//cin >> T;
while(T--) {
work();
}
return 0;
}
|
#include <iostream>
using ll = long long;
int const nmax = 100000;
int const modulo = 1000000007;
std::pair<int,int> dp[5 + nmax][2];
int v[5 + nmax];
std::pair<int,int> add(std::pair<int,int> f1, std::pair<int, int> f2) {
return {(f1.first + f2.first) % modulo,
(f1.second + f2.second) % modulo};
}
std::pair<int,int> append(std::pair<int,int> f1, int val) {
return {f1.first, (f1.second + 1LL * f1.first * val) % modulo};
}
int main() {
std::ios::sync_with_stdio(0);
std::cin.tie(0);
int n;
std::cin >> n;
for(int i = 1;i <= n; i++)
std::cin >> v[i];
dp[1][0] = {1, v[1]};
for(int i = 2; i <= n; i++) {
dp[i][0] = append(add(dp[i - 1][0], dp[i - 1][1]), v[i]);
dp[i][1] = append(dp[i - 1][0], modulo -v[i]);
}
std::cout << add(dp[n][0], dp[n][1]).second;
return 0;
}
| #include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<n; i++)
#define rng(i,l,r) for (int i=l; i<r; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define endl "\n"
#define INF 1000000007 // 1e9+7
#define LINF 1152921504606846976 // 1LL<<60
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> using V = vector<T>;
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; }
struct in { template <class T> operator T() { T t; std::cin >> t; return t; } };
int dx[8] = {0,1,0,-1,1,1,-1,-1};
int dy[8] = {1,0,-1,0,1,-1,1,-1};
auto solve() {
ll n = in();
int m = in();
V<string> ss(n);
rep(i,n) {
cin >> ss[i];
}
ll ans = n * (n-1) / 2;
ll c = 1;
int di = -1;
rng(j,1,n) {
int d = 0;
rep(k,m) {
if (ss[0][k] != ss[j][k]) d++;
}
if (d % 2 == 0) c++;
else di = j;
}
ans -= c * (c-1) / 2;
if (di != -1) {
c = 1;
rep(j,n) {
if (j == di) continue;
int d = 0;
rep(k,m) {
if (ss[di][k] != ss[j][k]) d++;
}
if (d % 2 == 0) c++;
}
ans -= c * (c-1) / 2;
}
return ans;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << solve() << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < n; ++i)
using ll = long long;
using P = pair<int,int>;
int main() {
int n,m;
cin>>n>>m;
vector<int> v(n),w(m);
rep(i,n)cin>>v[i];
rep(i,m)cin>>w[i];
int j=0;
rep(i,n){
while(j<m&&w[j]<v[i]){
cout<<w[j]<<" ";
j++;
}
if(v[i]==w[j]){
j++;
continue;
}
cout<<v[i]<<" ";
}
for (; j < m; j++)
{
cout<<w[j]<<" ";
}
cout<<endl;
} | #include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=(int)(x);i<(int)(y);i++)
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=1e9+7;
const int siz=3e5;
const int inf=1e9;
int main(){
int N,M; cin>>N>>M;
int x,y;
pair<int,int> vp[M+1]; vp[0] = {0, N};
map<pair<int,int>,bool> mp; mp[vp[0]] = true;
map<int,vector<int>> record; record[N].push_back(0);
rep(i,0,M){
cin>>x>>y;
vp[i+1] = {x, y};
record[y].push_back(x);
}
sort(vp,vp+M+1);
for(auto it = record.begin(); it != record.end(); it++){
sort((it->second).begin(), (it->second).end());
//print((it->second),,(it->second).size());
}
rep(i,1,M+1){
pair<int,int> p = vp[i];
mp[p] = false;
if(p.second > 0 && !record[p.second-1].empty()){
auto it = lower_bound(record[p.second-1].begin(), record[p.second-1].end(), p.first);
if(it != record[p.second-1].begin()){
mp[p] |= mp[{*(it-1), p.second-1}];
}
}
if(p.second < 2*N && !record[p.second+1].empty()){
auto it = lower_bound(record[p.second+1].begin(), record[p.second+1].end(), p.first);
if(it != record[p.second+1].begin()){
mp[p] |= mp[{*(it-1), p.second+1}];
}
}//cout<<p.first<<" "<<p.second<<" "<<mp[p]<<endl;
}
int ans = 0;
for(pair<int,vector<int>> pv:record){
if(!pv.second.empty()) ans += mp[{pv.second.back(), pv.first}];
}
cout<<ans<<endl;
} |
#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 fast { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define pb push_back
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define mp make_pair
#define infi INT_MAX
#define infl LONG_LONG_MAX
#define infd LDBL_MAX
#define f(i,a,b) for(ll i=a;i<b;i++)
#define ff first
#define ss second
#define pll pair<ll,ll>
#define endl "\n"
#define ALL(v) v.begin(),v.end()
#define nl cout<<"\n";
#define pr(x) cout<<x;
#define pr1(x) cout<<x<<" ";
#define pr2(x,y) cout<<x<<" "<<y;
#define deb printf("*****************************\n");
#define idk printf("idk idk ! \n");
#define hi printf("hi ! \n");
#define bye printf("bye bye ! \n");
#define o_set(ll) tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define number_of_set_bits __builtin_popcountll
//template<typename T>
//#define o_set(T) tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set
ll ceil(ll x,ll y){
return (x + y-1)/y;
}
int main()
{
fast
//#ifndef ONLINE_JUDGE
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
//#endif // ONLINE_JUDGE
ll ntc=1;
// cin>>ntc;
f(ks,1,ntc+1)
{
//cout<<"Case #"<<ks<<": ";
ll a,b,c,d; cin>>a>>b>>c>>d;
if( d*c - b > 0 ) cout<<ceil(a , (d*c - b));
else cout<<-1;
nl
}
return 0;
} | #include <cstdio>
#include <iostream>
using namespace std;
#define mod 1000000007
#define ll long long
#define maxn 1005
ll f[maxn], g[maxn];
int n;
char cAA, cAB, cBA, cBB;
int main() {
scanf( "%d", &n );
cin >> cAA >> cAB >> cBA >> cBB;
if( n == 2 ) return ! printf( "1\n" );
f[1] = 2, f[0] = g[0] = 1;
for( int i = 2;i <= n;i ++ )
f[i] = ( f[i - 1] + f[i - 2] ) % mod;
for( int i = 1;i <= n;i ++ )
g[i] = ( g[i - 1] << 1 ) % mod;
if( cAB == 'A' ) {
if( cAA =='A' ) printf( "1\n" );
else if( cBA == 'A' ) printf( "%lld\n", f[n - 3] );
else printf( "%lld\n", g[n - 3] );
}
else {
if( cBB == 'B' ) printf( "1\n" );
else if( cBA == 'B' ) printf( "%lld\n", f[n - 3] );
else printf( "%lld\n", g[n - 3] );
}
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define inF freopen("input.txt", "r", stdin);
#define outF freopen("output.txt", "w", stdout);
#define endl '\n'
#define mm(arr) memset(arr, 0, sizeof(arr))
#define F first
#define S second
#define scanArray(a,n) for(int i = 0; i < n; i++){cin >> a[i];}
#define coutArray(a,n) for(int i = 0; i < n; i++){cout << a[i] << " ";}cout << endl;
#define ld long double
#define PI 3.141592653589793238
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
#define int ll
#ifndef LOCAL
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#endif
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << '\n'; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
void solve(){
int n; cin >> n;
map<int, int> cnt;
set<int> s;
for(int i = 0; i < n; i++){
int x; cin >> x;
cnt[x] += 1;
s.insert(x);
}
for(int x : s){
if(cnt[x] != 1){
cout << "No" << endl;
return;
}
}
cout << (sz(s) == n ? "Yes" : "No") << endl;
}
int32_t main(){
FAST
int t = 1;
//cin >> t;
while(t--){
solve();
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n;
cin >> n;
set<int> s;
for (int i = 0; i < n; ++i) {
int x;
cin >> x;
s.insert(x);
}
if (s.size() == n && *s.begin() == 1 && *s.rbegin() == n) {
cout << "Yes\n";
} else {
cout << "No\n";
}
return 0;
}
|
#pragma region head
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
#define test(s) \
if (!(s)) \
cout << "Line " << __LINE__ << ": [" << #s << "] is false" << endl;
#define int long long
typedef long long ll;
#define double long double
typedef double ld;
const int INF = 1001001001001001001ll;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;
const double PI = acos(-1.0);
template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
int len = v.size();
for (int i = 0; i < len; ++i) {
s << v[i];
if (i < len - 1)
s << ' ';
}
return s;
}
template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
int len = vv.size();
for (int i = 0; i < len; ++i) {
s << vv[i];
if (i != len - 1)
s << '\n';
}
return s;
}
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;
}
__attribute__((constructor)) void initial() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
}
#pragma endregion
signed main() {
int N, S, D;
cin >> N >> S >> D;
vector<int> X(N), Y(N);
bool ans = false;
rep(i, N) {
cin >> X[i] >> Y[i];
if (X[i] < S && Y[i] > D)
ans = true;
}
if (ans)
cout << "Yes\n";
else
cout << "No\n";
} | #include <bits/stdc++.h>
using namespace std;
int main()
{
int n,s,d,x,y;
cin>>n>>s>>d;
for(int i=0;i<n;i++)
{
cin>>x>>y;
if(d<y && s>x)
{
cout<<"Yes";
return 0;
}
}
cout<<"No";
return 0;
} |
/*
LANG:C++
PROB:
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <iostream>
// #define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
typedef unsigned long long ui64;
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
const int mod=1000000007;
i64 poww(i64 a, i64 b)
{
a%=mod;
i64 res=1;
while(b)
{
if(b&1)res=res*a%mod;
a=a*a%mod;
b/=2;
}
return res;
}
i64 inv(i64 a)
{
return poww(a,mod-2);
}
void solve()
{
int x;
cin>>x;
x=x%100;
cout<<100-x;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int t=1;
while(t--)
{
solve();
}
return 0;
}
| #include <bits/stdc++.h>
#define ll long long
using namespace std;
namespace IO{
inline char ch(){
static char s[1<<16],*S,*T;
return (S == T)&&(T = (S = s)+
fread(s,1,1<<16,stdin),S == T)?EOF:*S++;
}
template<typename T> void read(T &x){
x = 0; int f(1); char c = ch();
for(;!isdigit(c);c = ch()) if(c == '-') f = -1;
for(;isdigit(c);c = ch()) x = x*10+c-'0';
x *= f;
}
template<typename T,typename... Args>
inline void read(T &x,Args&... args){
read(x); read(args...);
}
template<typename T> void write(T x,char f = '\n'){
if(x < 0) putchar('-'),x = -x;
if(x > 9) write(x/10,'\0');
putchar('0'+x%10);
if(f != '\0') putchar(f);
}
}
using namespace IO;
int main(){
#ifdef LZX_CAI
freopen("test.in","r",stdin);
freopen("test.out","w",stdout);
#endif
int n;
read(n);
write(100-n%100);
return 0;
} |
/*-------------必要なときに使うもの------------------*/
//#define _GLIBCXX_DEBUG
/*#include<atcoder/modint>
#include<atcoder/math>
using namespace atcoder;
using mint=modint1000000007;
using MINT=modint998244353;*/
/*#pragma GCC target("avx")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")*/
/*-------------------end-----------------------------*/
#include<bits/stdc++.h>
using namespace std;
/*---------------------マクロ-------------------------*/
#define int long long
#define rep(i, n) for (int i = 0; i < (long long)(n); i++)
#define stoi stoll
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define debug(x) cout<<#x<<" : "<<x<<endl
#define endl '\n'
/*------------------------end---------------------------*/
/*-----------------------型エイリアス--------------------*/
using ll = long long;
using lint=long long;
using P=pair<long long,long long>;
using vi=vector<long long>;
using vvi=vector<vi>;
using vb=vector<bool>;
using vc=vector<char>;
using vvc=vector<vc>;
using vs=vector<string>;
using vd=vector<double>;
/*------------------------end---------------------------*/
/* ----------------よく使う数字や配列-------------------- */
constexpr long long INF = LLONG_MAX/3;
constexpr long long dx[]={1,0,-1,0},dy[]={0,1,0,-1};
constexpr long long mod = 1e9 + 7;
constexpr long long MOD=998244353;
constexpr long double pi = 3.141592653589793238462643383279;
constexpr double EPS=1e-14;
/* ----------------------end-----------------------------*/
/*---------------------template------------------------*/
template<class T>inline bool chmin(T& a,T b){
if(a>b){a=b;return true;}
return false;
}
template<class T>inline bool chmax(T& a,T b){
if(a<b){a=b;return true;}
return false;
}
template<class T>inline void mainend(T x){cout<<x<<endl;exit(0);}
/*----------------------end-------------------------*/
void Main(){
int N;cin>>N;
vector<int>A(N);rep(i,N)cin>>A[i];
vector<vector<int>>ruiseki_min(N,vector<int>(N,INF));
int MAX=-INF;
rep(i,N){
ruiseki_min[i][i]=A[i];
chmax(MAX,A[i]);
for(int j=i+1;j<N;j++){
ruiseki_min[i][j]=min(ruiseki_min[i][j-1],A[j]);
chmax(MAX,ruiseki_min[i][j]*(j-i+1));
}
}
cout<<MAX<<'\n';
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout<<fixed<<setprecision(16);
Main();
return 0;
} | // #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD_1000000007 = 1000000007LL;
const ll MOD_998244353 = 998244353LL;
// ModInt begin
using ll = long long;
template<ll mod>
struct ModInt {
ll v;
ll mod_pow(ll x, ll n) const {
return (!n) ? 1 : (mod_pow((x*x)%mod,n/2) * ((n&1)?x:1)) % mod;
}
ModInt(ll a = 0) : v((a %= mod) < 0 ? a + mod : a) {}
ModInt operator+ ( const ModInt& b ) const {
return (v + b.v >= mod ? ModInt(v + b.v - mod) : ModInt(v + b.v));
}
ModInt operator- () const {
return ModInt(-v);
}
ModInt operator- ( const ModInt& b ) const {
return (v - b.v < 0 ? ModInt(v - b.v + mod) : ModInt(v - b.v));
}
ModInt operator* ( const ModInt& b ) const {return (v * b.v) % mod;}
ModInt operator/ ( const ModInt& b ) const {return (v * mod_pow(b.v, mod-2)) % mod;}
bool operator== ( const ModInt &b ) const {return v == b.v;}
bool operator!= ( const ModInt &b ) const {return !(*this == b); }
ModInt& operator+= ( const ModInt &b ) {
v += b.v;
if(v >= mod) v -= mod;
return *this;
}
ModInt& operator-= ( const ModInt &b ) {
v -= b.v;
if(v < 0) v += mod;
return *this;
}
ModInt& operator*= ( const ModInt &b ) {
(v *= b.v) %= mod;
return *this;
}
ModInt& operator/= ( const ModInt &b ) {
(v *= mod_pow(b.v, mod-2)) %= mod;
return *this;
}
ModInt pow(ll x) { return ModInt(mod_pow(v, x)); }
// operator int() const { return int(v); }
// operator long long int() const { return v; }
};
template<ll mod>
ModInt<mod> pow(ModInt<mod> n, ll k) {
return ModInt<mod>(n.mod_pow(n.v, k));
}
template<ll mod>
ostream& operator<< (ostream& out, ModInt<mod> a) {return out << a.v;}
template<ll mod>
istream& operator>> (istream& in, ModInt<mod>& a) {
in >> a.v;
return in;
}
// ModInt end
using mint = ModInt<MOD_1000000007>;
mint dp[100010][2], sum[100010][2];
int main() {
int N; scanf("%d", &N);
dp[0][1] = mint(1);
for(int i=0; i<N; i++) {
int A; scanf("%d", &A);
// 場合の数
dp[i+1][0] += dp[i][0] + dp[i][1];
dp[i+1][1] += dp[i][0];
// 和
sum[i+1][0] += sum[i][0] + sum[i][1] + dp[i+1][0] * mint(A);
sum[i+1][1] += sum[i][0] - dp[i+1][1] * mint(A);
// fprintf(stderr, "dp = %lld, %lld, sum = %lld, %lld\n", dp[i+1][0].v, dp[i+1][1].v, sum[i+1][0].v, sum[i+1][1].v);
}
mint ans = sum[N][0] + sum[N][1];
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i, l, r) for (int i = (l); i < (r); i++)
#define max(p, q) ((p) > (q) ? (p) : (q))
#define min(p, q) ((p) < (q) ? (p) : (q))
#define ALL(a) (a).begin(), (a).end()
#define INF ((1LL << 62) - (1LL << 31))
#define MOD 1000000007
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
int main(void) {
std::cin.tie(0);
std::ios::sync_with_stdio(false);
double n;
cin >> n;
double ans = 0;
rep(i, 1, n) { ans += n / (double)(n - i); }
cout << fixed << setprecision(12) << ans << endl;
return 0;
} | #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
int main() {
int n;
cin >> n;
vector<ll> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
sort(a.begin(), a.end());
ll prefix_sum = 0, ans = 0;
for (int i = 0; i < n; ++i) {
ans += a[i] * i - prefix_sum;
prefix_sum += a[i];
}
cout << ans << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define pii pair<int, int>
#define ull unsigned ll
#define f first
#define s second
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
#define SQ(x) (x)*(x)
#define MN(a,b) a = min(a,(__typeof__(a))(b))
#define MX(a,b) a = max(a,(__typeof__(a))(b))
#define pb push_back
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#ifdef BALBIT
#define IOS()
#define bug(...) fprintf(stderr,"#%d (%s) = ",__LINE__,#__VA_ARGS__),_do(__VA_ARGS__);
template<typename T> void _do(T &&x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S &&...y){cerr<<x<<", ";_do(y...);}
#else
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define bug(...)
#endif
const int iinf = 1e9+10;
const ll inf = 1ll<<60;
const ll mod = 1e9+7 ;
void GG(){cout<<"0\n"; exit(0);}
ll mpow(ll a, ll n, ll mo = mod){ // a^n % mod
ll re=1;
while (n>0){
if (n&1) re = re*a %mo;
a = a*a %mo;
n>>=1;
}
return re;
}
ll inv (ll b, ll mo = mod){
if (b==1) return b;
return (mo-mo/b) * inv(mo%b,mo) % mo;
}
const int maxn = 1e6+5;
int a[maxn], b[maxn];
int dp[maxn][2];
int X[2][2];
signed main(){
IOS();
int n; cin>>n;
ll re = 0;
for (int i =0 ; i<n; ++i) {
cin>>a[i];
}vector<int> v;
for (int i = 0; i<n; ++i) {
cin>>b[i];
if ( i & 1) swap(a[i], b[i]);
re += a[i];
v.pb({b[i] - a[i]});
}
sort(ALL(v));
for (int i = 0; i<n/2; ++i) {
re += v[SZ(v) - i - 1];
}
cout<<re<<endl;
}
| #include<bits/stdc++.h>
#define L(i, j, k) for(int i = (j); i <= (k); i++)
#define R(i, j, k) for(int i = (j); i >= (k); i--)
#define ll long long
#define sz(a) ((int) a.size())
#define vi vector<int>
using namespace std;
const int N = 2e5 + 7;
int n, a[N], b[N], r1[N], r2[N];
ll sum;
int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n;
L(i, 1, n) cin >> a[i];
L(i, 1, n) cin >> b[i], a[i] -= b[i], sum += b[i];
n >>= 1;
L(i, 1, n) r1[i] = a[i * 2 - 1];
L(i, 1, n) r2[i] = a[i * 2];
sort(r1 + 1, r1 + n + 1);
sort(r2 + 1, r2 + n + 1);
L(i, 1, n) if(r1[i] + r2[i] > 0) sum += r1[i] + r2[i];
cout << sum << '\n';
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
#define debug(...) cout << "[" << #__VA_ARGS__ << "]: "; cout << to_string(__VA_ARGS__) << endl
template <typename T, size_t N> int SIZE(const T(&t)[N]) { return N; } template<typename T> int SIZE(const T& t) { return t.size(); } string to_string(const string s, int x1 = 0, int x2 = 1e9) { return '"' + ((x1 < s.size()) ? s.substr(x1, x2 - x1 + 1) : "") + '"'; } string to_string(const char* s) { return to_string((string)s); } string to_string(const bool b) { return (b ? "true" : "false"); } string to_string(const char c) { return string({ c }); } template<size_t N> string to_string(const bitset<N>& b, int x1 = 0, int x2 = 1e9) { string t = ""; for (int __iii__ = min(x1, SIZE(b)), __jjj__ = min(x2, SIZE(b) - 1); __iii__ <= __jjj__; ++__iii__) { t += b[__iii__] + '0'; } return '"' + t + '"'; } template <typename A, typename... C> string to_string(const A(&v), int x1 = 0, int x2 = 1e9, C... coords); int l_v_l_v_l = 0, t_a_b_s = 0; template <typename A, typename B> string to_string(const pair<A, B>& p) { l_v_l_v_l++; string res = "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; l_v_l_v_l--; return res; } template <typename A, typename... C> string to_string(const A(&v), int x1, int x2, C... coords) { int rnk = rank<A>::value; string tab(t_a_b_s, ' '); string res = ""; bool first = true; if (l_v_l_v_l == 0) res += nl; res += tab + "["; x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v)); auto l = begin(v); advance(l, x1); auto r = l; advance(r, (x2 - x1) + (x2 < SIZE(v))); for (auto e = l; e != r; e = next(e)) { if (!first) { res += ", "; } first = false; l_v_l_v_l++; if (e != l) { if (rnk > 1) { res += nl; t_a_b_s = l_v_l_v_l; }; } else { t_a_b_s = 0; } res += to_string(*e, coords...); l_v_l_v_l--; } res += "]"; if (l_v_l_v_l == 0) res += nl; return res; } void dbgm() { ; } template<typename Heads, typename... Tails> void dbgm(Heads H, Tails... T) { cout << to_string(H) << " | "; dbgm(T...); }
//COMMENT DEBUG
void solve()
{
int n, x;
cin >> n;
long long sum = 0;
vector<int> a(n + 1);
for (int i = 1; i <= n; i++)
{
cin >> a[i];
//sum+=x;
}
for (int i = 1; i <= n; i++)
{
cin >> x;
sum += (a[i] * x);
}
if (sum == 0) {
cout << "Yes\n";
return;
}
cout << "No\n";
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios::sync_with_stdio(0);
cin.tie(0);
// int t;
// cin >> t;
// while (t--)
// {
solve();
// }
} | #include<bits/stdc++.h>
#define int long long
using namespace std;
int get() {
int x = 0, f = 1; char c = getchar();
while(!isdigit(c)) { if(c == '-') f = -1; c = getchar(); }
while(isdigit(c)) { x = x * 10 + c - '0'; c = getchar(); }
return x * f;
}
const int N = 2e5 + 5;
int n, m, q, a[N], b[N], ans, len, bin[N], tot;
struct Ask {
int T, x, y;
} s[N];
struct BIT {
int sum[N], sum0;
int lowbit(int x) { return x & (-x); }
void add(int x, int v) { while(x <= tot) sum[x] += v, x += lowbit(x); }
int ask(int x) { int r(0); while(x) r += sum[x], x -= lowbit(x); return r + sum0; }
int ask(int l, int r) { if(l > r) return 0; return ask(r) - ask(l - 1); }
} A1, B1, AS, BS;
void add1(int x) {
ans += BS.ask(a[x] + 1, tot) + bin[a[x]] * B1.ask(1, a[x]);
A1.add(a[x], 1), AS.add(a[x], bin[a[x]]);
}
void del1(int x) {
ans -= BS.ask(a[x] + 1, tot) + bin[a[x]] * B1.ask(1, a[x]);
A1.add(a[x], -1), AS.add(a[x], -bin[a[x]]);
}
void add2(int x) {
ans += AS.ask(b[x], tot) + bin[b[x]] * A1.ask(1, b[x] - 1);
B1.add(b[x], 1), BS.add(b[x], bin[b[x]]);
}
void del2(int x) {
ans -= AS.ask(b[x], tot) + bin[b[x]] * A1.ask(1, b[x] - 1);
B1.add(b[x], -1), BS.add(b[x], -bin[b[x]]);
}
signed main() {
n = get(), m = get(), q = get();
for(int i = 1; i <= q; i++) s[i].T = get(), s[i].x = get(), s[i].y = get(), bin[i] = s[i].y;
bin[q + 1] = 0;
sort(bin + 1, bin + 1 + q + 1), tot = unique(bin + 1, bin + 1 + q + 1) - bin - 1;
for(int i = 1; i <= q; i++) s[i].y = lower_bound(bin + 1, bin + 1 + tot, s[i].y) - bin;
for(int i = 1; i <= n; i++) a[i] = 1;
for(int i = 1; i <= m; i++) b[i] = 1;
A1.add(1, n), B1.add(1, m);
for(int i = 1; i <= q; i++) {
int T = s[i].T, x = s[i].x, y = s[i].y;
if(T == 1) del1(x), a[x] = y, add1(x);
else del2(x), b[x] = y, add2(x);
printf("%lld\n", ans);
}
return 0;
}
|
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
const int maxn = 1000010, inf = 1e9 + 233;
struct edge{int too, pre;}e[maxn << 1];
int n, m, tot;
int last[maxn];
char s[maxn];
bool vis[maxn];
inline void add(int x, int y) {e[++tot] = (edge){y, last[x]}; last[x] = tot;}
inline void ins(int x, int y) {add(x, y); add(y, x);}
void dfs(int x)
{
vis[x] = 1;
for (int i = last[x], too; i; i = e[i].pre)
if (!vis[too = e[i].too])
dfs(too);
}
int main()
{
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++)
{
scanf("%s", s + 1);
for (int j = 1; j <= m; j++)
if (s[j] == '#')
ins(i, j + n);
}
ins(1, 1 + n); ins(1, m + n);
ins(n, 1 + n); ins(n, m + n);
int ans1 = -1;
for (int i = 1; i <= n; i++)
if (!vis[i])
dfs(i), ans1++;
memset(vis, 0, sizeof(vis));
int ans2 = -1;
for (int i = n + 1; i <= n + m; i++)
if (!vis[i])
dfs(i), ans2++;
printf("%d\n", min(ans1, ans2));
}
| #include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template<typename T = int> using V = vector<T>;
template<typename T = int> using VV = vector<vector<T>>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
os << '(' << a.first << ',' << a.second << ')';
return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
for (auto x : v) os << x << ' ';
return os;
}
void debug() {
cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
cerr << a;
if (sizeof...(b)) cerr << ", ";
debug(b...);
}
vector<int>g[200005];
int c[20];
int dp[1<<17][17];
vector<int>d[20];
int n;
void bfs(int s){
int k = c[s];
queue<int> q;
q.push(k);
vector<int>a(n, 1<<30);
a[k] = 0;
while(q.size()){
int x = q.front();
q.pop();
for(int t:g[x]){
if(a[t] == 1<<30){
a[t] = a[x] + 1;
q.push(t);
}
}
}
d[s] = a;
}
int main(){
int m;
cin >> n >> m;
while(m--){
int a, b;
cin >> a >> b;
a--;b--;
g[a].push_back(b);
g[b].push_back(a);
}
int k;
cin >> k;
rep(i,k){
cin >> c[i];
c[i]--;
}
rep(i,k)bfs(i);
rep(i,1<<k)rep(j,k)dp[i][j] = 1<<29;
rep(i,k)dp[1<<i][i] = 1;
rep(i,1<<k){
rep(j,k){
if(i >> j & 1){
rep(l,k){
dp[i][j] = min(dp[i][j], dp[i^(1<<j)][l] + d[l][c[j]]);
}
}
}
}
int ans = 1<<29;
rep(j,k){
ans = min(ans, dp[(1<<k)-1][j]);
}
if(ans == 1<<29)ans = -1;
cout << ans << endl;
}
|
#include<iostream>
#include<vector>
#include<algorithm>
#include<chrono>
using namespace std;
int main()
{
int pre_score;
for (int i = 0; i < 1000; i++) {
int si,sj,ti,tj;
cin >> si >> sj >> ti >> tj;
string ans="";
if (si-ti<0) {
for (int j = 0; j < ti-si; j++) ans += 'D';
}
else if (si-ti>0) {
for (int j = 0; j < si-ti; j++) ans += 'U';
}
if (sj-tj<0) {
for (int j = 0; j < tj-sj; j++) ans += 'R';
}
else if (sj-tj>0) {
for (int j = 0; j < sj-tj; j++) ans += 'L';
}
cout << ans << endl;
if (i==999) return 0;
cin >> pre_score;
}
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define pi 3.14159265359
#define all(i) i.begin(),i.end()
using namespace std;
const long long INF=1e9+7;
const string alp="abcdefghijklmnopqrstuvwxyz"; //26
const string ALP="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
//const ll MOD=998244353LL;
//const ll MOD=1777777777LL;
int main() {
long double sx,sy,gx,gy;
cin>>sx>>sy>>gx>>gy;
gy=-gy;
long double k=(gx-sx)/(gy-sy);
long double ans=sx-k*sy;
cout<<fixed<<setprecision(30)<<ans<<endl;
} |
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <bits/stdc++.h>
using namespace std;
#define lson 2*i
#define rson 2*i+1
#define LS l,mid,lson
#define RS mid+1,r,rson
#define UP(i,x,y) for(i=x;i<=y;i++)
#define DOWN(i,x,y) for(i=x;i>=y;i--)
#define MEM(a,x) memset(a,x,sizeof(a))
#define W(a) while(a)
#define gcd(a,b) __gcd(a,b)
#define ll long long
#define MAX 1000005
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define EXP 1e-8
#define lowbit(x) (x&-x)
ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}
void prt(vector<ll> &A) {
sort(A.begin(), A.end());
cout << A.size() << ' '; for (int i = 0; i < A.size(); ++i) cout << A[i] << ' ';
cout << endl;
}
int main () {
int n, t; cin >> n;
vector<int> a(n);
for (int i = 0; i < n; ++i)
cin >> a[i], a[i] %= 200;
unordered_map<int, vector<ll>> pos;
vector<ll> js, A, B;
js.push_back(-1);
bool flag = false;
for (int i = 0; i < a.size(); ++i) {
vector<ll> tmpJs = js;
for (auto &j : js) {
ll newJ = (max(j, 0ll) + a[i]) % 200;
auto prev = pos[j];
prev.push_back(i+1);
if (pos[newJ].size() == 0)
pos[newJ] = prev, tmpJs.push_back(newJ);
else {
A = pos[newJ], B = prev;
flag = true;
break;
}
}
if (flag) break;
js = tmpJs;
}
if (flag)
cout << "Yes"<< endl, prt(A), prt(B);
else
cout << "No" << endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define li long long int
#define rep(i,to) for(li i=0;i<((li)(to));i++)
#define repp(i,start,to) for(li i=(li)(start);i<((li)(to));i++)
#define pb push_back
#define sz(v) ((li)(v).size())
#define bgn(v) ((v).begin())
#define eend(v) ((v).end())
#define allof(v) (v).begin(), (v).end()
#define dodp(v,n) memset(v,(li)n,sizeof(v))
#define bit(n) (1ll<<(li)(n))
#define mp(a,b) make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;
#define INF bit(60)
#define DBGP 1
#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b) idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c) idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d) idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e) idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f) idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g) idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h) idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i) idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j) idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v) for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x) idp p2((x).F, (x).S)
#define dump(x,n) idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n) idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x) idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x) idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}
#define read2d(a,w,h) rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h) rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}
typedef pair<li, li> PI;
li n;
li x[111];
li y[111];
inline bool check(li i, li j, li k){
li dx1 = x[j]-x[i];
li dy1 = y[j]-y[i];
li dx2 = x[k]-x[i];
li dy2 = y[k]-y[i];
return (dx1*dy2 == dx2*dy1);
}
int main() {
cin>>n;
rin{
cin>>x[i]>>y[i];
}
rin{
repp(j,i+1,n){
repp(k,j+1,n){
if(check(i,j,k)){
puts("Yes");
return 0;
}
}
}
}
puts("No");
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
int main () {
int n;
string s;
cin>>s;
int f=0;
for (int i=0;i<s.size();i++) {
if (i%2==0&&s[i]>='a'&&s[i]<='z') continue;
if (i%2==1&&s[i]>='A'&&s[i]<='Z') continue;
f=1;
}
if (f)
printf("No\n");
else
printf("Yes\n");
} | #include <bits/stdc++.h>
using namespace std;
int main(){
int L;
cin>>L;
long long ans =1;
for(int i=1;i<=11;i++){
ans*=L-i;
ans/=i;
}
cout<<ans<<endl;
}
|
#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 n,m;
string s[15];
int sz;
bool not_front[10];
ll res=0;
vector<int> VV;
void cal(){
vector<int> v=VV;
do{
bool ok=true;
for(int i=0;i<m;i++){
if(v[i]==0 and !not_front[i])ok=false;
}
if(!ok)continue;
int k=0;
for(int j=0;j<sz;j++){
int sum=k/10;
for(int i=0;i<n-1;i++){
if((int)s[i].size()>j){
sum+=v[s[i][j]-'A'];
}
}
if(sum>0 and (int)(s[n-1].size())<=j){
ok=false; break;
}
if(v[s[n-1][j]-'A']!=sum%10){
ok=false; break;
}
k=sum;
}
if(ok and k/10==0){
for(int i=0;i<n;i++){
reverse(s[i].begin(), s[i].end());
for(int j=0;j<s[i].size();j++){
cout << v[s[i][j]-'A'];
}
cout << endl;
// cout << s[i] << endl;
}
exit(0);
}
}while(next_permutation(v.begin(), v.end()));
}
void solve(int sz,int cur){
if(sz==m){
cal(); return;
}
if(cur==10)return;
VV.push_back(cur);
solve(sz+1,cur+1);
VV.pop_back();
solve(sz,cur+1);
}
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
n=3;
vector<char> V;
for(int i=0;i<n;i++){
cin >> s[i];
for(int j=0;j<s[i].size();j++){
s[i][j]+=(+'A'-'a');
}
for(char c:s[i]){
V.push_back(c);
}
}
sort(V.begin(), V.end());
V.erase(unique(V.begin(), V.end()),V.end());
for(int i=0;i<n;i++){
for(int j=0;j<s[i].size();j++){
s[i][j]='A'+(lower_bound(V.begin(), V.end(),s[i][j])-V.begin());
}
}
// leading-0対策
m=V.size();
for(int i=0;i<m;i++){
not_front[i]=true;
}
sz=0;
for(int i=0;i<n;i++){
if((int)s[i].size())not_front[s[i][0]-'A']=false;
reverse(s[i].begin(), s[i].end());
sz=max(sz,(int)(s[i].size()));
}
// ここから 書く
res=0;
solve(0,0);
cout << "UNSOLVABLE" << endl;
} | //#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii; typedef vector<ll> VL; const int MD = 1e9 +7; const ll INF = 1e18;
void dbg(){cerr<<"\n";} template <class F,class ...S> void dbg(const F& f, const S&...s){cerr <<f <<": "; dbg(s...);}
//using mint = atcoder::modint998244353;
bool f(string s1, string s2, string s3){
VI cv(128, -1); int ct=0;
for(auto ch: (s1+s2+s3)) if(cv[ch]==-1) cv[ch] = ct++;
if(ct>10){/*cerr<<s1+" "+s2+" "+s3+" over 11!!! \n";*/return false;}
vector<VI> v(3);
for(auto ch: s1) v[0].push_back(cv[ch]);
for(auto ch: s2) v[1].push_back(cv[ch]);
for(auto ch: s3) v[2].push_back(cv[ch]);
//for(auto xl: v){for(auto x :xl) cerr<<x<<" ";dbg();}
rep(msk, 1<<10){ // ncr(10, ct) * ct! <= 10!
VI seq;
if(__builtin_popcount(msk) != ct) continue;
rep(i, 10) if(msk>>i &1) seq.push_back(i);
//for(auto x :seq) cerr<<x<<" "; dbg();
do {
bool ok =1;
VL nv(3);
rep(i, 3){
if(seq[v[i][0]]==0){ ok=0; break;} //先頭0 対策
for(auto ch: v[i]) nv[i] = nv[i] *10 + seq[ch];
}
if(ok && nv[0] + nv[1] == nv[2]){
cout << nv[0] <<"\n";
cout << nv[1] <<"\n";
cout << nv[2] <<"\n";
//for(auto x :seq) cerr<<x<<" "; dbg("OK");
return true;
//if(sz(cnd) > 1) return false; //複数解 認めない場合
}
} while ( next_permutation(all(seq)) );
}
return false;
}
int main()
{
cin.tie(0); ios_base::sync_with_stdio(false);
vector<string> v(3);
rep(i, 3) cin >>v[i];
auto zz= f(v[0], v[1],v[2]);
if(!zz) cout << "UNSOLVABLE" <<"\n";
return 0;
}
|
#include <iostream>
#include <vector>
using namespace std;
#define int long long
signed main(){
int N; cin >> N;
vector<int> W(N);
int S = 0;
for (int i=0; i<N; i++){
cin >> W[i];
S += W[i];
}
if (S % 2 != 0){
cout << 0;
}
else{
int s_ = S/2; int n_ = N/2;
vector<vector<int>> states;
for (int i=0; i<n_+1; i++){
vector<int> row(s_+1);
states.push_back(row);
}
states[0][0] = 1;
for (auto w: W){
for (int y=n_; y>0; y--){
for (int x=0; x<s_+1-w; x++){
states[y][x+w] = (states[y][x+w] + states[y-1][x]) % 998244353;
}
}
}
vector<int> fact(1,1);
for (int i=1; i<N+1; i++){
fact.push_back( (fact[i-1] * i) % 998244353 );
}
int total = 0;
for (int y=1; y<n_+1; y++){
total = (total + (fact[y] * fact[N-y] % 998244353) * states[y][s_]) % 998244353;
}
total = (2 * total) % 998244353;
if (N % 2 == 0){
total = total - (fact[n_] * fact[n_] % 998244353) * states[n_][s_] % 998244353;
}
total = (total + 998244353) % 998244353;
cout << total;
}
} | #include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define rng(i, a, b) for (int i = int(a); i < int(b); ++i)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); --i)
#define per(i, b) gnr(i, 0, b)
#define all(obj) begin(obj), end(obj)
#define allr(obj) rbegin(obj), rend(obj)
#define cinv(a) rep(i, (int)a.size()) cin >> a[i]
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<Pi> vp;
typedef vector<vp> vvp;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, 1, 0, -1};
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll LINF = 1e18;
const long double eps = 1e-10;
const char nl = '\n';
ll power(ll a, ll b) { return b ? power(a * a % MOD, b / 2) * (b % 2 ? a : 1) % MOD : 1; }
ll nCk(int n, int k)
{
ll x = 1, y = 1;
for (int i = 1; i <= k; ++i)
{
x = x * (n - i + 1) % MOD;
y = y * i % MOD;
}
return x * power(y, MOD - 2) % MOD;
}
struct UF
{
vi d;
UF(int n) : d(n, -1) {}
int root(int x)
{
if (d[x] < 0)
return x;
return d[x] = root(d[x]);
}
bool unite(int x, int y)
{
x = root(x); y = root(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 root(x) == root(y); }
int size(int x) { return -d[root(x)]; }
};
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout<<fixed<<setprecision(20);
int n; cin >> n;
vi x(n), y(n);
rep(i, n) cin >> x[i] >> y[i];
int x_min1 = INF, x_min2 = INF, y_min1 = INF, y_min2 = INF;
int x_max1 = 0, x_max2 = 0, y_max1 = 0, y_max2 = 0;
int index_x_max1, index_x_min1, index_y_max1, index_y_min1;
auto two_max = [&](int &max1, int &max2, int &index, vi &vec) -> void
{
rep(i, n)
{
if (max1 < vec[i])
{
max2 = max1;
max1 = vec[i];
index = i;
}
else if (max2 < vec[i])
{
max2 = vec[i];
}
}
};
two_max(x_max1, x_max2, index_x_max1, x);
two_max(y_max1, y_max2, index_y_max1, y);
auto two_min = [&](int &min1, int &min2, int &index, vi &vec) -> void
{
rep(i, n)
{
if (min1 > vec[i])
{
min2 = min1;
min1 = vec[i];
index = i;
}
else if (min2 > vec[i])
{
min2 = vec[i];
}
}
};
two_min(x_min1, x_min2, index_x_min1, x);
two_min(y_min1, y_min2, index_y_min1, y);
if (index_x_max1 == index_y_max1 && index_x_min1 == index_y_min1)
cout << max(max(x_max1 - x_min2, x_max2 - x_min1), max(y_max1 - y_min2, y_max2 - y_min1)) << nl;
else
{
vi ans;
ans.pb(x_max1 - x_min1);
ans.pb(y_max1 - y_min1);
ans.pb(x_max1 - x_min2);
ans.pb(y_max1 - y_min2);
ans.pb(x_max2 - x_min1);
ans.pb(y_max2 - y_min1);
sort(allr(ans));
cout << ans[1] << nl;
}
}
|
#include <bits/stdc++.h>
#define ALL(x) (x).begin(),(x).end()
#define PB push_back
#define MP make_pair
#define Mod 998244353
#define MOD 1000000007
using namespace std;
using lint = long long;
using vi = vector<lint>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<lint, lint>;
lint modpow(lint a, lint n, lint m = MOD){
lint ans = 1;
while(n>0){
if(n%2==1) ans *= a;
ans %= m;
a *= a;
a %= m;
n /= 2;
}
return ans;
}
lint inv(lint a, lint m = MOD){
return modpow(a, m-2, m);
}
lint gcd(lint a, lint b){
if (a%b == 0) return(b);
else return(gcd(b, a%b));
}
//////////////////////
////////////////////
// cout << fixed << setprecision(12);
int main(){
lint n; cin>>n;
lint ans = 0;
for(lint i=1; i<=n; i++){
bool ok = true;
lint tmp = i;
while(tmp>0){
if(tmp%10==7){
ok = false;
break;
}
tmp/=10;
}
lint tmp2 = i;
while(tmp2>0){
if(tmp2%8==7){
// cout << i << endl;
ok = false;
break;
}
tmp2/=8;
}
if(ok){
// cout << i << endl;
ans++;
}
}
cout << ans << endl;
}
| #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <deque>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <float.h>
using namespace std;
using ll = long long;
#define canDbg 0
#define dbg(x) if(canDbg) cout << x << endl;
#define rep(n, e) for(ll n = 0;n < e;n++)
int main()
{
int N;
cin >> N;
stringstream ss;
int sum = 0;
for (int n = 1; n <= N; n++)
{
string d = to_string(n);
stringstream ss;
ss << oct << n;
string o = ss.str();
//cout << "dec; " << d << endl;
//cout << "oct; " << o << endl;
if ((d.find('7') == string::npos) && (o.find('7') == string::npos))
{
sum++;
}
}
cout << sum;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
template<class T,class U>
inline bool chmax(T &a,U b){
if(a<b){
a=b;
return true;
}
return false;
}
template<class T,class U>
inline bool chmin(T &a,U b){
if(a>b){
a=b;
return true;
}
return false;
}
constexpr int INF=1000000000;
constexpr ll llINF=3000000000000000000;
constexpr int mod=1000000007;
constexpr double eps=1e-8;
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int Random(int mi,int ma){
random_device rnd;
mt19937 mt(rnd());//32bit
//[mi,ma]
uniform_int_distribution<int>engine(mi,ma);
return engine(mt);
}
/*
vector<vector<ll>>C,sC;
void init_comb(int n,int m){
C.resize(n+1,vector<ll>(m+1,0));
sC.resize(n+1,vector<ll>(m+1,0));
C[0][0]=1;
for(int i=1;i<=n;i++){
C[i][0]=1;
for(int j=1;j<=m;j++){
C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
}
}
rep(i,n+1){
rep(j,m){
sC[i][j+1]=(sC[i][j]+C[i][j])%mod;
}
}
}*/
ll gcd(ll a,ll b){
while(a%b){
a%=b;
swap(a,b);
}
return b;
}
ll lcm(ll a,ll b){
return a/gcd(a,b)*b;
}
bool isprime(int a){
if(a==1)return false;
for(int i=2;i*i<=a;i++){
if(a%i==0)return false;
}
return true;
}
vector<int>primes;
void init_prime(int n){
primes.push_back(2);
for(int i=3;i<=n;i+=2){
bool f=true;
for(int j:primes){
if(j*j>i)break;
if(i%j==0){
f=false;
break;
}
}
if(f)primes.push_back(i);
}
}
ll modpow(ll a,ll b){
ll res=1;
while(b){
if(b&1){
res*=a;
res%=mod;
}
a*=a;
a%=mod;
b>>=1;
}
return res;
}
vector<ll>inv,fact,factinv;
void init_fact(int n){
inv.resize(n+1);
fact.resize(n+1);
factinv.resize(n+1);
inv[0]=0;
inv[1]=1;
fact[0]=1;
factinv[0]=1;
for(ll i=1;i<=n;i++){
if(i>=2)inv[i]=mod-((mod/i)*inv[mod%i]%mod);
fact[i]=(fact[i-1]*i)%mod;
factinv[i]=factinv[i-1]*inv[i]%mod;
}
}
ll _inv(ll a,ll m=mod){
//gcd(a,m) must be 1
ll b=m,u=1,v=0;
while(b){
ll t=a/b;
a-=t*b;swap(a,b);
u-=t*v;swap(u,v);
}
u%=m;
if(u<0)u+=m;
return u;
}
ll comb(int a,int b){
if(a<b)return 0;
if(a<0)return 0;
return fact[a]*factinv[a-b]%mod*factinv[b]%mod;
}
ll multicomb(int a,int b){
return comb(a+b-1,b);
}
int n,m;
vector<int>g[1010][26];
int dp[1010][1010];
#define P pair<int,int>
#define PP pair<int,P>
void solve(){
cin>>n>>m;
priority_queue<PP,vector<PP>,greater<PP>>q;
rep(i,n)rep(j,n)dp[i][j]=INF;
rep(i,n){
dp[i][i]=0;
q.push({0,{i,i}});
}
rep(i,m){
int a,b;
char c;
cin>>a>>b>>c;
a--,b--;
g[a][c-'a'].push_back(b);
g[b][c-'a'].push_back(a);
if(a!=b){
dp[a][b]=dp[b][a]=1;
q.push({1,{a,b}});
q.push({1,{b,a}});
}
}
while(!q.empty()){
PP p=q.top();
q.pop();
int l=p.second.first,r=p.second.second;
if(dp[l][r]!=p.first)continue;
rep(k,26){
for(int a:g[l][k]){
for(int b:g[r][k]){
if(chmin(dp[a][b],p.first+2)){
q.push({dp[a][b],{a,b}});
}
}
}
}
}
cout<<(dp[0][n-1]==INF?-1:dp[0][n-1])<<endl;
}
int main(){
cin.tie(0);ios::sync_with_stdio(false);
//int t;cin>>t;while(t--)
solve();
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const int kmax = 1003;
struct Node {
int x, y;
} q[kmax * kmax];
struct O {
int to;
char c;
} o[kmax];
int ans = 1e9;
bool l[kmax][kmax];
int n, m, d[kmax][kmax], h = 1, t;
vector<O> p[kmax];
char c;
void E(int x, int y, int z) {
if (d[x][y]) {
return;
}
d[x][y] = d[y][x] = z;
q[++t] = {x, y};
if (x == y) {
ans = min(ans, z);
} else if (l[x][y]) {
ans = min(ans, z + 1);
}
}
int main() {
cin >> n >> m;
for (int i = 1, x, y; i <= m; i++) {
cin >> x >> y >> c;
p[x].push_back({y, c});
p[y].push_back({x, c});
l[x][y] = l[y][x] = 1;
}
for (E(1, n, 1); h <= t; h++) {
for (int i = 0; i < p[q[h].x].size(); i++) {
for (int j = 0; j < p[q[h].y].size(); j++) {
if (p[q[h].x][i].c == p[q[h].y][j].c) {
E(p[q[h].x][i].to, p[q[h].y][j].to, d[q[h].x][q[h].y] + 2);
}
}
}
}
cout << (ans == 1e9 ? -1 : ans - 1);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}
int main2() {
int N = nextLong();
double ans = 0;
for (int i = 1; i < N; i++) {
ans += (double)N / i;
}
printf("%.10f\n", ans);
return 0;
}
int main() {
#ifdef LOCAL
for (;!cin.eof();cin>>ws)
#endif
main2();
return 0;
} | #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>>;
#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)
#define line cout << "-----------------------------\n"
#define stop system("pause")
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>inline istream& operator>>(istream& is, deque<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]); }
int main() {
init();
int n, m; cin >> n >> m;
VL h(n), w(m); cin >> h >> w;
SORT(h);
VL l(n), r(n);
for (int i = 0; i + 1 < n; i += 2)l[i] = h[i + 1] - h[i];
for (int i = n - 1; 0 <= i - 1; i -= 2)r[i] = h[i] - h[i - 1];
FOR(i, 1, n)l[i] += l[i - 1];
rFOR(i, 0, n - 1)r[i] += r[i + 1];
ll ans = LLINF;
FOR(j, 0, m) {
int i = lower_bound(all(h), w[j]) - h.begin();
ll res = 0;
if (i & 1) {
res = (0 <= i - 2 ? l[i - 2] : 0) + w[j] - h[i - 1] + (i < n ? r[i] : 0);
}
else {
res = (0 <= i - 1 ? l[i - 1] : 0) + h[i] - w[j] + (i + 1 < n ? r[i + 1] : 0);
}
chmin(ans, res);
}
print(ans);
return 0;
} |
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define ina(n,a) cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev coyhhhhhhyoc
#define next sdNNNmNNNNNNNmds
#define y0 hNNNNy_yNNNNNN_sNh
#define y1 mNNNNNdtdNNNNNNtsNNm
#define yn mNNNNNNNNy___smNNNms
#define tm oooooosyysooooot
#define read tyhyt
#define rank ytmNmo
#define index yyy
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#define rall(x,a) for(auto x : a)
#define MOD 1000000007
#define endl "\n"
typedef long long ll;
using namespace std;
const int N = 1111;
int a[N], b[N];
int n;
int solve() {
cin >> n;
rep(i, 1, n) {
cin >> a[i] >> b[i];
}
int ans = 1e9;
rep(i, 1, n) {
rep(j, 1, n) {
int cur = i == j ? a[i] + b[j] : max(a[i], b[j]);
ans = min(ans, cur);
}
}
cout << ans << endl;
return 0;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int t = 1;
while(t--) {
solve();
}
return 0;
}
| //
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
typedef long long ll;
typedef long double ld;
const ll mod = 1e9 + 7;
int main ()
{
ios_base::sync_with_stdio (0); cin.tie (0); cout.tie (0);
ll n, m, q;
cin >> n >> m >> q;
pair<ll, ll> a[n], b[m];
for (auto& x : a) cin >> x.S >> x.F;
for (ll i = 0; i < m; ++i)
{
cin >> b[i].F;
b[i].S = i + 1;
}
sort (a, a + n, greater<pair<ll, ll>> ());
sort (b, b + m);
while (q--)
{
ll l, r, v = 0;
cin >> l >> r;
unordered_set<ll> s;
for (ll i = 0; i < n; ++i)
{
for (ll j = 0; j < m; ++j)
{
if (s.count (b[j].S) || (b[j].S >= l && b[j].S <= r)) continue;
if (b[j].F >= a[i].S)
{
v += a[i].F;
s.insert (b[j].S);
break;
}
}
}
cout << v << "\n";
}
}
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define forin(in) for(ll i=0; i<(ll)in.size(); i++) cin>>in[i]
#define forout(out) for(ll i=0; i<(ll)out.size(); i++) cout<<out[i]<<" "
#define rep(i, n) for(ll i=0; i<(n); i++)
#define rep_up(i, a, n) for (ll i = a; i < n; ++i)
#define rep_down(i, a, n) for (ll i = a; i >= n; --i)
#define P pair<ll, ll>
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 all(v) v.begin(), v.end()
#define fi first
#define se second
#define vvvll vector<vector<vector<ll>>>
#define vvll vector<vector<ll>>
#define vll vector<ll>
#define pqll priority_queue<ll>
#define pqllg priority_queue<ll, vector<ll>, greater<ll>>
constexpr ll INF = (1ll << 60);
constexpr ll mod = 1000000007;
int main() {
long double R, X, Y; cin >> R >> X >> Y;
long double d = sqrt(X*X+Y*Y);
if(d == R) cout << 1 << endl;
else if(d <= 2*R) cout << 2 << endl;
else cout << ceil(d/R) << endl;
} | #include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
int main(){
double r,x,y;
ll hosu = 0;
cin >> r >> x >> y;
if(sqrt(x * x + y * y) / r < 1){
hosu = 2;
}
else{
hosu = ceil(sqrt(x * x + y * y) / r);
}
cout << hosu;
} |
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <tuple>
#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__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#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, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << '\n'; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n;
cin, n;
ll ans = 0;
REP(i, 0, n) {
ll a, b;
cin, a, b;
ans += b * (b + 1) / 2 - a * (a - 1) / 2;
}
print(ans);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef const int ci;
typedef vector<int> vi;
typedef pair<ll, ll> pll;
#define INF (2e12)
#define fori(i, s, e) for(int i = s; i < ((int)e); ++i)
#define forj(i, s, e) for(int i = s; i >= ((int)e); --i)
#define all(s) (s).begin(), (s).end()
#define sz(s) ((int)s.size())
template <class T> void minify(T &a, const T &b) {if(a > b) a = b;}
template <class T> void maxify(T &a, const T &b) {if(a < b) a = b;}
void python() {ios_base::sync_with_stdio(false); cin.tie(0);}
// Code...
void solve() {
ll n;
ll sum = 0;
cin >> n;
fori(i, 0, n) {
ll a, b;
cin >> a >> b;
sum += (a + b)*(b - a + 1)/2;
}
cout << sum << endl;
}
int main() {
python();
solve();
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
namespace mymtx{
const int dim = 3;
template<class T> array<array<T,dim>,dim> mult(array<array<T,dim>,dim> a, array<array<T,dim>,dim> b){
array<array<T,dim>,dim> ret{};
for(int i=0;i<dim;i++) for(int j=0;j<dim;j++) for(int k=0;k<dim;k++)
ret[i][j] += a[i][k]*b[k][j];
return ret;
}
template<class T> array<T,dim> mult(array<array<T,dim>,dim> a, array<T,dim> b){
array<T,dim> ret{};
for(int i=0;i<dim;i++) for(int k=0;k<dim;k++)
ret[i] += a[i][k]*b[k];
return ret;
}
}
int main(){
std::cin.tie(nullptr);
ios::sync_with_stdio(false);
int64_t n; cin >> n;
vector<array<int64_t,3>> x(n);
for(int64_t i=0;i<n;i++){
cin >> x[i][0] >> x[i][1];
x[i][2] = 1;
}
int64_t m; cin >> m;
vector<array<array<int64_t,3>,3>> mtx(m+1);
mtx[0] = {{ {1,0,0}, {0,1,0}, {0,0,1} }};
for(int64_t i=1;i<=m;i++){
int64_t op[2]={0,0};
cin >> op[0];
array<array<int64_t,3>,3> tmp{{ {0,0,0},{0,0,0},{0,0,1} }};
if(op[0]==1){
tmp[0][1]=1; tmp[1][0]=-1;
}else if(op[0]==2){
tmp[0][1]=-1; tmp[1][0]=1;
}else if(op[0]==3){
cin >> op[1];
tmp[0][0]=-1; tmp[0][2]=2*op[1]; tmp[1][1]=1;
}else if(op[0]==4){
cin >> op[1];
tmp[0][0]=1; tmp[1][1]=-1; tmp[1][2]=2*op[1];
}
mtx[i] = mymtx::mult( tmp ,mtx[i-1]);
}
int64_t q; cin >> q;
array<int64_t,3> ans{0,0,0};
for(int64_t i=0,a,b;i<q;i++){
cin >> a >> b;
ans = mymtx::mult(mtx[a],x[b-1]);
cout << ans[0] << " " << ans[1] << "\n";
}
return 0;
} | //yukicoder@cpp14
//coder:luckYrat(twitter:@luckYrat_)
//競技プログラミングから逃げるな
//https://www.youtube.com/watch?v=z_B9iJ8r4ic
//せんげん!
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <cctype>
#include <utility>
#include <climits>
//なまえくーかん!
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
//てーすう!
const int mod = 1000000007;
const int inf = (1<<30)-1;
const ll linf = (1LL<<62LL)-1;
const double EPS = (1e-10);
//でふぁいん!
#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)
//みじかく!
#define pb push_back
#define mkp make_pair
#define fir first
#define scn second
#define ednl endl
//いぇすのー!
#define YesNo(a) (a?"Yes":"No")
#define YESNO(a) (a?"YES":"NO")
#define yesno(a) (a?"yes":"no")
//きんぼーnほーこー!!
P ar4[4] = {mkp(0,1),mkp(0,-1),mkp(1,0),mkp(-1,0)};
P ar8[8] = {mkp(-1,-1),mkp(-1,0),mkp(-1,1),mkp(0,-1),mkp(0,1),mkp(1,-1),mkp(1,0),mkp(1,1)};
/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる
計算量は変わらないが楽できるシリーズ
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる
*/
int pc[100001];
int neko[100001];
bool lck[100001];
vector<int> ed[100001];
vector<int> ans;
struct dta{
int n,ss[100001];
};
void dfs(int n,int* ss){
for(int i = 0; ed[n].size() > i; i++){
if(!lck[ed[n][i]]){
//cout << ed[n][i] << endl;
lck[ed[n][i]] = true;
if(!ss[pc[ed[n][i]]]){
ans.push_back(ed[n][i]);
}
ss[pc[ed[n][i]]]++;
dfs(ed[n][i],ss);
ss[pc[ed[n][i]]]--;
}
}
}
__attribute__((constructor))
void initial() {
cin.tie(0);
ios::sync_with_stdio(false);
}
int main(){
int n;cin>>n;
for(int i = 0; n > i; i++){
cin>>pc[i];
}
for(int i = 0; n-1 > i; i++){
int a,b;cin>>a>>b;a--;b--;
ed[a].push_back(b);
ed[b].push_back(a);
}
ans.push_back(0);
neko[pc[0]]++;
lck[0] = true;
dfs(0,neko);
sort(ans.begin(),ans.end());
for(int i = 0; ans.size() > i; i++){
cout << ans[i]+1 << endl;
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(const string& s) {
return '"' + s + '"';
}
string to_string(const char* s) {
return to_string((string) s);
}
string to_string(bool b) {
return (b ? "true" : "false");
}
string to_string(vector<bool> v) {
bool first = true;
string res = "{";
for (int i = 0; i < static_cast<int>(v.size()); i++) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(v[i]);
}
res += "}";
return res;
}
template <size_t N>
string to_string(bitset<N> v) {
string res = "";
for (size_t i = 0; i < N; i++) {
res += static_cast<char>('0' + v[i]);
}
return res;
}
template <typename A>
string to_string(A v) {
bool first = true;
string res = "{";
for (const auto &x : v) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(x);
}
res += "}";
return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
#define fi first
#define se second
#define pb push_back
#define mod(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,a,b) for(int i = a; i < b; i++)
#define forr(i,a,b) for(int i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
const int mod = 1e9+7;
int sum(int a, int b){return (a+b) % mod;}
int sub(int a, int b){return (a + mod - b) % mod;}
int mul(int a, int b){return (1ll * a * b) % mod;}
int power(int a,int b){
int res = 1;
while(b){
if(b&1)res = mul(res,a);
b >>= 1;
a = mul(a,a);
}
return res;
}
const int maxn = 2e5+10;
int N,enCamino[maxn],res[maxn];
vi graph[maxn];
void dfs(int u,int p,int d,int &maxi,int &p1){
if(d > maxi){
maxi = d;
p1 = u;
}
for(auto &v : graph[u]){
if(v == p)continue;
dfs(v,u,d+1,maxi,p1);
}
}
int buscaCamino(int u,int p,int fin,vi &path){
if(u == fin){
path.pb(u);
return 1;
}
for(auto &v : graph[u]){
if(v == p)continue;
if(buscaCamino(v,u,fin,path)){
path.pb(u);
return 1;
}
}
return 0;
}
void dfs2(int u,int p,int &idx){
res[u] = idx++;
for(auto &v : graph[u]){
if(enCamino[v])continue;
if(v == p)continue;
dfs2(v,u,idx);
}
idx++;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> N;
forn(i,0,N-1){
int u,v; cin >> u >> v; u--; v--;
graph[u].pb(v);
graph[v].pb(u);
}
int p1 = -1,lenDiameter = -1,p2 = -1;
dfs(0,0,0,lenDiameter,p1);
lenDiameter = -1;
dfs(p1,p1,0,lenDiameter,p2);
debug(p1+1,p2+1);
vi camino;
buscaCamino(p1,p1,p2,camino);
reverse(all(camino));
for(auto &u : camino)enCamino[u] = 1;
int idx = 1;
for(auto &u : camino){
res[u] = idx++;
for(auto &v : graph[u]){
if(enCamino[v])continue;
dfs2(v,v,idx);
}
}
debug(camino);
forn(i,0,N)cout << res[i] << ' ';
cout << '\n';
return 0;
}
/*
__builtin_mul_overflow(x,y,&x)
-fsplit-stack
*/
| #include "bits/stdc++.h"
using namespace std;
#define int long long
#define eb emplace_back
#define mp make_pair
typedef pair<int,int> pii;
#define f first
#define s second
#define min(a,b) ((a<b)?a:b)
//const int mod=1000000007;
bool debug=0;
vector<int> adjl[200005];
int dis[200005],prevv[200005];
pii fur;
void furth(int node,int prev=-1){
prevv[node]=prev;
fur=max(fur,mp(dis[node],node));
//if(debug)cout<<dis[node]<<' '<<node<<"kool\n";
for(int x:adjl[node]){
if(x==prev)continue;
dis[x]=dis[node]+1;
furth(x,node);
}
}
bool mark[200005];
int num[200005],cur=1;
void dfs(int node,int prev=-1){
//if(debug)cout<<"search "<<node<<'\n';
num[node]=cur++;
for(int x:adjl[node]){
if(x==prev)continue;
if(mark[x])continue;
dfs(x,node);
}
if(mark[node])
for(int x:adjl[node]){
if(x==prev)continue;
if(mark[x]){
dfs(x,node);break;
}
}
cur++;
}
int32_t main(){
ios_base::sync_with_stdio(false);cin.tie(0);
int n,a,b;
cin>>n;
for(int i=1;i<n;i++){
cin>>a>>b;
adjl[a].push_back(b);
adjl[b].push_back(a);
}
fur=mp(-1,-1);
dis[1]=1;furth(1);
a=fur.s;
fur=mp(-1,-1);
dis[a]=1;furth(a);
b=fur.s;
do{
mark[b]=true;
b=prevv[b];
}while(b!=-1);
//fur.f=-1;
//dis[fur.s]=1;furth(fur.s);
if(debug)cout<<"ENDPoint "<<fur.s<<'\n';
dfs(a);//one end of diameter...
for(int i=1;i<=n;i++){
cout<<num[i];
if(i<n)cout<<' ';
else cout<<'\n';
}
return 0;
}
/*
*/
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
int n;
ll t;
cin >> n >> t;
ll a[n];
for (int i = 0; i < n; i++) cin >> a[i];
vector<ll> sum1, sum2;
ll sum;
for (ll bit = ((ll)1 << (n / 2)) - 1; bit >= 0; bit--) {
sum = 0;
for (int i = 0; bit >> i; i++) {
sum += a[i] * ((bit >> i) & 1);
if (sum > t) break;
}
if (sum == t) {
cout << t;
return 0;
} else if (sum <= t) sum1.push_back(sum);
}
for (ll bit = ((ll)1 << (n - n / 2)) - 1; bit >= 0; bit--) {
sum = 0;
for (int i = 0; bit >> i; i++) {
sum += a[i + n / 2] * ((bit >> i) & 1);
if (sum > t) break;
}
if (sum == t) {
cout << t;
return 0;
} else if (sum <= t) sum2.push_back(sum);
}
sort(sum1.begin(), sum1.end());
sort(sum2.begin(), sum2.end());
ll dif, ans = 0;
auto itr = sum2.end();
for (auto s : sum1) {
dif = t - s;
itr = upper_bound(sum2.begin(), itr, dif);
if (itr == sum2.begin() && ans < s) ans = s;
else if (itr != sum2.begin() && ans < s + *(itr - 1)) ans = s + *(itr - 1);
}
cout << ans;
}
| #include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long int
#define pb push_back
#define fe first
#define lb lower_bound
#define ub upper_bound
#define pii pair<pair<int,int>,pair<int,int> >
#define se second
#define endl "\n"
#define pi pair<int, int>
#define vi vector<int>
#define vvi vector<vi>
#define bs binary_search
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,a,b) for(int i=a;i<=b;i++)
#define all(c) (c).begin(),(c).end()
#define sz(x) (int)x.size()
#define PI 3.14159265358979323846
const int N =2e5+10;
int mod= 1e9+7;
int dx[4]={0,0,+1,-1};
int dy[4]={+1,-1,0,0};
int po(int a, int b) {
int res = 1;
while (b > 0) {
if (b & 1)
res = (res%mod * a%mod) % mod;
a =(a%mod*a%mod) % mod;
b >>= 1;
}
return res;
}
set<int> cal(vi a) {
set<int> st;
int n=sz(a);
for(int i=0;i<(1<<n);i++) {
int sm=0;
for(int j=0;j<n;j++) {
if(i&(1<<j)) {
sm+=a[j];
}
}
st.insert(sm);
}
return st;
}
void solve(){
int n,k;
cin>>n>>k;
vi a(n,0);
rep(i,0,n) cin>>a[i];
int dn=n/2;
vi b,c;
rep(i,0,dn) {
b.pb(a[i]);
}
rep(i,dn,n) {
c.pb(a[i]);
}
set<int> x=cal(b);
set<int> y=cal(c);
int ans=k;
for(auto to:x) {
auto it=y.ub(k-to);
if(it==y.begin()) continue;
it--;
int mn=k-to-*it;
if(mn<ans) ans=mn;
}
cout<<k-ans<<endl;
}
int32_t main() {
cool;
int t=1;
// cin>>t;
while(t--)
solve();
return 0;
} |
//#include <bits/stdc++.h>
#include <queue>
#include <iostream>
#include <iomanip>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <string>
#define F(i, a, b) for(register int i = a, i##end = b; i <= i##end; i++)
#define UF(i, a, b) for(register int i = a, i##end = b; i >= i##end; i--)
#define ll long long
using namespace std;
inline int read()
{
int x = 0;
bool fu = 0;
char ch = 0;
while(ch > '9' || ch < '0')
{
ch = getchar();
if(ch == '-')
fu = 1;
}
while(ch <= '9' && ch >= '0')
x = (x * 10 - 48 + ch), ch = getchar();
return fu ? -x : x;
}
int main()
{
int ans = read();
ans = min(ans, read());
ans = min(ans, read());
ans = min(ans, read());
cout << ans;
getchar();
return 0;
} | //#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <ctime>
#include <cassert>
#include <complex>
#include <cstring>
#include <chrono>
#include <random>
#define pb push_back
#define f first
#define s second
#define pi acos(-1.0)
#define LCM(a,b) a*b/__gcd(a,b)
#define GCD(a,b) __gcd(a,b)
#define mod 1000000007
#define test int t; cin>>t; while(t--)
#define sof sizeof
#define endl '\n'
typedef long long ll;
using namespace std;
/*
Run, Rabbit run
Dig that hole, forget the sun
And when at last the work is done
Don't sit down,
it's time to dig another one
_Breathe(Pink Floyd)
*/
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int a,b,c,d;
cin>>a>>b>>c>>d;
cout<<min(min(a,b),min(c,d));
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a,b,c,d,ans;
cin>>a>>b>>c>>d;
ans = max(a-c, max(a-d, max(b-c, b-d)));
cout<<ans;
return 0;
} | #include<bits/stdc++.h>
#define int long long
#define REP(i,a,n) for(int i=a;i<(n);i++)
#define REP_sz(i,s) for(int i=0;i<s.size();i++)
#define gcd(a,b) __gcd(a,b)
#define RE return
#define FILL(a,b) memset(a,b,sizeof(a))
#define SO(a) sort(all(a))
#define all(a) a.begin(),a.end()
#define pb push_back
#define sz(a) a.size()
#define V vector
#define ld long double
#define viit(a) vector<int>::iterator a
#define IT iterator
#define SET setprecision
#define FOR(i,a,n) for(int i=a;i<=(n);i++)
#define ER1(a) a.erase(a.begin())
#define ER0(a) a.erase(a.end())
#define pii pair<int,int>
#define pause system("PAUSE")
#define cls system("CLS")
#define mod1 1000000007
#define mod2 998244353
#define infmod 9223372036854775783
using namespace std;
int n;
int a[200005],b[200005],ma[200005],c[200005];
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin>>n;
REP(i,0,n)
cin>>a[i];
REP(i,0,n)
cin>>b[i];
ma[0]=a[0];
REP(i,1,n)ma[i]=max(a[i],ma[i-1]);
c[0]=a[0]*b[0];
REP(i,1,n)c[i]=max(c[i-1],b[i]*ma[i]);
REP(i,0,n)cout<<c[i]<<endl;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF=1e8;
int n,m,res=0,cnt=0,tot=0;
int b[300005];
ll pp[300005],qq[300005];
int h[300005],to[600005],ver[600005];
inline int read() {
register int x=0,f=1;register char s=getchar();
while(s>'9'||s<'0') {if(s=='-') f=-1;s=getchar();}
while(s>='0'&&s<='9') {x=x*10+s-'0';s=getchar();}
return x*f;
}
inline void add(int x,int y) {
to[++cnt]=y;
ver[cnt]=h[x];
h[x]=cnt;
}
void work(int x,int fa,int mid) {
pp[x]=-INF;qq[x]=INF;
for(register int i=h[x];i;i=ver[i]) {
int y=to[i];
if(y==fa) continue;
work(y,x,mid);
pp[x]=max(pp[x],pp[y]+1);
qq[x]=min(qq[x],qq[y]+1);
}
if(pp[x]+qq[x]<=mid) pp[x]=-INF;
if(qq[x]>mid&&b[x]==1) pp[x]=max(pp[x],(long long)0);
if(pp[x]==mid) pp[x]=-INF,qq[x]=0,++tot;
}
int check(int x)
{
tot=0;
work(1,-1,x);
if(pp[1]>=0) ++tot;
return tot<=m;
}
int main()
{
n=read(),m=read();
for(register int i=1;i<=n;++i) b[i]=1;
for(register int i=1;i<n;++i)
{
int x=read(),y=read();
add(x,y);add(y,x);
}
int L=0,R=n;
while(L<=R) {
int mid=L+R>>1;
if(check(mid)) R=mid-1,res=mid;
else L=mid+1;
}
printf("%d\n",res);
return 0;
} | #include<bits/stdc++.h>
#define Re register
using namespace std;
const int N=10,M=100005;
struct Node {
int L,V;
bool operator <(const Node& b) const {
return L==b.L ? V<b.V : L<b.L;
}
bool operator <(const int& b) const {
return V<b;
}
}b[M];
int n,m;
int Max;
int c[N];
int p[N];
int f[N];
int Maxx[M];
int sum[N];
int ans=0x7f7f7f7f;
inline int rd()
{
char ch=getchar();
int x=0,f=1;
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int main()
{
scanf("%d%d",&n,&m);
for(Re int i=1;i<=n;i++)
{
c[i]=rd();
p[i]=i;
Max=max(Max,c[i]);
}
for(Re int i=1;i<=m;i++)
{
b[i].L=rd();
b[i].V=rd();
if(Max>b[i].V)
{
printf("-1");
return 0;
}
}
sort(b+1,b+m+1);
for(Re int i=m-1;i>0;i--)
{
b[i].V=min(b[i].V,b[i+1].V);
}
do
{
memset(f,0,sizeof f);
for(Re int i=1;i<=n;i++)
{
sum[i]=sum[i-1]+c[p[i]];
}
for(Re int i=2;i<=n;i++)
{
f[i]=f[i-1];
for(Re int j=1;j<i;j++)
{
int x=lower_bound(b+1,b+m+1,sum[i]-sum[j-1])-b-1;
f[i]=max(f[i],f[j]+b[x].L);
}
}
ans=min(ans,f[n]);
}while(next_permutation(p+1,p+n+1));
printf("%d",ans);
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define INF 1111111111111111
typedef long long ll;
struct gogo
{
ll to,nt,st;
};
ll n,m,x,y,a,b,t,k,d[101010];
vector<gogo> vec[101010];
void bfs()
{
queue<ll>que;
que.push(x);
while(!que.empty())
{
int from=que.front();
que.pop();
for(ll i=0; i<vec[from].size(); i++)
{
ll to=vec[from][i].to;
{
if(d[to]>((d[from]-1+vec[from][i].st)/vec[from][i].st)*vec[from][i].st+vec[from][i].nt)
{
d[to]=((d[from]-1+vec[from][i].st)/vec[from][i].st)*vec[from][i].st+vec[from][i].nt;
if(to!=y)que.push(to);
}
}
/*else
{
if(d[to]>d[from]+vec[from][i].nt)
{
d[to]=d[from]+vec[from][i].nt;
}
}*/
}
}
}
int main()
{
scanf("%lld%lld%lld%lld",&n,&m,&x,&y);
for(ll i=0; i<m; i++)
{
scanf("%lld%lld%lld%lld",&a,&b,&t,&k);
gogo gogo1,gogo2;
gogo1.to=b;
gogo1.nt=t;
gogo1.st=k;
gogo2.to=a;
gogo2.nt=t;
gogo2.st=k;
vec[a].push_back(gogo1);
vec[b].push_back(gogo2);
}
for(ll i=0; i<=n; i++)d[i]=INF;
d[x]=0;
bfs();
//for(ll i=0;i<=4;i++)printf("%lld\n",d[i]);
if(d[y]!=INF)printf("%lld",d[y]);
else printf("-1");
return 0;
}
| #include "bits/stdc++.h"
using namespace std;
typedef long long li;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
const li n = 4;
vector<li> xs(n);
for (int i = 0; i < n; ++i) {
cin >> xs[i];
}
const li sum = accumulate(xs.begin(), xs.end(), 0LL);
bool ok = false;
for (int mask = 0; mask < 1 << n; ++mask) {
li subsum = 0;
for (int i = 0; i < n; ++i) {
if ((mask >> i) & 1) {
subsum += xs[i];
}
}
ok |= subsum == sum - subsum;
}
cout << (ok ? "Yes" : "No") << endl;
return 0;
} |
#include <iostream>
using namespace std;
int main() {
int v, t, s, d; cin >> v >> t >> s >> d;
cout << (d <= (s * v) && d >= (t * v) ? "No" : "Yes") << '\n';
cin.ignore(2); return 0;
} | //Code Written by Pinaki Bhattacharjee
#include<bits/stdc++.h>
using namespace std;
// typedef
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
// #define
#define LOCAL
#define INF 1e18
#define MAX 10000
#define PI 2*acos(0.0)
#define endl "\n"
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define set_bits __builtin_popcountll
#define DEBUG(x) cerr << #x << " = " << x << endl;
#define pinakipb2 ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// constants
const int MOD = (int) 1e9 + 7;
// debugger
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " | ";
__f(comma + 1, args...);
}
/*--------------------------------------------------------------------------------------------------------------------------*/
#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x<<" "; _print(x); cerr << endl;
#else
#define debug(x);
#endif
void _print(ll t) {cerr << t;}
void _print(int t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(ld t) {cerr << t;}
void _print(double t) {cerr << t;}
void _print(ull t) {cerr << t;}
template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.first); cerr << ","; _print(p.second); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}
void google(int t) {cout << "Case #" << t << ": ";}
ll mod_add(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;}
ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;}
ll mod_sub(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;}
/*--------------------------------------------------------------------------------------------------------------------------*/
int main()
{
pinakipb2;
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
freopen("error.txt","w",stderr);
#endif
// Code begins
ll v,t,s,d;
cin>>v>>t>>s>>d;
ld hit = d/double(v);
if(hit<t || hit>s)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
// Code ends
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
void __print(int x) {cout << x;}void __print(long x) {cout << x;}void __print(long long x) {cout << x;}void __print(unsigned x) {cout << x;}void __print(unsigned long x) {cout << x;}void __print(unsigned long long x) {cout << x;}void __print(float x) {cout << x;}void __print(double x) {cout << x;}void __print(long double x) {cout << x;}void __print(char x) {cout << '\'' << x << '\'';}void __print(const char *x) {cout << '\"' << x << '\"';}void __print(const string &x) {cout << '\"' << x << '\"';}void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define loop(i,a,b) for (ll i=a;i<=(ll)b;i++)
#define rloop(i,a,b) for (ll i=a;i>=(ll)b;i--)
#define ms(a,x) memset(a,x,sizeof a)
#define ll long long
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define nl cout<<"\n"
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/(gcd(a,b))
#define sq(a) ((a)*(a))
#define sz(a) a.size()
#define mod 1000000007
#define PI (2*acos(0.0))
int main()
{
IOS
int T=1;
//cin>>T;
while(T--)
{
ll n;
cin>>n;
ll a[n],b[n];
ll mx=0;
loop(i,0,n-1)
{
cin>>a[i];
mx=max(mx,a[i]);
a[i]=mx;
}
mx=0;
loop(i,0,n-1)
{
cin>>b[i];
mx=max(mx,b[i]*a[i]);
cout<<mx;
nl;
}
}
return 0;
}
| //#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("avx2,tune=native")
#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(), (v).end()
#define sz(a) ((long long)(a).size())
#define X first
#define Y second
using ll = long long;
using ull = unsigned long long;
using dbl = long double;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll mod) {
return (ull)rng() % mod;
}
const string atcoder = "atcoder";
string s;
void solve() {
cin >> s;
int i = 0;
while (i < sz(s) && s[i] == 'a') {
++i;
}
if (i == sz(s)) {
cout << "-1\n";
return;
}
if (s > atcoder) {
cout << "0\n";
return;
}
if (i == 0) {
assert(false);
cout << "0\n";
return;
}
if (s[i] > 't') {
cout << i - 1 << "\n";
return;
}
cout << i << "\n";
}
signed main() {
#ifdef LOCAL
assert(freopen("input.txt", "r", stdin));
// assert(freopen("output.txt", "w", stdout));
#endif
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(20);
int T = 1;
cin >> T;
for (int numt = 0; numt < T; ++numt) {
solve();
}
#ifdef LOCAL
cout << endl << endl << "time = " << clock() / (double)CLOCKS_PER_SEC << endl;
#endif
}
|
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int n,m,num[105][105],ans=0;
char s[105][105];
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
{
scanf("%s",s[i]);
for(int j=1;j<=m;j++)
{
if(s[i][j-1]=='#')continue;
if(i>1&&s[i][j-1]==s[i-1][j-1])ans++;
if(j>1&&s[i][j-1]==s[i][j-2])ans++;
}
}
printf("%d",ans);
return 0;
} | #pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please
ll dp[101][101];
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll N, X;
cin >> N >> X;
int A[100];
rep(i, N) cin >> A[i];
ll kotae = 2e18;
ll b = 0;
rep1(s, N) {
b += 2000000000;
ll amari = X % s;
dp[0][0] = b;
rep(i, N) {
ce(i);
for (int j = min(i, s - 1); j >= 0; j--) {
int t0 = A[i] % s;
int t = t0;
rep(k, s - t0) {
if (dp[j][k] >= b) chmax(dp[j + 1][t], dp[j][k] + A[i]);
t++;
}
t -= s;
for (int k = s - t0; k < s; k++) {
if (dp[j][k] >= b) chmax(dp[j + 1][t], dp[j][k] + A[i]);
t++;
}
}
}
if (dp[s][amari] >= b) {
chmin(kotae, (X - dp[s][amari] + b) / s);
}
}
co(kotae);
Would you please return 0;
} |
#include "bits/stdc++.h"
using namespace std;
long long ncr(long long a,long long b)
{
long long m=1;
for(int i=a;i>b;i--)
{
m*=i;
m/=a-i+1;
}
return m;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
long long a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, m = 0, n = 0, p = 0, q = 0, mod = 1000000007, pi = 3.1415926535;
string s1, s2;
char moji;
cin >> a >> b >> c;
d=a+b;
c--;
for(int i=0;i<d;i++)
{
if(ncr(a+b-1,max(a-1,b))<=c)
{
c-=ncr(a+b-1,max(a-1,b));
cout << 'b';
b--;
}
else
{
if(a)
{
cout << 'a';
a--;
}
else
{
cout << 'b';
b--;
}
}
}
cout << endl;
return 0;
} | #include <iostream>
#include <string>
constexpr int MAX = 30;
long long dp[MAX + 1][MAX + 1];
std::string find_kth(int A, int B, long long K) {
if (A == 0) {
return std::string(B, 'b');
}
if (B == 0) {
return std::string(A, 'a');
}
if (K <= dp[A - 1][B]) {
return std::string("a") + find_kth(A - 1, B, K);
}
else {
return std::string("b") + find_kth(A, B - 1, K - dp[A - 1][B]);
}
}
int main() {
int A, B;
long long K;
std::cin >> A >> B >> K;
dp[0][0] = 1;
for (int i = 0; i <= A; ++i) {
for (int j = 0; j <= B; ++j) {
if (i > 0) {
dp[i][j] += dp[i - 1][j];
}
if (j > 0) {
dp[i][j] += dp[i][j - 1];
}
}
}
std::cout << find_kth(A, B, K) << '\n';
return 0;
} |
#include <bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC target("fpmath=387") //extra precision
#define debug_input freopen("stdin.in", "r", stdin)
#define debug_output freopen("stdout.out", "w", stdout)
#define FOR(i, a, b) for(ll i = a; i <= b; i++)
#define FORALL(i, n) for(ll i = 0; i < n; i++)
#define FORD(i, a, b) for(ll i = a; i >= b; i--)
#define SORT(a) sort(a.begin(), a.end())
#define REV(a) reverse(a.begin(), a.end())
#define NP(a) next_permutation(a.begin(), a.end())
#define ALL(a) a.begin, a.end()
#define mp make_pair
#define pb push_back
#define endl '\n'
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll N = 1e5 + 5;
const ll mod = 1e9 + 7;
const ll inf = 1e18;
const double pi = 3.141592653589793;
const ll dr[4] = {-1,0,1,0}, dc[4] = {0,1,0,-1};
void solve() {
ll n, x;
cin >> n >> x;
ll total = 0;
FOR(i, 1, n) {
ll v, p;
cin >> v >> p;
total += v * p;
if(total > 100 * x) {
cout << i << endl;
return;
}
}
cout << -1 << endl;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
ll t = 1;
//cin >> t;
while(t--) {
solve();
}
return 0;
} | #include <bits/stdc++.h>
#define rep(i, l, r) for (int i = (l); i < (r); i++)
using namespace std;
typedef long long ll;
map<vector<int>, ll> mp;
ll MOD = 1e9 + 7;
ll mod_pow(ll x, ll n, ll mod) {
ll res = 1;
while (n > 0) {
if (n & 1) res = res * x % mod;
x = x * x % mod;
n >>= 1;
}
return res;
}
int main() {
int N, M, K;
cin >> N >> M >> K;
if (N > M + K) {
cout << 0 << endl;
return 0;
}
vector<ll> f(N + M + 1, 1);
rep(i, 0, N + M) f[i + 1] = (f[i] * (i + 1)) % MOD;
ll ans = f[N + M];
ans *= mod_pow(f[N], MOD - 2, MOD);
ans %= MOD;
ans *= mod_pow(f[M], MOD - 2, MOD);
ans %= MOD;
//cout << "ans0=" << ans << endl;
if (K < N && N - K - 1 >= 0) {
ll x = f[N + M];
x *= mod_pow(f[M + K + 1], MOD - 2, MOD);
x %= MOD;
x *= mod_pow(f[N - K - 1], MOD - 2, MOD);
x %= MOD;
//cout << "x=" << x << endl;
ans = (ans + MOD - x) % MOD;
}
cout << ans << endl;
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 998244353;
using graph = vector<vector<int>>;
bool can_reach(const graph &g, const int s, const int t, vector<bool> &visited){
if(s==t)return true;
if(!visited[s]){
visited[s] = true;
for(const auto u: g[s]){
if(can_reach(g, u, t, visited)){
return true;
}
}
}
return false;
}
struct Point{
int x;
int y;
};
double distance(const Point &p, const Point &q){
return sqrt((p.x - q.x) * (p.x - q.x) + (p.y - q.y) * (p.y - q.y));
}
int main()
{
int n;
cin >> n;
vector<Point> vp;
for(int i=0; i<n; ++i){
int x, y;
cin >> x >> y;
vp.push_back({x, y});
}
double thres_min = 1e-5, thres_max = 100.0;
while(thres_max - thres_min > 1e-6){
double thres = (thres_min + thres_max) / 2.0;
auto g = graph(n+2);
for(int i=0; i<n; ++i){
for(int j=i+1; j<n; ++j){
if(distance(vp[i], vp[j]) < 2*thres){
g[i].push_back(j);
g[j].push_back(i);
}
}
//上下端
if(vp[i].y < -100 + 2 * thres){
g[i].push_back(n);
g[n].push_back(i);
}
if(vp[i].y > 100 - 2 * thres){
g[i].push_back(n+1);
g[n+1].push_back(i);
}
}
auto visited = vector<bool>(n+2, false);
if(can_reach(g, n, n+1, visited)){
thres_max = thres;
}else{
thres_min = thres;
}
}
printf("%1.18f\n", (thres_min + thres_max) / 2.0);
return 0;
} | #define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
class UnionFind {
int cnt;
vector<int> par, rank, size;
public:
UnionFind() {}
UnionFind(int _n) :cnt(_n), par(_n), rank(_n), size(_n, 1) {
for (int i = 0; i<_n; ++i) par[i] = i;
}
int find(int k) {
return (k == par[k]) ? k : (par[k] = find(par[k]));
}
int operator[](int k) {
return find(k);
}
int getSize(int k) {
return size[find(k)];
}
void unite(int x, int y) {
x = find(x); y = find(y);
if (x == y) return;
--cnt;
if (rank[x] < rank[y]) {
par[x] = y;
size[y] += size[x];
} else {
par[y] = x;
size[x] += size[y];
if (rank[y] == rank[x]) ++rank[x];
}
}
int count() {
return cnt;
}
};
void solve() {
int N;
cin >> N;
vi X(N), Y(N);
rep(i, N)cin >> X[i] >> Y[i];
double ok = 0, ng = 200;
rep(ITER, 60) {
UnionFind uf(N + 2);
double d = (ok + ng) / 2;
rep(i, N) {
if (100 - Y[i] < d)uf.unite(i, N);
if (Y[i] + 100 < d)uf.unite(i, N + 1);
rep(j, i) {
if (hypot(X[i] - X[j], Y[i] - Y[j]) < d)uf.unite(i, j);
}
}
(uf[N] == uf[N + 1] ? ng : ok) = d;
}
cout << ok/2 << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(15);
solve();
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define rev(i,n,a) for(ll i=n-1;i>=a;i--)
#define f first
#define s second
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define vpii vector<pair<int,int>>
#define vpll vector<pll>
#define pll pair<ll,ll>
#define secreterror() ios_base::sync_with_stdio(false);cin.tie(NULL);
void solve(){
ll n;
cin>>n;
vector<pair<ll,ll>>arr(n);
rep(i,0,n){
cin>>arr[i].first>>arr[i].second;
}
map<ll,ll>mp;
bool ok=false;
for(int i=0;i<n-2;i++){
for(int j=i+1;j<n-1;j++){
for(int k=j+1;k<n;k++){
ll a=arr[i].first*(arr[j].second-arr[k].second)+arr[j].first*(arr[k].second-arr[i].second)+arr[k].first*(arr[i].second-arr[j].second);
if(a==0){
ok=true;
break;
}
}
}
}
if(ok){
cout<<"Yes"<<endl;
}else{
cout<<"No"<<endl;
}
}
int main()
{
secreterror()
// ll t;
// cin>>t;
//while(t--){
solve();
//}
} | #include<bits/stdc++.h>
using namespace std;
#define fi(a,b) for(int i=a;i<b;i++)
#define fj(a,b) for(int j=a;j<b;j++)
#define ff first
#define ss second
#define ll long long
#define ld long double
#define ull unsigned long long
#define bp(x) __builtin_popcount(x)
#define pr(x) for(auto it: x) cout<<it<<" "; cout<<endl;
#define getMax(x) max_element(x.begin(),x.end())
#define getMin(x) min_element(x.begin(),x.end())
#define endl "\n"
typedef vector<int> vi;
typedef vector< pair<int,int> > vii;
typedef vector<long long> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector< pair<ll,ll> > vll;
//int dx[]={1,0,-1,0};
//int dy[]={0,1,0,-1};
//int dx[]={-1,0,1,1,1,0,-1,-1};
//int dy[]={-1,-1,-1,0,1,1,1,0};
void nikal_pehli_fursat_mai(){
int n;
cin>>n;
map<string, bool>mp;
fi(0, n){
string s;
cin>>s;
mp[s] = 1;
}
for(auto it: mp){
string s = it.ff;
if(s[0]=='!'){
string s1 = s.substr(1);
if(mp[s1]){
cout<<s1<<endl;
return;
}
}
}
cout<<"satisfiable"<<endl;
}
int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios::sync_with_stdio(0);
cin.tie(0);
int tc=1;
// cin>>tc;
while(tc--){
nikal_pehli_fursat_mai();
}
}
|
// E - Throne
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
// 拡張ユークリッド互除法
// (g,x,y): ax+by=g
tuple<ll,ll,ll> extgcd(int a, int b){
if(b==0) return {a, 1, 0};
auto[g, x, y] = extgcd(b, a%b);
return {g, y, x-a/b*y};
}
int solve(int n, int s, int k){
auto[g, x, y] = extgcd(k, n);
if(s%g) return -1;
n /= g, s /= g, k /= g;
return (-s * x % n + n)%n;
}
int main(){
int t; cin>>t;
while(t--){
int n, s, k; cin>>n>>s>>k;
cout<< solve(n, s, k) <<endl;
}
}
| #include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>
#include<map>
#include<cassert>
using namespace std;
#define ll long long
#define reps(i, a, b) for(int i = a; i < b; i++)
#define rreps(i, a, b) for(int i = a-1; i >= b; i--)
#define rep(i, n) reps(i, 0, n)
#define rrep(i, n) rreps(i, n, 0)
#define P pair<int, int>
#define vec vector<int>
#define mat vector<vector<int> >
const ll mod = 1000000007;
const int INF = 1001001001;
ll extgcd(ll a, ll b, ll& x, ll& y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
ll g = extgcd(b, a%b, y, x);
y -= (a/b) * x;
return g;
}
void solve() {
ll n, s, k;
cin >> n >> s >> k;
ll g, x, y;
g = extgcd(k, n, x, y);
if (s % g != 0) {
cout << -1 << endl;
return;
}
n /= g;
s /= g;
k /= g;
ll ans = ((x*(-s))%n+n) % n;
cout << ans << endl;
}
int main(){
int t;
cin >> t;
rep(i, t){
solve();
}
} |
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <array>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
using namespace std;
using ll = long long;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;
template<class T>
inline bool chmax(T& x, T y){
if(x < y){
x = y;
return true;
}
return false;
}
template<class T>
inline bool chmin(T& x, T y){
if(x > y){
x = y;
return true;
}
return false;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin >> N;
vector<int> A(N), B(N);
for(int i = 0; i < N; ++i) cin >> A[i] >> B[i];
int ans = INF;
for(int i = 0; i < N; ++i) chmin(ans, A[i] + B[i]);
for(int i = 0; i < N; ++i){
for(int j = 0; j < N; ++j){
if(j == i) continue;
chmin(ans, max(A[i], B[j]));
}
}
cout << ans << endl;
return 0;
} | //BY: YASH JAIN, CF: BitSane
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#define May_the_fork_be_with_you ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define rall(v) v.rbegin(),v.rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define deb(x) cout<<#x<<": "<<x<<endl;
#define debn(x) cout<<#x<<": "<<x<<" ";
#define MOD 1000000007
#define mod 998244353
#define INF 1e18
#define ll long long
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define endl "\n"
#define int long long
#define N 100005
#define sq(x) ((x)*(x))
typedef vector<int> vi;
ll gcd(ll a, ll b) {if (!b)return a; return gcd(b, a % b);}
ll power(ll x, ll y, ll p = INF) {ll res = 1; x %= p; while (y > 0) {if (y & 1)res = (res * x) % p; y = y >> 1; x = (x * x) % p;} return res;}
// Do Not use power when calculating powers of 2 (its inefficient)
void solve() {
int n, m; cin >> n >> m;
vi res, a(n), b(m);
forn(i, n) cin >> a[i];
forn(j, m) cin >> b[j];
forn(i, n) {
bool foo = false;
forn(j, m) {
if (a[i] == b[j]) {
foo = true;
break;
}
}
if (!foo) res.eb(a[i]);
}
forn(j, m) {
bool foo = false;
forn(i, n) {
if (a[i] == b[j]) {
foo = true;
break;
}
}
if (!foo) res.eb(b[j]);
}
sort(all(res));
for (auto x : res) cout << x << " ";
}
int32_t main() {
#ifndef ONLINE_JUDGE
// for geting input form input.txt
freopen("input.txt", "r", stdin);
// for wrting output to output.txt
freopen("output.txt", "w", stdout);
#endif
May_the_fork_be_with_you
int t = 1;
int x = 1;
// cin >> t;
cout << fixed << setprecision(12);
while (t--) {
// cout << "Case #" << x << ": ";
solve();
x++;
}
#ifndef ONLINE_JUDGE
cerr << "Time Taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
#endif
} |
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------
int N,M;
const ll mo=998244353;
ll comb(ll N_, ll C_) {
const int NUM_=400001;
static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];
if (fact[0]==0) {
inv[1]=fact[0]=factr[0]=1;
for (int i=2;i<=NUM_;++i) inv[i] = inv[mo % i] * (mo - mo / i) % mo;
for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%mo, factr[i]=factr[i-1]*inv[i]%mo;
}
if(C_<0 || C_>N_) return 0;
return factr[C_]*fact[N_]%mo*factr[N_-C_]%mo;
}
ll pat[202020][100];
void solve() {
int i,j,k,l,r,x,y; string s;
cin>>N>>M;
int cnt=0;
ll ret=0;
for(i=1;i<=M;i++) {
pat[i][1]=1;
for(j=i*2;j<=M;j+=i) {
for(x=1;x<=99;x++) {
if(pat[i][x]==0) break;
(pat[j][x+1]+=pat[i][x])%=mo;
}
}
for(x=1;x<=99;x++) if(pat[i][x]) {
(ret+=comb(N-1,x-1)*pat[i][x])%=mo;
}
}
cout<<ret<<endl;
}
int main(int argc,char** argv){
string s;int i;
if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
cout.tie(0); solve(); return 0;
}
| #include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
const int N = 2e5 + 5, mod = 998244353;
int fact[N], inv[N];
vector<int> primes[N];
int mul(int a, int b){
return 1ll * a * b % mod;
}
int add(int a, int b){
return (a + b) % mod;
}
int fp(int b, int p){
if(!p) return 1;
ll ret = fp(b, p >> 1);
ret = ret * ret % mod;
if(p&1) ret = ret * b % mod;
return ret;
}
void pre(){
fact[0] = inv[0] = 1;
for(int i = 1; i < N; i++){
fact[i] = mul(fact[i - 1], i);
inv[i] = fp(fact[i], mod - 2);
}
}
int ncr(int n, int r){
if(n < r) return 0;
int ret = mul(fact[n], inv[n - r]);
return mul(ret, inv[r]);
}
int main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
pre();
int n, m;
cin >> n >> m;
if(n == 1) return cout << m, 0;
for(int i = 2; i <= m; i++){
if((int) primes[i].size() > 0) continue;
for(int j = i; j <= m; j += i){
int c = 1, tmp = j;
while(tmp % i == 0){
tmp /= i;
c++;
}
primes[j].push_back(c);
}
}
int ans = 0;
for(int i = 1; i <= m; i++){
int tmp = 1;
for(auto j: primes[i]){
int sum = 0;
for(int k = 1; k <= j; k++){
sum = add(sum, mul(ncr(n - 2, k - 1), ncr(j, k)));
}
tmp = mul(tmp, sum);
}
ans = add(ans, tmp);
}
cout << ans;
return 0;
} |
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
int p[102][2];
int q[102][2];
int main(){
int n,m;
cin>>n>>m;
for(int i=1;i<=m;i++){
cin>>p[i][0]>>p[i][1];
}
int k;
cin>>k;
for(int i=0;i<k;i++){
cin>>q[i][0]>>q[i][1];
}
int ans = 0;
for(int i=0;i<(1<<k);i++){
int trt = 0;
int cnt[102] = {};
for(int j=0;j<k;j++){
if(i&(1<<j)){
cnt[q[j][1]]++;
}
else{
cnt[q[j][0]]++;
}
}
for(int j=1;j<=m;j++){
if(cnt[p[j][0]]>0 and cnt[p[j][1]]>0)trt++;
}
ans = max(ans,trt);
}
cout<<ans<<endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main(){
int n; cin >> n;
vector<int> a(n), b(n);
int ans = INT_MAX;
for(int i = 0; i < n; i++){
cin >> a[i] >> b[i];
}
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
if(i == j) ans = min(ans, a[i] + b[j]);
else ans = min(ans, max(a[i], b[j]));
}
}
cout << ans << endl;
} |
#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 ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define int long long int
#define endl "\n"
#define MOD 1000000007
#define mod 1000000007
#define M 1000000007
#define pb push_back
#define take(a,b,c) for(int b=0;b<c;b++) cin>>a[b]
#define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mx 1000005
#define fiint(a,b) memset(a,b,sizeof(a))
#define bitcount __builtin_popcount
#define fori(i,a,b) for(int i=a;i<b;i++)
#define ford(i,a,b) for(int i=a;i>=b;i--)
#define debug(x) cout<<x<<endl;
#define cases(t) int t; cin>>t; while(t--)
#define inf1 INT_MAX
#define all(a) a.begin(),a.end()
#define vec vector<int>
#define pii pair<int,int>
#define plii pair<int,int>
#define pint pair<int,int>
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define mp make_pair
#define sz(x) (int)x.size()
#define PI 3.14159265359
int factorial[10000001]={0};
int gcd(int a, int b){
if (b == 0)
return a;
return gcd(b, a % b);
}
int powerFunction(int x,int y){
int res = 1;
int p = mod;
x = x;
while (y > 0){
if (y & 1)
res = (res*x)%p ;
y = y>>1;
x = (x*x)%p ;
}
return res;
}
void factorialFunction(int maxLimit){
factorial[0]=1;
for(int i=1 ; i <= maxLimit ; i++)
factorial[i]=(factorial[i-1]*i)%MOD;
return;
}
int nCr(int n, int r)
{
if(r < 0 || r > n){
return 0;
}
int temp = factorial[n];
temp *= (powerFunction(factorial[r], MOD-2)%MOD);
temp %= MOD;
temp *= (powerFunction(factorial[n-r], MOD-2)%MOD);
temp %= MOD;
return temp;
}
vec tree(5*300005);
int up(int node,int l ,int r , int idx , int v)
{
if(l == r)
{
tree[node] = v;
return tree[node];
}
int mid = (l + r )/2;
if(idx <= mid )
up(node*2 ,l , mid , idx , v );
else
up(node*2 + 1 , mid + 1 , r , idx , v );
tree[node] = tree[node*2] + tree[2*node + 1];
return tree[node];
}
int sum(int node,int st , int en , int l ,int r )
{
if(en < l || r < st)
return 0;
if(st >= l && en <= r)
return tree[node];
int mid = (st + en)/2;
return sum(node*2,st , mid , l , r ) + sum(node*2 + 1, mid + 1 , en , l , r) ;
}
signed main()
{
int n;cin>>n;
//vec ans;
vec v(n+1);
int ans = 0 ;
for(int i = 0 ; i < n;i++)
{
cin>>v[i];
ans += sum(1,0,n-1,v[i],n);
up(1, 0, n-1, v[i], 1);
}
for(int i = 0 ; i < n ;i++)
{
cout<<ans<<endl;
ans += n -1 - v[i]*2;
}
}
| #include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define MOD 1000000007
// 1-indexed
const int N = 1000010;
vector<ll> bit(N);
// a[p] += x
void add(int p, int x) {
for (int i = p; i <= N; i += i & -i) {
bit[i] += x;
}
}
// a[1] + a[2] + ... + a[p]
ll sum(int p) {
ll res = 0;
for (int i = p; i > 0; i -= i & -i) {
res += bit[i];
}
return res;
}
int main() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
a[i]++;
}
ll cnt = 0;
for (int i = 0; i < n; ++i) {
cnt += i - sum(a[i]);
add(a[i], 1);
}
cout << cnt << endl;
for (int i = 1; i <= n - 1; ++i) {
cnt += n - 2 * a[i - 1] + 1;
cout << cnt << endl;
}
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define rep2(i, j, n) for(int i=j;i<(int)(n);i++)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;
map<int, ll> table;
int main(){
int N;
cin >> N;
ll C;
cin >> C;
rep(i, N){
int a, b, e;
cin >> a >> b >> e;
table[a-1] += e;
table[b] -= e;
}
vector<pair<int, ll>> table2;
for(pair<int, ll> p : table){
table2.pb(p);
}
sort(all(table2));
ll rui[table2.size()+1];
ll sum = 0;
rui[0] = 0;
rep(i, table2.size()){
rui[i+1] = rui[i] + table2[i].second;
if(i>0 && rui[i]>C){
sum += (table2[i].first - table2[i-1].first)*C;
} else if(i>0) {
sum += (table2[i].first - table2[i-1].first)*rui[i];
}
}
cout << sum << endl;
}
| #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5,M=2e4+5,inf=0x3f3f3f3f,mod=1e9+7;
#define mst(a,b) memset(a,b,sizeof a)
#define PII pair<int,int>
#define fi first
#define se second
#define pb push_back
#define lx x<<1
#define rx x<<1|1
map<int,ll>mp;
int main(){
int n,C;
scanf("%d%d",&n,&C);
for(int i=1;i<=n;i++){
int a,b,c;scanf("%d%d%d",&a,&b,&c);
mp[a]+=c,mp[b+1]-=c;
}
int l=0;ll ans=0,s=0;
for(auto p:mp){
ans+=1LL*min(1LL*C,s)*(p.fi-l);
l=p.fi;
s+=p.se;
}printf("%lld\n",ans);
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define ar array
#define ll long long
#define For(i,k,n) for(int i=k;i<n;i++)
#define Forll(i,k,n) for(long long int i=k;i<n;i++)
#define Forull(i,k,n) for(long long int i=k;i<n;i++)
const ll MOD = 1e9 + 7;
const ll INF = 1e9;
void solve(){
int a,b,c;
cin>>a>>b>>c;
if(a*a+b*b<c*c)
cout<<"Yes"<<"\n";
else
cout<<"No"<<"\n";
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
ll int tc=1;
//cin >> tc;
for (ll int t = 1; t <= tc; t++) {
//cout << "Case #" << t << ": ";
solve();
}
}
| #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'; }
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
const ll INFLL = 1e18;
const int MAXN = 1e6+100;
const ll INF = 1e9;
const int mod1 = 1e9+7;
const int mod2 = 1e9+21;
void solve()
{
int a,b,c;
cin>>a>>b>>c;
cout<<(a*a+b*b<c*c?"Yes\n":"No\n");
}
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;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 10000000000000000 //10^16
template <typename T>
bool chmax(T &a, const T& b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T>
bool chmin(T &a, const T& b) {
if (a > b) {
a = b;
return true;
}
return false;
}
struct edge {
ll to;
};
vector<vector<edge>> graph;
vector<ll> gold(200000, -1); // gold.at(i)は町iから到達可能なi以外の町で最も高い金の値段
vector<ll> A(200000);
vector<ll> gold2(200000, -1); // gold.at(i)は町iから到達可能な町で最も高い金の値段
ll bfs(ll x){
if(gold2.at(x) != -1){
return gold2.at(x);
}
ll M = A.at(x);
ll L = -INF;
bool upd = false;
for(auto e : graph.at(x)){
ll K = bfs(e.to);
if(K >= M){
upd = true;
M = K;
}
chmax(L, K);
}
if(upd){
gold.at(x) = M;
}
else{
gold.at(x) = L;
}
gold2.at(x) = M;
return M;
}
int main()
{
ll N, M;
cin >> N >> M;
graph.resize(N);
rep(i, N) cin >> A.at(i);
vector<ll> X(M), Y(M);
rep(i, M){
cin >> X.at(i) >> Y.at(i);
X.at(i)--;
Y.at(i)--;
graph.at(X.at(i)).push_back({Y.at(i)});
}
rep(i, N){
if(gold.at(i) != -1){
continue;
}
bfs(i);
}
ll ans = -INF;
rep(i, N){
chmax(ans, gold.at(i) - A.at(i));
}
cout << ans << endl;
} | #include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using LL = long long;
using P = pair<int,int>;
const long double INF = 2e12;
const long double eps = 1e-12;
int N, M, K;
vector<int> A;
long double solve(long double ans){
vector<long double> dp(N + 1), sum(N + 1);
rep(i,N){
int n = N - 1 - i;
if(A[n]) dp[n] = ans;
else dp[n] = (sum[i] - sum[max(0, i - M)]) / M + 1;
sum[i+1] = sum[i] + dp[n];
}
return dp[0];
}
long double binary_search(long double left, long double right){
if(right - left < eps * left) return left;
long double ans = sqrt(left * right);
long double res = solve(ans);
if(ans > res) right = ans;
else left = ans;
return binary_search(left, right);
}
int main(){
cin >> N >> M >> K;
A = vector<int>(N + 1);
rep(i,K){
int a;
cin >> a;
A[a] = 1;
}
int num = 0;
rep(i,N+1){
if(A[i]) num++;
else num = 0;
if(num >= M){
cout << -1 << endl;
return 0;
}
}
cout << setprecision(20) << binary_search(1, INF) << endl;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pint = pair<int,int>;
const int D = 100000;
int main()
{
int N; cin >> N;
vector<int> a(N);
vector<vector<bool>> dp(N + 1, vector<bool>(D + 1, false));
dp[0][0] = true;
for(auto &i : a) cin >> i;
for(int i = 0; i < N; i++) {
for(int j = 0; j <= D; j++) {
if(!dp[i][j])continue;
dp[i + 1][j] = true;
if(j + a[i] <= D)dp[i + 1][j + a[i]] = true;
}
}
int sum = accumulate(a.begin(), a.end(), 0);
int ans = 1e9;
for(int i = 0; i <= D; i++) {
if(dp[N][i] == true) {
ans = min(ans, max(i, sum - i));
}
}
cout << ans << endl;
} | #include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define pii pair<int,int>
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define mp make_pair
#define endl '\n'
#define int long long
typedef double db;
typedef long long ll;
const int N = 1e5 + 5;
const int MOD = 1e9 + 7;
const int INF = 1e9;
int dp[101][N];
bool go(int n, vector<int>& arr, int sum) {
if (sum == 0) return true;
if (n == 0) return false;
int& ret = dp[n][sum];
if (ret != -1) return ret;
if (arr[n - 1] <= sum) {
//either inc or exclude
bool inc = go(n - 1, arr, sum - arr[n - 1]);
bool exc = go(n - 1, arr, sum);
return ret = (inc | exc);
}
else {
return ret = go(n - 1, arr, sum);
}
}
void solve() {
int n; cin >> n;
vector<int> arr(n);
int sum = 0;
for (int i = 0; i < n; i++) {
cin >> arr[i];
sum += arr[i];
}
memset(dp, -1, sizeof(dp));
int reqd = sum / 2;
int sum1 = -1, sum2 = -1;
for (int i = reqd; i >= 0; i--) {
bool cur = go(n, arr, i);
if (cur == 1) {
sum1 = i;
break;
}
}
sum2 = sum - sum1;
cout << max(sum1, sum2);
}
signed main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
fastIO
int t = 1;
// cin >> t;
for (int tt = 1; tt <= t; tt++) {
solve();
}
} |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
vector<pair<int, int>> P(M);
for (int i = 0; i < M; i++) cin >> P.at(i).first >> P.at(i).second;
sort(P.begin(), P.end());
set<int> S;
S.insert(N);
int l = 0;
while (l < M) {
vector<int> A, B;
int r = l;
while (r < M) {
if (P.at(r).first == P.at(l).first) r++;
else break;
}
for (int i = l; i < r; i++) {
int y = P.at(i).second;
if ((S.count(y - 1) || S.count(y + 1)) && !(S.count(y))) A.push_back(y);
if ((!S.count(y - 1) && !S.count(y + 1)) && S.count(y)) B.push_back(y);
}
for (int i = 0; i < A.size(); i++) S.insert(A.at(i));
for (int i = 0; i < B.size(); i++) S.erase(B.at(i));
l = r;
}
cout << S.size() << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(long long i=0; i<n; i++)
#define pii pair<long long,long long>
#define vi vector<long long>
#define vii vector<pii>
#define ll long long
long long par[200001],sizeT[200001],sizeP[200001],sizeX[200001],N,M;
void Initialize(){
for(long long i=1; i<=N; i++){
par[i]=i;
}
}
long long FindPar(long long x){
if(par[x]==x){
return x;
}else{
par[x]=FindPar(par[x]);
return par[x];
}
}
void Join(long long a, long long b){
long long RepA=FindPar(a),RepB=FindPar(b);
if(RepA==RepB)return;
par[RepA]=RepB; sizeP[RepB] += sizeP[RepA]; sizeP[RepA] = 0;
}
int main(){
cin>>N>>M;
for(long long i=1; i<=N; i++){
cin>>sizeP[i];
}
for(long long i=1; i<=N; i++){
cin>>sizeX[i];
}
Initialize();
for(long long i=1; i<=M; i++){
long long a,b;
cin>>a>>b;
Join(a,b);
}
for(long long i=1; i<=N; i++){
sizeT[FindPar(i)]+=sizeX[i];
}
for(long long i=1; i<=N; i++){
if(sizeT[i]!=sizeP[i]){
cout<<"No"<<endl; return 0;
}
}
cout<<"Yes"<<endl;
} |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(c) (c).begin(), (c).end()
void solve() {
int N;
cin >> N;
vector <pair <int, int> > time(N);
for (auto &el : time) cin >> el.first >> el.second;
int ans = INT_MAX;
for (int i = 0; i < N; i++) {
ans = min(ans, time[i].first + time[i].second);
}
sort(all(time));
int x = INT_MAX;
for (int i = 1; i < N; i++) {
x = min(x, time[i].second);
}
ans = min(ans, max(time[0].first, x));
sort(all(time), [] (const pair <int, int> &A, const pair <int, int> &B) {
return A.second < B.second;
});
x = INT_MAX;
for (int i = 1; i < N; i++) {
x = min(x, time[i].first);
}
ans = min(ans, max(time[0].second, x));
cout << ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
solve();
cout << '\n';
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main(){
int a=100000;
int b=100000;
int aa=0;
int N=0;
int ans=0;
cin>>N;
vector<int>A(N),B(N);
for(int i=0; i<N; i++){
cin>>A.at(i)>>B.at(i);
}
for(int i=0; i<N; i++){
if(A.at(i)<a){
a=A.at(i);
aa=i;
}
}
for(int j=0; j<N; j++){
if(j==aa){
continue;
}
else if(B.at(j)<b){
b=B.at(j);
}
}
if(a>b){
ans=a;
}
else{
ans=b;
}
if(A.at(aa)+B.at(aa)>=ans){
cout<<ans<<endl;
}
else {
cout<<A.at(aa)+B.at(aa)<<endl;
}
} |
#pragma GCC optimize("O2")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MXN = 3e3 + 10;
ll H, W, Par[MXN], Sz[MXN];
vector<ll> R[MXN], C[MXN];
string s[MXN];
ll f1, f2, f3;
ll Find(ll x){
return (x == Par[x] ? x : Par[x] = Find(Par[x]));
}
bool Union(ll u, ll v){
u = Find(u), v = Find(v);
if(u == v) return 0;
if(Sz[v] > Sz[u]) swap(u, v);
Sz[u] += Sz[v], Par[v] = u;
return 1;
}
void Build(){
for(int i = 1; i <= H + W; i ++){
Par[i] = i, Sz[i] = 1;
}
for(int i = 1; i <= H; i ++){
for(int j = 1; j <= W; j ++){
if(s[i][j] == '#') Union(i, j + H);
}
}
}
int main(){
//ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
cin >> H >> W;
if(min(H, W) <= 2) return cout << 0, 0;
for(int i = 1; i <= H; i ++){
cin >> s[i];
s[i] = "$" + s[i];
}
s[1][1] = s[1][W] = s[H][1] = s[H][W] = '#';
Build();
for(int i = 1; i <= H + W; i ++){
if(Find(i) != i) continue;
f1 += Union(i, 1);
}
Build();
for(int i = 1; i <= H; i ++){
f2 += Union(1, i);
}
Build();
for(int j = 1; j <= W; j ++){
f3 += Union(1, j + H);
}
for(int i = 1; i <= 100; i ++) Build();
cout << min({f1, f2, f3}) << '\n';
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
vector<string> unique(vector<string> vec){ //あんまり値渡しは良くない気がするけど一回ならいいか。
//12文字ならKMPとかするまでもないね。
sort(vec.begin(),vec.end(),[](auto const& l,auto const& r){
if(l.size()==r.size())return l>r;
return l.size()>r.size();
});//文字列長い順にsort
vector<pair<string,int>> cur;
for(int i=0;i<vec.size();i++){
string a=vec[i]; // 今から、aの判定をします
bool f=false;
for(int j=0;j<cur.size();j++){
string b=cur[j].first; //bと比較します。
for(int k=0;k+a.size()<=b.size();k++){
if(b.substr(k,a.size())==a){
cur[j].second++;
f=true;
}
}
}
if(!f){
cur.push_back({a,0});
}
}
sort(cur.begin(),cur.end(),[](auto const& l,auto const& r){
if(l.second==r.second){
if(l.first.size()==r.first.size()){
return l.first>r.first;
}
return l.first.size()>r.first.size();
}
return l.second>r.second;
});
vector<string> ret;
for(int i=0;i<cur.size();i++){
ret.push_back(cur[i].first);
}
return ret;
}
int main(){
int n,m;
cin>>n>>m;
vector<string> v(m);
for(int i=0;i<m;i++){
cin>>v[i];
}
v=unique(v);
m=v.size();
vector<string> b(n,string(n,'.'));
int cov=0;
for(int i=0;i<m;i++){//iを埋め込む。
bool ac=false;
for(int j=0;j<n;j++){
for(int k=0;k<n;k++){
bool f=true;
for(int l=0;l<v[i].size();l++){
if(b[j][(k+l)%n]!='.'&&b[j][(k+l)%n]!=v[i][l]){
f=false;
break;
}
}
if(f){
for(int l=0;l<v[i].size();l++){
b[j][(k+l)%n]=v[i][l];
}
ac=true;
cov++;
break;
}
}
if(ac){
break;
}
}
}
for(int i=0;i<n;i++){
cout<<b[i]<<endl;
}
// cerr<<"Analytics:"<<endl<<" Actual M="<<m<<endl<<" Cover Piece="<<cov<<endl;
return 0;
} |
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
#include<iostream>
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 mod = 998244353;
const int IMAX = 10000;
constexpr ll modpow(ll A, ll B) {
ll kotae = 1;
while (B > 0) {
if (B & 1) kotae = kotae * A % mod;
A = A * A % mod;
B >>= 1;
}
return kotae;
}
class unko {
public:
int fac[IMAX + 1], ifac[IMAX + 1], inv[IMAX + 1];
constexpr unko() : fac(), ifac(), inv() {
fac[0] = 1;
rep1(i, IMAX) fac[i] = ll(fac[i - 1]) * i % mod;
ifac[IMAX] = modpow(fac[IMAX], mod - 2);
for (int i = IMAX; i > 0; i--) ifac[i - 1] = ll(ifac[i]) * i % mod;
inv[0] = 1;
rep1(i, IMAX) inv[i] = ll(ifac[i]) * fac[i - 1] % mod;
}
int comb(int A, int B) {
return ll(fac[A]) * ifac[B] % mod * ifac[A - B] % mod;
}
} f;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N, M;
cin >> N >> M;
if (M & 1) {
co(0);
return 0;
}
ll dp[5001] = {};
dp[0] = 1;
int cb[5001] = {};
for (int i = 1; i * 2 <= N; i++) {
cb[i] = f.comb(N, i * 2);
}
rep1(k, 12) {
int are = (1 << k);
int kari = 0;
for (int i = M - are; i >= 0; i -= are) {
for (int j = kari + 1; 2 * j <= N && i + are * j <= M; j += 2) {
(dp[i + are * j] += dp[i] * cb[j]) %= mod;
}
kari ^= 1;
}
}
co(dp[M]);
Would you please return 0;
} | //#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using db = double;
using ld = long double;
template <typename T> using V = vector<T>;
template <typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define siz(v) (ll)(v).size()
#define rep(i, a, n) for(ll i = a; i < (ll)(n); ++i)
#define repr(i, a, n) for(ll i = n - 1; (ll)a <= i; --i)
#define ENDL '\n'
typedef pair<int, int> Pi;
typedef pair<ll, ll> PL;
constexpr ll mod = 1000000007; // 998244353;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 + 99);
const ld PI = acos((ld)-1);
const vector<ll> dx = {-1, 0, 1, 0}, dy = {0, 1, 0, -1};
template <typename T, typename U> inline bool chmin(T& t, const U& u) {
if(t > u) {
t = u;
return 1;
}
return 0;
}
template <typename T, typename U> inline bool chmax(T& t, const U& u) {
if(t < u) {
t = u;
return 1;
}
return 0;
}
template <typename T> inline T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
inline void yes() { cout << "Yes" << ENDL; }
inline void no() { cout << "No" << ENDL; }
template <typename T, typename Y> inline T mpow(T a, Y n) {
T res = 1;
for(; n; n >>= 1) {
if(n & 1) res = res * a;
a = a * a;
}
return res;
}
template <typename T> V<T> prefix_sum(const V<T>& v) {
int n = v.size();
V<T> ret(n + 1);
rep(i, 0, n) ret[i + 1] = ret[i] + v[i];
return ret;
}
template <typename T> istream& operator>>(istream& is, vector<T>& vec) {
for(auto&& x : vec) is >> x;
return is;
}
template <typename T, typename Y>
ostream& operator<<(ostream& os, const pair<T, Y>& p) {
return os << "{" << p.fs << "," << p.sc << "}";
}
template <typename T> ostream& operator<<(ostream& os, const V<T>& v) {
os << "{";
for(auto e : v) os << e << ",";
return os << "}";
}
template <typename... Args> void debug(Args&... args) {
for(auto const& x : {args...}) { cerr << x << ' '; }
cerr << ENDL;
}
ll dp[55][55]={};
signed main() {
cin.tie(0);
cerr.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
ll n, x;
cin >> n >> x;
V<ll> v(n);
cin >> v;
V<ll> ned(n, 0);
ll tmp=x;
repr(i, 0, n) {
ned[i] = tmp / v[i];
tmp %= v[i];
}
dp[0][0]=1;
rep(i,0,n-1){
dp[i+1][0]+=dp[i][0];
if((1+ned[i])*v[i]<v[i+1])dp[i+1][0]+=dp[i][1];
/*
if(ned[i]){
dp[i+1][0]+=dp[i][0]+dp[i][1];
}else{
dp[i+1][0]+=dp[i][1];
}*/
if(ned[i]){
dp[i+1][1]+=dp[i][0];
dp[i+1][1]+=dp[i][1];
}
else dp[i+1][1]+=dp[i][1];
}
cout<<dp[n-1][0]+dp[n-1][1]<<ENDL;
}
//! ( . _ . ) !
// CHECK overflow,vector_size,what to output? |
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
#include <cctype>
#include <bitset>
#include <cmath>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
using namespace std;
typedef long long ll;
int n;
int gcd(int a,int b){
return b==0?a:gcd(b,a%b);
}
void solve(){
scanf("%d",&n);
int GCD=0;
for(int i=1;i<=n;i++){
int x;
scanf("%d",&x);
GCD=gcd(GCD,x);
}
printf("%d\n",GCD);
}
int main(){
solve();
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for( int i=0; i<(n); i++)
int main(){
ll n; cin >> n;
map<ll, ll> mp;
for(int i = 0; i < n; i++){
int a; cin >> a;
mp[a] += 1;
}
ll res = 0;
auto begin = mp.begin(), end = mp.end();
for(auto iter = begin; iter != end; iter++) res += iter->second * (iter->second - 1) / 2;
cout << n*(n-1)/2 - res << endl;
} |
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define INF63 1061109567
#define INF127 9187201950435737471
#define UINF 18446744073709551615
#define F first
#define S second
#define ll long long
using namespace std;
ll mod;
ll ksm(ll x,ll y)
{
if(y==0)
{
return 1;
}
ll ret=ksm(x,y>>1);
ret=(ret*ret)%mod;
if(y&1)
{
ret=(ret*x)%mod;
}
return ret;
}
ll a,b,c,vis[15];
vector<ll> md;
int main(){
ll i,x,st;
cin>>a>>b>>c;
x=1;
memset(vis,-1,sizeof(vis));
for(i=0;i<100;i++)
{
md.push_back(x);
vis[x]=i;
x*=a;
x%=10;
if(vis[x]!=-1)
{
st=vis[x];
break;
}
}
mod=md.size()-st;
x=(ksm(b,c)-st+100*mod)%mod+st;
mod=10;
cout<<ksm(a,x)<<endl;
return 0;
} | #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 4000000000000000000 //オーバーフローに注意
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;
ll mod_pow(ll x,ll count, ll mod){
if(count == 0)return 1;
ll ret = mod_pow((x*x)%mod,count/2,mod);
if(count%2 == 1){
ret = (ret*x)%mod;
}
return ret;
}
int main(){
ll A,B,C;
scanf("%lld %lld %lld",&A,&B,&C);
ll ch = A%10;
if(ch == 1 || ch == 6 || ch == 5){
printf("%lld\n",ch);
return 0;
}
ll mult = mod_pow(B,C,4);
ll ans = mod_pow(ch,mult+4,10);
printf("%lld\n",ans);
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i,N) for(int i=0; i<(N); i++)
using namespace std;
int main() {
string s;
cin >> s;
cout << s.at(1) << s.at(2) << s.at(0) <<endl;
} | #include <bits/stdc++.h>
const long long INF = 1e9;
const long long MOD = 1e9 + 7;
//const long long MOD = 998244353;
const long long LINF = 1e18;
using namespace std;
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE" ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible" ) << endl
#define dump(x) cout << #x << " = " << (x) << endl
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define COUT(x) cout<<(x)<<endl
#define SCOUT(x) cout<<(x)<<" "
#define VECCOUT(x) for(auto&youso_: (x) )cout<<right<<setw(10)<<youso_<<" ";cout<<endl
#define ENDL cout<<endl
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) long long __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define mp make_pair
#define PQ priority_queue<long long>
#define PQG priority_queue<long long,V,greater<long long>>
typedef long long ll;
typedef vector<long long> vl;
typedef vector<long long> vi;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<vb> vvb;
typedef vector<vc> vvc;
typedef pair<long long, long long> pll;
#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
cin>>head;
CINT(move(tail)...);
}
template<class T>
void mod(T &x) {
x %= MOD;
x += MOD;
x %= MOD;
}
ll GCD(ll a, ll b) {
if(b == 0) return a;
else return GCD(b, a%b);
}
struct COMB{
vl fact, fact_inv, inv;
void init_nCk(long long SIZE) {
fact.resize(SIZE + 5);
fact_inv.resize(SIZE + 5);
inv.resize(SIZE + 5);
fact.at(0) = fact.at(1) = fact_inv.at(0) = fact_inv.at(1) = inv.at(1) = 1;
for(long long i = 2; i < SIZE + 5; i++) {
fact.at(i) = fact.at(i - 1)*i%MOD;
inv.at(i) = MOD - inv.at(MOD%i)*(MOD/i)%MOD;
fact_inv.at(i) = fact_inv.at(i - 1)*inv.at(i)%MOD;
}
}
long long nCk (long long n, long long k) {
assert(!(n < k));
assert(!(n < 0 || k < 0));
return fact.at(n)*(fact_inv.at(k)*fact_inv.at(n - k)%MOD)%MOD;
}
};
ll extGCD(ll a, ll b, ll &x, ll &y) {
if(b == 0) {
x = 1;
y = 0;
return a;
}
ll d = extGCD(b, a%b, y, x);
y -= a/b*x;
return d;
}
void Main() {
SCIN(S);
for(int i = 0; i < S.size(); i++) {
cout << S.at((i + 1)%S.size());
}
cout << endl;
}
int main() {
cout << fixed << setprecision(15);
Main();
return 0;
} |
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define ssort(a) sort(a.begin(), a.end())
#define INF 1001001001
#define INFll 10010010010010010
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;
using namespace std;
using ull = unsigned long long;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;
int main(){
int n, m;
cin >> n >> m;
vector<int> h(n);
vector<int> w(m);
rep(i, n){
cin >> h[i];
}
ssort(h);
rep(i, m){
cin >> w[i];
}
vector<ll> pair1((n-1)/2+1);
vector<ll> pair2((n-1)/2+1);
rep(i, (n-1)/2){
if(i>0){
pair1[i]=h[2*i+1]-h[2*i]+pair1[i-1];
} else {
pair1[i]=h[2*i+1]-h[2*i];
}
}
for(int i=(n-1)/2-1; i>=0; i--){
if(i<(n-1)/2-1){
pair2[i]=h[2*i+2]-h[2*i+1]+pair2[i+1];
} else {
pair2[i]=h[2*i+2]-h[2*i+1];
}
}
ll ans=INFll;
rep(i, m){
int wit=lower_bound(h.begin(), h.end(), w[i])-h.begin();
ll cand=0;
if(wit%2==0){
cand+=h[wit]-w[i];
} else {
cand+=w[i]-h[wit-1];
}
if(wit/2==0){
cand+=pair2[0];
} else if(wit/2==(n-1)/2){
cand+=pair1[wit/2-1];
} else {
cand+=pair1[wit/2-1]+pair2[wit/2];
}
ans=min(ans, cand);
}
cout << ans << endl;
return 0;
}
| #define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
const int N = 1e8 + 10;
typedef long long ll;
int main(){
int t,n,m;
cin>>n>>m;
int ans1=0,ans2=0;
while(n){
ans1+=n%10;
n/=10;
}
while(m){
ans2+=m%10;
m/=10;
}
cout<<max(ans1,ans2)<<endl;
return 0;
}
|
#include "bits/stdc++.h"
using namespace std;
/*
find my code templates at https://github.com/galencolin/cp-templates
also maybe subscribe please thanks
*/
#define send {ios_base::sync_with_stdio(false);}
#define help {cin.tie(NULL);}
#define f first
#define s second
#define getunique(v) {sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end());}
typedef long long ll;
// typedef int ll;
// #pragma warning("int")
typedef long double lld;
typedef unsigned long long ull;
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v);
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.f << ", " << p.s << ")"; }
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) {
cout << "["; for(int i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]";
}
template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p) {
cin >> p.first;
return cin >> p.second;
}
mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 rng(61378913);
/* usage - just do rng() */
void usaco(string filename) {
// #pragma message("be careful, freopen may be wrong")
freopen((filename + ".in").c_str(), "r", stdin);
freopen((filename + ".out").c_str(), "w", stdout);
}
// #include <atcoder/all>
// using namespace atcoder;
const lld pi = 3.14159265358979323846;
// const ll mod = 1000000007;
// const ll mod = 998244353;
// ll mod;
ll n, m, q, k, l, r, x, y, z;
const ll template_array_size = 1e6 + 15258;
ll a[template_array_size];
ll b[template_array_size];
ll c[template_array_size];
string s, t;
void solve(int tc = 0) {
cin >> n >> s >> t;
string a = s, b = t;
sort(a.begin(), a.end());
sort(b.begin(), b.end());
if (a != b) {
cout << "-1\n";
return;
}
vector<ll> at;
for (ll i = 0; i < n; i++) if (t[i] == '0') at.push_back(i);
ll ans = 0, pt = 0;
for (ll i = 0; i < n; i++) {
if (s[i] == '0') {
if (i != at[pt++]) ++ans;
}
}
cout << ans << '\n';
}
int main() {
#ifdef galen_colin_local
auto begin = std::chrono::high_resolution_clock::now();
#endif
send help
#ifndef galen_colin_local
// usaco("code");
#endif
// usaco("cowland");
// freopen("tc.cpp", "r", stdin);
// freopen("tc2.cpp", "w", stdout);
cout << setprecision(15) << fixed;
int tc = 1;
// cin >> tc;
for (int t = 0; t < tc; t++) solve(t);
#ifdef galen_colin_local
auto end = std::chrono::high_resolution_clock::now();
cerr << setprecision(4) << fixed;
cerr << "Execution time: " << std::chrono::duration_cast<std::chrono::duration<double>>(end - begin).count() << " seconds" << endl;
#endif
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
int main() {
string s, t;
int n;
cin >> n;
cin >> s >> t;
vector<int> szero;
vector<int> tzero;
REP(i, n) {
if (s[i] - '0' == 0) {
szero.push_back(i);
}
if (t[i] - '0' == 0) {
tzero.push_back(i);
}
}
if (szero.size() != tzero.size()) {
cout << -1 << endl;
return 0;
}
int length = szero.size();
int ans = 0;
REP(i, length) {
if (szero[i] != tzero[i]) {
ans++;
}
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define mod 1000000007
int main() {
#ifndef ONLINE_JUDGE
// for getting input from input.txt
freopen("input.txt", "r", stdin);
// for writing output to output.txt
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n;
cin>>n;
vector<pair<ll,ll>> v1,v2;
for(ll i=0;i<n;i++)
{
ll l,r;
cin>>l>>r;
v1.push_back({l,i});
v2.push_back({r,i});
}
sort(v1.begin(),v1.end());
sort(v2.begin(),v2.end());
if(v1[0].second==v2[0].second)
{
ll ans=min(v1[0].first+v2[0].first,min(max(v1[0].first,v2[1].first),max(v1[1].first,v2[0].first)));
cout<<ans<<endl;
}
else
cout<<max(v1[0].first,v2[0].first)<<endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define io ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
// debug & operator << (debug & dd, P p) { dd << "(" << p.x << ", " << p.y << ")"; return dd; }
int main() {
int n;
scanf("%d", &n);
int a[n][2];
for(int i = 0; i < n; ++i){
scanf("%d", &a[i][0]);
scanf("%d", &a[i][1]);
}
int ans = 1e9 + 7;
for(int i = 0; i < n; ++i){
ans = min(ans, a[i][0] + a[i][1]);
}
for(int i = 0; i < n; ++i){
int val1 = a[i][0];
int val2 = a[i][1];
for(int j = 0; j < n; ++j){
if(i != j) {
ans = min(ans, max(val1, a[j][1]));
ans = min(ans, max(val2, a[j][0]));
}
}
}
printf("%d\n", ans);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
vector<int> ans(n);
for (int i = 1; i <= n; i++) {
multiset<int> st;
int now = i;
for (int j = 2; j * j <= n; j++) {
while (now % j == 0) {
st.insert(j);
now /= j;
}
}
if (now >= 2) st.insert(now);
ans.at(i - 1) = st.size() + 1;
}
for (int i = 0; i < n; i++) {
if (i) cout << " ";
cout << ans.at(i);
}
cout << '\n';
} | #pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define DEBUG
#ifdef DEBUG
inline void debug_print() { cerr << endl; }
template <typename T1, typename... T2> void debug_print(const T1 a, const T2 &... b) { cerr << a << ' '; debug_print(b...); }
#define debug(...) cerr << __LINE__ << ": [" << #__VA_ARGS__ << "] = " , debug_print(__VA_ARGS__);
#else
#define debug(...) true
#endif
inline void print() { cout << '\n'; }
template <typename T1, typename... T2> void print(const T1 a, const T2 &... b) { cout << a << ' '; print(b...); }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; }
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto e : v) os << e << ' '; return os; }
template <typename T> ostream &operator<<(ostream &os, const set<T> &v) { for (auto e : v) os << e << ' '; return os; }
template <typename T> ostream &operator<<(ostream &os, const multiset<T> &v) { for (auto e : v) os << e << ' '; return os; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &mp) { for (auto e : mp) os << e << ' '; return os; }
template <typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } else return false; }
template <typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } else return false; }
const int INF = (1<<30)-1;
const long long LINF = 1LL<<60;
const double EPS = 1e-10;
const int MOD = 1000000007;
//const int MOD = 998244353;
const int dx[8] = {-1,0,1,0,1,-1,1,-1};
const int dy[8] = {0,1,0,-1,1,-1,-1,1};
//-------------------------- Libraries --------------------------//
//--------------------------- Solver ----------------------------//
void solve() {
int N;
cin >> N;
if (N == 1) {
cout << 1 << '\n';
return;
}
vector<int> A(N+1, 1);
for (int i = 2; i <= N; i++) {
for (int j = i+i; j <= N; j+=i) {
A[j] = A[i]+1;
}
}
int ma = 0;
for (int i = 0; i <= N; i++) {
chmax(ma, A[i]);
}
A[1] = ma+1;
for (int i = 1; i <= N; i++) {
cout << A[i] << ' ';
}
cout << '\n';
}
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(20);
int t = 1;
//cin >> t;
while (t--) solve();
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[65][3];
ll n;
vector<ll>v;
void ctdp()
{
dp[0][0]=1;
dp[0][1]=1;
for(ll i=1;i<=n;i++){
if(v[i-1]==0){
dp[i][0]=dp[i-1][0];
dp[i][1]=dp[i-1][0]+(2*dp[i-1][1]);
}else{
dp[i][0]=(2*dp[i-1][0])+dp[i-1][1];
dp[i][1]=dp[i-1][1];
}
}
}
int main()
{
cin>>n;
for(ll i=0;i<n;i++){
string tmp;
cin>>tmp;
if(tmp=="AND")v.push_back(1);
else v.push_back(0);
}
ctdp();
cout<<dp[n][1]<<endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const int N=4e5+2;
int stk[N],top;
int n,m,p,e,a[N],b[N];
int main()
{
scanf("%d",&n);
m=n<<1;
for(int i=1;i<=m;++i)
{
scanf("%d",&a[i]);
b[i]=a[i];
}
sort(b+1,b+m+1);
for(int i=1;i<=m;++i)
if(a[i]<b[n])++p;
else if(a[i]>b[n])++e;
for(int i=1;i<=m;++i)
{
int fl=0;
if(a[i]>b[n])fl=1;
else if(a[i]==b[n]&&p<n)++p;
else if(a[i]==b[n]&&p==n)fl=1,++e;
//else if(a[i]==b[n]&&!top)fl=1,++e;
if(top&&stk[top]!=fl)putchar(')'),--top;
else stk[++top]=fl,putchar('(');
}
}
|
// Problem: C. The Sports Festival
// Contest: Codeforces - Codeforces Round #715 (Div. 2)
// URL: https://codeforces.com/contest/1509/problem/C
// Memory Limit: 256 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)
/*
authored by
aden_frost
on 07-03-2021
Go Corona Corona Go!!
hurray! mission - 1 - completed;
mission - 2
____________
40 more to go
*/
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define lli long long int
#define MOD1 998244353
#define MOD 1000000007
using namespace std;
using namespace std::chrono;
void fastaf(void)
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
void solve(void)
{
lli N,M;
map<lli,lli>mp;
cin>>N>>M;
for(int i=0;i<N;i++)
{
string S;
cin>>S;
lli sum=0;
for(int j=0;j<M;j++)
sum+=(S[j]-'0');
mp[sum]++;
}
lli ans=0;
for(auto x: mp)
{
lli sum=0;
for(auto y: mp)
{
if((x.first!=y.first)&&(abs(x.first-y.first)%2!=0))
{
sum+=y.second;
}
}
sum*=x.second;
ans+=sum;
}
ans/=2;
cout<<ans;
}
/*
- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
*/
int main()
{
fastaf();
int Testcases=1;
//cin>>Testcases;
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
while(Testcases--)
{
solve();
cout<<"\n";
}
return 0;
} | #include<stdio.h>
#define reg register
#define ri reg int
#define rep(i, x, y) for(ri i = x; i <= y; ++i)
#define nrep(i, x, y) for(ri i = x; i >= y; --i)
#define DEBUG 1
#define ll long long
#define il inline
#define swap(a, b) ((a) ^= (b) ^= (a) ^= (b))
#define max(i, j) (i) > (j) ? (i) : (j)
#define min(i, j) (i) < (j) ? (i) : (j)
#define read(i) io.READ(i)
#define print(i) io.WRITE(i)
#define push(i) io.PUSH(i)
struct IO {
#define MAXSIZE (1 << 20)
#define isdigit(x) (x >= '0' && x <= '9')
char buf[MAXSIZE], *p1, *p2;
char pbuf[MAXSIZE], *pp;
#if DEBUG
#else
IO() : p1(buf), p2(buf), pp(pbuf) {}
~IO() {
fwrite(pbuf, 1, pp - pbuf, stdout);
}
#endif
inline char gc() {
#if DEBUG
return getchar();
#endif
if(p1 == p2)
p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, stdin);
return p1 == p2 ? ' ' : *p1++;
}
inline bool blank(char ch) {
return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t';
}
template <class T>
inline void READ(T &x) {
register double tmp = 1;
register bool sign = 0;
x = 0;
register char ch = gc();
for(; !isdigit(ch); ch = gc())
if(ch == '-') sign = 1;
for(; isdigit(ch); ch = gc())
x = x * 10 + (ch - '0');
if(ch == '.')
for(ch = gc(); isdigit(ch); ch = gc())
tmp /= 10.0, x += tmp * (ch - '0');
if(sign) x = -x;
}
inline void READ(char *s) {
register char ch = gc();
for(; blank(ch); ch = gc());
for(; !blank(ch); ch = gc())
*s++ = ch;
*s = 0;
}
inline void READ(char &c) {
for(c = gc(); blank(c); c = gc());
}
inline void PUSH(const char &c) {
#if DEBUG
putchar(c);
#else
if(pp - pbuf == MAXSIZE) {
fwrite(pbuf, 1, MAXSIZE, stdout);
pp = pbuf;
}
*pp++ = c;
#endif
}
template <class T>
inline void WRITE(T x) {
if(x < 0) {
x = -x;
PUSH('-');
}
static T sta[35];
T top = 0;
do {
sta[top++] = x % 10;
x /= 10;
} while(x);
while(top)
PUSH(sta[--top] + '0');
}
template <class T>
inline void WRITE(T x, char lastChar) {
WRITE(x);
PUSH(lastChar);
}
} io;
ll n, m, odd, even, num, a;
int main() {
read(n), read(m);
rep(i, 1, n) {
num = 0;
rep(j, 1, m) {
scanf("%1lld", &a);
num += a;
}
if(num % 2) ++odd;
else ++even;
}
print(odd * even);
} |
#include<bits/stdc++.h>
#define lint long long int
#define rep(i,n) for(int i=0;i<int(n);i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define arep(i,a,n) for(int i=a;i<n;i++)
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define fill(a,x) fill(a.begin(),a.end(),x)
#define eb(data) emplace_back(data)
#define pb(data) emplace_back(data)
#define mp make_pair
#define ALNUM 26
#define vint vector<int>
#define vlint vector<lint>
#define F first
#define S second
#define ALL(data) data.begin(),data.end()
#define GEts(s) getline(cin,s);
#define UNIQUE(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())
using namespace std;
template<typename Rast>inline void out(Rast rast){cout<<rast<<"\n";return;}
template<typename Rast>inline void in(Rast& rast){cin>>rast;return;}
template<typename T>istream& operator >> (istream& is, vector<T>& vec){for(T& x: vec) is >> x;return is;}
template<typename First, typename... Rest>void in(First& first, Rest&... rest){cin >> first;in(rest...);return;}
template<typename First, typename... Rest>void out(First first, Rest... rest){cout << first<<" ";out(rest...);return;}
template<typename T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<typename T>T lcm(T a,T b){return a * b / gcd(a, b);}
template<typename T1,typename T2>bool chmax(T1& a,T2 b){if(a<b){a=b;return true;}else{return false;}}
template<typename T1,typename T2>bool chmin(T1& a,T2 b){if(a>b){a=b;return true;}else{return false;}}
static const double pi = 3.141592653589793;
int modpow(int a,int n,int p){if (n==0)return 1%p; if(n==1)return a%p;if(n%2==1)return (a*modpow(a,n-1,p))%p;lint t=modpow(a,n/2,p);return (t*t)%p;}//a^n%p
lint MOD=pow(10,9)+7;
//lint MOD=998244353;
lint inf=pow(2,50);
int intinf=pow(2,30);
/**/int dirx[]={1,0};int diry[]={0,1};//*///右、下
/**int dirx[]={0,1,0,-1};int diry[]={-1,0,1,0};//*///四方位
/**int dirx[]={-1,0,1,1,1,0,-1,-1};int diry[]={-1,-1,-1,0,1,1,1,0};//*///八方位
class unionfind{
public:
vector<int> table;
void init(int size){
table.resize(size);
rep(i,size)table[i]=i;
};
int root(int index){
if(table[index]==index)return index;
else{
int hoge=root(table[index]);
table[index]=hoge;
return hoge;
}
};
bool same(int x,int y){
return(root(x)==root(y));
};
int marge(int x,int y){
int yroot=root(y);
int xroot=root(x);
if(xroot==yroot)return 0;
table[yroot]=xroot;
return 0;
}
int getsize(){
set<int> ma;
rep(i,table.size())ma.insert(root(i));
int re=ma.size();
return re;
}
};
int main(){
cin.tie(0);ios::sync_with_stdio(false);cout<<std::fixed<<std::setprecision(10);
int n,m;
in(n,m);
vlint a(n),b(n);
vint c(m),d(m);
in(a,b);
rep(i,m)in(c[i],d[i]);
unionfind uni;
uni.init(n);
rep(i,m)uni.marge(c[i]-1,d[i]-1);
map<int,lint> ma;
map<int,lint> mb;
rep(i,n)ma[uni.root(i)]+=a[i];
rep(i,n)mb[uni.root(i)]+=b[i];
rep(i,n){
if(ma[uni.root(i)]!=mb[uni.root(i)]){
out("No");
return 0;
}
}
out("Yes");
return 0;
}
| #include<bits/stdc++.h>
#define int long long
#define N 200010
using namespace std;
int n,m;
int a[N];
vector<int> v[N];
int dp[N],ans[N],res=-1e18;
signed main(){
scanf("%lld%lld",&n,&m);
for(int i=1;i<=n;i++)
scanf("%lld",&a[i]);
for(int i=1;i<=m;i++){
int x,y;
scanf("%lld%lld",&x,&y);
v[x].push_back(y);
}
for(int i=1;i<=n;i++)
ans[i]=-1e18;
for(int i=n;i>=1;i--){
for(int j=0;j<v[i].size();j++){
if(dp[v[i][j]]+a[v[i][j]]-a[i]>dp[i]){
dp[i]=dp[v[i][j]]+a[v[i][j]]-a[i];
}
if(dp[v[i][j]]+a[v[i][j]]-a[i]>ans[i]){
ans[i]=dp[v[i][j]]+a[v[i][j]]-a[i];
}
}
}
for(int i=1;i<=n;i++)
res=max(res,ans[i]);
cout<<res<<endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
// template {{{
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
#define range(i, l, r) for (i64 i = (i64)(l); i < (i64)(r); (i) += 1)
#define rrange(i, l, r) for (i64 i = (i64)(r) - 1; i >= (i64)(l); (i) -= 1)
#define whole(f, x, ...) ([&](decltype((x)) container) { return (f)( begin(container), end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)
#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl
constexpr i32 inf = 1001001001;
constexpr i64 infll = 1001001001001001001ll;
constexpr i32 dx[] = {0, -1, 1, 0, -1, 1, -1, 1};
constexpr i32 dy[] = {-1, 0, 0, 1, -1, -1, 1, 1};
struct IoSetup { IoSetup(i32 x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;
template <typename T = i64> T input() { T x; cin >> x; return x; }
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != (int)v.size() ? " " : ""); } return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// }}}
vector<i64> divisor(i64 n) {
vector<i64> res;
for (i64 i = 1; i * i <= n; i++) {
if (n % i != 0) continue;
res.emplace_back(i);
if (i * i == n) continue;
res.emplace_back(n / i);
}
return res;
}
void solve() {
i64 s = input(), p = input();
auto ds = divisor(p);
for (auto &d : ds) {
i64 n = d, m = p / d;
if (n + m != s) continue;
cout << "Yes" << endl;
return;
}
cout << "No" << endl;
}
signed main() {
solve();
}
| #include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ll S, P; cin >> S >> P;
for (ll i = 1; i * i <= P; i++) {
if (P % i) continue;
if (i + P / i == S) {
cout << "Yes" << endl;
return 0;
}
}
cout << "No" << endl;
} |
#include <iostream>
using namespace std;
int main()
{
int a,b,c,result;
cin>>a >>b>>c;
if((a*a)+(b*b) < (c*c))
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
} | #include<iostream>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<stdio.h>
#include<set>
#include<queue>
#include<stack>
#include<cstring>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <sstream>
//#include<bits/stdc++.h>
#define FILE_NAME "A"
#define mp make_pair
#define SZ(x) (int)x.size()
#define pb push_back
#define fi first
#define se second
#define watch(x) cout << (#x) << " is " << (x) << endl
#define whole(x) x.begin(), x.end()
#define in insert
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
const ll maxn = (2e5) + 11;
const int MOD = (1e9) + 7;
const ll INF = (1e10) + 777;
const ld pi = 2 * acos(0.0);
const ll E9 = 1e9;
const ll E8 = 1e8;
const ll E7 = 1e7;
const ll E6 = 1e6;
const ll E5 = 1e5;
const ll E4 = 1e4;
const ll E3 = 1e3;
ll toup(ll n,int div){
return n%div==0?(n/div):((n+(div-n%div))/div);
}
ll n,sum=0,er,er2,m,ans=0,a[maxn],cnt=0,pref[maxn],l,r;
string s,t;
//map<ll,int>mm;
vector<ll>v;
//vector<ll>v;
//vector<pair<ll,ll>>vp;
//vector<pair<int,int>>g[50000];
void solve() {
ll k;
cin>>n>>m>>k;
cout<<(n*n+m*m<k*k?"Yes":"No");
}
int main(){
int test=1;
// cin>>test;
while(test--){
solve();
// nosolve();
}
} |
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define get(a) ll a ; cin >> a ;
#define show(a) cout << a << endl;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
double a, b, w;
cin >> a >> b >> w;
int lower = int(ceil(1000*w/b)) ;
int upper = int(floor(1000*w/a));
if(lower > upper)
cout << "UNSATISFIABLE" << endl;
else
cout << lower << " " << upper << endl;
return 0;
} | #include <iostream>
using namespace std;
int A, B;
double W;
int isin(double N) {
if(N >= A and N <= B) {
return true;
} else {
return false;
}
}
int main() {
cin >> A >> B >> W;
int max = 0;
int min = 0;
for (int i = 1; i <= W * 1000; i++) {
double pre = W * 1000 / i;
if(isin(pre)) {
min = i;
break;
}
}
for (int i = W * 1000; i > 0; i--) {
double pre = W * 1000 / i;
if(isin(pre)) {
max = i;
break;
}
}
if (min == 0) {
min = max;
}
if (max == 0) {
max = min;
}
if (min == 0 and max == 0) {
cout << "UNSATISFIABLE" << endl;
} else {
cout << min << " " << max << endl;
}
} |
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using tii = tuple<int,int,int>;
template<typename T>bool chmin(T&x,const T&y) {if(x>y){x=y;return 1;} else return 0;}
template<typename T>bool chmax(T&x,const T&y) {if(x<y){x=y;return 1;} else return 0;}
int main() {
double a, b, c;
cin >> a >> b >> c;
ll X, Y, R;
X = round(a * 10000);
Y = round(b * 10000);
R = round(c * 10000);
ll top = (Y + R) / 10000 * 10000 + 60000;
while (top > Y + R) top -= 10000;
ll down = (Y-R) / 10000 * 10000 - 60000;
while (down < Y - R) down += 10000;
ll ans = 0;
for (ll y = down; y <= top; y += 10000) {
ll l = sqrt(R * R - (y - Y) * (y - Y)) + 10;
while (l * l > R * R - (y-Y) * (y-Y)) l--;
ll left = (X - l) / 10000 * 10000 - 60000;
while (left < X - l) left += 10000;
ll right = (X + l) / 10000 * 10000 + 60000;
while (right > X + l) right -= 10000;
if (left > right) continue;
ans += (right - left) / 10000 + 1;
// cout << left << ' ' << right << ' ' << l << '\n';
// cout << ans << '\n';
}
cout << ans << '\n';
return 0;
// get dp together, ll, paraphrase, debug
}
// 07 | #include <iostream>
#include <cmath>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
using ll = long long;
int in(){
double x;
cin >> x;
x*=10000;
return round(x);
}
bool ok(ll dx,ll dy,ll z){
return dx*dx+dy*dy <= z*z;
}
ll f(ll x,ll y,ll z,ll lim){
int l=0,r=1;
ll res = 0;
for(int i=1e9+50000;i>=lim;i-=10000){
while(ok(x-l*10000,i-y,z))--l;
while(ok(r*10000-x,i-y,z))r++;
res += r-l-1;
}
return res;
}
int main(){
ll x=in(),y=in(),z=in();
x%=10000;
y%=10000;
ll ans = f(x,y,z,10000);
ans += f(x,-y,z,0);
cout << ans << endl;
return 0;
} |
// 状压表示点的集合
// 每次尝试加入一个点,看能不能构成一个完全图
// 若能,则这个点集的完全图数为1
// 否则采用环形DP的方法求最小完全图数
// 太菜了,写不出来QAQ
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = 18;
int n, m;
int grap[maxn + 1][maxn + 1];
int f[1 << maxn], good[1 << maxn];
int main() {
scanf("%d%d", &n, &m);
for (int i = 0; i < m; i++) {
int a, b;
scanf("%d%d", &a, &b);
grap[a][b] = 1;
grap[b][a] = 1;
}
for (int i = 1; i < (1 << n); i++) {
vector<int> u;
for (int j = 1; j <= n; j++) {
if (i & (1 << (j - 1))) u.push_back(j);
}
good[i] = true;
for (int j = 0; j < u.size(); j++) {
for (int k = j + 1; k < u.size(); k++) {
if (!grap[u[j]][u[k]]) good[i] = false;
}
}
}
for (int i = 1; i < (1 << n); i++)
f[i] = INF;
for (int i = 1; i < (1 << n); i++) {
if (good[i]) {
f[i] = 1;
continue;
}
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>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using PP = std::pair<ll,P>;
#define REP(i,b,e) for(int i=b; i<e; i++)
#define PRINT(vec) {printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");}
#define fi first
#define se second
const int MOD = 1e9+7;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
int main(){
ll n, k;
scanf("%ld %ld", &n, &k);
ll dist[n][n];
REP(i, 0, n) REP(j, 0, n) scanf("%ld", &dist[i][j]);
ll ans = 0;
ll a[n-1];
REP(i, 0, n-1) a[i] = i+1;
do{
ll tmp = dist[0][a[0]];
REP(i, 1, n-1){
tmp += dist[a[i-1]][a[i]];
}
tmp += dist[a[n-2]][0];
if(tmp==k) ans++;
}while(std::next_permutation(a, a+n-1));
printf("%ld\n", ans);
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;
/*
実行時MODint :
template <int& MOD = 1000000007>
static int MOD;
cin >> MOD;
*/
template <int MOD = 1000000007>
struct Mint {
int x;
constexpr Mint() : x(0) {}
constexpr Mint(long long t)
: x(t >= 0 ? (t % MOD) : (MOD - (-t) % MOD) % MOD) {}
Mint pow(int n) {
Mint res(1), t(x);
while (n > 0) {
if (n & 1) res *= t;
t *= t;
n >>= 1;
}
return res;
}
Mint inv() const {
int a = x, b = MOD, u = 1, v = 0, t;
while (b > 0) {
t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
return Mint(u);
}
Mint &operator+=(Mint a) {
x += a.x;
if (x >= MOD) x -= MOD;
return *this;
}
Mint &operator-=(Mint a) {
x += MOD - a.x;
if (x >= MOD) x -= MOD;
return *this;
}
Mint &operator*=(Mint a) {
x = int(1LL * x * a.x % MOD);
return *this;
}
Mint &operator/=(Mint a) {
return (*this) *= a.inv();
}
Mint operator+(Mint a) const {
return Mint(x) += a;
}
Mint operator-(Mint a) const {
return Mint(x) -= a;
}
Mint operator*(Mint a) const {
return Mint(x) *= a;
}
Mint operator/(Mint a) const {
return Mint(x) /= a;
}
Mint operator-() const {
return Mint(-x);
}
bool operator==(const Mint a) {
return x == a.x;
}
bool operator!=(const Mint a) {
return x != a.x;
}
bool operator<(const Mint a) {
return x < a.x;
}
friend ostream &operator<<(ostream &os, const Mint &a) {
return os << a.x;
}
friend istream &operator>>(istream &is, Mint &a) {
int t;
is >> t;
a = Mint<MOD>(t);
return (is);
}
};
signed main() {
int n;
cin >> n;
char caa, cab, cba, cbb;
cin >> caa >> cab >> cba >> cbb;
if (n <= 3) {
cout << 1 << endl;
return 0;
}
if ((cab == 'A' && caa == 'A') || (cab == 'B' && cbb == 'B')) {
cout << 1 << endl;
return 0;
}
if ((cab == 'A' && caa == 'B' && cba == 'A') ||
(cab == 'B' && cbb == 'A' && cba == 'B')) {
Mint<> dp[n][2];
dp[0][0] = 1;
rep(i, n - 1) {
dp[i + 1][0] += dp[i][1];
dp[i + 1][1] += (dp[i][0] + dp[i][1]);
}
cout << dp[n - 1][1] << endl;
return 0;
}
cout << Mint<>(2).pow(n - 3) << endl;
return 0;
} | #include<bits/stdc++.h>
#include <iterator>
#include <iostream>
#include <numeric>
#include <math.h>
#define ll long long
#define ull long
#define mpa make_pair
#define pb push_back
#define ff first
#define pii pair<ll,ll>
#define dd double
#define trace(x) cerr << #x << " : " << x << endl
#define ss second
#define boost ios_base::sync_with_stdio(0)
#define forp(i,a,b) for(ll i=a;i<=b;i++)
#define rep(i,n) for(ll i=0;i<n;++i)
#define ren(i,n) for(ll i=n-1;i>=0;i--)
#define forn(i,a,b) for(ll i=a;i>=b;i--)
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end();
#define sc(x) scanf("%lld",&x)
#define clr(x,val) memset(x,val,sizeof(x))
#define pr(x) printf("%lld\n",x)
#define gc getchar
#define pdd pair<dd,dd>
#define read_arr(a,n) for(ll i=1;i<=n;i++)cin>>a[i];
#define init_arr(a,n) for(ll i=1;i<=n;i++)a[i]=n-i+1;
#define prec(x) cout<<fixed<<setprecision(x)
#define fre freopen("input.txt","r",stdin),freopen("output.txt","w",stdout)
#define arr array
using namespace std;
int main() {
ll n;
cin>>n;
if(n%2==0)cout<<"White";
else cout<<"Black";
}
|
#include <algorithm>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <thread>
#include <tuple>
#include <type_traits>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pii pair<int, int>
using namespace std;
using ll = long long;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
#define M (1'000'000'007)
int main() {
ios::sync_with_stdio(false);
int h, w;
cin >> h >> w;
vector<string> s(h);
for (int i = 0; i < h; i++) {
cin >> s[i];
}
int ans = 0;
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
for (int x = 0; x < w; x++) {
for (int y = 0; y < h; y++) {
if (s[y][x] != '.')
continue;
for (int i = 0; i < 4; i++) {
if (x + dx[i] >= 0 && x + dx[i] < w && y + dy[i] >= 0 &&
y + dy[i] < h) {
if (s[y + dy[i]][x + dx[i]] == '.')
ans++;
}
}
}
}
cout << ans / 2 << endl;
return 0;
}
| //Bismillah Hir Rehmanir Rahim
//Allah knows best
using namespace std;
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include<bits/stdc++.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#define endl "\n"
#define mini -10000000000000000
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define f(i, a, n) for( i=a; i<n;i++)
#define ll long long
#define pi 3.141592653589793
#define vi vector<int>
#define si set<int>
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rr return 0
#define ff first
#define in insert
#define ss second
#define setbits(x) __builtin_popcountll(x)
#define zrbits(x) __builtin_ctzll(x)
#define deb(x) cout << #x << " = " << x << endl
#define set_bit(x, idx) x = x|1LL<<idx
#define check_bit(x, idx) min(x&(1LL<<idx),1LL)
#define toggle_bit(x, idx) x = x^(1LL<<idx)
int main()
{
ios;
#ifdef DEBUG
freopen("input.txt", "r", stdin);
#endif
ll i,j,k,n,m;
cin>>n>>m;
string s[n],t;
f(i,0,n) cin>>s[i];
ll c=0,ct=0,ans=0;
for(i=0;i<n;i++)
{
t=s[i];
c=0;
for(j=0;j<m;j++)
{
if(t[j]=='.')
c++;
else
{
if(c>1)
ans=ans+c-1;
c=0;
}
}
if(c>1)
{
ans=ans+c-1;
c=0;
}
}
if(c>1)
{
ans=ans+c-1;
c=0;
}
c=0;
//deb(ans);
for(j=0;j<m;j++)
{
c=0;
for(i=0;i<n;i++)
{
// deb(s[i][j]);
if(s[i][j]=='.')
c++;
else
{
if(c>1)
ans=ans+c-1;
c=0;
}
}
if(c>1)
{
ans=ans+c-1;
c=0;
}
c=0;
}
cout<<ans<<endl;
rr;
} |
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef long long ll;
#define test ll t;cin>>t;while(t--)
#define f first
#define s second
#define pb push_back
#define pop pop_back
#define int long long int
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define mod 1000000007
#define inf 1LL<<60
int32_t main()
{
fast;
/*freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);*/
int h,m;
cin>>m>>h;
if(h%m==0)
cout<<"Yes"<<"\n";
else
cout<<"No"<<"\n";
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
int main(void)
{
int a,b;
cin>>a>>b;
if(b%a==0) cout<<"Yes\n";
else cout<<"No\n";
} |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.