code_file1
stringlengths 87
4k
| code_file2
stringlengths 82
4k
|
---|---|
#include <bits/stdc++.h>
using namespace std;
int n, k;
int dp[200005];
vector <int> Adj[200005];
int ans;
int f[200005];
int r[200005];
void DFS(int node, int maxx, int p = 0)
{
r[node] = 1;
for(auto x : Adj[node])
{
if(x == p)
{
continue;
}
DFS(x, maxx, node);
r[node] = max(r[node], r[x] + 1);
}
if(r[node] <= f[node])
{
r[node] = 0;
}
if(r[node] == maxx + 1)
{
r[node] = 0;
f[node] = maxx + 1;
ans++;
}
f[p] = max(f[p], f[node] - 1);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
// freopen("Input.txt", "r", stdin);
// freopen("Output.txt", "w", stdout);
cin >> n >> k;
for(int i = 1; i <= n; i++)
{
int u, v;
cin >> u >> v;
Adj[u].push_back(v);
Adj[v].push_back(u);
}
int ll = 1, rr = 2e5;
while(ll < rr)
{
ans = 0;
int mid = (ll + rr) >> 1;
for(int i = 1; i <= n; i++)
{
r[i] = 0;
f[i] = 0;
}
DFS(1, mid);
if(r[1])
{
ans++;
}
if(ans <= k)
{
rr = mid;
}
else
{
ll = mid + 1;
}
}
cout << ll;
} | #include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<complex>
#include<cstdio>
#define initdp(a,b) for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)dp[i][j]=-1;
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ppi pair<pii,int>
#define pip pair<int,pii>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define inf 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 1000005
#define mid(l,r) l+(r-l)/2
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 ed[20][20];
int n,m;
//int dp[20][1<<20];
int dp[1<<20];
/*int pos[1<<20];
int rec(int u,int mask){
if(mask+1==(1<<n)||u==n)return 0;
if(dp[u][mask]!=m+1)return dp[u][mask];
if(mask&(1<<u))return dp[u][mask]=rec(u+1,mask);
int &res=dp[u][mask]=1+rec(u+1,mask|(1<<u));
int newmask=(1<<u);
for(int i=0;i<n;i++){
//if(mask&(1<<i))continue;
if(!ed[u][i])continue;
newmask|=(1<<i);
}
for(int i=newmask;i;i=(i-1)&newmask)
if(pos[i]){//cout<<i<<"\n";
res=min(res,1+rec(u+1,mask|i));
break;
}
return res;
}*/
void solve(){
cin>>n>>m;
for(int i=0;i<m;i++){
int u,v;
cin>>u>>v;
u--;
v--;
ed[u][v]=ed[v][u]=1;
}
for(int i=0;i<n;i++)ed[i][i]=1;
//for(int i=0;i<n;i++)
for(int j=0;j<(1<<n);j++)dp[j]=inf;
for(int i=0;i<(1<<n);i++){
int f=0;
for(int j=0;j<n;j++){
for(int k=0;k<n;k++){
if(!(i&(1<<j)))continue;
if(!(i&(1<<k)))continue;
if(!ed[j][k]){f=1;break;}
}
}
if(!f){
//pos[i]=1;
//if(i&1)dp[0][i]=1;
dp[i]=1;
}
//cout<<i<<" "<<pos[i]<<"\n";
}
/*for(int i=1;i<n;i++){
for(int mask=0;mask<(1<<n);mask++){
if(!(mask&(1<<i)))continue;
dp[i][mask]=min(dp[i][mask],dp[i-1][mask]);
for(int s=mask;s;s=(s-1)&mask){
if(pos[mask^s])dp[i][mask]=min(dp[i][mask],1+dp[i-1][s]);
}
}
}*/
for(int mask=1;mask<(1<<n);mask++){
for(int s=mask;s;s=(s-1)&mask){
dp[mask]=min(dp[mask],dp[mask^s]+dp[s]);
}
//cout<<dp[mask]<<"\n";
}
//cout<<pos[(1<<n)-1];
//cout<<rec(0,0);
//cout<<dp[n-1][(1<<n)-1];
cout<<dp[(1<<n)-1];
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t=1;
//cin>>t;
while(t--){
solve();
}
} |
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cstdlib>
#include <queue>
#include <stack>
#include <bitset>
using namespace std;
#define MOD 1000000007
#define PI 3.1415926535897932
#define INF 1e9
#define rep(i, n) for (int i = 0; i < n; i++)
#define repe(i, j, n) for (int i = j; i < n; i++)
#define repi(i, n) for (int i = 0; i <= n; i++)
#define repie(i, j, n) for (int i = j; i <= n; i++)
#define all(x) x.begin(), x.end()
#define println() cout << endl
#define P pair<int, int>
#define fi first
#define se second
typedef long long ll;
using Graph = vector<vector<ll>>;
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 dp[2000][2000];
ll nCr(ll n, ll r)
{
if(n==r) return dp[n][r] = 1;
if(r==0) return dp[n][r] = 1;
if(r==1) return dp[n][r] = n%MOD;
if(dp[n][r]) return dp[n][r]%MOD;
return dp[n][r] = nCr(n-1,r)%MOD + nCr(n-1,r-1)%MOD;
}
ll H(ll n, ll r) {
return nCr(n+r-1, r)%MOD;
}
int prime[10000000];
bool is_prime[100000000 + 1];
int sieve(int n) {
int pcnt = 0;
for(int i = 0; i <= n; i++) {
is_prime[i] = true;
}
is_prime[0] = is_prime[1] = false;
for(int i = 2; i <= n; i++) {
if(is_prime[i]) {
prime[pcnt++] = i;
for(int j = 2*i; j <= n; j += i) {
is_prime[j] = false;
}
}
}
return pcnt;
}
struct UnionFind {
//自身が親であれば、その集合に属する頂点数に-1を掛けたもの
//そうでなければ親のid
vector<ll> r;
UnionFind(ll N) {
r = vector<ll>(N, -1);
}
ll root(ll x) {
if (r[x] < 0) return x;
return r[x] = root(r[x]);
}
bool unite(ll x, ll y) {
x = root(x);
y = root(y);
if (x == y) return false;
if (r[x] > r[y]) swap(x, y);
r[x] += r[y];
r[y] = x;
return true;
}
ll size(ll x) {
return -r[root(x)];
}
bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す
ll rx = root(x);
ll ry = root(y);
return rx == ry;
}
};
void solve1() {
ll m, h; cin >> m >> h;
if(h%m==0) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
int main()
{
solve1();
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
int m,h;
cin >> m >> h;
if(h % m == 0){
cout << "Yes" << endl;
}
else{
cout << "No" << endl;
}
} |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define FOR(i,a,b,c) for(int i=a;i<b;i+=c)
#define REV(i,a,b,c) for(int i=a;i>=b;i-=c)
#define all(x) x.begin(),x.end()
#define Dhruv main
const int pinf=LLONG_MAX;
const int ninf=LLONG_MIN;
const int mod=1000000007;
using namespace std;
using namespace __gnu_pbds;
typedef tree
<int,null_type,less <int>,rb_tree_tag,tree_order_statistics_node_update>
indexed_set;
typedef tree
<int,null_type,less_equal <int>,rb_tree_tag,tree_order_statistics_node_update>
indexed_multiset;
template <typename T>
istream & operator>>(istream &is, vector<T> &v) {
for(auto &data:v){
is>>data;
}
return is;
}
template <typename T>
ostream & operator<<(ostream &os,const vector<T> &v) {
for(auto &data:v){
os<<data<< " ";
}
return os;
}
int32_t Dhruv(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int T=1;
while(T--){
int n;
cin>>n;
vector <int> a(n);
cin>>a;
vector <int> b(n);
cin>>b;
cout<<a[0]*b[0]<< "\n";
vector <int> p(n);
p[0]=a[0];
FOR(i,1,n,1) p[i]=max(p[i-1],a[i]);
vector <int> c(n);
c[0]=a[0]*b[0];
FOR(i,1,n,1){
c[i]=max(c[i-1],p[i]*b[i]);
cout<<c[i]<< "\n";
}
}
#ifdef LOCAL
cout<< "Time Elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<< "s\n";
#endif
return 0;
}
| #include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const long long modd = 998244353;
const int N = 5000;
long long mp[N + 5][N + 5];
long long su[N + 5][N + 5];
long long n, m;
void init()
{
su[0][0] = 1;
for (long long j = 1; j <= m; ++j)
{
mp[j][0] = 1;
su[j][0] = (su[j - 1][0] + 1) % modd;
for (long long i = 1; i <= n; ++i)
{
mp[j][i] = mp[j][i - 1] * j % modd;
su[j][i] = (su[j - 1][i] + mp[j][i]) % modd;
}
}
}
int main()
{
scanf("%lld%lld", &n, &m);
init();
long long ans = mp[m][n] * n % modd;
for (int i = 2; i <= n; ++i)
{
for (int j = 1; j < i; ++j)
{
ans -= su[m - 1][i - j - 1] * mp[m][n - i + j - 1] % modd;
ans = (ans + modd) % modd;
}
}
printf("%lld", ans);
return 0;
}
|
#include<cstdio>
#include<iostream>
#include<queue>
#include<algorithm>
#include<cstring>
#include<set>
#include<vector>
#include<cmath>
#define PII pair<int,int>
#define pb push_back
#define ep emplace_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
inline int read(){
int x=0,f=1;char c=getchar();
while(c<'0'||c>'9'){ if(c=='-') f=-1; c=getchar();}
while(c>='0'&&c<='9'){x=(x<<3)+(x<<1)+(c^48);c=getchar();}
return f==1?x:-x;
}
inline void print(int x){
if(x<0) putchar('-'),x=~x+1;
if(x>=10) print(x/10);
putchar((x%10)|48);
}
int n;
struct edge{
int u,v,w;
bool operator <(const edge &x)const{
return w<x.w;
}
}e[100010];
int fa[210];
int m;
PII node[110];
int find(int x){
return fa[x]==x?x:fa[x]=find(fa[x]) ;
}
int main(){
n=read();
for(int i=1;i<=n+2;++i) fa[i]=i;
for(int i=1;i<=n;++i){
int x=read(),y=read();
node[i]=mp(x,y);
e[++m].u=i,e[m].v=n+1,e[m].w=(100-y)*(100-y);
e[++m].u=i,e[m].v=n+2,e[m].w=(y+100)*(y+100);
for(int j=1;j<i;++j){
e[++m].u=j,e[m].v=i,e[m].w=(x-node[j].fi)*(x-node[j].fi)+(y-node[j].se)*(y-node[j].se);
}
}
sort(e+1,e+m+1);
for(int i=1;i<=m;++i){
int fx=find(e[i].u);
int fy=find(e[i].v);
if(fx!=fy) fa[fx]=fy;
if(find(n+1)==find(n+2)){
printf("%.10Lf\n",sqrt(1.0L*e[i].w)/2.0L);return 0;
}
}
} | #include <bits/stdc++.h>
#define int long long
using namespace std;
int n;double eps=1e-6,ans;
int fath[105];
struct node
{
int x,y;
}a[105];
double dis(double a1,double b1,double c1,double d1)
{
return sqrt((c1-a1)*(c1-a1)+(b1-d1)*(b1-d1));
}
int fin(int x)
{
if (x==fath[x]) return x;
else return fath[x]=fin(fath[x]);
}
bool check(double mid)
{
for (int i=1;i<=n+2;i++) fath[i]=i;
for (int i=1;i<=n-1;i++)
{
for (int j=i+1;j<=n;j++)
{
if (dis(a[i].x,a[i].y,a[j].x,a[j].y)<mid)
fath[fin(j)]=fin(i);
}
}
for (int i=1;i<=n;i++)
{
if (abs(a[i].y-100)<mid) fath[fin(i)]=fin(n+1);
}
for (int i=1;i<=n;i++)
{
if (abs(a[i].y+100)<mid) fath[fin(i)]=fin(n+2);
}
for (int i=1;i<=n+2;i++) fath[i]=fin(fath[i]);
if (fin(n+1)==fin(n+2)) return false;
else return true;
}
signed main()
{
cin>>n;
for (int i=1;i<=n;i++) cin>>a[i].x>>a[i].y;
double l=0.00,r=200.00;
while (l+eps<=r)
{
double mid=(l+r)/2.00;
if (check(2.00*mid)) l=mid+eps,ans=mid;
else r=mid-eps;
}
cout<<fixed<<setprecision(4)<<ans<<endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define per(i, a, b) for (auto i = (b); i-- > (a); )
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) int((x).size())
#define lb(x...) lower_bound(x)
#define ub(x...) upper_bound(x)
template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n; cin >> n;
int D, H; cin >> D >> H;
float ans = 0;
rep(i, 0, n) {
int d, h; cin >> d >> h;
ckmax(ans, (float) (h * D - H * d) / (D - d));
}
cout << fixed << setprecision(10) << ans << '\n';
} | /**
* code generated by JHelper
* More info: https://github.com/AlexeyDmitriev/JHelper
* @author tatsumack
*/
#include <iostream>
#include <fstream>
#include <bits/stdc++.h>
#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)
using namespace std;
typedef pair<int, int> P;
class BOrthogonality {
public:
void solve(std::istream& cin, std::ostream& cout) {
int N;
cin >> N;
vector<int> A(N), B(N);
REP(i, N) cin >> A[i];
REP(i, N) cin >> B[i];
int res = 0;
REP(i, N) res += A[i] * B[i];
cout << (res == 0 ? "Yes" : "No") << endl;
}
};
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
std::istream& in(std::cin);
std::ostream& out(std::cout);
BOrthogonality solver;
solver.solve(in, out);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
static const auto _____ = []() {
// fast IO code : this I understand
ios::sync_with_stdio(false);
cout.tie(NULL);
cin.tie(0);
return 0;
}();
/******************** // Macros // ************************/
#define ll long long int
#define MAX 1000000
#define bitscount 32
#define mod 1000000007
int mpow(int base, int exp) {
base %= mod;
int result = 1;
while(exp > 0) {
if(exp & 1) result = ((ll)result * base) % mod;
base = ((ll)base * base) % mod;
exp >>= 1;
}
return result;
}
ll gcdExtended(ll a, ll b, ll *x, ll *y) {
if (a == 0) {
*x = 0, *y = 1;
return b;
}
ll x1, y1;
ll gcd = gcdExtended(b%a, a, &x1, &y1);
*x = y1 - (b/a) * x1;
*y = x1;
return gcd;
}
ll modInverse(ll b, ll m) {
ll x, y;
ll g = gcdExtended(b, m, &x, &y);
if (g != 1)
return -1;
return (x%m + m) % m;
}
struct st {
int a, b;
};
bool sortfunc (pair<int,int> a, pair<int,int> b) {
return a.first < b.first;
}
ll gcd(ll a, ll b) {
return (b == 0) ? a : gcd(b, a%b);
}
int dx[] = {0, 1, -1, 0};
int dy[] = {-1, 0, 0, 1};
//..................................................
ll mini = INT_MAX;
ll allinterval(vector<int> &v, int n, int start, int result) {
if(start == n)
return result;
int ored = 0;
for(int i = start; i < n; ++i) {
ored = ored | v[i];
mini = min(mini , allinterval(v, n, i + 1, ored xor result));
}
return mini;
}
void testcase(){
int n;
cin >> n;
vector<int>v(n);
for(int i = 0; i < n; ++i) {
cin >> v[i];
}
ll ans = allinterval(v,n,0,0);
cout << ans << endl;
}
int main()
{
// int t;
// cin >> t;
// while (t--)
// {
testcase();
// }
return 0;
}
| #include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
using namespace std;
typedef long long ll;
const long double PI = (acos(-1));
const long long MOD = 1000000007;
static const int MAX_INT = std::numeric_limits<int>::max();
static const long MAX_LONG = std::numeric_limits<long>::max();
static const ll MAX_LL = std::numeric_limits<long long>::max();
#define rep(i,n) REP(i,0,n)
#define REP(i,x,n) for(int i=x;i<n;++i)
///////////////////////////////////////////////////
// ------------------- utils ------------------- //
///////////////////////////////////////////////////
// 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; }
///////////////////////////////////////////////////
// ------------------- main -------------------- //
///////////////////////////////////////////////////
struct mint {
static const int mod = 1000000007;
long long x; // typedef long long ll;
mint(long long 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(long long 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; }
};
std::istream& operator>>(std::istream& is, mint& a) { return is >> a.x; }
std::ostream& operator<<(std::ostream& os, const mint& a) { return os << a.x; }
void countNb(ll& res) {
ll n, a, b; cin >> n >> a >> b;
// ensure A <= B
if (b < a) {
ll tmp = a;
a = b;
b = tmp;
}
mint N(n), A(a), B(b);
mint nbA = N - (A - 1); nbA = nbA * nbA;
mint nbB = N - (B - 1); nbB = nbB * nbB;
mint nbtotal = nbA * nbB;
// dupulication: inside
mint nbAb = B - (A - 1); nbAb = nbAb * nbAb;
mint nbInside = nbAb * nbB;
// cross
mint cnt = 0;
for (ll alpha = 1; alpha < a; ++alpha) {
mint Alpha(alpha);
mint nbCross = (B - A + Alpha * 2) * 4;
mint nbIn = N - (B + Alpha - 1); nbIn = nbIn * nbIn;
cnt += nbCross * nbIn;
}
mint count = nbtotal - nbInside - cnt;
res = count.x;
}
void countNb2(ll& res) {
mint N, A, B; cin >> N >> A >> B;
ll nbSpace = N.x - A.x - B.x;
mint x3 = (nbSpace >= 0) ? (N-A-B+2)*(N-A-B+1) : 0;
mint x2 = (N-A+1)*(N-B+1) - x3;
mint x1 = x2 * x2;
mint total = (N-A+1)*(N-B+1) * (N-A+1)*(N-B+1);
mint ans = total - x1;
res = ans.x;
}
void Main() {
ll T; cin >> T;
vector<ll> res(T);
for (ll i = 0; i < T; ++i) {
countNb2(res[i]);
}
rep(i, T) {
cout << res[i] << 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;
using ll = long long;
const int mod = 1e9+7;
int main(){
int N; cin >> N;
vector<ll> A(N), sum(N+1);
for(int i=0; i<N; i++){
cin >> A[i];
sum[i+1] = sum[i]+A[i];
}
vector<vector<int>> dp(N+2,vector<int>(N+2));
dp[1][0]++;
int ans = 0;
for(int i=0; i<N; i++){
for(int j=N; 1<=j; j--){
dp[j+1][sum[i+1]%(j+1)] += dp[j][sum[i+1]%j];
dp[j+1][sum[i+1]%(j+1)] %= mod;
if(i == N-1){
ans += dp[j][sum[i+1]%j];
ans %= mod;
}
}
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v)) //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd_(ll a,ll b){if(a%b==0)return b;return gcd_(b,a%b);}
ll lcm_(ll a,ll b){ll c=gcd_(a,b);return ((a/c)*b);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop_(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}
#define num_l(a,v) POSL(a,v) //v未満の要素数
#define num_eql(a,v) POSU(a,v) //v以下の要素数
#define num_h(a,v) (a.size() - POSU(a,v)) //vより大きい要素数
#define num_eqh(a,v) (a.size() - POSL(a,v)) //v以上の要素数
// http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2871291
// https://atcoder.jp/contests/arc017/submissions/10729573
template <typename T>
class Seg_Tree{
public: // 0-index
vector<T> dat;
T initial,M;
int n;
T unite(T a,T b){//
return (a + b)%M;
}
/*Seg_Tree(int n0_=1,T initial_=1,T M_=1){
initsize(n0_,initial_,M_);
}*/
void initsize(int n0,T initial_,T M_){
M = M_;
initial = initial_;
int k=1;
while(1){
if(n0<=k){
n=k;
dat.resize(2*n-1);
for(int i=0;i<2*n-1;i++)dat[i]=initial;
break;
}
k*=2;
}
}
//i banme wo x nisuru
void update(int i,T x){
i += n-1;
dat[i] = x;
while(i>0){
i = (i-1) / 2;
dat[i] = unite(dat[i*2+1],dat[i*2+2]);
}
}
//[a,b)
T query0(int a,int b,int k,int l,int r){
if(r<=a || b<=l)return initial;
if(a<=l && r<=b)return dat[k];
else{
T vl = query0(a,b,k*2+1,l,(l+r)/2);
T vr = query0(a,b,k*2+2,(l+r)/2,r);
return unite(vl,vr);
}
}
//return [a,b)
T query(int a,int b){
return query0(a,b,0,0,n);
}
};
int main(){
ll N;
cin >> N;
vector<ll> A(N+1,0),sum(N+1,0);
FOR(i,1,N+1) cin >> A[i];
FOR(i,1,N+1) sum[i] = sum[i-1] + A[i];
vector< vector<ll> > dp(N+1,vector<ll>(N+1,0));
dp[0][0] = 1;
vector<ll> wa(N+6,0);
//wa[1] = 1;
wa[0] = 1;
vector< Seg_Tree<ll> > Sg();
FOR(j,1,N+1){ // j個に分ける方法
FOR(i,1,N+1){ // i個目までで
(dp[i][j] += wa[ sum[i] % j ]) %= MOD;
( wa[ sum[i] % j ] += dp[i][j-1] ) %= MOD;
//(wa[ sum[i] % j ] += dp[i][j]) %= MOD;
}
FOR(i,0,N+1)wa[i] = 0;
//FOR(i,0,N+1)(wa[ sum[i]%(j+1) ] += dp[i][j]) %= MOD;
}
ll ans = 0;
FOR(i,1,N+1){
( ans += dp[N][i] ) %= MOD;
}
cout << ans << endl;
}
|
#include <iostream>
#include <cmath>
using namespace std;
int main() {
long long N;
cin >> N;
int ans = 0;
for (int d = 0; d < 6; d++) {
for (long long j = pow(10ll, d); j < pow(10ll, d + 1); j++) {
if (j * pow(10ll, d + 1) + j > N) break;
ans++;
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
#include <iostream>
#include <string>
using namespace std;
int main()
{
long N;
cin >> N;
long ans = 0;
if (N > 100) {
ans = 9;
} else {
ans += N / 11;
cout << ans << endl;
return 0;
}
if (N > 10000) {
ans = 99;
} else if (N > 1000) {
if (N / 100 - N % 100 > 0) {
ans += N/100 - 10;
} else {
ans += N/100 - 9;
}
cout << ans << endl;
return 0;
}
if (N > 1000000) {
ans = 999;
} else if (N > 100000) {
if (N / 1000 - N % 1000 > 0) {
ans += N/1000 - 100;
} else {
ans += N/1000 -99;
}
cout << ans << endl;
return 0;
}
if (N > 100000000) {
ans = 9999;
} else if (N > 10000000) {
if (N / 10000 - N % 10000 > 0) {
ans += N/10000 - 1000;
} else {
ans += N/10000 - 999;
}
cout << ans << endl;
return 0;
}
if (N > 10000000000) {
ans = 99999;
} else if (N > 1000000000) {
if (N / 100000 - N % 100000 > 0) {
ans += N/100000 - 10000;
} else {
ans += N/100000 - 9999;
}
cout << ans << endl;
return 0;
}
if (N > 100000000000) {
if (N / 1000000 - N % 1000000 > 0) {
ans += N/1000000 - 100000;
} else {
ans += N/1000000 - 99999;
}
cout << ans << endl;
return 0;
}
cout << ans << endl;
} |
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
typedef long long ll;
using namespace std;
int main() {
ll s, p;
cin >> s >> p;
bool ok = false;
for (ll i = 1; i*i <= p; i++) {
if (p%i == 0) {
if (s - i == p / i) ok = !ok;
}
}
if (ok) puts("Yes");
else puts("No");
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
long long S;
long long P;
cin>>S>>P;
int a=0;
long long sum=sqrt(P);
for(long long i=0;i<sum;i++){
if(S*(i+1)-(i+1)*(i+1)==P){
cout<<"Yes"<<endl;
a=1;
break;
}
}
if(a==0){
cout<<"No"<<endl;
}
} |
#include <bits/stdc++.h>
using namespace std;
#define intt long long int
#define F first
#define S second
#define pb push_back
const int N=1e5+5;
vector<pair<int,pair<int,int>>> adj[N];
intt vis[N],tim[N];
int n,m;
const intt INF=1e15;
intt calc(intt c,intt d,intt t)
{
// cout<<c<<" "<<d<<" "<<t<<endl;
intt ret=t+c+d/(t+1);
intt rt=sqrt(d);
if(t>rt){ return ret;}
t=rt;
ret=min(ret,t+c+d/(t+1));
t--;
if(t>=0) ret=min(ret,t+c+d/(t+1));
// cout<<"dd "<<ret<<endl;
return ret;
}
void dijkstra(int s)
{
set<pair<intt,intt>> sett; // time, city index
sett.insert({0,s});
for(int i=1;i<=n;i++)
{
tim[i]=INF;
}
tim[1]=0;
while(!sett.empty())
{
pair<intt,intt> aa=*sett.begin();
sett.erase(sett.begin());
if(tim[aa.S]<aa.F)
{ continue;}
//assert(tim[aa.S]==aa.F);
int pp=aa.S,tt=aa.F;
for(auto ss:adj[pp])
{
int ind=ss.F;
int cc=ss.S.F,dd=ss.S.S;
intt time_=calc(cc,dd,tim[pp]);
//cout<<time_<<endl;
if(time_<tim[ind])
{
tim[ind]=time_;
sett.insert({time_,ind});
}
}
}
}
int main()
{
cin>>n>>m;
for(int i=0;i<m;i++)
{
int a,b,c,d;cin>>a>>b>>c>>d;
if(a==b) continue;
adj[a].pb({b,{c,d}});
adj[b].pb({a,{c,d}});
}
dijkstra(1);
// for(int i=1;i<=n;i++) cout<<tim[i]<<endl;
if(tim[n]==INF)cout<<-1<<endl;
else
cout<<tim[n]<<endl;
return 0;
}
| #include <bits/stdc++.h>
#include <bits/extc++.h>
#define double long double
#define rbtree __gnu_pbds::tree<int,__gnu_pbds::null_type,less<int>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>
#define int ll
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);
#define pb push_back
#define ALL(X) X.begin(),X.end()
#define F(i,n) FF(i,0,n)
#define F1(i,n) FF(i,1,n+1)
#define FF(i,n,m) for(int i=(int)n;i<(int)m;++i)
#ifndef LOCAL
//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
#else
#endif // LOCOL
//#define mp make_pair
using namespace std;
//using namespace __gnu_pbds;
template<typename T> bool remax(T& a, const T& b) {return b>a?a=b,1:0;}
template<typename T> bool remin(T& a, const T& b) {return b<a?a=b,1:0;}
inline ostream& operator << (ostream& os,__int128_t a){if(a==0) {return (os<<'0');}bool flag=0;if(a<0) {a=-a,flag=1;}string s;while(a){s+=a%10+'0';a/=10;}s+=flag?"-":"";reverse(ALL(s));return os<<s;}
inline istream& operator >>(istream& is,__int128_t& a){string s;cin>>s;a=0;for(auto c:s) a=a*__int128_t(10)+__int128_t(c-'0');return is;}
template<typename T,typename P> inline ostream& operator << (ostream& os,pair<T,P> a){os<<a.first<<" "<<a.second; return os;}
template<typename T,typename P> inline istream& operator >> (istream& is,pair<T,P> &a){is>>a.first>>a.second; return is;}
using ll=long long;
using ull=unsigned long long;
using int128= __int128_t;
using uint128= __uint128_t;
using pii =pair<int,int>;
const double pi=acos(-1);
const int N=1E5+5;
const ll M=1000000000;
const ll INF_64=0x3f3f3f3f3f3f3f3f;
const int INF_32=0x3f3f3f3f;
const int16_t INF_16=0x3f3f;
const int klog=20;
const int mod=998244353;//1E9+7
const double eps=1E-8;
void gen(){
}
int d[N]{};
vector<pair<int,pii>> g[N];
int dis(int c,int d,int t){
double l=0,r=1E14;
F(_,100){
double m1=l+(r-l)/3.0,m2=r-(r-l)/3.0;
double mv1=t+m1+c+(d/(t+m1+1.0));
double mv2=t+m2+c+(d/(t+m2+1.0));
if(mv1==mv2) l=m1,r=m2;
else if(mv1>mv2) l=m1;
else r=m2;
}
int re=INF_64;
int L=l,R=r;
FF(j,L-3,R+3)
if(j>=0)remin(re,t+j+c+(d/(t+j+1)));
return re;
}
void sol(){
int n,m;cin>>n>>m;
priority_queue<pii,vector<pii>,greater<pii>> pq;
memset(d,0x3f,sizeof(d));
d[0]=0;pq.push({0,0});
F(i,m){
int a,b,C,D;cin>>a>>b>>C>>D;
a--,b--;
g[a].pb({b,{C,D}});
g[b].pb({a,{C,D}});
}
while(pq.size()){
auto [val,a]=pq.top();pq.pop();
if(val!=d[a]) continue;
for(auto &[b,tt]:g[a]){
if(remin(d[b],dis(tt.first,tt.second,d[a])))
pq.push({d[b],b});
}
assert(d[a]==val);
}
//F(i,n) cout<<d[i]<<" ";
//cout<<"\n";
assert(d[n-1]>=0);
cout<<(d[n-1]>=INF_64?-1:d[n-1])<<"\n";
}
int32_t main(){
#ifdef LOCAL
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
#endif // LOCAL
IOS;
int t=1;
gen();
//cin>>t;
FF(i,1,t+1){
//cout<<"Case #"<<i<<": ";
sol();
}
}
|
#include <bits/stdc++.h>
using namespace std;
#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second
using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;
const double eps = 1e-10;
template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
for(auto &e:u) fill_v<T>(e,v...);
}
template <typename F>
class
#if defined(__has_cpp_attribute) && __has_cpp_attribute(nodiscard)
[[nodiscard]]
#endif // defined(__has_cpp_attribute) && __has_cpp_attribute(nodiscard)
FixPoint final : private F
{
public:
template <typename G>
explicit constexpr FixPoint(G&& g) noexcept
: F{std::forward<G>(g)}
{}
template <typename... Args>
constexpr decltype(auto)
operator()(Args&&... args) const
#if !defined(__GNUC__) || defined(__clang__) || __GNUC__ >= 9
noexcept(noexcept(F::operator()(std::declval<FixPoint>(), std::declval<Args>()...)))
#endif // !defined(__GNUC__) || defined(__clang__) || __GNUC__ >= 9
{
return F::operator()(*this, std::forward<Args>(args)...);
}
}; // class FixPoint
#if defined(__cpp_deduction_guides)
template <typename F>
FixPoint(F&&)
-> FixPoint<std::decay_t<F>>;
#endif // defined(__cpp_deduction_guides)
namespace
{
template <typename F>
#if !defined(__has_cpp_attribute) || !__has_cpp_attribute(nodiscard)
# if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ >= 4)
__attribute__((warn_unused_result))
# elif defined(_MSC_VER) && _MSC_VER >= 1700 && defined(_Check_return_)
_Check_return_
# endif // defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ >= 4)
#endif // !defined(__has_cpp_attribute) || !__has_cpp_attribute(nodiscard)
inline constexpr decltype(auto)
makeFixPoint(F&& f) noexcept
{
return FixPoint<std::decay_t<F>>{std::forward<std::decay_t<F>>(f)};
}
} // namespace
template <typename T>
void fwt(vector<T>& f) {
int n = f.size();
for (int i = 1; i < n; i <<= 1) {
for (int j = 0; j < n; j++) {
if ((j & i) == 0) {
T x = f[j], y = f[j | i];
f[j] = x + y, f[j | i] = x - y;
}
}
}
}
template <typename T>
void ifwt(vector<T>& f) {
int n = f.size();
for (int i = 1; i < n; i <<= 1) {
for (int j = 0; j < n; j++) {
if ((j & i) == 0) {
T x = f[j], y = f[j | i];
f[j] = (x + y) / 2, f[j | i] = (x - y) / 2;
}
}
}
}
int main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
int64 N;
cin >> N;
int64 a = ((1 << N) - 1), b = ((1 << (N-1)) - 1);
if (N == 1) {
cout << 1 << endl << "AB" << endl;
return 0;
}
int64 n = b / __gcd(a, b);
int64 x = n * a / b, m = x;
cout << x << endl;
FOR(i, 1, x+1) {
REP(j, 1 << N) {
if (__builtin_popcount(i & j) % 2) cout << "A";
else cout << "B";
}
cout << endl;
}
}
| #include<bits/stdc++.h>
using namespace std;
int n,siz[1<<8];
int main(){
scanf("%d",&n);
printf("%d\n",(1<<n)-1);
for(int i=0;i<1<<n;i++) siz[i]=siz[i>>1]^(i&1);
for(int i=1;i<=(1<<n)-1;i++,puts(""))
for(int j=0;j<(1<<n);j++)
putchar('A'+siz[i&j]);
return 0;
} |
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define mod 1000000007
#define FAST ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define f(i,n) for(int i=0;i<n;i++)
#define fp(i,k,n) for(int i=k;i<=n;i++)
#define fr(i,k,n) for(int i=k;i>=n;i--)
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define dbg(x) cout << (#x) << " is " << (x) << '\n'
#define F first
#define S second
#define sz(x) (int)(x).size()
#define lb lower_bound
#define ub upper_bound
#define mems(x) memset(x,0,sizeof(x))
#define all(a) a.begin(),a.end()
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
/*---------------------------------------------------------------------------------------------------*/
void solve()
{
int n;
cin >> n;
int a[n];
int ans=0;
f(i,n)
cin >> a[i];
f(i,n)
{
int minm=mod;
fp(j,i,n-1)
{
minm=min(a[j],minm);
ans=max(ans,minm*(j-i+1));
}
}
cout << ans << '\n';
return;
}
signed main()
{
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
FAST
int T=1;
// cin >> T;
while(T--)
{
solve();
}
return 0;
}
| #pragma GCC optimize("O2")
#include <bits/stdc++.h>
namespace IN {
#define BUF_SIZE 1 << 17
static char buf[BUF_SIZE], *fs = buf, *ft = buf;
inline int nc() { return fs == ft && (ft = (fs = buf) + fread(buf, 1, BUF_SIZE, stdin), fs == ft) ? EOF : *fs++; }
template <typename T>
inline int rn(T &x) {
x = 0;
int f = 0;
char ch = nc();
while (ch < '0' || ch > '9') {
if (ch == '-') f = 1;
ch = nc();
if (ch == EOF) return EOF;
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - 48;
ch = nc();
}
x = f ? -x : x;
return 0;
}
template <typename T>
inline int read(T &x) {
return rn(x);
}
template <typename T, typename... Args>
inline int read(T &x, Args &...args) {
rn(x);
return read(args...);
}
#undef BUF_SIZE
} // namespace IN
namespace OUT {
template <typename T>
inline void print(std::string, T x) {
std::cout << x << std::endl;
}
template <typename T, typename... Args>
inline void print(std::string sep, T x, Args... args) {
std::cout << x << sep;
print(sep, args...);
}
} // namespace OUT
using namespace IN;
using namespace OUT;
using namespace std;
#define INF 0x3f3f3f3f
#define LL long long
#define PLL pair<LL, LL>
#define PII pair<int, int>
#define MP make_pair
#define FI first
#define SE second
#define PB push_back
#define ALL(A) A.begin(), A.end()
#define BPQ(type, name) priority_queue<type> name
#define SPQ(type, name) priority_queue<type, vector<type>, greater<type>> name
#define REP(i, n) for (LL i = 0; i < (LL)n; ++i)
#define REP1(i, n) for (LL i = 1; i <= (LL)n; ++i)
#define REP_R(i, a, b) for (LL i = (LL)a; i < (LL)b; ++i)
#define REP_RR(i, a, b) for (LL i = (LL)a; i >= (LL)b; --i)
#define SETVAL(array, val) memset(array, val, sizeof(array))
// Debug
#define DISP(arr, n) \
do { \
REP(i, n) cout << arr[i] << ' '; \
cout << endl; \
} while (0)
#define DISP1(arr, n) \
do { \
REP1(i, n) cout << arr[i] << ' '; \
cout << endl; \
} while (0)
#define DISP_T(arr, n, m) \
do { \
REP(i, n) { \
REP(j, m) cout << arr[i][j] << ' '; \
cout << endl; \
} \
} while (0)
#define DISP_T1(arr, n, m) \
do { \
REP1(i, n) { \
REP1(j, m) cout << arr[i][j] << ' '; \
cout << endl; \
} \
} while (0)
#define DISP_V(vec) \
do { \
for (auto elem : vec) cout << elem << ' '; \
cout << endl; \
} while (0)
#define SIZE 300010
int main() {
LL tx, ty, ta, tb;
cin >> tx >> ty >> ta >> tb;
__int128 x = tx, y = ty, a = ta, b = tb;
--y;
LL exp = 0;
while (x * a - x < b && x * a <= y) {
x *= a;
++exp;
}
exp += (y - x) / b;
cout << exp << endl;
return 0;
}
|
#include<iostream>
#include<vector>
using namespace std;
typedef long long li;
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define MOD 998244353
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }
struct modint{
li num;
modint(li a=0){
num=(a%MOD+MOD)%MOD;
}
modint operator+(modint a) {return{(num+a.num)%MOD};}
modint operator-(modint a) {return{((num-a.num)%MOD+MOD)%MOD};}
modint operator*(modint a) {return{num*a.num%MOD};}
modint inv(const modint& a);
modint operator/(modint a) {return (*this)*inv(a);}
modint& operator+=(modint a) {
(num += a.num)%=MOD;
return *this;
}
modint& operator-=(modint a) {
(num += MOD-a.num)%=MOD;
return *this;
}
modint& operator*=(modint a) {
(num*=a.num)%=MOD;
return *this;
}
};
std::ostream& operator<<(std::ostream& os, const modint& m){
// ここでストリームに obj を書き込みます。
li a=m.num;
a%=MOD;
a+=MOD;
a%=MOD;
cout << a;
return os;
}
std::istream& operator>>(std::istream& os,modint& m){
// ここでストリームに obj を書き込みます。
li a; cin >>a;
m=a;
return os;
}
modint pow(modint a,int r){
if(a.num==0) return 0;
modint b=a,s=1;
while(r){
if(r%2) s*=b;
b*=b;
r/=2;
}
return s;
}
modint inv(modint a){
// MOD: prime
return pow(a,MOD-2);
}
modint f(int x,int n,modint mn,modint mx){
modint a=(pow(x,n)-mn)*mx*mx;
modint b=mn*mx*n;
return a-b;
}
int main(){
int n,m; cin >>n >>m;
vector<modint> dp(n+3,0);
// dp[i][j] : [M]^(i+1) で最終が(j+1) min=k のときの和
modint ans=pow(m,n)*n-pow(m,n-2)*(n-1);
rep(_i,n-1){
int i=_i+1;
rep(_x,m-1){
int x=_x+1;
ans-=pow(m,i-1)*pow(x,n-1-i)*i;
}
}
print(ans);
}
| #include<bits/stdc++.h>
using namespace std;
#define ll long long
int pow(ll a,ll b, ll m){
if(b == 0)return 1;
ll fix = 1;
if(b % 2 != 0){
fix = a;
b--;
}
ll tmp = pow(a, b/2, m);
return tmp * tmp % m * fix % m;
}
int main(){
ll n,m;
cin >> n >> m;
ll res = pow(10,n,m*m);
cout << res / m << endl;
} |
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
//思维转化::每堆只有一个或两个石子,每次可以取1个或两个,共N堆;
/*
int s[66];
int main(){
int n;
scanf("%d",&n);
int an=0;
int s[n];
for(int i=0;i<n;i++){
int now;
scanf("%d",&now);
//超过2为2不超过2为1
if(now>2)an++;
}
if(n%2){
}
}
*/
int main(){
int a,b;
scanf("%d %d",&a,&b);
if(a-b<3&&a-b>0){
printf("Yes");
}else if(b-a<3&&b-a>0){
printf("Yes");
}else{
printf("No");
}
} | #include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
int main()
{
char s, t;
cin >> s >> t;
if (s == 'Y')
{
int temp = t - 'a' + 'A';
cout << (char)temp << endl;
}
else
{
cout << t << endl;
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define Pint pair<int,int>
#define Pll pair<ll,ll>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
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;}
constexpr int INF=1000000000;
constexpr ll llINF=1000000000000000000;
constexpr int mod=1000000007;
constexpr double eps=1e-8;
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int Random(int mi,int ma){
random_device rnd;
mt19937 mt(rnd());//32bit
//[mi,ma]
uniform_int_distribution<int>engine(mi,ma);
return engine(mt);
}
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;
}
bool prime(int a){
if(a==1)return false;
for(int i=2;i*i<=a;i++){
if(a%i==0)return false;
}
return true;
}
ll modpow(ll a,ll b){
if(b==0)return 1;
if(b%2)return modpow(a,b-1)*a%mod;
ll memo=modpow(a,b/2);
return memo*memo%mod;
}
vector<ll>kaijo,invkaijo;
void init_fact(int n){
kaijo.resize(n+1);
invkaijo.resize(n+1);
kaijo[0]=1;
for(ll i=1;i<=n;i++){
kaijo[i]=kaijo[i-1]*i;
kaijo[i]%=mod;
}
rep(i,n+1)invkaijo[i]=modpow(kaijo[i],mod-2);
}
vector<vector<ll>>C,sC;
void init_comb(int n,int m){
C.resize(n+1,vector<ll>(m+1,0));
sC.resize(n+1,vector<ll>(m+1,0));
C[0][0]=1;
for(int i=1;i<=n;i++){
C[i][0]=1;
for(int j=1;j<=m;j++){
C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
}
}
rep(i,n+1){
rep(j,m){
sC[i][j+1]=(sC[i][j]+C[i][j])%mod;
}
}
}
ll comb(int a,int b){
if(a<b)return 0;
if(a<0||b<0)return 0;
return kaijo[a]*invkaijo[a-b]%mod*invkaijo[b]%mod;
}
ll inv(ll x){
x=modpow(x,mod-2);
return x;
}
int dp[100010];
void solve(){
int n;
cin>>n;
vector<ll>a(n),b(n),c,d;
rep(i,n)cin>>a[i];
rep(i,n)cin>>b[i];
ll ans=0;
for(int i=0;i<n;i+=2){
ans+=max(a[i]+a[i+1],b[i+1]+b[i]);
if(a[i]+a[i+1]>=b[i]+b[i+1]){
c.pb(b[i]-a[i]);
d.pb(b[i+1]-a[i+1]);
}
else{
c.pb(a[i+1]-b[i+1]);
d.pb(a[i]-b[i]);
}
}
sort(all(d));
sort(all(c));
rep(i,c.size()){
if(c[i]+d[i]>=0)ans+=c[i]+d[i];
}
cout<<ans<<endl;
}
int main(){
cin.tie(0);ios::sync_with_stdio(false);
//int t;cin>>t;while(t--)
solve();
return 0;
} | //g++ t.cpp -o t && t < p.txt
//d>p.txt&&t<p.txt&&t2<p.txt
#include <iostream> // プログラムの耳と口
#include <vector> // 超有能配列秘書
#include <algorithm> // みんな大好きソートと二分探索
#include <queue> // きゅーちゃん、だいすき
#include <string> // to_string
#include <functional> // 関数を変数に入れる子
#include <set> // 値の取得・挿入・削除を高速に
#include <map> // setの妹 これまた優秀
#include <random> // 乱択さん
#include <ctime> // へびになりたい
#include <bitset> // へびになった シャー
#include <cassert>
// #include <atcoder/all>
// using namespace atcoder; // コンパイル重い
#define DB cerr<<"D"<<endl
using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6;
using P=pair<ll,ll>;
const ll M = 1e9+7;
ll mod_pow(ll x, ll a) { ll an = 1; while(a > 0) { if (a&1) an = an * x % M; x = x * x % M; a >>= 1;} return an;}
ll mod_pow(ll x, ll a, ll m) { ll an = 1; while(a > 0) { if (a&1) an = an * x % m; x = x * x % m; a >>= 1;} return an;}
void add(ll& x, ll y) {x+=y; x%=M;}; void mul(ll& x, ll y) {x*=y; x%=M;}; template<typename T, typename U> void chmax(T& x, U y) {if (x<y) x=y;}; template<typename T, typename U> void chmin(T& x, U y) {if (x>y) x=y;} bool vaild(int x, int y, int hh, int ww){return 0<=x&&x<hh&&0<=y&&y<ww;}
ll gcd(ll a, ll b) {if (b==0) return a; else return gcd(b, a%b);}
int keta(ll a) {int res=0; while(a>0) res+=a%10, a/=10; return res;}
const int up[]={1,-1,0,0}, lf[]={0,0,1,-1};
int main() {
int n; cin>>n;
ll a[n],b[n];
for(int i=0;i<n;i++) cin>>a[i];
for(int i=0;i<n;i++) cin>>b[i];
for(int i=1;i<n;i+=2) {
swap(a[i],b[i]); // これにより、a[i]をn/2個とb[i]をn/2個足す問題に帰着
}
ll an=0;
for(int i=0;i<n;i++) {
an+=a[i]; b[i]-=a[i];
}
sort(b,b+n,greater<ll>());
for(int i=0;i<n/2;i++) {
an+=b[i];
}
cout<<an<<endl;
}
// ・配列の大きさok? ・priority_queueはgreater? ・debug消した?
// ・落ち着いて。提出まで4分待ってね……WJ……1/10……2/10……
// Thank you for making problems and running the contest
|
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int a,b,x,y;
int main() {
INCANT;
cin >> a >> b >> x >> y;
if (a==b) {
cout << x << endl;
return 0;
}
int ret=INF;
ret = min(ret, abs(b-a)*y+x);
if (a<b) {
ret = min(ret, (abs(b-a)*2+1)*x);
} else {
ret = min(ret, (abs(b-a)*2-1)*x);
}
ret = min(ret,abs(b-(a-1))*y+x); // Aa-> A_b+1 -> Bb
cout << ret << endl;
return 0;
} | /////////////////////////////////TEST CASES////////////////////////////////////
/*
*/
/////////////////////////////////////CODE//////////////////////////////////////
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORD(i, a, b) for (ll i = a ; i > b ; i--)
#define fastio ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define PI 3.14159265
typedef long long ll;
#define vl vector<ll>
#define IN(inp) ll inp;cin>>inp;
#define pb push_back
#define all(a) a.begin(),a.end()
#define FR(i,a) for(auto &i:a)
#define rvl(a,n) vl a;FOR(i,0,n){IN(in); a.pb(in);}
#define what(A) cout<<#A<<" is "<<A<<endl;
ll MAX = 100000000000;
ll MOD = 998244353;
void solve()
{
IN(a)IN(b)IN(x)IN(y);
if (abs(a - b) == 0)
{
cout << x << endl;
}
else if (a > b)
{
if (a - b == 1)
{
cout << x << endl;
}
else
{
ll ans1 = (a - b - 1) * y + x;
ll ans2 = x + (a - b - 1) * 2 * x;
cout << min(ans1, ans2) << endl;
}
}
else
{
if (b - a == 1)
{
cout << x + y << endl;
}
else
{
ll ans1 = (b - a) * y + x;
ll ans2 = x + (b - a) * 2 * x;
cout << min(ans2, ans1) << endl;
}
}
}
int main()
{
fastio
//freopen("input.txt", "rt", stdin);
//freopen("output.txt", "wt", stdout);
ll test = 1;
//cin >> test;
while (test--)
{
solve();
}
} |
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef vector<int> V;
#define F(N,S,E) for(int N=(int)(S);N<=(int)(E);N++)
#define R(N,S,E) for(int N=(int)(S);N>=(int)(E);N--)
#define D(N,E) for(int N=0;N<(int)(E);N++)
LL read(){LL x;scanf("%lld",&x);return x;}
const int N=2.1e5;
int a[N],b[N];
struct BIT{
int a[N];
void add(int x,int v){
for(x++;x<N;x+=x&-x)a[x]+=v;
}
int query(int x)const{
int ans=0;
for(x++;x;x&=x-1)ans+=a[x];
return ans;
}
}tr;
map<int,V> qwq;
int p[N];
int main(){
int n=read();
D(i,n)a[i]=read()+i;
D(i,n)b[i]=read()+i;
map<int,int> cnta,cntb;
D(i,n)cnta[a[i]]++;
D(i,n)cntb[b[i]]++;
if(cnta!=cntb){
puts("-1");
exit(0);
}
D(i,n){
qwq[b[i]].push_back(i);
}
R(i,n-1,0){
V &v=qwq[a[i]];
p[i]=v.back();
v.pop_back();
}
LL ans=0;
R(i,n-1,0){
ans+=tr.query(p[i]);
tr.add(p[i],1);
}
printf("%lld\n",ans);
return 0;
} | #include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define mp make_pair
#define inf 1000000000000000
#define mod 1000000007
#define ld long double
#define pll pair<ll,ll>
using namespace std;
ll n,timer;
vector<ll> adj[2000009];
vector<ll> euler,tin,tout;
void dfs(ll node,ll par)
{
tin[node]=++timer;
euler.pb(node);
for(ll j:adj[node])
if(j!=par)
dfs(j,node);
tout[node]=++timer;
euler.pb(node);
}
void build(ll root)
{
tin.resize(n),tout.resize(n);
timer=-1;
dfs(root,-1);
}
int main()
{
fast;
cin>>n;
vector<ll> ans(2*n+1,0);
vector<ll> a(n-1),b(n-1);
for(ll i=0;i<n-1;i++)
{
cin>>a[i]>>b[i];
a[i]--;
b[i]--;
adj[a[i]].pb(b[i]);
adj[b[i]].pb(a[i]);
}
build(0);
ll q;
cin>>q;
while(q--)
{
ll t,x,y,e,inc;
cin>>t>>e>>inc;
x=a[e-1],y=b[e-1];
if(t==2)
swap(x,y);
if(tin[y]>tin[x])
{
ans[0]+=inc;
ans[tin[y]]-=inc;
ans[tout[y]+1]+=inc;
}
else
{
ans[tin[x]]+=inc;
ans[tout[x]+1]-=inc;
}
}
ll w=0;
vector<ll> res(n+10,0);
for(ll i=0;i<2*n;i++)
{
w+=ans[i];
res[euler[i]]+=w;
}
for(ll i=0;i<n;i++)
cout<<res[i]/2<<" "<<endl;
}
|
#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <queue>
#define int unsigned long long
using namespace std;
const int maxn=2e5+10;
struct node {
int id,val;
}a[maxn];
int n;
signed main() {
int now=0;
cin>>n>>now;
for(int i=1;i<=n;i++) {
cin>>a[i].id>>a[i].val;
}
sort(a+1,a+1+n,[](node x,node y)->bool{return x.id<y.id;});
for(int i=1;i<=n;i++) {
if(now<a[i].id) {
cout<<now;
return 0;
}
now+=a[i].val;
}
cout<<now;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define PI 3.14159265
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
ll n, k, ans = 0;
void solve(vector<vector<ll> > &v,set<ll> st, ll last, ll val) {
if(st.size() == 0) {
val += v[last][0];
if(val == k) {
ans++;
}
return;
}
for(auto itr = st.begin(); itr != st.end(); itr++) {
set<ll> temp = st;
temp.erase(*itr);
solve(v, temp, *itr, val + v[last][*itr]);
}
return;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> k;
vector<vector<ll> > v(n, vector<ll> (n, 0));
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++ ) {
cin >> v[i][j];
}
}
set<ll> st;
for(int i = 1; i < n; i++) {
st.insert(i);
}
ll val = 0;
ll last = 0;
solve(v, st, last, val);
cout << ans;
}
|
#include <bits/stdc++.h>
#define db1(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(x,y,z,w) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<#w<<"="<<w<<'\n'
#define vll vector< ll >
//#define M 100000
#define MD 1000000007
#define pb push_back
#define rep(i,a,b) for(ll i = a; i <= b; ++i)
#define fo(i,a,b) for(int i = a; i<= b; ++i)
#define pii pair<int,int>
#define vec(a) vector<a >
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define se second
#define fi first
#define inf 0xffffffff
#define inchar getchar_unlocked
#define outchar(x) putchar_unlocked(x)
//#define int unsigned long long
//#define endl '\n'
#define IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define int long long
using namespace std;
//using ll = unsigned long long;
ll md=MD;
//ll M=1073741824;
ll M=1e9+7;
//ll exp(ll a,ll b){ll r=1;while(b>0){if(b&1){r=r*(a%md);r=(r+md)%md;}b>>=1;a=(a%md)*(a%md);a=(a+md)%md;}return (r+md)%md;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll Min(int a,int b){if(a<b)return a; return b;}
ll Max(int a,int b){if(a>b)return a; return b;}
ll powM(ll a,ll b){if(a==1) return 1;ll ans=1;while(b>0){if(b&1)ans=(ans*a)%M;a=(a*a)%M;b=b>>1;}return ans;}
ll power(ll a,ll b){if(a==1) return 1;ll ans=1;while(b>0){if(b&1)ans=(ans*a);a=(a*a);b=b>>1;}return ans;}
const int INF=1000000000000000000;
//always try to hack ur soln before submitting (penalty-50 wrong submission 50 min sochle isse aacha)
// Abe n*m ke grid main y ke coordinates m se akm hone chahiye na ke n se
int32_t main()
{
IOS;
int t;
t=1;
while(t--)
{
int x,y;
cin>>x>>y;
cout<<(x+y)/2<<" "<<(x-y)/2<<"\n";
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
using graph = vector<VI>;
template<class T = ll> using w_graph = vector<vector<pair<int, T>>>;
#define FOR(i,a,n) for(int i=(a);i<(n);++i)
#define eFOR(i,a,n) for(int i=(a);i<=(n);++i)
#define rFOR(i,a,n) for(int i=(n)-1;i>=(a);--i)
#define erFOR(i,a,n) for(int i=(n);i>=(a);--i)
#define SORT(a) sort(a.begin(),a.end())
#define rSORT(a) sort(a.rbegin(),a.rend())
#define fSORT(a,f) sort(a.begin(),a.end(),f)
#define all(a) a.begin(),a.end()
#define out(y,x) ((y)<0||h<=(y)||(x)<0||w<=(x))
#define tp(a,i) get<i>(a)
#ifdef _DEBUG
#define line cout << "-----------------------------\n"
#define stop system("pause")
#endif
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
template<class T>inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }
template<class T>inline void print(const T& a) { cout << a << "\n"; }
template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); }
template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); }
template<class T>inline void print(const vector<vector<T>>& v) { for (auto& a : v)print(a); }
template<class T>inline T sum(const vector<T>& a, int l, int r) { return a[r] - (l == 0 ? 0 : a[l - 1]); }
template<class T>inline void END(T s) { print(s); exit(0); }
void END() { exit(0); }
VS s(3);
string t;
vector<bool> used(10);
VI num;
int m;
void dfs(int i) {
if (i == m) {
VS n = s;
bool ng = false;
FOR(j, 0, 3) {
int f = lower_bound(all(t), s[j][0]) - t.begin();
if (num[f] == 0)ng = true;
FOR(k, 0, s[j].size()) {
int idx = lower_bound(all(t), s[j][k]) - t.begin();
n[j][k] = char('0' + num[idx]);
}
}
if (ng)return;
if (stoll(n[0]) + stoll(n[1]) == stoll(n[2])) {
FOR(j, 0, 3)print(n[j]);
END();
}
}
else {
FOR(j, 0, 10) {
if (used[j])continue;
used[j] = true;
num[i] = j;
dfs(i + 1);
used[j] = false;
}
}
}
int main() {
init();
cin >> s;
set<char> se;
FOR(i, 0, 3)for (char c : s[i])se.insert(c);
for (char c : se)t += c;
SORT(t);
m = t.size();
num.resize(m);
dfs(0);
print("UNSOLVABLE");
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d;
cin >> a >> b >> c >> d;
cout << b - c << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb(x) push_back(x)
#define mp make_pair
#define sz(x) (int)x.size()
#define mem(x ,y) memset(x , y , sizeof x )
#define all(a ) a.begin() , a.end()
#define pii pair<int,int >
#define endl "\n"
#define forn(i,x,y ) for(int i= x; i<=y ; i++ )
#define ford(i,x,y ) for(int i= x; i>=y ; i-- )
#define rep(i,n ) for(int i= 0; i<n ; i++ )
#define repi(i,n ) for(int i= 1; i<=n ; i++ )
#define repit(i, c) for( __typeof((c).begin()) i = (c).begin(); i != (c).end();++i )
#ifndef ONLINE_JUDGE
#define dbg(args...) do { cout << #args << ' ' ; print(args); } while(0); cerr<< endl ;
#else
#define dbg(args...) ;
#endif
typedef long long ll ;
typedef unsigned long long ull ;
ll mod = 1e9+7, mod2 = 998244353;
int setbit(int n, int pos ) { return n = n|(1LL<< pos) ; }
int resetbit(int n,int pos ) { return n = n & ~(1LL<<pos ); }
bool checkbit(int n,int pos) { return (bool ) (n&(1LL<<pos)) ; }
template<typename T>T add(T x, T y, T mod = mod ){ x%= mod ; y%= mod ; return (x+y)%mod ; }
template<typename T>T sub(T x, T y, T mod = mod ){ return ((x-y)%mod+mod )%mod; }
template<typename T>T mul(T x, T y, T mod = mod ){ x %= mod ; y %= mod ; return (x*y)%mod ; }
template<typename T> void print(const T& v) { cout << v << ' ' ;}
template<typename T1,typename... T2> void print( const T1& first, const T2&... rest ){ print(first); print(rest...) ;}
template<typename T> void dbg_a(T a[] ,int n=10 ) {cerr << "[ "; for(int i=0;i <= n ; i++ )cerr<<a[i]<<' ' ; cerr<< " ]" << endl; }
template<typename F,typename S>ostream& operator<<( ostream& os, const pair< F, S > & p ){return os << "[ " << p.first << ", " << p.second << " ]";}
template<typename T>ostream &operator<<(ostream & os, const vector< T > &v ){os << "[ "; for(int i=0; i<sz(v) ; i++ ) os << v[i] << ' ' ; return os << " ]\n" ; }
template<typename T>ostream &operator<<(ostream & os, const map< T ,T> &Map ){os << "[ "; repit(it , Map ) os << "[" <<(*it).ff << ' ' << (*it).ss << "] " ; return os << "]\n" ; }
template<typename T>ostream &operator<<(ostream & os, const set< T > &Set ){os << "[ "; repit(it , Set ) os << *it << ' ' ; return os << " ]\n" ; }
template<typename T>ostream &operator<<(ostream & os, const multiset< T > &Set) {os << "[ "; repit(it , Set )os << *it << ' ' ; return os << " ]\n" ; }
#define int ll
const int maxn = (int) 2e5 + 123;
const int inf = 1e9; //0xc0 ;//0x3f ;
/////////////////////////////////////////////////
int n ,m,sum , k ;
// int a[maxn ] , cnt ;
void solve() {
int x,y,z,p,q , tot = 0 , ans = 0 , mx =0 , mn ;
// cin >> n ;
// rep(i , n ) cin>> a[i ] ;
int a, b , c, d ;
cin >> a >> b >> c >> d ;
ans = -inf ;
forn(i ,a,b )forn(j , c,d ) ans = max(ans , i-j) ;
cout << ans << endl ;
}
// before submit -> // check case 1
signed main() {
ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0) ;
cout << fixed << setprecision( 12) ;
int t = 1 , cs =0 ;
// cin >> t ;
while(t--) {
solve() ;
}
return 0 ;
}
// check case 1
|
// Problem : C - POW
// Contest : AtCoder - AtCoder Beginner Contest 205
// URL : https://atcoder.jp/contests/abc205/tasks/abc205_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
/* DEBUGGING */
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 deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
/* MACROS */
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef map<int,int> mii;
typedef tuple<int,int,int> tup;
#define ff first
#define ss second
#define pb push_back
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define lb lower_bound
#define ub upper_bound
#define all(x) (x).begin(), (x).end()
#define lcm(x, y) ((x) * (y) / __gcd(x, y))
#define ps(x,y) fixed<<setprecision(y)<<x
#define setbit(x) __builtin_popcountll(x)
#define rep(i,a,b) for(int i=a ; i<b ; ++i)
#define repr(i,a,b) for(int i=a ; i>=b ; --i)
/* CONSTANTS */
#define PI 3.141592653589793
const ll MOD = 1e9 + 7;
const ll INF = 1000000000;
const ll MAX_N = 2e5 + 2;
ll power(ll x, ll y)
{
ll res = 1;
while (y > 0)
{
if (y & 1)
res = (res*x) ;
y = y>>1;
x = (x*x);
}
return res;
}
void solve(){
ll a,b,c; cin >> a >> b >> c;
ll val1 = abs(a);
ll val2 = abs(b);
if(c%2){
if(a<=0 && b<=0){
if(val1 < val2){
cout << ">";
} else if(val1 > val2){
cout << "<";
} else{
cout << "=";
}
} else if(a<=0 && b>=0){
if(a==b){
cout << "=";
} else{
cout << "<";
}
} else if(a>=0 && b<=0){
if(a==b){
cout << "=";
} else{
cout << ">";
}
} else{
if(val1 > val2){
cout << ">";
} else if(val1 < val2){
cout << "<";
} else{
cout << "=";
}
}
} else{
if(val1 < val2) cout << "<";
else if(val1 > val2) cout << ">";
else cout << "=";
}
}
int main(){
IOS;
solve();
} | #include <bits/stdc++.h>
using namespace std;
#include <string>
int main(void){
double R,X,Y,d;
cin>>R>>X>>Y;
d=sqrt(X*X+Y*Y);
if(R>d){
cout<<2;
}else{
cout<<ceil(d/R);
}
} |
#include <stdio.h>
#include <vector>
#include <iostream>
#include <algorithm>
#include <map>
#include <math.h>
#include <queue>
#include <functional>
#include <limits.h>
using namespace std;
typedef long long int ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define inf INT_MAX
#define linf LLONG_MAX
#define ninf INT_MIN
#define nlinf LLONG_MIN
#define pi 3.141592
int main(){
int t;cin>>t;
vector<ll> n(t);rep(i,t)cin>>n[i];
rep(i,t){
if(!(n[i]%4))cout<<"Even"<<endl;
else if (!(n[i]%2))cout<<"Same"<<endl;
else cout<<"Odd"<<endl;
}
return 0;
} | /** بِسْمِ اللهِ الرَّحْمٰنِ الرَّحِيْمِ (In the name of Allah, the Most Gracious, the Most Merciful.) */
/**
Institution : Hajee Mohammad Danesh Science and Technology University,Dinajpur,Bangladesh.
Name : Ashikur Rahman Bhuyain (Asif)
Email : [email protected]
*/
#include <bits/stdc++.h>
using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<
int,
null_type,
less_equal<int>,
rb_tree_tag,
tree_order_statistics_node_update> ordered_set;
*/
#define FasterIO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define TIME clock()*1.0/CLOCKS_PER_SEC
#define pi acos(-1.0)
///Library
#define mem(a,b) memset(a,b,sizeof(a))
#define all(a) a.begin(),a.end()
#define Sort(x) sort(x.begin(),x.end())
#define Reverse(x) reverse(x.begin(),x.end())
#define SortA(ar,s) sort(ar,ar+s)
#define SortD(ar,s) sort(ar,ar+s,greater<int>())
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sq(x) (x)*(x)
#define CEIL(a,b) ((a/b)+((a%b)!=0))
#define for0(i,n) for(int i=0;i<n;i++)
#define for1(i,n) for(int i=1;i<=n;i++)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define min3(a,b,c) min(a,min(b,c))
#define min4(a,b,c,d) min(a,min(b,min(c,d)))
#define max3(a,b,c) max(a,max(b,c))
#define max4(a,b,c,d) max(a,max(b,max(c,d)))
#define ABS(x) ((x)<0?-(x):(x))
#define pb push_back
#define nl printf("\n")
#define endl '\n'
#define oh cout<<"Problem ta ki? "<<endl;
/**------- Char Chk----------*/
inline bool isLower(char ch)
{
return (ch>='a' && ch<='z');
}
inline bool isUpper(char ch)
{
return (ch>='A' && ch<='Z');
}
inline bool isDigit(char ch)
{
return (ch>='0' && ch<='9');
}
inline bool isVowel(char ch)
{
ch=tolower(ch);
return (ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u');
}
/*----------------------Graph Moves----------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1}; // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1}; // Kings Move
//const int fx[]={-2, -2, -1, -1, 1, 1, 2, 2}; // Knights Move
//const int fy[]={-1, 1, -2, 2, -2, 2, -1, 1}; // Knights Move
/*------------------------------------------------*/
///vector
#define Lower_bound(vec,value) lower_bound(vec.begin(),vec.end(),value)
#define Upper_bound(vec,value) upper_bound(vec.begin(),vec.end(),value)
/// File In
#define READ(f) freopen(f".in","r" ,stdin)
#define WRITE(f) freopen(f".out","w" ,stdout)
#define mod 1000000007
#define ll long long int
#define SIZ 1000005
void solve()
{
ll n;cin>>n;
if(n&1)cout<<"Odd\n";
else {
n/=2;
if(n&1)cout<<"Same\n";
else cout<<"Even\n";
}
return;
}
int main()
{
int tc=1;
cin>>tc;
for1(i,tc)solve();
return 0;
}
/*"Success isn't permanent, failure isn't fatal,
it's the courage to continue that counts"*/
|
#include <bits/stdc++.h>
using namespace std;
int main() {
double A,B;
double res;
cin>>A>>B;
res=B/A;
res=1-res;
res*=100;
cout <<res<< endl;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
const int INF = 1 << 30;
const long long LINF = 1LL << 60;
const long long MOD = 1000000007LL;
int main()
{
string n;
int k;
cin >> n >> k;
for (int i = 0; i < k; ++i)
{
string s = n;
sort(s.begin(), s.end());
reverse(s.begin(), s.end());
ll g1 = stoll(s);
reverse(s.begin(), s.end());
ll g2 = stoll(s);
ll g3 = g1 - g2;
n = to_string(g3);
}
cout << n << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main()
{
long long n;
cin >> n;
long long ans = n + 1;
long long m = n + 1;
for( long long i = 1; i <= m; i++ ) {
m -= i;
ans--;
}
cout << ans << endl;
}
| #include <iostream>
#include <vector>
#include <bitset>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
int main(){
ll n;
cin >> n;
ll l=1,r=2E9;
while(l+1<r){
ll tmp=(l+r)/2;
if((1+tmp)*tmp<=2*(n+1)){
l=tmp;
}else{
r=tmp;
}
}
cout << n-l+1 << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
#define rep(i, a, b) for(int i = a; i < b; ++i)
int debug = 0;
const int N = 110;
int n, m, x[N], y[N], z[N], dp[1 << 19];
bool belong(int mask, int i) {
return (mask >> i) & 1;
}
bool ok(int mask) {
int k = (int)__builtin_popcount(mask);
rep(i, 0, m) {
if (k == x[i]) {
int cnt = 0;
rep(j, 0, n) if (belong(mask, j)) {
cnt += (j + 1 <= y[i]);
}
if (cnt > z[i]) {
return 0;
}
}
}
return 1;
}
main() {
cin >> n >> m;
rep(i, 0, m) {
cin >> x[i] >> y[i] >> z[i];
}
dp[0] = 1;
rep(mask, 1, (1 << n)) {
if (ok(mask)) {
rep(lst, 0, n) if (belong(mask, lst)) {
dp[mask] += dp[mask ^ (1 << lst)];
}
}
}
cout << dp[(1 << n) - 1];
} | #include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
#include <cstdint>
#include <string>
#include <sstream>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long ll;
using P=pair<ll,ll>;
const int INF=1001001001;
const int mod=998244353;
struct edge{
int to;
ll w;
edge(int to,ll w):to(to),w(w){}
};
int a[505][505],b[505][505];
void solve(){
int r,c;
cin>>r>>c;
rep(i,r){
rep(j,c-1){
cin>>a[i][j];
}
}
rep(i,r-1){
rep(j,c){
cin>>b[i][j];
}
}
int n=r*c;
vector<vector<edge>>G(2*n);
auto e=[&](int i,int j,int ni,int nj,int cost){
int p=i*c+j,np=ni*c+nj;
G[p].emplace_back(np,cost);
};
rep(i,r){
rep(j,c){
if(j+1<c){e(i,j,i,j+1,a[i][j]);}
if(j-1>=0){e(i,j,i,j-1,a[i][j-1]);}
if(i+1<r){e(i,j,i+1,j,b[i][j]);}
e(i,j,i+r,j,1);
e(r+i,j,i,j,0);
if(i-1>=0){e(r+i,j,r+i-1,j,1);}
}
}
priority_queue<P,vector<P>,greater<P>>q;
vector<vector<int>>dist(2*r,vector<int>(c,INF));
auto push=[&](int i,int j,int ni,int nj,int cost){
if(chmin(dist[ni][nj],dist[i][j]+cost)){q.push({dist[ni][nj],ni*c+nj});}
};
q.push({0,0});
dist[0][0]=0;
while(!q.empty()){
auto t=q.top();q.pop();
int d=t.first,p=t.second;
if(dist[p/c][p%c]!=d){continue;}
for(auto u:G[p]){
push(p/c,p%c,u.to/c,u.to%c,u.w);
}
}
cout<<dist[r-1][c-1]<<endl;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long A,B,C;
cin >> A >> B >> C;
long long count1 = A + B;
long long count2 = C + B;
long long count3 = A + C;
long long max_ans = 0;
max_ans = max(count1,count2);
max_ans = max(max_ans,count3);
cout << max_ans <<endl;
} | #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define ui unsigned int
#define ar array
#define vt vector
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()
#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)
template<class A> void read(vt<A>& v);
template<class A, size_t S> void read(ar<A, S>& a);
template<class T> void read(T& x) {
cin >> x;
}
void read(double& d) {
string t;
read(t);
d=stod(t);
}
void read(long double& d) {
string t;
read(t);
d=stold(t);
}
template<class H, class... T> void read(H& h, T&... t) {
read(h);
read(t...);
}
template<class A> void read(vt<A>& x) {
EACH(a, x)
read(a);
}
template<class A, size_t S> void read(array<A, S>& x) {
EACH(a, x)
read(a);
}
string to_string(char c) {
return string(1, c);
}
string to_string(bool b) {
return b?"true":"false";
}
string to_string(const char* s) {
return string(s);
}
string to_string(string s) {
return s;
}
string to_string(vt<bool> v) {
string res;
FOR(sz(v))
res+=char('0'+v[i]);
return res;
}
template<class A> void write(A x) {
cout << to_string(x);
}
template<class H, class... T> void write(const H& h, const T&... t) {
write(h);
write(t...);
}
template<class T> void write(const vt<T>& x) {
EACH(a, x){
write(a);
write(' ');
}
write("\n");
}
void print() {
write("\n");
}
template<class H, class... T> void print(const H& h, const T&... t) {
write(h);
if(sizeof...(t))
write(' ');
print(t...);
}
void DBG() {
cerr << "]" << endl;
}
template<class H, class... T> void DBG(H h, T... t) {
cerr << to_string(h);
if(sizeof...(t))
cerr << ", ";
DBG(t...);
}
//Uncomment line when debugging, and comment out to remove all debug outputs directly
// #define _DEBUG
#ifdef _DEBUG
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
vt<int> v(3);
FOR(i,3)
cin>>v[i];
sort(all(v));
cout<<v[2]+v[1]<<"\n";
}
|
#include <bits/stdc++.h>
#define watch(x) std::cout << (#x) << " is " << (x) << std::endl
using LL = long long;
using pii = std::pair<int, int>;
using pll = std::pair<LL, LL>;
int main() {
//freopen("in","r",stdin);
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n, k;
std::cin >> n >> k;
std::vector<std::vector<int>> a(n, std::vector<int>(n));
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
std::cin >> a[i][j];
}
}
std::vector<int> p(n - 1);
std::iota(p.begin(), p.end(), 1);
auto sum = [&]() {
LL r = a[0][p[0]];
for (int i = 0; i + 2 < n; ++i) r += a[p[i]][p[i + 1]];
return r + a[p.back()][0];
};
int r = 0;
do {
if (sum() == k) ++r;
} while (std::next_permutation(p.begin(), p.end()));
std::cout << r << std::endl;
return 0;
} | #include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;
using vi = vector<int>;
using ii = pair<int,int>;
using vii = vector<ii>;
using ll = long long;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update> ordered_set;
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) int((x).size())
#define REP(i, a, b) for (auto (i) = (a); (i) <= (b); (i)++)
#define PER(i, a, b) for (auto (i) = (a); (i) >= (b); (i)--)
#define ITR(i, x) for (auto (i) = (x).begin(); (i) != (x).end(); (i)++)
ll mod_pow(ll b, ll e, ll m) {
if (e == 0) return 1 % m;
if (e == 1) return b % m;
if (e & 1) return mod_pow(b, e-1, m) * b % m;
return mod_pow(b*b%m, e/2, m);
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
ll n, m;
cin >> n >> m;
cout << mod_pow(10, n, m*m)/m << '\n';
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
int main()
{
int l,i;
cin>>l;
long long ans=l-1;
for(i=2;i<=11;i++)
{
ans*=(l-i);
ans/=i;
}
cout<<ans;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
ll cnt[13][210], l;
int main() {
cin.tie(0);cout.tie(0);
ios::sync_with_stdio(0);
cin >> l;
cnt[0][0] = 1;
for (int j = 0; j < l; j++)
for (int i = 0; i < 12; i++)
for (int k = j + 1; k <= l; k++)
cnt[i + 1][k] += cnt[i][j];
cout << cnt[12][l];
return 0;
}
|
#include<ctime>
#include<cstdio>
#include<cctype>
using namespace std;
int read() {
char c;
int x=0,f=1;
while(!isdigit(c=getchar()))
f-=2*(c=='-');
while (isdigit(c)){
x=x*10+(c-48)*f;
c=getchar();
}
return x;
}
char c[17];
int res,v[17],f[17];
void dfs(int p){
if(p==4){
for(int i=0;i<10;++i){
if(f[i]==1&&!v[i])
return;
}
++res;
return;
}
for(int i=0;i<10;++i){
if(!~f[i])
continue;
++v[i];
dfs(p+1);
--v[i];
}
}
int main() {
#ifndef ONLINE_JUDGE
freopen("C.in","r",stdin);
freopen("C.out","w",stdout);
#endif
clock_t t1=clock();
//--------
scanf("%s",c);
for(int i=0;i<10;++i){
switch(c[i]){
case 'o':
f[i]=1;
break;
case 'x':
f[i]=-1;
break;
}
}
dfs(0);
printf("%d",res);
//--------
clock_t t2=clock();
fprintf(stderr,"time:%0.3lfs",1.0*(t2-t1)/CLOCKS_PER_SEC);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < n; ++i)
using ll = long long;
using P = pair<int,int>;
// auto mod int
const int mod = 998244353;
struct mint {
ll x; // typedef long long ll;
mint(ll x=0):x((x%mod+mod)%mod){}
mint operator-() const { return mint(-x);}
mint& operator+=(const mint a) {
if ((x += a.x) >= mod) x -= mod;
return *this;
}
mint& operator-=(const mint a) {
if ((x += mod-a.x) >= mod) x -= mod;
return *this;
}
mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
mint operator+(const mint a) const { return mint(*this) += a;}
mint operator-(const mint a) const { return mint(*this) -= a;}
mint operator*(const mint a) const { return mint(*this) *= a;}
mint pow(ll t) const {
if (!t) return 1;
mint a = pow(t>>1);
a *= a;
if (t&1) a *= *this;
return a;
}
// for prime mod
mint inv() const { return pow(mod-2);}
mint& operator/=(const mint a) { return *this *= a.inv();}
mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
mint f(mint n){
return n*(n+1)/mint(2);
}
int main() {
ll a,b,c;cin>>a>>b>>c;
mint ans=f(a)*f(b)*f(c);
cout<<ans<<endl;
} |
#include <iostream>
#include <vector>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> p(N);
for(int i=0; i<N; i++) cin >> p[i];
vector<bool> ans(210000, true);
int cur = 0;
for (int i = 0; i < N; i++) {
ans[p[i]] = false;
for (int j=cur; j <= 210000; j++) {
if (ans[j]) {
cout << j << endl;
cur = j;
break;
}else continue;
}
}
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> P;
typedef tuple<int,int,int> tpl;
#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)
#define en "\n"
constexpr double EPS = 1e-9;
constexpr double PI = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
void Main(){
int N; cin >> N;
vector<bool> exist(200200,false);
int pos = 0;
REP(i,N){
int p; cin >> p;
exist[p] = true;
while(exist[pos]) pos++;
cout << pos << en;
}
return;
}
int main(void){
cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
int t=1; //cin>>t;
REP(_,t) Main();
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef string str;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<db> vd;
typedef vector<str> vs;
typedef vector<pi> vpi;
#define sz(x) (int)(x).size()
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define sor(x) sort(all(x))
#define ins insert
#define ft front()
#define bk back()
#define pf push_front
#define pb push_back
#define endl '\n'
const ll MOD = 998244353;
const int MX = 2e5 + 5;
const ll INF = 1e18;
const ld PI = acos((ld)-1);
const int xd[4] = {1, 0, -1, 0}, yd[4] = {0, 1, 0, -1};
void setIO() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
}
int main() {
setIO();
int n, k;
cin >> n >> k;
vector<vi> a(n, vi(n));
for (vi &i : a) {
for (int &j : i)
cin >> j;
}
vector<vi> g_c(n), g_r(n);
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
bool e = true;
for (int l = 0; l < n; l++)
if (a[l][i] + a[l][j] > k) e = false;
if (e) {
g_c[i].pb(j);
g_c[j].pb(i);
}
e = true;
for (int l = 0; l < n; l++)
if (a[i][l] + a[j][l] > k) e = false;
if (e) {
g_r[i].pb(j);
g_r[j].pb(i);
}
}
}
vi cmp_c(n, -1), cmp_r(n, -1);
int cur = 0;
queue<int> q;
int n_cmp_c = 0;
while (true) {
while (cur < n && cmp_c[cur] >= 0)
cur++;
if (cur == n) break;
q.push(cur);
cmp_c[cur] = n_cmp_c;
while (!q.empty()) {
int v = q.ft;
q.pop();
for (int to : g_c[v]) {
if (cmp_c[to] == -1) {
cmp_c[to] = n_cmp_c;
q.push(to);
}
}
}
n_cmp_c++;
}
cur = 0;
int n_cmp_r = 0;
while (true) {
while (cur < n && cmp_r[cur] >= 0)
cur++;
if (cur == n) break;
q.push(cur);
cmp_r[cur] = n_cmp_r;
while (!q.empty()) {
int v = q.ft;
q.pop();
for (int to : g_r[v]) {
if (cmp_r[to] == -1) {
cmp_r[to] = n_cmp_r;
q.push(to);
}
}
}
n_cmp_r++;
}
vl cnt_c(n_cmp_c), cnt_r(n_cmp_r);
for (int i = 0; i < n; i++) {
cnt_c[cmp_c[i]]++;
cnt_r[cmp_r[i]]++;
}
ll ans = 1;
for (ll i : cnt_c) {
for (int j = 2; j <= i; j++)
ans = ans * j % MOD;
}
for (ll i : cnt_r) {
for (int j = 2; j <= i; j++)
ans = ans * j % MOD;
}
cout << ans << endl;
return 0;
} | #include<bits/stdc++.h>
#define DONTSYNC ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) //dont use stdio with iostream functions //input and output are out of order now!
#define TEST unsigned long long T; cin>>T; while(T--) //loop over each testcase
#define endl "\n"
#define fori(a,start,end) for(int a=start;a<end;a++)
#define forll(a,start,end) for(long long a=start;a<end;a++)
#define forull(a,start,end) for(unsigned long long a=start;a<end;a++)
#define MOD 998244353
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
int N,K;
int getroot(int a,vector<int> &par){
if(par[a]==a) return a;
return par[a]=getroot(par[a],par);
}
void joinsets(int a,int b,vector<int> &par,vector<int> &siz){
int roota=getroot(a,par),rootb=getroot(b,par);
if(roota!=rootb){
par[rootb]=roota;
siz[roota]+=siz[rootb];
}
}
bool check(int isrow,int a,int b,vector< vector<int> > &mat){
if(isrow){
fori(col,0,N){
if(mat[a][col]+mat[b][col]>K) return false;
}
}
else{
fori(row,0,N){
if(mat[row][a]+mat[row][b]>K) return false;
}
}
return true;
}
void solve(){
/* code */
cin>>N>>K;
long long res=1;
vector<int> fact(N+1); fact[0]=1; fori(i,1,N+1) fact[i]=(1ll*fact[i-1]*i)%MOD;
vector< vector<int> > mat(N,vector<int>(N));
fori(i,0,N) fori(j,0,N) cin>>mat[i][j];
////////
vector<int> par(N);
vector<int> siz(N);
fori(i,0,N) par[i]=i,siz[i]=1;
fori(a,0,N-1){
fori(b,a+1,N){
if (check(1,a,b,mat)) joinsets(a,b,par,siz);
}
}
// vector<int> count(N,1);
fori(i,0,N) if(getroot(i,par)==i) res=(res*fact[siz[i]])%MOD;
//////
fori(i,0,N) par[i]=i,siz[i]=1;
fori(a,0,N-1){
fori(b,a+1,N){
if (check(0,a,b,mat)) joinsets(a,b,par,siz);
}
}
// fill(count.begin(),count.end(),1);
fori(i,0,N) if(getroot(i,par)==i) res=(res*fact[siz[i]])%MOD;
cout<<res;
}
int main()
{
DONTSYNC;
// TEST{
solve();
// }
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
#include <cstdint>
#include <string>
#include <sstream>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long ll;
using P = pair<ll,ll>;
const int INF=1001001001;
const int mod=1e9+7;
int main() {
int n;
cin>>n;
vector<ll>a(n);
rep(i,n){cin>>a[i];}
sort(a.begin(),a.end());
ll res=0;
rep(i,n){
res+=a[i]*(i-(n-i-1));
}
cout<<res<<endl;
return 0;
} | // Varun Kedia - Asansol Engineering College
#include<bits/stdc++.h>
#define int long long int
#define read(a) int a;cin>>a;
#define readarray(a,n) vector<int> a(n);for(int i=0;i<n;i++) cin>>a[i];
#define printarray(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" ";cout<<endl;
#define line cout<<endl;
#define vi vector<int>
#define MAX 1000000009
#define null nullptr
using namespace std;
//--------------------------------------------------
bool prime(int); int numberofdigits(int); map<int,int> frequency(vector<int>,int);
map<int,int> frequency(int[],int);
//--------------------------------------------------------------
bool contains7(int n){
while(n>0){
if((n%10)==7)
return true;
n/=10;
}
return false;
}
bool contains7oct(int n){
while(n>0){
if((n%8)==7)
return true;
n/=8;
}
return false;
}
void solve()
{
read(n)
readarray(a,n)
int sum=0;
sort(a.begin(),a.end());
for(int i=n-1; i>=0; i--)
sum += i*a[i] - (n-1-i)*a[i];
cout<<sum<<endl;return;
}
signed main(){
int t=1;
// cin>>t;
for(int i=0;i<t;i++){
solve();
}
return 0;
}
int numberofdigits(int n){
string s = to_string(n);
return s.length();
}
bool prime(int n){
if(n<2)
return false;
for(int i=2;i*i<=n;i++){
if(n%i==2)
return false;
}
return true;
}
map<int,int> frequency(vector<int> a,int n){
map<int,int> m;
for(auto &i:a){
m[i]++;
}
return m;
}
map<int,int> frequency(int a[],int n){
map<int,int> m;
for(int i=0;i<n;i++){
m[a[i]]++;
}
return m;
} |
#include <bits/stdc++.h>
using namespace std;
const long long MOD1 = 1000000007;
const long long MOD2 = 998244353;
#define logn long
#define lnog long
#define lgon long
#define itn int
typedef long long ll;
typedef pair<long long, long long> P;
const long long INF = LLONG_MAX;
//input_arr : 配列 A を入力
template <typename T>
void input_arr(vector<T>& A, long long N) {
for (long long i = 0; i < N; i++) {
cin >> A[i];
}
}
int main() {
long long N; cin >> N;
vector<long long>A(N); input_arr(A, N);
sort(A.begin(), A.end());
if (N % 2 == 0) {
long long x1 = A[N/2], x2 = A[N/2-1], x3 = 1e10,x4=1e10;
if (N > 3) {
x3 = A[N/2-2];
x4 = A[N/2+1];
}
long double ans1 = 0, ans2 = 0, ans3 = 0, ans4 = 0;
for (long long i = 0; i < N; i++) {
ans1 += (long double)((long double)x1/2 + A[i] - min(A[i], x1));
ans2 += (long double)((long double)x2/2 + A[i] - min(A[i], x2));
ans3 += (long double)((long double)x3/2 + A[i] - min(A[i], x3));
ans4 += (long double)((long double)x4/2 + A[i] - min(A[i], x4));
}
ans1 /= (long double)N;
ans2 /= (long double)N;
ans3 /= (long double)N;
ans4 /= (long double)N;
cout << fixed << setprecision(12) << min({ans1,ans2,ans3,ans4}) << endl;
}
else {
long long x1 = A[N/2], x2 = 1e10, x3 = 1e10;
if (N > 2) {
x2 = A[N/2-1];
x3 = A[N/2+1];
}
long double ans1 = 0, ans2 = 0, ans3 = 0;
for (long long i = 0; i < N; i++) {
ans1 += (long double)((long double)x1/2 + A[i] - min(A[i], x1));
ans2 += (long double)((long double)x2/2 + A[i] - min(A[i], x2));
ans3 += (long double)((long double)x3/2 + A[i] - min(A[i], x3));
}
ans1 /= (long double)N;
ans2 /= (long double)N;
ans3 /= (long double)N;
cout << fixed << setprecision(12) << min({ans1,ans2,ans3}) << endl;
}
} | #include<cstdio>
#include<algorithm>
#define N 100010
#define db long double
#define ll long long
#define fo(x,a,b) for(int x=(a);x<=(b);x++)
#define fd(x,a,b) for(int x=(a);x>=(b);x--)
using namespace std;
int n;
ll a[N],qz[N],sum=0;
db ans=1e9;
inline int read() {
int x=0,f=0; char c=getchar();
while (c<'0'||c>'9') f=(c=='-')?1:f,c=getchar();
while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
return f?-x:x;
}
db calc(db val) {
int l=1,r=n,mid;
while (l<=r) {
mid=(l+r)>>1;
if (a[mid]+1e-9<val*2.0) l=mid+1;
else r=mid-1;
}
db res=(db)sum+val*n-(db)(qz[l-1]+(n-l+1)*val*2.0);
res=res/n;
if (res<ans) ans=res;
return res;
}
int main() {
n=read();
fo(i,1,n) a[i]=read(),sum+=a[i];
sort(a+1,a+n+1);
fo(i,1,n) qz[i]=qz[i-1]+a[i];
db l=0,r=a[n],mid1,mid2;
while (l+1e-8<r) {
mid1=l+(r-l)/3.0;
mid2=r-(r-l)/3.0;
db val1=calc(mid1),val2=calc(mid2);
if (val1<val2) r=mid2; else l=mid1;
}
printf("%.8Lf\n",ans);
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int maxn=266,mod=998244353;
#define MP make_pair
#define PB push_back
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
inline ll read(){
char ch=getchar();ll x=0,f=0;
while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
return f?-x:x;
}
inline int qmo(int x){return x+(x>>31?mod:0);}
int n,pos[maxn],s[maxn][maxn],t[maxn][maxn];
int main(){
n=read();
s[1][1]=0;s[1][2]=1;
FOR(i,2,n){
memcpy(t,s,sizeof(t));
memset(s,0,sizeof(s));
FOR(j,1,(1<<i)) s[1][j]=j>(1<<(i-1));
FOR(j,1,(1<<i)){
FOR(k,1,(1<<(i-1))) s[j+1][k]=t[(j+1)/2][k];
FOR(k,1,(1<<(i-1))) s[j+1][k+(1<<(i-1))]=j%2?t[(j+1)/2][k]:t[(j+1)/2][k]^1;
}
/* FOR(j,1,(1<<(i-1))-1){
FOR(k,1,(1<<(i-1))) putchar(t[j][k]?'B':'A');
puts("");
}
puts("");*/
}
printf("%d\n",(1<<n)-1);
FOR(i,1,(1<<n)-1){
FOR(j,1,(1<<n)) putchar(s[i][j]?'B':'A');
puts("");
}
}
/*
n=2
AABB
ABAB
ABBA
n=3
AAAABBBB
AABBAABB
AABBBBAA
ABABABAB
ABABBABA
ABBAABBA
ABBABAAB
(2^n-1)|(2^{n-1}-1)*k
7|3*k
every pair 2^{n-1}-1 times
*/ | #include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int n;
int cnt1[500][500];
int cnt2[500][500];
int team[500][500];
int tgt=0;
bool deta=false;
int col[500][500];
int main(void){
scanf("%d",&n);
if(n==1){
printf("1\n");
printf("AB\n");
return 0;
}
if(n==2){
printf("3\n");
printf("AABB\n");
printf("ABAB\n");
printf("ABBA\n");
return 0;
}
col[0][2]=1;
col[0][3]=1;
col[1][1]=1;
col[1][3]=1;
col[2][1]=1;
col[2][2]=1;
int m=(1<<n);
int s=2;
int sz=3;
int len=4;
for(int i=2;i<n;i++){
for(int j=0;j<sz;j++){
for(int k=0;k<len;k++){
col[j+sz][k]=col[j][k];
}
}
for(int j=0;j<sz;j++){
for(int k=0;k<len;k++){
col[j][k+len]=col[j][k];
col[j+sz][k+len]=1-col[j+sz][k];
}
}
for(int j=0;j<len;j++){
col[sz*2][j+len]=1;
}
sz=sz*2+1;
len=len*2;
}
printf("%d\n",m-1);
for(int i=0;i<m-1;i++){
for(int j=0;j<m;j++){
printf("%c",col[i][j]==0?'A':'B');
}
printf("\n");
}
return 0;
}
|
#include<bits/stdc++.h>
#define mp make_pair
#define mulitset
#define nline "\n"
#define ll long long int
#define ss(x) sort(x.begin(),x.end())
#include<map>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define tt(x) ll x;cin>>x;while(x--)
#define pb push_back
//#define a(x) std::vector<ll> a(x);
#define ins insert
#define sz size
using namespace std;
const int INF = (int)1e+9;
const int M=1e9+7;
bool gre(int a,int b){
if(a>b){
return true;
}else{
return false;
}
}
long long mod(long long x){
return ((x%M + M)%M);
}
long long add(long long a, long long b){
return mod(mod(a)+mod(b));
}
long long mul(long long a, long long b){
return mod(mod(a)*mod(b));
}
ll fact(int n){
if(n==1||n==0)return 1;
else
return n*fact(n-1);
}
int powm(ll b,ll p,ll m){
if(p==0){
return 1;
}
ll k=powm(b,p/2,m);
if(p%2){
return (mul((k*k),b));
}else{
return (mul(k,k));
}
}
void solve(){
ll n,k;cin>>n>>k;
map<ll,ll>mp;
rep(i,0,n){
ll a,b;cin>>a>>b;
mp[a]+=b;
}
ll ans=k;
for(auto it:mp){
if(ans<it.first){
cout<<ans<<nline;return;
}else{
ans+=it.second;
}
}
cout<<ans;return;
}
int32_t main(){ //learn "%.nof"printf("%.nof")
ios_base
::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
solve();
}
| #include <bits/stdc++.h>
using namespace std;
#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second
using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;
const double eps = 1e-10;
template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
for(auto &e:u) fill_v<T>(e,v...);
}
int main(void){
cin.tie(0);
ios::sync_with_stdio(false);
int64 N, M;
cin >> N >> M;
vector<int64> w(N);
REP(i, N) cin >> w[i];
int64 wmax = *max_element(all(w));
vector<PLL> parts(M);
REP(i, M) {
cin >> parts[i].fs >> parts[i].sc;
if (parts[i].sc < wmax) {
cout << -1 << endl;
return 0;
}
}
vector<int64> cost(1 << N, 0);
REP(i, 1 << N) {
int64 wsum = 0;
REP(j, N) {
if (i >> j & 1) wsum += w[j];
}
REP(j, M) {
if (parts[j].sc < wsum) chmax(cost[i], parts[j].fs);
}
}
int64 res = INF_LL;
vector<int64> ord(N);
iota(all(ord), 0);
do {
vector<int64> pos(N, 0);
FOR(j, 1, N) {
int64 bit = 0;
for (int64 k = j; k >= 0; k--) {
bit |= (1 << ord[k]);
chmax(pos[j], pos[k] + cost[bit]);
}
}
chmin(res, pos.back());
} while (next_permutation(all(ord)));
cout << res << endl;
}
|
#include <cstdio>
#include <cstdlib>
using namespace std;
#define ll long long
const ll MAXN = 400011;
struct fhqTreap {
ll tot, rt;
ll val[MAXN], sum[MAXN], sz[MAXN], ls[MAXN], rs[MAXN], rd[MAXN];
void pushup(ll u) {sz[u] = sz[ls[u]] + sz[rs[u]] + 1; sum[u] = sum[ls[u]] + sum[rs[u]] + val[u];}
void split(ll u, ll k, ll &x, ll &y) {
if(!u) {x = y = 0; return;}
if(val[u] <= k) x = u, split(rs[u], k, rs[u], y);
else y = u, split(ls[u], k, x, ls[u]);
pushup(u);
}
ll merge(ll u, ll v) {
if(!u || !v) return u | v;
if(rd[u] < rd[v]) {rs[u] = merge(rs[u], v); pushup(u); return u;}
else {ls[v] = merge(u, ls[v]); pushup(v); return v;}
}
ll add(ll k) {
rd[++tot] = rand();
sz[tot] = 1;
val[tot] = sum[tot] = k;
return tot;
}
void insert(ll k) {
ll x, y;
split(rt, k, x, y);
rt = merge(merge(x, add(k)), y);
}
ll cb(ll k) {
ll x, y;
split(rt, k, x, y);
ll ans = sz[x] * k + sum[y];
rt = merge(x, y);
return ans;
}
void delet(ll k) {
ll x, y, z;
split(rt, k, x, z);
split(x, k - 1, x, y);
y = merge(ls[y], rs[y]);
rt = merge(merge(x, y), z);
}
} t[2];
ll q;
ll len[2];
ll w[2][MAXN];
ll read() {
ll X = 0, F = 1; char C = getchar();
while(C < '0' || C > '9') {if(C == '-')F=-1; C = getchar();}
while(C >= '0' && C <= '9') {X = X*10+C-'0'; C = getchar();}
return X * F;
}
int main() {
ll ans = 0;
len[1] = read(); len[0] = read(); q = read();
for(ll i = 0; i < 2; ++i)
for(ll j = 1; j <= len[i]; ++j)
t[i].rt = t[i].merge(t[i].rt, t[i].add(0));
for(ll i = 1, opt, x, y; i <= q; ++i) {
opt = (read() & 1); x = read(); y = read();
t[opt].delet(w[opt][x]);
t[opt].insert(y);
ans -= t[opt^1].cb(w[opt][x]);
w[opt][x] = y;
ans += t[opt^1].cb(w[opt][x]);
printf("%lld\n", ans);
}
return 0;
} | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
int dx[4]={0,1,0,-1}, dy[4]={1,0,-1,0};
long double eps = 1e-9;
long double pi = acos(-1);
template<typename T>
struct BIT{
vector<T> bit;
BIT(int n) : bit(n+1) {}
void add(int a,T w){
for(int x=++a; x < bit.size(); x+=(x&(-x)) ){
bit[x] += w;
}
}
// return v[0]+v[1]+...+v[a-1];
T sum(int a){
T ret=0;
for(int x=a;x>0;x-=(x&(-x)) ){
ret+=bit[x];
}
return ret;
}
};
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(20);
int n,m,q;
cin>>n>>m>>q;
vector<array<ll,3>> v(q);
map<int,int> mp;
for(int i=0;i<q;i++){
int a,b,c;
cin>>a>>b>>c;
b--;
mp[c]=0;
v[i]={a,b,c};
}
mp[0]=0;
int now = 0;
for(auto &i:mp){
i.second = now;
now++;
}
ll ans = 0;
int k = now;
BIT<ll> c1(k),c2(k),s1(k),s2(k);
int a[n]={},b[m]={};
c1.add(0,n);
c2.add(0,m);
for(int i=0;i<q;i++){
auto [t,x,y] = v[i];
int pos = mp[y];
if(t == 1){
int pre = mp[a[x]];
ans -= a[x] * c2.sum(pre);
ans -= s2.sum(k) - s2.sum(pre);
c1.add(pre,-1);
c1.add(pos,1);
s1.add(pre,-a[x]);
s1.add(pos,y);
a[x]=y;
ans += y * c2.sum(pos);
ans += s2.sum(k) - s2.sum(pos);
}
else{
int pre = mp[b[x]];
ans -= b[x] * c1.sum(pre);
ans -= s1.sum(k) - s1.sum(pre);
c2.add(pre,-1);
c2.add(pos,1);
s2.add(pre,-b[x]);
s2.add(pos,y);
b[x]=y;
ans += y * c1.sum(pos);
ans += s1.sum(k) - s1.sum(pos);
}
cout << ans << "\n";
}
} |
#include "bits/stdc++.h"
using namespace std;
//#include "testlib.h"
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define int long long
#define ll long long
#define M 1000000007
#define MM 998244353
#define inputarr(a,n) for(int i=0;i<n;++i) cin>>a[i]
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) m*(n/GCD(m,n))
#define mii map<ll ,ll >
#define msi map<string,ll >
#define rep(a,b) for(ll i=a;i<b;i++)
#define rep0(n) for(ll i=0;i<n;i++)
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#define vi vector<ll>
#define vs vector<string>
#define ppb pop_back
#define endl '\n'
#define asdf ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define r0 return 0;
#define FORD(i, a, b) for (int i = (int) (a); i >= (int) (b); --i)
#define inputoutput freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define Set(a, s) (a, s, sizeof (a))
#define FOR repi
#define vii vector<pii>
#define pii pair<int,int>
#define REVERSE(v) reverse(all(v))
#define trav(a, x) for(auto& a : x)
#define display(x) trav(a,x) cout<<a<<" ";cout<<endl
#define debug cerr<<"bhau"<<endl
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
template<typename T, typename U> static inline void amin(T &x, U y)
{
if (y < x)
x = y;
}
template<typename T, typename U> static inline void amax(T &x, U y)
{
if (x < y)
x = y;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
// http://xorshift.di.unimi.it/splitmix64.c
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
ll max(ll a, ll b) { return (a > b)? a : b;}
int min(int a, int b) { return (a < b)? a : b;}
const int N = 2e5 + 10;
int divv[N];
void aaa(){
for(int i = 1;i<N;i++){
for(int j = 1;j*i<N;j++){
divv[i*j]++;
}
}
}
int find2(int n){
int ans = 0;
for(int k=1;k<=n;k++){
ans += divv[k] * (n/k);
}
return ans;
}
int solve(){
int k;
cin>>k;
cout<<find2(k)<<endl;
return 0;
}
signed main(){
asdf
int t=1;
aaa();
// cin>>t;
while(t--){
solve();
}
return 0;
}
| #include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = a; i < (int)(b); ++i)
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
using namespace std;
#define int long long int
//------------ATCODER TEMPLATE-------------
constexpr int kMax = 1e5 + 2;
signed main() {
int K; cin >> K;
int cnt = 0;
for (int A = 1; A <= K; ++A) {
for (int B = 1; A * B <= K; ++B) {
for (int C = 1; A * B * C <= K; ++C) {
++cnt;
}
}
}
cout << cnt << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i < (n); ++i)
using ll = long long;
using P = pair<int, int>;
int main(){
int n, m; cin >> n >> m;
vector<int> a(n);
rep(i, n) cin >> a[i];
vector<vector<int>> pos(n, vector<int> {-1});
rep(i, n) pos[a[i]].push_back(i);
rep(i, n) pos[i].push_back(n);
int ans;
rep(i, n) {
bool flag = false;
rep(j, pos[i].size()-1) {
//cout << pos[i][j] << " ";
if (pos[i][j+1] - pos[i][j] > m) flag = true;
}
//cout << pos[i].back() << endl;
if (flag) {
ans = i;
break;
}
}
cout << ans << endl;
return 0;
}
| #include<stdio.h>
#define rep(i,N) for(int i=0;i<(int)N;i++)
static int IN(void)
{
int x=0,f=1,c;while(c=getchar(),c<48||c>57){if(c==45)f=-f;}
while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f*x;
}
static void OUT(int x){if(x<0){putchar('-'),x=-x;}if(x>=10){OUT(x/10);}putchar(x-x/10*10+48);}
int main(void)
{
int N=IN(),K=IN(),ext=0,lim=(K*K)/2+1,ng=-1,ok=1.4e9,mid=0,A[800][800],sum[801][801];
rep(i,N)rep(j,N){A[i][j]=IN();sum[i][j]=0;}
while(ng+1<ok)
{
mid=(ng+ok)/2;
rep(i,N)rep(j,N)
{
sum[i+1][j+1]=sum[i+1][j]+sum[i][j+1]-sum[i][j];
if(A[i][j]>mid){sum[i+1][j+1]++;}
}
ext=0;
rep(i,N-K+1)rep(j,N-K+1)if((sum[i+K][j+K]+sum[i][j]-sum[i][j+K]-sum[i+K][j])<lim){ext=1;}
if(ext)ok=mid;else ng=mid;
}
OUT(ok);
} |
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
const int INF = 1001001001;
int main() {
char a[3];
cin >> a;
cout << a[1] << a[2] << a[0] << endl;
} | #pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
const ll LL_MAX=LLONG_MAX;
struct In{
template<typename T>
operator T(){
T x;
cin >> x;
return x;
}
};
In in;
template <typename T,typename U>
void forin(T* x,U n){
for (U i=0;i<n;i++) cin >> x[i];
}
template <typename T>
int div1(T x) {
return x%1000000007;
}
template <typename T>
void out(T x){
cout << x << endl;
}
template <typename T>
T gcd(T x,T y){
if (y == 0) return x;
return gcd(y,x%y);
}
template <typename T>
T lcm(T x,T y){
return x*y/gcd(x,y);
}
template <typename T>
T npr(T x,T y){
T loop=max(x-y,y),ans=1;
for (T i=loop;i<=x;i++){
ans*=i;
}
return ans;
}//xPy
template <typename T>
T ncr(T x,T y){
T loop=min(x,x-y),ans=npr(x,y);
for (T i=1;i<=loop;i++){
ans/=i;
}
return ans;
}//xCy
int main(){
string s=in;
cout << s[1] << s[2] << s[0] << endl;
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define endl '\n'
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb emplace_back
#define pii pair<int , int>
#define F first
#define S second
#define M_PI 3.14159265358979323846
const int mod = 1000000007;
const int MAXX = 2e6 + 5;
int n , m;
int a[MAXX];
vector<int> v[MAXX];
int mp[MAXX];
signed main()
{
_FastIO;
cout.precision(12);
cin >> n;
long double ans = n;
long double s = n * 1.00;
for(int i = 3; i <= n; i++){
long double p = s * 1.00 / ((i - 1) * 1.00) * 1.00;
ans = ans * 1.00 + p * 1.00;
}
cout << fixed << ans << endl;
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pint = pair<int,int>;
int main()
{
int N; cin >> N;
double ex = 0;
for(int i = 1; i < N; i++) {
ex += (double)N / i;
}
cout << fixed <<setprecision(12) << ex << endl;
} |
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define all(v) v.begin(), v.end()
#define rep(i, begin, end) for(auto i = begin; i < (end); i++)
#define contains(v, x) (find(all(v), x) != v.end())
template<class T> bool chmin(T& a, T b){ if (a > b){ a = b; return true; } return false; }
template<class T> bool chmax(T& a, T b){ if (a < b){ a = b; return true; } return false; }
template<class T> T roundup(T a, T b){ return (a + b - 1) / b; }
const vector<int> dy = {0, 1, 0, -1, 1, 1, -1, -1, 0};
const vector<int> dx = {1, 0, -1, 0, 1, -1, 1, -1, 0};
using ll = long long;
const ll INF = 1e9;
const double EPS = 1e-10;
/* #include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;
using d32 = mp::number<mp::cpp_dec_float<32>>; */
const ll MOD = 1e9 + 7;
/* #include <atcoder/all>
using namespace atcoder;
using mint = modint1000000007; */
using P = pair<int, ll>;
struct Edge{ int to; ll cost; Edge(int to, ll cost) : to(to), cost(cost) {} };
using Graph = vector<vector<int>>;
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
string s;
cin >> s;
vector<int> must, dont;
rep(i, 0, 10){
if(s[i] == 'o') must.emplace_back(i);
else if(s[i] == 'x') dont.emplace_back(i);
}
int ans = 0;
rep(num, 0, 10000){
string t = to_string(num);
while(t.size() < 4) t = '0' + t;
vector<bool> check(10);
for(const auto& e : t) check[e - '0'] = true;
bool ok = true;
for(const auto& e : must) if(!check[e]) ok = false;
for(const auto& e : dont) if(check[e]) ok = false;
ans += ok;
}
cout << ans << endl;
}
| #pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ll MOD = 1e9 + 7;
double eps = 1e-12;
#define forn(i, e) for (ll i = 0; i < e; i++)
#define forsn(i, s, e) for (ll i = s; i < e; i++)
#define rforn(i, s) for (ll i = s; i >= 0; i--)
#define rforsn(i, s, e) for (ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout << #x << " = " << x << ln
#define mp make_pair
#define pb push_back
#define INF 2e18
#define fast_cin() \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define allrev(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
char moves[4] = {'L', 'U', 'R', 'D'};
int dx[4] = {0, -1, 0, 1};
int dy[4] = { -1, 0, 1, 0};
void solve()
{
int n;
cin >> n;
n = n + (n * 0.08);
if (n < 206) {
cout << "Yay!";
} else if (n == 206) {
cout << "so-so";
} else {
cout << ":(";
}
}
int main()
{
fast_cin();
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ll t = 1;
// cin >> t;
for (int it = 0; it < t; it++)
{
//cout << "Case #" << it+1 << ": ";
solve();
}
return 0;
} |
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
int ri() {
int n;
scanf("%d", &n);
return n;
}
#define MOD 1000000007
int mpow(int a, int b) {
int res = 1;
for (; b; b >>= 1) {
if (b & 1) res = (int64_t) res * a % MOD;
a = (int64_t) a * a % MOD;
}
return res;
}
#ifdef WIN32
#define getchar_fast getchar
#else
#define getchar_fast getchar_unlocked
#endif
int main() {
int h = ri();
int w = ri();
int16_t a[h][w];
getchar_fast();
for (auto &i : a) {
for (int j = 0; j < w; j++) i[j] = getchar_fast() == '.';
getchar_fast();
}
int16_t free[h][w];
memset(free, 0, sizeof(free));
for (int i = 0; i < h; i++) {
int start = 0;
for (int j = 0; j <= w; j++) if (j == w || !a[i][j]) {
for (int k = start; k < j; k++) free[i][k] += j - start;
start = j + 1;
}
}
int16_t vertical[w];
memset(vertical, 0, sizeof(vertical));
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) free[i][j] += (vertical[j] = a[i][j] ? vertical[j] + 1 : 0);
}
memset(vertical, 0, sizeof(vertical));
for (int i = h; i--; ) {
for (int j = 0; j < w; j++) free[i][j] += (vertical[j] = a[i][j] ? vertical[j] + 1 : 0);
}
int k = 0;
for (auto &i : a) k += std::accumulate(i, i + w, 0);
int b2[h + w];
int all = mpow(2, k), cur = all;
for (int i = 0; i < h + w; i++) {
if (i) {
if (cur & 1) cur = (cur + MOD) >> 1;
else cur >>= 1;
}
b2[i] = cur ? MOD - cur : 0;
}
int64_t res = (int64_t) k * all;
for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) if (a[i][j]) res += b2[free[i][j] - 2];
std::cout << res % MOD << std::endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;
#define rep1(i, n) for (ll i=0; i<(n); i++)
#define rep2(i, k, n) for (ll i=k; i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int main() {
ll n;
cin >> n;
vector<ll> a(n, 0);
ll m = INF;
rep1(i, n){
cin >> a[i];
m = min(m, a[i]);
}
map<ll, ll> ma;
rep1(i, n){
ma[a[i]%m]++;
}
vector<ll> b;
for (auto x: ma){
if (x.first!=0) b.push_back(x.first);
}
while (b.size()>0){
m = b[0];
map<ll, ll> res;
for (auto x: b) if (x%m!=0) res[x%m]++;
b.assign(0, 0);
for (auto x: res) b.push_back(x.first);
}
cout << m << endl;
//printf("%.12f", ans);
} |
#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 ALL(v) begin(v),end(v)
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = false;
//---------------------------------//
int main() {
int N, M;
cin >> N >> M;
vector<int> W(N);
REP(i, N) cin >> W[i];
vector<int> L(M), V(M);
REP(i, M) scanf("%d %d", &L[i], &V[i]);
vector<int> ord(M);
iota(ALL(ord), 0);
sort(ALL(ord), [&](int x, int y) { return L[x] < L[y]; });
vector<pii> dat(M); // min V, L
dat[M - 1] = {V[ord[M - 1]], L[ord[M - 1]]};
for (int i = M - 2; i >= 0; --i) dat[i] = {min(dat[i + 1].first, V[ord[i]]), L[ord[i]]};
if (dat[0].first < *max_element(ALL(W))) {
puts("-1");
return 0;
}
int ans = INF;
ord.resize(N);
iota(ALL(ord), 0);
do {
[&]() -> void {
vector<int> sumw(N + 1); // [0, i)
REP(i, N) sumw[i + 1] = sumw[i] + W[ord[i]];
vector<int> pos(N);
pos[0] = 0;
FOR(i, 1, N) {
REP(j, i) {
int sw = sumw[i + 1] - sumw[j];
int idx = lower_bound(ALL(dat), pii{sw, -1}) - dat.begin();
if (idx == 0) continue;
--idx;
chmax(pos[i], pos[j] + dat[idx].second);
}
}
chmin(ans, pos[N - 1] - pos[0]);
}();
} while (next_permutation(ALL(ord)));
cout << ans << endl;
} | /*
author : Piyush Singh
*/
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<int> w(n);
for (int i = 0; i < n; i++) {
cin >> w[i];
}
int mx = *max_element(w.begin(), w.end());
vector<int> sums(1 << n), mn(1 << n);
for (int i = 0; i < (1 << n); i++) {
int x = 0;
for (int j = 0; j < n; j++) {
if (i & (1 << j)) {
x += w[j];
}
}
sums[i] = x;
}
for (int i = 0; i < m; i++) {
int l, v;
cin >> l >> v;
if (v < mx) {
cout << -1 << '\n';
return 0;
}
for (int j = 0; j < (1 << n); j++) {
if (sums[j] > v) {
mn[j] = max(mn[j], l);
}
}
}
int ans = (int) 1e9;
vector<int> per(n);
iota(per.begin(), per.end(), 0);
do {
vector<int> pos(n);
for (int i = 0; i < n; i++) {
int s = 1 << per[i];
for (int j = i - 1; j >= 0; j--) {
s |= 1 << per[j];
pos[i] = max(pos[i], pos[j] + mn[s]);
}
}
ans = min(ans, pos[n - 1]);
} while (next_permutation(per.begin(), per.end()));
cout << ans << '\n';
return 0;
} |
#include <bits/stdc++.h>
#define ll long long
#define fast ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
int n;
string s,t;
bool dp[200007][3][10];
bool vis[200007][3][10];
bool rec( int i, bool aoki, int mod )
{
if(i>=n)
{
if(mod)
return 0;
return 1;
}
if(vis[i][aoki][mod])
return dp[i][aoki][mod];
bool turn= aoki;
if(t[i+1]=='T' and aoki)
turn^= 1;
else if(t[i+1]=='A' and !aoki)
turn^= 1;
bool ret1= rec( i+1, turn, (mod*10+s[i]-'0')%7 );
bool ret2= rec( i+1, turn, (mod*10)%7 );
// cout<<i<<" "<<aoki<<" "<<mod<<" "<<ret1<<" "<<ret2<<endl;
vis[i][aoki][mod]= 1;
bool ans;
if( aoki )
{
if( ret1 and ret2 )
ans= 1;
else
ans= 0;
}
else
{
if( ret1 or ret2 )
ans= 1;
else
ans= 0;
}
return dp[i][aoki][mod]= ans;
}
int main()
{
cin>>n;
cin>>s>>t;
t[n]= 'C';
if(rec(0, t[0]=='A', 0))
cout<<"Takahashi";
else
cout<<"Aoki";
} | #include <bits/stdc++.h>
#define fi first
#define se second
#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 sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
class UnionFind {
public:
vi Parent;
UnionFind(int N) {
Parent = vi(N,-1);
}
int root(int A) {
if(Parent[A] < 0) return A;
return Parent[A] = root(Parent[A]);
}
int size(int A) {
return -Parent[root(A)];
}
bool connect(int A,int B) {
A = root(A);
B = root(B);
if(A == B) return false;
if(size(A) < size(B)) swap(A,B);
Parent[A] += Parent[B];
Parent[B] = A;
return true;
}
};
int main() {
int N,M;
cin >> N >> M;
vi A(N),B(N);
rep(i,N) {
cin >> A[i];
}
rep(i,N) {
cin >> B[i];
}
vi c(M),d(M);
rep(i,M) {
cin >> c[i] >> d[i];
c[i]--;
d[i]--;
}
UnionFind uf(N);
rep(i,M) {
uf.connect(c[i],d[i]);
}
vl now(N,0),ans(N,0);
rep(i,N) {
now[uf.root(i)] += A[i];
ans[uf.root(i)] += B[i];
}
rep(i,N) {
if(now[i]!=ans[i]) {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
return 0;
} |
#include <bits/stdc++.h>
#include"map"
#include"string"
#include"cmath"
#include"cstdio"
#include"iostream"
#include"cstring"
#include"algorithm"
#include"vector"
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#ifdef local
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
#define f(i, l, r) for (int i = l; i <= r; ++i)
#define rf(i, r, l) for (int i = r; i >= l; --i)
#define all(x) (x).begin(), (x).end()
#define l l
#define r r
#define lch (o << 1)
#define rch (o << 1 | 1)
#define mid ((l + r) >> 1)
const int inf = 2e9 + 7;
double eps = 1e-6;
const int mod = 998244353;
const int N = 2e5 + 10;
const double pi = acos(-1.0);
ll power(ll a, ll b) { ll res = 1; while (b) { if (b & 1)res = res * a % mod; a = a * a % mod; b >>= 1; }return res; }
ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
/*int len, C[N], clen;
int id(int v) { return lower_bound(C + 1, C + len, v) - C; }
void initC() { sort(C + 1, C + clen+1); len = unique(C + 1, C + 1 + clen) - C - 1; }*/
vector<int> g[N];
int now, need;
int mxdep[N], up[N];
void dfs(int u, int f) {
mxdep[u] = 0; up[u] = -1;
for (int v : g[u])if (v != f) {
dfs(v, u);
mxdep[u] = max(mxdep[u], mxdep[v] + 1);
up[u] = max(up[u], up[v] - 1);
}
if (up[u]!=-1) {
if (mxdep[u] <= up[u])mxdep[u] = -inf;
}
if (mxdep[u] == now) {
need++; mxdep[u] = -inf; up[u] = now;
}
}
int main() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#ifdef local
freopen("in.txt", "r", stdin);
#endif
int n, k; cin >> n >> k;
f(i, 1, n - 1) {
int u, v; cin >> u >> v;
g[u].push_back(v); g[v].push_back(u);
}
int l = 0, r = n;
while (l < r) {
now = mid;
need = 0; dfs(1, 0); if (mxdep[1]>=0)need++;
if (need <= k)r = mid;
else l = mid + 1;
}
cout << l;
} | // vaziat meshki-ghermeze !
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'
using namespace std;
typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
const ll Mod = 998244353;
const int N = 2e5 + 10;
const ll Inf = 2242545357980376863LL;
const ll Log = 30;
ll mul(ll a, ll b){
return (a * b) % Mod;
}
ll bin_pow(ll b, ll p){
ll res = 1;
for(ll j = 1, pw = b; j <= p; j <<= 1, pw = mul(pw, pw))
if(p & j)
res = mul(res, pw);
return res;
}
ll inv(ll x){
return bin_pow(x, Mod - 2);
}
ll a[N];
ll f[N], iv[N];
ll nCr(ll n, ll r){
return mul(f[n], mul(iv[r], iv[n - r]));
}
ll dp[N];
vector<int> G[N];
int x;
pll DFS(int u, int p, int d){ // cnt, dep;
pll nw = {0, Inf}, sn;
int fl = 0;
for(auto adj : G[u]){
if(adj == p) continue;
sn = DFS(adj, u, d + 1);
if(!fl){
fl = 1;
nw = sn;
continue;
}
nw.F += sn.F;
if(nw.S > d && sn.S > d){
nw.S = min(nw.S, sn.S);
} else if(nw.S <= d && sn.S <= d){
nw.S = max(nw.S, sn.S);
nw.F --;
} else {
ll a, b;
if(nw.S > d) a = nw.S, b = sn.S;
else b = nw.S, a = sn.S;
if(a - d <= d - b){
nw.F --;
nw.S = a;
} else {
nw.S = b;
}
}
}
if(fl == 0){
nw = {1, d - x};
} else if(abs(nw.S - d) > x){
nw.F ++, nw.S = d - x;
}
// cerr << "!! " << u << " -> " << nw.F << ", " << nw.S << '\n';
return nw;
}
int n, k;
bool Check(int t){
x = t;
pll res = DFS(1, -1, 0);
return res.F <= k;
}
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int u, v;
cin >> n >> k;
for(int i = 1; i < n; i++){
cin >> u >> v;
G[u].pb(v);
G[v].pb(u);
}
// cerr << "----------\n";
// Check(1);
// cerr << "----------\n";
int L = -1, R = n, mid;
while(L + 1 < R){
mid = (L + R) >> 1;
if(Check(mid)) R = mid;
else L = mid;
}
cout << R << '\n';
return 0;
}
/*
5 1
1 2
2 3
3 4
1 5
*/ |
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
ll a,b,c,d;
cin >> a >> b >> c >> d;
cout << a*d-b*c;
} | #include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define vi vector<int>
#define mii map<int,int>
#define 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 all(a) (a).begin(),(a).end()
#define ps(x,y) fixed<<setprecision(y)<<x
#define mk(arr,n,type) type *arr=new type[n];
#define w(x) int x; cin>>x; while(x--)
#define REP(i,n) for(i=0;i<n;i++)
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define mod 1000000007
void c_p_c()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
void solve()
{
int a, b, c, d;
cin >> a >> b >> c >> d;
int i;
int j;
int ans = INT_MIN;
for (i = a; i <= b; i++)
{
for (j = c; j <= d; j++)
{
ans = max(ans, i - j);
}
}
cout << ans;
}
int32_t main()
{
c_p_c();
FIO;
//w(t)
solve();
}
|
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 100000000
#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define repp(i, n, s) for (int i = (int)(n); i >= (int)(s); i--)
#define mp make_pair
#define tp make_tuple
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef tuple<int,int,int> T;
typedef tuple<ll,ll,ll> TL;
ll mod = 1000000007;
ll mod2 = 998244353;
vector<vector<P>> G(100050);
vector<ll> ans(100050);
int n,m;
void dfs(int index){
for (auto g : G[index]){
int nv = g.first;
int cv = g.second;
if (ans[nv]==0){
if (ans[index]==cv){
if (cv + 1 >n) {
ans[nv] = 1;
}else{
ans[nv] = cv + 1;
}
dfs(nv);
}else{
ans[nv] = cv;
dfs(nv);
}
}
}
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin>>n>>m;
rep(i,0,m){
int a,b,c;cin>>a>>b>>c;
a--;
b--;
G[a].push_back(mp(b,c));
G[b].push_back(mp(a,c));
}
dfs(0);
rep(i,0,n){
cout<<ans[i]<<endl;
}
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,a,b) for(int i = (a); i < (b); i++)
#define per(i,a,b) for(int i = (a); i > (b); i--)
#define repl(i,a,b) for(ll i = (a); i < (b); i++)
#define perl(i,a,b) for(ll i = (a); i > (b); i--)
#define factinv invfact
const ll MOD = 1000000007;
const int MAX = 2000000;
long long fact[MAX+1], invfact[MAX+1];
//Fast modular exponentiation, needed by the function below
long long fast_exp(long long base, long long exp, long long mod) {
long long res=1;
while(exp>0) {
if(exp%2==1) res=(res*base)%mod;
base=(base*base)%mod;
exp/=2;
}
return res%mod;
}
//Precomputes factorials and their inverses (modulo mod) from 0 to n
void binom(int n, long long mod){
fact[0] = 1; invfact[0] = 1;
for(int i = 1; i <= n; i++){
fact[i] = (fact[i-1]*i)%mod;
}
invfact[n] = fast_exp(fact[n], mod-2, mod);
for(int i = n-1; i >= 0; i--){
invfact[i] = ((i+1)*invfact[i+1])%mod;
}
}
void solve(){
binom(MAX, MOD);
int n, m, k;
cin >> n >> m >> k;
if(n-k-1 >= m){
cout << 0 << "\n";
}
else{
ll total = (((fact[n+m]*factinv[n])%MOD)*factinv[m])%MOD;
//cout << total << "\n";
if(n == k){
cout << total << "\n";
}
else{
ll bad = (((fact[n+m]*factinv[n-k-1])%MOD)*factinv[m+k+1])%MOD;
ll ans = total - bad;
if(ans < 0) ans += MOD;
cout << ans << "\n";
}
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t;
//ll t;
//cin >> t;
t = 1;
while(t--)solve();
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define sp <<" "<<
bool isprime(ll n){
if (n <= 1)return false;ll g=sqrt(n);
for (ll i = 2; i <= g; i++)if (n % i == 0)return false;
return true;
}
ll MOD=998244353;
ll power(ll base, ll exp)
{
if(exp==1)return base;
else{if(exp%2==0){ll base1=(pow(power(base, exp/2),2));return base1%MOD;}
else{ll ans=(base*pow(power(base,(exp-1)/2),2));return ans%MOD;}}
}
ll temp,temp1,temp2;
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);
ll a[3];
ll res=1;
cin>>a[0]>>a[1]>>a[2];
for(int i=0;i<3;i++)
{
//cout<<res<<endl;
if(a[i]%2)
{
res*=(a[i]+1)/2;
res%=MOD;
res*=a[i];
res%=MOD;
}
else
{
res*=(a[i])/2;
res%=MOD;
res*=a[i]+1;
res%=MOD;
}
}
cout<<res;
return 0;
}
| #include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long int
#define ff first
#define ss second
typedef tree<pair<ll,ll>,null_type,less<pair<ll,ll>>,rb_tree_tag,
tree_order_statistics_node_update>pbds;
//order_of_key:index number if it was there in sorted array
//find_by_order:value at 3rd index in sorted array.
const ll maxs=1e6+5;
ll root[maxs];
class cmp{
bool operator()(const ll &a,const ll &b)
{
return a<b;
}
};
void init()
{
iota(root,root+maxs,0);
}
ll find(ll u)
{
ll f;
if(root[u]==u)
return u;
else
{
ll f=find(root[u]);
root[u]=f;
return f;
}
}
void Union(ll x,ll y)
{
ll u=find(x);
ll v=find(y);
root[v]=u;
}
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;
}
int main()
{
ll t,n,i,k,y,x,j;
ll a,b,c,d;
cin>>a>>b>>c>>d;
cout<<a*d-b*c;
return 0;
}
|
#include<iostream>
using namespace std;
int main() {
int x;
cin >>x ;
if (x>0 || x==0) {
cout <<x;
}
else {
cout << 0; }
return 0;
} | // C - ℕ Coloring
#include <bits/stdc++.h>
using namespace std;
int main(){
int n; cin>>n;
for(int i=1; i<=n; ++i) cout<< (int)log2(i) + 1 <<endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
const int N = 210000;
int a, b;
cin >> a >> b;
int res = 0;
for (int i = 1; i <= N; i++) {
if (a % i == 0) {
if (b / i - a / i >= 1) res = max(res, i);
} else {
if (b / i - a / i >= 2) res = max(res, i);
}
}
cout << res << endl;
} | #include<bits/stdc++.h>
using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define pii pair<int,int>
#define pb push_back
typedef int64_t ll;
const ll M = 1e9 + 7;
const ll INF = 1e6+10;
bool prime[INF]={1};
//vector<vector<ll>> numways(target+1, vector<ll> (n+1, 0));
ll d[INF]={};
int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};
string ds="RLDU";
long long int invmod(long long int i){
if(i==1) return 1;
return (MOD - ((MOD/i)*invmod(MOD%i))%MOD+MOD)%MOD;
}
ll binpow(ll a,ll b)
{
if(b==0) return 1;
if(b==1) return a%MOD;
ll temp=binpow(a,b/2);
if(b%2==0) return (temp*temp)%MOD;
else return (((temp*temp)%MOD)*a)%MOD;
}
ll tot(ll n) {
ll result = n;
for (int i = 2; i * i <= n; i++) {
if (n % i == 0) {
while (n % i == 0)
n /= i;
result -= result / i;
}
}
if (n > 1)
result -= result / n;
return result;
}
void phi_1_to_n(int n) {//nloglogn
vector<int> phi(n + 1);
phi[0] = 0;
phi[1] = 1;
for (int i = 2; i <= n; i++)
phi[i] = i;
for (int i = 2; i <= n; i++) {
if (phi[i] == i) {
for (int j = i; j <= n; j += i)
phi[j] -= phi[j] / i;
}
}
}
int gcd(int a, int b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
bool is_prime(ll n) {
if (n == 1)
return false;
ll i = 2;
while (i*i <= n) {
if (n % i == 0)
{return false; }
i += 1; }
return true;}
void SieveOfEratosthenes()
{ prime[1]=0;prime[0]=0;
for (int p=2; p*p<=INF; p++)
{ if (prime[p] == true)
{for (int i=p*p; i<=INF; i += p)
prime[i]=false;
} } }
int countteampairs(int a[],int s,int n,map<int,int>m)
{ int k=0;
for(int i=0;i<n;i++)
{ for(int j=i+1;j<n;j++)
{ if(a[i]+a[j]<=s)
{ if(m[a[i]]>0 && m[a[j]]>0)
{ if(a[i]==a[j] && m[a[i]]<2)
{
break;
} k++; m[a[i]]--; m[a[j]]--;
}
}
}
} return k;
}
void div()
{
for(ll i=1;i<INF;i++)
{
for(ll j=i;j<INF;j+=i)
{
d[j]+=i;
d[j]=d[j]%M;
}
}
}
int LCSubStr(string X, string Y, int m, int n)
{
int LCSuff[m + 1][n + 1];
int result = 0;
for (int i = 0; i <= m; i++)
{
for (int j = 0; j <= n; j++)
{
if (i == 0 || j == 0)
LCSuff[i][j] = 0;
else if (X[i - 1] == Y[j - 1]) {
LCSuff[i][j] = LCSuff[i - 1][j - 1] + 1;
result = max(result, LCSuff[i][j]);
}
else
LCSuff[i][j] = 0;
}
}
return result;
} //min_element(v.begin(),v.begin()+mi) >= max_element(v.begin()+mi+1,v.end())
vector<vector<ll>> dp(505, vector<ll> (505, 0));
vector<ll>adj[INF];int ans=0;
vector<ll>fact(INF);
void solve() {
int a,b;
cin>>a>>b;
for(int c=b;;c--)
{
if(b/c-(a-1)/c>=2)
{
cout<<c<<endl; return;
}
}
}
int main() {
// fact[1]=1;
// fact[0]=0;
// for(ll i=2;i<INF;i++)
// {
// fact[i]=((fact[i-1]%M)*(i%M))%M;
// }
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
{
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
vector <vector <int>> mat;
vector <int> root;
long long int MOD = 998244353;
int find( int a )
{
while( root[a] != a )
a = root[a];
return root[a];
}
void unio( int a, int b )
{
int x = find(a);
int y = find(b);
root[x] = y;
}
int main()
{
long long int n, k = 0, ans = 1;
cin>>n>>k;
for( int i = 0; i < n; i++ )
{
vector <int> temp (n);
for( int j = 0; j < n; j++ )
cin>>temp[j];
mat.push_back(temp);
}
root.resize(2*n);
for( int i = 0; i < n; i++ )
{
root[i] = i;
root[i+n] = i+n;
}
for( int i = 0; i < n - 1; i++ )
{
for( int j = i + 1; j < n; j++ )
{
bool flag = false;
for( int idx = 0; idx < n; idx++ )
if( mat[i][idx] + mat[j][idx] > k )
flag = true;
if( !flag )
unio(i,j);
}
}
for( int i = 0; i < n - 1; i++ )
{
for( int j = i + 1; j < n; j++ )
{
bool flag = false;
for( int idx = 0; idx < n; idx++ )
if( mat[idx][i] + mat[idx][j] > k )
flag = true;
if( !flag )
unio(i+n,j+n);
}
}
unordered_map <int, int> hash;
for( int i = 0; i <2*n; i++ )
hash[find(i)]++;
vector <long long int> fact (55, 1);
for( int i = 2; i < 55; i++ )
fact[i] = ( fact[i-1]*i )%MOD;
for( auto it: hash )
ans = ( (ans*fact[it.second])%MOD);
cout<<ans%MOD<<endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------
const ll mo=1000000007;
const int MAT=101;
struct Mat { ll v[MAT][MAT]; Mat(){ZERO(v);};};
ll modpow(ll a, ll n = mo-2) {
ll r=1;a%=mo;
while(n) r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1;
return r;
}
Mat mulmat(Mat& a,Mat& b,int n=MAT) {
ll mo2=4*mo*mo;
int x,y,z; Mat r;
FOR(x,n) FOR(y,n) r.v[x][y]=0;
FOR(x,n) FOR(z,n) FOR(y,n) {
r.v[x][y] += a.v[x][z]*b.v[z][y];
if(r.v[x][y]>mo2) r.v[x][y] -= mo2;
}
FOR(x,n) FOR(y,n) r.v[x][y]%=mo;
return r;
}
Mat powmat(ll p,Mat a,int n=MAT) {
int i,x,y; Mat r;
FOR(x,n) FOR(y,n) r.v[x][y]=0;
FOR(i,n) r.v[i][i]=1;
while(p) {
if(p%2) r=mulmat(r,a,n);
a=mulmat(a,a,n);
p>>=1;
}
return r;
}
int N,M,K;
int A[101];
void solve() {
int i,j,k,l,r,x,y; string s;
cin>>N>>M>>K;
Mat X;
FOR(i,N) {
X.v[i][i]=1;
cin>>A[i];
}
FOR(i,M) {
cin>>x>>y;
x--,y--;
(X.v[x][x]+=mo-modpow(2*M))%=mo;
(X.v[y][y]+=mo-modpow(2*M))%=mo;
(X.v[x][y]+=modpow(2*M))%=mo;
(X.v[y][x]+=modpow(2*M))%=mo;
}
X=powmat(K,X,N);
ll R[101]={};
FOR(y,N) FOR(x,N) (R[y]+=A[x]*X.v[y][x])%=mo;
FOR(i,N) cout<<R[i]<<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<cstdio>
#define F(i,l,r) for(int i=l,i##_end=r;i<i##_end;++i)
#define G(i,a,b,c) for(long long i=(a+c-1)/c*c;i<b;i+=c)
using namespace std;
typedef unsigned long long ull;
const int N=80,P[20]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71};
template<typename T>void read(T &x)
{
bool neg=false;
unsigned char c=getchar();
for(;(c^48)>9;c=getchar())if(c=='-')neg=true;
for(x=0;(c^48)<10;c=getchar())x=(x<<3)+(x<<1)+(c^48);
if(neg)x=-x;
}
long long a,b;
int c[N];
ull ans,f[N][1<<20];
int main()
{
read(a);read(b);++b;
F(j,0,20)
{
G(k,a,b,P[j])c[k-a]|=1<<j;
}
f[0][(1<<20)-1]=1;
F(i,0,b-a)F(j,0,1<<20)
{
if((c[i]&j)==0)f[i+1][j]=f[i][c[i]^j];
f[i+1][j]+=f[i][j];
}
F(j,0,1<<20)ans+=f[b-a][j];
printf("%llu\n",ans);
return 0;
}
| #include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
os << "(" << p.first << "," << p.second << ")";
return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << (x) << '\n'
#define debugArray(x, n) \
cerr << __LINE__ << ": " << #x << " = {"; \
for (long long hoge = 0; (hoge) < (long long)(n); ++(hoge)) \
cerr << ((hoge) ? "," : "") << x[hoge]; \
cerr << "}" << '\n'
#define debugMatrix(x, h, w) \
cerr << __LINE__ << ": " << #x << " =\n"; \
for (long long hoge = 0; (hoge) < (long long)(h); ++(hoge)) { \
cerr << ((hoge ? " {" : "{{")); \
for (long long fuga = 0; (fuga) < (long long)(w); ++(fuga)) \
cerr << ((fuga ? ", " : "")) << x[hoge][fuga]; \
cerr << "}" << (hoge + 1 == (long long)(h) ? "}" : ",") << '\n'; \
}
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#define debugMatrix(x, h, w) (void(0))
#endif
long long dp[1 << 20];
signed main() {
cin.tie(0);
ios::sync_with_stdio(0);
int p[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;
cin >> A >> B;
dp[0] = 1;
long long ans = 0;
for (long long x = A; x <= B; x++) {
int b = 0;
for (int i = 0; i < 20; i++)
if (x % p[i] == 0) b |= 1 << i;
for (int s = 0; s < (1 << 20); s++)
if ((s & b) == 0) { dp[s | b] += dp[s]; }
}
for (int s = 0; s < (1 << 20); s++) ans += dp[s];
cout << ans << '\n';
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<iostream>
using namespace std;
int main()
{
int a,b,c;
int sum=0;
cin>>a>>b>>c;
sum=(7-a)+(7-b)+(7-c);
cout<<sum<<endl;
return 0;
} |
#include <iostream>
#include <iomanip>
#include <vector>
#include <array>
#include <stack>
#include <queue>
#include <tuple>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <map>
#include <numeric>
#include <cassert>
using ull = unsigned long long;
using ll = long long;
#define REP(i, n) for(ll i=0;i<(ll)n;i++)
#define REPab(i,a,b)for(ll i=(ll)a;i<(ll)b;i++)
constexpr bool bitp(ull bits, ull pos) { return bits & (1ULL << pos); }
constexpr ll mod(ll val, ll m) { return (val >= 0) ? (val % m) : (val % m + m); }
template <class T> void chmin(T& a, T b) { a = std::min(a, b); }
template <class T> void chmax(T& a, T b) { a = std::max(a, b); }
int main() {
ll N; std::cin >> N;
std::vector<ll> C(N);
std::vector<std::vector<ll>> routes(N);
REP(i, N) std::cin >> C[i];
REP(i, N-1) {
ll a, b;
std::cin >> a >> b;
routes[a - 1].push_back(b - 1);
routes[b - 1].push_back(a - 1);
}
std::vector<ll> goods;
std::unordered_set<ll> map;
const auto search = [&](auto&& search, ll node, ll parent) -> void {
const auto it = map.find(C[node]);
if (it == map.end()) {
goods.push_back(node);
map.insert(C[node]);
for (const auto& child : routes[node]) {
if (child != parent) {
search(search, child, node);
}
}
map.erase(C[node]);
}
else {
for (const auto& child : routes[node]) {
if (child != parent) {
search(search, child, node);
}
}
}
};
search(search, 0, -1);
std::sort(goods.begin(), goods.end());
for (const auto& g : goods) {
std::cout << g + 1 << "\n";
}
}
| #include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll long long
#define pb push_back
#define all(v) v.begin(),v.end()
const int INF=1e9+7;
const int N=1e5+5;
int col[N],frec[N];
vector<int>adj[N];
vector<int>ans;
void dfs(int node,int pa){
frec[col[node]]++;
if(frec[col[node]]==1)
ans.pb(node);
for(auto p:adj[node]){
if(p==pa)continue;
dfs(p,node);
}
frec[col[node]]--;
}
int main(){
FAST;
int n;
cin>>n;
for(int i=0;i<n;i++)
cin>>col[i];
for(int i=1;i<n;i++){
int a,b;
cin>>a>>b;
a--;b--;
adj[a].pb(b);
adj[b].pb(a);
}
dfs(0,-1);
sort(all(ans));
for(auto p:ans)
cout<<p+1<<endl;
return 0;
}
|
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <iomanip>
#include <random>
#include <climits>
#include <set>
#include <map>
using namespace std;
/*
*/
int main() {
int n;
long double D, H;
cin >> n >> D >> H;
vector<long double> d(n);
vector<long double> h(n);
for (int i = 0; i < n; ++i) {
cin >> d[i] >> h[i];
}
long double height = 1100;
long double a = 0;
long double b = 0;
bool flag = true;
for (int i = 0; i < n; ++i) {
flag = true;
a = (H - h[i]) / (D - d[i]);
b = h[i] - a * d[i];
//cout << a << endl;
//cout << b << endl;
if (b <= 0)continue;
for (int j = 0; j < n; ++j) {
if (i == j)continue;
if (h[j] > a * d[j] + b) {
flag = false;
break;
}
}
if (flag) {
height = min(height, b);
}
}
if (height != 1100)cout << height << endl;
else cout << "0.0" << endl;
return 0;
} | #include<bits/stdc++.h>
typedef unsigned long long ull;
typedef long long ll;
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define nep(i,r,l) for(int i=r;i>=l;i--)
void sc(int &x){scanf("%d",&x);}
void sc(int &x,int &y){scanf("%d%d",&x,&y);}
void sc(int &x,int &y,int &z){scanf("%d%d%d",&x,&y,&z);}
void sc(ll &x){scanf("%lld",&x);}
void sc(ll &x,ll &y){scanf("%lld%lld",&x,&y);}
void sc(ll &x,ll &y,ll &z){scanf("%lld%lld%lld",&x,&y,&z);}
void sc(char *x){scanf("%s",x);}
void sc(char *x,char *y){scanf("%s%s",x,y);}
void sc(char *x,char *y,char *z){scanf("%s%s%s",x,y,z);}
void out(int x){printf("%d\n",x);}
void out(ll x){printf("%lld\n",x);}
void out(int x,int y){printf("%d %d\n",x,y);}
void out(ll x,ll y){printf("%lld %lld\n",x,y);}
void out(int x,int y,int z){printf("%d %d %d\n",x,y,z);}
void out(ll x,ll y,ll z){printf("%lld %lld %lld\n",x,y,z);}
using namespace std;
const int N=3e5+5;
int n,d,h;
struct node
{
double x,y;
void sc()
{
scanf("%lf%lf",&x,&y);
}
}a,b,x;
int main()
{
//freopen("1.in","r",stdin);freopen("1.out","w",stdout);
sc(n);
a.sc();
x.x=0;
double ans=0;
while(n--)
{
b.sc();
double d=atan2((b.y-a.y),(b.x-a.x));
double l=0,r=2000;
for(int i=1;i<=50;i++)
{
double m=(l+r)/2;
if(a.x+m*cos(d)<=0) r=m;
else l=m;
}
ans=max(ans,a.y+(l+r)/2*sin(d));
}
printf("%.10f\n",ans);
}
|
#include<bits/stdc++.h>
using namespace std;
#define gc() getchar()
#define pc(a) putchar(a)
#define int long long
#define inf (1ll<<60)
inline int read()
{
int x=0,f=1;
char c=gc();
while(c<'0'||c>'9')
{
if(c=='-') f=-f;
c=gc();
}
while(c>='0'&&c<='9') x=x*10+c-'0',c=gc();
// cout<<x<<endl;
return x*f;
}
int nnu[25];
inline void write(int x)
{
if(x<0) pc('-'),x=-x;
if(!x)
{
pc('0');
return;
}
int tp=0;
while(x) nnu[++tp]=x%10,x/=10;
while(tp) pc(nnu[tp--]+'0');
return;
}
#define ma 500005
%:define db double
const db eps=1e-6;
inline bool eq(db x,db y)
{
return fabs(x-y)<=eps;
}
struct point
{
db x,y;
}A[ma],B[ma];
inline db dis(point x,point y)
{
return (x.x-y.x)*(x.x-y.x)+(x.y-y.y)*(x.y-y.y);
}
point O,Q;
inline db S(point a,point b)
{
return a.x*b.y-a.y*b.x;
}
inline db S(point a,point b,point c)
{
return S(a,b)+S(b,c)+S(c,a);
}
inline db cs(point a,point b,point c)
{
db aa=dis(b,c),cc=dis(a,b);
if(eq(aa,0)||eq(cc,0)) return 1e9;
return S(a,b,c)/(aa*cc);
}
struct pq
{
db x,y;
}a[ma],b[ma];
inline bool cmp(pq x,pq y)
{
return eq(x.x,y.x)?x.y<y.y:x.x<y.x;
}
inline bool eq(pq x,pq y)
{
return eq(x.x,y.x)&&eq(x.y,y.y);
}
inline void pre(int ido,int idq,point P[],pq x[],int n)
{
O=P[ido],Q=P[idq];
for(int i=1;i<=n;i++) x[i].x=dis(P[i],O),x[i].y=cs(P[i],O,Q);
sort(x+1,x+n+1,cmp);
return;
}
inline bool cpp(int n)
{
// for(int i=1;i<=n;i++) printf("(%0.3lf,%0.3lf) ",a[i].x,a[i].y);
// cout<<endl;
// for(int i=1;i<=n;i++) printf("(%0.3lf,%0.3lf) ",b[i].x,b[i].y);
// cout<<endl;
for(int i=1;i<=n;i++)
if(!eq(a[i],b[i]))
{
// cout<<i<<endl;
return 0;
}
return 1;
}
signed main()
{
int n=read();
if(n==1)
{
puts("Yes");
return 0;
}
for(int i=1;i<=n;i++) A[i].x=read(),A[i].y=read();
for(int i=1;i<=n;i++) B[i].x=read(),B[i].y=read();
pre(1,2,A,a,n);
for(int ido=1;ido<=n;ido++)
for(int idq=1;idq<=n;idq++)
{
if(ido==idq) continue;
pre(ido,idq,B,b,n);
if(cpp(n))
{
puts("Yes");
return 0;
}
}
puts("No");
}
| #include <bits/stdc++.h>
#define rep(i, l, r) for (int i = l; i <= r; ++i)
#define per(i, r, l) for (int i = r; i >= l; --i)
using namespace std;
const int N = 105;
const int inf = 0x3fffffff;
typedef long long ll;
int T;
int n, m;
class dot {
public:
int x, y;
dot() {}
dot(int _x, int _y) : x(_x), y(_y) {}
dot operator-(const dot &d) const { return dot(x - d.x, y - d.y); }
int operator*(const dot &d) { return x * d.x + y * d.y; }
int operator/(const dot &d) { return x * d.y - y * d.x; }
void read() { scanf("%d%d", &x, &y); }
} a[N], b[N];
int main() {
scanf("%d", &n);
rep(i, 1, n) { a[i].read(); }
rep(i, 1, n) { b[i].read(); }
bool ans = false;
rep(i1, 1, n) {
rep(i2, 1, n) {
if ((b[i2] - b[i1]) * (b[i2] - b[i1]) !=
(a[2] - a[1]) * (a[2] - a[1]))
continue;
// printf("%d %d:\n", i1, i2);
bool flag = true;
rep(i, 3, n) {
bool f = false;
rep(j, 1, n) {
if ((b[j] - b[i1]) * (b[i2] - b[i1]) ==
(a[i] - a[1]) * (a[2] - a[1]) &&
(b[j] - b[i1]) / (b[i2] - b[i1]) ==
(a[i] - a[1]) / (a[2] - a[1])) {
f = true;
// printf(" %d %d\n", i, j);
break;
}
}
if (!f) {
flag = false;
break;
}
}
if (flag) {
ans = true;
break;
}
}
}
if (n == 1) ans = true;
printf(ans ? "Yes\n" : "No\n");
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mii map <int, int>
#define mll map <ll, ll>
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vd vector <double>
#define vll vector <ll>
#define fi first
#define se second
#define si set <int>
#define sll set <ll>
#define spii set <pii>
#define vs vector <string>
#define vpii vector <pair <int, int> >
#define vpll vector <pair <long long, long long> >
#define vvi vector <vector <int> >
#define vvpii vector <vector <pii > >
#define vb vector <bool>
#define vvb vector <vb>
#define mp make_pair
#define vvll vector <vll>
#define vsi vector <si>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define MANX MAXN
#define itn int
#define dbg(x); {cout << #x << "=" << x << ", ";}
#define in(x); { for (auto &to : x) cin >> to;}
#define out(x); { for (auto &to : x) cout << to << " "; cout << '\n'; }
template<class T>
bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T>
bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
const ll INFLL = 1e18;
const int MAXN = 1e6 + 100;
const ll INF = 1e9;
const int mod1 = 1e9 + 7;
const int mod2 = 1e9 + 21;
void solve() {
int x, y;
cin >> x >> y;
cout << (x == y ? x : 3 ^ x ^ y) << '\n';
}
int main() {
#ifdef Mip182
freopen("a.in", "r", stdin);
#else
ios_base::sync_with_stdio(0);
cin.tie(0);
#endif
int _t;
_t = 1;
// cin>>_t;
while (_t--)
solve();
#ifdef Mip182
cout << '\n' << "Time : " << (double) (clock()) / CLOCKS_PER_SEC << '\n';
#endif
}
| #include<bits/stdc++.h>
using namespace std;
#ifdef local
string to_string(vector<bool> v) {
bool first = true;
string res = "{";
for (int i = 0; i < static_cast<int>(v.size()); i++) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(v[i]);
}
res += "}";
return res;
}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
typedef long long ll;
#define f(i, l, r) for(int i=l;i<=r;i++)
#define rf(i, r, l) for(int i=r;i>=l;--i)
#define all(x) x.begin(),x.end()
const int N = 2e5+10, mod = 1e9+7;
ll power(ll a, ll b) {ll res = 1;while (b) {if (b & 1)res = res * a % mod;a = a * a % mod;b >>= 1;}return res;}
ll INV(ll a){return power(a,mod-2);}
mt19937 Rand(123456);
int Range(int l,int r){
return l+Rand()%(r-l+1);
}
vector<int> g[N];
int dis[N];
int T,D;
int mx_dep[N],ans[N];
void dfs(int u,int f){
if(dis[u]>D){
D=dis[u];T=u;
}
mx_dep[u]=dis[u];
for(int v:g[u])if(v!=f){
dis[v]=dis[u]+1;
dfs(v,u);
mx_dep[u]=max(mx_dep[u],mx_dep[v]);
}
}
int sz[N];
int step;
void dfs2(int u,int f){
debug(u,dis[u]);
sort(all(g[u]),[&](int l,int r){
return mx_dep[l]<mx_dep[r];
});
ans[u]=++step;
for(int v:g[u])if(v!=f){
dfs2(v,u);
}
step++;
}
int main() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#ifdef local
freopen("../in.txt", "r", stdin);
#endif
int n;cin>>n;
f(i,1,n-1){
int u,v;cin>>u>>v;
g[u].push_back(v);
g[v].push_back(u);
}
D=-1;dfs(1,0);
D=-1;int k=T;dis[k]=1;dfs(T,0);
dfs2(k,0);
f(i,1,n)cout<<ans[i]<<" ";
} |
#include <bits/stdc++.h>
using namespace std;
int n, a[5001], g[5001], c[5001], t[5001], ans;
char s[5002];
int main()
{
scanf("%d %s", &n, s + 1);
for (int i = 1; i <= n; ++i) {
a[i] = a[i - 1] + (int)(s[i] == 'A');
g[i] = g[i - 1] + (int)(s[i] == 'G');
c[i] = c[i - 1] + (int)(s[i] == 'C');
t[i] = t[i - 1] + (int)(s[i] == 'T');
}
for (int i = 1; i < n; ++i) {
for (int j = i + 1; j <= n; ++j) {
if ((j - i + 1) & 1) continue;
if (a[j] - a[i - 1] == t[j] - t[i - 1] &&
g[j] - g[i - 1] == c[j] - c[i - 1]) {
++ans;
}
}
}
printf("%d\n", ans);
return 0;
} | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize ("Ofast")
#pragma GCC optimization ("unroll-loops, no-stack-protector")
#pragma GCC target ("avx")
#pragma GCC target ("avx2")
#pragma GCC target ("fma")
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define pll pair <ll, ll>
#define pci pair <char, int>
#define pld pair <ld, ld>
#define ppld pair <pld, pld>
#define ppll pair <pll, pll>
#define pldl pair <ld, ll>
#define vll vector <ll>
#define vvll vector <vll>
#define vpll vector <pll>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define mll map <ll, ll>
#define fastmap gp_hash_table
#define cd complex <double>
#define vcd vector <cd>
#define PI 3.14159265358979
#define ordered_set tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update>
#pragma 03
using namespace std;
using namespace __gnu_pbds;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
// "Em gioi roi, em o dang cap khac" - Vu Minh Chau aka. abc15566
mll occ;
int main(){
fastio;
ll n; string s; cin >> n >> s;
ll cprefix = 0; occ[0] = 1;
ll ans = 0;
for (ll i = 0; i < n; i++){
if (s[i] == 'A') cprefix += 1000000;
else if (s[i] == 'T') cprefix -= 1000000;
else if (s[i] == 'C') cprefix++;
else cprefix--;
ans += occ[cprefix]; occ[cprefix]++;
}
cout << ans << "\n";
} |
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define FIO ios_base::sync_with_stdio(false); cin.tie(0);
#define trav(x,a) for (auto& x: a)
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define mem(a,v) memset((a), (v), sizeof (a))
#define endl "\n"
#define case(t) cout << "Case #" << (t) << ": "
#define reada(a, n) for (int _i = 0; _i < (n); _i++) read(a[_i])
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define st first
#define nd second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int mod = 1e9 + 7;
const int inf = 1e9 + 7;
const int N = 1e6 + 5;
const double eps = 1e-9;
template<class T> void read(T& x) { cin >> x; }
template<class X, class Y> void read(pair<X,Y>& a) { read(a.first), read(a.second); }
template<class T, size_t U> void read(array<T,U>& x) { for (int i = 0; i < U; i++) read(x[i]); }
template<class T> void read(vector<T>& x) { trav(y, x) read(y); }
template<class T, class... O> void read(T& x, O&... y) { read(x), read(y...); }
string to_string(const char& x) { return string(1,x); }
string to_string(const char*& x) { return (string)x; }
string to_string(const string& x) { return x; }
template<class T, class U> string to_string(const pair<T,U>& x) { return to_string(x.first) + " " + to_string(x.second); }
template<class T, size_t U> string to_string(const array<T,U>& x) { string ret = ""; for (int i = 0; i < U; i++) ret += (!i ? "" : " ") + to_string(x[i]); return ret; }
template<class T> string to_string(const vector<T>& x) { string ret = ""; bool f = 0; trav(y, x) ret += (!f ? "" : " ") + to_string(y), f = 1; return ret; }
template<class T> string to_string(const set<T>& x) { string ret = ""; bool f = 0; trav(y, x) ret += (!f ? "" : " ") + to_string(y), f = 1; return ret; }
void print() { cout << endl; }
template<class T> void pr(const T& x) { cout << to_string(x); }
template<class T, class... O> void print(const T& x, const O&... y) { pr(x); if (sizeof...(y)) pr(" "); print(y...); }
int sm[N];
int main() {
FIO
int n, k; read(n, k);
ll ans = 0;
for (int i = 2; i <= 2 * n; i++) {
sm[i] = min(2*n-(i-1), i-1);
}
for (int i = 2; i <= 2 * n; i++) {
if (2 <= i + k && i + k <= 2 * n)
ans += sm[i] * 1ll * sm[i + k];
}
print(ans);
return 0;
}
| // ConsoleApplication1.cpp : Defines the entry point for the console application.
//
#include <stack>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <queue>
#include <climits>
#define MAXCHAR 255
#define ll long long
using namespace std;
const ll dividend = 1000000007;
const ll limit = pow(10, 18);
const ll bigNum = pow(10, 9);
const int intMax = 2147483647;
ll funcComb(int n, int k)
{
ll output = 1;
int sum = n + k;
vector<int> dividends;
for (int i = 0; i < k; i++)
{
dividends.push_back(k - i);
}
for (int i = 0; i < k; i++)
{
output *= sum - i;
for (auto it = dividends.begin(); it != dividends.end(); it++)
{
if (*it == 0)
continue;
if (output % *it == 0)
{
output /= *it;
*it = 0;
}
}
if (output > dividend)
{
output %= dividend;
}
}
return output;
}
ll funcPow(int n, int r)
{
ll ret = 1;
for (int i = 1; i <= r; i++)
{
ret *= n;
if (ret > dividend)
ret %= dividend;
}
return ret;
}
int main()
{
double a, b, out = 0;
cin >> a >> b;
out = a * b / 100;
cout << out << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repp(i, st, en) for (ll i = (ll)st; i < (ll)(en); i++)
#define repm(i, st, en) for (ll i = (ll)st; i >= (ll)(en); i--)
#define all(v) v.begin(), v.end()
void chmax(ll &x, ll y) {x = max(x,y);}
void chmin(ll &x, ll y) {x = min(x,y);}
void Yes() {cout << "Yes" << endl; exit(0);}
void No() {cout << "No" << endl; exit(0);}
template<class in_Cout> void Cout(in_Cout x) {cout << x << endl; exit(0);}
const ll inf = 1e18;
const ll mod = 1e9 + 7;
struct edge {
ll to, cost, K;
};
vector<edge> G[110000];
ll dist[110000];
ll dijkstra(ll s, ll g) {
rep(i,110000) dist[i] = inf;
dist[s] = 0LL;
priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>> que;
que.push({0,s});
while (que.size()) {
pair<ll,ll> p = que.top();
que.pop();
ll now = p.second, t = p.first;
if (dist[now]<t) continue;
for (edge e : G[now]) {
ll to = e.to, cost = e.cost, K = e.K;
ll dt = (K - (t % K)) % K;
if (dist[to] <= t + dt + cost) continue;
dist[to] = t + dt + cost;
que.push({dist[to],to});
}
}
if (dist[g]==inf) return -1;
else return dist[g];
}
int main() {
ll N, M, X, Y;
cin >> N >> M >> X >> Y;
rep(i,M) {
ll a, b, t, k;
cin >> a >> b >> t >> k;
G[a].push_back({b,t,k});
G[b].push_back({a,t,k});
}
cout << dijkstra(X,Y) << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;
using LD = long double;
template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <typename T> void coutall(T v) { for(auto i = v.begin(); i != --v.end(); i++){cout << *i << " ";} cout << *--v.end() << endl; }
void yes(bool ok = true){ cout << (ok ? "yes" : "no") << endl; }
void Yes(bool ok = true){ cout << (ok ? "Yes" : "No") << endl; }
void YES(bool ok = true){ cout << (ok ? "YES" : "NO") << endl; }
ll myceil(ll a, ll b) { return (a + (b - 1)) / b; }
int n, m;
vector<vector<P>> to;
vector<P> edge;
vi c;
vector<string> ans;
void dfs(int v){
for(auto [u, id] : to[v]){
if(c[v] > c[u]){
// v -> u
if(edge[id].fi == v) ans[id] = "->";
else ans[id] = "<-";
}else if(c[v] < c[u]){
// u -> v
if(edge[id].fi == v) ans[id] = "<-";
else ans[id] = "->";
}else{
ans[id] = "?";
}
}
}
void dfs2(int v, int p = -1){
for(auto [u, id] : to[v]){
if(u == p) continue;
if(ans[id] != "?") continue;
if(edge[id].fi == v) ans[id] = "->";
else ans[id] = "<-";
dfs2(u, v);
}
}
void Main(){
cin >> n >> m;
to.resize(n);
c.resize(n);
edge.resize(m);
ans.resize(m);
rep(i, m){
int a, b; cin >> a >> b;
a--; b--;
to[a].pb({b, i});
to[b].pb({a, i});
edge[i] = {a, b};
}
rep(i, n) cin >> c[i];
rep(i, n) dfs(i);
rep(i, m) {
if(ans[i] == "?") dfs2(edge[i].fi);
}
rep(i, m) cout << ans[i] << endl;
return;
}
int main(){
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(15);
Main();
return 0;
} |
#include <iostream>
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <algorithm>
using ll = long long;
#define fast_io \
ios::sync_with_stdio(false); \
cin.tie(0)
using namespace std;
int dx[4] = { 0,0,1,-1 };
int dy[4] = { 1,-1,0,0 };
void solve(ll ttt) {
ll n,t;
cin >>t>>n;
ll ans;
ll time = n * 100 / t + ((n * 100) % t > 0);
ans = time * (100 + t) / 100 - 1;
cout << ans << endl;
}
int main(void)
{
ll ttt = 0;
//cin >> t; for (ll i = 1; i <= t; i++) {solve(i);}
solve(ttt);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
#define F first
#define S second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define debug(a) cout << #a << " = " << a << " ";
template<typename T> istream &operator>>(istream &is, vector<T> &vec) { for (auto &v : vec) is >> v; return is; }
template<typename T> using min_heap = priority_queue<T, vector<T>, greater<T>>;
const int MOD=1000000007;
const int N=100005;
void solve(){
ll a,b,c,d;
cin>>a>>b>>c>>d;
ll A=a*d-b*c;
cout<<A;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long int t=1;
// cin>>t; // DON'T FORGET IT. ^^^
for(long int tt=1;tt<=t;tt++){
solve();
}
cerr << "Time : " << 1000 * ((double) clock()) / (double) CLOCKS_PER_SEC << "ms\n";
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
int main()
{
double a,b,c,d;
double x,m;
cin>>a>>b>>c>>d;
m=d/b;
x=(c-a)/(1+m)+a;
printf("%.10lf",x);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define ll long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define VVI vector<vector<int>>
#define PII pair<int,int>
#define VPII vector<PII>
#define LD long double
#define INF 1000000000000
#define MOD 1000000007
#define COMAX 110000 // combnation array max range
#define MAXR 100000 // array max range
#define FI first
#define SE second
#define PQG priority_queue<int,VI,greater<int>> // Ascending. e.g. 1..n
#define PQL priority_queue<int,VI,less<int>> // Descending. e.g. n..1
#define SETG set<int,greater<int>> // Descending. e.g. n..1
#define SETL set<int,less<int>> // Ascending. e.g. 1..n
#define vecprint(v) R(i,v.size())cerr << v[i] << " ";cerr << 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 (b<a) { a=b; return 1; } return 0; }
template<class T>T min(vector<T> &v) { return *min_element(v.begin(),v.end()); }
template<class T>T max(vector<T> &v) { return *max_element(v.begin(),v.end()); }
template<class T>T modpow(T a, T b, T m) { a %= m; T r = 1; while (b > 0) { if (b & 1) r = (r * a) % m; a = (a * a) % m; b >>= 1; } return r; }
ll modinv(ll a,ll m=MOD) {ll b = m, u = 1, v = 0;while (b) {ll t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}
template<class T>string radixconv(T n, T k){ string s; while(n/k){ s=to_string(n%k)+s; n/=k; } s=to_string(n%k)+s; return s; }
template<class T>vector<T> divs(T n){ T t=1; vector<T> r; while(t*t<=n){ if(!(n%t)){ r.push_back(t); if(t!=(n/t)) r.push_back(n/t); } t++; } return r; } // sqrt(n)
template<class T>vector<T> commondivs(vector<T> ns){ T mn=min(ns); vector<T> r; for(auto &d:divs(mn)){ for(int i=0;i<(int)ns.size();i++){ if(ns[i]%d) break; if(!((int)ns.size()-1-i)) r.push_back(d); } } return r; }
template<class T>vector<bool> eratosieve(T n){vector<bool> r((n+1>2 ? n+1 : 2),1);r[0]=0;r[1]=0;for(int i=2;i*i<=n;i++){if(r[i]){for(int j=i+i;j<=n;j+=i){r[j]=0;}}}return r;} // nloglogn
template<class T>T gcd(T a, T b) { return b ? gcd(b, a%b) : a; }
template<class T>T lcm(T a, T b) { return a*b/gcd(a,b); }
template<class T>vector<T> primefactor(T n){ vector<T> r; auto c = divs(n); for(auto &i:c){ for(auto &j:c){ if(i!=j && j!=1 && !(i%j)) break; if(j==c.back()) r.push_back(i); } } return r; }
template<class T>vector<pair<T,T>> primefactors(T n){ vector<pair<T,T>> r; for(int i=2;i*i<=n;i++){if(n%i)continue;int e=0;while(!(n%i)){n/=i;e++;}r.push_back(make_pair(i,e));}if(n!=1) r.push_back(make_pair(n,1));return r; }
template<class T>long long binsearch(long long from,long long to,T fn){while(to-from > 1){long long mid = (to+from)/2;if(fn(mid)){from=mid;}else{to=mid;}}return from;}
struct Comb{ll fac[COMAX+1],finv[COMAX+1],inv[COMAX+1];Comb() {init();}void init() {fac[0]=fac[1]=1;finv[0]=finv[1]=1;inv[1]=1;FOR(i,2,COMAX){fac[i] = ((fac[i - 1]%MOD) * (i%MOD)) % MOD;inv[i] = (((-inv[MOD%i]%MOD+MOD)%MOD) * ((MOD/i) % MOD))%MOD;finv[i] = ((finv[i - 1]%MOD) * (inv[i]%MOD)) % MOD;}}ll com(ll n,ll k){if(n<k)return 0;if(n<0 || k<0)return 0;return (((fac[n] * finv[k])%MOD) * finv[n - k] % MOD) % MOD;}};
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout << fixed << setprecision(11);
cerr << fixed << setprecision(6);
LD x1,y1,x2,y2;
cin >> x1 >> y1 >> x2 >> y2;
y2=-y2;
cerr << "y2:" << y2 << endl;
LD a=(y2-y1)/(x2-x1);
cerr << "a:" << a << endl;
LD b=y1-a*x1;
cerr << "b:" << b << endl;
LD ans=b/(-a);
//if(x1<x2){
// ans=abs(ans)+x1;
//}else{
// ans=x1-abs(ans);
//}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
#define SZ(x) (int) x.size()
#define F first
#define S second
const int N = 1e6 + 10, MOD = 1e9 + 7;
ll n, m, T, L[N], R[N], c;
int main() {
scanf("%lld%lld%lld", &n, &m, &T); c = n;
for (int i = 1; i <= m; i++) {
scanf("%lld%lld", &L[i], &R[i]);
}
for (int i = 1; i <= m; i++) {
c = max(0LL, c - (L[i] - R[i - 1]));
if (c == 0) return !printf("No\n");
c = min(n, c + R[i] - L[i]);
}
if (T - R[m] >= c) printf("No\n");
else printf("Yes\n");
return 0;
}
| #include <bits/stdc++.h>
#define vi vector<int>
#define tests int t; cin>>t; while(t--)
#define ll long long
#define vll vector<long long>
#define srt(v) sort(v.begin(), v.end())
#define srtg(v) sort(v.begin(), v.end(), greater<int> ())
#define FOR(k, n) for(int k=0; k<n; k++)
#define pb push_back
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define printarr(v) for(auto& x : v) cout<<x<<" "; cout<<endl
#define ree cout<<"******************************************"<<endl
#define double long double
using namespace std;
char nums[10] = { '0','1','2','3','4','5','6','7','8','9' };
char alphsl[26] = { 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z' };
const int MOD = 1000000007;
char alphs[26] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };
const double pi = 3.14159265358;
void solve() {
int n, m, t;
cin>>n>>m>>t;
vi a(m), b(m);
for(int i=0; i<m; i++){
cin>>a[i]>>b[i];
}
int last=0, start=n;
for(int i=0; i<m; i++){
n-=a[i]-last;
if(n<=0){
cout<<"No"<<endl;
return;
}
n+=b[i]-a[i];
n=min(start, n);
last=b[i];
}
n-=t-last;
if(n<=0){
cout<<"No"<<endl;
return;
}
cout<<"Yes"<<endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
//tests
solve();
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
#define FOR(i, a, b) for(ll i=(a); i < (ll)(b); ++i)
template<class T> inline bool chmax(T& a, T b) { if(a < b){ a=b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if(a > b){ a=b; return 1; } return 0;}
int main(){
int a[3];
REP(i,3) cin >> a[i];
sort(a, a+3);
if(a[1]-a[0]== a[2]-a[1] )cout << "Yes\n";
else cout<<"No\n";
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
#define rreps(i, n) for(int i=((int)(n)); i>0; --i)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void Yes(bool a) { cout << (a?"Yes":"No") << endl; }
void YES(bool a) { cout << (a?"YES":"NO") << endl; }
int main(int argc, char **argv) {
int a, b, c; cin >> a >> b >> c;
bool flag = false;
if (a*2 == b + c) flag = true;
if (b*2 == a + c) flag = true;
if (c*2 == a + b) flag = true;
Yes(flag);
} |
//DUEL
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define x first
#define y second
#define pii pair<int,int>
#define pb push_back
#define eb emplace_back
#pragma GCC optimize("unroll-loops")
#define shandom_ruffle(a, b) shuffle(a, b, rng)
#define vi vector<int>
#define vl vector<ll>
#define popcnt __builtin_popcount
#define popcntll __builtin_popcountll
#define all(a) begin(a),end(a)
using namespace std;
using namespace __gnu_pbds;
using ll=long long;
using ull=unsigned long long;
using ld=long double;
const int MOD=998244353;
vector<int> bases;
const ll LLINF=1ll<<60;
const char en='\n';
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void yes() {cout<<"YES"<<en; exit(0);}
void no() {cout<<"NO"<<en; exit(0);}
inline int rund() {int x576363482791fuweh=rng();return abs(x576363482791fuweh)%RAND_MAX;}
template<class T>
void prVec(vector<T> w,bool fl=false)
{
cout<<w.size()<<en;
for (int i=0;i<int(w.size())-1;++i) cout<<w[i]<<' ';
if (w.size()) cout<<w[w.size()-1]<<en;
if (fl) cout<<flush;
}
ll raand()
{
ll a=rund();
a*=RAND_MAX;
a+=rund();
return a;
}
#define rand raand
ll raaand()
{
return raand()*(MOD-7)+raand();
}
void compress(vi&v)
{
set<int> s;
for (auto a: v) s.insert(a);
vi o(all(s));
for (auto&a: v) a=lower_bound(all(o),a)-o.begin();
}
void compress(vl&v)
{
set<ll> s;
for (auto a: v) s.insert(a);
vl o(all(s));
for (auto&a: v) a=lower_bound(all(o),a)-o.begin();
}
string to_upper(string a)
{
for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A';
return a;
}
string to_lower(string a)
{
for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A';
return a;
}
ll sti(string a,int base=10)
{
ll k=0;
for (int i=0;i<(int)a.size();++i)
{
k*=base;
k+=a[i]-'0';
}
return k;
}
template<class T>
void eras(vector<T>& a,T b)
{
a.erase(find(a.begin(),a.end(),b));
}
string its(ll k,int base=10)
{
if (k==0) return "0";
string a;
while (k)
{
a.push_back((k%base)+'0');
k/=base;
}
reverse(a.begin(),a.end());
return a;
}
ll min(ll a,int b)
{
if (a<b) return a;
return b;
}
ll min(int a,ll b)
{
if (a<b) return a;
return b;
}
ll max(ll a,int b)
{
if (a>b) return a;
return b;
}
ll max(int a,ll b)
{
if (a>b) return a;
return b;
}
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;
}
template<class T,class K>
pair<T,K> mp(T a,K b)
{
return make_pair(a,b);
}
inline int mult(ll a,ll b)
{
return (a*b)%MOD;
}
inline int pot(int n,int k)
{
if (k==0) return 1;
ll a=pot(n,k/2);
a=mult(a,a);
if (k%2) return mult(a,n);
else return a;
}
int divide(int a,int b)
{
return mult(a,pot(b,MOD-2));
}
inline int sub(int a,int b)
{
if (a-b>=0) return a-b;
return a-b+MOD;
}
inline int add(int a,int b)
{
if (a+b>=MOD) return a+b-MOD;
return a+b;
}
bool prime(ll a)
{
if (a==1) return 0;
for (int i=2;i<=round(sqrt(a));++i)
{
if (a%i==0) return 0;
}
return 1;
}
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
const int N=300010;
int k,n,ch[1000][1000],a[N],sa[N];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
for (int i=0;i<10;++i) bases.push_back(rand()%(MOD-13893829*2)+13893829);
cin>>n>>k;
for (int i=0;i<n;++i)
{
int x;
cin>>x;
for (int j=0,r=1;j<=k;++j,r=mult(r,x)) sa[j]=add(sa[j],r);
}
for (int i=0;i<=k;++i)
{
ch[i][0]=1;
for (int j=1;j<=i;++j) ch[i][j]=add(ch[i-1][j],ch[i-1][j-1]);
}
for (int i=1;i<=k;++i)
{
int su=0;
for (int j=0;j<=i;++j) su=add(su,mult(ch[i][j],mult(sa[j],sa[i-j])));
su=sub(su,mult(sa[i],pot(2,i)));
su=divide(su,2);
cout<<su<<en;
}
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define pp pair<ll,ll>
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
constexpr int inf=1000001000;
constexpr ll INF=2e18;
constexpr ll mod=1000000007;
// ll MOD=998244353;
const ll MOD=998244353;
void Add(int &a, int b) {
a += b;
while (a >= MOD) a -= MOD;
while (a < 0) a += MOD;
}
void Mul(int &a, int b) {
a = 1LL * a * b % MOD;
}
int Pow(int b, int e) {
if (e < 0) e += MOD - 1;
int ret = 1;
while (e) {
if (e & 1) ret = 1LL * ret * b % MOD;
b = 1LL * b * b % MOD;
e >>= 1;
}
return ret;
}
int main() {
int n,k;
cin >> n >> k;
vector<ll> a(n);
rep(i,n) cin >> a[i];
// vector<vector<ll>> b(n,vector<ll>(k+1,1));
vector<ll> b(n,1);
vector<ll> e(k+5,0);
rep(i,k+1) e[i]=Pow(i,MOD-2);
vector<ll> c(k+1,0);
rep(i,n){
rep(j,k+1){
(c[j]+=b[i])%=MOD;
b[i]=(b[i]*a[i]%MOD*e[j+1])%MOD;
}
}
// rep(i,n){
// rep(j,k+1) (c[j]+=b[i][j])%=MOD;
// }
vector<ll> ans(k+1);
ans[1]=1;
rep(i,k){
ans[i+2]=(ans[i+1]*(i+2))%MOD;
}
vector<ll> o(k,0);
rep(i,k){
rep(j,k+1){
if (i+1-j<0) break;
(o[i]+=c[j]*c[i+1-j]%MOD)%=MOD;
}
}
vector<ll> p(k+2,0);
ll cc;
rep(i,n){
cc=a[i]*2;
rep(j,k) {
(p[j]+=cc)%=MOD;
(cc*=a[i]*2)%=MOD;
}
}
rep(i,k) cout << ((ans[i+1]*o[i]%MOD+MOD-p[i])%MOD)*Pow(2,MOD-2)%MOD << endl;
}
|
#include <cstdio>
#include <algorithm>
const int N = 2e5 + 5;
typedef long long LL;
int n, m, cntob;
int mxr[N], mxc[N];
int qry[N];
namespace BIT { // 树状数组
int t[N];
void add(int x) { while(x <= n) t[x]++, x += (x & -x); }
int query(int x) { int ret = 0; while(x > 0) ret += t[x], x -= (x & -x); return ret; }
}
int main() {
std::scanf("%d%d%d", &n, &m, &cntob);
for(int i = 1; i <= n; i++) mxr[i] = m; // 第 i 行第一步可以到达最右的地方
for(int i = 1; i <= m; i++) mxc[i] = n; // 第 i 列第一步可以到达最下的地方
for(int i = 1; i <= cntob; i++) {
int x, y;
std::scanf("%d%d", &x, &y);
mxr[x] = std::min(mxr[x], y - 1);
mxc[y] = std::min(mxc[y], x - 1);
}
for(int i = mxr[1] + 1; i <= m; i++) mxc[i] = 0;
for(int i = mxc[1] + 1; i <= n; i++) mxr[i] = 0;
LL ans = 0;
for(int i = 1; i <= m; i++) ans += mxc[i];
int cntqry = mxc[1];
for(int i = 1; i <= cntqry; i++) qry[i] = i;
std::sort(qry + 1, qry + cntqry + 1, [](int x, int y) { return mxr[x] < mxr[y]; });
int now = 1;
for(int i = 1; i <= m; i++) {
BIT::add(mxc[i] + 1);
for(; mxr[qry[now]] <= i && now <= cntqry; now++)
ans += BIT::query(qry[now]);
}
std::printf("%lld\n", ans);
return 0;
} /* self
about TLE (with 14 ACs, 1 WA and 14 TLEs):
BIT's indexes should add 1 each, because of zeros.
(0 can't be the index of BIT)
about WA (with 21 ACs and 8 WAs):
there shouldn't be n (H in the problem) querys
(line 32 shouldn't be n but mxc[1])
*/ | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(int i=(n);i<(k);i++)
#define ALL(a) (a).begin(),(a).end()
const int INIT = 0;//適当に変える max:0 min:2e9 gcd:0 sum:0
struct segmentTree{
private:
int n;
vector<int> node;
public:
segmentTree(vector<int> vec){
int sz = vec.size();
n = 1;
while(n<sz)n *= 2;
node.resize(2 * n - 1,INIT);
For(i,0,sz){
node[i + (n - 1)] = vec[i];
}
for(int i=n-2;i>-1;i--){
node[i] = node[2 * i + 1] + node[2 * i + 2];//演算子は適当に
}
}
void update(int x,int val){
x += (n - 1);
node[x] = val;
while(x){
x = (x - 1) / 2;
node[x] = node[2 * x + 1] + node[2 * x + 2];//演算子は適当に
}
}
//区間[a,b) k:今見ているノード
int get(int a, int b, int k=0, int l=0, int r=-1) {
// 最初に呼び出されたときの対象区間は [0, n)
if(r < 0) r = n;
// 要求区間と対象区間が交わらない
if(r <= a || b <= l) return INIT;
// 要求区間が対象区間を完全に被覆
if(a <= l && r <= b) return node[k];
// 要求区間が対象区間の一部を被覆 -> 子について探索を行う
// 左側の子を vl ・ 右側の子を vr としている
// 新しい対象区間は、現在の対象区間を半分に割ったもの
int vl = get(a, b, 2 * k + 1, l, (l + r) / 2);
int vr = get(a, b, 2 * k + 2, (l + r) / 2, r);
int val = vl + vr;//演算子は適当に
return val;
}
};
ll ans = 0;
void Main(){
using P = pair<int, int>;
int h, w, m;
cin >> h >> w >> m;
vector<int> x(m), y(m);
For(i,0,m) cin >> x[i] >> y[i];
vector<P> wall;
For(i,0,m){
wall.push_back({x[i], y[i]});
}
For(i,1,h+1){
wall.push_back({i, w+1});
}
sort(ALL(wall));
vector<int> vec(w + 2, 0);
segmentTree segTree(vec);
P last = {0, 0};
int xmax = h + 1;
int ymax = wall[0].second;
for(auto p : wall){
if(p.second == 1) xmax = min(xmax, p.first);
}
for(auto p : wall){
// cout << p.first << " " << p.second << " ";
if(last.first != p.first){
// 下右で来る場合の処理
if(p.first < xmax) ans += p.second - 1;
else{
int r = min(ymax, p.second);
ans += r - 1 - segTree.get(0, r);
// cout << segTree.get(0, r) << " ";
}
}
else{
// 右下で来る場合の処理
int r = min(ymax, p.second);
if(last.second < r && p.first > 1)ans += r - last.second - 1 - segTree.get(last.second + 1, r);
}
segTree.update(p.second, 1);
last = p;
// cout << ans << endl;
}
cout << ans << endl;
}
int main(){
Main();
/*
東方風神録は神が出てくるので当然神ゲー
*/
return 0;
} |
#include"bits/stdc++.h"
#define rep(i,n) for(ll i=0;i<n;++i)
#define ALL(x) x.begin(),x.end()
#define BACK(x) x.rbegin(),x.rend()
#define MOD 1000000007
#define INF INT_MAX
#define FLOAT_ANS setprecision(30)
#define TORAD(x) (x*acos(-1)/180.0)
#define TODEG(x) (x*180/acos(-1))
#define elif else if
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template<typename T>
bool chmin(T& a,T b){
if(a>b){
a=b;
return true;
}
return false;
}
template<typename T>
bool chmax(T& a,T b){
if(a<b){
a=b;
return true;
}
return false;
}
ll modpow(ll a, ll n, ll mod) {
ll res = 1;
while (n > 0) {
if (n & 1) res = (res * (a%mod)) % mod;
a = ((a%mod) * (a%mod)) % mod;
n >>= 1;
}
return res;
}
// MAIN PROGRAM -------------
int main(){
ll n,p;
cin>>n>>p;
--p;
ll ans=modpow(p-1,n-1,MOD);
cout<<(ans*p)%MOD;
}
/*
*/ | #include<algorithm>
#include<iostream>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<utility>
#include<bitset>
#include<cstdio>
#include<string>
#include<time.h>
#include<vector>
#include<cmath>
#include<deque>
#include<queue>
#include<map>
#include<set>
using namespace std;
const int M=1e9+7;
int ksm(int a,int b)
{
int c=1;
while(b)
{
if(b&1)
c=1ll*c*a%M;
a=1ll*a*a%M;
b>>=1;
}
return c;
}
int main()
{
int n,p,a=1;
scanf("%d%d",&n,&p);
printf("%lld",1ll*ksm(p-2,n-1)*(p-1)%M);
} |
#include<bits/stdc++.h>
using namespace std;
const int N = 67;
int S[N] , n;
long long x[N][2] , y[N][2] ;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
string t;
cin>>n;
for(int i=1;i<=n;i++){
cin>>t;
if(t=="AND")
S[i] = 0;
else
S[i] = 1;
}
x[0][0] = x[0][1] = y[0][0] = y[0][1] = 1;
for(int i=1;i<=n;i++){
if(S[i] == 1){
y[i][1] = y[i-1][1]*2+y[i-1][0];
y[i][0] = y[i-1][0];
}
else{//AND
y[i][1] = y[i-1][1];
y[i][0] = y[i-1][0]*2+y[i-1][1];
}
}
cout<<y[n][1]<<endl;
return 0;
}
| #include<bits/stdc++.h>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
#define int long long int
#define endl "\n"
#define pb push_back
int sum = 0;
#define arrinp(v) for(auto &i:v) cin>>i,sum+=i;
#define arrout(v) for(auto &i:v) cout<<i<<" ";
#define newline cout<<endl;
#define all(s) (s).begin(),(s).end()
#define dbg(a) cout<<a<<endl;
#define dbg2(a,b) cout<<a<<" "<<b<<endl;
using namespace std;
// using namespace __gnu_pbds;
// typedef tree<int,null_type,less<int>, rb_tree_tag,
// tree_order_statistics_node_update> new_data_set;
// // order_of_key(int) k-th largest element
// // find_by_order(int) gives us according to the order
// // insert() to insert in the PBDS
// // new_data_set ST; calling
int fastModExp(int a, int b) {
int res = 1;
while (b > 0) {
if (b & 1){
res = (res * a);
}
a = (a * a);
b = b >> 1;
}
return res;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int t(1);
// cin >> t;
while (t--) {
sum = 1;
int n;
cin>>n;
vector<int> v;
for(int i=0;i<n;i++){
string s;
cin>>s;
if(s[0]=='O'){
v.pb(i+1);
}
}
for(int i=0;i<v.size();i++){
sum+=fastModExp(2,v[i]);
}
cout<<sum<<endl;
}
return 0;
} |
#include <bits/stdc++.h>
#define pb push_back
#define fst first
#define snd second
#define INF 0x7fffffff
#define INFLL 0x7FFFFFFFFFFFFFFF
#define lenA(ar) sizeof(ar)/sizeof(*ar)
#define fill(a,c) memset(&a, c, sizeof(a))
#define fore(i,x,y) for(int i=x;i<y;i++)
#define foreI(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define sl "\n";
#define ii pair<ll,ll>
#define mk make_pair
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
int main(){
ll n,x;cin>>n>>x;
fore(i,0,n){
ll a;cin>>a;
if(a!=x)cout<<a<<" ";
}
cout<<"\n";
}
| #include <iostream>
#include <vector>
using namespace std;
int main()
{
int N;
long long X;
cin >> N >> X;
vector<long long> v;
for (int i = 0; i < N; i++) {
long long tmp;
cin >> tmp;
if (tmp != X) {
v.push_back(tmp);
}
}
for (long long ans : v) {
cout << ans << " ";
}
cout << endl;
return 0;
}
|
// Problem: A - God Sequence
// Contest: AtCoder - AtCoder Regular Contest 117
// URL: https://atcoder.jp/contests/arc117/tasks/arc117_a
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define vi vector<ll>
#define vll vector<ll>
#define all(x) (x).begin() , (x).end()
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rnd(x, y) uniform_ll_distribution<ll>(x, y)(rng)
void dbg(){
cerr << endl;
}
template<typename Head , typename... Tail>
void dbg(Head h , Tail... t){
cerr << h << " ";
dbg(t...);
}
#ifdef EMBI_DEBUG
#define debug(...) cerr << "(" << #__VA_ARGS__ << "): ", dbg(__VA_ARGS__)
#else
#define debug(...)
#endif
const ll max_n = 1e5 + 9;
const ll mod = 1e9 + 7;
const ll inf = 1e9;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a , ll b)
{
ll prod = 1;
while(b)
{
if(b&1)
prod = (prod*a)%mod;
a = (a*a)%mod;
b >>= 1;
}
return prod;
}
void solve(){
ll a , b;
cin >> a >> b;
if(a >= b) {
//positive > negative
vector<ll> pos , neg;
ll sum = 0;
for(ll i = 1 ; i <= a ; i++) {
pos.pb(i);
neg.pb(-i);
sum += i;
}
while(neg.size() > b) {
ll num = neg.back();
neg.pop_back();
neg.back() += num;
}
for(auto it : pos) {
cout << it << " ";
}
for(auto it : neg) {
cout << it << " ";
}
}
else {
vector<ll> pos , neg;
ll sum = 0;
for(ll i = 1 ; i <= b ; i++) {
pos.pb(i);
neg.pb(-i);
sum += i;
}
while(pos.size() > a) {
ll num = pos.back();
pos.pop_back();
pos.back() += num;
}
for(auto it : pos) {
cout << it << " ";
}
for(auto it : neg) {
cout << it << " ";
}
}
}
signed main(){
ll t = 1;
// cin >> t;
for(ll i = 1 ; i <= t ; i++){
solve();
}
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int x;
int y;
cin >> x >> y;
int k = 0;
for (int i = 0;i < min(x, y) - 1; i++) {
cout << i + 1 << endl;
cout << -1 * (i + 1) << endl;
k = i;
}
if(!(x == y)){
if(x == 1){
cout << -1 << endl;}
if(y == 1){
cout << 1 << endl;}
}
if(x > y){
for (int s = k;s < x - 1; s++) {
cout << s + 2 << endl;
}
cout << -1 * (x + y) * (x - y + 1) / 2 << endl;
}
if(x < y){
for (int s = k;s < y - 1; s++) {
cout << -1 * (s + 2) << endl;
}
cout << (x + y) * (y - x + 1) / 2 << endl;
}
if(x == y){
cout << (k + 1) + 1 << endl;
cout << -1 * (k + 1) - 1 << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;
int main(){
cin.tie(0); ios::sync_with_stdio(false);
ll h, w; cin >> h >> w;
string a[h]; zep(i, 0, h)cin >> a[i];
if(h == 1 && w == 1){
print("Draw") return 0;
}
ll dp[h][w];
dp[h - 1][w - 1] = 0;
if((h + w) % 2 == 0){
if(a[h - 1][w - 1] == '+'){
dp[h - 1][w - 1]--;
}else{
dp[h - 1][w - 1]++;
}
}else{
if(a[h - 1][w - 1] == '+'){
dp[h - 1][w - 1]++;
}else{
dp[h - 1][w - 1]--;
}
}
rrep(i, h - 1, 0){
rrep(j, w - 1, 0){
if(i != h - 1 || j != w - 1){
if(i == h - 1 && j != w - 1){
dp[i][j] = dp[i][j + 1];
}else if(i != h - 1 && j == w - 1){
dp[i][j] = dp[i + 1][j];
}else if(i != h - 1 && j != w - 1){
if((i + j) % 2 == 0){
if(dp[i + 1][j] > dp[i][j + 1]){
dp[i][j] = dp[i + 1][j];
}else{
dp[i][j] = dp[i][j + 1];
}
}else{
if(dp[i + 1][j] < dp[i][j + 1]){
dp[i][j] = dp[i + 1][j];
}else{
dp[i][j] = dp[i][j + 1];
}
}
}
if(i != 0 || j != 0){
if((i + j) % 2 == 0){
if(a[i][j] == '+'){
dp[i][j]--;
}else{
dp[i][j]++;
}
}else{
if(a[i][j] == '+'){
dp[i][j]++;
}else{
dp[i][j]--;
}
}
}
}
}
}
if(dp[0][0] > 0){
print("Takahashi")
}else if(dp[0][0] < 0){
print("Aoki")
}else{
print("Draw")
}
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define ulli unsigned long long int
#define vi vector<int>
#define ii pair<int,int>
#define all(v) v.begin(),v.end()
#define getunique(v) {v.erase(unique(v.begin(),v.end()),v.end());}
#define pb push_back
#define ff first
#define ss second
#define endl "\n"
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
const int MS=1000001;
const lli INF=1e9+7;
template<typename T>
bool comp(T a, T b){
if(a<b)
return true;
return false;
}
int n,m;
int get(int i, int j, vector<string> &v){
if(i>=n || j>=m)
return 0;
if(v[i][j]=='-')
return -1;
return 1;
}
int dp[3000][3000][3];
int solve(int i, int j, vector<string> &v, int inx){
if(i>=n-1 && j>=m-1)
return 0;
// if(i>=n || j>=m)
// return 0;
int add=0,a=0,b=0;
// cout<<mine<<" "<<i+1<<" "<<j+1<<" "<<inx<<endl;
if(dp[i][j][inx]!=-1)
return dp[i][j][inx];
if((inx==0)){
a=get(i+1,j,v);
b=get(i,j+1,v);
if(i==n-1)
return dp[i][j][inx]=b+solve(i,j+1,v,inx^1);
else if(j==m-1)
return dp[i][j][inx]=a+solve(i+1,j,v,inx^1);
return dp[i][j][inx]=max(a+solve(i+1,j,v,inx^1),b+solve(i,j+1,v,inx^1));
}
else{
a=get(i+1,j,v);
b=get(i,j+1,v);
if(i==n-1)
return dp[i][j][inx]=-b+solve(i,j+1,v,inx^1);
else if(j==m-1)
return dp[i][j][inx]=-a+solve(i+1,j,v,inx^1);
return dp[i][j][inx]=min(-a+solve(i+1,j,v,inx^1),-b+solve(i,j+1,v,inx^1));
}
// return add;
}
int main(){
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
fast_io;
cin>>n>>m;
vector<string> v(n);
for(int i=0; i<n; i++)
cin>>v[i];
memset(dp,-1,sizeof dp);
int ans=solve(0,0,v,0);
// cout<<ans<<endl;
if(ans>0)
cout<<"Takahashi";
else if(ans<0)
cout<<"Aoki";
else cout<<"Draw";
} |
#include<iostream>
using namespace std;
int main()
{
long long n,ans;
cin>>n;
int c[3]={0};
while(n!=0)
{
c[n%10%3]++;
n/=10;
}
int a=(c[1]+c[2]*2)%3;
int k=c[0]+c[1]+c[2];
if(a==0)
{
ans=0;
}
else if(a==1)
{
if(c[1])
{
if(k==1)
{
ans=-1;
}
else
{
ans=1;
}
}
else
{
if(k==2)
{
ans=-1;
}
else
{
ans=2;
}
}
}
else
{
if(c[2])
{
if(k==1)
{
ans=-1;
}
else
{
ans=1;
}
}
else
{
if(k==2)
{
ans=-1;
}
else
{
ans=2;
}
}
}
cout<<ans<<endl;
return 0;
}
| #include <bits/stdc++.h>
#include <iostream>
#include <string>
using namespace std;
#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「sからnまで」の降順の繰り返し
typedef long long ll;
const ll inf = 1e18+7;
const ll mod = 1e9+7;
int main(){
string n;
cin>>n;
int ans=100;
rep(bit,1<<n.size()){
string s;
int cnt=0,sum=0;
rep(i,n.size()){
if(bit&(1<<i)){
sum+=n[i]-'0';
cnt++;
}
}
if(cnt!=0){
if(sum%3==0){
int sub=n.size()-cnt;
ans=min(ans,sub);
}
}
}
if(ans==100)ans=-1;
cout<<ans<<endl;
}
|
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;
#define LL long long
int main()
{
LL H;
cin >> H;
LL W;
cin >> W;
map<string, bool> S;
for (long long i = 0; i < H; ++i)
{
for (long long j = 0; j < W; ++j)
{
char s;
cin >> s;
string label;
label += to_string(j);
label += ",";
label += to_string(i);
S[label] = (s == '#');
}
}
LL result = 0;
for (long long i = 1; i < H-1; ++i)
{
for (long long j = 1; j < W-1; ++j)
{
string label;
label += to_string(j);
label += ",";
label += to_string(i);
string above;
above += to_string(j);
above += ",";
above += to_string(i - 1);
string left;
left += to_string(j - 1);
left += ",";
left += to_string(i);
string right;
right += to_string(j + 1);
right += ",";
right += to_string(i);
string down;
down += to_string(j);
down += ",";
down += to_string(i + 1);
if (S[label])
{
if(!S[above] && !S[left])
{
result++;
}
if (!S[above] && !S[right])
{
result++;
}
if (!S[down] && !S[left])
{
result++;
}
if (!S[down] && !S[right])
{
result++;
}
}
else
{
if (S[above] && S[left])
{
result++;
}
if (S[above] && S[right])
{
result++;
}
if (S[down] && S[left])
{
result++;
}
if (S[down] && S[right])
{
result++;
}
}
}
}
cout << result << endl;
}
| #include<bits/stdc++.h>
using namespace std;
int main() {
int N, K;
cin >> N >> K;
vector<vector<int>> data(N, vector<int>(N));
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
cin >> data.at(i).at(j);
}
}
int ans = 0;
vector<int> cities(N);
for (int i = 0; i < N; i++) {
cities.at(i) = i;
}
do {
if (cities.at(0) != 0) continue;
int sum = 0;
for (int i = 0; i < N; i++) {
//cout << cities.at(i);
// 往路
if (i == N - 1) {
sum += data.at(cities.at(i)).at(0);
} else {
sum += data.at(cities.at(i)).at(cities.at(i + 1));
}
}
//cout << endl;
if (sum == K) ans++;
} while (next_permutation(cities.begin(), cities.end()));
cout << ans << endl;
} |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
map<string, int> m;
int highest = 0;
for (int i = 0; i < n; ++i) {
string s;
int a;
cin >> s >> a;
m[s] = a;
}
for (auto x : m) highest = max(highest, x.second);
int second_highest = 0;
for (auto x : m) if (x.second != highest) second_highest = max(second_highest, x.second);
string ans = "";
for (auto x : m) if (x.second == second_highest) ans = x.first;
cout << ans << endl;
return 0;
} | #include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define MP make_pair
#define EACH(i,c) for(auto i: c)
#define SORT(c) sort((c).begin(),(c).end())
#define ALL(a) (a).begin(),(a).end()
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
LL N;
cin >> N;
vector<LL> ret;
FOR(i, 1, max(2LL, (LL)sqrt(N)) + 1)
{
if((N % i) == 0){
ret.push_back(i);
ret.push_back(N / i);
}
}
SORT(ret);
ret.erase(unique(ALL(ret)), ret.end());
EACH(r, ret){
cout << r << endl;
}
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;
}
ll N = 50;
vll a = {-1, 1, 0, 0};
vll b = {0, 0, -1, 1};
vector<char> d = {'U', 'D', 'L', 'R'};
ll si, sj;
vvll tiles(N, vll(N)), points(N, vll(N));
ll tile_count = 0;
ll S = 0;
string ans = "";
vll ans_done;
ll ans_i, ans_j;
void RUN(ll si, ll sj, string st, vll don, ll sc) {
ll i = si, j = sj;
vll done = don;
ll score = sc;
done[tiles[i][j]] = 1;
string s = st;
while (1) {
vll ikeru;
rep(k, 4) {
ll ni = i + a[k];
ll nj = j + b[k];
if (ni < 0 or N <= ni or nj < 0 or N <= nj) continue;
if (done[tiles[ni][nj]] == 1) continue;
ikeru.pb(k);
}
if (ikeru.empty()) break;
ll r = rand() % ikeru.size();
ll index = ikeru[r];
s.pb(d[index]);
i += a[index];
j += b[index];
done[tiles[i][j]] = 1;
score += points[i][j];
}
if (S < score) {
S = score;
ans = s;
ans_done = done;
ans_i = i;
ans_j = j;
}
}
void NOB() {
ll t_i = ans_i;
ll t_j = ans_j;
string t_s = ans;
vll t_done = ans_done;
ll t_S = S;
ll modoru = rand() % t_s.size() + 1 + 20;
chmin(modoru, (ll)t_s.size());
rep(r, modoru) {
char c = t_s[t_s.size() - 1];
t_s.erase(t_s.end() - 1);
t_done[tiles[t_i][t_j]] = 0;
t_S -= points[t_i][t_j];
if (c == 'U') t_i += 1;
if (c == 'D') t_i -= 1;
if (c == 'L') t_j += 1;
if (c == 'R') t_j -= 1;
}
RUN(t_i, t_j, t_s, t_done, t_S);
}
signed main() {
init();
cin >> si >> sj >> tiles >> points;
rep(i, N) chmax(tile_count, MAX(tiles[i]));
ans_done.resize(tile_count + 1);
srand(time(NULL));
rep(n, 1000) RUN(si, sj, "", vll(tile_count + 1), points[si][sj]);
rep(n, 390000) NOB();
debug(S);
ANS;
return 0;
} | #include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cstdio>
#include <cmath>
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
struct Tile {
int tileNum;
int point;
};
int si, sj;
Tile tile[52][52];
string ans;
string finalans;
bool used[2500];
int di[4] = { -1,0,0,1 };
int dj[4] = { 0,1,-1,0 };
vector<pair<int,int>> moveij;
void move(int ni, int nj, int nowij) {
if (ni == 51 || nj == 51 || ans.empty()&&(ni!=si&&nj!=sj))
return;
moveij.push_back(pair<int, int>(ni, nj));
tile[50][50].point = -1;
used[tile[ni][nj].tileNum] = true;
/*
if ((tile[ni - 1][nj].used || tile[ni][nj].tileNum == tile[ni - 1][nj].tileNum) ||
(tile[ni + 1][nj].used || tile[ni][nj].tileNum == tile[ni + 1][nj].tileNum) ||
(tile[ni][nj - 1].used || tile[ni][nj].tileNum == tile[ni][nj - 1].tileNum) ||
(tile[ni][nj + 1].used || tile[ni][nj].tileNum == tile[ni][nj + 1].tileNum)) {//どこにもいけない
return;
}
*/
int nexti = 51, nextj = 51;
for (int i = 0; i < 4; i++) {
if (0 <= ni + di[i] && ni + di[i] < 50 && 0 <= nj + dj[i] && nj + dj[i] < 50){
if (!used[tile[ni + di[i]][nj + dj[i]].tileNum]) {
if (tile[ni + di[i]][nj + dj[i]].point > tile[nexti][nextj].point) {
nexti = ni + di[i]; nextj = nj + dj[i];
}
}
}
}
if (nexti == 51 && nextj == 51) {
//string change;
finalans = (finalans.size() > ans.size()) ? finalans : ans;
//finalans.erase(0);
//finalans = change;
ans.erase((int)ans.size() - 1);
if (moveij.size() <= 1)return;
moveij.erase(moveij.end()-1);
--nowij;
if (nowij <= 0)
return;
int nni = moveij[nowij].first;
int nnj = moveij[nowij].second;
moveij.erase(moveij.end() - 1);
move(nni, nnj, nowij);
}
else {
if (nexti == ni - 1) ans.push_back('U');
else if (nexti == ni + 1)ans.push_back('D');
else if (nextj == nj - 1)ans.push_back('L');
else if (nextj == nj + 1)ans.push_back('R');
move(nexti, nextj, ++nowij);
}
}
int main() {
cin >> si >> sj;
rep(i, 50) rep(j, 50) cin >> tile[i][j].tileNum;
rep(i, 50) rep(j, 50) cin >> tile[i][j].point;
move(si, sj, 0);
cout << finalans << endl;
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
ll i,n,x;
cin>>n>>x;
ll a[n];
for(i=1;i<=n;i++){
cin>>a[i];
}
ll cnt=0;
for(i=1;i<=n;i++){
if(a[i]!=x){
cout<<a[i]<<" ";
cnt++;
}
}
if(cnt==0) cout<<" "<<endl;
return 0;
} |
#include <bits/stdc++.h>
#define f first
#define s second
#define sym(s) s = "#" + s + "#";
#define all(x) (x).begin(), (x).end()
#define alll(x,n) x+1, x+n+1
#define newl cout<<"\n";
#define foo(i,a,n) for(ll i = (a); i <= n; i++)
#define deb1(a) cout<<a<<"\n";
#define deb2(a,b) cout<<a<<" "<<b<<"\n";
#define deb3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n";
#define deb4(a,b,c,d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n";
#define debp(a) cout<<a.f<<" "<<a.s<<"\n";
#define debv(a) for(auto it: a)cout<<it<<" ";newl;
#define debm(a) for(auto it: a)cout<<"{"<<it.f<<","<<it.s<<"}, ";newl;
#define deb1d(a,n) foo(i,1,n)cout<<a[i]<<" ";newl;
#define deb2d(a,n,m) foo(i,1,n){foo(j,1,m){cout<<a[i][j]<<" ";}newl;}
using namespace std;
using ll = long long;
using ld = long double;
const ll MOD = 1e+9 + 7;
const ll INF = LLONG_MAX;
const int N = (int)2e+5 + 8;
ll n, a[N], x;
void MAIN(int tc) {
cin >> n >> x;
for(int i = 1; i <= n; i++){
int y;
cin >> y;
if(y != x)cout << y << " ";
}
}
int main() {
ios:: sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
cout << fixed; cout << setprecision(10);
int test_cases = 1;
//cin>>test_cases;
for (int i = 1; i <= test_cases; i++) {
MAIN(i);
}
} |
#include <bits/stdc++.h>
#define fi first
#define se second
#define DB double
#define U unsigned
#define P std::pair
#define LL long long
#define LD long double
#define pb emplace_back
#define MP std::make_pair
#define SZ(x) ((int)x.size())
#define all(x) x.begin(),x.end()
#define CLR(i,a) memset(i,a,sizeof(i))
#define FOR(i,a,b) for(int i = a;i <= b;++i)
#define ROF(i,a,b) for(int i = a;i >= b;--i)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl
const int MAXN = 2e5 + 5;
int n,m,mid,ans;
std::vector<int> G[MAXN];
int f[MAXN],g[MAXN];
inline void dfs(int v,int fa=0){
f[v] = 1e9;g[v] = -1e9;
for(auto x:G[v]){
if(x == fa) continue;
dfs(x,v);
f[v] = std::min(f[v],f[x]+1);
g[v] = std::max(g[v],g[x]+1);
}
if(f[v] > mid) g[v] = std::max(g[v],0);
if(f[v]+g[v] <= mid) g[v] = -1e9;
if(g[v] == mid) ++ans,g[v] = -1e9,f[v] = 0;
}
inline bool chk(int x){
mid = x;ans = 0;dfs(1);
if(g[1] != -1e9) ++ans;
return ans <= m;
}
int main(){
scanf("%d%d",&n,&m);
FOR(i,2,n){
int u,v;scanf("%d%d",&u,&v);
G[u].pb(v);G[v].pb(u);
}
int l = 0,r = n,ans = -1;
while(l <= r){
int mid = (l + r) >> 1;
if(chk(mid)) ans = mid,r = mid-1;
else l = mid+1;
}
printf("%d\n",ans);
return 0;
}
| #include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
using ll = long long;
using ld = long double;
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
#define mp make_pair
const int MOD = 998244353;
int mul(int a, int b) {
return (1LL * a * b) % MOD;
}
int add(int a, int b) {
int s = (a+b);
if (s>=MOD) s-=MOD;
return s;
}
int sub(int a, int b) {
int s = (a+MOD-b);
if (s>=MOD) s-=MOD;
return s;
}
int po(int a, ll deg)
{
if (deg==0) return 1;
if (deg%2==1) return mul(a, po(a, deg-1));
int t = po(a, deg/2);
return mul(t, t);
}
int inv(int n)
{
return po(n, MOD-2);
}
mt19937 rnd(time(0));
/*
const int LIM = 3e5 + 5;
vector<int> facs(LIM), invfacs(LIM);
void init()
{
facs[0] = 1;
for (int i = 1; i<LIM; i++) facs[i] = mul(facs[i-1], i);
invfacs[LIM-1] = inv(facs[LIM-1]);
for (int i = LIM-2; i>=0; i--) invfacs[i] = mul(invfacs[i+1], i+1);
}
int C(int n, int k)
{
if (n<k) return 0;
if (n<0 || k<0) return 0;
return mul(facs[n], mul(invfacs[k], invfacs[n-k]));
}*/
/*struct DSU
{
vector<int> sz;
vector<int> parent;
void make_set(int v) {
parent[v] = v;
sz[v] = 1;
}
int find_set(int v) {
if (v == parent[v])
return v;
return find_set(parent[v]);
}
void union_sets(int a, int b) {
find_set(a);
find_set(b);
a = find_set(a);
b = find_set(b);
if (a != b) {
if (sz[a] < sz[b])
swap(a, b);
parent[b] = a;
sz[a] += sz[b];
};
}
DSU (int n)
{
parent.resize(n);
sz.resize(n);
for (int i = 0; i<n; i++) make_set(i);
}
};*/
vector<vector<int>> G;
int n, k;
vector<int> parent;
vector<int> depth;
vector<vector<int>> children;
void dfs(int v, int par = -1)
{
for (auto it: G[v]) if (it!=par)
{
children[v].push_back(it);
depth[it] = depth[v] + 1;
parent[it] = v;
dfs(it, v);
}
}
set<pair<int, int>> worst;
vector<bool> deleted;
vector<int> deleting;
void del(int v, int dist)
{
if (!deleted[v])
{
worst.erase(mp(depth[v], v)); deleted[v] = true;
}
if (dist<=deleting[v]) return;
deleting[v] = dist;
if (dist==0) return;
for (auto it: G[v]) del(it, dist-1);
}
bool check(int d)
{
worst.clear();
for (int i = 0; i<n; i++) worst.insert(mp(depth[i], i));
deleted.clear(); deleted.resize(n);
deleting.clear(); deleting.resize(n);
int cnt = 0;
while (!worst.empty())
{
cnt++;
//cout<<"Iter "<<cnt<<": "<<endl;
//for (auto it: worst) cout<<it.first<<' '<<it.second<<endl;
auto it = *prev(worst.end());
if (it.first<=d)
{
return (cnt<=k);
}
int deleting = it.second;
for (int i = 0; i<d; i++) deleting = parent[deleting];
//cout<<"Deleting: "<<deleting<<endl;
del(deleting, d);
}
if (worst.empty()) return (cnt<=k);
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(nullptr);
cin>>n>>k;
G.resize(n);
for (int i = 0; i<n-1; i++)
{
int u, v; cin>>u>>v; u--; v--;
G[u].push_back(v); G[v].push_back(u);
}
parent.resize(n); depth.resize(n); children.resize(n);
parent[0] = -1;
dfs(0);
int L = 0; int R = n;
while (R-L>1)
{
int mid = (L+R)/2;
if (check(mid)) R = mid; else L = mid;
}
cout<<R<<endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#include <ext/rope>
using namespace __gnu_cxx;
typedef tree<long long, null_type, less<long long>,
rb_tree_tag, tree_order_statistics_node_update> pbds;
//less_equal for identical elements
#define DEBUG
#ifdef DEBUG
#define debug(...) printf(__VA_ARGS__);
#else
#define debug(...)
#endif
#define fi first
#define se second
#define pb emplace_back
#define sz(x) (int)x.size()
#define mnto(x,y) x=min(x,(__typeof__(x))y)
#define mxto(x,y) x=max(x,(__typeof__(x))y)
#define INF 1023456789
#define LINF 1023456789123456789
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vll;
int primes[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71};
ll a,b,n,arr[80],memo[80][1500000];
ll dp(int x,int msk){
if(x==n)return 1;
if(memo[x][msk]!=-1)return memo[x][msk];
int nmsk=msk;
for(int i=0;i<20;++i){
if(arr[x]%primes[i]==0){
if(msk&(1<<i))return memo[x][msk]=dp(x+1,msk);
nmsk|=(1<<i);
}
}
return memo[x][msk]=dp(x+1,nmsk)+dp(x+1,msk);
}
int main(){
scanf("%lld%lld",&a,&b);
n=b-a+1;
for(int i=0;i<n;++i){
arr[i]=i+a;
}
memset(memo,-1,sizeof memo);
printf("%lld\n",dp(0,0));
}
| #include <bits/stdc++.h>
using namespace std;
const int N=73;
typedef long long ll;
int n=21;
ll a,b,ans,f[1<<21];
int p[]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73};
int main()
{
f[0]=1;
scanf("%lld%lld",&a,&b);
for(ll i=a;i<=b;++i)
{
int u=0;
for(int j=0;j<n;++j)
if(i%p[j]==0)u|=1<<j;
for(int j=0;j<1<<n;++j)
if(!(u&j))f[u|j]+=f[j];
}
for(int i=0;i<1<<n;++i)ans+=f[i];
printf("%lld\n",ans);
}
|
#include <bits/stdc++.h>
using namespace std;
string s;
int f[10];
int main() {
ios::sync_with_stdio(0);
cin >> s;
memset(f, 0, sizeof(f));
for(int i = 0; i < s.size(); i++)
f[s[i] - '0']++;
if(s.size() == 2) {
int d1 = (s[0] - '0') * 10 + (s[1] - '0');
int d2 = (s[1] - '0') * 10 + (s[0] - '0');
if(d1 % 8 == 0 || d2 % 8 == 0)
cout << "Yes" << endl;
else cout << "No" << endl;
return 0;
}
if(s.size() == 1) {
if(s == "8")
cout << "Yes" << endl;
else cout << "No" << endl;
return 0;
}
for(int i = 112; i < 1000; i += 8) {
int d1 = i / 100;
int d2 = i / 10 % 10;
int d3 = i % 10;
int t[10];
for(int i = 0; i <= 9; i++)
t[i] = f[i];
if(t[d1] > 0) t[d1]--;
else continue;
if(t[d2] > 0) t[d2]--;
else continue;
if(t[d3] <= 0) continue;
cout << "Yes" << endl;
return 0;
}
cout << "No" << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
// Compile with "(g++) -std=c++11 -Wall -Wextra -Wconversion -Wshadow -Dcychien"
#ifdef cychien
#define debug(...) do {\
fprintf(stderr, "%s - %d : (%s) = ", __PRETTY_FUNCTION__, __LINE__, #__VA_ARGS__);\
_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x) {cerr << x << '\n';}
template<typename I, typename ...T> void _DO(I&&x,T&&...tail) {cerr << x << ", "; _DO(tail...);}
#define IOS
#else
#define debug(...)
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
#endif
#define FOR(i, n) for(int i = 0; i < n; i++)
#define FOR1(i, n) for(int i = 1; i <= n; i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define SZ(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort(ALL(x))
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
const int NF = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll MOD = 1e9 + 7;
const ld PI = 3.14159265358979323846264338327950288;
ll mypow(ll a, ll x){
if (x == 0) return 1;
if (x == 1) return a;
ll res = mypow(a, x >> 1);
res *= res;
if (x & 1) res *= a;
return res;
}
set<ll> s;
int main() {
IOS;
ll n;
cin >> n;
for (ll a = 2; a <= 100000; a++){
for (ll b = 2; b <= 40; b++){
ld bb = ld(b), aa = ld(a);
if (bb * log(aa) <= log((ld)1e18)){
ll cc = mypow(a, b);
if (cc <= n){
s.insert(cc);
}
}
}
}
cout << n - SZ(s) << '\n';
return 0;
} |
#include<iostream>
using namespace std;
int main() {
int year;
cin >> year;
int century;
century = year/100;
if(year % 100 == 0) {
cout << century;
}
else{
cout << century + 1;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
//--------------------------------------------------------------------------------------//
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define int long long int
//--------------------------------------------------------------------------------------//
signed main()
{
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//#ifndef ONLINE_JUDGE
//freopen("input.txt", "r" , stdin);
//freopen("output.txt", "w" , stdout);
//#endif
int n;
cin>>n;
cout<<ceil((float)n/100);
cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
} |
/**
* @brief atcoder
* @author yao
*/
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <utility>
#include <algorithm>
#include <functional>
#include <climits>
#include <vector>
#include <map>
#define ft first
#define sd second
#ifdef DBG
# define dbg_pri(x...) fprintf(stderr,x)
#else
# define dbg_pri(x...) 0
# define NDEBUG
#endif //DBG
#include <cassert>
typedef unsigned int uint;
typedef long long int lli;
typedef unsigned long long int ulli;
#define N 262144
static_assert(__builtin_popcount(N) == 1);
template <class T>
class Bit{
public:
T a[N];
void add(int x,T k)
{
while( x < N ) a[x] += k, x += x+1&~x;
}
T qry(int x)
{
T res = 0;
while( x >= 0 ) res += a[x], x -= x+1&~x;
return res;
}
int lbd(T k)
{
if( a[N-1] < k ) return N;
int res = -1, x = N>>1;
while(x)
{
if(a[res+x]<k) k-=a[res+=x];
x>>=1;
}
return res+1;
}
int ubd(T k)
{
if( a[N-1] <= k ) return N;
int res = -1, x = N>>1;
while(x)
{
if(a[res+x]<=k) k-=a[res+=x];
x>>=1;
}
return res+1;
}
};
Bit<int> bit;
int a[N], b[N];
std::map<int, std::vector<int>> mp;
int main()
{
int n;
scanf("%d", &n);
for(int i=0;i<n;++i) scanf("%d", &a[i]);
for(int i=0;i<n;++i) scanf("%d", &b[i]);
for(int i=n-1;i>=0;--i) mp[b[i]+i].push_back(i);
lli ans = 0;
for(int i=0;i<n;++i)
{
std::vector<int> &v = mp[a[i]+i];
if(v.empty()) return puts("-1"), 0;
int k = v.back();
v.pop_back();
ans += i-bit.qry(k);
bit.add(k,1);
}
printf("%lld\n", ans);
return 0;
}
| #include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<numeric>
//#include<atcoder/all>
using namespace std;
//using namespace atcoder;
#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
//#define MOD 1000000007
#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
#define PI acos(-1.0)
const double EPS = 1e-10;
using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;
//using mint = modint998244353;
int dh[] = {-1,0,1,0};
int dw[] = {0,1,0,-1};
template<typename T>
struct BinaryIndexedTree{
vector<T> bit;
BinaryIndexedTree(int sz){
bit.resize(sz+1);
}
void add(int k, T x){ //k番目にxを加える
for(int i = k; i < (int)bit.size(); i |= i+1) bit[i] += x;
}
T sum(int k){ //[0,k)の区間の総和を求める
T res = 0;
for(int i = k-1; i >= 0; i = (i&(i+1))-1){
res += bit[i];
}
return res;
}
};
int main(){
int n; cin >> n;
vector<Pi> a(n);
vector<Pi> b(n);
rep(i,n) cin >> a[i].first,a[i].second = i;
rep(i,n) cin >> b[i].first,b[i].second = i;
rep(i,n) a[i].first += i;
rep(i,n) b[i].first += i;
vector<Pi> c,d;
c = a,d = b;
sort(c.begin(),c.end());
sort(d.begin(),d.end());
rep(i,n){
if(c[i].first != d[i].first){
cout << -1 << endl;
return 0;
}
}
vector<int> id(n);
rep(i,n) id[c[i].second] = d[i].second;
ll ans = 0;
BinaryIndexedTree<int> bit(n);
rep(i,n){
ans += bit.sum(n)-bit.sum(id[a[i].second]);
bit.add(id[a[i].second],1);
}
cout << ans << endl;
}
|
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <numeric>
/* debug macros */
#ifdef WAFDAYO
#define DBG_LINE() {std::cerr<<"\e[2m[L"<<__LINE__<<"]\e[m ";}
#define DBG_PRINT(s,t,u) {std::cerr<<(s)<<" \e[2m=\e[m \e[1m"<<(t)<<"\e[m"<<(u);}
#define SELECT_7TH(x1,x2,x3,x4,x5,x6,x7,...) x7
#define dbg1(x1) DBG_PRINT(#x1,x1,std::endl)
#define dbg2(x1,x2) DBG_PRINT(#x1,x1,", ")dbg1(x2)
#define dbg3(x1,x2,x3) DBG_PRINT(#x1,x1,", ")dbg2(x2,x3)
#define dbg4(x1,x2,x3,x4) DBG_PRINT(#x1,x1,", ")dbg3(x2,x3,x4)
#define dbg5(x1,x2,x3,x4,x5) DBG_PRINT(#x1,x1,", ")dbg4(x2,x3,x4,x5)
#define dbg6(x1,x2,x3,x4,x5,x6) DBG_PRINT(#x1,x1,", ")dbg5(x2,x3,x4,x5,x6)
#define dbg(...) DBG_LINE()\
SELECT_7TH(__VA_ARGS__,dbg6,dbg5,dbg4,dbg3,dbg2,dbg1)(__VA_ARGS__)
#else
#define dbg(...) {}
#endif
/* utility functions */
struct read_item{read_item(){};
template<class T>operator T(){T t;std::cin>>t;return t;}};
char splf(int i,int n){return(i+1<n)?' ':'\n';};
template<bool up>
struct _RI{int i;_RI(int a):i(a){}
int operator*(){return i;}void operator++(){i+=(up?1:-1);}
bool operator!=(const _RI& r){return up?i<r.i:i>r.i;}};
template<bool up>
struct _RX{_RI<up> x,y;_RI<up> begin(){return x;}_RI<up> end(){return y;}
_RX(int a,int b):x(up?a:(b-1)),y(up?b:(a-1)){}_RX(int a):_RX(0,a){}};
typedef _RX<true> range;
typedef _RX<false> revrange;
/* types and constants */
typedef int64_t i64;
typedef uint64_t u64;
// const i64 inf = (i64)1.05e18;
// const int inf = (int)1.05e9;
using namespace std;
int main() {
const int A = read_item();
const int B = read_item();
int total = A + B;
int ans = 4;
if(total >= 15 && B >= 8) {
ans = 1;
} else if(total >= 10 && B >= 3) {
ans = 2;
} else if(total >= 3) {
ans = 3;
}
printf("%d\n", ans);
return 0;
}
/* wafdayo~~~ */
| #include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
typedef long long ll;
typedef unsigned long long ull;
typedef short int si;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int nMax = 1e6+5;
const ll mod = 1e9+7;
int h,w,mini,sum;
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int x;
cin >> h >>w;
mini = INT_MAX;
for (int i=0;i<h;i++) {
for (int j=0;j<w;j++) {
cin >> x;
sum += x;
mini = min(mini,x);
}
}
cout << sum - mini * h * w << "\n";
return 0;
} |
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
ll a,b,c,d,count=1,x,y=0;
cin>>a>>b>>c>>d;
if(c*d<=b)cout<<-1<<endl;
else
{
if((a+b)<=(c*d))cout<<1<<endl;
else
{
count=1;
x=a;
while(1)
{
if(x<=(y*d)) {cout<<count-1<<endl;break;}
x+=b;
y+=c;
count++;
}
}
}
return 0;
}
| #include<cstdio>
#include<algorithm>
using namespace std;
long long a,b,c,d,x,ans;
int main(){
scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
x=c*d-b;
if(x<=0)ans=-1;
else{
ans=a/x;
if(a%x)++ans;
}
printf("%lld",ans);
return 0;
} |
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
int main() {
ll S, P; cin >> S >> P;
// N = S - M
// (S - M) * M = P
// SM - M^2 = P
// M^2 - SM + P = 0
ll ans = 0;
for(ll M=1; M<=8000000; M++) {
ll N = S - M;
if(N <= 0) break;
if(N*M == P) ans++;
}
cout << (ans > 0 ? "Yes" : "No") << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#include "_DEBUG.hpp"
#endif
#define int long long
const long long inf = 2e18;
const int mod = 1e9 + 7;
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
for (T &in : v) is >> in;
return is;
}
template <class T>
vector<T> make_vec(size_t a) {
return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T, class V>
typename enable_if<is_class<T>::value == 0>::type fill(T &t, const V &v) {
t = v;
}
template <class T, class V>
typename enable_if<is_class<T>::value != 0>::type fill(T &t, const V &v) {
for (auto &e : t) fill(e, v);
}
// nCr mod p (p < 10) O(100 + log(n))
int Lucas(int n, int r, int p) {
assert(n >= r);
vector<vector<int>> dp(p, vector<int>(p)); // dp[n][r] = nCr
for (int i = 0; i < p; i++) {
dp[i][0] = 1;
for (int j = 1; j <= i; j++) {
dp[i][j] = (dp[i - 1][j - 1] + dp[i - 1][j]) % p;
}
}
int res = 1;
while (n > 0) {
res = (res * dp[n % p][r % p]) % p;
n /= p;
r /= p;
}
return res;
}
signed main() {
int n;
cin >> n;
string s;
cin >> s;
int ans = 0;
for (int i = 0; i < n; i++) {
int color = (s[i] == 'B' ? 0 : s[i] == 'W' ? 1 : 2);
ans = (ans + Lucas(n - 1, i, 3) * color) % 3;
}
if (n % 2 == 0) ans = (3 - ans) % 3;
cout << (ans == 0 ? 'B' : ans == 1 ? 'W' : 'R') << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repp(i, st, en) for (ll i = (ll)st; i < (ll)(en); i++)
#define repm(i, st, en) for (ll i = (ll)st; i >= (ll)(en); i--)
#define all(v) v.begin(), v.end()
void chmax(ll &x, ll y) {x = max(x,y);}
void chmin(ll &x, ll y) {x = min(x,y);}
void Yes() {cout << "Yes" << endl; exit(0);}
void No() {cout << "No" << endl; exit(0);}
template<class in_Cout> void Cout(in_Cout x) {cout << x << endl; exit(0);}
template<class in_vec_cout>
void vec_cout(vector<in_vec_cout> vec) {
for (in_vec_cout res : vec) {cout << res << " ";}
cout << endl;
}
const ll inf = 1e18;
const ll mod = 1e9 + 7;
int main() {
ll N; cin >> N;
vector<ll> a(N), t(N);
rep(i,N) cin >> a[i] >> t[i];
ll l = -inf, r = inf, add = 0;
ll L = -inf, R = inf;
bool is_straight = false;
rep(i,N) {
if (t[i]==1) {
if (is_straight) {
L += a[i];
R += a[i];
continue;
}
add += a[i];
if (l!=-inf) L += a[i];
if (r!=inf) R += a[i];
} else if (t[i]==2) {
if (is_straight) {
chmax(L,a[i]);
chmax(R,a[i]);
continue;
}
if (a[i]<=L) continue;
if (R<=a[i]) {
L = a[i];
R = a[i];
is_straight = true;
continue;
}
L = a[i];
l = L - add;
} else {
if (is_straight) {
chmin(L,a[i]);
chmin(R,a[i]);
continue;
}
if (R<=a[i]) continue;
if (a[i]<=L) {
L = a[i];
R = a[i];
is_straight = true;
continue;
}
R = a[i];
r = R - add;
}
}
ll Q; cin >> Q;
vector<ll> res(Q);
rep(q,Q) {
ll x; cin >> x;
if (is_straight) {
res[q] = L;
} else {
if (x<=l) res[q] = L;
else if (x<r) res[q] = x + add;
else res[q] = R;
}
}
for (ll ans : res) cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
template<typename T>
void debug(vector<T> item) {
for (auto i : item) {
cout << i << " ";
}
cout << endl;
}
int main() {
int N;
cin >> N;
int64_t mn = -(int64_t)1e9;
int64_t mx = 1e9;
int64_t sum = 0;
for (int i = 0; i < N; ++i) {
int64_t a, b;
cin >> a >> b;
if (b == 1) {
sum += a;
mn += a;
mx += a;
} else if (b == 2) {
mn = max(a, mn);
mx = max(a, mx);
} else {
mn = min(a, mn);
mx = min(a, mx);
}
}
int Q;
cin >> Q;
for (int i = 0; i < Q; ++i) {
int64_t q;
cin >> q;
q += sum;
if (mn <= q && q <= mx) {
cout << q << endl;
} else if (q < mn) {
cout << mn << endl;
} else {
cout << mx << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#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 First = "First";
const string Second = "Second";
int main(){
cout<<setprecision(1000);
ll T;
cin>>T;
For(times,T){
ll N;
cin>>N;
vector<ll> A(N);
REP(N)cin>>A[i];
if(N%2){
cout<<Second<<endl;
}else{
map<ll,ll> cnt;
REP(N){
cnt[A[i]]+=1;
}
bool f = false;
for (auto &&i : cnt)
{
if(i.second%2){
f=true;
}
}
if(f){
cout<<First<<endl;
}else{
cout<<Second<<endl;
}
}
}
return 0;
}
| #include <iostream>
#include <set>
#include <queue>
#include <limits>
#include <string.h>
#include <algorithm>
#include <map>
#define INF 0x3f3f3f3f
#define LL long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
using namespace std;
typedef pair<int,int>pii;
int a[200010];
map<int,int>mm;
int main(){
int t;
cin>>t;
while(t--){
mm.clear();
int n;
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
mm[a[i]]++;
}
if(n&1)puts("Second");
else{
int flg=0;
for(auto it=mm.begin();it!=mm.end();it++){
if(it->S&1){
flg=1;
break;
}
}
if(flg)puts("First");
else puts("Second");
}
}
return 0;
} |
#include <bits/stdc++.h>
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
using namespace std;
using Graph = vector<vector<int>>;
using Grid= vector<string>;
using vin= vector<int>;
using ll=long long;
using ull=unsigned long long;
using vll= vector<ll>;
using vbl=vector<bool>;
using vch=vector<char>;
using P=pair<int ,int>;
//const long double pi=acos(-1);
#define ft first
#define sd second
#define fn front
#define pb push_back
#define eb emplace_back
#define it insert
#define si(v) int((v).size())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rell(i,n) for (ll i=0; i< (ll)(n); i++)
#define sot(x) sort(x.begin(), x.end())
#define rese(x) reverse(x.begin(), x.end())
#define vnn(x,y,s,name) vector<vector<int>> name(x, vector<int>(y,s))
#define mse(x) memset(x, 0, sizeof(x))
#define mii(x,y,z) min(x,min(y,z))
#define maa(x,y,z) max(x,max(y,z))
#define cps CLOCKS_PER_SEC
#define yes cout<<"Yes"<<"\n"
#define no cout<<"No"<<"\n"
#define cset(x) cout<<fixed<<setprecision(x)
//const int INF=1001001001;
//998244353 1000000007
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n;
cin>>n;
vector<long long> ax(n);
long long as=0;
rep(i,n){
ll a,b;
cin>>a>>b;
as-=a;
ax[i]=2*a+b;
}
sot(ax);
rese(ax);
int cnt=0;
while(as<=0){
as+=ax[cnt];
cnt++;
}
cout<<cnt<<endl;
}
| #include <bits/stdc++.h>
using namespace std;
typedef int_fast32_t int32;
typedef int_fast64_t int64;
const int32 inf = 1e9+7;
const int32 MOD = 1000000007;
const int64 llinf = 1e18;
#define YES(n) cout << ((n) ? "YES\n" : "NO\n" )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n" )
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n" )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define all(obj) (obj).begin(),(obj).end()
#define rall(obj) (obj).rbegin(),(obj).rend()
#define fi first
#define se second
#define pb(a) push_back(a)
typedef pair<int32,int32> pii;
typedef pair<int64,int64> pll;
template<class T> inline bool chmax(T& a, T b) {
if (a < b) { a = b; return true; } return false;
}
template<class T> inline bool chmin(T& a, T b) {
if (a > b) { a = b; return true; } return false;
}
template<int64 mod>
struct ModInt{
int64 x;
constexpr ModInt(int64 y = 0):x((y%mod+mod)%mod){}
constexpr ModInt& operator+=(const ModInt& a){
if((x += a.x) >= mod) x -= mod;
return *this;
}
constexpr ModInt& operator-=(const ModInt& a){
if((x -= a.x) < 0)x += mod;
return *this;
}
constexpr ModInt& operator*=(const ModInt& a){
x = x * a.x % mod;
return *this;
}
constexpr ModInt& operator/=(const ModInt& a){
*this *= a.inv();
return *this;
}
constexpr ModInt operator-() const {
return ModInt(-x);
}
constexpr ModInt operator+(const ModInt& a) const {
return ModInt(*this) += a;
}
constexpr ModInt operator-(const ModInt& a) const {
return ModInt(*this) -= a;
}
constexpr ModInt operator*(const ModInt& a) const {
return ModInt(*this) *= a;
}
constexpr ModInt operator/(const ModInt& a) const {
return ModInt(*this) /= a;
}
constexpr ModInt operator++(){
*this += ModInt(1);
return *this;
}
constexpr ModInt operator++(int){
ModInt old = *this;
++*this;
return old;
}
constexpr ModInt operator--(){
*this -= ModInt(1);
return *this;
}
constexpr ModInt operator--(int){
ModInt old = *this;
--*this;
return old;
}
constexpr bool operator==(const ModInt& a) const {
return x == a.x;
}
constexpr bool operator!=(const ModInt& a) const {
return x != a.x;
}
constexpr ModInt pow(int64 r) const {
if(!r)return 1;
ModInt res = pow(r>>1);
res *= res;
if(r & 1) res *= *this;
return res;
}
constexpr ModInt inv() const {
return pow(mod-2);
}
friend istream& operator>>(istream& is, ModInt& a){
int64 t;
is >> t;
a = ModInt(t);
return is;
}
friend ostream& operator<<(ostream& os, const ModInt& a){
return os << a.x;
}
};
using mint = ModInt<MOD>;
mint dp[(int)(2e5)+5][20][2]; // dp[i][j][k] := i番目までにj種類使って(1:Nと一致, 0:Nより真に小さい)ときの通り数
int32 hex2ten(char c){
if('0' <= c && c <= '9'){
return c - '0';
}else{
return 10 + c - 'A';
}
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
string s;
int32 k;
cin >> s >> k;
dp[0][0][0] = 1; // 0
dp[0][1][0] = hex2ten(s[0]) - 1; // 1,...,(s_0-1)
dp[0][1][1] = 1; //s_0
set<int32> st;
REP(i,s.size()-1){
st.insert(hex2ten(s[i]));
dp[i+1][1][0] += dp[i][0][0] * 15;
dp[i+1][0][0] += dp[i][0][0];
FOR(j,1,k+1){
dp[i+1][j+1][0] += dp[i][j][0] * (16 - j);
dp[i+1][j][0] += dp[i][j][0] * j;
REP(l,hex2ten(s[i+1])){
if(st.count(l)){
dp[i+1][j][0] += dp[i][j][1];
}else{
dp[i+1][j+1][0] += dp[i][j][1];
}
}
if(st.count(hex2ten(s[i+1]))){
dp[i+1][j][1] += dp[i][j][1];
}else{
dp[i+1][j+1][1] += dp[i][j][1];
}
}
}
ANS(dp[s.size()-1][k][0] + dp[s.size()-1][k][1]);
return 0;
} |
#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
#define rep(i,n) for(ll i=0;i<(n);++i)
#define rep2(i,n) for(ll i=1;i<=(n);++i)
#define rep3(i,i0,n) for(ll i=i0;i<(n);++i)
#define rrep(i,n) for(ll i=((n)-1); i>=0; --i)
#define rrep2(i,n) for(ll i=(n); i>0; --i)
#define pb push_back
#define mod 1000000007
#define fi first
#define se second
#define len(x) ((ll)(x).size())
using namespace std;
using ll = long long;
using ld = long double;
using Pi = pair< ll, ll >;
using vl = vector<ll>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vp = vector<Pi>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
const ll INF = 1LL << 60;
const ld PI = 3.1415926535897932385;
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; }
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 all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define mp make_pair
void printb(ll N,ll d=16){
rep(i,d){
cout<<(N/(1<<(d-i-1)))%2;
}
cout<<endl;
}
void printv(vector<ll>a){
rep(i,a.size()){
if(i==a.size()-1){
cout<<a[i]<<endl;
}else{
cout<<a[i]<<" ";
}
}
}
bool In_map(ll y,ll x,ll h,ll w){
if(y<0 || x<0 || y>=h || x>=w){
return 0;
}else{
return 1;
}
}
bool compare(Pi a, Pi b) {
if(a.first != b.first){
return a.first < b.first;
}else{
return a.second < b.second;
}
}
//const vector<ll> dx = {1, 0, -1, 0, 1, -1, 1, -1};
//const vector<ll> dy = {0, 1, 0, -1, 1, 1, -1, -1};
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};
int main() {
ll N;
cin>>N;
vector<ld> A(N);
rep(i,N){
cin>>A[i];
}
auto f = [&](ld x){
ld ret=0;
rep(i,N){
ret+=min(A[i],2*x)-A[i]-x;
}
return ret/ld(N);
};
ll cnt=500;
ld h=2e9;
ld l=0;
while(cnt--){
ld c1 = (l*2+h)/3.0;
ld c2 = (h*2+l)/3.0;
//cout<<c1<<" "<<c2<<" "<<l<<" "<<h<<endl;
if(f(c1)>f(c2)){
h=c2;
}else{
l=c1;
}
}
cout << fixed << setprecision(15);
cout<<-f((l+h)/2)<<endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF=1e9;
const int mod=1e9+7;
void solve()
{
int n;
cin>>n;
vector<double>v(n);
double sum=0;
for(int i=0;i<n;++i)
{
cin>>v[i];
sum+=v[i];
}
sum/=n;
sort(v.begin(), v.end());
vector<double>pre(n);
pre[0]=v[0];
for(int i=1;i<n;++i) pre[i]=pre[i-1]+v[i];
double ans=1000000000000000000;
for(int i=0;i<n;++i)
{
double x=v[i]/2;
double val=x+sum;
double w=0;
if(i>0) w=pre[i-1];
val-=(2*x*(n-i)+w)/n;
ans=min(ans,val);
//cout<<val<<' '<<i<<'\n';
}
cout<<fixed<<setprecision(6)<<ans;
}
int main()
{
solve();
} |
#include <bits/stdc++.h>
#define ll long long
#define vec vector
using namespace std;
const long long MAXVAL = (long long) 1e18 + 1;
const long long MOD = 1000000007ll;
//const long long MOD = 998244353ll;
const int INF = 1000000001;
long long poww(int x, long long pow) {
if (pow == 0ll ) return 1;
if (pow == 1ll) return x % MOD;
long long ans = poww(x, pow >> 1) % MOD;
ans = (ans * ans) % MOD;
if ((pow & 1) == 1) {
ans = (ans * x ) % MOD;
}
return ans % MOD;
}
ll gcd(ll x, ll y) {
if (x == 0) return y;
while (y) {
x %= y;
swap(x, y);
}
return x;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int q = 1;
//cin >> q;
while (q-- >0) {
int n;
cin >> n;
int k;
cin >> k;
int cc[n];
for (int i = 0; i < n; ++i) cc[i] = 0;
for (int i = 0; i < n; ++i) {
int x;
cin >> x;
cc[x]++;
}
int ans = 0;
int j =0 ;
while (cc[0] && j < k) {
for (int i = 0 ;i < n; ++i) {
if (cc[i] == 0) break;
++ans;
--cc[i];
}
++j;
}
cout << ans << "\n";
}
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define all(a) a.begin(),a.end()
#define MOD 1000000007
#define ff first
#define ss second
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define REPR(i,n,a) for(ll i=n;i>a;i--)
#define sq(x) (x)*(x)
#define t_c(t) ll t;cin>>t;while(t--)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
// #define gcd(a,b) __gcd(a,b)
// #define lcm(a,b) (a*(b/gcd(a,b)))
void init_code(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
ll gcd(ll a, ll b){
if(b==0){
return a;
}
return gcd(b,a%b);
}
ll lcm(ll a, ll b){
return a*(b/gcd(a,b));
}
ll neg_mod(ll a, ll b){
ll r=a%b;
return r<0 ? r+b : r;
}
// const ll maxN=1000000;
// ll prime[maxN+1];
// void sieve(){
// prime[0]=prime[1]=1;
// for(ll i=2;i<=maxN;i++){
// if(prime[i]==0){
// for(ll j=i*i;j<=maxN;j+=i){
// prime[j]=1;
// }
// }
// }
// }
void solve(){
ll t,n;
cin>>t>>n;
ll dis=100+t;
vector<ll> v(dis+1,0);
for(ll i=1;i<=100;i++){
ll curr=(ll)floor(((ld)t*(ld)i)/(ld)100);
v[i+curr]=1;
}
vector<ll> nv;
for(ll i=1;i<=dis;i++){
if(v[i]==0){
nv.pb(i);
}
}
ll mul=((ll)ceil((ld)n/(ld)t))-1;
ll mod=n%t;
if(mod==0){
mod=t;
}
ll ans=(mul*dis)+(nv[mod-1]);
cout<<ans;
// for(ll i=0;i<nv.size();i++){
// cout<<nv[i]<<" ";
// }
}
int main(){
fast_io;
// init_code();
// t_c(t){
// solve();
// }
solve();
return 0;
} |
#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;
const int maxN = 3e3; int n;
lli a[maxN][5];
map<vector<int>, int> cnt;
vector<int> merge(vector<int> &a1, vector<int> a2)
{
vector<int> ans(5);
for (int i = 0; i < 5; i++) ans[i] = max(a1[i], a2[i]);
return ans;
}
bool bruteForce(map<vector<int>, int>::iterator it = cnt.begin(), int chosen = 0, vector<int> curr = {0, 0, 0, 0, 0})
{
if (chosen == 3 && *min_element(curr.begin(), curr.end()) == 1)
return true;
if (it == cnt.end())
return false;
if (bruteForce(next(it), chosen, curr))
return true;
for (int j = 1; chosen + j <= 3 && j <= it->second; j++)
{
curr = merge(curr, it->first);
if (bruteForce(next(it), chosen + j, curr))
return true;
}
return false;
}
bool can(lli x)
{
cnt.clear();
for (int i = 0; i < n; i++)
{
vector<int> b(5);
for (int j = 0; j < 5; j++)
b[j] = a[i][j] >= x;
if (!cnt.count(b)) cnt[b] = 0;
cnt[b]++;
}
return bruteForce();
}
int main()
{
while (~scanf("%d", &n))
{
for (int i = 0; i < n; i++)
for (int j = 0; j < 5; j++)
scanf("%lld", &a[i][j]);
lli lo = 0, hi = 1e9;
while (lo < hi)
{
lli mid = (lo + hi + 1) >> 1LL;
if (can(mid)) lo = mid;
else hi = mid - 1;
}
printf("%lld\n", lo);
}
return 0;
} | #pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
typedef long long ll;
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 << "]";
}
// sim dor(const c&) { ris; }
};
#ifdef ASJKD
}
#endif
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define read(x) for(auto &i : (x)){cin>>i;}
#define all(x) begin(x), end(x)
#define pb push_back
#define maxn 1500
ll mod = 998244353;
int INF = 1e9+1e8+1e7;
ll INF64 = 1e18;
long long binpow(long long a, long long b, long long m) {
a %= m;
long long res = 1;
while (b > 0) {
if (b & 1){
res = res * a % m;
}
a = a * a % m;
b >>= 1;
}
return res;
}
struct pl{
vector<int> h;
void readd(){
h.resize(5);
for(int i=0;i<5;i++){
cin>>h[i];
}
}
bool amgood(vector<int> &sub, pl &other){
int mn = INF;
int mn2 = INF;
for(int i=0;i<sub.size();i++){
mn = min(h[sub[i]], mn);
}
for(int i=0;i<sub.size();i++){
mn2 = min(other.h[sub[i]], mn2);
}
return mn > mn2;
}
};
void test_case(int tnum){
int n;
cin>>n;
vector<pl> a(n);
for(int i=0;i<n;i++){
a[i].readd();
}
vector<int> perm(5);
for(int i=0;i<5;i++){
perm[i]=i;
}
int ans =0;
do{
for(int t1=0;t1<=5;t1++){
for(int t2=0;t2+t1<=5;t2++){
vector<vector<int>> sub(3);
for(int i=0;i<t1;i++){
sub[0].pb(perm[i]);
}
for(int i=t1;i<t1+t2;i++){
sub[1].pb(perm[i]);
}
for(int i=t1+t2;i<5;i++){
sub[2].pb(perm[i]);
}
vector<pl> team;
set<int> taken;
for(int i=0;i<3;i++){
int idx = -1;
pl cur;
cur.h.resize(5);
for(int j=0;j<n;j++){
if(!taken.count(j) && (idx == -1 or !cur.amgood(sub[i], a[j]))){
idx = j;
cur = a[j];
}
}
taken.insert(idx);
team.pb(a[idx]);
}
vector<int> mxs(5);
for(pl p : team){
for(int i=0;i<5;i++){
mxs[i] = max(mxs[i], p.h[i]);
}
}
ans = max(ans, *min_element(all(mxs)));
// debug() << imie(sub) imie(taken) imie(perm) imie(t1) imie(t2);
assert(sub[0].size() + sub[1].size() + sub[2].size() == 5);
}
}
} while(next_permutation(all(perm)));
cout << ans << '\n';
}
int main(){
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(false);
int t=1;
// cin>>t;
for(int test=1;test<=t;test++){
test_case(test);
}
return 0;
} |
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define even(x) (x % 2 == 0 ? true : false)
#define odd(x) (x % 2 ? true : false)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned;
using pii = pair<int, int>;
//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;
//const int mod = 1000000007;
//vector<vector<int>> dp(m, vector<int>(n));
void solve()
{
vector<int>a(3);
for (int i = 0; i < 3; i++) {
cin >> a[i];
}
sort(all(a));
if (a[2] - a[1] == a[1] - a[0])
cout << "Yes" << endl;
else
cout << "No" << endl;
}
int main(void)
{
ios::sync_with_stdio(0);
cin.tie(0);
solve();
}
| #include<bits/stdc++.h>
#define ll long long
ll n,m,k;
const ll mod = 998244353;
ll qmul(ll a,ll b){
ll tmp = 0,s=0;
while(b){
s=(s+a)%mod;
if(b&1) tmp=(tmp+s)%mod;
b>>=1;
}
return tmp;
}
ll qpow(ll a,ll b){
if(b==0) return 1;
ll tmp = qpow(a,b/2);
tmp = (tmp*tmp)%mod;
if(b&1) tmp=(tmp*a)%mod;
return tmp;
}
int main(){
scanf("%lld%lld%lld",&n,&m,&k);
if(n==1){
printf("%lld",qpow(k,m));
return 0;
}
if(m==1){
printf("%lld",qpow(k,n));
return 0;
}
ll ans = 0;
ll last = 0;
for(int i=1;i<=k;++i){
ll a = qpow(i,n);
ll b= qpow(k-i+1,m);
ans=(ans+((a-last+mod)%mod)*b%mod)%mod;
last = a;
}
printf("%lld",ans);
return 0;
} |
// {{{ Template
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef std::vector <int> poly;
typedef std::pair <int,int> pii;
#define fi first
#define se second
#define rez resize
#define pp pop_back
#define pb push_back
#define mkp std::make_pair
#define lep(i,l,r) for(int i=l;i<=r;++i)
#define rep(i,r,l) for(int i=r;i>=l;--i)
#define CLEAR(x) memset((x),0,sizeof((x)))
#define COPY(x,y) memcpy((x),(y),sizeof((x)))
const int inf=1e9+7;
const int mod=1e9+7;
template <class T> inline T read() {
char ch; bool flag=0; T x=0;
while(ch=getchar(),!isdigit(ch)) if(ch=='-') flag=1;
while(isdigit(ch)) x=x*10+ch-48,ch=getchar();
return flag?-x:x;
}
struct {
inline operator ll() {return read<ll>();}
inline operator int() {return read<int>();}
template <class T> inline void operator () (T &x) {x=*this;}
template <class T,class ...A> inline void operator () (T &x,A &...a)
{x=*this,this->operator()(a...);}
} IN;
template <class T> inline void chkmax(T &x,T y) {if(x<y) x=y;}
template <class T> inline void chkmin(T &x,T y) {if(x>y) x=y;}
inline int mul(int x,int y) {return 1ll*x*y%mod;}
inline int dec(int x,int y) {x-=y; if(x<0) x+=mod; return x;}
inline int add(int x,int y) {x+=y; if(x>=mod) x-=mod; return x;}
inline void sub(int &x,int y) {x-=y; if(x<0) x+=mod;}
inline void pls(int &x,int y) {x+=y; if(x>=mod) x-=mod;}
inline int modpow(int x,int y,int res=1) {
for(y = (y+mod-1)%(mod-1);y;y>>=1,x=mul(x,x)) if(y&1) res=mul(res,x);
return res;
}
// }}}
const int N = 2e5 + 5;
char s1[N], s2[N], s3[N];
int n;
inline void solve () {
IN (n);
scanf("%s%s%s\n",s1,s2,s3);
lep (i,1,n) putchar ('0');
lep (i,1,n) putchar ('1');
putchar ('0'), puts ("");
}
int main() {
int T = int(IN);
while (T--) solve ();
return 0;
}
| #include "bits/stdc++.h"
using namespace std;
#define ll long long
#define pb push_back
#define all(_obj) _obj.begin(),_obj.end()
#define F first
#define S second
#define pll pair<ll, ll>
#define vll vector<ll>
ll n,m,a,b,c,k,temp,x,y,INF=1e18;
const int MAXN=1e5+11,mod=1e9+7;
ll max(ll a,ll b) {return ((a>b)?a:b);}
ll min(ll a,ll b) {return ((a>b)?b:a);}
vll read(int n) {vll v(n);for (int i = 0; i < v.size(); i++)cin>>v[i];return v;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int tree[500000],t[500000+1],ne[500000+1];
void bfst()
{
for(int i=n-1;i>0;--i)
tree[i]=tree[i<<1]+tree[i<<1|1];
}
int qfst(int l,int r)
{
int res=0;
for(l+=n,r+=n;l<r;l>>=1,r>>=1)
{
if(l&1) res+=tree[l++];
if(r&1) res+=tree[--r];
}
return res;
}
void modify(int p, int value)
{
for (tree[p += n] = value; p > 1; p >>= 1)
tree[p >> 1] = tree[p]+tree[p ^ 1];
}
vll v[500000+2];
void sol(void)
{
cin>>n>>m>>k;
for(int i=1;i<=m;i++) t[i]=n+1;
for(int i=1;i<=n;i++) ne[i]=m+1;
vector<pll> vp;
while(k--)
{
cin>>a>>b;
t[b]=min(t[b],a);
ne[a]=min(ne[a],b);
vp.pb({a,b});
}
for(int i=2;i<=n;i++)
v[ne[i]].pb(i);
ll ans=1;
for(int j=2;j<=ne[1]-1;j++)
{
ans+=t[j];
ans--;
}
for(int i=2;i<=t[1]-1;i++)
{
ans+=ne[i];
ans--;
}
for(int i=0;i<n;i++) tree[i+n]=1;
bfst();
for(auto x:v[1])
modify(x-1,0);
for(int j=2;j<=ne[1]-1;j++)
{
ans-=qfst(1,min(t[j],t[1])-1);
for(auto x:v[j])
modify(x-1,0);
}
cout<<ans;
return ;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL),cout.tie(NULL);
int test=1;
//cin>>test;
while(test--) sol();
}
|
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
random_device rnd;
mt19937 mt(rnd());
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1000000007;
int main()
{
int a, b;
cin >> a >> b;
if (min(a, b) + 3 > max({a, b}))
{
cout << "Yes" << endl;
}
else
{
cout << "No" << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int x,y;
cin>>x>>y;
fabs(x-y)<=2?cout<<"Yes":cout<<"No";
} |
#include<stdio.h>
#include<stdlib.h>
#define rep(i,N) for(int i=0;i<(int)N;i++)
static int IN(void)
{
int x=0,f=1,c;while(c=getchar(),c<48||c>57){if(c==45)f=-f;}
while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f*x;
}
static void OUT(long x){if(x<0){putchar('-'),x=-x;}if(x>=10){OUT(x/10);}putchar(x-x/10*10+48);}
static int Asc(const void *p1,const void *p2){rep(i,2){return ((int*)p1)[i]-((int*)p2)[i];}}
int main(void)
{
int N=IN(),A[200000][2],B[200000][2],C[200000],bit[200000]={};long count=0l,sum=0l;
rep(i,N){A[i][0]=IN()+i;A[i][1]=i;}qsort(A,N,sizeof(int*),Asc);
rep(i,N){B[i][0]=IN()+i;B[i][1]=i;}qsort(B,N,sizeof(int*),Asc);
rep(i,N){if(A[i][0]!=B[i][0]){return !puts("-1");}C[A[i][1]]=B[i][1];}
rep(i,N)
{
sum=0l;for(int j=C[N-1-i]-1;j>=0;j=(j&(j+1))-1){sum+=bit[j];}count+=sum;
for(int j=C[N-1-i];j<N;j|=j+1){bit[j]++;}
}
OUT(count);
} | #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
const int N=5e5+500;
int n,a[N],b[N],tmpa[N],tmpb[N],cur[N],p[N],s[N];
vector<int>pos[N];
int query(int x){int ans=0;for(;x;x-=x&-x)ans+=s[x];return ans;}
void ins(int x){for(;x<=n;x+=x&-x)s[x]++;}
int main()
{
long long ans=0;
scanf("%d",&n);
for(int i=1;i<=n;i++)scanf("%d",a+i),a[i]+=i,tmpa[i]=a[i];
for(int i=1;i<=n;i++)scanf("%d",b+i),b[i]+=i,tmpb[i]=b[i];
sort(tmpa+1,tmpa+n+1),sort(tmpb+1,tmpb+n+1);
for(int i=1;i<=n;i++)if(tmpa[i]!=tmpb[i]){puts("-1");return 0;}
for(int i=1;i<=n;i++)a[i]=lower_bound(tmpa+1,tmpa+n+1,a[i])-tmpa;
for(int i=1;i<=n;i++)b[i]=lower_bound(tmpb+1,tmpb+n+1,b[i])-tmpb;
for(int i=1;i<=n;i++)pos[b[i]].push_back(i);
for(int i=1;i<=n;i++)p[i]=pos[a[i]][cur[a[i]]],cur[a[i]]++;
for(int i=n;i>=1;i--)ans+=query(p[i]),ins(p[i]);
cout<<ans<<endl;
} |
#include<bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define pb push_back
#define fi first
#define se second
#define ll long long
#define ld long double
#define lll __int128
#define tp top()
#define fr front()
#define vi vector<int>
#define sz size()
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define mem(a, b) memset(a, (b), sizeof(a))
#define clr(a) memset(a, 0, sizeof(a))
#define sqr(x) ( (x) * (x) )
#define all(v) v.begin(), v.end()
typedef pair<int, int> pii;
typedef pair<int,pii> pip;
typedef pair<pii,int> ppi;
typedef pair<pii,pii> ppp;
void optIO(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
string s1,s2,s3,ss1,ss2,ss3;
int n;
void solve(){
cin>>n;
cin>>s1>>s2>>s3;
string s;
rep(i,0,n) s+='0';
rep(i,0,n) s+='1';
s += '0';
cout<<s<<"\n";
}
int main()
{
optIO();
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int t=1;
cin>>t;
while(t--){
solve();
}
return 0;
}
| #include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <tuple>
using namespace std;
void yes(){ cout << "yes" << endl; }
void Yes(){ cout << "Yes" << endl; }
void YES(){ cout << "YES" << endl; }
void no(){ cout << "no" << endl; }
void No(){ cout << "No" << endl; }
void NO(){ cout << "NO" << endl; }
void print(string str){ cout << str << endl;}
#define rep(i, n)for(int i=0; i<n; i++)
#define ll long long
ll inf = 1000000007;
ll INF = 1000000000000000007;
int main(){
ll T;
cin >> T;
rep(i, T){
ll N;
cin >> N;
string S[3];
rep(j, 3){
cin >> S[j];
}
ll end = 2*N-1;
// 末尾が全て同じ
if(S[0][end] == S[1][end] && S[1][end] == S[2][end]){
if(S[0][end] == '0'){
rep(j, N){
cout << "1";
}
rep(j, N){
cout << "0";
}
cout << "1" << endl;
}
else{
rep(j, N){
cout << "0";
}
rep(j, N){
cout << "1";
}
cout << "0" << endl;
}
}
// 末尾が全て同じでない
else{
rep(j, N){
cout << "0";
}
rep(j, N){
cout << "1";
}
cout << "0" << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
#define vall(x) (x).begin(), (x).end()
using namespace std;
namespace atcoder {}
using namespace atcoder;
using lli = long long int;
void YESNO(bool), YesNo(bool);
template <class T1, class T2> bool chmin(T1 &l, const T2 &r);
template <class T1, class T2> bool chmax(T1 &l, const T2 &r);
#define int long long int
void solve(std::string S) {
rep(i, S.size()) {
if (!(S[i] >= 'a' && S[i] <= 'z' && i % 2 == 0) &&
!(S[i] >= 'A' && S[i] <= 'Z' && i % 2 == 1)) {
cout << "No" << endl;
return;
}
}
cout << "Yes" << endl;
}
signed main() {
std::string S;
std::cin >> S;
solve(S);
return 0;
}
// -- lib
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
template <class T1, class T2> bool chmin(T1 &l, const T2 &r) {
return (l > r) ? (l = r, true) : false;
}
template <class T1, class T2> bool chmax(T1 &l, const T2 &r) {
return (l < r) ? (l = r, true) : false;
}
template <class T1, class T2> void vadd(vector<T1> &v, T2 x) {
for (auto &s : v)
s += T2(x);
}
| #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int INF = 1001001001;
const long long LINF = 1001002003004005006;
const double PI = acos(-1);
int d4r[] = {1, 0, -1, 0};
int d4c[] = {0, 1, 0, -1};
int d8r[] = {1, 1, 0, -1, -1, -1, 0, 1};
int d8c[] = {0, 1, 1, 1, 0, -1, -1, -1};
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
string s; cin >> s;
bool flag = true;
for(int i = 0;i < s.size();++i) {
if(i % 2 == 0 && 'A' <= s[i] && s[i] <= 'Z') {
flag = false;
}
else if(i % 2 == 1 && 'a' <= s[i] && s[i] <= 'z') {
flag = false;
}
}
if(flag == true) {
cout << "Yes" << '\n';
}
else {
cout << "No" << '\n';
}
return 0;
} |
//Adarsh
//IIIT Gwalior
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define REP(i,n) for(int i=1;i<=(int)n;i++)
#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int MAX_N = 1e5 + 1;
const int MOD = 1e9 + 7;
#define pb push_back
#define vi vector<int>
#define initial(a, x) memset(a, x, sizeof(a))
void solve() {
ll n,x;
string s;
cin>>n>>x>>s;
rep(i,n){
if(s[i]=='o') x++;
else{
if(x>0) x--;
}
}
cout<<x;
}
int main() {
FAST_IO
// int tc;
// cin >> tc;
//for (int t = 1; t <= tc; t++) {
// cout << "Case #" << t << ": ";
solve();
//}
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
int main() {
int n, x;
cin >> n >> x;
string s;
cin >> s;
int ans = x;
rep(i, n) {
if (s[i] == 'o')
++ans;
else
ans = max(0, ans - 1);
}
cout << ans << endl;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int long long
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define mii map<int,int>
#define pqb priority_queue<int>
#define pqs priority_queue<int,vi,greater<int> >
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x,y) cout<<setprecision(y)<<x
#define mk(arr,n,type) type *arr=new type[n];
#define w(x) int x; cin>>x; while(x--)
#define pw(b,p) pow(b,p) + 0.1
#define endl "\n"
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void __print(int32_t 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
void fastIO()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
int power(int a,int b,int md)
{
int ans=1;
while(b)
{
if(b&1) ans*=a;
ans%=md;
a*=a;
a%=md;
b>>=1;
}
return ans;
}
int find(map<int,int> &mp,int x)
{
//debug("T",x);
if(!mp.count(x)) return x;
if(mp[x]==x) return x;
return mp[x]=find(mp,mp[x]);
}
void solve()
{
int n;
cin>>n;
map<int,int> mp;
for(int i=0;i<n;i++)
{
int x,y;
cin>>x>>y;
//debug(mp);
//debug(i);
if(!mp.count(x)&&!mp.count(y)) mp[min(x,y)]=max(x,y);
else if(!mp.count(x)) mp[x]=find(mp,y);
else if(!mp.count(y)) mp[y]=find(mp,x);
else
{
// debug("J",mp);
int px=find(mp,x),py=find(mp,y);
if(!mp.count(px))
{
mp[px]=py;
}
else if(!mp.count(py))
{
mp[py]=px;
}
}
// debug(mp);
}
mp.erase(0);
cout<<mp.size();
}
int32_t main()
{
fastIO();
//w(t)
{
solve();
cout<<endl;
}
return 0;
} | /* -*- coding: utf-8 -*-
*
* b.cc: B - Reversible Cards
*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
/* constant */
const int MAX_N = 200000;
const int MAX_M = 400000;
/* typedef */
typedef vector<int> vi;
/* global variables */
vi nbrs[MAX_M];
bool used[MAX_M];
int ps[MAX_M], cis[MAX_M];
/* subroutines */
/* main */
int main() {
int n;
scanf("%d", &n);
int m = 0;
for (int i = 0; i < n; i++) {
int a, b;
scanf("%d%d", &a, &b);
a--, b--;
nbrs[a].push_back(b);
nbrs[b].push_back(a);
m = max(m, max(a, b));
}
m++;
//printf("m=%d\n", m);
int sum = 0;
for (int st = 0; st < m; st++)
if (! used[st]) {
used[st] = true;
ps[st] = -1;
int gn = 1, en = 0;
for (int u = st; u >= 0;) {
vi &nbru = nbrs[u];
if (cis[u] < nbru.size() && nbru[cis[u]] == ps[u]) cis[u]++;
if (cis[u] < nbru.size()) {
int v = nbru[cis[u]++];
en++;
if (! used[v]) {
used[v] = true;
ps[v] = u;
gn++;
u = v;
}
}
else {
u = ps[u];
}
}
//printf("gn=%d,en=%d\n", gn, en);
sum += min(en, gn);
}
printf("%d\n", sum);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
// #include <atcoder/all>
// using namespace atcoder;
// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(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)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define irreps(i, m, n) for (int i = ((int)(n)-1); i > (int)(m); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) (int)(x.size())
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;
using ld = long double;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
const ll INF = 1e9+10;
const ll MOD = 1e9+7;
// const ll MOD = 998244353;
const ll LINF = 1e18;
void fail(){
cout << "No" << endl;
exit(0);
}
signed main()
{
cin.tie( 0 ); ios::sync_with_stdio( false );
int n; cin>>n;
vc<vc<int>> c(n, vc<int>(n));
rep(i,n) rep(j,n) cin>>c[i][j];
vc<int> a(n), b(n);
int minb=INF;
rep(i,n){
b[i]=c[i][0];
chmin(minb,b[i]);
}
int mina=INF;
rep(j,n){
a[j]=c[j][j]-b[j];
chmin(mina,a[j]);
}
rep(i,n){
rep(j,n){
if(b[i]+a[j]!=c[i][j]) {
fail();
}
}
}
if(mina<0){
if(abs(mina)>abs(minb)) fail();
int x=abs(mina);
rep(i,n) a[i]+=x, b[i]-=x;
}
cout<<"Yes"<<endl;
swap(a,b);
rep(i,n) cout<<a[i]<<' ';
cout<<endl;
rep(i,n) cout<<b[i]<<' ';
cout<<endl;
} | #include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define pll pair<long long, long long>
#define f first
#define s second
#define debug cout<<"here\n"
#define MOD 1000000009
using namespace std;
const int MAXN = 2e6 + 5;
int where[MAXN];
void solve(){
int n; cin>>n;
for(int i=0; i<2*n; i++) where[i] = i;
string s,ss; cin>>s;
ss = s;
int q; cin>>q;
bool x = 0;
while(q--){
int ct,a,b; cin>>ct;
if(ct == 1){
cin>>a>>b; a--; b--;
swap(where[(a+n*x)%(2*n)], where[(b+n*x)%(2*n)]);
}
else{
x ^= 1;
cin>>a>>b;
}
}
for(int i=0; i<2*n; i++) ss[i] = s[where[i]];
if(x){
for(int i=n; i<2*n; i++) cout<<ss[i];
for(int i=0; i<n; i++) cout<<ss[i];
}
else{
cout<<ss;
}
}
int main(){
ios_base::sync_with_stdio(false);
cout.tie(0); cin.tie(0);
cout<<fixed<<setprecision(12);
int t =1; //cin>>t;
for(int i=1; i<= t; i++){
solve();
cout<<"\n";
}
return 0;
} |
//#define _GLIBCXX_DEBUG
//#include <atcoder/all>
#include <bits/stdc++.h>
#include <chrono>
#include <random>
using namespace std;
//using namespace atcoder;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
//const ll MOD=998244353;
//using mint = modint998244353;
//using mint = modint1000000007;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);
int dx[9] = {1, 0, -1, 0, 1, 1, -1, -1, 0};
int dy[9] = {0, 1, 0, -1, 1, -1, -1, 1, 0};
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
// cout << fixed << setprecision(15);
string G="atcoder";
ll T; cin>>T;
rep(_,T){
string S; cin>>S;
ll N=S.size();
auto MS=S;
sort(MS.rbegin(),MS.rend());
if(G>=MS) {cout<<-1<<'\n'; continue;}
ll ans=INF;
vector<ll> vec(7,-1);
rep(i,N){
rep(j,7){
if(S[i]==G[j]&&vec[j]==-1) vec[j]=i;
}
}
//for(auto v:vec) cout<<v<<'\n';
rep(i,8){
ll sans=0;
rep(j,i){
if(vec[j]==-1) goto OUT;
sans+=abs(vec[j]-j);
}
int piyo=0;
rep(j,N){
int hoge=0;
rep(k,i){
if(j==vec[k]) hoge=1;
}
if(hoge) continue;
if(S[j]>(i==7?'a'-1:G[i])){
sans+=abs(j-i);
piyo=1;
//cout<<i<<' '<<j<<'\n';
break;
}
}
//cout<<i<<' '<<sans<<'\n';
if(piyo) chmin(ans,sans);
}
OUT:;
cout<<ans<<'\n';
}
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
int main(void)
{
string X = "atcoder";
long long T;
cin >> T;
for (long long i = 0; i < T; i++)
{
string S;
cin >> S;
if (S > X)
{
cout << 0 << endl;
continue;
}
else if (S == "a" || S == "aa")
{
cout << -1 << endl;
}
else if (S[1] != 'a')
{
cout << 1 << endl;
continue;
}
else
{
for (long long j = 2; j < S.size(); j++)
{
if (S[j] > 't')
{
cout << j-1 << endl;
break;
}
else if (S[j] != 'a')
{
cout << j << endl;
break;
}
if (j == S.size()-1)
{
cout << -1 << endl;
break;
}
}
}
}
} |
Subsets and Splits