code_file1
stringlengths 87
4k
| code_file2
stringlengths 82
4k
|
---|---|
///////////////////////Loading Payloads.......////////////////////////////
#include<bits/stdc++.h>
#define f(i,a,b) for(int i = a; i < b; i++)
#define fd(i,a,b) for(int i = a; i > b;i--)
#define fld(i,a,b) for(ll i = a ; i > b;i--)
#define ll long long
#define fl(i,a,b) for(ll i = a; i < b; i++)
#define VI vector<int>
#define VP vector<pair<int,int>>
#define VPL vector<pair<ll,ll>>
#define VS vector<string>
#define VL vector<long long>
#define VC vector<char>
#define VF vector<float>
#define VD vector<double>
#define VB vector<bool>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define fa(i,skill) for(auto i : skill)
#define fr(i,skill) for(VI :: reverse_iterator i = skill.rbegin(); i != skill.rend(); i++)
#define PI pair<int,int>
#define mi map<int,int>
#define ml map<ll,ll>
#define mci map<char,int>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define MAX 1000000007
#define INF 1000000000
#define debug(x) cout<<"This side ----> "<<#x<<" -> "<<x<<endl
using namespace std;
///////////////////////Engine Check.......////////////////////////////
void edit(VI &skill,int n)
{
f(i,0,n)
{
int x;
cin >> x;
skill.PB(x);
}
}
bool cmp(pair<ll,ll>p1,pair<ll,ll>p2)
{
if(p1.S > p2.S)
return true;
if(p1.S < p2.S)
return false;
if(p1.F > p2.F)
return true;
else
return false;
}
void editl(VL &skill,ll n)
{
fl(i,0,n)
{
ll x;
cin >> x;
skill.PB(x);
}
}
void editpl(VPL &skill,ll n)
{
fl(i,0,n)
{
ll x,y;
cin >> x >> y;
skill.PB({x,y});
}
}
bool isGoogles = 0;
bool testcase = 0;
void achilles()
{
VL arr;editl(arr,3);
sort(all(arr));
if(arr[1]-arr[0] == arr[2]-arr[1])
cout << "Yes\n";
else
cout << "No\n";
}
///////////////////////3....2....1...Ignition////////////////////////////
int main()
{
ios :: sync_with_stdio(0);
cin.tie(0);
//freopen("out.txt","r",stdin);
ll t=1,w=1;
if(testcase)
cin >>t;
// precalc();
while(t--)
{ if (isGoogles) {cout << "Case #" << w << ": ";}
achilles();
w++;
}
return 0;
} | #include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp> // Common file
#include<ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define F first
#define S second
#define ld long double
#define rep(i,a,n) for (int i = (a) ; i < (n); ++i)
#define vi vector<ll>
#define all(v) (v).begin(),(v).end()
#define M_PI 3.14159265358979323846
#define int ll
typedef tree <
pair<int, int>,
null_type,
less<pair<int, int>>,
rb_tree_tag,
tree_order_statistics_node_update > od_st; // find_by_order() and order_of_key()
const ll mod = 1e9 + 7;
const ll inf = 1e18;
void solve() {
vector<int> a(3);
for ( auto &k : a)cin >> k;
sort(all(a));
if ( 2 * a[1] == a[0] + a[2]) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
int32_t main() {
FASTIO
int t = 1;
// create();
// cin >> t;
ll k = 1;
while (t--) {
// cout << "Case #" << k++ << ": ";
solve();
}
return 0;
}
|
// -----------------------------------
// author : MatsuTaku
// country : Japan
// created : 11/22/20 20:12:05
// -----------------------------------
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr int INF = 2e9;
int main() {
cin.tie(nullptr); ios::sync_with_stdio(false);
int a,b,c,d; cin>>a>>b>>c>>d;
auto dist = [](int a, int b, int c, int d) {
if (((a+b)%2) != ((c+d)%2))
return INF;
if (a==c and b==d)
return 0;
if (abs(a-c) == abs(b-d))
return 1;
return 2;
};
int ans = INF;
for (int i = a-3; i <= a+3; i++) {
for (int j = b-3; j <= b+3; j++) {
if (abs(i-a)+abs(j-b) > 3)
continue;
int s = (i==a and j==b) ? 0 : 1;
for (int k = c-3; k <= c+3; k++) {
for (int l = d-3; l <= d+3; l++) {
if (abs(k-c) + abs(d-l) > 3)
continue;
int g = (k == c and l == d ? 0 : 1);
int aux = dist(i,j,k,l);
if (aux == INF)
continue;
ans = min(ans, s+g+aux);
}
}
}
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ll r1, r2, c1, c2;
cin >> r1 >> c1 >> r2 >> c2;
ll r = r2-r1, c = c2-c1;
if (r == 0 && c == 0) cout << 0 << endl;
else if (r == c || r == -c || abs(r) + abs(c) <= 3) cout << 1 << endl;
else if ((r+c)%2 == 0 || abs(r+c) <= 3 || abs(r-c) <= 3 || abs(r) + abs(c) <= 6) cout << 2 << endl;
else cout << 3 << endl;
}
|
#include <bits/stdc++.h>
#define rep0(i,r) for (int i=0,i##end=r;i<i##end;++i)
#define rep(i,l,r) for (int i=l;i<=r;++i)
#define per(i,r,l) for (int i=r;i>=l;--i)
#define pr pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pb push_back
using namespace std;
const int N=2e5+5;
int e[N][2],c[N],tag[N],dfn[N],dc; vector<pr> G[N];
void dfs(int u,int f){
dfn[u]=++dc;
rep0(i,G[u].size()){
int v=G[u][i].fi,t=G[u][i].se;
if (t){
if (!dfn[v]) tag[t]=1;
else if (dfn[v]<dfn[u]&&v!=f) tag[t]=1;
}
if (!dfn[v]) dfs(v,u);
}
}
int main(){
int n,m; scanf("%d%d",&n,&m);
rep(i,1,m) scanf("%d%d",&e[i][0],&e[i][1]);
rep(i,1,n) scanf("%d",&c[i]);
rep(i,1,m){
int u=e[i][0],v=e[i][1];
if (c[u]==c[v]) G[u].pb(mp(v,i)),G[v].pb(mp(u,0));
}
rep(i,1,n) if (!dfn[i]) dfs(i,0);
rep(i,1,m){
int u=e[i][0],v=e[i][1];
if (c[u]==c[v]) puts(tag[i]?"->":"<-");
else if (c[u]<c[v]) puts("<-");
else puts("->");
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define repi(i, a, n) for (int i = a; i < (int)(n); ++i)
#define rep(i, n) repi(i, 0, n)
#define all(v) begin(v), end(v)
using ll = long long;
int main() {
// freopen("1.txt", "rb", stdin);
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int V, T, S, D;
cin >> V >> T >> S >> D;
if (D < V * T || D > V * S) {
cout << "Yes" << '\n';
} else {
cout << "No" << '\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=3005;
inline ll bigmod(ll B,ll P){ll R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}
inline ll ad(ll x,ll y){ll ret=(x%mod+y%mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline ll sub(ll x,ll y){ll ret=((x%mod)-(y%mod)+mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline ll gun(ll x,ll y){ll ret=((x%mod)*(y%mod))%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
int n;
int a[M],pre[M];
int dp[M][M];
int sum[M],nxt[M];
main()
{
fast
cin>>n;
f(i,1,n)cin>>a[i],pre[i]=a[i]+pre[i-1];
rf(k,n,1)
{
f(pos,1,n)
{
int val=pre[pos-1]%k;
sum[val]=sub(sum[val],dp[pos][k+1]);
dp[pos][k]=sum[val];
int z=pre[n]-pre[pos-1];
z=z%k;
if(z==0)dp[pos][k]=(dp[pos][k]+1)%mod;
if(k!=1){
val=pre[pos-1]%(k-1);
nxt[val]=ad(nxt[val],dp[pos][k]);
}
}
f(j,0,k+1)
{
sum[j]=nxt[j];
nxt[j]=0;
}
}
cout<<dp[1][1]<<"\n";
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
struct MB{
int x;
MB(int _x=0):x(_x){}
void operator +=(const MB& o){ *this = *this + o; }
void operator -=(const MB& o){ *this = *this - o; }
void operator *=(const MB& o){ *this = *this * o; }
MB& operator ++(){ return *this = *this + MB(1); }
MB operator ++(int){ MB r=*this; ++(*this); return r; }
MB operator +(const MB& o){ return x+o.x >=mod ? x+o.x-mod : x+o.x; }
MB operator -(const MB& o){ return x-o.x < 0 ? x-o.x+mod : x-o.x; }
MB operator *(const MB& o){ return int(1ll*x*o.x%mod); }
operator int(){return x;}
friend ostream& operator<< (ostream& os, MB& o) { return os << o.x; }
friend istream& operator>> (istream& is, MB& o) { return is >> o.x; }
};
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
using ll = long long;
int n;cin>>n;
vector<ll>a(n),p(n+1);
for(int i=0;i<n;++i)cin>>a[i];
for(int i=0;i<n;++i)p[i+1] = a[i] + p[i];
vector<vector<MB>>dp(2,vector<MB>(n+1));
//dp[i][j] - #formas de fazer i grupos em [0..j)
dp[0][0] = 1;
MB ans = 0;
for(int i=1,o=1;i<=n;++i,o^=1){
vector<MB>s(n);
for(int j=0;j<=n;++j){
//dp[i][j] = somatorio de dp[i-1][x], soma( [x,j) ) == 0 mod i x < j
//dp[i][j] = somatorio de dp[i-1][x], p[j] == p[x] mod i x < j
dp[o][j] = s[ p[j] % i ];
s[p[j] % i] += dp[o^1][j];
}
ans += dp[o][n];
}
cout<<ans<<'\n';
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using P = pair<int,int>;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<vector<int>> g(n);
vector<int> root(n,-1);
root[0] = 0;
for (int i=0;i<n-1;i++) {
int p;
cin >> p;
p--;
g[i+1].emplace_back(p);
g[p].emplace_back(i+1);
root[i+1] = p;
}
stack<int> st;
queue<int> q;
q.push(0);
while (!q.empty()) {
int now = q.front();
q.pop();
st.push(now);
for (int i=0;i<g[now].size();i++) {
int to = g[now][i];
if (to != root[now]) {
q.push(to);
}
}
}
vector<int> subt(n,1);
vector<int> suba(n,0);
vector<int> turn(n,1);
while (!st.empty()) {
int now = st.top();
st.pop();
vector<P> ps;
int rett = 0;
int reta = 0;
int kt = 0;
for (int i=0;i<g[now].size();i++) {
int to = g[now][i];
if (to == root[now]) continue;
if (turn[to] == 1) {
ps.emplace_back(P(subt[to]-suba[to],to));
kt++;
}
else {
if (subt[to] < suba[to]) {
subt[now] += subt[to];
suba[now] += suba[to];
}
else {
rett += subt[to];
reta += suba[to];
}
}
}
sort(ps.begin(),ps.end());
for (int j=0;j<ps.size();j++) {
P pst = ps[j];
int ind = pst.second;
if (j%2 == 0) {
subt[now] += subt[ind];
suba[now] += suba[ind];
}
else {
subt[now] += suba[ind];
suba[now] += subt[ind];
}
}
if (kt%2 == 0) {
subt[now] += rett;
suba[now] += reta;
}
else {
subt[now] += reta;
suba[now] += rett;
}
turn[now] = (kt+1)%2;
}
cout << subt[0] << endl;
} | #include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define MP make_pair
#define N 200005
typedef long long LL;
int n, p[N];
int f[N], sz[N];
vector<int> E[N];
void dfs(int x)
{
++sz[x];
vector<int> v, v2;
for (auto &y: E[x])
{
dfs(y);
if (sz[y]&1) v.push_back(f[y]);
else v2.push_back(f[y]);
sz[x] += sz[y];
}
sort(v2.begin(), v2.end());
f[x]++;
int ss = 0;
for (auto val: v2)
{
if (val < 0) f[x] += val;
else ss+=val;
}
sort(v.begin(), v.end());
v.push_back(ss);
int o = 1;
for (auto val: v)
f[x] += o*val, o*=-1;
//cout << x << " " << f[x] << endl;
}
int main()
{
scanf("%d", &n);
for (int i = 2; i <= n; ++i)
scanf("%d", &p[i]), E[p[i]].push_back(i);
dfs(1);
cout << (n+f[1])/2<<endl;
return 0;
} |
//***********************************************************//
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define forr(i,a,n) for(ll i=a;i<n;i++)
#define forrr(i,a,n) for(ll i=a;i<=n;i++)
#define bp(n) __builtin_popcount(n) // prints one's in binary representation
#define w(t) int t;cin>>t;while(t--)
#define lc "\n"
#define men(a) (*min_element(a.begin(), a.end()))
#define mex(a) (*max_element(a.begin(), a.end()))
#define deb(x) cout << #x << " " << x << endl ;
#define all(x) x.begin(), x.end()
#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())
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
const ll MOD =1e9+7;
const ll INF = 1e18;
const int N = 100001;
//*********************************************************//
void solve()
{
ll n ;
cin >> n ;
vector<ll>v(n) ;
multiset < int > s ;
forr(i,0,n){
cin >> v[i] ;
s.insert( v[i] ) ;
}
ll ans = 1 ;
int c = 0 ;
ll prev = 0 ;
for(auto i : s ){
if(c == 0 ){
ll y = i - 0 + 1 ;
ans = (ans%MOD)*y ;
prev = i ;
c++;
}
else{
ans = ((ans)%MOD)*(i - prev + 1) ;
prev = i ;
}
}
cout << (ans)%MOD << endl ;
}
int main()
{
IOS;
//w(t)
{solve();}
// end_routine();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const int INF = 1e9;
const ll INF2 = 1e18;
const double PI = 3.141592653589793;
int main() {
const int div = 1e9 + 7;
int n;
ll ans = 1;
cin >> n;
vector<int> A(n, 0);
vector<int> B(n, 0);
for(int i = 0; i < n; i++){
cin >> A.at(i);
}
sort(A.begin(), A.end());
B.at(0) = A.at(0);
for(int i = 1; i < n; i++){
B[i] = A[i] - A[i-1];
}
for(int b: B){
ans *= b+1;
ans %= div;
}
cout << ans << endl;
} |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <chrono>
#define int long long
#define ld long double
#define db double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define debx cout << " X " << endl;
#define deby cout << " Y " << endl;
#define debz cout << " Z " << endl;
using namespace __gnu_pbds;
using namespace std;
using namespace chrono;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update> ;
/*
find_by_order() - Returns an iterator to the k-th largest element (counting from zero)
order_of_key() - The number of items in a set that are strictly smaller than our item
Rest same as set
*/
void deb_out() {
cout << endl;
}
template <typename Head, typename... Tail>
void deb_out(Head H, Tail... T) {
cout << " " << H;
deb_out(T...);
}
#ifdef LOCAL
#define deb(...) cout << "[" << #__VA_ARGS__ << "]:", deb_out(__VA_ARGS__);
#else
#define deb(...)
#endif
const long double PI = 3.14159265358979323846264338;
const long long INF = 1000000000000000000;
const long long INF1 = 1000000000;
const long long MOD = 1000000007;
// const long long MOD = 998244353;
int mpow(int a, int b){
a %= MOD;
if(!b)
return 1;
int temp = mpow(a, b / 2);
temp = (temp * temp) % MOD;
if(b % 2)
return (a * temp) % MOD;
return temp;
}
int _pow(int a, int b){
if(!b)
return 1;
int temp = _pow(a, b / 2);
temp = (temp * temp);
if(b % 2)
return (a * temp);
return temp;
}
inline int mod_in(int n){
return mpow(n, MOD - 2);
}
inline int cl(int a, int b){
if(a % b)
return 1 + a / b;
return a / b;
}
inline int rnd(int l = -INF, int r = INF){
int v = rng();
v = abs(v);
return l + v % (r - l + 1);
}
int32_t main(){
fastio;
int Tests = 1;
// cin >> Tests;
while (Tests--) {
int a, b;
cin >> a >> b;
cout << 2 * a + 100 - b << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
const int N = 200 + 1;
bool possible[N];
int id[N];
int a[N];
int b[N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
fill(id, id + 2 * n, -1);
for (int i = 0; i < n; ++i) {
cin >> a[i] >> b[i];
if (a[i] != -1) {
if (id[--a[i]] != -1) {
cout << "No\n";
exit(0);
}
id[a[i]] = i;
}
if (b[i] != -1) {
if (id[--b[i]] != -1) {
cout << "No\n";
exit(0);
}
id[b[i]] = i;
}
}
possible[2 * n] = true;
for (int i = 2 * n - 2; i >= 0; i -= 2) {
for (int j = 1; i + 2 * j <= 2 * n && !possible[i]; ++j) {
if (!possible[i + 2 * j]) {
continue;
}
bool ok = true;
for (int k = 0; k < j && ok; ++k) {
int l = i + k;
int r = i + k + j;
if (id[l] != -1 && a[id[l]] != l) {
ok = false;
}
if (id[r] != -1 && b[id[r]] != r) {
ok = false;
}
if (id[l] != id[r]) {
if (id[l] != -1 && id[r] != -1) {
ok = false;
} else if (id[l] == -1) {
ok &= (a[id[r]] == -1);
} else {
ok &= (b[id[l]] == -1);
}
}
}
possible[i] |= ok;
}
}
cout << (possible[0] ? "Yes" : "No") << "\n";
}
|
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iomanip>
#include <ios>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <utility>
using namespace std;
using i64 = int64_t;
using u64 = uint64_t;
using i32 = int32_t;
using pi64 = pair<i64, i64>;
#define vec vector
#define let const
#define DRi64(x) i64 x; cin >> x;
#define DRS(x) string x; cin >> x;
#define DRVi64(v, n) vec<i64> v(n); { for (i64 i = 0; i < n; ++i) { cin >> v[i]; }}
#define DRpi64(x) pi64 x; cin >> x.first >> x.second;
#ifdef DEBUG
#define P(x) cerr << x << "\n"
#else
#define P(x)
#endif
constexpr i64 MAXN = 3*100*1000LL+5LL;
constexpr i64 MOD = 1000000007LL;
constexpr i64 INF64 = MOD * MOD;
int
main()
{
ios_base::sync_with_stdio(false);
DRi64(N);
vec<double> dp(N + 1);
dp[1] = 0;
for (i64 i = 2; i <= N; ++i)
{
dp[i] = dp[i - 1] + N / double(N - i + 1);
}
cout << fixed << setprecision(12) << dp.back() << "\n";
return 0;
}
| #include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(int i=cc;i>=n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
using ll = long long;
const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const vector<int> dx2 = {1, 1, 1, 0, 0, 0, -1, -1, -1};
const vector<int> dy2 = {1, 0, -1, 1, -1, 0, 1, 0, -1};
const double PI = 3.1415926535;
const ll inf = 1001001001;
const ll e9 = 1000000000;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll MAX = 1000000;
const int MOD = 1000000007;
const ll big = (1ll<<60);
ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }
int main(){
int n;
cin >> n;
double ans = 0;
rep(i, 1, n){
ans += (double)(n)/(n-i);
}
cout << fixed << setprecision(10) << ans << endl;
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<ll, ll> Pair;
typedef vector<Pair> VP;
typedef vector<string> VS;
typedef vector<char> VC;
//typedef modint1000000007 mint;
//typedef modint998244353 mint;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n); i >= 0; i--)
#define RREP(i, n, e) for(int i = (int)(n); i>= e; i--)
#define all(a) (a).begin(), (a).end()
#define VEC(n, x) VI n(x); rep(i, x) cin >> n[i];
#define MAT(m, x, y) VVI m(x, VI(y)); rep(i, x) rep(j, y) cin >> m[i][j];
#define FIX cout << fixed << setprecision(10);
#define out(x) cout << (x) << endl;
#define fin(x) { out(x); return 0; }
#define IN(x, l, r) ((l) <= (x) && (x) < (r))
const VP dir4 = { { -1, 0 }, { 1, 0 }, { 0, 1 }, { 0, -1 } };
const VP dir8 = { { -1, 0 }, { -1, 1 }, { 0, 1 }, { 1, 1 }, { 1, 0 }, { 1, -1 }, { 0, -1 }, { -1, -1 } };
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main () {
int A, B, C, D; cin >> A >> B >> C >> D;
out(B - C);
return 0;
}
| #include<iostream>
using namespace std;
int main() {
int a, b, c, d;
cin >> a >> b;
cin >> c >> d;
cout << b - c << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
/*<DEBUG>*/
#define tem template <typename
#define can_shift(_X_, ...) enable_if_t<sizeof test<_X_>(0) __VA_ARGS__ 8, debug&> operator<<(T i)
#define _op debug& operator<<
tem C > auto test(C *x) -> decltype(cerr << *x, 0LL);
tem C > char test(...);
tem C > struct itr{C begin, end; };
tem C > itr<C> get_range(C b, C e) { return itr<C>{b, e}; }
struct debug{
#ifdef _LOCAL
~debug(){ cerr << endl; }
tem T > can_shift(T, ==){ cerr << boolalpha << i; return *this; }
tem T> can_shift(T, !=){ return *this << get_range(begin(i), end(i)); }
tem T, typename U > _op (pair<T, U> i){
return *this << "< " << i.first << " , " << i.second << " >"; }
tem T> _op (itr<T> i){
*this << "{ ";
for(auto it = i.begin; it != i.end; it++){
*this << " , " + (it==i.begin?2:0) << *it;
}
return *this << " }";
}
#else
tem T> _op (const T&) { return *this; }
#endif
};
string _ARR_(int* arr, int sz){
string ret = "{ " + to_string(arr[0]);
for(int i = 1; i < sz; i++) ret += " , " + to_string(arr[i]);
ret += " }"; return ret;
}
#define exp(...) " [ " << #__VA_ARGS__ << " : " << (__VA_ARGS__) << " ]"
/*</DEBUG>*/
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<int, int> pii;
//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define pb push_back
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define TC int __TC__; cin >> __TC__; while(__TC__--)
#define ar array
const ll M = 998244353LL, N = 50;
int g[N][N];
inline ll mul(ll a, ll b){
return (a * b) % M;
}
inline ll fact(ll x){
ll ans = 1;
for(ll i = 1; i <= x; ++i) ans = mul(ans, i);
return ans;
}
struct DSU{
vector<int> p, sz;
int cnt;
void init(int n){
p.resize(n); sz.resize(n);
iota(p.begin(), p.end(), 0);
fill(sz.begin(), sz.end(), 1);
cnt = n;
}
int find(int u){
return (p[u] == u ? u : p[u] = find(p[u]));
}
bool unite(int u, int v){
u = find(u);
v = find(v);
if(u == v) return 0;
p[v] = u;
sz[u] += sz[v];
--cnt;
return 1;
}
ll size(int u){
u = find(u);
return sz[u];
}
};
int main(void)
{
FAST;
DSU c, r;
int n, k; cin >> n >> k;
c.init(n);
r.init(n);
for(int i = 0; i < n; ++i){
for(int j = 0; j < n; ++j){
cin >> g[i][j];
}
}
for(int i = 0; i < n; ++i){
for(int j = i+1; j < n; ++j){
bool okr = 1, okc = 1;
for(int x = 0; x < n; ++x){
if(g[i][x] + g[j][x] > k) okr = 0;
if(g[x][i] + g[x][j] > k) okc = 0;
}
if(okr) r.unite(i, j);
if(okc) c.unite(i, j);
}
}
vector<bool> visr(n, 0), visc(n, 0);
ll rows = 1, cols = 1;
for(int i = 0; i < n; ++i){
int curr = r.find(i), curc = c.find(i);
if(!visr[curr]) rows = mul(rows, fact(r.size(curr))), visr[curr] = 1;
if(!visc[curc]) cols = mul(cols, fact(c.size(curc))), visc[curc] = 1;
}
cout << mul(rows, cols) << '\n';
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const int maxN = 55, mod = 998244353;
int n, lim;
int pa[maxN + 1], a[maxN + 1][maxN + 1];
int fac[maxN + 1], sz[maxN + 1];
inline int find(int x) { return pa[x] == x ? x : pa[x] = find(pa[x]); }
int main()
{
scanf("%d %d", &n, &lim);
for(int i = 1; i <= n; i++)
for(int j = 1; j <= n; j++)
scanf("%d", &a[i][j]);
fac[0] = 1;
for(int i = 1; i <= n; i++) fac[i] = 1ll * fac[i - 1] * i % mod;
int ans = 1;
for(int i = 1; i <= n; i++) pa[i] = i, sz[i] = 0;
for(int i = 1; i <= n; i++)
for(int j = i + 1; j <= n; j++)
{
bool flag = true;
for(int k = 1; k <= n; k++)
if(a[i][k] + a[j][k] > lim) { flag = false; break; }
if(flag) pa[ find(i) ] = find(j);
}
for(int i = 1; i <= n; i++) sz[ find(i) ] ++;
for(int i = 1; i <= n; i++)
if(find(i) == i) ans = 1ll * ans * fac[ sz[i] ] % mod;
for(int i = 1; i <= n; i++) pa[i] = i, sz[i] = 0;
for(int i = 1; i <= n; i++)
for(int j = i + 1; j <= n; j++)
{
bool flag = true;
for(int k = 1; k <= n; k++)
if(a[k][i] + a[k][j] > lim) { flag = false; break; }
if(flag) pa[ find(i) ] = find(j);
}
for(int i = 1; i <= n; i++) sz[ find(i) ] ++;
for(int i = 1; i <= n; i++)
if(find(i) == i) ans = 1ll * ans * fac[ sz[i] ] % mod;
printf("%d\n", ans);
return 0;
}
|
#include <bits/stdc++.h>
typedef long long LL;
#define lowbit(x) (x & (-x))
const LL inf = 1e17+9;
const LL mod = 1e9+7;
const LL maxn = 2e2+8;
LL n, m, fa[maxn];
double x[maxn], y[maxn], hi[maxn], lo[maxn];
LL find(LL u) {
if (fa[u] == u) return u;
return fa[u] = find(fa[u]);
}
void solve() {
LL i, j;
double h = 100, l = 0, mid;
scanf("%lld", &n);
for (i = 1; i <= n; i++) scanf("%lf%lf", &x[i], &y[i]);
while (l < h) {
mid = (h + l) / 2;
for (i = 1; i <= n; i++) {
fa[i] = i; hi[i] = y[i]; lo[i] = y[i];
}
for (i = 1; i <= n; i++) {
for (j = i + 1; j <= n; j++) {
if ((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]) < 4 * mid * mid) {
LL fi = find(i), fj = find(j);
fa[fj] = fi;
hi[fi] = std::max(hi[fi], hi[fj]);
lo[fi] = std::min(lo[fi], lo[fj]);
}
}
if (100.0 - hi[find(i)] < 2.0 * mid && lo[find(i)] + 100.0 < 2.0 * mid) break;
}
if (i <= n) h = mid - 1e-6;
else l = mid + 1e-6;
}
printf("%.10lf\n", h);
}
signed main() {
LL t = 1; // scanf("%lld", &t);
while (t--) solve();
return 0;
}
| #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
class union_find{
int n;
vector<int> p;
public:
union_find(int n):n(n),p(n,-1){}
int find(int u){ return p[u]<0?u:p[u]=find(p[u]); }
void unite(int u,int v){
u=find(u); v=find(v);
if(u!=v){
if(p[v]<p[u]) swap(u,v);
p[u]+=p[v]; p[v]=u; n--;
}
}
bool is_same(int u,int v){ return find(u)==find(v); }
int size()const{ return n; }
int size(int u){ return -p[find(u)]; }
};
struct edge{
int u,v,cost;
edge(){}
edge(int u,int v,int cost):u(u),v(v),cost(cost){}
bool operator<(const edge& e)const{ return cost<e.cost; }
};
int main(){
int n; scanf("%d",&n);
vector<int> x(n),y(n);
rep(i,n) scanf("%d%d",&x[i],&y[i]);
int s=n,t=n+1;
vector<edge> E;
rep(i,n) for(int j=i+1;j<n;j++) {
E.emplace_back(i,j,(x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
}
rep(i,n){
E.emplace_back(s,i,(100-y[i])*(100-y[i]));
E.emplace_back(i,t,(y[i]+100)*(y[i]+100));
}
sort(E.begin(),E.end());
union_find U(n+2);
for(auto e:E){
U.unite(e.u,e.v);
if(U.is_same(s,t)){
printf("%.9f\n",sqrt(e.cost)/2);
break;
}
}
return 0;
}
|
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define FOR(i, m, n) for(ll i = m; i < (n); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vii = vector<vi>;
using pii = pair<int, int>;
using vl = vector<ll>;
using vll = vector<vl>;
using pll = pair<ll, ll>;
int main() {
ll H, W;
cin >> H >> W;
vector<string> S(H);
rep(i, H){
cin >> S[i];
}
ll ans = 0;
rep(i, H){
rep(j, W-1){
if(S[i][j] == '.' && S[i][j+1] == '.'){
ans++;
}
}
}
rep(i, W){
rep(j, H-1){
if(S[j][i] == '.' && S[j+1][i] == '.'){
ans++;
}
}
}
cout << ans;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endll "\n"
#pragma GCC optimize(1)
#pragma GCC optimize(2)
#define ull unsigned long long
#define rep(i,b) for(int i=0;i<b;i++)
#define For(i, a, b) for(int i=a;i<=b;i++)
#define Rof(i, a, b) for(int i=a;i>=b;i--)
#define rest(a, b) memset(a,b, sizeof(a));
#define recopy(a, b) memcpy(b, a, sizeof(a));
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
int gcd(int a, int b) {while (b ^= a ^= b ^= a %= b);return a;}//最大公约数
ll gcd(ll a, ll b) {while (b ^= a ^= b ^= a %= b);return a;}
const int inf = 0x3f3f3f3f;
const int mod = 1e9+7;
const int N=1e5+50;
const int maxx=1e7;
int vis1[N],vis2[N];
int a[N],b[N],c[N];
int main(){
int n,m;
cin>>n>>m;
rest(vis1,0)
rest(vis2,0)
int k=0;
rep(i,n){
cin>>a[i];
vis1[a[i]]=1;
}
rep(i,m){
cin>>b[i];
vis2[b[i]]=1;
}
rep(i,n)
{
if(vis2[a[i]]==0)
{
c[k++]=a[i];
}
}
rep(i,m){
if(vis1[b[i]]==0){
c[k++]=b[i];
}
}
sort(c,c+k);
rep(i,k){
cout<<c[i]<<" ";
}
return 0;
}
|
/**
* code generated by JHelper
* More info: https://github.com/AlexeyDmitriev/JHelper
* @author
*/
#include <iostream>
#include <fstream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
inline int inint(istream& in) {int x; in >> x; return x;}
inline ll inll(istream& in) {ll x; in >> x; return x;}
inline string instr(istream& in) {string x; in >> x; return x;}
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)
class AKcal {
public:
void solve(std::istream& in, std::ostream& out) {
int a = inint(in);
int b = inint(in);
out << 1.0 * a * b / 100 << endl;
}
};
int main() {
AKcal solver;
std::istream& in(std::cin);
std::ostream& out(std::cout);
solver.solve(in, out);
return 0;
}
| #include <bits/stdc++.h>
#define endl '\n'
#define INF 0x3f3f3f3f
#define Inf 1000000000000000000LL
#define LL long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
using namespace std;
typedef pair<int,int>pii;
long double a,b;
int main(){
cin>>a>>b;
cout<<a*b/100.0<<endl;
return 0;
}
|
// Author: Amey Bhavsar - ameybhavsar24@(github & twitter)
// IDE: Geany on Ubuntu 20.04
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define repD(i,a,b) for(auto i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin, (x).rend()
#define MOD 1000000007
int main() {
ios_base::sync_with_stdio(false);cin.tie(NULL);
string s;
cin >> s;
deque< char > ans;
bool r = 0;
rep(i,0,(int)s.size()) {
if (s[i] == 'R') {
r = !r;
continue;
}
if (r) {
if (ans.size() > 0 && s[i] == ans.front()) {
ans.pop_front();
} else {
ans.push_front(s[i]);
}
}
else {
if (ans.size() > 0 && s[i] == ans.back()) {
ans.pop_back();
} else {
ans.push_back(s[i]);
}
}
}
for (int i=0; i<(int)ans.size(); i++) {
if (r) {
cout << ans[(int)ans.size()-1-i];
} else {
cout << ans[i];
}
}
cout << '\n';
return 0;
}
| #include <bits/stdc++.h>
#define f(a, n) for (int a=0; a<n; a++)
#define F(a, n) for (int a=1; a<=n; a++)
using namespace std;
int P[200005];
int find(int x){
if (P[x] == 0) return x;
return P[x] = find(P[x]);
}
bool join(int x, int y){ // 1 on non-trivial join
int a = find(x), b = find(y);
if (a == b) return 0;
P[a] = b;
return 1;
}
int A[200005];
int main(){
int n;
cin >> n;
for (int i = 1; i <= n; i++){
cin >> A[i];
}
int ans = 0;
for (int i = 1; i <= n / 2; i++){
ans += join(A[i], A[n + 1 - i]);
}
cout << ans << endl;
} |
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
// #include <atcoder/all>
// using namespace atcoder;
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << "\n"
typedef struct {
ll a;
ll b;
} P;
bool is_possible = false;
bool done[210][210] = {};
void check(ll last, ll minus1, vector<P> D){
if(done[last][minus1]) return;
done[last][minus1] = true;
ll sz = D.size();
rep(diff, 1, last/2+1){
vector<P> d = D;
vector<P> d_new;
ll cnt_1 = 0;
ll mp[210] = {};
ll start = last - 2 * diff + 1;
bool ok = true;
rep(i,0,sz){
bool use = false;
if(d[i].a == -1 && d[i].b == -1){
cnt_1++;
}else{
if(d[i].a != -1 && d[i].b != -1){
if(d[i].a >= start && d[i].a <= start + diff-1 && d[i].a + diff == d[i].b){
mp[d[i].a]++;
mp[d[i].b]++;
use = true;
}else if(d[i].a >= start && d[i].a <= start + diff-1){
ok = false;
}else if(d[i].b >= start + diff && d[i].b <= last){
ok = false;
}
}else if(d[i].b != -1){
if(d[i].b >= start+diff && d[i].b <= last){
mp[d[i].b]++;
mp[d[i].b - diff]++;
use = true;
}
}else if(d[i].a != -1){
if(d[i].a >= start && d[i].a <= start + diff-1){
mp[d[i].a]++;
mp[d[i].a+diff]++;
use= true;
}
}
if(not use){
d_new.push_back(d[i]);
}
}
}
ll cnt_ok = 0;
rep(i,start,last+1){
if(mp[i] == 1){
cnt_ok++;
}else if(mp[i] >= 2){
ok = false;
}
}
if(not ok) continue;
if(cnt_ok + cnt_1 * 2 >= diff * 2){
if(diff == last/2){
is_possible = true;
}else{
ll use = (2*diff - cnt_ok)/2;
rep(i,0,cnt_1 - use) d_new.push_back({-1,-1});
check(start-1, cnt_1 - use, d_new);
}
}
}
}
void solve(){
ll N;
cin >> N;
ll A[110], B[110];
rep(i,0,N) cin >> A[i] >> B[i];
vector<P> data;
rep(i,0,N) data.push_back({A[i], B[i]});
ll cnt = 0;
rep(i,0,N){
if(A[i] == -1 && B[i] == -1) cnt++;
}
check(2*N, cnt, data);
if(is_possible){
print("Yes");
}else{
print("No");
}
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
solve();
} | #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
using namespace std;
#define LL long long
int n;
vector<int> a, b, c;
vector<int> e;
int zz = 0;
int main() {
// std::ios::sync_with_stdio(false);
// std::cin.tie(0);
cin >> n;
a = vector<int>(2 * n, 0);
b = vector<int>(2 * n, 0);
c = vector<int>(2 * n, 0);
e = vector<int>(2 * n, -1);
vector<int> ee = vector<int>(2 * n, 0);
for (int i = 0; i < n; ++i) {
cin >> a[i] >> b[i];
if (a[i] != -1) {
// cout << "a = " << (a[i] - 1) << endl;
if (e[a[i] - 1] != -1) {
cout << "No" << endl;
return 0;
}
e[a[i] - 1] = i;
ee[a[i] - 1] = -1;
}
if (b[i] != -1) {
// cout << "b = " << (b[i] - 1) << endl;
if (e[b[i] - 1] != -1) {
cout << "No" << endl;
return 0;
}
e[b[i] - 1] = i;
ee[b[i] - 1] = 1;
}
if (a[i] != -1 && b[i] != -1 && a[i] >= b[i]) {
cout << "No" << endl;
return 0;
}
}
vector<int> f(n + 1, 0);
f[0] = 1;
// f[i]: 0 .. 2 * i - 1, can be dealt
vector<bool> app(n, false);
for (int i = 1; i <= n; ++i) {
// for (int j = 0; j <= zz; ++j) {
int tot = 0, totApp = 0, dis = 0;
for (int ii = i - 1; ii >= 0; --ii) {
for (int jj = 0; jj < app.size(); ++jj) {
app[jj] = false;
}
if (!f[ii]) {
continue;
}
// cout << "ii = " << ii << endl;
dis = (i - ii); // also the number of persons in this region
// consider ii * 2 and ii * 2 + 1
// tot += 2;
bool flag = true;
for (int jj = ii * 2; jj < ii * 2 + dis; ++jj) {
if (ee[jj] == 1 || ee[jj + dis] == -1) {
flag = false;
break;
}
// cout << "jj = " << jj << endl;
if (e[jj] != -1 && app[e[jj]]) {
flag = false;
break;
}
if (e[jj + dis] != -1 && app[e[jj + dis]]) {
flag = false;
break;
}
if (e[jj] != -1) {
if (e[jj + dis] != -1) {
if (e[jj] != e[jj + dis]) {
flag = false;
break;
}
}
app[e[jj]] = true;
} else {
if (e[jj + dis] != -1) {
app[e[jj + dis]] = true;
}
}
}
if (flag) {
// cout << i << " ok!" << endl;
f[i] = true;
break;
}
}
}
if (f[n]) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int main(){
int n,w;
cin >> n >> w;
cout << n/w << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
int main(){
int a, mf;
cin >> a >> mf;
int ms = a + mf;
if (ms >= 15 && mf >= 8)
cout << 1;
else if (ms >= 10 && mf >= 3)
cout << 2;
else if (ms >= 3)
cout << 3;
else
cout << 4;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i,a,b) for(int i=a;i<=b;i++)
inline ll rd() {
ll x=0,f=1;
char c=getchar();
while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
while(isdigit(c))x=x*10+c-'0',c=getchar();
return x*f;
}
#define d rd()
ll a[3];
int main(){
a[0]=d,a[1]=d,a[2]=d;
sort(a,a+3);
if(a[0]==a[1])cout<<a[2];
else if(a[1]==a[2])cout<<a[0];
else cout<<0;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int N;
ll X;
vector<map<ll,ll>> memo;
vector<ll> c;
vector<ll> a;
ll dp(int pos,ll value){
if (pos == N) return 1LL;
if (memo[pos].find(value) != memo[pos].end()) return memo[pos][value];
ll ans = dp(pos + 1,(value/a[pos])*a[pos]);
ll r = value % a[pos];
if (r)
ans += dp(pos + 1,(value/a[pos] + 1)*a[pos]);
//else ans += dp(pos + 1,value/c[pos] - 1);
return memo[pos][value] = ans;
}
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> N >> X;
a.resize(N + 1);
for (int i = 0; i < N; i++) cin >> a[i];
a[N] = a[N - 1];
c.resize(N);
for (int i = 0; i < N; i++) c[i] = a[i + 1]/a[i];
memo.resize(N);
cout << dp(0,X);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main(){
int a, b;
cin >> a >> b;
int c = a + b;
int answer = 0;
if(c>=15 && b>=8){
answer = 1;
}
else if(c>=10 && b>=3){
answer = 2;
}
else if(c>=3){
answer = 3;
}
else{
answer = 4;
}
cout << answer << endl;
} | #include<bits/stdc++.h>
using namespace std;
#define fi(a,b) for(int i=a;i<b;i++)
#define fj(a,b) for(int j=a;j<b;j++)
#define ff first
#define ss second
#define ll long long
#define ld long double
#define ull unsigned long long
#define bp(x) __builtin_popcount(x)
#define pr(x) for(auto it: x) cout<<it<<" "; cout<<endl;
#define getMax(x) max_element(x.begin(),x.end())
#define getMin(x) min_element(x.begin(),x.end())
#define endl "\n"
typedef vector<int> vi;
typedef vector< pair<int,int> > vii;
typedef vector<long long> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector< pair<ll,ll> > vll;
//int dx[]={1,0,-1,0};
//int dy[]={0,1,0,-1};
//int dx[]={-1,0,1,1,1,0,-1,-1};
//int dy[]={-1,-1,-1,0,1,1,1,0};
void nikal_pehli_fursat_mai(){
ll a, b;
cin>>a>>b;
a += b;
if(a>=15 and b>=8) cout<<1<<endl;
else if(a>=10 and b>=3) cout<<2<<endl;
else if(a>=3) cout<<3<<endl;
else cout<<4<<endl;
}
int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios::sync_with_stdio(0);
cin.tie(0);
int tc=1;
// cin>>tc;
while(tc--){
nikal_pehli_fursat_mai();
}
}
|
#include <bits/stdc++.h>
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
using namespace std;
//#define int long long
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef vector<vector<int>> graph;
#define pu push
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define MOD 1000000007
#define MAXX 1.1529215e+18
#define _1 first
#define _2 second
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define all(x) x.begin(),x.end()
#define si(x) int(x.size())
template<class t,class u> bool chmax(t&a,u b){if(a<b){a=b;return true;}else return false;}
template<class t,class u> bool chmin(t&a,u b){if(b<a){a=b;return true;}else return false;}
template<class t> using vc=vector<t>;
template<class T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<class T>
T extgcd(T a, T b, T &x, T &y) {
T d = a;
if (b == 0) {
x = 1;
y = 0;
} else {
d = extgcd(b, a%b, y, x);
y -= (a/b)*x;
}
return d;
}
template<class t,class u>
ostream& operator<<(ostream& os,const pair<t,u>& p){
return os<<"{"<<p._1<<","<<p._2<<"}";
}
template<class t> ostream& operator<<(ostream& os,const vc<t>& v){
os<<"{";
for(auto e:v)os<<e<<",";
return os<<"}";
}
template<class T>
void g(T &a){
cin >> a;
}
template<class T>
void o(const T &a,bool space=false){
cout << a << (space?' ':'\n');
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int K;
ll N, M;
cin >> K >> N >> M;
vector<ll> A(K);
rep(i, K) {
cin >> A[i];
}
ll l = 0;
ll r = 2e9;
while(r-l>1) {
ll m = (l+r)/2;
bool flag = true;
ll sum1 = 0;
ll sum2 = 0;
rep(i, K) {
ll t1 = (M*A[i]+m)/N;
ll t2 = (M*A[i]-m+N-1)/N;
sum1 += t1;
sum2 += t2;
if (t2 > t1) {
flag = false;
}
}
if (!(sum1 >= M && sum2 <= M))
flag = false;
if (flag) {
r = m;
} else {
l = m;
}
// cout << m << endl;
}
// cout << r << ' ' << l << endl;
vector<ll> v1(K);
vector<ll> v2(K);
int cnt = 0;
rep(i, K) {
v1[i] = (M*A[i]-r+N-1)/N;
v2[i] = (M*A[i]+r)/N-(M*A[i]-r+N-1)/N;
cnt += v1[i];
}
// cout << v1 << endl;
// cout << v2 << endl;
ll res = M-cnt;
rep(i, K) {
if (res < v2[i]) {
v1[i] += res;
res = 0;
} else {
v1[i]+= v2[i];
res -= v2[i];
}
}
// if (res > 0) {
// rep(i, K) {
// if (i < res % K) {
// v1[i] += res/K+1;
// } else {
// v1[i] += res/K;
// }
// }
// }
rep(i, K) {
cout << v1[i] << ' ';
}
cout << endl;
}
| #include <iostream>
#include <cmath>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;
#define mp make_pair
#define x first
#define y second
typedef pair<int,int> pii;
typedef long long ll;
typedef pair<ll,int> pl;
ll arr[100005],b[100005];
vector<pl> v;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int k;
cin>>k;
ll m,n;
cin>>n>>m;
for(int i=1;i<=k;i++){
cin>>arr[i];
}
ll sum=0ll;
for(int i=1;i<=k;i++){
b[i]=arr[i]*m/n;
sum+=b[i];
v.push_back(mp(m*arr[i]-n*b[i],i));
}
sort(v.begin(),v.end());
reverse(v.begin(),v.end());
for(int i=sum;i<m;i++){
b[v[i-sum].y]++;
}
for(int i=1;i<=k;i++) cout<<b[i]<<" ";
return 0;
}
|
#pragma GCC diagnostic ignored "-Wunused-const-variable"
#ifdef MAC
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <bitset>
#include <random>
#include <chrono>
#include <complex>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#else
#include <bits/stdc++.h>
#endif
using namespace std;
#define mp make_pair
#define pb push_back
#define forn(i, n) for(int i = 0; i < (int)(n); ++i)
#define for1(i, n) for(int i = 1; i < (int)(n); ++i)
#define nfor(i, n) for(int i = int(n) - 1; i >= 0; --i)
#define fore(i, l, r) for(int i = int(l); i < int(r); ++i)
#define correct(x, y, n, m) (0 <= x && x < n && 0 <= y && y < m)
#define all(x) (x).begin(), (x).end()
#define fst first
#define snd second
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef tuple<int,int,int> iii;
template<typename T> inline T abs(T a){ return ((a < 0) ? -a : a); }
template<typename T> inline T sqr(T a){ return a * a; }
template<class T> T gcd(T a, T b) { return a ? gcd (b % a, a) : b; }
template<class T> T lcm(T a, T b) { return a / gcd (a, b) * b; }
template<class T> T sign(T a) { return a > 0 ? 1 : (a < 0 ? -1 : 0); }
string to_string(string s) {
return '"' + s + '"';
}
string to_string(const char* s) {
return to_string((string) s);
}
string to_string(bool b) {
return (b ? "true" : "false");
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
bool first = true;
string res = "{";
for (const auto &x : v) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(x);
}
res += "}";
return res;
}
void dbg() { cout << endl; }
template <typename Head, typename... Tail>
void dbg(Head H, Tail... T) {
cout << " " << to_string(H);
dbg(T...);
}
#ifdef DEBUG
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg(__VA_ARGS__)
#else
#define dbg(...)
#endif
void fastIO() {
cin.sync_with_stdio(false);
cin.tie(0);
}
template<typename T>
vector<T> make_unique(vector<T> v) {
sort(all(v));
return v.resize(unique(all(v)) - v.begin());
}
int nxt() {
int x;
cin >> x;
return x;
}
const int dx[4] = {0, 0, 1, -1};
const int dy[4] = {1, -1, 0, 0};
const int dxKn[8] = {-2, -1, 1, 2, 2, 1, -1, -2};
const int dyKn[8] = { 1, 2, 2, 1, -1, -2, -2, -1};
const int dxK[8] = {0, 0, 1, -1, 1, 1, -1, -1};
const int dyK[8] = {1, -1, 0, 0, 1, -1, 1, -1};
const int MOD = int(1e9) + 7;
const int INF = int(1e9) + 100;
const ll INF64 = 2e18;
const ld PI = ld(3.1415926535897932384626433832795);
const ld e = ld(2.7182818284590452353602874713527);
const ld EPS = 1e-9;
//#############################
const int MAXN = 1000005;
int n, m; // sizes
vector<vector<int>> g; //graph, grid
int main() {
fastIO();
double ans = 0;
cin >> n;
for1(i, n+1) ans += 1.0/(double)i;
ans *= n;
ans-=1;
cout << setprecision(8);
cout << fixed;
cout << ans << endl;
return 0;
}
/*
RECALL CORNER CASES - e.g. n = 1, n = 0
WRITE SOME STUFF
think first, always -
1. concretely
2. graphically
3. abstractly
4. algebraically
Checklist:
- I/O make sense? - Exclusion/inclusion - Is a known sequence?
- Reverse - Brute force approach - DP
- Sort input - Greedy approach
- Check diagonals - Divide and Conquer approach
*/ | #include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type , less<ll> , rb_tree_tag , tree_order_statistics_Node_update>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define inf 1e18
#define mk make_pair
#define ld long double
#define mod 1000000007
#define fi first
#define se second
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test ll t; cin>>t; while(t--)
#define setbits __builtin_popcount
#define endl '\n'
#define LOCAL
#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__) << "] "
int main()
{
fastIO;
string str;
cin>>str;
deque<ll>q;
ll rev=0,n=str.size();
for(int i=0;i<n;i++)
{
if(str[i]=='R')
{
rev^=1;
}
else
{
if(rev)
{
q.push_front(str[i]);
}
else{
q.push_back(str[i]);
}
}
}
if(rev)
{
reverse(q.begin(),q.end());
}
string ans;
while(q.size())
{
char ch=q.front();
if(ans.size() && ans.back()==ch)
{
ans.pop_back();
}
else{
ans.push_back(ch);
}
q.pop_front();
}
cout<<ans;
} |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
scanf("%d%d", &a, &b);
if (a + b >= 15 && b >= 8) {
cout << 1 << endl;
}
else if (a + b >= 10 && b >= 3) {
cout << 2 << endl;
}
else if (a + b >= 3) {
cout << 3 << endl;
}
else {
cout << 4 << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
int n,m,t;
while(scanf("%d%d",&n,&m)!=EOF)
{
n+=m;
if(n>=15&&m>=8)t=1;
else if(n>=10&&m>=3)t=2;
else if(n>=3)t=3;
else t=4;
printf("%d\n",t);
}
}
|
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
ll n;
cin>>n;
for(ll i=0;;i++){
if(stoll(to_string(i)+to_string(i))>n){
cout<<i-1<<endl;
return 0;
}
}
cout<<n/11<<endl;
}
| #include <bits/stdc++.h>
using namespace std;
//解答
int main(){
string S;
cin >> S;
reverse(S.begin(),S.end());
for(int i=0;i<S.length();i++){
if(S[i] == '6'){
S.erase(i,1);
S.insert(i,"9");
}else if(S[i] == '9'){
S.erase(i,1);
S.insert(i,"6");
}
}
cout << S << endl;
}
|
#include<iostream>
using namespace std;
#include<vector>
using ll = long long;
using vi = vector<int>;
int main() {
int N,i;
cin>>N;
int a,c;
vi A(N,0), B(N);
for (i=0;i<N;i++) {
cin>>a;
A[a-1]++;
}
for (i=0;i<N;i++) cin>>B[i];
ll ans=0;
for (i=0;i<N;i++) {
cin>>c;
ans += A[B[c-1]-1];
}
cout<<ans<<endl;
return 0;
}
| #include<bits/stdc++.h>
#define lint long long int
#define rep(i,n) for(int i=0;i<int(n);i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define arep(i,a,n) for(int i=a;i<n;i++)
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define fill(a,x) fill(a.begin(),a.end(),x)
#define eb(data) emplace_back(data)
#define pb(data) emplace_back(data)
#define mp make_pair
#define ALNUM 26
#define vint vector<int>
#define vlint vector<lint>
#define F first
#define S second
#define ALL(data) data.begin(),data.end()
#define GEts(s) getline(cin,s);
#define UNIQUE(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())
using namespace std;
template<typename Rast>inline void out(Rast rast){cout<<rast<<"\n";return;}
template<typename Rast>inline void in(Rast& rast){cin>>rast;return;}
template<typename T>istream& operator >> (istream& is, vector<T>& vec){for(T& x: vec) is >> x;return is;}
template<typename First, typename... Rest>void in(First& first, Rest&... rest){cin >> first;in(rest...);return;}
template<typename First, typename... Rest>void out(First first, Rest... rest){cout << first<<" ";out(rest...);return;}
template<typename T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<typename T>T lcm(T a,T b){return a * b / gcd(a, b);}
template<typename T1,typename T2>bool chmax(T1& a,T2 b){if(a<b){a=b;return true;}else{return false;}}
template<typename T1,typename T2>bool chmin(T1& a,T2 b){if(a>b){a=b;return true;}else{return false;}}
static const double pi = 3.141592653589793;
int modpow(int a,int n,int p){if (n==0)return 1%p; if(n==1)return a%p;if(n%2==1)return (a*modpow(a,n-1,p))%p;lint t=modpow(a,n/2,p);return (t*t)%p;}//a^n%p
//lint MOD=1e9+7;
//lint MOD=998244353;
lint inf=pow(2,50);
int intinf=pow(2,30);
/**int dirx[]={1,0};int diry[]={0,1};//*///右、下
/**int dirx[]={0,1,0,-1};int diry[]={-1,0,1,0};//*///四方位
/**int dirx[]={-1,0,1,1,1,0,-1,-1};int diry[]={-1,-1,-1,0,1,1,1,0};//*///八方位
class unionfind{
public:
vector<int> table;
void init(int size){
table.resize(size);
rep(i,size)table[i]=i;
};
int root(int index){
if(table[index]==index)return index;
else{
int hoge=root(table[index]);
table[index]=hoge;
return hoge;
}
};
bool same(int x,int y){
return(root(x)==root(y));
};
int marge(int x,int y){
int yroot=root(y);
int xroot=root(x);
if(xroot==yroot)return 0;
table[yroot]=xroot;
return 0;
}
int getsize(){
set<int> ma;
rep(i,table.size())ma.insert(root(i));
int re=ma.size();
return re;
}
};
int main(){
cin.tie(0);ios::sync_with_stdio(false);cout<<std::fixed<<std::setprecision(16);
int n;
in(n);
int ans=n;
rep(i,n+1){
stringstream ss;
stringstream sb;
ss<<dec<<i;
sb<<oct<<i;
string a=ss.str();
string b=sb.str();
bool flg=false;
rep(i,a.size()){
if(flg)break;
if(a[i]=='7')flg=true;
}
rep(i,b.size())if(b[i]=='7'){
if(flg)break;
flg=true;
}
if(flg){
ans--;
}
}
out(ans);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e6+5,M=1e9+7,OO=0x3f3f3f3f;
int main(){
//freopen("myfile.txt","w",stdout);
int n,m;
scanf("%d%d",&n,&m);
vector<int> arr(n);
for(int i=0;i<n;++i)
scanf("%d",&arr[i]);
sort(arr.begin(),arr.end());
vector<ll> pre(n+1,0);
vector<ll> suf(n+2,0);
pre[1]=abs(arr[1]-arr[0]);
for(int i=3;i<n;i+=2)
pre[i]+=pre[i-2]+abs(arr[i]-arr[i-1]);
for(int i=n-2;i>0;i-=2)
suf[i]+=suf[i+2]+abs(arr[i]-arr[i+1]);
ll ans=LONG_LONG_MAX;
arr[n]=OO;
while(m--){
int x;
scanf("%d",&x);
int lo=0,hi=n,md;
while(lo<hi){
md=lo+(hi-lo)/2;
if(arr[md]<=x) lo=md+1;
else hi=md;
}
if(lo&1){
ll cur=suf[lo]+abs(arr[lo-1]-x);
if(lo-2>=0) cur+=pre[lo-2];
ans=min(ans,cur);
}
else{
ll cur=abs(arr[lo]-x);
if(lo-1>=0) cur+=pre[lo-1];
if(lo+1<=n) cur+=suf[lo+1];
ans=min(ans,cur);
}
}
printf("%lld\n",ans);
return 0;
} | #define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
const int INF = INT_MAX / 2;
int dp[200005][2];
void solve() {
int N, M;
cin >> N >> M;
vi H(N), W(M);
rep(i, N)cin >> H[i];
rep(i, M)cin >> W[i];
sort(all(H));
sort(all(W));
W.erase(unique(all(W)), W.end());
M = sz(W);
rep(i, N + 1)rep(j, 2)dp[i][j] = INF;
dp[0][0] = 0;
int cur = 0;
rep(i, N)rep(j, 2) {
if (i < N - 1) {
smin(dp[i + 2][j], dp[i][j] + H[i + 1] - H[i]);
}
while (cur != M && W[cur] < H[i])++cur;
if (j == 0) {
if (cur != M) {
smin(dp[i + 1][1], dp[i][j] + W[cur] - H[i]);
}
if (cur > 0) {
smin(dp[i + 1][1], dp[i][j] + H[i] - W[cur - 1]);
}
}
}
cout << dp[N][1] << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(15);
solve();
return 0;
} |
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <iomanip>
using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);
#define l_ength size
void mul_mod(ll& a, ll b){
a *= b;
a %= MOD;
}
void add_mod(ll& a, ll b){
a = (a<MOD)?a:(a-MOD);
b = (b<MOD)?b:(b-MOD);
a += b;
a = (a<MOD)?a:(a-MOD);
}
std::vector<int> g[111];
std::string s;
bool visited[111][111];
void dfs(int v, int u){
int i;
if(visited[v][u]){
return;
}
visited[v][u] = true;
for(i=(g[u].l_ength()-1); i>=0; --i){
dfs(v,g[u][i]);
}
}
int main(void){
int n,i,j;
long double ans = 0.0L, tmp;
std::cin >> n;
for(i=0; i<n; ++i){
std::cin >> s;
for(j=0; j<n; ++j){
if(s[j]-'0'){
g[i].push_back(j);
}
}
}
for(i=0; i<n; ++i){
dfs(i,i);
}
for(i=0; i<n; ++i){
tmp = 0.0L;
for(j=0; j<n; ++j){
if(visited[j][i]){
tmp += 1.0L;
}
}
ans += 1.0L/tmp;
}
std::cout << std::fixed << std::setprecision(25) << ans << std::endl;
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
#define int long long int
#define ld long double
#define F first
#define S second
#define P pair<int,int>
#define V vector
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define endl "\n"
#define all(x) x.begin(), x.end()
#define forstl(i, s) for (__typeof ((s).end ()) i = (s).begin (); i != (s).end (); ++i)
// #pragma comment(linker, '/STACK:200000') //prevent stack overflow ..STACK Limiter
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define time() cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n"
#define db(...) __f(#__VA_ARGS__, __VA_ARGS__)
const int MOD=1e9+7;
const int MOD2=998244353;
ld PI=2*acos(0.0);
template <typename T> T gcd(T a, T b){return (b==0)?a:gcd(b,a%b);}
template <typename T> T lcm(T a, T b){return a*(b/gcd(a,b));}
template <typename T> T mod_exp(T b, T p, T m){T x = 1;while(p){if(p&1)x=(x*b)%m;b=(b*b)%m;p=p>>1;}return x;}
template <typename T> T invFermat(T a, T p){return mod_exp(a, p-2, p);}
template <typename T> T exp(T b, T p){T x = 1;while(p){if(p&1)x=(x*b);b=(b*b);p=p>>1;}return x;}
string tostring(int number){stringstream ss; ss<<number; return ss.str();}
int toint(const string &s) {stringstream ss; ss << s; int x; ss >> x; return x;}
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << '\n'; }
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...);
}
void solve()
{
int x,y,a,b; cin>>x>>y>>a>>b;
long long ans=0;
while((double)a*x<=2e18 && a*x<=x+b && a*x<y){
x*=a;
ans++;
}
cout << ans+(y-1-x)/b << endl;
}
int32_t main()
{
ios_base:: sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
#ifndef ONLINE_JUDGE //file start
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif //file end
// int cases=1;
// int t; cin>>t;
// while(t--)
solve();
return 0;
}
// 1LL check ? |
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <tuple>
#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<ll, ll>;
// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << '\n'; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on
const int sz = 105;
ll dp[sz][sz][sz];
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
ll n, x;
cin, n, x;
vector<ll> a(n);
rep(i, 0, n) {
cin, a[i];
}
const ll inf = 1LL << 60;
ll ans = inf;
rep(k, 1, n + 1) {
rep(t, 0, sz) rep(b, 0, sz) rep(c, 0, sz) dp[t][b][c] = -1;
dp[0][0][0] = 0;
rep(i, 0, n) {
rep(j, 0, k + 1) { // cnt
rep(t, 0, k) { // mod
if (dp[i][j][t] == -1) continue;
ll num = dp[i][j][t] * k + t;
ll aft = num + a[i];
ll div = aft / k;
ll q = aft % k;
chmax(dp[i + 1][j][t], dp[i][j][t]);
if (j + 1 <= k) {
chmax(dp[i + 1][j + 1][q], div);
}
}
}
}
ll aft = dp[n][k][x % k];
if (aft == -1) {
continue;
}
chmin(ans, (x - aft * k - x % k) / k);
}
print(ans);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
long long dp[110][110][110][110] = {0}; //何個目まで見たか 何個選んだか mod mod何か
int main(){
long long N,X;
cin >> N >> X;
vector <long long> potion;
long long maxa = 0;
for(int i=0;i<N;i++){
long long a;
cin >> a;
potion.push_back(a);
maxa = max(a,maxa);
}
if(N==1){
cout << X-potion[0] << endl;
return 0;
}
for(int i=0;i<N;i++){
for(int j=0;j<=i;j++){
for(int k=2;k<=N;k++){
for(int l=0;l<k;l++){
if(dp[i][j][k][l]==0&&(l!=0||j!=0)){
continue;
}
dp[i+1][j+1][k][(l+potion[i])%k]=max(dp[i+1][j+1][k][(l+potion[i])%k],dp[i][j][k][l]+potion[i]);
dp[i+1][j][k][l]=max(dp[i+1][j][k][l],dp[i][j][k][l]);
}
}
}
}
/*
for(int i=1;i<=N;i++){
for(int j=1;j<=i;j++){
for(int k=2;k<=N;k++){
for(int l=0;l<k;l++){
cout << i<< "番目までで" << j << "個選んで mod "<< k << " = " << l << "の最大値は " <<dp[i][j][k][l] << endl;
}
cout << endl;
}
cout << endl;
}
cout << endl;
}
*/
long long ans = 9000000000000000000;
for(long long j=N;j>0;j--){
for(int i=N;i>=j;i--){
if(dp[i][j][j][X%j]!=0){
ans = min(ans,(X-dp[i][j][j][X%j])/j);
}
}
}
if(ans == 9000000000000000000){
ans = X - maxa;
}
cout << ans << endl;
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define per(i, a, b) for (auto i = (b); i-- > (a); )
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) int((x).size())
#define lb(x...) lower_bound(x)
#define ub(x...) upper_bound(x)
template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll ans = 1;
int n; cin >> n;
ll p = 1;
rep(i, 0, n) {
string s; cin >> s;
p <<= 1;
if (s[0] != 'A') ans |= p;
}
cout << ans;
} | #include <bits/stdc++.h>
using ull = unsigned long long int;
using ll = long long;
using ld = long double;
using pii = std::pair<int,int>;
using pll = std::pair<ll, ll>;
using vi = std::vector<int> ;
using vvi = std::vector<vi> ;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vd = std::vector<double> ;
using vvd = std::vector<vd> ;
using qi = std::queue<int> ;
using vpii = std::vector<std::pair<int, int> >;
using vpll = std::vector<pll>;
using namespace std;
#define rep(i,j) for(int (i)=0;(i)<(j);(i)++)
#define drep(i,j) for(int (i)=(j);(i) >= 0;(i)--)
template<class T1, class T2> inline void chmin(T1 &a, T2 b){if(a > b) a = b;}
template<class T1, class T2> inline void chmax(T1 &a, T2 b){if(a < b) a = b;}
template<class T> inline void pri(T a){cout << a << endl;}
template<class Z> using vec = vector<Z>;
template<class T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
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 << endl;
return;
}
template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
cout << first << " " ;
OUT(rest...);
return;
}
const int max_n = 3 * (1e5) + 1;
const int max_m = 83 * (1e5) + 1;
const int INF = int(1e9);
const long long int INFL = (long long int)1e18;
int n,m,k;
string S;
int ans;
void solve()
{
int N;
IN(N);
string S,X;
IN(S,X);
vi dp(N+1);
dp[N] = 1;
vi ten(N+5);
ten[0] = 1;
rep(i,N+1)
{
ten[i+1] = (ten[i]*10) %7;
}
//OUT("dp[N]",dp[N]);
for(int i=N;i>0;i--)
{
vi pos;
rep(j,7)
{
if(dp[i]&(1 << j))
{
pos.push_back(j);
//OUT(j);
}
}
//for(auto e : pos) cout << e << " ";
//OUT();
if(X[i-1] == 'T')
{
int x = S[i-1] - '0';
//OUT("x",x);
x *= ten[N-i];
x %= 7;
int ret = 0;
for(auto &e: pos )
{
int k = (e - x + 7)%7;
ret |= (1 << k);
ret |= (1 << e);
}
//OUT("x",x);
dp[i-1] = ret;
//OUT("T",dp[i-1]);
}
else
{
int x = S[i-1] - '0';
//OUT("x",x);
x *= ten[N-i];
x %= 7;
int tmp1 = 0;
int tmp2 = 0;
for(auto &e : pos)
{
int k = (e - x + 7)%7;
tmp1 |= (1 << k);
tmp2 |= (1 << e);
}
dp[i-1] = (tmp1 & tmp2);
//OUT("x",x);
//OUT("A",dp[i-1]);
}
}
if(dp[0] & 1)
{
cout << "Takahashi" << endl;
}
else cout << "Aoki" << endl;
}
signed main (int argc, char* argv[])
{
cin.tie(0);
ios::sync_with_stdio(false);
int cases=1;
//IN(cases);
while(cases--)solve();
//pri(ans);
//for(auto c : ans){cout << c << endl;}
//cout << fixed << setprecision(15) << ans << endl;
return 0;
} |
//
#include <iostream>
#include <string>
using namespace std;
int main() {
int N, D, H;
cin >> N >> D >> H;
int O[N][2];
for (int i = 0; i < N; i++) {
for (int j = 0; j < 2; j++)
cin >> O[i][j];
}
int noview = 0;
int ans = 0;
for (int i = 0; i <= H; i++) {
float m = ((float)H - (float)i) / (float) D;
noview = 0;
for (int j = 0; j < N; j++) {
if (O[j][1] > (int) ((float)i + m * (float) O[j][0])) {
noview = 1;
break;
}
}
if (noview) {
ans++;
continue;
}
else
break;
}
if (ans > 0) {
float mar = (float) (ans - 1);
while (mar < (float) ans) {
mar += 0.0005;
float m = ((float) H - mar) / (float) D;
noview = 0;
for (int j = 0; j < N; j++) {
if (O[j][1] > (int) (mar + m * (float) O[j][0])) {
noview = 1;
break;
}
}
if (noview)
continue;
else
break;
}
cout << mar << "\n";
}
else
cout << (float) ans << "\n";
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INFint = 1e9+1;
const ll INFll = (ll)1e18+1;
const int MOD=1e9+7;
int main(){
int N, D, H;
cin>>N>>D>>H;
double a = INFint;
for(int i = 0; i < N; ++i) {
int d, h;
cin>>d>>h;
a = min(a, (H - h)/(double(D - d)));
}
cout << setprecision(15) << max(0.0, H - a * D) << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
const int MOD = 1e9 + 7, N = 3e3 + 5;
int add(int x, int y)
{
x += y;
while (x >= MOD)
x -= MOD;
while (x < 0)
x += MOD;
return x;
}
int mul(int x, int y)
{
return (x * 1ll * y) % MOD;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
vector<ll> arr(n + 1);
for (int i = 1; i <= n; i++)
cin >> arr[i];
vector<vector<int>> dp(n + 1, vector<int>(n + 1)), last(n + 1, vector<int>(n + 1));
for (int k = 1; k <= n; k++)
{
vector<int> div(k + 1, -1);
div[0] = 0;
int sum = 0;
for (int i = 1; i <= n; i++)
{
sum += arr[i] % k;
sum %= k;
last[i][k] = div[sum];
div[sum] = i;
}
}
dp[0][0] = 1;
for (int i = 1; i <= n; i++)
{
for (int k = 1; k <= i; k++)
{
int l = last[i][k];
if (l >= 0)
dp[i][k] = add(dp[l][k], dp[l][k - 1]);
}
}
int res = 0;
for (int i = 1; i <= n; i++)
res = add(res, dp[n][i]);
cout << res << "\n";
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll; //int:2*10**9
typedef long double ld;
typedef pair<ll,ll> P;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define pb push_back
#define MOD 1000000007 //998244353
#define PI 3.141592653
#define INF 100000000000000 //14
//cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
int main(){
ll n; cin >> n;
vector<ll> a(n);
REP(i,n) cin >> a[i];
vector<vector<ll>> dp(n,vector<ll>(n+1,0));
vector<vector<ll>> conn(n,vector<ll>(n+1,-1));
vector<vector<ll>> table(n,vector<ll>(n+1,-1));
ll asum = 0;
REP(i,n) {
asum += a[i];
FOR(j,1,n) {
ll ad = asum%j;
conn[i][j]= table[ad][j];
table[ad][j]=i;
}
}
dp[0][1]=1;
FOR(i,1,n-1) {
dp[i][1]=1;
FOR(j,2,n) {
if (conn[i][j]!=-1) {
// cout << i << " " << j << " " << dp[conn[i][j]][j] << " " << dp[conn[i][j]][j-1] << endl;
dp[i][j]=(dp[i][j]+dp[conn[i][j]][j])%MOD;
dp[i][j]=(dp[i][j]+dp[conn[i][j]][j-1])%MOD;
}
}
}
// REP(i,n){
// REP(j,n+1) cout << dp[i][j] << " ";
// cout << endl;
// }
ll ans = 0;
FOR(i,1,n) ans = (ans+dp[n-1][i])%MOD;
cout << ans << endl;
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define forn(i,x,n) for(int i = x;i <= n;++i)
#define forr(i,x,n) for(int i = n;i >= x;--i)
#define Angel_Dust ios::sync_with_stdio(0);cin.tie(0)
const int N = 2e6+7,MOD = 1e9+7;
int fact[N],infact[N];
ll qpow(ll a,ll b,ll MOD)
{
ll res = 1;
while(b)
{
if(b & 1) res = a * res % MOD;
a = a * a % MOD;
b >>= 1;
}
return res;
}
void init()
{
fact[0] = infact[0] = 1;
forn(i,1,N - 1)
{
fact[i] = 1ll * i * fact[i - 1] % MOD;
infact[i] = qpow(i,MOD - 2,MOD) * infact[i - 1] % MOD;
}
}
int main()
{
init();
int n,m,k;scanf("%d%d%d",&n,&m,&k);
if(n > m + k) return puts("0"),0;
int res = 1ll * fact[n + m] * infact[n] % MOD * infact[m] % MOD;
if(k + 1 <= n)
{
ll rt = 1ll * fact[n + m] * infact[n - k - 1] % MOD * infact[m + k + 1] % MOD;
res = ((res - rt) % MOD + MOD) % MOD;
}
printf("%d\n",res);
return 0;
}
| //INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a) (a).begin(),(a).end()
#define ALL(a,n) (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
#define dcml(n) fixed<<setprecision(n)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
//CONST
//------------------------------------------
const ll INF=1010000000000000017LL;
const ll MOD=1000000007LL;
const ld EPS=1e-12;
const ld PI=3.14159265358979323846;
//REPEAT
//------------------------------------------
#define FOR(i,m,n) for(ll (i)=(m); (i)<(n); (i)++)
#define FORS(i,m,n) for(ll (i)=(m); (i)<=(n); (i)++)
#define RFOR(i,m,n) for(ll (i)=(n)-1; (i)>=(n); (i)--)
#define RFORS(i,m,n) for(ll (i)=(n); (i)>(n); (i)--)
#define REP(i,n) for(ll (i)=0; (i)<(n); (i)++)
#define REPS(i,x) for(ll (i)=1; (i)<=(x); (i)++)
#define RREP(i,x) for(ll (i)=(x)-1; (i)>=0; (i)--)
#define RREPS(i,x) for(ll (i)=(x); (i)> 0; (i)--)
#define WREP(i,in,j,jn) REP(i,in)REP(j,jn)
#define WREPS(i,in,j,jn) REPS(i,in)REPS(j,jn)
//-----------------------------------------
//namespace
using namespace std;
//ライブラリはここに
//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
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 Factorial(ll n){ ll m=1;while(n>=1)m*=n--;return m; }
ll pow(ll a, ll b, ll mod=INF){
ll res=1;
while(b>0){
if(b&1) res=res*a%mod;
a=a*a%mod;
b>>=1;
}
return res;
}
ll getDigit(ll num){
ll digit=0;
while(num!=0){num/=10;digit++;}
return digit;
}
//-----------------------------------------
int main(void){
ll N;
cin>>N;
ll res,a;
REP(i,N){
cin>>a;
if(i==0)res=a;
res=GCD(res,a);
}
cout<<res<<"\n";
}
|
#include <iostream>
using namespace std;
int main()
{
int n;
cin>>n;
if(n%2!=0)
{
cout<<"Black";
}
else{
cout<<"White";
}
return 0;
} | #include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_set>
#include <vector>
#define REP(i, n) for(int i = 0; i < n; ++i)
using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;
// 素因数分解:O(sqrt(N))
const map<LLONG, LLONG> PrimeFactorize(LLONG N)
{
map<LLONG, LLONG> prime2NumMap;
for (LLONG p = 2; p * p <= N; ++p)
{
if (N % p != 0) continue;
while (N % p == 0)
{
N /= p;
++prime2NumMap[p];
}
}
if (N != 1) prime2NumMap[N] = 1;
return prime2NumMap;
}
int main()
{
int N; cin >> N;
REP(ai, N)
{
int num = 0;
for (const auto& kvp : PrimeFactorize(ai + 1))
{
num += kvp.second;
}
cout << num + 1 << ' ';
}
}
|
#include<bits/stdc++.h>
using namespace std;
#define lowbit(x) (x&-x)
#define reg register
typedef long long LL;
typedef unsigned long long uLL;
typedef unsigned int uint;
const int INF=0x7f7f7f7f;
const int jzm=233;
const int mo=998244353;
const double Pi=acos(-1.0);
typedef pair<int,int> pii;
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;
}
LL n,ans;
int main(){
read(n);
if(n>=1000LL)ans+=(n-999LL);
if(n>=1000000LL)ans+=(n-999999LL);
if(n>=1000000000LL)ans+=(n-999999999LL);
if(n>=1000000000000LL)ans+=(n-999999999999LL);
if(n>=1000000000000000LL)ans+=(n-999999999999999LL);
printf("%lld\n",ans);
return 0;
} | // C -Comma
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(int)(n); ++i)
#define rep2(i, s, n) for(int i=(s); i<(int)(n); ++i)
using namespace std;
using ll = long long;
using ull = unsigned long long;
int main(){
string N;
cin >> N;
ull len = 0;
ull s3 = 999999-1000+1, s6 = (999999999-1000000+1)*2;
ull s9 = (999999999999-1000000000+1)*3;
ull s12 = (999999999999999-1000000000000+1)*4;
ll v = stoll(N);
if(N.size() >= 4 && N.size() <= 6){
len = v-1000+1;
}else if(N.size() >= 7 && N.size() <= 9){
len = (v-1000000+1)*2+s3;
}else if(N.size() >= 10 && N.size() <= 12){
len = (v-1000000000+1)*3+s3+s6;
}else if(N.size() >= 13 && N.size() <= 15){
len = (v-1000000000000+1)*4+s3+s6+s9;
}else if(N.size() == 16){
len = 5+s3+s6+s9+s12;
}
cout << len << endl;
return 0;
} |
#include <bits/stdc++.h>
//#include <atcoder/all>
#define For(i, a, b) for (int(i) = (int)(a); (i) < (int)(b); ++(i))
#define rFor(i, a, b) for (int(i) = (int)(a)-1; (i) >= (int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
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 T>
T div_floor(T a, T b) {
if (b < 0) a *= -1, b *= -1;
return a >= 0 ? a / b : (a + 1) / b - 1;
}
template <class T>
T div_ceil(T a, T b) {
if (b < 0) a *= -1, b *= -1;
return a > 0 ? (a - 1) / b + 1 : a / b;
}
constexpr lint mod = 1000000007;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;
int main() {
int x, y;
scanf("%d%d", &x, &y);
puts(abs(x - y) <= 2 ? "Yes" : "No");
} | /*input
*/
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <sstream>
#include <iterator>
#include <cstdlib>
#include <unordered_map>
#include <map>
#include <list>
#include <utility>
using namespace std;
#define endl ("\n")
#define pi (3.141592653589)
#define mod 1000000007
#define int int64_t
#define float double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(c) c.begin(), c.end()
#define min3(a, b, c) min(c, min(a, b))
#define min4(a, b, c, d) min(d, min(c, min(a, b)))
#define rrep(i, n) for(int i=n-1;i>=0;i--)
#define rep(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
#define srt(v) sort(v.begin(),v.end())
#define ld long double
#define scanArray(a,n) for(int i = 0; i < n; i++){cin >> a[i];}
#define coutArray(a,n) for(int i = 0; i < n; i++){cout << a[i] << " ";};cout << endl;
#define coutSet(set) for (auto it = set.begin(); it != set.end(); ++it) {cout << *it << " "};cout << endl;
struct debugger
{
template<typename T> debugger& operator , (const T& v)
{
cerr<<v<<" ";
return *this;
}
} dbg;
bool check_key(map<int, int> m, int key)
{
if (m.find(key) == m.end())
return false;
return true;
}
vector<int> SieveOfEratosthenes(int n)
{
bool prime[n+1];
memset(prime, true, sizeof(prime));
vector<int> res;
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])
res.push_back(p);
//cout << p << " ";
return res;
}
int decimalToOctal(int decimalNumber) {
int rem, i = 1, octalNumber = 0;
while (decimalNumber != 0) {
rem = decimalNumber % 8;
decimalNumber /= 8;
octalNumber += rem * i;
i *= 10;
}
return octalNumber;
}
int32_t main()
{
fast;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int x; cin>>x;
int y; cin>>y;
int minNum = min(x, y);
int maxNum = max(x, y);
if ((minNum + 3) > maxNum)
{
cout<<"Yes";
} else {
cout<<"No";
}
// Happy Competitive Programming!
} |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
typedef unordered_map<int, int> uii;
typedef unordered_map<ll, ll> ull;
#define mp make_pair
#define pb push_back
#define PB pop_back
#define F first
#define S second
#define Endl '\n'
const int mod = 1e9+7;
void call()
{
ll n,m;
cin >> n >> m;
unordered_map<ll,ll>m1;
unordered_map<ll,ll>m2;
set<ll>s;
for(ll i=0;i<n;++i)
{
ll tmp;
cin >> tmp;
m1[tmp]++;
}
for(int i=0;i<m;++i)
{
ll tmp;
cin >> tmp;
m2[tmp]++;
}
for(auto&it:m1)
{
if(m2.find(it.first)==m2.end())
{
s.insert(it.first);
}
}
for(auto&it:m2)
{
if(m1.find(it.first)==m1.end())
{
s.insert(it.first);
}
}
for(auto&it:s)
{
cout << it << " ";
}
cout << endl;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int TC;TC=1;
while(TC--)
call();
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int main() {
int n, m; cin >> n >> m;
int a[n], b[m];
rep(i, n) cin >> a[i];
rep(i, m) cin >> b[i];
set<int> ans;
rep(i, n){
bool flag = true;
rep(j, m){
if(a[i] == b[j]) flag = false;
}
if(flag) ans.insert(a[i]);
}
rep(j, m){
bool flag = true;
rep(i, n){
if(a[i] == b[j]) flag = false;
}
if(flag) ans.insert(b[j]);
}
for(auto x:ans) cout << x << ' ';
cout << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FORI(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define ll long long
#define mp(m, n) make_pair((m), (n))
// #define DEBUG
#ifdef DEBUG
template<typename T>
void _debug(string s, T x) {
cerr << s << ":";
for (auto it = x.begin(); it != x.end(); ++it) {
cerr << " " << *it;
}
cerr << endl;
}
template<typename T, typename K>
void _debug(string s, map<T, K> x) {
cerr << s << ":";
for (auto it = x.begin(); it != x.end(); ++it) {
cerr << " " << it->first << ":" << it->second;
}
cerr << endl;
}
template<typename T, typename K>
void _debug(string s, set<T, K> x) {
cerr << s << ":";
for (auto it = x.begin(); it != x.end(); ++it) {
cerr << " " << *it;
}
cerr << endl;
}
template<typename T, typename K>
void _debug(string s, vector<pair<T, K> > x) {
cerr << s << ":";
for (auto it = x.begin(); it != x.end(); ++it) {
cerr << " " << it->first << "," << it->second;
}
cerr << endl;
}
void _debug(string s, int x) {
cerr << s << ": " << x << endl;
}
void _debug(string s, long long x) {
cerr << s << ": " << x << endl;
}
void _debug(string s, double x) {
cerr << s << ": " << x << endl;
}
void _debug(string s, string x) {
cerr << s << ": " << x << endl;
}
void _debug(string s, char x) {
cerr << s << ": " << x << endl;
}
#define debug(x) _debug(#x, (x))
#else
#define debug(x)
#endif
#define db debug
int count(vector<string> &m, int index) {
vector<int> vis(m.size());
queue<int> q;
q.push(index);
vis[index] = 1;
while(q.size()) {
int x = q.front();
q.pop();
for (int i = 0; i < m.size(); i++) {
if (m[i][x] == '1' && vis[i] == 0) {
vis[i] = 1;
q.push(i);
}
}
}
return std::accumulate(vis.begin(), vis.end(), 0);
}
int main() {
ios_base::sync_with_stdio(false); std::cin.tie(0);
int n;
cin >> n;
vector<string> v(n);
FOR(i, n) cin >> v[i];
double R = 0;
FOR(i, n) {
int t = count(v, i);
debug(t);
R += 1.0 / t;
}
cout << setprecision(15) << R << endl;
} | #include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)
#define bit(n,k) ((n>>k)&1) //nのk bit目
#define vec(T) vector<T>
#define vvec(T) vector<vector<T>>
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll llINF = 1LL << 60;
const int iINF = 1e9;
//------------------------------------------------
struct Solver{
void solve(){
int N;
ll X;
cin >> N >> X;
vec(ll) A(N),B(N);
rep(i,N) cin >> A[i];
rep(i,N-1) B[i]=A[i+1]/A[i];
B[N-1] = llINF;
vector<map<ll,ll>> dp(N+1);
dp[N][-X]=1;
for(int i=N-1; i>=0 ; i--){
for(auto p:dp[i+1]){
//cout << "i=" << i << "," <<p.first << ","<<p.second<<endl;
ll di = p.first;
ll num,a,b;
num=-A[i]-di;
if(num%A[i]==0) a = num/A[i]+1;
else{
if(num>0) a = num/A[i]+1;
else a = num/A[i];
}
if(abs(a) < B[i]) dp[i][di+a*A[i]] += p.second;
num=A[i]-di;
if(num%A[i]==0) b = num/A[i]-1;
else{
if(num>0) b = num/A[i];
else b = num/A[i]-1;
}
if(abs(b) < B[i] && b>a ) dp[i][di+b*A[i]] += p.second;
}
}
cout << dp[0][0] << endl;
}
};
int main(){
int testcasenum=1;
//cin >> testcasenum;
rep1(ti,testcasenum){
Solver solver;
solver.solve();
}
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#define FOR(i, x, y) for(int i = (x); i < (y); ++i)
#define REP(i, x, y) for(int i = (x); i <= (y); ++i)
#define PB push_back
#define MP make_pair
#define PH push
#define fst first
#define snd second
typedef long long ll;
typedef unsigned long long ull;
typedef double lf;
typedef long double Lf;
typedef pair<int, int> pii;
const int maxn = 2e5 + 5;
int n;
int cnt[10], tmp[10];
char s[maxn];
int main(){
scanf("%s", s);
n = strlen(s);
reverse(s, s + n);
if(n <= 3){
sort(s, s + n);
do{
int val = 0;
FOR(i, 0, n)
(val *= 10) += (s[i] - '0');
if(!(val % 8)){
puts("Yes");
return 0;
}
}
while(next_permutation(s, s + n));
puts("No");
return 0;
}
FOR(i, 0, n)
++cnt[s[i] - '0'];
FOR(i, 0, 10) FOR(j, 0, 10) FOR(k, 0, 10){
FOR(x, 0, 10)
tmp[x] = 0;
++tmp[i]; ++tmp[j]; ++tmp[k];
bool f = true;
FOR(x, 0, 10)
f &= (tmp[x] <= cnt[x]);
if(f && !((i + j * 10 + k * 100) % 8)){
puts("Yes");
return 0;
}
}
puts("No");
return 0;
} | #include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
string s;
int cnt[10];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> s;
for(char i : s) cnt[i - '0']++;
int i = 8;
if((int)s.length() == 2) i = 16;
else if((int)s.length() > 2) i = 104;
for(; i < 1000; i += 8){
string num = to_string(i);
int work = true;
for(char i : num){
cnt[i - '0']--;
if(cnt[i - '0'] < 0) work = false;
}
if(work){
cout << "Yes\n";
return 0;
}
for(char i : num) cnt[i - '0']++;
}
cout << "No\n";
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define int long long
#define inf 1e15
#define pii pair<int,int>
#define fi first
#define se second
int dis[17][17];
int dp[(1<<17)][17];
int k;
int fun(int mask,int i){
if(__builtin_popcount(mask)==1 && mask&(1<<i))return 1;
if(dp[mask][i]!=-1)return dp[mask][i];
int a=inf;
int sub=mask^(1<<i);
for(int j=0;j<k;j++){
if(sub&(1<<j))a=min(a,fun(sub,j)+dis[j][i]);
}
return dp[mask][i]=a;
}
signed main(){
fastio
int n,m;
cin>>n>>m;
vector<vector<int>> adj(n);
for(int i=0;i<m;i++){
int x,y;
cin>>x>>y;
--x;--y;
adj[x].push_back(y);
adj[y].push_back(x);
}
cin>>k;
int c[k];
for(int i=0;i<k;i++){
int x;
cin>>x;
--x;
c[i]=x;
}
for(int i=0;i<k;i++){
int dist[n];
memset(dist,-1,sizeof dist);
dist[c[i]]=0;
queue<int> q;
q.push(c[i]);
while(!q.empty()){
int v=q.front();
q.pop();
for(int u:adj[v]){
if(dist[u]!=-1)continue;
dist[u]=dist[v]+1;
q.push(u);
}
}
for(int j=0;j<k;j++){
if(dist[c[j]]==-1){cout<<"-1";return 0;}
dis[i][j]=dist[c[j]];
}
}
memset(dp,-1,sizeof dp);
int ans=inf;
for(int i=0;i<k;i++)ans=min(ans,fun((1<<k)-1,i));
cout<<ans;
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=1000000007;
constexpr ll INF=1e18;
VVI edge(110000,VI(0));
VI d(110000,INF);
void dijkstra(int s){
priority_queue<P,vector<P>,greater<P>> que;
d[s]=0;
que.push(P(0,s));
while(!que.empty()){
P p=que.top();
que.pop();
int v=p.second;
if(d[v]<p.first) continue;
for(auto to:edge[v]){
if(d[to]>d[v]+1){
d[to]=d[v]+1;
que.push(P(d[to],to));
}
}
}
}
VVI kdist(18,VI(18,INF));
VI kd(5000000,INF);
int M=270000;
int k;
ll dijkstra2(){
priority_queue<P,vector<P>,greater<P>> que;
REP(i,k){
kd[i*M+(1<<i)]=0;
que.push(P(0,i*M+(1<<i)));
}
ll ans=INF;
while(!que.empty()){
P p=que.top();
que.pop();
int v=p.second/M;
int w=p.second%M;
if(kd[p.second]<p.first) continue;
if(w==(1<<k)-1){
ans=min(ans,kd[p.second]);
continue;
}
REP(i,k){
int to=i*M+(w|(1<<i));
if(kd[to]>kd[p.second]+kdist[v][i]){
kd[to]=kd[p.second]+kdist[v][i];
que.push(P(kd[to],to));
}
}
}
return (ans==INF?-1:ans+1);
}
int main(){
int n, m; cin >> n >> m;
int a, b;
REP(i,m){
cin >> a >> b;
a--, b--;
edge[a].push_back(b);
edge[b].push_back(a);
}
cin >> k;
VI c(k);
REP(i,k) cin >> c[i], c[i]--;
REP(i,k){
dijkstra(c[i]);
REP(j,k) kdist[i][j]=d[c[j]];
REP(j,n) d[j]=INF;
}
cout << dijkstra2() << endl;
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repn(i,a,b) for(int i=a;i>=b;i--)
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define mod 1000000007
const int N = 200001;
// int fexp(int a, int b,int m){int ans = 1;while(b){if(b&1)ans=(ans*a)%m; b/=2;a=(a*a)%m;}return ans;}
// int inverse(int a, int p){return fexp(a, p-2,p);}
// int fac[2000001];
// int nCrModPFermat(int n, int r,int p) {
// // cout<<1<<endl;
// if (r==0) return 1;
// return (((fac[n]*((((inverse(fac[r],p)%p)*inverse(fac[n-r],p))%p))))%p);
// }
// vi prime(555,1);
void solve(){
int a,b,x,y;cin>>a>>b>>x>>y;
if(a==x&&y==b)cout<<0;
else if((abs(a-x)+abs(b-y))<=3)cout<<1;
else{
if(abs(a-b)==abs(x-y)||abs(a+b)==abs(x+y))cout<<1;
else if(abs(abs(a-b)-abs(x-y))<4||abs(abs(a+b)-abs(x+y))<4)cout<<2;
else if((abs(a-b)%2)==(abs(x-y)%2))cout<<2;
else cout<<3;
}
}
signed main(){
IOS;
int t=1;
// cin>>t;
// for(int i=2; i*i<=550; i++)
// if(prime[i])
// for(int j=i*i; j<=550; j+=i)
// prime[j]=0;
// fac[0] = 1;
// for (int i=1 ; i<=100001; i++) fac[i] = fac[i-1]*i%mod;
rep(i,0,t){
// cout<<"Case #"<<i+1<<": ";
solve();
cout<<"\n";
}
// return 0;
} | #include<string>
#include<iostream>
#include <algorithm>
#include<vector>
#include<functional>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <numeric>
#include <math.h>
#define ll long long
#define PI 3.14159265358979323846
#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep1(x,n) for(ll x=1;x<(ll)n+1;x++)
using namespace std;
int g1(ll g1) {
vector<ll> a;
bool sw = true;
ll l1 = 1;
while (sw) {
if (g1 > 9) {
a.push_back(g1 % 10);
g1 /= 10;
l1++;
}
else {
a.push_back(g1);
sw = false;
}
}
sort(a.begin(), a.end());
ll gg1 = 0;
ll b = 1;
rep(j, l1) {
gg1 += a.at(j) * b;
b *= 10;
}
return gg1;
}
int g2(ll g2) {
vector<ll> a;
bool sw = true;
ll l1 = 1;
while (sw) {
if (g2 > 9) {
a.push_back(g2 % 10);
g2 /= 10;
l1++;
}
else {
a.push_back(g2);
sw = false;
}
}
sort(a.begin(), a.end(),greater<ll>());
ll gg2 = 0;
ll b = 1;
rep(j, l1) {
gg2 += a.at(j) * b;
b *= 10;
}
return gg2;
}
int main() {
ll N;
ll sw = 0;
cin >> N;
vector <ll> A(N), P(N), X(N);
rep(i, N) cin >> A.at(i) >> P.at(i) >> X.at(i);
vector<ll> B;
rep(i, N) {
if (A.at(i) < X.at(i)) {
B.push_back(P.at(i));
sw++;
}
}
if (sw == 0) {
cout << "-1" << endl;
return 0;
}
else {
sort(B.begin(), B.end());
cout << B.at(0) << endl;
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++)
ll gcd(ll x, ll y) {return (x%y) ? gcd(y, x%y) : y; }
const int inf = 1000000000;
const int dx[]={1,0,-1,0};
const int dy[]={0,1,0,-1};
const ll mod = 1e9+7;
int main(){
int x, y;
cin >> x >> y;
if(y>x){
if(y-x>=3){
cout << "No" << endl; return 0;
}
else{
cout << "Yes" << endl;
return 0;
}
}
else{
if(x-y>=3){
cout << "No" << endl; return 0;
}
else{
cout << "Yes" << endl;
return 0;
}
}
} | #include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#define ll long long
#define MAXN 200005
#define uns unsigned
#define MOD 998244353ll
#define INF 0x7f7f7f7f
using namespace std;
inline ll read(){
ll x=0;bool f=1;char s=getchar();
while((s<'0'||s>'9')&&s>0){if(s=='-')f^=1;s=getchar();}
while(s>='0'&&s<='9')x=(x<<1)+(x<<3)+s-'0',s=getchar();
return f?x:-x;
}
ll x,y,p,q;
inline ll ksm(ll a,ll b,ll mo){
ll res=1;
for(;b;b>>=1,a=a*a%mo)if(b&1)res=res*a%mo;
return res;
}
inline ll gcd(ll a,ll b){
return b==0?a:gcd(b,a%b);
}
inline ll exgcd(ll a,ll b,ll&x,ll&y){
if(b==0){x=1,y=0;return a;}
ll res=exgcd(b,a%b,y,x);
y-=a/b*x;return res;
}
signed main()
{
for(int T=read();T--;){
x=read(),y=read(),p=read(),q=read();
ll md=(x+y)<<1,lim=md*(p+q)+1,ans=lim;
for(ll i=x;i<x+y;i++){
ll b=p,a=p+q,c=((i-b)%md+md)%md;
ll k,f,g=exgcd(a,md,k,f);
if(c%g!=0)continue;
c/=g,k=(k*c%md+md)%md,f=md/g,k%=f,a=p+q,b=p;
if((k*a+b)%md>=x&&(k*a+b)%md<x+y)ans=min(ans,k*a+b);
}
md=p+q;
for(ll i=p;i<p+q;i++){
ll b=x,a=(x+y)<<1,c=((i-b)%md+md)%md;
ll k,f,g=exgcd(a,md,k,f);
if(c%g!=0)continue;
c/=g,k=(k*c%md+md)%md,f=md/g,k%=f,a=(x+y)<<1,b=x;
if((k*a+b)%md>=p&&(k*a+b)%md<p+q)ans=min(ans,k*a+b);
}
if(ans>=lim)printf("infinity\n");
else printf("%lld\n",ans);
}
return 0;
} |
#include<stdio.h>
#include<math.h>
#include<algorithm>
#define it register int
#define ct const int
#define il inline
typedef long long ll;
#define rll register ll
#define cll const ll
#define mkp make_pair
using namespace std;
const int N=30;
const ll inf=1e15;
int n,x[N],y[N],z[N],pw[N];
ll w[N][N],f[20][1<<19];
il int A(ct x){return x<0?-x:x;}
il int Max(ct p,ct q){return p>q?p:q;}
il ll Min(cll p,cll q){return p<q?p:q;}
int main(){
scanf("%d",&n);it i,j,s;
for(i=pw[0]=1;i<=30;++i) pw[i]=pw[i-1]<<1;
for(i=0;i<n;++i) scanf("%d%d%d",&x[i],&y[i],&z[i]);
// x[n]=x[1],y[n]=y[1],z[n]=z[1],++n;
for(i=0;i<n;++i)
for(j=0;j<n;++j)
w[j][i]=A(x[i]-x[j])+A(y[i]-y[j])+Max(z[i]-z[j],0);
//printf("%d %d\n",w[0][1]);
ct lim=1<<n;
for(i=0;i<n;++i) for(j=0;j<=lim;++j) f[i][j]=inf;
f[0][1]=0;
for(s=0;s<lim;++s)
for(i=0;i<n;++i)
if(f[i][s]<inf){
for(j=0;j<n;++j){
if(s>>j&1) continue;
// if(i==0&&j==n-1) continue;
f[j][s|pw[j]]=Min(f[j][s|pw[j]],f[i][s]+w[i][j]);
}
}
rll ans=inf;
for(i=1;i<n;++i) ans=Min(ans,f[i][lim-1]+w[i][0]);
printf("%lld",ans);
// printf("%lld",f[n-1][lim-1]);
return 0;
}
/*
f[i][S]=现在走到 i,已经走了的状态集合是S
f[j][S|pw[j]]=f[i][S]+a[i][j]
*/
| #include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define all(a) a.begin(), a.end()
#define ff(i,a,b) for(int i=a;i<=b;i++)
#define fb(i,b,a) for(int i=b;i>=a;i--)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 20;
const ll inf = 1e18 + 5;
int n;
array<ll,3> niz[maxn];
ll dp[maxn][(1 << 17)];
ll dist[maxn][maxn];
ll memo(int x, int mask){
if(mask == (1 << n) - 1)return dist[x][0];
if(dp[x][mask] != -1)return dp[x][mask];
ll ans = inf;
ff(i,0,n - 1){
if(!(mask & (1 << i)))ans = min(ans, dist[x][i] + memo(i, mask | (1 << i)));
}
return dp[x][mask] = ans;
}
int main()
{
ios::sync_with_stdio(false);
cout.tie(nullptr);
cin.tie(nullptr);
cin >> n;
ff(i,0,n - 1){
ff(j,0,2)cin >> niz[i][j];
}
ff(i,0,n - 1){
ff(j,0,n - 1)dist[i][j] = abs(niz[i][0] - niz[j][0]) + abs(niz[i][1] - niz[j][1]) + max(0ll, niz[j][2] - niz[i][2]);
}
memset(dp, -1, sizeof(dp));
cout << memo(0, 1) << endl;
return 0;
}
/**
// probati bojenje sahovski ili slicno
**/
|
#include <bits/stdc++.h>
using namespace std;
typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldbl;
typedef pair<int, int> pii;
typedef pair<uint, uint> puu;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<uint> vu;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pii> vpii;
typedef vector<puu> vpuu;
typedef vector<pll> vpll;
typedef vector<pull> vpull;
typedef vector<string> vstr;
typedef vector<double> vdbl;
typedef vector<ldbl> vldbl;
#define pb push_back
#define ppb pop_back
#define pfr push_front
#define ppfr pop_front
#define emp emplace
#define empb emplace_back
#define be begin
#define rbe rbegin
#define all(x) (x).be(), (x).end()
#define rall(x) (x).rbe(), (x).rend()
#define fir first
#define sec second
#define mkp make_pair
#define brif(cond) if (cond) break
#define ctif(cond) if (cond) continue
#define retif(cond) if (cond) return
void canhazfast() {ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);}
template<typename T> T gcd(T a, T b) {return b ? gcd(b, a%b) : a;}
template<typename T> T extgcd(T a, T b, T &x, T &y)
{
T x0 = 1, y0 = 0, x1 = 0, y1 = 1;
while (b) {
T q = a/b; a %= b; swap(a, b);
x0 -= q*x1; swap(x0, x1);
y0 -= q*y1; swap(y0, y1);
}
x = x0; y = y0; return a;
}
int ctz(uint x) {return __builtin_ctz(x);}
int ctzll(ull x) {return __builtin_ctzll(x);}
int clz(uint x) {return __builtin_clz(x);}
int clzll(ull x) {return __builtin_clzll(x);}
int popcnt(uint x) {return __builtin_popcount(x);}
int popcntll(ull x) {return __builtin_popcountll(x);}
int bsr(uint x) {return 31^clz(x);}
int bsrll(ull x) {return 63^clzll(x);}
int main()
{
canhazfast();
ll n, ans;
cin >> n;
ans = n;
for (int b = 0; ; ++b) {
ll p = 1LL<<b;
brif(p > n);
ll a = n/p;
ll c = n%p;
ans = min(ans, a+b+c);
}
cout << ans << '\n';
return 0;
}
| #include <cstdio>
#include <algorithm>
using namespace std;
int main(){
long long n;
scanf("%lld",&n);
long long ans=n;
for(int b=0;b<=62;b++){
long long a=n>>b;
long long c=n-(a<<b);
ans=min(ans,a+b+c);
}
printf("%lld",ans);
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#define ps push_back
#define mk make_pair
#define ll long long int
int main()
{
int n;
cin>>n;
unordered_map<int,vector<int>> a;
unordered_map<int,vector<int>> b;
unordered_map<int,vector<int>> c;
int cnt;
for(int i=0;i<n;i++)
{
cin>>cnt;
a[cnt].push_back(i);
}
for(int i=0;i<n;i++)
{
cin>>cnt;
b[cnt].push_back(i);
}
for(int i=0;i<n;i++)
{
cin>>cnt;
c[cnt-1].push_back(i);
}
long long int ans=0;
for(auto j:a)
{
if(b.find(j.first)!=b.end())
{
for(auto i:b[j.first])
{
if(c.find(i)!=c.end())
{
ans+=(j.second.size()*c[i].size());
}
}
}
}
cout<<ans<<endl;
return 0;
} | #include <iostream>
#include <vector>
int main() {
int N;
std::cin >> N;
std::vector<int> A(N), B(N), C(N);
for (auto& x : A) {
std::cin >> x;
x -= 1;
}
for (auto& x : B) {
std::cin >> x;
x -= 1;
}
for (auto& x : C) {
std::cin >> x;
x -= 1;
}
std::vector<int> count(N);
for (int j = 0; j < N; ++j) {
count[B[C[j]]] += 1;
}
long long ans = 0;
for (int i = 0; i < N; ++i) {
ans += count[A[i]];
}
std::cout << ans << '\n';
}
|
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double db;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pll pair<ll,ll>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ub(v,val) upper_bound(v.begin(),v.end(),val)
#define np(str) next_permutation(str.begin(),str.end())
#define lb(v,val) lower_bound(v.begin(),v.end(),val)
#define sortv(vec) sort(vec.begin(),vec.end())
#define rev(p) reverse(p.begin(),p.end());
#define v vector
#define len length()
#define repc(i,s,e) for(ll i=s;i<e;i++)
#define fi first
#define se second
#define mset(a,val) memset(a,val,sizeof(a));
#define mt make_tuple
#define repr(i,n) for(i=n-1;i>=0;i--)
#define rep(i,n) for(i=0;i<n;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define at(s,pos) *(s.find_by_order(pos))
#define set_ind(s,val) s.order_of_key(val)
long long int M = 1e9 + 7 ;
long long int inf = 9 * 1e18;
const double PI = acos(-1);
//CLOCK
ll begtime = clock();
#define time() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//CLOCK ENDED
ll n, m;
// modular exponentiation
ll binpow(ll val, ll deg)
{
if (deg < 0)
return 0;
if (!deg)
return 1 % M;
if (deg & 1)
return binpow(val, deg - 1) * val % M;
ll res = binpow(val, deg >> 1);
return (res * res) % M;
}
//binomial
ll modinv(ll n) {
return binpow(n, M - 2);
}
int main() {
// your code goes here
IOS;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ll i, j, t, k, x, y, z, N;
cin >> n;
ll a[n];
rep(i, n) {
cin >> a[i];
}
ll sum = 0;
ll dp[n + 1][2];
mset(dp, 0);
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
dp[i][0] = (dp[i - 1][0] + dp[i - 1][1]) % M;
dp[i][1] = dp[i - 1][0];
}
//0 for +
//1 for -
// cout << dp[2][0] << ' ' << dp[2][1];
rep(i, n) {
ll prod1 = (dp[i][0] * (dp[n - 1 - i][0] + dp[n - 1 - i][1])) % M;
ll prod2 = dp[i][1];
if (n - 2 - i >= 0)
prod2 = (prod2 * (dp[n - 2 - i][0] + dp[n - 2 - i][1])) % M;
// cout << prod2 << '\n';
(sum += (a[i] * prod1)) %= M;
(sum -= a[i] * prod2) %= M;
if (sum < 0) sum += M;
}
cout << sum;
return 0;
}
| #include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
using namespace std;
//#pragma GCC optimize("Ofast")
//#pragma GCC optimization("unroll-loops, no-stack-protector")
//#pragma GCC target("avx,avx2,fma")
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
long long n, i, j, k, s, MOD = 1000000007, ans;
cin >> n;
vector<long long> a(n);
for (i = 0; i < n; i++) cin >> a[i];
vector<long long> dp(n, 0), dp2(n, 0);
vector<long long> dpc(n, 0), dpc2(n, 0);
dp[0] = a[0];
dpc[0] = 1;
for (i = 1; i < n; i++) {
dpc[i] = (dpc[i - 1] + dpc2[i - 1]) % MOD;
dp[i] = (dp[i - 1] + dp2[i - 1] + a[i] * (dpc[i - 1] + dpc2[i - 1])) % MOD;
dpc2[i] = dpc[i - 1];
dp2[i] = (dp[i - 1] - a[i] * dpc[i - 1] + MOD * MOD) % MOD;
}
ans = (dp[n - 1] + dp2[n - 1]) % MOD;
cout << ans << "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif
#define rep(i, n) for (int i = 0; i < (n); i++)
#define mins(x, y) (x = min(x, y))
#define maxs(x, y) (x = max(x, y))
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using P = pair<int, int>;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
void solve() {
int n;
cin >> n;
vi a(n);
rep(i, n) cin >> a[i];
rep(i, n) a[i]--;
dump(a);
vi idx(n);
rep(i, n) idx[a[i]] = i;
dump(idx);
int x = 0;
vi ans;
while (x < n - 1) {
for (int i = idx[x] - 1; x <= i; i--) {
if (i < 0 || n <= i + 1) {
cout << -1 << endl;
return;
}
swap(a[i], a[i + 1]);
ans.push_back(i);
}
if (idx[x] <= x) {
cout << -1 << endl;
return;
}
x = idx[x];
}
dump(a);
if (ans.size() != n - 1) {
cout << -1 << endl;
return;
}
rep(i, n) {
if (a[i] != i) {
cout << -1 << endl;
return;
}
}
rep(i, ans.size()) {
cout << ans[i] + 1 << endl;
}
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
// freopen("temp.1", "r", stdin);
solve();
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(i64 i=0; i<n; i++)
#define all(v) v.begin(),v.end()
#define pp pair<int,int>
using Graph=vector<vector<int>>;
using i64=int64_t;
int main() {
int n;cin>>n;
vector<int>a(n);rep(i,n)cin>>a[i];
i64 ans=0;
rep(i,n) {
ans+=max(0, a[i]-10);
}
cout << ans;
} |
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
int main(){
int n, count = 1;
double total = 0;
bool same = 1;
cin >> n;
double t[n], leng = n;
for(int i = 0; i < n; i++){
cin >> t[i];
total += t[i];
}
sort(t, t + n);
for(int i = 1; i < n; i++){
if(t[i] == 1){
i++;
continue;
}
if(t[i - 1] == t[i]){
count++;
continue;
}
else{
if(t[i - 1] != 1){
same = 0;
break;
}
}
}
if(n == 1)
cout << t[0] << endl;
else if(n == 2)
cout << max(t[0], t[1]) << endl;
else{
if(count == n){
cout << t[0] * ceil(leng/2) << endl;
}
else if(same && (count % 2) && t[n - 1] != 1)
cout << ceil(total/2) + 1 << endl;
else
cout << ceil(total/2) << endl;
}
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
template<ll MOD = 1000000007>
class ModInt {
ll n;
ModInt constexpr inverse() const {
return ModInt::pow(*this, MOD - 2);
}
public:
ModInt() : n(0) {}
ModInt(ll _n) : n(((_n % MOD) + MOD) % MOD) {}
ModInt operator+=(const ModInt &m) {
n += m.n;
if (n >= MOD) n -= MOD;
return *this;
}
ModInt operator-=(const ModInt &m) {
n -= m.n;
if (n < 0) n += MOD;
return *this;
}
ModInt operator*=(const ModInt &m) {
n *= m.n;
if (n >= MOD) n %= MOD;
return *this;
}
ModInt operator/=(const ModInt &m) {
(*this) *= m.inverse();
return *this;
}
friend ModInt operator+(ModInt t, const ModInt &m) {
return t += m;
}
friend ModInt operator-(ModInt t, const ModInt &m) {
return t -= m;
}
friend ModInt operator*(ModInt t, const ModInt &m) {
return t *= m;
}
friend ModInt operator/(ModInt t, const ModInt &m) {
return t /= m;
}
ModInt operator=(const ll l) {
n = l % MOD;
if (n < 0) n += MOD;
return *this;
}
friend ostream &operator<<(ostream &out, const ModInt &m) {
out << m.n;
return out;
}
friend istream &operator>>(istream &in, ModInt &m) {
ll l;
in >> l;
m = l;
return in;
}
static constexpr ModInt pow(const ModInt x, ll p) {
ModInt<MOD> ans = 1;
for (ModInt<MOD> m = x; p > 0; p /= 2, m *= m) {
if (p % 2) ans *= m;
}
return ans;
}
static constexpr ll mod() {
return MOD;
}
};
using mint = ModInt<998244353>;
mint operator"" _m(unsigned long long m) {
return mint(m);
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int h, w;
input(h, w);
auto dp = make_v(h, w, '.');
rep(i, 0, h) {
rep(j, 0, w) {
input(dp[i][j]);
}
}
vector<int> r(h + w, 0), b(h + w, 0), q(h + w, 0);
rep(i, 0, h) {
rep(j, 0, w) {
if (dp[i][j] == 'R') {
r[i + j]++;
} else if (dp[i][j] == 'B') {
b[i + j]++;
} else {
q[i + j]++;
}
}
}
mint ans = 1;
rep(i, 0, h + w) {
if (r[i] > 0 && b[i] > 0) {
ans = 0;
} else if (q[i] > 0 && (r[i] == 0 && b[i] == 0)) {
ans *= 2;
}
}
print(ans);
return 0;
}
|
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <fstream>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define x first
#define y second
#define Time (double)clock()/CLOCKS_PER_SEC
#define debug(x) std::cerr << #x << ": " << x << '\n';
#define FOR(i, n) for (int i = 0; i < n; ++i)
#define FORN(i, n) for (int i = 1; i <= n; ++i)
#define pb push_back
#define trav(a, x) for (auto& a : x)
using vi = vector<int>;
template <typename T>
std::istream& operator >>(std::istream& input, std::vector<T>& data)
{
for (T& x : data)
input >> x;
return input;
}
template <typename T>
std::ostream& operator <<(std::ostream& output, const pair <T, T> & data)
{
output << "(" << data.x << "," << data.y << ")";
return output;
}
template <typename T>
std::ostream& operator <<(std::ostream& output, const std::vector<T>& data)
{
for (const T& x : data)
output << x << " ";
return output;
}
ll div_up(ll a, ll b) { return a/b+((a^b)>0&&a%b); } // divide a by b rounded up
ll div_down(ll a, ll b) { return a/b-((a^b)<0&&a%b); } // divide a by b rounded down
ll math_mod(ll a, ll b) { return a - b * div_down(a, b); }
#define tcT template<class T
#define tcTU tcT, class U
tcT> using V = vector<T>;
tcT> void re(V<T>& x) {
trav(a, x)
cin >> a;
}
tcT> bool ckmin(T& a, const T& b) {
return b < a ? a = b, 1 : 0;
} // set a = min(a,b)
tcT> bool ckmax(T& a, const T& b) {
return a < b ? a = b, 1 : 0;
}
ll gcd(ll a, ll b) {
while (b) {
tie(a, b) = mp(b, a % b);
}
return a;
}
signed main() {
#ifdef LOCAL
#else
#define endl '\n'
ios_base::sync_with_stdio(0); cin.tie(0);
#endif
int n;
cin >> n;
vi a(2 * n);
cin >> a;
vi sign(2 * n);
V <ii> ord;
FOR (i, 2 * n) {
ord.app(mp(a[i], i));
}
sort(all(ord));
FOR (i, n) {
sign[ord[i].y] = -1;
}
FOR (i, n) {
sign[ord[i + n].y] = 1;
}
string ans;
vi S;
trav (e, sign) {
if (S.empty() || S.back() == e) {
ans += '(';
S.app(e);
}
else {
ans += ')';
S.pop_back();
}
}
assert(S.empty());
cout << ans << endl;
} | #include<bits/stdc++.h>
using namespace std;
#define ll long long
ll dp[100010];
ll tong[10];
int jud(string s,string t){
int tt[10]={0},ss[10]={0};
int i;
for(i=0;i<5;i++)ss[s[i]-'0']++;
for(i=0;i<5;i++)tt[t[i]-'0']++;
ll sums=0,sumt=0;
for(i=1;i<=9;i++){
sums+=pow(10,ss[i])*i;
sumt+=pow(10,tt[i])*i;
}
return sums>sumt;
}
int main(){
ll n,i,j,k,_=1;
// cin>>_;
cin>>k;
for(i=1;i<=9;i++)tong[i]=k;
ll cnt=0,all=0;
string s,t;
cin>>s>>t;
for(i=0;i<4;i++){
tong[s[i]-'0']--;
tong[t[i]-'0']--;
}
for(i=1;i<=9;i++){
for(j=1;j<=9;j++){
if(!tong[i]||!tong[j]||tong[i]+tong[j]<2)continue;
ll temp;
if(i!=j)temp=tong[i]*tong[j];
else temp=tong[i]*tong[i]-tong[i];
all+=temp;
s[4]='0'+i,t[4]='0'+j;
if(jud(s,t))cnt+=temp;
}
}
printf("%.7f",cnt*1.0/all);
}
|
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define ll long long
const ll mod = 998244353;
int n, m, k;
char grd[5005][5005];
ll dp[5005][5005], pw3[10005];
int cnt[5005][5005];
int sm(int x1, int y1, int x2, int y2){
if(x1 > x2) swap(x1, x2);
if(y1 > y2) swap(y1, y2);
return cnt[x2][y2] - cnt[x2][y1 - 1] - cnt[x1 - 1][y2] + cnt[x1 - 1][y1 - 1];
}
ll pw(ll b, ll e){
return pw3[e];
}
int main(){
cin.tie(0) -> sync_with_stdio(0);
cin >> n >> m >> k;
for(int i = 1; i <= n; i ++)
for(int j = 1; j <= m; j ++)
grd[i][j] = '?';
for(int x, y, i = 0; i < k; i ++){
cin >> x >> y;
cin >> grd[x][y];
}
pw3[0] = 1ll;
for(int i = 1; i <= n + m; i ++)
pw3[i] =(pw3[i - 1] * 3ll) % mod;
for(int i = 1; i <= n; i ++){
for(int j = 1; j <= m; j ++){
cnt[i][j] = cnt[i - 1][j] + cnt[i][j - 1] - cnt[i - 1][j - 1] + (grd[i][j] == '?');
// cout << cnt[i][j] << ' ';
}
// cout << endl;
}
for(int i = n; i >= 1; i --){
for(int j = m; j >= 1; j --){
if(i == n){
if(j == m) dp[i][j] = (grd[i][j] == '?' ? 3 : 1);
else{
if(grd[i][j] == '?')
(dp[i][j] += 2 * dp[i][j + 1]) %= mod;
else if(grd[i][j] == 'D')
dp[i][j] = 0ll;
else
(dp[i][j] += dp[i][j + 1]) %= mod;
}
}else{
if(j == m){
if(grd[i][j] == '?')
(dp[i][j] += 2 * dp[i + 1][j]) %= mod;
else if(grd[i][j] == 'R')
dp[i][j] = 0;
else
(dp[i][j] += dp[i + 1][j]) %= mod;
}else{
if(grd[i][j] == '?')
(dp[i][j] += (2 * dp[i + 1][j] * pw(3ll, sm(i, j + 1, i, m))) % mod + (2 * dp[i][j + 1] * pw(3ll, sm(i + 1, j, n, j))) % mod) %= mod;
else if(grd[i][j] == 'R')
(dp[i][j] += (dp[i][j + 1] * pw(3ll, sm(i + 1, j, n, j))) % mod) %= mod;
else if(grd[i][j] == 'D')
(dp[i][j] += (dp[i + 1][j] * pw(3ll, sm(i, j + 1, i, m))) % mod) %= mod;
else{
(dp[i][j] += (dp[i + 1][j] * pw(3ll, sm(i, j + 1, i, m))) % mod + (dp[i][j + 1] * pw(3ll, sm(i + 1, j, n, j))) % mod) %= mod;
}
}
}
}
}
cout << dp[1][1] << endl;
// for(int i = 1; i <= n; i ++){
// for(int j = 1; j <= m; j ++)
// cout << dp[i][j] << " ";
// cout << endl;
// }
return 0;
} | #include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
#define forn(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define fore(i,b,a)for(int i=(b),_a=(a);i>=_a;i--)
#define rep(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pii>
#define m_p make_pair
#define re return
#define pb push_back
#define si set<int>
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define mod 998244353
#define INF 1000000007
#define x1 XZVJDFADSPFOE
#define y1 GASDIJSLDAEJF
#define x2 DFDAJKVOHKWIW
#define y2 PSFSAODSXVNMQ
#define LLINF 0x3f3f3f3f3f3f3f3fLL
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
using namespace std;
inline void read(int &x)
{
short negative=1;
x=0;
char c=getchar();
while(c<'0' || c>'9')
{
if(c=='-')
negative=-1;
c=getchar();
}
while(c>='0' && c<='9')
x=(x<<3)+(x<<1)+(c^48),c=getchar();
x*=negative;
}
ll quickpower(ll n,ll k){
ll ans=1;
while(k){
if(k%2){
ans*=n;
ans%=mod;
}
n*=n;
n%=mod;
k/=2;
}
return ans;
}
string int_to_string(int n)
{
string s="";
while(n)
{
int now=n%10;
s+=now+'0';
n/=10;
}
reverse(s.begin(),s.end());
return s;
}
int string_to_int(string s)
{
int n=0;
rep(i,s.size())
{
n*=10;
n+=s[i]-'0';
}
return n;
}
int h,w;
ll dp[5555][5555];
int k;
char c[5555][5555];
ll inv;
int main()
{
ios::sync_with_stdio(0);
inv=quickpower(3,mod-2);
inv%=mod;
cin>>h>>w>>k;
rep(i,h+1)rep(j,w+1)c[i][j]='N';
rep(i,k)
{
int x,y;
char op;
cin>>x>>y>>op;
c[x][y]=op;
}
dp[1][1]=1;
forn(i,1,h)
{
forn(j,1,w)
{
if(c[i-1][j]=='D'||c[i-1][j]=='X')dp[i][j]+=dp[i-1][j];
if(c[i-1][j]=='N')dp[i][j]+=dp[i-1][j]*2*inv;
dp[i][j]%=mod;
if(c[i][j-1]=='R'||c[i][j-1]=='X')dp[i][j]+=dp[i][j-1];
if(c[i][j-1]=='N')dp[i][j]+=dp[i][j-1]*2*inv;
dp[i][j]%=mod;
}
}
cout<<(dp[h][w]*quickpower(3,h*w-k))%mod<<endl;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
int main(){
int m, n;
cin >> n >> m;
vector<int> a(n);
for(int i = 0; i < n; i++){
cin >> a[i];
}
vector<int> used(n);
set<int> unused;
for(int i = 0; i <= n; i++){
unused.insert(i);
}
for(int i = 0; i < m; i++){
used[a[i]]++;
if(used[a[i]] == 1){
unused.erase(a[i]);
}
}
int mem = *unused.begin();
for(int i = m; i < n; i++){
used[a[i - m]]--;
if(used[a[i - m]] == 0){
unused.insert(a[i - m]);
}
used[a[i]]++;
if(used[a[i]] == 1){
unused.erase(a[i]);
}
mem = min(mem, *unused.begin());
}
cout << mem << endl;
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned ll
#define pi pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vb vector<bool>
#define vd vector<double>
#define vs vector<string>
#define vvi vector<vi>
#define ff first
#define ss second
#define pb push_back
#define vpi vector<pi>
#define vpll vector<pll>
#define umap unordered_map
#define uset unordered_set
#define all(x) x.begin(),x.end()
#define fr(i,j,n) for(int i=j;i<n;++i)
#define rfr(i,j,n) for(int i=j; i>=n;--i)
#define MOD 1000000007
#define INF INT_MAX
#define LINF LONG_LONG_MAX
#define mp make_pair
#define endl "\n"
#define sz size()
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
void solve(){
int n,m;
cin>>n>>m;
vi arr(n);
vvi pos(n+1);
fr(i,0,n+1){
// cin>>arr[i-1];
pos[i].pb(-1);
}
fr(i,0,n){
cin>>arr[i];
pos[arr[i]].pb(i);
}
fr(i,0,n+1){
// cin>>arr[i-1];
pos[i].pb(n);
}
fr(i,0,n+1){
fr(j,1,pos[i].sz){
if(pos[i][j]-pos[i][j-1]>m){
cout<<i<<endl;
return;
}
}
}
}
void pre() {
int t = 1;
// cin>>t;
while(t--){
solve();
// cout<<solve()<<endl;
}
}
int main() {
fastIO;
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
pre();
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
using namespace std;
vector<int> v(200, -1);
void print_answer(int x)
{
int cnt = 0;
vector<int> t;
for (int i = 0; i < 20; ++i)
{
if (x & (1 << i))
{
t.push_back(i + 1);
cnt++;
}
}
cout << cnt << " ";
for (int d : t) cout << d << " ";
cout << endl;
}
int main()
{
int n;
cin >> n;
vector<int> a(n);
rep(i,0,n-1) cin >> a[i];
rep(i,0,n-1) a[i] %= 200;
int m = min(n, 20);
int x = -1, y = -1;
for (int i = 1; i < (1 << m); ++i)
{
int p = 0;
for (int j = 0; j < m; ++j)
{
if (i & (1 << j))
{
p = (p + a[j]) % 200;
}
}
if (v[p] == -1)
v[p] = i;
else
{
x = v[p], y = i;
break;
}
}
if (x == -1)
cout << "No" << endl;
else
{
cout << "Yes" << endl;
print_answer(x);
print_answer(y);
}
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,l,r) for(int i=(l);i<(r);++i)
#define per(i,l,r) for(int i=(r)-1;i>=(l);--i)
#define dd(x) cerr<<#x<<"="<<x<<","
#define de(x) cerr<<#x<<"="<<x<<endl
//-------
const int N = 201;
int n, a[N], dp[N][N][4];
pair<int, int> go[N][N][4];
pair<vector<int>, vector<int>> gao() {
vector<int> B, C;
per(K, 1, 4) if (dp[n][0][K]) {
for (int i = n, j = 0, k = K; i > 0; --i) {
int pk, op; tie(pk, op) = go[i][j][k];
if (-1 == op) {
C.emplace_back(i);
j = (j + a[i]) % 200;
} else if (1 == op) {
B.emplace_back(i);
j = ((j - a[i]) % 200 + 200) % 200;
}
k = pk;
}
if (K == 3) return {B, C};
if (B.size() == n || C.size() == n) {
B.clear(), C.clear();
return {B, C};
}
if (B.empty() || C.empty()) {
vector<bool> used(n + 1, false);
for (auto p : B) used[p] = true;
for (auto p : C) used[p] = true;
rep(p, 1, n + 1) if (!used[p]) {
B.emplace_back(p);
C.emplace_back(p);
break;
}
}
return {B, C};
}
return {B, C};
}
int main() {
scanf("%d", &n);
rep(i, 1, n + 1) {
scanf("%d", a + i);
a[i] %= 200;
}
rep(i, 0, n + 1) rep(j, 0, 200) rep(k, 0, 4)
dp[i][j][k] = false;
dp[0][0][0] = true;
rep(i, 0, n) {
rep(j, 0, 200) rep(k, 0, 4) if (dp[i][j][k]) {
dp[i + 1][j][k] = true;
go[i + 1][j][k] = {k, 0};
}
rep(j, 0, 200) rep(k, 0, 4) {
if (0 == dp[i][j][k])
continue;
int ni = i + 1, nj, nk;
// add Ai
nj = (j + a[ni]) % 200, nk = k | 2;
if (0 == dp[ni][nj][nk]) {
dp[ni][nj][nk] = true;
go[ni][nj][nk] = {k, 1};
}
// minus Ai
nj = ((j - a[ni]) % 200 + 200) % 200, nk = k | 1;
if (0 == dp[ni][nj][nk]) {
dp[ni][nj][nk] = true;
go[ni][nj][nk] = {k, -1};
}
}
}
vector<int> B, C;
tie(B, C) = gao();
if (B.empty() || C.empty()) {
puts("No");
} else {
sort(B.begin(), B.end());
sort(C.begin(), C.end());
puts("Yes");
printf("%d", B.size());
for (auto b : B) printf(" %d", b);
puts("");
printf("%d", C.size());
for (auto c : C) printf(" %d", c);
puts("");
}
return 0;
}
|
#include<bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define repk(i,k,n) for (ll i = k; i < (ll)(n); ++i)
#define MOD 1000000007
typedef long long ll;
using namespace std;
int ans, cnt;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
vector<pair<int, string>> V(N);
rep(i, N) {
cin >> V[i].second >> V[i].first;
}
sort(V.begin(), V.end());
cout << V[N - 2].second << endl;
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
int main() {
int n;
cin >> n;
vector<int> a(n);
rep(i, n) cin >> a[i];
ll now = 0, s = 0, mx = 0;
ll ans = 0;
rep(i, n) {
s += a[i];
mx = max(mx, s);
ans = max(ans, now + mx);
now += s;
}
cout << ans << endl;
return 0;
} |
/*****************************
* Author :: Πρασαννα Κ. Ροι *
*****************************/
/***********************************
* Unus pro omnibus, omnes pro uno *
***********************************/
#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;
using namespace std::chrono;
#define __AcHiLlEs ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define __AnAkLuSmOs freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define int long long
#define span(a) begin(a), end(a)
template<typename t>
using vc = vector<t>;
vc<vc<int>> gph1;
vc<vc<int>> d, dp;
unordered_map<int, int> id;
int cnt(0);
void bfs(int u, int n) {
queue<int> q;
vc<int> dist(n + 1, -1);
dist[u] = 0;
q.push(u);
while (!q.empty()){
int v = q.front();
q.pop();
for (auto &i: gph1[v]) if (dist[i] == -1) {
dist[i] = dist[v] + 1;
q.push(i);
}
}
for (int i = 1; i <= n; i++) if (id[i])
d[id[u]][id[i]] = d[id[i]][id[u]] = dist[i];
}
int compute(int u, int vis, int k) {
int res(1e18);
if (vis == (1 << k) - 1) return 0;
if (~dp[u][vis]) return dp[u][vis];
dp[u][vis] = 0;
for (int i = 0; i < k; i++) if (!(vis & (1 << i)))
res = min(res, compute(i + 1, vis | (1 << i), k) + d[u][i + 1]);
return dp[u][vis] = res;
}
void solve() {
id.reserve(1 << 20);
id.max_load_factor(0.25);
int n, m, x, y;
cin >> n >> m;
gph1.assign(n + 1, vc<int>());
for (int i = 0; i < m; i++) cin >> x >> y, gph1[x].push_back(y), gph1[y].push_back(x);
int k, cnt(0);
cin >> k;
vc<int> a(k);
d.assign(k + 1, vc<int>(k + 1, -1));
for (auto &i: a) cin >> i, id[i] = ++cnt;
if (k == 1) return void(cout << 1 << "\n");
for (auto &i: a) bfs(i, n);
for (int i = 1; i <= k; i++)
for (int j = 1; j <= k; j++) if (d[i][j] == -1) return void(cout << -1 << "\n");
dp.assign(k + 1, vc<int>(1 << k, -1));
int res(LLONG_MAX);
for(int i = 1; i <= k; i++)
res = min(res, compute(i, 1 << (i - 1), k));
cout << res + 1 << "\n";
}
signed main() {
// auto start = high_resolution_clock::now();
__AcHiLlEs
int t(1);
// cin >> t;
for (int i = 1; i <= t; /*cout << "Case " << i << ": ",*/ solve(), i++);
// auto stop = high_resolution_clock::now();
// double duration = duration_cast<microseconds>(stop - start).count();
// cout << fixed << setprecision(4) << duration / 1000000 << "\n";
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int N,M, dist[1000000];
vector<int> lst[1000000];
vector< tuple<int,int,char> > A;
queue<int> q;
bitset<1000> bs[1000];
int main() {
scanf("%d %d", &N, &M);
for (int i = 0; i < M; ++i) {
int u,v; char c; scanf(" %d %d %c", &u, &v, &c); u--, v--;
bs[u][v] = bs[v][u] = true;
for (auto x: A) {
int a,b; char c1; tie(a,b,c1) = x;
if (c == c1) {
lst[u*N+a].push_back(v*N+b);
lst[v*N+b].push_back(u*N+a);
lst[a*N+u].push_back(b*N+v);
lst[b*N+v].push_back(a*N+u);
lst[u*N+b].push_back(v*N+a);
lst[v*N+a].push_back(u*N+b);
lst[b*N+u].push_back(a*N+v);
lst[a*N+v].push_back(b*N+u);
}
}
A.emplace_back(u,v,c);
}
memset(dist,-1,sizeof(dist));
q.emplace(N-1);
dist[N-1] = 0;
while (!q.empty()) {
int u = q.front(); q.pop();
for (int v: lst[u]) if (dist[v] == -1) {
dist[v] = dist[u] + 1;
q.push(v);
}
}
int ans = 2e9;
for (int i = 0; i < N; ++i) for (int j = 0; j < N; ++j) if (dist[i*N+j] != -1) {
if (i == j) ans = min(ans, dist[i*N+j] * 2);
if (bs[i][j]) ans = min(ans, dist[i*N+j] * 2 + 1);
}
if (ans == 2e9) ans = -1;
printf("%d", ans);
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int a,b;
cin>>a>>b;
int milk_solid=a+b;
if (milk_solid>=15 && b>=8){
cout<<"1";
}
else if(milk_solid>=10 && b>=3 ){
cout<<"2";
}
else if(milk_solid>=3 && b>=0){
cout<<"3";
}
else{
cout<<"4";
}
return 0;
} | #include<bits/stdc++.h>
namespace gengar
{
#pragma GCC optimize("Ofast")
using namespace std;
namespace TypeDef
{
#define int long long
#define itn int
#define uint unsigned long long
using Int=int64_t;
using uInt=uint64_t;
#define ld long double
#define P pair<int,int>
#define vt(tp) vector<tp>
#define vvt(nm,tp,h,w,n) vector<vector<tp>>nm((h),vector<tp>(w,n))
#define vvp vector<vector<P>>
#define hmap unordered_map
#define hset unordered_set
#define PQ priority_queue
};
namespace OthDef
{
#define all(x) x.begin(),x.end()
#define nsort(x) sort(all(x))
#define rsort(x) nsort(x);reverse(all(x))
#define unq(v) v.erase(unique(all(v)),v.end())
#define l_b(c,x) distance(c.begin(),lower_bound(all(c),(x)))
#define u_b(c,x) distance(c.begin(),upper_bound(all(c),(x)))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define spc ' '
#define pass
void CIN(){}
template<typename Car,typename... Cdr>
void CIN(Car&&car,Cdr&&...cdr){cin>>car;CIN(forward<Cdr>(cdr)...);}
template<class T>void drop(T x){cout<<(x)<<endl;exit(0);}
void dYes(){puts("Yes");exit(0);}
void dNo(){puts("No");exit(0);}
#define Bit(n) (1LL<<(n))
#define Bitall(n,i) for(int bit=0;bit<(1<<(int)(n));bit++)for(int i=0;i<(int)(n);i++)
#define Bitif(i) if(bit&(1<<i))
};
namespace RepDef
{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(a),__SIZE##_=(b);i<__SIZE##_;i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,n) for(int i=1,__SIZE##_=(n);i<__SIZE##_;i++)
#define repp(i,n) for(int i=0,__SIZE##_=(n);i<=__SIZE##_;i++)
#define per(i,n) for(int i=(n)-1;i>=0;i--)
#define pper(i,n) for(int i=(n)-1;i>=1;i--)
#define perr(i,n) for(int i=(n);i>=0;i--)
};
namespace MathDef
{
const int inf=Bit(60);
const int pi=acos(-1);
const int mod=1000000007;//998244353
#define myceil(a,b) ((a)+((b)-1))/(b)
#define scale(n) cout<<fixed<<setprecision(n)
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
int fact(int n){int f=n;pper(i,n){f*=i;f%=mod;}return f;}
template<class T>int chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>int chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
};
namespace AllDef
{
using namespace TypeDef;
using namespace OthDef;
using namespace RepDef;
using namespace MathDef;
};
using namespace AllDef;
};
using namespace gengar;
int32_t main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int a,b;cin>>a>>b;
if(a+b>=15&&b>=8)drop(1);
else if(a+b>=10&&b>=3)drop(2);
else if(a+b>=3)drop(3);
else drop(4);
return 0;
} |
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
#define mp make_pair
#define pb push_back
#define ll long long
//#define debug(x) ;
#define debug(x) cerr << #x << " = " << x << "\n";
ostream& operator<<(ostream& cerr, vector<ll> aux) {
cerr << "[";
for (auto e : aux) cerr << e << ' ';
cerr << "]";
return cerr;
}
const int maxN = 211;
int n;
int a[maxN], b[maxN];
bool used[maxN], sol[maxN];
void result(bool yes) {
cout << (yes ? "Yes" : "No");
exit(0);
}
bool canTile(int l, int r) {
int full = r - l;
int half = full / 2;
for (int i = l; i < r; i++) used[i] = false;
for (int i = 0; i < n; i++) {
int posX = a[i];
int posY = b[i];
bool outX = (posX < l || posX >= r);
bool outY = (posY < l || posY >= r);
if (outX && outY) continue;
if (outX ^ outY) {
// one in one out
if (posX != -1 && posY != -1) return false;
if (posX != -1) {
if (posX >= l + half) return false;
if (used[posX] || used[posX + half]) return false;
used[posX] = true;
used[posX + half] = true;
}
if (posY != -1) {
if (posY < l + half) return false;
if (used[posY] || used[posY - half]) return false;
used[posY] = true;
used[posY - half] = true;
}
} else {
// both in
if (posX >= l + half || posY < l + half) return false;
if (posY - posX != half) return false;
if (used[posX] || used[posY]) return false;
used[posX] = used[posY] = true;
}
}
return true;
}
int main()
{
//freopen("test.in", "r", stdin);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
if (a[i] != -1 && b[i] != -1 && a[i] >= b[i])
result(false);
}
sol[0] = true;
for (int i = 0; i < 2 * n; i++) {
if (!sol[i]) continue;
for (int j = i + 2; j <= 2 * n; j += 2) {
if (sol[j]) continue;
sol[j] |= canTile(i + 1, j + 1);
}
}
result(sol[2 * n]);
return 0;
}
|
// '-.-'
// () __.'.__
// .-:--:-. |_______|
// () \____/ \=====/
// /\ {====} )___(
// (\=, //\\ )__( /_____\
// __ |'-'-'| // .\ ( ) /____\ | |
// / \ |_____| (( \_ \ )__( | | | |
// \__/ |===| )) `\_) /____\ | | | |
// /____\ | | (/ \ | | | | | |
// | | | | | _.-'| | | | | | |
// |__| )___( )___( /____\ /____\ /_____\
// (====) (=====) (=====) (======) (======) (=======)
// }===={ }====={ }====={ }======{ }======{ }======={
// (______)(_______)(_______)(________)(________)(_________)
//
// Credits :- Joan G. Stark
//|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
//| AUTHOR - KASPAROVIAN |
//|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
#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 frr(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fr first
#define sc second
#define mk make_pair
#define endl '\n'
#define MOD 1000000007
#define in insert
#define sz(x) (ll)(x).size()
#define mem(a,b) memset(a,b,sizeof(a))
#define int long long
#define runtime() ((double)clock() / CLOCKS_PER_SEC)
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pi;
typedef pair<int,pi> ppi;
typedef vector<vi> graph;
template<class T> void mxi(T & a, const T & b) { a = max(a, b); }
template<class T> void mni(T & a, const T & b) { a = min(a, b); }
ld EPS=1e-9;
mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count());
#define SHUF(v) shuffle(all(v), RNG);
// Use mt19937_64 for 64 bit random numbers.
void solve()
{
int n; cin>>n;
n*=2;
int ans=0;
for(int i=1;i*i<=n;i++)
{
if(n%i==0)
{
int val=(int)(n/i)-(i+1);
if(abs(val)%(2)==0)ans++;
if(i*i!=n)
{
int d=n/i;
val=(int)(n/d)-(d+1);
if(abs(val)%(2)==0)ans++;
}
}
}
cout<<ans<<endl;
}
signed main()
{
fast;
int t,tab;
t=1;
tab=t;
while(t--)
{
//cout<<"Case #"<<(tab-t)<<": ";
solve();
}
cerr<<runtime();
}
//APPROACHING A QUESTION
//+ Think of binary search (max of min etc also if n<=2*10^5)
//+ Think of common dp states (Even if it appears as maths but constraints are small)
//+ Check constraints
//+ Keep calm and enjoy the question
//+ Be sure to remove MOD from binpow (if needed)
//+ Try bidirectional analysis for constructive questions
//+ If given some sequence try thinking of prefix sums
//+ If constraints are too large maybe its simple maths
//+ In questions with binary operations think of bits independently and also the change pattern
//+ If two or more binary operations are given mostly there is a relation between them and an arithmatic operator |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INFint = 1e9+1;
const ll INFll = (ll)1e18+1;
const int MOD=1e9+7;
int main(){
int N;
cin>>N;
vector<pair<pair<ll,ll>, int>> py(N), px(N);
for (int i = 0; i < N; i++) {
int x, y;
cin>>x>>y;
py[i] = {{y, x}, i};
px[i] = {{x, y}, i};
}
set<int> st;
sort(py.begin(), py.end());
sort(px.begin(), px.end());
vector<pair<int,int>> kouho;
if (st.find(py[0].second) == st.end()) {
st.insert(py[0].second);
kouho.push_back({py[0].first.second, py[0].first.first});
}
if (st.find(py[1].second) == st.end()) {
st.insert(py[1].second);
kouho.push_back({py[1].first.second, py[1].first.first});
}
if (st.find(py[N - 1].second) == st.end()) {
st.insert(py[N - 1].second);
kouho.push_back({py[N - 1].first.second, py[N - 1].first.first});
}
if (st.find(py[N - 2].second) == st.end()) {
st.insert(py[N - 2].second);
kouho.push_back({py[N - 2].first.second, py[N - 2].first.first});
}
if (st.find(px[0].second) == st.end()) {
st.insert(px[0].second);
kouho.push_back(px[0].first);
}
if (st.find(px[1].second) == st.end()) {
st.insert(px[1].second);
kouho.push_back(px[1].first);
}
if (st.find(px[N - 1].second) == st.end()) {
st.insert(px[N - 1].second);
kouho.push_back(px[N - 1].first);
}
if (st.find(px[N - 2].second) == st.end()) {
st.insert(px[N - 2].second);
kouho.push_back(px[N - 2].first);
}
vector<ll> ans;
for (int i = 0; i < (int)kouho.size(); i++) {
for (int j = i + 1; j < (int)kouho.size(); j++) {
ans.push_back(max(abs(kouho[i].first - kouho[j].first), abs(kouho[i].second - kouho[j].second)));
}
}
sort(ans.rbegin(), ans.rend());
// for (int i = 0; i < (int)ans.size(); i++) cout << ans[i] << " ";
// cout << endl;
cout << ans[1] << endl;
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
#define DONTSYNC ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) //dont use stdio with iostream functions //input and output are out of order now!
#define TEST unsigned long long T; cin>>T; while(T--) //loop over each testcase
#define endl "\n"
#define fori(a,start,end) for(int a=start;a<end;a++)
#define forl(a,start,end) for(long long a=start;a<end;a++)
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
const double PI = acos(-1);
void solve(){
/* code */
int n; cin>>n;
vll x(n),y(n);
fori(i,0,n){
cin>>x[i].fi>>y[i].fi;
x[i].se=i; y[i].se=i;
}
sort(all(x)); sort(all(y));
// vl res({abs(x[n-1]-x[0]),abs(x[n-2]-x[0]),abs(x[n-1]-x[1]),abs(y[n-1]-y[0]),abs(y[n-2]-y[0]),abs(y[n-1]-y[1])});
vector<pair<ll,pll>> res;
res.push_back({abs(x[n-1].fi-x[0].fi),{x[n-1].se,x[0].se}});
res.push_back({abs(x[n-2].fi-x[0].fi),{x[n-2].se,x[0].se}});
res.push_back({abs(x[n-1].fi-x[1].fi),{x[n-1].se,x[1].se}});
res.push_back({abs(y[n-1].fi-y[0].fi),{y[n-1].se,y[0].se}});
res.push_back({abs(y[n-2].fi-y[0].fi),{y[n-2].se,y[0].se}});
res.push_back({abs(y[n-1].fi-y[1].fi),{y[n-1].se,y[1].se}});
sort(all(res)); set<pll> ss;
if(res[5].se.fi<res[5].se.se) ss.insert({res[5].se.fi,res[5].se.se});
else ss.insert({res[5].se.se,res[5].se.fi});
for(int i=5;~i;i--){
auto [val,p]=res[i];
if(p.fi>p.se) swap(p.fi,p.se);
if(ss.find(p)!=ss.end()){
continue;
}else{
cout<<val<<endl;
return;
}
}
}
int main()
{
DONTSYNC;
// TEST
solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define inf 1000000001
typedef long l;
typedef long long ll;
const ll INF = 1e18L + 5;
# define MOD 1000000007
# define PI 3.14
#define vi vector<int>
#define vl vector<l>
#define vll vector<ll>
#define pb push_back
#define pob pop_back
#define f first
#define s second
#define ml map<l,l>
#define mll map<ll,ll>
#define mcl map<char,ll>
# define umll unordered_map<ll,ll,custom_hash>
# define umcl unordered_map<char,l>
#define pll pair<ll,ll>
#define mp make_pair
# define forl(i,range) for(l i=0;i<range;i++)
# define forll(i,range) for(ll i=0;i<range;i++)
// int ans=upper_bound(start,end ,value)-start;
// auto itr=uper_bound(start,end ,value)-vector.begin();
// for (ll i = 0; i < s1.size() && j < s2.size(); i++) if (s1[i]==s2[j]) j++;//subsequence
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
// http://xorshift.di.unimi.it/splitmix64.c
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = std::chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
ll myceil(ll num,ll den)
{
if ((num >= 0 and den > 0) or ( num <= 0 and den < 0))
return num%den == 0 ? num/den : num/den + 1;
return num / den;
}
ll myfloor(ll num,ll den)
{
if ((num >= 0 and den > 0) or ( num <= 0 and den < 0))
return num%den == 0 ? num/den : num/den;
int ans = num / den;
return num % den == 0 ? ans : ans - 1;
}
void dfs(vector<vector<ll>> &v, vector<ll> &df, vll &seen, ll i){ //Also outputed resultant dfs
df.pb(i);
for(ll j=0; j<v[i].size(); j++){
if(seen[v[i][j]]==0){seen[v[i][j]]=seen[i]; dfs(v, df, seen, v[i][j]);}
}
}
/* ************************************************************************************************************** */
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n,m;
cin>>n>>m;
vector<vll>v(n);
forll(i,m){
ll x,y;
cin>>x>>y;
v[x-1].pb(y-1);
}
ll ans=0;
forll(i,n){
vll seen(n);vll df;
seen[i]=1;
dfs(v,df,seen,i);
ans+=df.size();
}
cout<<ans<<"\n";
}
| #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vs = vector<string>;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vpi = vector<pair<int, int>>;
using vpl = vector<pair<ll, ll>>;
using ld = double;
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define ins insert
#define nl "\n"
const ll MOD = 998244353;
ll add(ll x, ll y) {
x += y;
if (x >= MOD) return x - MOD;
return x;
}
ll sub(ll x, ll y) {
x -= y;
if (x < 0) return x + MOD;
return x;
}
ll mult(ll x, ll y) {
return (x * y) % MOD;
}
template<typename T> T signum(T a) {
return (a > 0) - (a < 0);
}
template<typename T> T cmp(T a, T b) {
return signum(a-b);
}
template<typename T> bool mins(T& lhs , T& rhs) {
if (rhs < lhs) {
lhs = rhs;
return true;
}
return false;
}
template<typename T> bool maxs(T& lhs , T& rhs) {
if (rhs > lhs) {
lhs = rhs;
return true;
}
return false;
}
const int MAX = INT_MAX;
void gks(int tc) {
printf("Case #%d: ", tc);
};
vector<bool> v;
ll ans = 0;
vector<vector<int>> g;
void dfs(int r) {
v[r] = true;
ans += 1;
for (auto neigh : g[r]) {
if (!v[neigh]) {
dfs(neigh);
}
}
}
int main() {
int n, m;
cin>>n>>m;
g.resize(n);
for (int i = 0;i < m;++i) {
int u, v;
cin>>u>>v;
--u, --v;
g[u].push_back(v);
}
v.resize(n);
for (int i =0 ;i < n;++i) {
dfs(i);
fill(all(v), false);
}
cout<<ans<<nl;
}
|
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
ll n, d; cin>> n>> d;
ll a[n+n+1]={0};
for(ll i=1; i<=n+n; i++){
if(i<=n+1){
a[i]=i-1;
}
else{
ll k=i-n;
a[i]=n-k+1;
}
}
ll ans=0;
for(ll i=0; i<=n+n; i++){
if(i-d<=n+n && i-d>=0){
ans+=a[i]*a[i-d];
}
}
cout<< ans<< 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;
}();
const double PI = acos(-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) double 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<double, double>;
using vd= vector<double>;
using vb= vector<bool>;
using vi= vector<int>;
using vvi= vector<vi>;
using vs= vector<string>;
#define endl "\n"
/* foreach x in 2..n*2
* ans+=(number of pairs a+b==x) * (number of pairs c+d+K==x)
*
* if x<=n+1
* p1=x-1 (since we have a pair foreach a=1..n)
* else
* (we have a pair foreach a=x-n .. n
*
*/
void solve() {
cini(n);
cini(k);
int ans=0;
for(int aplusb=2; aplusb<=n+n; aplusb++) {
/* number of pairs a+b==aplusb */
int miD=max(1LL, aplusb-n);
int maD=min(n, aplusb-1);
int p1=maD-miD+1;
/* number of pairs c+d+k==aplusb */
int aplusb2=aplusb-k;
miD=max(1LL, aplusb2-n);
maD=min(n, aplusb2-1);
int p2=max(0LL, maD-miD+1);
//cerr<<"aplusb="<<aplusb<<" p1="<<p1<<" p2="<<p2<<endl;
ans+=p1*p2;
}
cout<<ans<<endl;
}
signed main() {
solve();
}
// FIRST THINK, THEN CODE
// DO NOT JUMP BETWEEN PROBLEMS
|
/* Created By::Shashwat Singh
* (shashwa_t)
*
* Alwayz look for edge cases(n=1 or 1111 or similar mutiple values).
* Look for integer overflow.(>=10^6);
* Look for out of bounds(array);
*/
# include<bits/stdc++.h>
# define ll long long
# define pb push_back
# define endl "\n"
# define mod 1000000007ll
# define pi 3.1415926535897932384626
using namespace std;
void solve()
{
long long n,x=-1; cin>>n;
string s,t; cin>>s>>t;
set<long long>ind;
for(int i=0;i<n;i++)
{
if(s[i]=='1')
ind.insert(i);
}
long long ans=0;
for(int i=0;i<n;i++)
{
if(i<=x)
{
s[i]='0';
if(s[i]!=t[i])
{
auto it=ind.upper_bound(x);
if(it!=ind.end())
{
x=*it;
ans+=(x-i);
}
else
{
cout<<-1; return;
}
}
}
else if(s[i]!=t[i])
{
auto it=ind.upper_bound(i);
if(it!=ind.end())
{
x=*it;
ans+=(x-i);
}
else
{
cout<<-1; return;
}
}
}
cout<<ans;
}
int main()
{
# ifndef ONLINE_JUDGE
freopen("input1.txt","r",stdin);
freopen("output1.txt","w",stdout);
# endif
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
solve();
cout<<endl;
return 0;
} | #include <bits/stdc++.h>
#define pb push_back
#define db1(x) cout << #x << " = " << x << endl
#define db2(x, y) cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define paging cout << "-----------------------" << endl
using namespace std;
void localFileInput() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll mod = 998244353;
const int INF = 0x3f3f3f3f;
const int N = 1e5+10;
int a, b, c, d;
void sol() {
cin >> a >> b >> c >> d;
a = a * d - b * c;
cout << a << endl;
}
int main()
{
// localFileInput();
// int _; scanf("%d", &_); while(_ --)
sol();
return 0;
} |
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
char In[1 << 20], *ss = In, *tt = In;
#define getchar() (ss == tt && (tt = (ss = In) + fread(In, 1, 1 << 20, stdin), ss == tt) ? EOF : *ss++)
ll read() {
ll x = 0, f = 1; char ch = getchar();
for(; ch < '0' || ch > '9'; ch = getchar()) if(ch == '-') f = -1;
for(; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + int(ch - '0');
return x * f;
}
int read01() {
char ch = getchar();
for(; ch != '0' && ch != '1'; ch = getchar());
return ch - '0';
}
const int MAXN = 5e5 + 5;
int n, a[MAXN], b[MAXN], qa[MAXN], hda, tla, qb[MAXN], hdb, tlb, to[MAXN];
ll ans;
vector<int> le, ri;
int main() {
n = read();
for(int i = 1; i <= n; i++) a[i] = read01();
for(int i = 1; i <= n; i++) b[i] = read01();
hda = hdb = 1; tla = tlb = 0;
for(int i = 1; i <= n; i++) {
if(a[i]) {
if(hdb <= tlb) {
to[i] = qb[hdb++]; le.push_back(i);
} else qa[++tla] = i;
}
if(b[i]) {
if(hda <= tla) {
to[qa[hda]] = i; ri.push_back(qa[hda]);
hda++;
} else qb[++tlb] = i;
}
}
if(hdb <= tlb || hda <= tla) {
printf("-1\n");
return 0;
}
if(le.size()) ans += le[0] - to[le[0]];
for(int i = 1; i < (int)le.size(); i++) {
ans += le[i] - max(to[le[i]], le[i-1] + 1);
}
if(ri.size()) ans += to[ri[ri.size()-1]] - ri[ri.size()-1];
for(int i = (int)ri.size() - 2; i >= 0; i--) {
ans += min(to[ri[i]], ri[i+1] - 1) - ri[i];
}
printf("%lld\n", ans);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++)
{
cin >> a[i];
}
int ans = INT_MAX;
for (int i = 0; i < (1<<(n-1)); i++)
{
int in, out;
in = out = 0;
for (int j = 0; j < n; j++)
{
in |= a[j];
if (i&1<<j)
{
out ^= in;
in = 0;
}
}
out ^= in;
ans = min(ans, out);
}
cout << ans << endl;
}
|
#include<bits/stdc++.h>
using namespace std;
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')';}
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) {os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#define int long long
template<typename T>
void dbg_a(T *a,int l,int r){cout<<" {";for(int i = l;i<r;i++) cout<<a[i]<<", ";cout<<a[r]<<"}"<<endl;}
typedef long long ll;
template<typename T = int>
inline T read(){
T f = 1,r = 0;
char c = getchar();
while(c<'0'||c>'9'){if(c == '-') f = -1; c = getchar();}
while(c>='0'&&c<='9'){ r = (r<<1) + (r<<3) + c - '0';c = getchar();}
return f*r;
}
typedef pair<int,int> PII;
#define fi first
#define se second
#define mst(a,b) memset(a,b,sizeof(a))
#define For(i,a,b) for(int i = a;i<=b;i++)
#define For_(i,a,b) for(int i = a;i>=b;i--)
#define _for(i,a) for(int i = 0;i<a;i++)
#define All(x) x.begin(),x.end()
// For(i,1,n) For(j,1,m) printf("f[%lld][%lld] = %lld\n",i,j,f[i][j]);
const int N = 2e5 + 10,M = 2*N + 10,INF = 0x3f3f3f3f;
const int mod = 998244353;
int h[N],ne[M],e[M],idx;
void add(int a,int b){
e[++idx] = b;ne[idx] = h[a];h[a] = idx;
}
int exgcd(int a,int b,int &x,int &y){
int d = a;
if(b){ d = exgcd(b, a%b, y, x);y -= (a/b)*x;}
else{x = 1;y = 0;}
return d;
}
int inv(int a,int mo){
int x,y;
int d = exgcd(a,mo,x,y);
return d == 1 ? (x + mo)%mo : -1;//-1表示不存在,并对逆元调整
}
int gcd(int a,int b){
return b?gcd(b,a%b):a;
}
bool merge(int a1,int m1,int a2,int m2,int &A,int &mo){
int c = (a2 - a1),d = gcd(m1,m2);
if(c % d) return 0;//gcd(m1,m2)|(a2 - a1)时才有解
c = (c%m2 + m2)%m2;//将c变为[0,m2)之间的数
c /= d;m1 /= d;m2 /= d;//两边除以d
c = c*inv(m1,m2) % m2;//将m1/d 移到右边
mo = m1*m2*d;// mo = m1 * m2 /d
A = (c*m1%mo*d%mo + a1)%mo;
return 1;
}
int EXCRT(int n,int a[],int mo[]){
int a1 = a[1],m1 = mo[1],A,Mo;
for(int i = 2;i<=n;i++){
if(!merge(a1,m1,a[i],mo[i],A,Mo)) return -1;//不合法
a1 = A;m1 = Mo;
}
return (a1 + m1)%m1;
}
int n;
void solve(){
int x,y,p,q;
cin>>x>>y>>p>>q;
int a[3] = {},mo[3] = {};
int ans = 3e18;
For(i,x,x+y-1){
For(j,p,p+q-1){
a[1] = i,mo[1] = 2*(x+y);
a[2] = j,mo[2] = p + q;
int res = EXCRT(2,a,mo);
if(res == -1) continue;
ans = min(res,ans);
}
}
if(ans == 3e18)cout<<"infinity"<<"\n";
else cout<<ans<<"\n";
}
signed main(){
int T = 1;
T = read();
while(T--) solve();
system("pause");
return 0;
}
| #include <bits/stdc++.h>
// clang-format off
using namespace std; using ll =long long; using ull = unsigned long long; using pll = pair<ll,ll>; const ll INF=9e18;
void print0() {}
template<typename Head,typename... Tail> void print0(Head head,Tail... tail){cout<<fixed<<setprecision(15)<<head;print0(tail...);}
void print() { print0("\n"); }
template<typename Head,typename... Tail>void print(Head head,Tail... tail){print0(head);if(sizeof...(Tail)>0)print0(" ");print(tail...);}
using i128 = __int128_t;
// clang-format on
// 最大公約数
ll gcdf(ll a, ll b) {
if (b == 0) {
return a;
}
return gcdf(b, a % b);
}
// ax + by = gcd(a, b) となるような (x, y) を求める
// https://qiita.com/drken/items/0c88a37eec520f82b788
ll extgcd(ll a, ll b, ll& x, ll& y) {
if (b == 0) {
x = 1;
y = 0;
//return abs(a);
return a;
}
ll d = extgcd(b, a % b, y, x);
y -= a / b * x;
return d;
}
ll divceil(ll x, ll y){
return (x+y-1)/y;
}
void solve() {
ll x, y, p, q;
cin >> x >> y >> p >> q;
ll a = 2 * x + 2 * y;
ll b = p + q;
ll g = gcdf(a, b);
ll lcm = a * b / g;
// lcmは2e18くらい
ll ans = INF;
for (ll i = 0; i < y; i++) {
for (ll j = 0; j < q; j++) {
// (2x+2y)k+x+i=(p+q)m+p+j
// ak+x+i=bm+p+j
// ak=bm+c
// ak+bl=c (l=-m)
// これは一次不定方程式で、c%gcd(a,b) == 0 なら拡張ユークリッドの互除法により解を求められる https://qiita.com/drken/items/b97ff231e43bce50199a
ll c = p - x - i + j;
if (c % g != 0) continue;
ll k, l;
extgcd(a, b, k, l);
ll ratio = c / g;
k = k * ratio;
l = l * ratio;
ll m = -l;
// ある時刻から LCM(a,b) 秒後には、高橋君と電車は元の時刻と同じ状態になる.
// 周期を左右にずらすことで「k,mが0以上で最小」になるよう調整する
// (事実上CRTをやっていると思われる)
{
// 周期を右にずらす
// k+f*z >= 0
// z>=-k/f
ll za = -i128(k) * a / lcm + 1;
ll zb = -i128(m) * b / lcm + 1;
ll z = max(za, zb);
k += z * (lcm/a);
m += z * (lcm/b);
}
{
// 周期を左にずらしてk,mを0以上で最小にする
// k-v*lcm/a >= 0
// v <= k*a/lcm;
ll za = -i128(k) * a / lcm;
ll zb = -i128(m) * b / lcm;
ll z = min(za, zb);
k += z * (lcm / a);
m += z * (lcm / b);
}
ll r = a * k + x + i;
ans = min(ans, r);
}
}
if (ans == INF) {
print("infinity");
} else {
print(ans);
}
}
int main() {
ll t;
cin >> t;
for (ll i = 0; i < t; i++) {
solve();
}
}
|
#include<bits/stdc++.h>
using namespace std;
#define test_case int t;cin>>t;while(t--)
const double pi=acos(-1.0);
void RAmadAN()
{
/*
cout<<fixed<<setprecision(2);
itoa to convert any system itoa(n,bin,2)
*/
std::ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
long long gcd(long long a,long long b)
{
return a ? gcd(b%a,a):b;
}
long long lcm(long long a,long long b)
{
return a/gcd(a,b)*b;
}
int dx_r[]= {1, 0, -1, 0, -1, 1, -1, 1};
int dy_c[]= {0, 1, 0, -1, -1, 1, 1, -1};
int main()
{
/*freopen("","r",stdin);
freopen("","w",stdout);*/
RAmadAN();
int a,b;
cin>>a>>b;
cout<<(2*a+100)-b;
return 0;
}
| #include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque>
#include <string>
using namespace std;
int main()
{
int a, b;
scanf("%d%d", &a, &b);
int total = a * 2 + 100;
int left = total - b;
printf("%d\n", left);
return 0;
}
|
#include <bits/stdc++.h>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define mod 998244353
//#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second
#define bs(yup,x) binary_search(yup.begin(),yup.end(),x) //it will return bollean value
#define lb(yup,x) lower_bound(yup.begin(),yup.end(),x) //it will return the adress of the number which is equal to or just greater than x ,and if it is equal to yup.end() than their in no such number exist
#define ub(yup,x) upper_bound(yup.begin(),yup.end(),x)
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
using namespace std;
const long long N=1000005, INF=2000000000000000000;
int power(int a, int b, int p)
{
if(a==0)
return 0;
int res=1;
a%=p;
while(b>0)
{
if(b&1)
res=(res*a)%p;
b>>=1;
a=(a*a)%p;
}
return res;
}
vi prime;
bool isprime[N];
void pre()
{
for(int i=2;i<N;i++)
{
if(isprime[i])
{
for(int j=i*i;j<N;j+=i)
isprime[j]=false;
prime.pb(i);
}
}
return;
}
int32_t main()
{
IOS;
//fill(isprime, true);
//pre();
int qu=1;
//cin>>qu;
while(qu--)
{
int n;
cin>>n;
int a[n];
rep(i,0,n) cin>>a[i];
sort(a,a+n);
int pr1[n],pr2[n],sum=0;
pr1[0]=0;
pr2[0]=0;
int pr3[n];
rep(i,1,n)
{
pr1[i]=a[i]-a[i-1];
pr2[i]=pr2[i-1]+pr1[i];
sum+=pr2[i];
}
// rep(i,0,n)cout<<pr2[i]<<" ";
//cout<<"\n";
int ans=sum;
pr3[0]=sum;
rep(i,1,n) pr3[i]=pr3[i-1]-pr2[i],ans+=pr3[i];
//cout<<"\n";
//cout<<sum<<" ";
rep(i,0,n)
{
ans-=(n-i-1)*pr2[i];
}
cout<<ans;
}
}
| #include<bits/stdc++.h>
#define fi first
#define se second
#define io std::ios::sync_with_stdio(false)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
const ll mod=1e9+7,INF = 0x3f3f3f3f;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
ll exgcd(ll a, ll b, ll &x, ll &y) {if(!b) {x = 1; y = 0; return a;}ll r = exgcd(b, a % b, x, y);ll tmp = x; x = y, y = tmp - a / b * y;return r;}
ll qpow(ll a,ll n){ll r=1%mod;for (a%=mod; n; a=a*a%mod,n>>=1)if(n&1)r=r*a%mod;return r;}
ll qpow(ll a,ll n,ll P){ll r=1%P;for (a%=P; n; a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll EX_BSGS(ll a,ll b,ll p){if(b == 1) return 0;map<ll,ll> pw;ll cnt = 0, t = 1, s, x, m;for(ll d = gcd(a, p); d != 1; d = gcd(a, p)){if(b % d) return -1;++cnt, b /= d, p /= d, t = 1LL * t * a / d % p;
if(b == t) return cnt;}s = b, m = sqrt(p) + 1;for(ll i = 0; i < m; ++i){pw[s] = i;s = 1LL * s * a % p;}x = qpow(a, m, p), s = t;for(ll i = 1; i <= m; ++i){s = 1LL * s * x % p;if(pw.count(s)) return i * m - pw[s] + cnt;
}return -1;} //拔山盖世!
/*const int maxn=3e5+10;
ll _next[maxn*2],head[maxn],tot,to[maxn*2],w[2*maxn];
void add(ll x,ll y,ll z)
{
_next[++tot]=head[x],head[x]=tot,to[tot]=y,w[tot]=z;
//_next[++tot]=head[y],head[y]=tot,to[tot]=x;
}*/
const int maxn=2e5+10;
ll a[maxn],b[maxn];
int id[maxn];
bool cmp(int x,int y)
{
return 2*a[x]+b[x]>2*a[y]+b[y];
}
int main()
{
int n;
cin>>n;
ll sum=0;
for(int i=1;i<=n;i++)
{
cin>>a[i]>>b[i];
id[i]=i;
sum+=a[i];
}
ll ans=0;
sort(id+1,id+1+n,cmp);
for(int i=1;i<=n;i++)
{
int now=id[i];
ans+=b[now]+a[now];
sum-=a[now];
if(ans>sum)
{
cout<<i<<endl;
break;
}
}
}
|
#include<cstdio>
#include<iostream>
#define re register
using namespace std;
long long n,k;
long long sum=3;
long long a=1,b,c;
template<typename T>
inline void read(T&x){
x=0;re bool f=true;re char c=getchar();
while(c<'0'||c>'9'){if(c=='-') f=false;c=getchar();}
while(c>='0'&&c<='9'){x=(x<<3)+(x<<1)+(c^48);c=getchar();}
x=f?x:-x;
}
template<typename T>
inline void write(T x){
if(x<0) x=~x+1,putchar('-');
if(x>9) write(x/10);
putchar(x%10+'0');
}
int main(){
read(n),read(k);
while(1){
long long res,tmp;
if(sum<=n+2) res=(sum-1)*(sum-2)/2;
else if(n+2<sum&&sum<=2*n+1){
tmp=2*n+1-sum;
res=(tmp+1+n)*(n-tmp)/2+(2*n-tmp-1)*tmp/2;
}
else{
tmp=3*n-sum+1;
res=tmp*(tmp+1)/2;
}
// if(k<1000000000000000000/2) cout<<"k: "<<k<<" res: "<<res<<" sum: "<<sum<<endl;
if(k<=res) break;
k-=res;
sum++;
}
// cout<<"k: "<<k<<" sum: "<<sum<<endl;
while(1){
if(sum-a<=2*n) break;
a++;
}
// cout<<"a: "<<a<<endl;
if(a==1){
if(sum<=n+2){
long long i=sum-2;
while(k>i){
k-=i;
a++,i--;
}
}
else if(n+2<sum&&sum<=2*n+1){
long long i=2*n+2-sum;
while(1){
long long res;
if(i>n) res=2*n-i;
else res=i;
if(k<=res) break;
k-=res;
a++,i++;
}
}
}
else{
long long i=1;
while(k>i){
k-=i;
i++,a++;
}
}
write(a),putchar(' ');
if(sum-a<=n+1) b=1,c=sum-a-1;
else b=sum-a-n,c=n;
k--;
while(k--) b++,c--;
write(b),putchar(' '),write(c);
return 0;
} | #include <bits/stdc++.h>
#define int long long
using namespace std;
main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int n, k; cin >> n >> k;
int real = k;
vector <vector <int>> f(4, vector <int> (3 * n + 1)), sum(4, vector <int> (3 * n + 1));
for (int i = 0; i <= 3 * n; ++ i) sum[0][i] = 1;
/// f[i][j] : chọn i thằng, tổng thu được j
for (int i = 1; i <= 3; ++ i){
for (int j = 1; j <= 3 * n; ++ j){
if (j > n) f[i][j] = (sum[i - 1][j - 1] - sum[i - 1][j - n - 1]);
else f[i][j] = sum[i - 1][j - 1];
sum[i][j] += sum[i][j - 1] + f[i][j];
}
}
int en;
for (int i = 1; i <= 3 * n; ++ i){
if (k <= f[3][i]){
en = i;
break;
}
k -= f[3][i];
}
for(int i = 1; i <= n; ++ i){
if (en - i > 2 * n) continue;
int dau = max(1ll, en - i - n);
int cuoi = min(n, en - i - 1);
if (k > cuoi - dau + 1){
k -= (cuoi - dau + 1);
continue;
}
int x = dau + k - 1;
int y = en - x - i;
cout << i << " " << x << " " << y;
return 0;
}
}
|
/*
ID: hedichehaidar
TASK: photo
LANG: C++11
*/
#include<bits/stdc++.h>
typedef long long ll;
ll gcd(ll a , ll b) {return b ? gcd(b , a % b) : a ;} // greatest common divisor (PGCD)
ll lcm(ll a , ll b) {return (a * b) / gcd(a , b);} // least common multiple (PPCM)
#define ss second
#define ff first
#define all(x) (x).begin() , (x).end()
#define pb push_back
#define vi vector<int>
#define vii vector<pair<int,int>>
#define vl vector<ll>
#define vll vector<pair<ll,ll>>
#define pii pair<int,int>
#define pll pair<ll,ll>
using namespace std;
const int INF = 1000*1000*1000; // 1 e 9
const int MOD = INF + 7;
const double EPS = 0.000000001; // 1 e -9
const ll inf = (ll)1e18;
ll powe(ll u , ll v , ll mod = MOD){
ll acc = u;
ll res = 1;
while(v){
if(v % 2){
res = (res * acc)%mod;
}
v /= 2;
acc = (acc * acc)%mod;
}
return res;
}
int main() {
//ifstream fin ("race.in");
//ofstream fout ("race.out");
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int x , y ; cin>>x>>y;
double res = ((double)(x - y) / x) * 100;
printf("%.9f\n" , res);
return 0;
}
| #include <stdio.h>
#include <iostream>
#include <vector>
// #include <bits/stdc++.h>
#include <queue>
#include <algorithm>
#include <string>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;
#define rep(i,k,n) for(ll i=k; i<(ll)(n); i++)
int main() {
double a,b; cin >> a >> b;
cout << std::fixed << std::setprecision(15) << (a-b)*100/a << endl;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b){return b? gcd(b, a % b): a;}
const int N = 73;
int prime[N], vis[N], cnt = 0;
ll l, r, dp[1 << 21];
void init(void) {
for (int i = 2; i < N; i++) {
if (vis[i]) continue;
prime[++cnt] = i;
for (int j = i; j < N; j += i) vis[j] = 1;
}
prime[0] = 1;
}
int main(void){
init();
scanf("%lld%lld", &l, &r);
dp[0] = 1;
for (ll i = l; i <= r; i++) {
int now = 0;
for (int j = 0; j < cnt; j++) {
if (i % prime[j + 1] == 0) {
now += (1 << j);
}
}
for (int i = 0; i < (1 << 20); i++) {
if ((i & now) > 0) continue;
dp[now | i] += dp[i];
}
}
ll ans = 0;
for (int i = 0; i < (1 << 20); i++) {
ans += dp[i];
}
printf("%lld\n", ans);
return 0;
}
| #include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long ll;
using namespace std;
const int maxn = 1e2 + 50, INF = 0x3f3f3f3f;
inline ll read () {
register ll x = 0, w = 1;
register char ch = getchar ();
for (; ch < '0' || ch > '9'; ch = getchar ()) if (ch == '-') w = -1;
for (; ch >= '0' && ch <= '9'; ch = getchar ()) x = x * 10 + ch - '0';
return x * w;
}
ll a, b, ans, pw[maxn];
int sum, cnt[maxn];
bool vis[maxn], black[maxn][maxn];
inline ll GCD (register ll a, register ll b) {
return b == 0 ? a : GCD (b, a % b);
}
inline void DFS (register int now) {
if (now == b - a + 2) return ans ++, void ();
if (vis[now]) DFS (now + 1);
else {
DFS (now + 1);
register bool flag = 1;
for (register int i = 1; i <= now - 1; i ++)
if (vis[i] && black[now][i]) flag = 0;
if (flag) vis[now] = 1, DFS (now + 1), vis[now] = 0;
}
}
int main () {
a = read(), b = read(), pw[0] = 1;
for (register int i = 1; i <= 62; i ++) pw[i] = pw[i - 1] * 2ll;
for (register ll i = a; i <= b; i ++) {
for (register ll j = a; j <= b; j ++) {
if (GCD (i, j) != 1) black[i - a + 1][j - a + 1] = 1;
else cnt[i - a + 1] ++;
}
if (cnt[i - a + 1] == b - a) sum ++, vis[i - a + 1] = 1;
}
DFS (1), printf ("%lld\n", ans * pw[sum]);
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pf(a) cout << a << endl
#define sz(x) (int)(x).size()
#define pb push_back
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
void go() {
ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
}
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;
void solve() {
int n;cin >> n;
vector<int> a(n);for(int i = 0;i < n;i++) cin >> a[i];
vector<int> b(n);for(int i = 0;i < n;i++) cin >> b[i];
vector<int> c(n);for(int i = 0;i < n;i++) cin >> c[i];
unordered_map<int, int> mp;
for(int i = 0;i < n;i++) mp[c[i]]++;
unordered_map<int, ll> store;
for(int i = 0;i < n;i++) store[b[i]] += mp[i + 1];
ll ans = 0;
for(int i = 0;i < n;i++) {
ans += store[a[i]];
}
pf(ans);
}
int main() {
go();
int t = 1;
while(t--) solve();
return 0;
} | // C - Made Up
#include <bits/stdc++.h>
#define repi(i, s, n) for(int i=(int)(s); i<(int)(n); ++i)
#define rep(i, n) repi(i, 0, n)
#define rrep(i, n, s) for(int i=(int)(n-1); i>=(int)(s); --i)
using namespace std;
using ll = long long;
using ull = unsigned long long;
int main(){
int n;
cin >> n;
map<int, int> a;
vector<int> b(n);
rep(i, n){
int aa; cin >> aa;
++a[aa];
}
rep(i, n) cin >> b[i];
vector<int> d(n, 0);
rep(i, n){
int c; cin >> c;
++d[c-1];
}
ll ans = 0;
rep(i, n){
if(d[i]){
if(a[b[i]]){
ll v =(ll)a[b[i]]*d[i];
ans += v;
}
}
}
cout << ans << endl;
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
int dx[4]={0,1,0,-1}, dy[4]={1,0,-1,0};
long double eps = 1e-9;
long double pi = acos(-1);
// https://ei1333.github.io/luzhiled/snippets/graph/dinic.html
template< typename flow_t >
struct Dinic {
const flow_t INF;
struct edge {
int to;
flow_t cap;
int rev;
bool isrev;
int idx;
};
vector< vector< edge > > graph;
vector< int > min_cost, iter;
Dinic(int V) : INF(numeric_limits< flow_t >::max()), graph(V) {}
void add_edge(int from, int to, flow_t cap, int idx = -1) {
graph[from].emplace_back((edge) {to, cap, (int) graph[to].size(), false, idx});
graph[to].emplace_back((edge) {from, 0, (int) graph[from].size() - 1, true, idx});
}
bool bfs(int s, int t) {
min_cost.assign(graph.size(), -1);
queue< int > que;
min_cost[s] = 0;
que.push(s);
while(!que.empty() && min_cost[t] == -1) {
int p = que.front();
que.pop();
for(auto &e : graph[p]) {
if(e.cap > 0 && min_cost[e.to] == -1) {
min_cost[e.to] = min_cost[p] + 1;
que.push(e.to);
}
}
}
return min_cost[t] != -1;
}
flow_t dfs(int idx, const int t, flow_t flow) {
if(idx == t) return flow;
for(int &i = iter[idx]; i < graph[idx].size(); i++) {
edge &e = graph[idx][i];
if(e.cap > 0 && min_cost[idx] < min_cost[e.to]) {
flow_t d = dfs(e.to, t, min(flow, e.cap));
if(d > 0) {
e.cap -= d;
graph[e.to][e.rev].cap += d;
return d;
}
}
}
return 0;
}
flow_t max_flow(int s, int t) {
flow_t flow = 0;
while(bfs(s, t)) {
iter.assign(graph.size(), 0);
flow_t f = 0;
while((f = dfs(s, t, INF)) > 0) flow += f;
}
return flow;
}
void output() {
for(int i = 0; i < graph.size(); i++) {
for(auto &e : graph[i]) {
if(e.isrev) continue;
auto &rev_e = graph[e.to][e.rev];
cout << i << "->" << e.to << " (flow: " << rev_e.cap << "/" << e.cap + rev_e.cap << ")" << endl;
}
}
}
};
// Dinic< int > g(V);
// g.add_edge(from,to,cost);
// cout << g.max_flow(from,to) << endl;
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(20);
int n;
cin>>n;
Dinic<int> g(600000+2);
for(int i=1;i<=n;i++){
int a,b;
cin>>a>>b;
g.add_edge(i,a+n,1);
g.add_edge(i,b+n,1);
}
for(int i=1;i<=n;i++)g.add_edge(0,i,1);
for(int i=n+1;i<=600000;i++)g.add_edge(i,600000+1,1);
cout << g.max_flow(0,600000+1) << endl;
} | #include <bits/stdc++.h>
#define sort stable_sort
using namespace std;
int _;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
int n,cnt[400050],ans;
set<int> s,p[400050];
inline void dfs(int x)
{
for(auto v:p[x])
{
p[v].erase(x);
p[x].erase(v);
cnt[x]--;
cnt[v]--;
if(cnt[v] == 0)
ans--;
if(cnt[v] == 1)
dfs(v);
break;
}
}
int main()
{
//for(scanf("%d",&_);_;_--)
scanf("%d",&n);
for(int i=0;i<n;i++)
{
int x,y;
scanf("%d%d",&x,&y);
p[x].insert(y);
p[y].insert(x);
s.insert(x);
s.insert(y);
cnt[x]++;
cnt[y]++;
}
ans=s.size();
for(auto x:s)
if(cnt[x] == 1)
dfs(x);
printf("%d\n",ans);
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
int n;
cin >> n;
double a[n],b[n],c[n];
int ans = n*(n-1)/2;
rep(i,n){
cin >> a[i] >> b[i] >> c[i];
if(a[i] ==2)
{c[i] -= 0.1;}
else if(a[i] ==3)
{b[i] += 0.1;}
else if(a[i] ==4)
{c[i] -= 0.1;
b[i] += 0.1;}
}
rep(i,n-1){
for(int j =i+1;j<n;j++){
if(c[i] < b[j] || b[i] > c[j])
{ans -=1;}
}
}
cout << ans << endl;
return 0;
}
| /********************************************************************************/
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
const double PI = 4*atan(1);
#define loop(i,n) for(int i=0;i<n;i++)
#define itr(it,v) for(auto it=v.begin();it!=v.end();++it)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define debug(x) cout << "[ " << #x << " : " << x << " ]" << endl ;
#define MOD (int)(1e9+7)
void solve()
{
int n;
cin>>n;
int t[n],l[n],r[n];
int ans=0;
for(int i=0;i<n;i++)
{
cin>>t[i];
cin>>l[i]>>r[i];
for(int k=i-1;k>=0;k--)
{
int x1=l[k];
int y1=r[k];
if((y1<l[i] or x1>r[i]) or((r[k]==l[i] and (t[k]==2 or t[k]==4 or t[i]==4 or t[i]==3)) or (r[i]==l[k] and (t[i]==2 or t[k]==4 or t[i]==4 or t[k]==3))))
{
}
else
ans++;
}
//cout<<ans<<endl;
}
cout<<ans<<endl;
}
int32_t main()
{ IOS
int t=1;
//cin>>t;
while(t--)
{
solve();
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<ll> vl;
#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define vt vector
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)size(x)
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
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;
}
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...);}
const int d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1};
const int d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1};
const ll mod=1e9+7;
//-------------------####Real Programming###------------------
void solve(){
ll n; cin>>n; ll a[1 << 18], g[1 << 18]; ll ans=1;
FOR(i,1,n+1) cin>>a[i];
sort(a+1,a+n+1);
FOR(i,1,n+1) g[i]=(a[i]-a[i-1]);
FOR(i,1,n+1) {ans*=(g[i]+1); ans%=mod;}
cout<<ans<<"\n";
return;
}
int main() {
//freopen("blocks.in", "r", stdin);
//freopen("blocks.out", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0);
//int t; cin>>t;
//F0R(i,t){
//write("Case #", i+1, ": ");
solve();
//}
return 0;
} | ///Bismillahir Rahmanir Rahim
/*
Author: Tanzin Ahammad
*/
#include<bits/stdc++.h>
#define u64 uint64_t
#define ll long long
#define endl "\n"
#define PI acos(-1)
#define fi first
#define si second
#define pb push_back
#define set0(arr) memset(arr, 0, sizeof(arr))
#define setinf(arr) memset(arr, 126, sizeof(arr))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define all(x) (x).begin(),(x).end()
#define sz(v) ((ll)(v).size())
#define mem(a,b) memset(a, b, sizeof(a))
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define mchk(mask,pos) (mask & (1ll<<pos))
#define mset(mask,pos) (mask bitor (1ll<<pos))
#define munset(mask,pos) (mask ^ (1ll<<pos))
#define print_case cout<<"Case "<<cs<<": "
#define sumt(a,b) ((a%mod)+(b%mod))%mod
#define subt(a,b) ((a%mod)-(b%mod)+mod)%mod
#define mult(a,b) ((a%mod)*(b%mod))%mod
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
using pll = pair<ll, ll> ;
using vl = vector<ll> ;
using vpll = vector<pll> ;
using mll = map<ll, ll> ;
using mcl = map<char, ll> ;
using msl = map<string,ll> ;
using sl = set<ll> ;
using sc = set<char> ;
const int N = 1e6+5;
const int mod = (int) 1e9 + 7;
ll arr[N];
int main()
{
IOS;
ll tc,n,x,i,j;
cin>>n;
for(i=0;i<n;i++) cin>>arr[i];
sort(arr,arr+n);
ll mul=1;x=0;
for(i=0;i<n;i++)
{
mul=mult(mul,arr[i]-x+1);
x=arr[i];
}
cout<<mul<<endl;
return 0;
}
|
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main() {
int N, C;
cin >> N;
vector<double> x(N);
vector<double> y(N);
C = 0;
for (int i = 0; i < N; i++) {
cin >> x.at(i) >> y.at(i);
}
for (int i = 0; i < N - 1; i++) {
for (int j = i + 1; j < N; j++) {
double t = (y.at(j) - y.at(i)) / (x.at(j) - x.at(i));
if (t >= -1 && t <= 1) {
C = C + 1;
}
}
}
cout << C;
} | //pikuskd_32->42
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
#define fr(i,s,e) for(ll i=s;i<=e;i++)
#define rfo(i,s,e) for(ll i=s;i>=e;i--)
#define f(x,m) for(auto x : m)
#define ff first
#define ss second
const ll INF = (1LL << 60) - 1;
#define pb push_back
#define pp pop_back
#define pf push_front
#define ppf pop_front
#define m_p make_pair
#define mod 1000000007
#define TIME cerr<<"Time Taken:"<<(float)clock()/CLOCKS_PER_SEC*1000<<"ms"<<endl
// __builtin_popcount(n)
// cout << fixed << setprecision(2) << a << endl; ->'a' is floating point.
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input1.txt", "r", stdin);
freopen("output2.txt", "w", stdout);
#endif
ll t = 1; //cin>>t;
while (t--) {
ll n; cin >> n;
vector<pair<ll, ll>> v;
ll x, y;
fr(i, 0, n - 1) {
cin >> x >> y; v.pb(m_p(x, y));
}
ll c = 0;
fr(i, 0, n - 1) {
fr(j, i + 1, n - 1) {
if (abs(v[j].ss - v[i].ss) <= abs(v[j].ff - v[i].ff)) c++;
}
}
cout << c << endl;
}
TIME;
return 0;
} |
#include <iostream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
int main() {
string s; cin >> s;
bool flag = false;
if (s.size() == 1) {
if (s == "8") flag = true;
}
else if (s.size() == 2) {
if (stoi(s) % 8 == 0) flag = true;
swap(s[0], s[1]);
if (stoi(s) % 8 == 0) flag = true;
}
else {
vector<int> cnt(10);
for (int i = 0; i < (int)s.size(); ++i) {
cnt[s[i] - '0']++;
}
for (int i = 112; i < 1000; i += 8) {
vector<int> check = cnt;
string n = to_string(i);
for (int j = 0; j < 3; ++j) {
check[n[j] - '0']--;
}
if (check[n[0] - '0'] >= 0 && check[n[1] - '0'] >= 0 && check[n[2]- '0'] >= 0) {
flag = true;
}
}
}
if (flag) cout << "Yes" << endl;
else cout << "No" << endl;
return 0;
} | #include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<iomanip>
#include<algorithm>
#include<utility>
#include<set>
#include<map>
#include<queue>
#include<complex>
#define Debug cout<<"line: "<<__LINE__<<"Debug"<<endl;
#define Yes cout<<"Yes"<<endl;
#define YES cout<<"YES"<<endl;
#define No cout<<"No"<<endl;
#define NO cout<<"NO"<<endl;
#define ALL(a) (a).begin(),(a).end()
#define MOD 1000000007
#define PI 3.14159265358979323846
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vd = vector<double>;
using vl = vector<long long>;
void set_FPD(int n){ cout<<fixed<<setprecision(n); return; }
void Main(){
string s;
cin>>s;
vi num(10,0);
int size=s.size();
for(char &x:s) num[x-'0']++;
if(size<3){
if(size<2) num[0]+=2;
else num[0]++;
}
for(int i=0;i<10;i++){
if(size<3 && i>0) continue;
for(int j=0;j<10;j++){
if(size<2 && j>0) continue;
for(int k=0;k<10;k++){
vi cnt(10,0);
cnt[i]++;
cnt[j]++;
cnt[k]++;
int n=100*i+10*j+k;
if(n%8==0 && cnt[i]<=num[i] && cnt[j]<=num[j] && cnt[k]<=num[k]){
//cout<<n<<endl;
Yes
return;
}
}
}
}
No
return;
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
Main();
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 FOR(i, m, n) for(int i = m;i < n;i++)
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
using namespace std;
long long modPow(long long x, long long a) {
if (a == 1) return x;
if (a % 2) return (x * modPow(x, a - 1)) % MOD;
long long t = modPow(x, a / 2);
return (t * t) % MOD;
}
long long modInv(long long x) {
return modPow(x, MOD - 2);
}
void recursive_comb(int *indexes, int s, int rest, std::function<void(int *)> f) {
if (rest == 0) {
f(indexes);
} else {
if (s < 0) return;
recursive_comb(indexes, s - 1, rest, f);
indexes[rest - 1] = s;
recursive_comb(indexes, s - 1, rest - 1, f);
}
}
// nCkの組み合わせに対して処理を実行する
void foreach_comb(int n, int k, std::function<void(int *)> f) {
int indexes[k];
recursive_comb(indexes, n - 1, k, f);
}
// nPnの順列に対して処理を実行する
void foreach_permutation(int n, std::function<void(int *)> f) {
int indexes[n];
for (int i = 0; i < n; i++) indexes[i] = i;
do {
f(indexes);
} while (std::next_permutation(indexes, indexes + n));
}
// nPkの順列に対して処理を実行する
void foreach_permutation(int n, int k, std::function<void(int *)> f) {
foreach_comb(n, k, [&](int *c_indexes) {
foreach_permutation(k, [&](int *p_indexes) {
int indexes[k];
for (int i = 0; i < k; i++) {
indexes[i] = c_indexes[p_indexes[i]];
}
f(indexes);
});
});
}
int main() {
string s;
cin >> s;
for (int i = 0; i < s.size(); i++) {
if(s[i] == '9'){
s[i] = '6';
}
else if(s[i] == '6'){
s[i] = '9';
}
}
reverse(s.begin(), s.end());
cout << s << endl;
} | #include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define P pair<int,int>
#define PI 3.141592653589793
const int INF = 1001001001;
const ll MX = 1e18;
const int mod = 998244353;
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
int main() {
int n;
cin >> n;
string s;
cin >> s;
vector<int> cnt(4);
ll ans = 0;
rep(i, n) {
for (int j = i; j < n; j++) {
if (s[j] == 'A') cnt[0]++;
if (s[j] == 'T') cnt[1]++;
if (s[j] == 'C') cnt[2]++;
if (s[j] == 'G') cnt[3]++;
if (cnt[0] == cnt[1] && cnt[2]==cnt[3]) ans++;
}
rep(m, 4) cnt[m] = 0;
}
cout << ans << endl;
} |
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0; i<(n); ++i)
#define RREP(i, n) for(int i=(n);i>=0;--i)
#define FOR(i, a, n) for (int i=(a); i<(n); ++i)
#define RFOR(i, a, b) for(int i=(a);i>=(b);--i)
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl;
template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
REP(i, SZ(v)) {
if (i) os << " ";
os << v[i];
}
return os;
}
template <class T>
void debug(const vector<T> &v) {
cout << "[";
REP(i, SZ(v)) {
if(i) cout << ", ";
cout << v[i];
}
cout << "]" << endl;
}
template<class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
return os << p.first << " " << p.second;
}
template <class T, class U>
void debug(const pair<T, U> &p) {
cout << "(" << p.first << " " << p.second << ")" << endl;
}
template<class T>
bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template<class T>
bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return true;
}
return false;
}
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;
const ll MOD = 1e9 + 7;
const ll MOD998 = 998244353;
const int INF = INT_MAX;
const ll LINF = LLONG_MAX;
const int inf = INT_MIN;
const ll linf = LLONG_MIN;
const ld eps = 1e-9;
template<int m>
struct mint {
int x;
mint(ll x = 0) : x(((x % m) + m) % m) {}
mint operator-() const { return x ? m - x : 0; }
mint &operator+=(mint r) {
if ((x += r.x) >= m) x -= m;
return *this;
}
mint &operator-=(mint r) {
if ((x -= r.x) < 0) x += m;
return *this;
}
mint &operator*=(mint r) {
x = ((ll) x * r.x) % m;
return *this;
}
mint inv() const { return pow(m - 2); }
mint &operator/=(mint r) { return *this *= r.inv(); }
friend mint operator+(mint l, mint r) { return l += r; }
friend mint operator-(mint l, mint r) { return l -= r; }
friend mint operator*(mint l, mint r) { return l *= r; }
friend mint operator/(mint l, mint r) { return l /= r; }
mint pow(ll n) const {
mint ret = 1, tmp = *this;
while (n) {
if (n & 1) ret *= tmp;
tmp *= tmp, n >>= 1;
}
return ret;
}
friend bool operator==(mint l, mint r) { return l.x == r.x; }
friend bool operator!=(mint l, mint r) { return l.x != r.x; }
friend ostream &operator<<(ostream &os, mint a) {
return os << a.x;
}
friend istream &operator>>(istream &is, mint &a) {
ll x;
is >> x;
a = x;
return is;
}
};
using Int = mint<MOD>;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
int n; cin >> n;
vll a(n), b(n);
REP(i, n) {
cin >> a[i];
}
REP(i, n) {
cin >> b[i];
}
vll c(n);
ll ma = 0;
ll maa = 0;
REP(i, n) {
chmax(maa, a[i]);
chmax(ma, maa * b[i]);
c[i] = ma;
}
REP(i, n) {
cout << c[i] << endl;
}
return 0;
}
| #include <bits/stdc++.h>
#define ll long long
using namespace std;
int n;
ll a[200010], b[200010], maxa[200010], maxb[200010];
int main(){
scanf("%d", &n);
ll maxn = -1e18;
for(int i = 1; i <= n; i++) scanf("%lld", &a[i]);
for(int i = 1; i <= n; i++) scanf("%lld", &b[i]);
maxa[1] = a[1];
for(int i = 2; i <= n; i++){
maxa[i] = max(a[i], maxa[i - 1]);
}
for(int i = 1; i <= n; i++){
maxn = max(maxn, maxa[i] * b[i]);
printf("%lld\n", maxn);
}
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define u unsigned
#define ull unsigned long long
#define ld long double
#define pb push_back
#define fasterInOut ios::sync_with_stdio(false); cin.tie(0);
#define pi acos(-1)
#define f(i,a,b) for(int i=(a);i<=(b);i++)
#define fr(i,a,b) for(int i=(a);i>=(b);i--)
#define MAX 1000000
int main()
{
int a,b,c;
cin>>a>>b>>c;
if(a==b)
{
cout<<c;
}
else if(a==c)
{
cout<<b;
}
else if(b==c)
{
cout<<a;
}
else if(a==b && b!=c)
{
cout<<a;
}
else
{
cout<<0;
}
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
int main(void){
int a, b, c;
cin >> a >> b >> c;
if (a == b) cout << c << endl;
else if (b == c) cout << a << endl;
else if (c == a) cout << b << endl;
else cout << 0 << endl;
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);
int m, h;
cin >> m >> h;
string ans = "No";
if (h % m == 0) {
ans = "Yes";
}
COUT(ans);
} | #include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int INF = 1e9;
const long long INFLL = 1e18;
using ll = long long;
int digit(int n){
int res = 0;
while(n > 0){
res += n % 10;
n /= 10;
}
return res;
}
int main(){
int a, b;
cin >> a >> b;
cout << max(digit(a), digit(b)) << endl;
return 0;
} |
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
typedef unsigned long long int ll;
#define MAX 1000000000
#define mod 1000000007
ll gcd(ll a, ll b){
if (a == 0)
return b;
else
return gcd(b % a, a);
}
ll lcm(ll a, ll b) {
return (a*b)/gcd(a, b);
}
ll fact(ll n){
if(n==0)
return 1;
else
return n*fact(n-1);
}
bool dig(char S){
return S>='0' && S<='9';
}
bool sma(char S){
return S>='a' && S<='z';
}
bool cap(char S){
return S>='A' && S<='Z';
}
void solve(ll t){
ll N;
cin>>N;
ll p=1,i;
for(i=1;i<=N;i++){
p = lcm(p,i);
}
ll r=p+1;/*
for(i=2;i<=N;i++){
cout<<r%i<<" ";
}*/
cout<<r;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//freopen("D:\\codes\\input_10.txt","r",stdin);
//freopen("D:\\codes\\1output.txt","w",stdout);
ll T=1;
//cin>>T;
for(ll t=1;t<=T;t++){
//cout<<"Case #"<<t<<": ";
solve(t);
cout<<"\n";
}
return 0;
}
| #include<bits/stdc++.h>
#include<algorithm>
#define int long long
using namespace std;
signed main(){
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
//MessageBox(GetForegroundWindow(),"标题","内容",MB_YESNO);
int n;
cin>>n;
int sum=1;
for(int i=1;i<=n;i++){
sum*=i/(__gcd(sum,i));
}
cout<<sum+1-1+1-1+1-1+1-1+1<<endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define mp make_pair
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;
ll A[50];
void calc(set<ll>& time, int v, int end, ll sum, bool rev){
if(v == end){
if(rev)
sum *= -1;
time.insert(sum);
}
else{
calc(time, v+1, end, sum, rev);
calc(time, v+1, end, sum + A[v], rev);
}
}
int main(){
ll N, T;
cin >> N >> T;
REP(i,N){
cin >> A[i];
}
set<ll> timeA;
set<ll> timeB;
calc(timeA, 0, N/2, 0, false);
calc(timeB, N/2, N, 0, true);
ll ans = -1;
for(auto&& tA : timeA){
ll rem = T - tA;
auto iter = timeB.lower_bound(-rem);
if(iter != timeB.end()){
chmax(ans, tA - *iter);
}
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<long long, long long>;
constexpr char ln = '\n';
constexpr long long MOD = 1000000007;
constexpr long long INF = 1<<30;
constexpr long long LINF = 1LL<<60;
constexpr double EPS = 1e-9;
#define all(v) v.begin(), v.end()
#define rep(i, n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll X[110], Y[110], Z[110], dp[1<<18];
int main(){
int N, M; cin >> N >> M;
rep(i, M)cin >> X[i] >> Y[i] >> Z[i];
dp[0] = 1;
for(int mask=1; mask<1<<N; mask++){
int popcnt = __builtin_popcount(mask);
bool fg = true;
rep(i, M){
if(X[i]!=popcnt)continue;
int cnt = 0;
rep(j, Y[i]){
if(mask>>j&1)cnt++;
}
if(cnt > Z[i])fg = false;
}
if(fg){
for(int from=0; from<N; from++){
if(mask>>from&1){
dp[mask] += dp[mask^1<<from];
}
}
}
}
cout << dp[(1<<N)-1] << ln;
} |
#include<bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vector<int>>
#define pb push_back
#define int long long int
#define mod 1000000007
#define from(i,n) for(int i=0;i<(int)n;i++)
#define from_j(i,j,n) for(int i=j:i<(int)n;i++)
using namespace std;
int power(int n , int k) {
if (k == 0)return 1;
int temp = power(n, k / 2);
temp = (temp * temp);
if (k % 2) return (temp * n);
return temp;
}
int fact(int x)
{
int res = 1;
for(int i=2;i<=x;i++)
res = i*res;
return res;
}
int choose(int n, int r)
{
return fact(n)/(fact(r)*fact(n-r));
}
void sync()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
/*
#ifndef ONLINEJUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
freopen("error.txt", "w", stderr);
#endif
*/
}
int32_t main() {
sync();
int n, s, d;
cin>>n>>s>>d;
int count = 0;
from(i,n)
{
int x,y;
cin>>x>>y;
if(x>=s)
continue;
else
{
if(y>d)
count++;
}
}
if(count)
cout<<"Yes";
else
cout<<"No";
cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
#define For(i,a,b) for(int i=a,i##_end=b;i<i##_end;++i)
using ll=long long;
using pii=pair<int,int>;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
const int mo=1e9+7;
using L=__int128;
ll Pow(ll a,ll b,ll p=mo){ll r=1;for(;b;b>>=1,a=(L)a*a%p)if(b&1)r=(L)r*a%p;return r;}
//template<typename T>
void inc(int &x,int y){x=(x+y>=mo?x+y-mo:x+y);}
int ad(int x,int y){return x+y>=mo?x+y-mo:x+y;}
template<typename T>T gcd(T a,T b){while(b)a%=b,swap(a,b);return a;}
mt19937 rnd(time(0));
int main(){
#ifdef SGR
freopen("a.txt","r",stdin);
#endif
ios::sync_with_stdio(0);
ll n,m;
cin>>n>>m;
int x=Pow(10,n,m);
ll y=Pow(10,n,m*m);
//cerr<<x<<" "<<y<<endl;
cout<<(y)/m<<endl;
} |
#include <bits/stdc++.h>
using namespace std;
// #define LOCAL // 提出時はコメントアウト
#define DEBUG_
typedef long long ll;
const double EPS = 1e-9;
const ll INF = ((1LL<<62)-(1LL<<31));
typedef vector<ll> vecl;
typedef pair<ll, ll> pairl;
template<typename T> using uset = unordered_set<T>;
template<typename T, typename U> using mapv = map<T,vector<U>>;
template<typename T, typename U> using umap = unordered_map<T,U>;
#define ALL(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define sz(x) (ll)x.size()
ll llceil(ll a,ll b) { return (a+b-1)/b; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> vector<vector<T>> genarr(ll n, ll m, T init) { return vector<vector<T>>(n,vector<T>(m,init)); }
///// DEBUG
#define DUMPOUT cerr
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
template<typename T>istream&operator>>(istream&is,vector<T>&vec){for(T&x:vec)is>>x;return is;}
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>ostream&operator<<(ostream&os,const vector<T>&vec){os<<"{";for(int i=0;i<vec.size();i++){os<<vec[i]<<(i+1==vec.size()?"":", ");}
os<<"}";return os;}
template<typename T,typename U>ostream&operator<<(ostream&os,map<T,U>&map_var){os<<"{";repi(itr,map_var){os<<*itr;itr++;if(itr!=map_var.end())os<<", ";itr--;}
os<<"}";return os;}
template<typename T>ostream&operator<<(ostream&os,set<T>&set_var){os<<"{";repi(itr,set_var){os<<*itr;itr++;if(itr!=set_var.end())os<<", ";itr--;}
os<<"}";return os;}
void dump_func(){DUMPOUT<<endl;}
template<class Head,class...Tail>void dump_func(Head&&head,Tail&&...tail){DUMPOUT<<head;if(sizeof...(Tail)>0){DUMPOUT<<", ";}
dump_func(std::move(tail)...);}
#ifndef LOCAL
#undef DEBUG_
#endif
#ifdef DEBUG_
#define DEB
#define dump(...) \
DUMPOUT << " " << string(#__VA_ARGS__) << ": " \
<< "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" \
<< endl \
<< " ", \
dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
//////////
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
int solve(ostringstream &cout) {
#ifdef LOCAL
ifstream in("../../Atcoder/input.txt");
cin.rdbuf(in.rdbuf());
#endif
ll N,K;
cin>>N>>K;
rep(i,K) {
if (N % 200 == 0) N /= 200;
else {
N *= 1000, N += 200;
}
}
cout << N << endl;
return 0;
}
int main() {
ostringstream oss;
int res = solve(oss);
cout << oss.str();
return res;
}
| #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,k;
int main()
{
scanf("%d%d",&n,&k);
ll x=n;
for(int i=1;i<=k;)
{
if(x%200ll==0)x/=200ll,i++;
else
{
if(i<k)
{
int t=x%2;t*=10;
x/=2;
x*=10;
x+=t/2+1;
i+=2;
// cout<<x<<" ";
}
else
{
cout<<x;
cout<<200;
return 0;
}
}
}
cout<<x;
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#define INF 1234567890
#define ll long long
#define MOD 998244353
ll N, M, K, res;
ll pw(ll a, ll n)
{
ll ret = 1;
while(n)
{
if (n&1) ret=ret*a%MOD;
a=a*a%MOD;
n>>=1;
}
return ret;
}
int main()
{
scanf("%lld %lld %lld", &N, &M, &K);
if (N < M) swap(N, M);
if (M == 1)
{
printf("%lld\n", pw(K, N));
return 0;
}
for(ll x=1; x<=K; x++)
res += pw(K-x+1,M)*(pw(x,N)-pw(x-1,N))%MOD;
res %= MOD; res += MOD; res %= MOD;
printf("%lld\n", res);
return 0;
} | #include <vector>
#include <set>
#include <iostream>
#include <algorithm>
#include <string>
#include <utility>
#define mod % 998244353
#define MAX 998244353
#define ll long long
using namespace std;
int main() {
int high,wide,k;
cin >> high;
cin >> wide;
cin >> k;
ll ans = 0;
if(high == wide and high == 1){
cout << k mod << endl;
return 0;
}
if(high == 1 or wide == 1){
if(wide == 1){
wide = high;
}
for(int i = 1;i <= k;i ++){
int m = wide;
vector<ll> mul(21);
vector<ll> mult(21);
mul[0] = i;
mult[0] = i-1;
ll pl = 1;
ll plt = 1;
for(int j = 0;j < 20;j++){
mul[j+1] = (mul[j]*mul[j])mod;
mult[j+1] = (mult[j]*mult[j])mod;
if(m % 2 == 1){
pl = (pl*mul[j])mod;
plt = (plt*mult[j])mod;
}
m = m/2;
}
ans = (ans+MAX+pl-plt)mod;
}
cout << ans mod << endl;
return 0;
}
for(int i = 1;i <= k;i ++){
ll pl = 1;
int m = wide;
vector<ll> mul(21);
mul[0] = k-i+1;
for(int j = 0;j < 20;j ++){
mul[j+1] = (mul[j]*mul[j])mod;
if(m % 2 == 1){
pl = (pl*mul[j]) mod;
}
m = m/2;
}
ll kakerua = 1;
ll kakerub = 1;
if(i == 1){
kakerub = 0;
}
m = high;
vector<ll> mult(21);
mul[0] = i;
mult[0] = i-1;
for(int j = 0;j < 20;j ++){
mul[j+1] = (mul[j]*mul[j])mod;
mult[j+1] = (mult[j]*mult[j])mod;
if(m % 2 == 1){
kakerua = (kakerua*mul[j])mod;
kakerub = (kakerub*mult[j])mod;
}
m = m/2;
}
kakerua = (MAX-kakerub+kakerua)mod;
pl = (pl*kakerua)mod;
ans = (ans +pl)mod;
}
cout << ans mod<< endl;
return 0;
} |
#define G 3
#include<map>
#define AK goto
#include<cmath>
#include<queue>
#include<bitset>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
#define ll long long
#define md ((l+r)>>1)
#define cht 1000000007
#define inf 1145141919810
#define mem(i,j)memset(i,j,sizeof(i))
#define F(i,j,n)for(int i=j;i<=n;i++)
#define D(i,j,n)for(int i=j;i>=n;i--)
using namespace std;
namespace sky_chen{
// char buf[1<<23],*p1=buf,*p2=buf,obuf[1<<23],*O=obuf;
// #define gc() p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++
inline ll read(){ll ans=0,f=1;char a=getchar();while(a>'9'||a<'0'){if(a=='-')f=-1;a=getchar();}while(a>='0'&&a<='9')ans=ans*10+(a^48),a=getchar();return ans*f;}
inline char red(){char a=getchar();while(a>'z'||a<'a')a=getchar();return a;}
// inline void print(ll x){if(x>9)print(x/10);*O++=x%10+'0';}
inline void cadd(ll &x,ll y){x=(x+y)%cht;}
inline void cmin(ll &x,ll y){x=min(x,y);}
inline void cmax(ll &x,ll y){x=max(x,y);}
ll qpow(ll n,ll base=cht-2){ll ans=1;while(base){if(base&1)ans=ans*n%cht;n=n*n%cht;base>>=1;}return ans;}
const int maxn = 1e6+5;
const int maxc = 3e5+5;
ll n,x[maxn],y[maxn];
struct node{
ll a=0,b=0,c=0;
}p1,p2,t,f[maxn],g[maxn];
int yyds(){
n=read();
F(i,1,n)x[i]=read(),y[i]=read();
ll m=read();
p1.a=1;p2.b=1;
f[0]=p1;g[0]=p2;
F(i,1,m){
ll opt=read();
if(!(opt-1)){
t=p1;p1=p2;p2.a=-t.a;p2.b=-t.b;p2.c=-t.c;
f[i]=p1;g[i]=p2;
}
else if(!(opt-2)){
t=p2;p2=p1;p1.a=-t.a;p1.b=-t.b;p1.c=-t.c;
f[i]=p1;g[i]=p2;
}
else if(!(opt-3)){
p1.c=2*read()-p1.c;p1.b=-p1.b;p1.a=-p1.a;
f[i]=p1;g[i]=p2;
}
else{
p2.c=2*read()-p2.c;p2.b=-p2.b;p2.a=-p2.a;
f[i]=p1;g[i]=p2;
}
}
// F(i,0,m)cout<<f[i].a<<' '<<f[i].b<<' '<<f[i].c<<' '<<g[i].a<<' '<<g[i].b<<' '<<g[i].c<<endl;
ll q=read();
F(i,1,q){
ll sb1=read(),sb2=read();
ll za=x[sb2],zb=y[sb2];
ll nza=f[sb1].a*za+f[sb1].b*zb+f[sb1].c,nzb=g[sb1].a*za+g[sb1].b*zb+g[sb1].c;
printf("%lld %lld\n",nza,nzb);
}
return 0;
}
}
int main(){return sky_chen::yyds();}
//sky_chen txdy! | #include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std;
void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------
void _main(){
double A, B, C, ans;
cin >> A >> B;
C = A - B;
C *= 100;
ans = C / A;
cout << ans << endl;
return;
} |
//BadWaperZ
#include<bits/stdc++.h>
#define inf 1e9
#define eps 1e-6
#define mp make_pair
#define pb push_back
#define fr first
#define sd second
#define pa pair<ll,ll>
#define re register ll
#define FOR(i,a,b) for(re i=a;i<=b;i++)
#define REP(i,a,b) for(re i=a;i>=b;i--)
#define MEM(a) memset(a,0,sizeof(a))
#define N 5010
#define M 21
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
inline ll read()
{
char ch=getchar();
ll s=0,w=1;
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
return s*w;
}
inline ll lowbit(ll x){return x&(-x);}
const ll mod=998244353;
ll f[M][N],C[N][N];
ll n,m;
inline ll Z(ll x){return (x>=mod?x-mod:x);}
int main()
{
//ios::sync_with_stdio(false);
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
n=read(),m=read();
C[0][0]=1;
FOR(i,1,n){C[i][0]=1;FOR(j,1,i)C[i][j]=Z(C[i-1][j]+C[i-1][j-1]);}
f[0][0]=1;ll t=0;
FOR(k,1,20)
{
int v=(1<<(k-1));
if(v>m){t=k-1;break;}
FOR(s,0,m)if(f[k-1][s])for(re j=0;j<=n;j+=2)
{
if(s+j*v>m)break;
f[k][s+j*v]=Z(f[k][s+j*v]+1LL*f[k-1][s]*C[n][j]%mod);
}
}
cout<<f[t][m]<<'\n';
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repp(i, st, en) for (ll i = (ll)st; i < (ll)(en); i++)
#define repm(i, st, en) for (ll i = (ll)st; i >= (ll)(en); i--)
#define all(v) v.begin(), v.end()
void chmax(ll &x, ll y) {x = max(x,y);}
void chmin(ll &x, ll y) {x = min(x,y);}
void Yes() {cout << "Yes" << endl; exit(0);}
void No() {cout << "No" << endl; exit(0);}
template<class in_Cout> void Cout(in_Cout x) {cout << x << endl; exit(0);}
template<class in_vec_cout>
void vec_cout(vector<in_vec_cout> vec) {
for (in_vec_cout res : vec) {cout << res << " ";}
cout << endl;
}
const ll inf = 1e18;
const ll mod = 998244353;
const ll logM = 16;
ll N, M;
vector<ll> to_bin(ll N) {
vector<ll> res(logM);
vector<ll> tmp;
while (N>0) {
tmp.push_back(N%2);
N /= 2;
}
rep(i,tmp.size()) res[i] = tmp[i];
return res;
}
// nCr (mod p) 計算量 O(3*10^5*logp)
const ll Maximum = 3e5;
ll Fac[Maximum+1], iFac[Maximum+1];
bool made_Fac = false;
// x^n (mod p) 計算量 O(logn)
ll powmodp(ll x, ll n) {
if (n==0) return 1;
else if (n%2==0) {
ll ans = powmodp(x,n/2);
return ans*ans % mod;
}
else return x * powmodp(x,n-1) % mod;
}
// nCr (mod p) 計算量 O(3*10^5*logp)
void make_Fac() {
Fac[0] = 1;
iFac[0] = 1;
for (ll i=0; i<Maximum; i++) {
Fac[i+1] = Fac[i] * (i+1) % mod;
iFac[i+1] = iFac[i] * powmodp(i+1,mod-2) % mod;
}
}
ll nCrmodp(ll n, ll r) {
if (!made_Fac) {
make_Fac();
made_Fac = true;
}
r = min(r,n-r);
if (n==0 or r==0) return 1;
ll tmp = iFac[n-r] * iFac[r] % mod;
return tmp * Fac[n] % mod;
}
int main() {
cin >> N >> M;
if (M%2) Cout(0);
vector<ll> S = to_bin(M);
vector<vector<ll>> dp(logM,vector<ll>(M+1));
for (ll i=0; i<=N; i+=2) {
ll up = i/2;
if (up>M) continue;
dp[0][up] = nCrmodp(N,i);
}
for (ll i=1; i<logM; i++) {
for (ll k=0; k<=N; k+=2) {
ll cnt = nCrmodp(N,k);
for (ll j=0; j<=M; j++) {
if (S[i]!=j%2) continue;
ll up = (k + j)/2;
if (up>M) continue;
dp[i][up] += cnt * dp[i-1][j] % mod;
dp[i][up] %= mod;
}
}
}
ll ans = dp.back()[0];
cout << ans << endl;
} |
#include "bits/stdc++.h"
#include <cmath>
#include <limits>
using namespace std;
#define int long long
#define pb push_back
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define F first
#define S second
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define ld long double
#define pii pair<int, int>
#define vi vector<int>
ld x,y,r;
bool sarkha(ld a, ld b)
{
return (a - b) <= std::numeric_limits<long double>::epsilon();
}
bool ander(int X, int Y)
{
ld Xx = (x - X) * (x - X) + (y - Y) * (y - Y);
ld Yy = r * r;
return sarkha(Xx, Yy);
}
void solve()
{
cin >> x >> y >> r;
int A = 0;
for(int X = -4e5 ; X <= 4e5 ; X++)
{
int LEFT = -1e9;
int RIght = -1e9;
int L = -2e6, H = 2e6;
while(L <= H)
{
int Middd = (L + H)/2;
if(ander(X, Middd))
{
H = Middd - 1;
LEFT = Middd;
}
else
{
if(Middd < y)
{
L = Middd + 1;
}
else
{
H = Middd - 1;
}
}
}
L = -2e6, H = 2e6;
while(L <= H)
{
int Middd = (L + H)/2;
if(ander(X, Middd))
{
L = Middd + 1;
RIght = Middd;
}
else
{
if(Middd < y)
{
L = Middd + 1;
}
else
{
H = Middd - 1;
}
}
}
if(LEFT != -1e9)
{
A += RIght - LEFT + 1;
}
}
cout << A << "\n";
}
int32_t main() {
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
fast;
int t = 1;
// cin >> t;
while (t--)
{
solve();
}
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define in pair<int, int>
#define f first
#define s second
#define pb push_back
#define pob pop_back
#define INF 1e17
#define zero (int)0
#define MX (int)3e5+5
#define fast() ios_base::sync_with_stdio(false); cin.tie(NULL);
const int mod = 1e9+7; //may change to that 99.. number.
signed main()
{
fast();
int a, b, c, d;
cin >> a >> b >> c >> d;
int x = d*c-b;
if(x <= 0)
{
cout << "-1\n";
return 0;
}
int t = a/x;
t+=(a%x>0);
cout << t << "\n";
return 0;
} |
#define rep(i,n) for (int i=0;i<n;i++)
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main() {
ll h,w,co=0;
cin >> h >> w;
vector <vector <char>>s(h,vector<char>(w));
rep(i,h){
rep(j,w){
cin >> s.at(i).at(j);
}
}
//cout << 1 << endl;
rep(i,h){
rep(j,w-1){
if(s.at(i).at(j)=='.' && s.at(i).at(j+1)=='.'){
co++;
}
}
}
// cout << 1 << endl;
rep(i,w){
rep(j,h-1){
if(s.at(j).at(i)=='.' && s.at(j+1).at(i)=='.'){
co++;
}
}
}
cout << co << endl;
} | #include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <fstream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <cstdint>
#include <chrono>
#include <hash_map>
#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 lp(i,a,n) for(ll i=a;i<n;i++)
#define lp2(i,n,a) for(ll i=a-1;i>=n;i--)
#define all(arr,n) arr,arr+n
#define allv(v) (v).begin(),(v).end()
#define rallv(v) (v).rbegin(),(v).rend()
#define m_p make_pair
#define ll long long
#define pii pair<int,int>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<pii>
#define sz(x) (int)x.size()
#define pb push_back
#define endl '\n'
#define Endl '\n'
#define f first
#define s second
#define mem(dp,n) memset(dp,n,sizeof dp)
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
template<typename T>void max_self(T &a,T b){a=max(a,b);}
template<typename T>void min_self(T &a,T b){a=min(a,b);}
int dx[] = { 1 , 0 ,-1 , 0 ,-1 ,-1 , 1 , 1 };
int dy[] = { 0 , 1 , 0 ,-1 ,-1 , 1 ,-1 , 1 };
int KnightX[] = { 2, 1, -1, -2, -2, -1, 1, 2 };
int KnightY[] = { 1, 2, 2, 1, -1, -2, -2, -1 };
void fast(){
std::ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
}
vector<string> vec_splitter(string s) {
s += ',';
vector<string> res;
while(!s.empty()) {
res.push_back(s.substr(0, s.find(',')));
s = s.substr(s.find(',') + 1);
}
return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx,
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
stringstream ss; ss << H;
cerr << args[idx] << " = " << ss.str();
debug_out(args, idx + 1, LINE_NUM, T...);
}
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
const ll mxN=1e6+1,oo=0x3f3f3f3f,MOD=998244353;
const long double PI = acos(-1),eps=1e-9;
void solve(){
int h,w;
cin>>h>>w;
char grid[h][w];
lp(i,0,h){
lp(j,0,w)
cin>>grid[i][j];
}
int res=0;
lp(i,0,h){
lp(j,0,w){
if(grid[i][j]!='.')continue;
lp(k,0,4){
int ti=i+dx[k],tj=j+dy[k];
if(ti>=0&&ti<h&&tj>=0&&tj<w&&grid[ti][tj]=='.')
res++;
}
}
}
cout<<res/2<<endl;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
fast();
int t=1;
//cin>>t;
while(t--)
solve();
return 0;
}
|
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using ll = long long;
#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()
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF (int)1e9
#define LLINF (long long)1e12
#define MOD (int)1e9 + 7
#define PI 3.141592653589
#define PB push_back
#define F first
#define S second
#define co cout <<
#define en << endl;
#define __MAGIC__ \
ios::sync_with_stdio(false); \
cin.tie(nullptr);
#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 Graph vector<vector<int>>
#define PII pair<int, int>
#define VI vector<int>
#define VL vector<long long>
#define VVI vector<vector<int>>
#define VPII vector<pair<int, int>>
#define VS vector<string>
#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))
#define DDD fixed << setprecision(10)
using namespace std;
/*..................DEFINE GLOBAL VARIABLES...................*/
/*.....................DEFINE FUNCTIONS ......................*/
double power(double a, ll n)
{
double r;
ll abs_n;
r = 1;
abs_n = n < 0 ? -n : n;
while (abs_n > 0)
{
if (abs_n % 2 == 1)
{
r *= a;
}
a *= a;
abs_n /= 2;
}
return n >= 0 ? r : 1 / r;
}
double nthroot(double a, ll n)
{
double x, y;
// if (a <= 0 || n < 0)
// {
// return 0;
// }
// if (n == 0)
// {
// return 1;
// }
/* a > 0 かつ n > 0 の場合 */
y = (a > 1) ? a : 1;
do
{
x = y;
y = ((n - 1) * x + a / power(x, n - 1)) / n;
} while (y < x);
return y;
}
ll is_power(ll a)
{
ll i;
if (a == 1)
{
return 1;
}
for (i = 2; i <= floor(log2(a)); i++)
{
if (power(floor(nthroot(a, i)), i) == a)
{
return 1;
}
}
return 0;
}
/*.........................kemkemG0...........................*/
signed main()
{
__MAGIC__
int m, h;
cin >> m >> h;
if (h % m == 0)
{
co "Yes" en
}
else
{
co "No" en
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main(){
long m, h;
long A;
cin >> m >> h;
A = h % m;
if(A == 0)cout << "Yes" << endl;
else cout << "No" << endl;
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll INF = 1e9+7;
ll MOD = 998244353;
typedef pair<ll,ll> ii;
#define iii pair<ll,ii>
#define f(i,a,b) for(ll i = a;i < b;i++)
#define pb push_back
#define vll vector<ll>
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
///I hope I will get uprating and don't make mistakes
///I will never stop programming
///sqrt(-1) Love C++
///Please don't hack me
///@TheofanisOrfanou Theo830
///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst)
///Stay Calm
///Look for special cases
///Beware of overflow and array bounds
///Think the problem backwards
///AtCoder Regular Contest 117
void YESNO(ll a){cout<<(a ? "YES" : "NO")<<"\n";}
int main(void){
ios_base::sync_with_stdio(0);
cin.tie(0);
ll n;
cin>>n;
char arr[n];
ll sum = 0;
ll b = 1;
ll num = n-1;
ll posa[2] = {0};
ll kato = 1;
map<char,ll>mp;
mp['B'] = 0;
mp['W'] = 1;
mp['R'] = 2;
f(i,0,n){
cin>>arr[i];
ll bb = b;
assert(posa[0] >= posa[1]);
if(posa[0] != posa[1]){
b = 0;
}
if(b < 0){
b += 3;
}
sum += (mp[arr[i]] * b) % 3;
sum %= 3;
b = bb;
ll NUM = num;
while(NUM % 3 == 0 && NUM != 0){
posa[0]++;
NUM /= 3;
}
if(NUM % 3 == 2){
b *= -1;
}
NUM = kato;
while(NUM % 3 == 0 && NUM != 0){
posa[1]++;
NUM /= 3;
}
if(NUM % 3 == 2){
b *= -1;
}
kato++;
num--;
}
char ans[3] = {'B','W','R'};
if(n % 2 == 0){
sum = 3 - sum;
sum %= 3;
}
cout<<ans[sum]<<"\n";
}
| #include <bits/stdc++.h>
#define fo(a,b,c) for (a=b; a<=c; a++)
#define fd(a,b,c) for (a=b; a>=c; a--)
#define ll long long
#define add(a,b) a=((a)+(b))%mod
#define mod 3
#define Mod 1
//#define file
using namespace std;
int n,i,j,k,l;
char st[400001];
int a[400001];
int ans;
ll Jc[3];
ll qpower(ll a,int b) {ll ans=1; while (b) {if (b&1) ans=ans*a%mod;a=a*a%mod;b>>=1;} return ans;}
ll cc(int n,int m)
{
ll ans=1;
int i;
fo(i,1,m) ans=ans*(n-i+1)%mod;
return ans*Jc[m];
}
ll C(int n,int m)
{
// int s=1,s2=1;
// fo(i,1,m) s=s*(n-i+1),s2=s2*i;
// s/=s2;
// return s%mod;
if (n<m) return 0;
if (m<3) return cc(n,m);
return C(n/mod,m/mod)*C(n%mod,m%mod)%mod;
}
int turn(char ch)
{
if (ch=='R') return 0;
if (ch=='B') return 1;
if (ch=='W') return 2;
}
char Turn(int t)
{
if (t==0) return 'R';
if (t==1) return 'B';
if (t==2) return 'W';
}
int main()
{
#ifdef file
freopen("c.in","r",stdin);
#endif
Jc[0]=1;
fo(i,1,2) Jc[i]=Jc[i-1]*qpower(i,Mod)%mod;
scanf("%d",&n);
scanf("%s",st+1);
fo(i,1,n)
a[i]=turn(st[i]),add(ans,C(n-1,i-1)*a[i]);
ans=ans*qpower(2,n-1)%mod;
ans=(ans+mod)%mod;
cout<<Turn(ans)<<endl;
fclose(stdin);
fclose(stdout);
return 0;
} |
//! 尺卂乃卂.卂フ乇乇ㄒ
#include<bits/stdc++.h>
//#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
//Using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> Ordered_set;
#define ll long long
#define int long long
#define ld long double
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<vi>
#define vip vector<pii>
#define mii map<int,int>
#define mip map<pair<int,int>,int>
#define mic map<char,int>
#define all(v) v.begin(),v.end()
#define pqb priority_queue<int>
#define pqs priority_queue<int,vi,greater<int> >
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define lb(x) (x&(-x))
#define mod 1000000007
#define inf 1e18
#define ps(x,y) fixed<<setprecision(y)<<x
#define w(x) int x; cin>>x; while(x--)
#define itr(it,v) for(auto it:v)
#define show(arr,n) for(int i=0;i<n;i++) cout<<arr[i]<<" "; cout<<"\n";
#define fi(i,n) for(int i=0;i<n;i++)
#define fir(i,k,n) for(int i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ff first
#define ss second
#define deb(x) cout << #x << "=" << x << endl
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define check(x) (x && cout<<"Yes\n")||(cout<<"No\n");
#define fin(s) freopen(s,"r",stdin);
#define fout(s) freopen(s,"w",stdout);
const ld pi = 3.141592653589793238462643383279502884;
const int xd[]={-1,0,1,0};
const int yd[]={0,-1,0,1};
int XX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int YY[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
int expo(int a,int b,int m);
int mmi(int a,int m);
void ipgraph(int m);
const int N=5*(1e5)+10;
vii adj(N);
int a[N];
void solve(){
}
int dp[31][31];
int32_t main()
{
FIO
int a,b,c; cin>>a>>b>>c;
dp[0][0]=1;
fi(i,31){
fi(j,31){
if(i>0 || j>0)
dp[i][j]=0;
if(i>0) dp[i][j]+=dp[i-1][j];
if(j>0) dp[i][j]+=dp[i][j-1];
}
}
int x=a+b;
while(a>0 && b>0){
if(c>dp[a-1][b]){
c=c-dp[a-1][b];
cout<<'b';
b--;
}
else{
a--;
cout<<'a';
}
}
while(a>0) {
cout<<'a';
a--;
}
while(b>0){
cout<<'b';
b--;
}
cout<<"\n";
return 0;
}
void ipgraph(int m){
int i, u, v;
while(m--){
cin>>u>>v;
u--, v--;
adj[u].pb(v);
adj[v].pb(u);
}
}
int expo(int a,int b,int m){
if(b==0) return 1;
if(b==1) return a;
int val=(expo(a,b/2,m)*expo(a,b/2,m))%m;
if(b & 1) return (val*a)%m;
else return val;
}
int mmi(int a,int m){
return expo(a,m-2,m);
} | #include<bits/stdc++.h>
#define ull unsigned long long
#define ll int64_t
#define f(i,s,e) for(i=s;i<e;++i)
#define endl << "\n"
#define sp << " "
#define INF INFINITY
#define mset(a,b) memset(a,b,sizeof(a))
#define mod 1000000007
#define mp(a,b) make_pair(a,b)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define PI acos(-1)
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define CY cout << "YES\n"
#define CN cout << "NO\n"
#define print(x) for(auto it:x) cout<<it<<' '; cout<<"\n";
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
using namespace std;
ll fpower(ll x,ll y) // without mod
{
if(!x)
return x;
if(!y)
return 1;
return (y&1) ? x*fpower(x*x,y>>1) : fpower(x*x,y>>1) ;
}
bool isWin(vector<ll>&arr1,vector<ll>&arr2)
{
ll s1,s2;
s1 = s2 = 0;
ll i;
f(i,1,10)
{
s1 += i*(fpower(10,arr1[i]));
s2 += i*(fpower(10,arr2[i]));
}
if(s1>s2)
return true;
return false;
}
int main()
{
FAST_IO ;
ll i,j,k,n;
cin >> k;
n = k;
string s,t;
vector<ll>arr1(10,0),arr2(10,0),available(10,0);
cin >> s >> t;
f(i,0,s.size()-1)
arr1[s[i]-'0']++;
f(i,0,t.size()-1)
arr2[t[i]-'0']++;
for(i=1;i<=9;i++)
available[i] = k - arr1[i] - arr2[i];
// print(available);
ll total = 0;
ll win = 0;
for(i=1;i<=9;i++)
{
for(j=1;j<=9;j++)
{
if(!available[i]||!available[j])
continue;
arr1[i]++;
arr2[j]++;
if(i==j)
total += available[i]*(available[j]-1);
else
total += available[i]*available[j];
if(isWin(arr1,arr2))
{
if(i==j)
win += available[i]*(available[j]-1);
else
win += available[i]*available[j] ;
}
arr1[i]--;
arr2[j]--;
}
}
// cout << win sp << total endl;
double ans;
ans = win/(double)total;
cout << setprecision(20) << ans endl;
return 0;
}
/*
If u haven't come up with an approach yet ,skip this one
Try this when feeling stuck -
1. Int overflow, array bounds
2. Special cases (n=1?)
3. Prove your approach to yourself(mathematical induction,counter-intuitive or stronger test cases)
4. Calm down and don't look at standings and stop thinking about rating and think about the question
5. Just do it!
*/
//Benq's advice -
/*
And following advices are must for me -
* do something instead of nothing and stay organized
* WRITE STUFF DOWN
*/
//#define _GLIBCXX_DEBUG
// It will convert WA verdict to runtime error if that error is caused due to out of bound excess , declare it at the top
//#pragma GCC optimize "trapv"
// It will convert WA to runtime error if WA was caused due to int overflow error,declare it anywhere
|
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
int main()
{
int n;
ll w;
cin >> n >> w;
vll need(200000,0ll);
for (int i = 0; i < n; i++)
{
int s,t;
cin >> s >> t;
ll p;
cin >> p;
need[s] += p;
need[t] -= p;
}
for (int i = 1; i < n; i++)
{
need[i] += need[i-1];
}
string ans = "Yes";
for (int i = 0; i < n; i++)
{
if (need[i] > w)
{
ans = "No";
}
}
cout << ans << endl;
} | #include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fast_IO ios::sync_with_stdio(false);
#define DEBUG fprintf(stderr,"Running on Line %d in Function %s\n",__LINE__,__FUNCTION__)
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define fir first
#define sec second
#define mod 998244353
#define int long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
inline int read()
{
char ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();}
int ans=0; while(isdigit(ch)) {ans=ans*10+ch-48;ch=getchar();}
if(nega==-1) return -ans;
return ans;
}
typedef pair<int,int> pii;
void print(vector<int> x){for(int i=0;i<(int)x.size();i++) printf("%d%c",x[i]," \n"[i==(int)x.size()-1]);}
#define N 400005
int s[N],t[N],w[N],n,m,r[N];
int sum[N];
signed main()
{
cin>>n>>m;
for(int i=1;i<=n;i++) s[i]=read(),t[i]=read(),w[i]=read();
int cnt=0;
for(int i=1;i<=n;i++) r[++cnt]=s[i],r[++cnt]=t[i];
sort(r+1,r+cnt+1); int Q=unique(r+1,r+cnt+1)-r-1;
for(int i=1;i<=n;i++) s[i]=lower_bound(r+1,r+Q+1,s[i])-r;
for(int i=1;i<=n;i++) t[i]=lower_bound(r+1,r+Q+1,t[i])-r;
for(int i=1;i<=n;i++) sum[s[i]]+=w[i],sum[t[i]]-=w[i];
int maxn=0;
for(int i=1;i<=Q;i++) sum[i]+=sum[i-1];
for(int i=1;i<=Q;i++) maxn=max(maxn,sum[i]);
if(maxn<=m) cout<<"Yes\n";
else cout<<"No\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
int main() {
ll n, s, d;
cin >> n >> s >> d;
using pll = pair<ll, ll>;
vector<pll> xy(n);
for (int i = 0; i < n; i++) {
cin >> xy.at(i).first >> xy.at(i).second;
}
bool judge = false;
for (int i = 0; i < n; i++) {
if (xy.at(i).first < s && xy.at(i).second > d) {
judge = true;
break;
}
}
if (judge) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
typedef long double ld;
int main() {
int n;int mn=INT_MAX;
cin>>n;
for (int i=0;i<n;i++){
int a,p,x;
cin>>a>>p>>x;
//cout<<x<<" "<<a<<"\n";
if (x-a>0)mn=min(p,mn);
}
if (mn!=INT_MAX)cout<<mn<<"\n";
else cout<<"-1\n";
return 0;
} |
#include <bits/stdc++.h>
#include <stdlib.h>
#include <fstream>
#include <iostream>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;
ll mod(ll a, ll b){
ll ret=a%b;
if(ret<0) ret+=b;
return ret;
}
ll modpow(ll a,ll b,ll c){
ll res=1;
while(b>0){
if(b&1) res=mod(res*a,c);
a=mod(a*a,c);
b>>=1;
}
return res;
}
int GCD(int x,int y){
if(x<y){
swap(x,y);
}
while(x%y!=0){
int temp=x;
x=y;
y=temp%y;
}
return y;
}
int digitsum(int x){
int sum=0;
while(x>0){
sum+=(x%10);
x/=10;
}
return sum;
}
int main() {
int t;
cin>>t;
for(int I=0;I<t;I++){
string s;
cin>>s;
string temp=s;
sort(temp.begin(),temp.end());
reverse(temp.begin(),temp.end());
if(temp<="atcoder"){
cout<<-1<<endl;
continue;
}
string b="atcoder";
if(b<s){
cout<<0<<endl;
continue;
}
for(int i=0;i<s.size();i++){
if(s[i]!='a'){
if(s[i]<='t'){
cout<<i<<endl;
}
else{
cout<<i-1<<endl;
}
break;
}
}
}
return 0;
}
| #include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(nullptr);
#define ll long long
#define l long int
#define f(i, a, b) for(int i=a; i<b; i++)
#define fr(i, a, b) for(int i=a; i>=b; i--)
#define endl '\n'
#define pb push_back
#define pf pop.front()
#define all(x) x.begin(),x.end()
#define debug(x) cerr << #x << " = " << x << endl;
#define lcm(a,b) a*b/__gcd(a,b)
using namespace std;
string s = "atcoder";
int solve()
{
string s1;
cin>>s1;
bool tr = false;
int n = s1.length();
int ans = 0;
for(int i=0;i<n;i++){
if(s1[i]!= 'a')
{
tr = true;
}
}
if(!tr )
return -1;
if(s < s1)
return 0;
int i;
for( i=0;i<n;i++){
if(s1[i] != 'a')
{
break;
}
}
if(s1[i] > 't')
return i-1;
return i;
}
int32_t main()
{
FAST
l T=1;
cin>>T;
while(T--)
{
cout<<solve()<<endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
#include <cstdint>
#include <string>
#include <sstream>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long ll;
using P=pair<ll,ll>;
const int INF=1001001001;
const int mod=1e9+7;
void solve(){
ll t,n;
cin>>t>>n;
int p=100+t;
set<ll>st;
rep(i,100){st.insert(p*i/100);}
vector<ll>b;
rep(i,p*100/100){
if(!st.count(i)){
b.push_back(i);
}
}
ll sz=b.size();
ll x=(n-1)/sz,y=(n-1)%sz;
ll ans=p*x+b[y];
cout<<ans<<endl;
}
int main(){
solve();
return 0;
}
| #include<iostream>
#include<algorithm>
using namespace std;
int main() {
int n;
int k[1001] = {};
cin >> n;
int ans, m, b;
ans = m = b = 0;
int aa = 0;
for (int i = 1;i <= n;i++) {
int a; cin >> a;
aa = max(aa, a);
int j = 2;
while (1) {
if (a%j == 0) {
m = j, k[j]++;
if (a / j == 1) break;
}
j++;
}
ans = max(ans, m);
}
int c = 0;
for (int i = 2;i <= 1000;i++) {
if (c <k[i])c = k[i], ans = i;
}
cout << ans << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define trav(a, A) for (auto & a : A)
#define f first
#define s second
typedef long long ll;
ll MOD = 1e+9+7;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const ll MAXN = 1e+5+7;
int main ()
{
ios_base::sync_with_stdio (0);
cin.tie (0);
ll i, j, n;
string s;
cin >> s;
vector <ll> dp (9*s.size()+2, -INF);
for (i = 0; i < 1LL<<s.size(); ++i)
{
int cs = 0, ca = 0;
for (j = 0; j < s.size (); ++j)
cs += (i>>j&1)*(s[j] - '0'),
ca += (i>>j&1);
dp[cs] = ca;
}
ll ans = -1;
for (i = 0; i < dp.size (); i += 3)
ans = max (ans, dp[i]);
if (ans == 0) cout << -1 << '\n';
else cout << s.size () - ans << '\n';
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
string N;
cin >> N;
int l = N.size();
int zero = 0, one = 0, two = 0;
for (int i = 0; i < l; i++) {
if (N[i]%3 == 1) one++;
else if (N[i]%3 == 2) two++;
else zero++;
}
if (one == 0 && two == 0) cout << 0 << endl;
else if (zero == 0 && one <= 2 && two == 0) cout << -1 << endl;
else if (two == 0) cout << one%3 << endl;
else if (zero == 0 && one == 0 && two <= 2) cout << -1 << endl;
else if (one == 0) cout << two%3 << endl;
else if ((one-two)%3 == 0) cout << 0 << endl;
else cout << 1 << endl;
return 0;
} |
//REST IN THE END NOT IN THE MIDDLE
//CODE STARTS FROM HERE.
#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin>>n;
if(floor(1.08*n)<206){
cout<<"Yay!";
}
if(floor(1.08*n)==206){
cout<<"so-so";
}
if(floor(1.08*n) > 206){
cout<<":(";
}
return 0;
} | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e6+10;
const double eps = 0.01;
inline ll read()
{
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
inline ll pt(ll ans,ll f){
printf("%lld",ans);
if(f==1) putchar(' ');
else putchar('\n');
}
ll n,k,m,tot;
ll a[N],c[N],vis[N];
int main()
{
// freopen("../in.in","r",stdin);
ll _;
char ch[10];
for(int i=0;i<3;i++){
ch[i]=getchar();
}
putchar(ch[1]);
putchar(ch[2]);
putchar(ch[0]);
putchar('\n');
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double dbl;
typedef float flt;
#define for0(i, n) for(ll i=0; i<n; i++)
#define for1(i, n) for(ll i=1; i<=n; i++)
#define forab(i, a, b) for(ll i=a; i<=b; i++)
#define clr0(a) memset(a, 0, sizeof(a))
void solve() {
char a[1010];
cin >> a;
ll n = strlen(a);
bool ans = true;
for0(i, n) {
if (i%2==0) {
if (a[i]<97 || a[i]>122) {
ans = false;
break;
}
}
else {
if (a[i]<65 || a[i]>90) {
ans = false;
break;
}
}
}
if (ans) {
cout << "Yes" << endl;
}
else {
cout << "No" << endl;
}
}
void testcase() {
ll t;
cin >> t;
while (t--) {
solve();
}
}
int main () {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//testcase();
solve();
return 0;
}
| #include <stdio.h>
int main()
{
int i, j, N, A[100] = {}; //入力しないところ1にしておく
int k, GCD, maxGCD = 0, ans = 0;
scanf("%d", &N);//これの存在忘れてた。もっと簡単にできた
for (i = 1; i <= N; i++) {
scanf("%d", &A[i]);
}
for (k = 2; k <= 1000; k++) { //ここたぶんあほ
GCD = 0; //GCD reset
for (j = 1; j <= N; j++) {
if (A[j] % k == 0) { //もし割り切れたら
GCD = GCD + 1; //GCD度
}
}
if (maxGCD < GCD) {
maxGCD = GCD;
ans = k; //そのときのk
}
}
printf("%d", ans);
return(0);
}
//問題点 kの扱い 二重ループにしたらタイムアウトするに違いない
//二重ループで書いてみる |
// Rishabh Singhal
#include<bits/stdc++.h>
#define w(x) int x; cin>>x; for(int tc=1;tc<=x;tc++)
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl;
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define pb push_back
#define endl "\n"
#define mod 1000000007
#define f first
#define s second
#define inf 1e18
using namespace std;
bool cmp(vector<int>a, vector<int>b) {
if (a[1] == b[1]) {
return a[2] < b[2];
} else
return a[1] < b[1];
}
void solve(int tc) {
int n;
cin >> n;
vector<vector<int>>vec;
int a, b, c;
for (int i = 0; i < n; i++) {
cin >> a >> b >> c;
vec.push_back({a, b, c});
}
sort(vec.begin(), vec.end(), cmp);
int ans = 0;
for (int i = 0; i < n; i++) {
int type = vec[i][0];
int x = vec[i][1];
int y = vec[i][2];
for (int j = i + 1; j < n; j++) {
if (type == 1 or type == 3) {
if (vec[j][1] > y) {
} else if (vec[j][1] == y) {
if (vec[j][0] == 1 or vec[j][0] == 2) {
ans++;
}
} else {
ans++;
}
} else {
if (vec[j][1] < y) {
ans++;
}
}
}
}
cout << ans << endl;
}
int32_t main() {
FIO
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
// w(x) {
solve(1);
// }
return 0;
}
//mistakes
// debug fast don't be lazy
// always check for n = 1 condition
// clear the graph -- check index 1 based or 0 based
// set vis to 0
// check constraints of graph question
// use map and set wherever need
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<double,double> pdd;
#define forn(i,x,n) for(int i = x;i <= n;++i)
#define forr(i,x,n) for(int i = n;i >= x;--i)
#define Angel_Dust ios::sync_with_stdio(0);cin.tie(0)
#define x first
#define y second
const int N = 2005;
pdd a[N];
int main()
{
int n;scanf("%d",&n);
forn(i,1,n)
{
int t,l,r;scanf("%d%d%d",&t,&l,&r);
a[i] = {l,r};
if(t == 2) a[i].y -= 0.1;
if(t == 3) a[i].x += 0.1;
if(t == 4) a[i].x += 0.1,a[i].y -= 0.1;
}
int res = 0;
forn(i,1,n) forn(j,i + 1,n)
{
if(min(a[i].y,a[j].y) < max(a[i].x,a[j].x)) continue;
++res;
}
printf("%d\n",res);
return 0;
}
|
// Problem: B - Hydrate
// Contest: AtCoder - AtCoder Beginner Contest 207
// URL: https://atcoder.jp/contests/abc207/tasks/abc207_b
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)
//The code written by Javokhir Akramjonov
#include <bits/stdc++.h>
using namespace std;
//#define file
#define int long long
#define ff first
#define ss second
#define N 111111
#define pb push_back
#define eb emplace__back
#define pii pair<int, int>
#define vi vector<int>
#define rep(i, a, b) for(int i = a; i < b; i ++)
#define trav(x, a) for(auto &x : a)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).end()
#define ios ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int M = 1e9 + 7;
void solution()
{
/*a + bx <= dcx
x >= a / (dc-b);*/
int a, b, c, d;
cin >> a >> b >> c >> d;
if(d * c > b)
{
if(a % (d * c - b) == 0)
cout << a / (d * c - b);
else
cout << a / (d * c - b) + 1;
}
else if(d * c == b)
{
if(a > 0)
cout << -1;
else
cout << 0;
}
else
{
if(a == 0)
cout << 0;
else
cout << -1;
}
}
signed main()
{
#ifdef file
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios;
int t = 1;
//cin >> t;
while(t--)
solution();
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
#define LL long long
#define DD double
#define Pb push_back
#define Bp pop_back
#define Pf push_front
#define Fp pop_front
#define Ub upper_bound
#define Lb lower_bound
#define Bs binary_search
#define In insert
#define Mp make_pair
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)
#define X first
#define Y second
const int mx1 = 65;
const int mx2 = 205;
const int mx3 = 2005;
const int mx4 = 30005;
const int mx5 = 100005;
const int mx6 = 1000005;
typedef vector<int> Vi;
typedef vector<DD> Vd;
typedef vector<bool> Vb;
typedef vector<Vi> VVi;
typedef pair<int, int> Pii;
typedef pair<DD, DD> Pdd;
typedef vector<Pii> Vpi;
typedef vector<Pdd> Vpd;
typedef queue<int> Qi;
typedef stack<int> Si;
typedef deque<int> Di;
int _toggle(int N, int pos) {return N = N ^ (1 << pos);}
int _set(int N, int pos) {return N = N | (1 << pos);}
int _reset(int N, int pos) {return N = N & ~(1 << pos);}
bool _check(int N, int pos) {return (bool)(N & (1 << pos));}
bool _upper(char a) {return a >= 'A' && a <= 'Z';}
bool _lower(char a) {return a >= 'a' && a <= 'z';}
bool _digit(char a) {return a >= '0' && a <= '9';}
int dx[] = {1, -1, 0, 0, -1, -1, 1, 1};
int dy[] = {0, 0, 1, -1, -1, 1, -1, 1};
///******************************************************///
int n;
string s, t;
set<int> st;
void solve()
{
cin >> n >> s >> t;
for(int i = 0; i < n; i++){
if(s[i] == '1'){
st.In(i);
}
}
LL ans = 0;
for(int i = 0; i < n; i++){
if(s[i] == '1' && t[i] == '0'){
st.erase(i);
auto j = st.Lb(i);
if(j == st.end()){
cout << -1 << '\n';
return;
}
ans += (*j - i);
s[*j] = '0';
st.erase(j);
}
if(s[i] == '0' && t[i] == '1'){
auto j = st.Lb(i);
if(j == st.end()){
cout << -1 << '\n';
return;
}
ans += (*j - i);
s[*j] = '0';
st.erase(j);
}
}
cout << ans << '\n';
}
int main()
{
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
fast;
int tc = 1;
//cin >> tc;
while(tc--){
solve();
}
}
|
#include <bits/stdc++.h>
long long extGCD(long long a, long long b, long long c, long long &x, long long &y){
long long a_gcd = a;
long long b_gcd = b;
std::vector< long long > A, B;
A.push_back(a_gcd);
B.push_back(b_gcd);
while(b_gcd != 0){
long long tmp = a_gcd % b_gcd;
a_gcd = b_gcd;
b_gcd = tmp;
A.push_back(a_gcd);
B.push_back(b_gcd);
}
if(c % a_gcd != 0){
x = -1e18;
y = -1e18;
return -1;
}
std::vector< long long > X(A.size()), Y(A.size());
X[A.size() - 1] = c / a_gcd;
Y[A.size() - 1] = 0;
for(int i=A.size()-2; i>=0; i--){
X[i] = Y[i+1];
Y[i] = X[i+1] - (A[i] / B[i]) * X[i];
}
x = X[0];
y = Y[0];
b /= a_gcd;
if(x >= 0){
return x % b;
}else{
long long ret;
ret = b - std::abs(x) % b;
if(ret == b){
ret = 0;
}
return ret;
}
}
int main(){
int T;
std::cin >> T;
std::vector< long long > ans(T);
for(int t=0; t<T; t++){
long long X, Y, P, Q;
std::cin >> X >> Y >> P >> Q;
long long min = 9223372036854775807;
for(int p=P; p<P+Q; p++){
for(int x=X; x<X+Y; x++){
long long ret1, ret2;
long long tmp = extGCD(P+Q, 2*(X+Y), x-p, ret1, ret2);
if(tmp != -1){
min = std::min(min, p + (P+Q) * tmp);
}
}
}
ans[t] = min;
}
for(int i=0; i<T; i++){
if(ans[i] == 9223372036854775807){
std::cout << "infinity" << std::endl;
}else{
std::cout << ans[i] << std::endl;
}
}
return 0;
}
| #pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
using ll = int64_t;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vpii = vector<pii>;
using vpll = vector<pll>;
constexpr char newl = '\n';
constexpr double eps = 1e-10;
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define show(x) cout << #x << " = " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define sz(x) (int)(x).size()
#define YesNo {cout<<"Yes";}else{cout<<"No";}
#define YESNO {cout<<"YES";}else{cout<<"NO";}
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> bool lcmp(const pair<T, T>& l, const pair<T, T>& r) {
return l.first < r.first;
}
template<class T> istream& operator>>(istream& i, v(T)& v) {
F0R(j, sz(v)) i >> v[j];
return i;
}
template<class A, class B> istream& operator>>(istream& i, pair<A, B>& p) {
return i >> p.first >> p.second;
}
template<class A, class B, class C> istream& operator>>(istream& i, tuple<A, B, C>& t) {
return i >> get<0>(t) >> get<1>(t) >> get<2>(t);
}
template<class T> ostream& operator<<(ostream& o, const pair<T, T>& v) {
o << "(" << v.first << "," << v.second << ")";
return o;
}
template<class T> ostream& operator<<(ostream& o, const vector<T>& v) {
F0R(i, v.size()) {
o << v[i] << ' ';
}
o << newl;
return o;
}
template<class T> ostream& operator<<(ostream& o, const set<T>& v) {
for (auto e : v) {
o << e << ' ';
}
o << newl;
return o;
}
template<class T1, class T2> ostream& operator<<(ostream& o, const map<T1, T2>& m) {
for (auto& p : m) {
o << p.first << ": " << p.second << newl;
}
o << newl;
return o;
}
#if 1
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll extGCD(ll a, ll b, pll& out) {
ll l = a, r = b;
ll la = 1, lb = 0, ra = 0, rb = 1;
while (true) {
// l / r = c ... d
ll c = l / r, d = l - r * c;
if (!d) {
out = { ra,rb };
return r;
}
la = la - ra * c;
lb = lb - rb * c;
swap(la, ra);
swap(lb, rb);
l = r; r = d;
}
}
ll mod(ll a, ll b) {
a %= b;
if (a < 0) a += b;
return a;
}
ll solve() {
ll X, Y, P, Q;
cin >> X >> Y >> P >> Q;
/*
i = [0,Y)
j = [0,Q)
2(X+Y)a+X + i == (P+Q)b+P + j
(P+Q)b + P+j == X+i mod 2(X+Y)
(P+Q)b == X+i-P-j mod 2(X+Y)
*/
ll a = 2 * (X + Y), c = (P + Q);
pll out;
ll g = extGCD(a, c, out);
//show(g);
//show(out);
a /= g; c /= g;
// mod a における c の逆数
ll e = out.second;
if (e < 0) e = (-e * (a - 1)) % a;
//cout << "1 / " << c << " = " << e << " mod " << a << newl;
ll re = INT64_MAX;
F0R(i, Y) {
F0R(j, Q) {
ll f = X + i - P - j, b;
if (!f) b = 0;
else if (f % g) continue;
else {
f /= g;
if (f < 0) f += (-f+a-1)/a*a; // -f//a*a
b = (f * e) % a;
}
chmin(re, (c * b)*g + P + j);
}
}
return re >= INT64_MAX ? -1 : re;
}
// INSERT ABOVE HERE
signed main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
int T; cin >> T;
F0R(i, T) {
auto re = solve();
if (re < 0) {
cout << "infinity";
}
else {
cout << re;
}
cout << newl;
}
}
#endif
|
//Code by Ritik Agarwal
#include<bits/stdc++.h>
using namespace std;
#define sz(x) (int)(x).size()
#define int long long int
#define loop(i,a,b) for(int i=a;i<b;i++)
#define scan(arr,n) for (int i = 0; i < n; ++i) cin >> arr[i]
#define vi vector<int>
#define si set<int>
#define pii pair <int, int>
#define sii set<pii>
#define vii vector<pii>
#define mii map <int, int>
#define pb push_back
#define ff first
#define ss second
#define all(aa) aa.begin(), aa.end()
#define rall(a) a.rbegin() , a.rend()
#define read(a,b) int a,b; cin>>a>>b
#define readt(a,b,c) int a,b,c; cin>>a>>b>>c
#define readf(a,b,c,d) int a,b,c,d; cin>>a>>b>>c>>d;
#define print(v) for(auto x:v) cout<<x<<" ";cout<<endl
#define printPair(res) for(pair<int,int>& p:res) cout<<p.first<<" "<<p.second<<endl;
#define faster ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
//***** Constants *****
const int mod = 1000000007; /* 1e9 + 7*/
const int MAXN = 1000005; /*1e6 +5 */
const int mod1= 998244353;
int vis[MAXN]={0};
int fac[300001];
void fact(int m){fac[0]=1;for(int i=1;i<=300000;i++) fac[i]=(fac[i-1]%m * i%m)%m;}
/* Iterative Function to calculate (x^y)%p in O(log y)*/
long long power( long long x, int y, int p){ long long res = 1;
x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p;} return res;}
// Returns n^(-1) mod p
long long modInverse( long long n, int p) { return power(n, p - 2, p); }
long long nCr( long long n,int r, int p) { if (r == 0) return 1; if(n<r) return 0;
return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p; }
int binarySearch(vi arr, int l, int r, int x) {
if (r >= l) { int mid = l + (r - l) / 2; if (arr[mid] == x) return mid;
if (arr[mid] > x) return binarySearch(arr, l, mid - 1, x);
return binarySearch(arr, mid + 1, r, x); } return -1; }
const int NAX=3E5+5;
int BIT[NAX];
int getSum( int index)
{
int sum=0;
while(index>0)
{
sum+=BIT[index];
index -=index & (-index);
}
return sum;
}
void update(int n , int index , int val)
{
while(index<=n)
{
BIT[index]+=val;
index += index & (-index);
}
}
void convert(int arr[], int n)
{
// Create a copy of arrp[] in temp and sort the temp array
// in increasing order
int temp[n];
for (int i=0; i<n; i++)
temp[i] = arr[i];
sort(temp, temp+n);
// Traverse all array elements
for (int i=0; i<n; i++)
{
// lower_bound() Returns pointer to the first element
// greater than or equal to arr[i]
arr[i] = lower_bound(temp, temp+n, arr[i]) - temp + 1;
}
}
void solve(int test)
{
int n;cin>>n;
vi arr(n);
scan(arr,n);
sort(all(arr));
if(n&1) cout<<"Second\n";
else
{
int f=0;
for(int i=-0;i<n;i+=2)
{
if(arr[i]!=arr[i+1])
f=1;
}
if(f==1)
cout<<"First\n";
else
cout<<"Second\n";
}
}
int32_t main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
faster;//fact(mod1);
int t=1;
cin>>t;
for(int test=1;test<=t;test++)
{
solve(test);
}
} | #include <bits/stdc++.h>
using namespace std;
/*
#include <atcoder/all>
using namespace atcoder;
*/
#define rep(i, m, n) for(int(i) = (int)(m); i < (int)(n); ++i)
#define rep2(i, m, n) for(int(i) = (int)(n)-1; i >= (int)(m); --i)
#define REP(i, n) rep(i, 0, n)
#define REP2(i, n) rep2(i, 0, n)
#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
using tp = tuple<ll, ll, ll>;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll)1e9 + 7;
//constexpr long long MOD = 998244353LL;
using ld = long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
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;
}
//グラフ関連
struct Edge {
ll to, cap, rev;
Edge(ll _to, ll _cap, ll _rev) {
to = _to;
cap = _cap;
rev = _rev;
}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
void add_edge(Graph &G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
G[from].push_back(Edge(to, cap, (ll)G[to].size()));
if(revFlag)
G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}
void solve() {
ll n;
cin >> n;
vec<ll> a(n);
map<ll, ll> mp;
REP(i, n) {
cin >> a[i];
mp[a[i]]++;
}
if(n % 2) {
cout << "Second" << en;
} else {
bool flag = true;
for(auto i : mp) {
if(i.second % 2)
flag = false;
}
if(flag)
cout << "Second" << en;
else
cout << "First" << en;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll t;
cin >> t;
while(t--)
solve();
return 0;
}
|
#include <bits/stdc++.h>
#define pb push_back
#define ss second
#define ff first
#define all(x) x.begin(), x.end()
#define INF 3000000000000001 // 3e15
#define ll_max 9000000000000000000
#define PI 3.14159265358979323846L
#define fill(a, n, x) for(int i = 0; i < n; i++) a[i] = x;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> pll;
const ll mod = 1000000007;
const ll N = 200011;
const ll M = log2(N) + 1;
struct point
{
ll x, y;
};
template<typename T>
T fast_exp(T x,T n)
{
if(n == 0) return 1;
T ans = 1;
if( n % 2 == 0)
{
ans = fast_exp(x, n / 2);
ans = ans * ans % mod;
}
else ans = fast_exp(x, n - 1) * x % mod;
return ans;
}
ll fact[N], infac[N];
void work()
{
fact[0] = 1;
infac[0] = 1;
for(ll i = 1; i < N; i++)
{
fact[i] = fact[i - 1] * i % mod;
infac[i] = fast_exp(fact[i], mod - 2);
}
}
ll ncr(ll n, ll r)
{
return fact[n] * infac[n - r] % mod * infac[r] % mod;
}
ll depth[N], anc[N][M];
set<ll> val[N][M];
void dfs(vector<int> tree[], vector<ll> lab[], int x, int p, int d = 0)
{
depth[x] = d;
if(lab[p].size() > 0)
{
for(auto i:lab[p]) val[x][0].insert(i);
}
if(lab[x].size() > 0)
{
for(auto i:lab[x]) val[x][0].insert(i);
}
anc[x][0] = p;
for(int i = 1; i < M; i++)
{
anc[x][i] = anc[anc[x][i - 1]][i - 1];
set<ll> &v1 = val[x][i - 1];
set<ll> &v2 = val[anc[x][i - 1]][i - 1];
for(auto j:v1) val[x][i].insert(j);
for(auto j:v2) val[x][i].insert(j);
while(val[x][i].size() > 10)
val[x][i].erase(val[x][i].begin());
}
for(auto i:tree[x])
{
if(i != p)
dfs(tree, lab, i, x, d + 1);
}
}
set<ll> LCA(ll l, ll r, ll g)
{
set<ll> s;
if(depth[l] != depth[r])
{
if(depth[l] > depth[r])
swap(l, r);
ll x = depth[r] - depth[l];
for(int i = M - 1; i > -1; i--)
{
if(x & (1ll << i)) {
for(auto j:val[r][i]) s.insert(j);
r = anc[r][i];
}
}
}
if(l == r) return s;
for(int i = M - 1; i > -1; i--)
{
if(anc[l][i] != anc[r][i])
{
for(auto j:val[r][i]) s.insert(j);
for(auto j:val[l][i]) s.insert(j);
l = anc[l][i];
r = anc[r][i];
}
}
for(auto j:val[l][0]) s.insert(j);
while(s.size() > g)
s.erase(s.begin());
return s;
}
bool solve(vector<int> tree[], ll x, ll p, ll tar, vector<ll> lab[], set<ll> &s)
{
bool ans = 0;
if(x == tar)
ans = 1;
for(auto i:tree[x])
{
if(i != p)
{
ans = ans | solve(tree, i, x, tar, lab, s);
}
}
if(ans)
{
for(auto i:lab[x]) s.insert(i);
}
return ans;
}
int main()
{
fast;
int _ = 1;
//cin >> _;
int test = 0;
while(_--)
{
test++;
ll n, m, x, y, ans = 0, k;
cin >> n >> m;
ll a[n + 1], b[m + 1];
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = 1; i <= m; i++) cin >> b[i];
ll dp[n + 1][m + 1];
for(int i = 0; i <= n; i++)
{
for(int j = 0; j <= m; j++)
dp[i][j] = i + j - min(i, j);
}
dp[0][0] = 0;
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= m; j++)
{
if(a[i] == b[j]) dp[i][j] = dp[i - 1][j - 1];
dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + 1);
dp[i][j] = min(dp[i][j], dp[i - 1][j] + 1);
dp[i][j] = min(dp[i][j], dp[i][j - 1] + 1);
}
}
cout << dp[n][m] << "\n";
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define deb(x) cout<< #x << " " << x << "\n";
#define MAX 9223372036854775807
#define MIN -9223372036854775807
#define PI 3.141592653589
#define setbits(n) __builtin_popcountll(n)
#define mkunique(a) a.resize(unique(a.begin(),a.end())-a.begin());
const ll mod=1e9+7;
const int N=1010;
ll dp[N][N], n, m;
vector<ll> a,b;
ll go(ll l, ll r){
if(l==n)
return m-r;
if(r==m)
return n-l;
if(dp[l][r]!=-1)
return dp[l][r];
ll ans=mod;
if(a[l]==b[r])
ans=min(ans,go(l+1,r+1));
else
ans=min(ans,1+go(l+1,r+1));
ans=min(ans,1+go(l+1,r));
ans=min(ans,1+go(l,r+1));
//cout<<l<<" "<<r<<" "<<ans<<"\n";
return dp[l][r]=ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll T=clock();
cin>>n>>m;
a.assign(n,0);
b.assign(m,0);
for(ll i=0;i<n;i++)
cin>>a[i];
for(ll i=0;i<m;i++)
cin>>b[i];
memset(dp,-1,sizeof(dp));
cout<<go(0,0);
cerr<<"\n\nTIME: "<<(double)(clock()-T)/CLOCKS_PER_SEC<<" sec\n";
T = clock();
return 0;
} |
//There are no beautiful surface without a terrible depth
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(i=0;i<n;i++)
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define fora(it,x) for(auto it:x)
#define PI 3.14159265
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef long double ld;
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
ll a[1002],b[1002];
int main(){
ll n,m,t,f=0,charge=0;
cin>>n>>m>>t;
charge=n;
forn(i,m){
cin>>a[i]>>b[i];
}
charge-=(a[0]);
forn(i,m){
if(charge<=0){
f=1;
break;
}
charge+=(b[i]-a[i]);
charge=min(charge,n);
if(i!=m-1) charge-=(a[i+1]-b[i]);
else charge-=(t-b[i]);
if(charge<=0){
f=1;
break;
}
//cout<<charge<<" ";
}
if(f==0)cout<<"Yes";
else cout<<"No";
}
| #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define n_l '\n'
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define forn(i,n) for(int i=0;i<n;i++)
#define for1(i,n) for(int i=1;i<=n;i++)
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef double db;
typedef vector<vi> vvi;
const ll mod=1000000007;
const ll N=200005; //check this
int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll powb(ll a,ll b) {ll res=1;a ; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a;a=a*a;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
bool cmp(pair<ll,ll> a, pair<ll,ll> b){
return (a.fi)*2 + a.se > (b.fi)*2 + b.se;
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t=1;
// cin>>t;
while(t--){
int n;cin >> n;
vector<pair<ll,ll>> a(n);
forn(i,n)cin >> a[i].fi >> a[i].se;
sort(all(a),cmp);
vector<ll> suf(n+2,0);
for(int i = n-1;i>=0;i--){
suf[i] = suf[i+1] + a[i].fi;
}
int ans = n;
ll sum = 0;
for(int i = 0;i < n; i++){
sum += a[i].fi + a[i].se;
if(sum > suf[i+1]){
ans = i + 1;
break;
}
}
cout << ans;
}
} |
#include <cmath>
#include <iostream>
using namespace std;
using ll = long long;
int main (int argc, char* argv[]) {
ll s, p;
cin >> s >> p;
auto flag = false;
for (auto i = 1; i < sqrt (p + 1); i++) {
auto j = p / i;
if (i * j != p) continue;
if (i + j == s) {
flag = true;
break;
}
}
cout << (flag ? "Yes" : "No") << endl;
return 0;
}
| /**
* author: BueVonHun 🐼🎋
* More Info: https://github.com/Bue-von-hon
**/
#include <iostream>
#include <algorithm>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <cstring>
#include <cmath>
#include <tuple>
#include <set>
#include <map>
#include <bitset>
#include <sstream>
typedef long long ll;
using namespace std;
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl '\n'
#define mp make_pair
#define pii pair<int,int>
#define piii pair<int,pii>
#define vt vector
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()
#define X first
#define Y second
#define rep(i, n) for (register int i = 0; i < (n); i++)
template <class T> T _min(T a,T b){return (a<b ? a : b);}
template <class T> T _max(T a,T b){return (a>b ? a : b);}
template<class T> void read(T& x) {cin >> x;}
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
ll LCM(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a / GCD(a, b) * b; }
vector<string> vec_splitter(string s) {
s += ',';
vector<string> res;
while(!s.empty()) {
res.push_back(s.substr(0, s.find(',')));
s = s.substr(s.find(',') + 1);
}
return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx,
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
stringstream ss; ss << H;
cerr << args[idx] << " = " << ss.str();
debug_out(args, idx + 1, LINE_NUM, T...);
}
//#define XOX;
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
int INF = numeric_limits<int>::max();
int mod=1e9+7;
inline ll power(ll a, ll n) {
if (n==1) return a;
if (n==0) return 1;
ll ret=1;
if (n%2!=0) ret=(ret*a)%mod;
ll tmp = power(a, n/2);
ll tmp2 = tmp*tmp%mod;
return (ret*tmp2)%mod;
}
inline int MOD(long long n){
if(n >= 0) return n % mod;
return ((-n/mod+1)*mod + n) % mod; // 음수일 경우
}
vt<int> A, B;
int main(void) {
fast_cin();
int n;read(n);
rep(i, n) {
int tmp;read(tmp);
A.pb(tmp);
}
rep(i, n) {
int tmp;read(tmp);
B.pb(tmp);
}
ll ans = 0;
rep(i, n) {
ans += A[i]*B[i];
}
if (ans==0) cout << "Yes" << endl;
else cout << "No" << endl;
return 0;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.