code_file1
stringlengths 87
4k
| code_file2
stringlengths 85
4k
|
---|---|
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
ll dp[3010][1 << 5][5];
int main() {
int N; scanf("%d", &N);
vector< vector<ll> > A(N, vector<ll>(5));
for(int i=0; i<N; i++) {
for(int j=0; j<5; j++) {
scanf("%lld", &A[i][j]);
}
}
fill(dp[0][0], dp[N+1][0], -1);
dp[0][0][0] = LONGINF;
for(int i=0; i<N; i++) {
for(int S=0; S<(1<<5); S++) {
for(int j=0; j<=3; j++) {
if(dp[i][S][j] < 0) continue;
// 追加しない
chmax(dp[i+1][S][j], dp[i][S][j]);
// 追加する (集合を決める)
if(j + 1 > 3) continue;
int mask = (1<<5) - 1 - S;
for(int T=mask; T>0; T=(T-1)&mask) {
ll mi = LONGINF;
for(int k=0; k<5; k++) {
if(T >> k & 1) chmin(mi, A[i][k]);
}
chmax(dp[i+1][S|T][j+1], min(dp[i][S][j], mi));
}
}
}
}
cout << dp[N][(1<<5)-1][3] << endl;
return 0;
}
| #include<iostream>
#include<algorithm>
#include<cstring>
#include<set>
using namespace std;
const int N = 3e3 + 10, M = 1 << 5;
int n;
int w[N][5];
bool check(int x){
set<int> s;
for(int i = 1; i <= n; i ++){
int t = 0;
for(int j = 0; j < 5; j ++)
if(w[i][j] >= x) t += 1 << j;
s.insert(t);
}
for(int a : s)
for(int b : s)
for(int c : s)
if((a | b | c) == 31) return true;
return false;
}
int main(){
scanf("%d", &n);
for(int i = 1; i <= n; i ++)
for(int j = 0; j < 5; j ++)
scanf("%d", &w[i][j]);
int l = 1, r = 1e9;
while(l < r){
int mid = l + r + 1 >> 1;
if(check(mid)) l = mid;
else r = mid - 1;
}
printf("%d\n", l);
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pi pair<int,int>
#define pll pair<ll,ll>
#define ld long double
const int INF = 1e9 + 7;
void solve(){
ll L , R; cin >> L >> R;
ll ans = 0;
if(R < 2 * L) cout << 0 << endl;
else{
ll numAs = R - 2 * L + 1;
ll ans = numAs * (R + 2 * L) / 2;
ans -= (2 * L * numAs);
ans += numAs;
cout << ans << endl;
}
}
int main(){
ios :: sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int tt = 1;
cin >> tt;
for(int tc = 1; tc <= tt; tc++){
// cout << "Case #" << tc << ": ";
solve();
}
} | #include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#define LL long long
using namespace std;
int main (){
LL T, l, r;
cin >> T;
while (T--){
scanf("%lld%lld", &l, &r);
LL m = r - 2 * l + 1;
if (m <= 0){
printf("0\n");
}
else{
printf("%lld\n", (m + 1) * m / 2);
}
}
return 0;
}
//n: n - 2l + 1 (2l ~ r)
// m = r - 2l + 1 |
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <list>
#include <utility>
#include <tuple>
#include <cstdio>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <cmath>
#include <limits>
#include <iomanip>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
const long long INF = 1LL << 60;
typedef long long ll;
const ll mod = 998244353;
ll power(ll x, ll n){
ll ret = 1;
while(n > 0) {
if(n & 1) {
ret = ret * x % mod;
}
x = x* x % mod;
n >>= 1;
}
return ret;
}
int main() {
cout << std::fixed << std::setprecision(15) ;
double s_x,s_y,g_x,g_y;
cin >> s_x >> s_y >> g_x >> g_y ;
double ans = s_x + (g_x - s_x) * s_y / (s_y + g_y);
cout << ans << endl;
} | //#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
#define all(n) begin(n), end(n)
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
if (a < b)
{
a = b;
return 1;
}
return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
if (b < a)
{
a = b;
return 1;
}
return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
for (auto &e : t)
fill_v(e, v);
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int a, b, c;
cin >> a >> b >> c;
auto dp = make_v<double>(101, 101, 101);
for (int i = 99; i >= 0; i--)
{
for (int j = 99; j >= 0; j--)
{
for (int k = 99; k >= 0; k--)
{
dp[i][j][k] = (double)(i * (1 + dp[i + 1][j][k]) + j * (1 + dp[i][j + 1][k]) + k * (1 + dp[i][j][k + 1])) / (double)(i + j + k);
}
}
}
cout << setprecision(20) << dp[a][b][c];
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=1e5 ;
const int INF=1001001001 ;
void solve(){
int n,x ;
cin>>n>>x ;
vector<int> a(n) ;
rep(i,n){
cin>>a[i] ;
}
stack<int> st ;
rep(i,n){
if(a[i]==x){
continue ;
}
else{
st.push(a[i]) ;
}
}
vector<int> ans ;
while(!st.empty()){
int y=st.top() ;
ans.push_back(y) ;
st.pop() ;
}
reverse(ans.begin(),ans.end()) ;
for(int i=0;i<(int)ans.size();i++){
cout<<ans[i]<<" " ;
}
}
int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin) ;
freopen("output.txt","w",stdout) ;
#endif
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(false);
int y ;
y=1 ;
//cin>>y ;
while(y--){
solve() ;
}
return 0 ;
} | #include<bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int a, b;
cin >> a >> b;
if(a == b) {
cout << a << '\n';
}
else {
if(2 != a && 2 != b) {
cout << 2 << '\n';
}
else if(1 != a && 1 != b) {
cout << 1 << '\n';
}
else {
cout << 0 << '\n';
}
}
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
static const ll mod=998244353;
ll N,K;
ll power[301];
ll modpow(ll a,ll n){
ll res=1;
while(0<n){
if(n%2==1)res=(res*a)%mod;
a=(a*a)%mod;
n>>=1;
}return res;
}
ll fac[301];
ll rev[301];
ll comb(ll n,ll k){
if(n<k)return 0;
ll x=(fac[n]*rev[k])%mod;
x=(x*rev[n-k])%mod;return x;
}
int main(){
cin>>N>>K;ll rev2=modpow(2,mod-2);
fac[0]=1;rev[0]=1;
for(ll i=1;i<=300;i++){
fac[i]=(i*fac[i-1])%mod;
rev[i]=modpow(fac[i],mod-2);
}
vector<ll>A(N);
for(ll i=0;i<N;i++)
cin>>A[i];power[0]=N;
for(ll i=0;i<N;i++){
ll a=A[i];
for(ll j=1;j<=300;j++){
power[j]=(power[j]+a)%mod;
a=(a*A[i])%mod;
}
}for(ll k=1;k<=K;k++){
ll ans=0;
for(ll i=1;i<=k/2;i++){
ll x=(comb(k,i)*(mod-power[k]+(power[i]*power[k-i])%mod))%mod;
ans=(ans+x)%mod;
}
ans=(ans+(N-1)*power[k])%mod;
if(k%2==0){ ll x=(comb(k,k/2)*(mod-power[k]+(power[k/2]*power[k/2])%mod))%mod;
x=(x*rev2)%mod;
ans=(mod+ans-x)%mod;}
cout<<ans<<endl;
}
return 0;
} | //#pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define DB double
#define LD long double
#define ST string
#define BS bitset
#define PA pair<LL,LL>
#define VE vector
#define VL VE<LL>
#define VP VE<PA>
#define VVL VE<VL>
#define VVVL VE<VVL>
#define PQ priority_queue
#define PQS priority_queue<LL,vector<LL>,greater<LL>>
#define FI first
#define SE second
#define PB push_back
#define POB pop_back
#define PF push_front
#define POF pop_front
#define MP make_pair
#define TS to_string
#define TU to_ullong
#define BPL __builtin_popcountll
#define FOR(i,a,n) for(i=a;i<n;++i)
#define FORR(i,a,n) for(i=n-1;i>=a;--i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) FORR(i,0,n)
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define UB(a,n) *upper_bound(ALL(a),n)
#define UBn(a,n) upper_bound(ALL(a),n)-a.begin()
#define LB(a,n) *lower_bound(ALL(a),n)
#define LBn(a,n) lower_bound(ALL(a),n)-a.begin()
#define INF 1000000000000000003
#define PI 3.14159265358979323846264338327950288
//#define MOD 1000000007
#define MOD 998244353
#define ERR 1e-10
#define coutl cout<<fixed<<setprecision(15)
#define FAST cin.tie(0);ios::sync_with_stdio(false)
void Yn(LL a){if(a)cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void YN(LL a){if(a)cout<<"YES"<<endl;else cout<<"NO"<<endl;}
LL pwmn(LL a,LL n){LL ans=1;while(ans<a)ans*=n;return ans;}
LL dig(LL n){LL ret=0;while(n)n/=10,++ret;return ret;}
LL GCD(LL a,LL b){LL c=1,tmp=max(a,b);b=min(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
LL LCM(LL a,LL b){return a*b/GCD(a,b);}
LL cmod(LL a,LL m){if(a%m<0)return a%m+abs(m);else return a%m;}
LL cdiv(LL a,LL b){return ((a<0&&b<0)||(a>=0&&b>=0)?a/b:(a-b+1)/b);}
LL DIV(LL a,LL d,LL m){LL l=m,x=1,y=0,k;while(l){k=d/l;d-=k*l;swap(l,d);x-=k*y;swap(x,y);}return cmod(a*cmod(x,m),m);}
LL POW(LL a,LL n,LL m){LL ans=1;while(n>0){if(n&1)ans=ans*a%m;a=a*a%m;n>>=1;}return ans;}
VL fact,finv,inv;
void comi(LL n){LL i;fact.resize(max(2LL,n+1));finv.resize(max(2LL,n+1));inv.resize(max(2LL,n+1));fact[0]=fact[1]=1;finv[0]=finv[1]=1;inv[0]=inv[1]=1;FOR(i,2,n+1){fact[i]=fact[i-1]*i%MOD;inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;finv[i]=finv[i-1]*inv[i]%MOD;}}
LL com(LL n,LL k){if(n<k||n<0||k<0)return 0;return fact[n]*(finv[k]*finv[n-k]%MOD)%MOD;}
bool cmps(PA a,PA b){if(a.SE!=b.SE)return a.SE<b.SE;return a.FI<b.FI;}
template<typename T>bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>void vout(VE<T> &v){LL i;rep(i,v.size()){cout<<v[i];if(i<v.size()-1)cout<<" ";}cout<<endl;}
template<typename T>void v2out(VE<VE<T>> &v){for(auto a:v)vout(a);}
int main(){
FAST;
LL i,j,ans=0,N,s=0;
cin>>N;
VL A(N);
rep(i,N){
cin>>A[i];
s+=A[i];
ans+=A[i]*A[i]*(N-1);
}
rep(i,N){
ans-=A[i]*(s-A[i]);
}
cout<<ans<<endl;
}
|
// __________________
// | ________________ |
// || ____ ||
// || /\ | ||
// || /__\ | ||
// || / \ |____ ||
// ||________________||
// |__________________|
// \###################\
// \###################\
// \ ____ \
// \_______\___\_______\
// An AC a day keeps the doctor away.
#ifdef local
#include <bits/extc++.h>
#define safe std::cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n"
#define debug(args...) qqbx(#args, args)
using ost = std::ostream;
#define DESTL(STL, BEG, END, OUT) \
template <typename ...T> ost& operator<<(ost &O, std::STL<T...> v) { int f=0; for(auto x: v) O << (f++ ? ", " : BEG) << OUT; return O << END; }
DESTL(deque, "[", "]", x); DESTL(vector, "[", "]", x);
DESTL(set, "{", "}", x); DESTL(multiset, "{", "}", x); DESTL(unordered_set, "{", "}", x);
DESTL(map , "{", "}", x.first << ":" << x.second); DESTL(unordered_map , "{", "}", x.first << ":" << x.second);
template <typename U, typename V> ost& operator<<(ost &O, std::pair<U,V> p) { return O << '(' << p.first << ',' << p.second << ')'; }
template <typename T, size_t N> ost& operator<<(ost &O, std::array<T,N> a) { int f=0; for(T x: a) O << (f++ ? ", " : "[") << x; return O << "]"; }
template <typename T, size_t ...I> ost& prtuple(ost &O, T t, std::index_sequence<I...>) { return (..., (O << (I ? ", " : "(") << std::get<I>(t))), O << ")"; }
template <typename ...T> ost& operator<<(ost &O, std::tuple<T...> t) { return prtuple(O, t, std::make_index_sequence<sizeof...(T)>()); }
template <typename ...T> void qqbx(const char *s, T ...args) {
int cnt = sizeof...(T);
(std::cerr << "\033[1;32m(" << s << ") = (" , ... , (std::cerr << args << (--cnt ? ", " : ")\033[0m\n")));
}
#else
#pragma GCC optimize("Ofast")
#pragma loop_opt(on)
#include <bits/extc++.h>
#include <bits/stdc++.h>
#define debug(...) ((void)0)
#define safe ((void)0)
#endif // local
#define all(v) begin(v),end(v)
#define get_pos(v,x) int(lower_bound(begin(v),end(v),x)-begin(v))
#define sort_uni(v) sort(begin(v),end(v)),v.erase(unique(begin(v),end(v)),end(v))
#define pb emplace_back
#define ff first
#define ss second
#define mem(v,x) memset(v,x,sizeof v)
using namespace std;
using namespace __gnu_pbds;
typedef int64_t ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pld;
template <typename T> using max_heap = std::priority_queue<T,vector<T>,less<T> >;
template <typename T> using min_heap = std::priority_queue<T,vector<T>,greater<T> >;
template <typename T> using rbt = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
constexpr ld PI = acos(-1), eps = 1e-7;
constexpr ll N = 100025, INF = 1e18, MOD = 998244353, K = 19, inf = 1e7;
constexpr inline ll cdiv(ll x, ll m) { return x/m + (x%m ? (x<0) ^ (m>0) : 0); } // ceiling divide
constexpr inline ll modpow(ll e,ll p,ll m=MOD) { ll r=1; for(e%=m;p;p>>=1,e=e*e%m) if(p&1) r=r*e%m; return r; }
ll f(ll x) {
return x*(x+1)/2 % MOD;
}
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0);
ll a, b, c;
cin >> a >> b >> c;
cout << f(a) * f(b) % MOD * f(c) % MOD << '\n';
}
| #include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);
#define l_ength size
void mul_mod(ll& a, ll b){
a *= b;
a %= MOD;
}
void add_mod(ll& a, ll b){
a = (a<MOD)?a:(a-MOD);
b = (b<MOD)?b:(b-MOD);
a += b;
a = (a<MOD)?a:(a-MOD);
}
ll solve(ll a, ll b, ll c, ll d){
if(a==c && b==d){
return 0ll;
}
if(a+b == c+d){
return 1ll;
}
if(a-b == c-d){
return 1ll;
}
if(std::abs(a-c)+std::abs(b-d) <= 3ll){
return 1ll;
}
if((a+b+c+d)%2==0){
return 2ll;
}
return INFLL;
}
int main(void){
ll sx,sy,gx,gy,ans,i,j;
std::cin >> sx >> sy;
std::cin >> gx >> gy;
ans = solve(sx,sy,gx,gy);
for(i=-3; i<=3; ++i){
for(j=-3; j<=3; ++j){
if(std::abs(i)+std::abs(j)>3ll){
continue;
}
ans = std::min(ans,solve(sx+i,sy+j,gx,gy)+1);
}
}
std::cout << ans << std::endl;
return 0;
}
|
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <string>
#include <bitset>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
using namespace std;
typedef long long ll;
//infの設定
#define INF32 2147483647
#define INF64 9223372036854775807
//repマクロ
#define rep(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
struct dataE{
ll error;
ll key;
};
bool cmp(const dataE &a, const dataE &b){
return a.error>b.error;
}
int main(){
ll K,N,M;
cin>>K>>N>>M;
vector<ll> A(101010),B(101010);
vector<dataE> e(101010);
ll sumB=0;
rep(i,0,K){
cin>>A.at(i);
B.at(i)=A.at(i)*M/N;
e.at(i).error=A.at(i)*M-B.at(i)*N;
e.at(i).key=i;
sumB+=B.at(i);
}
sort(e.begin(),e.end(),cmp);
ll rem=M-sumB;
rep(i,0,rem){
B.at(e.at(i).key)++;
}
rep(i,0,K) cout<<B.at(i)<<" ";
cout<<endl;
return 0;
} | #include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>
#include <random>
#define FOR_LT(i, beg, end) for (decltype(end) i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (decltype(end) i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (decltype(beg) i = beg; end <= i; i--)
#define REP(n) for (decltype(n) repeat_index = 0; repeat_index < n; repeat_index++)
using namespace std;
template<typename T, size_t S>
T minval(const T(&vals)[S])
{
T val = numeric_limits<T>::max();
FOR_LT(i, 0, S) {
val = min(val, vals[i]);
}
return val;
}
template<typename T, size_t S>
T maxval(const T(&vals)[S])
{
T val = numeric_limits<T>::min();
FOR_LT(i, 0, S) {
val = max(val, vals[i]);
}
return val;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout << fixed << setprecision(20);
int64_t k, n, m; cin >> k >> n >> m;
vector<int64_t> as(k); for (auto& a : as) { cin >> a; }
vector<int64_t> bs(k);
vector<int64_t> rs(k);
int64_t sum = 0;
FOR_LT(i, 0, k) {
int64_t x = as[i] * m;
bs[i] = x / n;
rs[i] = x % n;
sum += bs[i];
}
multimap<int64_t, int64_t> rmap;
FOR_LT(i, 0, k) {
rmap.insert({ rs[i], i });
}
{
auto it = rmap.rbegin();
while (it != rmap.rend()) {
if (sum == m) break;
bs[it->second]++;
it++;
sum++;
}
}
FOR_LT(i, 0, k) {
cout << bs[i] << " ";
}
cout << endl;
return 0;
} |
//Update : 2021.2.26
#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define ll long long
#define ld long double
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define For(x,a,b) if(a!=b){icdc=(b-a)/abs(b-a);}else{icdc=1;}for(int x=(a);x!=(b+icdc);x+=icdc)
#define forp(x,a,b) if(b-a!=0){icdc=(b-a)/abs(b-a);}else{icdc=1;};for(int x=(a);x!=(b);x+=icdc)
#define FOR(x,n) for(int x=0;x<(n);x++)
int icdc;
//Frequently Used Variables
ull M=1e9+7;
ll b;
//ll A[100005];
ll maxv=-1e18,minv=1e18,LLINF=1e18,INF=1e9;
string s;
map<long long,int> mp;
vector<ll> v;
#define co cout<<
#define kj <<" "<<
#define ml <<'\n';
void solve(){
cin>>b;
//cout<<b<<endl;
sort(v.begin(), v.end());
//ll js=upper_bound(v.begin(), v.end(),b)-v.begin();
for(ll i=0;i<(int)v.size();i++){
//co "vi" kj b kj v[i] ml
if(b<v[i]){
cout<<b-i<<endl;
return;
}
}
cout<<b-v.size()<<endl;
}
void prekomput(){
ll j;
//cout<<"aman"<<endl;
for(ll i=2;i<=1e5;i++){
//cout<<"I"<<i<<endl;
j=i*i;
while(j<=1e10+1){
if(mp[j]==0){
mp[j]=1;
v.push_back(j);
//cout<<"vs"<<v.size()<<" ";
//cout<<j<<endl;
}
j=j*i;
}
}
//cout<<"aman"<<endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
prekomput();
solve();
}
/*
*/ | #include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
ll n;cin>>n;
unordered_set<ll> s;
for(ll i=2;i*i<=n;i++){
ll k=i*i;
while(k<=n){
s.insert(k);
k=k*i;
}
}
cout<<n-s.size();
} |
#include <bits/stdc++.h>
using namespace std;
#define IO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define whilet int T;cin>>T;while(T--)
#define clr(a,x) memset(a,x,sizeof(a));
#define ll long long
#define PI 3.1415926535897932384626
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define endl "\n"
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
#define MOD 998244353
int d4x[] = {0, 0, 1, -1};
int d4y[] = {1, -1, 0, 0};
int d8x[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int d8y[] = {-1, 0, 1, -1, 1, -1, 0, 1};
ll a, b, c;
int main() {
IO;
cin >> a >> b >> c;
ll res = ((((a*(a+1)/2)%MOD) * ((b*(b+1)/2)%MOD)%MOD) * ((c*(c+1)/2)%MOD))%MOD;
cout << res << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main(){
long long a,b,c;
cin >> a >> b >> c;
long long mod = 998244353;
cout << ( (a) * (a+1) / 2 % mod) * ( (b) * (b+1) / 2 % mod) % mod * ( (c) * (c+1) / 2 % mod ) % mod;
} |
#include <iostream>
int main(void)
{
int a, b, c, d;
std::cin >> a >> b >> c >> d;
std::cout << a*d - b*c << std::endl;
return 0;
} | /*
このコード、と~おれ!
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>
////多倍長整数, cpp_intで宣言
//#include <boost/multiprecision/cpp_int.hpp>
//#include <boost/multiprecision/cpp_dec_float.hpp>
//using namespace boost::multiprecision;
//
#pragma GCC target ("avx2")
//#pragma GCC target("arch=skylake-avx512")
//#pragma GCC optimiz ("O3")
//#pragma GCC target ("sse4")
//#pragma GCC optimization ("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()) //string出力
#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)) /*(a, b) から (c, d) のマンハッタン距離 */
#define inf numeric_limits<double>::infinity();
#define linf numeric_limits<long double>::infinity()
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;
}
//atcoder library
//#include <atcoder/all>
//using namespace atcoder;
//random_device seed_gen;
//mt19937 engine(seed_gen());
//uniform_distribution dist(-1.0, 1.0);
/*-----------------------------------------ここからコード-----------------------------------------*/
int main() {
int a, b, c, d;
scanf("%d%d%d%d", &a, &b, &c, &d);
printf("%d\n", a * d - b * c);
Please AC;
} |
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
int A, B; cin >> A >> B;
int t = min(A, B) - 1;
vector<ll> ans(A + B);
for(int i = 0; i < t; i++){
ans[i] = i + 1;
}
for(int i = 0; i < t; i++){
ans[t + i] = (i * -1) - 1;
}
int n = max(A, B) - t;
int sum = 0;
for(int i = 0; i < n; i++){
ans[2 * t + i] = 10000 + i;
if(A < B)ans[2 * t + i] *= -1;
sum += 10000 + i;
}
ans[A + B - 1] = sum;
if(A >= B)ans[A + B - 1] *= -1;
for(ll &x: ans)cout << x << " ";
cout << endl;
} | /*
written by Pankaj Kumar.
country:-INDIA
Institute: National Institute of Technology, Uttarakhand
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll ;
typedef unsigned long long ull;
typedef vector<ll> vl;
#define speed cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
/* Abbrevations */
#define ff first
#define ss second
#define mp make_pair
#define line cout<<endl;
#define pb push_back
#define Endl "\n"
// loops
#define forin(arr,n) for(ll i=0;i<n;i++) cin>>arr[i];
// Some print
#define no cout<<"No"<<endl;
#define yes cout<<"Yes"<<endl;
// sort
#define all(V) (V).begin(),(V).end()
#define srt(V) sort(all(V))
#define srtGreat(V) sort(all(V),greater<ll>())
// some extra
#define printv(v) for(ll i=0;i<ll(v.size());i++){cout<<v[i]<<" ";} line;
#define precision(x) cout<<fixed<<setprecision(x);
#define sz(V) ll(V.size())
// template
template <typename T>
T mymax(T x,T y)
{
return (x>y)?x:y;
}
// function
ll power(ll x,ll y,ll mod)
{
ll res=1;
// x=x%mod;
while(y>0)
{
if(y%2==1)
{
res*=x;
// res=res%mod;
}
y/=2; x*=x; // x=x%mod;
}
return res;
}
ll str_to_num(string s)
{
return stoi(s);
}
string num_to_str(ll num)
{
return to_string(num);
}
// datatype definination
#define ordered_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
class Point
{
public:
ll x;
ll y;
ll z;
ll getsum()
{
return x+y+z;
}
};
/* ascii value
A=65,Z=90,a=97,z=122
*/
/* --------------------MAIN PROGRAM----------------------------*/
// to run ctrl+b
const ll INF=LONG_MAX;
const ll mod1=1e9+7;
const ll mod2=998244353;
// Techniques
// divide into cases, brute force, pattern finding
// sort, greedy, binary search, two pointer
// transform into graph
ll solve()
{
ll a,b;
cin>>a>>b;
if(a>b){
ll sum=0;
for(ll i=1;i<=a;i++){
cout<<i<<" ";
sum+=i;
}
for(ll i=1;i<b;i++){
cout<<-i<<" ";
sum-=i;
}
cout<<-sum<<endl;
}
else{
vl neg(b);
ll sum=0;
for(int i=0;i<b;i++){
sum+=i+1;
neg[i]=-(i+1);
}
vl pos(a);
for(int i=0;i<a-1;i++){
pos[i]=(i+1);
sum-=(i+1);
}
pos[a-1]=sum;
for(auto x:pos)
cout<<x<<" ";
for(auto x:neg)
cout<<x<<" ";
line;
}
return 0;
}
int main()
{
speed;
/* #ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif */
ll TestCase=1;
// cin>>TestCase;
while(TestCase--)
{
solve();
}
}
/* -----------------END OF PROGRAM --------------------*/
/*
* stuff you should look before submission
* constraint and time limit
* int overflow
* special test case (n=0||n=1||n=2)
* don't get stuck on one approach if you get wrong answer
*/ |
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
#include<chrono>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define vint(a,n) vint a(n); rep(i, n) cin >> a[i];
#define vll(a,n) vll a(n); rep(i, n) cin >> a[i];
#define ALL(n) begin(n),end(n)
#define RALL(n) rbegin(n),rend(n)
#define MOD (1000000007)
// #define MOD (998244353)
#define INF (2e9)
#define INFL (2e18)
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
using vint=vector<int>;
using vll=vector<ll>;
using vbool=vector<bool>;
template<class T>using arr=vector<vector<T>>;
template<class T>int popcount(T &a){int c=0; rep(i, 8*(int)sizeof(a)){if((a>>i)&1) c++;} return c;}
template<class T>void pl(T x){cout << x << " ";}
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){pl(a[i]);} pr(a.back());}
template<class T>void prarr(arr<T>& a){rep(i, a.size()) if(a[i].empty()) pr(""); else prvec(a[i]);}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
//数列a(a[0],a[1],…,a[n-1])についての区間和と点更新を扱う
//区間和,点更新,二分探索はO(log{n})で動作する
class BIT {
public:
//データの長さ
ll n;
//データの格納先
vector<ll> a;
//コンストラクタ
BIT(ll n):n(n),a(n+1,0){}
//a[i]にxを加算する
void add(ll i,ll x){
i++;
if(i==0) return;
for(ll k=i;k<=n;k+=(k & -k)){
a[k]+=x;
}
}
//a[i]+a[i+1]+…+a[j]を求める
ll sum(ll i,ll j){
return sum_sub(j)-sum_sub(i-1);
}
//a[0]+a[1]+…+a[i]を求める
ll sum_sub(ll i){
i++;
ll s=0;
if(i==0) return s;
for(ll k=i;k>0;k-=(k & -k)){
s+=a[k];
}
return s;
}
//a[0]+a[1]+…+a[i]>=xとなる最小のiを求める(任意のkでa[k]>=0が必要)
ll lower_bound(ll x){
if(x<=0){
//xが0以下の場合は該当するものなし→0を返す
return 0;
}else{
ll i=0;ll r=1;
//最大としてありうる区間の長さを取得する
//n以下の最小の二乗のべき(BITで管理する数列の区間で最大のもの)を求める
while(r<n) r=r<<1;
//区間の長さは調べるごとに半分になる
for(int len=r;len>0;len=len>>1) {
//その区間を採用する場合
if(i+len<n && a[i+len]<x){
x-=a[i+len];
i+=len;
}
}
return i;
}
}
};
int main()
{
int n; cin >> n;
vint(a, n);
int d[n][2];
rep(i, n){
d[i][0] = i;
d[i][1] = n-i-1;
}
BIT bt(n);
ll f = 0;
rep(i, n){
f += i - bt.sum_sub(a[i]);
bt.add(a[i], 1);
}
// pr(f);
rep(i, n){
pr(f);
f = f - d[a[i]][0] + d[a[i]][1];
}
return 0;} | #include <bits/stdc++.h>
#define INF 1000000007
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i < b; i++)
using namespace std;
typedef long long ll;
typedef long long int lli;
typedef long double ld;
typedef vector<int> vi;
typedef unordered_map<int,int> umi ;
typedef unordered_set<int> usi ;
typedef pair<int,int> pi;
#include <bits/stdc++.h>
using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
//declare here -------------------------------------------------------------------------------
const int N =4e5+1;
bool taketest=false ;
vi adj[N] ;
bool visited[N] ;
bool visited2[N] ;
bool cycle(int u ,int p){
if(visited2[u]) return true ;
visited2[u] =true ;
bool ans=false ;
for(auto v:adj[u]){
if(v==p) continue ;
ans|= cycle(v,u) ;
}
return ans ;
}
int sze(int u ,int p){
if(visited[u]) return 0 ;
visited[u] =true ;
int res=0 ;
res++ ;
for(auto v:adj[u]){
if(v==p) continue ;
res+= sze(v,u) ;
}
return res ;
}
// solve here ---------------------------------------------------------------------------------
void solve(){
int n ;
cin>>n ;
int u,v ;
REP(i,0,n){
cin>>u>>v ;
adj[u].PB(v) ;
adj[v].PB(u) ;
}
int ans=0 ;
REP(i,0,N){
if(visited[i]) continue ;
ans+=sze(i,-1) ;
if(!cycle(i,-1)) ans-- ;
}
cout<<ans ;
}
//--------------------------------------------------------------------------------------------
int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios::sync_with_stdio(0);
cin.tie(0);
long long test =1 ;
if(taketest) cin>>test ;
while(test--){
solve() ;
cout<<"\n" ;
}
return 0 ;
} |
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,j,n) for(int i=j;i<n;i++)
#define readvec(v,n) for(int i=0;i<n;i++){cin>>v[i];}
#define MOD 1000000007
int main()
{
int n;
cin>>n;
vector<char> v(2*n);
readvec(v,2*n);
int q;
cin>>q;
int ind=0;
rep(i,0,q)
{
int t,a,b;
cin>>t>>a>>b;
if(t==2){ind=(ind==0)?n:0;continue;}
int ia=(ind+a-1)%(2*n);
int ib=(ind+b-1)%(2*n);
char ch = v[ia];
v[ia] = v[ib];
v[ib] = ch;
}
rep(i,0,2*n)cout<<v[(ind+i)%(2*n)];
cout<<"\n";
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define int long long
int N, ans;
struct Node{
int v, idx;
inline bool operator < (const Node &comp) const {return comp.v < v;}
}a[400000 + 5];
set <int> b;
set <int> :: iterator it;
signed main() {
ios :: sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> N;
for (int i = 1; i <= N; i ++) {
cin >> a[i].v; a[i].idx = N + 1 - i; b.insert(i);
}
for (int i = 1; i <= N; i ++) {
cin >> a[N + i].v; a[N + i].idx = i;
}
sort(a + 1, a + N + N + 1);
for (int i = 1, j = 1; i <= N; i ++) {
while (j <= N + N) {
it = b.upper_bound(a[j].idx);
if (it != b.begin()) break;
j ++;
}
ans += a[j ++].v;
b.erase(-- it);
}
cout << ans << '\n';
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define ceil(x) static_cast<ll>(ceil(x))
#define floor(x) static_cast<ll>(floor(x))
#define pow(x, y) static_cast<ll>(pow(x, y))
#define gcd(x, y) static_cast<ll>(__gcd(x, y))
#define lcm(x, y) static_cast<ll>(a * (b / gcd(x, y)))
#define F first
#define S second
#define eb emplace_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define FI(i, a, b) for (ll i{a}; i <= b; i++)
#define FD(i, a, b) for (ll i{a}; i >= b; i--)
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<pair<ll, ll>> vpii;
typedef pair<ll, ll> pi;
const ll mod{static_cast<ll>(1e9) + 7};
const ld Pi{3.14159265358979323846};
auto int_from(istream &in) -> int
{
int x;
in >> x;
return x;
}
auto lng_from(istream &in) -> ll
{
ll x;
in >> x;
return x;
}
auto str_from(istream &in) -> string
{
string x;
in >> x;
return x;
}
auto chr_from(istream &in) -> char
{
char x;
in >> x;
return x;
}
int main()
{
IOS;
ll a{lng_from(cin)}, b{lng_from(cin)}, c{lng_from(cin)};
if (c % 2)
{
if (a > b)
{
cout << ">\n";
}
else if (a < b)
{
cout << "<\n";
}
else
{
cout << "=\n";
}
}
else
{
a = abs(a);
b = abs(b);
if (a > b)
{
cout << ">\n";
}
else if (a < b)
{
cout << "<\n";
}
else
{
cout << "=\n";
}
}
return 0;
} | #include<bits/stdc++.h>
using namespace std;
long long a,b,c;
long long pw(long long x,long long y,long long md)
{
long long rt=1;
while(y)
{
if(y&1)
{
rt*=x;
rt%=md;
}
x*=x;
x%=md;
y>>=1;
}
return rt;
}
int main()
{
cin>>a>>b>>c;
a%=10;
if(a==0)
{
cout<<0<<endl;
}
if(a==1)
{
cout<<1<<endl;
}
if(a==2)
{
b%=4;
long long nw=pw(b,c,4);
if(nw==0)
{
cout<<6<<endl;
}
else if(nw==1)
{
cout<<2<<endl;
}
else if(nw==2)
{
cout<<4<<endl;
}
else
{
cout<<8<<endl;
}
}
if(a==3)
{
b%=4;
long long nw=pw(b,c,4);
if(nw==0)
{
cout<<1<<endl;
}
else if(nw==1)
{
cout<<3<<endl;
}
else if(nw==2)
{
cout<<9<<endl;
}
else
{
cout<<7<<endl;
}
}
if(a==4)
{
b%=2;
long long nw=pw(b,c,2);
if(nw==0)
{
cout<<6<<endl;
}
else
{
cout<<4<<endl;
}
}
if(a==5)
{
cout<<5<<endl;
}
if(a==6)
{
cout<<6<<endl;
}
if(a==7)
{
b%=4;
long long nw=pw(b,c,4);
if(nw==0)
{
cout<<1<<endl;
}
else if(nw==1)
{
cout<<7<<endl;
}
else if(nw==2)
{
cout<<9<<endl;
}
else
{
cout<<3<<endl;
}
}
if(a==8)
{
b%=4;
long long nw=pw(b,c,4);
if(nw==0)
{
cout<<6<<endl;
}
else if(nw==1)
{
cout<<8<<endl;
}
else if(nw==2)
{
cout<<4<<endl;
}
else
{
cout<<2<<endl;
}
}
if(a==9)
{
b%=2;
long long nw=pw(b,c,2);
if(nw==0)
{
cout<<1<<endl;
}
else
{
cout<<9<<endl;
}
}
return 0;
} |
/* {{{ */
#include <bits/stdc++.h>
using namespace std;
#ifdef __LOCAL
#include <prettyprint.hpp>
#define debug(a) cerr << "[\033[33mDEBUG\033[m] " << (#a) << ": " << (a) << endl
#else
#define debug(s) cerr << "[\033[33mDEBUG\033[m] local only" << endl
#endif
using ll = long long;
template <class T> using vec = vector<T>;
#define endl "\n"
#define INF (int)1e9
#define LINF (long long)1e12
#define MOD (int)1e9+7
#define _rep(i,_a,_b,a,b,...) for (int i=(a), lim##i=(b); i<lim##i; i++)
#define rep(i, ...) _rep(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define _rrep(i,_a,_b,a,b,...) for (int i=(a), lim##i=(b); i>=lim##i; i--)
#define rrep(i, ...) _rrep(i, __VA_ARGS__, __VA_ARGS__, __VA_ARGS__, 0)
#define each(e, c) for (auto &e: c)
#define all(v) begin(v), end(v)
#define popcount __builtin_popcount
template <class T> bool chmin(T& a, const T& b) { return a>b?a=b,true:false; }
template <class T> bool chmax(T& a, const T& b) { return a<b?a=b,true:false; }
void init()
{
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(10);
}
/* }}} */
int n;
vec<vec<ll>> capa;
bool check(ll x)
{
vec<bool> can(1 << 5, false);
each(c, capa)
{
int bit = 0;
rep(i, 5)
{
if (c[i] >= x) bit |= 1 << i;
}
can[bit] = true;
}
rep(i, 1 << 5) rep(j, i + 1) rep(k, j + 1)
{
if (can[i] && can[j] && can[k]
and (i | j | k) == (1 << 5) - 1)
{
return true;
}
}
return false;
}
int main()
{
init();
cin >> n;
capa.resize(n);
rep(i, n)
{
capa[i].resize(5);
rep(j, 5) cin >> capa[i][j];
}
ll ok = -1, ng = LINF;
while (ng - ok > 1)
{
ll mid = (ok + ng) / 2;
if (check(mid)) ok = mid;
else ng = mid;
}
cout << ok << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int a[3001][5];
int n;
bool valid(int req) {
set<int> mask;
for(int i = 0; i < n; i++) {
int bits = 0;
for(int j = 0; j < 5; j++) {
if(a[i][j] >= req)
bits |= (1 << j);
}
mask.insert(bits);
}
for (auto i : mask) {
for (auto j : mask) {
for (auto k : mask) {
if((i | j | k) == 31)
return true;
}
}
}
return false;
}
void solve() {
cin >> n;
for (int i = 0; i < n; i++) {
for (int j = 0; j < 5; j++) {
cin >> a[i][j];
}
}
int l = 0, r = 1000000001;
while (l + 1 < r) {
int mid = l + (r - l) / 2;
if (valid(mid)) {
l = mid;
}
else {
r = mid;
}
}
cout << l;
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1;
//cout << fixed << setprecision(10);
for (int i = 0; i < t; i++) {
solve();
}
return 0;
}
|
/// B I S M I L L A H I R R A H M A N I R R A H I M
#include<bits/stdc++.h>
#include<vector>
#include<set>
#include<map>
using namespace std;
typedef bool boo;
typedef int li;
typedef long long int ll;
typedef unsigned long long int l1;
typedef double db;
//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
typedef vector < li > vli;
typedef vector < ll > vll;
typedef set < li > sli;
typedef set < ll > sll;
typedef pair < li , li > pli;
typedef pair < ll , ll > pll;
typedef map < li ,li > mli;
typedef map < ll ,ll > mll;
typedef vector < pair < li , li > > vpi;
typedef vector < pair < ll , ll > > vpl;
//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#define tc int t;cin>>t;while(t--)
#define inp_i(a,n) for(i=0; i<n ;i++) cin>>a[i]
#define lp(i,a,b) for(i=a;i<b;i++)
#define len(z) z.begin(),z.end()
#define faster ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
#define input_txt freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define nl <<endl
#define spc <<" "
#define sp <<" "<<
#define co(x) cout<<x nl
#define sz(a) a.size()
#define cy cout<<"YES" nl
#define cn cout<<"NO" nl
#define pb push_back
#define F first
#define S second
#define pi 2*acos(0.0)
#define clr(z) z.clear()
#define rn return
#define gcd(a,b) __gcd(a,b)
#define mem(b,z) memset(b,z,sizeof(b))
#define fixed(x) fixed<<setprecision(x)
const int lx=3e5+123;
void solve()
{
li n, k, x;
cin>>n>>x;
while(n--)
{
cin>>k;
if(k != x) cout<<k spc;
}
cout nl;
}
int main()
{
faster
solve();
// A L H A M D U L I L L A H
// 1 2 3 2 1
}
/*
ll gcd(ll a, ll b)
{
if (a == 0)
return b;
return gcd(b % a, a);
}
*/
| #include <bits/stdc++.h>
using namespace std;
// #include <atcoder/all>
// using namespace atcoder;
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll = long long;
void solve(long long N, long long K, std::vector<long long> a){
map<int, int> cnt;
int mx = 0;
rep(i, N) {
cnt[a[i]]++;
mx = max<int>(mx, a[i]);
}
ll ans = 0;
while (1) {
int n = -1;
rep(i, mx + 1) {
if (cnt[i]) {
n = i;
cnt[i]--;
} else {
break;
}
}
ans += n + 1;
K--;
if (n == -1 || K == 0) {
break;
}
}
cout << ans << endl;
}
// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
int main(){
long long N;
scanf("%lld",&N);
long long K;
scanf("%lld",&K);
std::vector<long long> a(N);
for(int i = 0 ; i < N ; i++){
scanf("%lld",&a[i]);
}
solve(N, K, std::move(a));
return 0;
}
|
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
// please, read the question correctly (do you need set or multiset)???
const int N=200010; //check the limits, dummy
int a[N];
int n, m;
int main(){
// int t;
// while(){
int n, m, a, b;
scanf("%d%d%d%d",&n,&m,&a,&b);
int ans = n*b-m*a;
cout<<ans<<endl;
// }
} | #include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int arr[2][2];
for(int i =0;i<2;++i){
for(int j = 0;j<2;++j)cin >> arr[i][j];
}
cout << arr[0][0]*arr[1][1] - (arr[0][1]*arr[1][0]);
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ll N;
cin >> N;
vector<pair<pair<ll, ll>, int>> lrt(N);
for (int i = 0; i < N; i++){
ll a, b, c;
cin >> a >> b >> c;
lrt.at(i).first.first = b;
lrt.at(i).first.second = c;
lrt.at(i).second = a;
}
sort(lrt.begin(), lrt.end());
ll count = 0;
for (int i = 0; i < N; i++) {
if (lrt.at(i).second == 1 || lrt.at(i).second == 3) {
for (int j = i + 1; j < N; j++) {
if (lrt.at(i).first.second > lrt.at(j).first.first) {
count++;
}
else if (lrt.at(i).first.second == lrt.at(j).first.first && lrt.at(j).second == 1) {
count++;
}
else if (lrt.at(i).first.second == lrt.at(j).first.first && lrt.at(j).second == 2) {
count++;
}
}
}
if (lrt.at(i).second == 2 || lrt.at(i).second == 4) {
for (int j = i + 1; j < N; j++) {
if (lrt.at(i).first.second > lrt.at(j).first.first) {
count++;
}
}
}
}
cout << count << endl;
}
| #include<iostream>
#include<cstdlib>
#include<utility>
#include<tuple>
#include<string>
#include<vector>
#include<numeric>
#include<algorithm>
#include<queue>
#include<deque>
#include<bitset>
#include<cmath>
#include<map>
#include<string>
#include<list>
#include<iomanip>
#include<set>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const double PI = acos(-1);
#define rep(i, a, b) for(ll i = a; i < b; i++)
ll MOD(ll x) {
return (x % mod + mod) % mod;
}
int main() {
ll n; cin >> n;
ll mini = mod, maxi = -1;
vector<double>t(n), l(n), r(n);
ll ans = 0;
rep(i, 0, n) {
cin >> t[i] >> l[i] >> r[i];
if (t[i] == 2)r[i] -= 0.5;
else if (t[i] == 3)l[i] += 0.5;
else if (t[i] == 4) {
r[i] -= 0.5; l[i] += 0.5;
}
rep(j, 0, i) {
if (l[i] >= l[j] && l[i] <= r[j])ans++;
else if (r[i] <= r[j] && r[i] >= l[j])ans++;
else if (l[i] <= l[j] && r[i] >= r[j])ans++;
}
}
cout << ans << endl;
return 0;
} |
// Generated by 2.3.1 https://github.com/kyuridenamida/atcoder-tools
#include <bits/stdc++.h>
// #include "atcoder/all"
#define SUBMIT
using namespace std;
using i64 = long long;
const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;
template <typename T>
bool chmin(T& x, T y){
if(x > y){
x = y;
return true;
}
return false;
}
template <typename T>
bool chmax(T& x, T y){
if(x < y){
x = y;
return true;
}
return false;
}
using Uint = uint64_t;
constexpr int n = 20;
array<Uint, n> h_res, w_res;
void solve(long long m, std::vector<std::string> s){
// sort(s.begin(), s.end(), [](auto x, auto y){return x.size() < y.size();});
int min_len = 100;
int max_len = 0;
vector<pair<int,Uint>> target(m);
for(int i = 0; i < m; ++i){
chmin(min_len, int(s[i].size()));
chmax(max_len, int(s[i].size()));
target[i].first = s[i].size();
target[i].second = 0;
for(int j = 0; j < s[i].size(); ++j){
target[i].second |= ((s[i][j] - 'A') << (3 * j));
}
}
for(int i = 0; i < n; ++i){
for(int j = 0; j < n; ++j){
Uint val = (rand() & 7);
h_res[i] |= val << (j * 3);
w_res[j] |= val << (i * 3);
}
}
auto get = [&](int i, int j){
Uint h = (h_res[i] >> (3 * j)) & 7;
Uint w = (w_res[j] >> (3 * i)) & 7;
assert(h == w);
return h;
};
auto get_h = [&](int i, int j, int len){
Uint h = (h_res[i] >> (3 * j)) & ((1uLL << (3 * len)) - 1);
if(j + len > n){
int over = j + len - n;
return h | Uint((h_res[i] & ((1uLL << (3 * over)) - 1)) << (3 * (n - j)));
}
return h;
};
auto get_w = [&](int i, int j, int len){
Uint w = (w_res[j] >> (3 * i)) & ((1uLL << (3 * len)) - 1);
if(i + len > n){
int over = i + len - n;
return w | Uint((w_res[j] & ((1uLL << (3 * over)) - 1)) << (3 * (n - i)));
}
return w;
};
// TODO: hash_map
vector<unordered_map<Uint, int>> now_hash(max_len + 1);
for(int i = 0; i < n; ++i){
for(int j = 0; j < n; ++j){
for(int l = min_len; l <= max_len; ++l){
++now_hash[l][get_h(i, j, l)];
++now_hash[l][get_w(i, j, l)];
}
}
}
// 以下回答関連
#ifndef SUBMIT
int ans = 0;
for(int i = 0; i < m; ++i){
auto t = target[i];
if(now_hash[t.first].count(t.second)){
cout << "correct: " << i << " " << s[i] << endl;
++ans;
}
}
cout << "ans: " << ans << endl;
cout << Uint(round(1e8 * ans / m)) << endl;
#endif
for(int i = 0; i < n; ++i){
for(int j = 0; j < n; ++j){
cout << char('A' + ((h_res[i] >> (3 * j)) & 7));
}
cout << endl;
}
cout << endl;
}
signed main(){
#ifndef SUBMIT
long long N;
long long M;
ifstream fs("../contests/ahc004/A/in/0001.txt");
assert(fs.is_open());
fs >> N >> M;
std::vector<std::string> s(M);
for(int i = 0 ; i < M ; i++){
fs >> s[i];
}
#else
long long N;
std::scanf("%lld", &N);
long long M;
std::scanf("%lld", &M);
std::vector<std::string> s(M);
for(int i = 0 ; i < M ; i++){
std::cin >> s[i];
}
#endif
solve(M, std::move(s));
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main()
{
int N,M;
int x,y;
string A[800];
int score[800]={0};
char dna[20][20];
cin >> N >> M;
for(int i=0; i<M; i++) {
string a;
cin >> a;
bool iscontain=false;
int conv=0;
int convj=0;
for( int j=0; j<i; j++)
if(A[j].find(a)!=string::npos) {
iscontain=true;
if(score[j]>conv) {
conv=score[j];
convj=j;
}
break;
}
if(iscontain!=true) {
A[i]=a;
score[i]++;
} else {
score[convj]++;
A[i]="";
}
}
bool convine=true;
while(convine) {
convine=false;
for(int i=0; i<M; i++) {
if(A[i].size()>2){
string b=A[i].substr(A[i].size()-2);
for(int j=0; j<M; j++) {
if( i==j ) continue;
if( A[j][0]==b[0] && A[j][1]==b[1] ){
if( A[i].size()+A[j].size()-2 <= N) {
A[i] = A[i] + A[j].substr(2);
A[j] ="";
score[i]+=score[j];
score[j]=0;
convine=true;
break;
}
}
}
}
}
}
convine=true;
while(convine) {
convine=false;
for(int i=0; i<M; i++) {
if(A[i].size()>2 && A[i].size()<N){
for(int j=0; j<M; j++) {
if( i==j ) continue;
if( (A[j].size() > 2) && ((A[i].size()+A[j].size()) <= N) ){
A[i] = A[i] + A[j];
A[j] ="";
score[i]+=score[j];
score[j]=0;
convine=true;
break;
}
}
}
}
}
for(int i=0; i<M; i++){
int max=score[i];
int maxj=i;
for(int j=i; j<M; j++){
if(score[j]>max) {
max=score[j];
maxj=j;
}
}
if( i!=maxj){
string tmp;
tmp=A[maxj];
A[maxj]=A[i];
A[i]=tmp;
int ti=score[maxj];
score[maxj]=score[i];
score[i]=ti;
}
}
for(int i=0; i<N; i++) {
if(A[i].size() < 20) A[i]+="....................";
}
for(int i=0; i<N; i++) {
cout << A[i].substr(0,20) << endl;
}
};
|
#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=(1<<19);
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar(); while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
LL dp[maxn];
LL ma[20][20];
LL s[maxn];///标记该集合状态是否是完全图
LL b[maxn];///标记每个点的连通点图状态
int main(void){
cin.tie(0);std::ios::sync_with_stdio(false);
LL n,m;cin>>n>>m;
for(LL i=1;i<=m;i++){
LL u,v;cin>>u>>v;
ma[u][v]=ma[v][u]=1;
}
for(LL i=1;i<=n;i++) b[i]=1<<(i-1);
for(LL i=1;i<=n;i++){
for(LL k=1;k<=n;k++){
if(ma[i][k]) b[i]|=1<<(k-1);
}
}
for(LL x=0;x<(1<<n);x++){
bool flag=1;
for(LL i=1;i<=n;i++){
if(x&(1<<(i-1))){
if(! ( (x|b[i])==b[i]) ){
flag=0;
break;
}
}
}
if(flag) s[x]=1;
}
memset(dp,0x3f,sizeof(dp));
dp[0]=0;
for(LL x=0;x<(1<<n);x++){
for(LL i=x;i;i=(i-1)&x){
if(s[i]) dp[x]=min(dp[x],dp[x^i]+1);
}
}
cout<<dp[(1<<n)-1]<<"\n";
return 0;
}
| #pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
constexpr ll MOD = 1'000'000'007LL; /*998'244'353LL;*/
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
template<class T> bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
constexpr int dy[4]={-1,0,1,0};
constexpr int dx[4]={0,-1,0,1};
int N, M;
int A[1000], B[1000];
bool con[18][18];
int dp[1<<18];
int solve(int s){
if(dp[s] != -1) return dp[s];
bool ok = true;
rep(i, N){
for(int j=i+1; j<N; j++){
if(((s>>i)&1) & ((s>>j)&1)){
ok &= con[i][j];
}
}
}
if(ok) return dp[s] = 1;
int ret = 100;
for(int i=(s-1)&s; i>0; i=(i-1)&s){
chmin(ret, solve(i) + solve(i^s));
}
return dp[s] = ret;
}
signed main(){
cin >> N >> M;
rep(i, M){
cin >> A[i] >> B[i];
A[i]--; B[i]--;
con[A[i]][B[i]] = true;
con[B[i]][A[i]] = true;
}
memset(dp, -1, sizeof(dp));
cout << solve((1<<N)-1) << endl;
} |
// Code Written by Pinaki Bhattacharjee (pinakipb2)
#include<bits/stdc++.h>
using namespace std;
// typedef
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
// #define
#define LOCAL
#define INF 1e18
#define PI 2*acos(0.0)
#define endl "\n"
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define ppc __builtin_popcountll
#define pinakipb2 ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// constants
const int MAX = 2e5 + 5;
const int MOD = (int) 1e9 + 7;
ll func(ll a)
{
ll temp=0;
while(a)
{
temp += (a%10);
a/=10;
}
return temp;
}
int main()
{
pinakipb2;
ll a,b;
cin>>a>>b;
cout<<max(func(a),func(b))<<endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 20;
const int M = 73;
const int K[N] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71};
ll a, b, f[M + 1][1 << N];
int s[M], c;
ll help(int i, int j) {
if (f[i][j]) {
return f[i][j];
}
f[i][j] = 1;
for (int k = i; k <= b - a; ++k) {
if (s[k] && (j & s[k]) == 0) {
f[i][j] += help(k + 1, j | s[k]);
}
}
return f[i][j];
}
int main() {
cin >> a >> b;
for (ll i = a; i <= b; ++i) {
for (int j = 0; j < N; ++j) {
if (i % K[j] == 0) {
s[i - a] |= 1 << j;
}
}
c += !s[i - a];
}
cout << help(0, 0) * (1 << c);
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define Rep(i,j,n) for(int i = j; i < (int)(n); i++)
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int main(){
int n; cin >> n;
int ans = 0;
rep(i,n){
int a; cin >> a;
a -= 10;
if(a >= 0) ans += a;
}
cout << ans << endl;
return 0;
} | /*
start of cp 3.0BETA
NEW-BETA-LADDER
https://codeforces.com/problemset/page/1?tags=1800-1800
DEAD PERSON CODING
*/
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007
#define int long long int
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define graph vector<vector<int>>
#define print(s) for(auto it:s) cout<<it<<" "
#define print2(s) for(auto it:s) cout<<it.fi<<" : "<<it.se
#define uset unordered_set
#define maxheap priority_queue<int>
#define minheap priority_queue<int,vi,greater<int>>
#define ln cout<<'\n'
#define space cout<<" "
#define len(x) x.size()
#define bits(x) __builtin_popcount(x)
void fileio()
{
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
}
graph g;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
fileio();
int n,m;
cin>>n>>m;
int o=0,e=0;
for(int i=0;i<n;i++){
string x;
cin>>x;
int ct=0;
for(int j=0;j<m;j++){
ct+=(x[j]=='1');
}
if(ct&1)o++;
else e++;
}
cout<<o*e;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 100;
typedef long long LL;
#define debug(x) cout << "debug : " << x << endl;
//#define int long long
//#define LOCAL
signed main() {
// ios::sync_with_stdio(0);
// cin.tie(0); cout.tie(0);
int a, b, c, d; cin >> a >> b >> c >> d;
int mx = -1e9;
for(int i = a; i <= b; ++i) {
for (int j = c; j <= d; ++j) {
mx = max(i - j, mx);
}
}
cout << mx << endl;
}
| #include<iostream>
using namespace std;
int main() {
int a,b,c,d;
cin>>a>>b>>c>>d;
int x,y;
if(a>b){
x = a;
}else x = b;
if(c>d){
y = d;
}else y = c;
cout<<x-y;
}
|
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
#define SIZE(x) ll(x.size())
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; }
typedef long long ll;
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
const int MAX_N = 10000;
typedef pair<int, int> P;
bool isPrime(int n) {
bool flag = true;
for (int i = 2; i * i <= n; i++) {
if (n % i == 0) {
flag = false;
break;
}
}
return flag;
}
int main()
{
int N;
cin >> N;
vector<int> ans, ct(4);
set<int> st;
int last = 3 * 5 * 7 * 11;
ct[0] = 3;
ct[1] = 5;
ct[2] = 7;
ct[3] = 11;
for (int i2 = 2; i2 <= MAX_N; i2 += 2) {
rep(i, 4) {
int t = i2 * ct[i];
if (t <= MAX_N) st.insert(t);
}
}
int cnt = 0;
for (auto i : st) {
cout << i << " ";
cnt++;
if (cnt >= N - 1) break;
}
cout << last << endl;
return 0;
} | #include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i < (n);i++)
using namespace std;
bool solve(string s) {
if(s.size() == 1) return s == "8";
if(s.size() == 2){
if(stoi(s) % 8 == 0) return 1;
swap(s[0], s[1]);
if(stoi(s) % 8 == 0) return 1;
return 0;
}
vector<int> cnt(10, 0);
int n = s.size();
rep(i,n) cnt[s[i] - '0']++;
for(int i = 112;i < 1000;i += 8) {
auto c = cnt;
for(char j : to_string(i)) c[j - '0']--;
bool flag = true;
for(char j : to_string(i)){
if(c[j - '0'] < 0) {
flag = false;
}
}
if(flag) return 1;
}
return 0;
}
int main() {
string s;
cin >> s;
string ans;
solve(s) ? ans = "Yes" : ans = "No";
cout << ans << endl;
} |
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <numeric>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <random>
#include <list>
#include <iomanip>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <deque>
#include <math.h>
#include <assert.h>
#include <functional>
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define ll long long
#define s(v) ((int)(v).size())
#define vLL(X) array<ll,X>
#define FOR(I,A,B) for(ll I = (A); I <= (B); I++)
#define RFOR(I,B,A) for(ll I = (B); I >=(A); I--)
#define SORT(c) (sort(c.begin(),c.end()))
#define aLL(X) X.begin(),X.end()
#define deb(x) cout << x << endl
#define deb1(x) cout << #x <<" "<< x << endl
#define deb2(x,y) cout << #x <<" "<< x <<" "<< #y <<" "<< y << endl
#define mem0(X) memset((X), 0, sizeof((X)))
#define mem1(X) memset((X), -1, sizeof((X)))
#define INS(v,v2) v.insert(v.end(), v2.begin(), v2.end());
#define BS(v,X) binary_search(v.begin(),v.end(),X)
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define CASES int ___T; cin >> ___T; for(int cs=1;cs<=___T;cs++)
#define Time cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<< "sec \n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
template<typename T>T gcd(T x, T y){if(y==0)return x;else return gcd(y,x%y);}
ll fx4[] = {0, 0, 1, -1};
ll fy4[] = {1, -1, 0, 0};
ll fx8[] = {1, 1, 0, -1, -1, -1, 0, 1};
ll fy8[] = {0, 1, 1, 1, 0, -1, -1, -1};
using db = double;
using LL = long long;
using ull = unsigned long long;
using pII = pair <int, int>;
using pLL = pair <long long, long long>;
const ll INF = 1e18;
const int mod = 1000000007;
const ll L_inf = 9223372036854775807;
const int inf = 2147483647;
const int mx = 1000005;
bool isprime[mx];
ll POWER(ll y,ll z){ll res=1;while(z){if(z%2==1){res=(res*y)%mod;}y=(y*y)%mod;z>>=1LL;}return res;}
void SIEVE(){for(ll i=2; i<=mx; i++)isprime[i]=true;for(ll i=3; i<=mx; i+=2){if(isprime[i]==true)
{for(ll J=i*i; J<=mx; J+=i)isprime[J]=false;}}}
int main()
{
IOS
ll n, a, b;
cin >> n >> a >> b;
deb(n-a+b);
}
| #include <bits/stdc++.h>
using namespace std;
int a, b, c, d, w;
int main()
{
cin >> a >> b >> w;
c = (w * 1000 + b - 1) / b;
d = w * 1000 / a;
if (d < c)
{
cout << "UNSATISFIABLE" << endl;
}
else
{
cout << c << ' ' << d << endl;
}
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pii;
#define ffor(i,n) for(ll i=0;i<n;i++)
#define rfor(x,y) for(ll i=x;i<y;i++)
#define ff first
#define ss second
#define pb push_back
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define all(v) v.begin(),v.end()
#define vi std::vector<ll>
#define M 1000000007
bool cmp(pii a,pii b)
{
return 2*a.ff + a.ss > 2*b.ff + b.ss;
}
void solve()
{
ll n;
cin>>n;
vector<pii> v(n);
ll a=0,k=0;
ffor(i,n){
cin>>v[i].ff>>v[i].ss;
a+=v[i].ff;}
k = 0;
sort(all(v),cmp);
ll i=0;
while(a >= k)
{
k += (v[i].ff + v[i].ss);
a -= v[i].ff;
i++;
}
cout<<i<<endl;
return;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.in","r",stdin);
freopen("output.in","w",stdout);
#endif
fastio
ll t=1;
// cin>>t;
while(t--)
{
solve();
}
return 0;
} | // code by lynmisakura. wish to be accepted!
#include<bits/stdc++.h>
using ll = long long;
using namespace std;
#define debug(arr) std::cout << #arr << " = " << arr << '\n'
#define debug2(a,b) std::cout<<"["<<#a<<","<<#b<<"] = "<<"["<<a<<","<<b<<"]\n"
#define debug3(a,b,c) std::cout<<"["<<#a<<","<<#b<<","<<#c<<"] = "<<"["<<a<<","<<b<<","<<c<<"]\n"
template<class T> std::ostream &operator << (std::ostream& out, const std::vector<T>& arr) {
std::cout << "{"; for (int i = 0; i < arr.size(); i++)std::cout << (!i ? "" : ", ") << arr[i]; std::cout << "}";
return out;
}
template<class T> std::ostream &operator << (std::ostream& out, const std::vector<std::vector<T> >& arr) {
std::cout << "{\n"; for (auto& vec : arr)std::cout << " " << vec << ",\n"; std::cout << "}";
return out;
}
template<class S,class T> std::ostream &operator << (std::ostream& out, const std::pair<S,T>& p){
std::cout << "{" << p.first << "," << p.second << "}" << '\n';
return out;
}
template<class T> std::istream &operator >> (std::istream& in, std::vector<T>& arr) {
for (auto& i : arr) std::cin >> i; return in;
}
template<class S,class T> std::istream &operator >> (std::istream& in,std::pair<S,T>& p){
std::cin >> p.first >> p.second; return in;
}
template<class T> void debug_a(T *a , int N){
std::cout << "debug array : {";
for(int i = 0;i < N;i++){
std::cout << *(a + i) << (i < N-1 ? ", " : "}\n");
}
}
#define REP(i,N) for(int i = 0;i < N;i++)
int n,q;
vector<int> graph[200020];
int U[200020],D[200020];
void __input__(){
cin >> n;
REP(i,n-1){
int p;cin >> p;
p--;
graph[i+1].push_back(p);
graph[p].push_back(i+1);
}
cin >> q;
REP(i,q) cin >> U[i] >> D[i] , U[i]--;
}
int dist[200020];
pair<int,int> pos[200020];
vector<int> dists[200020];
int num = 0;
vector<int> tour;
void dfs(int x,int p,int d){
tour.push_back(x);
dists[d].push_back(num);
pos[x].first = num++;
dist[x] = d;
for(int to : graph[x]){
if(to != p) dfs(to,x,d+1);
}
tour.push_back(-x);
pos[x].second = num++;
return;
}
int main(){
__input__();
dfs(0,-1,0);
// debug(tour);
REP(i,200020) dists[i].push_back(100000000);
REP(i,q){
cout << lower_bound(dists[D[i]].begin(),dists[D[i]].end(),pos[U[i]].second)
- lower_bound(dists[D[i]].begin(),dists[D[i]].end(),pos[U[i]].first) << '\n';
}
}
|
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef long long ll;
#define test ll t;cin>>t;while(t--)
#define f first
#define s second
#define pb push_back
#define pop pop_back
#define int long long int
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define mod 1000000007
#define inf 1LL<<60
int grid[16][16];
int ans;
bool check(int h,int w)
{
for(int i=0;i<h;i++)
{
for(int j=0;j<w;j++)
{
if(grid[i][j]==-1)
return false;
}
}
return true;
}
void helper(int h,int w,int a,int b)
{
if(a==0 && b==0)
{
if(check(h,w))
{
ans++;
}
return;
}
int i,j;
bool flag=0;
for(int x=0;x<h;x++)
{
for(int y=0;y<w;y++)
{
if(grid[x][y]==-1)
{
i=x;
j=y;
flag=1;
break;
}
}
if(flag)
break;
}
if(a>0 && grid[i][j]==-1 && j+1<w && grid[i][j+1]==-1)
{
grid[i][j]=1;
grid[i][j+1]=1;
helper(h,w,a-1,b);
grid[i][j]=-1;
grid[i][j+1]=-1;
}
if(a>0 && grid[i][j]==-1 && i+1<h && grid[i+1][j]==-1)
{
grid[i][j]=1;
grid[i+1][j]=1;
helper(h,w,a-1,b);
grid[i][j]=-1;
grid[i+1][j]=-1;
}
if(b>0 && grid[i][j]==-1)
{
grid[i][j]=1;
helper(h,w,a,b-1);
grid[i][j]=-1;
}
return;
}
int32_t main()
{
fast;
int h,w,a,b;
cin>>h>>w>>a>>b;
ans=0;
memset(grid,-1,sizeof(grid));
helper(h,w,a,b);
cout<<ans;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define _for(i,a,b) for(int i = (a); i < (b); i++)
#define _rep(i,a,b) for(int i = (a); i <= (b); i++)
#define all(v) (v).begin(), (v).end()
#define nl "\n"
#define reunique(v) v.resize(std::unique(v.begin(), v.end()) - v.begin())
#define sz(v) ((int)(v).size())
//#define LOCAL
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
#ifdef LOCAL
//#include "pretty_print.h"
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define dbg(...) 42
#endif
template <typename T> T sqr(T x) { return x * x; }
template <typename T> T abs(T x) { return x < 0? -x : x; }
template <typename T> T gcd(T a, T b) { return b? gcd(b, a % b) : a; }
template <typename T> bool chmin(T &x, const T& y) { if (x > y) { x = y; return true; } return false; }
template <typename T> bool chmax(T &x, const T& y) { if (x < y) { x = y; return true; } return false; }
auto random_address = [] { char *p = new char; delete p; return (uint64_t) p; };
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count() * (random_address() | 1));
mt19937_64 rngll(chrono::steady_clock::now().time_since_epoch().count() * (random_address() | 1));
#define PI acos(-1)
void taskD() {
double n, x0, y0, x1, y1;
cin >> n >> x0 >> y0 >> x1 >> y1;
double a = 2*PI/n;
double xm = (x0+x1)/2;
double ym = (y0+y1)/2;
double x = (x0-xm)*cos(a) - (y0-ym)*sin(a)+xm;
double y = (x0-xm)*sin(a) + (y0-ym)*cos(a)+ym;
//cout << " PI = " << PI << "\n";
cout << setiosflags(ios::fixed) << setprecision(11) << x << " ";
cout << setiosflags(ios::fixed) << setprecision(11) << y << "\n";
return;
}
int main() {
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
taskD();
//task10391();
//task1595();
#ifdef LOCAL
//assert(freopen("i.txt", "r", stdin)); assert(freopen("o.txt", "w", stdout));
//freopen("i.txt", "r", stdin); freopen("o.txt", "w", stdout);
cerr << "Time execute: " << clock() / (double)CLOCKS_PER_SEC << " sec" << endl;
#endif
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
// const ll mod = 998244353;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;
//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
ll res = 1;
while (n) {
if (n & 1)res = res * a%m;
a = a * a%m; n >>= 1;
}
return res;
}
struct modint {
ll n;
modint() :n(0) { ; }
modint(ll m) :n(m) {
if (n >= mod)n %= mod;
else if (n < 0)n = (n%mod + mod) % mod;
}
operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
if (n == 0)return modint(1);
modint res = (a*a) ^ (n / 2);
if (n % 2)res = res * a;
return res;
}
//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }
const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
fact[0] = modint(1);
for (int i = 0; i < max_n - 1; i++) {
fact[i + 1] = fact[i] * modint(i + 1);
}
factinv[max_n - 1] = modint(1) / fact[max_n - 1];
for (int i = max_n - 2; i >= 0; i--) {
factinv[i] = factinv[i + 1] * modint(i + 1);
}
}
modint comb(int a, int b) {
if (a < 0 || b < 0 || a < b)return 0;
return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
void solve() {
int h, w; cin >> h >> w;
vector<string> s(h);
rep(i, h) cin >> s[i];
vector<vec> yoko(h+1, vec(w, 0)), tate(h, vec(w+1, 0));
rep(i, h){
rep(j, w){
if(s[i][j] == '#'){
if(s[i+dy[0]][j+dx[0]] != '#') yoko[i+1][j] = 1;
if(s[i+dy[1]][j+dx[1]] != '#') tate[i][j+1] = 1;
if(s[i+dy[2]][j+dx[2]] != '#') yoko[i][j] = 1;
if(s[i+dy[3]][j+dx[3]] != '#') tate[i][j] = 1;
}
}
}
int res = 0;
rep(i, h+1){
bool f = false;
rep(j, w){
if(yoko[i][j]){
if(!f){
f = true;
}
}else{
if(f){
f = false;
res++;
}
}
}
}
rep(j, w+1){
bool f = false;
rep(i, h){
if(tate[i][j]){
if(!f){
f = true;
}
}else{
if(f){
f = false;
res++;
}
}
}
}
cout << res << endl;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
//cout << fixed << setprecision(10);
//init_f();
//init();
//int t; cin >> t; rep(i, t)solve();
solve();
// stop
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
char grid[15][15];
int numOfV(int x, int y){
if(grid[x][y] != '#') return 0;
int vertexs = 0;
if(grid[x][y-1] != '#' && grid[x+1][y] != '#' && grid[x-1][y] != '#'){ vertexs += 2; /*cout<<"1"<<endl;*/}
if(grid[x][y-1] != '#' && grid[x][y+1] != '#' && grid[x-1][y] != '#') { vertexs += 2;}// cout<<"2"<<endl;}
if(grid[x-1][y] != '#' && grid[x+1][y] != '#' && grid[x][y+1] != '#') { vertexs += 2;}// cout<<"3"<<endl;}
if(grid[x][y-1] != '#' && grid[x][y+1] != '#' && grid[x+1][y] != '#') { vertexs += 2;}// cout<<"4"<<endl;}
if(grid[x+1][y] == '#' && grid[x][y+1] == '#' && grid[x+1][y+1] != '#'){ vertexs++;}// cout<<"5"<<endl;}
if(grid[x-1][y] == '#' && grid[x][y+1] == '#' && grid[x-1][y+1] != '#'){ vertexs++;}// cout<<"6"<<endl;}
if(grid[x][y-1] == '#' && grid[x+1][y] == '#' && grid[x+1][y-1] != '#'){ vertexs++;}// cout<<"7"<<endl;}
if(grid[x-1][y] == '#' && grid[x][y-1] == '#' && grid[x-1][y-1] != '#'){ vertexs++;}// cout<<"8"<<endl;}
//if(grid[x+1][y] == '#' && grid[x][y-1] == '#' && grid[x+1][y-1] != '#'){ vertexs++; cout<<"9"<<endl;}
if(grid[x+1][y] == '#' && grid[x][y+1] == '#' && grid[x-1][y] != '#' && grid[x][y-1] != '#'){ vertexs++;}// cout<<"9"<<endl;}
if(grid[x+1][y] == '#' && grid[x][y-1] == '#' && grid[x-1][y] != '#' && grid[x][y+1] != '#'){ vertexs++;}// cout<<"10"<<endl;}
if(grid[x][y-1] == '#' && grid[x-1][y] == '#' && grid[x+1][y] != '#' && grid[x][y+1] != '#'){ vertexs++;}// cout<<"11"<<endl;}
if(grid[x-1][y] == '#' && grid[x][y+1] == '#' && grid[x+1][y] != '#' && grid[x][y-1] != '#'){ vertexs++;}// cout<<"12"<<endl;}
return vertexs;
}
int main(){
int n,w; cin>>n>>w;
int vertexs = 0;
int catCounter = 0;
for(int i = 0; i<n; i++){
for(int j = 0; j<w; j++){
cin>>grid[i][j];
if(grid[i][j] == '#') catCounter++;
}
}
for(int i = 1; i<n-1; i++){
for(int j = 1; j<w-1; j++){
int noV = numOfV(i,j);
//cout<<"i = "<<i<< " j = "<<j<<" v = "<< noV << endl;
vertexs += noV;
}
}
if(catCounter == 1) cout<<"4\n";
else cout<<vertexs<<"\n";
}
|
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(c) (c).begin(), (c).end()
#define pb push_back
#define eb emplace_back
using namespace std;
const long long INF = 1LL<<60; // 仮想的な無限大の値;
using ll = long long;
using P = pair<int, int>;
#define vi vector<int>
#define vll vector<ll>
#define vs vector<string>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b){
if(b == 0) return a;
return gcd(b, a%b);
}
int main()
{
int n;
cin >> n;
vll a(n);
rep(i, n) cin >> a[i];
ll x = a[0];
rep(i, n){
x = gcd(x, a[i]);
}
cout << x << endl;
// ll MAX = -1, MIN = INF;
// multiset<ll> X;
// rep(i, n){
// cin >> a[i];
// chmax(MAX, a[i]);
// chmin(MIN, a[i]);
// X.insert(a[i]);
// }
// rep(i, n){
// ll max = *X.rbegin();
// if(a[i] == max){
// cout << a[i] << endl;return 0;
// }
// rep(i, X.count(max)) X.insert(*X.rbegin()-*X.begin());
// X.erase(max);
// }
// ll ans = *X.begin();
// cout << *X.begin() << endl;return 0;
return 0;
} | #include "bits/stdc++.h"
#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define rrep(i, n) for(ll i=(n)-1; i >=0; i--)
#define ALL(v) v.begin(),v.end()
#define rALL(v) v.rbegin(),v.rend()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define debug_print(var) cerr << #var << "=" << var <<endl;
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" "
#define fi first
#define se second
using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge{ll x, c;};
vector<llvec> e;
llvec p;
using PP = pair<ll, P>;
vector<ll> d;
llvec tour;
vector<P> range;
void dfs(ll i){
range[i].fi = tour.size();
tour.push_back(d[i]);
for(auto ie: e[i]){
d[ie] = d[i] + 1;
dfs(ie);
}
//tour.push_back(d[i]);
range[i].se = tour.size();
return;
}
/**************************************
** A main function starts from here **
***************************************/
int main(){
ll N;
cin >> N;
p = llvec(N);
d = llvec(N, -1);
e = vector<llvec>(N);
//tour = llvec(N);
range = vector<P>(N);
rep(i, N-1){
ll t;
cin >> t;
t--;
e[t].push_back(i+1);
}
d[0] = 0;
dfs(0);
ll Q;
cin >> Q;
vector<P> v(Q);
rep(i, Q){
ll u, t;
cin >> u >> t;
u--;
v[i] = {u, t};
}
vector<llvec> dd(N+1);
ll cnt = 0;
for(auto i: tour){
dd[i].push_back(cnt);
cnt++;
}
for(auto iv: v){
ll num = lower_bound(ALL(dd[iv.se]), range[iv.fi].se) - lower_bound(ALL(dd[iv.se]), range[iv.fi].fi);
cout << num << endl;
}
return 0;
}
|
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<int> d(3);
int ans = 0;
for (auto& x : d) {
cin >> x;
ans += 7 - x;
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int d4r[] = {1, 0, -1, 0}, d4c[] = {0, 1, 0, -1};
int d8r[] = {1, 1, 0, -1, -1, -1, 0, 1}, d8c[] = {0, 1, 1, 1, 0, -1, -1, -1};
constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
constexpr int INF = 1001001001;
constexpr long long LINF = 1001002003004005006;
constexpr double PI = acos(-1);
template<typename T> inline void chmax(T &a, T b) {a = max(a, b);}
template<typename T> inline void chmin(T &a, T b) {a = min(a, b);}
int main() {
int a,b,c; cin >> a >> b >> c;
cout << 21- a-b-c << '\n';
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;
#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)
int main() {
int n,k,m;
cin >> n >> k >> m;
int a=0;
int temp;
rep(i,n-1) {
cin >> temp;
a += temp;
}
//cout << a << endl;
rep(i,k+1) {
if (((a + i)/n)>=m) {
cout << i << endl;
return 0;
}
}
cout << "-1" << endl;
return 0;
}
| #include <iostream>
using namespace std;
int main(){
int n, k, m, sum = 0;
cin >> n >> k >> m;
int *a = new int[n];
for(int i=0;i<n-1;i++){
cin >> a[i];
}
for(int i=0;i<n-1;i++){
sum += a[i];
}
if(n*m-sum<=k){
if(n*m-sum>0){
cout << n*m-sum << endl;
}else {
cout << '0' << endl;
}
}else{
cout << "-1" << 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<int> x(n);
rep(i,n) cin >> x[i];
ll ansM=0;
double ans=0;
int ansC=0;
ll ansU=0;
rep(i,n) {
ansM += abs(x[i]);
ll x2 = ll(x[i])*ll(x[i]);
ansU += x2;
ansC = max(ansC,abs(x[i]));
}
ans +=ansU;
ans = sqrt(ans);
cout << ansM << endl;
printf("%.15lf\n", ans);
cout << ansC << endl;
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
int n,p,ans;
bool b[200010];
inline int read()
{
int num=0,flag=1;
char c=getchar();
for (;c<'0'||c>'9';c=getchar())
if (c=='-') flag=-1;
for (;c>='0'&&c<='9';c=getchar())
num=(num<<3)+(num<<1)+c-48;
return num*flag;
}
int main()
{
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
memset(b,0,sizeof(b));
ans=0;
n=read();
for (int i=1;i<=n;++i)
{
p=read();
b[p]=true;
if (ans==p)
for (int j=p+1;j<=200000;++j)
if (!b[j])
{
ans=j;
break;
}
printf("%d\n",ans);
}
fclose(stdin);
fclose(stdout);
return 0;
}
|
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define test int tt; cin>>tt; while(tt--)
#define ff first
#define ss second
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin>>n;
vector<pair<pair<int, int>, int>> intervals(n);
for(auto &[in, t]: intervals)
cin>>t>>in.ff>>in.ss;
sort(intervals.begin(), intervals.end());
ll int ans=0;
for(int i=0; i<n; i++)
{
for(int j=i+1; j<n; j++)
{
int l1=intervals[i].ff.ff;
int r1=intervals[i].ff.ss;
int t1=intervals[i].ss;
int l2=intervals[j].ff.ff;
int r2=intervals[j].ff.ss;
int t2=intervals[j].ss;
if((t1==1 || t1==3) && t2<=2 && r1>=l2)
ans++;
else if((t1==1 || t1==3) && t2>2 && r1>l2)
ans++;
else if((t1==2 || t1==4) && r1>l2)
ans++;
}
}
cout<<ans<<endl;
}
| #include <bits/stdc++.h>
#include <iostream>
#include<stdio.h>
#include<math.h>
#include<string.h>
using namespace std;
double mina(double a,double b)
{
if(a<=b)
return a;
return b;
}
double maxa(double a,double b)
{
if(a<=b)
return b;
return a;
}
int main() {
long long int t,n,i,j,k,l,flag,flag1,count,count1,count2,count3,count4,sum,max1,max2,m,c1,c2,temp,suma,sumb;
long long int d,e,a,b,c;
double a2[300001],b1[2002][3],a1[300001];
//vector< long long int> v1,v2,v;
// vector< pair <long long int,long long int> > v3;
// string s1,s2,s;
// char s[300001],s1[300001];
// long long int f[100001];
// for(i=0;i<100001;i++)
// f[i]=0;
count=0,flag=0,flag1=0,sum=0,max1=0,max2=0,c1=0,c2=0,temp=0,suma=0,sumb=0,count1=0,count2=0,count3=0,count4=0;
// long long int max3=0,max4=0,ans=0,mina=999999999999999999,c0=0,c3,c4;
cin>>n;
for(i=0;i<n;i++)
{
for(j=0;j<3;j++)
cin>>b1[i][j];
}
for(i=0;i<n;i++)
{
if(b1[i][0]==2)
b1[i][2]=b1[i][2]-0.1;
else if(b1[i][0]==3)
b1[i][1]=b1[i][1]+0.1;
if(b1[i][0]==4)
{
b1[i][2]=b1[i][2]-0.1;
b1[i][1]=b1[i][1]+0.1;
}
}
for(i=0;i<n;i++)
{
if(b1[i][1]>b1[i][2])
swap(b1[i][1],b1[i][2]);
}
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(mina(b1[i][2],b1[j][2]) >=maxa( b1[i][1],b1[j][1]) )
count++;
}
}
//for(i=0;i<n;i++)
// for(j=0;j<3;j++)
// cout<<b1[i][j];
cout<<count;
return 0;
} |
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#define for_n(i, n) for (int i = 0; i < (int) n; i++)
using namespace std;
using li = int;
const li INF = 0x3fffffff;
struct vertex {
vector<li> neigh;
};
int main() {
li n, m, a, b, k; cin >> n >> m;
vector<vertex> vertices(n + 1);
while (m--) {
cin >> a >> b;
vertices[a].neigh.push_back(b);
vertices[b].neigh.push_back(a);
}
cin >> k;
vector<li> gems(k, 0);
for_n(i, k) cin >> gems[i];
auto bfs = [&](int beg) {
vector<li> costs(n + 1, INF);
costs[beg] = 0;
queue<li> queue;
queue.push(beg);
while (!queue.empty()) {
li next = queue.front(); queue.pop();
for (auto y : vertices[next].neigh) {
if (costs[next] + 1 < costs[y]) {
costs[y] = costs[next] + 1;
queue.push(y);
}
}
}
vector<li> final_costs(k, 0);
for_n(i, k) final_costs[i] = costs[gems[i]];
return final_costs;
};
vector<vector<li>> dp(1 << k, vector<li>(k, INF));
vector<vector<li>> costs(k);
for_n(i, k) costs[i] = bfs(gems[i]);
for (li i = 0; i < k; i++) dp[1 << i][i] = 1;
for (li bit = 1; bit < 1 << k; bit++)
for (li i = 0; i < k; i++)
if (bit & 1 << i) {
li bit2 = bit ^ 1 << i;
for (li j = 0; j < k; j++)
if (bit2 & 1 << j)
dp[bit][i] = min(dp[bit][i], dp[bit2][j] + costs[i][j]);
}
li ans = *min_element(dp.back().begin(), dp.back().end());
if(ans == INF) ans = -1;
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
t=0; char ch=getchar(); int f=1;
while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
const int maxn=(2e5)+10;
int n,k,mid,tot;
vector<int> g[maxn];
int mx[maxn];
void dfs(int u,int p) {
mx[u]=0;
for (int v : g[u]) if (v!=p) {
dfs(v,u);
if (mx[u]+mx[v]+1>2*mid) {
tot++;
mx[u]=min(mx[u],mx[v]+1);
} else mx[u]=max(mx[u],mx[v]+1);
}
}
bool solve() {
tot=0;
dfs(1,0);
return tot+1<=k;
}
int main() {
//freopen("1.txt","r",stdin);
read(n),read(k); int x,y;
for (int i=1;i<n;i++) {
read(x),read(y);
g[x].push_back(y),g[y].push_back(x);
}
int l=0,r=n,res;
while (l<=r) {
mid=(l+r)>>1;
if (solve()) res=mid,r=mid-1;
else l=mid+1;
}
printf("%d\n",res);
return 0;
}
/*
0. Enough array size? Enough array size? Enough array size? Integer overflow?
1. Think TWICE, Code ONCE!
Are there any counterexamples to your algo?
2. Be careful about the BOUNDARIES!
N=1? P=1? Something about 0?
3. Do not make STUPID MISTAKES!
Time complexity? Memory usage? Precision error?
*/ |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FOR1(i, n) for(int (i)=1; (i)<=(n); (i)++)
#define FORI(i, n) for(int (i)=n-1; (i)>=0; (i)--)
template<class T, class U> void umin(T& x, const U& y){ x = min(x, (T)y);}
template<class T, class U> void umax(T& x, const U& y){ x = max(x, (T)y);}
template<class T, class U> void init(vector<T> &v, U x, size_t n) { v=vector<T>(n, (T)x); }
template<class T, class U, typename... W> void init(vector<T> &v, U x, size_t n, W... m) { v=vector<T>(n); for(auto& a : v) init(a, x, m...); }
int n;
vector<ll> d; vector<int> mtl;
vector<vector<int>> edges;
vector<int> par;
vector<bool> marked;
int mintoleaf(int u, int p){
if (mtl[u]!=-1) return mtl[u];
int ret = n+1;
for(int v : edges[u]) if (v !=p){
umin(ret, 1 + mintoleaf(v, u));
}
if (edges[u].size() == 1)
ret = 0;
return mtl[u] = ret;
}
void dfs1(int u, int p){
for(int v : edges[u]) if (v !=p){
d[v] = d[u]+1;
par[v] = u;
dfs1(v, u);
}
}
int dfs(int u, int p, int e){
d[u] = e;
vector<pii> o;
for(int v : edges[u]) if (v != p){
o.emplace_back(mintoleaf(v, u), v);
if (marked[v]) o.back().first = 1e9;
}
sort(o.begin(), o.end());
int start = e+1;
for(auto it : o){
int dist = dfs(it.second, u, start);
start = dist + 1;
}
return start;
}
int main(int argc, char** argv) {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(15);
if (argc == 2 && atoi(argv[1]) == 123456789) freopen("d:\\code\\cpp\\contests\\stdin", "r", stdin);
cin >> n;
edges.resize(n+1);
d.resize(n+1);
mtl.resize(n+1, -1);
FOR(i, n-1){
int u, v;
cin >> u >> v;
edges[u].push_back(v);
edges[v].push_back(u);
}
int ondiag = 1;
d.clear(); d.resize(n + 1);
par.clear(); par.resize(n+1);
dfs1(ondiag, -1);
int dist = -1;
ondiag = -1;
FOR1(u, n) {
if (d[u] > dist) {
dist = d[u];
ondiag = u;
}
}
d.clear(); d.resize(n + 1);
par.clear(); par.resize(n+1);
dfs1(ondiag, -1);
marked.clear(); marked.resize(n+1);
dist = -1;
int other = -1;
FOR1(u, n){
if (d[u] > dist){
dist = d[u];
other = u;
}
}
marked[other] = 1;
while(other!=ondiag){
other = par[other];
marked[other] = 1;
}
d.clear(); d.resize(n + 1);
dfs(ondiag, -1, 1);
FOR1(i, n)
cout << d[i] << " "; cout << endl;
if (argc == 2 && atoi(argv[1]) == 123456789) cout << clock()*1.0/CLOCKS_PER_SEC << " sec\n";
return 0;
}
| // YATIN KWATRA
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ar array
#define sz(v) (int)(v.size())
#define inf 1e18
#define int ll
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ld long double
#define ull unsigned long long
#define endl "\n"
#define fo(i,a,b) for(int i = a; i<=b ; i++)
#define rfo(i,a,b) for(int i = a; i>=b ; i--)
#define vii vector<int>
#define pq priority_queue
#define uomii unordered_map<int,int,best_hash>
#define all(v) v.begin(),v.end()
#define mp make_pair
#define pb push_back
#define pob pop_back
#define ff first
#define ss second
#define pii pair<int,int>
#define mii map<int,int>
#define vvii vector<vii>
#define mod 200
#define MIN -1e9
#define pi 3.1415926535897932384626433832795
#define cz(x) 63 - __builtin_clzll(x)
using namespace std;
using namespace __gnu_pbds;
template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
struct best_hash {
static uint64_t splitmix64(uint64_t x) {
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 INPUT()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
/*
----------------------------------------------------------------
-> Check For Overflows
-> Out of Bounds
-> Initialisations of global arrays and variables
----------------------------------------------------------------
*/
void solve()
{
int n;
cin >> n;
vii v(n);
fo(i, 0, n - 1) cin >> v[i], v[i] %= mod;
uomii dp;
n = min(n, 20LL);
for (int mask = 1; mask < (1 << n); mask++) {
int sum = 0;
fo(i, 0, n - 1) if (mask & (1 << i)) sum = (sum + v[i]) % mod;
if (dp.count(sum)) {
cout << "YES\n";
cout << __builtin_popcount(mask) << " ";
fo(i, 0, n - 1) {
if (mask & (1 << i)) cout << i + 1 << " ";
}
cout << endl;
cout << __builtin_popcount(dp[sum]) << " ";
fo(i, 0, n - 1) {
if (dp[sum] & (1 << i)) cout << i + 1 << " ";
}
cout << endl;
return;
}
dp[sum] = mask;
}
cout << "NO\n";
}
signed main() {
FIO
INPUT();
int t;
t = 1;
//cin >> t;
fo(i, 0, t - 1) {
solve();
}
return 0;
}
|
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
#include <cmath>
#include <deque>
using ll=long long;
using namespace std;
int main(){
int R,C;
cin>>R>>C;
vector<vector<int>> A(R,vector<int>(C-1));
vector<vector<int>> B(R-1,vector<int>(C));
for(int i=0;i<R;i++){
for(int j=0;j<C-1;j++){
cin>>A[i][j];
}
}
for(int i=0;i<R-1;i++){
for(int j=0;j<C;j++){
cin>>B[i][j];
}
}
ll INF = 1e15;
vector<vector<ll>> dp(R,vector<ll>(C,INF));
dp[0][0] = 0;
priority_queue<pair<ll, pair<int,int>>> q;
q.push({0,{0,0}});
while(!q.empty()){
auto recv = q.top();
ll nowc = recv.first*-1;
int nx = recv.second.first;
int ny = recv.second.second;
q.pop();
//cout<<nowc<<" "<<nx<<" "<<ny<<endl;
/*
if(dp[nx][ny] <= nowc){
continue;
}else{
dp[nx][ny] = nowc;
}
//*/
if(nx == R-1 && ny == C-1){
break;
}
if(ny < C-1){
ll cos = nowc+A[nx][ny];
if(dp[nx][ny+1] > cos){
dp[nx][ny+1] = cos;
q.push({-1*cos, {nx, ny+1}});
}
}
if(ny > 0){
ll cos = nowc+A[nx][ny-1];
if(dp[nx][ny-1] > cos){
dp[nx][ny-1] = cos;
q.push({-1*(nowc+A[nx][ny-1]), {nx,ny-1}});
}
}
if(nx < R-1){
ll cos = nowc+B[nx][ny];
if(dp[nx+1][ny] > cos){
dp[nx+1][ny] = cos;
q.push({-1*(nowc+B[nx][ny]), {nx+1,ny}});
}
}
//*
for(int i=1;i<=nx;i++){
if(nowc+1+i > dp[nx-i][ny]){
break;
}
dp[nx-i][ny] = nowc+1+i;
q.push({-1*(nowc+1+i), {nx-i,ny}});
}
//*/
/*
if(nx != 0){
q.push({-1*(nowc)})
}
//*/
}
cout<<dp[R-1][C-1]<<endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)
template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;}
const char newl = '\n';
template <typename T>
void dijkstra(int s,vector<vector<pair<int,T>>>& edges,vector<T>& dist) {
priority_queue<pair<T,int>,vector<pair<T,int>>,greater<pair<T,int>>> que;
dist[s] = 0;
que.push(make_pair(0,s));
while (!que.empty()) {
pair<ll,int> p = que.top();
que.pop();
int v = p.second;
if (dist[v] < p.first) continue;
for (pair<int,T>& e : edges[v]) {
if (dist[e.first] > dist[v]+e.second) {
dist[e.first] = dist[v]+e.second;
que.push(make_pair(dist[e.first],e.first));
}
}
}
}
int r,c;
int coord(int i,int j) {
return i*c+j;
}
int main() {
cin >> r >> c;
vector<vector<pair<int,ll>>> edges(r*c*2);
for (int i = 0;i < r;++i) for (int j = 0;j < c-1;++j) {
int a;
scanf("%d",&a);
edges[coord(i,j)].push_back(make_pair(coord(i,j+1),a));
edges[coord(i,j+1)].push_back(make_pair(coord(i,j),a));
}
for (int i = 0;i < r-1;++i) for (int j = 0;j < c;++j) {
int a;
scanf("%d",&a);
edges[coord(i,j)].push_back(make_pair(coord(i+1,j),a));
}
for (int i = 0;i < r;++i) for (int j = 0;j < c;++j) {
edges[coord(i,j)].push_back(make_pair(coord(i,j)+r*c,0));
edges[coord(i,j)+r*c].push_back(make_pair(coord(i,j),1));
}
for (int i = 1;i < r;++i) for (int j = 0;j < c;++j) {
edges[coord(i,j)+r*c].push_back(make_pair(coord(i-1,j)+r*c,1));
}
vector<ll> dist(2*r*c,1e18);
dijkstra(0,edges,dist);
cout << dist[coord(r-1,c-1)] << newl;
} |
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <sstream>
#include <set>
#include <functional>
#include <map>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define all(u) u.begin(),u.end()
using Interval = pair<ll,ll>;
using Graph = vector<vector<ll> >;
template<class T> void chmax(T& a, T b){
if (a < b){
a=b;
}
}
template<class T> void chmin(T& a, T b){
if (a > b){
a=b;
}
}
int main(){
ll N;
cin >> N;
vector<ll> a(N);
rep(i,N) cin >> a[i];
ll ans;
ll maxnum = 0;
repi(i,2,1001){
ll num = 0;
rep(j,N){
if (a[j] % i == 0) num++;
}
if (num >= maxnum){
maxnum = num;
ans = i;
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
#define ll long long
#define sf scanf
#define pf printf
#define nl printf("\n")
#define endl '\n'
#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--)
#define TEST int Test;cin>>Test;for(int _t=1;_t<=Test;_t++)
#define isValid(a,b,A,B) (0<=a&&a<A) and (0<=b&&b<B)
using namespace std;
template <typename... T> void read(T &... args){ ((cin >> args), ...); }
void yes(){ pf("Yes\n"); }
void no() { pf("No\n"); }
typedef pair<int,int> Pr;
int main()
{
int n,x;
vector<Pr> vec,temp;
read(n);
n = pow(2,n);
rep(i,0,n) read(x), vec.pb(Pr(x,i+1));
while(vec.size()>2){
for(int i=0; i<(int)vec.size(); i+=2){
if(vec[i].first>vec[i+1].first)
temp.pb(vec[i]);
else temp.pb(vec[i+1]);
}
vec.clear();
for(auto w : temp) vec.pb(w);
temp.clear();
}
int ans;
if(vec[0].first<vec[1].first) ans = vec[0].second;
else ans = vec[1].second;
pf("%d\n",ans);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a,b,c;
cin>>a>>b>>c;
cout<<(7-a)+(7-b)+(7-c);
return 0;
} | //多练,就是多练
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
//记得初始化和clear
//记得取模
//数组开够
//边界情况不要想当然
//特判记得return
const int maxn=100010;
const int mod=1e9+7;
int a[1010];
void solve(int T)
{
ll a,b,c;
cin>>a>>b>>c;
if(c%2==0)
{
if(c==0)
{
cout<<"="<<endl;
return;
}
a=abs(a);b=abs(b);
if(a>b) cout<<">"<<endl;
else if(a==b) cout<<"="<<endl;
else cout<<"<"<<endl;
}
else
{
if(a<0&&b<0)
{
if(a>b) cout<<">"<<endl;
else if(a==b) cout<<"="<<endl;
else cout<<"<"<<endl;
}
else if(a>=0&&b>=0)
{
if(a>b) cout<<">"<<endl;
else if(a==b) cout<<"="<<endl;
else cout<<"<"<<endl;
}
else if(a>=0&&b<0) cout<<">"<<endl;
else if(a<0&&b>=0) cout<<"<"<<endl;
}
}
//#define ONLINE_JUDGE
signed main()
{
#ifndef ONLINE_JUDGE
freopen("lotato.in","r",stdin);
freopen("lotato.out","w",stdout);
#endif
int t=1;
//scanf("%d",&t);
for(int i=1;i<=t;i++)
{
solve(i);
}
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fast_IO ios::sync_with_stdio(false);
#define DEBUG fprintf(stderr,"Running on Line %d in Function %s\n",__LINE__,__FUNCTION__)
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define fir first
#define sec second
#define mod 998244353
#define ll long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
inline int read()
{
char ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();}
int ans=0; while(isdigit(ch)) {ans=ans*10+ch-48;ch=getchar();}
if(nega==-1) return -ans;
return ans;
}
typedef pair<int,int> pii;
void print(vector<int> x){for(int i=0;i<(int)x.size();i++) printf("%d%c",x[i]," \n"[i==(int)x.size()-1]);}
signed main()
{
int n=read(),ans=0;
for(int i=1;i<=n;i++)
{
for(int j=1;i*j<=n;j++)
{
ans+=n/i/j;
}
}
cout<<ans<<endl;
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
#define int long long int
#define endl '\n'
int countConsecutive(int N)
{
int count = 0;
for (int L = 1; L * (L + 1) < 2 * N; L++)
{
double a = (1.0 * N-(L * (L + 1)) / 2) / (L + 1);
if (a-(int)a == 0.0)
count++;
}
return count;
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int N;
cin >> N;
cout << 2+2*countConsecutive(N) << endl;
return 0;
} |
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define LL long long
#define DD double
using namespace std;
const int pri[10] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29};
int main() {
int n;
scanf("%d", &n);
LL ans = 1;
for (int i = 0; i < 10 && pri[i] <= n; i++) {
int xans = pri[i];
while (xans * pri[i] <= n) xans *= pri[i];
ans *= xans;
}
printf("%lld", ans + 1);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main()
{
int a;
cin>>a;
a=a*1.08;
// cout<<a<<" ";
if(a<206)
cout<<"Yay!";
else if(a==206)
cout<<"so-so";
else
cout<<":(";
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve() {
int n;
cin>>n;
ll a, sum=0, high=0, ans=0;
for(int i=0; i<n; i++) {
cin>>a;
sum+=a;
ans+=sum;
high=max(high, a);
cout<<ans+(i+1)*high<<endl;
}
return;
}
int main() {
#ifdef bipinpathak
(void)!freopen("input.txt", "r", stdin);
(void)!freopen("output.txt", "w", stdout);
#endif
ios::sync_with_stdio(false);
cin.tie(NULL);
auto start=clock();
int t = 1;
//cin>>t;
for(int i=0; i<t; i++) {
//cout<<"Case #"<<i+1<<": ";
solve();
}
double used= (double) (clock()-start);
used=(used*1000)/CLOCKS_PER_SEC;
cerr<<fixed<<setprecision(2)<<used<<" ms"<<endl;
return 0;
}
| // KNOW NOTHING!
#include <bits/stdc++.h>
#define ll long long int
#define F(i,j,k,in) for(int i=j;i<k;i+=in)
#define DF(i,j,k,in) for(int i=j;i>=k;i-=in)
#define feach(it,l) for (auto it = l.begin(); it != l.end(); ++it)
#define fall(a) a.begin(),a.end()
#define sz(x) (int)x.size()
#define szs(x) (int)x.length()
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define eq equal_range
#define fs first
#define ss second
#define ins insert
#define mkp make_pair
#define endl "\n"
using namespace std;
typedef vector<ll> vll;
typedef vector<int> vin;
typedef vector<char> vch;
typedef vector<string> vst;
typedef set<ll> sll;
typedef set<int> sint;
typedef set<char> sch;
typedef set<string> sst;
typedef queue<ll> qll;
typedef queue<int> qin;
typedef deque<ll> dqll;
typedef deque<int> dqint;
typedef priority_queue<ll> pqll;
typedef priority_queue<int> pqin;
typedef map<ll,ll> mpll;
typedef map<int,int> mpin;
typedef pair<ll,ll> pll;
typedef pair<int,int> pin;
const ll MOD=1000000007;
const long double PI=3.1415926535897932384626433832795;
ll pwr(ll b,ll p){ll res=1;while(p){if(p&1) {res*=b; p--;}else{b*=b; p>>=1;}}return res;}
ll mpwr(ll b,ll p){ll res=1;while(p){if(p&1) {res=(res*b)%MOD; p--;}else{b=(b*b)%MOD; p>>=1;}}return res;}
int msb (int n) {return 31-__builtin_clz(n);}
ll msbl (ll n) {return 63-__builtin_clzll(n);}
int lsb (int n) {return __builtin_ctz(n);}
ll lsbl (ll n) {return __builtin_ctzll(n);}
int setbit (int n) {return __builtin_popcount(n);}
ll setbitl (ll n) {return __builtin_popcountll(n);}
int main()
{
/*
freopen ("input.txt","r","stdin");
freopen ("output.txt","w","stdout");
*/
ios_base::sync_with_stdio(false) , cin.tie(NULL) , cout.tie(NULL);
ll n; cin>>n;
vll a (n);
F (i,0,n,1) cin>>a[i];
vll pr (n); pr[0]=a[0];
vll pri (n);
F (i,1,n,1) pr[i]=pr[i-1]+a[i];
pri[0]=pr[0];
F (i,1,n,1) pri[i]=pri[i-1]+pr[i];
ll mx = a[0];
F (i,0,n,1) {
mx = max (mx, a[i]);
cout<<mx*(i+1)+pri[i]<<endl;
}
return 0;
}
/* What we know is a drop , but what we don't know is an ocean !*/ |
#include<bits/stdc++.h>
using namespace std;
#define ints(...) int __VA_ARGS__; vin(__VA_ARGS__)
#define dbls(...) double __VA_ARGS__; vin(__VA_ARGS__)
#define ulls(...) unsigned long long __VA_ARGS__; vin(__VA_ARGS__)
#define strs(...) string __VA_ARGS__; vin(__VA_ARGS__)
#define vifin(x, y) vi x(y); fin(x, y)
#define vvis(x, y, z, p) vvi x(y, vi(z, p))
#define deb cout << "<deb> DEB" << endl
#define debi(x) cout << "<deb> " << #x << " == " << x << endl
#define rep(x, y) for(int x = 0; x < y; x++)
#define reps(x, y, z) for(int x = y; x < z; x++)
#define rev(x, y) for(int x = y; x >= 0; x--)
#define revs(x, y, z) for(int x = y; x >= z; x--)
#define syz(x) (int)x.size()
#define euc(x, y) (sqrt((x*x)+(y*y)))
#define all(x) x.begin(), x.end()
#define will(x) do{cout << x << endl; return 0;}while(0)
using ll = long long;
using ull = unsigned long long;
using str = string;
using vi = vector<int>;
using vc = vector<char>;
using vs = vector<str>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pi = pair<int, int>;
template<class T> using v = vector<T>;
template<class T> using vv = vector<vector<T>>;
template<class T> using pq = priority_queue<T>;
void vin(){return;}
template<class T>void fin(T& __x,int __y){rep(i, __y){cin >>__x[i];};}
void lout(){cout<<"=============================================="<<endl;}
template<class T>void fout(T& __x){cout<<"<deb> ";for(auto __y:__x){cout<< __y<<' ';}cout<<endl;}
template<class T>void fout(T& __x,int __y){cout<<"<deb> ";rep(i,__y)cout <<__x[i]<<' ';cout<<endl;}
template<class T>void ffout(T __x){lout();for(auto __y:__x){for(auto __z:__y){cout<<__z<<' ';}cout<<endl;}}
template<class T>void ffout(T __x,int __y,int __z){lout();rep(i,__y){rep(j,__z)cout<<__x[i][j]<<' ';cout<<endl;}lout();}
template<class C,class ...T>inline void vin(C& __f,T&... __x){cin >> __f;vin(__x...);}
template<class T>inline void chmax(T &a,const T &b){if(a<b)a=b;}
template<class T>inline void chmin(T &a,const T &b){if(b<a)a=b;}
constexpr ull LINF = 4500000000000000000;
constexpr int INF = 2000000000;
constexpr int four = 10007 ;
constexpr int five = 100007 ;
constexpr int six = 1000007 ;
constexpr int seven = 10000007 ;
constexpr int eight = 100000007 ;
constexpr int nine = 1000000007;
signed main() {
dbls(a, b, w);
w *= 1000.0;
int min = INF, max = 0;
double ans;
rep(i, eight) {
ans = w / i;
if(a <= ans&&b >= ans) {
chmax(max, i);
chmin(min, i);
}
}
if(min == INF) will("UNSATISFIABLE");
cout << min << ' ' << max << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(NULL), cout.tie(NULL);
int a, b, w;
cin >> a >> b >> w;
w *= 1000;
int minn = (w + b - 1) / b, maxx = w / a;
if (minn > maxx)
cout << "UNSATISFIABLE\n";
else
cout << minn << " " << maxx << "\n";
return 0;
}
|
#include <bits/stdc++.h>
#define ll long long
ll md = 1000000007;
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define pb push_back
#define g(v, i, j) get<i>(v[j])
#define vi vector<int>
#define vll vector<ll>
#define srt(v) sort(v.begin(), v.end())
#define rsrt(v) sort(v.begin(), v.end(), greater<int>())
#define fi(i, a, b) for (int i = a; i < b; i++)
#define fll(i, a, b) for (ll i = a; i < b; i++)
using namespace std;
//using namespace std::chrono;
template <typename T>
T pw(T a, T b)
{
T c = 1, m = a;
while (b)
{
if (b & 1)
c = (c * m);
m = (m * m), b /= 2;
}
return c;
}
template <typename T>
T ceel(T a, T b)
{
if (a % b == 0)
return a / b;
else
return a / b + 1;
}
template <typename T>
T my_log(T n, T b)
{
T i = 1, ans = 0;
while (1)
{
if (i > n)
{
ans--;
break;
}
if (i == n)
break;
i *= b, ans++;
}
return ans;
}
template <typename T>
T gcd(T a, T b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
template <typename T>
T mysqt(T a)
{
T ans = 1;
while (ans * ans <= a)
ans++;
ans--;
return ans;
}
ll pwmd(ll a, ll b)
{
ll c = 1, m = a;
while (b)
{
if (b & 1)
c = (c * m) % md;
m = (m * m) % md;
b /= 2;
}
return c;
}
ll modinv(ll n)
{
return pwmd(n, md - 2);
}
ll inverse(ll i)
{
if (i == 1)
return 1;
return (md - ((md / i) * inverse(md % i)) % md + md) % md;
}
bool sortbysec(const pair<ll, ll> &a,
const pair<ll, ll> &b)
{
return (a.second < b.second);
}
/* auto start = high_resolution_clock::now();
auto stop = high_resolution_clock::now();
auto duration = duration_cast<microseconds>(stop - start);
cerr << "Time taken: "
<< duration.count()<< "ms" <<"\n";*/
vector<char> capl = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
vector<char> sml = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
template <typename T>
string conv(T a)
{
string b;
T e = 2;
T c = my_log(a, e);
c++, b = '1';
for (T i = 0; i < c - 1; i++)
{
T k = a >> (c - 2 - i);
if (k & 1)
b += '1';
else
b += '0';
}
if (a == 0)
return "0";
return b;
}
int main()
{
fast;
ll n, m, q, l, r;
cin >> n >> m >> q;
ll w[n], val[n], x[m];
fll(i, 0, n) cin >> w[i] >> val[i];
fll(i, 0, m) cin >> x[i];
while (q--){
vector<pair<int, int>> vp;
fll(i, 0, n) vp.pb({w[i], val[i]});
vll vis(n);
vll xs;
cin >> l >> r;
l--, r--;
fll(i, 0, m){
if (i >= l && i <= r) continue;
xs.pb(x[i]);
}
srt(xs);
ll ans = 0;
fll(i, 0, xs.size()){
ll ind = -1, mx = 0;
fll(j, 0, n){
if (vis[j]) continue;
if (vp[j].first <= xs[i]){
// cout << vp[j].second << "a\n";
if (vp[j].second > mx) mx = vp[j].second, ind = j;
}
}
if (ind == -1) continue;
ans += mx, vis[ind] = 1;
}
cout << ans << "\n";
}
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define MAXN 1000005
#define INF (ll)1e18
#define mod 1000000007
//#define mod 998244353
#define endl '\n'
ll cc=0;
void boost()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
ll inv(ll a, ll m)
{
ll m0 = m;
ll y = 0, x = 1;
if (m == 1)
return 0;
while (a > 1) {
// q is quotient
ll q = a / m;
ll t = m;
// m is remainder now, process same as
// Euclid's algo
m = a % m, a = t;
t = y;
// Update y and x
y = x - q * y;
x = t;
}
// Make x positive
if (x < 0)
x += m0;
return x;
}
int main()
{
boost();
ll i,j,k,n,t,c=0,l,r,d=0;
ll ans,h,z,m,u,q,mm,w,mx,x,y;
ld f;
cin>>t;
while(t--)
{
cin>>n>>z>>k;
y=__gcd(n,z);
y=__gcd(y,k);
n=n/y;
z=z/y;
k=k/y;
ans=-1;
l=n-z;
r=__gcd(n,k);
if(r!=1)
{
cout<<ans<<endl;
}
else
{
r=inv(k,n);
ans=r*l;
ans=ans%n;
cout<<ans<<endl;
}
}
return 0;
}
|
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define FI(n) FastIO::read(n)
#define FO(n) FastIO::write(n)
#define ull unsigned long long
#define mst(a,b) memset(a,b,sizeof(a))
#define foR(i,k,j) for(int i=(k);i>=(j);i--)
#define For(i,k,j) for(int i=(k);i<=(j);i++)
#define Foe(i,u) for(int i=lst[u],v=e[i].v;i;i=e[i].nxt,v=e[i].v)
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define Fin(s) freopen(s,"r",stdin)
#define Fout(s) freopen(s,"w",stdout)
#define file(s) Fin(s".in"),Fout(s".out")
#define INF ((1<<30)-1)
#define int long long
const int P=998244353; //
using namespace std;
template<typename T>inline void ckmax(T &a,T b) {(a<b)&&(a=b);}
template<typename T>inline void ckmin(T &a,T b) {(a>b)&&(a=b);}
inline int mul(int a,int b) {return 1ull*a*b%P;}
inline int add(int a,int b) {return a+b>=P?a+b-P:a+b;}
inline int sub(int a,int b) {return a-b>=0?a-b:a-b+P;}
inline void mulmod(int &a,int b) {a=mul(a, b);}
inline void addmod(int &a,int b) {((a+=b)>=P)&&(a-=P);}
inline void submod(int &a,int b) {((a-=b)<0)&&(a+=P);}
inline int ksm(int a,int b) {int ans=1; for(;b;b>>=1) {if(b&1) ans=1ll*ans*a%P;a=1ll*a*a%P;}return ans;}
inline void fprint(const int &x,char c=' ') {fprintf(stderr,"%lld%c",x,c);}
inline void fprint(const pii &x,char c='\n') {fprintf(stderr,"%lld %lld%c",x.first,x.second,c);}
inline void fprint(const int *f,const int &n,char c='\n') {for(int i=1;i<=n;i++) fprint(f[i]); fprintf(stderr,"%c",c);}
inline void fprint(const vector<int> &f,char c='\n') {for(int i=0;i<(int)f.size();i++) fprint(f[i]); fprintf(stderr,"%c",c);}
inline int inv(int a) {return ksm(a,P-2);}
namespace FastIO {
const int SIZE=1<<16; char buf[SIZE],obuf[SIZE],str[64]; int bi=SIZE,bn=SIZE,opt;
int read(char *s) {
while (bn) {for (;bi<bn&&buf[bi]<=' ';bi++);if (bi<bn) break; bn=fread(buf,1,SIZE,stdin),bi=0;}
int sn=0;while (bn) {for (;bi<bn&&buf[bi]>' ';bi++) s[sn++]=buf[bi];if (bi<bn) break; bn=fread(buf,1,SIZE,stdin),bi=0;}s[sn]=0;return sn;
}
bool read(int& x) {if(x)x=0;int bf=0,n=read(str); if(!n) return 0; int i=0; if (str[i]=='-') bf=1,i=1; for(x=0;i<n;i++) x=x*10+str[i]-'0'; if(bf) x=-x; return 1;}
void write(int x) {
if(!x) obuf[opt++]='0'; else {if(x<0) obuf[opt++]='-',x=-x;int sn=0; while(x)str[sn++]=x%10+'0',x/=10;for (int i=sn-1;i>=0;i--) obuf[opt++]=str[i];}
if (opt>=(SIZE>>1)){fwrite(obuf,1,opt,stdout); opt=0;}
}
void write(char x) {obuf[opt++]=x;if (opt>=(SIZE>>1)){fwrite(obuf,1,opt,stdout); opt=0;}}
void Fflush() {if (opt) fwrite(obuf,1,opt,stdout); opt=0;}
};
inline int read() {int x; FI(x); return x;}
const int MN=6e3+5;
int a[MN],f[MN][MN],n,K;
signed main() {
#ifndef ONLINE_JUDGE
freopen("pro.in","r",stdin);
freopen("pro.out","w",stdout);
#endif
n=read(),K=read();
For(i,0,MN-5) f[0][i]=1;
For(i,1,n-K) {
// f[i][0]=1;
For(j,1,i) {
f[i][j]=add(f[i][j-1],f[i-j][min(2*j,i-j)]);
}
// For(j,1,K) cerr<<f[i][j]<<' ';
// cerr<<endl;
}
printf("%lld\n",f[n-K][min(K,n-K)]);
return FastIO::Fflush(),0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int, int>
#define mk make_pair
const int N = 1e6 + 10;
const int mod = 998244353;
int read()
{
int x = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9')
{
if (c == '-')
f = -1;
c = getchar();
}
while (c >= '0' && c <= '9')
x = (x << 1) + (x << 3) + c - '0', c = getchar();
return x * f;
}
int main()
{
int n = read(), k = read();
vector<vector<int>> dp(n + 1, vector<int>(n + 1));
for (int i = 1; i <= n; i++)
{
dp[i][i] = 1;
for (int j = i - 1; j >= 1; j--)
{
if (j)
dp[i][j] = (dp[i][j] + dp[i - 1][j - 1]) % mod;
if (2 * j <= i)
dp[i][j] = (dp[i][j] + dp[i][2 * j]) % mod;
}
}
cout << dp[n][k] << endl;
} |
#include<iostream>
#include<vector>
#include<map>
using namespace std;
int _C3(int n, int k)
{
if(k > n)
return 0;
else if(n==2 && k==1)
return 2;
else
return 1;
}
int C(int n, int k)
{
int ans = 1;
while(n > 0 || k > 0)
{
ans = (ans*_C3(n%3, k%3))%3;
n /= 3;
k /= 3;
}
return ans;
}
int main()
{
string x = "RWB";
map<char,int> conv;
for(int i = 0; i < 3; i++)
conv[x[i]] = i;
/***
R W B
R R B W
W B W R
B W R B
***/
vector<vector<char>> huh = {{'R','B','W'},{'B','W','R'},{'W','R','B'}};
int n; cin >> n;
string orig; cin >> orig;
string s;
if(n&1)
s = orig;
else
{
s = "";
n--;
for(int i = 0; i < n; i++)
s += huh[conv[orig[i]]][conv[orig[i+1]]];
}
int ans = 0;
for(int i = 0; i <= n; i++)
ans += C(n-1, i)*conv[s[i]];
ans %= 3;
cout<<x[ans]<<endl;
return 0;
} | #pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2")
#include <functional>
template <typename T>
inline void hash_combine(std::size_t &seed, const T &val) {
seed ^= std::hash<T>()(val) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}
template <typename T> inline void hash_val(std::size_t &seed, const T &val) {
hash_combine(seed, val);
}
template <typename T, typename... Types>
inline void hash_val(std::size_t &seed, const T &val, const Types &... args) {
hash_combine(seed, val);
hash_val(seed, args...);
}
template <typename... Types>
inline std::size_t hash_val(const Types &... args) {
std::size_t seed = 0;
hash_val(seed, args...);
return seed;
}
struct pair_hash {
template <class T1, class T2>
std::size_t operator()(const std::pair<T1, T2> &p) const {
return hash_val(p.first, p.second);
}
};
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#define INF 0x3f3f3f3f
#define mod 1000000007
#define G 3
#define MAX_N 300005
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
typedef complex<double> E;
ll pow_mod(ll x,ll n){
ll ret=1;
while(n>0){
if(n&1)ret=ret*x%mod;
x=x*x%mod;
n>>=1;
}
return ret;
}
ll n,p;
int main(){
cin>>n>>p;
cout<<(p-1)*pow_mod(p-2,n-1)%mod;
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll MAX =1000000000000000000;
ll mod= 1000000000;
long double pi=3.141592653589793238;
void pls()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
#endif
}
ll n,m,k;
vector<pair<ll,ll>> p,temp;
ll recursion(int i,vector<int> &visi){
if(i==k)
{
ll tot=0;
for(i=0;i<p.size();i++){
if(visi[p[i].first] && visi[p[i].second])
tot++;
}
return tot;
}
visi[temp[i].first]+=1;
ll val=recursion(i+1,visi);
visi[temp[i].first]-=1;
visi[temp[i].second]+=1;
ll val1=recursion(i+1,visi);
visi[temp[i].second]-=1;
return max(val,val1);
}
void solve()
{
cin>>n>>m;
for(int i=0;i<m;i++){
ll x,y; cin>>x>>y;
p.push_back({x,y});
}
cin>>k;
for(int i=0;i<k;i++){
ll x,y; cin>>x>>y;
temp.push_back({x,y});
}
vector<int> visi(n+1,0);
cout<<recursion(0,visi)<<endl;
}
int main(){pls(); solve(); return 0;}
/*
Mostly wrong answer form base case or overflow or runtime
Debug--> check overflow---> check varible name---> check logic implementation----> check logic
*/
| #include<bits/stdc++.h>
using namespace std;
int ara[262150],n,two[23],tra[23][23],dp[262150],sz,bits[23],tz;
int on(int val,int pos)
{
return (val|two[pos]);
}
bool ck(int val,int pos)
{
return (bool)(val&two[pos]);
}
int off(int val,int pos)
{
return (val^two[pos]);
}
void subsets(int mask,int idx)
{
if(idx==n){ ara[mask]=1; }
else
{
subsets(mask,idx+1);
int flg=1;
for(int lp=0;lp<=n-1;lp++)
{
if(ck(mask,lp)==true)
{
if(tra[idx][lp]==0){ flg=0; break; }
}
}
if(flg==1)
{
int t; t=on(mask,idx); subsets(t,idx+1);
}
}
}
void work(int mask,int start,int idx)
{
if(idx==tz)
{
int remain;
if(mask!=0){ remain=start^mask; dp[start]=min(dp[start],dp[mask]+dp[remain]); }
}
else
{
work(mask,start,idx+1);
int q,r,s; q=bits[idx];
r=off(mask,q);
work(r,start,idx+1);
}
}
int main()
{
two[0]=1;
for(int lp=1;lp<=20;lp++)
{
two[lp]=two[lp-1]*2;
}
int m,i,j,k,a,b,c,fn,mask,x,y,z;
scanf("%d %d",&n,&m);
for(i=1;i<=m;i++)
{
scanf("%d %d",&a,&b); tra[a-1][b-1]=1; tra[b-1][a-1]=1;
}
subsets(0,0); fn=two[n]-1;
for(mask=1;mask<=fn;mask++)
{
if(ara[mask]==1){ dp[mask]=1; }
else
{
tz=0; dp[mask]=99999;
for(i=0;i<=n-1;i++)
{
if(ck(mask,i)==true){ bits[tz]=i; tz++; }
}
work(mask,mask,0);
}
}
printf("%d\n",dp[fn]);
return 0;
}
|
// #define ONLINE_JUDGE
// _
// (_)
// _ __ ___ __ _ _ ___ _ __ _ __ ___
//| '_ ` _ \ / _` | |/ _ \| '__| '__/ _ \
//| | | | | | (_| | | (_) | | | | | (_) |
//|_| |_| |_|\__,_| |\___/|_| |_| \___/
// _/ |
// |__/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef tree<
pll,//
null_type,
less<pll>,//
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
#define majorro cout.precision(20); ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define forn(i, n) for(ll (i) = 0; (i) < (n); ++(i))
#define fornm(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define rfornm(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define readvec(vector, n) {ll temp_vec_val;forn(inc, n){cin >> temp_vec_val;vector.push_back(temp_vec_val);}}
#define printvec(vector, delimeter) {ll length_of_vector=vector.size(); forn(elementvec, length_of_vector){cout << vector[elementvec] << delimeter;}}
#define all(vector) (vector).begin(), (vector).end()
#define rall(vector) (vector).rbegin(), (vector).rend()
#define endl "\n"
#define sz(something) (ll)something.size()
struct pair_hash
{
template <class T1, class T2>
size_t operator() (const pair<T1, T2>& pair) const
{
return hash<T1>()(pair.first) ^ hash<T2>()(pair.second);
}
};
const ld EPS = 1e-8;
const ll MOD = 1e9+7;
// const ll MOD = 998244353;
const ll INF = 1e18;
const ld pi = 2.0*acos(0.0);
ll n, m, k, p, q, t, sum=0, cnt=0;
ll mx = -INF;
ll mn = INF;
bool flag = 0;
vll v;
string s = "", s1, s2;
char c;
void solve()
{
cin >> n >> k;
vector<pll> v;
forn(i,n)
{
cin >> p >> q;
v.pb({p,q});
}
sort(all(v));
p = 0;
q = 0;
while(k)
{
p += k;
k = 0;
while(q<n&&v[q].first<=p) k += v[q++].second;
}
cout << p;
}
int main()
{
#if defined ACMP
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#elif !defined ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
majorro
solve();
return 0;
} | #include <bits/stdc++.h>
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef double ld;
typedef unsigned long long ull;
typedef long double lld;
#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x <<" "; _print(x); cerr << endl;
#else
#define debug(x)
#endif
void _print(ll t) {cerr << t;}
void _print(int t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(lld t) {cerr << t;}
void _print(double t) {cerr << t;}
void _print(ull t) {cerr << t;}
template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
//-------------------------------------------------------------------------------
const ll N = 2e5+7;
vll g[N];
ll st[N],en[N];
vll d[N];
ll timer=0;
void dfs(ll v,ll depth=0){
st[v] = timer++;
d[depth].pb(st[v]);
for(auto x:g[v]){
dfs(x, depth+1);
}
en[v] = timer;
}
void solve(){
int n;cin>>n;
for(int i=2;i<=n;++i){
int x;cin>>x;
g[x].pb(i);
}
dfs(1);
int q;
cin>>q;
while(q--){
int u,D;cin>>u>>D;
ll r = en[u], l= st[u];
ll ans = lower_bound(d[D].begin(),d[D].end(),r) - lower_bound(d[D].begin(),d[D].end(),l);
cout<<ans<<'\n';
}
}
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("E:\\input-output\\input.txt","r",stdin);
freopen("E:\\input-output\\output.txt","w",stdout);
freopen("E:\\input-output\\Error.txt", "w", stderr);
#endif
int t=1;
while(t--){
solve();
}
}
|
#ifndef LOCAL
#include <bits/stdc++.h>
using namespace std;
#define debug(...) 42
#else
#include "Debug.hpp"
#endif
class Task {
public:
void Perform() {
Read();
Solve();
}
private:
int n;
vector<pair<int, int>> intervals;
void Read() {
cin >> n;
intervals.resize(n);
for (auto &[l, r] : intervals) {
int typ;
cin >> typ >> l >> r;
l *= 2, r *= 2;
if (typ == 2) {
--r;
} else if (typ == 3) {
++l;
} else if (typ == 4) {
++l, --r;
}
}
}
void Solve() {
int res = 0;
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n; ++j) {
int intersect = min(intervals[i].second, intervals[j].second) - max(intervals[i].first, intervals[j].first) + 1;
res += intersect > 0;
}
}
cout << res << '\n';
}
};
int main() {
ios_base::sync_with_stdio(false), cin.tie(nullptr);
Task t;
t.Perform();
return 0;
} | /* BABA JAGAAAAAA */
#include<bits/stdc++.h>
#define pb push_back
#define un unordered_map
#define us unordered_set
#define ll long long
#define PI 3.1415926535897932384626
#define fast ios:: sync_with_stdio(false);cin.tie(NULL)
#define l long
using namespace std;
const int mod= 1e9+7;
const int inf=1e9+3;
/*
vector<int>parent;
vector<int>rank;
int find(int x)
{
if(parent[x]==x)
return x;
return parent[x]= find(parent[x]); // path compression// O(log n)
}
void merge(int a, int b)
{
int x1= find(a);
int x2= find(b);
if(rank[x1]<rank[x2])
parent[x1]=x2;
else if(rank[x2]<rank[x1]) //(lon n)
parent[x2]=x1; // union by rank//
else
{
parent[x1]=x2;
rank[x2]++;
}
}
ll pri[10000002]; // for precomputing
ll primes[10000002];
void seive()
{
primes[0]=primes[1]=-1;
for(ll i=2; i<10000002; i++)
{
if(primes[i]==0)
{
for(ll j=i*i; j<10000002; j+=i)
{
primes[j]=-1;
}
}
}
}
*/
inline void solve()
{
ll n;
cin>>n;
vector<ll>a,b;
for(ll i=0; i<n; i++)
{
ll x;
cin>>x;
a.pb(x);
}
for(ll i=0; i<n; i++)
{
ll x;
cin>>x;
b.pb(x);
}
sort(a.begin(), a.end());
sort(b.begin(), b.end());
un<ll,ll>mp;
for( ll i=0; i<n; i++)
{
ll mini= min(a[i],b[i]);
ll maxi= max(a[i],b[i]);
for(ll j=mini; j<=maxi; j++)
{
mp[j]++;
}
}
ll count=0;
for(auto it=mp.begin(); it!=mp.end(); it++)
{
if(it->second==n)
count++;
}
cout<<count;
return;
}
int main()
{
fast;
int t=1;
//cin>>t;
// seive();
while(t--)
{
solve();
cout<<"\n";
}
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define reps(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define ALL(obj) begin(obj), end(obj)
#define cinv(a) rep(i,(int)a.size()) cin>>a[i]
#define pb push_back
#define eb emplace_back
typedef pair<int, int> Pi;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
template<typename T>
bool chmax(T& a, const T& b){if(a < b){a=b;return true;}return false;}
template<typename T>
bool chmin(T& a, const T& b){if(a > b){a=b;return true;}return false;}
int main()
{
int n; cin >> n;
vl a(n), b(n);
rep(i, n) scanf("%lld", &a[i]);
rep(i, n) scanf("%lld", &b[i]);
reps(i, 1, n)
a[i] = max(a[i-1], a[i]);
ll ans;
rep(i, n)
{
if (i == 0)
ans = a[0] * b[0];
else
ans = max(ans, a[i] * b[i]);
printf("%lld\n", ans);
}
}
| #include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define rep(i,n) repi(i,0,n)
#define repi(i,a,n) for(ll i = a;i < (ll)n;++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SHOW(str,val) cout<<(str)<<" : "<<(val)<<endl;
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
// using P = pair<int, int>;
void YN(bool a) { cout << (a ? "Yes" : "No"); }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
void solve()
{
ll n;
cin >> n;
ll thr = 3;
ll cnt_3 = 0;
for(thr; thr <= n; thr *= 3)
{
cnt_3++;
ll cnt_5 = 0;
for(ll fiv = 5; thr + fiv <= n; fiv *= 5)
{
cnt_5++;
if (thr + fiv == n)
{
cout << cnt_3 << " " << cnt_5 << endl;
return;
}
}
}
cout << -1;
}
int main()
{
fastio;
solve();
return 0;
} |
#include<iostream>
#include<algorithm>
using namespace std;
const int N = 410, offset = 200;
int a[N];
int main(){
int n;
cin >> n;
while(n--){
int x;
cin >> x;
a[x + offset]++;
}
long long ans = 0;
for(int i = 0; i <= 400; i++){
for(int j = i; j <= 400; j++){
int c1 = a[i], c2 = a[j];
if(c1 && c2) ans += (i - j) * (i - j) * c1 * c2;
}
}
printf("%lld", ans);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
void DAU(const string &task = "") {
if (!task.empty())
freopen((task + ".in").c_str(), "r", stdin),
freopen((task + ".out").c_str(), "w", stdout);
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
void PLEC() {
exit(0);
}
#define int long long
int n, s1, s2, x, res;
signed main() {
DAU();
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> x;
s1 += x * x;
s2 += x;
}
res = n * s1 - s2 * s2;
cout << res;
PLEC();
}
|
#include <bits/stdc++.h>
using namespace std;
char a[10];
int st[10];
vector<int> v;
vector<int> m;
int ans[5];
int len ;
int le;
int out;
void dfs(int x)
{
if(x == 4){
int cnt =0 ;
for(int i = 0 ; i < le; i++){
for(int j = 0; j < 4 ; j++){
if( ans[j] == m[i]){
cnt++;
break;
}
}
}
if(cnt == le){
out++;
}
}
else{
for(int i =0 ; i < len ; i++){
if( ans[x] == -1){
ans[x] = v[i];
dfs(x+1);
ans[x] = -1;
}
}
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
fill(ans,ans+5,-1);
int cnt_x=0,cnt_o=0,cnt_q= 0;
for(int i =0 ; i < 10 ; i++){
cin >> a[i];
if( a[i] == 'o' ){
cnt_o++;
v.push_back(i);
m.push_back(i);
}
else if(a[i]=='x'){
cnt_x++;
}
else{
cnt_q++;
v.push_back(i);
}
}
len = v.size();
le = m.size();
if( cnt_o > 4 ){
cout << 0 << endl;
}
else{
dfs(0);
cout << out << endl;
}
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
int64_t kai(int n){
if(n==0)return 1;
return n*kai(n-1);
}
int main(){
string S;
cin>>S;
int maru=0;
int batsu=0;
for(int i=0;i<10;i++) {
if(S.at(i)=='o') maru++;
if(S.at(i)=='x') batsu++;
}
if(maru>4) {cout<<0<<endl;return 0;}
int ans=0;
for(int i=0;i<=maru;i++){
ans+=pow(-1,i)*pow(10-batsu-i,4)*kai(maru)/(kai(i)*kai(maru-i));
}
cout<<ans<<endl;
return 0;
} |
/*
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
//*/
#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
#define int ll
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
void YES(bool t=true) {cout<<(t?"YES":"NO")<<endl;}
void Yes(bool t=true) {cout<<(t?"Yes":"No")<<endl;}
void yes(bool t=true) {cout<<(t?"yes":"no")<<endl;}
void NO(bool t=true) {cout<<(t?"NO":"YES")<<endl;}
void No(bool t=true) {cout<<(t?"No":"Yes")<<endl;}
void no(bool t=true) {cout<<(t?"no":"yes")<<endl;}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
// int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {0, 1, 0, -1}, dy = {-1, 0, 1, 0};
// vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
struct Setup_io {
Setup_io() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cout << fixed << setprecision(25);
}
} setup_io;
const ll MOD = 1000000007;
// const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'
signed main() {
int n;
cin >> n;
vl a(n), b(n), p(n);
rep (i, n) {
cin >> a[i];
}
rep (i, n) cin >> b[i];
vi q(n);
rep (i, n) {
cin >> p[i];
p[i]--;
q[p[i]] = i;
}
vector<pii> ai(n);
rep (i, n) {
ai[i] = pii(a[i], i);
}
sort(all(ai));
vector<pii> op;
rep (idx, n) {
int i = ai[idx].second;
if (p[i] == i) continue;
if (b[p[i]] >= a[i]) {
cout << -1 << endl;
return 0;
}
int j = q[i];
if (b[p[j]] >= a[j]) {
cout << -1 << endl;
return 0;
}
op.push_back(pii(i, j));
p[j] = p[i];
p[i] = i;
q[p[i]] = i;
q[p[j]] = j;
}
cout << op.size() << endl;
rep (i, op.size()) {
cout << op[i].first + 1 << " " << op[i].second + 1 << endl;
}
} | #include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define FI(n) FastIO::read(n)
#define FO(n) FastIO::write(n)
#define ull unsigned long long
#define mst(a,b) memset(a,b,sizeof(a))
#define foR(i,k,j) for(int i=(k);i>=(j);i--)
#define For(i,k,j) for(int i=(k);i<=(j);i++)
#define Foe(i,u) for(int i=lst[u],v=e[i].v;i;i=e[i].nxt,v=e[i].v)
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define Fin(s) freopen(s,"r",stdin)
#define Fout(s) freopen(s,"w",stdout)
#define file(s) Fin(s".in"),Fout(s".out")
#define INF ((1<<30)-1)
#define int long long
int P=1e9+7; //
using namespace std;
template<typename T>inline void ckmax(T &a,T b) {(a<b)&&(a=b);}
template<typename T>inline void ckmin(T &a,T b) {(a>b)&&(a=b);}
inline int mul(int a,int b) {return 1ull*a*b%P;}
inline int add(int a,int b) {return a+b>=P?a+b-P:a+b;}
inline int sub(int a,int b) {return a-b>=0?a-b:a-b+P;}
inline void mulmod(int &a,int b) {a=mul(a, b);}
inline void addmod(int &a,int b) {((a+=b)>=P)&&(a-=P);}
inline void submod(int &a,int b) {((a-=b)<0)&&(a+=P);}
inline int ksm(int a,int b) {int ans=1; for(;b;b>>=1) {if(b&1) ans=1ll*ans*a%P;a=1ll*a*a%P;}return ans;}
inline void fprint(const int &x,char c=' ') {fprintf(stderr,"%d%c",x,c);}
inline void fprint(const pii &x,char c='\n') {fprintf(stderr,"%d %d%c",x.first,x.second,c);}
inline void fprint(const int *f,const int &n,char c='\n') {for(int i=1;i<=n;i++) fprint(f[i]); fprintf(stderr,"%c",c);}
inline void fprint(const vector<int> &f,char c='\n') {for(int i=0;i<(int)f.size();i++) fprint(f[i]); fprintf(stderr,"%c",c);}
inline int inv(int a) {return ksm(a,P-2);}
namespace FastIO {
const int SIZE=1<<16; char buf[SIZE],obuf[SIZE],str[64]; int bi=SIZE,bn=SIZE,opt;
int read(char *s) {
while (bn) {for (;bi<bn&&buf[bi]<=' ';bi++);if (bi<bn) break; bn=fread(buf,1,SIZE,stdin),bi=0;}
int sn=0;while (bn) {for (;bi<bn&&buf[bi]>' ';bi++) s[sn++]=buf[bi];if (bi<bn) break; bn=fread(buf,1,SIZE,stdin),bi=0;}s[sn]=0;return sn;
}
bool read(int& x) {if(x)x=0;int bf=0,n=read(str); if(!n) return 0; int i=0; if (str[i]=='-') bf=1,i=1; for(x=0;i<n;i++) x=x*10+str[i]-'0'; if(bf) x=-x; return 1;}
void write(int x) {
if(!x) obuf[opt++]='0'; else {if(x<0) obuf[opt++]='-',x=-x;int sn=0; while(x)str[sn++]=x%10+'0',x/=10;for (int i=sn-1;i>=0;i--) obuf[opt++]=str[i];}
if (opt>=(SIZE>>1)){fwrite(obuf,1,opt,stdout); opt=0;}
}
void write(char x) {obuf[opt++]=x;if (opt>=(SIZE>>1)){fwrite(obuf,1,opt,stdout); opt=0;}}
void Fflush() {if (opt) fwrite(obuf,1,opt,stdout); opt=0;}
};
inline int read() {int x; FI(x); return x;}
const int MN=5e5+5;
int n,a[MN],b[MN],p[MN],v[MN],vis[MN],vis2[MN],r[MN];
signed main() {
#ifndef ONLINE_JUDGE
freopen("pro.in","r",stdin);
freopen("pro.out","w",stdout);
#endif
n=read();
For(i,1,n) a[i]=read();
For(i,1,n) b[i]=read();
For(i,1,n) p[i]=read();
For(i,1,n) r[p[i]]=i;
For(i,1,n) {
v[i]=b[p[i]];
if(v[i]>=a[i]) {
if(r[i]==i) continue;
return printf("-1\n"),0;
}
}
vector<pii>ans;
For(i,1,n) {
int u=i,mnv=a[u],mnp=u;
if(vis[i]) continue;
while(!vis[u]) {
vis[u]=i; u=r[u];
if(mnv>a[u]) {
mnv=a[u],mnp=u;
}
}
u=mnp; do {
if(r[u]!=mnp) ans.pb(mkp(u,r[u]));
u=r[u];
} while(u!=mnp);
}
printf("%d\n",(int)ans.size());
for(auto it:ans) {
printf("%d %d\n",it.first,it.second);
}
return FastIO::Fflush(),0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 10007;
int main() {
ll n;
cin >> n;
string s,t;
cin >> s >> t;
vector<ll>ss(n),tt(n);
for(ll i=0;i<n;i++){
ss[i]=s[i]-'0';
tt[i]=t[i]-'0';
}
ll ans=0;
ll j=0;
for(ll i=0;i<n;i++){
if(ss[i]!=tt[i]){
j=max(j,i+1);
while((j<n)&&ss[j]!=1){
j++;
}
if(j==n)break;
ans+=j-i;
ss[i]=(ss[i]+1)%2;
ss[j]=(ss[j]+1)%2;
}
}
bool ok=false;
for(ll i=0;i<n;i++){
if(ss[i]!=tt[i]){
ok=true;
}
}
if(ok){
cout << -1 << endl;
}else{
cout << ans << endl;
}
} | #include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=500005;
int n,S[N],T[N],ans,tot,st[N];
char s[N],t[N];
queue<int>q;
signed main()
{
scanf("%lld%s%s",&n,s+1,t+1);
for(int i=1;i<=n;i++)S[i]=(s[i]^48),T[i]=(t[i]^48);
for(int i=1;i<=n;i++)if(S[i])q.push(i);
for(int i=1;i<=n;i++){
if(!T[i])continue;
while(!q.empty()){
if(q.front()<i||tot&1){
st[++tot]=q.front();q.pop();
}else break;
}if(q.empty()){puts("-1");return 0;}
ans+=q.front()-i;q.pop();
}while(!q.empty())st[++tot]=q.front(),q.pop();
if(tot&1){puts("-1");return 0;}
for(int i=1;i<tot;i+=2)ans+=st[i+1]-st[i];
cout<<ans;
return 0;
} |
#include <bits/stdc++.h>
#define MOD_10_9_7 1000000007
#define MOD 998244353;
#define all(x) x.begin(), x.end()
#define endl '\n'
using namespace std;
template <typename T>
void update_max(T& a, T b) {
if (b > a) a = b;
}
template <typename T>
void update_min(T& a, T b) {
if (b < a) a = b;
}
class DisjointSet {
int size;
int components;
vector<int> parents;
public:
DisjointSet(int size) {
this->size = size;
this->parents = vector<int>(size);
for (int i = 0; i < size; i++) {
parents[i] = i;
}
components = size;
};
int find(const int index) {
vector<int> path;
int current = index;
while (current != parents[current]) {
path.push_back(current);
current = parents[current];
}
for (int parent : path) {
parents[parent] = current;
}
return current;
};
bool merge(const int index1, const int index2) {
int parent1 = find(index1), parent2 = find(index2);
if (parent1 != parent2) {
parents[parent1] = parent2;
components -= 1;
return true;
};
return false;
};
};
vector<long long> factorials;
int main() {
#ifdef LOCAL_PROJECT
freopen("input.txt", "r", stdin);
#endif
ios::sync_with_stdio(false);
cin.tie(0);
int N, K;
cin >> N >> K;
factorials = vector<long long>(N + 1, 1);
for (int i = 2; i < N + 1; i++) {
factorials[i] = (i * factorials[i - 1]) % MOD;
}
vector<vector<int>> a(N, vector<int>(N, 0));
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
cin >> a[i][j];
}
}
DisjointSet column_ds(N); //= new DisjointSet(N);
for (int i = 0; i < N; i++) {
for (int j = 0; j < i; j++) {
bool lower_than_k = true;
for (int r = 0; r < N; r++) {
if (a[r][i] + a[r][j] > K) {
lower_than_k = false;
break;
}
}
if (lower_than_k) column_ds.merge(i, j);
}
}
unordered_map<int, int> column_counter;
for (int i = 0; i < N; i++) {
column_counter[column_ds.find(i)] += 1;
}
DisjointSet row_ds(N); //= new DisjointSet(N);
for (int i = 0; i < N; i++) {
for (int j = 0; j < i; j++) {
bool lower_than_k = true;
for (int r = 0; r < N; r++) {
if (a[i][r] + a[j][r] > K) {
lower_than_k = false;
break;
}
}
if (lower_than_k) row_ds.merge(i, j);
}
}
unordered_map<int, int> row_counter;
for (int i = 0; i < N; i++) {
row_counter[row_ds.find(i)] += 1;
}
long long answer = 1;
for (auto it : column_counter) {
answer = (answer * factorials[it.second]) % MOD;
}
for (auto it : row_counter) {
answer = (answer * factorials[it.second]) % MOD;
}
cout << answer;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
#define REP(i, n, m) for(ll i=n; i<(ll)m; ++i)
#define IREP(i, n, m) for(ll i=n-1; i>=m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()
#define vprint(v) for(auto e:v){cout<<e<<" ";};cout<<endl;
#define vvprint(vv) for(auto v:vv){vprint(v)};
class UnionFind{
public:
ll size;
vll v;
UnionFind(ll n){
this->v = vll(n);
rep(i, n) this->v[i] = i;
}
ll root(ll n){
if(n!=v[n]) return v[n] = root(v[n]);
return n;
}
void unite(ll l, ll r){
ll lroot = root(l);
ll rroot = root(r);
if(lroot!=rroot) this->v[rroot] = lroot;
}
};
ll fac(ll n, ll mod=998244353){
static const ll N_MAX = 200001;
static vll fac(N_MAX+1, -1);
if(fac[0]<0){
fac[0] = 1;
rep(i, N_MAX){
fac[i+1] = fac[i] * (i+1) % mod;
}
}
return fac[n] % mod;
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
cout << setprecision(20);
ll N, K;
cin >> N >> K;
vvll a(N, vll(N, 0));
rep(i, N) rep(j, N){
cin >> a[i][j];
}
UnionFind ufx(N), ufy(N);
rep(i, N) REP(j, i+1, N){
bool okx = true, oky = true;
rep(k, N){
okx &= a[k][i]+a[k][j] <= K;
oky &= a[i][k]+a[j][k] <= K;
}
if(okx) ufx.unite(i, j);
if(oky) ufy.unite(i, j);
}
unordered_map<ll, unordered_set<ll>> mx, my;
rep(i, N){
ll rx = ufx.root(i);
ll ry = ufy.root(i);
mx[rx].insert(i);
my[ry].insert(i);
}
ll cx = 1, cy = 1;
for(auto p : mx){
cx = cx*fac(p.second.size()) % 998244353;
}
for(auto p : my){
cy = cy*fac(p.second.size()) % 998244353;
}
ll ans = cx*cy % 998244353;
cout << ans << endl;
}
|
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>
using namespace std;
const int K = 16;
const int MOD = 1e9 + 7;
int add(int a, int b) {
if (a + b < MOD) {
return a + b;
}
return a + b - MOD;
}
int sub(int a, int b) {
if (a >= b) {
return a - b;
}
return a - b + MOD;
}
int mul(int a, int b) {
return 1LL * a * b % MOD;
}
int binpow(int a, int b) {
int res = 1;
while (b) {
if (b & 1) {
res = mul(res, a);
}
a = mul(a, a);
b >>= 1;
}
return res;
}
int divv(int a, int b) {
return mul(a, binpow(b, MOD - 2));
}
int c[K + 1][K + 1];
void init() {
for (int i = 0; i <= K; i++) {
c[i][0] = 1;
c[i][i] = 1;
for (int j = 1; j < i; j++) {
c[i][j] = add(c[i - 1][j], c[i - 1][j - 1]);
}
}
}
int C(int n, int k) {
if (k < 0 || k > n) return 0;
return c[n][k];
}
vector<int> parse() {
string s;
cin >> s;
vector<int> ans;
for (auto x : s) {
if (x <= '9') {
ans.push_back(x - '0');
} else {
ans.push_back(10 + (x - 'A'));
}
}
return ans;
}
int solve(int len, int cnt) {
vector<int> tmp(cnt + 1);
for (int i = 1; i <= cnt; i++) {
tmp[i] = binpow(i, len);
for (int j = 1; j < i; j++) {
tmp[i] = sub(tmp[i], mul(tmp[j], C(i, j)));
}
}
return tmp[cnt];
}
int solve(int n, int k, vector<int> cnt) {
int alr = 0;
int s = 0;
for (int i = 0; i < 16; i++) {
alr += (cnt[i] > 0);
s += cnt[i];
}
if (alr > k) {
return 0;
}
vector<int> tmp(k + 1);
tmp[alr] = binpow(alr, n - s);
for (int i = alr + 1; i <= k; i++) {
// tmp[i] = mul(C(16 - alr, i - alr), binpow(i, n - s));
// cerr << i << ' ' << tmp[i] << endl;
tmp[i] = binpow(i, n - s);
for (int j = alr; j < i; j++) {
tmp[i] = sub(tmp[i], mul(tmp[j], C(i - alr, j - alr)));
}
}
return mul(tmp[k], C(16 - alr, k - alr));
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
init();
int k;
vector<int> a;
a = parse();
cin >> k;
int n = (int)a.size();
int ans = 0;
for (int len = 1; len < n; len++) {
{
int cr = mul(C(15, k), solve(len, k));
ans = add(ans, cr);
}
{
int cr = mul(C(15, k - 1), solve(len, k));
cr = mul(cr, divv(k - 1, k));
ans = add(ans, cr);
}
}
{
vector<int> cnt(16);
for (int pref = 0; pref <= n; pref++) {
if (pref == n) {
ans = add(ans, solve(n, k, cnt));
} else {
for (int j = 0; j < a[pref]; j++) {
if (pref == 0 && j == 0) continue;
cnt[j]++;
ans = add(ans, solve(n, k, cnt));
cnt[j]--;
}
cnt[a[pref]]++;
}
}
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define llong long long
#define len(x) ((int)x.size())
#define rep(i,n) for (int i = -1; ++ i < n; )
#define rep1(i,n) for (int i = 0; i ++ < n; )
#ifdef testing/*{{{*/
mt19937 rng(177013);
#else
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
#endif
#define rand() (int)(rng() >> 1)
#define CONCAT_(x, y) x##y
#define CONCAT(x, y) CONCAT_(x, y)
#define SPEC(name) CONCAT(name, __LINE__)
#ifdef LOCAL_DEBUG
int __db_level = 0;
#define clog cerr << string(__db_level * 2, ' ')
struct debug_block {
string msg;
debug_block(const string& s): msg(s) { clog << "{ " << msg << endl; ++__db_level; }
~debug_block() { --__db_level; clog << "} " << msg << endl; }
};
#define DB(args...) stringstream SPEC(ss); SPEC(ss)<< args; debug_block SPEC(dbbl)(SPEC(ss).str())
#else
#define clog if (0) cerr
#define DB(...)
#endif
#define db(val) "[" #val " = " << val << "]; "
template<class U, class V> ostream& operator<<(ostream& out, const pair<U, V>& p) {
return out << "(" << p.first << ", " << p.second << ")";
}
template<size_t i, class T> ostream& print_tuple_utils(ostream& out, const T& tup) {
if constexpr(i == tuple_size<T>::value) return out << ")";
else return print_tuple_utils<i + 1, T>(out << (i ? ", " : "(") << get<i>(tup), tup);
}
template<class ...U>
ostream& operator<<(ostream& out, const tuple<U...>& tup) { return print_tuple_utils<0, tuple<U...>>(out, tup); }
template<class, typename = void> struct has_const_iterator : false_type {};
template<class T> struct has_const_iterator<T, void_t<typename T::const_iterator>> : true_type {};
template<class T>
typename enable_if<has_const_iterator<T>::value && !is_same<T, string>::value, ostream&>::type
operator<<(ostream& out, const T& container) {
auto beg = container.begin(), end = container.end();
out << "(" << container.size() << ") {";
if (beg != end) out << *(beg++);
while (beg != end) out << ", " << *(beg++);
return out << "}";
}
#define ptrtype(x) typename iterator_traits<x>::value_type
template<class u> vector<ptrtype(u)> $v(u a, u b) { return vector<ptrtype(u)>(a, b); }/*}}}*/
// ACTUAL SOLUTION START HERE ////////////////////////////////////////////////////////////////
void inv(string& a) {
for (auto& ch: a) ch ^= 'A' ^ 'B';
}
void inv(list<string>& u) {
for (auto& s: u) inv(s);
}
list<string> concat(list<string> u, const list<string>& v) {
auto iu = u.begin();
auto iv = v.begin();
for (; iu != u.cend(); ++iu, ++iv)
*iu += *iv;
return u;
}
int main(void) {
#ifdef LOCAL
freopen("main.inp", "r", stdin);
freopen("main.out", "w", stdout);
freopen(".log", "w", stderr);
#endif
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n; cin >> n;
list<string> ans = {"AB"};
for (int i = 2; i <= n; ++i) {
auto a1 = concat(ans, ans);
auto x = ans; inv(x);
auto a2 = concat(ans, x);
ans = a1;
ans.splice(ans.end(), a2);
ans.push_back(string((1 << i >> 1), 'A') + string((1 << i >> 1), 'B'));
}
cout << len(ans) << '\n';
for (auto& s: ans) cout << s << '\n';
return 0;
}
// vim: foldmethod=marker
|
// #define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#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;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
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...);
}
typedef long long int64;
typedef pair<int, int> ii;
#define SZ(x) (int)((x).size())
template <typename T> static constexpr T inf = numeric_limits<T>::max() / 2;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }
struct fast_ios {
fast_ios() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
};
} fast_ios_;
bool is_prime(int n) {
for (int i = 2; i * i <= n; ++i) {
if (n % i == 0) return false;
}
return true;
}
int main() {
vector<int> p;
for (int i = 2; i <= 50; ++i) {
if (is_prime(i)) p.push_back(i);
}
trace(p, SZ(p));
int n, m = SZ(p);
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
int x;
cin >> x;
for (int j = 0; j < SZ(p); ++j) {
if (x % p[j] == 0) a[i] |= 1 << j;
}
}
trace(a);
int64 ret = inf<int64>;
for (int k = 1; k < (1 << m); ++k) {
bool ok = true;
for (int i = 0; i < n; ++i) {
if ((k & a[i]) == 0) {
ok = false;
break;
}
}
if (ok) {
int64 cur = 1;
for (int i = 0; i < m; ++i) {
if ((k >> i) & 1) cur *= p[i];
}
// trace(k, cur);
ret = min(ret, cur);
}
}
cout << ret << '\n';
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define ll long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(), v.end()
#define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a))
#define FORN(a, b, c) for (int(a) = (b); (a) <= (c); ++(a))
#define FORD(a, b, c) for (int(a) = (b); (a) >= (c); --(a))
#define FOREACH(a, b) for (auto&(a) : (b))
#define REP(i, n) FOR(i, 0, n)
#define REPN(i, n) FORN(i, 1, n)
#define dbg(x) cout << (#x) << " is " << (x) << endl;
#define dbg2(x, y) cout << (#x) << " is " << (x) << " and " << (#y) << " is " << y << endl;
#define dbgarr(x, sz) \
for (int asdf = 0; asdf < (sz); asdf++) cout << x[asdf] << ' '; \
cout << endl;
#define dbgarr2(x, rose, colin) \
for (int asdf2 = 0; asdf2 < rose; asdf2++) { \
dbgarr(x[asdf2], colin); \
}
#define dbgitem(x) \
for (auto asdf = x.begin(); asdf != x.end(); asdf++) cout << *asdf << ' '; \
cout << endl;
const int mod = 3, MAXN = 2e5 + 1;
int n, diam_kid[MAXN];
vi adj[MAXN];
struct Solution {
vi res;
int t = 1;
pii diam;
void solve() {
res.resize(n), memset(diam_kid, -1, sizeof(diam_kid));
diam = get_diameter(0);
// dbg2(diam.first, diam.second);
dfs(diam.first, -1);
walk(diam.first, -1);
}
void walk(int i, int p) {
res[i] = t++;
for (int j : adj[i]) {
if (j == p || j == diam_kid[i]) continue;
walk(j, i);
}
if (diam_kid[i] != -1) walk(diam_kid[i], i);
t++; // revisit
}
bool dfs(int i, int p) { // track which kid leads to the other endpoint of the diameter
if (i == diam.second) return true;
for (int j : adj[i]) {
if (j == p) continue;
if (dfs(j, i)) diam_kid[i] = j; // j leads to diam.second
}
return diam_kid[i] != -1;
}
pii get_diameter(int i) { // returns diam from the region i is in
auto p = farthest(i, 0, -1);
return {farthest(p.second, 0, -1).second, p.second};
}
pii farthest(int i, int d, int p) { // returns {dist, node} farthest from i; d= dist from source node
pii res = {d, i};
for (int j : adj[i]) {
if (j == p) continue;
res = max(res, farthest(j, d + 1, i));
}
return res;
}
};
void print(vector<int>& nums) {
for (auto num : nums) cout << num << " ";
cout << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
Solution test;
int a, b;
cin >> n;
REP(i, n - 1)
cin >> a >> b,
adj[--a].push_back(--b), adj[b].push_back(a);
test.solve();
print(test.res);
} |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
struct Dijkstra {
struct Edge {
int to;
T cost;
};
vector<int> prev;
vector<vector<Edge>> g;
Dijkstra(int n) : prev(n, -1), g(n) {}
void add_edge(int u, int v, T w) { g[u].push_back({v, w}); }
vector<T> build(int s) {
using Node = pair<T, int>;
vector<T> dist(g.size(), -1);
priority_queue<Node, vector<Node>, greater<Node>> pq;
pq.push({dist[s] = 0, s});
while (!pq.empty()) {
T d = pq.top().first;
int u = pq.top().second;
pq.pop();
if (dist[u] < d) continue;
for (auto&& v : g[u]) {
if (dist[v.to] < 0 || dist[v.to] > dist[u] + v.cost) {
pq.push({dist[v.to] = dist[u] + v.cost, v.to});
prev[v.to] = u;
}
}
}
return dist;
}
vector<int> get_path(int t) {
vector<int> path;
for (int i = t; i != -1; i = prev[i]) path.push_back(i);
reverse(begin(path), end(path));
return path;
}
};
int main() {
int a, b, x, y;
cin >> a >> b >> x >> y;
a--;
b--;
Dijkstra<int> g(200);
for (int i = 0; i < 100; i++) {
g.add_edge(i, i + 100, x);
g.add_edge(i + 100, i, x);
}
for (int i = 0; i < 99; i++) {
g.add_edge(i + 1, i + 100, x);
g.add_edge(i + 100, i + 1, x);
g.add_edge(i, i + 1, y);
g.add_edge(i + 1, i, y);
g.add_edge(i + 100, i + 101, y);
g.add_edge(i + 101, i + 100, y);
}
auto d = g.build(a);
cout << d[b + 100] << endl;
} | #include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <unordered_map>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
using namespace std;
using namespace __gnu_pbds;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> order_set;
bool check(auto &light, auto &grid, int i, int j, bool OK) {
if (grid[i][j] == 0) OK = false;
else if (grid[i][j] == 1) OK = true;
light[i][j] |= OK;
return OK;
}
int main() {
int H, W, N, M;
scanf("%d %d %d %d", &H, &W, &N, &M);
vector<vector<int>> grid(H, vector<int>(W, -1));
vector<vector<int>> light(H, vector<int>(W, 0));
for (int i = 0; i < N; i++) {
int a, b;
scanf("%d %d", &a, &b);
a--, b--;
grid[a][b] = 1;
}
for (int i = 0; i < M; i++) {
int a, b;
scanf("%d %d", &a, &b);
a--, b--;
grid[a][b] = 0;
}
for (int i = 0; i < H; i++) {
bool OK = false;
for (int j = 0; j < W; j++)
OK = check(light, grid, i, j, OK);
OK = false;
for (int j = W - 1; j >= 0; j--)
OK = check(light, grid, i, j, OK);
}
for (int c = 0; c < W; c++) {
bool OK = false;
for (int r = 0; r < H; r++)
OK = check(light, grid, r, c, OK);
OK = false;
for (int r = H - 1; r >= 0; r--)
OK = check(light, grid, r, c, OK);
}
int ans = 0;
for (int i = 0; i < H; i++)
for (int j = 0; j < W; j++) {
ans += light[i][j];
//printf("i = %d j = %d l = %d\n", i, j, light[i][j]);
}
printf("%d\n", ans);
return 0;
}
/* stuff you should look for
* int overflow, array bounds
* special cases (n=1?)
* do smth instead of nothing and stay organized
* WRITE STUFF DOWN
by Benq;
*/
|
#include <bits/stdc++.h>
using namespace std;
#define MAX 1e9
int main(){
int n,m,a,b,c;
pair<int,int> x;
cin>>n>>m;
vector<pair<int,int>> lst[n];
for(int i=0; i<m; i++){
cin>>a>>b>>c;
lst[a-1].push_back({-c,b-1});
}
bool visited[n],exists;
for(int i=0; i<n; i++){
priority_queue<pair<int,int>> pr;
memset(visited,false,n);
for(int j=0; j<lst[i].size(); j++) pr.push(lst[i][j]);
exists=false;
while(!pr.empty()){
if(pr.top().second==i){
exists=true;
break;
}
x=pr.top();
//cout<<x.second<<" ";
pr.pop();
if(visited[x.second])continue;
else visited[x.second]=true;
for(int j=0; j<lst[x.second].size(); j++) pr.push({x.first+lst[x.second][j].first,lst[x.second][j].second});
}
if(exists)cout<<(-pr.top().first)<<"\n";
else cout<<"-1\n";
//cout<<endl;
}
} | #define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define forn(a, e) for (i64 a = 0; a < (i64)(e); a++)
#define forr(a, s, e) for (i64 a = s; a < (i64)(e); a++)
#define fore(e, a) for (auto& e : a)
#ifdef LOCAL
#define logv(a) {cerr << #a << " = "; fore(e, a) {cerr << e << " ";} cerr << "\n";}
#define logvp(a) {cerr << #a << " = "; fore(e, a) {cerr << "(" << e.first << ", " << e.second << ") ";} cerr << "\n";}
#define logvv(a) {cerr << #a << " = \n"; fore(r, a) { fore(e, r) {cerr << e << " ";} cerr << "\n";} }
#define logvf(a, field) {cerr << #a"."#field << " = \n"; fore(e, a) { cerr << e.field << " ";} cerr << "\n"; }
#define logvff(a, f1, f2) {cerr << #a".{"#f1 << ", "#f2 << "} = \n"; fore(e, a) { cerr << "(" << e.f1 <<", " << e.f2 << ") ";} cerr << "\n"; }
#define logs(a) cerr << #a << " = " << (a) << "\n";
#define logss(a, b) cerr << #a << " = " << (a) << ", " << #b << " = " << (b) << "\n";
#define logp(a) cerr << #a << " = " << "(" << a.first << ", " << a.second << ")" << "\n";
#define cond(pred, stmt) if (pred) { stmt }
#else
#define logv(a)
#define logvp(a)
#define logvv(a)
#define logvf(a, field)
#define logvff(a, f1, f2)
#define logs(a)
#define logss(a, b)
#define logp(a)
#define cond(pred, stmt)
#endif
using iip = pair<int, int>;
using llp = pair<i64, i64>;
using ivec = vector<int>;
using llvec = vector<i64>;
using svec = vector<string>;
template<typename T> using vec = vector<T>;
template<typename T, typename Dim>
auto make_vec(T value, Dim dim) { return vector<T>(dim, value); }
template<typename T, typename Dim1, typename... Dim>
auto make_vec(T value, Dim1 dim1, Dim... dims) { return make_vec(make_vec(value, dims...), dim1); }
template<typename T>
bool uax(T& v, const T& newv) { if (v < newv) { v = newv; return true; } else return false; }
template<typename T>
bool uin(T& v, const T& newv) { if (v > newv) { v = newv; return true; } else return false; }
template<typename T>
istream& operator>>(istream& is, vector<T>& c) { for (auto& e : c) is >> e; return is; }
template<typename T, size_t N>
istream& operator>>(istream& is, array<T, N>& c) { for (auto& e : c) is >> e; return is; }
template<typename ...T>
istream& read(T&... args) { return (cin >> ... >> args); }
static mt19937 rande(123123);
template<typename T>
T rand_int(T from, T to) { uniform_int_distribution<T> distr(from, to); return distr(rande); }
// const i64 INF = 2e18;
const int INF = 2e9;
const __int128_t M = 1000000;
const int MXB = 20;
using bin = bitset<MXB + 1>;
const double EPS = 1e-8;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
rande.seed(chrono::steady_clock::now().time_since_epoch().count());
int n, m;
while (read(n, m)) {
vec<vec<iip>> g(n);
vec<vec<iip>> ing(n);
forn(i, m) {
int a, b, c;
read(a, b, c);
a--; b--;
g[a].emplace_back(b, c);
ing[b].emplace_back(a, c);
}
auto check_city = [&](int s) {
int ans = 1e9;
priority_queue<iip, vec<iip>, greater<iip>> q;
ivec dist(n, 1e9);
dist[s] = 0;
q.emplace(0, s);
while (!q.empty()) {
auto [d, v] = q.top();
q.pop();
if (d != dist[v]) {
continue;
}
for (auto [u, w] : g[v]) {
if (uin(dist[u], dist[v] + w)) {
q.emplace(dist[u], u);
}
}
}
for (auto [v, w] : ing[s]) {
uin(ans, dist[v] + w);
}
return ans;
};
ivec ans(n);
forn(i, n) {
ans[i] = check_city(i);
if (ans[i] == 1e9) {
ans[i] = -1;
}
}
forn(i, n) {
cout << ans[i] << "\n";
}
}
} |
#include <bits/stdc++.h>
using namespace std;
char A[303][303];
char tmp[303][303];
int main() {
int N; scanf("%d", &N);
A[0][0] = tmp[0][0] = 'A'; A[0][1] = tmp[0][1] = 'B';
for(int i = 2; i <= N; i++) {
for(int j = 0; j < 1 << i - 1; j++) A[0][j] = 'A';
for(int j = (1 << i - 1); j < 1 << i; j++) A[0][j] = 'B';
int x = 1, y = 0;
for(int j = 0; j < (1 << i - 1) - 1; j++) {
for(int k = 0; k < 1 << i - 1; k++) {
A[j + x][k + y] = tmp[j][k];
}
}
x = 1; y = 1 << i - 1;
for(int j = 0; j < (1 << i - 1) - 1; j++) {
for(int k = 0; k < 1 << i - 1; k++) {
A[j + x][k + y] = tmp[j][k];
}
}
x = 1 + ((1 << i - 1) - 1); y = 0;
for(int j = 0; j < (1 << i - 1) - 1; j++) {
for(int k = 0; k < 1 << i - 1; k++) {
A[j + x][k + y] = tmp[j][k];
}
}
x = 1 + ((1 << i - 1) - 1); y = 1 << i - 1;
for(int j = 0; j < (1 << i - 1) - 1; j++) {
for(int k = 0; k < 1 << i - 1; k++) {
A[j + x][k + y] = 131 - tmp[j][k];
}
}
for(int j = 0; j < (1 << i) - 1; j++) {
for(int k = 0; k < 1 << i; k++) tmp[j][k] = A[j][k];
}
}
printf("%d\n", (1 << N) - 1);
for(int i = 0; i < (1 << N) - 1; i++) printf("%s\n", A[i]);
return 0;
} | #include<bits/stdc++.h>
using namespace std;
int main(){
int64_t N;
cin>>N;
int64_t cnta=1,cntb=1;
int64_t i=3,j=5;
while(i<=N){
int64_t M=N-i;
while(j<=M){
if(j==M){
cout<<cnta<<' '<<cntb<<endl;
return 0;
}
cntb++;
j*=5;
}
cntb=1;j=5;
cnta++;i*=3;
}
cout<<-1<<endl;
} |
#include <bits/stdc++.h>
using namespace std;
// 総数を1000000007(素数)で割った余り
const long long mod = 1e9 + 7;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>
#define Graph vector<vector<int>>
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair
#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)
ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }
const string YES = "Yes";
const string NO = "No";
void func(std::string S, std::string T){
}
int main() {
string A, B;
cin >> A >> B;
if(A=="Y"&&B=="a"){
cout << "A" << endl;
}
else if(A=="Y"&&B=="b"){
cout << "B" << endl;
}
else if(A=="Y"&&B=="c"){
cout << "C" << endl;
}
else if(A=="N"&&B=="a"){
cout << "a" << endl;
}
else if(A=="N"&&B=="b"){
cout << "b" << endl;
}
else if(A=="N"&&B=="c"){
cout << "c" << endl;
}
} | #include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
using namespace std;
#define pq_max priority_queue<ll>
#define pq_min priority_queue<ll,vi,greater<ll>>
#define iint int
#define f(i,a,b) for(ll i=a;i<b;i++)
#define f0(i,n) f(i,0,n)
#define fr(i,a,b) for(ll i=a;i>=b;i--)
#define for1(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define tc(t) int t;cin >>t;while(t--)
#define lol std::ios::sync_with_stdio(false); cin.tie(NULL);
#define endl "\n"
#define ss second
#define ff first
#define ll long long
#define lld long double
#define int long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
const long long inf = 1e18;
#define all(a) a.begin(),a.end()
#define arr(a,n) int a[n];f0(i, n) cin >> a[i];
#define ini(a,n) memset(a,n,sizeof(a))
#define printArr(a,n) f0(i,n) cout<<a[i]<<" ";
// #define in cin>>
#define rr return 0;
#define vi vector< int >
#define vs vector<string>
#define l_b lower_bound
#define u_b upper_bound
#define mod 1000000007
#define pi 3.141592653589793238
#define fmap(m) for(auto it:m)
#define deb(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define debarr(arr,a,b) for(int i=(a);i<(b);i++) cout<<(arr[i])<<" ";cout<<endl;
#define long_max numeric_limits<ll>::max()
vs tokenizer(string str, char ch) {std::istringstream var((str)); vs v; string t; while (getline((var), t, (ch))) {v.pb(t);} return v;}
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cout << *it << " = " << a << endl;
err(++it, args...);
}
int dx[8] = { +1, +1, +1, 0, 0, -1, -1, -1};
int dy[8] = { +1, 0, -1, +1, -1, +1, 0, -1};
int dx4[4] = { +1 , -1 , +0 , +0};
int dy4[4] = { 0 , 0 , +1 , -1};
int dx2[2] = {0, 1};
int dy2[2] = {1, 0};
const int N = 1e6 + 1;
int nc2(int n )
{
return n * (n - 1) / 2;
}
void solve()
{
int a, b;
cin >> a >> b;
// 0 rock 1 scissor 2 paper;
if ( a == b)
cout << a << '\n';
// if (a > b) swap(a, b);
else
cout << 3 - (a + b) << "\n";
}
signed main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
lol;
int t = 1;
// cin >> t;
while (t--)
solve();
return 0;
} |
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
// please, read the question correctly (do you need set or multiset)???
const int N=510; //check the limits, dummy
int a[N];
int n, m;
char c[N];
set<char> s[N+N];
int main(){
scanf("%d%d",&n,&m);
for(int i=0; i<n; ++i){
scanf("%s",c);
for(int j=0; j<m; ++j){
if(c[j]!='.')
s[i+j].insert(c[j]);
}
}
ll ans = 1, mod = 998244353;
for(int i=0; i<=n+m-2; ++i){
if(s[i].size()==2){
ans = 0;
break;
}
else if(s[i].size()==0){
ans *= 2;
ans %= mod;
}
}
printf("%lld\n",ans) ;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#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 FOR(i,n) for(ll i=0;i<n;i++)
#define pb push_back
#define mp make_pair
#define PI 3.14159265358979323846
#define fi first
#define se second
#define max3(a, b, c) max(max(a, b), c)
#define min3(a, b, c) min(min(a, b), c)
#define all(x) x.begin(),x.end()
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const ll mod = 998244353;
const ll inf = 1e18;
vector<ll> factorial;
void fill_factorial(ll n) {
factorial.resize(n+1);
factorial[0] = 1;
for(ll i=1; i<=n; i++) factorial[i] = (factorial[i-1]*i)%mod;
}
ll gcd(ll a, ll b, ll& x, ll& y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
ll x1, y1;
ll d = gcd(b, a % b, x1, y1);
x = y1;
y = x1 - y1 * (a / b);
return d;
}
ll binpow(ll a, ll b) {
a %= mod;
ll res = 1;
while (b > 0) {
if (b & 1)
res = res * a%mod;
a = a * a%mod;
b >>= 1;
}
return res;
}
ll inv(ll a) {
ll x, y;
ll g = gcd(a, mod, x, y);
x = (x % mod + mod) % mod;
return x;
}
ll CC(ll n, ll k) {
if(k>n) return 0LL;
return factorial[n] * inv(factorial[k]) % mod * inv(factorial[n - k]) % mod;
}
void solve() {
ll n; cin>>n;
ll ans = 0;
FOR(i,n) {
ll a,b; cin>>a>>b;
ans += (b*(b+1))/2 - (a*(a-1))/2;
}
cout<<ans<<"\n";
}
int main() {
IOS;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
//ll no_of_test_cases; cin>>no_of_test_cases;
ll no_of_test_cases = 1;
while(no_of_test_cases--) {
solve();
}
return 0;
} |
/**
* author: zakhio (mttk1528)
* created: 13.03.2021 21:04:51
**/
// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
using namespace std;
#define dump(x) cout << #x << " = " << (x) << endl
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define len(x) (int)(x.size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pcnt(x) __builtin_popcount(x)
#define ctz(x) __builtin_ctz(x)
#define rup(x, y) ((x + y - 1) / (y))
using str = string;
using ll = long long;
using ld = long double;
using pll = pair<ll,ll>;
using pii = pair<int,int>;
using pil = pair<int,ll>;
using pli = pair<ll,int>;
using pldld = pair<ld,ld>;
// using bint = boost::multiprecision::cpp_int;
constexpr ld PI = M_PI;
constexpr ld EPS = 1e-10;
constexpr ll LINF = 1e18;
constexpr int INF = 1e9;
constexpr int MAX = 2000020;
constexpr int MOD1 = 1000000007;
constexpr int MOD2 = 998244353;
const int di[4] = {1, 0, -1, 0};
const int dj[4] = {0, 1, 0, -1};
const int di2[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj2[8] = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr ld radian_to_degree(ld r) { return (r * 180.0 / PI); }
constexpr ld degree_to_radian(ld d) { return (d * PI / 180.0); }
inline bool eq(ld lhs, ld rhs) { return std::fabs(lhs - rhs) < EPS; }
inline void print() { cout << endl; return; }
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) { cout << head; if (sizeof...(tail)) cout << " "; print(forward<Tail>(tail)...); }
template <typename T, typename U> inline bool chmax(T &lhs, U rhs) { if (lhs < rhs) { lhs = rhs; return true; } return false; }
template <typename T, typename U> inline bool chmin(T &lhs, U rhs) { if (lhs > rhs) { lhs = rhs; return true; } return false; }
template <typename T> inline T gcd_all(vector<T> &v) { return reduce(all(v), v[0], [] (T x, T y) { return gcd(x, y); }); }
template <typename T> inline T lcm_all(vector<T> &v) { return reduce(all(v), v[0], [] (T x, T y) { return lcm(x, y); }); }
template <typename T> inline T bpow(T a, int n) { T r(1); while (n) { if (n & 1) r *= a; a *= a; n >>= 1; } return r; }
template <typename T> inline auto comp(vector<T> v) { sort(all(v)); v.erase(unique(all(v)), v.end()); return v; }
template <typename T> inline string join(string s, vector<T> v) { string t = ""; rep(i, len(v)) { if (i) t += s; t += to_string(v[i]); } return t; }
template <typename T> inline ld eucdist(pair<T,T> x, pair<T,T> y) { return hypotl(x.first - y.first, x.second - y.second); }
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T,U> &p) { return os << p.first << " " << p.second;}
template <typename T, typename U> istream &operator>>(istream &is, pair<T,U> &p) { return is >> p.first >> p.second; }
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { rep(i, len(v)) { if (i) os << " "; os << v[i]; } return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template <typename T> ostream &operator<<(ostream &os, const set<T> &st) { int c(0); for (auto &x : st) { if (c) os << " "; os << x; c++; } return os;}
void solve() {
ll a, b, x; cin >> a >> b >> x;
ll as = a, bs = b;
x *= 1000;
bool ok = false;
while (true) {
if (as <= x && x <= bs) ok = true;
as += a, bs += b;
if (as > x) break;
}
if (ok) print(rup(x, b), x / a);
else print("UNSATISFIABLE");
return;
}
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
// cout << fixed << setprecision(15);
solve();
return 0;
} | #include <iostream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>
#include <math.h>
//#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#define MAX (1LL<<63)-1
#include <algorithm>
//#pragma GCC optimize ("-O3")
using namespace std;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
typedef long long ll;
#define PI 3.14159265358979323846
#define NIL -1
int main(){
float A,B;
cin >> A >> B;
float C=B*A/100;
cout << C << endl;
} |
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define MO 1000000007
#define mem(a,s) memset(a,s,sizeof(a))
#define IOS ios_base::sync_with_stdio(0); cin.tie(NULL);
#define lop(i,s,e) for(int i=s;i<e;i++)
#define lopi(i,s,e) for(int i=s;i>=e;i--)
#define prina(a,n) for(int i=0;i<=n;i++)cout<<a[i]<<" ";cout<<endl;
#define prin2da(a,n,m) lop(i,1,n){lop(j,1,m)cout<<a[i][j]<<" ";cout<<endl;}
#define atout(v) for(auto x:v) cout<<x<<" ";cout<<endl;
#define atin(v) for(auto &x:v) cin>>x;
#define vl vector<ll >
#define vi vector<int >
#define lb lower_bound
#define ub upper_bound
#define sort(a) sort(a.begin(),a.end())
#define mp make_pair
#define all(v) v.begin(),v.end()
#define pll pair<ll,ll>
using namespace std;
bool check(ll l,ll r,vector<vector<ll>> &p,vector<ll> &b) {
ll n=p.size();
lop(i,l,r+1) b[i]=0;
lop(i,0,n) {
ll x=p[i][0],y=p[i][1];
if(x!=-1 and y!=-1) {
if(y<l or x>r) continue;
if(y-x!=(r-l+1)/2 or b[x]) return false;
b[x]=1;
}
else if(x!=-1 and y==-1) {
if(x>r or x<l) continue;
if(x>=(r+l+1)/2 or b[x]) return false;
b[x]=1;
}
else if(x==-1 and y!=-1) {
if(y<l or y>r) continue;
x=y-((r-l+1)/2);
if(y<(r+l+1)/2 or b[x]) return false;
b[x]=1;
}
}
return true;
}
void solve() {
ll n;
cin>>n;
vector<vector<ll>> p(n,vector<ll>(2,0));
vector<bool> dp(2*n+1,false);
vector<ll> b(2*n+1);
lop(i,0,n) cin>>p[i][0]>>p[i][1];
dp[0]=true;
for(int i=0 ; i<(2*n)+1 ; i+=2) {
for(int j=i+2 ; j<=(2*n)+1 ; j+=2) {
//cout<<check(i+1,j,p,b)<<endl;
dp[j]=dp[j]or(dp[i] and check(i+1,j,p,b));
}
}
//atout(dp);
cout<<((dp[2*n])?"Yes":"No")<<endl;
return;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ll t=1;
while(t--) {
solve();
}
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#pragma region atcoder
/*#include <atcoder/all>
using namespace atcoder;*/
//using mint = modint998244353;
//using mint = modint1000000007;
#pragma endregion
#pragma region macros
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vs = vector<string>;
using vl = vector<ll>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, a, b) for(int i = a; i < b; i++)
#define rrep(i, n) for(int i = n - 1; i >= 0; i--)
#define RREP(i, a, b) for(int i = b - 1; i >= a; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (r).rend()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
#pragma endregion
#pragma region debug for var, v, vv
#define debug(var) do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){cout << endl;int cnt = 0;for(const auto& v : vv){cout << cnt << "th : "; view(v); cnt++;} cout << endl;}
#pragma endregion
const ll mod = 1000000007;
const int inf = 1001001001;
const ll INF = 1001001001001001001;
const int MAX = 2000005;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
template<class T>bool chmax(T &a, const T b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T b) { if (b<a) { a=b; return 1; } return 0; }
ll rudiv(ll a, ll b) { return a/b+((a^b)>0&&a%b); }
ll rddiv(ll a, ll b) { return a/b-((a^b)<0&&a%b); }
ll modpow(ll a, ll p){ll ret = 1; while(p){if(p & 1){ret = ret * a % mod;} a = a * a % mod; p >>= 1;} return ret;}
/*--------------------------------------------------------------------------------------------------------------------------------*/
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
//cout << fixed << setprecision(15);
ll n; cin >> n;
bool ok = false;
ll a = 1, b = 1;
for(int i = 1; i < 100; i++){
a *= 3;
b = 1;
if(a > n) break;
for(int j = 1; j < 100; j++){
b *= 5;
if(n < a + b) break;
if(a + b == n){
ok = true;
cout << i << " " << j << endl;
return 0;
}
}
}
if(!ok) cout << -1 << endl;
}
/*
* int overflow, array bounds
* special cases (n=1?)
*/
|
#include<bits/stdc++.h>
using namespace std;
int main()
{
char arr[101][101];
int i,n,m,x,y,count=0;
char ch;
cin>>n>>m>>x>>y;
for(i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
cin>>arr[i][j];
}
}
if(arr[x][y]=='.')
count++;
else if(arr[x][y]=='#')
{
cout<<"0"<<endl;
return 0;
}
for(i=x+1;i<=n;i++)
{
if(arr[i][y]=='.')
count++;
else
break;
}
for(i=x-1;i>=1;i--)
{
if(arr[i][y]=='.')
count++;
else
break;
}
for(i=y+1;i<=m;i++)
{
if(arr[x][i]=='.')
count++;
else
break;
}
for(i=y-1;i>=1;i--)
{
if(arr[x][i]=='.')
count++;
else
break;
}
cout<<count<<endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int h, w, x, y;
cin >> h >> w >> x >> y;
x--;
y--;
vector<string> mp(h);
for (int i = 0; i < h; i++) cin >> mp[i];
int ans = 0;
for (int i = x; i < h; i++) {
if (mp[i][y] == '#') break;
ans++;
}
for (int i = x - 1; i >= 0; i--) {
if (mp[i][y] == '#') break;
ans++;
}
for (int j = y + 1; j < w; j++) {
if (mp[x][j] == '#') break;
ans++;
}
for (int j = y - 1; j >= 0; j--) {
if (mp[x][j] == '#') break;
ans++;
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<int,int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
int main(){
int n;
cin >> n;
vector<vector<int>> a(n,vector<int>(5));
vector<vector<int>> b(n,vector<int>(5));
rep(i,n){
rep(j,5) cin >> a[i][j];
}
rep(i,5) b[n-1][i]=n-1;
for(int i=n-2;0<=i;i--){
rep(j,5){
if(a[i][j]<a[b[i+1][j]][j]) b[i][j]=b[i+1][j];
else b[i][j]=i;
}
}
int ans=0;
rep(i,n-2){
for(int j=i+1;j<n-1;j++){
rep(l,5){//もう1人を選ぶ時に見る能力
vector<int> c(5);
rep(k,5){
c[k]=max(a[i][k],a[j][k]);
c[k]=max(c[k],a[b[j+1][l]][k]);
}
int m=1e9+10;
rep(k,5) m=min(m,c[k]);
ans=max(ans,m);
}
}
}
cout << ans << endl;
} | #ifndef DEBUG
#define NDEBUG
#endif
#include <bits/stdc++.h>
#define def(v) int &v = e[i].v
#define cls(a) memset (a, 0, sizeof (a))
#define mset(a,b) memset (a, b, sizeof (a))
#define go(i,e,u,...) for (int i = (u), ##__VA_ARGS__; i; i = e[i].nt)
#define fir(i,a,b,...) for (int i = (a), ##__VA_ARGS__; i <= (b); ++i)
#define firr(i,a,b,...) for (int i = (a), ##__VA_ARGS__; i >= (b); --i)
#ifdef DEBUG
#define debug(format,...) (void)fprintf (stderr, "debug in %d: " format "\n", __LINE__, ##__VA_ARGS__)
#define dbug(x) (void)(std::cerr << #x " = " << (x) << std::endl)
#else
#define debug(...) (void)0
#define dbug(...) (void)0
#endif
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#ifndef DEBUG
namespace IO {
char ibuf[1 << 21], *p1 = ibuf, *p2 = ibuf, obuf[1 << 21], *p = obuf;
#define getchar() (::IO::p1 == ::IO::p2 && (::IO::p2 = (::IO::p1 = ::IO::ibuf) + fread (::IO::ibuf, 1, 1 << 21, stdin), ::IO::p1 == ::IO::p2) ? EOF : *::IO::p1++)
#define putchar(x) (::IO::p == ::IO::obuf + sizeof (::IO::obuf) && (fwrite (::IO::obuf, 1, 1 << 21, stdout), ::IO::p = ::IO::obuf), *::IO::p++ = x)
#define ioflush() (void)(fwrite (::IO::obuf, 1, ::IO::p - ::IO::obuf, stdout), fflush (stdout), ::IO::p = ::IO::obuf)
struct outflush {~outflush () {ioflush ();}} flushout;
}
#endif
int rec () {
int ch;
while (isspace (ch = getchar ()));
return ch;
}
bool rei (char& c) {
int ch;
while (isspace (ch = getchar ()));
if (ch == EOF) return false;
c = ch;
return true;
}
bool rei (char* s) {
if (!rei (*s)) return false;
int ch;
while (*++s = ch = getchar (), ch != EOF && !isspace (ch));
*s = 0;
return true;
}
template<class T>
bool rei (T& x) {
bool f = true; int ch; x = 0;
while (!isdigit (ch = getchar ())) {
if (ch == EOF) return false;
f = ch != '-';
}
if (f) do x = x * 10 + (ch & 15); while (isdigit (ch = getchar ()));
else do x = x * 10 - (ch & 15); while (isdigit (ch = getchar ()));
return true;
}
void pti (const char& c) {putchar (c);}
void pti (const char* s) {while (*s) putchar (*s++);}
template<class T>
void pti (T x) {
char buf[sizeof (T) * 3], *p = buf + 1;
if (x >= 0) *buf = (x % 10) | 48, x /= 10;
else putchar ('-'), *buf = (-(x % 10)) | 48, x = -(x / 10);
while (x) *p++ = (x % 10) | 48, x /= 10;
while (p != buf) putchar (*--p);
}
template<class T> void pri (const T& x) {pti (x), putchar (' ');}
template<class T> void prn (const T& x) {pti (x), putchar ('\n');}
template<class T, class... Args> bool rei (T&& x, Args&&... args) {return rei (std::forward<T> (x)) ? rei (std::forward<Args> (args)...) : false;}
template<class T, class... Args> void pti (const T& x, const Args&... args) {pti (x), pti (args...);}
template<class T, class... Args> void pri (const T& x, const Args&... args) {pri (x), pri (args...);}
template<class T, class... Args> void prn (const T& x, const Args&... args) {pri (x), prn (args...);}
template<class T1, class T2> T1& cmax (T1& a, const T2& b) {return a < b ? a = b : a;}
template<class T1, class T2> T1& cmin (T1& a, const T2& b) {return a > b ? a = b : a;}
template<class T> T lowbit (const T& x) {return x & -x;}
using namespace std;
const int MOD = 1e9 + 7;
int mod1 (int x) {return x >= MOD ? x - MOD : x;}
int mod2 (int x) {return x < 0 ? x + MOD : x;}
signed main () {
int n, x;
rei (n, x);
int dp[] = {x, 0}, ct[] = {1, 0};
fir (i, 2, n) {
rei (x);
int t = dp[0];
dp[0] = (dp[0] + dp[1] + (LL)x * (ct[0] + ct[1])) % MOD;
dp[1] = (t + (LL)(MOD - x) * ct[0]) % MOD;
t = ct[0];
ct[0] = mod1 (ct[0] + ct[1]);
ct[1] = t;
}
prn (mod1 (dp[0] + dp[1]));
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int main(){
//freopen("vs.inp","r",stdin);
int a,b,T;
scanf("%d %d %d",&a,&b,&T);
T*=1000;
int s1=(T)/a;
int s2=(T+b-1)/b;
if((a+(T%a+s1-1)/s1)>b || (b-(T%b+s2-1)/s2)<a) printf("UNSATISFIABLE");
else printf("%d %d",s2,s1);
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}
int main2() {
ll A = nextLong();
ll B = nextLong();
ll W = 1000 * nextLong();
int mi = 90000000;
int ma = -1;
for (int k = 1; k <= 10000000; k++) {
if (k * A <= W && W <= k * B) {
chmin(mi, k);
chmax(ma, k);
}
}
if (ma == -1) {
cout << "UNSATISFIABLE" << endl;
} else {
cout << mi << " " << ma << endl;
}
return 0;
}
int main() {
#ifdef LOCAL
for (;!cin.eof();cin>>ws)
#endif
main2();
return 0;
} |
#include<iostream>
#include<vector>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> op(N);
int i;
char s[4];
for(i=0;i<N;i++) {
cin >> s;
if(s[0] == 'A')op[i] = 0;
else op[i] = 1;
}
vector<long long> dp0(N+1,0),dp1(N+1,0);
dp0[0] = dp1[0] = 1;
for(i=0;i<N;i++) {
if(op[i]==0) {
dp0[i+1] = dp0[i]*2 + dp1[i];
dp1[i+1] = dp1[i];
}
else {
dp0[i+1] = dp0[i];
dp1[i+1] = dp0[i] + dp1[i]*2;
}
}
cout << dp1[N] << endl;
} | #include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;
template <class T>
inline void chmin(T &a, const T &b) { a = min(a, b); }
template <class T>
inline void chmax(T &a, const T &b) { a = max(a, b); }
template <class T>
inline bool kbit(const T &x, const int &k) { return ((x >> k) & 1LL); }
inline int popcount(const int &n) { return __builtin_popcount(n); }
inline ll popcountll(const ll &n) { return __builtin_popcountll(n); }
inline ll mask(const ll &k) { return (1LL << k) - 1LL; }
template <class T>
void zip(V<T> &v) {
sort(all(v));
v.erase(unique(all(v)), v.end());
}
template <class T>
int lwb(V<T> &v, const T &x) { return lower_bound(all(v), x) - v.begin(); }
template <class T>
int upb(V<T> &v, const T &x) { return upper_bound(all(v), x) - v.begin(); }
void dump() {
cerr << '\n';
}
template <class Head, class... Tail>
void dump(Head &&head, Tail &&...tail) {
cerr << head << (sizeof...(Tail) == 0 ? " " : ", ");
dump(std::move(tail)...);
}
template <class T>
void print(const vector<T> &v) {
for (int i = 0; i < v.size(); i++) cout << v[i] << (i + 1 == v.size() ? '\n' : ' ');
}
template <class T>
void read(vector<T> &v) {
for (int i = 0; i < v.size(); i++) cin >> v[i];
}
constexpr char sp = ' ', newl = '\n';
constexpr int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
constexpr ll INF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
//////////////////////////////////////////////INSERT ABOVE HERE
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
V<V<int>> c(n, V<int>(n));
for (int i = 0; i < n; i++) {
read(c[i]);
}
V<int> aa(n), bb(n);
for (int i = 0; i + 1 < n; i++) {
bb[i] = c[0][i + 1] - c[0][i];
aa[i] = c[i + 1][0] - c[i][0];
}
for (int i = 1; i < n; i++) {
for (int j = 0; j + 1 < n; j++) {
if (c[j + 1][i] - c[j][i] != aa[j]) {
cout << "No" << newl;
return 0;
}
if (c[i][j + 1] - c[i][j] != bb[j]) {
cout << "No" << newl;
return 0;
}
}
}
V<int> a(n);
V<int> b(n);
bool f = true;
a[0] = 0;
b[0] = 0;
int ma = 0, mb = 0;
for (int i = 0; i + 1 < n; i++) {
a[i + 1] = a[i] + aa[i];
chmin(ma, a[i + 1]);
}
for (int i = 0; i + 1 < n; i++) {
b[i + 1] = b[i] + bb[i];
chmin(mb, b[i + 1]);
}
ma *= -1;
mb *= -1;
if (ma + mb > c[0][0]) {
cout << "No" << newl;
} else {
a[0] = ma;
b[0] = c[0][0] - ma;
for (int i = 0; i + 1 < n; i++) {
a[i + 1] = a[i] + aa[i];
}
for (int i = 0; i + 1 < n; i++) {
b[i + 1] = b[i] + bb[i];
}
cout << "Yes" << newl;
print(a);
print(b);
}
}
|
#include<bits/stdc++.h>
#include<string>
using namespace std;
const int N=1e3+10;
typedef long long ll;
int n,k,q,m,h,w;
const ll mod=998244353;
int a[N];
int b[N];
map<int,map<int,int> > mp;
set<int> se;
string s;
stack <int> st;
int X[]={-1,-1,-1,0,0,1,1,1};
int Y[]={-1,0,1,-1,1,-1,0,1};
int main()
{
int r1,c1,r2,c2;
cin>>r1>>c1;
cin>>r2>>c2;
int cha1=abs(r1-r2);
int cha2=abs(c1-c2);
int ans;
int ans1;
if(r1==r2&&c1==c2){
cout<<0;
return 0;
}
if(cha1+cha2<=3){
cout<<1;
return 0;
}
if(cha1==cha2){
cout<<1;
return 0;
}
if((cha1+cha2)%2==0){
cout<<2;
return 0;
}
if(abs(cha1-cha2)<=3){
cout<<2;
return 0;
}
if(cha1+cha2<=6){
cout<<2;
return 0;
}
cout<<3;
}
| #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define ALL(x) ::std::begin(x), ::std::end(x)
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 pii = pair<ll,ll>;
int64_t solve(vector<pii> & a) {
// TODO: edit here
ll x = abs(a[1].first - a[0].first);
ll y = abs(a[1].second - a[0].second);
if(x==0LL && y==0LL) return 0;
if(x==y) return 1;
else if((x+y)<= 3LL) return 1;
if((((x&1LL)+(y&1LL))&1LL)==1LL){
if(abs(x-y) <= 6LL) return 2;
else return 3;
}
else{
return 2;
}
return 0;
}
// generated by online-judge-template-generator v4.7.1 (https://github.com/online-judge-tools/template-generator)
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
constexpr char endl = '\n';
// failed to analyze input format
// TODO: edit here
vector<pii> a(2);
REP (i, 2) {
cin >> a[i].first >> a[i].second;
}
auto ans = solve(a);
cout << ans << endl;
return 0;
}
|
/*
Remember, Hope is a good thing... May be the best of things... and No Good thing ever Dies !!!
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define IOS ios::sync_with_stdio(0); cout.tie(0);
#define endl "\n"
#define MOD1 1000000007
#define yes cout<<"Yes"<<endl
#define no cout<<"No"<<endl
#define fi first
#define se second
const ll inf=(1LL<<60)-1;
const ll mxn=1e5+7;
int dx[]= {-1,1,0,0};
int dy[]= {0,0,-1,1};
const ll limit=1e6+5;
/*
sort(v.begin(),v.end(),[&](const pair<ll,ll>&a,const pair<ll,ll>&b)
{
if(a.first==b.first)
return a.second<b.second;
else
return a.first>b.first;
});
*/
void solve()
{
//freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
ll c,d,i,j,p,q,k,l,r,w,h,n,m,x,y,z=0,cnt=0,ans=0;
cin>>n;
vector<ll>v(1LL<<n);
for(ll i=0;i<1LL<<n;i++)
cin>>v[i];
m=1LL<<n;
x=max_element(v.begin(),v.begin()+m/2)-v.begin();
y=max_element(v.begin()+m/2,v.end())-v.begin();
if(v[x]<v[y])
ans=x+1;
else
ans=y+1;
cout<<ans<<endl;
}
int main()
{
IOS;
ll t=1;
//cin>>t;
while(t--)
solve();
return 0;
}
| //JOY SREE RAM
//JOY SREE GANESH
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define vl vector<long long>
#define all(v) begin(v),end(v)
#define vs vector<string>
#define ll long long
#define all(v) begin(v),end(v)
#define vs vector<string>
#define qi queue<int>
#define pqi priority_queue<int>
#define sti stack<int>
#define si set<int>
#define pii pair<long,long>
#define mpi map<int,int>
#define mps map<string,int>
#define mpc map<char,int>
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define pi pair<int,int>
#define vpi vector<pair<ll,ll> >
#define np next_permutation
#define mod 1000000007
#define INF 1e9
#define kom -10000000
#define fst ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL)
const int mxn =1e7 + 5;
ll cc_size;
int mark[mxn];
set<int> primes;
void sieve(){
for(int i=4; i<mxn; i+=2)mark[i] = 1;
for(int i=3; i*i<mxn; i+=2){
if(mark[i] == 0){
for(int j=i*i; j<mxn; j+=(i*2))mark[j] = 1;
}
}
}
bool is_prime(int x) {
if(x == 1) return false;
for(int i = 2; i*i <= x; i++) {
if(x % i == 0) return false;
}
return true;
}
bool cmp1(pii x, pii y){
if(x.ff!=y.ff) return x.ff<y.ff;
return x.ss>y.ss;
}
int vis[200005];
vi adj[200005];
void dfs(int u){
cc_size++;
vis[u]=1;
for(auto v : adj[u]){
if(vis[v])continue;
dfs(v);
}
}
int main(){
vi v;int a;
for(int i=0;i<3;i++){
cin>>a;
v.pb(a);
}
sort(all(v));
cout<<v[2]+v[1]<<'\n';
return 0;
}
|
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using pi = pair<int, int>;
using vpi = vector<pair<int, int>>;
using pl = pair<ll, ll>;
using vl = vector<ll>;
#define all(v) (v).begin(), (v).end()
#define ar array
#define PB push_back
#define sz(x) (int)(x).size()
template <typename T>
using pqg = priority_queue<T, vector<T>, greater<T>>;
template <typename A, typename B>
ostream &operator<<(ostream &os, const pair<A, B> &p)
{
return os << '(' << p.first << ", " << p.second << ')';
}
template <typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type>
ostream &operator<<(ostream &os, const T_container &v)
{
os << '{';
string sep;
for (const T &x : v)
os << sep << x, sep = ", ";
return os << '}';
}
void dbg_out()
{
cerr << endl;
}
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T)
{
cerr << ' ' << H;
dbg_out(T...);
}
#ifdef LOCAL
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif
struct custom_hash
{
static uint64_t splitmix64(uint64_t x)
{
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);
}
};
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9 + 7; //998244353
void solve()
{
int n;
cin >> n;
vector<pair<pi,pi>> p(n);
for (int i=0;i<n;++i){
int t,l,r;
cin >> t >> l >> r;
if (t==1) p[i] = {{l,1}, {r,1}};
else if (t==2) p[i] = {{l,1}, {r,0}};
else if (t==3) p[i] = {{l,0}, {r,1}};
else p[i] = {{l,0}, {r,0}};
}
int ans = 0;
for (int i=0;i<n;++i){
pi l = p[i].first, r = p[i].second;
for (int j=i+1;j<n;++j){
pi L = p[j].first, R = p[j].second;
if (L.first>r.first||R.first<l.first) continue;
ans++;
dbg(l, r, L,R);
if (L.first==r.first&&(!L.second||!r.second))ans--;
if (R.first==l.first&&(!R.second||!l.second))ans--;
}
}
cout << ans << "\n";
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
solve();
} | #include <bits/stdc++.h>
#define tez ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mb make_pair
#define el "\n"
#define MAX 100005
using namespace std;
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
tez
ll t = 1;
// cin >> t;
while (t--)
{
ll n;
cin >> n;
vector <vector <ll>> p(n, vector <ll> (3));
for (ll i = 0; i < n; ++i)
cin >> p[i][2] >> p[i][0] >> p[i][1];
sort(p.begin(), p.end());
// for (ll i = 0; i < n; ++i)
// {
// cout << p[i][0] << " " << p[i][1] << " " << p[i][2];
// cout << el;
// }
ll ans = 0;
for (ll i = 0; i < n; ++i)
{
ll ed = p[i][1];
for (ll j = i + 1; j < n; ++j)
{
if (p[j][0] > ed)
break;
else
{
if (p[j][0] < ed)
ans++;
else
{
if ((p[i][2] == 1 && p[j][2] == 1) ||
(p[i][2] == 1 && p[j][2] == 2) ||
(p[i][2] == 3 && p[j][2] == 1) ||
(p[i][2] == 3 && p[j][2] == 2))
ans++;
}
}
}
}
cout << ans << el;
}
return 0;
} |
/*
ID: Λινδα
LANG: C++
TASK: abc194a
*/
#include <stdio.h>
#include <algorithm>
using namespace::std;
int read(){char c=getchar();int t=0,f=1;while(c<'0'||c>'9'){if(c=='-'){f=-1;}c=getchar();}while(c>='0'&&c<='9'){t=(t<<1)+(t<<3)+(c^48);c=getchar();}return t*f;}
void write(int x){char ch[50];int l=0;if(x<0){putchar('-');x=-x;}do{ch[l++]=x%10+'0';x=x/10;}while(x);while(l){putchar(ch[--l]);}}
struct wrkr
{
int id,tm;
};
bool cmpr(wrkr x,wrkr y)
{
return x.tm<y.tm;
}
int main()
{
// freopen("main.in","r",stdin);
// freopen("main.out","w",stdout);
// freopen("main.err","w",stderr);
int i,n=read();
wrkr a[1004],b[1004];
for(i=0;i!=n;++i)
{
a[i].tm=read();
a[i].id=i;
b[i].tm=read();
b[i].id=i;
}
sort(a,a+n,cmpr);
sort(b,b+n,cmpr);
if(a[0].id==b[0].id)
{
write(min(a[0].tm+b[0].tm,min(max(a[0].tm,b[1].tm),max(a[1].tm,b[0].tm))));
}
else
{
write(max(a[0].tm,b[0].tm));
}
putchar('\n');
// fclose(stdin);
// fclose(stdout);
// fclose(stderr);
return 0;
} | #include<cstdio>
#include<vector>
int w[15];
struct Element{
int l,v;
};
struct Edge{
int v,w;
Edge(int v,int w):v(v),w(w){}
};
std::vector<Edge>g[15];
int f[15];
Element e[100005];
int seq[15];
int vis[15];
int pos[15];
int ans = -1;
int dis[1<<10];
void dfs(int p,int n,int m){
if(p==n+1){
for(int i = 1; i <= n; i++){
g[i].clear(), f[i] = 0;
pos[seq[i]] = i;
}
for(int i = 0; i < (1<<n); i++){
int l = n+1, r = -1;
int mask = i;
for(int j = 1; j <= n; j++){
if(mask%2){
int p = pos[j];
if(l>p) l = p;
if(r<p) r = p;
}
mask /= 2;
}
if(l<=n && r>=1 && l<r) g[l].push_back(Edge(r,dis[i]));
}
for(int i = 1; i <= n; i++){
if(f[i]<f[i-1]) f[i] = f[i-1];
for(Edge e: g[i]){
int j = e.v, w = e.w;
if(f[j]<f[i]+w) f[j] = f[i]+w;
}
}
if(ans==-1 || ans>f[n]) ans = f[n];
}
else{
for(int i = 1; i <= n; i++){
if(vis[i]==0){
seq[p] = i;
vis[i] = 1;
dfs(p+1,n,m);
vis[i] = 0;
}
}
}
}
int main(){
int n,m;
scanf("%d%d",&n,&m);
int maxn = -1;
for(int i = 1; i <= n; i++){
scanf("%d",&w[i]);
if(maxn<w[i]) maxn = w[i];
}
int ok = 1;
for(int i = 1; i <= m; i++){
scanf("%d%d",&e[i].l,&e[i].v);
if(e[i].v<maxn) ok = 0;
}
if(!ok){
printf("-1\n");
return 0;
}
for(int i = 0; i < (1<<n); i++){
int sum = 0, mask = i;
for(int j = 1; j <= n; j++){
if(mask%2) sum += w[j];
mask /= 2;
}
dis[i] = 0;
for(int j = 1; j <= m; j++){
if(e[j].v<sum && dis[i]<e[j].l) dis[i] = e[j].l;
}
}
dfs(1,n,m);
printf("%d\n",ans);
return 0;
}
|
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <vector>
#include <map>
#include <cmath>
#include <numeric>
#include<cctype>
#include<deque>
#include<iomanip>
#include<queue>
#include<cstring>
#include<stack>
#include<unordered_map>
#define endl "\n"
#define ll long long
using namespace std;
typedef vector<int> v_c;
typedef vector<v_c>vv_c;
ll gcd(ll m, ll n) {
if (n == 0) {
return m;
}
return gcd(n, m % n);
}
ll lcm(ll m, ll n) {
return (m / gcd(m, n)) * n;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
ll n;
cin >> n;
ll g = n;
for (ll i = 2;i< n;i++) {
g = lcm(g, i);
}
cout << g + 1 << endl;
return 0;
} | #include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); ++i)
#define ALL(x) (x).begin(), (x).end()
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;}
using namespace std;
int main(){
string s; cin >> s;
vector<int> memory(10);
for(int i=0; i<10; ++i){
if(s[i] == 'o') memory[i] = 1;
else if(s[i] == 'x') memory[i] = 0;
else memory[i] = 2;
}
int ans = 0;
for(int i=0; i<10000; ++i){
ostringstream oss;
oss << setfill('0') << setw(4) << i;
string s = oss.str();
bool correct = true;
for(char c: s){
int cint = c -'0';
if(memory[cint] == 0){
correct = false;
break;
}
}
for(int i=0; i<10; ++i){
bool contain = false;
if(memory[i] == 1){
for(char c: s){
if(c - '0' == i) contain = true;
}
if(!contain){
correct = false;
break;
}
}
}
if(correct) ans++;
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef int_fast32_t int32;
typedef int_fast64_t int64;
const int32 inf = 1e9+7;
const int32 MOD = 1000000007;
const int64 llinf = 1e18;
#define YES(n) cout << ((n) ? "YES\n" : "NO\n" )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n" )
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n" )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define all(obj) (obj).begin(),(obj).end()
#define rall(obj) (obj).rbegin(),(obj).rend()
#define fi first
#define se second
#define pb(a) push_back(a)
typedef pair<int32,int32> pii;
typedef pair<int64,int64> pll;
template<class T> inline bool chmax(T& a, T b) {
if (a < b) { a = b; return true; } return false;
}
template<class T> inline bool chmin(T& a, T b) {
if (a > b) { a = b; return true; } return false;
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int64 n,k;
cin >> n >> k;
vector<pll> ab(n);
REP(i,n)cin >> ab[i].fi >> ab[i].se;
sort(all(ab));
int64 cur = 0;
REP(i,n){
if(ab[i].fi - cur <= k){
k -= ab[i].fi - cur;
k += ab[i].se;
cur = ab[i].fi;
}else{
ANS(cur + k);
return 0;
}
}
ANS(cur + k);
return 0;
} | #include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
using namespace std;
int main(void)
{
int n, k;
cin >> n >> k;
map<long, long> mp;
vector<long long> veca;
vector<long long> vecb;
for (int i = 0; i < n; i++)
{
long long a, b;
cin >> a >> b;
mp[a] += b;
}
for (auto i = mp.begin(); i != mp.end(); i++)
{
veca.push_back(i->first);
}
sort(veca.begin(), veca.end());
long long have_money = k;
long long i = 0;
if (have_money > veca[veca.size() - 1])
{
for (long long i = 0; i <= veca.size() - 1; i++)
{
have_money += mp[veca[i]];
}
cout << have_money << endl;
return 0;
}
else
{
while (have_money >= veca[i])
{
have_money += mp[veca[i]];
i++;
}
}
cout << have_money << endl;
} |
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <cassert>
#include <stack>
#include <numeric>
typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;
#define rip(i, n, _s) for (int i = (_s);i < (int)( n ); i++)
#define all(_l) _l.begin(), _l.end()
#define rall(_l) _l.rbegin(), _l.rend()
#define MM << " " <<
template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template<typename T>
inline bool chmax(T &_l, const T b) {
if (_l < b) {
_l = b;
return true;
}
return false;
}
template<typename T>
inline bool chmin(T &_l, const T b) {
if (_l > b) {
_l = b;
return true;
}
return false;
}
# ifdef LOCAL_DEBUG
template<typename T>
void vdeb(const std::vector<T> &bb) {
for (unsigned int i = 0;i < bb.size();i++) {
if (i == bb.size() - 1) std::cout << bb[i];
else std::cout << bb[i] << ' ';
}
std::cout << '\n';
}
template<typename T>
void vdeb(const std::vector<std::vector<T>> &bb) {
for (unsigned int i = 0;i < bb.size();i++) {
std::cout << i << ' ';
vdeb(bb[i]);
}
std::cout << '\n';
}
# endif
using namespace std;
int main() {
int n; cin >> n;
vector<int> a(n);
rip(i,n,0) cin >> a[i];
vector<int> b(n);
rip(i,n,0) cin >> b[i];
vector<int> p(n);
vector<int> q(n);
rip(i,n,0) {
cin >> p[i];
p[i]--;
q[p[i]] = i;
}
vector<Pii> ans(0);
MinHeap<Pii> pq;
rip(i,n,0) {
pq.push({a[i], i});
}
while(!pq.empty()) {
auto now = pq.top(); pq.pop();
if(p[now.second] == now.second) continue;
if(now.first <= b[p[now.second]]) {
cout << -1 << endl;
return 0;
}
int c = q[now.second];
ans.push_back({now.second+1, c+1});
q[p[now.second]] = c;
q[now.second] = now.second;
p[c] = p[now.second];
p[now.second] = now.second;
}
cout << ans.size() << '\n';
rip(i,ans.size(), 0) {
cout << ans[i].first MM ans[i].second << '\n';
}
} | #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()
{
ll i,j,k,n,m;
cin>>n>>m;
vll v(n);
scan(v);
set<ll> s;
mll mp;
f(i,0,n+1)
s.insert(i);
ll ans=INF;
ll l=0,h=0;
while(h<n)
{
if(s.find(v[h])!=s.end())
s.erase(s.find(v[h]));
mp[v[h]]++;
if(h-l+1==m)
{
ans=min(ans,*s.begin());
if(mp[v[l]]==1)
s.insert(v[l]);
mp[v[l]]--;
h++;
l++;
}
else
h++;
}
cout<<ans;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
ll t = 1;
while(t--) {
solve();
}
return 0;
} |
#include <iostream>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
#include <ctime>
#pragma warning(disable:4996)
typedef long long ll;
#define LINF 9223300000000000000
using namespace std;
void solve()
{
int n; cin >> n;
vector<int> a(n), t(n);
int i;
for (i = 0; i < n; i++) cin >> a[i] >> t[i];
int Q; cin >> Q;
vector<ll> x(Q);
for (i = 0; i < Q; i++) cin >> x[i];
ll offs = 0, M = LINF, m = -LINF;
for (i = 0; i < n; i++) {
if (t[i] == 1) offs += a[i];
else if (t[i] == 2) m = max(m, a[i] - offs), M = max(M, m);
else M = min(M, a[i] - offs), m = min(m, M);
}
for (i = 0; i < Q; i++) {
x[i] = min(x[i], M);
x[i] = max(x[i], m);
cout << x[i]+offs << endl;
}
return;
}
int main()
{
solve();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define int long long
using vec_int = vector<int>;
using P = pair<int,int>;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
signed main(){
int N ; cin>>N;
vec_int A(N), B(N); rep(i,N)cin>>A.at(i)>>B.at(i);
int ans = INT_MAX;
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
int temp;
if(i==j){
temp = A.at(i) + B.at(i);
}else{
temp = max(A.at(i), B.at(j));
}
ans = min(temp, ans);
}
}
cout<<ans<<endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(ll i=0;i<(ll)n;i++)
#define dump(x) cerr << "Line " << __LINE__ << ": " << #x << " = " << (x) << "\n";
#define spa << " " <<
#define fi first
#define se second
#define ALL(a) (a).begin(),(a).end()
#define ALLR(a) (a).rbegin(),(a).rend()
using ld = long double;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;
template<typename T> using V = vector<T>;
template<typename T> using P = pair<T, T>;
template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){os << "(" << v.first << ", " << v.second << ")"; return os;}
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<vector<T>> &v){ for(auto &e : v){os << e << "\n";} return os;}
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template <class T> void UNIQUE(vector<T> &x) {sort(ALL(x));x.erase(unique(ALL(x)), x.end());}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
void fail() { cout << -1 << '\n'; exit(0); }
inline int popcount(const int x) { return __builtin_popcount(x); }
inline int popcount(const ll x) { return __builtin_popcountll(x); }
template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<"\n";}};
template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0];
for(ll i=1;i<n;i++)cerr spa v[i];
cerr<<"\n";};
const ll INF = (1ll<<62);
// const ld EPS = 1e-10;
// const ld PI = acos(-1.0);
const ll mod = (int)1e9 + 7;
//const ll mod = 998244353;
int main(){
ll N;
string S, T;
cin >> N >> S >> T;
ll cntS=0, cntT=0;
REP(i, N) cntS += (S[i] == '1');
REP(i, N) cntT += (T[i] == '1');
if(cntS != cntT){
cout << -1 << endl;
return 0;
}
V<ll> posS, posT;
REP(i, N) if(S[i] == '0') posS.push_back(i);
REP(i, N) if(T[i] == '0') posT.push_back(i);
ll sz = posS.size();
ll res = 0;
REP(i, sz){
if(posS[i] != posT[i]) res++;
}
cout << res << endl;
return 0;
} | // Author: param3435
#include <bits/stdc++.h>
#pragma GCC optimize ("-O2")
using namespace std;
#define LL long long
#define LD long double
#define divisor 1000000007
#define INFP LLONG_MAX
#define INFN LLONG_MIN
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mp make_pair
#define pLL pair<LL, LL>
#define loop(i,a,b) for(LL i = a; i < b; i++)
#define loopd(i,a,b) for(LL i = a; i > b; i--)
#define numberOfOnes(n) __builtin_popcountll(n)
#define parity(n) __builtin_parityll(n) // = 1 when numberOfOnes(n) is odd
#define leadingZeros(n) __builtin_clzll(n)
#define trailingZeros(n) __builtin_ctzll(n)
#define gcd(first, second) __gcd(first, second)
#define debug(x) cout << #x << " = " << x << '\n'
#define all(x) (x).begin(), (x).end()
#define sz(x) (LL)(x).size()
#define sum(x) (accumulate((x).begin(), (x).end(), 0LL))
#define minE(x) (*min_element((x).begin(), (x).end()))
#define maxE(x) (*max_element((x).begin(), (x).end()))
#define minI(x) ( min_element((x).begin(), (x).end()) - (x).begin())
#define maxI(x) ( max_element((x).begin(), (x).end()) - (x).begin())
#define lB(x, y) ( lower_bound((x).begin(), (x).end(), (y)) - (x).begin())
#define uB(x, y) ( upper_bound((x).begin(), (x).end(), (y)) - (x).begin())
#define FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
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> 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;}
void solve() {
LL A, B, C;
cin >> A >> B >> C;
if (A == B || (abs(A) == abs(B) && C % 2 == 0)) {
cout << '=';
}
else if (C % 2 == 0) {
cout << ((pow(A, 2) > pow(B, 2)) ? '>' : '<');
}
else
cout << ((A > B) ? '>' : '<');
return;
}
int main() {
FastIO;
LL T = 1;
// cin >> T;
loop(i, 0, T - 1) {
solve();
cout << '\n';
}
solve();
return 0;
} |
#include <cstdlib>
#include<iostream>
#include<string>
#include<cmath>
#include<vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
void GP(){
int N;
cin >> N;
int x[N],y[N];
rep(i,N){
cin >> x[i] >> y[i];
}
int ans=0;
rep(i,N){
rep(j,i){
double P = abs(y[i]-y[j])/((double)abs(x[i]-x[j]));
if(abs(P)<=1){
ans++;
}
}
}
cout << ans << endl;
}
int main(){
GP();
return 0;
} | #include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <cmath>
#include <deque>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <functional>
#include <iomanip>
#include <cstdint>
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep3(i,a,b) for(int i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tpiii tuple<int,int,int>
#define mp make_pair
#define mt make_tuple
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector
#define vi vec<int>
#define vl vec<ll>
#define vvi vec<vi>
#define vvl vec<vl>
#define vpii vec<pii>
#define vpll vec<pll>
#define vbl vec<bool>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
string stin(){string s;cin>>s;return s;}
void drop(string s){cout<<s<<endl; exit(0);}
void drop(int x){cout<<x<<endl; exit(0);}
void drop(ll x){cout<<x<<endl; exit(0);}
void drop(double x){cout<<x<<endl; exit(0);}
int main(){
int n=in();
vi x(n),y(n);
rep(i,n){
x[i]=in();
y[i]=in();
}
int cnt=0;
rep(i,n)rep2(j,i+1,n-1)if(abs(x[i]-x[j])>=abs(y[i]-y[j]))cnt++;
drop(cnt);
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef pair<int,int> pi;
typedef pair<lld,lld> pl;
typedef pair<int,lld> pil;
typedef pair<lld,int> pli;
typedef vector<int> vit;
typedef vector<vit> vitt;
typedef vector<lld> vlt;
typedef vector<vlt> vltt;
typedef vector<pi> vpit;
typedef vector<vpit> vpitt;
typedef long double ld;
#define x first
#define y second
#define pb push_back
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define mk(a,b) make_pair(a,b)
bool isrange(int y,int x,int n,int m){
if(0<=y&&y<n&&0<=x&&x<m) return true;
return false;
}
int dy[4] = {1,0,-1,0},dx[4]={0,1,0,-1},ddy[8] = {1,0,-1,0,1,1,-1,-1},ddx[8] = {0,1,0,-1,1,-1,1,-1};
const int MAX = 202020;
int dp[26];
void solve(int tc){
string s;
cin >> s;
lld ans = 0;
char rr = '?';
for(int e=sz(s)-1;e>=0;e--){
if(s[e]==s[e+1]&&e+1<sz(s)){
ans += sz(s) - 1 - e - dp[s[e]-'a'];
memset(dp,0,sizeof(dp));
dp[s[e]-'a'] = sz(s) - e;
}else{
dp[s[e]-'a']++;
}
}
printf("%lld\n",ans);
}
int main(void){
/*
ios_base :: sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
*/
int tc = 1;
/*
cin >> tc;
*/
for(int test_number=1;test_number<=tc;test_number++){
solve(test_number);
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main(){
/* long double n;
cin>>n;
long long unsigned t = n;
cout<<t;
stringstream ss;
ss<<n;
string s;
ss>>s;
long long a = (s.size());
long long x = 0;
while(x<a){
if(s[x]=='.'){
break;
}
cout<<s[x];
x++;
}
//cout<<s;*/
string s;
cin>>s;
long long a = (s.size());
long long x = 0;
while(x<a){
if(s[x]=='.'){
break;
}
cout<<s[x];
x++;
}
} |
#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
int main(){
long S, P, M;
int N = 0;
cin >> S >> P;
for(M = 1; M <= sqrt(P); M++){
if(P%M == 0){
if(P/M + M == S){
N = 1;
break;
}
}
}
if(N == 1) cout << "Yes" << endl;
else cout << "No" << endl;
return 0;
} | // C++ includes
#include <bits/stdc++.h>
// 俳句
using namespace std;
// alias templates
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
// alias declaration
using ll = long long;
using str = string;
using vll = V<ll>;
using vvll = V<vll>;
using vs = V<str>;
// loops
#define FOR(i, a, b) for (ll i = (a); i <= (ll)(b); i++) // [a,b]
#define rFOR(i, a, b) for (ll i = (b); i >= (ll)(a); i--) // [b,a]
#define REP(i, a) FOR((i), 0, (ll)(a)-1) // [0,a-1]
// for debug
#define dbg(a) cerr << " " << (#a) << ": " << (a) << "\n";
// procon common constants
const ll MOD_BIG = 1e9 + 7;
bool sol(void){
ll s,p;
cin >> s >> p;
ll start = 1, end = (s+1) / 2;
FOR(i,1,sqrt<ll>(p)){
if(i*(s-i) == p){
return true;
}
}
return false;
}
int main(void){
if(sol()){
cout << "Yes" << endl;
}else{
cout << "No" << endl;
}
} |
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define Pii pair<int,int>
#define Pll pair<long long,long long>
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
//vector<vector<ll>> dp(n,vector<ll>(n))
//2-dim:vector<vector<Type>> vv(n, vector<Type>(m, d));
//3-dim:vector<vector<vector<Type>>> vvv(n, vector<vector<Type>>(m, vector<Type>(l, d)));
using namespace std;
signed main()
{
std::cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
int n; cin >> n;
ll ans0=1,ans1=1;
rep(i,n){
string s; cin >> s;
if(s=="OR"){
ans1 = ans0+ans1*2;
}else{
ans0 = ans0*2+ans1;
}
}
cout << ans1 << endl;
return 0;
}
// g++ main.cpp -o a.out && ./a.out | #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
using namespace std;
long long dp[65][2];
int main()
{
dp[0][1] = 1;
dp[0][0] = 1;
int int_n;
scanf("%d",&int_n);
for(int i = 1; i <= int_n; i++)
{
string s;
cin >> s;
if(s == "AND"){
dp[i][0] = dp[i-1][1] * 1 + dp[i-1][0] * 2;
dp[i][1] = dp[i-1][1] * 1 + dp[i-1][0] * 0;
}
else{
dp[i][0] = dp[i-1][1] * 0 + dp[i-1][0] * 1;
dp[i][1] = dp[i-1][1] * 2 + dp[i-1][0] * 1;
}
}
printf("%lld\n",dp[int_n][1]);
}
//系统提示:哔哩哔哩直播内容及互动评论须严格遵守直播规范,
//严禁传播违法违规、低俗血暴、吸烟酗酒、造谣诈骗等不良有害信息。
//如有违规,平台将进行封禁直至永久封停账号哦!注意理性打赏,
//严禁未成年人直播或打赏。请勿轻信平台上各类广告信息,谨防上当受骗。
|
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
# define rep(i,a,b) for(int i=(a); i<=(b); ++i)
# define drep(i,a,b) for(int i=(a); i>=(b); --i)
typedef long long int_;
inline int readint(){
int a = 0; char c = getchar(), f = 1;
for(; c<'0'||c>'9'; c=getchar())
if(c == '-') f = -f;
for(; '0'<=c&&c<='9'; c=getchar())
a = (a<<3)+(a<<1)+(c^48);
return a*f;
}
const int MaxN = 200005;
vector<int> G[MaxN];
int dep[MaxN], son[MaxN];
int heit[MaxN];
void getInfo(int x){
heit[x] = son[x] = 0;
for(int y : G[x]){
dep[y] = dep[x]+1;
getInfo(y);
if(heit[y] > heit[x]){
heit[x] = heit[y];
son[x] = y;
}
}
++ heit[x];
}
struct Query{
int d, id;
};
vector<Query> ask[MaxN];
int ans[MaxN]; // get ans
int tmp[MaxN], *dp[MaxN];
void dfs(int x){
int *now = dp[x]+heit[x];
if(son[x]){
dp[son[x]] = dp[x]+1;
dfs(son[x]);
}
for(int y : G[x])
if(y != son[x]){
dp[y] = now; dfs(y);
for(int j=0; j<heit[y]; ++j)
dp[x][j+1] += dp[y][j];
now += heit[y]; // leave them
}
dp[x][0] = 1; // itself
while(!ask[x].empty()){
int p = ask[x].back().id;
int v = ask[x].back().d;
ask[x].pop_back();
if(v >= dep[x] && v < dep[x]+heit[x])
ans[p] = dp[x][v-dep[x]];
else ans[p] = 0;
}
}
int main(){
int n = readint();
for(int i=2,a; i<=n; ++i){
a = readint();
G[a].push_back(i);
}
int q = readint();
for(int i=1; i<=q; ++i){
int x = readint();
ask[x].push_back(Query());
ask[x].back().id = i;
ask[x].back().d = readint();
}
getInfo(1); dp[1] = tmp; dfs(1);
rep(i,1,q) printf("%d\n",ans[i]);
return 0;
} | #include<bits/stdc++.h>
#define f first
#define s second
#define int long long
using namespace std;
const int N=3e3+5,mod=1e9+7;
int t,a[N],pref[N],dp[N][N],n;
vector<int>c[N];
main(){
cin>>n;
for(int i=1;i<=n;i++){
cin >> a[i];
pref[i] = pref[i-1] + a[i] ;
}
dp[0][0] = 1;
int ans = 0;
for(int i=1;i<=n;i++) {
for(int j=0;j<=n;j++) {
c[pref[j]%i].push_back(j);
}
for(int j=0;j<i;j++) {
int p = 0;
for(int k=0;k<c[j].size();k++) {
dp[c[j][k]][i] = p;
p += dp[c[j][k]][i-1];
if(p>=mod) p-=mod;
}
c[j].clear();
}
ans += dp[n][i];
if(ans>=mod) ans -= mod;
}
cout<<ans;
}
|
#include "bits/stdc++.h"
#define YES "YES"
#define NO "NO"
#define Yes "Yes"
#define No "No"
#define DEFAULT LL ans=solve();\
if(ans==NONE){\
}else{\
cout << ans << endl;\
}
#define YESNO three(solve(),(OUT(YES),1),(OUT(NO),0))
#define YesNo three(solve(),OUT(Yes),OUT(No))
#define ECHO OUT(solve())
#define three(A,B,C) ((A)?(B):(C))
#define FOR(i,a,b) for(LL i=(a);i< (LL)(b);i++)
#define EFOR(i,a,b) for(LL i=(a);i<=(LL)(b);i++)
#define RFOR(i,a,b) for(LL i=(b-1);i>=(LL)(a);i--)
#define REP(i,b) FOR(i,zero,b)
#define rep REP
#define EREP(i,b) EFOR(i,zero,b)
#define RREP(i,b) RFOR(i,zero,b)
#define ALL(c) c.begin(),c.end()
#define UNIQUE(c) sort(ALL(c));c.erase(unique(ALL(c)),c.end())
#define MAX(c) (*max_element(ALL(c)))
#define MIN(c) (*min_element(ALL(c)))
#define MP make_pair
#define FI first
#define SE second
#define SI(x) (LL(x.size()))
#define PB push_back
#define DEBUG(a) OUT(a)
#define DEBUG2(a,b) OUT2(a,b)
#define cat cout << __LINE__ << endl
#define OUT(a) cout << (a) << endl
#define OUT2(a,b) cout << (a) <<" "<<(b) << endl
#define zero 0LL
#define all ALL
#define pb emplace_back
#define eb pb
#define int long long
using namespace std;
template<typename T> inline void maximize(T &a, T b) { a = max(a, b); }
template<typename T> inline void minimize(T &a, T b) { a = min(a, b); }
template<typename T> inline bool middle(T a, T b, T c) { return b <= a && a <= c; }
template<class T> inline bool MX(T &l, const T &r) { return l < r ? l = r, 1 : 0; }
template<class T> inline bool MN(T &l, const T &r) { return l > r ? l = r, 1 : 0; }
typedef int LL;
typedef double ld;
typedef int ut;
typedef vector<ut> VI;
typedef vector<VI> VII;
typedef pair<ut, ut> pr;
typedef pair<ut, pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef tuple<int, int, int, int> tapu;
typedef vector<tapu> Vtapu;
typedef priority_queue<pr, Vpr > PQ;
inline void outputVI(VI x) { REP(i, SI(x)) { cout << three(i, " ", "") << x[i]; }OUT(""); }
const int SIZE1 = 5e5 + 1000;
const int SIZE2 = 5010;
const int SIZE3 = 430;
const int SIZE = 300;
const int MAPSIZE = 40;
const LL p998 = 998244353;
const LL p107 = 1000000007;
const LL p = p107;
const LL INF = 1LL << 60;
const long double EPS = 1e-7;
const LL NONE=-2;
#define endl "\n"
ut N, M,K, Q, D, H, W;
VI edges[SIZE];
LL vals[SIZE], answer = zero;
//LL A[SIZE],B[SIZE],C[SIZE];
LL pai[SIZE];
bool reached[SIZE][SIZE];
bool dp[SIZE][SIZE];
bool isA[SIZE];
bool isB[SIZE];
bool able(int a,int b){
if(a>=b) return false;
if((b-a)%2) return false;
if(reached[a][b]) return dp[a][b];
reached[a][b]=true;
FOR(i,a,b){
if(able(a,i) and able(i,b)) dp[a][b]|=true;
}
if(dp[a][b]) return true;
LL len=(b-a)/2;
FOR(i,a,a+len){
if(isB[i]) return false;
if(pai[i]!=-1 and pai[i]!=i+len) return false;
}
FOR(i,a+len,b){
if(isA[i]) return false;
if(pai[i]!=-1 and pai[i]!=i-len) return false;
if(isB[i] and isA[i-len] and pai[i]==-1) return false;
}
return dp[a][b]=true;
}
LL counts[SIZE];
LL solve(){
cin >> N;
REP(i,2*N+1) pai[i]=-1;
REP(i,N){
LL a,b;
cin >>a >> b;
if(a!=-1 and b!=-1){
if(b<a) return false;
pai[a]=b;
pai[b]=a;
}
if(b!=-1){
isB[b]=true;
counts[b]++;
}
if(a!=-1){
counts[a]++;
isA[a]=true;
}
}
REP(i,2*N+1) if(counts[i]>=2) return false;
return able(1,2*N+1);
return NONE;
}
signed main() {
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(10);
LL T=1;
REP(i,T){
YesNo;
}
// YesNo;
// YESNO;
// three(solve(),OUT("First"),OUT("Second"));
//cin >> N;
return 0;
}
| #include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int MAXN = 1e2 + 5;
int a[MAXN], b[MAXN];
int main(void)
{
int n;
scanf("%d",&n);
for(int i=1; i<=n; ++i) scanf("%d%d",&a[i],&b[i]);
static int seq[MAXN*2];
static bool has[MAXN];
for(int i=1; i<=n; ++i)
{
if(a[i] != -1)
{
if(seq[a[i]]) return printf("No"), 0;
seq[a[i]] = i;
}
if(b[i] != -1)
{
if(seq[b[i]]) return printf("No"), 0;
seq[b[i]] = -i;
}
if(a[i] != -1 && b[i] != -1)
{
if(a[i] > b[i]) return printf("No"), 0;
has[i] = 1;
}
}
static bool can[MAXN*2];
can[0] = 1;
for(int i=1; i<=n*2; ++i)
{
for(int j=i&1; j<i; j+=2) if(can[j])
{
int len = (i-j)/2;
bool flag = 1;
for(int k=1; k<=len && flag; ++k)
{
int x = seq[j+k], y = seq[j+len+k];
if(!x && !y) continue;
if(x<0){ flag = 0; break;}
if(y>0){ flag = 0; break;}
if(x && y && x != -y){ flag = 0; break;}
if(x && !y && has[x]){ flag = 0; break;}
if(!x && y && has[-y]){ flag = 0; break;}
}
if(flag){ can[i] = 1; break;}
}
}
if(can[n*2]) printf("Yes");
else printf("No");
return 0;
} |
/*n=2:1,3, 3,1
n=3:1,3,6,7, 6,3,1
n=4:1,3,6,10,12, 12,10,6,3,1
n=5:1,3,6,10,15,18,19, 18,15,10,6,3,1
n=6:1,3,6,10,15,21,25,27, 27,25,21,15,10,6,3,1
n=7:1,3,6,10,15,21,28,33,36,37, 36,33,28,21,15,10,6,3,1
n=8:1,3,6,10,15,21,28,36,42,46,48, 48,46,42,36,28,21,15,10,6,3,1
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=3e6+5;
int n;
ll k;
ll sum[maxn],temp[maxn];
/*int main(){
int n;
map<int,int>res;
while(cin>>n){
res.clear();
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++)
for(int k=1;k<=n;k++)
res[i+k+j]++;
}
for(int i=3;i<=3*n;i++){
if(i!=3) cout<<",";
cout<<res[i];
}
cout<<"\n";
}
return 0;
}*/
void init_sum(int n){ //预处理和为sum时的三元数组的数量
ll pos=3;
for(int j=1;j<=n;j++){
sum[pos]=sum[pos-1]+j;
pos++;
}
for(int j=n-2;j>0;j-=2){
sum[pos]=sum[pos-1]+j;
pos++;
}
if(n&1){
int k=pos-2,l=pos;
for(int i=pos;i<=3*n;i++){
sum[i]=sum[k-(i-l)];
}
}
else{
int k=pos-1,l=pos;
for(int i=pos;i<=3*n;i++){
sum[i]=sum[k-(i-l)];
}
}
}
void init_temp(int n){
for(int i=2;i<=n+1;i++)
temp[i]=i-1;
for(int i=n+2;i<=2*n;i++)
temp[i]=temp[i-1]-1;
}
int main(){
cin>>n>>k;
init_sum(n);
init_temp(n);
ll ans=3;
while(k>sum[ans]){
k-=sum[ans];
ans++; //k<=sum[ans] 在sum=ans时可以求得其中的一个三元数组(i,j,k) 为第cnt个三元数组
} //i+j+k=ans
//cout<<ans<<endl;
for(int i=ans-2*n;i<=ans-2;i++){ //枚举i的值
if(i<1) continue;
ll t1=ans-i; //j+k
if(k>temp[t1]){ //则第一个数大于i
k-=temp[t1];
}
else{
cout<<i;
int x,y; //x+y=t1
if(t1>n+1){
x=t1-n,y=n; //x:t1-n -> n y:n -> t1-n
}
else{
x=1,y=t1-1; //x:1 -> t1-1 y:t1-1 -> 1
}
//cout<<x<<" "<<y<<endl;
k--; //x y 在第一种情况下
while(k){
x++,y--; //从小到大枚举情况 直到k=0
k--;
}
cout<<" "<<x<<" "<<y<<endl;
break;
}
}
return 0;
}
//i+j+k=3*n
//i [1,n]
//j+k [2,2*n]
//2->n+1 cnt:1,2,……,n
//n+2->2*n cnt:n-1,n-2,……,1 | #include <bits/stdc++.h>
using namespace std;
const int MN = 200 + 5;
int dp[MN][MN][4], a[MN];
array<int,3> from[MN][MN][4];
long long f(int x) {return (long long)x * (x+1) / 2;}
int main () {
int n; long long k,sofar = 0;
scanf ("%d %lld",&n,&k);
for (int c = 0; c <= 3 * (n-1); c++) {
int low = max(0,c - (n - 1)), high = min(c,2*(n-1));
long long ret = 0;
if (n-1 <= low) ret += (long long)(n-1) * (high-low+1);
else if (high <= n-1) ret += f(high) - f(low-1);
else ret += (long long)(n-1) * (high-(n-1)) + f(n-1)-f(low-1);
low -= (n-1); high -= (n-1);
if (high <= 0) ret -= 0;
else if (0 <= low) ret -= f(high) - f(low-1);
else ret -= f(high);
ret += high - low + 1;
long long old = sofar;
sofar += ret;
if (sofar >= k) {
long long go = 0; low += (n-1); high += (n-1);
for (int get = high; get >= low; get--) {
int goFirst = c - get;
long long ree = go + old;
go += min(c-goFirst,n-1) - max(c-goFirst+1-n,0) + 1;
if (go + old >= k) {
int togo = c - goFirst; long long add = 0;
for (int nxt = 0; nxt < n; nxt++) if (nxt <= togo && 0 <= togo-nxt && togo-nxt < n) {
++add;
if (ree + add >= k) {
printf ("%d %d %d\n",goFirst+1,1+nxt,1+c-goFirst-nxt);
return 0;
}
}
return 0;
}
}
return 0;
}
}
return 0;
}
|
#include<iostream>
using namespace std;
int main()
{
int n, w;
int count;
cin >> n >> w;
count = n / w;
cout << count << endl;
return 0;
} | #include<bits/stdc++.h>
#define ll long long int
using namespace std;
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define endl "\n"
#define maxpq priority_queue<ll>
#define minpq priority_queue<ll, vector<ll>, greater<ll> >
#define vi vector<ll>
#define pii pair<ll, ll>
#define vii vector<pii>
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
ll MOD =1000000007;
#define INT_MAXI 9000000000000000000
#define INT_MINI -9000000000000000000
ll max(ll a, ll b) {if (a > b) return a; else return b;}
ll min(ll a, ll b) {if (a < b) return a; else return b;}
const int dx[4] = { -1, 1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
int XX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int YY[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
int main()
{
fio;
ll t,i,j,x,l,r,k,y,val,n,w,m,a,b,c;
cin>>n>>w;
cout<<n/w;
} |
#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>;
class RangeMexQuery {
private:
int n, m;
vector<array<int, 3> > ptr;
vector<int> arr, st;
int update(const int prv, const int id, const int val, const int l,
const int r) {
const int cur = (int)ptr.size();
ptr.push_back({0, 0, id});
if (r - l == 1) return cur;
const int mid = (l + r) / 2;
if (val < mid) {
const int res = update(ptr[prv][0], id, val, l, mid);
ptr[cur][0] = res, ptr[cur][1] = ptr[prv][1];
} else {
const int res = update(ptr[prv][1], id, val, mid, r);
ptr[cur][0] = ptr[prv][0], ptr[cur][1] = res;
}
ptr[cur][2] = min(ptr[ptr[cur][0]][2], ptr[ptr[cur][1]][2]);
return cur;
}
void preprocessing(const vector<int>& vec) {
arr[0] = 0;
for (int i = 0; i < n; ++i)
arr[2 * i + 1] = vec[i], arr[2 * i + 2] = vec[i] + 1;
sort(arr.begin(), arr.end());
arr.erase(unique(arr.begin(), arr.end()), arr.end());
m = (int)arr.size(), st[0] = 0, ptr.push_back({0, 0, -1});
for (int i = 0; i < n; ++i) {
const int val = (int)(lower_bound(arr.begin(), arr.end(), vec[i]) -
arr.begin());
st[i + 1] = update(st[i], i, val, 0, m);
}
}
int query(const int cur, const int cri, const int l, const int r) {
if (cur == 0 || r - l == 1) return arr[l];
const int mid = (l + r) / 2;
if (ptr[ptr[cur][0]][2] < cri)
return query(ptr[cur][0], cri, l, mid);
else
return query(ptr[cur][1], cri, mid, r);
}
public:
RangeMexQuery(const vector<int>& vec)
: n((int)vec.size()), arr(2 * n + 1), st(n + 1) {
preprocessing(vec);
}
int query(const int l, const int r) { return query(st[r], l, 0, m); }
};
int main() {
int n, m;
cin >> n >> m;
vector<int> a(n);
rep(i, n) cin >> a[i];
RangeMexQuery rmq(a);
int ans = 10e8;
for (int i = 0; i + m - 1 < n; i++) {
ans = min(ans, rmq.query(i, i + m));
}
cout << ans << endl;
} | #include<bits/stdc++.h>
using namespace std;
#define fi(a,b) for(int i=a;i<b;i++)
#define fj(a,b) for(int j=a;j<b;j++)
#define ff first
#define ss second
#define ll long long
#define ld long double
#define ull unsigned long long
#define bp(x) __builtin_popcount(x)
#define pr(x) for(auto it: x) cout<<it<<" "; cout<<endl;
#define getMax(x) max_element(x.begin(),x.end())
#define getMin(x) min_element(x.begin(),x.end())
#define endl "\n"
typedef vector<int> vi;
typedef vector< pair<int,int> > vii;
typedef vector<long long> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector< pair<ll,ll> > vll;
//int dx[]={1,0,-1,0};
//int dy[]={0,1,0,-1};
//int dx[]={-1,0,1,1,1,0,-1,-1};
//int dy[]={-1,-1,-1,0,1,1,1,0};
void nikal_pehli_fursat_mai(){
ll n, m;
cin>>n>>m;
vl v(n), ans;
fi(0, n) cin>>v[i];
set<int>st;
multiset<int>st1;
fi(0, m) st1.insert(v[i]);
fi(0, m+1){
if(st1.find(i)==st1.end()) st.insert(i);
}
ans.push_back(*st.begin());
int i=0, j=m;
while(j<n){
st1.erase(st1.find(v[i]));
if(st1.find(v[i])==st1.end()) st.insert(v[i]);
i++;
st1.insert(v[j]);
if(st.find(v[j])!=st.end()){
st.erase(st.find(v[j]));
}
j++;
ans.push_back(*st.begin());
}
// pr(ans);
cout<<(*getMin(ans))<<endl;
}
int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios::sync_with_stdio(0);
cin.tie(0);
int tc=1;
// cin>>tc;
while(tc--){
nikal_pehli_fursat_mai();
}
}
|
#include<cstdio>
#define F(i,l,r) for(int i=l,i##_end=r;i<i##_end;++i)
using namespace std;
const int N=2e5+5;
template<typename T>void read(T &x)
{
bool neg=false;
unsigned char c=getchar();
for(;(c^48)>9;c=getchar())if(c=='-')neg=true;
for(x=0;(c^48)<10;c=getchar())x=(x<<3)+(x<<1)+(c^48);
if(neg)x=-x;
}
int n,f[N][8],b=1;
char s[N],x[N];
int main()
{
read(n);scanf("%s%s",s,x);
F(i,0,n/2)s[i]^=s[n-1-i]^=s[i]^=s[n-1-i];
F(i,0,n/2)x[i]^=x[n-1-i]^=x[i]^=x[n-1-i];
f[0][0]=1;
F(i,0,n)
{
int t=(s[i]-'0')*b%7;
if(x[i]=='A')F(j,0,7)f[i+1][j]=f[i][j]&&f[i][(j+t)%7];
else F(j,0,7)f[i+1][j]=f[i][j]||f[i][(j+t)%7];
b=b*10%7;
}
puts(f[n][0]?"Takahashi":"Aoki");
return 0;
}
| #include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const long long mod = 1000000007;
// const long long mod = 998244353;
int main(void){
int t;
cin >> t;
while(t--){
long long n, a, b;
cin >> n >> a >> b;
if(a+b > n){
cout << 0 << endl;
continue;
}
long long c = n - a - b + 1;
long long d = c*(c+1)/2 % mod;
long long ans = d;
ans *= (n-a+1) * (n-b+1) % mod;
ans %= mod;
// cout << ans << endl;
ans += mod - (d*d%mod);
cout << ans*4 % mod << endl;
}
}
|
#include <bits/stdc++.h>
#define arr array
#define pb push_back
#define fs first
#define sc second
#define eb emplace_back
#define vt vector
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
using namespace std;
typedef long long ll;
const int maxn=2e5;
const int MAXINT=1e9;
const ll MAXLL=1e18;
void solve(){
int n;
cin >> n;
n*=2;
vt<arr<int, 3>> a(n);
rep(i, 0, n) cin >> a[i][0], a[i][1]=i;
sort(a.begin(), a.end(), [&](arr<int, 3> x, arr<int, 3> y){
return x[0]<y[0];
});
rep(i, 0, n/2) a[i][2]=1;
rep(i, n/2, n) a[i][2]=0;
sort(a.begin(), a.end(), [&](arr<int, 3> x, arr<int, 3> y){
return x[1]<y[1];
});
//rep(i, 0, n) cout << a[i][2] << " "; cout << endl;
vt<int> st;
vt<char> ans(n);
rep(i, 0, n){
if (!st.empty()&&a[i][2]!=a[st.back()][2]) ans[st.back()]='(', ans[i]=')', st.pop_back();
else st.pb(i);
}
rep(i, 0, n) cout << ans[i]; cout << endl;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t=1;
while(t--){
solve();
}
} | #include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
#define debug(x) cerr << #x << '=' << x <<'\n'
#define rep(i, b, n) for (int i = b; i <= n; i++)
const int N = 1123456;
int n, m, a, b;
char s[N];
int main(void) {
scanf("%s", s + 1);
int len = strlen(s + 1);
rep (i, 2, len) {
if (s[i] != s[i - 1]) {
puts("Lost");
return 0;
}
}
puts("Won");
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int maxN = 100000, N, M;
vector<vector<pair<int,int>>> G(maxN,vector<pair<int,int>>(0));
vector<int> A(maxN,-1);
void dfs(int u, int pre, int e){
if(G[pre][e].second == A[pre]){
A[u] = G[pre][e].second + 1;
if(A[u]>N) A[u] = 1;
}
else A[u] = G[pre][e].second;
for(int i=0;i<G[u].size();i++){
pair<int,int> p = G[u][i];
if(A[p.first]!=-1) continue;
dfs(p.first,u,i);
}
return;
}
int main(){
cin >> N >> M;
for(int i=0;i<M;i++){
int u,v,c;
cin >> u >> v >> c;
u--;v--;
G[u].push_back(make_pair(v,c));
G[v].push_back(make_pair(u,c));
}
dfs(0,G[0][0].first,0);
for(int i=0;i<N;i++) cout << A[i] << endl;
return 0;
}
| #include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>
#include<math.h>
#include<stack>
#include<set>
#include<map>
#include<ctime>
#include<cstdlib>
#include<fstream>
#define INF 1001001001001001001
#define MAX 50000001
#define rep(i,n,m) for(int i=n;i<m;i++)
using namespace std;
int main() {
int n, m, q;
cin >> n >> m >> q;
vector<pair<int, int>>budget;
int x, y;
rep(i, 0, n) {
cin >> x >> y;
budget.push_back({ x,y });
}
sort(budget.begin(), budget.end());
vector<int>box(m + 1, 0);
rep(i, 1, m + 1)cin >> box[i];
long long ans;
vector<long long>A;
rep(i, 0, q) {
ans = 0;
cin >> x >> y;
vector<int>ibox;
rep(i, 1, x)ibox.push_back(box[i]);
rep(i, y + 1, m + 1)ibox.push_back(box[i]);
sort(ibox.begin(), ibox.end());
// cout << "done" << endl;
int a = 0;
vector<int>now;
rep(j, 0, ibox.size()) {
while (a < n && budget[a].first <= ibox[j]) {
now.push_back(budget[a].second);
a++;
}
sort(now.rbegin(), now.rend());
if (!now.empty()) {
ans += now[0];
now[0] = 0;
}
}
A.push_back(ans);
}
rep(i, 0, A.size())cout << A[i] << endl;
} |
/*Allah Vorosha*/
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define pb push_back
#define n_p next_permutation
#define p_p prev_permutation
#define in insert
#define rev reverse
#define pf push_front
#define pob pop_back
#define uniq(v) v.resize(distance(v.begin(),unique(v.begin(),v.end())))
#define all(x) (x).begin(),(x).end()
#define pof pop_front
#define ios ios_base::sync_with_stdio(0);cin.tie();cout.tie();
#define scn scanf
#define prt printf
#define rep(i, a, n) for(int i = a; i < n; i++)
#define mod 1000000007
#define yes cout << "YES\n"
#define no cout << "NO\n";
#define take for(auto &it : a) cin >> it;
#define out cout << a << "\n";
#define l_b lower_bound
#define u_b upper_bound
#define Max 100005
template<typename T> T mymax(T x, T y) {
return (x > y ? x : y);
}
using namespace std;
const int N = 1e7 + 5;
void solve() {
int n;
string s;
cin >> n >> s;
vector<int> pre(n, 0);
ll ans = 0;
for(int i = 0; i < n; i++) {
int g = 0, a = 0;
for(int j = i; j < n; j++) {
if(s[j] == 'G') g++;
if(s[j] == 'C') g--;
if(s[j] == 'A') a++;
if(s[j] == 'T') a--;
if(!g && !a) {
pre[j] = (i == 0 ? 0 : pre[i - 1]) + 1;
break;
}
}
}
for(int i = 0; i < n; i++) {
ans += pre[i];
}
cout << ans << '\n';
}
int main() {
/*int tc;
scanf("%d", &tc);
while(tc--)*/
solve();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<(n);i++)
using ll = long long;
const ll INF = 1e9+7;
const ll mod=1000000007;
using P = pair<ll, ll>;
int main(){
int n;
string s;
cin >> n >> s;
ll ans =0;
for(int i=0; i<n; i++){
map<char,int> ma;
for(int j=0; j+i<=n-1; j++){
ma[s[i+j]]++;
if(ma['A']==ma['T'] & ma['C']==ma['G']) ans++;
}
}
cout << ans << endl;
} |
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define drep(i,j,n) for(int i=0;i<(int)(n-1);i++)for(int j=i+1;j<(int)(n);j++)
#define trep(i,j,k,n) for(int i=0;i<(int)(n-2);i++)for(int j=i+1;j<(int)(n-1);j++)for(int k=j+1;k<(int)(n);k++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yes(ans) if(ans)printf("yes\n");else printf("no\n")
#define Yes(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YES(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector1d(type,name,...) vector<type>name(__VA_ARGS__)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define vector3d(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
const int MOD2=998244353;
const int INF=1<<30;
const ll INF2=(ll)1<<60;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T,class L>void scan(pair<T, L>& p){scan(p.first);scan(p.second);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T,class L>void print(const pair<T, L>& p){print(p.first);putchar(' ');print(p.second);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll updivide(ll a,ll b){if(a%b==0) return a/b;else return (a/b)+1;}
template<class T> void chmax(T &a,const T b){if(b>a)a=b;}
template<class T> void chmin(T &a,const T b){if(b<a)a=b;}
int main(){
INT(n,k);
string s;
cin>>s;
auto ope=[&](char a,char b){
if(a=='R'&&b=='R')return 'R';
if(a=='R'&&b=='S')return 'R';
if(a=='R'&&b=='P')return 'P';
if(a=='S'&&b=='R')return 'R';
if(a=='S'&&b=='S')return 'S';
if(a=='S'&&b=='P')return 'S';
if(a=='P'&&b=='R')return 'P';
if(a=='P'&&b=='S')return 'S';
if(a=='P'&&b=='P')return 'P';
};
string t;
while(k--){
t=s+s;
for(int i=0;i<n;i++)s[i]=ope(t[2*i],t[2*i+1]);
}
out(s[0]);
}
| #include <bits/stdc++.h>
using namespace std;
#define NFS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fr(i,a,b) for(ll i=a; i<b; i++)
#define rf(i,a,b) for(ll i=a; i>=b; i--)
#define endl "\n"
#define err() cout<<"=================================="<<endl;
#define errA(A) for(auto i:A) cout<<i<<" ";cout<<endl;
#define err1(a) cout<<#a<<" "<<a<<endl
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<endl
#define ll long long int
#define ull unsigned long long
#define vll vector<long long>
#define mll map<long long,long long>
#define pll pair<long long,long long>
#define v2d vector<vll>
#define vpll vector<pll>
#define mpll map<pll>
#define all(v) v.begin(),v.end()
#define mx(a) *max_element(all(a))
#define mn(a) *min_element(all(a))
#define alla(v) v,v+n
#define acc(a) accumulate(alla(a),(ll)0)
#define PB push_back
#define MP make_pair
#define ms(arr, v) memset(arr, v, sizeof(arr))
#define mod 1000000007
#define PI 3.14159265358979323846
/*
bool prime[1000001];
ll fsp[10000001];
void sieve() {memset(prime, true, sizeof(prime));
for (ll i = 2; i * i <= 1000000; i++)if (prime[i])for (ll j = i * i; j <= 1000000; j+= i)prime[j] = false;
prime[0] = prime[1] = false;}
void fastsieve() {fsp[1]=1;for(int i=2;i<=1e7;i++) fsp[i]=i;for (int i=4;i<=1e7;i+=2) fsp[i] = 2;
for (int i=3; i*i<=1e7; i++) {if(fsp[i]==i) {for (int j=i*i; j<=1e7; j+=i)if (fsp[j]==j) fsp[j] = i;}}}
*/
ll mul(ll a,ll b) {
return ((a % mod) * (b % mod)) % mod;
}
ll add(ll a,ll b) {
return (a % mod + b % mod) % mod;
}
ll gcd(ll a, ll b){
if (b == 0)
return a;
return gcd(b, a % b);
}
ll extgcd(ll a,ll b,ll& x,ll& y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
ll x1, y1;
ll d = extgcd(b, a % b, x1, y1);
x = y1;
y = x1 - y1 * (a / b);
return d;
}
bool isPrime(ll n){
if (n <= 1)
return false;
if (n <= 3)
return true;
if (n % 2 == 0 || n % 3 == 0)
return false;
for (ll i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
bool isPowerOfTwo(ll n) {
if(n==0)
return false;
return (ceil(log2(n)) == floor(log2(n)));
}
//Prime factorization of integer n O(sqrt(n))
vector<ll> factors(ll n)
{
vector<ll> f;
for (ll x = 2; x*x <= n; x++)
{
while (n%x == 0)
{
f.push_back(x);
n /= x;
}
}
if (n > 1) f.push_back(n);
return f;
}
ll bin_exp_mod(ll a,ll n)
{
ll res=1;
a%=mod;
if(a==0)
return 0;
while(n>0)
{
if(n&1)
res=((res%mod)*(a%mod))%mod;
n=n>>1;
a=((a%mod)*(a%mod))%mod;
}
res%=mod;
return res;
}
void solve()
{
ll n;
cin>>n;
double p = (double)n*1.08;
ll o = (ll) p;
if(o < 206)
{
cout<<"Yay!";
}
else if(o == 206)
{
cout<<"so-so\n";
}
else
{
cout<<":(\n";
}
}
int main() {
// your code goes here
NFS;
solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod=1e9+7;
int pw(int a,int t=mod-2){
int x=1;
while(t>0){
if(t&1)x=x*a%mod;
a=a*a%mod,t/=2;
}
return x;
}
int32_t main(){
ios::sync_with_stdio(0),cin.tie(0);
int n,m,s=0,ans=1;
cin >> n >> m;
for(int i=0;i<n;i++){
int x;
cin >> x;
s+=x;
}
s+=n,m+=n;
for(int i=1;i<=s;i++){
ans=ans*(m-i+1)%mod;
ans=ans*pw(i)%mod;
}
cout << ans;
} | #include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const int mod = 998244353;
int inc(int x, int y) { return x + y >= mod ? x + y - mod : x + y; }
namespace math
{
int qpow(int a, int x, int mo)
{
int res = 1;
while (x)
{
if (x & 1)
res = 1ll * res * a % mod;
a = 1ll * a * a % mod;
x >>= 1;
}
return res;
}
vector<int> Fac, invFac;
void Finit(int n)
{
Fac.resize(n + 1);
invFac.resize(n + 1);
Fac[0] = 1;
invFac[0] = 1;
for (int i = 1; i <= n; i++)
Fac[i] = 1ll * Fac[i - 1] * i % mod;
invFac[n] = qpow(Fac[n], mod - 2, mod);
for (int i = n - 1; i >= 1; i--)
invFac[i] = 1ll * invFac[i + 1] * (i + 1) % mod;
}
int C(int n, int m)
{
if (m == 0)
return 1;
if (n < m || m < 0)
return 0;
return (int)(1ll * Fac[n] * invFac[m] % mod * invFac[n - m] % mod);
}
}
void solve()
{
int n, m;
cin >> n >> m;
math::Finit(n);
vector<vector<int>> dp(14, vector<int>(n + 1));
dp[0][0] = 1;
for (int t = 0; t < 13; t++)
{
for (int k = 0; k <= n; k++)
{
for (int j = 0; j <= n; j += 2)
{
if (((j + k) & 1) == (m >> t & 1))
{
dp[t + 1][(j + k) / 2] = inc(dp[t + 1][(j + k) / 2], 1ll * math::C(n, j) * dp[t][k] % mod);
}
}
}
}
//cout << dp[0][0] << endl;
cout << dp[13][0] << endl;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T = 1;
while (T--)
{
solve();
}
} |
#pragma GCC optimize("Ofast")
#if 1
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
using ll = int64_t;
using db = double;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vpii = vector<pii>;
using vpll = vector<pll>;
constexpr char newl = '\n';
constexpr double eps = 1e-10;
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define show(x) cerr << #x << " = " << (x) << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define sz(x) (int)(x).size()
#define YesNo(x) cout<<((x)?"Yes":"No")<<newl;
#define YESNO(x) cout<<((x)?"YES":"NO")<<newl;
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
template<class A, class B> using umap = unordered_map<A, B>;
template<class A> using uset = unordered_set<A>;
template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> bool lcmp(const pair<T, T>& l, const pair<T, T>& r) {
return l.first < r.first;
}
template<class T> istream& operator>>(istream& i, v(T)& v) {
F0R(j, sz(v)) i >> v[j];
return i;
}
template<class A, class B> istream& operator>>(istream& i, pair<A, B>& p) {
return i >> p.first >> p.second;
}
template<class A, class B, class C> istream& operator>>(istream& i, tuple<A, B, C>& t) {
return i >> get<0>(t) >> get<1>(t) >> get<2>(t);
}
template<class T> ostream& operator<<(ostream& o, const pair<T, T>& v) {
o << "(" << v.first << "," << v.second << ")";
return o;
}
template<class T> ostream& operator<<(ostream& o, const vector<T>& v) {
F0R(i, v.size()) {
o << v[i] << ' ';
}
o << newl;
return o;
}
template<class T> ostream& operator<<(ostream& o, const set<T>& v) {
for (auto e : v) {
o << e << ' ';
}
o << newl;
return o;
}
template<class T1, class T2> ostream& operator<<(ostream& o, const map<T1, T2>& m) {
for (auto& p : m) {
o << p.first << ": " << p.second << newl;
}
o << newl;
return o;
}
struct P {
int x, y;
int dist(const P& v) {
return max(abs(v.x - x), abs(v.y - y));
}
};
// INSERT ABOVE HERE
signed main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
int N; cin >> N;
v(P) as(N);
vpii xs(N), ys(N);
F0R(i, N) {
cin >> as[i].x>>as[i].y;
xs[i] = { as[i].x,i };
ys[i] = { as[i].y,i };
}
sort(rng(xs));
sort(rng(ys));
uset<int> vs;
auto F = [&](int i) {
vs.insert(xs[i].second);
vs.insert(ys[i].second);
};
F(0); F(1); F(N - 2); F(N - 1);
vi bs;
for (auto v : vs) {
bs.push_back(v);
}
vi rs;
F0R(i, sz(bs)) {
FOR(j, i + 1, sz(bs)) {
rs.push_back(as[bs[i]].dist(as[bs[j]]));
}
}
sort(rrng(rs));
cout << rs[1];
}
#endif
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fr first
#define sc second
const int N = 2e5+5;
const int MOD = 1e9+7;
void solve(){
int n;
cin>>n;
vector<pair<pair<ll,ll>,int> > f,s;
for(int i=0;i<n;i++){
ll x,y;
cin>>x>>y;
f.pb({{x,y},i});
s.pb({{y,x},i});
}
sort(f.begin(),f.end());
sort(s.begin(),s.end());
set<pair<ll,pair<int,int> > >a;
a.insert({-max(abs(f[0].fr.fr-f[n-1].fr.fr),abs(f[0].fr.sc-f[n-1].fr.sc)),
{min(f[0].sc,f[n-1].sc),max(f[0].sc,f[n-1].sc)}});/// f[0],f[n-1]
a.insert({-max(abs(f[0].fr.fr-f[n-2].fr.fr),abs(f[0].fr.sc-f[n-2].fr.sc)),
{min(f[0].sc,f[n-2].sc),max(f[0].sc,f[n-2].sc)}});/// f[0],f[n-2]
a.insert({-max(abs(f[1].fr.fr-f[n-1].fr.fr),abs(f[1].fr.sc-f[n-1].fr.sc)),
{min(f[1].sc,f[n-1].sc),max(f[1].sc,f[n-1].sc)}});/// f[1],f[n-1]
a.insert({-max(abs(s[0].fr.fr-s[n-1].fr.fr),abs(s[0].fr.sc-s[n-1].fr.sc)),
{min(s[0].sc,s[n-1].sc),max(s[0].sc,s[n-1].sc)}});/// s[0],s[n-1]
a.insert({-max(abs(s[0].fr.fr-s[n-2].fr.fr),abs(s[0].fr.sc-s[n-2].fr.sc)),
{min(s[0].sc,s[n-2].sc),max(s[0].sc,s[n-2].sc)}});/// s[0],s[n-2]
a.insert({-max(abs(s[1].fr.fr-s[n-1].fr.fr),abs(s[1].fr.sc-s[n-1].fr.sc)),
{min(s[1].sc,s[n-1].sc),max(s[1].sc,s[n-1].sc)}});/// s[1],s[n-1]
auto it = a.begin();
it++;
cout<<-(it->fr)<<endl;
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t = 1;
// cin>>t;
while(t--){
solve();
}
return 0;
}
|
/******************* This is ZerothKing *******************/
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for(int i = int(a); i < int(b); i++)
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define sz(a) int((a).size())
const double pi = acos(-1.0);
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef map<int, int> mpii;
typedef set<int> seti;
typedef set<ll> setll;
typedef multiset<int> mseti;
typedef vector<ll> vll;
typedef vector<vll> vvl;
void solve() {
int i, j, k = 0, n, m;
cin >> n;
for (int i = 1; i <= n; i++) {
int temp = i;
bool inc = false;
while (temp) {
if (temp % 10 == 7) {
k++;
inc = true;
break;
}
temp /= 10;
}
if (inc) continue;
temp = i;
while (temp) {
if (temp % 8 == 7) {
k++;
break;
}
temp /= 8;
}
}
cout << n - k;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif // ONLINE_JUDGE
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
} | #include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define st first
#define nd second
#define pii pair<int,int>
#define mp make_pair
#define pll pair<long long,long long>
using namespace std;
const int nax = 1e6 + 5;
char ans[nax];
void solve(){
string s; cin >> s;
int lo = nax / 2;
int hi = nax / 2 - 1;
bool rev = false;
for(char x : s){
if(x == 'R') rev = !rev;
else{
if(!rev){
if(lo <= hi && ans[hi] == x){
hi--;
}
else ans[++hi] = x;
}
else{
if(lo <= hi && ans[lo] == x){
lo++;
}
else ans[--lo] = x;
}
}
}
if(!rev){
for(int i=lo;i<=hi;i++) cout << ans[i];
}
else{
for(int i=hi;i>=lo;i--) cout << ans[i];
}
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
int tt = 1;
// cin >> tt;
while(tt--) solve();
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
template<typename T>inline T read(){
T f=0,x=0;char c=getchar();
while(!isdigit(c)) f=c=='-',c=getchar();
while(isdigit(c)) x=x*10+c-48,c=getchar();
return f?-x:x;
}
#define int long long
namespace run{
const int N=4e5+9;
int head[N],nex[N],to[N],cnt;
inline void add(int u,int v){
nex[++cnt]=head[u];
head[u]=cnt,to[cnt]=v;
}
int n,m,a[N],b[N],vis[N],tota,totb;
inline void dfs(int u){
vis[u]=1,tota+=a[u],totb+=b[u];
for(int i=head[u];i;i=nex[i])
if(!vis[to[i]]) dfs(to[i]);
}
int main(){
n=read<int>(),m=read<int>();
for(int i=1;i<=n;i++) a[i]=read<int>();
for(int i=1;i<=n;i++) b[i]=read<int>();
for(int i=1;i<=m;i++){
int u=read<int>(),v=read<int>();
add(u,v),add(v,u);
}
for(int i=1;i<=n;i++) if(!vis[i]){
tota=totb=0,dfs(i);
if(tota!=totb) puts("No"),exit(0);
}
puts("Yes");
return 0;
}
}
#undef int
int main(){
#ifdef my
freopen(".in","r",stdin);
freopen(".out","w",stdout);
#endif
return run::main();
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<typename T>
void view_1d(vector<T> V, string sep) {
for (ll i=0; i<V.size(); i++) {
cout << V[i];
if (i == V.size() - 1) {
cout << endl;
} else {
cout << sep;
}
}
}
template<typename T>
void view_2d(vector<vector<T>> V, string sep) {
for (ll i=0; i<V.size(); i++) {
for (ll j=0; j<V[i].size(); j++) {
cout << V[i][j];
if (j == V[i].size() - 1) {
cout << endl;
} else {
cout << sep;
}
}
}
}
//==============================//
int main() {
ll N, K;
cin >> N >> K;
vector<pair<ll,ll>> F(N);
for (ll i=0; i<N; i++) {
ll A, B;
cin >> A >> B;
F[i] = make_pair(A, B);
}
sort(F.begin(), F.end());
ll ans;
for (ll i=0; i<=N; i++) {
if (i == 0) {
if (K < F[0].first) {
ans = K;
break;
} else {
K += F[0].second - F[0].first;
}
} else if (i == N) {
ans = F[N-1].first + K;
} else {
if (K < F[i].first - F[i-1].first) {
ans = F[i-1].first + K;
break;
} else {
K += F[i].second - (F[i].first - F[i-1].first);
}
}
}
cout << ans << endl;
}
|
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__);fflush(stderr);
#else
#define eprintf(...) 42
#endif
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
template<typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
return (ull)rng() % B;
}
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
clock_t startTime;
double getCurrentTime() {
return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}
const ll MOD = 998244353;
ll add(ll x, ll y) {
x += y;
if (x >= MOD) return x - MOD;
return x;
}
ll sub(ll x, ll y) {
x -= y;
if (x < 0) return x + MOD;
return x;
}
ll mult(ll x, ll y) {
return (x * y) % MOD;
}
ll bin_pow(ll x, ll p) {
if (p == 0) return 1;
if (p & 1) return mult(x, bin_pow(x, p - 1));
return bin_pow(mult(x, x), p / 2);
}
ll rev(ll x) {
return bin_pow(x, MOD - 2);
}
const int N = 200200;
int a[N];
int n;
int main()
{
startTime = clock();
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
scanf("%d", &n);
for (int i = 0; i < n; i++)
scanf("%d", &a[i]);
sort(a, a + n);
int ans = 0;
int sum = 0;
for (int i = 0; i < n; i++) {
ans = add(ans, mult(a[i], add(sum, a[i])));
sum = add(mult(sum, 2), a[i]);
}
printf("%d\n", ans);
return 0;
}
| /*
Motto - Try Hard To become **MASTER** ;-)
*/
#include <bits/stdc++.h>
#include <map>
#include <algorithm>
#include <vector>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <chrono>
#include <thread>
#include <iomanip>
//define
#define rep(i,n) for(int i=0;i<n;i++)
#define repu(i,k,n) for(int i=k;i<=n;i++)
#define repd(i,k,n) for(int i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define INF (int)INT_MAX
#define all(v) v.begin(), v.end()
#define endl "\n"
//typedef
typedef long long int ll;
typedef long double ld;
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
typedef std::vector< pii > vii;
typedef std::vector< ll > vll;
typedef std::vector< std::pair < pii, int > > vpp;
const int N = 3*1e5 +5 ;
const long long MOD = 1e9 + 7;
const long long inf = 1e18;
using namespace std;
ll modpow(ll x,ll n){
ll res=1;
while(n>0){
if(n&1) res=res*x%MOD;
x=x*x%MOD;
n>>=1;
}
return res;
}
//bool compare(const string &a , const string&b){
// set<pair<int,int> , decltype(&compare)>s(&compare) ;
//}
// struct compare{
// // for priority_queue
// bool operator()(const int &a , const int&b){
// return a<b ;
// }
// };
void solve()
{
int ans = 0 , n ;
cin>>n ;
for(int i = 1 ; i<=n ;i++){
int temp = i ;
bool is7 = false ;
while(temp){
if(temp%10 == 7){
is7 = true ;
}
temp /= 10 ;
}
temp = i ;
while(temp){
if(temp%8 == 7){
is7 = true ;
}
temp -= temp%8 ;
temp /= 8 ;
}
if(!is7)ans++ ;
}
cout<<ans<<endl;
}
int main() {
#ifndef ONLINE_JUDGE
// for getting input from input.txt
freopen("input.txt", "r", stdin);
// for writing output to output.txt
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(0);
cin.tie(NULL);
int t = 1;
// cin>>t;
while(t--)
{
solve();
}
cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
} |
#include <bits/stdc++.h>
#define f(i,a,b) for( ll i = a; i < b ; i++ )
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ones(x) (ll) __builtin_popcount(x)
#define fs first
#define sc second
#define pb push_back
#define po pop_back
#define mp make_pair
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ller ios::sync_with_stdio(false);cin.tsie(nullptr);cout.tie(nullptr)
#define watch(x) cout << (#x) << " is " << (x) <<"\n"
#define test ll t;cin>>t;while(t--)
#define PI 3.1415926535
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> ii ;
typedef vector<ll> vi ;
typedef vector<ii> vii ;
const ll mod = 998244353;
const ll MAX = 3e3+120;
const ll inf = 1e9;
ll dp[MAX][2*MAX];
ll DP(ll n,ll k){
if(n<k) return 0;
if(k==0){
if(!n) return 1;
return 0;
}
if(dp[n][k]) return dp[n][k];
ll ans = DP(n-1,k-1) + DP(n,2*k);
ans%=mod;
return dp[n][k] = ans;
}
int main(){
fastio;
ll n,k;
cin>>n>>k;
cout<<DP(n,k)<<"\n";
return 0;
} | #include <cstdio>
#include <cstring>
#include <algorithm>
#define cs const
#define il inline
#define max_n 3000
#define mod 998244353
using namespace std;
typedef long long ll;
typedef cs int& ci;
int dp[max_n+1][max_n<<1|1];
int main(){
int n,k;
scanf("%d%d",&n,&k);
memset(dp,0,sizeof(dp));
dp[0][0]=1;
for(int i=1; i<=n; ++i)
for(int j=i; j; /*printf("dp[%d][%d]:%d\n",i,j,dp[i][j]),*/--j)
(dp[i][j]=dp[i-1][j-1]+dp[i][j<<1])>=mod&&(dp[i][j]-=mod);
printf("%d\n",dp[n][k]);
return 0;
} |
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>
using namespace std;
typedef long long int ll;
#define SP(x) setprecision((int)x)
#define SW(x) setw(x) // 桁数指定
#define SF(c) setfill(c) // 埋め文字指定('0')
#define ALL(v) v.begin(), v.end()
int main(int argc, char const *argv[])
{
ll n, k, m;
cin >> n >> k >> m;
vector<ll> a(n - 1);
ll sum = 0;
for (ll i = 0; i < n - 1; i++)
{
cin >> a[i];
sum += a[i];
}
ll temp = m * n - sum;
if (temp > k)
{
cout << -1 << endl;
}
else
cout << max(temp, 0LL) << endl;
} | #include <iostream>
using namespace std;
int main()
{
int N,K,M,total,test,sum=0;
cin>>N>>K>>M;
int A[N];
for(int i=0;i<N-1;i++)
cin>>A[i];
for(int i=0;i<N-1;i++)
sum=sum+A[i];
total=sum/N;
test=(sum+K)/N;
if(total>=M)
cout<<"0";
else if(test<M)
cout<<"-1";
else
{
for(int i=1;i<=K;i++)
{
if(((sum+i)/N)==M)
{
cout<<i;
break;
}
}
}
return 0;
}
|
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long ll;
using pll = pair<int, int>;
int n;
string nums, turn;
vector<vector<int>> dp;
void dfs(int i, int num) {
if (i == n) {
if (num % 7 == 0) dp[i][num] = true;
else dp[i][num] = false;
return;
}
int v1 = (num * 10) % 7;
int v2 = (num * 10 + (nums[i] - '0')) % 7;
if (dp[i + 1][v1] == -1) dfs(i + 1, v1);
if (dp[i + 1][v2] == -1) dfs(i + 1, v2);
if (turn[i] == 'A') {
if (dp[i + 1][v1] && dp[i + 1][v2]) dp[i][num] = true;
else dp[i][num] = false;
}
else {
if (dp[i + 1][v1] || dp[i + 1][v2]) dp[i][num] = true;
else dp[i][num] = false;
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
cin >> nums;
cin >> turn;
dp.resize(n + 1, vector<int>(8, -1));
dfs(0, 0);
if (dp[0][0]) cout << "Takahashi" << endl;
else cout << "Aoki" << endl;
return 0;
} | // I solemnly swear that I am upto no good //
#include <bits/stdc++.h>
#define sub freopen("input.txt", "r", stdin);//freopen("output.txt", "w", stdout);
using namespace std;
#define ll long long
#define ld long double
#define ttime cerr << '\n'<<"Time (in s): " << double(clock() - clk) * 1.0 / CLOCKS_PER_SEC << '\n';
#define pb push_back
#define endl "\n"
#define unq(a) sort(all(a));a.resize(unique(all(a)) - a.begin())
#define sz(x) (int)((x).size())
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define fast ios_base::sync_with_stdio(false);cin.tie(0);
#define all(x) x.begin(),x.end()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define mp make_pair
#define ff first
#define ss second
#define YY cout<<"Yes"<<endl
#define NN cout<<"No"<<endl
#define ub upper_bound
#define lb lower_bound
#define A 1000001
const long long INF=1e18;
const long long mod=1000000007;
typedef pair<ll,ll> pairll;
typedef map<ll,ll> mapll;
bool comp(ll a,ll b){
return a>b;
}
ll n,k;
void solve(){
string s,t;
cin>>n>>s>>t;
std::vector<std::vector<bool> > dp(n+1, std::vector<bool> (7,0));
dp[n][0]=1;
for(int i=n-1;i>=0;--i){
for(int r=0;r<7;++r){
if(t[i]=='A'){
dp[i][r]=true;
for(int d : {0,s[i]-'0'}){
int rem=(r*10 + d)%7;
if(!dp[i+1][rem])dp[i][r]=0;
}
}
else{
dp[i][r]=false;
for(int d : {0,s[i]-'0'}){
int rem=(r*10 + d)%7;
if(dp[i+1][rem])dp[i][r]=1;
}
}
}
}
cout << (dp[0][0] ? "Takahashi" : "Aoki") << "\n";
}
int main(){
//sub;
fast;
// pre();
// clock_t clk = clock();
ll t=1;
// cin>>t;
while(t--){
solve();
}
// ttime;
return 0;
}
// Mischief Managed // |
#include <bits/stdc++.h>
/*#include <iostream>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <sstream>*/
#define ll long long
#define fop(i,m,n) for(ll i=m; i<n; i++)
#define fastIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define X first
#define Y second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define ep emplace_back
using namespace std;
const long long MOD = 998244353;
const long long N = 1e5+5;
const long long Nlog = 17;
const long long Hash = 257;
const double PI = 2.0*acos(0.0);//<cmath>
//const double PI = 3.141592653;
const double E = 2.718281828;
void solve(){
ll n;
cin >> n;
ll a[n], m[n], p[n], pp[n];
fop(i,0,n){
cin >> a[i];
if(i){
m[i] = max(m[i-1], a[i]);
p[i] = p[i-1] + a[i];
pp[i] = pp[i-1] + p[i];
}else{
m[i] = a[i];
p[i] = a[i];
pp[i] = a[i];
}
}
fop(i,0,n){
cout << (i+1)*m[i] + pp[i] << '\n';
}
}
int main()
{
fastIO;
int t=1;
//cin >> t;
while(t--) solve();
return 0;
} | #include <iostream>
using namespace std;
using lint = long long;
void solve() {
int n;
cin >> n;
lint ma = 0, sum = 0, ans = 0;
for (int k = 1; k <= n; ++k) {
lint a;
cin >> a;
ma = max(ma, a);
sum += a;
ans += sum;
cout << ans + ma * k << "\n";
}
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
#define REP(i, n, m) for(ll i=n; i<(ll)m; ++i)
#define IREP(i, n, m) for(ll i=n-1; i>=m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()
#define vprint(v) for(auto e:v){cout<<e<<" ";};cout<<endl;
#define vvprint(vv) for(auto v:vv){vprint(v)};
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
cout << setprecision(20);
ll n;
cin >> n;
ll total = 0;
ll left = 1;
ll right = n;
ll skip = 101;
while(n>1){
++total;
skip = right;
++left;
--right;
ll next = skip-left;
if(next<right && next>left){
total += right - next;
right = next;
}
else break;
}
total += right - left + 1;
cout << total << endl;
}
| #include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
long long int n;
cin>>n;
long long int sa=floor(-(long double)1/2 + sqrt((long double)1/4 + 2*(n+1)));
long long int ans=n-sa+1;
cout<<ans<<endl;
} |