code_file1
stringlengths 87
4k
| code_file2
stringlengths 85
4k
|
---|---|
#include<bits/stdc++.h>
using namespace std;
const int inf=0x3f3f3f3f;
const int maxn=1e5;
typedef long long ll;
int main(){
ll a,b,c,d;
cin>>a>>b>>c>>d;
ll x=max(a,b);
ll y=min(c,d);
ll ans=x-y;
cout<<ans<<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 < (int)(n); i++)
int main() {
int a, b, c, d;
cin >> a >> b >> c >> d;
cout << b-c << endl;
return 0;
} |
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define double long double
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define gcd(x,y) __gcd(x,y)
#define MOD (int)(1e9 + 7)
#define INF (int)9e18
#define ps(x,y) fixed<<setprecision(y)<<x
int fastpow (int a, int b, int m = MOD) { int res = 1; a %= m;
while (b > 0) { if (b & 1) res = (res * a) % m; a = (a * a) % m; b >>= 1; } return res;}
#define inv(a) fastpow(a, MOD - 2)
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> pbds;
int32_t main()
{
fastio;
int N;
cin>>N;
vector<string>v;
for(int i=0;i<N;i++)
{
string str;
cin>>str;
v.push_back(str);
}
unordered_map<string,int>um;
for(int i=0;i<N;i++)
{
string s=v[i];
um[s]++;
}
for(int i=0;i<N;i++)
{
string s=v[i];
if(s[0]=='!')
{
string s2=s.substr(1,s.size()-1);
if(um[s2]>0)
{
cout<<s2<<"\n";
return 0;
}
}
}
cout<<"satisfiable\n";
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define FORI(i, a, b) for (int i = (int)a; i <= (int)b; i++)
#define FORD(i, a, b) for (int i = (int)a; i >= (int)b; i--)
#define PB push_back
#define ALL(v) v.begin(),v.end()
#define OJ \
freopen("input.txt", "r", stdin); \
freopen("output.txt", "w", stdout);
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<pii> vpii;
int main() {
int n; cin >> n;
set<string> st;
bool has = false;
string ans = "";
FORI(i, 0, n - 1) {
string str; cin >> str;
if (str[0] == '!') {
if (st.count(str.substr(1))) {
has = true;
ans = str.substr(1);
break;
}
} else {
if (st.count("!" + str)) {
has = true;
ans = str;
break;
}
}
st.insert(str);
}
if (has) cout << ans << endl;
else cout << "satisfiable" << endl;
return 0;
} |
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){
int N,M,i,j,n=0;
cin >> N >> M;
int hurui[1001];
hurui[0]=0;
for(i=1;i<=1000;i++){
hurui[i]=0;
}
int A[N],B[M];
for(i=0;i<N;i++){
cin >> A[i];
hurui[A[i]]++;
}
for(i=0;i<M;i++){
cin >> B[i];
hurui[B[i]]++;
}
for(i=1;i<=1000;i++){
if(hurui[i]==1){
cout << i << " ";
}
}
} | #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
int N,M;
cin >> N >> M;
vector<int> A(N),B(M);
for(int n=0;n<N;n++) cin >> A[n];
for(int m=0;m<M;m++) cin >> B[m];
vector<int> ans(0);
int cnt = 0;
for(int n=0;n<N;n++){
bool found1 = false;
for(int m=0;m<M&!found1;m++){
if(A[n]==B[m]){
found1=true;
}
}
if(!found1){
ans.push_back(A[n]);
cnt++;
}
}
for(int m=0;m<M;m++){
bool found2 = false;
for(int n=0;n<N&!found2;n++){
if(A[n]==B[m]){
found2=true;
}
}
if(!found2){
ans.push_back(B[m]);
cnt++;
}
}
sort(ans.begin(),ans.end());
for(int n=0;n<cnt;n++) cout << ans[n] << " ";
cout << endl;
return 0;
} |
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define x first
#define y second
using namespace std;
typedef long long ll;
int mas[200005];
int main()
{
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
ios_base::sync_with_stdio(0); cin.tie(0);
int n;
cin >> n;
for (int i = 1; i <= n; i++) cin >> mas[i];
int mx = 0;
ll pref = 0, ans = 0;
for (int i = 1; i <= n; i++)
{
pref += (ll) mas[i];
ans += pref;
mx = max(mx, mas[i]);
cout << ans + (ll) i * (ll) mx << '\n';
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(lint i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
///#pragma GCC optimize ("-O3")
ll input(){
ll n;
cin >> n;
return n;
}///input関数
ll combination(ll n,ll r){
if (r == 0 || r == n)
return (1);
else if (r == 1)
return (n);
return (combination(n-1,r-1) + combination(n-1,r));
}///nCr
ll facctorialMethod(ll k){
ll sum = 1;
for (ll i = 1; i <= k; ++i)
{
sum *= i;
}
return sum;
}///階乗
int main(){
ll n = input();
vector<ll>a;
ll a_max = 0;
ll ans = 0;
ll total = 0;
ll pir = 0;
rep(i,0,n){
a.push_back(input());
pir += total;
total += a.at(i);
a_max = max(a_max,a.at(i));
ans = pir + total + a_max*(i+1);
cout << ans << endl;
}
} |
/*
Author : $%U%$
Time : $%h%$:$%m%$:$%s%$, $%D%$/$%M%$/$%Y%$
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = long double; // or double, if TL is tight
using str = string; // yay python!
using pi = pair<int,int>;
using pl = pair<ll,ll>;
using pd = pair<db,db>;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<ll>;
using vd = vector<db>;
using vs = vector<str>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vpd = vector<pd>;
#define tcT template<class T
#define tcTU tcT, class U
// ^ lol this makes everything look weird but I'll try it
tcT> using V = vector<T>;
tcT, size_t SZ> using AR = array<T,SZ>;
tcT> using PR = pair<T,T>;
// pairs
#define mp make_pair
#define f first
#define s second
// vectors
// oops size(x), rbegin(x), rend(x) need C++17
#define sz(x) int((x).size())
#define bg(x) begin(x)
#define all(x) bg(x), end(x)
#define rall(x) x.rbegin(), x.rend()
#define sor(x) sort(all(x))
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define pb push_back
#define eb emplace_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
tcT> int lwb(V<T>& a, const T& b) { return int(lb(all(a),b)-bg(a)); }
// loops
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)
const int MOD = 1e9+7; // 998244353;
const int MX = 2e5+5;
const ll INF = 1e18; // not too close to LLONG_MAX
const db PI = acos((db)-1);
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1}; // for every grid problem!!
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
template<class T> using pqg = priority_queue<T,vector<T>,greater<T>>;
// bitwise ops
// also see https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html
constexpr int pct(int x) { return __builtin_popcount(x); } // # of bits set
constexpr int bits(int x) { // assert(x >= 0); // make C++11 compatible until USACO updates ...
return x == 0 ? 0 : 31-__builtin_clz(x); } // floor(log2(x))
constexpr int p2(int x) { return 1<<x; }
constexpr int msk2(int x) { return p2(x)-1; }
ll cdiv(ll a, ll b) { return a/b+((a^b)>0&&a%b); } // divide a by b rounded up
ll fdiv(ll a, ll b) { return a/b-((a^b)<0&&a%b); } // divide a by b rounded down
tcT> bool ckmin(T& a, const T& b) {
return b < a ? a = b, 1 : 0; } // set a = min(a,b)
tcT> bool ckmax(T& a, const T& b) {
return a < b ? a = b, 1 : 0; }
tcTU> T fstTrue(T lo, T hi, U f) {
hi ++; assert(lo <= hi); // assuming f is increasing
while (lo < hi) { // find first index such that f is true
T mid = lo+(hi-lo)/2;
f(mid) ? hi = mid : lo = mid+1;
}
return lo;
}
tcTU> T lstTrue(T lo, T hi, U f) {
lo --; assert(lo <= hi); // assuming f is decreasing
while (lo < hi) { // find first index such that f is true
T mid = lo+(hi-lo+1)/2;
f(mid) ? lo = mid : hi = mid-1;
}
return lo;
}
tcT> void remDup(vector<T>& v) { // sort and remove duplicates
sort(all(v)); v.erase(unique(all(v)),end(v)); }
tcTU> void erase(T& t, const U& u) { // don't erase
auto it = t.find(u); assert(it != end(t));
t.erase(it); } // element that doesn't exist from (multi)set
#define el '\n'
void solve()
{
ll n,S,D; cin>>n>>S>>D;
bool flag=false;
for(int i=0;i<n;i++)
{
ll x,y;
cin>>x>>y;
if(x<S and y>D)
{
flag=true;
}
}
if(flag) cout<<"Yes"<<el;
else cout<<"No"<<el;
}
int main()
{
cin.tie(0)->sync_with_stdio(0);
int ct=1;
// cin>>ct;
while(ct--)
{
solve();
}
} | #include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 200005;
int seg[4*N],h;
void update(int idx,int p=1,int s=0,int e=h)
{
if(s==e)
{
seg[p] = 1;
return;
}
int mid = (s+e)>>1;
if(idx<=mid)
update(idx,2*p,s,mid);
else
update(idx,2*p+1,mid+1,e);
seg[p] = seg[2*p] + seg[2*p+1];
}
int get(int l,int r,int p=1,int s=0,int e=h)
{
if(r<s||l>e)
return 0;
if(l<=s&&e<=r)
return seg[p];
int mid = (s+e)>>1;
return get(l,r,p<<1,s,mid)+get(l,r,p<<1|1,mid+1,e);
}
void solve()
{
int w, m;
cin>>h>>w>>m;
vector<pair<int,int>> v(m);
for(int i=0;i<m;i++)
{
cin>>v[i].first>>v[i].second;
v[i].first--;
v[i].second--;
}
sort(v.begin(),v.end());
vector<vector<int>> by_row(h), by_col(w);
for (auto &it : v)
{
by_row[it.first].push_back(it.second);
by_col[it.second].push_back(it.first);
}
for (int x = 0; x < h; x++)
by_row[x].push_back(w);
for (int y = 0; y < w; y++)
by_col[y].push_back(h);
int reachable_rows = by_col[0].front();
int reachable_cols = by_row[0].front();
ll ans = 0;
for (int x = 0; x < reachable_rows; x++)
ans += by_row[x].front();
for (int y = 1; y < reachable_cols; y++)
{
int height = by_col[y].front();
ans += max(0, height - reachable_rows);
int x = min(reachable_rows, height);
ans += get(0,x-1);
for (int it : by_col[y])
update(it);
}
cout<<ans<<'\n';
}
int main()
{
ios_base::sync_with_stdio(false),cin.tie(0);
solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
signed main() {
int a,b;
cin >> a >> b;
b = a-b;
double tmp = 1.0*b/a;
printf("%f",tmp*100);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
//UnionFindテンプレ
class UnionFind {
// まとめる 判定 サイズを知る
public:
// Aから見た親の番号を格納する。rootだったら-1*その集合のサイズ。
vector<int> Parent;
// 初期化
UnionFind(int N) {
Parent = vector<int>(N, -1);
}
// Aのrootを調べる
int root(int A) {
if (Parent[A] < 0) return A; // マイナスならそれはroot
return Parent[A] = root(Parent[A]);
}
// rootの値をプラスに戻して返す(サイズ)
int size(int A) {
return -Parent[root(A)];
}
// くっつける関数
bool connect(int A, int B) {
// AとBのroot同士をくっつける
A = root(A); // ここのAは、"rootの場所"の意味
B = root(B);
if (A == B) return false; // 既にくっついている
if (size(A) < size(B))
swap(A, B); // 大きい方にくっつけるために中身交換
Parent[A] += Parent[B]; // 中身更新
Parent[B] = A;
return true;
}
//連結か調べる関数
bool issame(int A, int B) {
return root(A) == root(B);
}
};
//chmin,chmax関数(DP用)
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
//aのZ/mZでの逆元
int64_t modinv(int64_t a, int64_t m) {
int64_t b = m, u = 1, v = 0;
while (b) {
int64_t t = a / b;
a -= t * b; swap(a, b);
u -= t * v; swap(u, v);
}
u %= m;
if (u < 0) u += m;
return u;
}
//ここから
int main() {
int64_t S,P;
cin >> S >> P;
for (int64_t i = 1; i*i <= P; i++) {
if (i*(S-i) == P) {
cout << "Yes" << endl;
return 0;
}
}
cout << "No" << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,srt,end) for(ll i = (srt); i < (ll)(end); i++)
//ll MOD=1000000007;
//ll mod=998244353;
//int inf=1000001000;
//ll INF=1e18+5;
//cout << std::fixed << std::setprecision(15) << y << endl;
// For debug
// Ref: https://qiita.com/ysuzuki19/items/d89057d65284ba1a16ac
#define dump(var) do{std::cerr << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cerr << e << "\n";}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cerr << e << " "; } std::cerr << "\n";}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ std::cerr << "\n"; for(const auto& v : vv){ view(v); } }
template<typename T> void dump_cout(const T& v) { for(long long i = 0; i < v.size(); i++) std::cout << v[i] << (i == v.size()-1 ? "\n" : " "); }
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
string s;
cin >> s;
ll cnt = 0;
deque<char> q;
rep(i,0,s.size()){
if(s[i] == 'R') cnt ^= 1;
else if(cnt) q.push_back(s[i]);
else q.push_front(s[i]);
}
if(!cnt) reverse(q.begin(),q.end());
string ans;
for(auto c : q){
if(ans.size() && ans.back() == c) ans.pop_back();
else ans.push_back(c);
}
cout << ans << endl;
return 0;
} | #include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cmath>
#include <limits>
#include <stdio.h>
#include <string.h>
#include <numeric>
#define P pair<int, int>
#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))
#define rep(i, a, b) for (int i = a; i < b; i++)
const long long INF = 1LL << 60;
typedef long long ll;
template <class T>
inline bool chmin(T &a, T b)
{
if (a > b)
{
a = b;
return true;
}
return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
if (a < b)
{
a = b;
return true;
}
return false;
}
#define all(x) (x).begin(), (x).end()
using namespace std;
// 上下左右の移動用配列
// セットで上、右、下、左の順番
int dx[4] = {0, 1, 0, -1};
int dy[4] = {-1, 0, 1, 0};
int main(int, char **){
ll n;
cin >> n;
set<ll> s;
for(ll a = 2; a*a <= n; a++){
ll x = a * a;
while(x <= n){
s.insert(x);
x *= a;
}
}
cout << n-s.size() << endl;
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<ll, ll>;
using tp = tuple<ll, ll, ll>;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;
#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
#define rep(i, m, n) for(ll i = (ll)(m); i < (ll)(n); ++i)
#define rep2(i, m, n) for(ll i = (ll)(n)-1; i >= (ll)(m); --i)
#define REP(i, n) rep(i, 0, n)
#define REP2(i, n) rep2(i, 0, n)
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll)1e9 + 7;
//constexpr long long MOD = 998244353LL;
static const ld pi = 3.141592653589793L;
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
template <class T>
inline bool chmin(T &a, T b) {
if(a > b) {
a = b;
return true;
}
return false;
}
template <class T>
inline bool chmax(T &a, T b) {
if(a < b) {
a = b;
return true;
}
return false;
}
//グラフ関連
struct Edge {
int to, rev;
ll cap;
Edge(int _to, int _rev, ll _cap) : to(_to), rev(_rev), cap(_cap) {}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
void add_edge(Graph &G, int from, int to, ll cap, bool revFlag, ll revCap) {
G[from].push_back(Edge(to, (int)G[to].size(), cap));
if(revFlag)
G[to].push_back(Edge(from, (int)G[from].size() - 1, revCap));
}
void solve() {
ll a, b, c, d;
cin >> a >> b >> c >> d;
if(b >= c * d) {
cout << -1 << en;
return;
}
ll ans = (a + (c * d - b - 1)) / (c * d - b);
cout << ans << en;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
//cout << fixed << setprecision(10);
// ll t;
// cin >> t;
// REP(i, t - 1) {
// solve();
// }
solve();
return 0;
}
| /* >>>>>Shwetal<<<<< */
#include <bits/stdc++.h>
#define int long long
#define f(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define inputArray(arr) f(i, 0, arr.size()) cin >> arr[i]
#define printArray(arr) f(i, 0, arr.size()) cout << arr[i] << ' '; cout << endl
#define endl '\n'
typedef long long ll;
const int mod = 1e9+7;
using namespace std;
void solve() {
int x;
cin >> x;
int n = x;
int a = 100;
int rem = x % a;
int div = x/a;
if(rem == 0){
cout << 100 << endl;
return;
}else{
while(x % a != 0){
div++;
x = div * a;
if(x % a == 0){
cout << x - n << endl;
return;
}
}
}
}
int32_t main(){
// freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
ios::sync_with_stdio(0);
cin.tie(0);
int T = 1;
// cin >> T;
while(T--){
solve();
// if(solve())
// cout << "YES" << endl;
// else
// cout << "NO" << endl;
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, c) for (int i = 0; i < (int)c; i++)
using ll = long long;
// 入力のときに10000倍して四捨五入する関数
int in() {
double x;
cin >> x;
x *= 10000;
return round(x);
}
// x^2 * y^2 = r^2
bool ok(ll dx, ll dy, ll z) { return dx * dx + dy * dy <= z * z; }
// 円の上半分を探索
ll f(ll x, ll y, ll z, ll lim) { //lim上限
int l = 0, r = 1;
ll res = 0;
for (int i = int(1e9) + 50000; i >= lim; i -= 10000) {
while (ok(x - l * 10000, i - y, z)) --l;
while (ok(r * 10000 - x, i - y, z)) ++r;
res += r - l - 1;
}
return res;
}
int main() {
ll x = in();
ll y = in();
ll z = in();
x %= 10000;
y %= 10000;
ll ans = f(x, y, z, 10000); //上半分
ans += f(x, -y, z, 0); //下半分
cout << ans << endl;
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)/(dbl)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;
}
|
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <limits.h>
using namespace std;
typedef long long ll;
template<class T>
inline bool chmax(T &a, T b) {
if(a < b) {
a = b;
return true;
}
return false;
}
template<class T>
inline bool chmin(T &a, T b) {
if(a > b) {
a = b;
return true;
}
return false;
}
const int INF = INT_MAX / 2;
ll gcd(const ll sx, const ll sy) {
ll x = min(sx, sy);
ll y = max(sx, sy);
ll tmp;
while (x > 0) {
tmp = y;
y = x;
x = tmp % x;
}
return y;
}
vector<int> as;
vector<int> calc_divisors(const int a) {
vector<int> ans;
for (int i = 1; i * i <= a; i++) {
if (a % i == 0) {
if (i * i == a) {
ans.push_back(i);
} else {
ans.push_back(i);
ans.push_back(a / i);
}
}
}
sort(ans.begin(), ans.end());
return ans;
}
int main(void) {
int N;
cin >> N;
int min_a = INF;
as.resize(N);
for (int i = 0; i < N; i++) {
cin >> as[i];
chmin(min_a, as[i]);
}
map<int, int> memo;
for (int i = 0; i < N; i++) {
vector<int> divisors = calc_divisors(as[i]);
for (auto d : divisors) {
if (memo.find(d) == memo.end()) {
memo[d] = as[i];
} else {
memo[d] = gcd(memo[d], as[i]);
}
}
}
int ans = 0;
for (auto kv : memo) {
const int key = kv.first;
const int val = kv.second;
if (key <= min_a && key == val) {
ans++;
}
}
cout << ans << endl;
return 0;
}
| #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 unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
const ll N = 1e6+5;
const ll mod = 998244353 ;
const ll INF = 0x7f7f7f7f;
const int INFi = 0x7f7f7f7f;
ll n, m, a[2002];
map <ll, ll> g;
void solve(){
cin >> n;
for(int i = 1; i <= n; i++){
cin >> a[i];
for(int j = 1; j * j <= a[i]; j++){
if(a[i] % j == 0){
g[j] = __gcd(g[j], a[i]);
g[a[i] / j] = __gcd(g[a[i] / j], a[i]);
}
}
}
int mn = *min_element(a + 1, a + n + 1);
ll ans = 1;
for(auto it : g){
if(it.f < mn && it.s == it.f) ans++;
}
deb1(ans)
}
int main(){
GODSPEED;
int test = 1;
//cin >> test;
for(int i = 1; i <= test; i++){
solve();
}
} |
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
#define eps 1e-8
//#define eq(x,y) (fabs((x)-(y)) < eps)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int>pii;
const int mod= 1e9+7;
long double pi = acosl(-1);
//const ll infl = LLONG_MAX;
const int inf = 1e9+2;
const int nmax = 2e5+5;
//const int MAXLG = log2(nmax)+1;
//mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
//typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ost;
void NA(){
cout<<"-1", exit(0);
}
int a[nmax], b[nmax], p[nmax];
pii a2[nmax];
int koi[nmax];
int main(){
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int n;
cin>>n;
for(int i=1; i<=n; i++) cin>>a[i];
for(int i=1; i<=n; i++) cin>>b[i];
for(int i=1; i<=n; i++) cin>>p[i];
for(int i=1; i<=n; i++) a2[i] = {a[i], i};
sort(a2+1, a2+1+n);
for(int i=1; i<=n; i++){
koi[ a2[i].second ] = i;
}
for(int i=1; i<=n; i++){
if(p[i]!=i and b[ p[i] ] >= a[i]) NA();
}
vector<pii>ans;
for(int i=1; i<=n; i++){
int manid = a2[i].second;
int bagid = p[ manid ];
while( koi[ bagid ] < i){
ans.push_back( {manid, bagid} );
bagid = p[ bagid ];
p[ manid ] = bagid;
}
}
cout<<ans.size()<<"\n";
for(pii z : ans) cout<<z.first<<" "<<z.second<<"\n";
}
/*
*/
| #include "bits/stdc++.h"
using namespace std;
// 定義
typedef long long ll;
typedef pair<ll, ll> P;
#define ALL(x) (x).begin(),(x).end()
#define REP(i, n) for(ll i = 0 ; i < (ll)n ; ++i)
#define REPN(i, m, n) for(ll i = m ; i < (ll)n ; ++i)
#define VL vector<ll>
#define VVL vector<vector<ll>>
#define VVVL vector<vector<vector<ll>>>
#define INF (ll)2e9
#define INF_LL 1LL<<60
//#define MOD 998244353
#define MOD 1000000007
ll Ceil(ll val, ll div) { return (val + div - 1) / div; }
ll CeilN(ll val, ll div) { return Ceil(val, div) * div; }
ll FloorN(ll x, ll n) { return (x - x % n); }
bool IsOdd(ll x) { return ((x & 1) == 1); }
bool IsEven(ll x) { return ((x & 1) == 0); }
class BinaryIndexedTree {
private:
int n;
vector<ll> bit;
public:
BinaryIndexedTree(int num)
{
// 0は番兵
n = num + 1;
bit.assign(n + 1, 0);
}
// idx is 1-indexed
void add(int idx, ll val)
{
while (idx <= n) {
bit[idx] += val;
idx += idx & -idx;
}
}
// [1, idx) idx is 1-indexed
ll sum(int idx)
{
ll sum = 0;
while (0 < idx) {
sum += bit[idx];
idx -= idx & (-idx);
}
return sum;
}
// [a, b) idx is 1-indexed
ll range(int a, int b)
{
return (sum(b) - sum(a));
}
// val-th number (val is 0-indexed)
int lower_bound(ll val)
{
int idx = 0;
int k = 1;
while (2 * k <= n) {
k <<= 1;
}
for (; 0 < k; k >>= 1) {
if (idx + k < n && bit[idx + k] < val) {
val -= bit[idx + k];
idx += k;
}
}
return idx + 1;
}
};
struct PINFO {
ll pIdx;
ll pWeight;
ll bIdx;
ll bWeight;
};
// 処理
void Solve()
{
ll K;
cin >> K;
vector<PINFO> hito(K);
VL b2w(K);
REP(i, K) {
ll a;
cin >> a;
hito[i].pIdx = i;
hito[i].pWeight = a;
}
REP(i, K) {
ll b;
cin >> b;
b2w[i] = b;
}
REP(i, K) {
ll p;
cin >> p;
p--;
hito[i].bIdx = p;
hito[i].bWeight = b2w[p];
}
for (auto one : hito) {
if (one.pIdx != one.bIdx) {
if (one.pWeight <= one.bWeight) {
cout << -1 << endl;
return;
}
}
}
vector<PINFO> sortedHito = hito;
auto comp = [](PINFO a, PINFO b) {
return a.pWeight < b.pWeight;
};
sort(ALL(sortedHito), comp);
VL b2Idx(K);
REP(i, K) {
auto one = hito[i];
b2Idx[one.bIdx] = i;
}
vector<P> ans;
for (PINFO s : sortedHito) {
ll srcIdx = s.pIdx;
auto &src = hito[srcIdx];
auto dstIdx = b2Idx[srcIdx];
auto &dst = hito[dstIdx];
if (dstIdx == srcIdx) continue;
ans.emplace_back(src.pIdx + 1, dst.pIdx + 1);
swap(b2Idx[src.bIdx], b2Idx[dst.bIdx]);
swap(src.bIdx, dst.bIdx);
swap(src.bWeight, dst.bWeight);
}
cout << ans.size() << endl;
for (auto a : ans) {
cout << a.first << " " << a.second << endl;
}
}
// メイン
int main()
{
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(15);
Solve();
return 0;
}
|
// Problem : A - Three Dice
// Contest : AtCoder - AISing Programming Contest 2021(AtCoder Beginner Contest 202)
// URL : https://atcoder.jp/contests/abc202/tasks/abc202_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
/* DEBUGGING */
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
/* MACROS */
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef map<int,int> mii;
typedef tuple<int,int,int> tup;
#define ff first
#define ss second
#define pb push_back
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define lb lower_bound
#define ub upper_bound
#define all(x) (x).begin(), (x).end()
#define lcm(x, y) ((x) * (y) / __gcd(x, y))
#define ps(x,y) fixed<<setprecision(y)<<x
#define setbit(x) __builtin_popcountll(x)
#define rep(i,a,b) for(int i=a ; i<b ; ++i)
#define repr(i,a,b) for(int i=a ; i>=b ; --i)
/* CONSTANTS */
#define PI 3.141592653589793
const ll MOD = 1e9 + 7;
const ll INF = 1000000000;
const ll MAX_N = 2e5 + 2;
void solve(){
vi v(3);
rep(i,0,3) cin >> v[i];
cout << 21-accumulate(all(v),0);
}
int main(){
IOS;
solve();
} | /* in the name of Anton */
/*
Compete against Yourself.
Author - Aryan Choudhary (@aryanc403)
*/
#ifdef ARYANC403
#include "/home/aryan/codes/PastCodes/template/header.h"
#else
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#pragma GCC optimize ("-ffloat-store")
#include<iostream>
#include<bits/stdc++.h>
#define dbg(args...)
#endif
using namespace std;
#define fo(i,n) for(i=0;i<(n);++i)
#define repA(i,j,n) for(i=(j);i<=(n);++i)
#define repD(i,j,n) for(i=(j);i>=(n);--i)
#define all(x) begin(x), end(x)
#define sz(x) ((lli)(x).size())
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define endl "\n"
typedef long long int lli;
typedef long double mytype;
typedef pair<lli,lli> ii;
typedef vector<ii> vii;
typedef vector<lli> vi;
const auto start_time = std::chrono::high_resolution_clock::now();
void aryanc403()
{
#ifdef ARYANC403
auto end_time = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> diff = end_time-start_time;
cerr<<"Time Taken : "<<diff.count()<<"\n";
#endif
}
const lli INF = 0xFFFFFFFFFFFFFFFL;
lli seed;
mt19937 rng(seed=chrono::steady_clock::now().time_since_epoch().count());
inline lli rnd(lli l=0,lli r=INF)
{return uniform_int_distribution<lli>(l,r)(rng);}
class CMP
{public:
bool operator()(ii a , ii b) //For min priority_queue .
{ return ! ( a.X < b.X || ( a.X==b.X && a.Y <= b.Y )); }};
void add( map<lli,lli> &m, lli x,lli cnt=1)
{
auto jt=m.find(x);
if(jt==m.end()) m.insert({x,cnt});
else jt->Y+=cnt;
}
void del( map<lli,lli> &m, lli x,lli cnt=1)
{
auto jt=m.find(x);
if(jt->Y<=cnt) m.erase(jt);
else jt->Y-=cnt;
}
bool cmp(const ii &a,const ii &b)
{
return a.X<b.X||(a.X==b.X&&a.Y<b.Y);
}
const lli mod = 998244353LL;
// const lli maxN = 1000000007L;
lli T,n,i,j,k,in,cnt,l,r,u,v,x,y;
lli m;
string s;
vi a;
//priority_queue < ii , vector < ii > , CMP > pq;// min priority_queue .
int main(void) {
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
// freopen("txt.in", "r", stdin);
// freopen("txt.out", "w", stdout);
// cout<<std::fixed<<std::setprecision(35);
// cin>>T;while(T--)
{
lli ans=1;
k=3;
while(k--)
{
cin>>n;
ans*=(n*(n+1)/2)%mod;
ans%=mod;
}
cout<<ans<<endl;
} aryanc403();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long s,p;
int main() {
cin>>s>>p;
for(int i=1;i<=sqrt(p);i++){
if(!(p%i)){
if(i+p/i==s){
cout<<"Yes";
return 0;
}
}
}
cout<<"No";
return 0;
} | #include <bits/stdc++.h>
#define ll long long
//int n; cin>>n; int i,a[n]; for(i=0;i<n;i++) cin>>a[i];
using namespace std;
int main(void){
// Your code here!
int t;
t=1;
while(t--)
{
ll s,p,m,n,i;cin>>s>>p;
string ans="No";
for(i=1;i*i<=p;i++)
if(i*(s-i)==p)
ans="Yes";
cout<<ans<<endl;
}
}
|
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <math.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define ll long long
using namespace std;
unsigned int factorial(unsigned int n){
if (n==0) return 1;
else return n*factorial(n-1);
}
int binary_search(vector<int> v,int key){
int left=-1;
int right=v.size();
while(right-left>1){
int mid=left+(right-left)/2;
if (v[mid]>=key) right=mid;
else left=mid;
}
return right;
}
int main(){
int n;
string S;
int ar[4][n+1];
cin>>n>>S;
for (int i=0;i<4;i++){
for(int j=0;j<n+1;j++){
ar[i][j]=0;
}
}
for (int j=0;j<n;j++){
for (int i=0;i<4;i++){
ar[i][j+1]=ar[i][j];
}
if (S[j]=='A') ar[0][j+1]+=1;
if (S[j]=='T') ar[1][j+1]+=1;
if (S[j]=='C') ar[2][j+1]+=1;
if (S[j]=='G') ar[3][j+1]+=1;
}
ll ans=0;
for (int width=2;width<n+1;width++){
for (int j=1;j<n-width+2;j++){
int x=j+width-1;
int y=j-1;
int A_num=ar[0][x]-ar[0][y];
int T_num=ar[1][x]-ar[1][y];
int C_num=ar[2][x]-ar[2][y];
int G_num=ar[3][x]-ar[3][y];
if ((A_num==T_num)&&(C_num==G_num)) ans++;
}
}
cout<<ans<<endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main(){
int N;
long long ans = 0;
string S;
cin >> N >> S;
int A, T, C, G;
for(int i = 0; i < N; i++){
A = 0;
T = 0;
C = 0;
G = 0;
for(int j = i; j < N; j++){
if(S.at(j) == 'A') A++;
if(S.at(j) == 'T') T++;
if(S.at(j) == 'G') G++;
if(S.at(j) == 'C') C++;
if(A == T && C == G){
ans++;
}
}
}
cout << ans << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int main(){
long long N;
cin >> N;
set<long long> A,B,C;
vector<vector<long long> > BB;
vector<long long> v0;
vector<long long> Ac,Cc;
for(long long i=0; i<N; i++){
Ac.push_back(0);
BB.push_back(v0);
Cc.push_back(0);
}
long long p;
for(long long i=0; i<N; i++){
cin >> p;
Ac.at(p-1)++;
A.insert(p-1);
}
for(long long i=0; i<N; i++){
cin >> p;
BB.at(p-1).push_back(i);
B.insert(p-1);
}
for(long long i=0; i<N; i++){
cin >> p;
Cc.at(p-1)++;
C.insert(p-1);
}
set<long long> D;
set_intersection(A.begin(), A.end(),B.begin(), B.end(),inserter(D, D.end()));
long long ans = 0;
for(auto itr = D.begin(); itr != D.end(); ++itr) {
long long d = *itr;
//cout << d;
long long ccc=0;
for(long long i=0; i < BB.at(d).size(); i++){
long long bbb = BB.at(d).at(i);
//cout << Ac.at(bbb) << "*" << Cc.at(bbb) << "=" << ans << endl;
ccc += Cc.at(bbb);
}
ans += Ac.at(d) * ccc;
}
cout << ans;
} | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define lb lower_bound
#define ub upper_bound
#define fe(x) (*(x.begin()))
#define le(x) (*(x.rbegin()))
#define pb push_back
#define load(node,n) bool operator < (const node &n) const
#define fbo(x,id) (*(x.find_by_order(id)))
#define ook(y) order_of_key(y)
#define all(x) (x).begin(),(x).end()
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define sl(a) scanf("%lld",&a)
#define sll(a,b) scanf("%lld %lld",&a,&b)
#define slll(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define rep(i,a,b) for(ll i = a; i<=b; i++)
#define un(x) x.erase(unique(all(x)), x.end())
#define TT long long TC; scanf("%lld",&TC); for(ll tc = 1; tc<=TC; tc++)
#define read freopen("input.txt","r",stdin)
#define write freopen("output.txt","w",stdout)
#define set(x) tree<x,null_type,less<x>,rb_tree_tag,tree_order_statistics_node_update>
#define assign(v,n,x) v.clear(); for(int I = 0; I<n; I++) v.pb(x);
#define SZ(x) (int)x.size()
#define ff first
#define ss second
#define FF fflush(stdout);
#define ms(AR,x) memset(AR,x,sizeof AR);
#define case printf("Case %lld: ",tc);
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
#define mx 200003
ll ara[mx];
map<char,vector<ll> > ar;
main(){
//read;
int n;
si(n);
for(int i = 0; i<2*n; i++){
ll x;
sl(x);
char c;
cin>>c;
ar[c].pb(x);
}
ll ans = 0;
vector<char> v;
char d;
for(auto i:ar){
if( SZ(i.ss)%2 ) v.pb(i.ff),ans = 9e18;
else d = i.ff;
}
for(char X:{'R','G','B'})
sort(all(ar[X]));
if(SZ(v)){
for(ll i:ar[v[0]]){
int id = lb( all(ar[v[1]]),i ) - ar[v[1]].begin();
id = min( id,SZ(ar[v[1]]) - 1 );
int id2 = id - 1;
id2 = max(0,id2);
ll x = ar[v[1]][id],y = ar[v[1]][id2];
ans = min( { ans, abs(i-x) , abs(i-y) } );
}
if(SZ(ar[d])){
ll tmp[mx];
set<pll> st;
for(ll i = 0; i<SZ(ar[d]); i++){
ll x = ar[d][i];
int id = lb( all(ar[v[1]]), x ) - ar[v[1]].begin();
id = min( id,SZ(ar[v[1]]) - 1 );
int id2 = id - 1;
id2 = max(0,id2);
ll p = min( abs(x - ar[v[1]][id] ) , abs( x - ar[v[1]][id2]) );
tmp[i] = p;
st.insert(pll(p,i));
}
for(ll i = 0; i<SZ(ar[d]); i++){
pll u = pll(tmp[i],i);
st.erase(u);
ara[i] = fe(st).ff;
st.insert(u);
}
for(ll i = 0; i<SZ(ar[d]); i++){
ll x = ar[d][i],y,z;
int id = lb(all(ar[v[0]]),x) - ar[v[0]].begin();
id = min( id, SZ(ar[v[0]]) - 1);
int id2 = id - 1;
id2 = max(0,id2);
y = ar[v[0]][id];
z = ar[v[0]][id2];
ll p = min( abs(x - y), abs(x - z) );
ans = min(ans, p + ara[i]);
}
}
}
cout<<ans;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
int H,W;cin>>H>>W;
vector<vector<char>>S(H,vector<char>(W));
for(int i=0;i<H;i++){
for(int j=0;j<W;j++){
cin>>S[i][j];
}
}
vector<vector<int>>dp(H,vector<int>(W,0));
for(int i=0;i<H;i++){
for(int j=0;j<W;j++){
if(S[i][j]=='R'){
dp[i][j]++;
}
if(i!=0){
dp[i][j]+=dp[i-1][j];
}
if(j!=0){
dp[i][j]+=dp[i][j-1];
}
}
}
int ans=1;
for(int i=0;i<=H+W-2;i++){
char defo='-';
for(int j=0;j<=i;j++){
int k=i-j;
if(j>=0&&k>=0&&j<H&&k<W){
if(defo=='-'){
if(S[j][k]!='.')defo=S[j][k];
}
else if(S[j][k]!='.'&&defo!=S[j][k]){
cout<<0<<endl;
return 0;
}
}
}
if(defo=='-'){
ans*=2;
ans%=998244353;
}
}
cout<<ans<<endl;
} | #include <bits/stdc++.h>
int main() {
using std::cin;
using std::string;
using std::vector;
int h, w;
cin >> h >> w;
vector<string> s (h);
for (int i = 0; i < h; i++)
cin >> s[i];
int ans = 1;
for (int i = 0; i <= h + w - 2; i++) {
int b_ok = 1, r_ok = 1;
for (int j = std::max(0, i - w + 1); j <= std::min(h - 1, i); j++) {
if (s[j][i - j] == 'R')
b_ok = 0;
if (s[j][i - j] == 'B')
r_ok = 0;
}
ans = ans * (b_ok + r_ok) % 998244353;
}
std::cout << ans << std::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;
int main() {
int N, M; cin >> N >> M;
vector<vector<vector<int>>> G(N, vector<vector<int>>(26));
vector<vector<bool>> adj(N, vector<bool>(N, false));
REP(i, 0, M) {
int a, b; char c; cin >> a >> b >> c; a--; b--; c -= 'a';
G[a][c].push_back(b);
G[b][c].push_back(a);
adj[a][b] = adj[b][a] = true;
}
int ans = 1 << 30;
queue<pair<int, int>> Q;
Q.push({0, N - 1});
vector<vector<int>> dist(N, vector<int>(N, -1));
dist[0][N - 1] = dist[N - 1][0] = 0;
while (!Q.empty()) {
auto [u, v] = Q.front(); Q.pop();
if (ans <= dist[u][v]) break;
if (u == v) {
ans = min(ans, 2 * dist[u][v]);
continue;
}
if (adj[u][v]) {
ans = min(ans, 2 * dist[u][v] + 1);
continue;
}
REP(i, 0, 26) {
for (auto x : G[u][i]) {
for (auto y : G[v][i]) {
if (dist[x][y] != -1) continue;
dist[x][y] = dist[y][x] = dist[u][v] + 1;
Q.push({x, y});
}
}
}
}
if (ans < (1 << 30)) cout << ans << endl;
else cout << -1 << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)
void chmin(ll& a, ll b) {
if (a > b) a = b;
}
int main() {
int N, M;
cin >> N >> M;
ll H[N];
rep(i, N) {
cin >> H[i];
}
sort(H, H+N);
vector<ll> left(N/2), right(N/2);
rep(i, N/2) {
left[i] = H[2*i+1] - H[2*i];
right[i] = H[2*(i+1)] - H[2*i+1];
}
vector<ll> left_sum(N/2 + 1, 0), right_sum(N/2+1, 0);
rep(i, N/2) {
left_sum[i+1] = left_sum[i] + left[i];
right_sum[i+1] = right_sum[i] + right[i];
}
vector<ll> W(M);
rep(i, M) {
cin >> W[i];
}
ll ans = 10000000000000000;
rep(i, M) {
// 先生を初めて超えるindex
int x = lower_bound(H, H +N, W[i]) - H;
if (x % 2) {
chmin(ans, left_sum[(x-1)/2] + (W[i]-H[x-1])
+ right_sum[(N-1)/2] - right_sum[(x-1)/2]);
} else {
chmin(ans, left_sum[x/2] + (H[x]-W[i])
+ right_sum[(N-1)/2] - right_sum[x/2]);
}
}
cout << ans << endl;
} |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<array<int, 2>> a(n);
int res = INT_MAX;
for(int i = 0;i < n;i ++) {
cin >> a[i][0] >> a[i][1];
}
for(int i = 0;i < n;i ++) {
for(int j = 0;j < n;j ++) {
if(i == j) {
res = min(res, a[i][0]+a[j][1]);
} else {
res = min(res, max(a[i][0], a[j][1]));
}
}
}
cout << res << '\n';
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pint = pair<int,int>;
using p = complex<double>;
void f(vector<p>& B) {
int N = B.size();
double x = 0, y = 0;
for(auto u : B)x += u.real(), y += u.imag();
x /= N, y /= N;
for(auto&u : B) {
u = {u.real() - x, u.imag() - y};
}
sort(B.begin(), B.end(), [&](p a, p b){return (a.real() == b.real() ? a.imag() < b.imag() : a.real() < b.real()) ;});
}
void g(vector<p>& B, double b) {
for(auto &i : B) {
i *= p{cos(b), sin(b)};
}
sort(B.begin(), B.end(), [&](p a, p b){return (a.real() == b.real() ? a.imag() < b.imag() : a.real() < b.real()) ;});
}
int main()
{
std::random_device seed_gen;
std::default_random_engine engine(seed_gen());
std::uniform_real_distribution<> dist(0.0, 2 * acos(-1));
int N; cin >> N;
vector<p> A(N), B(N);
for(auto &u : A) {
double a, b; cin >> a >> b;
u = {a, b};
}
for(auto &u : B) {
double a, b; cin >> a >> b;
u = {a, b};
}
f(A);
f(B);
const double eps = 1e-2;
for(int i = 0; i < 100000; i++) {
g(B, dist(engine));
bool ok = true;
for(int i = 0; i < N; i++) {
auto v = A[i] - B[i];
if(abs(v) > eps) {
ok = false;
}
}
if(ok) {
cout << "Yes" << endl;
return 0;
}
}
cout << "No" << endl;
} |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, c, n) for(int i = c; i < n; i++)
#define inv(n, a) for(int i = 0; i < n; i++) cin >> a[i]
#define MOD 1000000007
#define INF 1e7
#define LINF 1e15
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<int>>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
void print(){ cout << endl; }
template <class H, class... T> void print(H&& h, T&&... t){ cout << h << ", "; print(forward<T>(t)...); }
template <class C> void dump(C o){ rep(i, o.size()-1) cout << o[i] << ", "; cout << o.back() << endl; }
int main() {
int v, t, s, d; cin >> v >> t >> s >> d;
if (v * t <= d && d <= v * s)
cout << "No" << endl;
else
cout << "Yes" << endl;
}
| #include <iostream>
using namespace std;
int main() {
int v, t, s, d;
cin >> v >> t >> s >> d;
if (d >= v * t && d <= v * s) {
cout << "No";
} else {
cout << "Yes";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__)
#else
#define DEBUG(...) 6
#endif
template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template <typename T, typename... Args> void debug(string s, T x, Args... args) {for (int i=0, b=0; i<(int)s.size(); i++) if (s[i] == '(' || s[i] == '{') b++; else
if (s[i] == ')' || s[i] == '}') b--; else if (s[i] == ',' && b == 0) {cerr << s.substr(0, i) << " = " << x << " | "; debug(s.substr(s.find_first_not_of(' ', i + 1)), args...); break;}}
template<int MOD>
struct ModInt {
long long v;
ModInt(long long _v = 0) {v = (-MOD < _v && _v < MOD) ? _v : _v % MOD; if (v < 0) v += MOD;}
ModInt& operator += (const ModInt &other) {v += other.v; if (v >= MOD) v -= MOD; return *this;}
ModInt& operator -= (const ModInt &other) {v -= other.v; if (v < 0) v += MOD; return *this;}
ModInt& operator *= (const ModInt &other) {v = v * other.v % MOD; return *this;}
ModInt& operator /= (const ModInt &other) {return *this *= inverse(other);}
bool operator == (const ModInt &other) const {return v == other.v;}
bool operator != (const ModInt &other) const {return v != other.v;}
friend ModInt operator + (ModInt a, const ModInt &b) {return a += b;}
friend ModInt operator - (ModInt a, const ModInt &b) {return a -= b;}
friend ModInt operator * (ModInt a, const ModInt &b) {return a *= b;}
friend ModInt operator / (ModInt a, const ModInt &b) {return a /= b;}
friend ModInt operator - (const ModInt &a) {return 0 - a;}
friend ModInt power(ModInt a, long long b) {ModInt ret(1); while (b > 0) {if (b & 1) ret *= a; a *= a; b >>= 1;} return ret;}
friend ModInt inverse(ModInt a) {return power(a, MOD - 2);}
friend ostream& operator << (ostream &os, const ModInt &m) {return os << m.v;}
};
typedef ModInt<998244353> M;
const int MAX = 5005;
M contr[MAX], pw[MAX][MAX];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m;
cin >> n >> m;
for (int x=0; x<=m; x++) {
pw[x][0] = 1;
for (int i=1; i<=n; i++)
pw[x][i] = pw[x][i-1] * x;
}
M ret = 0;
for (int i=0; i<n; i++) {
for (int x=1; x<=m; x++) {
contr[x] *= m;
if (i > 0) contr[x] += pw[m-1][i-1] - pw[m-x][i-1];
ret += (pw[m-1][i] + contr[x]) * pw[m][n-i-1];
}
}
cout << ret << "\n";
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;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
void setIO(string name = "") {
ios_base::sync_with_stdio(0); cin.tie(0);
/*if ((int)name.size()) {
freopen((name + ".in").c_str(), "r", stdin);
freopen((name + ".out").c_str(), "w", stdout);
}*/
}
typedef long long ll;
#define int long long
#define ld long double
#define pb push_back
#define endl "\n"
#define for0(i,n) for(int i=0;i<n;i++)
#define for1(i,n) for(int i=1;i<n;i++)
#define ps(x,y) fixed << setprecision(y) << x
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
using pi = pair<int, int>;
int dx[] = { -1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
const int MAX = 200005;
const int mod = 1e9 + 7;
const ll modulo = 998244353;
void anshu_man(int tt = 0) {
//cout << "Case #" << tt << ": ";
int t, n;
cin >> t >> n;
int ans = ((100LL + t) * n) / t;
if (((100LL + t)*n) % t == 0)
ans--;
cout << ans << endl;
}
int32_t main() {
setIO();
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int t = 1;
//cin >> t;
for (int i = 1; i <= t; i++)
{
anshu_man(i);
}
return 0;
} |
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
typedef long int li;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define test ll t; cin >> t; while(t--)
const long long int dx[4] = {0, 0, -1, 1}, dy[4] = {1, -1, 0, 0};
const long long int cons = 100005;
const long long int MOD = 1000000007; // const long long int MOD = 998244353;
const long long int const_INT_MAX = 1000000000000000000, const_INT_MIN = -1 * 1000000000000000000;
using namespace std;
bool sortinrev(const pair<ll,ll> &a, const pair<ll,ll> &b){return (a.first > b.first);}
bool sortbysec(const pair<ll,ll> &a, const pair<ll,ll> &b){return (a.second < b.second);}
bool sortbysecinrev(const pair<ll,ll> &a, const pair<ll,ll> &b){return (a.second > b.second);}
ll gcd(ll x, ll y){return (ll)(__gcd(x, y));}
ll lcm(ll x, ll y){return (ll)((x * y) / gcd(x, y));}
ll mod_expo(ll x, ll y, ll p){
ll res = 1;
if((x + p) % p == 0){
return res = 0;
}
x = (x + p) % p;
while (y > 0){
if (y & 1) res = (res*x + p) % p;
y = y>>1; x = (x*x + p) % p;
}
return res;
}
void usaco(string str = ""){
fastio;
if(str.size()) {
freopen((str + ".in").c_str(), "r", stdin);
freopen((str + ".out").c_str(), "w", stdout);
}
}
// GFG orz (and the blessings of nishuz sir)
ll getSum(ll BITree[], ll index){
ll sum = 0;
while (index > 0){
sum += BITree[index]; index -= index & (-index);
}
return sum;
}
void updateBIT(ll BITree[], ll n, ll index, ll val){
while (index <= n){BITree[index] += val; index += index & (-index);}
}
void convert(ll arr[], ll n){
ll temp[n]; for(ll i=0;i<n;i++) temp[i] = arr[i];
sort(temp, temp+n);
for (ll i=0;i<n;i++){
arr[i] = lower_bound(temp, temp+n, arr[i]) - temp + 1;
}
}
ll getInvCount(ll arr[], ll n){
ll invcount=0, BIT[n+1];;
convert(arr, n);
for (ll i=1;i<=n;i++) BIT[i] = 0;
for (ll i=n-1;i>=0;i--){
invcount += getSum(BIT, arr[i]-1); updateBIT(BIT, n, arr[i], 1);
}
return invcount;
}
int main(){
usaco();
ll n; cin >> n; ll a[n], dp[n], temp[n];
for(ll i=0;i<n;i++){cin >> a[i]; temp[i] = a[i];}
dp[0] = getInvCount(temp, n);
for(ll i=1;i<n;i++){
dp[i] = dp[i-1] - 2 * a[i-1] + n - 1;
}
for(ll i=0;i<n;i++) cout << dp[i] << "\n";
cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
} | #include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rrep(i,n) for(ll i=n-1; i>=0; i--)
#define fi first
#define se second
#define pcnt __builtin_popcountll
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef pair<ll,Pll> PlP;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}
string zero_padding(int val, int nf){ ostringstream sout;sout << setfill('0') << setw(nf) << val; return sout.str();};
const ld eps = 1e-10;
ull mo = 1000000007;
ld PI=asin(1)*2;
//using namespace atcoder;
int main(){
ll N;
cin >> N;
vector<ll> A(N),S(N+1);
rep(i,N) cin >> A[i];
rep(i,N){
if(i%2) A[i] = -A[i];
}
rep(i,N){
S[i+1] = S[i] + A[i];
}
map<ll,ll> mp;
rep(i,N+1) mp[S[i]]++;
ll ans = 0;
for(auto& p:mp){
ll n = p.se;
ans += n*(n-1)/2;
}
cout << ans << endl;
}
|
//W4P3R
#include<bits/stdc++.h>
#define inf 1e9
#define eps 1e-6
#define mp make_pair
#define pb push_back
#define re register ll
#define fr first
#define sd second
#define pa pair<ll,ll>
#define FOR(i,a,b) for(re i=a;i<=b;i++)
#define REP(i,a,b) for(re i=a;i>=b;i--)
#define MEM(a) memset(a,0,sizeof(a))
#define N 200010
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
inline ll read()
{
char ch=getchar();
ll s=0,w=1;
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
return s*w;
}
inline ll lowbit(ll x){return x&(-x);}
int n;
vector<int>e[N];
int sz[N],f[N];
void dfs(int x)
{
sz[x]=1;
for(int y:e[x]){dfs(y);sz[x]+=sz[y];}
int sum=0;vector<int>v;
for(int y:e[x])
{
if(sz[y]%2==0){if(f[y]<0)f[x]+=f[y];else sum+=f[y];}
else {v.pb(f[y]);}
}
sort(v.begin(),v.end());
int op=1;
for(int val:v){f[x]+=op*val;op=-op;}
//cout<<"WTF:"<<x<<" "<<sum<<" "<<op<<" "<<f[x]<<" "<<(v.size()?v[0]:0)<<endl;
f[x]+=op*sum+1;
}
int main()
{
//ios::sync_with_stdio(false);
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
n=read();
FOR(i,2,n)
{
int fa=read();
e[fa].pb(i);
}
dfs(1);
//FOR(i,1,n)cout<<f[i]<<' ';cout<<'\n';
cout<<(n+f[1])/2<<'\n';
return 0;
}
//gl
| #include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, a, b) for (int i = b; i >= a; i--)
using namespace std;
const int N = 200111;
int n, s, t, sub[N], ans[N], e = 1;
vector<int> g[N];
pair<int, int> dfs(int v, int p) {
pair<int, int> a = {0, v};
for (auto u : g[v]) {
if (u != p) {
auto b = dfs(u, v);
b.first++;
a = max(a, b);
}
}
return a;
}
void go(int v, int p) {
sub[v] = (v == t);
for (auto u : g[v])
if (u != p) {
go(u, v);
sub[v] |= sub[u];
}
}
void solve(int v, int p) {
ans[v] = e;
sort(g[v].begin(), g[v].end(), [&](int a, int b) {
return sub[a] < sub[b];
});
for (auto u : g[v])
if (u != p) {
e++;
solve(u, v);
}
e++;
}
int main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
cin >> n;
rep(i, 1, n - 1) {
int a, b;
cin >> a >> b;
g[a].push_back(b);
g[b].push_back(a);
}
s = dfs(1, 0).second;
t = dfs(s, 0).second;
go(s, 0);
solve(s, 0);
rep(i, 1, n)
cout << ans[i] << " ";
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
using namespace std;
int main(){
char s,t;
cin>>s>>t;
if(s=='Y')t= toupper(t);
cout<<t<<endl;
}
| #include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main(){
int n , s , d;
cin >> n >> s >> d;
rep(i,n){
int x , y;
cin >> x >> y;
if(x >= s || y <= d){
continue;
}
else{
cout << "Yes";
return 0;
}
}
cout << "No";
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
int n,m,k,x,sum=0;
cin>>n>>k>>m;
for(int i=0;i<n-1;i++)
{
cin>>x;
sum+=x;
}
int target = n*m;
if(sum>target) cout<<0<<endl;
else if(abs(target-sum)>k) cout<<-1<<endl;
else {
cout<<abs(target-sum)<<endl;
}
return 0;
} | /*
このコード、と~おれ!
Be accepted!
∧_∧
(。・ω・。)つ━☆・*。
⊂ ノ ・゜+.
しーJ °。+ *´¨)
.· ´¸.·*´¨) ¸.·*¨)
(¸.·´ (¸.·'* ☆
*/
#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
#include <stack>
#include <bitset>
#include <array>
#include <chrono>
//#pragma GCC target("arch=skylake-avx512")
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse4")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define repeat(i, n, m) for(int i = n; i < (m); ++i)
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a)
#define printLdb(a) printf("%.50Lf\n", a)
#define printdbd(a) printf("%.16lf\n", a)
#define prints(s) printf("%s\n", s.c_str())
#define all(x) (x).begin(), (x).end()
#define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI)
#define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L)
#define Please return
#define AC 0
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d))
using ll = long long;
using ull = unsigned long long;
constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1e9 + 7;
constexpr ll mod = 998244353;
constexpr long double eps = 1e-6;
const long double PI = acosl(-1.0L);
using namespace std;
void scans(string& str) {
char c;
str = "";
scanf("%c", &c);
if (c == '\n')scanf("%c", &c);
while (c != '\n' && c != -1 && c != ' ') {
str += c;
scanf("%c", &c);
}
}
void scanc(char& str) {
char c;
scanf("%c", &c);
if (c == -1)return;
while (c == '\n') {
scanf("%c", &c);
}
str = c;
}
double acot(double x) {
return PI / 2 - atan(x);
}
ll LSB(ll n) { return (n & (-n)); }
template<typename T>
inline T chmin(T& a, const T& b) {
if (a > b)a = b;
return a;
}
template<typename T>
inline T chmax(T& a, const T& b) {
if (a < b)a = b;
return a;
}
//cpp_int
#if __has_include(<boost/multiprecision/cpp_int.hpp>)
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
using namespace boost::multiprecision;
#else
using cpp_int = ll;
#endif
//atcoder library
#if __has_include(<atcoder/all>)
#include <atcoder/all>
//using namespace atcoder;
#endif
/*
random_device seed_gen;
mt19937 engine(seed_gen());
uniform_int_distribution dist(1, 100);
*/
/*----------------------------------------------------------------------------------*/
ll pow(ll a, ll n, ll m) {
ll ret = 1;
while (n > 0) {
a %= m;
ret %= m;
if (n % 2) ret *= a;
a *= a;
n /= 2;
}
ret %= m;
return ret;
}
int main() {
ll a, b, c;
scanf("%lld%lld%lld", &a, &b, &c);
vector<ll> ans;
set<ll> st;
{
ll num = a % 10;
while (st.find(num) == st.end()) {
st.insert(num);
ans.push_back(num);
num *= a;
num %= 10;
}
}
b = pow(b, c, ans.size());
if (b == 0)b = ans.size() - 1;
else --b;
printf("%lld\n", ans[b]);
Please AC;
} |
/**
* author: yuya1234
* created: 17.10.2020 20:15:10
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define SORT(x) sort(x.begin(),x.end())
#define SORTD(x) sort(x.rbegin(),x.rend())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define SZ(x) ll(x.size())
#define MEMSET(v, h) memset((v), h, sizeof(v))
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
vector< ll > divisor(ll n) {
vector< ll > ret;
for(ll i = 1; i * i <= n; i++) {
if(n % i == 0) {
ret.push_back(i);
if(i * i != n) ret.push_back(n / i);
}
}
sort(begin(ret), end(ret));
return (ret);
}
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
ll n;
cin>>n;
vector<ll> ret;
ret=divisor(n);
REP(i,SZ(ret))
{
cout<<ret[i]<<endl;
}
return 0;
} | #define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
//#include <Windows.h>
#include<unordered_map>
//#include"testlib.h"
using namespace std;
//<DEFINE>
void Fast() {
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
}
void File() {
#ifndef ONLINE_JUDGE
/* HWND Stealth;
AllocConsole();
Stealth = FindWindowA("ConsoleWindowClass", NULL);
ShowWindow(Stealth, 0);*/
freopen("Input.txt", "r", stdin);
freopen("Output.txt", "w", stdout);
#endif
}
#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcount __popcnt
#ifdef _WIN64
#define __builtin_popcountll __popcnt64
#else
inline int __builtin_popcountll(__int64 a) {
return __builtin_popcount((unsigned int)a) + __builtin_popcount(a >> 32);
}
#endif
#endif
using ll = long long;
using ull = unsigned long long;
#define mod 1000000007
ll gcd(ll a, ll b) {
return!b ? a : gcd(b, a % b);
}
#define fix(n) cout << fixed << setprecision(n);
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define skip continue
#define pi acos(-1)
#define endl "\n"
//#define ceil(x,y) (((x)+(y)-1)/(y))
#define clr(v,d) memset(v, d, sizeof v)
//sin(x*pi/180)
//alot of memset may cause TLE
#define TC int t$$t$;cin>>t$$t$;while(t$$t$--)
//</DEFINE>
int dx[] = { 0,0,-1,1,1,1,-1,-1 };
int dy[] = { 1,-1,0,0,1,-1,1,-1 };
//***********stop when you reach the concept of don't stop***********
//<FUNCTIONS>
struct point
{
ll x, y;
point() {}
point(ll x, ll y) :x(x), y(y) {}
};
double getDis(point a, point b) {
return sqrt(pow(a.x - b.x, 2) + pow(a.y - b.y, 2));
}
void solve() {
ll r, x, y;
cin >> r >> x >> y;
fix(0);
if (getDis(point(0, 0), point(x, y)) < r)cout << 2;
else
cout << ceil(getDis(point(0, 0), point(x, y)) / r);
}
//</FUNCTIONS>
int main() {
Fast();
File();
solve();
} |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i< (n); i++)
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
template<class T> void chmax(T& a, T b){
if(a < b){
a = b;
}
}
template<class T> void chmin(T& a, T b){
if(a > b){
a = b;
}
}
int main()
{
int n;
cin >> n;
int a[n],b[n];
rep(i,n)cin >> a[i];
rep(i,n)cin >> b[i];
int ans = 0;
for(int x = 0; x <= 1000; x++){
bool check = true;
rep(i,n){
if(!(a[i] <= x && x <= b[i]))check = false;
}
if(check)ans++;
}
cout << ans << endl;
return 0;
} | //#include <stdio.h>
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
int n;
cin>>n;
int a[n+5],b[n+5];
int min=0;
int max=10000;
for(int i=0; i<n; i++){
cin>>a[i];
if(min<a[i]) min=a[i];
}
//cout<<min<<"\n";
for(int i=0; i<n; i++){
cin>>b[i];
if(max>b[i]) max=b[i];
}
//cout<<max<<"\n";
if(min>max) cout<<'0'<<"\n";
else cout<<(max-min)+1<<"\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int a[100][100];
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int h, w;
cin >> h >> w;
int mn = 1e9, total = 0;
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
cin >> a[i][j];
mn = min(mn, a[i][j]);
total += a[i][j];
}
}
cout << total - h*w*mn;
}
| #include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ld long double
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define mp map<ll, ll>
#define um unordered_map<ll, ll>
#define st set<ll>
#define us unordered_set<ll>
#define vt vector<ll>
#define vp vector<pll>
#define pll pair<ll, ll>
#define fl(i, x, y) for(ll i=x;i<y;++i)
#define flr(i, x, y) for(ll i=x;i>=y;--i)
#define endl "\n"
#define speedup ios_base::sync_with_stdio(false), cin.tie(NULL)
void solve()
{
ll n,m;
cin>>n>>m;
ll a[n][m], mn=LONG_MAX, s=0;
fl(i, 0, n)
{
fl(j, 0, m)
{
cin>>a[i][j];
mn = min(mn, a[i][j]);
}
}
fl(i, 0, n)
{
fl(j, 0, m)
s += (abs(a[i][j]-mn));
}
cout<<s<<endl;
}
int main()
{
speedup;
#ifndef ONLINE_JUDGE
freopen("E:\\competitive programming\\input.txt", "r", stdin);
freopen("E:\\competitive programming\\output.txt", "w", stdout);
#endif
ll tt=1;
//cin>>tt;
while(tt--)
{
solve();
}
return 0;
}
|
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define N 200005
using namespace std;
int read() {
int x=0,f=1;char c=getchar();
while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
while('0'<=c&&c<='9'){x=x*10+c-'0';c=getchar();}
return x*f;
}
int n,m,a[N],vst[17],tot;
char s[N];
ll f[N][17];
int main() {
scanf("%s",s+1);n = strlen(s+1);
for(int i=1; i<=n; ++i)if(s[i] <= '9')a[i] = s[i]-'0';else a[i] = s[i]-'A'+10;
m = read();
for(int i=1; i<=n; ++i) {
for(int j=1; j<=m; ++j)
f[i][j] = f[i-1][j]*j+f[i-1][j-1]*(16-j+1);
if(a[i] >= 1) {
int sum = 0;
for(int j=0; j<a[i]; ++j)sum += vst[j];
f[i][tot] += sum;
int tmp = a[i]-sum;
if(i==1)tmp--;
f[i][tot+1] += max(tmp,0);
}
if(i > 1)f[i][1] += 15;
for(int j=1; j<=m; ++j)f[i][j] %= mod;
if(!vst[a[i]])vst[a[i]] = 1,tot++;
}
cout << f[n][m]+(tot==m);
} | #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;
using ll=long long;
using db=double;
///***************************************************** CONSTANTS ******************************************************///
int const N=1e6+3;
ll MOD=1e9+7,fact[N];
const long long inf=(long long)1e18;
const long double PI=3.14159265358979;
///************************************************ CONTAINER DEFINITIONS ***********************************************///
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef set<int> si;
typedef set<ll> sl;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
///************************************************ SHORT FORM KEYWORDS *************************************************///
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define I insert
#define lb lower_bound
#define ub upper_bound
#define endl '\n'
///************************************************ SHORT FORM FUNCTIONS ************************************************///
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define loopr(i,a,b) for(ll i=a-1;i>=b;i--)
#define afor(x, y) for (auto x : y)
#define mem(a,b) memset(a, b, sizeof(a) )
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sa(v) sort(v.begin(),v.end())
#define sd(v) sort(v.begin(),v.end(),greater<>())
#define rev(s) reverse(s.begin(),s.end())
#define stll(x) stoll(x, nullptr, 10);
#define yes cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
#define mx(a) *max_element(all(a))
#define mn(a) *min_element(all(a))
#define all(a) a.begin(),a.end()
#define mxa(a,N) *max_element(a,a+N)
#define mna(a,N) *min_element(a,a+N)
#define print(a) {for(auto x:a)cout<<x<<" ";cout<<endl;}
///******************************************** FAST IO $ FILE INPUT ****************************************************///
#define io() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define fio() freopen("input_file_name","r",stdin);freopen("output_file_name","w",stdout);
///********************************************* REQUIRED FUNCTIONS *****************************************************///
ll powmod(ll a,ll b){ll p=MOD;a%=p;if(!a) return 0;ll pr=1;while(b>0){if(b&1){pr*=a;pr%=p;--b;}a*=a;a%=p;b/=2;}return pr;}
ll inv(ll a,ll p){return powmod(a,p-2);}
ll nCr(ll n,ll k,ll p){fact[0]=1;loop(i,1,n+1) fact[i]=fact[i-1]*i;return ((fact[n]*inv(fact[k],p)%p)*inv(fact[n-k],p))%p;}
bool isPrime(ll n){ if(n<=1)return false;if(n<=3)return true;if(n%2==0 or n%3==0)return false;for(ll i=5;i*i<=n;i+=6){if(n%i==0|n%(i+2)==0)return false;}return true;}
///######################################################################################################################///
typedef tree<pair<ll,ll>, null_type, less<pair<ll,ll>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
///************************************************ SOLUTION STARTS HERE ************************************************///
///======================================================================================================================///
void solve()
{
ll n;
cin>>n;
ll ans=n;
for(int i=1;i<=n;i++){
ll k=i;
bool b=true;
while(k){
if(k%10==7) {ans--;b=false;break;}
k/=10;
}
k=i;
if(b){
while(k){
if(k%8==7){
ans--;b=false;break;
}
k/=8;
}
}
}
cout<<ans<<endl;
}
int main()
{
io();
int $=1;//cin>>$;
while($--) solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
double dp[101][101][101];
double funct(int a, int b, int c){
if(dp[a][b][c]) return dp[a][b][c];
if(a == 100 || b == 100 || c == 100) return 0;
double ans = 0;
ans += (funct(a + 1, b, c) + 1)*a/(a + b + c);
ans += (funct(a, b + 1, c) + 1)*b/(a + b + c);
ans += (funct(a, b, c + 1) + 1)*c/(a + b + c);
dp[a][b][c] = ans;
return ans;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int a, b, c;
cin >> a >> b >> c;
printf("%.9lf\n", funct(a, b, c));
return 0;
} | #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,a,b) for(int i=(a);i<(b);++i)
template<class T> inline void chmin(T& a, T b) {if (a > b) a = b;}
template<class T> inline void chmax(T& a, T b) {if (a < b) a = b;}
//vector出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){
o<<"{";
for(int i=0;i<(int)v.size();i++) o << (i>0?", ":"") << v[i];
o<<"}"<<endl;
return o;
}
//逆元 a/b の modをとるとき -> a*modinv(b)%mod
long long modinv(long long a, long long m = 1e9+7) {
long long b = m, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b; swap(a, b);
u -= t * v; swap(u, v);
}
u %= m;
if (u < 0) u += m;
return u;
}
ll const mod = 1e9+7;
// combination
const int MAX = 510000;
const ll MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++){
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
long long COM(int n, int k){
if (n < k) return 0;
if (n < 0 || k < 0) return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// べき乗
ll modpow(ll x, ll n) {
x = x%MOD;
if(n==0) return 1; //再帰の終了条件
else if(n%2==1) {
return (x*modpow(x, n-1))%MOD; //nが奇数ならnを1ずらす
}
else return modpow((x*x)%MOD, n/2)%MOD; //nが偶数ならnが半分になる
}
////
//Union Find
struct UnionFind {
vector<int> par; // 親ノード
vector<int> rank; // ランク
UnionFind(int n = 1) {
init(n);
}
void init(int n = 1) {
par.resize(n); rank.resize(n);
for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0;
}
int root(int x) {
if (par[x] == x) {
return x;
}
else {
int r = root(par[x]);
return par[x] = r;
}
}
bool issame(int x, int y) {
return root(x) == root(y);
}
bool merge(int x, int y) {
x = root(x); y = root(y);
if (x == y) return false;
if (rank[x] < rank[y]) swap(x, y);
if (rank[x] == rank[y]) ++rank[x];
par[y] = x;
return true;
}
};
//BIT
template <class Abel> struct BIT {
vector<Abel> dat;
Abel UNITY_SUM = 0; // to be set
/* [1, n] */
BIT(int n) { init(n); }
void init(int n) {
dat.resize(n + 1);
for (int i = 0; i < (int)dat.size(); ++i) dat[i] = UNITY_SUM;
}
/* a is 1-indexed */
inline void add(int a, Abel x) {
for (int i = a; i < (int)dat.size(); i += i & -i)
dat[i] = dat[i] + x;
}
/* [1, a], a is 1-indexed */
inline Abel sum(int a) {
Abel res = UNITY_SUM;
for (int i = a; i > 0; i -= i & -i)
res = res + dat[i];
return res;
}
/* [a, b), a and b are 1-indexed */
inline Abel sum(int a, int b) {
return sum(b - 1) - sum(a - 1);
}
/* k-th number (k is 0-indexed) */
int get(int k) {
++k;
int res = 0;
int N = 1; while (N < (int)dat.size()) N *= 2;
for (int i = N / 2; i > 0; i /= 2) {
if (res + i < (int)dat.size() && dat[res + i] < k) {
k = k - dat[res + i];
res = res + i;
}
}
return res + 1;
}
};
int main() {
int N;
cin >> N;
int ans = 1e9+1;
int a,p,x;
rep(i,N) {
cin >> a >> p >> x;
if (x-a>0) chmin(ans,p);
}
if (ans>1e9) ans = -1;
cout << ans << endl;
}
|
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <complex>
#include <vector>
#include <limits>
#include <iomanip>
#include <cassert>
#include <numeric>
#include <chrono>
#include <random>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define debug(x) cout << #x << " = " << (x) << endl;
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n-1;i >= 0;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
const long double pi = 3.141592653589793;
const int mod = 998244353;
int dp[3022][6044];
int solve2(int n,int k) {
if(k > n) return 0;
if(k == n) return 1;
if(k == 0) return 0;
if(dp[n][k] != 0) return dp[n][k];
return dp[n][k] = (solve2(n-1, k-1) + 0LL + solve2(n, 2*k))%mod;
}
void solve() {
int n,k;cin>>n>>k;
cout << solve2(n,k) << endl;
}
int main() {
// freopen("input.in","r",stdin);
// freopen("output.out","w",stdout);
// cout << fixed << setprecision(15);
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t=1;//cin>>t;
while (t--) {
solve();
}
return 0;
}
|
#pragma GCC optimize("O3")
//#pragma GCC target("avx2")
//#pragma GCC optimize("unroll-loops")
#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 vector<ll> vll;
typedef vector<ld> vld;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;
ll INF = 1e16;
int inf = 1e9;
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (ll i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (ll i = ((n) - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll
#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif
void d_err() {
cerr << endl;
}
template <typename H, typename... T>
void d_err(H h, T... t) {
cerr << h << " ";
d_err(t...);
}
template <typename T>
void print(T x) {
cout << x << "\n";
}
template <typename T>
void print(vector<T>& x) {
int N = x.size();
REP(i, N) {
if (i > 0) cout << " ";
cout << x[i];
}
cout << "\n";
}
int main(){
cin.tie(0);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(20);
int n, m; cin >> n >> m;
vector<vector<Pll>> xyz(n + 1);
REP(i, m) {
ll _x, _y, _z;
cin >> _x >> _y >> _z;
xyz[_x].eb(make_pair(_y, _z));
}
vector<ll> dp(1LL << n, 0);
dp[0] = 1;
REP(i, n) {
REVREP(j, 1LL << n) {
if (bcnt(j) != i || dp[j] == 0) continue;
REP(k, n) {
if (j >> k & 1) continue;
ll sn = j | (1LL << k);
bool f = true;
for (auto [y, z]: xyz[i + 1]) {
ll mask = (1LL << y) - 1;
if (bcnt(sn & mask) > z) {
f = false;
break;
}
}
if (f) dp[sn] += dp[j];
}
}
}
print(dp[(1LL << n) - 1]);
}
|
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n;
cin>>n;
vector<pair<ll,int>> X(n),Y(n);
rep(i,n){
ll x,y;
cin>>x>>y;
X[i]={x,i};
Y[i]={y,i};
}
sort(ALL(X));
sort(ALL(Y));
vector<pair<ll,pair<int,int>>> A;
A.push_back({X[n-1].first-X[0].first,{X[n-1].second,X[0].second}});
A.push_back({X[n-1].first-X[1].first,{X[n-1].second,X[1].second}});
A.push_back({X[n-2].first-X[0].first,{X[n-2].second,X[0].second}});
A.push_back({Y[n-1].first-Y[0].first,{Y[n-1].second,Y[0].second}});
A.push_back({Y[n-1].first-Y[1].first,{Y[n-1].second,Y[1].second}});
A.push_back({Y[n-2].first-Y[0].first,{Y[n-2].second,Y[0].second}});
sort(ALL(A));
reverse(ALL(A));
ll ma=A[0].first;
ll tma0=A[0].second.first,tma1=A[0].second.second;
if(tma1>tma0) swap(tma1,tma0);
ll sma0=A[1].second.first,sma1=A[1].second.second;
if(sma1>sma0) swap(sma1,sma0);
if(tma1==sma1 && tma0==sma0){
cout<<A[2].first<<endl;
}
else cout<<A[1].first<<endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
pair<int,int> solve(int x,int y) {
if(x > y) {
swap(x,y);
}
return {x,y};
}
int main() {
int N;
cin >> N;
vector<pair<pair<int,int>,int>>tmp(N);
for(int i = 0; i < N; i++) {
cin >> tmp[i].first.first >> tmp[i].first.second;
tmp[i].second = i;
}
sort(tmp.begin(),tmp.end());
vector<pair<int,pair<int,int>>>tmp2;
tmp2.push_back({tmp[N-1].first.first-tmp[0].first.first,solve(tmp[N-1].second,tmp[0].second)});
tmp2.push_back({tmp[N-1].first.first-tmp[1].first.first,solve(tmp[N-1].second,tmp[1].second)});
tmp2.push_back({tmp[N-2].first.first-tmp[0].first.first,solve(tmp[N-2].second,tmp[0].second)});
for(int i = 0; i < N; i++) {
swap(tmp[i].first.first,tmp[i].first.second);
}
sort(tmp.begin(),tmp.end());
tmp2.push_back({tmp[N-1].first.first-tmp[0].first.first,solve(tmp[N-1].second,tmp[0].second)});
tmp2.push_back({tmp[N-1].first.first-tmp[1].first.first,solve(tmp[N-1].second,tmp[1].second)});
tmp2.push_back({tmp[N-2].first.first-tmp[0].first.first,solve(tmp[N-2].second,tmp[0].second)});
sort(tmp2.rbegin(),tmp2.rend());
for(int i = 1; i < tmp2.size(); i++) {
if(tmp2[i].second != tmp2[i-1].second) {
cout << tmp2[i].first << endl;
return 0;
}
}
}
|
#include <bits/stdc++.h>
using i64 = long long;
using u32 = unsigned;
using u64 = unsigned long long;
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
i64 n;
std::cin >> n;
std::string s, t;
std::cin >> s;
std::cin >> t;
std::vector<int> a, b;
for (int i = 0; i < n; i++) {
if (s[i] == '0') {
a.push_back(i);
}
if (t[i] == '0') {
b.push_back(i);
}
}
if (a.size() != b.size()) {
std::cout << "-1\n";
return 0;
}
int ans = 0;
for (int i = 0; i < int(a.size()); i++) {
ans += (a[i] != b[i]);
}
std::cout << ans << "\n";
return 0;
} | #define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
//template
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(v) (v).begin(),(v).end()
using ll=long long int;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
//end
bitset<7> dp[201010];
int main(){
int n;
cin>>n;
string s,t;
cin>>s>>t;
dp[n]=1;
for(int i=n-1;i>=0;i--){
if(t[i]=='A'){
rep(x,0,7)dp[i][x]=1;
rep(x,0,7){
if(!dp[i+1][(10*x+(s[i]-'0'))%7]){
dp[i][x]=0;
}
if(!dp[i+1][(10*x)%7]){
dp[i][x]=0;
}
}
}
else{
rep(x,0,7){
if(dp[i+1][(10*x+(s[i]-'0'))%7]){
dp[i][x]=1;
}
if(dp[i+1][(10*x)%7]){
dp[i][x]=1;
}
}
}
}
if(dp[0][0])puts("Takahashi");
else puts("Aoki");
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define REP(i, j, n) for (int i = (j); i < (n); ++i)
#define mp make_pair
using ll = long long;
using ld = long double;
typedef pair<int, int> P;
typedef pair<P, int> COST;
#define repl(i, n) for (ll i = 0; i < (n); ++i)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
using vll = vector<char>;
using GrafPair = vector<vector<P>>;
using Graf = vector<vll>;
#define MAX int(1e9) + 7
#define DOUBLE fixed << setprecision(15)
int main()
{
ll n, k;
cin >> n >> k;
vector<ll> a(n), b(n);
rep(i,n)cin >> a[i] >> b[i];
map<ll,ll> money;
rep(i,n){
money[a[i]]=0;
}
money[0]= k;
rep(i,n){
money[a[i]]+=b[i];
}
vector<ll> c(n+1);
c[0]=0;
rep(i,n)c[i+1]=a[i];
sort(c.begin(),c.end());
c.erase(unique(c.begin(),c.end()),c.end());
ll sum=0;
ll last=0;
rep(i,c.size()){
if(sum>=(c[i]-last)){
sum-=(c[i]-last);
sum+=money[c[i]];
last=c[i];
}else{
if(i==0)sum+=k;
cout << last+sum << endl;
return 0;
}
}
cout << c[c.size()-1]+sum << endl;
} | #include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main(void)
{
ios::sync_with_stdio(false);
cin.tie(0);
ll N, K, r, m, n;
cin >> N >> K;
N--;
ll sum = N * 3, zero = 0, one = 1, tmp = 0;
for (r = 0; r <= sum; r++){
tmp = 0;
if (r <= N)
tmp = (r + 1) * (r + 1) - (r + 1) * r / 2;
else if (r > N && r <= 2 * N)
tmp = (r - N + 1) * (2 * N - r + 1) + (r - N + 1) * (r - N) / 2
+ (2 * N - r) * (r + 1) - (2 * N - r) * (r + 1) / 2;
else
tmp = (3 * N - r + 1) * (2 * N - r + 1) + (3 * N - r + 1) * (r - N) / 2;
if (K > tmp)
K -= tmp;
else
break;
}
for (m = max(r - 2 * N, zero); m <= min(r, N); m++){
tmp = (min(N, r - m) - max(r - m - N, zero) + 1);
if (K > tmp)
K -= tmp;
else
break;
}
for (n = max(r - m - N, zero); n <= min(N, r - m); n++){
if (K > 1)
K--;
else
break;
}
cout << m + 1 << ' ' << n + 1 << ' ' << r - m - n + 1 << '\n';
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define MAXN 200005
#define lowbit(x) (x&-x)
#define reg register
#define mkpr make_pair
#define fir first
#define sec second
typedef long long LL;
typedef unsigned long long uLL;
const int INF=0x3f3f3f3f;
const int mo=998244353;
const LL jzm=2333;
const int iv2=499122177;
const double Pi=acos(-1.0);
typedef pair<int,int> pii;
const double PI=acos(-1.0);
template<typename _T>
_T Fabs(_T x){return x<0?-x:x;}
template<typename _T>
void read(_T &x){
_T f=1;x=0;char s=getchar();
while(s>'9'||s<'0'){if(s=='-')f=-1;s=getchar();}
while('0'<=s&&s<='9'){x=(x<<3)+(x<<1)+(s^48);s=getchar();}
x*=f;
}
template<typename _T>
void print(_T x){if(x<0){x=(~x)+1;putchar('-');}if(x>9)print(x/10);putchar(x%10+'0');}
int n,a[MAXN],pow2[MAXN],inv2[MAXN],suf[MAXN],ans;
int add(int x,int y){return x+y<mo?x+y:x+y-mo;}
signed main(){
read(n);for(int i=1;i<=n;i++)read(a[i]);sort(a+1,a+n+1);
pow2[0]=1;for(int i=1;i<=n;i++)pow2[i]=add(pow2[i-1],pow2[i-1]);
inv2[0]=1;for(int i=1;i<=n;i++)inv2[i]=1ll*inv2[i-1]*iv2%mo;
for(int i=n;i>0;i--)suf[i]=add(suf[i+1],1ll*a[i]*pow2[i-1]%mo);
for(int i=1;i<=n;i++)ans=add(ans,1ll*suf[i+1]*inv2[i]%mo*a[i]%mo);
for(int i=1;i<=n;i++)ans=add(ans,1ll*a[i]*a[i]%mo);printf("%d\n",ans);
return 0;
} | #include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=998244353 ;
#define PI 3.141592653589793
//#include <atcoder/all>
//using namespace atcoder;
//using Mint = modint;
long long modinv(long long a, long long m) {
long long b = m, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b; swap(a, b);
u -= t * v; swap(u, v);
}
u %= m;
if (u < 0) u += m;
return u;
}
ll modpow(ll a, ll n, ll p){
if(n==0) return 1;
if(n%2) return (a*modpow(a, n-1, p))%p;
if(!(n%2)){
ll t=modpow(a, n/2, p);
return (t*t)%p;
}
}
int main(){
int n, m; cin >> n >> m; ll igai = 0; ll iga = 0, ig = 0;
if(n==1){
cout << m << endl; return 0;
}
ll dp[m+1][n+1] = {};
rep(i, m+1){
rep(j, n+1){
if(j==0) dp[i][j] = 1;
else dp[i][j] = dp[i][j-1]*i%mod;
}
}
ll minv[m+1];
rep(i, m+1){
minv[i] = modinv(i, mod);
}
for(int i=1; i<=n-1; i++){
for(int j=1; j<=m; j++){
ll now = dp[m][n-1] - dp[m][i-1]*dp[m-j][n-i]%mod;
if(now<0) now+=mod;
now%=mod;
now*=minv[j];
iga+=now; iga%=mod;
}
}
//cout << (modpow(m, n, mod)*n%mod-igai+mod)%mod << endl;
ll all = modpow(m, n, mod)*n%mod;
all-=iga;
if(all<0) all+=mod; all%=mod;
cout << all << endl;
}
|
#include<bits/stdc++.h>
using namespace std;
long long n,a[39],b[31];
int main()
{
cin>>n;
a[0]=b[0]=1ll;
for(int i=1;i<=38;i++)
a[i]=a[i-1]*3;
for(int i=1;i<=26;i++)
b[i]=b[i-1]*5;
// for(int i=1;i<=30;i++)
// cout<<a[i]<<endl;
// for(int i=1;i<=30;i++)
// cout<<b[i]<<endl;
for(int i=1;i<=38;i++)
for(int j=1;j<=26;j++)
if(a[i]+b[j]==n)
{
cout<<i<<' '<<j;
return 0;
}
cout<<-1;
return 0;
}
| #include <iostream>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <list>
#include <cmath>
#include <algorithm>
#include <assert.h>
using namespace std;
template <typename input_type>
input_type input() {
input_type inp;
cin >> inp;
return inp;
}
const int max_vrtx = 4e5 + 5;
bool cycle, mark[max_vrtx];
int nm, sz;
vector <int> graph[max_vrtx];
void DFS(int vrtx, int par = -1) {
int useless = 0;
mark[vrtx] = true;
sz++;
for (auto ngh: graph[vrtx]) {
if (not mark[ngh]) {
DFS(ngh, vrtx);
} else if ((ngh != par) or useless) {
cycle = true;
} else {
useless++;
}
}
}
int main() {
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
nm = input<int>();
for (int i = 0; i < nm; i++) {
pair <int, int> color = {input<int>(), input<int>()};
graph[color.first].push_back(color.second);
graph[color.second].push_back(color.first);
}
int ans = 0;
for (int i = 0; i < max_vrtx; i++) {
if ((not mark[i]) and (not graph[i].empty())) {
DFS(i);
if (cycle) {
ans += sz;
} else {
ans += (sz - 1);
}
sz = 0;
cycle = false;
}
}
cout << ans;
return 0;
} |
#include <bits/stdc++.h>
#pragma GCC diagnostic warning "-std=c++11"
#define ll long long
#define pb push_back
#define pi acos(-1.0)
#define maxn 1000009
#define sorted(s) sort(s.begin(),s.end())
#define sl(n) scanf("%lld", &n)
#define pb push_back
#define fr first
#define sc second
#define all(a) a.begin(),a.end()
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n;
cin>>n;
string t;
cin>>t;
ll x = 1e10;
if(t=="11" or t=="0" or t=="110"){
cout << x << "\n";
return 0;
}
if(t=="1"){
cout << 2*x << endl;
return 0;
}
string s = "110";
bool flag = false;
ll fst;
for(ll i=0;i<3;i++){
ll st = i, j;
for(j=0;j<n;j++){ //loop whole t.
ll ind = (i+j)%3;
char ch = s[ind];
if(t[j] != ch){
break;
}
}
if(j==n){
flag = true;
fst = i;
break;
}
}
if(flag==false){
cout << 0 << "\n";
return 0;
}
// cout << fst << endl;
ll tot = 3*1e10;
// cout << tot << endl;
// cout << (tot-fst)/n << endl;
tot-=n;
ll ans = (tot-fst)/3;
ans++;
cout << ans << "\n";
return 0;
} | #define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios::sync_with_stdio(false); cin.tie(0);
//b
int n;
cin >> n;
string t;
cin >> t;
string s = "";
while ((int) s.size() <= n) {
s += "110";
}
s += s;
const int long long SN = 3e10;
long long ans = 0;
// first
{
if (s.substr(0, n) == t) {
long long st = SN - n;
ans += st / 3 + 1;
}
}
// second
{
if (s.substr(1, n) == t) {
long long st = SN - n;
st--;
ans += st / 3 + 1;
}
}
// third
{
if (s.substr(2, n) == t) {
long long st = SN - n;
st -= 2;
ans += st / 3 + 1;
}
}
cout << ans << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<long long> a(n);
for (int i = 0; i < n; i++) {
cin >> a.at(i);
}
sort(a.begin(), a.end());
long long m = 998244353;
vector<long long> min_sum(n);
min_sum.at(0) = a.at(0);
if (n > 1) {
for (int i = 1; i < n; i++) {
min_sum.at(i) = (min_sum.at(i-1)*2-a.at(i-1)+a.at(i))%m;
}
}
long long res = 0;
for (int i = 0; i < n; i++) {
res = (res+a.at(i)*min_sum.at(i)%m)%m;
}
cout << res << endl;
} | #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;
// #define endl '\n'
#define int long long int
#define rep(i, a, b) for (int i = a; i < b; i++)
#define revrep(i, a, b) for (int i = a; i >= b; i--)
#define pb push_back
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
ostream &operator<<( ostream &output, const pii &p ) { output << p.first << " " << p.second;return output; }
istream &operator>>( istream &input, pii &p ) { input >> p.first >> p.second;return input; }
template<typename T>
void inline println(vector<T> args){ for(T i: args)cout<<i<<" ";cout<<endl; }
void amax(int& a, int b) { a = max(a, b); }
void amin(int& a, int b) { a = min(a, b); }
int ceilInt(int a, int b) {
if(!b) return 0;
if(a%b) return a/b + 1;
return a/b;
}
int INF = 1e18;
int MOD = 998244353;
static int mod_inv(int a, int m = MOD) {
int g = m, r = a, x = 0, y = 1;
while (r != 0) {
int q = g / r;
g %= r; swap(g, r);
x -= q * y; swap(x, y);
}
return x < 0 ? x + m : x;
}
void solve()
{
int n; cin>>n;
int arr[n];
rep(i, 0, n) cin>>arr[i];
vi two(n+1, 1), twoInv(n+1, 1);
int inv = mod_inv(2);
rep(i, 1, n+1) {
twoInv[i] = (inv*twoInv[i-1])%MOD;
two[i] = (2*two[i-1])%MOD;
}
auto f = [&](int i) {
return (twoInv[i]*arr[i])%MOD;
};
sort(arr, arr+n);
int ans = 0;
int pre = 0;
rep(i, 0, n) {
if(i-1 >= 0)
ans += (((pre*two[i-1])%MOD)*arr[i])%MOD;
ans += (arr[i]*arr[i])%MOD;
ans %= MOD;
pre += f(i);
pre %= MOD;
}
cout<<ans<<endl;
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
// cin>>t;
rep(i, 0, t)
{
// cout<<"Case #"<<i+1<<": ";
solve();
}
return 0;
} |
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline int my_getchar_unlocked(){
static char buf[1048576];
static int s = 1048576;
static int e = 1048576;
if(s == e && e == 1048576){
e = fread_unlocked(buf, 1, 1048576, stdin);
s = 0;
}
if(s == e){
return EOF;
}
return buf[s++];
}
inline void rd(int &x){
int k;
int m=0;
x=0;
for(;;){
k = my_getchar_unlocked();
if(k=='-'){
m=1;
break;
}
if('0'<=k&&k<='9'){
x=k-'0';
break;
}
}
for(;;){
k = my_getchar_unlocked();
if(k<'0'||k>'9'){
break;
}
x=x*10+k-'0';
}
if(m){
x=-x;
}
}
inline void rd(long long &x){
int k;
int m=0;
x=0;
for(;;){
k = my_getchar_unlocked();
if(k=='-'){
m=1;
break;
}
if('0'<=k&&k<='9'){
x=k-'0';
break;
}
}
for(;;){
k = my_getchar_unlocked();
if(k<'0'||k>'9'){
break;
}
x=x*10+k-'0';
}
if(m){
x=-x;
}
}
inline void rd(__int128_t &x){
int k;
int m=0;
x=0;
for(;;){
k = my_getchar_unlocked();
if(k=='-'){
m=1;
break;
}
if('0'<=k&&k<='9'){
x=k-'0';
break;
}
}
for(;;){
k = my_getchar_unlocked();
if(k<'0'||k>'9'){
break;
}
x=x*10+k-'0';
}
if(m){
x=-x;
}
}
struct MY_WRITER{
char buf[1048576];
int s;
int e;
MY_WRITER(){
s = 0;
e = 1048576;
}
~MY_WRITER(){
if(s){
fwrite_unlocked(buf, 1, s, stdout);
}
}
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
MY_WRITER_VAR.s = 0;
}
MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
my_putchar_unlocked(a);
}
inline void wt_L(int x){
int s=0;
int m=0;
char f[10];
if(x<0){
m=1;
x=-x;
}
while(x){
f[s++]=x%10;
x/=10;
}
if(!s){
f[s++]=0;
}
if(m){
my_putchar_unlocked('-');
}
while(s--){
my_putchar_unlocked(f[s]+'0');
}
}
inline void wt_L(long long x){
int s=0;
int m=0;
char f[20];
if(x<0){
m=1;
x=-x;
}
while(x){
f[s++]=x%10;
x/=10;
}
if(!s){
f[s++]=0;
}
if(m){
my_putchar_unlocked('-');
}
while(s--){
my_putchar_unlocked(f[s]+'0');
}
}
inline void wt_L(__int128_t x){
int s=0;
int m=0;
char f[40];
if(x<0){
m=1;
x=-x;
}
while(x){
f[s++]=x%10;
x/=10;
}
if(!s){
f[s++]=0;
}
if(m){
my_putchar_unlocked('-');
}
while(s--){
my_putchar_unlocked(f[s]+'0');
}
}
template<class T> inline T pow2_L(T a){
return a*a;
}
int main(){
__int128_t R;
rd(R);
__int128_t X;
rd(X);
__int128_t Y;
rd(Y);
__int128_t res;
if((pow2_L(X))+(pow2_L(Y))==(pow2_L(R))){
wt_L(1);
wt_L('\n');
return 0;
}
__int128_t Lj4PdHRW;
__int128_t KL2GvlyY;
__int128_t Q5VJL1cS;
Lj4PdHRW = 0;
KL2GvlyY = 1000000;
while(Lj4PdHRW < KL2GvlyY){
if((Lj4PdHRW + KL2GvlyY)%2==0){
Q5VJL1cS = (Lj4PdHRW + KL2GvlyY) / 2;
}
else{
Q5VJL1cS = (Lj4PdHRW + KL2GvlyY - 1) / 2;
}
if((pow2_L(X))+(pow2_L(Y))<=(pow2_L((Q5VJL1cS*R)))){
KL2GvlyY = Q5VJL1cS;
}
else{
Lj4PdHRW = Q5VJL1cS + 1;
}
}
res =KL2GvlyY;
if(res==1){
res = 2;
}
wt_L(res);
wt_L('\n');
return 0;
}
// cLay version 20210405-1
// --- original code ---
// {
// __int128_t @R, @X, @Y, res;
// if(X**2 + Y**2 == R**2) wt(1), return 0;
// res = bsearch_min[__int128_t,c,0,1d6](X**2+Y**2 <= (c*R)**2);
// if(res==1) res = 2;
// wt(res);
// }
| #include <stdio.h>
#include <algorithm>
#include <vector>
#define MN 100000
int n;
std::vector<int> e[MN+5];
void add(int u,int v){
e[u].push_back(v);
}
struct state{
int c,f,s;
}s[MN+5];
void dfs(int u){
s[u].c = 1;
s[u].f = 1;
s[u].s = 0;
std::vector<int> ve[2];
for(auto v:e[u]){
dfs(v);
s[u].c += s[v].c;
if(s[v].c&1){
ve[1].push_back(v);
}else{
if(s[v].s>=s[v].f){
s[u].s += s[v].s;
s[u].f += s[v].f;
}else{
ve[0].push_back(v);
}
}
}
std::sort(ve[1].begin(),ve[1].end(),[](int a,int b)->bool{
return s[a].s-s[a].f>s[b].s-s[b].f;
});
for(int i=0;i<(int)ve[1].size();i++){
int v = ve[1][i];
if(i&1){
s[u].f += s[v].s;
s[u].s += s[v].f;
}else{
s[u].s += s[v].s;
s[u].f += s[v].f;
}
}
if(ve[1].size()&1){
for(auto v:ve[0]){
s[u].f += s[v].s;
s[u].s += s[v].f;
}
}else{
for(auto v:ve[0]){
s[u].s += s[v].s;
s[u].f += s[v].f;
}
}
}
int main(){
scanf("%d",&n);
for(int i=2,f;i<=n;i++){
scanf("%d",&f);
add(f,i);
}
dfs(1);
printf("%d\n",s[1].f);
} |
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define rep(i,s,e) for(int i=s ; i < e ; i++)
#define rrep(i,s,e) for(int i=s ; i > e ; i--)
#define srep(i,s,e,j) for(int i=s ; i < e ; i+=j)
#define tr(i,x) for(auto i : x)
#define inp(a) for(int i=0 ; i<a.size() ; i++)cin>>a[i]
#define int long long
#define vi vector<int>
#define vs vector<string>
#define vb vector<bool>
#define vpi vector<pii>
#define maxpqi priority_queue<int>
#define minpqi priority_queue <int, vector<int>, greater<int> >
#define pii pair<int,int>
#define F first
#define S second
#define mk make_pair
#define pb push_back
#define pf push_front
#define endl '\n'
#define br printf("\n")
#define inf 1000000
#define imap map<int,int>
#define uimap unordered_map<int,int>
#define gcd(a,b) __gcd(a,b)
#define mod 1000000007
#define clr(x) memset(x,0,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define lb lower_bound
#define ub upper_bound
#define npos string::npos
#define all(x) x.begin(),x.end()
#define descen greater<int>()
string yes="YES",no="NO";
const int hi = 1e4;
vi must;
vi wrong;
bool ok(int n){
vi pre;
if(n == 0)pre.pb(0);
while(n > 0){
pre.pb(n%10);
n = n/10;
}
while(pre.size() < 4)pre.pb(0);
sort(all(pre));
bool ans;
tr(i,must){
ans = false;
tr(j,pre){
if(i == j){
ans = true;
break;
}
}
if(!ans)return false;
}
tr(i,wrong){
tr(j,pre){
if(i == j){
return false;
}
}
}
// bool ans = true;
// tr(i,must){
// ans = false;
// // tr(j,pre){
// // if(i == j){
// // pre.erase(find(all(pre),j));
// // ans = true;
// // break;
// // }
// // }
// rep(j,0,pre.size()){
// if(i == pre[j]){
// pre.erase(find(all(pre),pre[j]));
// ans = true;
// break;
// }
// }
// if(!ans)return false;
// }
// tr(i,wrong){
// tr(j,pre){
// if(i == j)return false;
// }
// }
return true;
}
void solve(){
string s;cin>>s;
int o = count(all(s),'o');
if(o > 4){
cout << 0 << endl;
return;
}
rep(i,0,10){
if(s[i] == 'o')must.pb(i);
if(s[i] == 'x')wrong.pb(i);
}
// cout << "must : ";
// tr(i,must)cout << i << " ";
// cout<<endl;
// cout << "wrong : ";
// tr(i,wrong)cout << i << " ";
// cout<<endl;
int ans = 0;
int tmp;
rep(i,0,hi){
tmp = ok(i);
// if(tmp){
// cout << "- " << i << endl;
// }
ans += tmp;
}
cout << ans << endl;
// int q;cin>>q;
// while(q--){
// int n;cin>>n;
// cout << (ok(n) ? yes : no ) << endl;
// }
}
int32_t main()
{
// fastio
// ios::sync_with_stdio(false);
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
solve();
return 0;
}
/*
// Sort the array in descending order
sort(arr, arr + n, greater<int>());
*/ | #include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a,i##end=b;i<=i##end;i++)
#define drep(i,a,b) for(int i=a,i##end=b;i>=i##end;i--)
inline int read() {
int x=0,f=1;char c=getchar();
while(c<48||c>57){if(c=='-')f=-1;c=getchar();}
while(c>=48&&c<=57)x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
using namespace std;
typedef long long ll;
ll k;
int n;
ll div(ll x){
if(x>=3)return x*(x-2)-x*(x-1)/2+1;
return 0;
}
ll que(ll x){
// 将x分成3个正整数方案数
return div(x)-3*div(x-n)+3*div(x-2*n)-div(x-3*n);
}
ll D(ll x){
if(x>=2)return x-1;
return 0;
}
ll q2(ll x){
return D(x)-2*D(x-n)+D(x-2*n);
}
int main() {
n=read(),scanf("%lld",&k);
int pos=-1;
rep(i,3,3e6){
if(que(i)>=k){pos=i;break;}
else k-=que(i);
}
rep(i,1,pos-2){
ll rst=q2(pos-i);
if(rst>=k){
int u=max(1,pos-i-n);
printf("%d %lld %lld\n",i,u+k-1,pos-i-(u+k-1));
return 0;
}else k-=rst;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
#include <cstdint>
#include <string>
#include <sstream>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long ll;
using P=pair<ll,ll>;
const int INF=1001001001;
const int mod=998244353;
int a[505][505],b[505][505];
void solve(){
int r,c;
cin>>r>>c;
rep(i,r){
rep(j,c-1){
cin>>a[i][j];
}
}
rep(i,r-1){
rep(j,c){
cin>>b[i][j];
}
}
priority_queue<P,vector<P>,greater<P>>q;
vector<int>dist(r*c*2,INF);
auto push=[&](int i,int j,int k,int nd){
int v=i*c*2+j*2+k;
if(dist[v]<=nd){return;}
dist[v]=nd;
q.emplace(nd,v);
};
push(0,0,0,0);
while(!q.empty()){
auto t=q.top();q.pop();
int d=t.first,v=t.second;
if(dist[v]!=d){continue;}
int i=v/(2*c),j=v/2%c,k=v%2;
if(k==0){
if(j+1<c){push(i,j+1,k,d+a[i][j]);}
if(j-1>=0){push(i,j-1,k,d+a[i][j-1]);}
if(i+1<r){push(i+1,j,k,d+b[i][j]);}
push(i,j,1,d+1);
}
else{
if(i-1>=0){push(i-1,j,1,d+1);}
push(i,j,0,d);
}
}
cout<<dist[r*c*2-2]<<endl;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
return 0;
} | #include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <limits>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
template<class T> inline int sz(T &a) { return a.size(); }
using ll = long long; using ld = long double;
using pi = pair<int,int>; using pl = pair<ll,ll>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
const int inf = numeric_limits<int>::max();
const ll infll = numeric_limits<ll>::max();
int main()
{
int a,b; cin >> a >> b;
printf("%.10Lf\n", (ld)(a-b)/a*100);
return 0;
}
|
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>
#include <cassert>
#include <random>
#include <chrono>
/* #include <atcoder/all> */
/* using namespace atcoder; */
using namespace std;
void debug_out(){ cout << "\n"; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cout << H << " ";
debug_out(T...);
}
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const ll MOD = 1000000007;
/* const ll MOD = 998244353; */
const ll INF = 1ll<<60;
const double PI = acos(-1);
struct INIT { INIT(){
cin.tie(0); ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
}}INIT;
signed main() {
int N;
cin >> N;
N *= 2;
int ans = 0;
vector<int> v;
for(int i = 1; i*i <= N; i++){
if(N%i == 0){
if(i*i != N) v.emplace_back(N/i);
v.emplace_back(i);
}
}
N /= 2;
for(auto x : v){
if((x+1)%2 == 0){
if(N%x == 0) ans++;
}else{
if((N+x/2)%x == 0) ans++;
/* cout << N << " " << x/2 << " " << N+x/2 << " " << x << "\n"; */
}
}
cout << ans << "\n";
return 0;
}
| #include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
ll n, f[200111];
ll ck[200111], step[200111];
ll dfs(ll x, ll color, ll curstep = 1) {
ck[x] = color;
step[x] = curstep;
ll nx = f[x];
if (ck[nx] == 0) {
return dfs(nx, color, curstep + 1);
}
if (ck[nx] == color) {
return curstep + 1 - step[nx];
}
return 0;
}
int main(void) {
scanf("%lld", &n);
for (ll i = 1; i <= n; i++) {
scanf("%lld", &f[i]);
}
ll t = 0;
for (ll i = 1; i <= n; i++) {
if (!ck[i]) {
ll cycle = dfs(i, i);
if (cycle) {
t++;
}
}
}
ll p = 998244353;
ll ans = 1;
for (ll i = 0; i < t; i++) {
ans *= 2;
ans %= p;
}
printf("%lld\n", ans - 1);
} |
#include <bits/stdc++.h>
#define ss second
#define ll long long
#define mod 1000000007
#define ff first
#define pb push_back
#define pll pair<ll,ll>
#define w(x) ll x; cin>>x; while(x--)
#define ps(x,y) fixed<<setprecision(y)<<x;
#define fo(i, j, k, in) for (ll i=j ; i<k ; i+=in)
#define re(i, j) fo(i, 0, j, 1)
#define pi acos(-1)
#define all(cont) cont.begin(), cont.end()
#define countbit(x) __builtin_popcount(x)
#define de(n) ll n;cin>>n;
#define def(a,n) ll n;cin>>n;ll a[n];re(i,n){cin>>a[i];}
#define defi(a,n,k) ll n;cin>>n; ll k;cin>>k;ll a[n];re(i,n){cin>>a[i];}
#define deb(x) cout<<#x<<"="<<x<<endl;
#define tr(it,a) for(auto it=a.begin();it!=a.end();it++)
#define nl cout<<endl;
using namespace std;
//18-1326D1 1208B 845C 912B 1009B 1350C 20C 1333C 1234D 1327C 1305B 1304B (or in matrix) 1216-C(26) 21
void cp()
{
ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
ll powermod(ll x, ll y,ll p)
{
int res = 1;
x = x % p;
if (x == 0) return 0;
while (y > 0)
{
if (y & 1)
res = (res*x) % p;
y = y>>1; // y = y/2
x = (x*x) % p;
}
return res;
}
int main()
{
//cp();
de(n);
de(p);
if(p==2)
{
if(n==1)
cout<<"1";
else{
cout<<"0";
}
}
else
{
ll ans=powermod(p-2,n-1,mod);
ans=((ans%mod)*((p-1)%mod))%mod;
cout<<ans;
}
} | // Problem: E - Train
// Contest: AtCoder - AtCoder Beginner Contest 192
// URL: https://atcoder.jp/contests/abc192/tasks/abc192_e
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define ll long long
#define mod 1000000007
// templates
#define all(v) v.begin(), v.end()
#define F first
#define S second
#define sz(x) (int)x.size()
#define po(x, y) fixed << setprecision(y) << x
#define ss(s) scanf(" %[^\n]%*c", s)
#define sc(n) scanf("%d", &n)
#define sl(n) scanf("%lld", &n)
#define ps(s) printf("%s\n", s)
#define pr(n) printf("%d\n", n)
#define pl(n) printf("%lld\n", n)
#define prs(n) printf("%d ", n)
#define pls(n) printf("%lld ", n)
using namespace std;
const ll inf = (ll)1e16 + 10;
const int N = (int)1e5 + 10;
int a[N], b[N];
vector<array<ll, 3>> adj[N]; // u->v,t,k
vector<ll> dist(N);
ll n, m, x, y;
void bfs() {
set<array<ll, 2>> s; // time,node
s.insert({0, x});
for (int i = 0; i <= n; i++) {
dist[i] = inf;
}
dist[x] = 0;
while (sz(s)) {
auto temp = *s.begin();
s.erase(s.begin());
ll node = temp[1], kete = temp[0];
for (auto c : adj[node]) {
ll add = 0;
if (kete < c[2] && kete != 0) {
add = (c[2] - kete);
} else if (kete != 0) {
if (kete % c[2]) {
add = c[2] - (kete % c[2]);
}
}
ll curr = c[1] + add + kete;
// printf("node-> %lld curr-> %lld\n", node, curr);
if (dist[c[0]] > curr) {
s.erase({dist[c[0]], c[0]});
dist[c[0]] = curr;
s.insert({curr, c[0]});
}
}
}
if (dist[y] == inf) {
dist[y] = -1;
}
pl(dist[y]);
}
void solve() {
sl(n), sl(m), sl(x), sl(y);
for (int i = 1; i <= m; i++) {
ll u, v, t, k;
sl(u), sl(v), sl(t), sl(k);
adj[u].push_back({v, t, k});
adj[v].push_back({u, t, k});
}
bfs();
}
int main() {
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
int t = 1;
// sc(t);
while (t--) {
solve();
}
// cerr << (float)clock() / CLOCKS_PER_SEC * 1000 << " ms" << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define FastIO() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define read() freopen("in.txt","r",stdin)
#define write() freopen("out.txt","w",stdout)
typedef long long ll;
typedef unsigned long long ull;
typedef double dbl;
typedef float flt;
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pl> vpl;
#define pie acos(-1)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define MAX 300005
#define MOD 1000000007
#define INF 1000000100
#define for0(i, n) for(ll i=0; i<n; i++)
#define for1(i, n) for(ll i=1; i<=n; i++)
#define forab(i, a, b) for(ll i=a; i<=b; i++)
#define forabx(i, a, b, x) for(ll i=a; i<=b; i+=x)
#define forinv(i, a, b) for(ll i=a; i>=b; i--)
#define clr0(a) memset(a, 0, sizeof(a))
#define ceil(x, y) (x+y-1) / (y)
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a * b) / __gcd(a, b))
#define sort1(a) sort(a+1, a+n+1)
#define debug(x) cout << "DEBUG " << x << endl;
#define Y() cout << "YES" << endl;
#define N() cout << "NO" << endl;
#define inArr(a, x, y) forab(i, x, y) { cin >> a[i]; }
#define outArr(a, x, y) forab(i, x, y) { cout << a[i] << " "; } cout << endl;
void solve() {
int n;
cin >> n;
int now = 3;
cout << 6 << " " << 10 << " " << 15 << " ";
for(int i=16; ; i+=1) {
if (i==6 || i==10 || i==15) {
continue;
}
ll dv = 0;
if (__gcd(i, 6)>1) {
dv++;
}
if (__gcd(i, 10)>1) {
dv++;
}
if (__gcd(i, 15)>1) {
dv++;
}
if (dv>2) {
cout << i << " ";
now++;
}
if (now==n) {
break;
}
}
cout << endl;
}
void testcase() {
ll t;
cin >> t;
while (t--) {
solve();
}
}
int main () {
FastIO()
//testcase();
solve();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
template<typename T = int> vector<T> create(size_t n){ return vector<T>(n); }
template<typename T, typename... Args> auto create(size_t n, Args... args){ return vector<decltype(create<T>(args...))>(n, create<T>(args...)); }
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
vector<int> good = {6, 10, 15}, ans;
for(int i = 1; i <= 10000; i++){
int g = 0;
for(int v : good) if((i % v) == 0) g = 1;
if(g)
ans.push_back(i);
}
swap(ans[2], ans[3]);
int n;
cin >> n;
for(int i = 0; i < n; i++)
cout << ans[i] << ' ';
return 0;
}
|
#define LOCAL
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
#define rep(i,s,n) for (int i = (ll)s; i < (ll)n; i++)
#define rrep(i,n,e) for (int i = (ll)n; i > (ll)e; i--)
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
// #define M_PI 3.14159265358979323846 // CF
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) cout << fixed << setprecision(10) << x << endl; // print Decimal number 10 Rank
#define endl "\n"
#define Case(x) printf("Case #%d: ", x); // gcj
typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
typedef vector<PI> vpi;
typedef vector<vector<PI>> vvpi;
typedef vector<PLL> vpl;
typedef vector<vector<PLL>> vvpl;
typedef vector<char> vch;
typedef vector<vector<char>> vvch;
constexpr ll LINF = 1001002003004005006ll;
constexpr int INF = 1002003004;
constexpr int n_max = 2e5+10;
template<class T>
inline bool chmax(T &a, T b) { if(a<b) { a=b; return true; } return false; };
template<class T>
inline bool chmin(T &a, T b) { if(a>b) { a=b; return true; } return false; };
template<class T, class U>
T POW(T x, U n) {T ret=1; while (n>0) {if (n&1) {ret*=x;} x*=x; n>>=1;} return ret;};
// debug
template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';};
string to_string(const char c) {return to_string((string) &c);};
string to_string(bool b) {return (b ? "true" : "false");};
template <size_t N>
string to_string(bitset<N> v){
string res = "";
for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
return res;
};
template <typename A>
string to_string(A v) {
bool first = true;
string res = "{";
for(const auto &x : v) {
if(!first) res += ", ";
first = false; res += to_string(x);
}
res += "}";
return res;
};
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
void debug_out() {cerr << endl;};
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); };
void LINE_OUT() {
cout << "--------------" << endl;
};
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define LINE LINE_OUT();
#else
#define debug(...) 71
#define LINE 71;
#endif
void print() { cout << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
cout << head;
if (sizeof...(tail) != 0) cout << " ";
print(forward<Tail>(tail)...);
};
template <class T>
void print(vector<T> &vec) {
for (auto& a : vec) {
cout << a;
if (&a != &vec.back()) cout << " ";
}
cout << endl;
};
template <class T>
void print(vector<vector<T>> &df) {
for (auto& vec : df) {
print(vec);
}
};
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int N; cin >> N;
vector<ll> X(N);
rep(i, 0, N) cin >> X[i];
ll m = 0;
ld y = 0.0;
ll c = 0;
rep(i, 0, N) {
m += abs(X[i]);
chmax(c, abs(X[i]));
y += (ld)abs(X[i]) * (ld)abs(X[i]);
}
y = sqrt(y);
cout << m << endl;
Decimal(y);
cout << c << endl;
return 0;
};
| #include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<ll, ll>;
// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; debug_print(__VA_ARGS__); } while(false)
template<typename T, typename... Ts> void debug_print(const T &t, const Ts &...ts) { cerr << t; ((cerr << ", " << ts), ...); cerr << endl; }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, const T& b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, const T& b) { if (a < b) {a = b; return true; } return false; }
template<typename T, typename... Ts> void print(const T& t, const Ts&... ts) { cout << t; ((cout << ' ' << ts), ...); cout << '\n'; }
template<typename... Ts> void input(Ts&... ts) { (cin >> ... >> ts); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n, m;
input(n, m);
vector<vector<int>> graph(n);
rep(i, 0, m) {
int a, b;
input(a, b);
graph[a - 1].push_back(b - 1);
}
vector<bool> used(n, false);
auto dfs = [&](auto &f, int v) -> void {
if (used[v]) return;
used[v] = true;
for (auto nv : graph[v]) {
f(f, nv);
}
};
int ans = 0;
rep(i, 0, n) {
used.assign(n, false);
dfs(dfs, i);
rep(j, 0, n) {
ans += used[j];
}
}
print(ans);
return 0;
}
|
#include <iostream>
#include <vector>
#include <string>
#include <array>
using namespace std;
string s, t;
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n; cin >> n >> s >> t;
vector<array<int, 7>> dp(n + 1);
for (int i = 0; i < 7; i++) dp[n][i] = (i != 0);
for(int i = n - 1; i >= 0; i--)
for (int j = 0; j < 7; j++) {
if (t[i] == 'A') {
if (dp[i + 1][(j * 10) % 7]) { dp[i][j] = 1; continue; }
if (dp[i + 1][(j * 10 + s[i] - '0') % 7]) { dp[i][j] = 1; continue; }
dp[i][j] = 0;
}
else {
if (!dp[i + 1][(j * 10) % 7]) { dp[i][j] = 0; continue; }
if (!dp[i + 1][(j * 10 + s[i] - '0') % 7]) { dp[i][j] = 0; continue; }
dp[i][j] = 1;
}
}
cout << (dp[0][0] ? "Aoki" : "Takahashi") << '\n';
cin.ignore(2); return 0;
} | #include <bits/stdc++.h>
#ifdef LILY
#include "./Debug.h"
#else
#define var(...) (0)
#define dbg(...) (0)
#endif
using int32 = int;
using int64 = long long;
using namespace std;
class Solution
{
#define int int32
#define sfor(i, n) for (int i = 1; i <= (n); ++i)
#define tfor(i, n) for (int i = 0; i < (n); ++i)
int n;
string s, x;
// dp[i] is a set including the numbers which Takahashi wants the remainder of the current number divided by 7 to be after the appending i digits.
vector<int> dp;
void SHURU()
{
cin >> n;
cin >> s >> x;
dp = vector<int>(n + 1, 0);
dp[n] = 1;
}
void SHUCHU()
{
cout << ((dp[0] & 1) ? "Takahashi\n" : "Aoki\n");
}
int Tmove(int ap, int tars)
{
dbg(var(ap));
int ret = 0, d, e;
for (int i = 0; i < 10; ++i)
{
d = (3 * i + ap) % 7;
e = (3 * i) % 7;
if ((tars & (1 << d)) || (tars & (1 << e)))
{
ret |= (1 << i);
dbg(var(d), var(tars));
}
}
return ret;
}
int Amove(int ap, int tars)
{
dbg(var(ap));
int ret = 0, d, e;
for (int i = 0; i < 10; ++i)
{
d = (3 * i + ap) % 7;
e = (3 * i) % 7;
if ((tars & (1 << d)) && (tars & (1 << e)))
{
ret |= (1 << i);
dbg(var(d), var(e), var(tars));
}
}
return ret;
}
void CHULI()
{
for (int i = n - 1; i >= 0; i--)
{
switch (x[i])
{
case 'T':
dp[i] = Tmove(s[i] - 48, dp[i + 1]);
break;
case 'A':
dp[i] = Amove(s[i] - 48, dp[i + 1]);
break;
default: dbg("WTF, ", var(x[i]));
break;
}
dbg(var(i), var(dp[i]));
}
}
public:
Solution()
{
SHURU();
CHULI();
SHUCHU();
}
#undef int
#undef tfor
#undef sfor
};
int32 main()
#ifndef LILY
{
Solution();
}
#endif
|
#include <bits/extc++.h>
using namespace std;
using ll = long long;
#define REP(i,n) for(int i=0;i<int(n);i++)
#define FOR(i,a,b) for(int i=a;i<=int(b);i++)
#define ALL(x) x.begin(),x.end()
#define MOD (ll)1000000007
vector<vector<int>> pass;
vector<vector<int>> tour;
vector<pair<int, int>>inout;
int depth = 0;
int pcount = 0;
void dfs(int now){
inout[now].first = pcount;
tour[depth].emplace_back(pcount);
depth ++;
pcount ++;
for(int ver: pass[now]){
dfs(ver);
}
depth --;
pcount ++;
inout[now].second = pcount;
}
signed main() {
int n;
cin >> n;
pass.resize(n);
tour.resize(n);
inout.resize(n);
int p;
for(int i = 1; i < n; i++){
cin >> p;
p--;
pass[p].emplace_back(i);
}
dfs(0);
REP(i, n){
sort(tour[i].begin(), tour[i].end());
}
int q;
cin >> q;
int u, d;
REP(i, q){
cin >> u >> d;
u--;
auto in = lower_bound(tour[d].begin(), tour[d].end(), inout[u].first);
auto out = lower_bound(tour[d].begin(), tour[d].end(), inout[u].second);
cout << out - in <<endl;
}
return 0;
} | #include<bits/stdc++.h>
using namespace std;
const int mod=998244353;
int add(int a,int b) {return a+b>=mod?a+b-mod:a+b;}
int dec(int a,int b) {return a<b?a+mod-b:a-b;}
int mul(int a,int b) {return 1ll*a*b%mod;}
void Add(int &a,int b) {(a+=b)>=mod?a-=mod:0;}
void Dec(int &a,int b) {(a-=b)<0?a+=mod:0;}
void Mul(int &a,int b) {a=1ll*a*b%mod;}
int pw2[303];
int c[303][303];
int f[303],g[303];
int a[200503];
int re(){
int i=0,f=1;
char c=getchar();
for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
for(;isdigit(c);c=getchar()) i=(i<<3)+(i<<1)+c-'0';
return i*f;
}
int main(){
c[0][0]=1;
for(int i=1;i<=300;++i){
c[i][0]=1;
for(int j=1;j<=i;++j) c[i][j]=add(c[i-1][j-1],c[i-1][j]);
}
pw2[0]=1;
for(int i=1;i<=300;++i) pw2[i]=add(pw2[i-1],pw2[i-1]);
int n=re(),m=re();
for(int i=1;i<=n;++i) a[i]=re();
int inv2=mod-mod/2;
for(int i=1;i<=n;++i){
int buf=1;
for(int j=0;j<=m;++j){
Add(f[j],buf);
Mul(buf,a[i]);
}
}
for(int i=1;i<=m;++i){
for(int j=0;j<=i;++j){
Add(g[i],mul(mul(f[j],f[i-j]),c[i][j]));
}
Dec(g[i],mul(f[i],pw2[i]));
Mul(g[i],inv2);
cout<<g[i]<<endl;
}
} |
//------------------------------------------
// C++ templete
//------------------------------------------
#include <bits/stdc++.h>
#define lint long long int
using namespace std;
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;
//REPEAT
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
//container util
//------------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define PRINT(V) for (auto v : (V)) cout << v << " "
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
//constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
//math
//------------------------------------------
int QP(int a,int b){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int QP(int a,int b,int MOD){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int GCD(int a,int b){return b?GCD(b,a%b):a;}
//grobal variable
//------------------------------------------
int N,M;
VI Vec;
//main
//------------------------------------------
int vector_finder(std::vector<lint> vec, lint number) {
auto itr = std::find(vec.begin(), vec.end(), number);
size_t index = std::distance( vec.begin(), itr );
if (index != vec.size()) { // 発見できたとき
return 1;
}
else { // 発見できなかったとき
return 0;
}
}
int main(){
lint t,n;
cin >> t >> n;
n--; // 0から数えるため
vector<lint> x,y;
for(lint i=1;i<=100+t;i++){
lint tmp = i*(100+t);
tmp /=100;
x.push_back(tmp);
}
for(lint i=1;i<=100+t;i++){
if( !vector_finder(x,i)){
y.push_back(i);
}
}
lint n_t = n/y.size();
lint cnt = (100 + t) * n_t + y[n%y.size()];
cout << cnt << endl;
} | //#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
//#include <immintrin.h>
//#include <emmintrin.h>
#include <bits/stdc++.h>
using namespace std;
#define rep(i,h,t) for (int i=h;i<=t;i++)
#define dep(i,t,h) for (int i=t;i>=h;i--)
#define ll long long
#define me(x) memset(x,0,sizeof(x))
#define IL inline
#define rint register int
inline ll rd(){
ll x=0;char c=getchar();bool f=0;
while(!isdigit(c)){if(c=='-')f=1;c=getchar();}
while(isdigit(c)){x=(x<<1)+(x<<3)+(c^48);c=getchar();}
return f?-x:x;
}
char ss[1<<24],*A=ss,*B=ss;
IL char gc()
{
return A==B&&(B=(A=ss)+fread(ss,1,1<<24,stdin),A==B)?EOF:*A++;
}
template<class T>void maxa(T &x,T y)
{
if (y>x) x=y;
}
template<class T>void mina(T &x,T y)
{
if (y<x) x=y;
}
template<class T>void read(T &x)
{
int f=1,c; while (c=gc(),c<48||c>57) if (c=='-') f=-1; x=(c^48);
while(c=gc(),c>47&&c<58) x=x*10+(c^48); x*=f;
}
const int mo=1e9+7;
ll fsp(int x,int y)
{
if (y==1) return x;
ll ans=fsp(x,y/2);
ans=ans*ans%mo;
if (y%2==1) ans=ans*x%mo;
return ans;
}
struct cp {
ll x,y;
cp operator +(cp B)
{
return (cp){x+B.x,y+B.y};
}
cp operator -(cp B)
{
return (cp){x-B.x,y-B.y};
}
ll operator *(cp B)
{
return x*B.y-y*B.x;
}
int half() { return y < 0 || (y == 0 && x < 0); }
};
struct re{
int a,b,c;
};
const int N=6e5;
char s[N],t[N];
vector<int> v1,v2;
int main()
{
// freopen("1.in","r",stdin);
// freopen("1.out","w",stdout);
ios::sync_with_stdio(false);
int n;
cin>>n;
cin>>(s+1)>>(t+1);
rep(i,1,n)
if (s[i]-'0'==0) v1.push_back(i);
rep(i,1,n)
if (t[i]-'0'==0) v2.push_back(i);
if (v1.size()!=v2.size())
{
cout<<-1<<endl; return 0;
}
int m=v1.size();
int cnt=0;
rep(i,1,m) if (v1[i-1]!=v2[i-1]) cnt++;
cout<<cnt<<endl;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;typedef double db;
typedef pair<int, int> pii;typedef pair<ll, ll> pll;
typedef pair<int,ll> pil;typedef pair<ll,int> pli;
#define Fi first
#define Se second
#define _Out(a) cerr<<#a<<" = "<<(a)<<endl
const int INF = 0x3f3f3f3f, MAXN = 1e2 + 3,MAXV=1e3+4;
const ll LINF = 0x3f3f3f3f3f3f3f3f;ll MOD = 998244353;
const db Pi = acos(-1), EPS = 1e-6;
void test(){cerr << "\n";}template<typename T,typename...Args>void test(T x,Args...args){cerr<<x<<" ";test(args...);}
inline ll qpow(ll a, ll b){return b?((b&1)?a*qpow(a*a%MOD,b>>1)%MOD:qpow(a*a%MOD,b>>1))%MOD:1;}
inline ll qpow(ll a, ll b,ll c){return b?((b&1)?a*qpow(a*a%c,b>>1,c)%c:qpow(a*a%c,b>>1,c)) %c:1;}
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline ll cede(ll a,ll b){if(b<0)return cede(-a,-b);if(a<0)return a/b;return (a+b-1)/b;}
inline ll flde(ll a,ll b){if(b<0)return flde(-a,-b);if(a<0)return (a-b+1)/b;return a/b;}
inline int sign(db x){return x<-EPS ? -1:x>EPS;}
inline int dbcmp(db l,db r){return sign(l - r);}
namespace Fast_IO{ //orz laofu
const int MAXL((1 << 18) + 1);int iof, iotp;
char ioif[MAXL], *ioiS, *ioiT, ioof[MAXL],*iooS=ioof,*iooT=ioof+MAXL-1,ioc,iost[55];
char Getchar(){
if (ioiS == ioiT){
ioiS=ioif;ioiT=ioiS+fread(ioif,1,MAXL,stdin);return (ioiS == ioiT ? EOF : *ioiS++);
}else return (*ioiS++);
}
void Write(){fwrite(ioof,1,iooS-ioof,stdout);iooS=ioof;}
void Putchar(char x){*iooS++ = x;if (iooS == iooT)Write();}
inline int read(){
int x=0;for(iof=1,ioc=Getchar();(ioc<'0'||ioc>'9')&&ioc!=EOF;)iof=ioc=='-'?-1:1,ioc=Getchar();
if(ioc==EOF)Write(),exit(0);
for(x=0;ioc<='9'&&ioc>='0';ioc=Getchar())x=(x<<3)+(x<<1)+(ioc^48);return x*iof;
}
inline long long read_ll(){
long long x=0;for(iof=1,ioc=Getchar();(ioc<'0'||ioc>'9')&&ioc!=EOF;)iof=ioc=='-'?-1:1,ioc=Getchar();
if(ioc==EOF)Write(),exit(0);
for(x=0;ioc<='9'&&ioc>='0';ioc=Getchar())x=(x<<3)+(x<<1)+(ioc^48);return x*iof;
}
void Getstr(char *s, int &l){
for(ioc=Getchar();ioc==' '||ioc=='\n'||ioc=='\t';)ioc=Getchar();
if(ioc==EOF)Write(),exit(0);
for(l=0;!(ioc==' '||ioc=='\n'||ioc=='\t'||ioc==EOF);ioc=Getchar())s[l++]=ioc;s[l] = 0;
}
template <class Int>void Print(Int x, char ch = '\0'){
if(!x)Putchar('0');if(x<0)Putchar('-'),x=-x;while(x)iost[++iotp]=x%10+'0',x/=10;
while(iotp)Putchar(iost[iotp--]);if (ch)Putchar(ch);
}
void Putstr(const char *s){for(int i=0,n=strlen(s);i<n;++i)Putchar(s[i]);}
} // namespace Fast_IO
using namespace Fast_IO;
int dp[MAXN][MAXN*MAXN*MAXN];
void work()
{
int n=read(),k=read();MOD=read();
dp[0][0]=1;int UPD=n*(n+1)/2*k;
for(int i=1;i<=n;i++)
{
for(int j=0;j<i;j++)
{
ll sum=0;
for(int now=j;now<=UPD;now+=i)
{
sum=(sum+dp[i-1][now])%MOD;
if(now>=i*(k+1))sum=(sum-dp[i-1][now-i*(k+1)]+MOD)%MOD;
dp[i][now]=sum;
}
}
}
for(int x=1;x<=n;x++)
{
ll ans=0;
for(int i=0;i<=UPD;i++)ans=(ans+1ll*dp[x-1][i]*dp[n-x][i]%MOD*(k+1)%MOD)%MOD;
printf("%lld\n",(ans-1+MOD)%MOD);
}
}
int main()
{
//std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//int T=read();for(int cas=1;cas<=T;cas++)
//int T;scanf("%d",&T);for(int i=1;i<=T;i++)
work();
// Write();
}
/**
4
-1 1
-1 -1
-1 -1
-1 -1
4
3 5
-1 -1
-1 -1
-1 -1
-1 -1
4
1 -1
2 -1
6 -1
-1 7
3
2 -1
-1 3
5 6
*/ | #include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
const int N = 100 + 5;
int mod, k, dp[N][N], a[N];
string s;
int add(int a, int b){
return (a + b) % mod;
}
int mul(int a, int b){
return 1ll * a * b % mod;
}
int fp(int b, int p){
if(p == 0) return 1;
int ret = fp(b, p >> 1);
ret = mul(ret, ret);
if(p & 1) ret = mul(ret, b);
return ret;
}
int beats(int a, int b){
if(a == b) return a;
if((a + 1) % 3 == b) return b;
return a;
}
int solve(int idx, int k){
if(k == 0) return a[idx];
if(dp[idx][k] != -1) return dp[idx][k];
int l = solve(idx, k - 1);
int r = solve(add(idx, fp(2, k - 1)), k - 1);
return dp[idx][k] = beats(l, r);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> mod >> k >> s;
for(int i = 0; i < mod; i++){
if(s[i] == 'P') a[i] = 1;
else if(s[i] == 'S') a[i] = 2;
}
memset(dp, -1, sizeof dp);
int ans = solve(0, k);
if(ans == 0) cout << 'R';
else if(ans == 1) cout << 'P';
else cout << 'S';
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,f,n) for(ll i=(f); (i) < (n); i++)
#define repe(i,f,n) for(ll i=(f); (i) <= (n); i++)
#define repc(i,f,n) for(char i=(f); (i) <= (n); i++)
#define PI 3.14159265358979323846264338327950ll
#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
#define Pl pair<ll, ll>
#define dvec vector<vector<ll>>
#define OUT(x) cout << x << endl; return 0;
//printf("%.10f\n")
//cout << fixed << setprecision(10);
template<class T> inline bool chmax(T& a, T b){if (a < b) { a = b; return true; } return false;}
template<class T> inline bool chmaxe(T& a, T b){if (a <= b) { a = b; return true; } return false;}
template<class T> inline bool chmin(T& a, T b){if (a > b) { a = b; return true; } return false;}
const ll MOD = 1000000007ll;
const ll INF = 1e+18;
const int iINF = 1e9;
const double EPS = 1e-8;
int
main()
{
double A, B; cin >> A >> B;
cout << (A / 100) * B << endl;
} | #include<bits/stdc++.h>
#include<cmath>
#define pb push_back
#define ld long double
#define mp make_pair
#define vl vector<ll>
#define vd vector<double>
#define vld vector<long double>
#define ll long long int
#define pl pair<ll, ll>
#define all(a) a.begin(), a.end()
#define forr(i, n) for(ll i=0; i<n; i++)
#define forr1(i, n) for(ll i=1; i<=n; i++)
using namespace std;
const ld PI =3.1415926535897923846;
const ll MOD = 1000000007;
const ll N=998244353;
ll power(ll x,ll n){ll res=1;while(n>0){if(n&1) res=res*x%MOD;x=x*x%MOD;n>>=1;}return res;}
ll modinverse(ll a){return power(a, MOD-2);}
void solve()
{
ll x, y, a, b;
cin>>x>>y>>a>>b;
// check when it's optimal to use b instead of a
// when b>=x
ll ans=0;
while(x<b/a)
{
ans++;
x*=a;
if(x>=y)
{
cout<<ans-1<<endl;
return;
}
}
//x/=a;
//ans--;
ll rem=max((ll)0, y-x);
ans+=((rem/b));
if(rem%b==0)
ans--;
cout<<ans<<endl;
}
int main()
{
#ifndef ONLINE_JUDGE
// for getting input from input.txt
freopen("input.txt", "r", stdin);
// for writing output to output.txt
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll test=1;
//cin>>test;
while(test--)
{
solve();
}
cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
} |
#include <bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//#include <atcoder/all>
using namespace std;
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a; i > -1; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a; i > b; --i)
#define repl(i, a) for (ll i = (ll)0; i < (ll)a; ++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll
#define fi first
#define se second
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll mod_998244353 = 998244353;
constexpr ll INF = 1LL << 60;
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
// using lll=boost::multiprecision::cpp_int;
// using
// Double=boost::multiprecision::number<boost::multiprecision::cpp_dec_float<128>>;//仮数部が1024桁
template <class T>
inline bool chmin(T &a, T b)
{
if (a > b)
{
a = b;
return true;
}
return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
if (a < b)
{
a = b;
return true;
}
return false;
}
ll mypow(ll x, ll n, const ll &p = -1)
{ // x^nをmodで割った余り
if (p != -1)
{
x = (x % p + p) % p;
}
ll ret = 1;
while (n > 0)
{
if (n & 1)
{
if (p != -1)
ret = (ret * x) % p;
else
ret *= x;
}
if (p != -1)
x = (x * x) % p;
else
x *= x;
n >>= 1;
}
return ret;
}
struct myrand{
random_device seed;
mt19937 mt;
myrand():mt(seed()){}
int operator()(int a,int b){//[a,b)
uniform_int_distribution<int>dist(a,b-1);
return dist(mt);
}
};
// using namespace atcoder;
//------------------------
//------------------------
//------------------------
//------------------------
//------------------------
using P=pair<int,int>;
void solve()
{
int n,m;
cin>>n>>m;
vector<int>x(m),y(m);
map<int,int>mp;
rep(i,m){
cin>>x[i]>>y[i];
if(!mp.count(x[i])){
mp[x[i]]=mp.size();
}
}
vector<set<int>>row(mp.size()+5);
rep(i,m){
row[mp[x[i]]].emplace(y[i]);
}
unordered_set<int>ans;
ans.emplace(n);
for(auto &e:mp){
set<int>add,sub;
for(auto &ee:row[e.se]){
if(ans.count(ee-1)||ans.count(ee+1)){
add.emplace(ee);
}else if(ans.count(ee)){
sub.emplace(ee);
}
}
for(auto &ee:sub)ans.erase(ee);
for(auto &ee:add)ans.emplace(ee);
}
cout<<ans.size()<<"\n";
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(15);
solve();
return 0;
} | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll N=1e6+5,inf=1e18,mod=1e9+7;
#define test ll testcases;cin>>testcases; while(testcases--)
#define pb push_back
#define mp make_pair
#define pf push_front
#define ff first
#define ss second
#define vll vector<ll>
#define vld vector<ld>
#define pll pair<ll,ll>
#define ppll pair<ll,pair<ll,ll>>
#define pld pair<ld,ld>
#define vpll vector<pll>
#define vpld vector<pld>
#define all(X) X.begin(),X.end()
#define sz(x) ((ll)((x).size()))
const ld pi=3.141592653589793238;
bool check_prime(ll n)
{
ll flag=0,i;
for(i=2;i*i<=n;i++)
{
if(n%i==0)
{
flag=1;
break;
}
}
if(n==1)
{
return false;
}
else if(flag==0 || n==2 || n==3)
{
return true;
}
else
{
return false;
}
}
ll fastexpo(ll a,ll b,ll MOD)
{
ll result=1;
while(b>0)
{
if(b%2==1)
{
result=(result*a)%MOD;
}
a=(a*a)%MOD;
b=b/2;
}
return result;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n,x,i;
cin>>n>>x;
char str[n+1]={'\0'};
cin>>str;
for(i=0;i<strlen(str);i++)
{
if(str[i]=='o')
{
x++;
}
else
{
if(x!=0)
{
x--;
}
}
}
cout<<x<<"\n";
return 0;
} |
#include <sys/time.h>
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll = int64_t;
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define rep(i, n) FOR(i, 0, n)
template <class T, class U>
bool chmax(T &a, const U &b) {
return a < b ? a = b, true : false;
}
template <class T, class U>
bool chmin(T &a, const U &b) {
return b < a ? a = b, true : false;
}
constexpr int INF = 1000000003;
constexpr ll LINF = 1000000000000000003;
constexpr int BEAM_SIZE = 10000;
constexpr int N = 50;
int tile[50][50];
int board[50][50];
int dirx[4] = {1, -1, 0, 0}, diry[4] = {0, 0, 1, -1};
char op[4] = {'D', 'U', 'R', 'L'};
inline bool in_board(int x, int y) {
return x >= 0 && x < N && y >= 0 && y < N;
}
struct beam_search {
struct State {
int px, py;
int score;
bitset<2048> is_used;
string ops;
State(int _px, int _py) : px(_px), py(_py), score(), is_used() {
score += board[px][py];
is_used.set(tile[px][py]);
}
bool operator<(const State &rhs) const { return eval() < rhs.eval(); }
bool operator>(const State &rhs) const { return rhs < *this; }
int eval() const { return score; }
void update_score(int row) {}
void _place(int dir) {
px += dirx[dir];
py += diry[dir];
score += board[px][py];
is_used.set(tile[px][py]);
ops.push_back(op[dir]);
}
State place(int dir) {
State res(*this);
res._place(dir);
return res;
}
bool is_place(int dir) {
int x = px + dirx[dir];
int y = py + diry[dir];
return in_board(x, y) && !is_used[tile[x][y]];
}
string answer() const {
return ops;
}
};
string solve(int sx, int sy) {
priority_queue<State> cur, nxt;
cur.push(State(sx, sy));
State res(sx, sy);
while (!cur.empty() && (double)clock() / CLOCKS_PER_SEC < 1.95) {
while (!nxt.empty()) nxt.pop();
while (!cur.empty()) {
State now = cur.top();
cur.pop();
if (cur.empty()) chmax(res, now);
for (int dir = 0; dir < 4; ++dir) {
if (!now.is_place(dir))
continue;
State s = now.place(dir);
if (nxt.size() < BEAM_SIZE || s.eval() > nxt.top().eval())
nxt.push(s);
if (nxt.size() > BEAM_SIZE) nxt.pop();
}
}
swap(cur, nxt);
}
cerr << res.eval() << endl;
return res.answer();
}
};
int main(void) {
int sx, sy;
cin >> sx >> sy;
rep(i, N) {
rep(j, N) cin >> tile[i][j];
}
rep(i, N) {
rep(j, N) cin >> board[i][j];
}
beam_search solver;
cout << solver.solve(sx, sy) <<endl;
return 0;
}
| //#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(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; }
int main() {
ll N; cin>>N;
vector<ll> A(N);
rep(i, N) cin>>A[i];
int n = N-1;
ll res = -1;
for (int bit = 0; bit < (1<<n); ++bit) {
ll xxor = 0;
queue<ll> oor;
oor.push(A[0]);
for (int ii = 0; ii < n; ++ii) {
if (bit & (1 << ii)) {
ll o = 0;
while(!oor.empty()){
o |= oor.front();
oor.pop();
}
xxor ^= o;
}
oor.push(A[ii+1]);
}
ll o = 0;
while(!oor.empty()){
o |= oor.front();
oor.pop();
}
xxor ^= o;
if(res == -1) res = xxor;
else chmin(res, xxor);
}
cout << res << endl;
} |
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
#define rep(i, N) for (int i = 0; i < N; i++)
#define repi(i, ini, N) for(int i = ini; i < N; i++)
#define chmax(i, j) i = max(i, j)
#define chmin(i, j) i = min(i, j)
typedef long long ll;
ll N;
ll K;
int main() {
cin >> N >> K;
vector<pair<ll, ll> > A;
rep(i, N) {
ll a, b;
cin >> a >> b;
A.push_back(make_pair(a,b));
}
sort(A.begin(), A.end());
ll now = 0;
rep(i, N) {
if (A[i].first > now+K) {
cout << now+K << endl;
return 0;
}
K = K - (A[i].first-now);
now = A[i].first;
K += A[i].second;
}
cout << now + K << endl;
} | #include <bits/stdc++.h>
#define REP(i, N) for (int i = 0; i < (int)N; i++)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
using namespace std;
int main() {
int N;
cin >> N;
vector<int> used(2 * N);
auto out = []() {
cout << "No" << endl;
exit(0);
};
REP(i, N) {
int A, B;
cin >> A >> B;
if (A != -1 && B != -1 && A >= B) out();
if (A != -1) {
if (used[A - 1] != 0) out();
used[A - 1] = i + 1;
}
if (B != -1) {
if (used[B - 1] != 0) out();
used[B - 1] = -(i + 1);
}
}
vector<bool> dp(N + 1);
dp[0] = 1;
FOR(i, 1, N + 1) {
REP(j, i)
if (dp[j]) {
bool ng = 0;
REP(k, i - j) {
int a = used[2 * j + k], b = used[2 * j + k + i - j];
ng |= (a < 0) || (b > 0) || (a > 0 && b < 0 && b != -a);
}
if (!ng) {
dp[i] = 1;
break;
}
}
}
cout << (dp[N] ? "Yes" : "No") << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
using Graph = vector<vector<ll>>;
const ll INF = 1LL << 60;
const double pi = acos(-1);
ll mod = 1000000007;
//
struct Edge {
int to;
long long w;
Edge(int to, long long w) : to(to), w(w) {}
};
// Union find
struct dsu {
vector<int> d;
dsu(int n = 0): d(n,-1) {}
int findRoot(int x) {
if(d[x] < 0) return x;
return d[x] = findRoot(d[x]);
}
bool unite(int x,int y) {
x = findRoot(x); y = findRoot(y);
if(x == y) return false;
if(d[x] > d[y]) swap(x,y);
d[x] += d[y];
d[y] = x;
return true;
}
bool same(int x,int y) { return findRoot(x) == findRoot(y);}
int size(int x) {return -d[findRoot(x)];}
};
#include <iostream>
using namespace std;
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
long long res = 1;
while (n > 0) {
if (n & 1) res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
// a^{-1} mod を計算する
long long modinv(long long a, long long mod) {
return modpow(a, mod - 2, mod);
}
/*
long long modinv(long long a, long long m) {
long long b = m, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b; swap(a, b);
u -= t * v; swap(u, v);
}
u %= m;
if (u < 0) u += m;
return u;
}
*/
template <typename T>
T my_lower_bound(vector<T> a, T lb, T ub, T k) {
while(ub - lb > 1) {
T mid = (lb + ub) / 2;
if(a[mid] >= k) {
ub = mid;
}else{
lb = mid;
}
}
return ub;
}
//change a large letter into a small letter
char chupper(char a) {
a += ('A' - 'a');
return a;
}
//change a small letter into a large letter
char chlower(char a) {
a += ('a' - 'A');
return a;
}
template <class T> void chmin(T &a, T b){
if(a > b){
a = b;
}
}
template <class T> void chmax(T &a, T b){
if(a < b){
a = b;
}
}
int main() {
ll n; int m;
cin >> n >> m;
cout << modpow(10,n,m * m) / m % m << endl;
return 0;
}
| /*
* @Author: kabbo
* @Date: 2020-06-24 08:40:07
* @Last Modified by: kabbo
* @Last Modified time: 2020-06-24 08:49:58
*/
#include<bits/stdc++.h>
using namespace std;
#define pii pair<long long,long long>
#define endl '\n'
#define ull unsigned long long
#define ll int64_t
#define ar array
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0200r0.html
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));
}
const int mod = 1e9 + 7;
using u64 = uint64_t;
using u128 = __uint128_t;
#define sc1(x) scanf("%lld",&(x));
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
int dp[1005][1005];
vector<int>a,b;
int sol(int i,int j){
if (i == -1 and j == -1)return 0;
if (i == -1)return j + 1;
if (j == -1)return i + 1;
int &ret = dp[i][j];
if (ret != -1)return ret;
int op1 = sol(i - 1, j) + 1;
int op2 = sol(i, j - 1) + 1;
int op3 = sol(i - 1, j - 1) + (a[i] != b[j]);
return ret = min({op1, op2, op3});
}
void solve() {
int n, m;
cin >> n >> m;
a.resize(n),b.resize(m);
for (auto& x : a)cin >> x;
for (auto& x : b)cin >> x;
memset(dp, -1, sizeof(dp));
cout<<sol(n-1,m-1)<<endl;
// auto res = y_combinator([&](auto sol, int i, int j)->int {
//
// })(n-1,m-1);
// cout<<res<<endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
/*int t;
cin >> t;
for (int i(1); i <= t; ++i) {
printf("Case %d:\n", i);*/
solve();
//}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int main(){
char s, t;
cin >> s >> t;
if(s == 'Y'){
if(t == 'a'){
cout << "A";
}else if(t == 'b'){
cout << "B";
}else{
cout << "C";
}
}else{
cout << t;
}
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
string S,T;
cin>>S>>T;
if(S=="Y"){
if(T=="a"){
T = "A";
}
if(T=="b"){
T = "B";
}
if(T=="c"){
T = "C";
}
}
cout<<T<<endl;
} |
#include<bits/stdc++.h>
using namespace std;
#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=(b-1); i>=(a); i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back
using ll = long long;
using D = double;
using LD = long double;
using P = pair<int, int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int main(){
int m,h; cin >> m >> h;
if(h % m == 0) cout << "Yes" << endl;
else cout << "No" << endl;
}
| #include<bits/stdc++.h>
using namespace std;
int main(){
int m,h;
cin >> m >> h;
if (h%m==0){
cout << "Yes" << endl;
}
else{
cout << "No" << endl;
}
}
|
//#include<bits/stdc++.h>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<cstring>
#include<string>
#include<set>
//#include<unordered_map>
using namespace std;
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define dep(i,b,a) for(int i=b;i>=a;i--)
#define m_p make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define pi acos(-1)
#define IO ios::sync_with_stdio(false);cin.tie(0)
#define io ios::sync_with_stdio(false)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll>pll;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
const double eps=1e-9;
inline int gcd(int a,int b){return b?gcd(b,a%b):a;}
inline int lcm(int a,int b){return a*b/gcd(a,b);}
inline int rd()
{
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;
}
const int maxn=1e5+50;
void run()
{
int a, b, c;
cin >> a >> b >> c;
cout << 21 - a - b - c << endl;
}
int main()
{
run();
return 0;
}
/*
start time:
over time:
*/
| #include<bits/stdc++.h>
using namespace std;
//#include<atcoder/all>
//using namespace atcoder;
using ll = long long;
#define For(i,n,k) for(int i=(n);i<(k);i++)
#define ALL(a) (a).begin(),(a).end()
struct edge{
int to;
char c;
};
void Main(){
int n, m;
cin >> n >> m;
vector<vector<edge>> graph(n);
For(i,0,m){
int a, b;
char c;
cin >> a >> b >> c;
a--;
b--;
graph[a].push_back({b, c});
if(a != b) graph[b].push_back({a, c});
}
vector<vector<int>> exGraph(n * n);
For(i,0,n){
For(j,0,n){
for(auto [to1, c1]: graph[i]){
for(auto [to2, c2]: graph[j]){
if(c1 == c2){
exGraph[i * n + j].push_back(to1 * n + to2);
}
}
}
}
}
vector<int> dist(n * n, 1e9);
dist[n - 1] = 0;
queue<int> que;
que.push(n - 1);
while(!que.empty()){
auto now = que.front();
que.pop();
for(auto to: exGraph[now]){
if(dist[to] > dist[now] + 1){
dist[to] = dist[now] + 1;
que.push(to);
}
}
}
int ans = 1e9;
For(i,0,n){
ans = min(ans, dist[i * n + i] * 2);
for(auto [to, c]: graph[i]){
ans = min(ans, dist[i * n + to] * 2 + 1);
}
}
if(ans == 1e9) ans = -1;
cout << ans << endl;
}
int main(){
Main();
/*
東方風神録は神が出てくるので当然神ゲー
*/
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pll;
#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(40)
const ll MOD = 1000000007;
const ll INF = (ll) 1e15;
ll N;
ll A[200005];
ll T[200005];
ll func(ll value, ll index) {
if (T[index] == 1) {
return value + A[index];
}
else if (T[index] == 2) {
return std::max(value, A[index]);
}
return std::min(value, A[index]);
}
ll calc(ll value) {
REP(i, N) {
value = func(value, i);
}
return value;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> N;
REP(i, N) {
cin >> A[i] >> T[i];
}
ll low = calc(-INF);
ll heigh = calc(INF);
ll sum = 0;
REP(i, N) {
if (T[i] == 1)
sum += A[i];
}
ll Q;
cin >> Q;
REP(i, Q) {
ll x;
cin >> x;
if (x < low - sum)
cout << low << endl;
else if (heigh - sum < x)
cout << heigh << endl;
else
cout << x + sum << endl;
}
return 0;
} | #include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <math.h>
#include <map>
#include <queue>
#include <set>
#define say(s) cout << s << endl
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define vec vector
using namespace std;
using ll = long long int;
using P = pair<int, int>;
int main() {
int a1, a2, a3;
int a[3] = {0};
rep(i, 3) {
int b;
cin >> b;
a[i] = b;
}
for(int i=0; i<3; i++) {
for(int j=0; j<3; j++) {
for(int k=0; k<3; k++) {
if(i!=j && i!=k && j!=k) {
if(a[k]-a[j] == a[j] - a[i]) {
say("Yes");
return 0;
}
}
}
}
}
say("No");
return 0;
}
|
#include <bits/stdc++.h>
// clang-format off
using namespace std; using ll = long long; const ll INF = 9e18;
void print() { cout << endl; }
template<typename Head,typename... Tail> void print(Head head,Tail... tail){cout<<head;if(sizeof...(Tail)>0)cout<<" ";print(tail...);}
void print0() {}
template<typename Head,typename... Tail> void print0(Head head,Tail... tail){cout<<head;print0(tail...);}
// clang-format on
int main() {
int n;
string s;
cin >> n;
vector<char> atcoder={'a','t','c','o','d','e','r'};
for (int i = 0; i < n; i++) {
cin >> s;
int lg = -1;
int gta = 4000;
int gtt = 4000;
for (int j = 0; j < s.length(); j++) {
if (j<=6 && lg==-1 && s.at(j)>atcoder.at(j) ) lg = 1;
if (j<=6 && lg==-1 && s.at(j)<atcoder.at(j) ) lg = 0;
if (j>=7 && lg==-1) lg = 1;
if (s.at(j)>'a') gta=min(gta,j);
if (s.at(j)>'t') gtt=min(gtt,j);
}
if(lg==1){
print(0);
}else if (gtt<4000){
print(min(gtt-1,gta));
}else if (gta<4000){
print(gta);
}else{
print(-1);
}
}
} | #include <bits/stdc++.h>
#include <bits/extc++.h>
#define ll long long
#define endl "\n"
#define pb push_back
#define ms(v,x) memset(v,x,sizeof(v))
#define ff first
#define ss second
#define td(v) v.begin(),v.end()
#define rep(i,a,n) for (int i=(a);i<(n);i++)
#define re(v) {for(auto &_re : v) cin >> _re;}
#define pr(v) {for(auto _pr : v) cout << _pr << " "; cout << endl;}
#define sz(x) (int)(x).size()
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define eb emplace_back
using namespace std;
const ll M = 1e9 + 7;
const ll mod = 998244353;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll binpow(ll a, ll b){
ll res = 1;
while(b > 0){
if(b&1) res = res * a % M;
a = a * a % M;
b>>=1;
}
return res;
}
//#define double long double
//#define int long long
string t = "atcoder";
void solve(){
string s;
cin >> s;
bool ok = false;
for(char c : s) if(c!='a') ok = true;
if(!ok){
cout << -1 << endl;
return;
}
if(t < s){
cout << 0 << endl;
return;
}
int eq = 1;
for(int i=0;i<min((int)s.size(), 7);i++){
if(s[i] == t[i]){
eq++;
}
}
int ans = 1e9;
for(int i=0;i<s.size();i++){
for(int j=0;j<eq; j++){
if(s[i] > t[j]){
ans = min(ans, abs(i-j));
}
}
}
cout << ans << endl;
}
int32_t main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//freopen("jump.in", "r", stdin);
//freopen("equal.out", "w", stdout);
int t = 1;
cin >> t;
while(t--){
solve();
}
} |
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <ctype.h>
#include <climits>
#include <queue>
#include <iostream>
#include <string>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
// using ll = long long;
//using P = pair<int,int>;
int main () {
int n;
cin >> n;
vector<string> s(n);
set<string> s_set;
rep(i,n) {
cin >> s[i];
s_set.insert(s[i]);
}
rep(i,n) {
if(s_set.count("!" + s[i])) {
cout << s[i] << endl;
return 0;
}
}
cout << "satisfiable" << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define int long long int
#define popcount(x) __builtin_popcountll(x)
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define sc second
#define pb push_back
#define fr first
#define all(a) (a).begin(),(a).end()
#define mem0(a) memset(a,0,sizeof(a))
#define ld long double
const int INF = __LONG_LONG_MAX__;
#define rall(a) (a).rbegin(),(a).rend()
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroint-loops")
int power(int a,int b,int m)
{
int res=1;
while(b)
{
if(b&1) res=((res%m)*(a%m))%m;
a=((a%m)*(a%m))%m;
b>>=1;
}
return res;
}
int power(int a,int b)
{
int res=1;
while(b)
{
if(b&1) res*=a;
a*=a;
b>>=1;
}
return res;
}
bool isPowerOfTwo(int x)
{
// x will check if x == 0 and !(x & (x - 1)) wiint check if x is a power of 2 or not
return (x && !(x & (x - 1)));
}
void solve()
{
int n;
cin>>n;
int ans=1;
for(int i=2;i<=n;i++)
{
ans=(ans*i)/__gcd(i,ans);
}
ans++;
cout<<ans;
}
signed main()
{
fastio
int tt=1;
// cin>>tt;
// freopen("input.txt", "r" , stdin);
// freopen("output.txt", "w", stdout);
while(tt--)
{
solve();
cout<<"\n";
}
return 0;
} |
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rrep(i,n) for(ll i=n-1; i>=0; i--)
#define fi first
#define se second
long long mo = 1000000007;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef pair<ll,Pll> PlP;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
string zero_padding(int val, int nf){ ostringstream sout;sout << setfill('0') << setw(nf) << val; return sout.str();};
ld PI=3.14159265358979323846;
//using namespace atcoder;
int main(){
ll N,W;
cin >> N >> W;
vector<ll> S(N), T(N), P(N), A(200001);
rep(i,N){
cin >> S[i] >> T[i] >> P[i];
A[S[i]] += P[i];
A[T[i]] -= P[i];
}
rep(i,200000){
A[i+1] += A[i];
}
ll M = -1;
rep(i,200001){
cmax(M,A[i]);
}
string ans = "No";
if(M <= W){
ans = "Yes";
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int a,b,c,f=0;
string g="Yes";
cin>>a>>b>>c;
int h=a;
vector<int> d(b),e(b);
for(int i=0;i<b;i++){
cin>>d.at(i)>>e.at(i);
}
for(int i=0;i<b;i++){
a-=d.at(i)-f;
f=d.at(i);
if(a<=0)g="No";
a+=e.at(i)-f;
if(h<a)a=h;
f=e.at(i);
}
a-=c-f;
if(a<=0)g="No";
cout<<g<<endl;
} |
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <cstdlib>
using namespace std;
typedef long long ll;
string intToA(int n,int radix){
string ans="";
do{
int t=n%radix;
if(t>=0&&t<=9)ans+=t+'0';
else ans+=t-10+'a';
n/=radix;
}while(n!=0);
reverse(ans.begin(),ans.end());
return ans;
}
const int maxn = 1e3 + 5;
int res[100086] = {0};
int main(){
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
res[1] = 1;
for(int i = 2;i<=100000;i++){
string w1 = intToA(i,10);
string w2 = intToA(i,8);
//cout << w1 << w2 <<endl;
if(w1.find('7')!=w1.npos || w2.find('7')!=w2.npos){
res[i] = res[i-1];
}else{
res[i] = res[i-1]+1;
}
}
int k;
cin >> k;
cout << res[k] << endl;
return 0;
} | #include<iostream>
#include<algorithm>
#include<cmath>
#include<numeric>
#include<vector>
#include<map>
#include<climits>
using namespace std;
int main(){
int n;
cin >> n;
vector<int> a(n);
for(auto &e: a) cin >> e;
int ans = INT_MAX;
for(int i = 0; i < 1 << n; i++){
int xored = 0, ored = 0;
for(int j = 0; j < n; j++){
ored |= a[j];
if(j == n - 1 || (i >> j) & 1){
xored ^= ored;
ored = 0;
}
}
ans = min(ans, xored);
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 101;
int dp[N][N * N * N], cnt[N];
int n, k, mod;
void upd(int & var, int val) {
var += val;
if (var >= mod)
var -= mod;
}
int main() {
scanf("%d %d %d", &n, &k, &mod);
dp[0][0] = 1;
int sum = 0;
for (int x = 1; x <= n; ++x) {
memset(cnt, 0, sizeof cnt);
sum += k * x;
int full = k * x;
for (int j = 0, z = 0; j <= sum; ++j) {
int now = dp[x-1][j];
upd(cnt[z], now);
dp[x][j] = cnt[z];
if (j >= full) {
upd(cnt[z], mod - dp[x-1][j-full]);
}
++z;
if (z >= x)
z -= x;
}
}
for (int i = 1; i <= n; ++i) {
int lef = i - 1, rig = n - i;
long long ans = 0;
for (int j = 0; j <= sum; ++j) {
ans = (ans + 1LL * dp[lef][j] * dp[rig][j]) % mod;
}
ans = (ans * (k+1) - 1) % mod;
if (ans < 0)
ans += mod;
printf("%lld\n", ans);
}
return 0;
}
|
// Author: Muhesh Kumar
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using db = long double;
using str = string;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pd = pair<db, db>;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<ll>;
using vd = vector<db>;
using vs = vector<str>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vpd = vector<pd>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using si = set<int>;
using sl = set<ll>;
using ss = set<str>;
ll mod = 1000000007;
ll inf = 1e18 + 1;
#define fr first
#define sc second
#define sz(x) (x).size()
#define bg(x) begin(x)
#define all(x) bg(x), end(x)
#define ft front()
#define bk back()
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define nl '\n'
#define rev(v) reverse(all(v))
#define sor(v) sort(all(v))
#define lb lower_bound
#define ub upper_bound
#define amax(a, b) a = max(a, b)
#define amin(a, b) a = min(a, b)
#define mxele(v) *max_element(all(v))
#define mnele(v) *min_element(all(v))
#define rep(i, a, b) for(int i = a; i < b; i++)
#define repeq(i, a, b) for (int i = a; i <= b; i++)
#define reprev(i, b, a) for (int i = b - 1; i >= a; i--)
#define repeach(a, b) for (auto& a: b)
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, a, b; cin >> n >> a >> b;
cout << n - a + b;
return 0;
} |
#include <bits/stdc++.h>
#define LL long long
#define ull unsigned long long
#define F(i, j, k) for (int i = j; i <= k; ++i)
#define DF(i, j, k) for (int i = j; i >= k; --i)
using namespace std;
template <typename T> inline void read(T &n) {
T w = 1;
n = 0;
char ch = getchar();
while (!isdigit(ch) && ch != EOF) {
if (ch == '-') w = -1;
ch = getchar();
}
while (isdigit(ch) && ch != EOF) {
n = (n << 3) + (n << 1) + (ch & 15);
ch = getchar();
}
n *= w;
}
template <typename T> inline void write(T x) {
T l = 0;
ull y = 0;
if (!x) { putchar(48); return; }
if (x < 0) { x = -x; putchar('-'); }
while (x) { y = y * 10 + x % 10; x /= 10; ++l; }
while (l) { putchar(y % 10 + 48); y /= 10; --l; }
}
template <typename T> inline void writes(T x) {
write(x);
putchar(' ');
}
template <typename T> inline void writeln(T x) {
write(x);
puts("");
}
template <typename T> inline void checkmax(T &a, T b) { a = a > b ? a : b; }
template <typename T> inline void checkmin(T &a, T b) { a = a < b ? a : b; }
const int N = 5000, MOD = 998244353;
int cm[N + 10][N + 10], ans;
inline int add(int x, int y) { x += y; return x >= MOD ? x - MOD : x; }
inline int dec(int x, int y) { x -= y; return x < 0 ? x + MOD : x; }
int main() {
//freopen(".in", "r", stdin);
//freopen(".out", "w", stdout);
int n, m;
read(n);
read(m);
F(i, 1, N) {
cm[i][0] = 1;
F(j, 1, N) cm[i][j] = (LL)cm[i][j - 1] * i % MOD;
}
F(v, 1, m) {
F(len, 1, n) {
if (len + 2 <= n) ans = add(ans, (LL)dec(cm[m - v + 1][len], cm[m - v][len]) * (v - 1) % MOD * (v - 1) % MOD * cm[m][n - len - 2] % MOD * (n - len - 1) % MOD);
if (len + 1 <= n) ans = add(ans, 2LL * dec(cm[m - v + 1][len], cm[m - v][len]) % MOD * (v - 1) % MOD * cm[m][n - len - 1] % MOD);
if (len == n) ans = add(ans, dec(cm[m - v + 1][len], cm[m - v][len]));
}
}
writeln(ans);
return 0;
} | #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
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; }
typedef long long ll;
using namespace std;
const ll mod=1e9+7;
ll n;
ll b=0,c=0;
//vector<ll> B(2e5,0),C(2e5,0);
vector<bool> used(2e5,false);
vector<vector<pair<ll,ll>>> t(2e5);
//vector<ll> a(2e5,0);
ll res=0,tmp=1;
void dfs(ll x,int k){
if(k==1){
res=(res+(b*tmp)%mod)%mod;
c++;
}else{
res=(res+(c*tmp)%mod)%mod;
b++;
}
rep(i,t[x].size()){
ll y=t[x][i].first,w=t[x][i].second%2;
if(used[y])continue;
used[y]=true;
int nk=k^w;
dfs(y,nk);
t[x][i].second/=2;
}
}
int main(void){
cin>>n;
rep(i,n-1){
ll u,v,w;cin>>u>>v>>w;u--;v--;
t[u].push_back({v,w});
t[v].push_back({u,w});
}
rep(i,60){
rep(j,n)used[j]=false;
b=0,c=0;
used[0]=true;
dfs(0,0);
tmp=(tmp*2)%mod;
//cout<<res<<endl;
}
cout<<res<<endl;
} |
//DUEL
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define x first
#define y second
#define pii pair<int,int>
#define pb push_back
#define eb emplace_back
#pragma GCC optimize("unroll-loops")
#define shandom_ruffle(a, b) shuffle(a, b, rng)
#define vi vector<int>
#define vl vector<ll>
#define popcnt __builtin_popcount
#define popcntll __builtin_popcountll
#define all(a) begin(a),end(a)
using namespace std;
using namespace __gnu_pbds;
using ll=long long;
using ull=unsigned long long;
using ld=long double;
int MOD=1000000007;
int MOD2=998244353;
vector<int> bases;
const ll LLINF=1ll<<60;
const char en='\n';
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void yes() {cout<<"YES"<<en; exit(0);}
void no() {cout<<"NO"<<en; exit(0);}
inline int rund() {int x576363482791fuweh=rng();return abs(x576363482791fuweh)%RAND_MAX;}
template<class T>
void prVec(vector<T> w,bool fl=false)
{
cout<<w.size()<<en;
for (int i=0;i<int(w.size())-1;++i) cout<<w[i]<<' ';
if (w.size()) cout<<w[w.size()-1]<<en;
if (fl) cout<<flush;
}
void M998()
{
swap(MOD,MOD2);
}
ll raand()
{
ll a=rund();
a*=RAND_MAX;
a+=rund();
return a;
}
#define rand raand
ll raaand()
{
return raand()*(MOD-7)+raand();
}
template<class T>
vi compress(vector<T>&v)
{
set<T> s;
for (auto a: v) s.insert(a);
vector<T> o(all(s));
vi nv;
for (int i=0;i<(int)v.size();++i) nv.pb(lower_bound(all(o),v[i])-o.begin());
return nv;
}
string to_upper(string a)
{
for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A';
return a;
}
string to_lower(string a)
{
for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A';
return a;
}
ll sti(string a,int base=10)
{
ll k=0;
for (int i=0;i<(int)a.size();++i)
{
k*=base;
k+=a[i]-'0';
}
return k;
}
template<class T>
void eras(vector<T>& a,T b)
{
a.erase(find(a.begin(),a.end(),b));
}
string its(ll k,int base=10)
{
if (k==0) return "0";
string a;
while (k)
{
a.push_back((k%base)+'0');
k/=base;
}
reverse(a.begin(),a.end());
return a;
}
ll min(ll a,int b)
{
if (a<b) return a;
return b;
}
ll min(int a,ll b)
{
if (a<b) return a;
return b;
}
ll max(ll a,int b)
{
if (a>b) return a;
return b;
}
ll max(int a,ll b)
{
if (a>b) return a;
return b;
}
ll gcd(ll a,ll b)
{
if (b==0) return a;
return gcd(b,a%b);
}
ll lcm(ll a,ll b)
{
return a/gcd(a,b)*b;
}
template<class T,class K>
pair<T,K> mp(T a,K b)
{
return make_pair(a,b);
}
inline int mult(ll a,ll b)
{
return (a*b)%MOD;
}
inline int pot(int n,int k)
{
if (k==0) return 1;
ll a=pot(n,k/2);
a=mult(a,a);
if (k%2) return mult(a,n);
else return a;
}
int divide(int a,int b)
{
return mult(a,pot(b,MOD-2));
}
inline int sub(int a,int b)
{
if (a-b>=0) return a-b;
return a-b+MOD;
}
inline int add(int a,int b)
{
if (a+b>=MOD) return a+b-MOD;
return a+b;
}
void ad(int&a,int b)
{
a+=b;
if (a>=MOD) a-=MOD;
}
bool prime(ll a)
{
if (a==1) return 0;
for (int i=2;i<=round(sqrt(a));++i)
{
if (a%i==0) return 0;
}
return 1;
}
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
const int N=300010;
int a,b;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
for (int i=0;i<10;++i) bases.push_back(rand()%(MOD-13893829*2)+13893829);
cin>>a>>b;
int s=0;
for (int i=0;i<a;++i) cout<<900000+i<<' ',s+=900000+i;
for (int i=0;i<b-1;++i) cout<<-1-i<<' ',s+=-1-i;
cout<<-s<<endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, n) for (int i = 0; i < (int)(n); ++ i)
int fa[200005];
ll sz[200005];
int find(int x) {
return x == fa[x] ? x : fa[x] = find(fa[x]);
}
void merge(int x, int y) {
x = find(x), y = find(y);
if (x == y) return ;
fa[y] = x;
sz[x] += sz[y];
}
int main() {
int n, m;
scanf("%d %d", &n, &m);
vector <int> a(n), b(n);
rep(i, n) scanf("%d", &a[i]);
rep(i, n) scanf("%d", &b[i]);
rep(i, n) fa[i] = i, sz[i] = a[i] - b[i];
rep(i, m) {
int u, v;
scanf("%d %d", &u, &v);
-- u, -- v;
merge(u, v);
}
rep(i, n) if (i == find(i)) {
if (sz[i] != 0) {
puts("No");
return 0;
}
}
puts("Yes");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 105;
int from[MAXN], to[MAXN];
int dp[2 * MAXN];
int r = 0;
int N;
int valid(int l, int r) {
if (r % 2 == l % 2) return 123456;
//cerr << "check " << l << " " << r << endl;
int len = r - l + 1, m = (l + r) / 2;
vector<bool> can(len / 2, false);
for (int i = 1; i <= N; i++) {
if (from[i] != -1 && to[i] != -1) {
if (from[i] >= l && from[i] <= m && to[i] > m && to[i] <= r && to[i] - from[i] == len / 2) {
can[from[i] - l] = true;
}
} else if (from[i] != -1) {
if (from[i] >= l && from[i] <= m) {
if (can[from[i] - l]) {
//cerr << "INF" << endl;
return 123456;
}
can[from[i] - l] = true;
}
} else {
if (to[i] > m && to[i] <= r) {
if (can[to[i] - len / 2 - l]) {
//cerr << "INF" << endl;
return 123456;
}
can[to[i] - len / 2 - l] = true;
}
}
}
int ans = 0;
for (int i = 0; i < len / 2; i++) {
if (can[i]) ans += 1;
}
int need = len / 2 - ans;
//cerr << need << endl;
return need;
}
int main() {
cin >> N;
int real_n = N;
set<int> vals;
for (int i = 1; i <= N; i++) {
cin >> from[i] >> to[i];
if (from[i] > -1 && to[i] > -1 && from[i] >= to[i]) return 0 * puts("No");
if (from[i] != -1) {
if (vals.count(from[i])) return 0 * puts("No");
vals.insert(from[i]);
}
if (to[i] != -1) {
if (vals.count(to[i])) return 0 * puts("No");
vals.insert(to[i]);
}
if (from[i] == -1 && to[i] == -1) {
i -= 1;
N -= 1;
r += 1;
}
}
dp[0] = 0;
for (int i = 1; i <= 2 * real_n; i++) {
dp[i] = 123456;
for (int j = 1; j <= i; j++) {
int cur = dp[j - 1] + valid(j, i);
//cerr << j << " tries " << cur << endl;
dp[i] = min(dp[i], cur);
}
//cerr << "dp_res: " << i << " " << dp[i] << endl;
}
cout << (dp[2 * real_n] <= r ? "Yes" : "No") << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
//using namespace atcoder;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define pb push_back
#define fi first
#define se second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void chOut(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }
using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using v_bool = vector<bool>;
using v_Pii = vector<Pii>;
//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};
const int mod = 1000000007;
//const int mod = 998244353;
signed main(){
int N; cin >> N;
vec A(N), B(N);
vec flg(2 * N + 1, 0), to(2 * N + 1, -1), from(2 * N + 1, -1);
REP(i, N){
cin >> A[i] >> B[i];
/*if(A[i] > 0 && B[i] > 0 && A[i] > B[i]){
Out("No");
return 0;
}*/
if(A[i] > 0) flg[A[i]] = 1;
if(B[i] > 0) flg[B[i]] = -1;
if(A[i] > 0 && B[i] > 0){
to[A[i]] = B[i];
from[B[i]] = A[i];
}
}
REP(i, N) REP(j, N){
if(A[i] > 0 && B[j] > 0 && A[i] == B[j]){
Out("No");
return 0;
}
if(A[i] > 0 && A[j] > 0 && A[i] == A[j] && i != j){
Out("No");
return 0;
}
if(B[i] > 0 && B[j] > 0 && B[i] == B[j] && i != j){
Out("No");
return 0;
}
}
v_bool pos(2 * N + 1, false);
pos[0] = true;
FOR(i, 1, 2 * N + 1){
FOR(k, 1, N + 1){
int j = i - 2 * k;
if(j < 0 || !pos[j]) continue;
bool ok = true;
FOR(x, 1, k + 1){
if(flg[j + x] == -1 || flg[j + k + x] == 1) ok = false;
else if(flg[j + x] == 1 && flg[j + k + x] == -1){
if(to[j + x] != j + k + x || from[j + k + x] != j + x) ok = false;
}else if(flg[j + x] == 1){
if(to[j + x] > 0 && to[j + x] != j + k + x) ok = false;
}else if(flg[j + k + x] == -1){
if(from[j + k + x] > 0 && from[j + k + x] != j + x) ok = false;
}
}
if(ok) pos[i] = true;
}
}
chOut(pos[2 * N], "Yes", "No");
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 55;
int n, a[N];
ll mem[N][1<<17];
vector<int> primes;
bool check(int x) {
for(int i = 2; i*i <= x; ++i)
if(!(x % i))
return 0;
return 1;
}
void init() {
memset(mem, -1, sizeof mem);
for(int i = 2; i <= 50; ++i) {
if(check(i))
primes.push_back(i);
}
//for(int i = 0; i < primes.size(); ++i)
//cout<<primes[i]<<endl;
}
ll dp(int i, int msk) {
if(i == n+1)
return 1;
ll &ret = mem[i][msk];
if(ret != -1)
return ret;
ret = 2e18;
for(int j = 0; j < (int)primes.size(); ++j) {
ll curr = primes[j];
if(a[i] % curr == 0) {
if((msk & (1<<j)) == 0)
ret = min(ret, dp(i+1, (msk | (1<<j))) * curr);
else
ret = min(ret, dp(i+1, msk));
}
}
return ret;
}
int main() {
init();
scanf("%d", &n);
for(int i = 1; i <= n; ++i)
scanf("%d", a+i);
printf("%lld", dp(1, 0));
return 0;
}
| #include <bits/stdc++.h>
//#include <chrono>
#pragma GCC optimize("O3")
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
ll N,M,H,W,Q,K,A,B;
string S;
using P = pair<ll, ll>;
const ll INF = (1LL<<60);
template<class T> bool chmin(T &a, const T b){
if(a > b) {a = b; return true;}
else return false;
}
template<class T> bool chmax(T &a, const T b){
if(a < b) {a = b; return true;}
else return false;
}
template<class T> void my_printv(std::vector<T> v,bool endline = true){
if(!v.empty()){
for(std::size_t i{}; i<v.size()-1; ++i) std::cout<<v[i]<<" ";
std::cout<<v.back();
}
if(endline) std::cout<<std::endl;
}
vec prime;
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
reps(i, 2, 51){
bool pr = true;
reps(j, 2, i) if(i%j == 0) pr = false;
if(pr) prime.push_back(i);
}
M = 15;
ll res = INF;
cin>>N;
vec a(N);
rep(i, N) cin>>a[i];
rep(s, 1<<M){
ll cmp = 1;
rep(i, M) if((s>>i)&1) cmp *= prime[i];
rep(i, N){
bool ok = false;
rep(j, M){
if(((s>>j)&1) && a[i]%prime[j] == 0){
ok = true;
break;
}
}
if(!ok){
cmp = -1;
break;
}
}
if(cmp != -1) chmin(res, cmp);
}
cout<<res<<endl;
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll solve() {
ll X, Y;
cin >> X >> Y;
ll ans = (6-X-Y)%3;
return ans;
}
int main() {
auto ans = solve();
cout << ans << "\n";
return 0;
} | // #pragma GCC optimize("Ofast,unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#include <bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define forn(i, s, n) for(ll i=(ll)s; i<(ll)(n); i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define pll pair<long long int, long long int>
#define pii pair<int, int>
#define pss pair<string, string>
#define ull unsigned long long int
#define lld long double
#define F first
#define S second
#define PI 3.141592653589793238
#define prec(n) fixed<<setprecision(n)
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define itsval(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); itval(_it, args); }
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
void itval(istream_iterator<string> it) {}
template<typename T, typename... Args>
void itval(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << endl;
itval(++it, args...);
}
const ll MOD = 1e9 + 7;
template <typename T>
inline void print(T x) {cout << x << "\n";}
template <typename T>
inline void printvec(T x) {for (auto a : x) cout << a << ' '; cout << '\n';}
// -----------------------------------------------------------------------
struct custom {
bool operator()(const pair<int, pii> &p1, const pair<int, pii> &p2)const {
return p1.F < p2.F;
}
};
// Calculate a^b % MOD -------------------------------------------------
ll get_pow(ll a, ll b, ll M = MOD) {
ll res = 1;
while (b) {
if (b & 1) res = (res * a) % M;
a = (a * a) % M;
b >>= 1;
}
return res;
}
// ---------------------------------------------------------------------
const ll N = 1e3 + 5, inf = 2e18;
void solve()
{
ll A, B;
cin >> A >> B;
A += B;
if (A >= 15 && B >= 8)
{
cout << 1;
}
else if (A >= 10 && B >= 3)
{
cout << 2;
}
else if (A >= 3)
{
cout << 3;
}
else
cout << 4;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output1.txt", "w", stdout);
#endif
int test = 1;
//cin >> test;
clock_t z = clock();
forn(tes, 0, test)
{
// cout << "Case #" << tes + 1 << ": ";
solve();
}
debug("Total Time:%.4f\n", (double)(clock() - z) / CLOCKS_PER_SEC);
return 0;
} |
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
const int maxx = 100005;
int n , c[maxx];
vector<int> edge[maxx];
int asd[maxx];
multiset<int> s;
vector<int> ans;
void dfs(int u)
{
s.insert(c[u]);
asd[u] = 1;
for(int i : edge[u])
{
if(!asd[i])
{
if(!s.count(c[i])) ans.pb(i);
dfs(i);
set<int>:: iterator it = s.lower_bound(c[i]);
if(it != s.end()) s.erase(it);
}
}
}
signed main()
{
ios_base::sync_with_stdio(false);cin.tie(nullptr);
cin >> n ;
for(int i = 1; i <= n; ++i)
{
cin >> c[i];
}
for(int i = 1 ; i < n ; ++i) {
int u , v; cin >> u >> v;
edge[u].pb(v);
edge[v].pb(u);
}
dfs(1);
ans.pb(1);
sort(begin(ans),end(ans));
for(int i : ans ) cout << i << '\n';
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 allr(v) v.rbegin(), v.rend()
#define V vector
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define sz(x) int(x.size())
#define pcnt __builtin_popcountll
template <typename T> bool chmin(T &a, const T &b) {if(a > b){a = b; return true;} return false;}
template <typename T> bool chmax(T &a, const T &b) {if(a < b){a = b; return true;} return false;}
template <typename T> void print(T a) {cout << a << ' ';}
template <typename T> void printe(T a) {cout << a << endl;}
template <typename T> void printv(T a) {rep(i, sz(a))print(a[i]); cout<<endl;}
template <typename T> void printp(pair<T, T> a) {print(a.first); cout<<a.second<<endl;}
template <typename A, size_t N, typename T> void Fill (A (&array)[N], const T & val) {fill ((T*)array, (T*)(array+N), val);}
template <typename T> using vc = vector<T>;
template <typename T> using vv = vc<vc<T>>;
template <typename T> using vvv = vc<vv<T>>;
using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using vi = vc<int>;
using vvi = vv<int>;
using vl = vc<ll>;
using vvl = vv<ll>;
vi di = {-1, 1, 0, 0, -1, -1, 1, 1};
vi dj = { 0, 0, -1, 1, -1, 1, -1, 1};
const int MAX_N = 1e5 + 10;
int n;
vi c(MAX_N);
vc<bool> used(MAX_N, false);
vi ans;
vvi to(MAX_N);
void dfs (int now, int p) {
for (int nxt : to[now]) {
if (nxt == p) continue;
if (!used[c[nxt]]) {
ans.eb(nxt);
used[c[nxt]] = true;
dfs(nxt, now);
used[c[nxt]] = false;
continue;
}
dfs(nxt, now);
}
}
int main () {
cin >> n;
rep(i, n) cin >> c[i];
rep(i, n-1) {
int a, b; cin >> a >> b, a--, b--;
to[a].eb(b);
to[b].eb(a);
}
ans.eb(0);
used[c[0]] = true;
dfs(0, -1);
sort(all(ans));
rep(i, sz(ans)) cout << ans[i] + 1 << endl;
return 0;
} |
#include<iostream>
#include<vector>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<cmath>
#include<set>
using namespace std;
int main()
{
int i ;
cin >> i ;
if(i % 2 == 0){
cout << "White" << endl;
}
else{
cout << "Black" << endl;
}
}
| #include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define F first
#define S second
#define pss pair<string,string>
#define pcc pair<char,char>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define piii pair<int,pii>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define vs vector<string>
#define vl vector<ll>
#define vs vector<string>
#define vll vector<pll>
#define vss vector<pss>
#define vcc vector<pcc>
#define MP make_pair
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=n-1;i>=0;i--)
#define Very_fast std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
const int N = 1e5+5;
const int mod=1e9+7;
const int INF=0x3f3f3f3f;
inline ll gcd(ll a,ll b){if(b==0)return a;else return gcd(b,a%b);}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll lowbit(ll x){return (x&-x);}
inline ll kissme(ll x,ll y)
{
ll res=1;
if(x==0)return 1;
if(x==1)return y;
res=kissme(x/2,y);
res=res*res%mod;
if(x%2==1)res=res*y%mod;
return res;
}
int n;
signed main()
{
Very_fast;
cin>>n;
if(n%2==0)cout<<"White\n";
else cout<<"Black\n";
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
//freopen("D://input.txt", "r", stdin);
int n, m;
cin >> n >> m;
vector<int> v(n);
vector<int> x(2, 0);
for(int i = 0; i < n; i++){
string s;
cin >> s;
int total = 0;
int bit_count = 0;
for(int j = 0; j < m; j++){
total *= 2;
total += s[j]=='1';
bit_count += s[j]=='1';
}
v[i] = total;
x[bit_count%2]++;
}
ll ans = 1LL * x[0] * x[1];
cout << ans << endl;
}
| #include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
int main(int argc, char const *argv[])
{
int n;
cin >> n;
vector<int> a(n);
vector<int> b(n);
rep(i,n) cin >> a[i];
rep(i,n) cin >> b[i];
int cnt = 0;
for (int i = 0; i <= 1000; ++i)
{
bool ok = true;
rep(j,n){
if(i < a[j] || i > b[j] ){
ok = false;
}
}
if(ok) cnt++;
}
cout << cnt << endl;
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int a,b,c,d; cin>>a>>b>>c>>d;
cout<<(a*d-b*c);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = double;
const int mxn = 1e6+10;
bool mt[20][20];
int h, w,a , b;
ll ans = 0;
void rec(int i=0, int j=0, int a0=0) {
//cout << "[" << i << ", " << j << ", " << a0 << "]\n";
if(a0>a or i>=h or j>=w) return;
if(i==h-1 and j==w-1) {
if(a==a0) {
/*cout << "mat: \n";
for(int x=0; x<h; x++) {
for(int y=0; y<w; y++) cout << mt[x][y] << " "; cout << '\n';
}*/
ans++;
}
return;
}
if(!mt[i][j]) {
if(j+1<w) rec(i, j+1, a0);
else rec(i+1, 0, a0);
if(j+1<w and !mt[i][j+1]) mt[i][j] = mt[i][j+1] = 1, rec(i, j+1, a0+1), mt[i][j] = mt[i][j+1] = 0;
if(i+1<h and !mt[i+1][j]) {
mt[i][j] = mt[i+1][j] = 1;
if(j+1<w) rec(i, j+1, a0+1);
else rec(i+1, 0, a0+1);
mt[i][j] = mt[i+1][j] = 0;
}
}
else {
if(j+1<w) rec(i, j+1, a0);
else rec(i+1, 0, a0);
}
}
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin>>h>>w>>a>>b;
rec();
cout << ans << '\n';
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> pi;
#define f first
#define s second
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);
#define all(x) x.begin(),x.end()
typedef pair<int, pi> pii;
const int maxn = 10000;
const int INF = LLONG_MAX/2;
int n,K,mod;
int dp[110][510000];
int32_t main() {
FAST
cin >> n >> K >> mod;
int maxv = K * n * (n + 1) / 2;
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
vector <int> temp(i+1,0);
int s = 0;
for (int sum = 0; sum <= maxv; sum++) {
while (s < sum - i * K) {
int indx = s % i;
temp[indx] = (temp[indx] - dp[i-1][s] + mod) % mod;
s++;
}
int indx = sum % i;
temp[indx] = (temp[indx] + dp[i-1][sum]) % mod;
dp[i][sum] = (dp[i][sum] + temp[indx]) % mod;
}
}
for (int avg = 1; avg <= n; avg++) {
int ans = 0;
for (int sum = 0; sum <= maxv; sum++) {
ans += (dp[avg - 1][sum] * dp[n - avg][sum]) % mod;
ans %= mod;
}
ans = (ans * (K+1)) % mod;
ans = (ans - 1 + mod) % mod;
cout << ans << "\n";
}
}
| #include <bits/stdc++.h>
const long long INF = 1e9;
const long long MOD = 1e9 + 7;
//const long long MOD = 998244353;
const long long LINF = 1e18;
using namespace std;
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE" ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible" ) << endl
#define dump(x) cout << #x << " = " << (x) << endl
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define COUT(x) cout<<(x)<<endl
#define SCOUT(x) cout<<(x)<<" "
#define VECCOUT(x) for(auto&youso_: (x) )cout<<right<<setw(1)<<youso_<<" ";cout<<endl
#define ENDL cout<<endl
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) long long __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define mp make_pair
#define PQ priority_queue<long long>
#define PQG priority_queue<long long,V,greater<long long>>
typedef long long ll;
typedef vector<long long> vl;
typedef vector<long long> vi;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<vb> vvb;
typedef vector<vc> vvc;
typedef pair<long long, long long> pll;
#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
cin>>head;
CINT(move(tail)...);
}
template<class T>
void mod(T &x) {
x %= MOD;
x += MOD;
x %= MOD;
}
ll GCD(ll a, ll b) {
if(b == 0) return a;
else return GCD(b, a%b);
}
struct COMB{
vl fact, fact_inv, inv;
void init_nCk(long long SIZE) {
fact.resize(SIZE + 5);
fact_inv.resize(SIZE + 5);
inv.resize(SIZE + 5);
fact.at(0) = fact.at(1) = fact_inv.at(0) = fact_inv.at(1) = inv.at(1) = 1;
for(long long i = 2; i < SIZE + 5; i++) {
fact.at(i) = fact.at(i - 1)*i%MOD;
inv.at(i) = MOD - inv.at(MOD%i)*(MOD/i)%MOD;
fact_inv.at(i) = fact_inv.at(i - 1)*inv.at(i)%MOD;
}
}
long long nCk (long long n, long long k) {
assert(!(n < k));
assert(!(n < 0 || k < 0));
return fact.at(n)*(fact_inv.at(k)*fact_inv.at(n - k)%MOD)%MOD;
}
};
ll extGCD(ll a, ll b, ll &x, ll &y) {
if(b == 0) {
x = 1;
y = 0;
return a;
}
ll d = extGCD(b, a%b, y, x);
y -= a/b*x;
return d;
}
void Main() {
LCIN(N);
vl fib(92, 1);
for(int i = 2; i < 92; i++) {
fib.at(i) = fib.at(i - 1) + fib.at(i - 2);
}
vl fibs(92, 1);
ll memo = N;
for(int i = 0; i < 92; i++) {
int j = 91 - i;
fibs.at(j) = N/fib.at(j);
N %= fib.at(j);
}
vl fibsc(30, 1);
for(int i = 0; i < 30; i++) {
fibsc.at(i) = i;
}
// VECCOUT(fibsc);
// VECCOUT(fibs);
queue<int> ans;
bool c = 0;
int KKK = 1;
for(int i = 1; i < 92 - KKK; i++) {
int j = 91 - i;
if(fibs.at(j) && c) {
ans.push(2 - (i)%2);
}
if(c) {
ans.push(4 - (i + 1)%2);
}
if(fibs.at(j) && !c) {
ans.push(1);
ans.push(2);
c = 1;
}
}
cout << ans.size() << endl;
while(ans.size()) {
ll tmp = ans.front();
ll res = tmp;
cout << res << endl;
ans.pop();
}
}
int main() {
cout << fixed << setprecision(15);
Main();
return 0;
}
|
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <ctime>
#include <numeric>
#include <vector>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <complex>
#include <deque>
#include <functional>
#include <list>
#include <map>
#include <string>
#include <sstream>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>
#include <forward_list>
#include <thread>
#include <random>
#include <array>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
void io()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
int main()
{
io();
int si,sj; cin>>si>>sj;
int pos[50][50];
for(int i=0; i<50; i++){
for(int j=0; j<50; j++){
cin>>pos[i][j];
}
}
bool chek[3000];
memset(chek,false,sizeof(chek));
int arr[50][50];
for(int i=0; i<50; i++){
for(int j=0; j<50; j++){
cin>>arr[i][j];
}
}
string str="";
chek[pos[si][sj]]=true;
while(true){
int qwe=-1;
char keeper=' ';
if(si!=0 && !chek[pos[si-1][sj]]){
if(arr[si-1][sj]>=qwe){qwe=arr[si-1][sj]; keeper='U';}
}
if(si!=49 && !chek[pos[si+1][sj]]){
if(arr[si+1][sj]>=qwe){qwe=arr[si+1][sj]; keeper='D';}
}
if(sj!=0 && !chek[pos[si][sj-1]]){
if(arr[si][sj-1]>=qwe){qwe=arr[si][sj-1]; keeper='L';}
}
if(sj!=49 && !chek[pos[si][sj+1]]){
if(arr[si][sj+1]>=qwe){qwe=arr[si][sj+1]; keeper='R';}
}
if(qwe==-1){
break;
}
if(keeper=='U'){
chek[pos[si-1][sj]]=true;
si--;
str+=keeper;
}
else if(keeper=='D'){
chek[pos[si+1][sj]]=true;
si++;
str+=keeper;
}
else if(keeper=='L'){
chek[pos[si][sj-1]]=true;
sj--;
str+=keeper;
}
else if(keeper=='R'){
chek[pos[si][sj+1]]=true;
sj++;
str+=keeper;
}
}
cout<<str<<endl;
}
//Aneegha Thithiesha Mahabaduge.
| /*
* Author : Andrew J
*/
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) x.begin() , x.end()
#define rall(x) x.rbegin() , x.rend()
#define vz(x) x.size()
using ll = long long;
using ii = pair <int , int>;
void in(int &x);
// const int N = ;
const int INF = 1e9 + 50;
const int MOD = 1e9 + 7;
int f(int x) {
vector <int> dig, desc, asc;
while (x) {
dig.pb(x % 10);
x /= 10;
}
desc = dig, asc = dig;
sort(all(asc));
sort(rall(desc));
int desc_int = 0, asc_int = 0;
{
int tens = 1;
for (int x : desc) {
asc_int += x * tens;
tens *= 10;
}
}
{
int tens = 1;
for (int x : asc) {
desc_int += x * tens;
tens *= 10;
}
}
return desc_int - asc_int;
}
int main() {
int n, k; scanf("%d%d", &n, &k);
while (k--) {
n = f(n);
}
printf("%d\n", n);
return 0;
}
void in(int &x){
bool neg = false;
register int c;
x = 0;
c = getchar();
if(c == '-'){
neg = true;
c = getchar();
}
for (; c > 47 && c < 58; c = getchar()) {
x = (x << 1) + (x << 3) + c - 48;
}
if (neg) x *= -1;
}
|
#include<bits/stdc++.h>
#define ls rt << 1
#define rs rt << 1 | 1
#define lson l , mid , rt << 1
#define rson mid + 1, r, rt << 1 | 1
#define lr2 (l + r) >> 1
using namespace std;
typedef long long ll;
const int maxn = 4e5 + 50;
ll sum[maxn << 2], lazy[maxn << 2];
int L[maxn], R[maxn];
void push_up(int rt){
sum[rt] = sum[ls] + sum[rs];
}
void push_down(int rt, int m){
if(lazy[rt])
{
lazy[ls] += lazy[rt];
lazy[rs] += lazy[rt];
sum[ls] += lazy[rt] * (m - (m >> 1));
sum[rs] += lazy[rt] * (m >> 1);
lazy[rt] = 0;
}
}
void update(int a, int b, ll v, int l, int r, int rt){
if(a <= l && b >= r){
sum[rt] += 1LL * (r - l + 1) * v;
lazy[rt] += v;
return;
}
push_down(rt, r - l + 1);
int mid = lr2;
if(a <= mid) update(a, b, v, lson);
if(b > mid) update(a, b, v, rson);
push_up(rt);
}
ll query(int a, int b, int l, int r, int rt){
if(a <= l && b >= r){
return sum[rt];
}
int mid = lr2;
push_down(rt, r - l + 1);
ll ans = 0;
if(a <= mid) ans += query(a, b, lson);
if(b > mid) ans += query(a, b, rson);
return ans;
push_up(rt);
}
int a[maxn], b[maxn];
int cnt, n;
vector<int> G[maxn];
int d[maxn];
void dfs(int v, int fa){
L[v] = ++cnt;
d[v] = d[fa] + 1;
for(auto u : G[v]){
if(u != fa){
dfs(u, v);
}
}
R[v] = cnt;
}
int main()
{
std::ios::sync_with_stdio(false);
cin >> n;
for(int i = 1;i < n;i++){
cin >> a[i] >> b[i];
G[a[i]].push_back(b[i]);
G[b[i]].push_back(a[i]);
}
dfs(1, 0);
int q;
cin >> q;
ll ans = 0;
while(q--){
int t, id;
ll x;
cin >> t >> id >> x;
if(t == 1){
if(d[a[id]] < d[b[id]]){
ans += x;
update(L[b[id]], R[b[id]], -x, 1, n, 1);
}
else update(L[a[id]], R[a[id]], x, 1, n, 1);
}
else{
if(d[b[id]] < d[a[id]]){
ans += x;
update(L[a[id]], R[a[id]], -x, 1, n, 1);
}
else update(L[b[id]], R[b[id]], x, 1, n, 1);
}
}
for(int i = 1;i <= n;i++) cout << query(L[i], L[i], 1, n ,1) + ans << endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
bool _DD = false;
#define _D(a)if(_DD)cout<<#a<<':'<<a<<" | ";
#define DBG(a){_D(a);if(_DD)cout<<'\n';}
#define DBG2(a,b){_D(a);_D(b);if(_DD)cout<<'\n';}
#define DBG3(a,b,c){_D(a);_D(b);_D(c);if(_DD)cout<<'\n';}
#define DBG4(a,b,c,d){_D(a);_D(b);_D(c);_D(d);if(_DD)cout<<'\n';}
#define DBG5(a,b,c,d,e){_D(a);_D(b);_D(c);_D(d);_D(e);if(_DD)cout<<'\n';}
#define DBG6(a,b,c,d,e,f){_D(a);_D(b);_D(c);_D(d);_D(e);_D(f);if(_DD)cout<<'\n';}
#define PB push_back
#define EB emplace_back
#define btoe(v) (v).begin(),(v).end()
#define etob(v) (v).rbegin(),(v).rend()
#define F first
#define S second
#define SZ size()
typedef unsigned long long int ulli;
typedef long long int lli;
typedef long double ldbl;
#define f(i,a,b) for(int i=(a); i<(b); ++i)
#define fr(i,a,b) for(int i=(a); i>(b); --i)
#define fl(i,a,b) for(lli i=(a); i<(b); ++i)
#define flr(i,a,b) for(lli i=(a); i>(b); --i)
#define w(x) lli x; cin>>x; while(x--)
#define inpn(n,v,T) T n; cin>>n; vector<T> v(n); fl(i,0,n) cin>>v[i];
#define inp(n,v,T) vector<T> v(n); fl(i,0,n) cin>>v[i];
typedef pair<int,int> pii;typedef vector<int> vi;typedef vector<vi> vvi;typedef vector<pii> vpii;typedef vector<vector<pii>> vvpii;typedef pair<lli,lli> plli;typedef vector<lli> vlli;typedef vector<vlli> vvlli;typedef vector<plli> vplli;typedef vector<vector<plli>> vvplli;typedef vector<bool> vb;typedef vector<vb> vvb;typedef vector<string> vs;typedef vector<vector<string>> vvs; typedef vector<char> vc; typedef vector<vc> vvc;
#define unmp unordered_map
const lli PRIME = 1000000007ll;
const lli PRIME2 = 998244353ll;
inline void debugORfast(bool a=0,bool b=1){
if(a) _DD=1;
if(b){ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}
}
//Question Link
class mysort{
public:
bool operator() (const plli &p1, const plli &p2){
if(p1.F+p1.S>p2.F+p2.S) return true;
else if(p1.F+p1.S==p2.F+p2.S){
if(p1.F>p2.F) return true;
else return false;
}
else return false;
}
}mysorto;
vi times;
vlli ans;
void dfsh(const vvi &g, int n, int p, int &t, const vlli &c, vb &vis){
vis[n] = true;
times[n] = t++;
ans[n] = ans[p]+c[n];
for(int ch:g[n]){
if(ch!=p and !vis[ch]) dfsh(g,ch,n,t,c,vis);
}
}
void dfs(const vvi &g, const vlli &c){
times.clear();
times.resize(g.size(),0);
ans.clear();
ans.resize(g.size(),0);
vb vis(g.size(),false);
int t = 0;
dfsh(g,1,0,t,c,vis);
}
int main(int argc,char* argv[])
{
if(argc>1 and strcmp(argv[1],"1")==0) debugORfast(1,1);
else debugORfast(0,1);
/*
int n; cin>>n;
lli asum = 0;
vplli v(n);
f(i,0,n){
cin>>v[i].F>>v[i].S;
asum += v[i].F;
}
sort(btoe(v),mysorto);
//f(i,0,n){
// cout<<v[i].F<<'-'<<v[i].S<<endl;
//}
lli bsum = 0,asumsmall=0;
f(i,0,n){
asumsmall += v[i].F;
bsum += (v[i].F+v[i].S);
if(bsum>(asum-asumsmall)){
cout<<i+1<<endl;
break;
}
}
*/
int n; cin>>n;
vvi g(n+1);
vpii e(n+1);
f(i,1,n){
int a,b; cin>>a>>b;
e[i].F = a; e[i].S = b;
g[a].PB(b);
g[b].PB(a);
}
vlli c(n+1,0);
dfs(g,c); //pops times
//f(i,1,times.SZ) cout<<times[i]<<' '; cout<<endl;
w(qq){
lli t,ei,x;
cin>>t>>ei>>x;
int a = e[ei].F;
int b = e[ei].S;
//cout<<a<<' '<<b<<endl;
if(t==2) swap(a,b);
if(times[a]<times[b]){
c[1]+=x; c[b]-=x;
}else{
c[a]+=x;
}
}
//f(i,1,c.SZ) cout<<c[i]<<' '; cout<<endl;
dfs(g,c);
f(i,1,ans.SZ){
cout<<ans[i]<<endl;
}
return 0;
}
|
//#define _GLIBCXX_DEBUG
#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 rall(v) v.rbegin(), v.rend()
using ll = int64_t;
using ull = uint64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T>>;
const int INF = 0xccccccc;
const ll LINF = 0xcccccccccccccccLL;
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 T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}
//head
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int h, w, a, b;
cin >> h >> w >> a >> b;
vector<vector<vvi>> dp(h+1, vector<vvi>(w+1, vvi(1<<w, vi(a+1))));
dp[0][0][0][0] = 1;
rep(i, h) {
rep(j, w) {
rep(k, 1<<w) {
rep(l, a+1) {
dp[i][j+1][k&~(1<<j)][l] += dp[i][j][k][l];
if(~k>>j&1 and l != a) {
if(j != w-1 and ~k>>j+1&1) dp[i][j+1][k^(1<<j+1)][l+1] += dp[i][j][k][l];
dp[i][j+1][k^(1<<j)][l+1] += dp[i][j][k][l];
}
}
}
}
rep(k, 1<<w) {
rep(l, a+1) {
dp[i+1][0][k][l] = dp[i][w][k][l];
}
}
}
cout << dp[h][0][0][a] << endl;
} |
//================code===================//
//#define TLE
#ifdef TLE
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#endif
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <ctime>
#define ci(t) cin>>t
#define co(t) cout<<t
#define LL long long
#define ld double
#define fa(i,a,b) for(LL i=(a);i<(LL)(b);++i)
#define fd(i,a,b) for(LL i=(a);i>(LL)(b);--i)
#define setp tuple<LL,LL,LL>
#define setl pair<LL,LL>
#define micro 0.000001
using namespace std;
LL gcd(LL a, LL b) { return a % b ? gcd(b, a % b) : b; }
#ifdef OHSOLUTION
#define ce(t) cerr<<t
#define AT cerr << "\n=================ANS=================\n"
#define AE cerr << "\n=====================================\n"
#define DB(a) cerr << __LINE__ << ": " << #a << " = " << (a) << endl;
#define __builtin_popcount __popcnt
#define __builtin_popcountll __popcnt64
#else
#define AT
#define AE
#define ce(t)
#endif
pair <int, int> vu[9] = { {0,-1},{1,0},{0,1} ,{-1,0},{0,0},{1,1}, {-1,1} , {1,-1},{-1,-1} }; //RDLU EWSN
template<typename T, typename U> void ckmax(T& a, U b) { a = a < b ? b : a; }
template<typename T, typename U> void ckmin(T& a, U b) { a = a > b ? b : a; }
struct gcmp { bool operator()(LL a, LL b) { return a < b; } bool operator()(setl& a, setl& b) { return a.second < b.second; } };
struct lcmp { bool operator()(LL a, LL b) { return a > b; } bool operator()(setl& a, setl& b) { return a.second > b.second; } };
const int max_v = 1e4 + 7;
const int max_k = 1027;
const int INF = 1e9 + 7;
const LL LNF = (LL)5e18 + 7ll;
LL mod = 1e9+7;
template<typename T, typename U> void MOD(T& a, U b) { a += b; if (a >= mod) a -= mod; }
int r, c;
int ans = 0;
bool arr[17][17];
void dfs(int idx, int a, int b)
{
if (a < 0 || b < 0) return;
if (idx == r*c)
{
++ans;
return;
}
int nr = idx / c;
int nc = idx % c;
if (arr[nr][nc]) dfs(idx + 1, a, b);
else
{
if (nr + 1 != r)
{
arr[nr + 1][nc] = 1;
dfs(idx + 1, a - 1, b);
arr[nr + 1][nc] = 0;
}
if (nc + 1 != c && !arr[nr][nc+1])
{
arr[nr][nc + 1] = 1;
dfs(idx + 1, a - 1, b);
arr[nr][nc + 1] = 0;
}
dfs(idx + 1, a, b - 1);
}
}
int main()
{
#ifdef OHSOLUTION
freopen("input.txt", "r", stdin);
#endif
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int a, b; ci(r >> c >> a >> b);
dfs(0, a, b);
co(ans);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll= long long;
// #define double long double
#define sz(x) (int)x.size()
#define all(x) (x).begin(),(x).end()
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define _set(x) __builtin_popcount(x)
#define _setl(x) __builtin_popcountll(x)
#define PI 3.14159265358979323846264338327950L
#define mod 1000000007LL
#ifdef LOCAL
#define elapsed_time 1.0 * clock() / CLOCKS_PER_SEC
#endif
void debug(){
cerr<<"]\n";
}
template<class H,class ... T> void debug(H h,T... t){
cerr<<h;
if(sizeof... (t)){
cerr<<", ";
}
debug(t...);
}
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#ifdef DEBUG
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", debug(__VA_ARGS__)
#define dpv(...) cerr<< "["#__VA_ARGS__ " : ";for(int i: (__VA_ARGS__)){cerr<<i<<" ";}cerr<<"]\n"
#else
#define dbg(...) 0
#define dpv(...) 0
#endif
void solve(){
int v, t,s ,d;
cin>>v>>t>>s>>d;
t *= v;
s *= v;
if(s< t) swap(s, t);
if(!(d<= s && d>= t)){
cout<<"Yes\n";
}else{
cout<<"No\n";
}
}
int32_t main(){
IOS
// freopen("input.txt","r",stdin);
int _;
// cin>>_;
_=1;
for(int i=1;i<=_;i++){
// cout<<"Case #"<<i<<": ";
solve();
}
#ifdef LOCAL
cerr<<endl<<"[Time Elapsed : "<<elapsed_time<<"]"<<endl;
#endif
return 0;
}
/*
check for overflows int long long
correct mize of array
*/ | #include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
double v,t,s,d;
cin>>v>>t>>s>>d;
double x = d/v;
if(x<t||x>s)puts("Yes");
else puts("No");
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define ub upper_bound
#define lb lower_bound
#define all(v) ((v).begin()),((v).end())
#define allr(v) ((v).rbegin()),((v).rend())
#define ff first
#define ss second
#define mp make_pair
#define pll pair<ll,ll>
#define fo(i,n) for(ll i=0;i<n;i++)
#define foa(i,s,e) for(ll i=(s);i<=e;i++)
#define fod(i,s,e) for(ll i= (s);i>=(e);i--)
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n'
#define sz(x) (ll)(x.size())
#define ANS cout<<ans<<'\n'
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
#define Yes cout<<"Yes\n"
#define No cout<<"No\n"
const ld pi = 3.14159265358979323846;
ll MOD = 1e9 + 7;
//ll MOD = 998244353;
const char nl = '\n';
const ll inf = 1e15;
#define fill(a,b) memset(a, b, sizeof(a))
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) fo(i, n){fo(j, m)cout<<dp[i][j]<<" ";cout<<"\n";}
ll nxt(){ll x; cin >> x; return x;}
ll mul(ll x,ll y){
return (1ll* (x%MOD)*(y%MOD));
}
ll modpow(ll x,ll y){ll z=1;while(y>0){if(y%2)z=mul(z,x);x =mul(x,x) ;y/=2;}return z;}
ll power(ll x,ll y){ll z=1;while(y>0){if(y%2)z=z*x;x =x*x ;y/=2;}return z;}
ll gcd(ll a,ll b){if(a<b) return gcd(b,a);if(b==0) return a;return gcd(b,a%b);}
ll min(ll a,ll b){if(a<b)return a;return b;}
ll max(ll a,ll b){if(a>b)return a;return b;}
ll sq(ll a){
ll ans = (1ll*a*a);
return ans;
}
void solve(){
ll n, m;
cin >> n >> m;
ll a[m][2];
fo(i, m){
cin >> a[i][0] >> a[i][1];
}
ll k;
cin >> k;
ll c[k][2];
fo(i, k){
cin >> c[i][0] >> c[i][1];
}
ll ans = 0;
ll tot = (1LL << k);
fo(i, tot){
vll ok(n + 1);
fo(j, k){
if((i >> j) & 1){
ok[c[j][1]] = 1;
}
else{
ok[c[j][0]] = 1;
}
}
ll cnt = 0;
fo(j, m){
if(ok[a[j][0]] && ok[a[j][1]]){
cnt++;
}
}
ans = max(ans, cnt);
}
ANS;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt" , "r" , stdin) ;
freopen("output.txt" , "w" , stdout) ;
freopen("error.txt" , "w" , stderr) ;
#endif
ll TC = 1;
//cin>>TC;
fo(TT, TC){
// Google,FB cout << "Case #"<< TT + 1 << ": ";
solve();
}
cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}
| #include "bits/stdc++.h"
using namespace std;
#define int long long
#define pb push_back
#define pf push_front
#define ppf pop_front
#define ppb pop_back
#define ff first
#define s(num) to_string(num)
#define ss second
#define mp(a,b) make_pair(a,b)
#define pii pair<int,int>
#define vi vector<int>
#define mem1(a) memset(a,-1,sizeof(a))
#define mem0(a) memset(a,0,sizeof(a))
#define ssort(v) sort(v.begin(),v.end())
#define rsort(v) sort(v.rbegin(),v.rend())
#define start(t) int x;cin>>x;while(x--)
#define endl "\n"
#define all(x) (x).begin(),(x).end()
void rec(vector<pii>& v, vector<pii>& p, int &cnt, int idx, unordered_map<int, int> um) {
if (idx >= p.size()) {
int q = 0;
for (pii x : v) {
if (um[x.ff] && um[x.ss])
q += 1;
}
cnt = max(cnt, q);
return;
}
um[p[idx].ff] += 1;
rec(v, p, cnt, idx + 1, um);
um[p[idx].ff] -= 1;
um[p[idx].ss] += 1;
rec(v, p, cnt, idx + 1, um);
um[p[idx].ss] -= 1;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
#ifdef NCR
init();
#endif
int n, m; cin >> n >> m;
vector<pii> v;
for (int i = 0; i < m; i++) {
int x, y; cin >> x >> y;
v.pb(mp(x, y));
}
int k; cin >> k;
vector<pii> p;
unordered_map<int, int> um;
for (int i = 0; i < k; i++) {
int a, b;
cin >> a >> b;
p.push_back(mp(a, b));
}
int cnt = INT_MIN;
rec(v, p, cnt, 0, um);
cout << cnt << 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 x;
R x;
pr(100-x%100);
}
int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int main() {
int X;
cin >> X;
cout << 100 - X % 100 << endl;
return 0;
} |
// RioTian 21/03/15
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 2e5 + 10;
int dp[N][7];
int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
int n;
string s, t;
cin >> n >> s >> t, s = " " + s, t = " " + t;
dp[n][0] = 1;
for (int i = n; i >= 1; --i) {
for (int j = 0; j < 7; ++j) {
int a = dp[i][(j * 10 + s[i] - '0') % 7];
int b = dp[i][j * 10 % 7];
if (t[i] == 'A') dp[i - 1][j] = a & b;
else
dp[i - 1][j] = a | b;
}
}
cout << (dp[0][0] ? "Takahashi\n" : "Aoki\n");
return 0;
} | #include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
bool f[N][7];
int X[N];
char op[N];
int n;
int qpow(int p,int q){
int ans=1;
while(q){
if(q&1)ans=ans*p%7;
q>>=1;
p=p*p%7;
}
return ans;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
cin>>n;
char cc;
for(int i=1;i<=n;++i){
cin>>cc;
X[i]=(cc-'0')*qpow(10,n-i)%7;
}
cin>>(op+1);
f[n][0]=1;
for(int i=n-1;i>=0;i--){
if(op[i+1]=='A'){
for(int j=0;j<7;++j){
if((f[i+1][(j+X[i+1])%7])&&(f[i+1][j]))f[i][j]=1;
}
}
else{
for(int j=0;j<7;++j){
if(f[i+1][(j+X[i+1])%7]||f[i+1][j])f[i][j]=1;
}
}
}
if(f[0][0])cout<<"Takahashi\n";
else cout<<"Aoki\n";
return 0;
} |
#include "bits/stdc++.h"
using namespace std;
int func(int a, int b, int c, int d) {
if (a >= b) {
if (a >= c) {
if (a >= d) {
return 0;
}
else {
return 3;
}
}
else {
if (c >= d) {
return 2;
}
else {
return 3;
}
}
}
else {
if (b >= c) {
if (b >= d) {
return 1;
}
else {
return 3;
}
}
else {
if (c >= d) {
return 2;
}
else {
return 3;
}
}
}
}
int main(void) {
int si, sj;
vector<vector<int>> t(50, vector<int>(50));
vector<vector<int>> p(50, vector<int>(50));
cin >> si >> sj;
for (int i = 0; i < 50; ++i) {
for (int j = 0; j < 50; ++j) {
cin >> t[i][j];
}
}
for (int i = 0; i < 50; ++i) {
for (int j = 0; j < 50; ++j) {
cin >> p[i][j];
}
}
int c;
for (;;) {
int up = -1;
int down = -1;
int left = -1;
int right = -1;
if (si > 0 && t[si][sj] != t[si - 1][sj]) {
up = p[si - 1][sj];
}
if (si < 49 && t[si][sj] != t[si + 1][sj]) {
down = p[si + 1][sj];
}
if (sj > 0 && t[si][sj] != t[si][sj - 1]) {
left = p[si][sj - 1];
}
if (sj < 49 && t[si][sj] != t[si][sj + 1]) {
right = p[si][sj + 1];
}
int m = func(up, down, left, right);
if (up == -1 && down == -1 && left == -1 && right == -1) {
return 0;
}
c = t[si][sj];
if (m == 0) {
cout << "U";
--si;
}
else if (m == 1) {
cout << "D";
++si;
}
else if (m == 2) {
cout << "L";
--sj;
}
else if (m == 3) {
cout << "R";
++sj;
}
int c2 = t[si][sj];
if (si > 0 && c2 == t[si - 1][sj]) {
t[si - 1][sj] = c;
}
if (si < 49 && c2 == t[si + 1][sj]) {
t[si + 1][sj] = c;
}
if (sj > 0 && c2 == t[si][sj - 1]) {
t[si][sj - 1] = c;
}
if (sj < 49 && c2 == t[si][sj + 1]) {
t[si][sj + 1] = c;
}
t[si][sj] = c;
}
return 0;
} | #include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
using namespace std;
#define FIO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
#define mp make_pair
#define fi first
#define se second
#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) (((a) * (b)) / (__gcd((a), (b))))
#define in_range(x, y, r, c) (x < r && y < c && x >= 0 && y >= 0)
#define setbits(x) __builtin_popcountll(x)
#define unsetend(x) __builtin_ctzll(x)
#define unsetfront(x) __builtin_clzll(x)
#define f first
#define s second
#define pb push_back
#define pf push_front
#define ll long long
#define all(a) a.begin(), a.end()
#define sd(x) scanf("%d", &x) // to use this make sure to remove ios_base....
#define sll(x) scanf("%lld", &x)
#define endl "\n"
#define Endl "\n"
#define INF INT_MAX
long long expo(long long a, long long b, long long m)
{
ll ret = 1;
while (b > 0)
{
if (b % 2 == 1)
ret = ((ret % m) * (a % m)) % m;
a = (a % m) * (a % m);
b = b / 2;
}
return ret;
}
vector<long long> seive()
{
long long i, j;
vector<long long> hash(1000001, 1);
vector<long long> primes;
for (i = 2; i * i <= 1000000; i++)
{
if (hash[i])
{
for (j = i * i; j <= 1000000; j += i)
hash[j] = 0;
}
}
for (i = 2; i < 1000001; i++)
{
if (hash[i])
primes.pb(i);
}
return primes;
}
int main()
{
FIO;
int n, m;
cin >> n >> m;
int mod = 1e9 + 7;
char arr[n][m];
int dp[n][m];
int dpup[n][m];
int dpleft[n][m];
int dpdiag[n][m];
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
cin >> arr[i][j];
dp[i][j] = 0;
dpup[i][j] = 0;
dpleft[i][j] = 0;
dpdiag[i][j] = 0;
}
}
dp[0][0] = 1;
dpleft[0][0] = 1;
dpup[0][0] = 1;
dpdiag[0][0] = 1;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
if (i == 0 && j == 0)
continue;
if (arr[i][j] == '.')
{
int a = 0, b = 0, c = 0;
if (i - 1 >= 0)
a = dpup[i - 1][j];
if (j - 1 >= 0)
b = dpleft[i][j - 1];
if (i - 1 >= 0 && j - 1 >= 0)
c = dpdiag[i - 1][j - 1];
dp[i][j] = (((a + b) % mod) + c) % mod;
dpup[i][j] = (dp[i][j] + a) % mod;
dpleft[i][j] = (dp[i][j] + b) % mod;
dpdiag[i][j] = (dp[i][j] + c) % mod;
}
}
}
// for (int i = 0; i < n; i++)
// {
// for (int j = 0; j < m; j++)
// cout << dp[i][j] << " ";
// cout << endl;
// }
cout << dp[n - 1][m - 1] << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
std::fill( (T*)array, (T*)(array+N), val );
}
template<class T> inline bool chmax(T &a, T b){
if(a<b){
a = b;
return true;
}
return false;
}
template<class T> inline bool chmin(T &a, T b){
if(a>b){
a = b;
return true;
}
return false;
}
int w[51],v[51];
int x[51];
int main(){
int n,m,q;
cin >> n >> m >> q;
rep(i,n)cin >> w[i] >> v[i];
rep(i,m)cin >> x[i];
rep(zz,q){
int L,R;
cin >> L >> R;
vector<pair<int,int> > p;
for(int i=0;i<L-1;i++){
p.push_back(MP(x[i],inf));
}
for(int i=R;i<m;i++){
p.push_back(MP(x[i],inf));
}
for(int i=0;i<n;i++){
p.push_back(MP(w[i],v[i]));
}
sort(p.begin(),p.end());
int res = 0;
priority_queue<int> pq;
for(auto x:p){
if(x.second==inf){
if(!pq.empty()){
res += pq.top();
pq.pop();
}
}else{
pq.push(x.second);
}
}
cout << res << "\n";
}
return 0;
} | #include <algorithm>
#include <functional>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using ll = long long;
using namespace std;
ll dp[51][51] = {0};
int main(int argc, char *argv[]) {
ll N, M, Q;
cin >> N >> M >> Q;
vector<pair<ll, ll>> wv_org(N);
vector<pair<ll, ll>> wv(N);
for (int i = 0; i < N; i++) {
cin >> wv_org[i].first >> wv_org[i].second;
}
vector<pair<ll, int>> box(M, pair<ll, int>(0, 0));
for (int i = 0; i < M; i++) {
cin >> box[i].first;
// 元のindex 覚えておく
box[i].second = i;
}
sort(box.begin(), box.end());
vector<ll> ans(Q, 0);
for (int i = 0; i < Q; i++) {
wv = wv_org;
ll l, r;
cin >> l >> r;
l--, r--;
for (int j = 0; j < M; j++) {
if (box[j].second >= l && box[j].second <= r) {
continue;
}
ll v = 0;
ll used = -1;
for (int k = 0; k < N; k++) {
if (box[j].first >= wv[k].first && v < wv[k].second) {
v = wv[k].second;
used = k;
}
}
if (used != -1) {
wv[used].first = 1LL << 60;
ans[i] += v;
}
}
}
for (int i = 0; i < Q; i++) {
cout << ans[i] << endl;
}
}
|
///Bismillahir Rahmanir Rahim
#include "bits/stdc++.h"
#define ll long long
#define int ll
#define fi first
#define si second
#define mp make_pair
#define pb push_back
#define pi pair<int,int>
#define nd(a,b,c) mp(mp(a,b),c)
#define clr(x) memset(x,0,sizeof(x));
#define f(i,l,r) for(int i=l;i<=r;i++)
#define rf(i,r,l) for(int i=r;i>=l;i--)
#define done(i) cout<<"done = "<<i<<endl;
#define show(x,y) cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
const ll inf=2e18;
const int mod=1e9+7;
const int M=200005;
char x[M],y[M];
void solve()
{
int n,flag=0;
cin>>n;
string s;
cin>>s;
for(int i=1;i<=n;i++)
{
x[i]=s[i-1];
y[i]=s[i-1+n];
}
x[n+1]='\0';
y[n+1]='\0';
int q;
cin>>q;
while(q--)
{
int typ,u,v,p,q;
cin>>typ>>u>>v;
if(typ==2)
{
flag=1-flag;
}
else
{
if(flag==0)
{
if(v<=n)
{
swap(x[u],x[v]);continue;
}
if(u>n)
{
swap(y[u-n],y[v-n]);continue;
}
p=u;q=v-n;
swap(x[p],y[q]);
}
else
{
if(v<=n)
{
swap(y[u],y[v]);continue;
}
if(u>n)
{
swap(x[u-n],x[v-n]);continue;
}
p=v-n;q=u;
swap(x[p],y[q]);
}
}
}
if(flag==0)
{
f(i,1,n)cout<<x[i];
f(i,1,n)cout<<y[i];
cout<<"\n";
}
else
{
f(i,1,n)cout<<y[i];
f(i,1,n)cout<<x[i];
cout<<"\n";
}
}
main()
{
fast
int t=1;
//cin>>t;
while(t--)
{
solve();
}
return 0;
}
| //#define _GLIBCXX_DEBUG
//#include "atcoder/all"
//using namespace atcoder;
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
#define Dump(x) \
if (dbg) { \
cerr << #x << " = " << (x) << endl; \
}
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) (((n) >> (k)) & 1) /*nのk bit目*/
namespace mydef {
const int INF = 1ll << 60;
const int MOD = 1e9 + 7;
template <class T>
bool chmin(T& a, const T& b) {
if (a > b) {
a = b;
return 1;
} else
return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
if (a < b) {
a = b;
return 1;
} else
return 0;
}
void Yes(bool flag = true) {
if (flag)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
void No(bool flag = true) {
Yes(!flag);
}
void YES(bool flag = true) {
if (flag)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
void NO(bool flag = true) {
YES(!flag);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
std::fill((T*)array, (T*)(array + N), val);
}
bool dbg = true;
} // namespace mydef
using namespace mydef;
#define pb push_back
//#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<pair<int, int>>
#define vvp vector<vector<pair<int, int>>>
#define pi pair<int, int>
//#define P pair<int, int>
//#define V vector<int>
//#define S set<int>
#define asn ans
int N, M;
vector<pi> G[101010];
int ans[101010];
int seen[101010];
void dfs(int now, int bef) {
if (seen[now])
return;
seen[now] = 1;
for (auto& p : G[now]) {
int nxt = p.first;
if (seen[nxt])
continue;
if (bef == nxt)
continue;
int c = p.second;
int nxt_c;
if (ans[now] == c) {
nxt_c = (c + 1) % N;
} else
nxt_c = c;
ans[nxt] = nxt_c;
dfs(nxt, now);
}
}
void solve() {
dfs(0, -1);
for (int i = 0; i < N; i++) {
cout << ans[i] + 1 << endl;
}
}
signed main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cin >> N >> M;
for (int i = 0; i < M; i++) {
int u, v, c;
cin >> u >> v >> c;
u--;
v--;
c--;
G[u].push_back({v, c});
G[v].push_back({u, c});
}
solve();
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
//common file for PBDS
#include<ext/pb_ds/assoc_container.hpp>
// including tree_order_statistics_node_update
#include<ext/pb_ds/tree_policy.hpp>
//namespace
using namespace __gnu_pbds;
//#define int long long
//macro definition
#define ordered_set tree<pair<int,int>, null_type, less<pair<int,int > >, rb_tree_tag, tree_order_statistics_node_update>
int main()
{
long long int a,b,c;
cin>>a>>b>>c;
if(c%2==0)
{
if(abs(a)==abs(b))
cout<<"="<<endl;
else if(abs(a)>abs(b))
cout<<">";
else
cout<<"<";
}
else
{
if((a)==(b))
cout<<"="<<endl;
else if((a)>(b))
cout<<">";
else
cout<<"<";
}
return 0;
} | //----AUTHOR: eeshan_deo_iitkgp----/
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define ll long long
#define ld long double
#define pb push_back
#define ppb pop_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vb vector<bool>
#define vd vector<double>
#define vll vector<ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define vs vector<string>
#define vc vector<char>
#define vvi vector<vi>
#define vvb vector<vb>
#define vvd vector<vd>
#define vvll vector<vll>
#define vvc vector<vc>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define w(x) \
int x; \
cin >> x; \
for (ll tc = 1; tc <= x; tc++)
#define in(i, x, y) for (ll i = x; i < y; i++)
#define rin(i, x, y) for (ll i = x; i >= y; i--)
#define all(a) begin(a), end(a)
#define rall(a) rbegin(a), rend(a)
#define lb lower_bound
#define ub upper_bound
ll fxp(ll a, ll b) {
assert(b >= 0);
a %= mod;
ll res = 1;
while (b > 0) {
if (b % 2 == 1)
res = (res * a) % mod;
a = (a * a) % mod;
b /= 2;
}
return res % mod;
}
inline ll minv(ll x) { return fxp(x, mod - 2); }
void c_p_c() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
const int mXn = 1;
const ll inf = 1e18;
signed main() {
c_p_c();
ll a, b, c; cin >> a >> b >> c;
if (a == 0 or b == 0) {
if (a == 0 and b == 0)cout << "=";
else if (a == 0) {
if (b < 0) {
if (c % 2)cout << ">";
else cout << "<";
}
else cout << "<";
}
else {
if (a < 0) {
if (c % 2)cout << "<";
else cout << ">";
}
else cout << ">";
}
}
else if (a < 0 or b < 0) {
if (a < 0 and b < 0) {
if (c % 2) {
if (abs(a) < abs(b))cout << ">";
else if (abs(a) > abs(b))cout << "<";
else cout << "=";
}
else {
if (abs(a) > abs(b))cout << ">";
else if (abs(a) < abs(b))cout << "<";
else cout << "=";
}
}
else if (a < 0) {
if (c % 2)cout << "<";
else {
if (abs(a) > abs(b))cout << ">";
else if (abs(a) < abs(b))cout << "<";
else cout << "=";
}
}
else if (b < 0) {
if (c % 2)cout << ">";
else {
if (abs(a) > abs(b))cout << ">";
else if (abs(a) < abs(b))cout << "<";
else cout << "=";
}
}
}
else {
if (a > b)cout << ">";
else if (a < b)cout << "<";
else cout << "=";
}
} |
#include <bits/stdc++.h>
using namespace std;
int main(){
long long N;
cin >> N;
vector<int> ans;
long long INF = 1000000000000000000;
vector<long long> fib(87, INF);
fib[0] = 1;
fib[1] = 1;
for(int i = 2; i < 87; i++){
fib[i] = fib[i - 1] + fib[i - 2];
}
vector<int> ind;
while(N > 0){
for(int i = 86; i >= 0; i--){
if(N >= fib[i]) {
N -= fib[i];
ind.push_back(86 - i);
break;
}
}
}
int id = 0;
for(int i = 0; i < 86; i++){
if(i > 0){
if(i % 2 == 0){
ans.push_back(3);
}
else{
ans.push_back(4);
}
}
while(id < ind.size() && ind[id] == i){
if(i % 2 == 0){
ans.push_back(1);
}
else ans.push_back(2);
id++;
}
}
long long x = 0, y = 0;
ans.push_back(3);
for(int i = 0; i < ans.size(); i++){
if(ans[i] == 1) x++;
else if(ans[i] == 2) y++;
else if(ans[i] == 3) x = x + y;
else y = x + y;
}
cout << ans.size() << endl;
for(int t: ans) cout << t << endl;
} | #include <bits/stdc++.h>
// clang-format off
using namespace std; using ll=long long; using ull=unsigned long long; using pll=pair<ll,ll>; const ll INF=4e18;
void print0(){}; template<typename H,typename... T> void print0(H h,T... t){cout<<h;print0(t...);}
void print(){print0("\n");}; template<typename H,typename... T>void print(H h,T... t){print0(h);if(sizeof...(T)>0)print0(" ");print(t...);}
void perr0(){}; template<typename H,typename... T> void perr0(H h,T... t){cerr<<h;perr0(t...);}
void perr(){perr0("\n");}; template<typename H,typename... T>void perr(H h,T... t){perr0(h);if(sizeof...(T)>0)perr0(" ");perr(t...);}
void ioinit() { cout << fixed << setprecision(15); cerr<<fixed<<setprecision(6); ios_base::sync_with_stdio(0); cin.tie(0); }
// clang-format on
ll fibrest(ll x0, ll y0, ll n, bool isx) {
ll iter = 0;
vector<ll> fib = {x0, y0};
ll x = x0;
ll y = y0;
ll op = 0;
while (true) {
if (isx) {
x = x + y;
} else {
y = y + x;
}
if (x >= n) break;
op++;
isx = !isx;
}
return op;
}
void op(vector<ll> &ops, ll &x, ll &y, ll t) {
if (t == 1) {
x = x + 1;
}
if (t == 2) {
y = y + 1;
}
if (t == 3) {
x = x + y;
}
if (t == 4) {
y = y + x;
}
ops.push_back(t);
}
void output(vector<ll> &ops) {
ll k = ops.size();
print(ops.size());
for (auto ope : ops) {
print(ope);
}
}
int main() {
ioinit();
ll n;
cin >> n;
// while (fib.back() < n) {
// fib.push_back(fib[fib.size() - 1] + fib[fib.size() - 2]);
// }
// ll m = fib.size();
ll x = 0;
ll y = 0;
vector<ll> ops;
if (n < 120) {
while (x < n) {
op(ops, x, y, 1);
}
output(ops);
return 0;
}
op(ops, x, y, 2);
bool isx = true;
while (true) {
if (x + y > n) {
while (x < n) {
op(ops, x, y, 1);
}
break;
}
ll curop = fibrest(x, y, n, isx);
{
ll k = 0;
while (true) {
ll r = fibrest(x + k + 1, y, n, isx);
if (r != curop) break;
//perr(curop, r);
op(ops, x, y, 1);
k = k + 1;
}
}
if (isx) {
op(ops, x, y, 3);
} else {
op(ops, x, y, 4);
}
isx = !isx;
if (x >= n) break;
}
output(ops);
}
|
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#include<bitset>
#include<functional>
#include <fstream>
//#include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define rep(i, x) for(ll i = 0; i < x; i++)
#define rep2(i, x) for(ll i = 1; i <= x; i++)
#define rep3(i, x, y) for(ll i = x; i < y; i++)
#define rep4(i, x) for(ll i = x; i >= 0; i--)
#define all(a) (a).begin(),(a).end()
#define puts(x) cout << (x) << "\n"
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 1000000000000000000;
const int intINF = 1000000000;
const ll mod = 1000000007;
const ll MOD = 998244353;
const ld pi = 3.141592653589793238;
//const ld EPS = 1e-9;
bool isprime(int p) {
if (p == 1) return false;
for (int i = 2; i < p; i++) {
if (p % i == 0) return false;
}
return true;
}
ll gcd(ll a, ll b) {
if (a < b)swap(a, b);
if (a % b == 0)return b;
return gcd(b, a % b);
}
//ax + by = cが整数解をもつための必要十分条件は c が gcd(a,b) で割り切れること。
// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
//main関数内に extGCD(a, b, x, y); でx, yに解が格納
ll extGCD(ll a, ll b, ll& x, ll& y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
ll d = extGCD(b, a % b, y, x);
y -= a / b * x;
return d;
}
ll lcm(ll a, ll b) {
return a / gcd(a, b) * b;
}
ll keta(ll n) {
ll res = 0;
while (n >= 1) {
res += n % 10; n /= 10;
}
return res;
}
ll modpow(ll x, ll y, ll m) {
ll res = 1;
while (y) {
if (y % 2) { res *= x; res %= m; }
x = x * x % m; y /= 2;
}
return res;
}
ll kaijyo[600005];
void nCkinit(ll n, ll m) {
ll cnt = 1; kaijyo[0] = 1;
for (int h = 1; h <= n; h++) { cnt *= h; cnt %= m; kaijyo[h] = cnt; }
}
ll nCk(ll n, ll k, ll m) {
/*ll a = 1, b = 1;
for (int h = 1; h <= n; h++) { a *= h; a %= m; }
for (int h = 1; h <= k; h++) { b *= h; b %= m; }
for (int h = 1; h <= n - k; h++) { b *= h; b %= m; }*/
ll a = kaijyo[n], b = kaijyo[k] * kaijyo[n - k] % m;
return a * modpow(b, m - 2, m) % m;
}
//printf("%.10f\n", n);
typedef pair <ll, ll> P;
typedef pair <ll, string> pp;
ll dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
struct edge { ll to, cost; };
struct xy { ll x, y; };
struct status {
ll cost;
ll x;
ll y;
bool operator<(const status& rhs) const { return cost < rhs.cost; };
bool operator>(const status& rhs) const { return cost > rhs.cost; };
};
map<ll, set<ll>> ma;
map<ll, bool> ok;
void dfs(ll x, ll y) {
//まず自分の下にあるかどうか
auto itr1 = ma[y].lower_bound(x + 1);
ll sita = 0;
if (itr1 == ma[y].end()) { ok[y] = true; sita = INF; }
else { sita = *itr1; }
//y-1
if (y != 0) {
ll now = x + 1;
while (true) {
auto itr2 = ma[y - 1].lower_bound(now);
if (itr2 == ma[y - 1].end()) { break; }
if (sita < *itr2) { break; }
now = *itr2;
ma[y - 1].erase(now); dfs(now, y - 1);
}
}
//y + 1
ll now = x + 1;
while (true) {
auto itr2 = ma[y + 1].lower_bound(now);
if (itr2 == ma[y + 1].end()) { break; }
if (sita < *itr2) { break; }
now = *itr2;
ma[y + 1].erase(now); dfs(now, y + 1);
}
}
int main() {
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
//cout << fixed << setprecision(15);
ll n, m; cin >> n >> m; vector<ll>x(m), y(m);
rep(i, m) {
cin >> x[i] >> y[i]; ma[y[i]].insert(x[i]);
}
/*for (int i = max((ll)0, n - m - 1); i <= n + m + 1; i++) {
sort(all(ma[i]));
}*/
dfs(0, n);
ll ans = 0;
for (int i = max((ll)0, n - m - 1); i <= n + m + 1; i++) {
if (ok[i]) { ans++; }
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2,fma,tune=native")
#define ll long long
#define int ll
#define ull unsigned ll
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
//#define inf 1010000000
#define inf 4000000000000000000
#define eps 1e-9
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define print0(a) cout << (a) << ' '
#define ykh mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#ifdef i_am_noob
#define bug(...) cerr << "#" << __LINE__ << ' ' << #__VA_ARGS__ << "- ", _do(__VA_ARGS__)
template<typename T> void _do(vector<T> x){for(auto i: x) cerr << i << ' ';cerr << "\n";}
template<typename T> void _do(set<T> x){for(auto i: x) cerr << i << ' ';cerr << "\n";}
template<typename T> void _do(unordered_set<T> x){for(auto i: x) cerr << i << ' ';cerr << "\n";}
template<typename T> void _do(T && x) {cerr << x << endl;}
template<typename T, typename ...S> void _do(T && x, S&&...y) {cerr << x << ", "; _do(y...);}
#else
#define bug(...) 826
#endif
template<typename T> void print(T && x) {cout << x << "\n";}
template<typename T, typename... S> void print(T && x, S&&... y) {cout << x << ' ';print(y...);}
const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod;
const int maxn=200005;
//i_am_noob
//#define wiwihorz
template<int N>
struct hash_table1{
int ground=0,siz=0;
bool vis[N+5]={0};
int size(){return siz;}
void insert(int x){x-=ground;if(!vis[x]) siz++;vis[x]=1;}
void erase(int x){x-=ground;if(vis[x]) siz--;vis[x]=0;}
int count(int x){x-=ground;return vis[x];}
};
int n,m;
pii a[maxn];
map<int,vector<int>> mm;
hash_table1<maxn<<1> st;
void orzck(){
cin >> n >> m;
rep(m){
int x,y;
cin >> x >> y;
if(y>=n-m&&y<=n+m) mm[x].pb(y);
}
st.ground=n-maxn;
st.insert(n);
for(auto p: mm){
vector<int> vec=p.second;
unordered_set<int> st1,st2;
for(auto i: vec){
if(st.count(i-1)||st.count(i+1)) st1.insert(i);
else st2.insert(i);
}
for(auto i: st1) st.insert(i);
for(auto i: st2) st.erase(i);
}
print(sz(st));
}
signed main(){
ios_base::sync_with_stdio(0),cin.tie(0);
#ifdef i_am_noob
freopen("input1.txt","r",stdin);
freopen("output1.txt","w",stdout);
freopen("output2.txt","w",stderr);
#endif
cout << fixed << setprecision(15);
int t;
#ifdef wiwihorz
cin >> t;
#else
t=1;
#endif
while(t--) orzck();
return 0;
} |
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)
int N,Q;
vector<ll> A;
vector<ll> K;
int main(){
cin >> N >> Q;
A.resize(N);
rep(i,N) cin >> A[i];
rep(i,N) A[i] -= i;
K.resize(Q);
rep(i,Q) cin >> K[i];
rep(i,Q){
ll ans = K[i] + (upper_bound(A.begin(),A.end(),K[i]) - A.begin());
cout << ans << "\n";
}
return 0;
}
struct ios_do_not_sync{
ios_do_not_sync(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
}
} ios_do_not_sync_inst;
| //@formatter:off
#include<bits/stdc++.h>
#define overload4(_1,_2,_3,_4,name,...) name
#define rep1(i,n) for (ll i = 0; i < ll(n); ++i)
#define rep2(i,s,n) for (ll i = ll(s); i < ll(n); ++i)
#define rep3(i,s,n,d) for(ll i = ll(s); i < ll(n); i+=d)
#define rep(...) overload4(__VA_ARGS__,rep3,rep2,rep1)(__VA_ARGS__)
#define rrep(i,n) for (ll i = ll(n)-1; i >= 0; i--)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define popcount(x) __builtin_popcount(x)
#define pb push_back
#define eb emplace_back
#ifdef __LOCAL
#define debug(...) { cout << #__VA_ARGS__; cout << ": "; print(__VA_ARGS__); cout << flush; }
#else
#define debug(...) void(0)
#endif
#define INT(...) int __VA_ARGS__;scan(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;scan(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;scan(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;scan(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;scan(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__;scan(__VA_ARGS__)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int,int>;
using LP = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vs = vector<string>;
using vc = vector<char>;
using vvc = vector<vector<char>>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vp = vector<P>;
using vvp = vector<vector<P>>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==int(v.size()-1)?"":","); return os<<']'; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
void scan(){}
template <class Head, class... Tail> void scan(Head& head, Tail&... tail){ cin >> head; scan(tail...); }
template<class T> void print(const T& t){ cout << t << '\n'; }
template <class Head, class... Tail> void print(const Head& head, const Tail&... tail){ cout<<head<<' '; print(tail...); }
template<class... T> void fin(const T&... a) { print(a...); exit(0); }
const string yes[] = {"no","yes"};
const string Yes[] = {"No","Yes"};
const string YES[] = {"NO","YES"};
const int inf = 1001001001;
const ll linf = 1001001001001001001;
//@formatter:on
template<typename T>
class BIT {
int n;
vector<T> val;
public:
BIT(int n) : n(n), val(n + 1, 0) {}
void add(int i, T x = 1) {
i++;
while (i <= n) {
val[i] += x;
i += i & -i;
}
}
T sum(int i) {
T ret = 0;
i++;
while (i > 0) {
ret += val[i];
i -= i & -i;
}
return ret;
}
// [l,r)
T sum(int l, int r) { return sum(r - 1) - sum(l - 1); }
};
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
INT(n);
vi a(n);
cin >> a;
BIT<int> bt(n);
ll ans = 0;
rep(i, n) {
ans += bt.sum(a[i] + 1, n);
bt.add(a[i]);
}
rep(i, n) {
print(ans);
ans -= a[i];
ans += n - 1 - a[i];
}
}
|
#include <iostream>
constexpr int N = 5005;
constexpr int p = 998244353;
int add(int x, int y) { return (x += y) >= p ? x - p : x; }
int sub(int x, int y) { return (x -= y) < 0 ? x + p : x; }
int mul(int x, int y) { return (long long)x * y % p; }
int n, m;
int f[N], g[N];
int main() {
std::ios::sync_with_stdio(false), std::cin.tie(nullptr);
std::cin >> n >> m;
g[0] = 1;
for (int i = 1; i <= n; ++i) g[i] = mul(g[i - 1], m);
int ans = mul(n, g[n]);
for (int i = 1; i <= m; ++i)
for (int j = 1; j <= n; ++j) {
f[j] = add(mul(f[j - 1], i), sub(g[j - 1], f[j - 1]));
ans = sub(ans, mul(f[j - 1], g[n - j]));
}
std::cout << ans << '\n';
return 0;
}
| #include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int N = 105;
const int MOD = 1e9 + 7;
const long long INF = 5e18;
const double PI = 2 * acos(0.0);
#define debug(x) cerr << #x << " :: " << x << '\n';
//template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
long long x, a[N], dp[2][N][N][N];
int n, COL, K;
long long fun(int pos, int cnt, int rem) {
if (pos == n || cnt == K) {
long long vaL = x - rem;
if (vaL % K == 0 && cnt == K) {
return vaL / K;
}
return INF;
}
long long &tmp = dp[0][pos][cnt][rem];
long long &vmp = dp[1][pos][cnt][rem];
if (vmp == COL) {
return tmp;
}
vmp = COL;
tmp = INF;
long long vaL = a[pos] + rem;
tmp = min(tmp, fun(pos + 1, cnt, rem));
tmp = min(tmp, fun(pos + 1, cnt + 1, vaL % K) - (vaL / K));
return tmp;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> x;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
long long ans = INF;
for (int i = 1; i <= n; i++) {
COL++, K = i;
ans = min(ans, fun(0, 0, 0));
}
cout << ans << '\n';
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string X;
cin >> X;
for(int i = 0; i < X.size(); i++){
if(X.at(i) == '.') break;
cout << X.at(i);
}
cout << endl;
} | #include <iostream>
#include <iomanip>
#include <algorithm>
#include <assert.h>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#include <chrono>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=a;i<b;++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,a) rrepi(i,a,0)
#define rrepi(i,a,b) for(ll i=a-1;i>=b;--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
for (auto i = first;i != last;i++){
cin >> (*i);
}
}
template<class itr> void array_output(itr start,itr goal){
string ans = "",k = " ";
for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
if (!ans.empty()) ans.pop_back();
PRINT(ans);
}
ll gcd(ll a, ll b) {
return a ? gcd(b%a,a) : b;
}
const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ll MOD3 = 1e6;
const ll EPS = 1e-10;
int sgn(const double a){
return (a < -EPS ? -1 : (a > EPS ? +1 : 0));
}
typedef pair<int,int> pi;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> tri;
typedef pair<double,double> point;
typedef complex<double> Point;
typedef string::const_iterator State;
const ll MAX = 125000;
constexpr ll nx[4] = {-1,0,1,0};
constexpr ll ny[4] = {0,1,0,-1};
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
string s;
cin >> s;
string ans = "";
rep(i,s.length()){
if (s[i] == '.') break;
ans += s[i];
}
PRINT(ans);
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb emplace_back
#define mp make_pair
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define run ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0);
#define LL_MAX LLONG_MAX
#define ub(v,x) upper_bound(v.begin(),v.end(),x)
#define lb(v,x) lower_bound(v.begin(),v.end(),x)
#define mod 1000000007
int exp(int x,int y){int res=1;x=x%mod;while(y>0){if(y&1)res=(res*x)%mod;y=y>>1;x=(x*x)%mod;}return res;}
int modinv(int x){return exp(x,mod-2);}
int add(int a,int b){a%=mod,b%=mod;a=((a+b)%mod+mod)%mod;return a;}
int sub(int a,int b){a%=mod,b%=mod;a=((a-b)%mod+mod)%mod;return a;}
int mul(int a,int b){a%=mod,b%=mod;a=((a*b)%mod+mod)%mod;return a;}
int fac[1000009];int ncr_mod(int n,int k){int ans=fac[n];ans*=modinv(fac[k]);ans%=mod;ans*=modinv(fac[n-k]);ans%=mod;return ans;}
vector<int>v_prime;void Sieve(int n){bool prime[n + 1];memset(prime,true,sizeof(prime));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])v_prime.pb(p);}
vector<int>v_factor;void factor(int n){ for (int i=1; i<=sqrt(n); i++) {if (n%i == 0) {if (n/i == i) v_factor.pb(i);else { v_factor.pb(i),v_factor.pb(n/i);};} } sort(all(v_factor)); }
int power(int x, int y){int temp;if( y == 0)return 1; temp = power(x, y / 2);if (y % 2 == 0) return temp * temp;else return x * temp * temp;}
int gcd(int a, int b){if (b == 0)return a; return gcd(b, a % b);}
int log2n( int n){ return (n > 1) ? 1 + log2n(n / 2) : 0;}
void out(vector<int>&a){for(int i=0;i<a.size();i++) cout<<a[i]<<" "; cout<<endl;}
void sout(set<int>s){for(auto it=s.begin();it!=s.end();++it)cout<<*it<<" "; cout<<endl;}
void mout(map<int,int>mm){for(auto it=mm.begin();it!=mm.end();++it) cout<<it->fi<<" "<<it->se<<endl;}
#define ms(a,x) memset(a, x, sizeof(a));
#define decimal(n,k) cout<<fixed<<setprecision(k)<<n<<endl
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
// debug functions
#define deb1(x) cout << #x <<" " << x <<endl
#define deb2(x,y) cout << #x <<" "<< x << " " << #y <<" " << y <<endl
#define deb3(x, y, z) cout << #x <<" " << x << " " << #y <<" " << y << " " << #z << " " << z<<endl
// In binary search always report l-1
signed main()
{
run;
/*
open for mod factorial
fac[0]=1;
for(int i=1;i<1000009;i++)
{
fac[i]=mul(fac[i-1],i);
}
*/
/*
for sieve open this and use v_prime
int pp=pow(10,6)+100000;
Sieve(pp);
*/
// factor(n) && USE v_factor For calculating factors && don't forget v_factor.clear();
int t=1;
while(t--)
{
// map<int,int>mm; // it->second-->frequency
int n,i,x,y,ok=0,sum=0,ans=0,j,k,cnt=0,m,c=0,q,z;
int h[100009]={0};
cin>>x>>y;
if(x==y)
cout<<y<<endl;
else
{
sum+=x+y;
cout<<3-sum<<endl;
}
}
} | #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define repn(i,n) for(int i=1;i<=n;++i)
#define LL long long
#define pii pair <int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
using namespace std;
const LL MOD=1e9+7;
int main()
{
int a,b;
cin>>a>>b;
if(a==b) cout<<a<<endl;
else
{
if(a>b) swap(a,b);
if(a==0&&b==1) cout<<2<<endl;
else if(a==0&&b==2) cout<<1<<endl;
else cout<<0<<endl;
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main(){
ios::sync_with_stdio(0),cin.tie(0);
int n,m,q;
cin >> n;
int x[n],y[n];
for(int i=0;i<n;i++)
cin >> x[i] >> y[i];
cin >> m;
vector <pair <int,int> > op,ans;
vector <pair <int,int> > qry[m];
for(int i=0;i<m;i++){
int t,p=0;
cin >> t;
if(t>2)cin >> p;
op.push_back({t,p});
}
cin >> q;
ans.resize(q);
int s=0,fx=1,fy=1,dx=0,dy=0;
for(int i=0;i<q;i++){
int a,b;
cin >> a >> b;
b--;
a--;
if(a==-1){
ans[i]={x[b],y[b]};
continue;
}
qry[a].push_back({b,i});
}
for(int i=0;i<m;i++){
auto [t,p]=op[i];
if(t==1){
s^=1;
swap(fx,fy);
swap(dx,dy);
fy=-fy;
dy=-dy;
}
if(t==2){
s^=1;
swap(fx,fy);
swap(dx,dy);
fx=-fx;
dx=-dx;
}
if(t==3){
fx=-fx;
dx=-dx;
dx+=2*p;
}
if(t==4){
fy=-fy;
dy=-dy;
dy+=2*p;
}
for(auto &[j,id]:qry[i]){
int tx=x[j],ty=y[j];
if(s)swap(tx,ty);
tx*=fx,ty*=fy;
tx+=dx,ty+=dy;
ans[id]={tx,ty};
}
}
for(auto [tx,ty]:ans)
cout << tx << ' ' << ty << '\n';
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define forn(i,x,n) for(int i = x;i <= n;++i)
typedef pair<int,int> pii;
#define x first
#define y second
const int N = 3,_N = 2e5 + 7;
struct mat
{
ll m[N][N];
};
pii a[_N];
mat op[_N];
mat mul(mat A,mat B,int len)
{
mat c;memset(c.m,0,sizeof c.m);
for(ll i = 0;i < len;++i)
for(ll j = 0;j < len;++j)
for(ll k = 0;k < len;++k)
{
c.m[i][j]=(c.m[i][j]+(A.m[i][k]*B.m[k][j]));
}
return c;
}
mat qpow(mat a,ll len,ll k)
{
mat res;memset(res.m,0,sizeof res.m);
for(ll i = 0;i < len;++i) res.m[i][i] = 1;
while(k)
{
if(k & 1) res = mul(res,a,len);
a = mul(a,a,len);
k >>= 1;
}
return res;
}
int main()
{
int n;scanf("%d",&n);
forn(i,1,n) scanf("%d%d",&a[i].x,&a[i].y);
int m;scanf("%d",&m);
forn(i,1,m)
{
int t;scanf("%d",&t);
mat _;memset(_.m,0,sizeof _.m);
if(t == 1)
{
_.m[0][1] = -1;_.m[1][0] = 1;_.m[2][2] = 1;
op[i] = mul(op[i - 1],_,3);
}
else if(t == 2)
{
_.m[0][1] = 1;_.m[1][0] = -1;_.m[2][2] = 1;
op[i] = mul(op[i - 1],_,3);
}
else if(t == 3)
{
int p;scanf("%d",&p);
_.m[0][0] = -1;_.m[1][1] = 1;_.m[2][0] = 2 * p;_.m[2][2] = 1;
op[i] = mul(op[i - 1],_,3);
}
else
{
int p;scanf("%d",&p);
_.m[0][0] = 1;_.m[1][1] = -1;_.m[2][1] = 2 * p;_.m[2][2] = 1;
op[i] = mul(op[i - 1],_,3);
}
if(i == 1) op[i] = _;
}
int q;scanf("%d",&q);
while(q--)
{
int A,B;scanf("%d%d",&A,&B);
if(A == 0) printf("%d %d\n",a[B].x,a[B].y);
else
{
mat gamma;memset(gamma.m,0,sizeof gamma.m);
gamma.m[0][0] = a[B].x,gamma.m[0][1] = a[B].y,gamma.m[0][2] = 1;
gamma = mul(gamma,op[A],3);
printf("%lld %lld\n",gamma.m[0][0],gamma.m[0][1]);
}
}
return 0;
} |
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(){
int n, k;
int ans = 0;
cin >> n >> k;
for (int i = 100; i <= n * 100; i += 100) {
for (int j = 1; j <= k; j++) {
ans += i + j;
}
}
cout << ans << endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repn(i,a,b) for(int i=a;i>=b;i--)
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define mod 1000000007
int fexp(int a, int b,int m){int ans = 1;while(b){if(b&1)ans=(ans*a)%m; b/=2;a=(a*a)%m;}return ans;}
int inverse(int a, int p){return fexp(a, p-2,p);}
// int fac[2000001];
// int nCrModPFermat(int n, int r,int p) {
// // cout<<1<<endl;
// if (r==0) return 1;
// return (((fac[n]*((((inverse(fac[r],p)%p)*inverse(fac[n-r],p))%p))))%p);
// }
// vi spf(10000001,1);
void solve(){
int n,k;cin>>n>>k;
int val=(k)*(k+1)/2;
int temp=(n)*(n+1)/2;
cout<<(temp*100*k+val*n);
}
signed main(){
IOS;
auto start = high_resolution_clock::now();
int t=1;
// cin>>t;
// spf[1]=1;
// for(int i=2; i<=10000001; i++){
// if(spf[i]==1){
// // allprime.pb(i);
// for(int j=i; j<=10000001; j+=i)
// if(spf[j]==1)spf[j]=i;
// }
// }
// fac[0] = 1;
// for (int i=1 ; i<=200001; i++) fac[i] = fac[i-1]*i%mod;
rep(i,0,t){
// cout<<"Case #"<<i+1<<": ";
solve();
cout<<"\n";
}
auto stop = high_resolution_clock::now();
auto duration = duration_cast<microseconds>(stop - start);
cerr<<"Time taken:"<<duration.count()/1000000.0<<"seconds"<<"\n";
// return 0;
} |
#include <cstdio>
int n;
int main(){
scanf("%d", &n);
printf("%d\n", (1 << n) - 1);
for(int i = 1; i < (1 << n); ++i){
for(int j = 0; j < (1 << n); ++j)
if(__builtin_popcount(i & j) & 1) putchar('A');
else putchar('B');
puts("");
}
return 0;
} | #include<iostream>
#include<algorithm>
#include<math.h>
#include<cstring>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<string.h>
using namespace std;
long long int a[300001];
long long int b[300001];
long long int amax[200001];
string func0(string s);
string func1(string s);
string func2(string s);
int main() {
int n;
cin >> n;
int bi[9] = { 1,2,4,8,16,32,64,128,256 };
cout << bi[n] - 1 << endl;
string ab[256], abold[256];
int i, j;
ab[0] = "AB";
for (i = 2; i <= n; i++) {
for (j = 0; j < 256; j++) {
abold[j] = ab[j];
}
ab[0] = func0(abold[0]);
for (j = 0; j < bi[i - 1] - 1; j++) {
ab[j+1] = func1(abold[j]);
}
for (j = 0; j < bi[i - 1]-1; j++) {
ab[j + bi[i - 1]] = func2(abold[j]);
}
}
for (i = 0; i < bi[n]-1; i++) {
cout << ab[i] << endl;
}
return 0;
}
string func0(string s) {
return s + s;
}
string func1(string s) {
int i;
string t = "";
for (i = 0; i < s.size(); i++) {
if (s[i] == 'A') {
t = t + "AA";
}
else if(s[i] == 'B') {
t = t + "BB";
}
}
return t;
}
string func2(string s) {
int i;
string t = "";
for (i = 0; i < s.size(); i++) {
if (s[i] == 'A') {
t = t + "AB";
}
else if (s[i] == 'B') {
t = t + "BA";
}
}
return t;
} |
#include <bits/stdc++.h>
using namespace std;
long long int MOD = 1000000007;
long long int modpow(long long int a, long long int n) {
long long int res = 1;
while (n > 0) {
if (n & 1) res = res * a % MOD;
a = a * a % MOD;
n >>= 1;
}
return res;
}
int main() {
long long int N, P;
cin >> N >> P;
long long int ans = (P - 1) * modpow(P - 2, N - 1) % MOD;
if (ans < 0) ans += MOD;
cout << ans << endl;
} | #include<iostream>
#include<iterator>
#include<algorithm>
#include<climits>
#include<map>
#include<set>
#include<numeric>
#include<string>
#include<sstream>
#include<cstdio>
#define ll long long
using namespace std;
int main()
{
int i, j;
cin >> i >> j;
cout << (abs(i-j)<3?"Yes":"No");
} |
#include<bits/stdc++.h>
#define int long long
using namespace std;
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<<3)+(x<<1)+(ch^48); ch=getchar(); }
return x * f;
}
const int N = 3007, mod = 998244353;
int n,K;
int f[N][N];
int DP(int i,int k) {
if(k>i || k==0) return 0; //先要判断是否越界,如果 k>i 可以会爆数组 f[N][N] 的下表,因为 N=3007
if(f[i][k] != -1) return f[i][k];
if(i == k) return f[i][k] = 1;
return f[i][k] = (DP(i-1,k-1) + DP(i,2*k)) % mod;
}
signed main()
{
n = read(), K = read();
memset(f, -1, sizeof(f));
printf("%lld\n",DP(n,K));
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define reps(i, a, n) for (int i = (a); i < (n); ++i)
#define rep(i, n) reps(i, 0, n)
#define deps(i, a, n) for (int i = (a); i >= (n); --i)
#define dep(i, n) deps(i, n, 0)
#define inf 2147483647
#define mod 1000000007
#define int long long
int x, y;
map<int, int> mp;
int absll(int a)
{
if (a > 0) return a;
return -a;
}
int func(int a)
{
if (mp.find(a) != mp.end()) return mp[a];
if (a == 1) return mp[a] = absll(x - a);
if (a % 2 == 0) return mp[a] = min(absll(x - a), func(a / 2) + 1);
return mp[a] = min(absll(x - a), min(func((a + 1) / 2) + 2, func((a - 1) / 2) + 2));
}
signed main(void)
{
cin >> x >> y;
cout << func(y) << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
const int mxn=3e5+5;
vector<int>a(mxn);
template<typename T>
struct segtree {
const int n;
vector<T> stree;
segtree(int n) : n(n), stree(4*n) {}
void build(int id,int l,int r){//build segment tree
if(r-l<2){
stree[id]=a[l];
return;
}
int mid=(l+r)/2;
build(2*id,l,mid);
build(2*id+1,mid,r);
stree[id]=stree[2*id]^stree[2*id+1];
}
void modify(int p,T x,int id,int l,int r){//here we change pth position to x(0-based)
stree[id]^=x;
if(r-l<2){
a[p]=x;
return;
}
int mid=(l+r)/2;
if(mid>p)
return modify(p,x,2*id,l,mid);
else
return modify(p,x,2*id+1,mid,r);
}
T query(int x,int y,int id,int l,int r){//sum from x to y
if(x >= r or l >= y) return 0;
if(x <= l && r <= y) return stree[id];
int mid = (l+r)/2;
return query(x, y, id * 2, l, mid)^query(x, y, id * 2 + 1, mid, r);
}
};
int main() {
int i,n,q;
cin>>n>>q;
for(i=0;i<n;i++)
cin>>a[i];
segtree<int>st(n+1);
st.build(1,0,n+1);
for (i=0;i<q;i++) {
int c,x,y;
cin>>c;
if(c==1){
cin>>x>>y;
st.modify(x-1,y,1,0,n+1);
}
else{
cin>>x>>y;
cout<<st.query(x-1,y,1,0,n+1)<<'\n';
}
}
}
| #include <vector>
#include <array>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>
using namespace std;
int main(int argc, char** argv) {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(12);
int n;
cin >> n;
int m;
cin >> m;
vector<int> A(m);
vector<int> B(m);
vector<int> C(m);
for (int i = 0; i < m; ++i) {
cin >> A[i] >> B[i] >> C[i];
--A[i], --B[i];
}
vector<vector<int>> graph(n);
vector<vector<int>> rgraph(n);
for (int i = 0; i < m; ++i) {
int u = A[i];
int v = B[i];
graph[u].push_back(i);
rgraph[v].push_back(i);
}
const long long INF = 1LL << 40;
vector<long long> dis(n, INF);
using PII = pair<long long,int>;
priority_queue<PII, vector<PII>, greater<PII>> pq;
auto dijkstra = [&](int s) -> long long {
fill(dis.begin(), dis.end(), INF);
dis[s] = 0;
pq.emplace(0, s);
while (!pq.empty()) {
int u = pq.top().second;
auto d = pq.top().first;
pq.pop();
if (d != dis[u]) {
continue;
}
for (auto e : graph[u]) {
int v = B[e];
long long w = C[e];
if (dis[v] > d + w) {
dis[v] = d + w;
pq.emplace(dis[v], v);
}
}
}
long long res = INF;
for (auto e : rgraph[s]) {
int v = A[e];
long long w = C[e];
res = min(res, dis[v] + w);
}
if (res >= INF) {
return -1;
}
return res;
};
for (int i = 0; i < n; ++i) {
cout << dijkstra(i) << '\n';
}
return 0;
} |
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("fast-math")
#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 deb(x) cout << #x << " is " << x << "\n"
#define int long long
#define MOD 1000000007LL
#define PI acos(-1)
template <typename T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <typename T>
using max_heap = priority_queue<T>;
template <class T>
using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename... T>
void read(T &...args) {
((cin >> args), ...);
}
template <typename... T>
void write(T &&...args) {
((cout << args), ...);
}
template <typename T>
void readContainer(T &t) {
for (auto &e : t) {
read(e);
}
}
template <typename T>
void writeContainer(T &t) {
for (const auto &e : t) {
write(e, " ");
}
write("\n");
}
void solve(int tc) {
long double r, x, y;
read(r, x, y);
long double num = sqrt((x * x) + (y * y));
if (num < r) {
write(2, "\n");
return;
} else if (num == r) {
write(1, "\n");
return;
}
int ans = ceil(num / r);
write(ans, "\n");
}
signed main() {
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
ios::sync_with_stdio(false);
cin.tie(nullptr);
int tc = 1;
// read(tc);
for (int curr = 1; curr <= tc; ++curr) {
solve(curr);
}
return 0;
} | // C - Compass Walking
#include <bits/stdc++.h>
using namespace std;
int main(){
int64_t d2, ok, ng, m, r, x, y; cin>>r>>x>>y;
d2 = x*x + y*y;
ok = 0, ng = 1e6;
while(ng - ok > 1){
m = (ok + ng) / 2;
__int128_t rm2 = (__int128_t)r*r*m*m;
(rm2 < d2? ok:ng) = m;
}
cout<< ok + 1 + (d2 < r*r) <<endl;
}
|
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
int main()
{
ll a, b;
cin >> a >> b;
if(abs(a - b) < 3)
puts("Yes");
else puts("No");
}
| #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define ub upper_bound
#define lb lower_bound
#define all(v) ((v).begin()),((v).end())
#define allr(v) ((v).rbegin()),((v).rend())
#define ff first
#define ss second
#define mp make_pair
#define pll pair<ll,ll>
#define fo(i,n) for(ll i=0;i<n;i++)
#define foa(i,s,e) for(ll i=(s);i<=e;i++)
#define fod(i,s,e) for(ll i= (s);i>=(e);i--)
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n'
#define sz(x) (ll)(x.size())
#define ANS cout<<ans<<'\n'
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
#define Yes cout<<"Yes\n"
#define No cout<<"No\n"
const ld pi = 3.14159265358979323846;
//ll MOD = 1e9 + 7;
ll MOD = 998244353;
const char nl = '\n';
const ll inf = 1e15;
#define fill(a,b) memset(a, b, sizeof(a))
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) fo(i, n){fo(j, m)cout<<dp[i][j]<<" ";cout<<"\n";}
ll nxt(){ll x; cin >> x; return x;}
ll mul(ll x,ll y){
return (1ll* (x%MOD)*(y%MOD));
}
ll modpow(ll x,ll y){ll z=1;while(y>0){if(y%2)z=mul(z,x);x =mul(x,x) ;y/=2;}return z;}
ll power(ll x,ll y){ll z=1;while(y>0){if(y%2)z=z*x;x =x*x ;y/=2;}return z;}
ll gcd(ll a,ll b){if(a<b) return gcd(b,a);if(b==0) return a;return gcd(b,a%b);}
ll min(ll a,ll b){if(a<b)return a;return b;}
ll max(ll a,ll b){if(a>b)return a;return b;}
ll sq(ll a){
ll ans = (1ll*a*a);
return ans;
}
void solve(){
ll x,y;
cin >> x >> y;
if(abs(x - y) < 3){
Yes;
}
else No;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("inputf.txt" , "r" , stdin) ;
freopen("outputf.txt" , "w" , stdout) ;
freopen("error.txt" , "w" , stderr) ;
#endif
ll TC = 1;
//cin>>TC;
fo(TT, TC){
// Google,FB cout << "Case #"<< TT + 1 << ": ";
solve();
}
cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}
|
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 998244353;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long double PI = acos(-1.0);
// cout << fixed << setprecision(14);
signed main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
int A, B, C;
cin >> A >> B >> C;
A = (A+1)*A/2;
B = (B+1)*B/2;
C = (C+1)*C/2;
A %= MOD;
B %= MOD;
C %= MOD;
B = A*B % MOD;
C = B*C % MOD;
cout << C << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int long long
#define pb push_back
#define rb pop_back
#define mp make_pair
#define pii pair<int,int>
#define vi vector<int>
#define mii map<int,int>
#define un_mii unordered_map<int,int>
#define pqb priority_stack<int>
#define pqs priority_stack<int,vi,greater<int> >
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x,y) fixed<<setprecision(y)<<x
#define all(x) (x).begin(),(x).end()
#define double long double
#define pi 3.14159265358979323846
int moduloExp(int a, int b, int n) {
int result = 1;
while (b > 0) {
if ((b & 1) == 1) {
result = ((result % n) * (a % n)) % n;
}
a = ((a % n) * (a % n)) % n;
b = b >> 1;
}
return result % n;
}
int inverseModulo(int a, int m){
return moduloExp(a,m-2,m);
}
int power(int a, int b) {
int result = 1;
while (b > 0) {
if (b & 1) {
result *= a;
}
a = a * a;
b >>= 1;
}
return result;
}
int gcd(int a, int b) {
if (b == 0) {
return a;
}
return gcd(b, a % b);
}
// GRAPH
// class Graph{
// public:
// vector<int> g[100005];
// int V;
// Graph(int v){
// V=v;
// }
// void addEdge(int x, int y){
// g[x].pb(y);
// g[y].pb(x);
// }
// int bfs(){
// map<int,int> dist;
// for(int i=0;i<V;i++){
// dist[i]=INT_MAX;
// }
// dist[0]=0;
// queue<int> pendingNodes;
// pendingNodes.push(0);
// while(!pendingNodes.empty()){
// int current_node=pendingNodes.front();
// pendingNodes.pop();
// for(auto i:g[current_node]){
// if(dist[i]==INT_MAX){
// pendingNodes.push(i);
// dist[i]=dist[current_node]+1;
// }
// }
// }
// return dist[V-1];
// }
// };
// PRIME SEIVE
// const int N=1000001;
// int arr[N];
// vi primes;
// void seive(){
// for(int i=0;i<N;i++){
// arr[i]=i;
// }
// for(int i=2;i<N;i++){
// if(arr[i]==i){
// primes.pb(i);
// for(int j=i*i;j<N;j+=i){
// arr[j]=i;
// }
// }
// }
// }
// NCR
// int fact[1005]={0};
// int invfact[1005]={0};
// void preCompute(){
// fact[0]=1;
// fact[1]=1;
// for(int i=2;i<1005;i++){
// fact[i]=((fact[i-1]%mod)*(i%mod))%mod;
// }
// for(int i=0;i<1005;i++){
// invfact[i]=inverseModulo(fact[i],mod);
// }
// }
// int ncr(int n, int r){
// int ans=((fact[n]%mod)*((invfact[n-r]*invfact[r])%mod))%mod;
// return ans;
// }
void solve() {
int a,b,c;cin>>a>>b>>c;
if(c==0){
if(a>b){
cout<<"Takahashi";
}
else{
cout<<"Aoki";
}
}
else{
if(a<b){
cout<<"Aoki";
}
else{
cout<<"Takahashi";
}
}
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;
struct union_find{
vector<int> rnk, par;
union_find(int n){
rnk.resize(n);
par.resize(n);
for(int i = 0; i < n; i++){
par[i] = i;
rnk[i] = 0;
}
}
int find(int x){
if (par[x] == x) return x;
return par[x] = find(par[x]);
}
void unite(int x, int y){
x = find(x);
y = find(y);
if (x == y)return;
if (rnk[x] < rnk[y]){
par[x] = y;
}
else{
par[y] = x;
if (rnk[x] == rnk[y])rnk[x]++;
}
}
bool same(int x, int y){
return find(x) == find(y);
}
};
vector<vector<P>> g;
int main(){
cin.tie(0); ios::sync_with_stdio(false);
ll n, m; cin >> n >> m;
g.resize(n);
ll u[m], v[m], c[m];
zep(j, 0, m){
cin >> u[j] >> v[j] >> c[j];
u[j]--;
v[j]--;
c[j]--;
g[u[j]].push_back(P(v[j], c[j]));
g[v[j]].push_back(P(u[j], c[j]));
}
ll ans[n];
ans[0] = 0;
queue<ll> q;
q.push(0);
bool use[n]; memset(use, 0, sizeof(use));
while(!q.empty()){
ll at = q.front(); q.pop();
use[at] = true;
zep(j, 0, g[at].size()){
ll nx = g[at][j].first;
ll la = g[at][j].second;
if(!use[nx]){
q.push(nx);
if(ans[at] != la){
ans[nx] = la;
}else{
ans[nx] = (la + 1) % n;
}
}
}
}
zep(i, 0, n){
print(ans[i] + 1)
}
return 0;
} | #include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define sz(a) ((int)a.size())
#define re return
#define all(a) a.begin(),a.end()
#define int long long
#define Type int
#define rept(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,a) rept(i,0,a)
using namespace std;
const int mod=998244353;
const int mul=332748118;
const int D[4]={mul*2,0,1,1};
const int R[4]={mul*2,1,0,1};
int fac;
int n,m,k;
int f[5005][5005];
int dp[5005][5005];
int num(){
char c;cin>>c;
if (c=='R') re 1;
if (c=='D') re 2;
re 3;
}
void o(int l){
fac=1;
rep(i,l) fac=fac*3%mod;
}
signed main()
{
cin>>n>>m>>k;
o(n*m-k);
rep(i,k){
int a,b;
cin>>a>>b;
f[a-1][b-1]=num();
}
for (int i=n-1;i>=0;i--)
for (int j=m-1;j>=0;j--){
if (i==n-1&&j==m-1){
dp[i][j]=fac;
continue;
}
dp[i][j]+=D[f[i][j]]*dp[i+1][j];
dp[i][j]%=mod;
dp[i][j]+=R[f[i][j]]*dp[i][j+1];
dp[i][j]%=mod;
}
cout<<dp[0][0];
re 0;
}
|
/***"In the name of Allah(swt), the most gracious, most merciful. Allah(swt) blesses with knowledge whom he wants."***/
/*** "ALHAMDULILLAH for Everything..." ***/
/*
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
*/
#include<bits/stdc++.h>
using namespace std;
#define fastt ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define debug printf("Come here!")
#define inf 1000000000000000000
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define mem(a,b) memset(a,b,sizeof(a))
#define clr(x) x.clear()
#define ff first
#define ss second
#define case(x) cout << "Case " << x <<": "
#define md 1000000007
#define pi acos(-1.0)
#define cos(a) cos(a*pi/180)
#define sin(a) sin(a*pi/180)
#define tan(a) tan(a*pi/180)
#define cosi(a) acos(a)/(pi/180)
#define sini(a) asin(a)/(pi/180)
#define tani(a) atan(a)/(pi/180)
#define vl vector <ll>
#define vs vector <string>
#define vc vector <char>
#define vpll vector < pair <ll, ll> >
#define vpsl vector < pair <string, ll> >
#define vpls vector < pair <ll, string> >
#define pql priority_queue<ll>
#define minpql priority_queue<ll,vector<ll>,greater<ll> >
#define setbits(x) __builtin_popcountll(x)
#define zerobits(x) __builtin_ctzll(x)
#define toll(a) atoll(a.c_str())
string tostr(ll a) {stringstream rr;rr<<a;return rr.str();}
ll pow(ll c,ll d){return d==0?:c*pow(c,d-1);}
ll gcd(ll a,ll b) {return b==0? a:gcd(b,a%b);}
ll lcm(ll a,ll b) {return ((a*b)/gcd(a,b));}
int dx[]={-1, 0, 0, 1};
int dy[]={0, -1, 1, 0};
int dx1[]={-1, -1, -1, 0, 0, 0, 1, 1, 1};
int dy1[]={-1, 0, 1, -1, 0, 1, -1, 0, 1};
/* mpp.max_load_factor(0.25); mpp.reserve(1024); */
/* cout << fixed << setprecision(12);*/
ll n, m;
ll power(ll a, ll b){
if(b==0)return 1;
if(b%2==1){
return ((a%m)*(power(a, b-1)%m))%m;
}
else{
ll x = power(a, b/2);
return ((x%m) * (x%m))%m;
}
}
int main()
{
ll k, i, j;
ll x, y, p=0, s=10, h, f=0;
cin>>n>>m;
p = m;
m*=m;
x = power(s, n);
cout<<x/p<<endl;
return 0;
}
| #include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define fixed_setprecision(n) fixed << setprecision((n))
#define execution_time(ti) printf("Execution Time: %.4lf sec\n", 1.0 * (clock() - ti) / CLOCKS_PER_SEC);
#define pai 3.1415926535897932384
#define NUM_MAX 2e18
#define NUM_MIN -1e9
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmax(T& a, T b){ if(a<b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b){ if(a>b){ a=b; return 1; } return 0; }
int H, W, ans;
void dfs(int n, int bit, int A, int B){
if(n==H*W){
ans++;
return;
}
if(bit & 1 << n) return dfs(n + 1, bit, A, B);
if(B) dfs(n+1, bit | 1<<n, A, B-1);
if(A){
if(n%W < W-1 && ~bit << n && ~bit << (n+1)) dfs(n+1, bit | 1<<n | 1<<(n+1), A-1, B);
if(n+W < H*W) dfs(n+1, bit | 1<<n | 1<<(n+W), A-1, B);
}
}
int main() {
int A, B;
cin >> H >> W >> A >> B;
dfs(0, 0, A, B);
cout << ans << endl;
return 0;
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.