code_file1
stringlengths 87
4k
| code_file2
stringlengths 85
4k
|
---|---|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename T>bool chmin(T& x,const T&y) {if(x>y){x=y;return true;} else return false;}
template<typename T>bool chmax(T& x,const T&y) {if(x<y){x=y;return true;} else return false;}
template<typename T>
struct BIT {
int n;
vector<T> d;
BIT(int n=0):n(n), d(n+1) {}
void add(int i, T x=1) {
for (i++; i <= n; i += i&-i) {
//i&-iで最下位bitを足している
d[i] += x;
}
}
T sum(int i) {
T x = 0;
for (i++; i; i -= i&-i) {
x += d[i];
}
return x;
}
T semiopenSum(int l, int r) {
// [l,r)の半開区間
return sum(r-1) - sum(l-1);
}
}; // BIT<int> bit(N);
int main() {
ll H, W, M;
cin >> H >> W >> M;
vector<int> col(W, H), row(H, W);
rep(i, M) {
int x, y;
cin >> x >> y;
--x; --y;
chmin(col[y], x);
chmin(row[x], y);
}
ll ans = 0;
rep(i, col[0]) ans += row[i];
rep(j, row[0]) ans += col[j];
vector<vector<int>> A(H+1);
rep(j, row[0]) A[col[j]].push_back(j);
BIT<int> bit(W+1);
rep(j, row[0]) bit.add(j, 1);
rep(i, col[0]) {
for (int a : A[i]) {
bit.add(a, -1);
}
ans -= bit.semiopenSum(0, row[i]);
}
cout << ans << '\n';
return 0;
// 重複, 境界, 条件, ll (1e5のnCr), 0, -, 1i, for s&g, debug
} | #include <bits/stdc++.h>
using namespace std;
#define END '\n'
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define bug(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define loop(i, a, b) for(int i = (a); i < (b); i++)
#define loopb(i, b, a) for(int i = (b); i > (a); --i)
const int mod = 1e9+7;
const int mod1 = 998244353;
const ll inf = 1e14;
const int nax = 200005;
int H, W, M, x[nax], y[nax], L[nax], T[nax], a[nax];
vector<int> row[nax];
void MIN(int &a, int b){
a = min(a, b);
}
void update(int pos){
while(pos <= W){
a[pos]++;
pos += pos&-pos;
}
}
int sum(int pos){
int now = 0;
while(pos >= 1){
now += a[pos];
pos -= pos&-pos;
}
return now;
}
void solve()
{
cin>>H>>W>>M;
for(int i = 1; i <= H; i++)
L[i] = W + 1;
for(int i = 1; i <= W; i++)
T[i] = H + 1;
for(int i = 1; i <= M; i++){
cin>>x[i]>>y[i];
MIN(L[x[i]], y[i]);
MIN(T[y[i]], x[i]);
}
ll ans = 0;
for(int i = 1; i <= W; i++){
if(i < L[1])
ans += T[i] - 1;
else
T[i] = 1;
row[T[i]].pb(i);
}
for(int i = 1; i < T[1]; i++){
ans += sum(L[i] - 1);
for(int x : row[i])
update(x);
}
cout<<ans;
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
/* int t;
cin>>t;
while(t--)*/
solve();
return 0;
}
|
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vpl = vector<pair<ll, ll>>;
using pll = pair<ll, ll>;
#define rep(i, k, n) for(ll i = k; i < n; i++)
#define pb push_back
#define mp make_pair
int main(){
ll n; cin >> n;
vll a(n);
rep(i, 0, n) cin >> a[i];
sort(a.begin(), a.end());
ll ans = 0;
rep(i, 0, n){
ans += ((2*i+1) - n) * a[i];
}
cout << ans << endl;
} |
#include<bits/stdc++.h>
using namespace std;
#define ar array<ll, 2>
#define ll long long
#define in insert
#define pb push_back
#define pii pair<ll,ll>
#define vt vector
#define P_Q(x) priority_queue<x>
#define p_q(x) priority_queue<x, vector<x>, greater<x>>
#define For(i, n) for(ll i = 0; i < n; i++)
#define Rev(i, n) for(ll i = n-1; i >= 0; i--)
#define FOR(i, n) for(ll i = 1; i <= n; i++)
#define REV(i, n) for(ll i = n; i >= 1; i--)
#define Rep(i,a,b) for(ll i = a; i <= b; i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int) (x).size()
void solve()
{
long double x,y,r;
cin>>x>>y>>r;
ll ans=0;
r=nextafter(r,1e14);
for(ll i=ceil(x-r);i<=floor(x+r);i++)
{
long double count=sqrt((r*r)-(x-i)*(x-i));
ans+=floor(y+count)-ceil(y-count)+1;
}
cout<<ans<<endl;
return;
}
int main()
{
ios::sync_with_stdio(0); cin.tie(0);
solve();
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
int main ()
{
int i,f=0,p=0;
string s,s1;
cin>>s;
for(i=s.size()-1;i>=0;i--)
{
if(s[i]!='0')break;
else if(s[i]=='0')p++;
}
for(i=1;i<=p;i++)
{
s1+='0';
}
for(i=0;i<s.size();i++)
{
s1+=s[i];
}
for(i=0; i < s1.size() ; i++)
{
if(s1[i] != s1[s1.size()-i-1])
{
f = 1;
break;
}
}
if(f==0)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
return 0 ;
} | #include <bits/stdc++.h>
using namespace std;
int main(){
int a,f=0,b,c=0,d;
cin>>a;
while(a%10==0&&a!=0){
a/=10;
}
d=a;
while(a>0){
b=a%10;
a/=10;
c=c*10+b;
}
if(d==c) f=1;
if(f==1) cout<<"Yes";
else cout<<"No";
return 0;
} |
/*Bismillahi-r-Rahmani-r-Rahim*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi acos(-1.0)
#define mod 1000000007
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define vi vector<int>
#define vl vector<ll int>
#define pb push_back
#define test cin>>t;while(t--)
#define lcm(a,b) a*b/__gcd(a,b)
#define sd second
#define ft first
int main()
{
ios_base::sync_with_stdio(false);cin.tie(NULL);
ll int i,n,t,j=0,p,x,a=0,b,l=0,r=0,y,k,c,sum=0,m,d,cnts=0;
cin>>n;
map<string,int>mp;
// map<string,int>:: iterator it;
string sm,sp;
for(i=0;i<n;i++){
cin>>sm;
mp[sm]++;
}
i=0;
string s[mp.size()];
for(auto it : mp){
sp=it.ft;
if(sp[0]=='!'){
sp=sp.substr(1,sp.size()-1);
}
s[i++]=sp;
}
l=0;
sort(s,s+mp.size());
for(i=0;i<mp.size()-1;i++){
if(s[i]==s[i+1]){
l=1;sm=s[i];break;
}
}
if(l==0){
cout<<"satisfiable"<<endl;
}
else{
cout<<sm<<endl;
}
}
| #define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(...) begin(__VA_ARGS__) , end(__VA_ARGS__)
#define boost {ios_base::sync_with_stdio(false); cin.tie(); cout.tie();}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector <int> vi;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
constexpr ll nax = 2e5+6969, INF = 2e9+6969;
int n;
set <string> a,b;
int main()
{
cin >> n;
for(int i=0;i<n;i++)
{
string tmp;
cin >> tmp;
if(tmp[0] == '!') a.insert(tmp);
else b.insert(tmp);
}
string ans = "satisfiable";
for(auto e: b)
{
string tmp = "!" + e;
if(a.find(tmp) != a.end()) ans = e;
}
cout << ans << "\n";
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i, n) for (ll i=0; i<n; ++i)
#define all(obj) (obj).begin(),(obj).end()
using namespace std;
typedef long long ll;
long long GCD(long long x, long long y) { return y ? GCD(y, x%y) : x; }
int main(){
int N;
string S;
string T;
cin >> N >> S >> T ;
int n1 = count(all(S),'0');
int n0 = count(all(T),'0');
int szc=0, tzc=0;
if (n1!=n0)
cout << "-1" <<endl;
else{
vector<int> sv (n0);
vector<int> tv (n0);
rep(i,N){
if (S[i]=='0'){
sv[szc]=i;
szc++;
}
if (T[i]=='0'){
tv[tzc]=i;
tzc++;
}
}
int ans = 0;
rep(i,n0){
//cout << sv[i]<<" " <<tv[i]<<endl;
if (sv[i]!=tv[i])
ans++;
}
cout <<ans <<endl;
}
return 0;
}
| #include <bits/stdc++.h>
#define ll long long int
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define io ios_base::sync_with_stdio(false); cin.tie(NULL);
#define N 200005
using namespace std;
void great(){
cout<<">";
}
void same(){
cout<<"=";
}
void small(){
cout<<"<";
}
int main()
{
ll a,b,c;
cin>>a>>b>>c;
if(a>0 && b>0){
if(a>b) great();
else if(a<b) small();
else same();
}
else if(a==0){
if(b==0) same();
else if(b<0){
if(c&1) great();
else small();
}
else small();
}
else if(b==0){
if(a<0){
if(c&1) small();
else great();
}
else great();
}
else if(a>0){
if(c&1) great();
else{
if(a>abs(b)) great();
else if(a==abs(b)) same();
else small();
}
}
else{
if(b>0){
if(c&1) small();
else{
if(abs(a)>b) great();
else if(abs(a)==b) same();
else small();
}
}
else{
if(c%2==0){
a=abs(a);
b=abs(b);
}
if(a>b) great();
else if(a==b) same();
else small();
}
}
return 0;
}
|
/*
* * * * * * * * * * * * * * * * * *
*
* @author: Xingjian Bai
* @date: 2021-04-10 13:21:51
* @description:
*
*
* @notes:
* g++ -fsanitize=address -ftrapv
* * * * * * * * * * * * * * * * * */
#include <bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define TIME (double)clock()/CLOCKS_PER_SEC
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
const int mod = 1000000007;
const ll oo = 1e18;
const ld eps = 1e-8;
#define debug(x) cerr << "(debug mod) " << #x << " = " << x << endl
int n;
ll v[1000010], s[1000010];
priority_queue <ll> q;
int main() {
ios::sync_with_stdio(false);
cin >> n;
for (int i = 1; i <= 2 * n; i ++) {
cin >> v[i];
s[i] = s[i - 1] + v[i];
}
// ll mn = 1e16;
// for (int i = n; i <= 2 * n; i ++)
// mn = min (mn, s[i] - s[i - n]);
// cerr << mn << " " << s[2 * n] << endl;
// cout << s[2 * n] - mn << endl;
ll mn = 0;
for (int i = n; i >= 1; i --) {
q.push(-v[i]);
q.push(-v[n + n - i + 1]);
mn += q.top();
q.pop();
}
cout << s[2 * n] + mn << endl;
return 0;
} | #include <bits/stdc++.h>
#include <bits/extc++.h>
#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define iter(a) a.begin(), a.end()
#define riter(a) a.rbegin(), a.rend()
#define lsort(a) sort(iter(a))
#define gsort(a) sort(riter(a))
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define pf(a) push_front(a)
#define ef(a) emplace_front(a)
#define pob pop_back()
#define pof pop_front()
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
#define mt make_tuple
#define gt(t, i) get<i>(t)
#define tomax(a, b) ((a) = max((a), (b)))
#define tomin(a, b) ((a) = min((a), (b)))
#define topos(a) ((a) = (((a) % MOD + MOD) % MOD))
#define uni(a) a.resize(unique(iter(a)) - a.begin())
#define printv(a, b) {bool pvaspace=false; \
for(auto pva : a){ \
if(pvaspace) b << " "; pvaspace=true;\
b << pva;\
}\
b << "\n";}
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;
using tiii = tuple<int, int, int>;
const ll MOD = 1000000007;
const ll MAX = 2147483647;
template<typename A, typename B>
ostream& operator<<(ostream& o, pair<A, B> p){
return o << '(' << p.F << ',' << p.S << ')';
}
ll ifloor(ll a, ll b){
if(b < 0) a *= -1, b *= -1;
if(a < 0) return (a - b + 1) / b;
else return a / b;
}
ll iceil(ll a, ll b){
if(b < 0) a *= -1, b *= -1;
if(a > 0) return (a + b - 1) / b;
else return a / b;
}
int main(){
StarBurstStream
int n;
cin >> n;
vector<ll> v(2 * n + 1);
ll sum = 0;
for(int i = 1; i <= 2 * n; i++){
cin >> v[i];
sum += v[i];
}
std::priority_queue<ll, vector<ll>, greater<>> pq;
ll ans = 0;
for(int i = 1; i <= n; i++){
pq.push(v[n - i + 1]);
pq.push(v[n + i]);
ans += pq.top();
pq.pop();
}
ans = sum - ans;
cout << ans << "\n";
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define all(v) ((v).begin()), ((v).end())
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define debug(x) cout<<#x<<" = "<<x<<" \n"
typedef long long ll;
typedef unsigned long long ull;
void xin(){
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
}
// int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
// inline bool valid(int x, int y, char v) {
// return x >= 0 && x < n && y >= 0 && y < m && !visited[x][y] && grid[x][y] == v;
// }
int main()
{
xin();
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
char S,T;
cin>>S>>T;
if(S == 'Y')
{
cout<<char(T-32)<<endl;
}
else
{
cout<<T<<endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define init(a,i) for(int k=0;k<(i);k++)(a)[k]=0
#define in(a,i) for(int k=0;k<(i);k++)cin>>(a)[k]
#define all(a) (a).begin(),(a).end()
#define inf 2147483647
#define range(x,a,b) (a)<=x&&x<=(b)
int main(){
char s,t;
cin>>s>>t;
if(s=='Y'){
switch(t){
case 'a':
cout<<'A';
break;
case 'b':
cout<<'B';
break;
case 'c':
cout<<'C';
break;
}
}
else {
cout<<t;
}
return 0;
} |
#ifdef LOCAL
cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
#endif
#include "bits/stdc++.h"
using namespace std;
using namespace std::chrono;
#define ll long long
#define vll vector<ll>
#define pii pair<ll,ll>
#define un_mp unordered_map<ll,ll,modified_hash>
#define endl "\n"
#define pb push_back
#define all(a) a.begin(),a.end()
ll mod=1000000007;
struct modified_hash {
static uint64_t splitmix64(uint64_t x){
x += 0x9e3779b97f4a7c15;
x=(x^(x>>30))*0xbf58476d1ce4e5b9;
x=(x^(x>>27))*0x94d049bb133111eb;
return x^(x>>31);
}
ll operator()(uint64_t x) const{
static const uint64_t random= steady_clock::now().time_since_epoch().count();
return splitmix64(x + random);
}
};
const ll N = 1000000;
ll lp[N+1];
vector<ll> pr;
void solve(){
ll a,b,k,c,n,d,m,x,y,l,r;
ll i,j;
cin>>l>>r;
ll fans=0;
for(ll i=2LL;i<=r;i++){
un_mp mp;
ll fk=i;
bool flag=true;
while (fk>1){
mp[lp[fk]]++;
if(mp[lp[fk]]>1) flag=false;
fk/=lp[fk];
}
ll cnt=mp.size();
ll ans=r/i-((l-1)/i);
if(flag&&cnt%2==0){
fans-=(ans*(ans-1))/2;
}
else if(flag){
// cout<<i2<<" "<<ans<<endl;
fans+=(ans*(ans-1))/2;
}
}
for(ll i=max(2LL,l);i<=r;i++) fans-=(r/i-1);
cout<<fans*2<<endl;
return;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
ll a,b,c,n,tt,d,m,k,x,y;
tt=1;
// cin>>tt;
for (ll i=2;i<=N;++i){
if (lp[i]==0){
lp[i]=i;
pr.push_back(i);
}
for (ll j=0;j<(ll)pr.size()&&pr[j]<=lp[i]&&i*pr[j]<=N;++j){
lp[i*pr[j]]=pr[j];
}
}
while(tt--){
solve();
}
} | // E - Divide Both
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
int main(){
int L, R; cin>>L>>R;
auto x = [&](int k){ return R/k - (L-1)/k; };
ll ans = 0;
vector<ll> F(R+1);
for(int k=R; k>=2; --k){
ll c = x(k);
F[k] = c * c;
for(int g=2*k; g<=R; g+=k) F[k] -= F[g];
ans += F[k];
}
for(int g=max(2, L); g<=R; ++g) ans -= x(g)*2 - 1;
cout<< ans <<endl;
}
|
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include <cmath>
using namespace std;
int cd(long long int i){
int j=0;
while(i){
j++;
i=i/10;
}
return j;
}
int main(){
int N;
cin>>N;
vector<int> V1(N);
vector<int> V2(N);
int max=0, min=INT32_MAX;
for(int i=0; i<N; i++){
cin>>V1[i];
if(V1[i]>max){
max=V1[i];
}
}
for(int i=0; i<N; i++){
cin>>V2[i];
if(V2[i]<min){
min=V2[i];
}
}
if(max>min){
cout<<0;
}
else{
cout<<min-max+1;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main(){
int n,sum=0,c;
cin>>n;
int a[n+1],b[n+1];
for(int i=1;i<=n;i++)
cin>>a[i];
for(int i=1;i<=n;i++)
cin>>b[i];
for(int i=1;i<=1000;i++)
{
c=1;
for(int j=1;j<=n;j++)
if(i<a[j]||i>b[j])
c=0;
if(c==1)
sum++;
}
cout<<sum;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
long long ans = 0;
vector<int> a(2 * n);
for (auto &i : a) cin >> i;
priority_queue<int, vector<int>, greater<int>> pq;
pq.emplace(max(a[n - 1], a[n]));
for (int i = 1; i < n; i++) {
int u = a[n - i - 1];
int v = a[n + i];
if (pq.top() < min(u, v)) {
pq.pop();
pq.emplace(min(u, v));
}
pq.emplace(max(u, v));
}
while (!pq.empty()) {
ans += pq.top();
pq.pop();
}
cout << ans << '\n';
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
int N; cin >> N;
vector<pair<ll, ll>> range(N);
for(int i = 0; i < N; i++){
int t; ll l, r; cin >> t >> l >> r;
l *= 2LL; r *= 2LL;
if(t == 2 || t == 4)r--;
if(t == 3 || t == 4)l++;
range[i] = make_pair(l, r);
}
int ans = 0;
for(int i = 0; i < N - 1; i++){
ll l1 = range[i].first, r1 = range[i].second;
for(int j = i + 1; j < N; j++){
ll l2 = range[j].first, r2 = range[j].second;
if(r1 < l2 || l1 > r2)continue;
ans++;
}
}
cout << ans << endl;
} |
#include<bits/stdc++.h>
#define PI 3.141592653589793238462
#define eps 1e-20
#define fi first
#define se second
using namespace std;
using cd = complex<double>;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<db,db> pdd;
ll mod=1e9+7;
ll qpow(ll a,ll b){
ll res=1;
while(b){
if(b&1) res=res*a%mod;
a=a*a%mod;b/=2;
}return res%mod;
}
int main(){
ll n,p;cin>>n>>p;
ll x=p-1,ans=x;
ans*=qpow(x-1,n-1);
cout<<ans%mod<<endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ll a, b;
cin>>a>>b;
cout<<a*b/(double)100<<endl;
return 0;
}
|
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
inline int read()
{
int x=0,w=1; char c=getchar();
while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
return w==1?x:-x;
}
int n,q,c[maxn],f[maxn];
map <int,int> mp[maxn];
inline int F(int x)
{
if(f[x]==x) return x;
return f[x]=F(f[x]);
}
inline void mer(int u,int v)
{
int tx=F(u),ty=F(v);
if(tx!=ty)
{
int x=mp[tx].size(),y=mp[ty].size();
if(x<y)
{
for(map <int,int>::iterator it=mp[tx].begin();it!=mp[tx].end();it++)
{
pair <int,int> p=*it;
mp[ty][p.first]+=p.second;
}
f[tx]=ty;
}
else
{
for(map <int,int>::iterator it=mp[ty].begin();it!=mp[ty].end();it++)
{
pair <int,int> p=*it;
mp[tx][p.first]+=p.second;
}
f[ty]=tx;
}
}
}
int main()
{
n=read(); q=read(); rep(i,1,n) c[i]=read(),f[i]=i;
rep(i,1,n) mp[i][c[i]]++;
while(q--)
{
int opt=read(),u=read(),v=read();
if(opt==1) mer(u,v);
else
{
printf("%d\n",mp[F(u)][v]);
}
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
ll H,W;
ll A,B;
vector<vector<bool>> note;
ll dfs(ll h,ll w,ll count) {
if(h==H-1&w==W-1) {
if(count==A) {
return 1;
}
else return 0;
}
ll s=0;
if(!note[h][w]) {
if(h<H-1&&w<W-1) {
if(!note[h+1][w]) {
note[h][w]=true;
note[h+1][w]=true;
s+=dfs(h+1,w,count+1);
note[h][w]=false;
note[h+1][w]=false;
}
if(!note[h][w+1]) {
note[h][w]=true;
note[h][w+1]=true;
s+=dfs(h+1,w,count+1);
note[h][w]=false;
note[h][w+1]=false;
}
s+=dfs(h+1,w,count);
}
else if(h==H-1) {
if(!note[h][w+1]) {
note[h][w]=true;
note[h][w+1]=true;
s+=dfs(0,w+1,count+1);
note[h][w]=false;
note[h][w+1]=false;
s+=dfs(0,w+1,count);
}
else {
s+=dfs(0,w+1,count);
}
}
else {
if(!note[h+1][w]) {
note[h][w]=true;
note[h+1][w]=true;
s+=dfs(h+1,w,count+1);
note[h][w]=false;
note[h+1][w]=false;
s+=dfs(h+1,w,count);
}
else {
s+=dfs(h+1,w,count);
}
}
}
else {
if(h<H-1) {
s+=dfs(h+1,w,count);
}
else {
s+=dfs(0,w+1,count);
}
}
return s;
}
int main() {
cin>>H>>W;
cin>>A>>B;
note=vector<vector<bool>>(H,vector<bool> (W,false));
cout<<dfs(0,0,0)<<endl;
}
|
/*
may God of speed-forces be with us !!
--problem isnt, life is empty;
--problem is, life is full of emptiness;
a non-strugling pupil coder !!
*/
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define F first
#define S second
//#define biGinf 9e+18
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define inpv(v) for(auto &x:v) cin>>x
#define otpv(v) for(auto &x:v) cout<<x<<nwl
#define otpv2(v) for(auto &x:v) cout<<x<<" "
#define CASES int tt;cin>>tt; while(tt--)
#define for0(i,n) for(int i=0; i<n; i++)
#define for1(i,n) for(int i=1; i<=n; i++)
#define forr(i,r,n) for(int i=r; i<=n; i++)
#define forj(j,n) for(int j=n; j>=0; j--)
#define forx(x,v) for(auto &x:v)
#define sz(v) (int)(v).size()
#define rz(n) resize(n)
#define vec(x) vector < x >
#define vvim(n,m,v) vvi v(n, vi(m))
using int64 = long long;
using vi = vector < int >;
using vi64 = vector < int64 >;
using mii = map <int , int >;
using vvi = vector < vi >;
using pii = pair < int , int >;
using vpii = vector < pii >;
const int inf = 2e9 + 7;
const char nwl = '\n';
const int mxx = 1e6 + 3;
int64 sumV(vi &v) {
int64 s = 0;
for (int x : v) {
s += (int64)x;
}
return s;
}
int gcd(int a, int b) {
if (!b) return a;
return gcd(b, a % b);
}
//const int64 biGinf = 9e+18;
const string yo = "Yes\n", no = "No\n";
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//ur code
int n;
cin >> n;
vpii v(n);
for0(i, n) {
cin >> v[i].F >> v[i].S;
}
std::map<int, int> x, y, z;
for0(i, n) {
x[v[i].F]++;
y[v[i].S]++;
z[v[i].F - v[i].S]++;
}
bool f = 0;
for (auto e : x) {
if (e.S >= 3)f = 1;
if (f) break;
}
for (auto e : y) {
if (e.S >= 3)f = 1;
if (f) break;
}
for (auto e : z) {
if (e.S >= 3)f = 1;
if (f) break;
}
if (!f) {
for0(i, n) {
for (int j = i + 1; j < n; j++) {
for (int k = j + 1; k < n; k++) {
if ((v[i].F - v[j].F) and (v[i].F - v[k].F)) {
if (((float)(v[i].S - v[j].S) / ((v[i].F - v[j].F))) == ((float)(v[i].S - v[k].S) / ((v[i].F - v[k].F)))) f = 1;
}
if (f) break;
}
if (f) break;
}
if (f) break;
}
}
if (f) cout << yo;
else cout << no;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i);
using ll = long long;
int main() {
int n;
cin >> n;
vector<int> x(n), y(n);
for (int i = 0; i < n; i++) {
cin >> x.at(i) >> y.at(i);
}
string ans = "No";
for (int i = 0; i < n; i++) {
for (int j = i+1; j < n; j++) {
for (int k = j+1; k < n; k++) {
int x1 = x.at(j) - x.at(i);
int y1 = y.at(j) - y.at(i);
int x2 = x.at(k) - x.at(i);
int y2 = y.at(k) - y.at(i);
if (x1*y2 == x2*y1) {
ans = "Yes";
}
}
}
}
cout << ans << endl;
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
int n,m,ans;
int now[2008],to[20000],pre[20000],tot;
void add(int x,int y) {
to[++tot]=y;
pre[tot]=now[x];
now[x]=tot;
}
bool vis[20000];
void dfs(int u) {
vis[u]=1;
ans++;
for(int i=now[u]; i; i=pre[i]) {
int v=to[i];
if(!vis[v]) dfs(v);
}
}
int main() {
cin>>n>>m;
for(int i=1,x,y; i<=m; i++) {
cin>>x>>y;
add(x,y);
}
for(int i=1; i<=n; i++) {
memset(vis,0,sizeof vis);
dfs(i);
}
printf("%d\n",ans);
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>;
vector<vector<int>> g;
vector<int> visited;
int dfs(int v) {
int res = 1;
visited[v] = 1;
for (auto nv : g[v]) {
if (visited[nv]) continue;
res += dfs(nv);
}
return res;
}
int main() {
int n, m;
cin >> n >> m;
g.resize(n);
rep(i, m) {
int a, b;
cin >> a >> b;
a--, b--;
g[a].push_back(b);
}
int ans = 0;
rep(i, n) {
visited.assign(n, 0);
ans += dfs(i);
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define f(a,b,c,d) for(ll a=b; a<c; a+=d)
#define MOD 1000000007
#define pb push_back
#define umap unordered_map
#define uset unordered_set
#define pq priority_queue
void solve()
{
ll a, b, c;
cin >> a >> b >> c;
cout << 21 - a - b - c;
}
signed main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll t = 1;
//cin >> t;
ll tt = t;
while (t--)
{
//cout << "Case #" << tt - t << ": ";
solve();
}
}
| #include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define int long long
#define ll long long
#define pii std::pair<int, int>
#define pdd std::pair<double, double>
#define INF (1LL << 33)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define SHOW(p) \
if (test) \
cout << #p " : " << p << endl;
bool test = false;
int R, X, Y;
signed main() {
test = true;
test = false;
cin >> R >> X >> Y;
if (test) {
cout << X * X + Y * Y << endl;
}
if (X * X + Y * Y == R * R) {
cout << 1 << endl;
} else if (X * X + Y * Y <= 4 * R * R) {
cout << 2 << endl;
} else {
cout << ceil(sqrt((X * X + Y * Y - 1) / (R * R) + 1)) << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using Int = long long; // clang-format off
using pii = std::pair<Int, Int>;
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define RREP_(i, a_, b_, a, b, ...) for (Int i = Int(b) - 1, low##i = (a); i >= low##i; i--)
#define RREP(i, ...) RREP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define ALL(v) std::begin(v), std::end(v)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef dump
#define dump(...)
#endif // clang-format on
struct in {
template <class T> operator T() {
T t;
std::cin >> t;
return t;
}
};
void out() { std::cout << "\n"; }
template <class Head, class... Tail> void out(Head&& h, Tail&&... t) {
std::cout << h << (sizeof...(Tail) == 0 ? "" : " "), out(std::forward<Tail>(t)...);
}
template <class T> bool chmin(T& a, const T& b) { return a > b ? a = b, true : false; }
template <class T> bool chmax(T& a, const T& b) { return a < b ? a = b, true : false; }
template <class T> using V = std::vector<T>;
/**
* author: knshnb
* created: Sun Jun 27 14:56:28 JST 2021
**/
using comp = std::complex<double>;
double EPS = 1e-8;
bool equal(double a, double b) { return std::abs(a - b) < EPS; }
bool equal(comp a, comp b) { return std::abs(a - b) < EPS; }
bool set_equal(V<comp> a, V<comp> b) {
for (comp x : a) {
bool del = false;
for (comp y : b) {
if (equal(x, y)) {
del = true;
b.erase(std::find(ALL(b), y));
break;
}
}
if (!del) return false;
}
return true;
}
bool check(V<comp> a, V<comp> b, Int i, Int j) {
Int n = a.size();
comp dif1 = a[0], dif2 = b[i];
REP(k, n) a[k] -= dif1, b[k] -= dif2;
if (!equal(std::abs(a[1]), std::abs(b[j]))) return false;
comp arg = a[1] / b[j];
assert(equal(std::abs(arg), 1.));
REP(k, n) b[k] *= arg;
return set_equal(a, b);
}
signed main() {
Int n = in();
V<comp> s(n), t(n);
REP(i, n) s[i].real(in()), s[i].imag(in());
REP(i, n) t[i].real(in()), t[i].imag(in());
if (n == 1) {
out("Yes");
return 0;
}
REP(i, n) {
REP(j, n) {
if (i == j) continue;
if (check(s, t, i, j)) {
out("Yes");
return 0;
}
}
}
out("No");
}
| #include <bits/stdc++.h>
using namespace std;
using I64 = int64_t;
template <typename T> T gcd(T x, T y) {
if (y == 0) {
return x;
} else {
return gcd(y, x % y);
}
}
template <typename T> T lcm(T x, T y) { return x / gcd(x, y) * y; }
const char NL = '\n';
int main() {
int N, M;
cin >> N >> M;
vector<int> va(N), vb(M);
for (auto &a : va) {
cin >> a;
}
for (auto &b : vb) {
cin >> b;
}
sort(va.begin(), va.end());
sort(vb.begin(), vb.end());
auto ia = va.begin();
auto ib = vb.begin();
vector<int> ans;
for (; ia != va.end() || ib != vb.end();) {
if (ia == va.end()) {
ans.push_back(*ib);
ib++;
} else if (ib == vb.end()) {
ans.push_back(*ia);
ia++;
} else if (*ia > *ib) {
ans.push_back(*ib);
ib++;
} else if (*ia < *ib) {
ans.push_back(*ia);
ia++;
} else {
ia++;
ib++;
}
}
bool blank = false;
for (auto x : ans) {
if (blank) {
cout << ' ';
}
cout << x;
blank = true;
}
cout << NL;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int N;
ll X;
vector<ll> A;
map<pair<int, ll>, ll> memo;
ll dfs(int i, ll x) {
if (x == 0) return 1;
if (i == -1) return 0;
if (i < N - 1 && A[i + 1] <= x) return 0;
if (x % A[i] == 0) return 1;
if (memo.count({i, x})) return memo[{i, x}];
ll a = x / A[i];
ll ret = 0;
if (i == N - 1 || A[i] * a < A[i + 1]) {
ret += dfs(i - 1, x - A[i] * a);
}
if (i == N - 1 || A[i] * (a + 1) < A[i + 1]) {
ret += dfs(i - 1, A[i] * (a + 1) - x);
}
return memo[{i, x}] = ret;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> N >> X;
A.resize(N);
for (auto& x : A) cin >> x;
cout << dfs(N - 1, X) << endl;
} | #include<bits/stdc++.h>
using namespace std;
char s[101][101];
int ans;
int main() {
int n,m;
scanf("%d%d",&n,&m);
for(int i=1; i<=n; i++)
scanf("%s",s[i]+1);
for(int i=1; i<n; i++) {
bool ok=false;
for(int j=1; j<=m; j++) {
if(s[i][j]!=s[i+1][j]) {
if(!ok) {
ans++;
ok=true;
}
} else ok=false;
}
}
for(int i=1; i<m; i++) {
bool ok=false;
for(int j=1; j<=n; j++) {
if(s[j][i]!=s[j][i+1]) {
if(!ok) {
ans++;
ok=true;
}
} else ok=false;
}
}
printf("%d\n",ans);
return 0;
} |
#include <vector>
#include <array>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>
using namespace std;
int main(int argc, char** argv) {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(12);
long long n;
cin >> n;
vector<long long> fibs;
fibs.push_back(1);
fibs.push_back(1);
while (fibs.back() < n) {
long long x = fibs[fibs.size() - 2] + fibs[fibs.size() - 1];
fibs.push_back(x);
}
const int LIMIT = 130;
// const int LIMIT = 0;
vector<int> res;
if (n < LIMIT) {
for (int i = 0; i < n; ++i) {
res.push_back(1);
}
} else {
int m = fibs.size();
if (fibs.back() == n) {
for (int i = m - 1, t = 3; i > 1; --i, t = 7 - t) {
res.push_back(t);
}
res.push_back(1);
res.push_back(2);
} else {
assert(fibs.back() > n);
vector<int> coes(m, 0);
{
long long x = n - fibs[m - 2];
// cout << "X " << x << endl;
for (int i = m - 1; i >= 0; --i) {
coes[i] = x / fibs[i];
x -= coes[i] * 1LL * fibs[i];
}
}
for (int i = m - 2, j = 0, t = 3; i > 1; --i, t = 7 - t, ++j) {
for (int k = 0; k < coes[j]; ++k) {
res.push_back(t >> 1);
}
res.push_back(t);
}
res.push_back(1);
res.push_back(2);
}
reverse(res.begin(), res.end());
}
auto calc = [&](vector<int>& ops) {
long long x = 0;
long long y = 0;
for (auto op : ops) {
if (op == 1) {
++x;
} else if (op == 2) {
++y;
} else if (op == 3) {
x += y;
} else {
assert(op == 4);
y += x;
}
}
return x;
};
// cout << calc(res) << " | " << n << endl;
cout << res.size() << '\n';
for (auto x : res) {
cout << x << '\n';
}
return 0;
} | #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define ins insert
#define debug(a) cerr<<(a)<<endl
#define dbrep(a,n) rep(_i,n) cerr<<(a[_i])<<" "; cerr<<endl
#define dbrep2(a,n,m) rep(_i,n){rep(_j,m) cerr<<(a[_i][_j])<<" "; cerr<<endl;}
using namespace std;
template<class A, class B>
ostream &operator<<(ostream &os, const pair<A,B> &p){return os<<"("<<p.fi<<","<<p.se<<")";}
template<class A, class B>
istream &operator>>(istream &is, pair<A,B> &p){return is>>p.fi>>p.se;}
template<class T>
vector<T> make_vec(size_t a){
return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
//-------------------------------------------------
int main(void)
{
cin.tie(0);
ios::sync_with_stdio(false);
ll N; cin>>N;
vll fib(2); fib[0]=fib[1]=1;
for(int i=2; fib[i-2]+fib[i-1]<=N; i++){
fib.pb(fib[i-2]+fib[i-1]);
}
int F = fib.size();
set<int> se;
RFOR(i,F-1,0){
if (fib[i]>N) continue;
se.ins(i);
N-=fib[i];
}
vi ans;
RFOR(i,F-1,0){
if (se.count(i)){
if (i&1) ans.pb(2);
else ans.pb(1);
}
if (i&1) ans.pb(3);
else ans.pb(4);
}
int K = ans.size();
cout<<K<<"\n";
rep(i,K) cout<<ans[i]<<"\n";
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define pll pair<int,int>
#define MOD 1000000007
#define M2 998244353
#define INF 2e18
#define EPS 1e-9
#define minheap priority_queue<int, vector<int>, greater<int>>
const ld PI = 3.14159265358979323846;
const int MAX_N = 1e6 + 5;
vector<int> findVals(int a) {
vector<int> vals;
int val = a;
vals.pb(a);
if (a == 1)
return vals;
val = val * a;
val = val % 10;
while (val != a) {
vals.pb(val);
val *= a;
val %= 10;
}
return vals;
}
int power(int x, int y, int p) {
int res = 1;
x = x % p;
while (y > 0) {
if (y & 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
void solve() {
int a, b, c;
cin >> a >> b >> c;
a %= 10;
vector<int> vals = findVals(a);
int len = vals.size();
if (len == 1) {
cout << a << "\n";
return;
}
b %= len;
int rem = power(b, c, len);
rem %= len;
int ind = rem - 1;
if (ind < 0)
ind = len - 1;
cout << vals[ind] << "\n";
}
signed main() {
ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
int t = 1;
//cin >> t;
while (t--) {
solve();
}
return 0;
}
| // clang-format off
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcountll
#define ffs __builtin_ffsll
#define ctz __builtin_ctzll
#define clz __builtin_clz
#define clzll __builtin_clzll
#define all(a) (a).begin(), (a).end()
using namespace std;
using namespace __gnu_pbds;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;
template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename K, typename V> using ordered_map = tree<K, V, less<K>, rb_tree_tag, tree_order_statistics_node_update>;
// clang-format on
int main() {
fastio();
int n;
string s, t;
cin >> n >> s >> t;
int borrow = 0;
ll ans = 0;
forn(i, n) {
ans += borrow;
if (s[i] == '1' and t[i] == '0') {
if (borrow > 0)
borrow--;
else
borrow++;
}
if (s[i] == '0' and t[i] == '1') {
borrow++;
}
}
bool ok = borrow == 0;
cout << (ok ? ans : -1) << endl;
return 0;
} |
#ifdef _DEBUG
#include "../../../library/src/debug_template.cpp"
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else
#define DMP(...) ((void)0)
#endif
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <functional>
using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;
struct init {
init() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
}
} init_;
lint modpow(lint a, lint n, lint mod = MOD) {
lint res = 1;
while (n > 0) {
if (n & 1) res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
int main() {
lint N, M;
cin >> N >> M;
cout << modpow(10, N, M * M) / M % M << '\n';
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
bool solve(long long s, long long p) {
p = 4 * p;
long long up = min(p, (long long)sqrt(p) + 5);
for (long long p1 = 1; p1 <= up; p1++) {
if (p % p1 == 0 && 2 * s == p1 + p / p1) return true;
}
return false;
}
int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
long long s, p;
cin >> s >> p;
cout << (solve(s, p) ? "Yes" : "No") << "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define All(a) (a).begin(),(a).end()
#define INF numeric_limits<ll>::max()
#define MOD 1000000007
ll n;
vector<ll> v;
bool check(ll md){
vector<ll> y;
ll N=n;
while(N>0){
y.push_back(N%md);
N/=md;
}
reverse(All(y));
if(v.size()>y.size()) return false;
if(v.size()<y.size()) return true;
for(ll i=0;i<v.size();i++){
if(v[i]<y[i])return true;
if(v[i]>y[i])return false;
}
return true;
}
int main(){
ll ans,MAX=0,tmp;
string s;
cin >> s>>n;
if(s.size()==1){
if((s[0]-'0')<=n){
cout<<1<<endl;
}else{
cout<<0<<endl;
}
return 0;
}
for(auto i:s){
tmp=i-'0';
v.push_back(tmp);
MAX=max(MAX,tmp);
}
//reverse(All(v));
ll ng=n+1,ma=MAX,md;
//cout << ng <<" "<<ma<< endl;
while(ng-ma>1){
ll md=(ma+ng)/2;
//cout<<md<<endl;
if(check(md)){
ma=md;
}else{
ng=md;
}
}
cout<<ma-MAX<<endl;
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
int main()
{
int a, b;
cin >> a >> b;
int ans = 1;
for(int i = b - a; i ; i--)
{
if(b / i != (a + i - 1) / i)
{
cout << i;
break;
}
}
}
|
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 100000000
#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define repp(i, n, s) for (int i = (int)(n); i >= (int)(s); i--)
#define mp make_pair
#define tp make_tuple
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef tuple<int,int,int> T;
typedef tuple<ll,ll,ll> TL;
ll mod = 1000000007;
ll mod2 = 998244353;
struct UnionFind {
int _n;
vector<int> par, siz;
UnionFind(int n) : par(n), siz(n, 1) {
_n = n;
for (int i = 0; i < n; i++) par[i] = i;
}
int root(int x) {
if (par[x] == x) return x;
return par[x] = root(par[x]);
}
int unite(int x, int y) {
int rx = root(x);
int ry = root(y);
if (rx == ry) return -1;
if (siz[rx] < siz[ry]) swap(rx, ry);
// rx>=ry rxが親
siz[rx] += siz[ry];
par[ry] = rx; //rxにryを結合
return rx;
}
bool same(int x, int y) {
int rx = root(x);
int ry = root(y);
return rx == ry;
}
int size(int x) {
return siz[root(x)];
}
};
ll fraction (ll n){
if (n==1) return 1;
return n * fraction(n-1) % mod2;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll n,k;cin>>n>>k;
vector<vector<ll>> a(n,vector<ll>(n));
rep(i,0,n){
rep(j,0,n){
cin>>a[i][j];
}
}
UnionFind uf1(n);
ll ans = 1;
rep(i,0,n){
rep(j,0,n){
ll f = 0;
if (i<j){
f = 1;
rep(s,0,n){
if (a[i][s]+a[j][s]>k){
f = 0;
}
}
}
if (f) {
uf1.unite(i,j);
}
}
}
rep(i,0,n){
if (uf1.par[i]==i){
ans = ans * fraction(uf1.size(i)) %mod2;
}
}
UnionFind uf2(n);
rep(i,0,n){
rep(j,0,n){
ll f = 0;
if (i<j){
f = 1;
rep(s,0,n){
if (a[s][i]+a[s][j]>k){
f = 0;
}
}
}
if (f) {
uf2.unite(i,j);
}
}
}
rep(i,0,n){
if (uf2.par[i]==i){
ans = ans * fraction(uf2.size(i)) %mod2;
}
}
cout<<ans<<endl;
} | #include <iostream>
#include <algorithm>
#define MOD 998244353
int N, K;
int A[50][50];
int row_ok[50][50];
int col_ok[50][50];
long long num[51];
using namespace std;
long long calc(int line_ok[][50]) {
long long ans = 1;
int group[50];
int groupN[50];
for (int i=0; i<N; i++) group[i] = i;
for (int i=0; i<N; i++) {
groupN[i] = 0;
}
for (int _=0; _<=N; _++) {
for (int i=0; i<N; i++) {
for (int j=0; j<N; j++) {
if (line_ok[i][j] == 1) {
int x = min(group[i], group[j]);
group[i] = group[j] = x;
}
}
}
}
for (int i=0; i<N; i++) {
groupN[group[i]]++;
}
for (int i=0; i<N; i++) {
if (groupN[i] > 0) {
ans *= num[groupN[i]];
ans %= MOD;
}
}
return ans;
}
int main() {
{
long long x = 1;
for (int i=1; i<51; i++)
{
x *= i;
x %= MOD;
num[i] = x;
}
}
cin >> N >> K;
for (int i=0; i<N; i++) {
for (int j=0; j<N; j++) {
cin >> A[i][j];
}
}
for (int i=0; i<N; i++) {
for (int j=0; j<N; j++) {
bool ok = true;
for (int c=0; c<N; c++) {
if (A[c][i] + A[c][j] > K) {
ok = false;
break;
}
}
if (ok) col_ok[i][j] = 1;
}
}
for (int i=0; i<N; i++) {
for (int j=0; j<N; j++) {
bool ok = true;
for (int c=0; c<N; c++) {
if (A[i][c] + A[j][c] > K) {
ok = false;
break;
}
}
if (ok) row_ok[i][j] = 1;
}
}
// row
cout << (calc(row_ok) * calc(col_ok)) % MOD << endl;
return 0;
} |
#include <iomanip>
#include <iostream>
#include <cmath>
using namespace std;
int main() {
int n;
cin >> n;
long long m = 0, c = 0;
double e = 0;
for (int i = 0; i < n; i++) {
long long x;
cin >> x;
m += abs(x);
c = max(c, abs(x));
e += (x * x);
}
e = sqrt(e);
cout << m << endl;
cout << setprecision(18) << e << endl;
cout << c << endl;
} | #include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
#define rrep(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;
}
constexpr double eps = 1e-10;
constexpr ll LINF = 1001002003004005006ll;
constexpr int INF = 1001001001;
#define dame \
{ \
puts("-1"); \
return 0; \
}
#define yn \
{ \
puts("Yes"); \
} \
else { puts("No"); }
constexpr int MAX = 1000001;
int main()
{
cout << fixed << setprecision(20);
int n;
long double b = 0, c = 0, d = 0;
cin >> n;
for (int i = 0; i < n; i++)
{
long double a;
cin >> a;
b += max(a, -a);
c += max(a, -a) * (long double)max(a, -a);
d = max(d, max(a, -a));
}
c = sqrt(c);
cout << b << "\n";
cout << c << "\n";
cout << d << "\n";
return 0;
} |
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb(i) push_back(i)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=b;i>=a;i--)
#define mem(a,b) memset(a,b,sizeof(a))
#define VI vector<int>
#define VLL vector<ll>
#define MPII map<pair<int,int>,int>
#define mp make_pair
#define PQI priority_queue<int>
#define lowbit(x) x&-x
#define debug(a) cout<<#a<<'='<<a<<'\n'
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 1e6 + 10;
const int M = 2e5 + 10;
const int INF = 0x3f3f3f3f;
const int inf = - INF;
const int mod = 1e9+7;
const double pi = acos(-1.0);
const double eps=1e-5;
struct point{
int x,y;
bool operator < (point t) const{
if (x == t.x)
return y < t.y;
return x < t.x;
}
bool operator == (point t) const{
return x == t.x && y == t.y;
}
}p[N];
int a[M],c[M];
int getsum(int x){
int res = 0;
while(x){
res += c[x];
x-=lowbit(x);
}
return res;
}
void update(int x, int y, int n){
while (x <= n){
c[x] += y;
x += lowbit(x);
}
}
point read(){
int x,y;
scanf("%d%d", &x, &y);
return (point){x,y};
}
int main()
{
int h, w, m;
scanf("%d%d%d", &h, &w, &m);
int mx = h + 1, my = w + 1;
for (int i = 1; i <= m; i++){
p[i] = read();
if (p[i].y == 1)
mx = min(mx, p[i].x);
if (p[i].x == 1)
my = min(my, p[i].y);
}
for (int i = mx + 1; i <= h; i++){
p[++m].x = i;
p[m].y = 1;
}
for (int i = my + 1; i <= w; i++){
p[++m].x = 1;
p[m].y = i;
}
sort(p + 1, p + 1 + m);
//m = unique(p + 1, p + 1 + m) -(p + 1);
int pos = 1;
ll ans = 0;
for (int i = 1; i <= m; i++){
if (a[p[i].y] == 0){
a[p[i].y] = 1;
update(p[i].y, 1, w);
}
if (i == m || p[i + 1].x != p[i].x){
ans += getsum(w) - getsum(p[pos].y - 1);
pos = i + 1;
}
}
printf("%lld\n", 1ll* h * w - ans);
return 0;
} | #include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <vector>
#include <map>
#include<cstdio>
#include<functional>
#include <bitset>
#include <iomanip>
#include <cctype>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define ll long long
using namespace std;
template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
vector<vector<ll>> dist;
int main()
{
ll n; cin >> n;
vector<ll> xl(n);
vector<ll> yl(n);
vector<ll> zl(n);
dist.resize(n, vector<ll>(n));
vector<vector<ll>> dp(1 << 17 + 1,vector<ll>(18, INF));
rep(i, n) {
ll x, y, z; cin >> x >> y >> z;
xl[i] = x;
yl[i] = y;
zl[i] = z;
}
rep(i, n) {
rep(j, n) {
dist[i][j] = abs(xl[i] - xl[j]) + abs(yl[i] - yl[j]) + max((ll)0, zl[j] - zl[i]);
}
}
dp[1][0] = 0;
rep(i, 1 << n) {
rep(x, n) {
if (i & (1 << x)) {
rep(y, n) {
chmin(dp[i | (1 << y)][y], dp[i][x] + dist[x][y]);
}
}
}
}
cout << dp[(1 << n) - 1][0] << endl;
system("Pause");
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pll = pair<ll,ll>;
using pld = pair<ld,ld>;
using vll = vector<ll>;
using vld = vector<ld>;
using vstr = vector<string>;
#define _GLIBCXX_DEBUG
#define rep(j, m) for (ll j = 0; j < (ll)(m); j++)
#define rep2(i, l, n) for (ll i = l; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
const ld PI = 3.1415926535897932;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
vll dx = {-1,0,1,0};
vll dy = {0,-1,0,1};
vll Dx = {-1,-1,-1,0,0,1,1,1};
vll Dy = {-1,0,1,-1,1,-1,0,1};
const ll INF = 1000000000000000;
int main() {
ll N;
cin >> N;
if (N*108/100 > 206) {cout << ":(" << endl;}
else if (N*108/100 == 206) {cout << "so-so" << endl;}
else {cout << "Yay!" << endl;}
}
| #include <bits/stdc++.h>
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = 1e5 + 7;
int main(){
int d; scanf("%d", &d);
printf("%d\n", 100 - d % 100);
return 0;
}
|
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
string s;
bool ans = true;
bool flag = true;
int point = 0;
int main()
{
cin >> s;
reverse(s.begin(), s.end());
for (int i = 0; i < s.size(); i++) {
if (s[i] == '0') {
continue;
} else {
point = i;
break;
}
}
for (int i = point; i < s.size(); i++) {
if (s[i] == s[s.size() - 1 - i + point]) {
} else {
flag = false;
}
}
if (flag) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} | //kyoprosaikoooooooooooo!!
#include <bits/stdc++.h>
#define ll long long
#define MOD 1000000007
using namespace std;
//素数判定 O(√N)
ll prime (ll abc) {
if (abc < 2) {
return 0;
}
else if (abc == 2) {
return 1;
}
else if (abc % 2 == 0) {
return 0;
}
double sqrtabc = sqrt(abc);
for (int i = 3; i <= sqrtabc; i++) {
if (abc % i == 0) {
return 0;
}
}
return 1;
}
//素因数分解(約数列挙) O(√N)
vector<ll> divisor(ll n) {
vector<long long> ret;
for (long long 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;
}
//最大公約数
ll gcd(ll x,ll y){
if(x<y) swap(x,y);
ll r;
while(y>0){
r=x%y;
x=y;
y=r;
}
return x;
}
//最小公倍数
ll lcm(ll x,ll y){
return (ll)(x/gcd(x,y))*y;
}
int main() {
string S;
cin >> S;
int sum = 0;
deque<char> ans;
if (S.at(0) != 'R') {
ans.push_back(S.at(0));
}
else {
sum++;
}
for (int i = 1; i < (int)S.size(); i++) {
char a = S.at(i);
if (a == 'R') {
sum++;
}
else {
if (sum % 2 == 0) {
ans.push_back(a);
}
else {
ans.push_front(a);
}
}
}
if (sum % 2 == 1) {
reverse(ans.begin(), ans.end());
}
string A = "";
for (char c : ans) {
if (A.back() == c && A.size()) {
A.pop_back();
}
else {
A.push_back(c);
}
}
cout << A << endl;
} |
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>
using namespace std;
#define int long long
#define endl "\n"
constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007;
struct fast_io {
fast_io(){
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
};
} fio;
signed main(){
cout<<fixed<<setprecision(10);
int N;
long double ans = 0;
cin>>N;
for(int i = 1; i < N; i++){
ans += (long double)N / (N - i);
}
cout<<ans<<endl;
return 0;
} | #include<bits/stdc++.h>
#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i)
#define foreach(i, n) for(auto &i:(n))
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
#define lambda(RES_TYPE, ...) (function<RES_TYPE(__VA_ARGS__)>)[&](__VA_ARGS__) -> RES_TYPE
#define method(FUNC_NAME, RES_TYPE, ...) function<RES_TYPE(__VA_ARGS__)> FUNC_NAME = lambda(RES_TYPE, __VA_ARGS__)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(x) (void)0
#endif
namespace templates{
ll modpow(ll x, ll b,ll mod=MOD){
ll res = 1;
while(b){
if(b&1)res = res * x % mod;
x = x * x % mod;
b>>=1;
}
return res;
}
ll modinv(ll x){
return modpow(x, MOD-2);
}
bool was_output = false;
template<class t>
void output(t a){
if(was_output)cout << " ";
cout << a;
was_output = true;
}
void outendl(){
was_output = false;
cout << endl;
}
template<class t>
istream& operator>>(istream&is, vector<t>&x){
for(auto &i:x)is >> i;
return is;
}
template<class t, class u>
istream& operator>>(istream&is, pair<t, u>&x){
is >> x.first >> x.second;
return is;
}
template<class t>
ostream& operator<<(ostream&os, vector<t> &v){
os << "{";
for(t &i:v){
os << i << ", ";
}
os << "}";
return os;
}
template<class t = long long>
t in(){
t res; cin >> res; return res;
}
template<class t>
void out(t x){
cout << x;
}
template<class t>
vector<t> sorted(vector<t> line,function<bool(t,t)> comp=[](t a,t b){return a<b;}){
sort(line.begin(),line.end(),comp);
return line;
}
template<class t>
vector<t> reversed(vector<t> line){
reverse(line.begin(),line.end());
return line;
}
string reversed(string str){
reverse(str.begin(),str.end());
return str;
}
long long gcd(long long a,long long b){
while(b){
a %= b;
swap(a,b);
}
return a;
}
long long lcm(long long a,long long b){
return a / gcd(a,b) * b;
}
}
using namespace templates;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n = in();
double ans = 0;
rep(i,1,n){
ans += 1 / (1 - (n-i) / (double) n);
}
printf("%.20lf\n",ans);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ll long long
#define ld long double
#define ALL(a) (a).begin(), (a).end()
int main() {
int n;
cin >> n;
vector<pair<ll,ll>> a;
rep(i,n){
ll t, l, r;
cin >> t >> l >> r;
l *= 2;
r *= 2;
if(t==2) r--;
else if(t==3) l++;
else if(t==4){
l++; r--;
}
a.push_back(make_pair(l,r));
}
sort(ALL(a));
ll ans = 0;
for(int i=0; i < (int)a.size()-1; i++){
ll s = a[i].second;
for(int j=i+1; j < (int)a.size(); j++){
ll t = a[j].first;
ll u = a[j].second;
if(t <= s && s <= u) ans++;
else if(u <= s) ans++;
}
}
cout << ans << endl;
return 0;
} | // UTF−8
#include<bits/stdc++.h>
using namespace std;
using ll = long long int;
using lc = complex<double>;
template <class T>
bool complex_comparator(const complex<T> &a, const complex<T> &b) {
return real(a) == real(b) ? imag(a) < imag(b) : real(a) < real(b);
}
/* #include<atcoder/all> */
/* using namespace atcoder; */
template<class T>bool chmax(T &a, const T &b) { return (a<b ? (a=b,1) : 0); }
template<class T>bool chmin(T &a, const T &b) { return (a>b ? (a=b,1) : 0); }
int main(void) {
constexpr ll MOD = 1 ? 1e9+7 : 998244353;
const double PI = acos(-1);
constexpr double eps = 1e-5;
cout << fixed << setprecision(32);
cin.tie(0); ios::sync_with_stdio(false);
if(1) {
ll n;
cin >> n;
vector<tuple<ll,ll,ll>> v(n);
for(auto &[t, l, r]: v)
cin >> t >> l >> r;
ll res = 0;
for(ll i=0; i<n; i++)
for(ll j=i+1; j<n; j++) {
auto [t1, l1, r1] = v[i];
auto [t2, l2, r2] = v[j];
bool ok = true;
ok &= ((t1<3) && ((t2&1) == 1) && l1 <= r2) || l1 < r2;
ok &= ((t2<3) && ((t1&1) == 1) && l2 <= r1) || l2 < r1;
res += ok;
}
cout << res<< endl;
}
return 0;
} |
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define mydeb(fmt, ...) fprintf(stderr, fmt, __VA_ARGS__)
//#define mydeb(fmt, ...)
int main()
{
int64_t k,n,m;
cin >> k >> n >> m;
vector<int64_t> a(k);
rep(i,k)
{
cin >> a[i];
}
vector<int64_t> modn(k);
int64_t modtotal=0;
rep(i,k)
{
modn[i]=(a[i]*m)%n;
modtotal+=modn[i];
//mydeb("i:%d modn:%ld\n",i,modn[i]);
}
modtotal/=n;
vector<pair<int,int>> mp(k);
rep(i,k)
{
mp[i]=make_pair(modn[i],i);
}
sort(mp.begin(),mp.end());
auto it=mp.rbegin();
vector<int> add1(k);
rep(i,modtotal)
{
add1[it->second]=1;
++it;
}
bool first=true;
rep(i,k)
{
if (first==false)
{
cout << " ";
}
first=false;
cout << a[i]*m/n + add1[i];
}
}
| #include<bits/stdc++.h>
#define rep(i,n) for(int i = 0 ; i < (n); ++i)
using namespace std ;
using ll=long long ;
using P=pair<ll,int> ;
const int mod=1000000007;
const int N=1e5 ;
const ll INF=1e18;
struct Edge
{
int to,t,k ;
Edge(int to, int t ,int k):to(to),t(t),k(k){}
};
void solve(){
int n,m,s,d ;
cin>>n>>m>>s>>d ;
s-- ;
d-- ;
vector<vector<Edge>> g(n+1) ;
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>> q ;
auto push=[&](int v,ll x){
if(dist[v]<=x) return ;
dist[v]=x ;
q.emplace(x,v) ;
};
push(s,0) ;
while(!q.empty()){
auto x=q.top().first ;
auto v=q.top().second ;
q.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) ;
}
}
if(dist[d]==INF)
cout<<-1 ;
else
cout<<dist[d] ;
}
int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin) ;
freopen("output.txt","w",stdout) ;
#endif
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(false);
int y ;
y=1 ;
//cin>>y ;
while(y--){
solve() ;
}
return 0 ;
} |
#include <bits/stdc++.h>
using namespace std;
/* * * * * * * * * * */
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
/* * * * * * * * * * */
/* *
*
* I love Ylva Eriksson
*
* */
int main(){
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
int n; cin >> n;
vector <int> a(n);
for (int i = 0; i < n; ++i) cin >>a[i];
int cnt = 0, ans= 0;
for (int i = 2; i <= 1000; ++i) {
int cur = 0;
for (int j = 0; j < n; ++j) cur += (a[j] % i == 0);
if (cur > cnt) {cnt = cur, ans = i; }
}
cout << ans << '\n';
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
long long mod=1e9+7,ans,n;
int main ()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
long long a[n+1],f[n+1];
for(int i=1;i<=n;i++) cin >> a[i];
f[0]=1,f[1]=1;
for(int i=2;i<=n;i++) f[i]=(f[i-1]+f[i-2])%mod;
ans=(f[n]*a[1])%mod;
for(int i=2;i<=n;i++)
{
ans+=(f[n+1-i]*f[i-1]%mod*2%mod+mod-f[n])%mod*a[i]%mod;
ans%=mod;
}
cout << ans;
}
|
#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define BIT(i) (1LL << (i))
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
const long long MOD = 1000000007;
const ll sz = 18;
ll N, M;
ll dp[BIT(sz)];
vector<pll> C[sz + 1];
bool check(ll bit){
vector<ll> acc(N, 0);
REP(i, N){
if(bit & BIT(i)) acc[i]++;
}
ll j = accumulate(ALL(acc), 0LL);
REP(i, N - 1) acc[i + 1] += acc[i];
for(auto [y, z] : C[j]){
if(z < acc[y]) return false;
}
return true;
}
signed main(){
cin >> N >> M;
ll X, Y, Z;
REP(i, M){
cin >> X >> Y >> Z;
Y--;
C[X].push_back({Y, Z});
}
dp[0] = 1;
REP(i, BIT(N)){
REP(j, N){
if(i & BIT(j)) continue;
if(check(i | BIT(j))){
dp[i | BIT(j)] += dp[i];
}
}
}
cout << dp[BIT(N) - 1] << endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxl=3e5+10;
int n,m,k,tot,cas,ans;
int a[maxl];ll fac[maxl];
int cnt[maxl][20];
ll dp[20][maxl];
int x[maxl],y[maxl],z[maxl];
bool vis[maxl];
char s[maxl];
inline void prework()
{
fac[0]=1;
for(int i=1;i<=18;i++)
fac[i]=fac[i-1]*i;
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++)
scanf("%d%d%d",&x[i],&y[i],&z[i]);
for(int s=1;s<(1<<n);s++)
{
for(int i=1;i<=n;i++)
{
if(s>>(i-1)&1)
cnt[s][i]=1;
cnt[s][i]+=cnt[s][i-1];
}
}
}
inline bool jug(int ind,int s)
{
for(int i=1;i<=m;i++)
if(x[i]==ind && cnt[s][y[i]]>z[i])
return false;
return true;
}
inline void mainwork()
{
dp[0][0]=1;
for(int i=1;i<=n;i++)
for(int s=1;s<(1<<n);s++)
if(cnt[s][n]==i && jug(i,s))
{
for(int j=1;j<=n;j++)
if(s>>(j-1)&1)
dp[i][s]+=dp[i-1][s^(1<<(j-1))];
}
}
inline void print()
{
printf("%lld",dp[n][(1<<n)-1]);
}
int main()
{
int t=1;
//scanf("%d",&t);
for(cas=1;cas<=t;cas++)
{
prework();
mainwork();
print();
}
return 0;
} |
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define drep(i,j,n) for(int i=0;i<(int)(n-1);i++)for(int j=i+1;j<(int)(n);j++)
#define trep(i,j,k,n) for(int i=0;i<(int)(n-2);i++)for(int j=i+1;j<(int)(n-1);j++)for(int k=j+1;k<(int)(n);k++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yes(ans) if(ans)printf("yes\n");else printf("no\n")
#define Yes(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YES(ans) if(ans)printf("YES\n");else printf("NO\n")
#define popcount(v) __builtin_popcount(v)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define vector3d(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
const int MOD2=998244353;
const int INF=1<<30;
const ll INF2=1LL<<60;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T,class L>void scan(pair<T, L>& p){scan(p.first);scan(p.second);}
template<class T,class U,class V>void scan(tuple<T,U,V>& p){scan(get<0>(p));scan(get<1>(p));scan(get<2>(p));}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T,class L>void print(const pair<T, L>& p){print(p.first);putchar(' ');print(p.second);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll modinv(ll a, ll m) {ll b = m, u = 1, v = 0;while (b) {ll t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}
ll updivide(ll a,ll b){if(a%b==0) return a/b;else return (a/b)+1;}
template<class T> void chmax(T &a,const T b){if(b>a)a=b;}
template<class T> void chmin(T &a,const T b){if(b<a)a=b;}
/*string dijkstra(int sy,int sx,int gy,int gx){
}*/
int main(){
int test=1000,sy,sx,gy,gx;
int score;
double d2;
while(test--){
cin>>sy>>sx>>gy>>gx;
string s,t;
if(gy>sy)s.resize(gy-sy,'D');
else s.resize(sy-gy,'U');
if(gx>sx)t.resize(gx-sx,'R');
else t.resize(sx-gx,'L');
cout<<s<<t<<endl;
cin>>score;
}
} | #pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
//#include<atcoder/all>
//using namespace atcoder;
using ll = long long;
#define For(i,n,k) for(int i=(n);i<(k);i++)
#define ALL(a) (a).begin(),(a).end()
const int MAX_N = 18;
vector<vector<int>> exdist(MAX_N, vector<int> (MAX_N, 1e9));
int k;
vector<int> c(MAX_N);
int dp[1<<MAX_N][MAX_N];
int dfs(int s, int v){
if(dp[s][v] >= 0){
return dp[s][v];
}
if(s == (1<<k)-1){
return dp[s][v] = 0;
}
int ans = 1e9+100;
For(u,0,k){
if(!(s >> u & 1)){
ans = min(ans, dfs(s | 1 << u, u) + exdist[v][u]);
}
}
dp[s][v] = ans;
return ans;
}
void Main(){
int n, m;
cin >> n >> m;
vector<vector<int>> graph(n+1);
For(i,0,m){
int a, b;
cin >> a >> b;
graph[a].push_back(b);
graph[b].push_back(a);
}
cin >> k;
For(i,0,k){
cin >> c[i];
}
For(i,0,k){
int cnt = 0;
vector<int> dist(n+1, 1e9);
queue<int> q;
dist[c[i]] = 0;
q.push(c[i]);
while(!q.empty()){
auto now = q.front();
q.pop();
for(auto to:graph[now]){
if(dist[to] > dist[now] + 1){
dist[to] = dist[now] + 1;
q.push(to);
}
}
}
For(j,0,k) exdist[i][j] = dist[c[j]];
}
For(i,0,k+1){
exdist[i][k] = 0;
exdist[k][i] = 0;
}
memset(dp,-1,sizeof(dp));
int ans = dfs(0,k) + 1;
cout << (ans >= 1e9 ? -1 : ans) << endl;
}
int main(){
Main();
/*
東方風神録は神が出てくるので当然神ゲー
*/
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, a, b) for(int i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef pair<ll,ll> pll;
typedef vector<string> vs;
typedef vector<pll> vpl;
typedef vector<int> vi;
std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());
#define endl '\n'
#define pb push_back
#define db(x) cerr << #x <<" == "<<x << endl;
#define db2(x,y) cerr<<#x <<" == "<<x<<", "<<#y<<" == "<<y<<endl;
#define db3(x,y,z) cerr << #x<<" == "<<x<<", "<<#y<<" == "<<y<<", "<<#z<<" == "<<z<<endl;
#define ms(v,x) memset(v,x,sizeof(v))
ll exp(ll b,ll e,ll m){
b%=m;
ll ans = 1;
for (; e; b = b * b % m, e /= 2)
if (e & 1) ans = ans * b % m;
return ans;
}
const int N = 21;
vi g[N];
int vis[N];
vi order;
void dfs(int i){
vis[i] = 1;
order.pb(i);
for(auto j : g[i])if(!vis[j])dfs(j);
}
int cor[N];
ll go(int p){
if(p==sz(order))return 1;
ll tot=0;
vi cnt(4,0);
for(auto to : g[order[p]]){
cnt[cor[to]]++;
}
rep(j,1,4){
if(cnt[j])continue;
cor[order[p]] = j;
tot+=go(p+1);
cor[order[p]] = 0;
}
return tot;
}
ll solve(int i){
order.clear();
dfs(i);
return go(0);
}
int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int n,m;
cin >> n >> m;
ll ans = 1;
rep(i,0,m){
int a,b;
cin>>a>>b;
--a;--b;
g[a].pb(b);
g[b].pb(a);
}
rep(i,0,n){
if(!vis[i]){
ans = ans * solve(i);
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#include <chrono>
using namespace std;
using namespace __gnu_pbds;
#define endl '\n'
typedef long long ll;
typedef pair<ll, ll> pii;
typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod = 1e9 + 7;
ll mod_exp(ll a, ll b){
if(b == 0)
return 1ll;
if(b % 2 == 0){
ll t = mod_exp(a, b / 2) % mod;
return t * t % mod;
}
return a * mod_exp(a, b - 1) % mod;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
int n, m;
cin >> n >> m;
ll ans = 0, k = 0;
vector<string> a(n);
for(int i = 0; i < n; i++){
cin >> a[i];
for(int j = 0; j < m; j++)
if(a[i][j] == '.')
k++;
}
vector<vector<int>> u(n, vector<int>(m)), d(n, vector<int>(m));
vector<vector<int>> l(n, vector<int>(m)), r(n, vector<int>(m));
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
if(a[i][j] == '.'){
if(j - 1 >= 0 && a[i][j - 1] == '.')
l[i][j] = l[i][j - 1] + 1;
}
}
for(int j = m - 1; j >= 0; j--){
if(a[i][j] == '.'){
if(j + 1 < m && a[i][j + 1] == '.')
r[i][j] = r[i][j + 1] + 1;
}
}
}
for(int j = 0; j < m; j++){
for(int i = 0; i < n; i++){
if(a[i][j] == '.'){
if(i - 1 >= 0 && a[i - 1][j] == '.')
u[i][j] = u[i - 1][j] + 1;
}
}
for(int i = n - 1; i >= 0; i--){
if(a[i][j] == '.'){
if(i + 1 < n && a[i + 1][j] == '.')
d[i][j] = d[i + 1][j] + 1;
}
}
}
for(int i = 0; i < n; i++)
for(int j = 0; j < m; j++){
if(a[i][j] == '.'){
ll cnt = 1 + u[i][j] + d[i][j] + l[i][j] + r[i][j];
ll rem = k - cnt;
ll ways = (mod_exp(2ll, cnt) + mod - 1) % mod;
ways = (ways * mod_exp(2ll, rem)) % mod;
ans = (ans + ways) % mod;
}
}
cout << ans << endl;
return 0;
} |
#include <iostream>
using namespace std;
int H, W, A, B, ans = 0;
void dfs(int i, int bit, int A, int B){
if(i == H * W) return (void)ans++;
if(bit & 1 << i) return dfs(i + 1, bit, A, B);
if(B) dfs(i + 1, bit | 1 << i, A, B - 1);
if(A){
if(i % W != W - 1 && ~bit & 1 << (i + 1)) dfs(i + 1, bit | 1 << i | 1 << (i + 1), A - 1, B);
if(i + W < H * W) dfs(i + 1, bit | 1 << i | 1 << (i + W), A - 1, B);
}
}
int main(){
cin >> H >> W >> A >> B;
dfs(0, 0, A, B);
cout << ans << endl;
} | #include<bits/stdc++.h>
using namespace std;
main()
{
float v,t,s,d;
cin>>v>>t>>s>>d;
float app=d/v;
if(app<t||app>s)
{
cout<<"Yes"<<endl;
}
else
{
cout<<"No"<<endl;
}
} |
#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;
int a[110];
int b[110];
int c[110];
int d[110];
int n,m,k;
int ans=0;
int s[110];
int p[110];
void f(int x)
{
if(x==k)
{
for(int i=1;i<=n;i++) p[i]=0;
for(int i=1;i<=k;i++)
{
if(s[i-1]==0) p[c[i]]=1;
else p[d[i]]=1;
}
int cnt=0;
for(int i=1;i<=m;i++)
{
if(p[a[i]]==1&&p[b[i]]==1) cnt++;
}
ans=max(ans,cnt);
return;
}
s[x]=0;
f(x+1);
s[x]=1;
f(x+1);
return;
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++)
{
scanf("%d%d",&a[i],&b[i]);
}
scanf("%d",&k);
for(int i=1;i<=k;i++)
{
scanf("%d%d",&c[i],&d[i]);
}
f(0);
printf("%d",ans);
return 0;
}
| #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
// #define int long long
template <class T>
bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template <class T>
inline bool chmin(T &a, T b)
{
if (a > b)
{
a = b;
return true;
}
return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
if (a < b)
{
a = b;
return true;
}
return false;
}
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
<< " " << __FILE__ << endl;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
int N, M;
cin >> N >> M;
vi a(M), b(M);
REP(i, M) {
cin >> a[i] >> b[i];
a[i]--, b[i]--;
}
int K;
cin >> K;
vi c(K), d(K);
REP(i, K) {
cin >> c[i] >> d[i];
c[i]--, d[i]--;
}
int ans = 0;
for (int bit = 0; bit < (1<<K); ++bit)
{
vector<bool> S(N, false);
REP(i, K)
if (bit & (1<<i)) {
S[c[i]] = true;
} else {
S[d[i]] = true;
}
int cnt = 0;
REP(i, M) {
if (S[a[i]] and S[b[i]]) cnt++;
}
ans = max(ans, cnt);
}
cout << ans << endl;
return 0;
}
|
#include<iostream>
#include<utility>
#include<algorithm>
#include<map>
#include<vector>
#include<cmath>
#define forn(i, x, n) for(int i = x; i < (int)(n); i++)
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const bool DEBUG = 0;
void solve(){
int n;
cin>>n;
int sz = (1 << n);
int a[sz];
forn(i, 0, sz) cin>>a[i];
int l = 0, r = sz/2;
forn(i, 0, sz/2) if(a[l] < a[i]) l = i;
forn(i, sz/2, sz) if(a[r] < a[i]) r = i;
cout<< ((a[l] > a[r])? r+1: l+1);
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
//cin>>t;
//while(t--) cout<<solve()<<'\n';
while(t--) solve(), cout<<'\n';
}
| #include <bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
int a,b,c,d;
cin>>a>>b>>c>>d;
cout<<min(min(a,b),min(c,d));
return 0;
} |
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main() {
int n; ll x;
cin >> n >> x;
vector<ll> a(n);
rep(i,n) cin >> a[i];
reverse(a.begin(),a.end());
map<ll,ll> dp;
ll x0 = x/a[0]*a[0];
dp[x0] = 1;
if(x0!=x) dp[x0+a[0]] = 1;
for(int i=1;i<n;++i){
map<ll,ll> ndp;
ll mx = a[i-1]/a[i];
for(auto p:dp){
ll d = x-p.first;
ll m = d/a[i];
ll nx = p.first + m*a[i];
if(abs(m)<mx) {
ndp[nx] += p.second;
}
if(nx!=x && abs(m)+1<mx) {
ndp[nx + a[i]*(d/abs(d))] += p.second;
}
}
swap(dp,ndp);
}
cout << dp[x] << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)
namespace IO {
const int MAXIOSIZE = 1 << 24 | 1;
unsigned char buf[MAXIOSIZE], *p1, *p2;
#define gc (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 24, stdin), p1 == p2) ? EOF : *p1++)
template <typename T> void read(T& x) {
x = 0; char ch = gc; bool flg = false;
for (; ch < '0' || '9' < ch; ch = gc) if (ch == '-') flg |= true;
for (; '0' <= ch && ch <= '9'; ch = gc) x = x * 10 + ch - '0';
flg ? x = -x : 0;
}
template <typename T> void out(const T& x) { if (x > 9) out(x / 10); putchar(x % 10 + '0'); }
template <typename T> inline void write(const T& x, const char& ed) { if (x < 0) putchar('-'), out(-x); else out(x); putchar(ed); }
}
typedef long long ll;
const int MAXN = 50 + 10;
int n;
ll x, X[MAXN], a[MAXN], A[MAXN], f[MAXN][2];
int main() {
IO::read(n); IO::read(x);
a[0] = 1;
rep(i, 1, n) IO::read(a[i]), A[i - 1] = (a[i] / a[i - 1]) - 1;
A[n] = LONG_LONG_MAX;
ll x_copy = x;
per(i, n, 1) {
if (!x_copy) break;
if (x_copy >= a[i]) X[i] = x_copy / a[i], x_copy %= a[i];
}
f[0][0] = 1;
rep(i, 0, n - 1) {
rep(carry, 0, 1) {
ll& slf = f[i][carry];
ll nxt = X[i + 1] + carry; bool carry_tag = false;
if (nxt > A[i + 1]) carry_tag = true;
f[i + 1][carry_tag] += slf;
nxt = A[i + 1] + 1 - carry - X[i + 1];
if (nxt > 0 && nxt <= A[i + 1]) f[i + 1][true] += slf;
}
}
IO::write(f[n][false], '\n');
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int c,a,b;
cin >> a >> b>> c;
cout << a-b+c;
// your code goes here
return 0;
} | #include<bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
int main() {
int a, b, c;
cin >> a >> b >> c;
vector<int> m(3);
m[0] = a;
m[1] = b;
m[2] = c;
sort(m.rbegin(), m.rend());
int ans = 0;
rep(i, 0, 2) ans += m[i];
cout << ans << endl;
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,x;
double now;
int main() {
cin>>n>>x;
x*=100;
for(int i=1,v,p;i<=n;i++) {
cin>>v>>p;
x-=v*p;
if(x<0) {cout<<i<<endl;return 0;}
}
cout<<-1;
return 0;
}
| //-----------------------------------------------MACROS----------------------------------------------------------------------
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define ull unsigned long long
#define lld long double
#define all(a) a.begin(),a.end()
#define fi first
#define sc second
#define pii pair<int,int>
#define FOR(sz) for(int i = 0; i < sz; i++)
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
//-----------------------------------------------MACROS----------------------------------------------------------------------
//---------------------------------------------DEBUGGER-----------------------------------------------------------------------
#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x <<" "; _print(x); cerr << endl;
#else
#define debug(x)
#endif
void _print(ll t) {cerr << t;}
void _print(int t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(lld t) {cerr << t;}
void _print(double t) {cerr << t;}
void _print(ull t) {cerr << t;}
template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}
//---------------------------------------------DEBUGGER-----------------------------------------------------------------------
//TO-DO ll V/s int?
int t;
ll n;
ll f(ll m) {
ll x = (ll)((100 + t) * m)/100;
return x;
}
void solve() {
cin >> t >> n;
ll l = 1;
ll r = 1e12 + 1;
while(r > l + 1) {
ll mid = (l+r)/2;
if(f(mid) - mid < n) {
l = mid;
}
else
r = mid;
}
cout << f(l) + 1;
}
int main(){
IOS;
#ifndef ONLINE_JUDGE
freopen("input.txt","r", stdin);
freopen("output.txt", "w" , stdout);
freopen("Error.txt","w",stderr);
#endif
int tc = 1;
//cin >> tc;
while(tc--) {
solve();
}
return 0;
} |
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#include <complex>
#define rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define reps(x, s) for(llint (x) = 0; (x) < (llint)(s).size(); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define all(x) (x).begin(),(x).end()
#define outl(x) cout << x << endl
#define SP << " " <<
#define inf 1e18
using namespace std;
typedef long long llint;
typedef long long ll;
typedef pair<llint, llint> P;
ll n;
vector<ll> G[100005];
ll num[100005];
ll dp[100005];
void dfs(int v)
{
num[v] = 1;
for(auto u : G[v]) dfs(u), num[v] += num[u];
vector<ll> vec[2];
for(auto u : G[v]) vec[num[u]%2].push_back(dp[u]);
sort(all(vec[0])), reverse(all(vec[0]));
sort(all(vec[1])), reverse(all(vec[1]));
dp[v] = -1;
reps(i, vec[0]) if(vec[0][i] >= 0) dp[v] += vec[0][i];
reps(i, vec[1]){
if(i % 2 == 0) dp[v] += vec[1][i];
else dp[v] -= vec[1][i];
}
reps(i, vec[0]) if(vec[0][i] < 0){
if(vec[1].size() % 2) dp[v] -= vec[0][i];
else dp[v] += vec[0][i];
}
}
int main(void)
{
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
ll p;
rep(i, 2, n){
cin >> p;
G[p].push_back(i);
}
dfs(1);
//rep(i, 1, n) cout << dp[i] << " "; cout << endl;
cout << (n-dp[1])/2 << endl;
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using std::cin;
using std::cout;
using std::vector;
using ll = long long;
int main() {
int n;
cin >> n;
vector<int> a(n);
rep(i, n) cin >> a[i];
vector<int> cnt(200);
rep(i, n) cnt[a[i] % 200]++;
ll ans = 0;
rep(i, 200) ans += (ll)cnt[i] * (cnt[i] - 1) / 2;
cout << ans << '\n';
return 0;
} |
//Let's join Kaede Takagaki Fan Club !!
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//#define int long long
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define a first
#define b second
#define fi first
#define sc second
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),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 all(x) x.begin(),x.end()
#define si(x) int(x.size())
#ifdef LOCAL
#define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl
#else
#define dmp(x) void(0)
#endif
template<class t,class u> bool chmax(t&a,u b){if(a<b){a=b;return true;}else return false;}
template<class t,class u> bool chmin(t&a,u b){if(b<a){a=b;return true;}else return false;}
template<class t> using vc=vector<t>;
template<class t,class u>
ostream& operator<<(ostream& os,const pair<t,u>& p){
return os<<"{"<<p.fi<<","<<p.sc<<"}";
}
template<class t> ostream& operator<<(ostream& os,const vc<t>& v){
os<<"{";
for(auto e:v)os<<e<<",";
return os<<"}";
}
template<class T>
void g(T &a){
cin >> a;
}
template<class T>
void o(const T &a,bool space=false){
cout << a << (space?' ':'\n');
}
//ios::sync_with_stdio(false);
const ll mod = 1000000007;//998244353
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
template<class T>
void add(T&a,T b){
a+=b;
if(a >= mod) a-=mod;
}
ll modpow(ll x,ll n){
ll res=1;
while(n>0){
if(n&1) res=res*x%mod;
x=x*x%mod;
n>>=1;
}
return res;
}
void solve(){
int l, r; cin >> l >> r;
ll ans = 0;
if(l+l > r) ans = 0;
else ans = 1LL * (r - l - l + 1) * (r - l - l + 2) / 2;
cout << ans << endl;;
}
signed main(){
cin.tie(0);
ios::sync_with_stdio(0);
cout<<fixed<<setprecision(20);
int t; cin >> t;
while(t--) solve();
}
| #include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
const int mm=2e5+100;
ll d[mm];
int main()
{
ll n,m,i,j,t,a,b,c,p,k,kk;
scanf("%lld",&t);
while(t--)
{
scanf("%lld%lld",&n,&m);
ll sum=0;
a=m-(2*n)+1; a=max(0ll,a);
p=m-(n+m)+1; p=max(0ll,p);
sum=(a+p)*(a-p+1)/2;
cout<<sum<<endl;
}
} |
#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 rep2(i, n, m) for(int i=(int)n; i<=(int)m; i++)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> wi;
typedef vector<ll> vl;
const ll inf=1LL<<60;
const ll mod=1000000007;
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
vi a(n), b(n);
rep(i, n){cin >> a[i];
}
rep(i, n)cin >> b[i];
int ans=0;
rep(i, n)ans+=a[i]*b[i];
if(ans!=0)cout << "No\n";
else cout << "Yes\n";
return 0;
} | #include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>
#include <cassert>
using namespace std;
//using namespace atcoder;
#define REP(i, n) for (int i=0; i<(n); ++i)
#define RREP(i, n) for (int i=(int)(n)-1; i>=0; --i)
#define FOR(i, a, n) for (int i=(a); i<(n); ++i)
#define RFOR(i, a, n) for (int i=(int)(n)-1; i>=(a); --i)
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl;
template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
os << "[";
REP(i, SZ(v)) {
if (i) os << ", ";
os << v[i];
}
return os << "]";
}
template<class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
return os << "(" << p.first << " " << p.second << ")";
}
template<class T>
bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template<class T>
bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return true;
}
return false;
}
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;
const ll MOD = 1e9 + 7;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
const ld eps = 1e-9;
// edit
void solve() {
int T;
cin >> T;
while (T--) {
int N;
cin >> N;
vector<ll> v(N);
REP(i, N) cin >> v[i];
if (N % 2 == 1) {
cout << "Second" << endl;
} else {
// cout << "First" << endl;
sort(ALL(v));
bool first = false;
for (int i = 0; i < v.size(); i += 2) {
if (v[i] != v[i + 1]) {
first = true;
break;
}
}
if (first) {
cout << "First" << endl;
} else {
cout << "Second" << endl;
}
}
}
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
// std::ifstream in("input.txt");
// std::cin.rdbuf(in.rdbuf());
solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define d(x) cout<<x<<" "
#define nl cout<<endl
#define rep(var,init_val,final_val) for(int var = init_val; var < final_val; ++var)
#define show(a,b) rep(i,0,b) d(a[i]);nl;
#define showv(a) for(auto x : a) d(x);nl;
#define vi std::vector<int>
#define pi pair<int,int>
#define mod 1000000007
void solve(){
int a , b;
cin>>a>>b;
vi ans;
if(a>b){
int sum = 0;
rep(i,1,a+1){
ans.pb(i);
sum+=i;
}
rep(i,1,b){
ans.pb(-i);
sum-=i;
}
ans.pb(-sum);
}
else{
int sum = 0;
rep(i,1,b+1){
ans.pb(-i);
sum+=i;
}
rep(i,1,a){
ans.pb(i);
sum-=i;
}
ans.pb(sum);
}
showv(ans);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
//cin>>t;
while(t--)
solve();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false), cin.tie(0);
if (fopen("input.in", "r"))
freopen("input.in", "r", stdin), freopen("output.out", "w", stdout);
int n;
cin>>n;
vector<int> a(n); for(int& i : a) cin>>i, i--;
vector<int> loc(n);
for(int i = 0; i < n; i++) loc[a[i]] = i;
vector<int> ans;
vector<bool> used(n-1, 0);
bool bad = 0;
for(int i = 0; i < n; i++) {
if(loc[i] != i){
assert(loc[i] > i);
for(int k = loc[i]-1; k>=i; k--){
if(used[k]) {
bad = 1; goto done;
}
used[k] = 1;
ans.push_back(k);
loc[a[k]]++;
loc[a[k+1]]--;
swap(a[k], a[k+1]);
assert(loc[a[k+1]]==k+1 && loc[a[k]]==k);
}
}
assert(loc[i] == i);
}
done:;
if(ans.size()!=n-1) bad=1;
if(bad) cout<<-1<<'\n';
else for(int i : ans) cout<<i+1<<'\n';
}
|
#include <iostream>
#include <vector>
using namespace std;
vector<int> v[1500010];
int main(){
int i,j,n,m; cin >> n >> m;
for(i=0;i<n;i++) v[i].push_back(-1);
for(i=0;i<n;i++){
int a; cin >> a;
v[a].push_back(i);
}
for(i=0;i<n;i++) v[i].push_back(n);
for(i=0;i<=n;i++){
if(v[i].size()<=2){
cout << i << endl;
return 0;
}
for(j=1;j<v[i].size();j++){
if(v[i][j] - v[i][j - 1]>m){
cout << i << endl;
return 0;
}
}
}
} | #include<bits/stdc++.h>
using namespace std;
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
typedef int ll;
typedef long double ld;
typedef pair<ll,ll> p2;
#define sz(a) ll(a.size())
ll a[2000005];
void solve(){
ll n,m;
cin>>n>>m;
for(ll i=0;i<n;i++)
cin>>a[i];
ll l0=0,r0=n;
while(l0<=r0){
ll m0=(l0+r0)/2,f=0;
vector<ll> v(m0,0);
for(ll i=0;i<m;i++){
if(a[i]>=m0)
continue;
v[a[i]]++;
}
for(ll i=0;i<m0;i++)
if(v[i]==0){
f=1;
break;
}
if(!f){
for(ll i=1;i<=n-m;i++){
if(a[i+m-1]<m0){
v[a[i+m-1]]++;
}
if(a[i-1]<m0){
v[a[i-1]]--;
if(v[a[i-1]]==0){
f=1;
break;
}
}
}
}
if(f)
r0=m0-1;
else
l0=m0+1;
}
cout<<r0;
}
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
clock_t z=clock();
ll qc=1;
//cin>>qc;
for(ll i=1;i<=qc;i++){
solve();
}
debug("Total Time:%.4Lf\n",(ld)(clock()-z)/CLOCKS_PER_SEC);
} |
#include <cmath>
#include <iostream>
int main() {
long long n;
std::cin >> n;
long long ans {0};
long long k {1};
while (n >= pow(10, k*3)) {
ans += n - pow(10, k*3) + 1;
++k;
}
std::cout << ans << std::endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
string s;cin>>s;int cnt=0;
for(int i=3;i<s.size();i++){
if(s[i]=='e' && s[i-1]=='N' && s[i-2]=='O' && s[i-3]=='Z')cnt++,i+=2;
}
cout<<cnt<<endl;
} |
// arc110_a
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()
#define INF (ll)(1e9)
#define MOD (1000000007)
#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int idx=0;idx<(n-1);idx++) cout << (vec)[idx] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << "\n";}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a * b / gcd(a, b);}
int main() {
#ifdef LOCAL
ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif
ll N;
cin >> N;
ll m = 1;
REPN(i, 2, N+1){
m = lcm(m, i);
}
print(m+1);
return 0;
}
| #include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
// please, read the question correctly (do you need set or multiset)???
const int N=200010; //check the limits, dummy
int a[N];
int n, m;
int main(){
// int t;
// while(){
scanf("%d",&n);
ll ans = 2, tmp;
for(ll i=3; i<=n; ++i){
tmp = __gcd(ans, i);
ans = (ans * i)/tmp;
}
ans += 1;
for(int i=2; i<=n; ++i){
assert(ans%i==1);
}
cout<<ans<<endl;
// }
} |
#include <cstdio>
int main() {
long long s, p;
scanf("%lld%lld", &s, &p);
for (long long i = 1; i * i <= p; ++i)
if (p % i == 0) {
if (i + p / i == s) return puts("Yes"), 0;
}
puts("No");
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//
int main() {
ll S, P;
cin >> S >> P;
puts([&] {
for (ll i = 1; i * i <= P; ++i) {
ll n = i, m = S - i;
if (n > 0 && m > 0 && n * m == P) return true;
}
return false;
}() ? "Yes": "No");
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)
#define io ios::sync_with_stdio(false); cin.tie(0)
int main()
{
io;
int n, m; cin >> n >> m;
ll a = 0, b = 0;
rep(i, n) {
string s;
cin >> s;
int cnt = 0;
for (auto c : s) {
if (c == '1') cnt++;
}
if (cnt % 2 == 0) a++;
else b++;
}
cout << a*b << endl;
return 0;
} | #include <bits/stdc++.h>
#include <variant>
#define rep2(i,k,n) for(i64 i=(i64)(k);i<(i64)(n);i++)
#define rep(i,n) rep2(i,0,n)
#define all(x) begin(x),end(x)
#ifdef ENV_LOCAL
#define dump if (1) cerr
#else
#define dump if (0) cerr
#endif
using namespace std;
using namespace std::string_literals;
using i32 = int32_t;
using i64 = int64_t;
using f64 = double;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
//using namespace harudake;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
i32 n;
cin>>n;
vi32 oknum;
rep2(i,1,5000) {
if (i % 3 == 0 || i % 5 == 0 || i % 7 == 0) {
oknum.push_back(i*2);
}
}
rep(i,n-1) {
cout<<oknum[i]<<" ";
}
cout<<(3*5*7)<<endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
//#include "testlib.h"
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define int long long
#define ll long long
#define M 1000000007
#define MM 998244353
#define inputarr(a,n) for(int i=0;i<n;++i) cin>>a[i]
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) m*(n/GCD(m,n))
#define mii map<ll ,ll >
#define msi map<string,ll >
#define rep(a,b) for(ll i=a;i<b;i++)
#define rep0(n) for(ll i=0;i<n;i++)
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#define vi vector<ll>
#define vs vector<string>
#define ppb pop_back
#define endl '\n'
#define asdf ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define r0 return 0;
#define FORD(i, a, b) for (int i = (int) (a); i >= (int) (b); --i)
#define inputoutput freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define Set(a, s) (a, s, sizeof (a))
#define FOR repi
#define vii vector<pii>
#define pii pair<int,int>
#define REVERSE(v) reverse(all(v))
#define trav(a, x) for(auto& a : x)
#define display(x) trav(a,x) cout<<a<<" ";cout<<endl
#define debug cerr<<"bhau"<<endl
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
template<typename T, typename U> static inline void amin(T &x, U y)
{
if (y < x)
x = y;
}
template<typename T, typename U> static inline void amax(T &x, U y)
{
if (x < y)
x = y;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll max(ll a, ll b) { return (a > b)? a : b;}
int min(int a, int b) { return (a < b)? a : b;}
const int N = 4e5+10;
vi adj[N];
bool vis[N];
int vert;
bool tree = 1;
void dfs(int v,int p){
vert++;
vis[v]=1;
for(auto i:adj[v]){
if(i!=p){
if(vis[i])
tree=0;
else
dfs(i,v);
}
}
}
int solve(){
int n;cin>>n;
int a,b;
rep0(n){
cin>>a>>b;
adj[a].pb(b);
adj[b].pb(a);
}
int ans=0;
for(int i=1;i<=N;i++){
if(!vis[i]){
tree = 1;
vert=0;
dfs(i,-1);
if(tree){
ans+=vert-1;
}
else ans+=vert;
}
}
cout<<ans<<endl;
return 0;
}
signed main(){
asdf
int t=1;
// cin>>t;
while(t--){
solve();
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <class c, class cmp = less<c> > using ordered_set = tree<c, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}
template <typename T,typename U>pair<T,U> operator+(const pair<T,U> & l,const std::pair<T,U> & r) { return {l.first+r.first,l.second+r.second};}
typedef long long int ll;
const ll MOD = 1e9 + 7;
const ll maxn = 5e6 + 5;
#define endl '\n'
#define ld long double
#define int ll
#define all(x) (x).begin(),(x).end()
ll sum(ll x, ll y)
{
x += y;
if (x >= MOD)
return x - MOD;
return x;
}
ll mult(ll x, ll y)
{
return (x * y) % MOD;
}
inline ll power(ll a, long long b) {
ll res = 1;
while (b > 0) {
if (b & 1) {
res = mult(res, a);
}
a = mult(a, a);
b >>= 1;
}
return res;
}
const ll N=100;
int n;
struct Matrix
{
ll a[N][N];
Matrix()
{
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
a[i][j] = 0;
}
Matrix operator * (const Matrix &X) const
{
Matrix res;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
{
res.a[i][j] = 0;
for (int h = 0; h < n; h++)
{
res.a[i][j] = sum(res.a[i][j], mult(a[i][h], X.a[h][j]));
}
}
return res;
}
};
Matrix bin_pow(Matrix x, ll pow)
{
if (pow == 1) return x;
if (pow == 2) return x * x;
if (pow & 1) return x * bin_pow(x, pow - 1);
return bin_pow(bin_pow(x, pow / 2), 2);
}
int32_t main(){
IOS
int m, k;
cin >> n >> m >> k;
int a[n];
for(int i = 0; i<n;i++){
cin >> a[i];
if(k == 0) cout << a[i] << endl;
}
if(k == 0) return 0;
int inv_m = power(2*m, MOD - 2);
Matrix G;
int deg[n] = {0};
for(int i = 0; i < m;i++){
int u, v;
cin >> u >> v;
u--, v--;
deg[u]++;
deg[v]++;
G.a[u][v] = inv_m;
G.a[v][u] = inv_m;
}
for(int i = 0;i < n;i++) G.a[i][i] = mult(2*m - deg[i], inv_m);
// for(int i = 0; i < n;i++){
// for(int j = 0;j<n;j++) cout << G.a[i][j] << " ";
// cout << endl;
// }
G = bin_pow(G, k);
for(int i = 0; i < n;i++){
int ans = 0;
for(int j = 0; j < n;j++){
ans = sum(ans, mult(a[j], G.a[j][i]));
}
cout << ans << endl;
}
} |
#include"bits/stdc++.h"
using namespace std;
#define pb push_back
#define eb emplace_back
#define ins insert
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define lb lower_bound
#define ub upper_bound
#define sz(x) (int)x.size()
#define pii pair<int,int>
#define fir first
#define sec second
#define popcount __builtin_popcount
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using ll=long long int;
using ld=long double;
#define mp make_pair
#define mt make_tuple
#define bit(x,j) (((ll)x>>j)&1)
#define um unordered_map
#define mem(a,val) memset(a,val,sizeof(a))
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(ld 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...);}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p)
{ return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p)
{ return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")"; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
cerr << " " << to_string(H);
debug_out(T...);
}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#ifndef ONLINE_JUDGE
#define debugt(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debugt(...) 42
#endif
constexpr ll inf=2223372036854775807;
constexpr int mod1=(1e9+7);
constexpr int mod2=(998244353);
constexpr int MAX=(1e4+3);
constexpr int N=2e5+5;
int f(int n){
int s=0;
while(n){
s+=n%10; n/=10;
}
return s;
}
void solve()
{
int a,b; cin>>a>>b;
cout<<max(f(a),f(b))<<"\n";
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(0);
int t=1; int c=1;
while(t--)
{
solve(); c++;
}
} | #include<bits/stdc++.h>
#define For(a,b,c) for(int a=b;a<=c;++a)
#define Dor(a,b,c) for(int a=b;a>=c;--a)
#define CC(_...) fprintf(stderr,_)
using namespace std;
typedef long long LL;
enum{N=800007};
int n,A[N],B[N],I[N],S[N];
bool cmp(int x,int y) {
return A[x]<A[y];
}
int main() {
scanf("%d",&n);
For(i,1,2*n) scanf("%d",A+i),I[i]=i;
sort(I+1,I+1+2*n,cmp);
For(i,1,n) B[I[i]]=1;
int t=0,o;
For(i,1,2*n) {
if(!t||o==B[i]) {
S[++t]=i,o=B[i];
putchar('(');
}
else {
--t;
putchar(')');
}
}
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#define Mod(x) (x>=P)&&(x-=P)
#define rep(i,a,b) for(ll i=a,i##end=b;i<=i##end;++i)
#define drep(i,a,b) for(ll i=a,i##end=b;i>=i##end;--i)
#define erep(i,a) for(ll i=hd[a];i;i=nxt[i])
typedef long long ll;
void Max(ll &x,ll y){x<y&&(x=y);}
void Min(ll &x,ll y){x>y&&(x=y);}
bool vio;
char IO;
ll rd(ll res=0){
bool f=0;
while(IO=getchar(),IO<48||IO>57)
f|=IO=='-';
do res=(res<<1)+(res<<3)+(IO^48);
while(IO=getchar(),isdigit(IO));
return f?-res:res;
}
const ll M=1005;
ll nxt[M],to[M],hd[M],ecnt,n,m;
bool mk[M],fl;
ll dep[M];
void Add(ll a,ll b){
nxt[++ecnt]=hd[a],to[hd[a]=ecnt]=b;
}
void dfs(ll x){
if(!fl)return ;
erep(i,x){
ll y=to[i];
if(!mk[y])continue;
if(dep[y]==-1)dep[y]=dep[x]^1,dfs(y);
else if(dep[y]==dep[x])fl=0;
}
}
bool let;
int main(){
cerr<<(&vio-&let)/1024.0/1024<<endl;
n=rd(),m=rd();
rep(i,1,m){
ll a=rd(),b=rd();
Add(a,b),Add(b,a);
}
ll S=(1<<n)-1,res=0;
rep(k,0,S){
rep(i,1,n)mk[i]=0,dep[i]=-1;
rep(i,1,n)if(1<<(i-1)&k)
mk[i]=1;
ll ans=1;
fl=1;
rep(i,1,n)if(!mk[i])
erep(j,i)if(!mk[to[j]])fl=0;
rep(i,1,n)if(mk[i]&&dep[i]==-1)
ans=ans*2,dep[i]=0,dfs(i);
if(fl)res+=ans;
}
printf("%lld",res);
return 0;
}
| #include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<utility>
using namespace std;
typedef long long ll;
const int MAXN = 1e5 + 5;
ll A[MAXN], N, M, K, mx[MAXN], mn[MAXN];
bool check(ll x) {
ll MX = 0, MN = 0;
for(int i = 1; i <= K; i++) {
MX += (x + M * A[i]) / N;
if(M * A[i] - x > 0) {
MN += (M * A[i] - x) / N + ((M * A[i] - x) % N != 0);
}
}
return (MX >= M && MN <= M);
}
ll find() {
ll l = 0, r = M * N;
ll ans = (l + r) >> 1;
while(l <= r) {
ll mid = (l + r) >> 1;
if(check(mid)) {
ans = mid;
r = mid - 1;
} else l = mid + 1;
}
return ans;
}
int main() {
scanf("%lld%lld%lld", &K, &N, &M);
for(int i = 1; i <= K; i++) scanf("%lld", &A[i]);
ll ans = find();
for(int i = 1; i <= K; i++) {
mx[i] = (ans + M * A[i]) / N;
if(M * A[i] - ans > 0) {
mn[i] = (M * A[i] - ans) / N + ((M * A[i] - ans) % N != 0);
} else mn[i] = 0;
}
for(int i = 1; i <= K; i++) M -= mn[i];
for(int i = 1; i <= K; i++) {
ll diff = mx[i] - mn[i];
mn[i] += min(M, diff);
M -= min(M, diff);
if(M == 0) break;
}
for(int i = 1; i <= K; i++) printf("%lld ", mn[i]);
return 0;
}
|
#include <bits/stdc++.h>
//#include <atcoder/all>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}
const long long INF = 1e18;
//const ll mod = 1000000007;
ll N, K;
ll h(ll j) {
ll ret = 0;
if(j <= 0) return 0;
if(j > 2 * N) {
return 0;
}
if(j <= N + 1) {
return j - 1;
} else {
ll k = N - (j - N) + 1;
return k;
}
return ret;
}
ll g(ll j) {
ll ret = 0;
if(j <= 0) return 0;
if(j > 2 * N) {
ret += N * N;
return ret;
}
if(j <= N + 1) {
ret += (j - 1) * j / 2;
} else {
ret += N * N;
ll k = N - (j - N) + 1;
ret -= (k - 1) * (k) / 2;
}
return ret;
}
ll f(ll x) {
ll ret = 0;
for(ll i = 1; i <= N; i++) {
ll j = x - i;
ret += g(j);
}
return ret;
}
ll f2(ll x) {
if(1 <= x and x <= N) return 1;
return 0;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> N >> K;
ll ok = 0;
ll ng = 3 * N + 1;
while(abs(ok - ng) > 1) {
ll mid = (ok + ng) / 2;
if(f(mid) < K) ok = mid;
else ng = mid;
}
ll sum = ok + 1;
K -= f(ok);
//cout << ok << " " << K << endl;
for(ll a = 1; a <= N; a++) {
if(K > h(sum - a)) {
K -= h(sum - a);
continue;
}
for(ll b = 1; b <= N; b++) {
if(K > f2(sum - a - b)) {
K -= f2(sum - a - b);
continue;
}
ll c = sum - a - b;
cout << a << " " << b << " " << c << endl;
return 0;
}
}
return 0;
} | #include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <functional>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <bitset>
#include <math.h>
#include <random>
#include <chrono>
#include <assert.h>
using namespace std ;
using ll = long long ;
using ld = long double ;
template<class T> using V = vector<T> ;
template<class T> using VV = V<V<T>> ;
using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end()
ll mod = 1000000007 ;
long double pie = acos(-1) ;
ll INF = 1e18 ;
void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
ll extGCD(ll a,ll b,ll &x,ll &y){
if(b==0){
x = 1 ;
y = 0 ;
return a ;
}
ll d = extGCD(b,a%b,y,x) ;
y -= a/b*x ;
return d ;
}
void fix_cout(){cout << fixed << setprecision(20) ;}
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 ;}
int main(){
ll n,k ;
cin >> n >> k ;
auto f = [&](ll a){
ll res = 0 ;
if(a-3<0) return res ;
res += (a-1)*(a-2)/2 ;
if(a-3-n<0) return res ;
res -= (a-1-n)*(a-2-n)/2*3 ;
if(a-3-2*n<0) return res ;
res += (a-1-2*n)*(a-2-2*n)/2*3 ;
if(a-3-3*n<0) return res ;
res -= (a-1-3*n)*(a-2-3*n)/2 ;
return res ;
} ;
V<ll> three(3*n+1,0) ;
for(int i=0;i<=3*n;i++) three[i] = f(i) ;
for(int i=1;i<=3*n;i++) three[i] += three[i-1] ;
auto g = [&](ll a){
ll res = 0 ;
if(a-2<0) return res ;
res += (a-1) ;
if(a-2-n<0) return res ;
res -= (a-1-n)*2 ;
if(a-2-2*n<0) return res ;
res += (a-1-2*n) ;
return res ;
} ;
ll l=0,r=3*n,mid ;
while(l+1<r){
mid = (l+r)/2 ;
if(three[mid]>=k) r = mid ;
else l = mid ;
}
ll sum = r ;
k -= three[l] ;
V<ll> two(2*n+2,0) ;
for(int i=1;i<=n;i++) if(2<=sum-i&&sum-i<=2*n) two[sum-i] = g(sum-i) ;
for(int i=2*n-1;i>=0;i--) two[i] += two[i+1] ;
// for(auto i:two) cout << i << " " ; cout << endl ;
// cout << "???" << endl ;
l = max(1ll,sum-2*n)-1 ;
r = min(n,sum-2) ;
while(l+1<r){
mid = (l+r)/2 ;
// cout << l << " " << mid << " " << r << " " << k << endl ;
if(sum-mid<=2*n&&(sum-mid<2||two[sum-mid]>=k)) r = mid ;
else l = mid ;
}
// cout << sum << " " << r << endl ;
k -= two[sum-r+1] ;
mid = max(1ll,sum-r-n)+k-1 ;
cout << r << " " << mid << " " << sum-r-mid << endl ;
}
|
#pragma GCC optimize("Ofast") //Comment optimisations for interactive problems (use endl)
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define fastio ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
#define randomINIT mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define all(x) (x).begin(),(x).end()
#define mset(x,val) memset(x,val,sizeof(x))
#define endl "\n"
#define pb push_back
#define sym(s) s="#"+s+"#";
#define mp make_pair
#define s second
#define f first
#define dline cerr<<"///REACHED///\n";
#define debv(a) for(auto it: a)cout<<it<<" ";cout<<endl;
#define deb1(a) cout<<a<<endl;
#define deb2(a,b) cout<<a<<" "<<b<<endl;
#define deb3(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl;
#define deb4(a,b,c,d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
#define uniq(a) a.resize(unique(a.begin(), a.end()) - a.begin());
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
const ll MOD = 1e+9+7;
const ll INF = 0x7f7f7f7f7f7f7f7f;
const int INFi = 0x7f7f7f7f;
const ll N = 3e+5+7;
vll adj[N];ll vis[N]={};
int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1};
int dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};
//<<-----Declare Variable Here------->>//
int t=1;
ll n,a[N];
vll v;
ll p[N],sz[N];
//<<-----Implement Functions Here---->>//
void make(){
for(ll i = 1;i <= 2e5; i++)p[i] = i,sz[i] = 1;
}
ll find(ll x){
return (p[x] == x)? x: p[x] = find(p[x]);
}
void merge(ll x, ll y){
ll a = find(x);ll b = find(y);
if(a != b){
if(sz[a] >= sz[b])swap(a,b);
p[a] = b;sz[b] += sz[a];
}
//else cycle.
}
//<<-----Start of Main--------------->>//
void MAIN(){
cin>>n;ll ans = 0;make();set<ll>set1;
for(ll i=1;i<=n;i++)cin>>a[i];
for(ll i=1;i<=n;i++){
merge(a[i],a[n-i+1]);set1.insert(a[i]);
}
// for(ll i=1;i<=n;i++)find(a[i]);
for(ll i=1;i<=n;i++){
if(vis[find(a[i])])continue;
vis[find(a[i])] = 1;ans++;
}
cout<<set1.size()-ans<<endl;
}
int main(){
fastio;randomINIT;
//cin>>t;
while(t--){
MAIN();
}
#ifndef ONLINE_JUDGE
cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
#endif
} | #include<bits/stdc++.h>
using namespace std;
namespace IO
{
const int buffer_size=1e5+5;
char buf[buffer_size],*S,*T;
bool flag_EOF;
inline char read_char()
{
if(S==T)
T=(S=buf)+fread(buf,1,buffer_size,stdin);
return S!=T?*(S++):EOF;
}
inline int read_int()
{
int flag=1;
char c=read_char();
while(c<'0'||c>'9')
{
if(c==EOF)
{
flag_EOF=true;
return 0;
}
flag=(c=='-'?-1:1);
c=read_char();
}
int x=0;
while(c>='0'&&c<='9')
{
x=x*10+(c^48);
c=read_char();
}
return x*flag;
}
inline void read_string(char *s)
{
char x;
do
{
x=read_char();
if(x==EOF)
{
flag_EOF=true;
return;
}
}while(x<'a'||x>'z');
int len=0;
while(x>='a'&&x<='z')
{
s[len++]=x;
x=read_char();
}
s[len]='\0';
}
char fw[buffer_size];
int pw;
inline void flush()
{
fwrite(fw,1,pw,stdout);
pw=0;
}
inline void write_char(char x)
{
if(pw==buffer_size)
flush();
fw[pw++]=x;
}
char st[13];
int top;
inline void write_int(int x)
{
if(!x)
{
write_char('0');
return;
}
if(x<0)
{
write_char('-');
x=-x;
}
while(x)
{
st[++top]=x%10+'0';
x/=10;
}
while(top>0)
write_char(st[top--]);
}
inline void write_string(const char *s)
{
for(int i=0;s[i];++i)
write_char(s[i]);
}
inline void write_double(double x,int cnt_digits,bool mark=true)
{
if(x<0)
{
write_char('-');
x=-x;
}
if(mark)
{
double eps=0.1;
for(int i=1;i<=cnt_digits;++i)
eps*=0.1;
x+=5*eps;
}
write_int(int(x));
write_char('.');
for(int i=1;i<=cnt_digits;++i)
{
x-=int(x);
x*=10;
write_char(int(x)+'0');
}
}
}
const int max_N=49+5;
int X[max_N];
const int prime[15]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};
long long Gcd(long long a,long long b)
{
return b?Gcd(b,a%b):a;
}
int main()
{
int N;
scanf("%d",&N);
for(int i=1;i<=N;++i)
scanf("%d",X+i);
long long ans=7e17;
for(int s=0;s<(1<<15);++s)
{
long long now=1;
for(int i=0;i<15;++i)
now*=((s>>i)&1)?prime[i]:1;
bool flag=true;
for(int i=1;i<=N;++i)
{
if(Gcd(now,X[i])==1)
{
flag=false;
break;
}
}
if(flag)
ans=min(ans,now);
}
printf("%lld\n",ans);
IO::flush();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(v) begin(v),end(v)
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
#define TO_STRING(VariableName) # VariableName
#define debug(x) cerr<<TO_STRING(x)<<" : "<<x<<" "<<endl;
void debugs() { cerr << endl; }
template <class T, class... Args>
void debugs(const T& x, const Args &... args) {
cerr << x << " ";
debugs(args...);
}
template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>& p) {
ost << "{ " << p.first << ", " << p.second << " }";
return ost;
}
template<class T>
ostream& operator<<(ostream& ost, const vector<T>& v) {
ost << "{ ";
for (int i = 0; i < v.size(); i++) {
if (i)ost << ", ";
ost << v[i];
}
ost << " }";
return ost;
}
template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>& v) {
ost << "{ ";
for (auto p : v) {
ost << "{ " << p.first << ", " << p.second << " }";
}
ost << " }";
return ost;
}
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//
int main() {
string s;
cin >> s;
vector<ll> cnt(26);
char p_c = s.back();
cnt[p_c-'a']++;
ll ans = 0;
for (ll i = s.length()-2; i >= 0; i--){
char c = s[i];
cnt[c-'a']++;
if (p_c == c){
ans+=(s.length()-i) - cnt[c-'a'];
rep(j, 26) cnt[j] = 0;
cnt[c-'a'] = s.length()-i;
}
p_c = c;
}
cout << ans << endl;
return 0;
}
| #pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
#define PB push_back
#define fi first
#define se second
#define MP make_pair
const int P = 1000000007;
const int V = 200100;
char s[V];
int a[30];
int main() {
while (~scanf("%s", s)) {
int n = strlen(s);
memset(a, 0, sizeof(a));
int last = -1;
LL ans = 0;
for (int i = n - 1; i >= 0; --i) {
a[s[i] - 'a']++;
if (i != n - 1 && s[i + 1] == s[i]) {
if (last == -1) {
ans += n - i - a[s[i] -'a'];
} else if (s[last] == s[i]) {
ans += last - i - a[s[i] - 'a'];
} else {
ans += n - i - a[s[i] - 'a'];
}
last = i;
for (int j = 0; j < 26; ++j) a[j] = 0;
}
}
printf("%lld\n", ans);
}
return 0;
}
/*
accept
atcoder
anerroroccurred
*/
|
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
void solve()
{
int n; cin >> n;
vector<int> a(n);
for (int i = 0; i < n; ++i) cin >> a[i];
int max_gcd = 1;
int max_count = 0;
for (int gcd = 1000; gcd > 1; --gcd) {
int count = 0;
for (int i = 0; i < n; ++i) {
if (a[i] % gcd == 0) ++count;
}
if (max_count < count) {
max_count = count;
max_gcd = gcd;
}
}
cout << max_gcd << "\n";
}
int main()
{
IOS;
solve();
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
using P=pair<ll, ll>;
int gcd(int a, int b)
{
if (b == 0) return a;
return (gcd(b, a % b));
}
signed main(void)
{
int n;
int ans, out, tmp, g, g_tmp;
cin >> n;
vector<int> a(n);
rep(i, n) cin>>a[i];
sort(a.begin(), a.end());
ans = 0;
out = 1;
for (int i = 0; i < n - 1; i++)
{
tmp = 1;
g = a[i];
for (int j = i + 1; j < n; j++)
{
g_tmp = gcd(g, a[j]);
if (g_tmp == 1)
continue;
g = g_tmp;
tmp++;
}
if (tmp > ans)
{
out = g;
ans = tmp;
}
}
cout << (out == 1 ? a[0] : out )<< endl;
return 0;
}
|
#pragma GCC optimize(2)
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
#include<map>
#include<bitset>
#include<climits>
using namespace std;
//#define int long long
typedef long long ll;
//template<typename T = int>
inline int read(){
int f = 1,r = 0;
char c = getchar();
while(c<'0'||c>'9'){if(c == '-') f = -1; c = getchar();}
while(c>='0'&&c<='9'){ r = (r<<1) + (r<<3) + c - '0';c = getchar();}
return f*r;
}
typedef pair<ll,int> PII;
#define fi first
#define se second
#define mst(a,b) memset(a,b,sizeof(a))
#define For(i,a,b) for(int i = a;i<=b;i++)
#define For_(i,a,b) for(int i = a;i>=b;i--)
#define _for(i,a) for(int i = 0;i<a;i++)
#define All(x) x.begin(),x.end()
const int N = 18 ,M = 4e6,INF = 0x3f3f3f3f;
int n,m,t;
int a[(1<<N)+1],g[N+1][N+1],dp[(1<<N) + 1];
signed main(){
n = read();m = read();
For(i,1,m){
int x = read(),y = read();
g[x][y] = g[y][x] = 1;
}
For(S,0,(1<<n)-1){//枚举全部集合
bool ok = 1;
For(i,1,n){//判断集合是不是一个完全联通图(把集合中的边完全遍历一遍)都有,是就储存
if(!(S & (1<<(i-1)))) continue;
For(j,1,n){
if(i == j) continue;
if(!(S & (1<<(j-1)))) continue;
if(g[i][j] == 0){
ok = 0;
break;
}
}
if(!ok) break;
}
a[S] = ok;
}
mst(dp,0x3f);
dp[0] = 0;
For(S,1,(1<<n)-1){
for(int sub = S;sub;sub =(sub-1)&S){
if(a[sub]) dp[S] = min(dp[S],dp[S ^ sub] + 1);
}
}
cout<<dp[(1<<n)-1]<<"\n";
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using vi = vector <int>;using vl = vector <long long>;
using vs = vector <string>;using vc = vector <char>;
using ll= long long;using vvl = vector<vector<ll> >;
using vvc = vector<vector<char> >;using vd = vector <double>;
using vpl = vector <pair<ll,ll> >;using vb = vector<bool>;
#define rep(i,r) for(ll i=0;i<(r);i++)
#define Rep(i,l,r) for(ll i=(l);i<(r);i++)
#define print(n) cout<<n<<endl
#define vcin(a) rep(i,a.size())cin>>a[i]
#define sortp(d) sort(d.begin(),d.end()) //1234
#define sortm(d) sort(d.rbegin(),d.rend()) //4321
#define all(n) n.begin(),n.end()
//各位の和
int wa(ll x){ll sum = 0;while(x!=0){sum += x% 10;x /= 10;}return sum;}
/*-----------順列生成-----------------
do {
} while (next_permutation(配列変数.begin(), 配列変数.end()));*/
//最大公約数 ユークリッドの互除法
ll gcd(ll a, ll b) {if (b==0) return a;else return gcd(b, a%b);}
//最小公倍数 a*b/gcd
ll lcm(ll a, ll b){return a/gcd(a, b)*b;}
//コンビネーション nCk
ll C(ll n,ll k){ll p=1;rep(i,k)p=p*(n-i)/(i+1);return p;}
//'A'65,'a'97
/*小数点精度指定
cout<<fixed<<setprecision(9)<<;
*/
//priority_queue 優先度付きキュー
ll modpow(ll a,ll n,ll mod) {ll res=1;while(n>0)
{if(n&1)res=res*a%mod;a=a*a%mod;n >>= 1;}return res;}
ll modinv(ll a,ll mod){return modpow(a, mod - 2, mod);}
ll p=0,q=0,r=0;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
#define inf 1000000000000 //10^12:∞
#define mod 1000000007 //10^9+7:合同式の法
const long double pi = acos(-1);
int main()
{
ll n,m;cin>>n>>m;
print((modpow(10,n,m*m)/m)%m);
} |
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;
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; }
map<ll,ll> prime_factor(ll n){
map<ll,ll> res;
for(ll i = 2; i * i <= n; i++) {
while(n % i == 0){
res[i]++;
n /= i;
}
}
if (n != 1){
res[n] = 1;
}
return res;
}
int main(){
int n;cin>>n;
ll x = 1;
map<ll,ll> ans;
for(ll i = 2; i <= n; i++) {
map<ll,ll> tmp = prime_factor(i);
for(auto e:tmp) {
if(ans[e.fs] < e.sc){
ans[e.fs] = e.sc;
}
}
}
for(auto e:ans) {
for(int i = 0; i < e.sc; i++) {
x *= e.fs;
}
}
for(int i = 2; i <= n; i++) {
if((x + 1) % i == 1){
continue;
}
else{
cout << "no" << endl;
}
}
cout << x + 1 << endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vl;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;
const int mod = 1e9+7;
const int N = 1e5+2;
#pragma region Debugger
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
#pragma endregion Debugger
//My tools
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i,s,e) for(int i=s;i<e;i++)
#define repe(i,s,e) for(int i=s;i<=e;i++)
#define all(v) (v).begin(),(v).end()
main(){
int n;ll x;
cin>>n>>x;
rep(i,0,n){
ll a;
cin>>a;
if(a!=x) cout<<" "<<a;
}
} |
//Iamskk//
#include <iostream>
#include <iosfwd>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <cassert>
#include <cctype>
#include <climits>
#include <vector>
#include <bitset>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <deque>
#include <string>
#include <list>
#include <iterator>
#include <sstream>
#include <complex>
#include <fstream>
#include <functional>
#include <numeric>
#include <utility>
#include <algorithm>
#include <assert.h>
#include <unordered_map>
using namespace std;
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
#define endl '\n'
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define ai(arr,n) for(int i=0;i<n;i++)cin>>arr[i];
#define ao(arr) for(auto asdfasdfasdf:arr) cout<<asdfasdfasdf<<" ";
#define mi(arr,m,n) for(int i=0;i<m;i++){ for(int j=0;j<n;j++) cin>>arr[i][j];}
#define mo(arr,m,n) for(int i=0;i<m;i++){ for(int j=0;j<n;j++) cout<<arr[i][j]<<" "; cout<<endl;}
#define countsetbits(x) __builtin_popcount(x)
#define ll long long
#define debug cout<<"I AM EXECUTING"<<endl
#define testcases int asdf; cin>>asdf; while(asdf--)
#define vi vector<int>
#define vll vector<long long int>
#define vppo(prs) for(auto x:prs){cout<<x.first<<" "<<x.second<<endl;}
#define For(__,hajmola,adfdf) for(int __ = hajmola; __<adfdf;__++)
#define formax 1e18
#define formin -1e18
string sconvert(ll int n)
{
stringstream ss;
ss<<n;
string str = ss.str();
return str;
}
bool sortbysec(const pair<int,int> &a,
const pair<int,int> &b)
{
return (a.second > b.second);
}
template<typename T>
void imax(T &x,T y){
x = max(x,y);
}
template<typename T>
void imin(T &x,T y){
x = min(x,y);
}
void single()
{
int n;
cin>>n;
int m;
cin>>m;
vector<string> mat(n+1);
for(int i=0;i<n;i++){
cin>>mat[i];
}
int finalanswer=0;
For(i,0,n-1){
For(j,0,m-1){
int count=0;
if(mat[i+1][j+1]==mat[i][j]){
count++;
}
if(mat[i+1][j]==mat[i][j]){
count++;
}
if(mat[i][j+1]==mat[i][j]){
count++;
}
if(count==0 or count==2){
finalanswer++;
}
}
}
cout<<finalanswer<<endl;
return;
}
void multiple()
{
testcases
{
single();
}
}
int main()
{
IOS;
// freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
single();
}
| #include <bits/stdc++.h>
#define rep(i, l, r) for (int i = (l); i < (r); i++)
#define max(p, q) ((p) > (q) ? (p) : (q))
#define min(p, q) ((p) < (q) ? (p) : (q))
#define INF ((1LL << 62) - (1LL << 31))
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(void)
{
std::cin.tie(0);
std::ios::sync_with_stdio(false);
int vx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int vy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
int h, w;
cin >> h >> w;
char s[h][w];
pair<int, int> a;
rep(i, 0, h)
{
rep(j, 0, w)
{
char tmp;
cin >> tmp;
if (tmp == '#' || tmp == '.')
{
s[i][j] = tmp;
}
}
}
ll ans=0;
rep(i,0,h){
rep(j,0,w){
ll tmp=0;
if(s[i][j]=='#')tmp++;
if(s[i][j+1]=='#')tmp++;
if(s[i+1][j]=='#')tmp++;
if(s[i+1][j+1]=='#')tmp++;
if(tmp%2==1){
ans++;
}
}
}
cout << ans << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N,M,P;
cin >> N >> M;
P=N+M;
vector<int> A(P);
for (int i=0;i<P;i++) {
cin >> A.at(i);
}
sort(A.begin(),A.end());
for (int i=0;i<P;i++) {
if (i==0) {
int a,b;
a=A.at(0);
b=A.at(1);
if (a!=b) {
cout << A.at(0) << " ";
}
}
else if ((i>0)&&(i<P-1)) {
int a,b,c;
a=A.at(i-1);
b=A.at(i);
c=A.at(i+1);
if ((a!=b)&&(b!=c)) {
cout << A.at(i) << " ";
}
}
else if (i==P-1) {
int b,c;
b=A.at(P-2);
c=A.at(P-1);
if (b!=c) {
cout << A.at(P-1) << " ";
}
}
}
} | ///********************** Bismillahir Rahmanir Rahim *****************///
#include<bits/stdc++.h>
using namespace std;
///*********************** Template Start Here ***********************///
///************************ C o n t a i n e r ************************///
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<int>::iterator vit;
typedef set<int> si;
typedef set<string> ss;
typedef set<int>::iterator sit;
typedef map<int, int> mii;
typedef map<string, int> msi;
typedef map<int, string> mis;
typedef map<string, string> mss;
typedef pair<ll, ll> pll;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef double dl;
///**************************** M a r c o ****************************///
#define f first
#define s second
#define endl '\n'
#define sp <<" "<<
#define pb push_back
#define MP make_pair
#define MOD 1000000007
#define sqr(a) ((a) * (a))
#define sz(x) (int)x.size()
#define mid(l,r) ((l+r)/2)
#define fora(a) for(auto u:a)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mem(a,b) memset(a, b, sizeof(a))
#define test int tc; cin>>tc; while(tc--)
#define forn(i,n) for(auto i=0; i<n; i++)
#define rforn(i,n) for(auto i=n-1; i>=0; i--)
#define abid() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fori(a,b,c) {for(a = c.begin(); a!=b; a++) cout<< *a<< " "; cout<<endl;}
int main()
{
abid();
int n,m;
cin>>n>>m;
vi v(n),v1(m),ans(n+m);
forn(i,n) cin>>v[i];
forn(i,m) cin>>v1[i];
vit st,it;
it = set_symmetric_difference(all(v), all(v1), ans.begin());
fori(st,it,ans);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long double ld;
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define ROF(i, a, b) for(int i = a; i >= b; i--)
#define ms memset
#define pb push_back
#define F first
#define S second
ll MOD = 1000000007;
ll power(ll base, ll n){
if (n == 0) return 1;
if (n == 1) return base;
ll halfn = power(base, n/2);
if (n % 2 == 0) return (halfn * halfn) % MOD;
return (((halfn * halfn) % MOD) * base) % MOD;
}
ll inverse(ll n){
return power(n, MOD-2);
}
ll add(ll a, ll b){
return (a+b) % MOD;
}
ll mul(ll a, ll b){
return (a*b) % MOD;
}
ll gcd(ll a, ll b){
if (a == 0) return b;
if (a == 1) return 1;
return gcd(b % a, a);
}
int main(){
ios::sync_with_stdio(false);
int n; cin >> n;
string s; cin >> s;
vi a(n+1); FOR(i, 0, n+1) cin >> a[i];
int mini = abs(a[1] - a[0]);
FOR(i, 1, n+1){
mini = min(mini, abs(a[i]-a[i-1]));
}
cout << mini << '\n';
FOR(i, 0, mini){
FOR(j, 0, n+1){
if (a[j] % mini > i) cout << a[j]/mini + 1 << " ";
else cout << a[j]/mini << " ";
}
cout << '\n';
}
return 0;
}
| // #pragma GCC optimize("Ofast,unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,mmx,avx,avx2")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
//All indexing is 0-based
template<class key, class cmp = std::less<key>>
using oset = tree<key, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
//methods: find_by_order(k); & order_of_key(k);
//To make it an ordered_multiset, use pairs of (value, time_of_insertion)
//to distinguish values which are similar
template<class key, class value, class cmp = std::less<key>>
using omap = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long
#define ull unsigned long long
#define lld long double
#define w(x) ll x;cin>>x;while(x--)
#define all(x) x.begin(), x.end()
#define iceil(n, x) (((n) + (x) - 1) / (x))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) __detail::__lcm(a,b)
#define goog(tno) cout << "Case #" << tno <<": "
#define PRESS_F_TO_PAY_RESPECT ios_base::sync_with_stdio(false), cin.tie(nullptr)
void __print(int x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define bug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define bug(x...)
#endif
ll dx[]= {-1,-1,-1,0,0,1,1,1};
ll dy[]= {-1,0,1,-1,1,-1,0,1};
const lld pi=3.1415926535897932384626433832795;
const ll INF=1e18;
const ll mod=1000000007;
const ll maxn=1e5+5;
template<typename T>
void printv(const vector<T>& v) { for(auto i:v) cout<<i<<' '; cout<<'\n'; }
template<typename T>
void printv(const vector<pair<T, T>>& v) { for(auto p:v) cout<<"("<<p.first<<","<<p.second<<"),"; cout<<'\n'; }
int main(){
PRESS_F_TO_PAY_RESPECT;
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
ll pos,neg; cin>>pos>>neg;
vector<ll> p,n;
for(ll i=0;i<neg;i++){
// cout<<-1*pos<<" ";
n.push_back(-1*pos);
}
for(ll i=0;i<pos;i++){
// cout<<neg<<" ";
p.push_back(neg);
}
vector<ll> v;
ll cnt=0;
for(ll i=0;i<p.size();i++){
v.push_back(p[i]+cnt);
cnt++;
}
cnt=0;
for(ll i=0;i<n.size();i++){
v.push_back(n[i]-cnt);
cnt++;
}
bug(v);
ll s=accumulate(all(v),0LL);
bug(s);
if(s>0) v.back()-=s;
else v.front()-=s;
bug(v);
s=accumulate(all(v),0LL);
bug(s);
printv(v);
return 0;
} |
/* بِسْمِ اللَّـهِ الرَّحْمَـٰنِ الرَّحِيمِ
( إِنِ الْحُكْمُ إِلَّا لِلَّهِ )
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const long double pi=acos(-1);
#define x first
#define y second
#define read(n,a) for(int i=0;i<n;i++)cin>>a[i];
#define rep(i,z,n)for(ll i=z;i<n;i++)
#define all(v) v.begin(),v.end()
pair<int,int> a[200002]={};
ll b[200002]={};
string s="",ss="";
ll n,m,k,w;
ll ans ;
ll mod = 1e9 +7;
int main()
{
cin.tie(0);
cin.sync_with_stdio(0);
//freopen("rect.in","r",stdin);
//freopen("output.txt","w",stdout);
int t=1;
//cin>>t;
while(t--)
{
cin>>n;
rep(i,0,1ll<<n)cin>>a[i].x,a[i].y=i;
n=(1ll<<n);
n/=2;
sort(a,a+n);
sort(a+n,a+n+n);
if(a[n-1].x<a[n+n-1].x)cout<<a[n-1].y+1;
else cout<<a[n+n-1].y+1;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define MOD 1000000007
int main() {
int n, x;
cin >> n >> x;
// vector<int> v(n), p(n);
int sum = 0;
rep(i, n) {
int v, p;
cin >> v >> p;
sum += v * p;
if (x * 100 < sum) {
cout << i + 1 << endl;
return 0;
}
}
cout << -1 << endl;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
typedef long long ll;
const int maxn=2e5+5;
struct node{
int l,r,x;
}p[maxn];
ll a[maxn*2];
int b[maxn*2];
map<int,int>pos;
int main(){
int n,c;
scanf("%d%d",&n,&c);
int cnt=0;
for(int i=1;i<=n;i++){
int l,r,x;
scanf("%d%d%d",&p[i].l,&p[i].r,&p[i].x);
b[++cnt]=p[i].l;
b[++cnt]=p[i].r+1;
}
sort(b+1,b+1+cnt);
cnt= unique(b+1,b+1+cnt)-b-1;
for(int i=1;i<=cnt;i++){
pos[b[i]]=i;
}
for(int i=1;i<=n;i++){
a[pos[p[i].l]]+=p[i].x;
a[pos[p[i].r+1]]-=p[i].x;
}
b[cnt+1]=b[cnt]+1;
ll ans=0;
for(int i=1;i<=cnt;i++){
a[i]+=a[i-1];
ans+=(b[i+1]-b[i])*min(a[i],1ll*c);
}
printf("%lld\n",ans);
return 0;
}
| #include <iostream>
#include <vector>
#include <algorithm>
template<class Tp>
void chmax (Tp &a, const Tp &b) {
if (a < b) a = b;
}
int main() {
int n;
long long t;
std::cin >> n >> t;
std::vector<long long> a(n);
for (auto &e : a) std::cin >> e;
int n1 = (n >> 1), n2 = n - n1;
long long time = 0;
std::vector<long long> times(1 << n1, 0);
for (int s = 1; s < (1 << n1); s++) {
const int tmp = (s ^ (s >> 1));
const int i = __builtin_ctz(s);
if (tmp >> i & 1) time += a[i];
else time -= a[i];
times[s] = time;
}
time = 0;
std::sort(times.begin(), times.end());
times.erase(std::unique(times.begin(), times.end()), times.end());
long long ans = *std::prev(std::upper_bound(times.begin(), times.end(), t));
for (int s = 1; s < (1 << n2); s++) {
const int tmp = (s ^ (s >> 1));
const int i = __builtin_ctz(s);
if (tmp >> i & 1) time += a[n1 + i];
else time -= a[n1 + i];
if (time <= t) {
chmax(ans, time + *std::prev(std::upper_bound(times.begin(), times.end(), t - time)));
}
}
std::cout << ans << '\n';
return 0;
} |
#include <iostream>
#include <vector>
#include <array>
#include <cmath>
#include <string>
#include <algorithm>
#include <functional>
#include <map>
#include <tuple>
#include <queue>
#include <bitset>
#define rep(i,n) for(int i = 0;i < (n);i++)
using namespace std;
using ll = long long int;
int cnt = 0;
using Graph = vector<vector<int>>;
vector<bool> seen; // 探索したか記録
void dfs(const Graph &G, int v) {
seen[v] = true;
for (auto e : G[v]) {
if (seen[e]) continue; // 訪問済みでなければ探索
dfs(G, e);
}
cnt++;
}
int main(){
int n,m;cin>>n>>m;
Graph G(n);
rep(i,m){
int a,b;cin>>a>>b;
a--;b--;
G[a].push_back(b);
}
// 初期化
rep(i,n) {
seen.assign(n, false);
if (!seen[i]) {
dfs(G, i);
}
}
cout << cnt << endl;
return 0;
} | //#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 bit(n) (1LL<<(n))
#define FIX(d) fixed << setprecision(d)
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
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 = 1e9;
const ll LINF = (1LL<<60);
struct edge
{
int to;
int cost;
edge(int a, int b){
to = a;
cost = b;
}
};
using Graph = vector<vector<edge>>;
vector<ll> dijkstra(int s, const Graph &G)
{
int n = G.size();
priority_queue<P, vector<P>, greater<P>> que;
vector<ll> d(n, INF);
d[s] = 0;
que.emplace(0, s);
while (!que.empty()){
P p = que.top();
que.pop();
int v = p.second;
if (d[v] < p.first) continue;
for(auto nv: G[v]){
if (d[nv.to] > d[v] + nv.cost){
d[nv.to] = d[v] + nv.cost;
que.emplace(d[nv.to], nv.to);
}
}
}
return d;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int r,c; cin >> r >> c;
vvi a(r, vector<int>(c-1)), b(r-1, vector<int>(c));
REP(i,r) REP(j,c-1) cin >> a[i][j];
REP(i,r-1) REP(j,c) cin >> b[i][j];
Graph G(r*c);
REP(i,r) REP(j,c){
// r,c -> r,c+1
if(j<c-1) G[i*c+j].push_back(edge(i*c+(j+1), a[i][j]));
// r,c -> r,c-1
if(j>0) G[i*c+j].push_back(edge(i*c+(j-1), a[i][j-1]));
// r,c -> r+1,c
if(i<r-1) G[i*c+j].push_back(edge((i+1)*c+j, b[i][j]));
// r,c -> r-k,c
REP(k,i) G[i*c+j].push_back(edge((i-k-1)*c+j, k+2));
}
auto dist = dijkstra(0, G);
cout << dist[r*c-1] << endl;
return 0;
}
|
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define ll long long
#define sz(s) (int)s.size()
#define vi vector<int>
#define ii pair<int,int>
#define vii vector<ii>
const int MOD = 1e9 + 7;
const double pi = acos(-1);
const double EPS = 1e-9;
ll binpowmod(ll a, ll b)
{
a %= MOD;
ll ret = 1;
while (b)
{
if (b & 1)
ret = ret * a % MOD;
a = a * a % MOD;
b >>= 1;
}
return ret % MOD;
}
int gcd(int a, int b)
{
if (!b)
return a;
return gcd(b, a % b);
}
const int N = 1 << 18;
const int E = N * 2;
#define neigh(u,v,e) for (int e = head[u], v; ~e && ((v = to[e]), 1); e = nxt[e])
#define foreach(it, x) for(auto it = x.begin(); it != x.end(); ++it)
vector <set<pair<int,ll>>> adj;
vector<int> subtreeSz;
vector<ll> OurAns,OurAns2;
vector<int> parent;
void calcSz(int u = 0, int p = -1)
{
subtreeSz[u] = 1;
for (auto i = adj[u].begin(); i != adj[u].end(); ++i)
{
int v = i->first;
if (v != p)
{
calcSz(v, u);
subtreeSz[u] += subtreeSz[v];
parent[v] = u;
}
}
}
void calcAns(int u = 0)
{
for (auto i = adj[u].begin(); i != adj[u].end(); ++i)
{
int v = i->first;
ll w = i->second;
if (v != parent[u])
{
calcAns(v);
OurAns[u] += subtreeSz[v] * w + OurAns[v];
}
}
}
void calcAns2(int u = 0, int cnt = 0, ll weight = 0)
{
OurAns2[u] = (parent[u] != -1 ? OurAns2[parent[u]] : 0) + cnt * weight;
for (auto i = adj[u].begin(); i != adj[u].end(); ++i)
{
int v = i->first;
ll w = i->second;
if (v != parent[u])
{
calcAns2(v, cnt + 1, w);
}
}
}
void solve()
{
int n, m, x, y;
cin >> n >> m >> x >> y;
vector<string> v(n);
for (int i = 0; i < n; ++i)
cin >> v[i];
x--; y--;
int ans = 1;
for (int i = x + 1; i < n; ++i)
{
if (v[i][y] == '#')
break;
ans++;
}
for (int i = x - 1; i >= 0; --i)
{
if (v[i][y] == '#')
break;
ans++;
}
for (int i = y + 1; i < m; ++i)
{
if (v[x][i] == '#')
break;
ans++;
}
for (int i = y - 1; i >= 0; --i)
{
if (v[x][i] == '#')
break;
ans++;
}
cout << ans << '\n';
}
int main(void)
{
#ifdef ONLINE_JUDGE
//freopen("hamming.in", "r", stdin);
#endif
//freopen("output.txt", "w", stdout);
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int tc = 1;
//cin >> tc;
while (tc--)
{
solve();
}
} |
/*/ Author : Abhishek Chauhan /*/
#include<bits/stdc++.h>
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
using namespace std::chrono;
using namespace __gnu_pbds;
using namespace std;
// a+b = a^b + 2*(a&b)
// whenever using a comparator return true only if a<b
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define mod 1000000007
#define umap unordered_map
#define trailzero(x) __builtin_ctz(x)
#define bpop(x) __builtin_popcountll((x))
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define endl '\n'
template<class T>
using ordered_set = tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update> ;
// find_by_order(k) returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
template<class T>
T power(T x, T y){T res = 1;while (y > 0){ if (y & 1){res = res*x;} y = y>>1;x = x*x;}return res;}
template<class T>
T powermod(T x, T y, T p){T res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1; x = (x*x) % p;}return res;}
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int64_t random_long(long long l,long long r){
uniform_int_distribution<int64_t> generator(l,r);
return generator(rng);
}
inline int64_t random_long(){
uniform_int_distribution<int64_t> generator(LLONG_MIN,LLONG_MAX);
return generator(rng);
}
const int mxn = 5e5+10;
int st[8*mxn];
int lazy[8*mxn];
int arr[mxn];
int merge(int a,int b){
return min(a,b);
}
int query( int ss, int se, int qs, int qe, int si)
{
if (qs <= ss && qe >= se)
return st[si];
if (se < qs || ss > qe)
return 1e18;
int mid = ss+(se-ss)/2;
return merge(query( ss, mid, qs, qe, 2*si+1),query( mid+1, se, qs, qe, 2*si+2));
}
void build(int ss, int se,int si)
{
if (ss == se){
st[si] = arr[ss];
return;
}
int mid = ss+(se-ss)/2;
build(ss , mid, 2*si +1);
build(mid+1, se,2*si +2);
st[si] = merge(st[2*si+1],st[2*si+2]);
}
void snow(){
int n;
cin>>n;
rep(i,n){
cin>>arr[i];
}
build(0,n-1,0);
int ans = 0;
for(int i=0;i<n;i++){
int l = 0;
int r = i-1;
int left = i;
while(l<=r){
int mid = (l+r)/2;
int f = query(0,n-1,mid,i-1,0);
if(f<arr[i]){
l = mid+1;
}
else{
left = mid;
r = mid-1;
}
}
l = i+1;
r = n-1;
int right = i;
while(l<=r){
int mid = (l+r)/2;
int f = query(0,n-1,i+1,mid,0);
if(f<arr[i]){
r = mid-1;
}
else{
l = mid+1;
right = mid;
}
}
ans = max(ans,(right-left+1)*arr[i]);
}
cout<<ans<<endl;
}
int32_t main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
auto start = high_resolution_clock::now();
fastio;
int _;
_=1;
// cin>>_;
for(int i=1;i<=_;i++){
// cout<<"Case #"<<i<<": ";
snow();
}
auto stop = high_resolution_clock::now();
auto duration = duration_cast<microseconds>(stop - start);
#ifndef ONLINE_JUDGE
cerr << "Time: " << duration.count()/1000.0 << endl;
#endif
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MX = 2000005;
vector<vector<int>> g(MX);
vector<int> a;
int ans = 0;
vector<bool> used(MX , false);
void dfs(int v , int &depth) {
if (used[v]) {
return;
}
used[v] = true;
for (int v2 : g[v]) {
if (!used[v2]) {
depth++;
dfs(v2 , depth);
}
}
return;
}
int main() {
int n;
cin >> n;
a = vector<int>(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n / 2; i++) {
g[a[i]].push_back(a[n - 1 - i]);
g[a[n - 1 - i]].push_back(a[i]);
}
for (int i = 0; i < n / 2; i++) {
int depth = 0;
dfs(a[i] , depth);
ans += depth;
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define put(i) cout << i << endl
#define rep(i, s, n) for (long long i = s; i < (long long)(n); i++)
using namespace std;
using ll = long long;
ll n;
vector<ll> a;
struct UnionFind {
vector<int> r;
UnionFind(int N) { r = vector<int>(N + 1, -1); }
int root(int x) {
if (r[x] < 0) return x;
return r[x] = root(r[x]);
}
bool unite(int x, int y) {
x = root(x);
y = root(y);
if (x == y) return false;
if (r[x] > r[y]) swap(x, y);
r[x] += r[y];
r[y] = x;
return true;
}
int size(int x) { return -r[root(x)]; }
};
int main() {
cin >> n;
a = vector<ll>(n);
rep(i, 0, n) cin >> a[i];
UnionFind UF(*max_element(all(a)));
ll ans = 0;
rep(i, 0, n / 2) { UF.unite(a[i], a[n - 1 - i]); }
set<ll> st, st2;
for (auto x : a) st.insert(x);
rep(i, 0, n) { st2.insert(UF.root(a[i])); }
put(st.size() - st2.size());
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
ll N, X;
cin >> N >> X;
vector<int> V(N);
vector<int> P(N);
int flag = 0;
ll now = 0;
ll total = 0;
for(ll i = 0; i < N; i++){
cin >> V.at(i) >> P.at(i);
}
for(ll i = 0; i < N; i++){
total += V.at(i) * P.at(i);
if(total > X*100){
flag = 1;
now = i+1;
break;
}
}
if(flag == 1){
cout << now << endl;
}else{
cout << "-1" << endl;
}
} | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//turn on extra precision
//#pragma GCC target("fpmath=387")
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef string str;
typedef pair <int,int> pii;
typedef pair <ll,ll> pll;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_multiset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'
#define fbo find_by_order
#define ook order_of_key
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(),x.rend()
#define watch(x) cout << (#x) << " is : " << (x) << newl
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
vi dirx = {0,0,1,-1};
vi diry = {1,-1,0,0};
char to_upper (char x){
if( 97 <= int(x) && int(x) <= 122) return char(x-32);
if( 65 <= int(x) && int(x) <= 90) return x;
return -1;
}
char to_lower (char x){
if( 97 <= int(x) && int(x) <= 122) return x;
if( 65 <= int(x) && int(x) <= 90) return char(x+32);
return -1;
}
int numerize (char x){
if(48 <= int(x) && int(x) <= 57) return int(x-'0');
if(97 <= int(x) && int(x) <= 122) return int(x-96);
if(65 <= int(x) && int(x) <= 90) return int(x-64);
return -1;
}
bool isect (int l1, int r1, int l2, int r2){ return max(l1,l2) <= min(r1,r2); }
ll quickpow (ll num1, ll num2, ll MOD){
if(num2==0)return 1%MOD;
else if(num2==1)return num1%MOD;
else{
ll temp = quickpow (num1,num2>>1LL,MOD); ll res = ((temp%MOD) * (temp%MOD))%MOD;
if(num2&1) res = ((res%MOD)*(num1%MOD))%MOD; return res;
}
}
ll invmod (ll num, ll MOD){return quickpow (num,MOD-2,MOD);}
ll gcd (ll num1, ll num2){
if(num1 < num2) swap(num1,num2); ll num3 = num1 % num2 ;
while(num3 > 0){ num1 = num2; num2 = num3; num3 = num1 % num2;}
return num2;
}
ll lcm (ll num1 , ll num2){return (ll) (num1/__gcd(num1,num2))*num2;}
// end of Template
ll n,x,p[3000];
int main(){
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> x; x *= 100;
for(int i = 1; i <= n; ++i){
int a,b; cin >> a >> b;
p[i] = a * b;
}
int res = 0;
int ans = INT_MAX;
for(int i = 1; i <= n; ++i){
res += p[i];
if(res > x) ans = min(ans,i);
}
if(ans == INT_MAX) ans = -1;
cout << ans << newl;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
int n,a[1001],t[1001];
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
t[a[i]]++;
}
for(int i=1;i<=n;i++){
if(t[i]!=1){
puts("No");
return 0;
}
}
puts("Yes");
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;
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 t;cin>>t;
for(int i = 0; i < t; i++) {
int n;cin>>n;
map<ll,ll> dict;
for(int i = 0; i < n; i++) {
ll tmp;cin>>tmp;
dict[tmp]++;
}
if(n % 2 == 1){
cout << "Second" << endl;
continue;
}
else{
bool flag = true;
for(auto e:dict) {
if(e.sc % 2 == 1){
cout << "First" << endl;
flag = false;
break;
}
}
if(flag)cout << "Second" << endl;
}
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
if ( N%2 == 1 ) {
cout << "Black" << endl;
}
else {
cout << "White" << endl;
}
} | #include <bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define vl vector<long long>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_lr(i, f, n) for (int i = f; i < (int)(n); i++)
#define sum(v) accumulate(arr.begin(),arr.end(),0)
#define sumll(v) accumulate(arr.begin(),arr.end(),0LL)
#define maxe(v) *max_element(v.begin(),v.end())
#define mine(v) *min_element(v.begin(),v.end())
#define sorts(v) sort(v.begin(),v.end())
#define sortg(v) sort(v.begin(),v.end(),greater<int>)
using namespace std;
string replace_all(string &s, string from, string to) {
ll pos = s.find(from);
while(true){
pos = s.find(from, pos);
if(pos==-1) break;
s.replace(pos, from.length(), to);
pos += to.length();
}
return s;
}
int combination(int n, int r) {
if(r < n) return 0;
if(r*2 > n) r = n-r;
int nume = 1;
int deno = 1;
rep_lr(i, 1, r+1) {
nume *= (n-i+1);
deno *= i;
}
return nume / deno;
}
int ceil(int nume, int deno){
return (nume+deno-1)/deno;
}
template<typename T>
void vinp(int n, T v){
rep(i,n){
cin >> v.at(i);
}
}
void solve(){
int N;
cin >> N;
cout << (N%2==0?"White":"Black") << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
solve();
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#define int long long //delete if causing problems
#define F first
#define dbg(x) cout<<#x<<" "<<x<<endl;
#define S second
#define setbit(n) __builtin_popcount(n)
#define all(x) x.begin() , x.end()
#define clr(x) memset(x,0,sizeof(x))
#define fast ios_base::sync_with_stdio(0); cin.tie(0);
#define endl "\n" //delete if interactive
#define MOD 1000000007
const int inf = 1e18;
int power(int a, int b);
signed main()
{
fast
int tt = 1;
//cin >> tt;
while (tt--)
{
int n;
cin >> n;
int l = -inf, r = inf, add = 0;
for (int i = 1; i <= n; i++) {
int ele, type;
cin >> ele >> type;
if (type == 1) {
add += ele;
l += ele;
r += ele;
}
else if (type == 2) { //max
l = max(l, ele);
r = max(r, ele);
}
else {
l = min(l, ele);
r = min(r, ele);
}
}
int q;
cin >> q;
while (q--) {
int x;
cin >> x;
int ans = x;
ans += add;
if (ans > r) ans = r;
if (ans < l) ans = l;
cout << ans << endl;
}
}
return 0;
}
int power(int a, int b)
{
int res = 1;
while (b)
{
if (b % 2) b-- , res = res * a;
else b = b / 2 , a *= a;
}
return res;
}
/*
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
*/
| #include <bits/stdc++.h>
#define rep3(i, s, n, a) for (long long i = (s); i < (long long)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
int main() {
ll n;
cin >> n;
// vector<ll> x, t;
vector<ll> boarder(2), b(2);
boarder[0] = INT64_MIN;
boarder[1] = INT64_MAX;
// rep(i, 2){
// b[i] = boarder[i];
// }
boarder[0] += (ll)(3*100000)*(ll)INT32_MAX;
boarder[1] -= (ll)(3*100000)*(ll)INT32_MAX;
ll num = 0;
rep(i, n){
ll a, t;
cin >> a >> t;
if(t==1){
num += a;
}
if(t==2){
if(boarder[0]+num<a){
boarder[0] = a-num;
// b[0] = boarder[0] + num;
}
if(boarder[1]+num<a){
boarder[1] = a-num;
// boarder[1] = INT64_MAX - (ll)(3*100000)*(ll)INT32_MAX;
// boarder[0] = boarder[1];
// b[1] = INT64_MAX - (ll)(2*10000)*(ll)INT32_MAX;
}
}
if(t==3){
if(a<boarder[0]+num){
boarder[0] = a-num;
// boarder[0] = INT64_MIN + (ll)(3*100000)*(ll)INT32_MAX;
// boarder[1] = boarder[0];
// b[0] = INT64_MIN + (ll)(2*10000)*(ll)INT32_MAX;
}
if(a<boarder[1]+num){
boarder[1] = a-num;
// b[1] = INT64_MAX - (ll)(2*10000)*(ll)INT32_MAX;
}
}
}
int q;
cin >> q;
rep(i, q){
ll x;
cin >> x;
if(x<boarder[0]){
cout << boarder[0] + num << endl;
}else{
if(x<boarder[1]){
cout << x + num << endl;
}else{
cout << boarder[1] + num << endl;
}
}
}
return 0;
} |
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include <algorithm>
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define PI acos(-1.0)
#define No cout<<"No\n"
#define Yes cout<<"Yes\n"
#define no cout<<"no\n"
#define yes cout<<"yes\n"
#define NO cout<<"NO\n"
#define YES cout<<"YES\n"
// #define MOD (int)1000000007
#define int long long
#define ll long long
#define pii pair<int, int>
#define fi first
#define se second
#define sf(a) scanf("%lld", &a)
#define pf(a) printf("%lld ", a)
#define pfn(a) printf("%lld\n", a)
#define case(a) cout<<"Case "<<a<<": ";
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define pb push_back
#define mem(arr) memset(arr, 0, sizeof(arr))
#define mem1(arr) memset(arr, -1, sizeof(arr))
#define all(a) a.begin(),a.end()
#define f(i,a,b) for (int i = a; i<=b; i++)
#define fr(i,a,b) for (int i = a; i>=b; i--)
#define rr return 0
#define prec(n) fixed<<setprecision(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define inf (int)(1e18)
#define vi vector<int>
#define vii vector<pii>
#define sz(s) s.size()
#define lcm(a,b) (a*(b/gcd(a,b)))
int gcd(int a, int b) {return __gcd(a,b);}
int MOD;
inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p & 1LL) r = modMul(r, b); b = modMul(b, b); p >>= 1LL; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }
inline bool checkBit(ll n, int i) { return n&(1LL<<i); }
inline ll setBit(ll n, int i) { return n or (1LL<<i);; }
inline ll resetBit(ll n, int i) { return n&(~(1LL<<i)); }
const double eps = 1e-9;
int dx[5] = {+1, +0, -1, -0};
int dy[5] = {+0, +1, -0, -1};
int XX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int YY[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
inline bool Equal(double x, double y) { return fabs(x-y)<eps; }
inline bool Greater(double x, double y){ return x-eps>y; }
inline bool Lesser(double x, double y){ return x+eps<y; }
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); cerr << '\n'; }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << " "; err(++it, args...); }
///Write what you need -->
/// nt, ft, kmp, tri, sufarr, ub_lb, lis
/// dsu, combi
///Template Ends Here////////////////////////////
signed main()
{
// root = new trinode();
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
FASTIO
// int n;
// cin>>n;
//
// int a[n+1];
// f(i, 1, n){
// cin>>a[i];
// }
int n, m;
cin>>n>>m;
MOD = m*m;
int r = modPow(10, n);
MOD = m;
int r1 = modPow(10, n);
cout<<(r-r1)/m;
// tridel(root);
}
| #include <bits/stdc++.h>
//#include <atcoder/modint.hpp>
using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
const int mod2=998244353;
using P = pair<int,int>;
using Pl= pair<ll,ll>;
using ld=long double;
using V=vector<int>;
using Vl=vector<ll>;
using Vd=vector<ld>;
using VV=vector<vector<int>>;
using VVl=vector<vector<ll>>;
using VVd=vector<vector<ld>>;
//using mint=atcoder::modint1000000007;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;cin >>n;
string t;cin >>t;
ll k=1e10;
ll ans=0;
for (int i = 0; i < 3; ++i) {
bool flg=true;
for (int j = 0; j < n; ++j) {
char s=(i+j)%3==2?'0':'1';
if(s!=t[j])flg=false;
}
if(flg){
ll pl=k-((n+i-1)/3+1);
ans+=(pl+1);
}
}
cout <<ans<<"\n";
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,a[200005],c[200005],c2[200005],d[200005];
vector<int> g[200005];
void U(int x,int k){
if(!x)return ;
while(x<=n)c[x]+=k,x+=x&-x;
}
int Q(int x){
int r=0;
while(x)r+=c[x],x-=x&-x;
return r;
}
void U2(int x,int k){
if(!x)return ;
while(x<=n)c2[x]+=k,x+=x&-x;
}
int Q2(int x){
int r=0;
while(x)r+=c2[x],x-=x&-x;
return r;
}
int main(){
cin>>n;
ll sum=0;
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<=n;i++){
if(i==a[i])return puts("-1"),0;
if(i>a[i]){
if(a[i]>1){
U(a[i]-1,1);
U(a[i],-1);
}
//A(a[i],a[i]-1);
//for(int j=a[i];j<i-1;j++)A(j,j+1);
//A(i,i-1);
if(i<a[i]-1)U2(i,1),U2(a[i]-1,-1);
if(i>1){
U(i-1,1);
U(i,-1);
}
}
else {
if(a[i]>1){
U2(a[i]-1,1);
U2(a[i],-1);
}
//A(a[i]-1,a[i]);a[i]-1在a[i]之后
if(i<a[i]-1)U(i,1),U(a[i]-1,-1);
//for(int j=a[i]-1;j>i;j--)A(j,j-1);
//A(i-1,i);i-1在i之后
if(i>1){
U2(i-1,1);
U2(i,-1);
}
}
//for(int i=1;i<=n;i++)cout<<Q(i)<<' '<<Q2(i)<<endl;
//cout<<endl;
}
for(int i=1;i<n-1;i++){
if(Q(i)&&Q2(i))return puts("-1"),0;
if(Q(i)==0&&Q2(i)==0)return puts("-1"),0;
if(Q(i)){
g[i].push_back(i+1),d[i+1]++;
//cout<<i<<' '<<i+1<<endl;
}
else {
g[i+1].push_back(i),d[i]++;
//cout<<i+1<<' '<<i<<endl;
}
}
queue<int> q;
for(int i=1;i<n;i++)if(!d[i])q.push(i);
while(!q.empty()){
int x=q.front();
q.pop(),printf("%d\n",x);
for(int i=0;i<g[x].size();i++){
int y=g[x][i];
if(!(--d[y]))q.push(y);
}
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for(int i=0;i<(int)(n);i++)
#define si(c) ((int)(c).size())
#define forsn(i,s,n) for(int i = (int)(s); i<((int)n); i++)
#define dforsn(i,s,n) for(int i = (int)(n)-1; i>=((int)s); i--)
#define all(c) (c).begin(), (c).end()
#define D(a) cerr << #a << "=" << (a) << endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 2e5 + 10;
int n, p[N];
bool vis[N];
vi ans;
void swp(int i) {
if (vis[i]) {
cout << "-1\n";
exit(0);
}
vis[i] = 1;
swap(p[i], p[i+1]);
ans.pb(i);
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n;
forn(i,n) cin >> p[i];
for (int i = 1; i < n; i++) {
int j = i;
while (j > 0 && p[j] < p[j-1]) {
swp(j-1);
--j;
}
}
if (si(ans) != n-1) cout << "-1\n";
else for (auto x : ans) cout << x+1 << '\n';
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
int main(){
string sa, sb;
cin>>sa>>sb;
cout<<max(((sa[0]-'0')+(sa[1]-'0')+(sa[2]-'0')), ((sb[0]-'0')+(sb[1]-'0')+(sb[2]-'0')));
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
const int INF = 1e9;
const ll LINF = 1e18;
template <class T>
void get_unique(vector<T>& x) {
x.erase(unique(x.begin(), x.end()), x.end());
}
template <class T>
bool chmax(T& a, const T& b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
for (int i = 0; i < int(v.size()); i++) {
is >> v[i];
}
return is;
}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
for (int i = 0; i < int(v.size()); i++) {
os << v[i];
if (i < sz(v) - 1) os << ' ';
}
return os;
}
int main() {
string a, b;
cin >> a >> b;
int sa = 0, sb = 0;
for (char c : a) sa += c - '0';
for (char c : b) sb += c - '0';
cout << max(sa, sb) << '\n';
} |
//#include "test.hpp"
#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define pre(a,b) cout<<fixed<<setprecision(a)<<b<<"\n";//a for precision b for answer
#define mp make_pair
#define pb push_back
#define forn(n) for(ll i=0;i<n;i++)
#define ff first
#define ss second
#define MAX 1e18
#define all(x) (x).begin(),(x).end()
#define lb lower_bound
#define ub upper_bound
const double pi = 3.141592653589793238;
const int MOD1 = 1e9 + 7;
const int MOD2 = 998244353;
const int N=3e5+5;
//cout<<"Case #"<<p<<": "<<;
//file input freopen("input.txt","r",stdin);
//file output freopen("output.txt","w",stdout);
using namespace std;
//check edge cases, alternate methods, n==1,
//check MOD1,MOD2,
//stuck?? - try simplifying expression, try reversing the problem,
int32_t main()
{
IOS;
ll a,b,c;
cin>>a>>b>>c;
(a+c>b)?cout<<"Takahashi":cout<<"Aoki";
} | #include <iostream>
#include <algorithm>
using namespace std;
main()
{
string tak = "Takahashi";
string aok = "Aoki";
int a, b, c;
cin >> a >> b >> c;
if(c == 0){
while(true)
{
if(a <= 0){cout << aok;return 0;}
a--;
if(b <= 0){cout << tak; return 0;}
b--;
}
}else {
while(true)
{
if(b <= 0){cout << tak; return 0;}
b--;
if(a <= 0){cout << aok;return 0;}
a--;
}
}
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FOR1(i, n) for(int (i)=1; (i)<=(n); (i)++)
#define FORI(i, n) for(int (i)=n-1; (i)>=0; (i)--)
template<class T, class U> void umin(T& x, const U& y){ x = min(x, (T)y);}
template<class T, class U> void umax(T& x, const U& y){ x = max(x, (T)y);}
template<class T, class U> void init(vector<T> &v, U x, size_t n) { v=vector<T>(n, (T)x); }
template<class T, class U, typename... W> void init(vector<T> &v, U x, size_t n, W... m) { v=vector<T>(n); for(auto& a : v) init(a, x, m...); }
int main(int argc, char** argv) {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(15);
if (argc == 2 && atoi(argv[1]) == 123456789) freopen("d:\\code\\cpp\\contests\\stdin", "r", stdin);
int n;
cin >> n;
vector<int> a(n), b(n);
vector<ll> c(n);
FOR(i, n) cin >> a[i];
FOR(i, n) cin >> b[i];
ll am = a[0];
ll bm = b[0];
ll x = am*bm;
FOR(i, n){
umax(am, a[i]);
if (b[i] > bm) {
bm = b[i];
x = am*bm;
}
umax(x, am * b[i]);
c[i] = x;
}
FOR(i, n) cout << c[i] << '\n';
if (argc == 2 && atoi(argv[1]) == 123456789) cout << clock()*1.0/CLOCKS_PER_SEC << " sec\n";
return 0;
}
| #pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
#define DEBUG
#ifdef DEBUG
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
os << '(' << p.first << ',' << p.second << ')';
return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
os << '{';
for(int i = 0; i < (int)v.size(); i++) {
if(i) { os << ','; }
os << v[i];
}
os << '}';
return os;
}
void debugg() { cerr << endl; }
template <class T, class... Args>
void debugg(const T &x, const Args &... args) {
cerr << " " << x;
debugg(args...);
}
#define debug(...) \
cerr << __LINE__ << " [" << #__VA_ARGS__ << "]: ", debugg(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = (1<<30) - 1;
const ll linf = 1LL<<62;
const int MAX = 10100000;
int dy[8] = {0,1,0,-1,1,-1,-1,1};
int dx[8] = {-1,0,1,0,1,-1,1,-1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
if(a>b){
a = b; return true;
}
else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
if(a<b){
a = b; return true;
}
else return false;
}
template<typename T> inline void print(T &a){
int sz = a.size();
for(auto itr = a.begin(); itr != a.end(); itr++){
cout << *itr;
sz--;
if(sz) cout << " ";
}
cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){
cout << a << " " << b << "\n";
}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
cout << a << " " << b << " " << c << "\n";
}
void mark() {cout << "#" << "\n";}
ll pcount(ll x) {return __builtin_popcountll(x);}
const int mod = 1e9 + 7;
//const int mod = 998244353;
int main(){
int a,b; cin >> a >> b;
printf("%.5f\n",(a-b)/(double)a*100);
} |
#include <bits/stdc++.h>
//#define rep(i,a,n) for (int i=a;i<n;i++)
#define overload4(_1, _2, _3, _4, name, ...) name
#define rep1(n) for(ll i = 0; i < (n); ++i)
#define rep2(i, n) for(ll i = 0; i < (n); ++i)
#define rep3(i, a, b) for(ll i = (a); i < (b); ++i)
#define rep4(i, a, b, c) for(ll i = (a); i < (b); i += (c))
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define rrep(i,a,n) for (int i=n-1;i>=a;i--)
#define ALL(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pause "read -p 'Press Enter to continue...' var"
using namespace std;
//int gcd(int a,int b){return b?gcd(b,a%b):a;}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
/*
テスト通りますように
●
/⌒ヽ
| |/⌒ヽ(ヽ
(` ∥ー⌒) |
| ̄|| ̄ ̄ ̄ ̄ ̄|
|―||―――――|
| U |
| ̄ ̄ ̄ ̄ ̄ ̄ ̄|
|_______|
|―――――|
|―――――|
wwWwwWwWWw
*/
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
const ll INF = numeric_limits<ll>::max()/4;
const ll MAX = 200000;
const int MOD = 1e9 + 7;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int main(){
ll n,C;
cin >> n >> C;
vector<pll> vec;
vec.pb(mp(0,0));
rep(i,n){
ll a,b,c;
cin >> a >> b >> c;
vec.pb(mp(a,c));
vec.pb(mp(b+1,c*-1));
}
sort(ALL(vec));
ll now = 0;
ll ans = 0;
vec.pb(mp(vec[vec.size()-1].fi + 1,0));
rep(i,vec.size()-1){
now += vec[i].se;
//cout << vec[i].fi << ' ' << vec[i+1].fi << ' ' << now << endl;
if(vec[i].fi == vec[i+1].fi) continue;
if(now >= C){
ans += C * (vec[i+1].fi - vec[i].fi);
//cout << "+=" << C * (vec[i+1].fi - vec[i].fi) << endl;
}
else{
ans += now * (vec[i+1].fi - vec[i].fi);
//cout << "2+=" << now * (vec[i+1].fi - vec[i].fi) << ' ' << ans << endl;
}
}
cout << ans << endl;
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod=1e9+7;
void solve(){
int n,C;cin>>n>>C;
vector<int>a(n),b(n),c(n);
for(int i=0;i<n;i++) cin>>a[i]>>b[i]>>c[i];
map<int,int>mp;
for(int i=0;i<n;i++){
mp[a[i]]+=c[i];
mp[b[i]+1]-=c[i];
}
int curr=0;
int prev=0;
int ans=0;
for(auto x:mp){
ans+=min(C,curr)*(x.first-prev);
curr+=x.second;
prev=x.first;
}
cout<<ans;
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);
int T=1;
// cin>>T;
while(T--){
solve();
}
} |
#include<bits/stdc++.h>
using namespace std;
#define sz(x) (int)(x).size()
#define int long long int
#define loop(i,a,b) for(int i=a;i<b;i++)
#define scan(arr,n) for (int i = 0; i < n; ++i) cin >> arr[i]
#define vi vector<int>
#define si set<int>
#define pii pair <int, int>
#define sii set<pii>
#define vii vector<pii>
#define mii map <int, int>
#define pb push_back
#define ff first
#define ss second
#define all(aa) aa.begin(), aa.end()
#define rall(a) a.rbegin() , a.rend()
#define read(a,b) int a,b; cin>>a>>b
#define readt(a,b,c) int a,b,c; cin>>a>>b>>c
#define readf(a,b,c,d) int a,b,c,d; cin>>a>>b>>c>>d;
#define print(v) for(auto x:v) cout<<x<<" ";cout<<endl
#define printPair(res) for(pair<int,int>& p:res) cout<<p.first<<" "<<p.second<<endl;
#define faster ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
int fac[300001];
void fact(int m){fac[0]=1;for(int i=1;i<=300000;i++) fac[i]=(fac[i-1]%m * i%m)%m;}
/* Iterative Function to calculate (x^y)%p in O(log y)*/
long long power( long long x, int y, int p){ long long res = 1;
x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p;} return res;}
// Returns n^(-1) mod p
long long modInverse( long long n, int p) { return power(n, p - 2, p); }
long long nCr( long long n,int r, int p) { if (r == 0) return 1; if(n<r) return 0;
return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p; }
int binarySearch(vi arr, int l, int r, int x) {
if (r >= l) { int mid = l + (r - l) / 2; if (arr[mid] == x) return mid;
if (arr[mid] > x) return binarySearch(arr, l, mid - 1, x);
return binarySearch(arr, mid + 1, r, x); } return -1; }
bool sortGrt(const pair<int,int> &a, const pair<int,int> &b)
{
return (a.second > b.second);
}
void solve(int test)
{
int n;cin>>n;
vi a(n);
scan(a,n);
sort(all(a));
int suffix[n]={0};
suffix[n-1]=0;
for(int i=n-2;i>=0;i--)
{
suffix[i]=suffix[i+1]+a[i+1];
}
// loop(i,0,n)
// cout<<suffix[i]<<" ";
// cout<<endl;
int t1=0;
for(int i=0;i<n;i++)
{
t1+=(a[i]*a[i]);
}
t1=t1* (n-1);
int t2=0;
loop(i,0,n)
{
t2+= a[i]*suffix[i];
}
t2*=2;
t1=t1-t2;
cout<<t1;
}
int32_t main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
faster;
//fact(mod);
int t=1;
//cin>>t;
for(int test=1;test<=t;test++)
{
solve(test);
}
} | #include <bits/stdc++.h>
using namespace std;
struct Fast {Fast() {std::cin.tie(0); ios::sync_with_stdio(false);}} fast;
using ull = unsigned long long;
using ll = long long;
using vi = vector<int>;
using vl = vector<long>;
using vll = vector<long long>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using vvll = vector<vll>;
using vs = vector<string>;
using pii = pair<int, int>;
#define pb push_back
#define mp make_pair
#define YESNO(bool) if(bool){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(bool) if(bool){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(bool) if(bool){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define reps(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define rep(i, n) reps(i, 0, n)
#define rrep(i, n) reps(i, 1, n + 1)
#define repd(i,n) for(ll i=n-1;i>=0;i--)
#define rrepd(i,n) for(ll i=n;i>=1;i--)
#define debug(x) cerr << "\033[33m(line:" << __LINE__ << ") " << #x << ": " << x << "\033[m" <<endl;
inline int in_int() {int x; cin >> x; return x;}
inline ll in_ll() {ll x; cin >> x; return x;}
inline string in_str() {string x; cin >> x; return x;}
template <typename T> inline bool chmin(T& a, const T& b) {bool compare = a > b; if (a > b) a = b; return compare;}
template <typename T> inline bool chmax(T& a, const T& b) {bool compare = a < b; if (a < b) a = b; return compare;}
int main()
{
int n = in_int();
ll ret = 0;
ll x = 0;
ll y = 0;
rep(i, n) {
int a = in_int();
ret += i * a * a - 2 * a * x + y;
x += a;
y += a * a;
}
//reps(i, 1, n) {
// rep(j, i) {
// ret += (a[i] - a[j]) * (a[i] - a[j]);
// }
//}
cout << ret;
return 0;
}
|
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cmath>
#include <climits>
#include <map>
#include <queue>
#include <functional>
using namespace std;
typedef long long ll;
#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 all(v) v.begin(),v.end()
const ll mod = 1e9+7;
// int main() {
// int a,b,c,d;
// cin >> a >> b >> c >> d;
// cout << b-c << endl;
// return 0;
// }
// /*
// int main() {
// string s;
// cin >> s;
// rep(i,s.size()) {
// if (s[i] == '.') {
// cout << endl;
// return 0;
// }
// cout << s[i];
// }
// cout << endl;
// return 0;
// }
int main() {
ll n;
cin >> n;
int d = 0;
ll m = n;
while (m > 0) {
d++;
m /= 10;
}
int ans = 0;
for (int i = 1; i <= 7; i++)
{
for (int j = pow(10,i-1); j < pow(10,i); j++)
{
if (n >= j*pow(10,i) + j) {
ans++;
} else {
cout << ans << endl;
return 0;
}
}
}
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
int main(){
cin >> n;
for(int i=0; i<n ;i++){
cout << i*2%n+1 << ' ' << (i*2+1)%n+1 << '\n';
}
} |
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
using ll=int;
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;
/*
01234でタイルの方向管理?
*/
#define TIMEOVER_M 25000
#define TIMEOVER 1950000
ll T[50][50];
bool B[50][50];
ll P[50][50];
ll D[50][50];
char *ans;
char *W;
ll score=0;
ll high=0;
ll dx[]={0, 1, 0, -1};
ll dy[]={-1, 0, 1, 0};
char dc[]={'U', 'R', 'D', 'L'};
bool all_fin;
bool fin;
clock_t start;
clock_t start_m;
ll loop;
void steped(ll y, ll x, bool b){
ll d=D[y][x];
if (d){
--d;
ll ny=y+dy[d];
ll nx=x+dx[d];
B[ny][nx]=b;
}
B[y][x] = b;
}
// 行き止まりになったら、その時点でのstringを出力
void dfs(ll y, ll x, ll c){// {y, x, 歩数}
bool used[4]={};
rep(i, 4){
clock_t now = clock();
if(now-start_m>TIMEOVER_M) fin=true;
if(now-start>TIMEOVER) all_fin=true;
ll r=now%4;
while(used[r]) (r+=1)%=4;
used[r]=true;
ll ny=y+dy[r];
ll nx=x+dx[r];
// cout << "time:" << now-start << endl;
if(ny<0 || nx<0 || ny>49 || nx>49 || B[ny][nx] || fin || all_fin){
if(chmax(high, score)){
if(ans) free(ans);
ans=strdup(W);
}
}
else{
//反映
score+=P[ny][nx];
W[c]=dc[r];
steped(ny, nx, true);
dfs(ny, nx, c+1);
//復元
score-=P[ny][nx];
W[c]='\0';
steped(ny, nx, false);
}
}
}
int main(){
cin.tie(0);
ios::sync_with_stdio(0);
cout << fixed << setprecision(10);
W=(char*)calloc(2000, 1);
start = clock();
ll si, sj;
cin >> si >> sj;
rep(i, 50) rep(j, 50) cin >> T[i][j];
rep(i, 50) rep(j, 50) cin >> P[i][j];
// タイルの方向D
rep(i, 50) rep(j, 50){
rep(k, 4){
ll ny=i+dy[k];
ll nx=j+dx[k];
if(ny<0 || nx<0 || ny>49 || nx>49) continue;
if(T[i][j]==T[ny][nx]) D[i][j]=k+1;
}
}
while(!all_fin){
loop++;
fin=false;
start_m = clock();
score = P[si][sj];
chmax(high, score);
rep(y, 50) rep(x, 50) B[y][x]=false;
rep(i, 2000) W[i]='\0';
steped(si, sj, true);
dfs(si, sj, 0);
}
// cout << high << " " << loop << endl;
printf("%s\n", ans);
}
| #pragma GCC optimize("Ofast")
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h>
#include <functional>
#include <cassert>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
constexpr ll INF = 1e18;
constexpr ll LLMAX = 9223372036854775807;
constexpr int inf = 1e9;
constexpr ll mod = 1'000'000'007;
// constexpr ll mod = 998244353;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define eol endl
// ---------------------------------------------------------------------------
#include<time.h>
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
clock_t start,end;
start = clock();
int x = 0;
int sy,sx;
cin >> sy >> sx;
int H = 50;
int W = 50;
vector<vector<int>> tile_id(H,vector<int>(W));
for(int i=0; i<H; i++){
for(int j=0; j<W; j++){
cin >> tile_id[i][j];
}
}
vector<vector<int>> score(H,vector<int>(W));
for(int i=0; i<H; i++){
for(int j=0; j<W; j++){
cin >> score[i][j];
}
}
vector<bool> used_id(10000,false);
string str = "RDLU";
int sum = 0;
int ans_sum = 0;
string ans;
string now;
auto solve = [&](){
bool fin = false;
function<void(int,int)> dfs = [&](int y,int x)->void{
end = clock();
if((double)(end-start)/CLOCKS_PER_SEC >= 1.95){
fin = true;
return;
}
vector<P> can;
for(int k=0; k<4; k++){
int ny = y + dy[k];
int nx = x + dx[k];
if(ny<0 || ny>=H || nx<0 || nx>=W) continue;
if(used_id[tile_id[ny][nx]]) continue;
can.emplace_back(score[ny][nx],k);
}
sort(can.rbegin(),can.rend());
if(can.size() == 0){
if(chmax(ans_sum,sum)){
ans = now;
}
return;
}
for(auto hoge: can){
int k = hoge.second;
int ny = y + dy[k];
int nx = x + dx[k];
sum += score[ny][nx];
used_id[tile_id[ny][nx]] = true;
now += str[k];
dfs(ny,nx);
if(fin) return;
sum -= score[ny][nx];
used_id[tile_id[ny][nx]] = false;
now.pop_back();
}
};
sum += score[sy][sx];
used_id[tile_id[sy][sx]] = true;
dfs(sy,sx);
return;
};
solve();
cout << ans << eol;
return 0;
} |
# include<bits/stdc++.h>
using namespace std;
# define l long long
# define db long 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 << ')'; }
const bool MULTIPLE_TEST_CASES = false;
const l MOD=1e9+7;
const l N=1e5+5;
const l INF=1e12;
void solve() {
l n;
l x;
cin>>n>>x;
vector<l> v(n), p(n);
rep(i,0,n) {
cin>>v[i]>>p[i];
}
x*=100;
l cur = 0;
rep(i,0,n) {
cur+= (v[i]*p[i]);
if(cur>x) {
cout<<i+1<<"\n";
return;
}
}
cout<<"-1\n";
return;
}
int main(){
io;
int t=1;
if (MULTIPLE_TEST_CASES) cin>>t;
rep(i,0,t) {
solve();
}
return 0;
}
| #include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
int n;
char p[201000], st[201000];
int main(){
int i;
scanf("%d",&n);
scanf("%s",p);
int top = 0;
int res = 0;
for(i=0;i<n;i++){
if(p[i]!='f' && p[i]!='o' && p[i]!='x'){
res += top;
res++;
top=0;
continue;
}
st[++top] = p[i];
while(st[top]=='x' && st[top-1]=='o' && st[top-2]=='f')top-=3;
}
res+=top;
printf("%d\n",res);
} |
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
const lld N = 200043;
const lld MOD = 1000000007;
lld add(lld x, lld y)
{
x =((x%MOD)+(y%MOD))%MOD;
while(x >= MOD) x -= MOD;
while(x < 0) x += MOD;
return x;
}
lld mul(lld x, lld y)
{
return ((x%MOD)*(y%MOD))% MOD;
}
lld binpow(lld x, lld y)
{
lld z = 1;
while(y)
{
if(y & 1) z = mul(z, x);
x = mul(x, x);
y >>= 1;
}
return z;
}
lld inv(lld x)
{
return binpow(x, MOD - 2);
}
lld divide(lld x, lld y)
{
return mul(x, inv(y));
}
// Combinations
/*
lld fact[N];
void precalc()
{
fact[0] = 1;
for(lld i = 1; i < N; i++)
fact[i] = mul(fact[i - 1], i);
}
lld C(lld n, lld k)
{ if(k>n)
return 0;
return divide(fact[n], mul(fact[k], fact[n - k]));
}
*/
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
lld t,i,j;
//cin>>t;
t=1;
while(t--)
{
lld x;
cin>>x;
if(x%100==0)
cout<<100<<endl;
else
cout<<100-(x%100)<<endl;
}
}
| #define _USE_MATH_DEFINES
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<climits>
#include<bitset>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<list>
#include<functional>
using namespace std;
#define MAX(A,B) ((A)>(B)?(A):(B))
#define MIN(A,B) ((A)<(B)?(A):(B))
#define LP(I,S,G) for (long long int I = S; I < G; I++)
#define IN(X) for (int i = 0; i < X.size(); i++)cin >> X[i]
#define OUT(X) for (int i = 0; i < X.size(); i++)out << X[i]
#define SORT(X) sort(X.begin(), X.end())
#define CSORT(X,Y) sort(X.begin(), X.end(),Y)
#define COPY(X,Y) copy(X.begin(), X.end(), Y.begin())
#define ALL(X,Y) for (auto X = Y.begin(); X != Y.end(); X++)
template<class I1, class I2>
istream& operator>>(istream& s, pair<I1, I2>& in) {
s >> in.first >> in.second;
return s;
}
long long int M = 998244353;
bool comp(pair<int, int>& a, pair<int, int>& b) {
return (a.second < b.second);
}
vector<int> t(pow(10, 5), 0);
int main(void) {
int n, m;
cin >> n >> m;
vector<int> t(pow(10, 3) + 1, 0);
LP(i, 0, n) {
int a;
cin >> a;
t[a] = 1;
}
LP(i, 0, m) {
int b;
cin >> b;
t[b] |= 2;
}
ALL(i, t) {
if (*i == 1 || *i == 2)cout << (i - t.begin()) << " ";
}
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 P = pair<int, int>;
int main() {
int H, W;
cin >> H >> W;
char map[H][W];
rep(i, H) rep(j, W) {
char c;
cin >> c;
map[i][j] = c;
}
int count = 0;
rep(i, H) rep(j, W) {
if(map[i][j] == '.') {
if(i+1 < H && map[i+1][j] == '.') count++;
if(j+1 < W && map[i][j+1] == '.') count++;
}
}
cout << count << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define pp pair<ll,ll>
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
constexpr int inf=1000001000;
constexpr ll INF=2e18;
constexpr ll mod=1000000007;
// ll MOD=998244353;
constexpr ll MOD=998244353;
int main() {
int h,w,n,m;
cin >> h >> w >> n >> m;
vector<vector<int>> a(w,vector<int>(h,0)),b(w,vector<int>(h,0));
rep(i,n){
int f,g;
cin >> f >> g;
f--;
g--;
a[g][f]=2;
}
rep(i,m){
int f,g;
cin >> f >> g;
f--;
g--;
a[g][f]=1;
}
rep(i,h){
int u=0;
rep(j,w){
if (a[j][i]==2) u=1;
if (a[j][i]==1) u=0;
if (u==1) b[j][i]=1;
}
}
rep(i,h){
int u=0;
rep(j,w){
if (a[w-j-1][i]==2) u=1;
if (a[w-1-j][i]==1) u=0;
if (u==1) b[w-j-1][i]=1;
}
}
rep(i,w){
int u=0;
rep(j,h){
if (a[i][j]==2) u=1;
if (a[i][j]==1) u=0;
if (u==1) b[i][j]=1;
}
}
rep(j,w){
int u=0;
rep(i,h){
if (a[j][h-i-1]==2) u=1;
if (a[j][h-i-1]==1) u=0;
if (u==1) b[j][h-i-1]=1;
}
}
int ans=0;
rep(i,h){
rep(j,w){
if (b[j][i]==1) ans++;
}
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int64_t N;
cin >> N;
set<int64_t> check;
int64_t ans = 0;
for (int i = 2; i <= log2(N); i++){
int a = 2;
while(true){
if(pow(a, i) > N){
break;
}
check.insert(pow(a,i));
a++;
}
}
ans = N - check.size();
cout << ans <<endl;
} | #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define pii pair<int, int>
#define qi queue<int>
#define sti stack<int>
#define pqi priority_queue<int>
#define pqii priority_queue<pair<int, int>>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define nl endl
#define INF (int)1e9
#define MOD 1000000007
int main()
{
ios_base::sync_with_stdio(false);cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("error.txt", "w", stderr);
freopen("output.txt", "w", stdout);
#endif
int case_t=1;
// cin>>case_t; // Multiple testcases
while(case_t--)
{
ll n;
cin>>n;
ll n1 = (int)sqrt(n);
// cout<<n1;
ll a[n1+5];
memset(a, 0, sizeof(a));
// p = 2;
ll ans = n;
ll p;
for(ll p=2; p*p<=n; p++){
if (a[p] == 1) continue;
ll x = p*p;
while(x<=n){
if(x<=n1 && a[x]==1) ;
else if (x<=n1){
a[x]=1;
ans--;
}
else ans--;
x = x*p;
}
}
// ans += n-p;
cout<<ans;
cout<<"\n";
}
cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define P pair<int,int>
ll cnt(ll y,ll x,map<ll,ll> &data){
if(data.count(y)){
return data[y];
}
if(x>=y){
data[y] = x-y;
return (ll) x-y;
}
if(y%2==0){
ll z = min(cnt(y/2,x,data)+1,abs(y-x));
data[y] = z; return z;
}
else{
ll z = min(min(cnt(y+1,x,data)+1,abs(y-x)),cnt(y-1,x,data)+1);
data[y] = z; return z;
}
}
int main(){
long long X,Y;
cin >> X >> Y;
map<ll,ll> data;
cout << cnt(Y,X,data) << endl;
} | #include <bits/stdc++.h>
#define int long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
signed main(){
fastio
int x,y;
cin >> x >> y;
int ans = 1e18;
for(int i = 0;i <= 63;i++){
if(x > LLONG_MAX/2) break;
int sum = i;
int diff = abs(x-y);
sum += diff/(1LL<<i);
diff %= (1LL<<i);
for(int j = 0;j <= i;j++){
if (diff&(1LL<<j)) {
if (diff&(1LL<<j+1)) diff+=1LL<<j;
else diff-=1LL<<j;
sum++;
}
}
ans = min(ans,sum);
x *= 2;
}
cout << ans << "\n";
} |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e3+5,M=2e4+5,inf=0x3f3f3f3f,mod=1e9+7;
#define mst(a,b) memset(a,b,sizeof a)
#define lx x<<1
#define rx x<<1|1
#define reg register
#define PII pair<int,int>
#define fi first
#define se second
#define pb push_back
#define il inline
ll x,y,a,b,s;
int main(){
cin>>x>>y>>a>>b;
while(x<y/a&&x<(x+b)/a){
x*=a;
s++;
}
cout<<s+(y-1-x)/b<<'\n';
return 0;
}
| #include<bits/stdc++.h>
#include<chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace std::chrono;
using namespace __gnu_pbds;
#define ll long long int
#define ull unsigned long long int
#define FOR(I,a,b) for(int I=a;I<b;I++)
#define FORit(it,a) for(auto it=a.begin();it!=a.end();it++)
#define ROF(I,a,b) for(int I=a;I>=b;I--)
#define vec vector
#define vi vec<int>
#define vll vec<ll>
#define pb push_back
#define pp pop_back
#define all(x) x.begin(),x.end()
#define testcases ll t;cin>>t;while(t--)
#define mem(a,k) memset(a,k,sizeof(a))
#define FF first
#define SS second
#define MP(x,y) make_pair(x,y)
#define rt return
#define br break
#define ct continue
#define elif else if
#define ii pair<int,int>
#define vecin(a,n,index) for(int I=index;I<n;I++)cin>>a[I]
#define vecout(a,n,index) for(int I=index;I<n;I++)cout<<a[I]<<"\n";cout<<endl;
//ll mod = 1000000007;
template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T> using omset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
void solve() {
ll x, y, a, b;
cin >> x >> y >> a >> b;
ll ans = 0;
bool is = false;
while (x * a <= x + b && x * a > 0) {
x *= a;
if (x >= y || x <= 0) {cout << ans << endl; is = true; br;}
ans++;
}
if (!is) {
ans += ((y - x - 1) / b);
cout << ans << endl;
}
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
// START FROM HERE :)
solve();
} |
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#define len(v) v.size()
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define pb push_back
#define endl '\n'
using namespace std;
string toOctal(int n) {
string ans = "";
while(n != 0) {
ans += to_string(n % 8);
n /= 8;
}
return ans;
}
bool isLucky(int n) {
string s = to_string(n);
for(auto ch: s)
if(ch == '7')
return false;
s = toOctal(n);
for(auto ch: s)
if(ch == '7')
return false;
return true;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int N; cin >> N;
int ans = 0;
for(int i = 1;i <= N;++i)
ans += isLucky(i);
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
#include <string.h>
#include <math.h>
using namespace std;
#define loop(i, x, y) for (i = x; i < y; i++)
#define loopr(i, x, y) for (i = x; i > y; i--)
//use *it instead of it
#define vloop(it, x) for (auto it = x.begin(); it != x.end(); it++)
#define vloopr(it, x) for (auto it = x.end() - 1; it != x.begin() - 1; it--)
#define yes printf("YES\n")
#define no printf("NO\n")
#define pb push_back
#define mp make_pair
#define debug(x) cerr << #x << ":" << x << endl
#define yo cerr << "yo" << endl
typedef long long ll;
typedef pair<ll, ll> ii;
typedef pair<ii, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
const ll INF = LLONG_MAX;
const ll MOD = 1e9 + 7;
#define test(t) \
ll t; \
cin >> t; \
while (t--)
//use double
#define precision(x) \
cout.setf(ios::fixed); \
cout << setprecision(10) << x << endl;
// ll gcd(ll x_f, ll y_f)
// {
// if (x_f == 0)
// return y_f;
// return gcd(y_f % x_f, x_f);
// }
// ll power(ll x_f, ll y_f, ll m_f)
// {
// ll res_f = 1;
// x_f = x_f% m_f;
// while (y_f)
// {
// if (y_f & 1)
// res_f = (res_f * x_f) % m_f;
// y_f = y_f >> 1;
// x_f = (x_f * x_f) % m_f;
// }
// return res_f;
// }
// ll less(ll x_f, ll y_f)
// {
// return (x_f > y_f) ? y_f : x_f;
// }
// ll more(ll x_f, ll y_f)
// {
// return (x_f < y_f) ? y_f : x_f;
// }
ll fac(ll x_f)
{
ll fac_f = 1;
for (ll i = 1; i <= x_f; i++)
{
fac_f *= i;
fac_f = fac_f % MOD;
}
return fac_f;
}
bool composite[1000007] = {false};
void seive(ll x)
{
composite[0] = true;
composite[1] = true;
for (ll i = 2; i <= x; i++)
{
if (!composite[i])
{
for (ll j = 2 * i; j <= x; j += i)
{
composite[j] = true;
}
}
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll n, ans = 0;
cin >> n;
for (ll i = 1; i <= n; i++)
{
ll num1 = i, num2 = i, flag = 0;
// debug(num);
while (num1 > 0 && num2 > 0)
{
if (num1 % 10 == 7 || num2 % 8 == 7)
{
flag = 1;
break;
}
num1 = num1 / 10;
num2 = num2 / 8;
}
if (flag == 1)
continue;
//cout << i << endl;
ans++;
}
cout << ans << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define Mp make_pair
#define pb push_back
using ll = long long;
using db = double;
using pii = pair<int, int>;
using vi = vector<int>;
mt19937 mrand(time(0));
ll get(ll r) { return ((ll)mrand() * mrand() % r + r) % r; }
ll get(ll l, ll r) { return get(r - l + 1) + l; }
signed main() {
vi a(4); for(int& i : a) cin >> i;
int bo = 0, sum = a[0] + a[1] + a[2] + a[3];
function<void(int, int)> dfs = [&](int x, int nw) {
if(x == 4) return bo |= (2 * nw == sum), void();
dfs(x + 1, nw), dfs(x + 1, nw + a[x]);
}; dfs(0, 0);
puts(bo ? "Yes" : "No");
fprintf(stderr, "time=%.4f\n", (db)clock()/CLOCKS_PER_SEC);
return 0;
} | /**
* code generated by JHelper
* More info: https://github.com/AlexeyDmitriev/JHelper
* @author tatsumack
*/
#include <iostream>
#include <fstream>
#include <bits/stdc++.h>
#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)
using namespace std;
class CCalculator {
public:
map<int, int> memo;
int fib(int n) {
if (n == 1 || n == 2) return 1;
if (memo.count(n)) return memo[n];
return memo[n] = fib(n - 1) + fib(n - 2);
}
void solve(std::istream& cin, std::ostream& cout) {
int N;
cin >> N;
set<int> s;
REV(i, 90, 0) {
int val = fib(i + 1);
if (N >= val) {
N -= val;
s.insert(i + 1);
}
}
int num = *s.rbegin();
if (num % 2 == 0) num++;
vector<int> res;
FOR(i, 1, num) {
if (i % 2 == 1) {
res.push_back(3);
} else {
res.push_back(4);
}
if (s.count(num - i + 1)) {
if (i % 2 == 1) {
res.push_back(1);
} else {
res.push_back(2);
}
}
}
cout << res.size() << endl;
REP(i, res.size()) cout << res[i] << endl;
}
};
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
std::istream& in(std::cin);
std::ostream& out(std::cout);
CCalculator solver;
solver.solve(in, out);
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(),(x).end
#define rall(x) (x).rbegin(),(x).rend
const int MOD=(int)1e9+7;
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
//freopen("teamwork.in","r",stdin);
//freopen("teamwork.out","w",stdout);
int n;
cin>>n;
int a[n+1],pref[n+1]={};
for(int i=1;i<=n;i++){
cin>>a[i];
pref[i]=a[i]+pref[i-1];
}
int sum1=0,sum2=0;
for(int i=1;i<=n;i++) sum1+=(a[i]*a[i]);
sum1*=n-1;
for(int i=1;i<=n;i++){
sum2+=a[i]*(pref[n]-pref[i]);
}
sum2*=(-2);
cout<<sum1+sum2;
}
| #pragma GCC target("avx2")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("O3")
// include
#include <bits/stdc++.h>
using namespace std;
// conversion
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T>
inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
// change
template <class T>
bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T>
bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return true;
}
return false;
}
// math
template <class T>
inline T sqr(T x) {
return x * x;
}
template <class T>
inline T nCr(T n, T r) {
T num = 1;
for (int i = 1; i <= r; ++i) {
num *= (n - i + 1) / i;
}
return num;
}
template <class T>
inline T nPr(T n, T r) {
r = n - r;
T sum = 1;
int i;
for (i = n; i >= r + 1; --i) sum *= i;
return sum;
}
template <class T>
inline T facctorial(T k) {
T sum = 1;
for (int i = 1; i <= k; ++i) {
sum *= i;
}
return sum;
}
// numeric
template <class T>
inline T gcd(T a, T b) {
if (a < b) {
a ^= b;
b ^= a;
a ^= b;
}
return b ? gcd(b, a % b) : a;
}
template <class T>
inline T lcm(T a, T b) {
return a * b / gcd(a, b);
}
// using
using VI = vector<int>;
using VVI = vector<VI>;
using VS = vector<string>;
using PII = pair<int, int>;
using LL = int64_t;
// container util
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) static_cast<int>((a).size())
#define EACH(i, c) \
for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
// repetition
#define FOR(i, a, b) for (int i = (a); i < static_cast<int>(b); ++i)
#define REP(i, n) FOR(i, 0, n)
// constant
constexpr double EPS = 1e-10;
const double PI = acos(-1.0);
constexpr LL INF = 1e10;
// clear memory
#define CLR(a) memset((a), 0, sizeof(a))
// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) \
cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
<< " " << __FILE__ << endl;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int T;
cin >> T;
vector<PII> LR(T);
for (auto &&[L, R] : LR) {
cin >> L >> R;
}
for (auto &&[L, R] : LR) {
const LL n = R - 2 * L + 1;
if (n < 0) {
cout << 0 << "\n";
continue;
}
cout << n * (n + 1) / 2 << "\n";
}
return 0;
}
|
//デバッグ用オプション:-fsanitize=undefined,address
//コンパイラ最適化
#pragma GCC optimize("Ofast")
//インクルードなど
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using vint = vector<int>;
using vll = vector<ll>;
using vbool = vector<bool>;
template <class T>
using arr = vector<vector<T>>;
//マクロ
//forループ
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
//FORAは範囲for文(使いにくかったら消す)
#define REP(i, n) for (ll i = 0; i < ll(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i < ll(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= ll(b); i--)
#define FORA(i, I) for (const auto &i : I)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(), x.end()
#define SIZE(x) ll(x.size())
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T &b)
{
if (a < b)
{
a = b; // aをbで更新
return true;
}
return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T &b)
{
if (a > b)
{
a = b; // aをbで更新
return true;
}
return false;
}
template <typename... Args>
std::string to_str_by(const std::string &fmt, Args... args)
{
size_t len = std::snprintf(nullptr, 0, fmt.c_str(), args...);
std::vector<char> buf(len + 1);
std::snprintf(&buf[0], len + 1, fmt.c_str(), args...);
return std::string(&buf[0], &buf[0] + len);
}
template <class T>
int popcount(T &a)
{
int c = 0;
REP(i, 8 * (int)sizeof(a))
{
if ((a >> i) & 1)
c++;
}
return c;
}
template <class T>
void pl(T x) { cout << x << " "; }
template <class T>
void pr(T x) { cout << x << endl; }
template <class T>
void prvec(vector<T> &a)
{
REP(i, a.size() - 1)
{
cout << a[i] << " ";
}
pr(a[a.size() - 1]);
}
template <class T>
void prarr(arr<T> &a)
{
REP(i, a.size())
if (a[i].empty())
pr("");
else
prvec(a[i]);
}
using P = pair<ll, ll>;
void prp(P &p) { cout << p.first << " " << p.second << endl; }
/**
* 何も書かれていない黒板があります。 高橋くんは N 回の操作を行い、黒板に整数を書きます
* i 回目の操作では、 Ai 以上 Bi 以下の整数すべてを 1 個ずつ、合計 Bi−Ai+1 個の整数を書きます。
* N回の操作を終えたときの、黒板に書かれた整数の合計を求めてください。
*/
struct Args
{
ll N;
vll A, B;
Args()
{
cin >> N;
A.resize(N);
B.resize(N);
REP(i, N)
{
cin >> A.at(i) >> B.at(i);
}
}
};
class Solver
{
private:
/* data */
Args &args;
ll ans;
public:
Solver(Args &args) : args(args), ans(0)
{
}
void solve()
{
ans = 0;
REP(i, args.N)
{
ll A = args.A.at(i);
ll B = args.B.at(i);
ll sum = (B - A + 1) * (A + B) / 2;
ans += sum;
}
}
void output()
{
pr(ans);
}
};
int main()
{
//入力の高速化用のコード
ios::sync_with_stdio(false);
cin.tie(nullptr);
Args args;
Solver s(args);
s.solve();
s.output();
}
| #include <iostream>
using namespace std;
using ll = int64_t;
int main(){
ll n;
cin >> n;
ll ans = 0;
for(ll i = 0; i < n; i++){
ll a, b;
cin >> a >> b;
ans += b * (b + 1) / 2 - a * (a - 1) / 2;
}
cout << ans << endl;
} |
// Artur Kraska, II UWr
#include <bits/stdc++.h>
#define forr(i, n) for(int i=0; i<n; i++)
#define FOREACH(iter, coll) for(auto iter = coll.begin(); iter != coll.end(); ++iter)
#define FOREACHR(iter, coll) for(auto iter = coll.rbegin(); iter != coll.rend(); ++iter)
#define lbound(P,R,PRED) ({typeof(P) X=P,RRR=(R), PPP = P; while(PPP<RRR) {X = (PPP+(RRR-PPP)/2); if(PRED) RRR = X; else PPP = X+1;} PPP;})
#define testy() int _tests; scanf("%d", &_tests); FOR(_test, 1, _tests)
#define CLEAR(tab) memset(tab, 0, sizeof(tab))
#define CONTAIN(el, coll) (coll.find(el) != coll.end())
#define FOR(i, a, b) for(int i=a; i<=b; i++)
#define FORD(i, a, b) for(int i=a; i>=b; i--)
#define MP make_pair
#define PB push_back
#define ff first
#define ss second
#define deb(X) X;
#define M 998244353
#define INF 1000000007LL
using namespace std;
int n, m, a;
long long tr[200057][22];
long long sito[200057];
int solve()
{
scanf("%d %d", &n, &m);
tr[0][0] = 1;
FOR(i, 1, n+30)
{
tr[i][0] = 1;
FOR(j, 1, 20)
{
tr[i][j] = (tr[i-1][j-1] + tr[i-1][j]) % M;
}
}
FOR(i, 2, m)
{
if(sito[i] == 0)
{
sito[i] = i;
for(long long j = i*(long long)i; j <= m; j+=i)
if(sito[j] == 0)
sito[j] = i;
}
}
long long res = 1;
FOR(i, 2, m)
{
long long r = 1;
int x = i;
map <int, int> mapa;
while(x != 1)
{
mapa[sito[x]]++;
x = x/sito[x];
}
for(auto p : mapa)
{
r = (r*tr[n+p.ss-1][p.ss])%M;
}
//cout << i << " daje " << r << endl;
res = (res + r)%M;
}
printf("%lld\n", res);
return 0;
}
int main()
{
solve();
return 0;
}
| #include<bits/stdc++.h>
#define ll long long int
#define pll pair<ll,ll>
#define vpll vector< pll >
#define mpll map<ll,ll>
#define MOD 998244353
#define all(v) v.begin(),v.end()
#define s(v) v.size()
#define test ll t;cin>>t;while(t--)
#define vec vector<ll>
#define read0(v,n) for(int i=0;i<n;i++)cin>>v[i];
#define read1(v,n) for(int i=1;i<=n;i++)cin>>v[i];
#define trav(a,x) for (auto& a: x)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define cut(x) {cout<<x;return 0;}
#define print(x) {cout<<x<<nl;continue;}
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORB(i,a,b) for(int i=a;i>=b;i--)
#define err1(a) {cout<<#a<<' '<<a<<nl;}
#define err2(a,b) {cout<<#a<<' '<<a<<' '<<#b<<' '<<b<<nl;}
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define f first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define nl '\n'
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define oset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
ll gcd(ll a, ll b)
{
if (b==0)return a;
return gcd(b, a % b);
}
ll lcm(ll a,ll b)
{
return (a*b)/gcd(a,b);
}
ll bpow(ll a, ll b)
{
ll ans=1;
while(b)
{
if(b&1)
ans=(ans*a)%MOD;
b/=2;
a=(a*a)%MOD;
}
return ans;
}
mpll factorise(ll n)
{
mpll fact;
while (n % 2 == 0)
{
fact[2]++;
n = n/2;
}
// n must be odd at this point. So we can skip
// one element (Note i = i +2)
for (int i = 3; i <= sqrt(n); i = i + 2)
{
// While i divides n, print i and divide n
while (n % i == 0)
{
fact[i]++;
n = n/i;
}
}
// This condition is to handle the case when n
// is a prime number greater than 2
if (n > 2)
fact[n]++;
return fact;
}
const int N=1e6;
ll fac[N];
void precompute()
{
fac[0]=1;
FOR(i,1,(ll)5e5)fac[i]=(i*fac[i-1])%MOD;
}
ll ncr(ll n,ll r)
{
return (((fac[n]*bpow(fac[r],MOD-2))%MOD)*(bpow(fac[n-r],MOD-2)))%MOD;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
fast
ll n,m;
cin>>n>>m;
precompute();
ll sum=0;
FOR(i,1,m)
{
mpll temp=factorise(i);
ll x=1;
trav(it,temp)
{
x=(x*ncr(n+it.sc-1,n-1))%MOD;
}
sum=(sum+x)%MOD;
}
cut(sum)
}
|
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<map>
#include<vector>
#include<set>
//const int MOD = int(1e9) + 7;
using namespace std;
int main(){
long long int s,p;
cin >> s >> p;
int flag = 0;
for(int i =1; i< 10000000;i++){
long long int t = pow(i,2);
t = t - (s * i);
if(t + p == 0){
if(s - i > 0){
cout << "Yes" << endl;
flag++;
break;
}
}
}
if(flag == 0){
cout << "No" << endl;
}
}
| #include<bits/stdc++.h>
using namespace std;
long const mod = 1e9+7;
int main(){
long s,p;
cin >> s >> p;
for(long i = 1;i<=sqrt(p);i++){
if(p % i != 0)continue;
if(i + p/i == s){
cout << "Yes";
return 0;
}
}
cout << "No";
} |
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
using namespace std;
template <typename T>
inline void read(T&x){
x=0; char temp=getchar(); bool f=false;
while(!isdigit(temp)){if(temp=='-') f=true; temp=getchar();}
while(isdigit(temp)){x=(x<<1)+(x<<3)+temp-'0'; temp=getchar();}
if(f) x=-x;
}
template <typename T>
void print(T x){
if(x<0) putchar('-'),x=-x;
if(x>9) print(x/10);
putchar(x%10+'0');
}
typedef long long ll;
const int MAXN = 105;
const ll mod = 998244353;
inline ll Add(ll x,ll y){return x+y>=mod? x+y-mod:x+y;}
//basic
int n,w[MAXN],pre[MAXN],sum,aim;
ll fac[MAXN];
//DP
ll f[MAXN][MAXN][MAXN*MAXN];
inline ll DP(){
f[0][0][0]=1;
for(register int i=1;i<=n;i++)
for(register int j=0;j<=i;j++)
for(register int k=0;k<=pre[i];k++){
int x=k,y=pre[i]-k,now=w[i];
if(j>0&&x-now>=0) f[i][j][x]=Add(f[i][j][x],f[i-1][j-1][x-now]);
if(y-now>=0) f[i][j][x]=Add(f[i][j][x],f[i-1][j][x]);
}
ll res=0;
for(register int i=0;i<=n;i++) res=Add(res,fac[i]*fac[n-i]%mod*f[n][i][aim]%mod);
return res;
}
int main(){
read(n),fac[0]=1;
for(register int i=1;i<=n;i++) read(w[i]),sum+=w[i],pre[i]=pre[i-1]+w[i],fac[i]=fac[i-1]*i%mod;
if(sum&1) return puts("0"),0;
aim=sum>>1;
print(DP());
return 0;
} | #include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long ll;
ll a, b, k;
const int n = 35;
vector<vector<ll>> dp(n + 2, vector<ll>(n + 2));
string findkth(int i, int j, ll x) {
if (i == 0) return string(j, 'b');
if (j == 0) return string(i, 'a');
if (x <= dp[i - 1][j]) return "a" + findkth(i - 1, j, x);
return "b" + findkth(i, j - 1, x - dp[i - 1][j]);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> a >> b >> k;
dp[0][0] = 1;
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= n; j++) {
if (i > 0) dp[i][j] += dp[i - 1][j];
if (j > 0) dp[i][j] += dp[i][j - 1];
}
}
cout << findkth(a, b, k) << endl;
return 0;
} |
//#include<math.h>
#include<algorithm>
#include<stdlib.h>
#include<time.h>
#include<stdio.h>
#include<string.h>
#define un unsigned
#define srd srand(time(0))
#define ll long long
#define con continue
#define gtc getchar()
#define ptc putchar
#define dou double
#define eps 0.00000000001
#define opr operator
#define cl(x,a) memset(x,a,sizeof(x))
#define fo0(i,k) for(i=fr[k];i;i=nx[i])
#define fo1(i,l,r) for(i=l;i<=r;i++)
#define fo2(i,l,r) for(i=l;i>=r;i--)
#define fo(i,n) for(i=1;i<=n;i++)
#define ret return
#define x first
#define cint const int
#define y second
#define opi(x) freopen(x,"r",stdin)
#define opo(x) freopen(x,"w",stdout)
#define tpl template<class T>
#define priq priority_queue
#define mp make_pair
#define use using namespace
#define WT while(T--)
#define pb push_back
#define sz size()
use std;
typedef pair<int,int> pii;typedef pair<int,ll> pil;typedef pair<ll,int> pli;typedef pair<ll,ll> pll;
namespace io
{
void _(int &k){char c;int e=1;k=0;while((c=gtc)>'9'||c<'0')if(c=='-')e=-1;k=c-'0';while((c=gtc)<='9'&&c>='0'){k*=10;k+=c-'0';}k*=e;}
void _(ll &k){char c;int e=1;k=0;while((c=gtc)>'9'||c<'0')if(c=='-')e=-1;k=c-'0';while((c=gtc)<='9'&&c>='0'){k*=10;k+=c-'0';}k*=e;}
void _(char &c){while((c=gtc)==' '||c=='\n');}void _(dou &c){scanf("%lf",&c);}void _(char *s){char c;while((c=gtc)!=EOF&&c!=' '&&c!=10)*s++=c;}
template<class t1,class t2>void _(t1 &a,t2 &b){_(a);_(b);}template<class t1,class t2,class t3>void _(t1 &a,t2 &b,t3 &c){_(a);_(b);_(c);}
template<class t1,class t2,class t3,class t4>void _(t1 &a,t2 &b,t3 &c,t4 &d){_(a);_(b);_(c);_(d);}
template<class t1,class t2,class t3,class t4,class t5>void _(t1 &a,t2 &b,t3 &c,t4 &d,t5 &e){_(a);_(b);_(c);_(d);_(e);}
void _p(dou k){printf("%.6lf",k);}void _p(char *c){for(;*c;ptc(*c++));}void _p(const char *c){for(;*c;ptc(*c++));}void _p(char c){ptc(c);}
tpl void _p0(T k){if(k>=10)_p0(k/10);ptc(k%10+'0');}tpl void _p(T k){if(k<0){ptc('-');_p0(-k);}else _p0(k);}tpl void __p(T k){_p(k);ptc(' ');}
tpl void _pn(T k){_p(k);ptc('\n');}template<class t1,class t2>void _p(t1 a,t2 b){__p(a);_pn(b);}
template<class t1,class t2,class t3>void _p(t1 a,t2 b,t3 c){__p(a);__p(b);_pn(c);}
template<class t1,class t2,class t3,class t4>void _p(t1 a,t2 b,t3 c,t4 d){__p(a);__p(b);__p(c);_pn(d);}
tpl void op(T *a,int n){int i;n--;fo(i,n)__p(a[i]);_pn(a[n+1]);}int gi(){int x;_(x);ret x;}ll gll(){ll x;_(x);ret x;}
}
int gcd(int a,int b){ret b?gcd(b,a%b):a;}void fcl(){fclose(stdin);fclose(stdout);}
void fop(const char *s){char c[256],d[256];cl(c,0);cl(d,0);strcpy(c,s);strcpy(d,s);opi(strcat(c,".in"));opo(strcat(d,".out"));}
int eq(dou a,dou b){return a+eps>=b&&b+eps>=a;}tpl void _ma(T &a,T b){if(a<b)a=b;}tpl void _mi(T &a,T b){if(a>b)a=b;}
cint N=1234567,EE=100000000,GG=1000000000,ima=2147483647;
use io;
int n,m,a[N],f[N],T;
int main()
{
int i,j,a1,a2;
_(n,m);
if(n+m>=15&&m>=8)
_pn(1);
else if(n+m>=10&&m>=3)
_pn(2);
else
_pn(3+((n+m)<3));
}
| #include<bits/stdc++.h>
#define fore(i,n) for(int i=0;i<(n);i++)
#define foree(i,a,n) for(int i=(a);i<=(n);i++)
#define mp make_pair
#define pb push_back
#define endl "\n"
#define pii pair<int,int>
#define pll pair<long long,long long>
#define ll long long
#define inp(n) int n;cin>>n;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define YES cout<<"YES\n";
#define NO cout<<"NO\n";
#define OK cout<<"OK\n";
#define si size()
#define emp empty()
#define fi first
#define se second
#define test int T; cin>>T; while(T--)
#define all(x) x.begin(),x.end()
ll mod=1e9+7;
using namespace std;
int checkprime(int N)
{
int count = 0;
for( int i = 1;i * i <=N;++i )
{
if( N % i == 0)
{
if( i * i == N )
count++;
else
count += 2;
}
}
if(count == 2)
return 1;
else
return 0;
}
//---------------------------------------------
int main()
{
fastio;
int r,c,x,y;
cin>>r>>c>>y>>x;
char a[r][c];
fore(i,r)
{
fore(j,c)
cin>>a[i][j];
}
x--;
y--;
int ans=0;
for(int i=y;i<r;i++)
{
if(a[i][x]=='.')
ans++;
else
break;
}
for(int i=y-1;i>=0;i--)
{
if(a[i][x]=='.')
ans++;
else
break;
}
for(int i=x+1;i<c;i++)
{
if(a[y][i]=='.')
ans++;
else
break;
}
for(int i=x-1;i>=0;i--)
{
if(a[y][i]=='.')
ans++;
else
break;
}
cout<<ans;
} |
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
ll n, a, b, i, sum = 0;
cin>>n;
vector<ll> arr(n);
for(i=0;i<n;i+=1)
{
cin>>a>>b;
arr[i] = 2*a+b;
sum+=a;
}
sum = -sum;
sort(arr.begin(), arr.end(), greater<ll>());
i = 0;
while(sum<=0)
{
sum+=arr[i];
i+=1;
}
cout<<i<<endl;
}
| #include<bits/stdc++.h>
using namespace std;
using ll=int64_t;
ll c,x;vector<ll>v;
int main(){
ll n;cin>>n;vector<vector<ll>>s(n,vector<ll>(2));
for(int i=0;i<n;i++){
for(int j=0;j<2;j++)cin>>s[i][j];
x+=s[i][0];
v.push_back(2*s[i][0]+s[i][1]);
}
sort(v.begin(),v.end());reverse(v.begin(),v.end());
for(int i=0;i<n;i++){if(x>=0){c++;x-=v[i];}else break;}
cout<<c<<endl;
}
|
/*
2021-04-15 03:44:57.635786
Category: cumsum
Rating: x
*/
/*
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/
#include<bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define int long long
#define ll long long
#define ld long double
#define gap ' '
#define endl '\n'
void solve(int testcase) {
int n; cin>>n;
vector<int> v(n+1),p(n+1,0);
for(int i=1;i<=n;i++) cin>>v[i];
sort(v.begin()+1,v.end(),greater<int>());
for(int i=1;i<=n;i++) p[i]=p[i-1]+v[i];
int sum=0;
for(int i=1;i<=n-1;i++) {
sum+=(n-i)*v[i]-(p[n]-p[i]);
}
cout<<sum<<endl;
}
int32_t main() {
fio
int T=1;
//cin>>T;
for(int t=1;t<=T;t++) solve(t);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --i)
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; }
typedef long long ll;
typedef pair<int, int> P;
const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;
int main(){
int x[4];
rep(i, 4) cin >> x[i];
int S = 0;
rep(i, 4) S += x[i];
rep(i, 1<<4) {
int t = 0;
rep(j,4) {
if (i>>j&1) t += x[j];
}
if (t == S-t) {
puts("Yes");
return 0;
}
}
puts("No");
} |
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
ll X, Y;
unordered_map<ll, ll> mp;
ll solve(ll y) {
if(mp.find(y) != mp.end()) return mp[y];
if (y == 1) return mp[y] = abs(X-y);
else if (y % 2 == 1) return mp[y] = min(min(solve(y+1)+1, solve(y-1)+1), abs(X-y));
else return mp[y] = min(abs(X-y), solve(y/2)+1);
}
int main() {
cin >> X >> Y;
solve(Y);
cout << mp[Y] << endl;
return 0;
} | #include<bits/stdc++.h>
#define faster ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ull unsigned long long
#define pb push_back
const double PI = acos(-1.0);
using namespace std;
int main()
{
faster
ll n,m;
cin>>n>>m;
if(m==0)
{
cout<<1<<endl;
return 0;
}
ll a[m];
for(int i=0; i<m; i++)
cin>>a[i];
sort(a,a+m);
vector<int> v;
ll mn;
if(a[0]!=1)
{
v.pb(a[0]-1);
}
for(int i=1; i<m; i++)
{
if(a[i]-(a[i-1]+1)!=0)
v.pb(a[i]-(a[i-1]+1));
}
if(a[m-1]!=n)
{
v.pb(n-a[m-1]);
}
//cout<<v.size()<<endl;
if(v.size()==0)
{
cout<<0<<endl;
return 0;
}
sort(v.begin(),v.end());
mn=v[0];
ll ans=0;
for(int i=0; i<v.size(); i++)
{
//cout<<v[i]<<" ";
ans=ans+(v[i]/mn);
if(v[i]%mn!=0)
ans++;
}
cout<<ans<<endl;
return 0;
}
|
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <string.h>
using namespace std;
int main()
{
long long n, k;
cin >> n >> k;
for (int i = 0; i < k; i++)
{
if (n % 200 == 0)
n = n / 200;
else
{
string str = to_string(n);
str = str + "200";
n = stoll(str.c_str());
}
}
cout << n;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main(){
double a, b;
cin >> a >> b;
cout << a * b / 100 << endl;
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const ll mod=1e9+7;
#define rep(i,n) for (int i = 0; i < (n); i++)
ll b,c,ans;
int main(){
cin >> b >> c;
ll k=c/2;
if(c==1){
if(b==0)ans=1;
else ans=2;
}
else if(c%2==1) ans=(k*4+1)-max(0LL,min(b+k-1,k-b)-max(-b-k,b-k)+1);
else ans=(k*4-1)-max(0LL,min(b+k-1,k-b-1)-max(-b-k+1,b-k)+1);
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int64_t B,C;
cin >> B >> C;
int64_t ans = 0;
if(B == 0){
cout << C << endl;
return 0;
}
if(C < 3){
cout << C+1 << endl;
return 0;
}
if(abs(B) >= C){
cout << (C-2)*2+3 << endl;
return 0;
}else{
if(C <= abs(B)*2){
cout << (C-2)*2+3 << endl;
return 0;
}
if(B <= 0){
cout << C + -B*2 << endl;
}else{
cout << C + B*2 - 1 << endl;
}
}
} |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
#define eb(t) emplace_back(t)
typedef long long ll;
typedef long double ld;
typedef long long unsigned int llu;
ll INF = 1000000009;
ll MOD = 1000000007;
ll result[9];
ll p[9];
ll q[9];
ll all[9];
void product(){
result[0] = p[0]*q[0]+p[1]*q[3]+p[2]*q[6];
result[1] = p[0]*q[1]+p[1]*q[4]+p[2]*q[7];
result[2] = p[0]*q[2]+p[1]*q[5]+p[2]*q[8];
result[3] = p[3]*q[0]+p[4]*q[3]+p[5]*q[6];
result[4] = p[3]*q[1]+p[4]*q[4]+p[5]*q[7];
result[5] = p[3]*q[2]+p[4]*q[5]+p[5]*q[8];
result[6] = p[6]*q[0]+p[7]*q[3]+p[8]*q[6];
result[7] = p[6]*q[1]+p[7]*q[4]+p[8]*q[7];
result[8] = p[6]*q[2]+p[7]*q[5]+p[8]*q[8];
return;
}
void solve(){
ll n;
cin >> n;
vector<pair<ll,ll>> v;
rep(i,n){
ll x,y;
cin >> x >> y;
v.eb(make_pair(x,y));
}
ll m;
cin >> m;
rep(i,9){
q[i]=0;
}
q[0]=1;
q[4]=1;
q[8]=1;
vector<tuple<ll,ll,ll,ll,ll,ll,ll,ll,ll>> vt;
vt.eb(make_tuple(1,0,0,0,1,0,0,0,1));
rep(i,m){
ll op;
cin >> op;
if(op==2){
p[0]=0;
p[1]=-1;
p[2]=0;
p[3]=1;
p[4]=0;
p[5]=0;
p[6]=0;
p[7]=0;
p[8]=1;
}
else if(op==1){
p[0]=0;
p[1]=1;
p[2]=0;
p[3]=-1;
p[4]=0;
p[5]=0;
p[6]=0;
p[7]=0;
p[8]=1;
}
else if(op==3){
ll p_;
cin >> p_;
p[0]=-1;
p[1]=0;
p[2]=2*p_;
p[3]=0;
p[4]=1;
p[5]=0;
p[6]=0;
p[7]=0;
p[8]=1;
}
else{
ll p_;
cin >> p_;
p[0]=1;
p[1]=0;
p[2]=0;
p[3]=0;
p[4]=-1;
p[5]=2*p_;
p[6]=0;
p[7]=0;
p[8]=1;
}
product();
rep(j,9) q[j] = result[j];
vt.eb(make_tuple(result[0],result[1],result[2],result[3],result[4],result[5],result[6],result[7],result[8]));
rep(i,9){
//cout << result[i] << " ";
}
//cout << endl;
}
rep(i,9) all[i]=result[i];
ll query;
cin >> query;
rep(i, query){
ll a,b;
cin >> a >> b;
ll cx = v[b-1].first;
ll cy = v[b-1].second;
ll ansx = get<0>(vt[a])*cx + get<1>(vt[a])*cy + get<2>(vt[a]);
ll ansy = get<3>(vt[a])*cx + get<4>(vt[a])*cy + get<5>(vt[a]);
cout << ansx << " " << ansy << endl;
}
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
solve();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using LL = long long;
using vll = vector<LL>;
const vector<vll> CW = {{0, 1, 0}, {-1, 0, 0}, {0, 0, 1}};
const vector<vll> CCW = {{0, -1, 0}, {1, 0, 0}, {0, 0, 1}};
vector<vll> multiply(vector<vll>& A, vector<vll>& B){
int m = A.size(), n = B.size(), p = B[0].size();
vector<vll> answer(m, vll(p, 0));
for (int i = 0; i < m; i++){
for (int j = 0; j < p; ++j){
for (int k = 0; k < n; ++k){
answer[i][j] += A[i][k] * B[k][j];
}
}
}
return answer;
}
void print_matrix(vector<vll>& A){
for (int i = 0; i < A.size(); ++i){
for (int j = 0; j < A[i].size(); ++j){
cout << A[i][j] << (j != A[i].size() - 1 ? ' ' : '\n');
}
}
}
int main(){
ios_base::sync_with_stdio(false);
int n; cin >> n;
vector<vector<vll>> pieces(n);
for (int i = 0; i < n; ++i){
int x, y; cin >> x >> y;
pieces[i] = {{x},{y},{1}};
}
int m; cin >> m;
vector<vector<vll>> ops(m + 1);
ops[0] = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}};
for (int i = 1; i <= m; ++i){
int op; cin >> op;
if (op == 1){
ops[i] = CW;
}
else if (op == 2){
ops[i] = CCW;
}
else if (op == 3){
int p; cin >> p;
ops[i] = {{-1 , 0, 2 * p}, {0, 1, 0}, {0, 0, 1}};
}
else{
int p; cin >> p;
ops[i] = {{1, 0, 0}, {0, -1, 2 * p}, {0, 0, 1}};
}
}
for (int i = 1; i <= m; ++i){
ops[i] = multiply(ops[i], ops[i - 1]);
}
int q; cin >> q;
for (int i = 0; i < q; ++i){
int a, b; cin >> a >> b;
b--;
vector<vll> res = multiply(ops[a], pieces[b]);
cout << res[0][0] << ' ' << res[1][0] << '\n';
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
using ll = long long;
int main() {
double r, x, y;
cin >> r >> x >> y;
double w = sqrt(x * x + y * y);
int ans = ceil(w / r);
if (ans == 1 && w != r) ans++;
cout << ans << endl;
}
| #include<bits/stdc++.h>
using namespace std;
char f(char a, char b) {
if (a == b) return a;
if (a == 'R' && b == 'S') return a;
if (a == 'S' && b == 'R') return b;
if (a == 'P' && b == 'R') return a;
if (a == 'R' && b == 'P') return b;
if (a == 'S' && b == 'P') return a;
return b;
}
string yo(string s, int k) {
int n = s.size();
if (k <= 7 && (1 << k) <= n) {
s.resize(1 << k);
n = 1 << k;
}
if (k == 0) return s;
string p = "";
for (int i = 0; i < n; i += 2) {
p += f(s[i], s[i + 1]);
}
p += p;
return yo(p, k - 1);
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, k; cin >> n >> k;
string s; cin >> s;
s += s;
cout << yo(s, k) << '\n';
return 0;
} |
#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 dsrep(i,t,s) for(int i = (t)-1; i >= (s); --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 snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cerr<<#x<<" = "<<x<<endl;
#define bn(x) ((1<<(x))-1)
#define newline puts("")
using namespace std;
template<typename T> using vc = vector<T>;
template<typename T> using vv = vc<vc<T>>;
template<typename T> using PQ = priority_queue<T,vc<T>,greater<T> >;
using ll = long long;
using uint = unsigned;
using ull = unsigned long long;
using P = pair<int,int>;
using T3 = tuple<int,int,int>;
using vi = vc<int>;
using vvi = vv<int>;
using vl = vc<ll>;
using vp = vc<P>;
using vt = vc<T3>;
int getInt(){int x;scanf("%d",&x);return x;}
template<typename T>istream& operator>>(istream&i,vc<T>&v){rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const vc<T>&v,const string& d=""){stringstream s;rep(i,sz(v))(i?s<<d:s)<<v[i];return s.str();}
template<typename T>ostream& operator<<(ostream&o,const vc<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;}
vc<string> split(const string& s,char d=' '){vc<string> r(1);for(char c:s)if(c==d)r.pb("");else r.back()+=c;return r;}
string operator*(const string& s,int t){return join(vc<string>(t,s));}
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>T dup(T x, T y){return (x+y-1)/y;}
template<typename T>ll suma(const vc<T>&a){ll res(0);for(auto&&x:a)res+=x;return res;}
template<typename T>void uni(vc<T>& a){sort(rng(a));a.erase(unique(rng(a)),a.end());}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;
struct Solver {
int n;
vvi to;
int c;
int cnt;
int dfs(int v, int p=-1) {
int y = 0;
int w = -INF;
for (int u : to[v]) {
if (u == p) continue;
int r = dfs(u,v);
if (r < 0) maxs(w, -r);
else maxs(y, r);
}
// cerr<<y<<" "<<w<<endl;
if (y <= w-1) return -(w-1);
if (y == c) {
++cnt;
return -c;
}
return y+1;
}
int f() {
cnt = 0;
int r = dfs(0);
// cerr<<r<<endl;
if (r > 0) ++cnt;
return cnt;
}
void solve() {
int k;
scanf("%d%d",&n,&k);
to = vvi(n);
rep(i,n-1) {
int a, b;
scanf("%d%d",&a,&b);
--a; --b;
to[a].pb(b);
to[b].pb(a);
}
// c = 1; cerr<<f()<<endl; return;
int l = 0, r = n;
while (l+1<r) {
c = (l+r)/2;
if (f() <= k) r = c; else l = c;
}
cout<<r<<endl;
}
};
int main() {
int ts = 1;
// scanf("%d",&ts);
rrep(ti,ts) {
Solver solver;
solver.solve();
}
return 0;
}
| #include<cstdio>
#include<iostream>
const int MAXN = 3e5 + 10, INF = 0x3f3f3f3f;
int f1[MAXN], f2[MAXN], is_key[MAXN], h[MAXN] = {0};
int N, M, tot, cnt;
struct E{
int t, nxt;
}Ed[2 * MAXN];
void Add(int f, int t){Ed[++tot].t = t, Ed[tot].nxt = h[f]; h[f] = tot;}
void dfs(int u, int fa, int mid)
{
f1[u] = -INF, f2[u] = INF;
for (int i = h[u]; i; i = Ed[i].nxt)
{
int v = Ed[i].t; if (v == fa) continue;
dfs(v, u, mid);
f1[u] = std::max(f1[u], f1[v] + 1);
f2[u] = std::min(f2[u], f2[v] + 1);
}
if (is_key[u] && f2[u] > mid) f1[u] = std::max(0, f1[u]);
if (f1[u] + f2[u] <= mid) f1[u] = -INF;
if (f1[u] == mid) f1[u] = -INF, f2[u] = 0, cnt++;
}
int check(int mid)
{
cnt = 0;
dfs(1, 0, mid);
if (f1[1] >= 0) cnt++;
return cnt <= M;
}
int rd()
{
int ret = 0; char ch = getchar();
while (!isdigit(ch)) ch = getchar();
for (; isdigit(ch); ch = getchar()) ret = ret * 10 + (int)ch - 48;
return ret;
}
int main()
{
N = rd(), M = rd();
for (int i = 1; i <= N; i++) is_key[i] =1;
for (int i = 1; i < N; i++) {int f = rd(), t = rd(); Add(f, t); Add(t, f);}
int l = 0, r = N, ans = N;
while (l <= r)
{
int mid = (l + r) >> 1;
if (check(mid)) ans = mid, r = mid - 1;
else l = mid + 1;
}
dfs(1, 0, 1);
printf("%d\n", ans);
return 0;
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.