code_file1
stringlengths 87
4k
| code_file2
stringlengths 82
4k
|
---|---|
#include<bits/stdc++.h>
#define inf INT_MAX
#define sc(a) scanf("%d",&a)
#define scc(a,b) scanf("%d %d",&a,&b)
#define sccc(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pf(a) printf("%d",a)
#define pff(a,b) printf("%d %d",a,b)
#define pfff(a,b,c) printf("%d %d %d",a,b,c)
#define pb(a) push_back(a)
#define em empty()
#define fr front()
#define cl clear()
#define sz size()
#define mp(a,b) make_pair(a,b)
#define fri(b) freopen(b,"r",stdin)
#define fro(b) freopen(b,"w",stdout)
using namespace std;
int sum1,sum2;
int main(){
//fri("gir.txt");
//fro("cik.txt");
int a,b;
cin>>a>>b;
sum1+=a%10;
sum2+=b%10;
a/=10;
b/=10;
sum1+=a%10;
sum2+=b%10;
a/=10;
b/=10;
sum1+=a%10;
sum2+=b%10;
cout<<max(sum1,sum2);
return 0;
}
| #pragma region Template
#pragma region Includes
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#pragma endregion Includes
#pragma region Setting
#pragma GCC optimize("Ofast")
#define FAST \
ios::sync_with_stdio(false); \
cin.tie(nullptr);
#pragma endregion Setting
#pragma region Defines
using LL = long long;
template<class T> using P = pair<T, T>;
template<class T> using VEC = vector<T>;
template<class T> using VEC2 = vector<vector<T>>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T, vector<T>, greater<T>>;
#define REP(i, m, n) for(int i = m; i < (int)(n); i++)
#define REPE(i, m, n) for(int i = m; i <= (int)(n); i++)
#define REPR(i, m, n) for(int i = m; i >= (int)(n); i--)
#define FORR(itr, dict) for(auto &itr : dict)
#define REPBIT(n) for(int bit = 0; bit < (1 << (int)(n)); bit++)
#define ALL(v) v.begin(), v.end()
#define SETPRE(n) cout << fixed << setprecision(n)
#define en '\n'
constexpr LL LLINF = LLONG_MAX;
constexpr int IINF = INT_MAX;
constexpr int MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
#pragma endregion Defines
#pragma region Functions
void string_lower(string &s, int n) {
if(s[n] >= 65 && s[n] <= 90) s[n] = s[n] + ('a' - 'A');
}
void string_upper(string &s, int n) {
if(s[n] >= 97 && s[n] <= 122) s[n] = s[n] - ('a' - 'A');
}
template<class T> inline void CO(T value) { cout << value << en; }
inline void CO(void) { cout << en; }
template<class T> inline void CON(T value) { cout << value; }
int ctoi(char c) {
if('0' <= c && c <= '9') return (c - '0');
else {
CO("ctoi error!");
return -1;
}
}
char itoc(int n) { return n + '0'; }
template<class T> inline bool chmin(T &a, T b) {
if(a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T &a, T b) {
if(a < b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool int_chk(T n) {
if(ceil(n) == floor(n)) return true;
return false;
}
#pragma endregion Functions
#pragma endregion Template
/* update 2021/02/17 */
////////////////////////////////////////////////////////////////////////////////////////////////////
void solve() {
int a, b, c;
cin >> a >> b >> c;
if(a != b && a != c && b != c) CO(0);
else {
if(a == b) {
CO(c);
return;
}
if(b == c) {
CO(a);
return;
} else if(c == a) {
CO(b);
return;
}
}
}
int main() {
FAST;
solve();
} |
#include<bits/stdc++.h>
#include<string>
#define FIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define ll long long
#define mod (ll)(1e9+7)
#define nax (ll)(1e5 + 10)
#define INFL LLONG_MAX
#define NINFL LLONG_MIN
#define INF INT_MAX
#define disp(a,n,arr) for(int i=a;i<(ll)n;i++) cout << arr[i] << " "; cout << "\n";
#define check cout << "Working\n";
#define pi pair<int,int>
#define pl pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define vpl vector<pl>
#define vpi vector<pi>
#define vb vector<bool>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(a) a.begin(),a.end()
using namespace std;
string sol(string number, int divisor)
{
string ans;
int idx = 0;
int temp = number[idx] - '0';
while (temp < divisor)
temp = temp * 10 + (number[++idx] - '0');
while (number.size() > idx) {
ans += (temp / divisor) + '0';
temp = (temp % divisor) * 10 + number[++idx] - '0';
}
if (ans.length() == 0)
return "0";
return ans;
}
int main() {
FIO;
int t = 1;
//cin >> t;
while(t--){
ll n;
cin >> n;
map<ll,ll> mpp;
ll ans = 0;
for(int i=0;i<n;i++){
ll a;
cin >> a;
ans += mpp[a%200];
mpp[a%200]++;
}
cout << ans << "\n";
}
return 0;
}
| #include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define debug(output) cout<<#output<<"= "<<output<<endl
using P=pair<int,int>;
using lint=long long;
using ll=long long;
const lint inf=1e18+7;
const int MOD=1000000007;
int n,l;
int calc(vector<int>& a,vector<int> b){
auto prev=a;
rep(i,n+1){
a[i]+=n-i;
}
int res=0;
int add=0;//a[i]からは引き、b[i]には足す
for(int i=n;i>0;--i){
auto it=upper_bound(a.begin(),a.end(),b[i]+add);
--it;
int ind=it-a.begin();
if(ind>i){
++add;
continue;
}
if(*it==b[i]+add){
int last=*it;
res+=i-ind;
while(*it!=a[i]){
++it;
*it=last;
}
a[i]=last;
}
else{
;
}
++add;
}
rep(i,n+1){
a[i]-=n-i;
}
return res;
}
signed main(){
cin>>n>>l;
lint res=0;
vector<lint> a(n+1,0),b(n+1,0);
rep1(i,n)cin>>a[i];
rep1(i,n)cin>>b[i];
a.push_back(l+1);
b.push_back(l+1);
res+=calc(a,b);
reverse(a.begin(),a.end());
reverse(b.begin(),b.end());
for(auto& val:a){
val=l+1-val;
}
for(auto& val:b){
val=l+1-val;
}
res+=calc(a,b);
rep1(i,n){
if(a[i]!=b[i])res=-1;
}
cout<<res<<"\n";
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<ll, ll>;
// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; debug_print(__VA_ARGS__); } while(false)
template<typename T, typename... Ts> void debug_print(const T &t, const Ts &...ts) { cerr << t; ((cerr << ", " << ts), ...); cerr << endl; }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, const T& b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, const T& b) { if (a < b) {a = b; return true; } return false; }
template<typename T, typename... Ts> void print(const T& t, const Ts&... ts) { cout << t; ((cout << ' ' << ts), ...); cout << '\n'; }
template<typename... Ts> void input(Ts&... ts) { (cin >> ... >> ts); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int a, b, c;
input(a, b, c);
if (a > b) swap(a, b);
if (b > c) swap(b, c);
if (a > b) swap(a, b);
if (a == b) {
print(c);
} else if (b == c) {
print(a);
} else {
print(0);
}
return 0;
}
| #include<iostream>
#include<vector>
#include<bits/stdc++.h>
using namespace std;
int main()
{
int x;
vector<int> a(3);
for(int i=0; i<3; i++) {
cin>>x;
a[i]=x;
}
sort(a.begin(),a.end());
if(a[0] == a[1])
cout<<a[2]<<endl;
else if(a[1] == a[2])
cout<<a[0]<<endl;
else if(a[0] == a[2])
cout<<a[1]<<endl;
else
cout<<"0"<<endl;
}
|
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) x.begin(),x.end()
#define pb push_back
#define po pop_back
#define pi(i, v) v[i]=v.back(); v.pop_back()
#define li long long
#define INF INT_MAX
// #define TEST_CASES
const int mod = 1e9 + 7;
void IO () {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
vector<vector<li>> dp;
li binomialCoeff(int n, int k)
{
if(dp[n][k] != -1) return dp[n][k];
if (k > n)
return dp[n][k] = 0;
if (k == 0 || k == n)
return dp[n][k] = 1;
return dp[n][k] = binomialCoeff(n - 1, k - 1)
+ binomialCoeff(n - 1, k);
}
void solve() {
// write your code here
for(auto &x: dp) x.clear();
int a, b;
li k;
cin >> a >> b >> k;
dp.resize(70, vector<li>(70, -1));
--k;
string answer;
int iter = a + b;
for(int i=0; i<iter; ++i) {
li study;
//cout << a << " " << b << endl;
if(dp[a+b-1][a-1] == -1) study = binomialCoeff(a+b-1, a-1);
else study = dp[a+b-1][a-1];
//cout << study << "-" << k << endl;
if(study > k) answer.push_back('a'), --a;
else answer.push_back('b'), k -= study, --b;
if(k <= 0) {
for(int i=0; i<a; ++i) answer.pb('a');
for(int i=0; i<b; ++i) answer.pb('b');
break;
}
if(a == 0) {
for(int i=0; i<b; ++i) answer.pb('b');
break;
}
if(b == 0) {
for(int i=0; i<a; ++i) answer.pb('a');
break;
}
}
/*for(int i=0; i<70; ++i) {
for(auto x: dp[i]) cout << x << ",";
cout << endl;
}*/
cout << answer << endl;
}
int main() {
fast;
IO();
#ifdef TEST_CASES
int T;
cin >> T;
while(T--)
#endif
solve();
}
| #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626
#define mod 1000000007
#define mod1 998244353
#define ms(arr, v) memset(arr, v, sizeof(arr))
#define fo1(i,a,b) for(int i=a;i<=b;i++)
#define deb(x) cout<<x<<"\n";
#define deB(x,y) cout<<x<<" "<<y<<"\n";
#define Deb(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define YES cout<<"YES\n";
#define Yes cout<<"Yes\n";
#define NO cout<<"NO\n";
#define No cout<<"No\n";
#define all(v) (v).begin(),(v).end()
#define mk(arr,n,type) type *arr=new type[n];
/*-------------------------------------------------------------------------------------------*/
ll mod_add(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;}
ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;}
ll mod_sub(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;}
/*--------------------------------------------------------------------------------------------*/
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
//ncr->pascals traingle
vector<vector<ll>> ncr(61, vector<ll>(61));
ncr[0][0] = 1;
for (ll n = 1; n < 61; n++) {
ncr[n][0] = 1;
for (ll r = 1; r < n; r++) {
ncr[n][r] = ncr[n - 1][r - 1] + ncr[n - 1][r];
}
ncr[n][n] = 1;
}
ll a, b, k;
cin >> a >> b >> k;
ll n = (a + b);
for (ll i = 0; i < n; i++) {
//If we put a at that position
// Now we find that at the remaining positions how many ways by which we can fill
ll x = ncr[a - 1 + b][b];
if (x >= k) {
cout << 'a';
a--;
} else {
cout << 'b';
b--;
k -= x;
}
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
#define F(index,start,end) for(ll index=start;index<end;++index)
#define IA(array,size) F(index,0,size) cin >> array[index]
#define IA2(array,height,width) F(i,0,height) F(j,0,width) cin >> array[i][j]
#define PA(array,size) F(index,0,size) cout << array[index] << " "; cout << endl
#define PA2(array,height,width) F(i,0,height) {F(j,0,width) cout << array[i][j]; cout << endl;}
#define P(str) cout << str << endl
constexpr int32_t MOD=1000000007;
int main(){
ll n,k;
cin>>n>>k;
if(k<0) k*=-1;
ll ans=0;
F(i,2,2*n+1){
ll j=i-k;
if(j<2) continue;
ll p=i-1,q=j-1;
if(p>n) p=2*n-p;
if(q>n) q=2*n-q;
ans+=p*q;
}
P(ans);
return 0;
} | #include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
#define Test(tt) cout << "Case #" << tt << ": "
using namespace std;
const int MOD = 998244353;
int main() {
#ifdef HOME
ifstream cin("A.in");
ofstream cout("A.out");
#endif
int n, k;
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n >> k;
k = abs(k);
auto get = [](int sum, int n) {
int l = max(sum - n, 1);
int r = min(sum - 1, n);
return r - l + 1;
};
ll ans = 0;
for(int suma = k + 2; suma <= 2 * n; suma++) {
ans += 1LL * get(suma, n) * get(suma - k, n);
}
cout << ans;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll cnt[2][200009];
ll vec[200009];
ll val[200009];
ll par[200009],lev[200009];
vector<pair<ll,ll> >tmp;
ll pp[70];
vector<pair<ll,ll>>ad[200009];
ll n;
ll M;
void dfs(ll a,ll p, ll t)
{
val[a]+=t;
ll b,i,l=ad[a].size();
for(i=0; i<l; i++)
{
b=ad[a][i].first;
if(b!=p)
{
dfs(b,a,val[a]);
}
}
}
void dfs2(ll a,ll p,ll c)
{
par[a]=p;
lev[a]=lev[p]+1;
vec[a]=c;
ll b,i,l=ad[a].size(),d;
for(i=0; i<l; i++)
{
b=ad[a][i].first;
d=ad[a][i].second;
if(b!=p)
{
dfs2(b,a,d);
}
}
}
ll call()
{
ll a,b,c,x,y,ans=0,m,i,j,l,o,z;
for(i=0; i<n; i++)
{
a=tmp[i].second;
o=z=0;
c=val[a]%2;
c=(c+1)%2;
ans+=cnt[c][a];
l=ad[a].size();
for(j=0; j<l; j++)
{
b=ad[a][j].first;
if(b!=par[a])
{
x=cnt[0][a]-cnt[0][b]-z;
y=cnt[1][b];
ans+=(x*y);
x=cnt[1][a]-cnt[1][b]-o;
y=cnt[0][b];
ans+=(x*y);
o+=cnt[1][b];
z+=cnt[0][b];
}
}
c=val[a]%2;
cnt[c][a]++;
b=par[a];
cnt[0][b]+=cnt[0][a];
cnt[1][b]+=cnt[1][a];
}
return ans;
}
int main()
{
ll a,b,c,d,e,i,j,k,l,m,x,y,t,p;
M=(1e9)+7;
pp[0]=1;
for(i=1; i<=61; i++)
{
pp[i]=pp[i-1]*2;
}
scanf("%lld",&n);
for(i=1; i<n; i++)
{
scanf("%lld%lld%lld",&a,&b,&c);
ad[a].push_back({b,c});
ad[b].push_back({a,c});
}
dfs2(1,0,0);
for(i=1; i<=n; i++)
{
tmp.push_back({lev[i],i});
}
sort(tmp.rbegin(),tmp.rend());
ll ans=0;
for(i=0; i<60; i++)
{
for(j=1; j<=n; j++)
{
if((vec[j]&pp[i])!=0)
{
val[j]=1;
}
else
{
val[j]=0;
}
cnt[0][j]=cnt[1][j]=0;
}
dfs(1,0,0);
x=call();
//cout<<x<<endl;
y=((x%M)*(pp[i]%M))%M;
ans=(ans+y)%M;
}
printf("%lld\n",ans);
}
| #include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
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);
}
#define int long long
#define pb push_back
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define precise(x) fixed << setprecision(x)
const int MOD = 1e9+7;
int mod_pow(int a,int b,int M = MOD)
{
if(a == 0) return 0;
b %= (M - 1); //M must be prime here
int res = 1;
while(b > 0)
{
if(b&1) res=(res*a)%M;
a=(a*a)%M;
b>>=1;
}
return res;
}
const int N = 2e5 + 10;
vector<pii> g[N];
int arr[N];
void dfs(int node,int par = -1,int val = 0)
{
if(par != -1)
{
arr[node] = val;
}
for(auto x : g[node])
{
if(x.F == par) continue;
dfs(x.F,node,val^x.S);
}
}
void solve()
{
int n;
cin >> n;
int u,v,w;
f(i,n-1)
{
cin >> u >> v >> w;
g[u].pb({v,w});
g[v].pb({u,w});
}
dfs(1);
vector<int> vs;
for(int i=1;i<=n;i++) vs.pb(arr[i]);
int res = 0;
f(j,60)
{
int c0 = 0;
int c1 = 0;
for(int i=0;i<n;i++)
if((vs[i] >> j) & 1) c1++;
else c0++;
int ways = (c0*c1);
ways %= MOD;
int pw = mod_pow(2,j);
ways*=pw;
ways%= MOD;
res+=ways;
res%=MOD;
}
res %= MOD;
cout <<res;
}
signed main()
{
fast;
int t = 1;
// cin >> t;
while(t--)
solve();
}
|
#include <bits/stdc++.h>
using namespace std;
#define MS(a, b) memset(a, b, sizeof(a))
#define REP(a, b, c) for (register int a = b, _n = c; a <= _n; ++a)
#define DREP(a, b, c) for (register int a = b, _n = c; a >= _n; --a)
#define FOR(a, b, c) for (register int a = b, _n = c; a < _n; ++a)
#define EREP(a, b) for (register int a = head[b]; a; a = edge[a].nxt)
inline int rd () {
int x = 0; char c = getchar(); bool f = 0;
while (c < '0' && c != '-') c = getchar();
if (c == '-') f = 1, c = getchar();
while (c >= '0') x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
return f ? -x : x;
}
const int SIZE = 2e5 + 100;
int n, K;
int head[SIZE], ecnt;
struct Edge {
int v, nxt;
} edge[SIZE << 1];
void Add_Edge (int u, int v) {
edge[++ecnt] = (Edge) { v, head[u] };
head[u] = ecnt;
}
int bz[SIZE][18], dep[SIZE];
void dfs (int u, int fa) {
bz[u][0] = fa;
dep[u] = dep[fa] + 1;
EREP (i, u) {
int v = edge[i].v;
if (v == fa) continue;
dfs(v, u);
}
}
int a[SIZE];
struct cmp {
bool operator () (const int& x1, const int& x2) const {
return dep[x1] > dep[x2];
}
};
int dis[SIZE], mid;
void Cover (int u) {
if (dis[u] == mid) return;
EREP (i, u) {
int v = edge[i].v;
if (dis[v] == -1 || dis[v] > dis[u] + 1) {
dis[v] = dis[u] + 1;
Cover(v);
}
}
}
void _main () {
n = rd(), K = rd();
FOR (i, 1, n) {
int u = rd(), v = rd();
Add_Edge(u, v);
Add_Edge(v, u);
}
dfs(1, 0);
REP (i, 1, n) a[i] = i;
sort(a + 1, a + n + 1, cmp());
REP (i, 1, 17) REP (j, 1, n)
bz[j][i] = bz[bz[j][i - 1]][i - 1];
int L = 1, R = n, res = n;
while (L <= R) {
mid = (L + R) >> 1;
int num = 0;
MS(dis, -1);
REP (i, 1, n) {
int u = a[i];
if (dis[u] == -1) {
++num;
DREP (j, 17, 0) if (1 << j & mid)
u = bz[u][j];
if (u == 0) u = 1;
dis[u] = 0;
Cover(u);
}
}
if (num <= K) res = mid, R = mid - 1;
else L = mid + 1;
}
cout << res << endl;
}
int main () {
_main();
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=(n)-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<unordered_setprecision(x)
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,1,0,-1,1,-1,1,-1};
template <typename T> inline bool chmax(T &a, T b) {
return ((a < b) ? (a = b, true) : (false));
}
template <typename T> inline bool chmin(T &a, T b) {
return ((a > b) ? (a = b, true) : (false));
}
int main(){
ll k,n,m;cin >> k >> n >>m;
vl a(k);rep(i,k)cin >> a[i];
ll sum=0;
vl b(k);rep(i,k){
b[i]=(m*a[i]+n-1)/n;
sum+=b[i];
}
//rep(i,k)cout << b[i] <<" ";cout << endl;
vpl st(k);
rep(i,k){
st[i]={b[i]*n-a[i]*m,i};
}
sort(all(st));rev(all(st));
//cout << sum-m <<endl;
rep(i,sum-m){
b[st[i].se]--;
}
rep(i,k)cout << b[i] <<" ";cout << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pr;
typedef vector<int> vec;
typedef long long int lli;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define TEST int T; cin >> T; while(T--)
#define rep(i,n) for (auto i = 0; i < n; ++i)
#define repk(i,k,n) for (auto i = k; i < n; ++i)
#define repr(i,k,n) for (auto i = k; i >= n; --i)
void solve() {
int a,b,c;
cin >> a >> b >> c;
if(a>b) cout << "Takahashi" << endl;
else if(a<b) cout << "Aoki" << endl;
else {
if(c == 0) cout << "Aoki" << endl;
else cout << "Takahashi" << endl;
}
}
int main() {
std::ios_base::sync_with_stdio(false);
cin.tie(NULL);
// TEST {
solve();
// }
} | #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}
const ll INF=1e18;
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int N,M;
cin>>N>>M;
vector<int> A(M),B(M);
vector<ll> C(M);
rep(i,M){
cin>>A[i]>>B[i]>>C[i];
A[i]--;B[i]--;
}
vector<vector<pair<int,ll>>> g(N);
rep(i,M) g[A[i]].push_back(mkp(B[i],C[i]));
vector<ll> ans(N,-1);
for(int st=0;st<N;st++){
vector<ll> dist(N,INF);
priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>> PQ;
for(auto e:g[st]){
int nex=e.first;
ll neco=e.second;
if(dist[nex]>neco){
dist[nex]=neco;
PQ.push(mkp(neco,nex));
}
}
while(!PQ.empty()){
auto f=PQ.top();
PQ.pop();
int now=f.second;
ll cost=f.first;
if(dist[now]<cost) continue;
for(auto e:g[now]){
int nex=e.first;
ll neco=e.second;
if(dist[nex]>dist[now]+neco){
dist[nex]=dist[now]+neco;
PQ.push(mkp(dist[nex],nex));
}
}
}
if(dist[st]!=INF) ans[st]=dist[st];
}
for(auto d:ans) cout<<d<<"\n";
return 0;
}
|
/*
このコード、と~おれ!
Be accepted!
∧_∧
(。・ω・。)つ━☆・*。
⊂ ノ ・゜+.
しーJ °。+ *´¨)
.· ´¸.·*´¨) ¸.·*¨)
(¸.·´ (¸.·'* ☆
*/
#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
#include <stack>
#include <bitset>
#include <array>
#include <chrono>
//#pragma GCC target("arch=skylake-avx512")
#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse4")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define repeat(i, n, m) for(int i = n; i < (m); ++i)
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a)
#define printLdb(a) printf("%.50Lf\n", a)
#define printdbd(a) printf("%.16lf\n", a)
#define prints(s) printf("%s\n", s.c_str())
#define all(x) (x).begin(), (x).end()
#define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI)
#define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L)
#define Please return
#define AC 0
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d))
using ll = long long;
using ull = unsigned long long;
constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1e9 + 7;
constexpr ll mod = 998244353;
constexpr long double eps = 1e-6;
const long double PI = acosl(-1.0L);
using namespace std;
void scans(string& str) {
char c;
str = "";
scanf("%c", &c);
if (c == '\n')scanf("%c", &c);
while (c != '\n' && c != -1 && c != ' ') {
str += c;
scanf("%c", &c);
}
}
void scanc(char& str) {
char c;
scanf("%c", &c);
if (c == -1)return;
while (c == '\n') {
scanf("%c", &c);
}
str = c;
}
double acot(double x) {
return PI / 2 - atan(x);
}
ll LSB(ll n) { return (n & (-n)); }
template<typename T>
inline T chmin(T& a, const T& b) {
if (a > b)a = b;
return a;
}
template<typename T>
inline T chmax(T& a, const T& b) {
if (a < b)a = b;
return a;
}
//cpp_int
#if __has_include(<boost/multiprecision/cpp_int.hpp>)
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
using namespace boost::multiprecision;
#else
using cpp_int = ll;
#endif
//atcoder library
#if __has_include(<atcoder/all>)
#include <atcoder/all>
//using namespace atcoder;
#endif
/*
random_device seed_gen;
mt19937 engine(seed_gen());
uniform_int_distribution dist(1, 100);
*/
/*----------------------------------------------------------------------------------*/
int main() {
int v, t, s, d;
scanf("%d%d%d%d", &v, &t, &s, &d);
printyn(d < t * v or v * s < d);
Please AC;
} | #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
const ll mod=1000000007;
const char nl='\n';
void solve(){
ll i,j,k,l,n,r,m,u,v,x,y;
cin>>n>>x>>y>>k;
if(x>y) swap(x,y);
cout<< ((k>=n*x and k<=n*y)?"No":"Yes")<<nl;
}
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
int t = 1,i=1;
// cin >> t;
while (t--)
{
// cout<<"Case #"<< i++ <<": ";
solve();
}
return 0;
} |
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define MOD 1000000007
int main() {
int t;
cin >> t;
while (t--) {
ll n;
cin >> n;
n %= 4;
if (n == 1 || n == 3) {
cout << "Odd" << endl;
} else if (n == 2) {
cout << "Same" << endl;
} else {
cout << "Even" << endl;
}
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
typedef long long ll;
typedef pair<ll, ll> P;
const ll MM = 1000000007;
const ll INF = 1e18;
const long double PI = acos(-1.0);
//------------------------------------------//
int main(){
int M,H;cin >> M >> H;
if(H%M==0){
cout<<"Yes"<<endl;
}
else{
cout<<"No"<<endl;
}
return 0;
} |
#line 1 "Contests/AtCoder_abc200/abc200_b/main.cpp"
using namespace std;
#line 2 "library/bits/stdc++.h"
// C
#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>
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
// C++
#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>
#if __cplusplus >= 201103L
#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
#line 3 "Contests/AtCoder_abc200/abc200_b/main.cpp"
#define ll long long
void solve(){
// write your solution here.
}
int main() {
ll N;
int K;
cin >> N >> K;
for(int i=0; i<K; i++){
if(N%200==0) N/=200;
else{
N=N*1000+200;
}
}
cout << N << endl;
return 0;
}
| #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
int main() {
double a, b, c;
cin >> a >> b;
cout << (1 - (b / a)) * 100 << endl;
} |
#include<cstring>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<queue>
#include<bitset>
#include<cstdlib>
#include<set>
#include<unordered_map>
#define l(x) (x<<1)
#define r(x) ((x<<1)|1)
#define low(x) (x&(-x))
#define IL inline
#define reg register
#define LL long long
#define N 1010
#define MOD 998244353
#define MO 1000000007
#define INF 0x3f3f3f3f
using namespace std;
LL T,n,s,k,i,j,x,Ans;
IL int Abs(int x){return (x<0)?-x:x;}
IL void Swap(int &a,int &b){a^=b^=a^=b;}
IL int Min(int a,int b){return (a<b)?a:b;}
IL int Max(int a,int b){return (a>b)?a:b;}
IL LL read(){
LL p=0,f=1; char c=getchar();
while (c<48||c>57) {if (c=='-') f=-1; c=getchar();}
while (c>=48&&c<=57) p=(p<<1)+(p<<3)+c-48,c=getchar();
return p*f;
}
IL LL Gcd(LL a,LL b){return (!b)?a:Gcd(b,a%b);}
IL void Ex_gcd(LL a,LL b,LL &x,LL &y){
LL p=0,q=0;
if (b==0) {
x=1; y=0; return;
} else {
Ex_gcd(b,a%b,p,q);
x=q; y=p-a/b*q;
}
}
IL LL Inv(LL a,LL p){
LL x=0,y=0;
Ex_gcd(a,p,x,y);
return x;
}
int main(){
#ifdef __Marvolo
freopen("zht.in","r",stdin);
freopen("zht.out","w",stdout);
#endif
T=read();
while (T--){
n=read(); s=read(); k=read();
s=n-s;
if (!s) {
puts("0");
continue;
}
if (s%Gcd(k,n)){
puts("-1");
continue;
}
x=Gcd(k,n);
k/=x; n/=x; s/=x;
x=Inv(k,n)%n;
Ans=(x*s)%n;
Ans%=n;
while (Ans<0) Ans+=n;
cout<<Ans<<endl;
}
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
int main(){
int A, B, C, D;
cin >> A >> B >> C >> D;
ll n = 0;
if( B >= C*D ) n = -1;
else{
double m = C*D - B;
double r = A / m;
n = ceil(r);
}
cout << n;
return 0;
} |
#include <iostream>
#include<string>
using namespace std;
int main()
{
int a;
cin >> a;
if (a % 2 == 1)cout << "Black"<<endl;
else cout << "White" << endl;
} | #include <bits/stdc++.h>
using namespace std;
//関数定義
int main() {
//ここに中身
string S;
cin >> S;
char x = S.at(0);
S.at(0) = S.at(1);
S.at(1) = S.at(2);
S.at(2) = x;
cout << S;
} |
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, N) for (int i = 0; i < (N); ++i)
#define rep2(i, a, b) for (ll i = a; i <= b; ++i)
#define rep3(i, a, b) for (ll i = a; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define nl '\n'
#define endl '\n'
#define all(c) begin(c), end(c)
#define ok() puts(ok ? "Yes" : "No");
#define pcnt(x) __builtin_popcountll(x)
#define df(x) ll x = in();
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvll = vector<vll>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using vs = vector<string>;
using P = pair<ll, ll>;
using gt = greater<P>;
using minq = priority_queue<P, vector<P>, gt>;
using vP = vector<P>;
inline ll in() {
ll x;
scanf("%lld", &x);
return x;
}
template <class T> void takeUnique(vector<T> &v) {
auto last = std::unique(v.begin(), v.end());
v.erase(last, v.end());
}
template <class T> void print(const initializer_list<T> &il) {
for (auto x : il) {
cout << x << " ";
}
cout << "\n";
}
inline void priv(vll a) {
rep(i, (int)a.size() - 1) cout << a[i] << " ";
cout << a.back() << nl;
}
inline void priv(vi a) {
rep(i, (int)a.size() - 1) cout << a[i] << " ";
cout << a.back() << nl;
}
const ll LINF = 8e18L + 1;
const int INF = 8e9 + 1;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int dxx[] = {0, 1, 1, 1, 0, -1, -1, -1};
int dyy[] = {1, 1, 0, -1, -1, -1, 0, 1};
// g++ -std=c++17 -stdlib=libc++
#define _GLIBCXX_DEBUG
// This slows down the execution; even the time complexity, since it checks if
// std funcs such as lower_bound meets prereqs
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout << fixed << setprecision(16);
int n;
cin >> n;
vi a(n);
vi b(n);
rep(i, n) cin >> a[i];
rep(i, n) cin >> b[i];
int mx = 0;
int mn = INF;
rep(i, n) chmax(mx, a[i]);
rep(i, n) chmin(mn, b[i]);
cout << max(0, mn - mx + 1) << nl;
return 0;
}
| #include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define PRECISION std::cout << std::fixed << std::setprecision(20);
using namespace std;
void solve() {
int n;
cin >> n;
vector<int> a(n), b(n);
for (int &i: a) cin >> i;
for (int &i: b) cin >> i;
int ans = 0;
for (int i = 1; i <= 1000; i++) {
int ok = 1;
for (int x = 0; x < n; x++) {
ok &= (i >= a[x] && i <= b[x]);
}
ans += ok;
}
cout << ans << "\n";
}
int main() {
FASTIO;
PRECISION;
int t = 1;
// cin >> t;
for (int i = 1; i <= t; i++) {
solve();
}
} |
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
int main()
{
int n;
cin>>n;
string aa,ab,ba,bb;
cin>>aa>>ab>>ba>>bb;
int ans=1;
for(int i=0;i<n-3;i++) ans=ans*2%mod;
if((ab=="A"&&aa=="B"&&ba=="B")||(ab=="B"&&bb=="A"&&ba=="A"))
cout<<ans<<'\n';
else if((ab=="A"&&aa=="B")||(ab=="B"&&bb=="A"))
{
int dp1=1,dp2=0;
for(int i=2;i<=n;i++)
{
int sv=dp1;
dp1=(dp2+dp1)%mod;
dp2=sv;
}
cout<<dp2<<'\n';
}
else cout<<1<<'\n';
} | #include <bits/stdc++.h>
#define fileio \
freopen("C:\\Users\\PRISM17\\Desktop\\in.txt", "r", stdin); \
freopen("C:\\Users\\PRISM17\\Desktop\\out.txt", "w", stdout);
#define fastio \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define dbg(x) cout << #x << " : " << x << endl;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define mid (st[id].l + st[id].r >> 1)
#define lson (id << 1)
#define rson (id << 1 | 1)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> PII;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const int inf = 0x3f3f3f3f;
const int INF = 1e9;
const ll mod = 1e9 + 7;
string s[2][2];
set<string> st;
int n;
void dfs(string str) {
if (str.length() == n) {
st.insert(str);
return;
}
int len = str.length();
for (int i = 1; i < len; i++) {
string nstr = str;
nstr.insert(i, s[str[i - 1] - 'A'][str[i] - 'A']);
dfs(nstr);
}
}
void table() {
for (int aa = 0; aa <= 1; aa++) {
for (int bb = 0; bb <= 1; bb++) {
for (int ab = 0; ab <= 1; ab++) {
for (int ba = 0; ba <= 1; ba++) {
s[0][0] = string(1, 'A' + aa); s[1][1] = string(1, 'A' + bb);
s[0][1] = string(1, 'A' + ab); s[1][0] = string(1, 'A' + ba);
cout << endl << s[0][0] << s[0][1] << s[1][0] << s[1][1] << ' ';
for (int i = 3; i <= 10; i++) {
n = i;
st.clear();
dfs("AB");
cout << st.size() << ' ';
}
}
}
}
}
}
int main() {
// table();
cin >> n;
string str(4, ' ');
for (int i = 0; i < 4; i++) cin >> str[i];
auto solve = [&](int n, string& pat) -> int {
vector<int> pow(n + 1, 1), fib(n + 1, 1);
for (int i = 4; i <= n; i++) {
pow[i] = pow[i - 1] * 2 % mod;
fib[i] = (fib[i - 1] + fib[i - 2]) % mod;
}
if (pat[0] == 'A' && pat[1] == 'A') return 1;
if (pat[1] == 'B' && pat[3] == 'B') return 1;
if (pat == "ABAA" || pat == "BABA" || pat == "BBAA" || pat == "BABB") return pow[n];
else return fib[n];
};
cout << solve(n, str) << endl;
} |
#include <bits/stdc++.h>
#define rep(i, n) for (ll i=0; i<n; ++i)
#define all(obj) (obj).begin(),(obj).end()
using namespace std;
typedef long long ll;
long long GCD(long long x, long long y) { return y ? GCD(y, x%y) : x; }
int main(){
int h, w;
int min_n = 100000;
int ans = 0;
cin >> h >> w;
vector<int> a(h*w);
rep(i, h*w){
cin >> a[i];
min_n = min(min_n, a[i]);
}
rep(i, h*w){
ans+=a[i]-min_n;
}
cout << ans << endl;
return 0;
}
| #pragma region template
// clang-format off
#if __has_include(<src.hpp>)
#include <src.hpp> // precompiled header
#endif
#ifdef __INTELLISENSE__
#define NDEBUG
namespace std {
#endif
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#ifdef __INTELLISENSE__
using namespace std;
}
#endif
#ifdef LOCAL_DEBUG
#include <debugger.hpp> // https://gist.github.com/naskya/d28b74e1df8816740c6fcbf0c66c5693
#define see(...) debugger::print(#__VA_ARGS__, __VA_ARGS__)
#define here(label) debugger::output << "[Debug] " << #label << (std::string(#label).size() ? " | " : "") << "line " << __LINE__ << " (" << __func__ << ")\n"
#define com(msg) debugger::output << "[Debug] " << msg << "\n"
#define local(x) do{x} while(0)
#define alter(x, y) x
#else
#define see(...) (static_cast<void>(0))
#define here(label) (static_cast<void>(0))
#define com(msg) (static_cast<void>(0))
#define local(x) (static_cast<void>(0))
#define alter(x, y) y
#endif
#if (!defined LOCAL_DEBUG) || (defined NOWARN)
#define warn(msg) (static_cast<void>(0))
#else
#define warn(msg) debugger::output << "[Warning] " << msg << "\n \033[0;35m#define NOWARN\033[0m to suppress this warning.\n"
#endif
#if (defined LOCAL_DEBUG) || (defined LOCAL_NDEBUG) || (defined __INTELLISENSE__)
#define NOEXCEPT
#define M_assert(expr) assert(expr)
#define O_assert(expr) assert(expr)
#else
#define NOEXCEPT noexcept
#define M_assert(expr) do{if(__builtin_expect(!(expr), 0)) {long long *p = (long long*) std::malloc(1 << 30); for (int i = 0; i < static_cast<int>((1 << 30) / sizeof(long long)); p[i] = 1, i += (1 << 9)); std::fprintf(stderr, "%lld", *p);}} while(0)
#define O_assert(expr) do{if(__builtin_expect(!(expr), 0)) for(int i = 0; i < (1 << 24); i++) std::puts("Hello, world!");} while(0)
#endif
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rng(i, f, t, s) for (int i = (f); ((s) > 0) ? (i < (int)(t)) : (i > (int)(t)); i += (s))
#define erng(i, f, t, s) for (int i = (f); ((s) > 0) ? (i <= (int)(t)) : (i >= (int)(t)); i += (s))
[[maybe_unused]] constexpr int INF = 1000000005;
[[maybe_unused]] constexpr long long LINF = 1000000000000000005LL;
[[maybe_unused]] constexpr double EPS = 1e-9;
[[maybe_unused]] constexpr int dy[8] = {1, 0, -1, 0, 1, 1, -1, -1};
[[maybe_unused]] constexpr int dx[8] = {0, 1, 0, -1, -1, 1, 1, -1};
template <class S, class T, class... U, class V = std::common_type_t<S, T, U...>> constexpr V Min(S a, T b, U... c) {
if constexpr (sizeof...(U) > 0) return std::min((V) a, (V) Min(b, c...)); else return std::min((V) a, (V) b);
}
template <class S, class T, class... U, class V = std::common_type_t<S, T, U...>> constexpr V Max(S a, T b, U... c) {
if constexpr (sizeof...(U) > 0) return std::max((V) a, (V) Max(b, c...)); else return std::max((V) a, (V) b);
}
// clang-format on
#pragma endregion
void solve(long long H, long long W, std::vector<std::vector<long long>> A) {
int ans = 0;
int min = INF;
rep(i, H) {
rep(j, W) {
min = Min(min, A[i][j]);
}
}
rep(i, H) {
rep(j, W) {
ans += A[i][j] - min;
}
}
std::cout << ans << "\n";
}
int main() {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-result"
long long H;
std::scanf("%lld", &H);
long long W;
std::scanf("%lld", &W);
std::vector<std::vector<long long>> A(H, std::vector<long long>(W));
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
std::scanf("%lld", &A[i][j]);
}
}
#pragma GCC diagnostic pop
solve(H, W, std::move(A));
}
|
#include<cstdio>
#define N 100002
int n, pri[N], bz[N], ans[N], tot;
int main(){
scanf("%d", &n);
for (int i = 2; i <= n; i ++){
if (!bz[i]){
pri[++ tot] = i;
ans[i] = 1;
}
for (int j = 1; j <= tot && i * pri[j] <= n; j ++){
bz[i * pri[j]] = 1;
ans[i * pri[j]] = ans[i] + 1;
if (i % pri[j] == 0) break;
}
}
for (int i = 1; i <= n; i ++) printf("%d ", ans[i] + 1);
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
/*freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);*/
int n;
cin >> n;
int curr = 1;
for (int i = 1; i <= n; i++) {
if (i == (1 << curr)) {
curr++;
}
cout << curr << ' ';
}
} |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
ll n,sn;
cin >> n >> sn;
vector<ll> a(n);
vector<ll> b(n);
vector<ll> c(n);
map<ll,ll> day;
for(int i = 0;i < n;i++){
cin >> a[i] >> b[i] >> c[i];
a[i]--,b[i]--;
day[a[i]]++,day[b[i]]++;
day[b[i]+1]++;
}
ll si = day.size();
map<ll,ll> dtoi;
ll nowc = 0;
for(auto i:day){
dtoi[i.first] = nowc;
nowc++;
}
vector<ll> itod;
for(auto i:day){
itod.push_back(i.first);
}
itod.push_back(itod[itod.size() - 1] + 1);
vector<ll> sum(si+1,0);
for(int i = 0;i < n;i++){
ll ait = dtoi[a[i]];
ll bit = dtoi[b[i]];
sum[ait] += c[i],sum[bit + 1] -= c[i];
}
//cout << sum[0] << " " << sum[1] << " " << sum[2] << " " << sum[3] << " " << sum[4] << endl;
for(int i = 1;i < si;i++)sum[i] += sum[i - 1];
//cout << sum[0] << " " << sum[1] << " " << sum[2] << " " << sum[3] << " " << sum[4] << endl;
ll res = 0;
for(int i = 0;i < si;i++){
res += min(sn,sum[i]) * (itod[i + 1] - itod[i]);
}
//cout << itod[0] << " "<< itod[1] << " " << itod[2] << " " << itod[3] << " " << itod[4] << endl;
cout << res << endl;
} | #include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#define ll long long
#define MAXN 200005
#define uns unsigned
#define INF 0x3f3f3f3f
using namespace std;
inline ll read(){
ll x=0;bool f=1;char s=getchar();
while((s<'0'||s>'9')&&s>0){if(s=='-')f^=1;s=getchar();}
while(s>='0'&&s<='9')x=(x<<1)+(x<<3)+s-'0',s=getchar();
return f?x:-x;
}
int n,m,q,sr[55];
ll w[55],v[55],x[55];
bool vis[55];
inline bool cmp(int a,int b){
return v[a]>v[b];
}
int main()
{
n=read(),m=read(),q=read();
for(int i=1;i<=n;i++)w[i]=read(),v[i]=read(),sr[i]=i;
for(int i=1;i<=m;i++)x[i]=read();
sort(sr+1,sr+1+n,cmp);
while(q--){
int l=read(),r=read();
ll ans=0;
for(int i=1;i<=m;i++)vis[i]=0;
for(int i=1;i<=n;i++){
int u=sr[i],y=0;
for(int j=1;j<=m;j++){
if(j>=l&&j<=r)continue;
if(!vis[j]&&x[j]>=w[u]){
if(!y)y=j;
else if(x[j]<x[y])y=j;
}
}
if(y)vis[y]=1,ans+=v[u];
}
printf("%lld\n",ans);
}
return 0;
} |
#include <cmath>
#include <deque>
#include <algorithm>
#include <iterator>
#include <list>
#include <tuple>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <unordered_set>
#include <stack>
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
#include <functional>
#include <numeric>
#include <iomanip>
#include <stdio.h>
//end of libraries
#define lnf 3999999999999999999
#define inf 999999999
#define PI 3.14159265359
#define endl "\n"
#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(c) (c).begin(),(c).end()
#define sz(c) (int)(c).size()
#define mkp(a,b) make_pair(a,b)
#define make_unique(a) sort(all(a)),a.erase(unique(all(a)),a.end())
#define rsz(a,n) a.resize(n)
#define pii pair <int,int>
#define rep(i,n) for(int i = 0 ; i < n ; i++)
#define drep(i,n) for(int i = n-1 ; i >= 0 ; i--)
#define crep(i,x,n) for(int i = x ; i < n ; i++)
#define fcin ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
const int max_n = 300000;
using namespace std;
int n;
ll d[20] , f[20] , cnt[20];
bool game(vector <int> a,vector<int> b){
crep(i,1,10) {d[i]=0;f[i]=0;}
rep(i,sz(a)) {
d[a[i]]++;
}
rep(i,sz(b)){
f[b[i]]++;
}
int c1=0,c2=0;
crep(i,1,10) {
c1 += pow(10,d[i]) * i;
c2 += pow(10,f[i]) * i;
}
if(c1>c2) return 1;
return 0;
}
vector <int> a , b;
void read(){
string s1,s2;
cin >> s1 >> s2;
rep(i,sz(s1)-1) {
a.pb(s1[i]-'0');
}
rep(i,sz(s2)-1){
b.pb(s2[i]-'0');
}
}
int main(){
fcin;
cin >> n;
read();
crep(x,1,10) {
int d=0;
rep(i,sz(a)) if(a[i]==x)d++;
rep(i,sz(b)) if(b[i]==x)d++;
cnt[x]=(n-d);
}
ll e=0,t=0;
crep(x,1,10) {
crep(y,1,10) {
if(x==y and cnt[x] < 2) continue;
a.pb(x);b.pb(y);
bool g = game(a,b);
a.pop_back();b.pop_back();
if(g==1) {
e+=(cnt[x]*(cnt[y]-(x==y)));
}
t+= (cnt[x]*(cnt[y]-(x==y)));
}
}
long double e1 = e;
long double t1 = t;
cout << fixed<<setprecision(11);
cout << e1/t1 << "\n";
/*
*/
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
static const ll INF=1000000000000000;
ll K;
ll sum0[10];
ll sum1[10];
ll Sum0[10];
ll Sum1[10];
string S,T;
int main(){
cin>>K>>S>>T;
for(ll i=0;i<4;i++){
ll x=S[i]-'0';sum0[x]++;
}for(ll i=0;i<4;i++){
ll x=T[i]-'0';sum1[x]++;
}ld ans=0;
for(ll i=1;i<=9;i++)
for(ll j=1;j<=9;j++){
for(ll k=0;k<10;k++){
Sum0[k]=sum0[k];Sum1[k]=sum1[k];
}Sum0[i]++;Sum1[j]++;ll x0=0;ll x1=0;
for(ll k=1;k<10;k++){
x0+=k*pow(10,Sum0[k]);
x1+=k*pow(10,Sum1[k]);
}
if(x1<x0){
ld X=(9*K-8)*(9*K-9);
if(i==j){
ld Y=(K-sum0[i]-sum1[i])*(K-sum0[i]-sum1[i]-1);
ans+=Y/X;
}else{
ld Y=(K-sum0[i]-sum1[i])*(K-sum0[j]-sum1[j]);
ans+=Y/X;
}
}
}cout<<fixed<<setprecision(10)<<ans<<endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
int main () {
int N, X;
cin >> N >> X;
int t = 0;
for (int i = 0; i < N; i++) {
int v, p;
cin >> v >> p;
t += v * p;
if (t > X * 100) {
cout << i+1 << endl;
return 0;
}
}
cout << -1 << endl;
} | // #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
// #include <atcoder/all> // g++ main.cpp -std=c++17 -I .
using namespace std;
// using namespace atcoder;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) (v).begin(), (v).end()
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}
using ll=long long;
const int inf = INT_MAX / 2; const ll INF = 1LL << 60;
const ll MOD = 1000000007;
// const int MOD = 998244353;
// cout << fixed << setprecision(15) << ans << endl;
// using mint = modint1000000007;
////////////////////////////////////////////////////////////////////////////////////////////
int main() {
ll n,k;cin>>n>>k;
if(k<0) k = -k;
vector<ll> v(2*n-1);
rep(i, n) {
v[i] = v[2*n-2-i] = i+1;
}
ll ans = 0;
for(int i = 0; i+k <= 2*n-2; i++) {
ans += v[i]*v[i+k];
}
cout << ans << endl;
} |
#include <bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef DEBBY
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define ll long long
#define print_mat(i,j,a,b,v) for(int i=0;i<a;i++){for(int j=0;j<b;j++)cerr<<v[i][j] << " "; cerr<<endl;}
#define sz(v) (int)(v).size()
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define pi pair<int,int>
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define vpi vector<pi>
#define pq priority_queue<int>
#define pqg priority_queue<int, vi, greater<int> >
#define fs first
#define sd second
#define pb push_back
#define eb emplace_back
#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)
///////////////////////////////////////
// READING
template<class A> void read(vector<A>& v);
template<class A, size_t S> void read(array<A, S>& a);
template<class T> void read(T& x) {
cin >> x;
}
void read(double& d) {
string t;
read(t);
d=stod(t);
}
void read(long double& d) {
string t;
read(t);
d=stold(t);
}
template<class H, class... T> void read(H& h, T&... t) {
read(h);
read(t...);
}
template<class A> void read(vector<A>& x) {
EACH(a, x)
read(a);
}
template<class A, size_t S> void read(array<A, S>& x) {
EACH(a, x)
read(a);
}
////////////////////////////////
// PRINTING
string to_string(char c) {
return string(1, c);
}
string to_string(bool b) {
return b?"true":"false";
}
string to_string(const char* s) {
return string(s);
}
string to_string(string s) {
return s;
}
string to_string(vector<bool> v) {
string res;
FOR(sz(v))
res+=char('0'+v[i]);
return res;
}
template<size_t S> string to_string(bitset<S> b) {
string res;
FOR(S)
res+=char('0'+b[i]);
return res;
}
template<class T> string to_string(T v) {
bool f=1;
string res;
EACH(x, v) {
if(!f)
res+=' ';
f=0;
res+=to_string(x);
}
return res;
}
template<class A> void write(A x) {
cout << to_string(x);
}
template<class H, class... T> void write(const H& h, const T&... t) {
write(h);
write(t...);
}
void print() {
write("\n");
}
template<class H, class... T> void print(const H& h, const T&... t) {
write(h);
if(sizeof...(t))
write(' ');
print(t...);
}
////////////////////////////////
// START PROGRAM
///////////////////////////////
void solve(){
int a,b,c;
read(a,b,c);
if(a*a + b*b < c*c)
print("Yes");
else
print("No");
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//int t;
//read(t);
//FOR(t){
//write("Case #", i+1, ": ");
//solve();
//}
solve();
return 0;
}
| #include<bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <chrono>
#include <complex>
using namespace std;
#define ll long long
#define ld long double
#define ui unsigned int
#define ull unsigned ll
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define hashmap unordered_map
#define hashset unordered_set
#define lb lower_bound
#define ub upper_bound
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define ff first
#define ss second
#define foi(n) for(ll i=0;i<n;i++)
#define foj(n) for(ll j=0;j<n;j++)
#define fok(n) for(ll k=0;k<n;k++)
#define forr(i,a,b) for(ll i=a;i<b;i++)
#define forrr(i,b,a) for(ll i=b;i>=a;i--)
#define forrrr(i,a,b,k) for(ll i=a;i<b;i=i+k)
#define graph vector<vector<int>>
#define sz(v) v.size()
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef pair< ll, pll> plll;
typedef vector<plll> vplll;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef map<string, int> msi;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
typedef map<char, int> mci;
typedef map<int, string> mis;
typedef pair<string, int> psi;
typedef pair<string, string> pss;
typedef priority_queue <ll> pq;
typedef priority_queue<pii, vector<pii>, greater<pii> > pqq;
const ll MOD = 1000000007;
void solve();
int main()
{
ios_base::sync_with_stdio(false); cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input1.txt", "r", stdin);
freopen("error1.txt", "w", stderr);
freopen("output1.txt", "w", stdout);
#endif
// ll t ; cin >> t;
// while (t--)
{
solve();
cout << "\n";
}
cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
return 0;
}
ll ceils(ll x, ll y) {
return x / y + ((x % y) != 0);
}
ll gcd(ll a, ll b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
return a / gcd(a, b) * b;
}
void solve() {
ll t, n;
cin >> t >> n;
vll ans;
for (ll i = 1; i <= 100; ++i) {
ll a = (100 + t) * (i - 1) / 100;
ll b = (100 + t) * i / 100;
if (b - a == 2)
ans.pb(a + 1);
}
n--;
cout << (100 + t) * (n / t) + ans[n % t];
}
|
// 2021-03-28 11:22:37
// clang-format off
#include <bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
// clang-format on
const int MX = 1010, inf = 1e9;
bool A[MX][MX];
int dist[MX][MX];
vector<int> G[MX][26];
using T = tuple<int, int, int>;
void answer() {
int n, m;
cin >> n >> m;
rep(i, m) {
int a, b, c;
char c_;
cin >> a >> b >> c_;
a--;
b--;
c = c_ - 'a';
A[a][b] = A[b][a] = true;
G[a][c].push_back(b);
G[b][c].push_back(a);
}
rep(i, n) rep(j, n) dist[i][j] = inf;
dist[0][n - 1] = 0;
int ans = inf;
queue<T> que;
que.emplace(0, n - 1, 0);
while (!que.empty()) {
auto [x, y, cost] = que.front();
que.pop();
if (dist[x][y] < cost) continue;
if (x == y) {
chmin(ans, cost * 2);
continue;
}
if (A[x][y]) {
chmin(ans, cost * 2 + 1);
continue;
}
rep(z, 26) {
for (auto x2 : G[x][z]) {
for (auto y2 : G[y][z]) {
int u = min(x2, y2);
int v = max(x2, y2);
if (dist[u][v] <= cost + 1) continue;
dist[u][v] = cost + 1;
que.emplace(u, v, cost + 1);
}
}
}
}
if (ans == inf) ans = -1;
cout << ans << '\n';
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
answer();
return 0;
} | //12252024832524
#include <queue>
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
#define TT template<typename T>
using namespace std;
typedef long long LL;
const int MAXN = 1005;
int n,m;
int vis[MAXN][MAXN],woc[MAXN][MAXN];
LL Read()
{
LL x = 0,f = 1;char c = getchar();
while(c > '9' || c < '0'){if(c == '-')f = -1;c = getchar();}
while(c >= '0' && c <= '9'){x = (x*10) + (c^48);c = getchar();}
return x * f;
}
TT void Put1(T x)
{
if(x > 9) Put1(x/10);
putchar(x%10^48);
}
TT void Put(T x,char c = -1)
{
if(x < 0) putchar('-'),x = -x;
Put1(x); if(c >= 0) putchar(c);
}
TT T Max(T x,T y){return x > y ? x : y;}
TT T Min(T x,T y){return x < y ? x : y;}
TT T Abs(T x){return x < 0 ? -x : x;}
vector<int> E[30][MAXN];
void Add_Edge(int x,int y,int z)
{
E[z][x].push_back(y);
}
void Add_Double_Edge(int x,int y,int z)
{
vis[x][y] = vis[y][x] = z;
Add_Edge(x,y,z);
Add_Edge(y,x,z);
}
int gc()
{
char c = getchar();
while(c > 'z' || c < 'a'){c = getchar();}
return c - 'a' + 1;
}
struct node
{
int s,t,dis;
node(){}
node(int s1,int t1,int dis1){
s = s1;
t = t1;
dis = dis1;
}
};
int bfs()
{
queue<node> q;
q.push(node(1,n,0));
woc[1][n] = 1;
while(!q.empty())
{
node w = q.front(); q.pop();
if(vis[w.s][w.t]) return w.dis * 2 + 1;
for(int i = 1;i <= 26;++ i)
{
for(int j = 0,len1 = E[i][w.s].size();j < len1;++ j)
for(int k = 0,len2 = E[i][w.t].size();k < len2;++ k)
{
int tox = E[i][w.s][j],toy = E[i][w.t][k];
if(!woc[tox][toy])
{
woc[tox][toy] = 1;
if(tox == toy) return w.dis*2+2;
q.push(node(tox,toy,w.dis+1));
}
}
}
}
return -1;
}
int main()
{
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
n = Read(); m = Read();
for(int i = 1;i <= m;++ i)
{
int u = Read(),v = Read();
Add_Double_Edge(u,v,gc());
}
Put(bfs());
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1 << 19;
int n, m;
long long dp[maxn]; bool ok[maxn];
int x[110], y[110], z[110];
int main()
{
scanf ("%d %d", &n, &m);
for (int i = 1; i <= m; i++)
scanf ("%d %d %d", x + i, y + i, z + i);
int upp = 1 << n;
dp[0] = 1;
for (int sta = 0; sta < upp; sta++)
{
bool f = 1;
int cnt = __builtin_popcount(sta);
for (int i = 1; i <= m; i++)
{
if (cnt > x[i]) continue;
int u = 1 << y[i]; u--;
int v = u & sta;
int c = __builtin_popcount(v);
if (c > z[i]) f = 0;
}
if (!f) dp[sta] = 0;
for (int o = 0; o < n; o++) if (!((1 << o) & sta)) dp[sta | (1 << o)] += dp[sta];
}
printf ("%lld\n", dp[upp - 1]);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define debug puts("WHAP")
const int N = 101;
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
int n; cin >> n;
vector<pair<int,int> > a;
int ans = 0;
for(int i = 0; i < n; ++i){
int t,x,y; cin >> t >> x >> y;
x*=2;
y*=2;
if(t == 1){
a.push_back(make_pair(x,y));
}
else if(t == 2){
a.push_back(make_pair(x,y-1));
}
else if(t == 3){
a.push_back(make_pair(x+1, y));
}
else{
a.push_back(make_pair(x+1,y-1));
}
}
for(int i = 0; i < n; ++i){
for(int j = i+1; j < n; ++j){
if(a[i].second < a[j].first){
continue;
}
if(a[j].second < a[i].first){
continue;
}
++ans;
}
}
cout << ans << "\n";
return 0;
} |
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <tuple>
#include <vector>
using namespace std;
#define REP(i, n) for (ll i = 0; i < ll(n); i++)
#define FOR(i, a, b) for (ll i = a; i <= ll(b); i++)
#define ALL(x) x.begin(), x.end()
typedef long long ll;
class dstream : public ostream {};
template <typename T>
dstream &operator<<(dstream &os, T v) {
#ifdef ATCODERDEBUG
cout << v;
#endif
return os;
}
ostream &endd(std::ostream &out) {
#ifdef ATCODERDEBUG
out << std::endl;
#endif
return out;
}
dstream dout;
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
os << "[ ";
for (auto const &x : v) {
os << x;
if (&x != &v.back()) {
os << " : ";
}
}
os << " ]" << endl;
return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<vector<T>> &v) {
os << "[" << endl;
for (auto const &x : v) {
os << " ";
print_vec(x);
}
os << "]" << endl;
return os;
}
template <typename T, typename U, typename Comp = less<>>
bool chmax(T &xmax, const U &x, Comp comp = {}) {
if (comp(xmax, x)) {
xmax = x;
return true;
}
return false;
}
template <typename T, typename U, typename Comp = less<>>
bool chmin(T &xmin, const U &x, Comp comp = {}) {
if (comp(x, xmin)) {
xmin = x;
return true;
}
return false;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll N, M, K, a, b, c, d;
cin >> N >> M;
vector<pair<ll, ll>> ablist;
REP(i, M) {
cin >> a >> b;
a--;
b--;
ablist.push_back(make_pair(a, b));
}
cin >> K;
vector<pair<ll, ll>> cdlist;
REP(i, K) {
cin >> c >> d;
c--;
d--;
cdlist.push_back(make_pair(c, d));
}
ll ans = 0;
for (unsigned long i = 0; i < pow(2LL, K); i++) {
vector<ll> llist(N, 0);
for (unsigned long j = 0; j < K; j++) {
ll idx = 0;
if ((i >> j) & 1)
idx = cdlist[j].first;
else
idx = cdlist[j].second;
llist[idx]++;
}
ll cnt = 0;
REP(j, M) {
if (llist[ablist[j].first] > 0 && llist[ablist[j].second] > 0) cnt++;
}
dout << cnt << " " << i << "" << llist << endd;
chmax(ans, cnt);
}
// dout << ((2 >> 0) & 1) << endd;
cout << ans << endl;
// cout << std::fixed << std::setprecision(15) << sqrt(ans) << endl;
} | #include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <numeric>
#include <limits>
#include <type_traits>
#include <locale>
#include <omp.h>
using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE) \
if (TRUE_OR_FALSE) \
{ \
cout << "YES" << endl; \
} \
else \
{ \
cout << "NO" << endl; \
}
#define IFYes(TRUE_OR_FALSE) \
if (TRUE_OR_FALSE) \
{ \
cout << "Yes" << endl; \
} \
else \
{ \
cout << "No" << endl; \
}
#define IFyes(TRUE_OR_FALSE) \
if (TRUE_OR_FALSE) \
{ \
cout << "yes" << endl; \
} \
else \
{ \
cout << "no" << endl; \
}
#define DEBUG_OUTPUT_ARRAY(XXX, ONE) \
for (int i = 0; i < (ONE); i++) \
{ \
cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
}
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO) \
for (int i = 0; i < (ONE); i++) \
{ \
cout << "<<< i = " << i << " >>>" << endl; \
for (int j = 0; j < (TWO); j++) \
{ \
cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
} \
}
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
for (int i = 0; i < (ONE); i++) \
{ \
cout << i << " "; \
for (int j = 0; j < (TWO); j++) \
{ \
cout << XXX[i][j] << " "; \
} \
cout << endl; \
}
typedef pair<long long int, long long int> pll;
typedef pair<long long int, pll> lpll;
const long long int mod = 998244353;
const long long int INF = 1e16;
const long double PI=3.14159265358979323;
const long long int pl=1100;
const long double eps =0.0000001;
long long int res=0,N,M,K,A[200200],B[200200],C[200200],D[200200],memo[200200]={};
int main()
{
cout << fixed << setprecision(18);
cin>>N>>M;
for (long long int i = 0; i < M; i++)
{
cin>>A[i]>>B[i];
}
cin>>K;
for (long long int i = 0; i < K; i++)
{
cin>>C[i]>>D[i];
}
for (long long int i = 0; i < (1<<K); i++)
{
for (long long int j = 0; j <= N; j++)
{
memo[j]=0;
}
for (long long int j = 0; j < K; j++)
{
if((i&(1<<j))==0){
memo[C[j]]=1;
}else{
memo[D[j]]=1;
}
}
long long int tmp=0;
for (long long int j = 0; j < M; j++)
{
if(memo[A[j]]==1&&memo[B[j]]==1){
tmp++;
}
}
res=max(res,tmp);
}
cout<<res<<endl;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
constexpr bool typetest = 0;
constexpr int N = 2e5 + 5;
constexpr ll mod = 1e9 + 7;
int n, dp[N][65][2];
vector<pair<int, ll>> adj[N];
ll ans(0);
void Read()
{
cin >> n;
for (int i = 2; i <= n; ++i)
{
int u, v;
ll w;
cin >> u >> v >> w;
adj[u].emplace_back(v, w);
adj[v].emplace_back(u, w);
}
}
#define bit(i, x) (((x) >> (i)) & 1)
void dfs(int v, int par)
{
for (int j = 0; j < 61; ++j)
{
++dp[v][j][0];
(ans += (1ll << j) % mod * dp[v][j][1] % mod) %= mod;
}
for (auto i : adj[v])
if (i.first != par)
{
for (int j = 0; j < 61; ++j)
{
dp[i.first][j][1] += dp[v][j][!bit(j, i.second)];
dp[i.first][j][0] += dp[v][j][bit(j, i.second)];
}
dfs(i.first, v);
for (int j = 0; j < 61; ++j)
{
dp[v][j][1] = dp[i.first][j][!bit(j, i.second)];
dp[v][j][0] = dp[i.first][j][bit(j, i.second)];
}
}
}
void Solve()
{
dfs(1, 1);
cout << ans;
}
int32_t main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t(1);
if (typetest)
cin >> t;
for (int _ = 1; _ <= t; ++_)
{
Read();
Solve();
}
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(a) (a).begin(), (a).end()
#define mp make_pair
template<typename T1, typename T2>
inline void chkmin(T1& x, const T2& y) {
if (y < x) x = y;
}
template<typename T1, typename T2>
inline void chkmax(T1& x, const T2& y) {
if (x < y) x = y;
}
#define int ll
struct Fenwick{
vector<int> tree;
int n;
Fenwick() {}
Fenwick(int _n) {
n = _n;
tree.assign(n, 0);
}
void upd(int pos, int val) {
for (; pos < n; pos |= pos + 1) {
tree[pos] += val;
}
}
int get(int r) {
int ans = 0;
for (; r >= 0; r = (r & (r + 1)) - 1) {
ans += tree[r];
}
return ans;
}
int get(int l, int r) {
if (l > r) return 0;
return get(r) - get(l - 1);
}
};
struct Query{
int t, x, y;
};
int ans = 0;
Fenwick treeA, treeB, cntA, cntB;
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cout.precision(20), cout.setf(ios::fixed);
int n, m, q;
cin >> n >> m >> q;
vector<Query> queries(q);
vector<int> coord;
for (auto &i : queries) {
cin >> i.t >> i.x >> i.y;
--i.x;
coord.push_back(i.y);
}
coord.push_back(0);
sort(all(coord));
coord.resize(unique(all(coord)) - coord.begin());
vector<int> a(n + 1, 0);
vector<int> b(m + 1, 0);
treeA = Fenwick(coord.size());
treeB = Fenwick(coord.size());
cntA = Fenwick(coord.size());
cntB = Fenwick(coord.size());
for (int i = 0; i < n; ++i) {
cntA.upd(0, 1);
}
for (int i = 0; i < m; ++i) {
cntB.upd(0, 1);
}
for (auto [t, x, y] : queries) {
// int posY = lower_bound(all(coord), y) - coord.begin();
if (t == 1) {
int posNow = lower_bound(all(coord), a[x]) - coord.begin();
ans -= cntB.get(posNow) * a[x];
ans -= treeB.get(posNow + 1, coord.size() - 1);
treeA.upd(posNow, -a[x]);
cntA.upd(posNow, -1);
a[x] = y;
posNow = lower_bound(all(coord), a[x]) - coord.begin();
treeA.upd(posNow, a[x]);
cntA.upd(posNow, 1);
ans += cntB.get(posNow) * a[x];
ans += treeB.get(posNow + 1, coord.size() - 1);
} else {
int posNow = lower_bound(all(coord), b[x]) - coord.begin();
ans -= cntA.get(posNow) * b[x];
ans -= treeA.get(posNow + 1, coord.size() - 1);
treeB.upd(posNow, -b[x]);
cntB.upd(posNow, -1);
b[x] = y;
posNow = lower_bound(all(coord), b[x]) - coord.begin();
treeB.upd(posNow, b[x]);
cntB.upd(posNow, 1);
ans += cntA.get(posNow) * b[x];
ans += treeA.get(posNow + 1, coord.size() - 1);
}
cout << ans << '\n';
}
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl '\n'
#define fo(i,n) for(int i=0;i<n;++i)
#define fn(i,n) for(int i=1;i<=n;++i)
#define Fo(i,k,n) for(int i=k;i<=n;++i)
typedef long long int lli;
int32_t main(){
FIO
lli n, m; cin >> n >> m;
lli l = m * m;
lli a = 10;
lli b = 1;
while(n > 0){
if(n % 2 > 0) b *= a;
b %= l;
a = a * a;
a %= l;
n /= 2;
}
b /= m;
cout << b % m << endl;
}
| //Don't act like a loser.
//This code is written by huayucaiji
//You can only use the code for studying or finding mistakes
//Or,you'll be punished by Sakyamuni!!!
//#pragma GCC optimize("Ofast","-funroll-loops","-fdelete-null-pointer-checks")
//#pragma GCC target("ssse3","sse3","sse2","sse","avx2","avx")
#include<bits/stdc++.h>
#define int long long
using namespace std;
int read() {
char ch=getchar();
int f=1,x=0;
while(ch<'0'||ch>'9') {
if(ch=='-')
f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9') {
x=x*10+ch-'0';
ch=getchar();
}
return f*x;
}
int n,m;
int qpow(int x,int y) {
int ret=1;
while(y) {
if(y&1) {
ret=ret*x%(m*m);
}
x=x*x%(m*m);
y>>=1;
}
return ret;
}
signed main() {
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
cin>>n>>m;
cout<<qpow(10,n)/m<<endl;
//fclose(stdin);
//fclose(stdout);
return 0;
}
|
#include <bits/stdc++.h>
#define F first
#define S second
#define MAX 10000003
using namespace std;
#define ll long long int
#include<fstream>
#define MOD 1000000007
#define fast ios_base::sync_with_stdio(false);
#define io cin.tie(NULL);
#define inp(arr,n) for(ll i=0;i<n;i++){cin>>arr[i];}
#define print(arr,n) for(ll i=0;i<n;i++){cout<<arr[i]<<" ";}
#define pb push_back
#define all(v) (v).begin(),(v).end()
int main()
{
double x1,y,z;
cin>>x1>>y>>z;
ll ans=((y/x1)*1.0)*z;
if(ans*x1==y*z)
cout<<max(ans-1,0LL)<<endl;
else
cout<<ans<<endl;
return 0;
} | #include<iostream>
#include<math.h>
using namespace std;
int main()
{
float X, Y, Z;
cin >> X >> Y >> Z;
float a, b;
a = Y / X;
b = a * Z;
if (b - floor(b) == 0)
{
cout << floor(b) - 1;
}
else
{
cout << floor(b);
}
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define BE(x) x.begin(), x.end()
int main() {
int a, b;
cin >> a >> b;
int ans = 1;
for (int i = 2; i <= b; i++) {
if (b/i - (a-1)/i >= 2) ans = i;
}
cout << ans << endl;
} | #include <iostream>
#include <algorithm>
#define flush fflush(stdout)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;
const int mod = (int)1e9 + 7, INF = (int)1e9;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };
int main(void)
{
ll s, p, div;
scanf("%lld%lld", &s, &p);
for (div = 1; div * div <= p; div++)
{
if (p % div == 0 && div + p / div == s)
{
printf("Yes\n");
return (0);
}
}
printf("No\n");
return (0);
} |
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <set>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int N = 1e5 + 10;
set<long long> s;
int st[N];
int primes[N];
int cnt;
void get_primes(int n)
{
for (int i = 2; i <= n; i ++ ){
if (!st[i])
primes[cnt ++] = i;
for (int j = 0; primes[j] <= n / i; j ++ ){
st[primes[j] * i] = 1;
if (i % primes[j] == 0)
break;
}
}
}
int main()
{
get_primes(100002);
long long n;
cin >> n;
long long res = n;
long long m = 1e5 + 2;
//cout << st[2] << endl;
for (long long i = 2; i <= 1e5 + 2; i ++ ){
long long t = i * i;
while (1){
if (t > n){
break;
}else{
s.insert(t);
//cout << t << endl;
}
t = t * i;
}
}
long long k = s.size();
cout << res - k << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int i=(a);i<(n);++i)
#define eFOR(i,a,n) for(int i=(a);i<=(n);++i)
#define rFOR(i,a,n) for(int i=(n)-1;i>=(a);--i)
#define erFOR(i,a,n) for(int i=(n);i>=(a);--i)
#define SORT(a) sort(a.begin(),a.end())
#define rSORT(a) sort(a.rbegin(),a.rend())
#define fSORT(a,f) sort(a.begin(),a.end(),f)
#define all(a) a.begin(),a.end()
#define out(y,x) ((y)<0||h<=(y)||(x)<0||w<=(x))
#define tp(a,i) get<i>(a)
#ifdef _DEBUG
#define line cout << "-----------------------------\n"
#define stop system("pause")
#endif
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }
template<class T>inline void print(const T& a) { cout << a << "\n"; }
template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); }
template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); }
template<class T>inline void print(const vector<vector<T>>& v) { for (auto& a : v)print(a); }
inline string reversed(const string& s) { string t = s; reverse(all(t)); return t; }
template<class T>inline T sum(const vector<T>& a, int l, int r) { return a[r] - (l == 0 ? 0 : a[l - 1]); }
template<class T>inline void END(T s) { print(s); exit(0); }
void END() { exit(0); }
int main() {
init();
int n; cin >> n;
FOR(i, 0, n)print(i * 2 % n + 1, (i * 2 + 1) % n + 1);
return 0;
} |
#include"bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ff first
#define ss second
#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define vi vector<int>
#define mii map<int,int>
#define pq_max priority_queue<int>
#define pq_min 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,s,n) for(int i=s;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define allr(c) (c).rbegin(), (c).rend()
#define sz(x) ((int)(x).size())
#define itr_v(v) for(int i=0;i<sz(v);i++)
#define itr_str(s) for(int i=0;i<s.length();i++)
#define endl ("\n")
#define ip(v) for(auto& i:v) cin>>i;
#define ip_2d(a) for(auto &v:a) for(auto &x:v) cin>>x;
#define sumv(a) accumulate(all(a),0)
#define yn(x) ((x)?"YES":"NO")
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#define ci(X) int X; cin>>X
#define cii(X, Y) int X, Y; cin>>X>>Y
#define ciii(X, Y, Z) int X, Y, Z; cin>>X>>Y>>Z
#define ciiii(W, X, Y, Z) int W, X, Y, Z; cin>>W>>X>>Y>>Z
template <typename T> void out(T t) { cout << t << endl; }
#define dbg(x) cout<<#x<<"="<<(x)<<endl;
#define dbg2(x,y) cout<<#x<<"="<<(x)<<" "<<#y<<"="<<(y)<<endl;
#define dbg3(x,y,z) cout<<#x<<"="<<(x)<<" "<<#y<<"="<<(y)<<" "<<#z<<"="<<(z)<<endl;
#define dbg4(x,y,z,w) cout<<#x<<"="<<(x)<<" "<<#y<<"="<<(y)<<" "<<#z<<"="<<(z)<<" "<<#w<<"="<<(w)<<endl;
void io()
{
ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
long long binpow(long long val, long long deg, long long m) {
if (!deg) return 1 % m;
if (deg & 1) return binpow(val, deg - 1, m) * val % m;
long long res = binpow(val , deg >> 1, m);
return (res * res) % m;
}
// int fact[1000010];
// void initfact(int N) {
// fact[0] = 1;
// for (int i = 1; i < N; i++) {
// fact[i] = (fact[i - 1] * i);
// fact[i] %= mod;
// }
// }
// long long nCr(int n, int i) {
// long long res = fact[n];
// long long div = fact[n - i] * fact[i];
// div %= mod; div = binpow(div, mod - 2, mod);
// return (res * div) % mod;
// }
void print(vi a)
{
for (int i = 0; i < sz(a); i++)
cout << a[i] << " ";
cout << endl;
}
void print_2d(vector<vi> &a)
{
const int n = sz(a), m = sz(a[0]);
f(i, 0, n)
{
f(j, 0, m)
{
cout << a[i][j] << " ";
}
cout << endl;
}
}
bool isPrime(int n)
{
if (n == 1) return false;
if (n == 2) return true;
if (n == 3) return true;
f(i, 2, sqrt(n) + 1) if (n % i == 0) return false;
return true;
}
void SieveOfEratosthenes(int n)
{
bool prime[n + 1];
memset(prime, true, sizeof(prime));
for (int p = 2; p * p <= n; p++)
{
if (prime[p] == true)
{
for (int i = p * p; i <= n; i += p)
prime[i] = false;
}
}
for (int p = 2; p <= n; p++)
if (prime[p])
cout << p;
}
void rotate_anti_2d(vector<vi> &a)
{
const int n = sz(a), m = sz(a[0]);
vector<vi> b(m, vi(n));
int i, j;
f(i, 0, n) f(j, 0, m) b[m - 1 - j][i] = a[i][j];
a.swap(b);
}
void ap_18()
{
ci(n);
vi a(n);
ip(a);
mii m;
for(int i=0;i<n;i++)
{
m[a[i]]++;
}
int ans=0;
for(auto it:m)
{
ans+=((it.ss)*(n-it.ss));
}
out(ans/2);
}
int32_t main()
{
io();
ap_18();
return 0;
} | #include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define pb push_back
#define mp make_pair
#define inp(arr, n) \
for (ll i = 0; i < (ll)n; i++) \
cin >> arr[i];
#define fori(i, a, b) for (ll i = a; i < (ll)b; i++)
#define forib(i, a, b) for (ll i = a; i >= (ll)b; i--)
#define printarr(i, n, arr) \
for (ll i = 0; i < n; i++) \
cout << arr[i] << " ";
#define test(x) \
ull x; \
cin >> x; \
while (x--)
const ull mod = 1e9 + 7;
using namespace std;
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ull n;
cin >> n;
ull arr[n];
fori(i, 0, n) cin >> arr[i];
sort(arr, arr + n);
vector<ll> countArr;
ll count = 1;
fori(i, 1, n) {
if (arr[i] == arr[i - 1])
count++;
else {
countArr.pb(count);
count = 1;
}
}
countArr.pb(count);
count = n * (n - 1) / 2;
for (auto i : countArr) {
count -= (i * (i - 1) / 2);
}
cout << count;
return 0;
}
|
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
// a^n (mod.MOD)を求める。計算量はO(logn)
ll modpow(ll a, ll n, ll MOD = mod) {
if(n == 0) {
return 1;
}
if(n%2 == 1) {
return (a * modpow(a, n-1, MOD))%MOD;
}
return (modpow(a, n/2, MOD) * modpow(a, n/2, MOD))%MOD;
}
// nCrをO(r)で求める。
ll Comb(ll n, ll r) {
if(n < r) {
return 0;
}
if(r > n-r) {
return Comb(n, n-r);
}
ll Mul = 1;
ll Div = 1;
rep(i, r) {
Mul *= (n-i);
Div *= (i+1);
Mul %= mod;
Div %= mod;
}
ll res = Mul*modpow(Div, mod-2)%mod;
return res;
}
int main() {
ll n, m;
cin >> n >> m;
ll s = 0;
rep(i, n) {
ll a;
cin >> a;
s += a;
}
out(Comb(n+m, n+s));
re0;
} | #include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <functional>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <bitset>
#include <math.h>
#include <random>
#include <chrono>
using namespace std ;
using ll = long long ;
using ld = long double ;
template<class T> using V = vector<T> ;
template<class T> using VV = V<V<T>> ;
using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end()
ll mod = 1000000007 ;
long double pie = acos(-1) ;
ll INF = 1000000000000 ;
void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
void fix_cout(){cout << fixed << setprecision(20) ;}
template<class T> void chmax(T &a,T &b){if(a<b) a = b ;}
template<class T> void chmin(T &a,T &b){if(a>b) a = b ;}
// fac:階乗, inv:逆元, finv:階乗の逆元
vector<long long> fac,inv,finv ;
// nまでの配列を用意する
void nCr_set(int n){
fac = inv = finv = vector<long long>(n+1,1) ;
for(int i=2;i<=n;i++){
fac[i] = fac[i-1]*i%mod ;
inv[i] = mod-inv[mod%i]*(mod/i)%mod ;
finv[i] = finv[i-1]*inv[i]%mod ;
}
}
// nCrを計算して返す
ll nCr(int n,int r){
if(n<0||r<0||n<r) return 0 ;
if(n==r||r==0) return 1 ;
return fac.at(n)*finv.at(n-r)%mod*finv.at(r)%mod ;
}
// nHrを計算して返す
ll nHr(int n,int r) {
return nCr(n+r-1,n-1) ;
}
// Nが巨大なときにnCrをO(r)で計算して返す
ll nCr_big_n(ll n,ll r){
ll res = 1 ;
for(ll i=n-r+1;i<=n;i++) res = i%mod*res%mod ;
return res*finv[r]%mod ;
}
int main(){
ll n,m ;
cin >> n >> m ;
ll sum = 0 ;
nCr_set(5e6) ;
for(int i=0;i<n;i++){
ll a ; cin >> a ;
sum += a ;
}
if(m<sum){
cout << 0 << endl ;
return 0 ;
}
cout << nCr_big_n(m+n,sum+n) << endl ;
} |
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <queue>
#include <math.h>
#include <assert.h>
#include <set>
#include <map>
#include <bitset>
#include <ctime>
#include <time.h>
#include <algorithm>
#include <cstdio>
#include <fstream>
#include <stack>
#include <ctype.h>
#include <numeric>
#include <sstream>
#include <unistd.h>
#include <unordered_map>
#include <unordered_set>
#include <limits>
#include <random>
#include <chrono>
#include <iomanip>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
using ll = long long;
#define endl '\n'
#define debug(name) DEBUG(#name, (name))
template<typename T>
void DEBUG(string label, T value) {
cerr << "[" << label << " = " << value << "]\n";
}
void solve(){
int n;
cin >> n;
vector<int> arr(n);
vector<ll> pref(n), mx(n, -(1LL<<60));
for(int i = 0; i < n; ++i){
cin >> arr[i];
if(i > 0){
pref[i] = pref[i - 1] + 1LL * arr[i];
mx[i] = max(mx[i - 1], pref[i]);
}
else{
pref[i] = 1LL * arr[i];
mx[i] = pref[i];
}
}
ll ans = 0;
ll cur = 0;
for(int i = 0; i < n; ++i){
ans = max(ans, cur + mx[i]);
cur += pref[i];
}
cout << ans << endl;
}
int main(){
ios::sync_with_stdio(false); cin.tie(nullptr);
solve();
}
| #include <bits/stdc++.h>
#define f first
#define s second
#define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
#define vv(type, name, h, ...) vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...) vector<vector<vector<type>>> name(h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
using namespace std;
typedef long double ld;
typedef long long lli;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<ii> vii;
typedef vector<string> vs;
#define deb(x) cout << #x": " << (x) << endl;
lli gcd(lli a, lli b){return (b?gcd(b,a%b):a);}
lli lcm(lli a, lli b){ if(!a || !b) return 0; return a * b / gcd(a, b); }
int popcount(lli x) { return __builtin_popcountll(x); }
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int n){return uniform_int_distribution<int>(0, n-1)(rng);}
lli poww(lli a, lli b){
lli res =1;
while(b){ if(b&1) res = res * a; a = a*a; b/=2; }
return res;
}
bool isPrime(lli x){
if(x==1 or (x%2==0 and x>2))return 0;
for(lli i = 3; i*i<=x; i+=2)if(x%i==0)return 0;
return 1;
}
vi sieve(int N){
vi m(N+1,0);
vi primes(1,2);
for(int i = 4; i<N; i+=2)m[i]=1;
for(int i = 3; i*i<=N; i+=2)if(!m[i])for(int j = i*i; j<N; j+=i)m[j]=1;
for(int i = 3; i<N; i+=2)if(!m[i])primes.pb(i);
return primes;
}
int dx[4]={0,0,1,-1}, dy[4]={1,-1,0,0};
vvi graph(int n, int m, bool dir=1){
vv(int,v,n+1,0);
fore(i,0,m){
int a,b; cin>>a>>b;
v[a].pb(b);
if(dir)v[b].pb(a);
}
return v;
}
template <typename T> static constexpr T inf = numeric_limits<T>::max() / 2;
// ---- コーディングはここから! ('-')7
void solve(){
int n; cin>>n;
vl v(n); fore(i,0,n)cin>>v[i];
vl pre(n+1,0); fore(i,0,n)pre[i+1]=pre[i]+v[i];
lli sum =0;
lli mx = 0;
lli m = 0;
fore(i,0,n){
m = max(m,pre[i]);
mx = max(mx,sum+m),sum=sum+pre[i+1];
}
mx=max(mx,sum);
cout<<mx<<ENDL;
}
int main(){_
//int t; cin>>t; while(t--)
solve();
}
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fo(i, n) for (int i = 0; i < n; i++)
#define fo1(i, n) for (int i = 1; i <= n; i++)
#define w(n) while (n--)
#define scl(n) scanf("%lld", &n)
#define scf(n) scanf("%lf", &n)
#define pfl(x) printf("%lld\n", x)
#define ps printf(" ")
#define INF 10000000
#define pb push_back
#define all(x) (x).begin(), (x).end()
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
float a, b;
cin >> a >> b;
cout << (a * b) / 100.0;
}
| #define George_Plover
#include <queue>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <algorithm>
#define MAXN 1100000
#define LL long long
using namespace std;
int T;
int L,R;
int main()
{
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&L,&R);
if(L+L>R)
{
printf("0\n");
continue;
}
printf("%lld\n",(R-L-L+1)*1ll*(R-L-L+2)/2);
}
return 0;
}
|
/**
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡀⠀⠀⠀⠀⢀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⡖⠁⠀⠀⠀⠀⠀⠀⠈⢲⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⣼⡏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢹⣧⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⣸⣿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⣿⣇⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⣿⣿⡇⠀⢀⣀⣤⣤⣤⣤⣀⡀⠀⢸⣿⣿⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⢻⣿⣿⣔⢿⡿⠟⠛⠛⠻⢿⡿⣢⣿⣿⡟⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣀⣤⣶⣾⣿⣿⣿⣷⣤⣀⡀⢀⣀⣤⣾⣿⣿⣿⣷⣶⣤⡀⠀⠀⠀⠀
⠀⠀⢠⣾⣿⡿⠿⠿⠿⣿⣿⣿⣿⡿⠏⠻⢿⣿⣿⣿⣿⠿⠿⠿⢿⣿⣷⡀⠀⠀
⠀⢠⡿⠋⠁⠀⠀⢸⣿⡇⠉⠻⣿⠇⠀⠀⠸⣿⡿⠋⢰⣿⡇⠀⠀⠈⠙⢿⡄⠀
⠀⡿⠁⠀⠀⠀⠀⠘⣿⣷⡀⠀⠰⣿⣶⣶⣿⡎⠀⢀⣾⣿⠇⠀⠀⠀⠀⠈⢿⠀
⠀⡇⠀⠀⠀⠀⠀⠀⠹⣿⣷⣄⠀⣿⣿⣿⣿⠀⣠⣾⣿⠏⠀⠀⠀⠀⠀⠀⢸⠀
⠀⠁⠀⠀⠀⠀⠀⠀⠀⠈⠻⢿⢇⣿⣿⣿⣿⡸⣿⠟⠁⠀⠀⠀⠀⠀⠀⠀⠈⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣼⣿⣿⣿⣿⣧⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠐⢤⣀⣀⢀⣀⣠⣴⣿⣿⠿⠋⠙⠿⣿⣿⣦⣄⣀⠀⠀⣀⡠⠂⠀⠀⠀
⠀⠀⠀⠀⠀⠈⠉⠛⠛⠛⠛⠉⠀⠀⠀⠀⠀⠈⠉⠛⠛⠛⠛⠋⠁⠀⠀
**/
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define nl cout<<"\n";
#define ll long long int
#define ld double
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define F(i,a,b) for(i=a;i<b;i++)
//#include <ext/pb_ds/assoc_container.hpp> // policy based data structure header files
//#include <ext/pb_ds/tree_policy.hpp> // policy based data structure header files
#define IOS ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
//using namespace __gnu_pbds; // for pbds
//#define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> // have functions like order_of_key, find_by_order
const double PI = 3.14159265358979323846264338327950288419716939937510582097494459230781641;
const ll M=1e9+7;
const ll MAXN=100200;
ll i,j,mask;
ll mod(ll x)
{
return (x+M)%M;
}
ll add(ll a,ll b)
{
return mod(mod(a)+mod(b));
}
ll mul(ll a,ll b)
{
return mod(mod(a)*mod(b));
}
ll power(ll p,ll x)
{
ll res=1;
while(x>0) {
if(x%2==1) {
res=mul(res,p);
}
x/=2;
p=mul(p,p);
}
return res;
}
void solve()
{
ll n;
cin>>n;
ll sumMinus=0, sumPlus=0;
vector<ll> v(n);
F(i,0,n) {
cin>>v[i];
}
if(n==1) {
cout<<v[0];
} else {
sumMinus=add(v[0], -v[1]);
sumPlus=add(v[0], v[1]);
ll cntPlus=1;
ll cntMinus=1;
F(i,2,n) {
ll mn=add(sumPlus, mul(-1,mul(v[i], cntPlus)) );
ll mx=add(sumPlus, mul(cntPlus, v[i]) );
mx=add(mx, add(sumMinus, mul(cntMinus, v[i]) ));
sumMinus=mn;
sumPlus=mx;
ll tmp=cntPlus;
cntPlus=add(cntPlus, cntMinus);
cntMinus=tmp;
//cout<<sumMinus<<" "<<sumPlus;nl
}
// nl
// cout<<sumMinus<<" "<<sumPlus;nl
ll ans=add(sumMinus, sumPlus);
cout<<ans;
}
}
int main()
{
IOS
/*#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif // ONLINE_JUDGE*/
ll t,test=1;
//cin>>test;
F(t,1,test+1) {
//cout<<"Case #"<<t<<": ";
solve();
nl
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
void solve(){
int n;cin>>n;
vector<int> v(n);
REP(i,n)cin>>v[i];
vector<int> ans;
REP(i,n*n){
if(i&1){
for(int j=1;j<n-1;j+=2){//j:odd
if(v[j]>v[j+1]){
ans.push_back(j+1);
swap(v[j],v[j+1]);
j=n;
}
}
}
else{
for(int j=0;j<n-1;j+=2){
if(v[j]>v[j+1]){
ans.push_back(j+1);
swap(v[j],v[j+1]);
j=n;
}
}
}
if(ans.size()<=i){
bool ok=1;
for(int j=0;j<n;j++)ok&=v[j]==j+1;
if(ok)break;
if((i&1)^((n-2)&1)){
ans.push_back(n-2);
swap(v[n-3],v[n-2]);
}
else{
ans.push_back(n-1);
swap(v[n-2],v[n-1]);
}
}
}
cout<<ans.size()<<endl;for(int p:ans)cout<<p<<" ";cout<<endl;
}
signed main(){
int t;cin>>t;
while(t--)solve();
}
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const long double k=0.6180339887498948482045;
ll x,y,tmp;
vector<int> ans;
int main(){
scanf("%lld",&tmp);if(tmp==0) {printf("0\n");return 0;}
//printf("%lf\n",((long double)tmp)*k-50);
for(ll i=max((ll)(((long double)tmp)*k)-50,0ll);;i++){
x=tmp;y=i;ans.clear();
while(x&&y){
if(x>y) ans.push_back(3),x=x-y;
else ans.push_back(4),y=y-x;
if(ans.size()>130) {break;}
}
if(ans.size()+max(x,y)<=130){
if(x) for(int i=1;i<=x;i++) ans.push_back(1);
else for(int i=1;i<=y;i++) ans.push_back(2);
printf("%d\n",ans.size());
for(int i=ans.size()-1;i>=0;i--) printf("%d\n",ans[i]);
return 0;
}
}
return 0;
}/*
47584759575744849
*/ | #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define debug(output) if(debugFlag)cout<<#output<<"= "<<output<<endl
using lint = long long;
typedef pair<int,int> P;
const bool debugFlag=true;
const lint linf=1e18+7;
const lint inf=1e9+7;
const int MOD=1000000007;
signed main(){
lint n;cin>>n;
queue<int> que;
vector<lint> dp={1,1,2};
while(dp.back()<linf){
int num=dp.size();
dp.push_back(dp[num-1]+dp[num-2]);
}
lint buf=n;
int num=0;
for(int i=dp.size()-1;i>=0;--i){
while(dp[i]<=buf){
buf-=dp[i];
que.push(i);
num=max(num,i);
}
}
vector<int> res;
num+=num%2;
int cnt=num;
que.push(-inf);
rep(i,num){
while(que.front()==cnt){
if(que.front()==cnt){
que.pop();
if(i%2==0)res.push_back(1);
else res.push_back(2);
}
}
if(i%2==0)res.push_back(4);
else res.push_back(3);
--cnt;
}
cout<<res.size()<<"\n";
rep(i,res.size()){
cout<<res[i]<<"\n";
}
return 0;
} |
///Bismillahir Rahmanir Rahim
#include "bits/stdc++.h"
#define ll long long
#define int ll
#define fi first
#define si second
#define mp make_pair
#define pb push_back
#define pi pair<int,int>
#define nd(a,b,c) mp(mp(a,b),c)
#define clr(x) memset(x,0,sizeof(x));
#define f(i,l,r) for(int i=l;i<=r;i++)
#define rf(i,r,l) for(int i=r;i>=l;i--)
#define done(i) cout<<"done = "<<i<<endl;
#define show(x,y) cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
const ll inf=2e18;
const int mod=1e9+7;
const int M=100005;
main()
{
fast
int a,b,c,d;
cin>>a>>b>>c>>d;
int ses=min(a,b);
ses=min(ses,c);
ses=min(ses,d);
cout<<ses<<"\n";
return 0;
}
| #include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e5+7;
int32_t main()
{
int a,b,c,d;
cin>>a>>b>>c>>d;
cout<<min({a,b,c,d})<<endl;
} |
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define f first
#define s second
#define int long long
#define sz(x) (ll)(x.size())
using namespace std;
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
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);
}
const int mod = 1e9+7;
int expo_pow(int x,int y){
if(y == 0) return 1;
y=y%(mod-1);
x%=mod;
if(y==0) y=mod-1;
int res=1;
while(y){
if(y&1) res=(res*x)%mod;
x=(x*x)%mod;
y>>=1;
}
return res;
}
ll add()
{
return 0;
}
template <typename T, typename... Types>
T add(T var1, Types... var2){
return (((((ll)(var1)) % mod + (ll)(add(var2...))) % mod) + mod) % mod;
}
ll mul(){
return 1;
}
template <typename T, typename... Types>
T mul(T var1, Types... var2){
return (((ll)(var1)) % mod * (ll)(mul(var2...))) % mod;
}
int ncr(int n,int r) {
if (n < r) return 0;
int num = n*(n-1);
return num/2;
}
int n,k;
int get(int x) {
int ans = 0;
for (int i = 3; i < x; ++i) {
for (int msk = 0; msk < 8; ++msk) {
int cnt = __builtin_popcount(msk);
if (cnt%2 == 0) ans += ncr(i-3+2 - cnt*(n),2);
else ans -= ncr(i-3+2 - cnt*(n),2);
}
}
return ans;
}
int ncr2(int n,int r) {
if (n < r) return 0;
return n;
}
int get2(int x) {
int ans = 0;
for (int i = 0; i < 4; ++i) {
int cnt = __builtin_popcount(i);
if(cnt%2 == 0) ans += ncr2(x-2+1-cnt*n,1);
else ans -= ncr2(x-2+1-cnt*n,1);
}
return ans;
}
void solve(){
cin >> n >> k;
//cout << get(5) << "\n";
// find beauty
int st = 3;
int end = 3*n;
int tar_beauty = -1;
while (end >= st) {
int mid = (st + end)/2;
int num_less = get(mid);
if (num_less < k) {
tar_beauty = mid;
st = mid + 1;
}
else {
end = mid - 1;
}
}
int to_sub = get(tar_beauty);
k -= to_sub;
int be,ta,pop;
for (int i = 1; i <= min(n,tar_beauty-2); ++i) {
int req = tar_beauty - i;
if (req > 2*n) continue;
int tmp = get2(req);
if (k <= tmp) {
be = i;
for (int i = 1; i <= n; ++i) {
int tmp_pop = req - i;
if (tmp_pop >= 1 and tmp_pop <= n) {
k--;
}
if (k == 0) {
cout << be << " " << i << " " << tmp_pop << "\n";
return;
}
}
break;
}
k-= tmp;
}
}
signed main(){
fast;
int test = 1;
int i=1;
while(test--){
solve();
}
}
| #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 = 1000010;
LL f[4][3 * N], n, k;
int main(){
cin >> n >> k;
f[0][0] = 1;
for (int i = 0; i < 3; i ++) {
for (int j = 0; j <= i * n; j ++){
f[i + 1][j + 1] += f[i][j];
f[i + 1][j + n + 1] -= f[i][j];
}
for (int j = 1; j <= (i + 1) * n; j ++)
f[i + 1][j] += f[i + 1][j - 1];
}
int it = 3;
int sum = 3;
while (k > f[3][it]) k -= f[3][it], sum ++, it ++;
int a = 1, b, c;
for (int i = 1; i <= n; i ++) {
int maxd = min((int)n, sum - i - 1);
int mind = max(1, (int)(sum - i - n));
if (mind > maxd) continue;
if (k <= maxd - mind + 1) {
a = i;
break;
}
k -= (maxd - mind + 1);
}
c = min((int)n, sum - a - 1) - (k - 1);
b = sum - a - c;
cout << a << ' ' << b << ' ' << c;
return 0;
}
|
// Pratiyush Mishra
#include <bits/stdc++.h>
#define ull unsigned long long int
#define ll long long int
#define LL_MAX 9223372036854775807
#define pb push_back
#define pf push_front
#define mp make_pair
#define popb pop_back
#define vl vector<ll>
#define bs(v, x) binary_search(v.begin(), v.end(), x)
#define mem1(a) memset(a, -1, sizeof(a))
#define popf pop_front
#define p() cout << '\n'
#define p0(x) cout << x << " "
#define p1(x) cout << x << '\n'
#define p2(x, y) cout << x << " " << y << '\n'
#define p3(x, y, z) cout << x << " " << y << " " << z << '\n'
#define printv(v) \
for (ll i = 0; i < v.size(); ++i) \
cout << v[i] << " "; \
cout << '\n'
#define pr1(x) cout << fixed << setprecision(15) << x << '\n'
#define ordered_set tree<pair<ll, ll>, null_type, less<pair<ll, ll>>, rb_tree_tag, tree_order_statistics_node_update>
// ordered_set s ; s.order_of_key(val) no. of elements strictly less than val
// s.find_by_order(i) itertor to ith element (0 indexed)
#define mod 1000000007
#define mod1 998244353
#define fio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL)
#define get(n) \
ll n; \
cin >> n
#define getvec(v, n) \
vector<ll> v(n); \
for (ll i = 0; i < n; i++) \
cin >> v[i];
#define getstr(s) \
string s; \
cin >> s
#define all(x) x.begin(), x.end()
#define countBits(x) __builtin_popcount(x)
using namespace std;
//unordered_map < char, vector<pair<int, int>>> e;
vector<vector<pair<int, int>>> e(26);
vector<string> v;
int n, m, sx, sy, gx, gy;
vector<vector<int>> r = {{1, -1, 0, 0} , {0, 0, 1, -1}};
queue<pair<int, int>> q;
vector<int> visx(26);
void mainSolve()
{
cin >> n >> m;
for (int i = 0; i < n; i++)
{
getstr(s);
v.pb(s);
for (int j = 0; j < m; j++)
{
if (s[j] >= 'a' && s[j] <= 'z')
e[s[j] - 'a'].pb({i, j});
else if (s[j] == 'S')
{
sx = i;
sy = j;
}
else if (s[j] == 'G')
{
gx = i;
gy = j;
}
}
}
q.push({sx, sy});
vector<vector<bool>> vis(n, vector<bool>(m, false));
vis[sx][sy] = true;
vector<vector<int>> dis(n, vector<int>(m, 0));
while (!q.empty())
{
ll cx = q.front().first;
ll cy = q.front().second;
q.pop();
if (v[cx][cy] >= 'a' && v[cx][cy] <= 'z' && !visx[v[cx][cy] - 'a'])
{
for (pair<int, int> it : e[v[cx][cy] - 'a'])
{
ll nx = it.first;
ll ny = it.second;
if (vis[nx][ny])
continue;
dis[nx][ny] = dis[cx][cy] + 1;
vis[nx][ny] = true;
q.push({nx, ny});
//p2(nx, ny);
if (nx == gx && ny == gy)
{
p1(dis[nx][ny]);
return;
}
}
visx[v[cx][cy] - 'a'] = true;
}
for (int j = 3; j >= 0; j--)
{
ll nx = cx + r[0][j];
ll ny = cy + r[1][j];
//p2(nx, ny);
if (nx >= 0 && nx < n && ny >= 0 && ny < m && !vis[nx][ny] && v[nx][ny] != '#')
{
vis[nx][ny] = true;
dis[nx][ny] = dis[cx][cy] + 1;
q.push({nx, ny});
//p2(nx, ny);
if (nx == gx && ny == gy)
{
p1(dis[nx][ny]);
return;
}
}
}
}
p1(-1);
}
int main()
{
fio;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
//get(t);
ll t = 1;
while (t--)
{
mainSolve();
}
return 0;
}
| /* _____ __ __
/^--^\ | () )\ \/ /
\____/ |_()_) |__|
/ \ _____ _ __ __ ____ _ ____ ____ _____
| || ()_)| |\ \/ /| ===|| |__ / (__` / () \|_ _|
\__ __/ |_| |_|/_/\_\|____||____|\____)/__/\__\ |_|
|^|^\ \^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|
| | |\ \| | | | | | | | | | | | | | | | | | | | | | | | |
#####/ /#################################################
| | |\/ | | | | | | | | | | | | | | | | | | | | | | | | |
|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|*/
#pragma GCC optimize("O4,unroll-loops,no-stack-protector")
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<ll,ll>;
#define int ll
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Forr(i,a,b) for(int i=a;i>=b;i--)
#define F first
#define S second
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define mkp make_pair
#define MOD (long long)(998244353)
#define INF (1e15)
#define EPS (1e-6)
#ifdef LOCALMEOW
#define debug(...) do{\
cerr << __PRETTY_FUNCTION__ << " - " << __LINE__ <<\
" : ("#__VA_ARGS__ << ") = ";\
_OUT(__VA_ARGS__);\
}while(0)
template<typename T> void _OUT(T x) { cerr << x << "\n"; }
template<typename T,typename...I>
void _OUT(T x,I ...tail) { cerr << x << ", "; _OUT(tail...); }
#else
#define debug(...)
#endif
void INIT(){ ios::sync_with_stdio(false); cin.tie(0); }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
int gcd(int a,int b) { return b==0?a:gcd(b,a%b); }
int lcm(int a,int b) { return a/gcd(a,b)*b; }
int fpow(int b,int p){
int ans=1,now=b;
while(p){
if(p&1) ans=ans*now%MOD;
p/=2; now=now*now%MOD;
}
return ans;
}
double dp[110][110][110];
double go(int a,int b,int c){
if(dp[a][b][c]>=0) return dp[a][b][c];
if(a>=100 || b>=100 || c>=100) return dp[a][b][c]=0;
double ans=1;
ans+=(double)a/(a+b+c)*go(a+1,b,c);
ans+=(double)b/(a+b+c)*go(a,b+1,c);
ans+=(double)c/(a+b+c)*go(a,b,c+1);
return dp[a][b][c]=ans;
}
char g[2010][2010];
bool vis[2010][2010];
int32_t main(){
INIT();
//code...
int n,m; cin>>n>>m;
pii s,t;
vector<vector<pii>> vtp(26);
For(i,0,n+1) For(j,0,m+1){
if(i==0 || j==0 || i==n+1 || j==m+1) g[i][j]='#';
else cin>>g[i][j];
if(g[i][j]=='S') s=mkp(i,j);
else if(g[i][j]=='G') t=mkp(i,j);
else if(g[i][j]>='a' && g[i][j]<='z') vtp[g[i][j]-'a'].eb(i,j);
}
memset(vis,0,sizeof(vis));
queue<pair<pii,int>> que;
que.emplace(s,0);
vis[s.F][s.S]=1;
while(!que.empty()){
pii p=que.front().F;
int d=que.front().S;
que.pop();
if(g[p.F][p.S]=='#') continue;
if(p==t){
cout<<d<<"\n";
return 0;
}
if(g[p.F][p.S]>='a' && g[p.F][p.S]<='z'){
for(auto &i:vtp[g[p.F][p.S]-'a']){
if(!vis[i.F][i.S]){
vis[i.F][i.S]=1;
que.emplace(i,d+1);
}
}
}
if(!vis[p.F+1][p.S]){vis[p.F+1][p.S]=1;que.emplace(mkp(p.F+1,p.S),d+1);}
if(!vis[p.F-1][p.S]){vis[p.F-1][p.S]=1;que.emplace(mkp(p.F-1,p.S),d+1);}
if(!vis[p.F][p.S+1]){vis[p.F][p.S+1]=1;que.emplace(mkp(p.F,p.S+1),d+1);}
if(!vis[p.F][p.S-1]){vis[p.F][p.S-1]=1;que.emplace(mkp(p.F,p.S-1),d+1);}
}
cout<<"-1\n";
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
int main(){
double X , Y , Z ;
cin >> X >> Y >> Z ;
int max_s = 0 ;
for(int i = 0 ; i < 1000000 ; i++){
double t = Y/X ;
double s = (double)i/Z ;
//cout <<fixed << setprecision(10) << s << endl;
if( s < t) max_s = max(max_s , i) ;
else{
break ;
}
}
cout << max_s << endl;
} | #include<bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define MP make_pair
#define PB emplace_back
using namespace std;
const int SIZE = 101;
double dp[SIZE][SIZE][SIZE];
bool visited[SIZE][SIZE][SIZE];
double f(int x, int y, int z) {
if(visited[x][y][z]) { return dp[x][y][z]; }
if(x == 100 || y == 100 || z == 100) { return 0; }
visited[x][y][z] = true;
dp[x][y][z] = 1 + 1. * x / (x + y + z) * f(x + 1 ,y , z) + 1. * y / (x + y + z) * f(x, y + 1, z) + 1. * z / (x + y + z) * f(x, y, z + 1);
return dp[x][y][z];
}
void solve() {
int A, B, C;
cin >> A >> B >> C;
printf("%.12f\n",f(A, B, C));
}
int main() {
solve();
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=1e4+5;
int n,a[2505],top=3;
int main(){
int n=read();
a[1]=6,a[2]=10,a[3]=15;
rep(i,16,10000){
if(i%6==0||i%10==0||i%15==0){
a[++top]=i;
if(top==n)break;
}
}
rep(i,1,n)cout<<a[i]<<" ";
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ll N; cin >> N;
map<int, int> mp;
for (int i = 0; i < N; i++) {
int a; cin >> a;
mp[a]++;
}
ll res = N * N;
for (auto m : mp) {
ll n = m.second;
res -= n * n;
}
cout << res / 2 << endl;
} |
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
using namespace std;
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define int long long
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(i, a) for (auto &i: (a))
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define fr(i, a, b) for (int i = (a); i <= (b); ++i)
typedef long long ll;
typedef long double ld;
void run_case();
int32_t main () {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(20);
#ifndef ONLINE_JUDGE
freopen("in", "r", stdin);
#endif
int t = 1;
// cin >> t;
while (t--) {
run_case();
}
return 0;
}
const int N = 2e5 + 5;
int x[N], id[N];
int n;
set<int> s;
map<int, int> comp;
int pt[N][2];
int dp[N][2];
void run_case() {
cin >> n;
pt[0][0] = pt[0][1] = 0;
for (int i = 1; i <= n; ++i) {
pt[i][0] = 1e9 + 5;
pt[i][1] = -1e9 - 5;
cin >> x[i] >> id[i];
s.insert(id[i]);
}
int cur = 0;
for (auto i : s) comp[i] = ++cur;
for (int i = 1; i <= n; ++i) id[i] = comp[id[i]], pt[id[i]][1] = max(pt[id[i]][1], x[i]), pt[id[i]][0] = min(pt[id[i]][0], x[i]);
pt[(int) comp.size() + 1][0] = 0;
pt[(int) comp.size() + 1][1] = 0;
dp[0][0] = dp[0][1] = 0;
for (int i = 1; i < N; ++i) dp[i][0] = dp[i][1] = 1e18;
for (int i = 1; i <= (int) comp.size() + 1; ++i) {
for (int prv = 0; prv < 2; ++prv) {
for (int cur = 0; cur < 2; ++cur) {
dp[i][cur] = min(dp[i][cur], dp[i - 1][prv] + llabs(pt[i - 1][prv] - pt[i][cur ^ 1]) + llabs(pt[i][cur ^ 1] - pt[i][cur]));
}
}
}
cout << dp[(int) comp.size() + 1][0];
} | #include <bits/stdc++.h>
using namespace std ;
using ll = long long;
#define ffor(n) for(ll i = 0; i < n; i++)
#define fffor(n) for(int j = 0; j < n; j++)
#define mod 1000000007
#define all(v) (v).begin(),(v).end()
using ld = long double;
using pi = pair<int,int>;
using pl = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vd = vector<ld>;
using vpi = vector<pair<int,int>>;
void solve(){
ll n,q;
cin>>n>>q;
vl v(n);
ffor(n)
{
ll a;cin>>a;
v[i] = a;
}
sort(all(v));
while(q--)
{
ll b;cin>>b;
ll k=b;
ll c = -1;
ll it = -2;
ll i = 0;
while(!(c == it))
{
c = it;
it = upper_bound(all(v),b)-v.begin();
if(i)b += (it-c);
else b += it;
i++;
}
cout<<k+it<<"\n";
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t=1;
//cin>>t;
while(t--)
{
solve();
}
return 0;
} |
#pragma warning (disable:4996)
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#define ll long long
#define REP(i, n) for(ll i = 0; i < n; i++)
#define SET(a) ll a = 0; (void)scanf("%lld", &a);
/*
ll cutLog(ll);
ll sum(ll);
*/
ll cutLogNew(ll);
int main() {
SET(n);
if (n == 1 || n == 2)printf("1");
else printf("%lld", n - cutLogNew(n) + 1);
return 0;
}
/*
ll cutLog(ll n) {
ll ans;
REP(i, n + 1) {
if (sum(i + 1) > n + 1) {
ans = i;
break;
}
}
return ans;
}
ll sum(ll n) {
ll sum = 0;
REP(i, n) {
sum += (i + 1);
}
return sum;
}
*/
ll cutLogNew(ll n) {
ll ans = 0;
ll m = n + 1;
REP(i, n) {
m -= (i + 1);
if (m < 0) {
ans = i;
break;
}
}
return ans;
} | #include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define ff first
#define ss second
#define mod 1000000007
#define ull unsigned long long
#define vll vector<ll>
#define uom unordered_map
#define uos unordered_set
#define pll pair<ll, ll>
#define INF 9223372036854775807
#define w(t) ll tests; cin>>tests; while(tests--)
#define endl "\n"
#define pb(x) push_back(x)
#define ppb() pop_back()
#define all(x) x.begin(), x.end()
#define mp(a, b) make_pair(a, b)
#define setp(x, y) fixed << setprecision(x) << y
#define f(i, a, b) for(ll i = a ; i < b ; i++)
#define fo(j, a, b) for(ll j = a ; j >= b ; j--)
#define fill(a, n, x) f(i, 0, n) a[i]=x;
using namespace std;
void init() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
int main() {
init();
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll x;
cin >> x;
if (x < 0)
x = 0;
cout << x;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
void chmin(int& a, int b) {if (b<a) a=b;}
int main() {
int n;
cin >> n;
vector<int> x(n), y(n), z(n);
rep(i,n) cin >> x[i] >> y[i] >> z[i];
vector<vector<int>> dist(n, vector<int>(n));
rep(i,n) rep(j,n)
dist[i][j] = abs(x[j]-x[i])+abs(y[j]-y[i])+max(0,z[j]-z[i]);
vector<vector<int>> dp(1<<n, vector<int>(n,17*3*2000000));
for (int i=1; i<n; i++) dp[1<<i][i]=dist[0][i];
for (int i=0; i<(1<<n); i++) {
int r = (1<<n)-1-i;
while (r>0) {
int j = -r&r; r -= j;
int k = 0; while ((1<<k)!=j) k++;
for (int l=0; l<n; l++)
chmin(dp[i|j][k], dp[i][l]+dist[l][k]);
}
}
cout << dp[(1<<n)-1][0] << endl;
}
| #include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef pair <int,int> pi;
int n;
int a[300005],wi[300005],wi2[300005];
int t[2400005];
void update(int x,int l,int r,int wi) {
if(wi < l||r < wi) return;
if(l == r) {
t[x] = 1; return;
}
int mid = (l + r) >> 1;
update(x*2,l,mid,wi), update(x*2+1,mid+1,r,wi);
t[x] = t[x*2]+t[x*2+1];
}
int query(int x,int l,int r,int rl,int rr) {
if(rl > rr) return 0;
if(rl <= l&&r <= rr) return t[x];
if(rl > r||l > rr) return 0;
int mid = (l + r) >> 1;
return query(x*2,l,mid,rl,rr)+query(x*2+1,mid+1,r,rl,rr);
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n;
for(int i = 1;i <= n;i++) cin >> a[i], wi2[++a[i]] = i;
for(int i = 1;i <= n;i++) {
wi[i] = i;
}
ll ans = 0;
for(int i = 1;i <= n;i++) {
ans += query(1,1,2*n,n+wi[a[i]],2*n);
update(1,1,2*n,n+wi[a[i]]);
}
vector <ll> Ans;
for(int i = n;i >= 1;i--) {
ans -= n-wi[a[i]];
ans += wi[a[i]]-1;
Ans.push_back(ans);
}
reverse(Ans.begin(),Ans.end());
for(ll i : Ans) cout << i << '\n';
}
|
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline int my_getchar_unlocked(){
static char buf[1048576];
static int s = 1048576;
static int e = 1048576;
if(s == e && e == 1048576){
e = fread_unlocked(buf, 1, 1048576, stdin);
s = 0;
}
if(s == e){
return EOF;
}
return buf[s++];
}
inline void rd(int &x){
int k;
int m=0;
x=0;
for(;;){
k = my_getchar_unlocked();
if(k=='-'){
m=1;
break;
}
if('0'<=k&&k<='9'){
x=k-'0';
break;
}
}
for(;;){
k = my_getchar_unlocked();
if(k<'0'||k>'9'){
break;
}
x=x*10+k-'0';
}
if(m){
x=-x;
}
}
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);
}
int WRITER_DOUBLE_DIGIT = 15;
inline int writerDigit_double(){
return WRITER_DOUBLE_DIGIT;
}
inline void writerDigit_double(int d){
WRITER_DOUBLE_DIGIT = d;
}
inline void wt_L(double x){
const int d = WRITER_DOUBLE_DIGIT;
int k;
int r;
double v;
if(x!=x || (x==x+1 && x==2*x)){
my_putchar_unlocked('E');
my_putchar_unlocked('r');
my_putchar_unlocked('r');
return;
}
if(x < 0){
my_putchar_unlocked('-');
x = -x;
}
x += 0.5 * pow(0.1, d);
r = 0;
v = 1;
while(x >= 10*v){
v *= 10;
r++;
}
while(r >= 0){
r--;
k = floor(x / v);
if(k >= 10){
k = 9;
}
if(k <= -1){
k = 0;
}
x -= k * v;
v *= 0.1;
my_putchar_unlocked(k + '0');
}
if(d > 0){
my_putchar_unlocked('.');
v = 1;
for(r=(0);r<(d);r++){
v *= 0.1;
k = floor(x / v);
if(k >= 10){
k = 9;
}
if(k <= -1){
k = 0;
}
x -= k * v;
my_putchar_unlocked(k + '0');
}
}
}
double dp[101][101][101];
int main(){
int i;
int A;
rd(A);
int B;
rd(B);
int C;
rd(C);
for(i=(100)-1;i>=(A);i--){
int j;
for(j=(100)-1;j>=(B);j--){
int k;
for(k=(100)-1;k>=(C);k--){
if(i+j+k > 0){
dp[i][j][k] = 1 + (dp[i+1][j][k] * i + dp[i][j+1][k] * j + dp[i][j][k+1] * k) / (i+j+k);
}
}
}
}
wt_L(dp[A][B][C]);
wt_L('\n');
return 0;
}
// cLay version 20201123-1
// --- original code ---
// double dp[101][101][101];
// {
// int @A, @B, @C;
// rrep(i,A,100) rrep(j,B,100) rrep(k,C,100) if(i+j+k > 0){
// dp[i][j][k] = 1 + (dp[i+1][j][k] * i + dp[i][j+1][k] * j + dp[i][j][k+1] * k) / (i+j+k);
// }
// wt(dp[A][B][C]);
// }
| #include <iostream>
#include <iomanip>
using namespace std;
long double dp[100][100][100];
long double solve(int a, int b, int c, int cnt) {
// basis
if (a == 100 || b == 100 || c == 100)
{
return cnt;
}
if (dp[a][b][c] != 0)
{
return dp[a][b][c];
}
long double ret = 0;
// a + 1
ret += solve(a + 1, b, c, cnt + 1) * a / (a + b + c);
// b + 1
ret += solve(a, b + 1, c, cnt + 1) * b / (a + b + c);
// c + 1
ret += solve(a, b, c + 1, cnt + 1) * c / (a + b + c);
return dp[a][b][c] = ret;
}
int main() {
int a, b, c;
cin >> a >> b >> c;
cout << setprecision(12) << solve(a, b, c, 0) << endl;
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
// --------------------------------------------------------
template<class T> bool chmax(T& a, const T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, const T b) { if (b < a) { a = b; return 1; } return 0; }
#define FOR(i,l,r) for (int i = (l); i < (r); ++i)
#define RFOR(i,l,r) for (int i = (r)-1; (l) <= i; --i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define MIN(c) *min_element(ALL(c))
#define MAX(c) *max_element(ALL(c))
#define SUM(c) accumulate(ALL(c), 0)
#define SUMLL(c) accumulate(ALL(c), 0LL)
#define SZ(c) ((int)(c).size())
#define CIN(c) cin >> (c)
#define COUT(c) cout << (c) << '\n'
#define debug(x) cerr << #x << " = " << (x) << '\n';
using P = pair<int,int>;
using VP = vector<P>;
using VVP = vector<VP>;
using VS = vector<string>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<ll>;
using VVLL = vector<VLL>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
static const double EPS = 1e-10;
static const double PI = acos(-1.0);
static const ll MOD = 1000000007;
// static const ll MOD = 998244353;
static const int INF = (1 << 30) - 1; // 1073741824 - 1
// static const ll INF = (1LL << 62) - 1; // 4611686018427387904 - 1
// --------------------------------------------------------
// #include <atcoder/all>
// using namespace atcoder;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(15);
ll r1, c1; cin >> r1 >> c1;
ll r2, c2; cin >> r2 >> c2;
ll dr = llabs(r1 - r2);
ll dc = llabs(c1 - c2);
if (r1 == r2 && c1 == c2) { COUT(0); return 0; }
if (dr + dc <= 3) { COUT(1); return 0; }
if (dr == dc) { COUT(1); return 0; }
if (dr + dc <= 6) { COUT(2); return 0; }
if (llabs(dr - dc) % 2 == 0) { COUT(2); return 0; }
if (llabs(dr - dc) <= 3) { COUT(2); return 0; }
COUT(3); return 0;
return 0;
}
| #include<bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
using namespace std;
typedef long long ll;
vector<ll> ans_vec(500,0);
ll H,W,A,B;
void dfs(ll a,ll k,ll board[]){
if(k == A){
ans_vec[a]++;
}
for(ll h=0;h<H;h++){
for(ll w=0;w<W;w++){
if(k < a){
if(w == W-1)
continue;
if(board[h*H+w] == 1 || board[h*H+w+1] == 1)
continue;
ll copy_board[500];
rep(i,500)
copy_board[i] = board[i];
copy_board[h*H+w] = 1;
copy_board[h*H+w+1] = 1;
dfs(a,k+1,copy_board);
}
else{
if(h == H-1)
continue;
if(board[h*H+w] == 1 || board[h*H+w+H] == 1)
continue;
ll copy_board[500];
rep(i,500)
copy_board[i] = board[i];
copy_board[h*H+w] = 1;
copy_board[h*H+w+H] = 1;
dfs(a,k+1,copy_board);
}
}
}
}
ll frac(ll a){
if(a == 0)
return 1;
else
return a*frac(a-1);
}
int main(){
ll ans = 0;
cin >> H >> W >> A >> B;
if(H < W){
ll tmp = W;
W = H;
H = tmp;
}
//0...縦 1...横
for(ll a = 0; a <= A; a++){
ll board[500];
memset(board,0,sizeof(board));
dfs(a,0,board);
}
for(ll a = 0; a <= A;a++){
ans += ans_vec[a]/(frac(a)*frac(A-a));
}
cout << ans << endl;
}
|
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <bitset>
#include <vector>
#include <cstdio>
#include <string>
#include <cassert>
#include <climits>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define PB push_back
#define MP make_pair
#define SZ(v) ((int)(v).size())
#define abs(x) ((x) > 0 ? (x) : -(x))
#define FOREACH(e,x) for(__typeof(x.begin()) e=x.begin();e!=x.end();++e)
typedef long long LL;
const int maxn = 105;
int n;
int x[maxn], y[maxn];
double d[maxn][maxn];
struct DisJointSet{
int rank[maxn], parent[maxn];
void init(int n) {
for (int i = 0; i < n; i++) {
rank[i] = 0;
parent[i] = i;
}
}
int Find(int x) {
if (parent[x] == x) return x;
return parent[x] = Find(parent[x]);
}
void Union(int x, int y) {
x = Find(x);
y = Find(y);
if (x == y) return;
if (rank[x] >= rank[y]) {
parent[y] = x;
if (rank[x] == rank[y])
rank[x]++;
}
else {
parent[x] = y;
}
}
int count(int n) {
int ret = 0;
for (int i = 0; i < n; i++)
ret += Find(i) == i;
return ret;
}
}uf;
double distance(int x1, int y1, int x2, int y2) {
return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
bool check(double r) {
int s = n, t = n + 1;
uf.init(n + 2);
for (int i = 0; i < n; i++) {
if (100 - y[i] <= 2 * r) {
uf.Union(s, i);
}
if (y[i] - (-100) <= 2 * r) {
uf.Union(i, t);
}
}
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (d[i][j] <= 2 * r) {
uf.Union(i, j);
}
}
}
return uf.Find(s) == uf.Find(t);
}
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> x[i] >> y[i];
}
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
d[i][j] = d[j][i] = distance(x[i], y[i], x[j], y[j]);
}
}
double lo = 0, hi = 200, res;
while (hi - lo > 1e-5) {
double mid = (lo + hi) / 2;
if (check(mid)) {
res = mid;
hi = mid;
} else {
lo = mid;
}
}
printf("%.4f\n", res);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;
template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (ll i=(ll)N-1; i>=0; i--)
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const ll INF = pow(2,30)-1;
vector<ll> fac;
void c_fac(ll x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { ll d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll modpow(ll x, ll p) { ll result = 1, now = 1, pm = x; while (now<=p) { if (p&now) { result = result * pm % MOD; } now*=2; pm = pm*pm % MOD; } return result; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }
struct coord {
double x, y; ll i;
bool operator< (const coord &c) const { return x<c.x||(x==c.x&&y<c.y); };
};
struct dist {
ll x, y; double d;
bool operator< (const dist &c) const { return d<c.d; };
};
dist calc_d(coord x, coord y) {
double d = sqrt(pow(x.x-y.x,2)+pow(x.y-y.y,2));
return {x.i, y.i, d};
}
// ----------------------------------------------------------------------
// ----------------------------------------------------------------------
struct UnionFind {
vector<int> par, s;
UnionFind(int N) : par(N), s(N) { rep(i,N) { par[i] = i; s[i] = 1; } }
int root(int x) { return par[x]==x ? x : par[x] = root(par[x]); }
int size(int x) { return par[x]==x ? s[x] : s[x] = size(root(x)); }
void unite(int x, int y) { int rx=root(x), ry=root(y); if (rx!=ry) { s[rx] += s[ry]; par[ry] = rx; } }
bool same(int x, int y) { int rx=root(x), ry=root(y); return rx==ry; }
};
// ----------------------------------------------------------------------
// ----------------------------------------------------------------------
int main() {
ll N; cin >> N;
coord c[N]; rep(i,N) { cin >> c[i].x >> c[i].y; c[i].i = i+1; }
vector<dist> d;
rep(i,N) repr(j,i+1,N) d.push_back(calc_d(c[i], c[j]));
rep(i,N) {
d.push_back({0 ,c[i].i,c[i].y+100.0});
d.push_back({N+1,c[i].i,100.0-c[i].y});
}
sort(all(d));
// for (auto x: d) cout << x.x << "-" << x.y << ": " << x.d << endl;
UnionFind uf(N+2);
double result;
for (auto x: d) {
uf.unite(x.x, x.y);
if (uf.same(0,N+1)) {
result = x.d/2;
break;
}
}
cout << setprecision(10) << result << endl;
return 0;
} |
/* _____________________
|Author : canhnam357|
|___________________|
*/
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <string> vs;
typedef vector <vector <int>> vvi;
typedef vector <vll> vvll;
typedef map<int, int> mi;
typedef map<string, int> ms;
typedef map<char, int> mc;
typedef map <int, bool> mb;
typedef map<ll, ll> mll;
typedef unordered_map<int, int> umi;
typedef unordered_map<string, int> ums;
typedef unordered_map<char, int> umc;
typedef unordered_map <int, bool> umb;
typedef unordered_map<ll, ll> umll;
typedef vector <ld> vld;
typedef vector <bool> vb;
typedef pair <int, int> pii;
typedef pair<ll, ll> pll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
int CASE = 1;
const int mxn = 4e3 + 1;
const ll INF = 1e10;
#define FOR(i,N) for(ll i = 0 ; i < N;i++)
#define eFOR(i,a,b) for(ll i = a; i <=b;i++)
#define dFOR(i,N) for(ll i = N - 1; i>=0;i--)
#define edFOR(i,b,a) for(ll i = b ; i >=a;i--)
#define all(x) x.begin(),x.end()
#define SORT(x) sort(all(x))
#define RSORT(x) sort(x.rbegin(),x.rend())
#define UNQ(x) unique(all(x))
#define mine(x) min_element(all(x))
#define maxe(x) max_element(all(x))
#define lb(v, x) lower_bound(all(v) , x)
#define ub(v , x) upper_bound(all(v) , x)
#define pb push_back
#define PI 3.141592653589793
#define FIX cout << fixed << setprecision(15)
#define g(i , a) get<i>(a)
const ll mod = 2e5;
int a[1000000];
bool prime(ll n)
{
if (n <= 1)
return false;
eFOR(i, 2, sqrt(n))
if (!(n % i))
return false;
return true;
}
ll __gcd(ll a, ll b)
{
return !b ? a : __gcd(b, a % b);
}
bool cpx(pair<pii, pii> a, pair<pii, pii> b)
{
return a.first.first < b.first.first;
}
bool cpy(pair<pii, pii> a, pair<pii, pii> b)
{
return a.second.first < b.second.first;
}
void solve()
{
int n;
cin >> n;
vector <pair<pii, pii>> v;
vi vx, vy;
vb ok(n, false);
FOR(i, n)
{
int x, y;
cin >> x >> y;
v.push_back(make_pair(make_pair(x, i), make_pair(y, i)));
}
sort(all(v), cpx);
set <pair <pii, pii>> s;
s.insert(v[0]);
s.insert(v[1]);
s.insert(v[n - 2]);
s.insert(v[n - 1]);
sort(all(v), cpy);
s.insert(v[0]);
s.insert(v[1]);
s.insert(v[n - 2]);
s.insert(v[n - 1]);
vector <pair<pii, pii>> vec(all(s));
vi ans;
for (int i = 0; i < vec.size() - 1; i++)
{
for (int j = i + 1; j < vec.size(); j++)
{
ans.push_back(max(abs(vec[i].first.first - vec[j].first.first), abs(vec[i].second.first - vec[j].second.first)));
}
}
RSORT(ans);
cout << ans[1];
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int T = 1;
while (T--)
{
solve();
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
#define all(m) m.begin(),m.end()
#define sz(m) lld(m.size())
#define pb push_back
#define mod 1000000007
#define st first
#define nd second
#define endl "\n"
#ifdef LOCAL
#define debug(...) debug_out(#__VA_ARGS__, __VA_ARGS__)
#define debug2(v,a,b) debug2_out(#v,v,a,b)
#else
#define debug(...)
#define debug2(v,a,b)
#endif
const int N=1e6+100;
void swagWaalaFunction()
{
lld l,r,ans=0;
cin>>l>>r;
vector<lld> nfac(N);
// Counts number of factors
// stores -ve value if it is of form a1^x1 * a2^x2 ...., where a1,a2 are primes and some xi%2==0
// Used to calculate mobius
for(lld i=2;i<=r;i++)
{
if(nfac[i])
continue;
for(lld j=i;j<=r;j+=i)
nfac[j]++;
for(lld j=i*i;j<=r;j+=i*i)
nfac[j]=-1e18;
}
// MOBIOUS MAGICCCC !!!
for(lld i=2;i<=r;i++)
{
if(nfac[i]<0)
continue;
lld cnt=r/i-(l-1)/i;
lld pairs=cnt*(cnt-1)/2;
if(nfac[i]%2)
ans+=pairs;
else
ans-=pairs;
}
// Remove multiples
for(lld i=max(2LL,l);i<=r;i++)
ans-=(r/i-1);
ans*=2; // x,y and y,x are different
cout<<ans<<endl;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
lld tc=1;
//cin>>tc;
for(int i=0;i<tc;i++)
{
// cout<<"Case #"<<i+1<<": ";
swagWaalaFunction();
}
return 0;
} |
#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define mp make_pair
#define pb push_back
#define pll pair<LL,LL>
#define pii pair<int,int>
#define y second
#define x first
#define LL long long
#define ULL unsigned long long
#define sqr(x) ((x)*(x))
#define pi acos(-1)
#define pdd pair<double,double>
#define MEM(x) memset(x,0,sizeof(x))
#define MEMS(x) memset(x,-1,sizeof(x))
using namespace std;
void solve(){
LL n;
scanf("%lld",&n);
LL tmp=n+1;
LL Max=2e9+10,Min=0;
while(Max>Min+1){
LL mid=(Max+Min)/2;
if(mid*(mid+1)/2<=n+1)Min=mid;
else Max=mid;
}
printf("%lld\n",n+1-Min);
}
int main(){
int t=1;
// scanf("%d",&t);
while(t--){
solve();
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
long N;
cin >> N;
long count = 0;
long tasu = 0;
for(long i = 1; i <= N+1; i++) {
tasu += i;
if(tasu > N+1) break;
count++;
}
cout << N + 1 - count << endl;
} |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
const ll mod=998244353;
const int N=2e6+1;
int n,k;
char c[101];
ll md[101];
char dp[101][101];//
char win(char x,char y){
if(x==y) return x;
if(x+y=='P'+'S') return 'S';
if(x+y=='P'+'R') return 'P';
return 'R';
}
int main(){
ios::sync_with_stdio(false);cin.tie(0);
cin >> n >> k;
md[0]=1;
for(int i=0; i<n ;i++){
cin >> c[i];
dp[0][i]=c[i];
}
md[0]=1;
for(int j=1; j<=k ;j++){
md[j]=md[j-1]*2%n;
}
for(int i=1; i<=k ;i++){
for(int j=0; j<n ;j++){
dp[i][j]=win(dp[i-1][j],dp[i-1][(j+md[i-1])%n]);
}
}
cout << dp[k][0] << '\n';
} | #include <bits/stdc++.h>
using namespace std;
//const long nPrime = 1000000007;
//const long nPrime = 998244353;
int main() {
long n,k;
cin >> n >> k;
vector<vector<long>> vviGrid(n,vector<long>(n));
for(long i = 0; i < n; i++){
for(long j = 0; j < n; j++){
cin >> vviGrid[i][j];
}
}
long iOK = 2e9, iNG = -1;
while(iOK - iNG > 1){
long iTmp = (iOK+iNG)/2;
vector<vector<long>> vviGridThis(n,vector<long>(n));
for(long i = 0; i < n; i++){
for(long j = 0; j < n; j++){
vviGridThis[i][j] = (iTmp<vviGrid[i][j]) ? 1 : 0;
}
}
vector<vector<long>> vviSum(n+1,vector<long>(n+1,0));
for(long i = 1; i <= n; i++){
for(long j = 1; j <= n; j++){
vviSum[i][j] = vviSum[i-1][j]+vviSum[i][j-1]-vviSum[i-1][j-1]+vviGridThis[i-1][j-1];
}
}
long iMin = 1e9;
for(long i = k; i <= n; i++){
for(long j = k; j <= n; j++){
long iThis = vviSum[i][j]-vviSum[i][j-k]-vviSum[i-k][j]+vviSum[i-k][j-k];
iMin = min(iMin, iThis);
}
}
if(iMin >= (k*k)/2+1){
iNG = iTmp;
} else {
iOK = iTmp;
}
}
cout << iOK << endl;
return 0;
} |
// Rakib (CSE'19)
#include<bits/stdc++.h>
#include<iostream>
#include<queue>
#include<stack>
#include<set>
#include<iomanip>
#include<iterator>
#include<sstream>
#include<algorithm>
#include<vector>
#include<string>
#include<cstdlib>
#include<cmath>
#include<map>
#define boost_ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define read(i,n,a) for(i=0;i<n;++i) cin>>a[i]
#define print(i,a) for(auto i:a) cout<<i<< " " ; cout<<endl ;
#define dpoint(n) cout<<showpoint<<fixed<<setprecision(n)
#define MOD 1000000007
#define llmax LONG_LONG_MAX
#define llmin LONG_LONG_MIN
#define read_grid(i,j,n,m,a) for(i=0;i<n;++i) for(j=0;j<m;++j) cin >> a[i][j];
#define all(a) a.begin(),a.end()
#define vl vector<ll>
#define MP make_pair
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
int gcd(int x,int y){
if(!y) return x;
return gcd(y,x%y);
}
/*ll MX=100001;
//vector<ll>check(MX,1), divisor(MX,2);
//vector<ll>primes,divisor;
void prime(){
ll i,j;
//check[1]=0;
//check[2]=1;
//primes.pb(2);
for(i=3;i<MX;i+=2){
if(check[i]){
//primes.pb(i);
divisor[i]=i;
for(j=i*i;j<MX;j+=2*i) divisor[j]=i, check[j]=0;
}
}
} */
ll power_mod(ll b,ll p){
ll ans=1;
b%=MOD; //if b>MOD;
if(!b) return 0 ;
while(p){
if(p%2) ans=(ans*b)%MOD;
p>>=1; // top to bottom
b=(b*b)%MOD; // bottom to top
}
return ans;
}
bool cmp(const pair<ll,ll> &a, const pair<ll,ll> &b){ return 2*a.first+a.second>2*b.first+b.second; }
void task(ll case_no){
ll n;
cin >> n;
vector<pair<ll,ll>>a;
ll sum=0,cnt=n;
while(n--){
ll x,y;
cin >> x >> y;
a.pb({x,y});
sum+=x;
}
sort(all(a),cmp);
ll sum1=0,i;
for(i=0;i<a.size();++i){
sum1+=a[i].first +a[i].second;
sum-=a[i].first;
if(sum1>sum) break;
}
cout << i+1 << "\n";
}
int main(){
boost_;
//prime();
ll t=1,i=0;
//cin >> t;
while(t--){
task(++i);
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
struct edge {int to, cost; };
int main(){
int n;
cin >> n;
ll sa = 0;
ll delta[n];
for(int i=0; i<n; i++){
ll a, b;
cin >> a >> b;
sa += a;
delta[i] = 2*a+b;
}
sort(delta, delta+n, greater<ll>());
int ans = 0;
for(int i=0; i<n; i++){
if(sa<0) break;
sa -= delta[i];
ans++;
}
cout << ans << endl;
} |
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
const int N=5e6+5;
const int M=1e5+5;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
const double eps=1e-8;
const long double pi=acos(-1.0L);
#define ls (i<<1)
#define rs (i<<1|1)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mem(a,b) memset(a,b,sizeof(a))
LL read()
{
LL x=0,t=1;
char ch;
while((ch=getchar())<'0'||ch>'9') if(ch=='-') t=-1;
while(ch>='0'&&ch<='9'){ x=(x<<3)+(x<<1)+ch-'0'; ch=getchar(); }
return x*t;
}
int a[N],ans[N];
int main()
{
int T=read();
while(T--)
{
//并不需要考虑去将每一个数字归位,而是可以直接考虑减少逆序对(交换相邻的逆序数字)
int n=read(),tot=0;
for(int i=1;i<=n;i++) a[i]=read();
for(int k=0;;k^=1){
int flag=0;
for(int i=1;i<n;i++)
if(a[i]>a[i+1]) flag=1;
if(!flag) break;
int i;
for(i=k+1;i<n&&a[i]<a[i+1];i+=2);
if(i>=n) i-=2;
ans[++tot]=i;
swap(a[i],a[i+1]);
}
printf("%d\n",tot);
for(int i=1;i<=tot;i++) printf("%d%c",ans[i],i==tot?'\n':' ');
}
return 0;
}
| #include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)
void testcase(){
int N; cin >> N;
vector<int> A(N); rep(i,N) cin >> A[i];
vector<int> ans;
int turn = 0;
auto op = [&ans,&A,&turn](int p)->void{
swap(A[p],A[p+1]);
ans.push_back(p+1);
turn ^= 1;
};
while(A.size() >= 4){
int p = -1;
rep(i,A.size()) if(A[i] == A.size()) p = i;
if(p%2 != turn){
int x = -1;
if(p == 0) op(1);
if(p == 1) op(2);
if(p == 2){ op(1); op(2); p=1; }
if(p >= 3 && p%2 == 1) op(0);
if(p >= 4 && p%2 == 0) op(1);
}
while(p != A.size()-1){
op(p++);
}
A.pop_back();
}
vector<int> tg(A.size());
rep(i,tg.size()) tg[i] = i+1;
while(tg != A) op(turn);
cout << ans.size() << "\n";
rep(i,ans.size()){
if(i) cout << " ";
cout << ans[i];
}
cout << "\n";
}
int main(){
int T; cin >> T;
while(T--) testcase();
return 0;
}
struct ios_do_not_sync{
ios_do_not_sync(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
}
} ios_do_not_sync_instance;
|
#include<bits/stdc++.h>
using namespace::std;
class Advertisement{
public:
void set_val(int x,int y,int inr);
long get_height();
long get_width();
long a;
long b;
long c;
long d;
long s;
long r;
};
void Advertisement::set_val(int x,int y,int inr){
a = x;
b = y;
c = x+1;
d = y+1;
r = inr;
s = 1;
}
long Advertisement::get_width(){
return d-b;
}
long Advertisement::get_height(){
return c-a;
}
int main(){
long n;
cin >> n;
long x,y,r;
Advertisement *ad = new Advertisement[n];
for(int i=0;i<n;i++){
cin >> x >> y >> r;
ad[i].set_val(x,y,r);
}
for(int i=0;i<n;i++){
cout << ad[i].a << ' ' << ad[i].b << ' ' << ad[i].c << ' ' << ad[i].d << ' ' << endl;
}
}
| #include<stdio.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include <cassert>
#include <numeric>
#include <unordered_map>
//#include <atcoder/all>
#include <queue>
#include <math.h>
#include <climits>
#include <set>
#include <map>
//using namespace atcoder;
typedef long long ll;
#define FOR(i, a, b) for(ll i=(a); i<(b);i++)
#define REP(i, n) for(ll i=0; i<(n);i++)
#define ROF(i, a, b) for(ll i=(b-1); i>=(a);i--)
#define PER(i, n) for(ll i=n-1; i>=0;i--)
#define REPREP(i,j,a,b) for(ll i=0;i<a;i++)for(ll j=0;j<b;j++)
#define VV(type) vector<vector<type>>
#define VV2(type,n,m,val) vector<vector<type>> val;val.resize(n);for(ll i;i<n;i++)val[i].resize(m)
#define vec(type) vector<type>
#define VEC(type,n,val) vector<type> val;val.resize(n)
#define VL vector<ll>
#define SZ size()
#define all(i) begin(i),end(i)
#define SORT(i) sort(all(i))
#define max(a,b) a>b?a:b
using namespace std;
int main() {
ll n;
cin >> n;
VL x(n),y(n),r(n);
ll mi = n;
ll mx = 0;
REP(i, n) {
cin >> x[i] >> y[i] >> r[i];
if (mx < r[i]) {
mx = r[i];
mi = i;
}
}
if (1.25*1e9 < mx * n) {
REP(i, n) {
if (i == mi) {
cout << x[(i + 0) % n] <<" "<< y[(i + 0) % n] << " " << x[(i + 0) % n] + 1 << " " << y[(i + 0) % n] + 1<<endl;
}
else if ((i + 1) % n == mi) {
cout << x[(i + 2) % n] << " " << y[(i + 2) % n] << " " << x[(i + 2) % n] + 1 << " " << y[(i + 2) % n] + 1 << endl;
}
else {
cout << x[(i + 1) % n] << " " << y[(i + 1) % n] << " " << x[(i + 1) % n] + 1 << " " << y[(i + 1) % n] + 1 << endl;
}
}
}
else {
REP(i, n) {
cout << x[(i + 1) % n] << " " << y[(i + 1) % n] << " " << x[(i + 1) % n] + 1 << " " << y[(i + 1) % n] + 1 << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;
using LD = long double;
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 coutall(T v) { if(v.empty()){cout << endl; return;} for(auto i = v.begin(); i != --v.end(); i++){cout << *i << " ";} cout << *--v.end() << endl; }
template <typename T> void DEBUGall(T v) { if(v.empty()){cerr << endl; return;} for(auto i = v.begin(); i != --v.end(); i++){cerr << *i << " ";} cerr << *--v.end() << endl; }
inline void IN(void){ return; }
template <typename First, typename... Rest> void IN(First& first, Rest&... rest){ cin >> first; IN(rest...); return; }
inline void OUT(void){ cout << "\n"; return; }
template <typename First, typename... Rest> void OUT(First first, Rest... rest){ cout << first << " "; OUT(rest...); return; }
inline void DEBUG(void){ cerr << "\n"; return; }
template <typename First, typename... Rest> void DEBUG(First first, Rest... rest){ cerr << first << " "; DEBUG(rest...); return; }
void yes(bool ok = true){ cout << (ok ? "yes" : "no") << endl; }
void Yes(bool ok = true){ cout << (ok ? "Yes" : "No") << endl; }
void YES(bool ok = true){ cout << (ok ? "YES" : "NO") << endl; }
ll myceil(ll a, ll b) { return a >= 0 ? (a+b-1)/b : -((-a)/b); }
ll myfloor(ll a, ll b) { return a >= 0 ? a/b : -myceil(-a, b); }
void Main(){
int h, w, x, y; IN(h, w, x, y);
x--; y--;
vector<string> s(h);
rep(i, h) cin >> s[i];
int ans = 1;
rep3(i, x, x){
rep3(j, y+1, w-1){
if(s[i][j] == '.') ans++;
else break;
}
rep3rev(j, y-1, 0){
if(s[i][j] == '.') ans++;
else break;
}
}
rep3(j, y, y){
rep3(i, x+1, h-1){
if(s[i][j] == '.') ans++;
else break;
}
rep3rev(i, x-1, 0){
if(s[i][j] == '.') ans++;
else break;
}
}
OUT(ans);
return;
}
int main(){
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(15);
Main();
return 0;
} | #include<bits/stdc++.h>
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define ll long long
#define ii pair<ll,ll>
#define vi vector<ll>
#define vii vector<ii>
#define INF 1000000000
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_multiset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
ll nni[2000005],fni[2000005],fact[2000005];
const ll md=1e9+7;
void ion()
{
nni[0]=nni[1]=1;
for(int i=2;i<2000005;i++)
{
nni[i]=nni[md%i]*(md-md/i)%md;
}
}
void iof()
{
fni[0]=fni[1]=1;
for(int i=2;i<2000005;i++)
{
fni[i]=(nni[i]*fni[i-1])%md;
}
}
void fac()
{
fact[0]=1;
for(int i=1;i<2000005;i++)
{
fact[i]=(fact[i-1]*i)%md;
}
}
int main(){
IOS
ll t;
t=1;
ion();
iof();
fac();
while(t--)
{
ll w,b,k;
cin>>w>>b>>k;
if(w>b+k){cout<<"0"<<"\n";return 0;}
ll to=(((fact[w+b]*fni[w-(k+1)])%md)*fni[b+k+1])%md;
ll ans=(((((fact[w+b]*fni[w])%md)*fni[b])%md)-to+md)%md;
cout<<ans<<"\n";
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5+5;
int readint(){
int x=0,f=1;char s=getchar();
#define sc (s=getchar())
while(s<'0'||s>'9'){
if(s=='-')
f=-1;
sc;
}
while(s>='0'&&s<='9'){
x=(x<<3)+(x<<1)+(s^48);
sc;
}
#undef sc
return x*f;
}
struct zz{
int u,v,w;
}s[maxn];
struct edge{
int v,w,nxt;
edge(){};
edge(int V,int W,int N){
v=V;
w=W;
nxt=N;
}
}e[maxn<<1];
int head[maxn],edge_cnt=-1;
void addedge(int u,int v,int w){
e[++edge_cnt]=edge(v,w,head[u]);
head[u]=edge_cnt;
e[++edge_cnt]=edge(u,w,head[v]);
head[v]=edge_cnt;
}
int fa[maxn];
int findset(int x){
if(fa[x]!=x)
fa[x]=findset(fa[x]);
return fa[x];
}
int ans[maxn];
void dfs(int u,int pre){
for(int i=head[u];~i;i=e[i].nxt){
int v=e[i].v;
if(v==pre)
continue;
if(ans[u]==e[i].w)
ans[v]=(e[i].w-1>0?e[i].w-1:e[i].w+1);
else
ans[v]=e[i].w;
dfs(v,u);
}
}
bool cmp(const zz &x,const zz &y){
return x.w<y.w;
}
int main (){
memset(head,-1,sizeof(head));
int n=readint(),m=readint();
for(int i=1;i<=m;i++){
s[i].u=readint(),s[i].v=readint(),s[i].w=readint();
}
for(int i=1;i<=n;i++){
fa[i]=i;
}
int cnt=0;
for(int i=1;i<=m;i++){
int u=s[i].u,v=s[i].v;
int fu=findset(u),fv=findset(v);
if(fu==fv)
continue;
addedge(u,v,s[i].w);
fa[fu]=fv;
cnt++;
if(cnt==n-1)
break;
}
int sum=0;
for(int i=1;i<=n;i++){
if(fa[i]==i)
sum++;
}
if(sum!=1)
return !printf("No");
ans[1]=1;
dfs(1,0);
for(int i=1;i<=n;i++){
printf("%d\n",ans[i]);
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int N, M;
int X[101], Y[101], Z[101];
int cnt[101];
ll memo[2 << 19];
ll dfs(int bit, int nbit){
if(bit == (1 << N) - 1){
return 1;
}
if(memo[bit] != -1) return memo[bit];
ll ret = 0;
for(int i=0;i<N;i++){
if ((bit>>i)&1) continue;
for(int j=0;j<M;j++){
if(nbit + 1 <= X[j] && (i + 1) <= Y[j]){
cnt[j]++;
}
}
bool ok = true;
for(int j=0;j<M;j++){
if(cnt[j] > Z[j]){
ok = false;
break;
}
}
if(ok){
ret += dfs(bit | (1 << i), nbit + 1);
}
for(int j=0;j<M;j++){
if(nbit + 1 <= X[j] && (i + 1) <= Y[j]){
cnt[j]--;
}
}
}
memo[bit] = ret;
return ret;
}
int main(){
cin >> N >> M;
for(int i=0;i<M;i++){
cin >> X[i] >> Y[i] >> Z[i];
}
memset(cnt, 0, sizeof(cnt));
memset(memo, -1, sizeof(memo));
cout << dfs(0, 0) << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int A[105],B[105];
int main(){
int n,a,b,ans;
cin>>n;
for(int i=0;i<n;i++){
cin>>A[i];
}
for(int i=0;i<n;i++){
cin>>B[i];
}
sort(A,A+n);
a=A[n-1];
sort(B,B+n);
b=B[0];
ans=b-a+1;
if(ans>=0)cout<<ans;
else cout<<0;
}
| #include<bits/stdc++.h>
#define pb emplace_back
#define AI(i) begin(i), end(i)
using namespace std;
using ll = long long;
template<class T> bool chmin(T &a, T b) { return b < a && (a = b, true); }
template<class T> bool chmax(T &a, T b) { return a < b && (a = b, true); }
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] = ", args)
void kout() {cerr << endl;}
template<class T, class ...U> void kout (T v, U ...e) { cerr << v << ' ', kout(e...); }
template<class T> void debug(T L, T R) { while (L != R) cerr << *L << " \n"[next(L)==R], ++L; }
#else
#define DE(...) 0
#define debug(...) 0
#endif
// What I should check
// 1. overflow
// 2. corner cases
// Enjoy the problem instead of hurrying to AC
// Good luck !
const int MAX_N = 300010;
const int in_t = 1, out_t = 2, no_t = 0, p = 998244353;
int vis[MAX_N], nxt[MAX_N], n;
int32_t main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> n;
for (int i = 1;i <= n;++i)
cin >> nxt[i];
ll res = 1;
for (int i = 1;i <= n;++i) {
vector<int> stk;
bool bad = false;
for (int x = i;;x = nxt[x]) {
if (vis[x] == out_t) {
bad = true;
break;
}
if (vis[x] == in_t) break;
stk.pb(x);
vis[x] = in_t;
}
if (!bad) {
res = res * 2 % p;
}
for (int u : stk)
vis[u] = out_t;
}
--res;
if (res < 0) res += p;
cout << res << '\n';
}
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int INF = INT_MAX;
const ll LINF = LLONG_MAX;
const int MOD = 1e9+7;
const int N = 1e5+7;
void test_cases(){
int n,m;
cin >> n >> m;
set<int> mp;
mp.insert(n);
mp.insert(m);
if(mp.size()==1){
cout << m;
}else{
if((n==1&&m==2)||(n==2&&m==1))cout << "0";
else if((n==1&&m==0)||(n==0&&m==1))cout << "2";
else cout << "1";
}
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
//cin >> t;
for(int tt = 1; tt <= t; tt++){
test_cases();
}
return 0;
} | #include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<functional>
#include<numeric>
using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define x first
#define y second
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
typedef long long ll;
const int MAXN = 2e5+5, INF = 0x3f3f3f3f, MOD = 998244353;
const ll INFL = 0x3f3f3f3f3f3f3f3f;
const int M = 30;
void run(){
int a,b; cin>>a>>b;
if(a==b)cout<<a<<'\n';
else cout<<3-a-b<<'\n';
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int t=1;
//cin>>t;
while(t--)run();
return 0;
} |
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int X, Y, Z;
int main() {
scanf("%d %d %d", &X, &Y, &Z);
for (int i = 1; i < 1e8; i++) {
if (i * X >= Y * Z) {
printf("%d\n", i - 1);
return 0;
}
}
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define int long long
#define fi first
#define se second
#define debug(x) cerr << #x << ": " << x << '\n'
#define yn {puts("Yes");}else{puts("No");} // if(a == b) yn;
template<class T>inline bool chmax(T &a, const T &b) { if (b > a) { a = b; return true; } return false; }
template<class T>inline bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }
constexpr int INF = 1001001001;
constexpr long long LINF = 1001001001001001001;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;
void solve() {
int x,y,z;
cin >> x >> y >> z;
cout << (y * z - 1) / x << endl;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(20);
solve();
return 0;
} |
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const int sz = 2e3 + 9;
const ll mod = 1e9 + 7;
const ll inf = 1e9;
const double eps = 1e-6;
void test()
{
int n,t;scanf("%d%d", &n, &t);
ll x[n];
for(int i=0;i<n;i++)
scanf("%lld", &x[i]);
int m = n - (n / 2),temp = n;
vector<int> a(temp),b(temp);
n/=2;
for(int i=0;i < n;i++)
a[i] = x[i];
for(int i = n,p = 0;i < temp;i++,p++)
b[p] = x[i];
vector<ll> s(1<<n),s2(1<<m);
for(int i = 0;i < (1<<n);i++)
{
ll sum=0;
for(int j=0;j<n;j++)
{
if(i & (1<<j))
sum+=a[j];
}
s[i] = sum;
}
for(int i=0;i<(1<<m);i++)
{
ll sum = 0;
for(int j=0;j<m;j++)
{
if(i & (1<<j))
sum+=b[j];
}
s2[i] = sum;
}
ll ans = 0;
sort(s2.begin(),s2.end());
for(ll i : s)
{
if(i<=t)
{
int it = (int)(upper_bound(s2.begin(),s2.end(),t - i) - s2.begin());
if(it)
ans = max(ans,i + s2[it - 1]);
}
}
printf("%lld", ans);
}
int main()
{
int cases = 1;
// cin>>cases;
while(cases--)
test();
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef multiset<string> mss;
typedef map<int, int> mii;
typedef set<string> ss;
typedef vector<int> vi;
typedef vector<string> vs;
// -------------------------------------------------
// https://atcoder.jp/contests/abc201/tasks/abc201_d
// -------------------------------------------------
int main(void){
int H, W;
cin >> H >> W;
// int s[2000][2000];
vs s(H);
for(int h = 0; h < H; h++) {
string _s;
cin >> _s;
s[h] = _s;
}
int dp[H][W];
for(int h = 0; h < H; h++) {
for(int w = 0; w < W; w++) {
dp[h][w] = 0;
}
}
auto f = [](char c) {
return c == '+' ? 1 : -1;
};
for(int h = H - 1; h >= 0; h--) {
for(int w = W - 1; w >= 0; w--) {
if(h == H - 1 && w == W - 1) {
dp[h][w] = 0;
continue;
}
// Aoki
if((h + w) % 2) {
dp[h][w] = 1e9;
if(h + 1 < H) dp[h][w] = min(dp[h][w], dp[h + 1][w] - f(s[h + 1][w]));
if(w + 1 < W) dp[h][w] = min(dp[h][w], dp[h][w + 1] - f(s[h][w + 1]));
// Takahashi
} else {
dp[h][w] = -1e9;
if(h + 1 < H) dp[h][w] = max(dp[h][w], dp[h + 1][w] + f(s[h + 1][w]));
if(w + 1 < W) dp[h][w] = max(dp[h][w], dp[h][w + 1] + f(s[h][w + 1]));
}
}
}
for(int h = 0; h < H; h++) {
for(int w = 0; w < W; w++) {
// cout << "dp[" << h << "][" << w << "]:" << dp[h][w] << endl;
}
}
if(dp[0][0] > 0) cout << "Takahashi" << endl;
else if(dp[0][0] < 0) cout << "Aoki" << endl;
else cout << "Draw" << endl;
}
|
#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 mp make_pair
#define pb push_back
#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; (i) >= 0; i--)
#define rep3r(i, m, n) for (int i = (n); (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; }
constexpr int INF = 1070000000;
constexpr long long LINF = 4611686015206162431;
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int N, M, Q;
cin >> N >> M >> Q;
vc<IP> bag(N);
rep (i, N) cin >> bag[i].first >> bag[i].second;
vc<int> X(M);
rep (i, M) cin >> X[i];
sort(all(bag));
rep (l, Q) {
int L, R;
cin >> L >> R;
L--; R--;
vc<int> box;
rep (i, M) {
if (i == L) {
i = R;
continue;
}
box.push_back(X[i]);
}
sort(all(box));
int ans = 0;
PQ<int> vals;
int j = 0;
rep (i, box.size()) {
while (j < N && bag[j].first <= box[i]) {
vals.push(bag[j].second);
j++;
}
if (!vals.empty()) {
ans += vals.top();
vals.pop();
}
}
cout << ans << endl;
}
} | #include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do { cout << "\033[32;1m " << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
sort(v.begin(),v.end());
v.erase(unique(v.begin(),v.end()),v.end());
}
ll rand_int(ll l, ll r) //[l, r]
{
static mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());
return uniform_int_distribution<ll>(l, r)(gen);
}
template<class T>
void print(T x,int suc=1)
{
cout<<x;
if(suc==1) cout<<'\n';
else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
for(int i=0;i<v.size();i++)
print(v[i],i==(int)(v.size())-1?suc:2);
}
const int maxn=105;
int w[maxn],v[maxn];
int x[maxn];
namespace KM{
const int maxn = 50 + 7;
const int INF = 0x3f3f3f3f;
int n; //点数
int cost[maxn][maxn];
int lx[maxn], ly[maxn], match[maxn], slack[maxn];
int pprev[maxn];
bool vy[maxn];
void augment(int root)
{
memset(vy, 0, sizeof(vy));
memset(slack, 0x3f, sizeof(slack));
int py;
match[py = 0] = root;
do
{
vy[py] = true;
int x = match[py], yy;
int delta = INF;
for (int y = 1; y <= n; y++)
{
if (!vy[y])
{
if (lx[x] + ly[y] - cost[x][y] < slack[y])
slack[y] = lx[x] + ly[y] - cost[x][y], pprev[y] = py;
if (slack[y] < delta)
delta = slack[y], yy = y;
}
}
for (int y = 0; y <= n; y++)
{
if (vy[y])
lx[match[y]] -= delta, ly[y] += delta;
else
slack[y] -= delta;
}
py = yy;
} while (match[py] != -1);
do
{
int pre = pprev[py];
match[py] = match[pre], py = pre;
} while (py);
}
int KM()
{
for (int i = 1; i <= n; i++)
{
lx[i] = ly[i] = 0;
match[i] = -1;
for (int j = 1; j <= n; j++)
lx[i] = max(lx[i], cost[i][j]);
}
int ans = 0;
for (int root = 1; root <= n; root++)
augment(root);
for (int i = 1; i <= n; i++)
ans += lx[i], ans += ly[i];
return ans;
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n,m,q;
cin>>n>>m>>q;
for(int i=0;i<n;i++) cin>>w[i]>>v[i];
for(int i=0;i<m;i++) cin>>x[i];
while(q--)
{
int l,r;
cin>>l>>r;
l--,r--;
KM::n=50;
memset(KM::cost,0,sizeof(KM::cost));
for(int i=0;i<m;i++)
{
if(i>=l&&i<=r) continue;
for(int j=0;j<n;j++)
{
if(x[i]>=w[j])
KM::cost[i+1][j+1]=v[j];
}
}
print(KM::KM());
}
} |
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
int main() {
int N,A,B;cin>>N>>A>>B;
cout<<N-A+B<<endl;
}
| #include <stdio.h>
constexpr unsigned char H[16] = {0, 1, 0, 3, 1, 1, 1, 1, 0, 1, 2, 2, 3, 1, 2, 3};
int main() {
unsigned char n, k;
scanf("%hhd %hhd", &n, &k);
getchar_unlocked();
unsigned char h[101], h2[101];
for (unsigned char i = 0; i < n; i++) h[i] = getchar_unlocked() - 80;
for (unsigned char i = 0; i < k; i++) {
unsigned char *cur = (i & 1) ? h2 : h, *nxt = (i & 1) ? h : h2;
for (unsigned char j = 0; j < n; j++) {
nxt[j] = H[(cur[(j * 2) % n] * 4) + cur[((j * 2) + 1) % n]];
}
}
putchar_unlocked(((k & 1) ? (*h2) : (*h)) + 80);
}
|
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
using namespace std;
#define LETS_GET_SCHWIFTY ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ff first
#define ss second
#define int long long
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define pqb priority_queue<int>
#define pqs priority_queue<int,vi,greater<int> >
#define setbits(x) __builtin_popcountll(x)
#define zerobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x,y) fixed<<setprecision(y)<<x
#define vpii vector<pair<int,int> >
#define all(x) x.begin(),x.end()
#define matrixprint(arr,a,b,c,d) for(int i=a;i<=c;i++){for(int j=b;j<=d;j++){cout<<arr[i][j]<<" ";}cout<<"\n";}
#define show(arr,x,y) for(int i=x;i<=y;i++){cout<<arr[i]<<" ";}cout<<"\n"
#define sz(x) (int)x.size()
#define db(x) cout<<x<<"\n";
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
//insert,find_by_order,order_of_key,lower_bound,upper_bound;
#define TRACE
#ifdef TRACE
#define deb(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
#else
#define deb(...)
#endif
//////////////////////////////code//////////////////////////////
const int N = 200;
int power(int a, int b = mod - 2) {
int x = 1 % mod;
a %= mod;
b %= mod - 1;
while (b) {
if (b & 1) x = (x * a)%mod;
a = (a * a)%mod;
b >>= 1;
// deb(x);
}
return x;
}
void solve()
{
int n , p;
cin >> n >> p;
if(n == 1)
{
db(p - 1)
return;
}
if(p == 0)
{
db(0)
return;
}
int ans = (p - 1) % mod;
ans *= power(p - 2,n - 1);
ans %= mod;
db(ans)
}
int32_t main()
{
LETS_GET_SCHWIFTY;
#ifndef ONLINE_JUDGE
freopen("INP.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
int t = 1;
//cin >> t;
while (t--)
solve();
}
// check out for following mistakes-
// if using pb operation on vector and then trying to access index..check if sizeof that vec could remain 0 only
// is using prime sieve make sure it fits
// when using factorial template or combinatorics make sure that you edit fillfac fun values and array values
| #include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
const int mod = 1e9 + 7;
long long Pow(long long a, long long b) {
long long res = 1;
while (b) {
if (b & 1) {
res = res * a % mod;
}
a = a * a % mod;
b >>= 1;
}
return res;
}
int main() {
int n, p;
cin >> n >> p;
long long res = 1;
res = 1ll * (p - 1) * Pow(p - 2, n - 1) % mod;
cout << res << "\n";
}
|
#include<bits/stdc++.h>
using namespace std;
int main(){
vector<int> v(4);
for(int i=0;i<4;i++)
cin >> v[i];
sort(v.begin(),v.end());
if(v[0]+v[3]==v[1]+v[2])
cout << "Yes" << endl;
else if(v[0]+v[1]+v[2]==v[3])
cout << "Yes" << endl;
else
cout << "No" << endl;
} |
#include <bits/stdc++.h>
using namespace std;
int main() {
int A,B,N;
cin >> N >> A >> B;
cout << N - A + B << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;
#define F first
#define S second
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define mt(a,b,c) make_tuple(a,b,c)
#define sz size()
#define all(A) A.begin(), A.end()
#define mem(a, b) memset(a, b, sizeof(a)) // all elements of A are b=0 or b=-1 else don't work
#define f0(i,b) for(ll i=0;i<(b);i++)
#define f1(i,b) for(ll i=1;i<=(b);i++)
#define f2(i,a,b) for(ll i=(a);i<=(b);i++)
#define f3(i,b,a) for(ll i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(ll i=(a);i!=(b);i+=(c))
#define MOD 1000000007 //10^9 + 7
#define PI acos(-1.0)
#define MAX3(a,b,c) max(a,max(b,c))
#define MIN3(a,b,c) min(a,min(b,c))
/*------------------------Bitmask-------------------------------*/
#define bitOn(N,pos) (N | (1LL<<(pos)))
#define bitOff(N,pos) (N & (~(1LL<<(pos))))
#define bitCheck(N,pos) ((bool)(N & (1LL<<(pos)))) //check whether the (pos)th bit is On or Off in N(number)
#define bitFlip(a,k) (a^(1LL<<(k)))
#define whilee(i,t) while(i!=t)
#define sl(a) scanf("%lld",&a)
#define pl(a) printf("%lld\n",a)
//x = 1e18 means 10^18
//for(auto it =A.begin(); it!=A.end(); it++)
//sort(A.begin(),A.end()); //sort(A, +n, greater<int>());
//binary_search(A.begin(),A.end(),x);
//reverse(A.begin(), A.end());
//cout << *max_element(A.begin(), A.end()); //will have index if A.begin() is minus from it
//cout << *min_element(A.begin(), A.end());
//count(A.begin(), A.end(), X); //counts the occurrences of X
//distance(A.begin(),A.end()); //distance between first to last element
//accumulate(A.begin(), A.end(), 0); //add
//next_permutation(A.begin(), A.end());
//prev_permutation(A.begin(), A.end());
//swap(S[0], T[0]);
//scanf("%lld",&x);
//printf("%lld\n",x);
//printf("%I64d\n", a);
//while (scanf("%lld %lld", &a, &b) == 2)
//printf("Case %lld: %lld\n", t++, a);
/*----------------------- Graph Moves---------------------------*/
// int dx[] = {1,-1,0,0} , dy[] = {0,0,1,-1}; // 4 Direction
// int dx[] = {0,0,1,-1,-1,1,-1,1} , dy[] = {-1,1,0,0,1,1,-1,-1}; // 8 Direction // Kings Move
// int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1}; // Knight Direction
// int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1}; // Hexagonal Direction
//vector <ll> A;
//deque <ll> A;
//queue <ll> A;
//stack <ll> A;
//list <int> A;
//set <ll> A;
//map <ll,ll> A;
//unordered_map <ll, ll> A;
//pair <ll,ll> A ;
//tuple <ll, ll, ll> A;
//vector <pair <ll,ll>> A;
//bitset<32> bset1;
//bool ok = true;
//char ch;
//string S, T, U;
bool decToOctal(int n)
{
// array to store octal number
int octalNum[100];
// counter for octal number array
int i = 0;
while (n != 0)
{
// storing remainder in octal array
octalNum[i] = n % 8;
if(octalNum[i]==7)
{
return true;
}
n = n / 8;
i++;
}
return false;
}
ll i=0, j=0, k=0, a, b, c, d, e, f, g, h, l, m, n, o, p, q, r, s, t=1, u, v, w, x, y, z, maxx=INT_MIN, minn=INT_MAX, ans=0, sum=0, flag=0, cnt=0;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);//NULL
cout.tie(nullptr);//NULL
//cin>>t; while(t--){ }
cin>>n;
j=7;
for(i=7; i<=n; i++)
{
if(decToOctal(i))
{
cnt++;
}
else
{
x=i;
while(x>0)
{
if(x%10==7)
{
cnt++;
break;
}
x/=10;
}
}
}
cout<<n-cnt<<endl;
return 0;
}
| #pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
const int INF = 0x3f3f3f3f;
#define FOR(i, b, e) for(int i = (b); i < (e); i++)
#define TRAV(x, a) for(auto &x: (a))
#define SZ(x) ((int)(x).size())
#define PB push_back
#define PR pair
#define X first
#define Y second
bool digs(int x, int base){
while(x){
if(x%base == 7) return 0;
x /= base;
}
return 1;
}
void solve(){
int n, ans = 0;
cin >> n;
FOR(i, 1, n+1) ans += digs(i, 10) & digs(i, 8);
cout << ans << '\n';
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
// int tt; cin >> tt;
// FOR(te, 0, tt){
// // cout << "Case #" << te+1 << ": ";
// solve();
// }
solve();
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const int mod = 1000000007;
//const int mod = 998244353;
int main()
{
int n;
cin >> n;
vector<int> a(n), b(n);
rep(i, 0, n) cin >> a[i];
rep(i, 0, n) cin >> b[i];
vector<bool> c(10005, true);
rep(i, 0, n){
rep(j, 0, a[i]) c[j] = false;
rep(j, b[i] + 1, 10005) c[j] = false;
}
int ans = 0;
rep(i, 0, 10005) if(c[i]) ans++;
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define llu unsigned long long int
#define ld long double
#define mod 998244353
#define big 1e18 + 10000000
#define small -big
#define pb push_back
#define endl "\n"
template <typename T>
void prarr(T a)
{
cerr << "[ ";
for(auto i : a){
cerr << i << " ";
}
cerr << "]" << endl;
}
#define trace(...) _er(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void _er(const char* name, Arg1&& arg1){
cerr << "[" << name << " : " << arg1 << "]" << endl;
}
template <typename Arg1, typename... Args>
void _er(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr << "[" ; cerr.write(names, comma - names) << " : " << arg1 << "] ";
_er(comma+2, args...);
}
ll n;
vector<ll> A[102];
ll cou[102] = {0};
bool visited[102];
void dfs(ll v) {
if(visited[v]) {
return;
}
visited[v] = true;
for(auto it : A[v]) {
if(!visited[it]) {
dfs(it);
}
}
}
void solve() {
cin >> n;
for(ll i = 1; i <= n; i++) {
string s;
cin >> s;
for(ll j = 0; j < n; j++) {
if(s[j] - 48) {
A[i].pb(j + 1);
}
}
}
for(ll i = 1; i <= n; i++) {
memset(visited, false, sizeof(visited));
dfs(i);
for(ll j = 1; j <= n; j++) {
if(visited[j]) {
cou[j]++;
}
}
}
ld ans = 0.0;
for(ll i = 1; i <= n; i++) {
ld curr = cou[i];
ans += (1.0 / curr * 1.0);
}
cout << fixed << setprecision(11) << ans << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
//cin >> t;
for(int i = 1; i <= t; i++) {
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
using namespace std;
using ll = long long;
struct Edge
{
ll to;
ll cost;
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, ll>;
#define mp make_pair
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), v.end()
ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = LLONG_MAX;
const int MAX = 510000;
bool graph[nmax][nmax];
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit()
{
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++)
{
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
ll COM(int n, int k)
{
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
for (size_t i = 0; i < n; i++)
{
for (size_t j = 0; j < n; j++)
{
for (size_t k = 0; k < n; k++)
{
dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
}
}
}
}
ll gcd(ll a, ll b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
ll lcm(ll a, ll b)
{
ll g = gcd(a, b);
return a / g * b;
}
ll mulMod(ll a, ll b)
{
return (((a % MOD) * (b % MOD)) % MOD);
}
ll powMod(ll a, ll p)
{
if (p == 0)
{
return 1;
}
else if (p % 2 == 0)
{
ll half = powMod(a, p / 2);
return mulMod(half, half);
}
else
{
return mulMod(powMod(a, p - 1), a);
}
}
ll ceil(ll a, ll b)
{
return (a + b - 1) / b;
}
void solve(long long A, long long B, long long C)
{
if (A % 10 == 0)
{
cout << 0 << endl;
return;
}
else if (A % 10 == 1)
{
cout << 1 << endl;
return;
}
else if (A % 10 == 2)
{
ll ans[4] = {6, 2, 4, 8};
MOD = 4;
ll ind = powMod(B, C);
cout << ans[ind] << endl;
}
else if (A % 10 == 3)
{
ll ans[4] = {1, 3, 9, 7};
MOD = 4;
ll ind = powMod(B, C);
cout << ans[ind] << endl;
}
else if (A % 10 == 4)
{
ll ans[2] = {6, 4};
// 4,6,4,6,4,6....
MOD = 2;
ll ind = powMod(B, C);
cout << ans[ind] << endl;
}
else if (A % 10 == 5)
{
cout << 5 << endl;
return;
}
else if (A % 10 == 6)
{
cout << 6 << endl;
return;
}
else if (A % 10 == 7)
{
ll ans[4] = {1, 7, 9, 3};
MOD = 4;
ll ind = powMod(B, C);
cout << ans[ind] << endl;
}
else if (A % 10 == 8)
{
ll ans[4] = {6, 8, 4, 2};
MOD = 4;
ll ind = powMod(B, C);
cout << ans[ind] << endl;
// 8,4,2,6,8....
}
else if (A % 10 == 9)
{
ll ans[2] = {1, 9};
MOD = 2;
ll ind = powMod(B, C);
cout << ans[ind] << endl;
// 9,1,9,1...
}
}
int main()
{
long long A;
scanf("%lld", &A);
long long B;
scanf("%lld", &B);
long long C;
scanf("%lld", &C);
solve(A, B, C);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define MOD 1000000007
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int main(){
ll a, b, c;
cin >> a >> b >> c;
a %= 10;
b %= 4;
ll x;
if(b==0) x=4;
else if(b==1) x=1;
else if(b==2){
if(c>1) x=4;
else x=2;
}else{
if(c%2==0) x=1;
else x=3;
}
ll ans=powl(a, x);
cout << ans%10 << endl;
return 0;
}
|
#include <bits/stdc++.h>
using ll =long long;
using namespace std;
const int mod = 1000000007;
//const int mod = 998244353;
struct mint {
ll x; // typedef long long ll;
mint(ll x=0):x((x%mod+mod)%mod){}
mint operator-() const { return mint(-x);}
mint& operator+=(const mint a) {
if ((x += a.x) >= mod) x -= mod;
return *this;
}
mint& operator-=(const mint a) {
if ((x += mod-a.x) >= mod) x -= mod;
return *this;
}
mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
mint operator+(const mint a) const { return mint(*this) += a;}
mint operator-(const mint a) const { return mint(*this) -= a;}
mint operator*(const mint a) const { return mint(*this) *= a;}
mint pow(ll t) const {
if (!t) return 1;
mint a = pow(t>>1);
a *= a;
if (t&1) a *= *this;
return a;
}
// for prime mod
mint inv() const { return pow(mod-2);}
mint& operator/=(const mint a) { return *this *= a.inv();}
mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
int main(){
int N;
cin>>N;
set<ll> st;
ll a;
for(int i=0;i<N;i++){
cin>>a;
st.insert(a);
}
mint pre(0);
mint ans(1);
for(auto s:st){
ans=ans*(mint(s)-pre+1);
pre=s;
}
cout<<ans<<endl;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll z = 0;
int main(){
ll N;
cin >> N;
vector<ll> A(N);
for (ll i = 0; i < N; i++){
cin >> A[i];
}
sort(A.begin(), A.end());
ll ans = 0, prevsum = 0;
for (ll i = N - 2; i >= 0; i--){
prevsum += A[N - 1] - A[i];
}
ans = prevsum;
for (ll i = N - 2; i >= 0; i--){
prevsum = prevsum - (i + 1) * (A[i + 1] - A[i]);
ans += prevsum;
}
cout << ans << endl;
} |
#include<bits/stdc++.h>
using namespace std;
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
#define pb push_back
#define input(a,n) for(ll i=0;i<n;i++){ll y;cin>>y;a.pb(y);}
#define print(x) for(auto it:x)cout<<it<<" ";cout<<"\n";
#define all(x) (x).begin(),(x).end()
#define clr(x) memset(x,0,sizeof(x))
#define fn(a,n) for(ll i = a; i < n; ++i)
#define f(n) for(ll i = 0; i < n; i++)
#define endl '\n'
#define test ll t;cin>>t;while(t--)
#define INF 1000000000
#define MAX 100001
#define pyes cout<<"YES"<<endl;
#define pno cout<<"NO"<<endl;
#define sz(x) (x).size()
const ll mod=1000000007;
int main()
{
io;
//test
{
int a,b;
cin>>a>>b;
int x,y;
x=(a+b)/2;
y=(a-b)/2;
cout<<x<<" "<<y<<endl;
}
return 0;
}
| //#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v){
if(v.empty()){
os<<"{ }";
return os;
}
os<<"{"<<v.front();
for(auto itr=++v.begin();itr!=v.end();itr++){
os<<", "<<*itr;
}
os<<"}";
return os;
}
template<typename T_first,typename T_second>
ostream& operator<<(ostream& os,const pair<T_first,T_second>& P){
os<<"("<<P.first;
os<<", "<<P.second;
os<<")";
return os;
}
int main(){
int a,b; cin>>a>>b;
cout<<(a+b)/2<<" "<<(a-b)/2<<endl;
} |
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 1000000007;
// constexpr int MOD = 998244353;
constexpr int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
constexpr int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
IOSetup() {
std::cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
std::cout << fixed << setprecision(20);
}
} iosetup;
int main() {
constexpr int T = 200000;
int n, w; cin >> n >> w;
vector<ll> water(T + 1, 0);
while (n--) {
int s, t, p; cin >> s >> t >> p;
water[s] += p;
water[t] -= p;
}
REP(i, T) water[i + 1] += water[i];
cout << (*max_element(ALL(water)) <= w ? "Yes\n" : "No\n");
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reps(i,a,b) for(int i= a; i < b; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
struct UnionFind {
vector<int> d;
UnionFind(int n) : d(n, -1) {}
int find(int x) {
if(d.at(x) < 0) return x;
return d.at(x) = find(d.at(x));
}
bool unite(int a, int b) {
a = find(a); b = find(b);
if (a == b) return false;
if (d.at(a) > d.at(b)) swap(a, b);
d.at(a) += d.at(b); d.at(b) = a;
return true;
}
bool same(int a, int b) {
return find(a) == find(b);
}
int size(int x) {
return -d.at(find(x));
}
};
int main()
{
int n, m;
cin >> n >> m;
vector<ll> a(n), b(n);
UnionFind uf(n);
rep(i, n) cin >> a.at(i);
rep(i, n) cin >> b.at(i);
rep(i, m) {
int x, y;
cin >> x >> y;
--x; --y;
uf.unite(x, y);
}
map<ll, ll> am, bm;
rep(i, n) {
am[uf.find(i)] += a.at(i);
bm[uf.find(i)] += b.at(i);
}
for (auto it = am.begin(); it != am.end(); it++) {
if (it->second != bm[it->first]) {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
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;}
/*他のライブラリを入れる場所*/
map<int,int> zip;
int unzip[500000];
int compress(vector<int> &x) {
sort(x.begin(), x.end());
x.erase(unique(x.begin(),x.end()),x.end());
for(int i = 0; i < x.size(); i++){
zip[x[i]] = i;
unzip[i] = x[i];
}
return x.size();
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
ll n,c;
cin>>n>>c;
vl a(n),b(n),v(n);
vi tmp;
rep(i,n){
cin>>a[i]>>b[i]>>v[i];
tmp.push_back(a[i]);
tmp.push_back(b[i]+1);
}
compress(tmp);
vl imos(n*2+1, 0);
rep(i,n){
imos[zip[a[i]]]+=v[i];
imos[zip[b[i]+1]]-=v[i];
}
partial_sum(all(imos), imos.begin());
ll ans=0;
rep(i,n*2+1){
ll d=unzip[i+1]-unzip[i];
if(d<=0)continue;
ans+=min(c, imos[i]) * d;;
}
puta(ans);
return 0;
} | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef set<int> si;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef vector<pii> vii;
typedef vector<pll> vll;
#define fi first
#define se second
#define pi 3.141592653589793
#define mod 998244353
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define pqmax priority_queue<int>
#define pqmin priority_queue<int,vi,greater<int>>
#define fio ios_base::sync_with_stdio(0), cin.tie(NULL)
#define tc int tt;cin>>tt;for(int ti=1;ti<=tt;ti++)
#define case_g "Case #"<<ti<<": "
#define RED "\033[31m"
#define GREEN "\033[32m"
#define RESET "\033[0m"
#define sleep for (int i = 1, a;i < 100000000;i++, a = a * a)
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> ranked_pairset;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ranked_set;
typedef tree<int, int, less<int>, rb_tree_tag, tree_order_statistics_node_update> ranked_map;
int main() {
fio;
ll n, p;
cin >> n >> p;
mll m;
for (int i = 0;i < n;i++) {
int a, b, c;
cin >> a >> b >> c;
m[a] += c;
m[b + 1] -= c;
}
ll cur = 0, ans = 0;
for (auto itr = m.begin();next(itr) != m.end();itr++) {
ll d = next(itr)->fi - itr->fi;
cur += itr->se;
ll c = min(cur, p);
ans += d * c;
}
cout << ans << '\n';
}
|
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int M=1005;
inline int read(){
char c=getchar();int x=0,f=1;
for(;c<'0'||c>'9';c=getchar())if(c=='-')f=0;
for(;c<='9'&&c>='0';c=getchar())x=(x<<1)+(x<<3)+(c^48);
return f?x:-x;
}
struct node{
char s[20];int x;
bool operator <(const node &t)const{
return x>t.x;
}
}a[M];
int main(){
int n=read();
for(int i=1;i<=n;i++){
scanf("%s",a[i].s);a[i].x=read();
}
sort(a+1,a+1+n);
printf("%s",a[2].s);
return 0;
} | #include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
for(int i=0;i<n;i++)
cout<<(2*i)%n+1<<' '<<(2*i+1)%n+1<<'\n';
return 0;
} |
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <iomanip>
#include <functional>
using namespace std;
typedef long long ll;
int n,m;
string s[100010];
int k[100010];
int main(){
cin >> n >> m;
for(int i=0;i<n;i++)cin >> s[i];
ll a=0,b=0;
for(int i=0;i<n;i++){
int cnt=0;
for(int j=0;j<m;j++){
if(s[i][j]!=s[0][j]){
cnt++;
}
}
if(cnt%2==0)a++;
else b++;
}
cout << a*b << endl;
return 0;
}
| #include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define st first
#define nd second
#define pii pair<int,int>
#define mp make_pair
#define pll pair<long long,long long>
using namespace std;
ll xd[2];
void solve(){
int n,m; cin>>n>>m;
while(n--){
string s; cin>>s;
int x = 0;
for(char y : s){
if(y == '1') x++;
}
xd[x % 2]++;
}
cout<<xd[0] * xd[1];
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
solve();
return 0;
}
|
//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
#include <bits/stdc++.h>
#include<set>
#include <array>
using namespace std;
#define ll long long
#define endl '\n'
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define con continue
#define ub upper_bound
#define lb lower_bound
#define si(x) int(x.size())
#define sum_all(a) ( accumulate ((a).begin(), (a).end(), 0ll))
#define mine(a) (*min_element((a).begin(), (a).end()))
#define maxe(a) (*max_element((a).begin(), (a).end()))
#define mini(a) ( min_element((a).begin(), (a).end()) - (a).begin())
#define maxi(a) ( max_element((a).begin(), (a).end()) - (a).begin())
#define lowb(a, x) ( lower_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define uppb(a, x) ( upper_bound((a).begin(), (a).end(), (x)) - (a).begin())
const double pi = 2 * acos(0.0);
const int dx[] = { -1, 0, 1, 0 };
const int dy[] = { 0, -1, 0, 1 };
const int dx8[] = { -1, 0, 1, 0,1,1,-1,-1 };
const int dy8[] = { 0, -1, 0, 1,1,-1,1,-1 };
ll min(ll a,ll b)
{
if(a<b)return a;
return b;
}
ll max(ll a,ll b)
{
if(a>b)return a;
return b;
}
ll ceil1(ll a,ll b)
{
return(a+b-1)/b;
}
void read(vector<ll> & arr)
{
for(ll i=0;i<si(arr);i++)
cin >> arr[i];
}
void read_graph(vector<vector<ll>>& g, ll m)
{
while(m--)
{
ll x,y; cin >> x>> y ;
x--,y--;
g[x].pb(y);
g[y].pb(x);
}
}
void solve()
{
int n,m;
cin >> n >> m;
vector<vector<pair<char,int>>> g(n);
for(int i=0;i<m;i++)
{
int x,y;
char ch;
cin >> x >> y >> ch ;
x--,y--;
g[x].push_back({ch,y});
g[y].push_back({ch,x});
}
using node= pair<int,pair<int,int>>;
vector<vector<bool>> vis(n,vector<bool>(n));
queue<node> q ;
q.push({0,{0,n-1}});
int ans=INT_MAX;
while(!q.empty())
{
auto a1=q.front();
q.pop();
auto a=a1.ss.ff,b=a1.ss.ss;
auto dis= a1.ff;
if(a==b)
{
ans=min(ans,dis*2);
continue;
}
if(vis[a][b]) continue;
vis[a][b]=true;
vis[b][a]=true;
bool f=false;
for(auto info :g[a])
{
auto v=info.ss;
if(v==b)
{
f=true;
break;
}
}
if(f)
{
ans=min(ans,dis*2+1);
continue;
}
for(auto info :g[a])
for(auto info2 : g[b])
{
if(info.ff!=info2.ff) continue;
if(vis[info.ss][info2.ss]) continue;
q.push({dis+1,{info.ss,info2.ss}});
}
}
if(ans==INT_MAX) ans=-1;
cout << ans << endl;
return ;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
//int t; cin >> t; while (t--)
solve();
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;
ll n, p[2 * 101 * 1001], db[20][2 * 101 * 1001], iv[2 * 101 * 1001], dep[2 * 101 * 1001], Q;
vector<ll> v, ans;
int main(){
cin.tie(0); ios::sync_with_stdio(false);
cin >> n;
zep(i, 1, n){cin >> p[i]; p[i]--;}
vector<vector<ll>> g(n);
zep(i, 1, n)g[p[i]].push_back(i);
//zep(i, 0, n){zep(j, 0, g[i].size())cout << g[i][j] << " "; cout << endl;}
queue<ll> q;
iv[0] = v.size();
q.push(0);
v.push_back(0);
while(!q.empty()){
ll at = q.front(); q.pop();
db[0][iv[at]] = v.size();
zep(i, 0, g[at].size()){
iv[g[at][i]] = v.size();
v.push_back(g[at][i]);
q.push(g[at][i]);
dep[g[at][i]] = dep[at] + 1;
}
}
db[0][n] = v.size();
zep(j, 1, 20){
rep(i, 0, n){
db[j][i] = db[j - 1][db[j - 1][i]];
}
}
cin >> Q;
while(Q--){
ll u, d; cin >> u >> d; u--;
d -= dep[u];
if(d < 0){
ans.push_back(0); continue;
}
ll l = iv[u], r = iv[u] + 1;
rrep(j, 19, 0){
if(d & (1LL << j)){
l = db[j][l];
r = db[j][r];
}
}
ans.push_back(r - l);
}
zep(i, 0, ans.size())print(ans[i])
return 0;
} |
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#define mkp make_pair
#define mkt make_tuple
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
template <class T> void chmin(T &a, const T &b) {
if (a > b) a = b;
}
template <class T> void chmax(T &a, const T &b) {
if (a < b) a = b;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
ll K;
cin >> N >> K;
vector<ll> A(N + 1, 0), B(N + 1, 0);
rep(i, N) cin >> A[i + 1] >> B[i + 1];
A[0] = 0;
B[0] = K;
vector<int> ord(N + 1);
rep(i, N + 1) ord[i] = i;
sort(all(ord), [&](int a, int b) {
if (A[a] == A[b])
return a < b;
else
return A[a] < A[b];
});
ll money = 0;
int now = 0;
while (now <= N) {
int nex = now;
while (nex <= N && A[ord[now]] == A[ord[nex]]) {
money += B[ord[nex]];
nex++;
}
if (nex > N) {
cout << A[ord[N]] + money << endl;
return 0;
}
if (money >= A[ord[nex]] - A[ord[now]]) {
money -= A[ord[nex]] - A[ord[now]];
} else {
cout << A[ord[now]] + money << endl;
return 0;
}
now = nex;
}
return 0;
} | //Classic
// //g++ -std=c++17 -O2 -Wall a.cpp -o test
// _()_
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define vll vector<ll>
#define vi vector<int>
#define vb vector<bool>
#define pi pair<int,int>
#define pll pair<ll,ll>
#define vp vector<pi>
#define vpll vector<pll>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
#define For(i,a,b) for(ll i=a;i<b;i++)
//#define endl "\n"
#define debug2(x,y) cout<<"This side ----> "<<#x<<" -> "<<x<<" | "<<#y<<" -> "<<y<<endl;
#define debug(x) cout<<"This side ----> "<<#x<<" -> "<<x<<endl
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define mint map<int,int>
#define mall map<ll,ll>
#define ciN cin
#define gu(a,s) get<a>(s)
#define tin tuple<ll,ll,ll>
#define ter(x,y,z) ((x)?y:z)
#define ul ll
/////////////
const ll maxn = 2e5 + 5;
const ll max_val = 2e5 + 10;
ll mod = 1e9 + 7;
const ll bits = 20;
ll caseNumber = 1;
////////////////////////////////////////////////////////////////
void jabru() {
ll n, k; cin >> n >> k;
vpll v(n);
for (int i = 0; i < n; i++) {
cin >> v[i].F >> v[i].S;
}
ll curr = 0;
sort(all(v));
for (int i = 0; i < n; i++) {
ll req = v[i].F - curr;
if (k < req) {
break;
}
else {
k -= req;
k += v[i].S;
curr += req;
}
}
curr += k;
cout << curr << endl;
}
bool TestCase = 0;
bool isGoogles = 0;
//////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
ll t;
t = 1;
if (TestCase) {
cin >> t;
}
while (t--) {
if (isGoogles) {cout << "Case #" << caseNumber << ": ";} caseNumber++;
jabru();
}
return 0;
} |
#ifdef __GNUC__
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#endif
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cctype>
#include <iostream>
#include <sstream>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <vector>
using namespace std;
typedef long long LL;
typedef long double LD;
typedef pair<LL, LL> II;
typedef pair<LL, II> III;
typedef priority_queue<III, vector<III>, greater<>> Queue;
static const LL INF = 1LL << 60;
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; }
#if 0
const int dy[4] = { 0, -1, 0, 1 };
const int dx[4] = { -1, 0, 1, 0 };
void dfs(int y, int x) {
for (int dir = 0; dir < 4; ++dir) {
int ny = y + dy[dir], nx = x + dx[dir];
if (ny >= 0 && ny < H && nx >= 0 && nx < W && !vis[ny][nx] && B[ny][nx] != '#') {
vis[ny][nx] = 1;
dfs(ny, nx);
}
}
}
LL binary_search(vector<LL> a, LL x) {
vector<int> vi(N);
iota(vi.begin(), vi.end(), 0);
sort(vi.begin(), vi.end(), [&](int lhs, int rhs) {
return make_pair(x[lhs], y[lhs]) < make_pair(x[rhs], y[rhs]);
});
auto possible = [&](LL t) {
return t <= x;
};
LL left = -1, right = a.size();
while (right - left > 1) {
LL mid = (left + right) / 2;
if (possible(a[mid])) {
left = mid;
} else {
right = mid;
}
}
return left;
}
#endif
void solve(long long N, std::vector<long long> &x) {
LL ans = 0;
for (int i = 0; i < N; i++) {
ans += abs(x[i]);
}
cout << ans << endl;
LD sum = 0;
for (int i = 0; i < N; i++) {
sum += x[i] * x[i];
}
cout << sqrt(sum) << endl;
ans = 0;
for (int i = 0; i < N; i++) {
ans = max(ans, abs(x[i]));
}
cout << ans << endl;
}
int main() {
cout.precision(20);
long long N;
std::cin >> N;
std::vector<long long> x(N);
for (int i = 0; i < N; i++) {
std::cin >> x[i]; // x[i]--;
}
solve(N, x);
return 0;
}
| /* @author: saran
* Git: https://github.com/abhisheksaran
* LinkedIn: https://www.linkedin.com/in/abhishek-saran-2900b/
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<LL> vl;
typedef vector<vl> vvl;
double EPS = 1e-9;
int INF = 1000000005;
long long INFF = 1000000000000000005LL;
double PI = acos(-1);
int dirx[8] = { -1, 0, 0, 1, -1, -1, 1, 1 };
int diry[8] = { 0, 1, -1, 0, -1, 1, -1, 1 };
#ifdef TESTING
#define DEBUG fprintf(stderr, "====TESTING====\n")
#define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define DEBUG
#define VALUE(x)
#define debug(...)
#endif
#define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a))
#define FORN(a, b, c) for (int(a) = (b); (a) <= (c); ++(a))
#define FORD(a, b, c) for (int(a) = (b); (a) >= (c); --(a))
#define FORSQ(a, b, c) for (int(a) = (b); (a) * (a) <= (c); ++(a))
#define FORC(a, b, c) for (char(a) = (b); (a) <= (c); ++(a))
#define FOREACH(a, b) for (auto&(a) : (b))
#define REP(i, n) FOR(i, 0, n)
#define REPN(i, n) FORN(i, 1, n)
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define SQR(x) ((LL)(x) * (x))
#define RESET(a, b) memset(a, b, sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz))
#define PERMUTE next_permutation
#define TC(t) while (t--)
inline string IntToString(LL a)
{
char x[100];
sprintf(x, "%lld", a);
string s = x;
return s;
}
inline LL StringToInt(string a)
{
char x[100];
LL res;
strcpy(x, a.c_str());
sscanf(x, "%lld", &res);
return res;
}
inline string GetString(void)
{
char x[1000005];
scanf("%s", x);
string s = x;
return s;
}
inline string uppercase(string s)
{
int n = SIZE(s);
REP(i, n)
if (s[i] >= 'a' && s[i] <= 'z')
s[i] = s[i] - 'a' + 'A';
return s;
}
inline string lowercase(string s)
{
int n = SIZE(s);
REP(i, n)
if (s[i] >= 'A' && s[i] <= 'Z')
s[i] = s[i] - 'A' + 'a';
return s;
}
inline void OPEN(string s)
{
#ifndef TESTING
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
#endif
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string s;
cin>>s;
REVERSE(s);
int n = s.size();
int i;
REP(i,n){
if(s[i] == '6') s[i] = '9';
else if(s[i] == '9') s[i] = '6';
}
cout<<s<<endl;
return 0;
}
|
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>
#include <iomanip>
#include <cmath>
#include <set>
#include <unordered_set>
#include <functional>
#include <map>
#include <unordered_map>
#include <string>
#include <tuple>
using namespace std;
using ll = long long;
const int MOD=1e9+7;
const int MAX=100009;
ll fac[100009],finv[100009],inv[100009];
#define pi 3.14159265358979323846
#define ee 2.71828182845904523536
#define INF 1e18+1
ll gcd(ll x, ll y) { // 最大公約数
if (y == 0)return x;
else return gcd(y, x % y);
}
bool prime(ll x) { //素数判定
if(x==1)return false;
if (x!=2&&x % 2 == 0)return false;
for (ll i = 3; i <= sqrt(x); i+=2) {
if (x % i == 0)return false;
}
return true;
}
ll modinv(ll a, ll m) { //逆元
long long b = m, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b; swap(a, b);
u -= t * v; swap(u, v);
}
u %= m;
if (u < 0) u += m;
return u;
}
ll modpow(ll a, ll n, ll mod) { //二分累乗法
ll res = 1;
while (n) {
if (n % 2)res = res * a % mod;
a = a * a % mod;
n /= 2;
}
return res;
}
void COMinit() { //二項係数計算の前処理
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++){
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
ll COM(int n, int k){ //二項係数計算
if (n < k) return 0;
if (n < 0 || k < 0) return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
struct UnionFind { // UnionFind
vector<int> par;
vector<int> siz;
UnionFind(int N) : par(N), siz(N, 1) {
for (int i = 0; i < N; i++) par[i] = i;
}
int root(int x) {
if (par[x] == x) return x;
return par[x] = root(par[x]);
}
void unite(int x, int y) {
int rx = root(x);
int ry = root(y);
if (rx == ry) return;
if (par[rx] > par[ry])swap(rx, ry);
siz[rx] += siz[ry];
par[ry] = rx;
}
bool same(int x, int y) {
int rx = root(x);
int ry = root(y);
return rx == ry;
}
int size(int x) {
return siz[root(x)];
}
};
int main() {
int n,p;
cin>>n>>p;
ll ans=p-1;
cout<<ans*modpow(p-2,n-1,MOD)%MOD<<endl;
} | #pragma region Region_1
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
using ll = long long;
using P = pair<ll, ll>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VP = vector<P>;
using VS = vector<string>;
using VC = vector<char>;
using VVC = vector<vector<char>>;
#define MOD 1000000007
const int INF = (int)1e9 + 10; // int max > 2*10^9
const long long INFL = (ll)2e18 + 10; // ll max > 9*10^18
template <class T, class C>
bool chmax(T& a, C b) { if (a < b) { a = b; return true; } return false; }
template <class T, class C>
bool chmin(T& a, C b) { if (a > b) { a = b; return true; } return false; }
template <class T> T sum(const vector<T>& v) {
T res = 0;
for (size_t i = 0; i < v.size(); ++i) res += v[i];
return res;
}
/////////////////////////////////////////////////////////
// print like python
// https://qiita.com/Lily0727K/items/06cb1d6da8a436369eed
/////////////////////////////////////////////////////////
void print() { cout << endl; }
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {
cout << head;
if (sizeof...(tail) != 0) cout << " ";
print(forward<Tail>(tail)...);
}
template <class T> void print(vector<T>& vec) {
for (auto& a : vec) {
cout << a;
if (&a != &vec.back()) cout << " ";
}
cout << endl;
}
template <class T> void print(vector<vector<T>>& df) {
for (auto& vec : df) {
print(vec);
}
}
#pragma endregion Region_1
/////////////////////////////////////////////////////////
struct mint {
ll x; // typedef long long ll;
int mod;
mint(ll x = 0, int mod = MOD) : x((x % mod + mod) % mod), mod(mod) {}
mint operator-() const { return mint(-x); }
mint& operator+=(const mint a) {
if ((x += a.x) >= mod) x -= mod;
return *this;
}
mint& operator-=(const mint a) {
if ((x += mod - a.x) >= mod) x -= mod;
return *this;
}
mint& operator*=(const mint a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const {
mint res(*this);
return res += a;
}
mint operator-(const mint a) const {
mint res(*this);
return res -= a;
}
mint operator*(const mint a) const {
mint res(*this);
return res *= a;
}
// x^t
mint pow(ll t) const {
if (!t) return 1;
mint a = pow(t >> 1);
a *= a;// 桁ずらし
if (t & 1) a *= *this;
return a;
}
// for prime mod
mint inv() const { return pow(mod - 2); }
mint& operator/=(const mint a) { return (*this) *= a.inv(); }
mint operator/(const mint a) const {
mint res(*this);
return res /= a;
}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }
int main() {
//入力の高速化用のコード
ios::sync_with_stdio(false);
cin.tie(nullptr);
std::cout << std::setprecision(15);
//////////////////////////////////////////
ll n ,p;
cin >> n >> p;
mint x = p-2;
x = x.pow(n-1) * (p-1);
print(x.x);
return 0;
}
|
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define ld long double
#define mod 1000000007
#define mod2 998244353
#define ff first
#define ss second
#define pb push_back
#define endl "\n"
#define vi vector<int>
#define si set<int>
#define pii pair<int,int>
#define mii map<int,int>
#define umii unordered_map<int,int>
#define vii vector<pii>
#define sii set<pii>
#define vvi vector<vi>
#define vvii vector<vii>
#define vsi vector<si>
#define in(arr,n) for(int i=0;i<n;i++)cin>>arr[i];
#define out(arr,n) for(int i=0;i<n;i++)cout<<arr[i]<<" ";cout<<endl;
#define inn(arr,m,n) for(int i=m;i<n;i++)cin>>arr[i];
#define outt(arr,m,n) for(int i=m;i<n;i++)cout<<arr[i]<<" ";cout<<endl;
#define narr int arr[n];in(arr,n)
#define nbrr int brr[n];in(brr,n)
#define intt(n,m) int n,m;cin>>n>>m;
using namespace std;
void solve1();
int power(int x, int y, int p){
//if(x==0&&y==0)return 1;
int res = 1;x = x % p;if (x == 0) return 0;
while (y > 0){if (y & 1)res = (res*x) % p;y = y>>1;x = (x*x) % p;}
return res;
}
int power(int x, int y){
//if(x==0&&y==0)return 1;
int res = 1;if (x == 0) return 0;
while (y > 0){if (y & 1)res = (res*x);y = y>>1;x = (x*x);}
return res;
}
int fib(int s1) {
int s2, s4, s5, s3;
s2 = s3 = 1;
s4 = s5 = 0;
while (s1 > 0) {
if (s1 % 2 == 0) {
int s6 = s3*s3;
s3 = 2*s5*s3 + s6;
s5 = s5*s5 + s6;
s1 /= 2;
} else {
int s6 = s2*s3;
s2 = s4*s3 + s6 + s2*s5;
s4 = s4*s5 + s6;
s1 -= 1;
}
}
return s4;
}
int sum(int arr[],int a,int n)
{
int zz=0;
for(int i=a;i<n;i++)
{
zz+=arr[i];
}
return zz;
}
void solve(){
int t;cin>>t;
while(t--){solve1();}
}
signed main()
{
//std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
solve1();
return 0;
}
void solve1()
{
int n,m,a,b;cin>>n>>m;
if(n==1&&m==0)
{
cout<<1<< " "<<3<<endl;return;
}
if(((m<0)||(m>=n-1)))
{
cout<<-1<<endl;return;
}
int arr[n][2];
arr[0][0]=2;arr[0][1]=4;
for(int i=1;i<n;i++)
{
arr[i][0]=arr[i-1][0]+4;
arr[i][1]=arr[i-1][1]+4;
}
if(m>0)
{
arr[0][1]+=(m)*4+3;
}
else if(m<0)
{
arr[n-1][0]-=3+(abs(m))*4;
}
for(int i=0;i<n;i++)
{
cout<<arr[i][0]<<" "<<arr[i][1]<<endl;
}
}
| #pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = 1'000'000'007LL; /*998'244'353LL;*/
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dx[4]={ 1,0,-1,0 };
const int dy[4]={ 0,1,0,-1 };
int N, M;
signed main(){
cin >> N >> M;
if(N == 1){
if(M == 0) cout << 1 << " " << 2 << endl;
else cout << -1 << endl;
return 0;
}
if(N == 2){
if(M == 0){
cout << 1 << " " << 2 << endl;
cout << 3 << " " << 4 << endl;
}
else{
cout << -1 << endl;
}
return 0;
}
if(M < 0 || M > N-2){
cout << -1 << endl;
return 0;
}
if(M == 0){
rep(i, N){
cout << 2*i+1 << " " << 2*i+2 << endl;
}
}
else{
cout << 1 << " " << 100000000 << endl;
rep(i, M+1){
cout << 2*i+2 << " " << 2*i+3 << endl;
}
rep(i, N-1-(M+1)){
cout << 100000000 + 2*i+1 << " " << 100000000 + 2*i+2 << endl;
}
}
} |
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
using namespace std;
#define MAXN 100005
#define lowbit(x) (x&-x)
#define reg register
typedef long long LL;
typedef unsigned long long uLL;
typedef unsigned int uint;
typedef pair<int,int> pii;
const int INF=0x7f7f7f7f;
const int mo=998244353;
const double PI=acos(-1.0);
template<typename _T>
_T Fabs(_T x){return x<0?-x:x;}
template<typename _T>
void read(_T &x){
_T f=1;x=0;char s=getchar();
while(s>'9'||s<'0'){if(s=='-')f=-1;s=getchar();}
while('0'<=s&&s<='9'){x=(x<<3)+(x<<1)+(s^48);s=getchar();}
x*=f;
}
int a,b;LL dp[35][35],k;
char str[65];
signed main(){
dp[0][0]=1;
for(int i=0;i<=30;i++)
for(int j=0;j<=30;j++){
if(i)dp[i][j]+=dp[i-1][j];
if(j)dp[i][j]+=dp[i][j-1];
}
read(a);read(b);read(k);int len=a+b;
for(int i=1;i<=len;i++){
if(a&&b){
if(k>dp[a-1][b])k-=dp[a-1][b],str[i]='b',b--;
else str[i]='a',a--;
}
else if(!a)str[i]='b',b--;
else if(!b)str[i]='a',a--;
//printf("%d %d %d:%d %d %d\n",a,b,k,dp[a][b],dp[a-1][b],dp[a][b-1]);
}
printf("%s\n",str+1);
return 0;
}
|
#include"bits/stdc++.h"
#define rep(i,n) for(ll i=0;i<n;++i)
#define ALL(x) x.begin(),x.end()
#define BACK(x) x.rbegin(),x.rend()
#define MOD 1000000007
#define INF INT_MAX
#define FLOAT_ANS setprecision(30)
#define TORAD(x) (x*acos(-1)/180.0)
#define TODEG(x) (x*180/acos(-1))
#define elif else if
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template<typename T>
bool chmin(T& a,T b){
if(a>b){
a=b;
return true;
}
return false;
}
template<typename T>
bool chmax(T& a,T b){
if(a<b){
a=b;
return true;
}
return false;
}
ll modpow(ll a, ll n, ll mod) {
ll res=1;
while (n>0) {
if(n&1)res=(res*(a%mod))%mod;
a=((a%mod)*(a%mod))%mod;
n>>=1;
}
return res;
}
// MAIN PROGRAM -------------
int main(){
string s;
cin>>s;
ll n=s.length();
vector<char>t(n*2+100,'.');
ll left=n+10,right=n+9;
bool turn = false;
for(auto c:s){
if(c=='R'){
turn=!turn;
--n;
}
else{
if(turn){
--left;
t[left]=c;
}
else{
++right;
t[right]=c;
}
}
}
stack<char>stk;
rep(i,n){
if(!stk.empty() && stk.top()==t[left+i]){
stk.pop();
}
else{
stk.push(t[left+i]);
}
}
vector<char>ans;
while(!stk.empty()){
ans.push_back(stk.top());
stk.pop();
}
if(turn){
for(auto i:ans){
cout<<i;
}
}
else{
for(ll i=ans.size()-1; i>=0; --i)cout<<ans[i];
}
}
/*
*/ |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAXV = 1000000;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int l, r;
cin >> l >> r;
int n = r - l + 1;
int m = r;
vector<int> a(n);
iota(a.begin(), a.end(), l);
vector<int> is_prime(m + 1, true);
vector<int> num(m + 1, 0);
vector<int> fs(m + 1, 1);
is_prime[0] = false;
is_prime[1] = false;
for (int i = 2; i <= m; i++) {
if (!is_prime[i]) continue;
num[i]++;
fs[i] *= i;
for (int j = 2 * i; j <= m; j += i) {
is_prime[j] = false;
num[j]++;
fs[j] *= i;
}
}
vector<int> cnt(m + 1, 0);
for (int i = 0; i < n; i++) {
if (a[i] <= m && fs[a[i]] == a[i]) cnt[a[i]]++;
for (int j = 2; j * j <= a[i]; j++) {
if (a[i] % j != 0) continue;
if (j <= m && fs[j] == j) cnt[j]++;
if (j * j == a[i]) continue;
int k = a[i] / j;
if (k <= m && fs[k] == k) cnt[k]++;
}
}
vector<int> ans(m + 1, 0);
for (int i = 2; i <= m; i++) {
if (fs[i] != i) continue;
for (int j = i; j <= m; j += i) {
if (num[i] % 2 == 0) ans[j] -= cnt[i];
else ans[j] += cnt[i];
}
}
ll total_ans = 0;
for (int i = l; i <= r; i++) {
if (i == 1) continue;
total_ans += ans[i] - 2 * (r / i - (l - 1) / i) + 1;
}
cout << total_ans << "\n";
return 0;
} | #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>
using namespace std;
typedef long long ll;
#define fi first
#define se second
const ll mod=1e9+7;
string t="atcoder";
void solve(){
string s;cin >> s;
int ans=1e9;
int cur=0;
bool totok=true;
for(int i=0; i<7 ;i++){
for(int j=0; j<s.size() ;j++){
if(s[j]>t[i]) ans=min(ans,cur+j);
}
bool ok=false;
for(int j=0; j<s.size() ;j++){
if(s[j]==t[i]){
s.erase(j,1);
cur+=j;
ok=true;
break;
}
}
if(!ok){
totok=false;
break;
}
}
if(s.size()>0 && totok) ans=min(ans,cur);
if(ans>1e8) cout << "-1\n";
else cout << ans << '\n';
}
int main(){
ios::sync_with_stdio(false);cin.tie(0);
int t;cin >> t;while(t--) solve();
} | #include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
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 (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#define ynmes(a) (a) ? mes("Yes") : mes("No")
#define YNmes(a) (a) ? mes("YES") : mes("NO")
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
struct io { io() { ios::sync_with_stdio(false); cin.tie(0); } };
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;
ll gcd(ll a, ll b) {
return b ? gcd(b, a%b) : a;
}
ll lcm(ll a, ll b) {
return a / gcd(a, b) * b;
}
ll nlcm(vector<ll> numbers) {
ll res;
res = numbers[0];
for (ll i = 1; i < (ll)numbers.size(); i++) {
res = lcm(res, numbers[i]);
}
return res;
}
uintmax_t ncr(unsigned int n, unsigned int r) {
if ( r * 2 > n ) r = n - r;
uintmax_t dividend = 1;
uintmax_t divisor = 1;
for ( unsigned int i = 1; i <= r; ++i ) {
dividend *= (n-i+1);
divisor *= i;
}
return dividend / divisor;
}
signed main() {
ll t;
cin >> t;
rep(i, t) {
string s;
cin >> s;
ll len = (ll)s.size();
if ("atcoder" < s) {
mes(0);
continue;
}
ll tmp = 0;
rep(j, len) {
if (s[j] == 'a') {
tmp++;
if (tmp == len) {
mes(-1);
break;
}
} else {
if (s[j] > 't') {
mes(tmp-1);
} else {
mes(tmp);
}
break;
}
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
int main(){
int n,w;
cin >> n >> w;
vector<int> s(n),t(n),p(n);
for(int i=0; i<n; ++i)
cin >> s[i] >> t[i] >> p[i];
vector<ll> oyu(*max_element(t.begin(), t.end()),0);
for(int i=0; i<n; ++i) {
oyu[s[i]] += p[i];
oyu[t[i]] -= p[i];
}
for(int i=1; i<oyu.size(); ++i)
oyu[i] += oyu[i-1];
cout << (*max_element(oyu.begin(), oyu.end())>w ? "No" : "Yes") << endl;
}
| // Pratiyush Mishra
#include <bits/stdc++.h>
#define ull unsigned long long int
#define ll long long int
#define LL_MAX 9223372036854775807
#define pb push_back
#define pf push_front
#define mp make_pair
#define popb pop_back
#define vl vector<ll>
#define bs(v, x) binary_search(v.begin(), v.end(), x)
#define mem1(a) memset(a, -1, sizeof(a))
#define popf pop_front
#define p() cout << '\n'
#define p0(x) cout << x << " "
#define p1(x) cout << x << '\n'
#define p2(x, y) cout << x << " " << y << '\n'
#define p3(x, y, z) cout << x << " " << y << " " << z << '\n'
#define printv(v) \
for (ll i = 0; i < v.size(); ++i) \
cout << v[i] << " "; \
cout << '\n'
#define pr1(x) cout << fixed << setprecision(15) << x << '\n'
#define ordered_set tree<pair<ll, ll>, null_type, less<pair<ll, ll>>, rb_tree_tag, tree_order_statistics_node_update>
// ordered_set s ; s.order_of_key(val) no. of elements strictly less than val
// s.find_by_order(i) itertor to ith element (0 indexed)
#define mod 1000000007
#define mod1 998244353
#define fio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL)
#define get(n) \
ll n; \
cin >> n
#define getvec(v, n) \
vector<ll> v(n); \
for (ll i = 0; i < n; i++) \
cin >> v[i];
#define getstr(s) \
string s; \
cin >> s
#define all(x) x.begin(), x.end()
#define countBits(x) __builtin_popcount(x)
using namespace std;
const ll M = 2e5;
void mainSolve()
{
get(n);
get(w);
vl v(M + 1, 0);
for (int i = 0; i < n; i++)
{
ll p, s, e;
cin >> s >> e >> p;
v[s] += p;
v[e] -= p;
}
for (int i = 1; i <= M; i++)
v[i] += v[i - 1];
for (ll x : v)
{
if (x > w)
{
p1("No");
return;
}
}
p1("Yes");
}
int main()
{
fio;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
//get(t);
ll t = 1;
while (t--)
{
mainSolve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
using ll = long long;
int main(){
string s;
cin>>s;
if(s.size()<3){
if(s.size()==1){
if(s == "8"){
cout << "Yes" << endl;
return 0;
}
cout << "No" << endl;
return 0;
}
int a = s[0]-'0';
int b = s[1]-'0';
if((10*a+b)%8 == 0 || (10*b+a)%8 == 0){
cout << "Yes" << endl;
return 0;
}
cout << "No" << endl;
return 0;
}
int test[10];
int test2[10];
int test3[113] = {000,104, 112, 120, 128, 136, 144, 152, 160, 168, 176, 184, 192, 200, 208, 216, 224, 232, 240, 248, 256, 264, 272, 280, 288, 296, 304, 312, 320, 328, 336, 344, 352, 360, 368, 376, 384, 392, 400, 408, 416, 424, 432, 440, 448, 456, 464, 472, 480, 488, 496, 504, 512, 520, 528, 536, 544, 552, 560, 568, 576, 584, 592, 600, 608, 616, 624, 632, 640, 648, 656, 664, 672, 680, 688, 696, 704, 712, 720, 728, 736, 744, 752, 760, 768, 776, 784, 792, 800, 808, 816, 824, 832, 840, 848, 856, 864, 872, 880, 888, 896, 904, 912, 920, 928, 936, 944, 952, 960, 968, 976, 984, 992};
rep(x,10){
test[x] = 0;
test2[x] = 0;
}
rep(i,int(s.size())){
int a = s[i] - '0';
test[a]++;
}
rep(i,113){
rep(j,10) test2[j] = 0;
int a,b,c;
a = test3[i]%10;
b = test3[i]/100;
c = (test3[i]%100)/10;
test2[a]++;
test2[b]++;
test2[c]++;
rep(j,10){
if(test2[j]>test[j]) break;
if(j == 9){
cout << "Yes" << endl;
return 0;
}
}
}
cout << "No" << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define endl "\n"
#define all(v) v.begin(),v.end()
#define double long double
#define trace1(x) cerr<<#x<<": "<<x<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e) cerr<<#a<<": "<<a<<" | "<<#b<< ": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define cases int testcases;cin>>testcases; while(testcases--)
const int N = 200005;
#define rep(i, x, y) for (__typeof(x) i = x; i <= y; i ++)
#define repi(i, x, y) for (__typeof(x) i = x; i >= y; i --)
int32_t main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
IOS
set<string> ss,sss;
int n;
cin >> n;
while(n--)
{
string s;
cin >> s;
if(s[0] == '!')
{
string str;
for(int i = 1; i< s.size(); i++)
{
str.push_back(s[i]);
}
sss.insert(str);
}
else
{
ss.insert(s);
}
}
for(auto &i : ss)
{
if(sss.count(i))
{
cout << i ;
return 0;
}
}
cout << "satisfiable";
return 0;
}
|
//Badwaper gg
#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 FOR(i,a,b) for(re i=a;i<=b;i++)
#define REP(i,a,b) for(re i=a;i>=b;i--)
#define lowbit(x) x&(-x)
#define Z(x) (x>=mod?x-mod:x)
#define pa pair<int,int>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
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;
}
ll n;
int main()
{
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
n=read();
ll l=0,r=2e9,ans=0;
while(l<=r)
{
ll mid=(l+r)>>1;
if(mid*(mid+1)/2<=n+1)ans=mid,l=mid+1;
else r=mid-1;
}
//cout<<"WTF:"<<ans<<" "<<ans*(ans+1)/2;
printf("%lld\n",n-ans+1);
return 0;
}
| //author: hitch_hiker42;
#include<bits/stdc++.h>
using namespace std;
//solution:
#define int int64_t
#define span(a) begin(a), end(a)
struct segtree {
int n;
static inline int size = 1;
vector<int> t, lazy;
segtree() = default;
segtree(int n): n(n) {
while(size < n) size <<= 1;
t.assign(size << 1, 0);
lazy.assign(size << 1, 0);
}
void push(int x, int l, int r) {
//a[l, r] += x ---> delta = (r - l) * lazy;
int m = l + r >> 1;
t[2 * x + 1] += lazy[x] * (m - l);
t[2 * x + 2] += lazy[x] * (r - m);
lazy[2 * x + 1] += lazy[x];
lazy[2 * x + 2] += lazy[x];
lazy[x] = 0;
}
int query(int lo, int hi, int x = 0, int l = 0, int r = size) {
if(lo >= r || l >= hi) return 0;
if(lo <= l and r <= hi) return t[x];
push(x, l, r);
int m = l + r >> 1;
return query(lo, hi, 2 * x + 1, l, m) + query(lo, hi, 2 * x + 2, m, r);
}
void update(int lo, int hi, int v, int x = 0, int l = 0, int r = size) {
if(lo >= r || l >= hi) return;
if(lo <= l and r <= hi) {
t[x] += v * (r - l), lazy[x] += v; //remember how t[x] is updated here!
return;
}
push(x, l, r);
int m = l + r >> 1;
update(lo, hi, v, 2 * x + 1, l, m);
update(lo, hi, v, 2 * x + 2, m, r);
t[x] = t[2 * x + 1] + t[2 * x + 2];
}
};
void hike() {
int n; cin >> n;
vector<int> a(n);
segtree s(n), t(n);
for(int i = 0; i < n; ++i) cin >> a[i];
for(int i = n - 1; ~i; --i) {
s.update(a[i], a[i] + 1, t.query(0, a[i]));
t.update(a[i], a[i] + 1, 1);
}
for(int i = 0; i < n; ++i) {
cout << s.query(0, n) << "\n";
s.update(a[i] + 1, n, 1);
s.update(0, a[i], -1);
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
int t = 1; //cin >> t;
while(t--) hike();
return 0;
} //farewell, until we meet again.. |
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define ALL(a) (a).begin(), (a).end()
#define min_e(v) *min_element(ALL(v))
#define max_e(v) *max_element(ALL(v))
#define acm accumulate
#define SUM(v) accumulate(ALL(v), 0l)
#define SORT(v) sort(ALL(v))
#define P 1000000007
long powP (long a, long b) {
if (b == 1) return a;
else if (b == 0) return 1;
else if (b < 0) return powP(a, P - 1 + b);
else {
long b2 = powP(a, b/2);
b2*=b2;
b2%=P;
return (b2 * powP(a, b%2)) % P;
}
}
template <typename T>
using vec = vector<T>;
template <typename T>
using vvec = vector<vector<T>>;
#define INF INT_MAX
#define pii pair<int, int>
int main() {
long n;
cin>>n;
vec<long> fib(2,1);
do {
fib.push_back(*(fib.end()-1)+*(fib.end()-2));
} while (fib.back()<pow(10,18));
int m = fib.size();
vec<int> fibs(m);
int o = (upper_bound(ALL(fib), n)-fib.begin()-1);
while (n!=0) {
int i = (upper_bound(ALL(fib), n)-fib.begin()-1);
fibs[i]++;
n-=fib[i];
}
int flag = o%2;
vec<int> exe(0);
for (int i = o; i >= 0; i--) {
exe.push_back(3+flag);
for (int j = 0; j < fibs[i]; j++) {
exe.push_back(1+flag);
}
flag=1-flag;
}
cout<<exe.size()<<endl;
for (int i = 0; i < exe.size(); i++) {
cout<<exe[i]<<endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
#define pp pair<ll,ll>
ll MOD=1000000007;
ll mod=998244353;
int inf=2000001000;
ll INF=1e18+5;
int main() {
ll n;
cin >> n;
vector<ll> a;
a.push_back(1);
a.push_back(1);
int u=0;
while(true){
if (a[u]+a[u+1]>n) break;
a.push_back(a[u]+a[u+1]);
u++;
}
u=a.size();
n-=a[u-1];
vector<int> c(u);
rep(i,a.size()){
while(true){
if (n<a[u-i-1]) break;
c[u-i-1]++;
n-=a[u-i-1];
}
}
if (n==1){
cout << 1 << endl;
cout << 1 << endl;
return 0;
}
vector<int> ans;
int st;
// cout << u << endl;
// rep(i,u) cout << a[i] << endl;
// cout << endl;
if (u%2==1){
st=0;
ans.push_back(1);
}
else {
st=1;
ans.push_back(2);
}
rep(i,a.size()-1){
rep(j,c[u-1-i]){
if (st==0) ans.push_back(1);
else ans.push_back(2);
}
if (st==0) ans.push_back(4);
else ans.push_back(3);
st=1-st;
}
cout << ans.size() << endl;
rep(i,ans.size()){
cout << ans[i] << endl;
}
}
|
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
typedef pair<ll, bool> pib;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<double> vf;
typedef long double ld;
#define mp make_pair
#define pb push_back
#define rep(i, N) for(ll i = 0; i < N; i++)
#define repa(i, a, N) for(ll i = a; i < N; i++)
#define repr(i, N) for(ll i = N-1; i >= 0; i--)
#define drep(i, N, j, M) rep(i, N) rep(j, M)
#define trep(i, N, j, M, k, L) rep(i, N) rep(j, M) rep(k, L)
#define all(A) A.begin(), A.end()
#define printItr(A) for(auto itr = A.begin(); itr != A.end(); ++itr){cout << * itr << ", ";}cout << endl;
const double PI = 3.141592653589793;
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const ll LLMAX = numeric_limits<long long>::max();
void No() {
cout << "No" << endl;
}
void Yes() {
cout << "Yes" << endl;
}
ll id(char c) {
return c - 'a';
}
bool isOK(vi& a, ll k, ll index) {
return a[index] < k * (index + 1);
}
ll binary_search(vi& a, ll k) {
ll left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
ll right = (ll)a.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
/* どんな二分探索でもここの書き方を変えずにできる! */
while (right - left > 1) {
ll mid = left + (right - left) / 2;
if (isOK(a, k, mid))
right = mid;
else left = mid;
}
/* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
return right;
}
template<class t, class u>
ostream& operator<<(ostream& os, const pair<t, u>& p) {
return os << "{" << p.first << "," << p.second << "}";
}
template<class t> ostream& operator<<(ostream& os, const vector<t>& v) {
os << "{";
for (auto e : v)os << e << ",";
return os << "}";
}
bool eq(vi P, vi Q) {
rep(i, P.size()) {
if (P[i] != Q[i]) {
return false;
}
}
return true;
}
ll gcd(ll a, ll b)
{
if (a%b == 0)
{
return(b);
}
else
{
return(gcd(b, a%b));
}
}
ll lcm(ll a, ll b)
{
return a * b / gcd(a, b);
}
ll modinv(ll a, ll m) {
ll b = m, u = 1, v = 0;
while (b) {
ll t = a / b;
a -= t * b; swap(a, b);
u -= t * v; swap(u, v);
}
u %= m;
if (u < 0) u += m;
return u;
}
int main() {
ll N, K, M;
cin >> N >> K >> M;
ll s = 0;
rep(i, N - 1) {
ll a;
cin >> a;
s += a;
}
ll ans = N * M - s;
if (ans < 0) {
ans = 0;
}
if (ans > K) {
ans = -1;
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
int main() {
int n,k,m,a;
cin >>n>>k>>m;
int sum=0;
rep(i,n-1){
cin>>a;
sum+=a;
}
rep(i,k+1){
if((sum+i)>=m*n){
cout << i <<endl;
return 0;
}
}
cout << -1 <<endl;
} |
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define F first
#define S second
int main(){
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
ll n; cin >> n;
vector<ll> r, g, b;
for(int i = 0; i < 2*n; i++){
ll x; cin >> x;
char c; cin >> c;
if(c == 'R') r.push_back(x);
else if(c == 'G') g.push_back(x);
else b.push_back(x);
}
sort(r.begin(), r.end());
sort(g.begin(), g.end());
sort(b.begin(), b.end());
ll x = 0, y = 0, z = 0, ans = LLONG_MAX;
x = y = z = ans;
if(r.size() & 1){
if(b.size() & 1) swap(g, b);
} else if(g.size() & 1){
swap(r, b);
} else {
ans = 0;
}
for(auto &i: r){
auto p = lower_bound(g.begin(), g.end(), i);
if(p != g.end()) x = min(x, abs(i - *p));
if(p != g.begin()) x = min(x, abs(i - *prev(p)));
}
for(auto &i: g){
auto p = lower_bound(b.begin(), b.end(), i);
if(p != b.end()) y = min(y, abs(i - *p));
if(p != b.begin()) y = min(y, abs(i - *prev(p)));
}
for(auto &i: r){
auto p = lower_bound(b.begin(), b.end(), i);
if(p != b.end()) z = min(z, abs(i - *p));
if(p != b.begin()) z = min(z, abs(i - *prev(p)));
}
ans = min(ans, x);
if(y != LLONG_MAX && z != LLONG_MAX) ans = min(ans, y + z);
cout << ans << '\n';
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vc = vector<T>;
template<class T> using vvc = vc<vc<T>>;
template<class T> using vvvc = vc<vvc<T>>;
template<class T> using vvvvc = vvc<vvc<T>>;
template<class T> using PQ = priority_queue<T>;
template<class T> using invPQ = priority_queue<T, vector<T>, greater<T>>;
using IP = pair<int, int>;
using LP = pair<ll, ll>;
#define all(x) begin(x), end(x)
#define rep(i, n) for (int i = 0; (i) < (int)(n); i++)
#define rep3(i, m, n) for (int i = (m); (i) < (int)(n); i++)
#define repr(i, n) for (int i = (n) - 1; (i) >= 0; i--)
#define rep3r(i, m, n) for (int i = (n) - 1; (i) >= (int)(m); i--)
template<class T> inline bool chmax(T & a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T & a, T b) { if (a > b) { a = b; return 1; } return 0; }
constexpr long long LINF = 4611686015206162431;
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int N;
cin >> N;
ll a[2*N];
vc<int> c(2*N);
vvc<ll> dogs(3);
rep (i, N*2) {
cin >> a[i];
char col;
cin >> col;
if (col == 'G') c[i] = 1;
else if (col == 'B') c[i] = 2;
dogs[c[i]].emplace_back(a[i]);
}
rep (i, 3) {
sort(all(dogs[i]));
}
int oddcnt = dogs[0].size() % 2 + dogs[1].size() % 2 + dogs[2].size() % 2;
ll ans = LINF;
if (oddcnt == 0) ans = 0;
else {
int even = 0;
rep (i, 3) if (dogs[i].size() % 2 == 0) even = i;
int odd1 = (even + 1) % 3, odd2 = (even + 2) % 3;
rep (i, dogs[odd1].size()) {
int pos = lower_bound(all(dogs[odd2]), dogs[odd1][i]) - dogs[odd2].begin();
if (pos < dogs[odd2].size()) chmin(ans, abs(dogs[odd2][pos] - dogs[odd1][i]));
if (pos > 0) {
chmin(ans, abs(dogs[odd2][pos-1] - dogs[odd1][i]));
}
}
ll tmp1 = LINF, tmp2 = LINF;
rep (i, dogs[odd1].size()) {
int pos1 = lower_bound(all(dogs[even]), dogs[odd1][i]) - dogs[even].begin();
if (pos1 < dogs[even].size()) chmin(tmp1, abs(dogs[even][pos1] - dogs[odd1][i]));
if (pos1 > 0) chmin(tmp1, abs(dogs[even][pos1-1] - dogs[odd1][i]));
}
rep (i, dogs[odd2].size()) {
int pos2 = lower_bound(all(dogs[even]), dogs[odd2][i]) - dogs[even].begin();
if (pos2 < dogs[even].size()) chmin(tmp2, abs(dogs[even][pos2] - dogs[odd2][i]));
if (pos2 > 0) chmin(tmp2, abs(dogs[even][pos2-1] - dogs[odd2][i]));
}
chmin(ans, tmp1 + tmp2);
}
cout << ans << endl;
} |
#include<bits/stdc++.h>
#define faster ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ull unsigned long long
#define pb push_back
const double PI = acos(-1.0);
using namespace std;
ll a[300009];
ll tree[900099];
int c;
void seg(ll node,ll b,ll e)
{
if(b==e)
{
//cout<<node<<" "<<a[b]<<endl;
tree[node]=a[b];
//cout<<tree[node].value<<endl;
return;
}
ll left=node*2;
ll right=(node*2)+1;
ll mid=(b+e)/2;
seg(left,b,mid);
seg(right,mid+1,e);
tree[node]=tree[left]^tree[right];
}
ll query(int node,int b,int e,int i,int j)
{
if(i>e || j<b)
return 0;
if(i<=b && e<=j)
return tree[node];
ll left=node*2;
ll right=(node*2)+1;
ll mid=(b+e)/2;
ll x=query(left,b,mid,i,j);
ll y=query(right,mid+1,e,i,j);
return x^y;
}
void update(ll node,ll b,ll e,ll i,ll value)
{
if(i>e || i<b)
return;
if(i<=b && e<=i)
{
tree[node]^=value;
return;
}
ll left=node*2;
ll right=(node*2)+1;
ll mid=(b+e)/2;
update(left,b,mid,i,value);
update(right,mid+1,e,i,value);
tree[node]=tree[left]^tree[right];
}
int main()
{
faster
int n,q;
cin>>n>>q;
for(int i=1; i<=n; i++)
cin>>a[i];
seg(1,1,n);
/*for(int i=1; i<=3*n; i++)
cout<<tree[i].value<<" ";
cout<<endl;*/
ll t,l,r;
while(q--)
{
cin>>t>>l>>r;
if(t==1)
{
update(1,1,n,l,r);
}
else
{
cout<<query(1,1,n,l,r)<<endl;
}
}
return 0;
}
| #include<ctime>
#include<cstdio>
#include<cctype>
#define le(p) ((p)<<1)
#define ri(p) ((p)<<1|1)
using namespace std;
const int N=1.2e6+7;
int read(){
char c;
int x=0,f=1;
while(!isdigit(c=getchar()))
f-=2*(c=='-');
while(isdigit(c)){
x=x*10+f*(c-48);
c=getchar();
}
return x;
}
int n,q,t,x,y,a[N];
int L[N],R[N],X[N];
void up(int p){
X[p]=X[le(p)]^X[ri(p)];
}
void build(int p,int l,int r){
L[p]=l;
R[p]=r;
if(l==r){
X[p]=a[l];
return;
}
int m=(l+r)>>1;
build(le(p),l,m);
build(ri(p),m+1,r);
up(p);
}
void upd(int p,int x,int k){
if(L[p]==R[p]){
X[p]^=k;
return;
}
int m=(L[p]+R[p])>>1;
if(x<=m)
upd(le(p),x,k);
else
upd(ri(p),x,k);
up(p);
}
int ask(int p,int l,int r){
if(l<=L[p]&&R[p]<=r)
return X[p];
int m=(L[p]+R[p])>>1;
int res=0;
if(l<=m)
res^=ask(le(p),l,r);
if(r>m)
res^=ask(ri(p),l,r);
return res;
}
int main(){
#ifndef ONLINE_JUDGE
freopen("F.in","r",stdin);
freopen("F.out","w",stdout);
#endif
clock_t t1=clock();
//--------
n=read();
q=read();
for(int i=1;i<=n;++i)
a[i]=read();
build(1,1,n);
for(int i=1;i<=q;++i){
t=read();
x=read();
y=read();
if(t==1)
upd(1,x,y);
else
printf("%d\n",ask(1,x,y));
}
//--------
fprintf(stderr,"%0.3lfs",1.0*(clock()-t1)/CLOCKS_PER_SEC);
return 0;
} |
#include <iostream>
#include <cstdlib>
#include <time.h>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <array>
#include <string>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define mp make_pair
#define eb emplace_back
#define f first
#define s second
#define sz(x) (ll)x.size()
#define lnt(s) (ll)s.length()
#define mt(cnt) cnt.empty()
using namespace std;
using namespace __gnu_pbds;
typedef long long int ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> osSet;
using pll = pair<ll, ll>;
using pl = pair<ll, pll>;
using tll = tuple<ll, ll, ll>;
const ll maxN = 1e5;
const ll INF = 1e17;
const ll MOD = 1e9 + 7;
ll xs[] = {-1, 1, 0, 0, -1, 1, 1, -1};
ll ys[] = {0, 0, -1, 1, -1, 1, -1, 1};
ll segtree[maxN << 2];
ll lazy[maxN << 2];
ll A[maxN];
inline ll left(ll x){
return x << 1;
}
inline ll right(ll x){
return (x<<1) + 1;
}
ll func(ll x){
return (x*(x+1))/2;
}
ll _pow(ll b, ll p){
if(p == 0) return 1;
if(p == 1) return b;
ll exB = b*b;
if(p&1) return b*_pow(exB, p/2);
return _pow(exB, p/2);
}
int main(){
cin.sync_with_stdio(false);
cin.tie(0);
ll n, m;
cin >> n >> m;
ll ar[m];
for(ll i=0; i<m; i++)
cin >> ar[i];
sort(ar, ar+m);
vector<ll> v;
ll low = 0;
for(ll i=0; i<m; i++){
if(i == m-1 and ar[i] != n){
v.emplace_back(n-ar[i]);
}
v.emplace_back(ar[i]-low-1);
low = ar[i];
}
if(!(n-m))
cout << "0";
else if(!m)
cout << "1";
else{
ll mn = INF, ans = 0;
for(ll i=0; i<v.size(); i++){
if(v[i] != 0)
mn = min(mn, v[i]);
}
for(ll i=0; i<v.size(); i++)
ans += v[i]/mn + (v[i]%mn != 0 ? 1 : 0);
cout << ans;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
// --------------------------------------------------------
template <class T>
bool chmax(T& a, const T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T>
bool chmin(T& a, const T b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
#define FOR(i, l, r) for (int i = (l); i < (r); ++i)
#define RFOR(i, l, r) for (int i = (r)-1; (l) <= i; --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define MIN(c) *min_element(ALL(c))
#define MAX(c) *max_element(ALL(c))
#define SUM(c) accumulate(ALL(c), 0)
#define SUMLL(c) accumulate(ALL(c), 0LL)
#define SZ(c) ((int)(c).size())
#define CIN(c) cin >> (c)
#define COUT(c) cout << (c) << '\n'
#define debug(x) cerr << #x << " = " << (x) << '\n';
using P = pair<ll, ll>;
using VP = vector<P>;
using VVP = vector<VP>;
using VS = vector<string>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<ll>;
using VVLL = vector<VLL>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
static const double EPS = 1e-10;
static const double PI = acos(-1.0);
static const ll MOD = 1000000007;
// static const ll MOD = 998244353;
static const int INF = (1 << 30) - 1; // 1073741824 - 1
// static const ll INF = (1LL << 60) - 1; // 4611686018427387904 - 1
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll N, M;
cin >> N >> M;
if (M == 0) {
COUT(1);
return 0;
}
VLL A(M);
REP(i, M) {
CIN(A[i]);
}
SORT(A);
ll minVal = INF;
ll bef = 1;
VI between;
A.push_back(N + 1);
// A.push_back(N);
REP(i, M + 1) {
ll p = A[i] - bef;
bef = A[i] + 1;
if (p <= 0) continue;
chmin(minVal, p);
between.push_back(p);
}
ll ans = 0;
for (auto v : between) {
ans += ceil(v / (double)minVal);
}
COUT(ans);
return 0;
} |
#include <iostream>
#include <string>
using namespace std;
int main(void) {
long long N, K;
cin >> N >> K;
for (int i = 0; i < K; i++) {
if (N % 200 == 0) {
N /= 200;
}
else {
N *= 1000;
N += 200;
}
}
cout << N << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#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 ALL(x) x.begin(),x.end()
#define SIZE(x) ll(x.size())
#define INF (int)1e9
#define LLINF (ll)1e12
#define MOD (int)1e9+7
#define PB push_back
#define endl "\n"
#define YESNO(T) if(T){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(T) if(T){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define PRINT(I) cout<<(I)<<endl
void solve() {
ll n,k;
cin >> n >> k;
REP(i,k){
if(n%200==0){
n /= 200;
}else{
n = n*1000+200;
}
}
cout << n << endl;
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
solve();
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define all(v) (v.begin(),v.end())
#define sz(v) ((int)((v).size()))
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define endl '\n'
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair< ll, ll> pll;
typedef vector<pll> vll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ull> vul;
typedef vector<pii> vii;
typedef vector<vi> vvi;
void fast() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("inputf.txt", "r", stdin);
freopen("outputf.txt", "w", stdout);
#endif
}
void solve()
{
}
bool have_7(int num)
{
while (num)
{
int d = num % 10;
num /= 10;
if (d == 7) return true;
}
return false;
}
int decimaltooctal(int decimalNum)
{
int octalNum = 0, placeValue = 1;
int dNo = decimalNum;
while (decimalNum != 0) {
octalNum += (decimalNum % 8) * placeValue;
decimalNum /= 8;
placeValue *= 10;
}
return octalNum;
}
int to_int(string s)
{
stringstream k(s);
int x = 0;
k >> x;
return x;
}
int main() {
fast();
int n;
cin >> n;
int res = n;
for (int i = 1; i <= n; i++)
{
if (have_7(decimaltooctal(i)) || have_7(i))
res--;
}
cout << res << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;
signed main() {
int n;
cin >> n;
int m = n / 2;
ll a[n], b[n];
rep(i, n) {
cin >> a[i];
}
rep(i, n) {
cin >> b[i];
}
ll ans = 0;
vector<ll> even, odd;
rep(i, n) {
ll c = a[i] - b[i];
if (i % 2 == 0) {
even.emplace_back(c);
} else {
odd.emplace_back(c);
}
ans += max(a[i], b[i]);
}
sort(ALL(even));
sort(ALL(odd));
rep(i, m) {
if (even[i] * odd[i] < 0) {
ans -= min(abs(even[i]), abs(odd[i]));
}
}
cout << ans << endl;
return 0;
} |
#include<stdio.h>
int main()
{
double Sx,Sy,Gx,Gy;
scanf("%lf%lf%lf%lf",&Sx,&Sy,&Gx,&Gy);
double ans;
ans=Gx+Gy*(Sx-Gx)/(Gy+Sy);
printf("%.10lf\n",ans);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define inf 1000000005 /*10^9+5*/
#define mod 1000000007 /*10^9+7*/
#define eps 1e-10
#define rep(i,n) for(int i = 0; i < (n); ++i) /*0からn-1までのrepeat*/
#define rrep(i,n) for(int i = 1; i <= (n); ++i) /*1からnまでのrepeat*/
#define drep(i,n) for(int i = (n)-1; i >= 0; --i) /*n-1から0までのrepeat*/
#define srep(i,s,t) for (int i = s; i < t; ++i) /*sからt-1までのrepeat*/
#define isin(x,l,r) ((l) <= (x) && (x) < (r)) /*l以上r未満のx*/
#define each(a,b) for(auto& (a): (b)) /*よくわかんない☆*/
#define pct __builtin_popcountll /*1bitの数*/
#define all(a) a.begin(),a.end() /*ぜーんぶ*/
#define sz(v) (int)(v).size() /*大きさ*/
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end()) /*重複削除*/
#define cmx(x,y) x=max(x,y) /*最大*/
#define cmn(x,y) x=min(x,y) /*最小*/
#define rev(v) reverse((v).begin(),(v).end()); /*逆順*/
#define so(v) sort((v).begin(), (v).end()); /*ソート*/
#define yn {puts("Yes");}else{puts("No");} /*はいかいいえか*/
#define YN {puts("YES");}else{puts("NO");} /*大文字-はいかいいえか*/
#define dame { puts("-1"); return 0;}/*だめ*/
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define vipls vector<int> pls; /*@_vipls*/
using ll = long long;
using unit = unsigned;
using ull = unsigned long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vd = vector<double>;
using vp = vector<P>;
using vt = vector<T>;
using vs = vector<string>;
using vc = vector<char>;
int main() {
double a, b, c, d;
cin >> a >> b >> c >> d;
cout <<setprecision(15)<<c-((d*(c-a))/(d+b)) <<endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
constexpr ll MOD=998244353;
constexpr ll INF=1e18;
int main(){
ll n, k; cin >> n >> k;
VI a(n), b(n), c(n);
REP(i,n) cin >> a[i] >> b[i] >> c[i], b[i]++;
set<int> t;
REP(i,n){
t.insert(a[i]);
t.insert(b[i]);
}
map<int,int> mp;
int tm=0;
VI tt;
for(auto x:t) tt.push_back(x);
REP(i,tt.size()){
mp[tt[i]]=tm;
tm++;
}
VI im(tt.size(),0);
REP(i,n){
im[mp[a[i]]]+=c[i];
im[mp[b[i]]]-=c[i];
}
ll ans=0, now=0;
REP(i,tt.size()-1){
now+=im[i];
if(k<now)
ans+=(tt[i+1]-tt[i])*k;
else
ans+=(tt[i+1]-tt[i])*now;
}
cout << ans << endl;
return 0;
} | #include"bits/stdc++.h"
using namespace std;
#define int long long
#define pb push_back
#define all(v) begin(v), end(v)
#define sz(v) (int)v.size()
#define ff first
#define ss second
const int inf = 4e18;
const int N = 2e5 + 10;
int n, m;
int dp[1 << 20];
vector<pair<int, int>> q[20];
int rec(int pos, int mask) {
int &ans = dp[mask];
if (pos == n) return 1;
if (ans != -1) return ans;
ans = 0;
for (int i = 0; i < n; i++) {
if (!(mask & (1 << i))) {
int nMask = mask | (1 << i);
bool can = 1;
for (auto &p : q[pos]) {
int got = ((1 << p.ff) - 1) & nMask;
can &= (__builtin_popcountll(got) <= p.ss);
}
if (can) ans += rec(pos + 1, nMask);
}
}
return ans;
}
void testCase() {
cin >> n >> m;
for (int i = 0; i < m; i++) {
int x, y, z; cin >> x >> y >> z; x--;
q[x].pb({y, z});
}
memset(dp, -1, sizeof(dp));
cout << rec(0, 0);
}
int32_t main() {
ios::sync_with_stdio(0); cin.tie(0);
int t_c = 1;
// cin >> t_c;
while (t_c--) testCase();
} |
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define endl "\n"
#define pb push_back
#define PI 3.1415926535897932384626433832795l
#define F first
#define S second
#define mp make_pair
#define f(i,n) for(int i=0;i<n;++i)
#define loop(i,a,b) for (int i=a ; i<b ;++i)
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define gcd(a,b) __gcd((a),(b))
#define fill(a,value) memset(a,value,sizeof(a));
#define minn(v) *min_element(v.begin(), v.end());
#define maxx(v) *max_element(v.begin(), v.end());
#define print(x) cout<<(x)<<endl;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int mod = 1e9 + 7;
const int MOD = 998244353;
int power(int x, int y, int p)
{
int res = 1;
x = x % p;
while (y > 0) {
if (y & 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
int modInverse(int n, int p)
{
return power(n, p - 2, p);
}
// Returns nCr % p using Fermat's little
// theorem.
int nCr(int n, int r, int p)
{
// Base case
if (r == 0)
return 1;
int fac[n + 1];
fac[0] = 1;
for (int i = 1; i <= n; i++)
fac[i] = (fac[i - 1] * i) % p;
return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p;
}
void solve()
{
string s;
cin >> s;
int ans = 0;
for (int i = 0; i < 9;)
{
if (s[i] == 'Z' and s[i + 1] == 'O' and s[i + 2] == 'N' and s[i + 3] == 'e')
{
ans++;
i += 3;
}
else
{
i++;
}
}
print(ans)
}
signed main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
fastio;
cout << fixed << setprecision(12);
int T = 1;
//cin >> T;
f(tc, T)
{
//cout << "Case #" << tc + 1 << ": ";
solve();
}
return 0;
} | #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define boostIO \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repn(i, n) for (int i = 1; i <= n; i++)
#define rrep(i, b, a) for (int i = b; i >= a; i--)
#define sz(v) (int)(v.size())
#define all(v) v.begin(), v.end()
#define mem0(a) memset(a, 0, sizeof(a))
#define mem1(a) memset(a, -1, sizeof(a))
#define trav(a, x) for (auto &a : x)
#define popcount(x) __builtin_popcountll(x)
#define pb push_back
#define fi first
#define se second
#define mod 1000000007
#define int long long
typedef pair<int, int> pii;
const long long INF = 1e18;
const int N = 1e5 + 5;
signed main() {
boostIO;
char c1, c2, c3;
cin >> c1 >> c2 >> c3;
if (c1 == c2 && c2 == c3) {
cout << "Won\n";
} else {
cout << "Lost\n";
}
return 0;
}
// XD |
#include<bits/stdc++.h>
using namespace std;
#define li long long int
#define rep(i,to) for(li i=0;i<((li)(to));i++)
#define repp(i,start,to) for(li i=(li)(start);i<((li)(to));i++)
#define bit(n) (1ll<<(li)(n))
#define INF bit(60)
#define MOD 998244353
int main() {
li a,b;
cin>>a>>b;
cout<<(a-b)*100.0/a<<endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define REP(i, n) for (int i=1; i<=(int)(n); i++)
#define FOR(i, n, m) for (int i=(n); i<=(int)(m); i++)
#define ll long long
const ll INF=1LL<<60;
const double pi=3.1415926535;
int main() {
vector<vector<int>> dp(900, vector<int>(900));
vector<int> vec_output;
rep(i, 1000) {
//入力
vector<int> input(4);
rep(j, 4) cin >> input.at(j);
//通った道
vector<int> usei(0), usej(0);
usei.push_back(input.at(0));
usej.push_back(input.at(1));
int x = input.at(1);
int y = input.at(0);
int xplus = 0;
int yplus = 0;
if (x < input.at(3)) xplus = 1;
if (x > input.at(3)) xplus = -1;
if (y < input.at(2)) yplus = 1;
if (y > input.at(2)) yplus = -1;
bool X = false;
//経路探索
while (x != input.at(3)) {
//xの残りをうめる
if (y == input.at(2)) {
while (x != input.at(3)) {
x += xplus;
usei.push_back(y);
usej.push_back(x);
cout << (xplus == 1 ? "R" : "L") << flush;
}
break;
}
//探索済みか近いかを調べる
if (dp.at(y*30 + x).at(y*30 + x+xplus) == 0 && dp.at(y*30 + x).at((y+yplus)*30 + x) == 0) {
X = !X;
} else if (dp.at(y*30 + x).at(y*30 + x+xplus) == 0) {
X = true;
} else if (dp.at(y*30 + x).at((y+yplus)*30 + x) == 0) {
X = false;
} else if (dp.at(y*30 + x).at(y*30 + x+xplus) < dp.at(y*30 + x).at((y+yplus)*30 + x)) {
X = true;
} else if (dp.at(y*30 + x).at(y*30 + x+xplus) > dp.at(y*30 + x).at((y+yplus)*30 + x)) {
X = false;
} else {
X = !X;
}
if (X) {
x += xplus;
usei.push_back(y);
usej.push_back(x);
cout << (xplus == 1 ? "R" : "L") << flush;
} else {
y += yplus;
usei.push_back(y);
usej.push_back(x);
cout << (yplus == 1 ? "D" : "U") << flush;
}
}
//yの残りをうめる
while (y != input.at(2)) {
y += yplus;
usei.push_back(y);
usej.push_back(x);
cout << (yplus == 1 ? "D" : "U") << flush;
}
cout << endl;
//入力
ll output;
cin >> output;
//点数の平均を計算
vec_output.push_back(output);
ll sum = 0;
for (ll a : vec_output) {
sum += a;
}
ll ave = sum / vec_output.size();
output -= ave;
output *= 60;
int size = usei.size();
rep(j, usei.size()-1) {
int a = usei.at(j);
int b = usej.at(j);
int c = usei.at(j+1);
int d = usej.at(j+1);
//cout << a*30+b << " " << c*30+d << endl;
dp.at(a*30+b).at(c*30+d) += output / size;
dp.at(c*30+d).at(a*30+b) += output / size;
}
/*rep(j, 29) {
rep(k, 29) {
cout << " " << dp.at(j*30+k).at(j*30+k+1);
}
cout << endl;
rep(k, 30) {
cout << dp.at(j*30+k).at((j+1)*30+k) << " ";
}
cout << endl;
}*/
}
} |
#include<bits/stdc++.h>
#define rep(i,a,b) for (register int i=(a);i<=(b);++i)
#define req(i,a,b) for (register int i=(a);i>=(b);--i)
using namespace std;
int a,b;
int main()
{
cin>>a>>b;
cout<<(a+b>>1)<<' '<<(a-b>>1)<<endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int a,b;
cin>>a>>b;
ll x=(a+b)/2,y=(a-b)/2;
cout<<x<<" "<<y;
} |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a)
#define dumparr(a,n)
#endif
#define FOR(i, a, b) for(ll i = (ll)a;i < (ll)b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = (ll)b-1LL;i >= (ll)a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))
typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;
typedef long double ld;
typedef pair<ld,ld> pdd;
pll operator+(pll a,pll b){
return pll(a.first+b.first,a.second+b.second);
}
pll operator-(pll a,pll b){
return pll(a.first-b.first,a.second-b.second);
}
pll operator*(ll a,pll b){
return pll(b.first*a,b.second*a);
}
const ll INF=(1LL<<60);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
a=abs(a);
b=abs(b);
if(a==0)return b;
if(b==0)return a;
if(a < b) return gcd(b, a);
ll r;
while ((r=a%b)) {
a = b;
b = r;
}
return b;
}
#endif
template<class T>
bool chmax(T& a,const T& b){
if(a<b){
a=b;
return true;
}
return false;
}
template<class T>
bool chmin(T& a,const T& b){
if(a>b){
a=b;
return true;
}
return false;
}
template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
os << "(" << a.first << "," << a.second << ")";
return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
os << "[ ";
REP(a.size()){
os<< a[i] << " ";
}
os<< " ]";
return os;
}
const long long MOD = 998244353;
void solve(long long A, long long B, long long C){
auto f = [](ll x){return x*(x+1)/2%MOD;};
cout<< f(C)*f(A)%MOD*f(B)%MOD<<endl;
}
int main(){
cout<<setprecision(1000);
long long A;
scanf("%lld",&A);
long long B;
scanf("%lld",&B);
long long C;
scanf("%lld",&C);
solve(A, B, C);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define INF 1e8
typedef long long int ll;
const double PI = acos(-1);
int gcd(int a, int b) {
if (a % b == 0)
return b;
else
return gcd(b, a % b);
}
int lcm(int a, int b) { return abs(a) / gcd(a, b) * abs(b); }
int main() {
ll a, b, c;
cin >> a >> b >> c;
ll sa = (a * (a + 1) / 2) % 998244353;
ll sb = (b * (b + 1) / 2) % 998244353;
ll sc = (c * (c + 1) / 2) % 998244353;
ll ans = (((sa * sb) % 998244353) * sc) % 998244353;
cout << ans << endl;
}
|
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using PP = std::pair<ll,P>;
#define REP(i,b,e) for(int i=b; i<e; i++)
#define PRINT(vec) {printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");}
#define fi first
#define se second
const int MOD = 1e9+7;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
int main(){
std::string s;
std::cin >> s;
std::deque<char> deq;
bool flip = false;
for(char c: s){
if(c=='R') flip = !flip;
else{
if(flip){
if(deq.size() && deq.front()==c) deq.pop_front();
else deq.push_front(c);
}else{
if(deq.size() && deq.back()==c) deq.pop_back();
else deq.push_back(c);
}
}
}
if(flip){
REP(i, 0, deq.size()) printf("%c", deq[deq.size()-1-i]); puts("");
}else{
REP(i, 0, deq.size()) printf("%c", deq[i]); puts("");
}
return 0;
}
| #define MOD_TYPE 1
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
#if 0
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
using Int = boost::multiprecision::cpp_int;
using lld = boost::multiprecision::cpp_dec_float_100;
#endif
#if 1
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#endif
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;
constexpr ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
constexpr int INF = (int)1e9 + 10;
constexpr ll LINF = (ll)4e18;
constexpr ld PI = acos(-1.0);
constexpr ld EPS = 1e-7;
constexpr int Dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
constexpr int Dy[] = {1, -1, 0, 0, -1, -1, 1, 1, 0};
#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define REPI(i, m, n) for (int i = m; i < (int)(n); ++i)
#define repi(i, n) REPI(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";
struct io_init
{
io_init()
{
cin.tie(0);
ios::sync_with_stdio(false);
cout << setprecision(30) << setiosflags(ios::fixed);
};
} io_init;
template <typename T>
inline bool chmin(T &a, T b)
{
if (a > b)
{
a = b;
return true;
}
return false;
}
template <typename T>
inline bool chmax(T &a, T b)
{
if (a < b)
{
a = b;
return true;
}
return false;
}
inline ll CEIL(ll a, ll b)
{
return (a + b - 1) / b;
}
template <typename A, size_t N, typename T>
inline void Fill(A (&array)[N], const T &val)
{
fill((T *)array, (T *)(array + N), val);
}
template <typename T, typename U>
constexpr istream &operator>>(istream &is, pair<T, U> &p) noexcept
{
is >> p.first >> p.second;
return is;
}
template <typename T, typename U>
constexpr ostream &operator<<(ostream &os, pair<T, U> &p) noexcept
{
os << p.first << " " << p.second;
return os;
}
#pragma endregion
// --------------------------------------
void solve()
{
ll n;
cin >> n;
vector<ll> a(n);
rep(i, n) cin >> a[i];
ll Max = -1;
ll sum = 0, wsum = 0;
rep(i, n)
{
chmax(Max, a[i]);
sum += a[i];
wsum += sum;
ll ans = wsum + (i + 1) * Max;
cout << ans << "\n";
}
}
int main()
{
solve();
}
|
#include <bits/stdc++.h>
//#include <chrono>
//#pragma GCC optimize("Ofast")
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
ll N,M,H,W,Q,K,A,B;
string S;
using P = pair<ll, ll>;
const ll INF = (1LL<<60);
template<class T> bool chmin(T &a, const T b){
if(a > b) {a = b; return true;}
else return false;
}
template<class T> bool chmax(T &a, const T b){
if(a < b) {a = b; return true;}
else return false;
}
template<class T> void my_printv(std::vector<T> v,bool endline = true){
if(!v.empty()){
for(std::size_t i{}; i<v.size()-1; ++i) std::cout<<v[i]<<" ";
std::cout<<v.back();
}
if(endline) std::cout<<std::endl;
}
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
cin>>S;
N = S.size();
vec num(26, 0);
++num[S.back() - 'a'];
ll res = 0;
Rreps(i, N - 1, 1){
if(S[i-1] == S[i]){
res += N - 1 - i - num[S[i] - 'a'];
rep(j, 26) num[j] = 0;
num[S[i] - 'a'] = N - i;
}else{
++num[S[i] - 'a'];
}
}
cout<<res<<endl;
} |
/**
* Dont raise your voice, improve your argument.
* --Desmond Tutu
*/
#include <bits/stdc++.h>
using namespace std;
const bool ready = [](){
ios_base::sync_with_stdio(false); cin.tie(0);
cout << fixed << setprecision(12);
return true;
}();
using ld=long double;
const ld PI = acos((ld)-1);
using ll= long long;
#define int ll
#define all(v) (v).begin(), (v).end()
#define fori(n) for(int i=0; i<int(n); i++)
#define cini(i) int i; cin>>i;
#define cins(s) string s; cin>>s;
#define cind(d) ld d; cin>>d;
#define cinai(a,n) vi a(n); fori(n) { cin>>a[i]; }
#define cinas(s,n) vs s(n); fori(n) { cin>>s[i]; }
#define cinad(a,n) vd a(n); fori(n) { cin>>a[i]; }
using pii= pair<int, int>;
using pdd= pair<ld, ld>;
using vd= vector<ld>;
using vb= vector<bool>;
using vi= vector<int>;
using vvi= vector<vi>;
using vs= vector<string>;
#define endl "\n"
/* from first pair of chars we can change the whole
* string, but only that positions with are not
* allready that char.
*
* Then note that we can do that for the rightmost char-pair,
* then for the second rightmost...etc.
*
* Note also that we apply operatios from right to
* left, so after applying the operation until the
* end of the string, the whole string is same char up to the end.
*/
void solve() {
cins(s);
vvi cnt(26, vi(s.size()+1));
const int n=s.size();
for(size_t i=0; i<s.size(); i++) {
for(int j=0; j<26; j++)
cnt[j][i+1]=cnt[j][i];
cnt[s[i]-'a'][i+1]++;
}
char prev=' ';
stack<pair<int,char>> pos;
for(int i=1; i+1<s.size(); i++) {
if(s[i]==s[i-1] && s[i]!=prev) {
pos.push({i+1,s[i]-'a'});
prev=s[i];
}
}
int ans=0;
int pp=s.size();
while(pos.size()) {
/* each pair contributes nuber of chars until end of string
* minus number of same char up to next double char position.
*/
auto [p,c]=pos.top();
pos.pop();
ans+=n-p-( cnt[c][pp]-cnt[c][p]);
pp=p;
}
cout<<ans<<endl;
}
signed main() {
solve();
} |
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#include <complex>
#define rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define reps(x, s) for(llint (x) = 0; (x) < (llint)(s).size(); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define sz(x) ((ll)(x).size())
#define ceil(x, y) (((x)+(y)-1) / (y))
#define all(x) (x).begin(),(x).end()
#define outl(...) dump_func(__VA_ARGS__)
#define inf 1e18
using namespace std;
typedef long long llint;
typedef long long ll;
typedef pair<ll, ll> P;
bool exceed(ll x, ll y, ll m){return x >= m / y + 1;}
struct edge{
ll to, cost;
edge(){}
edge(ll a, ll b){
to = a, cost = b;
}
};
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec) {
for(int i = 0; i<vec.size(); i++) {
os << vec[i] << (i + 1 == vec.size() ? "" : " ");
}
return os;
}
template<typename T, typename U>
ostream& operator << (ostream& os, pair<T, U>& pair_var) {
os << "(" << pair_var.first << ", " << pair_var.second << ")";
return os;
}
template<typename T, typename U>
ostream& operator << (ostream& os, map<T, U>& map_var) {
for(typename map<T, U>::iterator itr = map_var.begin(); itr != map_var.end(); itr++) {
os << "(" << itr->first << ", " << itr->second << ")";
itr++;
if(itr != map_var.end()) os << ",";
itr--;
}
return os;
}
template<typename T>
ostream& operator << (ostream& os, set<T>& set_var) {
for(typename set<T>::iterator itr = set_var.begin(); itr != set_var.end(); itr++) {
os << *itr;
++itr;
if(itr != set_var.end()) os << " ";
itr--;
}
return os;
}
void dump_func() {cout << endl;}
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail) {
cout << head;
if(sizeof...(Tail) > 0) cout << " ";
dump_func(std::move(tail)...);
}
ll n;
string s, x;
ll dp[200005][7];
int main(void)
{
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> s >> x;
s = "#" + s, x = "#" + x;
dp[n][0] = 1;
rep(i, 1, 6) dp[n][i] = -1;
for(int i = n-1; i >= 0; i--){
rep(j, 0, 6){
if(x[i+1] == 'T') dp[i][j] = max(dp[i+1][j*10%7], dp[i+1][(j*10+s[i+1]-'0')%7]);
if(x[i+1] == 'A') dp[i][j] = min(dp[i+1][j*10%7], dp[i+1][(j*10+s[i+1]-'0')%7]);
}
}
if(dp[0][0] > 0) outl("Takahashi");
if(dp[0][0] < 0) outl("Aoki");
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int N;
string digit, turn;
int dp[100001][7];
bool calc(int index, int rem) {
if (index == N) {
return rem == 0;
}
int &retVal = dp[index][rem];
if (retVal != -1)
return retVal;
if (turn[index]) {
retVal = calc(index + 1, (10 * rem) % 7);
retVal |= calc(index + 1, (10 * rem + digit[index]) % 7);
}
else {
retVal = calc(index + 1, (10 * rem) % 7);
retVal &= calc(index + 1, (10 * rem + digit[index]) % 7);
}
return retVal;
}
int main() {
memset(dp, -1, sizeof(dp));
cin >> N;
cin >> digit >> turn;
for (int x = 0; x < N; x++)
{
digit[x] -= '0';
turn[x] = turn[x] == 'T';
}
cout << (calc(0, 0) ? "Takahashi" : "Aoki");
} |
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int,int>;
void debug(map<int,pii> a) {
for (auto p : a) {
cout << p.first << ": " << "(" << p.second.first << "," << p.second.second << ")\n";
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N,L;
cin >> N >> L;
auto read = [](int N, int L) {
vector<int> v{0};
for (int i = 1; i <= N+1; i++) {
int ai = L+1;
if (i <= N)
cin >> ai;
v.push_back(ai-i);
}
map<int,pii> interval;
for (int i = 0; i < v.size(); i++) {
if (i==0 || v[i] != v[i-1])
interval[v[i]].first = i;
interval[v[i]].second = i;
}
return interval;
};
auto A = read(N,L);
auto B = read(N,L);
ll ans = 0;
for (auto p : B) {
int val = p.first;
if (!A.count(val)) {
cout << -1 << '\n';
return 0;
}
ans += max(A[val].first-B[val].first,0) + max(B[val].second-A[val].second,0);
}
cout << ans << '\n';
}
| #include <bits/stdc++.h>
typedef long long int64;
typedef unsigned int uint;
typedef unsigned long long uint64;
const int N = 1e5;
int n, L, a[N + 5], b[N + 5];
int main() {
scanf("%d%d", &n, &L);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
for (int i = 1; i <= n; i++) {
scanf("%d", &b[i]);
}
a[n + 1] = b[n + 1] = L + 1;
for (int i = n + 1; i >= 1; i--) {
a[i] -= a[i - 1] + 1;
b[i] -= b[i - 1] + 1;
}
int64 ans = 0;
for (int j = 1, i = 1; i <= n + 1; i++) {
if (b[i] > 0) {
for (; a[j] == 0; j++);
ans += std::max(0, i - j);
int sum = 0;
for (; j <= n + 1 && sum < b[i]; sum += a[j++]);
if (sum != b[i]) {
printf("-1\n");
return 0;
}
ans += std::max(0, j - 1 - i);
}
}
printf("%lld\n", ans);
return 0;
} |
#include<bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i, 0, n)
#define all(x) (x).begin(),(x).end()
const int INF = 1e9+1;
using namespace std;
using ll = long long;
using p = pair<int, int>;
int main() {
string S;
string Z = "ZONe";
cin >> S;
int i = 0;
int j = 0;
int ans = 0;
while (true) {
while (S[i+j] == Z[j]) {
j++;
if (j >= 4) {
j--;
ans++;
break;
}
}
i += max(1, j-1);
if (i >= 11) break;
j = 0;
}
cout << ans << endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
int main()
{
string s;
cin>>s;
int count=0;
for(int i=0;i<12;i++)
{
if(s[i] == 'Z' && s[i+1] == 'O' && s[i+2] == 'N' && s[i+3]=='e')
{count++;}
}
cout<<count<<endl;
return 0;
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.