code_file1
stringlengths 87
4k
| code_file2
stringlengths 82
4k
|
---|---|
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int main() {
int h, w; cin >> h >> w;
string s[h];
REP(i, h) cin >> s[i];
int res = 0;
REP(i, h-1) REP(j, w-1) {
int cnt = 0;
REP(x, 2) REP(y, 2)
if (s[i+y][j+x] == '#') cnt++;
if (cnt%2) res++;
}
cout << res << '\n';
return 0;
}
| #include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define P pair<ll,ll>
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
#define fi first
#define se second
#define set20 cout<<fixed<<setprecision(20) ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
double pi=acos(-1) ;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
ll dp[1005][1005] ;
int main(){
ll n,m ; cin>>n>>m ;
vector<ll> A(n),B(m) ;
rep(i,n) cin>>A[i] ;
rep(i,m) cin>>B[i] ;
rep(i,1005) dp[i][0]=i ;
rep(i,1005) dp[0][i]=i ;
rep2(i,1,n)rep2(j,1,m){
ll p=dp[i-1][j-1] ;
if(A[i-1]!=B[j-1]) p++ ;
dp[i][j]=min(min(dp[i-1][j],dp[i][j-1])+1,p) ;
}
cout<<dp[n][m]<<endl ;
return 0 ;
} |
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
using namespace std;
int R, C;
long long int A[520][520], B[520][520];
long long int INF = 99999999999999;
long long int dis[300000];
vector<int> Adj[300000];
vector<long long int> cost[300000];
priority_queue < pair<long long int, int> > PQ;
int used[300000];
int main(void) {
cin >> R >> C;
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];
}
}
int N = R*C;
dis[0] = 0;
for (int i = 1; i <= R*C; i++) { dis[i] = INF; }
for (int i = 0; i <= R - 1; i++) {
for (int j = 0; j <= C - 2; j++) {
int k = i*C + j;
int u = i*C + j + 1;
Adj[k].push_back(u);
cost[k].push_back(A[i][j]);
}
}
for (int i = 0; i <= R - 1; i++) {
for (int j = 1; j <= C - 1; j++) {
int k = i*C + j;
int u = i*C + j - 1;
Adj[k].push_back(u);
cost[k].push_back(A[i][j-1]);
}
}
for (int i = 0; i <= R - 2; i++) {
for (int j = 0; j <= C - 1; j++) {
int k = i*C + j;
int u = (i + 1)*C + j;
Adj[k].push_back(u);
cost[k].push_back(B[i][j]);
}
}
for (int i = 1; i <= R - 1; i++) {
for (int j = 0; j <= C - 1; j++) {
int k = i*C + j;
for (int y = 0; y <= i - 1; y++) {
int u = y*C + j;
Adj[k].push_back(u);
cost[k].push_back(i - y + 1);
}
}
}
PQ.push(make_pair(dis[0], 0)); used[0] = 1;
int g = (R - 1)*C + C - 1;
pair<long long int, int> tmp;
while (PQ.size() > 0) {
tmp = PQ.top();
PQ.pop();
long long int D = -tmp.first;
int pos = tmp.second;
used[pos] = 1;
if (dis[pos] != D) { continue; }
if (pos == g) { break; }
for (int v = 0; v < (int)Adj[pos].size();v++) {
int y = Adj[pos][v];
if (used[y] != 0) { continue; }
if (D + cost[pos][v] < dis[y]) {
dis[y] = D + cost[pos][v];
PQ.push(make_pair(-dis[y], y));
}
}
}
cout << dis[g]<< endl;
return 0;
}
| #ifdef _DEBUG
#define _GLIBCXX_DEBUG
#endif
#if __has_include(<atcoder/all>)
#include <atcoder/all>
#endif
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
#define rep(i, a, b) for(int i = (int)(a); i <= (int)(b); i++)
#define rrep(i, a, b) for(int i = (int)(a); i >= (int)(b); i--)
const int MOD = 1000000007;
const int MOD2 = 998244353;
const ll INF = 1e18;
const ld PI = acos(-1);
struct edge{
int to,cost;
};
const int MXV = 1000000;//変更可
vector<edge> G[MXV];
vector<int> d(MXV, 1e9);
void dijkstra(int s){
using Pair_for_edge = pair<int,int>;
priority_queue<Pair_for_edge, vector<Pair_for_edge>, greater<Pair_for_edge>> pq;
d[s] = 0;
pq.push(Pair_for_edge(0, s));
while(pq.size()){
Pair_for_edge p = pq.top();
pq.pop();
int V = p.second;
if(d[V] < p.first){
continue;
}
rep(i,0,G[V].size()-1){
edge e = G[V][i];
if(d[e.to] > d[V] + e.cost){
d[e.to] = d[V] + e.cost;
pq.push(P(d[e.to], e.to));
}
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int R,C;
cin >> R >> C;
vector<vector<int>> A(R,vector<int>(C-1)),B(R-1,vector<int>(C));
rep(i,0,R-1){
rep(j,0,C-2){
cin >> A[i][j];
int v=i+1000*j,u=i+1000*(j+1);
edge e;
e.cost=A[i][j];
e.to=u;
G[v].push_back(e);
e.to=v;
G[u].push_back(e);
}
}
rep(i,0,R-2){
rep(j,0,C-1){
cin >> B[i][j];
int v=i+1000*j,u=i+1+1000*j;
edge e;
e.cost=B[i][j];
e.to=u;
G[v].push_back(e);
e.to=v;
e.cost=2;
while((1000+e.to)%1000!=999){
G[u].push_back(e);
//cout << e.cost << endl;
e.cost++;
e.to--;
}
}
}
dijkstra(0);
cout << d[(R-1)+1000*(C-1)] << endl;
} |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define inF freopen("input.txt", "r", stdin);
#define outF freopen("output.txt", "w", stdout);
#define endl '\n'
#define MOD 1000000007
#define mm(arr) memset(arr, 0, sizeof(arr))
#define F first
#define S second
#define scanArray(a,n) for(int i = 0; i < n; i++){cin >> a[i];}
#define coutArray(a,n) for(int i = 0; i < n; i++){cout << a[i] << " ";}cout << endl;
#define ld long double
#define PI 3.141592653589793238
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
#define int ll
#ifndef LOCAL
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#endif
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << '\n'; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
int fastpow(int v, int p){
if (p == 0)return 1;
if (p == 1)return v;
int ans = fastpow(v, p/2);
if (p&1)return (((ans%MOD) * (ans%MOD)%MOD) * (v%MOD))%MOD;
else return ((ans%MOD) * (ans%MOD))%MOD;
}
void solve(){
int n, p; cin >> n >> p;
int ans = p - 1;
ans *= fastpow(p - 2, n - 1);
ans %= MOD;
cout << ans << endl;
}
int32_t main(){
FAST
int t = 1;
//cin >> t;
while(t--){
solve();
}
return 0;
}
| #include<bits/stdc++.h>
#define int ll
#define sz(x) int((x).size())
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define x first
#define y second
using namespace std;
using ll = long long;
using pi = pair<int,int>;
const int inf = 0x3f3f3f3f3f3f3f3f;
const int minf = 0xc0c0c0c0c0c0c0c0;
const int mod = 1e9+7;
int pw(int a, int b) {
if (b == 0) return 1;
if (b == 1) return a;
int h = pw(a, b>>1);
if (b & 1) return h*h%mod*a%mod;
return h*h%mod;
}
signed main() {
ios::sync_with_stdio(0); cin.tie(0);
int n,p;
cin>>n>>p;
cout<<pw(p-2, n-1)*(p-1)%mod<<'\n';
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long i64;
typedef unsigned long long ui64;
typedef vector<i64> vi;
typedef vector<vi> vvi;
typedef pair<i64, i64> pi;
#define pb push_back
#define sz(a) i64((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)
inline void RI(i64 &i) {scanf("%lld", &(i));}
inline void RVI(vi &v) { for(i64 i=0;i<sz(v);++i) { RI(v[i]); } }
inline void RVVI(vvi &vv) { for(i64 i=0;i<sz(vv);++i) { RVI(vv[i]); } }
inline void WI(const i64 &i) {printf("%lld\n", i);}
inline void WVI(const vi &v, char sep=' ') { for(i64 i=0;i<sz(v);++i) { if(i != 0){ printf("%c", sep); } printf("%lld", v[i]);} printf("\n"); }
inline void WS(const string &s) { printf("%s\n", s.c_str()); }
inline void WB(bool b, const string &yes, const string &no) { if(b){ WS(yes);} else { WS(no);} }
inline void YESNO(bool b) { WB(b, "YES", "NO"); }
inline void YesNo(bool b) { WB(b, "Yes", "No"); }
#define BUF_LENGTH 1000000
inline void RS(string &s) {static char buf[BUF_LENGTH]; scanf("%s", buf); s = buf;}
template<typename T> inline bool IN(T &S, const typename T::key_type &key) {
return S.find(key) != S.end();
}
template<typename T> inline bool ON(const T &b, i64 idx) {
return ((T(1) << idx) & b) != 0;
}
template<long long M, typename T=long long>
struct modint {
modint(T v=T(0)) : val((v >= 0 ? v : (M - ((-v) % M))) % M) {}
using this_type = modint<M, T>;
T val;
this_type operator++(int) {
this_type ret = *this;
val++; val %= M;
return ret;
}
this_type operator--(int) {
this_type ret = *this;
val += M-1; val %= M;
return ret;
}
this_type &operator++() {
val++; val %= M;
return *this;
}
this_type &operator--() {
val += M-1; val %= M;
return *this;
}
this_type operator+() const { return *this; }
this_type operator-() const { return this_type(M-val); };
friend this_type operator+(const this_type &lhs, const this_type &rhs) {
return this_type(lhs) += rhs;
}
friend this_type operator-(const this_type &lhs, const this_type &rhs) {
return this_type(lhs) -= rhs;
}
friend this_type operator*(const this_type &lhs, const this_type &rhs) {
return this_type(lhs) *= rhs;
}
friend this_type operator/(const this_type &lhs, const this_type &rhs) {
return this_type(lhs) /= rhs;
}
this_type pow(long long b) const {
this_type ret = 1, a = *this;
while(b != 0) {
if(b % 2 != 0) {
ret *= a;
}
b /= 2;
a = a * a;
}
return ret;
}
this_type inv() const {
return pow(M-2);
}
this_type& operator+=(const this_type &rhs) {
val += rhs.val; val %= M; return *this;
}
this_type& operator-=(const this_type &rhs) {
val += M - rhs.val; val %= M; return *this;
}
this_type& operator*=(const this_type &rhs) {
val *= rhs.val; val %= M; return *this;
}
this_type& operator/=(const this_type &rhs) {
*this *= rhs.inv(); return *this;
}
friend bool operator==(const this_type &lhs, const this_type &rhs) {
return lhs.val == rhs.val;
}
friend bool operator!=(const this_type &lhs, const this_type &rhs) {
return lhs.val != rhs.val;
}
T mod() const {return M;}
};
using mi = modint<1000000007>;
using vmi = vector<mi>;
using vvmi = vector<vmi>;
int main(int argc, char *argv[]) {
i64 i, j, k;
i64 N, M; cin >> N >> M;
vi A(N); RVI(A);
i64 S = accumulate(all(A), 0LL);
mi ans = 1;
REP(0, S+N, i) {
ans *= (N + M - i);
ans /= i + 1;
}
WI(ans.val);
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
const int N=3e5+5;
int n,m,k,cnt,tot,cas,ans;
int a[N];
bool vis[N];
char s[N];
#define ll long long
long long qmi(long long a,long long b)
{
long long ans=1;
while(b){
if(b&1) ans=ans*a%mod;
b>>=1;a=a*a%mod;
}
return ans;
}
ll C(ll n,ll r)
{
if(r>n||r<0) return 0;
ll fz=1,fm=1;
for(int i=1;i<=r;i++)
fz=fz*(n-i+1)%mod,fm=fm*i%mod;
return fz*qmi(fm,mod-2)%mod;
}
int main()
{
long long sum=0;
cin>>n>>m;
for(int i=1;i<=n;i++)
cin>>a[i],sum+=a[i];
printf("%lld\n",C(n+m,sum+n));
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb emplace_back
#define pii pair<int , int>
#define F first
#define S second
const int mod = 1000000007;
const int MAXX = 1e5 + 5;
const int N = 1e5;
int t , n , m;
int a[MAXX];
signed main()
{
_FastIO;
cin >> n;
a[1] = 1;
for(int i = 2; i <= n; i++){
int cnt = 1;
for(int j = 1; (j * j) <= i; j++){
if(i % j == 0){
cnt = max(cnt , a[j]);
cnt = max(cnt , a[i / j]);
}
}
a[i] = cnt + 1;
}
for(int i = 1; i <= n; i++){
cout << a[i] << " ";
}
cout << endl;
return 0;
}
| #include<bits/stdc++.h>
#define int long long
int n,now,ans;
using namespace std;
signed main()
{
scanf("%lld",&n);
int p=sqrt((n+1)*2);
while(p*(p+1)/2<=n+1)
{
p++;
}
p--;
//cout<<p<<endl;
//if(p*p==n*2) p--;
//cout<<p<<endl;
printf("%lld\n",n-p+1);
return 0;
} |
#include <iostream>
#include <deque>
#include <climits>
#include <cmath>
using namespace std;
int main() {
int N;
std::cin >> N;
double x0, y0, xh, yh;
std::cin >> x0 >> y0 >> xh >> yh;
double dx = x0 - (x0 + xh) / 2;
double dy = y0 - (y0 + yh) / 2;
double ox = cos(M_PI * 2 / N);
double oy = sin(M_PI * 2 / N);
double x1 = dx * ox - dy * oy + (x0 + xh) / 2;
double y1 = dy * ox + dx * oy + (y0 + yh) / 2;
std::cout << x1 << ' ' << y1 << std::endl;
// std::deque<int> A;
// for (int i = 0; i < N; i++) {
// int n;
// std::cin >> n;
// A.push_back(n);
// }
// // std::cout << N << std::endl;
// // for (int i = 0; i < A.size(); i++) {
// // std::cout << i << std::endl;
// // }
// const int result = search(0, A);
// std::cout << result << std::endl;
return 0;
}
| /** P L E X I U S ** 2021 Jan 29 17:22:53 **/
#include<bits/stdc++.h>
using namespace std;
#define int long long
void solve(){
int n; cin>>n;
int cnt = 0;
for(int i= 1; i*(i+1)<=2*n; i++) {
if((n-i*(i-1)/2)%i==0) cnt++;
}
cout<<cnt*2<<"\n";
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int t = 1;
while(t--) solve();
}
|
#include <bits/stdc++.h>
using namespace std;
long long multi(string x){
long long a,i,minus,multiple=10000,n=x.size();
a=0;
if(x[0]=='-'){
minus=-1;
i=1;
}else{
minus=1;
i=0;
}
while(i<n){
if(x[i]=='.'){
i++; continue;
}else{
a=a*10+(x[i]-'0');
i++;
}
}
if(n>=2 && x[n-2]=='.'){
multiple=1000;
}else if(n>=3 && x[n-3]=='.'){
multiple=100;
}else if(n>=4 && x[n-4]=='.'){
multiple=10;
}else if(n>=5 && x[n-5]=='.'){
multiple=1;
}else{
multiple=10000;
}
return minus*a*multiple;
}
int main() {
long long n,i,j,a,b,c,cur,lef,rig,ans;
string x,y,r;
cin >> x >> y >> r;
a=multi(x); b=multi(y); c=multi(r);
a=abs(a); b=abs(b);
//a=x*10000; b=y*10000; c=r*10000;
//cout << a <<' '<< b << ' '<< c << endl;
/*
lef=((a-c+10000000000+9999)/10000)*10000-10000000000;
rig=((a+c+10000000000)/10000)*10000-10000000000;
ans=0;
for(i=lef; i<=rig; i+=10000){
cur=floor(sqrt(c*c-abs(a-i)*abs(a-i)));
//cout << i << ' ' << cur << endl;
ans+=((b+cur+10000000000)/10000)-((b-cur+10000000000+9999)/10000)+1;
}
cout << ans << endl;
*/
ans=0;
long long ok,ng,mid,res;
for(i=-300000; i<=300000; i++){
if(abs(i*10000-a)<=c){
res=c*c-abs(i*10000-a)*abs(i*10000-a);
ok=-1; ng=10000000000;
while(ng-ok>1){
mid=(ok+ng)/2;
if(mid*mid<=res){
ok=mid;
}else{
ng=mid;
}
}
ans+=(ok+b+10000000000)/10000-(b-ng+10000000000)/10000;
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repp(i, st, en) for (ll i = (ll)st; i < (ll)(en); i++)
#define repm(i, st, en) for (ll i = (ll)st; i >= (ll)(en); i--)
#define all(v) v.begin(), v.end()
template<class in_chmax> void chmax(in_chmax &x, in_chmax y) {x = max(x,y);}
template<class in_chmin> void chmin(in_chmin &x, in_chmin y) {x = min(x,y);}
void Yes() {cout << "Yes" << endl; exit(0);}
void No() {cout << "No" << endl; exit(0);}
template<class in_Cout> void Cout(in_Cout x) {cout << x << endl; exit(0);}
template<class in_vec_cout>
void vec_cout(vector<in_vec_cout> vec) {
for (in_vec_cout res : vec) {cout << res << " ";}
cout << endl;
}
const ll inf = 1e18;
const ll mod = 1e9 + 7;
int main() {
ll N, M; cin >> N >> M;
vector<vector<ll>> a(N,vector<ll>(N,inf));
rep(i,M) {
ll x, y, z;
cin >> x >> y >> z;
x--; y--;
chmin(a[x][y],z);
}
vector<vector<ll>> dp(N+1,vector<ll>(1<<N));
dp[0][0] = 1;
rep(i,N) {
rep(bit,1<<N) {
if (dp[i][bit]==0) continue;
rep(j,N) {
if ((bit>>j)&1) continue;
ll nbit = bit | (1<<j);
bool ng = false;
ll cnt = 0;
rep(k,N) {
if ((nbit>>k)&1) cnt++;
if (cnt>a[i][k]) ng = true;
}
if (ng) continue;
dp[i+1][nbit] += dp[i][bit];
}
}
}
ll X = (1<<N)-1;
ll ans = dp[N][X];
Cout(ans);
} |
#include <bits/stdc++.h>
int ri() {
int n;
scanf("%d", &n);
return n;
}
int main() {
int h = ri();
int w = ri();
int x = ri() - 1;
int y = ri() - 1;
std::string s[h];
for (int i=0; i<h; i++) std::cin >> s[i];
int cnt = -3;
for (int i = x; i < h && s[i][y] != '#'; i++) cnt++;
for (int i = x; i >= 0 && s[i][y] != '#'; i--) cnt++;
for (int j = y; j < w && s[x][j] != '#'; j++) cnt++;
for (int j = y; j >= 0 && s[x][j] != '#'; j--) cnt++;
printf("%d\n", cnt);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
//using namespace atcoder;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define pb push_back
#define fi first
#define se second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void chOut(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }
using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using v_bool = vector<bool>;
using v_Pii = vector<Pii>;
//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};
const int mod = 1000000007;
//const int mod = 998244353;
signed main(){
int H, W, X, Y; cin >> H >> W >> X >> Y;
X--; Y--;
vector<string> S(H); cin >> S;
int ans = 1;
IFOR(i, 0, X){
if(S[i][Y] == '.') ans++;
else break;
}
FOR(i, X + 1, H){
if(S[i][Y] == '.') ans++;
else break;
}
IFOR(j, 0, Y){
if(S[X][j] == '.') ans++;
else break;
}
FOR(j, Y + 1, W){
if(S[X][j] == '.') ans++;
else break;
}
Out(ans);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define max(x,y) ((x)>(y)?(x):(y))
inline int read(){
int f=1,r=0;char c=getchar();
while(!isdigit(c))f^=c=='-',c=getchar();
while(isdigit(c))r=(r<<1)+(r<<3)+(c^48),c=getchar();
return f?r:-r;
}
const int N=2e5+5;
int mx[N<<2],tg[N<<2];
#define ls (p<<1)
#define rs (p<<1|1)
inline void spread(int p){
if(!tg[p])return;
tg[ls]+=tg[p],mx[ls]+=tg[p];
tg[rs]+=tg[p],mx[rs]+=tg[p];
tg[p]=0;
}
inline void change(int p,int l,int r,int x,int y,int val){
if(x<=l && r<=y){tg[p]+=val,mx[p]+=val;return;}
spread(p);int mid=(l+r)>>1;
if(x<=mid)change(ls,l,mid,x,y,val);
if(y>mid)change(rs,mid+1,r,x,y,val);
mx[p]=max(mx[ls],mx[rs]);
}
int main(){
int n=read(),w=read();
while(n--){
int l=read()+1,r=read(),x=read();
change(1,1,2e5,l,r,x);
if(mx[1]>w)puts("No"),exit(0);
}
puts("Yes");
return 0;
} | #include <bits/stdc++.h>
#define rei register int
#define ll long long
using namespace std;
const int N=4e5+100;
int head[N],ver[N],Next[N],tot;
int depth[N],len[N];
int son[N];
int ans[N],cnt;
int root,n;
inline void add(int u,int v){
ver[++tot]=v;
Next[tot]=head[u];
head[u]=tot;
}
void init(int x,int fa){
depth[x]=depth[fa]+1;
if(depth[root]<depth[x]) root=x;
for(rei i=head[x];i;i=Next[i]){
rei y=ver[i];
if(y==fa) continue;
init(y,x);
}
}
void dfs(int x,int fa){
for(rei i=head[x];i;i=Next[i]){
rei y=ver[i];
if(y==fa) continue;
dfs(y,x);
len[x]=max(len[x],len[y]+1);
if(!son[x] || len[y]>len[ son[x] ]) son[x]=y;
}
}
void calc(int x,int fa){
ans[x]=++cnt;
for(rei i=head[x];i;i=Next[i]){
rei y=ver[i];
if(y==fa || y==son[x]) continue;
calc(y,x);
++cnt;
}
if(son[x]) calc(son[x],x),++cnt;
}
int main(){
scanf("%d",&n);
for(rei i=1;i<n;++i){
rei x,y;
scanf("%d%d",&x,&y);
add(x,y),add(y,x);
}
init(1,0);
dfs(root,0);
calc(root,0);
for(rei i=1;i<=n;++i)
printf("%d ",ans[i]);
puts("");
getchar();
getchar();
return 0;
} |
#include "bits/stdc++.h"
#define ll long long int
#define ld long double
#define fastIO ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define pb push_back
using namespace std;
typedef pair<int, int> pii;
int main() {
fastIO;
string s;
cin >> s;
map<int, int> digits;
for (int i = 0; i < s.length(); i++) {
int d = s[i] - '0';
digits[d]++;
}
bool possible = false;
int i;
if (s.length() == 1) i = 8;
else if (s.length() == 2) i = 16;
else i = 104;
for (; i < 1000; i += 8) {
map<int, int> temp;
int num = i;
while (num > 0) {
temp[num % 10]++;
num /= 10;
}
bool poss = true;
for (pii p : temp) {
if (digits[p.first] < p.second) poss = false;
}
possible |= poss;
}
if (possible) cout << "Yes";
else cout << "No";
}
| #include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i, n) for(ll i=n-1;i>=0;--i)
#define rep1(i, n) for(ll i=1; i<=n; ++i)
#define repitr(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pll = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll LINF = 1LL << 60;
const int INF = 1e9 + 7;
const double PI = 3.1415926535897932384626433;
ll Str2Long(string s){
reverse(ALL(s));
ll n = 0;
rep(i, s.size()){
n += (s[i]-'0')*pow(10, i);
}
return n;
}
string Long2Str(ll x){
if(x <= 0)return "";
char c = '0' + x % 10;
return Long2Str(x/10) + c;
}
int main(){
string s;
cin >> s;
if(s.size() == 1){
if(s == "8" || s=="0")cout << "Yes";
else cout << "No";
return 0;
}
if(s.size() == 2){
if(Str2Long(s) % 8 == 0)cout << "Yes";
else {
reverse(ALL(s));
if(Str2Long(s) % 8 == 0)cout << "Yes";
else cout << "No";
}
return 0;
}
vector<ll> cnt(10, 0);
for(char c: s){
cnt[c - '0']++;
}
for(ll i = 104; i <= 992; i += 8){
string s_i = Long2Str(i);
ll cnt_0 = cnt[s_i[0] - '0'];
ll cnt_1 = cnt[s_i[1] - '0'];
ll cnt_2 = cnt[s_i[2] - '0'];
if(cnt_0 * cnt_1 * cnt_2 == 0)continue;
bool ok = false;
if(s_i[0] == s_i[1] && s_i[0] == s_i[2]){
if(cnt_0 >= 3)ok = true;
}
else if(s_i[0] == s_i[1]){
if(cnt_0 >= 2 && cnt_2 >= 1)ok = true;
}
else if(s_i[1] == s_i[2]){
if(cnt_0 >= 1 && cnt_1 >= 2)ok = true;
}
else if(cnt_0 >= 1 && cnt_1 >= 1 && cnt_2 >= 1)ok = true;
if(ok){
cout << "Yes";
return 0;
}
}
cout << "No";
} |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i=0; i<(ll)n; i++)
#define ALL(obj) begin(obj), end(obj)
typedef long long ll;
int n, m, a, b, cnt;
vector<vector<int> > G(22);
vector<int> color(22, -1), ts;
vector<bool> vit(22, 0);
void dfs(int now){
ts.push_back(now);
vit[now]=1;
for(int i : G[now]){
if(!vit[i])
dfs(i);
}
}
ll DFS(int i){
if(i==ts.size())
return 1;
ll ret=0;
rep(j, 3){
bool f=1;
for(int v:G[ts[i]]){
if(color[v]==j)
f=0;
}
if(!f)
continue;
color[ts[i]]=j;
ret+=DFS(i+1);
color[ts[i]]=-1;
}
return ret;
}
int main()
{
cin>>n>>m;
ll ans=1;
rep(i, m){
cin>>a>>b;
a--;
b--;
G[a].push_back(b);
G[b].push_back(a);
}
rep(i, n){
if(vit[i])
continue;
dfs(i);
fill(ALL(color), -1);
ans*=DFS(0);
ts.clear();
}
cout<<ans<<endl;
return 0;
}
| #pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int,null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_set_pair tree<pair<int,int>,null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_set_mutiset tree<int,null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
typedef pair<int,int> pi;
#define PI 3.1415926535897932384
#define FOR(i,vv,n) for(ll i=vv;i<n;i++)
#define FORR(i,n,vv) for(ll i=n-1;i>=vv;i--)
#define ve vector
#define maxind(v) (max_element(v.begin(),v.end())-v.begin())
#define minind(v) (min_element(v.begin(),v.end())-v.begin())
#define maxe(v) *max_element(v.begin(),v.end())
#define mine(v) *min_element(v.begin(),v.end())
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define eb emplace_back
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mp make_pair
#define M 1000000007ll
#define INF 1000000000000000000ll
#define PRECISE cout.precision(18);
#define BS(v,n) binary_search(v.begin(),v.end(),n)
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(v.begin(),v.end(),greater <ll>())
#define uni(v) v.resize(unique(v.begin(),v.end())-v.begin())
#define F first
#define S second
#define GET(i,p) get<p>(i)
int main(){
#ifndef ONLINE_JUDGE
// for getting input from input.txt
freopen("input.txt", "r", stdin);
// for writing output to output.txt
freopen("output.txt", "w", stdout);
#endif
FAST
ll n;cin>>n;
string s,t;
cin>>s>>t;
ll ans = 0;
ll k1 = 0,k2 = 0;
FOR(i,0,n){
if(s[i]-'0'==0)k1++;
if(t[i]-'0'==0)k2++;
}
if(k1!=k2)ans=-1;
else{
ve <ll> z(2);
ll don = 0;
FOR(i,0,n){
ll x1 = s[i]-'0';
ll x2 = t[i]-'0';
if(z[x2]>0){
z[x2]--;
}
else{
ll c1 = 0;
while(s[don]-'0'!=x2){
c1++;don++;
}
don++;
z[1-x2]+=c1;
if(x2==0){
if(c1!=0||(c1==0&&z[1]!=0))ans++;
}
else{
if(c1!=0)ans+=c1;
}
}
}
}
cout<<ans;
return 0;
} |
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define rep(i,n) repi(i,0,n)
#define repi(i,a,n) for(ll i=a;i<(ll)n;++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
void YN(bool a) { cout << (a ? "Yes" : "No") << endl; }
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; }
void show(){ cout << endl; }
template <class Head, class... Tail>
void show(Head&& head, Tail&&... tail){ cout << head << " "; show(std::forward<Tail>(tail)...); }
template<class T> inline void showall(T& a) { for(auto v:a) cout<<v<<" "; cout<<endl; }
void solve()
{
ll t;
cin >> t;
rep(ti, t)
{
ll l, r;
cin >> l >> r;
ll ans = 0;
if (r < l * 2) ans = 0;
else if (r == l * 2) ans = 1;
else {
r -= (l - 1) * 2 + 1;
ans = (r) * (r + 1) / 2;
}
show(ans);
}
}
int main()
{
fastio;
solve();
return 0;
} | #include <bits/stdc++.h>
/*#include <iostream>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <sstream>*/
#define ll long long
#define fop(i,m,n) for(int i=m; i<n; i++)
#define fastIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define X first
#define Y second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define ep emplace_back
using namespace std;
const long long MOD = 1e9+7;
const long long N = 1e9+5;
const long long Nlog = 17;
const long long Hash = 257;
const double PI = 2.0*acos(0.0);//<cmath>
//const double PI = 3.141592653;
const double E = 2.718281828;
bool cmp(pair<ll, int> a, pair<ll, int> b){
return a.X<b.X;
}
void solve(){
int k;
ll n, m;
cin >> k >> n >> m;
ll a[k];
fop(i,0,k) cin >> a[i];
ll l[k], num = m;
pair<ll, int> c[k];
fop(i,0,k){
l[i] = m*a[i]/n;
c[i].X = (n*l[i])-(m*a[i]);
c[i].Y = i;
num-=l[i];
}
ll ans[k];
fop(i,0,k) ans[i] = l[i];
sort(c, c+k, cmp);
fop(i,0,num) ans[c[i].Y]++;
fop(i,0,k) cout << ans[i] << ' ';
}
int main()
{
fastIO;
int t=1;
//cin >> t;
while(t--) solve();
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
int n,a[200005],parent[200005],s=0;
int findparent(int x)
{
if (x==parent[x]) return x;
return parent[x]=findparent(parent[x]);
}
void Union(int u,int v)
{
int p=findparent(u);//find parents of u
int q=findparent(v);//find parents of v;
if(p!=q)parent[q]=p;
}
int main()
{
cin>>n;
for (int i=1; i<=n; i++) cin>>a[i],parent[a[i]]=a[i];
for (int i=1; i<=n; i++)
{
int x=findparent(a[i]);
int y=findparent(a[n-i+1]);
if (x!=y)
{
s++;
Union(x,y);
}
}
cout<<s<<endl;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define drep(i, cc, n) for (ll i = (cc); i <= (n); ++i)
#define rep(i, n) drep(i, 0, n - 1)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define fi first
#define se second
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ll INF = 1e18;
const ll n_max = 2e5 + 1;
vector<vector<ll>> G(n_max);
vector<bool> check(n_max, false);
ll dfs(ll v){
if(check[v]) return 0;
check[v] = true;
ll ret = 0;
for(ll u : G[v]){
if(check[u]) continue;
ret += dfs(u) + 1;
}
return ret;
}
int main(){
ll n;
cin >> n;
vector<ll> a(n);
rep(i, n) cin >> a[i];
for(ll i = 0; i <= (n-1)/2; i++){
if(a[i] != a[n-1-i]){
G[a[i]].pb(a[n-1-i]);
G[a[n-1-i]].pb(a[i]);
}
}
ll ans = 0;
drep(i, 1, n_max-1){
if(check[i]) continue;
ans += dfs(i);
}
cout << ans << endl;
} |
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
void amain()
{
long long n; cin >> n;
if (n%4==0) cout << "Even" << endl;
if (n%4==2) cout << "Same" << endl;
if (n%2) cout << "Odd" << endl;
return;
}
int main()
{
ios_base::sync_with_stdio(0);
int t; cin >> t;
while (t--) amain();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(a) (a).begin(), (a).end()
#define mp make_pair
template<typename T1, typename T2>
inline void chkmin(T1& x, const T2& y) {
if (y < x) x = y;
}
template<typename T1, typename T2>
inline void chkmax(T1& x, const T2& y) {
if (x < y) x = y;
}
int getLen(ll x) {
int ans = 0;
while (x) {
ans++;
x /= 10;
}
return ans;
}
int getPow(int len) {
int ans = 1;
for (int i = 0; i < len; ++i) {
ans *= 10;
}
return ans;
}
ll get(ll x) {
return x * getPow(getLen(x)) + x;
}
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cout.precision(20), cout.setf(ios::fixed);
ll n;
cin >> n;
int ans = 0;
int x = 1;
while (true) {
ll have = get(x);
if (have > n) break;
++ans;
++x;
}
cout << ans << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr char newl = '\n';
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
vector<ll> w(n);
for (int i = 0; i < n; i++) {
cin >> w[i];
}
vector<P> vl(m);
for (int i = 0; i < m; i++) {
cin >> vl[i].second >> vl[i].first;
vl[i].second = -vl[i].second;
}
sort(vl.begin(), vl.end());
{
ll maxw = 0;
for (int i = 0; i < n; i++) {
maxw = max(maxw, w[i]);
}
if (maxw > vl[0].first) {
cout << -1 << newl;
return 0;
}
}
map<ll, ll> memo;
{
ll maxl = 0;
for (int i = 0; i < m; i++) {
if (maxl < -vl[i].second) {
maxl = -vl[i].second;
memo[vl[i].first] = maxl;
}
}
}
vector<int> ids(n);
iota(ids.begin(), ids.end(), 0);
ll ans = 1e18;
ll foo = 0;
do {
vector<ll> dp(n, 0);
for (int ii = 0; ii < n; ii++) {
int i = ids[ii];
ll wsum = w[i];
for (int jj = ii + 1; jj < n; jj++) {
int j = ids[jj];
wsum += w[j];
auto it = memo.lower_bound(wsum);
if (it == memo.begin()) continue;
dp[jj] = max(dp[jj], dp[ii] + prev(it)->second);
}
}
ans = min(ans, dp.back());
} while (next_permutation(ids.begin(), ids.end()));
cout << ans << newl;
return 0;
} | #include<iostream>
using namespace std;
int l[200005], r[200005];
long long dp[200005][2];
int n, x, c;
const int aa = 1 << 30;
int main() {
cin >> n;
fill(l + 1, l + 1 + n,aa);
fill(r + 1, r + 1 + n,-aa);
for (int i = 1; i <= n; i++) {
cin >> x >> c;
l[c] = min(l[c], x);
r[c] = max(r[c], x);
}
for (int i = 1, j = 0; i <= n + 1; i++) {
if (l[i] != aa) {
dp[i][0] = min(dp[j][0] + abs(r[i] - l[j]), dp[j][1] + abs(r[i] - r[j]));
dp[i][1] = min(dp[j][0] + abs(l[i] - l[j]), dp[j][1] + abs(l[i] - r[j]));
dp[i][0] += abs(l[i] - r[i]), dp[i][1] += abs(l[i] - r[i]);
j = i;
}
}
cout << dp[n + 1][0];
return 0;
} |
#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
//#include <bits/stdc++.h>
using namespace std;
int main() {
int H, W;
cin >> H >> W;
vector<vector<int>> X(H, vector<int>(W));
for (int i = 0; i < H; ++i) {
for (int j = 0; j < W; ++j) {
cin >> X[i][j];
}
}
int min_val = X[0][0];
for (int i = 0; i < H; ++i) {
for (int j = 0; j < W; ++j) {
if(min_val > X[i][j]){
min_val = X[i][j];
}
}
}
int ans = 0;
for (int i = 0; i < H; ++i) {
for (int j = 0; j < W; ++j) {
ans = ans + X[i][j] - min_val;
}
}
cout << ans;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define rep(i,a,b) for( i=a;i<b;++i)
#define repr(i,a,b) for( i=a;i>=b;i--)
#define up upper_bound
#define lb lower_bound
// #define t() int test;cin>>test;while(test--)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cout << name << " : " << arg1 << endl;
//use cerr if u want to display at the bottom
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
ll dp[2000][2000];
ll down[2000][2000];
ll rig[2000][2000];
ll diag[2000][2000];
const ll mod = 1000000007;
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
IOS;
ll h,w;
cin >> h >> w;
vector<vector<char>> a(h,vector<char> (w));
for(ll i = 0;i < h;i++){
for(ll j = 0;j < w;j++){
cin >> a[i][j];
}
}
dp[0][0] = 1;
for(ll i = 0;i < h;i++){
for(ll j = 0;j < w;j++){
if(i == 0 && j == 0){
continue;
}
if(a[i][j] == '#'){
continue;
}
if(j > 0){
rig[i][j] = (rig[i][j-1] + dp[i][j-1])%mod;
}
if(i > 0){
down[i][j] = (down[i-1][j] + dp[i-1][j])%mod;
}
if(i > 0 && j > 0){
diag[i][j] = (diag[i-1][j-1] + dp[i-1][j-1])%mod;
}
dp[i][j] = (rig[i][j] + down[i][j] + diag[i][j])%mod;
}
}
cout << dp[h-1][w-1] << "\n";
return 0;
} |
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define pii pair<int, int>
#define pll pair<long long,long long>
#define vl vector<long long>
#define vll vector<pll>
#define vi vector<int>
#define vii vector<pii>
#define sws ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl '\n'
#define tcase int tt; cin>>tt; while(tt--)
#define tcase2 int tt; cin>>tt; for(int qq=1;qq<=tt;qq++)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
const int MAXN = 1000002;
const int MOD2 = 998244353;
const int MOD = 1000000007;
const int INF = 1e8;
const ld EPS = 1e-7;
// Extra
#define forn(i, n) for(int i = 0; i < (int)n; i++)
#define forne(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define trav(a, x) for(auto& a : x)
#define fill(x,y) memset(x,y,sizeof(x))
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
ll mul(ll x, ll y)
{
return (x * 1ll * y) % MOD;
}
ll fastpow(ll x, ll y)
{
ll z = 1;
while(y)
{
if(y & 1) z = mul(z, x);
x = mul(x, x);
y >>= 1;
}
return z;
}
ll modinv(ll n,ll p)
{
return fastpow(n,p-2) ;
}
struct Comp {
bool operator()(const std::pair<int, int> &a, const std::pair<int, int> &b) {
if (a.first != b.first) {
return a.first > b.first;
}
return a.second >b.second;
}
};
int main(int argc, char** argv)
{ sws ;
cout<<setprecision(10);
// ll google=0 ;
// tcase
{
ll a,b,c ;
cin>>a>>b>>c;
if(a<=0&&b<=0)
{ a*=-1 ;
b*=-1;
if(c%2)
{
if(a==b)
cout<<"=" ;
else if(a>b)
cout<<"<" ;
else
cout<<">" ;
}
else
{
if(a==b)
cout<<"=" ;
else if(a>b)
cout<<">" ;
else
cout<<"<" ;
}
}
else if(a>=0&&b>=0)
{
if(a==b)
cout<<"=" ;
else if(a>b)
cout<<">" ;
else
cout<<"<" ;
}
else if(a>=0&&b<=0)
{
if(c%2)
cout<<">" ;
else
{
b*=-1 ;
if(a==b)
cout<<"=" ;
else if(a>b)
cout<<">" ;
else
cout<<"<" ;
}
}
else
{
if(c%2)
cout<<"<" ;
else
{
a*=-1 ;
if(a==b)
cout<<"=" ;
else if(a>b)
cout<<">" ;
else
cout<<"<" ;
}
}
}
return 0 ;
} | #include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<complex>
#include<cstdio>
#define initdp(a,b) for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)dp[i][j]=-1;
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ppi pair<pii,int>
#define pip pair<int,pii>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define inf 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 100005
#define mid(l,r) l+(r-l)/2
#define removeduplicates(vec) vec.erase( unique( vec.begin(), vec.end() ), vec.end() )
#define memset1(v) memset(v,-1,sizeof(v))
#define memset0(v) memset(v,0,sizeof(v))
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
void mad(ll &a,ll b){a=(a+b)%mod;if(a<0)a+=mod;}
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}
int n,m;
vector<pii>ed[2005];
void solve(){
cin>>n>>m;
rep(i,m){
int u,v,c;
cin>>u>>v>>c;
ed[u].pb(pii(v,c));
}
for(int i=1;i<=n;i++){
int d[n+1];
for(int i=1;i<=n;i++)d[i]=inf;
priority_queue<pii>pq;
for(pii p:ed[i]){
pq.push(pii(-p.se,p.fi));
d[p.fi]=min(d[p.fi],p.se);
}
while(!pq.empty()){
pii p=pq.top();
int u=p.se;
int d1=-p.fi;
pq.pop();
if(d1>d[u])continue;
for(pii p:ed[u]){
if(d[p.fi]>d1+p.se){
d[p.fi]=d1+p.se;
pq.push(pii(-d[p.fi],p.fi));
}
}
}
if(d[i]>=inf)cout<<-1<<"\n";
else cout<<d[i]<<"\n";
}
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t=1;
//cin>>t;
while(t--){
solve();
}
} |
# include<bits/stdc++.h>
using namespace std;
# define l long long
# define db double
# define rep(i,a,b) for(l i=a;i<b;i++)
# define vi vector<l>
# define vvi vector<vi>
# define vsi vector<set<l> >
# define pb push_back
# define mp make_pair
# define ss second
# define ff first
# define pii pair<l,l>
# define trvi(v,it) for(vi::iterator it=v.begin();it!=v.end();++it)
# define read(a) freopen(a,"r",stdin)
# define write(a) freopen(a,"w",stdout)
# define io ios::sync_with_stdio(false)
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ' ' << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
#ifdef KRISHNAN_DEBUG
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif
const bool MULTIPLE_TEST_CASES = false;
const l MOD=1e9+7;
const l N=1e5+5;
const l INF=1e12;
l H,W,A,B;
void cnt(vector<vector<bool> > &visited, l A_rem, l B_rem, l &ans) {
if(A_rem<0 || B_rem<0) {
return;
}
if(A_rem==0 && B_rem==0) {
ans++;
return;
}
bool found = false;
l i=-1,j=-1;
for(l x=0;x<H;x++) {
for(l y=0;y<W;y++) {
if(visited[x][y]==false) {
i=x;
j=y;
found = true;
break;
}
}
if(found) {
break;
}
}
if(i==-1 || j==-1) {
return;
}
dbg(i,j);
visited[i][j]=true;
cnt(visited, A_rem, B_rem-1,ans);
if(i+1<H && visited[i+1][j]==false) {
visited[i+1][j]=true;
cnt(visited, A_rem-1, B_rem,ans);
visited[i+1][j]=false;
}
if(j+1<W && visited[i][j+1]==false) {
visited[i][j+1]=true;
cnt(visited, A_rem-1, B_rem,ans);
visited[i][j+1]=false;
}
visited[i][j] = false;
}
void solve() {
cin>>H>>W>>A>>B;
vector<vector<bool> > visited(H, vector<bool>(W, false));
l ans = 0;
cnt(visited, A, B, ans);
cout<<ans<<"\n";
return;
}
int main(){
io;
int t=1;
if (MULTIPLE_TEST_CASES) cin>>t;
rep(i,0,t) {
solve();
}
return 0;
}
| #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using VI = vector<int>;
int h, w;
int g(VI& a, int i, int d);
int f(VI& v) {
int i = find(cbegin(v), cend(v), 0) - cbegin(v);
return i < v.size() ? g(v, i, 0) + g(v, i, 1) : 1;
}
int g(VI& v, int i, int d) {
int j = i + (d ? w : 1);
if (!d && i % w == w - 1 || d && i / w == h - 1 || v[j]) {
return 0;
}
v[i] = v[j] = 1;
int r = f(v);
v[i] = v[j] = 0;
return r;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int a, b;
cin >> h >> w >> a >> b;
VI v(2 * a);
v.insert(end(v), b, 1);
int r = 0;
do r += f(v);
while (next_permutation(begin(v), end(v)));
cout << r << '\n';
return 0;
}
|
/**
* code generated by JHelper
* More info: https://github.com/AlexeyDmitriev/JHelper
* @author
*/
#include <iostream>
#include <fstream>
#ifndef PRELUDE_H
#define PRELUDE_H
#define M_PI 3.14159265358979323846
#define EPS 1e-9
#include <algorithm>
#include <cmath>
#include <numeric>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef std::pair<int, int> ii;
typedef std::pair<ll, ll> llll;
typedef std::pair<int, ll> ill;
typedef std::pair<double, double> dd;
typedef std::vector<int> vi;
typedef std::vector<ii> vii;
typedef std::vector<vi> vvi;
typedef std::vector<vvi> vvvi;
typedef std::vector<vii> vvii;
typedef std::vector<ill> vill;
typedef std::vector<vill> vvill;
typedef std::vector<bool> vb;
typedef std::vector<char> vc;
typedef std::vector<std::vector<char>> vvc;
typedef std::vector<ll> vll;
typedef std::vector<vll> vvll;
typedef std::vector<llll> vllll;
typedef std::vector<double> vd;
typedef std::vector<dd> vdd;
typedef std::string ss;
typedef std::vector<ss> vss;
typedef std::vector<vss> vvss;
typedef std::set<int> si;
typedef std::set<ii> sii;
typedef std::set<ll> sll;
typedef std::map<int, int> mii;
typedef std::map<char, int> mci;
typedef std::queue<int> qi;
typedef std::vector<std::pair<int, ii>> EdgeList;
#define REP(i,n) for(int i=0;i<n;++i)
#define DEBUG(a) #a << ": " << (a) << " " <<
#define ENDL "\n"
#define REPLL(l,n) for(ll l=0;l<n;++l)
#define FOR(i,s,n) for(int i=s;i<=n;++i)
#define FOREACH(it,a) for(auto it=a.begin(); it != a.end(); ++it)
#endif //PRELUDE_H
class EWhiteAndBlackBalls {
public:
vll fac, invfac;
ll mod = 1'000'000'000 + 7;
std::tuple<ll, ll, ll> extendedEuclid(ll a, ll b) {
if (b == 0) {
return {a, 1, 0};
}
auto [d, x, y] = extendedEuclid(b, a % b);
ll x1 = y;
ll y1 = x - (a / b) * y;
return {d, x1, y1};
}
ll modularInverse(ll a, ll n) {
auto [d, x, y] = extendedEuclid(a, n);
return (x + n) % n;
}
ll choose (ll n, ll k) {
if (k > n) {
return 0;
}
return fac[n] * invfac[k] % mod * invfac[n-k] % mod;
}
void solve(std::istream& in, std::ostream& out) {
ll n, m, k;
in >> n >> m >> k;
if (n > m + k) {
out << 0; return;
}
fac = vll(n+m+1);
invfac = vll(n+m+1);
fac[0] = 1; invfac[0] = 1;
for(int i = 1; i <= n+m; ++i) {
fac[i] = i * fac[i-1] % mod;
invfac[i] = modularInverse(fac[i], mod);
}
ll ans = choose(n+m, n) - choose(n+m, m+k+1);
ans = (ans + mod) % mod;
out << ans;
}
};
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
std::cout << std::fixed;
std::cout << std::setprecision(15);
EWhiteAndBlackBalls solver;
std::istream& in(std::cin);
std::ostream& out(std::cout);
solver.solve(in, out);
return 0;
}
| #include <bits/stdc++.h>
#define MAXN 2000005
#define ll long long
#define F first
#define S second
#define MOD 1000000007
#define ll long long
using namespace std;
ll n, m, k;
ll gt[MAXN], inv[MAXN];
ll poW(ll A, ll B)
{
ll C = 1;
for(; B; B /= 2, A = (A * A) % MOD)
{
if(B % 2) C = (C * A) % MOD;
}
return C;
}
ll C(ll A, ll B)
{
if(B < A) return 0;
ll res = (((gt[B] * inv[A] ) % MOD ) * inv[B - A] ) % MOD;
return res;
}
void solve()
{
cin >> n >> m >> k;
//if(n < m) swap(n, m);
if(n > m + k)
{
cout << 0;
return;
}
gt[0] = 1;
for(int i = 1; i <= n + m; ++i)
{
gt[i] = (gt[i-1] * i) % MOD;
}
inv[n+m] = poW(gt[n + m], MOD - 2);
for(int i = n + m - 1; i >= 0; --i)
{
inv[i] = (inv[i + 1] * (i + 1)) % MOD;
}
ll ans = C(m, n + m) % MOD;
ans = (ans - C(m + k + 1, n + m)) % MOD;
if(ans < 0 ) ans += MOD;
cout << ans;
}
int main()
{
ios_base :: sync_with_stdio(0);
cin.tie();
cout.tie();
if(fopen(".inp", "r"))
{
freopen(".inp", "r", stdin);
freopen(".out", "w", stdout);
}
int t;
t = 1;
//cin >> t;
while(t--)
{
//cerr << t << '\n';
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
#define PB push_back
#define pb pop_back
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int a,b; cin>>a>>b;
a *=2; a += 100;
cout<< a - b;
return 0;
} | #include <bits/stdc++.h>
#define int long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
signed main(){
fastio
int n,k;
cin >> n >> k;
auto f = [&](int a, int b){
return min(b-1,2*a+1-b);
};
int ans = 0;
for(int i = 2;i <= 2*n;i++){
if(i-k < 2 || i-k > 2*n) continue;
ans += f(n,i)*f(n,i-k);
}
cout << ans << "\n";
} |
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
using namespace chrono;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vii;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define pb push_back
#define odd(x) ((x)&1)
#define even(x) (!odd(x))
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(auto i=0ll;i<n;++i)
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define TEST_CASE int tc;cin>>tc;while(tc--)
#define Clock high_resolution_clock::now()
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;
}
#ifdef LOCAL
#define cerr cout
#else
#endif
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define JD
// #define TIME
/******************************************************************************************************************************/
const ll inf = 2e18;
const ll mod = 1e9+7;
const ll N = 1e6+3;
int main()
{
auto start_time = Clock;
FASTIO
#ifndef JD
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
ll n,x;
string s;
cin>>n>>x>>s;
for(auto i: s) {
if(i=='o') ++x;
else --x;
chmax(x,0ll);
}
cout<<x;
auto end_time = Clock;
#ifndef TIME
return 0;
#endif
cout << "\nTime elapsed: "
<< (double)duration_cast<milliseconds>(end_time-start_time).count()
<< "ms";
return 0;
}
| #include <iostream>
using namespace std;
int main()
{
int N,X;
cin >> N >> X;
string s;
cin >> s;
for(int i=0;i<N;i++) {
if(s[i]=='x' && X==0)
{
continue;
}
else if(s[i]=='x' && X!=0) {
X--;
}
else if(s[i]=='o') {
X++;
}
}
cout << X << endl;
return 0;
} |
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <iomanip>
#include <cmath>
#include <map>
#include <bitset>
#include <numeric>
using namespace std;
using ll = long long;
struct UnionFind
{
vector<int> data;
UnionFind(int sz)
{
data.assign(sz, -1);
}
bool unite(int x, int y)
{
x = find(x), y = find(y);
if (x == y)
return (false);
if (data[x] > data[y])
swap(x, y);
data[x] += data[y];
data[y] = x;
return (true);
}
bool same(int x, int y)
{
x = find(x), y = find(y);
return x == y;
}
int find(int k)
{
if (data[k] < 0)
return (k);
return (data[k] = find(data[k]));
}
int size(int k)
{
return (-data[find(k)]);
}
};
int main()
{
ll N;
cin >> N;
vector<ll> A(N);
vector<ll> B(N);
vector<ll> P(N);
for (size_t i = 0; i < N; i++)
{
cin >> A[i];
}
for (size_t i = 0; i < N; i++)
{
cin >> B[i];
}
priority_queue<ll> odd_plus;
priority_queue<ll> odd_minus;
ll odds = 0;
ll ans = 0;
for(int i = 0;i < N;i++){
if (A[i] > B[i]){
ans += A[i];
if (i % 2 == 0){
odds--;
odd_plus.push(B[i]-A[i]);
}else{
odds++;
odd_minus.push(B[i]-A[i]);
}
}else{
ans += B[i];
if (i % 2 == 0){
odd_minus.push(A[i]-B[i]);
}else{
odd_plus.push(A[i]-B[i]);
}
}
}
while(odds > 0){
ans += odd_minus.top();
odd_minus.pop();
odds--;
}
while(odds < 0){
ans += odd_plus.top();
odd_plus.pop();
odds++;
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#define fi first
#define se second
#define lc (x << 1)
#define rc (x << 1 | 1)
#define gc getchar() //(p1==p2&&(p2=(p1=buf)+fread(buf,1,size,stdin),p1==p2)?EOF:*p1++)
#define mk make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define IT iterator
#define V vector
#define TP template <class o>
#define TPP template <typename t1, typename t2>
#define SZ(a) ((int)a.size())
#define all(a) a.begin(), a.end()
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define REP(i, a, b) for (int i = b; i >= a; i--)
#define FOR(i,n) rep(i,1,n)
#define debug(x) cerr << #x << ' ' << '=' << ' ' << x << endl
using namespace std;
typedef unsigned ui;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
const int N = 2e5 + 10, size = 1 << 20, mod = 998244353, inf = 2e9;
const ll INF = 1e15;
// char buf[size],*p1=buf,*p2=buf;
TP void qr(o& x) {
char c = gc;
x = 0;
int f = 1;
while (!isdigit(c)) {
if (c == '-')
f = -1;
c = gc;
}
while (isdigit(c))
x = x * 10 + c - '0', c = gc;
x *= f;
}
TP void qw(o x) {
if (x / 10)
qw(x / 10);
putchar(x % 10 + '0');
}
TP void pr1(o x) {
if (x < 0)
x = -x, putchar('-');
qw(x);
putchar(' ');
}
TP void pr2(o x) {
if (x < 0)
x = -x, putchar('-');
qw(x);
putchar(10);
}
// math
ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll power(ll a, ll b = mod - 2, ll p = mod) {
ll c = 1;
while (b) {
if (b & 1)
c = c * a % p;
b /= 2;
a = a * a % p;
}
return c;
}
TP void cmax(o& x, o y) {
if (x < y)
x = y;
}
void cmax(int& x, int y) { x = x - y >> 31 ? y : x; }
TP void cmin(o& x, o y) {
if (x > y)
x = y;
}
void cmin(int& x, int y) { x = x - y >> 31 ? x : y; }
TPP void ad(t1& x, t2 y) {
x += y;
if (x >= mod)
x -= mod;
}
TPP void dl(t1& x, t2 y) {
x -= y;
if (x < 0)
x += mod;
}
// dbinom
ll jc[N], inv[N];
void jc_init(int n) {
jc[0] = 1;
for (int i = 1; i <= n; i++)
jc[i] = jc[i - 1] * i % mod;
inv[n] = power(jc[n]);
for (int i = n; i; i--)
inv[i - 1] = inv[i] * i % mod;
}
ll C(int x, int y) {
if (x < y || y < 0)
return 0;
return jc[x] * inv[y] % mod * inv[x - y] % mod;
}
int n, a[N], b[N];
ll ans, c[2][N];
void solve() {
qr(n);
FOR(i,n) qr(a[i]),ans += a[i];
FOR(i,n) qr(b[i]),c[i&1][(i+1)>>1]=b[i]-a[i];
sort(c[0]+1,c[0]+n/2+1);
sort(c[1]+1,c[1]+n/2+1);
REP(i,1,n/2) {
ll x=c[0][i]+c[1][i];
if(x<0) break;
ans += x;
}
pr2(ans);
}
int main() {
int T = 1;
// qr(T);
while (T--)
solve();
return 0;
}
|
#include <algorithm>
#include <cassert>
#include <iostream>
#include <memory>
#include <numeric>
#include <array>
#include <deque>
#include <map>
#include <set>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstring>
#include <ostream>
#include <type_traits>
#include <utility>
#include <chrono>
#include <random>
#ifdef ONLINE_JUDGE
#pragma GCC optimize ("O3")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif
using namespace std;
using uint64 = uint64_t;
using int64 = int64_t;
using uint32 = uint32_t;
using vi = vector<int>;
#define seq(i,a,b) for (auto i = (a); i < (b); ++i)
#define rev(i,a,b) for (auto i = (b)-1; i >= (a); --i)
#define sz(x) ((int)x.size())
#define all(x) x.begin(), x.end()
#define dbg(x) {cerr << #x << ": " << x << endl;}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int64 s,p; cin >> s >> p;
int64 i = 1;
while (i*i <= p) {
if (p%i == 0) {
if (i + p/i == s) {
cout << "Yes" << endl;
return 0;
}
}
++i;
}
cout << "No" << endl;
}
| ///OM
///SUVOM SHAHA
///AUST CSE 39
#include<bits/stdc++.h>
#define loo(i, n) for(int i = 0; i < n; i++)
#define mod 1000000007
#define pb push_back
#define ff first
#define sc second
#define ii pair<int, int>
#define vi vector<int>
#define vii vector<ii>
#define ll long long int
#define inf 1000000000
#define mpch map<char, int>
#define mpint map<int, int>
#define endl '\n'
//to iterate map :for (auto i : mp):
using namespace std;
int main(void)
{
int a, b, i, j = 0;
cin>>a>>b;
int ara[a+b], n = a+b;
if(a >= b){
for(i = 0; i < a; i++){
ara[i] = i+1;
j += ara[i];
}
for(i = a; i < n-1; i++){
ara[i] = -(ara[i-a]);
j += ara[i];
}
ara[n-1] = -(j);
}
else{
for(i = 0; i < b; i++){
ara[i] = -(i+1);
j -= ara[i];
}
for(i = b; i < n-1; i++){
ara[i] = -(ara[i-b]);
j -= ara[i];
}
ara[n-1] = j;
}
for(i = 0; i < n; i++){
if(i == n-1)cout<<ara[i]<<endl;
else cout<<ara[i]<< " ";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define SZ(v) ((int)(v.size()))
const int N = 2e5+9;
void run () {
int a, b, c;
cin >> a >> b >> c;
int sum = 6 * 7 / 2;
sum -= a;
sum -= b;
sum -= c;
cout << sum << endl;
}
int main () {
int tt;
tt = 1;
// cin >> tt;
while (tt--)
run();
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=(int)(x);i<(int)(y);i++)
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=1e9+7;
const int siz=3e5;
const int inf=1e9;
int main(){
int a,b,c; cin>>a>>b>>c;
cout<<21 - a - b - c<<endl;
} |
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
#include <functional>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<PII> VPI;
typedef vector<PLL> VPL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound
//#include <atcoder/all>
//using namespace atcoder;
//typedef modint998244353 mint;
ll inf=1001001001001001001;
ll pls(ll a,ll b){
if(inf-a<b) return inf;
return a+b;
}
ll mul(ll a,ll b){
if(a==0 or b==0) return 0;
if(inf/a<b) return inf;
return a*b;
}
int main(){
string S;
cin>>S;
ll M;
cin>>M;
if(S.size()==1){
if(stoi(S)<=M) cout<<1<<endl;
else cout<<0<<endl;
return 0;
}
ll ok=0;
ll ng=inf;
VL X(0);
for(auto e:S) X.pb(e-'0');
ll ans=*max_element(all(X))+1;
while(abs(ok-ng)>1){
ll mid=(ok+ng)/2;
ll sum=0;
ll tmp=1;
rep(i,S.size()){
ll nu=mul(stoi(S.substr(S.size()-1-i,1)),tmp);
sum=pls(sum,nu);
tmp=mul(tmp,mid);
}
if(sum==inf or sum>M) ng=mid;
else ok=mid;
}
cout<<max(0ll,ok-ans+1)<<endl;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using C = complex<double>;
C inC() {
double x, y;
cin >> x >> y;
return C(x, y);
}
int main() {
int N;
cin >> N;
C p0 = inC();
C ph = inC();
C core = (p0 + ph) / 2.0;
double PI = acos(-1);
double rad = 2 * PI / N;
C r(cos(rad), sin(rad));
C ans = core + (p0 - core) * r;
printf("%.10f %.10f\n", ans.real(), ans.imag());
return 0;
}
|
#include <bits/stdc++.h>
#define INF 1e9
#define INFLL 1ull<<60u
using namespace std;
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a) (a).begin(),(a).end()
#define endl "\n"
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
typedef long long ll;
using vi = vector<int>;
using vvi = vector<vi>;
using vpii = vector<pair<int,int>>;
void solve() {
double X,Y,Z; cin >> X >> Y >> Z;
double t = Y / X;
REPR(i,1e8) {
double snuke = (double)i / Z;
if (snuke < t) {
cout << i << endl;
return;
}
}
}
int main() {
solve();
return 0;
} | #pragma GCC optimize("Ofast")
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h>
#include <cmath>
#include <functional>
#include <cassert>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double EPS = 1e-10;
// constexpr ll mod = 1000000007;
constexpr ll mod = 998244353;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
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 char eol = '\n';
// --------------------------------------------------------------------------
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int X,Y,Z;
cin >> X >> Y >> Z;
for(int i=1000000; i>=0; i--){
if(Y*Z > (ll)i*X){
cout << i << endl;
return 0;
}
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
template< typename T >
T mod_pow(T x, T n, const T &p) {
T ret = 1;
while(n > 0) {
if(n & 1) (ret *= x) %= p;
(x *= x) %= p;
n >>= 1;
}
return ret;
}
int main() {
int h, w;
cin >> h >> w;
vector<string> s(h + 2);
vector<vector<ll>> cross(h + 2, vector<ll>(w+2));
s[0] = string(w + 2, '#');
s[h+1] = string(w + 2, '#');
for (int i = 1; i <= h; ++i) {
cin >> s[i];
s[i] = '#' + s[i] + '#';
}
ll l = 0;
for (int i = 1; i <= h; ++i) {
ll temp = 0;
for (int j = 0; j <= w; ++j) {
if (s[i][j] == '.') {
cross[i][j] += temp - 1;
l++;
continue;
}
temp = 0;
for (int k = j + 1; k <= w; ++k) {
if (s[i][k] == '.') temp++;
else break;
}
}
}
for (int j = 1; j <= w; ++j) {
ll temp = 0;
for (int i = 0; i <= h; ++i) {
if (s[i][j] == '.') {
cross[i][j] += temp;
continue;
}
temp = 0;
for (int k = i + 1; k <= h; ++k) {
if (s[k][j] == '.') temp++;
else break;
}
}
}
ll result = 0;
for (int i = 1; i <= h; ++i) {
for (int j = 1; j <= w; ++j) {
result += (mod_pow(2ll, cross[i][j], mod) - 1) * (mod_pow(2ll, l - cross[i][j], mod)) % mod;
result %= mod;
}
}
cout << result << endl;
}
| #include<bits/stdc++.h>
#define _USE_MATH_DEFINES
using namespace std;
#define ll long long int
#define ld double
#define pb push_back
#define rep(i , j , n) for(ll i = j ; i < n ; i++)
#define pre(i , j , n) for(ll i = j ; i >= n ; i--)
#define all(x) x.begin(), x.end()
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef pair<ll,ll> pll;
#define br "\n"
#define ff first
#define ss second
#define MAXIM 4000001
ll mod = 1e9 + 7;
vector<vll> v,row,col;
vll pw2(MAXIM);
ll bin_exp(ll a, ll b){
a = a % mod;
ll ans = 1;
while(b > 0){
if(b & 1 == 1) ans = (a * ans) % mod;
a = (a * a) % mod;
b = b >> 1;
}
return ans;
}
void calc(){
pw2[0] = 1;
rep(i,1,MAXIM){
pw2[i] = pw2[i - 1]*2;
while(pw2[i] > mod) pw2[i] -= mod;
}
}
void solve(){
ll n,m;
cin >> n >> m;
v.assign(n,vll(m));
row.assign(n,vll(1,-1)),
col.assign(m,vll(1,-1));
ll dot = 0;
rep(i,0,n){
rep(j,0,m){
char c;
cin >> c;
if(c == '.'){
v[i][j] = 1;
dot++;
}
else{
v[i][j] = 0;
row[i].pb(j);
col[j].pb(i);
}
}
}
rep(i,0,n) row[i].pb(m);
rep(j,0,m) col[j].pb(n);
ll ans = 0;
rep(i,0,n){
rep(j,0,m){
if(v[i][j] == 0) continue;
ll x1 = upper_bound(all(row[i]),j) - row[i].begin();
ll x2 = upper_bound(all(col[j]),i) - col[j].begin();
ll temp = (row[i][x1] - row[i][x1 - 1] - 1) + (col[j][x2] - col[j][x2 - 1] - 1) - 1;
ll t1 = (pw2[temp] - 1 + mod);
ll t2 = pw2[dot - temp];
ll t = t1*t2;
if(t > mod) t %= mod;
ans += t;
if(ans > mod) ans -= mod;
}
}
cout << ans << br;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ll t = 1;
calc();
// cin >> t;
rep(i,0,t){
// cout << "Case #" << i + 1 << ": ";
solve();
}
} |
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main() {
long long a, b, c, d;
cin >> a >> b >> c >> d;
if (b >= c*d) {
cout << -1 << '\n';
return 0;
}
for (int i=0; ; i++) {
if ((a + i*b) <= (i*c*d)) {
cout << i << '\n';
break;
}
}
return 0;
}
| #include<bits/stdc++.h>
#define ll int
#define pii pair<ll,ll>
#define debug(a) cout<<a<<'\n'
#define maxn 100009 /// I wanna be withma youlu
#define MOD 1000000007
#define F first
#define S second
#define rep(i, a, b) for( ll i = a; i < (b); ++i)
#define per(i, b, a) for(ll i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (ll)(x).size()
using namespace std;
const ll INF = 2e9 + 9;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
ll a,b,w;
cin>>a>>b>>w;
w*=1000;
ll mini = INF,maxi = -1;
for(int i = 1;;i++){
ll minv = a*i;
ll maxv = b*i;
if(minv > w)
break;
if(minv<=w && maxv>=w){
mini = min(mini,i);
maxi = max(maxi,i);
}
}
if(mini == INF) cout<<"UNSATISFIABLE"<<'\n';
else cout<<mini<<" "<<maxi<<endl;
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#define GODSPEED ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(15);
#define f first
#define s second
#define newl cout<<"\n";
#define pb push_back
#define mset(a,x) memset(a,x,sizeof(a))
#define debv(a) for(auto it: a)cout<<it<<" ";newl;
#define deb1(a) cout<<a<<"\n";
#define deb2(a,b) cout<<a<<" "<<b<<"\n";
#define deb3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n";
#define deb4(a,b,c,d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n";
#define uniq(a) a.resize(unique(a.begin(), a.end()) - a.begin());
#define all(a) a.begin(),a.end()
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
const ll N = 1e5 + 5;
const ll mod = 1e9 + 7;
const ll INF = 0x7f7f7f7f7f7f7f7f;
const int INFi = 0x7f7f7f7f;
const ll LEVEL = log2(N) + 1;
ll n, m, d[25][25], vis[25], ans = 0, v[25];
vector <int> s;
void dfs(int x) {
vis[x] = 1;
s.pb(x);
for (int i = 1; i <= n; i++) {
if (vis[i] == 1 || d[x][i] == 0) continue;
dfs(i);
}
}
void rec(int i) {
if (i == s.size()) {
ans++;
return;
}
vector <int> p(n + 1, 0);
if (v[s[i]] == 7) return;
for (int k = 1; k <= n; k++) p[k] = v[k];
for (int j = 0; j < 3; j++) {
if (v[s[i]]&(1<<j)) continue;
for (int k = 1; k <= n; k++) {
if (d[s[i]][k] == 0) continue;
v[k] |= (1<<j);
}
rec(i + 1);
for (int k = 1; k <= n; k++) v[k] = p[k];
}
}
void solve() {
cin >> n >> m;
for (int i = 1; i <= m; i++) {
int a, b; cin >> a >> b;
d[a][b] = d[b][a] = 1;
}
ll res = 1;
for (int i = 1; i <= n; i++) {
if (vis[i] == 0) {
s.clear();
ans = 0;
dfs(i);
rec(0);
res *= ans;
}
}
deb1(res)
}
int main() {
GODSPEED;
int test = 1;
// cin >> test;
for (int i = 1; i <= test; i++) {
solve();
}
} | #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pint = pair<ll,ll>;
vector<ll> bipartite(const vector<vector<ll>>& hen) {
ll n = hen.size();
vector<ll> col(n, -1);
col[0] = 0;
stack<ll> st;
for(ll i = n - 1; i >= 0; i--) st.push(i);
while(st.size()) {
ll v = st.top(); st.pop();
// print(v);
if(col[v] == -1) col[v] = 0;
for(auto i : hen[v]) {
if(col[i] != -1) {
if(col[i] == col[v]) return {-1};
continue;
} else {
col[i] = !col[v];
st.push(i);
}
}
// print(col);
}
vector<ll> red;
red.reserve(count(col.begin(), col.end(), 0));
for(ll i = 0; i < (ll)col.size(); i++) if(col[i] == 0) red.push_back(i);
return red;
}
#pragma region UnionFind
#define UNIONFIND
class UnionFind{
private:
vector<ll> data;
public:
UnionFind(ll n) : data(n,-1) {}
ll root(ll i) { return data[i] < 0 ? i : data[i] = root(data[i]); }
ll size(ll i) { return -data[root(i)]; }
bool same(ll x, ll y) {return root(x) == root(y); }
bool connected() {return size(0) == (ll)data.size(); }
bool unit(ll i,ll j){
i = root(i);
j = root(j);
if(i != j){
data[i] += data[j];
data[j] = i;
}
return i != j;
}
};
#pragma endregion
#define bitget(n,k) (((n)>>(k))&1) /*nのk bit目*/
int main()
{
ll N, M; cin >> N >> M;
vector<vector<ll>> hen(N);
for(ll i = 0; i < M; i++) {
ll u, v; cin >> u >> v;
u--,v--;
hen[u].push_back(v);
hen[v].push_back(u);
}
ll sum = 0;
for(ll bit = 0; bit < (1<<N); bit++) {
vector<ll> vers;
vector<vector<ll>> edge(N);
bool ok = true;
for(ll i = 0; i < N; i++) {
if(bitget(bit, i)) {
for(auto j : hen[i]) {
if(bitget(bit, j)) {
ok = false;
break;
}
}
} else {
for(auto j : hen[i]) {
if(bit & (1<<j)) continue;
edge[i].push_back(j);
}
}
}
if(ok == false)continue;
// print(bit, edge);
auto v = bipartite(edge);
if(v == vector<ll>{-1})continue;
UnionFind uni(N);
for(ll i = 0; i < N; i++) {
for(auto j : edge[i]) {
uni.unit(i, j);
}
}
set<ll> st;
for(ll i = 0; i < N; i++) {
if(bit & (1<<i))continue;
st.insert(uni.root(i));
}
sum += (1LL<<(int)st.size());
}
cout << sum << endl;
}
|
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std; //using namespace atcoder;
template<typename T> using ve=vector<T>;
using ll=long long; using ld=long double; using str=string; using pint=pair<ll,ll>;
using vll=ve<ll>; using vd=ve<ld>; using vs=ve<str>; using vll2=ve<ve<ll>>;
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#define b2e(v) v.begin(),v.end()
#define p2a(v, p) v[p.first][p.second]
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repi(i,n) for(ll i=(n-1);i>=0;i--)
#define repe(e,v) for(auto e:v)
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
const int MOD=1000000007;
//const int MOD=998244353;
ll divceil (ll x, ll div) { return (x/div) + (x%div>0); }
ll divfloor(ll x, ll div) { return (x/div) - (x%div<0); }
int main() {
ll kn; cin >> kn;
ll nn; cin >> nn;
ll mn; cin >> mn;
vll a1(kn);
rep(i,kn) {
ll x;
cin >> x; a1[i]=x;
}
// 1. 剰余なしの値を設定B=(floor(MA/N))
ll ct=0;
vll b1(kn);
ve<ld> lb1(kn, 0);
rep(i,kn) {
b1[i] =divfloor(mn*a1[i],nn);
if(a1[i]) lb1[i] =(ld)(mn*a1[i])/(ld)nn;
ct+=b1[i];
}
// 2. 誤差とidxのpairの配列を作成(floorなしB-B)
vector<pair<ld,ll>> vp1;
rep(i,kn) {
vp1.push_back({lb1[i]-(ld)b1[i],i});
}
// 3. 配列を誤差で降順ソート
sort( vp1.begin(), vp1.end(), greater<pair<ld,ll>>() );
// 4. 剰余分を更新
rep(i,mn-ct) {
b1[vp1[i].second]++;
}
rep(i,kn) {
cout << b1[i] << " ";
}
cout << endl;
}
| // B - Village of M People
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,e) for(int i=0;i<(e);++i)
int main(){
int k, n, m; cin>>k>>n>>m;
vector<ll> B;
vector<pair<ll,ll>> R;
ll rest = m;
rep(i, k){
ll a; cin>>a;
ll b = a*m / n;
rest -= b;
B.push_back(b);
R.emplace_back(a*m % n, i);
}
sort(R.rbegin(), R.rend());
rep(i, rest) B[R[i].second] += 1;
rep(i, k) cout<< B[i] <<(i < k-1? " ":"\n");
}
|
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll=long long;
int main(){
int n;
cin >> n;
vector<int> a(n);
rep(i,n) cin >> a[i];
ll ans=0;
rep(i,n){
ll sum=a[i];
int k=i-1;
while(0<=k){
if(a[k]<a[i]) break;
sum+=a[i];
k--;
}
k=i+1;
while(k<n){
if(a[k]<a[i]) break;
sum+=a[i];
k++;
}
ans=max(ans,sum);
}
cout << ans << endl;
} | #include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cassert>
#include <functional>
using ll = long long;
using namespace std;
template<typename A, typename B>
bool chmin(A &a, const B b) {
if (a <= b) return false;
a = b;
return true;
}
template<typename A, typename B>
bool chmax(A &a, const B b) {
if (a >= b) return false;
a = b;
return true;
}
#ifndef LOCAL
#define debug(...) ;
#else
#define debug(...) cerr << __LINE__ << " : " << #__VA_ARGS__ << " = " << _tostr(__VA_ARGS__) << endl;
template<typename T>
ostream &operator<<(ostream &out, const vector<T> &v);
template<typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
out << "{" << p.first << ", " << p.second << "}";
return out;
}
template<typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
out << '{';
for (const T &item : v) out << item << ", ";
out << "\b\b}";
return out;
}
void _tostr_rec(ostringstream &oss) {
oss << "\b\b \b";
}
template<typename Head, typename... Tail>
void _tostr_rec(ostringstream &oss, Head &&head, Tail &&...tail) {
oss << head << ", ";
_tostr_rec(oss, forward<Tail>(tail)...);
}
template<typename... T>
string _tostr(T &&...args) {
ostringstream oss;
int size = sizeof...(args);
if (size > 1) oss << "{";
_tostr_rec(oss, forward<T>(args)...);
if (size > 1) oss << "}";
return oss.str();
}
#endif
constexpr int mod = 1'000'000'007; //1e9+7(prime number)
constexpr int INF = 1'000'000'000; //1e9
constexpr ll LLINF = 2'000'000'000'000'000'000LL; //2e18
constexpr int SIZE = 200010;
int main() {
int N, A[SIZE];
scanf("%d", &N);
for (int i = 0; i < N; i++) {
scanf("%d", A + i);
}
ll ans = 0;
for (int i = 0; i < N; i++) {
int minA = INF;
for (int j = i + 1; j <= N; j++) {
chmin(minA, A[j - 1]);
chmax(ans, minA * (j - i));
}
}
cout << ans << endl;
return 0;
} |
#include <bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define inf 1000000000000000001
#define mod 1000000007
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define pb push_back
#define f first
#define s second
#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL);
#define precise fixed(cout);cout<<setprecision(16);
#define Set(N,p) N=((N)|((1LL)<<(p)))
#define Reset(N,p) N=((N)&(~((1LL)<<(p))))
#define Check(N,p) (!(((N)&((1LL)<<(p)))==(0)))
#define POPCOUNT __builtin_popcountll
#define RIGHTMOST __builtin_ctzll
#define LEFTMOST(x) (63-__builtin_clzll((x)))
#define NUMDIGIT(x,y) (((vlong)(log10((x))/log10((y))))+1)
#define OUT(x) for(auto a:x) cout << a << " "; cout << endl;
#define OK cout << "@===================ok===================@" <<endl;
#define WTF cout <<"< "<<lo<<" | "<< hi <<" >" << endl;
using namespace std;
vll temp;
void prec(){
ll x=1;
while(x<=1e16){
x*=1000;
temp.pb(x);
}
}
int main()
{
prec();
ll n;
cin >> n;
ll res=0;
for(auto a:temp){
if(a>n) break;
ll dist=n-a+1;
res+=dist;
}
cout << res <<"\n";
}
| //雪花飄飄北風嘯嘯
//天地一片蒼茫
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define lb lower_bound
#define ub upper_bound
#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
//change less to less_equal for non distinct pbds, but erase will bug
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
int n;
int arr[3005][5];
int val[3005];
int memo[3005][32][4];
int dp(int i,int j,int k){
if (k==4) return 0;
if (i==n) return j==31;
if (memo[i][j][k]!=-1) return memo[i][j][k];
return memo[i][j][k]=max(dp(i+1,j,k),dp(i+1,j|val[i],k+1));
}
bool can(int i){
rep(x,0,n){
val[x]=0;
rep(y,0,5) if (arr[x][y]>=i) val[x]|=(1<<y);
}
//cout<<i<<endl;
//rep(x,0,n) cout<<val[x]<<" "; cout<<endl;
memset(memo,-1,sizeof(memo));
return dp(0,0,0);
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin.exceptions(ios::badbit | ios::failbit);
cin>>n;
rep(x,0,n) rep(y,0,5) cin>>arr[x][y];
int lo=0,hi=1e9+5,mi;
while (hi-lo>1){
mi=hi+lo>>1;
if (can(mi)) lo=mi;
else hi=mi;
}
cout<<lo<<endl;
}
|
#include <bits/stdc++.h>
#define int long long
#define loop(i, a, b) for (int i = a; i < b; i++)
#define loope(i, a, b) for (int i = a; i <= b; i++)
#define bloop(i, a, b) for (int i = a; i >= b; i--)
#define FastIO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
#define PRECISION \
std::cout.unsetf(std::ios::fixed); \
std::cout.precision(9)
#define scan(a, n) \
for (int i = 0; i < n; i++) \
cin >> a[i]
#define print(a, n) \
for (int i = 0; i < n; i++) \
{ \
cout << a[i] << ' '; \
} \
cout << '\n'
using namespace std;
int mod = 1e9 + 7;
void solve()
{
long double a,b;
cin>>a>>b;
cout<<a*(b/100)<<"\n";
}
int32_t main()
{
FastIO;
PRECISION;
int t = 1;
// cin >> t;
while (t--)
{
solve();
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define flush cout.flush
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pl = pair<ll, ll>;
const ll INF = 1e9 + 7;
const ll mod = 1e9 + 7;
const ll mod2 = 998244353;
const ld eps = 1e-9;
const ld PI = acos(-1);
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
ld a, b;
cin >> a >> b;
a /= 100;
cout << fixed << setprecision(20);
cout << a * b << "\n";
return 0;
} |
#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 all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cerr << #x << " = " << (x) << endl
#define show2(x,y) cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second)
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) (find(all(v),x)!=v.end())
#define incls(s,c) (s.find(c)!=string::npos)
#define lb(a,x) distance((a).begin(),lower_bound(all(a),(x)))
#define ub(a,x) distance((a).begin(),upper_bound(all(a),(x)))
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(all(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
//const int mod = 1000000007;
const double EPS = 1e-9;
//const long double EPS = 1e-14;
const int INF = (1<<30)-1;
const ll LINF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define YN {puts("YES");}else{puts("NO");}
inline int in() { int x; cin >> x; return x;}
inline ll lin() { ll x; cin >> x; return x;}
inline char chin() { char x; cin >> x; return x;}
inline string stin() { string x; cin >> x; return x;}
inline double din() { double x; cin >> x; return x;}
//template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const vector<T>& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
char itoa(int n) { return n + '0';}
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
const int dy[4] = {1, 0, -1, 0};
const int dx[4] = {0, 1, 0, -1};
int main () {
int n;
cin >> n;
vi x(n), y(n), z(n);
rep(i,n) cin >> x[i] >> y[i] >> z[i];
int n2 = 1<<n;
vvi dp(n2,vi(n,INF));
vvi dist(n,vi(n));
rep(i,n)rep(j,n) {
int now = abs(x[i]-x[j]);
now += abs(y[i]-y[j]);
now += max(0, z[j]-z[i]);
dist[i][j] = now;
}
rep(i,n) {
//if (i == 0) continue;
dp[1<<i][i] = dist[0][i];
}
rep(i,n2)rep(j,n) {
// j: 現在いる都市
if (~i>>j&1) continue; // 既に訪れているかの確認
rep(k,n) {
// k: 次に訪れる都市
if (i>>k&1) continue; // まだ訪れていないかの確認
chmin(dp[i|1<<k][k], dp[i][j]+dist[j][k]);
}
}
cout << dp[n2-1][0] << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(int)n; i++)
#define INF 1e9
const int MAXN=20;
int n;
int d[MAXN][MAXN];
int dp[1<<MAXN][MAXN];
int rec(int S, int v) {
if(dp[S][v] >= 0) return dp[S][v];
if(S==(1<<n)-1 && v==0) return dp[S][v]=0;
int tmp=INF;
REP(u,n) if(!(S>>u & 1)) tmp=min(tmp, rec(S|1<<u,u)+d[v][u]);
return dp[S][v]=tmp;
}
int main() {
cin>>n;
REP(i,n) REP(j,n) d[i][j]=d[j][i]=INF;
vector<tuple<int,int,int>> data(n);
REP(i,n){
int x,y,z;
cin>>x>>y>>z;
data.at(i)=make_tuple(x,y,z);
}
REP(s,n){
REP(t,n){
d[s][t]=abs(get<0>(data.at(t))-get<0>(data.at(s)))+abs(get<1>(data.at(t))-get<1>(data.at(s)))+max(0,get<2>(data.at(t))-get<2>(data.at(s)));
}
}
fill((int *)dp, (int *)(dp+(1<<MAXN)), -1);
cout << rec(0,0) << endl;
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=1e3+5,M=2e4+5,inf=0x3f3f3f3f,mod=1e9+7;
#define mst(a,b) memset(a,b,sizeof a)
#define PII pair<int,int>
#define fi first
#define se second
#define pb emplace_back
#define SZ(a) (int)a.size()
#define IOS ios::sync_with_stdio(false),cin.tie(0)
void Print(int *a,int n){
for(int i=1;i<n;i++)
printf("%d ",a[i]);
printf("%d\n",a[n]);
}
bitset<N>vis;
int p[N],cnt;
void ss(int n){
vis[0]=vis[1]=1;
for(int i=2;i<=n;i++){
if(!vis[i]) p[++cnt]=i;
for(int j=1;j<=cnt&&i*p[j]<=n;j++){
vis[i*p[j]]=1;
if(i%p[j]==0) break;
}
}
}
ll dp[1<<20];
int main(){
ss(72);
ll A,B;scanf("%lld%lld",&A,&B);
dp[0]=1;
//Print(p,cnt);
for(ll i=A;i<=B;i++){
int msk=0;
for(int j=1;j<=cnt;j++) if(i%p[j]==0) msk|=(1<<(j-1));
for(int j=0;j<(1<<cnt);j++)
if(!(msk&j)) dp[msk|j]+=dp[j];
}
ll s=0;
for(int i=0;i<(1<<cnt);i++) s+=dp[i];
printf("%lld\n",s);
return 0;
}
| #include<bits/stdc++.h>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include<map>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double lb;
#define rep(i, f, t) for(int i = f; i <= t; i ++)
#define urep(i, f, t) for(int i = f; i >= t; i --)
#define pb push_back
#define eb emplace_back
#define pq priority_queue
#define umap unordered_map
#define addr(v) v.begin(), v.end()
#define uaddr(v) v.rbegin(), v.rend()
#define mst(arr, val) memset(arr, val, sizeof arr)
#define qstream std::ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//when qstream exists , cout and printf can't be used together
//
#define ls(t) (t << 1)
#define rs(t) (t << 1 | 1)
#define lowbit(x) ((x) & (-(x)))
#define ceil_div(a, b) ((a) + (b) - 1) / (b)
const ll INF = 1e18 + 7;
const int inf = 0x3f3f3f3f;
const int maxn = 1050;
const int Maxn = 5e5 + 5;
const int mod = 1e9 + 7;
const int MOD = 100003;
const int Mod = 998244353;
const int D = 233;//HASH
const double PI = acos(-1.0);
// tips: i int for_loop i*i can't be used for long long
int n, m;
struct Edge {
int to, next;
char w;
}e[Maxn];
int head[maxn], id;
struct nd {
int a, b;
};
int dis[maxn][maxn];
void add(int u, int v, char w) {
e[id].to = v;
e[id].w = w;
e[id].next = head[u];
head[u] = id ++;
}
queue<nd> q;
int main() {
qstream;
mst(dis, inf);
mst(head, -1);
cin >> n >> m;
rep(i, 1, m) {
int u, v;
char w;
cin >> u >> v >> w;
add(u, v, w);
add(v, u, w);
}
rep(i, 1, n) {
dis[i][i] = 0;
q.push({i, i});
}
rep(j, 1, n) {
for(int i = head[j]; i != -1; i = e[i].next) {
int v = e[i].to;
if(j >= v) continue;
dis[j][v] = dis[v][j] = 1;
q.push({j, v});
}
}
while(!q.empty()) {
int x = q.front().a, y = q.front().b;
q.pop();
//cout << x << " " << y << endl;
for(int i = head[x]; i != -1; i = e[i].next) {
int tx = e[i].to;
for(int j = head[y]; j != -1; j = e[j].next) {
int ty = e[j].to;
if(e[i].w == e[j].w && tx != ty) {
if(dis[tx][ty] > dis[x][y] + 2) {
dis[ty][tx] = dis[tx][ty] = dis[x][y] + 2;
q.push({tx, ty});
}
}
}
}
}
cout << (dis[1][n] == inf ? -1 : dis[1][n]) << endl;
// #ifndef ONLINE_JUDGE
// system("pause");
// #endif
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int Maxn = 1000005;
char tmp[Maxn];
int n;
string A;
string B;
void Read(string &s)
{
scanf("%s", tmp); s = tmp;
}
int main()
{
cin >> n;
Read(A);
Read(B);
int asum = 0, bsum = 0;
int add = 0, neutr = 0;
ll res = 0;
for (int i = 0; i < n; i++) if (A[i] != '1' || B[i] != '1') {
asum += A[i] == '1';
bsum += B[i] == '1';
if (A[i] == '0' && B[i] == '1') add++;
if (A[i] == '0' && B[i] == '0') neutr++;
if (asum == bsum) {
if (add > 0) res += add + neutr;
add = neutr = 0;
}
}
printf("%lld\n", asum != bsum? -1ll: res);
return 0;
}
| #include<iostream>
#include<algorithm>
using namespace std;
const int N=100010;
typedef long long ll;
int n;
char a[N];
int sum1[N];
int sum2[N];
int main()
{
cin>>n;
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<=n;i++)
{
if(a[i]=='A')
{
sum1[i]=1;
}
else if(a[i]=='T')
{
sum1[i]=-1;
}
else if (a[i]=='C')
{
sum2[i]=1;
}
else if (a[i]=='G')
{
sum2[i]=-1;
}
}
for(int i=1;i<=n;i++)
{
sum1[i]+=sum1[i-1];
sum2[i]+=sum2[i-1];
}
//只有5000,可以枚举两个区间
ll ans=0;
for(int i=1;i<=n;i++)
for(int j=i;j<=n;j++)
{
if(sum1[j]-sum1[i-1]==0&&sum2[j]-sum2[i-1]==0)ans++;
}
cout<<ans;
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
int main() {
double A, B;
cin >> A >> B;
double f = 0.00;
f = B /A;
f = 1-f;
f=f*100;
cout << f << endl;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0,endrep=(n); i<endrep; ++i)
#define rep1(i,n) for(ll i=1,endrep=(n); i<=endrep; ++i)
#define revrep(i,n) for(ll i=(n)-1; i>=0; --i)
inline constexpr ll Inf = (1ULL << 60) -123456789;
#define fastio cin.tie(nullptr); ios_base::sync_with_stdio(false);
#define newl '\n'
#define YN(e) ((e)?"Yes":"No")
#define all(a) begin(a),end(a)
#define rall(a) rbegin(a),rend(a)
template <class T,class U> bool updmax(T& a, U b) { if(b>a){ a=b; return true;} return false;}
template <class T,class U> bool updmin(T& a, U b) { if(b<a){ a=b; return true;} return false;}
inline constexpr int Mod = 1000000007;
//inline constexpr int Mod = 998244353;
#define dbg(a) cout << #a << ": " << a << endl;
#define dbg1(a,n) cout<<#a<<": "; rep(i,n) cout<<a[i]<<" "; cout<<endl;
#define dbg2(m,h,w) cout<<#m<<":"<<endl; rep(i,h){ rep(j,w)cout<<m[i][j]<<" "; cout<<endl; }
int rng(int n) { return rand()/(RAND_MAX+1.0)*n; }
int main() {
fastio;
double ans{};
ll a,b;
cin >> a >> b;
ans = (1-(double)b/a)*100;
cout << ans << endl;
}
|
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(x) (int) x.size()
#define cat(x) cerr << #x << " = " << x << endl
#define all(x) x.begin(), x.end()
#define rep(i, j, n) for (int i = j; i <= n; ++i)
#define per(i, j, n) for (int i = n; j <= i; --i)
using ll = long long;
using ld = long double;
using namespace std;
string a = "atcoder#";
int f(int pref, int c, string s) {
int ans = 0, n = sz(s);
rep(i, 0, pref) {
char C = (i == pref ? (char)('a' + c) : a[i]);
int g = -1;
rep(j, i, n - 1) {
if (s[j] == C) {
g = j;
break;
}
}
if (g == -1) return 1e9;
per(j, i + 1, g) {
ans++;
swap(s[j - 1], s[j]);
}
}
return ans;
}
int main() {
int t;
cin >> t;
while (t--) {
string s;
cin >> s;
int n = sz(s);
int res = 1e9;
rep(i, 0, 7)
rep(c, 0, 25) {
if (i + 1 > n) continue;
if ((char) ('a' + c) <= a[i]) continue;
//~ cout << i << " " << c << " " << f(i, c, s) << endl;
res = min(res, f(i, c, s));
}
if (res == 1e9) res = -1;
printf ("%d\n", res);
}
return 0;
}
| #include <bits/stdc++.h>
#define INF 1e9
#define INFLL 1ull<<60u
using namespace std;
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a) (a).begin(),(a).end()
#define endl "\n"
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
typedef long long ll;
using vi = vector<int>;
using vvi = vector<vi>;
using vpii = vector<pair<int,int>>;
void solve() {
int N,S,D; cin >> N >> S >> D;
REP(_,N) {
int X,Y; cin >> X >> Y;
if (S > X && D < Y) {
cout << "Yes" << endl;
return;
}
}
cout << "No" << endl;
}
int main() {
solve();
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
// template <class T = ll> using P = pair< T,T>;
template <class T = ll> using V = vector<T>;
template <class T = ll> using VV = V<V<T>>;
#define rep(i,n) for(int i=0; i<(n);++i)
#define repp(i, l, r) for(int i = (l); i < (r); ++i)
#define pb push_back
#define all(v) (v).begin(), (v).end()
int main()
{
int n;
cin >> n;
V<pair<int,int>> x(n);
V<pair<int,int>> y(n);
rep(i, n) {
cin >> x[i].first >> y[i].first;
x[i].second = i;
y[i].second = i;
}
sort(all(x), greater<pair<int,int>>());
sort(all(y), greater<pair<int,int>>());
V<pair<pair<int,int>,int>> ans;
{
pair<pair<int,int>,int> can;
pair<int,int> a;
a.first = x[0].second;
a.second = x[n-1].second;
can.first = a;
can.second = x[0].first - x[n-1].first;
ans.push_back(can);
}
{
pair<pair<int,int>,int> can;
pair<int,int> a;
a.first = y[0].second;
a.second = y[n-1].second;
can.first = a;
can.second = y[0].first - y[n-1].first;
ans.push_back(can);
}
{
pair<pair<int,int>,int> can;
pair<int,int> a;
a.first = x[1].second;
a.second = x[n-1].second;
can.first = a;
can.second = x[1].first - x[n-1].first;
ans.push_back(can);
}
{
pair<pair<int,int>,int> can;
pair<int,int> a;
a.first = x[0].second;
a.second = x[n-2].second;
can.first = a;
can.second = x[0].first - x[n-2].first;
ans.push_back(can);
}
{
pair<pair<int,int>,int> can;
pair<int,int> a;
a.first = y[1].second;
a.second = y[n-1].second;
can.first = a;
can.second = y[1].first - y[n-1].first;
ans.push_back(can);
}
{
pair<pair<int,int>,int> can;
pair<int,int> a;
a.first = y[0].second;
a.second = y[n-2].second;
can.first = a;
can.second = y[0].first - y[n-2].first;
ans.push_back(can);
}
sort(all(ans), [](auto lhs, auto rhs){return lhs.second > rhs.second;});
ll cnt = 0;
pair<int,int> pre;
for(auto abc : ans){
if(pre == abc.first) continue;
cnt++;
pre = abc.first;
if(cnt == 2){
cout << abc.second << endl;
}
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define lowbit(x) (x & (-x))
const LL inf = 1e17+9;
const LL mod = 1e9+7;
const LL maxn = 3e5+8;
LL n, m, a[maxn], bit[maxn];
void add(LL x, LL v) {
while (x <= n) {
bit[x] += v;
x += lowbit(x);
}
}
LL query(LL x) {
LL ans = 0;
while (x > 0) {
ans += bit[x];
x -= lowbit(x);
}
return ans;
}
void solve() {
LL i, cnt = 0;
scanf("%lld", &n);
for (i = 1; i <= n; i++) {
scanf("%lld", &a[i]); a[i]++;
cnt += query(n) - query(a[i]);
add(a[i], 1);
}
printf("%lld\n", cnt);
for (i = 1; i < n; i++) {
cnt += (n - a[i]) - (a[i] - 1);
printf("%lld\n", cnt);
}
}
signed main() {
LL t;
//scanf("%lld", &t);
//while (t--)
solve();
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define debug(x) {cerr<<#x<<" = "<<(x)<<endl;}
ll ksm(ll a,ll k,ll p)
{
ll ans=1;
while(k)
{
if(k&1) ans=ans*a%p;
k>>=1;
a=a*a%p;
}
return ans;
}
int sz[10][4] = {
{0,0,0,0},
{1,1,1,1},
{6,2,4,8},
{1,3,9,7},
{6,4,6,4},
{5,5,5,5},
{6,6,6,6},
{1,7,9,3},
{6,8,4,2},
{1,9,1,9}
};
int main()
{
ios::sync_with_stdio(false);
ll a,b,c; cin>>a>>b>>c;
cout<<sz[a%10][ksm(b,c,4)];
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
ll n, x;
string s;
cin >> n >> x >> s;
for (int i = 0; i < n; i++)
{
if (x > 0 && s[i] == 'x')
x--;
else if (s[i] == 'o')
x++;
}
cout << x << endl;
} |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> t(N);
vector<double> l(N), r(N);
for (int i = 0; i < N; i++) scanf("%d %lf %lf", &t[i], &l[i], &r[i]);
int Ans = 0;
for (int i = 0; i < N - 1; i++) {
double l1, r1;
if (t[i] == 1) l1 = l[i], r1 = r[i];
else if (t[i] == 2) l1 = l[i], r1 = r[i] - 0.1;
else if (t[i] == 3) l1 = l[i] + 0.1, r1 = r[i];
else l1 = l[i] + 0.1, r1 = r[i] - 0.1;
for (int j = i + 1; j < N; j++) {
double l2, r2;
if (t[j] == 1) l2 = l[j], r2 = r[j];
else if (t[j] == 2) l2 = l[j], r2 = r[j] - 0.1;
else if (t[j] == 3) l2 = l[j] + 0.1, r2 = r[j];
else l2 = l[j] + 0.1, r2 = r[j] - 0.1;
if (r1 < l2 || r2 < l1) continue;
Ans++;
}
}
cout << Ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef tuple<ll, ll, ll> ti;
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;
//using Bint = mp::cpp_int;
#define REP(a,b,c) for(ll a=b;a<(c);a++)
#define PER(a,b,c) for(ll a=b;a>=(c);a--)
inline ll ii(){ ll x; cin >> x; return x; }
inline string is(){ string x; cin >> x; return x; }
inline ld id(){ ld x; cin >> x; return x; }
inline void oi(ll x){ cout << x; }
inline void od(ld x){ cout << fixed << setprecision(12) << x; }
inline void os(string x){ cout << x; }
inline void oe(){ cout << endl; }
inline void oie(ll x){ oi(x); oe(); }
inline void ode(ld x){ od(x); oe(); }
inline void ose(string x){ os(x); oe(); }
inline void maxin(ll &a, ll b){ a=max(a,b); }
inline void minin(ll &a, ll b){ a=min(a,b); }
int main(){
ll N=ii(), M=ii();
if(N==M){
oie(0);
return 0;
}
if(M==0){
oie(1);
return 0;
}
vector<ll> A;
REP(i,0,M){
A.push_back(ii());
}
sort(A.begin(), A.end());
ll cur=1;
ll k=112345678901;
vector<ll> B;
for(ll a:A){
if(a>cur){
B.push_back(a-cur);
minin(k,a-cur);
}
cur=a+1;
}
if(N>=cur){
B.push_back(N-cur+1);
minin(k,N-cur+1);
}
ll ret=0;
for(ll b:B){
ret+=b/k;
if(b%k>0){ret++;}
}
oie(ret);
return 0;
}
|
#include <bits/stdc++.h>
#define pb push_back
#define int long long
using namespace std;
#define debug(args...) kout("[ " + string(#args) + " ]", args)
void kout() { cerr << endl; }
template <class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ',kout(b...); }
template <class T> void pary(T L, T R) { while (L != R) cerr << *L << " \n"[++L==R]; }
const int MAXN = 200000;
const int INF = 1e18;
int n, m;
int x, y;
int a[MAXN+1];
vector <int> path[MAXN+1];
int mmin[MAXN+1];
int ans = -INF;
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 0; i < m; i++) {
cin >> x >> y;
path[x].pb(y);
}
for (int i = 1; i <= n; i++)
mmin[i] = INF;
for (int i = 1; i <= n; i++) {
if (mmin[i] != INF)
ans = max(ans, a[i] - mmin[i]);
mmin[i] = min(mmin[i], a[i]);
for (int j : path[i])
mmin[j] = min(mmin[j], mmin[i]);
}
cout << ans << "\n";
}
| #include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
#include <cstdint>
#include <string>
#include <sstream>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long ll;
using P=pair<int,int>;
const int INF=1001001001;
const int mod=1e9+7;
int main(){
int n,m;
cin>>n>>m;
vector<ll>a(n);
rep(i,n){cin>>a[i];}
vector<vector<int>>G(n);
rep(i,m){
int x,y;
cin>>x>>y;
x--;y--;
G[x].push_back(y);
}
vector<ll>buy(n,1e18);
ll ans=-1e18;
rep(i,n){
chmax(ans,a[i]-buy[i]);
for(int u:G[i]){
chmin(buy[u],min(buy[i],a[i]));
}
}
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 std;
using namespace __gnu_pbds;
typedef long long ll;
template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937/*_64*/ rng(chrono::steady_clock::now().time_since_epoch().count());
#define printArr(arr, n) cerr << #arr << " = ["; for(int i=0; i<(n); i++){if (i) cerr << ", "; cerr << arr[i];} cerr << "]\n"
template<class A> ostream& operator<<(ostream &cout, vector<A> const &v) {cout << "["; for(int i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]";};
template<class A, class B> ostream& operator<<(ostream &cout, const pair<A,B> &x) {return cout << "(" <<x.first << ", " << x.second << ")";};
void _print() {cerr << "]\n";}
template <class T, class... V> void _print(T t, V... v) {cerr << t; if (sizeof...(v)) cerr << ", "; _print(v...);}
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#define fi first
#define se second
#define SZ(x) (int)((x).size())
#define pii pair<int,int>
template<int modd> struct modint {
static const int mod = modd;
int v; explicit operator int() const { return v;}
modint() : v(0) {}
modint(ll x) : v(int(x%mod)) {if (v < 0) v += mod;}
friend bool operator==(const modint& a, const modint& b) {return a.v == b.v;}
friend bool operator!=(const modint& a, const modint& b) {return a.v != b.v;}
friend bool operator<(const modint& a, const modint& b) {return a.v < b.v;}
modint& operator+=(const modint& a) {if ((v += a.v) >= mod) v -= mod; return *this;}
modint& operator-=(const modint& a) {if ((v -= a.v) < 0) v += mod; return *this;}
modint& operator*=(const modint& a) {v = int((ll)v*a.v%mod); return *this;}
modint& operator/=(const modint& a) {return (*this) *= inv(a);}
friend modint pow(modint a, ll p) {modint ret = 1; for (; p; p /= 2, a *= a){if (p&1) ret *= a;} return ret;}
friend modint inv(const modint& a) {return pow(a,mod-2);}
modint operator-() const {return modint(-v);}
modint& operator++() {return *this += 1;}
modint& operator--() {return *this -= 1;}
friend modint operator+(modint a, const modint& b) {return a += b;}
friend modint operator-(modint a, const modint& b) {return a -= b;}
friend modint operator*(modint a, const modint& b) {return a *= b;}
friend modint operator/(modint a, const modint& b) {return a /= b;}
friend ostream& operator<<(ostream& out, modint a) {return out << a.v;}
friend istream& operator>>(istream& in, modint& a) {ll b; in >> b; a.v = b; return in;}
};
using mint = modint<998244353>;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n,m,k;
cin >> n >> m >> k;
if (n == 1) {
if (m == 1) {
cout << k << "\n";
} else {
mint x = k;
cout << pow(x,m) << "\n";
}
} else {
if (m == 1) {
mint x = k;
cout << pow(x,n) << "\n";
} else {
mint ans = 0;
for (int q = 1; q <= k; q++) {
mint x = pow(mint(q),n) - pow(mint(q-1),n);
x *= pow(mint(k-q+1),m);
ans += x;
}
cout << ans << "\n";
}
}
return 0;
}
| #include <sstream>
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <numeric>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <list>
#include <cassert>
#include <cmath>
#include <climits>
#include <map>
#include <queue>
#include <functional>
#include <cassert>
using namespace std;
int main()
{
#if 0
stringstream sstr;
sstr << R"()";
auto& in = sstr;
#else
auto& in = cin;
#endif
int N, M;
in >> N >> M;
if (M == 0) {
for (int i = 0; i < N; ++i) {
cout << (i + 1) * 2 << " " << (i + 1) * 2 + 1 << endl;
}
}
else if (M < 0 || M > (N-2)) {
cout << -1 << endl;
}
else {
for (int i = 0; i < M + 1; ++i) {
cout << (i + 1) * 2 << " " << (i + 1) * 2 + 1 << endl;
}
cout << 1 << " " << (M + 2) * 2 << endl;
int num = N - (M + 2);
for (int i = 0; i < num; ++i) {
cout << (M + 2) * 2 + 1 + i * 2 << " " << (M + 2) * 2 + 1 + i * 2 + 1 << endl;
}
}
return 0;
}
|
#pragma GCC optimize("Ofast") //Comment optimisations for interactive problems (use endl)
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define fastio ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
#define randomINIT mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define all(x) (x).begin(),(x).end()
#define mset(x,val) memset(x,val,sizeof(x))
#define endl "\n"
#define pb push_back
#define sym(s) s="#"+s+"#";
#define mp make_pair
#define s second
#define f first
#define dline cerr<<"///REACHED///\n";
#define debv(a) for(auto it: a)cout<<it<<" ";cout<<endl;
#define deb1(a) cout<<a<<endl;
#define deb2(a,b) cout<<a<<" "<<b<<endl;
#define deb3(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl;
#define deb4(a,b,c,d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
#define uniq(a) a.resize(unique(a.begin(), a.end()) - a.begin());
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
const ll MOD = 1e+9+7;
const ll INF = 0x7f7f7f7f7f7f7f7f;
const int INFi = 0x7f7f7f7f;
const ll N = 3e+5+7;
vll adj[N];ll vis[N]={};
int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1};
int dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};
//<<-----Declare Variable Here------->>//
int t=1;
ll n;
//<<-----Implement Functions Here---->>//
//<<-----Start of Main--------------->>//
void MAIN(){
string s;cin>>s;n = s.size();
reverse(all(s));
for(ll i=0;i<n;i++){
if(s[i] == '6')s[i] = '9';
else if(s[i] == '9')s[i] = '6';
}
cout<<s<<endl;
}
int main(){
fastio;randomINIT;
//cin>>t;
while(t--){
MAIN();
}
#ifndef ONLINE_JUDGE
cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
#endif
} | #include <bits/stdc++.h>
using namespace std;
int main()
{
string s;
cin >> s;
reverse(s.begin(), s.end());
for (int i = 0; i < s.size(); i++) {
if (s[i] == '6') s[i] = '9';
else if (s[i] == '9') s[i] = '6';
}
cout << s << endl;
} |
/**
* code generated by JHelper
* More info: https://github.com/AlexeyDmitriev/JHelper
* @author NikuKyabe
*/
#include <iostream>
#include <fstream>
#include <bits/stdc++.h>
#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define REV(i, a, b) for (int i = (b) - 1; i >= (a); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001l
#define MOD 1000000007
#define fcout cout << fixed << setprecision(12)
using namespace std;
typedef pair<int, int> P;
template<class T>
using M =vector<vector<T>>;
class BAtCoderCondominium {
public:
void solve(std::istream& cin, std::ostream& cout) {
int n,k;
cin >> n >> k;
int ans = 0;
REP(i,n)REP(j,k){
ans += (i+1) * 100 + (j+1);
}
cout << ans << endl;
}
};
signed main() {
BAtCoderCondominium solver;
std::istream& in(std::cin);
std::ostream& out(std::cout);
solver.solve(in, out);
return 0;
}
| #include<bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define all(k) k.begin(),k.end()
#define INF 1e9
#define repk(i,a,n) for(int i=a;i<=n;i++)
#define rep(i,a,n) for(int i=a;i<n;i++)
#define rep2(i,a, n) for(int i=a;i<n;i+=2)
#define per(i,a,n) for(int i=n-1;i>=a;i--)
#define pb push_back
#define ub pop_back
#define eb emplace_back
#define ll long long int
#define ull unsigned long long
#define pi pair<int,int>
#define vc vector<char>
#define vpi vector<pi>
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vi>
#define vb vector<bool>
#define pq priority_queue
#define vvc vector<vc>
#define mi map<int,int>
#define mset map<string,set<char>>
#define umap unordered_map
#define int int64_t
using namespace std;
#define fi first
#define se second
const int mod = int(1e9)+7;
int ar(int x,int y){
int res=1;
while(y){
if(y&1)
res=(res*x)%mod;
y>>=1;
x=((x*x)%mod);
}
return res;
}
int gcd(int x,int y){
if(x==0)
return y;
return gcd(y%x,x);
}
vvi dp;
int fun(int a, int b) {
if (dp[a][b] != -1) return dp[a][b];
else if(a == 0 || b == 0)
return dp[a][b] = 1;
else
return dp[a][b] = fun(a - 1, b) + fun(a, b - 1);
}
void sol()
{int a,b,k;
cin>>a>>b>>k;k--;
dp = vvi(a + 1, vi(b + 1, -1));
int cnt = k;
int ca = a, cb = b;
rep(i,0, a + b) {
if (ca == 0) {
cout << "b";
cb--;
continue;
}
if (cb == 0) {
cout << "a";
ca--;
continue;
}
if (fun(ca - 1, cb) > cnt) {
ca--;
cout << "a";
} else {
cnt -= fun(ca - 1, cb);
cb--;
cout << "b";
}
}
cout<<'\n';
}
int32_t main() {
int t=1;
// cin>>t;
for(int i=1;i<=t;++i){
// cout<<"Case #"<<i<<": ";
sol();
}
return 0;
}
|
/*input
10 165
82 94 21 65 28 22 61 80 81 79
93 35 59 85 96 1 78 72 43 5
12 15 97 49 69 53 18 73 6 58
60 14 23 19 44 99 64 17 29 67
24 39 56 92 88 7 48 75 36 91
74 16 26 10 40 63 45 76 86 3
9 66 42 84 38 51 25 2 33 41
87 54 57 62 47 31 68 11 83 8
46 27 55 70 52 98 20 77 89 34
32 71 30 50 90 4 37 95 13 100
*/
//#include "wall.h"
#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;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
#define ll long long
#define ld long double
#define pii pair<int,int>
#define piii pair<int,pii>
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define MP make_pair
const ll INF64=4e18;
const int INF=0x3f3f3f3f;
const ll MOD=998244353;
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
ll mult(ll a,ll b){
return ((a%MOD)*(b%MOD))%MOD;
}
ll mypow(ll a,ll b){
if(b<=0) return 1;
ll res=1LL;
while(b){
if(b&1){
res=(res*a)%MOD;
}
a=(a*a)%MOD;
b>>=1;
}
return res;
}
const ll maxn=50+5;
const ll maxlg=__lg(maxn)+2;
vector<int> r[maxn],c[maxn];
int arr[maxn][maxn];
bool vis[maxn];
int dfs(int u){
vis[u]=1;
int cnt=1;
for(auto x:r[u]){
if(!vis[x]) cnt+=dfs(x);
}
return cnt;
}
int dfs2(int u){
vis[u]=1;
int cnt=1;
for(auto x:c[u]){
if(!vis[x]) cnt+=dfs2(x);
}
return cnt;
}
ll fac[maxn];
int main(){
ios::sync_with_stdio(false),cin.tie(0);
int n,s;
cin>>n>>s;
fac[0]=1;
REP1(i,n) fac[i]=mult(fac[i-1],i);
REP(i,n) REP(j,n) cin>>arr[i][j];
REP(i,n){
REP(j,n){
bool wk=1;
REP(k,n){
if(arr[i][k]+arr[j][k]>s) wk=0;
}
if(wk){
r[i].pb(j);
}
}
}
REP(i,n){
REP(j,n){
bool wk=1;
REP(k,n){
if(arr[k][i]+arr[k][j]>s) wk=0;
}
if(wk){
c[i].pb(j);
}
}
}
ll ans=1;
REP(i,n){
if(!vis[i]){
ans=mult(ans,fac[dfs(i)]);
}
}
REP(i,n) vis[i]=0;
REP(i,n){
if(!vis[i]){
ans=mult(ans,fac[dfs2(i)]);
}
}
cout<<ans<<'\n';
} | #include <bits/stdc++.h>
using namespace std;
// one-based numbering
struct UnionFind {
vector<int> data;
// i: (data[i] < 0) -> group size, (data[i] > 0) -> parent;
UnionFind(int n) {
data.resize(n+1, -1);
}
int find(int x) {
if(data[x] < 0) return x;
else return data[x] = find(data[x]);
}
int size(int x) {
return -data[find(x)];
}
bool unite(int x, int y) {
x = find(x); y = find(y);
if(x == y) return false;
if (data[x] > data[y]) swap(x, y);
data[x] += data[y];
data[y] = x;
return true;
}
bool same(int x, int y) {
x = find(x); y = find(y);
return x == y;
}
};
int A[60][60];
constexpr long long mod = 998244353;
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int N, K; cin >> N >> K;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
cin >> A[i][j];
}
}
UnionFind X(N), Y(N);
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
bool ok = true;
for (int k = 0; k < N; k++) {
ok &= (A[i][k] + A[j][k] <= K);
}
if (ok) X.unite(i+1, j+1);
}
}
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
bool ok = true;
for (int k = 0; k < N; k++) {
ok &= (A[k][i] + A[k][j] <= K);
}
if (ok) Y.unite(i+1, j+1);
}
}
long long Ans = 1;
for (int i = 1; i < N; i++) {
if (X.find(i) == i) {
for (int j = X.size(i); j > 0; j--) {
Ans = Ans * j % mod;
}
}
}
for (int i = 1; i < N; i++) {
if (Y.find(i) == i) {
for (int j = Y.size(i); j > 0; j--) {
Ans = Ans * j % mod;
}
}
}
cout << Ans << "\n";
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false), cin.tie(nullptr);
int n;
cin >> n;
vector<int> a(n);
for (int &it : a) {
cin >> it;
it %= 200;
}
vector<int> p(200, -1);
if (n > 8) n = 8;
for (int m = 1; m < (1 << n); m++) {
int sum = 0;
for (int i = 0; i < n; i++) {
if ((m >> i) % 2 == 1) {
sum += a[i];
}
}
sum %= 200;
if (p[sum] != -1) {
cout << "Yes\n";
vector<int> b, c;
for (int i = 0; i < n; i++) {
if ((p[sum] >> i) % 2 == 1) {
b.push_back(i);
}
if ((m >> i) % 2 == 1) {
c.push_back(i);
}
}
cout << b.size();
for (int x : b) cout << ' ' << x + 1;
cout << '\n';
cout << c.size();
for (int x : c) cout << ' ' << x + 1;
cout << '\n';
return 0;
} else {
p[sum] = m;
}
}
cout << "No\n";
}
| #include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
template <class T, class U>ostream& operator<<(ostream& os, const pair<T, U>& p) {
os << "(" << p.first << " " << p.second << ")";
return os;
}
template <class T>ostream& operator<<(ostream& os, const vector<T>& v) {
rep(i, v.size()) {
if (i) os << " ";
os << v[i];
}
return os;
}
template <class T, class U>istream& operator>>(istream& is, pair<T, U>& p) {
is >> p.first >>p.second ;
return is;
}
template <class T>istream& operator>>(istream& is, vector<T>& v) {
rep(i, v.size()) {
is >> v[i];
}
return is;
}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
#ifdef LOCAL
#define dbg(x) cerr << #x << ": " << (x) << '\n'
#define say(x) cerr<<(x) <<'\n'
#else
#define dbg(x)
#define say(x)
#endif
string solve(bool a) { return ((a) ? "Yes" : "No"); }
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
int m,h;
int ans=0;
cin >>m>>h;
cout<<solve(h%m==0)<<endl;
} |
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define all(arr) arr.begin(),arr.end()
#define f first
#define s second
#define debug1(x) cout<<x<<"\n"
#define debug2(x,y) cout<<x<<" "<<y<<"\n"
#define debug3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define nl cout<<"\n";
#define pq priority_queue
#define inf 0x3f3f3f3f
#define test cout<<"abcd\n";
#define pi pair<int,int>
#define pii pair<int,pi>
#define pb push_back
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define ss(s) scanf("%s",s)
#define pl(x) printf("%lld\n",x)
#define ps(s) printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define MOD 1000000007
#define space ' '
#define kick(t) cout << "Case #" << t+1 << ":" << endl;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
template <typename T>
void input(vector<T> &arr,lli n) {
T temp;
for(lli i=0;i<n;i++) cin>>temp, arr.push_back(temp);
}
template <typename T>
void output(vector<T> arr) {
for(auto x:arr) cout<<x<<" ";
cout<<endl;
}
template <typename T>
void input_set(set<T> &arr,lli n) {
T temp;
for(lli i=0;i<n;i++) cin>>temp, arr.insert(temp);
}
lli mul(lli a, lli b) {
return (a%MOD*b%MOD)%MOD;
}
lli power(lli a,lli b) {
lli ans = 1;
while(b > 0) {
if(b&1)
ans = mul(ans, a);
a = mul(a,a);;
b >>= 1;
}
return ans;
}
void solve(int testcase) {
lli n;
cin >> n;
if(n%2==0 && n%4==0) cout << "Even\n";
else if(n%2==0) cout << "Same\n";
else cout << "Odd\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
lli testcases=1;
cin >> testcases;
for(int testcase=0; testcase<testcases; testcase++) {
solve(testcase);
}
}
| #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
//#define mod 998244353
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
template<class T> using V=vector<T>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline void out(T a){ cout << a << '\n'; }
void YN(bool ok){if(ok) cout << "Yes" << endl; else cout << "No" << endl;}
//void YN(bool ok){if(ok) cout << "YES" << endl; else cout << "NO" << endl;}
const ll INF=1e18;
const int mx=200005;
//abc201
int main(){
//オーバーフローは大丈夫ですか??
cin.tie(0);ios::sync_with_stdio(false);
int n;
cin>>n;
V<pair<int,string>> p(n);
rep(i,n){
string s;
int t;
cin>>s>>t;
p[i]={t,s};
}
sort(all(p));
reverse(all(p));
out(p[1].sc);
}
//B
//ペナルティ出しても焦らない ACできると信じろ!!!
//どうしてもわからないときはサンプルで実験 何か見えてくるかも
//頭で考えてダメなら紙におこせ!!
//添字注意!!(特に多重ループのとき) |
//#define _GLIBCXX_DEBUG
//#include "atcoder/all"
//using namespace atcoder;
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
#define Dump(x) \
if (dbg) { \
cerr << #x << " = " << (x) << endl; \
}
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) (((n) >> (k)) & 1) /*nのk bit目*/
namespace mydef {
const int INF = 1ll << 60;
const int MOD = 1e9 + 7;
template <class T>
bool chmin(T& a, const T& b) {
if (a > b) {
a = b;
return 1;
} else
return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
if (a < b) {
a = b;
return 1;
} else
return 0;
}
void Yes(bool flag = true) {
if (flag)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
void No(bool flag = true) {
Yes(!flag);
}
void YES(bool flag = true) {
if (flag)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
void NO(bool flag = true) {
YES(!flag);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
std::fill((T*)array, (T*)(array + N), val);
}
bool dbg = true;
} // namespace mydef
using namespace mydef;
#define pb push_back
//#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<pair<int, int>>
#define vvp vector<vector<pair<int, int>>>
#define pi pair<int, int>
//#define P pair<int, int>
//#define V vector<int>
//#define S set<int>
#define asn ans
int T;
bool check(const string& S, const string& T) {
//S > T;
int N = S.size();
int now = 0;
for (int i = 0; i < T.size(); i++) {
if (now >= N)
return false;
while (T[i] != S[now]) {
now++;
if (now >= N)
return false;
}
now++;
}
return true;
}
void solve() {
while (T--) {
int N;
cin >> N;
string S[3];
cin >> S[0] >> S[1] >> S[2];
vector<string> T;
for (int a = 0; a < 2; a++) {
for (int b = 0; b < 2; b++) {
string A, B;
for (int i = 0; i < N; i++) {
A += (char)('0' + a);
B += (char)('0' + b);
}
T.emplace_back('0' + A + B);
T.emplace_back('1' + A + B);
T.emplace_back(A + '0' + B);
T.emplace_back(A + '1' + B);
T.emplace_back(A + B + '0');
T.emplace_back(A + B + '1');
}
}
for (int i = 0; i < 3; i++) {
S[i] += S[i];
}
string ans;
for (auto& s : T) {
if (check(S[0], s) && check(S[1], s) && check(S[2], s)) {
ans = s;
break;
}
}
cout << ans << endl;
}
}
signed main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cin >> T;
solve();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define int long long int
#define yes cout<<"YES\n";
#define no cout<<"NO\n";
#define fl(n) for(int i=0;i<n;i++)
#define flo(n) for(int i=1;i<=n;i++)
#define mii map<int,int>
#define mci map<char,int>
#define V vector<int>
#define vp vector<pair<int,int>>
#define pb push_back
#define pp pair<int,int>
#define ff first
#define ss second
#define S set<int>
#define all(v) v.begin(),v.end()
#define gr greater<int>()
#define show2(a, b) cout<<a<<' '<<b<<endl;
#define show3(a, b, c) cout<<a<<' '<<b<<' '<<c<<endl;
const long long mod=1000000007;
const int N=4e5+5;
const long double PI=3.14159265358;
vector<vector<int>> adj;
bool v[N];
void dfs(int j){
v[j]=true;
for(auto u:adj[j]){
if(!v[u]) dfs(u);
}
}
int32_t main(){
int t=1;
//cin>>t;
while(t--){
int n,m;
cin>>n>>m;
mii mp;
fl(n+2) mp[i]=0;
//for(auto i:mp) cout<<i.ff<<"."<<i.ss<<endl;
int a[n];
fl(n) cin>>a[i];
S s;
fl(m) mp[a[i]]++;
//for(auto i:mp) cout<<i.ff<<"."<<i.ss<<endl;
fl(n+2){
if(mp[i]==0){
s.insert(i);}
}
auto it=s.begin();
int ans=*it;
// cout<<ans<<endl;
// for(auto it=s.begin();it!=s.end();it++) cout<<*it<<'.';
// cout<<endl;
for(int i=m;i<n;i++){
mp[a[i]]++;
// cout<<mp[a[i]]<<'.';
mp[a[i-m]]--;
// cout<<mp[a[i-m]]<<endl;
if(mp[a[i-m]]==0)
s.insert(a[i-m]);
if(s.find(a[i])!=s.end()){
s.erase(a[i]);
}
auto k=s.begin();
ans=min(ans,*k);
// cout<<*k<<endl;
}
cout<<ans;
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
using ll = long long;
int main() {
int n; cin >> n;
string s; cin >> s;
int q; cin >> q;
bool flag = false;
for (int i = 0; i < q; i++) {
int t, a, b; cin >> t >> a >> b;
if(t == 1){
if(flag){
if(a <= n && b <= n){
a = a + n - 1;
b = b + n - 1;
}else if(n < a && n < b){
a = a - n - 1;
b = b - n - 1;
}else{
a = a + n - 1;
b = b - n - 1;
}
char ta = s[a];
char tb = s[b];
s[a] = tb;
s[b] = ta;
}else{
char ta = s[a - 1];
char tb = s[b - 1];
s[a - 1] = tb;
s[b - 1] = ta;
}
}else{
flag = !flag;
}
}
string t = s + s;
if(flag) cout << t.substr(n, 2 * n) << endl;
else cout << s << endl;
return 0;
}
| #include<bits/stdc++.h>
#define int long long
#define rint regester int
const int maxn = 1e6 + 10;
const int INF = 1e9;
using std::ios;
using std::cin;
using std::cout;
using std::max;
using std::min;
using std::sort;
using std::unique;
using std::lower_bound;
using std::swap;
using std::abs;
using std::acos;
using std::queue;
using std::map;
using std::string;
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;}
int n, q, op, t, a, b;
char s[maxn];
signed main(){
cin >> n >> s + 1;
q = read();
while(q--){
t = read(), a = read(), b = read();
if(t == 2)op ^= 1;
if(t == 1){
if(op == 1){
if(a > n)a -= n;else a += n;
if(b > n)b -= n; else b += n;
}
swap(s[a], s[b]);
}
}
if(op == 1){
for(int i = n + 1; i <= n + n; i++)cout << s[i];
for(int i = 1; i <= n; i++)cout << s[i];
}else
for(int i = 1; i <= n + n; i++)cout << s[i];
} |
#include <bits/stdc++.h>
using namespace std;
void solve(){
string s,ans="";
cin>>s;
int n,i,j=-1;
n=s.length();
for(i=0;i<n;i++){
if(s[i]=='.'){
j=i;
break;
}
}
if(j==0){
cout<<"0"<<endl;
return;
}
if(j==-1){
cout<<s<<endl;
return;
}
for(i=0;i<j;i++)
ans=ans+s[i];
cout<<ans<<endl;
}
int main() {
// your code goes here
solve();
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;
string ans;
rep(i, X.size()) {
if (X.at(i) == '.') break;
ans.push_back(X.at(i));
}
cout << ans << endl;
} |
#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 vector1d(type,name,...) vector<type>name(__VA_ARGS__)
#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=(ll)1<<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> 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 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);
pair<double,double> p1,p2,p3;
cin>>p1.first>>p1.second>>p2.first>>p2.second;
pair<double,double> pc={(p1.first+p2.first)/2,(p1.second+p2.second)/2};
p1.first-=pc.first;
p1.second-=pc.second;
double theta=((double)360/n)*((double)M_PI/180);
p3.first=p1.first*cos(theta)-p1.second*sin(theta)+pc.first;
p3.second=p1.first*sin(theta)+p1.second*cos(theta)+pc.second;
out(p3.first,p3.second);
} | #pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> p32;
typedef pair<ll, ll> p64;
typedef pair<double, double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int>> vv32;
typedef vector<vector<ll>> vv64;
typedef vector<vector<p64>> vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
double eps = 1e-12;
#define forn(i, e) for (ll i = 0; i < e; i++)
#define forsn(i, s, e) for (ll i = s; i < e; i++)
#define rforn(i, s) for (ll i = s; i >= 0; i--)
#define rforsn(i, s, e) for (ll i = s; i >= e; i--)
#define endl "\n"
#define dbg(x) cout << x << " = " << x << endl
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 2e18
#define fast_cin() \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
void solve()
{
int n;
cin >> n;
int day=0;
int sum=0;
while(sum<n)
{
sum+=(day+1);
day++;
}
cout<<day<<endl;
}
int main()
{
fast_cin();
ll t=1;
// cin >> t;
while (t--)
{
solve();
}
return 0;
} |
#include <iostream>
#include <assert.h>
#include <vector>
#include <unordered_map>
#include <queue>
#include <climits>
#include <cmath>
#include <algorithm>
#include <iomanip>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
//cout << std::fixed << std::setprecision(15) << res << endl;
//int di[] = {-1,0,1,0};
//int dj[] = {0,-1,0,1};
//printf("%.10f %.10f\n), ans.real(), ans.imag());
int main(){
std::cin.tie(0);
std::ios::sync_with_stdio(false);
int N;
cin >> N;
int res = N / 100 + 1;
if (N % 100 == 0) {
res = N / 100;
}
cout << res << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main(){
string x;
cin >> x;
for(int i=0; i<x.length(); i++){
if(x[i]!='.'){
cout << x[i];
}else{
break;
}
}
cout << endl;
return 0;
}
|
#include<iostream>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<deque>
#include <algorithm>
using namespace std;
#define mem(a,b) memset(a,b,sizeof a)
#define PII pair<int,int>
#define ll long long
#define ull unsigned long long
#define ft first
#define sd second
#define endl '\n'
#define PI acos(-1.0)
#define lcm(a,b) a/gcd(a,b)*b
#define INF_INT 0x3f3f3f3f
#define debug(a) cout<<#a<<"="<<a<<endl;
#define _for(i,a,b) for( int i=(a); i<(b); ++i)
#define _rep(i,a,b) for( int i=(a); i<=(b); ++i)
//inline void print(__int128 x){if(x<0){putchar('-');x=-x;}if(x>9) print(x/10);putchar(x%10+'0');}
int gcd(int a, int b){return b ? gcd(b, a % b) : a;}
int exgcd(int a, int b, int &x, int &y){if(!b){x = 1; y = 0;return a;}int d = exgcd(b, a % b, y, x);y -= (a/b) * x;return d;}
int qmi(int m, int k, int p){int res = 1 % p, t = m;while (k){if (k&1) res = res * t % p;t = t * t % p;k >>= 1;}return res;}
inline int read(){int s=0,x=1;char ch=getchar();while(ch<'0'||ch>'9') {if(ch=='-') x=-1; ch=getchar();}while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar(); }return s*x;}
const int N = 1e6+7;
int n,m;
void solve()
{
n = read();
map<int,int> mp;
_for(i,0,n){
m = read();
if(mp[m]){
puts("No");
return;
}
else{
mp[m] = 1;
}
}
puts("Yes");
return;
}
int main()
{
//ios::sync_with_stdio(0);
int T = 1;
// cin >> T;
while(T--)
{
solve();
}
return 0;
}
| #include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<set>
#include<queue>
#include<stack>
#include<math.h>
#include<time.h>
#include<deque>
#include<cstring>
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define MOD (ll)(1e9+7)
#define INF (ll)(1e18)
#define M 5000005
#define endl "\n"
#define AC ios::sync_with_stdio(0);cin.tie(0);
using namespace std;
ll fpow(ll x,ll y){
ll r=1;
while(y){
if(y&1){
r*=x;
r%=MOD;
}
x*=x;
x%=MOD;
y>>=1;
}
return r;
}
ll gcd(ll x,ll y){
if(y>x) swap(x,y);
return y?gcd(y,x%y):x;
}
signed main(){
AC;
int n;
int cnt[1005]={0};
cin>>n;
FOR(i,0,n){
int x;
cin>>x;
cnt[x]++;
}
FOR(i,1,n+1){
if(cnt[i]!=1){
cout<<"No"<<endl;
return 0;
}
}
cout<<"Yes"<<endl;
}
|
#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)
using namespace std;
typedef long long ll;
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; }
// dijkstra 蟻本
struct edge {ll to, cost;};
typedef pair<ll, int> P; // firstはsからの最短距離, secondは頂点の番号
const ll INF = 4e18;
int n;
vector<vector<edge>> g;
vector<ll> dijkstra(int n, int s){
vector<ll> d(n, INF);
d[s] = 0;
priority_queue<P,vector<P>,greater<P> > que;
que.push(P(0, s));
while(!que.empty()){
P p = que.top();
que.pop();
int v = p.second;
if(d[v] < p.first) continue; //後から最短パスが見つかった場合、先にqueに入っているものはここではじかれる
for(int i = 0; i < g[v].size(); i++){
edge e= g[v][i];
if(d[e.to] > d[v] + e.cost){
d[e.to] = d[v] + e.cost;
que.push(P(d[e.to], e.to));
}
}
}
return d;
}
int nth_bit(int b, int i){
return (b >> i) & 1;
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int m;
cin >> n >> m;
g.resize(n, vector<edge>());
rep(i, m){
int u, v;
cin >> u >> v;
u--;
v--;
g[u].push_back({v, 1ll});
g[v].push_back({u, 1ll});
}
int k;
cin >> k;
vector<int> t(k);
rep(i, k){
cin >> t[i];
t[i]--;
}
vector<vector<ll>> d(k);
rep(i, k) d[i] = dijkstra(n, t[i]);
auto dp = vector<vector<ll>>((1 << k), vector<ll>(k, INF));
rep(i, k) dp[1 << i][i] = 1;
rep(b, 1 << k) rep(i, k) rep(j, k){
if(nth_bit(b, i) && !nth_bit(b, j)) {
chmin(dp[b + (1 << j)][j], dp[b][i] + d[i][t[j]]);
}
}
auto &v = dp[(1 << k) - 1];
ll ans = *min_element(v.begin(), v.end());
if(ans == INF){
cout << -1 << endl;
}else{
cout << ans << endl;
}
}
| #include "bits/stdc++.h"
using namespace std;
using ll = int64_t;
#define eb emplace_back
#define F first
#define S second
#define ice(i, a, b) for (int (i) = (a); (i) < (b); ++(i))
const ll MOD = 1e9 + 7;
vector<vector<pair<int, ll>>> adj(200001);
vector<ll> val(200001, 0);
void dfs(int n, int m = -1) {
for (auto b : adj[n]) {
if (b.F != m) {
val[b.F] = val[n] ^ b.S;
dfs(b.F, n);
}
}
}
void solve() {
int n; cin >> n;
ice (i, 0, n - 1) {
int u, v; ll w; cin >> u >> v >> w; --u; --v;
adj[u].eb(v, w);
adj[v].eb(u, w);
}
dfs(0);
ll ans = 0;
ice (i, 0, 60) {
ll zero = 0, one = 0;
ice (j, 0, n) {
val[j] & (1LL << i) ? one++ : zero++;
}
ll cnt = (((zero * one) % MOD) * ((1LL << i) % MOD)) % MOD;
ans = (ans + cnt) % MOD;
}
cout << ans;
}
int main() {
solve();
} |
#include<bits/stdc++.h>
#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,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
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; }
__attribute__ ((constructor))
void fastio() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(10);
}
int main(){
int n, m;
cin >> n >> m;
vector<int> a(m);
vector<int> b(m);
rep(i, m) cin >> a[i] >> b[i];
rep(i, m){
a[i]--;
b[i]--;
}
int k;
cin >> k;
vector<int> c(k);
vector<int> d(k);
rep(i, k){
cin >> c[i] >> d[i];
c[i]--;
d[i]--;
}
int ans = 0;
rep(i,(1<<k)){
vector<int> sara(n, 0);
rep(j,k){
if((i>>j)&1){
sara[c[j]]++;
}else{
sara[d[j]]++;
}
}
int cnt = 0;
rep(j,m){
if(sara[a[j]] > 0 && sara[b[j]] > 0)
cnt++;
}
chmax(ans, cnt);
}
cout << ans << endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
const int N=110;
int n,m,k,a[N],b[N],c[N],d[N];
int vis[N],ans;
void dfs(int x){
if(x==k+1){
int sum=0;
for(int i=1;i<=m;i++){
if(vis[a[i]]&&vis[b[i]]){
sum++;
}
}
ans=max(ans,sum);
return ;
}
vis[c[x]]++;
dfs(x+1);
vis[c[x]]--;
vis[d[x]]++;
dfs(x+1);
vis[d[x]]--;
}
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++){
scanf("%d%d",&a[i],&b[i]);
}
scanf("%d",&k);
for(int i=1;i<=k;i++){
scanf("%d%d",&c[i],&d[i]);
}
dfs(1);
printf("%d\n",ans);
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int mod = 1000 * 1000 * 1000 + 7;
const int INF = 1e9 + 100;
const ll LINF = 1e18 + 100;
#ifdef DEBUG
#define dbg(x) cout << #x << " = " << (x) << endl << flush;
#define dbgr(s, f) { cout << #s << ": "; for (auto _ = (s); _ != (f); _++) cout << *_ << ' '; cout << endl << flush; }
#else
#define dbg(x) ;
#define dbgr(s, f) ;
#endif
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
//#define fast_io ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//#define msub(a, b) ((mod + ((ll)(a) - (b)) % mod) % mod)
//#define mdiv(a, b) ((ll)(a) * poww((b), mod - 2) % mod)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define endl '\n'
#define MAXN 200100
#define MAXK 20
ll poww(ll a, ll b)
{
ll res = 1;
while (b)
{
if (b & 1) res = res * a % mod;
a = a * a % mod;
b /= 2;
}
return res;
}
string s;
int k;
int n;
ll ans;
ll dp[MAXK];
ll comb[MAXK][MAXK];
ll ps[MAXK];
inline int getdig(char c)
{
if ('0' <= c && c <= '9')
return c - '0';
return c - 'A' + 10;
}
ll f(int n, int k, int t)
{
if (k - t > n) return 0;
if (n == 0 && k == t) return 1;
ll res = 0;
FOR(i, 0, k - t + 1)
{
res = (res + comb[k - t][i] * poww(k - i, n) * (i % 2 ? -1 : 1)) % mod;
}
res = (res * comb[16 - t][k - t]) % mod;
res = (mod + res) % mod;
return res;
}
int cnt[MAXN];
int dif;
inline void add(int x)
{
cnt[x]++;
if (cnt[x] == 1)
dif++;
}
inline void rem(int x)
{
cnt[x]--;
if (cnt[x] == 0)
dif--;
}
int32_t main(void)
{
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> s >> k;
n = s.size();
FOR(i, 0, MAXK)
{
comb[i][0] = comb[i][i] = 1;
FOR(j, 1, i)
comb[i][j] = (comb[i - 1][j - 1] + comb[i - 1][j]) % mod;
}
FOR(i, 0, n)
{
int fr = (i ? 0 : 1);
int d = getdig(s[i]);
FOR(j, fr, d)
{
add(j);
if (dif <= k) ans = (ans + f(n - i - 1, k, dif)) % mod;
rem(j);
}
add(d);
if (dif > k) break;
}
if (dif == k)
ans = (ans + 1) % mod;
FOR(i, 1, n)
{
ans = (ans + f(i - 1, k, 1) * 15) % mod;
}
cout << ans << endl;
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const ll N=2e5+5;
char s[N];
ll k,len;
ll nums[N];
ll dp[N][20][2][2];
ll dfs(ll pos,int st,bool pre,bool limit){
int cnt=__builtin_popcount(st);
if(cnt>k) return 0;
if(pos>len) return cnt==k&⪯
if(dp[pos][cnt][limit][pre]!=-1) return dp[pos][cnt][limit][pre];
ll ans=0;
ll up=limit?nums[pos]:15;
for(int i=0;i<=up;i++){
ans=(ans+dfs(pos+1,(!i&&!pre)?st:st|(1<<i),i|pre,i==up&&limit))%mod;
}
if(!limit) dp[pos][cnt][limit][pre]=ans;
return ans;
}
int main(){
memset(dp,-1,sizeof(dp));
cin>>s+1>>k;
len=strlen(s+1);
for(ll i=1;i<=len;i++){
if(s[i]>='0'&&s[i]<='9') nums[i]=s[i]-'0';
else nums[i]=s[i]-'A'+10;
}
cout<<dfs(1,0,0,true)<<"\n";
} |
#include <bits/stdc++.h>
using namespace std;
const int Maxn = 400004;
char tmp[Maxn];
int T;
int n;
string A, B, C;
int nxtA[Maxn][2], nxtB[Maxn][2], nxtC[Maxn][2];
char res[Maxn];
int rlen;
void Read(string &S, int nxt[][2])
{
scanf("%s", tmp);
S = tmp; S = S + S;
nxt[S.length()][0] = nxt[S.length()][1] = S.length();
for (int i = int(S.length()) - 1; i >= 0; i--) {
nxt[i][0] = nxt[i + 1][0];
nxt[i][1] = nxt[i + 1][1];
nxt[i][S[i] - '0'] = i;
}
}
int main()
{
scanf("%d", &T);
while (T--) {
scanf("%d", &n);
Read(A, nxtA);
Read(B, nxtB);
Read(C, nxtC);
printf("%s%s%s\n", string(n, '0').c_str(), string(n, '1').c_str(), string(1, '0').c_str());
}
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD 1000000007
const ll INF=1e18;
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<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; }
int main(int argc, char const *argv[]) {
ll n, sum = 0, ans=0;
cin >> n;
vector<ll> a(n),an(n);
rep(i,n) {
cin >> a[i];
sum += a[i];
ans += a[i] * a[i];
}
ans *= (n-1);
ll tmp = 0;
rep(i, n) {
sum -= a[i];
ans -= a[i] * sum * 2;
}
cout << ans << endl;
return 0;
} |
#include<iostream>
#include<vector>
using namespace std;
int main()
{
/**/
int start_x, start_y, goal_x, goal_y;
int cost=0;
for (int i = 0; i < 1000; i++)
{
/*input*/
cin >> start_x >> start_y >> goal_x >> goal_y;
/*cul*/
if (start_x - goal_x >= 0)
for (int j = 0; j < start_x - goal_x; j++)
cout << 'U';
else
for (int j = 0; j > start_x - goal_x; j--)
cout << 'D';
if (start_y - goal_y >= 0)
for (int j =0; j < start_y - goal_y; j++)
cout << 'L';
else
for (int j = 0; j > start_y - goal_y; j--)
cout << 'R';
cout << endl;
cin >> cost;
}
return 0;
} | //GIVE ME AC!!!!!!!!!!!!!!!!!
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#include <random>
#define ll long long
#define rep(i, s, n) for (ll i = s; i < (ll)(n); i++)
using namespace std;
int main(){
rep(i,0,1000){
ll a,b,c,d;
cin>>a>>b>>c>>d;
string ans="";
if(c>a){
rep(i,0,c-a){
ans+="D";
}
}
else{
rep(i,0,a-c){
ans+="U";
}
}
if(b>d){
rep(i,0,b-d){
ans+="L";
}
}
else{
rep(i,0,d-b){
ans+="R";
}
}
std::mt19937 get_rand_mt;
std::shuffle( ans.begin(), ans.end(), get_rand_mt );
cout<<ans<<endl;
ll n;
cin>>n;
}
} |
// Problem: E - Spread of Information
// Contest: AtCoder - AtCoder Regular Contest 116
// URL: https://atcoder.jp/contests/arc116/tasks/arc116_e
// Memory Limit: 1024 MB
// Time Limit: 3000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include <bits/stdc++.h>
using namespace std;
inline int read(){
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s*w;
}
const int N=5e5+5;
int n,m,cnt,f[N],g[N],is[N],head[N],ans,gs;
struct nood
{
int nex,to;
};
nood e[N*2];
inline void jia(int u,int v)
{
e[++cnt].nex=head[u];
head[u]=cnt;
e[cnt].to=v;
}
inline void dfs(int u,int fa,int x)
{
f[u]=1e9;
g[u]=-1e9;
for ( int i=head[u];i;i=e[i].nex )
{
int v=e[i].to;
if(v==fa) continue;
dfs(v,u,x);
f[u]=min(f[v]+1,f[u]);
g[u]=max(g[v]+1,g[u]);
}
if(is[u]&&f[u]>x) g[u]=max(g[u],0);
if(g[u]+f[u]<=x) g[u]=-1e9;
if(g[u]==x)
gs++,g[u]=-1e9,f[u]=0;
}
inline bool check(int mid)
{
gs=0;
dfs(1,0,mid);
gs+=(g[1]>=0);
return gs<=m;
}
int main()
{
n=read();
m=read();
for ( int i=1;i<=n;i++ )
is[i]=1;
for ( int i=1;i<n;i++ )
{
int x,y;
x=read(),y=read();
jia(x,y);
jia(y,x);
}
int l=0,r=n;
while(l<=r)
{
int mid=(l+r)/2;
if(check(mid))
{
ans=mid;
r=mid-1;
}
else l=mid+1;
}
printf("%d\n",ans);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define mp make_pair
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;
ll C[200100];
class UnionFind{
public:
vector<int> par;
vector<set<int>> child;
vector<int> rank;
vector<map<int, int>> num;
UnionFind(int n){
child.resize(n);
num.resize(n);
for(int i = 0; i < n; i++){
par.push_back(i);
rank.push_back(0);
num[i][C[i]] = 1;
}
}
int find(int x){
if(x == par[x])
return x;
else
return par[x] = find(par[x]);
}
void unite(int x, int y){
x = find(x);
y = find(y);
if(x == y) return;
if(rank[x] < rank[y]){
par[x] = y;
child[y].insert(x);
for(auto&& p : num[x]){
num[y][p.first] += p.second;
}
}
else{
par[y] = x;
child[x].insert(y);
if(rank[x] == rank[y]) rank[x]++;
for(auto&& p : num[y]){
num[x][p.first] += p.second;
}
}
}
bool same(int x, int y){
return find(x) == find(y);
}
ll get_num(int x, int y){
x = find(x);
return num[x][y];
}
};
int main(){
ll N, Q;
cin >> N >> Q;
REP(i,N){
ll c;
cin >> c;
C[i] = c-1;
}
UnionFind uni(N);
REP(q,Q){
ll a, x ,y;
cin >> a >> x >> y;
x--, y--;
if(a == 1){
uni.unite(x, y);
}
else{
ll ans = 0;
ans = uni.get_num(x, y);
cout << ans << endl;
}
}
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define res register int
#define ll long long
//#define cccgift
#define lowbit(x) ((x)&-(x))
#define rep(i,l,r) for(res i=l,_r=r;i<=_r;++i)
#define per(i,r,l) for(res i=r,_l=l;i>=_l;--i)
#define mkp make_pair
#define pb push_back
#define mem0(a) memset(a,0,sizeof(a))
#define mem0n(a,n) memset(a,0,(n)*sizeof(a[0]))
#define iter(x,v) for(res v,_p=head[x];v=ver[_p],_p;_p=nxt[_p])
#ifdef cccgift //by lqh
#define SHOW(x) cerr<<#x"="<<(x)<<endl
#else
#define SHOW(x) 0
#endif
//#define getchar()(ip1==ip2&&(ip2=(ip1=ibuf)+fread(ibuf,1,1<<21,stdin),ip1==ip2)?EOF:*ip1++)
//char ibuf[1<<21],*ip1=ibuf,*ip2=ibuf;
template<typename T>
inline void read(T &x)
{
static char ch;bool f=1;
for(x=0,ch=getchar();!isdigit(ch);ch=getchar()) if(ch=='-') f=0;
for(;isdigit(ch);x=(x<<1)+(x<<3)+(ch^48),ch=getchar());x=f?x:-x;
}
template<typename T>
void print(T x)
{
if (x<0) x=-x,putchar('-');
if (x>9) print(x/10);
putchar(x%10+48);
}
template<typename T>
inline void print(T x,char ap) {print(x);if (ap) putchar(ap);}
template<typename T>
inline void chkmax(T &x,const T &y) {x=x<y?y:x;}
template<typename T>
inline void chkmin(T &x,const T &y) {x=x<y?x:y;}
unordered_map<int,bool> mp;
int t,n,x;
int main()
{
read(t);
while(t--) {
read(n),mp.clear();
rep(i,1,n) read(x),mp[x]^=1;
if(n&1) {puts("Second");continue;}
bool flag=false;
for(auto &p:mp) if(p.second) flag=true;
puts(flag?"First":"Second");
}
return 0;
}
/* stuff you should look for
* int overflow, array bounds
* special cases (n=1?), set tle
* do something instead of nothing and stay organized
*/
| #include <bits/stdc++.h>
using namespace std;
using lint = long long;
constexpr lint mod = 1e9 + 7;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
#define rep(i, n) for(int i = 0; i < int(n); i++)
#define rep2(i, l, r) for(int i = int(l); i < int(r); i++)
#define repr(i, n) for(int i = int(n) - 1; i >= 0; i--)
#define repr2(i, l, r) for(int i = int(r) - 1; i >= int(l); i--)
#define SZ(x) int(x.size())
constexpr int inf9 = 1e9; constexpr lint inf18 = 1e18;
inline void YES(bool condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
inline void Yes(bool condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
inline void assertNO(bool condition){ if(!condition){ cout << "NO" << endl; exit(0); } }
inline void assertNo(bool condition){ if(!condition){ cout << "No" << endl; exit(0); } }
inline void assertm1(bool condition){ if(!condition){ cout << -1 << endl; exit(0); } }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class T> string to_string(complex<T> x){ return to_string(make_pair(x.real(), x.imag())); }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) cout << (i == start ? "" : " ") << (*i); if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(b) return gcd(b, a % b); else return a; }
template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint P(int n, int r){ if(r < 0 || n < r) return 0; return (fact[n] * inv[n - r] % mod); } lint C(int p, int q){ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }
template<class itr, class itr2> bool next_sequence2(itr first, itr last, itr2 first2, itr2 last2){ itr now = last; itr2 now2 = last2; while(now != first){ now--, now2--; (*now)++; if((*now) == (*now2)){ (*now) = 0; }else{ return true; } } return false; }
template<class T> bool chmax(T &a, const T &b){ if(a < b){ a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b){ if(b < a){ a = b; return 1; } return 0; }
inline int at(lint i, int j){ return (i >> j) & 1; }
random_device rnd;
bool is_in_board(lint y, lint x, lint H, lint W){ return (0 <= y && y < H && 0 <= x && x < W); }
string pool[2] = {"First", "Second"};
void solve(){
int N;
cin >> N;
lint a[N];
cins(a, a + N);
map<lint, int> inv;
rep(i, N){
inv[a[i]]++;
}
for(auto i: inv){
if(i.second % 2){
cout << pool[N % 2] << endl;
return;
}
}
cout << pool[1 - N % 2] << endl;
}
int main(){
int T;
cin >> T;
rep(i, T) solve();
}
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int maxn=200020,mod=998244353;
#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,m;
char s[maxn],t[maxn];
int main(){
n=read();
scanf("%s",s+1);
FOR(i,1,n){
t[++m]=s[i];
if(m>=3 && t[m-2]=='f' && t[m-1]=='o' && t[m]=='x') m-=3;
}
printf("%d\n",m);
} | #include <bits/stdc++.h>
using namespace std;
#define N 200000
int main()
{
int n, p, q = 0;
vector<bool> u(N+5, 0);
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%d", &p);
u[p] = 1;
while (u[q]) ++q;
printf("%d\n", q);
}
} |
#include <bits/stdc++.h>
using namespace std;
int dp[1001][1001];
int a[1001], b[1001];
int n, m;
int solve(int i, int j) {
if (dp[i][j] != -1) {
return dp[i][j];
}
int & res = dp[i][j];
if (i == n) {
res = m - j;
return res;
}
if (j == m) {
res = n - i;
return res;
}
if (a[i] == b[j]) {
res = solve(i + 1, j + 1);
} else {
res = 1 + solve(i + 1, j + 1);
res = min(res, 1 + solve(i, j + 1));
res = min(res, 1 + solve(i + 1, j));
}
return res;
}
int main() {
memset(dp, -1, sizeof dp);
cin >> n >> m;
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
for (int i = 0; i < m; ++i) {
cin >> b[i];
}
cout << solve(0, 0) << endl;
return 0;
} | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;
#define rep(i, a, b) for (__typeof((b)) i = (a); i < (b); i++)
#define nrep(i, a, b) for (__typeof((b)) i = (a); i > (b); i--)
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define ppi pair<int, int>
#define pppi pair<ppi, int>
#define vi vector<int>
#define vii vector<ppi>
#define viii vector<pppi>
#define vs vector<string>
#define pb push_back
#define bitcount __builtin_popcountll // count no's of ones in a set bit
#define prq priority_queue
#define mp make_pair
#define mem(x, val) memset((x), (val), sizeof(x));
#define sz(x) (int)x.size()
#define M_PI 3.14159265358979323846
#define rootdada \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define test \
int t; \
cin >> t; \
while (t--)
#define debug(a) \
cerr << #a << ": "; \
for (auto i : a) cerr << i << " "; \
cerr << '\n';
#define trace(a) cerr << #a << ": " << a << "\n"
#define print(ar, n) \
for (int u = 0; u < n; u++) { \
cout << ar[u] << " "; \
} \
cout << endl;
#define int long long
#define M 1000000007
#define ordered_set \
tree<int, null_type, less<int>, rb_tree_tag, \
tree_order_statistics_node_update>
int lcs( vector<int> X, vector<int> Y, int n, int m )
{
int L[n + 1][m + 1];
int i, j;
/* Following steps build L[m+1][n+1] in
bottom up fashion. Note that L[i][j]
contains length of LCS of X[0..i-1]
and Y[0..j-1] */
for (i = 0; i <= n; i++)
L[i][0] = i;
for (j = 0; j <= m; j++)
L[0][j] = j;
for (i = 0; i < n; i++)
{
for (j = 0; j < m; j++)
{
if (X[i] == Y[j])
L[i + 1][j + 1] = L[i][j];
else
L[i + 1][j + 1] = min(L[i][j], min(L[i + 1][j], L[i][j + 1])) + 1;
}
}
/* L[m][n] contains length of LCS
for X[0..n-1] and Y[0..m-1] */
return L[n][m];
}
signed main() {
rootdada;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("error.txt", "w", stderr);
freopen("output.txt", "w", stdout);
#endif
int n, m;
cin >> n >> m;
vi a(n), b(m);
rep(i, 0, n)
cin >> a[i];
rep(i, 0, m)
cin >> b[i];
int ans = lcs(a, b, n, m);
cout << ans << endl;
} |
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define mem(a,val) memset(a,(val),sizeof((a)))
#define FAST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define decimal(n) cout << fixed ; cout << setprecision((n));
#define mp make_pair
#define eb emplace_back
#define f first
#define s second
#define all(v) v.begin(), v.end()
#define endl "\n"
#define lcm(m,n) (m)*((n)/__gcd((m),(n)))
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(ll (i)=1;(i)<(n);(i)++)
#define repa(i,n,a) for(ll (i)=(a);(i)<(n);(i)++)
#define repr(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define vll vector<ll>
#define sz(x) (ll)x.size()
#define ub upper_bound
#define lb lower_bound
#define pcnt(x) __builtin_popcountll(x)
const long long N=1e4+10;
const long long NN=1e18;
const int32_t M=1e9+7;
const int32_t MM=998244353;
template<typename T,typename T1>T maxn(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T minn(T &a,T1 b){if(b<a)a=b;return a;}
ll abc[61];
void pre()
{
abc[0]=1;
for(int i=1;i<=60;i++)
{
abc[i]=abc[i-1]*2;
}
}
void solve()
{
//code begins from here//
ll n;
cin>>n;
string s[n+1];
rep1(i,n+1)cin>>s[i];
ll ans=0;
for(int i=n;i>=1;i--)
{
if(s[i]=="OR")
{
ans+=abc[i];
}
}
ans++;
cout<<ans;
}
signed main()
{
FAST
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
int testcase=1;
//cin>>testcase;
pre();
while(testcase--) solve();
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
using ll = long long;
using P = tuple<ll, ll, int>;
int main() {
int n; cin >> n;
vector<P> ps;
rep(i, n) {
ll x, y;
cin >> x >> y;
ps.emplace_back(x, y, i);
}
vector<bool> pushed(n);
vector<P> use;
auto push = [&]() -> void {
rep(i, 3) {
auto[x, y, id] = ps[i];
if(pushed[id]) continue;
use.push_back(ps[i]);
pushed[id] = true;
}
rep(_i, 3) {
int i = n - 1 - _i;
auto[x, y, id] = ps[i];
if(pushed[id]) continue;
use.push_back(ps[i]);
pushed[id] = true;
}
};
sort(ps.begin(), ps.end());
push();
sort(ps.begin(), ps.end(), [&](auto a, auto b) {
auto[x, y, i] = a;
auto[xb, yb, ib] = b;
return y < yb;
});
push();
vector<int> dist;
for(auto &[x, y, i] : use) {
for(auto &[x2, y2, i2] : use) {
if(i == i2) continue;
ll d = max(abs(x - x2), abs(y - y2));
dist.push_back(d);
}
}
sort(dist.rbegin(), dist.rend());
cout << dist[2] << '\n';
return 0;
}
|
#include <bits/stdc++.h>
#define pb push_back
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ggdem=b;i<ggdem;++i)
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define mset(a,v) memset((a),(v),sizeof(a))
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;
const ll MOD=998244353;
const int MAXN=5005;
ll fact[MAXN],facti[MAXN];
ll be(ll b, ll e, ll mod){
ll r=1;
while(e)if(e&1)r=(r*b)%mod,e^=1; else b=(b*b)%mod,e/=2;
return r;
}
ll comb(ll n, ll k){
if(k>n)return 0;
return fact[n]*(facti[k]*facti[n-k]%MOD)%MOD;
}
vector<ll> mul(vector<ll> a, vector<ll> b){
vector<ll> res(SZ(a)+SZ(b)-1);
fore(i,0,SZ(a)){
if(a[i]==0)continue;
fore(j,0,SZ(b)){
res[i+j]=(res[i+j]+a[i]*b[j])%MOD;
}
}
return res;
}
int main(){FIN;
fact[0]=1;
fore(i,1,MAXN)fact[i]=fact[i-1]*i%MOD;
fore(i,0,MAXN)facti[i]=be(fact[i],MOD-2,MOD);
ll n,m; cin>>n>>m;
if(m&1){
cout<<"0\n";
return 0;
}
vector<ll> res(m+1);
res[0]=1;
fore(i,0,13){
ll pot=(1ll<<(i+1));
if(pot>m)break;
vector<ll> p(m+1);
for(ll j=0;j<=m;j+=pot){
p[j]=comb(n,2*j/pot);
}
//for(auto i:p)cout<<i<<" ";
//cout<<"\n";
res=mul(p,res);
//for(auto i:res)cout<<i<<" ";
//cout<<"\n";
while(SZ(res)>m+1)res.pop_back();
}
cout<<res.back()<<"\n";
return 0;
} | #include<cstdio>
#define mod 998244353
#define N 5001
int f[N],C[N][N];
int main()
{
int n,m,t;
scanf("%d%d",&n,&m);
for(int i=0;i<=n;++i)
{
C[i][0]=1;
for(int j=1;j<=i;++j)
{
C[i][j]=C[i-1][j-1]+C[i-1][j];
if(C[i][j]>=mod) C[i][j]-=mod;
}
}
f[0]=1;
for(int i=0;i<=11;++i)
{
t=(1<<i)<<1;
for(int k=m;k>=t;--k)
for(int j=t,l=2;j<=k;j+=t,l+=2)
{
f[k]+=1ll*f[k-j]*C[n][l]%mod;
if(f[k]>=mod) f[k]-=mod;
}
}
printf("%d",f[m]);
} |
#include <bits/stdc++.h>
using namespace std;
typedef int_fast32_t int32;
typedef int_fast64_t int64;
const int32 inf = 1e9+7;
const int32 MOD = 1000000007;
const int64 llinf = 1e18;
#define YES(n) cout << ((n) ? "YES\n" : "NO\n" )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n" )
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n" )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define all(obj) (obj).begin(),(obj).end()
#define rall(obj) (obj).rbegin(),(obj).rend()
#define fi first
#define se second
#define pb(a) push_back(a)
typedef pair<int32,int32> pii;
typedef pair<int64,int64> pll;
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;
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int32 n,m;
cin >> n >> m;
vector<vector<int32>> adj(n);
REP(i,m){
int32 a,b;
cin >> a >> b;
--a;--b;
adj[a].pb(b);
adj[b].pb(a);
}
int32 k;
cin >> k;
vector<int32> c(k);
REP(i,k){
cin >> c[i];
--c[i];
}
vector<vector<int32>> g(k,vector<int32>(k,inf));
REP(i,k){
vector<int32> dist(n,inf);
queue<pii> que;
auto push = [&](int32 d,int32 v){
if(chmin(dist[v],d))
que.emplace(d,v);
};
push(0,c[i]);
while(!que.empty()){
auto [d,v] = que.front();que.pop();
if(d != dist[v])continue;
for(auto u : adj[v]){
push(d+1,u);
}
}
REP(j,k){
g[i][j] = dist[c[j]];
}
}
// REP(i,k){
// REP(j,k){
// cout << g[i][j] << " ";
// }
// cout << endl;
// }
vector<vector<int32>> dist(k,vector<int32>(1<<k,inf));
queue<pair<int32,pii>> que;
auto push = [&](int32 d, int32 v, int32 s){
if(chmin(dist[v][s],d))
que.emplace(d,pii(v,s));
};
REP(i,k){
push(0,i,1<<i);
}
while(!que.empty()){
auto [d,p] = que.front();que.pop();
auto [v,s] = p;
if(dist[v][s] != d)continue;
REP(u,k){
if(u == v)continue;
if(g[v][u] == inf)continue;
push(d+g[v][u],u,s|(1<<u));
}
}
int32 ans = inf;
REP(i,k){
chmin(ans,dist[i][(1<<k)-1]);
}
if(ans == inf){
ANS(-1);
}else{
ANS(ans+1);
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
#define pb push_back
#define mp make_pair
const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;
const int MAX_N = 2e5+10;
const int MAX_K = 19;
int n, m;
int a[MAX_N],b[MAX_N];
int k;
int c[MAX_K];
int dist[MAX_K][MAX_N];
int dp[1<<MAX_K][MAX_K];
vector<int> g[MAX_N];
void bfs(int s)
{
int* D = dist[s];
D[c[s]] = 0;
queue<int> que;
que.push(c[s]);
while(!que.empty()){
int cur = que.front(); que.pop();
for(int t : g[cur]){
if(D[t]>D[cur]+1){
D[t]=D[cur]+1;
que.push(t);
}
}
}
}
void solve()
{
for(int i=0;i<m;++i){
g[a[i]].push_back(b[i]);
g[b[i]].push_back(a[i]);
}
memset(dist,0x3f,sizeof(dist));
for(int i=0;i<k;++i) bfs(i);
memset(dp, 0x3f, sizeof(dp));
for(int i=0;i<k;++i)dp[1<<i][i]=1;
for(int i=0;i<(1<<k);++i)for(int j=0;j<k;++j)if(dp[i][j]!=INF){
for(int x=0;x<k;x++)if(!(i>>x&1)){ // adding x
const int d=dist[j][c[x]];
if(d != INF){
dp[i|(1<<x)][x]=min(dp[i|(1<<x)][x],dp[i][j]+d);
}
}
}
int ans = INF;
for(int i=0;i<k;++i)ans=min(ans,dp[(1<<k)-1][i]);
if(ans==INF)ans=-1;
cout<<ans<<'\n';
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n >> m;
for(int i=0;i<m;++i){
cin>>a[i]>>b[i];
a[i]--,b[i]--;
}
cin >> k;
for(int i=0;i<k;++i){
cin>> c[i];
c[i]--;
}
solve();
return 0;
} |
/*@author Vipen Loka*/
#include <bits/stdc++.h>
#define endl '\n'
#define ff first
#define ss second
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define deb(x) cout << #x << ':' << x << '\n';
#define int long long
using namespace std;
template<class T>void show(vector<T> &a) {cerr << "[ "; for (int ij = 0; ij < (int)a.size(); ij++) {cerr << a[ij] << " ";} cerr << "]\n";}
template<class T>void show(T a) {cerr << a << endl;}
int n, k;
int nc2(int n) {
if (n <= 0) {
return 0;
}
return (n * (n - 1)) / 2;
}
int f(int s) {
int res = nc2(s - 1);
res -= nc2(s - 1 - n) * 3;
res += nc2(s - 1 - n * 2) * 3;
res -= nc2(s - 1 - n * 3) * 3;
return res;
}
int f2(int s) {
int l = max(1LL, s - n);
int r = min (n, s - 1);
if (l > r)return 0;
return r - l + 1;
}
void solve() {
int i, j;
cin >> n >> k;
int ksum, pref = 0;
for (int sum = 3; sum <= 3 * n; sum++) {
int now = f(sum);
if (k <= now) {
ksum = sum;
break;
}
else {
k -= now;
}
}
pref = 0;
int beauty, taste, popularity;
for (beauty = 1; beauty <= n; beauty++) {
int now = f2(ksum - beauty);
if (k <= now) {
break;
}
else {
k -= now;
}
}
for (taste = 1; taste <= n; taste++) {
popularity = ksum - beauty - taste;
if (popularity <= 0 || popularity > n)continue;
if (k == 1) {
break;
}
k--;
}
popularity = ksum - beauty - taste;
cout << beauty << ' ' << taste << ' ' << popularity << endl;
}
int32_t main(int32_t argc, char *argv[]) {
ios_base::sync_with_stdio(false);
cin.tie(0);
int T = 1;
// cin >> T;
while (T--) {
solve();
}
cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
} | #include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
#include<array>
using namespace std;
//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
constexpr ll mod = 10007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acosl(-1.0);
ll mod_pow(ll x, ll n, ll m = mod) {
if (n < 0) {
ll res = mod_pow(x, -n, m);
return mod_pow(res, m - 2, m);
}
if (abs(x) >= m)x %= m;
if (x < 0)x += m;
ll res = 1;
while (n) {
if (n & 1)res = res * x % m;
x = x * x % m; n >>= 1;
}
return res;
}
struct modint {
ll n;
modint() :n(0) { ; }
modint(ll m) :n(m) {
if (n >= mod)n %= mod;
else if (n < 0)n = (n % mod + mod) % mod;
}
operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint& a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, ll n) {
if (n == 0)return modint(1);
modint res = (a * a) ^ (n / 2);
if (n % 2)res = res * a;
return res;
}
ll inv(ll a, ll p) {
return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }
modint operator/=(modint& a, modint b) { a = a / b; return a; }
const int max_n = 1 << 1;
modint fact[max_n], factinv[max_n];
void init_f() {
fact[0] = modint(1);
for (int i = 0; i < max_n - 1; i++) {
fact[i + 1] = fact[i] * modint(i + 1);
}
factinv[max_n - 1] = modint(1) / fact[max_n - 1];
for (int i = max_n - 2; i >= 0; i--) {
factinv[i] = factinv[i + 1] * modint(i + 1);
}
}
modint comb(int a, int b) {
if (a < 0 || b < 0 || a < b)return 0;
return fact[a] * factinv[b] * factinv[a - b];
}
modint combP(int a, int b) {
if (a < 0 || b < 0 || a < b)return 0;
return fact[a] * factinv[a - b];
}
const int sup = 1000000;
ll dp[3 * sup + 5][4];
void solve() {
int n; ll k; cin >> n >> k;
dp[0][0] = 1;
rep(t, 3) {
rep(i, t * n + 1) {
dp[i + 1][t + 1] += dp[i][t];
dp[i + n + 1][t + 1] -= dp[i][t];
}
rep(i, (t + 1)* n + 1) {
dp[i + 1][t + 1] += dp[i][t+1];
}
}
k--;
ll s = 0;
for (int i = 3; i <= 3 * n; i++) {
if (k < dp[i][3]) {
s = i; break;
}
else {
k -= dp[i][3];
}
}
ll ans[3] = {};
//cout << dp[4][2] << "\n";
rep1(c, n) {
ll r = s - c;
if (k < dp[r][2]) {
ans[0] = c; break;
}
else {
k -= dp[r][2];
}
}
s -= ans[0];
rep1(c, n) {
ll r = s - c;
if (k < dp[r][1]) {
ans[1] = c; break;
}
else {
k -= dp[r][1];
}
}
s -= ans[1];
ans[2] = s;
rep(i, 3) {
if (i > 0)cout << " ";
cout << ans[i];
}
cout << "\n";
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
//cout << fixed << setprecision(10);
//init_f();
//init();
//expr();
//int t; cin >> t;rep(i,t)
//while(cin>>n,n)
//solve();
solve();
return 0;
} |
#include <bits/stdc++.h>
// clang-format off
using namespace std; using ll = long long; using ull = unsigned long long; using pll = pair<ll,ll>; const ll INF = 4e18;
void print0() {}
template<typename Head,typename... Tail> void print0(Head head,Tail... tail){cout<<fixed<<setprecision(15)<<head;print0(tail...);}
void print() { print0("\n"); }
template<typename Head,typename... Tail>void print(Head head,Tail... tail){print0(head);if(sizeof...(Tail)>0)print0(" ");print(tail...);}
// clang-format on
ll all;
ll memo[65537][9][17];
ll h, w, a, b;
ll bit(ll i, ll j) {
return 1ULL << (i * w + j);
}
bool empty(ll stat, ll i, ll j){
if (i >= h) return false;
if (j >= w) return false;
if(stat & bit(i,j)) return false;
return true;
}
ll dfs(ll stat, ll full, ll half, ll bi, ll bj) {
if (full < 0 || half < 0) return 0;
if (stat + 1 == all) return 1;
if (memo[stat][full][half] != -INF) return memo[stat][full][half];
// 常に一番左上に置く
ll ti = -1;
ll tj = -1;
for (ll j = bj; j < w; j++) {
if(empty(stat,bi,j)){
ti=bi;
tj=j;
break;
}
}
for (ll i = bi+1; i < h; i++) {
if (ti >= 0) break;
for (ll j = 0; j < w; j++) {
if (empty(stat,i,j)) {
ti = i;
tj = j;
break;
}
}
}
return memo[stat][full][half] =
dfs(stat | bit(ti,tj), full, half - 1, ti, tj) +
(empty(stat,ti+1,tj) ? dfs(stat | bit(ti+1,tj) | bit(ti,tj), full - 1, half, ti, tj) : 0) +
(empty(stat,ti,tj+1) ? dfs(stat | bit(ti,tj+1) | bit(ti,tj), full - 1, half, ti, tj) : 0);
}
int main() {
cin >> h >> w >> a >> b;
all = 1ll << (h * w);
for(ll s=0; s<all; s++){
for(ll i=0; i<=a; i++){
for(ll j=0; j<=b; j++){
memo[s][i][j] = -INF;
}
}
}
print(dfs(0, a, b, 0, 0));
}
| #include "bits/stdc++.h"
#define int long long
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = (1LL << 61);
ll mod = 998244353;
int ans = 0;
int next_combination(int sub) {
if (sub == 0)return 1001001001;
int x = sub & -sub, y = sub + x;
return (((sub & ~y) / x) >> 1) | y;
}
int H, W;
int A, B;
int tmp[17];
map<int, bool>mp;
int cnt2 = 0;
void dfs(int nowA, vector<vector<int>>&now) {
cnt2++;
int nowbit = 0;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
nowbit += tmp[i * W + j]*now[i][j];
}
}
int cnt = 0;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
if (i + 1 < H && now[i][j] == 0 && now[i + 1][j] == 0)cnt++;
if (j + 1 < W && now[i][j] == 0 && now[i][j + 1] == 0)cnt++;
}
}
if (mp[nowbit] || cnt < nowA)return;
mp[nowbit] = true;
if (nowA <= 0) {
ans++;
return;
}
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
if (i + 1 < H && now[i][j] == 0 && now[i + 1][j] == 0) {
now[i][j] = 2; now[i + 1][j] = 2;
nowA--;
dfs(nowA, now);
nowA++;
now[i][j] = 0; now[i + 1][j] = 0;
}
if (j + 1 < W && now[i][j] == 0 && now[i][j + 1] == 0) {
now[i][j] = 3; now[i][j + 1] = 3;
nowA--;
dfs(nowA, now);
nowA++;
now[i][j] = 0; now[i][j + 1] = 0;
}
}
}
return;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> H >> W;
cin >> A >> B;
int s = 1;
for (int i = 0; i < 17; i++) {
tmp[i] = s;
s *= 4;
}
int bit = (1 << B) - 1;
for (; bit < (1 << (H*W)); bit = next_combination(bit)) {
mp.clear();
vector<vector<int>>now(H, vector<int>(W, 0));
for (int i = 0; i < H * W; i++) {
if (bit & (1 << i)) {
now[i / W][i % W] = 1;
}
}
dfs(A, now);
//cout << "NOW" << endl;
}
//cout << cnt2 << endl;
cout << ans << endl;
return 0;
} |
//dhruv
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ffor(i,n) for(int i = 0;i < (n); ++i)
#define fro(i,j,n) for(int i = (j);i < (n); ++i)
#define all(v) v.begin(),v.end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vpii vector<pii>
#define ff first
#define ss second
const int mod = 1e9 + 7;
const int inf = 1e18 + 5;
template<typename T>
T binpow(T a,T b,T modi){
T res = 1;
while(b){
if(b&1){
res = (res*a)%modi;
}
b /= 2;
(a *= a) %= modi;
}
return res;
}
template<typename T>
T binpow(T a,T b){
T res = 1;
while(b){
if(b&1){
res = (res*a);
}
b /= 2;
a *= a;
}
return res;
}
template<typename T>
T add(T a,T b){
T x = (a + b)%mod;
x%= mod;
x += mod;
return (x%mod);
}
template<typename T>
T sub(T a,T b){
return add(a,mod - b);
}
template<typename T>
T mul(T a,T b){
return (a*b)%mod;
}
template<typename T>
T inv(T a){
return binpow(a,mod - 2,mod);
}
int make_int(string s){
int x = 0;
reverse(s.begin(),s.end());
string tmp = s;
for(int i = 0;i < s.length(); ++i){
x *= 10;
x += (int)(tmp.back() - '0');
tmp.pop_back();
}
return x;
}
string make_string(int s){
string x;
while(s){
x.push_back(char(s%10 + '0'));
s /= 10;
}
reverse(x.begin(),x.end());
return x;
}
random_device rd;
mt19937 g(rd());
int dx[] = {0,-1,0,1};
int dy[] = {1,0,-1,0};
const int N = 100;
vi fact;
void factorial(){
fact.resize(N);
fact[0] = 1,fact[1] = 1;
fro(i,2,N){
fact[i] = (fact[i - 1]*i)%mod;
}
}
int nCr(int n,int r){
return (mul(fact[n],inv(mul(fact[r],fact[n - r]))));
}
int nPr(int n,int r){
return(mul(nCr(n,r),fact[r]));
}
// Linear Seive
int lp[N + 1];
vector<int> pr;
void ls(){
for(int i = 2;i <= N; ++i){
// means prime
if(lp[i] == 0){
lp[i] = i;
pr.push_back(i);
}
for(int j = 0;j < pr.size() && pr[j] <= lp[i] && i*pr[j] <= N; j++){
lp[i*pr[j]] = pr[j];
}
}
}
// getting the prime factorisation
vector<int> getfc(int n){
vi factors;
while(n != 1){
int x = lp[n];
factors.push_back(x);
while(n%x == 0){
n /= x;
}
}
return factors;
}
int gcd(int a,int b){
while(b){
a %= b;
swap(a,b);
}
return a;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
// shuffle(all(a),g);
char a,b;
cin >> a >> b;
if(a == 'Y'){
cout << char(b - 'a' + 'A');
}else{
cout << b;
}
return 0;
} | #include<bits/stdc++.h>
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1000000007;
const int INF = 1001001001;
int main() {
string s, t;
cin >> s >> t;
if (s == "Y") {
rep(i, t.size()) {
t[i] = t[i] - 'a' + 'A';
}
}
cout << t << endl;
} |
#line 1 "main_b.cpp"
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <type_traits>
#include <unordered_map>
#include <utility>
#include <vector>
/* template start */
using i64 = std::int_fast64_t;
using u64 = std::uint_fast64_t;
#define rep(i, a, b) for (i64 i = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()
#ifdef LOCAL
#define debug(...) \
std::cerr << "LINE: " << __LINE__ << " [" << #__VA_ARGS__ << "]:", \
debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
void debug_out() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
std::cerr << " " << h;
if (sizeof...(t) > 0) std::cout << " :";
debug_out(t...);
}
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
return os << pa.first << " " << pa.second;
}
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
for (std::size_t i = 0; i < vec.size(); i++)
os << vec[i] << (i + 1 == vec.size() ? "" : " ");
return os;
}
template <typename T1, typename T2>
inline bool chmax(T1& a, T2 b) {
return a < b && (a = b, true);
}
template <typename T1, typename T2>
inline bool chmin(T1& a, T2 b) {
return a > b && (a = b, true);
}
template <typename Num>
constexpr Num mypow(Num a, u64 b, Num id = 1) {
if (b == 0) return id;
Num x = id;
while (b > 0) {
if (b & 1) x *= a;
a *= a;
b >>= 1;
}
return x;
}
template <typename T>
std::vector<std::pair<std::size_t, T>> enumerate(const std::vector<T>& data) {
std::vector<std::pair<std::size_t, T>> ret;
for (std::size_t index = 0; index < data.size(); index++)
ret.emplace_back(index, data[index]);
return ret;
}
/* template end */
int main() {
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
i64 n;
std::cin >> n;
std::string s, t;
std::cin >> s >> t;
if (s == t) {
std::cout << 0 << "\n";
return 0;
}
std::vector<i64> sbit, tbit;
rep(i, 0, n) {
if (s[i] == '1') sbit.emplace_back(i);
if (t[i] == '1') tbit.emplace_back(i);
}
i64 snum = sbit.size();
i64 tnum = tbit.size();
if (snum < tnum) {
std::cout << -1 << "\n";
return 0;
}
if ((snum - tnum) % 2 != 0) {
std::cout << -1 << "\n";
return 0;
}
i64 offset = snum - tnum;
rep(i, 0, tnum) {
if (tbit[i] > sbit[i + offset]) {
std::cout << -1 << "\n";
return 0;
}
}
i64 ans = 0;
i64 now = 0;
rep(i, 0, tnum) {
while (sbit[now] < tbit[i]) {
ans += sbit[now + 1] - sbit[now];
now += 2;
}
ans += sbit[now] - tbit[i];
now++;
}
while (now < snum) {
ans += sbit[now + 1] - sbit[now];
now += 2;
}
std::cout<<ans<<"\n";
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
const int INF = 1e9;
const ll LINF = 1e18;
template <class T>
void get_unique(vector<T>& x) {
x.erase(unique(x.begin(), x.end()), x.end());
}
template <class T>
bool chmax(T& a, const T& b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
for (int i = 0; i < int(v.size()); i++) {
is >> v[i];
}
return is;
}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
for (int i = 0; i < int(v.size()); i++) {
os << v[i];
if (i < sz(v) - 1) os << ' ';
}
return os;
}
int main() {
int n;
cin >> n;
queue<int> s, t;
rep(i, n) {
char c;
cin >> c;
if (c == '1') s.push(i);
}
rep(i, n) {
char c;
cin >> c;
if (c == '1') t.push(i);
}
ll ans = 0;
while (sz(s)) {
if (!sz(t)) {
if (sz(s) & 1) {
ans = -1;
} else {
while (sz(s)) {
int x = s.front();
s.pop();
int y = s.front();
s.pop();
ans += ll(y - x);
}
}
break;
}
if (s.front() == t.front()) {
s.pop();
t.pop();
} else if (s.front() < t.front()) {
if (sz(s) < 2) {
ans = -1;
break;
}
int x = s.front();
s.pop();
int y = s.front();
s.pop();
ans += ll(y - x);
} else {
int x = s.front();
s.pop();
int y = t.front();
t.pop();
ans += ll(x - y);
}
}
if (sz(t)) ans = -1;
cout << ans << '\n';
} |
// Copyright 2020 Tsutomu ISHIKAWA
// Author: Tsutomu ISHIKAWA
#include <bits/stdc++.h>
using namespace std;
int l;
int res;
long long a[1010];
long long calcNumOfCombination(int n, int r){
long num = 1;
for(int i = 1; i <= r; i++){
num = num * (n - i + 1) / i;
}
return num;
}
int main() {
cin >> l;
cout << calcNumOfCombination(l-1, 11) << endl;
return 0;
}
| /*
2021-03-29 14:18:10.721371
Category: combi
Rating: ?
*/
/*
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/
#include<bits/stdc++.h>
using namespace std;
//
//
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define int long long
#define ll long long
#define ld long double
#define gap ' '
#define endl '\n'
/*
void solve() {
int n; cin>>n; n--; // we have n-1 positions to split, choose 11
int up=1,down=1;
for(int i=1;i<=11;i++) {
up*=n--;
down*=i;
int g=__gcd(up,down);
up/=g;
down/=g;
}
cout<<up/down<<endl;
}
let try dp approach....
*/
int dp[201][12];
void solve() {
int n; cin>>n;
for(int i=1;i<=n;i++) {
for(int j=0;j<=11;j++) {
if(j==0) dp[i][j]=1;
else
dp[i][j]=dp[i-1][j-1] + dp[i-1][j];
}
}
cout<<dp[n][11]<<endl;
}
void solve(bool testcase) {
int t;cin>>t;while(t--)solve();
}
int32_t main() {
fio
solve();
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n, res = INT_MAX;
cin >> n;
vector<vector<int>> p(n, vector<int>(3));
for (auto& i : p) {
for (auto& j : i) {
cin >> j;
}
}
auto calc = [&](int x, int y) {
return abs(p[x][0] - p[y][0]) + abs(p[x][1] - p[y][1]) + max(0, p[y][2] - p[x][2]);
};
vector<vector<int>> dp(1 << n, vector<int>(n, 1e9));
dp[1][0] = 0;
for (int s = 0; s < (1 << n); s++) {
for (int j = 0; j < n; j++) { // 枚举 当前经过的最后那个点
if (!(s & (1 << j))) continue;
for (int k = 0; k < n; k++) { // 枚举 将要前往的点
if (s & (1 << k)) continue;
dp[s | (1 << k)][k] = min(dp[s | (1 << k)][k], dp[s][j] + calc(j, k));
}
}
}
for (int i = 0; i < n; i++) {
res = min(res, dp[(1 << n) - 1][i] + calc(i, 0));
}
cout << res;
return 0;
}
| #include<iostream>
#include<string>
#include<vector>
#include<deque>
#include<algorithm>
#include<stack>
#include<iomanip>
#include<queue>
#include<map>
#include<math.h>
#include<climits>
#include<limits.h>
using namespace std;
const int N = 17, M = 272144;
int x[N], y[N], z[N];
int dp[M][N];
int dis(int f, int s) {
return abs(x[f] - x[s]) + abs(y[f] - y[s]) + max(0, z[s] - z[f]);
}
int solve(int lst, vector <bool> v, bool is_back = false) {
if (is_back) {
if (lst == 0)
return 0;
}
int h = 0;
for (int i = 0; i < (int)v.size(); i++) {
h *= 2;
h += (int)v[i];
}
h *= 2;
h += (int)is_back;
if (dp[h][lst] != -1)
return dp[h][lst];
bool f = true;
for (int i = 0; i < (int)v.size(); i++)
if (!v[i])
f = false;
if (lst == 0 && f) {
return 0;
}
if (f) {
for (int i = 0; i < (int)v.size(); i++) {
v[i] = false;
}
v[lst] = true;
return solve(lst, v, true);
}
int ans = INT_MAX;
for (int i = 0; i < (int)v.size(); i++) {
if (v[i])
continue;
v[i] = true;
int t = solve(i, v, is_back) + dis(lst, i);
ans = min(ans, t);
v[i] = false;
}
return dp[h][lst] = ans;
}
int main(){
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> x[i] >> y[i] >> z[i];
}
for (int i = 0; i < M; i++)
for (int j = 0; j < N; j++)
dp[i][j] = -1;
vector <bool> v;
for (int i = 0; i < n; i++)
v.push_back(false);
v[0] = true;
cout << solve(0, v)<<'\n';
}
|
#include <bits/stdc++.h>
typedef long long ll ;
using namespace std;
int main() {
int n; cin >> n;
vector<int> a(n),b(n),c(n), hash(n,0);
for (int i = 0; i < n ; i++)
cin >> a[i];
for (int i = 0; i < n; i++)
cin >> b[i];
for (int i = 0; i < n; i++)
cin >> c[i];
for (int i = 0; i < n ; i++)
hash[a[i]-1]++;
ll ans = 0;
for (int i = 0; i < n; i++)
ans += hash[b[c[i]-1]-1];
cout << ans;
return 0;
} | // Whatever doesn't kill you simply makes you stronger.
// Every single thing is destined, everything is written.
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long
#define hii cout << "hii" << endl
#define int long long
#define endl '\n'
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)
#define all(s) s.begin(), s.end()
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
template <class Arg1, class... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
const char* sep = strchr(names + 1, ',');
cerr.write(names, sep - names) << " : " << arg1 << " ";
__f(sep + 1, args...);
}
#else
#define trace(...) 0
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE
const int N = 5e5 + 5;
const int MAXN = 1e7 + 5;
const int M = 1000 + 5;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const int INF = 1e17 + 8;
const int INFF = 1e18 + 8;
const int LG = 21;
int arr[N];
int cnt[N];
void solve()
{
int n;
cin >> n;
for(int i = 0; i < n; i++)
{
cin >> arr[i];
cnt[arr[i]]++;
}
int mx = 0;
int no = -1;
for(int i = 2; i < N; i++)
{
int check = 0;
for(int j = i; j < N; j += i)
{
check += cnt[j];
}
if(check > mx)
{
mx = check;
no = i;
}
}
cout << no << endl;
}
int32_t main()
{
ios_base:: sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output1.txt", "w", stdout);
#endif
int t = 1;
// cin >> t;
while(t--)
{
solve();
}
return 0;
} |
#include <bits/stdc++.h>
#define fo(a,b,c) for (a=b; a<=c; a++)
#define fd(a,b,c) for (a=b; a>=c; a--)
#define add(a,b) a=((a)+(b))%mod
#define mod 998244353
#define Mod 998244351
#define ll long long
//#define file
using namespace std;
int n,i,j,k,l,sum;
int a[101];
int f[101][10001];
ll jc[101];
ll ans;
ll qpower(ll a,int b) {ll ans=1; while (b) {if (b&1) ans=ans*a%mod;a=a*a%mod;b>>=1;} return ans;}
int main()
{
#ifdef file
freopen("b.in","r",stdin);
#endif
scanf("%d",&n);
fo(i,1,n) scanf("%d",&a[i]),sum+=a[i];
if (sum&1) {printf("0\n");return 0;}
f[0][0]=1;
fo(i,1,n)
{
fd(j,i-1,0)
{
fo(k,0,10000)
if (f[j][k])
add(f[j+1][k+a[i]],f[j][k]);
}
}
sum/=2;
jc[0]=1;
fo(i,1,n) jc[i]=jc[i-1]*i%mod;
fo(i,1,n) add(ans,jc[i]*jc[n-i]%mod*f[i][sum]);
printf("%lld\n",(ans+mod)%mod);
fclose(stdin);
fclose(stdout);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
int64_t A[n];
for(int i=0; i<n; i++) cin >> A[i];
if(n==1){
cout << A[0] << endl;
return 0;
}else if(n==2){
cout << (A[0]^A[1]) << endl;
}
int64_t ans = 1 << 30;
for(int64_t i=1; i<(1<<(n-1)); i++){
int j=0;
int64_t or_result = A[0], tmp=0;
while(j<n-1){
if(i>>j&1){
tmp = tmp ^ or_result;
or_result = A[j+1];
}else{
or_result = or_result | A[j+1];
}
j++;
}
tmp = tmp ^ or_result;
if(ans>tmp){
ans = tmp;
}
if(ans==0){
cout << 0 << endl;
return 0;
}
}
cout << ans << endl;
return 0;
}
|
//
// Created by Anton Gorokhov
//
#ifdef lolipop
#define _GLIBCXX_DEBUG
#endif
#include <iostream>
#include <cstddef>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <ctime>
#include <unordered_map>
#include <random>
#include <iomanip>
#include <cmath>
#include <queue>
#include <unordered_set>
#include <cassert>
#include <bitset>
#include <deque>
#include <utility>
#define int long long
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define ld double
using namespace std;
mt19937 rnd(time(nullptr));
inline void fastio() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
}
void solve() {
int n;
cin >> n;
int L = -1, R = n;
while (L + 1 < R) {
int M = (L + R) / 2;
if ((M * (M + 1)) / 2 >= n) {
R = M;
} else {
L = M;
}
}
cout << R << '\n';
}
signed main() {
#ifdef lolipop
freopen("input.txt", "r", stdin);
#else
fastio();
#endif
int T = 1;
// cin >> T;
while (T--) {
solve();
}
return 0;
} | #include <stdio.h>
int N, Sum;
int main() {
int i;
scanf("%d", &N);
for (i = 1; Sum < N; Sum += i, i++);
printf("%d", i - 1);
return 0;
}
|
#include<bits/stdc++.h>
#define AynVul int main()
#define ll long long
#define task "A"
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define Rep(i, r, l) for (int i = (r); i >= (l); --i)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x.size())
#define eb emplace_back
#define debug(a) cout << a << ' '
#define Debug(a, b) cout << a << ' ' << b << '\n'
using namespace std;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
const int Sz = 2e3+3;
const ll MOD = 1e9+7;
const int oo = 1e9;
vi g[Sz];
vector<bool> vis(Sz);
int cnt[Sz];
int dfs(int u)
{
int ans = 1;
vis[u] = 1;
for(int v: g[u])
if(!vis[v])
ans += dfs(v);
return ans;
}
AynVul
{
//freopen(task".inp", "r", stdin);
//freopen(task".out", "w", stdout);
ios_base::sync_with_stdio(0); cin.tie(0);
//~This too, shall pass~
//Fighting
int n, m;
cin >> n >> m;
rep(i, 1, m)
{
int u, v;
cin >> u >> v;
g[u].eb(v);
}
rep(i, 1, n) vis[i] = 0;
int ans = 0;
rep(i, 1, n)
{
vis.assign(n, 0);
ans += dfs(i);
}
cout << ans;
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define all(v) v.begin(),v.end()
const int mod = 1e9 + 7;
ll dp[(1 << 18)][18];
int main (){
fast_io;
ll n, m;
cin >> n >> m;
vector<vector<int> > constraints;
for (int i = 0; i < m; i++) {
int x, y, z;
cin >> x >> y >> z;
x--, y--;
constraints.push_back({x, y, z});
}
dp[0][0] = 1;
for (int i = 0; i < (1 << n); i++) {
int pref[n];
memset(pref, 0, sizeof(pref));
for (int j = 0; j < n; j++) {
if (i & (1 << j))
pref[j]++;
}
for (int j = 1; j < n; j++)
pref[j] += pref[j - 1];
for (int j = 0; j < n; j++) {
if (dp[i][j] == 0)
continue;
for (int k = 0; k < n; k++) {
if ((i & (1 << k)))
continue;
bool flag = false;
int len = __builtin_popcount(i);
for (auto& constraint: constraints) {
if (len != constraint[0])
continue;
if ((k <= constraint[1] && constraint[2] == pref[constraint[1]]) ||
(constraint[2] < pref[constraint[1]])) {
flag = true;
break;
}
}
if (flag == true)
continue;
dp[i | (1 << k)][k] += dp[i][j];
}
}
}
ll ans = 0;
for (int i = 0; i < n; i++) {
ans += dp[(1 << n) - 1][i];
}
cout << ans << endl;
}
|
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <complex>
#include <regex>
#define Debug cout << "line: " << __LINE__ << "Debug" << endl;
#define Yes cout << "Yes" << endl;
#define YES cout << "YES" << endl;
#define No cout << "No" << endl;
#define NO cout << "NO" << endl;
#define ALL(a) (a).begin(), (a).end()
#define MP make_pair
#define MOD 1000000007
#define PI 3.14159265358979323846
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vd = vector<double>;
using vl = vector<long long>;
void set_FPD(int n){
cout << fixed << setprecision(n);
return;
}
ll func(vl a,vl b,vl c){
ll abmin=1e15,acmin=1e15,bcmin=1e15;
for(ll &x:a){
auto itr=lower_bound(ALL(b),x);
abmin=min({abs(x-*itr),abs(x-*(itr-1)),abmin});
}
for(ll &x:a){
auto itr=lower_bound(ALL(c),x);
acmin=min({abs(x-*itr),abs(x-*(itr-1)),acmin});
}
for(ll &x:b){
auto itr=lower_bound(ALL(c),x);
bcmin=min({abs(x-*itr),abs(x-*(itr-1)),bcmin});
}
return min(abmin,acmin+bcmin);
}
ll func(vl a,vl b){
ll abmin=1e15;
for(ll &x:a){
auto itr=lower_bound(ALL(b),x);
abmin=min({abs(x-*itr),abs(x-*(itr-1)),abmin});
}
return abmin;
}
void Main(){
int n;
cin>>n;
vl r,g,b;
for(int i=0;i<2*n;i++){
ll a;
char c;
cin>>a>>c;
if(c=='R') r.push_back(a);
else if(c=='G') g.push_back(a);
else b.push_back(a);
}
ll rsize=r.size(),gsize=g.size(),bsize=b.size();
if(rsize%2==0 && gsize%2==0 && bsize%2==0){
cout<<0<<endl;
return;
}
if(rsize!=0) sort(ALL(r));
if(gsize!=0) sort(ALL(g));
if(bsize!=0) sort(ALL(b));
if(rsize%2==1 && gsize%2==1){
if(bsize==0) cout<<func(r,g);
else cout<<func(r,g,b);
}
else if(gsize%2==1 && bsize%2==1){
if(rsize==0) cout<<func(g,b);
else cout<<func(g,b,r);
}
else if(bsize%2==1 && rsize%2==1) {
if(gsize==0) cout<<func(b,r);
else cout<<func(b,r,g);
}
cout<<endl;
return;
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
Main();
return 0;
} | #pragma region Macros
#include <bits/stdc++.h>
// #include <atcoder/all>
using std::cin;
using std::cout;
using std::endl;
using std::sort;
using std::string;
using std::vector;
// using namespace atcoder;
typedef long long ll;
#define int long long
#ifdef _DEBUG
#define DEBUG(x) cout << #x << ": " << x << endl;
#else
#define DEBUG(x)
#endif
#define ALL(obj) (obj).begin(), (obj).end()
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define YesNo(bool) \
if (bool) \
{ \
cout << "Yes" << endl; \
} \
else \
{ \
cout << "No" << endl; \
}
#define PRINTARR(arr) \
for (auto e : arr) \
cout << e << " "; \
cout << endl;
constexpr ll MOD = (ll)1e9 + 7;
constexpr ll INF = (ll)1e18;
constexpr double EPS = 1e-9;
const double PI = std::acos(-1);
#pragma endregion
#pragma region Library
#pragma endregion
int calc(vector<int> arr1, vector<int> arr2)
{
if (arr1.size() == 0 || arr2.size() == 0)
{
return INF;
}
auto it1 = 0;
auto it2 = 0;
int ret = std::abs(arr1[0] - arr2[0]);
while (!(it1 == (int)arr1.size() - 1 && it2 == (int)arr2.size() - 1))
{
ret = std::min(ret, std::abs(arr1[it1] - arr2[it2]));
if (it1 == (int)arr1.size() - 1)
{
it2++;
}
else if (it2 == (int)arr2.size() - 1)
{
it1++;
}
else if (arr1[it1] < arr2[it2])
{
it1++;
}
else
{
it2++;
}
}
ret = std::min(ret, std::abs(arr1[it1] - arr2[it2]));
return ret;
}
signed main()
{
std::ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> red, green, blue;
REP(i, 2 * n)
{
int c;
string color;
cin >> c >> color;
if (color == "R")
{
red.push_back(c);
}
if (color == "G")
{
green.push_back(c);
}
if (color == "B")
{
blue.push_back(c);
}
}
if (red.size() % 2 == 0 && green.size() % 2 == 0 && blue.size() % 2 == 0)
{
cout << 0 << endl;
}
else
{
vector<int> even, odd1, odd2;
if (red.size() % 2 == 0)
{
even = red;
odd1 = green;
odd2 = blue;
}
if (green.size() % 2 == 0)
{
even = green;
odd1 = red;
odd2 = blue;
}
if (blue.size() % 2 == 0)
{
even = blue;
odd1 = green;
odd2 = red;
}
std::sort(ALL(even));
std::sort(ALL(odd1));
std::sort(ALL(odd2));
cout << std::min(calc(odd1, odd2), calc(odd1, even) + calc(even, odd2)) << endl;
// cout << calc(odd1, even) << " " << calc(even, odd2) << endl;
// PRINTARR(even);
return 0;
}
}
|
#include <bits/stdc++.h>
using i32 = std::int32_t;
using i64 = std::int64_t;
using u32 = std::uint32_t;
using u64 = std::uint64_t;
using usize = std::size_t;
const i32 INF = 1001001001;
const i64 LINF = 1001001001001001;
const u32 MOD1 = 1000000007;
const u32 MOD2 = 998244353;
i64 ntop(i64 x, i64 m) {
if(x < 0) x += std::ceil((double)std::abs(x) / m) * m;
return x % m;
}
i64 gcd(i64 a, i64 b) {
return (b == 0 ? a : gcd(b, a % b));
}
i64 lcm(i64 a, i64 b) {
if(a == 0 || b == 0) return -1;
return a / gcd(a, b) * b;
}
i64 ext_gcd(i64 a, i64& x, i64 b, i64& y) {
if(b == 0) {
x = 1;
y = 0;
return a;
}
i64 g = ext_gcd(b, y, a % b, x);
y -= a / b * x;
return g;
}
std::vector<std::pair<i64, i64>> prime_factor(i64 n) {
std::vector<std::pair<i64, i64>> pf;
i64 e = 0;
while(n % 2 == 0) {
e++;
n /= 2;
}
if(e > 0) pf.emplace_back(std::make_pair(2, e));
for(i64 i = 3; i * i <= n; i += 2) {
e = 0;
while(n % i == 0) {
e++;
n /= i;
}
if(e > 0) pf.emplace_back(std::make_pair(i, e));
}
if(n > 1) pf.emplace_back(std::make_pair(n, 1));
return pf;
}
i64 euler_totient(i64 n) {
std::vector<std::pair<i64, i64>> pf = prime_factor(n);
i64 res = n;
for(const auto& x : pf) {
res -= res / x.first;
}
return res;
}
i64 linear_congruence_equation(i64 a, i64 c, i64 m) {
i64 u, v;
i64 g = ext_gcd(a, u, m, v);
if(c % g != 0) return -1;
i64 res = c / g * u % m;
return ntop(res, m);
}
i64 chinese_remainder_theorem(i64 b, i64 m, i64 c, i64 n) {
return m * linear_congruence_equation(m, ntop(c - b, n), n) + b;
}
using namespace std;
int main(){
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
i64 n;
cin>>n;
i64 ans=1;
for(i64 i=2;i<=n;i++){
ans=lcm(ans,i);
}
cout<<ans+1<<endl;
} | #include <bits/stdc++.h>
using namespace std;
////////////////////////////////////////////////////////////////////////////<editor-fold desc="macros">
#define endl "\n"
#define long long long
#define all(v) (v).begin(),(v).end()
#define makeset(v) (v).resize(unique((v).begin(),(v).end())-(v).begin())
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define filein freopen("input.txt", "r", stdin);
#define fileout freopen("output.txt", "w", stdout);
#define getline(x) getline(cin,x)
#define makelower(s) transform(s.begin(),s.end(),s.begin(),::tolower)
bool sortby(pair<int,int> a,pair<int,int> b){
double x=(double )a.first/a.second;
double y=(double )b.first/b.second;
return x<y;}
long Pow(long x, long y) {
if(y == 0)return 1;
long tmp=Pow(x,y/2);
tmp*=tmp;
if(y&1)tmp*=x;
return tmp;
}
#define printcase(x) cout<<"Case "<<in++<<": "<<x<<endl
#define memset(a,b) memset(a,b,sizeof(a))
#define print1d(ary) cout<<"[";for(auto x:(ary)){cout<<x<<",";}cout<<"]"<<endl;
#define print2d(x) for(int m = 0; m <sizeof(x)/sizeof(x[0]) ; ++m){for(int l = 0; l <sizeof(x[0])/sizeof(x[0][0]) ; ++l){cout<<x[m][l]<<" ";}cout<<endl;}
#define pi acos(-1)
#define esp 1e-9
////////////////////////////////////////////////////////////////////////////</editor-fold>
int main() {
///<editor-fold desc="ios">
IOS
#ifdef _AD_
filein //fileout
#endif
///</editor-fold>
int in=1,o;
long t,n,m,q,tmp;
cin>>n;
if(n&1)cout<<"Black"<<endl;
else cout<<"White"<<endl;
}
|
#include <iostream>
#include <string>
#include <set>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <array>
typedef long long ll;
using namespace std;
const int logn = 17;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<vector<int> > f(n+1, vector<int>(logn, 0));
vector<int> ans(n + 1, 0);
for (int i = 1; i <= n; i++)
{
ans[i] = -1;
for (int j = 0; j < logn; j++)
{
if (!f[i][j])
{
ans[i] = j;
break;
}
}
for (int j = i; j <= n; j += i)
{
f[j][ans[i]]++;
}
}
for (int i = 1; i <= n; i++) cout << ans[i] + 1 << " ";
cout << "\n";
return 0;
} | #include <bits/stdc++.h>
//#include <cmath>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define mod 1000000007
//#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second
#define bs(yup,x) binary_search(yup.begin(),yup.end(),x) //it will return bollean value
#define lb(yup,x) lower_bound(yup.begin(),yup.end(),x) //it will return the adress of the number which is equal to or just greater than x ,and if it is equal to yup.end() than their in no such number exist
#define ub(yup,x) upper_bound(yup.begin(),yup.end(),x)
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
using namespace std;
const long long N=100005, INF=2000000000000000000;
const long double EPS= 0.000000000001;
int power(int a, int b, int p)
{
if(a==0)
return 0;
int res=1;
a%=p;
while(b>0)
{
if(b&1)
res=(res*a)%p;
b>>=1;
a=(a*a)%p;
}
return res;
}
vi prime;
bool isprime[N];
void pre()
{
for(int i=2;i<N;i++)
{
if(isprime[i])
{
for(int j=i*i;j<N;j+=i)
{
isprime[j]=false;
prime.pb(i);
}
}
}
return;
}
int32_t main()
{
IOS;
//fill(isprime, true);
//pre();
int qter=1;
//cin>>qter;
for(int wert=1;wert<=qter;wert++)
{
//cout<<"Case #"<<wert<<": ";
int n;
cin>>n;
int ans[n+1];
ans[1]=1;
rep(i,2,n+1) ans[i]=2;
rep(i,2,n+1)
{
int val=ans[i];
for(int j=i*2;j<=n;j+=i)
{
ans[j]=max(ans[j],ans[i]+1);
}
}
rep(i,1,n+1) cout<<ans[i]<<" ";
//cout<<ans<<"\n";
}
}
|
#include<bits/stdc++.h>
#define rei register int
#define ll long long
#define PLL pair<ll,ll>
#define mk make_pair
using namespace std;
const int N=1e5+100;
ll k,n,m;
ll a[N],b[N];
priority_queue<PLL>p;
int main(){
scanf("%d%d%d",&k,&n,&m);
ll sum=0;
for(rei i=1;i<=k;++i){
scanf("%d",&a[i]);
b[i]=(m*a[i])/n;
sum+=b[i];
ll temp=m*a[i]-n*b[i];
p.push(mk(temp,i));
}
while(sum<m){
++b[p.top().second];
p.pop();
++sum;
}
for(rei i=1;i<=k;++i)
printf("%d ",b[i]);
puts("");
return 0;
} | /*
@author: Saurav Sihag
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ull unsigned long long
#define ff first
#define ss second
#define lld long double
template <class T>
void print(vector<T>& v){
for(T x:v) cout<<x<<" ";
cout<<"\n";
}
void inp(vector<ll>& v, int n){
for (int i=0; i<n; ++i) scanf("%lld", &v[i]);
}
// const int nax=1e+5+5;
// const int inf=1e+9+5;
const ll mod=1e+9+7;
// const ll mod=998244353;
const ll nax=1e+17+5;
// const int dx[4]={0,0,-1,1};
// const int dy[4]={1,-1,0,0};
lld dp[101][101][101];
lld recur(int a, int b, int c){
if (a==100 || b==100 || c==100) return 0;
if (dp[a][b][c]!=-1) return dp[a][b][c];
lld res=0, aa=a, bb=b, cc=c, d=(aa+bb+cc);
if (a>0){
res+=aa*(recur(a+1, b, c)+1.0);
}
if (b>0){
res+=bb*(recur(a, b+1, c)+1.0);
}
if (c>0){
res+=cc*(recur(a, b, c+1)+1.0);
}
res/=d;
// cout<<a<<" "<<b<<" "<<c<<" res="<<res<<endl;
return dp[a][b][c]=res;
}
void sol(){
int a, b, c;
cin>>a>>b>>c;
// memset(dp, -1, sizeof(dp));
for (int i=0; i<101; ++i) for (int j=0; j<101; ++j) for (int k=0; k<101; ++k) dp[i][j][k]=-1;
lld res=recur(a, b, c);
cout<<res<<endl;
return ;
}
int main() {
int t;
t=1;
// cin>>t;
t++;
std::cout << std::setprecision(20);
for (int i=1; i<t; ++i){
// printf("Case #%d: ", i);
sol();
}
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 gc getchar_unlocked
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long int
#define s(x) cin>>x
#define p(x) cout<<x<<"\n"
#define goog(x, y) cout<<"Case #"<<x<<": "<<y<<"\n"
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define INF 100000000000
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef long double ld;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
uniform_int_distribution<int> uid(0,lim-1);
return uid(rang);
}
int mpow(int base, int exp);
void ipgraph(int n, int m);
void dfs(int u, int par);
int gcd(int a, int b) ;
const int mod = 1'000'000'007;
const int N = 3e5, M = N;
//=======================
vi g[N];
int a[N];
void solve() {
int n,a,b;cin>>n>>a>>b;
p(n-a+b);
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
srand(chrono::high_resolution_clock::now().time_since_epoch().count());
int t = 1;
//cin >> t;
while(t--) {
solve();
}
return 0;
}
int mpow(int base, int exp) {
base %= mod;
int result = 1;
while (exp > 0) {
if (exp & 1) result = ((ll)result * base) % mod;
base = ((ll)base * base) % mod;
exp >>= 1;
}
return result;
}
void ipgraph(int n, int m){
int i, u, v;
while(m--){
cin>>u>>v;
//u--, v--;
g[u].pb(v);
g[v].pb(u);
}
}
void dfs(int u, int par){
for(int v:g[u]){
if (v == par) continue;
dfs(v, u);
}
}
int gcd(int a, int b)
{
if (a == 0)
return b;
return gcd(b % a, a);
} | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define pb push_back
#define ppb pop_back
#define endl '\n'
#define mii map<ll, ll>
#define pii pair<ll, ll>
#define vi vector<ll>
#define all(a) (a).begin(), (a).end()
#define mem0(x) memset(x, 0, sizeof(x))
#define mem1(x) memset(x, -1, sizeof(x))
#define F first
#define S second
#define sz(x) ((ll)x.size())
#define DECIMAL(n) cout<<fixed<<setprecision(n);
#define rep(i, a, b) for (ll i=a; i<b; i++)
#define repr(i, a, b) for (ll i=a-1; i>=b; i--)
#define bitcount(a) (ll)__builtin_popcount(a)
#define lbnd lower_bound
#define ubnd upper_bound
#define ios ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
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>;
// find_by_order(k) returns iterator to kth element starting from 0
// order_of_key(k) returns count of elements strictly smaller than k
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
std::cerr<<name<<" : "<<arg1<<endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
const char* comma = strchr(names+1, ','); std::cerr.write(names, comma-names)<<" : "<<arg1<<" | ";
__f(comma+1, args...);
}
const long double PI=3.14159265358979323846264338;
const double eps=1e-10;
ll hell=1e9+7;
ll inf=((ll)5e18+5);
void solve() {
ll n;
cin>>n;
ll arr[n];
cin>>arr[0];
ll ans=arr[0];
rep(i, 1, n) {
cin>>arr[i];
ans=__gcd(ans, arr[i]);
}
cout<<ans<<endl;
}
signed main() {
ios
ll test=1;
// cin>>test;
while (test--) solve();
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O0")
typedef long long ll;
typedef long double ld;
const ll mod = 1e9+7;
const ll INF = 1e18;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define Rep(i,a,n) for (ll i = (a); i < (n); ++i)
#define All(a) (a).begin(),(a).end()
#define Pi acos(-1)
using V = vector<ll>;
using P = pair<ll,ll>;
using Graph = vector<V>;
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
cout << setprecision(15) << fixed;
ll s, p;
cin >> s >> p;
for (ll i = 1; i <= sqrt(p) + 100; ++i) {
if (p%i == 0) {
ll j = p/i;
if (i+j == s) {
cout << "Yes\n";
return 0;
}
}
}
cout << "No\n";
} | #include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,s,n) for (int i = (s); i < (n); ++i)
#define rrep(i,n,g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define len(x) (int)(x).size()
#define dup(x,y) (((x)+(y)-1)/(y))
#define pb push_back
#define eb emplace_back
#define Field(T) vector<vector<T>>
#define pq(T) priority_queue<T,vector<T>,greater<T>>
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main() {
int n;
cin >> n;
vector<vector<ll>> cnt(n+1);
cnt[n].eb(0);
set<int> st;
st.emplace(n);
rep(i,0,n) {
ll x;
int c;
cin >> x >> c;
--c;
cnt[c].eb(x);
st.emplace(c);
}
ll a1 = 0, a2 = 0;
ll ps = 0, pt = 0;
for (auto e : st) {
vector<ll> &v = cnt[e];
sort(all(v));
ll ns = v.front(), nt = v.back();
ll na1 = min(a1 + abs(ps - nt), a2 + abs(pt - nt)) + nt - ns;
ll na2 = min(a1 + abs(ps - ns), a2 + abs(pt - ns)) + nt - ns;
a1 = na1, a2 = na2;
ps = ns, pt = nt;
}
cout << min(a1, a2) << endl;
return 0;
} |
#include <bits/stdc++.h>
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
using namespace std;
using ll = long long;
struct Edge
{
ll to;
ll cost;
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, ll>;
#define mp make_pair
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), v.end()
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = LLONG_MAX;
const int MAX = 510000;
bool graph[nmax][nmax];
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit()
{
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++)
{
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
ll COM(int n, int k)
{
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
for (size_t i = 0; i < n; i++)
{
for (size_t j = 0; j < n; j++)
{
for (size_t k = 0; k < n; k++)
{
dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
}
}
}
}
ll gcd(ll a, ll b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
ll lcm(ll a, ll b)
{
ll g = gcd(a, b);
return a / g * b;
}
ll mulMod(ll a, ll b)
{
return (((a % MOD) * (b % MOD)) % MOD);
}
ll powMod(ll a, ll p)
{
if (p == 0)
{
return 1;
}
else if (p % 2 == 0)
{
ll half = powMod(a, p / 2);
return mulMod(half, half);
}
else
{
return mulMod(powMod(a, p - 1), a);
}
}
ll ceil(ll a, ll b)
{
return (a + b - 1) / b;
}
ll A, B;
bool isOK(ll key)
{
ll cnt = 0;
for (int i = A; i <= B; i++)
{
if (i % key == 0)
{
cnt++;
}
}
if (cnt >= 2)
{
return true;
}
else
{
return false;
}
}
int main()
{
scanf("%lld", &A);
scanf("%lld", &B);
ll ans = -1;
for (int i = 1; i < 200010; i++)
{
ll mi = ceil(A, i);
ll div = mi * i;
ll div2 = (mi +1) * i;
if (A <= div && div2 <= B)
{
ans = i;
}
}
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;
}
const int maxn=3010;
const int INF=1e9;
int n,a[maxn][5];
int dp[maxn][32][5];
bool solve(int mid) {
memset(dp,0,sizeof(dp));
dp[0][0][0]=1;
for (int id=1;id<=n;id++) {
int now=0;
for (int i=0;i<=4;i++) if (a[id][i]>=mid) now|=(1<<i);
for (int i=0;i<=3;i++) {
for (int t=0;t<32;t++) if (dp[id-1][t][i]) {
dp[id][t|now][i+1]=dp[id][t][i]=1;
}
}
}
return dp[n][31][3];
}
int main() {
//freopen("1.txt","r",stdin);
read(n);
for (int i=1;i<=n;i++)
for (int j=0;j<=4;j++) read(a[i][j]);
int l=0,r=INF+10,res,mid;
while (l<=r) {
mid=(l+r)>>1;
if (solve(mid)) res=mid,l=mid+1;
else r=mid-1;
}
printf("%d\n",res);
return 0;
}
/*
REMEMBER:
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!
Array size? Integer overflow? Time complexity? Memory usage? Precision error?
*/ |
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
using namespace std;
template <typename T1, typename T2> bool mini(T1 &a, T2 b) {
if (a > b) {a = b; return true;} return false;
}
template <typename T1, typename T2> bool maxi(T1 &a, T2 b) {
if (a < b) {a = b; return true;} return false;
}
const int N = 1e5 + 5;
const int oo = 1e9;
vector <long long> s[100];
vector <int> val;
long long l, r, ans;
bool used[100];
bool cop[100][100];
void backtrack(int i, vector <long long> &a) {
if (i == (int) val.size()) {
ans++;
return;
}
backtrack(i + 1, a);
for (long long x : s[val[i]]) {
bool ok = true;
for (long long y : a) if (!cop[x - l][y - l]) {
ok = false;
break;
}
if (!ok)
continue;
a.push_back(x);
backtrack(i + 1, a);
a.pop_back();
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> l >> r;
for (long long i = l; i <= r; i++)
for (long long j = l; j <= r; j++)
if (__gcd(i, j) == 1)
cop[i - l][j - l] = true;
for (int i = 2; i <= 80; i++)
for (long long j = l; j <= r; j++) if (!used[j - l] && j % i == 0) {
s[i].push_back(j);
used[j - l] = true;
}
for (int i = 2; i <= 80; i++)
if (s[i].size())
val.push_back(i);
vector <long long> a;
backtrack(0, a);
for (int i = 0; i <= r - l; i++)
if (!used[i])
ans <<= 1;
cout << ans;
return 0;
} | #pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
#include<iostream>
#include<cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please
const int CM = 320000;
char cn[CM], * ci = cn, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
ll tmp = *(ll*)ci;
int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
tmp = tmp << dig & ma1;
tmp = tmp * 10 + (tmp >> 8) & ma2;
tmp = tmp * 100 + (tmp >> 16) & ma3;
tmp = tmp * 10000 + (tmp >> 32) & ma4;
ci += 72 - dig >> 3;
return tmp;
}
const int MAX = 10000;
class shuturyoku_unko {
public:
char C[MAX * 5];
constexpr shuturyoku_unko() : C() {
rep(i, MAX) {
int X = i;
rep(j, 4) {
C[i * 5 + 3 - j] = '0' + X % 10;
X /= 10;
}
C[i * 5 + 4] = '\n';
}
}
};
constexpr shuturyoku_unko f;
const int dm = 260000;
char dn[dm], * di = dn;
void putint(ll A) {
int dig = 1;
if (A >= 100000000) {
if (A >= 100000000000) dig = 4;
else if (A >= 10000000000) dig = 3;
else if (A >= 1000000000) dig = 2;
memcpy(di + 4 + dig, f.C + A % 10000 * 5, 5);
A /= 10000;
memcpy(di + dig, f.C + A % 10000 * 5, 4);
memcpy(di, f.C + A / 10000 * 5 + 4 - dig, dig);
di += 9 + dig;
}
else {
if (A >= 10000) {
if (A >= 10000000) dig = 4;
else if (A >= 1000000) dig = 3;
else if (A >= 100000) dig = 2;
memcpy(di + dig, f.C + A % 10000 * 5, 5);
memcpy(di, f.C + A / 10000 * 5 + 4 - dig, dig);
di += 5 + dig;
}
else {
if (A >= 1000) dig = 4;
else if (A >= 100) dig = 3;
else if (A >= 10) dig = 2;
memcpy(di, f.C + A * 5 + 4 - dig, dig + 1);
di += 1 + dig;
}
}
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
fread(cn, 1, 320000, stdin);
int T = getint();
rep(t, T) {
int L = getint(), R = getint();
ll tmp = R - L - L;
if (tmp >= 0) putint((tmp + 2) * (tmp + 1) >> 1);
else putint(0);
}
fwrite(dn, 1, di - dn, stdout);
Would you please return 0;
} |
//-- In the name of ALLAH --
// We're nothing and you're everything.
// Ya Ali!
#include<bits/stdc++.h>
using namespace std;
#define pai acos(-1)
#define ff first
#define ss second
#define ll long long
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define sz(a) (ll)a.size()
#define endl "\n"
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a)*((b)/gcd(a,b))
#define all(vec) vec.begin(),vec.end()
#define ms(a, b) memset(a,b,sizeof(a))
#define rep(i,n) for(int i= 0; i < int(n); i++)
#define rep1(i,n) for(int i= 1; i <= n; i++)
#define rev(i,n) for(int i= (int)(n-1);i>=0;i--)
#define rev1(i,n) for(int i= (int) n;i>= 1;i--)
#define TEST_CASE(t) for(int zz=1;zz<=t;zz++)
#define PRINT_CASE printf("Case %d: ",zz)
#define fii freopen("input.txt","r",stdin);
#define foo freopen("output.txt","w",stdout);
#define FAST ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
const ll M = 1e9+7;
const ll mxn = 2e5+7;
int main()
{
ll i,j,k,a,b,c,d,n,m,t,x,y,z,u,v;
set<ll>st;
for(i=0;i<=mxn;i++)
{
st.insert(i);
}
ll ans;
map<ll,bool>vis;
cin>>n;
for(i=0;i<n;i++)
{
cin>>m;
auto p = st.begin();
if(*p!=m)
{
ans=*p;
if(!vis[m]&&(st.find(m)!=st.end()))
{
st.erase(st.find(m));
vis[m]=true;
}
}
else
{
st.erase(st.begin());
p = st.begin();
ans=*p;
}
cout<<ans<<endl;
}
return 0;
}
| /*------------------------------------
.......Bismillahir Rahmanir Rahim.....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <utility>
#include <list>
#include <stack>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#include <functional>
#define mod 998244353
#define int long long
#define ld long double
#define pb push_back
#define vi vector<int>
#define co(x) cout << x << '\n'
#define dbg(x) cerr << #x << " = " << x << '\n'
#define bitcount(x) (int)__builtin_popcount(x)
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define sz(x) (int)x.size()
#define all(a) a.begin(),a.end()
#define ff first
#define ss second
#define pi acos(-1.0)
#define pii pair<int,int>
#define lcm(a,b) (a*b)/__gcd(a,b)
using namespace std;
inline void solve(){
int n; cin>>n;
map <int,int> c;
int cur = 0 ;
while (n--){
int x; cin >> x;
c[x] = 1;
while (c.count(cur)) cur++;
co(cur);
}
}
signed main()
{
fast ;
int n=1; // cin>>n;
while (n--) solve();
return 0;
}
|
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <fstream>
#include <array>
#include <map>
#include <queue>
#include <time.h>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) (min(a,b) <= (x) && (x) <= max(a,b)) //hei
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 1000000007LL
#define bitcheck(a,b) ((a >> b) & 1)
#define bitset(a,b) ( a |= (1 << b))
#define bitunset(a,b) (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589
#define izryt bool
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
std::fill((T*)array, (T*)(array + N), val);
}
//[a, b)
#define Getsum(ar, a,b) (ar[b] - ar[a])
#define INF 10000000000000000LL
#define chmax(a,b) a = max(a,b)
#define chmin(a,b) a = min(a,b)
struct Edge {
int from, to;
ll w;
bool operator<(const Edge& rhs) const {
return MP(w, MP(from, to)) < MP(rhs.w, MP(rhs.from, rhs.to));
}
};
typedef vector<vector<Edge>> Graph;
typedef unsigned long long ull;
void end(){
cout << "No" << endl;
exit(0);
}
#define IKI 1000
int main(){
int n;
cin >> n;
vector<int> p(n * 2);
REP(i,n){
int a,b;
cin >> a >> b;
a--,b--;
if(a != -2){
if(p[a]) end();
p[a] = i+1;
}
if(b != -2){
if(p[b]) end();
p[b] = -i-1;
}
if(a != -2 && b != -2){
p[a] += IKI;
p[b] -= IKI;
}
}
bool dp[201][201] = {};
rep(len,1,n + 1){
REP(st, n*2){
int en = st + len * 2;
if (en > n*2) continue;
rep(i, 1, len){
dp[st][en] |= dp[st][st + i*2] & dp[st + i*2][en];
}
bool ok = true;
REP(i,len){
if(p[st + i] < 0 || p[st + i + len] > 0) ok = false;
else if(p[st + i] == 0){
if(abs(p[st + i + len])>IKI) ok = false;
}
else if(p[st + i] > IKI){
if(p[st + i + len] != -p[st + i]) ok =false;
}
else {
if(p[st + i + len] != 0) ok =false;
}
}
dp[st][en] |= ok;
}
}
cout << (dp[0][n * 2] ? "Yes" : "No") << endl;
} | #include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
#include <cstdint>
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 int INF=1001001001;
const int mod = 1000000007;
int main() {
int N;
cin>>N;
vector<int>type(2*N);//iが誰かの 始点=1 終点=-1 なんでもいい=0 になっているか
vector<vector<int>>p(2*N,vector<int>(2*N));//A,Bを ペアにしていい={1,0} ダメ=-1
vector<int>xs,ps;
for(int i=0;i<N;i++){
int a,b;
cin>>a>>b;
if(a!=-1){
a--;
if(type[a]!=0){cout<<"No"<<endl;return 0;}
type[a]=1;
xs.push_back(a);
}
if(b!=-1){
b--;
if(type[b]!=0){cout<<"No"<<endl;return 0;}
type[b]=-1;
xs.push_back(b);
}
if(a!=-1&&b!=-1){p[a][b]=1;ps.push_back(a);ps.push_back(b);}
}
for(int a:xs){//xs:-1ではない物なのでそれ同士は(元からペアになっているものを除いて)ペアにならない。
for(int b:xs){
if(p[a][b]!=1){p[a][b]=-1;}
}
}
for(int a:ps){//ps:元からペアになっているものの片方。元からペアのものがある場合は、その相手以外はペアにできないようにする。
for(int i=0;i<2*N;i++){
if(!p[a][i]){p[a][i]=-1;}
if(!p[i][a]){p[i][a]=-1;}
}
}
vector<bool>dp(2*N+1,false);
dp[0]=true;
for(int i=0;i<2*N;i+=2){//区間の左側を0~2N-2まで試す。奇数だと以前の区間にペアにできないマスがあるので偶数。
if(!dp[i]){continue;}
for(int j=1;j<=N;j++){//ある区間の中の人数をN人まで試す。これで区間が定まる(2j人分の空きマスが必要なので)。
int id=i+j*2;//len:区間の終わりのid。
if(id>2*N){break;}
bool ok=true;
for(int l=i;l<i+j;l++){//l:区間の中のA(入ってくる方)のid(始点)。0インデックスなので<。
int r=l+j;//r:区間の中のB(出ていく方)のid(終点)
if(type[l]==-1){ok=false;}//始点を当てはめるとき終点がすでに書き込まれている場合は駄目
if(type[r]==1){ok=false;}//終点を当てはめるとき始点がすでに書き込まれている場合は駄目
if(p[l][r]==-1){ok=false;}//ペアにしてはいけない場合。
}
if(ok){dp[id]=true;}
}
}
if(dp[2*N]){cout<<"Yes"<<endl;}
else{cout<<"No"<<endl;}
return 0;
}//お試し |
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
#define rep(i,n) for (ll i = 0;i<(n);++i)
#define all(v) v.begin(),v.end()
template <typename T>bool chmax(T &a, const T& b) {if (a < b) {a = b;return true;}return false;}
template <typename T>bool chmin(T &a, const T& b) {if (a > b) {a = b;return true;}return false;}
vector<long long> divisor(long long n){vector<long long> res;long long i = 1;while (i*i<=n){if(n%i==0){res.push_back(i);}i++;}if(res.size()==0)return res;for(long long i = res.size()-1-(res.back()*res.back()==n);i>=0;--i){res.push_back(n/res[i]);}return res;}
long long safe_mod(long long x,long long m){x%=m;if(x<0){x+=m;}return x;}
long long modpow(long long x,long long n,long long mod){long long ans=1;while(n>0){if(n&1){ans*=x;ans%=mod;}n>>=1;x*=x;x%=mod;}return ans;}
long long intpow(long long x,long long n){long long ans=1;while(n>0){if(n&1){ans*=x;}n>>=1;x*=x;}return ans;}
vector<pair<long long,long long>> factor_lst(long long n){vector<pair<long long,long long>> factor_lst;long long d=2;while(d*d<=n){if(n%d==0){long long num=0;while(n%d==0){num+=1;n/=d;}factor_lst.push_back({d,num});}d+=1;}if(n!=1){factor_lst.push_back({n,1});}return factor_lst;}
int msb(int x){return x==0 ? -1:32-__builtin_clz(x);}//1-indexed
int lsb(int x){return x==0 ? 32:__builtin_ctz(x)+1;}//1-indexed
int popcnt(int x){return __builtin_popcount(x);}
const ll LINF=4*1e18;
const ll MINF=5*1e15;
const int INF=2*1e9;
void Main();
int main(){cout<<fixed<<setprecision(15);Main();}
void Main(){
int H,W,X,Y;
cin>>H>>W>>X>>Y;
X--;Y--;
vector<string> S(H);
rep(i,H)cin>>S[i];
int cnt=-3;
for(int i=X;i>=0;--i){
if(S[i][Y]=='#')break;
++cnt;
}
for(int i=X;i<H;++i){
if(S[i][Y]=='#')break;
++cnt;
}
for(int j=Y;j>=0;--j){
if(S[X][j]=='#')break;
++cnt;
}
for(int j=Y;j<W;++j){
if(S[X][j]=='#')break;
++cnt;
}
cout<<cnt<<endl;
}
| #include "bits/stdc++.h"
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second
#define cbr cerr<<"hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x,y) (lower_bound(all(x),y)-x.begin())
#define ubd(x,y) (upper_bound(all(x),y)-x.begin())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline long long rand(long long x, long long y) { return rng() % (y+1-x) + x; } //inclusive
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }
using ll=long long;
using ld=long double;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
using pi=pair<ll,ll>; using spi=pair<ll,pi>; using dpi=pair<pi,pi>;
long long LLINF = 1e18;
int INF = 1e9+1e6;
#define MAXN (200006)
int h, w;
string A[1002], B[1002];
int p[1002], sz[1002];
void init() {
FOR(i,0,1001) p[i]=i, sz[i]=1;
}
int find(int x) { return p[x] == x ? x : p[x] = find(p[x]); }
void merge(int a,int b) {
a = find(a), b = find(b);
if(a==b) return;
if(sz[a]>sz[b]) swap(a, b);
sz[b]+=sz[a], p[a]=b;
}
ll solve() {
init();
int ans = 0;
A[0][0] = A[0].back() = A[h-1][0] = A[h-1].back() = '#';
FOR(j,0,w-1) {
ll pre = -1;
FOR(i,0,h-1) {
if(A[i][j] != '#') continue;
if(~pre) merge(pre, i);
pre = i;
}
}
FOR(i,0,h-1) if(find(i) == i) ++ ans;
-- ans;
return ans;
}
void copy() {
FOR(i,0,h-1) A[i]=B[i];
}
int main() {
FAST
cin>>h>>w;
FOR(i,0,h-1) cin>>B[i];
copy();
ll ans = solve();
// invert
for(auto&i:A) i.clear();
FOR(i,0,w-1) A[i].resize(h);
FOR(i,0,h-1) FOR(j,0,w-1) A[j][i]=B[i][j];
swap(h, w);
ans = min(ans, solve());
cout<<ans<<'\n';
}
|
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
using ll = int64_t;
using db = double;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vpii = vector<pii>;
using vpll = vector<pll>;
constexpr char newl = '\n';
constexpr double eps = 1e-10;
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define show(x) cout << #x << " = " << (x) << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define sz(x) (int)(x).size()
#define YesNo {cout<<"Yes";}else{cout<<"No";}
#define YESNO {cout<<"YES";}else{cout<<"NO";}
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> bool lcmp(const pair<T, T>& l, const pair<T, T>& r) {
return l.first < r.first;
}
template<class T> istream& operator>>(istream& i, v(T)& v) {
F0R(j, sz(v)) i >> v[j];
return i;
}
template<class A, class B> istream& operator>>(istream& i, pair<A, B>& p) {
return i >> p.first >> p.second;
}
template<class A, class B, class C> istream& operator>>(istream& i, tuple<A, B, C>& t) {
return i >> get<0>(t) >> get<1>(t) >> get<2>(t);
}
template<class T> ostream& operator<<(ostream& o, const pair<T, T>& v) {
o << "(" << v.first << "," << v.second << ")";
return o;
}
template<class T> ostream& operator<<(ostream& o, const vector<T>& v) {
F0R(i, v.size()) {
o << v[i] << ' ';
}
o << newl;
return o;
}
template<class T> ostream& operator<<(ostream& o, const set<T>& v) {
for (auto e : v) {
o << e << ' ';
}
o << newl;
return o;
}
template<class T1, class T2> ostream& operator<<(ostream& o, const map<T1, T2>& m) {
for (auto& p : m) {
o << p.first << ": " << p.second << newl;
}
o << newl;
return o;
}
#if 1
int red = 1, gre = 2, blu = 4, all = 7;
// INSERT ABOVE HERE
signed main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
int N, M; cin >> N >> M;
vvi es(N);
F0R(i, M) {
int a, b; cin >> a >> b;
a--; b--;
es[a].push_back(b);
es[b].push_back(a);
}
ll re = 1;
v(bool) vs(N);
F0R(i, N) {
if (vs[i]) continue;
vi as; // 連結になっている頂点リスト
auto arrange = [&](auto arrange, int v)->void {
vs[v] = true;
as.push_back(v);
for (auto to : es[v]) {
if (!vs[to]) {
arrange(arrange, to);
}
}
};
arrange(arrange, i);
vi cs(N, 0);
auto calc = [&](auto calc, int ai)->ll {
if (ai == sz(as)) return 1;
int v = as[ai], a = 0;
for (auto to : es[v]) {
a |= cs[to];
}
ll re = 0;
F0R(c, 3) {
if ((a >> c) & 1) continue;
cs[v] = 1 << c;
re += calc(calc, ai+1);
}
cs[v] = 0;
return re;
};
re *= calc(calc, 0);
}
cout << re << newl;
}
#endif
| #include<bits/stdc++.h>
using namespace std ;
const int N = 2e3+5 ;
int n ,m ,u ,v ;
char ch ;
vector<int> adj[128][N] ;
bool edge[N][N] ;
long long dis[N][N] ;
long long bfs(){
long long ret = 1e18 ;
memset(dis,'?',sizeof dis);
queue<pair<int,int>> q ;
q.push({1,n});
dis[1][n] = 0 ;
while(q.size()){
int a = q.front().first ;
int b = q.front().second ;
q.pop() ;
if(a==b){
ret = min(ret ,dis[a][b]*2);
continue ;
}
if(edge[a][b]){
ret = min(ret ,dis[a][b]*2+1);
continue ;
}
for(int ch='a';ch<='z';++ch){
if(!adj[ch][a].size() || !adj[ch][b].size()) continue ;
for(int i:adj[ch][a]) for(int j:adj[ch][b]){
long long to = dis[a][b]+1 ;
if(dis[i][j]<=to) continue ;
dis[i][j] = to ;
if(i==j){
ret = min(ret,to*2) ;
continue ;
}
if(edge[i][j]){
ret = min(ret,to*2+1) ;
continue ;
}
q.push({i,j});
}
}
}
if(ret>1e9) ret = -1 ;
return ret ;
}
int main(){
scanf("%d%d",&n,&m);
while(m--){
scanf("%d%d %c",&u,&v,&ch);
edge[u][v] = edge[v][u] = 1 ;
adj[ch][u].push_back(v);
adj[ch][v].push_back(u);
}
printf("%lld",bfs());
return 0;
}
|
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
using std::cout;
using std::cin;
using std::endl;
using ll=long long;
using ld=long double;
ll I=1167167167167167167;
ll Q=1e9+7;
#define rep(i,a) for (ll i=0;i<a;i++)
template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>;
template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}else return 0;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}else return 0;}
template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());}
template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});}
template<class T> void print_tate(vector<T> &v) {rep(i,v.size()) cout<<v[i]<<"\n";}
void yneos(bool a){if(a) cout<<"Yes"<<"\n"; else cout<<"No"<<"\n";}
ll Range=2000000;
vector<ll> Kai(Range+1,1);
vector<ll> Kai_re(Range+1,1);
vector<ll> Kai_g(Range+1,1);
void Re(int potato){//Re(0)で初期化
for(int i=1;i<=Range;i++){
if(i!=1){
Kai_g[i]=((Q-Q/i)*Kai_g[Q%i])%Q;
}
Kai_re[i]=(Kai_g[i]*Kai_re[i-1])%Q;
}
for(int i=1;i<=Range;i++){
Kai[i]=(i*Kai[i-1])%Q;
}
}
ll si(ll x,ll y){
if(y<0) return 0;
ll C;
C=(Kai_re[y]*Kai_re[x-y])%Q;
C=(C*Kai[x])%Q;
return C;
}
//おちこんだりもしたけれど、私はげんきです。
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll N,M,K;
cin>>N>>M>>K;
Re(0);
if(N>M+K) cout<<"0"<<endl;
else cout<<(Q+si(N+M,N)-si(N+M,N-K-1))%Q<<endl;
}
| #include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_set>
#include <cstdlib>
#include <cfloat>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#define ll long long
#define lp pair<ll, ll>
#define max(a,b)((a)>(b)?(a):(b))
#define min(a,b)((a)<(b)?(a):(b))
#define ALL(obj) (obj).begin(), (obj).end()
using namespace std;
#define DIV 1000000007
//#define LLONG_MAX 9223372036854775807
//#define LLONG_MIN -9223372036854775808
int main(){
ll i,j,n,a,b,c;
cin >> a >> b >> c;
if ((-1*a == b && c%2==0) || a == b) {
cout << "=" << endl;//
} else if (a == 0) {
if (b < 0 && c%2 == 1) {
cout << ">" << endl;
} else {
cout << "<" << endl;
}//
} else if(b==0) {
if (a < 0 && c%2 == 1) {
cout << "<" << endl;
} else {
cout << ">" << endl;
}//
} else if (a > 0 && b > 0) {
if (a>b) {
cout << ">" << endl;
} else {
cout << "<" << endl;
}
} else if (a > 0 && b < 0) {
if (c%2 == 1) {
cout << ">" << endl;
} else {
if (a > -1*b) {
cout << ">" << endl;
} else {
cout << "<" << endl;
}
}//
} else if (a < 0 && b > 0) {
if (c%2 == 1) {
cout << "<" << endl;
} else {
if (-1*a > b) {
cout << ">" << endl;
} else {
cout << "<" << endl;
}
}//
} else {//a<0 && b<0
if (c%2==1) {
if (-1*a > -1*b) {
cout << "<" << endl;
}else {
cout << ">" << endl;
}//
} else {
if (-1*a > -1*b) {
cout << ">" << endl;
}else {
cout << "<" << endl;
}
}
}
return 0;
} |
//#undef DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll llinf = (1ll<<61)-1;
#define sz(a) int(a.size())
#define all(x) begin(x), end(x)
#ifdef DEBUG
const int DEBUG_END = 26;
#define DOS cout
#include <debug.h>
#else
#define bug(args...) void()
#define cbug(a, args...)
#endif
#define ASSERT(a, o, b, args...) if (!((a)o(b))) bug(a, b, ##args), assert((a)o(b));
#define fi first
#define se second
int TC = 1, CN;
const int inf = 1000000007;
const int H = 1005;
int h, w, d[2];
string grid[H];
bitset<H> vstd[H], visd[2];
vector<pair<int, int>> g[2][H];
void dfs(pair<int, int> u) {
auto [r, c] = u;
int p[2] = {r, c};
for (int i = 0; i < 2; i++) {
if (visd[i][p[i]]) continue;
visd[i][p[i]] = 1;
for (auto &j : g[i][p[i]]) {
if (!vstd[j.fi][j.se]) vstd[j.fi][j.se] = 1, dfs(j);
}
}
}
signed main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); cout.precision(11), cout.setf(ios::fixed);
//cin >> TC;// inputAll + resetAll -> solution
auto kase = [&]()->void {
cin >> h >> w;
d[0] = h, d[1] = w;
for (int i = 0; i < h; i++) {
cin >> grid[i];
for (int j = 0; j < w; j++) {
if (grid[i][j] == '#') g[0][i].push_back({i, j}), g[1][j].push_back({i, j});
}
}
queue<pair<int, int> > q;
for (int i = 0; i < 2; i++) {
for (auto &j : g[i][0]) {
if (!vstd[j.fi][j.se]) vstd[j.fi][j.se] = 1, dfs(j);
}
for (auto &j : g[i][d[i]-1]) {
if (!vstd[j.fi][j.se]) vstd[j.fi][j.se] = 1, dfs(j);
}
}
int cnt = 0, cntr = h-2, cntc = w-2;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
if (!vstd[i][j] and grid[i][j] == '#') ++cnt, dfs({i, j});
}
}
for (int i = 1; i < h-1; i++) {
bool ok = 0;
for (int j = 0; j < w; j++) {
ok |= vstd[i][j];
}
cntr -= ok;
}
for (int i = 1; i < w-1; i++) {
bool ok = 0;
for (int j = 0; j < h; j++) {
ok |= vstd[j][i];
}
cntc -= ok;
}
cout << cnt+min(cntr, cntc) << '\n';
};
while (CN++!=TC) kase();
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template<class T> bool chmin(T& a,T b){if(a>b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b){if(a<b) {a = b; return true;} return false;}
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << " = " << (x) << endl;
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int N,L;
cin >> N >> L;
vec<int> A(N+2),B(N+2);
for(int i=1;i<=N;i++) cin >> A[i];
for(int i=1;i<=N;i++) cin >> B[i];
A[N+1] = B[N+1] = L+1;
vec<int> C(N+1),D(N+1);
for(int i=0;i<=N;i++){
C[i] = A[i+1]-A[i]-1;
D[i] = B[i+1]-B[i]-1;
}
ll ans = 0;
int sum = 0,r = 0;
// for(int i=0;i<=N;i++) cerr << C[i] << " " << D[i] << "\n";
for(int i=0;i<=N;i++) if(D[i]){
while(C[r]==0) r++;
int l = r;
while(r<=N && sum+C[r]<=D[i]){
sum += C[r++];
if(sum==D[i]) break;
}
if(sum!=D[i]){
cout << "-1\n";
return 0;
}
// cerr << l << " " << r << "\n";
if(r<=i) ans += i-l;
else if(i<=l) ans += r-i-1;
else ans += r-l-1;
sum = 0;
}
cout << ans << "\n";
} |
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = vector<T>;
using vvi = vector<vt<int>>;
int main(){
int n, num = 0, t_n;
cin >> n;
num = pow(2,n);
t_n = num;
vt<int> a(num);
vt<int> tp(num);
rep(i,num){
cin >> a[i];
tp[i] = a[i];
}
while(num != 2) {
rep(i,num){
if (a[i] > a[i+1]) {
a.erase(a.begin() + i+1);
} else {
a.erase(a.begin() + i);
}
num--;
}
}
int p = a[0] > a[1] ? a[1] : a[0];
rep(i,t_n){
if(p == tp[i]){
cout << i+1 << endl;
break;
}
}
return 0;
}
| #include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <vector>
#include <algorithm>
#include <iostream>
#include <map>
using namespace std;
int main(){
int n;
scanf("%d", &n);
long nNum = 1;
for(int i = 0; i < n; i++){
nNum *= 2;
}
vector<int> viNum(nNum);
for(int i = 0; i < nNum; i++){
scanf("%d", &viNum[i]);
}
vector<int> viNumTmp = viNum;
long nNumTmp = nNum;
while(nNumTmp > 2){
nNumTmp /= 2;
for(int i = 0; i < nNum; i++){
viNumTmp[i] = max(viNumTmp[2*i], viNumTmp[2*i+1]);
}
}
int nAns = min(viNumTmp[0], viNumTmp[1]);
for(int i = 0; i < nNum; i++){
if(viNum[i] == nAns){
printf("%d", i+1);
}
}
return 0;
}
|
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <set>
#include <map>
#include <list>
#include <cstdlib>
#include <queue>
#include <stack>
#include <bitset>
using namespace std;
#define MOD 998244353
#define PI 3.1415926535897932
#define INF 1e9
#define rep(i, n) for (int i = 0; i < n; i++)
#define repe(i, j, n) for (int i = j; i < n; i++)
#define repi(i, n) for (int i = 0; i <= n; i++)
#define repie(i, j, n) for (int i = j; i <= n; i++)
#define all(x) x.begin(), x.end()
#define println() cout << endl
#define P pair<int, int>
#define fi first
#define se second
typedef long long ll;
using Graph = vector<vector<ll>>;
void solve1() {
ll a, b; cin >> a >> b;
ll sum = 0;
if(a == b) {
rep(i, a) {
cout << i + 1 << " ";
}
rep(i, b) {
if(i == b-1) {
cout << -b << endl;
break;
}
cout << -(i+1) << " ";
}
} else if(a > b) {
for(ll i = 1; i <= a; i++) {
sum += i;
cout << i << " ";
}
sum *= -1;
ll sumb = 0;
for(ll i = 1; i <= b; i++) {
if(i == b) {
cout << sum - sumb << endl;
break;
}
sumb -= i;
cout << -i << " ";
}
} else if(b > a) {
for(ll i = 1; i <= b; i++) {
sum += i;
cout << -i << " ";
}
ll sumb = 0;
for(ll i = 1; i <= a; i++) {
if(i == a) {
cout << sum - sumb << endl;
break;
}
sumb += i;
cout << i << " ";
}
}
}
int main()
{
solve1();
}
| #include <bits/stdc++.h>
#define fo(i, k, n) for (ll i = k; i < n; i++)
#define ll long long
#define ld long double
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
int a, b;
cin >> a >> b;
vector<int> pos(a);
vector<int> neg(b);
if (a > b)
{
fo(i, 0, a)
pos[i] = i + 1;
int sum = 0;
if (b == 1)
{
fo(i, 0, a)
sum = sum + pos[i];
neg[0] = -(sum);
}
else
{
fo(i, 0, b - 1)
neg[i] = -(i + 1);
fo(i, b - 1, a)
sum = sum + pos[i];
neg[b - 1] = -(sum);
}
}
else
{
fo(i, 0, b)
neg[i] = -(i + 1);
int sum = 0;
if (a == 1)
{
fo(i, 0, b)
sum = sum + neg[i];
pos[0] = -(sum);
}
else
{
fo(i, 0, a - 1)
pos[i] = (i + 1);
fo(i, a - 1, b)
sum = sum + neg[i];
pos[a - 1] = -(sum);
}
}
fo(i, 0, a)
cout
<< pos[i] << " ";
fo(i, 0, b)
cout
<< neg[i] << " ";
cout << 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 ccont(c, i) ((c).find(i) != (c).end())
#define lcont(c, i) (find(all(c), i) != (c).end())
#define trav(x, c) for(auto& x : c)
#define readv(c) for(auto& x : c) read(x)
#define rep(i, n) for(int i = 0; i < n; i++)
#define repa(i, b, e) for(int i = b; i < e; i++)
#define repd(i, b, e) for(int i = b-1; i >= e; i--)
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 << (sizeof...(args) > 0 ? " " : ""); 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);
string s; read(s);
if(s[0] != s[n-1]) {
println(1);
return;
}
repa(i, 1, n-2) {
if(s[0] != s[i] && s[i+1] != s[n-1]) {
println(2);
return;
}
}
println(-1);
}
//=========================
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 <bits/stdc++.h>
using namespace std;
#define int long long
#define forn(i,a,n) for (int i=a; i<n; i++)
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
string s;
cin>>s;
if (s[0]==s[1] && s[1]==s[2])
cout<<"Won"<<endl;
else cout<<"Lost"<<endl;
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define pll pair<ll,ll>
#define rep(i,n) for(ll i=0;i<n;i++)
#define mod 1000000007
#define INF 10000000000000000
#define F first
#define S second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pie 3.141592653589793238462643383279
#define PYES cout<<"YES"<<endl
#define PNO cout<<"NO"<<endl
#define SB(a) sort(a.begin(),a.end(),greater<ll>());
#define SS(a) sort(a.begin(),a.end());
#define vll vector<ll>
#define vpll vector<pll>
vector<bool> prime;
vector<ll> fact,inv,primes,factors;
void fast()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
void factorize(ll a)
{
factors.clear();
for(ll i=1;i*i<=a;i++)
{
if (i*i==a) factors.pb(i);
else if (a%i==0)
{
factors.pb(i);
factors.pb(a/i);
}
}
sort(factors.begin(),factors.end());
}
ll power(ll a,ll b)
{
if(a==1||b==0) return 1;
ll c=power(a,b/2);
ll res=1;
res=c*c;
if(res>=mod) res%=mod;
if(b%2) res*=a;
if(res>=mod) res%=mod;
return res;
}
ll modInv(int a)
{
return power(a,mod-2);
}
void factorial(ll n)
{
fact.resize(n+1);
fact[0]=1;
for(ll i=1;i<=n;i++)
{
fact[i]=fact[i-1]*i;
if(fact[i]>=mod) fact[i]%=mod;
}
}
void InvFactorial(ll n)
{
inv.resize(n+1);
inv[0]=1;
for(ll i=1;i<=n;i++) inv[i]=modInv(fact[i]);
}
ll ncr(ll n,ll r)
{
if(n<r||n<0||r<0) return 0;
ll b=inv[n-r];
ll c=inv[r];
ll a=fact[n]*b;
if(a>=mod) a%=mod;
a*=c;
if(a>=mod) a%=mod;
return a;
}
void remove_duplicates(vector<pair<ll,ll> > &v)
{
sort(v.begin(),v.end());
ll _size=unique(v.begin(),v.end())-v.begin();
v.resize(_size);
}
unsigned ll gcd(unsigned ll u, unsigned ll v)
{
if(u==0||v==0) return max(u,v);
unsigned ll shift=__builtin_ctz(u|v);
u>>=__builtin_ctz(u);
do{
v>>=__builtin_ctz(v);
if(u>v) swap(u,v);
v-=u;
}while(v!=0);
return u<<shift;
}
void sieve(int n)
{
prime.assign(n+1,1);
prime[1]=false;
for(ll p=2;p*p<=n;p++) if(prime[p]) for(ll i=p*p;i<=n;i+=p) prime[i]=false;
for(ll i=2;i<n+1;i++) if(prime[i]) primes.push_back(i);
}
ll size(ll l)
{
ll p=l;
ll count=0;
while(p) p/=10,count++;
return count;
}
//--------------------------------------------------------------------------------------------------------------------------------------------------
// Always remember: if (condition) if (condition) statement; This doesn't work !!
// Always increase boundaries for global or frequency questions
// pow((int)10,i) doesn't work sometimes. It is better to use multiple of 10 in arrays. Always remember this.
// delete values when defining global if there are multiple testcases
// don't try to be smart and make stupid mistakes
ll n,m;
vector<string> a(2005);
vector<vll> dp(2005,vll(2005,-INF));
ll cont(ll i,ll j)
{
if (a[i][j]=='+') return 1;
else return -1;
}
ll func(ll i,ll j)
{
if (i==n-1 && j==m-1) return 0;
ll &ans=dp[i][j];
if (ans>-INF) return ans;
if ((i-j)%2==0)
{
ll t=-INF;
if (i<n-1) t=max(t,func(i+1,j)+cont(i+1,j));
if (j<m-1) t=max(t,func(i,j+1)+cont(i,j+1));
ans=t;
}
else
{
ll t=INF;
if (i<n-1) t=min(t,func(i+1,j)-cont(i+1,j));
if (j<m-1) t=min(t,func(i,j+1)-cont(i,j+1));
ans=t;
}
return ans;
}
void solve()
{
cin>>n>>m;
rep(i,n) cin>>a[i];
ll ans=func(0,0);
if (ans>0) cout<<"Takahashi";
else if (ans<0) cout<<"Aoki";
else cout<<"Draw";
}
signed main()
{
fast();
ll T=1;
//cin>>T;
for(ll i=1;i<=T;i++) solve();
}
| // Always remember that you are absolutely unique, just like everyone else!
#include <iostream>
#include <vector>
using namespace std;
// DEBUGGING SECTION
void __print(int x) {cerr << x;}
void __print(long long 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 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...);}
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#define MOD 1000000007
#define INF 3e18
#define pb push_back
#define endl '\n' // Remove if interactive
#define ff first
#define ss second
#define FOR(i, a, b) for(int i = a; i < b; i++)
//#include <algorithm>
//#include <cstring>
//#include <map>
//#include <set>
//#include <queue>
//#include <stack>
//#include <math.h>
//#include <bits/stdc++.h>
#define int long long
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi>
#define vpii vector<pii>
#define all(x) x.begin(), x.end()
int power(int x, int y) {
int ans = 1; x %= MOD;
while (y) {
if (y & 1)
ans = (x * ans) % MOD;
x = (x * x) % MOD;
y >>= 1;
}
return ans;
}
// comparator(A, B) -> should return true if A needs to come before B!
// ALWAYS RETURN FALSE IF A == B
// USE INTEGERS TO REDUCE RUNTIME!
const int maxn = 2010;
int n, m;
vvi arr(maxn, vi(maxn));
vector<vpii> dp(maxn, vpii(maxn, { -1, -1}));
pii helper(int x, int y) {
if (dp[x][y].ff != -1)
return dp[x][y];
if (x == n && y == m)
return {0, 0};
pii curr = { -INF, INF};
if (x + 1 <= n) {
pii a = helper(x + 1, y);
if (a.ss + arr[x + 1][y] - a.ff > curr.ff - curr.ss) {
curr = {a.ss + arr[x + 1][y], a.ff};
}
}
if (y + 1 <= m) {
pii a = helper(x, y + 1);
if (a.ss + arr[x][y + 1] - a.ff > curr.ff - curr.ss) {
curr = {a.ss + arr[x][y + 1], a.ff};
}
}
dp[x][y] = curr;
return curr;
}
void solve() {
cin >> n >> m;
FOR(i, 1, n + 1) {
FOR(j, 1, m + 1) {
char c;
cin >> c;
arr[i][j] = (c == '+') ? 1 : -1;
}
}
pii ans = helper(1, 1);
debug(ans);
if (ans.ff == ans.ss) {
cout << "Draw\n";
} else if (ans.ff > ans.ss) {
cout << "Takahashi\n";
} else {
cout << "Aoki\n";
}
}
int32_t main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
// freopen("error.txt", "w", stderr);
freopen("output.txt", "w", stdout);
#endif
fastio;
int t = 1;
// cin >> t;
while (t--) {
solve();
}
}
|
#include<bits/stdc++.h>
using namespace std;
int a[102],b[102];
int c[20],d[20];
int ans = 0;
void solve(int n,int m,bool flag[],int k,int l){
if(l>=k){
int cnt = 0;
for(int i=0;i<m;i++)
{
if(flag[a[i]] == true && flag[b[i]] == true)
cnt++;
}
ans = max(ans,cnt);
return ;
}
bool temp =flag[c[l]];
flag[c[l]] = true;
solve(n,m,flag,k,l+1);
flag[c[l]] = temp;
temp = flag[d[l]];
flag[d[l]] = true;
solve(n,m,flag,k,l+1);
flag[d[l]] = temp;
}
int main(){
int n,m;
cin >> n >> m;
for(int i=0;i<m;i++)
cin >> a[i] >> b[i];
int k;
cin >> k;
for(int i=0;i<k;i++)
{
cin >> c[i] >> d[i];
}
bool flag[105] = {false,};
solve(n,m,flag,k,0);
cout<<ans<<endl;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repp(i, st, en) for (ll i = (ll)st; i < (ll)(en); i++)
#define repm(i, st, en) for (ll i = (ll)st; i >= (ll)(en); i--)
#define all(v) v.begin(), v.end()
void chmax(ll &x, ll y) {x = max(x,y);}
void chmin(ll &x, ll y) {x = min(x,y);}
int main() {
ll N, M; cin >> N >> M;
vector<pair<ll,ll>> m(M);
rep(i,M) {
ll a, b; cin >> a >> b;
a--; b--;
m[i] = {a,b};
}
ll K; cin >> K;
vector<pair<ll,ll>> k(K);
rep(i,K) {
ll c, d; cin >> c >> d;
c--; d--;
k[i] = {c,d};
}
ll ans = 0;
rep(bit,1<<K) {
vector<ll> vec(N);
rep(i,K) {
ll x = k[i].first, y = k[i].second;
if ((bit>>i)&1) vec[x]++;
else vec[y]++;
}
ll cnt = 0;
rep(i,M) {
ll x = m[i].first, y = m[i].second;
if (vec[x]>=1 && vec[y]>=1) cnt++;
}
ans = max(ans,cnt);
}
cout << ans << endl;
} |
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MAXN = 4e5 + 100;
int A[MAXN];
char res[MAXN];
int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int N;
cin >> N;
vector<pair<int,int>> vect;
for(int i = 1 ; i <= 2*N ; i++)
{
int n;
cin >> n;
vect.push_back({n,i});
}
sort(vect.begin(), vect.end());
for(int i = 1 ; i <= N ; i++)
{
A[vect[i-1].second] = 1;
}
vector<int> vvv;
bool flag = false;
for(int i = 1 ; i <= 2*N ; i++)
{
if(flag == false)
{
if(A[i])
{
vvv.push_back(i);
}
else
{
if(vvv.size())
{
res[vvv.back()] = '(';
res[i] = ')';
vvv.pop_back();
}
else
{
flag = true;
vvv.push_back(i);
}
}
}
else
{
if(!A[i])
{
vvv.push_back(i);
}
else
{
if(vvv.size())
{
res[vvv.back()] = '(';
res[i] = ')';
vvv.pop_back();
}
else
{
flag = false;
vvv.push_back(i);
}
}
}
}
for(int i = 1 ; i <= 2*N ; i++)
{
cout << res[i];
}
cout << '\n';
return 0;
} | #include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define pre(i,a,b) for(int i=a;i>=b;i--)
#define N 400005
using namespace std;
int n,a[N],c[N],ans[N],sta[N],top;pair<int,int>u[N];
int main(){
scanf("%d",&n);n<<=1;
rep(i,1,n)scanf("%d",&a[i]),u[i]=make_pair(a[i],i);
sort(u+1,u+n+1);
rep(i,1,n/2)c[u[i].second]=1;
rep(i,1,n){
if(!top||c[sta[top]]==c[i])sta[++top]=i;
else{
ans[sta[top--]]=0;ans[i]=1;
}
}
rep(i,1,n)if(ans[i])putchar(')');else putchar('(');
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef pair<int,int> Pair;
typedef tuple<int,int,int> tpl;
#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)
#define en "\n"
constexpr double EPS = 1e-9;
constexpr double PI = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;
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;}
int N,M;
VL dp(8,-1);
ll L[8][8];
ll rec(int v){
if(dp[v] != -1) return dp[v];
ll ret = 0;
FOR(to,v+1,N){
chmax(ret, rec(to) + L[v][to]);
}
return dp[v] = ret;
}
void Main(){
cin >> N >> M;
ll MINV = LINF, MAXW = 0;
VL w(N); REP(i,N) cin >> w[i], chmax(MAXW,w[i]);
VL l(M),v(M); REP(i,M) cin >> l[i] >> v[i], chmin(MINV, v[i]);
if(MINV<MAXW){
cout << -1 << en;
return;
}
VI p(M); REP(i,M) p[i] = i;
auto cmp = [&](int i, int j){return v[i]<v[j];}; sort(ALL(p), cmp);
VL mx(M+1,0); REP(i,M) chmax(mx[i+1], max(mx[i],l[p[i]]));
ll ans = LINF;
VI q(N); REP(i,N) q[i] = i;
do{
VL ww(N); REP(i,N) ww[i] = w[q[i]];
VL sum(N+1,0); REP(i,N) sum[i+1] = sum[i] + ww[i];
REP(i,N-1)FOR(j,i+1,N){
ll s = sum[j+1] - sum[i];
int l = -1, r = M;
while(r-l>1){
int x = (l+r)/2;
if(v[p[x]]<s) l = x;
else r = x;
}
L[i][j] = mx[r];
}
REP(i,N) dp[i] = -1;
chmin(ans, rec(0));
}while(next_permutation(ALL(q)));
cout << ans << en;
return;
}
int main(void){
cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
int t=1; //cin>>t;
REP(_,t) Main();
return 0;
} | #include<cstdio>
#include<vector>
int w[15];
struct Element{
int l,v;
};
struct Edge{
int v,w;
Edge(int v,int w):v(v),w(w){}
};
std::vector<Edge>g[15];
int f[15];
Element e[100005];
int seq[15];
int vis[15];
int pos[15];
int ans = -1;
int dis[1<<10];
void dfs(int p,int n,int m){
if(p==n+1){
for(int i = 1; i <= n; i++){
g[i].clear(), f[i] = 0;
pos[seq[i]] = i;
}
for(int i = 0; i < (1<<n); i++){
int l = n+1, r = -1;
int mask = i;
for(int j = 1; j <= n; j++){
if(mask%2){
int p = pos[j];
if(l>p) l = p;
if(r<p) r = p;
}
mask /= 2;
}
if(l<=n && r>=1 && l<r) g[l].push_back(Edge(r,dis[i]));
}
for(int i = 1; i <= n; i++){
if(f[i]<f[i-1]) f[i] = f[i-1];
for(Edge e: g[i]){
int j = e.v, w = e.w;
if(f[j]<f[i]+w) f[j] = f[i]+w;
}
}
if(ans==-1 || ans>f[n]) ans = f[n];
}
else{
for(int i = 1; i <= n; i++){
if(vis[i]==0){
seq[p] = i;
vis[i] = 1;
dfs(p+1,n,m);
vis[i] = 0;
}
}
}
}
int main(){
int n,m;
scanf("%d%d",&n,&m);
int maxn = -1;
for(int i = 1; i <= n; i++){
scanf("%d",&w[i]);
if(maxn<w[i]) maxn = w[i];
}
int ok = 1;
for(int i = 1; i <= m; i++){
scanf("%d%d",&e[i].l,&e[i].v);
if(e[i].v<maxn) ok = 0;
}
if(!ok){
printf("-1\n");
return 0;
}
for(int i = 0; i < (1<<n); i++){
int sum = 0, mask = i;
for(int j = 1; j <= n; j++){
if(mask%2) sum += w[j];
mask /= 2;
}
dis[i] = 0;
for(int j = 1; j <= m; j++){
if(e[j].v<sum && dis[i]<e[j].l) dis[i] = e[j].l;
}
}
dfs(1,n,m);
printf("%d\n",ans);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<pair<int, int>> pos(n);
for (auto &&[x, y] : pos) {
cin >> x >> y;
}
auto judge = [&](double r) -> bool {
queue<int> q;
for (auto i = 0; i != n; ++i) {
if (100 - r < pos[i].second + r) {
q.push(i);
}
}
vector<bool> used(n);
while (!q.empty()) {
auto id = q.front();
q.pop();
if (used[id]) continue;
used[id] = true;
for (auto i = 0; i != n; ++i) {
if (hypot(pos[i].first - pos[id].first,
pos[i].second - pos[id].second) < 2 * r) {
q.push(i);
}
}
}
for (auto i = 0; i != n; ++i) {
if (used[i]) {
if (r - 100 > pos[i].second - r) {
return false;
}
}
}
return true;
};
constexpr double eps = 1e-4;
double ok = 0, ng = 100;
while (ng - ok > eps) {
auto r = (ok + ng) / 2;
if (judge(r))
ok = r;
else
ng = r;
}
cout << ok << endl;
}
| #include <bits/stdc++.h>
#define ll long long int
#define w(t) int t; cin>>t; while(t--)
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define mii map<int,int>
#define sp(x,y) fixed<<setprecision(y)<<x
using namespace std;
// ll modular(ll base, unsigned long long int exp, unsigned int mod)
// {
// ll x = 1;
// ll power = base % mod;
// for (ll i = 0; i < sizeof(long long int) * 8; i++) {
// ll least_sig_bit = 0x00000001 & (exp >> i);
// if (least_sig_bit)
// x = (x * power) % mod;
// power = (power * power) % mod;
// }
// return x;
// }
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
// ll a,b,c;
// cin>>a>>b>>c;
// if(modular(a,c,1000000007)==modular(b,c,1000000007))cout<<"=";
// else if(modular(a,c,1000000007)<modular(b,c,1000000007))cout<<"<";
// else if(modular(a,c,1000000007)>modular(b,c,1000000007))cout<<">";
// return 0;
float a,b;
cin>>a>>b;
float ans=b/100;
ans*=a;
cout<<ans;
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef tree<long long, null_type, less<long long>, rb_tree_tag,
tree_order_statistics_node_update>
is;*/
#define fb find_by_order
#define ok order_of_key
#define mem(x,y) memset(x,y,sizeof x)
typedef long long ll;
typedef int ii;
typedef pair<ll,ll> pi;
typedef vector<pi> vii;
#define map unordered_map
#define INF 1000000000000007
#define pi 3.141592654
#define T while(t--)
#define for2(i,a,b) for(i=a;i>=b;i--)
#define for3(i,a,b) for(i=a;i<=b;i=i+2)
#define for1(i,a,b) for(i=a;i<=b;i=i+1)
#define for4(i,a,b) for(i=a;i>=b;i=i-2)
#define pb push_back
#define pf push_front
#define mp make_pair
#define ff first
#define ss second
#define si set<ll>
#define se multiset<ll>
typedef double ld;
typedef vector<ll> vi;
#define all(v) sort(v.begin(),v.end())
#define all1(v) sort(v.rbegin(),v.rend())
#define pff(uuv) printf("%lld\n",uuv)
#define pf1(uu) printf("%.20Lf\n",uu)
bool comp(pair<ll,char> aa, pair<ll,char> bb) {
if (aa.ff != bb.ff) return aa.ff > bb.ff;
return aa.ss < bb.ss;
}
bool comp1(pair<ll,char> aa, pair<ll,char> bb) {
if (aa.ff != bb.ff) return aa.ff < bb.ff;
return aa.ss > bb.ss;
}
bool comp2(pair<ll,ll> aa, pair<ll,ll> bb) {
if (aa.ff != bb.ff) return aa.ff > bb.ff;
return aa.ss < bb.ss;
}
bool comp3(pair<ll,ll> aa, pair<ll,ll> bb) {
if (aa.ff != bb.ff) return aa.ff < bb.ff;
return aa.ss > bb.ss;
}
ll rup(ll ik,ll ikk){
if(ik%ikk==0) return ik/ikk;
else return (ik/ikk)+1;
}
ll gcd(ll a,ll b){
if(b==0) return a;
return gcd(b,a%b);
}
ll lcm(ll a ,ll b){
return (a*b)/gcd(a,b);
}
ii main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll t=1;
//cin>>t;
while(t--){
ld n;
cin>>n;
n*=1.08;
n=ll(n);
if(n<206) cout<<"Yay!\n";
else if(n==206) cout<<"so-so\n";
else cout<<":(\n";
}
}
| #include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <array>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;
int main()
{
int N;
cin >> N;
int v = N * 1.08;
if (v == 206) {
puts("so-so");
} else if (v < 206) {
puts("Yay!");
} else {
puts(":(");
}
return 0;
}
|
#include<iostream>
#include<math.h>
#include<map>
#include<vector>
using namespace std;
int main()
{
long long int n;
cin>>n;
long long int ans= n*(n-1)/2;
map<long long int ,long long int > count;
long long int y;
for (long long int i = 0; i < n; i++)
{
cin>>y;
count[y]++;
}
for (auto it = count.begin();it != count.end(); ++it)
{
if(it->second>0)
ans= ans- ((it->second)*((it->second)-1))/2;
}
cout<<ans;
} | #include <vector>
#include <iostream>
#include <set>
#include <map>
#include <unordered_set>
#include <queue>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stack>
#include <valarray>
#include <typeinfo>
#include <array>
using namespace std;
using ll=long long;
using P = pair<ll,ll>;
#define rep(i,n) for (int i=0; i<(n);++i)
//ll mod=998244353,fac[1000001],finv[1000001],inv[1000001];
int MOD = 1e9+7,ans=0,n,m;
unordered_set<char> tops;
const double PI = acos(-1);
vector<vector<int>> dir = {{0,1},{1,0},{0,-1},{-1,0}};
const int MAX = 1e5+5;
vector<ll> fac,finv,inv;
int ser(int i,int j,int w,vector<vector<int>> &par){
if(par[i][j]==i*w+j) return par[i][j];
else return par[i][j]=par[par[i][j]/w][par[i][j]%w];
}
int main()
{
int n;
cin >> n;
vector<int> pw(n),sp(n),te(n),kn(n),id(n);
rep(i,n){
cin >> pw[i] >> sp[i] >> te[i] >> kn[i] >> id[i];
}
int l=0,r=1e9+1;
while(r-l>1){
int mid=(r+l)/2,out=1;
vector<int> cnt(32);
rep(i,n){
int p=0;
if(pw[i]>=mid) p+=1;
if(sp[i]>=mid) p+=2;
if(te[i]>=mid) p+=4;
if(kn[i]>=mid) p+=8;
if(id[i]>=mid) p+=16;
cnt[p]++;
}
//rep(i,32) cout << cnt[i] << ' ';
//cout << endl;
rep(i,32){
rep(j,32){
rep(k,32){
if(cnt[i]==0 || cnt[j]==0 || cnt[k]==0) continue;
rep(l,5){
if(!((i& (1<<l)) || (j& (1<<l)) || (k& (1<<l)))) break;
if(l==4) out=0;
}
}
}
}
if(out==0) l=mid;
else r=mid;
//cout << mid << endl;
}
cout << l << endl;
} |
Subsets and Splits