code_file1
stringlengths 87
4k
| code_file2
stringlengths 82
4k
|
---|---|
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double db;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pll pair<ll,ll>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ub(v,val) upper_bound(v.begin(),v.end(),val)
#define np(str) next_permutation(str.begin(),str.end())
#define lb(v,val) lower_bound(v.begin(),v.end(),val)
#define sortv(vec) sort(vec.begin(),vec.end())
#define rev(p) reverse(p.begin(),p.end());
#define v vector
#define pi 3.14159265358979323846264338327950288419716939937510
#define len length()
#define repc(i,s,e) for(ll i=s;i<e;i++)
#define fi first
#define se second
#define mset(a,val) memset(a,val,sizeof(a));
#define mt make_tuple
#define repr(i,n) for(i=n-1;i>=0;i--)
#define rep(i,n) for(i=0;i<n;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define at(s,pos) *(s.find_by_order(pos))
#define set_ind(s,val) s.order_of_key(val)
long long int M = 1e9 + 7 ;
long long int inf = 9 * 1e18;
//CLOCK
ll begtime = clock();
#define time() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//CLOCK ENDED
ll n, m;
// modular exponentiation
ll binpow(ll val, ll deg)
{
if (deg < 0)
return 0;
if (!deg)
return 1 % M;
if (deg & 1)
return binpow(val, deg - 1) * val % M;
ll res = binpow(val, deg >> 1);
return (res * res) % M;
}
//binomial
ll modinv(ll n) {
return binpow(n, M - 2);
}
int main() {
// your code goes here
IOS;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ll i, j, t, k, x, y, z, N;
cin >> t;
while (t--) {
cin >> n;
ll a[n];
rep(i, n) cin >> a[i];
if (n % 2) {
cout << "Second";
}
else {
map<ll, ll> cnt;
rep(i, n) {
cnt[a[i]]++;
}
ll flg = 0;
for (auto u : cnt) {
if (u.se % 2)flg = 1;
}
if (flg == 0) {
cout << "Second";
}
else
cout << "First";
}
cout << '\n';
}
return 0;
}
// Second
// Second
// First
// First
// Second
| #include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <numeric>
#include <limits>
#include <type_traits>
#include <locale>
#include <omp.h>
using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE) \
if (TRUE_OR_FALSE) \
{ \
cout << "YES" << endl; \
} \
else \
{ \
cout << "NO" << endl; \
}
#define IFYes(TRUE_OR_FALSE) \
if (TRUE_OR_FALSE) \
{ \
cout << "Yes" << endl; \
} \
else \
{ \
cout << "No" << endl; \
}
#define IFyes(TRUE_OR_FALSE) \
if (TRUE_OR_FALSE) \
{ \
cout << "yes" << endl; \
} \
else \
{ \
cout << "no" << endl; \
}
#define DEBUG_OUTPUT_ARRAY(XXX, ONE) \
for (int i = 0; i < (ONE); i++) \
{ \
cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
}
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO) \
for (int i = 0; i < (ONE); i++) \
{ \
cout << "<<< i = " << i << " >>>" << endl; \
for (int j = 0; j < (TWO); j++) \
{ \
cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
} \
}
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
for (int i = 0; i < (ONE); i++) \
{ \
cout << i << " "; \
for (int j = 0; j < (TWO); j++) \
{ \
cout << XXX[i][j] << " "; \
} \
cout << endl; \
}
typedef pair<long long int, long long int> pll;
typedef pair<long long int, pll> lpll;
const long long int mod = 1000000007;
const long long int INF = 1e18;
const long double PI=3.14159265358979323;
//const long long int pl=1000000;
long long int T,N,M;
long long int A[300005],B,C,D,res=0,w[10],l[200200],v[200200];
int main()
{
cout << fixed << setprecision(18);
cin>>T;
for(long long int q = 0; q < T; q++){
cin>>N;
for(long long int i = 0; i < N; i++){
cin>>A[i];
}
sort(A,A+N);
if(N%2==1){
cout<<"Second"<<endl;
continue;
}
bool key =true;;
for(long long int i = 0; i < N; i+=2){
if(A[i]!=A[i+1]){
cout<<"First"<<endl;
key=false;
break;
}
}
if(key)cout<<"Second"<<endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
void solve(){
int n, s, d; cin>>n>>s>>d;
for(int i=0; i < n; i++){
int x, y; cin>>x>>y;
if (x < s && y > d) {
cout<<"Yes";
return;
}
}
cout<<"No";
}
int main(){
#ifdef USE_FILE_IO
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
#ifndef USE_FILE_IO
ios_base::sync_with_stdio(0); cin.tie();
#endif
solve();
} | #include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 100001
#define i197 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<ll,Pi> Pli;
typedef pair<Pi,Pi> Pi2;
typedef pair<P1,ll>P2;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};
struct pos{
// 1 変数を入れる;
int t,x,y;
};
int main(){
ll s,d;
int n;
cin>>n>>s>>d;
rep(i,n){
ll x,y;
cin>>x>>y;
if(x<s&&y>d){
cout<<"Yes"<<endl;
return 0;
}
}
cout<<"No"<<endl;
return 0;
}
|
#include<bits/stdc++.h> //Written by ThiDaiLoc
using namespace std; //Team Three Wolves
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> trp;
typedef vector<ll> vi;
typedef vector<pll> vp;
#define fu(i,a,b) for(ll i=a;i<=b;i++)
#define f1(i,n) for(ll i=1;i<=n;i++)
#define fs(i,s) for(ll i=0;i+1<=s.length();i++)
#define fd(i,b,a) for(ll i=b;i>=a;i--)
#define fuv(i,a) for(ll i=0;i<a.size();i++)
#define fdv(i,a) for(ll i=(ll)a.size()-1;i>=0;i--)
#define ms(a,x) memset(a, x, sizeof a)
#define prec(n) fixed<<setprecision(n)
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb(i) push_back(i)
#define pob pop_back()
#define sc(a) cin>>a
#define sc2(a,b) cin>>a>>b
#define sc3(a,b,c) cin>>a>>b>>c
#define pr(a) cout<<a<<endl
#define pr2(a,b) cout<<a<<" "<<b<<endl
#define rpr(a) return cout<<a<<endl,0
#define prY cout<<"YES"<<endl
#define prN cout<<"NO"<<endl
#define bit(n,i) (((n)>>(i))&1)
#define lowb(a,n,x) lower_bound(a,a+n,x) -a
#define lowb2(a,x) lower_bound(all(a),x) -a.begin()
#define all(x) (x).begin(), (x).end()
#define sz(a) (ll)a.size()
#define le(s) (ll)s.length()
#define re return
#define mp(a,b) make_pair(a,b)
#define mp3(a,b,c) make_pair(a,make_pair(b,c))
#define se second
#define fi first
#define sse second.second
#define sfi second.first
#define soA sort(A+1,A+1+n)
#define so(A,n) sort(A+1,A+1+n)
#define sov(v) sort(all(v))
#define sovr(v) sort(all(v),greater<ll>())
#define debug(x) cerr << #x << " = " << x << endl
#define INPUT freopen("locin.txt", "r", stdin)
#define OUTPUT freopen("locout.txt", "w", stdout)
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline ll mnz(ll& a,ll b){return a=(a>b?b:a);}
inline ll mxz(ll& a,ll b){return a=(a<b?b:a);}
inline string toString(ll n) {stringstream ss; ss << n;return ss.str();}
double const eps = 1e-6;
ll const Base=1e9+7,oo=1e17,MAXN=1e6;
pll A[MAXN+5];
pll B[MAXN+5];
pll add[MAXN+5];
pll xy[MAXN+5];
ll Solves(){
ll n,m,k,cnt=0,ans=0,x,y,q,c,sum=0,v,t;
// PROCESS IN HERE
cin>>n;
f1(i,n)sc2(A[i].fi,A[i].se);
sc(m);
xy[0]=mp(1,2);
f1(i,m){
sc(x);
if(x>=3){
sc(y);
}
if(x==1){
xy[i]=mp(xy[i-1].se,-xy[i-1].fi);
add[i]=mp(add[i-1].se,-add[i-1].fi);
}
if(x==2){
xy[i]=mp(-xy[i-1].se,xy[i-1].fi);
add[i]=mp(-add[i-1].se,add[i-1].fi);
}
if(x==3){
xy[i]=xy[i-1];
xy[i].fi=-xy[i].fi;
add[i]=add[i-1];
add[i].fi=-add[i].fi;
add[i].fi+=y*2;
}
if(x==4){
xy[i]=xy[i-1];
xy[i].se=-xy[i].se;
add[i]=add[i-1];
add[i].se=-add[i].se;
add[i].se+=y*2;
}
}
sc(q);
f1(i,q){
sc2(x,y);
if(abs(xy[x].fi)==1){
v=A[y].fi;
if(xy[x].fi<0)v=-v;
t=A[y].se;
if(xy[x].se<0)t=-t;
}
else{
v=A[y].se;
if(xy[x].fi<0)v=-v;
t=A[y].fi;
if(xy[x].se<0)t=-t;
}
v+=add[x].fi;
t+=add[x].se;
cout<<v<<" "<<t<<endl;
}
re 0;
// Hack it if you can :)
}
int main(){
//INPUT;
if(fopen("locin.txt", "r"))INPUT;
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
ll test=1;
// sc(test);
fu(T,1,test){
// cout<<"Case #"<<T<<": ";
Solves();
}
} | #include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int INF = 1e9;
const long long INFLL = 1e18;
using ll = long long;
ll mat[200000+10][2][2];
ll p[200000+10][2];
ll mix, miy;
vector<vector<ll>> cal(ll n, ll p){
vector<vector<ll>> res(2, vector<ll>(2));
if(n == 1){
res[0][0] = 0;
res[0][1] = 1;
res[1][0] = -1;
res[1][1] = 0;
}else if(n == 2){
res[0][0] = 0;
res[0][1] = -1;
res[1][0] = 1;
res[1][1] = 0;
}else if(n == 3){
}
return res;
}
int main(){
ll n;
cin >> n;
vector<ll> x(n), y(n);
for(ll i = 0; i < n; i++) cin >> x[i] >> y[i];
ll m;
cin >> m;
mix = -1;
miy = -1;
mat[0][0][0] = 1;
mat[0][0][1] = 0;
mat[0][1][0] = 0;
mat[0][1][1] = 1;
p[0][0] = 0;
p[0][1] = 0;
for(ll i = 1; i <= m; i++){
ll op;
cin >> op;
if(op == 1){
mat[i][0][0] = mat[i-1][1][0];
mat[i][0][1] = mat[i-1][1][1];
mat[i][1][0] = -mat[i-1][0][0];
mat[i][1][1] = -mat[i-1][0][1];
// p[i][0] = mat[i][0][0]*p[i-1][0] + mat[i][0][1]*p[i-1][1];
// p[i][0] = mat[i][1][0]*p[i-1][0] + mat[i][1][1]*p[i-1][1];
p[i][0] = p[i-1][1];
p[i][1] = -p[i-1][0];
}else if(op == 2){
mat[i][0][0] = -mat[i-1][1][0];
mat[i][0][1] = -mat[i-1][1][1];
mat[i][1][0] = mat[i-1][0][0];
mat[i][1][1] = mat[i-1][0][1];
// p[i][0] = mat[i][0][0]*p[i-1][0] + mat[i][0][1]*p[i-1][1];
// p[i][0] = mat[i][1][0]*p[i-1][0] + mat[i][1][1]*p[i-1][1];
p[i][0] = -p[i-1][1];
p[i][1] = p[i-1][0];
}else if(op == 3){
ll pp;
cin >> pp;
mix *= -1;
mat[i][0][0] = -mat[i-1][0][0];
mat[i][0][1] = -mat[i-1][0][1];
mat[i][1][0] = mat[i-1][1][0];
mat[i][1][1] = mat[i-1][1][1];
p[i][0] = -1 * p[i-1][0] + 2*pp;
p[i][1] = p[i-1][1];
}else{
ll pp;
cin >> pp;
miy *= -1;
mat[i][0][0] = mat[i-1][0][0];
mat[i][0][1] = mat[i-1][0][1];
mat[i][1][0] = -mat[i-1][1][0];
mat[i][1][1] = -mat[i-1][1][1];
p[i][0] = p[i-1][0];
p[i][1] = -1 * p[i-1][1] + 2*pp;
}
}
ll q;
cin >> q;
for(ll i = 0; i < q; i++){
ll a, b;
cin >> a >> b;
b --;
ll nx = mat[a][0][0]*x[b] + mat[a][0][1]*y[b] + p[a][0];
ll ny = mat[a][1][0]*x[b] + mat[a][1][1]*y[b] + p[a][1];
cout << nx << " " << ny << endl;
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL X, Y;
map<LL, LL> memo;
LL solve(LL y) {
if(memo.count(y)) return memo[y];
if(y == 1) return memo[y] = llabs(X-y);
if(y % 2 == 1) return memo[y] = min(llabs(X-y), min(solve((y+1)/2) + 2, solve((y-1)/2) + 2));
if(y % 2 == 0) return memo[y] = min(llabs(X-y), solve(y/2) + 1);
return memo[y];
}
int main() {
memo.clear();
cin >> X >> Y;
if(Y <= X){
cout << X - Y << endl;
return 0;
}
cout << solve(Y) << "\n";
}
| //#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 Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const ll LINF = (1LL<<60);
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll X,Y; cin >> X >> Y;
ll ans = LINF;
map<ll, ll> memo;
priority_queue<LP, vector<LP>, greater<LP>> que;
que.emplace(0, Y);
while(!que.empty()){
auto [v, x] = que.top();
que.pop();
if(v>=ans) continue;
chmin(ans, v+abs(X-x));
int r = (x&1);
ll nv = v+r+1;
int d = 2;
if(nv<ans && (!memo.count(x/d) || nv<memo[x/d])){
que.emplace(nv, x/d);
memo[x/d] = nv;
}
nv = v+(d-r)+1;
if(nv<ans && (!memo.count(x/d+1) || nv<memo[x/d+1])){
que.emplace(nv, x/d+1);
memo[x/d+1] = nv;
}
}
cout << ans << endl;
return 0;
}
|
/*
author: Maksim1744
created: 23.05.2021 16:09:04
*/
#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;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// find_by_order, order_of_key
using ll = long long;
using ld = long double;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define sum(a) ( accumulate ((a).begin(), (a).end(), 0ll))
#define mine(a) (*min_element((a).begin(), (a).end()))
#define maxe(a) (*max_element((a).begin(), (a).end()))
#define mini(a) ( min_element((a).begin(), (a).end()) - (a).begin())
#define maxi(a) ( max_element((a).begin(), (a).end()) - (a).begin())
#define lowb(a, x) ( lower_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define uppb(a, x) ( upper_bound((a).begin(), (a).end(), (x)) - (a).begin())
template<typename T> vector<T>& operator-- (vector<T> &v){for (auto& i : v) --i; return v;}
template<typename T> vector<T>& operator++ (vector<T> &v){for (auto& i : v) ++i; return v;}
template<typename T> istream& operator>>(istream& is, vector<T> &v){for (auto& i : v) is >> i; return is;}
template<typename T> ostream& operator<<(ostream& os, vector<T> v){for (auto& i : v) os << i << ' '; return os;}
template<typename T, typename U> pair<T,U>& operator-- (pair<T, U> &p){--p.first; --p.second; return p;}
template<typename T, typename U> pair<T,U>& operator++ (pair<T, U> &p){++p.first; ++p.second; return p;}
template<typename T, typename U> istream& operator>>(istream& is, pair<T, U> &p){is >> p.first >> p.second; return is;}
template<typename T, typename U> ostream& operator<<(ostream& os, pair<T, U> p){os << p.first << ' ' << p.second; return os;}
template<typename T, typename U> pair<T,U> operator-(pair<T,U> a, pair<T,U> b){return mp(a.first-b.first, a.second-b.second);}
template<typename T, typename U> pair<T,U> operator+(pair<T,U> a, pair<T,U> b){return mp(a.first+b.first, a.second+b.second);}
template<typename T, typename U> void umin(T& a, U b){if (a > b) a = b;}
template<typename T, typename U> void umax(T& a, U b){if (a < b) a = b;}
#ifdef HOME
#define SHOW_COLORS
#include "C:/C++ libs/print.cpp"
#else
#define show(...) void(0)
#define mclock void(0)
#define shows void(0)
#define debug if (false)
#endif
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int n;
cin >> n;
vector<int> a(n), b(n);
cin >> a >> b;
for (int i = 0; i < n; ++i) {
a[i] += i;
b[i] += i;
}
map<int, deque<int>> where;
for (int i = 0; i < n; ++i) {
where[a[i]].pb(i);
}
{
auto x = a;
auto y = b;
sort(x.begin(), x.end());
sort(y.begin(), y.end());
if (x != y) {
cout << -1 << '\n';
return 0;
}
}
vector<int> p(n);
for (int i = 0; i < n; ++i) {
p[i] = where[b[i]][0];
where[b[i]].pop_front();
}
ordered_set<int> s;
ll ans = 0;
for (int x : p) {
ans += s.size() - s.order_of_key(x);
s.insert(x);
}
cout << ans << '\n';
return 0;
}
| #include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i,a,b) for (ll i = (a); i < (ll)(b); i++)
#define rng(x) (x).begin(), (x).end()
#define rrng(x) (x).rbegin(), (x).rend()
#define popcnt(x) __builtin_popcountll(x)
#define pb push_back
#define eb emplace_back
#define MP make_pair
#define MT make_tuple
#define fr first
#define sc second
using namespace std;
template <class T, class U> inline bool chmax(T &a, const U &b) { return (a < b ? a = b, 1 : 0); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return (a > b ? a = b, 1 : 0); }
template <class T> using vc = vector<T>;
template <class T> using vv = vc<vc<T>>;
template <class T> using vvv = vc<vv<T>>;
template <class T> using PQ = priority_queue<T, vc<T>, greater<T>>;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;
using ti3 = tuple<int, int, int>;
using tl3 = tuple<ll, ll, ll>;
using vi = vc<int>;
using vl = vc<ll>;
using vs = vc<string>;
using vpl = vc<pll>;
using vpd = vc<pdd>;
using vvi = vv<int>;
using vvl = vv<ll>;
using vvpl = vv<pll>;
const ld pi = 3.141592653589793;
const ll linf = 1001001001001001001LL;
const int inf = 1001001001;
int main() {
vvpl primeFact(1010101);
repr(i,2,1010101) {
if (primeFact[i].size() > 0) continue;
for (ll j = i; j < 1010101; j += i) {
if (j%(i*i) != 0) primeFact[j].eb(i, 1);
else primeFact[j].eb(i, 2);
}
}
ll L, R;
cin >> L >> R;
ll ans = (R-L+1)*(R-L)/2;
repr(i,max(2LL, L),R+1) ans -= R/i-(L-1)/i-1;
ll sum = (R-L+1)*(R-L)/2;
repr(i,2,R+1) {
vpl &pf = primeFact[i];
bool ok = true;
for (auto [p, a] : pf) if (a >= 2) ok = false;
if (ok) {
ll m = pf.size();
ll C = R/i-(L-1)/i;
sum -= C*(C-1)/2*(m%2 == 0 ? -1 : 1);
}
}
ans -= sum;
ans *= 2;
cout << ans << endl;
} |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,t,n) for(int64_t i=t;i<n;i++)
#define Sort(a) sort(a.begin(),a.end())
#define rSort(a,n,m) sort(a.begin()+n-1,a.begin()+m)
#define Reverse(a) reverse(a.begin(),a.end())
#define rReverse(a,n,m) reverse(a.begin()+n-1,a.begin()+m)
#define MOD 1000000007
#define sign(i) -1*pow(-1,i)
#define vi(A,N,i) vector<int64_t> A(N,i)
#define vs(A,N,i) vector<string> A(N,i)
#define vb(A,N,i) vector<bool> A(N,i)
#define INF ((1LL<<62)-(1LL<<31))
//((a+b+c)-max(a,max(b,c))-min(a,min(b,c)))
/*template <class T>
}*/
//cout << fixed << setprecision(桁数);
int64_t def_str(string x,string y){
int64_t def=0;
rep(i,0,(int64_t)x.size()){
if(x[i]!=y[i]){
def++;
}
}
return def;
}
int main() {
int64_t a,b,c,d,e,f,ans=0,now_ans=0,mlt_ans=1;
//double a,b,c,d,e,f,ans=0,now_ans=0,mlt_ans=1;
string x,y,z;
char s,t,u;
bool frag=false,frag1=false,frag2=false;
vector<int64_t> A{},B{};
vector<string> C{},D{};
vector<char> E{},F{};
vector<bool> G(26,false);
cin>>a>>b;
//cin>>x>>y;
//cin>>s>>t;////////////////////////
rep(i,0,a){
cin>>c>>d;
ans+=c*d;
if(ans>b*100){
cout<<i+1;
return 0;
}
}
cout<<-1;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
long long N,X;
cin>>N>>X;
long long total=0;
long long count=0;
bool jud=0;
for(long long a=0;a<N;a++){
long long v,p;
cin>>v>>p;
total+=v*p;
count++;
if(total>(100*X)){
jud=1;
break;
}
}
//cout<<total<<endl;
if(jud){
cout<<count;
}
else{
cout<<"-1";
}
}
|
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <deque>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <cassert>
#include <iostream>
#include <stdio.h>
#include <time.h>
using namespace std;
typedef long long ll;
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define MOD 1000000007
long long modpow(long long a, long long b){
long long r = 1LL;
while(b){
if(b & 1LL)r *= a;
if(r >= MOD)r %= MOD;
a *= a;
if(a >= MOD)a %= MOD;
b >>= 1LL;
}
return r%MOD;
}
ll d1[2010][2010];
ll d2[2010][2010];
ll d3[2010][2010];
ll d4[2010][2010];
int main(){
ll h,w;
cin>>h>>w;
vector<string> vs;
ll sp = 0;
rep(y,0,h){
string s;
cin>>s;
vs.pb(s);
}
// 1
rep(x,0,w){
ll c = 0;
rep(y,0,h){
if(vs[y][x]=='#'){
c=0;
}
else{
sp++;
d1[y][x]=c;
c++;
}
}
}
// 2
rep(x,0,w){
ll c = 0;
per(y,0,h){
if(vs[y][x]=='#'){
c=0;
}
else{
d2[y][x]=c;
c++;
}
}
}
// 3
rep(y,0,h){
ll c = 0;
rep(x,0,w){
if(vs[y][x]=='#'){
c=0;
}
else{
d3[y][x]=c;
c++;
}
}
}
// 4
rep(y,0,h){
ll c = 0;
per(x,0,w){
if(vs[y][x]=='#'){
c=0;
}
else{
d4[y][x]=c;
c++;
}
}
}
ll ans = 0;
rep(y,0,h){
rep(x,0,w){
if(vs[y][x]=='.'){
ll a = d1[y][x] + d2[y][x] + d3[y][x] + d4[y][x] + 1;
ll c = 1;
c *= modpow(2,sp-a);
c %= MOD;
c *= modpow(2,a)+MOD-1;
c %= MOD;
ans += c;
ans %= MOD;
}
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#include <chrono>
using namespace std;
using namespace chrono;
typedef long long int ll;
typedef vector<int> vii;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define pb push_back
#define odd(x) ((x)&1)
#define even(x) (!odd(x))
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(auto i=0;i<n;++i)
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define TEST_CASE int tc;cin>>tc;while(tc--)
#define Clock high_resolution_clock::now()
template<class T>
inline bool chmax(T &a, T b) {if(a < b) {a = b;return true;}return false;}
template<class T>
inline bool chmin(T &a, T b) {if(a > b) {a = b;return true;}return false;}
#ifdef LOCAL
#define cerr cout
#else
#endif
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
// #define TIME
/******************************************************************************************************************************/
const ll inf = 2e18;
const ll mod = 998244353;
const ll N = 2e3;
void prt(vll &v) {
cout << v.size() << " ";
for(auto i: v) cout << i << " ";
cout << "\n";
}
int main()
{
auto start_time = Clock;
FASTIO
ll n;
cin >> n;
vll v(n);
rep(i,n) cin >> v[i];
map<ll, vector<vll> > mp;
ll m = min(8ll,n);
rep(i,1<<m) {
if(!i) continue;
vll tmp;
ll sum = 0;
for(ll j=0;j<m;++j) {
if(i&(1<<j)) {
sum += v[j]; sum %= 200;
tmp.pb(j+1);
}
}
// cout << bitset<4>(i) << " " << sum << "\n";
mp[sum].pb(tmp);
}
for(auto p: mp) {
if(p.second.size()>1) {
cout << "Yes\n";
// trace(p.first);
prt(p.second[0]), prt(p.second[1]);
return 0;
}
}
cout << "No\n";
auto end_time = Clock;
#ifndef TIME
return 0;
#endif
cout << "\nTime elapsed: "
<< (double)duration_cast<milliseconds>(end_time-start_time).count()
<< "ms";
return 0;
} |
#include <bits/stdc++.h>
#define ll long long int
#define vec vector<ll>
#define vecp vector<pair<ll,ll> >
#define mapp map<ll,ll>
#define mapit map<ll,ll>::iterator
#define mapr map<pair<ll,ll>,ll>
#define maprit map<pair<ll,ll>,ll>::iterator
#define fs first
#define sc second
#define bg begin()
#define en end()
#define pb push_back
#define fin(x,y) for(x=0;x<y;x++)
#define fin1(x,y) for(x=1;x<y;x++)
#define mod1 1000000007
#define INF 1000000000000000000
#define twodp vector<vec >dp(n+1,vec(k+1,0))
#define all(x) x.bg,x.en
#define rel(x) x.rbegin(),x.rend()
using namespace std;
ll gcd(ll a,ll b)
{
if(a==0 || b==0)
return a+b;
else
return __gcd(a,b);
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
ll i,j,k,l,n;
string s;
cin>>s;
n=s.size();
bool p=true;
fin(i,n)
{
if(i%2==1)
{
if(s[i]>='a'&& s[i]<='z')
p=false;
}
else
{
if(s[i]>='A'&& s[i]<='Z')
p=false;
}
}
if(p)
cout<<"Yes";
else
cout<<"No";
return 0;
}
| #include <iostream>
#include <string>
#include <ctype.h>
using namespace std;
int main()
{
string input;
cin >> input;
bool isDifficult = true;
bool odd = true;
for ( const auto &c : input )
{
if ( odd ) { if( isupper( c ) ) { isDifficult = false; break; } }
else { if( islower( c ) ) { isDifficult = false; break; } }
odd = !odd;
}
cout << ( ( isDifficult ) ? "Yes" : "No" );
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using _lint = int;
#define REP(i, n) for (_lint i = 0; i < (_lint)(n); i++)
#define FOR(i, a, b) for (_lint i = (_lint)(a); i < (_lint)(b); i++)
#define FORR(i, a, b) for (_lint i = (_lint)(b)-1; i >= (_lint)(a); i--)
#define CHMIN(a, b) (a) = min((a), (b))
#define CHMAX(a, b) (a) = max((a), (b))
#define ALL(v) (v).begin(), (v).end()
#define DEBUG(x) cerr << #x << ": " << (x) << endl
#define DEBUG_VEC(v) \
{ \
cerr << #v << ": "; \
REP(__i, size(v)) cerr << ((v)[__i]) << ", "; \
cerr << endl; \
}
int n, m;
bool g[25][21];
bool ok[1 << 20];
ll f[1<<20][21];
ll f2[1<<20][21];
ll ff[1<<20];
int main() {
cin >> n >> m;
REP(i, m) {
int a, b;
cin >> a >> b;
a--;
b--;
g[a][b] = g[b][a] = true;
}
REP(mask, 1 << n) {
bool go = true;
REP(i, n) REP(j, i) {
if (mask >> i & 1) {
if (mask >> j & 1) {
if (g[i][j]) {
go = false;
}
}
}
}
ok[mask] = go;
}
// https://judge.yosupo.jp/submission/4085
REP(i,1<<n)f[i][__builtin_popcount(i)] = ok[i];
REP(k,n)REP(i,1<<n)if(((i>>k)&1)==0)REP(j,n+1)f[i|1<<k][j]+=f[i][j];
REP(i,1<<n)REP(j,n+1)f2[i][j] = f[i][j];
REP(i,1<<n)FORR(j,0,n+1){
FOR(k,1,n-j+1)f[i][j+k] += f[i][j] * f2[i][k];
f[i][j] *= f2[i][0];
}
REP(k,n)REP(i,1<<n)if(((i>>k)&1)==0)REP(j,n+1)f[i|1<<k][j]-=f[i][j];
REP(i,1<<n)ff[i]=f[i][__builtin_popcount(i)];
ll ans = 0;
REP(mask, 1 << n) if (ok[mask]) {
int ho = ~mask & ((1 << n) - 1);
ans += ff[ho];
}
cout << ans << endl;
return 0;
}
| // -------- START : snippet -------- //
#include <bits/stdc++.h>
using namespace std;
struct IoSetup {
IoSetup() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
cerr << fixed << setprecision(10);
}
} iosetup;
// -------- START : macro -------- //
#define ll long long
#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 len(c) (ll)c.size()
#define all(v) (v).begin(),(v).end()
#define lb(v,x) (lower_bound(all(v),x)-v.begin())
#define ub(v,x) (upper_bound(all(v),x)-v.begin())
#define has(c,x) (c.find(x) != c.end())
#define uniq(v) v.erase(unique(all(v)),v.end())
#define bit(k) (1LL<<(k))
#define INF int(1e9)
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// -------- END : macro -------- //
// -------- START : debug macro -------- //
template<class T,class U> ostream& operator<<(ostream& ost, const pair<T,U> &p) { ost << "(" << p.first << ", " << p.second << ")"; return ost; }
#define ostream_container { ost << "{"; for(const auto &t : v) { if (&t != &*v.begin()) ost << ", "; ost << t; } ost << "}"; return ost; }
template<class T> ostream& operator<<(ostream &ost, const vector<T> &v) ostream_container
template<class T> ostream& operator<<(ostream &ost, const set<T> &v) ostream_container
template<class T,class U> ostream& operator<<(ostream &ost, const map<T,U> &v) ostream_container
template<class H> void recursive_debug(string s, H h) {
cerr << "\033[33m" << s << " = " << h << endl << "\033[m";
}
template<class H,class... T> void recursive_debug(string s, H h, T... t) {
int comma = s.find(',');
cerr << "\033[33m" << s.substr(0,comma) << " = " << h << ", ";
recursive_debug(s.substr(comma+1), t...);
}
#define debug(...) recursive_debug(#__VA_ARGS__, __VA_ARGS__)
// -------- END : debug macro -------- //
// -------- END : snippet -------- //
template <typename T>
class SegmentTree{
public:
int n;
T element;
vector<T> dat;
function<T(T,T)> operate;
SegmentTree(){}
SegmentTree(int n_,T element_,function<T(T,T)> operate_){
element = element_;
operate = operate_;
n = 1;
while(n < n_) n *= 2;
dat = vector<T>(n*2,element);
}
void update(int k,T a){
k += n-1;
dat[k] = a;
while(k > 0){
k = (k-1)/2;
dat[k] = operate(dat[k*2+1],dat[k*2+2]);
}
}
T query(int a,int b,int k,int l,int r){
if(r<=a || b<=l) return element;
if(a<=l && r<=b) return dat[k];
T vl = query(a,b,k*2+1,l,(l+r)/2);
T vr = query(a,b,k*2+2,(l+r)/2,r);
return operate(vl,vr);
}
T query(int a,int b) { return query(a,b,0,0,n); }
T get(int k){ return query(k,k+1); }
};
int main(void) {
int N, Q;
cin >> N >> Q;
vector<ll> a(N);
SegmentTree<ll> seg(N, 0, [](ll x, ll y){ return x^y; });
rep(i,N) {
cin >> a[i];
seg.update(i, a[i]);
}
rep(q,Q) {
int t;
ll x,y;
cin >> t >> x >> y;
if (t == 1) {
x--;
seg.update(x, seg.get(x) ^ y);
} else {
x--;
cout << seg.query(x,y) << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
// Sieve of Eratosthenes
// https://youtu.be/UTVg7wzMWQc?t=2774
struct Sieve {
int n;
vector<int> f, primes;
Sieve(int n = 1) : n(n), f(n + 1) {
f[0] = f[1] = -1;
for (ll i = 2; i <= n; ++i) {
if (f[i]) continue;
primes.push_back(i);
f[i] = i;
for (ll j = i * i; j <= n; j += i) {
if (!f[j]) f[j] = i;
}
}
}
bool isPrime(int x) { return f[x] == x; }
vector<int> factorList(int x) {
vector<int> res;
while (x != 1) {
res.push_back(f[x]);
x /= f[x];
}
return res;
}
vector<P> factor(int x) {
vector<int> fl = factorList(x);
if (fl.size() == 0) return {};
vector<P> res(1, P(fl[0], 0));
for (int p : fl) {
if (res.back().first == p) {
res.back().second++;
} else {
res.emplace_back(p, 1);
}
}
return res;
}
vector<pair<ll, int>> factor(ll x) {
vector<pair<ll, int>> res;
for (int p : primes) {
int y = 0;
while (x % p == 0) x /= p, ++y;
if (y != 0) res.emplace_back(p, y);
}
if (x != 1) res.emplace_back(x, 1);
return res;
}
};
ll A, B;
unordered_map<ll, int> mp;
ll dp[1 << 20][74];
ll dfs(ll t, int mask) {
if (dp[mask][t - A] != 0) {
return dp[mask][t - A];
}
if (t > B) {
return dp[mask][t - A] = 1;
}
int tmask = mp[t];
ll retVal = 0;
// cerr << "tmask =" << tmask << "bit wise=" << bitset<20>(mask & tmask) << endl;
if ((mask & tmask) == 0) {
retVal += dfs(t + 1, mask | tmask);
}
retVal += dfs(t + 1, mask);
return dp[mask][t - A] = retVal;
}
void solve() {
Sieve sieve(72);
for (ll i = A; i <= B; i++) {
int mask = 0;
rep(j, sieve.primes.size()) {
if (i % sieve.primes[j] == 0) {
mask |= (1 << j);
}
}
// cerr << "i=" << i << " mask=" << mask << endl;
mp[i] = mask;
}
dfs(A, 0);
cout << dp[0][0] << endl;
}
// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)
int main() {
scanf("%lld", &A);
scanf("%lld", &B);
solve();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll =unsigned long long;
typedef pair<ll,ll> P;
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
#define For(i, a, b) for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n) For(i, 0, n)
#define debug(x) cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}
void mswap(ll &a, ll &b){ if(a >= b) swap(a,b); }
void rswap(ll &a, ll &b){ if(a <= b) swap(a,b); }
const int dy[] = {0,0,1,-1};
const int dx[] = {1,-1,0,0};
const ll mod = 1e9+7;
const ll MOD = 998244353;
const double PI=3.14159265358979323846;
const int inf = 1001001001;
const ll INF = 1e18;
//Write From this Line
int main()
{
int n;
cin >> n;
vector<int> a(n), b(n);
rep(i,n) cin >> a[i] >> b[i];
int ans = inf;
rep(i,n){
rep(j,n){
if(i == j){
chmin(ans, a[i] + b[j]);
}else{
chmin(ans, max(a[i],b[j]));
}
}
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using P = pair<int, int>;
using ll = long long;
int main(){
int n, m;
cin >> n >> m;
map<int, vector<int>> mp;
rep(i, m){
int x, y;
cin >> x >> y;
mp[x].push_back(y);
}
set<int> s;
s.insert(n);
for(auto p : mp){
vector<int> add;
for(int y : p.second){
if(s.count(y-1) || s.count(y+1)) add.push_back(y);
}
for(int y : p.second) s.erase(y);
for(int y : add) s.insert(y);
}
cout << s.size() << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define all(x) (x).begin(),(x).end() // 昇順ソート
#define rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define sz(x) ((int)(x).size())
typedef long long ll;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VP = vector<P>;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
const int inf = 1 << 30;
const ll INF = 1LL << 60;
const int mod = 1000000007;
struct mint {
ll x; // typedef long long ll;
mint(ll x=0):x((x%mod+mod)%mod){}
mint operator-() const { return mint(-x);}
mint& operator+=(const mint a) {
if ((x += a.x) >= mod) x -= mod;
return *this;
}
mint& operator-=(const mint a) {
if ((x += mod-a.x) >= mod) x -= mod;
return *this;
}
mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
mint operator+(const mint a) const { return mint(*this) += a;}
mint operator-(const mint a) const { return mint(*this) -= a;}
mint operator*(const mint a) const { return mint(*this) *= a;}
mint pow(ll t) const {
if (!t) return 1;
mint a = pow(t>>1);
a *= a;
if (t&1) a *= *this;
return a;
}
// for prime mod
mint inv() const { return pow(mod-2);}
mint& operator/=(const mint a) { return *this *= a.inv();}
mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
mint pow2[4000005];
int main(){
int h, w;
cin >> h >> w;
vector<string> s(h);
rep(i,h) cin >> s[i];
VVI l(h, VI(w)), r(h, VI(w)), u(h, VI(w)), d(h, VI(w));
rep(i, h) rep(j, w){
if (s[i][j] == '#') continue;
if (i != 0) u[i][j] += u[i-1][j];
if (j != 0) l[i][j] += l[i][j-1];
u[i][j] += 1;
l[i][j] += 1;
}
rrep(i, h) rrep(j, w){
if (s[i][j] == '#') continue;
if (i != h-1) d[i][j] += d[i+1][j];
if (j != w-1) r[i][j] += r[i][j+1];
d[i][j] += 1;
r[i][j] += 1;
}
ll cnt = 0;
rep(i,h) rep(j,w) if (s[i][j] == '.') cnt++;
pow2[0] = 1;
rep(i, 4000005) pow2[i+1] = pow2[i] * 2;
mint ans = 0;
rep(i,h) rep(j,w){
if (s[i][j] == '#') continue;
ll num = l[i][j] + r[i][j] + u[i][j] + d[i][j] - 3;
ans += (pow2[num] - 1) * pow2[cnt-num];
}
view(ans);
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
inline int read(){
int res=0;
char c;
bool zf=0;
while(((c=getchar())<'0'||c>'9')&&c!= '-');
if(c=='-')zf=1;
else res=c-'0';
while((c=getchar())>='0'&&c<='9')res=(res<<3)+(res<<1)+c-'0';
if(zf)return -res;
return res;
}
signed main(){
cout<<read()-read()+read();
return 0;
} | #include <iostream>
using namespace std;
int main() {
int N;
int A[4];
N = 4;
int ans;
for (int i = 0; i < N; i++) {
cin >> A[i];
}
for (int i = 0; i < N; i++) {
if (i == 0) {
ans = A[0];
}
else {
if (ans > A[i]) {
ans = A[i];
}
}
}
cout << ans << endl;
} |
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;
int main(){
int n;cin>>n;
for(int i=0;i<n;i++){
ll r,l;cin>>l>>r;
ll res=int(r-2*l);
if(res<0)cout<<0<<endl;
else {
res=(res+1)*(res+2)/2;
cout<<res<<endl;
}
}
return 0;
}
| // #define LOCAL
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,s,n) for (int i = (ll)s; i < (ll)n; i++)
#define rrep(i,n,e) for (int i = (ll)n; i > (ll)e; i--)
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
// #define M_PI 3.14159265358979323846 // CF
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) cout << fixed << setprecision(10) << x << endl; // print Decimal number 10 Rank
#define endl "\n"
#define Case(x) printf("Case #%d: ", x); // gcj
typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
typedef vector<PI> vpi;
typedef vector<vector<PI>> vvpi;
typedef vector<PLL> vpl;
typedef vector<vector<PLL>> vvpl;
typedef vector<char> vch;
typedef vector<vector<char>> vvch;
constexpr ll INF = 1001002003004005006ll;
constexpr int n_max = 2e5+10;
template<class T>
inline bool chmax(T &a, T b) { if(a<b) { a=b; return true; } return false; };
template<class T>
inline bool chmin(T &a, T b) { if(a>b) { a=b; return true; } return false; };
template<class T, class U>
T POW(T x, U n) {T ret=1; while (n>0) {if (n&1) {ret*=x;} x*=x; n>>=1;} return ret;};
// debug
template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';};
string to_string(const char c) {return to_string((string) &c);};
string to_string(bool b) {return (b ? "true" : "false");};
template <size_t N>
string to_string(bitset<N> v){
string res = "";
for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
return res;
};
template <typename A>
string to_string(A v) {
bool first = true;
string res = "{";
for(const auto &x : v) {
if(!first) res += ", ";
first = false; res += to_string(x);
}
res += "}";
return res;
};
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
void debug_out() {cerr << endl;};
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); };
void LINE_OUT() {
cout << "--------------" << endl;
};
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define LINE LINE_OUT();
#else
#define debug(...) 71
#define LINE 71;
#endif
void print() { cout << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
cout << head;
if (sizeof...(tail) != 0) cout << " ";
print(forward<Tail>(tail)...);
};
template <class T>
void print(vector<T> &vec) {
for (auto& a : vec) {
cout << a;
if (&a != &vec.back()) cout << " ";
}
cout << endl;
};
template <class T>
void print(vector<vector<T>> &df) {
for (auto& vec : df) {
print(vec);
}
};
void solve() {
int L, R; cin >> L >> R;
int alt = R-2*L+1;
if (alt <= 0) {
cout << 0 << endl;
} else {
cout << (alt+1)*alt/2 << endl;
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t; cin >> t;
while (t--) {
solve();
}
return 0;
};
|
#include<bits/stdc++.h>
using namespace std;
#define ll __int128
#define pll pair<ll,ll>
#define mp make_pair
#define fi first
#define se second
#define db double
#define pb push_back
#define N 1000000000
#define inf 10000000000000
char s[65];
ll len,mx,m;
inline ll ksm(ll a,ll b){ ll res=1;
for(;b;b>>=1,a=a*a){
if(b&1)res=res*a;
if(res>m)return -1;
}
return res;
}
inline ll read(){
ll f=0,s=0; char c=getchar();
while(c>'9'||c<'0')f=(c=='-'),c=getchar();
while(c>='0'&&c<='9')s=(s<<3)+(s<<1)+(c^'0'),c=getchar();
return f?-s:s;
}
inline void write(ll x)
{
if(x<0)
{
putchar('-');
x=-x;
}
if(x>9)
write(x/10);
putchar(x%10+'0');
}
inline ll check(ll x){ ll res=0;
for(int i=len;i>=1;i--){
ll tt=ksm(x,len-i);
if(tt!=-1)res+=(s[i]-'0')*tt; //write(res); cout<<endl;
else return 1e30;
}
return res;
}
int main(){
scanf("%s",s+1); len=strlen(s+1),mx=0; m=read();
for(int i=1;i<=len;i++)mx=max(mx,(ll)s[i]-'0');
if(len==1){
if(s[1]-'0'<=m)puts("1");
else puts("0");
return 0;
}
ll l=mx+1,r=m,mid,res=mx;
while(l<=r){
mid=(l+r)>>1; //write(l); putchar(' '); write(r); putchar(' '); write(mid); cout<<endl;
if(check(mid)<=m)l=mid+1,res=mid;
else r=mid-1;
}
write(res-mx);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
template<typename T>
struct counting_iterator: public iterator<random_access_iterator_tag, bool>{
T value = 0;
counting_iterator(const T &value): value(value){}
counting_iterator(const counting_iterator &it): value(it.value){}
counting_iterator(){}
typename iterator_traits<counting_iterator>::difference_type operator-(const counting_iterator &it) const{ return value - it.value; }
counting_iterator &operator++(){ return *this += 1; }
counting_iterator &operator--(){ return *this += -1; }
counting_iterator &operator+=(typename iterator_traits<counting_iterator>::difference_type n){ value += n; return *this; }
bool operator!=(const counting_iterator &it) const{ return value != it.value; }
T &operator*(){ return value; }
};
template<typename T>
using cnt_it = counting_iterator<T>;
int main(){
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(ios::badbit | ios::failbit);
string x;
long long m;
cin >> x >> m;
if((int)x.size() == 1){
cout << (x[0] - '0' <= m) << "\n";
return 0;
}
int d = *max_element(x.begin(), x.end()) - '0';
auto pred = [&](long long n){
long long cur = 0;
for(auto digit: x){
if(__builtin_mul_overflow_p(cur, n, 0LL) || __builtin_add_overflow_p(cur * n, digit - '0', 0LL)){
return false;
}
cur = cur * n + digit - '0';
}
return cur <= m;
};
cout << *partition_point(cnt_it<long long>(d + 1), cnt_it<long long>(numeric_limits<long long>::max()), pred) - d - 1 << "\n";
return 0;
}
/*
*/
////////////////////////////////////////////////////////////////////////////////////////
// //
// Coded by Aeren //
// //
//////////////////////////////////////////////////////////////////////////////////////// |
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
int n,m;
cin >> n >> m;
vector<vector<int>> g(n);
for(int i=0;i<m;++i){
int a,b;
cin >> a >> b;
a--;
b--;
g[a].push_back(b);
}
ll ans=0;
for(int i=0;i<n;++i){
vector<int> dist(n,-1);
queue<int> que;
dist[i]=0;
que.push(i);
while(!que.empty()){
int v=que.front();
que.pop();
ans++;
for(int nv : g[v]){
if(dist[nv]!=-1)continue;
dist[nv]=dist[v]+1;
que.push(nv);
}
}
}
cout << ans << endl;
return 0;
}
| //#include <atcoder/all>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#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++)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;
int main()
{
int N, M;
cin >> N >> M;
vector<int> A(N);
rep(i, N)
{
cin >> A[i];
}
multiset<int> st;
unordered_map<int, int> mp;
for (int i = 0; i <= N; i++) {
st.insert(i);
mp[i]++;
}
int res = INF_32;
int right = 0;
int size = 0;
for (int left = 0; left < N; left++) {
while (right < N && size < M) {
if (st.find(A[right]) != st.end()) {
st.erase(st.find(A[right]));
}
mp[A[right]]--;
size++;
right++;
}
res = min(res, *st.begin());
if (right == N)
break;
if (left == right)
right++;
else {
if (mp[A[left]] == 0) // 足りないのはあと一個
st.insert(A[left]);
mp[A[left]]++;
size--;
}
}
cout << res << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;
template<int M>
class ModInt {
public:
ll value;
constexpr ModInt(ll v = 0) { value = v % M; if (value < 0) value += M; }
constexpr ModInt pow(ll n) const { if (!n) return 1; ModInt a = pow(n >> 1); a *= a; if (n & 1) a *= *this; return a; }
constexpr ModInt inv() const { return this->pow(M - 2); }
constexpr ModInt operator + (const ModInt &rhs) const { return ModInt(*this) += rhs; };
constexpr ModInt operator - (const ModInt &rhs) const { return ModInt(*this) -= rhs; };
constexpr ModInt operator * (const ModInt &rhs) const { return ModInt(*this) *= rhs; };
constexpr ModInt operator / (const ModInt &rhs) const { return ModInt(*this) /= rhs; };
constexpr ModInt &operator += (const ModInt &rhs) { value += rhs.value; if (value >= M) value -= M; return *this; };
constexpr ModInt &operator -= (const ModInt &rhs) { value -= rhs.value; if (value < 0) value += M; return *this; };
constexpr ModInt &operator *= (const ModInt &rhs) { value = value * rhs.value % M; return *this; };
constexpr ModInt &operator /= (const ModInt &rhs) { return (*this) *= rhs.inv(); };
constexpr bool operator == (const ModInt &rhs) { return value == rhs.value; }
constexpr bool operator != (const ModInt &rhs) { return value != rhs.value; }
friend ostream &operator << (ostream &os, const ModInt &rhs) { os << rhs.value; return os; }
};
using mint = ModInt<MOD>;
int main() {
int N, M; cin >> N >> M;
vector<int> A(N); REP(i, 0, N) cin >> A[i];
ll S = accumulate(ALL(A), 0LL);
mint ans = 1;
REP(i, 0, N + S) {
ans *= (N + M - i);
ans /= (N + S - i);
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned int;
using ull = unsigned long long;
#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 per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define all(c) c.begin(),c.end()
#define si(x) int(x.size())
#define pb emplace_back
#define fs first
#define sc second
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
template<class T,class U> void chmax(T& x, U y){if(x<y) x=y;}
template<class T,class U> void chmin(T& x, U y){if(y<x) x=y;}
template<class T> void mkuni(V<T>& v){sort(all(v));v.erase(unique(all(v)),v.end());}
template<class T> int lwb(const V<T>& v, const T& a){return lower_bound(all(v),a) - v.begin();}
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
o<<"{";
for(const T& v:vc) o<<v<<",";
o<<"}";
return o;
}
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }
#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
void dmpr(ostream& os){os<<endl;}
template<class T,class... Args>
void dmpr(ostream&os,const T&t,const Args&... args){
os<<t<<" ~ ";
dmpr(os,args...);
}
#define shows(...) cerr << "LINE" << __LINE__ << " : ";dmpr(cerr,##__VA_ARGS__)
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {"; \
for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) void(0)
#define dump(x) void(0)
#define shows(...) void(0)
#endif
int main(){
cin.tie(0);
ios::sync_with_stdio(false); //DON'T USE scanf/printf/puts !!
cout << fixed << setprecision(20);
int N;
double D,H;
cin >> N >> D >> H;
double ans = 0;
while(N--){
double d,h; cin >> d >> h;
chmax(ans,h-(H-h)/(D-d)*d);
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n) for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif
// $ cp-batch VillageOfMPeople | diff VillageOfMPeople.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address VillageOfMPeople.cpp && ./a.out
/*
5/9/2021
23:18-23:48 give up
5/10/2021
22:20-22:33 WA
*/
const int MAX_K=1e6+1;
LL A[MAX_K];
LL K,N,M;
VV<LL> build(LL d) {
VV<LL> B(2,vector<LL>(K));
REP(i,K) {
LL minb=(M*A[i]-d+N-1)/N;
LL maxb=(M*A[i]+d)/N;
B[0][i]=minb,B[1][i]=maxb;
}
return B;
}
bool ok(LL d) {
VV<LL> B=build(d);
LL minm=0,maxm=0;
REP(i,K) minm+=B[0][i],maxm+=B[1][i];
return minm<=M&&M<=maxm;
}
void solve() {
LL good=2e18,bad=-1;
while(abs(good-bad)>1) {
LL m=(good+bad)/2;
(ok(m)?good:bad)=m;
}
auto B=build(good);
vector<LL> res=B[0];
LL sum=accumulate(ALL(B[0]),0LL);
assert(sum<=M);
LL rem=M-sum;
REP(i,K) {
while(rem>0&&res[i]<B[1][i]) res[i]++,--rem;
}
assert(accumulate(ALL(res),0LL)==M);
REP(i,K) cout<<res[i]<<" ";
cout<<endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout<<setprecision(12)<<fixed;
cin>>K>>N>>M;
REP(i,K) cin>>A[i];
solve();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define deb(x) cout<< #x << " " << x << "\n";
#define MAX 9223372036854775807
#define MIN -9223372036854775807
#define setbits(n) __builtin_popcountll(n)
#define mkunique(a) sort(a.begin(),a.end()); a.resize(unique(a.begin(),a.end())-a.begin());
#define print(s) for(ll u: s) cout<<u<<" "; cout<<"\n";
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod=1e9+7;
ll n;
vector<ll> a;
long double getexp(long double x){
long double sum=0;
for(ll i=0;i<n;i++){
sum = sum + x + (long double)a[i] - min((long double)a[i],x*2);
}
sum/=n;
return sum;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll TT=clock();
cin>>n;
a.assign(n,0);
for(ll i=0;i<n;i++)
cin>>a[i];
long double l=0, r=2e9;
for(ll i=0;i<100;i++){
long double m1 = l + (r-l)/3;
long double m2 = l + 2*(r-l)/3;
if(getexp(m1)>getexp(m2))
l = m1;
else
r = m2;
}
cout<<fixed<<setprecision(10);
cout<<getexp(l);
cerr<<"\n\nTIME: "<<(long double)(clock()-TT)/CLOCKS_PER_SEC<<" sec\n";
TT = clock();
return 0;
} |
// Link to the Problem
// https://atcoder.jp/contests/abc197/tasks/abc197_a
/*
飲んだ魔剤で家が建つ。
created at: 2021-04-11 19:20:49
cleared at:
*/
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF 1000000000
long long rtceil (long long x) {
long long i;
for (i = 1; x > 0; i++) {
x -= i*2 + 1;
}
return i - 1;
}
int main()
{
string s;
cin >> s;
s = (s + s[0]).substr(1);
cout << s << endl;
return 0;
}
|
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
#include <functional>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<PII> VPI;
typedef vector<PLL> VPL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<(n);i++)
#define rep2(i,n,m) for(ll i=n;i<(m);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound
#define fi first
#define se second
void YES(int a){
if(a) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
void Yes(int a){
if(a) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
//#include <atcoder/all>
//using namespace atcoder;
//typedef modint998244353 mint;
int main(){
string S;
cin>>S;
cout<<S.substr(1,2)<<S[0]<<endl;
}
|
#include <bits/stdc++.h>
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define endl '\n'
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int INF = 0x3f3f3f3f;
const ll INFLL = 0x3f3f3f3f3f3f3f3fLL;
const int MOD = 1000000007;
const int dx[] = { 0, 0, -1, 1, 1, -1, 1, -1};
const int dy[] = {-1, 1, 0, 0, 1, -1, -1, 1};
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
ll n;
cin >> n;
n = 2*n;
auto cnt = [&](ll x){
ll aux = n/x;
aux -= x-1;
return aux%2 == 0;
};
ll ans = 0;
for(ll d=1; d<=n/d; d++){
if(n%d == 0){
ans += cnt(d);
if(d*d != n)
ans += cnt(n/d);
}
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
template <class T = ll> using P = pair<T,T>;
template <class T = ll> using V = vector<T>;
template <class T = ll> using VV = V<V<T>>;
#define rep(i,n) for(int i=0; i<(n);++i)
#define repp(i, l, r) for(int i = (l); i < (r); ++i)
#define pb push_back
#define all(v) (v).begin(), (v).end()
// xのどれかにyを含むか
bool contain(int x, int y){
if(x%10 == y) return true;
else if((x/10)%10 == y) return true;
else if((x/100)%10 == y) return true;
else if((x/1000)%10 == y) return true;
else return false;
}
int main()
{
string s;
cin >> s;
int v[10] = {};
rep(i, 10){
if(s[i] == 'o'){
v[i] = 0;
}else if(s[i] == 'x'){
v[i] = 1;
}else{
v[i] = 2;
}
}
ll ans = 0;
rep(i, 10000){
bool ok = true;
rep(j, 10){
if(v[j] == 0){
ok &= contain(i, j);
}
else if(v[j] == 1){
ok &= !contain(i, j);
}
}
if(ok) ans++;
}
cout << ans << endl;
return 0;
} |
/**
* Author: Sohel Rana
* Date: 2020-10-24 23:02:29
* Task: B_Various_distances
**/
#include <bits/stdc++.h>
#define endl '\n'
#define db double
#define ld long double
#define ll long long
#define ull unsigned long long
#define sqr(x) (x) * (x)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a/gcd(a,b)) * b)
#define pf(x) push_front(x)
#define pb(x) push_back(x)
#define eb(x) emplace_back(x)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)x.size()
#define debug(x) cerr << #x << " = " << (x) << endl
#define debug2(x,y) cerr << #x << " = " << (x)<< "," << #y << " = " <<(y)<< endl
#define unsyncIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
const ld PI = acos((ld)-1);
const int MOD = 1e9+7;
const ll INF = 1e18;
using namespace std;
int main()
{
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
//unsyncIO;
int n, mx = 0;
ull Manhattan = 0;
ld euclidian = 0;
cin >> n;
for (int i = 0; i < n; i++) {
ll temp;
cin >> temp;
if (temp < 0) temp = temp * -1;
if ((temp) > mx)
mx = (temp);
Manhattan += (temp);
euclidian += sqr(temp);
}
cout << Manhattan << endl;
//ld euc = sqrt(euclidian);
printf("%0.15Lf\n",sqrt(euclidian));
//cout << sqrt(euclidian << endl;
cout << mx << endl;
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
#define res register int
#define ll long long
//#define cccgift
#define lowbit(x) ((x)&-(x))
#define rep(i,l,r) for(res i=l,_r=r;i<=_r;++i)
#define per(i,r,l) for(res i=r,_l=l;i>=_l;--i)
#define mkp make_pair
#define pb push_back
#define mem0(a) memset(a,0,sizeof(a))
#define mem0n(a,n) memset(a,0,n*sizeof(a[0]))
#define iter(x,v) for(res v,_p=head[x];v=ver[_p],_p;_p=nxt[_p])
#ifdef cccgift //by lqh
#define SHOW(x) cerr<<#x"="<<(x)<<endl
#else
#define SHOW(x) 0
#endif
//#define getchar()(ip1==ip2&&(ip2=(ip1=ibuf)+fread(ibuf,1,1<<21,stdin),ip1==ip2)?EOF:*ip1++)
//char ibuf[1<<21],*ip1=ibuf,*ip2=ibuf;
template<typename T>
inline void read(T &x)
{
static char ch;bool f=1;
for(x=0,ch=getchar();!isdigit(ch);ch=getchar()) if(ch=='-') f=0;
for(;isdigit(ch);x=(x<<1)+(x<<3)+(ch^48),ch=getchar());x=f?x:-x;
}
template<typename T>
void print(T x)
{
if (x<0) x=-x,putchar('-');
if (x>9) print(x/10);
putchar(x%10+48);
}
template<typename T>
inline void print(T x,char ap) {print(x);if (ap) putchar(ap);}
template<typename T>
inline void chkmax(T &x,const T &y) {x=x<y?y:x;}
template<typename T>
inline void chkmin(T &x,const T &y) {x=x<y?x:y;}
int n,k;
char s[201];
inline char doit(char ch1,char ch2) {
if(ch1==ch2) return ch1;
if(ch1>ch2) swap(ch1,ch2);
if(ch1=='P'&&ch2=='R') return 'P';
if(ch1=='P'&&ch2=='S') return 'S';
return 'R';
}
int main()
{
read(n),read(k),scanf("%s",s+1);
rep(i,1,k) {
if(n&1) {
rep(i,n+1,n+n) s[i]=s[i-n];
n*=2;
}int len=0;
for(res j=1;j<=n;j+=2) s[++len]=doit(s[j],s[j+1]);
n=len;
}
putchar(s[1]),puts("");
return 0;
}
/* stuff you should look for
* int overflow, array bounds
* special cases (n=1?), set tle
* do something instead of nothing and stay organized
*/
|
#include <iostream>
#include <vector>
#include <string>
#include <array>
#include <functional>
#include <algorithm>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <queue>
#include <bitset>
#include <cassert>
#include <math.h>
#include <complex>
#include <iomanip>
#include <unordered_map>
using namespace std;
#define ll long long
#define pb(x) push_back(x)
template<typename T1>
void dbg_pr(vector<T1> V, int add = 0, int start = -1, int end = -1) {
cout << "{";
if (start < 0) start = 0;
if (end < 0) end = V.size() - 1;
for (int i = start; i <= end; i++) {
cout << V[i] + add << ((i == end) ? "}" : " ");
}
}
void dbg_pr(string V) {cout << "\"" << V << "\"";}
template<typename T1>
void dbg_pr(T1 V) {cout << V;}
template<typename T1, typename T2>
void dbg_pr(map<T1, T2> M) {
cout << "{";
for(const auto m : M) {
dbg_pr(m.first);
cout << ":";
dbg_pr(m.second);
cout << ",";
}
cout << "}";
}
#ifdef _OLIMPOLOCAL
#define dbg(...) cerr << "\033[1;36m[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define dbg(...) 1337
#endif
void debug_out() { cout << "\033[0m\n";}
template<typename T1, typename... T2> void debug_out(T1 A, T2... B) { cout << " "; dbg_pr(A); debug_out(B...); }
int test = 1;
#define out(x) {cout << x << "\n";return;}
#define all(N) N.begin(),N.end()
#define allr(N) N.rbegin(),N.rend()
void setupFastCin() {ios::sync_with_stdio(false);cin.tie(0);}
template<typename T1>
T1 chmin(T1 &x, const T1 v) { return x = min(x,v); }
template<typename T1>
T1 chmax(T1 &x, const T1 v) { return x = max(x,v); }
template<typename T1>
void pr(vector<T1> V, int add = 0, int start = -1, int end = -1) {
if (start < 0) start = 0;
if (end < 0) end = V.size() - 1;
for (int i = start; i <= end; i++) {
cout << V[i] + add << ((i == end) ? "\n" : " ");
}
}
#define rep(i, n) for (int i = 0; i < n; i++)
#define reps(i, s, n) for (int i = s; i < n; i++)
#define repr(i, n) for (int i = n-1; i >= 0; i--)
#define repsr(i, s, n) for (int i = n-1; i >= s; i--)
#define PI pair<int,int>
#define PLL pair<ll, ll>
template<typename T1>
T1 gcd(const T1 &a, const T1 &b) {
if (a == 0 || b == 0) return a + b;
return gcd(b, a %b);
}
//-------------------------- ^ DONT TOUCH ^-----------------------------------------------------------------
#define MAX 1000000
#define MAXP 21
//#define MOD 998244353ll
#define MOD 1000000007ll
long long power(long long x, long long n) {
long long p = x;
long long s = 1;
while (n > 0) {
if (n & 1) s = (s * p) % MOD;
p = (p * p) % MOD;
n /= 2;
}
return s;
}
int n;
ll N[MAX];
double val(double x) {
double s = -x;
rep(i,n) {
s += min((double)N[i], 2 * x) / n;
}
//dbg(x, s);
return s;
}
void solve() {
cin >> n;
double s = 0;
double hi = 0;
double lo = 0;
rep(i,n) {
cin >> N[i];
s -= N[i];
chmax(hi, N[i] * 2.0 + 1);
}
rep(kk, 100) {
double sz = (hi - lo) / 3;
double m1 = lo + sz;
double m2 = hi - sz;
if (val(m1) < val(m2)) lo = m1;
else hi = m2;
}
double ans = s / n + val(lo);
printf("%.10lf\n", -ans);
}
int main() {
setupFastCin();
int T = 1;
#ifdef _OLIMPOLOCAL
cin >> T;
#endif
reps(t, 1, T + 1){
solve();
}
return 0;
} | #include <bits/stdc++.h>
#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif
#if __cplusplus <= 201402L
template <typename T>
T gcd(T a, T b) { return ((a % b == 0) ? b : gcd(b, a % b)); }
template <typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }
#endif
using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;
namespace Problem {
using namespace std;
class Solver {
public:
int n;
vector<double> a;
Solver(LL n) : n(n), a(n){};
void solve() {
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
sort(a.begin(), a.end());
double x = a[n / 2] / 2;
double ans = 0;
for (int i = 0; i < n; ++i) {
ans += x + a[i] - min(a[i], 2.0 * x);
}
cout << ans / n << endl;
}
};
} // namespace Problem
int main() {
std::cin.tie(0);
std::ios_base::sync_with_stdio(false);
std::cout << std::fixed << std::setprecision(12);
long long n = 0;
std::cin >> n;
Problem::Solver sol(n);
sol.solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl "\n"
#define all(v) begin(v),end(v)
#define pb push_back
#define fr first
#define sc second
#define si(s) (int)s.size()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define pi 3.1415926536
#define dig(a) fixed<<setprecision(a)
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
const int M = 1e9+7;
const int N = 1e5+5;
ll power(ll a, ll n) {
ll res = 1;
while (n) {
if (n % 2) {res = (res * a) % M;}
n >>= 1; a = (a * a) % M;}
return res;
}
void solve(){
int n;
cin>>n;
vector<ll> a(n);
for(auto &x:a){
cin>>x;
}
ll ma = INT_MIN;
for(int i=0;i<n;i++){
ll s = a[i];
for(int j=i-1;j>=0;j--){
if(a[i]<=a[j]){
s+=a[i];
}
else{
break;
}
}
for(int j=i+1;j<n;j++){
if(a[i]<=a[j]){
s+=a[i];
}
else{
break;
}
}
ma = max(ma,s);
}
cout<<ma;
}
int main(){
fast;
// #ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
// #endif
int tc=1; //cin>>tc;
while(tc--){
solve();
}
return 0;
}
| #include <bits/stdc++.h>
#define PRINT(x) cerr<<#x<<'='<<x<<endl
#define NL(x) " \n"[(x)]
#define sz(x) int((x).size())
#define all(x) begin(x),end(x)
#define mid (l+r)/2
#define fi first
#define se second
#define pb push_back
#define endl '\n'
#define lld long long
#define pii pair<int,int>
#define pli pair<lld,int>
#define pil pair<int,lld>
#define pll pair<lld,lld>
#define INF 1000000000
#define LINF 1000000000000000000LL
#define EPS 1e-9
using namespace std;
#define MAXN 10010
lld A[MAXN];
int main() {
ios::sync_with_stdio(false); cin.tie(0);
int N; cin >> N;
for(int i = 1; i <= N; i++) cin >> A[i];
long long rez = 0;
for(int i = 1; i <= N; i++) {
lld minn = INF;
for(int j = i; j <= N; j++) {
minn = min(minn, A[j]);
rez = max(rez, minn*(j-i+1));
}
}
cout << rez;
return 0;
}
|
/*input
10
6 7 5 18 2
3 8 1 6 3
7 2 8 7 7
6 3 3 4 7
12 8 9 15 9
9 8 6 1 10
12 9 7 8 2
10 3 17 4 10
3 1 3 19 3
3 14 7 13 1
*/
#include <bits/stdc++.h>
#define pb push_back
#define x first
#define y second
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
#define rd() abs((int)rng())
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
const int maxn = 2e5 + 10;
const int mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n;
vector<vector<int> >v;
int get(int msk, int i) {
int mn = mod;
for (int bit = 0; bit < 5; bit++) {
if (msk >> bit & 1) {
mn = min(mn, v[i][bit]);
}
}
return mn;
}
int main()
{
ios_base::sync_with_stdio(false), cin.tie(0);
cin >> n;
vector<int>best(1 << 5, -1);
for (int i = 0; i < n; i++) {
vector<int>cand;
for (int j = 0; j < 5; j++) {
int a;
cin >> a;
cand.pb(a);
}
v.pb(cand);
for (int msk = 0; msk < 1 << 5; msk++) {
if (best[msk] == -1) {
best[msk] = i;
} else if (get(msk, i) > get(msk, best[msk])) {
best[msk] = i;
}
}
}
int ans = 0;
for (int a = 0; a < 1 << 5; a++) {
for (int b = a; b >= 0; b = (b - 1) & a) {
int msk1 = b;
int msk2 = a ^ b;
int msk3 = ((1 << 5) - 1) ^ a;
vector<int>mx(5);
for (int idx : {best[msk1], best[msk2], best[msk3]}) {
for (int i = 0; i < 5; i++) {
mx[i] = max(mx[i], v[idx][i]);
}
}
int mn = mod;
for (int i = 0; i < 5; i++) {
mn = min(mn, mx[i]);
}
ans = max(ans, mn);
if (b == 0) {
break;
}
}
}
cout << ans << "\n";
return 0;
} | #include<bits/stdc++.h>
#define DONTSYNC ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) //dont use stdio with iostream functions //input and output are out of order now!
#define TEST unsigned long long T; cin>>T; while(T--) //loop over each testcase
#define endl "\n"
#define fori(a,start,end) for(int a=start;a<end;a++)
#define forll(a,start,end) for(long long a=start;a<end;a++)
#define forull(a,start,end) for(unsigned long long a=start;a<end;a++)
typedef long long ll;
typedef unsigned long long ull;
#define pii pair<int,int>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pll pair<ll,ll>
#define fi first
#define se second
using namespace std;
void solve(){
/* code */
int n; cin>>n;
vector<vector<int>> mat(n,vector<int>(n));
int mini=0,minj=0;
fori(i,0,n){
fori(j,0,n){
cin>>mat[i][j];
if(mat[i][j]<mat[mini][minj]) mini=i,minj=j;
}
}
vector<int> B(n);
vector<int> A(n);
fori(i,0,n){
if(!i) B[i]=0;
else{
B[i]=mat[0][i]-mat[0][0];
}
if(!i) A[i]=0;
else{
A[i]=mat[i][0]-mat[0][0];
}
}
fori(i,1,n){
fori(j,1,n){
if(B[j]!=mat[i][j]-mat[i][0])
{cout<<"No"<<endl;return;}
if(A[i]!=mat[i][j]-mat[0][j])
{cout<<"No"<<endl;return;}
}
}cout<<"Yes"<<endl;
fori(i,0,n){
cout<<A[i]-A[mini]<<' ';
} cout<<endl;
fori(i,0,n){
cout<<B[i]-B[minj]+mat[mini][minj]<<' ';
} cout<<endl;
}
int main()
{
DONTSYNC;
// TEST
solve();
return 0;
}
|
#include <iostream>
#include <string>
#include <algorithm>
int main()
{
std::string input;
std::cin >> input;
std::reverse(input.begin(), input.end());
for(int i = 0; i < input.length(); ++i)
{
if(input.at(i) == '6')
input.at(i) = '9';
else if(input.at(i) == '9')
input.at(i) = '6';
}
std::cout << input << std::endl;
return 0;
} | #include <bits/stdc++.h>
#define MOD 998244353
using namespace std;
typedef long long LL;
int main(){
long long i,j,k,l,m,n,t;
char a[300010];
cin>>n;
getchar();
for(i=0;i<n;i++) {
a[i]=getchar();
}
if (a[0]!=a[n-1]) {
cout<<1;
return 0;
}
for(i=1;i<n-1;i++) {
if (a[i]!=a[0]&&a[i+1]!=a[0]) {
cout<<2;
return 0;
}
}
cout<<-1;
return 0;
} |
// {{{ by unolight
#include <bits/stdc++.h>
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-function"
#define SZ(x) ((int)(x).size())
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP1(i,a,b) for (int i = a; i <= (int)(b); i++)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;
namespace { namespace unolight {
#ifdef UNOLIGHT
#include "dump.hpp"
#else
#define dump(...)
#endif
template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template <class T, class F = less<T>>
void sort_uniq(vector<T> &v, F f = F()) {
sort(begin(v), end(v), f);
v.resize(unique(begin(v), end(v)) - begin(v));
}
// }}}
void main() {
int n,m;
cin >> n >> m;
if ( m<0||(n==1 && m==1 )||(n>1 && m>n-2) ) {
cout << -1 << '\n';
return;
}
if ( n==1 ) {
cout << 1 << ' ' << 2 << '\n';
return;
}
int l=1, r=2*(m+1)+2;
vector<PII> ans;
ans.emplace_back(l,r);
for ( int i=0; i<=m; i++ ) {
int a=l+i*2+1;
int b=a+1;
ans.emplace_back(a,b);
}
int a=r+1;
for ( int i=m+2; i<n; i++ ) {
ans.emplace_back(a,a+1);
a+=2;
}
for ( auto [i,j]:ans ) {
cout << i << ' ' << j << '\n';
}
}
// {{{ main
}}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
unolight::main();
return 0;
}
// }}} | #include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp> // #include<ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp> //#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds; //using namespace __gnu_pbds;
#define pb push_back
#define ins insert
#define var auto
#define F first
#define S second
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
template <class T> using oset = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
const int Max = 4e5 + 10;
const int LOG = 30;
const int Mod = 1e9 + 7;
const int SQ = 3000;
const int INF = 1e9 + 10;
const int BMSK = 4e6;
ll pw(ll a , int b = Mod - 2)
{
if(b == 0) return 1;
ll half = pw(a , b / 2);
if(b % 2) return half * half % Mod * a % Mod;
return half * half % Mod;
}
void solve()
{
int n , m;cin >> n >> m;
if(n == 1 && m == 0)
{
cout << 1 << " " << 2 << '\n';
return;
}
if(m < 0 || m >= n - 1)
{
cout << -1 << '\n';
return;
}
for(int i = 0 ; i < n - 1 ; i++)
cout << 3 * i + 2 << " " << 3 * i + 1 + 2 << '\n';
cout << -1 + 2 << " " << 3 * m + 2 + 2 << '\n';
}
int32_t main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
// int t;cin >> t;
// while(t--)
solve();
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int sz = 105;
int dp[sz][sz][sz], ara[sz], a[sz], bm;
int fnc(int n, int k, int m) {
if(!n) return 0;
int &w = dp[n][k][m];
if(w < 0) {
w = fnc(n - 1, k, m);
if(k == 1) {
if(a[n] == m) w = max(w, ara[n]);
}
else {
int y = (m - a[n] + bm) % bm;
int z = fnc(n - 1, k - 1, y);
if(z) w = max(w, ara[n] + z);
}
}
return w;
}
int main() {
int n; ll x;
cin >> n >> x;
for(int i=1; i<=n; i++) scanf("%d", &ara[i]);
ll ans = LLONG_MAX;
for(int k=1; k<=n; k++) {
for(int i=1; i<=n; i++) a[i] = ara[i] % k;
memset(dp, -1, sizeof(dp));
bm = k;
int now = fnc(n, k, x % k);
if(now) ans = min(ans, (x - now) / k);
}
cout << ans;
}
| #include<bits/stdc++.h>
#define forn(i,s,t) for(register int i=(s);i<=(t);++i)
#define form(i,s,t) for(register int i=(s);i>=(t);--i)
using namespace std;
typedef long long LL;
const int N = 1e2+3;
const LL INF = 2e18;
template<typename T>inline T Max(T A, T B) {return A>B?A:B;}
template<typename T>inline T Min(T A, T B) {return A<B?A:B;}
LL a[N], f[N][N], X, Ans; int n;
int main() {
scanf("%d%lld", &n, &X);
forn(i,1,n) scanf("%lld", a+i);
Ans = INF;
forn(i,1,n) {
forn(j,1,n) form(k,i-1,0) f[j][k] = -1;
f[0][0] = 0;
forn(j,1,n) form(k,i,0) forn(l,0,i-1) if(f[k][l] != -1) {
LL tmp = f[k][l] + a[j];
f[k+1][tmp % i] = Max(f[k+1][tmp % i], tmp);
}
if(f[i][X % i] != -1) Ans = Min(Ans, (X - f[i][X % i]) / i);
}
printf("%lld\n", Ans);
return 0;
} |
/*
"An anomaly, I'm Muhammad Ali
Cause I know one day I'm gonna be the"
- Greatest, Eminem
*/
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long int ll;
#define ff first
#define Shazam ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ss second
#define all(c) c.begin(),c.end()
#define endl "\n"
#define test() int t; cin>>t; while(t--)
#define fl(i,a,b) for(int i = a ; i <b ;i++)
#define get(a) fl(i,0,a.size()) cin>>a[i];
#define pra(a) fl(i,0,a.size()) cout<<a[i]<<" "; cout<<endl;
#define pr(a,n) fl(i,0,n) cout<<a[i]<<" "; cout<<endl;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const ll INF = 2e18;
const int inf = 2e9;
const int mod1 = 1e9 + 7;
int main(){
Shazam;
string s; cin >> s;
while(s.size() && s.back() == '0') s.pop_back();
for(int i = 0; i < s.size() / 2 ; i++){
if(s[i] == s[s.size() - 1 - i]) continue;
cout << "No" << endl;
return 0;
}
cout << "Yes" << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
char s[N],t[N],f[]=" atcoder";
int main() {
int T;
scanf("%d", &T);
while (T--) {
scanf("%s", s+1);
int n = strlen(s+1);
int ook = 0;
for (int i=1; i<=min(n,7); ++i) {
if (s[i]>f[i]) {
ook = 1;
break;
}
if (s[i]<f[i]) {
ook = -1;
break;
}
}
if (ook==1||ook==0&&n>7) {
puts("0");
continue;
}
for (int i=1; i<=n; ++i) t[i] = s[i];
sort(t+1,t+1+n,greater<char>());
int ok = 0;
for (int i=1; i<=min(n,7); ++i) {
if (t[i]>f[i]) {
ok = 1;
break;
}
if (t[i]<f[i]) {
ok = -1;
break;
}
}
if (ok==-1||ok==0&&n<7) puts("-1");
else {
int ans = 1e9;
for (int i=1; i<=n; ++i) if (s[i]>'a') {
ans = min(ans, abs(i-1));
}
for (int i=1; i<=n; ++i) if (s[i]>'t') {
ans = min(ans, abs(i-2));
}
printf("%d\n", ans);
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0; i<n; i++)
int main(){
int A,B,C;
cin >> A >> B >> C;
if(C%2==0){
if(abs(A)>abs(B)) cout << ">" << endl;
else if(abs(A)<abs(B)) cout << "<" << endl;
else cout << "=" << endl;
}else{
if(A>B) cout << ">" << endl;
else if(A<B) cout << "<" << endl;
else cout << "=" << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
// clang-format off
using LL = long long;
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
const int fx[]={+1,-1,+0,+0};
const int fy[]={+0,+0,+1,-1};
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
// clang-format on
void solve(long long A, long long B, long long C) {
// solver code
if (A >= 0 && B >= 0) {
if (A < B) {
std::cout << "<" << std::endl;
} else if (A > B) {
std::cout << ">" << std::endl;
} else {
std::cout << "=" << std::endl;
}
return;
}
// std::cout << 1 << std::endl;
// if(A==0 || B==0){
// if(A==B){
// std::cout << "=" << std::endl;
// }else if(A<B){
// std::cout << "<" << std::endl;
// }else{
// std::cout << ">" << std::endl;
// }
// return;
// }
//
// std::cout << 2 << std::endl;
// if(A<0){
// if(B>0){
// if(C%2==0){
// if(abs(A)<abs(B)){
// std::cout << "<" << std::endl;
// }else if(abs(A)>abs(B)){
// std::cout << ">" << std::endl;
// }else{
// std::cout << "=" << std::endl;
//
// }
// }else{
// std::cout << "<" << std::endl;
// }
// }else{
// if(A<B){
// std::cout << ">" << std::endl;
// }else{
// std::cout << "<" << std::endl;
// }
// }
// }
if (A < 0) { // B>0
if (C % 2 == 0) {
if (abs(A) < abs(B)) {
std::cout << "<" << std::endl;
} else if (abs(A) > abs(B)) {
std::cout << ">" << std::endl;
} else {
std::cout << "=" << std::endl;
}
} else {
std::cout << "<" << std::endl;
}
} else { // A>0 -> b<0
if (C % 2 == 0) {
if (abs(A) < abs(B)) {
std::cout << "<" << std::endl;
} else if (abs(A) > abs(B)) {
std::cout << ">" << std::endl;
} else {
std::cout << "=" << std::endl;
}
} else {
std::cout << ">" << std::endl;
}
}
}
int main() {
long long A;
std::scanf("%lld", &A);
long long B;
std::scanf("%lld", &B);
long long C;
std::scanf("%lld", &C);
solve(A, B, C);
return 0;
}
|
#include <iostream>
using namespace std;
int main(){
int N;
cin >> N;
int a[N], b[N];
for (int i = 0; i < N; i++) cin >> a[i];
for (int i = 0; i < N; i++) cin >> b[i];
long long ans;
for (int i = 0; i < N; i++){
ans += a[i] * b[i];
}
if (ans == 0)cout << "Yes";
else cout << "No";
} | #include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ff first
#define ss second
int main(){
ll t,n,i;
cin>>n;
vector<ll>arr(n);
set<ll>s;
for(i=0;i<n;i++)
{
cin>>arr[i];
s.insert(arr[i]);
}
while(s.size()>=2)
{
ll x=*s.begin();
ll y=*s.rbegin();
s.insert(y-x);
s.erase(y);
}
cout<<*s.begin();
return 0;
}
|
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define WT int T=read();while(T--)
#define NO puts("NO");
#define YES puts("YES");
using namespace std;
inline int read()
{
char c=getchar();int x=0;bool f=0;
for(;!isdigit(c);c=getchar())f^=!(c^45);
for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
if(f)x=-x;return x;
}
const int M=2e5+10;
int sum[M],a[M],maxn[M],ans;
signed main()
{
int n=read();
for (int i=1;i<=n;i++)a[i]=read(),maxn[i]=max(maxn[i-1],a[i]),sum[i]=sum[i-1]+a[i];
for (int i=1;i<=n;i++)
{
ans+=sum[i];ans-=maxn[i-1]*(i-1),ans+=i*maxn[i];
cout<<ans<<endl;
}
return 0;
} | #include<cstdio>
using namespace std;
#define int long long
int n,a[200010],sum[200010],sum2[200010],mx[200010];
signed main(){
scanf("%lld",&n);
for(int i=1;i<=n;i++){
scanf("%lld",&a[i]);
sum[i]=sum[i-1]+a[i];
sum2[i]=sum2[i-1]+sum[i];
mx[i]=(mx[i-1]>a[i]?mx[i-1]:a[i]);
}
for(int i=1;i<=n;i++){
printf("%lld\n",sum2[i]+mx[i]*i);
}
return 0;
} |
//...Bismillahir Rahmanir Rahim. . .
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
// typedefs...
typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<ll, ll> pll;
typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update>pref_trie;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;
// constants...
const double PI = acos(-1);
const ll mod = 1000000007; // 998244353;
const int MXS = 2e5+5;
const ll MXI = 1e9+5;
const ll MXL = 1e18+5;
const ll INF = 1e9+5;
const ll INFLL = 1e18+5;
const ll EPS = 1e-9;
// defines...
#define MP make_pair
#define PB push_back
#define fi first
#define se second
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define si(a) scanf("%d", &a)
#define sii(a, b) scanf("%d%d", &a, &b)
#define ordered_set tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define boost_ ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define iter_(i,n) for (int i = 0; i < int(n); i++)
#define for_n(i, n) for (int i = 1; i <= int(n); i++)
#define print_array(a) for(int i=0;i<n;i++) cout<<a[i]<<" ";
#define rev(i,n) for(int i=n;i>=0;i--)
#define itr ::iterator
#define s_sort(s) sort(s.begin(),s.end())
#define n_sort(a, n) sort(a,a+n)
#define precise_impact cout<<setprecision(10)<<fixed;
#define endl "\n"
// functions...
ll gcd(ll a, ll b){ while (b){ a %= b; swap(a, b);} return a;}
ll lcm(ll a, ll b){ return (a/gcd(a, b)*b);}
ll ncr(ll a, ll b){ ll x = max(a-b, b), ans=1; for(ll K=a, L=1; K>=x+1; K--, L++){ ans = ans * K; ans /= L;} return ans;}
ll bigmod(ll a,ll b){ if(b==0){ return 1;} ll tm=bigmod(a,b/2); tm=(tm*tm)%mod; if(b%2==1) tm=(tm*a)%mod; return tm;}
ll egcd(ll a,ll b,ll &x,ll &y){ if(a==0){ x=0; y=1; return b;} ll x1,y1; ll d=egcd(b%a,a,x1,y1); x=y1-(b/a)*x1; y=x1; return d;}
int main()
{
ll t;
cin>>t;
vector<pair<ll,string> > v;
while(t--)
{
string s;
ll n;
cin>>s>>n;
v.PB({n,s});
}
sort(all(v));
cout<<v[v.size()-2].se<<endl;
}
| /*
このコード、と~おれ!
Be accepted!
∧_∧
(。・ω・。)つ━☆・*。
⊂ ノ ・゜+.
しーJ °。+ *´¨)
.· ´¸.·*´¨) ¸.·*¨)
(¸.·´ (¸.·'* ☆
*/
#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
#include <stack>
#include <bitset>
#include <array>
#include <chrono>
//#pragma GCC target("arch=skylake-avx512")
#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse4")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define repeat(i, n, m) for(int i = n; i < (m); ++i)
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a)
#define printLdb(a) printf("%.50Lf\n", a)
#define printdbd(a) printf("%.16lf\n", a)
#define prints(s) printf("%s\n", s.c_str())
#define all(x) (x).begin(), (x).end()
#define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI)
#define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L)
#define Please return
#define AC 0
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d))
using ll = long long;
using ull = unsigned long long;
constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1e9 + 7;
constexpr ll mod = 998244353;
constexpr long double eps = 1e-6;
const long double PI = acosl(-1.0L);
using namespace std;
void scans(string& str) {
char c;
str = "";
scanf("%c", &c);
if (c == '\n')scanf("%c", &c);
while (c != '\n' && c != -1 && c != ' ') {
str += c;
scanf("%c", &c);
}
}
void scanc(char& str) {
char c;
scanf("%c", &c);
if (c == -1)return;
while (c == '\n') {
scanf("%c", &c);
}
str = c;
}
double acot(double x) {
return PI / 2 - atan(x);
}
ll LSB(ll n) { return (n & (-n)); }
template<typename T>
inline T chmin(T& a, const T& b) {
if (a > b)a = b;
return a;
}
template<typename T>
inline T chmax(T& a, const T& b) {
if (a < b)a = b;
return a;
}
//cpp_int
#if __has_include(<boost/multiprecision/cpp_int.hpp>)
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
using namespace boost::multiprecision;
#else
using cpp_int = ll;
#endif
//atcoder library
#if __has_include(<atcoder/all>)
#include <atcoder/all>
//using namespace atcoder;
#endif
/*
random_device seed_gen;
mt19937 engine(seed_gen());
uniform_int_distribution dist(1, 100);
*/
/*----------------------------------------------------------------------------------*/
int main() {
int n;
scanf("%d", &n);
vector<ll> a(n);
rep(i, n)scanf("%lld", &a[i]);
map<ll, ll> mp;
ll ans = 0;
++mp[0];
ll r = 0;
rep(i, n) {
r += a[i] * (i % 2 ? -1 : 1);
ans += (mp[r]++);
}
printf("%lld\n", ans);
Please AC;
} |
/**
* author: shishunze
* date: 2021/2/18
**/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
const int N = 100005;
vector<int> e[N];
int n,x,dp[N],sz[N];
void dfs1(int u)
{
sz[u]=1;
for(int i=0;i<e[u].size();i++)
{
int v = e[u][i];
dfs1(v);
sz[u]+=sz[v];
}
}
void dfs2(int u)
{
vector<int> vt;
int sum=0;
dp[u]=1;
for(int i=0;i<e[u].size();i++)
{
int v = e[u][i];
dfs2(v);
if(sz[v]%2==0 && dp[v]<0) dp[u]+=dp[v];
if(sz[v]%2==1) vt.pb(dp[v]);
if(sz[v]%2==0 && dp[v]>=0) sum+=dp[v];
}
sort(vt.begin(),vt.end());
vt.pb(sum);
for(int i=0;i<vt.size();i++)
{
if(i%2==0) dp[u]+=vt[i];
else dp[u]-=vt[i];
}
}
int main()
{
ios::sync_with_stdio(false);
cin>>n;
for(int i=2;i<=n;i++)
{
cin>>x;
e[x].pb(i);
}
dfs1(1);
dfs2(1);
cout<<(n+dp[1])/2;
}
| #include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> v[100000];
pair<int, pair<int, int>> dfs(int x) {
int p1 = 0, p2 = 0, sa = 0, sb = 0, f = 0, i;
vector<pair<int, pair<int, int>>> w;
p1++;
f = 1 - f;
for (i = 0; i < v[x].size(); i++) {
pair<int, pair<int, int>> p = dfs(v[x][i]);
int x = p.second.first;
int y = p.second.second;
if (p.first == 0) {
if (x <= y) {
p1 += x;
p2 += y;
} else {
sa += x;
sb += y;
}
} else {
w.push_back(make_pair(x - y, make_pair(x, y)));
}
}
sort(w.begin(), w.end());
for (i = 0; i < w.size(); i++) {
int x = w[i].second.first;
int y = w[i].second.second;
if (f == 1) {
p1 += x;
p2 += y;
} else {
p1 += y;
p2 += x;
}
f = 1 - f;
}
if (f == 1) {
p1 += sa;
p2 += sb;
} else {
p1 += sb;
p2 += sa;
}
return make_pair(f, make_pair(p1, p2));
}
int main() {
int n, i;
scanf("%d", &n);
for (i = 1; i < n; i++) {
int p;
scanf("%d", &p);
v[p - 1].push_back(i);
}
printf("%d\n", dfs(0).second.first);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define scan(any) for(auto &i:any) cin>>i;
#define print(any) for(auto i:any) cout<<i<<" ";
#define endl '\n'
#define pb push_back
#define vll vector<ll>
#define f(i,x,y) for(i=x;i<y;i++)
#define INF LLONG_MAX
#define s(x) sort(x.begin(),x.end())
#define all(v) v.begin(),v.end()
#define p2(n,x) cout << fixed << setprecision(x) <<n<<endl;
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define ff first
#define ss second
#define blt(x) __builtin_popcount(x)
void solve()
{
long double n;
cin>>n;
long double ans=n;
long double i;
f(i,2,n)
{
ans+=(n/i);
}
p2(ans,10);
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
ll t = 1;
while(t--) {
solve();
}
return 0;
} | #include <bits/stdc++.h>
#define f first
#define s second
#define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
#define vv(type, name, h, ...) vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...) vector<vector<vector<type>>> name(h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
using namespace std;
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
using lli = long long;
using vi = vc<int>;
using ii = pair<int,int>;
lli gcd(lli a, lli b){return (b?gcd(b,a%b):a);}
lli lcm(lli a, lli b){ if(!a || !b) return 0; return a * b / gcd(a, b); }
int popcount(lli x) { return __builtin_popcountll(x); }
lli poww(lli a, lli b){
lli res = 1;
while(b){ if(b&1) res = res*a; a=a*a; b>>=1;}
return res;
}
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// int rnd(int n){return uniform_int_distribution<int>(0, n-1)(rng);}
template<class t,class u>bool mmax(t&a,u b){if(a<b)a=b;return a<b;}
template<class t,class u>bool mmin(t&a,u b){if(b<a)a=b;return b<a;}
template <typename T> static constexpr T inf = numeric_limits<T>::max() / 2;
// ---- しゃけ ツナマヨ ('-')7
void solve(){
int n; cin>>n;
int best = inf<int>,same=inf<int>;
vi x(n),y(n);
fore(i,0,n){
int a,b; cin>>a>>b;
mmin(same,a+b);
x[i]=a;
y[i]=b;
}
best = same;
fore(i,0,n)fore(j,0,n)if(i!=j)mmin(best,max(x[i],y[j]));
fore(i,0,n)fore(j,0,n)if(i!=j)mmin(best,max(y[i],x[j]));
cout<<best<<ENDL;
}
int main(){_
// int t; cin>>t; while(t--)
solve();
}
|
#include <iostream>
#include <set>
using namespace std;
const int max_n = 1000;
multiset<int> mst;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m, ta;
cin >> n >> m;
for (int i = 0; i < n; i++)
{
cin >> ta;
mst.insert(ta);
}
for (int i = 0; i < m; i++)
{
cin >> ta;
mst.insert(ta);
}
for (int i = 0; i <= max_n; i++)
{
if (mst.count(i) == 1)
cout << i << " ";
}
cout << endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define vec vector<int>
#define vecp vector<pair<int,int>>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define fr first
#define sc second
#define fr1(i,a,b) for(int i=a;i<b;i++)
#define fr2(i,a,b) for(int i=a;i>=b;i--)
#define fr3(i,a,b) for(int i=a;i<=b;i++)
#define umap unordered_map<int,int,custom_hash>
#define omap map<int,int>
#define uset unordered_set<int,custom_hash>
#define oset set<int>
#define pr pair<int,int>
#define mod 1000000007
#define mp make_pair
#define all(v) v.begin(),v.end()
#define ppb pop_back
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
// http://xorshift.di.unimi.it/splitmix64.c
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
void solve()
{
int n,m;
cin>>n>>m;
map<int,int> map1;
fr1(i,0,n)
{
int x;
cin>>x;
map1[x]++;
}
fr1(i,0,m)
{
int x;
cin>>x;
map1[x]++;
}
for(auto i:map1)if(i.sc==1)cout<<i.fr<<" ";
cout<<"\n";
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t=1;
//cin>>t;
fr3(i,1,t){
//cout<<"Case: "<<t<<;
solve();
}
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
int N;
vector<ll> A;
double f(double x) {
double ret = 0;
for (auto e : A) {
ret += max<double>(0, e - 2 * x);
}
return ret;
}
void solve() {
cin >> N;
A.resize(N);
REP(i, N) cin >> A[i];
sort(ALL(A));
double x1 = A[N / 2] / 2.;
// double lb = 0, ub = 2e9;
//// double lb = 0, ub = 3;
// REP(_, 100) {
//// double md = (lb + ub) / 2;
//// double tmp = f(md);
//// if (N * md < tmp) {
//// lb = md;
//// } else {
//// ub = md;
//// }
// double c1 = (lb * 2 + ub) / 3;
// double c2 = (lb + ub * 2) / 3;
// double f1 = f(c1);
// double f2 = f(c2);
// if (f1 < f2) {
// ub = c2;
// } else {
// lb = c1;
// }
// }
// double ans = lb + f(lb) / N;
// cout << 1.5 + f(1.5) / N << endl;
double ans = f(x1) / N + x1;
cout << ans << 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 <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <complex>
#include <vector>
#include <limits>
#include <iomanip>
#include <cassert>
#include <numeric>
#include <chrono>
#include <random>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define debug(x) cerr << #x << " = " << (x) << endl;
#define debug_pii(x) cerr << "(" << x.first << "," << x.second << ")";
#define rep(i, n) for(int i = 0;i < n;i++)
#define pb push_back
#define F first
#define S second
// template<typename _Ty1, typename _Ty2>
// ostream& operator<<(ostream& _os, const pair<_Ty1, _Ty2>& _p) {
// _os << '(' <<_p.first << ',' << _p.second << ')';
// return _os;
// }
//
// template<typename _Ty1, typename _Ty2>
// istream& operator>>(istream& _is, pair<_Ty1, _Ty2>& _p) {
// _is >> _p.first >> _p.second;
// return _is;
// }
// #1 >= #0
// #1 >= #0
//
// #0 > #1
// #0 > #1
// dp[i]['ab']
void solve() {
string s;
cin>>s;
int cnt = 0;
for(int i = 0;i <= 8;i++) {
if(s.substr(i, 4) == "ZONe") cnt++;
}
cout<<cnt;
}
// a1 a2 a3 a4 a4 a6 a7
// b1 b2 b3 b4 b5 b6 b7
//
// dp[i][j] = cost + dp[i+1][j-1]
int main() {
// freopen("input.in","r",stdin);
// freopen("output.out","w",stdout);
// cout << fixed << setprecision(15);
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
}
|
//region TEMPLATE
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
#define fastio ios_base::sync_with_stdio(0);cin.tie(NULL);
#define endl "\n"
#define pb push_back
#define all(X) begin((X)), end((X))
#define sz(X) (int)(X).size()
#define fi first
#define se second
#define fv(X) for(auto&_:(X))cin>>_
#define fv2(X) for(auto&__:(X))fv(__)
#define lboundi(X, n) (lower_bound(all(X), n) - begin(X))
#define uboundi(X, n) (upper_bound(all(X), n) - begin(X))
#define maxi(X) max_element(all(X)) - begin(X)
#define maxe(X) *max_element(all(X))
#define mini(X) min_element(all(X)) - begin(X)
#define mine(X) *min_element(all(X))
#define acc(X) accumulate(all(X), 0LL)
#ifdef LOCAL
template<size_t S>
string to_string(const bitset<S> &x) { return x.to_string(); }
string to_string(const string &x) { return '"' + x + '"'; }
string to_string(char x) { return string{'\'', x, '\''}; }
string to_string(bool x) { return x ? "true" : "false"; }
template<typename Head, typename Tail>
string to_string(const pair<Head, Tail> &x) { return "(" + to_string(x.first) + ", " + to_string(x.second) + ")"; }
template<class T>
string to_string(T x) {
string ret = "[";
for (const auto &i: x)
ret += to_string(i) + ", ";
if (sz(ret) > 1)
ret = ret.substr(0, sz(ret) - 2);
return ret += "]";
}
string to_string(const char *x) { return string(x); }
string to_string() { return ""; }
template<typename Head, typename... Tail>
string to_string(Head H, Tail... T) { return to_string(H) + ", " + to_string(T...); }
#define debug(...) sizeof( (char[]){#__VA_ARGS__} ) == 1 ? cerr << endl \
: cerr << "[" << #__VA_ARGS__ << "]: " << to_string(__VA_ARGS__) << endl
#define nr() cerr << endl
#else
#define debug(...) 1
#endif
// endregion
class FenwickTreeSum {
private:
int sum(int i) {
if (i <= 0) return 0;
int ret = 0;
while (i) {
ret += tree[i];
i -= i & -i;
}
return ret;
}
public:
int n;
vi tree;
FenwickTreeSum(int n) : n(n) {
tree.resize(n + 1);
}
void update(int i, int diff) {
i++;
while (i <= n) {
tree[i] += diff;
i += i & -i;
}
}
int query(int l, int r) { return sum(r + 1) - sum(l); }
};
void solve() {
int n;
cin >> n;
vi a(n), b(n);
fv(a);
fv(b);
if (acc(a) != acc(b)) {
cout << -1;
return;
}
if (a == b) {
cout << 0;
return;
}
// 8
map<int, vi> pos_a, pos_b;
for (int i = 0; i < n; i++) {
a[i] += i;
b[i] += i;
pos_a[a[i]].pb(i);
pos_b[b[i]].pb(i);
}
vi inversion_count(n);
for (const auto &p: pos_a) {
const vi &bv = pos_b[p.fi];
if (sz(p.se) != sz(bv)) {
cout << -1;
return;
}
for (int i = 0; i < sz(p.se); i++) {
inversion_count[bv[i]] = p.se[i];
}
}
debug(inversion_count);
FenwickTreeSum fenwick(n);
ll ret = 0;
for (int i = 0; i < n; i++) {
ret += fenwick.query(inversion_count[i], n - 1);
debug(fenwick.query(0, n - 1));
fenwick.update(inversion_count[i], 1);
}
cout << ret;
}
int main() {
fastio
solve();
return 0;
} | // #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization("unroll-loops")
#include "bits/stdc++.h"
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define endl '\n'
#define F first
#define S second
#define IO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define cf ll testcases;cin>>testcases;while(testcases--)
#define prn(x) if(x) cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define minel(x) (*min_element(all(x)))
#define maxel(x) (*max_element(all(x)))
#define cou dbg=1;cout
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pi;
typedef vector<ll> vi;
typedef vector<ld> vd;
typedef vector<pi> vp;
ll dbg=0;
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p);
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v);
template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p);
template<typename A> istream& operator>>(istream& cin, vector<A> &v);
int dx[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dy[] = {-1, 0, 1, -1, 1, -1, 0, 1};
void solve(){
ll n;
cin>>n;
vi arr(n);
cin>>arr;
ll man=0;
for(auto i:arr) man+=abs(i);
cout<<man<<endl;
ll euc=0;
for(auto i:arr) euc+=i*i;
cout.precision(15);
cout<<fixed<<sqrt(euc)<<endl;
ll cheb=LLONG_MIN;
for(auto i:arr) cheb=max(cheb,abs(i));
cout<<cheb<<endl;
}
int main(){
IO;
// cf
solve();
return 0;
}
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) {
if(dbg){
return cout << "(" << p.F << ", " << p.S << ")";
}else{
return cout<<p.F<<' '<<p.S;
}
dbg=0;}
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) {
if(dbg){
cout << "["; for(ll i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]";
}else{
for(ll i=0;i<v.size()-1;i++) cout<<v[i]<<' ';
return cout<<v[v.size()-1];
dbg=0;}
}
template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p) {
cin >> p.first;
return cin >> p.second;
}
template<typename A> istream& operator>>(istream& cin, vector<A> &v) {
for(ll i=0;i<v.size()-1;i++) cin>>v[i];
return cin >> v[v.size()-1];
} |
#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
#define _GLIBCXX_DEBUG
#define rep(i, s, n) for (int i = (int)s; i < (int)n; i++)
#define repr(i, n, s) for (int i = (int)n; (int)s < i; i--)
#define len(a) (int)a.size()
#define all(a) a.begin(), a.end()
const int INF32 = 1 << 30;
const long long INF64 = 1LL << 60;
const double PI = acos(-1);
/* 1次元ベクトルをスペースでつなぎ、改行をつけて出力
vi, vl, list<int>, list<ll>に対応 */
template<class T> string print_elements(T a) {
string str = "";
for (auto itr = a.begin(); itr != a.end(); ++itr) {
str += to_string(*itr) + ' ';
}
str.pop_back(); // 最後の空白を削除
str += '\n';
return str;
}
int main() {
int N, W;
cin >> N >> W;
cout << N / W << endl;
}
| #include<iostream>
using namespace std;
int main()
{
int n,w;
cin>>n>>w;
int i=1;
int t=1;
while(t<=n){
t=w*i;
i++;
}
cout<<i-2;
} |
#include<bits/stdc++.h>
#define L(i, j, k) for(int i = j, i##E = k; i <= i##E; i++)
#define R(i, j, k) for(int i = j, i##E = k; i >= i##E; i--)
#define ll long long
#define ull unsigned long long
#define db double
#define pii pair<int, int>
#define mkp make_pair
#define sz(x) ((int) x.size())
#define be(x) x.begin()
#define en(x) x.end()
using namespace std;
const int N = 1e5 + 7;
int n, m;
void exgcd(ll a, ll b, ll &x, ll &y) {
if(b == 0) return x = 1, y = 0, void();
exgcd(b, a % b, y, x), y -= x * (a / b);
}
ll mul(ll aa, ll bb, ll mod) {
ll sav = aa * bb - (ll)( (long db) aa * bb / mod + 0.2 ) * mod;
return sav < 0 ? sav + mod : sav;
}
ll crt(ll *a, ll *b, int len) { // x mod a_i = b_i
ll now = 1, ys = 0;
L(i, 1, len) {
ll g = __gcd(now, a[i]), c1, c2, md = a[i] / g;
if((b[i] - ys) % g) return 2e18;
exgcd(now, a[i], c1, c2), ((c1 %= md) += md) %= md, c1 = mul(c1, ((b[i] - ys) / g % md + md) % md, md);
((c1 %= md) += md) %= md, ys += c1 * now;
now /= g, now *= a[i], ((ys %= now) += now) %= now;
}
return ys;
}
ll a[N], b[N];
int T, x, y, p, q;
ll ans = 0;
void Main() {
ans = 2e18;
cin >> x >> y >> p >> q;
L(i, x, x + y - 1) L(j, p, p + q - 1) {
a[1] = 2 * (x + y), b[1] = i;
a[2] = p + q, b[2] = j;
ans = min(ans, crt(a, b, 2));
}
if(ans == 2e18) cout << "infinity\n";
else cout << ans << "\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> T;
while(T--) Main();
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define ri register int
typedef long long ll;
int p,q,t,x,y;
ll a[3],ans,g,m[3];
template<class T>
inline T slow_add(T a,T b,T mod){
while(a>mod-b)a-=mod;
return a+b;
}
template<class T>
inline T slow_mul(T a,T b,T mod){
T ret=0;
for(;b;a=(a+a)%mod,b>>=1)if(b&1)ret=(ret+a)%mod;
return ret;
}
template<class T>
T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T>
void exgcd(T a,T b,T &x,T &y){
a%=b;
if(!a){
x=b;y=0;
return;
}
ll s=b,t=a,m0=0,m1=1;
while(t){
ll u=s/t;
s-=t*u;
m0-=m1*u;
ll tmp=s;
s=t;
t=tmp;
tmp=m0;
m0=m1;
m1=tmp;
}
if(m0<0)m0+=b/s;
x=s,y=m0;
}
inline ll cn(int n){
ll mul=1,ret=0;
for(ri i=1;i<=n;++i){
ll a1=a[i]%m[i],m1=m[i];
if(mul<m1)swap(mul,m1),swap(ret,a1);
if(mul%m1==0){
if(ret%m1!=a1)return LLONG_MAX;
continue;
}
ll t1=0,t2=0;
exgcd(mul,m1,t1,t2);
ll u1=m1/t1;
ll tmp=(a1-ret)/t1%u1*t2%u1;
ret+=tmp*mul;
mul*=u1;
if(ret<0)ret+=mul;
}
return ret;
}
int main(){
scanf("%d",&t);
while(t--){
scanf("%d%d%d%d",&x,&y,&p,&q);
#define a1 a[1]
#define a2 a[2]
#define m1 m[1]
#define m2 m[2]
m1=(x+y)<<1,m2=p+q;
g=gcd(m1,m2);
ans=LLONG_MAX;
for(a1=x;a1<x+y;++a1)
for(a2=p;a2<p+q;++a2)
if((a2-a1)%g==0)
ans=min(ans,cn(2));
if(ans==LLONG_MAX)puts("infinity");
else printf("%lld\n",ans);
}
return 0;
} |
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
//#define mod 998244353
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline void out(T a){ cout << a << '\n'; }
void YN(bool ok){if(ok) cout << "Yes" << endl; else cout << "No" << endl;}
//void YN(bool ok){if(ok) cout << "YES" << endl; else cout << "NO" << endl;}
const ll INF=1e18;
const int mx=200005;
//arc106
int main(){
cin.tie(0);ios::sync_with_stdio(false);
ll n,m;
cin>>n>>m;
V<P> ans;
bool ok=1;
if(m==0){
rep(i,n) ans.emplace_back(2*(i+1)-1,2*(i+1));
}else if(m>0){
int r=1;
for(int i=1;i<=n;i++){
if(i-2==m){
ans.emplace_back(1,r+1);
r++;
}else{
ans.emplace_back(r+1,r+2);
r+=2;
}
}
}else{
int l=1000000000;
int tmp=10000000;
int cnt=1;
for(int i=1;i<=n;i++){
if(i==1){
ans.emplace_back(1,tmp);
cnt++;
}else if(i-2<=-m){
ans.emplace_back(cnt,tmp+cnt);
//cnt++;
if(i-1==-m){
cnt=tmp+cnt;
}else cnt++;
}else{
ans.emplace_back(cnt+1,cnt+2);
cnt+=2;
}
}
}
if(m>=n-1||m<0) ok=0;
if(n==1&&m==0){
cout<<1<<' '<<2<<endl;
return 0;
}
if(ok){
for(auto p:ans) cout<<p.ft<<' '<<p.sc<<'\n';
}else out(-1);
}
//ペナルティ出しても焦らない ACできると信じろ!!!
//どうしてもわからないときはサンプルで実験 何か見えてくるかも
//頭で考えてダメなら紙におこせ!!
/*
V,P(大文字)使用不可
乗算などの際にオーバーフローに注意せよ!
(適切にmodをとれ にぶたんで途中で切り上げろ)
制約をよく読め!
{
・全探索できるなら全探索しろ
・異常な制約ならそこに注目
}
stringの計算量(扱い)注意
コーナー注意!(特に数値が小さいものについては要検証)
N行出力のときは'¥n'
グリッド上では行先が範囲内におさまるかif文で確認(RE注意)
if文ではちゃんと比較演算子==を使え('='でもエラー出ない)
配列(vector)の大きさが0か1以上かで場合分けせよ(RE注意)
(vector<int> a(m)でm==0というものはできない)
modはなるべく最後に取れ!
doubleを扱うときには(abs)ではなく'fabs'!!!
dpするときは「配る」、「もらう」の両方を考えて最適な方を選べ
Segtreeで区間最大(max)を使うとき,単位元の設定をしっかり
(デフォルトは-INF,0の方が都合の良い場合は変更)
*/ | #include <bits/stdc++.h>
using namespace std;
#ifdef __DEBUG__
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {cerr << " " << H; debug_out(T...);}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
ll N,M;
inline void input(){
fast_io();
cin >> N >> M;
}
int cntR(vector<pll> a){
auto cmp = [](pll x, pll y){return x.second < y.second;};
sort(a.begin(),a.end(),cmp);
debug(a);
int ret = 0;
ll last = 0;
for (int i = 0; i < a.size(); i++)
{
if(last < a[i].first){
ret++;
last = a[i].second;
}
}
return ret;
}
int cntL(vector<pll> a){
auto cmp = [](pll x, pll y){return x.first < y.first;};
sort(a.begin(),a.end(),cmp);
debug(a);
int ret = 0;
ll last = 0;
for (int i = 0; i < a.size(); i++)
{
if(last < a[i].first){
ret++;
last = a[i].second;
}
}
return ret;
}
int solve(ll N, ll M){
if(M<0){
cout << -1 << endl;
return 0;
}
else if(N==1 && M==0){
vector<pll> Ans;
Ans.emplace_back(1,2);
for(auto [x,y]:Ans) cout << x << " " << y << "\n";
return 0;
}
else if(M>=N-1){
cout << -1 << endl;
return 0;
}
vector<pll> Ans;
ll rest = N-M;
for (int i = 1; i <= min(M+1,N); i++)
{
Ans.emplace_back(2*i+rest+10,2*i+rest+11);
}
for (int i = 0; i < rest-1; i++)
{
Ans.emplace_back(i+1,(ll)1e6+i+1);
}
debug(cntR(Ans));
debug(cntL(Ans));
debug(Ans.size());
for(auto [x,y]:Ans) cout << x << " " << y << "\n";
return 0;
}
int test(){
int n = 1;
for (int m = -n; m <= n; m++)
{
debug(n,m);
solve(n,m);
}
return 0;
}
int main()
{
// test();
input();
solve(N,M);
return 0;
}
|
// {{{ by unolight
#include <bits/stdc++.h>
#include <unistd.h>
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-function"
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x),end(x)
#define RALL(x) rbegin(x),rend(x)
#define REP(i,n) for ( int i=0; i<int(n); i++ )
#define REP1(i,a,b) for ( int i=(a); i<=int(b); i++ )
#define MP make_pair
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef pair<int,int> PII;
typedef vector<int> VI;
namespace { namespace unolight {
// Read Input
template<class T> void _R( T &x ) { cin>>x; }
void _R( int &x ) { scanf("%d",&x); }
void _R( int64_t &x ) { scanf("%" PRId64,&x); }
void _R( double &x ) { scanf("%lf",&x); }
void _R( char &x ) { scanf(" %c",&x); }
void _R( char *x ) { scanf("%s",x); }
void R() {}
template<class T, class... U> void R( T& head, U&... tail ) { _R(head); R(tail...); }
// Write Output
template<class T> void _W( const T &x ) { cout<<x; }
void _W( const int &x ) { printf("%d",x); }
void _W( const int64_t &x ) { printf("%" PRId64,x); }
void _W( const double &x ) { printf("%.16f",x); }
void _W( const char &x ) { putchar(x); }
void _W( const char *x ) { printf("%s",x); }
template<class T> void _W( const vector<T> &x ) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W( const T& head, const U&... tail ) { _W(head); putchar(sizeof...(tail)?' ':'\n'); W(tail...); }
#ifdef UNOLIGHT
#include "dump.hpp"
#else
#define dump(...)
#endif
template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
sort(begin(v),end(v),f);
v.resize(unique(begin(v),end(v))-begin(v));
}
// }}}
void main() {
int n;
R(n);
VI a(n);
REP(i,n) R(a[i]);
chmin(n,8);
vector<VI> g(200);
for ( int s=1; s<1<<n; s++ ) {
VI f;
int sum=0;
REP(i,n) if ( s>>i&1 ) {
sum=(sum+a[i])%200;
f.PB(i+1);
}
if ( SZ(g[sum]) ) {
W("Yes");
W(SZ(f),f);
W(SZ(g[sum]),g[sum]);
return;
}
g[sum]=f;
}
W("No");
}
// {{{ main
}}
int main() { unolight::main(); return 0; }
// }}}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
ll a[505][505];
ll b[505][505];
const int INF = 1000000000;
int dist[1000005];
vector <pair <int, int>> graf[1000005];
int n, m;
int hes(int i, int j, int k){
return k*n*m + (i-1)*m+j;
}
int main(){
ios_base::sync_with_stdio(false);
cout.precision(10);
cout << fixed;
cin >> n >> m;
for(int i=1; i<=n; i++){
for(int j=1; j<m; j++){
cin >> a[i][j];
}
}
for(int i=1; i<n; i++){
for(int j=1; j<=m; j++){
cin >> b[i][j];
}
}
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
if(j < m) graf[hes(i, j, 0)].push_back({hes(i, j+1, 0), a[i][j]});
if(j < m) graf[hes(i, j, 1)].push_back({hes(i, j+1, 0), a[i][j]});
if(j > 1) graf[hes(i, j, 0)].push_back({hes(i, j-1, 0), a[i][j-1]});
if(j > 1) graf[hes(i, j, 1)].push_back({hes(i, j-1, 0), a[i][j-1]});
if(i < n) graf[hes(i, j, 0)].push_back({hes(i+1, j, 0), b[i][j]});
if(i < n) graf[hes(i, j, 1)].push_back({hes(i+1, j, 0), b[i][j]});
if(i > 1) graf[hes(i, j, 0)].push_back({hes(i-1, j, 1), 2});
if(i > 1) graf[hes(i, j, 1)].push_back({hes(i-1, j, 1), 1});
}
}
for(int i=2; i<=2*n*m; i++) dist[i] = INF;
set <pair <int, int>> q;
q.insert({0, 1});
while(!q.empty()){
pair <int, int> pr = *q.begin();
q.erase(q.begin());
int v = pr.second;
for(auto c : graf[v]){
if(dist[c.first] > c.second + dist[v]){
q.erase({dist[c.first], c.first});
dist[c.first] = c.second + dist[v];
q.insert({dist[c.first], c.first});
}
}
}
cout << min(dist[n*m], dist[2*n*m]);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#ifdef BOI
#include "debug.h"
#else
#define debug(args...)
#endif
typedef long long ll;
int main() {
ios_base :: sync_with_stdio(0);
cin.tie(0);
int n; cin >> n;
ll k; cin >> k;
vector <vector <ll>> a(n, vector <ll>(n));
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
cin >> a[i][j];
}
}
vector <int> aa(n);
iota(aa.begin(), aa.end(), 0);
int cnt = 0;
do {
ll sum = 0;
for (int i = 1; i < n; ++i) {
sum += a[aa[i]][aa[i - 1]];
}
sum += a[aa[n - 1]][0];
if (sum == k) ++cnt;
debug(aa, sum);
} while (next_permutation(aa.begin() + 1, aa.end()));
cout << cnt;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<ll mod>
struct Mint {
ll x;
Mint(ll x = 0) : x((x %= mod) < 0 ? x + mod : x) { }
Mint& operator+=(Mint rhs) { return (x += rhs.x) >= mod ? x -= mod : 0, *this; }
Mint& operator-=(Mint rhs) { return (x -= rhs.x) < 0 ? x += mod : 0, *this; }
Mint& operator*=(Mint rhs) { return (x *= rhs.x) %= mod, *this; }
Mint& operator/=(Mint rhs) { return *this *= rhs.power(-1); }
Mint power(ll p) const {
p %= mod - 1;
if (p < 0) p += mod - 1;
Mint res = 1;
for (Mint y = *this; p; p >>= 1, y *= y) if (p & 1) res *= y;
return res;
}
bool operator==(Mint rhs) const { return x == rhs.x; }
bool operator<(Mint rhs) const { return x < rhs.x; }
friend Mint operator+(Mint lhs, Mint rhs) { return lhs += rhs; }
friend Mint operator-(Mint lhs, Mint rhs) { return lhs -= rhs; }
friend Mint operator*(Mint lhs, Mint rhs) { return lhs *= rhs; }
friend Mint operator/(Mint lhs, Mint rhs) { return lhs /= rhs; }
friend ostream& operator<<(ostream& out, Mint a) { return out << a.x; }
friend istream& operator>>(istream& in, Mint& a) {
ll x;
in >> x;
a = Mint(x);
return in;
}
};
constexpr ll mod = 998244353;
using mint = Mint<mod>;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int N;
cin >> N;
const int Wmax = 100;
vector<vector<mint>> dp(N + 1, vector<mint>(N * Wmax + 1));
dp[0][0] = 1;
int sum = 0;
for (int i = 0; i < N; ++i) {
int W;
cin >> W;
for (int k = N - 1; k >= 0; --k) {
for (int x = N * Wmax - W; x >= 0; --x) {
dp[k + 1][x + W] += dp[k][x];
}
}
sum += W;
}
mint ans = 0;
if (sum % 2 == 0) {
vector<mint> f(N + 1, 1);
for (int x = 1; x <= N; ++x) {
f[x] = x * f[x - 1];
}
for (int k = 1; k <= N; ++k) {
ans += dp[k][sum / 2] * f[k] * f[N - k];
}
}
cout << ans << endl;
exit(0);
}
|
#include <bits/stdc++.h>
using namespace std;
template<typename T,typename T1>T amax(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T amin(T &a,T1 b){if(b<a)a=b;return a;}
// =================
#define f(i, k, n) for (int i = k; i < n; i++)
#define ll long long
#define pb push_back
#define fr first
#define sc second
#define len(s) s.size()
#define all(v) v.begin(), v.end()
// =================
const int mod = 1e9+7;
const int N = 3e5 + 1;
void solve()
{
int v,t,s,d;
cin>>v>>t>>s>>d;
puts( (d>s*v || d<v*t) ? "Yes" : "No");
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t=1;
// cin>>t;
while (t--)
solve();
return 0;
} | #include <iostream>
#include <cmath>
using namespace std;
int main(){
int N, a, b;
cin >> N;
int arr[N], arr1[N];
for(int i = 0; i < N; i++){
cin >> a;
arr[i] = a;
}
for(int k = 0; k < N; k++){
cin >> b;
arr1[k] = b;
}
int result = 0;
for(int j = 0; j < N; j++){
result += arr[j]*arr1[j];
}
if(result == 0){
cout << "Yes" << endl;}
else{
cout << "No" << endl;
}
} |
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------
int N;
map<int,int> S;
void solve() {
int i,j,k,l,r,x,y; string s;
cin>>N;
ll ret=1LL*N*(N-1)/2;
FOR(i,N) {
cin>>x;
ret-=S[x];
S[x]++;
}
cout<<ret<<endl;
}
int main(int argc,char** argv){
string s;int i;
if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
cout.tie(0); solve(); return 0;
}
| #include <iostream>
#include <vector>
#include <map>
#include <numeric>
#include <algorithm>
using namespace std;
typedef long long ll;
int main() {
ll n;
cin >> n;
map<ll, ll> m;
vector<ll> v;
{
ll tmp;
while (cin >> tmp) {
m[tmp]++;
v.push_back(tmp);
}
}
ll ans = 0;
for (ll i: v) {
ans += (n - m[i]);
}
cout << ans / 2LL << endl;
} |
#include <bits/stdc++.h>
using namespace std;
int main(){
long long t, N;
cin>>t>>N;
long long ans;
long long nonexistcount=0;
long long i=1;
while(nonexistcount!=N){
if(i*(double)t/100>=nonexistcount+1){
ans = i+nonexistcount;
nonexistcount++;
if(nonexistcount==1&&N!=1){
i = i+(100/t)*(N-1);
nonexistcount=N-1;
}
else{
i = i+100/t;
}
}
else{
i++;
}
}
cout<<ans<<endl;
} | #include<bits/stdc++.h>
using namespace std;
#define _ 0
const int maxn=1e5+5;
const int inf=0x3f3f3f3f;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
long long t,n;
cin>>t>>n;
cout<<(n*100+t-1)/t+n-1<<endl;
return ~~(0^_^0);
}
|
#include<bits/stdc++.h>
using namespace std;
// for loop
#define rep(i,a,n) for(int i=(a);i<(n);++i)
#define repe(i,a,n) for(int i=(a);i<=(n);++i)
#define rrep(i,n,a) for(int i=(n);n>(a);--i)
#define rrepe(i,n,a) for(int i=(n);n>=(a);--i)
// abbreviati
#define PB(v) push_back(v)
#define MP(A,B) make_pair(A,B)
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define ENDL << "\n"
using ll = long long;
using P = pair<int,int>;
using itn = int;
// constant
const int INF = 1<<30;
const ll INFLL = 1LL << 60;
const ll MOD = 1000000007;
const long double PI =(acos(-1));
/***Snippet***************************************************
ifelse, isprime, torad, todeg, lcm, bfs,chmin,chmax
**************************************************************/
// adjacency list
vector<int> to[100005];
// Graph
using Graph = vector<vector<int>>;
// Grid
int H,W;
vector<vector<int>> field;
// 4方向への移動ベクトル
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int h,w; cin >> h >> w;
vector<string> s(h);
rep(i,0,h){
cin >> s[i];
}
bool flag=0;
int cnt=0;
rep(i,0,h){
rep(j,0,w){
flag=0;
//if(j==w-1 || i==h-1) continue;
if(s[i][j]=='.'){
flag=1;
}
if(j<w-1 && flag && s[i][j+1]=='.'){
cnt++;
}
if(i<h-1 && flag && s[i+1][j]=='.'){
cnt++;
}
}
}
cout << cnt ENDL;
return 0;
} | #include<iostream>
#include<cstdio>
#include<map>
using namespace std;
#define N 100012
inline int sgn(int x){return (x==0)?0:((x>0)?1:(-1));}
inline int Abs(int x){return (x>0)?x:(-x);}
int n,L,a[N],b[N],c[N],la[N];bool fl=true;map<int,int>mp;long long ans=0;
inline void Fin(int l,int r)
{
if(l+1>=r)return;int i,ql=l,qr=r,ls;
for(i=l+1;i<r-1;i++)if((c[i]==1)&&(c[i+1]==(-1))){fl=false;return;}
for(i=l;i<=r;i++)if(c[i]==(-1))ql=i;for(i=r;i>=l;i--)if(c[i]==1)qr=i;
mp.clear();for(i=l;i<=ql;i++){if(c[i]){if(!mp.count(b[i]-i)){fl=false;return;}la[i]=mp[b[i]-i];}mp[a[i]-i]=i;}
mp.clear();for(i=r;i>=qr;i--){if(c[i]){if(!mp.count(b[i]-i)){fl=false;return;}la[i]=mp[b[i]-i];}mp[a[i]-i]=i;}
ls=l;for(i=l;i<=r;i++){if(c[i]&&(ls>la[i])){fl=false;return;}if(c[i])ls=max(ls,la[i]);}
ls=r;for(i=r;i>=l;i--){if(c[i]&&(ls<la[i])){fl=false;return;}if(c[i])ls=min(ls,la[i]);}
ls=r;for(i=ql;i>=l;i--)if(c[i]&&(la[i]!=ls)){ans+=i-la[i];ls=la[i];}
ls=l;for(i=qr;i<=r;i++)if(c[i]&&(la[i]!=ls)){ans+=la[i]-i;ls=la[i];}
}
int main(){
scanf("%d%d",&n,&L);int i,l,r;for(i=1;i<=n;i++)scanf("%d",&a[i]);for(i=1;i<=n;i++)scanf("%d",&b[i]);a[0]=b[0]=0;a[n+1]=b[n+1]=L+1;
for(i=1;i<=n;i++)c[i]=sgn(b[i]-a[i]);
for(i=0;(i<=(n+1))&&fl;i=r){l=i;r=i+1;while((r<=n)&&c[r])++r;Fin(l,r);}if(!fl){printf("-1");return 0;}printf("%lld",ans);return 0;
} |
#include <bits/stdc++.h>
#define LL long long
#define ull unsigned long long
#define F(i, j, k) for(int i = j; i <= k; i++)
#define DF(i, j, k) for(int i = j; i >= k; i--)
using namespace std;
template <typename T> inline void read(T &n) {
T w = 1;
n = 0;
char ch = getchar();
while (!isdigit(ch) && ch != EOF) {
if (ch == '-') w = -1;
ch = getchar();
}
while (isdigit(ch) && ch != EOF) {
n = (n << 3) + (n << 1) + (ch & 15);
ch = getchar();
}
n *= w;
}
template <typename T> inline void write(T x) {
T l = 0;
ull y = 0;
if (!x) {
putchar(48);
return;
}
if (x<0) {
putchar('-');
x = -x;
}
while (x) {
y = y * 10 + x % 10;
x /= 10;
l++;
}
while (l) {
putchar(y % 10 + 48);
y /= 10;
l--;
}
}
template <typename T> inline void writes(T x) {
write(x);
putchar(' ');
}
template <typename T> inline void writeln(T x) {
write(x);
puts("");
}
template <typename T> inline void checkmax(T &a,T b) { a = a > b ? a : b; }
template <typename T> inline void checkmin(T &a,T b) { a = a < b ? a : b; }
const int MOD = 998244353;
inline int ksm(int x, int y) {
int k = 1;
while (y) {
if (y & 1) k = (long long)k * x % MOD;
x = (long long)x * x % MOD;
y >>= 1;
}
return k;
}
inline void add(int &a, int b) { a = (a + b >= MOD) ? a + b - MOD : a + b; }
inline int dec(int a, int b) { return (a - b < 0) ? a - b + MOD : a - b; }
int main() {
//freopen(".in", "r", stdin);
//freopen(".out", "w", stdout);
int n, m, k, ans = 0;
read(n);
read(m);
read(k);
if (n == 1 && m == 1) { writeln(k); return 0; }
if (n == 1) {
F(i, 1, k) add(ans, dec(ksm(k - i + 1, m), ksm(k - i, m)));
writeln(ans);
return 0;
}
if (m == 1) {
F(i, 1, k) add(ans, dec(ksm(i, n), ksm(i - 1, n)));
writeln(ans);
return 0;
}
F(i, 1, k) add(ans, (long long)dec(ksm(i, n), ksm(i - 1, n)) * ksm(k - i + 1, m) % MOD);
writeln(ans);
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define endl "\n"
#define yes "Yes\n"
#define no "No\n"
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
ll maxn = 1000006;
void solve(int test)
{
vector<ll>sieve(maxn,0);
ll i,j;
for(i=2;i<maxn;i++)
{
if(sieve[i] == 0)
{
for(j=i;j<maxn;j+=i)sieve[j]++;
for(j=i*i;j<maxn;j+=i*i)sieve[j] = -10000005;
}
}
ll l,r;
cin>>l>>r;
if(l==1)
{
l = min(r,2LL);
}
if(l==1 && r==1)
{
cout<<0<<endl;
return;
}
ll tot = (r-l+1)*(r-l);
tot = tot/2;
tot = 0;
for(i=2;i<=r;i++)
{
if(sieve[i] <= 0)continue;
ll val = r/i - (l-1)/i;
if(sieve[i]%2==1)
{
tot += val*(val-1)/2;
}
else
{
tot -= val*(val-1)/2;
}
}
ll sub = 0;
for(i=l;i<=r;i++)
{
for(j=2*i;j<=r;j+=i)sub++;
}
tot = tot - sub;
tot = 2*tot;
cout<<tot<<endl;
}
int main()
{
//fast;
int t = 1;
//cin>>t;
for(int x=1;x<=t;x++)
{
solve(x);
}
return 0;
}
|
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
template <typename T1, typename T2>
void mmin(T1& a, const T2& b) {
if (b < a) a = b;
}
template <typename T1, typename T2>
void mmax(T1& a, const T2& b) {
if (b > a) a = b;
}
const int MAXN = 5020, P = 998'244'353;
int n, m, k;
char c[MAXN][MAXN];
ll d[MAXN][MAXN];
constexpr ll qpow(ll base, ll exp) {
ll ans = 1;
while (exp) {
if (exp % 2) ans = ans * base % P;
base = base * base % P;
exp /= 2;
}
return ans % P;
}
constexpr ll two_thirds = qpow(3, P - 2) * 2 % P;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m >> k;
for (int i = 0; i < k; i++) {
int h, w;
char q;
cin >> h >> w >> q;
c[h][w] = q;
}
d[1][1] = qpow(3, n * m - k);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) {
if (i == 1 && j == 1) continue;
if (i > 1) {
if (!c[i - 1][j]) d[i][j] = (d[i][j] + d[i - 1][j] * two_thirds) % P;
else if (c[i - 1][j] != 'R') d[i][j] = (d[i][j] + d[i - 1][j]) % P;
}
if (j > 1) {
if (!c[i][j - 1]) d[i][j] = (d[i][j] + d[i][j - 1] * two_thirds) % P;
else if (c[i][j - 1] != 'D') d[i][j] = (d[i][j] + d[i][j - 1]) % P;
}
}
cout << d[n][m] << endl;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define REP(i, n) for(ll i = 0LL; i < (ll)(n); i++)
#define REPR(i, n) for (ll i = (ll)(n) - 1; i >= 0; i--)
#define FOR(i, n, m) for(ll i = (ll)n; i < (ll)(m); i++)
#define ALL(x) (x).begin(),(x).end()
// #define MOD 1000000007
#define MOD 998244353
#define INF (1LL << 62)
#define PI (acos(-1))
#define PRINT(x) std::cout << x << endl
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll countDigit(ll n) { return floor(log10(n) + 1); }
typedef pair <ll,ll> P;
static const ll dx[8] = {0,1,0,-1, 1, -1, 1, -1}, dy[8] = {1,0,-1,0,1,1,-1,-1};
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
for (int i = 0; i < (int)v.size(); ++i) os << v[i] << " ";
return os;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& os, const map<T1, T2>& m)
{
for (auto p : m) os << "<" << p.first << ", " << p.second << "> ";
return os;
}
int main()
{
ll N, K;
string S;
cin >> N >> K >> S;
for (ll k = 0; k < K; k++) {
string T = S;
for(ll i = 0; i < T.size(); i+=1) {
char te1 = S[(2*i)%N];
char te2 = S[(2*i+1)%N];
if (te1 != te2) {
if (te1 == 'R') {
if (te2 == 'S') {
T[i] = te1;
} else {
T[i] = te2;
}
} else if (te1 == 'S') {
if (te2 == 'R') {
T[i] = te2;
} else {
T[i] = te1;
}
} else {
if (te2 == 'R') {
T[i] = te1;
} else {
T[i] = te2;
}
}
} else {
T[i] = te1;
}
}
S = T;
}
cout << S[0] << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
int main() {
int N;
scanf("%d", &N);
vector<ll> A(N), S(N + 1, 0), M(N + 1, 0);
rep(i, N) {
scanf("%lld", &A[i]);
S[i + 1] = S[i] + A[i];
M[i + 1] = max(M[i], A[i]);
}
ll ans = 0;
rep(i, N) {
ans += S[i + 1];
printf("%lld\n", ans + M[i + 1] * (i + 1));
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
int i = 1;
int sum = 0;
while(true) {
sum = sum + i;
if (sum >= N) {
cout << i << endl;
return 0;
}
i++;
}
} |
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<pair<ll,ll>> vp;
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define mod 1000000007
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,a,b,c) for(ll i=a;i<b;i+=c)
#define repn(i,a,b,c) for(ll i=a;i>=b;i-=c)
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
#define yes cout<<"Yes\n"
#define no "no\n"
#define endl '\n'
#define F first
#define S second
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#define max(x,y) ((x<y)?y:x)
#define min(x,y) ((x<y)?x:y)
ll gcd(ll x, ll y){
ll temp=min(x,y);
y=x+y-temp;
x=temp;
while(y%x!=0){
temp=x;
x=y%x;
y=temp;
}
return x;
}
bool prime[1000005];
vll spf(20000005,0);
void Seive(ll n){
rep(i,0,n,1) prime[i]=true;
prime[0]=prime[1]=false;
for (int p=2; p*p<n; p++)
{
if (prime[p]==false) continue;
for (int i=p*p; i<n; i+=p)
prime[i] = false;
}
}
void Seive_spf(ll n){
spf[0]=0, spf[1]=1;
for (ll p=2; p<n; p++){
if (spf[p]>0) continue;
spf[p]=p;
for(ll i=p;i<n;i+=p) if(spf[i]==0) spf[i]=p;
}
}
ll nCrmodp_dp(ll n, ll r, ll p){
ll c[r+1]={0};
c[0]=1;
rep(i,1,n+1,1){
repn(j,min(i,r),0,1) c[j] = (c[j]+c[j-1])%p;
}
return c[r];
}
ll nCrmodp(ll n, ll r, ll p){
if(r==0) return 1;
return (nCrmodp(n/p, r/p, p)*nCrmodp_dp(n%p, r%p, p))%p;
}
void print2d(vvll a){
rep(i,0,a.size(),1){
rep(j,0,a[i].size(),1) cout<<a[i][j]<<' ';
cout<<endl;
}
}
void print1d(vll a){
rep(i,0,a.size(),1) cout<<a[i]<<' ';
cout<<endl;
}
void solve(){
ll n;
cin>>n;
vll a(n), b(n);
rep(i,0,n,1) cin>>a[i];
rep(i,0,n,1) cin>>b[i];
ll mi=a[0], ma=b[0];
rep(i,1,n,1){
mi=max(mi,a[i]);
ma=min(ma,b[i]);
}
cout<<max(ma-mi+1,0)<<endl;
}
int main(){
IOS
#ifdef OK
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int t=1;
//cin>>t;
/*Seive(1000000)
vll pr[1000000];
rep(i,2,1000000,1) if(prime[i]==false) pr.pb(i);
*/
while(t--) solve();
return 0;
} | #include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<queue>
#include<cmath>
//#include<bits/stdc++.h>
#define int long long
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define mp make_pair
#define all(x) x.begin(),x.end()
#define puts(x) cout << (x) << "\n"
constexpr int mod = 998244353;
using namespace std;
int input() { int t; cin >> t; return t; }
int n, s, t, ndm, ndi, dt[234567], ans[234567];
vector<int>g[234567];
void f1(int i, int d, int p) {
dt[i] = d;
if (ndm < d) { ndm = d; ndi = i; }
for (int j : g[i])if (j != p)f1(j, d + 1, i);
}
int f2t = 1;
void f2(int i, int p) {
if (ans[i] == 0)ans[i] = f2t;
for (int j : g[i])if (p != j && dt[j] > dt[i]) {
f2t++; f2(j, i); f2t++;
}
for (int j : g[i])if (p != j && dt[j] < dt[i]) {
f2t++; f2(j, i); f2t++;
}
}
signed main() {
//function<int(int, int)> gcd = [&gcd](int a, int b) {if (b == 0)return a; return gcd(b, a % b); };
cin >> n;
for0(i, n - 1) {
int a, b; cin >> a >> b;
g[a].push_back(b);
g[b].push_back(a);
}
ndm = 0; ndi = 1; f1(1, 0, 1); s = ndi;
ndm = 0; ndi = 1; f1(s, 0, s); t = ndi;
ndm = 0; ndi = 1; f1(t, 0, t);
f2(s, s);
for1(i, n) { cout << ans[i] << (i == n ? "\n" : " "); }
} |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<pair<int,int>> vpi;
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define pb push_back
#define mp make_pair
#define rev(i,a,b) for(int i=a;i<b;i++)
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
const int MOD = 1000000000+7;
ll mul(ll x,ll y)
{return (x*y)%MOD;}
ll bin_pow(ll x,ll p)
{if(p==0)return 1;if(p&1)return mul(x,bin_pow(x,p-1));return bin_pow(mul(x,x),p/2);}
ll gcd(ll a,ll b)
{if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b)
{return a / gcd(a, b) * b;}
bool prime(ll n)
{if(n<=1)return 0;for(ll i=2;i*i<=n;i++)if(n%i==0)return 0; return 1;}
bool adj[5005][5005];
int deg[5005];
int main()
{
ll n;
cin>>n;
vl f;
n=n*2;
f.pb(1);
f.pb(n);
for(ll i=2;i*i<=n;i++)
{
if(n%i==0)
{
f.pb(i);
if(i*i!=n)
f.pb(n/i);
}
}
// for(auto i:f)cout<<i<<" ";
ll a=0;
for(int i=0;i<sz(f);i++)
{
ll x=(n/f[i])+1-f[i];
if(x%2==0)
a++;
}
cout<<a<<endl;
}
| #include <bits/stdc++.h>
#define clog(x) std::clog << (#x) << " is " << (x) << '\n';
using LL = long long;
int main() {
//freopen("in", "r", stdin);
std::cin.tie(nullptr)->sync_with_stdio(false);
LL n;
std::cin >> n;
std::vector<LL> F{1, 1};
while (F.back() <= n) F.emplace_back(F[F.size() - 2] + F[F.size() - 1]);
F.pop_back();
int s = F.size(), now = s - 1;
std::vector<int> a(s), ans;
while (now >= 0 && n) {
if (F[now] <= n) { // 不会超过两次的
n -= F[now];
++a[s - 1 - now];
}
--now;
}
for (int i = 0; i < s; ++i) {
if ((i & 1) == (s & 1)) {
if (a[i]) ans.emplace_back(2);
ans.emplace_back(4);
} else {
if (a[i]) ans.emplace_back(1);
ans.emplace_back(3);
}
}
std::cout << ans.size() << '\n';
for (auto x : ans) std::cout << x << '\n';
return 0;
} |
/**
* Author: Daniel
* Created Time: 2021-03-27 20:02:48
**/
// time-limit: 2000
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define ER erase
#define IS insert
#define PI acos(-1)
#define PB pop_back
#define MP make_pair
#define MT make_tuple
#define LB lower_bound
#define UB upper_bound
#define EB emplace_back
#define lowbit(x) (x & -x)
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()
#define SOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout<<fixed<<setprecision(10)
typedef long long LL;
typedef vector<LL> VL;
typedef vector<int> VI;
typedef pair<LL, LL> PLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef unsigned long long ULL;
typedef pair<double, double> PDD;
typedef vector<pair<LL, LL> > VPLL;
typedef vector<pair<int, int> > VPII;
template <typename A> using VE = vector<A>;
template <typename A> using USET = unordered_set<A>;
template <typename A> using HEAP = priority_queue<A>;
template <typename A, typename B> using PA = pair<A, B>;
template <typename A, typename B> using UMAP = unordered_map<A, B>;
template <typename A> using RHEAP = priority_queue<A, vector<A>, greater<A> >;
template <typename A> A MAX(const A &a) { return a; }
template <typename A> A MIN(const A &a) { return a; }
template <typename A> A MAX(const A *a, const A *b) { assert(b - a > 0); return *max_element(a, b); }
template <typename A> A MIN(const A *a, const A *b) { assert(b - a > 0); return *min_element(a, b); }
template <typename A, typename... B> A MAX(const A &a, const B&... b) { return max(a, MAX(b...)); }
template <typename A, typename... B> A MIN(const A &a, const B&... b) { return min(a, MIN(b...)); }
template <typename A, typename B = typename std::iterator_traits<A>::value_type> B MAX(A a, A b) { assert(b - a > 0); return *max_element(a, b); }
template <typename A, typename B = typename std::iterator_traits<A>::value_type> B MIN(A a, A b) { assert(b - a > 0); return *min_element(a, b); }
mt19937 rng((unsigned int)chrono::steady_clock::now().time_since_epoch().count());
///////////////////////////////////////////////////////////////////////////
//////////////////// DO NOT TOUCH BEFORE THIS LINE ////////////////////////
///////////////////////////////////////////////////////////////////////////
// check the limitation!!!
const int N = 100010, M = 1010;
// read the question carefully!!!
int main()
{
SOS;
int n, m, x, y;
cin >> n >> m >> x >> y;
x -- , y -- ;
VS g(n);
for (auto &s : g) cin >> s;
int res = 1;
for (int j = y + 1; j < m; j ++ )
if (g[x][j] == '.') res ++ ;
else break;
for (int j = y - 1; j >= 0; j -- )
if (g[x][j] == '.') res ++ ;
else break;
for (int i = x - 1; i >= 0; i -- )
if (g[i][y] == '.') res ++ ;
else break;
for (int i = x + 1; i < n; i ++ )
if (g[i][y] == '.') res ++ ;
else break;
cout << res << '\n';
return 0;
}
// GOOD LUCK!!!
| #include <iostream>
#include <algorithm>
#include <vector>
#include <tuple>
using namespace std;
using p = pair<int, int>;
vector<p> d = {p(-1,0), p(1,0), p(0,-1), p(0,1)};
int main() {
int h, w, x, y;
cin >> h >> w >> x >> y;
x--;
y--;
vector<vector<char>> v(h, vector<char>(w));
for (int i=0; i<h; i++) {
for (int j=0; j<w; j++) {
cin >> v[i][j];
}
}
int ans = 0;
for (auto coord: d) {
bool b = true;
int s, t;
int t_x = x, t_y = y;
tie(s, t) = coord;
while (b) {
t_x += s;
t_y += t;
if ((t_x>=h) || (t_x<0) || (t_y>=w) || (t_y<0) || (v[t_x][t_y]=='#')) {
b = false;
} else {
ans += 1;
}
}
}
if (v[x][y]=='.') {
cout << ans+1 << endl;
} else {
cout << ans << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;
#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 loop(i,a) for(int i=0; i < (a); i++)
#define rloop(i,a) for(int i=(a-1); i >= 0; i--)
#define MAX(a,b) (a < b) ? (b) : (a)
#define BIGGEST(a,b,c) (MAX(a,b) < c) ? (c) : MAX(a,b)
#define END "\n"
#define pb push_back
#define ff first
#define ss second
#define sort(a) sort(a.begin(),a.end())
const int MAX_N = 1e5 + 5;
const int MAX_L = 20; // ~ Log N
const long long MOD = 1e9 + 7;
const long long INF = 1e9 + 7;
void solve(){
int n;
cin >> n;
map<string,ll>mp;
string s[n];
string ans = "satisfiable";
loop(i,n){
cin >> s[i];
if(s[i][0] != '!'){
mp[s[i]] = 1;
}
}
loop(i, n) {
if (s[i][0] == '!') {
if (mp[s[i].substr(1, s[i].length() - 1)]) {
ans = s[i].substr(1, s[i].length() - 1);
}
}
}
cout << ans;
}
int main() {
ios_base::sync_with_stdio(false);cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
freopen("error.txt","w",stderr);
#endif
// int t; cin >> t;
// while(t--)
solve();
cerr<<"\ntime taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
return 0;
}
| #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
const ll MAX_N = 1e18 + 2000;
int main () {
ios::sync_with_stdio(false);
ll n;
cin >> n;
ll on = n;
vector<ll> fib = {0, 1};
while (fib.back() < MAX_N) {
ll a = fib.back();
ll b = *next(fib.rbegin());
fib.push_back(a + b);
}
int mx = -1;
vector<int> decomp;
for (int i = (int) fib.size() - 1; i > 0; i--) {
if (n >= fib[i]) {
decomp.push_back(i);
n -= fib[i];
mx = max(mx, i);
}
}
if (mx % 2 == 1) {
mx++;
}
vector<int> adds (mx, 0);
for (int u : decomp) {
adds[mx - u] = 1;
}
ll a = 0, b = 0;
vector<int> sol;
for (int i = 0; i < (int) adds.size(); i += 2) {
if (a != 0) {
b += a;
sol.push_back(4);
}
if (adds[i]) {
b++;
sol.push_back(2);
}
if (b != 0) {
a += b;
sol.push_back(3);
}
if (adds[i + 1]) {
a++;
sol.push_back(1);
}
}
cout << sol.size() << '\n';
for (int o : sol) {
cout << o << '\n';
}
}
|
#include<bits/stdc++.h>
using namespace std;
#define M 1000000007
#define ll long long
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ifor(st,lim) for(int i=st;i<lim;i++)
#define jfor(stt,llim) for(int j=stt;j<llim;j++)
#define pb push_back
void solve() {
// cout<<"X";
int x,y; cin>>x>>y;
if(x == y) {
cout<<x;
}else {
// 0 1 2
// 0 1 2
cout<< 3 - (x + y);
}
}
void file_i_o() {
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
}
int main()
{
file_i_o();
FIO;
int t=1;
while(t--) {
solve();
}
} | #include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define fr(i,n) for(int i=0;i<n;i++)
#define pct(i,n) cout<<"Case "<<i<<": "<<n<<endl;
#define fast() ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define e "\n"
int main()
{
int x,y; cin>>x>>y;
if(x==y){
cout<<x<<e;
}
else if(x==0&&y==1){
cout<<2<<e;
}
else if(x==1&&y==0){
cout<<2<<e;
}
else if(x==1&&y==2){
cout<<0<<e;
}
else if(x==2&&y==1){
cout<<0<<e;
}
else if(x==2&&y==0){
cout<<1<<e;
}
else if(x==0&&y==2){
cout<<1<<e;
}
return 0;
}
|
#include<iostream>
using namespace std;
int A, B, W;
int main(){
cin >> A >> B >> W;
W*=1000;
int ans_max= W/A;
int ans_min= W/B + (W%B!=0);
bool IsSatisfiable = false;
for(int i=1; i<=1000000; i++){
if(A*i<=W&&W<=B*i){
IsSatisfiable = true;
break;
}
}
string S =to_string(ans_min) + " " + to_string(ans_max);
cout << (IsSatisfiable? S: "UNSATISFIABLE") << endl;
return 0;
} | //{{
/*
* Created at: 06/21/21 17:49:29
*
* FB: https://facebook.com/tgbaodeeptry
* From Viet Nam with Love :D
*
*/
#include <bits/stdc++.h>
using namespace std;
#define fast_io() \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define REP(i, a, b) for (int i = int(a); i < int(b); ++i)
#define RED(i, a, b) for (int i = int(a); i > int(b); --i)
#define FOR(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define FOD(i, a, b) for (int i = int(a); i >= int(b); --i)
#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define eb emplace_back
#define pb push_back
#define endl '\n'
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;
const int MOD = 1e9 + 7;
const int MAXN = 1e5;
const int INF = INT_MAX;
template <class T> void re(T &x) { cin >> x; };
template <class T> void re(vector<T> &v, int n) {
FOR(i, 0, n - 1) cin >> v[i];
};
template <class T> void re(vector<T> &v, int f, int t) {
FOR(i, f, t) cin >> v[i];
};
template <class T> void re(T v[], int n) { FOR(i, 0, n - 1) cin >> v[i]; };
template <class T> void re(T *v, int f, int t) { FOR(i, f, t) cin >> v[i]; };
template <class H, class... T> void re(H &v, T &... args) {
re(v);
re(args...);
};
void dbg_out() { cerr << endl; }
template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) {
cerr << ' ' << H;
dbg_out(T...);
}
template <typename T> void dbg_out(vector<T> a) {
for (auto c : a) cerr << ' ' << c;
cerr << endl;
};
template <typename T> void dbg_out(vector<T> a, int n) {
FOR(i, 0, n - 1) cerr << ' ' << a[i];
cerr << endl;
};
template <typename T> void dbg_out(vector<T> a, int u, int v) {
FOR(i, u, v) cerr << ' ' << a[i];
cerr << endl;
};
template <typename T> void dbg_out(T a[]) {
for (auto c : a) cerr << ' ' << c;
cerr << endl;
};
template <typename T> void dbg_out(T a[], int n) {
FOR(i, 0, n - 1) cerr << ' ' << a[i];
cerr << endl;
};
template <typename T> void dbg_out(T a[], int u, int v) {
FOR(i, u, v) cerr << ' ' << a[i];
cerr << endl;
};
#if defined(_CRUN) || defined(_RUN)
#define pd(...) \
cerr << "(L:" << __LINE__ << "): " \
<< "[" << #__VA_ARGS__ << "] =", \
dbg_out(__VA_ARGS__)
#else
#define pd(...)
#endif
#if defined(_CRUN)
#define c_input() freopen("input", "r", stdin)
#define c_output() freopen("output", "r", stdin)
#else
#define c_input()
#define c_output()
#endif
void ps(){};
template <typename Head, typename... Tail> void ps(Head H, Tail... T) {
cout << H;
ps(T...);
};
template <typename T> void ps(vector<T> a, int n) {
FOR(i, 0, n - 1) cout << a[i] << ' ';
};
template <typename T> void ps(T a[], int n) {
FOR(i, 0, n - 1) cout << a[i] << ' ';
};
ll add_mod(ll a, ll b) { return ((a % MOD) + (b % MOD)) % MOD; }
ll sub_mod(ll a, ll b) { return ((a % MOD) - (b % MOD) + MOD) % MOD; }
ll mul_mod(ll a, ll b) { return ((a % MOD) * (b % MOD)) % MOD; }
ll pow_mod(ll a, ll b) {
ll ans = 1;
while (b) {
if (b & 1) ans = mul_mod(ans, a);
a = mul_mod(a, a);
b >>= 1;
};
return ans;
};
ll lcm(ll a, ll b) { return a * b / __gcd(a, b); }
ll pow(ll a, ll b) {
ll ans = 1;
while (b) {
if (b & 1) ans *= a;
a *= a;
b >>= 1;
};
return ans;
};
void solve();
void init();
bool multi_test = false;
// ---- main below ----- ///
int main() {
fast_io();
init();
int T = 1;
if (multi_test) re(T);
FOR(i, 1, T) solve();
}
//}}
void init() {
// multi_test = true;
}
int n, sum;
int a[100];
int memo[100][100001];
int find(int u, int cur) {
if (u == n) {
return (2*cur >= sum ? cur : INF);
}
if (~memo[u][cur]) {
return memo[u][cur];
}
return memo[u][cur] = min(find(u + 1, cur), find(u + 1, cur + a[u]));
}
void solve() {
re(n);
re(a, n);
// tim subset minimize
memset(memo, -1, sizeof memo);
sum = accumulate(a, a + n, 0);
ps(find(0, 0));
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
template <typename T>
void print_vec(const vector<T>& v, bool newline = true) {
for (int i = 0; i < v.size(); ++i) {
cout << v[i] << " ";
}
if (newline) {
cout << "\n";
}
}
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
const int maxn = (int)5105;
const int mod = (int)998244353;
#define sz(x) ((int)(x.size()))
#define pb push_back
#define rep(i,a,b) for (int i = (a); i <= (b); i++)
#define repr(i,a,b) for (int i = (a); i >= (b); i--)
int fact_setup=0; int * fact;
int ex (int a, int b){
if(b==0)return 1; int e = ex(a,b/2); e=(1ll*e*e)%mod; if(b&1)e=(1ll*e*a)%mod; return e;
}
int inv (int a){
return ex(a, mod - 2);
}
int choose (int a, int b){
if(!fact_setup){
fact_setup=1;
fact = new int [maxn];
fact[0]=1; rep (i,1,maxn-1) fact[i]=(i*fact[i-1])%mod;
}
if(a<b)return 0;
int num = fact[a];
int denom = (fact[b] * fact[a - b]) % mod;
return (num * inv(denom)) % mod;
}
#define pii pair <int, int>
#define pvi pair <vector <int>, int>
#define pai array <int,2>
#define pdi array <double, 2>
#define pdt array <double, 3>
#define pti array <int,3>
#define pfi array <int,4>
#define all(v) v.begin(), v.end()
main(){
cin.tie(0); ios_base::sync_with_stdio(0);
int n, k; cin >> n >> k;
int ans = 0;
rep (i, 1, n){
rep (j, 1, k){
ans += 100*i;
ans += j;
}
}
cout << ans;
return 0;
} | #include <bits/stdc++.h>
// #include <atcoder/all>
// using namespace atcoder;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,n) for(int i=int(n-1);i>=int(0);--i)
#define fore(i,a) for(auto &i:a)
#define all(x) x.begin(),x.end()
#define sz(x) ((int)(x).size())
#define bp(x) (__builtin_popcount((long long)(x)))
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define V vector
#define P pair<int,int>
#define TP tuple<int,int,int>
#define F first
#define S second
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
using ll = long long;
using ld = long double;
using namespace std;
const int INF = 1001001001;
const ll INFL = 1001001001001001001;
const int MAX = 2e6+1;
template<int MOD> struct Fp {
long long val;
constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
if (val < 0) val += MOD;
}
constexpr int getmod() { return MOD; }
constexpr Fp operator - () const noexcept {
return val ? MOD - val : 0;
}
constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
constexpr Fp& operator += (const Fp& r) noexcept {
val += r.val;
if (val >= MOD) val -= MOD;
return *this;
}
constexpr Fp& operator -= (const Fp& r) noexcept {
val -= r.val;
if (val < 0) val += MOD;
return *this;
}
constexpr Fp& operator *= (const Fp& r) noexcept {
val = val * r.val % MOD;
return *this;
}
constexpr Fp& operator /= (const Fp& r) noexcept {
long long a = r.val, b = MOD, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b; swap(a, b);
u -= t * v; swap(u, v);
}
val = val * u % MOD;
if (val < 0) val += MOD;
return *this;
}
constexpr bool operator == (const Fp& r) const noexcept {
return this->val == r.val;
}
constexpr bool operator != (const Fp& r) const noexcept {
return this->val != r.val;
}
friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
return os << x.val;
}
friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
if (n == 0) return 1;
auto t = modpow(a, n / 2);
t = t * t;
if (n & 1) t = t * a;
return t;
}
};
const int MOD = 1000000007;
//const int MOD = 998244353;
using mint = Fp<MOD>;
int main() {
int n;cin>>n;
V<ll> a(n);
rep(i,n)cin>>a[i];
a.push_back(0);
sort(all(a));
mint ans=1;
rep(i,1,n+1){
ans*=a[i]-a[i-1]+1;
}
cout<<ans<<endl;
return 0;
} |
#include<bits/stdc++.h>
#define int long long
#define N 200000
#define P 1000000009
using namespace std;
int T,n,aa,hsh[4][2*N+1],pw2[2*N+1];
//n1[2][2*N+1],n2[2][2*N+1],n3[2][2*N+1],l0,l1,st[2][4];
string s1,s2,s3,ans,ss[4];
//int calmi(string ns){
// for(int i=0;i<ns.size();i++){
// if(ns[i]=='0'){
// int nans=0,ni=i;
// while(ni<ns.size()&&ns[ni]=='0')ni++;
// nans=ni-i;
// return nans;
// }
// }
//}
bool fnd(int x,string ns){
int np=0;
for(int i=0;i<ns.size();i++){
while(ss[x][np]!=ns[i]&&np<ss[x].size())np++;
if(np>=ss[x].size())return 0;
np++;
}return 1;
}
signed main(){
pw2[0]=1;for(int i=1;i<=2*N;i++)pw2[i]=pw2[i-1]*2%P;
cin>>T;
while(T--){
cin>>n;
cin>>s1>>s2>>s3;
ss[1]=s1+s1;ss[2]=s2+s2;ss[3]=s3+s3;
//for(int i=1;i<=3;i++)calhsh(i);
bool ffl=0;
for(int t=0;t<=1;t++){
for(int i=1;i<=3;i++){
for(int j=0;j<=1;j++){
string ns=ss[i].substr(0,2*n);
if(t==0)ns+=j+'0';
else{
string ng;ng.clear();ng+=j+'0';
ns.insert(0,ng);
}
//int nh=(hsh[i][2*n]*2+j)%P;
bool nfl=1;
for(int k=1;k<=3;k++){
if(k!=i&&!fnd(k,ns)){
nfl=0;break;
}
}
if(nfl){
cout<<ns<<endl;
ffl=1;break;
}
}if(ffl)break;
}if(ffl)break;
}
if(ffl)continue;
string ns;ns.clear();
for(int i=0;i<=1;i++){
for(int j=0;j<=1;j++){
ns.clear();
for(int k=1;k<=n;k++)ns+=i+'0';
ns+=j+'0';
for(int k=1;k<=n;k++)ns+=1-i+'0';
bool nfl=1;
for(int k=1;k<=3;k++){
if(k!=i&&!fnd(k,ns)){
nfl=0;break;
}
}
if(nfl){
cout<<ns<<endl;
ffl=1;break;
}
ns.clear();ns+=j+'0';
for(int k=1;k<=n;k++)ns+=i+'0';
for(int k=1;k<=n;k++)ns+=1-i+'0';
nfl=1;
for(int k=1;k<=3;k++){
if(k!=i&&!fnd(k,ns)){
nfl=0;break;
}
}
if(nfl){
cout<<ns<<endl;
ffl=1;break;
}
ns.clear();
for(int k=1;k<=n;k++)ns+=i+'0';
for(int k=1;k<=n;k++)ns+=1-i+'0';ns+=j+'0';
nfl=1;
for(int k=1;k<=3;k++){
if(k!=i&&!fnd(k,ns)){
nfl=0;break;
}
}
if(nfl){
cout<<ns<<endl;
ffl=1;break;
}
}
if(ffl)break;
}
}
return 0;
}
/*
5
3
000111
001110
011100
2
0011
1001
0110
3
001011
101010
000111
3
001011
010101
110010
4
11010010
01010110
00011101
s1+=s1;s2+=s2;s3+=s3;
// l0=l1=4*n;
// for(int i=4*n-1;i>=0;i--){
// n1[0][i]=l0;
// n1[1][i]=l1;
// if(s1[i]=='0')l0=i;
// else l1=i;
// }
// st[0][1]=l0;st[1][1]=l1;
// l0=l1=4*n;
// for(int i=4*n-1;i>=0;i--){
// n2[0][i]=l0;
// n2[1][i]=l1;
// if(s2[i]=='0')l0=i;
// else l1=i;
// }
// st[0][2]=l0;st[1][2]=l1;
// l0=l1=4*n;
// for(int i=4*n-1;i>=0;i--){
// n3[0][i]=l0;
// n3[1][i]=l1;
// if(s3[i]=='0')l0=i;
// else l1=i;
// }
// st[0][3]=l0;st[1][3]=l1;
// int np=st[0][1],nq=st[0][2],nr=st[0][3],nans=0;
// ans.clear();
// while(np<4*n&&nq<4*n&&nr<4*n){
// nans++;ans+=s1[np];
// if(max(n1[0][np],max(n2[0][nq],n3[0][nr]))<max(n1[1][np],max(n2[1][nq],n3[1][nr])))np=n1[0][np],nq=n2[0][nq],nr=n3[0][nr];
// else np=n1[1][np],nq=n2[1][nq],nr=n3[1][nr];
// }
// if(nans>=2*n+1){
// for(int i=0;i<=2*n;i++)printf("%c",ans[i]);printf("\n");
// continue;
// }
// np=st[1][1],nq=st[1][2],nr=st[1][3],nans=0;
// ans.clear();
// while(np<4*n&&nq<4*n&&nr<4*n){
// nans++;ans+=s1[np];
// if(max(n1[0][np],max(n2[0][nq],n3[0][nr]))<max(n1[1][np],max(n2[1][nq],n3[1][nr])))np=n1[0][np],nq=n2[0][nq],nr=n3[0][nr];
// else np=n1[1][np],nq=n2[1][nq],nr=n3[1][nr];
// }
//
// for(int i=0;i<=2*n;i++)printf("%c",ans[i]);printf("\n");
*/ | #include <bits/stdc++.h>
using namespace std;
int main() {
int n,t;
string s;
cin >> t;
for(int i=0; i<t; i++) {
cin >> n >> s >> s >> s;
for(int i=0; i<n; i++) cout << 0;
for(int i=0; i<n; i++) cout << 1;
cout << 0 << endl;
}
} |
/*
* @Author: RBQRBQ
* @Date: 2020-11-16 10:14:40
* @LastEditors: RBQRBQ
* @LastEditTime: 2020-11-16 10:36:16
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef pair<int,int> pii;
namespace IO{
template<typename T>inline void read(T &x){
x=0;ll f=1;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-f;ch=getchar();}
while(isdigit(ch)){x=x*10+ch-48;ch=getchar();}
x=x*f;
}
}
using namespace IO;
const int maxn (200);
string s[maxn];
double point[maxn];
int mp[maxn][maxn];
int dp[maxn][maxn];
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>s[i];
s[i]=" "+s[i];
}
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
if(s[i][j]=='1') mp[i][j]=1;
for(int i=1;i<=n;i++) mp[i][i]=1;
for(int k=1;k<=n;k++)
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
mp[i][j]=mp[i][j]|(mp[i][k]&mp[k][j]);
double ans=.0;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
point[i]+=mp[j][i];
for(int i=1;i<=n;i++){
ans+=(double)(1.0)/(double)(point[i]);}
cout<<fixed<<setprecision(10);
cout<<ans;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int,int>;
#define ff first
#define se second
#define pb push_back
#define all(x) (x).begin(),(x).end()
const int mod = 1e9+7;
const int inf = 1e9;
const int mx = 1e6+5;
int getsolve(int x){
int ans = 0;
for(int i=-200; i<=x; i++){
int sum = 0;
for(int j=i; j<=x; j++){
sum += j;
if(sum >= x) break;
}ans += (sum == x);
}return ans;
}
int add(ll x){
if(x&1) return 1;
return 0;
}
void solve(int cs){
// cout << "Case " << cs << ": ";
ll x; cin >> x; ll ans = 0;
for(int i=1; i*1LL*i<=x; i++){
if(x%i) continue;
ans += add(i);
if(i != (x/i))
ans += add(x/i);
}ans <<= 1;
cout << ans << "\n";
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
int tc = 1, cs = 1;
// cin >> tc;
while(tc--) solve(cs++);
return 0;
}
|
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
int main()
{
ll n,i,j,k;
ll a=0,b=0,c=0;
ll ci=0;
ll cs=0;
scanf("%lld",&n);
while(n)
{
k=n%10;
ci+=k;
cs++;
if(k%3==0)
a++;
if(k%3==1)
b++;
if(k%3==2)
c++;
n/=10;
}
//printf("%lld\n",cs);
if(ci%3==0)
printf("0\n");
else if(ci%3==1)
{
if(b>0)
{
cs--;
if(cs)
printf("1\n");
else
printf("-1\n");
}
else if(c>1)
{
cs-=2;
if(cs)
printf("2\n");
else
printf("-1\n");
}
else
printf("-1\n");
}
else
{
if(c>0)
{
cs--;
if(cs)
printf("1\n");
else
printf("-1\n");
}
else if(b>1)
{
cs-=2;
if(cs)
printf("2\n");
else
printf("-1\n");
}
else
printf("-1\n");
}
return 0;
}
| #include <bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
#ifdef CLION
freopen("in.txt", "rt", stdin);
freopen("out.txt", "w", stdout);
#endif
int cnt = 0;
int num;
cin>>num;
while (true){
if(num%100==0&&cnt!=0){
break;
}
cnt++;
num++;
}
cout<<cnt<<endl;
} |
#include <cstdio>
int n;
int a[505];
int ans[250005],len;
inline void swap(int &a,int &b) {
int tmp=a;
a=b;
b=tmp;
}
int p=1;
void doSwap(int pos) {
if(p%2==1) {
int x=0;
if(2*x+1==pos || 2*x+2==pos) {
x^=1;
}
swap(a[2*x+1],a[2*x+2]);
ans[++len]=2*x+1;
p++;
}else {
if(pos==2 || pos==3) {
swap(a[4],a[5]);
ans[++len]=4;
p++;
}else {
swap(a[2],a[3]);
ans[++len]=2;
p++;
}
}
}
void sortSwap4() {
if(a[4]==4) {
return;
}
int pos=0;
for(int j=1;j<=4;j++) {
if(a[j]==4) {
pos=j;
break;
}
}
if(pos==1) {
if(p%2==0) {
swap(a[2],a[3]);
ans[++len]=2;
p++;
}
swap(a[1],a[2]);
ans[++len]=1;
swap(a[2],a[3]);
ans[++len]=2;
swap(a[3],a[4]);
ans[++len]=3;
p++;
}else if(pos==2) {
if(p%2==1) {
swap(a[3],a[4]);
ans[++len]=3;
p++;
}
swap(a[2],a[3]);
ans[++len]=2;
swap(a[3],a[4]);
ans[++len]=3;
}else if(pos==3) {
if(p%2==0) {
swap(a[2],a[3]);
ans[++len]=2;
swap(a[3],a[4]);
ans[++len]=3;
swap(a[2],a[3]);
ans[++len]=2;
swap(a[3],a[4]);
ans[++len]=3;
}else {
swap(a[3],a[4]);
ans[++len]=3;
p++;
}
}
}
int main() {
int T;
scanf("%d",&T);
while(T--) {
scanf("%d",&n);
for(int i=1;i<=n;i++) {
scanf("%d",&a[i]);
}
if(n==2) {
if(a[1]!=1) {
swap(a[1],a[2]);
printf("1\n1\n");
}else {
printf("0\n\n");
}
continue;
}
len=0;
p=1;
for(int i=n;i>=5;i--) {
int pos=0;
for(int j=1;j<=n;j++) {
if(a[j]==i) {
pos=j;
break;
}
}
if((pos%2==0 && p%2==1) || (pos%2==1 && p%2==0)) {
doSwap(pos);
}
//printf("Value at position %d: %d\n",pos,a[pos]);
for(int j=pos;j<i;j++) {
swap(a[j],a[j+1]);
ans[++len]=j;
p++;
}
//printf("Stage 1 level %d: ",i);
}
//Sort 1-4
if(n>=4) {
sortSwap4();
}
//Sort 1-3
while(a[1]!=1 || a[2]!=2 || a[3]!=3) {
if(p%2==1) {
swap(a[1],a[2]);
ans[++len]=1;
p++;
}else {
swap(a[2],a[3]);
ans[++len]=2;
p++;
}
}
printf("%d\n",len);
for(int i=1;i<=len;i++) {
printf("%d ",ans[i]);
}
printf("\n");
}
return 0;
} | #include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>
using namespace std;
/* Defines begin */
#define fastio ios_base::sync_with_stdio(false), cin.tie(NULL) , cout.tie(NULL), cout<<fixed<<setprecision(20);
#define w1 solve();
#define for0(i, n) for (int i = 0; i < (int)(n); ++i) // 0 based indexing
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i) // 1 based indexing
#define forc(i, l, r) for (int i = (int)(l); i <= (int)(r); ++i) // closed interver from l to r r inclusive
#define forr0(i, n) for (int i = (int)(n) - 1; i >= 0; --i) // reverse 0 based.
#define forr1(i, n) for (int i = (int)(n); i >= 1; --i) // reverse 1 based
#define tr(it, x) for(auto it = x.begin(); it != x.end(); it++) //traversal for vector, set, pair, map
#define all(x) (x).begin(), (x).end() //Forward traversal
#define rall(x) (x).rbegin, (x).rend() //reverse traversal
#define cinvi0(a,n) vi a(n); for0(i,n) { cin>>a[i]; }
#define cinvs0(s,n) vs s(n); for0(i,n) { cin>>s[i]; }
#define cinvd0(a,n) vd a(n); for0(i,n) { cin>>a[i]; }
//short hand for usual tokens
#define pb push_back
#define mp make_pair
#define double long double
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define endl '\n'
//debugger
#define LOCAL
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
/* Defines end */
/* Constants begin */
const long long inf = 2e18 + 7;
const long long mod = 1e9 + 7;
const double eps = 1e-7;
const double PI = 2*acos(0.0);
const double E = 2.71828;
/* Constants end */
/* Typedef begin */
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pi;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<string> vs;
/* Typedef end */
/* Template begin */
//Short hand for token
template <class T> using V = vector<T>; // all type of vector regardless of class
template <class T> using VV = V<V<T>>; // all type of vector inside of vector regardless of class
//Debugger stuff
template <typename Arg1>
void __f(const char* name, Arg1&& arg1)
{
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args)
{
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
/* Template end */
//Set reminder
// x << b is equal to x * (2)^b
// x >> b is equal to x / (2)^b
// bitset<8>(x) is equal to binary number of specific x
void solve()
{
int n; cin >> n;
int cnt = 0;
int temp = 0;
while(temp < n)
{
if(temp <= n)
temp += 100;
cnt++;
}
cout << cnt << "\n";
}
auto main() -> int
{
fastio
w1
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ppb pop_back
#define make make_pair
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long int ll;
typedef double dd;
#define test int t;cin>>t;while(t--)
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fr(j,a,b) for(ll j=a;j>=b;j--)
#define ln cout<<"\n";
#define se second
#define fi first
#define vll vector<ll>
using namespace std;
const ll mod=1e9+7;
const ll MAX=LLONG_MAX;
const ll MIN=LLONG_MIN;
int main()
{FAST;
ll n,q;
cin>>n>>q;
ll a[n];
f(i,0,n)
cin>>a[i];
ll pref[n];
for(ll i=0;i<n;i++)
{
if(i==0)
{
pref[i]=a[i]-1;
}
else
{
pref[i]=a[i]-1-(i);
}
}
while(q--)
{
ll x;
cin>>x;
if(x>pref[n-1])
{
cout<<a[n-1]+(x-pref[n-1])<<"\n";
}
else
{
ll k=lower_bound(pref,pref+n,x)-pref;
ll ans=(a[k]-1)-(pref[k]-x);
cout<<ans<<"\n";
}
}
return 0;
} | #include <bitset>
#include <iostream>
#include <climits>
#include <vector>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <bitset>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stdio.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
#define mp(x, y) make_pair(x, y)
typedef queue<int> qi;
typedef queue<string> qs;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define repp(i, a, b) for(int i = (a); i <= (b); i++)
#define repm(i, n) for(int i=n; i >= 0; i--)
#define all(v) v.begin(), v.end()
//sort( all(v) ) などと使える
//nが素数かをO(√n)で判断
bool is_prime(int n) {
bool res = true;
if (n == 1) return false;
else if (n == 2) return true;
else {
for (int i = 2; i * i <= n; i++) {
if (n % i == 0) {
res = false;
break;
}
}
}
return res;
}
int perm(int n, int r) {
if (r == 1) return n;
return n * perm(n - 1, r - 1);
}
int fact(int n) {
if (n == 1) return 1;
return fact(n - 1) * n;
}
int comb(int n, int r) {
int a = min(n, r), b = max(n, r);
return perm(a, b) / fact(a);
}
//aの逆元 (a^(-1))を求める
ll inv_mod(ll a, ll mod) {
ll b = mod, u = 1, v = 0;
while (b) {
ll t = a / b;
a -= t * b; swap(a, b);
u -= t * v; swap(u, v);
}
u %= mod;
if (u < 0) u += mod;
return u;
}
//n!
ll fact_mod(ll n, ll mod) {
ll f = 1; for (int i = 2; i <= n; i++) f = f * (i % mod) % mod;
return f;
}
ll pow_mod(ll x, ll n, ll mod) {
ll res = 1;
while (n > 0) {
if (n & 1) res = (res * x) % mod;
x = (x * x) % mod;
n >>= 1;
}
return res;
}
ll my_pow(ll x, ll n) {
ll res = 1;
while (n > 0) {
if (n & 1) res = (res * x);
x = (x * x);
n >>= 1;
}
return res;
}
// nCr
ll comb_mod(ll n, ll r, ll mod) {
if (r > n - r) r = n - r;
if (r == 0) return 1;
ll a = 1;
for (int i = 0; i < r; i++) a = a * ((n - i) % mod) % mod;
ll b = pow_mod(fact_mod(r, mod), mod - 2, mod);
return (a % mod) * (b % mod) % mod;
}
//bool v included in S
bool contain(int v, int s) {
return s & (1 << v);
}
//unionFind
/*
int n;
struct unionFind{
vector<int> par,R;
unionFind(int n){
par.resize(n);
r.resize(n);
init(n);
}
void init(int n){
for(int i = 0; i < n; i++) par[i] = i;
for(int i = 0; i < n; i++) R[i] = 0;
}
int find(int x){
if(par[x] == x) return x;
else return find(par[x]);
}
void unite(int x,int y){
rx = find(x);
ry = find(y);
if(rx == rx) return;
if(R[rx] < R[ry]){
par[rx] = y;
}else{
par[ry] = rx;
if(R[rx] == R[ry]) R[rx]++;
}
}
bool same(int x,int y){
return find(x) == find(y);
}
};
*/
#define P pair<int, int>
//int: 2,147,483,647;
//ll 9,223,372,036,854,775,80
//小数点以下15コまで出力
//cout << fixed << setprecision(15);
const int INF = 1e9;
const ll LINF = 1e18;
int main() {
ll N;
cin >> N;
for (ll b = 1; b <= 26; b++) {
if (my_pow(5, b) >= N) break;
for (ll a = 1; a <= 38; a++) {
if (my_pow(3, a) + my_pow(5, b) > N) break;
if (my_pow(3, a) + my_pow(5, b) == N) {
cout << a << " " << b << endl;
return 0;
}
}
}
cout << -1 << endl;
return 0;
} |
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//namespace mp=boost::multiprecision;
//#define mulint mp::cpp_int
//#define mulfloat mp::cpp_dec_float_100
//#include<atcoder/all>
//using namespace atcoder;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define flc(x) __builtin_popcountll(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define vec vector<lint>
#define nep(x) next_permutation(all(x))
typedef long long lint;
typedef __int128_t llint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=3e5+5;
//vector<int> bucket[MAX_N/1000];
//constexpr int MOD=1000000007;
constexpr int MOD=998244353;
lint inverse(int *A,int N){
lint ans=0;
lint a[N+1000]={};
rep(i,N){
for(int j=A[i];j;j-=(j&(-j))) ans-=a[j];ans+=i;
for(int j=A[i];j<=N;j+=(j&(-j))) a[j]++;
}
return ans;
}
int main(void){
lint N;
cin >> N;
int A[N];
rep(i,N) cin >> A[i],A[i]++;
lint ans=inverse(A,N);
cout << ans << endl;
rep(i,N-1){
ans+=N+1-A[i]*2;
cout << ans << endl;
}
} | #include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std; using ll = long long;
using ull = unsigned long long; using P = pair<int, int>;
const int INF = 1e9; const int MOD = 1000000007;
const int dx[] = {-1,0,1,0}; const int dy[] = {0,-1,0,1};
// const int dx[] = {-1,-1,-1, 0, 0, 1, 1, 1}; const int dy[] = {-1, 0, 1,-1, 1,-1, 0, 1};
#define PI 3.14159265358979323846264338327950L
// static const double e = 2.718281828459045;
//cout << fixed << setprecision(10) << ans << endl;
vector<ll> A, B;
struct UnionFind {
vector<int> par, rnk, mem;
vector<ll> sum_a, sum_b;
UnionFind(int n) {
par.resize(n); fill(par.begin(), par.end(), -1);
rnk.resize(n); fill(rnk.begin(), rnk.end(), 0);
mem.resize(n); fill(mem.begin(), mem.end(), 1);
sum_a.resize(n);
rep(i, n) sum_a[i] = A[i];
sum_b.resize(n);
rep(i, n) sum_b[i] = B[i];
}
int root(int x) {
if (par[x] < 0) return x;
else return par[x] = root(par[x]);
}
bool issame(int x, int y) {
return root(x) == root(y);
}
void merge(int x, int y) {
x = root(x); y = root(y);
if (x == y) return;
if (rnk[x] < rnk[y]) {
par[x] = y; mem[y] += mem[x];
sum_a[y] += sum_a[x];
sum_b[y] += sum_b[x];
} else {
par[y] = x; mem[x] += mem[y];
sum_a[x] += sum_a[y];
sum_b[x] += sum_b[y];
if (rnk[x] == rnk[y]) rnk[x]++;
}
}
int size(int x) {
return mem[root(x)];
}
ll size_a(int x) {
return sum_a[root(x)];
}
ll size_b(int x) {
return sum_b[root(x)];
}
};
int main() {
int N, M; cin >> N >> M;
A.resize(N); B.resize(N);
rep(i, N) cin >> A[i];
rep(i, N) cin >> B[i];
UnionFind uf(N);
rep(i, M) {
int c, d; cin >> c >> d; c--; d--;
uf.merge(c, d);
}
int flg = 1;
rep(i, N) {
if (uf.size_a(i) != uf.size_b(i)) flg = 0;
}
if (flg == 1) cout << "Yes" << endl;
else cout << "No" << endl;
} |
#include <algorithm>
#include <iostream>
#include <stack>
#include <queue>
#include <math.h>
#include <cmath>
#include <string>
#include <string.h>
#include <iterator>
#include <map>
#include <set>
#include <iomanip>
#include <vector>
#include <cstdint>
#include <time.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
#define rep(i, N) for (int i = 0; i < N; i++)
#define rep2(i, l, r) for (ll i = (ll)l; i < (ll)(r); i++)
#define INF 1000000000
#define MAX 200001
#define PI 3.141592653589793
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
const ll MOD = 1000000007;
/*clock_t start = clock();
clock_t end = clock();
const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
printf("%lf", time);*/
template <typename T > inline string toString(const T &a) {ostringstream oss; oss << a; return oss.str();};
int main(){
int N,M,T;
cin >> N >> M >> T;
int MAX_N = N;
int now = 0;
rep(i,M){
int A,B;
cin >> A >> B;
N -= A-now;
if(N <= 0){
cout << "No" << endl;
return 0;
}
N += B-A;
N = min(MAX_N,N);
now = B;
if(i == M-1 && N <= T-B){
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
} | #include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main() {
int n,m,t;
cin>>n>>m>>t;
int prev_t = 0;
int curr = n;
for(int i=0;i<m;i++){
int a, b;
cin>>a>>b;
curr = max(curr-(a-prev_t)*1,0);
if(curr==0){
cout<<"No"<<endl;
return 0;
}
curr = min(curr+(b-a)*1, n );
prev_t = b;
}
curr = curr - (t-prev_t)*1;
if(curr>0) cout<<"Yes";
else cout<<"No";
return 0;
} |
#include <iostream>
#include <vector>
#include <set>
using namespace std;
using pairint = pair<int, int>;
int main(void){
int N, M, Abuf, Bbuf;
vector<int> dp;
vector<vector<int>> cgroups;
vector<pairint> upperbits;
vector<int> birank;
cin >> N >> M;
int numid = 1<<N;
upperbits.assign(numid, pairint(0, 0));
birank.assign(numid, 0);
cgroups.assign(N, {});
for(int i=0; i<N; i++)upperbits[1<<i].first=i;
for(int i=1; i<numid; i++){
if(upperbits[i].first==0)upperbits[i].first=upperbits[i-1].first;
upperbits[i].second=upperbits[i-(1<<upperbits[i].first)].first;
birank[i]=birank[i-(1<<upperbits[i].first)]+1;
}
dp.assign(numid, 0);
for(int i=1; i<numid; i<<=1){
dp[i]=1;
for(int j=i<<1; j<numid; j<<=1)dp[i+j]=2;
}
for(int i=0; i<M; i++){
cin >> Abuf >> Bbuf;
Abuf--;
Bbuf--;
int id = (1<<Abuf)+(1<<Bbuf);
dp[id]=1;
cgroups[Bbuf].push_back(id);
}
for(int i=1; i<numid; i++){
if(dp[(1<<upperbits[i].first)+(1<<upperbits[i].second)]!=1)continue;
if(dp[i-(1<<upperbits[i].first)]!=1)continue;
if(dp[i-(1<<upperbits[i].second)]!=1)continue;
dp[i]=1;
cgroups[upperbits[i].first].push_back(i);
}
for(int i=3; i<numid; i++){
if(dp[i]==1)continue;
int j = 1<<upperbits[i].first;
if(dp[i-j]==1){
dp[i]=2;
continue;
}
bool dividable = false;
for(int id: cgroups[upperbits[i].first]){
int jd = id-j;
if(jd != (i&jd))continue;
int kd = i&(~id);
if(dp[jd+kd] == dp[kd]+1){
dp[i] = dp[kd]+1;
dividable = true;
break;
}
}
if(!dividable)dp[i] = dp[i-j]+1;
}
cout << dp[numid-1] << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define loop(i,n) for(ll i=0;i<n;i++)
#define loop1(i,n) for(ll i=1;i<=n;i++)
#define fast_az_fck ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mod 1000000007
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
// http://xorshift.di.unimi.it/splitmix64.c
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
//template<class T, class H>using umap=unordered_map<T,H,custom_hash>;
void init_code()
{
fast_az_fck
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE
}
int main()
{
init_code();
ll t=1;
//cin>>t;
while(t--)
{
ll a,b;cin>>a>>b;
if(a>=b)
{
ll sum1=(a*(a+1))/2;
ll sum2=-sum1;
ll sum3=-((b*(b-1))/2);
for(ll i=1;i<=a;i++)
{
cout<<i<<" ";
}
for(ll i=-1;i>-b;i--)
{
cout<<i<<" ";
}
cout<<(sum2-sum3);
}
else
{
ll sum1=-((b*(b+1))/2);
ll sum2=-sum1;
ll sum3=((a*(a-1))/2);
for(ll i=-1;i>=-b;i--)
{
cout<<i<<" ";
}
for(ll i=1;i<a;i++)
{
cout<<i<<" ";
}
cout<<(sum2-sum3);
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll MOD = 1000000007;
int main() {
int n, m;
cin >> n >> m;
vector<int> w(n);
vector<int> sums(1 << n), mn(1 << n);
REP(i, n) cin >> w[i];
int mx = *max_element(w.begin(), w.end());
for (int s = 0; s < (1 << n); s++) {
int x = 0;
REP(j, n) if (s >> j & 1) x += w[j];
sums[s] = x;
}
REP(i, m) {
int l, v;
cin >> l >> v;
if (v < mx) {
cout << -1 << endl;
return 0;
}
for (int s = 0; s < (1 << n); ++s)
if (sums[s] > v) mn[s] = max(mn[s], l);
}
int ans = 1e9;
vector<int> perm(n);
iota(perm.begin(), perm.end(), 0);
do {
vector<int> pos(n);
REP(i, n) {
int s = 1 << perm[i];
for (int j = i - 1; j >= 0; j--) {
s |= 1 << perm[j];
pos[i] = max(pos[i], pos[j] + mn[s]);
}
}
ans = min(ans, pos[n - 1]);
} while (next_permutation(perm.begin(), perm.end()));
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
int main(){
int N, M;
cin >> N >> M;
vector<int> w(N);
for (int i = 0; i < N; i++){
cin >> w[i];
}
vector<int> l(M), v(M);
for (int i = 0; i < M; i++){
cin >> l[i] >> v[i];
}
vector<pair<int, int>> P(M + 1);
for (int i = 0; i < M; i++){
P[i] = make_pair(v[i], l[i]);
}
P[M] = make_pair(0, 0);
sort(P.begin(), P.end());
for (int i = 0; i < M; i++){
P[i + 1].second = max(P[i + 1].second, P[i].second);
}
int wmax = *max_element(w.begin(), w.end());
int vmin = *min_element(v.begin(), v.end());
if (wmax > vmin){
cout << -1 << endl;
} else {
long long ans = INF;
vector<int> p(N);
for (int i = 0; i < N; i++){
p[i] = i;
}
while (1){
vector<long long> w2(N);
for (int i = 0; i < N; i++){
w2[i] = w[p[i]];
}
vector<long long> S(N + 1);
S[0] = 0;
for (int i = 0; i < N; i++){
S[i + 1] = S[i] + w2[i];
}
vector<long long> x(N);
x[0] = 0;
for (int i = 1; i < N; i++){
long long minx = x[i - 1];
for (int j = 0; j < i; j++){
int wsum = S[i + 1] - S[j];
auto itr = lower_bound(P.begin(), P.end(), make_pair(wsum, -INF)) - 1;
long long d = (*itr).second;
minx = max(minx, x[j] + d);
}
x[i] = minx;
}
ans = min(ans, x[N - 1]);
if (!next_permutation(p.begin(), p.end())){
break;
}
}
cout << ans << endl;
}
} |
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define int long long
#define F(i, n) for (int i = 0; i < n; i++)
#define all(x)(x).begin(), (x).end()
#define show(A) for (auto i: A) cout << i << " "; cout << '\n';
#define show_(A, n) F(i, n) { show(A[i]) }
using namespace std;
using ld = long double;
using vi = vector < int > ;
using mi = map < int, int > ;
using pi = pair < int, int > ;
const int N = 100005;
const int MOD = 1e9 + 7;
const int inf = 1e18 + 1;
/***************************code begins here*****************************/
vector<vi> adj;
void dijkstra(int s, vector<int> & d, vector<int> & p) {
int n = adj.size();
d.assign(n, 1e9);
p.assign(n, -1);
d[s] = 0;
set<pair<int, int>> q;
q.insert({0, s});
while (!q.empty()) {
int v = q.begin()->second;
q.erase(q.begin());
for (auto edge : adj[v]) {
int to = edge;
int len = 1;
if (d[v] + len < d[to]) {
q.erase({d[to], to});
d[to] = d[v] + len;
p[to] = v;
q.insert({d[to], to});
}
}
}
}
void solve() {
int n,m,k, ans = inf;
cin >> n >> m;
adj.resize(n+1);
F(i, m){
int x,y;
cin >> x >> y;
adj[x].pb(y);
adj[y].pb(x);
}
cin >> k;
vector<int> c(k+1);
vector<vi> dis(k+1);
vector<vi> vis(k+1);
F(i, k){
cin >> c[i+1];
dijkstra(c[i+1],dis[i+1],vis[i+1]);
}
int dp[(1ll<<k)][k+1];
for(int i=0;i<(1ll<<k);i++){
for(int j=0;j<=k;j++){
dp[i][j]=1e9;
}
}
for(int i=0;i<k;i++){
dp[(1ll<<i)][i+1]=1;
}
for(int i=0;i<(1ll<<k);i++){
for(int j=0;j<k;j++){
if((i&(1ll<<j))==0) continue;
int t = (i^(1ll<<j));
for(int l=0;l<k;l++){
if((t&(1ll<<l))==0) continue;
dp[i][j+1] = min(dp[i][j+1],dp[t][l+1] + dis[l+1][c[j+1]]);
}
}
}
for(int i=1;i<=k;i++){
ans = min(ans,dp[(1ll<<k)-1][i]);
}
ans = (ans>=1e9) ? -1 : ans;
cout << ans << '\n';
}
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin >> t;
while (t--) solve();
return 0;
} | #include<bits/stdc++.h>
#include<bits/extc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
using namespace __gnu_pbds;
#ifdef DEBUG
#define debug(x) {{cerr<<#x<<": "; cerr<<x<<endl;}}
#define debugv(x) {{cerr<<#x<<": "; for(auto i:x) cerr<<i<<" "; cerr<<endl;}}
#else
#define debug(x)
#define debugv(x)
#define cerr while(0) cerr
#endif
#define int long long
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define priority_queue std::priority_queue
#define F first
#define S second
ll INF=1e15;
vi adj[100005], v;
bool vis[100005];
ll dp[150000][20], dist[20][100005];
void bfs(int src, int idx){
memset(vis, false, sizeof vis);
for(int i=0;i<100005;i++) dist[idx][i]=INF;
dist[idx][src]=0;
queue<int> q;
q.push(src);
vis[src]=true;
while(!q.empty()){
int x=q.front(); q.pop();
for(int y:adj[x]){
if(vis[y]) continue;
q.push(y);
vis[y]=true;
assert(dist[idx][y]==INF);
dist[idx][y]=dist[idx][x]+1;
}
}
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
memset(dp, -1, sizeof dp);
int n, m;
cin>>n>>m;
for(int i=1;i<=m;i++){
int x, y;
cin>>x>>y;
adj[x].push_back(y);
adj[y].push_back(x);
}
int k;
cin>>k;
for(int i=0;i<k;i++) dp[1<<i][i]=1;
for(int i=1;i<=k;i++){
int x;
cin>>x;
v.push_back(x);
bfs(x, i-1);
}
vi cur;
for(int i=1;i<(1<<k);i++){
cur.clear();
if(dp[i][(int)(log2(i))]!=-1) continue;
for(int j=0;j<k;j++){
if(i&(1<<j)) cur.push_back(j);
}
cerr<<i<<" ";
for(int j:cur){
dp[i][j]=INF;
for(int k:cur){
if(j==k) continue;
dp[i][j]=min(dp[i][j], dp[i^(1<<j)][k]+dist[j][v[k]]);
}
cerr<<dp[i][j]<<" ";
}
cerr<<endl;
}
ll ans=INF;
for(int i=0;i<k;i++){
ans=min(ans, dp[(1<<k)-1][i]);
}
if(ans>=INF){
cout<<-1<<endl;
return 0;
}
cout<<ans<<endl;
} |
#include <bits/stdc++.h>
#define f(i,j,k) for(long long i=j;i<k;i++)
#define f2(i,j,k) for(long long i=j;i>=k;i--)
#define ll long long
using namespace std;
int main(){
bool j=true;
ll n,m,c,d;
cin>>n>>m;
ll a[n],b[n],ansa=0,ansb=0;
vector <ll>now(n,0);
f(i,0,n){
cin>>a[i];
}
f(i,0,n){
cin>>b[i];
if(a[i]!=b[i]){
j=false;
}
}
f(i,0,m){
cin>>c>>d;
if(now[c-1]==0){
ansa+=a[c-1];
ansb+=b[c-1];
now[c-1]++;
}
if(now[d-1]==0){
ansa+=a[d-1];
ansb+=b[d-1];
now[d-1]++;
}
}
if(ansa==ansb&&ansa!=0){
cout<<"Yes"<<endl;
}
else if(j){
cout<<"Yes"<<endl;
}
else{
cout<<"No"<<endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string s;
cin >> n >> s;
vector<int> a(n + 1);
for (auto& e : a) cin >> e;
for (int k = *max_element(a.begin(), a.end()); k >= 1; k--) {
bool valid = true;
for (int i = 0; valid && i < n; i++) {
int l1 = a[i] / k, l2, l3;
int r1 = a[i + 1] / k, r2, r3;
l2 = l3 = l1;
r2 = r3 = r1;
if (a[i] % k > a[i + 1] % k) l2++;
if (a[i] % k < a[i + 1] % k) r2++;
if (a[i] % k != 0) l3++;
if (a[i + 1] % k != 0) r3++;
if (s[i] == '<') {
valid = valid && l1 < r1 && l2 < r2 && l3 < r3;
} else {
valid = valid && l1 > r1 && l2 > r2 && l3 > r3;
}
}
if (!valid) continue;
cout << k << endl;
for (int j = 0; j < k; j++) {
for (int i = 0; i < n + 1; i++) cout << a[i] / k + (j < a[i] % k ? 1 : 0) << ' ';
cout << endl;
}
return 0;
}
return 1;
}
|
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
#define PUTS(x) std::cout << (x) << endl;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define rep3(i, m, n) for (int i = (int)(m), i##_len = (int)(n); i < i##_len; i++)
template <typename T>
inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
const Int INF = 1000000000;
struct Node {
vector<Int> to;
Int dist = INF;
};
int main() {
Int n, m;
cin >> n >> m;
auto G = vector<Node>(n);
rep(i, m) {
Int a, b;
cin >> a >> b;
a--;
b--;
G[a].to.push_back(b);
G[b].to.push_back(a);
}
Int k;
cin >> k;
auto C = vector<Int>();
rep(i, k) {
Int c;
cin >> c;
c--;
C.push_back(c);
}
auto M = 1;
rep(i, k) {
M *= 2;
}
// d[i][j]: C[i] -> C[j] の最短距離 を記録
auto d = vector<vector<Int>>(k, vector<Int>(k, 0));
rep(i, k - 1) {
auto g = G;
g[C[i]].dist = 0;
auto q = queue<Int>();
q.push(C[i]);
while (!q.empty()) {
auto j = q.front();
auto &node = g[j];
q.pop();
for (auto p : node.to) {
auto oldValue = g[p].dist;
auto newValue = g[j].dist + 1;
if (newValue < oldValue) {
g[p].dist = newValue;
q.push(p);
}
}
}
rep3(j, i + 1, k) {
d[i][j] = g[C[j]].dist;
d[j][i] = d[i][j];
}
}
// dp[i][bits] : 既に訪れた頂点の集合が bits かつ今C[i]にいるという条件を満たす最小工程
// bits は右からjビット目がC[j]を既に訪れていることを示す(C[i]自身も「既に訪れた」扱いにする)
auto dp = vector<vector<Int>>(k, vector<Int>(M, INF));
// 配るdp
function<void(Int, Int)> dfs = [&](Int current, Int bits) {
rep(i, k) {
if (((1 << i) & bits) == 0) { // まだ訪れていないC[i]について
auto nextBits = (1 << i) | bits; // C[i]を次に訪れた場合の bit flag
auto oldValue = dp[i][nextBits];
auto newValue = dp[current][bits] + d[current][i];
if (newValue < oldValue) { // 最短記録が更新されたらそこから再度DFS
dp[i][nextBits] = newValue;
dfs(i, nextBits);
}
}
}
};
// 初期値設定(C[i] のみの列はコスト1扱い)
rep(i, k) {
dp[i][1 << i] = 1;
}
// スタート
rep(i, k) {
dfs(i, 1 << i);
}
Int ans = INF;
rep(i, k) {
// M-1 = [11111...]_2 は全てのC[j]を訪れたフラグ。dp[i][M-1]は全てのC[j]を訪れて最後にC[i]に至る場合の最短列の長さを示す。
chmin(ans, dp[i][M - 1]);
}
PUTS(ans == INF ? -1 : ans)
} | #include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
const int maxk = 17;
const int maxs = (1 << maxk) + 10;
const int INF = 0x3f3f3f3f;
int n, m, k;
vector<int> E[maxn];
int c[maxk], dis[maxn], a[maxk][maxk], f[maxk][maxs];
void bfs(int x)
{
memset(dis, 0x3f, sizeof dis);
queue<int> Q;
Q.push(x); dis[x] = 0;
while(!Q.empty())
{
x = Q.front(); Q.pop();
for(auto v : E[x])
if(dis[v] == INF)
{
dis[v] = dis[x] + 1;
Q.push(v);
}
}
}
int main()
{
scanf("%d%d", &n, &m);
for(int i = 1; i <= m; ++i)
{
int u, v;
scanf("%d%d", &u, &v);
E[u].push_back(v);
E[v].push_back(u);
}
scanf("%d", &k);
for(int i = 0; i < k; ++i)
scanf("%d", &c[i]);
for(int i = 0; i < k; ++i)
{
bfs(c[i]);
for(int j = 0; j < k; ++j)
a[i][j] = dis[c[j]];
}
const int S = (1 << k) - 1;
memset(f, 0x3f, sizeof f);
for(int i = 0; i < k; ++i) f[i][1 << i] = 0;
for(int s = 1; s <= S; ++s)
for(int i = 0; i < k; ++i)
if(s & (1 << i))
{
for(int j = 0; j < k; ++j)
if(i != j && (s & (1 << j)))
f[i][s] = min(f[i][s], f[j][s ^ (1 << i)] + a[j][i]);
}
int ans = INF;
for(int i = 0; i < k; ++i)
ans = min(ans, f[i][S] + 1);
printf("%d\n", ans == INF ? -1 : ans);
return 0;
} |
#include <iostream>
#include <math.h>
typedef long double ld;
typedef long long ll;
using namespace std;
const ld eps = 1e-12;
int main() {
ll n;
cin >> n;
ll L = 1, R = 2e9;
while (L != R) {
ll M = (L + R + 1) / 2;
ll val = M * (M + 1) / 2;
if (val <= n + 1)
L = M;
else
R = M - 1;
}
cout << n - L + 1;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//typedef tree <int,null_type,less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
// #include <ext/rope>
// using namespace __gnu_cxx;
typedef long long int ll;
typedef long double ld;
#define FAST \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define rep(g, i, n) for (ll g = i; g < n; g++)
#define rev(g, n, i) for (ll g = n - 1; g >= i; g--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define mxe(v) *max_element(v.begin(), v.end())
#define mne(v) *min_element(v.begin(), v.end())
#define ve vector
#define lb lower_bound
#define ub upper_bound
#define bb break
#define cc continue
#define rem 1000000007
#define PI 3.141592653589793238462643383279502
ll power(ll x, ll y, ll p)
{
ll res = 1; // Initialize result
x = x % p; // Update x if it is more than or
while (y > 0)
{
if (y & 1)
res = (res * x) % p;
y = y >> 1; // y = y/2
x = (x * x) % p;
}
return res;
}
ll modInverse(ll n, ll p)
{
return power(n, p - 2, p);
}
struct point
{
ll x, y;
};
int main()
{
FAST
// freopen("input1.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
/*ll tests;
cin>>tests;
rep (gg,0,tests)
{}*/
ll n;
cin>>n;
ld val=17+8*n;
val=sqrt(val);
val-=3;
val/=2;
ll z=val;
ll low=max(z-100,(ll)1);
ll high=z+100;
ll ans=1e18;
rep (i,low,high)
{
ll s=(i*(i+1))/2;
ll cnt=i;
if (s>n+1)
{
break;
}
if (n+1-s>i)
{
ans=min(ans,n-(i+1)+1);
}
else
{
ans=min(ans,n-i+1);
}
}
cout<<ans<<"\n";
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;
#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846
#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back
int main()
{
ll a, b, c, d;
cin >> a >> b >> c >> d;
PR(a*d-b*c);
return 0;
}
/*
*/ | #include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
//#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <time.h>
//#include <chrono>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <iostream>
#include <limits>
#include <numeric>
#include <sstream> // std::stringstream
#include <bitset> // std::bitset<N>
//#include <type_traits>
//#include <atcoder/scc>
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define RFOR(i,a,b) for(ll i=b-1;i>=a;i--)
#define INF 1000000001
#define MOD 1000000007
#define SORT(s) sort(s.begin(), s.end());
#define REVERSE(s) reverse(s.begin(), s.end());
#define SUM(s) accumulate(s.begin(), s.end(), 0LL);
#define P pair<ll,ll>
#define mp make_pair
#define valid(x,y,h,w) (0<=x&&x<h&&0<=y&&y<w)
//#define vint vector<int>
//#define vvint vector<vector<int>>
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define ALL(a) (a).begin(),(a).end()
//#define int ll
ll dx[4] = { 0,1,0,-1 };
ll dy[4] = { 1,0,-1,0 };
ll ndx[8] = { 0,1,0,-1, 1,1,-1,-1 };
ll ndy[8] = { 1,0,-1,0, 1,-1,-1,1 };
double pi = 3.141592653589793;
using namespace std;
int main() {
int n;
cin >> n;
vll a(n);
rep(i, n) {
cin >> a[i];
}
SORT(a);
vll im(n);
rep(i, n) {
if (i == 0) {
im[0] = a[0];
}
else {
im[i] = im[i - 1] + a[i];
}
}
//x=0
ll ans = im[n - 1] * 2;
rep(i, n) {
ll x2 = a[i];
ans = min(ans, n * x2 + im[n - 1] * 2
- 2 * (im[i] + x2 * (n - i - 1)));
}
cout << std::fixed << std::setprecision(15) << (double)ans / (n*2) << endl;
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
ll n; cin>>n;
vector<ll> t(n),p(n),s(n);
ll ans=1e9;
ll none=1;
for(int i=0; i<n; i++){
cin>>t[i]>>p[i]>>s[i];
if(s[i]-t[i]>0){
none=0;
ans = min(ans,p[i]);
}
}
if(none==0) cout<<ans;
else cout<<-1;
}
| #include<bits/stdc++.h>
#define INF 7F7F7F7F7F7F7F7F
using namespace std;
typedef long long ll;
int main(){
std::ios::sync_with_stdio(false);
std::cin.tie(0);
#ifdef LOCAL
freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
clock_t start,end;
start = clock();
#endif
void work();
work();
#ifdef LOCAL
end = clock();
cout<<"运行时间"<<(double)(end-start)<<"ms"<<endl;
#endif
return 0;
}
int n,m;
vector<pair<int, int>> mmap[2005];
// bool operator < (const pair<int, int>& i,const pair<int, int>& j){
// return i.second<j.second;
// }
void work(){
cin>>n>>m;
int a,b,c;
while(m--){
cin>>a>>b>>c;
mmap[a].push_back(make_pair(b,c));
}
for(int i=1;i<=n;i++){
vector<int> d(n+1,(int)1e9);
d[i]=0;
priority_queue<pair<int, int>, vector<pair<int, int>>,greater<pair<int, int>> > pq;
pq.push(make_pair(d[i],i));
int ans=1e9;
int flag=0;
while(!pq.empty()){
auto topp=pq.top();pq.pop();
// cout<<topp.second<<endl;
for(auto j:mmap[topp.second]){
if(j.first==i) {
ans=min(d[topp.second]+j.second,ans);
}
if(d[j.first]>d[topp.second]+j.second){
d[j.first]=d[topp.second]+j.second;
pq.push(make_pair(d[j.first],j.first));
}
}
if(ans<d[topp.second]) break;
}
if(ans!=int(1e9))
cout<<ans<<endl;
else cout<<-1<<endl;
}
} |
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define ALL(a) (a).begin(), (a).end()
#define min_e(v) *min_element(ALL(v))
#define max_e(v) *max_element(ALL(v))
#define order(neq_sl) [](const auto s, const auto l){return neq_sl;}
#define make_lr(v,type,l,r) vector<type> l(n+1),r(n+1);FOR(i,n){l[i+1]=l[i]+v[i];r[i+1]=r[i]+v[n-1-i];}
#define acm accumulate
#define SUM(v) accumulate(ALL(v), 0l)
#define SORT(v) sort(ALL(v))
#define P 1000000007
long powP (long a, long b) {
if (b == 1) return a;
else if (b == 0) return 1;
else if (b < 0) return powP(a, P - 1 + b);
else {
long b2 = powP(a, b/2);
b2*=b2;
b2%=P;
return (b2 * powP(a, b%2)) % P;
}
}
template <typename T>
using vec = vector<T>;
template <typename T>
using vvec = vector<vector<T>>;
/*
template <typename T>
T gcd(T a, T b) {
if (a > b) swap(a, b);
if (a == 0) return b;
return gcd(b%a, a);
}
template <typename InputItr, typename T>
T gcd(InputItr first, InputItr last, T init) {
for (; first != last; ++first) init = gcd(init, *first);
return init;
}
template <typename T>
T lcm(T a, T b) {
return (a * b / gcd(a, b)) % P;
}
template <typename InputItr, typename T>
T lcm(InputItr first, InputItr last, T init) {
for (; first != last; ++first) init = lcm(init, *first);
return init;
}
#define GCD(v) gcd(ALL(v), 0l)
#define LCM(v) lcm(ALL(v), 1l)
*/
//#define x first
//#define y second
int main() {
vec<int> p(3);
cin>>p[0]>>p[1]>>p[2];
SORT(p);
if (p[1]==0) cout<<100-p[2];
else if (p[0]==0) {
vvec<double> v(101, vec<double>(101));
v[100][100]=0;
for (int i = 99; i >= p[1]; i--) {
for (int j = 99; j >= p[2]; j--) {
v[i][j] = (v[i+1][j]*i+v[i][j+1]*j)/(i+j)+1;
}
}
cout<<setprecision(12)<<v[p[1]][p[2]];
} else {
vec<vvec<double>> v(101, vvec<double>(101, vec<double>(101)));
v[100][100][100]=0;
for (int i = 99; i >= p[0]; i--) {
for (int j = 99; j >= p[1]; j--) {
for (int k = 99; k >= p[2]; k--) {
v[i][j][k] = (v[i+1][j][k]*i+v[i][j+1][k]*j+v[i][j][k+1]*k)/(i+j+k)+1;
}
}
}
cout<<setprecision(12)<<v[p[0]][p[1]][p[2]];
}
return 0;
}
| #include <iostream>
#include <cmath>
#include <stdio.h>
#include <string.h>
#include <bits/stdc++.h>
#include <vector>
#include <array>
#include <tuple>
using namespace std;
int main() {
int A, B, C;
cin >> A >> B >> C;
double p[101][101][101];
for (int i=0; i<=100; i++){
for (int j=0; j<=100; j++){
p[i][j][100]=0.0;
p[i][100][j]=0.0;
p[100][i][j]=0.0;
}
}
for (int i=0; i<=99; i++){
for (int j=0; j<=99; j++){
for (int k=0; k<=99; k++){
p[99-i][99-j][99-k]=(p[99-i+1][99-j][99-k]+1)*(99-i)/(297-(i+j+k))+(p[99-i][99-j+1][99-k]+1)*(99-j)/(297-(i+j+k))+(p[99-i][99-j][99-k+1]+1)*(99-k)/(297-(i+j+k));
}
}
}
cout << fixed << setprecision(6) << p[A][B][C] << endl;
} |
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define bitsz(x) int(__builtin_popcount(x))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb(x) push_back(x)
#define INF 1e9
#define LINF 1e18
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
const int di[4] = {1,0,-1,0};
const int dj[4] = {0,1,0,-1};
const int mod = 1000000007;
//const int mod = 998244353;
//cout << fixed << setprecision(15);
int main() {
ll r1,c1,r2,c2; cin >> r1 >> c1 >> r2 >> c2;
if (r1==r2 && c1==c2) {
cout << 0 << endl;
return 0;
}
if (r1+c1 == r2+c2 || r1-c1 == r2-c2 || abs(r1-r2)+abs(c1-c2) <= 3) {
cout << 1 << endl;
return 0;
}
if ((r1+c1)%2 == (r2+c2)%2 || abs(r1-r2)+abs(c1-c2) <= 6 || abs((r1+c1)-(r2+c2)) <= 3 || abs((r1-c1)-(r2-c2)) <= 3) {
cout << 2 << endl;
} else {
cout << 3 << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
ll tt(ll n) {
ll res = 1;
for(ll i = 0; i < n; i++) {
res *= 2;
res %= MOD;
}
return res;
}
int main() {
ll N;
cin >> N;
char c1, c2, c3, c4;
cin >> c1 >> c2 >> c3 >> c4;
vector<ll> fib(1200);
fib.at(0) = 0;
fib.at(1) = 1;
for(ll i = 2; i < 1100; i++) {
fib.at(i) = fib.at(i - 1) + fib.at(i - 2);
fib.at(i) %= MOD;
}
if(c1 == 'A' && c4 == 'B') {
cout << 1 << endl;
return 0;
}
if(c1 == 'A' && c2 == 'A') {
cout << 1 << endl;
return 0;
}
if(c2 == 'B' && c4 == 'B') {
cout << 1 << endl;
return 0;
}
if(c2 == 'B' && c3 == 'A' && c4 == 'A') {
cout << tt(N - 3) << endl;
return 0;
}
if(c1 == 'B' && c2 == 'A' && c3 == 'B') {
cout << tt(N - 3) << endl;
return 0;
}
if(c1 == 'B' && c2 == 'B' && c3 == 'B' && c4 == 'A') {
cout << fib.at(N - 1) << endl;
return 0;
}
if(c1 == 'B' && c2 == 'B' && c3 == 'B' && c4 == 'A') {
cout << tt(N - 3) << endl;
return 0;
}
if(c1 == 'A' && c2 == 'B' && c3 == 'B' && c4 == 'A') {
cout << fib.at(N - 1) << endl;
return 0;
}
if(c1 == 'B' && c2 == 'A' && c3 == 'A' && c4 == 'A') {
cout << fib.at(N - 1) << endl;
return 0;
}
if(c1 == 'B' && c2 == 'A' && c3 == 'A' && c4 == 'B') {
cout << fib.at(N - 1) << endl;
return 0;
}
return 0;
} |
#include<bits/stdc++.h>
#define RG register
#define R RG int
#define ll long long
#define D double
#define I inline
using namespace std;
int main()
{
ll b,c;
scanf("%lld%lld",&b,&c);
if(b==0)printf("%lld\n",(c>>1)+(c-1>>1)+1);
else if(b>0)
{
printf("%lld\n",(max(c-2>>1,0ll))+(min((b<<1)-1,(c>>1)+(c-1>>1)))+(c-1>>1)+2);
}
else printf("%lld\n",(c>>1)+(min((-b<<1)-1,(c-1>>1)+(c-2>>1)))+(c-1>>1)+2);
return 0;
} | #include "bits/stdc++.h"
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
int N;
vector<int> A,B;
int solve(){
int res = 2e5;
REP(i,N) res = min(res,A[i]+B[i]);
REP(i,N){
REP(j,N){
if(i == j) continue;
res = min(res,max(A[i],B[j]));
}
}
return res;
}
int main(){
cin >> N;
A.resize(N); B.resize(N);
REP(i,N) cin >> A[i] >> B[i];
cout << solve();
return 0;
} |
#include <iostream>
#include <iomanip>
#include <vector>
#include <array>
#include <stack>
#include <queue>
#include <tuple>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <map>
#include <numeric>
#include <cassert>
#include <string>
#include <list>
using ull = unsigned long long;
using ll = long long;
#define REP(i, n) for(ll i=0;i<(ll)n;i++)
#define REPab(i,a,b)for(ll i=(ll)a;i<(ll)b;i++)
constexpr bool bitp(ull bits, ull pos) { return bits & (1ULL << pos); }
constexpr ll mod(ll val, ll m) { return (val >= 0) ? (val % m) : (val % m + m); }
template <class T> void chmin(T& a, T b) { a = std::min(a, b); }
template <class T> void chmax(T& a, T b) { a = std::max(a, b); }
ll extgcd(const ll a, const ll b, ll& x, ll& y) {ll d = a;if (b != 0) { d = extgcd(b, a % b, y, x);y -= (a / b) * x;} else { x = 1; y = 0; } return d;}
int main() {
ll N;
std::cin >> N;
std::unordered_set<ll> set;
REP(i, N) {
ll a;
std::cin >> a;
set.insert(a);
}
for (ll i = 1; i <= N;i++) {
if (set.count(i) == 0) {
std::cout << "No\n";
return 0;
}
}
std::cout << "Yes\n";
}
| #include <bits/stdc++.h>
// #include <atcoder/all>
// using namespace atcoder;
using namespace std;
#define rep2(i, m, n) for (int i = (m); i < (n); ++i)
#define rep(i, n) rep2(i, 0, n)
#define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i)
#define drep(i, n) drep2(i, n, 0)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#ifdef LOCAL
void debug_out() { cerr << endl; }
template <class Head, class... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...); }
#define debug(...) cerr << 'L' << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << 'L' << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif
template<class T> using V = vector<T>;
template<class T> using P = pair<T, T>;
using ll = long long;
using ld = long double;
using Vi = V<int>; using VVi = V<Vi>;
using Vl = V<ll>; using VVl = V<Vl>;
using Vd = V<ld>; using VVd = V<Vd>;
using Vb = V<bool>; using VVb = V<Vb>;
using Pi = P<int>;
using Pl = P<ll>;
using Pd = P<ld>;
template<class T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
template<class T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<class... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<class T> inline int sz(const T &x) { return size(x); }
template<class T> inline bool chmin(T &a, const T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T &a, const T b) { if (a < b) { a = b; return true; } return false; }
template<class T1, class T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; }
template<class T, size_t n> istream &operator>>(istream &is, array<T, n> &v) { for (auto &e : v) is >> e; return is; }
template<class T, size_t n> ostream &operator<<(ostream &os, const array<T, n> &v) { for (auto &e : v) os << e << ' '; return os; }
template<class T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<class T> inline void deduplicate(vector<T> &a) { sort(all(a)); a.erase(unique(all(a)), a.end()); }
template<class T> inline int count_between(const vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline ll cDiv(const ll x, const ll y) { return (x+y-1) / y; } // ceil(x/y)
inline int fLog2(const ll x) { assert(x > 0); return 63-__builtin_clzll(x); } // floor(log2(x))
inline int cLog2(const ll x) { assert(x > 0); return (x == 1) ? 0 : 64-__builtin_clzll(x-1); } // ceil(log2(x))
inline int popcount(const ll x) { return __builtin_popcountll(x); }
inline void fail() { cout << -1 << '\n'; exit(0); }
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
// const int INF = (1<<30) - 1;
// const ll INFll = (1ll<<60) - 1;
// const ld EPS = 1e-10;
// const ld PI = acos(-1.0);
int main() {
ll n, m; cin >> n >> m;
if (n == 1) {
if (m != 0) fail();
cout << "1 2\n";
return 0;
}
if (m < 0 || m > n-2) fail();
int k = n - 1 - m;
rep(i, k) cout << (i+1) << ' ' << (2*n-i) << '\n';
rep(i, n-k) cout << (k + 2*i + 1) << ' ' << (k + 2*i + 2) <<'\n';
}
|
#include "bits/stdc++.h"
using namespace std;
void solve(){
int a,b,c,d;
cin>>a>>b>>c>>d;
cout<<a*d-b*c<<'\n';
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t=1;
// cin>>t;
while(t--){
solve();
}
return 0;
} | #include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define ALL(obj) (obj).begin(), (obj).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; }
int dy[]={0, 0, 1, -1, 1, -1, -1, 1};
int dx[]={1, -1, 0, 0, 1, 1, -1, -1};
int main() {
cout<<fixed<<setprecision(10);
vint v(4); rep(i,4) cin>>v[i];
cout << v[0]*v[3] - v[1]*v[2] << endl;
return 0;
} |
// Template Libraries
#include <bits/stdc++.h>
using namespace std;
//Standard input
bool checkMod7(int n, int mod){
for(; n > 0; n = n / mod){
if(n % mod == 7) return true;
}
return false;
}
int main(){
int N, counter;
bool dec_flag, oct_flag;
cin >> N;
counter = N;
for(int i = N; i > 0; i--){
if(checkMod7(i, 10) || checkMod7(i, 8)) counter--;
}
cout << counter << endl;
return 0; //Must return 0 if you want to use return statement
} | #include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define vi vector<int>
#define mii map<int,int>
#define pqb priority_queue<int>
#define pqs priority_queue<int,vi,greater<int> >
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define ps(x,y) fixed<<setprecision(y)<<x
#define mk(arr,n,type) type *arr=new type[n];
#define w(x) int x; cin>>x; while(x--)
#define fo(i, n) for (int i = 0; i < n; i++)
#define Fo(i, k, n) for (int i = k; i < n; i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define endl '\n'
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
bool decimal(int n){
bool flag=0;
int l = 0;
while(n){
l = n%10;
n = n/10;
if(l==7){
flag=1; break;
}
}
if(flag) return 1;
return 0;
}
bool octal(int n){
int flag=0;
//cout << pow << endl;
while(n){
if(n%8 == 7){
flag = 1; break;
}
n = n/8;
}
if(flag) return 1;
else return 0;
}
int32_t main()
{
int c, x=INT_MAX , t, i, y, sum=0, n, m;
t = 1;
///cin >> t;
while(t--){
cin >> n ;
Fo(i, 1, n+1){
if(!decimal(i) && !octal(i))
sum++;
}
cout << sum;
}
}
|
#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(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define PRINT(a) cout << (a) << endl
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';
using ll = long long int;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
int main(){
int n;
cin >> n;
vi a(n),b(n);
REP(i,n)cin >> a[i] >> b[i];
ll ans=LINF;
REP(i,n)REP(j,n){
if(i==j){
chmin(ans, (ll)(a[i]+b[j]));
}else{
chmin(ans, (ll)max(a[i],b[j]));
}
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(int i=cc;i>=n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
using ll = long long;
const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const vector<int> dx2 = {1, 1, 1, 0, 0, 0, -1, -1, -1};
const vector<int> dy2 = {1, 0, -1, 1, -1, 0, 1, 0, -1};
const double PI = 3.1415926535;
const ll inf = 1001001001;
const ll e9 = 1000000000;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll MAX = 1000000;
const int MOD = 1000000007;
const ll big = (1ll<<60);
ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }
vector<vector<ll>>calc(vector<vector<ll>>a, vector<vector<ll>>b){
vector<vector<ll>> c(3,vector<ll>(3));
rep(i2, 0, 3){
rep(j2, 0, 3){
rep(k2, 0, 3){
c[i2][j2] += a[i2][k2]*b[k2][j2];
}
}
}
return c;
}
int main(){
int n;
cin >> n;
vector<ll>x(n),y(n);
rep(i, 0, n)cin >> x[i] >> y[i];
int m;
cin >> m;
vector<pll>op(m);
vector<vector<vector<ll>>>matrix(m+1,vector<vector<ll>>(3,vector<ll>(3)))
,accum(m+1,vector<vector<ll>>(3,vector<ll>(3)));
rep(i, 0, m){
cin >> op[i].first;
vector<vector<ll>>temp(3,vector<ll>(3));
if(op[i].first==3||op[i].first==4)cin >> op[i].second;
if(op[i].first==1){
temp[0][1] = 1;
temp[1][0] = -1;
}else if(op[i].first==2){
temp[0][1] = -1;
temp[1][0] = 1;
}else if(op[i].first==3){
temp[0][0] = -1;
temp[0][2] = 2*op[i].second;
temp[1][1] = 1;
}else{
temp[0][0] = 1;
temp[1][2] = 2*op[i].second;
temp[1][1] = -1;
}
temp[2][2] = 1;
matrix[i+1] = temp;
}
rep(i, 1, m+1){
if(i==1)accum[i] = matrix[i];
else{
accum[i] = calc(matrix[i],accum[i-1]);
}
}
int q;
cin >> q;
vector<pll>query(q);
rep(i, 0, q)cin >> query[i].first >> query[i].second;
rep(i, 0, q){
if(query[i].first==0){
cout << x[query[i].second-1] << " " << y[query[i].second-1] << endl;
}else{
ll ansx, ansy;
ansx = accum[query[i].first][0][0]*x[query[i].second-1]+
accum[query[i].first][0][1]*y[query[i].second-1]+
accum[query[i].first][0][2]*1;
ansy = accum[query[i].first][1][0]*x[query[i].second-1]+
accum[query[i].first][1][1]*y[query[i].second-1]+
accum[query[i].first][1][2]*1;
cout << ansx << " " << ansy << endl;
}
}
} |
#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()
using P = pair<int, int>;
void Main(){
int n, m;
cin >> n >> m;
vector<vector<P>> path(n);
For(i,0,m){
int a, b, c;
cin >> a >> b >> c;
path[a-1].push_back({b-1, c});
}
auto dijkstra = [&](int start, auto &graph){
vector<int> dist(n+1, 1e9);
priority_queue<P, vector<P>, greater<P>> pq;
pq.push({0, start});
while(!pq.empty()){
auto [cur, now] = pq.top();
pq.pop();
if(cur > dist[now]) continue;
for(auto [to, cost]:graph[now]){
if(dist[to] > cur + cost){
dist[to] = cur + cost;
pq.push({dist[to], to});
}
}
}
return dist[start] < 1e9 ? dist[start] : -1;
};
For(i,0,n) cout << dijkstra(i, path) << endl;
}
int main(){
Main();
/*
東方風神録は神が出てくるので当然神ゲー
*/
return 0;
} | #include <bits/stdc++.h>
using namespace std;
unsigned long long r,x,y;
int main(){
cin >> r >> x >> y;
unsigned long long target = x*x+y*y;
unsigned long long r2 = r*r;
unsigned long long ans = 0;
if(target%r2==0){
ans = target/r2;
if(sqrt(ans)!=(unsigned long long)sqrt(ans)){
cout << (unsigned long long)sqrt(ans)+1 << endl;
}else{
cout << (unsigned long long)sqrt(ans) << endl;
}
}else if(r2>target){
cout << 2 << endl;
}else{
long double tmp = (long double)target/(long double)r2;
if(sqrt(tmp)!=(long)sqrt(tmp)){
cout << (long)sqrt(tmp)+1 << endl;
}else{
cout << (long)sqrt(tmp) << endl;
}
}
return 0;
} |
// Author: wlzhouzhuan
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pb push_back
#define fir first
#define sec second
#define rep(i, l, r) for (int i = l; i <= r; i++)
#define per(i, l, r) for (int i = l; i >= r; i--)
#define mset(s, t) memset(s, t, sizeof(s))
#define mcpy(s, t) memcpy(s, t, sizeof(t))
#define poly vector<int>
#define SZ(x) (int(x.size()))
template<typename T1, typename T2> void ckmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> void ckmax(T1 &a, T2 b) { if (a < b) a = b; }
int read() {
int x = 0, f = 0; char ch = getchar();
while (!isdigit(ch)) f |= ch == '-', ch = getchar();
while (isdigit(ch)) x = 10 * x + ch - '0', ch = getchar();
return f ? -x : x;
}
template<typename T> void print(T x) {
if (x < 0) putchar('-'), x = -x;
if (x >= 10) print(x / 10);
putchar(x % 10 + '0');
}
template<typename T> void print(T x, char let) {
print(x), putchar(let);
}
const int N = 5005;
vector<int> adj[N];
bool vis[N];
int n, m;
int main() {
n = read(), m = read();
rep(i, 1, m) {
int u = read(), v = read();
adj[u].pb(v);
}
int num = 0;
rep(i, 1, n) {
rep(j, 1, n) vis[j] = 0;
queue<int> q;
q.push(i), vis[i] = 1;
while (!q.empty()) {
++num;
int u = q.front(); q.pop();
for (auto v: adj[u]) {
if (!vis[v]) {
vis[v] = 1, q.push(v);
}
}
}
}
print(num, '\n');
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using Graph = vector<vector<ll>>;
vector<bool> seen;
ll dfs(const Graph &G, ll v, ll cnt) {
seen[v] = true;
ll res = cnt;
for (auto next_v : G[v]) {
if (seen[next_v]) continue;
res = dfs(G, next_v, res)+1;
}
return res;
}
int main()
{
ll N,M;
cin >> N >> M;
Graph G(N);
for (ll i = 0; i < M; i++)
{
ll a, b;
cin >> a >> b;
a--;b--;
G[a].push_back(b);
}
ll ans = 0;
for(ll i = 0; i < N; i++){
seen.assign(2010, false);
ans += dfs(G,i,0);
}
cout << ans + N << endl;
return 0;
} |
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB emplace_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
#define DEBUG(...) {printf("[DEBUG] ");W(__VA_ARGS__);}
#else
#define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1<<20;
const int COMBINATION_SIZE = 1<<21;
LL pp[5001][5001];
int N,M;
void pre() {
pp[0][0]=1;
FOR(i,1,5000){
pp[i][0]=1;
FOR(j,1,5000){
pp[i][j]=(LL)pp[i][j-1]*i%MOD;
}
}
}
void solve() {
LL an=0;
FOR(i,1,N){
FOR(j,1,M){
if(j<M||(j==M&&i==1)){
ADD(an,pp[M-j][i-1]*(j-1)%MOD*(N-i)%MOD*pp[M][N-i-1]);
ADD(an,pp[M-j][i-1]*pp[M][N-i]);
}
}
}
W(an);
}
void input() {
R(N,M);
}
int main(){
MOD=998244353;
pre();
input();
solve();
return 0;
}
| #include <bits/stdc++.h>
#define rep0(i,r) for (int i=0,i##end=r;i<i##end;++i)
#define rep(i,l,r) for (int i=l;i<=r;++i)
#define per(i,r,l) for (int i=r;i>=l;--i)
#define ll long long
#define pb push_back
using namespace std;
const int N=5e3+3,P=998244353;
int dp[N][2],pw[N];
void upd(int x,int &y,int c){ y=(y+(ll)x*c)%P; }
int main(){
int n,m,ans=0; cin>>n>>m;
pw[0]=1; rep(i,1,n) pw[i]=(ll)pw[i-1]*m%P;
rep(v,1,m){
dp[0][0]=1;//count
rep(i,1,n) dp[i][0]=dp[i][1]=0;
rep(i,1,n){
upd(dp[i-1][0],dp[i][0],m-1);
upd(dp[i-1][0],dp[i][1],1);
ans=(ans+(ll)dp[i-1][0]*pw[n-i])%P;
upd(dp[i-1][1],dp[i][0],v-1);
upd(dp[i-1][1],dp[i][1],m-v+1);
}
}
printf("%d\n",ans);
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, k, n) for (int i = k; i < (int)(n); i++)
#define repd(i, n) for (int i = n-1; i >= 0; i--)
#define rrepd(i, k, n) for (int i = n-1; i >= (int)(k); i--)
#define all(x) (x).begin(),(x).end()
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
//V,Pは大文字i,l,bは小文字
using ll = long long;
using Vi = vector<int>;
using VVi = vector<Vi>;
using Vl = vector<ll>;
using VVl = vector<Vl>;
using Vb = vector<bool>;
using VVb = vector<Vb>;
using P = pair<int,int>;
using Pl = pair<ll, ll>;
using Vs = vector<string>;
const ll mod = 1000000007;
const ll inf = 1000000000000000000;//10の18乗
#define yn {puts("Yes");}else{puts("No");}
#define dame { puts("-1"); return 0;}
int main() {
ll a,b,c;
cin >> a >> b >> c;
if(a*a+b*b<c*c) yn;
}
| #include<bits/stdc++.h>
#define pb push_back
#define mk make_pair
#define mk make_pair
#define ll long long
#define ss second
#define ff first
#define mod 1000000007
#define w(x) ll x; cin>>x; while(x--)
#define ps(x,y) fixed<<setprecision(y)<<x;
#define fo(i, j, k, in) for (ll i=j ; i<k ; i+=in)
#define re(i, j) fo(i, 0, j, 1)
#define pi acos(-1)
#define all(cont) cont.begin(), cont.end()
#define countbit(x) __builtin_popcount(x)
#define de(n) ll n;cin>>n;
#define def(a,n) ll n;cin>>n;ll a[n];re(i,n){cin>>a[i];}
#define defi(a,n,k) ll n;cin>>n; ll k;cin>>k;ll a[n];re(i,n){cin>>a[i];}
#define deb(x) cout<<#x<<"="<<x<<endl;
#define tr(it,a) for(auto it=a.begin();it!=a.end();it++)
#define nl cout<<endl;
using namespace std;
//18-1326D1 1208B 845C 912B 1009B 1350C 20C 1333C 1234D 1327C 1305B 1304B (or in matrix) 1216-C(26) 21
void cp()
{
ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
int main()
{
cp();
de(n);
ll a[n],p[n],x[n];
ll ans=LLONG_MAX;
bool f=0;
re(i,n)
{
cin>>a[i]>>p[i]>>x[i];
if(x[i]-a[i]>0)
{
f=1;
ans=min(ans,p[i]);
}
}
if(f)
cout<<ans;
else{
cout<<"-1";
}
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair <int, int> pin;
const int N = 2e5 + 5;
const ll P = 998244353LL;
int n, tot, head[N], ans[N], dis[N], fa[N], diaSon[N];
bool vis[N], inDia[N];
vector <int> son[N];
struct Edge {
int to, nxt;
} e[N << 1];
inline void add(int from, int to) {
e[++tot].to = to;
e[tot].nxt = head[from];
head[from] = tot;
}
template <typename T>
inline void read(T &X) {
char ch = 0; T op = 1;
for (X = 0; ch > '9' || ch < '0'; ch = getchar())
if (ch == '-') op = -1;
for (; ch >= '0' && ch <= '9'; ch = getchar())
X = (X * 10) + ch - '0';
X *= op;
}
void dfs(int x, int fat) {
for (int i = head[x]; i; i = e[i].nxt) {
int y = e[i].to;
if (y == fat) continue;
fa[y] = x;
dis[y] = dis[x] + 1;
dfs(y, x);
}
}
void makeFlag(int x, int fat, int b) {
if (x == b) inDia[x] = 1;
for (int i = head[x]; i; i = e[i].nxt) {
int y = e[i].to;
if (y == fat) continue;
makeFlag(y, x, b);
if (inDia[y]) inDia[x] = 1;
}
}
// void getAns(int x, int now, int b) {
// vis[x] = 1;
// if (ans[x] == 0) ans[x] = now;
// if (x == b) return;
// bool flag = 0;
// int son = 0, sonInDia = 0;
// for (int i = head[x]; i; i = e[i].nxt) {
// int y = e[i].to;
// if (y == fa[x]) continue;
// if (inDia[y]) {
// sonInDia = y;
// continue;
// }
// if (vis[y]) continue;
// flag = 1;
// son = y;
// break;
// }
// if (flag) getAns(son, now + 1, b);
// else {
// if (sonInDia == 0) getAns(fa[x], now + 1, b);
// else getAns(sonInDia, now + 1, b);
// }
// }
void getAns(int x, int now, int b) {
vis[x] = 1;
if (ans[x] == 0) ans[x] = now;
if (x == b) return;
if (!son[x].empty()) {
int nowSon = son[x][son[x].size() - 1];
son[x].pop_back();
getAns(nowSon, now + 1, b);
} else {
if (diaSon[x] == 0) getAns(fa[x], now + 1, b);
else getAns(diaSon[x], now + 1, b);
}
}
int main() {
#ifndef ONLINE_JUDGE
freopen("sample.in", "r", stdin);
clock_t st_clock = clock();
#endif
read(n);
for (int x, y, i = 1; i < n; i++) {
read(x), read(y);
add(x, y), add(y, x);
}
dis[1] = 0;
dfs(1, 0);
int a = 1;
for (int i = 2; i <= n; i++)
if (dis[i] > dis[a]) a = i;
dis[a] = 0;
dfs(a, 0);
int b = 1;
for (int i = 2; i <= n; i++)
if (dis[i] > dis[b]) b = i;
makeFlag(a, 0, b);
for (int x = 1; x <= n; x++) {
for (int i = head[x]; i; i = e[i].nxt) {
int y = e[i].to;
if (y == fa[x]) continue;
if (inDia[x] && inDia[y]) diaSon[x] = y;
else son[x].push_back(y);
}
}
getAns(a, 1, b);
for (int i = 1; i <= n; i++)
printf("%d%c", ans[i], " \n"[i == n]);
#ifndef ONLINE_JUDGE
clock_t ed_clock = clock();
printf("time = %f ms\n", (double)(ed_clock - st_clock) / CLOCKS_PER_SEC * 1000);
#endif
return 0;
} | #include <bits/stdc++.h>
using namespace std;
string sdouble(string s) {
int n = s.size();
string s2(n*2,'a');
for (int i = 0; i < n; i++) {
s2[i*2] = s[i];
s2[i*2+1] = s[i];
}
return s2;
}
string ssign(string s) {
int n = s.size();
string s2(n*2,'a');
for (int i = 0; i < n; i++) {
if (s[i] == 'A') {
s2[i*2] = 'A';
s2[i*2+1] = 'B';
}
else {
s2[i*2] = 'B';
s2[i*2+1] = 'A';
}
}
return s2;
}
int main() {
int N;
cin >> N;
int m = 1;
for (int i = 0; i < N; i++) {
m *= 2;
}
cout << m-1 << endl;
vector<string> group(m);
group[0] = "A";
int m2 = 1;
for (int i = 0; i < N; i++) {
for (int i = 0; i < m2; i++) {
group[i+m2] = ssign(group[i]);
group[i] = sdouble(group[i]);
}
m2 *= 2;
}
for (int i = 1; i < m; i++) {
cout << group[i] << endl;
}
return 0;
} |
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000007
using namespace std;
int main(){
long n;
cin >> n;
vector<long> ans;
for(int i=1;i<sqrt(n)+1;i++){
if(n%i==0){
ans.push_back(i);
if(i*i != n)ans.push_back(n/i);
}
}
sort(ans.begin(), ans.end());
rep(i,(int)ans.size()){
cout << ans[i] << endl;
while(i+1 < (int)ans.size() && ans[i] == ans[i+1])i++;
}
return 0;
} | #include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n,i;
cin >>n;
set<long long int> s;
for(i=1;i<=sqrt(n);i++){
if(n%i==0){
s.insert(i);
s.insert(n/i);
}
}
for(auto it=s.begin();it!=s.end();it++){
cout<<*it<<endl;
}
return 0;
} |
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
// #include <atcoder/all>
// using namespace atcoder;
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
using vll = vector<ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
ostream& operator<<(ostream& os, lpair& h){ os << "(" << h.first << ", " << h.second << ")"; return os;}
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void solve(){
ll A,B;
cin >> A >> B;
vll ans;
ll sum = 0;
if(A <= B){
rep(i,0,B){
ans.push_back(-(i+1));
sum += i+1;
}
rep(i,0,A-1){
ans.push_back(i+1);
sum -= i+1;
}
ans.push_back(sum);
}else{
rep(i,0,A){
ans.push_back((i+1));
sum += i+1;
}
rep(i,0,B-1){
ans.push_back(-(i+1));
sum -= i+1;
}
ans.push_back(-sum);
}
printa(ans, ans.size());
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
solve();
} | #include<bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &x){
x=0;char ch=getchar();bool f=false;
while(!isdigit(ch)){if(ch=='-'){f=true;}ch=getchar();}
while(isdigit(ch)){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
x=f?-x:x;
return ;
}
template <typename T>
inline void write(T x){
if(x<0) putchar('-'),x=-x;
if(x>9) write(x/10);
putchar(x%10^48);
return ;
}
const int N=3e5+5;
int n,m;
#define ll long long
int main(){
read(n),read(m);
if(n>m){
for(int i=1;i<=n;i++) cout<<i<<" ";
for(int i=1;i<=m-1;i++) cout<<-i<<" ";
cout<<-(n*(n+1)/2-(m-1)*(m)/2);
}
else if(m>n){
for(int i=1;i<=n-1;i++) cout<<i<<" ";
for(int i=1;i<=m;i++) cout<<-i<<" ";
cout<<-((n)*(n-1)/2-(m+1)*m/2);
}
else for(int i=1;i<=n;i++) cout<<i<<" "<<-i<<" ";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main()
{
int numa, numb;
cin >> numa >> numb;
cout << numa* 2 + 100 - numb;
return 0;
} | #include <iostream>
#include<bits/stdc++.h>
#define pb(x) push_back(x)
#define ll long long
#define fr(i, n) for(int i=0; i<n; i++)
#define fr1(i, a, b) for(int i=a; i<=b; i++)
#define fr2(i, a, b) for(int i=a; i>=b; i--)
#define srt(a) sort(a.begin(), a.end())
#define frit(it, m) for(auto it=m.begin(); it!=m.end(); it++)
#define fritr(it, m) for(auto it=m.rbegin(); it!=m.rend(); it++)
#define all(c) c.begin(), c.end()
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<long>
#define vll vector<long long>
#define MAX(a,b) (a>=b)?a:b
#define MIN(a,b) (a<=b)?a:b
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int a, b;
cin>>a>>b;
cout<<(2*a + 100)-b;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main(){
int x,y; cin>>x>>y;
if(x>y){
if(y+3>x) cout<<"Yes";
else cout<<"No";
}
else if(y>x){
if(x+3>y) cout<<"Yes";
else cout<<"No";
}
}
| #include<bits/stdc++.h>
#define ll long long int
#define mii map<int,int>
#define qi queue<int>
#define pqi priority_queue<int>
#define pqgi priority_queue<int,vector<int>,greater<int>>
#define si set<int>
#define vi vector<int>
#define vll vector<long long int>
#define vii vector<pair<int,int>>
#define mii map<int,int>
#define ii pair<int,int>
#define SYNC ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define FRE freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define f(i,a,b) for(int i=a;i<b;i++)
#define rf(j,c,d) for(int j=c;j>d;j--)
#define mod 1000000007
#define mo 998244353
#define inf 1e18
#define F first
#define S second
#define ld long double
#define INF (int)INT_MAX
#define PI 3.1415926535898
using namespace std;
const int N=1e5+5;
clock_t timeStart, timeFinish;
void timeBegin(){
timeStart = clock();
}
void timeEnd() {
timeFinish = clock();
}
void timeDuration() {
double time_taken = double(timeFinish - timeStart) / double(CLOCKS_PER_SEC);
cout << "Time taken by program is : " << fixed << time_taken << setprecision(5);
cout << " sec " << endl;
}
/*ll po(ll A,ll B)
{
ll RES=1;
while(B)
{
if(B&1)
RES*=A;
B>>=1;
A*=A;
}
return RES;
}*/
/*void sieve(int P)
{
prime[0]=0;prime[1]=0;
f(i,2,P+1)
prime[i]=1;
f(i,2,P+1)
{
if(prime[i]==1)
{
for(int j=i*i;j<P+1;j+=i)
{
prime[j]=i;
}
}
}
}*/
void solve()
{
ll x,y;
cin>>x>>y;
if(x<y)
swap(x,y);
if(x-y<3)
cout<<"Yes\n";
else cout<<"No\n";
return;
}
int main()
{
SYNC
//sieve();
int t=1;
//cin>>t;
f(i,0,t)
//cout<<"Case #"<<i+1<<":"
solve();
//timeDuration();
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000010
#define EPS 1e-9
#define F first
#define S second
#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"
typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;
signed main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin>>n;
int a[n],b[n];
rep(i,n) cin>>a[i];
rep(i,n) cin>>b[i];
int ans=0;
int mx=0;
rep(i,n){
mx=max(mx,a[i]);
ans=max(ans,mx*b[i]);
cout<<ans<<endl;
}
return 0;
}
| #include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main() {
int n;
cin >> n;
vector<P> x(n);
bool ok = false;
rep(i, n) cin >> x[i].first >> x[i].second;
for (int i = 0; i < n; i++) {
for (int j = i+1; j < n; j++) {
for (int k = j+1; k < n; k++) {
P a = P(x[i].first-x[j].first, x[i].second-x[j].second);
P b = P(x[i].first-x[k].first, x[i].second-x[k].second);
if (a.first*b.second == a.second*b.first) {
ok = true;
break;
}
}
}
}
if (ok) cout << "Yes" << endl;
else cout << "No" << endl;
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,f,n) for(ll i=(f); (i) < (n); i++)
#define repe(i,f,n) for(ll i=(f); (i) <= (n); i++)
#define repc(i,f,n) for(char i=(f); (i) <= (n); i++)
#define PI 3.14159265359
#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
#define P pair<int, int>
#define Pl pair<ll, ll>
#define dvec vector<vector<ll>>
#define OUT(x) cout << x << endl; return 0;
//printf("%.10f\n")
//cout << fixed << setprecision(10);
template<class T> inline bool chmax(T& a, T b){if (a < b) { a = b; return true; } return false;}
template<class T> inline bool chmaxe(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 ll MOD = 1000000007ll;
const ll INF = 1e+18;
const int iINF = 1e9;
const double EPS = 1e-8;
int main()
{
int N, W; cin >> N >> W;
cout << N / W << endl;
} | #include<bits/stdc++.h>
typedef uint64_t u64;
typedef int64_t i64;
typedef long double f128;
using namespace std;
template<u64 mod>
class modint{
public:
u64 val;
constexpr modint(const u64 x=0) noexcept:val(x%mod){}
constexpr u64 &value() noexcept{
return val;
}
constexpr const u64 &value() const noexcept{
return val;
}
constexpr modint operator+(const modint rhs) const noexcept{
return modint(*this)+=rhs;
}
constexpr modint operator-(const modint rhs) const noexcept{
return modint(*this)-=rhs;
}
constexpr modint operator*(const modint rhs) const noexcept{
return modint(*this)*=rhs;
}
constexpr modint operator/(const modint rhs) const noexcept{
return modint(*this)/=rhs;
}
constexpr modint operator^(const u64 rhs) const noexcept{
return modint(*this)^=rhs;
}
constexpr bool operator==(const modint rhs) const noexcept{
return (*this).val==rhs.val;
}
constexpr bool operator!=(const modint rhs) const noexcept{
return (*this).val!=rhs.val;
}
constexpr modint &operator+=(const modint rhs) noexcept{
val+=rhs.val;
if(val>=mod){
val-=mod;
}
return *this;
}
constexpr modint &operator-=(const modint rhs) noexcept{
if(val<rhs.val){
val+=mod;
}
val-=rhs.val;
return *this;
}
constexpr modint &operator*=(const modint rhs) noexcept{
val=val*rhs.val%mod;
return *this;
}
constexpr modint &operator/=(modint rhs) noexcept{
u64 exp=mod-2;
while(exp){
if(exp&1){
(*this)*=rhs;
}
rhs*=rhs;
exp>>=1;
}
return *this;
}
constexpr modint &operator^=(u64 rhs) noexcept{
modint a=(*this);
(*this)=1;
while(rhs){
if(rhs&1){
(*this)*=a;
}
a*=a;
rhs>>=1;
}
return *this;
}
friend constexpr ostream &operator<<(ostream &os,const modint &x) noexcept{
return os<<(x.val);
}
friend constexpr istream &operator>>(istream &is,modint &x) noexcept{
u64 t;
is>>t;
x=t;
return is;
}
};
template<typename T>
void scan(T& n){
cin>>n;
}
template<typename T,typename U>
void scan(pair<T,U>& p){
cin>>p.first>>p.second;
}
void scan(){}
template<typename T,class... Args>
void scan(T& n,Args&... args){
scan(n);
scan(args...);
}
template<typename T>
void scanall(T start,T end){
for(;start!=end;++start){
scan(*start);
}
}
template<typename T>
void print(T n){
cout<<n;
}
template<typename T,typename U>
void print(pair<T,U> p){
cout<<'{'<<p.first<<','<<p.second<<'}';
}
void print(){}
template<typename T,class... Args>
void print(T n,Args... args){
print(n);
print(args...);
}
template<typename T>
void println(T n){
print(n);
cout<<endl;
}
template<typename T,class... Args>
void println(T n,Args... args){
print(n,' ');
println(args...);
}
template<typename T>
void printall(T start,T end){
if(start!=end){
print(*start);
for(++start;start!=end;++start){
print(' ',*start);
}
}
cout<<endl;
}
template<typename T>
T chmax(T& n,T m){
return n=max(n,m);
}
template<typename T>
T chmin(T& n,T m){
return n=min(n,m);
}
template<typename T,typename U>
T power(T a,U n){
T res=1;
while(n){
res*=(n&1)?a:1;
a*=a;
n>>=1;
}
return res;
}
template<typename T>
struct combination{
vector<T> fact;
combination(const int Max=10000000):fact(Max+1,1){
for(int i=2;i<=Max;++i){
fact[i]=fact[i-1]*(T)i;
}
}
template<typename U>
T nCk(U n,U k){
if(n<k||n<0||k<0){
return 0;
}
return fact[n]/fact[k]/fact[n-k];
}
};
void solve();
int main(){
cout<<fixed<<setprecision(15);
bool is_multitestcase=0;
int T=1;
if(is_multitestcase){
scan(T);
}
for(int i=0;i<T;++i){
solve();
}
return 0;
}
void solve(){
typedef modint<1000000007> mint;
combination<mint> COM(3000000);
i64 N,M,K;
scan(N,M,K);
if(M+K<N){
println(0);
return;
}
println(COM.nCk(N+M,N)-COM.nCk(N+M,N-(K+1)));
} |
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
int mod = 1000000007;
int main(void){
ios::sync_with_stdio(false);
cin.tie(nullptr);
string S[3]; cin >> S[0] >> S[1] >> S[2];
map<char, int> mp;
int idx = 0;
rep(i, 3){
rep(j, S[i].length()){
if(!mp.count(S[i][j])){
mp[S[i][j]] = idx;
idx++;
}
}
}
if(mp.size() > 10) cout << "UNSOLVABLE" << endl;
else{
vector<int> vec(10, 0);
rep(i, 10) vec[i] = i;
do{
bool cont = true;
ll v[3];
rep(i, 3){
string val = "";
rep(j, S[i].length()){
val += ('0' + vec[mp[S[i][j]]]);
}
if(val[0] == '0'){
cont = false;
break;
}
v[i] = stoll(val);
}
if(cont){
if(v[0] + v[1] == v[2]){
cout << v[0] << endl;
cout << v[1] << endl;
cout << v[2] << endl;
return 0;
}
}
}while(next_permutation(vec.begin(), vec.end()));
cout << "UNSOLVABLE" << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, e) for (ll i = s; i < e; i++)
#define rrep(i, s, e) for (ll i = s; i > e; i--)
int main() {
ll A, B, W;
cin >> A >> B >> W;
W *= 1000;
ll cnt_a = W / A, cnt_b = W / B;
if (cnt_a != cnt_b) cout << cnt_b + (W % B != 0) << " " << cnt_a;
else if ((W % A) * (W % B) == 0) cout << cnt_a << " " << cnt_a;
else cout << "UNSATISFIABLE";
}
|
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <numeric>
#include <iomanip>
#include <algorithm>
using namespace std;
string rus;
int point = 0;
void move(vector<vector<int>> &mdata, vector<vector<int>> &pdata, vector<int> cdata,int x,int y,int p,int dir, string sdata){
if (point < p) {
rus = sdata;
point = p;
}
if (x > 50 || y > 50 || x <= 0 || y <= 0) {
return;
}
if (cdata.at(mdata.at(y).at(x)) == 0) {
return;
}
cdata.at(mdata.at(y).at(x)) = 0;
p = p + pdata.at(y).at(x);
if (dir == 1)
sdata += 'D';
else if (dir == 2)
sdata += 'U';
else if (dir == 3)
sdata += 'R';
else if (dir == 4)
sdata += 'L';
map<int, int> hp;
int cnt = 0;
if(cdata.at(mdata.at(y + 1).at(x)) != 0)
hp[pdata.at(y + 1).at(x)] = 1;
if (cdata.at(mdata.at(y - 1).at(x)) != 0)
hp[pdata.at(y - 1).at(x)] = 2;
if (cdata.at(mdata.at(y).at(x + 1)) != 0)
hp[pdata.at(y).at(x + 1)] = 3;
if (cdata.at(mdata.at(y).at(x - 1)) != 0)
hp[pdata.at(y).at(x - 1)] = 4;
for (auto i = hp.rbegin();i != hp.rend();i++) {
if (i->second == 1) {
move(mdata, pdata, cdata, x, y + 1, p, 1, sdata);
}
else if (i->second == 2) {
move(mdata, pdata, cdata, x, y - 1, p, 2, sdata);
}
else if (i->second == 3) {
move(mdata, pdata, cdata, x + 1, y, p, 3, sdata);
}
else {
move(mdata, pdata, cdata, x - 1, y, p, 4, sdata);
}
//cout << i->second << endl;
cnt++;
if (cnt == 1 && dir != 0) break;
}
}
int main(void) {
int sx, sy;
string sdata;
cin >> sy >> sx;
vector<int> cdata(52 * 52, 0);
vector<vector<int>> mdata(52, vector<int>(52));
vector<vector<int>> pdata(52, vector<int>(52));
for (int i = 1;i <= 50;i++) {
for (int j = 1;j <= 50;j++) {
cin >> mdata.at(i).at(j);
cdata.at(mdata.at(i).at(j)) = 1;
}
}
for (int i = 1;i <= 50;i++) {
for (int j = 1;j <= 50;j++) {
cin >> pdata.at(i).at(j);
}
}
move(mdata,pdata, cdata, sx+1, sy+1,pdata.at(sy+1).at(sx+1),0,sdata);
cout << rus << endl;
} | #include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
char c=getchar();bool f=0;x=0;
while(!isdigit(c)) f|=c=='-',c=getchar();
while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
if(f) x=-x;return x;
}
template<class t> inline void write(t x){
if(x<0) putchar('-'),write(-x);
else{if(x>9) write(x/10);putchar('0'+x%10);}
}
const int N=505;
int n,a[N],b[N],c[N][N];
signed main(){
read(n);
for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) read(c[i][j]);
for(int i=1;i<=n;i++) a[i]=c[i][1]-c[1][1];
for(int i=1;i<=n;i++) b[i]=c[1][i];
for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) if(a[i]+b[j]!=c[i][j]) return puts("No"),0;
int ma=*min_element(a+1,a+1+n),mb=*min_element(b+1,b+1+n);
if(ma+mb<0) return puts("No"),0;
puts("Yes");
for(int i=1;i<=n;i++) write(a[i]-ma),putchar(' ');puts("");
for(int i=1;i<=n;i++) write(b[i]+ma),putchar(' ');
} |
#include <bits/stdc++.h>
using namespace std;
// typedef
using ll = long long;
using str = string;
using PL = pair<ll, ll>;
using P = pair<int, int>;
using VL = vector<ll>;
using VI = vector<int>;
using VS = vector<str>;
using VP = vector<P>;
using VPL = vector<PL>;
using VVL = vector<VL>;
using VVI = vector<VI>;
// const num
const ll INF = 1e18 + 18;
const ll MAX = 100005;
const ll MOD = 1000000007;
const long double PI = acosl(-1.0);
// loop
#define REP(i, a, b) for(ll(i) = (a); (i) < (b); (i)++)
#define RREP(i, a, b) for(ll(i) = (a); (i) >= (b); (i)--)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) RREP(i, n, 0)
// YesNo
#define Yes(n) cout << ((n) ? "Yes": "No") << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
// All
#define ALL(v) v.begin(), v.end()
#define deduplicate(v) (v).erase(unique(ALL(d)), (v).end())
int main(void){
int a,b;
int asum = 0;
int bsum = 0;
cin >> a >> b;
rep(i,3){
asum += (a%10);
bsum += (b%10);
a/=10;
b/=10;
}
cout << max(asum,bsum) << endl;
return 0;
} | #define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <complex>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#include <queue>
#define INF 1010101010LL
#define INFLL 1010101010101010101LL
using namespace std;
const int mod = 1000000007;
//const int mod = 998244353;
int main()
{
string s, t;
cin >> s >> t;
int a = 0, b = 0;
for (int i = 0; i < 3; i++) {
a += s[i] - '0';
b += t[i] - '0';
}
cout << max(a, b) << endl;
return 0;
} |
// WIP
#include <bits/stdc++.h>
using namespace std;
#define ALL(X) (X).begin(), (X).end()
#define FOR(I, X, Y) for (int I = (X); I < (Y); I++)
using ll = int64_t;
using ull = uint64_t;
namespace std {
template<class ...Ts> istream& operator>>(istream& i, tuple<Ts...>& x) { apply([&](auto&&... ys){ ((i >> ys), ...); }, x); return i; }
template<class ...Ts> ostream& operator<<(ostream& o, const tuple<Ts...>& x) { o << "("; auto s = ""; apply([&](auto&&... y){ ((o << s << y, s = ", "), ...); }, x); return o << ")"; }
template<class T1, class T2> istream& operator>>(istream& i, pair<T1, T2>& x) { return i >> tie(x.first, x.second); }
template<class T1, class T2> ostream& operator<<(ostream& o, const pair<T1, T2>& x) { return o << tie(x.first, x.second); }
template<class T, class = decltype(begin(declval<T>())), class = enable_if_t<!is_same<T, string>::value>>
istream& operator>>(istream& i, T& x) { for (auto& y : x) { i >> y; } return i; }
template<class T, class = decltype(begin(declval<T>())), class = enable_if_t<!is_same<T, string>::value>>
ostream& operator<<(ostream& o, const T& x) { o << "{"; auto s = ""; for (auto& y : x) { o << s << y; s = ", "; } return o << "}"; }
}
#ifdef DEBUG
#define dbg(...) do { cout << #__VA_ARGS__ ": " << make_tuple(__VA_ARGS__) << endl; } while (0)
#define dbg2(X) do { cout << #X ":\n"; for (auto& __x : (X)) { cout << __x << endl; } } while (0)
#else
#define dbg(...)
#define dbg2(X)
#endif
using Real = long double;
// Main
void mainCase() {
int n;
cin >> n;
vector<Real> xs(n);
cin >> xs;
array<Real, 3> res = {};
for (auto x : xs) {
res[0] += abs(x);
res[1] += x * x;
res[2] = max(res[2], abs(x));
}
res[1] = sqrt(res[1]);
FOR(i, 0, 3) {
cout << setprecision(numeric_limits<Real>::digits10 + 1) << res[i] << "\n";
}
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
mainCase();
return 0;
}
/*
python misc/run.py atcoder/abc180/b/main.cpp
{{TESTS}}
*/
| #include <cstdio>
using ll = long long int;
int cnt[405];
int N;
int main(){
scanf("%d",&N);
for(int i=0;i<N;i++){
int tmp;
scanf("%d",&tmp);
cnt[tmp+200]++;
}
ll ans=0ll;
for(int i=0;i<=400;i++){
for(int j=i+1;j<=400;j++){
ll diff=j-i;
// if (cnt[i]&&cnt[j])
// printf("diff=%lld\n",diff);
ans+=(diff*diff*cnt[i]*cnt[j]);
}
}
printf("%lld\n",ans);
return 0;
} |
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
using Graph = vector<vector<int>>;
const ll INF = 1LL << 62;
const double PI = acos(-1);
const ll mod = 998244353;
const ll MOD = 1000000007;
template<class T> void chmin(T &a,T b){if(a>b)a=b;}
template<class T> void chmax(T &a,T b){if(a<b)a=b;}
int main(){
int N;cin >> N;
int ans;
if(N%100 == 0) ans = N/100;
else ans = N/100+1;
cout << ans << endl;
} | #include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// #include <atcoder/all>
/*
cd $dir && g++ -std=c++17 -Wall -Wextra -O2 -DATCODERDEBUG
-I/mnt/d/MyProjects/atcoder/lib/ac-library $fileName && echo 'compilation ok!'
&& ./a.out
*/
using namespace std;
#define REP(i, n) for (ll i = 0; i < ll(n); i++)
#define FOR(i, a, b) for (ll i = a; i <= ll(b); i++)
#define ALL(x) x.begin(), x.end()
#define dame(a) \
{ \
cout << a << endl; \
return 0; \
}
typedef long long ll;
ll __per__(ll a, ll b) {
if (a >= 0) return a % b;
return (((-a - 1LL) / b) + 1LL) * b + a;
}
class dstream : public ostream {};
template <typename T>
dstream &operator<<(dstream &os, const T &v) {
#ifdef ATCODERDEBUG
cout << "\033[1;31m" << v << "\033[0m";
#endif
return os;
}
ostream &endd(std::ostream &out) {
#ifdef ATCODERDEBUG
out << std::endl;
#endif
return out;
}
dstream dout;
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
os << "[ ";
for (auto const &x : v) {
os << x;
if (&x != &v.back()) {
os << " : ";
}
}
os << " ]";
return os;
}
ostream &operator<<(ostream &os, const vector<bool> &v) {
os << "[ ";
for (size_t i = 0; i < v.size(); i++) {
os << v[i];
if (i != v.size() - 1) {
os << " : ";
}
}
os << " ]";
return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<vector<T>> &v) {
os << "[" << endl;
for (auto const &x : v) {
os << " ";
os << x;
os << endl;
}
os << "]";
return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &v) {
os << "{" << endl;
for (auto const &x : v) {
os << " ";
os << x;
}
os << "}" << endl;
return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const unordered_map<T, U> &v) {
os << "{" << endl;
for (auto const &x : v) {
os << " ";
os << x;
}
os << "}" << endl;
return os;
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> &v) {
os << "{";
for (auto const &x : v) {
os << " ";
os << x;
}
os << " }" << endl;
return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const unordered_set<T, U> &v) {
os << "{";
for (auto const &x : v) {
os << " ";
os << x;
}
os << " }" << endl;
return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &v) {
os << v.first << " : " << v.second << endl;
return os;
}
template <typename T, typename U, typename Comp = less<>>
bool chmax(T &xmax, const U &x, Comp comp = {}) {
if (comp(xmax, x)) {
xmax = x;
return true;
}
return false;
}
template <typename T, typename U, typename Comp = less<>>
bool chmin(T &xmin, const U &x, Comp comp = {}) {
if (comp(x, xmin)) {
xmin = x;
return true;
}
return false;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll N;
cin >> N;
ll ans = (N + 99) / 100;
cout << ans << endl;
// cout << std::fixed << std::setprecision(15) << sqrt(ans) << endl;
} |
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define V vector<long long>
#define VV vector<vector<long long>>
#define VVV vector<vector<vector<long long>>>
#define P pair<ll,ll>
#define rep(i,n) for(ll (i)=0;(i)<(n);++(i))
#define per(i,n) for(ll (i)=(n)-1;(i)>=0;--(i))
#ifdef LOCAL
#define debug(x) cerr<<__LINE__<<": "<<#x<<"="<<x<<endl;
#define debugALL(x) cerr<<__LINE__<<": "<<#x<<"=";for(auto i=(x).begin();i!=--(x).end();i++)cerr<<*i<<" ";cerr<<*--(x).end()<<endl;
#else
#define debug(x) true
#define debugALL(x) true
#endif
using namespace std;
long long mod=1e9+7;
struct mint{
long long x;
mint(long long x=0):x((x%mod+mod)%mod){}
mint operator-() const{return mint(-x);}
mint& operator+=(const mint a){
if((x+=a.x)>=mod)x-=mod;
return *this;
}
mint& operator-=(const mint a){
if((x+=mod-a.x)>=mod)x-=mod;
return *this;
}
mint& operator*=(const mint a){
(x*=a.x)%=mod;
return *this;
}
mint operator+(const mint a)const{return mint(*this)+=a;}
mint operator-(const mint a)const{return mint(*this)-=a;}
mint operator*(const mint a)const{return mint(*this)*=a;}
mint pow(long long t)const{
if(!t)return 1;
mint a=pow(t>>1);
a*=a;
if(t&1)a*=*this;
return a;
}
mint inv()const{return pow(mod-2);}
mint& operator/=(const mint a){return *this*=a.inv();}
mint operator/(const mint a)const{return mint(*this)/=a;}
};
istream& operator>>(istream& is,mint& a){return is>>a.x;}
ostream& operator<<(ostream& os,const mint& a){return os<<a.x;}
int main(){
ll n;
cin>>n;
vector<vector<P>> g(n,vector<P>());
rep(i,n-1){
ll u,v,w;
cin>>u>>v>>w;
u--;v--;
g[u].emplace_back(v,w);
g[v].emplace_back(u,w);
}
stack<P> sta;
sta.emplace(0,0);
vector<bool> used(n,false);
used[0]=true;
V sum(n);
while(sta.size()){
ll now=sta.top().first;
ll w=sta.top().second;
sta.pop();
sum[now]=w;
for(auto next:g[now]){
if(used[next.first])continue;
used[next.first]=true;
sta.emplace(next.first,next.second^w);
}
}
V cnt(60,0);
rep(i,n){
rep(k,60){
if(sum[i]&1ll<<k)cnt[k]++;
}
}
V ans(60,0);
rep(i,n){
rep(k,60){
if(sum[i]&1ll<<k){
ans[k]+=n-cnt[k];
}else{
ans[k]+=cnt[k];
}
}
}
mint tmp=0;
rep(i,60){
tmp+=mint(ans[i]/2)*mint(2).pow(i);
}
cout<<tmp<<endl;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())
int main() {
ll n, m;
cin >> n >> m;
vector<vector<P>> cond(n + 1);
REP(i, m) {
ll x, y, z;
cin >> x >> y >> z;
cond[x].push_back({y, z});
}
ll N = 1LL << n;
vector<ll> dp(N, 0);
dp[0] = 1;
REP(bit, N) if (dp[bit] > 0) {
vector<ll> a;
REP(i, n) {
if (bit & (1LL << i)) {
a.push_back(i + 1);
}
}
REP(i, n) {
if (bit & (1LL << i)) {
continue;
}
bool ok = true;
for (P p : cond[SZ(a) + 1]) {
ll y = p.first, z = p.second;
ll cnt = 0;
for (ll x : a) {
if (x <= y) {
cnt++;
}
}
if (i + 1 <= y) {
cnt++;
}
if (cnt > z) {
ok = false;
break;
}
}
if (ok) {
ll nxt = bit | (1LL << i);
dp[nxt] += dp[bit];
}
}
}
cout << dp[N - 1] << endl;
} |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pii pair <int, int>
#define vi vector<int>
#define FOR(i, a, b) for (int i=a; i<b; i++)
#define FORd(i, a, b) for (int i=a-1; i>=b; i--)
#define F0Rd(i, a) for (int i=a-1; i>=0; i--)
#define F0R(i, a) for (int i=0; i<a; i++)
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
const int MOD = 1000000007;
long double PI = 4*atan(1);
/*std::cout << std::fixed << std::setprecision(2);
ll po (ll b, ll p) return !p?1:po(b*b%MOD,p/2)*(p&1?b:1)%MOD;
ll inv (ll b) { return po(b,MOD-2); }*/
ll n,a[50],frq[50],x,ans=1;
vi v[50];
bool visited[50];
void solve() {
cin >> n;
F0R(i,n) {
cin >> x;
FOR(j,2,50) {
if (x%j == 0) v[i].pb(j);
while (x%j == 0) x /= j;
}
}
// F0R(i,n) {
// for (int j:v[i]) cout << j << " ";
// cout << "\n";
// }
while (1) {
int flag = 0,MxF = 0,MxN = -1;
F0R(i,50) frq[i] = 0;
F0R(i,n) {
if (visited[i]) continue;
flag = 1;
for (int j:v[i]) frq[j]++;
}
if (!flag) break;
F0R(i,50) if (frq[i] > MxF) MxF = frq[i],MxN = i;
ans = ans*(ll)(MxN);
F0R(i,n) {
if (!visited[i]) {
for (int j:v[i]) {
if (j == MxN) visited[i] = true;
}
}
}
}
cout << ans;
}
int main()
{
ios::sync_with_stdio(0), cin.tie(0);
int test_cases = 1;
//cin >> test_cases;
F0R(i,test_cases) {
solve();
}
return 0;
} | #include<bits/stdc++.h>
using namespace std;
long long ans;
void noanswer() {
puts("-1");
exit(0);
}
int a[100005], b[100001];
struct info {
int cnt, p;
};
info seq[100001];
int tot;
void solve(int l, int r) {
int p = l-1;
while (p < r && a[p+1] > b[p+1]) ++p;
for (int i = p+1; i <= r; i++)
if (a[i] > b[i]) noanswer();
for (int i = l-1; i <= p; i++) {
if (seq[tot].p + seq[tot].cnt == a[p]) ++seq[tot].cnt;
else ++tot, seq[tot].cnt = 1, seq[tot].p = a[i];
}
for (int i = p; i >= l; i--) {
int num = 0;
while (tot > 1 && seq[tot].p + seq[tot].cnt - 1 + num > b[i]) num += seq[tot].cnt, --tot;
if (seq[tot].p + seq[tot].cnt - 1 + num != b[i]) noanswer();
ans += num, seq[tot].cnt += num-1;
}
tot = 0;
for (int i = r+1; i > p; i--) {
if (seq[tot].p - seq[tot].cnt == a[p]) ++seq[tot].cnt;
else ++tot, seq[tot].cnt = 1, seq[tot].p = a[i];
}
for (int i = p+1; i <= r; i++) {
int num = 0;
while (tot > 1 && seq[tot].p - seq[tot].cnt + 1 - num < b[i]) num += seq[tot].cnt, --tot;
if (seq[tot].p - seq[tot].cnt + 1 - num != b[i]) noanswer();
ans += num, seq[tot].cnt += num-1;
}
}
int main() {
int n, l;
cin >> n >> l;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) cin >> b[i];
a[0] = 0, a[n+1] = l+1;
int last = 1;
for (int i = 1; i <= n; i++)
if (a[i] == b[i]) {
if (last != i) solve(last, i-1);
last = i+1;
}
if (last <= n) solve(last, n);
cout << ans << endl;
} |
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define REP(i,j) for(int i=0;i<j;i++)
#define REPA(i,j) for(int i=1;i<=j;i++)
#define FORN(i,j,k) for(int i=j;i<k;i++)
#define vi vector<int>
#define vvi vector<vi >
#define pii pair<int,int>
#define vpii vector<pii >
#define all(a) a.begin(),a.end()
using namespace std;
const int INF=1<<30;
//const ll INF=1ll<<60;
const ll MOD=1e9+7;
inline void read(int &x){
// short neg=1;
x=0;
char c=getchar();
/*while(c<'0'||c>'9'){
if(c=='-')neg=-1;
c=getchar();
}*/
while(c>='0'&&c<='9'){
x=(x<<3)+(x<<1)+(c^48),c=getchar();
}
// x*=neg;
}
ll quick_mod(ll A,ll B){//A^B
ll ret=1;
A%=MOD;
while(B)
{
if(B&1)ret=ret*A%MOD;
B>>=1;
A=A*A%MOD;
}
return ret;
}
const int MAXN=1e5+10;
ll N;
ll A[MAXN];
int main(void){
cin>>N;
REP(i,N)cin>>A[i];
if(N==1){
cout<<A[0];
return 0;
}
ll X=A[0]+A[1],Y=A[0]-A[1];
ll K1=1,K2=1;
for(int i=2;i<N;i++){
ll x,y;
x=(X+A[i]*K1+Y+A[i]*K2)%MOD;
y=(MOD*1000+X-A[i]*K1)%MOD;
X=x;
Y=y;
ll k1,k2;
k1=K1+K2;
k2=K1;
K1=k1%MOD;
K2=k2%MOD;
}
cout<<(ll)(MOD*3+X+Y)%MOD;
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
long long b,c,x,y;
unsigned long long ans=0;
int main(){
scanf("%lld%lld",&b,&c);
if(c==1){
if(b==0)printf("1");
else printf("2");
return 0;
}
if(b==0)printf("%lld",c);
else if(b>0){
x=c%2;
y=c/2;
if(y>=b)ans=2*b+1;
else if(x)ans=2*y+2;
else ans=2*y+1;
x=(c-1)%2;
y=(c-1)/2;
if(x)ans+=2*y;
else ans+=2*y-1;
printf("%llu",ans);
}
else{
x=(c-1)%2;
y=(c-1)/2;
b=-b;
if(y>=b)ans=2*b+1;
else if(x)ans=2*y+2;
else ans=2*y+1;
b=-b;
x=c%2;
y=c/2;
if(x)ans+=2*y;
else ans+=2*y-1;
printf("%llu",ans);
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 10000;
int main() {
int n, m;
cin >> n >> m;
vector<int> cnt(MAX);
for (int i = 0; i < n + m; i++) {
int x;
cin >> x;
++cnt[x];
}
for (int i = 0; i < MAX; i++) {
if (cnt[i] == 1) {
cout << i << " ";
}
}
return 0;
} | #include <bits/stdc++.h>
#include<iostream>
using namespace std;
typedef long long ll;
int keta(ll n) {
return log10(n)+1;
}
ll f() {
for (int i = 0; i< 10;i++) {}
for (int j = 0; j< 10;j++) {}
ll p = 3* 2e18;
vector<ll> vec;
vec.push_back(0);
vec.back();
vec.pop_back();
for_each(vec.begin(), vec.end(), [](ll& elem) {
elem = 4;
});
return 0;
}
int main(){
ll N,M;
cin>>N>>M;
vector<ll> A,B;
for (int i = 0; i< N;i++) {
ll a;
cin>>a;
A.push_back(a);
}
for (int i = 0; i< M;i++) {
ll b;
cin>>b;
B.push_back(b);
}
reverse(A.begin(),A.end());
reverse(B.begin(),B.end());
vector<ll> C;
while (!A.empty() || !B.empty())
{
if (A.empty()) {
ll b=B.back();
C.push_back(b);
B.pop_back();
} else if (B.empty()){
ll a =A.back();
C.push_back(a);
A.pop_back();
} else {
ll a =A.back();
ll b=B.back();
if (a<b){
C.push_back(a);
A.pop_back();
} else if (a==b){
A.pop_back();
B.pop_back();
} else {
C.push_back(b);
B.pop_back();
}
}
}
ll cl = C.size();
for (int i = 0; i< cl;i++) {
cout<<C[i]<<" ";
}
cout<<endl;
return 0;
} |
// header {{{
// header {{{
using namespace std;
#include <bits/stdc++.h>
#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x, y) CPP_CAT_I(x, y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x, y) x##y
#define ASSERT(expr...) assert((expr))
using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
// }}}
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define M5 100007
#define M9 1000000000
// util {{{
#define FOR(i, start, end) for (i64 i = (start), CPP_CAT(i, xxxx_end) = (end); i < CPP_CAT(i, xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f, c, ...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ##__VA_ARGS__); })(c))
#define ll long long int
#define VI vector<int>
template <typename C>
i64 SIZE(const C &c)
{
return static_cast<i64>(c.size());
}
template <typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }
template <typename T, typename U, typename Comp = less<>>
bool chmax(T &xmax, const U &x, Comp comp = {})
{
if (comp(xmax, x))
{
xmax = x;
return true;
}
return false;
}
template <typename T, typename U, typename Comp = less<>>
bool chmin(T &xmin, const U &x, Comp comp = {})
{
if (comp(x, xmin))
{
xmin = x;
return true;
}
return false;
}
// }}}
// init {{{
struct ProconInit
{
static constexpr int IOS_PREC = 15;
static constexpr bool AUTOFLUSH = false;
ProconInit()
{
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(IOS_PREC);
if (AUTOFLUSH)
cout << unitbuf;
}
} PROCON_INIT;
// }}}
//--------------------------------------------------------------------
bool isOK(int mid, double key)
{
}
int binary_search(double key)
{
int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
int right = 2000000000;
/* どんな二分探索でもここの書き方を変えずにできる! */
while (right - left > 1)
{
int mid = left + (right - left) / 2;
if (isOK(mid, key))
right = mid;
else
left = mid;
}
/* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
return right;
}
bool isKaibun(string st)
{
bool ans = true;
int n = st.length();
REP(i, n / 2)
{
if (st[i] != st[n - i - 1])
{
return false;
}
}
return true;
}
int toInt(char a)
{
return a - '0';
}
int gcd(int a, int b)
{
if (a % b == 0)
{
return (b);
}
else
{
return (gcd(b, a % b));
}
}
int lcm(int a, int b)
{
return a * b / gcd(a, b);
}
void solve()
{
int N;
cin >> N;
vector<int> A(N);
REP(i, N)
cin >> A[i];
ll ans = -1;
ll mans = 2;
FOR(i, 2, 1001)
{
ll sum = 0;
REP(j, N)
{
if (A[j] % i == 0)
{
sum++;
}
}
if (ans < sum)
{
ans = sum;
mans = i;
}
}
cout << mans;
}
signed main()
{
solve();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using LL = long long;
const int int_inf = 1e9;
const LL ll_inf = 1e18;
const int mod = 1000000009;
template <class T>
void sort(T &v) {
std::sort(v.begin(), v.end());
}
template <class T>
void rsort(T &v) {
std::sort(v.rbegin(), v.rend());
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> a(n);
for (auto &i : a) cin >> i;
int ans = 2;
int buf = 0;
for (int i = 2; i <= 1000; i++) {
int cnt = 0;
for (int j = 0; j < n; j++) {
if (a[j] % i == 0) cnt++;
}
if (buf < cnt) {
ans = i;
buf = cnt;
}
}
cout << ans << endl;
return 0;
} |
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
using namespace std;
using llong = long long;
using vi = vector<int>;
using vvi = vector<vi >;
using vvvi = vector<vvi >;
using pii = pair<int,int>;
constexpr int INF = 1e9;
constexpr llong LINF = 1e18;
constexpr double EPS = 1e-12;
constexpr int MOD = 1e9+7;
template<class Type>
void line(const Type &a){int cnt=0;for(const auto &elem:a)cerr<<(cnt++?' ':'>')<<elem;cerr<<endl;}
using vl = vector<long long>;
using vvl = vector<vl >;
using vvvl = vector<vvl >;
using pll = pair<long long,long long>;
int main(){
int n;
cin>>n;
vl cnt(200,0);
REP(i,n){
llong a;
cin>>a;
cnt[a%200]++;
}
llong ans=0;
REP(i,200){
ans+=cnt[i]*(cnt[i]-1)/2;
}
cout<<ans<<endl;
} | #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
int main(){
int n;
ll k;
cin >> n >> k;
vector<pair<ll,ll>> friends(n);
for(int i=0;i<n;i++){
ll a,b;
cin >> a >> b;
friends[i] = make_pair(a,b);
}
sort(friends.begin(), friends.end());
ll place = 0;
int vn = 0;
while(k > 0){
place += k;
k = 0;
for(int i=vn;i<n;i++){
if(friends[i].first <= place){
k += friends[i].second;
vn = i+1;
}else{
break;
}
}
}
cout << place << endl;
} |
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define IOS std::ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
using namespace std;
// DEBUG TEMPLATE
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
void OFFLINE(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define debug(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
}
const int MOD = 1e9 + 7;
int main(){
IOS;
OFFLINE();
//check for corner test cases
int n, k;
cin >> n >> k;
vector<int> arr(n);
vector<vector<int>> brr(k);
for(auto &x: arr) cin >> x;
sort(all(arr));
if(arr[0] != 0) {
cout << 0 << "\n";
return 0;
}
int pos = 0, prev = 0, i = 0;
while(i < n) {
if(prev != arr[i]) {
pos = 0;
}
if(brr[pos].empty()) {
if(arr[i] == 0) {
brr[pos].pb(arr[i]);
}
} else {
if(brr[pos].back() + 1 >= arr[i]) {
brr[pos].pb(arr[i]);
}
}
prev = arr[i];
i++;
pos = (pos + 1) % k;
}
int ans = 0;
for(int i = 0; i < k; i++) {
if(!brr[i].empty()) {
ans += brr[i].back() + 1;
}
}
cout << ans << "\n";
//check for corner test cases
return 0;
} | #include<bits/stdc++.h>
#define rep(i,n) for(int i = 0 ; i < (n); ++i)
using namespace std ;
typedef long long ll ;
const int mod=1000000007;
const int N=1e3 ;
void solve(){
int n,k;
cin>>n>>k ;
vector<int> a(n) ;
rep(i,n){
cin>>a[i] ;
}
map<int,int> mp ;
for(int i=0;i<n;i++){
mp[a[i]]++ ;
}
int mn=k ;
ll ans=0 ;
for(int i=0;i<=n;i++){
mn=min(mn,mp[i]) ;
ans+=mn ;
}
cout<<ans ;
}
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 ;
} |
Subsets and Splits