code_file1
stringlengths 87
4k
| code_file2
stringlengths 82
4k
|
---|---|
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type , less<int> , rb_tree_tag , tree_order_statistics_node_update>
#define int long long int
#define ull unsigned long long
#define pb push_back
#define inf 1e18
#define mk make_pair
#define ld long double
#define mod 1000000007
#define fi first
#define se second
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test int t; cin>>t; while(t--)
#define setbits __builtin_popcount
#define endl '\n'
#define LOCAL
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i));}
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
int32_t main()
{
fastIO;
int a,b,c;
cin>>a>>b>>c;
if(a<0 && c%2 && b>=0)
{
cout<<"<";
return 0;
}
if(b<0 && c%2 && a>=0)
{
cout<<">";
return 0;
}
a=abs(a);
b=abs(b);
ld val,val1;
val=(ld)c*log10((ld)a);
val1=(ld)c*log10((ld)b);
if(val<val1)
{
cout<<"<";
}
else
if(val>val1)
{
cout<<">";
}
else{
cout<<"=";
}
} | #include<stdio.h>
#include<algorithm>
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
int main() {
ll a, b, c;
cin >> a >> b >> c;
//coditions for a
if(a==b){
cout<<"="<<endl;
}
else if(a==0&&a<b){
cout<<"<"<<endl;
}
else if(a==0 && a>b && c%2!=0){
cout<<">"<<endl;
}
else if(a==0 && a>b && c%2==0){
cout<<"<"<<endl;
}
else if(a==0&&a<b){
cout<<"<"<<endl;
}
else if(a<0 && abs(a)<b && c%2==0){
cout<<"<"<<endl;
}
else if(a<0 && abs(a)<b && c%2!=0){
cout<<"<"<<endl;
}
else if(a<0 && abs(a)>b && c%2==0){
cout<<">"<<endl;
}
else if(a<0 && abs(a)>b && c%2!=0){
cout<<"<"<<endl;
}
else if(a<0 && abs(a)==b && c%2!=0){
cout<<"<"<<endl;
}
else if(a<0 && abs(a)==b && c%2==0){
cout<<"="<<endl;
}
//conditions for b
else if(b==0&&b<a){
cout<<">"<<endl;
}
else if(b==0 && b>a && c%2!=0){
cout<<"<"<<endl;
}
else if(b==0 && b>a && c%2==0){
cout<<">"<<endl;
}
else if(b==0&&b<a){
cout<<">"<<endl;
}
else if(b<0 && abs(b)<a && c%2==0){
cout<<">"<<endl;
}
else if(b<0 && abs(b)<a && c%2!=0){
cout<<">"<<endl;
}
else if(b<0 && abs(b)>a && c%2==0){
cout<<"<"<<endl;
}
else if(b<0 && abs(b)>a && c%2!=0){
cout<<">"<<endl;
}
else if(b<0 && abs(b)==a && c%2!=0){
cout<<">"<<endl;
}
else if(b<0 && abs(b)==a && c%2==0){
cout<<"="<<endl;
}
//overlapping conditions
else if(a>0 && a>b){
cout<<">"<<endl;
}
else if(a>0 && a<b){
cout<<"<"<<endl;
}
else if(b>0 && a>b){
cout<<">"<<endl;
}
else if(b>0 && a<b){
cout<<"<"<<endl;
}
} |
#include <bits/stdc++.h>
using namespace std;
// #define TEST(a) cout<<"Case #"<<a<<": ";
#define int long long
// #define ll unsigned long long
// #define Uint unsigned int
#define rep(i, a, b) for (int i = a; i < b; i++)
#define vi vector<int>
#define all(a) a.begin(),a.end()
#define pb push_back
#define mii map<int, int>
#define INF 100000000
#define take(a) int a;cin >> a;
#define MOD 1000000007
#define pii pair<int,int>
#define MAX_N 1000
int32_t main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin>>n;
vi a;
mii cnt;
rep(i,0,n)
{
take(val);
a.pb(val);
if(cnt.find(val) == cnt.end())
{
cnt.insert({val,1});
}
else
{
cnt[val]++;
}
}
int ans = 0;
for(int ele:a)
{
ans += (n-cnt[ele]);
}
cout<<ans/2;
return 0;
}
| #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector <int> Liczby(200003);
int main()
{
int Ilosc;
long long wynik = 0, AktualnyWynik = 0;
cin >> Ilosc;
for(int i = 0; i < Ilosc; ++i)
{
cin >> Liczby[i];
AktualnyWynik += Liczby[i];
}
sort(Liczby.begin(), Liczby.begin() + Ilosc);
AktualnyWynik -= Liczby[0];
for(int i = 1; i < Ilosc; ++i)
{
long long tmp = Liczby[i - 1];
tmp *= (Ilosc - i);
wynik += AktualnyWynik - tmp;
AktualnyWynik -= Liczby[i];
}
cout << wynik;
return 0;
}
|
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
bool fg[10005];
int main() {
int n;
cin>>n;
for(int i=6;6*i<=10000;i++) {
cout<<6*i<<" ";
fg[6*i]=true;
n--;
if(n==2) {
cout<<"10 15";
cout<<endl;
return 0;
}
}
for(int i=6;10*i<=10000;i++) {
if(fg[10*i]==false) {
cout<<10*i<<" ";
fg[10*i]=true;
n--;
}
if(n==1) {
cout<<"15"<<endl;
return 0;
}
}
for(int i=6;15*i<=10000;i++) {
if(fg[15*i]==false) {
cout<<15*i<<" ";
fg[15*i]=true;
n--;
}
if(n==0) {
break;
}
}
} | #include<bits/stdc++.h>
#define MAX 10000
#define N 2505
using namespace std;
int n;
int a[N];
int main(){
scanf("%d",&n);
for(int i=2;i<=MAX&&a[0]<n-1;i+=2){
if(i%3!=0&&i%5!=0&&i%7!=0&&i%11!=0)continue;
a[++a[0]]=i;
}
a[n]=3*5*7*11;
for(int i=1;i<=n;i++)printf("%d ",a[i]);
} |
//{{{
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using VLL = vector<LL>;
using vi = vector<int>;
using pii = pair<int, int>;
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define clr(a, b) memset(a, b, sizeof(a))
#ifdef LOCAL
#include "prettyprint.hpp"
// clang-format off
void _print() { cerr << "]\033[0m\n"; }
template <typename T> void __print(T x) { cerr << x; }
template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); }
#define debug(x...) cerr << "\033[1;34m[" << #x << "] = \033[1;32m["; _print(x)
#define debug_arr(x...) cerr << "\033[1;34m[" << #x << "] = \033[1;32m" << (x) << "\033[0m\n"
#else
#define debug(x...)
#define debug_arr(x...)
#endif
// clang-format on
//}}}
int k;
int n;
string s;
const int mod = 1e9 + 7;
inline int ch2dig(char ch)
{
if (ch >= 'A' && ch <= 'F') return ch - 'A' + 10;
return ch - '0';
}
const int N = 2e5 + 10;
LL dp[N][20];
LL cnt[N];
LL dfs(int pos, int st, bool bound, bool zeros)
{
if (pos == -1) return __builtin_popcount(st) == k;
LL ret = 0;
if (bound && zeros)
{
int ed = bound ? ch2dig(s[pos]) : 15;
for (int i = 0; i <= ed; i++)
{
int new_st = st;
if (i) new_st |= (1 << i);
ret += dfs(pos - 1, new_st, bound && i == ed, zeros && i == 0);
ret %= mod;
}
debug(pos, st, bound, zeros, ret);
return ret;
}
if (bound && !zeros)
{
int ed = bound ? ch2dig(s[pos]) : 15;
for (int i = 0; i <= ed; i++)
{
int new_st = st | (1 << i);
ret += dfs(pos - 1, new_st, bound && i == ed, 0);
ret %= mod;
}
debug(pos, st, bound, zeros, ret);
return ret;
}
if (!bound && zeros)
{
for (int i = 0; i <= 15; i++)
{
int new_st = st;
if (i) new_st |= (1 << i);
ret += dfs(pos - 1, new_st, 0, zeros && i == 0);
ret %= mod;
}
debug(pos, st, bound, zeros, ret);
return ret;
}
if (dp[pos][__builtin_popcount(st)] != -1) return dp[pos][__builtin_popcount(st)];
if (!bound && !zeros)
{
for (int i = 0; i <= 15; i++)
{
int new_st = st | (1 << i);
ret += dfs(pos - 1, new_st, 0, 0);
ret %= mod;
}
}
debug(pos, st, bound, zeros, ret);
return dp[pos][__builtin_popcount(st)] = ret;
}
int main()
{
#ifdef LOCAL
freopen("in", "r", stdin);
// freopen("out", "w", stdout);
#endif
ios::sync_with_stdio(false);
cin.tie(0);
while (cin >> s >> k)
{
clr(dp, -1);
n = sz(s);
reverse(all(s));
LL ans = dfs(n - 1, 0, 1, 1);
cout << ans << endl;
}
return 0;
} | #include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MAX_N = 19;
const int MAX_M = 105;
ll dp[(1 << MAX_N)];
int X[MAX_M],Y[MAX_M],Z[MAX_M];
int main()
{
int N,M;
cin >> N >> M;
rep(i,M)
{
cin >> X[i] >> Y[i] >> Z[i];
//X[i] = i%(N-1)+1; Y[i] = i%(N-1)+1; Z[i] = i%N;
}
dp[0] = 1;
for (int bits = 0; bits < (1 << N); ++bits)
{
vector<int> ppcnt(N+1,0);
rep(i,N) {ppcnt[i+1] = ppcnt[i] + ((bits >> i) & 1);}
/*
rep(i,N+1) cout << ppcnt[i] << " ";
cout << endl;
*/
rep(i,N)
{
if ((bits >> i) & 1 != 0) continue;
bool ok = true;
int c;
rep(j,M)
{
if (i+1 <= Y[j]) c = 1;
else c = 0;
if (X[j] == ppcnt[N]+1 && ppcnt[Y[j]]+c > Z[j]) ok = false;
}
if (ok) dp[bits | (1 << i)] += dp[bits];
}
//cout << bits << " " << dp[bits] << endl;
}
cout << dp[(1 << N) - 1] << endl;
return 0;
} |
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
cin >> N;
vector<int> A;
vector<int> B;
for (int i = 0; i < N; i++){
int a;
cin >> a;
A.push_back(a);
}
for (int i = 0; i < N; i++){
int b;
cin >> b;
B.push_back(b);
}
int minn = A[0];
int maxx = B[0];
for (int i = 1; i < N; i++){
minn = max(minn, A[i]);
maxx = min(maxx, B[i]);
}
if (maxx >= minn)
cout << maxx-minn+1;
else
cout << 0;
}
| #include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()
int main() {
int N, A[1000000];
cin >> N;
int size = 1 << N;
REP(i, size) cin >> A[i];
int half = size / 2;
int maxi1 = max_element(A, A + half) - A, maxi2 = max_element(A + half, A + size) - A;
if (A[maxi1] > A[maxi2]) cout << maxi2 + 1 << endl;
else cout << maxi1 + 1 << endl;
return 0;
} |
#include <bits/stdc++.h>
#define rep(i, n) for (ll i=0; i<n; ++i)
#define all(obj) (obj).begin(),(obj).end()
using namespace std;
typedef long long ll;
long long GCD(long long x, long long y) { return y ? GCD(y, x%y) : x; }
int main(){
int x;
cin >> x;
cout << max(x, 0) << endl;
return 0;
}
| #include <iostream>
#include <string>
#include <math.h>
using namespace std;
long long n;
long long bin_search(long long l, long long r) {
if (r == l) return l;
long long m = l + (r - l) / 2;
if (m * m + m > 2 * n + 2) {
return bin_search(l, m);
} else {
return bin_search(m + 1, r);
}
}
int main() {
cin >> n;
cout << n + 1 - bin_search(1, 2e9) + 1;
return 0;
}
|
#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;
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
#define int long long
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define eb emplace_back
#define g0(a) get<0>(a)
#define g1(a) get<1>(a)
#define g2(a) get<2>(a)
#define g3(a) get<3>(a)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef double db;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
main() {
ios::sync_with_stdio(0);
cin.tie(0);
int X;
cin >> X;
int OX = X;
X++;
while (X % 100) X++;
cout << X - OX << '\n';
}
| //in dp prefix suffix sum helps..
#include<iostream>
#include<vector>
#include<string.h>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<stack>
#include <iterator>
#include <map>
#include<list>
#include <fstream>
#include<unordered_map>
#include<set>
#include<queue>
#define int long long
#define double long double
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pip pair<int, pair<int, int> >
#define viv vector<vector<int> >
#define vip vector< pair<int, int> >
#define vi vector<int>
#define mii map<pii, int>
#define qu queue<int>
#define set set<int>
#define multi multiset<int>
#define stack stack<int>
#define fi first
#define se second
#define reverse(s) reverse(s.begin(), s.end())
#define sort1(v) sort(v.begin(), v.end())
#define it iterator
#define pq1 priority_queue <pii, vector<pii>, greater<pii> >
#define mem(x, y) memset(x, (int)y, sizeof(x))
#define ps(x,y) fixed<<setprecision(y)<<x
// author :: Anurag Anand.
using namespace std;
int z= 1e9+7;
//int z= 998244353;
int gcd(int a, int b){
if(a==0)return b;
if(b==0)return a;
return gcd(b, a%b);
}
int power(int a,int b)
{
int res=1;
while(b)
{
if(b&1)
{
res=(res*a)%z;
b--;
}
else
{
a=(a*a)%z;
b=b>>1;
}
}
return res;
}
vi sieve;
// vi seg;
// void arrange(int i, int v, int x, int lx, int rx){
// if(rx-lx==1){
// seg[x]+=v;
// return;
// }
// int m= (lx+rx)/2;
// if(i<m) arrange(i, v, 2*x+1, lx, m);
// else arrange(i, v, 2*x+2, m, rx);
// seg[x]=seg[2*x+1]+seg[2*x+2];
// }
// int calc(int l, int r, int x, int lx, int rx){
// if(l>=rx||r<=lx) return 0;
// if(lx>=l&&rx<=r) return seg[x];
// int mid=(lx+rx)/2;
// int sl= calc(l, r, 2*x+1, lx, mid), sr= calc(l, r, 2*x+2, mid, rx);
// return sl+sr;
// }
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
vi pp;
pp.assign(1000001, 0);
for(int i=2;i<1000;i++){
if(!pp[i]){
for(int j=i*i;j<=1000000;j+=i){
pp[j]=1;
}
}
}
for(int i=2;i<=1000000;i++) if(!pp[i]) sieve.pb(i);
int t;
t=1;
//cin>>t;
while(t--){
int x;
cin>>x;
cout<<(100-x%100)<<"\n";
}
} |
#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define eps (double)(1e-9)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;
int n;
vector<vector<int>> G(100010);
//ret = First - Second
//rに動かした人がplayer == 0, player == 1なら交代
P solve(int r){
int ret = 1;
int player = 1, cnt = 0;
priority_queue<int> que;
for(auto v : G[r]){
P now = solve(v);
if(!now.second && now.first < 0)ret += now.first;
if(!now.second && now.first > 0)cnt += now.first;
if(now.second)que.push(-now.first);
}
while(!que.empty()){
int t = -que.top();
que.pop();
if(player)ret += t;
else ret -= t;
player ^= 1;
}
if(player)ret += cnt;
else ret -= cnt;
return {ret, player};
}
int main() {
cin >> n;
rep(i, n-1){
int p;
cin >> p;
G[p-1].push_back(i+1);
}
cout << (n+solve(0).first)/2 << endl;
} | #define fast ios::sync_with_stdio(false); cin.tie(0)
#define foru(i, k, n) for (int i = k; i < n; i++)
#define ford(i, k, n) for (int i = k; i >= n; i--)
#define pb push_back
#define ff first
#define ss second
#include <iostream>
#include <vector>
#include <algorithm>
#include <bitset>
#include <queue>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
int main() {
fast;
int n;
cin >> n;
vector<ll> a(n, 0), b = a;
foru(i, 0, n)cin >> a[i];
foru(i, 0, n)cin >> b[i];
ll sm = 0;
foru(i, 0, n)sm += (a[i] * b[i]);
if (sm == 0)cout << "Yes";
else cout << "No";
return 0;
} |
#include <iostream>
using namespace std;
int main()
{
unsigned long long int n;
cin>>n;
unsigned long long i=1;
while(i*(i+1)/2<=n+1)
i++;
cout<<n-i+2<<endl;
return 0;
}
| //#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
//#include<ctime>
//#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vc = vector<char>;
using vvc = vector<vc>;
ll gcd(ll a,ll b){
if(b == 0) return a;
return gcd(b , a % b);
}
const ll MOD = 1000000007;
const ll MAX = 2000001;
ll mod(ll a){
return a % MOD;
}
ll lcm(ll a,ll b){
return (a*b)/gcd(a,b);
}
//ここに適切な判断条件を書く
bool isOK(ll index,ll n) {
if((long double)((index+1) <= 2.0*(long double)(n+1)/(long double)(index)) and ((index*(index+1))/2 <= n+1)) return true;
return false;
}
//臨機応変に引数を書き換える
int binary_search(ll n) {
ll ok = 0;
ll ng = min(n,ll(2000000002));
while (abs(ok - ng) > 1) {
ll mid = (ok + ng) / 2;
if (isOK(mid,n)) ok = mid;
else ng = mid;
}
return ok;
}
int main(){
ll n; cin >> n;
if(n == 1){
cout << 1 << endl;
return 0;
}
if(n == 2){
cout << 1 << endl;
return 0;
}
cout << n-binary_search(n)+1 << endl;
/*cout << ( double(1000000002+1) <= 2.0*double(109109109109109109
+1)/double(1000000002)
? "Yes" : "No") << endl;
*/
} |
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
//Graph[i][j][k] ==> i 番目のアルファベットが置かれている
//辺のうち、j から出ている k 番目の辺がつなぐ j 以外の頂点
vector<int> Graph[26][1000];
int main()
{
int N, M;
cin >> N >> M;
//作れるどんな回文の大きさよりも大きい数(今回はどんなに長くても N * N * 2 とかだねたぶん)
int inf = 1 << 30;
//真ん中に一文字入れたら回文ができるところで使う
vector<P> edges;
//辺の情報を入力
for (int i = 0; i < M; i++)
{
int u, v;
char c;
cin >> u >> v >> c;
u--;
v--;
int type = c - 'a';
Graph[type][v].push_back(u);
Graph[type][u].push_back(v);
edges.push_back(P(u, v));
edges.push_back(P(v, u));
}
//ここまでで作る回文の最短の長さをいれる配列
vector<vector<int>> LEN_up_to_here(N, vector<int>(N, inf));
LEN_up_to_here[0][N - 1] = 0;
//この queue に次に見ていく始点と終点の組を入れる
queue<P> que;
que.push(P(0, N - 1));
//次に見る始点と終点の組がなくなるまで
//始点終点両方から幅優先探索をするイメージ
//(既にみたものは書き換える必要がないね)
while (!que.empty())
{
//queue の先頭を見る
P now = que.front();
que.pop();
auto [start, goal] = now;
for (int i = 0; i < 26; i++)
{
//start と goal からそのアルファベットの辺が生えているときを考える
if (Graph[i][start].size() == 0 || Graph[i][goal].size() == 0)
{
continue;
}
for (auto to0 : Graph[i][start])
{
for (auto to1 : Graph[i][goal])
{
if (LEN_up_to_here[to0][to1] != inf)
{
continue;
}
//回文の長さは 2 づつ増えるよね(両端から作っていくので)
LEN_up_to_here[to0][to1] = LEN_up_to_here[start][goal] + 2;
que.push(P(to0, to1));
}
}
}
}
int ans = inf;
//回文ができたよ~~うれしいね
for (int i = 0; i < N; i++)
{
ans = min(ans, LEN_up_to_here[i][i]);
}
//あと一文字真ん中に入れたら回文になるよ~~
for (int i = 0; i < 2 * M; i++)
{
auto [start, goal] = edges[i];
ans = min(ans, LEN_up_to_here[start][goal] + 1);
}
// ans==inf となっている時は構築できない時と同値だよね~~(作れるときは inf 未満になるようにしたので)
if (ans != inf)
{
cout << ans << endl;
return 0;
}
cout << -1 << endl;
}
//計算量は幅優先探索以外は平気そう
//幅優先探索での計算量は実質的に
//頂点数 N*N, 辺 M*M とみなせるから、
//O(N*N+M*M)になる...タブンネ | #include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define N 1010
#define M 1010
#define ll long long
int last[N], nxt[M * 2], to[M * 2], ty[M * 2], len = 0;
int dis[N][N], p[N][N];
struct {
int x, y;
}q[9000010];
void add(int x, int y, int w) {
to[++len] = y;
nxt[len] = last[x];
ty[len] = w;
last[x] = len;
}
int main() {
int n, m, K, u, v, w, i, j, k;
scanf("%d%d", &n, &m);
memset(dis, 255, sizeof(dis));
int l = 0, r = 0;
for(i = 1; i <= m; i++) {
char ch;
scanf("%d%d %c", &u, &v, &ch);
w = ch - 'a' + 1;
add(u, v, w), add(v, u, w);
dis[u][v] = dis[v][u] = 1;
if(!p[u][v]) q[++r].x = u, q[r].y = v, p[u][v] = 1;
if(!p[v][u]) q[++r].x = v, q[r].y = u, p[v][u] = 1;
}
for(i = 1; i <= n; i++) dis[i][i] = 0, p[i][i] = 1, q[++r].x = i, q[r].y = i;;
while(l != r) {
l = l % 9000005 + 1;
u = q[l].x, v = q[l].y;
for(i = last[u]; i; i = nxt[i]) {
for(j = last[v]; j; j = nxt[j]) if(ty[j] == ty[i]) {
if(dis[u][v] + 2 < dis[to[i]][to[j]] || dis[to[i]][to[j]] == -1) {
dis[to[i]][to[j]] = dis[u][v] + 2;
if(!p[to[i]][to[j]]) {
r = r % 9000005 + 1;
q[r].x = to[i], q[r].y = to[j];
p[to[i]][to[j]] = 1;
}
}
}
}
p[u][v] = 0;
}
printf("%d\n", dis[1][n]);
return 0;
} |
#include <cstdio>
#include <cmath>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <cassert>
#include <string>
#include <cstring>
#include <queue>
using namespace std;
#define rep(i,a,b) for(int i = a; i < b; i++)
#define S(x) scanf("%d",&x)
#define S2(x,y) scanf("%d%d",&x,&y)
#define P(x) printf("%d\n",x)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second
#define pb push_back
#define mp make_pair
typedef long long int LL;
typedef pair<int, int > pii;
typedef vector<int > vi;
const int N = 200001;
int A[N], B[N], P[N], IP[N];
vector<pii > v, ans;
int main() {
int n;
S(n);
rep(i,1,n+1) {
S(A[i]);
v.pb(mp(A[i], i));
}
rep(i,1,n+1) {
S(B[i]);
}
rep(i,1,n+1) {
S(P[i]);
IP[P[i]] = i;
}
sort(all(v));
rep(i,0,v.size()) {
int x = v[i].SS;
if(IP[x] == x) continue;
if(B[P[x]] >= A[x]) {
P(-1);
return 0;
}
ans.pb(mp(x, IP[x]));
int y = P[x];
IP[y] = IP[x];
P[IP[x]] = y;
IP[x] = x;
P[x] = x;
}
P((int)ans.size());
rep(i,0,ans.size()) {
printf("%d %d\n",ans[i].FF, ans[i].SS);
}
return 0;
}
| #include<bits/stdc++.h>
// #include<atcoder/all>
using namespace std;
// using namespace atcoder;
using lint = long long;
using ulint = unsigned long long;
template<class T>using graph = vector<vector<T>>;
#define endl '\n'
int const INF = 1<<30;
lint const INF64 = 1LL<<61;
lint const mod = 1e9+7;
//long const mod = 998244353;
lint ceilDiv(lint x, lint y){if(x >= 0){return (x+y-1)/y;}else{return x/y;}}
lint floorDiv(lint x, lint y){if(x >= 0){return x/y;}else{return (x-y+1)/y;}}
lint Sqrt(lint x){lint upper = 1e9;lint lower = 0;while(upper - lower > 0){lint mid = (1+upper + lower)/2;if(mid * mid > x){upper = mid-1;}else{lower = mid;}}return upper;}
lint gcd(lint a,lint b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
lint lcm(lint a,lint b){return (a / gcd(a,b)) * b;}
lint chmin(vector<lint>&v){lint ans = INF64;for(lint i:v){ans = min(ans, i);}return ans;}
lint chmax(vector<lint>&v){lint ans = -INF64;for(lint i:v){ans = max(ans, i);}return ans;}
double dist(double x1, double y1, double x2, double y2){return sqrt(pow(x1-x2, 2) + pow(y1-y2,2));}
vector<lint>prime;void makePrime(lint n){prime.push_back(2);for(lint i=3;i<=n;i+=2){bool chk = true;for(lint j=0;j<prime.size() && prime[j]*prime[j] <= i;j++){if(i % prime[j]==0){chk=false;break;}}if(chk)prime.push_back(i);}}
int main(){
int n;
cin >> n;
int a[n];
int b[n];
int p[n];
for(int i=0;i<n;i++){
cin >> a[i];
}
for(int i=0;i<n;i++){
cin >> b[i];
}
for(int i=0;i<n;i++){
cin >> p[i];
p[i]--;
if(i != p[i] && a[i] <= b[p[i]]){
cout << -1 << endl;
return 0;
}
}
vector<pair<int,int>>ans;
vector<int>invP(n); //荷物iを誰が持ってるか
for(int i=0;i<n;i++){
invP[p[i]] = i;
}
priority_queue<pair<lint,int>>que;
for(int i=0;i<n;i++){
que.push({b[i], i});
}
while(!que.empty()){
auto f = que.top();
que.pop();
if(f.second == invP[f.second])continue;
int nimotu1 = f.second;
int hito1 = invP[f.second];
int hito2 = nimotu1;
int nimotu2 = p[hito2];
ans.push_back({hito1+1, 1+hito2});
p[hito1] = nimotu2;
p[hito2] = nimotu1;
invP[nimotu1] = hito2;
invP[nimotu2] = hito1;
}
cout << ans.size() << endl;
for(auto p: ans){
cout << p.first << " " << p.second<<endl;
}
}
|
#include "bits/stdc++.h"
#define int long long
#define pb push_back
using namespace std;
const int MOD = 1e9 + 7;
int power(int z){
if(z==0)return 1;
return power(z-1)*10;
}
signed main(){
int K;
cin >> K;
string S,T;
cin >> S >> T;
int cnt[10];
for(int i=1;i<=9;i++)cnt[i]=K;
int to=9*K-8;
for(int i=0;i<4;i++){
--cnt[S[i]-'0'];
--cnt[T[i]-'0'];
}
double ans=0;
for(int i=1;i<=9;i++){
for(int j=1;j<=9;j++){
double p_cards=cnt[i]*1.0/to;
if(i==j) p_cards*=(cnt[j]-1)*1.0/(to-1);
else p_cards*=cnt[j]*1.0/(to-1);
int tcnt[10], acnt[10];
for(int k=1;k<=9;k++) tcnt[k]=acnt[k]=0;
for(int k=0;k<4;k++){
++tcnt[S[k]-'0'];
++acnt[T[k]-'0'];
}
++tcnt[i];
++acnt[j];
int t_score=0, a_score=0;
for(int k=1;k<=9;k++){
t_score+=k*power(tcnt[k]);
a_score+=k*power(acnt[k]);
}
ans+=(t_score>a_score)*p_cards;
}
}
cout << fixed << setprecision(12) << ans << "\n";
} | #include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <sstream>
#include <set>
#include <functional>
#include <map>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <stack>
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> >;
#define fi first
#define se second
struct Edge{
ll to;
ll w;
Edge(ll to, ll w):to(to),w(w){}
};
using wGraph = vector<vector<Edge> >;
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;
}
}
template<class T> bool chmaxb(T& a, T b){
if (a < b){
a=b;
return true;
}
return false;
}
template<class T> bool chminb(T& a, T b){
if (a > b){
a = b;
return true;
}
return false;
}
const ll INF = 1LL << 60;
ll k;
string S,T;
ll MOD = 1000000007;
ll modpow(ll a, ll n, ll mod) {
ll res = 1;
while (n > 0) {
if (n & 1) res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
int main(){
cin >> k;
cin >> S >> T;
vector<ll>num(10,k);
vector<ll> tnum(10,0);
vector<ll> anum(10,0);
num[0] = 0;
rep(i,4){
ll s = S[i]-'0';
ll t = T[i]-'0';
tnum[s] += 1;
anum[t] += 1;
num[s] -= 1;
num[t] -= 1;
}
double sum = 0;
repi(i,1,10) sum+=num[i];
double ok = 0;
repi(i,1,10){
repi(j,1,10){
if (i == j){
if (num[i] <= 1) continue;
}
else{
if (num[i] <= 0 || num[j] <= 0) continue;
}
ll tc = 0;
ll ac = 0;
tnum[i] += 1;
anum[j] += 1;
rep(k,10){
tc += k*modpow(10,tnum[k],MOD);
ac += k*modpow(10,anum[k],MOD);
}
if (tc > ac){
if (i == j) ok += num[i]*(num[i]-1);
else ok += num[i]*num[j];
}
tnum[i] -= 1;
anum[j] -= 1;
}
}
cout << fixed << setprecision(15) << ok/(sum*(sum-1)) << endl;
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1e9+7;
int main()
{
cin.tie(0);
ios_base::sync_with_stdio(false);
ll t, n;
cin>>t>>n;
auto f = [&](auto x){
return (ll)floor((100+t)*x*0.01);
};
ll ok = 0, ng = 100*n;
while (abs(ok-ng) > 1) {
ll mid = (ok + ng) / 2;
if (f(mid) - mid < n) {
ok = mid;
} else {
ng = mid;
}
}
cout << f(ok) + 1 << "\n";
} | #include<bits/stdc++.h>
using namespace std;
int t,N,hah[160];
vector<int> g;
template<typename Tp>
void read(Tp &x)
{
x=0;int f=1;char c=getchar();
while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}x*=f;
}
int main()
{
read(t),read(N);
for(int i=1;i<=100;i++)
{
int now=(100+t)*i/100;
hah[now]=1;
}
for(int i=1;i<=100+t;i++) if(!hah[i]) g.push_back(i);
int sz=g.size();
int d=N/sz;
if(N%sz==0) d--;
N%=sz;
if(!N) N=sz;
N--;
printf("%lld\n",(long long)(100+t)*d+g[N]);
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(){
const int m=1000000007;
int n, p;
cin>>n>>p;
int ans=p-1;
int c=p-2;
for(int d=n-1; d>0; d>>=1){
if(d&1) ans=(ll)ans*c%m;
c=(ll)c*c%m;
}
cout<<ans<<endl;
return 0;
}
| #include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<float.h>
#include<tuple>
#include<string.h>
#include<iomanip>
#include<stack>
#include<queue>
#include<map>
#include<deque>
#include<math.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define REP(i,n) for(ll i=1;i<=n;i++)
#define ALLOF(c) (c).begin(), (c).end()
#define Pa pair<ll,ll>
//const ll mod=1000000007;
const ll mod=998244353;
const ll INF=10e12;
const ll inf=-1;
ll ABS(ll a){return max(a,-a);}
int main(void){
ll N;
cin>>N;
vector<ll> A(N);
rep(i,N) cin>>A.at(i);
sort(ALLOF(A));
ll ans=0;
rep(i,N) ans=(ans+A.at(i)*A.at(i))%mod;
ll rui=A.at(N-1);
for(ll i=N-2;i>=0;i--){
ans=(ans+A.at(i)*rui)%mod;
rui=(2*rui+A.at(i))%mod;
}
cout<<ans%mod<<endl;
return 0;
} |
/*
I love the sound you make when you shut up.
*/
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
/*-------typedefs------*/
template<class T> using ordered_set = tree<T, null_type , less<T> , rb_tree_tag , tree_order_statistics_node_update> ;
using ll = long long;
using pi = pair<int, int>;
/*-----in and out--------*/
#define pf(a) cout << a << endl
#define forIn(arr, num) for(int i = 0; i < num; i++) cin >> arr[i];
#define vpnt(ans) for(int i = 0; i < int(ans.size()); i++) cout << ans[i] << (i + 1 < int(ans.size()) ? ' ' : '\n');
/*---useful defines------*/
#define sz(x) (int)(x).size()
#define pb push_back
#define mem(a, b) memset(a,(b), sizeof(a))
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
/*----- the binary answer of life-----*/
#define no cout << "NO" << endl
#define yes cout << "YES" << endl
/*---checking and pushing-----*/
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
/*---- FAST I/O and file read ---*/
void go() {
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
}
/*-------- test-case stuff--------------*/
#define ssolve solve();
#define msolve int T;cin >> T;while(T--) {solve();}
#define mcsolve int T;cin >> T;for(int tt = 1;tt <= T;tt++) {cout << "Case #" << tt << ": ";solve();}
/*-------- movement in a 2D array ------*/
const int d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1};
const int d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1};
/*----------------------------------------------------------------*/
const int MOD = 1e9 + 7;
const int N = 2e5 + 5;
/*-------------- Push your limits here ---------------------------*/
int n, a[30], ans = 2e9;
void dfs(int x, int s1, int s2) {
if(x == n + 1) {
ckmin(ans, s1 ^ s2);
return;
}
dfs(x + 1, s1 | a[x], s2);
dfs(x + 1, a[x], s1 ^ s2);
}
void solve() {
cin >> n;
for(int i = 1;i <= n;i++) cin >> a[i];
dfs(1, 0, 0);
pf(ans);
}
int main() {
go();
ssolve
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
int N;
cin >> N;
vector<ll> A(N);
for (int i = 0; i < N; i++) cin >> A[i];
ll res = 2000000000;
for (int bit = 0; bit < (1<<N); bit++) {
stack<ll> tmp;
tmp.push(A[0]);
for (int i = 1; i < N; i++) {
if (bit & (1<<i)) tmp.top() |= A[i];
else tmp.push(A[i]);
}
ll ans = tmp.top();
tmp.pop();
while(!tmp.empty()) {
ans ^= tmp.top();
tmp.pop();
}
res = min(res, ans);
}
cout << res << endl;
} |
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define read freopen ("in.txt","r",stdin);
#define out freopen ("out.txt","w",stdout);
#define sz(x) int((x).size())
#define rep0(i,k) for (int i=0 ; i<k ; i++)
#define rep(i,k) for (int i=1 ; i<=k ; i++)
#define reset(a,b) memset(a, (b), sizeof(a))
#define sortv(k) sort(k.begin(),k.end())
#define sortg(k) sort(k.begin(),k.end(),greater<int>())
#define rev(k) reverse(k.begin(),k.end())
#define umin(a,b) a=min(a,b)
#define umax(a,b) a=max(a,b)
#define min3(a,b,c) min(a, min(b,c))
#define pyes cout<<"YES"<<endl
#define pno cout<<"NO"<<endl;
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define mpr make_pair
#define pi acos(-1.0)
typedef pair<int,int>pii;
typedef pair<ll,ll>pll;
constexpr ll imax=1e9;
constexpr ll imin=-1e9;
constexpr ll MOD=1e9+7;
const int limit=1000001;
void solution(){
ll a,b,c,d;
cin>>a>>b>>c>>d;
if(d*c-b<=0) cout<<-1;
else{
ll x=d*c-b;
ll y=a/x;
if(a%x) y++;
cout<<y;
}
return;
}
int main()
{
fast;
//read;
//out;
int tc=1;
//cin>>tc;
while(tc--) solution();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using lli = int64_t;
using ld = long double;
lli g = 10000;
lli dist(lli x1, lli y1, lli x2, lli y2)
{
return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
}
lli bsearch(lli x, lli y, lli r, lli y1, lli l, lli h, bool fl)
{
lli ans = LLONG_MAX;
while (l <= h)
{
lli mid = l + (h - l) / 2;
mid -= mid % g;
if (dist(x, y, mid, y1) <= r * r)
{
ans = mid;
(fl ? l : h) = mid + (fl ? g : -g);
}
else
(fl ? h : l) = mid + (fl ? -g : g);
}
return ans;
}
lli calc(lli x, lli y, lli r, lli y1)
{
lli rx = x;
rx -= rx % g;
lli mid = LLONG_MAX;
if (dist(x, y, rx, y1) <= r * r)
mid = rx;
else
if (dist(x, y, rx + g, y1) <= r * r)
mid = rx + g;
if (mid == LLONG_MAX) return 0;
lli rl = x - r;
lli rr = x + r;
rl -= rl % g;
rr -= rr % g;
rr += g;
lli l = bsearch(x, y, r, y1, rl, mid, false);
lli h = bsearch(x, y, r, y1, mid, rr, true);
return (h - l) / g + 1;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
ld xd, yd, rd; cin >> xd >> yd >> rd;
lli x = llroundl(xd * ld(g));
lli y = llroundl(yd * ld(g));
lli r = llroundl(rd * ld(g));
lli ans = 0;
for (lli y1 = y - y % g; y - y1 <= r; y1 -= g)
ans += calc(x, y, r, y1);
for (lli y1 = y - (y % g) + g; y1 - y <= r; y1 += g)
ans += calc(x, y, r, y1);
cout << ans << endl;
return 0;
}
|
#include<bits/stdc++.h>
#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i)
#define foreach(i, n) for(auto &i:(n))
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
#define lambda(RES_TYPE, ...) (function<RES_TYPE(__VA_ARGS__)>)[&](__VA_ARGS__) -> RES_TYPE
#define method(FUNC_NAME, RES_TYPE, ...) function<RES_TYPE(__VA_ARGS__)> FUNC_NAME = lambda(RES_TYPE, __VA_ARGS__)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(x) (void)0
#endif
namespace templates{
ll modpow(ll x, ll b){
ll res = 1;
while(b){
if(b&1)res = res * x % MOD;
x = x * x % MOD;
b>>=1;
}
return res;
}
ll modinv(ll x){
return modpow(x, MOD-2);
}
bool was_output = false;
template<class t>
void output(t a){
if(was_output)cout << " ";
cout << a;
was_output = true;
}
void outendl(){
was_output = false;
cout << endl;
}
ll in(){
ll res;
scanf("%lld", &res);
return res;
}
template<class t>
istream& operator>>(istream&is, vector<t>&x){
for(auto &i:x)is >> i;
return is;
}
template<class t, class u>
istream& operator>>(istream&is, pair<t, u>&x){
is >> x.first >> x.second;
return is;
}
template<class t>
t in(){
t res; cin >> res; return res;
}
template<class t>
void out(t x){
cout << x;
}
template<class t>
vector<t> sorted(vector<t> line,function<bool(t,t)> comp=[](t a,t b){return a<b;}){
sort(line.begin(),line.end(),comp);
return line;
}
template<class t>
vector<t> reversed(vector<t> line){
reverse(line.begin(),line.end());
return line;
}
}
using namespace templates;
ll func(){
int n = in();
int m = in();
vector<int> weights(n);
foreach(i,weights)i=in();
sort(all(weights));
vector<pll> bridge(m);
foreach(i,bridge)i=in<pll>();
ll res = INFLL;
foreach(i,weights){
foreach(bri,bridge){
if(i > bri.second){
return -1;
}
}
}
vector<ll> mins(bit(n));
rep(i,bit(n)){
ll sum = 0;
rep(j,n){
if(bit(j) & i){
sum += weights[j];
}
}
ll min_dis = 0;
foreach(bri,bridge){
if(sum > bri.second)chmax(min_dis,bri.first);
}
mins[i] = min_dis;
}
vector<int> order;
rep(i,n)order.emplace_back(i);
do{
vector<ll> pos(n);
rep(i,n){
ll min_pos = 0;
ll sum = bit(order[i]);
per(j,i){
sum += bit(order[j]);
chmax(min_pos,mins[sum]+pos[j]);
}
pos[i] = min_pos;
}
chmin(res,pos.back());
}while(next_permutation(all(order)));
if(res==INFLL)return -1;
return res;
}
int main(){
cout << func() << endl;
return 0;
}
|
using namespace std;
#define visual
#ifdef visual
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <assert.h>
#include <functional>
#include <math.h>
#include <string>
#include <ctime>
#endif
#ifndef visual
#include <bits/stdc++.h>
#endif
typedef long long ll;
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
long long n, m;
cin >> n >> m;
vector<long long> w;
long long mxw = 0;
for (long long i = 0; i < n; i++) {
long long x;
cin >> x;
mxw = max(mxw, x);
w.push_back(x);
}
vector<pair<long long, long long>> v;
v.push_back({ 0, 0 });
for (long long i = 0; i < m; i++) {
long long x, y;
cin >> x >> y;
if (y < mxw) {
cout << -1 << endl;
return 0;
}
v.push_back({y, x});
//camels with weight more than first must have length at least second
}
sort(v.begin(), v.end());
vector<pair<long long, long long> > u;
long long cur = -1;
for (long long i = 0; i < v.size(); i++) {
if (v[i].second > cur) {
u.push_back(v[i]);
//cout << v[i].first << " " << v[i].second << endl;
cur = v[i].second;
}
} //u now has increasing firsts, increasing seconds
sort(w.begin(), w.end());
ll ans = -1;
do {
vector<long long> loc(n);
for (long long i = 0; i < n; i++) {
long long bst = 0;
for (long long j = 0; j < i; j++) {
long long a;
long long tot = 0;
for (long long k = j; k <= i; k++) {
tot += w[k];
}
pair<long long, long long> p = { tot, -1 };
auto i = lower_bound(u.begin(), u.end(), p);
i--;
a = (*i).second;
//a should be minimum distance for weight of tot
bst = max(bst, loc[j] + a);
}
loc[i] = bst;
}
//cout << loc[n-1] << endl;
if (ans == -1 || loc[n-1] < ans) {
ans = loc[n-1];
}
} while (next_permutation(w.begin(), w.end()));
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define int long long
int32_t main() {
int n, m;
cin >> n >> m;
if (m < 0) {
cout << -1 << endl;
return 0;
}
else if (m > 0 && n-m < 2) {
cout << -1 << endl;
return 0;
}
vector<vector<int>> res;
int st = 1;
int mx = n-m-2;
if (m == 0)
mx = n-1;
for (int i = 0; i < mx; i++) {
res.push_back({st, st+1});
st += 2;
}
int en = st+2;
for (int i = 0; i <= m; i++) {
res.push_back({en-1, en});
en += 2;
}
if (m > 0)
res.push_back({st, en});
for (auto v: res)
cout << v[0] << " " << v[1] << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#ifndef aa
#define trace(...)
#define endl '\n'
#endif
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define fi first
#define se second
#define int long long
typedef long long ll;
typedef long double ld;
#define double long double
#define pii pair<int,int>
#define pdd pair<double,double>
#define pll pair<ll,ll>
#define sz(x) ((long long)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define frev(a,b,c) for(int a=c; a>=b; a--)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define trav(a,x) for(auto &a:x)
#define all(con) con.begin(),con.end()
#define deb(x) cout << x << endl
#define done(x) {cout << x << endl;return;}
#define mini(x,y) x=min(x,y)
#define maxi(x,y) x=max(x,y)
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
//const int mod = 998244353;
const int mod = 1e9 + 7;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<int>> vvi;
typedef vector<pair<int, int>> vpii;
typedef map<int, int> mii;
typedef set<int> si;
typedef set<pair<int,int>> spii;
typedef queue<int> qi;
const int N = 2e5+5;
void solve(){
int n, m;
cin>>n>>m;
if(n==1 && m==0)
done("1 2");
if(m<0 || m>=n-1)
done(-1);
vpii v;
v.pb({1,2*m+4});
fr(i,1,m+1)
v.pb({2*i, 2*i+1});
int cnt = 2*m+5;
while(sz(v)<n)
v.pb({cnt++,cnt++});
trav(p, v)
cout << p.fi << " " << p.se << endl;
}
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
//srand(chrono::high_resolution_clock::now().time_since_epoch().count());
cout << fixed << setprecision(15);
int t = 1;
//cin >> t;
while (t--)
solve();
#ifdef aa
cout << endl << endl << endl << endl << "Time elapsed: " << (double)(clock() - clk) / CLOCKS_PER_SEC << endl;
#endif
return 0;
}
int powm(int a, int b) {
int res = 1;
while (b) {
if (b & 1)
res = (res*a) % mod;
a = (a * a) % mod;
b >>= 1;
}
return res;
}
int divide(int a, int b) {
return (a % mod) * powm(b, mod - 2) % mod;
}
int norm(int a) {
while (a >= mod) a -= mod;
while (a < 0) a += mod;
return a;
}
int gcd(int a, int b) {
return b ? gcd(b, a % b) : a;
} |
#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;
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
#define int long long
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define g0(a) get<0>(a)
#define g1(a) get<1>(a)
#define g2(a) get<2>(a)
#define g3(a) get<3>(a)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef double db;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
int N, P;
const int MOD = 1e9 + 7;
int exp_mod(int a, int b) {
int r = 1ll;
while (b) {
if (b & 1ll) r = r * a % MOD;
a = a * a % MOD;
b >>= 1ll;
}
return r;
}
main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> N >> P;
cout << (P - 1) * exp_mod(P - 2, N - 1) % MOD << '\n';
}
| #ifndef _MSC_VER
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#endif
#pragma region
using llint = long long;
constexpr std::pair<int, int> dxy[] = { {1,0}, {0,1}, {-1,0}, {0,-1} };
#pragma endregion
namespace mtl {
template <class T, class U>
constexpr T Pow(T A, U B) noexcept {
T res = 1;
while (B) {
if (B & 1) { res *= A; }
A *= A; B >>= 1;
}
return res;
}
template <class M = int>
constexpr long long modpow(long long A, long long B, const M MOD = 1000000007) noexcept {
A %= MOD;
long long res = 1;
while (B > 0) {
if (B & 1) { res *= A; res %= MOD; }
A *= A; A %= MOD;
B >>= 1;
}
return res;
}
template <class T, class M = int>
constexpr T inverse(T A, const M MOD = 1000000007) noexcept {
T B = MOD, U = 1, V = 0;
while (B) {
T t = A / B;
A -= t * B; std::swap(A, B);
U -= t * V; std::swap(U, V);
}
U %= MOD;
return U < 0 ? U += MOD, U : U;
}
inline std::tuple<long long, long long, long long> extgcd(const long long a, const long long b) {
if (b == 0) return { a,1,0 };
long long g, x, y;
std::tie(g, x, y) = extgcd(b, a % b);
return std::make_tuple(g, y, x - a / b * y);
}
inline std::pair<long long, long long> Chinese_Rem(const std::vector<long long>& b, const std::vector<long long>& m) {
long long r = 0, M = 1;
for (int i = 0; i < (int)b.size(); ++i) {
long long p, q, d;
std::tie(d, p, q) = extgcd(M, m[i]);
if ((b[i] - r) % d != 0) return std::make_pair(0, -1);
long long tmp = (b[i] - r) / d * p % (m[i] / d);
r += M * tmp;
M *= m[i] / d;
}
return std::make_pair((r % M + M) % M, M);
}
}
constexpr llint mod = 1000000007ll;
int main() {
llint N, P; std::cin >> N >> P;
llint S = mtl::modpow(P - 1, N, mod);
llint V = mtl::modpow(mtl::inverse(P - 1, mod), N - 1, mod);
llint U = mtl::modpow(P - 2, N - 1, mod);
std::cout << (S * V % mod * U) % 1000000007ll << std::endl;
} |
/**
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡀⠀⠀⠀⠀⢀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⡖⠁⠀⠀⠀⠀⠀⠀⠈⢲⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⣼⡏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢹⣧⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⣸⣿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⣿⣇⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⣿⣿⡇⠀⢀⣀⣤⣤⣤⣤⣀⡀⠀⢸⣿⣿⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⢻⣿⣿⣔⢿⡿⠟⠛⠛⠻⢿⡿⣢⣿⣿⡟⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣀⣤⣶⣾⣿⣿⣿⣷⣤⣀⡀⢀⣀⣤⣾⣿⣿⣿⣷⣶⣤⡀⠀⠀⠀⠀
⠀⠀⢠⣾⣿⡿⠿⠿⠿⣿⣿⣿⣿⡿⠏⠻⢿⣿⣿⣿⣿⠿⠿⠿⢿⣿⣷⡀⠀⠀
⠀⢠⡿⠋⠁⠀⠀⢸⣿⡇⠉⠻⣿⠇⠀⠀⠸⣿⡿⠋⢰⣿⡇⠀⠀⠈⠙⢿⡄⠀
⠀⡿⠁⠀⠀⠀⠀⠘⣿⣷⡀⠀⠰⣿⣶⣶⣿⡎⠀⢀⣾⣿⠇⠀⠀⠀⠀⠈⢿⠀
⠀⡇⠀⠀⠀⠀⠀⠀⠹⣿⣷⣄⠀⣿⣿⣿⣿⠀⣠⣾⣿⠏⠀⠀⠀⠀⠀⠀⢸⠀
⠀⠁⠀⠀⠀⠀⠀⠀⠀⠈⠻⢿⢇⣿⣿⣿⣿⡸⣿⠟⠁⠀⠀⠀⠀⠀⠀⠀⠈⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣼⣿⣿⣿⣿⣧⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠐⢤⣀⣀⢀⣀⣠⣴⣿⣿⠿⠋⠙⠿⣿⣿⣦⣄⣀⠀⠀⣀⡠⠂⠀⠀⠀
⠀⠀⠀⠀⠀⠈⠉⠛⠛⠛⠛⠉⠀⠀⠀⠀⠀⠈⠉⠛⠛⠛⠛⠋⠁⠀⠀
* author: Daredevil666
* institution: IIT Patna
**/
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define nl cout<<"\n";
#define ll long long int
#define F(i,a,b) for(i=a;i<b;i++)
#include <ext/pb_ds/assoc_container.hpp> // policy based data structure header files
#include <ext/pb_ds/tree_policy.hpp> // policy based data structure header files
#define IOS ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
using namespace __gnu_pbds; // for pbds
#define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> // have functions like order_of_key, find_by_order
const double PI = 3.14159265358979323846264338327950288419716939937510582097494459230781641;
const ll M=1e16;
const ll MAXN=100200;
ll i,j,mask;
void solve()
{
ll n;
cin>>n;
cout<<100-(n%100);
}
int main()
{
IOS
/*#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#*/
ll t,test=1;
//cin>>test;
F(t,1,test+1)
{
//cout<<"Case #"<<t<<": ";
solve();
nl
}
return 0;
}
| #include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
ll X;
cin>>X;
ll Y=X;
Y/=100;
Y+=1;
Y*=100;
ll ans=Y-X;
cout<<ans<<endl;
} |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define DIV 998244353
#define INF LONG_MAX/3
#define bit(n) (1LL<<(n))
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
char ban[5005][5005];
ll dp[5005][5005];
long long modpow(long long ori, long long po){
long long res = 1;
while(po > 0){
if(po&1){
res *= ori;
res %= DIV;
}
ori *= ori;
ori %= DIV;
po >>= 1;
}
return res;
}
int main(){
ll H, W, K;
cin >> H >> W >> K;
rep(y, H) rep(x, W) ban[y][x] = '.';
rep(i, K) {
ll h, w;
char c;
cin >> h >> w >> c;
h--;w--;
ban[h][w] = c;
}
dp[0][0] = modpow(3, H * W - K);
ll memo = modpow(3, DIV-2);
rep(h, H) rep(w, W) {
if(ban[h][w] == 'R') {
dp[h][w+1] += dp[h][w];
dp[h][w+1] %= DIV;
} else if(ban[h][w] == 'D') {
dp[h+1][w] += dp[h][w];
dp[h+1][w] %= DIV;
} else if(ban[h][w] == 'X') {
dp[h][w+1] += dp[h][w];
dp[h][w+1] %= DIV;
dp[h+1][w] += dp[h][w];
dp[h+1][w] %= DIV;
} else {
//R
dp[h][w+1] += dp[h][w] * memo;
dp[h][w+1] %= DIV;
//D
dp[h+1][w] += dp[h][w] * memo;
dp[h+1][w] %= DIV;
//X
dp[h][w+1] += dp[h][w] * memo;
dp[h][w+1] %= DIV;
dp[h+1][w] += dp[h][w] * memo;
dp[h+1][w] %= DIV;
}
}
cout << dp[H-1][W-1] << endl;
}
| #include<bits/stdc++.h>
#include<bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define priority_queue std::priority_queue
#define F first
#define S second
ll MOD=998244353;
int h, w, k;
char g[5005][5005];
ll dp[5005][5005], emp[5005][5005], po3[200005], inv;
ll modpow(ll x, ll e){
if(x==0) return 0;
if(e==0) return 1;
ll y=modpow(x, e/2);
if(e%2==0) return (y*y)%MOD;
return ((y*y)%MOD*x)%MOD;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>h>>w>>k;
po3[0]=1;
for(int i=1;i<200005;i++){
po3[i]=(po3[i-1]*3)%MOD;
}
for(int i=0;i<=h;i++){
for(int j=0;j<=w;j++){
g[i][j]='.';
}
}
for(int i=0;i<k;i++){
int x, y;
char c;
cin>>x>>y>>c;
g[x][y]=c;
}
for(int i=1;i<=h;i++){
for(int j=1;j<=w;j++){
emp[i][j]=emp[i-1][j]+emp[i][j-1]-emp[i-1][j-1]+(g[i][j]=='.');
}
}
if(g[1][1]=='.') dp[1][1]=3;
else dp[1][1]=1;
inv=modpow(3, MOD-2);
for(int x=1;x<=h;x++){
for(int y=1;y<=w;y++){
if(x+y==2) continue;
ll c=po3[emp[x][y]-emp[x][y-1]], r=po3[emp[x][y]-emp[x-1][y]];
if(g[x][y-1]=='R' || g[x][y-1]=='X'){
dp[x][y]=(dp[x][y]+dp[x][y-1]*c)%MOD;
}
if(g[x-1][y]=='D' || g[x-1][y]=='X'){
dp[x][y]=(dp[x][y]+dp[x-1][y]*r)%MOD;
}
if(g[x][y-1]=='.'){
dp[x][y]+=(((2*inv*dp[x][y-1])%MOD)*c)%MOD;
dp[x][y]%=MOD;
}
if(g[x-1][y]=='.'){
dp[x][y]+=(((2*inv*dp[x-1][y])%MOD)*r)%MOD;
dp[x][y]%=MOD;
}
}
}
cout<<dp[h][w]<<endl;
} |
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define next Cry_For_theMoon
using namespace std;
const int MAXN=25,LIM=1<<19;
int n,m,g[MAXN][MAXN];
int f[LIM],d[LIM],ans,vis[MAXN];
inline int Min(int a,int b){
return (a<b)?a:b;
}
int main(){
scanf("%d%d",&n,&m);
ans=n;
for(int i=1;i<=n;i++){
g[i][i]=1;
}
for(int i=1,u,v;i<=m;i++){
scanf("%d%d",&u,&v);
g[u][v]=g[v][u]=1;
}
for(int i=0;i<n;i++){
f[1<<i]=1;
}
for(int i=1;i<(1<<n);i++){
if(f[i])continue;
memset(vis,0,sizeof vis);
f[i]=1;
for(int j=0;j<n;j++){
if(i&(1<<j)){
vis[j+1]=1;
}
}
for(int j=1;j<=n;j++){
if(!vis[j])continue;
for(int k=j+1;k<=n;k++){
if(!vis[k])continue;
if(!g[j][k]){
f[i]=0;
break;
}
}
if(!f[i])break;
}
}
for(int i=1;i<(1<<n);i++){
d[i]=1000;
for(int j=i;j;j=(j-1)&i){
if(!f[j])continue;
d[i]=Min(d[i],1+d[j xor i]);
}
}
printf("%d",d[(1<<n)-1]);
return 0;
} | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef tuple<int,int,int> ti;
typedef tuple<ll,ll,ll> tl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<ti> vti;
typedef vector<tl> vtl;
typedef priority_queue<int> pq;
typedef priority_queue<ti,vector<ti>,greater<ti>> pqg;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n,m;
cin>>n>>m;
vector<vpi> adj(n);
for(int i=0; i<m; i++){
int a,b;
char c;
cin>>a>>b>>c;
a--; b--;
adj[a].pb(mp(b,c-'a'));
adj[b].pb(mp(a,c-'a'));
}
vector<vector<bool>> vis(n, vector<bool>(n,false));
vis[0][n-1]=true;
pqg q;
q.push(mt(0,0,n-1));
while(!q.empty()){
int a,b,s;
tie(s,a,b)=q.top(); q.pop();
if(a==b){
cout<<s;
return 0;
}
for(auto u:adj[a]){
if(u.f==b){
vis[b][b]=true;
q.push(mt(s+1,b,b));
}
}
for(auto u:adj[a]){
for(auto v:adj[b]){
if(vis[u.f][v.f]) continue;
if(u.s==v.s){
vis[u.f][v.f]=true;
q.push(mt(s+2,u.f,v.f));
}
}
}
}
cout<<-1;
return 0;
}
|
#include <bits/stdc++.h>
#define Mod 998244353
using namespace std;
typedef long long ll;
inline int read() {
int out = 0;
bool flag = false;
register char cc = getchar();
while (cc < '0' || cc > '9') {
if (cc == '-') flag = true;
cc = getchar();
}
while (cc >= '0' && cc <= '9') {
out = (out << 3) + (out << 1) + (cc ^ 48);
cc = getchar();
}
return flag ? -out : out;
}
inline void write(int x, char ch) {
if (x < 0) putchar('-'), x = -x;
if (x == 0) putchar('0');
else {
int num = 0;
char cc[22];
while (x) cc[++num] = x % 10 + 48, x /= 10;
while (num) putchar(cc[num--]);
}
putchar(ch);
}
int fpow(int x, int y) {
int res = 1;
while (y) {
if (y & 1) res = 1ll * res * x % Mod;
x = 1ll * x * x % Mod;
y >>= 1;
}
return res;
}
int n, a[2510];
int main() {
n = read();
if (n <= 1668) {
a[1] = 6, a[n - 1] = 10, a[n] = 15;
for (int i = 1; i < n - 1; i++) a[i] = 6 * i;
}
else {
int cnt = 0;
for (int i = 1; i <= 1666; i++) if (i % 5 != 0) a[++cnt] = 6 * i;
for (int i = cnt + 1; i <= min(cnt + 1000, n - 1); i++) a[i] = 10 * (i - cnt);
cnt += 1000; if (cnt > n - 1) cnt = n - 1;
for (int i = cnt + 1, t = 1; i <= n; i++, t += 2) a[i] = 15 * t;
}
for (int i = 1; i <= n; i++) write(a[i], ' ');
return 0;
} | #include <bits/stdc++.h>
using namespace std;
//const long nPrime = 1000000007;
//const long nPrime = 998244353;
int main() {
int n;
cin >> n;
vector<long> viAns = {6,10,15};
for(long i = 2; 6*i < 10000; i++){
viAns.push_back(6*i);
}
for(long i = 2; 10*i < 10000; i++){
viAns.push_back(10*i);
}
for(long i = 2; 15*i < 10000; i++){
viAns.push_back(15*i);
}
vector<int> viCheck(10000,0);
int i = 0;
while(n>0){
if(viCheck[viAns[i]] == 0){
cout << viAns[i] << " ";
n--;
viCheck[viAns[i]] = 1;
}
i++;
}
return 0;
} |
//GIVE ME AC!!!!!!!!!!!!!!!!!
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define ll long long
#define floatset() fixed<<setprecision(15)
#define all(n) n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
#define rep(i, s, n) for (ll i = s; i < (ll)(n); i++)
using namespace std;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll inf =1e18;
const ll MOD=1000000007;
const ll mod=998244353;
const double pi=acos(-1);
using P=pair<ll,ll>;
ll dp[2500][2500];
ll add(char c){
if(c=='+'){
return 1;
}
return -1;
}
int main(){
ll h,w;
cin>>h>>w;
char c[h][w];
rep(i,0,h){
rep(j,0,w){
cin>>c[i][j];
}
}
dp[h-1][w-1]=0;
for(ll i=h-1;i>=0;i--){
for(ll j=w-1;j>=0;j--){
if(i==h-1&&j==w-1){
continue;
}
dp[i][j]=-inf;
if(i<h-1){
dp[i][j]=max(dp[i][j],add(c[i+1][j])-dp[i+1][j]);
}
if(j<w-1){
dp[i][j]=max(dp[i][j],add(c[i][j+1])-dp[i][j+1]);
}
}
}
if(dp[0][0]>0){
cout<<"Takahashi"<<endl;
}
if(dp[0][0]==0){
cout<<"Draw"<<endl;
}
if(dp[0][0]<0){
cout<<"Aoki"<<endl;
}
} | #include <algorithm>
#include <bitset>
//#include <cmath>
//#include <complex>
#include <cctype>
#include <cstdio>
#include <cstdint>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <climits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <valarray>
#include <vector>
#include <unordered_set>
#include <unordered_map>
using namespace std;
int64_t INF = LLONG_MAX;
void mod(int64_t &n){
n %= 998244353;
}
int64_t factorial(int64_t n){
if(n == 1 or n == 0){
return 1;
}else{
int64_t tmp = n*factorial(n-1);
mod(tmp);
return tmp;
}
}
//UnionFind木
class UnionFind {
private:
//xの親はparent.at(x).x==parent.at(x)ならxは根.
vector<int> parent;
public:
//コンストラクタ.parentの要素数をNで初期化.
UnionFind(int N) : parent(N, -1){
}
//再帰的にxの根を探索.この時,経路圧縮を同時に行う.
int root(int x){
if(parent.at(x) < 0){
return x;
}else{
parent.at(x) = root(parent.at(x));
return parent.at(x);
}
}
//xとyを接続.xをyの根に接続する.
void unite(int x, int y){
int rx = root(x);
int ry = root(y);
if(rx == ry){
return;
}else if(-(parent.at(rx)) > -(parent.at(ry))){
swap(rx, ry);
}
//rxのサイズ <= ryのサイズ
parent.at(ry) += parent.at(rx);
parent.at(rx) = ry;
return;
}
//xとyが同じ木に属するか判定.xの根とyの根が同じならtrue.
bool isSame(int x, int y){
return root(x) == root(y);
}
//xの属する木のサイズを取得.
int size(int x){
int rx = root(x);
return parent.at(rx) * (-1);
}
void calc(int64_t &n){
for(int i = 0; i < parent.size(); i++){
if(parent.at(i) < 0){
n *= factorial(-parent.at(i));
mod(n);
}
}
}
};
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int N, K;
cin >> N >> K;
vector<vector<int>> a(N, vector<int>(N));
for(int i = 0; i < N; i++){
for(int j = 0; j < N; j++){
cin >> a.at(i).at(j);
}
}
int64_t ans = 1;
UnionFind uf1(N);
//行スワップ
for(int i = 0; i < N; i++){
for(int j = i+1; j < N; j++){
bool flag = true;
for(int k = 0; k < N; k++){
if(a.at(i).at(k) + a.at(j).at(k) > K){
flag = false;
break;
}
}
if(flag){
uf1.unite(i, j);
}
}
}
uf1.calc(ans);
UnionFind uf2(N);
//列スワップ
for(int i = 0; i < N; i++){
for(int j = i+1; j < N; j++){
bool flag = true;
for(int k = 0; k < N; k++){
if(a.at(k).at(i) + a.at(k).at(j) > K){
flag = false;
break;
}
}
if(flag){
uf2.unite(i, j);
}
}
}
uf2.calc(ans);
cout << ans << endl;
return 0;
}
|
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
typedef long long ll;
ll i,j,k,a,b,c;
ll T,m;
ll t[10005],v[10005],f[100005];
int main()
{
cin>>a>>b;
if(b%a==0)
{
cout<<"Yes";
return 0;
}
else cout<<"No";
return 0;
}
| #include <bits/stdc++.h>
#define ig cin.ignore(numeric_limits<streamsize>::max(), '\n');
using namespace std;
int binarySearch(long long int arr[], int l, int r, int x)
{
if (r >= l) {
int mid = l + (r - l) / 2;
if (arr[mid] == x)
return mid;
if (arr[mid] > x)
return binarySearch(arr, l, mid - 1, x);
return binarySearch(arr, mid + 1, r, x);
}
return -1;
}
void solve()
{
int a,b,sum=0;
cin>>a>>b;
for(int i=1;i<=a;i++)
for(int j=1;j<=b;j++)
sum+=(i*100)+j;
cout<<sum<<endl;
}
int main(){
//int t;cin>>t;
// while(t--){
solve();
// }
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
using int64 = long long;
// const int mod = 1e9 + 7;
const int mod = 998244353;
const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;
struct IoSetup {
IoSetup() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
cerr << fixed << setprecision(10);
}
} iosetup;
template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
os << p.first << " " << p.second;
return os;
}
template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
is >> p.first >> p.second;
return is;
}
template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
for(int i = 0; i < (int) v.size(); i++) {
os << v[i] << (i + 1 != v.size() ? " " : "");
}
return os;
}
template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
for(T &in : v) is >> in;
return is;
}
template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template< typename T = int64 >
vector< T > make_v(size_t a) {
return vector< T >(a);
}
template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}
template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
t = v;
}
template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
for(auto &e : t) fill_v(e, v);
}
template< typename F >
struct FixPoint : F {
FixPoint(F &&f) : F(forward< F >(f)) {}
template< typename... Args >
decltype(auto) operator()(Args &&... args) const {
return F::operator()(*this, forward< Args >(args)...);
}
};
template< typename F >
inline decltype(auto) MFP(F &&f) {
return FixPoint< F >{forward< F >(f)};
}
int main() {
int N, M;
cin >> N >> M;
int x = 0;
for(int i = 0; i < N; i++) {
string s;
cin >> s;
x += count(begin(s), end(s), '1') % 2;
}
cout << 1LL * (N - x) * x << "\n";
} | #include <iostream>
#include <string>
int main() {
long long n,m;
std::cin >> n >> m;
long long p = 0;
for (int i = 0; i < n; i++) {
std::string s;
std::cin >> s;
int c = 0;
for (int k = 0; k < m; k++) {
if (s[k] == '1') c++;
}
if (c & 1) p++;
}
std::cout << p * (n - p) << std::endl;
return 0;
} |
#include<bits/stdc++.h>
#include<stdlib.h>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<queue>
#include<time.h>
#include <cstdio>
#include <iostream>
#include <vector>
#define ll long long
#define int long long
#define inf 0x3f3f3f3f
#define mods 1000000007
#define modd 998244353
#define PI acos(-1)
#define fi first
#define se second
#define lowbit(x) (x&(-x))
#define mp make_pair
#define pb push_back
#define si size()
#define E exp(1.0)
#define fixed cout.setf(ios::fixed)
#define fixeds(x) setprecision(x)
#define IOS ios::sync_with_stdio(false);cin.tie(0)
using namespace std;
ll gcd(ll a,ll b){if(a<0)a=-a;if(b<0)b=-b;return b==0?a:gcd(b,a%b);}
template<typename T>void read(T &res){bool flag=false;char ch;while(!isdigit(ch=getchar()))(ch=='-')&&(flag=true);
for(res=ch-48;isdigit(ch=getchar());res=(res<<1)+(res<<3)+ch - 48);flag&&(res=-res);}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
ll qp(ll a,ll b,ll mod){ll ans=1;if(b==0){return ans%mod;}while(b){if(b%2==1){b--;ans=ans*a%mod;}a=a*a%mod;b=b/2;}return ans%mod;}//快速幂%
ll qpn(ll a,ll b, ll p){ll ans = 1;a%=p;while(b){if(b&1){ans = (ans*a)%p;--b;}a =(a*a)%p;b >>= 1;}return ans%p;}//逆元 (分子*qp(分母,mod-2,mod))%mod;
ll a[11111];
ll last[11111];
ll pre[11111];
signed main(){
ll n;
read(n);
ll mi=1e9;
for(int i=1;i<=n;i++){
read(a[i]);
mi=min(mi,a[i]);
last[i]=n;
pre[i]=1;
}
ll ans=0;
for(int i=1;i<=n;i++){
for(int j=i-1;j>=1;j--){
if(a[j]<a[i]){
pre[i]=j+1;
break;
}
}
for(int j=i+1;j<=n;j++){
//i=L
if(a[j]<a[i]){
last[i]=j-1;
break;
}
}
}
for(int i=1;i<=n;i++){
ll len=last[i]-pre[i]+1;
ans=max(ans,len*a[i]);
}
printf("%lld",ans);
}
| #include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define f(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
#define pb push_back
using namespace std;
void test(){
ll n;
cin>>n;
ll a[n];
f(i,n)cin>>a[i];
ll res = a[0];
f(i,n){
ll c = 0, s = a[i];
for(int j=i;j<n;j++){
c++;
s = min(s,a[j]);
res = max(res,s*c);
}
}
cout<<res<<"\n";
}
int main(){
std::ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int tests=1;
// cin>>tests;
while(tests--){
test();
}
}
|
#include <iostream>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int T;
cin >> T;
while(T--)
{
int n;
cin >> n;
string s[3];
cin >> s[0] >> s[1] >> s[2];
int ones = 0, zeros = 0;
cout << 1;
for(int i = 1; i <= n; i++) cout << 0;
for(int i = 1; i <= n; i++) cout << 1;
cout << endl;
}
return 0;
}
| #include<bits/stdc++.h>
#define ll long long
#define N 200005
using namespace std;
int n,a[N],b[N],p[N],ans,sx[N],sy[N],z[N],zz,mx,mxid;
bool vis[N];
void dfs(int x)
{
if(vis[x])return;
z[++zz]=x;
vis[x]=1;
if(a[x]>mx)
{
mx=a[x];
mxid=x;
}
dfs(p[x]);
}
int main()
{
#ifdef lovelyG
Sfile(1);
#endif
scanf("%d",&n);
for(int i=1;i<=n;++i)scanf("%d",&a[i]);
for(int i=1;i<=n;++i)scanf("%d",&b[i]);
for(int i=1;i<=n;++i)scanf("%d",&p[i]);
for(int x,i=1;i<=n;++i)
{
if(vis[i])continue;
zz=mx=0;
dfs(i);
x=mxid;
while(p[x]!=x)
{
if(b[p[x]]>=a[x]||b[p[p[x]]]>=a[p[x]])
{
puts("-1");
return 0;
}
sx[++ans]=x;
sy[ans]=p[x];
swap(p[x],p[p[x]]);
}
}
printf("%d\n",ans);
for(int i=1;i<=ans;++i)
printf("%d %d\n",sx[i],sy[i]);
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 };
ll a1, b1, a2, b2;
signed main(){
cin >> a1 >> b1 >> a2 >> b2;
if((a1+b1)%2 == (a2+b2)%2){
if(a1 == a2 && b1 == b2){
cout << 0 << endl;
}
else if(a1+b1 == a2+b2 || a1-b1 == a2-b2 || abs(a1-a2)+abs(b1-b2) <= 3){
cout << 1 << endl;
}
else{
cout << 2 << endl;
}
}
else{
if(abs(a1-a2)+abs(b1-b2) <= 3){
cout << 1 << endl;
}
else if(abs((a1+b1)-(a2+b2)) <= 3 || abs((a1-b1)-(a2-b2)) <= 3 || abs(a1-a2)+abs(b1-b2) <= 6){
cout << 2 << endl;
}
else{
cout << 3 << endl;
}
}
} | #include <bits/stdc++.h>
using namespace std;
using ll=long long;
using pp=pair<int,int>;
const ll INF=1e9;
const ll mod=1e9+7;
int main() {
int a, b, c, d;
cin >> a >> b >> c >> d;
int x=c-a, y=d-b;
int s;
if (x==0 && y==0) {s=0; goto OUT;}
else if (abs(x)==abs(y) || (abs(x)<=2 && abs(y)<=2) || (abs(x)==3 && y==0) || (abs(y)==3 && x==0)) {
s=1;
goto OUT;
}
else if (x%2==y%2) {s=2; goto OUT;}
else {
queue<pp> Q;
for (int i=-2; i<=2; i++) {
for (int j=-2; j<=2; j++) {
Q.push(pp(x+i,y+j));
}
}
Q.push(pp(x,y+3));
Q.push(pp(x,y-3));
Q.push(pp(x+3,y));
Q.push(pp(x-3,y));
while (Q.size()>0) {
pp q=Q.front();
Q.pop();
x=q.first;
y=q.second;
if (abs(x)==abs(y) || (abs(x)<=2 && abs(y)<=2) || (abs(x)==3 && y==0) || (abs(y)==3 && x==0)) {
s=2;
goto OUT;
}
}
}
s=3;
OUT:
cout << s << endl;
} |
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
static const ll mod=1000000007;
ll H,W;
char f[2005][2005];
ll modpow(ll x,ll y){
if(y==0)
return 1;
else if(y%2==0){
ll z=modpow(x,y/2);
return (z*z)%mod;
}else{
ll z=modpow(x,y/2);
return (x*((z*z)%mod))%mod;
}
}
ll sum[2005][2005];
int main(){
cin>>H>>W;ll K=0;
for(ll i=0;i<H;i++){
string s;cin>>s;
for(ll j=0;j<W;j++){
f[i][j]=s[j];
if(f[i][j]=='.')K++;
}
}
for(ll i=0;i<H;i++){
ll x=0;
for(ll j=0;j<W;j++){
if(f[i][j]=='#')
x=0;
else{
x++;sum[i][j]+=x;
}
}
} for(ll j=0;j<W;j++){
ll x=0;
for(ll i=H-1;0<=i;i--){
if(f[i][j]=='#')
x=0;
else{
x++;sum[i][j]+=x;
}
}
} for(ll i=0;i<H;i++){
ll x=0;
for(ll j=W-1;0<=j;j--){
if(f[i][j]=='#')
x=0;
else{
x++;sum[i][j]+=x;
}
}
} for(ll j=0;j<W;j++){
ll x=0;
for(ll i=0;i<H;i++){
if(f[i][j]=='#')
x=0;
else{
x++;sum[i][j]+=x;
}
}
}ll ans=0;ll k=modpow(2,K);
for(ll i=0;i<H;i++)
for(ll j=0;j<W;j++)
if(f[i][j]!='#'){
ll y=sum[i][j]-3;
ll x=(k-modpow(2,K-y)+mod)%mod;
ans=(ans+x)%mod;
}cout<<ans<<endl;
return 0;
} | #include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;
template<int M>
class ModInt {
public:
ll value;
constexpr ModInt(ll v = 0) { value = v % M; if (value < 0) value += M; }
constexpr ModInt pow(ll n) const { if (!n) return 1; ModInt a = pow(n >> 1); a *= a; if (n & 1) a *= *this; return a; }
constexpr ModInt inv() const { return this->pow(M - 2); }
constexpr ModInt operator + (const ModInt &rhs) const { return ModInt(*this) += rhs; };
constexpr ModInt operator - (const ModInt &rhs) const { return ModInt(*this) -= rhs; };
constexpr ModInt operator * (const ModInt &rhs) const { return ModInt(*this) *= rhs; };
constexpr ModInt operator / (const ModInt &rhs) const { return ModInt(*this) /= rhs; };
constexpr ModInt &operator += (const ModInt &rhs) { value += rhs.value; if (value >= M) value -= M; return *this; };
constexpr ModInt &operator -= (const ModInt &rhs) { value -= rhs.value; if (value < 0) value += M; return *this; };
constexpr ModInt &operator *= (const ModInt &rhs) { value = value * rhs.value % M; return *this; };
constexpr ModInt &operator /= (const ModInt &rhs) { return (*this) *= rhs.inv(); };
constexpr bool operator == (const ModInt &rhs) { return value == rhs.value; }
constexpr bool operator != (const ModInt &rhs) { return value != rhs.value; }
friend ostream &operator << (ostream &os, const ModInt &rhs) { os << rhs.value; return os; }
};
using mint = ModInt<MOD>;
int main() {
int H, W; cin >> H >> W;
vector<string> S(H);
REP(i, 0, H) cin >> S[i];
int tot = 0;
vector<vector<int>> R(H, vector<int>(W, 0)), C(H, vector<int>(W, 0));
REP(i, 0, H) REP(j, 0, W) {
if (S[i][j] == '#') continue;
R[i][j] = 1 + ((j > 0) ? R[i][j - 1] : 0);
C[i][j] = 1 + ((i > 0) ? C[i - 1][j] : 0);
tot++;
}
REP(i, 0, H) for (int j = W - 1; j > 0; j--) if (R[i][j] && R[i][j - 1]) R[i][j - 1] = R[i][j];
REP(j, 0, W) for (int i = H - 1; i > 0; i--) if (C[i][j] && C[i - 1][j]) C[i - 1][j] = C[i][j];
mint ans = 0;
REP(i, 0, H) REP(j, 0, W) {
if (S[i][j] == '#') continue;
// cout << "#(" << i << "," << j << ") : " << R[i][j] << ", " << C[i][j] << endl;
int cnt = R[i][j] + C[i][j] - (R[i][j] && C[i][j]);
ans += (mint(2).pow(cnt) - 1) * mint(2).pow(tot - cnt);
}
cout << ans << endl;
return 0;
} |
/**
* @FileName d.cpp
* @Author kanpurin
* @Created 2020.10.10 22:08:23
**/
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
template< int MOD >
struct mint {
public:
long long x;
mint(long long x = 0) :x((x%MOD+MOD)%MOD) {}
mint(std::string &s) {
long long z = 0;
for (int i = 0; i < s.size(); i++) {
z *= 10;
z += s[i] - '0';
z %= MOD;
}
this->x = z;
}
mint& operator+=(const mint &a) {
if ((x += a.x) >= MOD) x -= MOD;
return *this;
}
mint& operator-=(const mint &a) {
if ((x += MOD - a.x) >= MOD) x -= MOD;
return *this;
}
mint& operator*=(const mint &a) {
(x *= a.x) %= MOD;
return *this;
}
mint& operator/=(const mint &a) {
long long n = MOD - 2;
mint u = 1, b = a;
while (n > 0) {
if (n & 1) {
u *= b;
}
b *= b;
n >>= 1;
}
return *this *= u;
}
mint operator+(const mint &a) const {
mint res(*this);
return res += a;
}
mint operator-() const {return mint() -= *this; }
mint operator-(const mint &a) const {
mint res(*this);
return res -= a;
}
mint operator*(const mint &a) const {
mint res(*this);
return res *= a;
}
mint operator/(const mint &a) const {
mint res(*this);
return res /= a;
}
friend std::ostream& operator<<(std::ostream &os, const mint &n) {
return os << n.x;
}
friend std::istream &operator>>(std::istream &is, mint &n) {
long long x;
is >> x;
n = mint(x);
return is;
}
bool operator==(const mint &a) const {
return this->x == a.x;
}
mint pow(long long k) const {
mint ret = 1;
mint p = this->x;
while (k > 0) {
if (k & 1) {
ret *= p;
}
p *= p;
k >>= 1;
}
return ret;
}
};
constexpr int MOD = 1e9 + 7;
int main() {
int t;cin >> t;
while(t--) {
ll n,a,b;cin >> n >> a >> b;
if (b > a) swap(a,b);
ll m = min(n-a,b-1);
auto k = (mint<MOD>(2) * (n-a+1)*m-mint<MOD>(m)*(m+1)+mint<MOD>(a-b+1)*(n-a+1));
auto p = mint<MOD>(n-a+1)*(n-b+1);
cout << p * p - k * k << endl;
}
return 0;
} | #include <cstdio>
#include <cctype>
#define rr register
using namespace std;
const int N=111;
int f[N],siz[N],x[N],y[N],n;
inline signed iut(){
rr int ans=0,f=1; rr char c=getchar();
while (!isdigit(c)) f=(c=='-')?-f:f,c=getchar();
while (isdigit(c)) ans=(ans<<3)+(ans<<1)+(c^48),c=getchar();
return ans*f;
}
inline signed getf(int u){return f[u]==u?u:f[u]=getf(f[u]);}
inline void uni(int x,int y){
rr int fa=getf(x),fb=getf(y);
if (fa==fb) return;
if (siz[fa]>siz[fb]) fa^=fb,fb^=fa,fa^=fb;
siz[fb]+=siz[fa],f[fa]=fb;
}
inline bool check(double mid){
for (rr int i=1;i<n+3;++i) f[i]=i,siz[i]=1;
for (rr int i=1;i<=n;++i){
if (mid*2>100-y[i]) uni(i,n+1);
if (y[i]+100<2*mid) uni(i,n+2);
for (rr int j=i+1;j<=n;++j)
if ((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j])<mid*mid*4)
uni(i,j);
}
return getf(n+1)==getf(n+2);
}
signed main(){
n=iut();
for (rr int i=1;i<=n;++i)
x[i]=iut(),y[i]=iut();
rr double l=0,r=100;
while (l+1e-6<r){
rr double mid=(l+r)/2;
if (check(mid)) r=mid;
else l=mid;
}
return !printf("%lf",l);
} |
#include "bits/stdc++.h"
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,mmx,avx,avx2")
using namespace std;
using ll = long long;
const int mod = 1e9+7;
ll ans = 0;
array<int, 61> dfs(auto &g, int u, int par, auto &pref, auto &sz)
{
sz[u] = 1;
array<int, 61> ret{};
int tot = 0;
for (auto [v, w] : g[u]) {
if (v == par) continue;
pref[v] = pref[u] ^ w;
auto child = dfs(g, v, u, pref, sz);
sz[u] += sz[v];
for (int i = 0; i < 61; ++i) {
ll mul = 1LL << i; mul %= mod;
ll ct = 1LL*child[i]*(tot-ret[i]) + 1LL*(sz[v]-child[i])*ret[i];
ct %= mod;
ans += mul*ct; ans %= mod;
ret[i] += child[i];
}
tot += sz[v];
}
for (int i = 0; i < 61; ++i) {
ll mul = 1LL << i; mul %= mod;
ll ct = 0;
if ((pref[u]>>i)&1) {
ct = sz[u]-1-ret[i];
++ret[i];
}
else {
ct = ret[i];
}
ct %= mod;
ans += mul*ct; ans %= mod;
}
return ret;
}
int main()
{
ios::sync_with_stdio(0); cin.tie(0);
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
int n; cin >> n;
vector<vector<array<ll, 2>>> g(n);
for (int i = 0; i < n-1; ++i) {
int u, v; cin >> u >> v;
ll w; cin >> w;
g[--u].push_back({--v, w});
g[v].push_back({u, w});
}
vector<ll> pref(n);
vector<int> sz(n);
dfs(g, 0, 0, pref, sz);
cout << ans;
} | #include <bits/stdc++.h>
#define int long long
using namespace std;
int n,m,dis[1001001],mod=1e9+7,u,v,w,num,ans;
struct node
{
int v,w;
}t;
vector<node>g[1001001];
void dfs(int u,int fa)
{
for(int i=0;i<g[u].size();i++)
{
int v=g[u][i].v;
if(g[u][i].v==fa)
continue;
dis[v]=dis[u]^g[u][i].w;
dfs(v,u);
}
}
signed main()
{
scanf("%lld",&n);
for(int i=1;i<+n;i++)
{
scanf("%lld%lld%lld",&u,&v,&w);
t.v=v;
t.w=w;
g[u].push_back(t);
t.v=u;
g[v].push_back(t);
}
dfs(1,0);
for(int j=60;j>=0;j--)
{
num=0;
for(int i=1;i<=n;i++)
if((dis[i]&(1ll<<j))>0)
num++;
ans=(ans+(((1ll<<j)%mod)*num%mod)*(n-num)%mod)%mod;
}
cout<<ans;
return 0;
} |
// Author: Pawan Raj
// Problem: D - Shipping Center
// Contest: AtCoder - Panasonic Programming Contest (AtCoder Beginner Contest 195)
// URL: https://atcoder.jp/contests/abc195/tasks/abc195_d
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define int long long
#define F(i, n) for (int i = 0; i < n; i++)
#define all(x)(x).begin(), (x).end()
#define show(A) for (auto i: A) cout << i << " "; cout << '\n';
#define show_(A, n) F(i, n) { show(A[i]) }
using namespace std;
using ld = long double;
using vi = vector < int > ;
using mi = map < int, int > ;
using pi = pair < int, int > ;
const int N = 100005;
const int MOD = 1e9 + 7;
const int inf = 1e18 + 1;
/***************************code begins here*****************************/
void solve() {
int n, m, q;
cin >> n >> m >> q;
pi a[n];
int b[m];
F(i,n) cin >> a[i].fi >> a[i].se;
F(i,m) cin >> b[i];
while(q--){
int ans = 0;
vi aa;
vi vis(n,0);
int l,r; cin >> l >> r;
for(int i=0;i<m;i++){
if(i >= (l-1) && i<r) continue;
aa.pb(b[i]);
}
sort(all(aa));
// show(aa);
for(int x : aa){
int c = -1;
F(i,n){
if(vis[i]) continue;
if(a[i].fi <= x){
if(c==-1) c = i;
if(a[c].se < a[i].se) c = i;
}
}
// cout << c << '\n';
if(c == -1) continue;
ans += a[c].se;
vis[c] = 1;
}
cout << ans << '\n';
}
}
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin >> t;
while (t--) solve();
return 0;
} | #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define fore(i_in,a) for (auto& i_in: a)
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fio() cin.tie(nullptr);ios::sync_with_stdio(false);
#define DEBUG_CTN(v) cerr<<#v<<":";for(auto itr=v.begin();itr!=v.end();itr++) cerr<<" "<<*itr; cerr<<endl
template<class T> bool chmax(T &a, const T &b) {if (a<b) { a = b; return true; } return 0;}
template<class T> bool chmin(T &a, const T &b) {if (a>b) { a = b; return true; } return 0;}
template<class T> void print(const T &t) { cout << t << "\n"; }
const ll INF = 1LL << 62;
const int iINF = 1 << 30;
int h,w,a,b;
int used[16][16];
int dfs(int x, int y, int n){
if(y==h) return n==0;
if(x==w) return dfs(0,y+1,n);
if(used[y][x]) return dfs(x+1,y,n);
int res = 0;
if(y+1<h and !used[y+1][x] and 0<n){
used[y][x] = used[y+1][x] = 1;
res += dfs(x+1,y,n-1);
used[y][x] = used[y+1][x] = 0;
}
if(x+1<w and !used[y][x+1] and 0<n){
used[y][x] = used[y][x+1] = 1;
res += dfs(x+1,y,n-1);
used[y][x] = used[y][x+1] = 0;
}
res += dfs(x+1,y,n);
return res;
}
int main() {
fio(); cin>>h>>w>>a>>b;
int ans = dfs(0,0,a);
print(ans);
}
|
#include <bits/stdc++.h>
using namespace std;
struct __INIT
{
__INIT()
{
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
}
} __init;
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
//#define INF (1<<30)
#define LINF (lint)(1LL << 56)
#define endl "\n"
#define rep(i, n) for (lint(i) = 0; (i) < (n); (i)++)
#define reprev(i, n) for (lint(i) = (n - 1); (i) >= 0; (i)--)
#define flc(x) __builtin_popcountll(x)
#define pint pair<int, int>
#define pdouble pair<double, double>
#define plint pair<lint, lint>
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define vec vector<lint>
#define nep(x) next_permutation(all(x))
typedef long long lint;
int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int MAX_N = 3e5 + 5;
constexpr int MOD = 1000000007;
typedef __int128_t llint;
int main(void)
{
int N, M, Q;
cin >> N >> M >> Q;
pint itm[N];
rep(i, N) cin >> itm[i].se >> itm[i].fi;
sort(itm, itm + N, greater<pint>());
int X[M];
rep(i, M) cin >> X[i];
while (Q--)
{
int L, R;
cin >> L >> R;
L--, R--;
vector<int> box;
rep(i, M) if (i < L || i > R) box.push_back(X[i]);
sort(all(box));
int ans = 0;
rep(i, N)
{
rep(j, box.size())
{
if (itm[i].se <= box[j])
{
ans += itm[i].fi, box[j] = 0;
break;
}
}
}
cout << ans << endl;
}
} | #include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rel register ll
#define rec register char
#define gc getchar
// #define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<23,stdin),p1==p2)?-1:*p1++)
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
char buf[1<<23],*p1=buf,*p2=buf;
inline int read(){
int x=0,f=1;char c=gc();
for (;!isdigit(c);c=gc()) f^=c=='-';
for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
return f?x:-x;
}
template <typename mitsuha>
inline bool read(mitsuha &x){
x=0;int f=1;char c=gc();
for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';
if (!~c) return 0;
for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
return x=f?x:-x,1;
}
template <typename mitsuha>
inline int write(mitsuha x){
if (!x) return 0&pc(48);
if (x<0) pc('-'),x=-x;
int bit[20],i,p=0;
for (;x;x/=10) bit[++p]=x%10;
for (i=p;i;--i) pc(bit[i]+48);
return 0;
}
inline char fuhao(){
char c=gc();
for (;isspace(c);c=gc());
return c;
}
}using namespace chtholly;
using namespace std;
const int yuzu=2e5;
typedef int fuko[yuzu|10];
fuko a,b;
int main() {
int i,n,m,c1,c2,j;
read(n),read(m);
for (i=1;i<=n;++i) a[i]=read();
for (i=1;i<=m;++i) b[i]=read();
for (i=1;i<=1e3;++i) {
c1=c2=0;
for (j=1;j<=n;++j) c1+=a[j]==i;
for (j=1;j<=m;++j) c2+=b[j]==i;
!c1&&c2||!c2&&c1?printf("%d ",i):0;
}
} |
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <random>
#include <chrono>
#include <tuple>
#include <random>
#include <cmath>
using namespace std;
typedef long long ll;
typedef long double ld;
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
const ll SZ = 2e5 + 100, INF = 1e9 * 1e9 + 10, MOD = 998244353;
vector<ll> vec1, vec2;
vector<pair<ll, ll>> v1, v2;
ll fnd(int j) {
int l = 0, r = v1.size();
while (r - l > 1) {
int mid = (l + r) / 2;
int newps = v1[mid].first - abs(j - mid);
if (newps >= v1[j].second) {
r = mid;
}
else {
l = mid;
}
}
return r;
}
ll get() {
vector<ll> c1, c2;
v1.clear();
for (int i = 0; i < vec1.size() - 1; i++) {
ll dir = 0, dir2 = 0;
if (vec1[i] < vec2[i]) dir = 1;
if (vec1[i] > vec2[i]) dir = 2;
if (vec1[i + 1] < vec2[i + 1]) dir2 = 1;
if (vec1[i + 1] > vec2[i + 1]) dir2 = 2;
if (dir == 1 || dir == 0) {
v1.push_back({ vec1[i], vec2[i] });
}
if (dir == 1 && dir2 == 2) {
cout << "-1";
exit(0);
}
}
v1.push_back({ vec1.back(), vec2.back() });
ll ans = 0;
ll upd = -1;
for (int i = 0; i < v1.size(); i++) {
if (upd != -1) {
v1[i].first = v1[upd].first - abs(upd - i);
if (upd == i) upd = -1;
}
if (v1[i].first == v1[i].second) continue;
auto it = lower_bound(v1.begin(), v1.end(), v1[fnd(i)]);
if (upd == -1 || (it - v1.begin()) >= upd) {
upd = (it - v1.begin());
if (v1[i].second != v1[(it - v1.begin())].first - abs(i - (it - v1.begin()))) {
cout << "-1";
exit(0);
}
ans += abs(i - (it - v1.begin()));
}
else {
ll j = (it - v1.begin());
v1[j].first = v1[upd].first - abs(upd - j);
if (v1[i].second != v1[(it - v1.begin())].first - abs(i - (it - v1.begin()))) {
cout << "-1";
exit(0);
}
ans += abs(i - (it - v1.begin()));
}
}
return ans;
}
int main()
{
fastInp;
ll n, l;
cin >> n >> l;
vec1.resize(n);
vec2.resize(n);
for (auto &cur : vec1) cin >> cur;
for (auto &cur : vec2) cin >> cur;
vec1.insert(vec1.begin(), 0);
vec2.insert(vec2.begin(), 0);
vec1.push_back(l + 1);
vec2.push_back(l + 1);
ll q = get();
for (int i = 0; i < vec1.size(); i++) {
vec1[i] = l + 1 - vec1[i];
vec2[i] = l + 1 - vec2[i];
}
reverse(vec1.begin(), vec1.end());
reverse(vec2.begin(), vec2.end());
ll k = q + get();
cout << k;
return 0;
} | #include <bits/stdc++.h>
#define fo(a,b,c) for (a=b; a<=c; a++)
#define fd(a,b,c) for (a=b; a>=c; a--)
#define min(a,b) (a<b?a:b)
#define ll long long
//#define file
using namespace std;
int a[100002],b[100002],n,L,i,j,k,l,sum;
ll ans;
void Exit() {printf("-1\n");exit(0);}
int main()
{
#ifdef file
freopen("c.in","r",stdin);
#endif
scanf("%d%d",&n,&L);
fo(i,1,n) scanf("%d",&a[i]);
fo(i,1,n) scanf("%d",&b[i]);
a[0]=0,a[n+1]=L+1;
b[0]=0,b[n+1]=L+1;
l=0;
fo(i,0,n)
if (b[i]+1<b[i+1])
{
sum=0;
while (l<=n && a[l]+1==a[l+1]) ++l;
k=min(l,i);
while (l<=n && sum<b[i+1]-b[i]-1)
sum+=a[l+1]-a[l]-1,++l;
if (sum>b[i+1]-b[i]-1) Exit();
ans+=max(l,i+1)-k-1;
}
printf("%lld\n",ans);
fclose(stdin);
fclose(stdout);
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double pi = acos(-1);
const int maxn = 2e6 + 10;
const double eps = 1e-8;
const ll mod = 1e9 + 7;
const ull base = 131;
const ull mod1 = 1e9 + 9;
const ull mod2 = 1610612741;
ll x, y, a, b;
int main() {
scanf("%lld%lld%lld%lld", &x, &y, &a, &b);
ll ans = 0;
ll k = b/(a-1);
while (x <= k && x*a < y) x *= a, ++ans;
if (x < y) ans += (y-x-1)/b;
printf("%lld\n", ans);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (long long i = 0; i < (long long)(n); i++)
typedef long long ll;
const ll mod=1e9+7;
typedef pair<int,int> P;
const int INF=1<<29;
int main(){
double a,b;
cin>>a>>b;
cout<<fixed<<setprecision(10);
cout<<a*b/100<<endl;
} |
#include <iostream>
#include <vector>
#include <utility>
#include<algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <random>
#include <tuple>
#include <set>
#define ll long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main(){
ll t,n;
cin >> t;
cin >> n;
ll ans = n-1+(100*n)/t;
if((100*n)%t != 0){
ans ++;
}
cout << ans << endl;
return 0;
} | #include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cfenv>
#include <cmath>
using namespace std;
int main() {
double t, N;
cin >> t >> N;
double A = ceil(N * 100 / t);
double B = floor(t * (A - 1.0) / 100);
long long C = (long long)A + (long long)B;
cout << C << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
int n,w;
cin >> n >> w;
cout << n/w << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define stp(var, init, end) for (auto var = init; var < end; ++var)
#define stpe(var, init, end) for (auto var = init; var <= end; ++var)
#define ll long long
int main(void)
{
string a, b;
cin >> a >> b;
int sa = 0, sb = 0;
stp(i, 0, 3)
{
sa += a[i] - '0';
sb += b[i] - '0';
}
cout << max(sa, sb);
return 0;
} |
/* winners never quit and quitters never win.
#swap */
#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;
#pragma GCC optimize ("-O3")
using ll = long long;
using ld = long double;
const ll mod = 1000000007;
const ll inf = 1000000000000000000;
const ll rk = 256;
const ld PI = 3.141592653589793;
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
template <typename T>
void make_unique(vector<T>& vec) {
sort(all(vec));
vec.erase(unique(all(vec)), vec.end());
}
#define endl '\n'
#define pb push_back
#define mp make_pair
#define vc vector
#define fs first
#define sec second
#define pql priority_queue<ll>
#define pqh priority_queue<ll,vc<ll>,greater<ll>>
#define lb lower_bound
#define ub upper_bound
#define pll pair<ll,ll>
#define pls pair<ll,string>
#define psl pair<string,ll>
#define plc pair<ll,char>
#define pcl pair<char,ll>
#define pss pair<string,string>
#define all(x) (x).begin(), (x).end()
#define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper);
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << endl;
err(++it, args...);
}
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define T ll t=0;cin>>t;for(ll test=0;test<t;test++)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll nxt() {
ll TemporaryVariable;
cin >> TemporaryVariable;
return TemporaryVariable;
}
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
// http://xorshift.di.unimi.it/splitmix64.c
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
//isprime();
//coeff();
/*freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);*/
ll n=nxt();
string s;
cin>>s;
string s1="110";
ll ans=0;
rep(a,0,3)
{
bool flag=true;
rep(b,a,a+n)
{
if(s1[b%3]!=s[b-a])
flag=false;
}
if(flag)
{
ll tot=(a+n+2)/3;
ans+=10000000000-tot+1;
}
}
cout<<ans<<endl;
printclock;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1000000007;
int main() {
int n;
cin >> n;
string t;
cin >> t;
if (t == "0") {
cout << 10000000000 << endl;
return 0;
}
if (t == "1") {
cout << 20000000000 << endl;
return 0;
}
if (t == "10") {
cout << 10000000000 << endl;
return 0;
}
if (t == "01") {
cout << 9999999999 << endl;
return 0;
}
if (t == "11") {
cout << 10000000000 << endl;
return 0;
}
ll zero = 0;
if (t[0] == '0') {
zero = 0;
} else if (t[1] == '0') {
zero = 1;
} else if (t[2] == '0') {
zero = 2;
} else {
cout << 0 << endl;
return 0;
}
for (int i = 0; i < n; ++i) {
if (i % 3 == zero && t[i] == '0') continue;
if (i % 3 != zero && t[i] == '1') continue;
cout << 0 << endl;
return 0;
}
ll m = (n + 2 - zero + 2) / 3;
cout << 10000000000 - m + 1 << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#define INF 1000000000
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define EPS 10e-9
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define st first
#define nd second
#define sz(v) int(v.size())
#define all(X) (X).begin(), (X).end()
#define FOR(I, A, B) for(int I = A; I < B; I++)
#define RFOR(I, A, B) for(int I = A; I >= B; I--)
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef vector<iii> viii;
typedef vector<ll> vll;
ll PD[205][205];
ll comb(ll k, ll n){
if(k == 0) return 1;
if(k == n) return 1;
ll &mem = PD[k][n];
if(mem != -1) return mem;
return mem = comb(k-1, n-1) + comb(k, n-1);
}
int main(){
ll l;
cin >> l;
memset(PD, -1, sizeof PD);
cout << comb(11, l-1) << endl;
return 0;
}
| //Code by Mukul Totla
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
void sublime(){
#ifndef ONLINE_JUDGE
freopen ("input.txt", "r", stdin);
freopen ("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
}
int main()
{
sublime();
string s;
ll i;
cin>>s;
if(s.length()==1)
{
if(s=="8")
cout<<"Yes";
else
cout<<"No";
}
else if(s.length()==2)
{
map<char,ll>mp;
for(i=0; i<s.length(); i++)
mp[s[i]]++;
int f=0;
for(i=16; i<=100; i+=8)
{
map<char,ll>m;
string str=to_string(i);
m[str[0]]++;
m[str[1]]++;
if(mp[str[0]]>=m[str[0]] && mp[str[1]]>=m[str[1]])
{
f=1;
break;
}
}
if(f==1)
cout<<"Yes";
else
cout<<"No";
}
else
{
map<char,ll>mp;
for(i=0; i<s.length(); i++)
mp[s[i]]++;
int f=0;
for(i=104; i<1000; i+=8)
{
map<char,ll>m;
string str=to_string(i);
m[str[0]]++;
m[str[1]]++;
m[str[2]]++;
if(mp[str[0]]>=m[str[0]] && mp[str[1]]>=m[str[1]]
&& mp[str[2]]>=m[str[2]])
{
f=1;
break;
}
}
if(f==1)
cout<<"Yes";
else
cout<<"No";
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int main(void){
int64_t a,b;
cin >> a >> b;
cout << max(2*a+100-b,0L) << endl;
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
#define NL '\n'
#define sz(x) x.size()
#define INF LONG_MAX
#define IINF LLONG_MAX
#define PI (2.0*acos(0.0))
#define sfi(x) scanf("%d",&x)
#define sfi2(x,y) scanf("%d %d",&x,&y)
#define sfi3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define sfl(x) scanf("%lld",&x)
#define sfl2(x,y) scanf("%lld %lld",&x,&y)
#define sfl3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define sfd(x) scanf("%lf",&x);
#define sfd2(x,y) scanf("%lf %lf",&x,&y);
#define max3(a,b,c) max(a,max(b,c))
#define max4(a,b,c,d) max(max3(a,b,c),d)
#define min3(a,b,c) min(a,min(b,c))
#define min4(a,b,c,d) min(a,min3(b,c,d))
#define fi first
#define se second
#define PB push_back
#define MP make_pair
#define For(i, j, k) for(int i = j; i <= k; i++)
#define Rof(i, j, k) for(int i = j; i >= k; i--)
#define all(x) x.begin(),x.end()
#define asort(x) sort(all(x));
#define dsort(x) sort(all(x), greater<int>())
#define unq(x) x.erase(unique(x.begin(),x.end()),x.end())
#define mem(ara,val) memset(ara,val,sizeof(ara))
#define READ freopen("input.txt","r",stdin)
#define WRITE freopen("output.txt","w",stdout)
#define IOS ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0)
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair <int,int> PII;
typedef pair <LL,LL> PLL;
LL gcd(LL a,LL b) { return b==0 ? a : gcd(b,a%b); }
LL lcm(LL a,LL b) { return (a/gcd(a,b))*b; }
int main()
{
// int t; sfi(t); For(tt,1,t){
//
//
// }
int a, b;
sfi2(a,b);
printf("%d\n", max(((2*a)+100)-b,0));
// main();
}
|
#pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include<stdio.h>
constexpr long long MOD = 998244353;
constexpr long long MOD32 = 665496236;
int main(){
long H=0, W=0, K=0;
char c=getchar_unlocked();
while(c<='9'&&c>='0') {H=(H<<1)+(H<<3)+c-'0'; c=getchar_unlocked();}
c=getchar_unlocked();
while(c<='9'&&c>='0') {W=(W<<1)+(W<<3)+c-'0'; c=getchar_unlocked();}
c=getchar_unlocked();
while(c<='9'&&c>='0') {K=(K<<1)+(K<<3)+c-'0'; c=getchar_unlocked();}
char f[H][W];
for(int i = 0;i < H;++i) for(int j = 0;j < W;++j) f[i][j] = '\0';
long long y = H * W - K;
while(--K>=0){
long h=0, w=0;
c=getchar_unlocked();
while(c<='9'&&c>='0') {h=(h<<1)+(h<<3)+c-'0'; c=getchar_unlocked();}
c=getchar_unlocked();
while(c<='9'&&c>='0') {w=(w<<1)+(w<<3)+c-'0'; c=getchar_unlocked();}
f[h-1][w-1] = getchar_unlocked();
getchar_unlocked();
}
--H; --W;
long long dp[W+1] = {0};
dp[0] = 1;
for(int i = 0; i < H; ++i){
for (int j = 0; j < W; ++j){
switch(f[i][j]) {
case 'R':
dp[j + 1] += dp[j];
dp[j] = 0;
break;
case '\0':
dp[j] = dp[j] * MOD32 % MOD;
case 'X':
dp[j + 1] += dp[j];
}
}
switch(f[i][W]) {
case 'R':
dp[W] = 0;
break;
case '\0':
dp[W] = dp[W] * MOD32 % MOD;
}
}
for (int j = 0; j < W; ++j){
switch(f[H][j]) {
case '\0':
dp[j] = dp[j] * MOD32 % MOD;
case 'R':
case 'X':
dp[j + 1] += dp[j];
}
}
long long ans = dp[W] % MOD;
long long x = 3;
while(y) {
if(y & 1) ans = ans * x % MOD;
x = x * x % MOD;
y >>= 1;
}
printf("%d", ans);
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
const int N=5010;
int dp[N][N];
char ma[N][N];
int row[N][N],col[N][N];
int po[N*N];
const int P=998244353;
const int inv2=P-P/2;
const int inv3=(P-P/3ll)*inv2%P;
int main(){
int H,W;
cin>>H>>W;
int K;cin>>K;
po[0]=1;
for(int i=1;i<=H*W;i++){
po[i]=(3ll*po[i-1])%P;
}
while(K--){
int x,y;
cin>>x>>y;
cin>>ma[x][y];
}
for(int i=1;i<=H;i++){
for(int j=1;j<=W;j++){
row[i][j]=row[i][j-1]+(!ma[i][j]);
}
}
for(int j=1;j<=W;j++){
for(int i=1;i<=H;i++){
col[i][j]=col[i-1][j]+(!ma[i][j]);
}
}
for(int i=1;i<=H;i++){
for(int j=1;j<=W;j++){
if(i==1&&j==1){
dp[i][j]=po[!ma[i][j]];
}
if(ma[i][j]){
if(ma[i][j]=='R'){
(dp[i][j+1]+=1ll*dp[i][j]*po[col[i][j+1]]%P)%=P;
}
else if(ma[i][j]=='D'){
(dp[i+1][j]+=1ll*dp[i][j]*po[row[i+1][j]]%P)%=P;
}
else {
(dp[i+1][j]+=1ll*dp[i][j]*po[row[i+1][j]]%P)%=P;
(dp[i][j+1]+=1ll*dp[i][j]*po[col[i][j+1]]%P)%=P;
}
}
else {
//cout<<dp[i][j]<<' '<<row[i+1][j]-1<<' '<<col[i][j+1]-1<<endl;
//cout<<2ll*dp[i][j]*po[row[i+1][j]-1]<<' '<<2ll*dp[i][j]*po[col[i][j+1]-1]<<endl;
(dp[i+1][j]+=2ll*dp[i][j]*po[row[i+1][j]]%P*inv3%P)%=P;
(dp[i][j+1]+=2ll*dp[i][j]*po[col[i][j+1]]%P*inv3%P)%=P;
}
//cout<<dp[i][j]<<' ';
}
//cout<<endl;
}
cout<<dp[H][W];
} |
#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(const string& s) {
return '"' + s + '"';
}
string to_string(const char* s) {
return to_string((string) s);
}
string to_string(bool b) {
return (b ? "true" : "false");
}
string to_string(vector<bool> v) {
bool first = true;
string res = "{";
for (int i = 0; i < static_cast<int>(v.size()); i++) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(v[i]);
}
res += "}";
return res;
}
template <size_t N>
string to_string(bitset<N> v) {
string res = "";
for (size_t i = 0; i < N; i++) {
res += static_cast<char>('0' + v[i]);
}
return res;
}
template <typename A>
string to_string(A v) {
bool first = true;
string res = "{";
for (const auto &x : v) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(x);
}
res += "}";
return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
#define fi first
#define se second
#define pb push_back
#define mod(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,a,b) for(int i = a; i < b; i++)
#define forr(i,a,b) for(int i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
const int mod = 1e9+7;
int sum(int a, int b){return (a+b) % mod;}
int sub(int a, int b){return (a + mod - b) % mod;}
int mul(int a, int b){return (1ll * a * b) % mod;}
int power(int a,int b){
int res = 1;
while(b){
if(b&1)res = mul(res,a);
b >>= 1;
a = mul(a,a);
}
return res;
}
const int maxn = 10;
int N,P,A[maxn];
//int res;
//void dfs(int pos){
//if(pos >= N){
//int act = 0;
//bool can = true;
//forn(i,0,N){
//act += A[i];
//if(act%P == 0){
//can = false;
//break;
//}
//}
//res += (can == true);
//return;
//}
//forn(i,1,P){
//A[pos] = i;
//dfs(pos+1);
//}
//}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> N >> P;
//dfs(0);
//cout << res << '\n';
int res = mul(P-1,power(P-2,N-1));
cout << res << '\n';
return 0;
}
/*
__builtin_mul_overflow(x,y,&x)
-fsplit-stack
*/
| #include"bits/stdc++.h"
//#include"atcoder.h"
#include<iostream>
using namespace std;
typedef long long ll;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
const ll inf = ll(1e18) + 1;
const ll mod = 1000000007;
int main() {
int N;
string S;
cin >> N >> S;
string V;
for (int i = 0; i < N; i++) {
V.push_back(S.at(i));
if (V.size() >= 3) {
int index = V.size() - 1;
if (V.at(index) == 'x' && V.at(index - 1) == 'o' && V.at(index - 2) == 'f') {
V.erase(index - 2, 3);
}
}
}
//cout << V << endl;
cout << V.size() << endl;
} |
#include <iostream>
#include <vector>
#include <algorithm> //sort,二分探査など
//#include<bitset>
//#include<cmath>//pow,logなど
//#include<deque>
//#include<functional>
//#include<iterator>
//#include<map>
//#include<numeric>//gcd,lcm
//#include<queue>
//#include<set>
//#include<stack>
//#include<string>
//#include<utility>//pair
//QCFium法
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
//浮動小数点処理高速化
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
using i64 = int64_t;
using f80 = __float80;
using u64 = uint_fast64_t;
constexpr i64 INF = 1010000000000000017LL;
constexpr u64 MOD = 1000000007LL;
constexpr f80 PI = 3.14159265358979323846;
#define _overload3(_1, _2, _3, name, ...) name
#define repi(i, start, end) for (int i = (int)(start); i < (int)(end); ++i)
#define _rep(i, n) repi(i, 0, n)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define rrep(i, start, end) for (int i = (int)(start); i > (int)(end); --i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define vvv(T) v(v(v(T)))
typedef v(int) vi;
#define show(x) cout << #x << " = " << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T>>
template <class T>
inline bool chmax(T &a, T b)
{
if (a < b)
{
a = b;
return true;
}
return false;
}
template <class T>
inline bool chmin(T &a, T b)
{
if (a > b)
{
a = b;
return true;
}
return false;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
rep(i, v.size()) os << v[i] << (i + 1 != v.size() ? " " : "");
return os;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v)
{
for (T &in : v)
is >> in;
return is;
}
//sort(rng(P),[](const vi &a, const vi &b){return a[1]<b[1];});
void Main()
{
i64 A, B, C;
cin >> A >> B >> C;
i64 ans = A * (A + 1) / 2;
i64 m = 998244353;
ans %= m;
ans *= (B * (B + 1) / 2) % m;
ans %= m;
ans *= (C * (C + 1) / 2) % m;
ans %= m;
cout << ans << "\n";
}
int main()
{
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
// cout << fixed << setprecision(15);
Main();
} | #include <iostream>
//#include <vector>
//#include <string>
//#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>
// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>
typedef long long LL;
//typedef long double LD;
using namespace std;
//#define MOD 1000000007
#define MOD 998244353
//#define MAX 100100
//#define NIL -1
//#define INFTY 1000000000000000000
int main(){
LL a;
LL b;
LL c;
LL ans;
cin >> a >> b >> c;
ans=(a*(a+1)/2)%MOD;
ans=(ans*((b*(b+1)/2)%MOD))%MOD;
ans=(ans*((c*(c+1)/2)%MOD))%MOD;
cout << ans << endl;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long n;
cin>>n;
long long tmp=n;
long long num=0;
long long len=1;
bool flag=true;
while(tmp>0){
if(flag&&tmp%10==0) len*=10;
else flag=false;
num=num*10+tmp%10;
tmp/=10;
}
num*=len;
cout<<(num==n?"Yes":"No")<<endl;
return 0;
} | #include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long
#define all(x) (x).begin(),(x).end()
using namespace std;
template<typename KeyType, typename ValueType>
std::pair<KeyType,ValueType> get_max( const std::map<KeyType,ValueType>& x ) {
using pairtype=std::pair<KeyType,ValueType>;
return *std::max_element(x.begin(), x.end(), [] (const pairtype & p1, const pairtype & p2) {
return p1.second < p2.second;
});
}
const int mod=1e9+7;
void solve()
{
string s;
cin>>s;
string temp=s;
reverse(temp.begin(),temp.end());
stringstream ss(temp);
int g=0;
ss>>g;
string ans=to_string(g);
string rev=ans;
reverse(rev.begin(),rev.end());
if(rev==ans)
{
cout<<"Yes";
}
else
{
cout<<"No";
}
return;
}
int main()
{
solve();
}
|
//#include <bits/stdc++.h>
//using namespace std;
#include <cstdio>
#include <vector>
using namespace std;
#define rep(i,_l,_r) for(signed i=(_l),_end=(_r);i<=_end;++i)
#define fep(i,_l,_r) for(signed i=(_l),_end=(_r);i>=_end;--i)
#define erep(i,u) for(signed i=head[u],v=to[i];i;i=nxt[i],v=to[i])
#define efep(i,u) for(signed i=Head[u],v=to[i];i;i=nxt[i],v=to[i])
#define print(x,y) write(x),putchar(y)
//#define debug(...) do {cerr<<__LINE__<<" : ("#__VA_ARGS__<<") = "; Out(__VA_ARGS__); cerr<<flush;} while(0)
//template <typename T> void Out(T x) {cerr<<x<<"\n";}
//template <typename T,typename ...I> void Out(T x,I ...NEXT) {cerr<<x<<", "; Out(NEXT...);}
template <class T> inline T read(const T sample) {
T x=0; int f=1; char s;
while((s=getchar())>'9'||s<'0') if(s=='-') f=-1;
while(s>='0'&&s<='9') x=(x<<1)+(x<<3)+(s^48),s=getchar();
return x*f;
}
template <class T> inline void write(const T x) {
if(x<0) return (void) (putchar('-'),write(-x));
if(x>9) write(x/10);
putchar(x%10^48);
}
template <class T> inline T Max(const T x,const T y) {if(x>y) return x; return y;}
template <class T> inline T Min(const T x,const T y) {if(x<y) return x; return y;}
template <class T> inline T fab(const T x) {return x>0?x:-x;}
template <class T> inline T gcd(const T x,const T y) {return y?gcd(y,x%y):x;}
template <class T> inline T lcm(const T x,const T y) {return x/gcd(x,y)*y;}
template <class T> inline T Swap(T &x,T &y) {x^=y^=x^=y;}
typedef long long ll;
typedef pair <int,ll> Pair;
const int maxn=2e5+5,mod=1e9+7;
int n,ans;
ll dep[maxn];
vector <Pair> g[maxn];
void dfs(int u,int fa) {
for(int i=0;i<g[u].size();++i) {
int v=g[u][i].first;
if(v==fa) continue;
dep[v]=(dep[u]^g[u][i].second);
dfs(v,u);
}
}
int main() {
n=read(9);
rep(i,1,n-1) {
int u=read(9),v=read(9); ll w=read(9ll);
g[u].push_back(make_pair(v,w)),g[v].push_back(make_pair(u,w));
}
dfs(1,0);
rep(i,0,60) {
int cnt=0;
rep(j,1,n) if(dep[j]>>i&1) ++cnt;
ans=(ans+1ll*(1ll<<i)%mod*cnt%mod*(n-cnt)%mod)%mod;
}
print(ans,'\n');
return 0;
} |
#include<bits/stdc++.h>
#define fi first
#define se second
#define INF 100000000000000000LL
#define ll long long
#define debug(x) cout << #x << " "<< x <<endl;
#define debug_vector(v) cout << #v << " "; _print(v);
const ll inf =1e9+44;
const int MAX=3e5+9;
const ll MOD= 1e9+7;
const double eps=1e-10;
double const PI=3.1415926535897931;
using namespace std;
int dx[4] = {1 ,0 , - 1, 0};
int dy[4] = {0 ,1 , 0 , -1};
void _print(vector<int> v){
cout << "[ ";
for ( auto u : v)
cout << u << " ";
cout << " ]"<< endl;
}
ll x[MAX];
vector < pair<int , ll > >adj[MAX];
ll arr[MAX];
void dfs(int u , int p ){
for(auto v : adj[u]){
if(v.first == p)
continue;
x[v.first] = x[u]^v.second;
dfs(v.first , u);
}
}
int main(){
int n;
cin >> n;
for(int i = 0 ; i <n-1 ;i++){
int x, y;
ll w;
cin >> x >> y >> w;
adj[x].push_back( { y , w});
adj[y].push_back( { x, w });
}
dfs( 1 , 0 );
ll ans = 0;
for ( ll j = 0 ; j <=60 ; j++){
ll o = 0 , z = 0;
for (int i = 1 ; i <= n ; i++){
if (x[i]&(1ll<<j))
o ++;
else
z ++;
// cout << x[i] << endl;
}
//cout << z <<" " <<o << endl;
z = (z*o+MOD)%MOD;
ans = ans + (1ll<<j)%MOD*z%MOD+MOD;
ans = ans%MOD;
}
cout << ans;
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define Test int T;cin>>T;while(T--)
#define ls lower_bound
#define up upper_bound
#define bs binary_search
#define S second
#define F first
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pii>
#define vvi vector<vi>
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define m_n(v) *min_element(all(v))
#define m_x(v) *max_element(all(v))
#define _(a) for(auto &i:a)
#define nl cout<<"\n";
#define momo(k) memset(k,0,sizeof(k))
#define momi(k) memset(k,-1,sizeof(k))
// #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds;
// typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>indexed_set;
int power(int x, int y,int mod){
int res = 1;
while (y){
if (y & 1)
res = (res*x)%mod;
y = y>>1;
x = (x*x)%mod;
}
return res;
}
int modInverse(int a, int m){
int m0 = m;
int y = 0, x = 1;
if (m == 1) return 0;
while (a > 1){
int q = a / m;
int t = m;
m = a % m, a = t;
t = y;
y = x - q * y;
x = t;
}
if (x < 0) x += m0;
return x;
}
int binomial(int n,int k){
int res = 1;
if ( k > n - k ) k = n - k;
for (int i = 0; i < k; ++i){
res *= (n - i);
res /= (i + 1);
}
return res;
}
// vector<int> prime;
// void sieve(){
// bool arr[30000]={0};
// prime.pb(2);
// for(int i=3;i<30000;i+=2){
// if(arr[i])continue;
// for(int j=i*i;j<30000;j+=i) arr[j]=1;
// prime.pb(i);
// }
// }
// const int N=1e18+2;
const int mod = 998244353;
const int N = 2e5+9;
void doper(){
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
freopen("error.txt","w",stderr);
#endif
}
int32_t main(){
// doper();
IOS;
int n;
cin>>n;
string s;
cin>>s;
stack<char> st;
for(auto i:s){
if(i == 'x' and st.size()>0){
if(st.top() == 'o' and st.size()>1){
bool flag = 0;
st.pop();
if(st.top() == 'f' ) {
st.pop();
flag = 1;
}
if(flag == 0){
st.push('o');
st.push(i);
}
}else st.push(i);
}else st.push(i);
}
cout<<st.size();
// while(!st.empty()){
// cout<<st.top();nl;
// st.pop();
// }
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define d(x) cout<<x<<" "
#define nl cout<<endl
#define rep(var,init_val,final_val) for(int var = init_val; var < final_val; ++var)
#define tt ll t;cin>>t;while(t--)
#define show(a,b) rep(i,0,b) d(a[i]);nl;
#define mod 1000000007
#define vi vector<int>
#define pii pair<int,int>
const int d4i[] = {-1,0,1,0};
const int d4j[] = {0,1,0,-1};
const int d8i[] = {-1,-1,-1,0,1,1,1,0};
const int d8j[] = {-1,0,1,1,1,0,-1,-1};
// #define ONLINE_JUDGE true
void solve(){
//cout<<"HELLO\n";
int n;
string s ,ans;
cin>>n>>s;
ans=s;
int j = 0;
rep(i,0,n){
//cout<<i<<endl;
ans[j]=s[i];
j++;
if(j<3) continue;
if(ans.substr(j-3,3)=="fox") j-=3;
//cout<<ans<<" "<<j<<endl;
}
cout<<j<<endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
solve();
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
long long n,K,T[3000000];
long long f(long long a){
if(a<2)return 0;
else if(a<=n+1)return a-1;
else if(a<=n+n)return n+n+1-a;
else return 0;
}
long long S(long long k){
if(k<0) return 0;
else if(k<n) return (k+2)*(k+1)/2;
else if(k<2*n-2)return (9*n-3*n*n+6*k*n-6*k-2*k*k-4)/2;
else if (k<3*n-2) return (3*n-k-1)*(3*n-k-2)/2;
else return 0;
}
int main(){
cin >> n >> K;
T[0]=1;
for(long long i=1;i<3*n-2;i++){
T[i]=T[i-1]+S(i);
}
long long lb = -1;
long long ub = 3*n-2;
while(ub - lb>1){
long long mid = (lb+ub)/2;
if(T[mid]>=K) ub = mid;
else lb = mid;
}
ub+=3;
K-=T[lb];
for(long long a=1;a<=ub-2;a++){
K-=f(ub-a);
if(K<=0){
if(ub-a>=n+1){
cout << a << " " << n+K << " " << ub-a-n-K << endl;
}else{
cout << a << " " << ub-a-1+K << " " << 1-K << endl;
}
break;
}
}
return 0;
} | // Problem: B - -- - B
// Contest: AtCoder - AtCoder Regular Contest 112
// URL: https://atcoder.jp/contests/arc112/tasks/arc112_b
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
#define pb push_back
#define mp make_pair
const double PI = 4*atan(1);
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9+7;
const int MAX_N = 2e6+10;
ll B, C;
void solve()
{
if(!C) cout<<1<<'\n';
else if(!B) cout << C << '\n';
else{
// *-1 ----- *-1
ll L1 = B-C/2, R1 = B+(C>=2?(C-2)/2:0);
ll L2 = -B-(C-1)/2,R2=-B+(C-1)/2;
if(R1<L2 || R2<L1){
cout<<R1+R2-L1-L2+2<<'\n';
}else{
cout<<max(R1,R2)-min(L1,L2)+1<<'\n';
}
}
}
int main()
{
cin >> B >> C;
solve();
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 998244353;
int p(int a, int b) {
if (b == 0) return 1;
int tmp = p(a, b / 2);
if (b % 2 == 0) return (tmp * tmp)%mod;
return ((tmp * tmp)%mod * a)%mod;
}
int n, m;
int sum[5001];
int val[5001][5001];
int pow_m[5001];
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
pow_m[0] = 1;
for (int i = 1; i <= 5000; i++)
pow_m[i] = (pow_m[i - 1] * m) % mod;
for (int j = 0; j <= m - 1; j++) {
int tmp = 1;
for (int i = 0; i <= n - 2; i++) {
(sum[i] += tmp) %= mod;
(tmp *= j) %= mod;
}
}
for (int i = 1; i <= n ; i++)
for (int j = 1; j < i - 1; j++)
val[i][j] = sum[i - j - 1];
int ans = 0;
for (int i = 1; i <= n; i++)
for (int j = 1; j < i; j++) {
if (j == i - 1)
(ans += m * pow_m[n - 2] % mod ) %= mod;
else
(ans += pow_m[n - i + j - 1] * val[i][j] % mod ) %= mod;
}
ans = ((n * p(m, n) % mod - ans)%mod + mod)%mod;
cout << ans;
}
| #include <bits/stdc++.h>
template <int MOD_> struct modnum {
static constexpr int MOD = MOD_;
static_assert(MOD_ > 0, "MOD must be positive");
private:
using ll = long long;
int v;
static int minv(int a, int m) {
a %= m;
assert(a);
return a == 1 ? 1 : int(m - ll(minv(m, a)) * ll(m) / a);
}
public:
modnum() : v(0) {}
modnum(ll v_) : v(int(v_ % MOD)) { if (v < 0) v += MOD; }
explicit operator int() const { return v; }
friend std::ostream& operator << (std::ostream& out, const modnum& n) { return out << int(n); }
friend std::istream& operator >> (std::istream& in, modnum& n) { ll v_; in >> v_; n = modnum(v_); return in; }
friend bool operator == (const modnum& a, const modnum& b) { return a.v == b.v; }
friend bool operator != (const modnum& a, const modnum& b) { return a.v != b.v; }
modnum inv() const {
modnum res;
res.v = minv(v, MOD);
return res;
}
friend modnum inv(const modnum& m) { return m.inv(); }
modnum neg() const {
modnum res;
res.v = v ? MOD-v : 0;
return res;
}
friend modnum neg(const modnum& m) { return m.neg(); }
modnum operator- () const {
return neg();
}
modnum operator+ () const {
return modnum(*this);
}
modnum& operator ++ () {
v ++;
if (v == MOD) v = 0;
return *this;
}
modnum& operator -- () {
if (v == 0) v = MOD;
v --;
return *this;
}
modnum& operator += (const modnum& o) {
v -= MOD-o.v;
v = (v < 0) ? v + MOD : v;
return *this;
}
modnum& operator -= (const modnum& o) {
v -= o.v;
v = (v < 0) ? v + MOD : v;
return *this;
}
modnum& operator *= (const modnum& o) {
v = int(ll(v) * ll(o.v) % MOD);
return *this;
}
modnum& operator /= (const modnum& o) {
return *this *= o.inv();
}
friend modnum operator ++ (modnum& a, int) { modnum r = a; ++a; return r; }
friend modnum operator -- (modnum& a, int) { modnum r = a; --a; return r; }
friend modnum operator + (const modnum& a, const modnum& b) { return modnum(a) += b; }
friend modnum operator - (const modnum& a, const modnum& b) { return modnum(a) -= b; }
friend modnum operator * (const modnum& a, const modnum& b) { return modnum(a) *= b; }
friend modnum operator / (const modnum& a, const modnum& b) { return modnum(a) /= b; }
};
template <typename T> T pow(T a, long long b) {
assert(b >= 0);
T r = 1; while (b) { if (b & 1) r *= a; b >>= 1; a *= a; } return r;
}
int main() {
using namespace std;
ios_base::sync_with_stdio(false), cin.tie(nullptr);
using num = modnum<998244353>;
int N, M; cin >> N >> M;
num ans = 0;
for (int v = 1; v <= M; v++) {
num cnt_open = 0;
num tot_open = 0;
num cnt_closed = 1;
num tot_closed = 0;
for (int i = 0; i < N; i++) {
num nxt_cnt_open = cnt_open * (M-v);
num nxt_tot_open = tot_open * (M-v);
num nxt_cnt_closed = cnt_closed * (M-v);
num nxt_tot_closed = tot_closed * (M-v);
// If the value is == v, must open
{
nxt_cnt_open += cnt_open;
nxt_tot_open += tot_open;
nxt_cnt_open += cnt_closed;
nxt_tot_open += tot_closed + cnt_closed;
}
// If the value is < v, must close
{
nxt_cnt_closed += cnt_open * (v-1);
nxt_tot_closed += tot_open * (v-1);
nxt_cnt_closed += cnt_closed * (v-1);
nxt_tot_closed += tot_closed * (v-1);
}
cnt_open = nxt_cnt_open;
tot_open = nxt_tot_open;
cnt_closed = nxt_cnt_closed;
tot_closed = nxt_tot_closed;
}
ans += tot_open + tot_closed;
}
cout << ans << '\n';
return 0;
}
// For each value v, we need to do
|
#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int h,w;
cin>>h>>w;
//(i,j)から a[i][j][k]にいける
vector<vector<vector<pair<int,int>>>>go(h,vector<vector<pair<int,int>>>(w,vector<pair<int,int>>(0)));
go.push_back(vector<vector<pair<int,int>>>(26,vector<pair<int,int>>(0)));
pair<int,int>S,G;
vector<vector<char>>a(h,vector<char>(w));
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
cin>>a[i][j];
if(a[i][j]=='S'){S={i,j};}
else if(a[i][j]=='G'){G={i,j};}
else if(a[i][j]!='.'&&a[i][j]!='#'){
go[i][j].push_back({h,a[i][j]-'a'});
go[h][a[i][j]-'a'].push_back({i,j});
}
}
}
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
if(a[i][j]=='#')continue;
if(i>0&&a[i-1][j]!='#')go[i][j].push_back({i-1,j});
if(i<h-1&&a[i+1][j]!='#')go[i][j].push_back({i+1,j});
if(j>0&&a[i][j-1]!='#')go[i][j].push_back({i,j-1});
if(j<w-1&&a[i][j+1]!='#')go[i][j].push_back({i,j+1});
}
}
//cout<<"ok\n";
vector<vector<int64_t>>cost(h,vector<int64_t>(w,1e18));
cost.push_back(vector<int64_t>(26,1e18));
cost[S.first][S.second]=0;
queue<pair<int,int>>bfs;
bfs.push(S);
pair<int,int>n;
while(bfs.size()){
n=bfs.front();
bfs.pop();
if(n.first==h){
for(int i=0,l=go[h][n.second].size();i<l;i++){
if(cost[go[h][n.second][i].first][go[h][n.second][i].second]>cost[h][n.second]){
cost[go[h][n.second][i].first][go[h][n.second][i].second]=cost[h][n.second];
bfs.push({go[h][n.second][i].first,go[h][n.second][i].second});
}
}
}else{
int i=n.first,j=n.second;
for(int k=0,l=go[i][j].size();k<l;k++){
if(cost[go[i][j][k].first][go[i][j][k].second]>cost[i][j]+1){
cost[go[i][j][k].first][go[i][j][k].second]=cost[i][j]+1;
bfs.push({go[i][j][k].first,go[i][j][k].second});
}
}
}
}
/*
for(int i=0;i<h;i++){
for(int j=0;j<w;j++)cout<<cost[i][j]<<' ';
cout<<'\n';
}
*/
cout<<(cost[G.first][G.second]==1e18?-1:cost[G.first][G.second])<<'\n';
} | #include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;
//typedef pair<int,int> P;
double const PI=3.141592653589793;
int const INF=1001001001;
ll const LINF=1001001001001001001;
ll const MOD=998244353;
struct unionFind{
int* par; //親
int* rank; //木の深さ
int* scale; //木のサイズ
unionFind(int n);
~unionFind();
int find(int x); //木の根を求める
void unite(int x,int y); //xとyの属する集合を併合
bool same(int x,int y); //xとyが同じ集合に属するか否か
int size(int x); //xの属する集合のサイズ
};
unionFind::unionFind(int n){
par=new int[n];
rank=new int[n];
scale=new int[n];
for(int i=0;i<n;i++){
par[i]=i;
rank[i]=0;
scale[i]=1;
}
}
unionFind::~unionFind(){
delete[] par;
delete[] rank;
delete[] scale;
}
int unionFind::find(int x){
if(par[x]==x) return x;
return par[x]=find(par[x]);
}
void unionFind::unite(int x,int y){
x=find(x);
y=find(y);
if(x==y) return;
if(rank[x]<rank[y]){
par[x]=y;
scale[y]+=scale[x];
}else{
par[y]=x;
scale[x]+=scale[y];
if(rank[x]==rank[y]) rank[x]++;
}
}
bool unionFind::same(int x,int y){
return find(x)==find(y);
}
int unionFind::size(int x){
x=find(x);
return scale[x];
}
ll mfrac(ll n){
if(n==0) return 1;
else return n*mfrac(n-1)%MOD;
}
ll N,K;
ll a[50][50];
int main(){
cin>>N>>K;
rep(i,N) rep(j,N) cin>>a[i][j];
unionFind ufr(N);
unionFind ufc(N);
rep(x,N-1){
for(int y=x+1;y<N;y++){
bool c=true, r=true;
rep(i,N){
c&=a[i][x]+a[i][y]<=K;
r&=a[x][i]+a[y][i]<=K;
}
if(c) ufc.unite(x,y);
if(r) ufr.unite(x,y);
}
}
vector<bool> chkr(N,true);
vector<bool> chkc(N,true);
ll cntr=1;
ll cntc=1;
rep(i,N){
if(chkr[ufr.find(i)]){
cntr*=mfrac(ufr.size(i));
cntr%=MOD;
chkr[ufr.find(i)]=false;
}
if(chkc[ufc.find(i)]){
cntc*=mfrac(ufc.size(i));
cntc%=MOD;
chkc[ufc.find(i)]=false;
}
}
ll ans=cntr*cntc%MOD;
cout<<ans<<endl;
} |
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define even(x) (x % 2 == 0 ? true : false)
#define odd(x) (x % 2 ? true : false)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned;
using pii = pair<int, int>;
//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;
//const int mod = 1000000007;
//vector<vector<int>> dp(m, vector<int>(n));
void solve()
{
int n;
cin >> n;
map<int, string> mp;
for (int i = 0; i < n; i++) {
string s;
int t;
cin >> s >> t;
mp[t] = s;
}
int i = 0;
for (auto p : mp) {
i++;
if (i == n - 1) {
cout << p.second << endl;
return ;
}
}
}
int main(void)
{
ios::sync_with_stdio(0);
cin.tie(0);
solve();
}
| #include <bits/stdc++.h>
using namespace std;
int main(){
int N;
cin >> N;
vector<string> S(N);
vector<int> T(N);
for(int i=0; i<N; i++) cin >> S.at(i) >> T.at(i);
vector<int> t(N);
for(int i=0; i<N; i++) t.at(i) = T.at(i);
sort(t.begin(),t.end());
int ans;
for(int i=0; i<N; i++){
if(T.at(i) == t.at(N-2)) ans = i;
}
cout << S.at(ans) << endl;
} |
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;
void Main() {
ll n;
R n;
vector<ll> a(n+1,0);
rep(i,n) R a[i];
sort(all(a));
a.erase(unique(all(a)),a.end());
ll ans=1;
rrep(i,a.size()-1) {
ans*=a[i+1]-a[i]+1;
ans%=MAX;
}
pr(ans);
}
int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}
| #include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ii pair<int,int>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<ii>
#define ar array
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const int maxn = 2e5+10;
const int mod = 1e9+7;
using namespace std;
void solve(){
double s1,s2,g1,g2;
cin >> s1 >> s2 >> g1 >> g2;
double ans = (g2*s1+s2*g1)/(s2+g2);
cout << setprecision(10) << ans << endl;
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin >> t;
while(t--){
solve();
}
return 0;
}
|
// radhey krishna
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
template<typename T> T sqr(const T &x) {
return x * x;
}
#define endl "\n"
int mx[31] , mn[31];
void solve(){
ll a ,b ,c ,d;
cin>>a>>b>>c>>d;
ll flag = 0;
if(a == b+c+d){
flag = 1;
}
if(b == a+c+d){
flag =1;
}
if(c == a+b+d){
flag =1;
}
if(a + b == c + d){
flag = 1;
}
if(b + c == a + d){
flag = 1;
}
if(d + b == a + c){
flag = 1;
}
if(a + b + c == d){
flag = 1;
}
if(flag == 1){
cout<<"Yes"<<endl;
}
else{
cout<<"No"<<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(false);
cin.tie(NULL);
int t =1 ;
//cin>>t;
while(t--){
solve();
}
} | #include<bits/stdc++.h>
using namespace std;
#define int long long
int32_t main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
vector<int> v(4);
int ans = 0;
for(int i=0;i<4;i++){
cin>>v[i];
ans+=v[i];
}
for(int i=1;i<8;i++){
int curr = 0;
for(int j=0;j<4;j++){
if(i&(1ll<<j)){
curr+=v[j];
}
}
if(curr == ans - curr){
cout<<"Yes\n";
exit(0);
}
}
cout<<"No\n";
return 0;
} |
#include<stdio.h>
int main()
{
int N,K,M,i,sum = 0;
scanf("%d %d %d",&N,&K,&M);
int ar[N-1];
for(i=0;i < N-1;i++)
{
scanf("%d",&ar[i]);
sum += ar[i];
}
if((sum/N) >= M)
{
printf("0\n");
}
else if(((sum+K)/N)< M)
{
printf("-1\n");
}
else
{
printf("%d\n",((N*M)-sum));
}
return 0;
} | #include<iostream>
using namespace std;
int main()
{
int N,K,M,t;
cin>>N;
cin>>K;
cin>>M;
int sum=0;
for(int i=0;i<N-1;i++){
cin>>t;
sum=sum+t;
}
int check=N*M-sum;
if(check<0)
cout<<0;
else if(check<=K && check>=0)
cout<<check;
else
cout<<-1;
return 0;
} |
#include <bits/stdc++.h>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include <numeric>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0 ; i < n ; i++)
#define Rep(i,n) for(int i = 1 ; i <= n ; i++)
const int maxn=2e5+5;
const ll mod = 1e9 + 7;
const bool DEBUG = 0;
int main(){
int a,b,ans;
cin >> a >> b;
int sum = 500500;
Rep(i,a){
if( i < a ){
cout << i << ' ';
sum = sum - i;
}else{
cout << sum << ' ';
}
}
sum = 500500;
Rep(i,b){
if( i < b){
cout << -i << ' ';
sum = sum - i;
}else{
cout << -sum << ' ';
}
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int a, b;
vector<int> ans;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
while (cin >> a >> b) {
int sum = 0;
ans.clear();
if (a >= b) {
for (int i = 1; i <= a; i++) ans.push_back(i), sum += i;
for (int i = 1; i < b; i++) ans.push_back(-i), sum -= i;
ans.push_back(-sum);
} else {
for (int i = 1; i <= b; i++) ans.push_back(-i), sum -= i;
for (int i = 1; i < a; i++) ans.push_back(i), sum += i;
ans.push_back(-sum);
}
for (int i = 1; i < a + b; i++) cout << ans[i - 1] << ' ';
cout << ans[a + b - 1] << '\n';
}
return 0;
} |
//#include<bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <iterator>
#include <string.h>
#include <vector>
#include <utility>
#include <map>
//#pragma GCC optimize "trapv"
#define int long long
#define For(i,a,b) for(int i=a;i<b;i++)
#define pb push_back
#define endl "\n"
#define F first
#define S second
#define dracarys ios_base::sync_with_stdio(false);cin.tie(NULL)
#define all(v) v.begin(),v.end()
#define TEST_CASE int t;cin>>t;while(t--)
#define debug(...) cout<<#__VA_ARGS__<<" = "; print(__VA_ARGS__);
using namespace std;
const int MOD = 1e9 + 7;
void print() { cout<<endl; }
void printArray() { return; }
void read() { return; }
template<typename T , typename... Args> void print(T a , Args... arg) { cout << a << " " ; print(arg...); }
template<typename T , typename... Args> void read(T &a , Args&... arg) { cin >> a; read(arg...); }
template<typename T,typename... Args> void read(vector<T>&v , Args&... arg) { for(auto &i : v) cin>>i; read(arg...); }
template<typename T,typename... Args> void printArray(vector<T>&v, Args&... arg) { for(auto i : v) cout<<i<<" "; cout<<endl; printArray(arg...); }
int power(int a,int b) { int res=1; while(b) { if(b&1LL) res=res*a; b>>=1LL; a=a*a; } return res; }
int modPower(int a,int b) { int res=1; while(b) { if(b&1L) res=(res%MOD*a%MOD)%MOD; b>>=1; a=(a%MOD*a%MOD)%MOD; } return res; }
int gcdExtended(int a,int b,int *x,int *y){ if(a==0) { *x=0,*y=1; return b; } int x1,y1; int gcd=gcdExtended(b%a,a,&x1,&y1); *x=y1-(b/a)*x1; *y = x1; return gcd; }
int modInverse(int b,int m) {int x,y; int g=gcdExtended(b,m,&x,&y); if (g != 1) return -1; return (x%m + m) % m; }
int modDivide(int a,int b,int m=MOD) { a=a%m; int inv=modInverse(b,m); if(inv==-1) return -1; else return (inv*a)%m; }
void runCase_()
{
int n; read(n);
vector<pair<int,int>>v(n);
for(auto &i : v) read(i.F,i.S);
int aoki = 0,taka = 0,ans = 0;
for(auto i : v) aoki += i.F;
sort(all(v),[](pair<int,int>a,pair<int,int>b)
{
return 2*a.F + a.S > 2*b.F + b.S;
});
int i = 0;
while(i < n && taka <= aoki)
{
taka += (v[i].F + v[i].S);
aoki -= v[i].F;
++ans,++i;
}
print(ans);
}
signed main()
{
dracarys;
// TEST_CASE
runCase_();
return 0;
}
/** TEST CASES HERE **/
/*
*/ | #include "bits/stdc++.h"
#define pb push_back
#define mp make_pair
using namespace std;
using ll = long long;
signed main(){
ll n;
cin >> n;
vector<ll>a(n),b(n);
ll sum = 0;
vector<pair<ll,pair<ll,ll>>>d;
for(ll i=0;i<n;i++){
cin >> a[i] >> b[i];
sum = sum + a[i];
d.pb(mp(-2*a[i]-b[i],mp(a[i],a[i]+b[i])));
}
sort(d.begin(),d.end());
ll c = 0;
ll cnt = 0;
for(auto u : d){
//cout << u.first << " " << u.second.first << " " << u.second.second << "\n";
if(sum < c){
break;
}
else{
sum = sum-u.second.first;
c = c + u.second.second;
cnt++;
}
}
cout << cnt << "\n";
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define SOLVER(x) solve_B x
static void s_solve(void)
{
long long N, X;
string S;
long long ans;
cin >> N >> X;
cin >> S;
ans = X;
for (long long i = 0; i < N; i++)
{
switch ( S.at(i) )
{
case 'o':
ans += 1;
break;
case 'x':
if ( ans > 0 )
{
ans -= 1;
}
break;
}
}
cout << ans << endl;
return;
}
void SOLVER((volatile bool *do_loop))
{
do {
s_solve();
} while ((do_loop != NULL) && (*do_loop));
}
#ifndef NO_PROBLEM_MAIN
int main( void )
{
SOLVER((NULL));
return 0;
}
#endif
| #include <string>
#include <iostream>
#include <vector>
#include <algorithm>
#include <sstream>
#define BUF_SIZE 500
enum way {
u,
l,
r,
d
};
int main()
{
short int si, sj;
{
char buf[1000];
std::stringstream ss;
std::cin.getline(buf, 1000);
ss << buf;
ss >> si >> sj;
}
short int t[52][52] = {0};
for (short int j=0;j<52;j++)
t[0][j] = -1;
for (short int i=1;i<51;i++) {
t[i][0] = -1;
char buf[BUF_SIZE];
std::stringstream ss;
std::cin.getline(buf, BUF_SIZE);
ss << buf;
for (short int j=1;j<51;j++) {
ss >> t[i][j];
}
t[i][51] = -1;
}
for (short int j=0;j<52;j++)
t[51][j] = -1;
short int p[52][52] = {0};
for (short int i=1;i<51;i++) {
char buf[1000];
std::stringstream ss;
std::cin.getline(buf, 1000);
ss << buf;
for (short int j=1;j<51;j++) {
ss >> p[i][j];
}
}
std::vector<short int>tiles;
tiles.push_back(-1);
tiles.push_back(0);
tiles.push_back(t[si+1][sj+1]);
short int val_t[4];
short int val_p[4];
std::string output = "";
char ways[5] = "ULRD";
short int diff_i[4] = { -1, 0, 0, +1 };
short int diff_j[4] = { 0, -1, +1, 0 };
while (true) {
val_t[u] = t[si+1-1][sj+1]; //u
val_t[l] = t[si+1] [sj+1-1]; //l
val_t[r] = t[si+1] [sj+1+1]; //r
val_t[d] = t[si+1+1][sj+1]; //d
val_p[u] = p[si+1-1][sj+1]; //u
val_p[l] = p[si+1] [sj+1-1]; //l
val_p[r] = p[si+1] [sj+1+1]; //r
val_p[d] = p[si+1+1][sj+1]; //d
short int max_t = 0;
short int max_p = -1;
short int max_way = -1;
for (int i=0;i<4;i++) {
if (std::find(tiles.begin(), tiles.end(), val_t[i]) == tiles.end()) {
if (max_p < val_p[i]) {
max_p = val_p[i];
max_t = val_t[i];
max_way = i;
}
}
}
if (max_way==-1)
break;
output += ways[max_way];
tiles.push_back(max_t);
si += diff_i[max_way];
sj += diff_j[max_way];
}
std::cout << output << std::endl;
return 0;
} |
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define mod 1000000007ll
//#define mod 998244353ll
#define endl '\n'
#define inf ((ll)1e18+1)
#include<chrono>
using namespace chrono;
mt19937_64 rng(high_resolution_clock::now().time_since_epoch().count());
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define debr(x,y) {cout<<"--> "<<#x<<" to "<<#y<<" : "; auto itr=x; while(itr!=y) cout<<(*itr++)<<' '; cout<<endl; }
#define deba(x) {cout<<"--> "<<#x<<" : "; for(auto ele:(x)) cout<<ele<<" "; cout<<endl; }
#define deb(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s);istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {cout<<endl;}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a <<" , ";
err(++it, args...);
}
ll cl(ll a,ll b){
return a/b+(a%b!=0);
}
const int maxN=2e5+5;
vector<int> adj[maxN];
int n,m;
int price[maxN],deg[maxN];
ll cost[maxN];
ll ans=-inf;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
ll t=1;
// cin>>t;
while(t--){
cin>>n>>m;
for(int x=1;x<=n;x++){
cin>>price[x];
cost[x]=inf;
}
for(int x=1;x<=m;x++){
int xi,yi;
cin>>xi>>yi;
adj[xi].push_back(yi);
deg[yi]++;
}
priority_queue<array<ll,2>,vector<array<ll,2>>,greater<array<ll,2>>> pq;
for(int x=1;x<=n;x++){
if(deg[x]==0){
pq.push({price[x],x});
cost[x]=price[x];
}
}
while(!pq.empty()){
auto pa=pq.top();
pq.pop();
ll mini=pa[0],u=pa[1];
for(int v:adj[u]){
if(cost[v]>mini){
cost[v]=mini;
pq.push({min(mini,(ll)price[v]),v});
}
}
}
for(int x=1;x<=n;x++){
if(deg[x]>0){
ans=max(ans,price[x]-cost[x]);
}
}
cout<<ans<<endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int inf = 1001001001;
int main(){
int N,M;
cin >> N >> M;
vector<int> A(N);
for(int i=0;i<N;i++) cin >> A[i];
vector<vector<int>> G(N,vector<int>(0));
for(int i=0;i<M;i++){
int x,y;
cin >> x >> y;
x--;y--;
G[x].push_back(y);
}
vector<int> V1(N),V2(N,inf);
for(int i=0;i<N;i++) V1[i] = A[i];
for(int i=0;i<N;i++){
for(int j=0;j<G[i].size();j++){
int v = G[i][j];
V1[v] = min(V1[v],V1[i]);
V2[v] = min(V2[v],V1[i]);
}
}
int ans = -inf;
for(int i=0;i<N;i++) if(V2[i]!=inf) ans = max(ans,A[i]-V2[i]);
cout << ans << endl;
return 0;
}
|
#include <iostream>
#include <string>
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
int main(){
int a, b, c;
cin >> a >> b >> c;
cout << 21 - a - b - c << endl;
return 0;
}
| // Problem Link - https://www.codechef.com/UADPIP01/problems/KFIB
/* By Prateek Pani */
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
// // #include<ext/pd_ds/tree_policy.hpp> // works on decommenting on my machine
// // #include<ext/pd_ds/trie_policy.hpp> // works on decommenting on my machine
using namespace __gnu_pbds;
using namespace std;
#define ll long long int
#define ld long double
#define mod 1000000007
#define inf 1e18
#define endl "\n"
#define pb emplace_back
#define vi vector<ll>
#define vs vector<string>
#define pii pair<ll,ll>
#define ump unordered_map
#define mp map
#define pq_max priority_queue<ll>
#define pq_min priority_queue<ll,vi,greater<ll> >
#define ff first
#define ss second
#define mid(l,r) (l+(r-l)/2)
#define loop(i,a,b) for(int i=(a);i<=(b);i++)
#define looprev(i,a,b) for(int i=(a);i>=(b);i--)
#define log(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define logarr(arr,a,b) for(int z=(a);z<=(b);z++) cout<<(arr[z])<<" ";cout<<endl;
#define token(str,ch) (std::istringstream var((str)); vs v; string t; while(getline((var), t, (ch))) {v.pb(t);} return v;)
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...);
}
// tree here is red-black tree and classic problem to solve this is "invCnt"
// trie here is trie ds .. use as pdtrie
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds; // run on online ide
typedef trie<string, null_type, trie_string_access_traits<>, pat_trie_tag, trie_prefix_search_node_update> pbtrie; // run on online ide
void file_i_o()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
int main(int argc, char const *argv[])
{
file_i_o();
int a, b, c;
cin>>a>>b>>c;
cout<<((7-a)+(7-b)+(7-c))<<endl;
return 0;
} |
/* dont stick to an approach */
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <algorithm>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <bitset>
using namespace std;
typedef long long ll;
typedef unsigned long long int ull;
typedef long double ldb;
#define PB push_back
#define For(i, n) for (ll i = 0; i < n; i++)
#define trav(a,x) for (auto& a : x)
#define PYES cout<<"YES\n"
#define PNO cout<<"NO\n"
#define PYes cout<<"Yes\n"
#define PNo cout<<"No\n"
#define endl '\n'
#define sq(x) (x*x)
#define vll vector<ll>
#define pll pair<ll,ll>
#define ff first
#define ss second
#define rev(v) reverse(v.begin(),v.end())
#define srt(v) sort(v.begin(),v.end())
#define grtsrt(v) sort(v.begin(),v.end(),greater<int>())
#define mnv(v) *min_element(v.begin(),v.end())
#define mxv(v) *max_element(v.begin(),v.end())
#define all(v) v.begin(),v.end()
#define ACC(v) accumulate(v.begin(),v.end(),0ll)
#define Fas ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
//--------------------------------------------functions-------------------------------------------------//
ll power(ll a,ll b){ll result=1;while(b>0){if(b%2 == 1){result *= a;} a *= a;b /= 2;}return result;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
ll countSetBits(ll x){ll Count=0;while(x>0){if(x&1) Count++;x=x>>1;}return Count;}
bool isPerfectSquare(ll n){ll sr = sqrt(n);if (sr * sr == n)return true;else return false;}
ll mod(ll x,ll M){return ((x%M + M)%M);}
ll add(ll a, ll b,ll M){return mod(mod(a,M)+mod(b,M),M);}
ll mul(ll a, ll b,ll M){return mod(mod(a,M)*mod(b,M),M);}
ll powerM(ll a,ll b,ll M){
ll res=1ll;
while(b){
if(b%2ll==1ll){
res=mul(a,res,M);
}
a=mul(a,a,M);b/=2ll;
}
return res;
}
//------------------------------------sieve of erantothenes-----------------------------------------------//
//ll MAXN=100150;
//vector<ll> fact(MAXN+1);
//void sieve_of_erantothenes()
//{
// fact[1] = 1;
// for (ll i = 2; i <= MAXN; i++)
// fact[i] = i;
// for (ll i = 4; i <= MAXN; i += 2)
// fact[i] = 2;
// for (ll i = 3; i * i <= MAXN; i++){
// if (fact[i] == i){
// for (ll j = i * i; j <= MAXN; j += i)
// if (fact[j] == j)
// fact[j] = i;
// }
// }
//}
//----------------------------------------nCr mod------------------------------------------------------//
ll nCr(ll n, ll k){
if(n<k) return 0;
if(k==0) return 1;
ll res = 1;
if (k > n - k) k = n - k;
for(ll i = 0; i < k; ++i){
res *= (n - i);
res /= (i + 1);
}
return res;
}
ll modInverse(ll n,ll M){
return powerM(n,M-2,M);
}
ll nCrM(ll n,ll r,ll M){
if(n<r) return 0;
if(r==0) return 1;
vector<ll> fact(n+1);
fact[0]=1;
for(ll i=1;i<=n;i++){
fact[i]=mul(fact[i-1],i,M);
}
return mul(mul(fact[n],modInverse(fact[r],M),M),modInverse(fact[n-r],M),M);
}
//-----------------------------------------------solve-----------------------------------------------------//
void solve(){
ll n;cin>>n;
vll v(n);
trav(w,v) cin>>w;
for(ll i=1;i<n;i++){
if(i%2==0){
v[i]=v[i-1]+v[i];
}else{
v[i]=v[i-1]-v[i];
}
}
map<ll,ll> mm;
for(ll i=0;i<n;i++){
mm[v[i]]++;
}
ll ans=0;
mm[0]++;
trav(w,mm){
ans+=nCr(w.ss,2);
}
cout<<ans<<endl;
}
int main(){
Fas;
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
// ll t=0;
// cin>>t;
// while(t--)
solve();
return 0;
}
| // author: sharad12arse
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define gcd __gcd
#define INF LONG_LONG_MAX
void solve(){
int n;
cin>>n;
vector<ll> arr(n);
for(int i=0;i<n;i++){
cin>>arr[i];
}
map<ll,ll> m1;
m1[0]=1;
ll sum=0;
ll ans=0;
for(int i=0;i<n;i++){
if(i%2==0){
sum+=arr[i];
}else{
sum-=arr[i];
}
ans+=m1[sum];
m1[sum]++;
}
cout<<ans<<"\n";
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int t=1;
// cin>>t;
while(t--){
solve();
}
}
|
#include <bits/stdc++.h>
using namespace std;
using ld = long double;
const int mxn = 103;
bool g[mxn][mxn], f[mxn][mxn];
int n, id;
void dfs(int v) {
f[v][id] = true;
for(int i = 0; i < n; i++)
if(g[v][i] && !f[i][id])
dfs(i);
}
signed main() {
std::ios::sync_with_stdio(0);
std::cout.tie(0);
std::cin.tie(0);
#ifdef saarang
freopen("/home/saarang/Documents/cp/input.txt", "r", stdin);
freopen("/home/saarang/Documents/cp/output.txt", "w", stdout);
#endif
cin >> n;
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
char c; cin >> c;
g[i][j] = c - '0';
}
}
for(id = 0; id < n; id++)
dfs(id);
ld ans = 0;
for(int i = 0; i < n; i++) {
int cnt = 0;
for(int j = 0; j < n; j++)
cnt += f[i][j];
ans += 1.0 / cnt;
}
cout << fixed << setprecision(15) << ans << '\n';
return 0;
} | // Problem: D - Message from Aliens
// Contest: AtCoder - ZONe Energy Programming Contest
// URL: https://atcoder.jp/contests/zone2021/tasks/zone2021_d
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pII pair<int,int>
#define mem(a,b) memset(a,b,sizeof(a))
#define rep(i, a, b) for (int i = a; i < b; i++)
#define do(i, a, b) for (int i= (a); i <= (b); i++)
#define com(s) (s).begin(),(s).end()
#define F first
#define S second
#define pb push_back
#define s(x) (int)(x).size()
#define CASES int tc;cin>>tc;while(tc--)
#define READ_INP freopen("inp.txt", "r", stdin)
#define UNIQUE(X) (X).erase(unique(S(X)),(X).end())
#define IOs ios_base::sync_with_stdio(false);cin.tie(NULL);
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define DISPV(v) { for(auto u: v) cout << u << " "; cout << endl; }
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define endl '\n'
const int inf = 1e18; const int M = 1e9 + 7; const int MAXN = 1e7 + 1;
const double pi = acos(-1.0);
//DEBUGGING-TOOL
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr <<*it << " = " << a << endl;
err(++it, args...);
}
//FUNC
int gcd(int a, int b) {return b == 0?a:gcd(b, a % b);}
int modMul(int a, int b, int m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;}
int modPow(int a, int b, int mod) {int res = 1; while (b > 0) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;}
int calculateNcR(int n, int r){ if(n<r)return 0; int p=1,k=1;if(n-r<r)r=n-r;if(r!=0){while(r){p*=n;k*=r;int m=gcd(p, k);p/=m;k/=m;n--;r--;}return p;}}
//CODE
int32_t main() {
IOs;
// CASES {
int n,m,l,r,d,b,k,u,p,a,q,x,y,z,mn,mx,rem,ans,res=0,c=0;
string s; cin >> s;
deque<char>Deq;
int ok = 0;
for (char I: s){
if(I == 'R') ok ^= 1;
else if(ok == 1) Deq.push_front(I);
else Deq.push_back(I);
}
if(ok == 1) reverse(Deq.begin(), Deq.end());
string Ano;
for (char d: Deq){
if(s(Deq) == 0) Ano.push_back(d);
else{
if(Ano.back() == d) Ano.pop_back();
else Ano.push_back(d);
}
}
cout << Ano << '\n';
// }
}
|
#include "bits/stdc++.h"
using namespace std;
#define sync ios_base::sync_with_stdio(0);cin.tie(0);
#define all(x) x.begin(),x.end()
#define unq(a) sort(all(a));a.resize(unique(all(a)) - a.begin())
#define ll long long
#define ld long double
#define pb push_back
#define fi first
#define se second
#define mem(a , x) memset(a, x, sizeof a)
#define endl '\n'
const ld pi = atan(1) * 4.0;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
sync
int t = 1;
//cin >> t;
while(t--){
int n, k; cin >> n >> k;
vector<int> a(n);
for (int& x : a) cin >> x;
vector<ll> f(*max_element(all(a)) + 2);
for (int& x: a) f[x]++;
ll cnt = 0, lst = -1, mx = *max_element(all(a)), ok = k;
for (int i = 0;i <= mx + 1;i++){
if (f[i]){
int mn = min(ok , f[i]);
cnt += ((ok - mn) * 1ll * i);
ok = mn;
}
else{
cnt += (i * 1ll * ok);
break;
}
}
cout << cnt << endl;
}
cerr << "processor time: " << clock() / (double) CLOCKS_PER_SEC << "s ";
return 0;
} | #include<bits/stdc++.h>
#include <iostream>
using namespace std;
int main()
{
#ifdef LOCAL_EXEC
#else
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#endif // LOCAL_EXEC
long long int n,i,j,k,x=0,y,z,sum=0;
cin>>n>>k;
long long int cnt[n+1]={0};
for(i=1;i<=n;i++){
cin>>x;
cnt[x]+=1;
}
y=n;
for(i=1;i<=k;i++){
for(j=0;j<=n;j++){
if(cnt[j]==0||y==0)
break;
cnt[j]-=1;
y-=1;
}
sum+=j;
if(y==0)
break;
}
cout<<sum;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
const int N=2e6+10;
const int p=1e9+7;
#define rint register int
#define rll register long long
#define ll long long
char s[N];
ll dp[N][20];
int n,k,st[N],a[N];
ll dfs(rint hh,rint re,bool ismx,bool iszero){
if(re<0||re>hh)return 0;
if(!hh)return 1;
if(dp[hh][re]!=-1&&!ismx&&!iszero)return dp[hh][re];
rll t=0;
if(!ismx){
if(!iszero)
t=dfs(hh-1,re,0,0)*(k-re)+dfs(hh-1,re-1,0,0)*(16-k+re);
else
t=dfs(hh-1,re,0,1)+dfs(hh-1,re-1,0,0)*(15-k+re);
}else {
if(iszero)
t=dfs(hh-1,re,!a[hh],1);
else {
if(st[hh+1]&1)t=dfs(hh-1,re,!a[hh],0);
else t=dfs(hh-1,re-1,!a[hh],0);
}
for(rint j=1;j<=a[hh];j++){
if(st[hh+1]&(1<<j))t+=dfs(hh-1,re,j==a[hh],0);
else t+=dfs(hh-1,re-1,j==a[hh],0);
}
}
t%=p;
if(!ismx&&!iszero)dp[hh][re]=t;
return t;
}
int main(){
scanf("%s",s+1);
n=strlen(s+1);
cin >> k;
for(rint i=1;i<=n;i++){
if('0'<=s[i]&&s[i]<='9')a[i]=s[i]-'0';
else a[i]=s[i]-'A'+10;
st[i]=st[i-1]|(1<<a[i]);
}
reverse(st+1,st+n+1);
reverse(a+1,a+n+1);
memset(dp,-1,sizeof(dp));
printf("%lld\n",dfs(n,k,1,1));
return 0;
}
| #pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please
ll dp[18];
char S[200200];
int suuji(char c) {
if (c < 'A') return c - '0';
else return c - ('A' - 10);
}
int main() {
//cin.tie(0);
//ios::sync_with_stdio(false);
fread(S, 1, 200200, stdin);
int K = 0;
int N = 200200 - 1;
while (S[N] != ' ') N--;
int tmp = N + 1;
while (S[tmp] >= '0') K = K * 10 + S[tmp++] - '0';
const int mod = 1e9 + 7;
int k = suuji(S[0]);
dp[1] = k - 1;
int kazu = 1 << 15 - k, kazu0 = 1;
rep1(i, N - 1) {
for(int j = 16; j >= 1; j--) {
dp[j] %= mod;
dp[j + 1] += (16 - j) * dp[j];
dp[j] = j * dp[j];
}
dp[1] += 15;
int k = suuji(S[i]);
int k1 = __builtin_popcount(kazu >> 16 - k);
dp[kazu0] += k1;
dp[kazu0 + 1] += k - k1;
kazu0 += !(kazu & 1 << 15 - k);
kazu |= 1 << 15 - k;
}
ll kotae = dp[K];
if (kazu0 == K) kotae++;
printf("%lld", kotae % mod);
Would you please return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define MTP make_tuple
typedef long long int ll;
constexpr int kN = int(2E5 + 10);
struct BIT {
int val[kN];
BIT () {memset(val, 0, sizeof(val));}
void add(int pos, int x) {
while (pos < kN) {
val[pos] += x;
pos += pos & -pos;
}
return ;
}
int ask(int pos) {
int ans = 0;
while (pos) {
ans += val[pos];
pos ^= pos & -pos;
}
return ans;
}
};
BIT bit;
vector<int> v[kN];
vector<tuple<int, int, int, int>> que[kN];
int p[kN], sz[kN], a[kN], b[kN], c[kN], k[kN], ans[kN], pos[kN];
int Find(int n) {return n == p[n] ? n : p[n] = Find(p[n]);}
void Merge(int l, int r) {
l = Find(l), r = Find(r);
if (l != r) {
if (sz[l] < sz[r]) swap(l, r);
for (int i : v[r]) v[l].PB(i);
for (tuple<int, int, int, int> i : que[r])
que[l].PB(MTP(get<0>(i) + sz[l], get<1>(i) + sz[l], get<2>(i), get<3>(i)));
sz[l] += sz[r];
p[r] = l;
}
return ;
}
int main() {
int n, q, idx;
vector<tuple<int, int, int, int>> events;
scanf("%d%d", &n, &q);
for (int i = 1; i <= n; i++) scanf("%d", &c[i]);
for (int i = 1; i <= q; i++) scanf("%d%d%d", &k[i], &a[i], &b[i]);
for (int i = 1; i <= n; i++) p[i] = i;
for (int i = 1; i <= n; i++) sz[i] = 1;
for (int i = 1; i <= n; i++) v[i].PB(i);
for (int i = 1; i <= q; i++) {
if (k[i] == 1) Merge(a[i], b[i]);
else {
idx = Find(a[i]);
que[idx].PB(MTP(1, sz[idx], b[i], i));
}
}
for (int i = 1; i <= n; i++) Merge(1, i);
idx = Find(1);
//v[idx].push_front(0);
for (int i = 0; i < n; i++) pos[v[idx][i]] = i + 1;
for (int i = 1; i <= n; i++) events.PB(MTP(c[i], -1, pos[i], 1));
for (int i = 1; i <= n; i++) events.PB(MTP(c[i] + 1, -1, pos[i], -1));
for (tuple<int, int, int, int> i : que[idx]) events.PB(MTP(get<2>(i), get<0>(i), get<1>(i), get<3>(i)));
sort(events.begin(), events.end());
for (tuple<int, int, int, int> i : events) {
//printf("i = (%d, %d, %d, %d)\n",
if (get<1>(i) == -1) bit.add(get<2>(i), get<3>(i));
else ans[get<3>(i)] = bit.ask(get<2>(i)) - bit.ask(get<1>(i) - 1);
}
for (int i = 1; i <= q; i++) if (k[i] == 2) printf("%d\n", ans[i]);
}
| #include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int fa[maxn];
unordered_map<int, int> mp[maxn];
int findfa(int x){
if(fa[x] == x) return x;
return fa[x] = findfa(fa[x]);
}
void merge(int x, int y){
int fx = findfa(x), fy = findfa(y);
if(fx==fy) return;
if(mp[fx].size() > mp[fy].size()){
swap(fx, fy);
}
for(auto& iter:mp[fx]){
mp[fy][iter.first] += iter.second;
}
fa[fx] = fy;
}
int main() {
int n, q;
scanf("%d%d", &n, &q);
for(int i=1;i<=n;i++){
int c;
scanf("%d", &c);
fa[i] = i;
mp[i][c] = 1;
}
while(q--){
int op, a, b;
scanf("%d%d%d", &op, &a, &b);
if(op==1){
merge(a, b);
}
else if(op==2){
int fx = findfa(a);
printf("%d\n", mp[fx].find(b) == mp[fx].end()?0:mp[fx][b]);
}
}
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long
#define db double
#define el "\n"
#define ld long double
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n;i>=0;i--)
#define rep_a(i,a,n) for(int i=a;i<n;i++)
#define all(ds) ds.begin(), ds.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef vector< long long > vi;
typedef pair<long long, long long> ii;
typedef priority_queue <ll> pq;
#define o_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
const ll mod = 1000000007;
const ll INF = (ll)1e18;
const ll MAXN = 1000006;
ll po(ll x, ll n){
ll ans=1;
while(n>0){ if(n&1) ans=(ans*x)%mod; x=(x*x)%mod; n/=2;}
return ans;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T=1;
//cin >> T;
while(T--){
int n;
cin>>n;
vector<ii> x,y;
ll _x,_y;
rep(i,n){
cin>>_x>>_y;
x.pb(mp(_x, _y));
y.pb(mp(_y, _x));
}
sort(all(x));
sort(all(y));
vi z;
if(x[n-1].ff-x[0].ff>=abs(x[n-1].ss-x[0].ss)) z.pb(x[n-1].ff-x[0].ff);
if(x[n-1].ff-x[1].ff>=abs(x[n-1].ss-x[1].ss)) z.pb(x[n-1].ff-x[1].ff);
if(x[n-2].ff-x[0].ff>=abs(x[n-2].ss-x[0].ss))z.pb(x[n-2].ff-x[0].ff);
if(y[n-1].ff-y[0].ff>abs(y[n-1].ss-y[0].ss)) z.pb(y[n-1].ff-y[0].ff);
if(y[n-1].ff-y[1].ff>abs(y[n-1].ss-y[1].ss)) z.pb(y[n-1].ff-y[1].ff);
if(y[n-2].ff-y[0].ff>abs(y[n-2].ss-y[0].ss)) z.pb(y[n-2].ff-y[0].ff);
sort(all(z));
int k = z.size();
cout<<z[k-2]<<el;
}
cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
return 0;
} | // D - Circle Lattice Points
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using dbl = long double;
int main(){
ll scale = 1e4;
dbl x, y, r; cin>>x>>y>>r;
ll X = round(x*scale);
ll Y = round(y*scale);
ll R = round(r*scale);
ll r2 = R*R;
ll ans = 0;
for(ll i=0; i<=2*R+scale; i+=scale){
ll y = floor((Y+R)/scale)*scale - i;
ll dy = Y - y;
ll dx2 = r2 - dy*dy;
if(dx2 < 0) continue;
ll dx = floor(sqrt((dbl)dx2));
ll L = ceil((X - dx)/(dbl)scale);
ll R = floor((X + dx)/(dbl)scale);
ans += R - L + 1;
}
cout<< ans <<endl;
}
|
/////home/mohammed/.config/sublime-text-3/Packages/User
/*input
*/
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <sstream>
#include <iterator>
#include <cstdlib>
#include <unordered_map>
#include <map>
#include <list>
#include <set>
using namespace std;
using bin = std::bitset<8>;
#define endl ("\n")
#define pi (3.141592653589)
#define mod 1000000007
#define int int64_t
#define float double
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(c) c.begin(), c.end()
#define min3(a, b, c) min({a,b,c})
#define max3(a, b, c) max({a,b,c})
#define min4(a, b, c, d) min({a,b,c,d})
#define max4(a, b, c, d) max({a,b,c,d})
#define rrep(i, n) for(int i=n-1;i>=0;i--)
#define rep(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
#define ld long double
#define scanArray(a,n) for(int i = 0; i < n; i++){cin >> a[i];}
#define coutArray(a,n) for(int i = 0; i < n; i++){cout << a[i] << " ";};cout << endl;
#define input(type, n) type n; cin>>n;
struct debugger
{
template<typename T> debugger& operator , (const T& v)
{
cerr << v << " ";
return *this;
}
} dbg;
bool check_key(map<int, int> m, int key)
{
if (m.find(key) == m.end())
return false;
return true;
}
vector<int> SieveOfEratosthenes(int n)
{
bool prime[n + 1];
memset(prime, true, sizeof(prime));
vector<int> res;
for (int p = 2; p * p <= n; p++)
{
if (prime[p] == true)
{
for (int i = p * p; i <= n; i += p)
prime[i] = false;
}
}
for (int p = 2; p <= n; p++)
if (prime[p])
res.push_back(p);
//cout << p << " ";
return res;
}
// function to convert decimal to binary
bin decToBinary(int n)
{
// array to store binary number
int binaryNum[32];
// counter for binary array
int i = 0;
while (n > 0) {
// storing remainder in binary array
binaryNum[i] = n % 2;
n = n / 2;
i++;
}
string x = "";
// printing binary array in reverse order
for (int j = i - 1; j >= 0; j--) {
x += to_string(binaryNum[j]);
}
bin result{x};
return result;
}
// for example:
// bin result = decToBinary(2);
// bin result2 = decToBinary(10);
// bin z = result xor result2;
// cout << z;
// return 0;
int convertBinaryToDecimal(long long n)
{
int decimalNumber = 0, i = 0, remainder;
while (n != 0)
{
remainder = n % 10;
n /= 10;
decimalNumber += remainder * pow(2, i);
++i;
}
return decimalNumber;
}
int factorial(int n) {
long long res = 1;
for (int i = 1; i <= n; i++) {
res = ((res * i) % mod + mod) % mod ;
}
return res;
}
int32_t main()
{
fast;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
input(int, a); input(int, b); input(int, c); input(int, d);
int cyan = a;
int red = 0;
for (int i = 0; i < 1e5 + 1; i++) {
// cout << cyan << " " << red << endl;
if (cyan <= red * d) {
cout << i << endl;
return 0;
}
cyan += b;
red += c;
}
cout << -1 << endl;
} | #include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#include <complex>
#define rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define all(x) (x).begin(),(x).end()
#define inf 1e18
using namespace std;
typedef long long llint;
typedef long long ll;
typedef pair<llint, llint> P;
ll n, m, t;
ll a[1005], b[1005];
int main(void)
{
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m >> t;
rep(i, 1, m) cin >> a[i] >> b[i];
a[m+1] = t;
ll sum = n, ans = inf;
sum -= a[1]; chmin(ans, sum);
rep(i, 1, m){
sum += b[i]-a[i], chmin(sum, n);
sum -= a[i+1]-b[i], chmin(ans, sum);
}
if(ans <= 0) cout << "No" << endl;
else cout << "Yes" << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define For(i, n) for (int i = 0; i < n; i++)
#define ll long long
#define End return 0
#define vi vector<int>
#define pb push_back
#define YES printf("YES\n")
#define NO printf("NO\n")
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define min4(a, b, c, d) min(min(a, b), min(c, d))
#define max4(a, b, c, d) max(max(a, b), max(c, d))
#define Fors(i, s) for (int i = 0; i < s.size(); i++)
#define all(v) v.begin(), v.end()
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * (b / __gcd(a, b)))
#define Erase(s) s.erase(unique(s.begin(), s.end()), s.end());
//-----------------------------------------------------//
int main()
{
//int T;cin >> T;while(T--)
{
string s;
cin >> s;
cout << s[1] << s[2] << s[0];
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
cout << s[1] << s[2] << s[0] << endl;
}
|
//
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
#define int long long
const int maxn = 2e5+10;
int lst[300];
int Minus[300];
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
string s;
cin >> s;
int n = s.size();
for(int i = 'a';i <= 'z';i++)lst[i] = n;
ll ans = 0;
if(s[n-1] != s[n-2])Minus[(int)s[n-1]]++;
for(int i = n-2;i >= 0;i--){
if(i > 0 and s[i-1] != s[i] and s[i+1] != s[i])Minus[(int)s[i]]++;
if(s[i] == s[i+1] and lst[(int)s[i]] != i+1){
ans += lst[(int)s[i]] - i - 2 - (Minus[(int)s[i]]?Minus[(int)s[i]]:0ll);
// cout << i << " " << lst[(int)s[i]] << " " << Minus[(int)s[i]] << " ans: " << lst[(int)s[i]] - i - 2 - (Minus[(int)s[i]]?Minus[(int)s[i]]:0ll) << endl;
lst[(int)s[i]] = i;
for(int j = 'a';j <= 'z';j++)if(j != s[i])lst[j] = n;
for(int j = 'a';j <= 'z';j++)Minus[j] = 0;
}
if(s[i] == s[i+1] and lst[(int)s[i]] == i+1)lst[(int)s[i]] = i;
// lst[(char)s[i]] = i;
// Minus[(int)s[i]]++;
}
cout << ans;
return 0;
}
| #include<bits/stdc++.h>
#define f(i,a,b) for( int i=a;i<=b;++i)
#define ff(i,a,b) for( int i=a;i>=b;--i)
#define debug(x) cerr << #x << " : " << x << " " << endl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
const ll mod = 1e9 + 7;
const ll mod2 = 998244353;
const int inf = 0x3f3f3f3f;
const double tiaohe = 0.57721566490153286060651209;
ll oula(ll x) { ll res = x;f(i, 2, x / i) { if (x % i == 0) { res = res / i * (i - 1);while (x % i == 0) x /= i; } }if (x > 1) res = res / x * (x - 1);return res; }
ll quickmod(ll a, ll n, ll m) { ll s = 1;while (n) { if (n & 1) { s = s * a % m; }a = (a*a) % m;n = n / 2; }return s; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
void ex_gcd(ll a, ll b, ll &x, ll &y, ll &d) { if (!b) { d = a, x = 1, y = 0; } else { ex_gcd(b, a % b, y, x, d);y -= x * (a / b); } }
ll inv(ll t, ll p) { ll d, x, y;ex_gcd(t, p, x, y, d);return d == 1 ? (x % p + p) % p : -1; }
bool isPrime(ll x) { if (x == 2)return true;if (x % 2 == 0)return false;for (ll i = 2;i*i <= x;i++) if (x % i == 0)return false; return true; }
inline int in() { char ch = getchar();int x = 0, f = 1;while (ch<'0' || ch>'9') { if (ch == '-')f = -1;ch = getchar(); }while (ch >= '0'&&ch <= '9') { x = x * 10 + ch - '0';ch = getchar(); }return x * f; }
//double a = log(n) +tiaohe + 1.0 / (2 * n);
double eqa = (1 + sqrt(5.0)) / 2.0;
const double eps = 1e-6;
const int N = 6e5 + 5;
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif
int n = in();
ll ans = 0;
while (n--)
{
int l = in();
int r = in();
ans += (ll)(r - l + 1)*(l + r)/2;
}
cout << ans << endl;
return 0;
}
|
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int T;
cin >> T;
int ans[100];
REP(i, T) {
string S;
cin >> S;
ans[i] = -1;
if ("atcoder" < S)
ans[i] = 0;
else{
REP(j, S.length())
{
if(S[j] > 'a') {
if(S[j] > 't')
ans[i] = j-1;
else
ans[i] = j;
break;
}
}
}
}
REP(i,T)
cout << ans[i] << "\n";
} | #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)
#define SZ(x) ((int)(x).size())
#define YESNO(bool) \
if (bool) { \
cout << "YES" << endl; \
} else { \
cout << "NO" << endl; \
}
#define yesno(bool) \
if (bool) { \
cout << "yes" << endl; \
} else { \
cout << "no" << endl; \
}
#define YesNo(bool) \
if (bool) { \
cout << "Yes" << endl; \
} else { \
cout << "No" << endl; \
}
#define endl "\n"
#define pb push_back
#define mp make_pair
#define ft first
#define sd second
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vll = vector<long long>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vs = vector<string>;
using pii = pair<int, int>;
template <class T>
bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
} else
return false;
}
template <class T>
bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return true;
} else
return false;
}
template <typename T>
inline void print(const T &x) {
cout << x << "\n";
}
template <typename T>
inline void print(const vector<T> &v, string s = " ") {
REP (i, v.size())
cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");
}
const int IINF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
string solve(string S) {
// TODO: edit here
string ret = "";
for (ll i = SZ(S) - 1; i >= 0; i--) {
if (S[i] == '0') ret += "0";
else if (S[i] == '1') ret += "1";
else if (S[i] == '6') ret += "9";
else if (S[i] == '8') ret += "8";
else if (S[i] == '9') ret += "6";
}
return ret;
}
// generated by oj-template v4.7.2 (https://github.com/online-judge-tools/template-generator)
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
string S;
cin >> S;
auto ans = solve(S);
cout << ans << endl;
return 0;
}
|
/**
* author: Taara Sinh Aatrey
* created: 26.06.2021 17:33:36
**/
#include <bits/stdc++.h>
using namespace std;
template<typename A, typename B> istream& operator>>(istream &is, pair<A, B> &p) { return is >> 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> istream& operator>>(istream &is, T_container &v) { for (T& x : v) is >> x; return is;} bool debug;
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return debug ? os << '(' << p.first << ", " << p.second << ')' : 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) { if(debug) { os << "{"; string sep; for (const T &x : v) os << sep << x, sep = ", "; os << '}'; } else { bool f = false; for (const T &x : v) { if(f) {os << " ";} os << x, f = true; } } return os;}
template <typename T, typename T1, typename... Tail> T amin(T& a, T1 b, Tail... c) { if(b < a) a = b; if constexpr (sizeof...(c) != 0) { amin(a, c...); } return a; } template <typename T, typename T1, typename... Tail> T amax(T& a, T1 b, Tail... c) { if(b > a) a = b; if constexpr (sizeof...(c) != 0) { amax(a, c...); } return a; }
void dbg_out() { cerr << endl; } template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#ifdef ONLINE_JUDGE
#define dbg(...)
#else
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]:", debug = true, dbg_out(__VA_ARGS__), debug = false
#endif
#define int int64_t
const int mod = 1e9 + 7; const int INF = 1e18L + 5; const int N = 2e5 + 5;
void solve() {
int a, b, c, d;
cin >> a >> b >> c >> d;
if(d * c <= b) {
cout << -1 << '\n';
return;
}
int op = 0;
int x = a, y = 0;
if(x > d * y && b >= c) {}
do {
x += b;
y += c;
op++;
} while(x > y * d);
cout << op;
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int t = 1;
for (int tt = 1; tt <= t; tt++) {
solve();
}
return 0;
} | #include <iostream>
#include <cstdint>
int main() {
std::int64_t A, B, C, D;
std::cin >> A >> B >> C >> D;
std::int64_t count = -1;
if (B < C * D) {
const auto denom = C * D - B;
count = (A + denom - 1) / denom;
}
std::cout << count << std::endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)
template<class T1, class T2> inline bool chmax(T1 &a, const T2 &b) {if (a<b) { a=b; return 1;} return 0;}
template<class T1, class T2> inline bool chmin(T1 &a, const T2 &b) {if (b<a) { a=b; return 1;} return 0;}
struct init{init(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}}init_;
#ifdef DEBUG
template <class T> void verr(const set<T> &st) { repa(a, st) cerr << a << " "; cerr << endl; }
template <class S, class T> void verr(const map<S, T> &mp) { repa(a, mp) cerr << "{" << a.first << ", " << a.second << "} "; cerr << endl; }
template <class S, class T, class N> void verr(const vector<pair<S,T>>& a, const N& n) { rep(i, n) cerr << "{" << a[i].first << ", " << a[i].second << "} "; cerr << endl; }
template <class T, class N> void verr(const vector<T>& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << endl; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << endl; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif
const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
int main() {
ll N;
cin >> N;
ll bn = (1 << N);
cout << bn - 1 << '\n';
repe(i, 1, bn){
string ans;
rep(j, bn) {
if(__builtin_popcount(i & j) % 2 == 0)
ans += 'A';
else
ans += 'B';
}
cout << ans << '\n';
}
} | #include <bits/stdc++.h>
using namespace std;
bool brute(int n,int k,vector<vector<int>> &a,vector<int> &b){
if(k==0){
bool bo=true;
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
if(a[i][j]!=a[0][1]){
bo=false;
break;
}
}
if(!bo) break;
}
if(bo){
cout << "conglats" << a[0][1] << "\n";
for(int i=0;i<(int)b.size();i++) cout << b[i] << " ";
cout << "\n";
return true;
}
return false;
}
for(int i=0;i<(1<<n);i++){
if(__builtin_popcount(i)!=(n/2)) continue;
for(int s=0;s<n;s++){
for(int t=s+1;t<n;t++){
if(((i>>s)&1)==((i>>t)&1)){
a[s][t]++;
}
}
}
b.push_back(i);
if(brute(n,k-1,a,b)) return true;
b.pop_back();
for(int s=0;s<n;s++){
for(int t=s+1;t<n;t++){
if(((i>>s)&1)==((i>>t)&1)){
a[s][t]--;
}
}
}
}
return false;
}
void kasan(string str,vector<vector<int>> &a){
for(int i=0;i<(int)str.size();i++){
for(int j=i+1;j<(int)str.size();j++){
if(str[i]==str[j]) a[i][j]++;
}
}
}
string xors(string &a,string &b){
int n=(int)a.size();
string res;
for(int i=0;i<n;i++){
if(a[i]==b[i]) res.push_back('A');
else res.push_back('B');
}
return res;
}
int main(){
//ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
int m=1<<n;
int kumi=m*(m-1)/2;
int sou=(m/2-1)*(m/2);
int g=__gcd(sou,kumi);
cout << kumi/g << "\n";
int cnt=0;
vector<vector<int>> a(m,vector<int>(m));
vector<string> st;
for(int h=1;h<m;h*=2){
//000...111...
string str;
for(int j=0;j<m;j++){
if((j/h)&1) str.push_back('B');
else str.push_back('A');
}
kasan(str,a);
int sz=(int)st.size();
cout << str << "\n";
for(int j=0;j<sz;j++){
string str2=xors(st[j],str);
cout << str2 << "\n";
kasan(str2,a);
st.push_back(str2);
}
st.push_back(str);
}
return 0;
} |
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long
#define reset(x) memset(x,0,sizeof(x))
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,n) for(int i=0;i<(n);++i)
#define repA(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define sz(a) (int)a.size()
#define pii pair<int,int>
#define all(a) a.begin(),a.end()
#define PI 3.1415926535897932384626433832795
#define INF 1000000000
#define MOD 1000000007
#define MOD2 1000000009
#define EPS 1e-6
#define pb push_back
#define fi first
#define se second
#define mp make_pair
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
const int MAXN = 100005;
signed main() {
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
//freopen(".inp", "r", stdin);
//freopen(".out", "w", stdout);
int n; cin >> n;
int arr[n + 1], brr[n + 1], crr[n + 1];
vector<vector<int>> equal(n + 1, vector<int>());
int exist[n + 1];
reset(exist);
for (int i = 0; i < n; i++)
{
cin >> arr[i + 1];
exist[arr[i + 1]]++;
}
for (int i = 0; i < n; i++)
{
cin >> brr[i + 1];
equal[brr[i + 1]].pb(i + 1);
}
int num_time[n + 1];
reset(num_time);
for (int i = 0; i < n; i++)
{
cin >> crr[i + 1];
num_time[crr[i + 1]]++;
}
int sum = 0;
bool used[n + 1]; reset(used);
for (int i = 1; i <= n; i++)
{
int tmp = 0;
if (used[arr[i]] == true)
{
continue;
}
for (int x : equal[arr[i]])
{
tmp += num_time[x];
}
sum += (tmp * exist[arr[i]]);
used[arr[i]] = true;
}
cout << sum;
}
| #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define iambharatks \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
#define bitcount __builtin_popcount
#define setbits(x) __builtin_popcountll(x)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define fo(i, j, n) for (int i = j; i <= n; i++)
#define rev(i, j, n) for (int i = n; i >= j; i--)
#define ln "\n"
#define dbg(x) cout << #x << " = " << x << ln
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define INF 2e18
#define w(x) \
int x; \
cin >> x; \
while (x--)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<bool>> vvb;
typedef vector<vector<pll>> vvpll;
typedef vector<pll> vpll;
typedef vector<pi> vpi;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
const int MOD = 998244353;
const int N = 2e5 + 5;
double eps = 1e-12;
const int mod = 1e9 + 7;
void solve()
{
string s;
cin >> s;
for (char &c : s)
{
if (c == '9')
c = '6';
else if (c == '6')
c = '9';
}
reverse(all(s));
cout << s << ln;
}
int main()
{
iambharatks;
// ll t;
// cin >> t;
// for (int it = 1; it <= t; it++)
// {
// cout << "Case #" << it << ": ";
solve();
// }
return 0;
} |
/**
* code generated by JHelper
* More info: https://github.com/AlexeyDmitriev/JHelper
* @author aurinegro (Nicolás Álvarez)
*/
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i=0;i<(int)(n);i++)
#define si(c) ((int)(c).size())
#define pb push_back
using ll = long long int;
using vi = vector<int>;
using pii = pair<int, int>;
class DChoosingUpSides {
public:
void solve(std::istream &cin, std::ostream &cout) {
int n;
cin >> n;
vector<bitset<256>> ans;
bitset<256> x = 3;
ans.pb(2);
for (int lvl = 2; lvl <= n; lvl++) {
for (auto &x : ans) x |= x << (1 << (lvl - 1));
int sz = si(ans);
forn (i, sz) ans.pb(ans[i] ^ (x << (1 << (lvl - 1))));
ans.pb(x);
x |= x << (1 << (lvl - 1));
}
cout << si(ans) << endl;
for (auto x : ans) {
forn(i, 1 << n) cout << char('A' + x[i]);
cout << endl;
}
}
};
int main() {
DChoosingUpSides solver;
std::istream &in(std::cin);
std::ostream &out(std::cout);
solver.solve(in, out);
return 0;
}
| #include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define ALL(obj) (obj).begin(), (obj).end()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int dy[]={0, 0, 1, -1, 1, -1, -1, 1};
int dx[]={1, -1, 0, 0, 1, 1, -1, -1};
int main() {
cout<<fixed<<setprecision(10);
ll n; cin>>n;
vint x(n); rep(i,n) cin>>x[i];
ll a1 = 0;
double a2 = 0;
ll a3 = 0;
for(auto e:x){
a1 += abs(e);
a2 += e*e;
chmax(a3, abs(e));
}
cout<<a1<<endl;
a2 = sqrt(a2);
cout<<a2<<endl;
cout<<a3<<endl;
return 0;
} |
#include <bits/stdc++.h>
#define pb(a) push_back(a)
#define rep(i, d, e) for (int i = d; i < e; i++)
#define ffor(i, a, b) for (int i = a; i <= b; i++)
#define rloop(i, c, d) for (int i = c; i >= d; i--)
#define ll long long
#define vc vector<ll>
#define pp pop_back()
#define mod 1000000007
#define MAX 1000000
using namespace std;
int main()
{
ll n;
cin >> n;
double l[n], r[n];
ffor(i, 0, n - 1)
{
int c;
cin >> c >> l[i] >> r[i];
if (c == 2)
r[i] -= 0.5;
if (c == 3)
l[i] += 0.5;
if (c == 4)
{
l[i] += 0.5;
r[i] -= 0.5;
}
}
ll cnt=0;
for(int i=0;i<n-1;i++)
{
for(int j=i+1;j<n;j++)
{
if(max(l[i],l[j])<=min(r[i],r[j]))
cnt++;
}
}
cout<<cnt<<endl;
} | #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for(int i = 0; i < n; i++)
int main()
{
int n;
cin >> n;
vector<vector<int>> a(n,vector<int>(3));
rep(i,n){
cin >> a[i][0] >> a[i][1] >> a[i][2];
}
int ans = 0;
rep(i,n){
for(int j = i+1; j<n; j++){
bool ok = false;
if(a[i][1]<=a[j][2] && a[i][2]>=a[j][1]){
ok = true;
if(a[i][1]==a[j][2] && !(a[i][0]<= 2&&a[j][0]%2==1))ok = false;
else if(a[i][2]==a[j][1] && !(a[j][0]<= 2&&a[i][0]%2==1))ok = false;
}
if(ok)ans++;
}
}
cout << ans << endl;
return 0;
} |
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(...) begin(__VA_ARGS__) , end(__VA_ARGS__)
#define boost {ios_base::sync_with_stdio(false); cin.tie(); cout.tie();}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector <int> vi;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
constexpr ll nax = 2e5+6969, INF = 2e9+6969;
int h,w,t[11][11],cnt[11],tmp[11][11];
int ans;
void solve()
{
for(int i=1;i<=10;i++) cnt[i] = 0;
for(int i=2;i<=h;i++)
{
for(int j=2;j<=w;j++)
{
if(t[i][j] != t[i-1][j]) cnt[j] = 1;
else cnt[j] = 0;
}
int last = 0;
for(int i=1;i<=w;i++)
{
if(last == 0 && cnt[i] == 1) ans++;
last = cnt[i];
}
}
}
int main()
{
scanf("%d%d", &h, &w);
for(int i=1;i<=h;i++)
{
for(int j=1;j<=w;j++)
{
char c;
cin >> c;
if(c == '#') t[i][j] = 1;
}
}
solve();
// cout << ans << "\n";
for(int i=1;i<=h;i++)
{
for(int j=1;j<=w;j++)
{
tmp[j][i] = t[i][j];
}
}
swap(h,w);
for(int i=1;i<=h;i++) for(int j=1;j<=w;j++) t[i][j] = tmp[i][j];
solve();
cout << ans << "\n";
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
struct fastio{fastio(){cin.tie(nullptr);ios_base::sync_with_stdio(false);std::cout<<std::fixed<<setprecision(10);}}oitsaf;
#define rep(i,n) for(int i=0;i<int(n);++i)
constexpr char newl = '\n';
template<class T>std::istream&operator>>(std::istream&is,std::vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T>std::ostream&operator<<(std::ostream&os,std::vector<T>const&v){for(auto const& vi:v)os<<vi<<" ";return os;}
#if _local
struct debug_structure{template<class T>debug_structure&operator<<(const T&elm){std::cerr<<elm<<std::flush;return*this;}}dout;
#else
struct debug_structure{template<class T>debug_structure&operator<<(const T&elm){return*this;}}dout;
#endif
int main() {
int h, w;
cin >> h >> w;
vector<string> s(h);
cin >> s;
int ans = 0;
bool prv = false;
rep(i, h - 1) rep(j, w) {
if (s[i][j] != s[i + 1][j]) {
dout << "{" << i << "," << j << "} : " << (s[i][j] != s[i + 1][j]) << " "
<< prv << " " << ans << newl;
;
if (!prv) {
prv = true;
ans++;
}
} else {
prv = false;
}
}
prv = false;
rep(j, w - 1) rep(i, h) {
if (s[i][j] != s[i][j + 1] ) {
dout << "{" << i << "," << j << "} : " << (s[i][j] != s[i + 1][j]) << " "
<< prv << " " << ans << newl;
if (!prv) {
prv = true;
ans++;
}
} else {
prv = false;
}
}
cout << (ans) << endl;
}
|
//g++ t.cpp -o t && t < p.txt
//d>p.txt&&t<p.txt&&t2<p.txt
#include <iostream> // プログラムの耳と口
#include <vector> // 超有能配列秘書
#include <algorithm> // みんな大好きソートと二分探索
#include <queue> // きゅーちゃん、だいすき
#include <string> // to_string
#include <functional> // 関数を変数に入れる子
#include <set> // 値の取得・挿入・削除を高速に
#include <map> // setの妹 これまた優秀
#include <random> // 乱択さん
#include <ctime> // へびになりたい
#include <bitset> // へびになった シャー
// #include <atcoder/all>
// using namespace atcoder; // コンパイル重い
#define DB cerr<<"D"<<endl
using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6;
using P=pair<ll,ll>;
const ll M = 1e9+7;
ll mod_pow(ll x, ll a) { ll an = 1; while(a > 0) { if (a&1) an = an * x % M; x = x * x % M; a >>= 1;} return an;}
ll mod_pow(ll x, ll a, ll m) { ll an = 1; while(a > 0) { if (a&1) an = an * x % m; x = x * x % m; a >>= 1;} return an;}
void add(ll& x, ll y) {x+=y; x%=M;}; void mul(ll& x, ll y) {x*=y; x%=M;}; template<typename T, typename U> void chmax(T& x, U y) {if (x<y) x=y;}; template<typename T, typename U> void chmin(T& x, U y) {if (x>y) x=y;} bool vaild(int x, int y, int hh, int ww){return 0<=x&&x<hh&&0<=y&&y<ww;}
ll gcd(ll a, ll b) {if (b==0) return a; else return gcd(b, a%b);}
int keta(ll a) {int res=0; while(a>0) res+=a%10, a/=10; return res;}
const int up[]={1,-1,0,0}, lf[]={0,0,1,-1};
int main() {
int _; cin>>_;
while(_-->0) {
int n; cin>>n;
ll a[n]; for(int i=0;i<n;i++) cin>>a[i];
if (n%2==0) {
// 先手はXOR!=0にすれば勝ち
sort(a,a+n,greater<ll>());
ll an=0;
for(int i=0;i<n;i++) {
if (i%2==0) an+=a[i];
else an-=a[i];
}
if (an==0) {
cout<<"Second"<<endl;
} else {
cout<<"First"<<endl;
}
} else {
// 必ず後手にXOR!=0で渡してしまう
cout<<"Second"<<endl;
}
}
}
// ・配列の大きさok? ・priority_queueはgreater? ・debug消した?
// ・落ち着いて。提出まで4分待ってね……WJ……1/10……2/10……
// Thank you for making problems and running the contest
| #define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(...) begin(__VA_ARGS__) , end(__VA_ARGS__)
#define boost {ios_base::sync_with_stdio(false); cin.tie(); cout.tie();}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector <int> vi;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
constexpr ll nax = 2e5+6969, INF = 2e9+6969;
struct P
{
PLL x;
PLL y;
int typ;
void op2()
{
PLL tmp = y;
y = x;
x = mp(-tmp.fi, -tmp.se);
typ ^= 1;
}
void op1()
{
PLL tmp = x;
x = y;
y = mp(-tmp.fi, -tmp.se);
typ ^= 1;
}
void op3(ll p)
{
x = mp(2*p - x.fi, -x.se);
}
void op4(ll p)
{
y = mp(2*p - y.fi, -y.se);
}
void f(PLL val)
{
if(typ) swap(val.fi, val.se);
PLL tmp = mp(x.fi + x.se * val.fi, y.fi + y.se * val.se);
cout << tmp.fi << " " << tmp.se << "\n";
}
};
int n,m;
PLL point[nax], ans[nax];
P ops[nax];
bool rev[nax];
vector <pair<PLL,int>> Q;
P p;
int main()
{
p.x = mp(0,1);
p.y = mp(0,1);
p.typ = 0;
ops[0] = p;
cin >> n;
for(int i=1;i<=n;i++) cin >> point[i].fi >> point[i].se;
cin >> m;
for(int i=1;i<=m;i++)
{
ll a,b = 0;
cin >> a;
if(a > 2) cin >> b;
if(a == 1) p.op1();
if(a == 2) p.op2();
if(a == 3) p.op3(b);
if(a == 4) p.op4(b);
ops[i] = p;
}
int q;
cin >> q;
for(int i=1;i<=q;i++)
{
ll a,b;
cin >> a >> b;
PLL tmp = point[b];
ops[a].f(tmp);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline ll read() {
ll sum = 0, ff = 1;
char ch = getchar();
while(ch < '0' || ch > '9') {
if(ch == '-') {
ff = -1;
}
ch = getchar();
}
while(ch >= '0' && ch <= '9') {
sum = sum * 10 + ch - 48;
ch = getchar();
}
return sum * ff;
}
void write(ll x) {
if(x < 0)
putchar('-'), x = -x;
if(x > 9)
write(x / 10);
putchar(x % 10 + '0');
}
int a, b, c;
int main() {
// freopen(".in", "r", stdin);
// freopen(".out", "w", stdout);
a = read(), b = read(), c = read();
if(a * a + b * b < c * c)
puts("Yes");
else
puts("No");
return 0;
}
| #include <iostream>
#include <algorithm>
using namespace std;
int main() {
int N, K;
cin >> N >> K;
long long ans = 0;
int abmin = max(2, K + 2);
int abmax = min(2 * N, K + 2 * N);
for (int ab = abmin; ab <= abmax; ab++) {
long long abl = max(ab - N, 1);
long long abr = min(N, ab-1);
long long cdl = max(ab - K - N, 1);
long long cdr = min(N, ab - K - 1);
ans += (abr - abl + 1) * (cdr - cdl + 1);
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int INF = int (1e9) + int (1e5);
const ll INFL = ll(2e18) + ll(1e10);
const ui MOD = 1E9 + 7;
const double EPS = 1e-9;
#define FOR(i,n) for (int i=0;i<(n);++i)
#define ROF(i,x) for(int i = (x) ; i >= 0 ; --i)
#define MP make_pair
#define all(a) (a).begin(),(a).end()
#define ODD(x) ( ((x)&1)==0?0:1 )
#define SIGN(x) ( ((x) > 0) - ((x) < 0) )
#define dbg(x) cerr << #x"= " << x << endl
std::mt19937_64 generator(std::chrono::system_clock::now().time_since_epoch().count());
inline ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a, ll b) { return a ? gcd(b%a, a): b; }
ll lcm(ll a, ll b) { return a / gcd(a,b) * b; }
void READ(bool _local){
ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef _DEBUG
if (_local)
freopen ("in.txt", "r", stdin);
#endif
}
#define NO "UNSOLVABLE\n"
string s[3];
int mp[27];
bool used[10];
int sz[3];
void solve(int idx,int carry=0){
FOR(i,3) {
if (idx == sz[i] - 1 && mp[s[i][idx] - 'a'] == 0) return;
}
if (idx==sz[2]){
if (carry) return;
FOR(i,3){
reverse(all(s[i]));
for(char c:s[i]){
int d = c-'a';
if (d==26) continue;
cout << mp[d];
}
cout << '\n';
}
exit(0);
}
FOR(i,3) {
if (mp[s[i][idx] - 'a'] == -1) {
FOR(j, 10) {
if (used[j]) continue;
mp[s[i][idx] - 'a'] = j;
used[j]=1;
solve(idx, carry);
used[j]=0;
}
mp[s[i][idx] - 'a'] = -1;
return;
}
}
int num = mp[s[0][idx]-'a']+mp[s[1][idx]-'a']+carry;
int d = num%10;
if (d!=mp[s[2][idx]-'a']) return;
solve(idx+1,num/10);
}
int main() {
READ(0);
FOR(i,3) {cin>>s[i];sz[i]=s[i].size();}
if (sz[2] < max(sz[0],sz[1])) {cout << NO;return 0;}
if (sz[2] > max(sz[0],sz[1])+1) {cout << NO;return 0;}
FOR(i,3) reverse(all(s[i]));
FOR(i,2) while(s[i].size()<s[2].size()) s[i] += char('z'+1);
memset(mp,-1,sizeof(mp));
mp[26]=0;
solve(0);
cout << NO;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
vector<int> check;
string get(string s){
string n="";
for (char&c:s){
n.push_back(check[c-'a']+'0');
}
return n;
}
int main(){
string s1,s2,s3;cin>>s1>>s2>>s3;
check.assign(26,-1);
for (char&c:s1) check[c-'a']=1;
for (char&c:s2) check[c-'a']=1;
for (char&c:s3) check[c-'a']=1;
int cnt=0;for(int &v:check) cnt+=(v==1);
if (cnt>10) {
cout<<"UNSOLVABLE\n";
return 0;
}
queue<vector<int>> q;
q.push(vector<int>());
while (q.front().size()<cnt){
vector<int> v=q.front();
q.pop();
vector<bool> inside(10);
for (int i:v) inside[i]=true;
v.push_back(0);
for (int i=0;i<10;++i){
if (inside[i]) continue;
v.back()=i;
q.push(v);
}
}
while (!q.empty()){
vector<int> v=q.front();
q.pop();
int cur=0;
for (int i=0;i<26;++i){
if (check[i]!=-1) check[i]=v[cur++];
}
string n1=get(s1),n2=get(s2),n3=get(s3);
if (n1[0]!='0'&&n2[0]!='0'&&n3[0]!='0'){
long long z1=stoll(n1),z2=stoll(n2),z3=stoll(n3);
if (z1+z2==z3){
cout<<z1<<'\n';
cout<<z2<<'\n';
cout<<z3<<'\n';
return 0;
}
}
}
cout<<"UNSOLVABLE\n";
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int main(){
string S;
cin >> S;
int ans = 0;
for(int i = 0; i < S.size(); i++){
if(i % 2 == 0 && S.at(i) > 'Z') ans++;
if(i % 2 == 1 && S.at(i) < 'a') ans++;
}
if(ans == S.size()) cout << "Yes" << endl;
else cout << "No" << endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
// #pragma GCC target ("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimization ("unroll-loops")
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC target("fpmath=387") //extra precision
#define debug_input cout<<"input"<<endl;freopen("input.txt","r",stdin);
#define debug_output cout<<"output"<<endl;freopen("output.txt","w",stdout);
#define debug debug_input;debug_output;
typedef double db;
typedef string str;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef pair<double,double> pd;
#define F first
#define S second
#define endl '\n'
#define ALL(a) a.begin(),a.end()
#define mp make_pair
#define pb push_back
#define FOR(i,a,b) for(int i=a;i<(int)b;i++)
#define FORN(i,a,b) for(int i=a;i<=(int)b;i++)
#define FORB(i,a,b) for(int i=a;i>=(int)b;i--)
#define REP(i,x) FOR(i,0,x)
#define MEM(arr, x) memset(arr, (x), sizeof(arr))
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<str> vs;
typedef vector<pi> vii;
typedef vector<pl> vll;
const int MOD = 1e9+7;
const ll INF = 1e18;
const ld PI = acos((ld)-1);
const int d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1};
const int d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1};
void solve(){
str x;
cin>>x;
int a = 1, b = 1;
for(int i=0;i<(int)x.size();i+=2)
if(x[i] >= 'A' && x[i] <= 'Z')
a = 0;
for(int i=1;i<(int)x.size();i+=2)
if(x[i] >= 'a' && x[i] <= 'z')
b = 0;
if(a && b) cout<<"Yes";
else cout<<"No";
cout<<endl;
}
int main(){
ios_base::sync_with_stdio(false);cin.tie(nullptr);
// cout.tie(nullptr);
// debug_output;
// debug;
int t = 1;
// cin>>t;
for(int tc=1;tc<=t;tc++){
// cout<<"Case #"<<tc<<": ";
solve();
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int main() {
string str;
int count = 1;
cin >> str;
for (auto s : str) {
if (count%2 == 1 && isupper(s)) {
cout << "No";
return 0;
}
else if (count%2 == 0 && islower(s)) {
cout << "No";
return 0;
}
++count;
}
cout << "Yes";
} | #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define REP(i, k, n) for(ll i = k; i < n; ++i)
#define REPI(i, k, n) for(ll i = k; i >= n; --i)
#define vi vector<int>
#define vch vector<char>
#define vstr vector<string>
#define vll vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vpl vector<pair<ll, ll>>
#define vpi vector<pair<int, int>>
#define F first
#define S second
#define el "\n"
#define sz(x) x.size()
#define ld long double
#define sortar(v) sort(v.begin(),v.end())
#define rsort(v) sort(v.rbegin(),v.rend())
#define all(x) x.begin(), x.end()
#define div 1000000007
#define div2 998244353
#define pi 3.14159265358979323846
#define inf 1000000000000000000
#define blk 455
#define pb push_back
#define ppb pop_back
#define print(x) for(auto p:x) cout<<p<<' '; cout<<el;
#define N 1000005
bool isPrime[N] = {false};
vll prm;
vll SPF(N);
void sieve()
{
isPrime[1] = isPrime[0] = 0;
ll i;
for(i=2;i<N;++i) isPrime[i] = 1;
for(i=2;i*i<N;++i)
{
if(isPrime[i])
{
for(ll j = i*i; j<N; j += i)
isPrime[j] = 0;
}
}
if(!prm.empty())
prm.clear();
REP(i,2,N)
{
if(isPrime[i])
prm.pb(i);
}
}
bool flip(bool f)
{
if(f) return 0;
return 1;
}
ll fastPower(ll a, ll b)
{
if(b == 0) return 1;
ll prod = 1;
while(b > 0)
{
if(b & 1)
prod = prod * a;
b = b >> 1;
a = a * a;
}
return prod;
}
ll fact(ll n) {
ll res = 1;
for(ll i=2;i<=n;i++) {
res*=i;
}
return res;
}
ll nCr(ll n,ll r) {
return (ld)fact(n)/(ld)(fact(r)*fact(n-r));
}
void printa(bool f){
if(f) cout<<"YES"<<el;
else cout<<"NO"<<el;
}
void solve()
{
string a;
cin>>a;
ll n = a.length(), i;
REP(i,0,n){
int v = (int)a[i];
if(i&1){
if(v>=65 && v <=90) continue;
else{cout<<"No"<<el; return;}
}
else{
if(v >= 97 && v <= 122) continue;
else{cout<<"No"<<el; return;}
}
}
cout<<"Yes"<<el;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("C:/Users/Lenovo/Desktop/inpOut/input.txt", "r", stdin);
freopen("C:/Users/Lenovo/Desktop/inpOut/output.txt", "w", stdout);
#endif
// ios_base::sync_with_stdio(0);
// cin.tie(0);
int tc = 1, i = 1;
scanf("%d", &tc);
while(tc--)
{
// cout<<"Case #"<<i<<": ";
solve();
// ++i;
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define fz(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
#define ffe(it,v) for(__typeof(v.begin()) it=v.begin();it!=v.end();it++)
#define fill0(a) memset(a,0,sizeof(a))
#define fill1(a) memset(a,-1,sizeof(a))
#define fillbig(a) memset(a,63,sizeof(a))
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
int n;
char s[500005],t[500005];
int p1[500005],n1=0;
int p2[500005],n2=0;
int main(){
scanf("%d%s%s",&n,s+1,t+1);
for(int i=1;i<=n;i++) if(s[i]=='1') p1[++n1]=i;
for(int i=1;i<=n;i++) if(t[i]=='1') p2[++n2]=i;
if(n1<n2||(n1-n2)%2) return puts("-1"),0;
ll ans=0;
set<int> st;
for(int i=1;i<=n1;i++) st.insert(p1[i]);
for(int i=n2;i;i--){
set<int>::iterator it=st.lower_bound(p2[i]);
if(it==st.end()) return puts("-1"),0;
ans+=*it-p2[i];st.erase(*it);
}
vector<int> v;
ffe(it,st) v.pb(*it);
for(int i=0;i<v.size();i+=2) ans+=v[i+1]-v[i];
printf("%lld\n",ans);
return 0;
} |
#include <bits/stdc++.h>
#define loop(s, e, i) for (int i = s; i < e; ++i)
#define print(s) cout << s << endl;
#define DIV 1000000007
#define ll long long
using namespace std;
const int INF = 1e9+7;
int show_matrix(vector<vector<int>> &dp) {
loop(0, dp.size(), i) {
loop(0, dp[i].size(), j) {
cout << dp[i][j] << " ";
}
cout << endl;
}
return 0;
}
/*
浮動小数点の入力
cout << fixed << setprecision(9) << endl;
*/
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
ll H, W;
cin >> H >> W;
ll gx ,gy;
vector<vector<char>> MAP(H, vector<char>(W, '.'));
vector<vector<ll>> DIST(H, vector<ll>(W, INF));
queue<pair<int, int>> Q;
vector<pair<int, int>> WARP[26];
loop(0, H, i) {
loop(0, W, j) {
char inp;
cin >> inp;
if (inp == 'S') {
Q.push(make_pair(i, j));
MAP[i][j] = '.';
DIST[i][j] = 0;
} else if (inp == 'G') {
MAP[i][j] = '.';
gx = i;
gy = j;
} else if (inp == '.') {
MAP[i][j] = '.';
} else if (inp == '#') {
MAP[i][j] = '#';
} else {
MAP[i][j] = inp;
ll pos = inp - 'a';
WARP[pos].push_back(make_pair(i, j));
}
}
}
ll dx[] = {0, 1, 0, -1};
ll dy[] = {1, 0, -1, 0};
while(!Q.empty()) {
auto top = Q.front(); Q.pop();
ll x = top.first;
ll y = top.second;
ll c = DIST[x][y];
loop(0, 4, i) {
ll nx = x + dx[i];
ll ny = y + dy[i];
if (0 <= nx && nx < H && 0 <= ny && ny < W) {
if (MAP[nx][ny] == '#' || DIST[nx][ny] <= c+1) continue;
DIST[nx][ny] = c+1;
Q.push(make_pair(nx, ny));
}
}
if (MAP[x][y] != '.') {
ll pos = MAP[x][y] - 'a';
for (auto &p : WARP[pos]) {
ll nx = p.first;
ll ny = p.second;
if (DIST[nx][ny] > c+1) {
DIST[nx][ny] = c+1;
Q.push(make_pair(nx, ny));
}
MAP[nx][ny] = '.';
}
}
MAP[x][y] = '.';
}
ll result = DIST[gx][gy];
if (result == INF) {
print(-1);
} else {
print(result);
}
}
|
#include <iostream>
#include <bits/stdc++.h>
#define ll long long int
#define max_value 0x3f3f3f
/*0 0, 0, 1, 0], [0, 1, 0, 0, 0], [0, 0, 0, 0, 1], [0, 0, 1, 0, 0], 1, 0, 0, 0, 0
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);*/
using namespace std;
typedef pair<ll,ll> pii;
const int inf=1e9+7;
const int mod=998244353;
const int maxn=3001;
ll modexpo(ll a,ll b){
a%=inf;
ll res=1;
while(b>0){
if(b&1)
res=res*a%inf;
a=a*a%inf;
b>>=1;
}
return res;
}
int arr[maxn][5];
bool good(int mid,int n){
set<int>masks;
for(int i=0;i<n;i++){
int mask=0;
for(int j=0;j<5;j++){
if(arr[i][j]>=mid)
mask|=(1<<j);
}
masks.insert(mask);
}
for(auto i:masks){
for(auto j:masks){
for(auto k:masks){
if((i|j|k)==31)
return true;
}
}
}
return false;
}
void solve(){
int n;
cin>>n;
for(int i=0;i<n;i++){
for(int j=0;j<5;j++)
cin>>arr[i][j];
}
int h=1e9+7;
int low=1;
while(h-low>1){
int mid=(h+low)/2;
if(good(mid,n))
low=mid;
else
h=mid;
}
cout<<low;
}
int main(){
int t;
t=1;
while(t--){
solve();
}
}
| // abc196_e
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../../debug_util/cxx-prettyprint/prettyprint.hpp"
#include "../../debug_util/rng.hpp"
#include "../../debug_util/timer.hpp"
#endif
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
#define REP(i, n) for (int i = 0 ; i < (int)(n) ; ++i)
#define REPN(i, m, n) for (int i = m ; i < (int)(n) ; ++i)
#define REP_REV(i, n) for (int i = (int)(n) - 1 ; i >= 0 ; --i)
#define REPN_REV(i, m, n) for (int i = (int)(n) - 1 ; i >= m ; --i)
#define ALL(x) x.begin(), x.end()
#define INF (ll)(1e15)
#define MOD (1000000007)
#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int idx=0;idx<(n-1);idx++) cout << (vec)[idx] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << "\n";}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;
void solve(){
ll N;
cin >> N;
vector<ll> A(N), T(N);
REP(i, N) cin >> A[i] >> T[i];
ll Q;
cin >> Q;
vector<ll> X(Q);
REP(i, Q) cin >> X[i];
ll sm = 0;
ll sup=INF, inf=-INF;
REP(i, N){
if (T[i] == 1){
sm += A[i];
sup += A[i];
inf += A[i];
} else if (T[i] == 2){
inf = max(inf, A[i]);
sup = max(sup, A[i]);
} else {
sup = min(sup, A[i]);
inf = min(inf, A[i]);
}
}
REP(i, Q){
ll ans = max(min(X[i] + sm, sup), inf);
print(ans);
}
}
int main() {
#ifdef LOCAL
ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif
solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PP;
#define MOD 1000000007
//#define MOD 998244353
#define INF 2305843009213693951
//#define INF 810114514
#define PI 3.141592653589
#define setdouble setprecision
#define REP(i,n) for(ll i=0;i<(n);++i)
#define OREP(i,n) for(ll i=1;i<=(n);++i)
#define RREP(i,n) for(ll i=(n)-1;i>=0;--i)
#define all1(i) begin(i),end(i)
#define GOODBYE do { cout << "-1" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug true
#define debug2 false
class unionfind{
/*
Copyright (c) 2020 0214sh7
https://github.com/0214sh7/library/
*/
private:
std::vector<int> UF,rank;
public:
void init(int N){
UF.clear();
rank.clear();
for(int i=0;i<N;i++){
UF.push_back(i);
rank.push_back(0);
}
}
int root(int k){
if(UF[k]==k){
return k;
}else{
UF[k]=root(UF[k]);
return UF[k];
}
}
bool same(int p,int q){
return root(p)==root(q);
}
void unite(int P,int Q){
int p=root(P);
int q=root(Q);
if(p==q)return;
if(rank[p]<rank[q])std::swap(p,q);
UF[q]=p;
if(rank[p]==rank[q])rank[p]++;
}
};
int main(void){
ll H,W;
vector<string> S;
cin >> H >> W;
REP(i,H){
string s;
cin >> s;
S.push_back(s);
}
if(H<=2 || W<=2){
cout << 0 << endl;
return 0;
}
unionfind UF;
UF.init(H+W-3);
//0:外周
//1~H-2:横線
//H-1~H+W-4:縦線
for(ll i=1;i<H-1;i++){
if(S[i][0]=='#' || S[i][W-1]=='#'){
UF.unite(0,i);
}
}
for(ll j=1;j<W-1;j++){
if(S[0][j]=='#' || S[H-1][j]=='#'){
UF.unite(0,H-2+j);
}
}
for(ll i=1;i<H-1;i++){
for(ll j=1;j<W-1;j++){
if(S[i][j]=='#'){
UF.unite(i,H-2+j);
}
}
}
set<ll> Y,X;
Y.insert(UF.root(0));
X.insert(UF.root(0));
for(ll i=1;i<H-1;i++){
Y.insert(UF.root(i));
}
for(ll i=H-1;i<H+W-3;i++){
X.insert(UF.root(i));
}
ll R=Y.size()-1,C=X.size()-1;
//cout << R MM C << endl;
cout << min(R,C) << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#ifndef ONLINE_JUDGE
#define F_AND_L __FUNCTION__ << ":" << __LINE__
#define X(x) { cerr << F_AND_L << "[ " << #x << " : " << x << " ]" << endl;}
#define D(x) << "[ " << #x << " : " << x << " ] "
#define S(...) cerr << F_AND_L __VA_ARGS__ << endl;
#define PC(a) { cerr << F_AND_L << " " << #a << "=["; for(auto __xmmp: a) { cerr << __xmmp << " "; } cerr << "]" << endl; }
#define PA(a,s,l) { cerr << F_AND_L << " " << #a << "=["; for(int __xmmp=s; __xmmp<s+l; __xmmp++) { cerr << a[__xmmp] << " "; } cerr << "]" << endl; }
#else
#define X(x)
#define D(x)
#define S(...)
#define PC(a)
#define PA(a,s,l)
#endif
#define rep(i, s, e) for(int i=s; i<e; i++)
#define reps(i, s, e, stp) for(int i=s; i<e; i+=stp)
#define per(i, s, e) for(int i=e; i>=0; i--)
#define pers(i, s, e, stp) for(int i=e; i>=0; i+=stp)
#define F(i, n) for(int i=0; i<n; i++)
#define R(i, n) for(int i=n-1; i>=0; i--)
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int h, w, m=0;
cin >> h >> w;
int a[h][w];
for(int i=0; i<h; i++) {
for(int j=0; j<w; j++) {
cin >> a[i][j];
if(i == 0 && j == 0)
m = a[i][j];
m=min(a[i][j], m);
}
}
ll ans=0;
for(int i=0; i<h; i++) {
for(int j=0; j<w; j++) {
ans += a[i][j] - m;
}
}
cout << ans << endl;
}
|
#include<bits/stdc++.h>
using namespace std;
// #pragma GCC target ("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimization ("unroll-loops")
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC target("fpmath=387") //extra precision
#define debug_input cout<<"input"<<endl;freopen("input.txt","r",stdin);
#define debug_output cout<<"output"<<endl;freopen("output.txt","w",stdout);
#define debug_io debug_input;debug_output;
//start debugger
#define tpc template<class c
#define ckt(x) tpc> typename enable_if<sizeof ptb<c>(0) x 1, debug&>::type
#define rpt return *this
#define dop debug& operator <<
tpc> struct rge { c b, e; };
tpc> rge<c> range(c x, c y) { return rge<c>{x, y}; }
tpc> auto ptb(c* x) -> decltype(cerr << *x, 0);
tpc> char ptb(...);
struct debug {
#ifdef LOCAL
// ~debug() {cerr << "\u001b[0m\n";}
// debug() {cerr << "\u001b[33m";}
ckt(!=) operator <<(c x) { cerr << boolalpha << x; rpt; }
ckt(==) operator <<(c x) { rpt << range(x.begin(), x.end()); }
tpc, class b> dop(pair<c,b> x) { rpt << "(" << x.first << ", " << x.second << ")"; }
tpc> dop(rge<c> r) { *this << "{";
for(auto it = r.b; it != r.e; ++it) *this << ", "+2*(it==r.b) << *it; rpt << "}";}
#else
tpc> dop(const c&) {rpt;}
#endif
};
#define imie(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
//end debugger
typedef double db;
typedef string str;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef pair<double,double> pd;
#define F first
#define S second
#define endl '\n'
#define ALL(a) a.begin(),a.end()
#define mp make_pair
#define pb push_back
#define FOR(i,a,b) for(int i=a;i<(int)b;i++)
#define FORN(i,a,b) for(int i=a;i<=(int)b;i++)
#define FORB(i,a,b) for(int i=a;i>=(int)b;i--)
#define REP(i,x) FOR(i,0,x)
#define MEM(arr, x) memset(arr, (x), sizeof(arr))
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<str> vs;
typedef vector<pi> vii;
typedef vector<pl> vll;
// const int MOD = 1e9+7;
const ll INF = 1e18;
const ld PI = acos((ld)-1);
const int d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1};
const int d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1};
ll MOD;
ll bin_pow(ll x,ll y){
if(y == 0) return 1;
ll temp = bin_pow(x,y/2)%MOD;
if(y&1) return (((temp*temp)%MOD)*x)%MOD;
return (temp*temp)%MOD;
}
void solve(){
ll n, m;
cin>>n>>m;
MOD = m * m;
n = bin_pow(10, n);
cout<<n/m<<endl;
}
int main(){
ios_base::sync_with_stdio(false);cin.tie(nullptr);
// cout.tie(nullptr);
#ifdef LOCAL
// system("cls");
// debug_input;
// debug_output;
// debug_io;
#endif
int t = 1;
// cin>>t;
for(int tc=1;tc<=t;tc++){
// cout<<"Case #"<<tc<<": ";
solve();
}
return 0;
} | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a)
#define dumparr(a,n)
#endif
#define FOR(i, a, b) for(ll i = (ll)a;i < (ll)b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = (ll)b-1LL;i >= (ll)a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))
typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;
typedef long double ld;
typedef pair<ld,ld> pdd;
pll operator+(pll a,pll b){
return pll(a.first+b.first,a.second+b.second);
}
pll operator-(pll a,pll b){
return pll(a.first-b.first,a.second-b.second);
}
pll operator*(ll a,pll b){
return pll(b.first*a,b.second*a);
}
const ll INF=(1LL<<60);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
a=abs(a);
b=abs(b);
if(a==0)return b;
if(b==0)return a;
if(a < b) return gcd(b, a);
ll r;
while ((r=a%b)) {
a = b;
b = r;
}
return b;
}
#endif
template<class T>
bool chmax(T& a,const T& b){
if(a<b){
a=b;
return true;
}
return false;
}
template<class T>
bool chmin(T& a,const T& b){
if(a>b){
a=b;
return true;
}
return false;
}
template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
os << "(" << a.first << "," << a.second << ")";
return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
os << "[ ";
REP(a.size()){
os<< a[i] << " ";
}
os<< " ]";
return os;
}
void solve(long long N, std::vector<long long> a){
ll ans=a[0];
REP(N){
ans=gcd(ans,a[i]);
}
cout<<ans<<endl;
}
int main(){
cout<<setprecision(1000);
long long N;
scanf("%lld",&N);
std::vector<long long> a(N);
for(int i = 0 ; i < N ; i++){
scanf("%lld",&a[i]);
}
solve(N, std::move(a));
return 0;
}
|
#include <bits/stdc++.h> //12.25 , -7,
using namespace std;
typedef long long ll;
typedef unsigned long long int ull;
#include <fstream>
#define int unsigned long long int
#define mod 1000000007
#define watch(x) cout<<(#x)<<" is "<<(x)<<"\n"
#define watch2(x,y) cout<<(#x)<<" is "<<(x)<<" and "<<(#y)<< " is " <<(y)<<"\n"
int powerr(int m,int n){if(m==0 || n==1)return m;if(n==0)return 1;int ans = 1;if(n&1)ans = m*powerr(m,n-1);else {ans = powerr(m,n/2);ans = ans * ans;}return ans%mod;}
int gcdd(int a,int b){if(b==0)return a; return gcdd(b,a%b);}
int lcmm(int a,int b){return (a*b)/gcdd(a,b);}
bool comparee(pair<int,int> &a,pair<int,int> &b){
return a.first < b.first;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,k;
cin>>n>>k;
vector<pair<int,int>> v;
for(int i=0;i<n;++i){
int a,b;cin>>a>>b;
v.push_back({a,b});
}
sort(v.begin(),v.end(),comparee);
int summ = k;
int pos = 0;
for(int i=0;i<n;++i){
if(v[i].first-pos<=summ){
summ = summ - (v[i].first - pos);
summ = summ + v[i].second;
pos = v[i].first;
}
else {
pos = pos + summ;
summ = 0;
break;
}
}
pos = pos + summ;
cout<<pos;
return 0;
}
| //Never stop trying
#include "bits/stdc++.h"
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
typedef long long ll;
#define int ll
typedef string str;
typedef long double ld;
typedef pair<int, int> pi;
#define fi first
#define se second
typedef vector<int> vi;
typedef vector<pi> vpi;
#define pb push_back
#define eb emplace_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define endl "\n"
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
const int MOD = 1e9 + 7; //998244353
const ll INF = 1e18;
const int MX = 2e5 + 10;
const int nx[4] = {0, 0, 1, -1}, ny[4] = {1, -1, 0, 0}; //right left down up
template<class T> using V = vector<T>;
template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
ll cdiv(ll a, ll b) { return a / b + ((a ^ b) > 0 && a % b); } // divide a by b rounded up
//constexpr int log2(int x) { return 31 - __builtin_clz(x); } // floor(log2(x))
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
//mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
ll random(ll a, ll b){
return a + rng() % (b - a + 1);
}
#ifndef LOCAL
#define cerr if(false) cerr
#endif
#define dbg(x) cerr << #x << " : " << x << endl;
#define dbgs(x,y) cerr << #x << " : " << x << " / " << #y << " : " << y << endl;
#define dbgv(v) cerr << #v << " : " << "[ "; for(auto it : v) cerr << it << ' '; cerr << ']' << endl;
#define here() cerr << "here" << endl;
void IO() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
/////////////////////////ONLY CLEAN CODES ALLOWED/////////////////////////
int32_t main() {
boost; IO();
int N,K; cin>>N>>K;
vpi vec={{0,K}};
FOR(i,0,N){
int a,b; cin>>a>>b;
vec.eb(a,b);
}
sort(all(vec));
int ans=0,r=0;
FOR(i,0,sz(vec)){
r+=vec[i].se;
if(i==sz(vec)-1) ans+=r;
else{
int d=vec[i+1].fi-vec[i].fi;
if(d<=r){
ans+=d;
r-=d;
}
else{
ans+=r;
break;
}
}
}
cout << ans << endl;
return 0;
}
//Change your approach |
#include <bits/stdc++.h>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
#define MAX_V 200005
ll A[MAX_V], X[MAX_V], Y[MAX_V];
ll buy[MAX_V];
ll ans = -3e9;
int V;
#define SZ(x) ((int)((x).size()))
vector<int> G[MAX_V];
bool used[MAX_V];
void add_edge(int from, int to){
G[from].push_back(to);
}
int main() {
ll N, M;
cin >> N >> M;
V = N;
rep(i, N)cin >> A[i];
rep(i, M){
cin >> X[i] >> Y[i];
X[i]--;
Y[i]--;
add_edge(X[i], Y[i]);
}
rep(i, MAX_V)buy[i] = 3e9;
//mmax[0] = A[0];
rep(v, N){
//cout << v << " " << buy[v] << " " << A[v] << endl;
chmax(ans, A[v] - buy[v]);
rep(i, SZ(G[v])){
ll j = G[v][i];
chmin(buy[j], buy[v]);
chmin(buy[j], A[v]);
}
}
cout << ans;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define N 2114514
const ll mod = 998244353;
const ll inf = 1000000000000000000;
P a[N];
ll num[N];
bool used[N];
int main() {
ll n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
ll x;
cin >> x;
num[i] = x;
a[i] = {x, i};
}
vector<vector<ll>> v(n + 1);
for (int i = 0; i < m; i++) {
ll x, y;
cin >> x >> y;
v[x].push_back(y);
}
sort(a + 1, a + n + 1);
queue<ll> que;
ll ans = -inf;
for (int i = 1; i <= n; i++) {
que.push(a[i].second);
ll ma = -inf;
while (!que.empty()) {
ll p = que.front();
que.pop();
for (ll x : v[p]) {
if (used[x]) continue;
used[x] = 1;
ma = max(ma, num[x] - a[i].first);
que.push(x);
}
}
ans = max(ans, ma);
}
cout << ans << endl;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define vec vector<int>
#define vecp vector<pair<int,int>>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define fr first
#define sc second
#define fr1(i,a,b) for(int i=a;i<b;i++)
#define fr2(i,a,b) for(int i=a;i>=b;i--)
#define fr3(i,a,b) for(int i=a;i<=b;i++)
#define umap unordered_map<int,int,custom_hash>
#define omap map<int,int>
#define uset unordered_set<int,custom_hash>
#define oset set<int>
#define pr pair<int,int>
#define mod 1000000007
#define mp make_pair
#define all(v) v.begin(),v.end()
#define ppb pop_back
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
// http://xorshift.di.unimi.it/splitmix64.c
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
void solve()
{
int n,m;
cin>>n>>m;
map<int,int> map1;
fr1(i,0,n)
{
int x;
cin>>x;
map1[x]++;
}
fr1(i,0,m)
{
int x;
cin>>x;
map1[x]++;
}
for(auto i:map1)if(i.sc==1)cout<<i.fr<<" ";
cout<<"\n";
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t=1;
//cin>>t;
fr3(i,1,t){
//cout<<"Case: "<<t<<;
solve();
}
return 0;
} | #include <bits/stdc++.h>
#define F first
#define S second
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define RFOR(i, a, b) for(int i = a; i >= b; i--)
#define all(v) ((v).begin()), ((v).end())
#define endl '\n'
using namespace std;
using ll = long long;
using ull = unsigned long long;
using Graph = vector<vector<int>>;
using vi = vector<int>;
using vl = vector<ll>;
using vll = vector<ll, ll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using BigInt = __int128;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
string s;
cin >> s;
if(s.size() == 1){
cout << (stoi(s) % 8 ? "No" : "Yes");
return 0;
}
if(s.size() == 2){
if(stoi(s) % 8 == 0)
return cout << "Yes", 0;
swap(s[0], s[1]);
if(stoi(s) % 8 == 0)
return cout << "Yes", 0;
return cout << "No", 0;
}
map<int, int> lookup;
for (const auto& c : s)
lookup[c-'0']++;
for (int i = 100; i < 1000; i++) {
if (i % 8) continue;
int t = i;
vi digits;
while (t) digits.push_back(t%10), t/=10;
bool ok = true;
for (const auto& d : digits) {
if (lookup[d] <= 0) ok = false;
lookup[d]--;
}
if(ok) return cout << "Yes", 0;
for (const auto& d : digits)
lookup[d]++;
}
cout << "No";
}
|
#include <bits/stdc++.h>
#define ff first
#define ss second
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define endl '\n'
// n acho que eu seja bom, mas eu ja fui pior
using namespace std;
const int MAX = 1e5+7;
const int INF = 1e9+7;
const ll LLINF = 0x3f3f3f3f3f3f3f3fll;
const int MOD = 1000000007;
const ld EPS = 1e-8;
const ld PI = acos(-1);
ll solve(ll n) {
return (n*(n+1)) / 2;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
ll n; cin >> n;
for (ll it = 1; it <= 1e9; it++) {
if (solve(it) >= n) {
cout << it << endl;
return 0;
}
}
return 0;
} | ///
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fo(i,a,b) for(int i=a;i<b;i++)
#define fodec(i,a,b) for(int i=a;i>b;i--)
#define sz(v) int(v.size())
#define len(s) s.length()
#define vi vector<int>
#define vll vector<ll>
#define vb vector<bool>
#define vvi vector<vector<int>>
#define vvb vector<vector<bool>>
#define vvll vector<vector<ll>>
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define piii pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define bit_cnt(x) __builtin_popcount(x)
#define fastio ios_base:: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define fileio freopen("input.txt","r",stdin); freopen("output.txt","w",stdout)
#define inf 1e9
#define cerr if(false)cerr
const int MOD = 1e9+7;
void solve(){
}
int main(){
int n; cin>>n;
int d=1;
int tot=0;
while(tot<n){
tot+=d;
d++;
}
cout<<d-1;
}
|
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <stack>
#include <vector>
using namespace std;
// タイプ定義
typedef long long llong;
// マクロ
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(llong i=llong(a);i<llong(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
int A[3];
int main()
{
cin >> A [0] >> A[1] >> A[2];
std::vector<int> v;
v.push_back(A[0]);
v.push_back(A[1]);
v.push_back(A[2]);
std::sort(v.begin(), v.end());
//cout << v[0] << v[1] << v[2];
if((v[1]-v[0]) == (v[2]-v[1])) {
cout << "Yes" << endl;
}else{
cout << "No" << endl;
}
return 0;
} | // In the name of God...
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define F first
#define S second
const int N = 3000;
int a[N], t;
bool mark[N];
ll GCD(int n, int m){
if(n == 0) return m;
if(m == 0) return n;
if(n > m) return GCD(n % m, m);
return GCD(n, m % n);
}
///////////////////////////////
int main(){
ios_base:: sync_with_stdio(false), cin.tie(0), cout.tie(0);
int n, m, k;
cin >> n >> m >> k;
if(n * n + m * m >= k * k) cout << "No\n";
else cout << "Yes\n";
return false;
} |
#include <bits/stdc++.h>
#define owo(i,a, b) for(int i=(a);i<(b); ++i)
#define uwu(i,a, b) for(int i=(a)-1; i>=(b); --i)
#define senpai push_back
#define ttgl pair<int, int>
#define ayaya cout<<"ayaya~"<<endl
using namespace std;
using ll = long long;
using ld = long double;
ll MOD = 1000000007;
const ll root = 3;
ll binpow(ll a,ll b){ll res=1;while(b){if(b&1)res=(res*a)%MOD;a=(a*a)%MOD;b>>=1;}return res;}
ll modInv(ll a){return binpow(a, MOD-2);}
const int INF = 0x3f3f3f3f;
const int NINF = 0xc0c0c0c0;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const ll NINFLL = 0xc0c0c0c0c0c0c0c0;
const int mxN = 200001;
vector<int> adj[mxN];
int dp[mxN];
int sz[mxN];
bool done[mxN];
int n;
void dfs(int u) {
sz[u] = 1;
vector<ttgl> t, o;
vector<int> rst;
int numod = 0;
for(int v: adj[u]) {
dfs(v);
if(sz[v]&1){
t.senpai({2*dp[v] - sz[v], v});
numod++;
}else {
rst.senpai(v);
}
sz[u]+=sz[v];
}
sort(t.begin(), t.end());
owo(_, 0, numod) {
if(_&1) {
//while(done[t[tid].second])tid--;
dp[u] += sz[t[_].second] - dp[t[_].second];
}else {//aoki choose a dp[0]
//while(done[t[tid].second])tid++;
dp[u]+=dp[t[_].second];
}
}
for(int k: rst) {
if(dp[k] < sz[k] - dp[k]) {
dp[u]+=dp[k];
}else{
if(numod%2==0) dp[u]+=dp[k];
else dp[u]+=sz[k]-dp[k];
}
}
dp[u]++;
}
int main() {
//freopen("file.in", "r", stdin);
//freopen("file.out", "w", stdout);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
cin.tie(0)->sync_with_stdio(0);
cin>>n;
int a;
owo(i, 1, n) {
cin>>a;
a--;
adj[a].senpai(i);
}
dfs(0);
cout<<dp[0]<<"\n";
return 0;
} | #include <bits/stdc++.h>
#define fo(a,b,c) for (a=b; a<=c; a++)
#define fd(a,b,c) for (a=b; a>=c; a--)
#define ll long long
//#define file
using namespace std;
int n,i,j,k,l;
char S[500001];
char T[500001];
int s1[500001],s2[500001];
int ans,sum;
int main()
{
#ifdef file
freopen("b.in","r",stdin);
#endif
scanf("%d",&n);
scanf("%s",S+1);
scanf("%s",T+1);
fo(i,1,n)
{
s1[i]=s1[i-1]+(S[i]=='0');
s2[i]=s2[i-1]+(T[i]=='0');
}
fo(i,1,n) sum+=S[i]=='0';
ans=sum;
fo(i,1,n) sum-=T[i]=='0';
if (sum) {printf("-1\n");return 0;}
fo(i,1,n)
if (S[i]==T[i] && S[i]=='0' && s1[i]==s2[i])
--ans;
printf("%d\n",ans);
fclose(stdin);
fclose(stdout);
return 0;
} |
////////////////////////////////////
/// ∧__∧ ///
/// ( '・ω・) < Let's ///
/// ( つ旦と) Go AC ///
/// と__)___) ///
////////////////////////////////////
/// Coded In Sublime Text ///
////////////////////////////////////
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define forin(in) for(int i=0; i<(int)in.size(); i++) cin >> in[i]
#define forout(out) for(int i=0; i<(int)out.size(); i++) cout << out[i] << endl
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
int main() {
int a, b, c, d;
cin >> a >> b >> c >> d;
cout << max(a, b) - min(c, d) << endl;
} | #include<bits/stdc++.h>
using namespace std;
int a[3];
int n1,n2,n;
int main(){
int t,i,m,j,k;
cin>>a[0]>>a[1]>>a[2];
sort(a,a+3);
if(a[0]==a[1])
{
cout<<a[2]<<endl;
}
else if(a[1]==a[2])
{
cout<<a[0]<<endl;
}
else
{
cout<<0<<endl;
}
} |
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define PRECISION cout << fixed << setprecision(20);
using namespace std;
template<class Fun>
class y_combinator_result {
Fun fun_;
public:
template<class T>
explicit y_combinator_result(T &&fun): fun_(std::forward<T>(fun)) {}
template<class ...Args>
decltype(auto) operator()(Args &&...args) {
return fun_(std::ref(*this), std::forward<Args>(args)...);
}
};
template<class Fun>
decltype(auto) y_combinator(Fun &&fun) {
return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun));
}
void solve() {
int n;
cin >> n;
vector<array<int, 5>> arr(n);
vector<int> store;
for (int i = 0; i < n; i++) {
for (int j = 0; j < 5; j++) {
cin >> arr[i][j];
store.push_back(arr[i][j]);
}
}
sort(store.begin(), store.end(), greater<>());
int low = 0, high = 1e9 + 6;
auto check = [&](int x) -> bool {
vector<int> mask(5, -1);
auto get = y_combinator([&](auto get, int pos) -> bool {
if (pos == 5) {
vector<vector<int>> all(3);
for (int i = 0; i < 5; i++) {
all[mask[i]].push_back(i);
}
for (int who = 0; who < 3; who++) {
if (all[who].size()) {
int done = 0;
for (int i = 0; i < n; i++) {
int ok = 1;
for (int j: all[who]) {
if (arr[i][j] < x) {
ok = 0; break;
}
}
if (ok) {
done = 1;
break;
}
}
if (!done) {
return false;
}
}
}
return true;
}
for (int i = 0; i <= 2; i++) {
mask[pos] = i;
if (get(pos + 1)) {
return true;
}
}
return false;
});
return get(0);
};
while (low + 1 < high) {
int mid = (low + high) / 2;
if (check(mid)) {
low = mid;
} else {
high = mid;
}
};
cout << low << "\n";
}
int main() {
FASTIO;
PRECISION;
int t = 1;
// cin >> t;
for (int i = 1; i <= t; i++) {
solve();
}
} | #include <bits/stdc++.h>
using namespace std ;
#define rep(i,n) for( int i = 0 ; i < n ; i++ )
typedef long long ll ;
const ll mod = 1e9 + 7 ;
int main(){
ll n ;
cin >> n ;
ll ans = 0 ;
map<ll,ll> P ;
rep(i,n){
ll p ;
cin >> p ;
P[p]++ ;
if( p == ans ){
for(ll j = ans ; ans < 200003 ; j++ ){
if(P[j] != 0 ) continue ;
else{
cout << j << endl;
ans = j ;
break ;
}
}
}
else{
cout << ans << endl ;
}
}
} |
#include <bits/stdc++.h>
using namespace std;
const int p[]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};
int n,x[55];
long long ans=1e18;
void dfs(int i,long long j) {
if (i==15) {
for (int i=1; i<=n; ++i)
if (__gcd((long long)x[i],j)==1) return;
ans=min(ans,j); return;
}
dfs(i+1,j);
dfs(i+1,j*p[i]);
}
int main() {
cin>>n;
for (int i=1; i<=n; ++i) cin>>x[i];
dfs(0,1);
cout<<ans;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb emplace_back
#define pii pair<int , int>
#define F first
#define S second
const int mod = 1000000007;
const int MAXX = 1e5 + 5;
int t , n;
int x[MAXX];
int gcd(int a , int b){
return (a ? gcd(b % a , a) : b);
}
signed main()
{
_FastIO;
cin >> n;
int a[16] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47};
vector<int> v;
for(int i = 1; i < (1 << 15); i++){
int k = 1;
for(int j = 0; j < 15; j++){
if(i & (1 << j)){
k *= a[j];
}
}
v.pb(k);
}
sort(v.begin() , v.end());
map<int , bool> m;
int ans = 1;
for(int i = 0; i < n; i++){
cin >> x[i];
}
for(int i = 0; i < v.size(); i++){
bool f = true;
for(int j = 0; j < n; j++){
if(gcd(v[i] , x[j]) == 1)
f = false;
}
if(f){
cout << v[i] << endl;
return 0;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main()
{
double N;
cin >> N;
double a;
int ans;
a = 1.08 * N;
ans = a;
if(ans < 206) {
cout << "Yay!" << endl;
}
else if(ans == 206) {
cout << "so-so" << endl;
}
else {
cout << ":(" << endl;
}
//system("pause");
return 0;
}
| // Ref :
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
#define tab "\t"
#define endl "\n"
#define pb emplace_back
#define sz(x) int((x).size())
#define gc getchar_unlocked
#define gcd(x,y) __gcd(x,y)
#define all(a) a.begin(), a.end() // usage in stl functions for traversing the container
#define rep(i,a,b) for(int i = a; i < b; i++) // @00G_aurkS00 @00G_aurkS00
#define rrep(i,a,b) for(int i = a; i >= b; i--)
#define in(a,b) ( (b).find(a) != (b).end() ) // returns true(1) if element is present otherwise false(0)
#define EPS 1e-9
#define INF (int)1e9
#define MOD 1000000007
#define countLZ(x) __builtin_clz(x) // returns the count of leading zeros in binary of a data upto first set(1) bit
#define countTZ(x) __builtin_ctz(x) // returns the count of trailing zeros in binary of a data from last set(1) bit
#define checkbit(n,b) ( (n >> b) & 1 ) // @00G_aurkS00 @00G_aurkS00
#define parityCheck(x) __builtin_parity(x) // returns 1(true) if odd number of set bits present in int, long data
#define setbitCount(x) __builtin_popcount(x) // returns the number of one’s(set bits) in binary of an int, long data
#define PI 3.1415926535897932384626433832795
#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 << "]";}
inline void boostIO(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input_6.txt","r",stdin);
freopen("output_6.txt","w",stdout);
#endif
}
/*=========================================================== End_Of_Header ===========================================================*/
int main(){
//boostIO();
ll tc = 1;
//cin >> tc;
while(tc--){
ll n;
cin >> n;
ll ans = n*1.08;
//cout << n*1.08 << endl;
if ( ans > 206 ) cout << ":(" << endl;
else if ( ans < 206 ) cout << "Yay!" << endl;
else cout << "so-so" << endl;
}
return 0;
} |
#include<bits/stdc++.h>
using namespace std ;
int main()
{
std::ios::sync_with_stdio(false) , cin.tie(0) ;
int n ;
cin >> n ;
vector<array<int , 2>> v(n) ;
for(int i = 0 ; i < n ; i ++) v[i][0] = i * 2 % n , v[i][1] = (i * 2 + 1) % n ;
for(int i = 0 ; i < n ; i ++) cout << v[i][0] + 1 << ' ' << v[i][1] + 1 << '\n' ;
return 0 ;
} | //#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define int long long
using namespace std;
typedef long long ll;
template<class T>T ABS(T x) {return x<0?-x:x;}
//int ksm(int x,int y) {int r=1;while(y) y&1?r=1ll*r*x%mod:0,x=1ll*x*x%mod,y>>=1;return r;}
//char __buf[1<<20],*__p1,*__p2;
//#define getchar() (__p1==__p2?(__p2=__buf+fread(__p1=__buf,1,1<<20,stdin),__p1==__p2?EOF:*__p1++):*__p1++)
int read() {
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9') {if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48),ch=getchar();
return s*w;
}
const int maxn = 4e5+10;
//const int mod = ;
//struct Edge{int to,next;}a[maxn];int h[maxn],cnt;
//void add(int x,int y) {a[++cnt]=(Edge){y,h[x]},h[x]=cnt,a[++cnt]=(Edge){x,h[y]},h[y]=cnt;}
//vector<int>G[maxn];
//void add(int x,int y) {G[x].push_back(y),G[y].push_back(x);}
int a[maxn],ans,n;
signed main() {
n=read();
for(int i=1;i<=n<<1;i++) a[i]=read();
for(int i=1;i<=n<<1;i++) ans+=a[i];
priority_queue<int,vector<int>,greater<int> >Q;
for(int i=1;i<=n;i++) Q.push(a[n-i+1]),Q.push(a[n+i]),ans-=Q.top(),Q.pop();
cout<<ans<<'\n';
return 0;
} |
#pragma GCC optimize("Ofast")
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <cctype>
#include <sstream>
#include <stack>
#include <deque>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Po = pair<double, double>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=ll(a);i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define PB push_back
#define MP make_pair
#define SZ(x) ll(x.size())
#define ALL(x) x.begin(),x.end()
#define NIL -1
#define INF pow(2,31)-1
#define MOD 1000000007
#define PI 3.14159265358979323846
#define endl "\n"
#define EPS 1e-9
template <class T, class U>
bool chmin(T& t, const U& u) {
if (t > u) {
t = u;
return true;
}
else return false;
}
template <class T, class U>
bool chmax(T& t, const U& u) {
if (t < u) {
t = u;
return true;
}
else return false;
}
ll powmod(ll x, ll n, ll mod) {
ll s = 1;
REP(i, n) {
s = s * x % mod;
}
if (s < 0)s += mod;
return s;
}
signed main() {
ll n, m;
cin >> n >> m;
n++;
ll c = 0;
V<ll> w, h;
REP(i, m) {
ll a;
cin >> a;
w.push_back(a);
}
sort(ALL(w));
REP(i, m) {
if (w[i] - c >= 2) {
h.push_back(w[i] - c-1);
}
c = w[i];
}
if (n - c >= 2)h.push_back(n - c-1);
sort(ALL(h));
if (SZ(h) == 0) {
cout << 0 << endl;
return 0;
}
ll x = 1;
FOR(i, 1, SZ(h) - 1) {
if (h[i] % h[0] == 0)x += h[i] / h[0];
else x += h[i] / h[0] + 1;
}
cout << x << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define vt vector
#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fi first
#define se second
using ll = long long;
using pii = pair<int, int>;
void solve() {
int a, b;
cin >> a >> b;
cout << (a + b) / 2 << ' ' << (a - b) / 2;
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int tcs = 1;
for (int tc = 1; tc <= tcs; tc++) {
// cout << "Case " << tc << ": ";
solve();
}
}
|
#include<bits/stdc++.h>
using namespace std;
#define GODSPEED ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(15);
#define f first
#define s second
#define newl cout<<"\n";
#define pb push_back
#define mset(a,x) memset(a,x,sizeof(a))
#define debv(a) for(auto it: a)cout<<it<<" ";newl;
#define deb1(a) cout<<a<<"\n";
#define deb2(a,b) cout<<a<<" "<<b<<"\n";
#define deb3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n";
#define deb4(a,b,c,d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n";
#define uniq(a) a.resize(unique(a.begin(), a.end()) - a.begin());
#define all(a) a.begin(),a.end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
const ll N = 2e3+5;
const ll mod = 998244353;
const ll INF = 0x7f7f7f7f7f7f7f7f;
const int INFi = 0x7f7f7f7f;
const ll LEVEL = log2(N)+1;
ll n, m, t, a[N], b[N], dp[N][N];
ll mem(int i, int j){
if(i == n + 1) return m - j + 1;
if(j == m + 1) return n - i + 1;
if(dp[i][j] != -1) return dp[i][j];
dp[i][j] = INFi;
if(a[i] != b[j])
dp[i][j] = min(dp[i][j], mem(i + 1, j + 1) + 1);
else
dp[i][j] = min(dp[i][j], mem(i + 1, j + 1));
dp[i][j] = min(dp[i][j], mem(i, j + 1) + 1);
dp[i][j] = min(dp[i][j], mem(i + 1, j) + 1);
return dp[i][j];
}
void solve(){
mset(dp, -1);
cin >> n >> m;
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = 1; i <= m; i++) cin >> b[i];
deb1(mem(1, 1))
}
int main(){
GODSPEED;
int test = 1;
//cin >> test;
for(int i = 1; i <= test; i++){
solve();
}
#ifndef ONLINE_JUDGE
cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
#endif
} | #include<bits/stdc++.h>
#include<algorithm>
#define int long long
using namespace std;
int n,m;
int dp[2000][2000];
int a[2000],b[2000];
signed main(){
memset(dp,10,sizeof(dp));
cin>>n>>m;
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<=m;i++)cin>>b[i];
dp[0][0]=0;
for(int i=1;i<=n;i++)dp[i][0]=i;
for(int i=1;i<=m;i++)dp[0][i]=i;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
int x=1;
if(a[i]==b[j]){
x=0;
}
dp[i][j]=min(dp[i-1][j]+1,min(dp[i][j-1]+1,dp[i-1][j-1]+x));
}
}
cout<<dp[n][m]<<endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)
#define repr(i,n) for (int i = (n)-1; i >= 0; --i)
#define rep1r(i,n) for (int i = (n); i > 0; --i)
#define bit(n,k) ((n>>k)&1) //nのk bit目
#define vec(T) vector<T>
#define vvec(T) vector<vector<T>>
using ll = long long;
using P = pair<int,int>;
using Pll = pair<ll,ll>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll llINF = 1LL << 60;
const int iINF = 1e9;
//------------------------------------------------
struct Solver{
ll mindiff(vec(ll) a, vec(ll) b){
ll res = llINF;
ll idx=0;
for(ll ai:a){
while(idx<b.size()){
ll bi = b[idx];
chmin(res, abs(ai-bi));
if(ai<=bi) break;
idx++;
}
}
return res;
}
void solve(){
ll N;
cin >> N;
vec(ll) R,G,B;
rep(i,2*N){
ll ai;
char ci;
cin >>ai >> ci;
if(ci=='R') R.push_back(ai);
if(ci=='G') G.push_back(ai);
if(ci=='B') B.push_back(ai);
}
if(R.size()%2==0 && G.size()%2==0 && B.size()%2==0){
cout << 0 << endl;
return;
}
sort(R.begin(),R.end());
sort(G.begin(),G.end());
sort(B.begin(),B.end());
ll ans = llINF;
if(R.size()%2==0){
ans = mindiff(R,G)+mindiff(R,B);
chmin(ans, mindiff(G,B));
}else if(G.size()%2==0){
ans = mindiff(R,G)+mindiff(G,B);
chmin(ans, mindiff(R,B));
}else{
ans = mindiff(R,B)+mindiff(G,B);
chmin(ans, mindiff(G,R));
}
cout << ans << endl;
}
};
int main(){
int testcasenum=1;
//cin >> testcasenum;
rep1(ti,testcasenum){
Solver solver;
solver.solve();
}
return 0;
}
| #include<bits/stdc++.h>
#define FORz(i,t,n) for(int i=t;i<=n;i++)
#define FORf(i,n,t) for(int i=n;i>=t;i--)
#define SCC(x) scanf("%d",&x)
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef long long ll;
using namespace std;
const int N=2e5+5;
const ll MOD=1e9+7;
// inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}return x*f;}
//ll pow1(ll a,ll b){ll r=1;while(b){if(b&1)r=r*a;a=a*a;b>>=1;}return r;}
ll pow2(ll a,ll b,ll mod){ll r=1;while(b){if(b&1)r=r*a%mod;a=a*a%mod;b>>=1;}return r%mod;}
//ll gcd(ll a,ll b){ll m=a%b;while(m){a=b;b=m;m=a%b;}return b;}
void exgcd(ll a, ll b, ll &d, ll &x, ll &y){if(!b) { d = a; x = 1; y = 0;}else { exgcd(b, a % b, d, y, x); y -= x * (a / b); }}
ll inv(ll a){ll d, x, y;exgcd(a, MOD, d, x, y);return d == 1 ? (x + MOD) % MOD : -1;}struct node{ll mat[105][105];};node mul(node x,node y,int n,ll mod){node tmp;for(int i=0;i<n;i++)for(int j=0;j<n;j++){tmp.mat[i][j]=0;for(int k=0;k<n;k++)tmp.mat[i][j]+=(x.mat[i][k]*y.mat[k][j])%mod;tmp.mat[i][j]%=mod;}return tmp;}
// node matpow(node x,node y,ll num,int n,ll mod){while(num){if(num&1){y=mul(x,y,n,mod);}x=mul(x,x,n,mod);num=num>>1;}return y;}
//for(ll i=2;i<N-1;i++){if(!a[i]) b[++cnt]=i;for(ll j=1;j<=cnt&&i*b[j]<N;j++){a[i*b[j]]=1;if(i%b[j]==0) break;}}
//int find(int x){return a[x]==x?x:a[x]=find(a[x]);}
//void merge(int x,int y){a[find(y)]=a[find(x)];}
int n;
struct ty{
ll a;
char c;
bool operator <(ty kk){
return a<kk.a;
}
}x[N];
char a[3];
int sum[500];
int w[500];
map<int,ll>mp;
int main()
{
cin>>n;
FORz(i,1,n<<1) cin>>x[i].a>>x[i].c,sum[x[i].c]++;
int p=-1;
if(sum['R']&1) a[++p]='R';else a[2]='R';
if(sum['G']&1) a[++p]='G';else a[2]='G';
if(sum['B']&1) a[++p]='B';else a[2]='B';
if(!a[0]){
cout<<0;
return 0;
}
sort(x+1,x+(n<<1)+1);
mp['R'+'B']=1e16,mp['R'+'G']=1e16,mp['B'+'G']=1e16;
FORz(i,1,n<<1){
w[x[i].c]=i;
if(w['R']) mp['R'+x[i].c]=min(x[i].a-x[w['R']].a,mp['R'+x[i].c]);
if(w['G']) mp['G'+x[i].c]=min(x[i].a-x[w['G']].a,mp['G'+x[i].c]);
if(w['B']) mp['B'+x[i].c]=min(x[i].a-x[w['B']].a,mp['B'+x[i].c]);
}
cout<<min(mp[a[0]+a[1]],mp[a[0]+a[2]]+mp[a[1]+a[2]]);
}
|
#include <iostream>
#include <vector>
#include <map>
using namespace std;
map<int,vector<int>> mp;
bool dp[400010];
int main(){
int i,n,m; cin >> n >> m;
for(i=0;i<m;i++){
int x,y; cin >> x >> y;
mp[x].push_back(y);
}
for(i=0;i<=2*m;i++) dp[i] = false;
dp[m] = true;
map<int,bool> mp1;
for(auto x:mp){
vector<int> v = x.second;
for(int y:v){
if(y<n - m || y>n + m) continue;
y -= n - m;
//cout << x.first << " " << y << endl;
if(y - 1>=0 && dp[y - 1]) mp1[y] = true;
else if(y + 1<=2*m && dp[y + 1]) mp1[y] = true;
else mp1[y] = false;
}
for(int y:v){
if(y<n - m || y>n + m) continue;
y -= n - m;
//cout << x.first << " " << y << " " << mp1[y] << endl;
if(mp1[y]) dp[y] = true;
else dp[y] = false;
}
/*for(i=0;i<=2*m;i++) cout << dp[i];
cout << endl;*/
}
int cnt = 0;
/*for(i=0;i<=2*m;i++){
cout << dp[i] << " ";
}
cout << endl;*/
for(i=0;i<=2*m;i++) cnt += dp[i];
cout << cnt << endl;
} | #include<bits/stdc++.h>
using namespace std;
#define int ll
#define ALL(x) begin(x),end(x)
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define mod 1000000007
using ll=long long;
const int INF=1000000000;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}
struct IOSetup{
IOSetup(){
cin.tie(0);
ios::sync_with_stdio(0);
cout<<fixed<<setprecision(12);
}
} iosetup;
template<typename T>
ostream &operator<<(ostream &os,const vector<T>&v){
for(int i=0;i<(int)v.size();i++) os<<v[i]<<(i+1==(int)v.size()?"":" ");
return os;
}
template<typename T>
istream &operator>>(istream &is,vector<T>&v){
for(T &x:v)is>>x;
return is;
}
signed main(){
int N,M;cin>>N>>M;
map<int,vector<int>> v;
rep(i,M){
int h,w;cin>>h>>w;
v[h].push_back(w);
}
set<int> st;
st.insert(N);
for(auto &p:v){
vector<int> nxt,ers;
for(auto &j:p.second){
if(st.count(j)){
if(!st.count(j-1) and !st.count(j+1)) ers.push_back(j);
}else{
if(st.count(j-1) or st.count(j+1)) nxt.push_back(j);
}
}
for(auto &j:ers) st.erase(j);
for(auto &j:nxt) st.insert(j);
}
cout<<st.size()<<endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(v) v.begin(), v.end()
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))
#define FOR(i,x,n) for(int i=x;i<(n);i++)
using ll = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vc = vector<char>;
using vvc = vector<vc>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vll = vector<ll>;
using vvll = vector<vll>;
using Graph = vector<vector<int>>;
ll MOD = 998244353;
int main()
{
ll N,sum=0;
ll ans = 0;
cin>>N;
vll A(N);
rep(i,N)
{
cin >> A[i];
A[i] %= MOD;
}
sort(all(A));
if(N==1)
{
ans = A[0] * A[0];
ans %= MOD;
cout << ans << endl;
return 0;
}
if(N==2)
{
ans += A[0] * A[1];
ans %= MOD;
ans += A[0] * A[0];
ans %=MOD;
ans += A[1] * A[1];
ans %= MOD;
cout << ans << endl;
return 0;
}
else
{
ll temp = 2;
FOR(i, 2, N)
{
sum += temp * A[i];
sum %= MOD;
temp *= 2;
temp %= MOD;
}
ll kasanari = 0;
rep(i,N-1)
{
kasanari += A[i] * A[i];
kasanari %= MOD;
kasanari += A[i] * A[i + 1];
kasanari %= MOD;
}
kasanari += A[N - 1] * A[N - 1];
kasanari %= MOD;
rep(i,N-2)
{
ans += A[i] * sum;
ans %= MOD;
if (sum %2)
{
sum += MOD;
}
sum /= 2;
if (sum < A[i + 2])
sum += MOD;
sum -= A[i + 2];
sum %= MOD;
}
ans += kasanari;
ans %= MOD;
}
cout << ans << endl;
}
| #include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> //Policy Based Data Structure
// using namespace __gnu_pbds; //Policy Based Data Structure
using namespace std;
// typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> pbds; //Policy Based Data Structure
// #define gc getchar_unlocked
// #define pqb priority_queue<int>
// #define pqs priority_queue<int, vi, greater<int> >
// #define mk(arr,n,type) type *arr = new type[n]
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define int long long
#define endl '\n'
#define w(t) int t; cin>>t; while(t--)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x,y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it,a) for(auto it = a.begin(); it != a.end(); it++)
#define ps(x,y) fixed<<setprecision(y)<<x
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define PI 3.1415926535897932384626
#define inf 1e18
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //Random Shuffler
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef map<int, int> mii;
int mpow(int base, int exp);
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
// const int N = 3e5, M = N;
// vi g[N];
//=======================
//and==1 OR==2
void sol()
{
int i, n;
cin >> n;
int a[n];
fo(i, n)
{
string s;
cin >> s;
if (s == "AND")
a[i] = 1;
else
a[i] = 2;
}
int tr = 0, fl = 0;
if (a[0] == 1)
{
tr = 1;
fl = 3;
}
else
{
tr = 3;
fl = 1;
}
Fo(i, 1, n) {
if (a[i] == 1) {
tr *= 1;
fl = (fl * 2 ) + tr;
}
else {
tr = (tr * 2);
tr += fl;
}
}
cout << tr;
}
int32_t main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
sol();
return 0;
}
int mpow(int base, int exp) {
base %= mod;
int result = 1;
while (exp > 0) {
if (exp & 1) result = (result * base) % mod;
base = (base * base) % mod;
exp >>= 1;
}
return result;
}
// void ipgraph(int n, int m){
// int i, u, v;
// while(m--){
// cin>>u>>v;
// g[u-1].pb(v-1);
// g[v-1].pb(u-1);
// }
// }
//
// void dfs(int u, int par){
// for(int v:g[u]){
// if (v == par) continue;
// dfs(v, u);
// }
// } |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.