code_file1
stringlengths 87
4k
| code_file2
stringlengths 85
4k
|
---|---|
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cerr<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
int getInt(){int x;scanf("%d",&x);return x;}
template<typename T>istream& operator>>(istream&i,v(T)&v){rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v){stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,const v(T)&v){if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v){return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v){return o<<v.fi<<","<<v.se;}
template<typename T>bool mins(T& x,const T&y){if(x>y){x=y;return true;}else return false;}
template<typename T>bool maxs(T& x,const T&y){if(x<y){x=y;return true;}else return false;}
template<typename T>ll suma(const v(T)&a){ll res(0);for(auto&&x:a)res+=x;return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 3005;
// Mod int
const int mod = 998244353;
struct mint {
ll x;
mint():x(0){}
mint(ll x):x((x%mod+mod)%mod){}
// mint(ll x):x(x){}
mint& fix() { x = (x%mod+mod)%mod; return *this;}
mint operator-() const { return mint(0) - *this;}
mint operator~() const { return mint(1) / *this;}
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){ (x*=a.pow(mod-2).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 operator/(const mint& a)const{ return mint(*this) /= a;}
mint pow(ll t) const {
if(!t) return 1;
mint res = pow(t/2);
res *= res;
return (t&1)?res*x:res;
}
bool operator<(const mint& a)const{ return x < a.x;}
bool operator==(const mint& a)const{ return x == a.x;}
};
mint ex(mint x, ll t) { return x.pow(t);}
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}
typedef vector<mint> vm;
struct comb {
vm f, g;
comb(){}
comb(int mx):f(mx+1),g(mx+1) {
f[0] = 1;
rrep(i,mx) f[i] = f[i-1]*i;
g[mx] = f[mx].pow(mod-2);
for(int i=mx;i>0;i--) g[i-1] = g[i]*i;
}
mint operator()(int a, int b) {
if (a < b) return 0;
return f[a]*g[b]*g[a-b];
}
};
//
mint dp[MX][MX];
int main() {
int n,k;
scanf("%d%d",&n,&k);
dp[0][0] = 1;
rep(i,n+1)drep(j,n+1) {
dp[i+1][j+1] += dp[i][j];
if (j%2 == 0) dp[i][j/2] += dp[i][j];
}
cout<<dp[n][k]<<endl;
return 0;
}
| #include<iostream>
using namespace std;
#define int long long
const int N=1e4;
const int MOD=998244353;
/**
* 设f[i][j]为用i个数凑出j的方案数
* 则有:
* f[i][j]=f[i-1][j-1]+f[i][2*j]
* f[i][j]=0 (j>i)
*
*/
int f[N][2*N];
int n,m;
signed main(){
cin>>n>>m;
f[0][0]=1;
for(int i=1;i<=n;i++)
for(int j=i;j>=1;j--)
f[i][j]=(f[i-1][j-1]+f[i][2*j])%MOD;
cout<<f[n][m]<<endl;
// system("pause");
} |
#include <bits/stdc++.h>
# define rep(i,l,n) for(int i=l,i##_end=n;i<i##_end;++i)
# define rrep(i,n,l) for(int i=((int)(n)-1),i##_end=l;i>=i##_end;--i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
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; }
int main() {
// 1. input
ll N;
cin>>N;
// 2.
ll ans = 0;
ans += max(0LL,N - 999);
ans += max(0LL,N - 999'999);
ans += max(0LL,N - 999'999'999);
ans += max(0LL,N - 999'999'999'999);
ans += max(0LL,N - 999'999'999'999'999);
// 3. output
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define all(x) (x).begin(),(x).end()
#define int long long
#define double long double
void solve() {
int n;
cin >> n;
int count = 0;
int i = 0;
for (i = 1000; i <= n; i *= 1000) {
count += n - i + 1 ;
}
cout << count << "\n";
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
// for getting input from input.txt
freopen("input.txt", "r", stdin);
// for writing output to output.txt
freopen("output.txt", "w", stdout);
#endif
int t = 1;
//cin >> t;
while (t-- > 0) {
solve();
}
return 0;
}
|
/*input
37 450
*/
#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define endl "\n"
#define sp " "
#define all(v) v.begin(),v.end()
#define makepr(a,b) make_pair(a, b)
#define loop(i,k,n) for(ll i=k;i<n;i++)
#define rlop(i,n,k) for(ll i=n-1;i>=k;i--)
#define lop(i ,a) for(auto i : a)
#define vecl vector<ll>
#define vecprl vector<pair<ll, ll> > v;
#define mpll map<ll, ll>
#define mpsl map<string, ll>
#define prll pair<ll, ll>
#define setl set<ll>
#define mod(a,b) a%b
typedef long long ll;
typedef long double ld;
int main()
{
fast;
int n , m;
cin >> n>> m;
float k = n*1.0/100;
cout<<m*k<<endl;
return 0;
}
| #include <iostream>
using namespace std;
int main(){
float a,b;
cin >> a >> b;
cout << b/100 * a;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main()
{
long long X, Y, A, B;
cin >> X >> Y >> A >> B;
long long ans = 0;
while (X < Y) {
if (X < Y / (double)A && X < Y - B) {
if (X * A < X + B) {
ans++;
X *= A;
} else {
ans += (X * A - X) / B;
X += (X * A - X) / B * B;
}
} else if (X < Y / (double)A) {
ans++;
X *= A;
} else if (X < Y - B) {
ans += (Y - X - 1) / B;
X += (Y - X - 1) / B * B;
} else {
break;
}
}
cout << ans << endl;
}
| /*/ Author: _Math.man /*/
#include<bits/stdc++.h>
using namespace std;
/*/---------------------------Defines-----------------------------------------/*/
#pragma GCC optimize("Ofast")
#define int long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define eb emplace_back
#define fn for(int i =0 ;i <n;i++)
#define fn1 for( int i =1;i<=n; i++)
#define fm for(int j =0 ;j <m;j++)
#define fm1 for(int j =1;j<=m;j++)
#define fi first
#define se second
#define endl '\n'
#define PI 3.14159265358979323846
#define MOD 1000000007
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
const int N = 2e6+5;
const int INF = 1e18L;
//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
/*/-----------------------------Debug begins----------------------------------/*/
vector<string> split(const string& s, char c) {
vector<string> v; stringstream ss(s); string x;
while (getline(ss, x, c)) v.emplace_back(x); return move(v);
}
template<typename T, typename... Args>
inline string arrStr(T arr, int n) {
stringstream s; s << "[";
for(int i = 0; i < n - 1; i++) s << arr[i] << ",";
if(n>0)
s << arr[n - 1] ;
s<< "]";
return s.str();
}
#define trace(args...) {__trace_begin(__LINE__); __trace(split(#args, ',').begin(), args);}
inline void __trace_begin(int line) { cerr << "#" << line << ": "; }
template<typename T> inline void __trace_out_var(vector<T> val) { cerr << arrStr(val, val.size()); }
template<typename T> inline void __trace_out_var(T* val) { cerr << arrStr(val, 10); }
template<typename T> inline void __trace_out_var(T val) { cerr << val; }
inline void __trace(vector<string>::iterator it) { cerr << endl; }
template<typename T, typename... Args>
inline void __trace(vector<string>::iterator it, T a, Args... args) {
cerr << it->substr((*it)[0] == ' ', it->length()) << "=";
__trace_out_var(a);
cerr << "; ";
__trace(++it, args...);
}
/*/-----------------------------Code begins----------------------------------/*/
int ar[N];
int dp[N];
signed main(){
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
IOS;
int T=1;
// cin >> T;
for(int i =1;i<=T;i++){
int x,y,a,b;
cin>>x>>y>>a>>b;
int ans = 0;
while(x < 2*INF/a && x<y/a && x*a <= x+ b)++ans,x*=a;
ans+=(y-x-1)/b;
cout <<ans;
}
return 0;
} |
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define REPD(i,a,b) for (int i=(a);i<=(b);i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef double d;
typedef long double ld;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<d> vd;
typedef vector<ld> vld;
typedef set<int> si;
typedef vector<si> vsi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> pi;
typedef queue<int> qi;
typedef queue<pi> qpi;
typedef pair<ll, ll> pll;
typedef queue<pll> qpll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const int mod = 1000000007;
const int INF = 1001001001;
// 小数点 << fixed << setprecision(0) <<
// sort降順 sort(ALL(),greater<int>());
// 円周率 M_PI
// 文字判定 isupper islower
// 文字変換
// 順列 do {} while(next_permutation(ALL(X)));
// 最大値 LLONG_MAX
// a内でx以上 auto iter = lower_bound(ALL(a), x);
// a内でxより大きい auto iter = upper_bound(ALL(a), x);
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
struct edge {
int from; //出発点
int to; //到達点
int cost; //移動コスト
};
typedef struct edge se;
typedef vector<edge> ve;
unsigned Euclidean_gcd(unsigned a, unsigned b) {
if(a < b) return Euclidean_gcd(b, a);
unsigned r;
while ((r=a%b)) {
a = b;
b = r;
}
return b;
}
int digit_sum(int n) {
int sum=n%10;
while(n!=0) {
n/=10;
sum+=n%10;
}
return sum;
}
vpll PrimeFactorization(ll n) {
vpll res;
for (ll i=2; i*i<=n; i++) {
if(n%i!=0) continue;
ll ex=0;
while(n%i==0) {
ex++;
n/=i;
}
res.push_back(pll(i,ex));
}
if(n!=1) res.push_back(pll(n,1));
return res;
}
int main() {
int n,a,b;
cin >> n >> a >> b;
cout << n+b-a << endl;
}
| #include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;
int main(){
float X, Y, Z;
cin >> X >> Y >> Z;
float res = Z*Y / X;
if(res == floor(res)) cout << res - 1 << endl;
else cout << floor(res) << endl;
} |
#include <math.h>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, l, n) for (int i = (l); i < (n); i++)
#define max(p, q) ((p) > (q) ? (p) : (q))
#define min(p, q) ((p) < (q) ? (p) : (q))
#define mod
using ll = long long;
using P = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T> >;
const ll INF = 1e18 + 1;
int main()
{
int n;
cin >> n;
VV<ll> c(n, V<ll>(n));
V<ll> a(n), b(n);
rep(i, 0, n) rep(k, 0, n)
cin >>
c[i][k];
a[0] = 0;
b[0] = c[0][0];
rep(i, 1, n)
{
a[i] = c[0][i] - c[0][i - 1] + a[i - 1];
b[i] = c[i][0] - c[i - 1][0] + b[i - 1];
}
int j = 0;
rep(i, 0, n) rep(k, 1, n)
{
if (a[k] - a[k - 1] != c[i][k] - c[i][k - 1])
j++;
if (b[k] - b[k - 1] != c[k][i] - c[k - 1][i])
j++;
}
if (j != 0)
cout << "No" << endl;
else
{
cout << "Yes" << endl;
ll ma = INF, mb = INF;
rep(i, 0, n)
{
ma = min(ma, a[i]);
mb = min(mb, b[i]);
}
if (ma < 0)
{
rep(i, 0, n)
{
a[i] += -ma;
b[i] += ma;
}
}
if (mb < 0)
rep(i, 0, n)
{
b[i] += -mb;
a[i] += mb;
}
rep(i, 0, n) cout << b[i] << " ";
cout << endl;
rep(i, 0, n) cout << a[i] << " ";
cout << endl;
}
return 0;
}
| #include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<numeric>
using namespace std;
#define INF (1 << 30) - 1
#define LINF 1LL << 60
const int MOD = 1000000007;
using ll = long long;
using P = pair<int, int>;
int main(){
int n;
cin >> n;
vector<vector<int>> c(n, vector<int>(n));
vector<int> a(n), b(n);
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
cin >> c[i][j];
}
}
int m = INF;
for(int i = 0; i < n; i++)m = min(m, c[i][0]);
for(int i = 0; i < n; i++)a[i] = c[i][0] - m;
for(int i = 0; i < n; i++)b[i] = c[0][i] - a[0];
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
if(c[i][j] != a[i] + b[j]){
cout << "No" << endl;
return 0;
}
}
}
cout << "Yes" << endl;
for(int i = 0; i < n; i++)cout << a[i] << " ";
cout << endl;
for(int i = 0; i < n; i++)cout << b[i] << " ";
cout << endl;
return 0;
}
|
#include <iostream>
#include <vector>
//#include <string>
//#include <algorithm>
//#include <math.h>
#include <queue>
//#include <stack>
#include <iomanip>
// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>
typedef long long LL;
typedef long double LD;
using namespace std;
//#define MOD 1000000007
//#define MOD 998244353
//#define MAX 200100
//#define NIL -1
//#define INFTY 1000000000000000000
vector<vector<vector<LD>>> abc(101, vector<vector<LD>>(101, vector<LD>(101, 0)));
vector<vector<vector<bool>>> is_visit(101, vector<vector<bool>>(101, vector<bool>(101, false)));
void bfs(pair<LL, pair<LL, LL>> s){
queue<pair<LL, pair<LL, LL>>> q;
q.push(s);
pair<LL, pair<LL, LL>> u;
while(!q.empty()){
u=q.front();
q.pop();
LL a=u.first;
LL b=u.second.first;
LL c=u.second.second;
//cout << a << " " << b << " " << c << endl;
if(a!=0){
abc[a+1][b][c]+=abc[a][b][c]*a/(a+b+c);
//cout << a+1 << " " << b << " " << c << endl;
if(a+1<100 && is_visit[a+1][b][c]==false){
is_visit[a+1][b][c]=true;
q.push(make_pair(a+1, make_pair(b,c)));
}
}
if(b!=0){
abc[a][b+1][c]+=abc[a][b][c]*b/(a+b+c);
if(b+1<100 && is_visit[a][b+1][c]==false){
is_visit[a][b+1][c]=true;
q.push(make_pair(a, make_pair(b+1,c)));
}
}
if(c!=0){
abc[a][b][c+1]+=abc[a][b][c]*c/(a+b+c);
//cout << abc[a][b][c] << " " << abc[a][b][c+1] << endl;
if(c+1<100 && is_visit[a][b][c+1]==false){
is_visit[a][b][c+1]=true;
q.push(make_pair(a, make_pair(b,c+1)));
}
}
}
}
int main(){
LL a;
LL b;
LL c;
cin >> a >> b >> c;
abc[a][b][c]=1;
is_visit[a][b][c]=true;
bfs(make_pair(a, make_pair(b, c)));
LD ans=0;
for(LL i=0; i<100; i++){
for(LL j=0; j<100; j++){
if(i<b || j<c){
continue;
}
ans+=abc[100][i][j]*(LD)(100+i+j-a-b-c);
}
}
for(LL i=0; i<100; i++){
for(LL j=0; j<100; j++){
if(i<a || j<c){
continue;
}
ans+=abc[i][100][j]*(LD)(100+i+j-a-b-c);
}
}
for(LL i=0; i<100; i++){
for(LL j=0; j<100; j++){
if(i<a || j<b){
continue;
}
ans+=abc[i][j][100]*(LD)(100+i+j-a-b-c);
}
}
cout << setprecision(12) << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define pi 3.14159265358979323846
const ll INF=1e18;
const ll N=2e5+5;
const ll MOD=1e9+7;
using namespace std;
double dp[105][105][105];
ll POWER(ll base,ll expo)
{
ll ret=1;
while(expo)
{
if(expo&1)ret=ret*base;
expo>>=1;
base=base*base;
}
return ret;
}
ld fun(ll a,ll b,ll c)
{
if(a==100 || b==100 || c==100)
return 0;
if(dp[a][b][c]!=-1)return dp[a][b][c];
double tot=a+b+c;
double ans=1+(a/tot)*fun(a+1,b,c)+(b/tot)*fun(a,b+1,c)+(c/tot)*(fun(a,b,c+1));
return dp[a][b][c]=ans;
}
int main()
{
ll test_case=1; //cin>>test_case;
while(test_case--)
{
ll a,b,c;
for(ll i=0;i<=100;i++){
for(ll j=0;j<=100;j++){
for(ll k=0;k<=100;k++)
dp[i][j][k]=-1;
}
}
cin>>a>>b>>c;
double ans=fun(a,b,c);
cout<<fixed<<setprecision(12)<<ans;
}
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e9;
#define mod 1000000007
#define what_is(x) cerr<<#x<<" is "<<x<<"\n";
#define read(x) freopen("in.txt","r",stdin);
#define write(x) freopen("out.txt","w",stdout);
#define Fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define sz 3000005
int main(){
Fast;///using Fast I/O
vector < ll > v;
ll a,b,c, i,j,k, t,n,m, x, y;
cin>>x>>y>>a>>b;
i=x;
v.push_back(x);
while((double)i*a<y){
v.push_back(i*a);
i=i*a;
}
ll ans=0, exp;
for(i=0; i<v.size(); i++){
exp=i+(y-v[i]-1)/b;
ans=max(ans, exp);
}
cout<<ans<<endl;
return 0;
}
| #include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;
bool check(ll a, ll b, ll c, ll d){
return a+b == c+d || a-b == c-d || abs(a-c) + abs(b-d) <= 3;
}
int ddx[4] = {3, 0, -3, 0};
int ddy[4] = {0, -3, 0, 3};
int main(){
ll a, b,c,d;
cin >>a >>b >> c >> d;
int ans = 3;
{
if((a+b) % 2 == (c + d) % 2)ans = 2;
for(int dy = -2; dy <= 2; ++dy){
for(int dx = -2; dx <= 2; ++dx){
int na = dx+a, nb = dy+b;
if(check(na, nb, c, d))ans = 2;
}
}
rep(i,4){
int na = ddx[i] + a, nb = ddy[i] + b;
if(check(na, nb, c, d))ans = 2;
}
//
for(int dy = -2; dy <= 2; ++dy){
for(int dx = -2; dx <= 2; ++dx){
int nc = dx+c, nd = dy+d;
if(check(a, b, nc, nd))ans = 2;
}
}
rep(i,4){
int nc = ddx[i] + c, nd = ddy[i] + d;
if(check(a, b, nc, nd))ans = 2;
}
}
if(check(a, b, c, d))ans = 1;
if(a == c && b == d)ans = 0;
cout << ans << endl;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define length size()
#define int long long
#define ll long long
#include <cstdint>
long long modpow(long long a, long long n, long long mod) {
long long res = 1;
while (n > 0) {
if (n & 1) res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
const int MOD = 1000000007;
const int mod = 1000000007;
const int MAX = 510000;
const double inf = 900719925474099;
template<typename T> string join(vector<T> &vec ,const string &sp){
int si = vec.length;
if(si==0){
return "";
}else{
stringstream ss;
rep(i,si-1){
ss << vec[i] << sp;
}
ss << vec[si - 1];
return ss.str();
}
}
vector<vector<int>> ruiseki2d(vector<vector<int>> vec){
rep(i,vec.size()-1){
rep(j,vec[0].size()-1){
vec[i+1][j+1] = vec[i][j+1]+vec[i+1][j]-vec[i][j]+vec[i+1][j+1];
}
}
return vec;
}
vector<int> ruiseki(vector<int> vec){
rep(i,vec.size()-1){
vec[i+1] += vec[i];
}
return vec;
}
signed main(void){
int a,b;
cin >> a >> b;
bool flag = false;
for(int i=1;sqrt(b)>=i;i++){
if(b%i!=0) continue;
if((i+(b/i))==a){
flag = true;
}
}
cout << ((flag)?"Yes":"No") << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int64_t S, P;
cin >> S >> P;
for (int64_t N = 1; N * N <= P; N++) {
if (P % N != 0) {
continue;
}
int64_t M = P / N;
if (N + M == S) {
cout << "Yes" << endl;
return 0;
}
}
cout << "No" << endl;
} |
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <complex>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#include <queue>
#define INF 1010101010LL
#define INFLL 1010101010101010101LL
using namespace std;
int mod = 1000000007;
//int mod = 998244353;
class BIT {
public:
BIT(int n) : a(n) {}
void add(int p, long long num)
{
while (p < a.size()) {
a[p] += num;
p |= p + 1;
}
}
/* i から j までの和 [i, j] */
long long sum(int i, int j)
{
long long s = 0, t = 0;
i--;
while (i >= 0) {
s += a[i];
i = (i & (i + 1)) - 1;
}
while (j >= 0) {
t += a[j];
j = (j & (j + 1)) - 1;
}
return t - s;
}
void print()
{
for (int i = 0; i < a.size(); i++) {
cout << a[i] << endl;
}
}
private:
vector<long long> a;
};
int main()
{
int n;
cin >> n;
vector<int> a(n);
vector<long long> b(n), c(n), d(n), e(n);
BIT bit(n);
long long t = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
b[i] = bit.sum(a[i] + 1, n - 1);
d[i] = n - b[i] - 1;
t += b[i];
bit.add(a[i], 1);
}
BIT bit1(n);
for (int i = n - 1; i >= 0; i--) {
c[i] = bit1.sum(a[i] + 1, n - 1);
e[i] = n - c[i] - 1;
bit1.add(a[i], 1);
}
for (int i = 0; i < n; i++) {
cout << t << endl;
t -= a[i];
t += n - 1 - a[i];
}
return 0;
} | #include<iostream>
#include<math.h>
#include<bits/stdc++.h>
#include<cmath>
#define ll long long int
#define hell 1000000007LL
using namespace std;
ll power(ll x, ll y,ll z){
if(y==0)
return 1;
else
{
ll p=power(x,y/2,z);
ll w=(p*p)%z;
if(y%2==0)
return w;
else
return (x*w)%z;
}}
ll gcd(ll x,ll y)
{
if(y==0)
return x;
else
return gcd(y,x%y);}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.precision(20);
ll n;
cin>>n;
ll a[200]={0},c=0;
for(int i=0;i<n;i++)
{
ll x;
cin>>x;
a[x%200]++;
}
for(int i=0;i<200;i++)
{
c=c+(a[i]*a[i]-a[i])/2;
}
cout<<c;} |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ford(i,a,b) for(int i=a;i<=b;i++)
#define foru(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,a,b) for(int i=a;i<b;i++)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define bug(x) cout<<x<<'\n';
#define bit(x,i) ((x>>i)&1ll)
int n,x,kq=0;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cin>>n;
ford(i,1,n){
cin>>x;
if(x>10) kq+=(x-10);
}
cout<<kq;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ll mod2 = 998244353;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n, k; cin >> n >> k;
vector<int> A(n);
map<int, int> cnt;
rep(i, n) {
cin >> A[i];
cnt[A[i]]++;
}
int mn = k;
ll ans = 0;
rep(i, n) {
ans += 1LL * (mn - min(mn, cnt[i])) * i;
chmin(mn, cnt[i]);
}
ans += mn * n;
cout << ans << endk;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i, n) for(int i = 0; i < n; i++)
int n,m;
vector<int> G[20];
bool used[20];
int col[20];
vector<int> vs;
void dfs(int v)
{
if(used[v])return;
used[v]=true;
vs.push_back(v);
for(int u:G[v])dfs(u);
}
ll now;
void dfs2(int i)
{
if(i==vs.size()){
now++;
return;
}
int v = vs[i];
rep(c,3){
col[v] = c;
bool ok = true;
for(int u:G[v]){
if(col[u]==c)ok=false;
}
if(!ok)continue;
dfs2(i+1);
}
col[v]=-1;
}
int main()
{
cin >> n >> m;
rep(i,m){
int a,b;
cin >> a >> b;
a--;b--;
G[a].push_back(b);
G[b].push_back(a);
}
ll ans = 1;
memset(col,-1,sizeof(col));
rep(i,n){
if(used[i])continue;
ans*=3;
vs = vector<int>();
dfs(i);
col[vs[0]]=0;
now=0;
dfs2(1);
ans*=now;
}
cout << ans << endl;
return 0;
} | //----------BHAVIK DIWANI(PICT_COMP)---------------
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define test ll t; cin>>t; while(t--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define ll long long
#define int long long
#define ull unsigned long long
#define MAX 1000005
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define endl '\n'
#define vs vector<string>
#define mii map<int,int>
#define msi map<string,int>
#define vpii vector< pair<int, int > >
#define vpsi vector< pair< string ,int > >
#define forci(p,q) for(int i=p;i<q;i++)
#define rep(i,n) for(int i=0;i<n;i++)
ll gcd(ll a,ll b){ if(b==0) return a; return gcd(b,a%b);}
ll lcm(ll a,ll b) { return (a/gcd(a,b)*b);}
ull power(ull a, ull b) {a %= mod; ull res = 1; while (b > 0) { if (b & 1) res = res * a % mod; a = a * a % mod; b >>= 1; } return res%mod; }
ll modmul(ll x, ll y){return (x*y)%mod;}
ll modadd(ll x, ll y){return (x+y)%mod;}
ll modsub(ll x, ll y){return (x-y+mod)%mod;}
ll fact[1000007]={0};
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<1000007;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[r],mod-2)))%mod; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
inline long long toint(const std::string &s) {std::stringstream ss; ss << s; long long x; ss >> x; return x;}
inline std::string tostring(long long number) {std::stringstream ss; ss << number; return ss.str();}
inline std::string tobin(long long x) {return std::bitset<63>(x).to_string();}
const int inf=1e9;
/*bool prime[MAX];
ull sieve(){memset(prime,true,sizeof(prime));for(ull p=2;p*p<MAX;p++){if(prime[p]==true){for(ull i=2*p;i<MAX;i+=p){prime[i]=false;}}}prime[0]=0;prime[1]=0;
}*/
/*
int inv[1000001]={0};int invf[1000001]={0};
void findinverse(){
inv[0]=1;
inv[1] = 1;
for(int i = 2; i <=1e6 ; ++i)
inv[i] = (mod - (mod/i) * inv[mod%i] % mod) % mod;
invf[0]=1;invf[1]=1;
for(int i=2;i<=1e6;i++){
invf[i]=invf[i-1]*inv[i]%mod;
}
}*/
using namespace std;
const int N=25;
int n,m;
vi adj[N];
vector<bool>vis(N,false);
vi g,color;
void dfs(int s){
vis[s]=true;
for(auto i:adj[s]){
if(!vis[i])
dfs(i);
}
g.pb(s);
}
int cnt(int idx){
if(idx==g.size())
return 1;
int s=g[idx];
int res=0;
for(int c=0;c<3;c++){
bool ok=true;
for(auto i:adj[s]){
if(c==color[i])
ok=false;
}
if(ok){
color[s]=c;
res+=cnt(idx+1);
color[s]=-1;
}
}
return res;
}
int solve()
{
bool flag=true;
cin>>n>>m;
color.resize(n+1,-1);
for(int i=0;i<m;i++){
int x,y;
cin>>x>>y;
adj[x].pb(y);
adj[y].pb(x);
}
int sum=1LL;
for(int i=1;i<=n;i++){
if(!vis[i]){
g.clear();
dfs(i);
reverse(g.begin(),g.end());
int ans=cnt(0);
sum*=ans;
}
}
cout<<sum<<endl;
return 0;
}
signed main()
{
fastio;
// test
solve();
} |
//----AUTHOR:kkdrummer----/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unordered_set<ll> usll;
typedef unordered_multiset<ll> umsll;
typedef multiset<ll> msll;
typedef set<ll> sll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef priority_queue<ll> pqll;
typedef vector<int> vi;
typedef set<int> si;
typedef multiset<int> msi;
typedef unordered_multiset<int> umsi;
typedef unordered_set<int> usi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef priority_queue<int> pqi;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ind_si;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ind_sll;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> ind_msi;
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> ind_msll;
#define in insert
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define be begin
#define en end
#define itr iterator
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mo 1000000007
#define inf 8222372026854775807
#define ninf -inf
#define ima 2047483647
#define imi -ima
#define oncnt __builtin_popcount
#define zerobegin __builtin_clz
#define zeroend __builtin_ctz
#define parity __builtin_parity
#define eps 1e-9
#define coutd cout<<setprecision(10)<<fixed
#define mems(dp,x) memset(dp,x,sizeof(dp))
#define fbo find_by_order
#define ook order_of_key
#define all(x) x.be(),x.en()
#define upb upper_bound
#define lowb lower_bound
#define lte(v,x) (upb(all(v),x)-v.be())
#define gte(v,x) (v.end()-lowb(all(v),x))
#define gt(v,x) (v.en()-upb(all(v),x))
#define lt(v,x) (lowb(all(v),x)-v.be())
const ld PI= 3.1415926535897932384626433832792884197169399375105820974944;
inline ll mpow(ll x,ll n){if(n==0)return 1;if(x==0)return 0;if(n==1)return(x%mo);ll u=(mpow(x,n/2));u=(u*u)%mo;if(n%2!=0)u=(u*x%mo)%mo;return u;}
inline ll minv(ll x){return mpow(x,mo-2);}
inline ll mmul(ll a,ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);}
inline ll madd(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a+b>=mo)return(a+b)%mo;return(a+b);}
inline ll msub(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;return(((a-b)%mo+mo)%mo);}
inline ll mdiv(ll a,ll bb){if(a>=mo)a=a%mo;ll b=minv(bb);if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);}
inline ll gcd(ll a,ll b){return __gcd(a,b);}
inline ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}
int main()
{ io
int testcases=1; // cin>>testcases;
while(testcases--)
{
ld a,b;
cin>>a>>b;
coutd<<((a-b)/a)*100.00;
}return 0;} | #include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, k, n) for (int i = k; i < (int)(n); i++)
#define repd(i, n) for (int i = n-1; i >= 0; i--)
#define rrepd(i, k, n) for (int i = n-1; i >= (int)(k); i--)
#define all(x) (x).begin(),(x).end()
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
//V,Pは大文字i,l,bは小文字
using ll = long long;
using Vi = vector<int>;
using VVi = vector<Vi>;
using Vl = vector<ll>;
using VVl = vector<Vl>;
using Vb = vector<bool>;
using VVb = vector<Vb>;
using P = pair<int,int>;
using Pl = pair<ll, ll>;
using Vs = vector<string>;
const ll mod = 1000000007;
const ll inf = 1000000000000000000;//10の18乗
#define yn {puts("Yes");}else{puts("No");}
#define dame { puts("-1"); return 0;}
int main() {
ll n,m,q;
cin >> n >> m >> q;
vector<Pl> v(n);
rep(i,n) cin >> v[i].F >> v[i].S;
sort(all(v));
v.PB(MP(inf,inf));
Vl box(m);
rep(i,m) cin >> box[i];
rep(i,q){
ll ans=0;
ll l,r;
cin >> l >> r;
l--;r--;
Vl ok;
rep(j,l) ok.PB(box[j]);
rrep(j,r+1,m) ok.PB(box[j]);
sort(all(ok));
priority_queue<ll> que;
ll now=0;
//cout << ok.size() << l << r << endl;
rep(j,ok.size()){
while(v[now].F<=ok[j]){
que.push(v[now].S);
now++;
}
if(!que.empty()){
ll x=que.top();que.pop();
ans+=x;
}
//cout << ans << endl;
}
cout << ans << endl;
}
}
|
#include <string>
#include <iostream>
#include <stack>
#include <queue> // priority_queue も入ってる
#include <set> // 要素数は size() で取得 multisetもある
#include <map>
#include <array> // sizeはコンパイル時定数で固定
#include <vector>
#include <numeric> // accumulate, gcd
#include <algorithm> // count_ifに必要
#include <iomanip> // cout << setprecision(15) << x で小数の出力精度を指定
#include <tuple>
#include <utility> //pair
#include <cmath>
#include <random>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); ++i)
int main()
{
ll n;
cin >> n;
vector<ll> a(n);
vector<ll> b(n);
rep(i, n)
{
ll tempA;
ll tempB;
cin >> tempA >> tempB;
tempA--;
tempB--;
// a<=b となるように並べます→いみない!!!
if (tempA <= tempB)
{
a[i] = tempA;
b[i] = tempB;
}
else
{
a[i] = tempB;
b[i] = tempA;
}
}
ll aMax = 0;
ll bMax = 0;
rep(i, n)
{
aMax = max(aMax, a[i]);
bMax = max(bMax, b[i]);
}
ll colorKinds = max(aMax, bMax) + 1;
vector<vector<ll>> targets(colorKinds);
rep(i, n)
{
targets[a[i]].push_back(b[i]);
targets[b[i]].push_back(a[i]);
}
ll result = 0;
vector<bool> doneColor(colorKinds, false);
for (ll color = 0; color < colorKinds; color++)
{
if (doneColor[color] == true)
{
}
else
{
queue<ll> que;
que.push(color);
ll islandMembers = 0;
ll kyohi = 0;
while (!que.empty())
{
ll nowColor = que.front();
que.pop();
if (doneColor[nowColor] == false)
{
doneColor[nowColor] = true;
islandMembers++;
for (ll target : targets[nowColor])
{
que.push(target);
}
}
else
{
// その頂点は調査済みだった場合
kyohi++;
}
}
if (kyohi == islandMembers - 1)
{
// loopなし
result += islandMembers - 1;
}
else
{
// loopあり
result += islandMembers;
}
}
}
cout << result << endl;
return 0;
} | #include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <iostream>
#include <fstream>
#include <chrono>
using namespace std;
void solve(int test, istream &in) {
int n; string s;
in >> n >> s;
vector<int> a(n + 1);
int maxa = 0;
for (int i = 0; i <= n; i++) {
in >> a[i];
maxa = std::max(maxa, a[i]);
}
int maxk = 1;
vector<int> b(n + 1), cnt(n + 1);
for (int k = 2; k <= maxa; k++) {
for (int i = 0; i <= n; i++) {
b[i] = a[i] / k;
cnt[i] = a[i] % k;
}
bool good = true;
for (int i = 0; i < n; i++) {
int l0 = b[i], l1 = b[i + 1];
int r0 = b[i], r1 = b[i + 1];
if (cnt[i] > cnt[i + 1])
r0++;
else if (cnt[i] < cnt[i + 1])
r1++;
if (s[i] == '>') {
std::swap(l0, l1);
std::swap(r0, r1);
}
if (l0 >= l1 || r0 >= r1)
good = false;
}
if (good)
maxk = k;
}
for (int i = 0; i <= n; i++) {
b[i] = a[i] / maxk;
cnt[i] = a[i] % maxk;
}
printf("%d\n", maxk);
for (int k = 0; k < maxk; k++) {
for (int i = 0; i <= n; i++) {
printf("%d ", k < cnt[i] ? b[i] + 1 : b[i]);
}
printf("\n");
}
}
int main(int argc, char* argv[])
{
#ifdef VLAD_LOCAL
//FILE *f = fopen("in.txt", "r");
ifstream f("in.txt");
auto start = std::chrono::steady_clock::now();
#else
//FILE *f = stdin;
istream &f = cin;
#endif
int tests = 1;
//f >> tests;
for (int test = 0; test < tests; test++) {
solve(test, f);
}
#ifdef VLAD_LOCAL
auto end = std::chrono::steady_clock::now();
double seconds = (double)std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() / 1000;
printf("\n%.3lf seconds\n", seconds);
#endif
return 0;
}
|
// .------------------------------------------------------------.
// | K U S A Y A R O U |
// | |
// | ---|---|--- ___ ____ _\_ ___ |
// | _______ |_|_| / |___| | / |
// | |_______| |_|_| \ |___| | / |
// | |_______| | _____ | | \ |
// | _____|_____ __|__ | / | \ | __\ |
// | | | | | / \ | |
// | | __|__ \| |/ | |
// | |
// |------------------------------------------------------------|
// | .------------. |
// | | KerakTelor | |
// | |------------| |
// | | 2020-07-21 | |
// | '------------' |
// '------------------------------------------------------------'
#include <bits/stdc++.h>
#define DEBUG(...)
// #pragma GCC optimize("O2,unroll-loops")
// #pragma GCC target("tune=native")
#define fi first
#define se second
using namespace std;
using ll = long long;
using ld = long double;
template<class T>
using vec = vector<T>;
template<class T>
using v2d = vector<vector<T>>;
template<class T>
using prq = priority_queue<T>;
template<class T>
using rpq = priority_queue<T, vector<T>, greater<T>>;
int n;
v2d<ld> dp;
ld solve(int on)
{
if(on == n)
{
return 0;
}
int off = n - on;
return (ld) n / off * ((ld) off / n * solve(on + 1) + 1);
}
int main()
{
scanf("%d", &n);
printf("%.12Lf\n", solve(1));
}
| #include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define U 998244353
#define N 1000005
#define int long long
#define sz(c) (int)c.size()
#define fr first
#define ll long long
#define sc second
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a ; i<n ; i++)
#define r0 return 0;
#define endl '\n'
#define INF (int)1e15
/* Debug Begins */
# define trace(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
string to_string(char c) { return "'" + string(1, c) + "'";}
string to_string(string s) { return '"' + s + '"';}
string to_string(bool f) { if(f) return "True"; else return "False";}
string to_string(const char* s) { return to_string((string) s);}
template<typename A> string to_string(A);
template<typename A, typename B> string to_string(pair<A, B> p){
return "(" + to_string(p.first) + ": " + to_string(p.second) + ")";}
template<typename A> string to_string(A v) {bool f = false; string r = "{";
for (auto x: v) {if (f) r += ", "; r += to_string(x); f = true;} return r += "}";}
template<typename A> string to_string(vector<vector<A>> v) {string r;
for (auto x: v) r += "\n" + to_string(x); return r;}
int Nerr;
template<typename A> string to_string(A *p) {return to_string(vector<A>(p, p + Nerr));}
void err(istream_iterator<string>) { cerr << endl; }
template<typename T,typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << to_string(a) << "; "; err(++it, args...); }
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
#define Lu(...) [&] (auto &&u) { return __VA_ARGS__; }
#define Luv(...) [&] (auto &&u, auto &&v) { return __VA_ARGS__; }
/***************************************************************/
bool sortbysec(const pair<int,int> &a,
const pair<int,int> &b)
{
return (a.second < b.second);
}
signed main()
{
ios_base::sync_with_stdio(0);
int TESTS=1;
// cin>>TESTS;
while(TESTS--)
{
double ans = 0;
int n;
cin >> n;
rep(i,1,n) ans += n*1.0/i;
cout << fixed << setprecision(10) << ans << endl;
}
} |
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
// using cint = cpp_int;
#define fastio \
std::cin.tie(nullptr); \
std::ios::sync_with_stdio(false);
using ll = long long;
using ld = long double;
#define For(i, m, n) for(int i = (m); (i) < (n); ++(i))
#define Rep(i, n) For(i, 0, n)
#define Each(e, con) for(auto e: con)
#define rEach(e, con) for(auto &e: con)
#define crEach(e, con) for(const auto &e: con)
#define All(con) (con).begin(), (con).end()
#define Unique(con) std::sort(All(con)); (con).erase(std::unique(All(con)), (con).end())
#define Reverse(con) std::reverse(All(con))
#define Middle(con) (con).begin() + ((con).end() - (con).begin()) / 2
template <class Ty1, class Ty2>
std::istream &operator>>(std::istream &is, std::pair<Ty1, Ty2> &arg)
{ is >> arg.first >> arg.second; return is; }
template <class Ty>
std::istream &operator>>(std::istream &is, std::vector<Ty> &arg)
{ rEach(e, arg) is >> e; return is; }
template <class Ty>
std::istream &operator>>(std::istream &is, std::vector<std::vector<Ty>> &arg)
{ rEach(sub, arg) { rEach(e, sub) { is >> e; }} return is; }
template <class Ty1, class Ty2>
std::istream &vecinput(std::vector<Ty1> &arg1, std::vector<Ty2> &arg2)
{ assert(arg1.size() == arg2.size());
auto sz = arg1.size(); Rep(i, (int)sz) std::cin >> arg1[i] >> arg2[i]; return std::cin; }
template <class Ty1, class Ty2, class Ty3>
std::istream &vecinput(std::vector<Ty1> &arg1, std::vector<Ty2> &arg2, std::vector<Ty3> &arg3)
{ assert(arg1.size() == arg2.size()); assert(arg2.size() == arg3.size());
auto sz = arg1.size(); Rep(i, (int)sz) std::cin >> arg1[i] >> arg2[i] >> arg3[i]; return std::cin; }
template <class Ty1, class Ty2, class Ty3, class Ty4>
std::istream &vecinput(std::vector<Ty1> &arg1, std::vector<Ty2> &arg2, std::vector<Ty3> &arg3, std::vector<Ty4> &arg4)
{ assert(arg1.size() == arg2.size()); assert(arg2.size() == arg3.size()); assert(arg3.size() == arg4.size());
auto sz = arg1.size(); Rep(i, (int)sz) std::cin >> arg1[i] >> arg2[i] >> arg3[i] >> arg4[i]; return std::cin; }
int main() {
fastio
int r, x, y;
cin >> r >> x >> y;
double dist = hypot(x, y);
int ans = 0;
while(dist > 2 * r) {
dist -= r;
++ans;
}
if(abs(dist - r) < 1e-9) cout << ans + 1 << endl;
else cout << ans + 2 << endl;
return 0;
} | #include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#define ll long long
using namespace std;
int main(){
ll n,a,b,c;
scanf("%lld%lld%lld",&n,&a,&b);
c=(ll)(sqrt(a*a+b*b));
if(c*c==a*a+b*b){
if(c==n)puts("1");
else if(c==0)puts("0");
else printf("%lld\n",max(2LL,(c+n-1)/n));
return 0;
}
++c;
printf("%lld\n",max(2LL,(c+n-1)/n));
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 5LL << 60;
const ll mod = 1e9 + 7;
int main(void) {
int N;
cin >> N;
int A[N], B[N], C[N];
for(int i = 0; i < N; i++) cin >> A[i];
for(int i = 0; i < N; i++) cin >> B[i];
for(int i = 0; i < N; i++) {
cin >> C[i];
C[i]--;
}
int cnt[100010];
for(int i = 0; i < 100010; i++) cnt[i] = 0;
for(int i = 0; i < N; i++) cnt[A[i]]++;
ll ans = 0;
for(int i = 0; i < N; i++) {
ans += cnt[B[C[i]]];
}
cout << ans << "\n";
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define fora(i, x, n) for(int i=(x); i<(n) ; ++i)
#define trav(a, A) for(auto& a : A)
#define endl '\n'
#define ford(i, x) for(int i=(x); i>=0 ; --i)
#define all(v) v.begin(), v.end()
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define INF ((long long int) ((unsigned long long int)~0>>1))
using li = long long int;
using vi = vector<int>;
unordered_map<int,int> freq_colors;
vi color;
vector<vi> tree;
vi good_vertex;
void dfs(int u, int parent = 0){
freq_colors[color[u]]++;
if ( freq_colors[color[u]] == 1 ){
good_vertex.pb(u);
}
for(auto v : tree[u]){
if (v == parent) continue;
dfs(v, u);
}
freq_colors[color[u]]--;
}
void solve(){
int n;
cin >>n;
color.resize(n);
tree.resize(n);
for(auto& c : color){
cin >> c;
}
int a, b;
fora(i, 0, n-1){
cin >> a >> b; a--; b--;
tree[a].pb(b);
tree[b].pb(a);
}
dfs(0, 0);
sort(all(good_vertex));
for(auto& v : good_vertex){
cout << v+1 << endl;
}
}
int main(void){
ios_base::sync_with_stdio(false); cin.tie(nullptr);
solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef string str;
#define all(x) (x).begin(),(x).end()
#define Sort(x) sort(all((x)))
#define X first
#define Y second
#define Mp make_pair
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define sep ' '
#define endl '\n'
#define debug(x) cerr << #x << " = " << x << endl
#define SZ(x) ll(x.size())
#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const ll MAXN = 1e3 + 10;
const ll INF = 1e18;
const ll LOG = 20;
const ll MOD = 1e9 + 7;
ll poww(ll a, ll b, ll md, ll ans = 1) {
for (; b; b >>= 1, a = a * a % md)
if (b & 1) ans = ans * a % md;
return ans;
}
ll fib[MAXN] , c[4];
int main(){
fast_io;
fib[1] = fib[2] = 1;
for (int i = 3; i < MAXN; i++){
fib[i] = (fib[i - 1] + fib[i - 2]) % MOD;
}
ll n;
cin >> n;
for (int i = 0; i < 4; ++ i){
char ch;
cin >> ch;
c[i] = ch - 'A';
}
if (n < 4){
cout << 1;
return 0;
}
if (!c[1]){
if (!c[0]){
cout << 1;
return 0;
}
if (!c[2]){
cout << fib[n - 1];
return 0;
}
cout << poww(2, n - 3, MOD);
return 0;
}
if (c[3]){
cout << 1;
return 0;
}
if (c[2]){
cout << fib[n - 1];
return 0;
}
cout << poww(2, n - 3, MOD);
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MAXM = 1e4 + 5;
#define pb push_back
#define eb emplace_back
#define w(x) \
int x; \
cin >> x; \
while (x--)
#define mod 1000000007
#define MAX 1e9
#define MIN -1e9
#define LINF 9223372036854775807
#define LMIN -9223372036854775807
#define mp make_pair
#define tiii tuple<int, int, int>
#define tlll tuple<ll, ll, ll>
#define mid(s, e) (s + (e - s) / 2)
#define F first
#define z endl
#define S second
#define for0(i, n) for (int i = 0; i < (int)(n); ++i) // 0 based indexing
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i) // 1 based indexing
#define forc(i, l, r) for (int i = (int)(l); i <= (int)(r); ++i) // closed interver from l to r r inclusive
#define forr0(i, n) for (int i = (int)(n)-1; i >= 0; --i) // reverse 0 based.
#define forr1(i, n) for (int i = (int)(n); i >= 1; --i) // reverse 1 based
#define all(x) (x).begin(), (x).end() //Forward traversal
#define rall(x) (x).rbegin, (x).rend() //reverse traversal
// find if a given value is present in a container. Container version. Runs in log(n) for set and map
#define pll pair<long long, long long>
#define present(c, x) ((c).find(x) != (c).end())
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, pair<int, int>> ppi;
typedef double ld;
//std::rotate(vec1.begin(), vec1.begin()+rotL, vec1.end()) Rotate vector left rotL times. in Theta(n)
// std::rotate(vec2.begin(), vec2.begin()+vec2.size()-rotR, vec2.end()); Rotate vector Right rotR times. int Theta(n)
class compare
{
public:
bool operator()(const pair<int, int> &a, const pair<int, int> &b)
{
if (a.first == b.first)
return a.second > b.second;
return a.first < b.first;
}
};
bool isprime(int n)
{
if (n == 1)
return false;
for (int i = 2; i * i <= n; i++)
{
if (n % i == 0)
return false;
}
return true;
}
int lcm(int a, int b)
{
return (a * b) / __gcd(a, b);
}
int gcd(int a, int b)
{
if (b == 0)
{
return a;
}
return gcd(b, a % b);
}
int countDigits(int n)
{
return floor(log10(n) + 1);
}
int main()
{
// auto start = chrono::high_resolution_clock::now();
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
if (n == 1)
cout << 1 << endl;
else
{
int count = 1;
int x = 0;
while (x < n)
{
x += count;
count++;
}
cout << count - 1 << endl;
}
// auto end = chrono::high_resolution_clock::now();
// double time_taken =
// chrono::duration_cast<chrono::nanoseconds>(end - start).count();
// time_taken *= 1e-9;
// cout << "Time taken by program is : " << fixed
// << time_taken << setprecision(9);
// cout << " sec" << endl;
return 0;
} |
#include<bits/stdc++.h>
#define ll long long
using namespace std;
void readFile(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
int main(){
readFile();
ios::sync_with_stdio(false);
cin.tie(NULL);
ll n, x;
cin >> n >> x;
vector<ll> ans;
for(ll i = 0 ; i < n ; ++i){
ll val;
cin >> val;
if(val != x) ans.push_back(val);
}
for(ll i : ans) cout << i << ' ';
cout << '\n';
} | #include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <functional>
#include <bitset>
#include <limits>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <random>
#ifdef DEBUG
#include "library/Utility/debug.cpp"
#else
#define debug(...)
#endif
#define rep(i,n) for(int i=0;i<(n);++i)
#define EL '\n'
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using lnt = long long;
struct FIO{FIO(){std::cin.tie(0);std::ios_base::sync_with_stdio(0);std::cout<<std::fixed<<std::setprecision(15);}}fIO;
template<typename T> using V = std::vector<T>;
template<typename T> void fill(V<T>&v) { for(T&e:v) std::cin >> e; }
/*-*/
int main() {
int h,w;
std::cin >> h >> w;
int n=h*w;
V<int> a(n);
fill(a);
int min=a[0];
rep(i,n) min=std::min(min,a[i]);
lnt ans=0;
rep(i,n) ans+=a[i]-min;
print(ans);
}
|
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <string>
#include <map>
#include <set>
#include <cstdio>
#include <numeric>
#include <iomanip>
using namespace std;
using ll = long long;
vector<ll> A;
ll calc(ll N, ll sep)
{
ll ret = 0;
//vector<ll> v;
ll OR = 0;
bool f = false;
for(ll i = 0;i < N;i++)
{
OR |= A[i];
f = true;
if(sep & (1LL<<i))
{
ret ^= OR;
OR = 0LL;
f = false;
}
}
if(f)
{
ret ^= OR;
}
return ret;
}
int main()
{
ll N;
cin >> N;
A.resize(N);
for(ll i = 0;i < N;i++)
{
cin >> A[i];
}
ll sep;
ll lim = 1<<(N-1LL);
ll ans = 1e15;
for(sep=0;sep<lim;sep++)
{
ll ret = calc(N, sep);
//cout << "ret = " << ret << " sep = " << sep << endl;
ans = min(ans, ret);
}
cout << ans << endl;
return 0;
} | // Problem: B - Mex Boxes
// Contest: AtCoder - KEYENCE Programming Contest 2021
// URL: https://atcoder.jp/contests/keyence2021/tasks/keyence2021_b
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)
// Problem: A - Two Sequences 2
// Contest: AtCoder - KEYENCE Programming Contest 2021
// URL: https://atcoder.jp/contests/keyence2021/tasks/keyence2021_a
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include <bits/stdc++.h>
#define int long long
using namespace std;
#ifndef use_ios11
#define use_ios11
using namespace std;
struct ins{
int ans;
ins(){ans=1;}
#define endl '\n'
void read(){}
void read1(char &s){
char c=getchar();
for(;!isprint(c)||c==' '||c=='\n'||c=='\t';c=getchar());
s=c;
if(c==EOF)ans=0;
}
void read1(string &s){
s="";
char c=getchar();
for(;!isprint(c)||c==' '||c=='\n'||c=='\t';c=getchar());
for (;isprint(c)&&c!=' '&&c!='\n'&&c!='\t';c=getchar())s+=c;
if(c==EOF)ans=0;
}
template<typename T>void read1(T &n){
T x=0;int f=1;char c=getchar();
for(;!isdigit(c);c=getchar()){
if(c=='-')f=-1;
if(c==EOF){ans=0;return;}
}
for(;isdigit(c);c=getchar())x=x*10+c-48;
n=x*f;
if(c==EOF)ans=0;
if(c!='.')return;
T l=0.1;
while((c=getchar())<='9'&&c>='0')x=x+(c&15)*l,l*=0.1;
n=x*f;
if(c==EOF)ans=0;
}
void write(){}
void write1(string s){
int n=s.size();
for(int i=0;i<n;i++)putchar(s[i]);
}
void write1(const char *s){
int n=strlen(s);
for(int i=0;i<n;i++)putchar(s[i]);
}
void write1(char s){putchar(s);}
void write1(float s,int x=6){
char y[10001];
sprintf(y,"%%.%df",x);
printf(y,s);
}
void write1(double s,int x=6){
char y[10001];
sprintf(y,"%%.%dlf",x);
printf(y,s);
}
void write1(long double s,int x=6){
char y[10001];
sprintf(y,"%%.%dLf",x);
printf(y,s);
}
template<typename T>void write1(T n){
if(n<0)n=-n,putchar('-');
if (n>9)write1(n/10);
putchar('0'+n%10);
}
template<typename T>friend ins operator>>(ins x,T &n);
template<typename T>friend ins operator<<(ins x,T n);
operator bool(){return ans;}
};
template<typename T>ins operator>>(ins x,T &n){
if(!x.ans)return x;
x.read1(n);return x;
}
template<typename T>ins operator<<(ins x,T n){
x.write1(n);
return x;
}
ins yin;
ins yout;
#endif
int ans,h[300010];
signed main(){
int n,k;yin>>n>>k;
for(int i=1;i<=n;i++){
int x;yin>>x;
if(x<=n)h[x]++;
}
int s=k;
for(int i=0;i<=n+1;i++){
if(h[i]<s)ans+=(s-h[i])*i,s=h[i];
// cout<<ans<<endl;
}yout<<ans;
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
int n,a[10005],b[10005],ans=12345678;
int main()
{
cin>>n;
for(int i=0;i<n;i++)
cin>>a[i]>>b[i];
for (int i=0;i<n;i++)
for (int j=0;j<n;j++)
if (i==j)
ans=min(ans,a[i]+b[i]);
else
ans=min(ans,max(a[i],b[j]));
cout<<ans;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<ll>
#define rep(i,a,b) for(int i=a; i<b; ++i)
#define pb push_back
#define endl '\n'
#define sa(x) sort((x).begin(), (x).end());
#define int long long
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; }
template<typename T> static inline void sd(vector<T> &x) {sort((x).begin(), (x).end(), greater<T>()) ; }
void solve(){
int n;
cin>>n;
vector<int> v[2];
v[0].resize(n);
v[1].resize(n);
int a=LLONG_MAX, b=LLONG_MAX;
rep(i,0,n){
cin>>v[0][i]>>v[1][i];
amin(a, v[1][i]+v[0][i]);
rep(j,0,i){
amin(a, min(max(v[0][i], v[1][j]), max(v[1][i], v[0][j])));
}
}
cout<<a;
}
signed main()
{
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int testcases=1;
//cin>>testcases;
while(testcases--){
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
constexpr ll MOD=1000000007;
constexpr ll INF=2e18;
struct edge{
ll to;
ll c;
};
vector<edge> g[210000];
VI sum(210000,0);
ll s=0;
void dfs(int v, int p){
sum[v]=s;
for(auto i:g[v]){
if(i.to!=p){
s^=i.c;
dfs(i.to,v);
s^=i.c;
}
}
}
int main(){
int n; cin >> n;
ll a, b, c;
REP(i,n-1){
cin >> a >> b >> c;
a--, b--;
g[a].push_back({b,c});
g[b].push_back({a,c});
}
dfs(0,-1);
VI cnt(60,0);
REP(i,n){
ll x=sum[i];
REP(j,60){
if(x&1)
cnt[j]++;
x>>=1;
}
}
ll ans=0;
ll p=1;
REP(i,60){
ans+=cnt[i]*(n-cnt[i])%MOD*p%MOD;
ans%=MOD;
p=p*2%MOD;
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<vector<pair<int, long long int>>> G(N);
for (int i = 0; i < N - 1; i++) {
int u, v;
long long int w;
cin >> u >> v >> w;
u--;
v--;
pair<int, long long int> p = make_pair(v, w), q = make_pair(u, w);
G.at(u).push_back(p);
G.at(v).push_back(q);
}
vector<long long int> dist(N, -1);
queue<int> que;
que.push(0);
dist.at(0) = 0;
while (!que.empty()) {
int u = que.front();
que.pop();
for (int i = 0; i < G.at(u).size(); i++) {
int v = G.at(u).at(i).first;
if (dist.at(v) >= 0) continue;
long long int w = G.at(u).at(i).second;
dist.at(v) = dist.at(u) ^ w;
que.push(v);
}
}
long long int ans = 0, MOD = 1000000007;
for (int k = 0; k < 60; k++) {
vector<long long int> cnt(2, 0);
for (int i = 0; i < N; i++) cnt.at((dist.at(i) >> k) & 1)++;
ans += ((long long int)1 << k) % MOD * cnt.at(0) % MOD * cnt.at(1) % MOD;
ans %= MOD;
}
cout << ans << endl;
} |
#include <bits/stdc++.h>
using namespace std;
int n,m,bl[55][55],val[55][55],di[]={0,0,-1,1},dj[]={1,-1,0,0},nn,mm;
bool vis[2505],p;
int main()
{
//freopen("in.txt","r",stdin);
p=true;
scanf("%d %d",&n,&m);
for(int i=0;i<50;i++)
{
for(int j=0;j<50;j++)
{
scanf("%d",&bl[i][j]);
}
}
for(int i=0;i<50;i++)
{
for(int j=0;j<50;j++)
{
scanf("%d",&val[i][j]);
}
}
while(1)
{
vis[bl[n][m]]=true;
p=false;
for(int i=0;i<4;i++)
{
nn=n+di[i];
mm=m+dj[i];
if(nn<0||mm<0||nn>=50||mm>=50)continue;
if(!vis[bl[nn][mm]])
{
if(i==0)printf("R");
else if(i==1)printf("L");
else if(i==2)printf("U");
else printf("D");
p=true;
n=nn;
m=mm;
//printf(" %d %d\n",n,m);
break;
}
}
if(!p)break;
}
}
| #include <bits/stdc++.h>
clock_t start;
constexpr int H = 50, W = 50;
int si, sj;
int t[H][W], p[H][W];
struct cand {
std::string s;
int score, i, j;
std::vector<bool> seen;
bool operator<(const cand& rhs) const { return score < rhs.score; }
bool valid(const char& c) {
if (c == 'L') return (0 < j && !seen[t[i][j - 1]]);
if (c == 'R') return (j < W - 1 && !seen[t[i][j + 1]]);
if (c == 'U') return (0 < i && !seen[t[i - 1][j]]);
if (c == 'D') return (i < H - 1 && !seen[t[i + 1][j]]);
}
cand move(const char& c) {
cand ret = *this;
ret.s.push_back(c);
if (c == 'L') ret.j--;
else if (c == 'R') ret.j++;
else if (c == 'U') ret.i--;
else ret.i++;
ret.score += p[ret.i][ret.j];
ret.seen[t[ret.i][ret.j]] = true;
return ret;
}
};
int main() {
start = clock();
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cin >> si >> sj;
for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) std::cin >> t[i][j];
for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) std::cin >> p[i][j];
constexpr int N = 1000;
int n = 1;
std::vector<bool> seen(H * W, false);
seen[t[si][sj]] = true;
cand ans = {"", p[si][sj], si, sj, seen};
std::vector<cand> c(N, ans);
while (clock() - start <= 1.95 * CLOCKS_PER_SEC) {
std::vector<cand> v;
for (int i = 0; i < n; i++) {
ans = std::max(ans, c[i]);
if (c[i].valid('L')) v.push_back(c[i].move('L'));
if (c[i].valid('R')) v.push_back(c[i].move('R'));
if (c[i].valid('U')) v.push_back(c[i].move('U'));
if (c[i].valid('D')) v.push_back(c[i].move('D'));
}
sort(v.begin(), v.end());
n = std::min(N, (int)v.size());
int m = n / 2;
for (int i = 0; i < m; i++) c[i] = v[(int)v.size() - 1 - i];
if (n == m) continue;
int skip = ((int)v.size() - m) / (n - m);
for (int i = 0; i < n - m; i++) c[i + m] = v[i * skip];
}
std::cout << std::max(ans, c[0]).s << '\n';
} |
#include <bits/stdc++.h>
using namespace std;
const int mod=998244353;
int main() {
long long a,b,c;
cin>>a>>b>>c;
long long ans=(((a*(a+1)/2%mod) * (b*(b+1)/2%mod)%mod) * (c*(c+1)/2%mod))%mod;
cout<<ans<<endl;
}
| #include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define tiii tuple<int, int, int>
#define pll pair<long long,long long>
#define sii set<int>
#define sll set<long long>
#define vii vector<int>
#define vll vector<long long>
#define vll vector<long long>
#define mii map<int,int>
#define mll map<long long, long long>
#define lob lower_bound
#define upb upper_bound
#define ret return
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define ford(container, it) for(auto it = container.begin(); it != container.end(); it++)
#define fors(container, it, a, b) for(auto it = a; it != b; it++)
#define ff first
#define all(v) v.begin(),v.end()
#define ss second
#define rep(i,n) for(i=0;i<n;i++)
#define fu(i,a,n) for(i=a;i<=n;i++)
#define fd(i,n,a) for(i=n;i>=a;i--)
#define gi(n) scanf(%d,&n)
int main()
{
int a,b,c;
cin>>a>>b>>c;
int arr[]={0,6,5,4,3,2,1};
int sum=arr[a]+arr[b]+arr[c];
cout<<sum<<endl;
} |
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);
int a,b;
cin>>a>>b;
cout<<(2*a+100)-b;
return 0;
} | #include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define ff first
#define ss second
#define pb push_back
#define ll long long
#define MX 100005
#define inf INT_MAX
#define mod 1000000007
#define endl "\n"
#define W(t) while(t--)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define all(v) v.begin(),v.end()
#define clr(a,x) memset(a,x,sizeof(a))
#define rep(i,a,b) for(i = a; i <= b; i++)
#define irep(i,b,a) for(i = b; i >= a; i--)
#define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
template <typename T> using ordered_set =
tree<T, null_type, less<T>,
rb_tree_tag, tree_order_statistics_node_update>;
int main()
{
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
IOS
ll a,b; cin >> a>>b;
cout << 2*a+100 - b<<endl;
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
#define read(a) scanf("%d", &a)
#define x first
#define y second
#define N 1011
int n, m;
int ans;
char a[N][N], b[N][N];
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
bool vis[N];
bool v[N][N][4];
struct state {
int x, y, d;
};
queue <state> q;
bool ok(int x, int y) {
return 1 <= x && x <= n && 1 <= y && y <= m;
}
void check(char g[N][N]) {
while (!q.empty()) {
auto o = q.front(); q.pop();
int x = o.x, y = o.y, d = o.d;
if (g[x][y] == '#' || !ok(x + dx[d], y + dy[d])) {
vis[y] = 1;
for (int i = 0; i < 4; i++) {
v[x][y][i] = 1;
}
for (d = 0; d < 4; d++) {
if (ok(x + dx[d], y + dy[d])) {
if ( !v[x + dx[d]][y + dy[d]][d] ) {
v[x + dx[d]][y + dy[d]][d] = 1;
q.push({x + dx[d], y + dy[d], d});
}
}
}
}
else if (ok(x + dx[d], y + dy[d])) {
if ( !v[x + dx[d]][y + dy[d]][d] ) {
v[x + dx[d]][y + dy[d]][d] = 1;
q.push({x + dx[d], y + dy[d], d});
}
}
}
}
void work(char g[N][N]) {
memset(vis, 0, sizeof vis);
vis[1] = 1; vis[m] = 1;
memset(v, 0, sizeof v);
int tot = 0;
v[1][1][0] = 1;
q.push({1, 1, 0});
v[1][1][1] = 1;
q.push({1, 1, 1});
check(g);
vector <int> op;
for (int i = 1; i <= m; i++) if (!vis[i]) {
op.push_back(i);
g[1][i] = '#';
tot++;
q.push({1, i, 0});
check(g);
}
for (auto x : op) {
g[1][x] = '.';
}
ans = min(ans, tot);
}
int main() {
read(n); read(m);
ans = n;
for (int i = 1 ;i <= n; i++) {
scanf("%s", a[i] + 1);
}
work(a);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
b[j][i] = a[i][j];
}
}
swap(n, m);
work(b);
printf("%d\n", ans);
}
| //W4P3R
#include<bits/stdc++.h>
#define inf 1e9
#define eps 1e-6
#define mp make_pair
#define pb push_back
#define re register ll
#define fr first
#define sd second
#define pa pair<ll,ll>
#define FOR(i,a,b) for(re i=a;i<=b;i++)
#define REP(i,a,b) for(re i=a;i>=b;i--)
#define MEM(a) memset(a,0,sizeof(a))
#define N 2010
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
inline ll read()
{
char ch=getchar();
ll s=0,w=1;
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
return s*w;
}
inline ll lowbit(ll x){return x&(-x);}
char s[N][N];
int n,m,vis[N],fa[N];
int find(int x){return x==fa[x]?x:fa[x]=find(fa[x]);}
inline void add(int x,int y){x=find(x),y=find(y);fa[x]=y;}
int main()
{
//ios::sync_with_stdio(false);
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
n=read(),m=read();
FOR(i,1,n+m)fa[i]=i;
FOR(i,1,n)
{
scanf("%s",s[i]+1);
FOR(j,1,m)if(s[i][j]=='#')add(i,j+n);
}
add(1,n+1);add(1,n+m);add(1,n);
int ans=0,num=0;
FOR(i,1,n)if(!vis[find(i)])vis[find(i)]=1,num++;
ans=num-1;MEM(vis);num=0;
FOR(i,1,m)if(!vis[find(i+n)])vis[find(i+n)]=1,num++;
ans=min(ans,num-1);MEM(vis);
cout<<ans<<'\n';
return 0;
}
//gl
|
#include<bits/stdc++.h>
using namespace std;
#define GODSPEED ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(15);
#define f first
#define s second
#define newl cout<<"\n";
#define pb push_back
#define mset(a,x) memset(a,x,sizeof(a))
#define debv(a) for(auto it: a)cout<<it<<" ";newl;
#define deb1(a) cout<<a<<"\n";
#define deb2(a,b) cout<<a<<" "<<b<<"\n";
#define deb3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n";
#define deb4(a,b,c,d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n";
#define uniq(a) a.resize(unique(a.begin(), a.end()) - a.begin());
#define all(a) a.begin(),a.end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
const ll N = 5e5+5;
const ll M = 4e6+5;
const ll mod = 1e9+7;
const ll INF = 0x7f7f7f7f7f7f7f7f;
const int INFi = 0x7f7f7f7f;
ll n, a, b;
ll fastmod(ll x, ll y = mod - 2){
ll res = 1;
while(y){
if(y&1) res = res * x % mod;
x = x * x % mod;
y /= 2;
}
return res;
}
ll sum(ll x){
return x * (x + 1) % mod * fastmod(2) % mod;
}
ll mul(ll x, ll y){
return x * y % mod;
}
void solve(){
cin >> n >> a >> b;
ll x = n - b + 1;
ll y = n - a - b + 1;
ll z = n - a + 1;
if(y <= 0){
deb1(0)
return;
}
ll s1 = mul(mul(sum(y), x), z), s2 = mul(sum(y), sum(y));
deb1((4*(s1 - s2) + 4*mod) % mod)
}
int main(){
GODSPEED;
int test = 1;
cin >> test;
for(int i = 1; i <= test; i++){
solve();
}
} | #include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
long long power(long long a, long long b,long long mod) {
long long res = 1;
while (b > 0) {
if (b & 1)
res = res * a %mod;
a = a * a %mod;
b >>= 1;
}
return res;
}
const int mod=1e9+7;
int find(int n)
{
int z=(n+1)*(n+2);
z%=mod;
return z;
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(0);
#ifndef ONLINE_JUDGE
if(fopen("INPUT.txt","r"))
{
freopen ("INPUT.txt" , "r" , stdin);
freopen ("OUTPUT.txt" , "w" , stdout);
}
#endif
int t;
cin>>t;
while(t--)
{
int n,a,b;
cin>>n>>a>>b;
if(a+b>n)
{
cout<<0<<'\n';
continue;
}
int x=find(n-a-b);
int ans=x*(n-a+1)%mod*(n-b+1)%mod;
ans*=2;
ans%=mod;
ans+=(mod-x*x%mod)%mod;
ans%=mod;
cout<<ans<<'\n';
}
} |
#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>;
const ll INF = 1e18;
const int MX = 2005;
int main() {
ll n;
cin >> n;
vector<ll>A(n);
rep(i,n) cin >> A[i];
vector<ll>maxS(n);
vector<ll>sumS(n);
rep(i,n){
if(i == 0){
sumS[i] = A[0];
maxS[i] = max(0ll,A[0]);
}else{
sumS[i] = sumS[i-1] + A[i];
maxS[i] = max(maxS[i-1],sumS[i-1] + A[i]);
}
}
ll m = 0;
ll sum = 0;
for(int i = 0; i < n; i++){
if(sum + maxS[i] > m){
m = sum + maxS[i];
}
sum += sumS[i];
}
cout << m << endl;
} | #include <bits/stdc++.h>
#define Fast cin.tie(0), ios::sync_with_stdio(0)
#define All(x) x.begin(), x.end()
#define louisfghbvc int t; cin >> t; while(t--)
#define sz(x) (int)(x).size()
using namespace std;
typedef long long LL;
typedef pair<LL, LL> ii;
typedef vector<LL> vi;
template<typename T> istream& operator>>(istream &is, vector<T> &v) { for(auto &it : v) is >> it; return is; }
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep = ""; for(const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
void dbg_out() { cerr << " end.\n"; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
const int N = 1e5+5;
const int inf = 0x3f3f3f3f;
/**
Read problem statement carefully
sum + len*y == x
**/
void solve(){
int n;
cin >> n;
LL res = 1e9;
LL mnA = 1e9, mnB = 1e9;
for(int i = 0; i < n; ++i){
LL a, b;
cin >> a >> b;
res = min({res, a+b, max(a, mnB), max(b, mnA)});
mnA = min(mnA, a);
mnB = min(mnB, b);
}
cout << res << "\n";
}
int main()
{
Fast;
//louisfghbvc
solve();
return 0;
}
/**
Enjoy the problem.
**/
|
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=(int)(x);i<(int)(y);i++)
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=1e9+7;
const int siz=2e5;
const int inf=1e9;
vector<pair<int,long>> g[siz];
long dist[siz];
void dfs(int v, int par, long d){
dist[v] = d;
for(pair<int,long> p:g[v]){
int u = p.first;
long w = p.second;
if(u == par) continue;
dfs(u, v, d ^ w);
}
}
long calc(long x, int j){
rep(i,0,j) (x *= 2) %= mod;
return x;
}
int main(){
int N; cin>>N;
int a,b; long c;
rep(i,0,N-1){
cin>>a>>b>>c; a--; b--;
g[a].push_back({b, c});
g[b].push_back({a, c});
}
dfs(0, -1, 0);
long cnt[60] = {};
rep(i,0,N)rep(j,0,60){
if(dist[i] & (1L<<j)) cnt[j]++;
}
long ans = 0;
rep(j,0,60) (ans += calc(cnt[j] * (N-cnt[j]) % mod, j)) %= mod;
cout<<ans<<endl;
} | //#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using namespace chrono;
#define ll long long
#define ld long double
#define mod 1000000007
#define pb push_back
#define inf 1000000000000000000
#define ff first
#define ss second
#define deb(x) cout<<#x<<" "<<x<<"\n"
#define Clear(x) memset(x,0,sizeof(x))
#define all(x) (x).begin(),(x).end()
void checkpoint1()
{
/******think more code less******/
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
freopen("Error.txt", "w", stderr);
#endif
}
bool comp(pair< ll,ll > &a,pair< ll,ll > &b)
{
if(a.ff!=b.ff)
return a.ff<b.ff;
else
{
if(a.ss>b.ss)
return b.ss<a.ss;
else if(a.ss<b.ss)
return a.ss<b.ss;
}
return a.ff>b.ff;
}
ll powe(ll a,ll b)
{
ll res=1;
while(b>0)
{
if(b&1)
{
res*=a;
res%=mod;
}
a*=a;
a%=mod;
b>>=1;
}
return res;
}
void terminAtor()
{
ll n;
cin>>n;
vector< pair< ll,ll > > adj[n+1];
for(ll i=1;i<n;i++)
{
ll x,y,z;
cin>>x>>y>>z;
adj[x].pb({z,y});
adj[y].pb({z,x});
}
vector< bool > vis(n+1,0);
vector< ll > dis(n+1,0);
queue< ll > q;
q.push(1);
while(!q.empty())
{
ll v=q.front();
q.pop();
vis[v]=1;
for(auto u:adj[v])
{
if(!vis[u.ss])
{
q.push(u.ss);
dis[u.ss]=dis[v]^u.ff;
}
}
}
ll ans=0;
for(ll i=0;i<60;i++){
ll tot0=0,tot1=0;
for(ll ii=1;ii<=n;ii++)
{
if(dis[ii]&(1LL<<i))
tot1++;
else
tot0++;
}
tot1*=tot0;
tot1%=mod;
ll ok=(1LL<<i);
ok%=mod;
tot1*=(ok);
tot1%=mod;
ans+=tot1;
ans%=mod;
}
cout<<ans;
}
int main()
{
checkpoint1();
/********************************************************/
auto startrrr = high_resolution_clock::now();
cout << setprecision(20);
/*******************************************************/
terminAtor();
/*******************************************************/
auto stoprrr = high_resolution_clock::now();
auto duration = duration_cast<microseconds>(stoprrr - startrrr);
#ifndef ONLINE_JUDGE
cerr << "Time: " << duration.count()/1000.0<<"\n";
#endif
/*******************************************************/
return 0;
} |
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG
#endif
#include <fstream>
#include <stdio.h>
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip> //setprecision
#include <map> // map
#include <unordered_map> //unordered_map
#include <queue> // queue, priority_queue
#include <set> // set,multiset
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
#include <numeric> //accumulate,,,
#include <sstream>
#include <random>
#include <initializer_list>
#define endl "\n";
using namespace std;
const long long INF = 4000000000000000001;
const int inf = 1001001001;
const long long MOD = 998244353;
//const long long MAXIMUM = INFINITY;
//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M, long long mod) {
if (M == 0) return 1;
long long res = mod_pow((N * N) % mod, M / 2,mod);
//When end-of-a bit is 1, times simple N.
if (M & 1) res = (res * N) % mod;
return res %= mod;
}
long long gcd(long long a, long long b) {
if (b == 0) return a; else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
return a / gcd(a, b) * b ;
}
long long get_mod(long long res){
if(res < 0) res += MOD;
return res % MOD;
}
typedef tuple<int,long long,long long> tup;
vector<vector<tup>> Edge(100005);
vector<long long> pre(100005,-1);
vector<long long> dist(100005,INF);
void dijkstra(){
priority_queue<pair<long long,int>,vector<pair<long long,int>>,greater<pair<long long,int>>> PQ;
PQ.emplace(0,0);
dist.at(0) = 0;
while(!PQ.empty()){
int now = PQ.top().second;
long long d = PQ.top().first;
PQ.pop();
if(dist.at(now) < d) continue;
for(tup t : Edge.at(now)){
int to = get<0>(t);
long long C = get<1>(t);
long long D = get<2>(t);
long long r = d;
// rが一番いい時間として、Di/t+1 + t+1 の最小値は√Diで取る(それはそう)
if(sqrt(D) < d) r = d;
else r = sqrt(D);
long long COST = C + D/(r+1);
if(dist[to] > COST + r){
dist[to] = COST + r;
PQ.emplace(COST+r , to);
}
}
}
}
int main() {
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
/*FILE* in = freopen("answer.txt", "w", stdout);
ifstream ifs("in.txt"); // 巨大ケースは in.txt に書いてifsで標準入力*/
int N;cin >> N;
int M;cin >> M;
for(int i = 0;i<M;i++){
int a,b;long long c,d;cin >> a >> b >> c >> d;a--;b--;
if(a == b) continue;
Edge.at(a).emplace_back(b,c,d);
Edge.at(b).emplace_back(a,c,d);
}
dijkstra();
if(dist[N-1] == INF){
cout << -1 << endl;
}
else{
cout << dist[N-1] << endl;
}
} | #include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>
#include <limits>
#include <math.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) a.begin(),a.end()
#define P pair<int,int>
#define Pll pair<long,long>
#define mp make_pair
#define INF 1000000001
#define INFl 1000000000000000001
#define ll long long
using namespace std;
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;
}
long time(long t,long c,long d){
if(t<0)return INFl;
return c+d/(t+1);
}
struct edge{long to,c,d;};
int main() {
int N,M;cin>>N>>M;
int X,Y,V;//始点X終点Y頂点数V
V=N;
vector< vector< edge > > G(V,vector<edge>(0));
rep(i,M){
long a,b,c,d;cin>>a>>b>>c>>d;
if(a==b)continue;
a--;b--;
edge e={b,c,d};
G[a].push_back(e);
edge e2={a,c,d};
G[b].push_back(e2);
}
X=0;Y=N-1;
vector<long>d(V,INFl);
priority_queue<Pll,vector<Pll>,greater<Pll> > que;
for(int i=0;i<V;i++){d[i]=INFl;}
d[X]=0;
que.push(Pll(0,X));//コスト,頂点
while(!que.empty()){
Pll p=que.top();que.pop();
long v=p.second;
if(d[v]<p.first)continue;
for(int i=0;i<G[v].size();i++){
edge e=G[v][i];
long to=e.to;
long c=e.c;
long t=d[v];
long D=e.d;
long left=t;
long right=INFl/10;
for(int i=0;i<100;i++){
long c1=(left*2+right)/3;
long c2=(left+right*2)/3;
long a1=c1+time(c1,c,D);
long a2=c2+time(c2,c,D);
if(a1>=a2){
left=c1;
}else{
right=c2;
}
}
long cost=INFl;
long pc=INFl;
for(long x=250;x>=-250;--x){
if(left+x<t)break;
cost=min(cost,left+x+time(left+x,c,D));
if(cost>pc)break;
pc=cost;
}
//cout<<v<<" "<<to<<" "<<left<<" "<<cost<<endl;
if(d[to]>cost){
d[to]=cost;
que.push(Pll(d[to],to));
}
}
}
if(d[Y]==INFl)cout<<-1<<endl;
else cout<<d[Y]<<endl;
} |
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using LL = long long;
using P = pair<LL,int>;
const LL INF = (LL)1e18;
struct edge{
int to;
LL T, K;
edge(int to, LL T, LL K) : to(to), T(T), K(K) {}
};
int main(){
int N, M, X, Y;
cin >> N >> M >> X >> Y;
X--; Y--;
vector<vector<edge>> G(N);
rep(i,M){
int a, b;
LL t, k;
cin >> a >> b >> t >> k;
a--; b--;
edge e1(b, t, k);
edge e2(a, t, k);
G[a].emplace_back(e1);
G[b].emplace_back(e2);
}
priority_queue<P, vector<P>, greater<P>> q;
vector<LL> dist(N, INF);
dist[X] = 0;
q.push(P(0, X));
while(!q.empty()){
P p = q.top(); q.pop();
int u = p.second;
LL d = p.first;
if(d > dist[u]) continue;
for(auto e : G[u]){
int v = e.to;
LL t = e.T, k = e.K;
LL cost = t + k - d % k;
if(d % k == 0) cost -= k;
if(dist[v] < d + cost) continue;
dist[v] = d + cost;
q.push(P(dist[v], v));
}
}
LL ans = dist[Y];
if(ans == INF) ans = -1;
cout << ans << endl;
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
const int mod=1e9+7;
bool visited[N];
long long dist[N];
vector<pair<int,pair<int,int>>>adj[N];
priority_queue<pair<long long,int>>pq;
void Dijkstra()
{
int k,t,x,y;
long long val;
while(!pq.empty())
{
val=-pq.top().first;
x=pq.top().second;
pq.pop();
if(visited[x])continue;
visited[x]=1;
for(auto it : adj[x])
{
y=it.first;
t=it.second.first;
k=it.second.second;
if(dist[y] > ((val+k-1)/k)*k+t)
{
dist[y]=((val+k-1)/k)*k+t;
pq.emplace(-dist[y],y);
}
}
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int a,b,i,k,m,n,t,x,y;
cin >> n >> m >> a >> b;
while(m--)
{
cin >> x >> y >> t >> k;
adj[x].push_back({y,{t,k}});
adj[y].push_back({x,{t,k}});
}
for(i=1;i<=n;i++)dist[i]=LLONG_MAX;
dist[a]=0;
pq.emplace(0,a);
Dijkstra();
if(dist[b] == LLONG_MAX)cout << "-1";
else cout << dist[b];
return 0;
}
//
|
#include <bits/stdc++.h>
clock_t start;
constexpr int H = 50, W = 50;
int si, sj;
int t[H][W], p[H][W];
struct cand {
std::string s;
int score, i, j;
std::vector<bool> seen;
bool operator<(const cand& rhs) const { return score < rhs.score; }
bool valid(const char& c) {
if (c == 'L') return (0 < j && !seen[t[i][j - 1]]);
if (c == 'R') return (j < W - 1 && !seen[t[i][j + 1]]);
if (c == 'U') return (0 < i && !seen[t[i - 1][j]]);
if (c == 'D') return (i < H - 1 && !seen[t[i + 1][j]]);
}
cand move(const char& c) {
cand ret = *this;
ret.s.push_back(c);
if (c == 'L') ret.j--;
else if (c == 'R') ret.j++;
else if (c == 'U') ret.i--;
else ret.i++;
ret.score += p[ret.i][ret.j];
ret.seen[t[ret.i][ret.j]] = true;
return ret;
}
};
int main() {
start = clock();
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cin >> si >> sj;
for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) std::cin >> t[i][j];
for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) std::cin >> p[i][j];
constexpr int N = 1000;
int n = 1;
std::vector<bool> seen(H * W, false);
seen[t[si][sj]] = true;
cand ans = {"", p[si][sj], si, sj, seen};
std::vector<cand> c(N, ans);
while (clock() - start <= 1.95 * CLOCKS_PER_SEC) {
std::priority_queue<cand> pq;
for (int i = 0; i < n; i++) {
ans = std::max(ans, c[i]);
if (c[i].valid('L')) pq.push(c[i].move('L'));
if (c[i].valid('R')) pq.push(c[i].move('R'));
if (c[i].valid('U')) pq.push(c[i].move('U'));
if (c[i].valid('D')) pq.push(c[i].move('D'));
}
n = std::min(N, (int)pq.size());
for (int i = 0; i < n; i++) {
c[i] = pq.top();
pq.pop();
}
}
std::cout << std::max(ans, c[0]).s << '\n';
} | #include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define absdiff(a,b) (a>b)?a-b:b-a
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false);cin.tie(0);
#define MOD 1000000007
#define ll_MAX 19223372036859
#define endl "\n"
ll fast_expo(ll x,ll p){
if(p==0) return 1;
else if(p%2==0){ ll t=fast_expo(x,p/2)%MOD;return (t*t)%MOD;}
else return (x*(fast_expo(x,p-1))%MOD)%MOD;}
ll dp[1005][1005], n, m, arr1[1005], arr2[1005];
vector<ll> AdjL[1005];
int main(){
fast
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ll t_c; t_c = 1;
// cin >> t_c;
for(ll t_i = 0; t_i < t_c; ++t_i){
ll n, m; cin >> n >> m;
ll a[n + 1], b[m + 1];
for(ll i = 1; i <= n; ++i)
cin >> a[i];
for(ll i = 1; i <= m; ++i)
cin >> b[i];
ll dp[n + 1][m + 1];
for(ll j = 0; j <= m; ++j){
dp[0][j] = j;
}
for(ll i = 1; i <= n; ++i){
dp[i][0] = i;
for(ll j = 1; j <= m; ++j){
if(a[i] == b[j]) dp[i][j] = dp[i - 1][j - 1];
else dp[i][j] = min({dp[i - 1][j] + 1, dp[i][j - 1] + 1, dp[i - 1][j - 1] + 1});
}
}
cout << dp[n][m];
}
return 0;
} |
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define NZB ios::sync_with_stdio(false)
typedef long long ll;
const int inf = 1e9 + 7;
const int mod = 1e9 + 7;
const int MAX_N = 1e3 + 7;
using namespace std;
int a[MAX_N], b[MAX_N];
int dp[MAX_N][MAX_N];
int main()
{
NZB;
int N, M;
cin>>N>>M;
for(int i=1;i<=N;i++) cin>>a[i];
for(int i=1;i<=M;i++) cin>>b[i];
memset(dp, 63, sizeof(dp));
for(int i=0;i<=N;i++) {
for(int j=0;j<=M;j++) {
if(!i || !j) {
dp[i][j] = max(i, j);
continue;
}
dp[i][j] = min(dp[i][j-1], dp[i-1][j]) + 1;
if(a[i] == b[j]) dp[i][j] = min(dp[i][j], dp[i-1][j-1]);
else dp[i][j] = min(dp[i][j], dp[i-1][j-1] + 1);
//printf("(%d,%d,%d)", i,j ,dp[i][j]);
}
}
cout<<dp[N][M]<<endl;
} | #include<bits/stdc++.h>
using namespace std;
long long n,L,A[2];
string s[200005];
int main() {
cin>>n>>L;
for(int i=1;i<=n;i++)
cin>>s[i];
A[0]=1;
for(int i=2;i<=n;i++) {
int cnt=0;
for(int j=0;j<L;j++)
if(s[i][j]!=s[1][j])
cnt++;
A[cnt%2]++;
}
cout<<A[0]*A[1];
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;//大きなint型
using ld = long double;//大きなdouble型
using P = pair<int,int>;//pair型の型エイリアス
#define rep(i,n) for (int i = 0; i < (n); ++i)//iをnまですすめる。
#define PI 3.14159265359
int main(){
int n,m;
int ans = 0;
int last_ans = 0;
cin>>n>>m;
int sara[n+1] = {0};
vector<int> a(m),b(m);
rep(i,m) cin>>a.at(i)>>b.at(i);
int k;
cin>>k;
vector<int> c(k),d(k);
rep(i,k) cin>>c.at(i)>>d.at(i);
//bit全探索
for(int bit = 0;bit < (1 << k); ++bit){
rep(i,n+1) sara[i]=0;
ans = 0;
rep(i,k){
if(bit & (1<<i)){//True
sara[d.at(i)] = 1;
}
else sara[c.at(i)] = 1;
}
rep(i,m){
//条件確認
if(sara[a.at(i)] == 1 && sara[b.at(i)] == 1) ans++;
}
last_ans = max(ans,last_ans);//達成した条件数が大きいほうを保存
}
cout << last_ans;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int MAXN = 110;
int a[MAXN], b[MAXN];
int ball[MAXN];
int c[20], d[20];
int n, m, k;
int ans = 0;
void dfs(int x) {
if (x > k) {
int cnt = 0;
// for (int i = 1; i <= n; i++) {
// cout << ball[i] << " ";
// }
// cout << endl;
for (int i = 1; i <= m; i++) {
if (ball[a[i]] && ball[b[i]]) {
//cout << c[i] << " " << d[i] << endl;
cnt++;
}
}
//cout << "cnt:" << cnt << endl;
ans = max(ans, cnt);
return;
}
ball[c[x]]++;
dfs(x + 1);
ball[c[x]]--;
ball[d[x]]++;
dfs(x + 1);
ball[d[x]]--;
}
int main() {
cin >> n >> m;
for (int i = 1; i <= m; i++) {
cin >> a[i] >> b[i];
}
cin >> k;
for (int i = 1; i <= k; i++) {
cin >> c[i] >> d[i];
}
dfs(1);
cout << ans;
return 0;
} |
# include<bits/stdc++.h>
using namespace std;
# define l long long
# define db double
# define rep(i,a,b) for(l i=a;i<b;i++)
# define vi vector<l>
# define vvi vector<vi>
# define vsi vector<set<l> >
# define pb push_back
# define mp make_pair
# define ss second
# define ff first
# define pii pair<l,l>
# define trvi(v,it) for(vi::iterator it=v.begin();it!=v.end();++it)
# define read(a) freopen(a,"r",stdin)
# define write(a) freopen(a,"w",stdout)
# define io ios::sync_with_stdio(false)
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ' ' << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
#ifdef KRISHNAN_DEBUG
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif
const bool MULTIPLE_TEST_CASES = false;
const l MOD=1e9+7;
const l N=1e5+5;
const l INF=1e12;
void solve() {
l n,m;
cin>>n>>m;
cout<<(m%n==0?"Yes":"No")<<"\n";
return;
}
int main(){
io;
int t=1;
if (MULTIPLE_TEST_CASES) cin>>t;
rep(i,0,t) {
solve();
}
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
int main(){
int n;
cin>>n;
vector<pair<int,string>> v(n);
rep(i,n){
string s;
int t;
cin>>s>>t;
v[i]={t,s};
}
sort(all(v));
cout<<v[n-2].second<<endl;
}
|
#include<bits/stdc++.h>
using namespace std;
const int M=1e5+5;
const int P=1e9+7;
int n,A[M];
long long dp[M][2];
void Dp()
{
dp[0][0]=dp[1][0]=dp[1][1]=1;
for(int i=2;i<=n;i++)
{
dp[i][0]=(dp[i-1][0]+dp[i-1][1])%P;
dp[i][1]=dp[i-1][0];
// printf("%d dp [0] %lld [1] %lld\n",i,dp[i][0],dp[i][1]);
}
}
void Solve()
{
Dp();
long long Add=0,Sub=0;
for(int i=1;i<=n;i++)(Add+=A[i]*dp[i-1][0]%P*dp[n-i+1][0])%=P;//,printf("%d Add %lld*%lld\n",i,dp[i-1][0],dp[n-i][0]%P);
for(int i=2;i<=n;i++)(Sub+=A[i]*dp[i-1][1]%P*dp[n-i+1][1])%=P;
// printf("%lld %lld\n",Add,Sub);
printf("%lld\n",(Add+P-Sub)%P);
}
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)scanf("%d",&A[i]);
Solve();
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define nl "\n"
#define pb(k) push_back(k)
#define vi vector<int>
bool ispali(string s)
{
bool ispalin = true;
int i = 0 ;
int j = s.size() - 1 ;
while(i<j)
{
if(s[i]!=s[j])
{
ispalin = false;
}
i++;
j--;
}
return ispalin;
}
float distance(int x1, int y1, int x2, int y2)
{
// Calculating distance
return sqrt(pow(x2 - x1, 2) +
pow(y2 - y1, 2) * 1.0);
}
void solve()
{
int n;
cin>>n;
vi input1;
vi input2;
for(int i = 0 ; i<n ; ++i)
{
int k ;
cin>>k;
input1.pb(k);
}
for(int i = 0 ; i<n ; ++i)
{
int k ;
cin>>k;
input2.pb(k);
}
int sum = 0 ;
for(int i = 0 ; i<n ; ++i)
{
sum += input1[i]*input2[i];
}
if(sum==0)
{
cout<<"Yes"<<nl;
}
else
{
cout<<"No"<<nl;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt" , "r" , stdin);
freopen("output.txt" , "w" , stdout);
#endif
solve();
}
//river
//
|
#include <bits/stdc++.h>
#define ll long long int
#define pii pair <int, int>
#define pb push_back
#define M 1000000007
#define umap unordered_map
#define uset unordered_set
#define endl "\n"
#define loop(i,x,n) for(ll i = x; i < n; i++)
#define rloop(i,x,n) for(ll i = n-1; i >= x ; i--)
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define vi vector <ll>
#define all(x) x.begin(), x.end()
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define f first
#define s second
using namespace std;
void seive(int N)
{
// move it up
vi isprime(N , true);
vi prime;
vi SPF(N);
vi primes;
// this block
isprime[0] = isprime[1] = false ;
for (ll i = 2; i < N ; i++)
{
if (isprime[i])
{
prime.push_back(i);
SPF[i] = i;
}
for (ll j = 0;
j < (int)prime.size() &&
i * prime[j] < N && prime[j] <= SPF[i];
j++)
{
isprime[i * prime[j]] = false;
SPF[i * prime[j]] = prime[j] ;
}
}
for (int i = 0; i < prime.size() && prime[i] <= N ; i++)
primes.pb(prime[i]);
}
bool is_prime(ll n) {
if (n == 1) {
return false;
}
int i = 2;
while (i * i <= n) {
if (n % i == 0) {
return false;
}
i += 1;
}
return true;
}
long long exponensiation(long long a, long long b) {
a %= M;
long long res = 1;
while (b > 0) {
if (b & 1)
res = res * a;
a = a * a % M;
b >>= 1;
}
return res;
}
//____________________________________________________________________________________________
vector <ll> dic;
void pre() {
ll x = 0;
for (int i = 1; i < 1000000; i++) {
x += i;
dic.pb(x);
}
}
void solve()
{
ll x;
cin >> x;
ll ans = lower_bound(dic.begin(), dic.end(), x) - dic.begin() + 1;
cout << ans << '\n';
}
//____________________________________________________________________________________________
int main() {
//____________________________________________________________________________________________
//#ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
//#endif
//____________________________________________________________________________________________
SPEED;
pre();
double T = 1;
//cin >> T;
while (T--) {
solve();
}
return 0;
} | /*****************************
* Author :: Πρασαννα Κ. Ροι *
*****************************/
/***********************************
* Unus pro omnibus, omnes pro uno *
***********************************/
#include<bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define __AcHiLlEs ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define span(a) begin(a), end(a)
template<typename t>
using vc = vector<t>;
int bSearch(int val) {
int l = 0, r = 100000;
while (r - l > 1) {
int m = (l + r) >> 1;
int sum = (m * (m + 1)) / 2;
if (sum >= val) r = m;
else l = m;
}
return r;
}
void solve() {
int n;
cin >> n;
cout << bSearch(n) << "\n";
}
signed main() {
// auto start = high_resolution_clock::now();
__AcHiLlEs
int t(1);
// cin >> t;
for (int i = 1; i <= t; /*cout << "Case " << i << ": ",*/ solve(), i++);
// auto stop = high_resolution_clock::now();
// double duration = duration_cast<microseconds>(stop - start).count();
// cout << fixed << setprecision(4) << duration / 1000000 << "\n";
return 0;
} |
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <stack>
#include <queue>
#include <vector>
static const int IINF = 1 << 30;
static const long long LINF = 1LL << 60;
static const long long MOD = 1.0e+9 + 7;
template <typename T> std::vector<T> vectors(std::size_t n, T val) {
return std::vector<T>(n, val);
}
template <typename T, typename... Args>
auto vectors(std::size_t n, Args... args) {
return std::vector<decltype(vectors<T>(args...))>(n, vectors<T>(args...));
}
template <class T> inline bool chmin(T &a, const T &b) {
return (a > b) ? a = b, true : false;
}
template <class T> inline bool chmax(T &a, const T &b) {
return (a < b) ? a = b, true : false;
}
template <class T> inline void chadd(T &a, const T &b) {
a += b, a %= MOD;
// TODO minus case
}
template <class T>
std::ostream &operator<<(std::ostream &stream, const std::vector<T> &vec) {
for (auto val : vec) {
if (std::is_fundamental<T>::value)
stream << " " << val;
else
stream << std::endl << val;
}
return stream;
}
int main() {
int n;
std::cin >> n;
std::vector<std::string> s(n);
std::vector<std::pair<int, int>> ti(n);
for (int i = 0; i < n; ++i) {
int tmp;
std::cin >> s[i] >> tmp;
ti[i] = std::make_pair(tmp, i);
}
std::sort(ti.begin(), ti.end(), std::greater<std::pair<int, int>>());
std::cout << s[ti[1].second] << std::endl;
}
| #include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>
using namespace std;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<pair<int, string>> a(n);
for (auto &[f, s] : a) {
cin >> s >> f;
}
sort(a.rbegin(), a.rend());
cout << a[1].second << endl;
}
|
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define tej ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define ve vector<int>
#define vl vector<long long int>
#define vp vector<pair<long long int,long long int>>
#define pb push_back
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define bp pop_back
#define fp pop_front
#define mp make_pair
#define fo(i,n) for(i=0;i<n;i++)
#define unq(v) unique(v.begin(), v.end())-v.begin()
#define fnd(v,a) find(v.begin(), v.end(), a)
#define uprb(v,a) upper_bound(v.begin(), v.end(), a)
#define upra(v,n,a) upper_bound(v, v+n, a)
#define lowb(v,a) lower_bound(v.begin(), v.end(), a)
#define lowa(v,n,a) lower_bound(v, v+n, a)
#define newuv(v) v.erase(unique(v.begin(),v.end()),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define rndshf(v) random_shuffle(v.begin(),v.end())
#define all(v) v.begin(),v.end()
// ll po(ll a,ll b,ll m)
// {
// ll t=1;
// while(b>0)
// {
// if(b%2!=0)
// {
// t=(t*a)%m;
// }
// a=(a*a)%m;
// b=b/2;
// }
// return t;
// }
// ll po(ll a,ll b)
// {
// ll t=1;
// while(b>0)
// {
// if(b%2!=0)
// {
// t=(t*a);
// }
// a=(a*a);
// b=b/2;
// }
// return t;
// }
// ll inv(ll a,ll m)
// {
// return po(a,m-2,m);
// }
// ll vis[100002]={0},x=0;
// vl v[100002];
// ll dfs(ll s)
// {
// ll c=1,i;
// for(i=0;i<v[s].size();i++)
// {
// if(vis[v[s][i]]==0)
// {
// vis[v[s][i]]=1;
// c+=dfs(v[s][i]);
// }
// }
// x+=c-1;
// //cout<<x<<endl;
// return c;
// }
//map<ll,ll>m;
void solve()
{
ll n,m,i,x,mi,c=0;
cin>>n>>m;
vl v,v1;
fo(i,m)
{
cin>>x;
v.pb(x);
}
if(n==m)
{
cout<<0;
return;
}
else if(m==0)
{
cout<<1;
return;
}
sort(all(v));
if(v[0]!=1)
v1.pb(v[0]-1);
for(i=1;i<m;i++)
{
if(v[i]-v[i-1]-1>0)
v1.pb(v[i]-v[i-1]-1);
}
if(v[m-1]!=n)
v1.pb(n-v[m-1]);
if(v1.size()==0){
cout<<"0\n";
return ;
}
sort(all(v1));
mi=v1[0];
c=0;
fo(i,v1.size())
{
c+=v1[i]/mi;
if(v1[i]%mi!=0)
c++;
}
cout<<c;
}
int main()
{
tej
ll t=1;
// cin>>t;
while(t--)
solve();
return 0;
}
| #include <algorithm>
#include <iostream>
#include <vector>
int main() {
int n, m;
std::cin >> n >> m;
std::vector<int> a(m);
for (int mi = 0; mi < m; ++mi) std::cin >> a[mi];
std::vector<int> lengths;
std::sort(a.begin(), a.end());
for (int mi = 0; mi < m; ++mi) {
int prev = (mi == 0 ? 0 : a[mi - 1]);
if (a[mi] - prev - 1 > 0) lengths.push_back(a[mi] - prev - 1);
}
if (n - (a.size() > 0 ? a.back() : 0) > 0) lengths.push_back(n - (a.size() > 0 ? a.back() : 0));
if (lengths.empty()) {
std::cout << 0 << std::endl;
return 0;
}
std::sort(lengths.begin(), lengths.end());
int k = lengths[0];
int ans = 0;
for (int len : lengths) {
ans += (len + k - 1) / k;
}
std::cout << ans << std::endl;
} |
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define rall (x) x.rbegin(), x.rend()
#define pb push_back
#define eb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
const int MOD = 1e9+7;
int main(){
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
vi arr(4);
int cs = 0;
for (auto &i: arr)
cin >> i, cs += i;
bool pos = false;
for (int i=0; i<4; i++){
if (arr[i]==cs-arr[i]) pos = true;
}
for (int i=0; i<4; i++)
for (int j=i+1; j<4; j++){
int cur = arr[i]+arr[j];
if (2*cur==cs) pos = true;
}
cout << (pos?"Yes\n":"No\n");
} | #include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <tuple>
#include <utility>
#include <functional>
#include <set>
#include <map>
#include <bitset>
#include <list>
#include<iomanip>
using namespace std;
using ll = long long;
using ULL = unsigned long long;
using pll = std::pair<ll, ll>;
using vi = std::vector<int>;
using vl = std::vector<ll>;
using vb = std::vector<bool>;
using db = double;
using vdb = std::vector<db>;
using qlg= std::priority_queue<ll, vl, std::greater<ll> > ; //ascending
using qll= std::priority_queue<ll, vl, std::less<ll> > ; // descending
using qdg= std::priority_queue<db, vdb, std::greater<db> > ; //ascending
using qdl= std::priority_queue<db, vdb, std::less<db> > ; // descending
template<class T>
using vv = std::vector<std::vector<T> >;
#define REPL(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FORL(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define REP(i, n) FORL(i, 0, n)
#define MREP(i, n) for (ll i= (ll)(n)-1; i>=0; i-- )
#define MFOR(i, a, b) for (ll i = (ll)(b)-1; i >= (ll)(a); i--)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rreps(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define bit(n) (1LL << (n))
#define INF pow(10, 10)
int main(void)
{
ll Sc, P, N, M, Q, A, B, C, D, K, T;
string Str, Pat, Text;
cin >> N >> M >> T;
vv<ll> times(M, vl(2, 0) );
REP(i, M)
{
cin >> times[i][0] >> times[i][1];
}
bool res = true;
ll rem = N;
ll time = 0;
REP(i, M)
{
rem -= times[i][0] - time;
if(rem<=0)
{
res = false;
break;
}
rem = min(rem+times[i][1]-times[i][0], N);
time = times[i][1];
}
rem -= T-time;
if(rem <= 0) res = false;
if(res) cout << "Yes"<<endl;
else cout << "No" << endl;
return 0;
}
|
// Problem: A - Not coprime
// Contest: AtCoder - AtCoder Regular Contest 114
// URL: https://atcoder.jp/contests/arc114/tasks/arc114_a
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)
/* Author : Atahar Islam Shihab
ICT'16th Batch,MBSTU
*/
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define ll long long
#define maxele(v) *max_element(v.begin(),v.end())
#define minele(v) *min_element(v.begin(),v.end())
#define deb(x) cout << #x << " -> " << x << endl
#define deb2(x, y) cout << #x << " -> " << x << " || " << #y << " -> " << y << endl
#define fast (ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0))
#define all(v) v.begin(),v.end()
#define sz(x) x.size();
#define clr(x) memset(x, 0, sizeof(x))
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
const int mxn = 100005;
int main()
{
fast;
int tc ;
int n;
cin >> n;
vector<ll>v(n);
for(int i=0;i<n;++i){
cin >> v[i];
}
sort(all(v));
vector<ll>prime;
for(int i=2;i<=50;++i){
bool ok = true;
for(int j=2;j*j<=i;++j){
if (i%j==0) {
ok=false;
break;
}
}
if (ok) prime.pb(i);
}
vector<ll>sub;
for(ll i=0; i< (1<<15) ;++i){
ll res=1;
for(ll j=0;j<15;++j){
if (i&(1<<j)){
res*=prime[j];
}
}
if (res>1)
sub.pb(res);
}
sort(all(sub));
ll ans=0;
for(int i=0;i<sub.size();++i){
bool ok = true;
for(int j=0;j<n;++j){
if (__gcd(sub[i],v[j])<2){
ok=false;
break;
}
}
if (ok){
cout << sub[i] <<'\n';
break;
}
}
return 0;
}
| #include<bits/stdc++.h>
#define L(i, j, k) for(int i = j, i##E = k; i <= i##E; i++)
#define R(i, j, k) for(int i = j, i##E = k; i >= i##E; i--)
#define ll long long
#define ull unsigned long long
#define db double
#define pii pair<int, int>
#define mkp make_pair
#define sz(a) ((int) (a).size())
using namespace std;
const int N = 1e5 + 7;
int n, Prime[N], p[N], tot;
ll a[N], ans = 7e18;
int main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n;
L(i, 1, n) cin >> a[i];
L(i, 2, 50) Prime[i] = true;
L(i, 2, 50) L(j, 2, 50 / i) Prime[i * j] = false;
L(i, 2, 50) if(Prime[i]) p[++tot] = i;
L(i, 1, (1 << tot) - 1) {
ll val = 1;
L(j, 1, tot) if(i >> (j - 1) & 1) val *= p[j];
bool ok = true;
L(j, 1, n) {
if(__gcd(a[j], val) == 1) {
ok = false;
break;
}
}
if(ok) ans = min(ans, val);
}
cout << ans << "\n";
return 0;
} |
#include<iostream>
#include<vector>
using namespace std;
using ll=long long;
int main(){
int n,k;cin>>n>>k;
vector<vector<ll>>f(n+1,vector<ll>(n+1,-1));
ll right=0,left=-1;
for(int y=0;y<n;y++){
for(int x=0;x<n;x++){
cin>>f.at(x+1).at(y+1);
right=max(right,f.at(x+1).at(y+1));
}
}
while(right-left>1){
ll mid=(right+left)/2;
vector<vector<ll>>s(n+1,vector<ll>(n+1,0));
bool judge=false;
for(int y=1;y<=n;y++){
for(int x=1;x<=n;x++){
s.at(x).at(y)=s.at(x-1).at(y)+s.at(x).at(y-1)-s.at(x-1).at(y-1);
if(f.at(x).at(y)>mid)s.at(x).at(y)++;
}
}
for(int y=1;y+k-1<=n;y++){
for(int x=1;x+k-1<=n;x++){
ll tmp=s.at(x+k-1).at(y+k-1)-s.at(x-1).at(y+k-1)-s.at(x+k-1).at(y-1)+s.at(x-1).at(y-1);
if(tmp<(k*k)/2+1)judge=true;
}
}
if(judge)right=mid;
else left=mid;
}
cout<<right<<endl;
}
| #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb pushback
#define fr(i,n) for(int i=0;i<n;i++)
#define fro(i,j,n) for(int i=j;i<n;i++)
#define ifr(i,n) for(int i=n-1;i>=0;i--)
int main() {
int h,w;
cin >> h>>w;
string s[h];
int ans=0;
fr(i,h){
cin >> s[i];
}
fr(i,h-1){
fr(j,w-1){
int count=0;
if(s[i][j]=='#')count++;
if(s[i+1][j]=='#')count++;
if(s[i][j+1]=='#')count++;
if(s[i+1][j+1]=='#')count++;
if(count==1||count==3)ans++;
}
}
cout << ans << endl;
}
|
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
#define pri(str) cout << str << endl
using ll = long long;
using P = pair<int, int>;
const ll MX = 1e18;
const long double PI = acos(-1);
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template<class T> inline vector<T> divisor(T n) {
vector<T> ret;
for (T i = 1; i * i <= n; i++) {
if (n % i == 0) {
ret.push_back(i);
if (i * i != n) ret.push_back(n / i);
}
}
sort(ret.begin(), ret.end());
return ret;
}
template<class T> inline vector<pair<T, T>> prime_factor(T n) {
vector<pair<T, T>> ret;
for (T i = 2; i * i <= n; i++) {
if (n % i != 0) continue;
T tmp = 0;
while (n % i == 0) {
tmp++;
n /= i;
}
ret.push_back(make_pair(i, tmp));
}
if (n != 1) ret.push_back(make_pair(n, 1));
return ret;
}
int main()
{
int n; cin >> n;
vector<int> a(n); rep(i, n){cin >> a[i]; a[i]--;}
vector<int> b(n); rep(i, n){cin >> b[i]; b[i]--;}
vector<int> c(n); rep(i, n){cin >> c[i]; c[i]--;}
vector<int> bc(n); rep(i, n) bc[b[c[i]]] += 1;
ll count = 0;
rep(i, n)
{
count += bc[a[i]];
}
pri(count);
return 0;
}
| #include<bits/stdc++.h>
#define int long long
#define uc getchar()
#define ph putchar
#define R register
#define CN const
#define rint R int
#define cint CN int
#define ps ph(' ')
#define pe ph('\n')
using namespace std;
cint inf=1e9+7;
cint mix=2e7+5;
inline int in();
inline void out(rint x);
int n=in(),k=in();
int c[10],nt;
inline int f(rint x){
nt=0;
while(x)c[++nt]=x%10,x/=10;
sort(c+1,c+nt+1);
//cerr<<nt<<endl;
rint rt=0;
for(rint i=1;i<=nt;++i)
(rt*=10)+=c[nt+1-i]-c[i];
return rt;
}
#undef int
int main() {
#define int long long
while(k--)n=f(n);
out(n),pe;
}
inline int in() {
rint x=0;
R bool f=0;
R char s=uc;
while((s<'0'||'9'<s)&&s!='-')s=uc;
if(s=='-')f=1,s=uc;
while('0'<=s&&s<='9')(x*=10)+=s^48,s=uc;
return f?-x:x;
}
inline void out(rint x) {
if(x<0)ph('-'),x=-x;
rint y=x/10;
if(y)out(y);
ph((x-y*10)^48);
} |
//#include <atcoder/all>
//using namespace atcoder;
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPR(i, n) for(int i=n-1; i>=0; i--)
#define FOR(i, m, n) for(int i=m; i<n; i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(x) int(x.size())
using P = pair<int, int>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 2e9;
const ll LINF = (1LL<<60);
const int mod = 1000000007;
//const int mod = 998244353;
struct mint {
ll x;
mint(ll x=0):x((x%mod+mod)%mod){}
mint operator-() const { return mint(-x);}
mint& operator+=(const mint a) {
if ((x += a.x) >= mod) x -= mod;
return *this;
}
mint& operator-=(const mint a) {
if ((x += mod-a.x) >= mod) x -= mod;
return *this;
}
mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
mint operator+(const mint a) const { return mint(*this) += a;}
mint operator-(const mint a) const { return mint(*this) -= a;}
mint operator*(const mint a) const { return mint(*this) *= a;}
mint pow(ll t) const {
if (!t) return 1;
mint a = pow(t>>1);
a *= a;
if (t&1) a *= *this;
return a;
}
// for prime mod
mint inv() const { return pow(mod-2);}
mint& operator/=(const mint a) { return *this *= a.inv();}
mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t; cin >> t;
while(t--){
int n,a,b; cin >> n >> a >> b;
if(n-a-b<0){
cout << 0 << endl;
continue;
}
mint ans = mint(n-a-b+2) * (n-a-b+1);
ans = mint(n-a+1)*(n-b+1) - ans;
ans *= ans;
mint total = mint(n-a+1).pow(2) * mint(n-b+1).pow(2);
cout << total - ans << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i,x,n) for(int i=x;i<(int)n;++i)
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define out(a) cout<<a<<endl;
#define vout(v) rep(i,0,v.size())cout<<v[i]<<(i==v.size()-1?"\n":" ");
#define vvout(vv) rep(j,0,vv.size()){vout(vv[j])}
#define mout(m) for(auto&e:m)cout<<e.first<<": "<<e.second<<endl;
#ifdef _CHK_
#define chk(a) if constexpr(_CHK_){cout<<#a<<": ";out(a)}
#define vchk(v) if constexpr(_CHK_){cout<<#v<<": ";vout(v)}
#define vvchk(vv) if constexpr(_CHK_){cout<<#vv<<": "<<endl;vvout(vv)}
#define mchk(m) if constexpr(_CHK_){cout<<#m<<": "<<endl;mout(m)}
#else
#define chk(a) {}
#define vchk(v) {}
#define vvchk(vv) {}
#define mchk(m) {}
#endif
vector<vector<int64_t>> adj;
vector<int64_t> depth;
vector<int64_t> imos;
vector<int64_t> score;
void get_score(int64_t now, int64_t prv, int64_t scr){
scr += imos[now];
score[now] = scr;
for (auto& nxt: adj[now]) {
if(nxt==prv) continue;
get_score(nxt, now, scr);
}
}
void get_depth(int64_t now, int64_t prv, int64_t dpt){
depth[now] = dpt;
for (auto& nxt: adj[now]) {
if(nxt==prv) continue;
get_depth(nxt, now, dpt+1);
}
}
int main(){
int64_t N;
cin>>N;
adj.resize(N);
vector<int64_t> A(N);
vector<int64_t> B(N);
for(int i = 0 ; i < N-1 ; i++){
int64_t a,b;
cin>>a>>b;
--a;--b;
adj[a].emplace_back(b);
adj[b].emplace_back(a);
A[i]=a;
B[i]=b;
}
vvchk(adj)
depth.resize(N);
get_depth(0, -1, 0);
vchk(depth)
int64_t Q;
cin>>Q;
imos.resize(N);
for(int i = 0 ; i < Q ; i++){
int64_t t,e,x;
cin>>t>>e>>x;
--e;
int64_t a=A[e], b=B[e];
if(t==2) swap(a,b);
if(depth[a]<depth[b]){
imos[0]+=x;
imos[b]-=x;
}else{
imos[a]+=x;
}
}
vchk(imos)
score.resize(N);
get_score(0, -1, 0);
for (auto& e: score) {
out(e);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long int_;
# define rep(i,a,b) for(int i=(a); i<=(b); ++i)
inline int readint(){
int a = 0; char c = getchar(), f = 1;
for(; c<'0'||c>'9'; c=getchar())
if(c == '-') f = -f;
for(; '0'<=c&&c<='9'; c=getchar())
a = (a<<3)+(a<<1)+(c^48);
return a*f;
}
const int MaxN = 1000000;
int_ dp[5][3*MaxN+1];
int main(){
int n = readint(), sum, A, B;
dp[0][0] = 1;
rep(i,1,3) rep(j,i,i*n){
dp[i][j] = dp[i][j-1]+dp[i-1][j-1];
if(j > n) dp[i][j] -= dp[i-1][j-n-1];
// printf("dp[%d,%d] = %d\n",i,j,dp[i][j]);
}
int_ k; scanf("%lld",&k);
for(sum=3; k>dp[3][sum]; ++sum)
k -= dp[3][sum];
for(A=1; k>dp[2][sum-A]; ++A)
k -= dp[2][sum-A];
for(B=1; k>dp[1][sum-A-B]; ++B)
k -= dp[1][sum-A-B];
printf("%d %d %d\n",A,B,sum-A-B);
return 0;
}
| #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define repn(i,n) for(int i=1;i<=n;++i)
#define LL long long
#define pii pair <int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
using namespace std;
const LL MOD=1e9+7;
LL n,t;
LL calc(LL sum)
{
LL lb=sum-n,ub=sum-1;
lb=max(lb,2LL);ub=min(ub,n*2);
if(ub<n+1) return (lb+ub-2)*(ub-lb+1)/2;
if(lb>n+1) return (n*4-lb-ub+2)*(ub-lb+1)/2;
return (lb+n-1)*(n-lb+2)/2+(n*3-ub+1)*(ub-n)/2-n;
}
LL calc2(LL sum,LL i)
{
if(sum-i<2||sum-i>2*n) return 0;
if(sum-i<=n+1) return sum-i-1;
return n*2-(sum-i)+1;
}
int main()
{
cin>>n>>t;
LL sum;
for(LL i=3;;++i)
{
LL val=calc(i);
if(t-val<=0)
{
sum=i;
break;
}
t-=val;
}
LL bea;
for(LL i=1;;++i)
{
if(t-calc2(sum,i)<=0)
{
bea=i;
break;
}
t-=calc2(sum,i);
}
LL tas=1;if(sum-bea-1>n) tas+=sum-bea-1-n;
tas+=t-1;
cout<<bea<<' '<<tas<<' '<<sum-bea-tas<<endl;
return 0;
} |
#include <bits/stdc++.h>
//#include <atcoder/all>
#define For(i, a, b) for (int(i) = (int)(a); (i) < (int)(b); ++(i))
#define rFor(i, a, b) for (int(i) = (int)(a)-1; (i) >= (int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template <class T>
bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T>
bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T>
T div_floor(T a, T b) {
if (b < 0) a *= -1, b *= -1;
return a >= 0 ? a / b : (a + 1) / b - 1;
}
template <class T>
T div_ceil(T a, T b) {
if (b < 0) a *= -1, b *= -1;
return a > 0 ? (a - 1) / b + 1 : a / b;
}
constexpr lint mod = 1000000007;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;
int main() {
int n;
scanf("%d", &n);
double x[n];
rep(i, n) scanf("%lf", &x[i]);
{
double ans = 0;
rep(i, n) ans += abs(x[i]);
printf("%.10lf\n", ans);
}
{
double ans = 0;
rep(i, n) ans += x[i] * x[i];
printf("%.10lf\n", sqrt(ans));
}
{
double ans = 0;
rep(i, n) chmax(ans, abs(x[i]));
printf("%.10lf\n", ans);
}
} | #include "bits/stdc++.h"
using namespace std;
using ll = long long;
int main() {
int n;
cin >> n;
vector<ll> x(n);
for (int i = 0; i < n; i++) {
cin >> x[i];
}
ll d1, d2;
ll d3;
d1 = 0;
d2 = 0;
d3 = 0;
for (int i = 0; i < n; i++) {
d1 += abs(x[i]);
d2 += x[i] * x[i];
d3 = max(d3, abs(x[i]));
}
long double d4 = sqrt(d2);
cout << d1 << endl;
cout << setprecision(20) << d4 << endl;
cout << (ll)d3 << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define REP(i, j, k) for (int i = j; i < k; i++)
#define RREP(i, j, k) for (int i = j; i >= k; i--)
typedef long long ll;
#define ALL(x) x.begin(), x.end()
#define pb push_back
typedef vector<int> vi;
typedef vector<ll> vll;
#define MAXN 5005
#define MOD 998244353
int n, m;
ll pw[MAXN][MAXN];
ll ans;
int main() {
scanf("%d%d", &n, &m);
ans = n;
REP (i, 0, n) {
ans = ans * m % MOD;
}
REP (i, 0, MAXN) {
pw[i][0] = 1;
REP (j, 1, MAXN) {
pw[i][j] = pw[i][j - 1] * i % MOD;
}
}
REP (i, 0, m) {
REP (j, 0, n - 1) {
ans -= pw[i][j] * (n - j - 1) % MOD * pw[m][n - j - 2] % MOD;
ans = (ans + MOD) % MOD;
}
}
printf("%lld\n", ans);
return 0;
}
| #include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <functional>
#include <bitset>
#include <limits>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <random>
#ifdef DEBUG
#include "library/Utility/debug.cpp"
#else
#define debug(...)
#endif
#define rep(i,n) for(int i=0;i<(n);++i)
#define EL '\n'
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using lnt = long long;
struct FIO{FIO(){std::cin.tie(0);std::ios_base::sync_with_stdio(0);std::cout<<std::fixed<<std::setprecision(15);}}fIO;
template<typename T> using V = std::vector<T>;
template<typename T> void fill(V<T>&v) { for(T&e:v) std::cin >> e; }
/*-*/
constexpr lnt MOD = 998244353;
struct mint
{
lnt v;
mint():v(0){}
mint(lnt v):v((v+MOD)%MOD){}
mint operator-()const{ return mint(0) - *this; }
mint& operator+=(const mint& a){ if((v+=a.v)>=MOD) v-=MOD; return *this; }
mint& operator-=(const mint& a){ if((v+=MOD-a.v)>=MOD) v-=MOD; return *this; }
mint& operator*=(const mint& a){ (v*=a.v)%=MOD; return *this; }
mint& operator/=(const mint& a){ (*this) *= a.inv(); 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 operator/(const mint& a)const{ return mint(*this) /= a; }
bool operator<(const mint& a)const{ return v < a.v; }
bool operator==(const mint& a)const{ return v == a.v; }
mint pow(lnt k)const{ mint r(1),t(v); while(k){ if(k&1) r*=t; t*=t; k>>=1; } return r; }
mint inv()const{ return pow(MOD-2); }
static mint comb(lnt n, lnt k) { if(n-k<k) k=n-k; mint num(1), dom(1); for(int i=0;i<k;i++) { num*=n-i; dom*=i+1; } return num/dom; }
static std::vector<mint> construct_comb(int n) {
std::vector<mint> c(n+1); mint a = 1; c[0] = a; for(int i=1;i<=n;i++) { a = a*mint(n+1-i)/i; c[i] = a; } return c;
}
static std::vector<mint> construct_fact(int n) { std::vector<mint> f(n+1,1); for(int i=2;i<=n;i++) f[i]=f[i-1]*i; return f; }
};
std::istream& operator>>(std::istream&i,mint&a){ lnt t; i>>t; a=mint(t); return i; }
std::ostream& operator<<(std::ostream&o,const mint&a){ o<<a.v; return o; }
int main() {
int n,m;
std::cin >> n >> m;
mint ans=mint(n)*mint(m).pow(n);
for(int x=2;x<=n;x++) {
mint o=0;
for(int y=1;y<=m;y++) {
o+=mint(m-y).pow(x-2)*mint(m).pow(n-x);
}
ans-=o*mint(n-x+1);
}
print(ans);
}
|
/**
* author: pankaj_m05
* created: 19.12.2020 23:17:06
**/
#include<bits/stdc++.h>
#define sz(x) (int(x.size()))
using namespace std;
struct fenwick {
int n;
vector< int > bit;
fenwick(int n) {
this -> n = n;
bit.assign(n + 1, 0);
}
fenwick(vector< int >& a) : fenwick(sz(a)) {
for (int i = 1; i <= n; ++i)
update(i, a[i - 1]);
}
void update(int idx, int k) {
for (int i = idx; i <= n; i += i & -i)
bit[i] ^= k;
}
int sum(int idx) {
int ans = 0;
for (int i = idx; i; i -= i & -i)
ans ^= bit[i];
return ans;
}
int range(int l, int r) {
return sum(r) ^ sum(l - 1);
}
};
int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, q;
cin >> n >> q;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
fenwick f(a);
while (q--) {
int t;
cin >> t;
if (t == 1) {
int x, v;
cin >> x >> v;
f.update(x, v);
} else {
int l, r;
cin >> l >> r;
cout << f.range(l, r) << '\n';
}
}
return 0;
} | #include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>
#include<list>
#define DIV 1000000007
#define TE 2e5
using namespace std;
using ll = long long;
using ldb = long double;
int sol(const string& S) {
const string A = "atcoder";
if (S > A)return 0;
int len = S.size(), K = 0;
for (int i = 0; i < len; i++) {
if (S[i] != 'a') {
K = i;
break;
}
if (i == len - 1)return -1;
}
if (S[1] != 'a')return 1;
if (S[K] > 't')return K - 1;
else return K;
}
int main() {
int T; cin >> T;
for (int i = 0; i < T; i++) {
string S; cin >> S;
cout << sol(S) << endl;
}
}
|
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;
const int N=1e5+5,M=4e5+5;
int edge[M],Next[M],ver[M],head[N];
int tot=0,tmp=0;
int dfn[N],dis[N];
int n,m;
void add(int x,int y,int z){
ver[++tot]=y,edge[tot]=z,Next[tot]=head[x],head[x]=tot;
}
void dfs(int x){
dfn[x]=++tmp;
for(int i=head[x];i;i=Next[i]){
int y=ver[i];
if(!dfn[y]){
if(dis[x]!=edge[i]) dis[y]=edge[i];
else dis[y]=dis[x]%n+1;
dfs(y);
}
}
}
int main(){
scanf("%d%d",&n,&m);
for(int i=0;i<m;i++){
int u,v,w;
scanf("%d%d%d",&u,&v,&w);
add(u,v,w);add(v,u,w);
}
dis[1]=1;
dfs(1);
if(tmp<n-1) puts("No");
else{
for(int i=1;i<=n;i++) printf("%d\n",dis[i]);
}
} | #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;
template <typename T> using vt = vector<T>;
template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pb push_back
#define SZ(x) ((int)((x).size()))
#define EACH(x, a) for (auto& x: a)
#define FOR(i,s,n) for (ll i = (s); (i) < (n); ++i)
#define FORD(i,s,l) for (ll i = (s); (i) >= l; --i)
#define F first
#define S second
#define TC int __tc; cin >> __tc; FOR(case_num,1,__tc+1)
#define TEST(x,i) ((x)&(1ll<<(i)))
#define SET(x,i) ((x)|(1ll<<(i)))
#define FLIP(x,i) ((x)^(1ll<<(i)))
#define CLEAR(x,i) ((x)&~(1ll<<(i)))
const double pi = 4 * atan(1);
using ll = long long;
using pll = pair<ll, ll>;
mt19937 mt_rng(chrono::steady_clock::now().time_since_epoch().count());
ll randint(ll a, ll b) {
return uniform_int_distribution<ll>(a, b)(mt_rng);
}
template<class T> bool umin(T& a, const T& b) {
return b<a?a=b, 1:0;
}
template<class T> bool umax(T& a, const T& b) {
return a<b?a=b, 1:0;
}
template<class ForwardIterator> void print_vec(ForwardIterator first,
ForwardIterator last, string sep = " ", string end = "\n") {
bool ft = true;
while (first != last) {
if (!ft) {cout << sep;} else {ft = false;}
cout << (*first);
++first;
}
cout << end;
}
template<typename T1, typename T2>
std::ostream& operator<<(std::ostream &o, const pair<T1, T2> &p) {
return o << p.F << " " << p.S;
}
inline ll floorDiv(ll x, ll y) {
ll d = x / y;
ll r = x % y;
return r ? (d - ((x < 0) ^ (y < 0))) : d;
}
ll ceilDiv(ll x, ll y) {
return -floorDiv(-x, y);
}
ll bin_search(ll lo, ll hi, function<bool(ll)> predicate) {
int sign = lo < hi ? 1 : -1;
lo *= sign;
hi *= sign;
hi++;
while (lo < hi) {
ll mid = lo + floorDiv(hi-lo, 2);
if (!predicate(sign * mid)) {
lo = mid + 1;
} else {
hi = mid;
}
}
return sign * lo;
}
const ll MOD = 1000000007;
const int MAXN = 100005;
map<int,vector<int>> adj[MAXN];
map<int,map<int,int>> used;
bool visited[MAXN];
int n;
void dfs(int u, vector<int> &ans) {
visited[u]=true;
for (auto &p : adj[u]) {
int val = p.F;
for (auto v : p.S) {
if (!visited[v]) {
ans[v] = (ans[u] == val ? (val+1)%n : val);
dfs(v, ans);
}
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n;
int m;
cin >> m;
vector<int> ans(n,-1);
while(m--) {
int x, y, v;
cin >> x >> y >> v; x--; y--; v--;
adj[x][v].pb(y);
adj[y][v].pb(x);
}
ans[0]=0;
dfs(0,ans);
if (find(ans.begin(),ans.end(),-1) != ans.end()) {
cout << "No\n";
} else {
for (auto v : ans) {
cout << v+1 << "\n";
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
#define ll long long
#define ar array
const ll mxN=2e5;
const int mod=1e9+7;
const ll INF=1e18;
#define what_is(x) cerr << #x << " is " << x << endl;
ll a,b,n,k,q,m,x,y,h,l,r,t;
void solve(){
cin>>n;
ll A[n],B[n],aoki=0,delta;
vector<ll> benifit(n);
for(int i=0;i<n;i++){
cin>>A[i]>>B[i];
aoki+=A[i];
benifit[i]=2*A[i]+B[i];
}
delta=-aoki;
sort(benifit.rbegin() , benifit.rend());
int i=0;
while(i<n && delta<=0){
delta+=benifit[i];
i++;
}
cout<<i<<endl;
}
signed main() {
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
#endif
// ios::sync_with_stdio(false);
// cin.tie(0);
// cout.tie(0);
cout<<setprecision(12)<<fixed;
// cin>>t;
// while(t--)
solve();
return 0;
}
| #include <bits/stdc++.h>
//#include <atcoder/all>
//using namespace atcoder;
//#include <boost/multiprecision/cpp_int.hpp>
//#include <boost/multiprecision/cpp_dec_float.hpp>
//using namespace boost::multiprecision;
using namespace std;
#pragma region Macros
using ll = long long;
#define int ll
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V<V<T>>;
#define IOS\
ios::sync_with_stdio(false);\
cin.tie(0);\
cout.tie(0);
#define FOR(i,l,r) for(int i=(l);i<int(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(int i=(l);i>=int(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define SORT(name) sort(name.begin(), name.end())
#define RSORT(name)\
SORT(name);\
reverse(all(name));
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';}
inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';}
template <class T> inline void print(T x){ cout << x << '\n';}
template<typename T1,typename T2> inline void chmin(T1 &a, T2 b){ if(a > b) a = b; }
template<typename T1,typename T2> inline void chmax(T1 &a, T2 b){ if(a < b) a = b; }
const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
#pragma endregion
const int MOD = 1000000007;
#if 1
# define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
# define DBG(fmt, ...)
#endif
const int MAX_N = 110;
int N;
int dp[MAX_N][2];
V<string> S;
int dfs(int i, int j) {
if(i >= N + 1) {
return j;
}
int& ret = dp[i][j];
if(~ret) { return ret; }
ret = 0;
if(i == 0) {
ret += dfs(i + 1, 1);
ret += dfs(i + 1, 0);
return ret;
}
// ここを 1 にする
int nj;
if(S[i] == "AND") {
nj = j & 1;
ret += dfs(i + 1, nj);
}
else {
nj = j | 1;
ret += dfs(i + 1, nj);
}
// ここを 0 にする
if(S[i] == "AND") {
nj = j & 0;
ret += dfs(i + 1, nj);
}
else {
nj = j | 0;
ret += dfs(i + 1, nj);
}
return ret;
}
signed main() {
IOS;
cin >> N;
S.resize(N + 1);
REP(i, N) { cin >> S[i + 1]; }
MINUS(dp);
int ans = dfs(0, 0);
print(ans);
return 0;
}
|
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstddef>
#include<queue>
#include<math.h>
#include<iomanip>
using namespace std;
typedef long long ll;
int main()
{
int n, maxcnt = 0, cnt = 0, ans = 0;
cin >> n;
vector<int> a(n),b(1000);
for(int i = 0; i < n; ++i) cin >> a.at(i);
for(int k = 2; k < 1001; ++k){
for(int i = 0; i < n; ++i) if(a.at(i) % k == 0) cnt += 1;
if(maxcnt < cnt){
maxcnt = cnt;
ans = k;
}
cnt = 0;
}
cout << ans << endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair<ll,ll>
#define vi vector<ll>
#define mii map<ll,ll>
#define pqi priority_queue<ll> //max pq
#define pqd priority_queue<ll,vi,greater<ll> >
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define MOD 1000000007
#define inf 1e18
#define ps(x,y) fixed<<setprecision(y)<<x
#define pw(b,p) pow(b,p) + 0.1
#define f(i,k,n) for(ll i=k;i<n;i++)
ll power(ll a, ll b, ll mod) {ll res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) {if (b & 1)res = res * a % mod; a = a * a % mod;} return res;}
ll power(ll a, ll b) {ll res = 1; assert(b >= 0); for (; b; b >>= 1) {if (b & 1)res = res * a ; a = a * a;} return res;}
ll min( ll a, ll b) { return (a < b) ? a : b;}
ll max(ll a, ll b) {return (a > b) ? a : b;}
ll gcd (ll a, ll b) {if (a == 0) return b; return gcd(b % a, a);}
void bwayne()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
void solve() {
ll n;
cin >> n;
vi a(n);
f(i, 0, n) cin >> a[i];
ll ans = 1;
mii poss;
f(i, 0, n) {
ll el = a[i];
for (ll j = 2; j * j <= a[i]; j++) {
ll count = 0;
while (el % j == 0) {
count++;
el /= j;
}
if (count >= 1) {
poss[j]++;
}
}
if (el > 1) {
poss[el]++;
}
}
mii m;
for (auto i = poss.begin(); i != poss.end(); i++) {
ll pos = i->first;
f(j, 0, n) {
if (a[j] % pos == 0) {
m[pos]++;
}
}
}
ll maxx = 0;
for (auto it = m.begin(); it != m.end(); it++) {
if (it->second > maxx) {
ans = it->first;
maxx = it->second;
}
}
cout << ans;
}
int main()
{
bwayne();// remember
ll t = 1;
// cin >> t;
for (ll tt = 1; tt <= t; tt++)
{
// cout<<"Case #"<<tt<<": ";
solve();
}
return 0;
} |
///Bismillahir Rahmanir Rahim
#include "bits/stdc++.h"
#define ll long long
#define int ll
#define fi first
#define si second
#define mp make_pair
#define pb push_back
#define pi pair<int,int>
#define nd(a,b,c) mp(mp(a,b),c)
#define clr(x) memset(x,0,sizeof(x));
#define f(i,l,r) for(int i=l;i<=r;i++)
#define rf(i,r,l) for(int i=r;i>=l;i--)
#define done(i) cout<<"done = "<<i<<endl;
#define show(x,y) cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
const ll inf=2e18;
const int mod=998244353;
const int M=100005;
void solve()
{
int h,w;
cin>>h>>w;
char yo[h+1][w+1];
f(i,1,h)
{
f(j,1,w)
{
cin>>yo[i][j];
}
cin.ignore();
}
int ses=1;
vector<pi>vec;
for(int i=1;i<=h;i++)vec.pb({i,1});
for(int j=2;j<=w;j++)vec.pb({h,j});
for(auto z:vec)
{
int x=z.fi,y=z.si;
int red=0,blue=0,no_colour=0;
while(x>=1 && y<=w)
{
if(yo[x][y]=='B')blue++;
else if(yo[x][y]=='R')red++;
else no_colour++;
x--;y++;
}
if(red>=1 && blue>=1)
{
cout<<"0\n";return ;
}
if(red==0 && blue==0)ses=(ses*2LL)%mod;
}
cout<<ses<<"\n";
}
main()
{
fast
int t=1;
//cin>>t;
while(t--)
{
solve();
}
return 0;
}
| #include <bits/stdc++.h>
#define rep(i,x,y) for(int i=x;i<=y;++i)
#define per(i,x,y) for(int i=x;i>=y;--i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int inf = 1e9;
const int mod=1e9+7;
const int N = 3e5 + 5;
int n;
int a[N];
int tr[N];
void add(int x,int k){
while(x<=n) tr[x]+=k,x+=x&-x;
}
int dor(int x){
int ret=0;
while(x) ret+=tr[x],x-=x&-x;
return ret;
}
int main() {
cin>>n;
rep(i,1,n){
cin>>a[i];
a[i]++;
}
ll ans=0;
rep(i,1,n){
ans+=dor(n)-dor(a[i]);
add(a[i],1);
}
cout<<ans<<'\n';
rep(i,1,n-1){
ans+=dor(n)-dor(a[i]);
ans-=dor(a[i]-1);
cout<<ans<<'\n';
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/modint>
//using namespace atcoder;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define sz(x) int(x.size())
const int INF = 1001001001;
const ll mod = 1000000007;
const ll INFL = 1001001001001001000;
int main() {
int n; cin >> n;
ll x[n]; rep(i,n) cin >> x[i];
ll md = 0; rep(i,n) md += abs(x[i]);
ll cd = 0; rep(i,n) cd = max(cd, abs(x[i]));
double ed = 0; rep(i,n) ed += (long double) x[i] * x[i];
ed = sqrt(ed);
cout << md << endl;
cout << setprecision(15) << ed << endl;
cout << cd << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define sz(a) int(a.size())
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) { out << "(" << a.first << "," << a.second << ")"; return out; }
template <typename T, size_t N> ostream& operator <<(ostream& out, const array<T, N>& a) { out << "["; bool first = true; for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]"; return out; }
template <typename T> ostream& operator <<(ostream& out, const vector<T>& a) { out << "["; bool first = true; for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]"; return out; }
template <typename T, class Cmp> ostream& operator <<(ostream& out, const set<T, Cmp>& a) { out << "{"; bool first = true; for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}"; return out; }
template <typename U, typename T, class Cmp> ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) { out << "{"; bool first = true; for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}"; return out; }
template <typename Arg1> void __f(const char* name, Arg1&& arg1){ cerr << name << ": " << arg1 << endl; }
template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args){ const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << ": " << arg1 << " |"; __f(comma + 1, args...); }
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
void solve() {
int n; cin >> n;
vector<string> s(n);
for(int i=0; i<n; i++) {
cin >> s[i];
}
unordered_map<string, int> m;
for(int i=0; i<n; i++) {
auto ss = s[i];
if(ss[0] == '!') {
ss = ss.substr(1);
m[ss] |= 1;
} else {
m[ss] |= 2;
}
if(m[ss] == 3) {
cout << ss << endl;
return;
}
}
cout << "satisfiable" << endl;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
solve();
return 0;
}
|
#include <bits/stdc++.h>
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(),(x).end()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
using namespace std;
typedef double DB;
typedef long double LD;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<PII> VPII;
//head
const int N=1e4+5;
int n,a[N];
int main() {
//freopen("E:/OneDrive/IO/in.txt","r",stdin);
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i];
int res=0;
for(int i=1;i<=n;i++) {
int t=1;
for(int j=i-1;j>=1;j--) {
if(a[j]>=a[i]) ++t;
else break;
}
for(int j=i+1;j<=n;j++) {
if(a[j]>=a[i]) ++t;
else break;
}
res=max(res,t*a[i]);
}
cout<<res<<'\n';
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repn(i,a,b) for(ll i=a;i>=b;i--)
#define ld long double
#define fi first
#define se second
#define pii pair<ll,ll>
#define vi vector<ll>
#define vii vector<pii>
#define pb push_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()
#define sz(a) (ll)(a.size())
#define len(a) (ll)(a.length())
#define mem0(a) memset(a, 0, sizeof(a))
#define mem1(a) memset(a, -1, sizeof(a))
#define trav(a, x) for (auto &a : x)
#define popcount(x) __builtin_popcountll(x)
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define mod 1000000007
ll INF = 1e6;
void solve() {
ll n;
cin >> n;
vi a(n), b(200);
rep(i, 0, n) {
cin >> a[i];
b[a[i] % 200]++;
}
ll c = 0;
rep(i, 0, 200) {
c += b[i] * (b[i] - 1) / 2;
}
cout << c;
}
int main() {
SPEED;
#ifndef ONLINE_JUDGE
freopen("input1.txt", "r", stdin);
freopen("output1.txt", "w", stdout);
#endif
clock_t z = clock();
ll t = 1;
//cin >> t;
while (t--) solve();
debug("Total Time:%.3Lf\n", (ld)(clock() - z) / CLOCKS_PER_SEC);
return 0;
} |
#include <cstdio>
#include <cmath>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <cassert>
#include <string>
#include <cstring>
#include <queue>
using namespace std;
#define rep(i,a,b) for(int i = a; i < b; i++)
#define S(x) scanf("%d",&x)
#define S2(x,y) scanf("%d%d",&x,&y)
#define P(x) printf("%d\n",x)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second
#define pb push_back
#define mp make_pair
typedef long long int LL;
typedef pair<int, int > pii;
typedef vector<int > vi;
const int N = 1001;
string s;
vi g[2 * N];
int vis[2 * N];
set<int > s1, s2;
void dfs(int c, int cmp) {
if(vis[c]) return;
vis[c] = cmp;
rep(i,0,g[c].size()) {
dfs(g[c][i], cmp);
}
}
int main() {
int n,m;
S2(n,m);
rep(i,0,n) {
cin >> s;
rep(j,0,m) if(((i == 0 || i == n - 1) && (j == 0 || j == m - 1)) ||s[j] == '#') {
g[i + 1].pb(n + j + 1);
g[n + j + 1].pb(i + 1);
}
}
int cnt = 0;
rep(i,1,n+m+1) if(!vis[i]) {
++cnt;
dfs(i, cnt);
}
rep(i,1,n+m+1) {
if(i <= n) s1.insert(vis[i]);
else s2.insert(vis[i]);
}
P((int)min(s1.size(), s2.size()) - 1);
return 0;
}
| #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;
struct union_find {
vector<int> par, siz;
union_find(int n) {
par.resize(n);
siz.resize(n);
for(int i = 0; i < n; i++){
par[i] = i;
siz[i] = 1;
}
}
int find(int x) {
if (par[x] == x) return x;
return par[x] = find(par[x]);
}
void unite(int x, int y) {
x = find(x);
y = find(y);
if (x == y)return;
if (siz[x] < siz[y]) {
par[x] = y;
siz[y] += siz[x];
}
else {
par[y] = x;
siz[x] += siz[y];
}
}
long long size(int x){
return siz[find(x)];
}
bool same(int x, int y) {
return (find(x) == find(y));
}
};
int main(){
cin.tie(0); ios::sync_with_stdio(false);
ll h, w; cin >> h >> w;
string s[h];
zep(i, 0, h)cin >> s[i];
union_find u(h + w);
u.unite(0, h - 1);
u.unite(0, h);
u.unite(0, h + w - 1);
zep(i, 0, h){
zep(j, 0, w){
if(s[i][j] == '#'){
u.unite(i, h + j);
}
}
}
set<ll> ansh, answ;
zep(i, 0, h)ansh.insert(u.find(i));
zep(j, 0, w)answ.insert(u.find(h + j));
print(min(ansh.size(), answ.size()) - 1)
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int main(){
vector<int> A;
vector<int> B;
vector<int> product;
int N,m;
int result = 0;
cin >> N;
for(int i = 0;i < N;i++){
cin >> m;
A.push_back(m);
}
for(int i = 0;i < N;i++){
cin >> m;
B.push_back(m);
}
for(int i = 0;i < N;i++){
int P;
P = A[i]*B[i];
product.push_back(P);
}
for(int i = 0;i < N;i++){
result += product[i];
}
if(result == 0){
cout << "Yes" << endl;
return 0;
}
cout << "No" << endl;
} | #include <bits/stdc++.h>
using namespace std;
void solve() {
int l,r;
cin >> l >> r;
long long marg = r-2*l;
long long ans = (marg+1)*(marg+2)/2;
if (marg < 0) ans = 0;
cout << ans << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
for (int i=0;i<t;i++) solve();
} |
#include <bits/stdc++.h>
using namespace std;
string to_string(string s) {
return '"' + s + '"';
}
string to_string(const char* s) {
return to_string((string) s);
}
string to_string(bool b) {
return (b ? "true" : "false");
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
bool first = true;
string res = "{";
for (const auto &x : v) {
if (!first) {
res += ", ";
}
first = false;
ostringstream name;
name<<x;
string l=name.str();
res += to_string(l);
}
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__)
int main()
{
int n,m;
scanf("%d %d",&n,&m);
vector<int>a(n);
for(int i=0;i<n;i++){
scanf("%d",&a[i]);
}
vector<int>b(m);
for(int i=0;i<m;i++){
scanf("%d",&b[i]);
}
for(int i=1;i<=1e3;i++){
auto poz = binary_search(a.begin(),a.end(),i) ;
auto poz2 = binary_search(b.begin(),b.end(),i) ;
if((poz && !poz2) ||
(!poz && poz2) ){
printf("%d ",i);
}
}
printf("\n");
return 0;
}
| #include <iostream>
#include <fstream>
#include <cstdio>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include <iomanip>
#include <cassert>
#include <random>
#include <time.h>
using namespace std;
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define REVERSE(v) reverse((v).begin(), (v).end())
#define pb push_back
#define FOR(i, n) for(int i = 0; i < (n); i++)
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
const int mod = 1e9 + 7;
const int mod2 = 998244353;
void fact_init(int n, int md);
ll exp(ll taban, ll us, ll md);
ll ebob(ll a, ll b);
ll ekok(ll a, ll b);
ll komb(int a, int b, int md);
ll mul(ll a, ll b, int md);
vector<ll> fact;
vector<ll> inv_fact;
void fact_init(int n, int md){
fact.resize(n+5);
inv_fact.resize(n+5);
fact[0] = inv_fact[0] = 1;
for(int i = 1; i <= n; i++){
fact[i] = (fact[i-1] * i) % md;
inv_fact[i] = exp(fact[i], md-2, md);
}
}
ll exp(ll taban, ll us, ll md) {
ll carpan = taban % md;
if(carpan == 0) return 0;
ll temp = us;
ll res = 1;
while(temp){
if(temp % 2) res = (res*carpan) % md;
temp /= 2;
carpan = (carpan*carpan) % md;
}
return res;
}
ll ebob(ll a, ll b){
if(!a)return b;
return ebob(b%a, a);
}
ll ekok(ll a, ll b){
return (a*b)/ebob(a, b);
}
ll komb(int a, int b, int md){
if(a < b) return 0;
return fact[a] * (inv_fact[a-b] * inv_fact[b] % md) % md;
}
ll mul(ll a, ll b, int md){
return a*b % md;
}
const int N = 2e5 + 5;
vector<vector<int>> g(N);
int a[N], b[N];
bool vis[N];
int main(){
ios::sync_with_stdio(false); cin.tie(NULL);
int n, m; cin>>n>>m;
for(int i = 1; i <= n; i++) cin>>a[i];
for(int i = 1; i <= n; i++) cin>>b[i];
for(int i = 0; i < m; i++){
int u, v; cin>>u>>v;
g[u].pb(v);
g[v].pb(u);
}
bool check = true;
for(int i = 1; i <= n; i++){
if(vis[i]) continue;
queue<int> q;
q.push(i);
vis[i] = true;
vector<int> cur_nodes;
while(!q.empty()){
int cur = q.front();
q.pop();
cur_nodes.pb(cur);
for(int node: g[cur]){
if(vis[node]) continue;
vis[node] = true;
q.push(node);
}
}
ll sum1 = 0, sum2 = 0;
for(int node: cur_nodes){
sum1 += a[node];
sum2 += b[node];
}
check &= sum1 == sum2;
}
cout<<(check ? "Yes\n" : "No\n");
} |
#include<bits/stdc++.h>
#define ll long long int
#define pii pair<int,pair<int,int> >
#define F first
#define S second
using namespace std;
#define mod 1000000007
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
///cout << "Case #"<<it<<": "<< res<< endl;
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
int t=1;///cin>>t;
while(t--){
int arr[4];
for(int i=0;i<4;i++) cin>>arr[i];
sort(arr,arr+4);
if(arr[3]==arr[0]+arr[1]+arr[2]){
cout<<"Yes"<<endl;
}else if(arr[3]+arr[0]==arr[1]+arr[2]){
cout<<"Yes"<<endl;
}else cout<<"No"<<endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define print(a) for(int i=0;i<(a.size());i++){cout<<a[i]<<"\n";}
#define sortt(a) sort(a.begin(),a.end())
#define loop(i,a,b) for(int i=0;i<n;i++)
#define int long long
#define pb push_back
#define mod 1000000007
#define PQ priority_queue
#define F first
#define S second
void S_G_()
{
string s;
cin>>s;
map<char,int>mp;
for(int i=0;i<3;i++)
{
mp[s[i]]++;
}
if(mp[s[0]]==3)
{
cout<<"Won"<<endl;
}
else
{
cout<<"Lost"<<endl;
}
}
signed main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
IOS;
int t=1;
// cin>>t;
while(t--)
{
S_G_();
}
cerr<<"time taken :"<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
} |
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
#define mp make_pair
#define pb push_back
#define ll long long
//#define debug(x) ;
#define debug(x) cerr << #x << " = " << x << "\n";
ostream& operator<<(ostream& cerr, vector<ll> aux) {
cerr << "[";
for (auto e : aux) cerr << e << ' ';
cerr << "]";
return cerr;
}
const int maxN = 3011;
ll mod = 998244353;
int n, k;
ll dp[maxN][maxN]; // i frac, j value
void add(ll& a, ll b) {
a += b;
if (a >= mod) a -= mod;
}
int main()
{
//freopen("test.in", "r", stdin);
cin >> n >> k;
dp[n][k] = 1;
for (int i = n; i >= 1; i--) {
for (int j = 1; j <= i; j++) {
if (dp[i][j] == 0) continue;
add(dp[i - 1][j - 1], dp[i][j]);
if (2 * j <= i)
add(dp[i][2 * j], dp[i][j]);
//cerr << i << ' ' << j << ' ' << dp[i][j] << '\n';
}
}
cout << dp[0][0];
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long i64;
typedef unsigned long long ui64;
typedef vector<i64> vi;
typedef vector<vi> vvi;
typedef pair<i64, i64> pi;
#define pb push_back
#define sz(a) i64((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)
inline void RI(i64 &i) {scanf("%lld", &(i));}
inline void RVI(vi &v) { for(i64 i=0;i<sz(v);++i) { RI(v[i]); } }
inline void RVVI(vvi &vv) { for(i64 i=0;i<sz(vv);++i) { RVI(vv[i]); } }
inline void WI(const i64 &i) {printf("%lld\n", i);}
inline void WVI(const vi &v, char sep=' ') { for(i64 i=0;i<sz(v);++i) { if(i != 0){ printf("%c", sep); } printf("%lld", v[i]);} printf("\n"); }
inline void WS(const string &s) { printf("%s\n", s.c_str()); }
inline void WB(bool b, const string &yes, const string &no) { if(b){ WS(yes);} else { WS(no);} }
inline void YESNO(bool b) { WB(b, "YES", "NO"); }
inline void YesNo(bool b) { WB(b, "Yes", "No"); }
#define BUF_LENGTH 1000000
inline void RS(string &s) {static char buf[BUF_LENGTH]; scanf("%s", buf); s = buf;}
template<typename T> inline bool IN(T &S, const typename T::key_type &key) {
return S.find(key) != S.end();
}
template<typename T> inline bool ON(const T &b, i64 idx) {
return ((T(1) << idx) & b) != 0;
}
struct graph {
using node_t = long long;
using weight_t = long long;
using edge_t = pair<node_t, weight_t>;
graph(node_t n) {
edges.resize(n);
}
virtual ~graph() {}
void add_edge(node_t i, node_t j, weight_t w=1) {
edges[i].push_back({j, w});
}
virtual vector<edge_t> get_edges(node_t n) const {
assert(n < get_num_nodes());
return edges[n];
}
int get_num_nodes() const {
return int(edges.size());
}
vector<vector<edge_t>> edges;
};
// dijkstra
i64 dijkstra(const graph &g, graph::node_t start) {
using node_t = graph::node_t;
using distance_t = graph::weight_t;
using flag_t = unsigned char;
const distance_t unreachable = -1;
using dn = pair<distance_t, node_t>;
priority_queue<dn, vector<dn>, greater<dn>> pq;
vector<distance_t> distances(g.get_num_nodes(), unreachable);
for(auto &e: g.get_edges(start)) {
node_t to = e.first;
distance_t w = e.second;
if(distances[to] == unreachable || w < distances[to]) {
distances[to] = w;
}
pq.push({distances[to], to});
}
while(!pq.empty()) {
dn cur_p = pq.top(); pq.pop();
int cur_d = cur_p.first, cur = cur_p.second;
if(distances[cur] != cur_d) {
continue;
}
for(auto &e: g.get_edges(cur)) {
node_t to = e.first;
distance_t w = e.second;
//cerr << cur << " -> " << to << ": " << w << endl;
if(distances[to] == unreachable || cur_d + w < distances[to]) {
distances[to] = cur_d + w;
pq.push({distances[to], to});
}
}
}
return distances[start];
}
int main(int argc, char *argv[]) {
i64 i, j, k;
i64 N, M; cin >> N >> M;
graph g(N);
REP(0, M, i) {
i64 a, b, c; RI(a); RI(b); RI(c); --a; --b;
g.add_edge(a, b, c);
}
REP(0, N, i) {
WI(dijkstra(g, i));
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using cd = complex<double>;
const double EPS = 1e-9;
bool isEq(double a, double b) {
return abs(a - b) < EPS;
}
bool operator==(cd a, cd b) {
return isEq(a.imag(), b.imag()) && isEq(a.real(), b.real());
}
bool operator!=(cd a, cd b) {
return !(a == b);
}
#ifdef _DEBUG
#define show(x) \
cerr << #x << " : "; \
showVal(x)
template <typename T>
void showVal(const T &a) { cerr << a << endl; }
template <typename T>
void showVal(const vector<T> &a) {
for (const T &v : a) cerr << v << " ";
cerr << endl;
}
template <typename T>
void showVal(const vector<vector<T>> &a) {
cerr << endl;
for (const vector<T> &v : a) showVal(v);
}
#else
#define show(x)
#endif
int main() {
int n;
cin >> n;
vector<cd> s(n), t(n);
for (int i = 0; i < n; i++) {
int a, b;
cin >> a >> b;
s[i] = cd(a, b);
}
for (int i = 0; i < n; i++) {
int a, b;
cin >> a >> b;
t[i] = cd(a, b);
}
if (n == 1) {
cout << "Yes" << endl;
return 0;
}
cd sg, tg;
for (int i = 0; i < n; i++) {
sg += s[i];
tg += t[i];
}
sg = cd(sg.real() / n, sg.imag() / n);
tg = cd(tg.real() / n, tg.imag() / n);
for (int i = 0; i < n; i++) {
s[i] -= sg;
t[i] -= tg;
}
cd sn = s[0];
if (sn == cd(0, 0)) {
sn = s[1];
}
for (int ti = 0; ti < n; ti++) {
if (!isEq(abs(sn), abs(t[ti]))) continue;
double th = arg(sn) - arg(t[ti]);
show(th);
bool ok = true;
for (int i = 0; i < n; i++) {
cd z = t[i] * polar<double>(1, th);
bool isEx = false;
for (int j = 0; j < n; j++) {
if (z == s[j]) {
isEx = true;
}
}
if (!isEx) {
ok = false;
}
}
if (ok) {
cout << "Yes" << endl;
return 0;
}
}
cout << "No" << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define reps(i,s,n) for (int i = (int)(s); i < (int)(n); i++)
#define repit(i,C) for (auto i = (C).begin(); i != (C).end(); i++)
#define pr(a) cout << a
#define prl(a) cout << (a) << endl
#define prld(a) cout << setprecision(15)<< (a) << endl
#define allrange(a) a.begin(),a.end()
bool solve_translated(vector<pair<int,int>> &S,vector<pair<int,int>> &T){
int N = S.size();
int dx = S[0].first-T[0].first;
int dy = S[0].second-T[0].second;
bool flg = true;
reps(i,1,N){
if(!((S[i].first==T[i].first+dx) && (S[i].second==T[i].second+dy))){flg = false; break;}
}
return flg;
}
/*ピタゴラ三角形
5 12 13
8 15 17
3 4 5
*/
vector<pair<int,int>> Pitagora_rot(vector<pair<int,int>> &S,int a, int b , int c){
int N = S.size();
vector<pair<int,int>> PS(N);
auto pt0 = S[0];
PS[0] = pt0;
bool flg = true;
reps(i,1,N){
int dx = S[i].first - pt0.first;
int dy = S[i].second - pt0.second;
if(((dx*b+dy*a)%c)!=0 || ((dx*a-dy*b)%c)!=0) {flg = false; break;}
PS[i] = make_pair((dx*a-dy*b)/c+pt0.first, (dx*b+dy*a)/c+pt0.second);
}
if(flg) return PS;
else return vector<pair<int,int>>();
}
int main(){
std::cin.tie(0); // cinとcoutの同期を解除
std::ios::sync_with_stdio(false);
int N;cin >> N;
vector<pair<int,int>> S(N),T(N);
rep(i,N)
{
int x,y;
cin >> x >> y;
S[i].first = x;S[i].second = y;
}
rep(i,N)
{
int x,y;
cin >> x >> y;
T[i].first = x;
T[i].second = y;
}
sort(allrange(T));
/*ピタゴラ三角形
5 12 13
8 15 17
3 4 5
*/
vector<vector<int>> tri(12);
tri[0]={0,1,1};
tri[1]={-1,0,1};
tri[2]={0,-1,1};
tri[3]={1,0,1};
tri[4]={3,4,5};
tri[5]={4,3,5};
tri[6]={-3,4,5};
tri[7]={-4,3,5};
tri[8]={-3,-4,5};
tri[9]={-4,-3,5};
tri[10]={3,-4,5};
tri[11]={4,-3,5};
/*
vector<vector<int>> tri(0);
tri.push_back(vector<int>({0,1,1}));
tri.push_back(vector<int>({-1,0,1}));
tri.push_back(vector<int>({0,-1,1}));
tri.push_back(vector<int>({1,0,1}));
tri.push_back(vector<int>({3,4,5}));
tri.push_back(vector<int>({4,3,5}));
tri.push_back(vector<int>({-3,4,5}));
tri.push_back(vector<int>({-4,3,5}));
tri.push_back(vector<int>({-3,-4,5}));
tri.push_back(vector<int>({-4,-3,5}));
tri.push_back(vector<int>({3,-4,5}));
tri.push_back(vector<int>({4,-3,5}));
*/
// tri.push_back(vector<int>({-5, -12, 13}));
// tri.push_back(vector<int>({-12, -5, 13}));
// tri.push_back(vector<int>({-8,-15,17}));
// tri.push_back(vector<int>({-15,-8,17}));
// tri.push_back(vector<int>({5, 12, 13}));
// tri.push_back(vector<int>({12, 5, 13}));
// tri.push_back(vector<int>({8,15,17}));
// tri.push_back(vector<int>({15,8,17}));
// tri.push_back(vector<int>({-5, 12, 13}));
// tri.push_back(vector<int>({-12, 5, 13}));
// tri.push_back(vector<int>({-8,15,17}));
// tri.push_back(vector<int>({-15,8,17}));
// tri.push_back(vector<int>({5, -12, 13}));
// tri.push_back(vector<int>({12, -5, 13}));
// tri.push_back(vector<int>({8,-15,17}));
// tri.push_back(vector<int>({15,-8,17}));
bool flg;
if(S.size()==2 && T.size()==2){
auto sx = S[0].first-S[1].first;
auto sy = S[0].second-S[1].second;
auto tx = T[0].first-T[1].first;
auto ty = T[0].second-T[1].second;
flg= (sx*sx+sy*sy==tx*tx+ty*ty);
} else {
rep(j,tri.size()){
auto S2 = Pitagora_rot(S,tri[j][0],tri[j][1],tri[j][2]);
if(S2.empty()) continue;
sort(allrange(S2));
flg = solve_translated(S2,T);
if(flg) break;
}
}
if(flg) prl("Yes"); else prl("No");
}
|
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
using namespace std;
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; }
typedef long long ll;
using P = pair<ll, int>;
const ll INF = 1e18;
struct Edge {
int to, t, k;
Edge(int to, int t, int k): to(to), t(t), k(k) {}
};
int main() {
int n, m, x, y;
cin >> n >> m >> x >> y;
--x; --y;
vector<vector<Edge>> g(n);
REP(i, m){
int a, b, t, k;
cin >> a >> b >> t >> k;
--a; --b;
g[a].emplace_back(b, t, k);
g[b].emplace_back(a, t, k);
}
vector<ll> dist(n, INF);
priority_queue<P, vector<P>, greater<P>> pq;
auto push = [&](int v, ll x){
if(dist[v] <= x) return;
dist[v] = x;
pq.emplace(x, v);
};
push(x, 0);
while(!pq.empty()){
auto [x, v] = pq.top(); pq.pop();
if(dist[v] != x) continue;
for(Edge& e : g[v]) {
ll nx = (x + e.k - 1)/e.k*e.k + e.t;
push(e.to, nx);
}
}
ll ans = dist[y];
if(ans == INF) ans = -1;
cout << ans << endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
const int N=5e5+10;
typedef long long ll;
int n,s[N],t[N],from[N];
char str[N];
set<int> pos[2];
ll ans;
int main() {
#ifdef LOCAL
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
#endif
ios::sync_with_stdio(0);cin.tie(0);
cin>>n>>(str+1);
for(int i=1;i<=n;i++) s[i]=str[i]-'0';
cin>>(str+1);
for(int i=1;i<=n;i++) t[i]=str[i]-'0';
for(int i=1;i<=n;i++) s[i]^=s[i-1],t[i]^=t[i-1],pos[s[i]].insert(i);
for(int i=1;i<=n;i++) {
auto it=pos[t[i]].lower_bound(max(from[i-1],i));
if(it==pos[t[i]].end()) return cout<<-1,0;
from[i]=*it;
}
for(int i=1;i<=n;i++)
if(from[i]!=from[i-1]) ans+=from[i]-i;
cout<<ans;
return 0;
}
|
#include <bits/stdc++.h>
#define NIL (-1)
#define ll long long
using namespace std;
const double PI = acos(-1.0);
int main() {
int N;
cin >> N;
bitset<100001> dp;
dp[0] = 1;
int tot = 0;
for (int i = 0; i < N; i++) {
int T;
cin >> T;
tot += T;
dp |= dp << T;
}
//cout << dp << endl;
//cout << tot << endl;
int ans = tot;
for (int i = 0; i < dp.size(); i++) if (dp[i]) ans = min(ans, max(i, (tot - i)));
cout << ans << endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
int main() {
int n;
int sum=0;
cin>>n;
int 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 = 0; i <n; i++)
{
if (a[0]<a[i])
{
a[0]=a[i];
}
if (b[0]>b[i])
{
b[0]=b[i];
}
}
for (int i = a[0]; i <=b[0]; i++)
{
sum++;
}
cout<<sum;
return 0;
} |
#pragma GCC target ("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define NN 60
constexpr ll M = 998244353;
vector<ll> edges[2][NN];
ll used[NN];
ll a[NN][NN];
ll f[NN];
ll dfs(ll u, bool t) {
used[u] = 1;
ll tot = 1;
for (auto v:edges[t][u]) if (!used[v])tot+=dfs(v, t);
return tot;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
f[0] = 1;
for (ll i=1; i<NN; ++i) f[i] = f[i-1]*i%M;
ll n, K;
cin>>n>>K;
for (ll i=0; i<n; ++i) for(ll j=0; j<n; ++j) cin>>a[i][j];
for (ll x=0; x<n; ++x) {
for (ll y=x+1; y<n; ++y) {
for (ll i=0; i<n; ++i) {
if (a[i][x]+a[i][y]>K) goto rfail;
}
edges[0][x].push_back(y);
edges[0][y].push_back(x);
rfail:;
for (ll i=0; i<n; ++i) {
if (a[x][i]+a[y][i]>K) goto cfail;
}
edges[1][x].push_back(y);
edges[1][y].push_back(x);
cfail:;
}
}
ll ans = 1;
for (ll i=0; i<n; ++i) if (!used[i]) ans = ans*f[dfs(i, 0)]%M;
memset(used, 0, sizeof used);
for (ll i=0; i<n; ++i) if (!used[i]) ans = ans*f[dfs(i, 1)]%M;
cout<<ans<<endl;
} | #include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std;
void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
int mod = 1000000007;
int add(int x, int y) { return (x += y) >= mod ? x - mod : x; }
template<class... T> int add(int x, T... y) { return add(x, add(y...)); }
int mul(int x, int y) { return 1LL * x * y % mod; }
template<class... T> int mul(int x, T... y) { return mul(x, mul(y...)); }
int sub(int x, int y) { return add(x, mod - y); }
int modpow(int a, long long b) {
int ret = 1; while (b > 0) {
if (b & 1) ret = 1LL * ret * a % mod; a = 1LL * a * a % mod; b >>= 1;
} return ret;
}
int modinv(int a) { return modpow(a, mod - 2); }
typedef vector<int> Vec;
typedef vector<Vec> Mat;
Vec mulMatVec(Mat a, Vec b)
{
int n = b.size(); Vec ret(n, 0);
rep(i, 0, n) rep(j, 0, n) ret[i] = add(ret[i], mul(a[i][j], b[j]));
return ret;
}
Mat mulMatMat(Mat a, Mat b)
{
int n = a.size(); Mat ret(n, Vec(n, 0));
rep(i, 0, n) rep(j, 0, n) rep(k, 0, n) ret[i][j] = add(ret[i][j], mul(a[i][k], b[k][j]));
return ret;
}
Mat fastpow(Mat x, ll n)
{
Mat ret(x.size(), Vec(x.size(), 0));
rep(i, 0, x.size()) ret[i][i] = 1;
while (0 < n) { if ((n % 2) == 0) { x = mulMatMat(x, x); n >>= 1; } else { ret = mulMatMat(ret, x); --n; } }
return ret;
}
void printVec(Vec a) { cout << "[\t"; rep(i, 0, a.size()) cout << a[i] << "\t"; cout << "]" << endl; }
void printMat(Mat a) { rep(i, 0, a.size()) printVec(a[i]); }
/*---------------------------------------------------------------------------------------------------
∧_∧
∧_∧ (´<_` ) Welcome to My Coding Space!
( ´_ゝ`) / ⌒i @hamayanhamayan0
/ \ | |
/ / ̄ ̄ ̄ ̄/ |
__(__ニつ/ _/ .| .|____
\/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/
int N, M, K, A[101];
int X[10101], Y[10101];
int cnt[101];
bool E[101][101];
//---------------------------------------------------------------------------------------------------
void _main() {
cin >> N >> M >> K;
rep(i, 0, N) cin >> A[i];
rep(i, 0, M) cin >> X[i] >> Y[i], X[i]--, Y[i]--;
Mat Ma(N, Vec(N));
rep(i, 0, M) {
cnt[X[i]]--;
cnt[Y[i]]--;
E[X[i]][Y[i]] = E[Y[i]][X[i]] = true;
}
rep(to, 0, N) {
int cnt = M;
rep(from, 0, N) if (to != from) {
if (E[to][from]) {
Ma[to][to] = add(Ma[to][to], mul(modinv(M), modinv(2)));
Ma[to][from] = add(Ma[to][from], mul(modinv(M), modinv(2)));
cnt--;
}
}
Ma[to][to] = add(Ma[to][to], mul(cnt, modinv(M)));
}
Vec v(N, 0);
rep(i, 0, N) v[i] = A[i];
Ma = fastpow(Ma, K);
v = mulMatVec(Ma, v);
rep(i, 0, N) cout << v[i] << endl;
}
|
#include <iostream>
#include <cmath>
#include <iomanip>
typedef long long ll;
using namespace std;
int main() {
int N, tmp;
ll mand = 0, powsum = 0, chebid = 0;
double eucd;
cin >> N;
for (int i = 0; i < N; i++) {
cin >> tmp;
mand += abs(tmp);
powsum += pow(tmp, 2);
if (chebid < abs(tmp)) {
chebid = abs(tmp);
}
}
eucd = sqrt(powsum);
cout << mand << endl;
cout << fixed << setprecision(10) <<eucd << endl;
cout << chebid << endl;
return 0;
}
| #include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <stack>
#include <queue>
#include <cassert>
#include <iomanip>
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 n;
cin >> n;
vector<int> x(n);
REP(i,n) cin >> x[i];
ll m=0;
ll eu=0;
ll che=0;
REP(i,n){
m += abs(x[i]);
eu += (ll)x[i]*x[i];
chmax(che, (ll)abs(x[i]));
}
long double ans = sqrt(eu);
printf("%Ld\n%.12Lf\n%Ld\n", m, ans, che);
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
int st[MAXN], ed[MAXN], idx;
vector<int> e[MAXN], h[MAXN];
void dfs(int u, int fa, int depth) {
st[u] = idx++;
h[depth].push_back(st[u]);
for (int v: e[u]) {
if (v == fa) continue;
dfs(v, u, depth + 1);
}
ed[u] = idx;
}
signed main(int argc, char *argv[]) {
int n;
cin >> n;
for (int i = 2; i <= n; ++i) {
int fa;
cin >> fa;
e[fa].push_back(i);
}
dfs(1, -1, 0);
int q;
cin >> q;
while (q--) {
int u, d;
cin >> u >> d;
#define ALL(vec) vec.begin(), vec.end()
cout << lower_bound(ALL(h[d]), ed[u]) - lower_bound(ALL(h[d]), st[u]) << '\n';
}
system("pause");
}
| #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long int
#define double long double
#define pb push_back
#define fi first
#define se second
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pii>
#define pqi priority_queue<int>
#define test int tcase; cin>>tcase; for(int tc = 1; tc <= tcase; tc++)
#define inp(a,n,f) vector<int> a(n+f);for(int hh=f;hh<n+f;hh++)cin>>a[hh];
#define printdecimal(k) cout<<fixed<<setprecision(k);
#define mem(a,k) memset(a,k,sizeof(a))
#define ub upper_bound
#define lb lower_bound
#define all(v) v.begin(),v.end()
#define mod (int)(1e9+7)
#define inf LLONG_MAX
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
int exp(int x,int y){int val=1;x=x%mod;while(y>0){if(y&1)val=(val*x)%mod;y=y>>1;x=(x*x)%mod;}return val;}
int modinv(int x){return exp(x,mod-2);}
int add(int a,int b){a%=mod,b%=mod;a=((a+b)%mod+mod)%mod;return a;}
int sub(int a,int b){a%=mod,b%=mod;a=((a-b)%mod+mod)%mod;return a;}
int mul(int a,int b){a%=mod,b%=mod;a=((a*b)%mod+mod)%mod;return a;}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n,ans=0;
cin>>n;
inp(a,n,0);
map<int, int> m;
for(int i:a)
ans+=m[i%200],m[i%200]++;
cout<<ans;
return 0;
} |
//Author: Fuadul Hasan(fuadul202@gmail.com)
//BSMRSTU,Gopalganj
//#include<bits/stdc++.h>
#define _USE_MATH_DEFINES
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <random>
#include <cassert>
#include <cstring>
#include <sstream>
#include <complex>
#include <numeric>
#include <iostream>
#include <algorithm>
#include <functional>
#include <unordered_set>
#include <unordered_map>
using namespace std;
//int input........
template <typename T> inline void readline(T &n) {n = 0; int f = 1; register int ch = getchar();
for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;for (; isdigit(ch);
ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';n = n * f;}
template <typename T, typename TT> inline void readline(T &n, TT &m) { readline(n); readline(m); }
template <typename T, typename TT, typename TTT> inline void readline(T &n, TT &m, TTT &l) { readline(n, m); readline(l);}
// long long input........
template <typename T> inline void readlinel(T &n) {n = 0; long long f = 1; register long long ch = getchar();
for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;for (; isdigit(ch);
ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';n = n * f;}
template <typename T, typename TT> inline void readlinel(T &n, TT &m) { readlinel(n); readlinel(m); }
template <typename T, typename TT, typename TTT> inline void readlinel(T &n, TT &m, TTT &l) { readlinel(n, m); readlinel(l);}
//debug..........
#define error(args...) {vector<string>_v=split(#args,',');err(_v.begin(),args);cout<<endl;}
vector<string> split(const string &s, char c) {vector<string>v; stringstream ss(s); string x;
while (getline(ss, x, c))v.emplace_back(x); return move(v);} void err(vector<string>::iterator it) {}
template<typename T, typename... Args>void err(vector<string>::iterator it, T a, Args...args) {
cout << it->substr((*it)[0] == ' ', it->length()) << " = " << a << " "; err(++it, args...);}
//............ignore it..................//
int dx[8]= {1,0,-1,0,-1,-1,1,1};int dy[8]= {0,1,0,-1,-1,1,-1,1}; int tc = 1;
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define Pi atan(1)*4
#define ll long long int
#define happy cin.tie(0);
#define point(x) setprecision(x)
#define coding ios::sync_with_stdio(false);
#define Test printf("Case %d: ",tc++);
#define Unique(c) (c).resize(unique(all(c))-(c).begin())
#define vout(v) for (auto z: v) cout << z << " "; cout << endl;
void print(int n){printf("%d\n", n);}
void Print(int n){printf("%d ", n);}
void print(int n,int m){printf("%d ",n);printf("%d ",m);}
void print(int n,int m,int k){printf("%d ",n);printf("%d ",m);printf("%d ",k);}
void print(ll n){printf("%I64d\n", n);}
void Print(ll n){printf("%I64d ", n);}
void print(ll n,ll m){printf("%I64d ",n);printf("%I64d ",m);}
void print(ll n,ll m,ll k){printf("%I64d ",n);printf("%I64d ",m);printf("%I64d ",k);}
int length(long long x){int l = 0;for(long long i=x;i;i/=10)l++;return l;}
int length(string s){return s.size();}
const int M = 1e9 + 7;
long long pow(long long a,long long n){ll res = 1;while(n){if(n&1) res = ((res%M)*(a%M))%M;a = ((a%M)*(a%M))%M;n>>=1;}return res%M;}
#define pr pair<int, int>
#define vpr vector<pr>
#define vi std::vector<int>
#define vll std::vector<ll>
#define all(n) n.begin(),n.end()
const int Inf = (int)2e9 + 5;
const ll Lnf = (ll)2e18 + 5;
const int N = 4e5 + 5;
const int NN = 1e6 + 5;
int solve()
{
//happy coding
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
int mn = 0;
map<int,int>vis;
for(int i=0;i<n;i++){
vis[a[i]] = 1;
if(vis[mn] == 0){
cout<<mn<<endl;
}else{
while(vis[mn])mn++;
cout<<mn<<endl;
}
}
return 0;
//error();
}
int main(){
int test = 1;
//readline(test);//(void)getchar();
while (test--)solve();return 0;
} | #include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
#define ll long long
int main(){
ll int N;
cin >> N;
vector<ll int> a(N);
for( ll int i = 0; i < N; i++){
cin >> a.at(i);
}
vector<ll int> sum_each_step(N);
ll int max_at_each_step = 0;
ll int max_point = 0;
// 1 ステップ目について
sum_each_step.at(0) = a.at(0);
if( sum_each_step.at(0) > 0){
max_at_each_step = sum_each_step.at(0);
max_point += max_at_each_step;
}
ll int last_point_pre_step = 0;
for( ll int i = 1; i < N; i++){
// 1 個前までのステップで進んだ点
last_point_pre_step += sum_each_step.at(i-1);
// i = 1 なら 0(1ステップ)までの進行 + 1 (2ステップ)での進行
sum_each_step.at(i) = sum_each_step.at(i-1) + a.at(i);
if( sum_each_step.at(i) > max_at_each_step ){
max_at_each_step = sum_each_step.at(i);
}
if( last_point_pre_step + max_at_each_step > max_point ){
max_point = last_point_pre_step + max_at_each_step;
}
}
cout << max_point;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define FOR(i, x, y) for(int i = (x); i < (y); ++i)
#define REP(i, x, y) for(int i = (x); i <= (y); ++i)
#define PB push_back
#define MP make_pair
#define PH push
#define fst first
#define snd second
typedef long long ll;
typedef unsigned long long ull;
typedef double lf;
typedef long double Lf;
typedef pair<int, int> pii;
const int maxn = 2e5 + 5;
const int maxk = 305;
const int INF = 998244353;
class Number{
public:
int dat;
Number(){}
Number(int dat_): dat(dat_){}
inline Number&operator += (const Number &oth){ (dat += oth.dat) -= (dat >= INF ? INF : 0); return *this; }
inline Number&operator -= (const Number &oth){ (dat -= oth.dat) += (dat < 0 ? INF : 0); return *this; }
inline Number&operator *= (const Number &oth){ dat = 1ll * dat * oth.dat % INF; return *this; }
inline Number operator + (const Number &oth)const{ Number ret = *this; ret += oth; return ret; }
inline Number operator - (const Number &oth)const{ Number ret = *this; ret -= oth; return ret; }
inline Number operator * (const Number &oth)const{ Number ret = *this; ret *= oth; return ret; }
}a[maxn], binom[maxk][maxk], pw[2][maxn], s[maxk];
const Number inv2 = (INF + 1) / 2;
int n, k;
inline void precalc(){
int p = 0, q = 1;
REP(i, 0, k){
binom[i][0] = 1;
REP(j, 1, i)
binom[i][j] = binom[i - 1][j - 1] + binom[i - 1][j];
FOR(j, 0, n){
pw[q][j] = (!i ? 1 : pw[p][j] * a[j]);
s[i] += pw[q][j];
}
swap(p, q);
}
return;
}
int main(){
scanf("%d%d", &n, &k);
FOR(i, 0, n)
scanf("%d", &a[i].dat);
precalc();
REP(x, 1, k){
Number ans = 0;
REP(i, 0, x){
Number res = s[i] * s[x - i] - s[x];
ans += res * binom[x][i];
}
printf("%d\n", (ans * inv2).dat);
}
return 0;
}
| #include <bits/stdc++.h>
// clang-format off
using namespace std; using ll = int64_t; using ull = uint64_t; const ll INF = 9e18;
void print0() {}
template<typename Head,typename... Tail> void print0(Head head,Tail... tail){cout<<fixed<<setprecision(15)<<head;print0(tail...);}
void print() { print0("\n"); }
template<typename Head,typename... Tail>void print(Head head,Tail... tail){print0(head);if(sizeof...(Tail)>0)print0(" ");print(tail...);}
// clang-format on
const ll MODULO = 998244353;
ll mod_minus(ll x, ll modval) {
if (x >= 0) {
return x % modval;
} else {
ll mm = ((-x) % modval);
if (mm == 0) {
return 0;
} else {
return modval - mm;
}
}
}
ll mod(ll x) {
return mod_minus(x, MODULO);
}
const ll COMBMAX = 212345;
ll fac[COMBMAX], finv[COMBMAX], inv[COMBMAX];
void combination_init() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < COMBMAX; i++) {
fac[i] = fac[i - 1] * i % MODULO;
inv[i] = MODULO - inv[MODULO % i] * (MODULO / i) % MODULO;
finv[i] = finv[i - 1] * inv[i] % MODULO;
}
}
ll combination(ll n, ll k) {
if (n < k) return 0;
if (n < 0 || k < 0) return 0;
return fac[n] * (finv[k] * finv[n - k] % MODULO) % MODULO;
}
int main() {
ll N, K;
cin >> N >> K;
vector<ll> a(N);
for (ll i = 0; i < N; i++) {
cin >> a[i];
}
vector<ll> apow(N, 1);
vector<ll> powsum(K + 1, 0);
powsum[0] = N;
for (ll k = 1; k <= K; k++) {
for (ll i = 0; i < N; i++) {
apow[i] = (apow[i] * a[i]) % MODULO;
powsum[k] = (powsum[k] + apow[i]) % MODULO;
}
}
combination_init();
for (ll k = 1; k <= K; k++) {
ll result = 0;
for (ll m = 0; m <= k; m++) {
ll v = 0;
v = mod(powsum[m] * powsum[k - m]);
v = mod(v - powsum[k]);
v = mod(combination(k, k - m) * v);
result = mod(v + result);
}
result = mod(finv[2] * result);
print(result);
}
}
|
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <string>
#include <numeric>
#include <ctype.h>
#include <limits>
#include <iomanip>
#define rep(i,n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
int main()
{
int n, q;
cin >> n >> q;
vector<ll>a(n);
rep(i, n)cin >> a[i];
sort(all(a));
ll k;
rep(i, q) {
cin >> k;
ll ans;
ll l = k - 2;
ll r = k + n + 2;
ll c;
while (l + 1 < r) {
c = (l + r) / 2;
auto itr = upper_bound(all(a), c);
if (c - ll(itr - a.begin())>= k)r = c;
else l = c;
}
ans = r;
cout << ans << endl;
}
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using pii = pair<int, int>;
int main() {
int n, q;
cin >> n >> q;
vector<ll> a(n + 1);
for (int i = 1; i <= n; i++) cin >> a[i];
a.push_back(2e18);
vector<ll> s(n + 2);
rep(i, n + 1) {
s[i + 1] = s[i] + a[i + 1] - a[i] - 1;
}
rep(i, q) {
ll k;
cin >> k;
auto itr = lower_bound(s.begin(), s.end(), k) - s.begin();
itr--;
k -= s[itr];
ll ans = a[itr] + k;
cout << ans << endl;
//cout << s[itr] << endl;
}
return 0;
} |
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
string s;
cin >> s;
long long int n = s.length();
long long int one = 0, two = 0, sum = 0;
for (long long int i = 0; i < n; i++)
{
int num = s[i] - 48;
if (num % 3 == 1)
one++;
else if (num % 3 == 2)
two++;
sum += num;
}
int res = -2;
if (sum % 3 == 0)
res = 0;
else {
if (abs(two - one) < n)
{
res = abs(two - one);
}
two = two % 3;
one = one % 3;
if (abs(two - one) < n)
res = abs(two - one) > res ? res : abs(two - one);
}
if (res == -2)
res = -1;
cout << res << endl;
} | #include<bits/stdc++.h>
#define pu push
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define rrep(i,x) for(int i=1;i<=x;i++)
#define drep(i,n) for(int i = (n)-1; i >= 0; i--)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define BITSC(x,v) (binary_search(x.begin(),x.end(),v)
#define dup(x,y) (((x)+(y)-1)/(y))
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
int getInt(){int x;scanf("%d",&x);return x;}
template<typename T>istream& operator>>(istream&i,v(T)&v){rep(j,sz(v))i>>v[j];return i;}
const double eps =1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
int main(){
string n;cin>>n;
int ans=2000;
srep(i,1,(1<<n.size())){
int temp=0;
int count=0;
rep(j,n.size()){
if((1<<j)&i){
temp+=n[j];
count++;
}
}
if(temp%3==0&&ans>n.size()-count)ans=n.size()-count;
}
if(ans==2000)cout<<-1<<endl;
else cout<<ans<<endl;
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<ll,ll> Pair;
typedef tuple<int,int,int> tpl;
#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)
#define en "\n"
constexpr double EPS = 1e-9;
constexpr double PI = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}
ll solve1(VL& g, VL& b){
int ng = g.size(), nb = b.size(), pos = 0;
ll ret = LINF;
REP(i,nb){
while(pos<ng-1 && abs(b[i]-g[pos]) > abs(b[i]-g[pos+1])) pos++;
chmin(ret, abs(b[i]-g[pos]));
}
return ret;
}
VL f(VL& b, VL& v){
int n = b.size(), m = v.size(), pos = 0;
VL ret(n);
REP(i,n){
while(pos<m-1 && abs(v[pos]-b[i]) > abs(v[pos+1]-b[i])) pos++;
ret[i] = abs(v[pos]-b[i]);
}
return ret;
}
ll solve2(VL& r, VL& g, VL& b){
int n = b.size(), nr = r.size(), ng = g.size();
if(n==0) return LINF;
VL dr = f(b,r), dg = f(b,g);
VI pr(n), pg(n); REP(i,n) pr[i] = pg[i] = i;
auto cr = [&](int i, int j){return dr[i]<dr[j];};
auto cg = [&](int i, int j){return dg[i]<dg[j];};
sort(ALL(pr), cr); sort(ALL(pg), cg);
ll ret = LINF;
if(pr[0] != pg[0]) chmin(ret, dr[pr[0]] + dg[pg[0]]);
else chmin(ret, min(dr[pr[0]]+dg[pg[1]], dr[pr[1]]+dg[pg[0]]));
return ret;
}
void Main(){
int N; cin >> N;
int M = N<<1, nr=0, ng=0, nb=0;
VL r,g,b; vector<char> c(M);
REP(i,M){
ll a; char c;
cin >> a >> c;
if(c=='R') nr++, r.push_back(a);
else if(c=='G') ng++, g.push_back(a);
else nb++, b.push_back(a);
}
if(nr%2 + ng%2 + nb%2 == 0){
cout << 0 << en;
return;
}
SORT(r); SORT(g); SORT(b);
if(nr%2 == 0) swap(r,b);
else if(ng%2 == 0) swap(g,b);
ll ans = solve1(r,g);
chmin(ans, solve2(r,g,b));
cout << ans << en;
return;
}
int main(void){
cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
int t=1; //cin>>t;
while(t--) Main();
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MOD int(1e9+7)
#define INF int(1e9+7)
#define LINF ll(1e18+7)
#define PI acos(-1)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define P pair<ll,ll>
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))
int n;
int Mat[550][550];
int main(){
cin>>n;
rep(i,n)rep(j,n) cin>>Mat[i][j];
vector<int> a(n),b(n);
a[0]=0;
b[0]=Mat[0][0]-a[0];
bool ok=1;
rep(i,n) a[i]=Mat[i][0]-b[0];
rep(j,n) b[j]=Mat[0][j]-a[0];
rep(i,n)rep(j,n){
if(a[i]+b[j]!=Mat[i][j]) ok=0;
}
int amin=INT_MAX, bmin=INT_MAX;
rep(i,n) chmin(amin,a[i]);
rep(i,n) chmin(bmin,b[i]);
if(amin<0 && bmin<0) ok=0;
else if(amin<0){
rep(i,n) a[i]+=abs(amin);
rep(i,n){
b[i]-=abs(amin);
if(b[i]<0) ok=0;
}
}else if(bmin<0){
rep(i,n) b[i]+=abs(bmin);
rep(i,n){
a[i]-=abs(bmin);
if(a[i]<0) ok=0;
}
}
if(ok){
cout<<"Yes"<<endl;
rep(i,n) cout<<a[i]<<" "; cout<<endl;
rep(i,n) cout<<b[i]<<" "; cout<<endl;
}else{
cout<<"No"<<endl;
}
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
bool solve() {
int n, m, t;
cin >> n >> m >> t;
vector<int> a(m), b(m);
int bat = n;
int time = 0;
rep(i, m) {
cin >> a[i] >> b[i];
bat -= (a[i] - time);
if (bat <= 0) return false;
bat = min(bat + b[i] - a[i], n);
time = b[i];
}
bat -= t - time;
if (bat <= 0) return false;
return true;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout << (solve() ? "Yes" : "No") << endl;
return 0;
} | #define rep(i, n) for(int i = 0; i < (int)(n); i++)
#include <iostream>
#include <string>
#include <algorithm>
#include<vector>
#include<cmath>
using namespace std;
int main(){
int n,m,t;
string ans = "Yes";
cin >> n >> m >> t;
int power = n;
int nt = 0;
rep(i,m){
int a,b;
cin >> a >> b;
power -= (a -nt);
if(power <= 0){
ans = "No";
break;
}
//cout << power << endl;
power = min(n,power + (b-a));
//cout << power << endl;
nt = b;
}
if(power -(t -nt) <=0){
ans = "No";
}
cout << ans << endl;
} |
#include <bits/stdc++.h>
using namespace std;
typedef pair<long long, int> P;
struct edge{
int to;
long long cost;
long long time;
};
int main(){
int N, M, X , Y;
cin >> N >> M >> X >> Y;
X--;
Y--;
vector<vector<edge>> G(N);
for(int i = 0; i < M; i++){
int A, B;
cin >> A >> B;
A--;
B--;
long long T, K;
cin >> T >> K;
G[A].push_back({B, T, K});
G[B].push_back({A, T, K});
}
long long INF = 1e18;
priority_queue<P, vector<P>, greater<P>> q;
vector<long long> d(N, INF);
d[X] = 0;
q.push(P(0, X));
while(!q.empty()){
P v = q.top();
q.pop();
if(d[v.second] < v.first) continue;
for(edge e: G[v.second]){
long long t = (v.first + e.time - 1) / e.time * e.time;
if(d[e.to] > t + e.cost){
d[e.to] = t + e.cost;
q.push(P(d[e.to], e.to));
}
}
}
if(d[Y] == INF) cout << -1 << endl;
else cout << d[Y] << endl;
} | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ll n,m,x,y;
cin>>n>>m>>x>>y;
vector<ll> adj[n+1],dis[n+1],tim[n+1],ans(n+1);
for(ll i=0;i<m;i++){
ll a,b,c,d;
cin>>a>>b>>c>>d;
adj[a].push_back(b);
adj[b].push_back(a);
dis[a].push_back(c);
dis[b].push_back(c);
tim[a].push_back(d);
tim[b].push_back(d);
}
for(ll i=1;i<n+1;i++)
ans[i]=-1;
ans[x]=0;
queue<ll> q;
q.push(x);
while(!q.empty()){
ll x1=q.front();
q.pop();
for(ll i=0;i<adj[x1].size();i++){
ll x2=ans[x1];
if(x2%tim[x1][i]!=0){
x2+=tim[x1][i]-(x2%tim[x1][i]);
}
if((ans[adj[x1][i]]==-1)||(x2+dis[x1][i]<ans[adj[x1][i]])){
ans[adj[x1][i]]=x2+dis[x1][i];
q.push(adj[x1][i]);
}
}
}
cout<<ans[y];
return 0;
} |
#include <bits/stdc++.h>
#include<vector>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
int main(){
string s;
cin>>s;
for(int i=s.size()-1;0<=i;i--){
if(s[i]=='6'){
cout<<'9';
}else if(s[i]=='9'){
cout<<'6';
}else{
cout<<s[i];
}
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)
#define ture ture
#define flase false
#define falg flag
#define REP(i, x) for (ll i = 0; i < (ll)(x); i++)
#define REPS(i, x) for (ll i = 1; i <= (ll)(x); i++)
#define RREP(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (ll i = ((ll)(x)); i > 0; i--)
#define all(x) (x).begin(), (x).end()
const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;//llの最大9*10^18
const int INF = pow(2, 30) - 1;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
ll N;
string S;
cin >> S;
reverse(S.begin(), S.end());
REP(i,S.size()){
if(S.at(i)=='6'){
cout << '9';
}
else if (S.at(i) == '9'){
cout << '6';
}
else{
cout << S.at(i);
}
}
cout << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define MP make_pair
#define PB push_back
#define REP(i, L, R) for (int i = L; i < (R); ++i)
#define SZ(x) (int)x.size()
using ll = long long;
using ld = long double;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
template <typename T>
bool ckmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; }
template <typename T>
bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
vector<int> compress(vector<int> &y)
{
vector<int> v(y);
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
for (int i = 0; i < SZ(y); ++i)
{
y[i] = lower_bound(v.begin(), v.end(), y[i]) - v.begin();
}
return v;
}
struct bit
{
int n;
vector<ll> v;
void init(int sz)
{
n = sz;
v.assign(n + 1, 0);
}
// sum([0..i])
ll prefix_sum(int i)
{
// internally we use 1-based index
int _i = i + 1;
ll s = 0LL;
while (_i)
{
s += v[_i];
_i -= (_i & -_i);
}
return s;
}
// sum([i..end])
ll suffix_sum(int i)
{
if (i == 0)
{
return prefix_sum(n - 1);
}
return prefix_sum(n - 1) - prefix_sum(i - 1);
}
void incr(int i, ll a)
{
// internally we use 1-based indexing
int _i = i + 1;
while (_i <= n)
{
v[_i] += a;
_i += (_i & -_i);
}
}
};
const int MAXN = 200005;
void solve()
{
int n, m, q;
cin >> n >> m >> q;
vector<int> t(q + 1), x(q + 1), y(q + 1, 0);
vector<int> a(n, 0), b(m, 0);
REP(i, 1, q + 1)
{
cin >> t[i] >> x[i] >> y[i];
--x[i]; // 0-based index
}
auto vy = compress(y);
// NOTE 1(coordinate compression): after compression, y is compressed to [0, q] and vy maps from a compressed y in [0,q] to its original value.
// r1[i] = #i in b; r2[i] = sum of all i's in b.
// c1[i] = #i in a; c2[i] = sum of all i's in a.
bit r1, r2, c1, c2;
r1.init(MAXN);
r2.init(MAXN);
c1.init(MAXN);
c2.init(MAXN);
// Initially, all b are 0
r1.incr(0, m);
// Initially, all a are 0
c1.incr(0, n);
ll ans = 0LL;
REP(i, 1, q + 1)
{
if (t[i] == 1)
{
// a[x[i]] = y[i]
int v = a[x[i]];
ans -= vy[v] * r1.prefix_sum(v);
ans -= r2.suffix_sum(v + 1);
c1.incr(v, -1);
c2.incr(v, -vy[v]);
a[x[i]] = y[i];
c1.incr(y[i], 1);
c2.incr(y[i], vy[y[i]]);
ans += vy[y[i]] * r1.prefix_sum(y[i]);
ans += r2.suffix_sum(y[i] + 1);
}
else
{
// b[x[i]] = y[i]
int v = b[x[i]];
ans -= vy[v] * c1.prefix_sum(v);
ans -= c2.suffix_sum(v + 1);
r1.incr(v, -1);
r2.incr(v, -vy[v]);
b[x[i]] = y[i];
r1.incr(y[i], 1);
r2.incr(y[i], vy[y[i]]);
ans += vy[y[i]] * c1.prefix_sum(y[i]);
ans += c2.suffix_sum(y[i] + 1);
}
cout << ans << endl;
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int T = 1;
while (T--)
{
solve();
}
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &x){
x=0;char ch=getchar();bool f=false;
while(!isdigit(ch)){if(ch=='-'){f=true;}ch=getchar();}
while(isdigit(ch)){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
x=f?-x:x;
return ;
}
template <typename T>
inline void write(T x){
if(x<0) putchar('-'),x=-x;
if(x>9) write(x/10);
putchar(x%10^48);
return ;
}
#define ll long long
const int N=2e5+5,M=1e8;
int n,m,q;
ll a[N],b[N];
struct SGTree{
int cur,root;
ll sum[N*80];
int num[N*80],ls[N*80],rs[N*80];
void Modify(int &x,int l,int r,int pos,int v,int tp){
if(!x) x=++cur;
int mid=l+r>>1;sum[x]+=v*tp;num[x]+=tp;
if(l==r) return ;
if(pos<=mid) Modify(ls[x],l,mid,pos,v,tp);
else Modify(rs[x],mid+1,r,pos,v,tp);
return ;
}
ll QuerySum(int x,int l,int r,int ql,int qr){
if(ql>qr||!x) return 0;
if(ql<=l&&r<=qr) return sum[x];
int mid=l+r>>1;ll res=0;
if(ql<=mid) res+=QuerySum(ls[x],l,mid,ql,qr);
if(qr>mid) res+=QuerySum(rs[x],mid+1,r,ql,qr);
return res;
}
int QueryNum(int x,int l,int r,int ql,int qr){
if(ql>qr||!x) return 0;
if(ql<=l&&r<=qr) return num[x];
int mid=l+r>>1,res=0;
if(ql<=mid) res+=QueryNum(ls[x],l,mid,ql,qr);
if(qr>mid) res+=QueryNum(rs[x],mid+1,r,ql,qr);
return res;
}
}t1,t2;
ll Ans;
int main(){
read(n),read(m),read(q);
for(int i=1;i<=n;i++) t1.Modify(t1.root,0,M,a[i],a[i],1);
for(int i=1;i<=m;i++) t2.Modify(t2.root,0,M,b[i],b[i],1);
// for(int i=1;i<=n;i++){
// Ans+=1ll*t2.QueryNum(t2.root,0,M,1,a[i])*a[i];
// Ans+=1ll*t2.QuerySum(t2.root,0,M,a[i]+1,M);
// }
for(int i=1;i<=q;i++){
int op,pos;ll v;
read(op),read(pos),read(v);
if(op==1){
Ans-=1ll*t2.QueryNum(t2.root,0,M,0,a[pos])*a[pos];
Ans-=1ll*t2.QuerySum(t2.root,0,M,a[pos]+1,M);
t1.Modify(t1.root,0,M,a[pos],a[pos],-1);
a[pos]=v;
Ans+=1ll*t2.QueryNum(t2.root,0,M,0,a[pos])*a[pos];
Ans+=1ll*t2.QuerySum(t2.root,0,M,a[pos]+1,M);
t1.Modify(t1.root,0,M,a[pos],a[pos],1);
}
else{
Ans-=1ll*t1.QueryNum(t1.root,0,M,0,b[pos])*b[pos];
Ans-=1ll*t1.QuerySum(t1.root,0,M,b[pos]+1,M);
t2.Modify(t2.root,0,M,b[pos],b[pos],-1);
b[pos]=v;
Ans+=1ll*t1.QueryNum(t1.root,0,M,0,b[pos])*b[pos];
Ans+=1ll*t1.QuerySum(t1.root,0,M,b[pos]+1,M);
t2.Modify(t2.root,0,M,b[pos],b[pos],1);
}
write(Ans),putchar('\n');
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int H, W;
char A[2000][2001];
int dp[2000][2000];
int main() {
scanf("%d %d", &H, &W);
for (int i = 0;i < H;i++) {
scanf("%s", A[i]);
}
dp[H - 1][W - 1] = 0;
for (int i = W - 2;i >= 0;i--) {
dp[H - 1][i] = (A[H - 1][i + 1] == '+' ? 1 : -1) - dp[H - 1][i + 1];
}
for (int i = H - 2;i >= 0;i--) {
dp[i][W - 1] = (A[i + 1][W - 1] == '+' ? 1 : -1) - dp[i + 1][W - 1];
}
for (int i = H - 2;i >= 0;i--) {
for (int j = W - 2;j >= 0;j--) {
dp[i][j] = max((A[i][j + 1] == '+' ? 1 : -1) - dp[i][j + 1], (A[i + 1][j] == '+' ? 1 : -1) - dp[i + 1][j]);
}
}
if (dp[0][0] > 0)printf("Takahashi\n");
else if (dp[0][0] == 0)printf("Draw\n");
else {
printf("Aoki\n");
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
int H,W;
vector<vector<char>> A;
vector<vector<ll>> dp(2000,vector<ll>(2000));
int f(int y,int x){
int p;
if(A[y][x] == '+') p=1;
else p=-1;
if((x+y)%2==0) p*=-1;
return p;
}
int main(){
cin>>H>>W;
A.resize(H);
for(int i=0;i<H;i++) A[i].resize(W);
for(int i=0;i<H;i++) for(int j=0;j<W;j++) cin>>A[i][j];
for(int i=H-1;i>=0;i--){
for(int j=W-1;j>=0;j--){
if(i==H-1&&j==W-1) dp[i][j] = 0;
else if(i==H-1) dp[i][j] = dp[i][j+1]+f(i,j+1);
else if(j==W-1) dp[i][j] = dp[i+1][j]+f(i+1,j);
else{
if((i+j)%2==0) dp[i][j] = max(dp[i][j+1]+f(i,j+1),dp[i+1][j]+f(i+1,j));
else dp[i][j] = min(dp[i][j+1]+f(i,j+1),dp[i+1][j]+f(i+1,j));
}
}
}/*
for(int i=0;i<H;i++){
for(int j=0;j<W;j++){
printf("%3d",dp[i][j]);
}
cout<<"\n";
}
*/
if(dp[0][0] > 0) cout<<"Takahashi";
else if(dp[0][0] < 0) cout<<"Aoki";
else cout<<"Draw";
} |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int n = s.length();
string result = "";
for (int j = 0; j < n; j++) {
int i = n - 1 - j;
if (s[i] == '0')
result += "0";
if (s[i] == '1')
result += "1";
if (s[i] == '6')
result += "9";
if (s[i] == '8')
result += "8";
if (s[i] == '9')
result += "6";
}
cout << result << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());
typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vi> vvi;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 29);
const ll LINF = 1e18;
const double PI = acos(-1);
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 V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
for (auto& e : t) fill_v(e, v);
}
template<class T> bool chmax(T& a, const T& b) {
if (a < b) { a = b; return 1; }
return 0;
}
template<class T> bool chmin(T& a, const T& b) {
if (a > b) { a = b; return 1; }
return 0;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int X;
cin >> X;
cout << 100 - (X % 100) << endl;
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define PI 3.1415926535897932384626
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
//=======================
const int MOD = 1000000007;
const int N = 2e6+13, M = N;
//=======================
vi g[N];
int arr[N];
vi a;
int n, m, k;
//=======================
void solve() {
int i, j, sx, sy, gx, gy;
cin >> sx >> sy >> gx >> gy;
double ans = 1.0 * sy * gx;
ans += 1.0*gy*sx;
ans = ans / (1.0*(sy + gy));
cout << setprecision(10) << fixed;
cout << ans << endl;
}
int main() {
ios_base::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 t = 1;
while(t--) {
solve();
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for (int i = 0; i < (int)(n) ; i++)
#define rep2(i,a,b) for (int i = (a); i < (int)(b); i++)
#define Rrep(i,n) for (int i = (n); i >= 0; i--)
#define ENDL '\n'
#define SZ(a) (int)(a.size())
#define all(a) a.begin(),a.end()
ll powi(ll x,ll y) { //繰り返し二乗法
if(y==0) return 1;
if(y==1) return x;
if(y%2==1) return x*pow(x,y-1);
ll rt = pow(x,y/2);
return rt*rt;
}
ll score(string s, ll n) {
n++;
s.at(4) = to_string(n).at(0);
vector<ll> ci(9,0);
rep(i,5) ci.at(s.at(i)-'0'-1)++;
ll ret=0;
rep(i,9) {
ret+=(i+1)*powi(10,ci.at(i));
}
return ret;
}
int main() {
cout << fixed << setprecision(20);
ll k; cin >> k;
string s, t; cin >> s >> t;
vector<ll> cards(9,k);
rep(i,4) cards.at(s.at(i)-'0'-1)--;
rep(i,4) cards.at(t.at(i)-'0'-1)--;
/*
ld all = 0;
rep(i,9) {
rep(j,9) {
if (i==j) {
if(cards.at(i) <2) continue;
all += cards.at(i)*(cards.at(i)-1);
}
else all += cards.at(i)*cards.at(j);
}
}
*/
ld win = 0;
rep(i,9) {
rep(j,9) {
if(cards.at(i) && cards.at(j)) {
if(score(s,i)>score(t,j)) {
win+=cards.at(i)*(cards.at(j)-(i==j));
/*
if (i==j) {
if(cards.at(i)<2) continue;
win += cards.at(i)*(cards.at(i)-1);
}
else win += cards.at(i)*cards.at(j);
*/
}
}
}
}
ll rem=9*k-8;
cout << win/rem/(rem-1) << endl;
} |
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int INF = 1001001001;
int main() {
int n, s, d;
cin >> n >> s >> d;
vector<int>x(n), y(n);
rep(i,n) cin >> x[i] >> y[i];
bool OK = false;
rep(i,n){
if(x[i] < s && y[i] > d) OK = true;
}
if(OK) puts("Yes");
else puts("No");
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define ll long long
// memo fixed setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1e9+7;
/*"itob" int to "N"base */ template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/ template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/ template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi" char to int*/ int ctoi(char c) {return c-'0';}
/*"gcd" MAX Euclidean */ ll gcd(ll a,ll b){if(b==0)return a; return gcd(b,a%b);}
/*"lcm" MIN*/ ll lcm(ll a,ll b){ll g = gcd(a,b);return a/g*b;}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
ll modpow(ll a,ll n, ll mod){ll res = 1;while(n>0){if (n%2==1){res = res * a % mod;}a = a * a % mod;n/=2;}return res;}
int main() {
ll n,s,d;
cin >>n >>s>>d;
for(int i=0;i<n;i++){
ll a,b;
cin >>a>>b;
if(a<s&&b>d){cout<<"Yes"<<endl;return 0 ;}
}
cout<<"No"<<endl;
}
|
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
int modd=998244353;
int a,b,c;
cin>>a>>b>>c;
a=a*(a+1);
a=a/2;
b=b*(b+1);
b=b/2;
c=c*(c+1);
c=c/2;
a=a%modd;
b=b%modd;
c=c%modd;
a=(a*b)%modd;
a=(a*c)%modd;
cout<<a;
}
| #pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// #include<ext/pb_ds/tag_and_trait.hpp>
// using namespace __gnu_pbds;
// #include<boost/multiprecision/cpp_int.hpp>
// namespace multiprecisioninteger = boost::multiprecision;
// using cint=multiprecisioninteger::cpp_int;
using namespace std;
using ll=long long;
#define double long double
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
// using llset=tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>;
#define For(i,a,b) for(i=a;i<(ll)b;++i)
#define bFor(i,b,a) for(i=b,--i;i>=(ll)a;--i)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N,0)
#define brep1(i,N) bFor(i,N,1)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define eb emplace_back
#define print(x) cout<<x<<endl
#define printyes print("Yes")
#define printno print("No")
#define printYES print("YES")
#define printNO print("NO")
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
#define matoutput(v) do{for(auto outimat:v)output(outimat);}while(0)
// const ll mod=1000000007;
const ll mod=998244353;
const ll inf=1LL<<60;
const double PI=acos(-1);
const double eps=1e-9;
template<class T,class E> ostream& operator<<(ostream& os,pair<T,E>& p){return os<<"{"<<p.first<<","<<p.second<<"}";}
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;}
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;}
void startupcpp(){
cin.tie(0);
ios::sync_with_stdio(false);
cout<<fixed<<setprecision(15);
}
double distance(ddatas x,ddatas y){
double a=x.first-y.first,b=x.second-y.second;
return sqrt(a*a+b*b);
}
ll modinv(ll a,ll m=mod) {
ll b=m,u=1,v=0,t;
while(b){
t=a/b;
a-=t*b; swap(a,b);
u-=t*v; swap(u,v);
}
return (u+m)%m;
}
ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}
vec modncrlistp,modncrlistm;
ll modncr(ll n,ll r){
if(n<r)return 0;
ll i,size=modncrlistp.size();
if(size<=n){
modncrlistp.resize(n+1);
modncrlistm.resize(n+1);
if(!size){
modncrlistp[0]=modncrlistm[0]=1;
size++;
}
For(i,size,n+1){
modncrlistp[i]=modncrlistp[i-1]*i%mod;
modncrlistm[i]=modinv(modncrlistp[i]);
}
}
return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}
ll modpow(ll a,ll n,ll m=mod){
ll res=1;
while(n>0){
if(n&1)res=res*a%m;
a=a*a%m;
n>>=1;
}
return res;
}
ll gcd(ll a,ll b){if(!b)return abs(a);return (a%b==0)?abs(b):gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll countdigits(ll n){
ll ans=0;
while(n){n/=10;ans++;}
return ans;
}
ll sumdigits(ll n){
ll ans=0;
while(n){ans+=n%10;n/=10;}
return ans;
}
ll N,M,K,H,W,A,B,C,D;
string s,t;
ll ans;
int main(){
startupcpp();
// int codeforces;cin>>codeforces;while(codeforces--){
ll i,j;
cin>>A>>B>>C;
A=(1+A)*A/2%mod;
B=(1+B)*B/2%mod;
C=(1+C)*C/2%mod;
print(A*B%mod*C%mod);
// }
} |
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
#define rep(i,n) for(int i=0; i<(int)n; i++)
#define llrep(i,n) for(ll i=0; i<(ll)n; i++)
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてから使う
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define kiriage(x,y) (((x)+(y)-1)/(y))
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vp;
int main(){
int n; cin>>n;
vector<pair<int, int>> x(n), y(n);
rep(i,n){
cin>>x[i].first>>y[i].first;
x[i].second = i;
y[i].second = i;
}
//fiが座標、seは何個目の組か
sort(x.rbegin(), x.rend());
sort(y.rbegin(), y.rend());
//座標で降順ソート
vector<tuple<ll, int, int>> t;
vi one = {0,0,1};
vi two = {n-1,n-2,n-1};
llrep(i,3){
ll nowx = abs(x[one[i]].first-x[two[i]].first);
ll nowy = abs(y[one[i]].first-y[two[i]].first);
t.emplace_back(nowx, x[one[i]].second, x[two[i]].second);
t.emplace_back(nowy, y[one[i]].second, y[two[i]].second);
}
sort(rbegin(t), rend(t));
int cnt = 0;
int pre_x, pre_y;
for (auto tmp:t){
cnt++;
if (cnt >= 2){
if (get<1>(tmp) == pre_x && get<2>(tmp) == pre_y){
continue;
}
else cout << get<0>(tmp) << endl;
return 0;
}
pre_x = get<1>(tmp);
pre_y = get<2>(tmp);
}
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const int maxn=100000+10;
int main()
{
vector <P> vec,vecx,vecy;
int n; cin>>n;
for(int i=0;i<n;i++)
{
P a; cin>>a.first>>a.second;
vec.push_back(a);
}
vecx=vec;
vecy=vec;
sort(vecx.begin(),vecx.end(),[](P a,P b){return a.first>b.first;});
sort(vecy.begin(),vecy.end(),[](P a,P b){return a.second>b.second;});
vector <ll> ans;
/*ans.push_back(abs(vecx[0].first-vecx[n-1].first));
ans.push_back(abs(vecx[0].first-vecx[n-2].first));
ans.push_back(abs(vecx[1].first-vecx[n-1].first));
ans.push_back(abs(vecy[0].second-vecy[n-1].second));
ans.push_back(abs(vecy[0].second-vecy[n-2].second));
ans.push_back(abs(vecy[1].second-vecy[n-1].second));
sort(ans.begin(),ans.end(),[](ll a,ll b){return a>b;});
cout<<ans[1]<<endl;*/
for(int i=n-1;i>0;i--)
{
if(abs(vecx[0].first-vecx[i].first)>abs(vecx[0].second-vecx[i].second))
ans.push_back(abs(vecx[0].first-vecx[i].first));
}
for(int i=1;i<n-1;i++)
{
if(abs(vecx[n-1].first-vecx[i].first)>abs(vecx[n-1].second-vecx[i].second))
ans.push_back(abs(vecx[n-1].first-vecx[i].first));
}
for(int i=n-1;i>0;i--)
{
if(abs(vecy[0].second-vecy[i].second)>=abs(vecy[0].first-vecy[i].first))
ans.push_back(abs(vecy[0].second-vecy[i].second));
}
for(int i=1;i<n-1;i++)
{
if(abs(vecy[n-1].second-vecy[i].second)>=abs(vecy[n-1].first-vecy[i].first))
ans.push_back(abs(vecy[n-1].second-vecy[i].second));
}
sort(ans.begin(),ans.end(),[](ll a,ll b) {return a>b;});
cout<<ans[1]<<endl;
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
long long pow(int k){
if(k==0) return 1;
else{
long long a = 2*pow(k-1);
a %= 998244353;
return a;
}
}
int main(){
int h,w;
cin >> h >> w;
vector<int> red(h+w-1),blue(h+w-1),white(h+w-1);
for(int i = 0 ; i < h ; i++ ) {
for(int j = 0 ; j < w ; j++ ) {
char c;
cin >> c;
if(c=='R') red.at(i+j)++;
else if(c=='B') blue.at(i+j)++;
else white.at(i+j)++;
}
}
int k=0;
bool flag = true;
for(int i = 0 ; i < h+w-1 ; i++ ) {
if(red.at(i)*blue.at(i)==0){
if(red.at(i)==0&&blue.at(i)==0&&white.at(i)!=0)k++;
}
else {
flag = false;
break;
}
}
if(flag) {
cout << pow(k) << endl;
}
else {
cout << 0 << endl;
}
} | #include "bits/stdc++.h"
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
long long a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, m = 0, n = 0, p = 0, q = 0, mod = 1000000007, pi = 3.1415926535;
string s1, s2;
char moji;
cin >> a >> b;
vector<string> v(a);
for(int i=0;i<a;i++)
{
cin >> v.at(i);
}
n=1;
for(int i=0;i<=a+b-2;i++)
{
int nanika=0;
for(int j=max(0LL,i-a+1);j<=i&&i-j<a&&j<b;j++)
{
if(v.at(i-j).at(j)=='R')
{
if(nanika==2||nanika==3)
{
nanika=3;
}
else
{
nanika=1;
}
}
else if(v.at(i-j).at(j)=='B')
{
if(nanika==1||nanika==3)
{
nanika=3;
}
else
{
nanika=2;
}
}
}
if(nanika==0)
n*=2;
if(nanika==3)
n*=0;
n%=998244353;
}
cout << n << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#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)return 0;
return kaijo[a]*invkaijo[a-b]%mod*invkaijo[b]%mod;
}
ll inv(ll x){
x=modpow(x,mod-2);
return x;
}
struct BIT{
int n,beki=1;
vector<int>bit;
BIT(int x){
bit.resize(x+1,0);
n=x;
while(beki*2<=n)beki*=2;
}
int sum(int i){
int res=0;
while(i>0){
res+=bit[i];
i-=i&-i;
}
return res;
}
int sum(int l,int r){
//[l,r]
return sum(r)-(l==0?0:sum(l-1));
}
void add(int i,int x){
while(i<=n){
bit[i]+=x;
i+=i&-i;
}
}
void add(int l,int r,int x){
//[l,r]+=x
add(l,x);
if(r<n)add(r+1,-x);
}
int lowerbound(int w){
if(w<=0)return 0;
int x=0;
for(int k=beki;k>0;k>>=1){
if(x+k<=n&&bit[x+k]<w){
w-=bit[x+k];
x+=k;
}
}
return x+1;
}
};
int h,w,m;
vector<int>G[200010];
int main(){
cin>>h>>w>>m;
int mi=h-1,mj=w;
rep(i,m){
int x,y;
cin>>x>>y;
x--;
if(x==0)chmin(mj,y-1);
else{
if(y==1)chmin(mi,x-1);
G[x].pb(y);
}
}
BIT bit(w);
ll ans=0;
rep(i,h){
if(i==0){
ans+=mj;
continue;
}
for(int j:G[i]){
if(bit.sum(j,j)==0)bit.add(j,1);
}
if(i<=mi){
int mjn=w;
for(int j:G[i]){
chmin(mjn,j-1);
}
ans+=mjn;
if(mjn+1<=mj)ans+=(mj-mjn)-bit.sum(mjn+1,mj);
}
else{
ans+=mj-bit.sum(1,mj);
}
}
cout<<ans<<endl;
return 0;
} | #include<bits/stdc++.h>
#define endl '\n'
#define mp make_pair
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
char *fs,*ft,buf[1<<20];
#define gc() (fs==ft&&(ft=(fs=buf)+fread(buf,1,1<<20,stdin),fs==ft))?0:*fs++;
inline int read()
{
int x=0,f=1;
char ch=gc();
while(ch<'0'||ch>'9')
{
if(ch=='-')
f=-1;
ch=gc();
}
while(ch>='0'&&ch<='9')
{
x=x*10+ch-'0';
ch=gc();
}
return x*f;
}
using namespace std;
#define int long long
const int mod = 1e9+7;
const int INF = 0x3f3f3f3f;
const int N = 2e5+10;
string a="0123456789ABCDEF",s;
int k,f[N][17];
int dfs(int pos,int st,int lim,int pre,int cnt)
{
if(pos==sz(s)) return (cnt==k);
if(!lim&&f[pos][cnt]!=-1&&!st) return f[pos][cnt];
char high = lim?s[pos]:'F';
int res=0;
for(int i=0;i<sz(a);i++)
{
if(st&&i==0)
res = (res+dfs(pos+1,st&&i==0,lim&&a[i]==high,pre,cnt))%mod;
else
res = (res+dfs(pos+1,st&&i==0,lim&&a[i]==high,pre|(1<<i),cnt+(pre!=(pre|(1<<i)))))%mod;
if(a[i]==high) break;
}
if(!lim&&!st) f[pos][cnt] = res;
return res;
}
signed main()
{
cin>>s>>k;
mem(f,-1);
cout<<dfs(0,1,1,0,0)<<endl;
}
|
///////////////////////Loading Payloads.......////////////////////////////
#include<bits/stdc++.h>
#define f(i,a,b) for(int i = a; i < b; i++)
#define fd(i,a,b) for(int i = a; i > b;i--)
#define ll long long
#define fl(i,a,b) for(ll i = a; i < b; i++)
#define VI vector<int>
#define VP vector<pair<int,int>>
#define VS vector<string>
#define VL vector<long long>
#define VC vector<char>
#define VF vector<float>
#define VD vector<double>
#define VB vector<bool>
#define PB push_back
#define F first
#define S second
#define fa(i,skill) for(auto i : skill)
#define fr(i,skill) for(VI :: reverse_iterator i = skill.rbegin(); i != skill.rend(); i++)
#define PI pair<int,int>
#define mi map<int,int>
#define mci map<char,int>
#define all(x) x.begin(),x.end()
#define MAX 1000000007
#define debug(x) cout<<"This side ----> "<<#x<<" -> "<<x<<endl
using namespace std;
///////////////////////Engine Check.......////////////////////////////
void edit(VI &skill,int n)
{
f(i,0,n)
{
int x;
cin >> x;
skill.PB(x);
}
}
void editl(VL &skill,ll n)
{
fl(i,0,n)
{
ll x;
cin >> x;
skill.PB(x);
}
}
void achilles(int w)
{
string s;cin >> s;
s += s[0];
cout << s[1]<<s[2]<<s[3] << "\n";
}
///////////////////////3....2....1...Ignition////////////////////////////
int main()
{
ios :: sync_with_stdio(0);
cin.tie(0);
//freopen("out.txt","r",stdin);
int x = 1;
/*int t;cin >>t ;
while(t--)*/
{achilles(x);x++;}
return 0;
} | #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
int main() {
ll n;
cin >> n;
vector<ll> v;
for (ll i = 1; i * i <= n; i++) {
if (n % i == 0) {
cout << i << "\n";
if (i * i != n)v.push_back(n / i);
}
}
reverse(v.begin(), v.end());
for (auto &x:v)cout << x << "\n";
cout << flush;
return 0;
}
|
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main()
{
int n;
cin>>n;
for(int i=1;i<=1000000;++i)
{
int k=log10(i);
int tmp=pow(10,k+1);
//cout<<i*tmp+i<<'\n';
if(i*tmp+i>n)
{
cout<<i-1<<'\n';
break;
}
}
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
int main(void){
long long n;
cin >> n;
long long m = 1;
long long k = 10;
long long ans = 0;
for(int i=1;i<1000000;i++){
if(k <= i) k*=10;
if(i*k+i <= n){
ans++;
}
if(i*k+i > n) break;
}
cout << ans << endl;
} |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, s, e) for (int i = (int)(s); i < (int)(e); i++)
#define _rep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define _REP(i, e, s) for (int i = (int)(e - 1); i >= (int)(s); i--)
#define yes cout << "yes" << endl;
#define Yes cout << "Yes" << endl;
#define YES cout << "YES" << endl;
#define no cout << "no" << endl;
#define No cout << "No" << endl;
#define NO cout << "NO" << endl;
#define AC cout << "AC" << endl;
#define WA cout << "WA" << endl;
#define out(s) cout << s << endl;
#define ll long long
#define ull unsigned long long
const unsigned int BIT_FLAG_0 = (1 << 0); // 0000 0000 0000 0001
const unsigned int BIT_FLAG_1 = (1 << 1); // 0000 0000 0000 0010
const unsigned int BIT_FLAG_2 = (1 << 2); // 0000 0000 0000 0100
const unsigned int BIT_FLAG_3 = (1 << 3); // 0000 0000 0000 1000
const unsigned int BIT_FLAG_4 = (1 << 4); // 0000 0000 0001 0000
const unsigned int BIT_FLAG_5 = (1 << 5); // 0000 0000 0010 0000
const unsigned int BIT_FLAG_6 = (1 << 6); // 0000 0000 0100 0000
const unsigned int BIT_FLAG_7 = (1 << 7); // 0000 0000 1000 0000
const double PI = 3.14159265358979323846;
const int dy[4] = {0, 1, 0, -1};
const int dx[4] = {1, 0, -1, 0};
#define H_MAX 500
#define W_MAX 500
#define INF 1e9 + 7
const long long MOD = 998244353;
long powInt(long x, int n) {
long ret = 1;
while (n > 0) {
if (n & 1) ret = ret * x;
x = x * x;
n >>= 1;
}
return ret;
}
// mod. m での a の逆元 a^{-1} を計算する
long modinv(long a, long m) {
long b = m, u = 1, v = 0;
while (b) {
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;
}
int main() {
int x;
cin >> x;
if(x>=0){
out(x);
}else
{
out(0);
}
} | #include <stdio.h>
int main(void) {
int in;
scanf("%d", &in);
printf("%d", (in > 0) ? in : 0);
} |
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_p(x) cerr<<#x": "<<(x).first<<' '<<(x).second<<endl
#define dbg_v(x, n) {cerr<<#x"[]: ";for(long long _=0;_<n;++_)cerr<<(x)[_]<<' ';cerr<<endl;}
#define all(v) v.begin(), v.end()
#define fi first
#define se second
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}
template<typename T1, typename T2>
ostream& operator <<(ostream &out, const pair<T1, T2> &item) {
out << '(' << item.first << ", " << item.second << ')';
return out;
}
template <typename T>
ostream& operator <<(ostream &out, const vector<T>& v) {
for(const auto &item : v) out << item << ' ';
return out;
}
int main()
{
ios_base::sync_with_stdio(false);
int n;
string t;
string p = "110";
ll len = 300000LL * 100000LL;
cin >> n >> t;
bool ok[3] = { true, true, true };
for(int i = 0; i < n; ++i) {
if(t[i] != p[i % 3]) ok[0] = false;
if(t[i] != p[(i + 1) % 3]) ok[1] = false;
if(t[i] != p[(i + 2) % 3]) ok[2] = false;
}
ll ans = 0;
if(ok[0]) ans += (len - n) / 3 + 1;
if(ok[1]) ans += (len - n - 1) / 3 + 1;
if(ok[2]) ans += (len - n - 2) / 3 + 1;
cout << ans << '\n';
return 0;
}
| #include<cstdio>
#include<algorithm>
#include<map>
using namespace std;
map<int,int>Map;
int n, L, A[101000], w[101000], B[101000];
long long res = 0;
int LL[101000], RR[101000];
int PP[101000], QQ[101000];
int main(){
int i;
scanf("%d%d",&n,&L);
for(i=1;i<=n;i++)scanf("%d",&A[i]);
for(i=1;i<=n;i++)scanf("%d",&B[i]);
A[n+1]=B[n+1]=L+1;
int cnt=0;
for(i=0;i<=n+1;i++){
A[i]-=i,B[i]-=i;
if(i==0 || A[i]!=A[i-1]){
cnt++;
LL[cnt]=i;
}
Map[A[i]]=cnt;
RR[cnt]=i;
}
for(i=0;i<=n+1;i++){
if(!Map.count(B[i])){
puts("-1");
return 0;
}
int x = Map[B[i]];
if(i==0||B[i]!=B[i-1])PP[x]=i;
QQ[x]=i;
}
for(i=1;i<=cnt;i++){
if(!QQ[i])continue;
if(QQ[i]>RR[i])res += QQ[i]-RR[i];
if(PP[i]<LL[i])res += LL[i]-PP[i];
}
printf("%lld\n",res);
} |
#pragma clang optimize on
#include <cstdio>
#include <functional>
#include <iostream>
#include <queue>
#include <tuple>
#include <vector>
using namespace std;
using ll = long long;
#define shift 30
inline int get_digit() {
int x = 0, f = 1;
char c = getchar();
while(c > '9' || c < '0') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
x = (x * 10) + (c ^ 48);
c = getchar();
}
return x * f;
}
int main() {
int R = get_digit(), C = get_digit();
int A[250000], B[250000];
int dist[500000], cost, pt, to_hide = R * C;
vector<ll> s;
s.reserve(2 * R * C);
priority_queue<ll, vector<ll>, greater<ll>> queue(s.begin(), s.end());
for(int i = 0; i < R * C; ++i) {
if(i % C != C - 1) A[i] = get_digit();
dist[i] = 0;
}
for(int i = 0; i < (R - 1) * C; ++i) B[i] = get_digit();
dist[0] = -10000000;
queue.push((ll)(-10000000) << shift);
while(queue.size()) {
pt = queue.top() & ((1 << shift) - 1);
if(pt == to_hide - 1) break;
cost = queue.top() >> shift;
queue.pop();
if(pt < to_hide) {
if(pt % C != C - 1 & cost + A[pt] < dist[pt + 1]) {
dist[pt + 1] = cost + A[pt];
queue.push(((ll)dist[pt + 1] << shift) | (pt + 1));
}
if(pt % C != 0 & cost + A[pt - 1] < dist[pt - 1]) {
dist[pt - 1] = cost + A[pt - 1];
queue.push(((ll)dist[pt - 1] << shift) | (pt - 1));
}
if(pt < to_hide - C & cost + B[pt] < dist[pt + C]) {
dist[pt + C] = cost + B[pt];
queue.push(((ll)dist[pt + C] << shift) | (pt + C));
}
if(cost + 1 < dist[pt + to_hide]) {
dist[pt + to_hide] = cost + 1;
queue.push(((ll)dist[pt + to_hide] << shift) | (pt + to_hide));
}
} else {
if(to_hide < pt - C && cost + 1 < dist[pt - C]) {
dist[pt - C] = cost + 1;
queue.push(((ll)(cost + 1) << shift) | (pt - C));
}
if(cost < dist[pt - to_hide]) {
dist[pt - to_hide] = cost;
queue.push(((ll)cost << shift) | (pt - to_hide));
}
}
}
printf("%d\n", dist[to_hide - 1] - dist[0]);
} | //For higher stack size use g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456 a.cpp -o a.exe in cmd
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define ll long long int
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define pb push_back
#define f first
#define s second
using namespace std;
int main()
{
std::ios::sync_with_stdio(false);
int T;
T=1;
// cin.ignore(); must be there when using getline(cin, s)
while(T--)
{
int n,m,i,j;
cin>>n>>m;
int ar[n+1][m+1],ar2[n+1][m+1],ar3[m+1],pos[m+1];
for(i=1;i<=n;++i)
{
for(j=1;j<=m-1;++j)
{
cin>>ar[i][j];
}
}
for(i=1;i<=n-1;++i)
{
for(j=1;j<=m;++j)
{
cin>>ar2[i][j];
}
}
int ans[n+1][m+1],flag=0;
for(i=1;i<=n;++i)
{
for(j=1;j<=m;++j)
{
ans[i][j]=1e9;
}
}
ans[n][m]=0;
start:
for(j=m-1;j>0;--j)
{
ans[n][j]=min(ans[n][j],ans[n][j+1]+ar[n][j]);
}
for(i=n-1;i>=1;--i)
{
for(j=m;j>=1;--j)
{
ans[i][j]=min(ans[i][j],ans[i+1][j]+ar2[i][j]);
}
for(j=m-1;j>=1;--j)
{
ans[i][j]=min(ans[i][j],ans[i][j+1]+ar[i][j]);
}
for(j=2;j<=m;++j)
{
ans[i][j]=min(ans[i][j],ans[i][j-1]+ar[i][j-1]);
}
}
++flag;
if(flag<=max(n,m)+10)
{
for(j=1;j<=m;++j)
{
ar3[j]=ans[1][j];
pos[j]=1;
}
for(i=2;i<=n;++i)
{
for(j=1;j<=m;++j)
{
ans[i][j]=min(ans[i][j],ar3[j]+1+(i-pos[j]));
if(ans[i][j]<=ar3[j]+(i-pos[j]))
{
ar3[j]=ans[i][j];
pos[j]=i;
}
}
}
goto start;
}
cout<<ans[1][1]<<endl;
}
return 0;
} |
#define IOS ios::sync_with_stdio(false);
#define rep(i, a, n) for(ll i=a;i<=n;i++)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double lb;
#define endl "\n"
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int N = 1e6 + 10;
ll n, m, t, k, ans, cnt, sum, flag;
ll arr[N], vis[N];
char s[N];
int main() {
IOS;
cin >> n;
cnt = 1, ans = 1;
while(n--) {
cin >> s;
cnt <<= 1;
if (s[0] == 'O') ans += cnt;
}
cout << ans << endl;
return 0;
} | #pragma GCC target ("avx2")
//#pragma GCC optimize "trapv"
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#define input(a,n) for(ll i1=0;i1<n;i1++)cin>>a[i1]
#define ll long long
#define pi 2 * acos(0.0)
#define usll unordered_set<ll>
#define sll set<ll>
#define vll vector<ll>
#define mll map<ll,ll>
#define pll pair<ll,ll>
#define umll unordered_map<ll,ll>
#define S second
#define sz size()
#define all(v) v.begin(),v.end()
#define Y cout<< "YES"<< "\n"
#define N cout<< "NO"<< "\n"
#define F first
#define mp make_pair
#define pb push_back
#define pf push_front
#define ld long double
using namespace std;
const ll mod = 1000000007;
vector<string> split(const string& s, char c) {
vector<string> v; stringstream ss(s); string x;
while (getline(ss, x, c)) v.push_back(x); return move(v);
}
template<typename T, typename... Args>
inline string arrStr(T arr, int n) {
stringstream s; s << "[";
for(int i = 0; i < n - 1; i++) s << arr[i] << ",";
s << arr[n - 1] << "]";
return s.str();
}
#define EVARS(args...) {__evars_begin(__LINE__); __evars(split(#args, ',').begin(), args);}
inline void __evars_begin(int line) { cerr << "#" << line << ": "; }
template<typename T> inline void __evars_out_var(vector<T> val) { cerr << arrStr(val, val.size()); }
template<typename T> inline void __evars_out_var(T* val) { cerr << arrStr(val, 10); }
template<typename T> inline void __evars_out_var(T val) { cerr << val; }
inline void __evars(vector<string>::iterator it) { cerr << endl; }
template<typename T, typename... Args>
inline void __evars(vector<string>::iterator it, T a, Args... args) {
cerr << it->substr((*it)[0] == ' ', it->length()) << "=";
__evars_out_var(a);
cerr << "; ";
__evars(++it, args...);
}
int 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
ll n;
cin>>n;
string s[n];
for(ll i=0;i<n;i++)
{
cin>>s[i];
}
ll dp[n+1];
if(s[0]=="OR")
dp[0]=3;
else
dp[0]=1;
for(ll i=1;i<n;i++)
{
if(s[i]=="AND")
dp[i]=dp[i-1];
else
dp[i]=dp[i-1]+(1LL<<(i+1));
}
cout<<dp[n-1];
return 0;
} |
#include<bits/stdc++.h>
#include<string>
using namespace std;
int main()
{
int i,j,n,k,m,l=0;
cin>>n>>k>>m;
int ara[n];
for(i=0;i<n-1;i++)
{
cin>>ara[i];
l+=ara[i];
}
if(l/n>=m)
{
cout<<"0";
return 0;
}
else
{
for(i=1;i<=k;i++)
{
l+=i;
if(l/n>=m)
{
cout<<i<<endl;
return 0;
}
l-=i;
}
}
cout<<"-1"<<endl;
return 0;
} | # include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <cmath>
# include <functional>
# include <utility>
# include <queue>
# include <stack>
# define MOD 1000000007
# define INF 2000000000
#define rep(i,rept) for(ll i = 0; i<rept;i++)
typedef long long ll;
using namespace std;
std::vector<bool> IsPrime;
int main() {
long long ans = 0, counter = 0, maxi = -1, mini = INF, pass = 0;
//new
ll n, k, m;
ll poi[10000];
cin >> n >> k >> m;
ll want = m * n;
rep(i, n-1) {
cin >> poi[i];
counter += poi[i];
}
if (want-counter<=k){
cout << max((ll)0,want - counter) << endl;;
}
else {
cout << -1 << endl;
}
} |
#include <bits/stdc++.h>
#define SpeeD ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define ll long long
#define endl '\n'
using namespace std;
ll n , t , k , m;
bool nud(int n)
{
int a[100];
int c= 0 ;
// counter for octal number array
int i = 0;
while (n != 0) {
// storing remainder in octal array
a[i] = n % 8;
n = n / 8;
i++;
}
for (int i = 0 ; i < 100; i++)
if (a[i] == 7 )c++;
return c;
}
bool num (int x)
{
int c= 0 ;
while (x)
{
if (x%10 == 7)c++;
x/=10;
}
return c;
}
int main(){
SpeeD;
int n;
cin >> n;
long long sum = 0 ;
// cout << nud(15);
for (int i = 1 ; i <=n ; i++)
{
// cout << i <<" " << num(i) <<" " << nud(i) << endl;
sum = sum + ( num(i) | nud(i));
}
cout << n- sum;
} | #include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <vector>
using namespace std;
int X;
int main(){
cin >> X;
cout << 100-X%100;
} |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 7;
const int inf = 1e9 + 7;
int a[807][807],b[807][807];
int n,k;
bool check(int m){
for(int i = 1;i <= n;i++){
for(int j = 1;j <= n;j++){
if(a[i][j] > m) b[i][j] = b[i-1][j]-1;
else b[i][j] = b[i-1][j]+1;
}
}
for(int i = 1;i <= n+1-k;i++){
int st = i+k-1,ans = 0;
for(int j = 1;j < k;j++){
ans = ans + b[st][j] - b[i-1][j];
}
for(int j = k;j <= n;j++){
ans += b[st][j] - b[i-1][j];
if(ans >= 0) return 0;
ans -= b[st][j+1-k] - b[i-1][j+1-k];
}
}
return 1;
}
int main(){
scanf("%d %d",&n,&k);
for(int i = 1;i <= n;i++){
for(int j = 1;j <= n;j++){
scanf("%d",&a[i][j]);
}
}
int l = 0,r = inf;
while(l < r){
int m = (l + r) / 2;
if(check(m)){
l = m + 1;
}else r = m;
}
printf("%d\n",l);
return 0;
}
| #include <bits/stdc++.h>
#define ll long long
#define map unordered_map
#define set unordered_set
#define l_l pair<ll, ll>
#define P pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>
#define mp make_pair
#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 rev(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define revs(i, n) for (int i = ((int)(n)); i > 0; --i)
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; }
using namespace std;
const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);
// template <class T> void plus_mod(T &a, const T &b) {a = (a + b) % MOD;}
ll N, K;
ll grid[999][999];
class Cumu {
private:
vector<ll> _sum;
public:
Cumu(vector<ll> &source) {
_sum = vector<ll>(source.size() + 1);
for (ll i = 1; i < source.size() + 1; i++) {
_sum[i] = _sum[i - 1] + source[i - 1];
}
}
ll sum(ll left, ll right) {
//
return _sum[right + 1] - _sum[left];
}
};
ll count_equal_or_less_than(ll th) {
// return 0;
ll start_y = 0;
ll max_count = 0;
// 前計算
vector<Cumu> cumu_list;
rep(x, N) {
vll zo_list;
rep(y, N) {
ll v = grid[y][x];
zo_list.emplace_back(v <= th);
}
cumu_list.emplace_back(Cumu(zo_list));
}
// 本計算
ll count = 0;
for (;;) {
ll end_y = start_y + K - 1;
if (end_y >= N) break;
// 最初の四角のカウント
count = 0;
rep(x, K) {
ll c = cumu_list[x].sum(start_y, end_y);
count += c;
}
chmax(max_count, count);
// 右まで移動
ll start_x = 0;
for (;;) {
ll end_x = start_x + K - 1;
if (end_x == N - 1) break; // 右端
count -= cumu_list[start_x].sum(start_y, end_y);
count += cumu_list[end_x + 1].sum(start_y, end_y);
chmax(max_count, count);
start_x += 1;
}
// 下に移動
start_y += 1;
}
return max_count;
}
int main() {
// std::cout << std::fixed << std::setprecision(10);
scanf("%lld %lld", &N, &K);
rep(y, N) {
rep(x, N) {
ll v;
scanf("%lld", &v);
grid[y][x] = v;
}
}
ll nth = (K * K / 2) + 1;
ll count_th = (K * K) - nth + 1;
// leftが条件を満たしていないケースに注意
ll left = -100;
ll right = 2000000000LL; // ■TODO
for (;;) {
// cout << "left:" << (left) << ",right:" << (right) << endl;
if (1 >= right - left) {
break;
}
ll center = (left + right) / 2;
ll count = count_equal_or_less_than(center);
if (count < count_th) {
left = center;
} else {
right = center;
}
}
// cout << "left:" << (left) << ",right:" << (right) << endl;
ll ans = right;
cout << (ans) << endl;
// // [1, 3, 5, 6] -> 2
// ll searchInsert(vector<ll>& nums, ll target) {
// ll left = 0;
// ll right = nums.size();
// for (;;) {
// if (1 == right - left) {
// if (nums[left] < target) {
// left = right;
// } else {
// right = left;
// }
// break;
// }
// if (0 >= right - left) {
// break;
// }
// ll center = (left + right) / 2;
// ll n = nums[center];
// if (n < target) {
// left = center;
// }
// if (n >= target) {
// right = center;
// }
// }
// return left;
// }
// ll ans = 0;
// cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#ifdef __DEBUG__
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {cerr << " " << H; debug_out(T...);}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll LL_INF = (ll)(2e18);
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }
int N;
string s;
inline void input(){
fast_io();
cin >> N;
cin >> s;
}
void fox(string &t){
if(t.length() < 3) return;
int n = t.length();
if(t[n-1] == 'x' && t[n-2] == 'o' && t[n-3] == 'f'){
t.pop_back();
t.pop_back();
t.pop_back();
}
return ;
}
inline int solve(){
string t = "";
for (int i = 0; i < N; i++)
{
t.push_back(s[i]);
fox(t);
}
cout << t.length() << endl;
return 0;
}
int main()
{
input();
solve();
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define ll long long
#define rep(n) for(int i=0;i<n;i++)
void fastInOut() {
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
}
void solve()
{
int a , b; // a = solid , b = fat
cin >> a >> b;
a = a + b;
if (a >= 15 && b >= 8)
{
cout << 1 ;
}
else if (a >= 10 && b >= 3)
{
cout << 2 ;
}
else if (a >= 3)
{
cout << 3;
}
else
{
cout << 4;
}
}
int main(int argc, char const * argv[]) {
fastInOut();
int tc = 1;
//cin >> tc;
while (tc--)
{
solve(); cout << endl;
}
} |
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
ll n, k;
ll c2(ll x) {
if(x < 2) {
return 0LL;
}
return x * (x - 1) / 2;
}
ll f(ll x) {
return c2(x - 1) - 3 * c2(x - n - 1) + 3 * c2(x - 2*n - 1) - c2(x - 3*n - 1);
}
ll g(ll x) {
ll L = max(1LL, x - n);
ll R = min(n, x - 1);
if(L > R) {
return 0LL;
}
return R - L + 1;
}
int main() {
cin >> n >> k;
exrep(s, 3, 3*n) {
ll x = f(s);
if(k <= x) {
exrep(a, 1, n) {
x = g(s - a);
if(k <= x) {
exrep(b, 1, n) {
ll c = s - a - b;
if(c <= 0 || n < c) {
continue;
}
if(k == 1) {
cout << a << " " << b << " " << c << endl;
re0;
}
k--;
}
}
k -= x;
}
}
k -= x;
}
re0;
} | #include<iostream>
#include<vector>
#include<string.h>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<stack>
#include <chrono>
#include <random>
#include <iterator>
#include <map>
#include<list>
#include<sstream>
#include <algorithm>
#include <fstream>
#include<unordered_map>
#include<set>
#include<queue>
#define int long long
#define double long double
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pip pair<int,pii>
#define vip vector<pii>
#define vi vector<int>
#define vs vector<string>
#define vd vector<double>
#define mii map<int, int>
#define qu queue<int>
#define set set<int>
#define multiset multiset<int>
#define rep(i, a, b) for(int i=a;i<b;i++)
#define rep1(i, b, a) for(int i=b;i>=a;i--)
#define viv vector<vi>
#define stack stack<char>
#define fi first
#define se second
#define all(v) (v).begin(), (v).end()
#define it iterator
#define pq priority_queue<int>
#define pq1 priority_queue <pii, vector<pii>, greater<pii> >
#define mem(x, y) memset(x, (int)y, sizeof(x))
#define ps(x,y) fixed<<setprecision(y)<<x
// author :: Anurag Anand.
using namespace std;
int z= 1e9+7;
//int z= 998244353;
int gcd(int a, int b){
if(a==0)return b;
if(b==0)return a;
return gcd(b, a%b);
}
int power(int a,int b){
int res=1;
while(b){
if(b&1) res=(res*a)%z, b--;
a=(a*a)%z;
b=b>>1;
}
return res;
}
vi sv;
int fact[1000001];
int ncr(int n, int r){
int p=fact[n];
p*=power(fact[r], z-2);
p%=z;
p*=power(fact[n-r], z-2);
p%=z;
return p;
}
int inv(int x){
return power(x, z-2);
}
int dsu(int x, int par[]){
if(x==par[x]) return x;
return dsu(par[x], par);
}
// vi seg;
// void arrange(int i, int v, int x, int lx, int rx){
// if(rx-lx==1){
// seg[x]=v;
// return;
// }
// int mid=(lx+rx)/2;
// if(i<mid) arrange(i, v, 2*x+1, lx, mid);
// else arrange(i, v, 2*x+2, mid, rx);
// seg[x]= min(seg[2*x+1], seg[2*x+2]);
// }
// int calc(int l, int r, int x, int lx, int rx){
// if(lx>=r||l>=rx) return 1e9;
// if(lx>=l&&rx<=r) return seg[x];
// int mid=(lx+rx)/2;
// int k1=calc(l, r, 2*x+1, lx, mid), k2=calc(l, r, 2*x+2, mid, rx);
// return min(k1, k2);
// }
vi pp;
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
// freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
pp.assign(1000001, 0);
for(int i=2;i<1000;i++){
if(!pp[i]){
for(int j=i*i;j<=1000000;j+=i){
pp[j]=1;
}
}
}
fact[0]=1;
rep(i,1,1000001) fact[i]=i*fact[i-1], fact[i]%=z;
for(int i=2;i<=1000000;i++) if(!pp[i]) sv.pb(i);
int t;
t=1;
//cin>>t;
while(t--){
int n, q;
cin>>n>>q;
vip v;
int ar[n];
rep(i,0,n) cin>>ar[i];
if(ar[0]>1){
v.pb(mp(ar[0]-1, 1));
}
rep(i,1,n){
if(ar[i]-ar[i-1]>1){
v.pb(mp(ar[i]-ar[i-1]-1, ar[i-1]+1));
}
}
v.pb(mp(1e18+1e10-ar[n-1], ar[n-1]+1));
rep(i,1,v.size()){
v[i].fi+=v[i-1].fi;
}
while(q--){
int k;
cin>>k;
int l=0, r=v.size()-1, ans=-1;
while(l<=r){
int mid=(l+r)/2;
if(v[mid].fi>=k){
ans=mid;
r= mid-1;
}
else l=mid+1;
}
if(ans!=-1){
if(ans>0) k-=v[ans-1].fi;
cout<<v[ans].se+k-1<<"\n";
}
}
}
} |
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(int i=cc;i>=n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
using ll = long long;
const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const vector<int> dx2 = {1, 1, 1, 0, 0, 0, -1, -1, -1};
const vector<int> dy2 = {1, 0, -1, 1, -1, 0, 1, 0, -1};
const double PI = 3.1415926535;
const ll inf = 1001001001;
const ll e9 = 1000000000;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll MAX = 1000000;
const int MOD = 1000000007;
const ll big = (1ll<<60);
ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }
ll modPow(ll a, ll n, ll p) {
if (n == 0) return 1;
if (n == 1) return a % p;
if (n % 2 == 1) return (a * modPow(a, n - 1, p)) % p;
ll t = modPow(a, n / 2, p);
return (t * t) % p;
}
int main(){
int n, m;
cin >> n >> m;
vector<ll>a(n),b(m);
vector<vector<ll>>dp(n+1,vector<ll>(m+1,0));
rep(i, 0, n)cin >> a[i];
rep(i, 0, m)cin >> b[i];
rep(i, 0, n+1)dp[i][0] = i;
rep(i, 0, m+1)dp[0][i] = i;
rep(i, 1, n+1){
rep(j, 1, m+1){
if(a[i-1]==b[j-1])dp[i][j] = min({dp[i-1][j]+1,dp[i][j-1]+1,dp[i-1][j-1]});
else dp[i][j] = min({dp[i-1][j]+1,dp[i][j-1]+1,dp[i-1][j-1]+1});
}
}
/*
rep(i, 0, n+1){
rep(j, 0, m+1){
cout << dp[i][j] << " ";
}
cout << endl;
}
*/
cout << dp[n][m] << endl;
} | /* � Ashiq Uddin Pranto
Department of Computer Science and Engineering
BATCH 27
University Of Rajshahi,Bangladesh
*/
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define FOR(x,y) for(ll i=x;i<=y;i++)
#define pb(x) push_back(x)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define matrix(x) vector<vector<x>>
#define vss vector<string>
#define PI (2*acos(0.0))
#define sqr(x) ((x)*(x))
#define sf(a) scanf("%d",&a)
#define sfl(a) scanf("%lld",&a)
#define sff(a,b) scanf("%d %d",&a,&b)
#define sffl(a,b) scanf("%lld %lld",&a,&b)
#define sfff(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define sfffl(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define ms(a,b) memset(a, b, sizeof(a))
#define ff first
#define ss second
#define lcm(a, b) ((a)*((b)/__gcd(a,b)))
#define all(a) a.begin(),a.end()
#define readfile freopen("input.txt","r",stdin);
#define writefile freopen("output.txt","w",stdout);
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define gap " "
#define mx 104
#define inf (ll)1e9
#define WHITE 1
#define GRAY 2
#define BLACK 3
#define EMPTY_VALUE -1
#define mod 1000000007
#define MOD(a,b) (a%b + b)%b
using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
ll n,m;
ll dp[1005][1005];
ll a[1005],b[1005];
ll solve(ll i,ll j)
{
if(dp[i][j]!=-1) return dp[i][j];
if(i>=n && j>=m) return 0;
if(i>=n) return (m-j);
if(j>=m) return (n-i);
ll ans = inf;
if(a[i]==b[j])
{
ans = min(ans,solve(i+1,j+1));
}
ans=min(ans,1+solve(i+1,j));
ans=min(ans,1+solve(i,j+1));
ans=min(ans,1+solve(i+1,j+1));
return dp[i][j] = ans;
}
void eff()
{
memset(dp,-1,sizeof(dp));
sffl(n,m);
for(ll i=0;i<n;i++) sfl(a[i]);
for(ll i=0;i<m;i++) sfl(b[i]);
printf("%lld\n",solve(0,0));
}
int main()
{
// fastio
// ll test ;
// sfl(test);
// for(ll i=0;i<test;i++)
// {
// printf("Case %lld: ",i+1);
eff();
// }
// cout<<check(81);
return 0;
}
|
// #pragma GCC optimize("Ofast,unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#include <bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define forn(i, s, n) for(ll i=(ll)s; i<(ll)(n); i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define pll pair<long long int, long long int>
#define pii pair<int, int>
#define pss pair<string, string>
#define ull unsigned long long int
#define lld long double
#define F first
#define S second
#define PI 3.141592653589793238
#define prec(n) fixed<<setprecision(n)
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define itsval(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); itval(_it, args); }
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
void itval(istream_iterator<string> it) {}
template<typename T, typename... Args>
void itval(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << endl;
itval(++it, args...);
}
const ll MOD = 1e9 + 7;
template <typename T>
inline void print(T x) {cout << x << "\n";}
template <typename T>
inline void printvec(T x) {for (auto a : x)cout << a << ' '; cout << '\n';}
// -----------------------------------------------------------------------
struct custom {
bool operator()(const pll &p1, const pll &p2)const {
return p1.F > p2.F;
}
};
// Calculate a^b % MOD -------------------------------------------------
ll get_pow(ll a, ll b, ll M = MOD) {
ll res = 1;
while (b) {
if (b & 1) res = (res * a) % M;
a = (a * a) % M;
b >>= 1;
}
return res;
}
// ---------------------------------------------------------------------
const ll N = 2e5 + 5, inf = 4e18;
ll dp[N][2];
void solve()
{
ll n;
cin >> n;
vll mx(n + 1, -inf), mi(n + 1, inf);
ll x, c;
forn(i, 0, n)
{
cin >> x >> c;
c--;
mi[c] = min(mi[c], x);
mx[c] = max(mx[c], x);
}
mx[n] = mi[n] = 0;
ll ans = 0, p = 0;
for (int j = n - 1; j >= 0; j--)
{
// dono mi
if (mi[j] == inf)
{
dp[j][0] = dp[j + 1][0];
dp[j][1] = dp[j + 1][1];
mx[j] = mx[j + 1];
mi[j] = mi[j + 1];
continue;
}
dp[j][0] = abs(mi[j + 1] - mx[j]) + mx[j] - mi[j] + dp[j + 1][0];
dp[j][0] = min(dp[j][0], abs(mx[j + 1] - mx[j]) + mx[j] - mi[j] + dp[j + 1][1]);
dp[j][1] = abs(mx[j + 1] - mi[j]) + mx[j] - mi[j] + dp[j + 1][1];
dp[j][1] = min(dp[j][1], abs(mi[j + 1] - mi[j]) + mx[j] - mi[j] + dp[j + 1][0]);
}
ans = min(dp[0][0] + abs(mi[0]), dp[0][1] + abs(mx[0]));
cout << ans;
}
int 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 test = 1;
clock_t z = clock();
// cin >> test;
forn(tes, 0, test)
{
solve();
}
debug("Total Time:%.4f\n", (double)(clock() - z) / CLOCKS_PER_SEC);
return 0;
} | #include <iostream>
#include <iomanip>
#include <cstdio>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <chrono>
#include <functional>
#define _crt_secure_no_warnings
#define JH ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define mp make_pair
#define INF 0x3F3F3F3F
#define MAXLL 1000000000000000000LL
#define MOD ll(1e9 + 7)
#define LOGMAX 21
#define ALPHABET 2
#define loop(i, n) for (int i = 1; i <= (n); i++)
#define loop0(i, n) for (int i = 0; i < (n); i++)
#define sz(x) (int)x.size()
#define all(v) v.begin(), v.end()
#define all1(v) v.begin() + 1, v.end()
#define F first
#define S second
#define EPS 1e-9
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
typedef pair<ll, ll> llll;
typedef pair<int, int> ii;
typedef unordered_map<int, int> umii;
typedef unordered_map<ll, ll> umll;
typedef unordered_set<int> usi;
typedef unordered_multiset<int> usmi;
//main exec
int main(){
JH
lld a, b; cin >> a >> b;
cout << fixed << setprecision(9) << (b / 100) * a << endl;
} |
#include<bits/stdc++.h>
using namespace std;
#define light ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define pb push_back
#define cases() ll t;cin>>t;while(t--)
#define all(c) c.begin(),c.end()
#define PI 3.14159265358979323846
const ll MAX = 2e5+5;
const ll INF = 1e18;
const ll MOD = 1e9+7;
int check(string a,int n)
{
int i,j;
for(i=0;i<n;i++)
{
if(a[i]!=a[n-1-i])
return 0;
}
return 1;
}
int main()
{
int n,i,j,k,l,p,q,x,y;
cin >> l;
string a = to_string(l);n = a.size();
if(check(a,n)==1)
{
cout << "Yes";
return 0;
}
string b;p = 0;
for(i=n-1;i>=0;i--)
{
if(p==0)
{
if(a[i]!='0')
{
p++;
b+=a[i];
}
}
else
b+=a[i];
}
reverse(b.begin(),b.end());
if(check(b,b.size())==1)
{
cout << "Yes";
return 0;
}
else
cout << "No";
} | #include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define MAX 100010
#define MOD 1000000007
#define INF 1e15
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pi 3.14159265358979323846
#define endl "\n"
#define coutflg if(flg){cout << "Yes\n";}else{cout << "No\n";}
#define coutyes cout << "Yes\n";
#define coutno cout << "No\n";
#define flush fflush(stdout);
#define fixedprec cout << fixed << setprecision(18);
void solve(){
string a;
cin >> a;
int flg = 1;
ll n = a.size();
ll l = 0;
ll r = a.size()-1;
while(l<n && a[l]=='0'){
l++;
}
while(r>=0 && a[r]=='0'){
r--;
}
while(l<=r){
if(a[l]!=a[r]){
flg = 0;
break;
}
else{
l++;
r--;
}
}
coutflg;
}
int main(){
fast
ll t,q;
q = 1;
// cin >> q;
for(t=1;t<=q;t++){
// cout << "Case #" << t << ": ";
solve();
}
} |
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define sz(a) ((int) (a).size())
#define all(x) (x).begin(), (x).end()
const long double eps = 1e-9;
const int inf = (1 << 30) - 1;
const long long inf64 = ((long long)1 << 62) - 1;
const long double pi = acos(-1);
template <class T> T sqr (T x) {return x * x;}
template <class T> T abs (T x) {return x < 0 ? -x : x;}
template <class T>
vector<T> ReadVector(int n) {
vector<T> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
return a;
}
template <class T>
void WriteVector(const vector<T>& a) {
for (int i = 0; i < sz(a); ++i) {
cout << a[i] << (i + 1 < sz(a) ? ' ' : '\n');
}
}
void DFS(const vector<vector<int>>& a, int v, vector<int>& used) {
used[v] = true;
for (int i = 0; i < sz(a[v]); ++i) {
if (!used[i] && a[v][i]) {
DFS(a, i, used);
}
}
}
void Solve() {
int n;
cin >> n;
vector<vector<int>> a(n, vector<int>(n));
for (int i = 0; i < n; ++i) {
string s;
cin >> s;
for (int j = 0; j < n; ++j) {
a[i][j] = (s[j] == '1');
}
}
vector<vector<int>> a_rev(n, vector<int>(n));
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
a_rev[i][j] = a[j][i];
}
}
double res = 0;
for (int i = 0; i < n; ++i) {
vector<int> used(n);
DFS(a_rev, i, used);
int cnt = 0;
for (int j = 0; j < n; ++j) {
cnt += used[j];
}
res += 1.0 / cnt;
}
cout.precision(20);
cout << res << "\n";
}
int main () {
ios_base::sync_with_stdio(0);
std::cin.tie(nullptr);
// clock_t start_clock = clock();
// freopen("_input.txt", "rt", stdin);
// freopen("_output.txt", "wt", stdout);
int tc = 1;
// cin >> tc;
for (int ti = 0; ti < tc; ++ti) {
Solve();
}
// double total_seconds = (double) (clock() - start_clock) / CLOCKS_PER_SEC;
// cerr << "Working time: " << total_seconds << "s." << endl;
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
#define lin(x) ll x; cin>>x;
#define stin(x) string x; cin>>x;
#define yn(x) if(x) { cout<<"Yes"<<endl; } else { cout<<"No"<<endl; }
#define YN(x) if(x) { cout<<"YES"<<endl; } else { cout<<"NO"<<endl; }
#define co(x) cout<<x<<endl;
using ll=long long;
using ld=long double;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll mod=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template <typename T> inline bool chmax(T &a, T b) {
return ((a < b) ? (a = b, true) : (false));
}
template <typename T> inline bool chmin(T &a, T b) {
return ((a > b) ? (a = b, true) : (false));
}
ll powmod(ll n, ll k, ll m) {
ll r=1;
for(; k>0; k >>=1) {
if(k&1) r=(r*n)%m;
n=(n*n)%m;
}
return r;
}
ll fact(ll n) {
ll a=1;
rep(i,n) {
a=a*(n-i);
}
return a;
}
ll pow(ll a, ll b) {
ll x=1;
rep(i,b) {
x=x*a;
}
return x;
}
int main() {
lin(N);
lin(M);
ll data[N][N];
rep(i,N) rep(j,N) data[i][j]=inf;
rep(i,M) {
lin(a); lin(b); lin(c);
chmin(data[a-1][b-1],c);
}
//Warshal-floyd neu
rep(k,N) {
rep(i,N) {
if(data[i][k]==inf) {
continue;
}
rep(j,N) {//rep1
if(data[k][j]==inf) {
continue;
}
else {
chmin(data[i][j],data[i][k]+data[k][j]);
}
}//rep1
}
}
rep(i,N) {
if(data[i][i]==inf) {
co(-1);
}
else {
co(data[i][i]);
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
float x=0,y=0,z=0;
int a=0;
cin >> x >> y >> z;
while(y/x > a/z){
a++;
}
cout << a -1;
}
| #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i <= n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n)
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
using Graph = vector<vector<int>>;
using Edge = pair<int, ll>;
const int MAX = 100000;
const ll INF = 1LL << 60;
int main()
{
// cin高速化
cin.tie(0);
ios::sync_with_stdio(false);
int x, y, z;
cin >> x >> y >> z;
cout << (z * y - 1) / x << "\n";
return 0;
} |
#include <bits/stdc++.h>
#define ll long long
using namespace std;
template <typename T>
void read(T &x) {
x = 0; char c = getchar(); int f = 0;
for (; !isdigit(c); c = getchar())
f |= c == '-';
for (; isdigit(c); c = getchar())
x = x * 10 + (c ^ '0');
if (f) x = -x;
}
template <typename T>
void write(T x, char ed = '\n') {
if (x < 0) putchar('-'), x = -x;
static short st[30], tp;
do st[++tp] = x % 10, x /= 10; while (x);
while (tp) putchar(st[tp--] | '0');
putchar(ed);
}
const int N = 1005000;
int ans, n;
char s[N];
inline int C(int n, int m) {
if (m > n) return 0;
if (n >= 3) return C(n / 3, m / 3) * C(n % 3, m % 3) % 3;
if (n == 2) return 1 + (m == 1);
return 1;
}
int main() {
read(n), scanf ("%s", s + 1);
for (int i = 1;i <= n; ++i) {
int c = (s[i] > 'B') + (s[i] > 'R');
ans += C(n - 1, i - 1) * c;
}
if (~n & 1) ans *= -1;
ans = (ans % 3 + 3) % 3;
if (ans == 0) putchar('B');
else if (ans == 1) putchar('R');
else putchar('W');
return 0;
}
| #include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
using ll=long long;
using ld=long double;
using pll=pair<ll, ll>;
//using mint = modint1000000007;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
#define PI acos(-1)
#define oo 2e18
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
//priority_queue<ll, vector<ll>, greater<ll>> Q;
/*
*/
char add_wbr(char a, char b){
if (a==b) return(a);
if (a=='W' && b=='R') return('B');
if (a=='W' && b=='B') return('R');
if (a=='B' && b=='W') return('R');
if (a=='B' && b=='R') return('W');
if (a=='R' && b=='W') return('B');
if (a=='R' && b=='B') return('W');
return (0);
}
int main(){
cin.tie(0);
ios::sync_with_stdio(0);
cout << fixed << setprecision(10);
ll N;
string S;
cin >> N >> S;
ll sz=S.size();
while (sz>1){ // 4->1, 5->4->1
while(sz%3!=1){
string T;
for(ll j=0; j<sz-1; j++)
T+=add_wbr(S[j], S[j+1]);
S=T;
sz=S.size();
}
string T;
for(ll j=0; j+3<sz; j+=3)
T+=add_wbr(S[j], S[j+3]);
if (T[0]) S=T;
sz=S.size();
}
cout << S[0] << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main()
{
string str;
cin >> str;
int i = 0;
int txtsize = str.size();
string after = "";
for (int j = txtsize; j >= 0; j--)
{
string ch = str.substr(j, 1);
if (ch == "6")
{
ch = "9";
}
else if (ch == "9")
{
ch = "6";
}
after += ch;
i++;
}
std::cout << after << std::endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
reverse(s.begin(), s.end());
for (int i = 0; i < s.size(); i++) {
if (s[i] == '6') {
cout << '9';
}
else if (s[i] == '9') {
cout << '6';
}
else {
cout << s[i];
}
}
cout << endl;
} |