code_file1
stringlengths 87
4k
| code_file2
stringlengths 85
4k
|
---|---|
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
cin >> N;
vector<long long> A(N+1);
for(int i=0;i<N;i++){
cin >> A.at(i+1);
A.at(i+1)+=A.at(i);
}
long long maxans=0;
long long C=0;
long long D=0;
for(int i=0;i<N+1;i++){
D=max(D,A.at(i));
maxans=max(maxans,C+D);
C+=A.at(i);
}
cout << maxans << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<string> vs;
typedef pair<int, int> P;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}
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 MOD = 1e9 + 7;
int main()
{
int n;
cin >> n;
vll a(n);
rep(i, n) cin >> a[i];
vll x(n, 0);
x[0] = a[0];
for(int i = 1; i < n; i++) x[i] = x[i-1] + a[i];
vll maxx(n, 0);
ll mx = 0;
rep(i, n) {
maxx[i] = max(mx, x[i]);
chmax(mx, x[i]);
}
vll p(n+1, 0);
rep(i, n) p[i+1]=p[i]+x[i];
ll ans = 0;
for(int i = 0; i < n; i++) chmax(ans, p[i]+maxx[i]);
cout << ans << endl;
//for(int t:maxx) cout << t << endl;
return 0;
}
|
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>
#include <cassert>
using namespace std;
//using namespace atcoder;
#define REP(i, n) for (int i=0; i<(n); ++i)
#define RREP(i, n) for (int i=(int)(n)-1; i>=0; --i)
#define FOR(i, a, n) for (int i=(a); i<(n); ++i)
#define RFOR(i, a, n) for (int i=(int)(n)-1; i>=(a); --i)
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl;
template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
os << "[";
REP(i, SZ(v)) {
if (i) os << ", ";
os << v[i];
}
return os << "]";
}
template<class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
return os << "(" << p.first << " " << p.second << ")";
}
template<class T>
bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template<class T>
bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return true;
}
return false;
}
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;
const ll MOD = 1e9 + 7;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
const ld eps = 1e-9;
// edit
void solve() {
int N, W;
cin >> N >> W;
int lim = 212345;
vector<ll> neri(lim);
for (int i = 0; i < N; ++i) {
ll s, t, p;
cin >> s >> t >> p;
neri[s] += p;
neri[t] -= p;
}
for (int i = 0; i + 1 < lim; ++i) {
neri[i + 1] += neri[i];
}
for (int i = 0; i < lim; ++i) {
if (neri[i] > W) {
cout << "No" << endl;
return;
}
}
cout << "Yes" << endl;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
// std::ifstream in("input.txt");
// std::cin.rdbuf(in.rdbuf());
solve();
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;
int main() {
ll n, w, ans = 0;
cin >> n >> w;
vector<ll> imos(200005, 0);
rep(i, n) {
ll s, t, p;
cin >> s >> t >> p;
imos[++s] += p;
imos[++t] -= p;
}
bool ok = true;
rep(i, 200004) {
imos[i + 1] += imos[i];
if (imos[i + 1] > w) ok = false;
}
cout << (ok ? "Yes" : "No") << endl;
return 0;
} |
# include <bits/stdc++.h>
using namespace std;
# define endl "\n"
# define io_boost std::ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
typedef unsigned long long int ulli;
typedef long long int lli;
typedef unsigned int ui;
int a[3];
int main(){
cin >> a[0] >> a[1] >> a[2];
if(2 * a[1] == a[2] + a[0]) cout << "Yes" << endl;
else if(2 * a[0] == a[2] + a[1]) cout << "Yes" << endl;
else if(2 * a[2] == a[0] + a[1]) cout << "Yes" << endl;
else cout << "No" << endl;
return 0;
} | #include<bits/stdc++.h>
#define endl '\n'
#define ri register
#define QAQ(m, n) for(ri ll i = m;i <= n;i++)
#define QWQ(m, n) for(ri ll j = m;j <= n;j++)
#define uQAQ(n, m) for(ri ll i = n;i >= m;--i)
#define uQWQ(n, m) for(ri ll j = n;j >= m;--j)
#define ALL(a) a.begin(), a.end()
#define all(a, n) a + 1, a + n + 1
#define fin(a) freopen(a, "r", "stdin")
#define fout(a) freopen(a, "w", "stdout")
#define pb push_back
#define mkp make_pair
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
ll a[4];
int main ()
{
std::cin.tie (0);
std::ios::sync_with_stdio (false);
cin >> a[1] >> a[2] >> a[3];
sort(all(a,3));
cout << ((a[3]-a[2]==a[2]-a[1])?("Yes"):("No"));
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
cout << (2 * a + 100) - b << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define ll long long
#define coYes cout << "Yes" << endl
#define coYES cout << "YES" << endl
#define coyes cout << "yes" << endl
#define coNo cout << "No" << endl
#define coNO cout << "NO" << endl
#define cono cout << "no" << endl
#define BIT_FLAG_0 (1<<0) // 0000 0000 0000 0001
int gcd(int a, int b){ //最大公約数
if(a%b == 0){
return b;
}else{
return gcd(b, a%b);
}
}
ll lcm(ll a, ll b) { //最小公倍数
return a * b / gcd(a, b);
}
ll digit_sum(ll a){ //10進桁和
ll ans=0;
while(a>0){
ans+=a%10;
a/=10;
}
return ans;
}
int main(){
ll a,b;
cin >> a >> b ;
cout << 2*a+100-b << endl;
return 0;
} |
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
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; }
typedef long long ll;
using namespace std;
int main(void){
ll n,k;cin>>n>>k;
vector<pair<ll,ll>> a(n);
rep(i,n) cin>>a[i].first>>a[i].second;
sort(a.begin(),a.end());
ll tmp=0;
rep(i,n){
ll x=a[i].first,y=a[i].second;
if(k<x-tmp){
cout<<tmp+k<<endl;
return 0;
}
k+=y;
}
cout<<tmp+k<<endl;
} | #include <iostream>
#include <algorithm>
using namespace std;
int main(){
long long k, n;
pair<long long, long long> m[(int)2e5];
scanf("%lld%lld", &n, &k);
for (int i=0;i<n;++i){
scanf("%lld%lld", &m[i].first, &m[i].second);
}
sort(m,m+n);
long long current = 0;
for (int i=0;i<n;i++){
if (m[i].first-current > k) break;
k -= m[i].first - current;
current = m[i].first;
k += m[i].second;
}
cout << current + k <<endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define REVERSE(v) reverse((v).begin(), (v).end())
#define MAX(v) (*max_element((v).begin(), (v).end()))
#define MIN(v) (*min_element((v).begin(), (v).end()))
#define pb push_back
#define FOR(i, n) for(int i = 0; i < (n); i++)
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;
const int mod = 1e9 + 7;
const int mod2 = 998244353;
inline void modsum(int&a, int b){a += b;if(a >= mod) a -= mod;if(a < 0) a += mod;}
inline void modmul(int&a, int b){a = 1ll*a*b % mod;}
inline int modexp(ll b, ll p){b %= mod;int res = 1;int mul = b;while(p){if(p&1) modmul(res, mul);p >>= 1;modmul(mul, mul);}return res;}
const int N = 1e5 + 5;
struct E{
int u, c, d;
};
int main(){
ios::sync_with_stdio(false); cin.tie(NULL);
int n, m; cin>>n>>m;
vector<E> g[n+1];
FOR(i, m){
int a, b, c, d; cin>>a>>b>>c>>d;
g[a].pb(E{b, c, d});
g[b].pb(E{a, c, d});
}
set<pair<long long, int>> q;
q.insert({0, 1});
long long dist[n+1];
FOR(i, n+1) dist[i] = 1e18;
bool vis[n+1] = {};
dist[1] = 0;
while(!q.empty()){
pair<long long, int> foo = *q.begin();
q.erase(q.begin());
int cur = foo.second;
if(vis[cur]) continue;
vis[cur] = true;
ll cur_t = dist[cur];
for(E& nxt: g[cur]){
int u = nxt.u, c = nxt.c, d = nxt.d;
//init. cost = c + (d/(cur_t+1))
//min(x + d/(cur_t+1+x)) ?
ll x = max(0ll, (ll)sqrt(d) - cur_t);
ll mn = c + d/(cur_t+1);
for(ll i = max(0ll, x-500); i <= x+500; i++){
mn = min(mn, c + i + d/(cur_t+1+i));
}
if(dist[u] <= dist[cur] + mn) continue;
dist[u] = dist[cur] + mn;
q.insert({dist[u], u});
}
}
if(!vis[n]) cout<<-1;
else cout<<dist[n];
} | //#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define SZ(x) ((int)x.size())
#define uni(x) sort(all(x)),x.resize(unique(all(x))-x.begin());
#define GETPOS(c,x) (lower_bound(all(c),x)-c.begin())
#define lown1(x,val) low(in(x),val)-x
#define lowm1(x,val) low(im(x),val)-x
#define low1(x,nums,val) low(x+1,x+nums+1,val)-x
#define mst(x,val) memset((x),val,sizeof((x)))
#define ls rt<<1
#define rs rt<<1|1
#define lson rt<<1,l,M
#define rson rt<<1|1,M+1,r
#define PI acos(-1)
#define MM int M=(l+r)>>1;
#define fu(i,r,t) for(int i=r;i<=t;i++)
#define fd(i,r,t) for(int i=r;i>=t;i--)
#define fh(i,be,e) for(int i=head[be];~i;i=e[i].next)
#define fa(i,V) for(auto i:V)
#define far(i,V) for(auto &i:V)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define lcm(a,b) ((a)*(b))/__gcd(a,b)
#define cp(i,ans) printf("%.if",ans);
#define cpp(i,ans) cout<<setprecision(i)<<fixed<<ans<<endl;
#define ppb pop_back
#define ppf pop_front
#define pb push_back
#define pf push_front
#define pq priority_queue
#define lowbit(x) ((x)&(-x))
#define all(V) V.begin(),V.end()
#define ms multiset
#define mod(x) (((x)<0)?(x)%mo_num+mo_num:(x)%mo_num)
#define vc vector
#define vct vector<int>
#define SET set<int>
#define dq deque<int>
#define out(i) cout<<(i)<<endl;
#define fi first
#define se second
#define fun(i) fu(i,1,n)
#define fut(i) fu(i,1,t)
#define fum(i) fu(i,1,m)
#define ld long double
#define umap unordered_map
#define Umap unordered_map<int,int>
#define P pair<int,int>
#define mk make_tuple
#define eps 1e-6
//Remember cancel"#define endl '\n'" in interactive questions or use "<<flush"
#define endl '\n'
#define low lower_bound
#define upp upper_bound
#define yn(key) out(key?"YES":"NO")
//#define yn(key) out(key?"Yes":"No")
#define in(i) i+1,i+1+n
#define im(i) i+1,i+1+m
#define ik(i,k) i+1,i+1+k
#define bffs(i) __builtin_ffs(i)
#define bcount(i) __builtin_popcount(i)
#define bone(i) ((1<<i)-1)
#define db double
#define ll long long
#define got(container,num) get<num-1>(container)
#define int long long
#define print(a,n) fun(i)cout<<a[i]<<(i!=n?' ':endl);
#define outcase(x) cout<<"Case #"<<(++case_of_T)<<": "<<(x)<<endl;
#define ptcase(x) printf("Case #%d: %d\n",++case_of_T,x);
#define plcase(x) printf("Case #%lld: %lld\n",++case_of_T,x);
using namespace std;
//Remember to cancel the line below and declare INT=INT_MAX/2; when you want to change long to int
const int INF=LLONG_MAX/4,SINF=0x3f3f3f3f,Lim=1<<20,MINF=LLONG_MAX;
//const int INF=INT_MAX/4,SINF=0x3f;
// use C:printf("%.16f", x); -> printf("%.10f", x); can accelerate the program
const int dx[]={0,0,-1,1},dy[]={-1,1,0,0};//down up left right
const int maxn=1e6+1e5;
int mo_num=1e9+7;
//const int mo_num=998244353;
int n,m,t,a[maxn],b[maxn],ans,case_of_T;
int c[maxn],d[maxn];
vc<P>have;
void change(int z,int y)
{
have.pb({z,y});
swap(c[z],c[y]);
d[c[z]]=z,d[c[y]]=y;
}
void deal(int x)
{
if(b[c[x]]<a[d[x]]){
change(x,d[x]);
return ;
}
while(b[c[x]]>=a[d[x]] && d[x]!=x)deal(d[x]);
if(d[x]!=x)change(x,d[x]);
}
void solve()
{
cin>>n;
fun(i)cin>>a[i];
fun(i)cin>>b[i];
fun(i) {
cin >> c[i], d[c[i]] = i;
if(c[i]!=i && b[c[i]]>=a[i]){out(-1)return;}
}
fun(i)
{
if(d[i]!=i)deal(i);
}
out(have.size())
fa(i,have)cout<<i.fi<<" "<<i.se<<endl;
return ;
}
main()
{
IOS
int T=1;
//cin>>T;
while(T--)solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("-ffloat-store")
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define endl '\n'
#define sz(a) ((int)(a).size())
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define tr(c, it) for (auto it = (c).begin(); (it) != (c).end(); it++)
#define pres(c, val) ((c).find(val) != (c).end()) // for sets, multisets, maps etc.
#define cpres(c, val) (find((c).begin(), (c).end(), val) != (c).end()) // for others
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define forf(i, a, b) for (int i = (a); i < (b); i++)
#define forb(i, a, b) for (int i = (b); i >= (a); i--)
#define fo(i, n) forf(i, 0, n)
#define fob(i, n) forb(i, 0, n - 1)
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;
typedef vector<pair<int, int>> vpii;
const int INF = 9e18;
const int N = 1000000007;
//const int N = 998244353;
const double eps = 1e-9;
const auto start_time = std::chrono::high_resolution_clock::now();
void zark() {
#ifdef ZARK
auto end_time = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> diff = end_time - start_time;
cerr << "Time Taken: " << diff.count() << "s\n";
#endif
}
#ifdef ZARK
#include "/home/aranjan/Desktop/CP/header.h"
#else
#define debug(args...) 42
#endif
/* ------------------ Actual Coding Starts ------------------ */
int mpow(int a, int n) {
a %= N;
if(n == 0) return 1;
else if(n&1) return (mpow(a, n-1)*a)%N;
else {
int k = mpow(a, n/2)%N;
return (k*k)%N;
}
}
int inv(int a) {
a %= N;
return mpow(a, N-2);
}
void solve() {
int n, m;
cin >> n >> m;
vi a(n);
fo(i, n) cin >> a[i];
int s = accumulate(all(a), 0);
int p1 = 1, p2 = 1;
forf(i, m-s+1, m+n+1) p1 = (p1*i)%N;
forf(i, 1, s+n+1) p2 = (p2*i)%N;
int ans = p1;
ans = (ans * inv(p2)) % N;
cout << ans << '\n';
}
int32_t main() {
fastio;
#ifdef ZARK
freopen("input.in", "r", stdin);
#endif
//freopen("sort.in", "r", stdin);
//freopen("txt.out", "w", stdout);
//cout << fixed << setprecision(10);
solve();
zark();
return 0;
} | #pragma GCC optimize("Ofast", "unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
template<ll mod = 1000000007LL>
ll modpow(ll a, ll b){
if (b == 0) return 1LL;
ll tmp = modpow(a * a % mod, b / 2);
if (b % 2 == 0) return tmp;
return tmp * a % mod;
}
template<ll mod = 1000000007LL>
ll comb(ll a, ll b){
ll n = 1, d = 1;
for (ll i = 0; i < b; ++i){
n = n * (i + 1) % mod;
d = d * (a - i) % mod;
}
return d * modpow<mod>(n, mod - 2) % mod;
}
int main(void){
int N; ll M;
cin >> N >> M;
ll S = 0;
for (int i = 0; i < N; ++i){
ll ai; cin >> ai;
S += ai;
}
ll ans = comb(N + M, S + N);
cout << ans << endl;
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,j,n) for(ll i=j;i<n;i++)
#define scn(a) scanf("%lld",&a)
#define scns(a,b) scanf("%lld %lld",&a,&b)
#define print(a) printf("%lld\n",a)
#define vec vector<ll>
#define pb push_back
#define pairs pair<ll,ll>
#define f first
#define s second
#define all(v) v.begin(),v.end()
#define mem(a,b) memset(a,b,sizeof(a))
#define tc ll t;scanf("%lld",&t); while(t--)
#define inf 1e18
const int mod = 1e9+7;
const int N = 5e5+5;
int main()
{
ll n;
scn(n);
ll a[n],p[n],x[n];
rep(i,0,n)
cin>>a[i]>>p[i]>>x[i];
rep(i,0,n)
a[i]*=60;
ll ans=1e10;
rep(i,0,n)
{
ll mn=a[i]/60;
x[i]-=mn;
if(x[i]>0)
ans=min(p[i],ans);
}
if(ans==1e10)
ans=-1;
cout<<ans;
} | //#include <bits/stdc++.h>
#include <cstdio>
//#include <cmath>
//#include <algorithm>
//#include <map>
//#include <iostream>
//#include <string>
//#include <string.h>
//#include <bitset>
//#define _GLIBCXX_DEBUG
//#include <vector>
//#include <regex>
using namespace std;
int N;
int main()
{
scanf("%d", &N);
int A, P, X;
int ans = __INT_MAX__;
for (int i = 0; i < N; i++)
{
scanf("%d%d%d", &A, &P, &X);
if (A < X)
if (P < ans)
ans = P;
}
if (ans == __INT_MAX__)
printf("-1\n");
else
printf("%d\n", ans);
return 0;
}
|
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <climits>
#define rep(i, n) for(int i = 0; i < n; i++)
#define per(i, n) for(int i = n - 1; i >= 0; i--)
using ll = long long;
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define mod 1000000007
using namespace std;
template<class T, class U>
T &chmax(T &a, const U &b){ if(a < b) a = b; return a; }
template<class T, class U>
T &chmin(T &a, const U &b){ if(a > b) a = b; return a; }
struct mint{
ll x;
mint(ll x = 0) : x((x + mod) % mod){}
mint operator-() const{ return mint(-x); }
mint operator+=(const mint &a){
if((x += a.x) >= mod) x -= mod;
return *this;
}
mint &operator++(){
if(++x == mod) x = 0;
return *this;
}
mint operator++(int){
mint temp = *this;
if(++x == mod) x = 0;
return temp;
}
mint &operator-=(const mint &a){
if((x -= a.x) < 0) x += mod;
return *this;
}
mint &operator--(){
if(--x < 0) x += mod;
return *this;
}
mint operator--(int){
mint temp = *this;
if(--x < 0) x += mod;
return temp;
}
mint &operator*=(const mint &a){
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint &a) const{ return mint(*this) += a; }
mint operator-(const mint &a) const{ return mint(*this) -= a; }
mint operator*(const mint &a) const{ return mint(*this) *= a; }
mint pow(ll t) const{
if(!t) return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1) a *= *this;
return a;
}
mint inv() const{ return pow(mod - 2); }
mint &operator/=(const mint &a){ return (*this) *= a.inv(); }
mint operator/(const mint &a) const{ return mint(*this) /= a; }
friend istream &operator>>(istream &is, mint &a){ return is >> a.x; }
friend ostream &operator<<(ostream &os, const mint &a){ return os << a.x; }
};
const int len = 2000020;
vector<mint> fact(len), invfact(len);
mint choose(int n, int r){
return fact[n] * invfact[n - r] * invfact[r];
}
int main(){
fact[0] = fact[1] = 1;
for(int i = 2; i < len; i++) fact[i] = fact[i - 1] * i;
invfact[len - 1] = fact[len - 1].inv();
for(int i = len - 2; i >= 0; i--) invfact[i] = invfact[i + 1] * (i + 1);
int n,m,k;
cin >> n >> m >> k;
if(n > m + k){
cout << "0\n";
return 0;
}
mint ans = choose(n + m, n);
if(n >= k + 1)
ans -= choose(n + m, m + k + 1);
cout << ans << "\n";
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve(ll r,ll x,ll y)
{
double step=sqrt((double)(x*x+y*y)/(r*r));
if (step<1)
{
cout<<2<<endl;
return;
}
if (step>(ll)step)
cout<<(ll)step+1<<endl;
else
cout<<step<<endl;
return;
}
int main()
{
ll r,x,y;
cin>>r>>x>>y;
solve(r,x,y);
//system("pause");
} |
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
void printout(set<int>* g, long* values, long curval, int cn, long* res)
{
curval+=values[cn];
res[cn] = curval;
for (set<int>::iterator it = g[cn].begin();it!=g[cn].end();++it){
if (res[*it]==-1) printout(g,values,curval,*it,res);
}
return;
}
void emain()
{
int n; cin >> n;
pair<int,int> ei[n];
set<int> g[n+1];
int parent[n+1];
for (int i=1;i<n;i++) {
cin >> ei[i].first >> ei[i].second;
g[ei[i].first].insert(ei[i].second);
g[ei[i].second].insert(ei[i].first);
parent[i+1] = 0;
}
parent[1] = -1;
vector<int> toprocess = {1};
int going;
while (toprocess.size()){
going = toprocess.back();
toprocess.pop_back();
for (set<int>::iterator it = g[going].begin(); it!=g[going].end();++it){
if (parent[*it]==0){
toprocess.push_back(*it);
parent[*it]=going;
}
}
}
// for (int i=1;i<=n;i++) cout << parent[i] << " ";
// cout << endl;
long values[n+1];
for (int i=0;i<=n;i++) values[i]=0;
int q; cin >> q;
long total = 0;
int ti,exi;
long xi;
for (int i=0;i<q;i++){
cin >> ti >> exi >> xi;
if (ti==1){
if (ei[exi].first==parent[ei[exi].second]){
values[ei[exi].second]-=xi;
total+=xi;
}
else {
values[ei[exi].first]+=xi;
}
}
else {
if (ei[exi].first==parent[ei[exi].second]){
values[ei[exi].second]+=xi;
}
else {
values[ei[exi].first]-=xi;
total+=xi;
}
}
}
long res[n+1];
for (int i=1;i<=n;i++) res[i] = -1;
printout(g,values,total,1,res);
for (int i=1;i<=n;i++){
cout << res[i] << endl;
}
return;
}
void dmain()
{
int n; cin >> n;
long ai,bi;
long aoki = 0;
long takahashi = 0;
pair<long,long> cities[n];
for (int i=0;i<n;i++){
cin >> ai >> bi;
cities[i] = {2*ai+bi,ai};
aoki+=ai;
}
sort(cities,cities+n,greater<pair<long,long>>());
int i=0;
while (aoki>=takahashi){
aoki-=cities[i].second;
takahashi+=cities[i].first-cities[i].second;
i++;
}
cout << i << endl;
return;
}
void cmain()
{
int n; cin >> n;
map<vector<char>,long> m;
vector<char> si;
string sis;
char c;
int j;
long val;
for (int i=0;i<n;i++){
sis.clear();
cin >> sis;
si.clear();
j=0;
while (j<sis.size()){
si.push_back(sis[j]);
j++;
}
if (si[0]=='!'){
si.erase(si.begin());
val = 1000000;
}
else val = 1;
if (m.count(si)) m[si]+=val;
else m[si]=val;
}
for (map<vector<char>,long>::iterator it=m.begin();it!=m.end();++it){
if (it->second>1000000 && it->second%1000000){
si = it->first;
for (vector<char>::iterator jt = si.begin();jt!=si.end();++jt){
cout << *jt;
}
return;
}
}
cout << "satisfiable" << endl;
return;
}
void bmain()
{
int n; cin >> n;
int x[n];
int y[n];
for (int i=0;i<n;i++){
cin >> x[i] >> y[i];
}
long cpt=0;
for (int i=0;i<n;i++){
for (int j=i+1;j<n;j++){
if (abs(y[i]-y[j])<=abs(x[i]-x[j])) cpt++;
}
}
cout << cpt << endl;
return;
}
void amain()
{
string a,b; cin >> a >> b;
int sa=0;
int sb=0;
sa=a[0]+a[1]+a[2]-48*3;
sb = b[0]+b[1]+b[2]-48*3;
cout << max(sa,sb) << endl;
return;
}
int main()
{
emain();
return 0;
}
| #include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define eps (double)(1e-9)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;
using Graph = vector<vector<int>>;
vector<ll> d, sum;
void dfs1(const Graph &G, int v, int p, int D) {
d[v] = D;
for (auto nv : G[v]) {
if (nv == p)continue;
dfs1(G, nv, v, D+1);
}
}
void dfs2(const Graph &G, int v, int p){
for (auto nv : G[v]) {
if (nv == p)continue;
sum[nv] += sum[v];
dfs2(G, nv, v);
}
}
int main() {
int n, q;
cin >> n;
Graph G(n);
vector<ll> a(n-1), b(n-1);
rep(i, n-1){
cin >> a[i] >> b[i];
a[i]--; b[i]--;
G[a[i]].push_back(b[i]);
G[b[i]].push_back(a[i]);
}
d.resize(n);
sum.resize(n);
dfs1(G, 0, -1, 0);
cin >> q;
rep(i, q){
ll t, e, x;
cin >> t >> e >> x; e--;
if(t == 1){
if(d[a[e]] < d[b[e]]){
sum[0] += x;
sum[b[e]] -= x;
}else{
sum[a[e]] += x;
}
}else{
if(d[b[e]] < d[a[e]]){
sum[0] += x;
sum[a[e]] -= x;
}else{
sum[b[e]] += x;
}
}
}
dfs2(G, 0, -1);
rep(i, n)cout << sum[i] << endl;
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P =pair<int,int>;
#define rep(i,n) for (int i = 0; i < (n); ++i)
int n,m;
std::vector<std::vector<int> > g;
std::map<P, int> v;
std::vector<int> ans;
void bfs(int nowP ,int ncost){
// std::cout << nowP<<":"<<ncost << '\n';
if(ans[nowP]!=-1)return ;
ans[nowP]=ncost;
for(int np :g[nowP]){
if(ans[np]==-1){
int cost =v[P(np,nowP)];
if(cost == ncost){
if(cost+1<n)cost++;
else cost--;
}
bfs(np,cost);
}
}
}
int main(){
std::cin >> n >>m;
ans.resize(n,-1);
g.resize(n,std::vector<int> ());
rep(i,m){
int v1,v2,c1;
std::cin >> v1 >> v2 >>c1;
v1--;v2--;c1--;
g[v1].push_back(v2);
g[v2].push_back(v1);
v[P(v1,v2)]=c1;
v[P(v2,v1)]=c1;
}
bfs(0,0);
rep(i,n){
if(ans[i]==-1){
std::cout << "No" << '\n';
return 0;
}
}
rep(i,n){
std::cout << ans[i]+1 << '\n';
}
return 0;
}
| #include <bits/stdc++.h>
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n, m;
std::cin >> n >> m;
std::vector<std::vector<std::pair<int, int>>> e(n);
for (int i = 0; i < m; ++i) {
int u, v, c;
std::cin >> u >> v >> c;
--u, --v, --c;
e[u].emplace_back(v, c);
e[v].emplace_back(u, c);
}
std::vector<int> a(n, -1);
std::function<void(int, int, int)> dfs = [&](int u, int p, int c) {
if (p == -1) {
a[u] = 0;
} else if (a[p] == c) {
a[u] = (c + 1) % n;
} else {
a[u] = c;
}
for (auto [v, c] : e[u])
if (a[v] == -1) dfs(v, u, c);
};
dfs(0, -1, -1);
for (int i = 0; i < n; ++i) std::cout << a[i] + 1 << "\n";
return 0;
} |
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int MOD=1000000007;
//~ const int MOD=998244353;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
int main(){
int a,b,c,d;cin>>a>>b>>c>>d;
if(a==c&&b==d){
puts("0");return 0;
}
if(abs(a-c)+abs(b-d)<=3){
puts("1");
return 0;
}
if(a+b==c+d||a-b==c-d){
puts("1");
return 0;
}
int x1=a-b,y1=a+b;
int x2=c-d,y2=c+d;
if(abs(x1-x2)<=3||abs(y1-y2)<=3){
puts("2");return 0;
}
if((a+b)%2==(c+d)%2){
puts("2");return 0;
}
puts("3");
} | #include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
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);
}
ll fc[2002002]={1ll},nv[2002002]={1ll};
ll rwpw(ll a, ll p){
ll ret = 1ll;
while(p){
if(p%2){
mul_mod(ret,a);
}
mul_mod(a,a);
p /= 2;
}
return ret;
}
ll c(int n, int k){
if(n<k){
return 0ll;
}
if(k<0){
return 0ll;
}
ll ret = fc[n];
mul_mod(ret,nv[k]);
mul_mod(ret,nv[n-k]);
return ret;
}
int main(void){
int n,m,k,i;
ll ans;
std::cin >> n >> m >> k;
if(n > m+k){
std::cout << "0" << std::endl;
return 0;
}
for(i=1; i<=n+m; ++i){
fc[i] = fc[i-1]*i%MOD;
nv[i] = rwpw(fc[i],MOD-2);
}
ans = c(n+m,n);
add_mod(ans,MOD-c(n+m,n-k-1));
std::cout << ans << std::endl;
return 0;
}
|
//Author: hyperion_1724
//Time and Date: 16:55:26 17 October 2020
//Optional FAST
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")
//Required Libraries
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
//Required namespaces
using namespace std;
using namespace __gnu_pbds;
//Required defines
#define endl '\n'
#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)
//Required typedefs
template <typename T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
template <typename T> using ordered_set1 = tree<T,null_type,greater<T>,rb_tree_tag,tree_order_statistics_node_update>;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
//Required Constants
const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);
const long double PI=3.14159265358979;
// Required random number generators
// mt19937 gen_rand_int(chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 gen_rand_ll(chrono::steady_clock::now().time_since_epoch().count());
//Required Functions
ll power(ll x,ll y)
{
if (y == 0)
return 1;
ll p = power(x, y/2) % MOD;
p = (p * p) % MOD;
return (y%2 == 0)? p : (x * p) % MOD;
}
ll modInverse(ll a)
{
return power(a,MOD-2);
}
//Work
int main()
{
#ifndef ONLINE_JUDGE
if (fopen("INPUT.txt", "r"))
{
freopen ("INPUT.txt" , "r" , stdin);
//freopen ("OUTPUT.txt" , "w" , stdout);
}
#endif
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
clock_t clk;
clk = clock();
//-----------------------------------------------------------------------------------------------------------//
READV(X);
READV(Y);
READV(A);
READV(B);
ll exp=0;
ll curr=0;
while (X<Y)
{
exp=max(exp,curr+((Y-X-1)/B));
if(((Y-1)/X)>=A)
{
curr++;
X=X*A;
}
else
{
break;
}
}
cout<<exp<<endl;
//-----------------------------------------------------------------------------------------------------------//
clk = clock() - clk;
cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << endl;
return 0;
} | #ifdef Prateek
#include "\Prateek.h"
#else
#include <bits/stdc++.h>
using namespace std;
#define debug(...) 42
#endif
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
const int MOD = 1e9+7, N = 1e5 + 10;
using i128 = __int128_t;
int32_t main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
int x, y, a, b;
cin >> x >> y >> a >> b;
int cnt = 0;
i128 n = x;
i128 m = y;
while(n < m) {
i128 na = n*a;
i128 nb = n+b;
if(na <= nb) {
++cnt;
n = na;
} else {
i128 r = na;
if(na > y) {
r = y;
}
r = (r-n+b-1) / b;
n += r*b;
cnt += r;
}
}
cout << cnt-1 << '\n';
return 0;
} |
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
long long n,tot;
struct node{
long long x,y,id;
}a[200010],b[200010];
struct fk{
long long w,id;
}f[10];
bool cx(node u,node v){
return u.x<v.x;
}
bool cy(node u,node v){
return u.y<v.y;
}
bool cf(fk u,fk v){
return u.w<v.w;
}
int main(){
long long i,j,u,v;
cin>>n;
for(i=1;i<=n;i++){
cin>>a[i].x>>a[i].y;
a[i].id=i;
}
memcpy(b,a,sizeof(b));
sort(a+1,a+n+1,cx);
sort(b+1,b+n+1,cy);
f[0].w=a[n].x-a[1].x;
f[0].id=a[n].id*200010+a[1].id;
f[1].w=a[n].x-a[2].x;
f[1].id=a[n].id*200010+a[2].id;
f[2].w=a[n-1].x-a[1].x;
f[2].id=a[n-1].id*200010+a[1].id;
f[3].w=b[n].y-b[1].y;
f[3].id=b[n].id*200010+b[1].id;
f[4].w=b[n].y-b[2].y;
f[4].id=b[n].id*200010+b[2].id;
f[5].w=b[n-1].y-b[1].y;
f[5].id=b[n-1].id*200010+b[1].id;
sort(f,f+6,cf);
if(f[4].id!=f[5].id) cout<<f[4].w<<endl;
else cout<<f[3].w<<endl;
return 0;
} | #include<bits/stdc++.h>
//#include<bits/extc++.h>
using namespace std;
//using namespace __gnu_pbds;
#define int long long
#define pii pair<int,int>
#define float long double
#define fi first
#define se second
#define pb push_back
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define uid uniform_int_distribution<int>
#define forn(i,st,n,inc) for(int i=st;i<n;i+=inc)
#define rforn(i,st,n,inc) for(int i=st-1;i>=n;i-=inc)
//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
//#define ordSet tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
const int MOD = 1e9+7;//998244353;
const int64_t LLINF = 1e18+7;
const int32_t INF = 1e9+7;
ostream& operator<<(ostream& o,const string& s){
for(auto c:s) o<<c;
return o;
}
template<typename F,typename S>
ostream& operator<<(ostream& o,const pair<F,S>& p){
o<<"["<<p.fi<<","<<p.se<<"]";
return o;
}
template<typename... T,template<class...> class C>
ostream& operator<<(ostream& o,const C<T...>& v){
o<<"[";
int tot=0;
for(auto x:v){
o<<x;
if(tot<v.size()-1) o<<",";
tot++;
}
o<<"]";
return o;
}
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...);
}
#ifdef OFFLINE
clock_t Tm=clock();
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...)
#endif
const int MAXN = 2e5+7, MAXX= 1e9;
int n;
int lx=-MAXX,ly=lx;
int rx=-lx,ry=rx;
void domax(int a){
if(a<=ly) return;
if(a>=ry){
ly=ry=a;
lx=-MAXX;
rx=MAXX;
}
lx=a-(ry-rx);
ly=a;
}
void domin(int a){
if(a>=ry) return;
if(a<=ly){
ly=ry=a;
lx=-MAXX;
rx=MAXX;
}
rx=a-(ly-lx);
ry=a;
}
int f(int x){
if(x<=lx) return ly;
if(x>=rx) return ry;
return x+(ry-rx);
}
int32_t main(){
ios_base::sync_with_stdio(false);cin.tie();
//If you hack my code , You are gay
cin>>n;
for(int i=0;i<n;i++){
int a,t;
cin>>a>>t;
if(t==1) ly+=a,ry+=a;
else if(t==2) domax(a);
else domin(a);
}
int q;
cin>>q;
for(int i=0;i<q;i++){
int x;
cin>>x;
cout<<f(x)<<"\n";
}
//mara kha
#ifdef OFFLINE
cerr<<"Time = "<<(double)(clock()-Tm)/CLOCKS_PER_SEC;
#endif
return 0;
} |
#include<bits/stdc++.h>
#define ll long long int
#define mp make_pair
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define mii map<int,int>
#define mll map<long long int,long long int>
#define rep(it,m) for(auto it=m.begin();it!=m.end();it++)
#define pb push_back
#define fr first
#define sc second
#define mod 1000000007LL
#define setbiti(x) __builtin_popcount(x)
#define setbitll(x) __builtin_popcountll(x)
#define vi vector<int>
#define vll vector<long long int>
#define f(i,x,n) for(int i=x;i<n;i++)
#define l(i,a,b) for(int i=a;i>b;i--)
#define w(x) int x; cin>>x; while(x--)
#define all(x) x.begin(),x.end()
#define fill(a,x) memset(a,x,sizeof(a))
#define pie 3.14159265
using namespace std;
void fio() {
/*#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif*/
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
int main() {
fio();
/*int prime[10005]{0};
prime[0]=prime[1]=1;
for(int i=2;i*i<10005;i++){
if(prime[i]==0){
for(int j=i*i;j<10005;j+=i){
prime[j]=1;
}
}
}
int cnt=0;
for(int i=2;i<10001;i++){
if(prime[i]==0)cnt++;
}*/
int n;
cin>>n;
ll ans[n]{0};
f(i,0,n){
if(i==0){
ans[i]=10;
}else if(i==n-1){
ans[i]=15;
}else{
ans[i]=6;
}
}
int j=1,id=-1;
f(i,1,n-1){
ans[i]=ans[i]*j;
j++;
if(ans[i]>10000){
id=i;
break;
}
}
if(id!=-1){
j=2;
int v=-1;
for(int i=id;i<n-1;i++){
ans[i]=10;
while((ans[i]*j)%6==0){
j++;
}
ans[i]=ans[i]*j;
if(ans[i]>10000){
v=i;
break;
}
j++;
}
if(v!=-1){
j=2;
f(i,v,n-1){
ans[i]=15;
while((ans[i]*j)%6==0 || (ans[i]*j)%10==0){
j++;
}
ans[i]=ans[i]*j;
j++;
}
}
}
f(i,0,n){
cout<<ans[i]<<" ";
}
cout<<endl;
return 0;
} | #include <bits/stdc++.h>
int main() {
using namespace std;
ios_base::sync_with_stdio(false), cin.tie(nullptr);
int N; cin >> N;
cout << 105 << ' ';
N--;
for (int v = 2; N > 0; v += 2) {
if (v % 3 == 0 || v % 5 == 0 || v % 7 == 0) {
cout << v << " \n"[--N == 0];
}
}
return 0;
}
// We'll 15, and anything that's even and a multiple of 3 or 5
// 7 / 15
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(a) a.begin(),a.end()
typedef pair<ll,ll> pi;
//__builtin_popcountll(2) (the number of ones in the binary representation)
//__builtin_clz(2) (number of leading zeroes)
//__builtin_ctz(2) (number of trailing zeroes)
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>*/
// s.find_by_order(k)(returns iterator to kth element), s.order_of_key(k)(number of elements less than number)
ll mod = 1e9+7;
vector<ll> fact(1);
/*vector<ll> spf(10000005), cntPrime(10000005);
void spff(){
int i;
for(i=1;i<10000005;i++) spf[i] = i;
for(i=2;i*i<10000005;i++)
{
if(spf[i] != i) continue;
for(int j = i*i; j < 10000005; j+= i){
if(spf[j]==j) spf[j] = i;
}
}
for(i=1;i<10000005;i++){
if(spf[i] != spf[i/spf[i]]){
cntPrime[i] = cntPrime[i/spf[i]]+1;
}
else cntPrime[i] = cntPrime[i/spf[i]];
}
}
while(spf[a[i]]!=a[i]){
z=spf[a[i]];
while(a[i]%z==0) a[i]/=z;
m[z]++;
}
if(a[i]>1) m[a[i]]++;*/
ll gcd(ll a, ll b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
ll power(ll x, ll y)
{
ll temp;
if( y == 0)
return 1;
temp = power(x, y/2);
if (y%2 == 0)
return temp*temp;
else
return x*temp*temp;
}
ll power(ll x, ll y, ll p)
{
ll res = 1;
x = x % p;
while (y > 0) {
if (y & 1) res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
ll modInv(ll n, ll p)
{
return power(n, p - 2, p);
}
ll ncr(ll n, ll r) {return (n>=r?(fact[n]*modInv(fact[r],mod))%mod*modInv(fact[n-r],mod)%mod:0);}
ll add(ll a, ll b) {ll z=a+b; if(z>=mod) z -= mod; return z;}
ll sub(ll a, ll b) { return (a-b+mod)%mod;}
// LLONG_MAX
vector<ll> v[25], vis(25), ver;
ll z;
void dfs(ll x){
vis[x]=1;
ver.pb(x);
for(auto i: v[x]){
if(vis[i]) continue;
dfs(i);
}
}
void solve(ll idx, vector<ll>& col){
if(idx == ver.size()){
z++; return;
}
vector<ll> a{1,2,3};
for(auto i: v[ver[idx]]){
if(find(all(a),col[i]) != a.end()) a.erase(find(all(a),col[i]));
}
for(auto i: a){
col[ver[idx]] = i;
solve(idx+1, col);
}
col[ver[idx]] = 0;
}
int main()
{
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
ll t=1,n,i,j,m,a,b;
//cin>>t;
//fact[0]=1;
//for(i=1;i<300003;i++)fact[i]=(fact[i-1]*i)%mod;
while(t--)
{
cin>>n>>m;
for(i=0;i<m;i++){
cin>>a>>b;
v[a].pb(b);
v[b].pb(a);
}
ll ans=1;
for(i=1;i<=n;i++){
ver.clear();
if(!vis[i]){
z=0;
dfs(i);
vector<ll> col(n+2);
solve(0, col);
ans*=z;
}
}
cout<<ans;
}
}
| #include <bits/stdc++.h>
using namespace std;
void dfs(const int64_t s, const vector<vector<int>>& g,
vector<bool>& v, vector<int>& p) {
if (v[s]) return;
p.push_back(s), v[s] = true;
for (auto i = 0; i < (int)g[s].size(); i++)
if (g[s][i] == 1) dfs(i, g, v, p);
}
void dfs2(const int64_t s, const vector<vector<int>>& g,
const vector<int>& p, vector<int>& color,
int64_t& ans) {
if (s == (int)p.size()) {
ans++;
return;
}
bool b[3] = {};
for (auto i = 0; i < s; i++) {
if (not g[p[i]][p[s]]) continue;
b[color[i]] = 1;
}
for (auto i = 0; i < 3; i++)
if (not b[i]) {
color[s] = i;
dfs2(s + 1, g, p, color, ans);
color[s] = -1;
}
}
int main() {
int64_t n, m, ans = 1;
cin >> n >> m;
vector<vector<int>> g(n, vector<int>(n, 0));
vector<bool> v(n, false);
for (auto i = 0; i < m; i++) {
int a, b;
cin >> a >> b, a--, b--;
g[a][b] = 1, g[b][a] = 1;
}
for (auto i = 0; i < n; i++) {
if (v[i]) continue;
vector<int> p, c;
dfs(i, g, v, p);
c.assign(p.size(), -1);
int64_t cnt = 0;
c[0] = 1;
dfs2(1, g, p, c, cnt);
ans *= (cnt * 3);
}
cout << ans << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
t=0; char ch=getchar(); int f=1;
while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
int n,m,X[100010],Y[100010],c[110];
vector<int> g[110];
int ans[110][110];
bool vis[110];
int st[110],tot,inst[110];
void dfs(int u,int p) {
//printf("%d\n",u);
vis[u]=1; st[++tot]=u; inst[u]=1;
for (int i=0,v;i<g[u].size();i++) {
v=g[u][i];
if (v==p) continue;
if (!vis[v]) {
dfs(v,u);
ans[u][v]=1,ans[v][u]=0;
} else if (inst[v]) {
ans[u][v]=1,ans[v][u]=0;
}
}
inst[u]=0,tot--;
}
vector<int> G[110];
int t[110],cnt;
void ddfs(int u) {
if (t[u]) return;
t[u]=1,cnt++;
for (int i=0,v;i<G[u].size();i++) {
v=G[u][i];
ddfs(v);
}
}
int main() {
//freopen("1.txt","r",stdin);
read(n),read(m); int x,y;
for (int i=1;i<=m;i++) {
read(x),read(y);
X[i]=x,Y[i]=y;
}
memset(ans,-1,sizeof(ans));
for (int i=1;i<=n;i++) read(c[i]);
for (int i=1;i<=m;i++) {
x=X[i],y=Y[i];
if (c[x]==c[y]) {
g[x].push_back(y),g[y].push_back(x);
//printf("add %d %d\n",x,y);
} else {
if (c[x]>c[y]) ans[x][y]=1,ans[y][x]=0; else ans[y][x]=1,ans[x][y]=0;
}
}
for (int i=1;i<=n;i++) if (!vis[i]) {
dfs(i,0);
}
for (int i=1;i<=m;i++) {
x=X[i],y=Y[i];
if (ans[x][y]) puts("->");
else puts("<-");
//if (ans[x][y]) G[x].push_back(y);//,printf("%d %d\n",x,y);
//else G[y].push_back(x);//,printf("%d %d\n",y,x);
}
/*
for (int i=1;i<=n;i++) {
for (int j=1;j<=n;j++) t[j]=0; cnt=0;
ddfs(i);
if (cnt!=c[i]) puts("WA");
//printf("%d ",cnt);
}
//puts("");
puts("AC");*/
return 0;
}
/*
0. Enough array size? Enough array size? Enough array size? Interger overflow?
1. Think TWICE, Code ONCE!
Are there any counterexamples to your algo?
2. Be careful about the BOUNDARIES!
N=1? P=1? Something about 0?
3. Do not make STUPID MISTAKES!
Time complexity? Memory usage? Precision error?
*/ | #include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;
vector<int> solve(const vector<int>& A, const vector<int>& B){
const int N = A.size();
vector<int> res(N, -1);
int last = -1;
for(int i=0;i<N;i++){
if(A[i] == B[i]){
res[i] = 0;
last = i;
} else if(A[i] < B[i]){
last = -1;
} else if(last != -1){
int L = last, R = i;
while(R-L > 1){
int mid = (L+R)/2;
int dst = A[mid] + i - mid;
if(dst <= B[i]) L = mid;
else R = mid;
}
if(A[L]+i-L == B[i]){
res[i] = i-L;
}
}
}
for(int i=N-1;i>0;i--){
if(res[i] > 0 && res[i-1] < res[i]) res[i] = 1;
}
return res;
}
int main(){
int N, L; cin >> N >> L;
vector<int> A(N+2, 0), B(N+2, 0);
for(int i=1;i<=N;i++) cin >> A[i];
for(int i=1;i<=N;i++) cin >> B[i];
A.back() = L+1;
B.back() = L+1;
vector<int> res(N+2, -1);
auto v = solve(A, B);
for(int i=0;i<N+2;i++) if(v[i] != -1) res[i] = v[i];
reverse(A.begin(), A.end());
reverse(B.begin(), B.end());
for(auto& t : A) t = L+1-t;
for(auto& t : B) t = L+1-t;
v = solve(A, B);
for(int i=0;i<N+2;i++) if(v[i] != -1) res[N+1-i] = v[i];
if(all_of(res.begin(), res.end(), [](int t){ return t != -1; })){
cout << accumulate(res.begin(), res.end(), 0LL) << endl;
} else {
cout << -1 << endl;
}
} |
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int N,M;
cin>>N>>M;
vector<int> A(M),B(M);
rep(i,M) cin>>A[i]>>B[i];
rep(i,M){
A[i]--;B[i]--;
}
vector<vector<int>> direct(N,vector<int> (N,0));
rep(i,M){
direct[A[i]][B[i]]=1;
direct[B[i]][A[i]]=1;
}
vector<int> complete((1<<N),0);
for(int bit=0;bit<(1<<N);bit++){
vector<int> v;
rep(i,N) if(bit&(1<<i)) v.push_back(i);
bool ng=false;
for(int i=0;i<v.size();i++) for(int j=i+1;j<v.size();j++){
if(direct[v[i]][v[j]]==0){
ng=true;
break;
}
}
if(ng==false) complete[bit]=1;
}
vector<int> dp((1<<N),-1);
auto dfs =[&](auto &&dfs,int state)->int{
if(dp[state]!=-1) return dp[state];
if(state==0) return 0;
int res=MOD;
for(int T=state;;T=(T-1)&state){
if(T==0) break;
if(complete[T]==0) continue;
chmin(res,dfs(dfs,state^T));
}
return dp[state]=res+1;
};
int ans=dfs(dfs,(1<<N)-1);
cout<<ans<<endl;
return 0;
}
| #include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpll vector<pll>
#define vpii vector<pii>
#define umap unordered_map
#define uset unordered_set
#define PQ priority_queue
#define printa(a, L, R) \
for (int i = L; i < R; i++) \
cout << a[i] << (i == R - 1 ? '\n' : ' ')
#define printv(a) printa(a, 0, a.size())
#define print2d(a, r, c) \
for (int i = 0; i < r; i++) \
for (int j = 0; j < c; j++) \
cout << a[i][j] << (j == c - 1 ? '\n' : ' ')
#define pb push_back
#define eb emplace_back
#define UB upper_bound
#define LB lower_bound
#define F first
#define S second
#define mem(a, x) memset(a, x, sizeof(a))
#define inf 1e18
#define E 2.71828182845904523536
#define gamma 0.5772156649
#define nl "\n"
#define lg(r, n) (int)(log2(n) / log2(r))
#define rev(v) reverse(v.begin(), v.end())
#define srt(v) sort(v.begin(), v.end())
#define grtsrt(v) sort(v.begin(), v.end(), greater<ll>())
#define all(v) v.begin(), v.end()
#define mnv(v) *min_element(v.begin(), v.end())
#define mxv(v) *max_element(v.begin(), v.end())
#define toint(a) atoi(a.c_str())
#define BeatMeScanf ios_base::sync_with_stdio(false)
#define one(x) __builtin_popcount(x)
#define Unique(v) v.erase(unique(all(v)), v.end())
#define fout(x) fixed << setprecision(x)
#define debug(args...) \
{ \
string _s = #args; \
replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); \
istream_iterator<string> _it(_ss); \
deb(_it, args); \
}
void deb(istream_iterator<string> it)
{
}
template <typename T, typename... Args>
void deb(istream_iterator<string> it, T a, Args... args)
{
cout << *it << " = " << a << endl;
deb(++it, args...);
}
const int mod = 1e9 + 7;
const int N = 100000;
const ld eps = 1e-9;
const ld PI = acos(-1.0);
// template <typename T>
// using o_set = tree<T, null_type, less<T>,
// rb_tree_tag, tree_order_statistics_node_update>;
//random_device rd;
//mt19937 random(rd());
ll gc(ll a, ll b)
{
while (b)
{
ll x = a % b;
a = b;
b = x;
}
return a;
}
ll lc(ll a, ll b) { return a / gc(a, b) * b; }
ll qpow(ll n, ll k)
{
ll ans = 1;
assert(k >= 0);
n %= mod;
while (k > 0)
{
if (k & 1)
ans = (ans * n) % mod;
n = (n * n) % mod;
k >>= 1;
}
return ans % mod;
}
ll g[20][20], n, m;
ll dp[1LL<<20];
void solve()
{
cin>>n>>m;
for(int i=1;i<=m;i++)
{
ll x, y;
cin>>x>>y;
x--, y--;
g[x][y]=1;
g[y][x]=1;
}
for(ll i=1;i<(1LL<<n);i++)
{
if(__builtin_popcount(i)==1)
{
dp[i]=1;
continue;
}
vll v;
for(ll j=0;j<n;j++)
{
if(i&(1LL<<j)) v.pb(j);
}
int f=0;
for(int a=0;a<v.size();a++)
{
for(int b=a+1;b<v.size();b++)
{
if(g[v[a]][v[b]]==0) f=1;
if(f) break;
}
if(f) break;
}
if(f) continue;
dp[i]=1;
// debug(i, dp[i]);
}
for(ll i=1;i<(1LL<<n);i++)
{
if(dp[i]!=0) continue;
ll mn=LLONG_MAX;
for(ll x=(i-1)&i;x>0;x=(x-1)&i)
{
mn=min(mn, dp[x]+dp[x^i]);
}
dp[i]=mn;
}
cout<<dp[(1LL<<n)-1]<<nl;
}
int main()
{
BeatMeScanf;
ll t=1;
// cin>>t;
int cs=0;
while(t--){
solve();
}
return 0;
}
|
#include<bits/stdc++.h>
namespace my_std{
using namespace std;
#define pii pair<int,int>
#define fir first
#define sec second
#define MP make_pair
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
#define drep(i,x,y) for (int i=(x);i>=(y);i--)
#define go(x) for (int i=head[x];i;i=edge[i].nxt)
#define templ template<typename T>
#define sz 202020
typedef long long ll;
typedef double db;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
templ inline T rnd(T l,T r) {return uniform_int_distribution<T>(l,r)(rng);}
templ inline bool chkmax(T &x,T y){return x<y?x=y,1:0;}
templ inline bool chkmin(T &x,T y){return x>y?x=y,1:0;}
templ inline void read(T& t)
{
t=0;char f=0,ch=getchar();double d=0.1;
while(ch>'9'||ch<'0') f|=(ch=='-'),ch=getchar();
while(ch<='9'&&ch>='0') t=t*10+ch-48,ch=getchar();
if(ch=='.'){ch=getchar();while(ch<='9'&&ch>='0') t+=d*(ch^48),d*=0.1,ch=getchar();}
t=(f?-t:t);
}
template<typename T,typename... Args>inline void read(T& t,Args&... args){read(t); read(args...);}
char __sr[1<<21],__z[20];int __C=-1,__zz=0;
inline void Ot(){fwrite(__sr,1,__C+1,stdout),__C=-1;}
inline void print(int x)
{
if(__C>1<<20)Ot();if(x<0)__sr[++__C]='-',x=-x;
while(__z[++__zz]=x%10+48,x/=10);
while(__sr[++__C]=__z[__zz],--__zz);__sr[++__C]='\n';
}
void file()
{
#ifdef NTFOrz
freopen("a.in","r",stdin);
#endif
}
inline void chktime()
{
#ifdef NTFOrz
cerr<<clock()/1000.0<<'\n';
#endif
}
#ifdef mod
ll ksm(ll x,int y){ll ret=1;for (;y;y>>=1,x=x*x%mod) if (y&1) ret=ret*x%mod;return ret;}
ll inv(ll x){return ksm(x,mod-2);}
#else
ll ksm(ll x,int y){ll ret=1;for (;y;y>>=1,x=x*x) if (y&1) ret=ret*x;return ret;}
#endif
// inline ll mul(ll a,ll b){ll d=(ll)(a*(double)b/mod+0.5);ll ret=a*b-d*mod;if (ret<0) ret+=mod;return ret;}
}
using namespace my_std;
int n;
vector<ll>a[3];
int main()
{
file();
map<char,int>mp; mp['R']=0,mp['G']=1,mp['B']=2;
read(n);
ll x; char cc;
rep(i,1,n*2) read(x),cin>>cc,a[mp[cc]].push_back(x);
rep(i,0,2) sort(a[i].begin(),a[i].end());
auto qq=[&](int id,ll w)
{
if (!a[id].size()) return ll(1e18);
int t=lower_bound(a[id].begin(),a[id].end(),w)-a[id].begin(); ll res=1e18;
if (t) chkmin(res,w-a[id][t-1]);
if (t!=(int)a[id].size()) chkmin(res,a[id][t]-w);
return res;
};
int c=0,p=0; rep(i,0,2) if (a[i].size()%2==0u) ++c,p=i; if (c==3) return puts("0"),0;
ll ans=1e18;
rep(i,0,2) if (i!=p) for (auto x:a[i]) chkmin(ans,qq(3-i-p,x));
int p1=(p==0?1:0),p2=3-p-p1;
auto wk=[&](){ll mn=1e18;for (auto x:a[p]) chkmin(ans,mn+qq(p2,x)),chkmin(mn,qq(p1,x));};
wk(); swap(p1,p2); wk();
cout<<ans;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef pair<int,int> pi;
typedef pair<lld,lld> pl;
typedef pair<int,lld> pil;
typedef pair<lld,int> pli;
typedef vector<int> vit;
typedef vector<vit> vitt;
typedef vector<lld> vlt;
typedef vector<vlt> vltt;
typedef vector<pi> vpit;
typedef vector<vpit> vpitt;
typedef long double ld;
#define x first
#define y second
#define pb push_back
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define mk(a,b) make_pair(a,b)
bool isrange(int y,int x,int n,int m){
if(0<=y&&y<n&&0<=x&&x<m) return true;
return false;
}
int dy[4] = {1,0,-1,0},dx[4]={0,1,0,-1},ddy[8] = {1,0,-1,0,1,1,-1,-1},ddx[8] = {0,1,0,-1,1,-1,1,-1};
vector<pair<lld,int> > v1,v2;
vector<lld> v[3];
void solve(int tc){
int n;
cin >> n;
for(int e=0;e<n*2;e++){
lld x;
char y[2];
cin >> x >> y;
if(y[0]=='B') v[0].push_back(x);
else if(y[0]=='R') v[1].push_back(x);
else v[2].push_back(x);
}
for(int e=0;e<3;e++) sort(all(v[e]));
int f1 = -1,f2 = -1,f3 = -1;
for(int e=0;e<3;e++){
if(sz(v[e])%2){
if(f1==-1) f1 = e;
else if(f2==-1) f2 = e;
}else{
f3 = e;
}
}
if(f1==-1){
cout << "0";
}else{
lld ans1 = 1e18;
for(int e=0;e<sz(v[f1]);e++){
lld x = v[f1][e];
int wh = lower_bound(all(v[f2]),x) - v[f2].begin();
if(wh!=sz(v[f2])){
ans1 = min(ans1,abs(v[f2][wh]-x));
}
if(wh){
wh--;
ans1 = min(ans1,abs(v[f2][wh]-x));
}
}
for(int e=0;e<sz(v[f3]);e++){
lld x = v[f3][e];
int wh = lower_bound(all(v[f1]),x) - v[f1].begin();
lld ans2 = 1e18;
if(wh!=sz(v[f1])){
ans2 = min(ans2,abs(v[f1][wh]-x));
}
if(wh){
wh--;
ans2 = min(ans2,abs(v[f1][wh]-x));
}
v1.push_back(mk(ans2,e));
}
for(int e=0;e<sz(v[f3]);e++){
lld x= v[f3][e];
int wh = lower_bound(all(v[f2]),x) - v[f2].begin();
lld ans3 = 1e18;
if(wh!=sz(v[f2])){
ans3 = min(ans3,abs(v[f2][wh]-x));
}
if(wh){
wh--;
ans3 = min(ans3,abs(v[f2][wh]-x));
}
v2.push_back(mk(ans3,e));
}
sort(all(v1));
sort(all(v2));
lld ans2 = 1e18;
for(int e=0;e<min(sz(v1),3);e++){
for(int p=0;p<min(sz(v2),3);p++){
if(v1[e].y!=v2[p].y){
ans2 = min(ans2,v1[e].x+v2[p].x);
}
}
}
cout << min(ans1,ans2);
}
}
int main(void){
ios_base :: sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int tc = 1;
/*
cin >> tc;
*/
for(int test_number=1;test_number<=tc;test_number++){
solve(test_number);
}
return 0;
} |
#include<cstdio>
#include<set>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<cstdlib>
#include<time.h>
#include<string>
#include<stack>
#include<cmath>
#include<iostream>
#include<cstring>
#include<complex>
#include<tr1/unordered_set>
#include<tr1/unordered_map>
#include<climits>
#include<chrono>
#include<iomanip>
using namespace std;
using namespace tr1;
#define FOR(i,j,k) for(int i=j;i<k;i++)
#define FORD(i,j,k) for(int i=j;i>=k;i--)
#define ll long long
//Make sure no overflow problems
#define pii pair<ll, ll>
#define vi vector<int >
#define pb push_back
#define mp make_pair
#define ff first
#define nitro_boost ios_base::sync_with_stdio(0); cin.tie(0),cout.tie(0);
#define ss second
#define VAR(i,n) __typeof(n) i = (n)
#define FOREACH(i,c) for(VAR(i,(c).begin());i!=(c).end();i++)
#define FORDEACH(i,c) for( VAR(i,(c).rbegin()),i!=(c).rend();i++)
#define REP(i,n) FOR(i,0,n)
#define ld long double
const int INF = 1000000009;
const long long INFLL = (ll)INF * (ll)INF;
const ld EPS = 10e-9;
///////////////////////////////////////////////////////////////
#define curr_time std::chrono::high_resolution_clock::now()
int main(){
nitro_boost;
ll N,C;
cin>>N>>C;
vector<pii> event;
for(ll i=0;i<N;i++){
ll a,b,c;
cin>>a>>b>>c;
event.push_back({a-1,c});
event.push_back({b,-c});
}
sort(event.begin(),event.end());
ll ans=0,fee=0,t=0;
for(auto [x,y]: event){
if(x!=t){
ans+=min(C,fee)*(x-t);
t=x;
}
fee+=y;
}
cout<<ans<<"\n";
return 0;
} | #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
#define rep(i,n) for(int i=0; i<(int)n; i++)
#define llrep(i,n) for(ll i=0; i<(ll)n; i++)
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてから使う
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define kiriage(x,y) (((x)+(y)-1)/(y))
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vp;
int main(){
ll n,cost; cin>>n>>cost;
vll a(n),b(n),c(n);
rep(i,n) cin>>a[i]>>b[i]>>c[i];
map<ll, ll>mp;
rep(i,n){
mp[a[i]] += c[i];
mp[b[i]+1] -= c[i];
}
ll sum = 0;
ll tmp = 0;
ll pre = 0;
for (auto p:mp){
sum += min(tmp, cost) * (p.first-pre);
tmp += p.second;
pre = p.first;
}
cout << sum << endl;
} |
#include <bits/stdc++.h>
using namespace std;
int main(){
int n,a,b;
cin>>n>>a>>b;
cout<<n-a+b<<endl;
return 0;
} | #include<iostream>
#include<cmath>
#include<bits/stdc++.h>
#include<string.h>
using namespace std;
typedef long long int ll;
const ll maxn=1e15;
const ll mod=1e9+7;
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n,a,b;
cin>>n>>a>>b;
cout<<(n-a)+b<<"\n";
cerr<<"\nTime elapsed:"<< 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
return 0;
}
|
#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
const long long MOD = 1000000007;
template<const long long MOD>
class Modint{
public:
Modint() : x(0) {
}
Modint(long long y) : x((y % MOD + MOD) % MOD) {
}
Modint& operator+=(const Modint& p){
if((x += p.x) >= MOD) x -= MOD;
return *this;
}
Modint& operator-=(const Modint& p){
if((x += MOD - p.x) >= MOD) x -= MOD;
return *this;
}
Modint& operator*=(const Modint& p){
x = x * p.x % MOD;
return *this;
}
Modint& operator/=(const Modint& p){
*this *= p.inverse();
return *this;
}
Modint operator-() const {
return Modint(-x);
}
Modint operator+(const Modint& p) const {
return Modint(*this) += p;
}
Modint operator-(const Modint& p) const {
return Modint(*this) -= p;
}
Modint operator*(const Modint& p) const {
return Modint(*this) *= p;
}
Modint operator/(const Modint& p) const {
return Modint(*this) /= p;
}
bool operator==(const Modint& p) const {
return x == p.x;
}
bool operator!=(const Modint& p) const {
return !(*this == p);
}
bool operator<(const Modint& p) const {
return x < p.x;
}
bool operator>(const Modint& p) const {
return x > p.x;
}
bool operator<=(const Modint& p) const {
return !(*this > p);
}
bool operator>=(const Modint& p) const {
return !(*this < p);
}
Modint inverse() const {
long long a = x, b = MOD, u = 1, v = 0;
while(b > 0){
long long t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
return Modint(u);
}
Modint pow(long long n) const {
Modint ret(1), mul(x);
while(n > 0){
if(n & 1) ret *= mul;
mul *= mul;
n >>= 1;
}
return ret;
}
friend ostream &operator<<(ostream& os, const Modint& p){
return os << p.x;
}
friend istream &operator>>(istream& is, Modint& a){
long long t;
cin >> t;
a = Modint<MOD>(t);
return is;
}
explicit operator long long() const {
return x;
}
static long long get_mod(){
return MOD;
}
private:
long long x;
};
using mint = Modint<MOD>;
ll H, W, S[3000][3000];
ll R[3000][3000], C[3000][3000];
signed main(){
cin >> H >> W;
string str;
ll K = 0;
REP(i, H){
cin >> str;
REP(j, W){
if(str[j] == '#') S[i][j] = 1;
else K++;
}
}
REP(i, H){
ll p = 0;
REP(j, W + 1){
if(S[i][j] == 1 || j == W){
FOR(k, p, j) R[i][k] = j - p;
p = j + 1;
}
}
}
REP(j, W){
ll p = 0;
REP(i, H + 1){
if(S[i][j] == 1 || i == H){
FOR(k, p, i) C[k][j] = i - p;
p = i + 1;
}
}
}
mint ans = 0;
REP(i, H){
REP(j, W){
if(S[i][j] == 1) continue;
ans += mint(2).pow(K) - mint(2).pow(K - (R[i][j] + C[i][j] - 1));
}
}
PRINT(ans);
return 0;
} | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a)
#define dumparr(a,n)
#endif
#define FOR(i, a, b) for(ll i = (ll)a;i < (ll)b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = (ll)b-1LL;i >= (ll)a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))
typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;
typedef long double ld;
typedef pair<ld,ld> pdd;
pll operator+(pll a,pll b){
return pll(a.first+b.first,a.second+b.second);
}
pll operator-(pll a,pll b){
return pll(a.first-b.first,a.second-b.second);
}
pll operator*(ll a,pll b){
return pll(b.first*a,b.second*a);
}
const ll INF=(1LL<<60);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
a=abs(a);
b=abs(b);
if(a==0)return b;
if(b==0)return a;
if(a < b) return gcd(b, a);
ll r;
while ((r=a%b)) {
a = b;
b = r;
}
return b;
}
#endif
template<class T>
bool chmax(T& a,const T& b){
if(a<b){
a=b;
return true;
}
return false;
}
template<class T>
bool chmin(T& a,const T& b){
if(a>b){
a=b;
return true;
}
return false;
}
template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
os << "(" << a.first << "," << a.second << ")";
return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
os << "[ ";
REP(a.size()){
os<< a[i] << " ";
}
os<< " ]";
return os;
}
void solve(long long N, long long K, std::vector<std::vector<long long>> T){
vector<ll> p(N-1);
iota(p.begin(),p.end(),1LL);
ll ans=0;
do{
ll distall=T[0][p[0]];
REP(N-2){
distall+=T[p[i]][p[i+1]];
}
distall+=T[p[N-2]][0];
if(distall==K){
++ans;
}
}while(next_permutation(p.begin(),p.end()));
cout<<ans<<endl;
}
int main(){
cout<<setprecision(1000);
long long N;
scanf("%lld",&N);
long long K;
scanf("%lld",&K);
std::vector<std::vector<long long>> T(N, std::vector<long long>(N));
for(int i = 0 ; i < N ; i++){
for(int j = 0 ; j < N ; j++){
scanf("%lld",&T[i][j]);
}
}
solve(N, K, std::move(T));
return 0;
}
|
#include <iostream>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cstdio>
#include <bitset>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <functional>
#include <stack>
#include <cmath>
#include <string>
#include <complex>
#include <cassert>
#define REP(i, N) for (int i = 0; i < (int)N; i++)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
constexpr int inf = 1 << 30;
constexpr long long llinf = 1LL << 62;
constexpr int mod = 1000000007; // 998244353;
constexpr int dy[4] = {-1, 0, 1, 0}, dx[4] = {0, -1, 0, 1};
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
int main() {
int N;
cin >> N;
vector<int> used(2 * N);
auto out = []() {
cout << "No" << endl;
exit(0);
};
REP(i, N) {
int A, B;
cin >> A >> B;
if (A != -1 && B != -1 && A >= B) {
out();
}
if (A != -1) {
if (used[A - 1] != 0) out();
used[A - 1] = i + 1;
}
if (B != -1) {
if (used[B - 1] != 0) out();
used[B - 1] = -(i + 1);
}
}
vector<bool> dp(N + 1);
dp[0] = 1;
FOR(i, 1, N + 1) {
REP(j, i)
if (dp[j]) {
bool ok = 1;
int width = i - j;
REP(k, width) {
int a = used[2 * j + k], b = used[2 * j + k + width];
if (a > 0) {
if (b != 0 && b != -a) ok = 0;
} else if (a < 0)
ok = 0;
if (b < 0) {
if (a != 0 && a != -b) ok = 0;
} else if (b > 0)
ok = 0;
}
if (ok) {
dp[i] = 1;
break;
}
}
}
cout << (dp[N] ? "Yes" : "No") << endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T> using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long
#define rep(i,j,n) for(int i=j;i<n;++i)
#define scn(a) scanf("%d",&a)
#define scns(a,b) scanf("%d %d",&a,&b)
#define print(a) printf("%d\n",a)
#define pb emplace_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
#define inf 1e18+7
const int mod = 1e9+7;
const int N = 5e5+5;
int n;
int main()
{
int test; test = 1;
for(int t = 1; t <= test; ++t)
{
int l,r,w; scns(l,r); scn(w);
n = w*1000;
if(n * (r-l) <= 1e8)
{
ll dp[n+1], dp1[n+1] = {}; dp[0] = 0;
for(int i = 1; i <= n; ++i)
{
dp[i] = inf;
for(int j = l; j <= r; ++j)
if(i >= j)
dp[i] = min(dp[i],dp[i-j] + 1);
}
for(int i = 1; i <= n; ++i)
{
dp1[i] = -inf;
for(int j = l; j <= r; ++j)
if(i >= j)
dp1[i] = max(dp1[i],dp1[i-j] + 1);
}
if(dp[n] >= inf)
puts("UNSATISFIABLE");
else
printf("%lld %lld\n",dp[n], dp1[n]);
continue;
}
if((n > r && n < 2*l) || n < l)
puts("UNSATISFIABLE");
else
printf("%lld %lld\n", (n-1)/r + 1, n/l);
}
return 0;
} |
#include <stack>
#include <cstdio>
#include <vector>
using namespace std;
#define int long long
stack < int > st;
vector < int > ans;
int fib[100];
int n;
signed main() {
scanf( "%lld", &n );
fib[1] = fib[2] = 1;
for( int i = 3;i <= 88;i ++ )
fib[i] = fib[i - 1] + fib[i - 2];
for( int i = 88;i;i -- )
if( n >= fib[i] ) st.push( i ), n -= fib[i];
int ip = 0;
while( ! st.empty() ) {
int x = st.top(); st.pop();
if( x & 1 ) {
while( ip < x - 1 ) {
if( ip & 1 ) ans.push_back( 4 );
else ans.push_back( 3 );
ip ++;
}
ans.push_back( 1 );
}
else {
while( ip < x - 1 ) {
if( ip & 1 ) ans.push_back( 4 );
else ans.push_back( 3 );
ip ++;
}
ans.push_back( 2 );
}
}
printf( "%lld\n", ans.size() );
for( int i = ans.size() - 1;~ i;i -- )
printf( "%lld\n", ans[i] );
} | #include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
vector<bool> prime(n+1,true);
for(int i=2;i<=n;i++){
if(prime[i]){
for(int j=i*i;j<=n;j+=i){
prime[j]=false;
}
}
}
long long int count=1;
for(int i=2;i<=n;i++){
if(prime[i]){
double d=n;
double d1=i;
int ans=floor(log(n)/log(i));
count*=pow(i,ans);
}
}
cout<<count+1;
} |
/**
* @author: adityasonani
* */
#include <bits/stdc++.h>
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
#define ll long long
#define ld long double
#define ln "\n"
#define fastio ios_base::sync_with_stdio(0); cin.tie(nullptr)
#define MOD (int) 1000000007
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << " = " << x << endl;
#define debugV(x) cerr << "["; for(auto i: x){ cerr << i << ", ";} cerr << "]" << endl;
#define precise(x) cout << fixed << setprecision(x)
#define MAX (int) 100007 // 10^5
std::vector<int> gv(int n){std::vector<int> v(n);for(auto &x: v){std::cin>>x;}return v;}
using namespace std;
/*
*/
void solve()
{
vector<int> v(3);
cin>>v[0]>>v[1]>>v[2];
sort(all(v));
if((v[2]+v[0])==2*v[1]){
cout << "Yes";
}
else cout << "No";
}
signed main()
{
fastio;
auto start = std::chrono::high_resolution_clock::now();
int t=1;
// cin>>t;
while(t--)
solve();
auto stop = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(stop - start);
// cerr << "\nTime taken : " << ((long double)duration.count())/((long double) 1e9) <<" s "<< endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
string X; cin >> X;
int64_t M; cin >> M;
if (X.size() == 1) {
if (stoll(X) > M) {
cout << 0 << endl;
return 0;
}
cout << 1 << endl;
return 0;
}
int64_t maxi = 0;
rep(i, X.size()) if (maxi < stoi(string(1, X.at(i)))) {
maxi = stoi(string(1, X.at(i)));
}
int64_t ans = (int64_t)pow(M / stoi(string(1, X.at(0))), 1 / (double)(X.size() - 1));
ans = max(maxi, ans - 1);
while (true) {
int64_t temp = 0;
rep(i, X.size()) {
if (temp != 0 && temp >= LLONG_MAX / ans) goto BREAK;
temp = temp * ans + stoi(string(1, X.at(i)));
}
if (temp > M) goto BREAK;
ans++;
}
BREAK:
ans = max((int64_t)0, ans - maxi - 1);
cout << ans << endl;
} |
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
#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 trav(a,x) for (auto& a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
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; }
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001; //check the limits, dummy
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int N; cin >> N;
set<string> A, B;
F0R(i, N) {
string S; cin >> S;
if (S[0] == '!') {
string T; trav(a, S) if (a != '!') T += a;
A.ins(T);
if (B.count(T)) {
cout << T << nl; return 0;
}
} else {
B.ins(S);
if (A.count(S)) {
cout << S << nl; return 0;
}
}
}
cout << "satisfiable" << nl;
}
// read the question correctly (ll vs int)
// template by bqi343
| #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
// #define int long long
template <class T>
bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
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;
}
#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, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
<< " " << __FILE__ << endl;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
int n, k;
cin >> n >> k;
vector<pair<ll, ll>> ab(n);
REP(i, n) {
ll a, b;
cin >> a >> b;
ab[i] = {a, b};
}
sort(ALL(ab));
ll now_lim = k;
REP(i, n) {
ll a, b;
a = ab[i].first;
b = ab[i].second;
if (now_lim < a) break;
else {
now_lim += b;
}
}
cout << now_lim << endl;
return 0;
}
|
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ldb double
template<typename T>void ckmn(T&a,T b){a=min(a,b);}
template<typename T>void ckmx(T&a,T b){a=max(a,b);}
void rd(int&x){scanf("%i",&x);}
void rd(ll&x){scanf("%lld",&x);}
void rd(char*x){scanf("%s",x);}
void rd(ldb&x){scanf("%lf",&x);}
void rd(string&x){scanf("%s",&x);}
template<typename T1,typename T2>void rd(pair<T1,T2>&x){rd(x.first);rd(x.second);}
template<typename T>void rd(vector<T>&x){for(T&i:x)rd(i);}
template<typename T,typename...A>void rd(T&x,A&...args){rd(x);rd(args...);}
template<typename T>void rd(){T x;rd(x);return x;}
int ri(){int x;rd(x);return x;}
template<typename T>vector<T> rv(int n){vector<T> x(n);rd(x);return x;}
template<typename T>void ra(T a[],int n,int st=1){for(int i=0;i<n;++i)rd(a[st+i]);}
template<typename T1,typename T2>void ra(T1 a[],T2 b[],int n,int st=1){for(int i=0;i<n;++i)rd(a[st+i]),rd(b[st+i]);}
template<typename T1,typename T2,typename T3>void ra(T1 a[],T2 b[],T3 c[],int n,int st=1){for(int i=0;i<n;++i)rd(a[st+i]),rd(b[st+i]),rd(c[st+i]);}
void re(vector<int> E[],int m,bool dir=0){for(int i=0,u,v;i<m;++i){rd(u,v);E[u].pb(v);if(!dir)E[v].pb(u);}}
template<typename T>void re(vector<pair<int,T>> E[],int m,bool dir=0){for(int i=0,u,v;i<m;++i){T w;rd(u,v,w);E[u].pb({v,w});if(!dir)E[v].pb({u,w});}}
void NO(){printf("-1\n");exit(0);}
ll Solve(vector<pii> pts){
if(pts[0].first==pts[0].second){
for(pii&p:pts)p.first*=-1,p.second*=-1;
reverse(pts.begin(),pts.end());
}
ll ans=0;
for(int i=0,las=-1;i+1<pts.size();i++){
int bot=i,top=pts.size()-1,mid,ptr=pts.size();
while(top>=bot){
mid=top+bot>>1;
int o=pts[mid].first-(mid-i);
if(o>=pts[i].second)ptr=mid,top=mid-1;
else bot=mid+1;
}
if(ptr==pts.size()||pts[ptr].first-(ptr-i)!=pts[i].second)NO();
if(las!=ptr)ans+=ptr-i;
las=ptr;
}
return ans;
}
vector<int> zero;
const int N=100050;
int a[N],b[N];
int main(){
int n,l;rd(n,l);
ra(a,n);
ra(b,n);
a[n+1]=b[n+1]=l+1;
for(int i=0;i<=n+1;i++)if(a[i]==b[i])zero.pb(i);
ll ans=0;
for(int i=1;i<zero.size();i++){
int l=zero[i-1]+1,r=zero[i]-1;
vector<pii> pts;
pts.pb({a[l-1],b[l-1]});
int L=l;while(a[L]>b[L])pts.pb({a[L],b[L]}),L++;
ans+=Solve(pts);
pts.clear();
pts.pb({a[r+1],b[r+1]});
int R=r;while(a[R]<b[R])pts.pb({a[R],b[R]}),R--;
reverse(pts.begin(),pts.end());
ans+=Solve(pts);
if(L!=R+1)NO();
}
printf("%lld\n",ans);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define pii pair<int, int>
#define ull unsigned ll
#define f first
#define s second
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
#define SQ(x) (x)*(x)
#define MN(a,b) a = min(a,(__typeof__(a))(b))
#define MX(a,b) a = max(a,(__typeof__(a))(b))
#define pb push_back
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#ifdef BALBIT
#define IOS()
#define bug(...) fprintf(stderr,"#%d (%s) = ",__LINE__,#__VA_ARGS__),_do(__VA_ARGS__);
template<typename T> void _do(T &&x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S &&...y){cerr<<x<<", ";_do(y...);}
#else
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define bug(...)
#endif
const int iinf = 1e9+10;
const ll inf = 1ll<<60;
const ll mod = 1e9+7 ;
void GG(){cout<<"0\n"; exit(0);}
ll mpow(ll a, ll n, ll mo = mod){ // a^n % mod
ll re=1;
while (n>0){
if (n&1) re = re*a %mo;
a = a*a %mo;
n>>=1;
}
return re;
}
ll inv (ll b, ll mo = mod){
if (b==1) return b;
return (mo-mo/b) * inv(mo%b,mo) % mo;
}
const int maxn = 1e6+5;
signed main(){
IOS();
int n,l; cin>>n>>l;
vector<int> a(n);
map<int,int> rch;
map<int, int> r2;
rch[1] = r2[1] = 0;
rch[(l-n+1)] = r2[l-n+1] = n+1;
for (int i = 0; i<n; ++i) {
cin>>a[i]; a[i] -= i;
bug(a[i]);
if (!r2.count(a[i])) r2[a[i]] = i+1;
else
MX(r2[(a[i])], i+1);
if (!rch.count(a[i])) rch[a[i]] = i+1;
else
MN(rch[(a[i])], i+1);
}
vector<int> b(n);
vector<int> mn(n+2, 10000000), mx(n+2, -10000000);
for (int i = 0; i<n+2; ++i) mn[i] = mx[i] = i-1;
for (int j = 0; j<n; ++j) {
cin>>b[j]; b[j] -= j;
bug(b[j]);
if (!rch.count(b[j])) {
cout<<-1<<endl; return 0;
}
int L = rch[b[j]]-1, R = r2[b[j]]-1;
int k = L;
if (j >= L && j <= R) k = j;
else if (j > R) k = R;
++k;
MN(mn[k], j);
MX(mx[k], j);
}
ll re = 0;
for (int i = 0; i<=n+1; ++i) {
re += max(0ll,mx[i] - mn[i]);
}
cout<<re<<endl;
}
|
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
constexpr ll INF = 1e11;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll n, m, ans = 0, mx = 0;
cin >> n >> m;
vector<ll> w(n), l(m), v(m);
vector<pair<ll, ll>> p(m);
rep(i, n) cin >> w[i];
mx = *max_element(w.begin(), w.end());
rep(i, m) {
cin >> l[i] >> v[i];
if (v[i] < mx) {
cout << -1 << endl;
return 0;
}
p[i] = {v[i], l[i]};
}
sort(p.begin(), p.end());
for (int i = 1; i < m; ++i) p[i].second = max(p[i].second, p[i - 1].second);
ll mn = 1 << 30;
vector<int> a;
rep(i, n) a.push_back(i);
ll d[10][10];
do {
rep(i, 10) rep(j, 10) d[i][j] = 0;
rep(i, n) {
ll ls = 0;
for (int j = i; j < n; ++j) {
ls += w[a[j]];
ll t = lower_bound(p.begin(), p.end(), make_pair(ls, 0ll)) - p.begin();
if (t) d[i][j] = max(d[i][j], p[t - 1].second);
}
}
rep(i, 8) rep(x, n) for (int z = x + 1; z < n;
++z) for (int y = z + 1; y < n; ++y) d[x][y] =
max(d[x][y], d[x][z] + d[z][y]);
mn = min(mn, d[0][n - 1]);
} while (next_permutation(a.begin(), a.end()));
cout << mn << endl;
return 0;
} |
// Author: Muhesh Kumar
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using db = long double;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using vs = vector<string>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using vvb = vector<vb>;
#define nl '\n'
#define fr first
#define sc second
#define bk back()
#define ft front()
#define pb push_back
#define ppb pop_back
#define lb lower_bound
#define ub upper_bound
#define bg(x) begin(x)
#define all(x) bg(x), end(x)
#define sz(x) (int) (x).size()
#define amax(a, b) a = max(a, b)
#define amin(a, b) a = min(a, b)
#define trav(a, b) for(auto &a: b)
#define rep(i, a, b) for(int i = a; i < b; i++)
const ll inf = 1e18 + 10;
const db eps = 1e-9;
const int mod = 1e9 + 7;
ll modadd(ll a, ll b, ll m = mod) { a %= m; b %= m; return (((a + b) % m) + m) % m; }
ll modsub(ll a, ll b, ll m = mod) { a %= m; b %= m; return (((a - b) % m) + m) % m; }
ll modmul(ll a, ll b, ll m = mod) { a %= m; b %= m; return (((a * b) % m) + m) % m; }
ll gcd(ll a, ll b) { return __gcd(a, b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template <typename T1, typename T2>
inline std::ostream &operator << (std::ostream& os, const std::pair<T1, T2>& p) {
return os << "(" << p.first << ", " << p.second << ")";
}
template<typename T>
inline std::ostream &operator << (std::ostream& os,const std::vector<T>& v) {
bool first = true;
os << "[";
for(unsigned int i = 0; i < v.size(); i++) {
if(!first)
os << ", ";
os << v[i];
first = false;
}
return os << "]";
}
template<typename T>
inline std::ostream &operator << (std::ostream& os,const std::vector<vector<T>>& v) {
bool first = true;
os << "[\n ";
for(unsigned int i = 0; i < v.size(); i++) {
if(!first)
os << ",\n ";
os << v[i];
first = false;
}
return os << "\n]";
}
template<typename T>
inline std::ostream &operator << (std::ostream& os,const std::set<T>& v) {
bool first = true;
os << "[";
for (typename std::set<T>::const_iterator ii = v.begin(); ii != v.end(); ++ii) {
if(!first)
os << ", ";
os << *ii;
first = false;
}
return os << "]";
}
template<typename T1, typename T2>
inline std::ostream &operator << (std::ostream& os,const std::map<T1, T2>& v) {
bool first = true;
os << "[\n ";
for (typename std::map<T1, T2>::const_iterator ii = v.begin(); ii != v.end(); ++ii) {
if(!first)
os << ",\n ";
os << *ii ;
first = false;
}
return os << "\n]";
}
#ifndef ONLINE_JUDGE
#define debug(a) cerr << #a << " " << a << '\n';
#else
#define debug(a)
#endif
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int N; cin >> N;
vl v(N);
trav (i, v) cin >> i;
int n = 8;
if (N < 8)
n = N;
map<int, vi> sum_seqs;
rep(mask, 0, 1 << n) {
vi seq;
ll sum = 0;
rep(i, 0, n) {
if (mask & (1 << i)) {
seq.pb(i);
sum += v[i];
}
}
sum %= 200;
if (!sum_seqs[sum].empty()) {
vi other_seq = sum_seqs[sum];
cout << "Yes" << nl;
cout << sz(other_seq) << " ";
trav (j, other_seq) cout << j + 1 << " ";
cout << nl;
cout << sz(seq) << " ";
trav (j, seq) cout << j + 1 << " ";
cout << nl;
return 0;
}
sum_seqs[sum] = seq;
}
cout << "No";
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
/* alias */
using ull = unsigned long long;
using ll = long long;
/* define short */
#define all(obj) (obj).begin(), (obj).end()
#define YESNO(bool) if(bool){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(bool) if(bool){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(bool) if(bool){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
/* REP macro */
#define reps(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define rep(i, n) reps(i, 0, n)
#define rrep(i, n) reps(i, 1, n + 1)
#define repd(i,n) for(ll i=n-1;i>=0;i--)
#define rrepd(i,n) for(ll i=n;i>=1;i--)
int main() {
string S;
int ans=0;
cin>>S;
for(int i=0;i<=9999;i++){//0000~9999を試行する
vector<bool> flag(10);//[0,9]のフラグ
int X =i;//Xは試行中の番号
for(int j=0;j<4;j++){
flag[X%10] = true;//1の位->千の位の数字にフラグを立てる=試行中の番号に含まれる数字
X/=10;
}
bool flag2 = true;
for(int j=0;j<10;j++){//備忘録Sとフラグを照合
if(S[j]=='o' && !flag[j]) flag2 = false;//iが確実に含まれるかつ試行中の番号に含まれない
if(S[j]=='x' && flag[j]) flag2 = false;//iが確実に含まれないかつ試行中の番号に含まれる
}
ans +=flag2;
}
cout<<ans<<endl;
return 0;//O(10^5)
} |
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(998244353)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll gcd(ll a,ll b){if(!b)return a;else return gcd(b,a%b);}
int main()
{
int n;
cin>>n;
vector<ll>p(1001,0);
for(int i=0;i<n;i++){
int a;
cin>>a;
for(int j=1;j*j<=a;j++){
if(a%j == 0){
if(j > 1)p[j]++;
if(j*j != a && a/j > 1)p[a/j]++;
}
}
}
int ans = 0,id = 0;
for(int i=1;i<=1000;i++){
if(p[i] > ans){
ans = p[i];
id = i;
}
}
cout<<id;
}
|
#pragma GCC optimize("03")
#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
using namespace std;
int n;
string s;
char a[200100];
int cnt[500];
int main() {
// ifstream cin("tst.in");
// ofstream cout("tst.out");
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cin >> s;
n = s.size();
for (int i = 1; i <= n; i++) {
a[i] = s[i - 1];
}
// for (int i = n; i > 0; i--) {
// for (int j = 'a'; j <= 'z'; j++) {
// dp[i][j - 'a'] = dp[i + 1][j - 'a'] + (a[i] == j);
// }
// }
ll ans = 0;
int p = n;
while (p > 0) {
int pp = p;
while (pp > 0 && a[pp] == a[p]) {
cnt[a[pp] - 'a']++;
pp--;
}
int dif = p - pp;
if (dif == 1) {
p = pp;
continue;
}
ll tot = n - p;
// cout << tot << " " << p << " " << a[p] << " " << cnt[a[p] - 'a'] << " " << p - pp << ' ';
ans += tot - cnt[a[p] - 'a'] + p - pp;
// cout << " " << ans << '\n';
for (int i = 'a'; i <= 'z'; i++) {
cnt[i - 'a'] = 0;
}
cnt[a[pp + 1] - 'a'] = n - pp;
p = pp;
}
cout << ans;
return 0;
} | #include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
#define int long long int
// quoted from beet-aizu
template <typename T,typename E, typename F, typename G, typename H>
struct LazySegmentTree{
//using F = function<T(T,T)>;
//using G = function<T(T,E)>;
//using H = function<E(E,E)>;
int n,height;
F f;
G g;
H h;
T ti;
E ei;
vector<T> dat;
vector<E> laz;
LazySegmentTree(F f,G g,H h,T ti,E ei):
f(f),g(g),h(h),ti(ti),ei(ei){}
void init(int n_){
n=1;height=0;
while(n<n_) n<<=1,height++;
dat.assign(2*n,ti);
laz.assign(2*n,ei);
}
void build(const vector<T> &v){
int n_=v.size();
init(n_);
for(int i=0;i<n_;i++) dat[n+i]=v[i];
for(int i=n-1;i;i--)
dat[i]=f(dat[(i<<1)|0],dat[(i<<1)|1]);
}
inline T reflect(int k){
return laz[k]==ei?dat[k]:g(dat[k],laz[k]);
}
inline void eval(int k){
if(laz[k]==ei) return;
laz[(k<<1)|0]=h(laz[(k<<1)|0],laz[k]);
laz[(k<<1)|1]=h(laz[(k<<1)|1],laz[k]);
dat[k]=reflect(k);
laz[k]=ei;
}
inline void thrust(int k){
for(int i=height;i;i--) eval(k>>i);
}
inline void recalc(int k){
while(k>>=1)
dat[k]=f(reflect((k<<1)|0),reflect((k<<1)|1));
}
void update(int a,int b,E x){
thrust(a+=n);
thrust(b+=n-1);
for(int l=a,r=b+1;l<r;l>>=1,r>>=1){
if(l&1) laz[l]=h(laz[l],x),l++;
if(r&1) --r,laz[r]=h(laz[r],x);
}
recalc(a);
recalc(b);
}
void set_val(int a,T x){
thrust(a+=n);
dat[a]=x;laz[a]=ei;
recalc(a);
}
T query(int a,int b){
thrust(a+=n);
thrust(b+=n-1);
T vl=ti,vr=ti;
for(int l=a,r=b+1;l<r;l>>=1,r>>=1) {
if(l&1) vl=f(vl,reflect(l++));
if(r&1) vr=f(reflect(--r),vr);
}
return f(vl,vr);
}
};
signed main() {
string s; cin >> s;
int n = s.size();
using P = pair<int, int>;
auto f = [](P a, P b){ return P(a.first + b.first, a.second + b.second); };
auto g = [](P a, int b){ return P(a.second * b, a.second); };
auto h = [](int a, int b){ return b != INT_MAX ? b : a; };
using SG = LazySegmentTree<P, int, decltype(f), decltype(g), decltype(h)>;
vector<SG> sg(26, SG(f, g, h, P(0, 0), INT_MAX));
for (int i = 0; i < 26; i++) {
sg[i].build(vector<P>(n, P(0, 1)));
}
// sg.build(vector<P>(n, P(0, 1)));
// for(int i = 0; i < q; i++){
// int com; cin >> com;
// if(!com){
// int s, t, x; cin >> s >> t >> x;
// sg.update(s, t + 1, x);
// }else{
// int s, t; cin >> s >> t;
// cout << sg.query(s, t + 1).first << endl;
// }
// }
for (int i = 0; i < s.size(); i++) {
sg[s[i] - 'a'].update(i, i + 1, 1);
}
int ans = 0;
for (int i = s.size() - 1; i >= 0; i--) {
if (s[i] != s[i + 1]) continue;
ans += n - i - sg[s[i] - 'a'].query(i, n).first;
for (int j = 0; j < 26; j++) {
if ((int)(s[i] - 'a') == j) {
sg[j].update(i, n, 1);
} else {
sg[j].update(i, n, 0);
}
}
}
cout << ans << endl;
return 0;
}
|
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <iomanip>
#include <cmath>
#include <queue>
#include <bitset>
#include <numeric>
#include <array>
#include <cstring>
#include <random>
#include <chrono>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
typedef long long ll;
typedef long double ld;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template<class T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const ll N = 2e5 + 42, stN = 4 * N;
ll t[stN] = {0};
void update(ll v, ll tl, ll tr, ll l, ll r, ll add) {
if(l > r) return;
if(l == tl && r == tr) t[v] += add;
else {
ll tm = (tl + tr) / 2;
update((v << 1), tl, tm, l, min(r, tm), add);
update((v << 1) + 1, tm + 1, tr, max(l, tm + 1), r, add);
}
}
ll get(ll v, ll tl, ll tr, ll pos) {
if(tl == tr) return t[v];
ll tm = (tl + tr) / 2;
if(pos <= tm) return t[v] + get((v << 1), tl, tm, pos);
else return t[v] + get((v << 1) + 1, tm + 1, tr, pos);
}
vector<ll> g[N];
ll subt[N], dep[N];
ll stv[N];
ll cur = 0;
void dfs(ll v, ll p) {
stv[v] = cur++;
subt[v] = 1;
for(auto& x : g[v])
if(x != p) {
dep[x] = dep[v] + 1;
dfs(x, v);
subt[v] += subt[x];
}
}
int main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll n = 0;
cin >> n;
ll tot = 0;
vector<pair<ll, ll> > ab(n);
for(ll i = 1; i < n; i++) {
ll a, b; cin >> a >> b;
g[--a].pb(--b);
g[b].pb(a);
ab[i - 1] = mp(a, b);
}
dfs(0, -1);
ll q = 0;
cin >> q;
while(q--) {
ll t, e, x;
cin >> t >> e >> x;
e--;
if(t == 1) {
if(dep[ab[e].fi] > dep[ab[e].se]) {
update(1, 0, n - 1, stv[ab[e].fi], stv[ab[e].fi] + subt[ab[e].fi] - 1, x);
} else {
tot += x;
update(1, 0, n - 1, stv[ab[e].se], stv[ab[e].se] + subt[ab[e].se] - 1, -x);
}
} else {
if(dep[ab[e].se] > dep[ab[e].fi]) {
update(1, 0, n - 1, stv[ab[e].se], stv[ab[e].se] + subt[ab[e].se] - 1, x);
} else {
tot += x;
update(1, 0, n - 1, stv[ab[e].fi], stv[ab[e].fi] + subt[ab[e].fi] - 1, -x);
}
}
}
for(ll i = 0; i < n; i++) cout << tot + get(1, 0, n - 1, stv[i]) << '\n';
return 0;
}
| #include <iostream>
#include <vector>
#include <utility>
#include <queue>
using namespace std;
int main()
{
long long n;
cin >> n;
vector<pair<long long, long long>> edge_num(n);
vector<vector<long long>> edge(n + 1);
vector<long long> depth(n + 1, -1);
for (long long i = 1; i <= n - 1; i++)
{
long long a, b;
cin >> a >> b;
edge.at(a).push_back(b);
edge.at(b).push_back(a);
edge_num.at(i).first = a;
edge_num.at(i).second = b;
}
queue<long long> qu;
depth.at(1) = 0;
qu.push(1);
while (qu.size() != 0)
{
long long p;
p = qu.front();
qu.pop();
for (long long i = 0; i < edge.at(p).size(); i++)
{
if (depth.at(edge.at(p).at(i)) == -1)
{
depth.at(edge.at(p).at(i)) = depth.at(p) + 1;
qu.push(edge.at(p).at(i));
}
}
}
//cout << "ask q" << endl;
long long q;
cin >> q;
vector<long long> add_to_child(n + 1, 0);
vector<long long> add_to_me(n + 1, 0);
for (long long i = 0; i < q; i++)
{
long long t, e, x;
cin >> t >> e >> x;
long long from, to;
if (t == 1)
{
from = edge_num.at(e).first;
to = edge_num.at(e).second;
}
else
{
from = edge_num.at(e).second;
to = edge_num.at(e).first;
}
if (depth.at(from) < depth.at(to))
{
add_to_child.at(1) += x;
add_to_child.at(to) -= x;
}
else
{
add_to_child.at(from) += x;
}
}
vector<long long> add_to_child_wfs(n + 1, -1);
add_to_child_wfs.at(1) = add_to_child.at(1);
qu.push(1);
while (qu.size() != 0)
{
long long p;
p = qu.front();
qu.pop();
for (long long i = 0; i < edge.at(p).size(); i++)
{
if (add_to_child_wfs.at(edge.at(p).at(i)) == -1)
{
add_to_child_wfs.at(edge.at(p).at(i)) = add_to_child_wfs.at(p) + add_to_child.at(edge.at(p).at(i));
qu.push(edge.at(p).at(i));
}
}
}
for (long long i = 1; i <= n; i++)
{
cout << add_to_child_wfs.at(i) << "\n";
}
return 0;
} |
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"
using namespace std;
constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-12;
int N, M, K, T, H, W, L, R;
//long long int N, M, K, T, H, W, L, R;
vector<int>lft;
vector<int>rht;
bool flag;
long long int Left(vector<int>&v, vector<int>&w, int st, int ed) {
int cnt = st - 1;
for (int i = st; i <= ed; i++) {
while (cnt < i&&v[cnt] + i - cnt != w[i]) {
cnt++;
}
while (cnt + 1 < i&&v[cnt + 1] + i - cnt - 1 == w[i]) {
cnt++;
}
if (cnt == i) {
flag = false;
break;
}
lft[i] = cnt;
}
long long int ret = 0;
if (!flag)return 0;
int bef = -1;
for (int i = ed; i >= st; i--) {
if (lft[i] != bef) {
ret += i - lft[i];
}
bef = lft[i];
}
return ret;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> N >> M;
flag = true;
vector<int>v(N + 2);
vector<int>w(N + 2);
lft.resize(N + 2);
rht.resize(N + 2);
for (int i = 1; i <= N; i++) {
cin >> v[i];
}
v.back() = M + 1;
for (int i = 1; i <= N; i++) {
cin >> w[i];
}
w.back() = M + 1;
auto revv = v;
auto revw = w;
for (auto &i : revv) {
i = M + 1 - i;
}
for (auto &i : revw) {
i = M + 1 - i;
}
reverse(revv.begin(), revv.end());
reverse(revw.begin(), revw.end());
vector<int>same;
for (int i = 0; i < N + 2; i++) {
if (v[i] == w[i])same.push_back(i);
}
long long int ans = 0;
for (int i = 1; i < same.size(); i++) {
int st = same[i - 1] + 1;
int ed = same[i] - 1;
if (v[st] > w[st]) {
if (v[ed] > w[ed]) {
ans += Left(v, w, st, ed);
}
else {
int box = st;
for (int j = st; j <= ed; j++) {
if (v[j] > w[j])box = j;
else break;
}
ans += Left(v, w, st, box);
ans += Left(revv, revw, N + 1 - ed, N + 1 - box - 1);
}
}
else {
if (v[ed] > w[ed]) {
cout << -1 << endl;
return 0;
}
ans += Left(revv, revw, N + 1 - ed, N + 1 - st);
}
}
if (flag) {
cout << ans << endl;
}
else {
cout << -1 << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define endl '\n'
#define all(x) (x).begin(),(x).end()
const int INF=1000000000+5;
const int N=1e5+5;
const ll oo=1e18+5;
const ll mod=1e9+7;
map<int,pair<int,int>> get(int n,int L){
vector<int> v{0};
for(int i=1;i<=n+1;++i){
int x=L+1;
if(i<=n) cin>>x;
v.push_back(x-i);
}
map<int,pair<int,int>> interval;
for(int i=0;i<(int)v.size();++i){
if(!i||v[i]!=v[i-1]){
interval[v[i]].first=i;
}
interval[v[i]].second=i;
}
return interval;
}
int main(){
ios::sync_with_stdio(0); cin.tie(0);
int n,L;
cin>>n>>L;
auto a=get(n,L);
auto b=get(n,L);
//~ cout<<"a : "<<endl;
//~ for(auto x:a){
//~ cout<<"("<<x.first<<")["<<x.second.first<<","<<x.second.second<<"]"<<endl;
//~ }
//~ cout<<"b : "<<endl;
//~ for(auto x:b){
//~ cout<<"("<<x.first<<")["<<x.second.first<<","<<x.second.second<<"]"<<endl;
//~ }
ll ans=0;
for(auto x:b){
int val=x.first;
if(!a.count(val)){
return cout<<-1,0;
}
ans+=max(0,a[val].first -b[val].first)+max(0,b[val].second-a[val].second);
}
cout<<ans;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int maxn=100010,mod=1000000007;
#define MP make_pair
#define PB push_back
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#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 MEM(x,v) memset(x,v,sizeof(x))
inline ll read(){
char ch=getchar();ll x=0,f=0;
while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
return f?-x:x;
}
inline int qmo(int x){return x+(x>>31?mod:0);}
int n,f[maxn][2];
char c[2][2];
int main(){
n=read()-2;
FOR(i,0,1) FOR(j,0,1) while(c[i][j]!='A' && c[i][j]!='B') c[i][j]=getchar();
if(c[0][1]=='A'){
if(c[0][0]=='A') puts("1");
else{
if(c[1][0]=='A'){
f[0][0]=1;
FOR(i,1,n){
f[i][0]=(f[i-1][0]+f[i-1][1])%mod;
f[i][1]=f[i-1][0];
}
printf("%d\n",f[n][0]);
}
else{
if(!n) puts("1");
else{
int pw=1;
FOR(i,1,n-1) pw=2*pw%mod;
printf("%d\n",pw);
}
}
}
}
else{
if(c[1][1]=='B') puts("1");
else{
if(c[1][0]=='B'){
f[0][0]=1;
FOR(i,1,n){
f[i][0]=(f[i-1][0]+f[i-1][1])%mod;
f[i][1]=f[i-1][0];
}
printf("%d\n",f[n][0]);
}
else{
if(!n) puts("1");
else{
int pw=1;
FOR(i,1,n-1) pw=2*pw%mod;
printf("%d\n",pw);
}
}
}
}
} | // Sometimes, the questions are complicated - and the answers are simple. //
#include<iostream>
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const int N = 1e3 + 5, mod = 1e9 + 7;
int n;
char AA, BB, AB, BA ;
void solve1() {
if(AA == 'A')
cout << 1;
else {
// AB=A , AA=B
if(BA == 'A') {
pair<int, int> dpAB = {1, 0};
for(int i = 2; i <= n; i++) {
dpAB = {(dpAB.first + dpAB.second) % mod, dpAB.first};
}
cout << dpAB.second;
} else {
int ans = 1;
for(int i = 1; i < n - 2; i++)
ans = ans * 2 % mod;
cout << ans;
}
}
}
// AB = B
void solve2() {
if(BB == 'B')
cout << 1;
else {
// AB=B , BB=A
if(BA == 'B') {
pair<int, int> dpAB = {0, 1};
for(int i = 3; i <= n; i++) {
dpAB = { dpAB.second, (dpAB.first + dpAB.second) % mod};
}
cout << dpAB.second;
} else {
int ans = 1;
for(int i = 1; i < n - 2; i++)
ans = ans * 2 % mod;
cout << ans;
}
}
}
int main() {
IO
cin >> n;
cin >> AA >> AB >> BA >> BB;
if(AB == 'A')
solve1();
else
solve2();
}
|
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<vector>
#define ll long long
using namespace std;
int n;
ll k,ans=0;
int t[9][9];
int num[]={2,3,4,5,6,7,8};
void solve(){
do{
ll sum=0;
sum+=(t[1][num[0]]+t[num[n-2]][1]);
for(int i=0;i<n-2;i++) sum+=t[num[i]][num[i+1]];
if(sum==k) ans++;
}while(next_permutation(num,num+n-1));
}
int main(){
cin>>n>>k;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++){
cin>>t[i][j];
}
solve();
cout<<ans;
}
| /* Simplicity and Goodness */
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
// using namespace __gnu_pbds;
// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
void my_dbg() { cout << endl; }
template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B) { cout << ' ' << A; my_dbg(B...); }
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)
#define scn(n) scanf("%d", &n)
#define lscn(n) scanf("%lld", &n)
#define pri(n) printf("%d ", (int)(n))
#define prin(n) printf("%d\n", (int)(n))
#define lpri(n) printf("%lld ", n)
#define lprin(n) printf("%lld\n", n)
#define rep(i,a,b) for(int i=a; i<(int)b; i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
const int inf = INT_MAX;
const int ninf = INT_MIN;
const int mod = 1e9+7;
const int maxN = 1e6+2;
int t[10][10];
int n, k;
bool check(vi order)
{
int prv = 1;
ll cost = 0;
rep(i, 0, n - 1) {
int to = order[i];
cost += t[prv][to];
prv = to;
}
cost += t[prv][1];
return cost == k;
}
int main()
{
scn(n); scn(k);
rep(i, 1, n + 1) {
rep(j, 1, n + 1) {
scn(t[i][j]);
}
}
vi permute;
rep(i, 2, n + 1)
permute.pb(i);
int cnt = 0;
do {
cnt += check(permute);
} while(next_permutation(permute.begin(), permute.end()));
prin(cnt);
return 0;
} |
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); ++i)
#define ALL(x) (x).begin(), (x).end()
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;}
using namespace std;
int main(){
int n; cin >> n;
vector<int> t(n);
vector<int> l(n);
vector<int> r(n);
int ans = 0;
for(int i=0; i<n; ++i){
cin >> t[i] >> l[i] >> r[i];
}
for(int i=0; i<n-1; ++i){
for(int j=i+1; j<n; ++j){
bool t1start = false;
bool t1end = false;
bool t2start = false;
bool t2end = false;
if(t[i] == 1 || t[i] == 2) t1start = true;
if(t[i] == 1 || t[i] == 3) t1end = true;
if(t[j] == 1 || t[j] == 2) t2start = true;
if(t[j] == 1 || t[j] == 3) t2end = true;
if(r[i] < l[j] || r[j] < l[i]) continue;
if(r[i] == l[j]){
if(t1end && t2start) ans++;
else continue;
} else if (r[j] == l[i]){
if(t2end && t1start) ans++;
else continue;
} else {
ans++;
}
}
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------
int H,W,A,B;
int did[16][16];
int ret=0;
void dfs(int y,int x,int A,int B) {
if(A<0||B<0) return;
if(x==W) {
dfs(y+1,0,A,B);
return;
}
if(y==H) {
ret++;
return;
}
if(did[y][x]) {
dfs(y,x+1,A,B);
}
else {
if(B) {
did[y][x]=1;
dfs(y,x+1,A,B-1);
did[y][x]=0;
}
if(A) {
if(x+1<W&&did[y][x+1]==0) {
did[y][x]=did[y][x+1]=1;
dfs(y,x+2,A-1,B);
did[y][x]=did[y][x+1]=0;
}
if(y+1<H&&did[y+1][x]==0) {
did[y][x]=did[y+1][x]=1;
dfs(y,x+1,A-1,B);
did[y][x]=did[y+1][x]=0;
}
}
}
}
void solve() {
int i,j,k,l,r,x,y; string s;
cin>>H>>W>>A>>B;
dfs(0,0,A,B);
cout<<ret<<endl;
}
int main(int argc,char** argv){
string s;int i;
if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
cout.tie(0); solve(); return 0;
}
|
#include <bits/stdc++.h>
// #include <atcoder/all>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;
// #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;
}
template <typename T>
T mypow(T x, T n, const T &p = -1)
{ //x^nをmodで割った余り
T ret = 1;
while (n > 0)
{
if (n & 1)
{
if (p != -1)
ret = (ret * x) % p;
else
ret *= x;
}
if (p != -1)
x = (x * x) % p;
else
x *= x;
n >>= 1;
}
return ret;
}
using namespace std;
// using namespace atcoder;
void solve()
{
int n;
cin>>n;
vector<pair<int,int>>e(n-1);
vector<vector<int>>g(n);
rep(i,n-1){
cin>>e[i].first>>e[i].second;
e[i].first--;e[i].second--;
g[e[i].first].eb(e[i].second);
g[e[i].second].eb(e[i].first);
}
vector<int>dis(n);
auto dfs=[&](auto self,int v,int par=-1)->void{
for(auto x:g[v]){
if(x!=par){
dis[x]=dis[v]+1;
self(self,x,v);
}
}
};
dfs(dfs,0);
vector<ll>add(n);
int q;
cin>>q;
while(q--){
int u,v;
ll t;
cin>>u>>v>>t;
u--;
v--;
int a=e[v].first,b=e[v].second;
if(dis[b]<dis[a]){
u^=1;
}
if(u==0){
add[0]+=t;
if(dis[a]<=dis[b]){
add[b]-=t;
}
else add[a]-=t;
}
else{
if(dis[a]<=dis[b])add[b]+=t;
else add[a]+=t;
}
}
auto rec=[&](auto self,int v,int par=-1)->void{
for(auto x:g[v]){
if(par!=x){
add[x]+=add[v];
self(self,x,v);
}
}
};
rec(rec,0);
rep(i,n){
cout<<add[i]<<"\n";
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(15);
solve();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define st first
#define nd second
#define endl '\n'
#define what_is(x) cerr << #x << " is " << x << endl;
#define what_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << e << ' '; cerr << '\n'; //vector, set
#define what_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << x[i] << ' '; cerr << '\n'; //n first element of array
#define cerr_pair(x) '{' << x.st << ", " << x.nd << '}'
#define pwhat_is(x) cerr << #x << " is " << cerr_pair(x) << endl;
#define pwhat_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << cerr_pair(e) << ' '; cerr << '\n'; //vector, set
#define pwhat_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << cerr_pair(x[i]) << ' '; cerr << '\n'; //n first element of array
// #define int long long
typedef pair<int,int> pii;
const int N = 1e5+5;
const int INF = 1e9;
const int MOD = 1e9+7;
int n;
int c[N];
vector<int> g[N];
vector<int> good_vers;
int cnt_colors[N];
void dfs(int v, int p) {
if (cnt_colors[c[v]] == 0) good_vers.push_back(v);
cnt_colors[c[v]] += 1;
for(int u:g[v]) {
if (u == p) continue;
dfs(u, v);
}
cnt_colors[c[v]] -= 1;
}
int32_t main()
{
IOS
// freopen("input.txt", "r", stdin);
cin >> n;
for(int i=0; i<n; i++) cin >> c[i];
for(int i=0; i<n-1; i++) {
int u, v; cin >> u >> v;
u--, v--;
g[u].push_back(v);
g[v].push_back(u);
}
dfs(0, -1);
sort(good_vers.begin(), good_vers.end());
for(int v:good_vers) cout << v + 1 << endl;
return 0;
}
|
// abc180_a
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()
#define INF (ll)(1e9)
#define MOD (1000000007)
#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int idx=0;idx<(n-1);idx++) cout << (vec)[idx] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << "\n";}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;
int main() {
#ifdef LOCAL
ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif
int N, A, B;
cin >> N >> A >> B;
int ans = N - A + B;
print(ans);
return 0;
}
| #ifdef _LOCAL
#include "local_include.hpp"
#else
#include <bits/stdc++.h>
using namespace std;
#endif
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define fto(i, s, e) for (int i = (s); i <= (e); ++i)
#define fto1(i, s, e) for (int i = (s); i < (e); ++i)
#define fdto(i, s, e) for (int i = (s); i >= (e); --i)
#define fit(it, a) for (auto it = (a).begin(); it != (a).end(); ++it)
#define fat(i, a) for (auto i : (a))
#define ll long long
#define ii pair<int, int>
#define pll pair<ll, ll>
template<class T, class Cmp = less<T>> using oss = tree<T, null_type, Cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define bc __builtin_popcountll
#define y1 ansdj
#define endl '\n'
#define ff first
#define ss second
#define sz(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define bug(...) _bug(cout, __VA_ARGS__)
#define buga(a, s, e) cout << '{'; if (e < s) cout << '}'; else fto (__i, s, e) cout << a[__i] << " }"[__i == e]; cout << endl
template<class T1, class T2> ostream& operator<<(ostream &os, pair<T1, T2> const &v) {
return os << '(' << v.ff << ", " << v.ss << ')';
}
template<typename T>
void _bug(ostream &os, T const &var) { os << var << endl; }
template<typename T, typename... Args>
void _bug(ostream &os, T const &var, Args const &... args) {
os << var << ' ';
_bug(os, args...);
}
double const pi = acos(-1);
#define oo 1000000007
#define OO 1000000000000000003LL
int const maxn = 1e5+3;
ii a[maxn];
#define multi_test 0
void _main() {
int cap, m, T;
cin >> cap >> m >> T;
ll n = cap;
fto (i, 1, m) {
cin >> a[i].ff >> a[i].ss;
n -= a[i].ff - a[i-1].ss;
if (n <= 0) {
bug("No");
return;
}
n = min(1LL*cap, n + (a[i].ss - a[i].ff));
}
n -= T - a[m].ss;
bug(n > 0 ? "Yes" : "No");
}
int main() {
#ifdef _LOCAL
freopen("main.inp", "r", stdin);
freopen("main.out", "w", stdout);
#endif
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int t = 1;
if (multi_test) cin >> t;
while (t--) {
_main();
}
#ifdef _LOCAL
cerr << 0.001*clock() << endl;
#endif
return 0;
} |
#include<bits/stdc++.h>
////////////////////////////dbug/////////////////////////////////////////////////////////////////////////
#define dbug(a) cerr<<"==> "<<a<<endl;
#define dbug_ok cerr<<"==> ok"<<endl;
#define dbug_2d(a,n,m) {cerr<<"********"<<endl;for(int i=0;i<n;i++){for(int j=0;j<m;j++)cerr<<a[i][j]<<" "; cerr<<endl;}cerr<<"********"<<endl; }
#define dbug_1d(a,n) {cerr<<"********"<<endl;for(int i=0;i<n;i++)cerr<<a[i]<<" "; cerr<<endl;cerr<<"********"<<endl;}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////fill//////////////////////////////////////////////////////////////////////////
#define fill(a,n) memset(a,n,sizeof(n))
#define fill_2d(a,n,m,v) {for(int i=0;i<n;i++)for(int j=0;j<m;j++)a[i][j]=v;}
#define fill_3d(a,n,m,l,v) {for(int i=0;i<n;i++)for(int j=0;j<m;j++)for(int k=0;k<l;k++)a[i][j][k]=v;}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////loops/////////////////////////////////////////////////////////////////////////
#define fr(i,n) for(int i=0;i<n;i++)
#define fi(i,l,r) for(int i=l;i<=r;i++)
#define frfr(i,n,j,k) for(int i=0;i<n;i++)for(int j=0;j<k;j++)
#define fifi(i,l,r,j,l1,r1) for(int i=l;i<=r;i++)for(int j=l1;j<=r1;j++)
/////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////types////////////////////////////////////////////////////////////////////////
#define ll long long
#define pp pair<int,int>
#define pll pair<ll,ll>
#define T1 first
#define T2 second
/////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////print///////////////////////////////////////////////////////////////////////
#define _YES puts("YES")
#define _Yes puts("Yes")
#define _yes puts("yes")
#define _no puts("no")
#define _No puts("No")
#define _NO puts("NO")
/////////////////////////////////////////////////////////////////////////////////////////////////////////
using namespace std;
void solve()
{
ll n,x,a;
cin>>n>>x;
while(n--)
{cin>>a;
if(x!=a)cout<<a<<" ";
}
}
int main()
{
cin.tie(nullptr);
ios::sync_with_stdio(false);
solve();
}
| #include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define S second
#define F first
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vll vector<long long int>
#define pll pair<long long int,long long int>
#define mod 1000000007
#define mod2 998244353
#define ll long long int
#define ld long double
#define pi 3.141592653589793238
#define Endl endl
#define endl "\n"
const int N = 5e5 + 5;
const ll infP = 1e18;
void solve()
{
ll n , x;
cin >> n >> x;
for(ll i=0;i<n;i++)
{
ll y;
cin >> y;
if(y != x)
cout << y << " ";
}
}
void debug(ll tt) {}
signed main()
{
FAST;
int t = 1;
// cin >> t;
while(t--)
{
solve();
}
} |
#define NOMINMAX
#define TEST_MODE true
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep2(i,a,b) for(int i=(a);i<(int)(b);++i)
#define rrep(i,n) for(int i=(n)-1;i>=0;--i)
#define rrep2(i,a,b) for(int i=(a)-1;i>=(int)b;--i)
#define range(i,a,b,c) for(int i=a;c>0?i<b:i>b;i+=c)
#define chmax(a,b) (a=(a)<(b)?(b):(a))
#define chmin(a,b) (a=(a)>(b)?(b):(a))
#define i1(a) cin>>a;
#define i2(a,b) cin>>a>>b;
#define i3(a,b,c) cin>>a;i2(b,c);
#define p1(a) cout<<a<<endl;
#define p2(a,b) cout<<a<<" ";p1(b);
#define p3(a,b,c) cout<<a<<" ";p2(b, c);
#define abp(o,a,b) p1(((o)?a:b))
#define YEP(x) abp(x,"YES","NO")
#define Yep(x) abp(x,"Yes","No")
#define all(a) begin(a),end(a)
#define ifnot(a) if(!(a))
#define int long long
#ifdef LOCAL_ENV
#if TEST_MODE==true
const bool test=true;
#define dump(x) cerr<<#x<<" : "<<(x)<< " "
#define dumpl(x) dump(x)<<endl
#else
const bool test=false;
#define dump(x)
#define dumpl(x)
#endif
#else
const bool test=false;
#define dump(x)
#define dumpl(x)
#endif
using ll = int;
using ull = unsigned int;
using ld = long double;
ll dx[]={1,0,-1,0};
ll dy[]={0,1,0,-1};
const ll inf=(ll)1<<60;
const ll undefined=inf;
const ll INFL=(ll)1<<60;
ll mod_n=(ll)1e9+7;
const double eps=1e-10;
typedef long double Real;
// return -1, 0, 1
ll sgn(const Real&r){return(r>eps)-(r<-eps);}
ll sgn(const Real&a,const Real&b) {return sgn(a-b);}
const ll MAX = (ll)2e5 + 5;
vector<string> split(const string&str,char sep){vector<string> v;stringstream ss(str);string buffer;while (getline(ss, buffer, sep)) v.push_back(buffer);return v;}
string join(const vector<string>& v, const string delim = 0){string s;if(!v.empty()){s+=v[0];for(decltype(v.size()) i=1,c=v.size();i<c;++i){if(delim!="")s+=delim;s+=v[i];}}return s;}
string operator*(const string&s,const ll&n){string res="";rep(i,n)res+=s;return res;}
#define sum(a) accumulate(all(a),0ll)
template<typename T>T gcd(T a,T b){T c;while(a!=0){c=a;a=b%a;b=c;};return b;}
#define bit_cnt(n) [](int n){int c=0;while(N){if(N&1)c++;N>>=1;}return c;};
template<typename T>void prll_vec(ostream& o,vector<T> a){rep(i,a.size()-1)o<<a[i]<<" ";o<<a.back()<<endl;}
ll pow_n(ll x,ll n){ll r=1;while(n>0){if(n&1)r=r*x;x=x*x;n>>=1;}return r;}
ll H,W;
#define grid_ng(y,x) (y<0||y>=H||x<0||x>=W)
ll div_ceil(ll a,ll b){ll r=a/b;if(a%b!=0)r++;return r;}
struct Point{ll x,y;bool operator<(const Point&r)const{if(x!=r.x)return x<r.x;return y<r.y;}};
int n, k;
int t[10][10];
bool visited[10];
int visited_n = 0;
int cost = 0;
class Solver {
public:
int dfs(int curId) {
if (visited_n == n - 1) {
return cost + t[curId][0] == k;
}
int cnt = 0;
rep(i, n) {
if (visited[i] == false) {
visited[i] = true;
cost += t[curId][i];
visited_n++;
cnt += dfs(i);
visited[i] = false;
cost -= t[curId][i];
visited_n--;
}
}
return cnt;
}
void solve() {
cin >> n >> k;
rep(i, n) {
rep(j, n) {
cin >> t[i][j];
}
}
visited[0] = true;
cout << dfs(0) << endl;
}
};
signed main(){srand((unsigned int)time(NULL));cout<<fixed<<setprecision(20);auto ptr=new Solver();ptr->solve();delete ptr;return 0;} | #include <bits/stdc++.h>
#define pb push_back
#define SZ(x) ((int)(x.size()))
#define FOR(i,s,n) for (ll i = (s); (i) < (n); ++i)
#define FORD(i,s,l) for (ll i = (s); (i) >= l; --i)
#define F first
#define S second
#define TC int __tc; cin >> __tc; FOR(case_num,1,__tc+1)
#define TEST(x,i) ((x)&(1ll<<(i)))
#define SET(x,i) ((x)|(1ll<<(i)))
#define FLIP(x,i) ((x)^(1ll<<(i)))
#define CLEAR(x,i) ((x)&~(1ll<<(i)))
const double pi = 4 * atan(1);
using namespace std;
typedef long long ll;
map<int,int> m;
int op[205];
int a[205];
int b[205];
bool dp[205][205];
bool dp2[205][205];
bool solve(int start, int end) {
bool &ret = dp[start][end];
if (dp2[start][end]){
return ret;
}
dp2[start][end]=true;
int d = (end-start)/2;
bool good = true;
for (int i = start; i+d < end && good; i++){
if (op[i] || op[i+d]) {
if (op[i] != i+d) {
good = false;
}
}
if (m.count(i)){
if (a[m[i]] != i) {
good = false;
}
}
if (m.count(i+d)) {
if (b[m[i+d]] != i+d) {
good = false;
}
}
if (m.count(i)&&m.count(i+d)){
if (m[i]!=m[i+d]) {
good = false;
}
}
}
if (good) {
return ret = true;
}
for (int i = start+2; i < end; i+=2){
if (solve(start,i) && solve(i,end)) {
return ret = true;
}
}
return ret = false;
}
bool answer() {
int n;
cin >> n;
int cnt = 0;
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
if (a[i]!=-1) {
m[a[i]]=i;
cnt++;
}
if (b[i]!=-1) {
m[b[i]]=i;
cnt++;
}
if (a[i]!=-1 && b[i]!=-1){
op[a[i]]=b[i];
op[b[i]]=a[i];
}
}
if(cnt!=(int)m.size()) return false;
for (int i = 0; i < n; i++) {
if (a[i] != -1 && b[i] != -1 && a[i] >= b[i])
return false;
}
return solve(1,2*n+1);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout << (answer() ? "Yes" : "No") << "\n";
}
|
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#include<bitset>
#include<functional>
#include <fstream>
//#include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define rep(i, x) for(ll i = 0; i < x; i++)
#define rep2(i, x) for(ll i = 1; i <= x; i++)
#define rep3(i, x, y) for(ll i = x; i < y; i++)
#define rep4(i, x) for(ll i = x; i >= 0; i--)
#define all(a) (a).begin(),(a).end()
#define puts(x) cout << (x) << "\n"
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 1000000000000000000;
const int intINF = 1000000000;
const ll mod = 1000000007;
const ll MOD = 998244353;
const ld pi = 3.141592653589793238;
//const ld EPS = 1e-9;
bool isprime(int p) {
if (p == 1) return false;
for (int i = 2; i < p; i++) {
if (p % i == 0) return false;
}
return true;
}
ll gcd(ll a, ll b) {
if (a < b)swap(a, b);
if (a % b == 0)return b;
return gcd(b, a % b);
}
// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
//main関数内に extGCD(a, b, x, y); でx, yに解が格納
ll extGCD(ll a, ll b, ll& x, ll& y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
ll d = extGCD(b, a % b, y, x);
y -= a / b * x;
return d;
}
ll lcm(ll a, ll b) {
return a / gcd(a, b) * b;
}
ll keta(ll n) {
ll res = 0;
while (n >= 1) {
res += n % 10; n /= 10;
}
return res;
}
ll modpow(ll x, ll y) {
ll res = 1;
while (y) {
if (y % 2) { res *= x; res %= mod; }
x = x * x % mod; y /= 2;
}
return res;
}
ll nCk(ll n, ll k) {
ll a = 1, b = 1;
for (int h = n - k + 1; h <= n; h++) { a *= h; a %= mod; }
for (int h = 1; h <= k; h++) { b *= h; b %= mod; }
return a * modpow(b, mod - 2) % mod;
}
//printf("%.10f\n", n);
typedef pair <ll, ll> P;
typedef pair <ld, ll> pp;
ll dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
struct edge { ll to, cost; };
struct status {
ll ima;
ll cost;
bool operator<(const status& rhs) const { return cost < rhs.cost; };
bool operator>(const status& rhs) const { return cost > rhs.cost; };
};
int main() {
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
//cout << fixed << setprecision(15);
//input
ll n; string s; cin >> n >> s;
vector<ll>a(n + 1); ll mi = INF;
rep(i, n + 1) {
cin >> a[i]; //mi = min(mi, a[i]);
}
rep(i, n) {
if (s[i] == '<') {
mi = min(mi, a[i + 1] - a[i]);
}
else {
mi = min(mi, a[i] - a[i + 1]);
}
}
vector<vector<ll>> ans(n + 2, vector<ll>(10002));
rep(i, n + 1) {
ll cnt = a[i];
rep(j, mi) {
ans[i][j] = cnt / (mi - j); cnt -= ans[i][j];
}
}
cout << mi << endl;
rep(j, mi) {
rep(i, n + 1) {
if (i != 0) { cout << ' '; }
cout << ans[i][j];
}
cout << endl;
}
return 0;
} | #include<iostream>
#include<algorithm>
#include<cstdlib>
#include<sstream>
#include<cstring>
#include<cstdio>
#include<string>
#include<deque>
#include<cmath>
#include<queue>
#include<set>
#include<map>
using namespace std;
struct Diff {
int thePos;
long long rPos;
long long rNeg;
long long max;
long long a;
long long b;
int d;
};
Diff diffs[100010];
int k;
long long n, m;
//long long a[100010];
//long long rPos[100010];
//long long rNeg[100010];
//
//long long b[100010];
bool compare(const Diff &a, const Diff &b) {
if (a.max == b.max) {
return a.thePos < b.thePos;
} else {
return a.max > b.max;
}
}
bool comparePos(const Diff &a, const Diff &b) {
return a.thePos < b.thePos;
}
int main(void)
{
scanf("%lld%lld%lld", &k, &n, &m);
for (int i = 0 ; i < k ; i++) {
scanf("%lld", &(diffs[i].a));
diffs[i].rPos = diffs[i].a * m % n;
diffs[i].rNeg = n - diffs[i].rPos;
diffs[i].thePos = i;
//似乎不会有相等额情况
if (diffs[i].rPos > diffs[i].rNeg) {
diffs[i].max = diffs[i].rPos;
} else {
diffs[i].max = diffs[i].rNeg;
}
}
sort(diffs, diffs + k, compare);
long long balance = 0;
//balance的值是固定的!
for (int i = 0 ; i < k ; i++) {
//似乎不会有相等额情况
if (diffs[i].rPos < diffs[i].rNeg) {
diffs[i].d = 1; //正向
balance = balance + diffs[i].rPos;
} else { //负向
diffs[i].d = -1;
balance = balance - diffs[i].rNeg;
}
}
int pPos = k - 1;
if (balance > 0) {
while (balance > 0) {
if (diffs[pPos].d == 1) {
diffs[pPos].d = -1;
balance = balance - n;
}
pPos--;
}
} else if (balance < 0) {
while (balance < 0) {
if (diffs[pPos].d == -1) {
diffs[pPos].d = 1;
balance = balance + n;
}
pPos--;
}
}
sort(diffs, diffs + k, comparePos);
for (int i = 0 ; i < k ; i++) {
diffs[i].b = diffs[i].a * m / n;
if (diffs[i].d < 0) {
diffs[i].b++;
}
}
for (int i = 0 ; i < k ; i++) {
printf("%d ", diffs[i].b);
}
printf("\n");
return 0;
}
|
#include"bits/stdc++.h"
using namespace std;
#define ll long long
#define ul unsigned long long
#define ui unsigned int
#define ri register int
#define pb push_back
#define mp make_pair
char p[30]={'0','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
inline ll rd(){
ll x=0,flag=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-') flag=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+(ch^48);ch=getchar();}
return x*flag;
}
ll n;
inline int lowbit(int x){return x & ( - x ) ;}
int main()
{
n=rd();int ok=0;
for(ll i=1;i*i<=n;++i){
if(n%i==0){
if(i&1||((n/i)&1)){
ok+=2;
if(i*i==n) continue;
if((i&1)&&((n/i)&1)) ok+=2;
}
}
}
cout<<ok;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
#define rep(i, n) for (int i=0; i<(n); ++i)
#define each(v, i) for (auto i : v)
#define pb push_back
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define maxs(x, y) x = max(x, y)
#define mins(x, y) x = min(x, y)
#define pcnt __builtin_popcount
#define rng(a) a.begin(), a.end()
#define out(v) cout << v << endl
template<typename T> using vc = vector<T>;
template<typename T> using vv = vector<vector<T>>;
using vi = vc<int>;
int main() {
int N; cin >> N;
N = N * 108/100;
int limit = 206;
if (N < limit) out("Yay!");
else if (N == limit) out("so-so");
else out(":(");
return 0;
} |
#include <bits/stdc++.h>
//#include <atcoder/all>
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using namespace std;
//using namespace atcoder;
const int mod = 998244353;
const int INF =1e9+1;
int ans=INF;
int main(){
int h,w,n,m;cin>>h>>w>>n>>m;
vector<vector<int>> math(h,vector<int> (w,0));
vector<pair<int,int>> light(n);
rep(i,n){
int a,b;cin>>a>>b;
math[a-1][b-1]=1;
light[i]=make_pair(a-1,b-1);
}
rep(i,m){
int a,b;cin>>a>>b;
math[a-1][b-1]=2;
}
rep(i,n){
int H=light[i].first,W=light[i].second;
int W1=W;
if(math[H][W]==3)continue;
while(++W<w&&math[H][W]!=2){
math[H][W]=3;
}
while(--W1>=0&&math[H][W1]!=2){
math[H][W1]=3;
}
}
rep(i,n){
int H=light[i].first,W=light[i].second;
int H1=H;
if(math[H][W]==4)continue;
while(++H<h&&math[H][W]!=2){
math[H][W]=4;
}
while(--H1>=0&&math[H1][W]!=2){
math[H1][W]=4;
}
}
int ans=0;
rep(i,h)rep(j,w){
if(math[i][j]==3||math[i][j]==4||math[i][j]==1)ans++;
}
cout<<ans<<endl;
}
| #include<bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define pb push_back
int32_t main(){
int n,m,a,b;
cin>>n>>m>>a>>b;
int grid[n][m];
memset(grid,-1,sizeof(grid));
//for bulbs
for(int i=0;i<a;i++){
int r,c;
cin>>r>>c;
r--;c--;
grid[r][c]=1;
}
//for blocks
for(int i=0;i<b;i++){
int r,c;
cin>>r>>c;
r--;c--;
grid[r][c]=2;
}
/*for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cout<<grid[i][j]<<" ";
}
cout<<endl;
}*/
int ans[n][m];
memset(ans,0,sizeof(ans));
//now solve for individual rows first
//yaar ab batao aage kya kare ya phir mtlb kya karna chahiye more precisely
for(int i=0;i<n;i++){
int s=0;
int lit=0;
for(int j=0;j<m;j++){
//block aa gya
if(grid[i][j]==2){
s=j+1;
lit=0;
}
//bulb aa gya
else if(grid[i][j]==1){
while(s<=j){
ans[i][s]=1;
s++;
}
lit=1;
s=j+1;
}
else {
if(lit) ans[i][j]=1;
}
}
}
//now solve for columns
for(int j=0;j<m;j++){
int s=0;
int lit=0;
for(int i=0;i<n;i++){
//block aa gya
if(grid[i][j]==2){
s=i+1;
lit=0;
}
//bulb aa gya
else if(grid[i][j]==1){
while(s<=i){
ans[s][j]=1;
s++;
}
lit=1;
s=i+1;
}
else {
if(lit) ans[i][j]=1;
}
}
}
int cnt=0;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cnt+=ans[i][j];
}
//cout<<endl;
}
cout<<cnt<<endl;
} |
# include <bits/stdc++.h>
using namespace std;
# define rep(i,a,n) for (int i=a; i<=n; ++i)
# define per(i,a,n) for (int i=a; i>=n; --i)
# define bug puts("H");
# define pb push_back
# define mp make_pair
# define all(x) (x).begin(), (x).end()
# define SZ(x) (int)x.size()
# define fi first
# define se second
# define lch p<<1,l,mid
# define rch p<<1|1,mid+1,r
# define mem(a,b) memset(a,b,sizeof(a))
# define INF 1000000001
# define MOD 1000000007
typedef vector<int> Vi;
typedef long long i64;
typedef pair<int, int> Pi;
mt19937 mrand(random_device{}());
int rnd(int x) {return mrand()%x;}
i64 powmod(i64 a, i64 b){i64 res=1;a%=MOD;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}
i64 Inv(i64 b){return powmod(b,(i64)MOD-2);}
typedef long long ll;
const int N = 100005;
const double eps = 1e-9;
const double inf = 1e18;
char s[1005];
int main ()
{
int T;
cin >> T;
string str = "atcoder", tmp;
while (T--) {
cin >> tmp;
int ans = INF;
if (str < tmp) ans = 0;
else {
int sz = SZ(tmp);
rep(i,1,sz-1) {
rep(j,0,min(i-1,6)) {
string t;
if (j) t += tmp.substr(0,j);
t += tmp[i];
t += tmp.substr(j,i-j);
t += tmp.substr(i+1,sz-1-i);
if (str < t) ans = min(ans, i-j);
//cout << i << " " << j << " " << t << endl;
}
}
}
if (ans == INF) cout << -1 << endl;
else cout << ans << endl;
}
return 0;
}
| #include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"
using namespace std;
constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-12;
int N, M, K, T, H, W, L, R;
//long long int N, M, K, T, H, W, L, R;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> T;
string t = "atcoder";
while (T--) {
string s;
cin >> s;
if (t < s) {
cout << 0 << endl;
continue;
}
int ans = MOD;
for (int i = 0; i < s.size() && i < t.size(); i++) {
for (int j = i + 1; j < s.size(); j++) {
if (t[i] < s[j]) {
ans = min(ans, j - i);
}
}
if (s[i] != t[i])break;
}
if (ans == MOD)ans = -1;
cout << ans << endl;
}
} |
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
long long a[45],b[45],d=0,t,n;
void DFS(int c,long long r);
int main()
{
cin>>n>>t;
for(int i = 1;i <= n;i++)
{
scanf("%d",&a[i]);
}
sort(a+1,a+n+1);
reverse(a+1,a+n+1);
for(int i=n;i>=1;i--)
{
b[i]=b[i+1]+a[i];
}
DFS(0,t);
cout << d;
return 0;
}
void DFS(int c,long long r)
{
if(c>n)
{
return;
}
d=max(d,t-r);
if(r==0)
{
cout<<t;
exit(0);
}
if(t-r+b[c+1]<=d)
{
return;
}
if(r-a[c+1]>=0)
{
DFS(c+1,r-a[c+1]);
}
DFS(c+1,r);
}
| #include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const ll inf=1e9+7;
const ll INF=1e18;
const ll mod=99824453;
vin dx={-1,0,1,0};
vin dy={0,1,0,-1};
int main(){
int n;ll t;cin>>n>>t;
vll a(n);rep(i,n)cin>>a[i];
int k=n/2,h=n-k;
vll x,y;
ll sum;
rep(i,(1<<k)){
bitset<22> tmp(i);
sum=0;
rep(j,k)if(tmp[j])sum+=a[j];
x.push_back(sum);
}
rep(i,(1<<h)){
bitset<22> tmp(i);
sum=0;
rep(j,h)if(tmp[j])sum+=a[k+j];
y.push_back(sum);
}
sort(all(y));
ll ans=0;
int l,r,m;
rep(i,x.size()){
l=-1;r=y.size();
while(r-l>1){
m=(l+r)/2;
if(y[m]+x[i]>t)r=m;
else l=m;
}
if(l>-1)ans=max(ans,y[l]+x[i]);
}
cout<<ans<<endl;
} |
#include <bits/stdc++.h>
using namespace std;
long long INF = 1000000000000000000;
int main(){
long long A, B;
cin >> A >> B;
vector<long long> d;
for(int i = 2; i <= 72; i++){
if(i == 2) d.push_back(i);
if(i % 2 == 0) continue;
bool flag = true;
for(int j = 2; j * j <= i; j++){
if(i % j == 0) flag = false;
}
if(flag) d.push_back(i);
}
int L = d.size();
vector<vector<long long>> dp((B - A + 2), vector<long long>(1 << L));
int ind = 0;
dp[0][0] = 1;
for(long long i = A; i <= B; i++){
long long bit = 0;
for(int k = 0; k < L; k++){
if(i % d[k] == 0) bit |= (1 << k);
}
for(int j = 0; j < (1 << 20); j++){
if((j & bit) == 0) dp[ind + 1][j | bit] += dp[ind][j];
dp[ind + 1][j] += dp[ind][j];
}
ind++;
}
long long ans = 0;
for(int i = 0; i < (1 << L); i++) ans += dp[B - A + 1][i];
cout << ans << endl;
} | #include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define pii pair<ll,ll>
#define inf 1000000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define autoitr(x,it) for(auto it = x.rbegin(); it != x.rend(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
vector<vector<ll>> g;
ll powa[64];
ll get(vector<ll> &v)
{
ll n = v.size();
if(n<2)
return n;
ll fst = (n+1)/2, sec = n/2;
vector<ll> v1,v2;
rep(n)
if(i<fst)
v1.pb(v[i]);
else v2.pb(v[i]);
ll self1[fst], self2[sec], cross[fst];
rep(fst)
self1[i] = powa[fst] - 1;
rep(sec)
self2[i] = powa[sec] - 1;
rep(fst)
cross[i] = powa[sec] - 1;
for(ll i=0;i<fst;i++)
for(ll j=0;j<fst;j++)
{
if(i != j && __gcd(v1[i],v1[j]) > 1)
self1[i]-=powa[j];
}
for(ll i=0;i<sec;i++)
for(ll j=0;j<sec;j++)
{
if(i != j && __gcd(v2[i],v2[j]) > 1)
self2[i]-=powa[j];
}
for(ll i=0;i<fst;i++)
for(ll j=0;j<sec;j++)
{
if(__gcd(v1[i],v2[j]) > 1)
cross[i]-=powa[j];
}
vector<ll> s1, s2;
for(ll mask=1;mask<powa[fst];mask++)
{
ll allowed = powa[fst] - 1;
for(ll j=0;j<fst;j++)
if(powa[j]&mask)
allowed&=self1[j];
if((mask&allowed) != mask)
continue;
s1.pb(mask);
}
for(ll mask=1;mask<powa[sec];mask++)
{
ll allowed = powa[sec] - 1;
for(ll j=0;j<sec;j++)
if(powa[j]&mask)
allowed&=self2[j];
if((mask&allowed) != mask)
continue;
s2.pb(mask);
}
ll dp[sec+1][powa[sec]];
memset(dp,0,sizeof(dp));
for(auto &x : s2)
dp[sec][x] = 1;
for(ll bit=sec-1;bit>-1;bit--)
{
for(ll mask=0;mask<powa[sec];mask++)
{
if(powa[bit]&mask)
dp[bit][mask]+=(dp[bit+1][mask] + dp[bit+1][mask^powa[bit]]);
else dp[bit][mask]+=(dp[bit+1][mask]);
}
}
ll ans = 0;
for(auto &x : s1)
{
ll allowed = powa[sec] - 1;
for(ll j=0;j<fst;j++)
if(powa[j]&x)
allowed&=cross[j];
ans+=dp[0][allowed];
}
ans+=((ll)s1.size());
ans+=((ll)s2.size());
return ans;
}
int main()
{
FAST/**/
powa[0] = 1;
for(ll i=1;i<64;i++)
powa[i] = powa[i-1]*2;
ll a,b;
cin>>a>>b;
vector<ll> even;
vector<ll> nums;
for(ll i=a;i<=b;i++)
if(i%2 == 0)
even.pb(i);
else nums.pb(i);
ll ans = 1;
ans+=get(nums);
for(ll i=0;i<even.size();i++)
{
vector<ll> v1;
for(ll j=0;j<nums.size();j++)
{
if(__gcd(nums[j], even[i]) == 1)
v1.pb(nums[j]);
}
ans+=(1ll + get(v1));
}
cout<<ans<<'\n';
return 0;
}
|
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define read(a) for(auto &z : a) cin >> z;
#define write(a) {for(auto &z : a) cout << z << ' ';cout << '\n';}
#define print(a) cout << a << "\n";
#define all(a) a.begin(), a.end()
int32_t main() {
ios_base::sync_with_stdio(false); cin.tie(0);
int _ = 1, n, m;
// cin >> _;
outer : while(_--) {
// int a, b;
// cin >> a >> b;
// double ans = ((a*1.0)/100.0) * b;
// cout << fixed << setprecision(9) << ans << "\n";
cin >> n;
vector<int> a(n);
read(a);
sort(all(a));
int flag = 1;
for(int i = 0 ; i < n ; i++) {
flag &= (a[i] == i+1);
}
cout << (flag ? "Yes\n" : "No\n");
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
// #include <atcoder/all>
// using namespace atcoder;
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll = long long;
const ll INF = 1001001001001001001;
void solve(long long N, std::vector<long long> a, std::vector<long long> t, long long Q, std::vector<long long> x){
ll mn = -INF;
ll mx = INF;
ll bias = 0;
rep(i, N) {
if (t[i] == 1) {
bias += a[i];
mn += a[i];
mx += a[i];
} else if (t[i] == 2) {
mn = max(mn, a[i]);
mx = max(mx, a[i]);
} else {
mn = min(mn, a[i]);
mx = min(mx, a[i]);
}
}
rep(i, Q) {
ll n = x[i] + bias;
if (mn <= n && n <= mx) {
cout << n << endl;
} else if (n < mn) {
cout << mn << endl;
} else {
cout << mx << endl;
}
}
}
// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
int main(){
long long N;
scanf("%lld",&N);
std::vector<long long> a(N);
std::vector<long long> t(N);
for(int i = 0 ; i < N ; i++){
scanf("%lld",&a[i]);
scanf("%lld",&t[i]);
}
long long Q;
scanf("%lld",&Q);
std::vector<long long> x(Q);
for(int i = 0 ; i < Q ; i++){
scanf("%lld",&x[i]);
}
solve(N, std::move(a), std::move(t), Q, std::move(x));
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x) << '\n'
typedef long long ll;
using P = pair<int,int>;
using pll = pair<ll,ll>;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
template <typename T> inline bool chmax(T &a, T b) {return a < b ? a = b, true : false;}
template <typename T> inline bool chmin(T &a, T b) {return a > b ? a = b, true : false;}
void solve(){
int n; cin >> n;
vector<ll> a(n);
for(int i = 0; i < n; i++) cin >> a[i];
vector<ll> c(n + 1, 0LL), d(n + 1, 0LL);
for (ll i = 0; i < n; i++) {
if(i % 2 == 0){
c[i + 1] = c[i] + a[i];
d[i + 1] = d[i];
}
else{
c[i + 1] = c[i];
d[i + 1] = d[i] + a[i];
}
}
map<ll,ll> mp;
for (ll i = 0; i < n + 1; i++) mp[c[i] - d[i]]++;
ll ans = 0;
for (auto p : mp) {
ll w = p.second;
ans += w * (w-1) / 2;
}
print(ans);
return;
}
int main() {
cin.tie(0); cout.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(18);
int t;
//cin >> t;
t = 1;
while(t--) solve();
return 0;
} | #include"bits/stdc++.h"
using namespace std;
vector<string> split(const string & s, char c=' ') {
vector<string> v; stringstream ss(s); string x;
while (getline(ss, x, c)) v.emplace_back(x); return move(v);
}
template<typename T, typename... Args>
inline string arrStr(T arr, int n) {
stringstream s; s << "[";
for(int i = 0; i < n - 1; i++) s << arr[i] << ",";
s << arr[n - 1] << "]";
return s.str();
}
#define EVARS(args...) {__evars_begin(__LINE__); __evars(split(#args, ',').begin(), args);}
inline void __evars_begin(int line) { cerr << "#" << line << ": "; }
template<typename T> inline void __evars_out_var(vector<T> val) { cerr << arrStr(val, val.size()); }
template<typename T> inline void __evars_out_var(T* val) { cerr << arrStr(val, 10); }
template<typename T> inline void __evars_out_var(T val) { cerr << val; }
inline void __evars(vector<string>::iterator it) { cerr << endl; }
template<typename T, typename... Args>
inline void __evars(vector<string>::iterator it, T a, Args... args) {
cerr << it->substr((*it)[0] == ' ', it->length()) << "=";
__evars_out_var(a);
cerr << "; ";
__evars(++it, args...);
}
template<typename T>
void maxa(T &a,T b){
if(a<b) a=b;
}
template<typename T>
void mina(T &a,T b){
if(a>b) a=b;
}
#define int long long
#define ll int
// const int inf=1e18;
#define F first
#define S second
#define Z(c) (int)(c).size()
#define pii pair<int,int>
const int mod=1e9+7;
const int N=2e5+10;
vector<int> adj[N];
int ct,vt[N];
void dfs(int x){
if(vt[x]) return;
vt[x]=1;
ct++;
for(int i:adj[x]) dfs(i);
}
void boomer(){
int n; cin>>n;
vector<int> v(n);
for(int &x:v) cin>>x;
int lt=0,rt=n-1;
while(lt<rt){
if(v[lt]!=v[rt]){
adj[v[lt]].push_back(v[rt]);
adj[v[rt]].push_back(v[lt]);
}
lt++;
rt--;
}
int ans=0;
for(int x:v){
ct=0;
dfs(x);
ans+=max(0LL,ct-1);
}
cout<<ans;
}
signed main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
int tc=1;
// cin>>tc;
for(int i=1;i<=tc;++i)
{
// cout<<"Case #"<<i<<": ";
boomer();
if(i<tc)
cout<<"\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void solve(){
int N,M;
cin>>N>>M;
vector<pair<int,int>> cond(M);
for(int i=0; i<M; i++){
int t1,t2;
cin>>t1>>t2;
cond[i]=make_pair(t1,t2);
}
int K;
cin>>K;
vector<pair<int,int>> person(K);
for(int i=0; i<K; i++){
int t1,t2;
cin>>t1>>t2;
person[i]=make_pair(t1,t2);
}
int last=0;
vector<int> dishes(N,0);
for(int i=0; i<(1<<K); i++){
int temp=0;
bitset<17> b(i);
dishes.assign(N,0);
for(int j=0; j<K; j++){
if(b[j]==0){
dishes[person[j].first-1]++;
}
else{
dishes[person[j].second-1]++;
}
}
for(auto x: cond){
if(dishes[x.first-1]>=1 && dishes[x.second-1]>=1){
temp++;
}
}
last=max(last,temp);
}
cout<<last<<endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t=1;
//cin>>t;
while(t--){
solve();
}
return 0;
}
| #include <bits/stdc++.h>
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define lli long long int
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define vi vector<int>
#define all(a) a.begin(),a.end()
#define sz(a) a.size()
using namespace std;
// bitset<8>set1(p);
// __builtin_popcountll(x);
// bitset<100> b("1010");
ll int MM = 998244353;
const int mod = 1e9 + 7;
const int INF = 1e9 + 5;
void solve()
{
int n,m;
cin >> n >> m;
vector<pair<int,int>> dish1(m);
FOR(i,0,m) {
cin >> dish1[i].first >> dish1[i].second;
}
int k;
cin >> k;
vector<pair<int,int>> dish2(k);
FOR(i,0,k) {
cin >> dish2[i].first >> dish2[i].second;
}
int mxans = 0;
for(int i=0;i<(1<<k);i++)
{
int ans = 0;
map<int,int>mpp;
for(int j=0;j<k;j++)
{
if((1<<j)&i)
{
mpp[dish2[j].first]++;
}
else
{
mpp[dish2[j].second]++;
}
}
FOR(i,0,m)
{
if(mpp[dish1[i].first] and mpp[dish1[i].second])
ans++;
}
mxans = max(mxans,ans);
}
cout << mxans << "\n";
}
int main()
{
ios;
#ifndef ONLINE_JUDGE
freopen("input2.txt","r",stdin);
freopen("output2.txt","w",stdout);
#endif
int t;
t=1;
// cin>>t;
while(t--)
{
solve();
}
} |
#include <bits/stdc++.h>
using namespace std;
int n;
vector <string> s;
vector <unsigned long long> t,f;
int main(){
cin >> n;
s = vector<string>(n);
for(int i = 0; i < n; i++){
cin >> s[i];
}
t = vector<unsigned long long>(n+1,0);
f = vector<unsigned long long>(n+1,0);
t[0]=1;
f[0]=1;
for(long long i = 1; i <= n; i++){
if(s[i-1].compare("AND")==0){
t[i]=t[i-1];
f[i]=t[i-1]+2*f[i-1];
}else{
t[i]=f[i-1]+2*t[i-1];
f[i]=f[i-1];
}
}
#if 0
for(long i = 0; i <= n; i++){
cout << t[i] << " ";
}
cout << endl;
for(long i = 0; i <= n; i++){
cout << f[i] << " ";
}
cout << endl;
#endif
cout << t.back() << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
#define sz(a) int((a).size())
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define ini(a, i) memset(a, i, sizeof(a))
#define inin(a, n, i) memset(a, i, sizeof(a[0])*(n))
#define contains(c, i) ((c).find(i) != (c).end())
#define present(i, c) (find(all(c), i) != (c).end())
#define trav(x, c) for(auto& x : c)
#define rep(i, n) for(int i = 0; i < n; i++)
#define repa(i, b, e) for(int i = (b)-((b)>(e)); i != (e)-((b)>(e)); i += 1-2*((b)>(e)))
template<class T> bool chkmax(T &x, T y) { return x < y ? x = y, true : false; }
template<class T> bool chkmin(T &x, T y) { return x > y ? x = y, true : false; }
template<class A, class B> A cvt(B x) { stringstream s; s << x; A r; s >> r; return r; }
void read() {}
void print() {}
template<class T, class... Args> void read(T& a, Args&... args) { cin >> a; read(args...); }
template<class T, class... Args> void print(T a, Args... args) { cout << a << ' '; print(args...); }
template<class... Args> void println(Args... args) { print(args...); cout << '\n'; }
#define debug(args...) { string s_(#args); replace(all(s_), ',', ' '); stringstream ss_(s_); istream_iterator<string> it_(ss_); cerr_(it_, args); }
void cerr_(istream_iterator<string> it) { (void) it; }
template<class T, class... Args> void cerr_(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << endl; cerr_(++it, args...); }
template<class T, class S> ostream& operator<<(ostream& os, const pair<T, S>& p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<class T> ostream& operator<<(ostream &os, const set<T> &s) { os << '{'; string sep; for (const auto &x : s) os << sep << x, sep = ", "; return os << '}'; }
template<class T, class S> ostream& operator<<(ostream &os, const map<T, S> &m) { os << '{'; string sep; for (const auto &x : m) os << sep << x, sep = ", "; return os << '}'; }
template<class T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
const int INF = 0x3F3F3F3F;
const int MAXN = (int) 1e6;
const int MOD = (int) 1e9+7;
//=========================
void run_test() {
int n; read(n);
vi v(n+1);
rep(i, n) {
string s; read(s);
if(s == "AND") v[i+1] = 0;
else v[i+1] = 1;
}
vector<vll> dp(2, vll(n+1));
dp[1][0] = 1;
dp[0][0] = 1;
for(int i = 1; i <= n; i++) {
if(!v[i]) {
dp[1][i] += dp[1][i-1];
dp[0][i] += dp[0][i-1] + dp[1][i-1]; // current is false
dp[0][i] += dp[0][i-1]; // current is true
} else {
dp[1][i] += dp[1][i-1] + dp[0][i-1]; // current is true
dp[1][i] += dp[1][i-1]; // current is false
dp[0][i] += dp[0][i-1];
}
}
ll ans = dp[1][n];
println(ans);
}
//=========================
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
//int t_ = 1, t__; cin >> t__; while(t_ <= t__) { cout << "Case #" << t_++ << ": "; run_test(); }
// int t_; cin >> t_; while(t_--) run_test();
run_test();
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <cmath>
using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF
constexpr int INTINF {1000000000};//int = 2*INTINF
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t; ++i)
template<typename T>
void maxs(T& x, T&& y) {
x=std::max(x,y);
}
template<typename T>
void maxs(T& x, T& y) {
x=std::max(x,y);
}
template<typename T>
void mins(T& x, T&& y) {
x=std::min(x,y);
}
template<typename T>
void mins(T& x, T& y) {
x=std::min(x,y);
}
using Pair = std::pair<int, int>;
char winner(const char& l, const char& r) {
if (l == r) return l;
if (l == 'R' && r == 'P' || l == 'P' && r == 'R') return 'P';
if (l == 'S' && r == 'P' || l == 'P' && r == 'S') return 'S';
if (l == 'R' && r == 'S' || l == 'S' && r == 'R') return 'R';
return '.';
}
int main() {
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n, k;
cin >> n >> k;
std::string s;
cin >> s;
s += s;
std::string target_s {s};
for (auto i = 0;i < k;++i) {
int new_s_size {static_cast<int>(target_s.size())};
std::string new_s{};
for (auto j = 0;j < new_s_size;++j) {
new_s += winner(target_s[2*j%n], target_s[(2*j + 1)%n]);
}
target_s = new_s;
//std::cout << target_s << '\n';
}
cout << target_s[0] << '\n';
}
| #include<bits/stdc++.h>
#define int ll
#define sz(x) int((x).size())
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using pi = pair<int,int>;
const int inf = 0x3f3f3f3f3f3f3f3f;
const int minf = 0xc0c0c0c0c0c0c0c0;
const int N = 2002002;
const int mod = int(1e9) + 7;
struct Modular {
int fact[N+5], inv[N+5], fact_inv[N+5];
Modular() {
fact[0] = fact[1] = inv[1] = fact_inv[0] = fact_inv[1] = 1;
for (int i=2; i<=N; i++) {
fact[i] = ll(fact[i-1])*i%mod;
}
for (int i=2; i<=N; i++) {
inv[i] = -mod/i*ll(inv[mod%i])%mod+mod;
}
for (int i=2; i<=N; i++) {
fact_inv[i] = ll(fact_inv[i-1])*inv[i]%mod;
}
}
int comb(int n, int r) {
return n>=r && r>=0 ? ll(fact[n])*fact_inv[n-r]%mod*fact_inv[r]%mod : 0;
}
int perm(int n, int r) {
return n>=r && r>=0 ? ll(fact[n])*fact_inv[n-r]%mod : 0;
}
} modular;
signed main() {
ios::sync_with_stdio(0); cin.tie(0);
int n,m,k; cin>>n>>m>>k;
if (n > m+k) {
cout<<0<<'\n';
return 0;
}
int res = modular.comb(n+m, n);
res -= modular.comb(m+n, k+1+m);
if (res < 0) res += mod;
cout<<res<<'\n';
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 r() {
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 r()
ll n,cmp;
ll a[200010];
ll b[200010];
vector<ll> e[200010];
ll in[200010];
bool vis[200010];
ll viss[200010];
void dfs(ll u){
//vis[u]=1;
if(in[u]==0)cout<<u<<"\n",vis[u]=1;
for(int i=0;i<e[u].size();i++){
ll v=e[u][i];
if(vis[v]||in[v]==0)continue;
in[v]--;
dfs(v);
}
}
int main(){
n=d;
f(i,1,n)a[i]=d,b[i]=i-a[i],cmp+=abs(b[i]);
if(cmp/2>=n){
cout<<-1;
return 0;
}
f(i,1,n){
if(b[i]>0){
ll now=i-1;
viss[now]++;
for(int j=i-2;j>=a[i];j--)e[now].push_back(j),in[j]++,viss[j]++,now=j;
}
if(b[i]<0){
ll now=i;
viss[now]++;
f(j,i+1,a[i]-1)e[now].push_back(j),viss[j]++,in[j]++,now=j;
}
}
// f(i,1,n-1){
// for(int j=0;j<e[i].size();j++)cout<<e[i][j]<<" ";
// cout<<endl;
// }
f(i,1,n-1){
//cout<<in[i]<<" ";
if(viss[i]!=2||b[i]==0){
cout<<-1;
return 0;
}
}
f(i,1,n-1)if(in[i]==0&&!vis[i])dfs(i);
return 0;
}
| #include<cmath>
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<map>
#include<queue>
#include<set>
#include<vector>
#include<bitset>
using namespace std;
const int maxn=105;
int n,k,m,a[maxn],sum;
inline int read()
{
int x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9')
{
if(ch=='-')
f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9')
{
x=(x<<1)+(x<<3)+(ch^48);
ch=getchar();
}
return x*f;
}
inline void write(int a)
{
if(a<0)
{
char a='-',b='1';
putchar(a);
putchar(b);
}
else
{
if(a>=10)
write(a/10);
putchar(a%10+'0');
}
}
int main()
{
n=read(),k=read(),m=read();
for(int i=1;i<n;++i)
a[i]=read(),sum+=a[i];
int shu=n*m-sum;
if(shu>k)
puts("-1");
else
write(max(0,shu));
return 0;
}
|
#include <bits/stdc++.h>
#define INF 1e18
#define mod 998244353
#define rep(i,n,m) for(int i = (n); i < (m); i++)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define tii tuple<int,int,int>
#define mt make_tuple
#define pb push_back
#define pq priority_queue
using namespace std;
typedef long long int ll;
typedef long double ld;
ld MAX(ld x, ld y)
{
if(x < y) return y;
return x;
}
ld MIN(ld x, ld y)
{
if(x < y) return x;
return y;
}
ll pmod(ll x, ll y)
{
return ((x*y)%mod + mod)%mod;
}
int main()
{
ll n,w; cin >> n >> w;
vector<ll>v(1000000,0);
ll end=0;
rep(i,0,n)
{
int s,t,p; cin >> s >> t >> p;
if(end < t) end = t;
v[s] += p; v[t] -= p;
}
rep(i,0,end)
{
v[i+1] += v[i];
}
rep(i,0,end+1)
{
if(v[i] > w)
{
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
return 0;
} | /*
* @Author: AsilenceBTF
* @LastEditTime: 2020-12-11 20:02:17
*/
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(), x.end()
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int N = 2e5 + 105;
ll pre[N] = {0};
int main(){
int n;
ll w;
cin >> n >> w;
for(int i = 1; i <= n; ++i){
int l, r, p;
cin >> l >> r >> p;
pre[r] += p;
if(l) pre[l] -= p;
}
for(int i = N - 2; i >= 0; --i) pre[i] += pre[i + 1];
for(int i = 0; i < N; ++i){
if(pre[i] > w) {
cout << "No" << endl;
return 0;
}
}cout << "Yes" << endl;
// system("pause");
} |
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+(ch^48);ch=getchar();}
return x*f;
}
int a,b,c;
int main()
{
a=read(),b=read(),c=read();
if(c%2==0)
a=abs(a),b=abs(b);
if(a>b)
puts(">"),exit(0);
if(a==b)
puts("="),exit(0);
if(a<b)
puts("<"),exit(0);
return 0;
} | #include<iostream>
#include <bits/stdc++.h>
#include<stdio.h>
#include <string.h>
using namespace std;
#define ll long long
#define INF 1000007
#define MAX 500007
#define EPS 1e-9
#define PI acos(-1.0)
#define nl "\n"
#define F first
#define S second
typedef vector<ll> vi;
typedef priority_queue<ll , vector<ll> , greater<ll> > pqmx;
typedef priority_queue<ll> pqmn;
typedef pair<ll , ll> pi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector< pair<int , int> > vpi;
#define fr(i,n) for(i=0;i<n;i++)
#define rep(i,a,n) for(i=a;i<n;i++)
#define yeS(GOOD) GOOD ? cout<<"YES\n" : cout<<"NO\n"
#define all(a) a.begin() , a.end()
#define pb push_back
#define ar array
ll mod = LLONG_MAX;
ll binpow(ll a, ll b){ll res=1;a%=mod;while(b>0){if(b&1)res=(res*a)%mod;a=(a*a)%mod;b>>=1;}return res;}
ll binmul(ll a, ll b){ll res=0;a%=mod;while(b>0){if(b&1)res=(res + a)%mod;a=(a + a)%mod;b>>=1;}return res;}
ll area(pi a, pi b,pi c){return abs(a.F * b.S + b.F * c.S + c.F*a.S - a.S * b.F - b.S * c.F - c.S * a.F);}
ll gcd (ll a,ll b){if(b==0)return a;else return gcd (b, a % b);}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}
ll min(ll a,ll b){if(a < b){return a;}return b;}
ll max(ll a,ll b){if(a > b){return a;}return b;}
double intlog(ll n ,ll base){return (double)log(n)/log(base);}
double DEG_to_RAD(double d) { return d * PI / 180.0; }
double RAD_to_DEG(double r) { return r * 180.0 / PI; }
ll n , t , m , temp , temp2, root , p ,q , k , i , j , r , u , v , w;
int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt" , "r" , stdin);
freopen("output.txt" , "w" , stdout);
#endif
int n;
cin>>n;
int i = 0;
while(n > 0){
n -= ++i;
}
cout<<i<<nl;
#ifndef ONLINE_JUDGE
cout << "Running Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s .\n";
#endif
} |
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define sz(v) (int)v.size()
#define nl "\n"
using namespace std;
//this fuction sorts vector pair according to first element in descending order.
bool sortinrev(const pair<int,int> &a,const pair<int,int> &b)
{
if(a.first==b.first){
return a.second<b.second;
}
return a.first<b.first;
}
int decimalToOctal(ll n) {
int remainder;
int octal = 0, i = 1;
while(n != 0) {
remainder = n%8;
if(remainder == 7) return false;
n = n/8;
octal = octal + (remainder*i);
i = i*10;
}
return true;
}
int digit(int n)
{
while(n != 0)
{
int re = n % 10;
if(re == 7) return false;
n/=10;
}
return true;
}
void solve()
{
int n, m;
cin>>n;
int ans = 0;
for(int i = 1; i<=n; i++)
{
if(decimalToOctal(i) && digit(i)) ans++;
}
cout<<ans<<nl;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(NULL);
// int t;
// cin>>t;
// while(t--)
solve();
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
int main(){
string s;
cin >> s;
if(s.length()==3 && s[0]==s[1] && s[1]==s[2]&& s[2]==s[0]){
cout << "Won" << endl;
}
else{
cout << "Lost" << endl;
}
return 0;
} |
#include<bits/stdc++.h>
#define x first
#define y second
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mem(x,val) memset(x,val,sizeof x)
#define pii pair<int,int>
#define pb emplace_back
#define ar array
#define int long long
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define M 1000000007
#define wopen(x) freopen((x),"w",stdout)
#define ropen(x) freopen((x),"r",stdin)
using namespace std;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
const int N = 2e5 + 5;
int n, m, top, chose, dp[(1<<18)], group[(1<<18)], st[20];
bitset<20> mat[20];
void init(){
for(int i = 0; i < (1<<n); i++){
top = 0;
for(int j = 0; j < n; j++)
if((i>>j)&1) st[top++] = j;
for(int j = 0; j < top; j++)
for(int k = 0; k < j; k++)
if(mat[st[j]][st[k]] == 0)
goto next;
group[i] = 1;
next:;
}
}
void dfs(int now, int bit){
if(group[bit] == 0 && bit) return;
if(now == top){
if(group[bit]) dp[chose|bit] = min(dp[chose|bit], dp[chose] + 1);
return;
}
dfs(now + 1, bit | (1<<st[now]));
dfs(now + 1, bit);
}
signed main(void){
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> m;
for(int i = 0; i < m; i++){
int a, b;
cin >> a >> b;
a--, b--;
mat[a][b] = mat[b][a] = 1;
}
init();
mem(dp, 0x3f);
dp[0] = 0;
for(int i = 0; i < (1<<n); i++){
top = 0;
if(group[i] && i) {
dp[i] = 1;
}
for(int j = 0; j < n; j++)
if(((i>>j)&1) == 0) st[top++] = j;
chose = i;
dfs(0, 0);
}
cout << dp[(1<<n)-1];
}
| #include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define drep(i,j,n) for(int i=0;i<(int)(n-1);i++)for(int j=i+1;j<(int)(n);j++)
#define trep(i,j,k,n) for(int i=0;i<(int)(n-2);i++)for(int j=i+1;j<(int)(n-1);j++)for(int k=j+1;k<(int)(n);k++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yes(ans) if(ans)printf("yes\n");else printf("no\n")
#define Yes(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YES(ans) if(ans)printf("YES\n");else printf("NO\n")
#define popcount(v) __builtin_popcount(v)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define vector3d(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
const int MOD2=998244353;
const int INF=1<<30;
const ll INF2=1LL<<60;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T,class L>void scan(pair<T, L>& p){scan(p.first);scan(p.second);}
template<class T,class U,class V>void scan(tuple<T,U,V>& p){scan(get<0>(p));scan(get<1>(p));scan(get<2>(p));}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T,class L>void print(const pair<T, L>& p){print(p.first);putchar(' ');print(p.second);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll modinv(ll a, ll m) {ll b = m, u = 1, v = 0;while (b) {ll t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}
ll updivide(ll a,ll b){if(a%b==0) return a/b;else return (a/b)+1;}
template<class T> void chmax(T &a,const T b){if(b>a)a=b;}
template<class T> void chmin(T &a,const T b){if(b<a)a=b;}
int main(){
INT(n,m);
vector2d(bool,A,n,n,false);
int u,v;
rep(i,m){
in(u,v);
A[--u][--v]=true;
A[v][u]=true;
}
vector<int> dp(1<<n,0);
bool h=false;
rep(S,1<<n){
dp[S]=popcount(S);
h=true;
for(int i=0;i<n;i++){
if(~S>>i&1)continue;
for(int j=i+1;j<n;j++){
if(~S>>j&1)continue;
if(!A[i][j]){
h=false;
break;
}
}
}
if(h){
dp[S]=1;
continue;
}
for(int T=(S-1)&S;T>0;T=(T-1)&S){
chmin(dp[S],dp[S^T]+dp[T]);
}
}
out(dp.back());
} |
#include <bits/stdc++.h>
#define ll long long int
#define db double
#define pb push_back
#define mpr make_pair
#define andl "\n"
#define f first
#define s second
#define mset(x,y) memset(x,y,sizeof(x))
#define fr(i,n) for(long long int i=0;i<n;i++)
#define trace(it,x) for(auto it = (x).begin(); it != (x).end(); it++)
#define mod 1000000007
#define fastio ios::sync_with_stdio (false); cin.tie (0); cout.tie (0);
#define runtime cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n" ;
using namespace std;
// convert number to string to_string(x);
// convert string to number stoi();
// ll mulmod(ll x,ll y)
// {
// return ((x%mod)*(y%mod))%mod;
// }
// ll binpow(ll x, ll y)
// {
// ll z = 1;
// while(y > 0)
// {
// if(y % 2 == 1)
// z = mulmod(z, x);
// x = mulmod(x, x);
// y /= 2;
// }
// return z;
// }
// ll ncr(ll n,ll r)
// {
// return mulmod(fact[n],binpow(mulmod(fact[n-r],fact[r]),mod-2));
// }
// ll pwr(ll n,ll m)
// {
// if(n==1 || m==0)
// return 1;
// ll x=pwr(n,m/2);
// if(m%2==0)
// return x*x;
// else
// return n*x*x;
// }
// ll pwr(ll n,ll m,ll b)
// {
// if(n==1 || m==0)
// return 1;
// ll x=pwr(n,m/2,b);
// if(m%2==0)
// return ((x%b)*(x%b))%b;
// else
// return ((n%b)*(((x%b)*(x%b))%b))%b;
// }
void solve()
{
ll n,c,ans=0,a,b,ci;
cin >> n >> c;
map<ll,ll>m;
fr(i,n)
{
cin >> a >> b >> ci;
m[a]+=ci;
m[b+1]-=ci;
}
ll d=1,t=0;
for(auto it=m.begin();it!=m.end();it++)
{
ans+=(min(t,c)*(it->first-d));
t+=it->second;
d=it->first;
}
cout << ans;
return ;
}
int main()
{
fastio
ll t=1;
// cin >> t;
while(t--)
solve();
runtime
} | #include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pi 3.141592653589793238
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define zip(i,a,b) for(int i=a;i<b;i++)
#define rzip(i,a,b) for(int i=a;i>=b;i--)
#define ll unsigned int
#define test int t;cin>>t; while(t--)
#define en '\n'
typedef pair<int, int> pii;
typedef pair<char, int> pci;
typedef pair<char, char> pcc;
typedef vector<pii> vii;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend()
#define sz(x) (int)x.size()
#define INF (1e18+5)
#define inf (1e9+5)
#define mod 1000000007
void __print(int x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
// You should only debug a pair of simple data types. For example,
// the debug won't work if one of pair's elements is collection type
// (std::vector, std::map, std::set...).
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
// bool check_prime(int n) return whether a number is prime or not O(sqrt(N));
// int BE(int x,int n,int m) return x^n%m; O(logN);
// void sieve() from number 1-1000001 saare prime store kar lega in bool is_prime[1000001] array
// vector<int> z_array(string s) return vector which is Z-array of string s;
// vector<int> lps(string s) return vector which is lps array of string s;
// int power(int x,int n) return x^n; O(logN);
// using_ordered_set (template for using ordered set , replace first 2 lines of this page with this code..);
const int gf = 1e6 + 9;
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(0);
#ifndef ONLINE_JUDGE
if (fopen("input.txt", "r"))
{
freopen ("input.txt" , "r" , stdin);
freopen ("output.txt" , "w" , stdout);
}
#endif
//_______________________________-code starts-_______________________________________________
int a, b;
cin >> a >> b;
cout << (a + b) / 2 << " " << (a - b) / 2 << en;
return 0;
}
|
#include <bits/stdc++.h>
#define LL long long
#define ULL unsigned long long
#define pb push_back
#define st first
#define nd second
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
template <class T> T read(T &a) {
a=0;char x=getchar();bool f=0;
for(;x<'0'||x>'9';x=getchar())f|=x=='-';
for(;x>='0'&&x<='9';x=getchar())a=(a<<3)+(a<<1)+x-'0';
if(f)a=-a;
return a;
}
using namespace std;
const int N = 1e6 + 5;
int id[1005][1005];
typedef pair<int, int> tp;
vector<int> mp[1005][30];
int dis[N];
bool vis[N];
queue<int> q;
int f[N], nnext[N << 3], v[N << 3], cnt, cnt1;
int n, m;
void add(int a, int b) {
nnext[++cnt] = f[a];
f[a] = cnt;
v[cnt] = b;
}
int main() {
read(n), read(m);
for (int i = 1; i <= m; ++i) {
int a, b;
char s[3];
read(a), read(b);
scanf("%s", s);
mp[a][s[0] - 'a'].pb(b);
mp[b][s[0] - 'a'].pb(a);
}
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
id[i][j] = ++cnt1;
}
}
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
for (int k = 0; k < 26; ++k) {
for (int I = 0; I < mp[i][k].size(); ++I) {
for (int J = 0; J < mp[j][k].size(); ++J) {
int x = mp[i][k][I], y = mp[j][k][J];
add(id[i][j], id[x][y]);
}
}
}
}
}
int ans = INF;
memset(dis, INF, sizeof dis);
q.push(id[1][n]);
dis[id[1][n]] = 0;
vis[id[1][n]] = 1;
while (!q.empty()) {
int k = q.front();
q.pop();
vis[k] = 0;
for (int i = f[k]; i; i = nnext[i]) {
int to = v[i];
if (dis[to] > dis[k] + 1) {
dis[to] = dis[k] + 1;
if (vis[to] == 0) {
vis[to] = 1;
q.push(to);
}
}
}
}
for (int i = 1; i <= n; ++i) {
if (dis[id[i][i]] != INF) ans = min(dis[id[i][i]] * 2, ans);
}
for (int i = 1; i <= n; ++i) {
for (int j = 0; j < 26; ++j) {
for (int k = 0; k < mp[i][j].size(); ++k) {
int to = mp[i][j][k];
if (dis[id[i][to]] != INF) {
ans = min(dis[id[i][to]] * 2 + 1, ans);
}
}
}
}
if (ans == INF) puts("-1"); else cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
int main() {
int N, M;
cin >> N >> M;
vector<int> A(M), B(M);
vector<char> C(M);
for (int i = 0; i < M; i++) {
cin >> A[i] >> B[i] >> C[i];
A[i]--;
B[i]--;
}
vector<int> dist(N*N, 1e9);
vector<int> visited(N*N, false);
queue<int> q;
for (int i = 0; i < N; i++) {
dist[i*N+i] = 0;
q.push(i*N+i);
visited[i*N+i] = true;
}
vector<vector<int>> edge(N*N);
for (int i = 0; i < M; i++) {
if (dist[A[i]*N+B[i]] > 1) {
dist[A[i]*N+B[i]] = 1;
q.push(A[i]*N+B[i]);
}
if (dist[B[i]*N+A[i]] > 1) {
dist[B[i]*N+A[i]] = 1;
q.push(B[i]*N+A[i]);
}
visited[A[i]*N+B[i]] = true;
visited[B[i]*N+A[i]] = true;
for (int j = i+1; j < M; j++) {
if (C[i] != C[j]) continue;
edge[A[i]*N+A[j]].push_back(B[i]*N+B[j]);
edge[A[j]*N+A[i]].push_back(B[j]*N+B[i]);
edge[B[i]*N+B[j]].push_back(A[i]*N+A[j]);
edge[B[j]*N+B[i]].push_back(A[j]*N+A[i]);
edge[A[i]*N+B[j]].push_back(B[i]*N+A[j]);
edge[A[j]*N+B[i]].push_back(B[j]*N+A[i]);
edge[B[i]*N+A[j]].push_back(A[i]*N+B[j]);
edge[B[j]*N+A[i]].push_back(A[j]*N+B[i]);
}
}
while (!q.empty()) {
int now = q.front();
q.pop();
for (int nxt : edge[now]) {
if (dist[nxt] <= dist[now]+2) continue;
dist[nxt] = dist[now]+2;
visited[nxt] = true;
q.push(nxt);
}
}
if (dist[N-1] >= 1e8) cout << -1 << endl;
else cout << dist[N-1] << endl;
return 0;
} |
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
char s[3];
char a;
int j=0;
for(int i=0;i<3;i++)
{
cin>>s[i];
}
char x=s[0];
int flag=1;
for(int i=1; i<3;i++)
{
if(x!=s[i])
{
flag=0;
cout<<"Lost";
break;
}
}
if(flag==1)
{
cout<<"Won";
}
return 0;
}
| #include<iostream>
using namespace std;
int main()
{
int n,a,b;
cin>>n>>a>>b;
cout<<n-a+b;
return 0;
} |
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>
using namespace std;
int main(int argc, char** argv) {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(12);
int n, m, K;
cin >> n >> m >> K;
vector<bool> bad(n + 1, false);
vector<int> A(K);
for (int i = 0; i < K; ++i) {
cin >> A[i];
bad[A[i]] = true;
A[i] -= i;
}
for (int i = 0; i < K; ++i) {
int len = 1;
while (i + 1 < K && A[i] == A[i + 1]) {
++i;
++len;
}
if (len >= m) {
cout << -1 << '\n';
return 0;
}
}
vector<long double> dp(n + 1, 0);
auto calc = [&](long double x) {
fill(dp.begin(), dp.end(), 0);
long double sum = 0;
for (int i = n - 1; i >= 0; --i) {
if (bad[i]) {
dp[i] = x;
} else {
dp[i] = sum / m + 1.0;
}
sum += dp[i];
if (i + m <= n) {
sum -= dp[i + m];
}
}
return dp[0];
};
long double lo = 0, hi = 1e20;
int rnd = 128;
while (rnd-- > 0) {
long double mi = (lo + hi) / 2;
auto ans = calc(mi);
if (ans < mi) {
hi = mi;
} else {
lo = mi;
}
}
cout << lo << '\n';
return 0;
} | // abc189_f
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<long double, long double> P;
#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()
#define INF (ll)(1e9)
#define MOD (1000000007)
#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int idx=0;idx<(n-1);idx++) cout << (vec)[idx] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << "\n";}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;
int main() {
#ifdef LOCAL
ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif
int N, M, K;
cin >> N >> M >> K;
vector<bool> A(N);
REP(i, K) {
int a; cin >> a; a;
A[a] = true;
}
vector<P> V(N+M);
P cumsum = {0, 0};
REP_REV(i, N){
if (A[i]){
V[i] = {1, 0};
} else {
V[i] = {cumsum.first / M, cumsum.second / M + 1};
}
cumsum.first = {cumsum.first - V[i+M].first + V[i].first};
cumsum.second = {cumsum.second - V[i+M].second + V[i].second};
// print(i, cumsum);
}
// REP(i, N+M) print(V[i]);
if (abs(V[0].first - 1) < 1e-6){
print(-1);
} else {
long double ans = V[0].second / (1 - V[0].first);
print(ans);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define M1 1000000007
#define M2 998244353
#define INF 1e18
#define ll long long
#define pll pair<ll,ll>
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define REPR(i,a,b) for(ll i=b-1;i>=a;i--)
#define forr(i,n) for(ll i=0;i<n;i++)
#define F first
#define S second
#define pb push_back
#define DB pop_back
#define mp make_pair
#define MT make_tuple
#define V(a) vector<a>
#define vi vector<int>
#define vlli vector <long long>
#define endl '\n'
#define ce(ele) cout<<ele<<' '
#define cs(ele) cout<<ele<<'\n'
#define CASE(t) ll t; cin>>t; while(t--)
/********************************************************************/
const double pi = 3.1415926535;
/********************************************************************/
//FAST IO//
void FAST() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
/********************************************************************/
int main()
{
FAST();
int a,b,c,d; cin>>a>>b>>c>>d;
cout<<b-c<<endl;
} | #include <bits/stdc++.h>
#include<sstream>
#include<string>
#include<vector>
#include <set>
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define mp make_pair
#define ll long long
#define ff first
#define ss second
long long M=1000000007;
using namespace std;
ll fact[10000];
ll power(ll x, unsigned ll y, unsigned ll m)
{
if (y == 0)
return 1;
ll p = power(x, y / 2, m) % m;
p = (p * p) % m;
return (y % 2 == 0) ? p : (x * p) % m;
}
unsigned long long modInverse(unsigned long long n,
int p)
{
return power(n, p - 2, p);
}
unsigned long long nCrModPFermat(unsigned long long n,
int r, int p)
{
// If n<r, then nCr should return 0
if (n < r)
return 0;
// Base case
if (r == 0)
return 1;
return (fact[n] * modInverse(fact[r], p) % p
* modInverse(fact[n - r], p) % p)
% p;
}
int32_t main()
{
IOS
ll a,b,c,d;
cin>>a>>b>>c>>d;
cout<<(b-(c))<<endl;
return 0;
}
|
#include <iostream>
#include <vector>
#include <queue>
#include <tuple>
#define MAX (int)(1e8)
using namespace std;
int main() {
int R, C;
cin >> R >> C;
vector<vector<int>> A(R, vector<int>(C - 1)), B(R - 1, vector<int>(C));
vector<vector<vector<int>>> costs(2, vector<vector<int>>(R, vector<int>(C, 0)));
vector<vector<vector<bool>>> visited(2, vector<vector<bool>>(R, vector<bool>(C, false)));
for (int i = 0; i < R; i++) for (int j = 0; j < C - 1; j++)
cin >> A[i][j];
for (int i = 0; i < R - 1; i++) for (int j = 0; j < C; j++)
cin >> B[i][j];
//優先順位付きキューを使ってダイクストラ法を行う
priority_queue<tuple<int, int, int, int>, vector<tuple<int, int, int, int>>, greater<tuple<int, int, int, int>>> que;
//始点を追加
que.push(make_tuple(0, 0, 0, 0));
while (!que.empty()) {
auto pos = que.top();
int cost = get<0>(pos), f = get<1>(pos), r = get<2>(pos), c = get<3>(pos);
que.pop();
if (visited[f][r][c]) continue; //確定なら終了
//コストを確定
costs[f][r][c] = cost;
visited[f][r][c] = true;
//自分が下っている最中かどうかで分岐
if (f == 0) {//下っていない
//上下左右に移動を考える
if (r + 1 < R) //上
que.push(make_tuple(cost + B[r][c], f, r + 1, c));
if (c - 1 >= 0) //左
que.push(make_tuple(cost + A[r][c - 1], f, r, c - 1));
if (c + 1 < C) //右
que.push(make_tuple(cost + A[r][c], f, r, c + 1));
if (r - 1 >= 0) //下
que.push(make_tuple(cost + 1, 1, r, c));
}
else { //下っている
//一つ下に移動するver or 下るのをやめる
if (r - 1 >= 0)//下る
que.push(make_tuple(cost + 1, f, r - 1, c));
que.push(make_tuple(cost, 0, r, c)); //戻る
}
}
cout << costs[0][R - 1][C - 1] << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define per(i, a, b) for(int i = (b)-1; i >= (a); --i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd 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; }
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pii> vii;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
map<int, int> rev;
const int N = 102;
const int M = 102102;
vi vis(N), ans(M), ok(M);
vii ed(M);
void dfs(vector<vii> &gr, int u, int p) {
vis[u] = 1;
for (auto [v, e]: gr[u]) if (p != v) {
if (vis[v]) {
ok[rev[e]] = 1;
ans[rev[e]] = ed[rev[e]].fst == v;
}
else {
ans[rev[e]] = ed[rev[e]].snd == v;
ok[rev[e]] = 1;
dfs(gr, v, u);
}
}
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
int n, m;
cin >> n >> m;
vi c(n+1), done(m), vis(n+1);
vector<vii> g(n+1);
rep(i,0,m) {
cin >> ed[i].first >> ed[i].second;
g[ed[i].fst].eb(ed[i].snd, i);
g[ed[i].snd].eb(ed[i].fst, i);
}
rep(i,1,n+1) cin >> c[i];
rep(i,1,n+1) {
if (vis[i]) continue;
queue<int> q;
q.push(i);
vis[i] = 1;
vi comp;
while (!q.empty()) {
int u = q.front(); q.pop();
comp.pb(u);
for (auto [v, j]: g[u]) if (!vis[v] && c[v] == c[u]) {
vis[v] = 1;
q.push(v);
}
}
vector<vii> gr(n+1);
int nedges = 0;
for (auto u: comp) {
for (auto [v, j]: g[u]) {
if (c[u] == c[v] && !done[j]) {
rev[nedges] = j;
gr[u].eb(v, nedges);
gr[v].eb(u, nedges);
++nedges;
done[j] = 1;
}
}
}
dfs(gr, i, i);
}
rep(i,0,m) {
if (!ok[i]) {
assert(c[ed[i].fst] != c[ed[i].snd]);
ans[i] = c[ed[i].fst] > c[ed[i].snd];
}
if (ans[i]) cout << "->";
else cout << "<-";
cout << '\n';
}
} |
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
ll N;
int main() {
cin >> N;
N *= 2;
vector<ll> yakusu;
for (ll i = 1; i * i <= N; i++) {
if (N % i == 0) {
yakusu.push_back(i);
yakusu.push_back(N / i);
}
}
sort(yakusu.begin(), yakusu.end());
//初項x, 項数bの等差数列の和はxb + b * (b - 1) / 2 == N
int ans = 0;
for (int i = 0; i < yakusu.size(); i++) {
ll b = yakusu[i];
ll x2 = (N / b + 1 - b);
if (x2 % 2 == 0)ans++;
}
cout << ans << endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <chrono>
// using namespace std::chrono;
// using namespace __gnu_pbds;
#define ff first
#define ss second
#define int long long
#define double long double
#define pb push_back
#define mp make_pair
#define pi pair<int,int>
#define vtiii vector<tuple<int,int,int>>
#define vi vector<int>
#define vpii vector<pair<int,int>
#define mii map<int,int>
#define pqb priority_queue<int>
#define pqs priority_queue<int,vi,greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define inf 1e18
// #define ps(x,y) fixed<<setprecision(y)<<x
#define mk(arr,n,type) type *arr=new type[n];
#define all(x) (x).begin(), (x).end()
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x <<" "; _print(x); cerr << endl;
#else
#define debug(x)
#endif
void _print(int t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(double t) {cerr << t;}
template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}
const int mxN = 1e7;
const int mod = 1e9 + 7;
void solve(){
int n;cin>>n;
int x = 0;
cout<<n-1<<endl;
}
int32_t main(){
// auto start = high_resolution_clock::now()
FIO;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
freopen("Error.txt", "w", stderr);
#endif
// precalc();
//int x; cin>>x; while(x--)
solve();
// auto stop = high_resolution_clock::now();
// auto duration = duration_cast<microseconds>(stop - start);
// cout << duration.count() << endl;
} |
// abc199_d
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../../debug_util/cxx-prettyprint/prettyprint.hpp"
#include "../../debug_util/rng.hpp"
#include "../../debug_util/timer.hpp"
#endif
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
#define REP(i, n) for (int i = 0 ; i < (int)(n) ; ++i)
#define REPN(i, m, n) for (int i = m ; i < (int)(n) ; ++i)
#define REP_REV(i, n) for (int i = (int)(n) - 1 ; i >= 0 ; --i)
#define REPN_REV(i, m, n) for (int i = (int)(n) - 1 ; i >= m ; --i)
#define ALL(x) x.begin(), x.end()
#define INF (ll)(1e15)
#define MOD (1000000007)
#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int idx=0;idx<(n-1);idx++) cout << (vec)[idx] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << "\n";}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
//struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;
struct Graph {
int n;
vector<vector<int>> edges;
vector<int> con_graph;
vector<int> vals;
vector<vector<int>> con_graph_list;
ll tmp_ans = 0;
Graph(int n_) : n(n_), edges(n_), con_graph(n_, -1), vals(n_, -1) {}
void add_edge(int u, int v) {
edges[u].emplace_back(v);
edges[v].emplace_back(u);
}
void dfs0(int u, int p, int k){
con_graph[u] = k;
for (auto v: edges[u]){
if (v == p) continue;
if (con_graph[v] != -1) continue;
dfs0(v, u, k);
}
}
void dfs(int idx, int k){
if (idx == con_graph_list[k].size()){
tmp_ans++;
} else {
int u = con_graph_list[k][idx];
vector<bool> tmp(3);
for (auto v: edges[u]){
if (vals[v] == -1) continue;
tmp[vals[v]] = true;
}
REP(i, 3){
if (tmp[i]) continue;
vals[u] = i;
dfs(idx+1, k);
vals[u] = -1;
}
}
}
void func(){
int k = 0;
REP(i, n){
if (con_graph[i] != -1) continue;
dfs0(i, -1, k++);
}
// print(k);
con_graph_list.resize(k);
REP(u, n){
con_graph_list[con_graph[u]].emplace_back(u);
}
// print(con_graph_list);
ll ans = 1;
REP(i, k){
tmp_ans = 0;
if (con_graph_list[i].size() == 1){
ans *= 3;
} else {
vals[con_graph_list[i][0]] = 0;
dfs(1, i);
ans *= 3 * tmp_ans;
}
}
print(ans);
}
};
int main() {
#ifdef LOCAL
ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif
int N, M;
cin >> N >> M;
Graph g(N);
REP(i, M){
int a,b;
cin >> a >> b;
a--; b--;
g.add_edge(a, b);
}
g.func();
return 0;
}
| #include<bits/stdc++.h>
#define N 25
using namespace std;
int n,m,no[N][3],id[N],p[N];
long long ans=1,cnt;
bitset<N> f[N];
inline int find(register int x){return x==id[x]?x:id[x]=find(id[x]);}
inline void dfs(register int x,register int y){
register bool flag=0;
for(register int i=x+1;i<=n;++i)if(find(i)==y){
flag=1;
for(register int j=0;j<3;++j)
if(!no[i][j]){
for(register int k=1;k<=n;++k)if(f[i][k])++no[k][j];
dfs(i,y);
for(register int k=1;k<=n;++k)if(f[i][k])--no[k][j];
}
return;
}
cnt++;
}
int main(){
cin>>n>>m;
srand(114514);
for(register int i=1;i<=n;++i)p[i]=i;
random_shuffle(p+1,p+1+n);
for(register int i=1;i<=n;++i)id[i]=i;
for(register int i=1,a,b;i<=m;++i)scanf("%d %d",&a,&b),a=p[a],b=p[b],id[find(a)]=find(b),f[a][b]=f[b][a]=1;
for(register int i=1;i<=n;++i)if(id[i]==i)cnt=0,dfs(0,id[i]),ans*=cnt;
cout<<ans<<endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false), cin.tie(nullptr);
set<char> s;
for(int i =0; i < 3; ++i){
char c;cin >>c;
s.insert(c);
}
cout <<(s.size() == 1 ? "Won" : "Lost");
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, X;
cin >> N >> X;
vector<int> A(N);
for (int i = 0; i < N; i++) {
cin >> A.at(i);
}
for (int i = 0; i < N; i++) {
if (A.at(i)!=X) cout << A.at(i) << ' ';
}
cout << endl;
} |
#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
#define f(i,a,b) for( int i=a;i<=b;++i)
#define ff(i,a,b) for( int i=a;i>=b;--i)
#define debug(x) cerr << #x << " : " << x << " " << endl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<int, int> pll;
typedef pair<string, string> pss;
const ll mod = 1e9 + 7;
const ll mod2 = 998244353;
const ll inf = 2e18;
const double tiaohe = 0.57721566490153286060651209;
ll oula(ll x) { ll res = x;f(i, 2, x / i) { if (x % i == 0) { res = res / i * (i - 1);while (x % i == 0) x /= i; } }if (x > 1) res = res / x * (x - 1);return res; }
ll quickmod(ll a, ll n, ll m) { ll s = 1;while (n) { if (n & 1) { s = s * a % m; }a = (a*a) % m;n = n / 2; }return s; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
void ex_gcd(ll a, ll b, ll &x, ll &y, ll &d) { if (!b) { d = a, x = 1, y = 0; } else { ex_gcd(b, a % b, y, x, d);y -= x * (a / b); } }
ll inv(ll t, ll p) { ll d, x, y;ex_gcd(t, p, x, y, d);return d == 1 ? (x % p + p) % p : -1; }
bool isPrime(ll x) { if (x == 2)return true;if (x % 2 == 0)return false;for (ll i = 2;i*i <= x;i++) if (x % i == 0)return false; return true; }
inline int in() { char ch = getchar();int x = 0, f = 1;while (ch<'0' || ch>'9') { if (ch == '-')f = -1;ch = getchar(); }while (ch >= '0'&&ch <= '9') { x = x * 10 + ch - '0';ch = getchar(); }return x * f; }
//double a = log(n) +tiaohe + 1.0 / (2 * n);
double eqa = (1 + sqrt(5.0)) / 2.0;
const double eps = 1e-6;
const int N = 6e5 + 5;
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif
int n;cin >> n;
map<string, int> mp;
while (n--)
{
string s;cin >> s;
mp[s]++;
}
int good = 0;
string ans = "sdsa";
for (auto i : mp)
{
string nx = '!' + i.first;
if (mp.count(nx)) {
ans = i.first;
good++;
break;
}
}
if (good)cout << ans << endl;
else puts("satisfiable");
return 0;
} | #include<bits/stdc++.h>
#define ll long long
using namespace std;
#define gc getchar
inline ll read(){
register ll x=0,f=1;char ch=gc();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=gc();}
while (isdigit(ch)){x=(x<<3)+(x<<1)+ch-'0';ch=gc();}
return (f==1)?x:-x;
}
int n;
ll A[1010101],B[1010101],sumB[1010101];
ll f[1010101][2],g[2][2];
priority_queue<ll> q[2];
signed main(){
n=read();
for (int i=1;i<=n;i++){
A[i]=read();
}
ll _=0,ans=0;
for (int i=1;i<=n;i++){
B[i]=read();
q[i%2].push(B[i]-A[i]);
_+=A[i];
}
ans=_;
for (int i=1;i<=n/2;i++){
_+=q[0].top(),_+=q[1].top();
ans=max(ans,_);
q[0].pop(),q[1].pop();
}
cout<<ans;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define testcase \
ll tc, t = 1; \
cin >> tc;
#define iloop(i, n) for (i = 0; i < n; i++)
#define dloop(i, n) for (i = n; i >= 0; i--)
#define fast \
ios_base::sync_with_stdio(0); \
cin.tie(0);
#define vll vector<ll>
#define ipop \
freopen("input.txt", "r", stdin); \
freopen("output.txt", "w", stdout);
//#define MAX 1000000
vector<ll> Seiveprime(ll n)
{
vector<bool> isPrime(n, true);
for (int i = 2; i * i < n; i++)
{
if (isPrime[i])
{
for (int j = i * i; j < n; j += i)
isPrime[j] = false;
}
}
vector<ll> prime;
prime.push_back(2);
for (int i = 3; i < n; i += 2)
if (isPrime[i])
prime.push_back(i);
return prime;
}
ll binpow(ll a, ll b)
{
ll res = 1;
while (b > 0)
{
if (b & 1)
res = res * a;
a = a * a;
b >>= 1;
}
return res;
}
bool isPrime(int n)
{
if (n <= 1)
return false;
if (n <= 3)
return true;
if (n % 2 == 0 || n % 3 == 0)
return false;
for (int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
ll lcm(ll a, ll b)
{
ll x = __gcd(a, b);
return (a * b) / x;
}
int binarySearch(int 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;
}
long long ncr(long long n, long long r)
{
if (n < r)
{
return 0;
}
if (n == r || r == 0)
{
return 1;
}
ll ans = 1;
for (ll i = n; i > n - r; i--)
ans *= i;
for (ll i = 1; i <= r; i++)
ans /= i;
return ans;
}
int main()
{
fast;
ll n = 0,s,d, m = 0, i = 0, j = 0, k = 0, l = 0;
cin >> n>>s>>d;
ll x[n],y[n];
bool f=0;
for(i=0;i<n;i++)
{
cin>>x[i]>>y[i];
if(s>x[i]&&y[i]>d)
f=1;
}
if(f)
cout<<"Yes";
else
{
cout<<"No";
}
return 0;
}
| #include <cstdio>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <cstring>
#include <queue>
#include <map>
#define LL long long
#define LD long double
#define MAXN 100005
#define MAXM
#define P
#define INF 0x3f3f3f3f
using namespace std;
int t, n, a[MAXN];
int main()
{
scanf("%d", &t);
while(t--)
{
scanf("%d", &n);
for(int i=1; i<=n; ++i) scanf("%d", &a[i]);
if(n%2) printf("Second\n");
else
{
int tag=0;
sort(a+1, a+n+1);
for(int i=1, cnt=0; i<=n; ++i)
{
if(a[i]!=a[i-1] && cnt%2) tag=1;
cnt++;
}
if(tag) printf("First\n");
else printf("Second\n");
}
}
return 0;
} |
/*The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.*/
//PRABHJOT SINGH A.K.A. PRABHI
//~~~~~conquizztador~~~~~
#include<bits/stdc++.h>
using namespace std;
using lli = long long int;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
const int MOD = 1000000007;
const int MOD1 = 998244353;
const int maxn = 100010;
const int lim = (int)1e9;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n = 0; cin >> n; cout << ((n & 1) ? "Black" : "White") << endl;
} | #include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#define __AceOfSpades__ ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define rep (i, n) for(int i=0; i<(n); i++)
typedef long long ll;
using namespace std;
int findSumOfDigits(int n){
int digit = 0;
while(n > 0){
digit += n % 10;
n /= 10;
}
return digit;
}
int main() {
__AceOfSpades__
int a;
cin >> a;
string ans;
if (a%2==0) ans = "White";
else ans = "Black";
cout << ans << 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);
ll calc_end_t(ll start,ll c,ll d){
ll tmin=(ll)sqrt(d)-1;
if(tmin<start) tmin=start;
ll end=LLONG_MAX;
for(ll i=tmin-2;i<tmin+3;i++){
if(i==-1 || i<start) continue;
end=min(end,i+c+d/(i+1));
}
return end;
}
void solve(){
/* code */
int n,m; cin>>n>>m;
vector<vii> graph(n); vll edge(m);
fori(i,0,m){
int a,b,c,d; cin>>a>>b>>c>>d; a--;b--;
graph[a].push_back({b,i});
graph[b].push_back({a,i});
edge[i]={c,d};
}
vl res(n,LLONG_MAX); res[0]=0;
// priority_queue<pll,vector<pll>,greater<pll>> pq; pq.push({0,0});
set<pll> pq; pq.insert({0,0});
while(pq.size()){
// auto [start_t,u]=pq.top(); pq.pop();
auto [start_t,u]=*pq.begin(); pq.erase(pq.begin());
if(start_t>res[u]) continue;
for(auto [v,e]:graph[u]){
ll end_t=calc_end_t(start_t,edge[e].fi,edge[e].se);
if(end_t<res[v]){
res[v]=end_t;
// pq.push({end_t,v});
pq.insert({end_t,v});
}
}
}
if(res[n-1]==LLONG_MAX) cout<<-1<<endl;
else cout<<res[n-1]<<endl;
}
int main()
{
DONTSYNC;
// TEST
solve();
return 0;
}
| /*
Author : MatsuTaku
Date : 01/09/21
*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (size_t i = 0, i##_len = (n); i < i##_len; i++)
using lint = long long int;
template<typename T>
using vvec = vector<vector<T>>;
template<typename T>
vvec<T> make_vvec(int n, int m, T v) { return vvec<T>(n, vector<T>(m, v)); }
template<typename T>
void chmax(T& dst, T x) { dst = max(dst, x); }
template<typename T>
void chmin(T& dst, T x) { dst = min(dst, x); }
class Solver {
public:
void solve();
};
constexpr int INF = 1e9;
void Solver::solve() {
int n,m; cin>>n>>m;
vector<tuple<int, int, int>> E(m);
rep(i, m) {
int a,b; cin>>a>>b; a--; b--;
E[i] = {a, b, 0};
}
vector<int> C(n); for (auto& c:C) cin>>c;
vector<int> Ci(n);
iota(Ci.begin(), Ci.end(), 0);
sort(Ci.begin(), Ci.end(), [&](auto l, auto r) {
return C[l] > C[r];
});
vector<tuple<int, int, int>> H[n];
rep(i, m) {
auto& [a, b, id] = E[i];
if (C[a] == C[b]) {
H[a].emplace_back(b, i, H[b].size());
H[b].emplace_back(a, i, H[a].size()-1);
} else {
id = C[a] > C[b] ? 1 : -1;
}
}
vector<int> v(n);
auto make_cycle = [&H, &E, &v](auto f, int s) -> void {
if (v[s]) {
return;
}
v[s] = true;
for (auto& [t, ei, it] : H[s]) {
auto& [es, et, eid] = E[ei];
if (eid != 0) {
continue;
}
eid = es == s ? 1 : -1;
f(f, t);
}
};
rep(i, n) {
make_cycle(make_cycle, i);
}
for (auto [s, t, id] : E) {
cout << (id == 1 ? "->" : "<-") << endl;
}
}
int main() {
cin.tie(nullptr); ios::sync_with_stdio(false);
cout<<fixed<<setprecision(10);
Solver().solve();
return 0;
}
|
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <limits>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
template<class T> inline int sz(T &a) { return a.size(); }
using ll = long long; using ld = long double;
using pi = pair<int,int>; using pl = pair<ll,ll>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
const int inf = numeric_limits<int>::max();
const ll infll = numeric_limits<ll>::max();
// ユークリッドの互除法で最大公約数を求める
int gcd(int a,int b){
if(b==0) return a;
return gcd(b,a%b);
}
// 最小公倍数
int lcm(int a,int b){
return a/gcd(a,b)*b;
}
int main()
{
int n; cin >> n;
vi a(n);
rep(i,n) cin >> a[i];
int mn = inf;
rep(i,n) {
chmin(mn, a[i]);
}
map<int,int> mp;
rep(tmp,n) {
for(int i = 1; i*i <= a[tmp]; ++i) {
if(a[tmp] % i == 0) {
if(mp[i] == 0) mp[i] = a[tmp];
else mp[i] = gcd(mp[i], a[tmp]);
if(a[tmp]/i!=i) {
int j = a[tmp]/i;
if(mp[j] == 0) mp[j] = a[tmp];
else mp[j] = gcd(mp[j], a[tmp]);
}
}
}
}
int res = 0;
for(auto tmp: mp) {
auto [key, val] = tmp;
if(mn >= key && key == val) res++;
}
cout << res << "\n";
return 0;
}
| /*
JAI JAGANNATH!
*/
//@Author : zanj0
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define ff first
#define ss second
#define pb push_back
#define MOD 1000000007
#define inf 1e18
#define ps(x,y) fixed<<setprecision(y)<<x
#define w(x) int x; cin>>x; while(x--)
#define endl "\n"
void zanj0()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
const int N = 1e3 + 5;
int a[N], b[N];
int n, m;
int dp[N][N];
int dfs(int i, int j) {
if (i > n) {
return m - j + 1;
} else if (j > m) {
return n - i + 1;
}
if (dp[i][j] != -1) return dp[i][j];
int ret = inf;
if (a[i] == b[j]) {
ret = min(ret, dfs(i + 1, j + 1));
}
int op = 1 + min({dfs(i + 1, j), dfs(i, j + 1), dfs(i + 1, j + 1)});
ret = min(ret, op);
return dp[i][j] = ret;
}
void solve() {
memset(dp, -1, sizeof dp);
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int j = 1; j <= m; j++) cin >> b[j];
cout << dfs(0, 0) << endl;
}
int32_t main()
{
zanj0();
solve();
return 0;
} |
#include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
int main()
{
ios_base::sync_with_stdio(false); cin.tie(NULL);
int a[3];
for (int i = 0; i < 3; i++)
{
cin>>a[i];
}
sort(a,a+3);
cout<<a[2]+a[1];
return 0;
} | #include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,f,n) for(ll i=(f); (i) < (n); i++)
#define repe(i,f,n) for(ll i=(f); (i) <= (n); i++)
#define repc(i,f,n) for(char i=(f); (i) <= (n); i++)
//#define PI 3.14159265358979323846264338327950L
#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
#define Pl pair<ll, ll>
#define OUT(x) cout << x << endl; return 0;
#define ALL(x) (x).begin(),(x).end()
#define UNIQUE(x) (x).erase(unique(ALL(x)),(x).end()) //x must be sorted
//printf("%.10f\n")
//cout << fixed << setprecision(10);
template<class T> inline bool chmax(T& a, T b){if (a < b) { a = b; return true; } return false;}
template<class T> inline bool chmaxe(T& a, T b){if (a <= b) { a = b; return true; } return false;}
template<class T> inline bool chmin(T& a, T b){if (a > b) { a = b; return true; } return false;}
const ll MOD = 1000000007ll;
const ll INF = 1e+18;
const int iINF = 1e9;
const double EPS = 1e-8;
//const double PI = acos(-1.0);
int
main()
{
vector<ll> arr(3);
rep(i, 0, 3) cin >> arr[i];
ll sum =0 ;
sort(ALL(arr));
rep(i, 1, 3) sum += arr[i];
cout << sum << endl;
} |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
vector<int> a(n);
for (int& it : a) cin >> it;
if (n & 1) {
cout << "Second\n";
} else {
sort(a.begin(), a.end());
bool win = false;
for (int i = 0; i < n; i += 2) {
win |= a[i] != a[i + 1];
}
cout << (win ? "First\n" : "Second\n");
}
}
int main() {
ios::sync_with_stdio(false), cin.tie(nullptr);
int tt = 1;
cin >> tt;
while (tt--)
solve();
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x) << '\n'
typedef long long ll;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
template <typename T> inline bool chmax(T &a, T b) {return a < b ? a = b, true : false;}
template <typename T> inline bool chmin(T &a, T b) {return a > b ? a = b, true : false;}
void solve() {
ll n; cin >> n;
string ans;
if(n == 1){
ans = "Odd";
}else if(n % 2 == 0){
if(n / 2 % 2) ans = "Same";
else ans = "Even";
}else{
ans = "Odd";
}
print(ans);
}
int main() {
cin.tie(0); cout.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(18);
int t;
cin >> t;
//t = 1;
while(t--) solve();
return 0;
} |
#include <bits/stdc++.h>
#define REP_(i, a_, b_, a, b, ...) \
for (int i = (a), END_##i = (b); i < END_##i; ++i)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
using i64 = long long;
using namespace std;
int main() {
i64 n, k;
cin >> n >> k;
const i64 n2 = n * 2, n3 = n * 3;
vector<i64> f3(n3 + 3, 0LL);
f3[3] = 1;
f3[n + 3] = -3;
f3[2 * n + 3] = 3;
REP(i, 3) REP(j, n3) f3[j + 1] += f3[j];
vector<i64> f2(n2 + 2, 0LL);
f2[2] = 1;
f2[n + 2] = -2;
REP(i, 2) REP(j, n2) f2[j + 1] += f2[j];
i64 rem = k;
i64 s, x;
for (s = 3; rem > f3[s]; ++s) {
rem -= f3[s];
}
for (x = max(s - n * 2, 1LL); rem > f2[s - x]; ++x) {
rem -= f2[s - x];
}
const i64 y = max(s - x - n, 1LL) + rem - 1;
const i64 z = s - x - y;
cout << x << " " << y << " " << z << endl;
}
| #include <bits/stdc++.h>
long long int sum_arr(long long int start, long long int end) {
if (start < 0 || end < 0) {
return 0;
}
return (start + end) * (start - end + 1) / 2;
}
int main() {
long long int N, K;
std::cin >> N >> K;
long long int res = K;
for (long long int l = 3; l <= 3 * N; l++) {
long long int c0 = (l - 1) * (l - 2) / 2;
long long int c1 = sum_arr(l - 1 - (N + 1), 0) * 3;
long long int c2 = sum_arr(l - 1 - N - (N + 1), 0) * 3;
long long int c = c0 - c1 + c2;
if (res - c <= 0) {
// i + j + k == l
// std::cout << l << " , " << res << std::endl;
// std::cout << "l = " << l << std::endl;
for (long long int i = std::max(1ll, l - 2 * N); i <= N; i++) {
long long int jk = l - i; // sum of j and k
long long int cnt = std::min(N, jk - 1) - std::max(1ll, jk - N) + 1;
// std::cout << i << " " << jk << " " << cnt << std::endl;
// std::cout << i << " " << jk << " " << cnt << std::endl;
if (res - cnt <= 0) {
long long int j = std::max(1ll, jk - N) + res - 1;
std::cout << i << " " << j << " " << l - i - j << std::endl;
return 0;
}
res -= cnt;
}
// std::cout << res << std::endl;
// break;
}
res -= c;
}
}
|
// Author :- Sarvesh Chaudhary
#include<bits/stdc++.h>
using namespace std;
#define w(x) int x; cin>>x; while(x--)
#define ll long long int
#define sidha(i,a,b) for(int i=a;i<b;i++)
#define set_built(x) __builtin_popcountll(x)
#define zero_built(x) __bultin_ctzll(x)
#define pairi pair<int,int>
#define vi vector<int>
#define mod 1000000007
#define MAX INT_MAX
#define MIN INT_MIN
#define pb push_back
#define po pop_back
#define all(c) c.begin(),c.end()
#define io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//Global Variable
map<int,int> m;
//Functions
//Driver Function
int main(){
io;
double a,b,c,d;cin>>a>>b>>c>>d;
double x=d/a;
if(x>c or x<b){
cout<<"Yes"<<endl;
}
else{
cout<<"No"<<endl;
}
return 0;
} | #include<bits/stdc++.h>
#define lli long long int
using namespace std;
int main()
{
lli a,b,c,d,t,n,x,y,z,i,j,k,s,v;
cin>>v>>s>>t>>d;
if(d>=v*s && d<=v*t)
{
cout<<"No"<<endl;
}
else
{
cout<<"Yes"<<endl;
}
return 0;
}
|
#include <stdio.h>
int main()
{
int arr[3], remaining = 0;
scanf("%d %d %d", &arr[0], &arr[1], &arr[2]);
bool flag = false;
for (int i = 0; i <= 1; i++)
{
for (int j = i + 1; j <= 2; j++)
{
if (arr[i] == arr[j])
{
flag = true;
if (i == 1)
{
remaining = arr[0];
}
else
{
(j == 1) ? remaining = arr[2] : remaining = arr[1];
}
break;
}
}
if (flag && remaining != 0)
{
break;
}
}
printf("%d\n", remaining);
return 0;
} | #pragma GCC optimize("Ofast")
/*#pragma GCC target("avx,avx2,fma")
#pragma GCC target ("sse4")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld double
#define rep(i,a,b) for(ll i=a; i<b; ++i)
#define BOOST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define all(v) v.begin(),v.end()
#define sl(a) a.size()
#define mod 1000000007
#define lcm(a,b) (a*b)/__gcd(a,b)
#define MAX1 100006
#define f first
#define s second
#define pi 2*acos(0.0)
bool isPowerOfTwo (ll x) { return x && (!(x&(x-1))); }
ll Modular_Exponentiation(ll x, ll n, ll M)
{
if(n==0) return 1;
if(n%2) return (x*Modular_Exponentiation((x*x)%M,n/2,M))%M;
else return (Modular_Exponentiation((x*x)%M,n/2,M))%M;
}
bool isPrime(ll n)
{
if (n<=1) return false;
if (n<=3) return true;
if (n%2==0||n%3==0) return false;
for(ll i=5; i*i<=n; i+=6)
if (n%i==0||n%(i+2)==0) return false;
return true;
}
/********************************************************************************************/
void solve()
{
char s,t; cin>>s>>t;
if(s=='Y') cout<<char(toupper(t));
else cout<<t;
}
int32_t main()
{
#ifndef ONLINE_JUDGE
// for getting input from input.txt
freopen("input.txt","r",stdin);
//for getting error from error.txt
freopen("error.txt", "w", stderr);
// for writing output to output.txt
freopen("output.txt","w",stdout);
#endif
BOOST
int T=1; //cin>>T;
while(T--) solve();
cerr<<"Time taken : "<<fixed<<setprecision(5)<<((float)clock()/CLOCKS_PER_SEC)*1000<<" ms"<<"\n";
cerr<<"My CLOCKS_PER_SEC= "<<CLOCKS_PER_SEC<<"\n";
return 0;
}
|
#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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
∧_∧
∧_∧ (´<_` ) Welcome to My Coding Space!
( ´_ゝ`) / ⌒i @hamayanhamayan0
/ \ | |
/ / ̄ ̄ ̄ ̄/ |
__(__ニつ/ _/ .| .|____
\/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/
int N;
vector<pair<int, string>> v;
//---------------------------------------------------------------------------------------------------
void _main() {
cin >> N;
rep(i, 0, N) {
string S; int T;
cin >> S >> T;
v.push_back({ T, S });
}
sort(all(v));
cout << v[v.size() - 2].second << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n, L;
cin >> n >> L;
auto input = [&]() {
vector<int> a(n);
for (auto&& e : a) {
cin >> e;
}
a.emplace_back(L + 1);
for (auto i = 0; i <= n; i++) a[i] -= i + 1;
for (auto i = n; i; i--) a[i] -= a[i - 1];
return a;
};
auto a = input();
auto b = input();
int l = 0;
long ans = 0;
for (auto i = 0; i <= n; i++) {
int w = b[i];
if (!w) continue;
while (l <= n && !a[l]) ++l;
int r = l;
int sum = 0;
while (r <= n && sum < w) {
sum += a[r];
r++;
}
if (sum > w) {
cout << "-1\n";
return 0;
}
ans += max(0, i - l);
ans += max(0, r - 1 - i);
l = r;
}
cout << ans << endl;
}
|
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i < n + 1; i++)
#define all(A) A.begin(), A.end()
typedef long long ll;
using P = pair<int, int>;
struct E
{
int to, co;
E(int a, int b)
{
to = a;
co = b;
}
};
struct node
{
int dis, pos;
node(int a, int b)
{
dis = a;
pos = b;
}
};
int n, m;
vector<vector<E>> g;
const int INF = (int)1e9;
void solve(int sv)
{
vector<int> dist(n+1, INF);
vector<bool> seen(n+1, 0);
priority_queue<P, vector<P>, greater<P>> q;
for (E next : g[sv])
{
if (next.co >= dist[next.to]){
continue;
}
q.emplace(make_pair(next.co, next.to));
dist[next.to] = next.co;
}
while (!q.empty())
{
node now = node(q.top().first, q.top().second);
q.pop();
for (E next : g[now.pos])
{
int this_route = now.dis + next.co;
if (this_route >= dist[next.to])
{
continue;
}
q.emplace(make_pair(this_route, next.to));
dist[next.to] = this_route;
}
}
int ans = dist[sv];
if (ans == INF)
{
ans = -1;
}
cout << ans << endl;
}
int main()
{
cin >> n >> m;
g.resize(n+1);
rep(i, m)
{
int a, b, c;
cin >> a >> b >> c;
g[a].push_back(E(b, c));
}
rep1(sv, n)
{
solve(sv);
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
// You should only debug a pair of simple data types. For example,
// the debug won't work if one of pair's elements is collection type
// (std::vector, std::map, std::set...).
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
// Shortcuts for "common" data types in contests
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<char,char> pcc;
typedef pair<char,int> pci;
typedef pair<int,char> pic;
typedef vector<pii> vpii;
typedef set<int> si;
typedef set<ll> sll;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
#define ff first
#define ss second
#define endl '\n'
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend()
#define rep(i, a, b) for(int i = a; i < b; i++)
#define repv(c, it) \
for(auto it = (c).begin(); it != (c).end(); it++)
#define repm(c, it) \
for(mll::iterator it = (c).begin(); it != (c).end(); it++)
const long long inf = 9223372036854775807;
#define pb push_back
const long long mod = 1000000007;
const double pi = acos(-1);
int main() {
//decreases the time taken by cin,cout.
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
//freopen("error.txt", "w", stderr);
freopen("output.txt", "w", stdout);
#endif
int n;cin>>n;
mii m;
rep(i,0,n)
{
int x;cin>>x;
if(m.find(x)==m.end()){m[x]=1;}
else{cout<<"No";return 0;}
}
cout<<"Yes";
return 0;
}
|
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read()
{
int x=0;
bool flag=1;
char c=getchar();
while(c<'0'||c>'9')
{
if(c=='-')
flag=0;
c=getchar();
}
while(c>='0'&&c<='9')
{
x=(x<<1)+(x<<3)+c-'0';
c=getchar();
}
return (flag?x:~(x-1));
}
int a,b,c,d;
signed main()
{
a=read();
b=read();
c=read();
d=read();
int l=0,r=1e8;
while(l<=r)
{
int mid=(l+r)>>1;
int x=a+mid*b,y=mid*c;
if(y*d>=x)
r=mid-1;
else
l=mid+1;
}
if(l==1e8+1)
puts("-1");
else
cout<<l<<endl;
return 0;
}
| #include<bits/stdc++.h>
#define vll vector<long long>
#define ll long long
#define dbg(x) cout << #x << " " << x <<endl;
#define forn(i,n) for(int i=0;i<(int)n;i++)
#define farn(i,x,n) for(int i=x;i<=(int)n;i++)
#define rforn(i,n) for(int i=n-1;i>=0;i--)
#define rep(i,s,n) for(int i=s;i<n;i++)
#define sz(x) ((int)x.size())
#define clr(x) memset(x,0,sizeof(x))
#define sa(v) sort(v.begin(), v.end())
#define sd(v) sort(v.begin(),v.end(), greater<int>())
#define pb push_back
#define mp make_pair
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define ff first
#define ss second
#define cl(a,b) (a+b-1)/b
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)
const int mod = 1000000007;//1e9+7
const int INF = 2e9 + 2;
const int N = 2e5+5;
using namespace std;
ll a, b, c, d;
void sol ()
{
cin >> a >> b>>c>>d;
if(d*c - b <= 0)cout<<-1;
else
cout<<cl(a,(d*c - b));
cout<<endl;
}
int main(){
int TC;
TC = 1;
// cin >> TC;
while (TC--)
{
sol();
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include <debugger.h>
#else
#define dbg(x...) {}
#define dbg_t() {}
#endif
using ll = long long;
using ld = long double;
const ll INF = 1e18;
void solve()
{
ll n, m; cin >> n >> m;
vector<string> grid(n);
for (ll i = 0; i < n; i++)
cin >> grid[i];
dbg(grid);
auto in = [&](ll x, ll y)
{
return (x >= 0 && y >= 0 && x < n && y < m);
};
vector<vector<array<ll, 2>>> dp(n, vector<array<ll, 2>>(m, {INF, INF}));
function<array<ll, 2>(ll, ll)> rec = [&](ll a, ll b)
{
dbg(a, b);
array<ll, 2> r = {0ll, 0ll};
if ((a == n - 1) && (b == m - 1))
return r;
if (!in(a, b))
return r;
array<ll, 2> d = {INF, INF};
if (dp[a][b] != d)
return dp[a][b];
array<ll, 2> x1 = rec(a, b + 1), x2 = rec(a + 1, b);
array<ll, 2> ans1 = {0, INF}, ans2 = {0, INF}, ans;
if (in(a, b + 1))
{
if (grid[a][b + 1] == '+')
ans1 = {x1[1] + 1, x1[0]};
else
ans1 = {x1[1] - 1, x1[0]};
}
if (in(a + 1, b))
{
if (grid[a + 1][b] == '+')
ans2 = {x2[1] + 1, x2[0]};
else
ans2 = {x2[1] - 1, x2[0]};
}
if ((ans1[0] - ans1[1]) > (ans2[0] - ans2[1]))
ans = ans1;
else
ans = ans2;
return dp[a][b] = ans;
};
array<ll, 2> res = rec(0, 0);
dbg(res);
if (res[0] > res[1])
cout << "Takahashi" << "\n";
else if (res[1] > res[0])
cout << "Aoki" << "\n";
else
cout << "Draw" << "\n";
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ll _t = 1;
// cin >> _t;
for (ll i = 1; i <= _t; i++)
{
// cout << "Case #" << i << ": ";
solve();
}
dbg_t();
return 0;
}
| #include "bits/stdc++.h"
using namespace std;
#define mp make_pair
#define pb push_back
#define ll long long int
#define sdll(x) scanf("%lld",&x)
#define sd(x) scanf("%d",&x)
#define inf (ll)(1e18+9)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define bits(x) __builtin_popcount(x)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define bitsll(x) __builtin_popcountll(x)
#define all(x) x.begin(),x.end()
#define ld long double
#define test() ll test; cin>>test; while(test--)
#define fi first
#define se second
inline ll GCD(ll x, ll y) {
if(x<y) swap(x,y);
if(x==0) return y;
if(y==0) return x;
return GCD(x%y,y);
}
ll phi(ll n) {
ll result = n;
for (ll i = 2; i * i <= n; i++) {
if(n % i == 0) {
while(n % i == 0)
n /= i;
result -= result / i;
}
}
if(n > 1)
result -= result / n;
return result;
}
ll power(ll x, ll n, ll mod) {
ll res = 1;
x %= mod;
while(n) {
if(n&1) {
res = ((res*x)%mod+mod)%mod;
}
x = ((x*x)%mod+mod);
n>>=1;
}
return res;
}
const int MAXN = 2005;
const ll INIT_VALUE = -inf;
int H,W;
ll dp[MAXN][MAXN];
char mat[MAXN][MAXN];
void clear() {
for(int i=0;i<=H;i++) {
for(int j=0;j<=W;j++) {
dp[i][j] = INIT_VALUE;
}
}
}
inline bool check(int x ,int y) {
return x>=1 && x<=H && y>=1 && y<=W;
}
inline ll getvalue(int x, int y) {
return mat[x][y]=='+'?1:-1;
}
ll solve(int x, int y);
ll solving(int x, int y) {
ll ans = -inf;
if(mat[x][y]=='+') {
if(check(x+1,y) && check(x,y+1)) {
ans = max(ans,1+min(solve(x+1,y)-getvalue(x+1,y),solve(x,y+1)-getvalue(x,y+1)));
} else if(check(x+1,y)) {
ans = max(ans,1+solve(x+1,y)-getvalue(x+1,y));
} else if(check(x,y+1)) {
ans = max(ans,1+solve(x,y+1)-getvalue(x,y+1));
} else {
ans = 1;
}
} else {
if(check(x+1,y) && check(x,y+1)) {
ans = max(ans,-1+min(solve(x+1,y)-getvalue(x+1,y),solve(x,y+1)-getvalue(x,y+1)));
} else if(check(x+1,y)) {
ans = max(ans,-1+solve(x+1,y)-getvalue(x+1,y));
} else if(check(x,y+1)) {
ans = max(ans,-1+solve(x,y+1)-getvalue(x,y+1));
} else {
ans = -1;
}
}
return ans;
}
ll solve(int x, int y) {
if(!check(x,y)) {
return -inf;
}
if(x==H && y==W) return 0;
if(dp[x][y]!=INIT_VALUE) return dp[x][y];
ll ans = -inf;
if(check(x+1,y)) {
ans = max(ans,solving(x+1,y));
}
if(check(x,y+1)) {
ans = max(ans,solving(x,y+1));
}
// cout<<x<<" "<<y<<" "<<ans<<endl;
return dp[x][y] = ans;
}
int main() {
fastio;
cin>>H>>W;
for(int i=1;i<=H;i++) {
for(int j=1;j<=W;j++) {
cin>>mat[i][j];
}
}
clear();
ll ans = solve(1,1);
if(ans>0) {
cout<<"Takahashi"<<endl;
} else if(ans<0) {
cout<<"Aoki"<<endl;
} else {
cout<<"Draw"<<endl;
}
}
|
#include <iostream>
#include <vector>
using namespace std;
int main(void){
long long N,M,T;
cin >> N >> M >> T;
long long start, end, now, B;
B = N;
now = 0;
for(int i=0;i<M;i++){
cin >> start >> end;
B -= start-now;
if(B<=0){
cout << "No";
return 0;
}
// cout << B << endl;
B = min(N, B+end-start);
// cout << B << endl;
now = end;
}
if(B-(T-now)<=0) cout << "No";
else cout << "Yes";
return 0;
} |
///−In the name of God −///
//In mathematics, an unordered pair or pair set is a set of the form {a, b},
//i.e. a set having two elements a and b with no particular relation between them.
//In contrast, an ordered pair (a, b) has a as its first element and b as its second element.
//So, (a,b)!=(b,a) in ordered pair but it is in case of unordered pair.
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long int
#define dl double
#define llu unsigned long long int
#define scll(x) scanf("%lld",&x)
#define scld(x) scanf("%lf",&x)
#define scull(x) scanf("%llu",&x)
#define scch(x) scanf(" %c",&x)
#define eb(x) emplace_back(x)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define ppb() pop_back()
#define ppf() pop_front()
#define Pi acos(-1.0)
#define inf 1000000000000000000
#define mod 1000000007
#define ff first
#define ss second
#define mpr make_pair
#define debug(x) cout<<x<<'\n';
#define MAX 1000000
#define eps 1e-8
#define nl cout<<'\n'
#define ump unordered_map
#define mp map
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_multiset;
//Taking input by EOF
//while(scanf("%lld",&x)!=-1){ }
// Creates a min heap
//priority_queue <int, vector<int>, greater<int> > pq;
//sin((x*pi)/180.0)[x in degree]
//sin(x)[x in radian]
//asin(x)[radian]
//(asin(x)*180)/pi[degree]
//or(|)//and(&)//xor(^)//not(~)
//S.order_of_key(x)[Give me the position of x]
//S.find_by_order(x)[Give me the x th element in set]
//pair can no te used as index in Unordered_map
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//Knight moves
ll dx[8]={-2,-2,2,2,-1,-1,1,1};
ll dy[8]={1,-1,1,-1,2,-2,2,-2};
ll lcm(ll a, ll b) {return (a * b) / __gcd(a, b);}
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ll a, b, c = 0, d, e, f = 0, g, h, i, j = 0, k, m, n, o, p, s, t, v, w, x = 0, y, z, l, res = 0;
ll cnt = 0, l1 = 0, l2, l3, c1 = 0, c2 = 0, c3 = 0, mx = 0, mn = inf;
ll prevsum = 0, ans1 = 0, ans2 = 0, odd = 0, even = 0, hh, mm;
string str, str1, str2, str3 = "", str4 = "";
ll ide = 0, idx = 0, Q;
ll xa, xy;
/*scll(t);
while(t--)
{
}*/
scll(n);
scll(m);
scll(t);
ll ans=n;
ll prev=0;
f=0;
for(i=0;i<m;i++)
{
scll(a);
ans-=a-prev;
if(ans<=0)
{
f=1;
}
scll(b);
ans+=b-a;
if(ans>n)
ans=n;
prev=b;
}
ans-=t-prev;
if(ans<=0)
f=1;
//cout<<ans;
if(f)
cout<<"No";
else
cout<<"Yes";
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define REP(i, a, b) for (ll i = a; i <= b; i++)
#define REP_REV(i, a, b) for (ll i = a; i >= b; i--)
#define debug(x) cerr << #x << " is " << x << endl;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define endl "\n"
#define pb push_back
#define rsz resize
#define f first
#define s second
#define mp make_pair
using ll = int64_t;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vc = vector<char>;
using ull = unsigned int64_t;
using pi = pair<int, int>;
using vl = vector<int64_t>;
using pl = pair<int64_t, int64_t>;
using vpl = vector<pair<int64_t, int64_t>>;
using msl = map<string, int64_t>;
using vvl = vector<vector<int64_t>>;
#define DBG1(x) cerr << (#x) << ": " << (x) << endl;
#define DBG2(x, y) cerr << (#x) << " " << (#y) << ": " << (x) << " " << y << endl;
#define DBG3(x, y, z) cerr << (#x) << " " << (#y) << " " << (#z) << ": " << (x) << " " << y << " " << z << endl;
#define DBG4(a, b, c, d) cerr << (#a) << " " << (#b) << " " << (#c) << " " << (#d) << ": " << a << " " << b << " " << c << " " << d << endl;
template <class T>
void DBGvec(vector<T> a) {
for (T i : a) cerr << i << " ";
cerr << endl;
}
const ll MOD = 1e9 + 7;
const int INF = int(1e9);
bool isPrime(ll n) {
if (n == 1) return false;
if (n == 2) return true;
for (ll i = 2; i * i <= n; i++) {
if (n % i == 0) {
return false;
}
}
return true;
}
unsigned long long factorial(int n) {
const unsigned int M = MOD;
unsigned long long f = 1;
for (int i = 1; i <= n; i++)
f = (f * i) % M;
return f;
}
ll expon(ll a, ll b, ll m = MOD) {
ll res = 1;
a %= m;
while (b > 0) {
if (b & 1)
res = res * a % m;
a = a * a % m;
b >>= 1;
}
return res;
}
void solve() {
ll n, q;
string s;
cin >> n >> s >> q;
bool turn = 1;
REP(i, 0, q - 1) {
ll t, a, b;
cin >> t >> a >> b;
if (t == 1) {
if (turn) {
swap(s[a - 1], s[b - 1]);
} else {
if (a <= n && b <= n) {
swap(s[n + a - 1], s[n + b - 1]);
} else if (a > n && b > n) {
swap(s[a - n - 1], s[b - n - 1]);
} else if (a <= n && b > n) {
swap(s[n + a - 1], s[b - n - 1]);
}
}
} else {
turn = !turn;
}
}
if (turn) {
cout << s;
} else {
cout << s.substr(n, n) + s.substr(0, n);
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
int tt = clock();
#endif
// freopen("split.in", "r", stdin);
// freopen("split.out", "w", stdout);
// ll t;
// cin >> t;
// while (t--)
solve();
#ifdef _DEBUG
cerr << "\nTIME = " << clock() - tt << endl;
tt = clock();
#endif
return 0;
} | //ver 8.1
#include <bits/stdc++.h>
using namespace std;
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vd = vector<ld>;
using vs = vector<string>;
using vb = vector<bool>;
using vvl = vector<vector<ll>>;
using vvd = vector<vector<ld>>;
using vvs = vector<vector<string>>;
using vvb = vector<vector<bool>>;
using pll = pair<ll,ll>;
using mll = map<ll,ll>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
#define each(x,v) for(auto& x : (v))
#define reps(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define mp make_pair
const ll INF = 1LL << 60;
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) ((a)<=(x)&&(x)<=(b))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ) //被り削除
#define debug cout << "line : " << __LINE__ << " debug" << endl;
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ind(...) long double __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define inc(...) char __VA_ARGS__; in(__VA_ARGS__)
void in(){}
template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
template <typename T> void in1(T &s) {rep(i,s.size()){in(s[i]);}}
template <typename T> void in2(T &s,T &t) {rep(i,s.size()){in(s[i],t[i]);}}
template <typename T> void in3(T &s,T &t,T &u) {rep(i,s.size()){in(s[i],t[i],u[i]);}}
template <typename T> void in4(T &s,T &t,T &u,T &v) {rep(i,s.size()){in(s[i],t[i],u[i],v[i]);}}
template <typename T> void in5(T &s,T &t,T &u,T &v,T &w) {rep(i,s.size()){in(s[i],t[i],u[i],v[i],w[i]);}}
void out(){cout << endl;}
template <typename T,class... U> void out(const T &t,const U &...u){cout << t; if(sizeof...(u)) cout << " "; out(u...);}
void die(){cout << endl;exit(0);}
template <typename T,class... U> void die(const T &t,const U &...u){cout << t; if(sizeof...(u)) cout << " "; die(u...);}
template <typename T> void outv(T s) {rep(i,s.size()){if(i!=0)cout<<" ";cout<<s[i];}cout<<endl;}
template <typename T> void out1(T s) {rep(i,s.size()){out(s[i]);}}
template <typename T> void out2(T s,T t) {rep(i,s.size()){out(s[i],t[i]);}}
template <typename T> void out3(T s,T t,T u) {rep(i,s.size()){out(s[i],t[i],u[i]);}}
template <typename T> void out4(T s,T t,T u,T v) {rep(i,s.size()){out(s[i],t[i],u[i],v[i]);}}
template <typename T> void out5(T s,T t,T u,T v,T w) {rep(i,s.size()){out(s[i],t[i],u[i],v[i],w[i]);}}
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
template <typename T> T allSum(vector<T> a){T ans=T();each(it,a)ans+=it;return ans;}
template<typename T> bool inside(T a,T b){auto it=a.begin()-1;each(x,b){it=find(it+1,a.end(),x);if(it==a.end())return false;}return true;}
ll ceilDiv(ll a,ll b) {return (a+b-1)/b;}
ld dist(pair<ld,ld> a, pair<ld,ld> b){return sqrt(abs(a.fi-b.fi)*abs(a.fi-b.fi)+abs(a.se-b.se)*abs(a.se-b.se));} // 2点間の距離
ll gcd(ll a, ll b) { return b != 0 ? gcd(b, a % b) : a; }
ll lcm(ll a,ll b){ return a / gcd(a,b) * b;}
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
#define YES(n) ((n) ? "YES" : "NO" )
#define Yes(n) ((n) ? "Yes" : "No" )
#define yes(n) ((n) ? "yes" : "no" )
int main(){
init();
inl(n,k);
ll ans=0;
rep(i,n)rep(j,k){
ll a=(i+1)*100+j+1;
ans+=a;
}
out(ans);
return 0;
} |
#include <bits/stdc++.h>
// #define x first
// #define y second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int N = 2e5 + 20;
int n, t;
bool vis[N];
int main()
{
IOS; cin >> t >> n;
// LL l = 1, r = 1e13, res = 1;
// while(l <= r)
// {
// LL mid = l + r >> 1;
// if(t * mid >= n * 100ll)
// {
// r = mid - 1;
// res = mid;
// }
// else l = mid + 1;
// }
// cout << res + n - 1 << endl;
cout << (100ll * n + t - 1) / t + n - 1 << endl;
return 0;
} | #include<bits/stdc++.h>
#define int long long
#define ls (rt<<1)
#define rs (rt<<1|1)
#define pii pair<int,int>
#define fi first
#define se second
#define rd(u) u=read()
#define endl '\n'
using namespace std;
const int N=2e6+5;
const int M=1e7+5;
const int mod=1e9+7;
const int inf=3e18;
inline int read(){int u=0,f=1;char ch=getchar();while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){u=u*10+ch-'0';ch=getchar();}return u*f;}
int ksm(int u,int y=mod-2,int z=mod){int ret=1;while (y){if (y&1) ret=(ret*u);u=(u*u);y>>=1;}return ret;}
int t,n,m,ans;
int x[N],y[N];
signed main()
{
rd(t);rd(n);
for (int a=1;a<=100;a++)
{
int b=(100+t)*a/100;
x[b]=1;
}
for (int i=1;i<=100+t;i++) if (!x[i]) y[++m]=i;
//for (int i=1;i<=m;i++) cout<<y[i]<<" ";cout<<endl;
n--;
ans=(n/m)*(100+t);
ans+=y[(n%m+1)];
cout<<ans<<endl;
} |
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <numeric>
#include <algorithm>
#include <queue>
#include <bitset>
using namespace std;
#define rep(i,n) for(int i=0 ; i<(n) ; ++i)
typedef long long ll;
typedef pair<int,int> p;
const int MOD = 1000000000+7;
const int INF = 1001000100;
int main(){
ll n;
cin >> n;
ll a[n];
rep(i,n) cin>>a[i];
//dp。i番目までに作業をして、i番目を+で足したか-で足した時の和と、その場合の数を足していく。
ll dp[n][2][2];//+で足した時の(和、場合の数)、-で足した時の(和、場合の数)
dp[0][0][0] = a[0];
dp[0][0][1] = 1;
dp[0][1][0] = 0;
dp[0][1][1] = 0;
for(int i=1 ; i<n ; ++i){
dp[i][0][0] = dp[i-1][0][0] + dp[i-1][1][0] + (dp[i-1][0][1]+dp[i-1][1][1])*a[i];
dp[i][0][0] = dp[i][0][0] % MOD;
dp[i][1][0] = dp[i-1][0][0] + dp[i-1][0][1]*(MOD - a[i]);
dp[i][1][0] = dp[i][1][0] % MOD;
dp[i][0][1] = (dp[i-1][0][1] + dp[i-1][1][1]) %MOD;
dp[i][1][1] = dp[i-1][0][1] % MOD;
}
cout << (dp[n-1][0][0] + dp[n-1][1][0])%MOD;
return 0;
} | #include <bits/stdc++.h>
#define N 567
typedef long long ll;
using namespace std;
const int P = 998244353;
inline void read(int &x) {
scanf("%d", &x);
}
int n, m;
char s[N];
int bin[N + N];
inline void Set(int p, int v) {
if (bin[p] == -1) {
bin[p] = v;
} else {
if (bin[p] ^ v) {
puts("0"); exit(0);
}
}
}
int main() {
read(n), read(m);
memset(bin, -1, sizeof(bin));
for (int i = 1; i <= n; ++i) {
scanf("%s", s + 1);
for (int j = 1; j <= m; ++j) if (s[j] != '.')
Set(i + j, s[j] == 'R' ? 0 : 1);
}
int ans = 1;
for (int i = 2; i <= n + m; ++i) if (bin[i] == -1) ans = (ans + ans) % P;//bug
printf("%d\n", (ans % P + P) % P);
return 0;
} |
#include <bits/stdc++.h>
#define ALL(x) (x).begin(),(x).end()
using namespace std;
using ll = long long int;
using ull = unsigned long long int;
const ll INF=LLONG_MAX;
const int inf=INT_MAX;
const ull md=1000000000;//10^9
void out(int ans){
cout << ans << endl;
exit(0);
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int N;
cin >> N;
for(int i=1; ; i++){
if(1+(1+i)*i/2 > N){
cout << i << endl;
break;
}
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
string a, saida = "";
cin >> a;
int i = 0;
while(a[i] != '.' && i < a.length()){
saida += a[i];
i++;
}
cout << saida << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
cout << (1 << n) - 1 << '\n';
for (int i = 1; i < 1 << n; ++i) {
for (int j = 0; j < 1 << n; ++j) {
if (__builtin_popcount(i & j) & 1) {
cout << 'B';
} else {
cout << 'A';
}
}
cout << '\n';
}
return 0;
}
| #include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
typedef long long ll;
char buf[10][2000][2000];
int n;
int main(void) {
scanf("%d", &n);
buf[0][0][0] = 'A';
buf[0][0][1] = 'B';
REP(k, n-1) {
REP(i, (1<<(k+1))-1) {
REP(j, 1<<(k+1)) {
if(buf[k][i][j] == 'A') {
buf[k+1][2*i][j*2] = 'A';
buf[k+1][2*i][j*2+1] = 'A';
} else {
buf[k+1][2*i][j*2] = 'B';
buf[k+1][2*i][j*2+1] = 'B';
}
}
// cerr << "1> " << 2*i << " " << buf[k+1][2*i] << endl;
REP(j, 1<<(k+1)) {
if(buf[k][i][j] == 'A') {
buf[k+1][2*i+1][j*2] = 'A';
buf[k+1][2*i+1][j*2+1] = 'B';
} else {
buf[k+1][2*i+1][j*2] = 'B';
buf[k+1][2*i+1][j*2+1] = 'A';
}
}
// cerr << "2> " << 2*i+1 << " " << buf[k+1][2*i+1] << endl;
}
REP(j, 1<<(k+2)) {
buf[k+1][((1<<(k+1))-1)*2][j] = j % 2 ? 'B' : 'A';
}
// cerr << "3> " << ((1<<(k+1))-1)*2 << " " << buf[k+1][((1<<(k+1))-1)*2] << endl;
}
printf("%d\n", (1<<n)-1);
for(int i = 0; i < (1 << n)-1; ++i) {
puts(buf[n-1][i]);
}
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int in();
ll sol(ll i){
if(i%200==0) i/=200;
else i=i*1000+200;
return i;
}
int main(){
ll n,k;
n=in();k=in();
for(int i=1; i<=k; i++) n=sol(n);
cout<<n;
return 0;
}
int in(){
ll nn=0,ff=0;
char cc;
cc=cin.get();
while((cc<'0' || cc>'9') && cc!='-') cc=cin.get();
if(cc=='-') ff=1;
else nn=cc-'0';
cc=cin.get();
while(cc>='0' && cc<='9'){
nn=nn*10+cc-'0';
cc=cin.get();
}
if(ff==1) return -nn;
return nn;
}
| #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;
}
|
/* *Which of the favors of your Lord will you deny ?* */
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define vpnt(ans) \
for (ll i = 0; i < ans.size(); i++) \
cout << ans[i] << (i + 1 < ans.size() ? ' ' : '\n');
#define setbit(x, k) (x |= (1LL << k))
#define clearbit(x, k) (x &= ~(1LL << k)) //x er last theke k-1 tomo ghor
#define checkbit(x, k) (x & (1LL << k))
#define mp make_pair
#define scl(x) scanf("%lld", &x)
#define sci(x) scanf("%d", &x)
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define ff first
#define ss second
#define pii pair<int, int>
#define YES printf("YES\n")
#define Yes printf("Yes\n")
#define yes printf("yes\n")
#define NO printf("NO\n")
#define No printf("No\n")
#define no printf("no\n")
#define nn cout << "\n";
#define INF (1 << 30)
#define LL_INF (1LL << 32)
#define pll pair<ll, ll>
#define pp(n, p) (ll)(pow(n, p) + 0.5)
#define ok ios::sync_with_stdio(false);
#define fine cin.tie(nullptr);
#define mod 1000000007
#define N 100005
int main()
{
ll n;
cin>>n;
vector<int>a, b;
for(int i=0; i<n; i++)
{
ll x;
cin>>x;
a.pb(x);
}
ll res = 0;
for(int i=0; i<n; i++)
{
ll x;
cin>>x;
res += x*a[i];
}
if(res == 0) Yes;
else No;
} | #include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define int long long
typedef vector<int> vi;typedef vector<vi> vvi;
signed main(){
ios::sync_with_stdio(0);cin.tie(0);
#ifndef ONLINE_JUDGE
freopen("E:\\in.txt","r", stdin);
#endif
int n; cin >> n;
vi a(n), b(n);
for(int i =0; i < n; i++){
cin >> a[i];
}
for(int i =0; i < n; i++){
cin >> b[i];
}
int x =0 ;
for(int i =0; i < n; i++){
x += a[i] * b[i];
}
cout << (x ? "No":"Yes") << '\n';
} |
#include <bits/stdc++.h>
using namespace std;
vector<vector<int64_t>> v_comb(100,vector<int64_t>(100));
int64_t comb(int64_t x, int64_t y){
if(x < 0 || y < 0 || x < y) return 0;
if(y == 0 || x == y) return 1;
if(v_comb[x][y] != 0) return v_comb[x][y];
int64_t rtn = comb(x-1,y-1)+comb(x-1,y);
v_comb[x][y] = rtn;
return rtn;
}
int main(){
int a, b;
int64_t k;
cin >> a >> b >> k;
int ai = a;
int bi = b;
int64_t mink = 1;
int64_t maxk = comb(a+b,a)+1;
string ans;
for(int i = 0; i < a+b; i++){
if(k < comb(ai+bi-1,ai-1)+mink){
ans.push_back('a');
maxk = comb(ai+bi-1,ai-1)+mink;
ai--;
}
else{
ans.push_back('b');
mink = comb(ai+bi-1,ai-1)+mink;
bi--;
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
constexpr bool typetest = 0;
constexpr int N = 35 + 5;
int a, b;
ll k;
void Read()
{
cin >> a >> b >> k;
}
ll Pow(ll a, ll b)
{
ll ans(1);
for (; b > 0; b >>= 1)
{
if ((b & 1))
ans = ans * a;
a = a * a;
}
return ans;
}
ll Cals(ll x, ll y)
{
ll ans(0);
while (y >= x)
ans += (y /= x);
return ans;
}
ll Cal(int x, int y)
{
int n = x + y;
ll ans(1);
bitset<N> ck;
for (int i = 2; i <= n; ++i)
if (!ck[i])
{
ans *= Pow(i, Cals(i, n) - Cals(i, x) - Cals(i, y));
for (int j = i; j <= n; j += i)
ck[j] = 1;
}
return ans;
}
void Solve()
{
int n = a + b;
for (int i = 1; i <= n; ++i)
{
//cerr << i << "\n";
if (a > 0 && Cal(a - 1, b) >= k)
cout << 'a', --a;
else
cout << 'b', k -= Cal(a - 1, b), --b;
}
}
int32_t main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t(1);
if (typetest)
cin >> t;
for (int _ = 1; _ <= t; ++_)
{
Read();
Solve();
}
} |
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;
int main()
{
int N;
cin>>N;
vector<string> S(N);
for (string &s: S)
cin>>s;
int oo = 9999;
vector<vector<int>> D(N, vector<int>(N, 9999));
for (int i=0; i<N; i++)
for (int j=0; j<N; j++)
if (S[i][j]=='1')
D[i][j] = 1;
for (int i=0; i<N; i++)
D[i][i] = 1;
for (int i=0; i<N; i++)
for (int j=0; j<N; j++)
for (int k=0; k<N; k++)
D[k][j] = min(D[k][j], D[k][i]+D[i][j]);
double ans = 0;
for (int i=0; i<N; i++)
{
int c = 0;
for (int j=0; j<N; j++)
if (D[j][i]<oo)
c++;
ans += 1./c;
}
printf("%.16f\n", ans);
}
| #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#ifndef aa
#define trace(...)
#define endl '\n'
#endif
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define fi first
#define se second
#define int long long
typedef long long ll;
typedef long double ld;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sz(x) ((long long)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define frev(a,b,c) for(int a=c; a>=b; a--)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define trav(a,x) for(auto &a:x)
#define all(con) con.begin(),con.end()
#define done(x) {cout << x << endl;return;}
#define mini(x,y) x=min(x,y)
#define maxi(x,y) x=max(x,y)
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
//const int mod = 998244353;
const int mod = 1e9 + 7;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<int>> vvi;
typedef vector<pair<int, int>> vpii;
typedef map<int, int> mii;
typedef set<int> si;
typedef set<pair<int,int>> spii;
typedef queue<int> qi;
uniform_int_distribution<int> rng(1,1e9);
//DEBUG FUNCTIONS START
#define cerr cout
void __print(int x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
//#define deb(x...) cerr << "[" << #x << "] = "; _print(x)
#define deb(x...) _print(x)
#else
#define deb(x...)
#endif
// DEBUG FUNCTIONS END
const int N = 1e3+5;
vi g[N];
void solve(){
int n;
cin>>n;
ld ans = 0;
vs a(n);
rep(i,0,n){
cin>>a[i];
rep(j,0,n){
if(a[i][j]=='1')
g[j].pb(i);
}
}
rep(i,0,n){
int cnt = 0;
vi vis(n);
qi q;
q.push(i);
vis[i] = 1;
while(q.size()){
int v = q.front();
q.pop();
cnt++;
trav(to, g[v]){
if(!vis[to]){
vis[to] = 1;
q.push(to);
}
}
}
ans += (ld)1/cnt;
}
cout << ans;
}
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cout << fixed << setprecision(15);
int t = 1;
//cin >> t;
while (t--)
solve();
return 0;
}
int powm(int a, int b){
int res = 1;
while (b) {
if (b & 1)
res = (res*a) % mod;
a = (a * a) % mod;
b >>= 1;
}
return res;
}
int divide(int a, int b) {
return (a % mod) * powm(b % mod, mod - 2) % mod;
}
int norm(int a) {
while (a >= mod) a -= mod;
while (a < 0) a += mod;
return a;
} |
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000007
using namespace std;
bool visited[2001];
ll dist[2001];
vector<pair<int,int>> adj[2001];
int edges[2001][2001];
int main()
{
int N,M;
cin>>N>>M;
memset(edges,0,sizeof(edges));
memset(dist,INF,sizeof(dist));
for(int i=1; i<=M; i++)
{
int A,B;
ll C;
cin>>A>>B>>C;
adj[A].push_back({C,B});
if(edges[A][B]==0 || C<edges[A][B])
{
edges[A][B]=C;
}
}
priority_queue<pair<int,int>> q;
for(int i=1; i<=N; i++)
{
dist[i]=0;
q.push({0,i});
while(!q.empty())
{
long long a=q.top().second;
q.pop();
if(visited[a])
{
continue;
}
visited[a]=true;
for(auto u: adj[a])
{
long long b=u.second;
long long w=u.first;
if(dist[a]+w<dist[b])
{
dist[b]=dist[a]+w;
q.push({-dist[b],b});
}
}
}
ll minn=INF;
for(int j=1; j<=N; j++)
{
if(dist[j]==INF)
{
continue;
}
if(edges[j][i]>0)
{
ll temp= dist[j]+edges[j][i];
if(temp<minn)
{
minn=temp;
}
}
}
if(minn==INF)
{
cout<<"-1"<<endl;
}
else
{
cout<<minn<<endl;
}
memset(visited,false,sizeof(visited));
for(int j=1; j<=N; j++)
{
dist[j]=INF;
}
}
return 0;
} | #include<bits/stdc++.h>
#define ll long long
#define dl long double
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define rep(i,a,b) for(i=a;i<b;i++)
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define mod 1000000007LL
#define CIN(V,s,n) for(int i=s;i<n;i++){cin >> V[i];}
#define COUT(V,s,n) {for(int i=s;i<n;i++){cout << V[i] << " " ;} cout << endl;}
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define CLEAR(V); for(ll i=0;i<V.size();i++) V[i] = 0;
#define N 200002LL
#define tmod 998244353LL
using namespace std;
bool sBs(const pair<int,int> &a,const pair<int,int> &b)
{ return (a.second < b.second); }
ll Powb(ll b,ll n,ll m);
ll BS(vector<pair< ll ,ll > > &PS,ll s,ll e,ll ser);
ll MI(ll a, ll m);
ll P[N+1];
void Sieve(int n=N);
vector<vector<ll> > G(N), K(N), T(N);
int main()
{
fast;
ll q=1,t;
//cin >> q; t = q;
while(q--)
{
ll i,j,n,m,k,l=0,r=0,a=0,b=0,c=0,d=0,e,g=1,p,u,v,w,x,y,z,flag=1;
//n=m=k=i=j=l=r=a=b=c=d=u=v=w=p=x=y=0;
cin >> n >> m >> x >> y;
for (i=0;i<m;i++) {
cin >> u >> v >> t >> k;
G[u].pb(v); K[u].pb(k), T[u].pb(t);
G[v].pb(u); K[v].pb(k), T[v].pb(t);
}
priority_queue<pair<ll,ll>, vector<pair<ll,ll>> , greater<pair<ll,ll>> > PQ;
PQ.push({0,x});
vector<ll> dist(n+1,-1);
while(!PQ.empty()) {
pair<ll,ll> U = PQ.top(); PQ.pop();
u = U.S;
w = U.F;
for (i=0;i<G[u].size();i++) {
v = G[u][i];
k = K[u][i];
t = T[u][i];
ll nw = t + ((w+k-1)/k)*k;
if (nw < dist[v] or dist[v] == -1) {
dist[v] = nw;
PQ.push({nw,v});
}
}
}
cout << dist[y];
}
return 0;
}
//*****************************************************************************************************************************************
ll Powb(ll b,ll n,ll m)
{
if(n==0) return 1LL;
if(n==1) return b;
ll temp = Powb(b,n/2,m);
if(n%2==0){return (temp*temp)%m;}
else{return (b*((temp*temp)%m))%m;}
}
ll BS(vector<pair<ll,ll> > &PS,ll s,ll e,ll ser)
{
if(s>e)
return s;
ll mid = (s+e)/2;
if(PS[mid].F==ser)
{
return mid;
}
else if(PS[mid].F > ser)
{
return BS(PS,s,mid-1,ser);
}
else
return BS(PS,mid+1,e,ser);
}
ll MI(ll a, ll m)
{
ll m0 = m;
ll y = 0, x = 1;
if (m == 1)
return 0;
while (a > 1)
{
ll q = a / m;
ll t = m;
m = a % m, a = t;
t = y;
y = x - q * y;
x = t;
}
if (x < 0)
x += m0;
return x;
}
void Sieve(int n)
{
//memset(P,1,sizeof(P));
P[0] = 0;
P[1]= 0;
for(int i=2;i<=n;i++) P[i] = 1;
for(ll i=2;i*i<=n;i++)
{
if(P[i]==1)
{
for(ll j=i*i;j<=n;j+=i)
{
P[j]=0;
}
}
}
}
|
/*
AUTHOR: nit1n
CREATED: 15.11.2020 18:02:29
*/
#include<bits/stdc++.h>
#define int long long
using namespace std ;
const int N = 2e5 + 10 ;
int a[N] ;
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL) ;
int n ,w ;
cin >> n >> w ;
for(int i = 0; i < n ; ++i){
int s , t , p ;
cin >> s >> t>>p ;
a[s] += p ;
a[t] -= p ;
}
int cur = 0 ;
for(int i = 0 ; i < N; ++i){
cur += a[i] ;
if(cur > w){
cout << "No" ;
return 0 ;
}
}
cout << "Yes" ;
}
| #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using ll = long long int;
#define ss string
#define mod 1000000007
#define pi 3.14159265358979
#define rep(i,s,n) for(int i=(s);i<(int)(n);i++)
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
#define all(v) v.begin(),v.end()
#define co(x) cout << (x) << endl
#define ci(x) cin >> (x)
int main(){
int maxn=200010,n,w;cin>>n>>w;
vector<ll> time(maxn);
vector<ll> s(maxn),t(maxn);
rep(i,0,n){
int ts,tt,p;cin>>ts>>tt>>p;
s[ts]+=p;t[tt]+=p;
}
rep(i,0,maxn-1){
time[i+1]=time[i]+s[i]-t[i];
if(time[i]>w){co("No");return 0;}
}
co("Yes");
} |
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(a) a.begin(), a.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vv = vector<vi>;
using Graph = vector<vector<int>>;
template<class T> bool chmax(T& a, T b){ if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T& a, T b){ if (a > b) { a = b; return true; } return false; }
const ll mod = 1000000007;
const int INF = 100000000;
const double PI = acos(-1);
int main()
{
int x;
cin >> x;
if (x < 0) cout << 0 << endl;
else cout << x << endl;
} | #include <bits/stdc++.h>
#define ll long long
using namespace std;
int gcd(int x, int y) { return (x % y) ? gcd(y, x % y) : y; }
const double PI = 3.14159265358979323846;
int vector_finder(vector<int> vec, int number) {
auto itr = find(vec.begin(), vec.end(), number);
size_t index = distance(vec.begin(), itr);
if (index != vec.size()) { // 発見できたとき
return 1;
} else { // 発見できなかったとき
return 0;
}
}
unsigned GetDigit(unsigned num) { return log10(num) + 1; }
int main() {
int n = 0, cnt = 0;
cin >> n;
if (n % 2 == 0) {
cout << "White";
}
if (n % 2 == 1) {
cout << "Black";
}
}
/*vector<int> a;
int d;
for (int i = 0; i < n; i++) {
cin >> d;
a.push_back(d);
}*/
// g++ lo.cpp
// ./a.exe
// g++ -o つくりたいふぁいるめい もとのふぁいる.cpp
/*
for (int i = 0; i < n - 2; i++) {
for (int j = i + 1; j < n - 1; j++) {
int k = 2 * j - i;*/
/* vector<int>a(n);
cin>>a.at(n);*/
/* queue<long long> q;
for(i=0;i<n-1;i++){
pop = q.front();
if(pop%10!=0) q.push(pop*10 + pop%10 -1);
q.push(pop*10+pop%10);
if(pop%10 != 9) q.push(pop*10 + pop%10 + 1);
q.pop();
}*/
/*
int value = 4287;
int a[ 4 ];
a[0] = (value % 10); value /= 10; // 1桁目を取り出す7
a[1] = (value % 10); value /= 10; // 2桁目を取り出す8
a[2] = (value % 10); value /= 10; // 3桁目を取り出す2
a[3] = (value % 10); value /= 10; // 4桁目を取り出す4
*/
/*nCm
int n, m;
cin >> n >> m;
int N = 1, M = 1;
for (int i = 0; i < m; i++) {
N = N * (n - i);
}
for (int j = 0; j < m; j++) {
M = m * (m - j);
}
cout << N / M;
*/ |
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <queue>
#define CHECK_IMPL1(cond) \
if (!(cond)) { \
DEBUG("expected cond: " << #cond); \
assert(cond); \
}
#define CHECK_IMPL2(cond, message) \
if (!(cond)) { \
DEBUG("expected cond: " << #cond << " failed with message: " << message); \
assert(cond); \
}
#define CHECK_IMPL(_1, _2, NAME, ...) NAME
#define CHECK(...) CHECK_IMPL(__VA_ARGS__, CHECK_IMPL2, CHECK_IMPL1, CHECK_IMPL0)(__VA_ARGS__)
#ifdef __APPLE__
#define DEBUG(message) std::cerr << message << std::endl;
#else
#define DEBUG(message)
#endif
constexpr int kMod = 998244353;
constexpr int N = 100;
int mul(int64_t a, int64_t b) {
return a * b % kMod;
}
int add(int64_t a, int64_t b) {
int64_t c = a + b;
if (c >= kMod) {
c -= kMod;
}
if (c < 0) {
c += kMod;
}
return c;
}
int pow(int a, int n) {
int r = 1;
while (n) {
if (n & 1) {
r = mul(r, a);
}
a = mul(a, a);
n >>= 1;
}
return r;
}
int inv(int a) {
return pow(a, kMod - 2);
}
int fac[N];
int solve(std::vector<std::vector<int>> g) {
std::vector<int> cmp(g.size(), -1);
std::vector<int> sz;
for (int i = 0; i < g.size(); ++i) {
if (cmp[i] != -1) {
continue;
}
cmp[i] = sz.size();
sz.push_back(1);
std::vector<int> q = {i};
for (int j = 0; j < q.size(); ++j) {
int v = q[j];
for (auto to : g[v]) {
if (cmp[to] == -1) {
cmp[to] = cmp[v];
q.push_back(to);
++sz.back();
} else {
CHECK(cmp[to] == cmp[v]);
}
}
}
}
int ans = 1;
for (auto x : sz) {
ans = mul(ans, fac[x]);
}
return ans;
}
void solve() {
int n, k;
std::cin >> n >> k;
fac[0] = 1;
for (int i = 1; i < N; ++i) {
fac[i] = mul(fac[i - 1], i);
}
std::vector<std::vector<int>> a(n, std::vector<int>(n));
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
std::cin >> a[i][j];
}
}
std::vector<std::vector<int>> g_cols(n);
std::vector<std::vector<int>> g_rows(n);
for (int x = 0; x < n; ++x) {
for (int y = 0; y < n; ++y) {
if (x == y) {
continue;
}
{
bool bad = false;
for (int i = 0; i < n; ++i) {
if (a[i][x] + a[i][y] > k) {
bad = true;
break;
}
}
if (!bad) {
g_cols[x].push_back(y);
g_cols[y].push_back(x);
}
}
{
bool bad = false;
for (int i = 0; i < n; ++i) {
if (a[x][i] + a[y][i] > k) {
bad = true;
break;
}
}
if (!bad) {
g_rows[x].push_back(y);
g_rows[y].push_back(x);
}
}
}
}
std::cout << mul(solve(g_cols), solve(g_rows)) << '\n';
}
int main() {
#ifdef __APPLE__
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
#endif
int t = 1;
//std::cin >> t;
while (t--) {
solve();
}
return 0;
}
| #include<cstdio>
#define fo(i,a,b) for(int i=a;i<=b;i++)
const int N=55,mo=998244353;
int n,K,fac[N],a[N][N],f[N][N],g[N][N],s,ans=1;
bool vf[N],vg[N];
void T(int&x,int y) {x=1ll*x*y%mo;}
void dg(int x,int f[N][N],bool vf[N])
{
vf[x]=1; s++;
fo(y,1,n) if(!vf[y]&&f[x][y]) dg(y,f,vf);
}
int main()
{
scanf("%d%d",&n,&K);
fac[0]=1;
fo(i,1,n) fac[i]=1ll*fac[i-1]*i%mo;
fo(i,1,n) fo(j,1,n) scanf("%d",&a[i][j]);
fo(i,1,n-1) fo(j,i+1,n)
{
fo(k,1,n) if(a[i][k]+a[j][k]>K) goto RW;
f[i][j]=f[j][i]=1;
RW:fo(k,1,n) if(a[k][i]+a[k][j]>K) goto NE;
g[i][j]=g[j][i]=1;
NE:;
}
fo(i,1,n)
{
if(!vf[i]) s=0,dg(i,f,vf),T(ans,fac[s]);
if(!vg[i]) s=0,dg(i,g,vg),T(ans,fac[s]);
}
printf("%d",ans);
} |
#include<bits/stdc++.h>
#define SZ(x) ((int)x.size())
#define uni(x) sort(all(x)),x.resize(unique(all(x))-x.begin());
#define GETPOS(c,x) (lower_bound(all(c),x)-c.begin())
#define lown1(x,val) low(in(x),val)-x
#define lowm1(x,val) low(im(x),val)-x
#define low1(x,nums,val) low(x+1,x+nums+1,val)-x
#define mst(x,val) memset((x),val,sizeof((x)))
#define ls rt<<1
#define rs rt<<1|1
#define lson rt<<1,l,M
#define rson rt<<1|1,M+1,r
#define PI acos(-1)
#define MM int M=(l+r)>>1;
#define fu(i,r,t) for(int i=r;i<=t;i++)
#define fd(i,r,t) for(int i=r;i>=t;i--)
#define fh(i,be,e) for(int i=head[be];~i;i=e[i].next)
#define fa(i,V) for(auto i:V)
#define far(i,V) for(auto &i:V)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define lcm(a,b) ((a)*(b))/__gcd(a,b)
#define cp(i,ans) printf("%.if",ans);
#define cpp(i,ans) cout<<setprecision(i)<<fixed<<ans<<endl;
#define ppb pop_back
#define ppf pop_front
#define pb push_back
#define pf push_front
#define pq priority_queue
#define lowbit(x) ((x)&(-x))
#define all(V) V.begin(),V.end()
#define ms multiset
#define mod(x) (((x)<0)?(x)%mo_num+mo_num:(x)%mo_num)
#define vc vector
#define vct vector<int>
#define out(i) cout<<(i)<<endl;
#define fi first
#define se second
#define fun(i) fu(i,1,n)
#define fut(i) fu(i,1,t)
#define fum(i) fu(i,1,m)
#define ld long double
#define umap unordered_map
#define Umap unordered_map<int,int>
#define P pair<int,int>
#define SET set<int>
#define mk make_tuple
#define eps 1e-6
//Remember cancel"#define endl '\n'" in interactive questions or use "<<flush"
#define endl '\n'
#define low lower_bound
#define upp upper_bound
#define yn(key) out(key?"YES":"NO")
//#define yn(key) out(key?"Yes":"No")
#define in(i) i+1,i+1+n
#define im(i) i+1,i+1+m
#define ik(i,k) i+1,i+1+k
#define bffs(i) __builtin_ffs(i)
#define bcount(i) __builtin_popcount(i)
#define bone(i) ((1<<i)-1)
#define db double
#define ll long long
#define got(container,num) get<num-1>(container)
#define int long long
#define print(a,n) fun(i)cout<<a[i]<<(i!=n?' ':endl);
#define outcase(x) cout<<"Case #"<<(++case_of_T)<<": "<<(x)<<endl;
#define ptcase(x) printf("Case #%d: %d\n",++case_of_T,x);
#define plcase(x) printf("Case #%lld: %lld\n",++case_of_T,x);
using namespace std;
//Remember to cancel the line below and declare INT=INT_MAX/2; when you want to change long to int
const int INF=LLONG_MAX/4,SINF=0x3f3f3f3f,Lim=1<<20,MINF=LLONG_MAX;
//const int INF=INT_MAX/4,SINF=0x3f;
// use C:printf("%.16f", x); -> printf("%.10f", x); can accelerate the program
const int dx[]={0,0,-1,1},dy[]={-1,1,0,0};//down up left right
const int maxn=1e6+1e5;
int mo_num=1e9+7;
//const int mo_num=998244353;
int n,m,t,a[maxn],b[maxn],ans,case_of_T;
void solve()
{
int A,B;
cin>>n>>A>>B;
if(n<A+B)out(0)
else{
m=n+2-A-B;
int C=mod(m*(m-1)/2);
ans=mod(4*mod(mod((n-A+1)*(n-B+1))*C));
ans=mod(ans-mod(4*C*C));
out(ans)
}
return ;
}
main()
{
IOS
int T=1;
cin>>T;
while(T--)solve();
return 0;
}
| //面倒くさがらずに実験したらすぐ分かった…
//all - NG * NGの形にして、1次元の問題でNGを数える。
//A, Bを置く位置x, y(0≦x, y≦N-1)を考えると
//0 ≦ x ≦ N - A
//0 ≦ y ≦ N - B
//y - A + 1 ≦ x ≦ y + B - 1
//なる(x, y)を数えたくなるので、そういう(x, y)を表示してみる。(実験)
//A + B > Nのときは、(N + 1 - A) * (N + 1 - B)個全てが埋まる.
//A + B <= Nのとき、
//1辺len = N + 1 - A - Bの二等辺三角形2つを引けばよい.
//ただし、二等辺三角形の面積は1 + … + lenなことに注意(離散的なので)
//(N + 1 - A) * (N + 1 - B) - (len + 1) * len個.
#include <iostream>
#define int long long
using namespace std;
int mod = 1000000007;
signed main() {
int T;
cin >> T;
while (T--) {
int n, a, b;
cin >> n >> a >> b;
int all = (n - a + 1) * (n - a + 1) % mod * (n - b + 1) % mod * (n - b + 1) % mod;
int ng;
if (a + b > n) ng = (n + 1 - a) * (n + 1 - b);
else ng = (n + 1 - a) * (n + 1 - b) - (n + 2 - a - b) * (n + 1 - a - b);
ng %= mod;
int ans = (all - ng * ng % mod + mod) % mod;
cout << ans << endl;
}
return 0;
} |
#include <iostream>
#include <cmath>
using namespace std;
int n;
double x0, z0, xn, zn, rx, ry, dx, dy, theta, c, s;
int main(){
cin >> n;
cin >> x0 >> z0 >> xn >> zn;
rx = (x0 + xn)/2.0;
ry = (z0 + zn)/2.0;
dx = x0 - rx;
dy = z0 - ry;
c = cos(M_PI*2.0/n);
s = sin(M_PI*2.0/n);
// cout << rx << " " << ry << endl;
// cout << c << " " << s << endl;
// cout << dx << " " << dy << endl;
printf("%9lf %9lf", rx +c*dx - s*dy, ry +s*dx + c*dy);
// cout << rx +c*dx - s*dy << " " << rx +c*dx - s*dy<<endl;
}
| #include <bits/stdc++.h>
#pragma region my_template
struct Rep {
struct I {
int i;
void operator++() { ++i; }
int operator*() const { return i; }
bool operator!=(I o) const { return i < *o; }
};
const int l_, r_;
Rep(int l, int r) : l_(l), r_(r) {}
Rep(int n) : Rep(0, n) {}
I begin() const { return {l_}; }
I end() const { return {r_}; }
};
struct Per {
struct I {
int i;
void operator++() { --i; }
int operator*() const { return i; }
bool operator!=(I o) const { return i > *o; }
};
const int l_, r_;
Per(int l, int r) : l_(l), r_(r) {}
Per(int n) : Per(0, n) {}
I begin() const { return {r_ - 1}; }
I end() const { return {l_ - 1}; }
};
template <class F>
struct Fix : private F {
Fix(F f) : F(f) {}
template <class... Args>
decltype(auto) operator()(Args&&... args) const {
return F::operator()(*this, std::forward<Args>(args)...);
}
};
template <class T = int>
T scan() {
T res;
std::cin >> res;
return res;
}
template <class T, class U = T>
bool chmin(T& a, U&& b) {
return b < a ? a = std::forward<U>(b), true : false;
}
template <class T, class U = T>
bool chmax(T& a, U&& b) {
return a < b ? a = std::forward<U>(b), true : false;
}
#ifndef LOCAL
#define DUMP(...) void(0)
template <int OnlineJudge, int Local>
constexpr int OjLocal = OnlineJudge;
#endif
using namespace std;
#define ALL(c) begin(c), end(c)
#pragma endregion
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
cout << fixed << setprecision(20);
int64_t ans = 0;
for (int n = scan(); n--;) {
int64_t a = scan();
int64_t b = scan();
ans += (a + b) * (b - a + 1) / 2;
}
cout << ans << '\n';
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pll;
#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(40)
const ll MOD = 1000000007;
const ll INF = (ll) 1e15;
bool solve(vector<ll> &A) {
ll N = A.size();
vector<ll> ans;
REP(i, N * N) {
bool sorted = true;
REP(j, N - 1) {
if (A[j] > A[j + 1]) {
sorted = false;
break;
}
}
if (sorted)
break;
bool update = false;
REP(j, N) {
if (i % 2 != j % 2)
continue;
if (j + 1 >= N)
break;
if (A[j] > A[j + 1]) {
update = true;
swap(A[j], A[j + 1]);
ans.push_back(j);
break;
}
}
if (!update) {
for (ll j = N - 2; j >= 0; --j) {
if (j % 2 == i % 2) {
swap(A[j], A[j + 1]);
ans.push_back(j);
break;
}
}
}
#if false
REP(j, N) {
cout << A[j] << " ";
}
cout << endl;
#endif
}
cout << ans.size() << endl;
REP(i, ans.size()) {
cout << ans[i] + 1 << " ";
}
cout << endl;
{
bool sorted = true;
REP(j, N - 1) {
if (A[j] > A[j + 1]) {
sorted = false;
break;
}
}
return sorted;
}
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
#if true
ll Q;
cin >> Q;
REP(_, Q) {
ll N;
cin >> N;
vector<ll> A(N);
REP(i, N) {
cin >> A[i];
}
if (!solve(A)) {
assert(false);
}
}
#else
vector<ll> A;
ll N = 8;
REP(i, N) {
A.push_back(i + 1);
}
do {
vector<ll> v;
REP(i, N) {
v.push_back(A[i]);
}
if (!solve(v)) {
assert(false);
}
} while (next_permutation(A.begin(), A.end()));
#endif
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
int main(){
ll n;
cin >> n;
while(n % 2 == 0){
n /= 2;
}
ll sq = sqrt(n);
ll ans = 0;
for(ll i = 1;i <= sq;i++){
if(n % i == 0){
ans += 2;
}
}
if(sq*sq == n) ans--;
cout << ans*2 << endl;
} |
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
const int MAX_T = 200005;
int main() {
int N, X;
cin >> N >> X;
string S;
cin >> S;
int score = X;
for (char s : S) {
score += (s == 'o' ? 1 : -1);
maxs(score, 0);
}
cout << score << endl;
return 0;
}
| #include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
long long a[100010];
vector<pair<long long, int>> vec;
int main() {
long long k, n, m, sum = 0;
cin >> k >> n >> m;
for (int i = 0; i < k; i++) {
cin >> a[i];
long long a1 = a[i] * m / n;
sum += a1;
vec.emplace_back(make_pair(a[i] * m - n * a1, i));
a[i] = a1;
}
sort(vec.rbegin(), vec.rend());
for (int i = 0; i < m - sum; i++) {
a[vec[i].second]++;
}
for (int i = 0; i < k; i++) {
cout << a[i] << " ";
}
cout << endl;
} |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 10000000000000007;
const long long mod = 1000000007;
typedef long long ll;
typedef pair<int, int> P;
template<class T> bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
vector<int> table(2500);
vector<vector<int>> tile(2500);
vector<vector<bool>> seen(50,vector<bool>(50,0));
vector<vector<int>>point(50,vector<int>(50));
int now_x, now_y;
int si, sj;
// ll sum = 0;
vector<int> dx = {1, 0, -1, 0};
vector<int> dy = {0, 1, 0, -1};
vector<int>ans;
void solve(int now_x, int now_y) {
while (1) {
int num = table[now_x+now_y*50];
for (int j = 0; j < tile[num].size(); j++) {
int k = tile[num][j];
seen[k/50][k%50] = 1;
}
int nx,ny,index=-1;
ll ma = -1;
for (int i = 0; i < 4; i++) {
nx = now_x + dx[i];
ny = now_y + dy[i];
if (nx<0||nx>=50||ny<0||ny>=50) continue;
if (seen[ny][nx]==1) continue;
ll score = 0;
if (i==0) score += 50-now_x;
else if (i==1) score += 50-now_y;
else if (i==2) score += now_x;
else if (i==3) score += now_y;
score += point[ny][nx] / 10;
if (chmax(ma, score)) {
index = i;
}
}
if (index==-1) break;
now_x = now_x + dx[index];
now_y = now_y + dy[index];
ans.push_back(index);
}
return;
}
int main()
{
cin >> sj >> si;
now_x = si;
now_y = sj;
for (int i = 0; i < 2500; i++) {
int num;
cin >> num;
table[i] = num;
tile[num].push_back(i);
}
for (int i = 0; i < 2500; i++) {
int x = i%50;
int y = i/50;
cin >> point[y][x];
}
solve(now_x, now_y);
// 出力
for (int i = 0; i < ans.size(); i++) {
if (ans[i]==0) cout << 'R';
else if (ans[i]==1) cout << 'D';
else if (ans[i]==2) cout << 'L';
else if (ans[i]==3) cout << 'U';
}
cout << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int H, W;
cin >> H >> W;
char X[H][W];
string S;
for (int i = 0; i < H; i++) {
cin >> S;
for (int j = 0; j < W; j++) {
X[i][j] = S.at(j);
}
}
int count = 0;
for (int i = 0; i < H - 1; i++) {
for (int j = 0; j < W - 1; j++) {
if (X[i][j] == '.') {
if (X[i + 1][j] == '.') {
count++;
}
if (X[i][j + 1] == '.') {
count++;
}
}
}
}
for (int i = 0; i < H - 1; i++) {
if (X[i][W-1] == '.' && X[i+1][W-1] == '.') {
count++;
}
}
for (int i = 0; i < W - 1; i++) {
if (X[H-1][i] == '.' && X[H-1][i+1] == '.') {
count++;
}
}
cout << count << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef DEBBY
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define ll long long
#define rep(i,a,b) for(int i=int(a); i<=int(b); i++)
#define print_mat(i,j,a,b,v) for(int i=0;i<a;i++){for(int j=0;j<b;j++)cerr<<v[i][j] << " "; cerr<<endl;}
#define sz(v) (int)(v).size()
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define pi pair<int,int>
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define vpi vector<pi>
#define pq priority_queue<int>
#define pqg priority_queue<int, vi, greater<int> >
#define fs first
#define sd second
#define pb push_back
#define eb emplace_back
void solve(){
string s;
cin >> s;
int j=sz(s)-1;
while(j>=0 and s[j]=='0')
j--;
j++;
for(int i=0; i<j/2; i++){
if(s[i]!=s[j-i-1]){
cout << "No"; return;
}
}
cout << "Yes";
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
void DBG() { cerr << endl; }
template<class Head, class... Tail>
void DBG(Head H, Tail... T) { cerr << ' ' << H; DBG(T...); }
#define dbg(...) cerr << "(" << (#__VA_ARGS__) << "):", DBG(__VA_ARGS__)
using ll = long long;
using ld = long double;
#define sqr(a) ll(a) * (a)
#define siz(a) int(a.size())
#define ints(a...) int a; read(a)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define trav(i, v) for (const auto i : v)
#define fill(a, b) memset(a, b, sizeof(a))
#define rep(i, b, n) for (auto i = b; i < n; i++)
#define per(i, b, n) for (auto i = b; i >= n; i--)
#define unify(a) sort(all(a)); a.resize(unique(all(a)) - a.begin())
template <class T> using vec = vector<T>;
template <class... Args> inline void read(Args&... args) { ((cin >> args), ...); }
template <class... Args> inline void show(Args... args) { ((cout << args << " "), ...); }
template <class T1, class T2> inline bool ckmin(T1 &a, T2 b) { return a > b ? a = b, 1 : 0; }
template <class T1, class T2> inline bool ckmax(T1 &a, T2 b) { return a < b ? a = b, 1 : 0; }
template <class T> inline void operator>> (istream& in, vector<T>& v) { rep(i, 0, siz(v)) in >> v[i]; }
template <class T> inline void operator<< (ostream& out, const vector<T>& v) { rep(i, 0, siz(v)) out << v[i] << " \n"[i + 1 == siz(v)]; }
const int MOD = 1e9 + 7;
const int N = 101;
ld dp[N][N][N];
ld f(int a, int b, int c) {
if (a == 100 || b == 100 || c == 100)
return 0;
if (dp[a][b][c] >= 0)
return dp[a][b][c];
ld res = 1, sum = a + b + c;
res += a * f(a + 1, b, c) / sum;
res += b * f(a, b + 1, c) / sum;
res += c * f(a, b, c + 1) / sum;
return dp[a][b][c] = res;
}
void solve() {
ints(a, b, c);
fill(dp, -1);
cout << f(a, b, c);
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(12);
cerr << fixed << setprecision(12);
int _ = 1;
// cin >> _;
rep(i, 1, _ + 1) {
// printf("Case %d: ", i);
// Solution solve;
solve();
}
return 0;
} |
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define reps(i,s,n) for(int i=s;i<n;++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int M = 1e5;
int main()
{
int n;
cin >> n;
vector<int> t(n);
rep(i, n) cin >> t[i];
int sum = 0;
rep(i, n) sum += t[i];
//for文でMまで探索するので、M+1000でもはみ出さないようにする。
vector<vector<int>> dp(n + 5, vector<int>(M+1005));
dp[0][0] = 1;
rep(i, n)
{
rep(j, M)
{
dp[i + 1][j] = dp[i][j] | dp[i + 1][j];
dp[i + 1][j + t[i]] = dp[i][j] | dp[i + 1][j + t[i]];
}
}
int ans = M;
rep(i, M)
{
if (dp[n][i] == 1)
{
int a = i;
int b = sum - i;
ans = min(ans, max(a, b));
}
}
cout << ans << endl;
return 0;
}
| /*
__
/\ \
_ __ ___ ___\ \ \/'\ ___ __ ___ ___ __
/\`'__\/ __`\ /'___\ \ , < / __`\ /'__`\ /' _ `\ /' _ `\ /'__`\
\ \ \//\ \L\ \/\ \__/\ \ \\`\ /\ \L\ \/\ \L\.\_/\ \/\ \/\ \/\ \/\ \L\.\_
\ \_\\ \____/\ \____\\ \_\ \_\ \____/\ \__/.\_\ \_\ \_\ \_\ \_\ \__/.\_\
\/_/ \/___/ \/____/ \/_/\/_/\/___/ \/__/\/_/\/_/\/_/\/_/\/_/\/__/\/_/
*/
#ifndef __AHA__HEADER
#define __AHA__HEADER
#include <bits/stdc++.h>
using namespace std;
#define g0 get<0>
#define g1 get<1>
#define g2 get<2>
#define ft first
#define sd second
#define sz(x) (i6) x.size()
#define psb(x) push_back(x)
#define ppb() pop_back()
#define bg(x) x.begin()
#define ed(x) x.end()
#define col(x) x.begin(), x.end()
#define srt(x) sort(x.begin(), x.end())
#define vec vector
#define deq deque
#define hmap unordered_map
#define pq priority_queue
#define fn function
#ifdef LOCAL
#define git stauDBG_MACRO_NO_WARNING
#include <dbg.h>
#define dbgt dbg(dbg::time())
#else
#define dbg(...)
#define dbgt
#endif
typedef string str;
typedef int32_t i3;
typedef int64_t i6;
typedef int64_t i64;
typedef uint32_t u3;
typedef uint64_t u6;
typedef long double d6;
typedef pair<i6, i6> p6;
typedef vec<i6> vi6;
typedef vec<p6> vp6;
typedef vec<bool> vb;
typedef vec<vi6> vv;
typedef deq<p6> dp6;
typedef deq<i6> di6;
typedef map<i6, i6> mi6;
typedef map<p6, i6> mp6;
typedef set<i6> si6;
typedef hmap<i6, i6> hi6;
typedef vv graph;
typedef vv matrix;
const i6 INF = INT64_MAX / 4;
const i6 NINF = -INF;
const i6 ZERO = 0;
const i6 ONE = 1;
#endif
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifdef LOCAL
ifstream cin{"input.txt"};
ofstream cout{"output.txt"};
#endif
i64 h, w;
cin >> h >> w;
vv v(h, vi6(w));
for (i64 i = 0; i < h; i++) {
string s;
cin >> s;
for (i64 j = 0; j < w; j++) {
if (s[j] == '.') {
v[i][j] = 0;
} else {
v[i][j] = 1;
}
}
}
i64 res = 0;
for (i64 i = 1; i < h; i++) {
for (i64 j = 1; j < w; j++) {
i64 x = 0;
if (v[i][j - 1] == 0) {
x += 1;
}
if (v[i - 1][j - 1] == 0) {
x += 1;
}
if (v[i - 1][j] == 0) {
x += 1;
}
if (v[i][j] == 0) {
x += 1;
}
if (x % 2 == 1) {
res += 1;
}
}
}
cout << res << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main(){
int r1, c1, r2, c2;
cin >> r1 >> c1 >> r2 >> c2;
int r = r2 - r1, c = c2 - c1;
int ans = 3;
if(!r && !c) ans = 0;
else if(r == c || r == -c || abs(r) + abs(c) <= 3) ans = 1;
else if((r ^ c ^ 1) & 1 || abs(r + c) <= 3 || abs(r - c) <= 3 || abs(r) + abs(c) <= 6) ans = 2;
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int A[3];
for (int i = 0; i < 3; i++) cin >> A[i];
int p[3] = {0, 1, 2};
bool res = false;
do {
if (A[p[2]] - A[p[1]] == A[p[1]] - A[p[0] ]) res = true;
} while (next_permutation(p, p + 3));
if (res) cout << "Yes";
else cout << "No";
} |