code_file1
stringlengths 87
4k
| code_file2
stringlengths 82
4k
|
---|---|
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ifs freopen("aa.in","r",stdin);
#define ofs freopen("aa.out","w",stdout);
#define iof ifs ofs
#define ll long long
#define ld long double
#define da(x,i) cout << #x << "[" << i << "]=" << x[i] << "\n";
#define da2(x,i,y,j) cout << #x << "[" << i << "]=" << x[i] << " ! " << #y << "[" << j << "]=" << y[j] << "\n";
#define d2a(x,i,j) cout << #x << "[" << i << "][" << j << "]=" << x[i][j] << "\n";
#define db(x) cout << #x << "=" << (x) << "\n";
#define db2(x,y) cout << #x << "=" << (x) << " ! " << #y << "=" << (y) << "\n";
#define db3(x,y,z) cout << #x << "=" << (x) << " ! " << #y << "=" << (y) << " ! " << #z << "=" << (z) << "\n";
#define db4(w,x,y,z) cout << #w << "=" << (w) << " ! " << #x << "=" << (x) << " ! " << #y << "=" << (y) << " ! " << #z << "=" << (z) << "\n";
#define inf LLONG_MAX
#define fr first
#define sc second
#define all(a) a.begin(),a.end()
const ll M=998244353,N=1e6+7;;
vector<ll> p(N,-1),g[N],f=p;
ll n,i,j,k,A,z;
void join(ll a,ll b)
{
if(a==b)
return;
ll sa,sb;
sa=(ll)g[a].size();
sb=(ll)g[b].size();
if(sa<sb)
swap(a,b);
for(ll i : g[b]){
p[i]=a;
g[a].push_back(i);
}
g[b]={};
}
ll bmod(ll n=j)
{
if(n==0)
return 1;
if(n==1)
return 2;
if(n%2)
return (2*bmod(n-1))%M;
ll R=bmod(n/2);
return (((R%M)*(R%M))%M+2*M)%M;
}
int main()
{
cin>>n;
for(i=1; i<=n; i++){
g[i]={i};
p[i]=i;
}
for(i=1,k=0; i<=n; i++){
cin>>j;
join(p[j],p[i]);
}
for(i=1,j=0; i<=n; i++){
z=(ll)g[i].size();
if(z)
j++;
}
A=bmod();
A=(A+3*M)%M;
cout<< A-1 <<"\n";
}
| #include<iostream>
#include<cstdio>
#include<ctime>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<string>
#include<vector>
#include<iomanip>
#include<fstream>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#include<sstream>
using namespace std;
#define sync std::ios::sync_with_stdio(false);std::cin.tie(0)
//string::npos
const double pi = 3.141592653589;
const int maxn = 200002;
const int maxm = 26;
const int mod = 998244353;
const int inf = 0x3f3f3f3f;
typedef long long ll;
ll ksm(int a, int k){
ll res = 1;
while(k){
if(k&1) res = (ll)res*a%mod;
a = (ll)a*a%mod;
k >>= 1;
}
return res;
}
int nxt[maxn];
int vis[maxn];
int ans, p, ring, n;
void solve(){
for(int i = 1; i <= n; ++i){
if(vis[i]) continue;
p = i;
++ring;
while(vis[p] == 0){
vis[p] = ring;
p = nxt[p];
if(vis[p] == ring) ++ans;
}
}
}
int main(){
sync;
cin >> n;
ring = 1;
for(int i = 1; i <= n; ++i){
cin >> nxt[i];
if(nxt[i] == i){
vis[i] = ring++;
ans++;
}
}
solve();
cout << ksm(2, ans)-1 << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define fast_io cin.tie(0);ios_base::sync_with_stdio(0);
string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
void debug_out() { cout << endl; }
void show() { cout << endl; }
void pret() { cout << endl; exit(0);}
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cout << " " << to_string(H); debug_out(T...);}
template <typename Head, typename... Tail> void show(Head H, Tail... T) {cout <<H<<" "; show(T...);}
template <typename Head, typename... Tail> void pret(Head H, Tail... T) {cout <<H<<" "; pret(T...);}
#define pr(...) cout << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
typedef long long ll;
#define int ll
typedef long double ld;
typedef vector<int> vi;
#define disp(x) cout<<x<<" ";
#define rep(i,a,b) for(int i=a;i<(int)b;i++)
#define fo(i,a,b) for(int i=a;i<=(int)b;i++)
#define rf(i,a,b) for(int i=a;i>=(int)b;i--)
#define mp make_pair
#define pb emplace_back
#define F first
#define S second
#define endl '\n'
//cout.setf(ios::fixed);cout.precision(18)
const int MOD = 1e9+7;
const int maxn = 300000+10;
int a[maxn], prefix[maxn];
int f(){
int n;
cin >> n;
fo(i, 1, n) cin >> a[i];
fo(i, 1, n) prefix[i] = a[i] + prefix[i - 1];
int ans = 0, curr = 0, val = -MOD;
fo(i, 1, n){
val = max(val, prefix[i]);
ans = max(ans, curr + val);
curr += prefix[i];
}
return ans;
}
int32_t main(){
fast_io;
int t = 1;
// cin>>t;
while(t--){
show(f());
// f();
// if(f()){
// cout<<"YES"<<endl;
// }
// else cout<<"NO"<<endl;
}
return 0;
} | #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;
int main(){
fast_io
ll n;
cin >> n;
vector<ll> A(n);
rep(i,n) cin >> A[i];
ll ans = 0;
ll s= 0, b = 0;
ll max_b = 0;
rep(i,n){
// フェーズごとの累積和
b += A[i];
// これまでの累積和の最大
max_b = max(max_b, b);
// 最終的な座標からそれまでの累積和の最大
ans = max(ans, s + max_b);
// 各フェーズの最終的な座標
s += b;
}
cout << ans << endl;
return 0;
}
|
// Problem: E - Akari
// Contest: AtCoder - AtCoder Beginner Contest 182
// URL: https://atcoder.jp/contests/abc182/tasks/abc182_e
// Memory Limit: 1024 MB
// Time Limit: 2500 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define forn(i,x,n) for(int i = x;i <= n;++i)
typedef pair<int,int> pii;
#define x first
#define y second
const int N = 1600;
pii blimit[N][N][4];
bool bubl[N][N],wall[N][N];
int main()
{
int h,w,n,m;scanf("%d%d%d%d",&h,&w,&n,&m);
forn(i,1,n)
{
int x,y;scanf("%d%d",&x,&y);
bubl[x][y] = 1;
}
forn(i,1,m)
{
int x,y;scanf("%d%d",&x,&y);
wall[x][y] = 1;
}
pii cur = {0,0};
//left -> right
forn(i,1,h)
{
cur = {0,0};
forn(j,1,w)
{
if(bubl[i][j]) cur.x = i,cur.y = j;
if(wall[i][j]) cur.x = 0,cur.y = 0;
blimit[i][j][0] = cur;
}
}
//right -> left
forn(i,1,h)
{
cur = {0,0};
for(int j = w;j >= 1;--j)
{
if(bubl[i][j]) cur.x = i,cur.y = j;
if(wall[i][j]) cur.x = 0,cur.y = 0;
blimit[i][j][1] = cur;
}
}
//up -> down
forn(j,1,w)
{
cur = {0,0};
forn(i,1,h)
{
if(bubl[i][j]) cur.x = i,cur.y = j;
if(wall[i][j]) cur.x = 0,cur.y = 0;
blimit[i][j][2] = cur;
}
}
// down -> up
forn(j,1,w)
{
cur = {0,0};
for(int i = h;i >= 1;--i)
{
if(bubl[i][j]) cur.x = i,cur.y = j;
if(wall[i][j]) cur.x = 0,cur.y = 0;
blimit[i][j][3] = cur;
}
}
// forn(i,1,h) forn(j,1,w)
// {
// printf("#%d %d\n",i,j);
// forn(k,0,3) printf("%d %d %d\n",k,blimit[i][j][k].x,blimit[i][j][k].y);
// }
int res = 0;
forn(i,1,h) forn(j,1,w)
{
int ok = 0;
forn(k,0,3) if(blimit[i][j][k].x) ok = 1;
// if(ok) cout << i << " " << j << endl;
res += ok;
}
printf("%d",res);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int h, w, n, m;
cin >> h >> w >> n >> m;
int map[h][w] = {};
int a, b, c, d, ans = 0;
for (int i = 0; i < n; i++) {
cin >> a >> b;
map[a - 1][b - 1] = -1;
ans++;
}
for (int i = 0; i < m; i++) {
cin >> c >> d;
map[c - 1][d - 1] = -2;
}
bool light;
int x, y;
queue<int> q;
for (int i = 0; i < h; i++) {
light = false;
q = queue<int>();
for (int j = 0; j < w; j++) {
if (map[i][j] == 0) {
if (light) {
map[i][j] = 1;
ans++;
} else {
q.push(i);
q.push(j);
}
} else if (map[i][j] == -1) {
while (!q.empty()) {
x = q.front();
q.pop();
y = q.front();
q.pop();
map[x][y] = 1;
ans++;
}
light = true;
} else if (map[i][j] == -2) {
light = false;
q = queue<int>();
}
}
}
for (int j = 0; j < w; j++) {
light = false;
q = queue<int>();
for (int i = 0; i < h; i++) {
if (map[i][j] == 0) {
if (light) {
map[i][j] = 1;
ans++;
} else {
q.push(i);
q.push(j);
}
} else if (map[i][j] == -1) {
while (!q.empty()) {
x = q.front();
q.pop();
y = q.front();
q.pop();
map[x][y] = 1;
ans++;
}
light = true;
} else if (map[i][j] == -2) {
light = false;
q = queue<int>();
}
}
}
cout << ans;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> x(n), y(n);
int ans = 0;
for (int i=0; i<n; i++) cin >> x[i] >> y[i];
for (int i=0; i<n; i++) {
for (int j=0; j<n; j++) {
if (i==j) continue;
int dx = x[i] - x[j];
int dy = y[i] - y[j];
if (-dx <= dy && dy <= dx) ans++;
}
}
cout << ans << endl;
} | #include <vector>
#include <iostream>
using namespace std;
int main(){
int N;
cin >> N;
int a=0;
vector<double> X(N,0);
vector<double> Y(N,0);
for (int i=0; i<N; i++){
cin >> X[i] >> Y[i];
}
for (int i=0; i<N; i++){
for (int j=i+1; j<N; j++){
for (int k=j+1; k<N; k++){
if (X[i]==X[j] && X[i]==X[k]){
a=1;
}
else {
double d1=(Y[j]-Y[i])/(X[j]-X[i]);
double d2=(Y[k]-Y[i])/(X[k]-X[i]);
if (d1==d2){
a=1;
break;
}
}
}
if (a==1){
break;
}
}
if (a==1){
break;
}
}
if (a==0){
cout << "No" <<endl;
}
else {
cout << "Yes" <<endl;
}
}
|
#include<bits/stdc++.h>
using namespace std;
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')';}
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) {os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#define int long long
template<typename T>
void dbg_a(T *a,int l,int r){cout<<" {";for(int i = l;i<r;i++) cout<<a[i]<<", ";cout<<a[r]<<"}"<<endl;}
typedef long long ll;
template<typename T = int>
inline T read(){
T f = 1,r = 0;
char c = getchar();
while(c<'0'||c>'9'){if(c == '-') f = -1; c = getchar();}
while(c>='0'&&c<='9'){ r = (r<<1) + (r<<3) + c - '0';c = getchar();}
return f*r;
}
typedef pair<int,int> PII;
#define fi first
#define se second
#define mst(a,b) memset(a,b,sizeof(a))
#define For(i,a,b) for(int i = a;i<=b;i++)
#define For_(i,a,b) for(int i = a;i>=b;i--)
#define _for(i,a) for(int i = 0;i<a;i++)
#define All(x) x.begin(),x.end()
// For(i,1,n) For(j,1,m) printf("f[%lld][%lld] = %lld\n",i,j,f[i][j]);
const int N = 2e5 + 10,M = 2*N + 10,INF = 0x3f3f3f3f;
const int mod = 998244353;
int h[N],ne[M],e[M],idx;
void add(int a,int b){
e[++idx] = b;ne[idx] = h[a];h[a] = idx;
}
int exgcd(int a,int b,int &x,int &y){
int d = a;
if(b){ d = exgcd(b, a%b, y, x);y -= (a/b)*x;}
else{x = 1;y = 0;}
return d;
}
int inv(int a,int mo){
int x,y;
int d = exgcd(a,mo,x,y);
return d == 1 ? (x + mo)%mo : -1;//-1表示不存在,并对逆元调整
}
int gcd(int a,int b){
return b?gcd(b,a%b):a;
}
bool merge(int a1,int m1,int a2,int m2,int &A,int &mo){
int c = (a2 - a1),d = gcd(m1,m2);
if(c % d) return 0;//gcd(m1,m2)|(a2 - a1)时才有解
c = (c%m2 + m2)%m2;//将c变为[0,m2)之间的数
c /= d;m1 /= d;m2 /= d;//两边除以d
c = c*inv(m1,m2) % m2;//将m1/d 移到右边
mo = m1*m2*d;// mo = m1 * m2 /d
A = (c*m1%mo*d%mo + a1)%mo;
return 1;
}
int EXCRT(int n,int a[],int mo[]){
int a1 = a[1],m1 = mo[1],A,Mo;
for(int i = 2;i<=n;i++){
if(!merge(a1,m1,a[i],mo[i],A,Mo)) return -1;//不合法
a1 = A;m1 = Mo;
}
return (a1 + m1)%m1;
}
int n;
void solve(){
int x,y,p,q;
cin>>x>>y>>p>>q;
int a[3] = {},mo[3] = {};
int ans = 3e18;
For(i,x,x+y-1){
For(j,p,p+q-1){
a[1] = i,mo[1] = 2*(x+y);
a[2] = j,mo[2] = p + q;
int res = EXCRT(2,a,mo);
if(res == -1) continue;
ans = min(res,ans);
}
}
if(ans == 3e18)cout<<"infinity"<<"\n";
else cout<<ans<<"\n";
}
signed main(){
int T = 1;
T = read();
while(T--) solve();
system("pause");
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define POPCOUNT(x) __builtin_popcount(x)
template <typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template <typename T> void chmax(T &a, const T &b) { a = max(a, b); }
const ll INF = 1LL << 60;
struct FastIO {
FastIO() {
cin.tie(0);
ios::sync_with_stdio(0);
}
} fastiofastio;
const ll MOD = 1e9 + 7;
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; }
// BEGIN CUT
ll modpow(ll x, ll y, ll m) {
ll a = 1, p = x;
while (y > 0) {
if (y % 2 == 0) {
p = (p * p) % m;
y /= 2;
} else {
a = (a * p) % m;
y--;
}
}
return a;
}
// END CUT
ll extgcd(ll a, ll b, ll &x, ll &y) {
ll d = a;
if (b != 0) {
d = extgcd(b, a % b, y, x);
y -= (a / b) * x;
} else {
x = 1;
y = 0;
}
return d;
}
int main() {
int T;
cin >> T;
while (T) {
T--;
ll X, Y, P, Q;
cin >> X >> Y >> P >> Q;
ll ans = INF;
for (ll k1 = X; k1 < X + Y; k1++) {
for (ll k2 = P; k2 < P + Q; k2++) {
ll x, y;
ll g = extgcd(2 * X + 2 * Y, P + Q, x, y);
if (abs(k2 - k1) % g != 0)
continue;
x *= (k2 - k1) / g;
ll b = (P + Q) / g;
if (x >= 0) {
x %= b;
} else {
ll k = (abs(x) + b - 1) / b;
x += k * b;
}
ans = min(ans, (2 * X + 2 * Y) * x + k1);
}
}
if (ans == INF)
cout << "infinity" << endl;
else
cout << ans << endl;
}
} |
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
int main() {
ll n, k, m;
cin >> n >> k >> m;
ll sum = 0;
rep(i, n-1) {
ll a;
cin >> a;
sum += a;
}
ll x = m*n - sum;
if(x > k) {
out(-1);
}
else {
out(max(0LL, x));
}
re0;
} | #include<stdio.h>
static inline int MPow(int a,int b,const int MOD){return b?1l*MPow(1l*a*a%MOD,b>>1,MOD)*(b&1?a:1)%MOD:1;}
int main(void){int A,B,C;if(!scanf("%d %d %d",&A,&B,&C)){return 1;}return !putchar(MPow(A,MPow(B,C,4)+4,10)+48);} |
// Problem: B - Alcoholic
// Contest: AtCoder - AtCoder Beginner Contest 189
// URL: https://atcoder.jp/contests/abc189/tasks/abc189_b
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define eb emplace_back
#define pb push_back
#define size(s) (int)s.size()
#define int long long
#define double long double
#define INF 1000000000000000000
#define vi vector<int>
#define vs vector<string>
#define vv vector<vector<int>>
#define pii pair<int,int>
#define m_p(x,y) make_pair(x,y)
#define vp vector<pair<int,int>>
#define setbits(x) __builtin_popcountll(x)
#define f first
#define se second
#define inc(v,n,x) v.assign(n,x)
#define incd(v,n) v.resize(n)
#define iniz(n) memset(n,0,sizeof(n))
#define inin(n) memset(n,-1,sizeof(n))
#define inimi(n) memset(n,0xc0,sizeof(n))
#define inima(n) memset(n,0x3f,sizeof(n))
#define all(v) (v).begin(),(v).end()
using namespace std;
template<typename T1,typename T2>istream &operator>>(istream &is, vector<pair<T1,T2>> &v) { for (pair<T1,T2> &t : v) is >> t.f>>t.se; return is; }
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }
double pi=acos(-1.0);
int md=1e9+7;
int dx1[]={0,0,-1,1};
int dy1[]={1,-1,0,0};
const int N=3e5+5;
template<class T>
T abst(T a)
{return a<0?-a:a;}
void solve()
{
int n;
int x;
cin>>n>>x;
vp v(n);cin>>v;
int y=0;
//double t=100.0;
for(int i=1;i<=n;i++)
{
y=y+v[i-1].f*v[i-1].se;
if(y/100.0>x)
{
cout<<i;
return;
}
}
cout<<-1;
//cout<<"\n"<<x<<"\n"<<y;
}
int32_t main(){
//ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int t=1;
//cin>>t;
for(int i=1;i<=t;i++)
{
solve();
}
return 0;
}
| #include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using ll = long long;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int a, b, c;
cin >> a >> b >> c;
cout << (a * a + b * b < c * c ? "Yes" : "No");
}
|
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <utility>
#include <unordered_set>
#include <map>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int main() {
int n;
ll cost;
cin >> n >> cost;
map<int, ll> delta;
for (int i = 0; i < n; i++) {
int a, b;
ll c;
cin >> a >> b >> c;
delta[a] += c;
delta[b+1] -= c;
}
ll ret = 0;
ll curr = 0;
int prev = 0;
for (auto [day, inc]: delta) {
ll actual = min(curr, cost);
ll val = actual * (day - prev);
ret += val;
prev = day;
curr += inc;
}
cout << ret << endl;
}
| #include "bits/stdc++.h"
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
ll x; // typedef long long ll;
mint(ll x = 0) :x((x%mod + mod) % mod) {}
mint operator-() const { return mint(-x); }
mint& operator+=(const mint a) {
if ((x += a.x) >= mod) x -= mod;
return *this;
}
mint& operator-=(const mint a) {
if ((x += mod - a.x) >= mod) x -= mod;
return *this;
}
mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
mint operator+(const mint a) const { return mint(*this) += a; }
mint operator-(const mint a) const { return mint(*this) -= a; }
mint operator*(const mint a) const { return mint(*this) *= a; }
mint pow(ll t) const {
if (!t) return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1) a *= *this;
return a;
}
// for prime mod
mint inv() const { return pow(mod - 2); }
mint& operator/=(const mint a) { return *this *= a.inv(); }
mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }
int main() {
int T;
cin >> T;
for (int i = 0; i < T; ++i) {
int N, A, B;
cin >> N >> A >> B;
//よんせっと
//まいなすよんせっと
if ((A + B) > N) {
cout << 0 << endl;
continue;
}
mint ans = 1;
ans *= (1 + N - B - A + 1);
ans *= (N - B - A + 1);
ans /= 2;
ans *= (N - A + 1);
ans *= (N - B + 1);
ans *= 4;
mint ans0 = 1;
ans0 *= (N - B - A + 1);
ans0 *= (N - B - A + 2);
ans0 /= 2;
ans0 *= ans0;
ans0 *= 4;
ans -= ans0;
cout << ans << endl;
}
return 0;
} |
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <string>
#include <ctime>
#include <cmath>
#include <vector>
#include <deque>
#include <queue>
#include <string>
#include <cctype>
#include <functional>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i)
typedef long long LL;
void run() {
int n;
cin >> n;
LL mx = 0, t = 0, q = 0, a;
REP(i,n) {
cin >> a;
mx = max(mx, a);
t += a;
q += t;
cout << mx * (i + 1) + q << endl;
}
}
int main() {
run();
return 0;
}
| //#pragma GCC optimize(2)
//#include <bits/stdc++.h>
#include <iostream>
#include <set>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <utility>
#include <map>
#define rush() int T;cin>>T;while(T--)
#define ms(a,b) memset(a,b,sizeof a)
#define lowbit(x) ((x)&(-x))
#define inf 0x7f7f7f7fll
#define eps 1e-11
#define sd(a) scanf("%d",&a)
#define sll(a) scanf("%lld",&a)
#define sll2(a,b) scanf("%lld%lld",&a,&b)
#define sll3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define sdd(a,b) scanf("%d%d",&a,&b)
#define sddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define sf(a) scanf("%lf",&a)
//#define sc(a) scanf("%c\n",&a)
#define ss(a) scanf("%s",a)
#define pd(a) printf("%d\n",a)
#define pdd(a,b) printf("%d %d\n",a,b)
#define pddd(a,b,c) printf("%d %d %d\n",a,b,c)
#define pll(a) printf("%lld\n",a)
#define pf(a) printf("%.1lf\n",a)
#define pc(a) printf("%c",a)
#define ps(a) printf("%s\n",a)
#define forn(i,a,b) for(int i=(a);i<=(b);i++)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define debug(a) cout<<#a<<" : "<<a<<" "<<" ; "
#define dbg(a) cout<<#a<<" : "<<a<<endl
#define show(a,b) cout<<a<<" :\t"<<b<<"\t*"<<endl
#define IOS ios::sync_with_stdio(0); cin.tie(0)
#define PAUSE system("pause")
//#define print(a) cout<<a<<endl;continue;
#define fr first
#define sc second
#define ceils(a,b) ceil(ll(a)/double(b))
#define floors(a,b) floor(ll(a)/double(b))
using namespace std;
//inline void swap(int &x,int &y){x^=y^=x^=y;}
typedef long long ll;
//using ui=unsigned int;
typedef unsigned long long ull;
typedef pair<int,int> Pair;
const double pi=acos(-1.0);
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};
const int limit=5e5;
int read()
{
int s=0;
char c=getchar(),lc='+';
while (c<'0'||'9'<c) lc=c,c=getchar();
while ('0'<=c&&c<='9') s=s*10+c-'0',c=getchar();
return lc=='-'?-s:s;
}
void write(int x)
{
if (x<0) putchar('-'),x=-x;
if (x<10) putchar(x+'0');
else write(x/10),putchar(x%10+'0');
}
void print(int x,char c='\n')
{
write(x);
putchar(c);
}
ll mod=1000003;
const int N=1e6+5;
int n, m, _;
int i, j, k;
int a[N];
ll pre[N];
signed main()
{
//IOS;
while(~sd(n)){
for(int i=1;i<=n;i++) sd(a[i]),pre[i]=a[i]+pre[i-1];
int maxx=0;
ll ans=0,sum=0;
for(int i=1;i<=n;i++){
ans+=a[i];
maxx=max(maxx,a[i]);
pll((ll)maxx*i+ans+sum);
sum+=pre[i];
}
}
//PAUSE;
return 0;
} |
#include<bits/stdc++.h>
//#include<atcoder/all>
using namespace std;
//using namespace atcoder;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int, int>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rrep(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr ll INF = 1LL << 60;
constexpr ll mod = 100000; //(ll)1e9 + 7;
constexpr double PI = 3.1415926535897932;
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;
}
inline void init() {
cin.tie(nullptr); cout.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
}
inline int popcount(ll n) {
n = (n & 0x5555555555555555) + (n >> 1 & 0x5555555555555555);
n = (n & 0x3333333333333333) + (n >> 2 & 0x3333333333333333);
n = (n & 0x0f0f0f0f0f0f0f0f) + (n >> 4 & 0x0f0f0f0f0f0f0f0f);
n = (n & 0x00ff00ff00ff00ff) + (n >> 8 & 0x00ff00ff00ff00ff);
n = (n & 0x0000ffff0000ffff) + (n >> 16 & 0x0000ffff0000ffff);
n = (n & 0x00000000ffffffff) + (n >> 32 & 0x00000000ffffffff);
return n;
}
int dx[] = { 1,0,-1,0,1,-1,-1,1 };
int dy[] = { 0,1,0,-1,1,-1,1,-1 };
int H, W, A, B;
vector<vector<bool>>v;
int dfs(int cnt = 0) {
if (cnt == A) return 1;
int res = 0;
rep(i, 0, H) {
rep(j, 0, W) {
if (v[i][j])continue;
rep(k, 0, 2) {
int x = j + dx[k], y = i + dy[k];
if (out(y, x, H, W))continue;
if (!v[y][x]) {
v[y][x] = true;
v[i][j] = true;
res += dfs(cnt + 1);
v[y][x] = false;
v[i][j] = false;
}
}
return res;
}
}
}
int main() {
init();
cin >> H >> W >> A >> B;
int _n = H * W, ans = 0;
for (int bit = 0;bit < (1 << _n);++bit) {
vector<vector<bool>>vec(H, vector<bool>(W, false));
if (popcount(bit) != B)continue;
rep(i, 0, _n) {
if ((bit >> i) & 1)vec[i / W][i % W] = true;
}
v = vec;
ans += dfs();
}
cout << ans << "\n";
return 0;
} | #include<bits/stdc++.h>
using namespace std;
bool f1;
#define LL long long
#define db double
#define Max(a,b) ((a)<(b))&&((a)=(b))
#define Min(a,b) ((a)>(b))&&((a)=(b))
inline int rd() {
int res=0;
char ch;
while(ch=getchar(),ch<48||ch>57);
do res=(res<<1)+(res<<3)+(ch^48);
while(ch=getchar(),ch>47&&ch<58);
return res;
}
const int M=1<<18;
int n,m;
LL f[M];
struct info {
int y,z;
};
int Sz[M];
vector<info>Q[20];
int X[M],Y[M],Z[M],sum[20];
bool f2;
int main() {
// printf("%lf\n",(&f2-&f1)/1024.0/1024.0);
// freopen("a.in","r",stdin);
// freopen("a.out","w",stdout);
n=rd(),m=rd();
for(int i=1; i<=m; ++i) {
X[i]=rd(),Y[i]=rd(),Z[i]=rd();
Q[X[i]].push_back((info)<%Y[i],Z[i]%>);
}
int t=1<<n;
f[0]=1;
for(int i=1; i<t;++i) {
Sz[i]=Sz[i^(i&-i)]+1;
memset(sum,0,sizeof sum);
for(int j=0; j<n; ++j)if(i&(1<<j))f[i]+=f[i^(1<<j)],sum[j+1]++;
for(int j=1; j<=n; ++j)sum[j]+=sum[j-1];
for(int j=0; j<Q[Sz[i]].size(); ++j) {
int yy=Q[Sz[i]][j].y,zz=Q[Sz[i]][j].z;
if(sum[yy]>zz){f[i]=0;break;}
}
}
printf("%lld",f[t-1]);
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);
}
const int inf = 2e9 + 123;
void solve() {
int n, k;
cin >> n >> k;
vector<vector<int> > v(n, vector<int>(n, 0));
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
cin >> v[i][j];
}
}
int L = -1, R = inf;
while (L + 1 < R) {
int M = (L + R) / 2;
vector<vector<int> > val(n + 1, vector<int>(n + 1, 0));
auto sum = [&] (int x1, int y1, int x2, int y2) {
x2++, y2++;
return val[x2][y2] + val[x1][y1] - val[x1][y2] - val[x2][y1];
};
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
val[i + 1][j + 1] = val[i][j + 1] + val[i + 1][j] - val[i][j] + (v[i][j] <= M);
}
}
bool ok = false;
for (int i = 0; i + k - 1 < n; ++i) {
for (int j = 0; j + k - 1 < n; ++j) {
if (sum(i, j, i + k - 1, j + k - 1) >= (k * k + 1) / 2) {
ok = true;
break;
}
}
if (ok) break;
}
if (ok) {
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 <bits/stdc++.h>
// #include <atcoder/all>
// using namespace atcoder;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << "\n"
#define COUTF(x) cout << setprecision(15) << (x) << "\n"
#define ENDL cout << "\n"
#define DF(x) x.erase(x.begin())
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define RSORT(x) sort(x.rbegin(), x.rend())
#define REVERSE(x) reverse(ALL(x))
#define MAX(x) *max_element(ALL(x))
#define MAXI(x) max_element(ALL(x)) - x.begin()
#define SUM(x) accumulate(ALL(x), 0ll)
#define COUNT(x, y) count(ALL(x), y);
#define ANS cout << ans << "\n"
#define YES cout << "YES\n";
#define NO cout << "NO\n";
#define Yes cout << "Yes\n";
#define No cout << "No\n";
#define init() \
cin.tie(0); \
ios::sync_with_stdio(false)
#define debug(x) cerr << "[debug] " << #x << ": " << x << endl;
#define debugV(v) \
cerr << "[debugV] " << #v << ":"; \
rep(z, v.size()) cerr << " " << v[z]; \
cerr << endl;
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;
using vp = vector<P>;
using vs = vector<string>;
template <typename T>
inline istream& operator>>(istream& i, vector<T>& v) {
rep(j, v.size()) i >> v[j];
return i;
}
template <typename T1, typename T2>
inline istream& operator>>(istream& i, pair<T1, T2>& v) {
return i >> v.first >> v.second;
}
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
return to_string(x).size();
}
ll gcd(ll x, ll y) {
return y ? gcd(y, x % y) : x;
}
ll lcm(ll a, ll b) {
return a / gcd(a, b) * b;
}
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 (b < a) a = b;
}
signed main() {
init();
ll N, K;
cin >> N >> K;
vvll A(N, vll(N));
cin >> A;
ll l = 0, r = INF;
while (r - l > 1) {
ll c = (l + r) / 2;
vvll R(N, vll(N));
rep(i, N) rep(j, N) {
if (c <= A[i][j]) R[i][j] += 1;
if (i != 0) R[i][j] += R[i - 1][j];
if (j != 0) R[i][j] += R[i][j - 1];
if (i != 0 and j != 0) R[i][j] -= R[i - 1][j - 1];
}
ll cnt = INF;
rep(i, N - (K - 1)) rep(j, N - (K - 1)) {
ll count = R[i + K - 1][j + K - 1];
if (i != 0) count -= R[i - 1][j + K - 1];
if (j != 0) count -= R[i + K - 1][j - 1];
if (i != 0 and j != 0) count += R[i - 1][j - 1];
chmin(cnt, count);
}
if (cnt < (K * K) / 2 + 1)
r = c;
else
l = c;
}
COUT(l);
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
using LL=long long;
using P=pair<int,int>;
using T=tuple<int,int,int>;
constexpr int mod=1000000007;
constexpr int inf=1e9;
constexpr double eps=1e-13;
int in(){
int x;
scanf("%d",&x);
return x;
}
int main(){
int n=in();
string s,x;
cin>>s>>x;
for(int i=0;i<n;i++)s[i]-='0';
vector<vector<int>>win(n+1,vector<int>(7));
win[n][0]=1;
for(int i=n-1;i>=0;i--){
if(x[i]=='T'){
for(int j=0;j<7;j++){
if(win[i+1][(j*10)%7] || win[i+1][(j*10+s[i])%7])win[i][j]=1;
}
}
else{
for(int j=0;j<7;j++){
if(win[i+1][(j*10)%7]==0 || win[i+1][(j*10+s[i])%7]==0)win[i][j]=0;
else win[i][j]=1;
}
}
}
cout<<(win[0][0] ? "Takahashi" : "Aoki")<<endl;
return 0;
} | #include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(int i=cc;i>=n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
using ll = long long;
const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const vector<int> dx2 = {1, 1, 1, 0, 0, 0, -1, -1, -1};
const vector<int> dy2 = {1, 0, -1, 1, -1, 0, 1, 0, -1};
const double PI = 3.1415926535;
const ll inf = 1001001001;
const ll e9 = 1000000000;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll MAX = 1000000;
const ll MOD = 1000000007;
const ll big = (1ll<<60);
const ll moda = 1000000007;
const ll modb = 100000007;
ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }
ll modPow(ll a, ll n, ll p) {
if (n == 0) return 1;
if (n == 1) return a % p;
if (n % 2 == 1) return (a * modPow(a, n - 1, p)) % p;
ll t = modPow(a, n / 2, p);
return (t * t) % p;
}
ll choose(ll n, ll r, ll mod){
ll mul = 1, div = 1;
for(ll i = 0; i < r; i++){
mul *= n - i;
div *= i + 1;
mul %= mod;
div %= mod;
}
return mul * modPow(div, mod - 2, mod) % mod;
}
int main(){
int n;
string s, x;
cin >> n >> s >> x;
vector<vector<bool>>dp(7,vector<bool>(n+1,false));//takahashi_win:true
dp[0][n] = true;
int digit = 1;
rep(i, 0, n){
int temp = (s[n-1-i]-'0');
if(x[n-1-i]=='T'){
rep(j, 0, 7){
dp[j][n-i-1] = dp[(temp*digit+j)%7][n-i]||dp[j][n-i];
}
}else{
rep(j, 0, 7){
dp[j][n-i-1] = dp[(temp*digit+j)%7][n-i]&&dp[j][n-i];
}
}
if(i!=n-1)(digit *= 10) %= 7;
}
/*
if(x[0]=='T'){
if(dp[(s[0]-'0')*digit%7][0]||dp[0][0]){
cout << "Takahashi" << endl;
}else{
cout << "Aoki" << endl;
}
}else{
if(dp[(s[0]-'0')*digit%7][0]&&dp[0][0]){
cout << "Takahashi" << endl;
}else{
cout << "Aoki" << endl;
}
}*/
if(dp[0][0]){
cout << "Takahashi" << endl;
}else{
cout << "Aoki" << endl;
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using _lint = int;
#define REP(i, n) for (_lint i = 0; i < (_lint)(n); i++)
#define FOR(i, a, b) for (_lint i = (_lint)(a); i < (_lint)(b); i++)
#define FORR(i, a, b) for (_lint i = (_lint)(b)-1; i >= (_lint)(a); i--)
#define CHMIN(a, b) (a) = min((a), (b))
#define CHMAX(a, b) (a) = max((a), (b))
#define ALL(v) (v).begin(), (v).end()
#define DEBUG(x) cerr << #x << ": " << (x) << endl
#define DEBUG_VEC(v) \
{ \
cerr << #v << ": "; \
REP(__i, size(v)) cerr << ((v)[__i]) << ", "; \
cerr << endl; \
}
int main() {
int ans = 1<<30;
int n;
cin>>n;
REP(i,n) {
int a,p,x;
cin>>a>>p>>x;
if(x>a) {
CHMIN(ans, p);
}
}
if(ans==(1<<30))ans=-1;
cout<<ans<<endl;
return 0;
}
| #include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#include<iomanip>
using namespace std;
int main(){
int n; cin >> n;
pair<int, int> a[n];
for(int i=0;i<n;i++) cin >> a[i].first >> a[i].second;
for(int i=0;i<(n-1);i++){
for(int j=i+1;j<n;j++){
for(int k=0;k<n;k++){
if(k == i || k == j) continue;
else{
int x = (a[j].first - a[i].first) * (a[k].second - a[i].second);
int y = (a[j].second - a[i].second) * (a[k].first - a[i].first);
if(x == y){
cout << "Yes" << endl;
return 0;
}
}
}
}
}
cout << "No" << endl;
} |
#include <bits/stdc++.h>
#define ff first
#define ss second
#define endl '\n'
// n acho que eu seja bom, mas eu ja fui pior
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
const int oo = 1e9;
const ll OO = 0x3f3f3f3f3f3f3f3fll;
const int MOD = 1000000007;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int n, a, b, ans = oo, menor = oo, maior = -oo; cin >> n;
vector<pii> ta, tb;
for (int i = 0; i < n; i++) {
cin >> a >> b;
ans = min(ans, a+b);
ta.push_back({a, i});
tb.push_back({b, i});
}
sort(ta.begin(), ta.end());
sort(tb.begin(), tb.end());
int it = 0;
while (it < n) {
if (tb[it].ss != ta[0].ss) {
ans = min(ans, max(tb[it].ff, ta[0].ff));
break;
}
it++;
}
it = 0;
while (it < n) {
if (tb[0].ss != ta[it].ss) {
ans = min(ans, max(tb[0].ff, ta[it].ff));
break;
}
it++;
}
cout << ans << endl;
return 0;
} | #include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)
#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>
#define F first
#define S second
#define MOD 1000000007
#define INF 1000000000000000LL
using namespace std;
int main(){
int n;cin>>n;
vector<ll>a(n), b(n);
rep(i, n)cin>>a[i]>>b[i];
ll r = INF;
rep(i, n)rep(j, n){
if(i==j)r = min<ll>(r, a[i]+b[j]);
else r = min<ll>(r, max<ll>(a[i], b[j]));
//cout<<i<<' '<<j<<' '<<r<<endl;
}
cout<<r<<endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int maxs = 2e5 + 5;
int PARENT[maxs];
int SIZE[maxs];
vector<int>a;
map<int,int>mp[maxs];
void SET(int V)
{
SIZE[V] = 1;
PARENT[V] = V;
}
int FIND_SET(int V)
{
if(V == PARENT[V])
return PARENT[V];
else
return PARENT[V] = FIND_SET(PARENT[V]);
}
void UNION(int A,int B)
{
A = FIND_SET(A);
B = FIND_SET(B);
if(A != B)
{
if(SIZE[A] < SIZE[B])
swap(A,B);
PARENT[B] = A;
SIZE[A] += SIZE[B];
for(auto it : mp[B])
mp[A][it.first] += it.second;
}
}
signed main()
{
int n,q;
cin >> n >> q;
a.resize(n + 1);
for(int i = 1;i <= n;++i)
{
SET(i);
cin >> a[i];
mp[i][a[i]]++;//.push_back(i);
}
while(q--)
{
int type,x,y;
cin >> type >> x >> y;
if(type & 1)
{
UNION(x,y);
}
else
{
int val = FIND_SET(x);
cout << mp[val][y];
cout << "\n";
}
}
}
| #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
// #define int long long
#define S second
#define F first
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define lb lower_bound
#define ub upper_bound
#define si(c) (int)((c).size())
#define lcm(a, b) (a * (b / __gcd(a,b)))
#define inf (int)(1e18)
#define endl '\n'
#define mp make_pair
#define time(s) (double(clock()-s)/double(CLOCKS_PER_SEC))
#define debug(args...) _F(#args, args)
#define vi std::vector<int>
#define pii pair<int, int>
#define vpi vector<pii>
#define ordered_set tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update>
clock_t start;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
template<typename T> void _F(const char *name, T arg1){ cerr << name << " = " << arg1 << endl;}
template<typename T, typename... Args> void _F(const char *names, T arg1, Args... args)
{ const char *name = strchr(names, ',');cerr.write(names, name-names) << " = " << arg1 << endl;_F(name+2, args...);}
template< typename T1, typename T2 > istream& operator>>(istream& in, pair<T1, T2> &q){ in >> q.F >> q.S; return in;}
template< typename T1, typename T2 > ostream& operator<<(ostream& out, pair<T1, T2> &q){ out << q.F << " " << q.S; return out;}
template< typename T1, typename T2 > pair<T1, T2> operator+(pair<T1, T2> p1, pair<T1, T2> p2){ return {p1.F+p2.F, p1.S+p2.S};}
template< typename T1, typename T2 > pair<T1, T2> operator-(pair<T1, T2> p1, pair<T1, T2> p2){ return {p1.F-p2.F, p1.S-p2.S};}
template< typename T1, typename T2 > bool operator<(pair<T1, T2> p1, pair<T1, T2> p2){ return p1 < p2 ;}
template<typename T> void Unique(vector<T> &v) {
sort(all(v)), v.resize(distance(v.begin(), unique(all(v))));
}
struct Dsu {
int n;
std::vector<int> par, siz;
std::vector<map<int, int> > un;
Dsu(int c[], int _n) {
n = _n;
par.resize(n+1), un.resize(n+1), siz.resize(n+1);
for(int i = 1; i <= n; i++)
par[i] = i, un[i][c[i]]++, siz[i] = 1;;
}
int root(int x) {
return (par[x] == x ? x : par[x] = root(par[x]));
}
void merge(int x, int y) {
x = root(x), y = root(y);
if(x == y) return;
if(siz[y] > siz[x]) swap(x, y);
par[y] = x;
siz[x] += siz[y];
for(auto u : un[y])
un[x][u.F] += u.S;
un[y].clear();
}
};
void solve() {
int n, q;
cin >> n >> q;
int c[n+1];
for(int i = 1; i <= n; i++)
cin >> c[i];
Dsu ds(c, n);
while(q--) {
int t, x, y;
cin >> t >> x >> y;
if(t == 1) {
ds.merge(x, y);
}
else {
int r = ds.root(x);
if(ds.un[r].count(y)) {
cout << ds.un[r][y] << endl;
}
else cout << 0 << endl;
// cout << ds.un[r].count(y) << endl;
}
}
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
start = clock();
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
freopen("error.txt", "w", stderr);
#endif
int test = 1;
// cin >> test;
cout << fixed << setprecision(12);
for(int i = 1; i <= test; ++i){
solve();
}
cerr << time(start);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n,m;
cin >> n >> m;
vector<int> vec (n);
for(int i=0; i<n; i++){
int x;
cin >> x;
vec.at(i) = x;
}
for(int i=0; i<m; i++){
int x;
cin >> x;
vec.push_back(x);
}
sort(vec.begin(),vec.end());
reverse(vec.begin(),vec.end());
stack<int> ans;
for(int i=0; i<vec.size(); i++){
if(ans.empty()){
ans.push(vec.at(i));
}
else if(vec.at(i) == ans.top()){
ans.pop();
}
else{
ans.push(vec.at(i));
}
}
while(!ans.empty()){
cout << ans.top() << " ";
ans.pop();
}
} | #include<bits/stdc++.h>
#define ll long long
#define pii pair<ll,ll>
#define fs first
#define ss second
#define fr(i,n) for(ll i=0;i<n;i++)
#define fr1(i,a,n) for(ll i=a;i<n;i++)
#define mp make_pair
#define pb push_back
using namespace std;
const ll mod=1e9+7;
const ll INF=LLONG_MAX;
const ll NINF=LLONG_MIN;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t=1;
while(t-->0){
string s;
cin>>s;
ll n=s.size();
fr(i,n){
if(s[n-i-1]=='9')cout<<6;
else if(s[n-i-1]=='6')cout<<9;
else cout<<s[n-i-1];
}
}
} |
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
// #include <atcoder/all>
using namespace std;
using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vii = V<int>;
using vvll = V<vll>;
using vvii = V< V<int> >;
using PII = P<int, int>;
using PLL = P<ll, ll>;
#define RevREP(i,n,a) for(ll i=n;i>a;i--) // (a,n]
#define REP(i,a,n) for(ll i=a;i<n;i++) // [a,n)
#define rep(i, n) REP(i,0,n)
#define ALL(v) v.begin(),v.end()
#define eb emplace_back
#define pb push_back
#define sz(v) int(v.size())
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
template< class A, class B > ostream& operator <<(ostream& out, const P<A, B> &p) {
return out << '(' << p.first << ", " << p.second << ')';
}
template< class A > ostream& operator <<(ostream& out, const V<A> &v) {
out << '[';
for (int i=0;i<int(v.size());i++) {
if (i) out << ", ";
out << v[i];
}
return out << ']';
}
template<class A, class B> istream& operator >>(istream& in, P<A, B> &p) {
return in >> p.first >> p.second;
}
template<class A> istream& operator >>(istream& in, V<A> &v) {
for (int i = 0; i < int(v.size()); i++) in >> v[i];
return in;
}
const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(12);
int a, b; cin >> a >> b;
cout << double(a) * double(b) / 100.0 << '\n';
return 0;
} | #include <bits/stdc++.h> // header file includes every Standard library
using namespace std;
int main() {
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif // ONLINE_JUDGE
ios_base::sync_with_stdio(false);
double n,d;
cin>>n>>d;
cout<< ((n-d)/n)*100;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "../debug.h"
#else
#define debug(x...) 141
#endif
#define forn(i,x,n) for(int i = x; i < n; ++i)
#define forit(it, m) for(auto it = m.begin(); it!=m.end(); ++it)
typedef long long ll;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
ll n,aa,ans=1e18;
char cc;
cin>>n;
map<char,vector<ll>> m;
vector<ll> a,b,c;
forn(i,0,2*n)
cin>>aa>>cc, m[cc].push_back(aa);
if(m['R'].size()%2==0&&m['G'].size()%2==0&&m['B'].size()%2==0){
cout<<0;
return 0;
}
debug(m['R'],m['G'],m['B']);
for(auto [_,x]:m)
if(x.size()%2&&a.empty())
a=x;
else if(x.size()%2)
b=x;
else
c=x;
sort(a.begin(),a.end());
sort(b.begin(),b.end());
for(auto x:a){
auto it=lower_bound(b.begin(),b.end(),x);
if(it!=b.end())
ans=min(ans,abs(x-*it));
if(it!=b.begin())
ans=min(ans,abs(x-*(--it)));
}
vector<pair<ll,ll>> ca(c.size(),{1e18,0}),cb(c.size(),{1e18,0});
forn(i,0,c.size()){
auto it=lower_bound(a.begin(),a.end(),c[i]);
if(it!=a.end())
ca[i].first=min(ca[i].first,abs(c[i]-*it));
if(it!=a.begin())
ca[i].first=min(ca[i].first,abs(c[i]-*(--it)));
it=lower_bound(b.begin(),b.end(),c[i]);
if(it!=b.end())
cb[i].first=min(cb[i].first,abs(c[i]-*it));
if(it!=b.begin())
cb[i].first=min(cb[i].first,abs(c[i]-*(--it)));
ca[i].second=cb[i].second=i;
}
sort(ca.begin(),ca.end());
sort(cb.begin(),cb.end());
if(c.size()&&ca[0].second==cb[0].second)
ans=min(ans,min(ca[0].first+cb[1].first,ca[1].first+cb[0].first));
else if(c.size())
ans=min(ans,ca[0].first+cb[0].first);
cout<<ans<<'\n';
return 0;
} | #include <bits/stdc++.h>
#define ll long long
using namespace std;
ll k, n;
const ll mod = 1e9 + 7;
ll dp[200100][17], cdp[17][17];
ll nCr(ll n, ll r)
{
if (r == 0 || r == n)
return 1;
if(cdp[n][r] != -1)
return cdp[n][r];
cdp[n][r] = (nCr(n-1, r-1) + nCr(n-1, r)) % mod;
return cdp[n][r];
}
ll pwr(ll a, ll b)
{
if(b == 0)
return 1;
if(b & 1)
{
return pwr(a, b - 1) * a % mod;
}
else
{
ll ret = pwr(a, b / 2);
return ret * ret % mod;
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
string str;
cin >> str;
cin >> k;
n = str.size();
memset(dp, 0, sizeof(dp));
memset(cdp, -1, sizeof(cdp));
for(int i = 0; i < 17; i++)
{
for(int j = 0; j <= i; j++)
{
cdp[i][j] = nCr(i, j);
}
}
dp[0][0] = 1;
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= i && j <= k; j++)
{
dp[i][j] = pwr(j, i);
for(int z = 0; z < j; z++)
{
dp[i][j] = (dp[i][j] - cdp[j][z] * dp[i][z] % mod + mod) % mod;
}
}
}
ll ret = 0;
for(int i = 1; i < n; i++)
{
ret += 15 * dp[i - 1][k - 1] * cdp[15][k - 1] % mod;
ret %= mod;
ret += 15 * dp[i - 1][k] * cdp[15][k - 1] % mod;
ret %= mod;
}
unordered_map<char, int> mp;
for(int i = 0; i < 10; i++)
mp[i + '0'] = i;
for(int i = 10; i < 16; i++)
mp[i - 10 + 'A'] = i;
unordered_set<int> used;
for(int i = 0; i < n && used.size() <= k; i++)
{
int sz = used.size();
// need (k - sz) new number for
int num = mp[str[i]];
int start = 0;
if(i == 0)
start = 1;
for(int j = start; j < num; j++)
{
int nsz = sz;
if(!used.count(j))
nsz++;
int nk = k - nsz;
if(nk < 0)
continue;
int nn = n - i - 1;
for(int z = nk; z <= k; z++)
{
ret += dp[nn][z] * cdp[16 - nsz][nk] % mod * cdp[nsz][z - nk] % mod;
ret %= mod;
}
}
used.insert(num);
}
unordered_set<char> st;
for(int i = 0; i < n; i++)
{
st.insert(str[i]);
}
if(st.size() == k)
ret++;
cout << ret << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
//↓AC-library使うなら
//型関係
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> pll;
typedef priority_queue<int, vector<int>, greater<int>> PQ;//昇順priority_queue
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<P > vpii;
typedef vector<pll > vpll;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
//repマクロ
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rrep(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i < (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
//範囲関係
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define ALL(x) (x).begin(), (x).end()
//定数
#define inf 1000000000000
#define mod 1000000007
#define MAXR 100000
#define MATHPI acos(-1)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
//操作
#define PB push_back
#define PF push_front
#define MP make_pair
#define F first
#define S second
//数学関係, a<=x<=b
bool updown(ll x, ll a, ll b) { return x >= a && x <= b; }
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; }
#define SUM(x) accumulate(ALL(x), 0)
//chmin, chmax
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;}
//小数出力(f...出力したい小数, n...小数点以下の桁数)
void printd(double f, int n) { cout << fixed << setprecision(n) << f << endl; } //指定した桁で小数を出力
//YES/NO, Yes/No, yes/no出力
void YES(bool c = true) { cout << (c ? "YES" : "NO") << endl; } //YES(条件式)で記述
void Yes(bool c = true) { cout << (c ? "Yes" : "No") << endl; } //Yes(条件式)で記述
void yes(bool c = true) { cout << (c ? "yes" : "no") << endl; } //yes(条件式)で記述
//if use atcoder library:g++ main.cpp -std=c++17 -I /home/k0gane/ac-library
//累積和
//https://qiita.com/drken/items/56a6b68edef8fc605821
//point...n+1の容量のリストを作る
//
//深さ優先...push_front
//幅優先...push_backP
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, k, m; cin >> n >> k >> m;
int tar = n * m;
rep(i, n-1){
int a; cin >> a;
tar -= a;
}
if(tar > k) cout << "-1" << endl;
else cout << max(0, tar) << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define rrep(i,a) for(ll i=a-1;i>=0;i--)
#define MOD 1000000007
//debug
#define debug(arr) cerr<<#arr<<"(l"<<__LINE__<<") : ";for(auto x:arr)cerr<<x<<" ";cerr<<endl;
int main(){
ll N, C, a, b, c;
cin >> N >> C;
vector<pll> schedule;
rep(i, N){
cin >> a >> b >> c;
schedule.emplace_back(a, c);
schedule.emplace_back(b+1, -c);
}
sort(schedule.begin(), schedule.end());
ll cost = 0, ans = 0, last_event = 0;
for(auto p: schedule){
ans += (p.first - last_event) * min(C, cost);
last_event = p.first;
cost += p.second;
}
cout << ans << endl;
return 0;
}
|
//In the name of ALLAH
#include<bits/stdc++.h>
using namespace std;
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
// User defined sizeof macro
# define my_sizeof(type) ((char *)(&type+1)-(char*)(&type))
#define ll long long int
int main()
{
optimize();
int n,a,b;
cin>>n>>a>>b;
cout<<n-a+b;
return 0;
}
| #include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
//#define int long long
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PI = pair<pair<int,int>,int>;
using PL = pair<long long, long long>;
using PLL = pair<pair<long long, long long>, long long>;
using Pxy = pair<long double, long double>;
using Tiib = tuple<int, int, bool>;
using vvl = vector<vector<ll>>;
const int INF = 1001001007;
const int modd = 1000000007;
const long long modl = 1000000007LL;
const long long mod = 998244353LL;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
rep(i,ar.size()-1) cout << ar[i] << " ";
cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
rep(i,ar.size()){
rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
cout << ar[i][ar[0].size()-1] << endl;
}
}
template <typename S>
bool range(S a, S b, S x){
return (a <= x && x < b);
}
void yes(){
cout << "Yes" << endl;
}
void no (){
cout << "No" << endl;
}
ll cel (ll a, ll b){
if (a % b == 0) return a / b;
else return a / b + 1;
}
ll gcds(ll a, ll b){
ll c = a % b;
while (c != 0){
a = b;
b = c;
c = a % b;
}
return b;
}
vector<vector<vector<ld>>> dp(101,vector<vector<ld>>(101,vector<ld>(101,-1.0)));
ld sik(int a, int b, int c){
if (dp[a][b][c] >= 0.0) return dp[a][b][c];
if (a == 100){
dp[a][b][c] = 0.0;
return dp[a][b][c];
}
if (b == 100){
dp[a][b][c] = 0.0;
return dp[a][b][c];
}
if (c == 100){
dp[a][b][c] = 0.0;
return dp[a][b][c];
}
ld i = a; ld j = b; ld k = c;
ld ans = i * sik(a+1,b,c) + j * sik(a,b+1,c) + k * sik(a,b,c+1);
ans /= i + j + k;
dp[a][b][c] = ans + 1.0;
return dp[a][b][c];
}
int main(){
int a, b, c; cin >> a >> b >> c;
cout << setprecision(20) << sik(a,b,c) << endl;
} |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define all(aa) aa.begin(), aa.end()
int main(){
int n, ans=0;
cin>>n;
for(int a = 1; a <= n; a++) for(int b = 1; b <= n/a; b++) ans+=n/(a*b);
cout<<ans<<endl;
} | #include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<bitset>
#include<cmath>
#include<ctime>
#include<queue>
#include<map>
#include<set>
#define int long long
#define lowbit(x) (x&(-x))
#define mid ((l+r)>>1)
#define lc (x<<1)
#define rc (x<<1|1)
#define max Max
#define min Min
#define abs Abs
using namespace std;
inline int read()
{
int ans=0,f=1;
char c=getchar();
while(c>'9'||c<'0'){if(c=='-')f=-1;c=getchar();}
while(c>='0'&&c<='9'){ans=(ans<<1)+(ans<<3)+c-'0';c=getchar();}
return ans*f;
}
inline void write(int x)
{
if(x<0) putchar('-'),x=-x;
if(x/10) write(x/10);
putchar((char)(x%10)+'0');
}
template<typename T>inline T Abs(T a){return a>0?a:-a;};
template<typename T,typename TT>inline T Min(T a,TT b){return a>b?b:a;}
template<typename T,typename TT> inline T Max(T a,TT b){return a>b?a:b;}
const int N=105;
int n,m,a[N][N],mmin,ans;
signed main()
{
n=read();m=read();mmin=1e18;
for(int i=1;i<=n;++i)
for(int j=1;j<=m;++j)
{
a[i][j]=read();
mmin=min(mmin,a[i][j]);
}
for(int i=1;i<=n;++i)
for(int j=1;j<=m;++j)
ans+=a[i][j]-mmin;
printf("%lld\n",ans);
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a(200010);
int ans = 0;
for(int i = 0; i < n; i++){
int p;
cin >> p;
a[p] = 1;
while(a[ans] == 1) ans++;
cout << ans << endl;
}
} | #include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
using namespace std;
using ll = long long;
int main()
{
int N;
cin >> N;
vector<int> n;
rep(i, 0, N + 1)
{
n.push_back(i);
}
vector<int> ans;
rep(i, 0, N)
{
int p;
cin >> p;
auto it = lower_bound(n.begin(), n.end(), p);
if (it != n.end())
{
if (p == *it)
{
n.erase(it);
}
}
ans.push_back(*n.begin());
}
rep(i, 0, N)
{
cout << ans[i] << endl;
}
}
|
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(ll i = (ll)(s); i < (ll)(t); i++)
#define rrep(i,s,t) for(ll i = (ll)(s-1);(ll)(t) <= i; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
constexpr ll INF = numeric_limits<ll>::max()/4;
constexpr ll n_max = 2e5+10;
#define int ll
const long double pi = 3.14159265358979323846;
template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';}
string to_string(const char *c) {return to_string((string) c);}
string to_string(bool b) {return (b ? "true" : "false");}
template <size_t N>
string to_string(bitset<N> v){
string res = "";
for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
return res;
}
template <typename A>
string to_string(A v) {
bool first = true;
string res = "{";
for(const auto &x : v) {
if(!first) res += ", ";
first = false;
res += to_string(x);
}
res += "}";
return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
void debug_out() {cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
template<class T>
bool chmax(T &a, T b){if(a < b){a = b; return true;} return false;}
template<class T>
bool chmin(T &a, T b){if(a > b){a = b; return true;} return false;}
signed main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
ll n; cin >> n;
ll ans = 0;
rep(i,0,n){
ll a,b; cin >> a >> b;
ans += (a + b) * (b - a + 1) / 2;
}
cout << ans << endl;
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t=1;
//cin>>t;
while(t--){
ll n,k;
cin>>n>>k;
vector<ll>a(n);
map<ll,ll>mp;
for(int i=0;i<n;i++){
cin>>a[i];
mp[a[i]]++;
}
ll res=0;
while(mp[0]>0 && k>0){
ll pre=0;
for(auto x:mp ){
if( x.second>0 ){
if(pre ==x.first )
pre++;
else
break;
mp[x.first]--;
}
else
break;
}
if(pre==0)
break;
else
res+=pre;
k--;
}
cout<<res;
}
return 0;
}
|
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
void sum(vector<ll>&x, vector<ll>&y, int pos, ll total){
if(pos >= (ll)x.size()) return;
y.push_back(total);
sum(x, y, pos+1, total);
y.push_back(total + x[pos]);
sum(x, y, pos+1, total + x[pos]);
}
int main(){
ll n, t, ans = 0;
cin >> n >> t;
vector<ll> a(n);
vector<ll> b, c, d, e;
for(int i = 0; i < n; i++) cin >> a[i];
for(int i = 0; i < n; i++){
if(i%2==0) b.push_back(a[i]);
else c.push_back(a[i]);
}
d.push_back(0);
e.push_back(0);
sum(b, d, 0, 0);
sum(c, e, 0, 0);
sort(d.begin(), d.end());
d.erase(unique(d.begin(), d.end()), d.end());
sort(e.begin(), e.end());
e.erase(unique(e.begin(), e.end()), e.end());
for(auto x: d){
if(x > t) continue;
auto maior = upper_bound(e.begin(), e.end(), t-x);
if(maior != e.begin() && e.size() != 0) maior--;
if(x+(*maior) <= t) ans = max(ans, x+(*maior));
}
cout << ans << '\n';
return 0;
} | /*
{
######################
# Author #
# Gary #
# 2020 #
######################
*/
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
#define check_min(a,b) a=min(a,b)
#define check_max(a,b) a=max(a,b)
using namespace std;
//inline int read(){
// int x=0;
// char ch=getchar();
// while(ch<'0'||ch>'9'){
// ch=getchar();
// }
// while(ch>='0'&&ch<='9'){
// x=(x<<1)+(x<<3)+(ch^48);
// ch=getchar();
// }
// return x;
//}
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
/*}
*/
int n;
LL t;
LL a[44];
vector<LL> solve(int l,int r){
int len=r-l+1;
if(len<=0) return vector<LL> (1,0ll);
vector<LL> rest;
rep(i,1<<len){
LL tot=0;
rep(j,len){
if((i>>j)&1)
{
int is=l+j;
tot+=a[is];
}
}
rest.PB(tot);
}
sort(ALL(rest));
return rest;
}
int main(){
scanf("%d%lld",&n,&t);
rb(i,1,n)
scanf("%lld",&a[i]);
vector<LL> v1,v2;
int half=(n+1)/2;
v1=solve(1,half);
int x=0;
v2=solve(half+1,n);
while(v1.back()>t){
v1.POB();
}
LL rest=0;
while(!v1.empty()){
LL now=v1.back();
v1.POB();
while(x+1<v2.size()&&v2[x+1]+now<=t)
x++;
check_max(rest,now+v2[x]);
}
cout<<rest<<endl;
return 0;
}
/** 程序框架:
*
*
*
*
**/
|
#include<bits/stdc++.h>
// #include<atcoder/all>
// #include<boost/multiprecision/cpp_int.hpp>
using namespace std;
// using namespace atcoder;
// using bint = boost::multiprecision::cpp_int;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007
// 2021/1/19
struct SCC{
/*
v := 隣接リスト有向グラフ
rv := vの逆辺
C := 同じ強連結成分のリスト
H := 強連結成分分解後のDAGの隣接リスト(頂点の重複有り。)
vs := 帰りがけ順
blg := その頂点が属す強連結成分の番号
*/
vector<vector<int>> v,rv,C,H;
vector<int> vs,blg;
vector<bool> used;
SCC(int n) : v(n),rv(n),blg(n),used(n,0) {}
void add_edge(int a,int b){
v[a].push_back(b);
rv[b].push_back(a);
}
//帰り帰りがけ順を探す
void dfs(int ov){
used[ov] = 1;
for(auto nv : v[ov]){
if(used[nv])continue;
dfs(nv);
}
vs.push_back(ov);
}
//逆辺を移動して、scc
void rdfs(int ov,int nu){
used[ov] = 1;
blg[ov] = nu;
C[nu].push_back(ov);
for(auto nv : rv[ov]){
if(used[nv])continue;
rdfs(nv,nu);
}
}
int build(){
int n = v.size();
for(int i = 0;i < n;i++)if(!used[i])dfs(i);
fill(used.begin(),used.end(),0);
int nu = 0;
for(int i = n-1;i >= 0;i--){
if(used[vs[i]])continue;
H.emplace_back();
C.emplace_back();
rdfs(vs[i],nu++);
}
for(int i = 0;i < n;i++){
for(auto j : v[i]){
if(blg[i] != blg[j])H[blg[i]].push_back(blg[j]);
}
}
return nu;
}
};
// 2020/12/06 rechecked
long long modpow(long long n,long long r,const int mod = 998244353){
long long res = 1;
while(r){
if(r & 1)res = res*n%mod;
n = n*n%mod;
r >>= 1;
}
return res;
}
int main(){
int n;
cin >> n;
vector<int> f(n);
rep(i,n)cin >> f[i],f[i]--;
SCC scc(n);
rep(i,n)scc.add_edge(i,f[i]);
scc.build();
int cnt = 0;
for(auto au : scc.C)if(au.size() >= 2 || au[0] == f[au[0]])cnt++;
cout << (modpow(2,cnt)-1+998244353)%998244353 << "\n";
return 0;
} | #include <iostream>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <algorithm>
#define rep(i, n) for(i = 0; i < (n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define MOD 998244353
#define PI 3.14159265358979323846
#define INF 1 << 30
using namespace std;
typedef long long ll;
typedef pair<int, int> pp;
ll Pow(ll n, ll k) {
ll ans = 1, a = n % MOD;
while (k > 0) {
if (k & 1) {
ans *= a;
ans %= MOD;
}
a *= a;
a %= MOD;
k >>= 1;
}
return ans;
}
int DFS(int n, int k, vector<int>& d, vector<int>& v) {
v[n] = k;
if (v[d[n]] < 0)
return DFS(d[n], k, d, v);
else if (v[d[n]] == k)
return 1;
return 0;
}
int main(void) {
int num, i, k = 0, x = 0;
cin >> num;
vector<int> d(num), v(num, -1);
rep(i, num) {
cin >> d[i];
d[i]--;
}
rep(i, num) {
if (v[i] < 0) {
if (DFS(i, x, d, v))
k++;
x++;
}
}
cout << Pow(2ll, k) - 1 << "\n";
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
cout << N - 1;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"
template<class T> void chmax(T &a, const T b){ a = max(a, b); }
template<class T> void chmin(T &a, const T b){ a = min(a, b); }
long long gcd(long long a, long long b) { return (a % b) ? gcd(b, a % b) : b; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
// ifstream in("input.txt");
// cin.rdbuf(in.rdbuf());
ll n;
cin >> n;
cout << (n - 1) << endl;
return 0;
}
|
#include<bits/stdc++.h>
#define LL long long
#define pb push_back
#define SZ(x) ((int)x.size()-1)
#define ms(a,b) memset(a,b,sizeof a)
#define F(i,a,b) for (int i=(a);i<=(b);++i)
#define DF(i,a,b) for (int i=(a);i>=(b);--i)
using namespace std;
inline int read(){
char ch=getchar(); int w=1,c=0;
for(;!isdigit(ch);ch=getchar()) if (ch=='-') w=-1;
for(;isdigit(ch);ch=getchar()) c=(c<<1)+(c<<3)+(ch^48);
return w*c;
}
int calc(int x){
int ret=0;
while (x){
ret+=x%10;
x/=10;
}
return ret;
}
int main(){
int a=read(),b=read();
cout<<max(calc(a),calc(b))<<'\n';
return 0;
}
/* stuff you should look for
* int overflow, array bounds
* special cases (n=1?)
* do smth instead of nothing and stay organized
* WRITE STUFF DOWN
* DON'T GET STUCK ON ONE APPROACH
*/
| #include <bits/stdc++.h>
using namespace std;
int fanc(string S){
int ret=0;
ret += S[0]-'0';
ret += S[1]-'0';
ret += S[2]-'0';
return ret;
}
int main() {
string A,B;
cin>>A>>B;
int ans = max(fanc(A),fanc(B));
cout<<ans<<endl;
return 0;
//解説を見た
}
|
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define fastIO ios_base::sync_with_stdio(false); cin.tie(0);
#define mod 1000000007
int main()
{
double R,X,Y;
cin>>R>>X>>Y;
double K = sqrt(X*X + Y*Y);
if(K == R)
cout<<1<<endl;
else if(K <= 2*R)
cout<<2<<endl;
else cout<<ceil(double(1.0 * K/R))<<endl;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
bool ll_sqrt(ll x, ll& lower_bound, ll& upper_bound)
{
constexpr ll ll_max = numeric_limits<ll>::max();
bool first_boost = true;
lower_bound = 0;
upper_bound = x;
while (upper_bound - lower_bound > 1)
{
if (first_boost)
{
ll guess = (ll)sqrt((double)x);
lower_bound = max(guess - 1, (ll)0);
upper_bound = lower_bound + 3;
first_boost = false;
}
ll newval = (lower_bound + upper_bound) / 2;
if ((newval != 0) && (newval > ll_max / newval)) // newval*newval becomes overflow
upper_bound = newval; // because overflow means newval is too big
else
{
ll newval_sqr = newval * newval;
if (newval_sqr < x)
lower_bound = newval;
else
upper_bound = newval;
}
}
if ((upper_bound != 0) && (upper_bound > ll_max / upper_bound))
{
if (lower_bound * lower_bound == x)
upper_bound = lower_bound;
}
else
{
if (lower_bound * lower_bound == x)
upper_bound = lower_bound;
else if (upper_bound * upper_bound == x)
lower_bound = upper_bound;
}
bool is_exact = (lower_bound == upper_bound);
return is_exact;
}
ll ll_ceil(ll x, int digit);
ll ll_floor(ll x, int digit);
ll ll_floor(ll x, int digit)
{
if (x < 0)
return -ll_ceil(-x, digit);
ll div = 1;
while (digit != 0)
{
div *= 10;
digit--;
}
ll modval = x % div;
ll ans = x - modval;
return ans;
}
ll ll_ceil(ll x, int digit)
{
if (x < 0)
return -ll_floor(-x, digit);
ll div = 1;
while (digit != 0)
{
div *= 10;
digit--;
}
ll modval = x % div;
ll ans = x - modval;
if (modval != 0)
ans += div;
return ans;
}
int main() {
ll R, X, Y;
cin >> R >> X >> Y;
R = R*R;
ll ans = 0;
ld dist = X*X + Y*Y;
ld div = sqrt(dist / R);
ans = ceil(sqrt(dist / R));
if(div < 1){
ans =2;
}
cout << ans << endl;
return 0;
} |
#include <bits/stdc++.h>
#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))
using ll = std::int64_t;
using P = std::tuple<int,int>;
double Sx, Sy, Gx, Gy;
int main(){
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
std::cin >> Sx >> Sy >> Gx >> Gy;
double a = (- Gy - Sy) / (Gx - Sx),
x = Sx - Sy / a;
printf("%.10f\n", x);
}
| /*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG
#endif
#include <stdio.h>
#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 <iomanip> //setprecision
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set,multiset
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
#include <numeric> //accumulate,,,
#include <time.h> //clock
#define endl "\n";
using namespace std;
using PLL = pair<long long,long long>;
using P = pair<int,int>;
const long long INF = 3000000000000000001;
const int inf = 1001001001;
long long MOD = 1000000007;
//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M, long long mod) {
if (M == 0) return 1;
long long res = mod_pow((N * N) % mod, M / 2,mod);
//When end-of-a bit is 1, times simple N.
if (M & 1) res = (res * N) % mod;
return res %= mod;
}
long long gcd(long long a, long long b) {
if (b == 0) return a; else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
return a / gcd(a, b) * b ;
}
long long get_mod(long long res){
if(res < 0) res += MOD;
return res % MOD;
}
int main() {
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
long double sx,sy,gx,gy;cin >> sx >> sy >> gx >> gy;
cout << fixed << setprecision(7) << (gx-sx)*(sy/(sy+gy))+sx << endl;
} |
#include <bits/stdc++.h>
#define SIS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define lowbit(x) (x & -x)
#define FOR(i,a,b) for(int i=(a); i< (b); ++i)
#define RFOR(i,b,a) for(int i=(b);i>=(a);i--)
#define REP(i,a,b) for(int i=(a); i<=(b); ++i)
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
template<typename T>
void PrArr(const T a[] , int len){
for(int i = 0;i <= len; i++)cout << a[i] << " ";
cout << endl;
}
template<typename T>
void PrVec(const vector<T> a){
for(auto it : a)cout << it << " ";
cout << endl;
}
const int MAX = 0x7ffffff;
const int MIN = 0xcf;
int test;
void slove()
{
string s1, s2, s3;
cin >> s1 >> s2 >> s3;
// 1. 记录一下每个字符出现的次数
map<char, int> mp;
for(char c : s1) mp[c] ++;
for(char c : s2) mp[c] ++;
for(char c : s3) mp[c] ++;
/*
如果出现的字母数量大于10意味着要出现10个不同数字表示
这样是不可能成立的,所以这种情况下一定不存在解
*/
if(mp.size() > 10) {
cout << "UNSOLVABLE" << endl;
return ;
}
// 获取到以上出现过哪些字母并组合成一个字符串
string s0;
for(auto p : mp) s0 += p.first;
int m = s0.size();
vector<int> v(10);
for(int i = 0; i < 10 ; i++) v[i] = i;
auto val = [&](char c) {
for(int i = 0; i < m; i ++)
{
if(c == s0[i]) {
return v[i];
}
}
return -1;
};
do {
// 此时数字包含前导0需要排除这种情况。
if(val(s1[0]) == 0 || val(s2[0]) == 0 || val(s3[0]) == 0) {
continue;
}
ll x1 = 0, x2 = 0, x3 = 0;
for(auto c : s1) {
x1 *= 10;
x1 += val(c);
}
for(auto c : s2) {
x2 *= 10;
x2 += val(c);
}
for(auto c : s3) {
x3 *= 10;
x3 += val(c);
}
if(x1 + x2 == x3)
{
cout << x1 << endl;
cout << x2 << endl;
cout << x3 << endl;
return ;
}
} while(next_permutation(v.begin(),v.end()));
cout << "UNSOLVABLE" << endl;
}
int main()
{
#ifdef LOCAL
auto start_time = clock();
cerr << setprecision(3) << fixed; // 在iomanip中
#endif
SIS;slove();
#ifdef LOCAL
auto end_time = clock();
cerr << "Execution time: " << (end_time - start_time) * (int)1e3 / CLOCKS_PER_SEC << " ms\n";
#endif
} | #include <bits/stdc++.h>
using namespace std;
#define int int64_t
void __print(int x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
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 DEBUG
#define imie(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define imie(x...)
#endif
int f(string s)
{
int ans = 0;
for(char c : s)
ans = ans * 10 + c - '0';
return ans;
}
int32_t main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
vector<string> s(3);
for(auto &x : s)
cin >> x;
vector<pair<int, int>> g[26];
set<int> idx;
for(int i = 0; i < 3; i++) {
for(int j = 0; j < int(s[i].size()); j++) {
idx.insert(s[i][j] - 'a');
g[s[i][j] - 'a'].push_back(make_pair(i, j));
}
}
int N = int(idx.size());
if(N > 10) {
cout << "UNSOLVABLE";
return 0;
}
vector<int> permute(10);
for(int i = 0; i < 10; i++)
permute[i] = i;
do {
int c = 0;
for(int idx_in_g : idx) {
for(auto p : g[idx_in_g])
s[p.first][p.second] = char(permute[c] + '0');
c++;
}
if(s[0][0] == '0' || s[1][0] == '0' || s[2][0] == '0')
continue;
vector<int> num(3);
for(int i = 0; i < 3; i++) {
num[i] = f(s[i]);
}
if(num[0] + num[1] == num[2]) {
for(int x : num)
cout << x << endl;
return 0;
}
} while(next_permutation(permute.begin(), permute.end()));
cout << "UNSOLVABLE";
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define eb emplace_back
#define ii pair<int, int>
#define OK (cerr << "OK" << endl)
#define debug(x) cerr << #x " = " << (x) << endl
#define ff first
#define ss second
#define int long long
#define tt tuple<int, int, int>
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vii vector<pair<int, int>>
#define vvi vector<vector<int>>
#define vvii vector<vector<pair<int, int>>>
#define Mat(n, m, v) vector<vector<int>>(n, vector<int>(m, v))
#define endl '\n'
constexpr int INF = (sizeof(int) == 4 ? 1e9 : 2e18) + 1e5;
constexpr int MOD = 1e9 + 7;
constexpr int MAXN = 2e5 + 3;
// INDEX BY ONE ALWAYS!!!
class BIT_2D {
private:
// row, column
const int n, m;
vector<vector<int>> tree;
private:
// Returns an integer which constains only the least significant bit.
int low(const int i) { return i & (-i); }
void _update(const int x, const int y, const int delta) {
for (int i = x; i < n; i += low(i))
for (int j = y; j < m; j += low(j))
tree[i][j] += delta;
}
int _query(const int x, const int y) {
int ans = 0;
for (int i = x; i > 0; i -= low(i))
for (int j = y; j > 0; j -= low(j))
ans += tree[i][j];
return ans;
}
public:
// put the size of the array without 1 indexing.
/// Time Complexity: O(n * m)
BIT_2D(const int n, const int m) : n(n + 1), m(m + 1) {
tree.resize(this->n, vector<int>(this->m, 0));
}
/// Time Complexity: O(n * m * (log(n) + log(m)))
BIT_2D(const vector<vector<int>> &mat)
: n(mat.size()), m(mat.front().size()) {
// Check if it is 1 indexed.
assert(mat[0][0] == 0);
tree.resize(n, vector<int>(m, 0));
for (int i = 1; i < n; i++)
for (int j = 1; j < m; j++)
_update(i, j, mat[i][j]);
}
/// Query from (1, 1) to (x, y).
///
/// Time Complexity: O(log(n) + log(m))
int prefix_query(const int x, const int y) {
assert(0 < x), assert(x < n);
assert(0 < y), assert(y < m);
return _query(x, y);
}
/// Query from (x1, y1) to (x2, y2).
///
/// Time Complexity: O(log(n) + log(m))
int query(const int x1, const int y1, const int x2, const int y2) {
assert(0 < x1), assert(x1 <= x2), assert(x2 < n);
assert(0 < y1), assert(y1 <= y2), assert(y2 < m);
return _query(x2, y2) - _query(x1 - 1, y2) - _query(x2, y1 - 1) +
_query(x1 - 1, y1 - 1);
}
/// Updates point (x, y).
///
/// Time Complexity: O(log(n) + log(m))
void update(const int x, const int y, const int delta) {
assert(0 < x), assert(x < n);
assert(0 < y), assert(y < m);
_update(x, y, delta);
}
};
vvi mat;
int n;
int k;
bool check(int mid) {
vvi mt = Mat(n + 1, n + 1, 0);
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j)
mt[i][j] = mat[i][j] <= mid;
BIT_2D bit(mt);
int sz = k * k / 2 + 1;
if (k % 2 == 0)
sz--;
// debug(sz);
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j) {
int x2 = i + k - 1;
int y2 = j + k - 1;
if (x2 > n || y2 > n)
break;
if (bit.query(i, j, x2, y2) >= sz) {
return true;
}
}
return false;
}
// #define MULTIPLE_TEST_CASES
void solve(const int test) {
cin >> n;
cin >> k;
mat = Mat(n + 1, n + 1, 0);
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j) {
cin >> mat[i][j];
}
int l = 0, r = 1e9;
int ans = -1;
while (l <= r) {
int mid = (l + r) / 2;
if (check(mid)) {
r = mid - 1;
ans = mid;
} else {
l = mid + 1;
}
}
assert(ans != -1);
cout << ans << endl;
}
signed main() {
// const string FILE_NAME = "";
// freopen((FILE_NAME + string(".in")).c_str(), "r", stdin);
// freopen((FILE_NAME + string(".out")).c_str(), "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
int t = 1;
#ifdef MULTIPLE_TEST_CASES
cin >> t;
#endif
for (int i = 1; i <= t; ++i)
solve(i);
}
| #include<bits/stdc++.h>
using namespace std;
const int N = 810;
typedef long long ll;
int g[N][N];
int s[N][N];
int n, k;
bool check(int x)
{
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
s[i][j] = s[i-1][j] + s[i][j-1] - s[i-1][j-1] + (g[i][j] >= x);
for(int i=k;i<=n;i++)
for(int j=k;j<=n;j++)
{
int t = s[i][j] - s[i-k][j] - s[i][j-k] + s[i-k][j-k];
if((k*k/2) + 1 > t) return 0;
}
return 1;
}
int main()
{
cin >> n >> k;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
cin >> g[i][j];
int l = 0, r = 1e9;
while(l < r)
{
int mid = (l + r + 1) >> 1;
if(check(mid)) l = mid;
else r = mid - 1;
}
cout << l;
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
//bool vis[1000];
//int x[]={1,-1,0,0};
//int y[]={0,0,1,-1};
//int f=0;
//"'';
void dfs(int i,ll d,vector<vector<vector<ll> > > &adj,vector<ll> &v){
v[i]=d;
//cout<<i<<" "<<d<<endl;
for(int j=0;j<adj[i].size();j++){
int u=adj[i][j][0];
ll w=adj[i][j][1];
if(v[u]==-1){
dfs(u,d^w,adj,v);
}
}
}
int main() {
int n;
cin>>n;
vector<vector<vector<ll> > > adj(n);
for(int i=1;i<n;i++){
ll a,b,c;
cin>>a>>b>>c;
a--;
b--;
adj[a].push_back({b,c});
adj[b].push_back({a,c});
}
vector<ll> v(n,-1);
dfs(0,0,adj,v);
int dp[62];
long long mod=1e9+7;
long long ans=0;
memset(dp,0,sizeof(dp));
for(int i=0;i<(int)v.size();i++){
//cout<<v[i]<<endl;
for(ll j=0;j<62;j++){
if(v[i]&(1ll<<j)){
dp[j]++;
}
}
}
for(ll i=0;i<62;i++){
long long a=dp[i];
long long b=v.size()-a;
//cout<<a<<" "<<b<<endl;
ll z=(a*b)%mod;
ll zz=pow(2ll,i);
zz=zz%mod;
zz=(z*zz)%mod;
//cout<<z<<" "<<zz<<endl;
ans=(ans+zz)%mod;
//cout<<i<<endl;
}
cout<<ans<<endl;
}
| //
// _oo0oo_
// o8888888o
// 88" . "88
// (| -_- |)
// 0\ = /0
// ___/`---'\___
// .' \\| |// '.
// / \\||| : |||// \
// / _||||| -:- |||||- \
// | | \\\ - /// | |
// | \_| ''\---/'' |_/ |
// \ .-\__ '-' ___/-. /
// ___'. .' /--.--\ `. .'___
// ."" '< `.___\_<|>_/___.' >' "".
// | | : `- \`.;`\ _ /`;.`/ - ` : | |
// \ \ `_. \_ __\ /__ _/ .-` / /
// =====`-.____`.___ \_____/___.-`___.-'=====
// `=---='
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define ll long long
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define F first
#define S second
#define P pair
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define V vector
#define RE return
#define ALL(a) a.begin(),a.end()
#define MP make_pair
#define PB emplace_back
#define PF emplace_front
#define FILL(a,b) memset(a,b,sizeof(a))
#define lwb lower_bound
#define upb upper_bound
#define lc (x<<1)
#define rc ((x<<1)|1)
using namespace std;
V<int> v[200005];
V<P<int,int> > g[200005];
int d[200005],ma[200005],it[200005],pl[200005];
void dfs(int x,int y){
for(auto u:v[x])if(u!=y)g[x].PB(MP(pl[u],u));
sort(ALL(g[x]));
ma[x]=d[x]+it[x];
for(auto u:g[x])if(u.S!=y){
it[u.S]=ma[x]+1-d[x];
d[u.S]=d[x]+1;
dfs(u.S,x);
gmax(ma[x],ma[u.S]);
}
}
int siz[200005],in[200005];
int n;
void get(int x,int y){
siz[x]=1;pl[x]=0;
for(auto u:v[x])if(u!=y){
d[u]=d[x]+1;
get(u,x);
gmax(pl[x],pl[u]);
siz[x]+=siz[u];
gmax(in[x],siz[u]);
}
pl[x]++;
gmax(in[x],n-siz[x]);
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin>>n;
FOR(i,2,n){
int x,y;
cin>>x>>y;
v[x].PB(y);
v[y].PB(x);
}
get(1,-1);
int st=1;
FOR(i,2,n){
if(d[i]>d[st])st=i;
}
get(st,-1);
it[st]=1;
dfs(st,-1);
FOR(i,1,n)cout<<it[i]<<' ';
RE 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define deb(k) cerr << #k << ": " << k << "\n";
#define size(a) (int)a.size()
#define fastcin cin.tie(0)->sync_with_stdio(0);
#define st first
#define nd second
#define pb push_back
#define mk make_pair
#define int long long
typedef long double ldbl;
typedef double dbl;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef map<int, int> mii;
typedef vector<int> vint;
#define MAXN 300100
#define MAXLG 20
const int inf = 0x3f3f3f3f;
const ll mod = 1000000007;
const ll linf = 0x3f3f3f3f3f3f3f3f;
const int N = 300100;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int x[200], y[200];
int n;
vector<int>g[200];
double dist[200][200];
bool vis[210];
void dfs(int x){
vis[x] = 1;
for(auto v : g[x]){
if(!vis[v]) dfs(v);
}
}
bool check(double mid){
for(int i=0;i<=n+1;i++) g[i].clear(), vis[i] = 0;
for(int i=0;i<=n+1;i++){
for(int j=i+1;j<=n+1;j++){
if( dist[i][j] < 2*mid + 1e-7){
g[i].pb(j);
g[j].pb(i);
}
}
}
dfs(0);
if(vis[n+1]) return false;
return true;
}
void solve(){
cin>>n;
for(int i=1;i<=n;i++) cin>>x[i]>>y[i];
for(int i=1;i<=n;i++){
dist[i][i] = 0;
for(int j=i+1;j<=n;j++){
dist[i][j] = sqrt(1.0*((x[i] - x[j])*(x[i] - x[j]) + (y[i] - y[j])*(y[i] - y[j])) );
dist[j][i] = dist[i][j];
}
dist[0][i] = y[i] + 100;
dist[i][0] = dist[0][i];
dist[n+1][i] = 100 - y[i];
dist[i][n+1] = dist[n+1][i];
}
dist[0][n+1] = 200;
dist[n+1][0] = 200;
double l = 0, r = 100;
while(r - l > 1e-9){
double mid = (l + r)/2;
if(check(mid)) l = mid;
else r = mid;
}
cout<<setprecision(9);
cout<<l<<"\n";
// Have you read the problem again?
// Maybe you understood the wrong problem
}
int32_t main(){
fastcin;
int t_ = 1;
//cin>>t_;
while(t_--)
solve();
return 0;
}
| //! 尺卂乃卂.卂フ乇乇ㄒ
#include<bits/stdc++.h>
//#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
//Using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> Ordered_set;
#define ll long long
#define int long long
#define ld long double
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<vi>
#define vip vector<pii>
#define mii map<int,int>
#define mip map<pair<int,int>,int>
#define mic map<char,int>
#define all(v) v.begin(),v.end()
#define pqb priority_queue<int>
#define pqs priority_queue<int,vi,greater<int> >
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define lb(x) (x&(-x))
#define mod 1000000007
#define inf 1e18
#define ps(x,y) fixed<<setprecision(y)<<x
#define w(x) int x; cin>>x; while(x--)
#define itr(it,v) for(auto it:v)
#define show(arr,n) for(int i=0;i<n;i++) cout<<arr[i]<<" "; cout<<"\n";
#define fi(i,n) for(int i=0;i<n;i++)
#define fir(i,k,n) for(int i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ff first
#define ss second
#define deb(x) cout << #x << "=" << x << endl
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define check(x) (x && cout<<"Yes\n")||(cout<<"No\n");
#define fin(s) freopen(s,"r",stdin);
#define fout(s) freopen(s,"w",stdout);
const ld pi = 3.141592653589793238462643383279502884;
const int xd[]={-1,0,1,0};
const int yd[]={0,-1,0,1};
int XX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int YY[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
int expo(int a,int b,int m);
int mmi(int a,int m);
void ipgraph(int m);
const int N=5*(1e5)+10;
vii adj(N);
int a[N];
void solve(){
}
int32_t main()
{
FIO
string x; cin>>x;
int i=0;
while(i<x.length() && x[i]!='.') cout<<x[i],i++; cout<<"\n";
return 0;
}
void ipgraph(int m){
int i, u, v;
while(m--){
cin>>u>>v;
u--, v--;
adj[u].pb(v);
adj[v].pb(u);
}
}
int expo(int a,int b,int m){
if(b==0) return 1;
if(b==1) return a;
int val=(expo(a,b/2,m)*expo(a,b/2,m))%m;
if(b & 1) return (val*a)%m;
else return val;
}
int mmi(int a,int m){
return expo(a,m-2,m);
} |
/***************************************************************
File name: D.cpp
Author: ljfcnyali
Create time: 2021年02月21日 星期日 21时00分33秒
***************************************************************/
#include<bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for ( int i = (a), _end_ = (b); i <= _end_; ++ i )
#define mem(a) memset ( (a), 0, sizeof ( a ) )
#define str(a) strlen ( a )
#define pii pair<int, int>
#define int long long
typedef long long LL;
const int maxn = 1e5 + 10;
const int Mod = 998244353;
int n, m, k, ans;
inline int power(int a, int b) { int r = 1; while ( b ) { if ( b & 1 ) r = r * a % Mod; a = a * a % Mod; b >>= 1; } return r; }
signed main()
{
scanf("%lld%lld%lld", &n, &m, &k);
if ( n == 1 || m == 1 )
{
printf("%lld\n", power(k, n + m - 1));
return 0;
}
REP(i, 1, k) ans = (ans + (power(i, n) - power(i - 1, n)) * power(k - i + 1, m)) % Mod;
printf("%lld\n", (ans + Mod) % Mod);
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
struct{template<class T>constexpr operator T(){return numeric_limits<T>::max();}constexpr auto operator-();}inf;
struct{template<class T>constexpr operator T(){return numeric_limits<T>::lowest();}constexpr auto operator-();}negative_inf;
constexpr auto decltype(inf)::operator-(){return negative_inf;}
constexpr auto decltype(negative_inf)::operator-(){return inf;}
#define swap(a,b) {a^=b;b^=a;a^=b;}
#define rep(i,n) for(long long i = 0; i < n; i++)
#define reps(i,s,n) for(long long i = (s); i < n; i++)
#define repr(i,n) for(long long i = (n - 1); i >= 0; i--)
#define LOOP for(long long i = 0;;i++)
#define PB push_back
#define ALL(v) v.begin(),v.end()
#define DOUBLE fixed << setprecision(15)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<double> vd;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<vd> vvd;
typedef vector<vc> vvc;
typedef vector<vb> vvb;
typedef pair<ll,ll> P;
typedef vector<P> vP;
#define F first
#define S second
#define SPC << " "
ll gcd(ll x,ll y){if(x<=0||y<=0)return 0;if(y>x){swap(x,y);}return x%y==0?y:gcd(y,x%y);}
ll lcm(ll x,ll y){return x*y/gcd(x,y);}
ll factrial(int x){return x<=1?1:x*factrial(x-1);}
ll nPr(ll n,ll r){ll a=1;rep(i,n-r)a*=(n-i);return a;}
ll nCr(ll n,ll r){ll a=1;rep(i,r){a*=(n-i);a/=(i+1);}return a;}
vP factor(ll n){vP r;if(n<=1)return{};ll m=pow(n,0.5)+1;reps(i,2,m){if(n%i==0){ll c=0;
while(n%i==0){c++;n/=i;}r.PB({i,c});}if(n<=1)break;}if(n>1)r.PB({n,1});return r;}
bool mycmp(P &a, P &b){
return a.F < b.F;
}
bool mycmp2(pair<ll,P> &a, pair<ll,P> &b){
return a.F > b.F;
}
int main(){
ll n;
cin >> n;
vP px(n), py(n);
rep(i,n){
cin >> px[i].F >> py[i].F;
px[i].S = i;
py[i].S = i;
}
sort(ALL(px), mycmp);
sort(ALL(py), mycmp);
ll dx, dy, dx0, dxn, dy0, dyn;
dx = px[n-1].F - px[0].F;
dy = py[n-1].F - py[0].F;
dx0 = px[n-1].F - px[1].F;
dxn = px[n-2].F - px[0].F;
dy0 = py[n-1].F - py[1].F;
dyn = py[n-2].F - py[0].F;
if(px[0].S == py[0].S && px[n-1].S == py[n-1].S){
cout << max(max(dx0,dxn), max(dy0,dyn)) << endl;
}else{
vll d = {dx, dx0, dxn, dy, dy0, dyn};
sort(ALL(d));
cout << d[4] << endl;
}
} |
//* Jai shree Ram
#include <bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define lli long long int
#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define vi vector<int>
#define vll vector<ll>
#define all(a) a.begin(),a.end()
#define sz(a) (int)a.size()
#define pb push_back
#define ppb pop_back
#define pf push_front
#define fr first
#define sc second
#define uniq(v) (v).erase(unique(all(v)),(v).end())
using namespace std;
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
template<typename T,typename T1>T amax(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T amin(T &a,T1 b){if(b<a)a=b;return a;}
// __builtin_popcountll(x);
// __builtin_clz(x) // Count Leading zeros
// __builtin_ctz(x) // Trailing zeros
const int MM = 998244353;
const int mod = 1e9 + 7;
const int INF = 1e9 + 5;
const int N = 1e5 + 5;
/* stuff you should look for
* make sure to read the bottom part of question
* special cases (n=1?)
* In Game Theory Check your solution and consider all the solutions
*/
void solve()
{
int a,b,c;
cin >> a >> b >> c;
cout << (21 - (a+b+c)) << "\n";
}
signed main()
{
IOS;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
int t;
t=1;
// cin>>t;
while(t--)
{
solve();
}
}
| #include<bits/stdc++.h>
using namespace std;
int main(){
int a, b, c;
cin >> a;
cin >> b;
cin >> c;
int d = 21 - (a+b+c);
cout << d;
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
int main(){
int arr[4],sum=0;
for(int i=0;i<3;i++){
cin>>arr[i];
int x=arr[i];
if(x==1) sum+=6;
else if(x==2) sum+=5;
else if(x==3) sum+=4;
else if(x==4) sum+=3;
else if(x==5) sum+=2;
else if(x==6) sum+=1;
}
cout<<sum;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define eb emplace_back
#define ii pair<int, int>
#define OK (cerr << "OK" << endl)
#define debug(x) cerr << #x " = " << (x) << endl
#define ff first
#define ss second
#define int long long
#define tt tuple<int, int, int>
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vii vector<pair<int, int>>
#define vvi vector<vector<int>>
#define vvii vector<vector<pair<int, int>>>
#define Mat(n, m, v) vector<vector<int>>(n, vector<int>(m, v))
#define endl '\n'
constexpr int INF = (sizeof(int) == 4 ? 1e9 : 2e18) + 1e5;
constexpr int MOD = 1e9 + 7;
constexpr int MAXN = 2e5 + 3;
vi arr;
int dp[MAXN][3];
int f(int idx, int val) {
if (idx == arr.size())
return (val == 1);
int &ret = dp[idx][val];
if (~ret)
return ret;
ret = 0;
if (arr[idx]) {
// AND
ret += f(idx + 1, val & 0);
ret += f(idx + 1, val & 1);
} else {
// OR
ret += f(idx + 1, val | 0);
ret += f(idx + 1, val | 1);
}
return ret;
}
// #define MULTIPLE_TEST_CASES
void solve() {
memset(dp, -1, sizeof dp);
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
string s;
cin >> s;
arr.eb(s.front() == 'A' ? 1 : 0);
}
cout << f(0, 0) + f(0, 1) << endl;
}
signed main() {
// const string FILE_NAME = "";
// freopen((FILE_NAME + string(".in")).c_str(), "r", stdin);
// freopen((FILE_NAME + string(".out")).c_str(), "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
int t = 1;
#ifdef MULTIPLE_TEST_CASES
cin >> t;
#endif
while (t--)
solve();
} |
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#define lli long long int
#define loop(i,x,n) for(int i=x;i<n;i++)
#define loopr(i,x,n) for(int i=n-1;i>=x;i--)
#define st set<lli>
#define v vector<lli>
#define um unordered_map<lli,lli>
#define vpl vector<pair<lli,lli>>
#define llu long long unsigned
#define ms multiset<int,greater<int>>
#define ums unordered_map<string,lli>
#define pb push_back
#define time ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout.setf(ios::fixed); cout.setf(ios::showpoint);
#define test lli t; cin>>t; while(t--)
using namespace std;
int main()
{
time
// test
{
int a,b,c;
cin>>a>>b>>c;
if(a==b) cout<<c;
else if(a==c) cout<<b;
else if(b==c) cout<<a;
else cout<<0;
}
return 0;
}
| /* これを翻訳している間、あなたはあなたの人生のいくつかの貴重な瞬間を無駄にしました */
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define S(x) (int)(x).size()
#define L(x) (int)(x).length()
#define ld long double
#define mem(x,y) memset(x,y,sizeof x)
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int , null_type , less<int> , rb_tree_tag , tree_order_statistics_node_update> ordered_set;
const int mod = 1e9+7;
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;
void solve()
{
int a,b,c;
cin>>a>>b>>c;
if(a==b) cout<<c<<'\n';
else if(b==c) cout<<a<<'\n';
else if(c==a) cout<<b<<'\n';
else cout<<0<<'\n';
}
int main()
{
IOS
int t=1;
//cin>>t;
while(t--)
{
solve();
}
}
|
#include <bits/stdc++.h>
using namespace std;
static const bool LOCAL_TEST = false;
vector<vector<int>> h(30, vector<int>(30, 5000));
vector<vector<int>> v(30, vector<int>(30, 5000));
int si, sj, ti, tj;
int b, result;
double a, e;
int prev_result;
double score;
string path;
void read_h_v()
{
for (int i = 0; i < 30; ++i)
for (int j = 0; j < 29; ++j)
cin >> h.at(i).at(j);
for (int i = 0; i < 29; ++i)
for (int j = 0; j < 30; ++j)
cin >> v.at(i).at(j);
}
void read_s_t_a_e()
{
cin >> si >> sj >> ti >> tj;
cin >> a >> e;
}
void read_s_t()
{
cin >> si >> sj >> ti >> tj;
}
void read_result()
{
cin >> result;
}
int compute_path_length(int x, int y, char ch)
{
if (ch == 'L' || ch == 'R')
return h.at(y).at(x);
return v.at(y).at(x);
}
int compute_total_path_length(string path)
{
int x = sj;
int y = si;
int len = 0;
for (char ch : path)
{
if (ch == 'L') --x;
if (ch == 'R') ++x;
if (ch == 'D') ++y;
if (ch == 'U') --y;
len += compute_path_length(x, y, ch);
}
return len;
}
void set_avg_path_length(string path, int result, int k)
{
size_t len = path.size();
int average = result + (len - 1) / len;
int x = sj, y = si;
for (char ch : path)
{
if (ch == 'L') --x;
if (ch == 'R') ++x;
if (ch == 'D') ++y;
if (ch == 'U') --y;
if (ch == 'L' || ch == 'R')
if (k < 200)
h.at(y).at(x) = min(h.at(y).at(x), average);
else
h.at(y).at(x) = (h.at(y).at(x) + average) / 2;
else
if (k < 200)
v.at(y).at(x) = min(v.at(y).at(x), average);
else
v.at(y).at(x) = (v.at(y).at(x) + average) / 2;
}
}
string query(int prev_result)
{
string ver = "", hor = "";
int x = ti - si;
for (int i = 0; i < x; ++i) ver += "D";
for (int i = 0; x < i; --i) ver += "U";
int y = tj - sj;
for (int i = 0; i < y; ++i) hor += "R";
for (int i = 0; y < i; --i) hor += "L";
x = sj, y = si;
string answer = "";
while (ver.size() && hor.size())
{
char s1 = ver.back(), s2 = hor.back();
int x1 = x + (s2 == 'R' ? 1 : -1);
int y1 = y + (s1 == 'D' ? 1 : -1);
int b1 = compute_path_length(x, y1, s1);
int b2 = compute_path_length(x1, y, s2);
char ch;
if (b1 < b2)
{
ch = s1;
ver.pop_back();
}
else if (b2 < b1)
{
ch = s2;
hor.pop_back();
}
else
{
if (ver.size() < hor.size())
{
ch = s2;
hor.pop_back();
}
else
{
ch = s1;
ver.pop_back();
}
}
answer += ch;
if (ch == 'L') --x;
if (ch == 'R') ++x;
if (ch == 'D') ++y;
if (ch == 'U') --y;
}
answer = answer + ver + hor;
return answer;
}
int main()
{
if (LOCAL_TEST)
{
read_h_v();
}
prev_result = 0;
score = 0.0;
for (int k = 0; k < 1000; ++k)
{
if (LOCAL_TEST)
read_s_t_a_e();
else
read_s_t();
path = query(prev_result);
cout << path << endl;
if (LOCAL_TEST)
{
b = compute_total_path_length(path);
score = score * 0.998 + a / b;
prev_result = round(b * e);
}
else
{
read_result();
prev_result = result;
set_avg_path_length(path, prev_result, k);
}
}
if (LOCAL_TEST)
{
cout << setprecision(32) << round(2312311 * score) << endl;
}
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define rrep(i, a, b) for(int i=a; i >=b; i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(), (x).end()
using namespace std;
void _main(); int main() {cin.tie(0); ios::sync_with_stdio(false); _main();}
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1;} return 0;}
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1;} return 0;}
string S1, S2, S3;
#define NOANS "UNSOLVABLE"
vector<char> chars;
char used[10];
bool check() {
map<char, char> mapping;
rep(i, 0, 10) {
if (used[i] != 0) {
mapping[used[i]] = char('0' + i);
}
}
string SS1, SS2, SS3;
fore(c, S1) {
SS1 += mapping[c];
}
fore(c, S2) {
SS2 += mapping[c];
}
fore(c, S3) {
SS3 += mapping[c];
}
if (to_string(stoll(SS1)) != SS1) return false;
if (to_string(stoll(SS2)) != SS2) return false;
if (to_string(stoll(SS3)) != SS3) return false;
if(stoll(SS1) + stoll(SS2) != stoll(SS3)) return false;
if(stoll(SS1) == 0) return false;
if(stoll(SS2) == 0) return false;
if(stoll(SS3) == 0) return false;
cout << SS1 << endl;
cout << SS2 << endl;
cout << SS3 << endl;
return true;
}
bool dfs(int cu) {
if (cu == chars.size()) return check();
rep(i, 0, 10) {
if(used[i] == 0) {
used[i] = chars[cu];
if (dfs(cu+1)) return true;
used[i] = 0;
}
}
return false;
}
void _main() {
cin >> S1 >> S2 >> S3;
fore(c, S1) chars.push_back(c);
fore(c, S2) chars.push_back(c);
fore(c, S3) chars.push_back(c);
sort(all(chars));
chars.erase(unique(all(chars)), chars.end());
if (10 < chars.size()) {
cout << NOANS << endl;
return;
}
bool res = dfs(0);
if(res == false) {
cout << NOANS << endl;
}
} |
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define ff first
#define ss second
#define mod 1000000007
#define ull unsigned long long
#define vll vector<ll>
#define uom unordered_map
#define uos unordered_set
#define pll pair<ll, ll>
#define INF 9223372036854775807
#define w(t) ll tests; cin>>tests; while(tests--)
#define endl "\n"
#define pb(x) push_back(x)
#define ppb() pop_back()
#define all(x) x.begin(), x.end()
#define mp(a, b) make_pair(a, b)
#define setp(x, y) fixed << setprecision(x) << y
#define f(i, a, b) for(ll i = a ; i < b ; i++)
#define fo(j, a, b) for(ll j = a ; j >= b ; j--)
#define fill(a, n, x) f(i, 0, n) a[i]=x;
using namespace std;
void init() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
int main() {
init();
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll n;
cin >> n;
ll a[200] = {0};
f(i, 0, n)
{
ll x;
cin >> x;
a[x % 200]++;
}
ll ans = 0;
f(i, 0, 200)
ans += a[i] * (a[i] - 1) / 2;
cout << ans;
return 0;
} | #include "bits/stdc++.h"
using namespace std;
typedef pair<int,int>pii;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef __int128 lll;
typedef vector<int> vi;
typedef vector<ll> vl;
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
const ll inf=0x3f3f3f3f3f3f3f3f;
const int mn=101;
const ll mod=998244353;
string g[mn];
bool vis[mn];
int n;
void dfs(int x){
vis[x]=1;
for(int y=0;y<n;y++)if(!vis[y]&&g[y][x]=='1'){
dfs(y);
}
}
int main(){
#ifdef LOCAL
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
freopen("error.txt","w",stderr);
#endif
cin.tie(0);
cin.sync_with_stdio(0);
cin>>n;
for(int i=0;i<n;i++)cin>>g[i];
double ans=0;
for(int i=0;i<n;i++){
memset(vis,0,sizeof(vis));
dfs(i);
int num=0;
for(int j=0;j<n;j++)num+=vis[j];
//cerr<<num<<endl;
ans+=1./num;
}
printf("%.20lf\n",ans);
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(a) a.begin(),a.end()
typedef pair<ll,ll> pi;
//__builtin_popcountll(2) (the number of ones in the binary representation)
//__builtin_clz(2) (number of leading zeroes)
//__builtin_ctz(2) (number of trailing zeroes)
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>*/
// s.find_by_order(k)(returns iterator to kth element), s.order_of_key(k)(number of elements less than number)
ll mod = 1e9+7;
vector<ll> fact(1);
/*vector<ll> spf(10000005), cntPrime(10000005);
void spff(){
int i;
for(i=1;i<10000005;i++) spf[i] = i;
for(i=2;i*i<10000005;i++)
{
if(spf[i] != i) continue;
for(int j = i*i; j < 10000005; j+= i){
if(spf[j]==j) spf[j] = i;
}
}
for(i=1;i<10000005;i++){
if(spf[i] != spf[i/spf[i]]){
cntPrime[i] = cntPrime[i/spf[i]]+1;
}
else cntPrime[i] = cntPrime[i/spf[i]];
}
}
while(spf[a[i]]!=a[i]){
z=spf[a[i]];
while(a[i]%z==0) a[i]/=z;
m[z]++;
}
if(a[i]>1) m[a[i]]++;*/
ll gcd(ll a, ll b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
ll power(ll x, ll y)
{
ll temp;
if( y == 0)
return 1;
temp = power(x, y/2);
if (y%2 == 0)
return temp*temp;
else
return x*temp*temp;
}
ll power(ll x, ll y, ll p)
{
ll res = 1;
x = x % p;
while (y > 0) {
if (y & 1) res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
ll modInv(ll n, ll p)
{
return power(n, p - 2, p);
}
ll ncr(ll n, ll r) {return (n>=r?(fact[n]*modInv(fact[r],mod))%mod*modInv(fact[n-r],mod)%mod:0);}
ll add(ll a, ll b) {ll z=a+b; if(z>=mod) z -= mod; return z;}
ll sub(ll a, ll b) { return (a-b+mod)%mod;}
// LLONG_MAX
vector<pi> v[105];
vector<ll> dp((1<<18), -1);
ll n;
ll solve(ll mask){
ll z=0, cnt = __builtin_popcountll(mask);
if(cnt==0) return 1;
if(dp[mask] != -1) return dp[mask];
for(auto i: v[cnt]){
ll pre = mask%(1<<i.fi);
pre = __builtin_popcountll(pre);
if(pre > i.se) return 0;
}
for(ll i=0;i<n;i++){
if(mask&(1<<i)){
z += solve(mask^(1<<i));
}
}
return dp[mask] = z;
}
int main()
{
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
ll t=1,i,j,m,x,y,z;
//cin>>t;
//fact[0]=1;
//for(i=1;i<300003;i++)fact[i]=(fact[i-1]*i)%mod;
while(t--)
{
cin>>n>>m;
for(i=0;i<m;i++){
cin>>x>>y>>z;
v[x].pb(mp(y,z));
}
cout<<solve((1<<n)-1);
}
}
| #include<bits/stdc++.h>
using namespace std;
const int N=20;
int n,m,s[N],g[N][N];
long long dp[N][1<<N];
int main()
{
cin>>n>>m;
memset(g,0x3f,sizeof g);
//前x个 最多有z个小于等于y
//y-1 映射到二进制的0 ~ n-1
for(int i=1,x,y,z; i<=m; ++i)
cin>>x>>y>>z,--y,g[x][y]=min(g[x][y],z);
dp[0][0]=1;
for(int i=0; i<n; ++i)
for(int s=0; s<1<<n; ++s)
{
long long v=dp[i][s];
if(!v)
continue;
for(int j=0; j<n; ++j)
if(!(s>>j&1))//如果第j个数没用过
{
int t=s|1<<j;//用过之后的状态
bool ok=1;
for(int k=0,s=0; k<n; ++k)
{
if((t>>k&1))
++s;
//
if(s>g[i+1][k])
ok=0;
}
if(ok)
dp[i+1][t]+=v;
}
}
printf("%lld\n",dp[n][(1<<n)-1]);
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<
#define sz(x) ((int) x.size())
#define pb(x) push_back(x)
#define TRACE(x) cerr << #x << " = " << x << endl
typedef long long ll;
typedef pair<int, int> point;
const int mod = 1e9 + 7;
int add(int x, int y) {x += y; if(x >= mod) return x - mod; return x;}
int sub(int x, int y) {x -= y; if(x < 0) return x + mod; return x;}
int mul(int x, int y) {return (ll) x * y % mod;}
const int MAXN = 105;
int n, k, m;
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n >> k >> m;
int sum = 0;
REP(i, n - 1){
int x; cin >> x;
sum += x;
}
if(sum / n >= m)
cout << 0;
else if((sum + k) / n < m)
cout << -1;
else
cout << m * n - sum;
}
| #pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000000
#define endl "\n"
#define PI 3.14159265358979323846264338327950288
using namespace std ;
using bigint = long long int ;
using vi = vector<int> ;
using vll = vector<long long int> ;
int main(){
FAST_IO ;
int N , K , M ; cin >> N >> K >> M ;
int sum = 0 ;
for( int i = 0 ; i < N - 1 ; i++ ){
int x ; cin >> x ;
sum += x ;
}
int ans = N * M - sum ;
// cout << ans << endl ;
if( ans > K ){
cout << "-1" << endl ;
return 0 ;
}
cout << max( 0 ,ans ) << endl ;
return 0 ;
}
|
//*
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
//*/
#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
#define int ll
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
void YES(bool t=true) {cout<<(t?"YES":"NO")<<endl;}
void Yes(bool t=true) {cout<<(t?"Yes":"No")<<endl;}
void yes(bool t=true) {cout<<(t?"yes":"no")<<endl;}
void NO(bool t=true) {cout<<(t?"NO":"YES")<<endl;}
void No(bool t=true) {cout<<(t?"No":"Yes")<<endl;}
void no(bool t=true) {cout<<(t?"no":"yes")<<endl;}
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; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
// int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {0, 1, 0, -1}, dy = {-1, 0, 1, 0};
vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
// const ll MOD = 1000000007;
const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'
signed main() {
fio();
int n;
cin >> n;
vi p(n);
vi pos(n);
rep (i, n) {
cin >> p[i];
p[i]--;
pos[p[i]] = i;
}
set<int> st;
vi ans;
rep (x, n) {
while (pos[x] != x) {
int i = pos[x];
int j = i - 1;
if (st.count(j)) {
cout << -1 << endl;
return 0;
}
ans.push_back(j);
st.insert(j);
swap(p[j], p[i]);
pos[p[j]] = j;
pos[p[i]] = i;
}
}
if (st.size() != n - 1) {
cout << -1 << endl;
return 0;
}
rep (i, ans.size()) {
cout << ans[i] + 1 << endl;
}
} | #include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
int p[n+1];
for(int i=1;i<=n;i++){
cin >> p[i];
}
int dis[n];
int dissum=0;
int absdissum=0;
for(int i=1;i<=n;i++){
dis[i]=p[i]-i;
if(dis[i]==0){
printf("-1");
return 0;
}
dissum+=dis[i];
absdissum+=abs(dis[i]);
}
if(dissum!=0 || absdissum!=2*n-2){
printf("-1");
return 0;
}
for(int i=1;i<=n;i++){
if(dis[i]<0){
for(int j=1;j<=abs(dis[i]);j++){
cout << i-j << endl ;
}
}
}
return 0;
} |
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
//const int mod= int(1e9)+7;
const int mod=998244353;
using P = pair<int,int>;
using Pl= pair<ll,ll>;
using ld=long double;
using V=vector<int>;
using Vl=vector<ll>;
using VV=vector<vector<int>>;
using VVl=vector<vector<ll>>;
ld d(P a, P b){
return sqrt((a.first-b.first)*(a.first-b.first)+(a.second-b.second)*(a.second-b.second));
}
struct UnionFind{
vector<int> d;
UnionFind(int n=0):d(n,-1){}
int root(int x){
if(d[x]<0)return x;
return d[x]=root(d[x]);
}
bool unite(int x,int y){
x=root(x);y=root(y);
if(x==y)return false;
if(d[x]>d[y])swap(x,y);
d[x]+=d[y];
d[y]=x;
return true;
}
bool same(int x,int y){return root(x)==root(y);}
int usize(int x){return -d[root(x)];}
};
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;cin >>n;
UnionFind uni(n+2);
vector<P>pos(n);
for (int i = 0; i < n; ++i) {
cin >>pos[i].first>>pos[i].second;
}
vector<pair<ld,P>>g;
for (int i = 0; i < n; ++i) {
g.push_back({100-pos[i].second,{0,i+2}});
g.push_back({pos[i].second+100,{1,i+2}});
}
for (int i = 0; i < n; ++i) {
for (int j =i+1; j <n; ++j) {
g.push_back({d(pos[i],pos[j]),{i+2,j+2}});
}
}
sort(all(g));
int m=g.size();
ld r=0;
for(auto e:g){
ld dd=e.first;
r=dd/2;
uni.unite(e.second.first,e.second.second);
if(uni.same(0,1))break;
}
cout <<setprecision(20)<<r<<"\n";
return 0;
} | #include<bits/stdc++.h>
using namespace std;
int main() {
int N;
int ans=0, tmp, maxa=0, maxb=0, maxc=0, maxd=0, maxe=0, ai, bi, ci, di, ei;
cin >> N;
vector<int> a(N), b(N), c(N), d(N), e(N), m(5);
for(int i=0; i<N; i++){
cin >> a[i] >> b[i] >> c[i] >> d[i] >> e[i];
if(maxa < a[i]){
maxa = a[i];
m[0] = i;
}
if(maxb < b[i]){
maxb = b[i];
m[1] = i;
}
if(maxc < c[i]){
maxc = c[i];
m[2] = i;
}
if(maxd < d[i]){
maxd = d[i];
m[3] = i;
}
if(maxe < e[i]){
maxe = e[i];
m[4] = i;
}
}
for(int i=0; i<N; i++){
for(int j=i+1; j<N; j++){
for(int k=0; k<5; k++){
maxa = max(max(a[i], a[j]), a[m[k]]);
maxb = max(max(b[i], b[j]), b[m[k]]);
maxc = max(max(c[i], c[j]), c[m[k]]);
maxd = max(max(d[i], d[j]), d[m[k]]);
maxe = max(max(e[i], e[j]), e[m[k]]);
tmp = min(min(min(min(maxa, maxb), maxc), maxd), maxe);
ans = max(ans, tmp);
}
}
}
// for(int i=0; i<N; i++){
// if(a[i]<=ans || b[i]<=ans ||c[i]<=ans ||d[i]<=ans ||e[i]<=ans )
// continue;
// for(int j=i+1; j<N; j++){
// if(a[j]<=ans || b[j]<=ans ||c[j]<=ans ||d[j]<=ans ||e[j]<=ans )
// continue;
// for(int k=j+1; k<N; k++){
// if(a[k]<=ans || b[k]<=ans ||c[k]<=ans ||d[k]<=ans ||e[k]<=ans )
// continue;
// maxa = max(max(a[i], a[j]), a[k]);
// maxb = max(max(b[i], b[j]), b[k]);
// maxc = max(max(c[i], c[j]), c[k]);
// maxd = max(max(d[i], d[j]), d[k]);
// maxe = max(max(e[i], e[j]), e[k]);
// tmp = min(min(min(min(maxa, maxb), maxc), maxd), maxe);
// ans = max(ans, tmp);
// }
// }
// }
cout << ans << endl;
}
|
#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 pil pair<int,ll>
#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 200005
#define m 61
#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;
ll res[m];
ll c[N][m][2];
vector<pil>ed[N];
void dfs(int u,int pa){
for(int i=0;i<m;i++)c[u][i][0]=1;
for(pil p:ed[u]){
int v=p.fi;
ll w=p.se;
if(pa==v)continue;
dfs(v,u);
for(ll i=0;i<m;i++){
if((w>>i)&1){
mad(res[i],c[v][i][0]*c[u][i][0]);
mad(res[i],c[v][i][1]*c[u][i][1]);
mad(c[u][i][0],c[v][i][1]);
mad(c[u][i][1],c[v][i][0]);
}
else{
mad(res[i],c[v][i][0]*c[u][i][1]);
mad(res[i],c[v][i][1]*c[u][i][0]);
mad(c[u][i][0],c[v][i][0]);
mad(c[u][i][1],c[v][i][1]);
}
}
}
}
void solve(){
cin>>n;
for(int i=0;i<n-1;i++){
int u,v;
ll w;
cin>>u>>v>>w;
ed[u].pb(pil(v,w));
ed[v].pb(pil(u,w));
}
dfs(1,0);
ll ans=0;
for(ll i=0;i<m;i++)mad(ans,res[i]*((1ll<<i)%mod));
cout<<ans;
}
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;
using ll = long long;
using pint = pair<ll,ll>;
// #include"debug.hpp"
void calc(vector<ll> A)
{
const ll M = 60;
const ll mod = 1e9 + 7;
ll n = A.size();
vector<ll> dig(M);
for(ll i = 0; i < n; i++) {
ll a = A[i];
for(ll j = 0; j < M; j++) if((1LL<<j) & (a))dig[j]++;
}
ll sum = 0;
for(ll i = 0; i < M; i++) {
ll num = (ll)dig[i] * (n - dig[i]) % mod;
(num *= (1LL<<i) % mod) %= mod;
(sum += num) %= mod;
}
cout << sum << endl;
}
vector<vector<pair<ll,ll>>> tre;
vector<ll> num;
void dfs(ll v, ll par, ll sum) {
num[v] = sum;
for(auto [i, len] : tre[v]) {
if(i == par)continue;
dfs(i, v, sum xor len);
}
}
int main()
{
ll N; cin >> N;
tre.resize(N);
num.resize(N);
for(ll i = 0; i < N - 1; i++) {
ll u, v, k; cin >> u >> v >> k;
u--,v--;
tre[u].push_back({v, k});
tre[v].push_back({u, k});
}
dfs(0, -1, 0);
// print(num);
calc(num);
} |
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
int n, k, m;
cin >> n >> k >> m;
int sm = 0;
rep(i, n - 1) {
int a;
cin >> a;
sm += a;
}
int ans = m * n - sm;
if (ans < 0) ans = 0;
if (ans > k)
cout << -1 << endl;
else
cout << ans << endl;
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
int T;
int extGCD(int a, int b, int &x, int &y)
{
if(b == 0)
{
x = 1;
y = 0;
return a;
}
int ret = extGCD(b, a % b, y, x);
y -= a / b * x;
return ret;
}
int unit(int a, int b)
{
if(a < 0)return 0;
return (a + b - 1) / b;
}
signed main()
{
cin >> T;
rep(_, T)
{
int X, Y, P, Q;
cin >> X >> Y >> P >> Q;
int T1 = 2 * (X + Y), T2 = P + Q;
int ans = -1;
rep(i, Y)rep(j, Q)
{
int x, y;
int c = P + j - X - i;
int d = extGCD(T1, -T2, x, y);
if(d < 0)
{
d = -d;
x = -x;
y = -y;
}
if(c % d != 0)continue;
// cout << T1 << "*" << x << "+" << -T2 << "*" << y << "=" << d << endl;
x *= c / d, y *= c / d;
// cout << T1 << "*" << x << "+" << -T2 << "*" << y << "=" << c << endl;
int t1 = T1 / d, t2 = T2 / d;
if(x < 0 || y < 0)
{
int MAX = max(unit(-x, t2), unit(-y, t1));
// cout << "((" << -x << ", " << t2 << ")" << unit(-x, t2) << ", " << "(" << -y << ", " << t2 << ")" << unit(-y, t1) << ")" << endl;
// cout << "MAX : " << MAX << endl;
x += MAX * t2, y += MAX * t1;
if(ans == -1)ans = x * T1 + i + X;
else ans = min(ans, x * T1 + i + X);
// assert(x * T1 + i + X == y * T2 + P + j);
}
else
{
int MIN = min(x / t2, y / t1);
// cout << "MIN : " << MIN << endl;
x -= MIN * t2, y -= MIN * t1;
if(ans == -1)ans = x * T1 + i + X;
else ans = min(ans, x * T1 + i + X);
// assert(x * T1 + i + X == y * T2 + P + j);
}
}
if(ans == -1)cout << "infinity " << endl;
else cout << ans << endl;
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(int argc, char const *argv[])
{
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
if (c % 2 == 0)
{
if (a < 0)
a = -a;
if (b < 0)
b = -b;
}
if (a == b)
printf("=\n");
if (a > b)
printf(">\n");
if (a < b)
printf("<\n");
return 0;
}
| #include <iostream>
using namespace std;
int hantei(long long n);
int main(){
long long t, n;
cin >> t;
for (int i = 0; i < t; i++){
cin >> n;
if (hantei(n) == -1) cout << "Odd" << endl;
else if (hantei(n) == 0) cout << "Same" << endl;
else if (hantei(n) == 1) cout << "Even" << endl;
}
return 0;
}
int hantei(long long n){
if (n % 2 == 1) return -1;
else if (n % 4 == 0) return 1;
else return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define rng(i, a, b) for (int i = int(a); i < int(b); ++i)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); --i)
#define per(i, b) gnr(i, 0, b)
#define all(obj) begin(obj), end(obj)
#define allr(obj) rbegin(obj), rend(obj)
#define cinv(a) rep(i, (int)a.size()) cin >> a[i]
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<Pi> vp;
typedef vector<vp> vvp;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, 1, 0, -1};
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll LINF = 1e18;
const long double eps = 1e-10;
const char nl = '\n';
ll power(ll a, ll b) { return b ? power(a * a % MOD, b / 2) * (b % 2 ? a : 1) % MOD : 1; }
ll nCk(int n, int k)
{
ll x = 1, y = 1;
for (int i = 1; i <= k; ++i)
{
x = x * (n - i + 1) % MOD;
y = y * i % MOD;
}
return x * power(y, MOD - 2) % MOD;
}
struct UF
{
vi d;
UF(int n) : d(n, -1) {}
int root(int x)
{
if (d[x] < 0)
return x;
return d[x] = root(d[x]);
}
bool unite(int x, int y)
{
x = root(x); y = root(y);
if (x == y) return false;
if (d[x] > d[y]) swap(x, y);
d[x] += d[y];
d[y] = x;
return true;
}
bool same(int x, int y) { return root(x) == root(y); }
int size(int x) { return -d[root(x)]; }
};
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout<<fixed<<setprecision(20);
ll n; cin >> n;
int ans = 2;
for (ll i = 1, k; (k = i*(i+1)/2) < n; ++i)
if ((n-k)%(i+1) == 0) ans += 2;
cout << ans << nl;
}
| #include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define endl "\n"
#define sd(val) scanf("%d", &val)
#define ss(val) scanf("%s", &val)
#define sl(val) scanf("%lld", &val)
#define debug(val) printf("check%d\n", val)
#define all(v) v.begin(), v.end()
#define pb push_back
#define mp make_pair
#define ff first
#define Ss second
#define ll long long
#define ull unsigned long long
#define MOD 1000000007
#define clr(val) memset(val, 0, sizeof(val))
#define what_is(x) cerr << #x << " is " << x << endl;
#define OJ \
freopen("input.txt", "r", stdin); \
freopen("output.txt", "w", stdout);
#define FIO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
int main()
{
ll n;
cin >> n;
while (n % 2 == 0)
{
n /= 2;
}
ll m = sqrt(n), ans = 0;
for (ll i = 1; i <= m; i++)
{
if (n % i == 0)
{
ans += 2;
}
}
if (m * m == n)
ans--;
cout << ans * 2 << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ff first
#define ss second
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repR(i, n) for (int i = n-1; i >= 0; --i)
#define repA(i, a, n) for (int i = a; i <= n; ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define mem1(a) memset(a,-1,sizeof(a))
#define mem0(a) memset(a,0,sizeof(a))
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
#define vi vector<int>
#define vvi vector<vi>
#define vll vector<ll>
#define vvll vector<vll>
#define vs vector<string>
#define vd vector<double>
#define vb vector<bool>
#define vpii vector<pii>
#define vpll vector<pll>
#define vpdd vector<pdd>
#define mod 1000000007
#define ps(x,y) fixed << setprecision(y) << x
#define fastio ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
void solve()
{
string s;
cin >> s;
rep(i, s.length()) {
if (i % 2 == 0) {
if (s[i] < 97 || s[i] > 122) {
cout << "No" << '\n';
return;
}
}
else {
if (s[i] < 65 || s[i] > 90) {
cout << "No" << '\n';
return;
}
}
}
cout << "Yes" << '\n';
}
int main()
{
fastio;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int t = 1;
//cin>>t;
while (t--) solve();
return 0;
} | #include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <unordered_map>
#include <stack>
#include <math.h>
#include <queue>
#include <functional>
#include <iomanip>
using namespace std;
#define ll long long
bool comp(pair<int,int> a, pair<int,int> b){
return a.first<b.first;
}
const int N=1000001;
bool solve(string s){
for(int i=0; i<s.length();i++){
char c= s.at(i);
if(i%2==0){
if(c-tolower(c)!=0) return true;
} else{
if(c-toupper(c)!=0) return true;
}
}
return false;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string s;
cin>>s;
cout<<(solve(s) ? "No":"Yes")<<"\n";
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
int read();
#define LL long long
#define fr(i,l,r) for(int i = (l);i <= (r);++i)
#define rf(i,l,r) for(int i = (l);i >= (r);--i)
#define fo(i,l,r) for(int i = (l);i < (r);++i)
#define foredge(i,u,v) for(int i = fir[u],v;v = to[i],i;i = nxt[i])
#define ci const int &
#define cl const LL &
#define I inline void
#define filein(File) freopen(File".in","r",stdin)
#define fileout(File) freopen(File".out","w",stdout)
const int N = 1e5 + 5,MOD = 1e9 + 7;
int n,a[N];
LL ans = 1;
int main() {
cin >> n;
fr(i,1,n) cin >> a[i];
sort(a+1,a+n+1);
fr(i,1,n) ans = ans * (a[i]-a[i-1]+1) % MOD;
cout << ans << endl;
return 0;
}
const int S = 1 << 21;
char p0[S],*p1,*p2;
#define getchar() (p2 == p1 && (p2 = (p1 = p0) + fread(p0,1,S,stdin)) == p1 ? EOF : *p1++)
inline int read() {
static int x,c,f;x = 0;f = 1;
do c = getchar(),c == '-' && (f = -1);while(!isdigit(c));
do x = x * 10 + (c & 15),c = getchar();while(isdigit(c));
return x * f;
}
| #include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;
const ll INF = 10000000000009;
int main()
{
int n, m;
cin >> n >> m;
ll h[200005], w[200005];
for(int i = 0; i < n; i++) cin >> h[i];
for(int i = 0; i < m; i++) cin >> w[i];
sort(h, h + n);
sort(w, w + m);
ll t[200005];
for(int i = 0; i < n; i++){
int j = lower_bound(w, w + m, h[i]) - w;
t[i] = INF;
if(j < m) t[i] = w[j] - h[i];
if(j > 0) t[i] = min(t[i], h[i] - w[j - 1]);
}
ll l[200005], r[200005];
l[1] = h[1] - h[0];
for(int i = 3; i < n; i += 2) l[i] = l[i - 2] + (h[i] - h[i - 1]);
r[n - 2] = h[n - 1] - h[n - 2];
for(int i = n - 4; i >= 0; i -= 2) r[i] = r[i + 2] + (h[i + 1] - h[i]);
ll ans = INF;
for(int i = 0; i < n; i++){
if(i % 2){
ll s = t[i] + (h[i + 1] - h[i - 1]);
if(i > 1) s += l[i - 2];
if(i < n - 2) s += r[i + 2];
ans = min(ans, s);
}
else{
ll s = t[i];
if(i > 0) s += l[i - 1];
if(i < n - 1) s += r[i + 1];
ans = min(ans, s);
}
}
cout << ans << endl;
}
|
#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 ll long long
#define int ll
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define ff first
#define ss second
#define vi vector<ll>
#define vii vector<vector<ll>>
#define viii vector<vii>
#define vpi vector<pii>
#define mod 1000000007
#define MOD 1000000007
#define full(a) a.begin(),a.end()
#define inf 1e9
#define minf -1e9
#define dd double
#define fori(i,x,n) for(ll i=x;i<=n;i++)
#define umap unordered_map<ll,ll>
#define mmap map<ll,ll>
#define mm 998244353
#define mod2 1000000009
#define br cout<<"\n"
// typedef tree<pii,null_type,less<pii>,rb_tree_tag,
// tree_order_statistics_node_update>PBDS;
ll n;
vi a;
map<pair<pii, ll>, ll>dp;
ll fun(ll i, ll orval, ll xorval) {
if (i == n)return (xorval ^ orval);
if (dp.count({{orval, xorval}, i}))return dp[ {{orval, xorval}, i}];
return dp[ {{orval, xorval}, i}] = min(fun(i + 1, orval | a[i], xorval), fun(i + 1, a[i], xorval ^ orval));
}
int32_t 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;
t = 1;
// cin >> t;
fori(test, 1, t) {
cin >> n;
a.resize(n);
fori(i, 0, n - 1)cin >> a[i];
cout << fun(0, 0, 0);
}
return 0;
} | #include<stdio.h>
#include<queue>
#define INF 1000000000000007
#define int long long
using namespace std;
struct pr{
int now;
int data;
};
int a[25];
queue<pr> q;
signed main(){
int n,ans=INF;
scanf("%lld",&n);
for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
pr x;x.data=0;x.now=1;
q.push(x);
while(!q.empty()){
x=q.front();q.pop();
if(x.now>n){
if(x.data<ans) ans=x.data;
//hello,thank you
continue;
}
int sum=x.data;
int ths=x.now;
int r=0;
for(int i=ths;i<=n;i++){
r|=a[i];
pr y;y.data=sum^r;y.now=i+1;
q.push(y);
}
}
printf("%lld",ans);
return 0;
} |
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
int mod = 1000000007;
int main(void){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int A[3]; rep(i, 3) cin >> A[i];
sort(A, A+3);
if(A[0] == A[1]) cout << A[2] << endl;
else if(A[1] == A[2]) cout << A[0] << endl;
else cout << 0 << endl;
return 0;
} | //----------BHAVIK DIWANI(PICT_COMP)---------------
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define test ll t; cin>>t; while(t--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define ll long long
#define int long long
#define ull unsigned long long
#define MAX 1000005
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define endl '\n'
#define vs vector<string>
#define mii map<int,int>
#define msi map<string,int>
#define vpii vector< pair<int, int > >
#define vpsi vector< pair< string ,int > >
#define forci(p,q) for(int i=p;i<q;i++)
ll gcd(ll a,ll b){ if(b==0) return a; return gcd(b,a%b);}
ll lcm(ll a,ll b) { return (a/gcd(a,b)*b);}
ull power(ull a, ull b) {a %= mod; ull res = 1; while (b > 0) { if (b & 1) res = res * a % mod; a = a * a % mod; b >>= 1; } return res%mod; }
ll modmul(ll x, ll y){return (x*y)%mod;}
ll modadd(ll x, ll y){return (x+y)%mod;}
ll modsub(ll x, ll y){return (x-y+mod)%mod;}
ll fact[1000007]={0};
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<1000007;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[r],mod-2)))%mod; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
inline long long toint(const std::string &s) {std::stringstream ss; ss << s; long long x; ss >> x; return x;}
inline std::string tostring(long long number) {std::stringstream ss; ss << number; return ss.str();}
inline std::string tobin(long long x) {return std::bitset<63>(x).to_string();}
const int inf=1e9;
/*bool prime[MAX];
ull sieve(){memset(prime,true,sizeof(prime));for(ull p=2;p*p<MAX;p++){if(prime[p]==true){for(ull i=2*p;i<MAX;i+=p){prime[i]=false;}}}prime[0]=0;prime[1]=0;
}*/
/*
int inv[1000001]={0};int invf[1000001]={0};
void findinverse(){
inv[0]=1;
inv[1] = 1;
for(int i = 2; i <=1e6 ; ++i)
inv[i] = (mod - (mod/i) * inv[mod%i] % mod) % mod;
invf[0]=1;invf[1]=1;
for(int i=2;i<=1e6;i++){
invf[i]=invf[i-1]*inv[i]%mod;
}
}*/
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> orderedSet;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> orderedMultiset;
int solve()
{
int r1,c1,r2,c2;
cin>>r1>>c1>>r2>>c2;
if(r1==r2 && c1==c2){
cout<<"0"<<endl;
}
else if(r1+c1==r2+c2 || r1-c1==r2-c2 || abs(r1-r2)+abs(c1-c2)<=3){
cout<<"1"<<endl;
}
else if((r1+r2+c1+c2)%2==0 || abs(r1-r2)+abs(c1-c2)<=6 || abs((r1-c1)-(r2-c2))<=3 || abs((r1+c1)-(r2+c2))<=3){
cout<<"2"<<endl;
}
else{
cout<<"3"<<endl;
}
return 0;
}
signed main()
{
fastio;
// test
solve();
}
|
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; } //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; } //最小公倍数
using Graph = vector<vector<int>>;
ll inf=300000000000000000;
const double PI = 3.14159265358979323846;
int main(){
int h,w;
cin >> h >> w;
int k[h][w];
ll p=1000000007;
int u=0;
rep(i,h){
string s;
cin >> s;
rep(j,w){
if(s[j]=='#'){
k[i][j]=1;
}
else{
k[i][j]=0;
u++;
}
}
}
ll o[u+1];
o[0]=1;
rep(i,u)o[i+1]=o[i]*2%p;
ll ans=0;
int hh[h][w];
int ww[h][w];
rep(i,h){
rep(j,w){
//cout << ans << endl;
if(k[i][j]==1)continue;
else{
int cnt=1;
if(i>0){
if(k[i-1][j]==0){
cnt=cnt-1+hh[i-1][j];
hh[i][j]=hh[i-1][j];
}
}
if(cnt==1){
int a=i+1;
while(true){
if(a<0||a>h-1)break;
if(k[a][j]==1)break;
cnt++;
a++;
}
hh[i][j]=cnt;
//if(i==0&&j==1)cout << cnt << endl;
}
if(j>0){
if(k[i][j-1]==0){
cnt=cnt-1+ww[i][j-1];
ww[i][j]=ww[i][j-1];
}
}
if(cnt==hh[i][j]){
int a=j+1;
while(true){
if(a<0||a>w-1)break;
if(k[i][a]==1)break;
cnt++;
a++;
}
ww[i][j]=a-j;
}
//cout << cnt <<" " << o[cnt] << " " << u-cnt << endl;
ans=(ans+(o[cnt]-1)*o[u-cnt])%p;
}
}
}
//rep(i,3)cout << hh[0][i] << endl;
cout << ans << endl;
}
| #include <bits/stdc++.h>
#ifndef M_PI
#define M_PI 3.14159265358979
#endif
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef pair<ll, ll> pll;
typedef pair<int, int> pi;
typedef long double ld;
typedef pair<long double, long double> pld;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
ll bpow(ll a, ll b) {
ll res = 1;
while(b) {
if(b & 1)
res = 1LL * res * a % MOD;
a = 1LL * a * a % MOD;
b >>= 1;
}
return res;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll i, j, k;
ll H, W;
cin >> H >> W;
vector<string> S(H);
for(auto &e : S)
cin >> e;
vector<vll> cv;
vector<vll> ch;
for(i = 0; i < H; i++) {
vll h(W);
ll p = 0;
for(j = 0; j < W; j++) {
if(S[i][j] == '.') {
p++;
} else {
p = 0;
}
h[j] = p;
}
for(j = W - 2; j >= 0; j--) {
if(h[j] > 0 && h[j + 1] > 0) {
h[j] = h[j + 1];
}
}
ch.push_back(h);
}
for(j = 0; j < W; j++) {
vll v(H);
ll p = 0;
for(i = 0; i < H; i++) {
if(S[i][j] == '.') {
p++;
} else {
p = 0;
}
v[i] = p;
}
for(i = H - 2; i >= 0; i--) {
if(v[i] > 0 && v[i + 1] > 0) {
v[i] = v[i + 1];
}
}
cv.push_back(v);
}
for(i = 0; i < H; i++) {
for(j = 0; j < W; j++) {
ch[i][j] += cv[j][i] - 1;
}
}
ll n_e = 0;
for(i = 0; i < H; i++) {
for(j = 0; j < W; j++) {
if(S[i][j] == '.')
n_e++;
}
}
ll n_b = bpow(2, n_e);
ll ans = 0;
for(i = 0; i < H; i++) {
for(j = 0; j < W; j++) {
if(S[i][j] == '#')
continue;
ll sub = n_b;
ll msub = bpow(2, n_e - ch[i][j]);
sub = (sub + MOD - msub) % MOD;
ans = (ans + sub) % MOD;
}
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int mod = 1e9 + 7;
//1.takes nothing returns nothing
//2.takes nothing returns something
//3.takes something returns something
//4.takes something returns nothing
int digi(ll n){
ll f=0;
while(n>0){
n/=10;f++;
}
return f;
}
bool isPrime(int n)
{
if (n <= 1)
return false;
for (int i = 2; i < n; i++)
if (n % i == 0)
return false;
return true;
}
ll Sum(string s)
{
ll count=0;
for(ll i=0;i<(s.size()-1);i++)
{
if(s[i]==s[i+1])
count += 2;
else
count += 1;
}
return count;
}
ll SieveOfEratosthenes(ll n)
{
bool prime[n + 1];
memset(prime, true, sizeof(prime));
for (ll p = 2; p * p <= n; p++)
{
// If prime[p] is not changed,
// then it is a prime
if (prime[p] == true)
{
for (int i = p * p; i <= n; i += p)
prime[i] = false;
}
}
ll f=1;
for (int p = 2; p <= n; p++){
if (prime[p]==true && p*2>n){
f++;//cout<<p<<" ";
}
}
return f;
}
void print(int n){
ll i=0,sum=0;
for(i=0;i<n;i++){
sum+=i;
}
cout<<sum<<" ";
}
//function declaration
//function defining
//function calling
int main() {
ll t;t=1;
while(t--){
ll n,m,i,f=0;cin>>n>>m;ll a[n+5];
if(n==m)
cout<<n<<endl;
else if(n==1&&m==2)
cout<<"0"<<endl;
else if(n==0&&m==1)
cout<<"2"<<endl;
else if(n==2&&m==1)
cout<<"0"<<endl;
else if(n==1&&m==0)
cout<<"2"<<endl;
else if(n==0&&m==2)
cout<<"1"<<endl;
else if(n==2&&m==0)
cout<<"1"<<endl;
}
} | #include<bits/stdc++.h>
#define ll long long int
#define ld long double
using namespace std;
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define endl "\n"
#define maxpq priority_queue<ll>
#define minpq priority_queue<ll, vector<ll>, greater<ll> >
#define vi vector<ll>
#define pii pair<ll, ll>
#define vii vector<pii>
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define INT_MAXI 9000000000000000000
#define INT_MINI -9000000000000000000
ll max(ll a, ll b) {if (a > b) return a; else return b;}
ll min(ll a, ll b) {if (a < b) return a; else return b;}
const int dx[4] = { -1, 1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
int XX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int YY[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
int main()
{
fio;
ll t,i,j,u,v,n,m,x,k,p,c,y;
cin>>x>>y;
ll mini=min(x,y),maxi=max(x,y);
if(mini+3>maxi)
{
cout<<"Yes";
}
else
cout<<"No";
} |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define all(v) v.begin(), v.end()
#define endl "\n"
#define MOD 1e9 + 7
int main()
{
int n, i, j;
cin >> n;
int A[n], B[n];
for (i = 0; i < n; i++)
cin >> A[i];
for (i = 0; i < n; i++)
cin >> B[i];
vector<int> v;
int cnt = 0;
for (i = 1; i <= 1000; i++)
{
int c = 0;
for (j = 0; j < n; j++)
{
if (i <= B[j] && i >= A[j])
c++;
}
if (c == n)
cnt++;
}
cout << cnt << endl;
return 0;
} | #include <bits/stdc++.h>
#define setIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.14159265358979
#define f first
#define s second
#define ar array
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, int> psi;
typedef pair<long long, long long> pll;
typedef pair<char, int> pci;
typedef pair<int, char> pic;
typedef pair<double, double> pdd;
typedef pair<int, string> pis;
int main() { // Ladder: Do 43
setIO;
int a; cin >> a;
int mx = INT_MIN, mn = INT_MAX;
for (int i = 0; i < a; i++) {
int x; cin >> x;
mx = max(mx, x);
}
for (int i = 0; i < a; i++) {
int x; cin >> x;
mn = min(mn, x);
}
if (mn-mx<0) cout << 0;
else cout << mn-mx+1;
} |
#include <bits/stdc++.h>
using namespace std;
char s[4];
int main()
{
cin >> s;
cout << s[1] << s[2] << s[0] << endl;
return 0;
} | #include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>
//#include<atcoder/all>
using namespace std;
//using namespace atcoder;
typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.12f\n", x)
const double pi = acos(-1.0);
const ll MOD = 998244353;
const ll INF = 1e18;
const ll MAX_N = 1010101;
//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX_N; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(ll n, ll k) {
if (n < k) return 0;
if (n < 0 || k < 0) return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// mod.m での a の逆元 a^ { -1 } を計算する
long long modinv(long long a, long long m) {
long long b = m, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b; swap(a, b);
u -= t * v; swap(u, v);
}
u %= m;
if (u < 0) u += m;
return u;
}
//最大公約数
ll gcd(ll x, ll y) {
return y ? gcd(y, x % y) : x;
}
ll lcm(ll x, ll y) {
if (x == 0 || y == 0)return 0;
return (x / gcd(x, y) * y);
}
//union-find木について
//サイズによる更新をしている
ll par[201010];
ll rank2[201010];
void init(ll n) {
rep(i, n) {
par[i] = i;
rank2[i] = 1;
}
}
ll find(ll x) {
if (par[x] == x) {
return x;
}
else {
return par[x] = find(par[x]);
}
}
void unite(ll x, ll y) {
x = find(x);
y = find(y);
if (x == y)return;
if (rank2[x] < rank2[y]) {
par[x] = y;
rank2[y] += rank2[x];
}
else {
par[y] = x;
rank2[x] += rank2[y];
}
}
ll dx[4] = { 1,-1,0,0 };
ll dy[4] = { 0,0,1,-1 };
vector<vector<pair<ll, ll>>>to;
bool flag[101010];
ll dist[101010];
void dfs(ll v) {
flag[v] = true;
for (auto nv : to[v]) {
ll nv2 = nv.first;
ll dist2 = nv.second;
if (flag[nv2] == false) {
dist[nv2] = dist[v] + dist2;
dfs(nv2);
}
}
}
ll c[1010][1010];
ll a[1010], b[1010];
ll dp[201010], dp2[201010];
//long longしか使わない
//素数は1より大きい
//lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
//upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
string s, ans;
cin >> s;
for (ll i = 1;i <= 2;++i)ans += s[i];
ans += s[0];
cout << ans << endl;
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
int main ()
{
long long int n, t, save;
cin >> n;
t= 0;
for(long long int i=1; ; i++)
{
t+= i;
if(t>=n)
{
save= i;
break;
}
}
cout << save << endl;
return 0;
} | /*
@uthor: Amit Kumar
user -->GitHub: drviruses ; CodeChef: dr_virus_ ; Codeforces,AtCoder,Hackerearth,Hakerrank: dr_virus;
*/
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
using namespace std::chrono;
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;
//#define ln mp::cpp_int;
#define int long long
#define double long double
#define uint unsigned long long
#define all(vec) vec.begin(),vec.end()
#define endl "\n"
int google_itr = 1;
#define google(x) cout<<"Case #"<<x<<": "
#define pi 3.14159265358979323846264338327950L
vector<string> vec_splitter(string s) {
s += ',';
vector<string> res;
while(!s.empty()) {
res.push_back(s.substr(0, s.find(',')));
s = s.substr(s.find(',') + 1);
}
return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx,
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
stringstream ss; ss << H;
cerr << args[idx] << " = " << ss.str();
debug_out(args, idx + 1, LINE_NUM, T...);
}
#define XOX
#ifdef XOX
#define deb(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define deb(...) 42
#endif
const int mod = 1e9+7;
const int inf = 1e18;
void virus(){
int n;
cin >> n;
cout << ((n&1) ? "Black" : "White");
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
/*#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif*/
int t = 1;
//cin >> t;
while(t--){
auto start = high_resolution_clock::now();
virus();
auto stop = high_resolution_clock::now();
auto duration = duration_cast<seconds>(stop - start);
//cerr << "\n Time: "<<duration.count()<<endl;
//your code goes here
}
return 0;
} |
#include<bits/stdc++.h>
#include<chrono>
using namespace std;
using namespace chrono;
typedef long long int lli;
typedef long long ll;
lli M=1000000007;
lli mod(lli a) { return ((a%M+M)%M);}
lli add(lli a,lli b) { return mod(mod(a)+mod(b));}
lli multiply(lli a,lli b) { return mod(mod(a)*mod(b));}
lli min(lli a,lli b) { if(a<b) return a; return b;}
lli max(lli a,lli b) { return (a>b)?a:b;}
lli modexpo(lli a,lli b){
lli res = 1;
while(b>0){
if(b&1) res = (res*a)%M;
a = (a*a)%M;
b/=2;
}
return res;
}
void solve(){
ll n;
cin>>n;
n*=2;
ll i=1;
ll ans=0;
while(true && i<n){
if(n%i==0){
ll a=i;
ll b=n/i;
// cout<<a<<":"<<b<<" ";
if(a>b) break;
// if(a==b){
// ll j=2*n-i-1;
// if(j%2==0) ans+=1;
// break;
// }
ll j=(b-i-1);
if(j<0) break;
// ll t=2*n
// cout<<j<<" ";
if(j%2==0) ans+=2;
i++;
}
else if((i*i)>n) break;
else i++;
}
cout<<ans<<"\n";
}
int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r" ,stdin);
// freopen("output.txt", "w" ,stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
// auto start1 = high_resolution_clock::now();
solve();
// int t;
// cin>>t;
// while(t--) solve();
// auto stop1 = high_resolution_clock::now();
// auto duration = duration_cast<microseconds>(stop1 - start1);
// #ifndef ONLINE_JUDGE
// cerr << "Time: " << duration.count() / 1000.0 << endl;
// cout<<duration.count()/1000.0<<endl;
// #endif
return 0;
} | #include <iostream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
using namespace std;
#define fr(i, s, t) for(int (i) = s; (i) <= t; (i)++)
typedef long long ll;
const int MAX_V = 100005;
const int IINF = 0x3f3f3f3f;
double x[MAX_V], h[MAX_V];
int n, m, q;
void solve()
{
string s;
cin>>s;
s += s[0];
s.erase(s.begin());
cout<<s<<'\n';
}
int main(void)
{
int t = 1;
//cin>>t;
while(t--)
solve();
return 0;
} |
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define setIO(x) freopen(x".in", "r", stdin), freopen(x".out", "w", stdout)
#define closefile fclose(stdin), fclose(stdout)
#define m_p make_pair
#define sz(x) (int)x.size()
#define see(x) cerr << x << " "
#define seeln(x) cerr << x << endl
#define out(x) cerr << #x << " = " << x << " "
#define outln(x) cerr << #x << " = " << x << endl
#define outarr(x, l, r) {cerr<< #x"[" << l << " ~ " << r << "] = "; for (int _i = l; _i <= r; ++_i) cerr << x[_i] << " "; cerr << endl;}
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define gc() getchar()
//#define gc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
char buf[1 << 21], *p1 = buf, *p2 = buf;
template <class T> void read(T &x)
{
x = 0; int c = gc(); int flag = 0;
while (c < '0' || c > '9') flag |= (c == '-'), c = gc();
while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) +(c ^ 48), c = gc();
if (flag) x = -x;
}
template <class T> T _max(T a, T b){return b < a ? a : b;}
template <class T> T _min(T a, T b){return a < b ? a : b;}
template <class T> bool checkmax(T &a, T b){return a < b ? a = b, 1 : 0;}
template <class T> bool checkmin(T &a, T b){return b < a ? a = b, 1 : 0;}
const int N = 200005, inf = 0x3f3f3f3f;
int n, k;
vector<int> G[N];
int l[N], z1, Q;
int dis[N], dp[N], far[N];
void add_edge(int x, int y)
{
G[x].push_back(y);
}
void dfs(int x, int f, int d)
{
l[x] = d;
for (int i = 0; i < sz(G[x]); ++i)
{
int to = G[x][i];
if (to == f) continue;
dfs(to, x, d + 1);
}
}
void init()
{
read(n); read(k);
for (int i = 1, v, u; i < n; ++i)
{
read(u); read(v);
add_edge(u, v);
add_edge(v, u);
}
dfs(1, 0, 0);
int mx = 0;
for (int i = 1; i <= n; ++i) if (checkmax(mx, l[i])) z1 = i;
}
void run(int x, int f)
{
dp[x] = 0; far[x] = -inf; dis[x] = inf;
int child = 0;
for (int i = 0; i < sz(G[x]); ++i)
{
int to = G[x][i];
if (to == f) continue;
++child;
run(to, x);
checkmin(dis[x], dis[to] + 1);
dp[x] += dp[to];
}
if (child == 0)
{
dp[x] = far[x] = 0;
dis[x] = inf;
}
else
{
for (int i = 0; i < sz(G[x]); ++i)
{
int to = G[x][i];
if (to == f) continue;
if (Q < dis[x] + far[to] + 1) checkmax(far[x], far[to] + 1);
}
//out(x); out(far[x]); outln(dis[x]);
if (far[x] == Q || dis[x] == Q + Q + 1)
{
++dp[x];
dis[x] = 0; far[x] = -inf;
}
}
//out(Q); out(x); out(dp[x]); out(dis[x]); outln(far[x]);
}
bool check(int mid)
{
Q = mid;
run(z1, 0);
if (dis[z1] > Q) ++dp[z1];
if (dp[z1] <= k) return 1;
else return 0;
}
void solve()
{
int l = 1, r = n - 1, mid, best = n - 1;
while (l <= r)
{
mid = (l + r) >> 1;
if (check(mid)) best = mid, r = mid - 1;
else l = mid + 1;
}
printf("%d\n", best);
}
int main()
{
//setIO("");
init();
solve();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------
int N,K,V;
vector<int> E[202020];
int need[202020],aff[202020];
int num;
void dfs(int cur,int pre) {
need[cur]=0;
aff[cur]=-1;
FORR(e,E[cur]) if(e!=pre) {
dfs(e,cur);
if(aff[e]>=0) aff[cur]=max(aff[cur],aff[e]-1);
if(need[e]>=0) need[cur]=max(need[cur],need[e]+1);
}
if(aff[cur]>=need[cur]) {
need[cur]=-1;
}
else {
if(need[cur]>=V) {
need[cur]=-1;
aff[cur]=V;
num++;
}
else {
aff[cur]=-1;
}
}
}
int ok(int v) {
if(v<=0) return 0;
V=v;
num=0;
dfs(0,0);
if(need[0]>=0) num++;
return num<=K;
}
void solve() {
int i,j,k,l,r,x,y; string s;
cin>>N>>K;
FOR(i,N-1) {
cin>>x>>y;
E[x-1].push_back(y-1);
E[y-1].push_back(x-1);
}
int ret=N;
for(j=20;j>=0;j--) if(ok(ret-(1<<j))) ret-=1<<j;
cout<<ret<<endl;
}
int main(int argc,char** argv){
string s;int i;
if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
cout.tie(0); solve(); return 0;
}
|
#include<bits/stdc++.h>
#define fast {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define all(x) (x).begin(), (x).end()
#define Unique(a) a.erase(unique(all(a)), a.end())
#define ld long double
#define pb push_back
#define fi first
#define se second
#define inf 1e9
using namespace std;
typedef long long int ll;
const int mxn=2e5+5,mod=1e9+7;
int main(void){
fast;
int n;
cin>>n;
int t[n],sum=0;
for(int i=0;i<n;i++){
cin>>t[i];
sum+=t[i];
}
int dp[sum+1]={0};
dp[0]=1;
for(int i=0;i<n;i++){
for(int j=sum-t[i];j>=0;j--){
if(dp[j]){
dp[j+t[i]]=1;
}
}
}
int i,ans=sum;
for(i=1;i<=sum;i++){
if(dp[i]==1)
ans=min(ans,max(i,sum-i));
}
cout<<ans;
}
| #include <bits/stdc++.h>
using namespace std;
#define vll vector<long long>
#define mll map<long long,long long>
#define pll pair<long long,long long>
#define pb push_back
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 998244353
typedef long long ll;
typedef long double ld;
long double pi=3.14159265358979323846;
vll al[300005];
ll I[101][101];
ll gcd(ll a,ll b)
{
if (b==0) return a;
return gcd(b,a%b);
}
bool isPrime(int n)
{
if (n<=1) return false;
if (n<=3) return true;
if (n%2==0||n%3==0) return false;
for (int i=5;i*i<=n;i=i+6) if (n%i==0||n%(i+2)==0) return false;
return true;
}
ll bpow(ll n, ll po)
{
ll res=1;
while(po>0)
{
if(po%2)
{
res=(res*n)%mod;
po--;
}
else
{
n=(n*n)%mod;
po/=2;
}
}
return res;
}
void swap(ll *a, ll *b)
{
ll temp=*a;
*a=*b;
*b=temp;
}
ll fact(ll n) {
if ((n==0)||(n==1))
return 1;
else
return n*fact(n-1);
}
ll modInverse(ll n,ll p)
{
return bpow(n,p-2);
}
ll fac[300001];
ll nCr(ll n,ll r)
{
if (r == 0) return 1;
return (fac[n] * modInverse(fac[r], mod) % mod * modInverse(fac[n - r], mod) % mod) % mod;
}
//bool bipartite_dfs(ll node, ll flag)
//{
// vis[node]=1;
// ll cflag=flag;
// color[node]=cflag;
// for(ll child : al[node])
// {
// if(!vis[child])
// {
// bool n=bipartite_dfs(child,1-cflag);
// if(n==false) return false;
// }
// else if(color[child]==color[node]) return false;
// }
// return true;
//}
void mmul(ll A[][101], ll B[][101], ll dim)
{
ll res[dim][dim];
for(ll i=0;i<dim;i++) for(ll j=0;j<dim;j++)
{
res[i][j]=0;
for(ll k=0;k<dim;k++) res[i][j]=(res[i][j]+A[i][k]*B[k][j])%1000000007;
}
for(ll i=0;i<dim;i++) for(ll j=0;j<dim;j++) A[i][j]=res[i][j];
}
void mpow(ll A[][101],ll dim, ll po)
{
for(ll i=0;i<dim;i++) for(ll j=0;j<dim;j++)
{
if(i==j) I[i][j]=1;
else I[i][j]=0;
}
while(po>0)
{
if(po%2==1)
{
mmul(I,A,dim);
po--;
}
else
{
mmul(A,A,dim);
po/=2;
}
}
for(ll i=0;i<dim;i++) for(ll j=0;j<dim;j++) A[i][j]=I[i][j];
}
int main()
{
FAST
// freopen("d.txt","r",stdin);
// freopen("outputd.txt","w",stdout);
ll testcases=1;
// cin>>testcases;
// fac[0]=1;
// for(ll i=1;i<300001;i++) fac[i]=(fac[i-1]*i)%mod;
while(testcases--)
{
ll n;
cin>>n;
ll a[n];
for(ll i=0;i<n;i++) cin>>a[i];
sort(a,a+n);
ll sum=0,ans=0;
for(ll i=0;i<n;i++) sum+=a[i];
ll dp[n+1][sum/2+1];
memset(dp,0,sizeof(dp));
dp[0][0]=1;
for(ll i=1;i<=n;i++)
{
for(ll j=0;j<=sum/2;j++)
{
if(j<a[i-1]) dp[i][j]=dp[i-1][j];
else dp[i][j]=max(dp[i-1][j-a[i-1]],dp[i-1][j]);
}
}
// for(ll i=0;i<=n)
for(ll i=sum/2;i>=0;i--)
{
if(dp[n][i]==1)
{
ans=sum-i;
break;
}
}
cout<<ans;
}
}
|
#include <bits/stdc++.h>
#pragma GCC optimize ("Ofast")
#define ll long long
#define ull unsigned long long
#define pll pair<long long,long long>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define forn(i, n) for(int i=0; i<int(n); i++)
#define Forn(i, n) for(int i=1; i<=int(n); i++)
using namespace std;
int main()
{
cin.tie(0); ios_base::sync_with_stdio(false);
double a,b;
cin >> a >> b;
cout << fixed << setprecision(8) << a*b/100.0 << endl;
}
| #include<iostream>
using namespace std;
int main()
{
float a,b;
cin >> a;
cin >> b;
cout << a*(b/100);
return 0;
} |
#include <iostream>
#include <cmath>
int main(void) {
int64_t A;
int64_t B;
int64_t C;
std::cin >> A >> B >> C;
if (C % 2 == 0) {
if (std::abs(A) == std::abs(B)) {
std::cout << "=" << std::endl;
} else if (std::abs(A) < std::abs(B)) {
std::cout << "<" << std::endl;
} else {
std::cout << ">" << std::endl;
}
} else {
if (A == B) {
std::cout << "=" << std::endl;
} else if (A < B) {
std::cout << "<" << std::endl;
} else {
std::cout << ">" << std::endl;
}
}
} | #include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
#define cerr if(0) cerr
#define ll long long int
#define fp cout<<fixed<<setprecision(15);
#define loop(var,s,n) for(ll var=s ;var<n;var++)
#define rloop(var,s,n) for(ll var=s ;var>=n;var--)
#define pb push_back
#define endl '\n'
#define mk make_pair
#define all(x) x.begin(),x.end()
#define mod 1000000007
#define ipair pair<ll,pair<ll,ll>>
using namespace std;
int main() {
#ifdef KEVIN
freopen("ingoing3.txt", "r", stdin);
freopen("outgoing3.txt", "w", stdout);
#endif
FAST
int t = 1;
// cin >> t;
while (t--)
{
ll a,b,c;
cin>>a>>b>>c;
if(a==b)
{
cout<<"=";
return 0;
}
if(a>=0&&b>=0)
{
if(a<b)cout<<"<";
else cout<<">";
return 0;
}
if(c%2==0)
{
if(abs(a)>abs(b))
{
cout<<">";
}
else if(abs(a)<abs(b))
{
cout<<"<";
}
else cout<<"=";
return 0;
}
if(a<b)cout<<"<";
else cout<<">";
}
} |
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i,m,n) for(int i = m - 1; i >= n; i--)
#define ALL(v) v.begin(), v.end()
#define itn int
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
#define YES() cout << "YES" << endl
#define NO() cout << "NO" << endl
#define println(x) cout << x << endl
#define print(x) cout << x << " "
template<typename T, typename U>
inline bool CMAX(T &m, U x) { if (m < x) { m = x; return true; } return false; }
template<typename T, typename U>
inline bool CMIN(T &m, U x) { if (m > x) { m = x; return true; } return false; }
typedef long long lint;
typedef long double ldouble;
const int INF = 1e9;
const lint LINF = 1e18;
const int MOD = 1e9+7;
int main(){
string s;
cin >> s;
itn time = 0;
FOR(i,3,s.size()){
string a;
a.push_back(s[i - 3]);
a.push_back(s[i - 2]);
a.push_back(s[i - 1]);
a.push_back(s[i]);
if(a == "ZONe") time++;
}
println(time);
return 0;
} | #include <stdio.h>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
using namespace std;
int main(){
long N,i,ans;
cin>>N;
string a,b,c;
for(i=0;i<N;++i){
a.replace(i,1,"1");
b.replace(i,1,"1");
c.replace(i,1,"1");
if(i%3==0){
c.replace(i,1,"0");
}
else if(i%3==1){
b.replace(i,1,"0");
}
else{
a.replace(i,1,"0");
}
}
string T;
cin>>T;
if(N>=2){
if(T.compare(a)==0){
ans=1e10-(N+2)/3+1;
}
else if(T.compare(b)==0){
ans=1e10-N/3;
}
else if(T.compare(c)==0){
ans=1e10-(N+1)/3;
}
else{
ans=0;
}
}
if(N==1){
if(T.compare("1")==0){
ans=2*1e10;
}
else{
ans=1e10;
}
}
cout<<ans<<endl;
return 0;
} |
#include <iostream>
using namespace std;
int main() {
int N;
string s,t;
cin >> N >> s;
for (char c: s) {
t.append(1,c);
if (t.length()>2 && t.substr(t.length()-3,3) == "fox") {
t.resize(t.length()-3);
}
}
cout << t.length() << endl;
}
| //IQ134高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF INT_MAX
#define LLINF LLONG_MAX
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007
#define MODB 998244353
template <typename T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
for (T& x: vec) { is >> x; }
return is;
}
int mobius[1000001] = {};
int main() {
ll ans = 0;
ll tmp = 0;
//int n; cin >> n;
ll L, R; cin >> L >> R;
//エラトステネスの篩でP_max以下の素数vector primeをつくる
bool *pr;
int P_max = 2000000; //10^6くらいまでが現実的か
pr = (bool*)malloc(sizeof(bool) * (P_max+1));
REP(i, P_max + 1) pr[i] = true;
pr[0] = false;
pr[1] = false;
int dx[P_max] = {}; // xを割り切る最小の素数の配列(素因数分解に使う)
for(int i = 2; i * i <= P_max; i++){
if(pr[i] == true){
for(int j = 2 * i; j <= P_max; j+=i){
pr[j] = false;
if(dx[j] == 0) dx[j] = i;
}
}
}
vector<int> prime;
for(int i = 2; i <= P_max; i++){
if(pr[i]) prime.push_back(i);
}
//
//配列dxを使って整数Xの素因数分解の結果をmapで返す。
map<int, int> prf;
for(int mo = 2; mo <= R; mo++){
int X = mo;
int diving = X; //これをどんどん割っていく。dividingが正しい
prf.clear();
while(dx[diving] != 0){
prf[dx[diving]]++;
diving /= dx[diving];
//重複なしで割り切れる素数を列挙する場合は上の行をコメントアウトして下を使う
//int nowdx = dx[diving]; while (diving % nowdx == 0) diving /= nowdx;
}
if(diving > 1)prf[diving]++;
//これは素因数分解の結果が見たくなったときに使うもの
//for(auto i = prf.begin(); i!= prf.end(); i++) cout << i->first << "," << i->second << " "; cout << endl;
//
//メビウス関数の計算
mobius[mo] = 1;
for(auto i = prf.begin(); i!= prf.end(); i++){
if(i->second == 1) mobius[mo] *= -1;
else if(i->second > 1) mobius[mo] = 0;
}
//メビウス関数の結果の反映
ll a = R / mo - (L-1) / mo;
ans += (-1LL) * mobius[mo] * a * (a-1) / 2;
}
for(int k = max(2LL, L); k <= R; k++){
ans -= R / k - (L-1) / k - 1;
}
cout << ans * 2 << endl;
} |
#include<bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for(int i=(a); i<(n); ++i)
#define per(i, a, n) for(int i=(a); i>(n); --i)
#define pb emplace_back
#define mp make_pair
#define clr(a, b) memset(a, b, sizeof(a))
#define all(x) (x).begin(),(x).end()
#define lowbit(x) (x & -x)
#define fi first
#define se second
#define lson o<<1
#define rson o<<1|1
#define gmid l[o]+r[o]>>1
using LL = long long;
using ULL = unsigned long long;
using pii = pair<int,int>;
using PLL = pair<LL, LL>;
using UI = unsigned int;
const int mod = 998244353;
const int inf = 0x3f3f3f3f;
const double EPS = 1e-8;
const double PI = acos(-1.0);
LL a, b, c;
LL cal(LL x){
x = (x + 1) * x / 2;
return x % mod;
}
int main(){
scanf("%lld %lld %lld", &a, &b, &c);
printf("%lld\n", cal(a) * cal(b) % mod * cal(c) % mod);
return 0;
}
| #pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<stdio.h>
#include<algorithm>
constexpr long long MOD = 998244353;
constexpr long long MOD32 = 665496236;
int main(){
long H=0, W=0, K=0;
char c=getchar_unlocked();
while(c<='9'&&c>='0') {H=(H<<1)+(H<<3)+c-'0'; c=getchar_unlocked();}
c=getchar_unlocked();
while(c<='9'&&c>='0') {W=(W<<1)+(W<<3)+c-'0'; c=getchar_unlocked();}
c=getchar_unlocked();
while(c<='9'&&c>='0') {K=(K<<1)+(K<<3)+c-'0'; c=getchar_unlocked();}
char f[H][W];
std::fill(f[0], f[H], 0);
long long y = H * W - K;
while(--K>=0){
long h=0, w=0;
c=getchar_unlocked();
while(c<='9'&&c>='0') {h=(h<<1)+(h<<3)+c-'0'; c=getchar_unlocked();}
c=getchar_unlocked();
while(c<='9'&&c>='0') {w=(w<<1)+(w<<3)+c-'0'; c=getchar_unlocked();}
f[h-1][w-1] = getchar_unlocked();
getchar_unlocked();
}
--H; --W;
long long dp[W+1] = {0};
dp[0] = 1;
for(int i = 0; i < H; ++i){
for (int j = 0; j < W; ++j){
switch(f[i][j]) {
case 'R':
dp[j + 1] += dp[j];
dp[j] = 0;
break;
case '\0':
dp[j] = dp[j] * MOD32 % MOD;
case 'X':
dp[j + 1] += dp[j];
}
}
switch(f[i][W]) {
case 'R':
dp[W] = 0;
break;
case '\0':
dp[W] = dp[W] * MOD32 % MOD;
}
}
for (int j = 0; j < W; ++j){
switch(f[H][j]) {
case '\0':
dp[j] = dp[j] * MOD32 % MOD;
case 'R':
case 'X':
dp[j + 1] += dp[j];
}
}
long long ans = dp[W] % MOD;
long long x = 3;
while(y) {
if(y & 1) ans = ans * x % MOD;
x = x * x % MOD;
y >>= 1;
}
printf("%d", ans);
return 0;
}
|
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0xccccccc;
const ll LINF = 0xcccccccccccccccLL;
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 T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}
//head
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
string s;
ll n;
cin >> s >> n;
ll u = *max_element(all(s))-'0';
u++;
int cnt = 0;
int siz = s.size();
if(siz == 1) {
cout << (n >= stoi(s)) << endl;
return 0;
}
if(siz == 2) {
if(u*(s[0]-'0')+(s[1]-'0') > n) {
cout << "0\n";
return 0;
}
int s0 = s[0]-'0';
int s1 = s[1]-'0';
ll x = (n-s1)/s0;
cout << x-u+1 << endl;
return 0;
}
if(siz == 3) {
ll s0 = s[0]-'0';
ll s1 = s[1]-'0';
ll s2 = s[2]-'0';
if(s0*u*u+s1*u+s2 > n) {
cout << "0\n";
return 0;
}
__int128_t lb = u, ub = 1e9+100;
while(ub != lb+1) {
__int128_t mid = (lb+ub)/2;
if(s0*mid*mid+s1*mid+s2 > n) ub = mid;
else lb = mid;
}
cout << ll(ub-u) << endl;
return 0;
}
while(true) {
__int128_t k = 1, x = 0;
rep(i, siz-1) {
k *= u;
if(k > n) goto OUT;
}
rep(i, siz) {
x += k*(s[i]-'0');
k /= u;
}
if(x > n) goto OUT;
u++;
cnt++;
}
OUT:;
cout << cnt << endl;
} | #include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define int long long
#define FOR(i, size) for (int i = 0; i < size; i++)
#define all(x) x.begin(), x.end()
#define endl "\n"
#define MOD 1000000007
#define deb(...) logger(#__VA_ARGS__, __VA_ARGS__)
template <typename... Args>
void logger(string vars, Args &&...values)
{
cout << vars << " = ";
string delim = "";
(..., (cout << delim << values, delim = ", "));
}
template <typename T>
void print_list(vector<T> collection, bool newline = true)
{
for (const auto &item : collection)
{
cout << item << " ";
}
if (newline)
cout << endl;
}
#define ONE_TESTCASE 1
int n, m, timer;
void Solve()
{
int a, b, c, d;
cin >> a >> b >> c >> d;
int de = c * d - b;
if (de <= 0)
{
cout << -1;
return;
}
int ans = a / de;
cout << (ans + (a % de == 0 ? 0 : 1));
}
int32_t main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#if ONE_TESTCASE
int test = 1;
#else
int test;
cin >> test;
#endif
for (int t = 1; t <= test; t++)
{
Solve();
cout << endl;
}
}
|
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include <utility>
#include<functional>
#include<math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define REP(i,l,n) for(ll i=(l);i<(n);i++)
#define per(i,n) for(ll i=(n);i>0;i--)
#define pf(n) printf("%d\n",n)
#define pf_(a) printf("%d ",a);
#define all(v) begin(v),end(v)
typedef long long ll;
typedef vector<int> vi;
typedef pair<ll, ll> p;
const int INF = 1001001001;
const double PI = acos(-1);
const ll mod = 1000000007;
struct UnionFind {
vector<int> par;
UnionFind(int n) : par(n) {
rep(i, n) par[i] = i;
}
int root(int x) {
if (par[x] == x) return x;
return par[x] = root(par[x]);
}
void unite(int x, int y) {
int rx = root(x);
int ry = root(y);
if (rx == ry) return;
par[rx] = ry;
}
bool same(int x, int y) {
int rx = root(x);
int ry = root(y);
return rx == ry;
}
};
int main() {
ll n, w;
cin >> n >> w;
vector<ll> T(1001001, 0);
ll mt = 0;
rep(i, n) {
ll s, t, p;
cin >> s >> t >> p;
T[s] += p;
T[t] += -p;
mt = max(mt, t);
}
ll cnt = 0;
bool ok = true;
rep(i, mt) {
if (T[i] > 0) {
cnt += T[i];
//cout << cnt << endl;
if (cnt > w) ok = false;
}
else if(T[i] < 0){
cnt += T[i];
}
}
puts(ok ? "Yes" : "No");
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long int
#define fi first
#define se second
#define pub push_back
#define pi pair<int,int>
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for(int i=(int)(l);i<(int)(r);i++)
#define repd(i, l, r) for (int i=(int)(l);i>=(int)(r);i--)
#define clrg(i, l, r) for(int i=(int)(l);i<(int)(r);i++)vis[i]=0,v[i].clear();
int power(int x, unsigned int y){int res = 1;while (y > 0){ if (y & 1){res = res*x;} y = y>>1;x = x*x;}return res;}
int powermod(int x, unsigned int y, int p){int res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1; x = (x*x) % p;}return res;}
#define print2d(mat,n,m){for(int i=0;i<(int)(n);i++){for(int j=0;j<(m);j++){cout<<mat[i][j]<<" ";}cout<< endl;}}
#define clr(a,x) memset(a,x,sizeof(a))
#define rr(v) for(auto &val:v)
#define print(v) for (const auto itr : v){cout<<itr<<' ';}cout<<"\n";
#define ln length()
#define sz size()
#define mod 1000000007
#define elif else if
int32_t main(){
fastIO
int x,y; cin>>x>>y;
if(x==y){
cout<<x<<"\n";
}
else{
set<int> s;
rep(i,0,3)s.insert(i);
s.erase(x),s.erase(y);
cout<<*s.begin()<<"\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main(){
int n; cin >> n;
double ans = 0;
for (int i = 1; i <= n-1; i++){
ans += 1.0*n/i;
}
cout << fixed << setprecision(8) << ans << endl;
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
const double EPS = 1e-10;
const double PI = acos(-1.0);
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
bool compare_by_b(pair<LL, LL> a, pair<LL, LL> b) {
if(a.second != b.second)return a.second < b.second;
else return a.first < b.first;
}
void solve(long long N){
double ret = 0;
for(int i= N-1; i >=1; i--){
ret+=(double)N/(double)i;
}
cout<<setprecision(12)<<ret<<endl;
return;
}
int main(){
long long N;
scanf("%lld",&N);
solve(N);
return 0;
}
|
#include<iostream>
using namespace std;
int main()
{
int n,x[201],y[201],a[201],b[201],c[201],d[201];
int i,j,rr;
long long int r[201];
cin >> n;
for(i=0;i<n;i++){
cin >> x[i] >> y[i] >> r[i];
if(x[i]==0 || y[i]==0){
if(x[i]==0 && y[i]==0){
a[i]=b[i]=0;
c[i]=x[i]+1;
d[i]=y[i]+1;
}
else if(x[i]==0){
a[i]=0;
b[i]=y[i]-1;
c[i]=x[i]+1;
d[i]=y[i]+1;
}
else if(y[i]==0){
a[i]=x[i]-1;
b[i]=0;
c[i]=x[i]+1;
d[i]=y[i]+1;
}
}
else{
a[i]=x[i]-1;
b[i]=y[i]-1;
c[i]=x[i]+1;
d[i]=y[i]+1;
}
}
int aflag,bflag,cflag,dflag;
for(i=0;i<n;i++){
aflag=bflag=cflag=dflag=0;
rr=(c[i]-a[i])*(d[i]-b[i]);
while((aflag!=1 || bflag!=1 || cflag!=1 || dflag!=1) && rr<r[i]+500){
if(aflag==0) a[i]--;
if(bflag==0) b[i]--;
if(cflag==0) c[i]++;
if(dflag==0) d[i]++;
for(j=0;j<n;j++){
if(i!=j){
if(a[i]<0){
a[i]=0;
aflag=1;
}
if(b[i]<0){
b[i]=0;
bflag=1;
}
if(c[i]>10000){
c[i]=10000;
cflag=1;
}
if(d[i]>10000){
d[i]=10000;
dflag=1;
}
if(a[i]<=a[j] && b[i]<=b[j] && c[i]>=c[j] && d[i]>=d[j]){
if(c[j]<x[i]){
a[i]=c[j];
aflag=1;
}
else if(a[j]>x[i]){
c[i]=a[j];
cflag=1;
}
else if(b[j]<y[i]){
b[i]=d[j];
bflag=1;
}
else if(b[j]>y[i]){
d[i]=b[j];
dflag=1;
}
}
if((a[j]>=a[i] && a[j]<c[i]) && (b[j]>=b[i] && d[j]<=d[i])){//右
c[i]--;
cflag=1;
}
else if((a[j]>=a[i] && c[j]<=c[i]) && (b[j]>=b[i] && b[j]<d[i])){//下
d[i]--;
dflag=1;
}
else if((a[j]>=a[i] && c[j]<=c[i]) && (d[j]>b[i] && d[j]<=d[i])){//上
b[i]++;
bflag=1;
}
else if((c[j]>a[i] && c[j]<=c[i]) && (b[j]>=b[i] && d[j]<=d[i])){//左
a[i]++;
aflag=1;
}
if((a[i]>=a[j] && a[i]<c[j]) && (b[i]>=b[j] && b[i]<d[j])){//左上
if((c[j]-a[i])<=(d[j]-b[i])){
a[i]++;
aflag=1;
}
if((c[j]-a[i])>=(d[j]-b[i])){
b[i]++;
bflag=1;
}
}
else if((a[i]>=a[j] && a[i]<c[j]) && (d[i]>b[j] && d[i]<=d[j])){//左下
if((c[j]-a[i])<=(d[i]-b[j])){
a[i]++;
aflag=1;
}
if((c[j]-a[i])>=(d[i]-b[j])){
d[i]--;
dflag=1;
}
}
else if((c[i]>a[j] && c[i]<=c[j]) && (d[i]>b[j] && d[i]<=d[j])){//右下
if((c[i]-a[j])<=(d[i]-b[j])){
c[i]--;
cflag=1;
}
if((c[i]-a[j])>=(d[i]-b[j])){
d[i]--;
dflag=1;
}
}
else if((c[i]>a[j] && c[i]<=c[j]) && (b[i]>=b[j] && b[i]<d[j])){//右上
if((c[i]-a[j])<=(d[j]-b[i])){
c[i]--;
cflag=1;
}
if((c[i]-a[j])>=(d[j]-b[i])){
b[i]++;
bflag=1;
}
}
}
}
rr=(c[i]-a[i])*(d[i]-b[i]);
}
}
for(i=0;i<n;i++){
cout << a[i] << " " << b[i] << " " << c[i] << " " << d[i] << endl;
}
return 0;
} | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
ll n;
cin >> n;
vector<ll> x(n);
vector<ll> y(n);
vector<ll> r(n);
for(int i = 0;i < n;i++)cin >> x[i] >> y[i] >> r[i];
for(int i = 0;i < n;i++){
ll xsi = 0;
ll ysi = 0;
ll xmin = 10000;
ll ymin = 10000;
for(int j = 0;j < n;j++){
if(x[i] < x[j])xmin = min(xmin,x[j]);
if(y[i] < y[j])ymin = min(ymin,y[j]);
}
//if(xmin * ymin > r[i])xmin = max((ll)1,r[i] / ymin - 1);
/*while(1){
bool can = true;
for(int j = 0;j < n;j++){
if(i == j || (x[i] > x[j] && y[i] > y[j]))continue;
if(x[j] <= x[i] + xsi && y[j] <= y[i] + ysi){
can = false;
j = n;
}
}
if(!can || xsi * ysi >= r[i] || x[i] + xsi >= 10000 || y[i] + ysi >= 10000)break;
xsi++,ysi++;
}*/
cout << x[i] << " " << y[i] << " " << xmin << " " << ymin << endl;
}
} |
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define repn(i,n) for(int i=1;i<=n;++i)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair
using namespace std;
const LL MOD=1e9+7;
int n,a[200010],b[200010],p[200010],pos[200010];
vector <int> v;
vector <pii> ans;
bool cmp(int x,int y)
{
return b[x]>b[y];
}
int main()
{
cin>>n;
rep(i,n) scanf("%d",&a[i]);
rep(i,n) scanf("%d",&b[i]);
rep(i,n)
{
scanf("%d",&p[i]),--p[i];
if(p[i]!=i&&b[p[i]]>=a[i])
{
puts("-1");
return 0;
}
pos[p[i]]=i;
v.pb(i);
}
sort(v.begin(),v.end(),cmp);
//rep(i,v.size()) cout<<v[i]<<'p'<<endl;
rep(i,n)
{
if(pos[v[i]]==v[i]) continue;
ans.pb(mpr(pos[v[i]],v[i]));
int aa=pos[v[i]],bb=v[i],cc=v[i],dd=p[v[i]];
p[cc]=bb;
p[aa]=dd;
pos[bb]=cc;
pos[dd]=aa;
}
cout<<ans.size()<<endl;
rep(i,ans.size()) printf("%d %d\n",ans[i].fi+1,ans[i].se+1);
return 0;
} | //Jo Hack kiya Wo Madharchod
#include"bits/stdc++.h"
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define ll long long int
#define inf 1e18+5
#define sr string
#define M 1000000007 //998244353//
#define start int t;cin>>t;while(t--)
#define db(x) cout<<#x<<"="<<x<<"\n"
#define db2(a,b)cout<<#a<<": "<<a<<" , "<<#b<<": "<<b<< endl;
#define db3(a,b,c)cout<<#a<<": "<<a<<" , "<<#b<<": "<<b<<" , "<<#c<<": "<<c<<endl;
#define forr(i, n) for (int i = 0; i < n; i++)
#define fr(i, n) for (int i = 1; i <= n; i++)
#define rep(i,j,k) for(int i = j; i < k; i++)
#define rp(i,j,k) for(int i = j; i <=k; i++)
#define nn "\n"
#define en "\n"
#define vvi vector<vector<ll>>
#define vi vector<int>
#define si set<ll>
#define mlsi multiset<ll>
#define vc vector<char>
#define vli vector<long long int>
#define vpii vector<pair<ll,ll>>
#define pii pair<ll,ll>
#define mii map<ll,ll>
#define msi map<string,int>
#define mci map<char,int>
#define umii unordered_map<ll,ll>
#define umsi unordered_map<string,int>
#define umci unordered_map<char,int>
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define sortv(x) sort(x.begin(),x.end())
#define sorta(x,n) sort(x,x+n)
#define sorted(x) is_sorted(x.begin(),x.end())
#define print_all(x) for(auto t:x) cout<<t<<" ";cout<<en;
#define mxe(x) *max_element(all(x))
#define mne(x) *min_element(all(x))
#define ad(x) accumulate(all(x),0)
#define ub upper_bound
#define lb lower_bound
#define go(x) for(auto &[u,v]:x)
#define gov(v) for(auto &x:v)
#define in(x) cin>>x
#define in2(x,y) cin>>x>>y
#define in3(x,y,z) cin>>x>>y>>z
#define in4(x,y,z,v) cin>>x>>y>>z>>v
#define oo(x) cout<<x<<en
#define oo2(x,y) cout<<x<<" "<<y<<en
#define oo3(x,y,z) cout<<x<<" "<<y<<" "<<z<<en
#define ood(n,x) cout<<fixed<<setprecision(n)<<x<<"\n"
#define sz(x) x.size()
#define ff first
#define ss second
#define ooy cout<<"Yes\n"
#define oon cout<<"No\n"
#define ooyy cout<<"YES\n"
#define oonn cout<<"NO\n"
#define rr return
#define cc continue
using namespace std;
template<class T> bool ckmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
void read(vli &a,int n){
a.resize(n);
forr(i,n) cin>>a[i];
}
bool fine=0;
vli a;
ll n,m,k,x,p,q;
void solve(){
in(n);
if(n&1){
cout<<"Black";
}
else cout<<"White";
}
int main(){
#ifndef ONLINE_JUDGE
freopen("input1.txt", "r", stdin);
freopen("error.txt", "w", stderr);
freopen("output1.txt", "w", stdout);
#endif
fast;
if(fine){
start{
solve();
}
}
else solve();
return 0;
} |
#include <bits/stdc++.h>
#define rep(i, f, n) for (ll i = (f); i < (ll)(n); i++)
#define repe(i, f, n) for (ll i = (f); i <= (ll)(n); i++)
using namespace std;
using ll = long long;
using pint = pair<int, int>;
template <class T>
void chmin(T& a, T b) {
if (a > b) a = b;
}
template <class T>
void chmax(T& a, T b) {
if (a < b) a = b;
}
int main() {
int n;
cin >> n;
vector<int> a(n);
rep(i, 0, n) cin >> a[i];
ll ans = 0;
rep(l, 0, n) {
int x = a[l];
rep(r, l, n) {
chmin(x, a[r]);
chmax(ans, x * (r - l + 1));
}
}
cout << ans << endl;
return 0;
}
| #include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
#define rep(i,a) for(i=0;i<=a;i++)
#define repr(i,a) for(i=a;i>=0;i--)
#define repp(i,a,b) for(i=a;i<=b;i++)
#define reppr(i,b,a) for(i=b;i>=a;i--)
#define maxarr(a,n) *max_element(a,a+n);
#define minarr(a,n) *min_element(a,a+n);
#define ll long long int
#define p(ans) cout<<ans<<endl;
#define pb push_back
#define pob pop_back
#define Groza ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
#define MOD 1000000007
#define Max 1000000000
#define pyn(flag) cout<<(flag?"YES":"NO")<<endl;
#define f first
#define s second
#define parr(a,i,n) for(i=0;i<n;i++)cout<<a[i]<<" ";
#define all(v) v.begin(),v.end()
#define in insert
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
ll poww(const ll &a, ll b, const ll &m = MOD)
{ if (b == 0)
return 1;
ll x = poww(a, b / 2, m);
x = x * x % m;
if (b & 1)
x = x * a % m;
return x;
}
template <class T>
inline void PRINT_ELEMENTS (const T& coll, const char* optcstr = "")
{
typename T::const_iterator pos;
std::cout << optcstr;
for (pos = coll.begin(); pos != coll.end(); ++pos) {
std::cout << *pos << ' ';
}
std::cout << std::endl;
}
template <class T>
inline void INSERT_ELEMENTS (T& coll, int first, int last)
{
for (int i = first; i <= last; ++i) {
coll.insert(coll.end(), i);
}
}
//ll spf[1000000],sum;
/*const int N = 5005;
std::vector<int> v[N];
bool ans = false;
int vis[N];
map<ll, ll>m;
//ll cnt = 0;
void dfs(ll n, ll par, ll cnt)
{
vis[n] = 1;
for (auto x : v[n])
{
if (!vis[x])
{
dfs(x, n, cnt + 1);
}
else if (vis[x] && cnt == 3 && par != x)
{
ans = true;
return;
}
}
}*/
/*std::vector<ll> res;
bool prime[MOD];
void seive(int n)
{
memset(prime, true, sizeof(prime));
for (int p = 2; p * p <= n; p++)
{
if (prime[p] == true)
{
for (int i = p * p; i <= n; i += p)
prime[i] = false;
}
}
for (int p = 2; p <= n; p++)
if (prime[p])
res.pb(p);
}
/*const int N = 1000007;
int fact[N];
int nCr(int n, int r){
int x =fact[r]*fact[n-r]%MOD;
return (fact[n]*poww( x ,MOD-2))%MOD;
}
*/
float Round(float var)
{
float value = (int)(var * 100 + .5);
return (float)value / 100;
}
ll sumofdigit(ll n)
{
ll sum = 0;
while (n > 0)
{
sum += 1;
n = n / 10;
}
return sum;
}
/*
int lcs( string X, string Y, int m, int n )
{
int L[m + 1][n + 1];
int i, j;
for (i = 0; i <= m; i++)
{
for (j = 0; j <= n; j++)
{
if (i == 0 || j == 0)
L[i][j] = 0;
else if (X[i - 1] == Y[j - 1])
L[i][j] = L[i - 1][j - 1] + 1;
else
L[i][j] = max(L[i - 1][j], L[i][j - 1]);
}
}
return L[m][n];
} */
using namespace __gnu_pbds;
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
Groza;
ll t = 1;
//cin >> t;
//seive(MOD);
while (t--)
{
ll n, k;
cin >> n >> k;
ll i = 0, sum = 0, j = 0, rem = 0;
repp(i, 1, n)
{
rem = i * 100;
repp(j, 1, k)
{
sum += (rem + j);
}
}
p(sum);
}
return 0;
} |
#include <bits/stdc++.h>
#define forsn(i,s,n) for(tint i=(s);i<(tint)(n); i++)
#define forn(i,n) forsn(i,0,n)
#define dforn(i,n) for(tint i = tint(n)-1; i >= 0; i--)
#define debug(x) cout << #x << " = " << x << endl
using namespace std;
typedef long long tint;
random_device rd;
mt19937 gen(rd());
uniform_int_distribution<tint> dis(1, 10000);
void imprimirVector (vector<tint> v)
{
if (!v.empty())
{
tint p = tint(v.size());
cout << "[";
forn(i,p-1)
cout << v[i] << ",";
cout << v[p-1] << "]" << endl;
}
else
cout << "[]" << endl;
}
const tint MAXR = 7;
tint mod(tint a, tint b)
{
a %= b;
if (a < 0)
a += b;
return a;
}
tint mult_table[10][10];
int main()
{
#ifdef ACMTUYO
assert(freopen("entrada.in", "r", stdin));
#endif
ios_base::sync_with_stdio(0);
cin.tie(NULL);
tint n;
string s, x;
forn(k1,10)
forn(k2,10)
mult_table[k1][k2] = mod(k1*10 + k2, MAXR);
while (cin >> n >> s >> x)
{
vector<vector<tint> > win (n+1, vector<tint> (MAXR,0));
forn(k,MAXR)
win[n][k] = 0;
win[n][0] = 1;
for (tint i = n-1; i >= 0; i--)
{
if (x[i] == 'A')
{
forn(k,MAXR)
{
tint move1 = win[i+1][mult_table[k][0]];
tint move2 = win[i+1][mult_table[k][s[i]-'0']];
win[i][k] = tint((move1 + move2 ) == 2);
}
}
else
{
forn(k,MAXR)
{
tint move1 = win[i+1][mult_table[k][0]];
tint move2 = win[i+1][mult_table[k][s[i]-'0']];
win[i][k] = tint((move1 + move2) > 0);
}
}
}
if (win[0][0] > 0)
cout << "Takahashi\n";
else
cout << "Aoki\n";
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ll mod2 = 998244353;
const ld eps = 1e-10;
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;}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n; cin >> n;
string s; cin >> s;
string x; cin >> x;
set<int> st;
rep(i, 10) if(i) st.insert(i);
reverse(all(s));
reverse(all(x));
rep(i, n) {
if(x[i] == 'T') {
set<int> nextSt;
rep(j, 10) nextSt.insert(j);
rep(j, 10) {
if(!st.count((j*10+(s[i]-'0'))%7)) nextSt.erase(j);
if(!st.count((j*10)%7)) nextSt.erase(j);
}
st = nextSt;
} else {
set<int> nextSt;
rep(j, 10) {
if(st.count((j*10+(s[i]-'0'))%7)) nextSt.insert(j);
if(st.count((j*10)%7)) nextSt.insert(j);
}
st = nextSt;
}
}
cout << (st.count(0) ? "Aoki" : "Takahashi") << endk;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
const int N=1e5;
vector<int>v[N];
int main()
{
int n;
cin>>n;
string s;
cin>>s;
if(s[0]==s[s.size()-1])
{
char x=s[0];
int o=0;
for(int i=1; i<s.size()-1; i++)
{
if(x!=s[i] && x!=s[i+1])
{
o=1;
break;
}
}
if(o==1)
{
cout<<"2"<<endl;
}
else
{
cout<<"-1"<<endl;
}
}
else
{
cout<<1<<endl;
}
}
| /*########################################################################
# File Name: d.cpp
# Author: SoMnus_L
# Mail: [email protected]
# Created Time:六 5/15 22:12:23 2021
########################################################################*/
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define me memset
#define rep(a,b,c) for(int a=b;a<=c;++a)
#define per(a,b,c) for(int a=b;a>=c;--a)
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
using namespace std;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}
int n,m;
string s[N];
int dp[2005][2005];
int main() {
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
cin>>n>>m;
me(dp,-INF,sizeof(dp));
rep(i,0,n-1){
cin>>s[i];
}
dp[n-1][m-1]=0;
per(i,n-1,0){
per(j,m-1,0){
if(i+1<n){
if(s[i+1][j]=='+') dp[i][j]=max(dp[i][j],1-dp[i+1][j]);
else dp[i][j]=max(dp[i][j],-1-dp[i+1][j]);
}
if(j+1<m){
if(s[i][j+1]=='+') dp[i][j]=max(dp[i][j],1-dp[i][j+1]);
else dp[i][j]=max(dp[i][j],-1-dp[i][j+1]);
}
}
}
if(dp[0][0]==0) cout<<"Draw\n";
else if(dp[0][0]>=1) cout<<"Takahashi\n";
else cout<<"Aoki\n";
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define INF 1234567890
#define ll long long
int N;
int A[100101];
double f(double X)
{
double ret = 0;
for(int i=1; i<=N; i++)
{
ret += X + A[i] - min(1.0*A[i], X+X);
}
ret /= N;
return ret;
}
int main()
{
ios::sync_with_stdio(0); cin.tie(0);
cin.exceptions(ios::badbit | ios::failbit);
cin >> N;
for(int i=0; i<N; i++)
cin >> A[i];
sort(A, A+N);
cout << setprecision(12) << fixed;
cout << f(A[N/2]/2.0) << "\n";
return 0;
} | #include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x) cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long
int gcd(int a, int b) {
if(a < b) return gcd(b, a);
if(b == 0) return a;
return gcd(b, a % b);
}
signed main(void)
{
cin.tie(0);
ios::sync_with_stdio(false);
int N; cin >> N;
int a = 1;
REP(i, 2, 30) {
a = a * i / gcd(a, i);
}
//REP(i, 2, 30) cout << (a + 1) % i << endl;
cout << a + 1 << endl;
return 0;
}
|
#include <iostream>
#include <iomanip>
#include <assert.h>
#include <vector>
#include <string>
#include <cstring>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef std::pair<long long, long long> Pll;
typedef std::vector<int> vi;
typedef std::vector<long long> vl;
typedef std::vector<std::string> vs;
typedef std::vector<std::pair<long long, long long>> vpll;
typedef std::vector<std::vector<ll>> vvl;
template<class T> using V = std::vector<T>;
template<class T> using VV = std::vector<std::vector<T>>;
template<class T> using PQue = std::priority_queue<T>;
template<class T> using RPQue = std::priority_queue<T, std::vector<T>, std::greater<T>>;
const long double PI = (acos(-1));
const long long MOD = 1000000007;
static const int MAX_INT = std::numeric_limits<int>::max(); // 2147483647 = 2^31-1
static const ll MAX_LL = std::numeric_limits<long long>::max();
static const int INF = (1 << 29); // cf) INT_MAX = 2147483647 = 2^31-1
static const ll INFLL = (1ll << 61); // cf) LLONG_MAX = 9223372036854775807 = 2^63 - 1
#define rep(i,n) REP(i,0,n)
#define REP(i,x,n) for(ll i=(ll)(x);i<(ll)(n);++i)
#define rrep(i,n) RREP(i,0,n)
#define RREP(i,x,n) for(ll i=(ll)(n)-1ll;i>=(ll)(x);--i)
#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()
#define SUM(x) accumulate(ALL(x), 0ll)
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define debug(var) do{std::cout << #var << " : ";view(var);}while(0)
// view
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
// change min/max
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; }
void Main() {
ll X, Y; cin >> X >> Y;
if (X > Y) swap(X, Y);
bool ans = ((Y - X) < 3);
cout << (ans ? "Yes" : "No") << endl;
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout << std::fixed << std::setprecision(15);
Main();
double tmp;
cin >> tmp;
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
int main()
{
int x,y;
cin>>x>>y;
if(abs(x-y)<3)
{
cout<<"Yes";
}
else
{
cout<<"No";
}
cout<<endl;
return 0;
}
|
#include <bits/stdc++.h>
// #include <atcoder/all>
// #include "icld.cpp"
using namespace std;
using ll = long long int;
using vi = vector<int>;
using si = set<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using ss = string;
using db = double;
template<typename T> using minpq = priority_queue <T,vector<T>,greater<T>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
#define V vector
#define P pair<ll,int>
#define rep(i,s,n) for(int i=(s);i<(int)(n);i++)
#define rev(i,s,n) for(int i=(s);i>=(int)(n);i--)
#define reciv(v,n) vi (v)((n)); rep(i,0,(n))cin>>v[i]
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define ci(x) cin >> x
#define cii(x) ll x;cin >> x
#define cci(x,y) ll x,y;cin >> x >> y
#define co(x) cout << x << endl
#define pb push_back
#define eb emplace_back
#define rz resize
#define sz(x) int(x.size())
#define yn cout<<"Yes"<<endl;else cout<<"No"<<endl
#define YN cout<<"YES"<<endl;else cout<<"NO"<<endl
template<class T>void chmax(T &x,T y){x=max(x,y);}
template<class T>void chmin(T &x,T y){x=min(x,y);}
struct ed{
int to,t,k;
ed(int to,int t,int k):to(to),t(t),k(k){}
};
int main(){
cci(n,m);
cci(sx,sy);
sx--;sy--;
V<V<ed>> v(n);
rep(i,0,m){
cci(x,y);
x--;y--;
cci(t,k);
v[x].eb(y,t,k);
v[y].eb(x,t,k);
}
ll inf=3e18;
vll dist(n,inf);
dist[sx]=0;
minpq<P>q;
q.push(P(0,sx));
while(sz(q)){
ll d=q.top().first;
int x=q.top().second;
q.pop();
if(dist[x]<d)continue;
for(auto e:v[x]){
int nx=e.to;
ll k=e.k;
ll tm=(d+k-1)/k*k+e.t;
if(dist[nx]>tm){
dist[nx]=tm;
q.push(P(tm,nx));
}
}
}
ll ans=dist[sy];
if(ans==inf)ans=-1;
co(ans);
} | //clear adj and visited vector declared globally after each test case
//check for long long overflow
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;
//Incase of close mle change language to c++17 or c++14
/**#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops”)**/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10);
#define pb push_back
#define mod 1000000007ll //998244353ll
#define lld long double
#define mii map<int, int>
#define pii pair<int, int>
#define ff first
#define ss second
#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)
#define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";}
typedef std::numeric_limits< double > dbl;
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set
const long long N=200005, INF=2000000000000000000;
lld pi=3.1415926535897932;
int lcm(int a, int b)
{
int g=__gcd(a, b);
return a/g*b;
}
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;
}
int32_t main()
{
IOS;
int n, m, q;
cin>>n>>m>>q;
vector <pii> v;
rep(i,0,n)
{
int a, b;
cin>>a>>b;
v.pb({a, b});
}
sort(all(v));
int ar[m];
rep(i,0,m)
cin>>ar[i];
while(q--)
{
int l, r;
cin>>l>>r;
l--,r--;
vi temp;
rep(i,0,l)
temp.pb(ar[i]);
rep(i,r+1,m)
temp.pb(ar[i]);
sort(all(temp));
mii s;
int cur=0, ans=0;
for(auto num:temp)
{
while(cur<n && v[cur].ff<=num)
s[(-v[cur].ss)]++, cur++;
if(!s.empty())
{
auto it=*s.begin();
ans-=it.ff;
s[it.ff]--;
if(s[it.ff]==0)
s.erase(it.ff);
}
}
cout<<ans<<"\n";
}
} |
#include <iostream>
#include <math.h>
#include <iomanip>
#include <bits/stdc++.h>
#include <string.h>
#include <string>
#include <algorithm>
#define ll long long int
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
ll binomialCoeff(ll n,ll k)
{
ll res = 1;
if(k >n - k)
k = n - k;
for(int i = 0; i < k; ++i)
{
res *= (n - i);
res /= (i + 1);
}
return res;
}
ll power(ll x,ll y)
{
ll temp;
if(y == 0)
return 1;
temp = power(x, y/2);
if (y%2 == 0)
return (temp*temp);
else
return (((x*temp))*temp);
}
//nCr % mod
const int N0 = 2e6 + 5;
ll fact[6*N0];
ll inv[6*N0],invfac[6*N0];
ll mod = 1e9 + 7;
void factorial()
{
fact[0] = invfac[0] = fact[1] = invfac[1] = 1;
inv[1] = 1;
for(int i=2;i<=5*N0 + 10;i++)
{
fact[i] = (fact[i-1]*i)%mod;
inv[i] = (inv[mod%i]*(mod - mod/i))%mod;
invfac[i] = (invfac[i-1]*inv[i])%mod;
}
}
vector<ll> primes;
void Sieve(int n)
{
bool prime[n+1];
memset(prime, true, sizeof(prime));
for (int p=2; p*p<=n; p++)
{
if (prime[p] == true)
{
for (int i=p*p; i<=n; i += p)
prime[i] = false;
}
}
for (int p=2; p<=n; p++)
if (prime[p])
primes.push_back(p);
}
//****************************************************** CHECK CONSTRAINTS ***************************************************************//
const int N = 2e5 + 5;
int main()
{
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
ll n,m;
ll sum = 0;
cin >> n >> m;
for(int i=0;i<n;i++)
{
ll x;
cin >> x;
sum += x;
}
m += n;
sum += n;
if(m < sum)
return cout << 0,0;
ll ans = 1;
factorial();
//cout << m << " " << sum << '\n';
for(int i=0;i<sum;i++)
{
ll val = (m - i)*(inv[sum - i])%mod;
//cout << val << "\n";
ans = (ans * val)%mod;
}
cout << ans;
}
| #include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 7;
vector<long long int> inverse;
void factorial_Initialize(int max){
inverse.assign(max+1,1);
for (int i=2; i<=max; i++){
inverse[i] = MOD - inverse[MOD % i] * (MOD / i) % MOD;
}
}
long long int nCr(int n, int r){
factorial_Initialize(r);
if(n < r || r < 0) return 0;
long long int ans = 1;
for(int i=0; i<r; i++){
ans = ans * (n-i) % MOD * inverse[i+1] % MOD;
}
return ans;
}
int main(){
int n, m;
cin >> n >> m;
int sum = 0;
vector<int> a(n);
for(int i=0; i<n; i++){
cin >> a[i];
sum += a[i];
}
long long int ans = nCr(m+n, sum+n);
cout << ans << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
//TEMPLATE
#define len(a) (ll) a.size()
#define ms(a, x) memset(a, x, sizeof a)
#define bitcount(n) __builtin_popcountll(n)
#define FR ios_base::sync_with_stdio(false);cin.tie(NULL)
#define cin1(a) cin >> a
#define cin2(a, b) cin >> a >> b
#define cin3(a, b, c) cin >> a >> b >> c
#define cin4(a, b, c, d) cin >> a >> b >> c >> d
#define cots(a) cout << a << " "
#define cot1(a) cout << a << "\n"
#define cot2(a, b) cout << a << " " << b << "\n"
#define cot3(a, b, c) cout << a << " " << b << " " << c << "\n"
#define cot4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << "\n"
#define cotcase(cs) cout << "Case " << cs << ": "
#define yes cout << "Yes\n"
#define no cout << "No\n"
#define line cout << "\n"
#define reversed(s) reverse(s.begin(), s.end())
#define asort(s) sort(s.begin(), s.end())
#define dsort(s) sort(s.rbegin(), s.rend())
#define all(s) s.begin(), s.end()
#define uniq(s) s.resize(distance(s.begin(),unique(s.begin(), s.end())))
#define found(s, x) (s.find(x) != s.end())
#define for0(i, n) for (i = 0; i < n; i++)
#define for1(i, n) for (i = 1; i <= n; i++)
#define fora(i, a, b) for (i = a; i <= b; i++)
#define forb(i, b, a) for (i = b; i >= a; i--)
#define ll long long
#define pb push_back
#define mp make_pair
#define ld long double
#define pii pair <ll, ll>
#define piii pair <ll, pii>
#define F first
#define S second
#define pi acos(-1)
const ll INF = LLONG_MAX;
const ll SZ = 17;
const ll mod = 1e9+7;
string s, s1, s2;
ll n, k, ans = 0;
ll a[SZ];
//ll b[SZ];
struct dat {
ll x, y, z;
} ct[SZ];
ll dp[20][(1LL<<SZ)+5];
bool check(ll x, ll pos) {
return (x & (1LL << pos));
}
ll set1(ll x, ll pos) {
return (x = x | (1LL << pos));
}
ll cal(dat c1, dat c2) {
ll d = abs(c1.x - c2.x) + abs(c1.y - c2.y) + max(0LL, c2.z-c1.z);
return d;
}
ll solve(ll in, ll msk) {
if(bitcount(msk) == n) return cal(ct[in], ct[0]);
ll i, t, &res = dp[in][msk];
if(res != -1) return res;
res = INF;
for0(i, n) {
if(check(msk, i)) continue;
t = cal(ct[in], ct[i]) + solve(i, set1(msk, i));
res = min(res, t);
}
return res;
}
int main() {
FR;
ll cs = 0, tc = 1, x, y, z, i, j, g, p, q, sum = 0, c = 0, t = 0;
// ll a, b, d;
// string s, s1, s2;
cin1(n);
for0(i, n) cin3(ct[i].x, ct[i].y, ct[i].z);
ms(dp, -1);
cot1(solve(0, 1));
return 0;
}
| //ll min_len[1<<8];
//void __(){
// _(ll,n);
// _(ll,m);
// _(vl,a,n);
// _(vpll,b,m);
// rep(bm,1<<n){
// ll w = 0;
// rep(i,n)
// if(bm&(1<<i))
// w += a[i];
// rep(i,m){
// if(b[i].Y < w)
// min_len[bm] = max(min_len[bm],b[i].X);
// }
// }
// rep(i,n)
// if(min_len[1<<i] != 0){
// print -1;
// return;
// }
// vi order(n);
// iota(all(order),0);
// ll ans = INF;
// do{
// vl x(n);
// rep(i,1,n-1){
// x[i] = x[i-1];
// ll bm = 1<<order[i];
// per(j,i){
// bm |= 1<<order[j];
// x[i] = max(x[i],min_len[bm]+x[j]);
// }
// }
// ans = min(ans,x.back());
// }while(next_permutation(all(order)));
// print ans;
//}
//
#include <numeric>
#include <iomanip>
#include <algorithm>
#include <cassert>
#include <vector>
#include <utility>
#include <iostream>
#include <string>
#define REP_INT(i,l,r) for(int i = (l); i <= (r); ++i)
#define REP_ZERO_INT(i,r) for(int i = 0; i < (r); ++i)
#define GET_REP_MACRO(_1,_2,_3,_4,NAME,...) NAME
#define rep(...) GET_REP_MACRO(__VA_ARGS__,REP_ANY,REP_INT,REP_ZERO_INT)(__VA_ARGS__)
#define PER_ZERO_INT(i,r) for(int i = (r)-1; i >= 0; --i)
#define GET_PER_MACRO(_1,_2,_3,_4,NAME,...) NAME
#define per(...) GET_PER_MACRO(__VA_ARGS__,PER_ANY,PER_INT,PER_ZERO_INT)(__VA_ARGS__)
#define all(v) (v).begin(), (v).end()
#define sz(v) ll(v.size())
#define X first
#define Y second
#define T1 template<typename T> static
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<int> vi;
const ll INF = ll(2e18) + 666;
T1 ostream& operator<<(ostream& stream, const vector<T>& t);
template <typename F, typename S> static
istream& operator>>(istream& stream, pair<F, S>& t){
return stream >> t.first >> t.second;
}
T1 istream& read(T, T, istream& = cin);
T1 istream& operator>>(istream& stream, vector<T>& t){
return read(all(t), stream);
}
T1 istream& read(T b, T e, istream& stream){
for(T it = b; it != e; ++it)
stream >> *it;
return stream;
}
struct _print {
string sep,end;
bool space;
ostream &stream;
_print(string _sep=" ",string _end="\n",
ostream &_stream = cout)
: sep(_sep),end(_end),space(false),
stream(_stream) {}
~_print() { stream << end; }
template <typename T>
_print &operator , (const T &t) {
if (space) stream << sep;
space = true;
stream << t;
return *this;
}
};
#define print _print(),
#define INPUT_WITHOUT_INIT(type,name) type name; cin >> name
#define _IWI(type,name,...) type name(__VA_ARGS__); cin >> name
#define GET_INPUT_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define _(...) GET_INPUT_MACRO(__VA_ARGS__,_IWI,_IWI,_IWI,_IWI,_IWI,_IWI,INPUT_WITHOUT_INIT)(__VA_ARGS__)
ll min_len[1<<8];
void __(){
_(ll,n);
_(ll,m);
_(vl,a,n);
_(vpll,b,m);
rep(bm,1<<n){
ll w = 0;
rep(i,n)
if(bm&(1<<i))
w += a[i];
rep(i,m){
if(b[i].Y < w)
min_len[bm] = max(min_len[bm],b[i].X);
}
}
rep(i,n)
if(min_len[1<<i] != 0){
print -1;
return;
}
vi order(n);
iota(all(order),0);
ll ans = INF;
do{
vl x(n);
rep(i,1,n-1){
x[i] = x[i-1];
ll bm = 1<<order[i];
per(j,i){
bm |= 1<<order[j];
x[i] = max(x[i],min_len[bm]+x[j]);
}
}
ans = min(ans,x.back());
}while(next_permutation(all(order)));
print ans;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(15);
__();
}
|
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define X first
#define Y second
#define nl '\n'
#define AC return 0
#define pb(a) push_back(a)
#define mst(a,b) memset(a, b, sizeof a)
#define rep(i,n) for(int i = 0; (i)<(n); i++)
#define rep1(i,n) for(int i = 1; (i)<=(n); i++)
#define scd(a) scanf("%lld", &a)
#define scdd(a,b) scanf("%lld%lld", &a, &b)
#define scs(s) scanf("%s", s)
//#pragma GCC optimize(2)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
const ll INF = (ll)0x3f3f3f3f3f3f3f, MAX = 9e18, MIN = -9e18;
const int N = 1e6+10, M = 2e6+10, mod = 1e9+7, inf = 0x3f3f3f3f;
pll a[N];
vector<ll> ans;
int main()
{
IOS;
int _;
// cin>>_;
_ = 1;
while(_--)
{
ll n;
cin>>n;
rep1(i, n) cin>>a[i].X>>a[i].Y;
sort(a+1, a+1+n);
ll mi1 = MAX, mi2 = MAX, mx1 = MIN, mx2 = MIN, id1 = 0, id2 = 0;
rep1(i, n)
{
if(a[i].Y <= mi1) mi2 = mi1, mi1 = a[i].Y, id1 = i;
else if(a[i].Y <= mi2) mi2 = a[i].Y;
if(a[i].Y >= mx1) mx2 = mx1, mx1 = a[i].Y, id2 = i;
else if(a[i].Y >= mx2) mx2 = a[i].Y;
}
ans.pb(a[n].X-a[1].X);
ans.pb(a[n].X-a[2].X);
ans.pb(a[n-1].X-a[1].X);
// cout<<id1<<' '<<id2<<nl;
if(id1 + id2 != n + 1 && (id1 != 1 || id1 != n || id2 != 1 || id2 != n))
ans.pb(mx1-mi1);//, cout<<"ok?"<<nl;
ans.pb(mx2-mi1);
ans.pb(mx1-mi2);
sort(ans.begin(), ans.end(), greater<ll>());
cout<<ans[1]<<nl;
}
AC;
}
| #include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using ld = long double;
using vld = vector<ld>;
using vb = vector<bool>;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define dbg(x) true
#endif
template <class T> bool chmin(T& a, T b) {
if(a > b) { a = b; return true; }
else return false;
}
template <class T> bool chmax(T& a, T b) {
if(a < b) { a = b; return true; }
else return false;
}
template <class T> ostream& operator<<(ostream& s, const vector<T>& a) {
for(auto i : a) s << i << ' ';
return s;
}
constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 62;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);
void solve() {
ll n;
cin >> n;
ll off = 0, ub = INFL, lb = -INFL;
while(n--) {
ll a, t;
cin >> a >> t;
if(t == 1) {
off += a;
}
else if(t == 2) {
a -= off;
chmax(lb, a);
if(lb > ub) ub = lb;
}
else {
a -= off;
chmin(ub, a);
if(lb > ub) lb = ub;
}
}
ll q;
cin >> q;
while(q--) {
ll x;
cin >> x;
if(ub == lb) cout << ub+off << endl;
else if(x < lb) cout << lb+off << endl;
else if(ub < x) cout << ub+off << endl;
else cout << x+off << endl;
}
return;
}
int main() {
std::cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
cout << fixed << setprecision(15);
solve();
} |
#include <bits/stdc++.h>
using namespace std;
int main(){
string S;
cin >> S;
int N = S.size();
bool ok = true;
for (int i = 0; i < N; i++){
if (i % 2 == 0){
if (isupper(S[i])){
ok = false;
}
} else {
if (islower(S[i])){
ok = false;
}
}
}
if (ok){
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// THINGS TO REMEMBER
// ENDL is slow, '\n' is fast
// Clear everything (including graphs) between test cases
// use anti-anti-hash: https://codeforces.com/blog/entry/62393
// pb-ds: https://codeforces.com/blog/entry/11080
// check when to use LLONG_MAX/LLONG_MIN vs INT_MAX or INT_MIN
// You frequently suffer from confirmation bias - you trust your initial solution and miss simple things.
// When you hit a roadblock, remember to rethink the solution ground up, not just try hacky fixes
int main(){
#ifndef ONLINE_JUDGE
freopen("input", "r", stdin);
freopen("output", "w", stdout);
freopen("error", "w", stderr);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string n;
cin>>n;
ll ans=INT_MAX;
ll sz=n.size();
for(int i=0;i<(1<<sz)-1;i++){
ll c=0;
for(int j=0;j<sz;j++){
if(((i>>j)&1)==0){
c+=n[j]-'0';
}
}
// cerr<<i<<" "<<c<<endl;
if(c%3==0){
ans=min(ans,(ll)__builtin_popcount(i));
}
}
if(ans==INT_MAX){
cout<<-1<<endl;
}
else{
cout<<ans<<endl;
}
} |
#include<iostream>
#define MAX_N 300000
using namespace std;
typedef long long ll;
ll N, a[MAX_N], ans[MAX_N];
ll bit[MAX_N + 1];
int sum(int i) {
int s = 0;
while (i > 0) {
s += bit[i];
i -= i & -i;
}
return s;
}
void add(int i, int x) {
while (i <= N) {
bit[i] += x;
i += i & -i;
}
}
int main() {
cin >> N;
for (int i = 0; i < N; i++)cin >> a[i];
for (ll i = 0; i < N; i++) {
ans[0] += i - sum(a[i] + 1);
add(a[i] + 1, 1);
}
for (int i = 0; i < N - 1; i++) {
ans[i + 1] = ans[i] + N - 2 * a[i] - 1;
}
for (int i = 0; i < N; i++) {
cout << ans[i] << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<vector<int>>C(N, vector<int>(N));
for(int i=0; i<N; i++){
for(int j=0; j<N; j++){
cin >> C[i][j];
}
}
vector<int>A(N);
vector<int>B(N);
int mini=1000000001;
for(int i=0; i<N; i++){
B[i]=C[0][i]-C[0][0];
mini=min(B[i], mini);
}
for(int i=0; i<N; i++){
for(int j=0; j<N; j++){
if(B[j]!=C[i][j]-C[i][0]){
cout << "No" << endl;
return 0;
}
}
}
for(int i=0; i<N; i++)B[i]-=mini;
for(int i=0; i<N; i++){
A[i]=C[i][0]-B[0];
}
cout << "Yes" << endl;
for(int i=0; i<N; i++){
if(i!=N-1)cout << A[i] << ' ';
else cout << A[i] << endl;
}
for(int i=0; i<N; i++){
if(i!=N-1)cout << B[i] << ' ';
else cout << B[i] << endl;
}
} |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
long long modpow(long long a, long long b){
long long ans = 1;
while (b > 0){
if (b % 2 == 1){
ans *= a;
ans %= MOD;
}
a *= a;
a %= MOD;
b /= 2;
}
return ans;
}
long long modinv(long long a){
return modpow(a, MOD - 2);
}
vector<long long> mf = {1};
vector<long long> mfi = {1};
long long modfact(int n){
if (mf.size() > n){
return mf[n];
} else {
for (int i = mf.size(); i <= n; i++){
long long next = mf.back() * i % MOD;
mf.push_back(next);
mfi.push_back(modinv(next));
}
return mf[n];
}
}
long long modfactinv(int n){
if (mfi.size() > n){
return mfi[n];
} else {
return modinv(modfact(n));
}
}
long long modbinom(int n, int k){
if (n < 0 || k < 0 || k > n){
return 0;
} else {
return modfact(n) * modfactinv(k) % MOD * modfactinv(n - k) % MOD;
}
}
int main(){
int N, M, K;
cin >> N >> M >> K;
if (N > M + K){
cout << 0 << endl;
} else {
long long ans = modbinom(N + M, N);
int a = N - K - 1, b = K + M + 1;
ans -= modbinom(a + b, a);
if (ans < 0){
ans += MOD;
}
cout << ans << endl;
}
} | // Author : Shivraj Ahirwar //
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep1(i,n) for (int i = 1; i < n; ++i)
#define REP(i,k,n) for (int i = k; i <= n; ++i)
#define REPR(i,k,n) for (int i = k; i >= n; --i)
#define ll long long int
#define nx cout<<"\n";
#define mod 1e9+7
//===================================================================================================================================
int main()
{
std::ios_base::sync_with_stdio(false);
cin.tie(NULL);
int tc = 1;
// cin>>tc;
while (tc--){
ll a,b,c;
cin>>a>>b>>c;
if(a*b>=0){
if(a<0){
if(c%2==0){
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<b) cout<<"<";
else if(a>b) cout<<">";
else cout<<"=";
}
}
else{
if(c%2==0){
if(abs(a)<abs(b)) cout<<"<";
else if(abs(a)>abs(b)) cout<<">";
else cout<<"=";
}
else{
if(a<b) cout<<"<";
else if(a>b) cout<<">";
else cout<<"=";
}
}
// else{
// if(c%2==0){
// if(abs(a)<abs(b)) cout<<"<";
// else if(abs(a)<abs(b)) cout<<">";
// else cout<<"=";
// }
// else{
// if(a<b) cout<<"<";
// else if(a>b) cout<<">";
// else cout<<"=";
// }
// }
nx
}
return 0;
} |
#include<bits/stdc++.h>
using namespace std ;
#define Next( i, x ) for( register int i = head[x]; i; i = e[i].next )
#define rep( i, s, t ) for( register int i = (s); i <= (t); ++ i )
#define drep( i, s, t ) for( register int i = (t); i >= (s); -- i )
#define re register
#define int long long
int gi() {
char cc = getchar() ; int cn = 0, flus = 1 ;
while( cc < '0' || cc > '9' ) { if( cc == '-' ) flus = - flus ; cc = getchar() ; }
while( cc >= '0' && cc <= '9' ) cn = cn * 10 + cc - '0', cc = getchar() ;
return cn * flus ;
}
const int N = 5e5 + 5 ;
int n ;
char s[N], t[N] ;
void out() {
puts("-1") ; exit(0) ;
}
int st[N], top ;
signed main()
{
n = gi() ;
scanf("%s", s + 1 ) ;
scanf("%s", t + 1 ) ;
int a = 0, b = 0 ;
rep( i, 1, n ) a += (s[i] == '1') ;
rep( i, 1, n ) b += (t[i] == '1') ;
if( a < b ) out() ;
if( (a % 2) != (b % 2) ) out() ;
int Ans = 0 ;
for(re int i = n; i >= 1; -- i) {
if( s[i] == '1' ) st[++ top] = i ;
if( t[i] == '1' ) {
if(top == 0) out() ;
Ans += (st[top] - i), -- top ;
}
}
for(re int i = 1; i <= top; i += 2) {
int u = st[i] - st[i + 1] ;
Ans += u ;
}
cout << Ans << endl ;
return 0 ;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
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; }
map<ll, ll> memo;
ll x, y;
ll solve(ll y) {
if (x >= y) return memo[y] = x-y;
if (memo.count(y)) return memo[y];
ll res = y-x;
if (y % 2 == 0) chmin(res, solve(y/2)+ 1);
else chmin(res, 1 + min(solve(y+1), solve(y-1)));
return memo[y] = res;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> x >> y;
cout << solve(y) << endl;
return 0;
} |
//→__int128_tを使う&GNU C++17 (64)で提出する
//インクルードなど
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//イテレーション
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
#define FORA(i,I) for(const auto& i:I)
//x:コンテナ
#define ALL(x) x.begin(),x.end()
#define SIZE(x) ll(x.size())
//定数
#define INF32 2147483647 //2.147483647×10^{9}:32bit整数のinf
#define INF64 9223372036854775807 //9.223372036854775807×10^{18}:64bit整数のinf
#define MOD 1000000007 //問題による
//略記
#define F first
#define S second
//出力(空白区切りで昇順に)
#define coutALL(x) for(auto i=x.begin();i!=--x.end();i++)cout<<*i<<" ";cout<<*--x.end()<<endl;
//aをbで割る時の繰上げ,繰り下げ
ll myceil(ll a,ll b){return (a+(b-1))/b;}
ll myfloor(ll a,ll b){return a/b;}
long long comb(int n, int r) {
if(r > n - r) r = n - r; // because C(n, r) == C(n, n - r)
long long ans = 1;
int i;
for(i = 1; i <= r; i++) {
ans *= n - r + i;
ans /= i;
}
return ans;
}
signed main(){
ll a,b,k;
cin >> a >> b >> k;
ll c;
ll n=a+b;
k--;
for(ll i=0;i<n;i++){
if(a>0){
c=comb(a+b-1,b);
if(k<c){
cout << "a";
a--;
}
else {
cout << "b";
k -= c;
b--;
}
}
else {
cout << 'b';
b--;
}
}
cout << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define rng(v) v.begin(),v.end()
#define rngr(v) v.rbegin(),v.rend()
const long long INF = 1LL << 60;
using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using P3 = tuple<int, int, int>;
#define vi vector<int>
#define vvi vector<vi>
#define vll vector<ll>
#define vs vector<string>
using vp = vector<P>;
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; }
using CP = complex<double>;
double dot( const CP &z, const CP &w ){ return (z.real()*w.real() + z.imag()*w.imag()); }
double cross( const CP &z, const CP &w ){ return (z.real()*w.imag() - z.imag()*w.real()); }
int n;
string s, x;
vvi memo;
bool dp(int i = 0, int r = 0){
if(memo[i][r] != -1) return memo[i][r] ;
if(i == n) return r==0;
int a = s[i]-'0';
int b = ((r*10+a)%7), c = ((r*10)%7);
if(memo[i+1][b] == -1) memo[i+1][b] = dp(i+1, b);
if(memo[i+1][c] == -1) memo[i+1][c] = dp(i+1, c);
if(x[i] == 'A'){
return memo[i+1][b] && memo[i+1][c];
//return (dp(i+1, (r*10+a)%7)) && (dp(i+1, (r*10)%7));
}else{
return memo[i+1][b] || memo[i+1][c];
//return (dp(i+1, (r*10+a)%7)) || (dp(i+1, (r*10)%7));
}
}
int main()
{
cin >> n >> s >> x;
memo.resize(n+1, vi(7, -1));
if(dp()) cout << "Takahashi" << endl;
else cout << "Aoki" << endl;
return 0;
} |
#include <cstdio>
#include <cstring>
#define N 110
#define mo 998244353
using namespace std;
int f[N][5010];
int n, w[N];
int sum;
int jc[N];
int ans;
int main(){
// freopen("funny.in", "r", stdin);
scanf("%d", &n);
for (int i=1; i<=n; i++) scanf("%d", &w[i]), sum+=w[i];
jc[0]=1;
for (int i=1; i<=n; i++) jc[i]=1ll*jc[i-1]*i%mo;
if (sum%2==1){
printf("%d\n", 0);
return 0;
}
int sx=sum/2;
f[0][0]=1;
for (int i=1; i<=n; i++){
for (int j=n; j; j--){
for (int k=w[i]; k<=sx; k++){
(f[j][k]+=f[j-1][k-w[i]])%=mo;
}
}
}
for (int i=1; i<=n; i++){
(ans+=1ll*jc[i]*jc[n-i]%mo*f[i][sx]%mo)%=mo;
}
printf("%d\n", ans);
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 = 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;}
struct modint {
long long x;
modint(long long x=0):x((x%MOD+MOD)%MOD){}
long long val(){
return x;
}
modint operator-() const { return modint(-x);}
modint& operator+=(const modint a) {
if ((x += a.x) >= MOD) x -= MOD;
return *this;
}
modint& operator-=(const modint a) {
if ((x += MOD-a.x) >= MOD) x -= MOD;
return *this;
}
modint& operator*=(const modint a) {
(x *= a.x) %= MOD;
return *this;
}
modint operator+(const modint a) const {
modint res(*this);
return res+=a;
}
modint operator-(const modint a) const {
modint res(*this);
return res-=a;
}
modint operator*(const modint a) const {
modint res(*this);
return res*=a;
}
modint pow(long long t) const {
if (!t) return 1;
modint a = pow(t>>1);
a *= a;
if (t&1) a *= *this;
return a;
}
// must be gcd(x,MOD)==1
modint inv() const {
// a^{-1} = 1/a MOD p (拡張Euclidの互除法)
long long b = MOD, u = 1, v = 0, z = x;
while(b){
long long t = z / b;
z -= t * b; swap(z, b);
u -= t * v; swap(u, v);
}
u %= MOD;
if (u < 0) u += MOD;
return modint(u);
}
//modint inv() const {
// return pow(MOD-2);
//}
modint& operator/=(const modint a) {
return (*this) *= a.inv();
}
modint operator/(const modint a) const {
modint res(*this);
return res/=a;
}
};
using mint = modint;
struct Factorial{
vector<mint> fact, ifact;
Factorial(int N): fact(N+1), ifact(N+1) {
assert(N < MOD);
fact[0] = 1;
for(int i=0; i<N; i++) fact[i+1] = fact[i] * (i+1);
ifact[N] = fact[N].inv();
for(int i=N; i>0; i--) ifact[i-1] = ifact[i] * i;
}
mint C(int n, int k){
if (k < 0 || k > n) return 0;
return fact[n]*ifact[k]*ifact[n-k];
}
mint P(int n, int k){
if (k < 0 || k > n) return 0;
return fact[n]*ifact[n-k];
}
mint inv(int n){
assert(n>0);
return fact[n-1]*ifact[n];
}
};
mint dp[101][101][10101];
void Main(){
int N; cin >> N;
int sum = 0;
Factorial F(100);
dp[0][0][0] = 1;
REP(i,N){
int w; cin >> w; sum += w;
REP(j,i+1)REP(k,10000){
dp[i+1][j+1][k+w] += dp[i][j][k];
dp[i+1][j][k] += dp[i][j][k];
}
}
if(sum&1){
cout << 0 << en;
return;
}
sum >>= 1;
mint ans(0);
REP(i,N+1){
ans += dp[N][i][sum] * F.fact[i] * F.fact[N-i];
}
cout << ans.x << 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;
while(t--) Main();
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
const ll MAX = 1001001;
const ll MOD = 1000000007;
const long double pi = 2.0 * asin(1.0);
ll dx[4] = {1, 0, -1, 0};
ll dy[4] = {0, 1, 0, -1};
ll modpow(ll a, ll n, ll mod)
{
ll res = 1;
while (n > 0)
{
if (n & 1)
res = res * a % mod;
a = a % mod * (a % mod) % mod;
n >>= 1;
}
return res;
}
int main()
{
ll n, p;
cin >> n >> p;
ll ans = (p - 1) * modpow(p - 2, n - 1, MOD) % MOD;
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
const int P = 1e9+7;
/*struct mat{
int a[3][3];
void start() {
for (int i = 0; i < 2; ++i) {
for (int j = 0; j < 2; ++j) {
a[i][j] = 0;
}
}
for (int i = 0; i < 2; ++i) {
a[i][i] = 1;
}
}
} base;
mat mult(mat a, mat b) {
mat res;
res.start();
for (int k = 0; k < 2; ++k) {
for (int i = 0; i < 2; ++i) {
for (int j = 0; j < 2; ++j) {
res.a[i][j] += (a.a[i][k] * 1ll * b.a[k][j])%P;
res.a[i][j] %= P;
}
}
}
return res;
};
mat fpow(mat a, int k) {
mat res;
res.start();
for (;k; k>>=1, a = mult(a, a)) {
if(k&1) {
res = mult(res, a);
}
}
return res;
}
int main() {
long long n, p;
cin >> n >> p;
base.a[0][0] = p;
base.a[0][1] = 0;
base.a[1][0] = p-1;
base.a[1][1] = 1;
mat ans = fpow(base, n-1);
cout << (3ll*ans.a[1][0])%P << endl;
}*/
int fpow(int a, int k) {
int res = 1;
for (;k; k>>=1, a = a * 1ll * a % P) {
if(k&1) {
res = res * 1ll * a % P;
}
}
return res;
}
int main() {
long long n, p;
cin >> n >> p;
if(p==2) {
if(n == 1) cout << 1 << endl;
else cout << 0 << endl;
} else {
int ans = fpow((p-2), n-1);
cout << ((p-1) * 1ll * ans) % P << endl;
}
} |
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
template<typename T>
long long modpow(const T n,const T p,const T mod);
template<typename T>
long long modinv(const T n,const T mod);
template<typename T>
bool chmax(T &a,const T &b);
template<typename T>
bool chmin(T &a,const T &b);
long long inf=1000000007;
int main(){
long long n;
cin>>n;
vector<vector<long long>> tosi(n,vector<long long>(3));
for(long long i=0;i<n;i++) cin>>tosi.at(i).at(0)>>tosi.at(i).at(1)>>tosi.at(i).at(2);
vector<vector<long long>> dp(n,vector<long long>(modpow((long long)2,n,inf),inf));
dp.at(0).at(0)=0;
for(long long i=0;i<(1<<n);i++){
bitset<18> bits=i;
for(long long j=0;j<n;j++){
if(!(i==0 && j==0) && bits.test(j)==false) continue;
for(long long k=0;k<n;k++){
if(bits.test(k)) continue;
long long a=abs(tosi.at(j).at(0)-tosi.at(k).at(0));
long long b=abs(tosi.at(j).at(1)-tosi.at(k).at(1));
long long c=max((long long)0,tosi.at(k).at(2)-tosi.at(j).at(2));
chmin(dp.at(k).at(i+modpow((long long)2,k,inf)),dp.at(j).at(i)+a+b+c);
}
}
}
cout<<dp.at(0).at(modpow((long long)2,n,inf)-1)<<endl;
return 0;
}
template<typename T>
long long modpow(const T n,const T p,const T mod){
if(p==0) return 1;
if(p%2==0){
long long a=modpow(n,p/2,mod);
return a*a%mod;
}
if(p%2==1) return (modpow(n,p-1,mod)*n)%mod;
cerr<<"ERROR"<<endl;
return 1;
}
template<typename T>
long long modinv(const T n,const T mod){
return modpow(n,mod-2,mod);
}
template<typename T>
bool chmax(T &a,const T &b){
if(a<b){
a=b;
return 1;
}
return 0;
}
template<typename T>
bool chmin(T &a,const T &b){
if(a>b){
a=b;
return 1;
}
return 0;
}
| #include <bits/stdc++.h>
#define F(i, l, r) for(int i = (l), _end_ = (int)(r); i <= _end_; ++i)
#define f(i, r, l) for(int i = (r), _end_ = (int)(l); i >= _end_; --i)
#define Set(a, v) memset(a, v, sizeof(a))
#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
using namespace std;
bool chkmin(int &a, int b) {return b < a ? a = b, 1 : 0;}
bool chkmax(int &a, int b) {return b > a ? a = b, 1 : 0;}
inline int read() {
int x = 0, fh = 1; char ch = getchar();
for (; !isdigit(ch); ch = getchar() ) if (ch == '-') fh = -1;
for (; isdigit(ch); ch = getchar() ) x = (x<<1) + (x<<3) + (ch ^ '0');
return x * fh;
}
int a,b,c,d;
int main () {
#ifndef ONLINE_JUDGE
file("e");
#endif
a=read();
b=read();
c=read();
d=read();
printf("%d\n",a*d-b*c);
return 0;
}
|
#pragma region Region_1
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
using ll = long long;
using P = pair<ll, ll>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VP = vector<P>;
using VS = vector<string>;
using VC = vector<char>;
using VVC = vector<vector<char>>;
#define MOD 1000000007
const int INF = (int)1e9 + 10; // int max > 2*10^9
const long long INFL = (ll)2e18 + 10; // ll max > 9*10^18
template <class T, class C>
bool chmax(T& a, C b) { if (a < b) { a = b; return true; } return false; }
template <class T, class C>
bool chmin(T& a, C b) { if (a > b) { a = b; return true; } return false; }
template <class T> T sum(const vector<T>& v) {
T res = 0;
for (size_t i = 0; i < v.size(); ++i) res += v[i];
return res;
}
/////////////////////////////////////////////////////////
// print like python
// https://qiita.com/Lily0727K/items/06cb1d6da8a436369eed
/////////////////////////////////////////////////////////
void print() { cout << endl; }
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {
cout << head;
if (sizeof...(tail) != 0) cout << " ";
print(forward<Tail>(tail)...);
}
template <class T> void print(vector<T>& vec) {
for (auto& a : vec) {
cout << a;
if (&a != &vec.back()) cout << " ";
}
cout << endl;
}
template <class T> void print(vector<vector<T>>& df) {
for (auto& vec : df) {
print(vec);
}
}
#pragma endregion Region_1
/////////////////////////////////////////////////////////
struct mint {
ll x; // typedef long long ll;
int mod;
mint(ll x = 0, int mod = MOD) : x((x % mod + mod) % mod), mod(mod) {}
mint operator-() const { return mint(-x); }
mint& operator+=(const mint a) {
if ((x += a.x) >= mod) x -= mod;
return *this;
}
mint& operator-=(const mint a) {
if ((x += mod - a.x) >= mod) x -= mod;
return *this;
}
mint& operator*=(const mint a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const {
mint res(*this);
return res += a;
}
mint operator-(const mint a) const {
mint res(*this);
return res -= a;
}
mint operator*(const mint a) const {
mint res(*this);
return res *= a;
}
// x^t
mint pow(ll t) const {
if (!t) return 1;
mint a = pow(t >> 1);
a *= a;// 桁ずらし
if (t & 1) a *= *this;
return a;
}
// for prime mod
mint inv() const { return pow(mod - 2); }
mint& operator/=(const mint a) { return (*this) *= a.inv(); }
mint operator/(const mint a) const {
mint res(*this);
return res /= a;
}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }
int main() {
//入力の高速化用のコード
ios::sync_with_stdio(false);
cin.tie(nullptr);
std::cout << std::setprecision(15);
//////////////////////////////////////////
ll n ,p;
cin >> n >> p;
mint x = p-2;
x = x.pow(n-1) * (p-1);
print(x.x);
return 0;
}
| #include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using LL = long long;
using P = pair<int,int>;
class FenwickTree {
private:
int bit_size;
vector<LL> bit;
public:
FenwickTree(int siz): bit_size(siz), bit(siz + 1) {}
void add(int num, LL val) {
for(int i = num + 1; i <= bit_size; i += i & -i) {
bit[i] += val;
}
}
LL sum(int end) {
LL res = 0;
for(int i = end + 1; i > 0; i -= i & -i) {
res += bit[i];
}
return res;
}
LL sum(int begin, int end) {
return sum(end - 1) - sum(begin - 1);
}
void init(LL val) {
for(int i = 1; i <= bit_size; i++) {
add(i, val);
}
}
int lower_bound(LL val) {
if(val <= 0) return 0;
int i = 0, n = 1;
while(n * 2 <= bit_size) n *= 2;
for(int k = n; k > 0; k /= 2) {
if(i + k <= bit_size && bit[i + k] < val) {
val -= bit[i + k];
i += k;
}
}
return i + 1;
}
};
int main(){
int N;
cin >> N;
vector<int> a(N);
rep(i,N) cin >> a[i];
vector<LL> left(N), right(N), ans(N+1);
LL res = 0;
FenwickTree ftl(N), ftr(N);
rep(i,N){
left[i] = 2 * ftl.sum(a[i]) - i;
res += i - ftl.sum(a[i]);
ftl.add(a[i], 1);
}
for(int i = N - 1; i >= 0; i--){
right[i] = 2 * ftr.sum(a[i]) - (N - 1 - i);
ftr.add(a[i], 1);
}
ans[N] = res;
rep(i,N){
ans[N-1-i] = ans[N-i] + left[N-1-i] + right[N-1-i];
}
//cout << res << endl;
rep(i,N) cout << ans[i] << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main(){
int N,M; cin >> N >> M;
if(M==0){
cout << 1 << endl;
}else{
vector<int> A(M), S(M+1);
int k=N;
for(int i=0; i<M; i++) cin >> A[i];
sort(A.begin(),A.end());
for(int i=0; i<M; i++){
if(i==0){
S[0]=A[0]-1;
if(S[0]>0) k=min(k,S[0]);
}else{
S[i]=A[i]-A[i-1]-1;
if(S[i]>0) k=min(k,S[i]);
if(i==M-1){
S[M]=N-A[M-1];
if(S[M]>0) k=min(k,S[M]);
}
}
}
int result=0;
for(int i=0; i<=M; i++){
result+=((S[i]+k-1)/k);
}
cout << result << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using pl = pair<ll, ll>;
using vl = vector<ll>;
using vp = vector< pair<ll, ll> >;
using vvl = vector<vl>;
using vs = vector<string>;
#define pi 3.14159265359;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (ll)(s); i < (ll)(n); i++)
#define rep3(i, s, n) for (ll i = (ll)(n); i >= (ll)(s); i--)
#define all(v) v.begin(), v.end()
template<class T> void chmax(T& a, T b) {
if (a < b) a = b;
}
template<class T> void chmin(T& a, T b) {
if (a > b) a = b;
}
ll binary_search2(ll key, vl vec) {
ll left = 0, right = vec.size() - 1;
while (right >= left) {
ll mid = left + (right - left) / 2;
if (vec[mid] == key) return mid;
else if (vec[mid] > key) right = mid - 1;
else left = mid + 1;
}
return left;
}
ll search(ll key, vl vec) {
rep(i, vec.size()) {
if (key <= vec[i]) return i;
}
return -1;
}
int main() {
ll n, m, q;
cin >> n >> m >> q;
vp vw(n);
rep(i, n) cin >> vw[i].second >> vw[i].first;
sort(vw.begin(), vw.end(), greater<pl>());
vl x(m);
rep(i, m) cin >> x[i];
vp lr(q);
rep(i, q) cin >> lr[i].first >> lr[i].second;
rep(i, q) {
vl ex(0);
rep(j, m) {
if (j < lr[i].first - 1 || j > lr[i].second - 1) {
ex.push_back(x[j]);
}
}
sort(all(ex));
ll len = ex.size();
vector<bool> used(len, true);
ll ansi = 0;
rep(a, n) {
if (ex.size() == 0) break;
ll value = vw[a].first;
ll weight = vw[a].second;
rep(b, len) {
if (weight <= ex[b] && used[b]) {
ansi += value;
used[b] = false;
break;
}
}
}
cout << ansi << endl;
}
} |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(int)(n);++i)
#define fixed(n)fixed<<setprecision(n)
#define ll long long
#define ALL(a)a.begin(),a.end()
#define LLA(a)a.rbegin(),a.rend()
template<class T>void chmin(T& a,T b){
if(a>b){
a=b;
}
}
template<class T>void chmax(T& a,T b){
if(a<b){
a=b;
}
}
ll gcd(ll a,ll b){
if(b==0)return a;
else return gcd(b,a%b);
}
ll lcm(ll a,ll b){
return a/gcd(a,b)*b;
}
const long long INF=1LL<<60;
const long long MOD=1000000007;
int main(){
int N;cin>>N;
vector<int>A(N);
rep(i,N){
cin>>A[i];
}
ll MIN=INF;
for(int bit=0;bit<(1<<(N-1));++bit){
vector<int>S(N);
rep(i,N){
if(N==0)S[i]=0;
else if(bit&(1<<(i-1))){
S[i]=1;
}
}
vector<int>OR;
ll orr=0;
rep(i,N){
if(S[i]==1){
OR.push_back(orr);
orr=A[i];
}else{
orr=orr|A[i];
}
}if(orr!=0){
OR.push_back(orr);
}
ll xorr=0;
rep(i,OR.size()){
xorr=xorr^OR[i];
}
chmin(MIN,xorr);
}
cout<<MIN;
} | #include <bits/stdc++.h>
#define FASTIO
using namespace std;
using ll = long long;
using Vi = std::vector<int>;
using Vl = std::vector<ll>;
using Pii = std::pair<int, int>;
using Pll = std::pair<ll, ll>;
constexpr int I_INF = std::numeric_limits<int>::max();
constexpr ll L_INF = std::numeric_limits<ll>::max();
template <typename T1, typename T2>
inline bool chmin(T1& a, const T2& b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <typename T1, typename T2>
inline bool chmax(T1& a, const T2& b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <std::ostream& os = std::cout>
class Prints {
private:
class __Prints {
public:
__Prints(const char* sep, const char* term) : sep(sep), term(term) {}
template <class... Args>
auto operator()(const Args&... args) const -> decltype((os << ... << std::declval<Args>()), void()) { print(args...); }
template <typename T>
auto pvec(const T& vec, size_t sz) const -> decltype(os << std::declval<decltype(std::declval<T>()[0])>(), void()) {
for (size_t i = 0; i < sz; i++)
os << vec[i] << (i == sz - 1 ? term : sep);
}
template <typename T>
auto pmat(const T& mat, size_t h, size_t w) -> decltype(os << std::declval<decltype(std::declval<T>()[0][0])>(), void()) {
for (size_t i = 0; i < h; i++)
for (size_t j = 0; j < w; j++)
os << mat[i][j] << (j == w - 1 ? term : sep);
}
private:
const char *sep, *term;
void print() const { os << term; }
void print_rest() const { os << term; }
template <class T, class... Tail>
void print(const T& head, const Tail&... tail) const { os << head, print_rest(tail...); }
template <class T, class... Tail>
void print_rest(const T& head, const Tail&... tail) const { os << sep << head, print_rest(tail...); }
};
public:
Prints() {}
__Prints operator()(const char* sep = " ", const char* term = "\n") const { return __Prints(sep, term); }
};
Prints<> prints;
Prints<std::cerr> prints_err;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void solve() {
int N;
cin >> N;
Vl A(N), B(N), P(N), invP(N);
for (ll i = 0; i < N; i++) {
cin >> A[i];
}
for (ll i = 0; i < N; i++) {
cin >> B[i];
}
for (ll i = 0; i < N; i++) {
int p;
cin >> p;
--p;
P[i] = p;
invP[p] = i;
}
Vi ord(N);
iota(ord.begin(), ord.end(), 0);
sort(ord.begin(), ord.end(), [&](int l, int r) { return A[l] < A[r]; });
vector<Pii> ans;
for (ll i = 0; i < N; i++) {
int u = ord[i];
int to = invP[u];
if (u == to) continue;
if (A[u] <= B[P[u]] || A[to] <= B[P[to]]) {
prints()(-1);
return;
}
int t = P[u];
ans.emplace_back(u, to);
P[u] = u;
P[to] = t;
invP[u] = u;
invP[t] = to;
}
prints()(ans.size());
for (auto [a, b] : ans) {
prints()(a + 1, b + 1);
}
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
int main() {
#ifdef FASTIO
std::cin.tie(nullptr), std::cout.tie(nullptr);
std::ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
std::ifstream ifs("./in_out/input.txt");
std::cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
std::ofstream ofs("./in_out/output.txt");
std::cout.rdbuf(ofs.rdbuf());
#endif
std::cout << std::setprecision(18) << std::fixed;
solve();
std::cout << std::flush;
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;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int inf=0x3f,INF=0x3f3f3f3f; const ll LLINF=0x3f3f3f3f3f3f3f3f;
#define sz(x) (int)x.size()
#define af(x) x.begin(), x.end()
#define ms(x, y) memset(x, y, sizeof x);
#define fil(x, y) fill(af(x), y);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define f first
#define s second
#define lc i << 1
#define rc i << 1 | 1
const int mod = 1e9 + 7;
ll fpow(ll a, ll b){ll ret=1;while(b){if(b&1)ret=ret*a%mod;a=a*a%mod,b>>=1;}return ret;}
ll inv(ll x){return x ? fpow(x, mod - 2) : 1;}
void madd(int &a, int b){a+=b;if(a>=mod)a-=mod;}
void msub(int &a, int b){a+=mod-b;if(a>=mod)a-=mod;}
const int MM = 2e5 + 5;
void solve(){
int n, k;
cin >> n >> k;
vector<vector<int>> g(n, vector<int>(n));
for (auto &v : g) for (auto &x : v) cin >> x;
vector<int> ord(n);
for (int i = 0; i < n; i++) ord[i] = i;
int ans = 0;
do{
int sum = 0;
for (int i = 0; i < n; i++)
sum += g[ord[i]][ord[(i+1)%n]];
ans += sum == k && ord[0] == 0;
} while(next_permutation(af(ord)));
cout << ans << '\n';
}
int main(){
cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);
int t = 1;
//cin >> t;
while(t--) solve();
}
| #include<iostream>
#include<cstdio>
#include<cstring>
#define MAXM 25
typedef long long ll;
using namespace std;
ll n,m;
ll cnt[3],ans;
char a[MAXM];
int main(){
cin>>n>>m;
ll zz = 0;
for(int i = 1 ; i <= n ; i++){
zz = 0;
scanf("%s" , a + 1);
for(int j = 1 ; j <= m ; j++)zz += (a[j] == '1');
zz %= 2;
if(zz % 2 == 1)ans += cnt[0];
else ans += cnt[1];
cnt[zz]++;
}
cout<<ans<<endl;
} |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{ll n;
cin>>n;
ll ans=0;
ll a[n],b[n];
for(ll i=0;i<n;i++)cin>>a[i];
for(ll j=0;j<n;j++)cin>>b[j];
for(ll i=0;i<n;i++)ans+=a[i]*b[i];
if(ans==0)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
| #define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;typedef long double ld;typedef vector <int> vi;typedef vector <ll> vll;typedef vector <string> vS;typedef vector <vector <int>> vv;typedef map<int, int> mi;typedef map<string, int> ms;typedef map<char, int> mc;typedef string S;typedef map <ll, ll> ml;typedef map <int, bool> mb;
#define FOR(i,N) for(int i = 0 ; i < N;i++)
#define eFOR(i,a,b) for(int i = a; i <=b;i++)
#define dFOR(i,N) for(int i = N - 1; i>=0;i--)
#define edFOR(i,a,b) for(int i = b ; i >=a;i--)
#define all(x) x.begin(),x.end()
#define SORT(x) sort(all(x))
#define RSORT(x) sort(x.rbegin(),x.rend())
#define mine(x) min_element(all(x))
#define maxe(x) max_element(all(x))
#define pb push_back
#define PI 3.14159265359
#define mod 1000000007
int CASE = 1;
void solve()
{
int n;
cin >> n;
vi a(n), b(n);
FOR(i, n)
cin >> a[i];
FOR(i, n)
cin >> b[i];
int cnt = 0;
FOR(i, n)
cnt += a[i] * b[i];
cout << (cnt ? "No" : "Yes");
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int T = 1;
while (T--)
{
solve();
}
} |
// B - Plus Matrix
#include <bits/stdc++.h>
using namespace std;
#define vec vector
using vi = vec<int>;
#define rep(i,e) for(int i=0;i<(e);++i)
int main(){
int n; cin>>n;
vec<vi> C(n, vi(n)); rep(i, n) rep(j, n) cin>>C[i][j];
vi B(n, 1e9), A(n, 0);
rep(i, n) rep(j, n) B[i] = min(B[i], C[j][i]);
rep(i, n){
rep(j, n) A[i] = max(A[i], C[i][j] - B[j]);
B[i] = C[i][i] - A[i];
}
rep(i, n) rep(j, n) if(A[i] + B[j] != C[i][j]){ puts("No"); return 0; }
puts("Yes");
rep(i, n) cout<< A[i] <<(i<n-1? " ":"\n");
rep(i, n) cout<< B[i] <<(i<n-1? " ":"\n");
}
| #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i,a,b) for(int i=a;i<=b;i++)
inline ll r() {
ll x=0,f=1;
char c=getchar();
while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
while(isdigit(c))x=x*10+c-'0',c=getchar();
return x*f;
}
#define d r()
ll n,tmp,k;
int main(){
n=d;
if(n==0){
cout<<0;
return 0;
}
if(n==2){
cout<<1;
return 0;
}
ll k=max((ll)0,(ll)sqrt(2*n+2)-100);
tmp=(1+k)*k/2;
while(1){
if(tmp>n+1)break;
k++;
tmp+=k;
}
k--;
cout<<n-k+1;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000030;
constexpr ll INF= 2000000000000000000;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int,int> P;
typedef pair<int,P> PP;
template<class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template<class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
ll mod(ll val, ll M) {
val = val % M;
if(val < 0) {
val += M;
}
return val;
}
template<typename T>
T RS(T N, T P, T M){
if(P == 0) {
return 1;
}
if(P < 0) {
return 0;
}
if(P % 2 == 0){
ll t = RS(N, P/2, M);
if(M == -1) return t * t;
return t * t % M;
}
if(M == -1) {
return N * RS(N,P - 1,M);
}
return N * RS(N, P-1, M) % M;
}
long double d[101][101][101];
long double solve(int A,int B,int C) {
if(d[A][B][C] != -1) {
return d[A][B][C];
}
if(A == 100 || B == 100 || C == 100) return 0;
long double a = A;
long double b = B;
long double c = C;
return d[A][B][C] = 1 + solve(A + 1,B,C) * (long double)(a / (a + b + c)) + solve(A,B + 1,C) * (long double)(b / (a + b + c)) + solve(A,B,C + 1) * (long double)(c / (a + b + c));
}
int main() {
int A,B,C;
cin >> A >> B >> C;
for(int i = 0;i < 101;i++) {
for(int j = 0;j < 101;j++) {
for(int k = 0;k < 101;k++) {
d[i][j][k] = -1;
}
}
}
cout << fixed;
cout << setprecision(8) << solve(A,B,C) << endl;
} | #include <bits/stdc++.h>
using namespace std;
void DBG() { cerr << endl; }
template<class Head, class... Tail>
void DBG(Head H, Tail... T) { cerr << ' ' << H; DBG(T...); }
#define dbg(...) cerr << "(" << (#__VA_ARGS__) << "):", DBG(__VA_ARGS__)
using ll = long long;
using ld = long double;
#define sqr(a) ll(a) * (a)
#define siz(a) int(a.size())
#define ints(a...) int a; read(a)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define trav(i, v) for (const auto i : v)
#define fill(a, b) memset(a, b, sizeof(a))
#define rep(i, b, n) for (auto i = b; i < n; i++)
#define per(i, b, n) for (auto i = b; i >= n; i--)
#define unify(a) sort(all(a)); a.resize(unique(all(a)) - a.begin())
template <class T> using vec = vector<T>;
template <class... Args> inline void read(Args&... args) { ((cin >> args), ...); }
template <class... Args> inline void show(Args... args) { ((cout << args << " "), ...); }
template <class T1, class T2> inline bool ckmin(T1 &a, T2 b) { return a > b ? a = b, 1 : 0; }
template <class T1, class T2> inline bool ckmax(T1 &a, T2 b) { return a < b ? a = b, 1 : 0; }
template <class T> inline void operator>> (istream& in, vector<T>& v) { rep(i, 0, siz(v)) in >> v[i]; }
template <class T> inline void operator<< (ostream& out, const vector<T>& v) { rep(i, 0, siz(v)) out << v[i] << " \n"[i + 1 == siz(v)]; }
const int MOD = 1e9 + 7;
const int N = 101;
ld dp[N][N][N];
ld f(int a, int b, int c) {
if (a == 100 || b == 100 || c == 100)
return 0;
if (dp[a][b][c] >= 0)
return dp[a][b][c];
ld res = 1, sum = a + b + c;
if (sum == 0)
return 0;
if (a < 100)
res += a * f(a + 1, b, c) / sum;
if (b < 100)
res += b * f(a, b + 1, c) / sum;
if (c < 100)
res += c * f(a, b, c + 1) / sum;
return dp[a][b][c] = res;
}
void solve() {
ints(a, b, c);
fill(dp, -1);
cout << f(a, b, c);
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(12);
cerr << fixed << setprecision(12);
int _ = 1;
// cin >> _;
rep(i, 1, _ + 1) {
// printf("Case %d: ", i);
// Solution solve;
solve();
}
return 0;
} |
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std;
void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
∧_∧
∧_∧ (´<_` ) Welcome to My Coding Space!
( ´_ゝ`) / ⌒i @hamayanhamayan0
/ \ | |
/ / ̄ ̄ ̄ ̄/ |
__(__ニつ/ _/ .| .|____
\/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/
vector<ll> masks;
#define pcnt __builtin_popcount
int N, M;
ll dp[1 << 18];
vector<pair<int, int>> restrictions[18];
//---------------------------------------------------------------------------------------------------
int tot[19];
bool check(int msk) {
int cnt = 0;
rep(i, 1, N + 1) tot[i] = 0;
rep(i, 0, N) if (msk & (1 << i)) {
tot[i + 1]++;
cnt++;
}
rep(i, 2, N + 1) tot[i] += tot[i - 1];
// fore(p, restrictions[cnt]){
fore(p, restrictions[pcnt(msk)]){
// if (p.second < tot[p.first]) return false;
if (p.second < pcnt( masks[p.first] & msk) ) return false;
}
return true;
}
//---------------------------------------------------------------------------------------------------
void _main() {
cin >> N >> M;
masks.resize(N+1,0);
rep(i,0,N){
masks[i+1] = (1<<i) | masks[i];
// cout << bitset<3>(masks[i+1]) << " " << bitset<3>(masks[i])<<endl;
}
rep(i, 0, M) {
int X, Y, Z; cin >> X >> Y >> Z;
restrictions[X].push_back({ Y, Z });
}
dp[0] = 1;
rep(msk, 0, 1 << N) rep(nxt, 0, N) if (!(msk & (1 << nxt))) {
if (check(msk + (1 << nxt))) dp[msk + (1 << nxt)] += dp[msk];
}
cout << dp[(1 << N) - 1] << endl;
}
| #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define ti3 tuple<int,int,int>
#define mat vector<vector<int>>
const int inf = 1 << 30;
const ll mod = 1e9 + 7;
const ll linf = 1LL << 62;
const db EPS = 1e-7;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}
int N, M;
vector<pii> ms[20];
ll dp[1 << 18][20];
int cnt[1 << 18][20];
vector<int> to[1 << 18];
int main() {
cin >> N >> M;
for (int i = 0; i < M; i++) {
int X, Y, Z;
cin >> X >> Y >> Z;
ms[X].push_back({Y, Z});
}
for (int i = 0; i < (1 << N); i++) {
for (int j = 0; j < N; j++) {
if ((i >> j) & 1) {
for (int k = j + 1; k <= N; k++) {
cnt[i][k]++;
}
} else {
to[i].push_back(j);
}
}
}
dp[0][0] = 1;
for (int i = 0; i <= N; i++) {
for (int j = 0; j < (1 << N); j++) {
bool flag = true;
for (auto u : ms[i]) {
if (cnt[j][u.first] > u.second) flag = false;
}
if (flag) {
for (auto u : to[j]) {
dp[j | (1 << u)][i + 1] += dp[j][i];
}
} else {
dp[j][i] = 0;
}
}
}
cout << dp[(1 << N) - 1][N] << endl;
} |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a)
#define dumparr(a,n)
#endif
#define FOR(i, a, b) for(ll i = (ll)a;i < (ll)b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = (ll)b-1LL;i >= (ll)a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))
typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;
typedef long double ld;
typedef pair<ld,ld> pdd;
pll operator+(pll a,pll b){
return pll(a.first+b.first,a.second+b.second);
}
pll operator-(pll a,pll b){
return pll(a.first-b.first,a.second-b.second);
}
pll operator*(ll a,pll b){
return pll(b.first*a,b.second*a);
}
const ll INF=(1LL<<60);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
a=abs(a);
b=abs(b);
if(a==0)return b;
if(b==0)return a;
if(a < b) return gcd(b, a);
ll r;
while ((r=a%b)) {
a = b;
b = r;
}
return b;
}
#endif
template<class T>
bool chmax(T& a,const T& b){
if(a<b){
a=b;
return true;
}
return false;
}
template<class T>
bool chmin(T& a,const T& b){
if(a>b){
a=b;
return true;
}
return false;
}
template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
os << "(" << a.first << "," << a.second << ")";
return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
os << "[ ";
REP(a.size()){
os<< a[i] << " ";
}
os<< " ]";
return os;
}
const string ATCODER="atcoder";
int main(){
cout<<setprecision(1000);
ll T;
cin>>T;
For(times,T){
string S;
cin>>S;
if(ATCODER<S){
cout<<0<<endl;
continue;
}
set<char> s;
for (auto &&i : S)
{
s.insert(i);
}
if(s.size()==1&&*s.begin()=='a'){
cout<<-1<<endl;
continue;
}
if(S[1]>'a'){
cout<<1<<endl;
continue;
}
([&S](){
REP(S.size()){
if(S[i]>'a'){
if(S[i]>'t'){
cout<<i-1<<endl;
return;
}else{
cout<<i<<endl;
return;
}
}
}
})();
}
return 0;
}
| #include<bits/stdc++.h>
#include<cmath>
#define pb push_back
#define ld long double
#define mp make_pair
#define vl vector<ll>
#define vd vector<double>
#define vld vector<long double>
#define ll long long int
#define pl pair<ll, ll>
#define all(a) a.begin(), a.end()
#define forr(i, n) for(ll i=0; i<n; i++)
#define forr1(i, n) for(ll i=1; i<=n; i++)
using namespace std;
const ld PI =3.1415926535897923846;
const ll MOD = 10000000000007;
const ll N=998244353;
ll power(ll x,ll n){ll res=1;while(n>0){if(n&1) res=res*x%MOD;x=x*x%MOD;n>>=1;}return res;}
ll modinverse(ll a){return power(a, MOD-2);}
void solve()
{
string str;
cin>>str;
ll n=str.length();
ll co=0, c_=0, cx=0;
forr(i, n)
{
if(str[i]=='o') co++;
else if(str[i]=='x') cx++;
else c_++;
}
if(co>4||cx==10)
{
cout<<0<<endl;
return;
}
ll ans=0;
vl fact(20, 1);
forr1(i, 18) fact[i]=(fact[i-1]*i);
if(co==4)
{
cout<<fact[4]<<endl;
return;
}
else if(co==3)
{
cout<<3*fact[4]/2+(fact[4]*c_)<<endl;
}
else if(co==2)
{
ans+=(14);
ans+=(2*c_*fact[4]/2);
if(c_>=2)
{
ans+=(c_*(c_-1)/2)*fact[4];
ans+=(c_*fact[4]/2);
}
else if(c_==1)
{
ans+=(c_*fact[4]/2);
}
cout<<ans<<endl;
}
else if(co==1)
{
ans=power(c_+1, 4);
ans-=power(c_, 4);
cout<<ans<<endl;
return;
}
else
{
cout<<power(c_, 4)<<endl;
return;
}
}
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
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll test=1;
//cin>>test;
while(test--)
{
solve();
}
cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
} |
#include <cmath>
#include <cstdio>
#include <bits/stdc++.h>
using namespace std;
long long S = 1;
void dfs(int i ,vector<int> arr[] , vector<bool>& v){
v[i] = true;
long long a = 3;
if(arr[i].size()> 2)
S = 0;
for(int k = 0; k < arr[i].size() ; k++){
if(!v[arr[i][k]])
a--;
}
if(a < 0)
S = 0 ;
S *= a;
for(int k = 0; k < arr[i].size() ; k++){
if(!v[arr[i][k]])
dfs(arr[i][k],arr,v);
}
}
int main() {
int n ,m ,k;
cin>>n>>m;
map<int,int> mp;
for(int i = 0; i < n ; i++){
cin>>k;
mp[k]++;
}
for(int i = 0; i < m ; i++){
cin>>k;
mp[k]++;
}
for(auto [x,y] : mp){
if(y == 1)
cout<<x<<" ";
}
} | #include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
// typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define ll long long
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld",n)
#define pri(n) printf("%d",n)
#define pln() printf("\n")
#define priln(n) printf("%d\n",n)
#define lpriln(n) printf("%lld\n",n)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN
#define inf INT_MAX
#define linf LLONG_MAX
#define lninf LLONG_MIN
const int mod = 1e9 + 7;
const int N = 1e5 + 4;
typedef long double ld;
int solve()
{
int n, m, k; scn(n); scn(m); scn(k);
pair<ld, ld> p = {0.0, 0.0};
vector<int> mark(n + 1, 0);
rep(i, 0, k)
{
int val; scn(val);
mark[val]++;
}
int cnt = 0;
rep(i, 1, n)
{
if(mark[i])
cnt++;
else
{
if(cnt >= m)
{
pri(-1); return 0;
}
cnt = 0;
}
}
if(cnt >= m)
{
pri(-1); return 0;
}
vector<pair<ld, ld>> v(n + m + 1, {0.0, 0.0});
for(int i = n - 1; i >= 0; i--)
{
p.F -= v[i + m + 1].F; p.S -= v[i + m + 1].S;
if(mark[i])
{
v[i].F = 1.0;
}
else
{
v[i].F = p.F / (ld)m; v[i].S = p.S / (ld)m;
v[i].S += 1.0;
}
// cout << v[i].F << " " << v[i].S << endl;
if(i == 0)
cout << fixed << setprecision(10) << v[i].S / (1.0 - v[i].F);
p.F += v[i].F; p.S += v[i].S;
}
return 0;
}
int main()
{
int t = 1; //scn(t);
while(t--)
{
solve();
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<pll> vpll;
void INX(){}
template<typename Head, typename... Tail>
void INX(Head&& head, Tail&&... tail)
{
cin >> head;
INX(forward<Tail>(tail)...);
}
void OUTX(){}
template<typename Head, typename... Tail>
void OUTX(Head&& head, Tail&&... tail)
{
cout << head << endl;
OUTX(forward<Tail>(tail)...);
}
#define ADD emplace_back
#define MP make_pair
#define VVEC(type) vector<vector<type>>
int main()
{
ll N;
INX(N);
vpll xy(N);
for (ll i = 0; i < N; i++)
{
INX(xy[i].first, xy[i].second);
}
sort(xy.begin(), xy.end());
ll cnt = 0;
bool isEnd = false;
for (ll i = 0; i < N - 1; i++)
{
if(xy[i].first == xy[i + 1].first)
{
cnt++;
if(cnt == 2)
{
isEnd = true;
OUTX("Yes");
break;
}
}
else
{
cnt = 0;
}
}
for (ll i = 0; !isEnd && i < N - 2; i++)
{
for (ll j = i + 1; !isEnd && j < N - 1; j++)
{
if(xy[i].first == xy[j].first)
{
continue;
}
pll dif = MP(xy[j].first - xy[i].first, xy[j].second - xy[i].second);
ld a = (ld)dif.second / (ld)dif.first;
ld b = (ld)xy[i].second - a * (ld)xy[i].first;
for (ll k = j + 1; !isEnd && k < N; k++)
{
ld tmp = (ld)xy[k].second - (a * (ld)xy[k].first + b);
if(abs(tmp) < 0.000000001)
{
isEnd = true;
OUTX("Yes");
break;
}
}
}
}
if(!isEnd)
{
OUTX("No");
}
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n) for (int i=1; i < (int)(n); i++)
#define rrep(i, n) for (int i=((int)(n)-1); i>=0; i--)
#define rreps(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 lint = long long;
// using p = pair<int, int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
// #define DEBUG
int main() {
#ifdef DEBUG
const time_t START_MILLISEC = time(NULL) * 1000;
#endif
int N; cin >> N;
vector<int> x(N);
vector<int> y(N);
rep (i, N) cin >> x[i] >> y[i];
bool flag = false;
for (int i = 0; i < N; i++) {
for (int j = i+1; j < N; j++) {
for (int k = j+1; k < N; k++) {
int xi = x[i] - x[k], yi = y[i] - y[k];
int xj = x[j] - x[k], yj = y[j] - y[k];
if (xi * yj == xj * yi) flag = true;
// double aij = (y[j] - y[i]) / (double)(x[j] - x[i]);
// double yk = aij * (x[k] - x[i]) + y[i];
// if (yk == (double)y[k]) {
// flag = true;
// printf("y=%lf(x-%d)+%d\n yk=%lf, y[k]=%d\n", aij, x[i], y[i], yk, y[k]);
// }
}
}
}
if (flag) cout << "Yes" << endl;
else cout << "No" << endl;
// scanf("%d%d%d%d", &, &, &, &);
#ifdef DEBUG
const time_t END_MILLISEC = time(NULL) * 1000;
cout << e-s << endl;
#endif
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
// #define LOCAL // 提出時はコメントアウト
#define DEBUG_
typedef long long ll;
const double EPS = 1e-9;
const ll INF = ((1LL<<62)-(1LL<<31));
typedef vector<ll> vecl;
typedef pair<ll, ll> pairl;
template<typename T> using uset = unordered_set<T>;
template<typename T, typename U> using mapv = map<T,vector<U>>;
template<typename T, typename U> using umap = unordered_map<T,U>;
#define ALL(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define sz(x) (ll)x.size()
ll llceil(ll a,ll b) { return (a+b-1)/b; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> vector<vector<T>> genarr(ll n, ll m, T init) { return vector<vector<T>>(n,vector<T>(m,init)); }
///// DEBUG
#define DUMPOUT cerr
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
template<typename T>istream&operator>>(istream&is,vector<T>&vec){for(T&x:vec)is>>x;return is;}
template<typename T,typename U>ostream&operator<<(ostream&os,pair<T,U>&pair_var){os<<"("<<pair_var.first<<", "<<pair_var.second<<")";return os;}
template<typename T>ostream&operator<<(ostream&os,const vector<T>&vec){os<<"{";for(int i=0;i<vec.size();i++){os<<vec[i]<<(i+1==vec.size()?"":", ");}
os<<"}";return os;}
template<typename T,typename U>ostream&operator<<(ostream&os,map<T,U>&map_var){os<<"{";repi(itr,map_var){os<<*itr;itr++;if(itr!=map_var.end())os<<", ";itr--;}
os<<"}";return os;}
template<typename T>ostream&operator<<(ostream&os,set<T>&set_var){os<<"{";repi(itr,set_var){os<<*itr;itr++;if(itr!=set_var.end())os<<", ";itr--;}
os<<"}";return os;}
void dump_func(){DUMPOUT<<endl;}
template<class Head,class...Tail>void dump_func(Head&&head,Tail&&...tail){DUMPOUT<<head;if(sizeof...(Tail)>0){DUMPOUT<<", ";}
dump_func(std::move(tail)...);}
#ifndef LOCAL
#undef DEBUG_
#endif
#ifdef DEBUG_
#define DEB
#define dump(...) \
DUMPOUT << " " << string(#__VA_ARGS__) << ": " \
<< "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" \
<< endl \
<< " ", \
dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
//////////
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
int solve(ostringstream &cout) {
#ifdef LOCAL
ifstream in("../../Atcoder/input.txt");
cin.rdbuf(in.rdbuf());
#endif
ll A,B;
cin>>A>>B;
ll N = B - A + 1;
vecl P = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71};
while (sz(P) > 0 && N < P.back()) P.pop_back();
ll U = 1LL<<sz(P);
auto dp = genarr(N+1,U+1,0LL);
dp[0][0] = 1;
ll ans = 0;
rep(i,N) {
ll x = i + A;
ll mask = 0;
rep(j,sz(P)) {
if (x % P[j]) continue;
mask += 1LL<<j;
}
rep(S,U) {
if ((mask & S) == 0) dp[i+1][S | mask] += dp[i][S];
dp[i+1][S] += dp[i][S];
}
if (i == N-1) {
rep(S,U) ans += dp[i+1][S];
}
}
cout << ans << endl;
return 0;
}
int main() {
ostringstream oss;
int res = solve(oss);
cout << oss.str();
return res;
}
| #include <stdio.h>
using namespace std;
long long pr[20] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71};
long long a, b, n, ans = 1;
long long dp[1 << 21];
long long te[73];
void dfs(long long now, long long t) {
if (t == n) {
return;
}
for (int i = t; i < n; i++) {
if (!(now & te[i])) {
dfs(now | te[i], i + 1);
ans++;
}
}
}
int main() {
long long a, b;
scanf("%lld%lld", &a, &b);
n = b - a + 1;
for (long long i = a; i <= b; i++) {
for (int j = 0; j < 20; j++) {
if (i % pr[j] == 0) {
te[i - a] = te[i - a] | (1 << j);
}
}
}
dfs(0, 0);
printf("%lld", ans);
} |
#include<bits/stdc++.h>
using namespace std;
const int64_t MAX = 10000000000;
int64_t is_valid(string &S, string &T){
int64_t ret = -1;
for(int i=0; i<S.size() - T.size()+1; i++){
bool flag = true;
for(int j=0; j<T.size(); j++){
if(S[i+j] != T[j]){
flag = false;
}
}
if(flag){
ret = i;
break;
}
}
return ret;
}
int main(){
int N;
cin >> N;
string T;
cin >> T;
if(T == "1"){
cout << MAX*2 << endl;
return 0;
}
if(T == "11" || T == "0"){
cout << MAX << endl;
return 0;
}
string A = "110";
string S = "";
for(int i=0; i<(N+4)/3; i++){
S += A;
}
//cout << S << endl;
int64_t x = is_valid(S,T);
if(x == -1){
cout << 0 << endl;
}
else{
int64_t ok = 0;
int64_t ng = MAX+10;
while(ng - ok > 1){
int64_t mid = (ok+ng)/2;
if((mid-1)*3 + N <= MAX*3 - x){
ok = mid;
}
else{
ng = mid;
}
}
cout << ok << endl;
}
} | #include "bits/stdc++.h"
#pragma GCC optimize "trapv"
#define int long long
#define For(i,a,b) for(int i=a;i<b;i++)
#define pb push_back
#define endl "\n"
#define F first
#define S second
#define drink_boost ios_base::sync_with_stdio(false);cin.tie(NULL)
#define all(v) v.begin(),v.end()
#define TEST_CASE int t;cin>>t;while(t--)
#define debug(...) cout<<#__VA_ARGS__<<" = "; print(__VA_ARGS__);
using namespace std;
const int MOD = 1e9 + 7;
void print() { cout<<endl; }
void printArray() { return; }
void read() { return; }
template<typename T , typename... Args> void print(T a , Args... arg) { cout << a << " " ; print(arg...); }
template<typename T , typename... Args> void read(T &a , Args&... arg) { cin >> a; read(arg...); }
template<typename T,typename... Args> void read(vector<T>&v , Args&... arg) { for(auto &i : v) cin>>i; read(arg...); }
template<typename T,typename... Args> void printArray(vector<T>&v, Args&... arg) { for(auto i : v) cout<<i<<" "; cout<<endl; printArray(arg...); }
int power(int a,int b) { int res=1; while(b) { if(b&1LL) res=res*a; b>>=1LL; a=a*a; } return res; }
int modPower(int a,int b) { int res=1; while(b) { if(b&1L) res=(res%MOD*a%MOD)%MOD; b>>=1; a=(a%MOD*a%MOD)%MOD; } return res; }
int gcdExtended(int a,int b,int *x,int *y){ if(a==0) { *x=0,*y=1; return b; } int x1,y1; int gcd=gcdExtended(b%a,a,&x1,&y1); *x=y1-(b/a)*x1; *y = x1; return gcd; }
int modInverse(int b,int m) {int x,y; int g=gcdExtended(b,m,&x,&y); if (g != 1) return -1; return (x%m + m) % m; }
int modDivide(int a,int b,int m=MOD) { a=a%m; int inv=modInverse(b,m); if(inv==-1) return -1; else return (inv*a)%m; }
void runCase_()
{
int n,a,b;
read(n,a,b);
int ans = n - a + b;
print(ans);
}
signed main()
{
drink_boost;
// TEST_CASE
runCase_();
return 0;
}
/** TEST CASES HERE **/
/*
*/
|
#include <bits/stdc++.h>
#define endl "\n"
#define rep(i, n) for(int i = 0; i < int(n); i++)
#define rep2(i, s, n) for(int i = (s); i < int(n); i++)
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ipair;
typedef pair<ll, ll> lpair;
template <class T> ostream &operator << (ostream &o, const vector<T> &v) //vectorの中身を見る
{o << "{"; for(int i = 0; i < (int)v.size(); i++) o << (i > 0 ? ", ":"") << v[i]; o << "}"; return o;}
void map_p(map<int, int> &d){cout << "map: "; for(auto a : d){cout << "{" << a.first << ":" << a.second << "}, ";} cout << endl;} //mapの中身を見る
void set_p(set<int> &d){cout << "set: "; for(int a : d){cout << a << ", ";} cout << endl;} //setの中身を見る
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(12);
ll n, cnt = 0;
cin >> n;
ll max_ = pow(10, 5) + 3;
set<ll> kinds;
rep2(i, 2, max_){
ll now = i;
while(true){
now *= i;
if(n < now) break;
if(kinds.find(now) == kinds.end()){ // a^b = c^dのこともある
cnt++;
kinds.insert(now);
}
}
}
cout << n - cnt << endl;
return 0;
} | #include<cstdio>
#include<iostream>
#include<cmath>
#define ll long long
using namespace std;
int main()
{
ll n;
scanf("%lld",&n);
for(ll i = 1; i<=sqrt(n); i++)
{
if(n%i==0)
cout<<i<<endl;
}
for(ll i = sqrt(n); i>=1; i--)
{
if(i*i!=n)
if(n%i==0)
cout<<n/i<<endl;
}
} |