code_file1
stringlengths 87
4k
| code_file2
stringlengths 85
4k
|
---|---|
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <numeric>
using namespace std;
int main(){
int N;
cin >> N;
vector<vector<int>> ability(N, vector<int>(5));
vector<int> max_ability(5);
for (int i=0; i<N; i++){
for (int j=0; j<5; j++){
cin >> ability.at(i).at(j);
max_ability.at(j) = max(ability.at(i).at(j), max_ability.at(j));
}
}
int ans = 0;
for (int i=0; i<N-1; i++){
for (int j=i+1; j<N; j++){ //候補者i,j
vector<int> candidate(5);
for (int k=0; k<5; k++) candidate.at(k) = max(ability.at(i).at(k), ability.at(j).at(k));
vector<int> order(5);
iota(order.begin(), order.end(),0);
sort(order.begin(), order.end(),[&](int x,int y) {
return candidate[x] > candidate[y];
});
ans = max(ans, min(candidate.at(order.at(3)), max_ability.at(order.at(4))));
}
}
cout << ans << endl;
} | #include <iostream>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <iterator>
#include <math.h>
#include <bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define MOD 1000000007;
#include <algorithm>
#include <cmath>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// int T,p;
// cin>>T;
// for(p=1;p<=T;p++)
// {
// ll N,M;
ll N;
cin>>N;
ll A[N][5],a,b,c,i,j,k;
vector <vector <pair <ll,ll> > > vect(5);
for(i=0;i<N;i++)
{
cin>>A[i][0]>>A[i][1]>>A[i][2]>>A[i][3]>>A[i][4];
vect[0].pb(mp(A[i][0],i));
vect[1].pb(mp(A[i][1],i));
vect[2].pb(mp(A[i][2],i));
vect[3].pb(mp(A[i][3],i));
vect[4].pb(mp(A[i][4],i));
}
sort(vect[0].begin(),vect[0].end());
sort(vect[1].begin(),vect[1].end());
sort(vect[2].begin(),vect[2].end());
sort(vect[3].begin(),vect[3].end());
sort(vect[4].begin(),vect[4].end());
ll ans=-1e15;
for(i=0;i<5;i++)
{
for(j=0;j<N;j++)
{
for(k=0;k<N;k++)
{
if(j==k)
continue;
a=1e15;
for(b=0;b<5;b++)
{
if(b==i)
continue;
a=min(a,max(A[j][b],A[k][b]));
}
b=N-1;
while((vect[i][b].second==k)||(vect[i][b].second==j))
{
b--;
}
a=min(a,vect[i][b].first);
ans=max(ans,a);
}
}
}
cout<<ans;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
cin.tie(0);
ios::sync_with_stdio(false);
set <int> s;
for (int i = 1; i <= 10000; i++)
{
if (i % 6 == 0 || i % 10 == 0 || i % 15 == 0)
{
s.insert(i);
}
}
int n;
cin >> n;
if (n == 3)
{
cout << 6 << ' ' << 10 << ' ' << 15 << '\n';
return 0;
}
for (auto it : s)
{
cout << it << ' ';
n--;
if (n == 0) break;
}
return 0;
} | #include <iostream>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
void solve(){
int n;
cin>>n;
double ans=0;
for(int i=1;i<n;i++){
ans+=(double)(n)/(double)(n-i);
}
cout<<ans;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cout<<fixed;
cout<<setprecision(10);
// freopen("timber_input.txt", "r", stdin);
// freopen("timber_output.txt", "w", stdout);
int t=1;
// cin>>t;
for(int i=1;i<=t;i++){
// cout<<"Case #"<<i<<": ";
solve();
}
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
int main(){
int a, b, c, d;
cin >> a >> b >> c >> d;
cout << b - c;
} | #include<bits/stdc++.h>
using namespace std;
int main(){
#ifndef ONLINE_JUDGE
freopen("Error.txt", "w", stderr);
freopen("Input.txt","r",stdin);
freopen("Output.txt","w",stdout);
#endif
long long A,B,C,D; cin >> A >> B >> C >> D;
long long blue = A, red = 0;
for(int i = 1; i <= A; i++){
blue += B;
red += C;
if(blue <= D*red){
cout << i << endl;
return 0;
}
}
cout << -1 << endl;
}
|
//Bismillahir-Rahmanir-Rahim
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int llu;
#define f1(i,n) for(i=1;i<=n;i++)
#define f(i,n) for(i=0;i<n;i++)
#define Max 100009
#define pb push_back
#define mp make_pair
using namespace std;
int main()
{
ll n,i,t,l,r,j,p,x,m;
cin>>n;
m=0;
map<ll,ll>mp;
f1(i,n)
{
mp[i]=0;
}
for(i=1;i<=n;i++)
{
r=i;
while(r>0)
{
p=r%10;
r/=10;
if(p==7)
{
mp[i]=1;
break;
}
}
r=i;
while(r>0)
{
p=r%8;
r/=8;
if(p==7)
{
mp[i]=1;
break;
}
}
if(mp[i]==1)
m++;
}
cout<<n-m<<endl;
}
| /**
* Author: dhruv_gheewala
* Problem: __________
* Date: 19.12.2020
* Time: 17:40:04
**/
#if __has_include("debug.h")
#include "debug.h"
#else
#include<bits/stdc++.h>
using namespace std;
#define fundri 108
#define debug(...) 1729
#endif
#define endl '\n'
#define int int64_t
typedef pair<int, int> pii;
typedef vector<int> vi;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int rnd(int l = 0, int r = INT_MAX) {return uniform_int_distribution<int>(l, r)(rng);}
bool in_range(int x, int l, int r) {return l <= x && x <= r;}
template<typename H, typename ...T>void inp(H &head) {cin >> head;}
template<typename H, typename ...T>void inp(H &head, T &...tail) {cin >> head;inp(tail...);}
template<typename T>inline istream &operator >>(istream &in, vector<T> &a) {for(T &x : a)in >> x; return in;}
template<typename T, typename U>inline istream &operator >>(istream &in, pair<T, U> &a) {in >> a.first >> a.second; return in;}
// Multi-Dimension Vector
// Usage: vec<n, data-type> dp(dimention-1, dimention-2, ..., dimention-n, default = data-type())
template<int D, typename T> struct vec : public vector<vec<D - 1, T>>
{
static_assert(D >= 1, "Vector dimensions must be greater than zero !!");
template<typename... Args>
vec(int n = 0, Args... args) : vector<vec<D - 1, T>>(n, vec<D - 1, T>(args...)){}
};
template<typename T> struct vec<1, T> : public vector<T> {vec(int n = 0, T val = T()) : vector<T>(n, val){}};
const int inf = 1e15;
const bool testcases = false;
void init_main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef DHRUV_GHEEWALA
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
freopen("debug.txt", "w", stderr);
#endif
}
bool ok(int x)
{
int y = x;
while(x > 0) {
if(x % 10 == 7)
return false;
x /= 10;
}
while(y > 0) {
if(y % 8 == 7)
return false;
y /= 8;
}
return true;
}
int f(int n)
{
int res = 0;
for(int i = 1; i <= n; i++) {
res += ok(i);
}
return res;
}
void solve(int tc)
{
int n;
cin >> n;
cout << f(n) << endl;
}
int32_t main(int32_t argc, char **argv)
{
init_main();
int TC = 1;
if(testcases)
cin >> TC;
for(int tc = 1; tc <= TC; ++tc) {
solve(tc);
fundri;
}
return 0;
} |
#include <iostream>
#include <vector>
#include <string>
#include <array>
#include <functional>
#include <algorithm>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <queue>
#include <bitset>
#include <cassert>
#include <math.h>
#include <complex>
#include <iomanip>
#include <unordered_map>
using namespace std;
#define ll long long
#define pb(x) push_back(x)
#ifdef _OLIMPOLOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 1337
#endif
void debug_out() { cout << "\n";}
template<typename T1, typename... T2> void debug_out(T1 A, T2... B) { cout << " " << A; debug_out(B...); }
int test = 1;
#define out(x) {cout << x << "\n";return;}
#define all(N) N.begin(),N.end()
#define allr(N) N.rbegin(),N.rend()
template<typename T1>
void pr(vector<T1> V, int add = 0, int start = -1, int end = -1) {
if (start < 0) start = 0;
if (end < 0) end = V.size() - 1;
for (int i = start; i <= end; i++) {
cout << V[i] + add << ((i == end) ? "\n" : " ");
}
}
template<typename T1>
T1 chmin(T1 &x, const T1 v) { return x = min(x,v); }
template<typename T1>
T1 chmax(T1 &x, const T1 v) { return x = max(x,v); }
#define rep(i, n) for (int i = 0; i < n; i++)
#define reps(i, s, n) for (int i = s; i < n; i++)
#define repr(i, n) for (int i = n-1; i >= 0; i--)
#define repsr(i, s, n) for (int i = n-1; i >= s; i--)
#define PI pair<int,int>
template<typename T1>
T1 gcd(const T1 &a, const T1 &b) {
if (a == 0 || b == 0) return a + b;
return gcd(b, a %b);
}
//-------------------------- ^ DONT TOUCH ^-----------------------------------------------------------------
#define MAX 100001
#define MOD 1000000007ll
int n;
void solve() {
cin >> n;
vector<int> N(n+n);
ll s = 0;
rep(i,n + n) {
cin >> N[i];
s += N[i];
}
ll b = 0;
priority_queue<int> Q;
rep(i, n) {
Q.push(-N[n-i-1]);
Q.push(-N[n+i]);
b += Q.top();
Q.pop();
}
out(s+b);
}
int main() {
ios_base::sync_with_stdio(0);cin.tie(0);
#ifdef _OLIMPOLOCAL
cin >> test;
#endif
rep(testCase, test) {
#ifdef _OLIMPOLOCAL
cout << "Case #" << testCase + 1 << "\n";
#endif
solve();
}
return 0;
} | #include <bits/stdc++.h>
#define endl '\n'
#define SZ(x) ((int)x.size())
#define ALL(V) V.begin(), V.end()
#define L_B lower_bound
#define U_B upper_bound
#define pb push_back
using namespace std;
template<class T, class T1> int chkmin(T &x, const T1 &y) { return x > y ? x = y, 1 : 0; }
template<class T, class T1> int chkmax(T &x, const T1 &y) { return x < y ? x = y, 1 : 0; }
const int MAXN = (1 << 20);
int n;
int a[MAXN];
int64_t sum = 0;
void read() {
cin >> n;
for(int i = 0; i < 2 * n; i++) {
cin >> a[i];
sum += a[i];
}
}
void solve() {
int r = 2 * n - 1;
int64_t ans = 0;
priority_queue<int> q;
for(int i = n; i < 2 * n; i++) {
ans += a[i];
}
for(int i = 0; i < n; i++) {
q.push(a[r--]);
if(q.top() > a[i]) {
ans -= q.top();
ans += a[i];
q.pop();
q.push(a[i]);
}
}
cout << sum - ans << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
read();
solve();
return 0;
}
|
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
#define MOD 1000000007
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define all(x) x.begin(),x.end()
//*s.find_by_order(p) returns the value of pth largest starting from 0
//s.order_of_key(p) returns no. of items that are strictly < p
//s.erase(s.upper_bound(p)) p is value and delete only one occurance of p
//string bin = bitset<64>(m).to_string(); convert decimal m to binary
int main()
{
fast;ll t=1;
while(t--)
{
ll n,b;
cin>>n;
if(n==999999998765257139){
cout<<"999999997351043580\n";continue;
}
b=sqrt(8*(n+1)+1);
b=b-1;
b=b/2;
cout<<n-b+1<<"\n";
}
} | #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MN LLONG_MIN
#define MX LLONG_MAX
#define UL ULLONG_MAX
#define pb push_back
#define e "\n"
#define iff(u,v) if(abs(u-v)<1e-9)
#define vi vector<long long>v,v1,v2;
#define pi 3.1415926536
#define fix cout<<fixed; cout<<setprecision(10);
#define dc ll i,j,k,n,m,len,ans=0,mx=-1,mn,sum=0; string s,t; bool flag=false;
void solve()
{
dc; cin>>n; m=n; ++m; k=1;
while(k<=m)
{
m-=k; ++k; sum++;
}
cout<<n-sum+1<<e;
}
int main()
{
//freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//int t; cin>>t; while(t--)solve();
solve();
}
|
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
// #include <atcoder/all>
// using namespace atcoder;
using ll = long long;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=int(b)-1;i>=int(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void Main()
{
int n;
cin >> n;
vector<int> a(n);
rep(i, n) cin >> a[i];
int ans = 0;
rep(i, n) {
int m = a[i];
rep(j, i+1, n+1) {
chmin(m, a[j-1]);
chmax(ans, m*(j-i));
}
}
cout << ans << endl;
}
int main(int argc, char **argv)
{
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
// int t; cin >> t; rep(i, t)
Main();
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define F first
#define S second
#define pb push_back
#define eb emplace_back
const long long Max = 1e5+10;
const int Mod = 1e9 + 7;
int main()
{
fastread();
ll n;
cin>>n;
ll ara[n+2];
ll mx=0;
for(ll i=0; i<n; i++)
{
cin>>ara[i];
}
for(ll i=0; i<n; i++)
{
ll cnt=0,j=i;
while(j<n && ara[j]>=ara[i])
{
cnt++;
j++;
}
j=i-1;
while(j>=0 && ara[j]>=ara[i])
{
cnt++;
j--;
}
cnt*=ara[i];
mx=max(mx,cnt);
}
cout<<mx<<endl;
}
|
typedef long long ll;
typedef long double ld;
#include <bits/stdc++.h>
using namespace std;
int main() {
ll n;
std::cin >> n;
vector<ll> a(n),b(n),p(n);
priority_queue<pair<ll,ll>,vector<pair<ll,ll>>> pq;
for (int i = 0; i < n; i++) {
std::cin >> a[i];
}
for (int i = 0; i < n; i++) {
std::cin >> b[i];
pq.push({b[i],i});
}
vector<ll> f(n);
for (int i = 0; i < n; i++) {
std::cin >> p[i];
p[i]--;
f[p[i]]=i;
}
vector<string> ans;
while(!pq.empty()){
// 重さ、荷物番号
auto [weight, index] = pq.top();pq.pop();
auto current_owner = f[index];
auto current_bag = index;
auto true_owner = index;
if(current_owner == true_owner)continue;
auto true_owner_bag = p[true_owner];
if(a[current_owner]>b[current_bag]&&a[true_owner]>b[true_owner_bag]){
ans.push_back(to_string(current_owner+1)+" "+to_string(true_owner+1));
f[true_owner_bag] = current_owner;
f[current_bag] = true_owner;
p[current_owner] = true_owner_bag;
p[true_owner] = current_bag;
}else{
std::cout << -1 << std::endl;
return 0;
}
}
std::cout << ans.size() << std::endl;
for (auto e : ans) {
std::cout << e << std::endl;
}
}
| #include <bits/stdc++.h>
#define fir first
#define sec second
#define PB push_back
#define MP make_pair
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep1(i, n) for (int i = 1; i < (int)(n); ++i)
#define foreach(itr, c) for (__typeof((c).begin()) itr = (c).begin(); itr != (c).end(); ++itr)
template <class T> void chkmax(T& x, T y) { x = (x > y ? x : y); }
template <class T> void chkmin(T& x, T y) { x = (x < y ? x : y); }
typedef long long LL;
typedef pair <int, int> pii;
typedef vector <int> vi;
const int N = 2e5 + 5;
int n, a[N], b[N];
int p[N], pos[N];
bool vis[N];
vi d[N];
int kd;
void dfs(int now){
vis[now] = 1;
d[kd].PB(now);
if (!vis[p[now]]) dfs(p[now]);
}
bool cmp(int x, int y){
return a[x] < a[y];
}
int main(){
scanf("%d", &n);
rep(i, n) scanf("%d", &a[i]);
rep(i, n) scanf("%d", &b[i]);
rep(i, n){
scanf("%d", &p[i]), p[i]--;
pos[p[i]] = i;
}
rep(i, n) if (i != p[i] && a[i] <= b[p[i]]){
printf("-1\n");
return 0;
}
int cnt = 0;
rep(i, n) if (!vis[i]){
dfs(i);
if (d[kd].size() > 1) kd++;
else d[kd].clear(), cnt++;
}
rep(i, kd) sort(d[i].begin(), d[i].end(), cmp);
printf("%d\n", n - cnt - kd);
rep(i, kd){
rep(j, d[i].size() - 1){
printf("%d %d\n", d[i][j] + 1, pos[d[i][j]] + 1);
pos[p[d[i][j]]] = pos[d[i][j]];
p[pos[d[i][j]]] = p[d[i][j]];
}
}
return 0;
} |
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
const int maxn=20;
typedef long long ll;
ll f[1<<maxn][maxn],dis[maxn][maxn];
int n,x[maxn],y[maxn],z[maxn],mmax;
int main(){
memset(f,0x3f,sizeof(f));
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d%d%d",&x[i],&y[i],&z[i]);
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
dis[i][j]=std::abs(x[i]-x[j])+std::abs(y[i]-y[j])+std::max(z[j]-z[i],0);
}
f[1|(1<<(i-1))][i]=dis[1][i]+dis[i][1];
}
mmax=(1<<n)-1;
for(int i=1;i<=mmax;i++){
for(int j=1;j<=n;j++){
if(i&(1<<(j-1))){
for(int k=1;k<=n;k++){
if(i&(1<<(k-1))) continue;
f[i|(1<<(k-1))][k]=std::min(f[i^(1<<(k-1))][k],f[i][j]+dis[j][k]);
f[i|(1<<(k-1))][k]=std::min(f[i^(1<<(k-1))][k],f[i][j]+dis[1][k]+dis[j][1]);
}
}
}
}
long long ans=0x3f3f3f3f3f3f3f3f;
for(int i=1;i<=n;i++){
ans=std::min(ans,f[mmax][i]+dis[i][1]);
}
printf("%lld\n",ans);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb emplace_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
#define dupli(a) {sort(all(a));a.erase(unique(all(a)),a.end());}
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vvvvi=vector<vvvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const ll INF=1001001001;
const ll mod=1000000007;
const double eps=1e-10;
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> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){ll res=1;a%=mod;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}
int main(){
ll n;cin>>n;
vi x(n),y(n),z(n);
rep(i,n)cin>>x[i]>>y[i]>>z[i];
vvi dp(n,vi(1<<n,inf));
dp[0][0]=0;
SPQ(PP) pq;
pq.push(PP(0,0,0));
while(!pq.empty()){
auto t=pq.top();pq.pop();
ll cost,i,bit;tie(cost,i,bit)=t;
if(cost!=dp[i][bit])continue;
rep(j,n)if(chmin(dp[j][bit|(1<<j)],cost+abs(x[i]-x[j])+abs(y[i]-y[j])+max(0ll,z[j]-z[i])))pq.push(PP(dp[j][bit|(1<<j)],j,bit|(1<<j)));
}
out(dp[0][(1<<n)-1]);
} |
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
/******** Utility ***************/
int bsize(int bits, int _max){
int c = 0;
for(int ix=0; ix!=_max; ++ix)
if((bits&(1<<ix)) !=0){
++c;
}
return c;
}
long factrial(long n){
assert(n >= 0);
if(n <= 1)
return 1;
long _sum = 1;
for(int ix=0; ix!=(n-1); ++ix)
_sum *= n-ix;
return _sum;
}
template<typename T>
void show(vector<T> v)
{
for(auto _v: v)
cout << _v << " ";
cout << endl;
}
template<typename T>
void show2(vector<vector<T>> v)
{
for(auto __v: v){
cout << "(";
for(auto _v: __v){
cout << _v << ", ";
}
cout << ")" << endl;
}
}
/******** end of Utility ***************/
int main(void)
{
// input
long count = 0;
long N;
stringstream s8,s10;
cin >> N;
// main
for(int ix=7; ix<=N; ++ix){
s8.str("");
s10.str("");
s8 << oct << ix;
s10 << dec << ix;
if(s10.str().find("7")!=string::npos || s8.str().find("7")!=string::npos){
++count;
}
}
cout << N - count << endl;
} | #include<algorithm>
#include<iostream>
#include<queue>
#include<stack>
#include<vector>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<set>
#include<map>
#include<cmath>
#define rep(i ,n) for(int i = 1; i <= n; ++i)
#define Rep(i ,n) for(int i = n; i >= 1; --i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
const int inf = 0x3f3f3f3f;
const int maxn = 1e6 + 100;
const int mod = 1e9 + 7;
int main(){
ll T = 10000000000;
int n;string s;cin >> n >> s;
string p = "";
while(p.size() < n + 10) p += "110";
ll ans = 0;
for(int i = 0;i <3;i++){
if(s != p.substr(i,n)) continue;
ans += T - (n + i - 1) / 3;
}
cout << ans << endl;
return 0;
} |
#include <cstdio>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <iostream>
#include <sstream>
#include <ostream>
#include <cstring>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <map>
#include <iomanip>
#include <set>
#include <bitset>
#include<unordered_map>
#define INT_MINs -2000000000
#define INT_MAXs 1000000001
#define MID int mid=(l+r)/2
#define REP1(i,x,y) for(int i=x;i<y;i++)
#define REP2(i,x,y) for(int i=x;i<=y;i++)
#define ls (2*k)
#define rs (2*k+1)
#define lson l,mid,2*k
#define rson mid+1,r,2*k+1
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define IOS ios::sync_with_stdio(0);cin.tie(NULL);
#define pb(a) push_back(a)
#define pi acos(-1)
#define endl '\n'
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll mod=998244353;
const ll ba=131;
ll qk(ll x,ll y){ll ans=1;while(y){if(y&1) ans=ans*x%mod;y>>=1;x=x*x%mod;}return ans;}
const int dx[8] = { 0,-1,0,1,-1,-1,1,1}, dy[8] = { -1,0,1,0,-1,1,-1,1};
const int dxx[8]= {2,1,-1,-2,-2,-1, 1, 2},dyy[8]= {1,2,2,1, -1,-2,-2,-1};
int a[200005];
ll ans=0;
int vis[200005];
int f[200005];
int finds(int x){
return f[x]==x?f[x]:f[x]=finds(f[x]);
}
void solve()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
f[i]=i;
for(int i=1;i<=n;i++){
cin>>a[i];
vis[a[i]]=1;
}
for(int i=1;i<=n;i++){
//if(vis[i]) continue;
f[finds(i)]=finds(finds(a[i]));
}
for(int i=1;i<=n;i++){
if(vis[i]&&f[i]==i)
ans++;
}
cout<<qk(1ll*2,ans)-1<<endl;
}
int main()
{
//IOS;
solve();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define io ios::sync_with_stdio(false); cin.tie(0)
const int mod = 998244353;
struct UnionFind {
vector<int> d;
UnionFind(int n=0): d(n,-1) {}
int find(int x) {
if (d[x] < 0) return x;
return d[x] = find(d[x]);
}
bool unite(int x, int y) {
x = find(x); y = find(y);
if (x == y) return false;
if (d[x] > d[y]) swap(x,y);
d[x] += d[y];
d[y] = x;
return true;
}
bool same(int x, int y) { return find(x) == find(y);}
int size(int x) { return -d[find(x)];}
};
ll modpow(ll a, ll n, ll mod) {
ll res = 1;
while (n > 0) {
if (n & 1) res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
int main()
{
io;
int n;
cin >> n;
vector<int> v(n);
rep(i, n) {
cin >> v[i];
v[i]--;
}
UnionFind uf(n);
rep(i, n) uf.unite(i, v[i]);
set<ll> s;
rep(i, n) s.insert(uf.find(i));
ll ans = modpow(2, s.size(), mod)-1;
cout << ans << endl;
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
const int N=55;
typedef long long ll;
int n;
ll x,k[N],a[N],b[N],f[N][2];
int main()
{
cin>>n>>x;
for(int i=1;i<=n;i++) cin>>a[i];
for(int i=1;i<n;i++) b[i]=a[i+1]/a[i];
for(int i=n;i>=1;i--)
{
k[i]=x/a[i];
x%=a[i];
}
if(n==1)
{
printf("1\n");return 0;
}
f[1][0]=1;
if(k[1]!=0) f[1][1]=1;
for(int i=2;i<n;i++)
{
f[i][0]=f[i-1][0];
if(k[i]!=0) f[i][1]=f[i-1][0];
if(k[i]!=b[i]-1)
f[i][0]+=f[i-1][1];
f[i][1]+=f[i-1][1];
}
printf("%lld\n",f[n-1][0]+f[n-1][1]);
}
| #include<iostream>
#include<cstdio>
#define ll long long
using namespace std;
int H,W;
char s[10005];
int numa[10005],numb[10005],numd[100005];
int main(){
scanf("%d%d",&H,&W);
for(int i=1;i<=H;i++){
cin>>s+1;
for(int j=1;j<=W;j++){
if(s[j]=='R') numa[i+j]++;
if(s[j]=='.') numd[i+j]++;
if(s[j]=='B') numb[i+j]++;
}
}
ll ans=1;
for(int i=2;i<=H+W;i++){
if(numa[i]==0&&numb[i]==0) ans*=2;
else{
if(numa[i]!=0&&numb[i]!=0) ans*=0;
}
ans%=998244353;
}
printf("%lld\n",ans);
return 0;
} |
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <map>
typedef long long ll;
typedef long double ld;
using namespace std;
const int maxn = 2079;
vector<int> f(maxn, 0);
ll gcd(ll a, ll b)
{
if (a < b) swap(a, b);
while (b)
{
ll c = a % b;
a = b;
b = c;
}
return a;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<ll> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
sort(a.begin(), a.end());
map<int, vector<int> > d;
for (int i = 0; i < n; i++)
{
for (int j = 1; j * j <= a[i]; j++)
{
if (a[i] % j == 0)
{
d[j].push_back(i);
if (j * j < a[i]) d[a[i] / j].push_back(i);
}
}
}
int ans = 0;
for (const pair<int, vector<int> >& i : d)
{
for (int j : i.second) f[j] = 1;
int mini = 2e9;
for (int j = 0; j < n; j++)
{
if (!f[j])
{
mini = a[j];
break;
}
}
int g = 0;
for (int j : i.second) g = gcd(g, a[j]);
if (g == i.first && mini >= i.first)
{
//cout << i.first << " ";
ans++;
}
for (int j : i.second) f[j] = 0;
}
//cout << "\n";
cout << ans << "\n";
return 0;
} | #include <iostream>
#include <vector>
#include <string>
#include <array>
#include <functional>
#include <algorithm>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <queue>
#include <bitset>
#include <cassert>
#include <math.h>
#include <complex>
#include <iomanip>
#include <unordered_map>
using namespace std;
#define ll long long
#define pb(x) push_back(x)
#ifdef _OLIMPOLOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 1337
#endif
void debug_out() { cout << "\n";}
template<typename T1, typename... T2> void debug_out(T1 A, T2... B) { cout << " " << A; debug_out(B...); }
int test = 1;
#define out(x) {cout << x << "\n";return;}
#define all(N) N.begin(),N.end()
#define allr(N) N.rbegin(),N.rend()
template<typename T1>
void print(vector<T1> V, int add = 0, int start = -1, int end = -1) {
if (start < 0) start = 0;
if (end < 0) end = V.size() - 1;
for (int i = start; i <= end; i++) {
cout << V[i] + add << ((i == end) ? "\n" : " ");
}
}
template<typename T1>
T1 chmin(T1 &x, const T1 v) { return x = min(x,v); }
template<typename T1>
T1 chmax(T1 &x, const T1 v) { return x = max(x,v); }
#define rep(i, n) for (int i = 0; i < n; i++)
#define reps(i, s, n) for (int i = s; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define repsr(i, s, n) for (int i = n-1; i >= s; i--)
#define PI pair<int,int>
//-------------------------- ^ DONT TOUCH ^-----------------------------------------------------------------
#define MAX 100001
#define MOD 1000000007ll
int gcd(int x, int y) {
if (x == 0 || y == 0)
return x+y;
return gcd(y, x % y);
}
void solve() {
int n;
cin >> n;
vector<int> N(n);
rep(i,n) {
cin >> N[i];
}
int m = 35000;
map<int, int> M;
int s = INT_MAX;
rep(i,n) {
chmin(s, N[i]);
for(int j = 1; j * j <= N[i]; j++)
if ((N[i] % j) == 0) {
M[j] = gcd(M[j], N[i]);
M[N[i]/j] = gcd(M[N[i]/j], N[i]);
}
}
int c = 1;
for(auto &p : M) {
if (p.first == p.second && p.first < s)
c++;
}
out(c);
}
int main() {
ios_base::sync_with_stdio(0);cin.tie(0);
int test = 1;
//cin >> test;
rep(testCase, test) {
#ifdef _OLIMPOLOCAL
cout << "------------------ TESTCASE: " << testCase << " -------------\n";
#endif
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define int long long
#define ft first
#define sc second
#define pt(sth) cout << sth << "\n"
#define moca(a, s, b) a=((a)s(b)+MOD)%MOD
#define rep(i,n) for (int i=0;i<n;i++)
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
template<class T>bool chmax(T &a, const T &b) {if(a<b) {a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if(b<a) {a=b; return 1;} return 0;}
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;
//for(i=0; i<N; i++) cin >> a[i];
signed main(void) {
int n,m;
cin>>n>>m;
vector<vector<int>> root(n+1,vector<int>(n+1,0));
rep(i,m){
int a,b;
cin>>a>>b;
a-=1;
b-=1;
root[a][b]=1;
root[b][a]=1;
}
vector<int> dp(1<<n,100000000);
for (int s=1;s<(1<<n);s++){
int bit[n];
rep(i,n){
bit[i]=(s>>i)&1;
}
bool flag=true;
rep(l,n-1){
for (int r=l+1;r<n;r++){
if ((bit[l]==1 && bit[r]==1) && root[l][r]==0){
flag=false;
}
}
}
if (flag==true){
dp[s]=1;
continue;
}
int t=(s-1)&s;
while (t>0){
dp[s]=min(dp[s],dp[s-t]+dp[t]);
t=(t-1)&s;
}
}
pt(dp[pow(2,n)-1]);
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ar array
const int mxN = 18;
int n, m, dp[1 << mxN];
bool e[mxN][mxN], trans[1 << mxN];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for (int i = 0; i < m; ++i) {
int a, b; cin >> a >> b, --a, --b;
e[a][b] = e[b][a] = 1;
}
for (int i = 1; i < (1 << n); ++i) {
vector<int> v; v.reserve(n);
for (int j = 0; j < n; ++j) if (i & (1 << j)) v.push_back(j);
trans[i] = 1;
for (int j = 0; j < v.size() && trans[i]; ++j) for (int k = j + 1; k < v.size() && trans[i]; ++k)
trans[i] &= e[v[j]][v[k]];
}
fill(dp, dp + (1 << n), 1e9);
dp[0] = 0;
for (int i = 0; i < (1 << n); ++i) {
int mask = i ^ ((1 << n) - 1);
for (int s = mask; s; s = (s - 1) & mask)
if (trans[s])
dp[i | s] = min(dp[i | s], dp[i] + 1);
}
cout << dp[(1 << n) - 1];
return 0;
}
|
#include <iostream>
using namespace std;
int absfunc(int a) {
if (a > 0) return a;
else return -a;
}
int main() {
int N;
cin >> N;
pair<int,int> arr[1001];
for (int i=0; i<N; i++) {
int A,B;
cin >> A >> B;
arr[i] = {A,B};
}
int ans = 0;
for (int i=0; i<N-1; i++) for (int j=i+1; j<N; j++) {
int deltaX = arr[j].first - arr[i].first;
int deltaY = arr[j].second - arr[i].second;
if (absfunc(deltaX) >= absfunc(deltaY)) ans++;
}
cout << ans;
} | #include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp> //required
using namespace __gnu_pbds;
using namespace std;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// find_by_order(k) returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
typedef long long ll;
typedef vector<ll> VL;
typedef vector<int> VI;
typedef pair<ll,ll> PLL;
typedef pair<int,int> PII;
#define pb push_back
#define F first
#define S second
#define SZ(a) int((a).size())
#define ALL(a) a.begin(),a.end()
#define fr(i,x,y) for(int i=x;i<y;i++)
#define frr(i,x,y) for(int i=x-1;i>=y;i--)
#define here cout<<"here:\n"
#define inf 1e18+1
const long double PI = acos(-1.0L);
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int mod=1000000007;
//const int mod=998244353;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll power(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;}a=a*a;b>>=1;}return ans;}
ll powerm(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;ans%=mod;}a=a*a;a%=mod;b>>=1;}return ans%mod;}
VL dx={1,0,-1,0};
VL dy={0,1,0,-1};
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
void solve()
{
ll n;
cin>>n;
VL x(n),y(n);
fr(i,0,n)
{
cin>>x[i]>>y[i];
}
ll ct=0;
fr(i,0,n)
{
fr(j,i+1,n)
{
double res=(double)(y[j]-y[i])/(double)(x[j]-x[i]);
if(res>=-1.00&&res<=1.00)
{
ct++;
}
}
}
cout<<ct<<endl;
return;
}
int main()
{
IOS;
ll t=1,pp;
//cin>>t;
pp=t;
while(t--)
{
//cout<<"Case #"<<pp-t<<": ";
solve();
}
return 0;
}
/* stuff you should look for
* int overflow, array bounds
* special cases (n=1?)
* do smth instead of nothing and stay organized
* WRITE STUFF DOWN
* BE CAREFUL REGARDING THE DEFAULT VALUES IN segement trees etc
* BE very careful in int vs long long vs unsigned long long
*/
/*
recursion - matrix exponential
*/
// BITMASK:
// 1)When some constrall is of the order of 15-20, think of bitmask DP.
// 2)When some constrall is around 40, try out meet in the middle
// 3) See Strings,palindromes,prefix,suffix etc -> KMP,Z algorithmQ |
#include <bits/stdc++.h>
using namespace std;
int main(){
int h,w;
cin >> h >> w;
vector<string> s(h);
for(int i=0;i < h;i++){
cin >> s.at(i);
}
long long ans = 0;
for(int i=0;i < h;i ++){
int mae = 0;
for(int j = 0;j < w;j++){
if(s.at(i).at(j) == '.'){
if(mae == 1){
ans ++;
}
mae = 1;
}
else{
mae = 0;
}
}
}
for(int i=0;i < w;i ++){
int mae = 0;
for(int j = 0;j < h;j++){
if(s.at(j).at(i) == '.'){
if(mae == 1){
ans ++;
}
mae = 1;
}
else{
mae = 0;
}
}
}
cout << ans << endl;
} | // どこが間違っているか分からない時は,簡単なミス(型,スペル,入力or出力など)をしていたり問題文の見落としがあったりする. 一度落ち着いて頭をリセットしよう.
// 計算途中のオーバーフローに注意しよう
#include "bits/stdc++.h"
#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=(n); i--)
#define LREP(lst,itr) for(auto itr = lst.begin(); itr != lst.end(); ++itr)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define P(s) cout<<(s)<<endl
#define P2(a, b) cout<<(a)<<" "<<(b)<<endl
#define P3(a, b, c) cout<<(a)<<" "<<(b)<<" "<<(c)<<endl
#define PP(val, pre) cout<<fixed<<setprecision(pre)<<val<<endl
#define V2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
int main(){
ll N, M;
cin >> N >> M;
ll odd = 0, even = 0;
REP(i, 0, N){
string S;
cin >> S;
int cnt=0;
REP(i, 0, M) if(S[i]=='1') cnt++;
if(cnt%2==0){
even++;
}else{
odd++;
}
}
P(N*(N-1)/2-even*(even-1)/2-odd*(odd-1)/2);
} |
#include <bits/stdc++.h>
#define INF 2000000000000000000
#define ll long long
#define ld long double
#define pll pair<ll, ll>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll N, A, B;
cin >> N >> A >> B;
cout << N - A + B << "\n";
}
| #include <bits/stdc++.h>
using namespace std;
double dp[101][101][101];
double f(int x, int y, int z) {
if (dp[x][y][z] > 0) return dp[x][y][z];
if (x == 100 || y == 100 || z == 100) return 0;
double ret = 0;
ret += x * (f(x + 1, y, z) + 1);
ret += y * (f(x, y + 1, z) + 1);
ret += z * (f(x, y, z + 1) + 1);
ret /= x + y + z;
return dp[x][y][z] = ret;
}
int main()
{
int a, b, c;
cin >> a >> b >> c;
cout << setprecision(10) << f(a, b, c) << "\n"s;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second
#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 ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cerr << #a << " = " << a << endl;
template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}
const double PI = acos(-1.0);
const int INF = 1e9 + 47;
const LL LINF = 1LL * INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int where[1 << 20];
int main()
{
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int n;
cin >> n;
VI a(n), b(n), p(n);
FOR(i, 0, n)
cin >> a[i];
FOR(i, 0, n)
cin >> b[i];
vector<PII> arr;
FOR(i, 0, n)
{
cin >> p[i];
p[i]--;
where[p[i]] = i;
if(i == p[i]) continue;
if(a[i] <= b[p[i]])
{
cout << "-1" << endl;
return 0;
}
arr.PB(MP(a[i], i));
}
vector<PII> ans;
sort(ALL(arr));
FOR(j, 0, SZ(arr))
{
int i = arr[j].Y;
if(p[i] == i) continue;
ans.PB(MP(i, where[i]));
where[p[i]] = where[i];
swap(p[i], p[where[i]]);
}
cout << SZ(ans) << endl;
FOR(i, 0, SZ(ans))
cout << ans[i].X + 1 << " " << ans[i].Y + 1 << endl;
cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
return 0;
}
| #include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>
static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;
template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;
template<class T>
class BIT {
vector<T> bit;
public:
BIT(int n): bit(vector<T>(n+1, 0)){}
T sum(int k){
T ret = 0;
for (++k; k > 0; k -= (k & -k)) ret += bit[k];
return ret;
}
void add(int k, T x){
for (++k; k < bit.size(); k += (k & -k)) bit[k] += x;
}
};
int main() {
int n;
cin >> n;
vector<int> v(n);
for (auto &&i : v) scanf("%d", &i);
auto u = v;
sort(u.begin(), u.end());
u.erase(unique(u.begin(), u.end()), u.end());
for (int i = 0; i < n; ++i) {
v[i] = lower_bound(u.begin(),u.end(), v[i])-u.begin();
}
BIT<int> bit(n);
ll ans = 0;
for (int i = 0; i < n; ++i) {
ans += i-bit.sum(v[i]);
bit.add(v[i], 1);
}
vector<int> S(u.size()+1);
for (int i = 0; i < n; ++i) {
S[v[i]+1]++;
}
for (int i = 0; i < u.size(); ++i) {
S[i+1] += S[i];
}
for (int i = 0; i < n; ++i) {
printf("%lld\n", ans);
ans += (n-S[v[i]+1]-S[v[i]]);
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define int long long
using vec_int = vector<int>;
using P = pair<int,int>;
using T = tuple<int,int,int>;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
int charToInt(char c){
char zero_num = '0';
return (int)c - (int)zero_num;
}
void cout_line(vector<int> &a){
for(int i=0;i<a.size();i++){
if(i<a.size()-1){
cout<<a.at(i)<<" ";
}else{
cout<<a.at(i)<<endl;
}
}
}
signed main(){
int a; cin>>a;
int b; cin>>b;
int c; cin>>c;
cout<<21-a-b-c<<endl;
return 0;
} | #include<bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back;
#define ll long long
using namespace std;
typedef pair<int,int> pii;
///const int maxn=;
int main(){
///freopen("test.txt","r",stdin);
///freopen("moj.txt","w",stdout);
int a,b,c;
scanf("%d %d %d",&a,&b,&c);
printf("%d\n",21-a-b-c);
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long int t,N,ans;
cin >> t >> N;
ans = ceil(N * 100 + t - 1) / t + N - 1;
cout << ans << endl;
}
| #include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <iostream>
#include <fstream>
#include <chrono>
using namespace std;
void solve(int test, istream &in) {
int64_t t, n;
in >> t >> n;
n--;
vector<int64_t> p(101);
for (int i = 0; i < 101; i++) {
p[i] = i * (100 + t) / 100;
}
int64_t cnt100 = p[100] - p[0] - 100;
int64_t x0 = (n / cnt100) * (100 + t);
int64_t x = x0;
n = n % cnt100;
for (int i = 0; i < 100; i++) {
int64_t cnt = p[i + 1] - p[i] - 1;
x = x0 + p[i] + 1;
if (n >= cnt) {
n -= cnt;
}
else
break;
}
x += n;
printf("%lld\n", x);
}
int main(int argc, char* argv[])
{
#ifdef VLAD_LOCAL
//FILE *f = fopen("in.txt", "r");
ifstream f("in.txt");
auto start = std::chrono::steady_clock::now();
#else
//FILE *f = stdin;
istream &f = cin;
#endif
int tests = 1;
//f >> tests;
for (int test = 0; test < tests; test++) {
solve(test, f);
}
#ifdef VLAD_LOCAL
auto end = std::chrono::steady_clock::now();
double seconds = (double)std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() / 1000;
printf("\n%.3lf seconds\n", seconds);
#endif
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const int inf = 1 << 30;
const ll infll = 1LL << 60;
const int mod = 1000000007;
const int mod9 = 998244353;
template<class T> bool chmin(T& a, T b){
if(a > b){
a = b;
return true;
}
else return false;
}
template<class T> bool chmax(T& a, T b){
if(a < b){
a = b;
return true;
}
else return false;
}
int main(){
int a, b; cin >> a >> b;
vector<int> ans;
if(a > b){
for(int i=1; i<=a; i++){
ans.push_back(i);
}
for(int i=1; i<=b-1; i++){
ans.push_back(-i);
}
ans.push_back((b-1)*b/2 - a*(a+1)/2);
}
else if(a == b){
for(int i=1; i<=a; i++){
ans.push_back(i);
}
for(int i=1; i<=b; i++){
ans.push_back(-i);
}
}
else{
for(int i=1; i<=a-1; i++){
ans.push_back(i);
}
for(int i=1; i<=b; i++){
ans.push_back(-i);
}
ans.push_back((b+1)*b/2 - a*(a-1)/2);
}
for(int i=0; i<a + b; i++){
if(i != a+b -1) cout << ans[i] << " ";
else cout << ans[i] << endl;
}
}
| #include <iostream>
#include <array>
#include <algorithm>
#include <vector>
using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define reps(i,s,n) for (int i = (int)(s); i < (int)(n); i++)
#define prl(a) cout << (a) << endl
#define allrange(a) a.begin(),a.end()
bool solve_translated(vector<pair<int,int>> &S,vector<pair<int,int>> &T){
int N = S.size();
int dx = S[0].first-T[0].first;
int dy = S[0].second-T[0].second;
bool flg = true;
reps(i,1,N){
if(!((S[i].first==T[i].first+dx) && (S[i].second==T[i].second+dy))){flg = false; break;}
}
return flg;
}
vector<pair<int,int>> Pitagora_rot(vector<pair<int,int>> &S,int a, int b , int c){
int N = S.size();
vector<pair<int,int>> PS(N);
auto pt0 = S[0];
PS[0] = pt0;
bool flg = true;
int dx,dy,x,y;
reps(i,1,N){
dx = S[i].first - pt0.first;
dy = S[i].second - pt0.second;
x=dx*a-dy*b;
y=dx*b+dy*a;
if(((x%c)!=0) || ((y%c)!=0)) {flg = false; break;}
PS[i] = make_pair(x/c+pt0.first, y/c+pt0.second);
}
if(flg) return PS;
else return vector<pair<int,int>>();
}
int main(){
std::cin.tie(0);
std::ios::sync_with_stdio(false);
int N;cin >> N;
vector<pair<int,int>> S(N),T(N);
rep(i,N)
{
int x,y;
cin >> x >> y;
S[i].first = x;S[i].second = y;
}
rep(i,N)
{
int x,y;
cin >> x >> y;
T[i].first = x;
T[i].second = y;
}
sort(allrange(T));
/*ピタゴラ三角形
5 12 13
8 15 17
3 4 5
*/
constexpr int tri[12][3] ={
{3,4,5},
{4,3,5},
{-3,4,5},
{-4,3,5},
{0,1,1},
{1,0,1},
{-1,0,1},
{0,-1,1},
{-3,-4,5},
{-4,-3,5},
{3,-4,5},
{4,-3,5}
};
/*
vector<vector<int>> tri(0);
tri.push_back(vector<int>({3,4,5}));
tri.push_back(vector<int>({4,3,5}));
tri.push_back(vector<int>({-3,4,5}));
tri.push_back(vector<int>({-4,3,5}));
tri.push_back(vector<int>({0,1,1}));
tri.push_back(vector<int>({1,0,1}));
tri.push_back(vector<int>({-1,0,1}));
tri.push_back(vector<int>({0,-1,1}));
tri.push_back(vector<int>({-3,-4,5}));
tri.push_back(vector<int>({-4,-3,5}));
tri.push_back(vector<int>({3,-4,5}));
tri.push_back(vector<int>({4,-3,5}));
// tri.push_back(vector<int>({-5, -12, 13}));
// tri.push_back(vector<int>({-12, -5, 13}));
// tri.push_back(vector<int>({-8,-15,17}));
// tri.push_back(vector<int>({-15,-8,17}));
// tri.push_back(vector<int>({5, 12, 13}));
// tri.push_back(vector<int>({12, 5, 13}));
// tri.push_back(vector<int>({8,15,17}));
// tri.push_back(vector<int>({15,8,17}));
// tri.push_back(vector<int>({-5, 12, 13}));
// tri.push_back(vector<int>({-12, 5, 13}));
// tri.push_back(vector<int>({-8,15,17}));
// tri.push_back(vector<int>({-15,8,17}));
// tri.push_back(vector<int>({5, -12, 13}));
// tri.push_back(vector<int>({12, -5, 13}));
// tri.push_back(vector<int>({8,-15,17}));
// tri.push_back(vector<int>({15,-8,17}));
*/
bool flg;
if(N==2){
auto sx = S[0].first-S[1].first;
auto sy = S[0].second-S[1].second;
auto tx = T[0].first-T[1].first;
auto ty = T[0].second-T[1].second;
flg= (sx*sx+sy*sy==tx*tx+ty*ty);
} else {
rep(j,12){
auto S2 = Pitagora_rot(S,tri[j][0],tri[j][1],tri[j][2]);
if(S2.empty()) continue;
sort(allrange(S2));
flg = solve_translated(S2,T);
if(flg) break;
}
}
if(flg) prl("Yes"); else prl("No");
}
|
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define input_output freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
template <typename Arg1>
void prn(Arg1&& arg1) { cout<<arg1<<"\n";}
template <typename Arg1, typename... Args>
void prn(Arg1&& arg1, Args&&... args) { cout<<arg1<<" "; prn(args...); }
template <typename Arg1>
void prs(Arg1&& arg1) { cout<<arg1<<" ";}
template <typename Arg1, typename... Args>
void prs(Arg1&& arg1, Args&&... args) { cout<<arg1<<" "; prs(args...); }
template <typename Arg1>
void read(Arg1&& arg1) { cin>>arg1; }
template <typename Arg1, typename... Args>
void read(Arg1&& arg1, Args&&... args) { cin>>arg1; read(args...); }
#define int long long
#define all(ds) ds.begin(), ds.end()
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define gcd(x,y) __gcd(x,y)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define precise(x) cout<<fixed<<setprecision(x)
#define endl "\n"
const long long INF = 1e18;
const int32_t MOD = 1e9+7;
const int N = 2e5+5;
int n, m, k, q, r, l, x, y, z;
int a[N], b[N], c[N];
string s, t;
int ans ;
unordered_map<int, int>dp;
int recur(int y){
if(dp.find(y) != dp.end())return dp[y];
dp[y] = abs(y-x);
if(y == 1){
return dp[y];
}
if(y%2 == 0){
dp[y] = min(dp[y], 1 + recur(y/2));
}
else{
dp[y] = min(dp[y], 1 + min(recur(y-1), recur(y+1)));
}
return dp[y];
}
void solve(){
read(x,y);
// ans = abs(x-y);
prn(recur(y));
}
signed main()
{
#ifndef ONLINE_JUDGE
input_output
#else
fastio
#endif
#ifdef SIEVE
sieve();
#endif
#ifdef NCR
init();
#endif
int t = 1;
// cin>>t;
while(t--){
solve();
}
return 0;
} | #include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int N = 810;
int a[N][N], sum[N][N];
int n, k, ju;
bool check(int mid) {
for (int i = 1; i <= n; i ++) {
for (int j = 1; j <= n; j ++) {
int t = (a[i][j] > mid);
sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + t;
}
}
for (int i = k; i <= n; i ++)
for (int j = k; j <= n; j ++) {
int t = sum[i][j] - sum[i][j - k] - sum[i - k][j] + sum[i - k][j - k];
if (t < ju) return 1;
}
return 0;
}
int main() {
cin >> n >> k;
ju = k * k / 2 + 1;
for (int i = 1; i <= n; i ++)
for (int j = 1; j <= n; j ++) cin >> a[i][j];
int l = 0, r = 1e9;
while (l < r) {
int mid = l + r >> 1;
if (check(mid)) r = mid;
else l = mid + 1;
}
cout << l;
return 0;
}
|
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define RNG(i, s, n) for(int i = s;i <= n;i++)
#define _RNG(i, e, s) for(int i = e;i >= s;i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define dup(x, y) (x + y - 1) / (y)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define lb(x, key) lower_bound(all(x) , (key))
#define ub(x, key) upper_bound(all(x) , (key))
#define _size(v) int((v).size())
template<class T>
bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
} else return false;
}
template<class T>
bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
} else return false;
}
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vpi = vector<pi>;
using vpl = vector<pl>;
#define debug(arr) cout << #arr << " = " << arr << '\n'
#define debug2(a, b) cout<<"["<<#a<<","<<#b<<"] = "<<"["<<a<<","<<b<<"]\n"
#define debug3(a, b, c) cout<<"["<<#a<<","<<#b<<","<<#c<<"] = "<<"["<<a<<","<<b<<","<<c<<"]\n"
template<class T>
ostream &operator<<(ostream &out, const vector<T> &arr) {
cout << "{";
for (int i = 0; i < arr.size(); i++)cout << (!i ? "" : ", ") << arr[i];
cout << "}";
return out;
}
template<class T>
ostream &operator<<(ostream &out, const vector<vector<T> > &arr) {
cout << "{\n";
for (auto &vec : arr)cout << " " << vec << ",\n";
cout << "}";
return out;
}
template<class S, class T>
ostream &operator<<(ostream &out, const pair<S, T> &p) {
cout << "{" << p.first << "," << p.second << "}" << '\n';
return out;
}
template<class T>
istream &operator>>(istream &in, vector<T> &arr) {
for (auto &i : arr)cin >> i;
return in;
}
template<class S, class T>
istream &operator>>(istream &in, pair<S, T> &p) {
cin >> p.first >> p.second;
return in;
}
template<class T>
T binom_lucas(T n, T k, T p) {
auto f = [&](T n, T k) {
if (n < 0 || k < 0 || n < k) return 0;
T res = 1;
for (int i = 1; i <= k; i++) {
res = (res * T(n + 1 - i));
res /= T(i);
res %= p;
}
return res;
};
T res = 1;
while (n) {
res = res * f(n % p, k % p);
n /= p;
k /= p;
res %= p;
}
return res;
}
int main(int argc, char const *argv[])
{
int N;
string s;
cin >> N >> s;
map<char , int> M;
M['R'] = 0,M['B'] = 1,M['W'] = 2;
ll sum = 0;
REP(i,N)
{
sum += binom_lucas(N-1,i,3) * M[s[i]];
// debug(binom_lucas(N-i,i,3));
sum %= 3;
}
// debug(sum);
if(N % 2 == 0)
{
sum = (3 - sum) % 3;
}
string A = "RBW";
cout << A[sum] << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
const ll MOD = 1e9+7;
ll modpow(ll a, ll n, ll p) {
ll res = 1;
while (n) {
if (n & 1) res = res * a % p;
a = a * a % p;
n >>= 1;
}
return res;
}
ll modinv(ll a, ll p = MOD) { return modpow(a, p-2, p); }
vvll cross(vvll &a, vvll &b) {
int n = (int)a.size();
int m = (int)b.size();
int nm = (int)a[0].size();
vvll res(n,vll(m,0));
rep(i,n) rep(j,m) rep(k,nm) ( res[i][j] += a[i][k] * b[k][j] ) %= MOD;
return res;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll n, m, k; cin >> n >> m >> k;
vvll a(n,vll(1)); rep(i,n) cin >> a[i][0];
vvll dp(n,vll(n,0)); rep(i,n) dp[i][i] = 1;
rep(i,m) {
ll s, t; cin >> s >> t; s--; t--;
( dp[s][s] -= modinv( 2 * m ) - MOD ) %= MOD;
( dp[s][t] += modinv( 2 * m ) ) %= MOD;
( dp[t][t] -= modinv( 2 * m ) - MOD ) %= MOD;
( dp[t][s] += modinv( 2 * m ) ) %= MOD;
}
while ( k ) {
if ( k & 1 ) a = cross( dp, a );
dp = cross( dp, dp );
k >>= 1;
}
rep(i,n) cout << a[i][0] << endl;
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
int a,b,c;
cin >> a >> b >> c;
if((c*b)%a==0) cout << c*b/a-1 <<endl;
else cout << c*b/a << endl;
} | #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(){
ll x, y, z;
cin>>x>>y>>z;
ll low = 0, high = 1e18;
while(low<high){
ll mid = low + (high-low+1)/2;
ld tmp = (ld)y/x;
ld tmp1 = (ld)mid/z;
if(tmp>tmp1){
low = mid;
}
else{
high = mid-1;
}
}
// ld tmp = (ld)y/x;
// ld tmp1 = (ld)z/593;
// cout<<tmp<<" "<<tmp1<<endl;
cout<<low<<endl;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int tc=1;
// cin>>tc;
while(tc--){
nikal_pehli_fursat_mai();
}
}
|
// Template
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <tuple>
#include <utility>
#include <queue>
#include <set>
#include <map>
#define rep_override(x, y, z, name, ...) name
#define rep2(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep3(i, l, r) for (int i = (int)(l); i < (int)(r); ++i)
#define rep(...) rep_override(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll infll = 3003003003003003003LL;
template <typename T>
inline bool chmin(T &x, const T &y) {
if (x > y) {
x = y;
return true;
}
return false;
}
template <typename T>
inline bool chmax(T &x, const T &y) {
if (x < y) {
x = y;
return true;
}
return false;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
for (T &element : vec) is >> element;
return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
for (int i = 0, vec_len = (int)vec.size(); i < vec_len; ++i) {
os << vec[i] << (i + 1 == vec_len ? "" : " ");
}
return os;
}
struct IOSET {
IOSET() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
}
} ioset;
// Main
int main() {
int n, m;
cin >> n >> m;
vector<int> a(m), b(m), c(m);
rep(i, m) {
int u, v;
char ch;
cin >> u >> v >> ch;
a[i] = u - 1;
b[i] = v - 1;
c[i] = ch - 'a';
}
vector<vector<int>> g(n * n);
rep(i, m) rep(j, m) {
if (c[i] == c[j]) {
g[a[i] * n + a[j]].push_back(b[i] * n + b[j]);
g[a[i] * n + b[j]].push_back(b[i] * n + a[j]);
g[b[i] * n + a[j]].push_back(a[i] * n + b[j]);
g[b[i] * n + b[j]].push_back(a[i] * n + a[j]);
}
}
vector<int> dist(n * n, inf);
queue<int> que;
rep(i, n) {
dist[i * n + i] = 0;
que.push(i * n + i);
}
rep(i, m) {
if (chmin(dist[a[i] * n + b[i]], 1)) que.push(a[i] * n + b[i]);
if (chmin(dist[b[i] * n + a[i]], 1)) que.push(b[i] * n + a[i]);
}
while (!que.empty()) {
int v = que.front();
que.pop();
for (int u : g[v]) {
if (chmin(dist[u], dist[v] + 2)) que.push(u);
}
}
int ans = dist[n - 1];
if (ans == inf) ans = -1;
cout << ans << "\n";
} | #include<bits/stdc++.h>
using namespace std;
struct edge {
int to;
int c;
edge(int to, int c) : to(to), c(c) {}
};
const int INF = 1001001001;
int main()
{
int n, m;
cin >> n >> m;
vector<vector<edge>> g(n);
for(int i = 0; i < m; i++) {
int a, b;
char c;
cin >> a >> b >> c;
a--;
b--;
g[a].emplace_back(b, c - 'a');
g[b].emplace_back(a, c - 'a');
}
vector<vector<int>> dp(n, vector<int>(n, INF));
queue<pair<int, int>> q;
auto push = [&](int a, int b, int x) {
if(dp[a][b] != INF) return;
dp[a][b] = x;
q.emplace(a, b);
};
push(0, n - 1, 0);
while(!q.empty()) {
auto [a, b] = q.front();
q.pop();
for(auto&& ea : g[a]) {
for(auto&& eb : g[b]) {
if(ea.c != eb.c) continue;
push(ea.to, eb.to, dp[a][b] + 1);
}
}
}
int ans = INF;
for(int i = 0; i < n; i++) {
ans = min(ans, dp[i][i] * 2);
for(auto&& e : g[i]) ans = min(ans, dp[i][e.to] * 2 + 1);
}
if(ans == INF) ans = -1;
cout << ans << endl;
return 0;
} |
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int N;
cin >> N;
int A[N];
for(int i = 0; i < N; i++){
cin >> A[i];
}
sort(A, A + N);
for(int i = 1; i <= N; i++){
if(i != A[i - 1]){
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
return 0;
} | ////JAI SHREE RAM////
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
const long long int INF = (long long)1e15;
const long long int mod = 1e9+7;
#define ll long long
#define f(i,a,b) for(int i=a;i<b;i++)
#define pb push_back
#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define sd second
#define ft first
//
bool cmp(const pair<int,int> &a, const pair<int,int> &b)
{
//return (a.sd>=b.sd);
return abs(a.ft)+abs(a.sd) < abs(b.ft)+abs(b.sd);
}
void solve()
{
int n;cin>>n;
string s;cin>>s;
if(n>1 && s[0]!=s[n-1]){
cout<<1<<endl;
return;
}
f(i,1,n-1){
if(s[i]!=s[0] && s[i+1]!=s[n-1]){
cout<<2<<endl;
return;
}
}
cout<<-1<<endl;
}
int main()
{
ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);
int t=1;
//cin>>t;
while(t--)
{
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
//.define
// #define FILE_IN_OUT
#define RET(_x) return cout << (_x) << '\n', 0;
#define all(_obj) (_obj).begin(), (_obj).end()
#define loop(_n) for (int i = 0; i < (_n); ++i)
#define sz(_obj) static_cast<int>((_obj).size())
#ifdef SHJ_LOCAL
#define debug(_x) std::cerr << (#_x) << " = " << (_x) << '\n' << std::flush;
#else
#define debug(_x) {}
#endif
#define endl "\n"
template<typename P, typename Q>
P CeilDiv(P _dividend, Q _divider) {
return static_cast<P>((_dividend - 1LL + _divider) / _divider);
}
template<typename Tp>
inline void outarr(Tp _begin, Tp _end, const char* _delim = " ") {
for (Tp current = _begin; current != _end; ++current) {
std::cout << *current << _delim;
}
std::cout << '\n';
}
//.constant
using ll = int64_t;
using pii = std::pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr int MOD = static_cast<int>(1e9 + 7);
//.data
constexpr int MAXN = 105;
char dp[MAXN][MAXN];
bool Win(char a, char b) {
if (a == b) {
return true;
}
if (a == 'R') {
return b == 'S';
}
if (a == 'P') {
return b == 'R';
}
return b == 'P';
}
int Mul(int x, int y, int mod) {
return int(1LL * x * y % mod);
}
int Add(int x, int y, int mod) {
x += y;
return x < mod ? x : x - mod;
}
int FastPow(int x, int p, int mod) {
int res = 1;
while (p > 0) {
if (p & 1) {
res = Mul(res, x, mod);
}
p >>= 1;
x = Mul(x, x, mod);
}
return res;
}
//.code
int main() {
#ifdef FILE_IN_OUT
std::ifstream cin ("input.txt", std::ios::in);
std::ofstream cout("output.txt", std::ios::out);
#else
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
#endif
int n, k;
string s;
cin >> n >> k >> s;
loop(n) {
dp[0][i] = s[i];
}
for (int i = 1; i <= k; ++i) {
for (int j = 0; j < n; ++j) {
int x = FastPow(2, i - 1, n);
dp[i][j] = Win(dp[i - 1][j], dp[i - 1][Add(j, x, n)]) ? dp[i - 1][j] : dp[i - 1][Add(j, x, n)];
}
}
cout << dp[k][0] << endl;
#ifdef FILE_IN_OUT
cin.close();
cout.close();
#endif
return 0;
} | #include <iostream>
#include <vector>
#include <math.h>
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int main() {
int n, k;
cin >> n >> k;
string s;
cin >> s;
// R .. グー P .. パー S .. チョキ
string t = s + s;
rep(a, k){
string t = s + s;
for(int i = 0; i < n; i++){
if(t[i*2] == 'R' and t[i*2+1] == 'R'){
s[i] = 'R';
}else if(t[i*2] == 'R' and t[i*2+1] == 'P'){
s[i] = 'P';
}else if(t[i*2] == 'R' and t[i*2+1] == 'S'){
s[i] = 'R';
}else if(t[i*2] == 'P' and t[i*2+1] == 'R'){
s[i] = 'P';
}else if(t[i*2] == 'P' and t[i*2+1] == 'P'){
s[i] = 'P';
}else if(t[i*2] == 'P' and t[i*2+1] == 'S'){
s[i] = 'S';
}else if(t[i*2] == 'S' and t[i*2+1] == 'R'){
s[i] = 'R';
}else if(t[i*2] == 'S' and t[i*2+1] == 'P'){
s[i] = 'S';
}else if(t[i*2] == 'S' and t[i*2+1] == 'S'){
s[i] = 'S';
}
}
}
cout << s[0] << endl;
} |
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define reps(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define repi(i, x) \
for (auto i = (x).begin(), i##_fin = (x).end(); i != i##_fin; i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int, int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long, long long> P;
typedef vector<P> VP;
template <class T>
inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
os << "(" << p.first << " " << p.second << ")";
return os;
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
#ifdef LOCAL
os << "{";
#endif
rep(i, v.size()) {
if (i) os << " ";
os << v[i];
}
#ifdef LOCAL
os << "}";
#endif
return os;
}
template <class T, class U>
istream& operator>>(istream& is, pair<T, U>& p) {
is >> p.first >> p.second;
return is;
}
template <class T>
istream& operator>>(istream& is, vector<T>& v) {
rep(i, v.size()) { is >> v[i]; }
return is;
}
const long long INFLL = 1LL << 60;
const int INF = 1 << 30;
const double PI = acos(-1);
#ifdef LOCAL
#define dbg(x) cerr << #x << ": " << (x) << '\n'
#define say(x) cerr << (x) << '\n'
#else
#define dbg(x)
#define say(x)
#endif
void init_main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
}
string solve(bool a) { return ((a) ? "Yes" : "No"); }
int main() {
init_main();
int a,b;
double ans = 0.0;
cin >> a>>b;
ans = (double)b * a / 100.0;
cout<< fixed << setprecision(15) << ans << '\n';
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln = '\n';
constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
constexpr long long INF = 1000000000 + 100;
constexpr long long LINF = 1000000000000000000 + 100;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int main(){
int t; cin >> t;
string a = "atcoder";
vector<int> ans;
while(t--){
string s; cin >> s;
if(s>a)ans.push_back(0);
else{
int first_index = -1;
rep(i, s.size()){
if(s[i]!='a'){
first_index = i;
if(s[i]<='t')first_index++;
break;
}
}
if(first_index==-1)ans.push_back(-1);
else ans.push_back(first_index-1);
}
}
for(auto a:ans)cout << a << ln;
} |
#include<bits/stdc++.h>
template <typename _Tp>void read(_Tp &x){
char ch(getchar());bool f(false);while(!isdigit(ch))f|=ch==45,ch=getchar();
x=ch&15,ch=getchar();while(isdigit(ch))x=x*10+(ch&15),ch=getchar();
if(f)x=-x;
}
template <typename _Tp,typename... Args>void read(_Tp &t,Args &...args){read(t);read(args...);}
const int N=200005;
typedef long long ll;
int a[N];
int main(){
int n;read(n);
int mx=0;
ll s=0,S=0;
for(int i=1;i<=n;++i){
read(a[i]),mx=std::max(a[i],mx);
s+=a[i],S+=s;
printf("%lld\n",S+1LL*i*mx);
}
return 0;
} | #include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
int main(){
int n,m; cin>>n>>m;
ll a{},b{};
for(int i=0; i<n; i++){
string s; cin>>s;
int cnt{};
for(auto i:s)if(i=='1')cnt++;
if(cnt%2) a++;
else b++;
}
cout<<a*b<<endl;
} |
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "/debug.h"
#else
#define db(...)
#endif
#define all(v) v.begin(), v.end()
#define pb push_back
using ll = long long;
const int NAX = 2e5 + 5, MOD = 1000000007;
class UnionFind
{ // OOP style
private:
vector<int> p, rank, setSize; // remember: vi is vector<int>
int numSets;
public:
UnionFind(int N)
{
setSize.assign(N, 1);
numSets = N;
rank.assign(N, 0);
p.assign(N, 0);
for (int i = 0; i < N; i++)
p[i] = i;
}
int findSet(int i) { return (p[i] == i) ? i : (p[i] = findSet(p[i])); }
bool isSameSet(int i, int j) { return findSet(i) == findSet(j); }
bool unionSet(int i, int j)
{
if (!isSameSet(i, j))
{
numSets--;
int x = findSet(i), y = findSet(j);
// rank is used to keep the tree short
if (rank[x] > rank[y])
{
p[y] = x;
setSize[x] += setSize[y];
}
else
{
p[x] = y;
setSize[y] += setSize[x];
if (rank[x] == rank[y])
rank[y]++;
}
return true;
}
return false;
}
int numDisjointSets() { return numSets; }
int sizeOfSet(int i) { return setSize[findSet(i)]; }
};
void solveCase()
{
int n, m;
cin >> n >> m;
vector<vector<pair<int, int>>> adj(n);
UnionFind U(n);
for (size_t i = 0; i < m; i++)
{
int u, v, c;
cin >> u >> v >> c;
--u, --v;
if (U.unionSet(u, v))
{
adj[u].pb({v, c});
adj[v].pb({u, c});
}
}
if (U.sizeOfSet(0) != n)
{
cout << "No\n";
return;
}
vector<int> mexes(n), res(n, -1);
for (size_t i = 0; i < n; i++)
{
set<int> ss;
for (auto &x : adj[i])
ss.insert(x.second);
mexes[i] = 1;
while (ss.count(mexes[i]))
mexes[i]++;
}
function<void(int, int)> dfs = [&](int node, int par) -> void {
if (res[node] == -1)
res[node] = mexes[node];
for (auto &x : adj[node])
if (x.first != par)
{
if (x.second != res[node])
res[x.first] = x.second;
dfs(x.first, node);
}
db(node, par, res[node], mexes[node]);
db(adj[node]);
};
dfs(0, 0);
for (size_t i = 0; i < n; i++)
cout << res[i] << '\n';
}
int32_t main()
{
#ifndef LOCAL
ios_base::sync_with_stdio(0);
cin.tie(0);
#endif
int t = 1;
// cin >> t;
for (int i = 1; i <= t; ++i)
solveCase();
return 0;
} | #define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
vector<pair<int,int>> G[100010];
int A[100010];
void bfs(int s){
queue<int> q;
A[s]=1;
q.push(s);
while(!q.empty()){
int t=q.front();
q.pop();
for(auto x:G[t]){
if(A[x.first]!=0) continue;
if(x.second==A[t]){
if(x.second!=1) A[x.first]=1;
else A[x.first]=2;
}
else{
A[x.first]=x.second;
}
q.push(x.first);
}
}
}
int main(){
int n,m;
cin>>n>>m;
rep(i,m){
int u,v,c;
cin>>u>>v>>c;
G[u].push_back({v,c});
G[v].push_back({u,c});
}
bfs(1);
for(int i=1;i<=n;i++) cout<<A[i]<<endl;
return 0;
} |
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main()
{
int n;
cin >>n;
int a[n];
int b[n];
for(int i=0; i<n; i++)
{
cin>>a[i];
}
for(int j=0; j<n; j++)
{
cin >>b[j];
}
int s=0;
for(int i=0; i<n ;i++)
{
s=s+(a[i]*b[i]);
}
//cout <<s;
if(s==0)
cout<<"Yes";
else
cout <<"No";
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ull=unsigned long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=((ll)n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=((ll)a);i<((ll)n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)
int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
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);}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0 : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S,class T>auto&operator<<(ostream&os,map<S,T>mp){bool a=1;for(auto p:mp){os<<(a?"":", ")<<p;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}
/*他のライブラリを入れる場所*/
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
ll n;
cin>>n;
vl a(n),b(n);cin>>a>>b;
ll ans=0;
rep(i,n)ans+=a[i]*b[i];
Yn(ans==0);
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define f first
#define s second
#define pii pair<int,int>
const int N =3e5+5;
const int MOD = 1e9+7;
ll qpow(ll a, ll b, ll m)
{
ll ans=1;
while(b)
{
if(b&1)
ans=(ans*a)%m;
b/=2;
a=(a*a)%m;
}
return ans;
}
//vector<int>adj[200005];
//vector<int>a,val;
//vector<bool>vis;
int a[200005];
int val[200005];
bool vis[200005];
vector<int>adj[200005];
ll ans = -1e18;
void dfs(int v, int par){
vis[v] = true;
for(int u:adj[v]){
if(u!=par){
ans = max(ans, (ll)a[u]-val[v]);
val[u] = min(val[v], a[u]);
if(!vis[u])
dfs(u, v);
}
}
}
ll x,y;
map<ll,ll>m;
ll func(ll v){
if(v<=x){
return m[v] = x-v;
}
if(m[v]) return m[v];
ll val = v-x;
if(v%2){
val = min(val, func(v-1)+1);
val = min(val, func(v+1)+1);
}
else{
val = min(val, func(v/2)+1);
}
return m[v] = val;
}
int main()
{
IOS;
int t=1; //cin>>t;
while(t--){
cin>>x>>y;
cout<<func(y);
}
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll x,y;
map<ll,ll>f;
ll dfs(ll u)
{
if(!u) return x;
if(f[u]) return f[u];
ll &ans=f[u];
ans=abs(x-u);
if(u%2==0) ans=min(ans,1+dfs(u/2));
else ans=min(ans,min(1+dfs(u-1),1+dfs(u+1)));
return ans;
}
int main()
{
cin>>x>>y;
printf("%lld\n",dfs(y));
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define sz(x) ((int) x.size())
#define all(x) x.begin(), x.end()
#define debug if (true) cerr
using ll = long long;
ll N;
void solve() {
cin >> N;
ll answer = N;
rep(b, 0, 60) {
ll B = 1LL << b;
if (B > N) continue;
ll A = N / B;
ll C = N - A * B;
// cout << A << " " << B << " " << C << endl;
answer = min(A+b+C, answer);
}
cout << answer << '\n';
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
solve();
return 0;
} | #include<bits/stdc++.h>
using namespace std;
typedef long long LL;
LL n;
void into(){
scanf("%lld",&n);
LL a=(1LL<<60)-1,b=0,c=0;
for (LL y=0;1LL<<y<=n;++y){
LL x=n>>y,z=n&(1LL<<y)-1;
if (x+y+z<a+b+c) a=x,b=y,c=z;
}
//printf("%lld %lld %lld\n",a,b,c);
printf("%lld\n",a+b+c);
}
void work(){
}
void outo(){
}
int main(){
int T=1;
//scanf("%d",&T);
for (;T--;){
into();
work();
outo();
}
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#define LL long long
LL Num;
LL Cnt[3],Loc;
int main() {
cin>>Num;
LL Temp=Num%3;
while(Num) {
Loc++;
Cnt[Num%10%3]++;
Num/=10;
}
if(Temp==0) printf("0\n");
else if(Temp==1) {
if(Cnt[1] >= 1 && 1 < Loc) printf("1\n");
else if(Cnt[2]>=2 && 2<Loc) printf("2\n");
else printf("-1\n");
}
else
{
if(Cnt[2]>=1 && 1<Loc) printf("1\n");
else if(Cnt[1]>=2 && 2<Loc) printf("2\n");
else printf("-1\n");
}
return 0;
} | #include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <bitset>
#include <cmath>
#include <set>
#include <map>
#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 int inf = 10111111;
int main() {
string s; cin >> s;
vector<int>c(3);
int n = s.size();
rep(i, n)c[(s[i] - '0') % 3]++;
int x = 0;
rep(i, 3)x += c[i] * i;
int ans = inf;
rep(i1, 3)rep(i2, 3) {
if (c[1] < i1)continue;
if (c[2] < i2)continue;
if (i1 + i2 == n)continue;
int cal = x;
cal -= 1 * i1;
cal -= 2 * i2;
if (cal % 3 == 0) {
ans = min(ans, i1 + i2);
}
}
if (ans == inf)ans = -1;
cout << ans << endl;
} |
#include <iostream>
using namespace std;
int main(void){
int A, B;
cin >> A >> B;
int sum = 0;
int i, j;
for (i = 1; i < A; i++) {
cout << i << " ";
sum += i;
}
for (j = 1; j < B; j++) {
cout << -j << " ";
sum -= j;
}
if(sum > 0){
cout << i << " " << -(sum + i) << endl;
} else {
cout << -j << " " << j - sum << endl;
}
} | /*
Author : DEBAPRIYA CHANDRA
[JGEC]
*/
#include<bits/stdc++.h>
#define ll long long int
#define dbl long double
#define loop(i,n) for(int i=0;i<n;i++)
#define test(t) int t;cin>>t;while(t--)
#define debo ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define vi vector<ll>
#define sz size()
#define iss is_sorted
#define bs binary_search
#define mx INT_MAX
#define mi INT_MIN
#define gcd(a,b) __gcd(a,b)
#define sw(a,b) swap(a,b)
using namespace std;
bool isPalindrome(string s,int i,int j)
{
if(i>j) return true;
if(s[i]!=s[j]) return false;
else return isPalindrome( s, i+1, j-1);
}
bool isPrime(ll n)
{
if (n <= 1) return false;
if (n <= 3) return true;
if (n % 2 == 0 || n % 3 == 0) return false;
for (int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
signed main(){
debo;
ll a,b;
cin>>a>>b;
if(a>=b)
{
for(ll i=1;i<=a;i++)cout<<i<<" ";
for(ll i=1;i<b;i++)cout<<-i<<" ";
ll sum=0;
for(ll i=b;i<=a;i++){
sum+=i;
}
cout<<-sum<<endl;
}
else {
ll bb[b];
for(ll i=1;i<a;i++)cout<<i<<" ";
for(ll i=1;i<=b;i++)bb[i-1]=-i;
ll sum=0;
for(ll i=a;i<=b;i++){
sum+=i;
}
cout<<sum<<" ";
for(ll i=0;i<b;i++)cout<<bb[i]<<" ";
}
return 0;
} |
#include<iostream>
#include<cmath>
using namespace std;
#define ll long long
ll k,ans,cnt[10],s[10],t[10],cntt[10],cnts[10];
string S,T;
ll che(int x,int y) {
int st=0,ss=0;
cnts[x]++,cntt[y]++;
for(int i=1; i<10; i++) {
ss+=i*pow(10,cnts[i]);
st+=i*pow(10,cntt[i]);
}
cnts[x]--,cntt[y]--;
if(ss<=st)return 0;
if(x==y)return cnt[x]*(cnt[x]-1);
else return cnt[x]*cnt[y];
}
int main() {
cin>>k>>S>>T;
for(int i=1; i<10; i++)cnt[i]=k;
for(int i=1; i<5; i++) {
s[i]=S[i-1]-'0';
t[i]=T[i-1]-'0';
cnt[s[i]]--,cnt[t[i]]--;
cnts[s[i]]++,cntt[t[i]]++;
}
for(int i=1; i<10; i++)
for(int j=1; j<10; j++)
ans+=che(i,j);
double lans=1.0*ans/((9*k-8)*(9*k-9));
printf("%.9f",lans);
} | #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 lowbit(x) x&(-x)
int tr[N],h,w,m,r[N],c[N];
void upd(int x,int v){
while(x<=h){
tr[x]+=v,x+=lowbit(x);
}
}
int que(int x){int s=0;
while(x){
s+=tr[x],x-=lowbit(x);
}
return s;
}
int main(){
scanf("%d%d%d",&h,&w,&m);
fill(r+1,r+h+1,w+1); //初始化
fill(c+1,c+w+1,h+1);
while(m--){
int x,y;scanf("%d%d",&x,&y);
r[x]=min(r[x],y),c[y]=min(c[y],x);
}ll ans=0;bool jg=0;
for(int i=1;i<=h;i++){
if(jg){
r[i]=1;continue;
}
if(r[i]==1){
jg=1;continue;
}
ans+=r[i]-1;
}
vector<int>v[w+2];
for(int i=1;i<=h;i++) v[r[i]].pb(i);
for(int i=1;i<=w;i++){
if(c[i]==1) break;
ans+=que(c[i]-1);
for(int j:v[i]) upd(j,1);
}printf("%lld\n",ans);
return 0;
}
|
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define INP "solve"
#define OUT "solve"
const long long INF_LL = 4e18;
const int INF = 1e9 + 100;
const int MOD = 1e9 + 7;
const long double EPS = 1e-10;
const int BLOCK = 550;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, 1, 0, -1};
mt19937 rnd(chrono::system_clock::now().time_since_epoch().count());
void open_file() {
#ifdef THEMIS
freopen(INP ".inp","r",stdin);
freopen(OUT ".out","w",stdout);
#endif // THEMIS
}
const int maxN = 1e2 + 100;
void sol() {
int n;
cin >> n;
string s;
cin >> s;
vector<int> dp(n + 1, INF);
vector<int> mn(26, INF);
dp[0] = 0;
for (int i = 1; i <= n; i++) {
int c = s[i - 1] - 'a';
for (int nc = 0; nc < 26; nc++) {
if (c == nc) continue;
dp[i] = min(dp[i], mn[nc] + 1);
}
mn[c] = min(mn[c], dp[i - 1]);
}
if (dp[n] == INF) cout << -1 << '\n';
else cout << dp[n] << '\n';
}
void solve() {
clock_t begin = clock();
int T;
//cin >> T;
T = 1;
int TestCase = 0;
while (T--) {
TestCase += 1;
//cout << "Case #" << TestCase << ": ";
//cout << "Test " << TestCase << ": ";
sol();
//if (T) cout << '\n';
}
clock_t end = clock();
cerr << "Time: " << fixed << setprecision(10) << (double)(end - begin) / (double)CLOCKS_PER_SEC << '\n';
}
int main(int argc,char *argv[]) {
///srand(Time(nullptr));
ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr);
open_file();
solve();
}
| #include <queue>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define pii pair <int , int>
#define mp make_pair
#define fs first
#define sc second
using namespace std;
typedef long long LL;
template <typename T>
void read(T &x) {
T f=1;x=0;char s=getchar();
while(s<'0'||s>'9') {if(s=='-') f=-1;s=getchar();}
while(s>='0'&&s<='9') {x=(x<<3)+(x<<1)+(s^'0');s=getchar();}
x *= f;
}
template <typename T>
void write(T x , char s='\n') {
if(!x) {putchar('0');putchar(s);return;}
if(x<0) {putchar('-');x=-x;}
T t = 0 , tmp[25] = {};
while(x) tmp[t ++] = x % 10 , x /= 10;
while(t -- > 0) putchar(tmp[t] + '0');
putchar(s);
}
const int MAXN = 1e5 + 5;
int n , f[MAXN] , val[30];
char s[MAXN];
int main() {
read(n);
scanf("%s" , s + 1);
memset(val , 127 , sizeof val);
val[s[n] - 'a'] = 0;
for (int i = n - 1; i >= 1; --i) {
f[i] = 1e9;
for (int j = 0; j < 26; ++j) if(val[j] < (int)(1e9) && s[i] - 'a' != j) f[i] = min(f[i] , val[j] + 1);
if(f[i] < (int)1e9) val[s[i - 1] - 'a'] = min(val[s[i - 1] - 'a'] , f[i]);
}
if(f[1] < (int)1e9) write(f[1]);
else puts("-1");
return 0;
} |
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
#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>
#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
#define mod 1000000007
#define mod2 998244353
#define pb push_back
#define ll long long
#define fi first
#define lb lower_bound
#define test ll int t;cin>>t;while(t--)
#define se second
#define pll pair<long long,long long>
#define icc ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
ll gcd(ll a, ll b){
if(!a)return b;
return gcd(b%a,a);
}
long long power(long long a,long long b){
long long ans=1;
while(b>0){
if(b&1){ans=(ans*a);}
a=(a*a);
b>>=1;
}
return ans;
}
vector<ll> spf,prime;
void primes(ll n){
spf.assign(n+1,0);
spf[1] = 1;
for(ll i=2; i<=n; i++){
if (!spf[i]){
spf[i]=i;prime.pb(i);
for (ll j=i*i; j<=n; j+=i)
if (!spf[j])
spf[j] = i;
}
}
}
ll fact[1000001];
void factorial(ll n){
fact[0]=1;
for(ll i=1;i<=n;i++){
fact[i]=fact[i-1]*i;
if(fact[i]>=mod)
fact[i]%=mod;
}
}
priority_queue<ll,vector<ll>,greater<ll> > qqqqq;
void solve(){
ll a,b,c,d;
cin>>a>>b>>c>>d;
if(c*d-b<0){cout<<"-1";return;}
for(ll i=0;i<10000000;i++){
if(a<=(c*d-b)*i){
cout<<i;
return ;
}
}
cout<<"-1";
}
int main(){
icc;
//test
solve();
return 0;
}
// ll op;
// cin>>op;
// for(ll fff=1;fff<=op;fff++){
// cout<<"Case #"<<fff<<": "<<ans<<endl;
// }
| //#include <atcoder/maxflow.hpp>
#include <memory>
#include <iostream>
#include <map>
#include <list>
#include <set>
#include <algorithm>
#include <vector>
#include <sstream>
#include <string>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <limits>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <fstream>
#include <iterator>
#include <random>
#include <chrono>
#include <complex>
#include <thread>
#include <bitset>
#define forr(i,start,count) for (int i = (start); i < (start)+(count); ++i)
#define set_map_includes(set, elt) (set.find((elt)) != set.end())
#define readint(i) int i; cin >> i
#define readll(i) ll i; cin >> i
#define readdouble(i) double i; cin >> i
#define readstring(s) string s; cin >> s
typedef long long ll;
using namespace std;
//using namespace atcoder;
//ll modd = (1000LL * 1000LL * 1000LL + 7LL);
ll modd = 998244353;
ll binary_search(function<bool(ll)> func, ll start, ll end) {
/* func:int ->bool
returns smallest int x where func(x) evaluates to true, searches in [start,end), it is assumed the values are false, .. , false, true ...
*/
if (end <= start) { return end; } // has to be here, otherwise func(end-1) in next line could be a problem
if (!func(end-1)) { return end; }
while (end-start>1) {
ll mid = (start+end)/2;
if (func(mid)) { end = mid; } else { start = mid; }
}
if (func(start)) { return start; } else { return end; }
};
int main(int argc, char *argv[]) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.precision(17);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_int_distribution<int> rand_gen(0, modd); // rand_gen(rng) gets the rand no
// auto start = chrono::steady_clock::now();
// readint(test_cases);
int test_cases = 1;
forr(t, 1, test_cases) {
readint(n); readint(m);
vector<vector<pair<int,ll>>> adj(n);
forr(i,0,m) {
readint(aa); readint(bb); readll(cc); --aa; --bb;
adj[aa].push_back(make_pair(bb,cc));
}
vector<vector<ll>> dist;
forr(i,0,n) {
priority_queue<pair<ll,int>> todo;
for(auto nn : adj[i]) {
todo.push(make_pair(-nn.second, nn.first));
}
dist.push_back(vector<ll>(n, modd*modd));
while (!todo.empty()) {
auto curr = todo.top(); todo.pop();
if (-curr.first < dist.back()[curr.second]) {
dist.back()[curr.second] = -curr.first;
for(auto nn : adj[curr.second]) {
todo.push(make_pair(-nn.second+curr.first, nn.first));
}
}
}
cout << ((dist.back()[i] == modd*modd) ? -1 : dist.back()[i]) << endl;
}
}
// auto stop = chrono::steady_clock::now();
// auto duration = chrono::duration_cast<chrono::milliseconds>(stop - start);
// cout << "Duration: " << duration.count() << endl;
return 0;
}
|
#include "bits/stdc++.h"
using namespace std;
#define pi acos(-1)
#define inc(a) a.begin(), a.end()
#define dec(a) a.rbegin(), a.rend()
#define Unique(n) (n).erase(unique(inc(n)), (n).end())
#define what_is(x) cerr << #x << " is " << x << '\n';
#define to(i, a, n) for(ll i=a; i<=n; i++)
#define fr(i, a, n) for(int i=a; i>=n; i--)
#define read(arr, l, r) for(int i=l; i<r; cin >> arr[i++])
#define prnt(arr, l, r) for(int i=l; i<r; cout << arr[i++] << " \n"[i==r])
typedef long long ll;
typedef long double ld;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
ll n, res, l, r, mid, sum;
ll check(ll x, ll y, ll ans = 0){
x--;
if(x & 1) ans = - ((x + 1) / 2) * x;
else ans = - (x + 1) * (x / 2);
if(y & 1) ans += ((y + 1) / 2) * y;
else ans += (y + 1) * (y / 2);
return ans;
}
bool bin(ll x){
l = 1, r = n/x + 1;
while (l <= r){
mid = (l+r) / 2;
sum = check(mid, mid+x-1);
if(sum == n) return true;
else if(sum > n) r = mid-1;
else l = mid+1;
}
return false;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
to(i, 1, 10000000)
if(bin(i)) res += 2;
cout << res;
return 0;
} | #include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define fst ios_base::sync_with_stdio(false);cin.tie(0), cout.tie(0);
#define pb push_back
#define mp make_pair
#define gcd __gcd
#define f first
#define s second
#define mm(arr) memset(arr, 0, sizeof(arr))
#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 mod 1000000007
typedef long long ll;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
int fact(int n);
int nCr(int n, int r) {return fact(n) / (fact(r) * fact(n - r));}
int fact(int n){
int res = 1;
for (int i = 2; i <= n; i++)
res = res * i;
return res;
}
bool isPrime(int n){
// Corner cases
if (n <= 1)
return false;
if (n <= 3)
return true;
if (n % 2 == 0 || n % 3 == 0)
return false;
for (int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
void solve(){
int k;
cin >> k;
int ans = 0;
for(int i = 1; i <= k; i++){
for(int j = 1; j <= (k / i) + 1; j++){
if (i * j <= k){
ans += (k / (i * j));
}
}
}
cout << ans << "\n";
}
//const int k = 2e5 + 5;
int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int t = 1;
// cin >> t;
while(t--){
solve();
}
return 0;
} |
#include<bits/stdc++.h>
#define fastcall __attribute__((optimize("-O3")))
#pragma GCC optimize(1)
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#define db double
#define il inline
#define iL (1<<20)
#define re register
#define ll long long
#define ui unsigned int
#define ull unsigned long long
#define TEM template<class T>il void
#define Write(x,LC) write((x)),*iter++=LC
#define Writeneg(x,LC) writeneg((x)),*iter++=LC
#define flush() fwrite(Out,1,iter-Out,stdout),iter=Out
#define gc() ((iS==iT)?(iT=(iS=ibuf)+fread(ibuf,1,iL,stdin),(iS==iT)?EOF:*iS++):*iS++)
using namespace std;
namespace IO{
char ibuf[iL],*iS=ibuf+iL,*iT=ibuf+iL,Out[iL],*iter=Out;
TEM read(re T &x){re char c;for(c=gc();!isdigit(c);c=gc());for(x=0;isdigit(c);x=(x<<1)+(x<<3)+(c^48),c=gc());}
TEM write(re T x){re T c[35],l;for(l=0;!l||x;c[l++]=x%10,x/=10);for(;l;*iter++=c[--l]+'0');flush();}
}
using namespace IO;
// int a,b,w;
int n,m,T;
struct Node{
int w,v;
}a[55];
struct Box{
int v,id;
}b[55];
bool vis[55];
il bool CMP(Box x,Box y){return x.v<y.v;}
il bool cmp(Node x,Node y){return x.v>y.v||(x.v==y.v&&x.w<y.w);}
int main(){
// cin>>a>>b>>w;w=w*1000;
// if(w<a){printf("UNSATISFIABLE");return 0;}
// int fl=0;
// while(w>b)++fl,w-=b;
// if(w<a){
// w+=b,--fl;
// if(w>=a+a){
// cout<<fl+2;
// return 0;
// }
// }
scanf("%d%d%d",&n,&m,&T);
for(re int i=1;i<=n;++i)scanf("%d%d",&a[i].w,&a[i].v);
for(re int i=1;i<=m;++i)scanf("%d",&b[i].v),b[i].id=i;
sort(a+1,a+1+n,cmp),sort(b+1,b+1+m,CMP);
for(re int _=0,l,r;_<T;++_){
scanf("%d%d",&l,&r);
int ans=0;
for(re int i=1;i<=m;++i)vis[i]=false;
for(re int i=1;i<=n;++i){
for(re int j=1;j<=m;++j){
if(b[j].id>=l&&b[j].id<=r)continue;
if(!vis[j]&&a[i].w<=b[j].v){vis[j]=true,ans+=a[i].v;break;}
}
}
printf("%d\n",ans);
}
} | #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>
using namespace std;
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());
typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vi> vvi;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 29);
const ll LINF = 1e18;
const double PI = acos(-1);
template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
for (auto& e : t) fill_v(e, v);
}
template<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;
}
typedef pair<int, int> P;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N, M, Q;
cin >> N >> M >> Q;
vector<P> V(N);
REP(i, N) {
cin >> V[i].first >> V[i].second;
}
vi X(M);
REP(i, M) {
cin >> X[i];
}
REP(i, Q) {
int L, R;
cin >> L >> R;
L--;R--;
vi curX;
for (int i = 0; i < L;i++) {
curX.push_back(X[i]);
}
for (int i = R + 1;i < M;i++) {
curX.push_back(X[i]);
}
so(curX);
int ans = 0;
vector<P> curV = V;
REP(i, SZ(curX)) {
int ind = -1;
int maxV = 0;
REP(j, SZ(curV)) {
if (curX[i] >= curV[j].first && maxV < curV[j].second) {
ind = j;
maxV = curV[j].second;
}
}
if (ind != -1) {
ans += curV[ind].second;
curV.erase(curV.begin() + ind);
}
}
cout << ans << endl;
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int const MAXN = 2e6 + 10;
int n, m, T;
int a[MAXN];
int num[MAXN];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= m; i++) num[a[i]]++;
int ans = 1e9;
for (int i = 0; ; i++)
if (!num[i]) {
ans = i;
break;
}
for (int i = m + 1; i <= n; i++) {
num[a[i-m]]--;
num[a[i]]++;
//cout << a[i - m] << " " << a[i] << endl;
if (!num[a[i-m]]) ans = min(ans, a[i-m]);
}
cout << ans;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i < b; i ++ )
int n, m;
vector<int> v[1500005];
int main(void)
{
cin >> n >> m;
rep(i, 0, n)
{
int x; scanf("%d", &x);
if (x < m) v[x].push_back(i);
}
rep(i, 0, m + 1)
{
// cout << v[i].size() << endl;
if (v[i].empty())
{
cout << i << "\n";
return 0;
}
bool flag = false;
int last = -1;
for (int it : v[i])
{
if (it - last <= m) last = it;
else
{
flag = true;
break;
}
}
if (n - last > m) flag = true;
if (flag) {cout << i << "\n"; return 0;}
}
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define debug(x) cout<<#x<<" :"<<x<<endl;
#define ff first
#define ss second
#define ar array
#define int long long
#define ld long double
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vpii vector<pair<int,int>>
#define mii map<int,int>
#define pqb priority_queue<int>
#define pqs priority_queue<int,vi,greater<int> >
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x,y) fixed<<setprecision(y)<<x
#define mk(arr,n,type) type *arr=new type[n];
#define w(x) int x; cin>>x; while(x--)
#define f(i,n) for(int i=0;i<n;i++)
#define MOD 1000000007
#define pi 3.14159265
#define umii unordered_map<int,int>
#define umci unordered_map<char,int>
#define umsi unordered_map<string,int>
#define sz(s) (int)s.size()
void KruNULL()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b)
{
return (a.second < b.second);
}
int gcd(int a, int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int prime(int n) {
int flag = 1;
for (int i = 2; i <= sqrt(n); i++) {
if (n % i == 0) {flag = 0; break;}
}
return flag;
}
int power(int x, int y)
{
if (y == 0)
return 1;
else if (y % 2 == 0)
return ((power(x, y / 2) % MOD) * ( power(x, y / 2) % MOD)) % MOD;
else
return ((x % MOD) * (power(x, y / 2) % MOD) * (power(x, y / 2) % MOD)) % MOD;
}
int lcm(int a, int b)
{
return (a * b) / gcd(a, b);
}
void solve()
{
string s;
cin >> s;
bool ok = true;
for (int i = 0; i < sz(s); i++)
{
if (i % 2 == 0)
{
ok &= (s[i] >= 'a' && s[i] <= 'z');
}
else
{
ok &= (s[i] >= 'A' && s[i] <= 'Z');
}
}
if (ok) cout << "Yes\n";
else cout << "No\n";
}
int32_t main()
{
KruNULL();
// int JUDGE_ONLINE = 1;
int tc = 1;
// cin >> tc;
for (int i = 1; i <= tc; i++)
{
// cout << "Case #" << i << ": ";
solve();
// if (JUDGE_ONLINE) {
// cout << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
// }
}
}
| #include <bits/stdc++.h>
using namespace std;
// clang-format off
/* accelration */
// 高速バイナリ生成
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
// cin cout の結びつけ解除, stdioと同期しない(入出力非同期化)
// cとstdの入出力を混在させるとバグるので注意
struct Fast {Fast() {std::cin.tie(0); ios::sync_with_stdio(false);}} fast;
/* alias */
using ull = unsigned long long;
using ll = long long;
using vi = vector<int>;
using vl = vector<long>;
using vll = vector<long long>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using vvll = vector<vll>;
using vs = vector<string>;
using pii = pair<int, int>;
/* define short */
#define pb push_back
#define mp make_pair
#define all(obj) (obj).begin(), (obj).end()
#define YESNO(bool) if(bool){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(bool) if(bool){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(bool) if(bool){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
/* REP macro */
#define reps(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define rep(i, n) reps(i, 0, n)
#define rrep(i, n) reps(i, 1, n + 1)
#define repd(i,n) for(ll i=n-1;i>=0;i--)
#define rrepd(i,n) for(ll i=n;i>=1;i--)
/* debug */
// 標準エラー出力を含む提出はrejectされる場合もあるので注意
#define debug(x) cerr << "\033[33m(line:" << __LINE__ << ") " << #x << ": " << x << "\033[m" << endl;
/* func */
inline int in_int() {int x; cin >> x; return x;}
inline ll in_ll() {ll x; cin >> x; return x;}
inline string in_str() {string x; cin >> x; return x;}
// search_length: 走査するベクトル長の上限(先頭から何要素目までを検索対象とするか、1始まりで)
template <typename T> inline bool vector_finder(std::vector<T> vec, T element, unsigned int search_length) {
auto itr = std::find(vec.begin(), vec.end(), element);
size_t index = std::distance( vec.begin(), itr );
if (index == vec.size() || index >= search_length) {return false;} else {return true;}
}
template <typename T> inline void print(const vector<T>& v, string s = " ")
{rep(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");}
template <typename T, typename S> inline void print(const pair<T, S>& p)
{cout << p.first << " " << p.second << endl;}
template <typename T> inline void print(const T& x) {cout << x << "\n";}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v)
{for (auto&& p : v) print(p);}
// 第一引数と第二引数を比較し、第一引数(a)をより大きい/小さい値に上書き
template <typename T> inline bool chmin(T& a, const T& b) {bool compare = a > b; if (a > b) a = b; return compare;}
template <typename T> inline bool chmax(T& a, const T& b) {bool compare = a < b; if (a < b) a = b; return compare;}
int main(){
int n;
cin >> n;
vector<int> a(n);
vector<int> b(n);
vector<int> num(1000, 0);
for(int i = 0; i < n; i++){
cin >> a[i];
}
for(int i = 0; i < n; i++){
cin >> b[i];
}
for(int i = 0; i < n; i++){
int anum = a[i];
int bnum = b[i];
for(int j = anum; j <= bnum; j++){
num[j]++;
}
}
int count = 0;
for(int i = 1; i <= 1000; i++){
if(num[i] == n){
count++;
}
}
cout << count << endl;
} |
#include<bits/stdc++.h>
#define fasterthanlight ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"
#define int long long
#define vi vector<int>
#define pb push_back
#define mod 1000000007
#define MAX 1e9
#define MIN -1e9
#define hi "visited\n" //sasta debugging
using namespace std;
//author::@whohet-->Het Patel
void solve()
{
char s, t;
cin >> s >> t;
if (s == 'Y')
{
if (t <= 'Z')
cout << t;
else
{
t -= 32;
cout << t;
}
}
else
{
if (t <= 'Z')
{
t += 32; cout << t;
}
else
{
cout << t;
}
}
}
signed main()
{
fasterthanlight;
int T; T = 1;
//cin>>T;
while (T--)
{
solve();
}
//cout << "\n\n"<<"Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " seconds.\n";
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1e9
typedef long long ll;
typedef long double ld;
int main(){
char c, a;
cin>>c>>a;
if(c=='Y'){
a-=32;
}
cout<<a<<endl;
return 0;
}
|
#include<bits/stdc++.h>
#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i)
#define foreach(i, n) for(auto &i:(n))
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
#define lambda(RES_TYPE, ...) (function<RES_TYPE(__VA_ARGS__)>)[&](__VA_ARGS__) -> RES_TYPE
#define method(FUNC_NAME, RES_TYPE, ...) function<RES_TYPE(__VA_ARGS__)> FUNC_NAME = lambda(RES_TYPE, __VA_ARGS__)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(x) (void)0
#endif
namespace templates{
ll modpow(ll x, ll b,ll mod=MOD){
ll res = 1;
while(b){
if(b&1)res = res * x % mod;
x = x * x % mod;
b>>=1;
}
return res;
}
ll modinv(ll x){
return modpow(x, MOD-2);
}
bool was_output = false;
template<class t>
void output(t a){
if(was_output)cout << " ";
cout << a;
was_output = true;
}
void outendl(){
was_output = false;
cout << endl;
}
ll in(){
ll res;
cin >> res;
return res;
}
template<class t>
istream& operator>>(istream&is, vector<t>&x){
for(auto &i:x)is >> i;
return is;
}
template<class t, class u>
istream& operator>>(istream&is, pair<t, u>&x){
is >> x.first >> x.second;
return is;
}
template<class t>
t in(){
t res; cin >> res; return res;
}
template<class t>
void out(t x){
cout << x;
}
template<class t>
vector<t> sorted(vector<t> line,function<bool(t,t)> comp=[](t a,t b){return a<b;}){
sort(line.begin(),line.end(),comp);
return line;
}
template<class t>
vector<t> reversed(vector<t> line){
reverse(line.begin(),line.end());
return line;
}
}
using namespace templates;
vector<ll> func(){
int n = in();
vector<ll> A(n);
vector<ll> B(n);
foreach(i,A)i=in();
foreach(i,B)i=in();
vector<ll> AM(n,0);
rep(i,n){
chmax(AM[i],A[i]);
if(i+1<n)chmax(AM[i+1],AM[i]);
}
ll CM = 0;
vector<ll> res(n);
rep(i,n){
chmax(CM,AM[i] * B[i]);
res[i] = CM;
}
return res;
}
int main(){
vector<ll> ans = func();
foreach(i,ans){
cout << i << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int x[n], y[n], r[n];
for (int i = 0;i < n;i++)
cin >> x[i] >> y[i] >> r[i];
for (int i = 0;i < n;i++){
bool dup = false;
for (int k = 0;k < n;k++){
if (i == k) continue;
if (y[i] == y[k]) {
dup = true;
break;
}
}
if (dup == false)
cout << 0 << ' ' << y[i] << ' ' << 9999 << ' ' << y[i] + 1 << endl;
else
cout << x[i] << ' ' << y[i] << ' ' << x[i] + 1 << ' ' << y[i] + 1 << endl;
}
return 0;
} |
#include <iostream>
using namespace std;
inline int ksm(int x,int y,int mod)
{
int rtn=1;
while(y)
{
if(y&1) rtn=(long long)rtn*x%mod;
x=(long long)x*x%mod,y>>=1;
}
return rtn%mod;
}
int main(int argc, char** argv) {
int a,b,c;
cin >> a >> b >> c;
if(b<=5&&c<=5||b==1)
cout << ksm(a,ksm(b,c,1000000000),10);
else
{
cout << ksm(a,ksm(b,c,4)+4,10);
}
return 0;
} | #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 + 9;
const ll LINF = 1e18;
const long double eps = 1e-10;
const char nl = '\n';
ll power(ll a, ll b, int mod) { return b ? power(a * a % mod, b / 2, mod) * (b % 2 ? a : 1) % mod : 1; }
ll nCk(int n, int k, int mod)
{
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) % 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);
ll a, b, c; cin >> a >> b >> c;
cout << power(a % 10, power(b, c, 4) + 4, 10) << nl;
} |
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using ld = long double;
using vld = vector<ld>;
using vb = vector<bool>;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define dbg(x) true
#endif
template <class T> bool chmin(T& a, T b) {
if(a > b) { a = b; return true; }
else return false;
}
template <class T> bool chmax(T& a, T b) {
if(a < b) { a = b; return true; }
else return false;
}
template <class T> ostream& operator<<(ostream& s, const vector<T>& a) {
for(auto i : a) s << i << ' ';
return s;
}
constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 62;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);
void solve() {
ll n, m;
cin >> n >> m;
vll cnt(1001);
rep(_, n) {
ll a;
cin >> a;
++cnt[a];
}
rep(_, m) {
ll b;
cin >> b;
++cnt[b];
}
for(ll i = 1; i <= 1000; ++i) {
if(cnt[i] == 1) cout << i << ' ';
}
cout << endl;
return;
}
int main() {
std::cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
cout << fixed << setprecision(15);
solve();
} | /*ver 7*/
#include <bits/stdc++.h>
using namespace std;
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vd = vector<ld>;
using vs = vector<string>;
using vb = vector<bool>;
using vvl = vector<vector<ll>>;
using vvd = vector<vector<ld>>;
using vvs = vector<vector<string>>;
using vvb = vector<vector<bool>>;
using pll = pair<ll,ll>;
using mll = map<ll,ll>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
#define each(x,v) for(auto& x : v)
#define reps(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define mp make_pair
const ll INF = 1LL << 60;
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<=b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ) //被り削除
#define debug cout << "line : " << __LINE__ << " debug" << endl;
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ind(...) long double __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define inc(...) char __VA_ARGS__; in(__VA_ARGS__)
void in(){}
template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
template <typename T> void in1(T &s) {rep(i,s.size()){in(s[i]);}}
template <typename T> void in2(T &s,T &t) {rep(i,s.size()){in(s[i],t[i]);}}
template <typename T> void in3(T &s,T &t,T &u) {rep(i,s.size()){in(s[i],t[i],u[i]);}}
template <typename T> void in4(T &s,T &t,T &u,T &v) {rep(i,s.size()){in(s[i],t[i],u[i],v[i]);}}
template <typename T> void in5(T &s,T &t,T &u,T &v,T &w) {rep(i,s.size()){in(s[i],t[i],u[i],v[i],w[i]);}}
void out(){cout << endl;}
template <typename T,class... U> void out(const T &t,const U &...u){cout << t; if(sizeof...(u)) cout << " "; out(u...);}
void die(){cout << endl;exit(0);}
template <typename T,class... U> void die(const T &t,const U &...u){cout << t; if(sizeof...(u)) cout << " "; die(u...);}
template <typename T> void outv(T s) {rep(i,s.size()){if(i!=0)cout<<" ";cout<<s[i];}cout<<endl;}
template <typename T> void out1(T s) {rep(i,s.size()){out(s[i]);}}
template <typename T> void out2(T s,T t) {rep(i,s.size()){out(s[i],t[i]);}}
template <typename T> void out3(T s,T t,T u) {rep(i,s.size()){out(s[i],t[i],u[i]);}}
template <typename T> void out4(T s,T t,T u,T v) {rep(i,s.size()){out(s[i],t[i],u[i],v[i]);}}
template <typename T> void out5(T s,T t,T u,T v,T w) {rep(i,s.size()){out(s[i],t[i],u[i],v[i],w[i]);}}
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
template <typename T> T allSum(vector<T> a){T ans=T();each(it,a)ans+=it;return ans;}
ll ceilDiv(ll a,ll b) {return (a+b-1)/b;}
ld dist(pair<ld,ld> a, pair<ld,ld> b){return sqrt(abs(a.fi-b.fi)*abs(a.fi-b.fi)+abs(a.se-b.se)*abs(a.se-b.se));} // 2点間の距離
ll gcd(ll a, ll b) { return b != 0 ? gcd(b, a % b) : a; }
ll lcm(ll a,ll b){ return a / gcd(a,b) * b;}
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
#define YES(n) ((n) ? "YES" : "NO" )
#define Yes(n) ((n) ? "Yes" : "No" )
#define yes(n) ((n) ? "yes" : "no" )
int main(){
init();
inl(n,m);
V<ll> a(n),b(m);
in1(a);
in1(b);
set<ll> A,B;
rep(i,n)A.insert(a[i]);
rep(i,m)B.insert(b[i]);
reps(i,1,1001){
ll af=A.count(i);
ll bf=B.count(i);
if(af+bf==1)out(i);
}
return 0;
} |
#include<iostream>
#include<bits/stdc++.h>
#define m_p make_pair
#define fi first
#define se second
#define pb push_back
typedef long long ll;
#define f(i,n) for(ll i=0;i<n;i++)
#define f1(i,n) for(ll i=1;i<=n;i++)
#define crap ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0)
using namespace std;
#define INF 1000000
#define vll vector<ll>
const int M = 1e9+7;
ll fastpower(ll x,ll n,ll M)
{
if(n==0)
return 1;
else if(n%2 == 0) //n is even
return fastpower((x*x)%M,n/2,M);
else //n is odd
return (x*fastpower((x*x)%M,(n-1)/2,M))%M;
}
ll GCD(ll A, ll B) {
if(B==0)
return A;
else
return GCD(B, A % B);
}
bool vowl(char c)
{
return c=='a'||c=='e'||c=='i'||c=='o'||c=='u';
}
ll modInverse(ll A,ll M)// when M is prime
{
return fastpower(A,M-2,M);
}
void sieve(ll N) {
bool isPrime[N+1];
for(ll i = 0; i <= N;++i) {
isPrime[i] = true;
}
isPrime[0] = false;
isPrime[1] = false;
for(ll i = 2; i * i <= N; ++i) {
if(isPrime[i] == true) { //Mark all the multiples of i as composite numbers
for(ll j = i * i; j <= N ;j += i)
isPrime[j] = false;
}
}
}
vector<ll> factorize(ll n) {
vector<ll> res;
for (ll i = 2; i * i <= n; ++i) {
while (n % i == 0) {
res.push_back(i);
n /= i;
}
}
if (n != 1) {
res.push_back(n);
}
return res;
}
int main()
{
crap;
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
double a,b,p,q;
cin>>a>>b>>p>>q;
cout<<setprecision(12)<<(b*p+q*a)/(q+b)<<endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define int ll
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vpii = vector<pii>;
using vvpii = vector<vpii>;
template<typename T, typename U>
ostream& operator<<(ostream& o, const pair<T,U>& p) {
return o << "(" << p.first << "," << p.second << ")";
}
template<typename T, typename U>
ostream& operator<<(ostream& o, const map<T,U>& m) {
o << "{";
for (const pair<T,U>& p : m)
o << p.first << ": " << p.second << ",";
return o << "}";
}
template<typename T>
ostream& operator<<(ostream& o, const vector<T>& v) {
o << "[";
for (const T& x : v)
o << x << ",";
return o << "]";
}
template<typename T>
ostream& operator<<(ostream& o, const vector<vector<T>>& v) {
o << "[";
for (const vector<T>& x : v)
o << x << ",\n";
return o << "]";
}
constexpr int MOD = 998244353;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int a, b, c;
cin >> a >> b >> c;
int sumc = (c+1)*c/2 % MOD;
int sumb = (b+1)*b/2 % MOD;
int suma = (a+1)*a/2 % MOD;
int res = suma * sumb % MOD * sumc % MOD;
cout << res << "\n";
}
|
#include <bits/stdc++.h>
#define int long long
#define float double
#define vi vector<int>
#define pb push_back
#define mod 1000000007
using namespace std;
// int N;
// char mat[1000][1000];
// int vis[1000][1000];
// int dist[1000][1000];
// int dx[]={-1,0,0,1};
// int dy[]={0,1,-1,0};
// bool isValid(int x, int y)
// {
// if(x>=N || x<0 || y>=N || y<0 || vis[x][y]==1 || mat[x][y]=='T')
// return false;
// return true;
// }
// void bfs(int sx, int sy)
// {
// queue<pair<int, int>>q;
// q.push({sx,sy});
// dist[sx][sy]=0;
// vis[sx][sy]=1;
// while(!q.empty())
// {
// int x=q.front().first;
// int y=q.front().second;
// q.pop();
// for(int i=0;i<4;i++)
// {
// if(isValid(x+dx[i], y+dy[i]))
// {
// vis[x+dx[i]][y+dy[i]]=1;
// q.push({x+dx[i],y+dy[i]});
// dist[x+dx[i]][y+dy[i]]=dist[x][y]+1;
// }
// }
// }
// }
// class Foo{
// static int i;
// public:
// Foo()
// {
// cout<< ++i <<" ";
// }
// };
// int Foo::i=0;
int lcm(int a, int b)
{
return (a*b)/__gcd(a,b);
}
int fact[1000000];
int factorial(int n)
{
fact[0] = 1;
for (int i = 1; i <= n; i++) {
fact[i] = (fact[i - 1] * i);
}
return fact[n];
}
bool isvowel(char ch)
{
if(ch=='a' || ch=='e' || ch=='i' || ch=='u' || ch=='o')
{
return true;
}
return false;
}
int power(int x, int y)
{
int temp;
if( y == 0)
return 1;
temp = power(x, y/2);
if (y%2 == 0)
return temp*temp;
else
return x*temp*temp;
}
int nCk(int n, int k)
{
if(k>n-k)
k=n-k;
int ans=1;
for(int i=0;i<k;i++)
{
ans*=(n-i);
ans/=(i+1);
}
return ans;
}
vi factorization(int n)
{
vi factors;
//factors.pb(1);
for(int d=2; d*d <= n; d++)
{
while(n%d==0)
{
factors.pb(d);
n/=d;
}
}
if(n>1)
factors.pb(n);
return factors;
}
vi divisors(int n)
{
vi divisors;
for(int i=2; i*i <= n; i++)
{
if( n%i == 0)
{
if(n/i == i)
divisors.pb(i);
else
divisors.pb(i), divisors.pb(n/i);
}
}
return divisors;
}
int sieve[1000001];
void SOE()
{
sieve[0]=0;
sieve[1]=0;
for(int i=2;i<=1000000;i++)
{
if(sieve[i])
{
for(int j=2; j*i <1000000; j++)
sieve[j*i]=0;
}
}
}
bool isPrime(int x)
{
if(x==1) return 0;
for(int i=2; i*i<=x; ++i)
{
if(x%i==0)
return false;
}
return true;
}
int nthXor(int n, int a, int b)
{
if (n == 0)
return a;
if (n == 1)
return b;
if (n == 2)
return (a ^ b);
return nthXor(n % 3, a, b);
}
void dfs(vi adj[], int src, bool visited[])
{
visited[src]=true;
for(auto it: adj[src])
{
if(visited[it]==false)
dfs(adj, it, visited);
}
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t=1;
// cin >> t;
while (t--)
{
int n; cin>>n;
int temp = n;
int digits=0, sum=0;
map<int, int>mp;
while(temp){
mp[temp%10%3]++;
sum += temp%10;
temp/=10;
digits++;
}
int ans;
if(sum % 3 == 0)
ans = 0;
else if(sum % 3 == 1){
if(mp[1]>0 and digits > 1){
ans = 1;
}
else if(mp[2]>=2 and digits > 2){
ans = 2;
}
else ans = -1;
}
else if(sum % 3 == 2){
if(mp[2]>0 and digits > 1){
ans = 1;
}
else if(mp[1] >=2 and digits > 2){
ans = 2;
}
else ans = -1;
}
cout<<ans;
}
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ll n;
cin >> n;
ll m = n;
int s = 0;
vector<int> c(3, 0);
while (m != 0) {
int d = m % 10;
s += d;
++c[d % 3];
m /= 10;
}
int r = s % 3;
if (r == 0) {
cout << 0;
return 0;
}
if (c[r] >= 1 && n > 9) {
cout << 1;
return 0;
}
if (c[3 - r] >= 2 && n > 99) {
cout << 2;
return 0;
}
cout << -1;
return 0;
}
|
#include <iostream>
#include <math.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define memset(v, h) memset((v), h, sizeof(v))
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int main(){
ll n, k, m;
cin >> n >> k >> m;
ll a[n];
ll p = 0;
rep(i,n-1){
cin >> a[i];
p+=a[i];
}
ll x = m * n;
ll g = x - p;
if(g < 0)
{
cout << 0 << endl;
}
else if(g > k)
{
cout << -1 << endl;
}
else
{
cout << g << endl;
}
return 0;
} | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
typedef long double ld;
int n,m;
ll k;
string s,t;
int c[10];
int p[6]={1,10,100,1000,10000,100000};
inline bool calc(int x,int y){
int i,j;
for(i=0;i<4;i++) c[s[i]-'0']++;
c[x]++;
int a1=0,a2=0;
for(i=1;i<=9;i++) a1+=i*p[c[i]];
for(i=1;i<=9;i++) c[i]=0;
for(i=0;i<4;i++) c[t[i]-'0']++;
c[y]++;
for(i=1;i<=9;i++) a2+=i*p[c[i]];
/// cout<<x<<" "<<y<<" "<<a1<<" "<<a2<<endl;
for(i=1;i<=9;i++) c[i]=0;
return (a1>a2);
}
int f[10];
int main(){
int i,j;
cin>>k>>s>>t;
for(i=1;i<=9;i++) f[i]=k;
for(i=0;i<4;i++){
f[s[i]-'0']--;
f[t[i]-'0']--;
}
ll sum=(9*k-8)*(9*k-9);
ld ans=0;
for(i=1;i<=9;i++){
for(j=1;j<=9;j++){
if(!f[i]||!f[j]) continue;
if(i==j){
if(f[i]<2) continue;
if(calc(i,j))
ans+=ld(f[i])*(f[i]-1)/sum;
}
else{
if(calc(i,j))
ans+=ld(f[i])*f[j]/sum;
}
}
}
printf("%.12Lf",ans);
return 0;
} |
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <cmath>
#include <set>
#define ll long long
using P = std::pair<int, int>;
int main()
{
int N;
std::string S;
std::cin >> N >> S;
int ans = 0;
for(int i=0; i < N; i++) {
int na=0, nt=0, nc=0, ng=0;
for(int j=i; j < N; j++) {
if(S[j] == 'A') na++;
else if(S[j] == 'T') nt++;
else if(S[j] == 'C') nc++;
else ng++;
if(na == nt and nc == ng) ans++;
}
}
std::cout << ans << std::endl;
return 0;
} | #include <bits/stdc++.h>
// #include <atcoder/all>
// #include "icld.cpp"
using namespace std;
using ll = long long int;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using ss = string;
using db = double;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
#define V vector
#define P pair<int,int>
#define rep(i,s,n) for(int i=(s);i<(int)(n);i++)
#define rev(i,s,n) for(int i=(s);i>=(int)(n);i--)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define ci(x) cin >> x
#define cii(x) int x;cin >> x
#define cci(x,y) int x,y;cin >> x >> y
#define co(x) cout << x << endl
template<class T>void chmax(T &x,T y){x=max(x,y);}
template<class T>void chmin(T &x,T y){x=min(x,y);}
int main(){
cii(n);
ss s;ci(s);
int ans=0;
rep(l,0,n){
map<char,int> mp;
// int a,t,g,c; a=t=g=c=0;
mp[s[l]]++;
rep(r,l+1,n){
mp[s[r]]++;
if(mp['A']==mp['T'] && mp['G']==mp['C'])ans++;
}
}
co(ans);
} |
#include<bits/stdc++.h>
using namespace std;
long long INF = 1000000000000;
std::vector<long long> AA;
std::vector<long long> visited;
bool comp(int a, int b) {
return AA[a] < AA[b];
}
long long bfs(long long now, std::vector<long long> &A, vector<vector<long long>> &edges){
long long m = -INF;
queue<long long> q;
q.push(now);
while(!q.empty()){
long long p = q.front();
q.pop();
int l = edges[p].size();
for(int i = 0 ; i < l ; i++){
if(visited[edges[p][i]] == false){
visited[edges[p][i]] = true;
q.push(edges[p][i]);
m = max(m, A[edges[p][i]]);
}
}
}
return m;
}
void solve(long long N, long long M, std::vector<long long> A, std::vector<long long> X, std::vector<long long> Y){
AA = A;
vector<long long> index(N);
for(int i = 0 ; i < N ; i++){
index[i] = i;
}
sort(index.begin(), index.end(), comp);
vector<vector<long long>> edges(N);
for(int i = 0 ; i < M ; i++){
edges[X[i] - 1].push_back(Y[i] - 1);
}
visited.resize(N);
for(int i = 0 ; i < N ; i++){
visited[i] = false;
// cout<<index[i]<<" ";
}
// cout<<endl;
long long max_profit = -INF;
for(int i = 0 ; i < N ; i++){
if(visited[index[i]] == false){
// visited[index[i]] = true;
long long m = bfs(index[i], A, edges);
max_profit = max(max_profit, m - A[index[i]]);
}
}
printf("%lld\n", max_profit);
}
int main(){
long long N;
scanf("%lld",&N);
long long M;
scanf("%lld",&M);
std::vector<long long> A(N);
for(int i = 0 ; i < N ; i++){
scanf("%lld",&A[i]);
}
std::vector<long long> X(M);
std::vector<long long> Y(M);
for(int i = 0 ; i < M ; i++){
scanf("%lld %lld",&X[i], &Y[i]);
}
solve(N, M, std::move(A), std::move(X), std::move(Y));
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define all(vr) vr.begin(),vr.end()
#define vi vector<int>
#define vll vector<ll>
const int N = 1e5 + 10;
vi G[N];
int vis[N];
void dfs(int u)
{
vis[u] = 1;
for (int v : G[u])
if (!vis[v]) dfs(v);
}
int main()
{
//freopen("ss.inp", "r", stdin);
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
for (int i = 1, u, v; i <= m; ++i)
{
cin >> u >> v;
G[u].eb(v);
}
int res = 0;
for (int i = 1; i <= n; ++i)
{
for (int j = 1; j <= n; ++j) vis[j] = 0;
dfs(i);
for (int j = 1; j <= n; ++j) res += vis[j];
}
cout << res;
return 0;
}
|
#include <bits/stdc++.h>
#define st first
#define nd second
#define PQ priority_queue
#define MP make_pair
using ll = long long ;
using namespace std;
using pii = pair<int,int>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using pll = pair<ll, ll>;
const int N = 105;
const int MAXN = 1e5 + 10;
const int MOD = 0;
bool dp[MAXN];
int a[N];
int main(){
int n, ma = 0, sum = 0;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
sum += a[i];
ma = max(ma, a[i]);
}
int half = sum / 2;
if (ma >= half) {
return !printf("%d", max(ma, sum - ma));
}
dp[0] = true, ma = 0;
for (int i = 1; i <= n; i++) {
for (int j = half; j - a[i] >= 0; j--) {
dp[j] = dp[j] || dp[j - a[i]];
if (dp[j]) ma = max(ma, j);
}
}
printf("%d", sum - ma);
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}
int main(){
int n;
cin >> n;
vi t(n);
rep(i, n) {
cin >> t[i];
}
vector<ll> cur(2e5, INF);
cur[0] = 0;
rep(i, n) {
vl nxt(cur.size(), INF);
rep(j, cur.size()) {
chmin(nxt[j], cur[j] + t[i]);
if(j + t[i] < cur.size()) chmin(nxt[j+t[i]], cur[j]);
}
swap(cur, nxt);
}
ll ans = INF;
rep(i, cur.size()) {
chmin(ans, max((ll)i, cur[i]));
}
cout << ans << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define Sort(a) sort(a.begin(), a.end())
using ll = long long;
#define DEBUG_ON
int main()
{
ll n;
cin>>n;
vector<ll>a(n);
vector<ll> _a(n);
vector<ll> _b(n);
vector<ll> b(n);
rep(i,n){
cin>>a.at(i)>>b.at(i);
_a.at(i) = a.at(i);
_b.at(i) = b.at(i);
}
ll min_ind_a;
ll min_ind_b;
ll min_a=10010101;
ll min_b = 10010101;
rep(i,n){
if(min_a>a.at(i)){
min_a=a.at(i);
min_ind_a=i;
}
if (min_b> b.at(i))
{
min_b = b.at(i);
min_ind_b = i;
}
}
if(min_ind_a==min_ind_b){
Sort(a);
Sort(b);
if (min_a + min_b < a.at(1) && min_a + min_b < b.at(1)){
cout << min_a + min_b ;
return 0;
}
if(a.at(0)>b.at(1)){
cout<<a.at(0);
return 0;
}
else if(b.at(0)>a.at(1)){
cout<<b.at(0);
return 0;
}
cout << min(a.at(1), b.at(1));
return 0;
}
else{
cout<<max(min_a,min_b);
return 0;
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
long long N;
cin >> N;
vector<long long> A(N),B(N);
vector<vector<long long>> C(N,vector<long long> (N));
for (long long i=0;i<N;i++) {
cin >> A.at(i) >> B.at(i);
}
long long X=A.at(0)+B.at(0);
for (long long i=0;i<N;i++) {
for (long long j=0;j<N;j++) {
if (i==j) {
C.at(i).at(j)=A.at(i)+B.at(j);
}
if (i!=j) {
C.at(i).at(j)=max(A.at(i),B.at(j));
}
if (X>C.at(i).at(j)) {
X=C.at(i).at(j);
}
}
}
cout << X << endl;
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using iPair = pair<int,int>;
using lPair = pair<ll, ll>;
using ivector = vector<int>;
using lvector = vector<long>;
using ivv = vector<vector<int>>;
using lvv = vector<vector<ll>>;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
#define dump(x) cout << #x << " = " << (x) << endl
#define ALL(x) begin(x),end(x)
#define rep(i,s,e) for(ll i=(s); i<(ll)(e); ++i)
#define repRev(i,s,e) for(ll i=(e-1); i>=(ll)(s); --i)
#define range(i,s,n) for(ll i=(s), i_stop=(s)+(n); i<i_stop; ++i)
#define rangeRev(i,s,n) for(ll i=(s), i_stop=(s)-(n); i>i_stop; --i)
#define foreach(x,container) for(auto &&x:container)
template<typename T> bool chmax(T& a, const T b) {if(a<b) {a=b;return true;} return false;}
template<typename T> bool chmin(T& a, const T b) {if(a>b) {a=b;return true;} return false;}
template<typename T> void printArr(vector<T> &arr){
for(auto &x:arr) {cout << x << " ";} cout << endl;
}
/*
https://atcoder.jp/contests/abc202/tasks/abc202_e
## 關鍵詞:
## 題意:
一個由N <= 2e5個節點組成的樹。樹根爲頂點1。
給出以下Q <= 2e5個問題:
給定U_i, D_i,求所有深度爲D_i且到達根節點的最短路徑包含U_i的節點數量。
## 思路:
本來的思路:用一個集合記錄每個節點的最短路徑上的頂點,但這樣一定會超時……
https://atcoder.jp/contests/abc202/editorial/1864
用DFS從根節點遍歷整棵樹,同時記錄每個頂點進入和退出的順序,in_i和out_i。
「x到root最短路徑包含y」 a.k.a 「x是y的子孫」的充分必要條件是:
「in_y <= in_x <= out_x <= out_y」,實際上只需要關注in_x即可。
用一個數組按照深度保存節點,並且按照in的順序從小到大排序。
實際求數量只需做兩次二分。
## 感想:
*/
void solve(){
int n;
#define maxn 200005
int in[maxn], out[maxn], depth[maxn]={0};
ivector son[maxn];
map<int,ivector> dvector; dvector[0] = {1};
// 讀取
cin>>n;
range(i,2,n-1) {
int p; cin>>p; son[p].push_back(i);
}
// dfs遍歷
auto dfs = [&](auto self, int ith, int &cnt) -> void {
in[ith] = cnt++;
foreach(v,son[ith]) {
depth[v] = depth[ith] + 1;
dvector[depth[v]].push_back(v);
self(self, v, cnt);
}
out[ith] = cnt++;
};
int cnt = 0;
dfs(dfs, 1, cnt);
// 對所有dvector[i]按照in的順序排序
foreach(x,dvector) {
auto [d,v] = x;
sort(ALL(dvector[d]), [&](const int &a, const int &b) {
return in[a] < in[b];
});
}
// 在[l,r)範圍內,尋找是check成立的最小下標
auto lower = [&](int l, int r, auto check) -> int {
while(l<r) {
int m = l + (r-l) / 2;
if(!check(m)) l = m+1;
else r = m;
}
return l;
};
// 在[l,r)範圍內,尋找是check不成立的最小下標
auto upper = [&](int l, int r, auto check) -> int {
while(l<r) {
int m = l + (r-l) / 2;
if(check(m)) l = m+1;
else r = m;
}
return l;
};
int q; cin>>q;
while(q--) {
int u,d; cin>>u>>d;
if(depth[u]>d) {cout<<0<<endl; continue;}
// 在x \in dvector[d]當中,尋找所有滿足 in[u] <= in[x] <= out[u]的節點
auto pl = lower(0, dvector[d].size(), [&](int ith) {
return in[dvector[d][ith]] >= in[u];
});
auto pr = upper(0, dvector[d].size(), [&](int ith) {
return in[dvector[d][ith]] <= out[u];
});
cout<<pr-pl<<endl;
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
solve();
return 0;
}
| #include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#define amax(a, b) a = max(a, b)
#define amin(a, b) a = min(a, b)
using ll = long long;
int main() {
int n, m;
std::cin >> n >> m;
if (n == 1 && m == 0) {
std::cout << 1 << ' ' << 2 << '\n';
return 0;
}
if (m < 0 || m >= n-1) {
std::cout << -1 << '\n';
return 0;
}
for (int i=1; i<n-m; i++) {
std::cout << i << ' ' << i + 100000000 << '\n';
}
int cur = n-m;
for (int i=n-m; i<=n; i++) {
std::cout << cur << ' ' << cur + 1 << '\n';
cur += 2;
}
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
const int maxN = 1e6 + 10;
#define pb push_back
int a[maxN];
string s;
int n;
vector<int> v[maxN];
int bit[maxN];
void update(int x, int poz)
{
for (int i = poz;i<maxN;i+=i&-i)
bit[i]+=x;
}
int get(int poz)
{
int ans = 0;
for (int i = poz;i>0;i-=i&-i)
ans+=bit[i];
return ans;
}
int main()
{
cin>>n;
for (int i = 1;i<=n;i++){
scanf("%d",&a[i]);
a[i]++;
}
long long ans = 0;
for (int i = 1;i<=n;i++)
{
ans+=i - 1 - get(a[i]);
update(1, a[i]);
}
int cur = 1;
for (int i = 1;i<=n;i++)
{
printf("%lld\n", ans);
ans-=a[cur] - 1;
ans+=n - a[cur];
cur++;
}
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ll long long
#define mset(A,val) memset(A,val,sizeof(A))
#define fi(a,b) for(int i=a;i<=b;++i)
#define fj(a,b) for(int j=a;j<=b;++j)
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define pii pair<int,int>
#define DEBUG(a...) cout<<#a<<": ";for(auto &it:a)cout<<it<<" ";cout<<"\n";
#define debug(a)cout<<#a<<": "<<a<<"\n";
#define int long long
// ---------------------------------------------------------------------------
const int mod = 1e9+7;
const int maxn = 3e5 + 9;
vi BIT(maxn);
// ---------------------------------------------------------------------------
int sum(int i){
int ans = 0;
while(i>0){
ans+=BIT[i];
i-=(i&(-i));
}
return ans;
}
void update(int i,int x,int n){
while(i<=n){
BIT[i]+=x;
i+=(i&(-i));
}
}
// ---------------------------------------------------------------------------
void test_case(int tc)
{
// cout<<"Case #"<<tc<<": ";
int n;cin>>n;
vector<int>arr(n+1);fi(1,n)cin>>arr[i],arr[i]++;
int inversion = 0;
for(int i=1;i<=n;++i){
inversion+=(sum(n)-sum(arr[i]));
update(arr[i],1,n);
}
cout<<inversion<<"\n";
for(int i=1;i<n;++i){
inversion+=(n-arr[i]);
inversion-=(arr[i]-1);
cout<<inversion<<"\n";
}
}
int32_t main()
{
FASTIO;
// #ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
// #endif
int t=1;
//cin>>t;
for(int tc=1;tc<=t;++tc)test_case(tc);
} |
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define deb(...)
#endif
#define endl "\n"
#define pb push_back
#define int long long
#define ll long long
#define pii pair<int,int>
#define F first
#define S second
#define all(c) c.begin(),c.end()
#define read(v) for(auto &it:v) cin>>it;
const int inf = 1e18;
const int N = 2e5 + 5;
const int mod = 1000000007;
void testCase() {
int n;
cin >> n;
int ans = inf;
for (int i = 0; i < 60; i++) {
int zx = (1LL << i);
ans = min(ans, n / zx + i + n % zx);
}
cout << ans << endl;
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t = 1;
// cin >> t;
while (t--)testCase();
return 0;
}
| #pragma GCC optimize("O3")
#pragma GCC target("avx2")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef pair<int, int> pi;
typedef pair<long long, long long> pll;
#define ff first
#define ss second
#define pb push_back
#define int long long // Make sure to use ll everywhere while commenting this, to avoid overflow
#define sz(v) (int)v.size()
#define inf 2147483647
#define llinf 9223372036854775807
#define all(v) v.begin(),v.end()
#define bp(n) __builtin_popcountll(n)
#define f(i,l,r) for(long long i=l;i<=r;i++)
#define rf(i,r,l) for(long long i=r;i>=l;i--)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
void dbg_out() { cout << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cout << ' ' << H; dbg_out(T...); }
const int N = 3e5 + 5, mod = 1e9 + 7, bit = 62;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int getRand(int l, int r)
{
uniform_int_distribution<int> uid(l, r);
return uid(rng);
}
signed main()
{
fast;
int t = 1;
// cin >> t;
f(tc, 1, t)
{
int n;
cin >> n;
int ans = llinf;
for (int i = 0; i < bit; i++)
{
int val = (1LL << i);
int c = n % val;
int d = (n - c);
if (d % val == 0)
{
ans = min(ans, i + c + (d / val));
}
}
cout << ans << endl;
}
return 0;
} |
//#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
constexpr lint mod = 1e9 + 7;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountll((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
#define rep(i, n) for(int i = 0; i < int(n); i++)
#define rep2(i, l, r) for(int i = int(l); i < int(r); i++)
#define repr(i, n) for(int i = int(n) - 1; i >= 0; i--)
#define repr2(i, l, r) for(int i = int(r) - 1; i >= int(l); i--)
constexpr int inf9 = 1e9; constexpr lint inf18 = 1e18;
inline void Yes(bool condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
inline void YES(bool condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int x, y; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) cout << (i == start ? "" : " ") << (*i); if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint P(int n, int r){ if(r < 0 || n < r) return 0; return (fact[n] * inv[n - r] % mod); } lint C(int p, int q){ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }
template<class itr, class itr2> bool next_sequence2(itr first, itr last, itr2 first2, itr2 last2){ itr now = last; itr2 now2 = last2; while(now != first){ now--, now2--; (*now)++; if((*now) == (*now2)){ (*now) = 0; }else{ return true; } } return false; }
template<class T> bool chmax(T &a, const T &b){ if(a < b){ a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b){ if(b < a){ a = b; return 1; } return 0; }
inline int at(lint i, int j){ return (i >> j) & 1; }
random_device rnd;
bool is_in_board(lint y, lint x, lint H, lint W){ return (0 <= y && y < H && 0 <= x && x < W); }
lint inv2 = power(2, mod - 2, mod);
struct io_init {
io_init() {
cin.tie(nullptr); cout.tie(nullptr);
std::ios::sync_with_stdio(false);
}
} io_init;
int main(){
string s;
cin >> s;
int ans = 0;
rep2(i, 3, s.size()){
if(s.substr(i - 3, 4) == "ZONe"){
ans++;
}
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
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 DEBUG
#ifdef DEBUG
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
os << '(' << p.first << ',' << p.second << ')';
return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
os << '{';
for(int i = 0; i < (int)v.size(); i++) {
if(i) { os << ','; }
os << v[i];
}
os << '}';
return os;
}
void debugg() { cerr << endl; }
template <class T, class... Args>
void debugg(const T &x, const Args &... args) {
cerr << " " << x;
debugg(args...);
}
#define debug(...) \
cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debugg(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif
struct Setup {
Setup() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
}
} __Setup;
using ll = long long;
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define repl(i, a, b) for(int i = a; i < int(b); i++)
#define rep(i, n) repl(i, 0, n)
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
//-------------------------------------
int main() {
string s;
cin >> s;
vector<int> cnt(10, 0);
rep(i, s.size()) cnt[s[i] - '0']++;
if(s.size() == 1) {
ll num = stoll(s);
if(num % 8 == 0) {
cout << "Yes\n";
} else {
cout << "No\n";
}
return 0;
} else if(s.size() == 2) {
bool f = false;
f = stoll(s) % 8 == 0;
if(f) {
cout << "Yes" << endl;
return 0;
}
string t = s;
reverse(ALL(t));
f = stoll(t) % 8 == 0;
cout << (f ? "Yes" : "No") << "\n";
return 0;
}
for(int i = 111; i < 1000; i++) {
{
string t = to_string(i);
bool f = true;
for(char c : t)
if(c == '0') f = 0;
if(!f) continue;
}
if(i % 8 != 0) continue;
string num = to_string(i);
vector<int> a(10, 0);
for(char c : num) a[c - '0']++;
bool ok = true;
rep(j, 10) if(a[j] > cnt[j]) ok = false;
if(ok) {
cout << "Yes\n";
return 0;
}
}
cout << "No\n";
} |
//全力以赴
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define PI 3.141592653L
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const ll INF = (ll)1e18;
const int N = 2e5 + 5;
const ll MOD = 1e9+7;
int parent[N];
const int dx[4] = {+1, 0, -1, 0};
const int dy[4] = {0, -1, 0, +1};
ll gcd(ll a, ll b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
ll extGcd(ll a, ll b, ll &x, ll &y) { // solves for x and y where ax+by=gcd(a,b)
if(b == 0) {
x = 1;
y = 0;
return a;
}
ll d = extGcd(b, a % b, y, x);
y -= a / b * x;
return d;
}
ll modInv(ll a, ll p) { // solve for x=a^-1 where ax + py = 1 % p
if(gcd(a, p) != 1) return -1; // modInv only exists if a and p are coprime (gcd(a, p) = 1)
ll x, y;
extGcd(a, p, x, y);
x = (x % p + p) % p;
return x;
}
ll lcm(ll a, ll b) {
return (a * b) / gcd(a,b);
}
/*
a^b:
if b is even -> a^b = a^(b/2) * a^(b/2)
if b is odd -> a^b = a * a^(b-1/2) * a^(b-1/2)
*/
ll modPow(ll a, ll n, ll mod) {
ll res = 1;
while (n > 0) {
if (n & 1) res = (res * a) % mod;
a = (a * a) % mod;
n >>= 1;
}
return res;
}
int find(int x) {
return x == parent[x] ? x : parent[x] = find(parent[x]);
}
void Union(int x, int y) {
int xPar = find(x), yPar = find(y);
if(xPar != yPar) parent[xPar] = yPar;
}
ll nCr(ll n, ll r) {
ll res = 1;
for(ll i=1;i<=r;i++) {
res = res * (n - r + i) / i;
}
return res;
}
int ask(int i, int j) {
cout << "? " << i + 1 << ' ' << j + 1 << endl;
int v;
cin >> v;
return v;
}
int msbPos(int n) {
if(n == 0) return 0;
int msbPos = 0;
n /= 2;
while(n != 0) {
n /= 2;
msbPos++;
}
return msbPos;
}
void solve() {
int n;
cin >> n;
vector<ll> a(n);
for(int i=0;i<n;i++) {
cin >> a[i];
}
int cnt = min(n, 8);
vector<vector<int>> v(200, vector<int>(0));
for(int i=1;i<(1<<cnt);i++) {
ll sum = 0;
vector<int> cur;
for(int j=0;j<cnt;j++) {
if(i & (1<<j)) {
cur.push_back(j + 1);
sum += a[j];
sum %= 200;
}
}
if(v[sum].size() != 0) {
cout << "Yes" << endl;
cout << cur.size() << ' ';
for(auto x : cur) cout << x << ' ';
cout << endl;
cout << v[sum].size() << ' ';
for(auto x : v[sum]) cout << x << ' ';
cout << endl;
return;
}
v[sum] = cur;
}
cout << "No" << endl;
}
int main()
{
IOS
//int t;
//cin >> t;
//while(t--) solve();
solve();
return 0;
} | #include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define rep(i, n) for(int i=0;i<n;i++)
#define all(i, v) for(auto& i : v)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
int main() {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
vector<ll> a(n);
rep(i, n) cin >> a[i];
n = min(n, 10);
rep(bit1, 1 << n) {
vector<int> v1;
rep(i, n) if(bit1 >> i & 1) v1.pb(i);
rep(bit2, 1 << n) {
vector<int> v2;
rep(i, n) if(bit2 >> i & 1) v2.pb(i);
if(v1.empty() || v2.empty() || v1 == v2) continue;
ll num = 0;
all(e, v1) num += a[e];
all(e, v2) num -= a[e];
if(num % 200 == 0) {
cout << "Yes" << endl;
cout << v1.size();
all(e, v1) cout << " " << e + 1;
cout << endl;
cout << v2.size();
all(e, v2) cout << " " << e + 1;
cout << endl;
return 0;
}
}
}
cout << "No" << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const ll Mod = 998244353;
const int MAX = 510000;
const double PI = 3.14159265358979;
const vector<int> dx = {1, 0};
const vector<int> dy = {0, 1};
int main() {
ll N;
cin >> N;
set<ll> PP; // 10^10以下の累乗数
for (ll i=2; i<=100000; i++) {
for (int j=2; (ll)pow(i, j)<=(ll)pow(10, 10); j++) {
PP.insert((ll)pow(i, j));
}
}
ll res = 0;
for (auto v: PP) {
if (v<=N) res++;
}
cout << N-res << endl;
return 0;
} | #include<iostream>
using namespace std;
int main()
{
int i,num=0;
char s[12];
for(i=0;i<12;i++)
{
cin>>s[i];
}
for(i=3;i<12;i++)
{
if(s[i-3]=='Z'&&s[i-2]=='O'&&s[i-1]=='N'&&s[i]=='e')
num++;
}
cout<<num;
return 0;
}
|
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
#define forn(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define fore(i,b,a)for(int i=(b),_a=(a);i>=_a;i--)
#define rep(i,n)for(int i=0,_n=n;i<n;i++)
#define pii pair<int,int>
#define m_p make_pair
#define pb push_back
#define ld long double
#define fi first
#define se second
#define ull unsigned long long
#define mod 1000000007
#define md 998244353
#define x1 XZVJDFADSPFOE
#define y1 GASDIJSLDAEJF
#define x2 DFDAJKVOHKWIW
#define y2 PSFSAODSXVNMQ
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define int long long
using namespace std;
inline void read(int &x){
short negative=1;
x=0;
char c=getchar();
while(c<'0'||c>'9'){
if(c=='-')negative=-1;
c=getchar();
}
while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+(c^48),c=getchar();
x*=negative;
}
const int M=200010;
int n,m;
map<int,int>dp,tmp;
pair<int,int>p[M];
int ans=0;
bool in(int x){
return x>=0&&x<=2*n;
}
signed main(){
cin>>n>>m;
rep(i,m){
cin>>p[i].fi>>p[i].se;
}
sort(p,p+m);
dp[n]=1;
int last=-1;
rep(i,m){
int cur=p[i].se;
if(p[i].fi!=last){
last=p[i].fi;
map<int,int>::iterator it;
for(it=tmp.begin();it!=tmp.end();it++){
dp[it->fi]=it->se;
}
tmp.clear();
}
if(in(cur)){
if(dp[cur]==1)tmp[cur]=-1;
}
if(in(cur-1)){
if(dp[cur-1]==1)tmp[cur]=1;
}
if(in(cur+1)){
if(dp[cur+1]==1)tmp[cur]=1;
}
}
map<int,int>::iterator it;
for(it=tmp.begin();it!=tmp.end();it++){
dp[it->fi]=it->se;
}
tmp.clear();
for(it=dp.begin();it!=dp.end();it++){
if(it->se==1)ans++;
}
cout<<ans<<"\n";
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
int main()
{
int n=4;
vector<int> arr(n);
int sum=0;
for(int i=0;i<=n-1;i++)
{
cin >> arr[i];
sum+=arr[i];
}
string ans="No";
for(int i=0;i<=n-1;i++)
{
if(arr[i]==sum-arr[i])
{
ans="Yes";
}
}
for(int i=0;i<=n-1;i++)
{
for(int j=i+1;j<=n-1;j++)
{
int g=arr[i]+arr[j];
if(g==sum-g)
{
ans="Yes";
}
}
}
cout << ans;
}
|
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=5005,mod=998244353;
int h,w,k;
int dp[N][N];
char a[N][N];
int qpow(int x,int k) {
int res=1;
while(k) {
if(k&1)res=1ll*res*x%mod;
x=1ll*x*x%mod;
k>>=1;
}
return res;
}
signed main() {
scanf("%lld %lld %lld",&h,&w,&k);
for(int i=1; i<=k; i++) {
int x,y;
char c;
scanf("%lld %lld\n%c",&x,&y,&c);
a[x][y]=c;
}
dp[1][1]=1;
int inv=qpow(3,mod-2);
for(int i=1; i<=h; i++)
for(int j=1; j<=w; j++) {
if(a[i][j]=='R'||a[i][j]=='X')
dp[i][j+1]=(dp[i][j]+dp[i][j+1])%mod;
if(a[i][j]=='D'||a[i][j]=='X')
dp[i+1][j]=(dp[i][j]+dp[i+1][j])%mod;
if(a[i][j]=='\0') {
dp[i][j+1]=(dp[i][j]*2*inv%mod+dp[i][j+1])%mod;
dp[i+1][j]=(dp[i][j]*2*inv%mod+dp[i+1][j])%mod;
}
}
printf("%lld\n",qpow(3,h*w-k)*dp[h][w]%mod);
return 0;
} | #pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include<stdio.h>
#include<algorithm>
constexpr unsigned long long MOD = 998244353;
constexpr unsigned long long IM = 18479187003;
constexpr unsigned long long MOD32 = 665496236;
char f[5000][5000];
unsigned long long dp[5000];
int main(){
int H=0, W=0, K=0;
char c=getchar_unlocked();
while(c<='9'&&c>='0') {H=(H<<1)+(H<<3)+c-'0'; c=getchar_unlocked();}
c=getchar_unlocked();
while(c<='9'&&c>='0') {W=(W<<1)+(W<<3)+c-'0'; c=getchar_unlocked();}
c=getchar_unlocked();
while(c<='9'&&c>='0') {K=(K<<1)+(K<<3)+c-'0'; c=getchar_unlocked();}
unsigned long long y = H * W - K;
while(--K>=0){
int h=0, w=0;
c=getchar_unlocked();
while(c<='9'&&c>='0') {h=(h<<1)+(h<<3)+c-'0'; c=getchar_unlocked();}
c=getchar_unlocked();
while(c<='9'&&c>='0') {w=(w<<1)+(w<<3)+c-'0'; c=getchar_unlocked();}
f[h-1][w-1] = getchar_unlocked();
getchar_unlocked();
}
--H; --W;
dp[0] = 1;
for(int i = 0; i < H; ++i){
for (int j = 0; j < W; ++j){
switch(f[i][j]) {
case 'R':
dp[j + 1] += dp[j];
dp[j] = 0;
break;
case '\0':{
dp[j] *= MOD32;
#ifdef _MSC_VER
unsigned long long x;
_umul128(dp[j], IM, &x);
#else
unsigned long long x =
(unsigned long long)(((unsigned __int128)(dp[j])*IM) >> 64);
#endif
dp[j] += - x * MOD+MOD;
}
case 'X':
dp[j + 1] += dp[j];
}
}
switch(f[i][W]) {
case 'R':
dp[W] = 0;
break;
case '\0':{
dp[W] *= MOD32;
#ifdef _MSC_VER
unsigned long long x;
_umul128(dp[W], IM, &x);
#else
unsigned long long x =
(unsigned long long)(((unsigned __int128)(dp[W])*IM) >> 64);
#endif
dp[W]+= - x * MOD+MOD;
}
}
}
for (int j = 0; j < W; ++j){
switch(f[H][j]) {
case '\0':{
dp[j] *= MOD32;
#ifdef _MSC_VER
unsigned long long x;
_umul128(dp[j], IM, &x);
#else
unsigned long long x =
(unsigned long long)(((unsigned __int128)(dp[j])*IM) >> 64);
#endif
dp[j] += - x * MOD+MOD;
}
case 'R':
case 'X':
dp[j + 1] += dp[j];
}
}
unsigned long long ans = dp[W];
unsigned long long x = 3;
while(y) {
if(y & 1) {
ans *= x;
#ifdef _MSC_VER
unsigned long long x2;
_umul128(ans, IM, &x2);
#else
unsigned long long x2 =
(unsigned long long)(((unsigned __int128)(ans)*IM) >> 64);
#endif
ans += - x2 * MOD+MOD;
}
{
x *= x;
#ifdef _MSC_VER
unsigned long long x2;
_umul128(x, IM, &x2);
#else
unsigned long long x2 =
(unsigned long long)(((unsigned __int128)(x)*IM) >> 64);
#endif
x += - x2 * MOD + MOD;}
y >>= 1;
}
printf("%d", ans % MOD);
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#endif
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef std::vector<vector<int> > vvi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
typedef vector<vll> vvll;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<ld> vld;
typedef vector<vld> vvld;
typedef vector<bool> vb;
typedef vector<vb> vvb;
#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define repi(i, a, b) for (int i = (int)(a); i >= (int)(b); i--)
#define pb push_back
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define sz(a) (int)(a.size())
template<typename T> void umin(T &a, T b) { a = min(a, b); }
template<typename T> void umax(T &a, T b) { a = max(a, b); }
ll nxt() {
ll x; cin >> x; return x;
}
void setIO(string s) {
#ifndef LOCAL
ios_base::sync_with_stdio(0); cin.tie(0);
freopen((s+".in").c_str(),"r",stdin);
freopen((s+".out").c_str(),"w",stdout);
#endif
}
void yes() {
cout << "Yes\n";
}
void no() {
cout << "No\n";
}
const ll mod = 1e9 + 7;
const ll INF = 2e9;
void solve() {
int n, s, d; cin >> n >> s >> d;
rep(i, 0, n) {
int x, y; cin >> x >> y;
if (x < s && y > d) {
yes();
return;
}
}
no();
}
int32_t main(){
// setIO("trapped");
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout << fixed << setprecision(10);
int T = 1;
// cin >> T;
for (int tc = 1; tc <= T; tc++) {
// cout << "Case #" << tc << ": ";
solve();
}
}
| #include <bits/stdc++.h>
using namespace std;
int main(){
int n,s,d,c=0;
cin>>n>>s>>d;
for(int i=0;i<n;i++){
int x,y;
cin>>x>>y;
if(x<s&&y>d){
c+=1;
}
}
if(c>0)cout<<"Yes";
else cout<<"No";
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
// Consecutive additon/subtraction is bad
// if x < y /4 , then its optimal to
long long int do_brute(long long int x, long long int y){
if(x == y)
return 0;
if(y%2 == 0){
if(y >= 2*x)
return 1 + do_brute(x,y/2);
else
return min(y-x,1+x-y/2);
}
else
return 1 + min(do_brute(x,y+1),do_brute(x,y-1));
}
int main(){
long long int x,y,oper = 0;
cin>>x>>y;
if(x >= y)
cout<<x-y;
else{
while(4*x < y){
if(y%2 == 0)
y/=2;
else if(y%4 == 1)
--y;
else
++y;
++oper;
}
oper += do_brute(x,y);
cout<<oper;
}
return 0;
}
| #include<bits/stdc++.h>
#define ll long long
#define rep(i, m, n) for (int i = m; i <= n; i++)
#define per(i, m, n) for (int i = m; i >= n; i--)
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define INF 0x3f3f3f3f
using namespace std;
ll x, y;
unordered_map<ll, ll> M;
ll solve(ll num) {
if (M.count(num)) return M[num];
if (num == 1) return abs(x - num);
if (num & 1) {
return M[num] = min(min(abs(num - x), solve((num + 1) / 2) + 2), solve((num - 1) / 2) + 2);
}
return M[num] = min(abs(num - x), solve(num / 2) + 1);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> x >> y;
cout << solve(y) << "\n";
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using pii = pair<int, int>;
int main() {
int n, m;
cin >> n >> m;
vector<int> h(n), w(m);
rep(i, n) cin >> h[i];
rep(i, m) cin >> w[i];
sort(h.begin(), h.end());
vector<int> l(n / 2 + 1), r(n / 2 + 1);
for (int i = 0; i < n / 2; i++) l[i + 1] = l[i] + h[2 * i + 1] - h[2 * i];
for (int i = n / 2; i > 0; i--) r[i - 1] = r[i] + h[2 * i] - h[2 * i - 1];
int ans = 1e9;
rep(i, m) {
int itr = lower_bound(h.begin(), h.end(), w[i]) - h.begin();
if (itr & 1) itr ^= 1;
ans = min(ans, abs(w[i] - h[itr]) + l[itr / 2] + r[itr / 2]);
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;
using ll = long long;
using ld = long double;
const int mod = 1e9 + 7;
const double pi = acos(-1.0);
const int inf = INT_MAX;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
vector<int> a(n), b(m);
for (auto &i : a) cin >> i;
for (auto &i : b) cin >> i;
sort(a.begin(), a.end());
vector<int> diff1(n), diff2(n);
for (int i = 1; i < n; i += 2) {
diff1[i] = a[i] - a[i - 1];
}
for (int i = 3; i < n; i += 2) {
diff1[i] += diff1[i - 2];
}
for (int i = n - 2; i >= 0; i -= 2) {
diff2[i] = a[i + 1] - a[i];
}
for (int i = n - 4; i >= 0; i -= 2) {
diff2[i] += diff2[i + 2];
}
int ans = INT_MAX;
for (int x : b) {
int i = upper_bound(a.begin(), a.end(), x) - a.begin();
if (i % 2 != 0) {
i--;
}
int val1 = (i == 0 ? 0 : diff1[i - 1]);
int val2 = abs(a[i] - x);
int val3 = (i + 1 == n ? 0 : diff2[i + 1]);
ans = min(ans, val1 + val2 + val3);
}
cout << ans << '\n';
return 0;
} |
#include <bits/stdc++.h>
#include <vector>
#include<math.h>
#include<string.h>
using namespace std;
#define MAX 300005
#define MOD 1000000007
#define INF 1000000000000000000
#define EPS 0.0000000001
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL)
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
int main()
{
int n;
//int p[]={2,3,5,7,11,13,17,19,23,29};
scanf("%d",&n);
/*long long x=1;
int i;
for(i=0;i<10&&p[i]<=n;i++)
{
int m=n;
while(m>=p[i])
{
m=m/p[i];
x=x*p[i];
}
}
printf("%lld",x+1);*/
printf("2329089562801");
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < n; ++i)
const ll INF=1000000010;
ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
int main(){
ll n;
cin>>n;
ll x=2;
for(ll y=3;y<=n;y++){
x = lcm(x,y);
}
cout << x+1 << endl;
return 0;
} |
#pragma GCC optimize(2)
#include<unordered_map>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<map>
#include<set>
#define Buff ios::sync_with_stdio(false)
#define rush() int Case = 0; int T; cin >> T; while(T--)
#define rep(i, a, b) for(int i = a; i <= b; i ++)
#define per(i, a, b) for(int i = a; i >= b; i --)
#define reps(i, a, b) for(int i = a; b; i ++)
#define clc(a, b) memset(a, b, sizeof(a))
#define Buff ios::sync_with_stdio(false)
#define readl(a) scanf("%lld", &a)
#define readd(a) scanf("%lf", &a)
#define readc(a) scanf("%c", &a)
#define reads(a) scanf("%s", a)
#define read(a) scanf("%d", &a)
#define lowbit(n) (n&(-n))
#define pb push_back
#define lson rt<<1
#define rson rt<<1|1
#define ls lson, l, mid
#define rs rson, mid+1, r
#define y second
#define x first
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int>PII;
const double eps = 1e-6;
const int INF = 1e9 + 7;
const int N = 2007;
const int M = 1e6 + 7;
const ll mod = 1e9 + 7;
ll dp[N][N];
ll sum[4][N][N];
char a[N][N];
signed main()
{
Buff;
int n, m;
cin >> n >> m;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
cin >> a[i][j];
dp[1][1] = sum[1][1][1] = sum[2][1][1] = sum[3][1][1] = 1;
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= m; j++)
{
if(a[i][j] == '#' || (i == j && j == 1))
continue;
else
{
dp[i][j] = (sum[1][i - 1][j] + sum[2][i][j - 1] + sum[3][i - 1][j - 1]) % mod;
sum[1][i][j] = (sum[1][i - 1][j] + dp[i][j]) % mod;
sum[2][i][j] = (sum[2][i][j - 1] + dp[i][j]) % mod;
sum[3][i][j] = (sum[3][i - 1][j - 1] + dp[i][j]) % mod;
}
}
}
cout << dp[n][m] << endl;
return 0;
} | #include <iostream>
#include <string>
#include <vector>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define ALL(x) ::std::begin(x), ::std::end(x)
using namespace std;
constexpr int64_t MOD = 1000000007;
int64_t solve(int H, int W, const vector<string> & S) {
vector<vector<int64_t>> count(H+1, vector<int64_t>(W+1));
vector<vector<int64_t>> count_horizontal(H+1, vector<int64_t>(W+1));
vector<vector<int64_t>> count_vertical(H+1, vector<int64_t>(W+1));
vector<vector<int64_t>> count_diagonal(H+1, vector<int64_t>(W+1));
// 初期値設定
count.at(1).at(1) = 1;
count_horizontal.at(1).at(1) = 1;
count_vertical.at(1).at(1) = 1;
count_diagonal.at(1).at(1) = 1;
for (int y=1; y <= H; y++) {
for (int x=1; x <= W; x++) {
if (x == 1 and y == 1) {
continue;
}
if (S.at(y-1).at(x-1) == '#') {
count.at(y).at(x) = 0;
count_horizontal.at(y).at(x) = 0;
count_vertical.at(y).at(x) = 0;
count_diagonal.at(y).at(x) = 0;
continue;
}
int64_t count_h = count_horizontal.at(y).at(x-1);
int64_t count_v = count_vertical.at(y-1).at(x);
int64_t count_d = count_diagonal.at(y-1).at(x-1);
int64_t sum_count = ((count_h + count_v) % MOD + count_d) % MOD;
count.at(y).at(x) = sum_count;
count_horizontal.at(y).at(x) = (sum_count + count_h) % MOD;
count_vertical.at(y).at(x) = (sum_count + count_v) % MOD;
count_diagonal.at(y).at(x) = (sum_count + count_d) % MOD;
}
}
return count.at(H).at(W);
}
// generated by online-judge-template-generator v4.7.1 (https://github.com/online-judge-tools/template-generator)
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
constexpr char endl = '\n';
// failed to analyze input format
// TODO: edit here
int H;
int W;
cin >> H;
cin >> W;
vector<string> S(H);
REP (i, H) {
cin >> S.at(i);
}
auto ans = solve(H, W, S);
cout << ans << endl;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define Rep(i,n) for(ll i=0;i<ll(n);i++)
#define Repd(i,n) for(ll i=n-1;i>=0;i--)
#define For(i,a,b) for(ll i=a;i<=ll(b);i++)
#define Ford(i,a,b) for(ll i=a;i>=ll(b);i--)
#define Fora(i,I) for(const auto& i:I)
#define Sort(a) sort(a.begin(), a.end())
const int INF = 1<<30;
const ll MOD = 1000000007;
const ll val = 0;
ll myceil(ll a,ll b){return (a+(b-1))/b;}
ll myfloor(ll a,ll b){return a/b;}
int main(void) {
int ans,x,y,z;
cin>>x>>y>>z;
float takahashi = (float)y / x;
ans = takahashi * z;
if(takahashi*z == (float)ans) {
--ans;
}
cout<<ans<<endl;
} | #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) x.begin(),x.end()
#define pll pair <long long,long long>
#define ss second
#define ff first
#define inf (ll)2e18
#define mod 1000000007
//#define mod 998244353
#define ld long double
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl "\n"
const ll N=200005 ;
ll dp[N][7],n ;
string s,x ;
ll solve(ll id,ll rem)
{
if(id==n)
{
if(rem==0) return 1;
return 0 ;
}
else if(dp[id][rem]!=-1) return dp[id][rem] ;
else
{
ll ans ;
if(x[id]=='A')
{
ans=1 ;
ans&=solve(id+1,(10*rem)%7) ;
ans&=solve(id+1,(rem*10+s[id]-'0')%7) ;
}
else
{
ans=0 ;
ans|=solve(id+1,(10*rem)%7) ;
ans|=solve(id+1,(rem*10+s[id]-'0')%7) ;
}
//cout<<id<<" "<<rem<<ans<<endl ;
return dp[id][rem]=ans ;
}
}
int main()
{
fast ;
cin>>n>>s>>x ;
for(ll i=0;i<N;i++) for(ll j=0;j<7;j++) dp[i][j]=-1 ;
if(solve(0,0)) cout<<"Takahashi" ;
else cout<<"Aoki" ;
}
|
#include<bits/stdc++.h>
using namespace std;
#define author "Sihare0riginals"
#define ss string
#define lli long long int
#define ld long double
#define f first
#define s second
#define all(v) v.begin(),v.end()
#define I(a,i) memset(a,i,sizeof(a));
#define pb push_back
#define mp make_pair
#define L(i,start,end) for(lli i=start;i<=end;i++)
#define R(i,start,end) for(lli i=start;i>=end;i--)
#define ip(n) cin>>n;lli ip[n+1];L(i,1,n)cin>>ip[i];
const lli LINF = 1e18,mod=1e9+7;
void Bl0ck_M0mb0();
signed main()
{
Bl0ck_M0mb0();
lli t=1;
//cin>>t;
while(t--){
ss s1;
cin>>s1;
lli n,l=0,cnt1=0,cnt2=0;
n=s1.length();
n--;
while(n>=0&&s1[n]=='0')
{
n--;
cnt1++;
}
while(l<s1.length()&&s1[l]=='0')
{
cnt2++;
l++;
}
//cout<<l<<" "<<n<<" "<<cnt1<<" "<<cnt2<<endl;
bool poss=true;
while(l<=n)
{
if(s1[l]!=s1[n])
{
poss=false;
break;
}
l++;
n--;
}
if(poss&&cnt1>=cnt2)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
return 0;
}
void Bl0ck_M0mb0(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("ip.txt","r",stdin);
freopen("op.txt","w",stdout);
#endif
}
/*
#define dbg1D(i,start,end,arr) for(lli i=start;i<=end;i++) cout<<i<<"th : "<<arr[i]<<endl;
#define dbg2D(i,j,s1,e1,s2,e2,arr) for(lli i=s1;i<=e1;i++){cout<<i<<"th :";for(lli j=s2;j<=e2;j++)cout<<arr[i][j]<<" ";cout<<endl;}
#define M map<lli,lli> \n #define sz(s) s.size()-1
#define P pair<lli,lli>
#define V vector<lli>
lli dx[4]={-1, 0, 0, +1};
lli dy[4]={0, -1, +1, 0};
lli power(lli a,lli b,lli m){ if(b==0) return 1; if(b==1) return a%m;
lli t=power(a,b/2,m); t=(t*t)%m; if(b&1) t=(t*a)%m; return t;}
lli modInverse(lli a, lli m) { return power(a, m-2, m); } */ | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define ll long long
#define F(type, i, a, b, incr) for (type i = a; i <= (type)(b); i += (type)(incr))
#define RF(type, i, a, b, decr) for (type i = a; i >= (type)(b); i -= (type)(decr))
#define sz(a) sizeof(a)
#define deb(a) cerr << " [" << #a << "->" << a << "] "
#define next_line cerr << '\n'
#define all(a) a.begin(), a.end()
#define iter(it, s) for (auto it = s.begin(); it != s.end(); it++)
#define setbits(x) __builtin_popcountll(x)
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
const int N = 1e5 + 1;
int arr[N], n;
double fun(double x){
double ans =0 ;
for(int i =0 ; i < n; i++){
ans += (x + (double)(arr[i]) - min((double)(arr[i]), 2.0*x));
}
return ans;
}
void solve()
{
cin>> n;
int mn = 1e9;
for(int i =0 ; i < n;i ++){
cin>> arr[i];
mn = min(arr[i], mn);
}
double l = (double(mn) / 2.0), r = 1e9, e = 1e-7;
while(r - l >= e){
double m1 = l + (r - l) / 3;
double m2 = r - (r - l) / 3;
double v1 = fun(m1);
double v2 = fun(m2);
if(v1 > v2){
l = m1;
}else{
r = m2;
}
}
double x = r;
double ans = fun(x) / (double(n));
cout<< ans << '\n';
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// freopen("Debug.txt", "w", stderr);
#else
#endif
cout << fixed << setprecision(10);
int _t =1;
// cin>>_t;
F(int, i, 1, _t, 1){
// cout << "Case #" << i << ": ";
solve();
}
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vc = vector<T>;
template<class T> using vvc = vc<vc<T>>;
template<class T> using vvvc = vc<vvc<T>>;
template<class T> using vvvvc = vvc<vvc<T>>;
template<class T> using PQ = priority_queue<T>;
template<class T> using invPQ = priority_queue<T, vector<T>, greater<T>>;
using IP = pair<int, int>;
using LP = pair<ll, ll>;
#define all(x) begin(x), end(x)
#define rep(i, n) for (int i = 0; (i) < (int)(n); i++)
#define rep3(i, m, n) for (int i = (m); (i) < (int)(n); i++)
#define repr(i, n) for (int i = (n) - 1; (i) >= 0; i--)
#define rep3r(i, m, n) for (int i = (n) - 1; (i) >= (int)(m); i--)
template<class T> inline bool chmax(T & a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T & a, T b) { if (a > b) { a = b; return 1; } return 0; }
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t, N;
cin >> t >> N;
auto isok = [&] (ll x) -> bool {
if (x - (x+1)*100/(100+t) < N) return true;
else return false;
};
ll ok = 0, ng = 1000000000000;
while (abs(ok - ng) > 1) {
ll mid = (ok + ng) / 2;
if (isok(mid)) ok = mid;
else ng = mid;
}
if ((ng+1)*100/(100+t) * (100+t)/100 == ng) cout << ok << endl;
else cout << ng << endl;
} | #ifndef DEBUG
#define NDEBUG
#endif
#include <bits/stdc++.h>
#define def(v) int &v = e[i].v
#define cls(a) memset (a, 0, sizeof (a))
#define mset(a, b) memset (a, b, sizeof (a))
#define go(i,e,u,...) for (int i = (u), ##__VA_ARGS__; i; i = e[i].nt)
#define fir(i,a,b,...) for (int i = (a), ##__VA_ARGS__; i <= (b); ++i)
#define firr(i,a,b,...) for (int i = (a), ##__VA_ARGS__; i >= (b); --i)
#ifdef DEBUG
#define debug(format,...) (void)(fprintf (stderr, "debug in %d: " format "\n", __LINE__, ##__VA_ARGS__))
#define dbug(x) (void)(std::cerr << #x " = " << (x) << std::endl)
#else
#define debug(...) (void)0
#define dbug(...) (void)0
#endif
typedef long long LL;
template<class T>
bool rei (T& x) {
bool f = true;
int ch;
for (ch = getchar (); !isdigit (ch); ch = getchar ()) {
if (ch == EOF) return false;
f = ch != '-';
}
x = 0;
if (f) do x = x * 10 + (ch & 15); while (isdigit (ch = getchar ()));
else do x = x * 10 - (ch & 15); while (isdigit (ch = getchar ()));
return true;
}
template<class T1, class T2> T1& cmax (T1& a, const T2& b) {return a < b ? a = b : a;}
template<class T1, class T2> T1& cmin (T1& a, const T2& b) {return a > b ? a = b : a;}
using namespace std;
signed main () {
LL t, n; rei (t), rei (n);
printf ("%lld\n", (100 * n + t - 1) / t + n - 1);
return 0;
} |
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
using namespace std;
#define hackcyborg shresth_walia
#define all(a) a.begin(), a.end()
#define ll long long
#define ld long double
#define pb push_back
#define mod 1000000007
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define int long long
#define ordered_set tree<int,null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define sz(x) (int)(x).size()
typedef pair<int, int> pii;
typedef vector<int> vi;
ll bp(ll a,ll b,int Mod=mod)
{
ll res=1;
a%=Mod;
while(b>0)
{
if(b&1)
res=(a*res)%Mod;
a=(a*a)%Mod;
b/=2;
}
return res;
}
main()
{
IO
int a,b;
cin>>a>>b;
if(b>a)
{ int su=0;
for(int x=1;x<=b;x++)
{cout<<-(x+10000)<<" ";su-=(x+10000);}
for(int x=1;x<=a-1;x++)
{cout<<x<<" ";su+=x;}
cout<<-su;
}
else
{
int su=0;
for(int x=1;x<=a;x++)
{cout<<x+10000<<" ";su+=(x+10000);}
for(int x=1;x<=b-1;x++)
{cout<<-x<<" ";su-=x;}
cout<<-su;
}
}
| #include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define int long long
#include <map>
#include <queue>
#include <set>
int fact[200001]; //https://atcoder.jp/contests/dp/tasks/dp_t
int inv[200001];
int de[200001];
ll mod=1000000007;
ll power(ll x,ll y){ll res = 1;while(y){if(y&1) res = (res*x)%mod;y=y/2,x=(x*x)%mod;}return res%mod;}
bool digits[49];
int low,high;
int n,k,totalcost;
int w[100100],v[100100];
int a[100100];
int prefix[100100];
int count1;
int ans;
//int a[3][3];
int connected;
string s1,s2;
bool isprime(ll x) {
//return a[x];
/*for(ll i = 2; i * i <= x; i++) {
if(x % i == 0)
return false;
}
return true;*/
}
void print(vector<int> sum)
{
cout<<"vector is \n";
for(int i=0;i<sum.size();i++)
{
cout<<sum[i]<<" ";
}
cout<<endl;
}
void solve(){
int a,b,c;
cin>>a>>b>>c;
cout<<(21-(a+b+c))<<"\n";
}
signed main(){
ios_base::sync_with_stdio(false);
cout.tie(0);cin.tie(0);
//cout.precision(10);
ll _t=1;
//cin>>_t;
while(_t--)
{
solve();
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「sからnまで」の降順の繰り返し
typedef long long ll;
typedef long double ld;
const ll inf = 1e18;
const ll mod = 1e9+7;
int main() {
ll n;
cin>>n;
ll L=0,R=2e9;
while(R-L>1){
ll m=(R+L)/2;
if(m*(m+1)/2<=n+1)L=m;
else R=m;
}
cout<<n-L+1<<endl;
}
| #include<cstdio>
#define lli long long
lli n,a;
int main()
{
scanf("%lld",&n),++n,a=n;
for(register int i=1;;++i)
if(n<i)return printf("%lld",a),0;
else n-=i,--a;
printf("%lld",a);
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#define FOR(i, x, y) for(int i = (x); i < (y); ++i)
#define REP(i, x, y) for(int i = (x); i <= (y); ++i)
#define PB push_back
#define MP make_pair
#define PH push
#define fst first
#define snd second
typedef long long ll;
typedef unsigned long long ull;
typedef double lf;
typedef long double Lf;
typedef pair<int, int> pii;
const int maxn = 2e5 + 5;
const int maxk = 305;
const int INF = 998244353;
class Number{
public:
int dat;
Number(){}
Number(int dat_): dat(dat_){}
inline Number&operator += (const Number &oth){ (dat += oth.dat) -= (dat >= INF ? INF : 0); return *this; }
inline Number&operator -= (const Number &oth){ (dat -= oth.dat) += (dat < 0 ? INF : 0); return *this; }
inline Number&operator *= (const Number &oth){ dat = 1ll * dat * oth.dat % INF; return *this; }
inline Number operator + (const Number &oth)const{ Number ret = *this; ret += oth; return ret; }
inline Number operator - (const Number &oth)const{ Number ret = *this; ret -= oth; return ret; }
inline Number operator * (const Number &oth)const{ Number ret = *this; ret *= oth; return ret; }
}a[maxn], binom[maxk][maxk], pw[2][maxn], s[maxk];
const Number inv2 = (INF + 1) / 2;
int n, k;
inline void precalc(){
int p = 0, q = 1;
REP(i, 0, k){
binom[i][0] = 1;
REP(j, 1, i)
binom[i][j] = binom[i - 1][j - 1] + binom[i - 1][j];
FOR(j, 0, n){
pw[q][j] = (!i ? 1 : pw[p][j] * a[j]);
s[i] += pw[q][j];
}
swap(p, q);
}
return;
}
int main(){
scanf("%d%d", &n, &k);
FOR(i, 0, n)
scanf("%d", &a[i].dat);
precalc();
REP(x, 1, k){
Number ans = 0;
REP(i, 0, x){
Number res = s[i] * s[x - i] - s[x];
ans += res * binom[x][i];
}
printf("%d\n", (ans * inv2).dat);
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using vvb = vector<vb>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, s, n) for(int i = (int)(s); i < (int)(n); ++i)
ll INF = 1ll << 60;
int main(){
ll n, q;
cin >> n >> q;
vl a(n);
rep(i, 0, n){
cin >> a[i];
}
vector<pll> k(q);
rep(i, 0, q){
ll t;
cin >> t;
k[i] = {t, i};
}
sort(k.begin(), k.end());
vl ans(q);
int id = 0;
rep(i, 0, q){
ll t = k[i].first;
if(id == 0){
if(a[0]-1 >= t){
ans[k[i].second] = t;
continue;
}
}
while(id < n-1 && a[id+1]-(id+2) < t){
id++;
}
ans[k[i].second] = t+id+1;
}
rep(i, 0, q){
cout << ans[i] << endl;
}
return 0;
} |
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
//using namespace atcoder;
using ll = long long;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
typedef vector<vector<int> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;
#define debug(v) cout<<#v<<": ",prt(v);
template <typename A,typename B>
inline void prt(pair<A,B> p){cout<<"("<<p.first<<", "<<p.second<<")\n";}
template <typename A,typename B,typename C>
inline void prt(tuple<A,B,C> p){cout<<"("<<get<0>(p)<<", "<<get<1>(p)<<", "<<get<2>(p)<<")\n";}
inline void prt(bool p){if(p)cout<<"True"<<'\n';else cout<<"False"<<'\n';}
template <typename T>
inline void prt(vector<T> v){cout<<'{';for(ll i=0;i<v.size();i++){cout<<v[i];if(i<v.size()-1)cout<<", ";}cout<<'}'<<'\n';}
template<typename T>
inline void prt(vector<vector<T> >& vv){ for(const auto& v : vv){ prt(v); } }
template <typename T>
inline void prt(deque<T> v){cout<<'{';for(ll i=0;i<v.size();i++){cout<<v[i];if(i<v.size()-1)cout<<", ";}cout<<'}'<<'\n';}
template <typename A,typename B>
inline void prt(map<A,B> v){cout<<'{';ll c=0;for(auto &p: v){cout<<p.first<<":"<<p.second;c++;if(c!=v.size())cout<<", ";}cout<<'}'<<'\n';}
template <typename A,typename B>
inline void prt(unordered_map<A,B> v){cout<<'{';ll c=0;for(auto &p: v){cout<<p.first<<":"<<p.second;c++;if(c!=v.size())cout<<", ";}cout<<'}'<<'\n';}
template <typename T>
inline void prt(set<T> v){cout<<'{';for(auto i=v.begin();i!=v.end();i++){cout<<*i;if(i!=--v.end())cout<<", ";}cout<<'}'<<'\n';}
template <typename T>
inline void prt(multiset<T> v){cout<<'{';for(auto i=v.begin();i!=v.end();i++){cout<<*i;if(i!=--v.end())cout<<", ";}cout<<'}'<<'\n';}
int main(){
ll n;
cin >> n;
vector<ll>a(n);
rep(i,n)cin>>a[i];
sort(a.begin(),a.end());
ll x = a[0];
set<ll>st;
rep(i,n)st.insert(a[i]);
ll X = *st.rbegin();
while(X!=x){
st.erase(X);
ll nx = X-x;
st.insert(nx);
X = *st.rbegin();
chmin(x,nx);
}
cout << X << endl;
return 0;
} | #include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define all(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;
//srand (time(NULL));
//rand()%10 //random 1-9
int arr[200005] = {0};
//queue<pair<int,int> pq;
//bool done = false;
//bool vis[105][105] = {0};
//int memo[105][105] = {0};
//vector<int> v;
//pair<int,int> arr;
int mov[2][4] = {{1 ,-1, 0, 0},
{0 , 0, 1,-1}};
int MOD = 1e9+7;
int gcd(int a,int b)
{
if(a==0) return b;
return gcd(b%a,a);
}
void solve()
{
int n,tmpgcd;
cin >> n;
cin >> tmpgcd;
for(int i=2;i<=n;i++)
{
int tmp;
cin >> tmp;
tmpgcd = gcd(tmpgcd,tmp);
}
cout << tmpgcd << endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int tc=1;
//cin>>tc;
while(tc--)
{
solve();
}
return 0;
}
|
#include<iostream>
using namespace std;
int main(){
int n;
cin>>n;
if(n%2 == 1){
cout<<"Black\n";
}
else{
cout<<"White\n";
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
int ri() {
int n;
scanf("%d", &n);
return n;
}
bool poss(string s, int x) {
int len = s.size();
if(to_string(x).size() > len)
return false;
vector<int> cnt(10, 0);
for(char c : s) {
int d = c - '0';
cnt[d] ++;
}
vector<int> need(10, 0);
for(int i = 0; i < min(len, 3); ++i) {
need[x % 10]++;
x /= 10;
}
for(int i = 0; i < 10; ++i)
if(cnt[i] < need[i])
return false;
return true;
}
int main() {
string s;
cin >> s;
for(int x = 8; x < 1000; x += 8) {
if(poss(s, x)) {
cout << "Yes";
return 0;
}
}
cout << "No";
} |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
if (n == 0) {
cout << "Yes\n";
return 0;
}
while (!(n % 10)) n /= 10;
vector<int> f, b;
while (n) {
f.emplace_back (n % 10);
n /= 10;
}
b = f;
reverse (b.begin(), b.end());
if (b == f) cout << "Yes\n";
else cout << "No\n";
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
bool palindromeasis(string s,int low,int high)
{
int flag=1;
while(low<=high)
{
if(s[low]==s[high])
{
low++;
high--;
}
else
{
flag=0;
break;
}
}
if(flag==0)
return false;
return true;
}
bool palindrome(string s)
{
if(palindromeasis(s,0,s.length()-1))
return true;
int j=s.length()-1;
while(s[j]=='0')
j--;
if(j<s.length() && palindromeasis(s,0,j))
return true;
return false;
}
int main()
{
string s;
cin>>s;
if(palindrome(s))
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
int N, M;
const int MOD = 998244353;
const int D = 20;
int f[200010][D + 1];
int fac[200010], ifac[200010];
vector<int> dv[200010];
int quick_pow(int a,int x) {
int ret = 1;
while(x) {
if (x & 1) ret = 1LL * ret * a % MOD;
a = 1LL * a * a % MOD;
x >>= 1;
}
return ret;
}
int C(int n, int k) {
if (k > n || k < 0) return 0;
return 1LL * fac[n] * ifac[k] % MOD * ifac[n - k] % MOD;
}
int main() {
fac[0] = ifac[0] = 1;
for (int i=1;i<=200000;i++) {
fac[i] = 1LL * fac[i - 1] * i % MOD;
ifac[i] = quick_pow(fac[i], MOD - 2);
}
scanf("%d%d",&N,&M);
for (int i=1;i<=M;i++) {
for (int j=i*2;j<=M;j+=i) {
dv[j].push_back(i);
}
}
for (int i=1;i<=M;i++) {
f[i][1] = 1;
for (auto d: dv[i]) {
for (int j=2;j<=D;j++) {
f[i][j] = (f[i][j] + f[d][j - 1]) % MOD;
}
}
}
int ans = 0;
for (int i=1;i<=M;i++) {
for (int j=1;j<=D;j++) {
ans = (ans + 1LL * C(N - 1, j - 1) * f[i][j] % MOD) % MOD;
}
}
printf("%d\n",ans);
} | //#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a) (a).begin(),(a).end()
#define ALLR(a) (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T1, typename T2>bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
template<typename T1, typename T2>bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}
template<typename T>void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++){cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++){for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>vector<vector<T>>vec(ll x, ll y, T w){vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,-1,0,0,1,1,-1,-1};vector<ll>dy={0,0,1,-1,1,-1,1,-1};
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 T1, typename T2>ostream &operator<<(ostream &os, const pair<T1, T2>&p){return os << p.first << " " << p.second;}
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v){for(auto &z:v)os << z << " ";cout<<"|"; return os;}
//mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
int main(){
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
ll res=0,buf=0;
bool judge = true;
ll n,m;cin>>n>>m;
vector<ll>w(n);
rep(i,0,n)cin>>w[i];
ll mxw=*max_element(ALL(w));
vector<P>p(m);
rep(i,0,m){
cin>>p[i].se>>p[i].fi;
if(p[i].fi<mxw){
cout<<-1<<endl;
return 0;
}
}
//荷重、長さ
//p.EB(INF,INF);
p.EB(0,0);
sort(ALL(p));
rep(i,0,(ll)p.size()-1){
chmax(p[i+1].se,p[i].se);
}
//debug(p,p.size());
vector<ll>v(n);
iota(ALL(v),0);
res=INF;
do{
vector<ll>pos(n);
rep(i,1,n){
ll nw=w[v[i]];
ll mx=0;
rrep(j,0,i){
nw+=w[v[j]];
P q=*(--lower_bound(ALL(p),MP(nw,0LL)));
chmax(mx,q.se-(pos[i-1]-pos[j]));
}
pos[i]=pos[i-1]+mx;
}
/*if(is_sorted(ALL(v))){
debug(v,3);debug(pos,3);cout<<endl;
}*/
chmin(res,pos[n-1]);
}while(next_permutation(ALL(v)));
cout<<res<<endl;
return 0;
} |
#include<bits/stdc++.h>
#define pb push_back
#define fo(i,n) for(int i=0;i<n;i++)
#define ll long long
#define int long long
#define Mod 1000000007
#define maxn 200005
#define MAX 4294967296 // 2^32
const int M=1e9+7;
#define ip pair<int,int>
#define test(t) ll t;cin>>t;while(t--)
using namespace std;
long long gcd(int x,int y){
if(y>x)swap(x,y);
if(y==0)return x;
return gcd(y,x%y);
}
int power(int x,int y){
if(y==0)return 1;
int t=1;
int ans=1;
while(y!=0){
if(y%2)ans=(ans%Mod*x%Mod)%Mod;
x=(x%Mod*x%Mod)%Mod;
y/=2;
}
return ans;
}
int prime[100005]={0};
vector<int>v;
int a[1001][3];
void solve(){
int n,m,k;
cin>>n>>m>>k;
n-=m;
n+=k;
cout<<n;
}
signed main(){
// std::string binary = std::bitset<8>(n).to_string();
ios::sync_with_stdio(0);
cin.tie(0);
{solve();}
} | #include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
#define inf 1e18+42
#define endl "\n"
#define pi 3.1415926535897932384626433832795028841971693993751058
#define maxn 100005
#define out1(a) cout<<#a<<" "<<a<<endl
#define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define fori(it,A) for(auto it=A.begin();it!=A.end();it++)
#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define pq priority_queue
#define all(x) (x).begin(),(x).end()
#define zero(x) memset(x,0,sizeof(x));
#define ceil(a,b) (a+b-1)/b
using namespace std;
int binpow(int a, int b) {
int res = 1;
while (b > 0) {
if (b & 1)
res = res * a;
a = a * a;
b >>= 1;
}
return res;
}
//START OF CODE ->->->->->->->
void solve()
{
int n;
cin>>n;
vector<pair<int,int>> p;
rep(i,0,n){
int x,y;
cin>>x>>y;
p.pb({x,y});
}
int ans = 0;
rep(i,0,p.size()){
rep(j,i+1,p.size()){
int x = p[j].ft - p[i].ft;
int y = p[j].sd - p[i].sd;
x = abs(x);
y = abs(y);
if ( y <= x ){
ans++;
}
}
}
cout<<ans<<endl;
}
//END OF CODE ->->->->->->->->
signed main()
{
fast;
int t = 1;
// cin>>t;
while(t--)
{
solve();
}
return 0;
}
|
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
int main()
{
int N,X,i;
char S[200005];
scanf("%d%d",&N,&X);
scanf("%s",S);
for(i=0;S[i]!='\0';i++){
if(S[i]=='x'){
if(X==0)X=0;
else --X;
}
if(S[i]=='o')++X;
}
printf("%d",X);
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
int main(){
string S; cin >> S;
int ans = 0;
for(int i=0; i<=9999; i++){
vector<bool> flag(10);
int X = i;
for(int j=0; j<4; j++){
flag[X%10] = true;
X /= 10;
}
bool flag2 = true;
for(int j=0; j<10; j++){
if(S[j]=='o' && !flag[j]) flag2 = false;
if(S[j]=='x' && flag[j]) flag2 = false;
}
ans += flag2;
}
cout << ans << endl;
} |
//W4P3R
#include<bits/stdc++.h>
#define inf 1e9
#define eps 1e-6
#define mp make_pair
#define pb push_back
#define re register int
#define fr first
#define sd second
#define pa pair<int,int>
#define FOR(i,a,b) for(re i=a;i<=b;i++)
#define REP(i,a,b) for(re i=a;i>=b;i--)
#define MEM(a) memset(a,0,sizeof(a))
#define N 200010
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
inline ll read()
{
char ch=getchar();
ll s=0,w=1;
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
return s*w;
}
inline int lowbit(int x){return x&(-x);}
int n,m,k;
const int mod=998244353;
inline int ksm(int a,int b)
{
int ans=1;
while(b){if(b&1)ans=1LL*ans*a%mod;b>>=1;a=1LL*a*a%mod;}
return ans;
}
inline int Z(int x){return (x>=mod?x-mod:x);}
int main()
{
//ios::sync_with_stdio(false);
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
n=read(),m=read(),k=read();
if(n>m)swap(n,m);int ans=0;
if(n==1)
{
swap(n,m);
FOR(x,1,k)
{
int v=1LL*(x-1)*ksm(x,mod-2)%mod,s=1LL*Z(1+mod-ksm(v,n))%mod*ksm(Z(1+mod-v),mod-2)%mod;
s=1LL*s*ksm(x,n-1)%mod;
// cout<<"WTF:"<<x<<" "<<s<<endl;
ans=Z(ans+s);
}
cout<<ans<<'\n';return 0;
}
FOR(x,1,k)
{
int v=1LL*(x-1)*ksm(x,mod-2)%mod,s=1LL*Z(1+mod-ksm(v,n))%mod*ksm(Z(1+mod-v),mod-2)%mod;
s=1LL*s*ksm(x,n-1)%mod;
//cout<<"WTF:"<<x<<" "<<s<<endl;
ans=Z(ans+1LL*s*ksm(k-x+1,m)%mod);
}
cout<<ans<<'\n';
return 0;
}
//gl
| #pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
void*wmem;
char memarr[96000000];
template<class S, class T> inline S max_L(S a,T b){
return a>=b?a:b;
}
template<class T> inline void walloc1d(T **arr, int x, void **mem = &wmem){
static int skip[16] = {0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
(*mem) = (void*)( ((char*)(*mem)) + skip[((unsigned long long)(*mem)) & 15] );
(*arr)=(T*)(*mem);
(*mem)=((*arr)+x);
}
template<class T1> void sortA_L(int N, T1 a[], void *mem = wmem){
sort(a, a+N);
}
template<class T1> void rsortA_L(int N, T1 a[], void *mem = wmem){
sortA_L(N, a, mem);
reverse(a, a+N);
}
inline int my_getchar_unlocked(){
static char buf[1048576];
static int s = 1048576;
static int e = 1048576;
if(s == e && e == 1048576){
e = fread_unlocked(buf, 1, 1048576, stdin);
s = 0;
}
if(s == e){
return EOF;
}
return buf[s++];
}
inline void rd(int &x){
int k;
int m=0;
x=0;
for(;;){
k = my_getchar_unlocked();
if(k=='-'){
m=1;
break;
}
if('0'<=k&&k<='9'){
x=k-'0';
break;
}
}
for(;;){
k = my_getchar_unlocked();
if(k<'0'||k>'9'){
break;
}
x=x*10+k-'0';
}
if(m){
x=-x;
}
}
inline void rd(long long &x){
int k;
int m=0;
x=0;
for(;;){
k = my_getchar_unlocked();
if(k=='-'){
m=1;
break;
}
if('0'<=k&&k<='9'){
x=k-'0';
break;
}
}
for(;;){
k = my_getchar_unlocked();
if(k<'0'||k>'9'){
break;
}
x=x*10+k-'0';
}
if(m){
x=-x;
}
}
struct MY_WRITER{
char buf[1048576];
int s;
int e;
MY_WRITER(){
s = 0;
e = 1048576;
}
~MY_WRITER(){
if(s){
fwrite_unlocked(buf, 1, s, stdout);
}
}
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
MY_WRITER_VAR.s = 0;
}
MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
my_putchar_unlocked(a);
}
inline void wt_L(long long x){
int s=0;
int m=0;
char f[20];
if(x<0){
m=1;
x=-x;
}
while(x){
f[s++]=x%10;
x/=10;
}
if(!s){
f[s++]=0;
}
if(m){
my_putchar_unlocked('-');
}
while(s--){
my_putchar_unlocked(f[s]+'0');
}
}
int N;
long long A[100000];
long long B[100000];
int os;
int es;
long long o[100000];
long long e[100000];
int main(){
int i;
wmem = memarr;
long long res;
rd(N);
{
int Lj4PdHRW;
for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
rd(A[Lj4PdHRW]);
}
}
{
int e98WHCEY;
for(e98WHCEY=(0);e98WHCEY<(N);e98WHCEY++){
rd(B[e98WHCEY]);
}
}
{
int FmcKpFmN;
long long xr20shxY;
if(N==0){
xr20shxY = 0;
}
else{
xr20shxY = A[0];
for(FmcKpFmN=(1);FmcKpFmN<(N);FmcKpFmN++){
xr20shxY += A[FmcKpFmN];
}
}
res =xr20shxY;
}
for(i=(0);i<(N);i+=(2)){
o[os++] = B[i] - A[i];
}
for(i=(1);i<(N);i+=(2)){
e[es++] = B[i] - A[i];
}
rsortA_L(os, o);
rsortA_L(es, e);
for(i=(0);i<(os);i++){
res +=max_L(o[i]+e[i], 0);
}
wt_L(res);
wt_L('\n');
return 0;
}
// cLay varsion 20201018-2
// --- original code ---
// int N;
// ll A[1d5], B[1d5];
// int os, es;
// ll o[1d5], e[1d5];
// {
// ll res;
// rd(N,A(N),B(N));
//
// res = sum(A(N));
// rep(i,0,N,2) o[os++] = B[i] - A[i];
// rep(i,1,N,2) e[es++] = B[i] - A[i];
// rsortA(os, o);
// rsortA(es, e);
// rep(i,os) res += max(o[i]+e[i], 0);
//
// wt(res);
// }
|
/**
* created: 18/04/2021, 15:08:05
**/
#include <bits/stdc++.h>
using namespace std;
const int max_n = 100111, mod = 1000000007;
int n, a[max_n], ans = 1;
int main() {
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%d", &a[i]);
}
++n;
sort(a, a + n);
for (int i = 1; i < n; ++i) {
ans = 1LL * ans * (a[i] - a[i - 1] + 1) % mod;
}
printf("%d\n", ans);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define pa pair<long long, int>
const int mod = 998244353, i2 = mod + 1 >> 1;
int n, a[200010];
long long pow2[200010], inv2[200010], ans = 0;
vector<pa> s;
int main()
{
scanf("%d", &n);
pow2[0] =inv2[0] = 1;
for (int i = 1; i <= n; i++)
{
pow2[i] = (pow2[i - 1] << 1) % mod;
inv2[i] = inv2[i - 1] * i2 % mod;
}
for (int i = 1; i <= n; i++)
scanf("%d", &a[i]);
sort(a + 1, a + 1 + n);
s.push_back({a[1], 1});
for (int i = 2; i <= n; i++)
if (a[i] == a[i - 1])
s.back().second++;
else
s.push_back({a[i], 1});
long long now = 0;
int num = 0;
for (int i = 0; i < s.size(); i++)
{
(ans += s[i].first * s[i].first % mod * (pow2[s[i].second] - 1) % mod) %= mod;
(ans += s[i].first * (pow2[s[i].second] - 1) % mod * pow2[num] % mod * now % mod) %= mod;
num += s[i].second;
(now += s[i].first * (pow2[s[i].second] - 1) % mod * inv2[num] % mod) %= mod;
}
printf("%lld\n", ans);
} |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
scanf("%d",&N);
int A[N];
int sum = 0;
for(int i=0;i<N;i++){
scanf("%d",&A[i]);
if(A[i]>10){
sum += A[i]-10;
}
}
printf("%d",sum);
return 0;
} | #include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque>
#include <string>
using namespace std;
int n;
int a[100010];
set<int> numSet;
int main()
{
scanf("%d", &n);
for (int i = 0 ; i < n ; i++) {
scanf("%d", &(a[i]));
numSet.insert(a[i]);
}
set<int>::iterator iBegin;
set<int>::reverse_iterator iLast;
while (numSet.size() > 1) {
iBegin = numSet.begin();
iLast = numSet.rbegin();
int minNum = *iBegin;
int maxNum = *iLast;
numSet.erase(maxNum);
// printf("%d\n", maxNum);
maxNum = maxNum % minNum;
if (maxNum == 0)
maxNum = minNum;
numSet.insert(maxNum);
}
iBegin = numSet.begin();
int lastNum = *iBegin;
printf("%d\n", lastNum);
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a,i##end=b;i<=i##end;i++)
#define drep(i,a,b) for(int i=a,i##end=b;i>=i##end;i--)
inline int read() {
int x=0,f=1;char c=getchar();
while(c<48||c>57){if(c=='-')f=-1;c=getchar();}
while(c>=48&&c<=57)x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
using namespace std;
char s[105][105];
int main() {
int n=read(),m=read(),x=read(),y=read();
rep(i,1,n)scanf("%s",s[i]+1);
int ly=y;while(ly>=1&&s[x][ly]!='#')ly--;
int ry=y;while(ry<=m&&s[x][ry]!='#')ry++;
int lx=x;while(lx>=1&&s[lx][y]!='#')lx--;
int rx=x;while(rx<=n&&s[rx][y]!='#')rx++;
printf("%d\n",rx-lx+ry-ly-3);
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
#define pqueue priority_queue
#define umap unordered_map
#define uset unordered_set
#define bits(x) __builtin_popcount((x))
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) ((x) / gcd(x, y) * (y))
#define inf 4557430888798830399LL
#define mst(dp, val) memset(dp, val, sizeof(dp))
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define repd(i, a, b, d) for (int i = a; i <= b; i += d)
#define rep_(i, a, b) for (int i = a; i >= b; --i)
#define repd_(i, a, b) for (int i = a; i >= b; i -= d)
#define mxm(a, b) a = max(a, b)
#define mnm(a, b) a = min(a, b)
#define L size()
#define pb push_back
#define X first
#define Y second
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << #x << "=" << x << endl
#define readArr(a, n) for (int i = 1; i <= n; i++) cin >> a[i];
#define printArr(a, n) for (int i = 1; i <= n; i++) cout << a[i] << " "; cout << endl;
#define mod 1000000007
#define Add(x, d) x = (x + (d)) % mod
#define print(e) cout << (e) << endl
// #define MULTI_CASES
// #define PRE
const int N = 2e5 + 5;
// int a[N];
void solve() {
int A, B, C;
cin >> A >> B >> C;
C = C % 2 ? 1 : 2;
int a = pow(A, C), b = pow(B, C);
if (A == B || a == b) print("=");
if (a > b) print(">");
if (a < b) print("<");
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
#ifdef MULTI_CASES
#ifdef PRE
pre();
#endif
int t; cin >> t;
while (t--) solve();
#else
solve();
#endif
return 0;
}
|
#include <bits/stdc++.h>
#define ll long long
#define fori(n) for( int i = 0; i < n; i++)
#define all(x) x.begin(),x.end()
#define pll pair < ll,ll >
using namespace std;
int main()
{
int n,m;
cin >> n >> m;
if(m%n==0)
{
cout << "Yes";
}
else
{
cout << "No";
}
}
| #include <math.h>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, l, n) for (int i = (l); i < (n); i++)
#define max(p, q) ((p) > (q) ? (p) : (q))
#define min(p, q) ((p) < (q) ? (p) : (q))
#define mod
using ll = long long;
using P = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T> >;
const ll INF = 1e18 + 1;
ll f(ll a, ll n, ll p)
{
if (n == 0)
return 1;
if (n == 1)
return a % p;
if (n % 2 == 1)
{
ll x = f(a, (n - 1) / 2, p);
return a * x * x % p;
}
ll y = f(a, n / 2, p);
return y * y % p;
}
int main()
{
ll n, m;
cin >> n >> m;
ll ans = f(10, n, m * m);
ans /= m;
cout << ans % m << endl;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
#define vec vector<ll>
#define mat vector<vector<ll> >
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef long double ld;
typedef complex<double> Complex;
const ll INF=1e9+7;
const ll inf=INF*INF;
const ll mod=998244353;
const ll MAX=140010;
template< class T >
struct BIT
{
vector< T > data;
BIT(int sz)
{
data.assign(++sz, 0);
}
T sum(int k)
{
T ret = 0;
for(++k; k > 0; k -= k & -k) ret += data[k];
return (ret);
}
void add(int k, T x)
{
for(++k; k < data.size(); k += k & -k) data[k] += x;
}
};
signed main(){
ll n;cin>>n;
vector<ll>a(n);
rep(i,n)cin>>a[i];
BIT<ll>bit(n+1);
ll ans=0;
rep(i,n){
ans+=bit.sum(n)-bit.sum(a[i]);
bit.add(a[i],1);
}
rep(i,n){
cout<<ans<<endl;
ans+=n-1-a[i];
ans-=a[i];
}
} | #include "bits/stdc++.h"
using namespace std;
//#include "testlib.h"
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define ll int
#define M 1000000007
#define MM 998244353
#define inputarr(a,n) for(int i=0;i<n;++i) cin>>a[i]
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) m*(n/GCD(m,n))
#define mii map<ll ,ll >
#define msi map<string,ll >
#define rep(a,b) for(ll i=a;i<b;i++)
#define rep0(n) for(ll i=0;i<n;i++)
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#define vi vector<ll>
#define vs vector<string>
#define ppb pop_back
#define endl '\n'
#define asdf ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define r0 return 0;
#define FORD(i, a, b) for (int i = (int) (a); i >= (int) (b); --i)
#define inputoutput freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define Set(a, s) (a, s, sizeof (a))
#define FOR repi
#define vii vector<pii>
#define pii pair<int,int>
#define REVERSE(v) reverse(all(v))
#define trav(a, x) for(auto& a : x)
#define display(x) trav(a,x) cout<<a<<" ";cout<<endl
#define debug cerr<<"bhau"<<endl
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
template<typename T, typename U> static inline void amin(T &x, U y)
{
if (y < x)
x = y;
}
template<typename T, typename U> static inline void amax(T &x, U y)
{
if (x < y)
x = y;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
// http://xorshift.di.unimi.it/splitmix64.c
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
ll max(ll a, ll b) { return (a > b)? a : b;}
int min(int a, int b) { return (a < b)? a : b;}
const int N = 2e5 + 10;
vi adj[N];
vi lvl[N];
int in[N];
int out[N];
int cnt = 0;
int L[N];
void dfs(int v,int l = 0){
in[v] = ++cnt;
// trace(v,cnt);
lvl[l].pb(cnt);
L[v] = l;
for(auto i: adj[v]){
dfs(i, l + 1);
}
out[v] = cnt;
}
int solve(){
int n;
cin >> n;
for(int i = 2; i <= n; i++){
int x;
cin >> x;
adj[x].pb(i);
}
dfs(1);
// return 0;
int q;
cin >> q;
while(q--){
int u, d;
cin >> u >> d;
// d -= L[u];
int ans = upper_bound(all(lvl[d]), out[u]) - lower_bound(all(lvl[d]), in[u]);
cout << ans << endl;
}
return 0;
}
signed main(){
asdf
// freopen("inputf.in", "w", stdout);
int t=1;
// cin>>t;
while(t--){
solve();
}
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define il inline
#define rg register
il int read()
{
int re=0,k=1;char ch=getchar();
while(ch>'9'||ch<'0'){if(ch=='-')k=-1;ch=getchar();}
while(ch<='9'&&ch>='0'){re=re*10+ch-48;ch=getchar();}
return re*k;
}
il void write(int x)
{
if(x<0) return putchar('-'),write(-x),void();
if(x<10)return putchar(x+48),void();
return write(x/10),putchar(x%10+48),void();
}
int col[200005],l,n,m;
int fa[200005],head[200005],tot;
int find(int x)
{
if(x==fa[x])return x;
return fa[x]=find(fa[x]);
}
struct ss{
int node,nxt,w;
}e[400005];
void add(int u,int v,int w)
{
e[++tot].nxt=head[u];
head[u]=tot;
e[tot].node=v;
e[tot].w=w;
}
void dfs(int x,int fa,int c)
{
// cerr<<x
col[x]=c;
for(rg int i=head[x];i;i=e[i].nxt)
{
int y=e[i].node;
if(y==fa)continue;
if(c==e[i].w)
{
dfs(y,x,c%n+1);
}
else
{
dfs(y,x,e[i].w);
}
}
}
signed main()
{
n=read();m=read();
for(rg int i=1;i<=n;i++)
fa[i]=i;
for(rg int i=1,a,b,c;i<=m;i++)
{
a=read();b=read();c=read();
int x=find(a);
int y=find(b);
if(x==y)continue;
fa[x]=y;
add(a,b,c);
add(b,a,c);
}
dfs(1,0,1);
for(rg int i=1;i<=n;i++)
write(col[i]),puts("");
} | #include <bits/stdc++.h>
using namespace std;
typedef long long i64;
typedef unsigned long long ui64;
typedef vector<i64> vi;
typedef vector<vi> vvi;
typedef pair<i64, i64> pi;
#define pb push_back
#define sz(a) i64((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)
inline void RI(i64 &i) {scanf("%lld", &(i));}
inline void RVI(vi &v) { for(i64 i=0;i<sz(v);++i) { RI(v[i]); } }
inline void RVVI(vvi &vv) { for(i64 i=0;i<sz(vv);++i) { RVI(vv[i]); } }
inline void WI(const i64 &i) {printf("%lld\n", i);}
inline void WVI(const vi &v, char sep=' ') { for(i64 i=0;i<sz(v);++i) { if(i != 0){ printf("%c", sep); } printf("%lld", v[i]);} printf("\n"); }
inline void WS(const string &s) { printf("%s\n", s.c_str()); }
inline void WB(bool b, const string &yes, const string &no) { if(b){ WS(yes);} else { WS(no);} }
inline void YESNO(bool b) { WB(b, "YES", "NO"); }
#define BUF_LENGTH 1000000
inline void RS(string &s) {static char buf[BUF_LENGTH]; scanf("%s", buf); s = buf;}
template<typename T> inline bool IN(T &S, const typename T::key_type &key) {
return S.find(key) != S.end();
}
struct BIT {
// definition
using size_type = long long; // must be signed
using value_type = int;
static value_type plus(value_type a, value_type b) {
return a + b;
}
const value_type identity = 0;
BIT(size_type N) : tree(N+1, identity) {
}
void add(size_type i, value_type x) {
++i; // convert to 1-based
while(i < tree.size()) {
tree[i] += x;
i += i & (-i);
}
}
value_type sum0(size_type i) {
// open boundary in 0-based index = close boundary in 1-based index
value_type ans = identity;
while(i > 0) {
ans += tree[i];
i -= i & (-i);
}
return ans;
}
value_type sum(size_type l, size_type r) {
return sum0(r) - sum0(l);
}
vector<value_type> tree;
};
int main(int argc, char *argv[]) {
i64 i, j, k;
i64 N; RI(N);
vi a(N); RVI(a);
BIT tree(N);
i64 T = 0;
REP(0, N, i) {
T += tree.sum(a[i], N);
tree.add(a[i], 1);
}
i64 T0 = T;
REP(0, N, i) {
cout << T << endl;
T -= a[i];
T += (N - 1 - a[i]);
}
assert(T == T0);
return 0;
}
|
#include <bits/stdc++.h>
#define int long long
using namespace std;
inline int read(){
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-')w=-1;ch=getchar();
}
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s*w;
}
inline bool read(int& a){
int s=0,w=1;
char ch=getchar();
if(ch==EOF){
return false;
}
while(ch<'0'||ch>'9'){
if(ch=='-')w=-1;ch=getchar();
}
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
a=s*w;
return true;
}
inline void write(int x){
if(x<0) putchar('-'),x=-x;
if(x>9) write(x/10);
putchar(x%10+'0');
}
inline void writeln(int x){
if(x<0) putchar('-'),x=-x;
if(x>9) write(x/10);
putchar(x%10+'0');
puts("");
}
signed main(){
char c[10];
for(int i=1;i<=3;i++)
c[i]=getchar();
if(c[1]==c[2]&&c[2]==c[3])
puts("Won");
else
puts("Lost");
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
vector<int> a(n), b(n);
for(int i = 0; i < n; i++)
scanf("%d", &a[i]);
for(int i = 0; i < n; i++)
scanf("%d", &b[i]);
int ans = 0;
for(int i = 0; i < n; i++) {
ans += (a[i] * b[i]);
}
if(ans == 0)
cout << "Yes" << endl;
else
cout << "No" << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(ll i=0;i<(ll)n;i++)
#define dump(x) cerr << "Line " << __LINE__ << ": " << #x << " = " << (x) << "\n";
#define spa << " " <<
#define fi first
#define se second
#define ALL(a) (a).begin(),(a).end()
#define ALLR(a) (a).rbegin(),(a).rend()
using ld = long double;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;
template<typename T> using V = vector<T>;
template<typename T> using P = pair<T, T>;
template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){os << "(" << v.first << ", " << v.second << ")"; return os;}
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<vector<T>> &v){ for(auto &e : v){os << e << "\n";} return os;}
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template <class T> void UNIQUE(vector<T> &x) {sort(ALL(x));x.erase(unique(ALL(x)), x.end());}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
void fail() { cout << -1 << '\n'; exit(0); }
inline int popcount(const int x) { return __builtin_popcount(x); }
inline int popcount(const ll x) { return __builtin_popcountll(x); }
template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<"\n";}};
template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0];
for(ll i=1;i<n;i++)cerr spa v[i];
cerr<<"\n";};
const ll INF = (1ll<<62);
// const ld EPS = 1e-10;
// const ld PI = acos(-1.0);
const ll mod = (int)1e9 + 7;
//const ll mod = 998244353;
int main(){
ll R, X, Y;
cin >> R >> X >> Y;
ll D = X*X + Y*Y;
ll E = R * R;
if(D == E){
cout << 1 << endl;
return 0;
}
if(D < E){
cout << 2 << endl;
return 0;
}
ll P = (D+E-1)/E;
ll k = (ll)sqrt(P) - 2;
while(1){
if(k*k >= P) break;
k++;
}
cout << k << endl;
return 0;
} | //Template Made By: Ojassvi Kumar
#include<bits/stdc++.h>
using namespace std;
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long int
#define fo(i,a,b) for(long long int i=a; i<b; i++)
#define endl "\n"
#define max3(a,b,c) max(max((a),(b)),(c))
#define max4(a,b,c,d) max(max((a),(b)),max((c),(d)))
#define min3(a,b,c) min(min((a),(b)),(c))
#define min4(a,b,c,d) min(min((a),(b)),min((c),(d)))
#define pb push_back
#define lb lower_bound
#define up upper_bound
#define all(V) V.begin(),V.end()
#define itv vector<long long int>::iterator
#define pll pair<long long int,long long int>
#define mp make_pair
#define itp vector<pair<long long int,long long int>>::iterator
#define sll set<long long int,greater<long long int>>
#define its set<long long int,greater<long long int>>::iterator
#define d0(x) cout<<(x)<<" "
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
//const long double pi = 3.14159265358979323846264338;
//const long long int MOD=1000000007;
//Template Ends
int main(){
ios
ll Tests=1;
// cin>>Tests;
while(Tests--){
ll A,B,C;
cin>>A>>B>>C;
map<ll,ll> MA;
MA[1]=6;
MA[2]=5;
MA[3]=4;
MA[4]=3;
MA[5]=2;
MA[6]=1;
ll ans=MA[A]+MA[B]+MA[C];
cout<<ans<<endl;
}
}
|
#include<iostream>
#include<string>
using namespace std;
int main() {
long int n, x;
string s;
cin>>n>>x;
cin>>s;
for(int i = 0; i < s.size(); i++) {
if(s[i] == 'x' && x != 0)
x--;
else if(s[i] == 'o')
x++;
}
cout<<x<<endl;
return 0;
} | /*
मनस्वी म्रियते कामं कार्पण्यं न तु गच्छति ।
अपि निर्वाणमायाति नानलो याति शीतताम् ॥
*/
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
#define mod 1000000007
#define pb push_back
#define ll long long int
#define ull unsigned ll
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define v2i vector<vector<int>>
#define v2l vector<vector<ll>>
#define ppi pair<int,int>
#define ppl pair<ll,ll>
#define vpi vector<ppi>
#define vpl vector<ppl>
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#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 forv(i,m) for(auto i : m)
#define p2d(v) for(auto a:v){for(auto b:a)cout<<b<<" ";cout<<endl;}
#define p1d(v) for(auto a:v)cout<<a<<" ";cout<<endl;
#define ppd(v) for(auto a:v)cout<<a.ff<<" "<<a.ss<<endl;
#define imx INT_MAX
#define imn INT_MIN
#define inf 9000000000000000000
#define minf -inf
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse
#define itr iterator
#define pre cout<<fixed<<setprecision(10);
#define umap unordered_map
#define uset unordered_set
#define pi 3.141592653589793
#define MAXN 100005
#define test1(x) cout << #x " = " << x << endl;
#define test2(x,y) cout << #x " = " << x << " " << #y " = " << y << endl;
#define test3(x,y,z) cout << #x " = " << x << " " << #y " = " << y << " " << #z " = " << z << endl;
#define test4(w,x,y,z) cout << #w " = " << w << " " << #x " = " << x << " " << #y " = " << y << " " << #z " = " << z << endl;
#define oset tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
/*
const ll infinity = 9e18;
bool compare(ll a,ll b) {return a > b;}
bool compare1(ppl a,ppl b) {return a.ff > b.ff;}
bool compare2(ppl a,ppl b) {return a.ss < b.ss;}
bool isprime(ll n){if(n < 2) return 0; ll i = 2; while(i*i <= n){if(n%i == 0) return 0; i++;} return 1;}
ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md = mod) {ll product = 1; while(b){if(b&1){product = (product*a)%md;}a = (a*a)%md;b = b>>1;} return product%md;}
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }
*/
int main()
{
fast
/*
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
//*/
ll n,x;
cin>>n>>x;
string s;
cin>>s;
for(int i = 0; i < n; i++)
{
if(s[i] == 'x')
{
x = max(0LL,x-1);
}
else
{
x = max(0LL,x+1);
}
}
cout<<x;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int n;
main()
{
cin>>n;
cout<<(n+99)/100<<endl;
}
| #include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
// Your code here!
long N;
long ans = 1000;
for(int i = 1; i <= 4; i++)
{
scanf("%ld",&N);
ans = (ans>N)? N:ans;
}
printf("%ld\n",ans);
}
|
#include<bits/stdc++.h>
//=====================START-MACRO=====================
namespace gengar
{
#pragma GCC optimize("Ofast")
using namespace std;
namespace TypeDef
{
#define int long long
#define itn int
#define uint unsigned long long
using Int=int64_t;
using uInt=uint64_t;
#define ld long double
#define P pair<int,int>
#define vt(tp) vector<tp>
#define vvt(nm,tp,h,w,n) vector<vector<tp>>nm((h),vector<tp>(w,n))
#define vvp vector<vector<P>>
#define hmap unordered_map
#define hset unordered_set
#define PQ priority_queue
};
namespace OthDef
{
#define all(x) x.begin(),x.end()
#define nsort(x) sort(all(x))
#define rsort(x) nsort(x);reverse(all(x))
#define unq(v) v.erase(unique(all(v)),v.end())
#define l_b(c,x) distance(c.begin(),lower_bound(all(c),(x)))
#define u_b(c,x) distance(c.begin(),upper_bound(all(c),(x)))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define spc ' '
#define pass
void CIN(){}
template<typename Car,typename... Cdr>
void CIN(Car&&car,Cdr&&...cdr){cin>>car;CIN(forward<Cdr>(cdr)...);}
template<class T>void drop(T x){cout<<(x)<<endl;exit(0);}
void dYes(){puts("Yes");exit(0);}
void dNo(){puts("No");exit(0);}
#define Bit(n) (1LL<<(n))
#define Bitall(n,i) for(int bit=0;bit<(1<<(int)(n));bit++)for(int i=0;i<(int)(n);i++)
#define Bitif(i) if(bit&(1<<i))
};
namespace RepDef
{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(a),__SIZE##_=(b);i<__SIZE##_;i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,n) for(int i=1,__SIZE##_=(n);i<__SIZE##_;i++)
#define repp(i,n) for(int i=0,__SIZE##_=(n);i<=__SIZE##_;i++)
#define per(i,n) for(int i=(n)-1;i>=0;i--)
#define pper(i,n) for(int i=(n)-1;i>=1;i--)
#define perr(i,n) for(int i=(n);i>=0;i--)
};
namespace MathDef
{
const int inf=Bit(60);
const int pi=acos(-1);
const int mod=1000000007;//998244353
#define myceil(a,b) ((a)+((b)-1))/(b)
#define scale(n) cout<<fixed<<setprecision(n)
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
int fact(int n){int f=n;pper(i,n){f*=i;f%=mod;}return f;}
template<class T>int chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>int chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
};
namespace AllDef
{
using namespace TypeDef;
using namespace OthDef;
using namespace RepDef;
using namespace MathDef;
};
using namespace AllDef;
};
using namespace gengar;
//=======================END-MACRO=======================
namespace AHC001
{
//=====================START-AHC001======================
double dst(double a,double b,double c,double d)
{
double ret=sqrt(pow(double(c)-double(a),2)+pow(double(d)-double(b),2));
return ret/2/sqrt(2);
}
void solve()
{
int n;cin>>n;
vector<double>a(n),b(n),r(n);
rep(i,n)cin>>a[i]>>b[i]>>r[i];
double dist[200];
rep(i,200)dist[i]=inf;
//ここまで入力とか
//dist計算
rep(i,n)for(int j=0;j<n;j++)
{
if(j==i)continue;
chmin(dist[i],dst(a[i],b[i],a[j],b[j]));
}
rep(i,n)
{
double lpdist=dist[i];
if(dist[i]*dist[i]>r[i]/4)lpdist=(sqrt(r[i]))/2;
cout<<(int)(max(a[i]-lpdist+0.5,0.0))<<spc;
cout<<(int)(max(b[i]-lpdist+0.5,0.0))<<spc;
cout<<(int)(min(a[i]+lpdist+0.5,10000.0))<<spc;
cout<<(int)(min(b[i]+lpdist+0.5,10000.0))<<endl;
}
exit(0);
}
//=====================END-AHC001======================
};
using namespace AHC001;
int32_t main()
{
ios::sync_with_stdio(false);
cin.tie(0);
solve();
return 0;
}
| #include <bits/stdc++.h>
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define RI register int
typedef long long LL;
#define FILEIO(name) freopen(name".in", "r", stdin), freopen(name".out", "w", stdout);
using namespace std;
namespace IO {
char buf[1000000], *p1 = buf, *p2 = buf;
inline char gc() {
if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin);
return p1 == p2 ? EOF : *(p1++);
}
template <class T> inline void read(T &n) {
n = 0; RI ch = gc(), f;
while ((ch < '0' || ch > '9') && ch != '-') ch = gc();
f = (ch == '-' ? ch = gc(), -1 : 1);
while (ch >= '0' && ch <= '9') n = n * 10 + (ch ^ 48), ch = gc();
n *= f;
}
char Of[105], *O1 = Of, *O2 = Of;
template <class T> inline void print(T n, char ch = '\n') {
if (n < 0) putchar('-'), n = -n;
if (n == 0) putchar('0');
while (n) *(O1++) = (n % 10) ^ 48, n /= 10;
while (O1 != O2) putchar(*(--O1));
putchar(ch);
}
}
using IO :: read;
using IO :: print;
int const mod = 1e9 + 7;
int f[1005];
int main() {
#ifdef LOCAL
FILEIO("a");
#endif
int n; cin >> n;
char AA; cin >> AA;
char AB; cin >> AB;
char BA; cin >> BA;
char BB; cin >> BB;
f[n - 2] = 1;
for (RI i = n - 2; i; --i) {
if (AB == 'A') {
if (AA == 'B') {
if (i - 2 >= 0)
f[i - 2] = (f[i - 2] + f[i]) % mod;
if (BA == 'B')
for (RI j = i - 3; j >= 0; --j)
f[j] = (f[j] + f[i]) % mod;
}
f[i - 1] = (f[i - 1] + f[i]) % mod;
}
else {
if (BB == 'A') {
if (i - 2 >= 0)
f[i - 2] = (f[i - 2] + f[i]) % mod;
if (BA == 'A')
for (RI j = i - 3; j >= 0; --j)
f[j] = (f[j] + f[i]) % mod;
}
f[i - 1] = (f[i - 1] + f[i]) % mod;
}
}
cout << f[0] << endl;
return 0;
}
// created by Daniel yuan
/*
________
/ \
/ / \ \
/ / \ \
\ /
\ ______ /
\________/
*/
|
#include <iostream>
using namespace std;
const int N = 1000010;
typedef long long LL;
LL f[N];
LL ans = 0;
int main() {
int l, r;
cin >> l >> r;
for (int i = r; i >= 2; i --) {
LL tem = r / i - (l - 1) / i;
f[i] = tem * tem;
for (int j = i * 2; j <= r; j += i)
f[i] -= f[j];
ans += f[i];
//cout << i << ' ' << f[i] << endl;
}
for (int i = max(l, 2); i <= r; i ++) {
LL tem = 0;
for (int j = i; j <= r; j += i) {
tem ++;
}
ans -= tem * 2 - 1;
}
cout << ans;
}
| #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T> using indexed_set = tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>;
template <typename T> using indexed_multiset = tree<T, null_type,less_equal<T>, rb_tree_tag,tree_order_statistics_node_update>;
#define int long long
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define vii vector<pii>
#define mii map<int,int>
#define rep(i, begin, end) for (int i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define pb push_back
#define mp make_pair
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define endl "\n"
#define ff first
#define ss second
#define PI 3.14159265358979323846
#define forn(i, n) for (int i = 0; i < (int)n; ++i)
#define bit(x,j) ((x>>j)&1)
#define sz(a) (int)((a).size())
#define PRINT(v) for(auto t:v) cout<<t<<" ";cout<<endl;
#define PRINTDP(v) for(auto t:v){for(auto u:t){ cout<<u<<" ";} cout<<endl;}
#define PRINTM(mpp) for(auto t:mpp) cout<<t.ff<<" "<<t.ss<<endl;
#define read(v,n) vector<int> v(n); rep(i,0,n) cin>>v[i];
const int MOD=1e9+7 ;
const int MOD2=998244353;
const int INF=1e18+5;
int nCr(int n, int k) { if(k>n) return 0; double res = 1; for (int i = 1; i <= k; ++i) res = res * (n - k + i) / i; return (int)(res + 0.01); }
int gcd(int a,int b){ return b? gcd(b,a%b):a; }
template<typename T,typename T1>T amax(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T amin(T &a,T1 b){if(b<a)a=b;return a;}
template<typename T,typename T1>T add_self(T &a,T1 b,T m=MOD){return a=((a%m+b%m)%m);}
const int N= 1e6+5;
int mob[N+2];
vector<int> primes;
int lp[N+1];
void linear_sieve(){
for(int i=2;i<=N;i++){
if(lp[i]==0){
lp[i]=i;
primes.push_back(i);
}
for(int j=0;j<sz(primes) && primes[j]<=lp[i] && i*primes[j]<=N;j++)
lp[i * primes[j]] = primes[j];
}
}
void precompute(){
mob[1]=1;
rep(i,2,N+1){
mob[i] = [](int x){
int cnt=0;
while(x>1){
int p=lp[x];
int k=0;
while(x%p==0){
x/=p;
k++;
}
if(k>1) return 0;
++cnt;
}
if(cnt & 1)
return -1;
else
return 1;
}(i);
}
}
void solve(){
int l,r;
cin>>l>>r;
if(l==1) l++;
int ans=0;
rep(g,2,N){
int cnt= r/g - (l-1)/g; // Coprime pairs in [l,r]
ans -= mob[g]*cnt*cnt;
}
// Removing pairs such as (x,kx) and (kx,x)
rep(i,l,r+1){
for(int j=i;j<=r;j+=i){
ans--;
if(i!=j)
ans--;
}
}
cout<<ans<<endl;
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.precision(17);
int t=1;
linear_sieve();
precompute();
// cin>>t;
while(t--)
solve();
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define fi first
#define se second
#define UP(a,b,c) for(ll (a)=(b);(a)<(c);(a)++)
#define UU(a,b,c) for(ll (a)=(b);(a)<=(c);(a)++)
#define DN(a,b,c) for(ll (a)=(b);(a)>(c);(a)--)
#define DU(a,b,c) for(ll (a)=(b);(a)>=(c);(a)--)
ll n, k, c[18], u, v, m;
vector<int> edge[100005];
int bitOf[100005];
ll DP[(1LL << 17)][18];
void reset()
{
UP(i, 0, 1LL << 17)
{
UP(j, 0, 17)
{
DP[i][j] = -1;
}
}
}
void input()
{
cin >> n >> m;
UU(i, 1, m)
{
cin >> u >> v;
edge[u].pb(v);
edge[v].pb(u);
}
cin >> k;
UP(i, 0, k)
{
cin >> u;
c[i] = u;
bitOf[u] = (1LL << i);
}
}
class Compare
{
public:
bool operator() (pair<int, pii> a, pair<int, pii> b)
{
if(a.fi == b.fi)
{
return __builtin_popcount(a.se.se) < __builtin_popcount(b.se.se);
}
return a.fi > b.fi;
}
};
bool vis[100005] = {0};
ll dist[20][20];
ll bfs(int now, int target)
{
bool vis[100005] = {0};
queue<int> q;
q.push(now);
for(int step = 0 ; !q.empty() ; step++)
{
int csz = q.size();
while(csz--)
{
int now = q.front();
q.pop();
vis[now] = true;
if(now == target)
{
return step;
}
UP(i, 0, edge[now].size())
{
if(vis[edge[now][i]] == false)
{
q.push(edge[now][i]);
vis[edge[now][i]] = true;
}
}
}
}
return INT_MAX;
}
ll dp(int now, int bit)
{
if(__builtin_popcount(bit) == k)
{
return 1;
}
else if(DP[bit][now] != -1) return DP[bit][now];
else
{
ll cost = INT_MAX;
UP(i, 0, k)
{
if(bit & (1LL << i)){}
else
{
cost = min(cost, dist[now][i] + dp(i, (bit | (1LL << i))));
}
}
cost = min(cost, (ll)INT_MAX);
return DP[bit][now] = cost;
}
}
void solve()
{
UU(j, 0, k)
{
UU(i, 0, k) dist[i][j] = INT_MAX;
}
UP(j, 0, k)
{
UP(i, j + 1, k)
{
dist[j][i] = dist[i][j] = bfs(c[i], c[j]);
}
}
ll ans = INT_MAX;
UP(i, 0, k)
{
ans = min(ans, dp(i, (1LL << i)));
}
if(ans == INT_MAX) ans = -1;
cout << ans << endl;
}
void LetsRock()
{
solve();
}
int main()
{
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
reset();
input();
LetsRock();
return 0;
}
| #include<bits/stdc++.h>
using namespace std ;
const long long INF =1001001001 ;
//巡回セールスマン問題
//要解き直し
int main(){
int N , M ;
cin >> N >> M ;
vector<vector<int > > to(N) ;
for(int i = 0 ; i < M ; i++){
int a , b ;
cin >> a >> b ;
a-- ;
b-- ;
to.at(a).push_back(b) ;
to.at(b).push_back(a) ;
}
int K ;
cin >> K ;
vector<int > C(K) ;
for(int i = 0 ; i < K ; i ++){
cin >> C.at(i) ;
C.at(i)-- ;
}
vector<vector<int > > dist(K , vector<int >(K)) ; //dist.at(i).at(j) = distance of i - j
auto bfs = [&](int sv){
vector<int > dist(N , INF) ;
queue<int > q ;
dist.at(sv) = 0 ;
q.push(sv) ;
while(!q.empty()){
int v = q.front() ;
q.pop() ;
for(int u : to.at(v)){
if(dist.at(u) != INF) continue ;
dist.at(u) = dist.at(v) + 1 ;
q.push(u) ;
}
}
return dist ;
} ;
for(int i = 0 ; i < K ; i++){
vector<int> d = bfs(C.at(i)) ;
for(int j = 0 ; j < K ; j++){
dist.at(i).at(j) = d.at(C.at(j)) ;
}
}
int k2 = 1<<K ;
vector<vector<int > > dp(k2 , vector<int > (K,INF));
for(int i = 0 ; i < K ; i++){
dp.at(1<<i).at(i) = 1 ;
}
for(int s = 0 ; s < k2 ; s++){
for(int i = 0 ; i < K ; i++){
if(!(s>>i&1)) continue ;
for(int j = 0 ; j < K ; j++){
if(s>>j&1) continue ;
dp.at(s|1<<j).at(j) = min(dp.at(s|1<<j).at(j) , dp.at(s).at(i) + dist.at(i).at(j)) ;
}
}
}
int ans = INF ;
for(int i = 0 ; i < K ; i++){
ans = min(ans , dp.at(k2-1).at(i)) ;
}
if(ans == INF) cout << -1 << endl;
else cout << ans << endl;
} |
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int x,y;
void solve()
{
cin>>x>>y;
int low=min(x,y);
int high=max(x,y);
low+=3;
if(low<=high)
cout<<"No";
else
cout<<"Yes";
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
solve();
return 0;
} | #include<bits/stdc++.h>
using namespace std;
signed main()
{
int a,b,x,y; cin >> a >> b;
x = (a+b)/2;
y = a-x;
cout << x << " " << y;
} |
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ull unsigned long long
#define ll long long
#define M 998244353
#define pb push_back
#define p_q priority_queue
#define pii pair<ll,ll>
#define vi vector<ll>
#define vii vector<pii>
#define mi map<ll,ll>
#define mii map<pii,ll>
#define all(a) (a).begin(),(a).end()
#define sz(x) (ll)x.size()
#define endl '\n'
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b)) / gcd((a),(b))
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second
#define rep(i, begin, end) for (int i=begin;i<end;i++)
#define repd(i, begin, end) for (int i=end-1;i>=begin;i--)
#define ini(a,n,b) for(ll int i=0;i<n;i++) a[i]=0;
#define cset(a) __builtin_popcountll(a)
#define hell 1000000007
#define re resize
const int INF=1e18;
const int N=3e5+5;
int powm(int a,int b,int c)
{
int res=1;
while(b)
{
if(b&1)
res=(res*a)%c;
a=(a*a)%c;
b>>=1;
}
return res;
}
int pow(int a,int b)
{
int res=1;
while(b)
{
if(b&1)
res=(res*a);
a=(a*a);
b>>=1;
}
return res;
}
signed main(void)
{ios
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);freopen("answer.txt", "w", stdout);
#endif
int n,m;
cin>>n>>m;
int p=powm(10,n,m*m);
int ans=(p/m)%m;
cout<<ans<<endl;
} | #include<bits/stdc++.h>
#define int long long
#define inf 999999999999
#define N 100000
using namespace std;
int n,dp[N+1],g[27];
string s;
signed main(){
// freopen("optimize0.in","r",stdin);
// freopen("optimize.out","w",stdout);
cin>>n;
cin>>s;
for(int i=1;i<=n;i++)dp[i]=inf;
for(int i=0;i<26;i++)g[i]=inf;
for(int i=1;i<=n;i++){
g[s[i-1]-'a']=min(g[s[i-1]-'a'],dp[i-1]);
for(int j=0;j<26;j++){
if(j!=s[i-1]-'a')dp[i]=min(dp[i],g[j]);
}
dp[i]++;
}
if(dp[n]<inf)cout<<dp[n]<<endl;
else cout<<-1<<endl;
return 0;
}
/*
*/ |
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
//ios_base::sync_with_stdio(0);
//cin.tie(0);
string s;
cin >> s;
int e = 0;
for (int i = s.size()-1; i >= 0; --i) {
if (s[i] != '0') {
e = i;
break;
}
}
bool ans = true;
for (int i = 0; i < (e+1)/2 && ans; ++i) {
if (s[i] != s[e-i]) ans = false;
}
if (ans) cout << "Yes";
else cout << "No";
return 0;
}
| #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>
#include <climits>
#include <cstring>
#include <cassert>
using namespace std;
//using namespace atcoder;
#define REP(i, n) for (int i=0; i<(n); ++i)
#define RREP(i, n) for (int i=(int)(n)-1; i>=0; --i)
#define FOR(i, a, n) for (int i=(a); i<(n); ++i)
#define RFOR(i, a, n) for (int i=(int)(n)-1; i>=(a); --i)
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl;
template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
os << "[";
REP(i, SZ(v)) {
if (i) os << ", ";
os << v[i];
}
return os << "]";
}
template<class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
return os << "(" << p.first << " " << p.second << ")";
}
template<class T>
bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template<class T>
bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return true;
}
return false;
}
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;
const ll MOD = 1e9 + 7;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
const ld eps = 1e-9;
// edit
void solve() {
string s;
cin >> s;
if (s == "0") {
cout << "Yes" << endl;
return;
}
while (s.back() == '0') {
s.pop_back();
}
string t = s;
reverse(ALL(t));
if (s == t) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
// std::ifstream in("input.txt");
// std::cin.rdbuf(in.rdbuf());
solve();
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i, f, n) for (ll i = (f); i < (ll)(n); i++)
#define repe(i, f, n) for (ll i = (f); i <= (ll)(n); i++)
using namespace std;
using ll = long long;
using pint = pair<int, int>;
template <class T>
void chmin(T& a, T b) {
if (a > b) a = b;
}
template <class T>
void chmax(T& a, T b) {
if (a < b) a = b;
}
int main() {
int n;
cin >> n;
vector<int> a(n);
rep(i, 0, n) cin >> a[i];
ll ans = 0;
rep(l, 0, n) {
int x = a[l];
rep(r, l, n) {
chmin(x, a[r]);
chmax(ans, x * (r - l + 1));
}
}
cout << ans << endl;
return 0;
}
| #include<iostream>
#include<string>
#include<algorithm>
#include<unordered_set>
using namespace std;
long long hasht[26];
void toZ(){
for(int i=0;i<26;i++)
hasht[i]=0;
}
long long getC(char c){
long long cnt=0;
for(int i=0;i<26;i++){
if('a'+i!=c)cnt+=hasht[i];
}
toZ();
return cnt;
}
int main(){
string s;
long long cnt=0;
cin>>s;
reverse(s.begin(),s.end());
int n=s.size();
int last=-1;
char cc='W';
hasht[s[0]-'a']++;
hasht[s[1]-'a']++;
for(int i=2;i<n;i++){
if(s[i]==s[i-1]&&s[i-1]!=s[i-2]){
cnt+=getC(s[i]);
if(cc!=s[i]){
cnt+=last+1;
}
last=i;
cc=s[i];
}else{
hasht[s[i]-'a']++;
}
}
cout<<cnt;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mat vector<vector<int>>
#define vi vector<int>
#define ff first
#define ss second
#define ll long long
#define pb push_back
#define pi pair<int, int>
#define inf 1000000000
#define mod 1000000007
//#define endl "\n"
const ll INF=1e18+5;
const int naxN=2e1+5;
int fact[naxN], inv_fact[naxN];
int power(int a, int n){
int res=1;
while(n){
if(n%2) res=(res*a)%mod, n--;
else a=(a*a)%mod, n/=2;
}
return res%mod;
}
void init(){
fact[0]=inv_fact[0]=1;
for(int i=1; i<naxN; i++){
fact[i]=(i*fact[i-1])%mod;
inv_fact[i]=power(fact[i], mod-2)%mod;
}
}
int ncr(int a, int b){
if(a<0 || b<0 || a<b) return 0;
return (fact[a]%mod*inv_fact[b]%mod*inv_fact[a-b]%mod)%mod;
}
int dx[8]={-1, -1, -1, 0, 1, 1, 1, 0};
int dy[8]={-1, 0, 1, 1, 1, 0, -1, -1};
int par[30];
int R[30];
int find(int a){
if(par[a]<0) return a;
return par[a]=find(par[a]);
}
void merge(int a, int b){
a=find(a);
b=find(b);
if(a==b) return;
if(R[a]>=R[b]){
par[b]=a;
R[a]+=R[b];
}
else{
par[a]=b;
R[b]+=R[a];
}
}
//****DO NOT TOUCH ABOVE THIS LINE****//
//#define kk
const int maxN=1e5+5;
void solve(){
int a, b;
cin>>a>>b;
long double ans=(long double)(a-b)/a;
ans*=100;
cout<<ans<<endl;
}
//****DO NOT TOUCH BELOW THIS LINE****//
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cout<<fixed<<setprecision(18);
#ifdef kk
freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
#endif
//preprocess();
int T=1;
//cin>>T;
while(T--){
solve();
}
}
| #include <bits/stdc++.h>
using namespace std;
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
using ll = long long;
#define pint pair<int, int>
#define pll pair<ll, ll>
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;
int main() {
int n;
cin >> n;
ll a[n];
rep(i, n) cin >> a[i];
ll ans = 0;
rep(left, n) {
int right = left + 1;
ll len = 1;
ll m = a[left];
while (right < n) {
ans = max(ans, m * len);
m = min(m, a[right]);
right++;
len++;
}
ans = max(ans, m * len);
}
cout << ans << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int main() {
int h,w,a,b,num=0,id1,id2;
cin>>h>>w>>a>>b;
int s=(h*(w-1))+(w*(h-1));
for (int i=0;i<(1<<s);i++){
set<int> m;
bool e=false;
int t_num=0;
for (int j=0;j<s;j++){
if(i&(1<<j))t_num++;
}
if (t_num!=a)continue;
for (int j=0;j<s;j++){
if(i&(1<<j)){
if(j<(w*(h-1))){
id1=j;
id2=id1+w;
if(m.count(id1)||m.count(id2)) e=true;
else{
m.insert(id1);
m.insert(id2);
}
}
else{
id1=(j-w*(h-1))+(j-w*(h-1))/(w-1);
id2=id1+1;
if(m.count(id1)||m.count(id2)) e=true;
else{
m.insert(id1);
m.insert(id2);
}
}
}
}
if (!e) num++;
}
cout<<num<<endl;
} | // execute g++ main.cpp -std=c++14 -I C:\Users\naoya\Desktop\code\Atcoder
#include<bits/stdc++.h>
//#include<atcoder/all>
typedef long long ll;
typedef long double ld;
using namespace std;
//using namespace atcoder;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
//ordered_set 重複不可
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// use set_function + find_by_order(select itr-num)
#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back
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;}
template<class T>inline bool chmax(T &a, T b) {if(a < b) {a = b;return true;}return false;}
template<class T>inline bool chmin(T &a, T b) {if(a > b) {a = b;return true;}return false;}
char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
char Alpha[26] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
int dx[2] = {1, 0};
int dy[2] = {0, 1};
//cout << std::fixed << std::setprecision(15) << y << endl; //小数表示
int h, w, a, b;
vector<vector<vector<Pii>>> gridmemo;
vector<vector<vector<Pii>>> gridmemo2;
void solve(vector<vector<Pii>> grid, int x, int y, int count){
if(x+1 == h && y+1 == w){
if(count == a){
gridmemo.pb(grid);
}else{
return;
}
}else if(x+1 == h){
solve(grid, 0, y+1, count);
}else{
solve(grid, x+1, y, count);
}
REP(i,0,2){
int nx = x + dx[i], ny = y+dy[i];
if(nx >= 0 && nx < h && ny >= 0 && ny < w && grid[nx][ny] == Pii(-1, -1) && grid[x][y] == Pii(-1, -1)){
grid[x][y] = Pii(nx, ny);
grid[nx][ny] = Pii(x, y);
if(x+1 == h && y+1 == w){
if(count+1 == a){
gridmemo.pb(grid);
}else{
return;
}
}else if(x+1 == h){
solve(grid, 0, y+1, count+1);
}else{
solve(grid, x+1, y, count+1);
}
grid[x][y] = Pii(-1, -1);
grid[nx][ny] = Pii(-1, -1);
}
}
}
int main(){
cin >> h >> w >> a >> b;
vector<vector<Pii> > grid(h, vector<Pii>(w, Pii(-1, -1)));
int ans = 0;
solve(grid, 0, 0, 0);
/*
REP(i, 0, gridmemo.size()){
REP(x, 0,h){
REP(y, 0, w){
cout << gridmemo[i][x][y] << " ";
}
cout << endl;
}
cout << endl;
}
*/
REP(i,0,gridmemo.size()){
int flag = 1;
REP(l, 0, gridmemo2.size()){
int f = 1;
REP(x, 0, h){
REP(y, 0, w){
if(gridmemo[i][x][y] != gridmemo2[l][x][y]){
f = 0; //OK
}
}
}
if(f){
flag = 0;
}
}
if(flag){
gridmemo2.pb(gridmemo[i]);
}
ans += flag;
}
cout << ans << endl;
} |
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;
ll d[1111][1111];
void init(ll n,ll m) {
rep(i,n+1)rep(j,m) d[i][j+1]+=d[i][j];
rep(j,m+1)rep(i,n) d[i+1][j]+=d[i][j];
}
ll calc(ll x1,ll y1,ll x2,ll y2) {return d[x2][y2]-d[x1][y2]-d[x2][y1]+d[x1][y1];}
void Main() {
ll n,k;
cin >> n >> k;
ll a[n][n];
rep(i,n)rep(j,n) R a[i][j];
ll l=-1,r=MAX,e=k*k/2+1;
while(l+1<r) {
ll m=(l+r)/2;
rep(i,n+1)rep(j,n+1) d[i][j]=0;
rep(i,n) {
rep(j,n) {
if(a[i][j]>=m) d[i+1][j+1]++;
}
}
init(n,n);
ll f=1;
rep(i,n-k+1) {
rep(j,n-k+1) {
ll c=calc(i,j,i+k,j+k);
if(c<e) f=0;
}
}
if(!f) r=m;
else l=m;
}
pr(l);
}
int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}
| #include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
int main(void)
{
IOS
int n, m;
cin >> n >> m;
vector<ll> h(n), w(m);
REP(i,n) cin >> h[i];
REP(i,m) cin >> w[i];
sort(ALL(h));
sort(ALL(w));
vector<ll> h2(n);
REP(i,n-1) h2[i] = h[i+1] - h[i];
vector<ll> hsumf(n), hsumb(n);
for(int i = 0; i < n; i += 2) hsumf[i+2] = hsumf[i] + h2[i];
for(int i = n-1; i > 0; i -= 2) hsumb[i-2] = hsumb[i] + h2[i-1];
ll ans = 1e18;
for(int i = 0; i < n ; i += 2) {
auto it = lower_bound(ALL(w),h[i]);
ll hw = abs(*it - h[i]);
if (it != w.begin()) {
it--;
hw = min(hw, abs(h[i]-*it));
}
ll tmp = hw + hsumf[i] + hsumb[i];
ans = min(ans,tmp);
}
cout << ans << '\n';
return 0;
} |
#include <iostream>
using namespace std;
typedef long long ll;
#define min(x,y) ((x)<(y)?(x):(y))
#define max(x,y) ((x)<(y)?(y):(x))
ll comb(ll n, ll k){
if (k == 0 || k == n) return 1;
if (k == 1 || k == n-1) return n;
return comb(n-1,k)+comb(n-1,k-1);
}
int main(){
ll n,k;cin >> n >> k;--k;
for(ll xyz=3;xyz<=3*n;++xyz){
if(xyz <= n+1){
ll xmin = 1;
ll xmax = xyz-2;
if (xmin <= xmax){
ll s = ((xyz-1-xmax)+(xyz-1-xmin))*(xmax-xmin+1)/2;
if(s <= k){
k -= s;
}else{
for(ll x=xmin;x<=xmax;++x){
ll c = xyz-1-x;
if(c <= k){
k -= c;
continue;
}
ll y=1+k;
ll z=xyz-x-y;
cout << x << " " << y << " " << z << "\n";
return 0;
}
}
}
}else if(xyz < 2*n+1){
{
ll xmin = 1;
ll xmax = xyz-n-1;
if(xmin <= xmax){
ll s = ((n-(xyz-n-xmax)+1)+(n-(xyz-n-xmin)+1))*(xmax-xmin+1)/2;
if(s <= k){
k -= s;
}else{
for(ll x=xmin;x<=xmax;++x){
ll c = n-(xyz-n-x)+1;
if(c <= k){
k -= c;
continue;
}
ll y=xyz-n-x+k;
ll z=xyz-x-y;
cout << x << " " << y << " " << z << "\n";
return 0;
}
}
}
}
{
ll xmin = xyz-n;
ll xmax = n;
if (xmin <= xmax){
ll s = ((xyz-1-xmax)+(xyz-1-xmin))*(xmax-xmin+1)/2;
if(s <= k){
k -= s;
}else{
for(ll x=xmin;x<=xmax;++x){
ll c = xyz-1-x;
if(c <= k){
k -= c;
continue;
}
ll y=1+k;
ll z=xyz-x-y;
cout << x << " " << y << " " << z << "\n";
return 0;
}
}
}
}
}else{
ll xmin = xyz-2*n;
ll xmax = n;
ll s = ((n-(xyz-n-xmax)+1)+(n-(xyz-n-xmin)+1))*(xmax-xmin+1)/2;
if(s <= k){
k -= s;
}else{
for(ll x=xmin;x<=xmax;++x){
ll c = n-(xyz-n-x)+1;
if(c <= k){
k -= c;
continue;
}
ll y=xyz-n-x+k;
ll z=xyz-x-y;
cout << x << " " << y << " " << z << "\n";
return 0;
}
}
}
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define mp make_pair
#define MOD(a, m) ((a % m + m) % m)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;
ll N, K;
int main(){
cin >> N >> K;
vector<vector<ll>> X(4, vector<ll>(3*N+1));
vector<vector<ll>> S(4, vector<ll>(3*N+1));
X[0][0] = 1;
REP(i,3){
S[i][0] = X[i][0];
REP(k,3*N){
S[i][k+1] = X[i][k+1] + S[i][k];
}
REPi(k,1,3*N+1){
//// X[][k] <= {X[][k-N] ... X[][k-1]}
X[i+1][k] = S[i][k-1];
if(k-N-1 >= 0)
X[i+1][k] -= S[i][k-N-1];
}
}
ll sum = 0;
ll num = -1;
REP(i,3*N+1){
auto tmp = X[3][i];
if(sum+tmp >= K){
num = i;
K -= sum;
break;
}
sum += tmp;
}
//cout << sum << endl;
//cout << num << endl;
ll left, mid;
bool valid = false;
for(left = 1; left <= N; left++){
ll rem = num - left;
if(rem < 0 || 3*N < rem) continue;
ll n = X[2][rem];
if(K > n){
K -= n;
}
else{
for(mid = 1; mid <= N; mid++){
ll rem2 = rem - mid;
if(rem2 < 0 || 3*N < rem2) continue;
ll n = X[1][rem2];
K -= n;
if(K == 0){
valid = true;
break;
}
}
}
if(valid)
break;
}
printf("%lld %lld %lld\n", left, mid, num - (left + mid));
return 0;
}
|
Subsets and Splits