code_file1
stringlengths 87
4k
| code_file2
stringlengths 82
4k
|
---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
int N,Q;
cin >> N;
string S;
cin >> S>> Q;
int t,a,b;
char c;
string St;
int Fcnt = 0;
for(int q=0;q<Q;q++){
cin >> t>> a>> b;
a--;
b--;
if(t==1){
if(Fcnt%2==0){
c = S.at(a);
S.at(a) = S.at(b);
S.at(b) = c;
}else{
if(a<N){
a+=N;
}else{
a-=N;
}
if(b<N){
b+=N;
}else{
b-=N;
}
//a=(a+N)%(N*2);
//b=(b+N)%(N*2);
c = S.at(a);
S.at(a) = S.at(b);
S.at(b) = c;
}
}else{
Fcnt++;
/*
St=S;
for(int i=0;i<N;i++){
S.at(i)=S.at(i+N);
S.at(i+N)=St.at(i);
}
*/
}
}
if(Fcnt%2==1){
St=S;
for(int i=0;i<N;i++){
S.at(i)=S.at(i+N);
S.at(i+N)=St.at(i);
}
}
//cout << N << endl;
cout << S << endl;
//cout << Q << endl;
} | #include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <iomanip>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#define rep(i,n) for (int i = 0; i < n; i++)
#define PI 3.1415926535897932384626433832795028
#define INF (1<<29)
#define LINF (1LL<<60)
using namespace std;
using INT = long long;
using P = pair<int,int> ;
int main(){
int n;
string s;
int q;
cin >> n ;
cin >> s >> q;
vector<int> t(q),a(q),b(q);
rep(i,q){
cin >> t[i] >> a[i] >> b[i];
}
vector<int> new_a,new_b;
int cnt=0;
rep(i,q){
if(t[i]==2)cnt = 1 - cnt;
if(t[i]==1){
if(cnt==0){
new_a.emplace_back(a[i]);
new_b.emplace_back(b[i]);
}
else {
if(a[i]>n)new_a.emplace_back(a[i]-n);
else new_a.emplace_back(a[i]+n);
if(b[i]>n)new_b.emplace_back(b[i]-n);
else new_b.emplace_back(b[i]+n);
}
}
}
rep(i,new_a.size()){
char temp = s[new_a[i]-1];
s[new_a[i]-1] = s[new_b[i]-1];
s[new_b[i]-1] = temp;
}
if(cnt==1){
string copy = s;
s.erase(0,n);
copy.erase(n);
s += copy;
}
cout << s << endl;
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using pl = pair<ll, ll>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define fore(i_in,a) for (auto& i_in: a)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pq(T) priority_queue<T, vector<T>, greater<T>>
#define fio() cin.tie(nullptr);ios::sync_with_stdio(false);
#define DEBUG_CTN(v) cerr<<#v<<":";for(auto itr=v.begin();itr!=v.end();itr++) cerr<<" "<<*itr; cerr<<endl
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
template<class T> bool chmax(T &a, const T &b) {if (a<b) { a = b; return true; } return 0;}
template<class T> bool chmin(T &a, const T &b) {if (a>b) { a = b; return true; } return 0;}
template<class T> void print(const T &t) { cout << t << "\n"; }
const ll INF = 1LL << 60;
int main() {
fio();
ll k;
cin >> k;
ll cnt=0;
for (ll a = 1; a <= k; a++) {
for (ll b = 1; b <= k; b++) {
if (a * b > k) {
break;
} else {
cnt += k / (a * b);
}
}
}
print(cnt);
}
| #include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector <int> vi;
typedef vector <vi> vii;
typedef vector <string> vs;
typedef vector <ll> vll;
#define LSB(x) x&(-x)
#define endl "\n"
#define quick ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define fl(a,b,c) for(ll (a)=(b);(a)<(c);++(a))
#define fe(a,b) for(auto &(a) : (b))
#define frl(i,a,b) for(ll (i)=(a);(i)>(b);(i)--)
#define r(a,b) fl(a,0,b)
#define v vector
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define tc(t) while(t--)
#define unS unordered_set
#define unM unordered_map
#define oS set
#define lb lower_bound
#define up upper_bound
#define oM map
#define eb emplace_back
#define pq priority_queue
#define print(x) cout<<(x)<<endl
#define MOD 1000000007
///////////////////// I/O shortcuts ////////////////////////////////
template <typename D>
istream& operator>> (istream &in , vector <D> &arr) {
ll n = arr.size();
r(i, n) {
in >> arr[i];
}
return in;
}
template <typename D>
ostream& operator<< (ostream &in , vector <D> &arr) {
for (auto x : arr) in << x << " ";
in << endl;
return in;
}
template <typename D, typename B>
ostream& operator<< (ostream &in , pair <D, B> &p) {
in << p.f << " " << p.s << endl;
return in;
} template <typename D, typename B>
istream& operator>> (istream &in , pair <D, B> &p) {
in >> p.f >> p.s;
return in;
}
////////////////////////////Global Variables////////////////////////////////
ll i, j, k, l, x, y, z, m, n, a, b, c, r, d, t = 1, ans;
string s;
template<typename A, typename B> A max(A a, B b) {return (a > b) ? a : b;}
template<typename A, typename B> A min(A a, B b) {return (a < b) ? a : b;}
/////////// The Code Starts Here ///////////////////////////////////////
void solve(int tc) {
cin >> n;
if (floor((1.08f)*n) < 206) print("Yay!");
else if (floor((1.08f)*n) == 206) print("so-so");
else print(":(");
}
///////////////////////////////////////////////////////////
int main() {
quick;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
freopen("error.txt", "w", stderr);
#endif
int k = 1;
// cin >> t;
tc(t) solve(k++);
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=1e9+7;
struct edge{
int to;
ll w;
edge(int to,ll w):to(to),w(w){}
};
using Graph=vector<vector<edge>>;
int n,m;
auto dijkstra(int s,Graph G){
vector<ll>dist(n,INF);
dist[s]=0;
priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>>q;
q.push({dist[s],s});
while(!q.empty()){
int v=q.top().second;
ll d=q.top().first;
q.pop();
if(d>dist[v]){continue;}
for(auto e:G[v]){
if(chmin(dist[e.to],dist[v]+e.w)){
q.push({dist[e.to],e.to});
}
}
}
return dist;
}
void solve(){
Graph G(2005);
cin>>n>>m;
vector<int>p(n,INF);
rep(i,m){
int a,b,c;
cin>>a>>b>>c;
a--;b--;
G[a].push_back(edge(b,c));
if(a==b){
chmin(p[a],c);
}
}
vector<vector<ll>>t;
rep(i,n){
auto r=dijkstra(i,G);
t.push_back(r);
}
rep(i,n){
int mn=INF;
rep(j,n){
if(i==j){continue;}
int res=t[i][j]+t[j][i];
chmin(mn,res);
}
if(mn==INF&&p[i]==INF){cout<<-1<<endl;}
else{cout<<min(p[i],mn)<<endl;}
}
}
int main(){
solve();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double dbl;
#define REP(i, n) for (ll i = 0; i < ll(n); ++i)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= ll(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= ll(b); i--)
#define FORA(i, I) for (const auto &i : I)
#define ALL(x) x.begin(), x.end()
#define SIZE(x) ll(x.size())
const ll INF = 1LL << 60;
const ll MOD = 1'000'000'007LL;
const dbl EPS = 1e-12;
const dbl PI = 3.14159265358979323846;
#define coutALL(x) \
for (auto i = x.begin(); i != --x.end(); ++i) \
cout << *i << ' '; \
cout << *--x.end() << endl;
ll myceil(ll a, ll b)
{
return (a + (b - 1)) / b;
}
ll myfloor(ll a, ll b) { return a / b; }
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;
}
using Graph = vector<vector<int>>;
vector<bool> seen;
vector<int> colors;
bool valid(const Graph &G, int v, int color)
{
for (auto nx : G[v])
{
if (colors[nx] == color)
return 0;
}
return 1;
}
void dfs(const Graph &G, int v, vector<int> &nodes)
{
if (seen[v])
return;
nodes.push_back(v);
seen[v] = true;
for (auto next : G[v])
{
dfs(G, next, nodes);
}
}
void colornize(const Graph &G, const vector<int> &nodes, int idx, ll &num)
{
if (idx == nodes.size())
{
num++;
return;
}
for (int color = 1; color <= 3; ++color)
{
if (valid(G, nodes[idx], color))
{
colors[nodes[idx]] = color;
colornize(G, nodes, idx + 1, num);
colors[nodes[idx]] = 0;
}
}
}
void solve()
{
int N, M;
cin >> N >> M;
Graph G(N);
REP(i, M)
{
int a, b;
cin >> a >> b;
--a;
--b;
G[a].push_back(b);
G[b].push_back(a);
}
seen.assign(N, false);
colors.assign(N, 0);
vector<int> nodes;
ll ans = 1;
REP(start, N)
{
if (seen[start])
continue;
nodes.clear();
dfs(G, start, nodes);
ll tmp = 0;
colornize(G, nodes, 0, tmp);
ans *= tmp;
}
cout << ans << endl;
}
signed main()
{
cout << fixed << setprecision(15);
solve();
return 0;
} |
#include "bits/stdc++.h"
using namespace std;
const int MOD=998244353;
long long powMod(long long a,int p){
if(p==1){
return a%MOD;
}
if(p==0){
return 1ll;
}
long long t=powMod(a,p/2);
t*=t;
t%=MOD;
if(p&1){
t*=a;
t%=MOD;
}
return t;
}
long long inv(long long a){
return powMod(a,MOD-2);
}
void solve(){
int n,k;
cin>>n>>k;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
long long fact[k+1];
fact[0]=1ll;
for(int i=1;i<k+1;i++){
fact[i]=i*fact[i-1];
fact[i]%=MOD;
}
long long sum[k+1];
fill(sum,sum+k+1,0ll);
for(int i=0;i<k+1;i++){
for(int j=0;j<n;j++){
sum[i]+=powMod(0ll+a[j],i);
sum[i]%=MOD;
}
}
long long ans[k+1];
fill(ans,ans+k+1,0ll);
for(int i=1;i<k+1;i++){
for(int j=0;j<=i-j;j++){
long long temp=(sum[j]*sum[i-j])%MOD;
temp-=sum[i];
temp%=MOD;
temp=(temp+MOD)%MOD;
temp*=fact[i];
temp%=MOD;
temp*=inv(fact[j]);
temp%=MOD;
temp*=inv(fact[i-j]);
temp%=MOD;
if(j==i-j){
temp*=inv(2ll);
temp%=MOD;
}
ans[i]+=temp;
ans[i]%=MOD;
}
cout<<ans[i]<<'\n';
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t=1;
// cin>>t;
while(t--){
solve();
}
return 0;
} | #include "bits/stdc++.h"
using namespace std;
#define for_(i, s, e) for (int i = s; i < (int) e; i++)
#define for__(i, s, e) for (ll i = s; i < e; i++)
typedef long long ll;
typedef vector<int> vi;
typedef array<int, 2> ii;
#define endl '\n'
ll n, k;
ll nCr(ll v, ll r) {
assert(r == 1 or r == 2);
if (r == 1) return v;
else if (r == 2) return (v*(v-1)) / 2;
}
ll raw(ll v, ll r) {
if (v < 0) return 0;
// assert(r == 2 or r == 3);
return nCr(v+r-1, r-1);
}
ll count(ll v, ll r) {
assert(r == 2 or r == 3);
if (r == 2) {
return raw(v, 2) - 2*raw(v-n, 2) + raw(v-2*n, 2);
}
return raw(v, 3) - 3*raw(v-n, 3) + 3*raw(v-2*n, 3) - raw(v-3*n, 3);
}
int main() {
#ifdef mlocal
freopen("test.in", "r", stdin);
#endif
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> k;
ll s = 3;
while (true) {
ll temp = count(s-3, 3);
if (temp >= k) break;
k -= temp;
s++;
}
// cout << "should be sum " << s << endl;
ll a = 1;
while (true) {
ll temp = count(s-a-2, 2);
if (temp >= k) break;
k -= temp;
a++;
}
// cout << "first should be " << a << endl;
ll b = 1;
while (true) {
ll v = s-a-b-1;
ll temp = (v < n) and (v >= 0);
if (temp >= k) break;
k -= temp;
b++;
}
cout << a << " " << b << " " << s-a-b << endl;
}
|
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_set>
#include <unordered_map>
#define all(a) (a).begin(), (a).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define range(i, a, b) for (ll i = (a); i < (b); i++)
#define pb push_back
#define debug(x) cerr << __LINE__ << ' ' << #x << ':' << (x) << '\n'
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
template<class T> using pri_s = priority_queue<T, vector<T>, greater<T>>;
template<class T> using pri_b = priority_queue<T>;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr int mod1e9 = 1000000007;
constexpr int mod998 = 998244353;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
constexpr ll ten(int n) { return n ? 10 * ten(n - 1) : 1; };
int dx[] = { 1,0,-1,0,1,1,-1,-1 }; int dy[] = { 0,1,0,-1,1,-1,1,-1 };
ll mul(ll a, ll b) { return (a > INF / b ? INF : a * b); }
void fail() { cout << "-1\n"; exit(0); } void no() { cout << "No\n"; exit(0); }
template<class T> void er(T a) { cout << a << '\n'; exit(0); }
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }
template<class T> istream &operator >> (istream &s, vector<T> &v) { for (auto &e : v) s >> e; return s; }
template<class T> ostream &operator << (ostream &s, const vector<T> &v) { for (auto &e : v) s << e << ' '; return s; }
template<class T, class U> ostream &operator << (ostream &s, const pair<T, U> &p) { s << p.first << ' ' << p.second; return s; }
struct fastio {
fastio() {
cin.tie(0); cout.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
cerr << fixed << setprecision(20);
}
}fastio_;
int main() {
int n;
cin >> n;
vector<ll> a(2 * n);
cin >> a;
vector<ll> x(n), y(n);
rep(i, n) {
x[i] = a[i];
y[i] = a[i + n];
}
reverse(all(x));
ll ans = accumulate(all(a), 0ll);
pri_s<ll> p;
rep(i, n) {
p.push(x[i]);
p.push(y[i]);
ans -= p.top(); p.pop();
}
cout << ans << '\n';
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define f first
#define s second
#ifndef LOCAL
#define cerr if(0) cerr
#endif
#pragma GCC diagnostic ignored "-Wunused-result"
void unsyncIO() { ios_base::sync_with_stdio(0); cin.tie(0); }
void setIO(string s = "") {
unsyncIO();
if (s.size()) { freopen((s+".in").c_str(),"r",stdin);
freopen((s+".out").c_str(),"w",stdout); } // for USACO
}
int main() {
setIO();
int n;
cin >> n;
vector<int> a(n);
for (auto& x : a) {
cin >> x;
}
int ans = 0, mx = INT_MIN;
for (int i = 2; i <= 1000; ++i) {
int cnt = 0;
for (auto& x : a) {
if (x % i == 0)
++cnt;
}
if (cnt > mx) {
mx = cnt;
ans = i;
}
}
cout << ans << "\n";
}
|
using namespace std;
#include<string>
#include<cmath>
#include<list>
#include <map>
#include <unordered_map>
#include <set>
#define ll long long
#define ld long double
#define ull unsigned long long
#define ml map<ll,ll>
#define pb push_back
#define mp make_pair
#define ppl pair<ll,ll>
#define F first
#define S second
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define fr(i,a,b) for(ll i=a;i<b;i++)
#define ffr(i,a,b) for(ll i=a;i>=b;i--)
#include<bits/stdc++.h>
#include<vector>
#define vl vector<ll>
#define PI 3.141592654
const ll N = 998244353;
#include<iterator>
#define EPSILON numeric_limits<double>::epsilon()
//vector<vl>vx(202, vl()), vy(202, vl());
//vector<vl> v;
// vl b;
// vector<bool> visited;
// void dfs(ll pnt, ll &ma) {
// ma++;
// fr(i, 0, v[pnt].size()) {
// ll cnt = 0;
// dfs(v[pnt][i], cnt);
// ma = max(cnt, ma);
// }
// b.pb(ma + 1);
// }
// vl pr(N, 0);
// void prime() {
// fr(i, 2, N + 1) {
// if (!pr[i]) {
// for (ll j = i * 2; j <= N; j += i)pr[j] = 1;
// }
// }
// }
// ll gcd(ll a, ll b) {
// if (a == b)return a;
// if (a % b == 0)return b;
// if (b % a == 0)return a;
// if (b > a)return gcd(a, b % a);
// if (a > b)return gcd(a % b, b);
// return 0;
// }
// ll fact(ll n) {
// ll res = 1;
// fr (i, 2, n + 1) res = res * i;
// return res;
// }
// ll nCr(ll n, ll r) {
// return fact(n) / (fact(r) * fact(n - r));
// }
void solve() {
ll a, b, c, d; cin >> a >> b >> c >> d;
cout << (a * d) - (b * c);
}
int main() {
fio;
#ifndef ONLINE_JUDGE
// for getting input
freopen("input.txt", "r", stdin);
//for writing output
freopen("jout.txt", "w", stdout);
#endif
//prime();
ll t;
if (1)
t = 1;
else
cin >> t;
while (t--) {
//cout << "Case #" << h << ": ";
solve();
//h++;
cout << '\n';
}
return 0;
}
| #include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
struct UnionFind{
vector<int> par, siz;
UnionFind(int n) : par(n,-1) , siz(n,1) {}
int root(int x){
if (par[x] == -1) return x;
else return par[x] = root(par[x]);
}
bool issame(int x,int y){
return root(x) == root(y);
}
bool unite(int x,int y){
x = root(x);y=root(y);
if(x == y) return false;
if(siz[x] < siz[y]) swap(x,y);
par[y] = x;
siz[x] += siz[y];
return true;
}
int size(int x){
return siz[root(x)];
}
};
// UnionFind uf(N) とかやってあげると0からN-1までを含むバラバラの集合が手に入る
// root(x) <- ルートを返してくれる,ルートが同じなら同じ集合にいるぞ!
// unite(x.y) <- x,yが含まれている集合を合体させる
int main(){
int a,b,c,d;
cin >> a >> b;
cin >> c >> d;
cout << a*d - b*c << endl;
}
|
#include <bits/stdc++.h>
#define int long long int
#define ll long long int
#define ld long double
#define getFaster ios_base::sync_with_stdio(false), cin.tie(nullptr)
#define rep(i, init, n) for (int i = init; i < (int)n; i++)
#define rev(i, n, init) for (int i = (int)n; i >= init; i--)
#define MOD1 1e9 + 7
#define MOD2 998244353
#define f first
#define s second
#define endl '\n'
#define pii pair<int, int>
#define tii tuple<int, int>
#define all(v) v.begin(), v.end()
#define mt make_tuple
#define precise(i) cout << fixed << setprecision(i)
#define codejam cout << "Case #" << ii + 1 << ": ";
#define impossible cout << "IMPOSSIBLE" << endl;
#define error(s) throw runtime_error(s)
#define hash hash1
std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
int myRand(int R)
{
int val = rng() % R;
assert(val >= 0);
return val;
}
const long double PI = atan(1.0) * 4;
const int32_t INF32 = 2e9 + 7;
const int64_t INF64 = 3e18;
const int32_t LOG = 21;
int32_t MOD = MOD1;
using namespace std;
//-------------------DEBUGGING-------------------------
void my_debugger(string s, int LINE_NUM) { cerr << endl; }
template <typename start, typename... end>
void my_debugger(string s, int LINE_NUM, start x, end... y)
{
if (s.back() != ',')
{
s += ',';
cerr << "LINE(" << LINE_NUM << "): ";
}
int i = s.find(',');
cerr << s.substr(0, i) << " = " << x;
s = s.substr(i + 1);
if (!s.empty())
cerr << ", ";
my_debugger(s, LINE_NUM, y...);
}
#ifdef AJIT
#define debug(...) my_debugger(#__VA_ARGS__, __LINE__, __VA_ARGS__);
#else
#define debug(...) ;
#endif
//-----------------------------------------------------
int32_t main()
{
getFaster;
//files_init();
int tests = 1;
//cin >> tests;
rep(ii, 0, tests)
{
int n;int lim;
cin>>n>>lim;
lim*=100;
int ans=-1;
int sum=0;
rep(i,0,n)
{
int cur,per;
cin>>cur>>per;
if(ans!=-1)continue;
sum+=(per)*cur;
if(sum>lim)
{
ans=i+1;
}
}
cout<<ans<<endl;
}
return 0;
} | #include <bits/stdc++.h>
//#include <atcoder/all>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
if(a < b) {
a = b;
return true;
}
return false;
}
template<class T>
inline bool chmin(T &a, T b) {
if(a > b) {
a = b;
return true;
}
return false;
}
const long long INF = 1e18;
//const ll mod = 1000000007;
void solve() {
ll L, R;
cin >> L >> R;
ll mini = 2 * L;
ll maxi = R;
ll ans = 0;
if(mini <= maxi) {
ll d = maxi - mini + 1;
ans = d * (d + 1) / 2;
}
cout << ans << endl;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll T;
cin >> T;
while(T--) solve();
return 0;
}
|
#include "bits/stdc++.h"
//#include "atcoder/all"
using namespace std;
//using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
//using mint = modint998244353;
//const int mod = 998244353;
const int INF = 1e9;
//const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define endl "\n"
vector<int>pos[2000006];
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N, M;
cin >> N >> M;
vector<int>A(N);
rep(i, N + 1) {
pos[i].push_back(0);
}
rep(i, N) {
cin >> A[i];
pos[A[i]].push_back(i + 1);
}
rep(i, N + 1) {
pos[i].push_back(N + 1);
}
rep(i, N + 1) {
rep2(j, 1, pos[i].size()) {
if ((pos[i][j] - pos[i][j - 1]) > M) {
cout << i << endl;
return 0;
}
}
}
return 0;
} | #include<bits/stdc++.h>
using namespace std ;
#define ll long long
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define pii pair<ll,ll>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
ll power(ll b,ll e,ll m)
{
if(e==0) return 1;
if(e&1) return b*power(b*b%m,e/2,m)%m;
return power(b*b%m,e/2,m);
}
ll power( ll b, ll e)
{
if(e==0) return 1;
if(e&1) return b*power(b*b,e/2);
return power(b*b,e/2);
}
int main()
{
fast
int n,m;
cin>>n>>m;
int a[n];
for(int i=0;i<n;i++)
cin>>a[i];
map<int,int> mm;
set<int>s;
for(int i=0;i<=m;i++)
s.insert(i);
for(int i=0;i<m;i++)
{mm[a[i]]++;if(s.count(a[i]))s.erase(a[i]);}
int ans=*s.begin();
for(int i=m;i<n;i++)
{
mm[a[i-m]]--;
mm[a[i]]++;
if(mm[a[i-m]]==0)
s.insert(a[i-m]);
ans=min(ans,*s.begin());
}
cout<<ans;
return 0;
} |
// C - Exoswap
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
int main(){
int n; cin>>n;
vector<int> ans, P(n); for(auto& x:P) cin>>x, --x; // -1
int l = 0;
rep(r, n){
if(r == n-1 and P[r] != l){ puts("-1"); return 0; }
if(P[r] == l){
for(int i=r-1; i>=l; --i){
ans.push_back(i+1);
P[i+1] = P[i];
}
P[l] = l;
l = r;
}
}
rep(i, n) if(P[i] != i){ puts("-1"); return 0; }
for(auto x:ans) cout<< x <<endl;
}
| #include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<n; i++)
#define rng(i,l,r) for (int i=l; i<r; i++)
#define all(x) begin(x), end(x)
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> using V = vector<T>;
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; }
struct in { template <class T> operator T() { T t; std::cin >> t; return t; } };
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
int dx[8] = {0,1,0,-1,1,1,-1,-1};
int dy[8] = {1,0,-1,0,1,-1,1,-1};
// ノードに方向と伝播する値の総数を記録する
struct Edge {
int to;
ll x;
Edge (int to) : to(to), x(0) {}
};
using Graph = V<V<Edge>>;
auto solve() {
int n = in();
Graph G(n+1);
vector<int> a(n), b(n);
rng(i,1,n) {
cin >> a[i] >> b[i];
G[a[i]].push_back(Edge(b[i]));
G[b[i]].push_back(Edge(a[i]));
}
vector<ll> res(n+1, 0);
vector<int> depth(n+1, 0);
auto getdepth = [&](auto && self, int v, int from, int d=0) -> void {
depth[v] = d;
for (auto e: G[v]) {
if (e.to == from) continue;
self(self, e.to, v, d+1);
}
};
getdepth(getdepth, 1, 0);
int q = in();
rep(i,q) {
int t = in();
int e = in();
ll x = in();
if (t == 1) {
if (depth[a[e]] < depth[b[e]]) {
res[b[e]] -= x;
res[1] += x;
} else {
res[a[e]] += x;
}
} else {
if (depth[a[e]] < depth[b[e]]) {
res[b[e]] += x;
} else {
res[a[e]] -= x;
res[1] += x;
}
}
}
auto propagate = [&](auto && self, int v, int from) -> void {
for (auto e : G[v]) {
if (e.to == from) continue;
res[e.to] += res[v];
self(self, e.to, v);
}
};
propagate(propagate, 1, 0);
rng(i,1,n+1) cout << res[i] << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
solve();
}
|
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a),i##end=(b);i<=i##end;i++)
#define per(i,a,b) for(int i=(a),i##end=(b);i>=i##end;i--)
#define mem(a,b) memset(a,b,sizeof(a))
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ll long long
using namespace std;
template<typename T>void cmax(T&x,T y){if(x<y)x=y;}
template<typename T>void cmin(T&x,T y){if(x>y)x=y;}
inline int read(){
int f=1,x=0;
char ch=getchar();
while(ch>'9'||ch<'0') {if(ch=='-') f=-1;ch=getchar();}
while(ch>='0'&&ch<='9') {x=x*10+ch-'0';ch=getchar();}
return f*x;
}
int a,b,c;
int main(){
a=read(),b=read(),c=read();
int t=min(min(a,b),c);
printf("%d",a+b+c-t);
}
| #include<bits/stdc++.h>
#include<chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace std::chrono;
using namespace __gnu_pbds;
#define ll long long int
#define ull unsigned long long int
#define FOR(I,a,b) for(ll I=a;I<b;I++)
#define FORit(it,a) for(auto it=a.begin();it!=a.end();it++)
#define ROF(I,a,b) for(int I=a;I>=b;I--)
#define vec vector
#define vi vec<int>
#define vll vec<ll>
#define pb push_back
#define pp pop_back
#define all(x) x.begin(),x.end()
#define testcases ll tc;cin>>tc;while(tc--)
#define mem(a,k) memset(a,k,sizeof(a))
#define FF first
#define SS second
#define MP(x,y) make_pair(x,y)
#define rt return
#define br break
#define ct continue
#define elif else if
#define ii pair<ll,ll>
#define vecin(a,n,index) for(int I=index;I<n;I++)cin>>a[I]
#define vecout(a,n,index) for(int I=index;I<n;I++)cout<<a[I]<<" ";cout<<endl;
template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T> using omset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
// ll mod = 1000000007;
// int max_size = 1000001;
// vi sv(max_size, 1);
// vi primes;
// void sieve();
// ll power(ll a, ll b);
// ll powerMod(ll a, ll b, ll mod);
// ll modIn(ll n);
// vll fact(200001);
vec<ii> factorize(ll k) {
vec<ii> v;
for (int i = 2; i * i <= k; i++) {
if (k % i == 0) {
int cnt = 0;
while (k % i == 0) {
k /= i;
cnt++;
}
v.pb({i, cnt});
}
}
if (k > 1)v.pb({k, 1});
rt v;
}
void solve() {
ll k;
cin >> k;
ll res = 0;
FOR(i, 1, k + 1) {
vec<ii> v = factorize(i);
ll tmp = 1;
for (auto p : v) {
tmp *= ((p.SS + 2) * 1ll * (p.SS + 1)) / 2;
}
res += tmp;
}
cout << res << endl;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
// testcases
solve();
}
/*void sieve() {
sv[0] = 0; sv[1] = 0;
for (int i = 2; i * i <= max_size; i++) {
if (sv[i]) {
for (int j = i * i ; j <= max_size; j += i) {
sv[j] = 0;
}
}
}
}*/
/*ll power(ll a , ll b) {
ll res = 1;
while (b) {
if (b % 2) {res *= a; b--;}
else {a *= a; b /= 2;}
}
rt res;
}*/
/*
ll powerMod(ll a, ll b, ll mod) {
ll res = 1;
while (b != 0) {
if (b % 2) {
res = (res % mod * a % mod) % mod;
b--;
}
else {
a = (a % mod * a % mod) % mod;
b /= 2;
}
}
rt res % mod;
}*/
/*
ll modIn(ll n) {rt powerMod(n, mod - 2) % mod;}
*/ |
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <chrono>
#include <climits>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
template <class T1, class T2>
ostream& operator << (ostream& out, const pair <T1, T2> p)
{
out << '(' << p.first << ',' << p.second << ')';
return out;
}
template <class T1, class T2>
istream& operator >> (istream& in, pair<T1, T2> &p)
{
in >> p.first >> p.second;
return in;
}
template <class T>
istream& operator >> (istream& in, vector<T> &v)
{
for (T &x : v)
in >> x;
return in;
}
template <class T>
ostream& operator << (ostream& out, const vector<vector<T>> &v)
{
for (const vector<T> &x : v)
out << x << '\n';
return out;
}
template <class T>
ostream& operator << (ostream& out, const vector<T> &v)
{
for (const T &x : v)
out << x << ' ';
return out;
}
long long gcd (long long a, long long b)
{
if (b > a)
swap(a, b);
return (b ? gcd(b, a % b) : a);
}
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
using tiii = pair<pair<int, int>, int>;
using vi = vector<int>;
using vl = vector<long long>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<long long>>;
#define F first
#define S second
#define First first.first
#define Second first.second
#define Third second
#define mp make_pair
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define per(i,b,a) for (int i = (b); i > (a); i--)
#define all(x) x.begin(), x.end()
#define ret(x) return cout << x, 0;
#define throwex throw runtime_error ("Found the error.");
const int h = 998244353;
signed main()
{
ios::sync_with_stdio(false);
#ifdef ONLINE_JUDGE
cin.tie(nullptr);
cerr.setstate(ios::failbit);
#endif
ll a, b, c;
cin >> a >> b >> c;
ll A = a * (a + 1) / 2 % h, B = b * (b + 1) / 2 % h, C = c * (c + 1) / 2 % h;
cout << (A * B) % h * C % h;
}
| #include<bits/stdc++.h>
using namespace std;
const int mod = 998244353;
int A, B, C;
int qpow(int a, int b)
{
int res = 1;
for(; b > 0; b >>= 1, a = 1ll * a * a % mod) if(b & 1) res = 1ll * res * a % mod;
return res;
}
int S(int n)
{
n %= mod;
return 1ll * n * (n + 1) % mod * qpow(2, mod - 2) % mod;
}
int main()
{
scanf("%d%d%d", &A, &B, &C);
printf("%lld\n", 1ll * S(A) * S(B) % mod * S(C) % mod);
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define INF ((1LL<<62)-(1LL<<31))
typedef long long ll;
int main()
{
int n,k;
cin >> n >> k;
vector<int> a(n),cnt(n,0);
rep(i,n) {
cin >> a[i];
cnt[a[i]]++;
}
int sum=0,nk=k;
for(int i=0;i<=n;i++) {
nk=min(nk,cnt[i]);
sum+=nk;
}
cout << sum << endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fo(i,n) for(int i=0;i<n;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define tr(it,a) for(auto it=a.begin();it!=a.end();it++)
typedef pair<int, int> pii;
typedef pair<long, long> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<pair<int, int>> vpii;
#define FASTIO ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
int main() {
FASTIO
int t = 1;
// cin >> t;
while (t--) {
int n;
cin >> n;
vpii v(n);
fo(i, n) {
cin>>v[i].F;
cin>>v[i].S;
}
int ans = 0;
fo(i, n) {
int x1 = v[i].F;
int y1 = v[i].S;
// cout<<x1<<" "<<y1<<"points"<<endl;
for (int j = i + 1; j < n; j++) {
int delx=v[j].F-x1;
int dely=v[j].S-y1;
// cout<<delx<<" "<<dely<<endl;
if ( abs(dely)<=abs(delx) ) {
ans++;
}
}
}
cout << ans << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>
using namespace std;
using ll =long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vs = vector<string>;
using vvs = vector<vs>;
using vc = vector<char>;
using vvc = vector<vc>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vp =vector<pair<ll,ll>>;
using vvp =vector<vp>;
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; }
const long long INF = 1LL << 60;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define fr(i,a,b) for(int i=a;i<b;i++)
#define pri(a) printf("%.14lf\n",a);
#define MOD 1000000007
#define dup(x,y) (((x)+(y)-1)/(y))
#define fi first
#define se second
#define sz(x) (ll)(x).size()
bool is_int_lround(double x){
return std::lround(x)==x;
}
ll keta(ll x){
ll n=0;
while(x>0){
x /=10 ;
n ++;
}
return n;
}
ll conbi(int n,int m){
cin>>n>>m;
vector<ll> a(100);
a[0] =1;
for(int i=0;i<14;i++){
a[i+1]=a[i]*(i+1);
}
return a[n] /(a[m] *a[n-m]);
}
long long fac[510000], finv[510000], inv[510000];
// テーブルを作る前処理
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < 510000; 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;
}
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;
}
ll kaijo(ll x){
ll z=1;
if(x==0){
return 1;
}
while(x>0){
z *=x;
z %=MOD;
x--;
}
return z;
}
ll yakusu_num(ll n){
vl yakusu(n+1,1);
for(ll i=2;i*i<=n;i++){
while(n%i==0){
n /=i;
yakusu[i]++;
}
}
if(n!=1)yakusu[n]++;
ll num=1;
for(ll i=0;i <=n;i++){
num*=yakusu[i];
}
return num;
}
struct UnionFind {
vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2
UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
for(int i = 0; i < N; i++) par[i] = i;
}
int root(int x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根}
if (par[x] == x) return x;
return par[x] = root(par[x]);
}
void unite(int x, int y) { // xとyの木を併合
int rx = root(x); //xの根をrx
int ry = root(y); //yの根をry
if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける
}
bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
int rx = root(x);
int ry = root(y);
return rx == ry;
}
};
//cout<<""<<endl;
// ./a.out
// g++ 201110.cpp
// ll N;cin>>N;
int main(){
ll M,H ;cin >>M>>H ;
if(H%M==0)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
} | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
using namespace std;
#define getbit(n, i) (((n) & (1LL << (i))) != 0)
#define setbit0(n, i) ((n) & (~(1LL << (i))))
#define setbit1(n, i) ((n) | (1LL << (i)))
#define togglebit(n, i) ((n) ^ (1LL << (i)))
#define lastone(n) ((n) & (-(n)))
char gap = 32;
#define ll long long
#define lll __int128_t
#define pb push_back
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll hashPrime = 1610612741;
string s , x;
ll dp[200005][7];
ll powerOfTen[200005];
void init(ll n){
powerOfTen[0] = 1;
for(ll i = 1;i<=n;i++){
powerOfTen[i] = (powerOfTen[i - 1] * 10 ) % 7;
}
}
ll recurse(ll pos , ll rem , ll n){
if(pos == n){
if(rem == 0)return 1;
else return 0;
}
if(dp[pos][rem] != -1){
return dp[pos][rem];
}
if(x[pos] == 'T'){
ll ans = 0;
ll newRem = (rem + ((s[pos] - '0') * powerOfTen[n - pos - 1]) % 7) % 7;
ans = max(ans , recurse(pos + 1 , newRem , n));
ans = max(ans , recurse(pos + 1 , rem , n));
return dp[pos][rem] = ans;
}
else{
ll ans = 1;
ll newRem = (rem + ((s[pos] - '0') * powerOfTen[n - pos - 1]) % 7) % 7;
ans = min(ans , recurse(pos + 1 , newRem , n));
ans = min(ans , recurse(pos + 1 , rem , n));
return dp[pos][rem] = ans;
}
return 1;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll i,j,k,l,n,m;
cin>>n;
init(n);
cin>>s>>x;
memset(dp , -1 , sizeof(dp));
if(recurse(0 , 0 , n)==1){
cout<<"Takahashi\n";
}
else{
cout<<"Aoki\n";
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
#define pb(a) push_back(a)
#define arr(a) new ll int[a]
#define INF 100000000000000000
#define MOD 1000000007
#define MOD1 998244353
#define arr1(a) new arra[a]
#define str(a) new string[a]
#define all(arr,n,a) for(ll int i=0;i<=n;i++)arr[i]=a
#define mp(a,b) make_pair(a,b)
//const int N = 1000008,p=31;
//ll int pw[N],inv_pw[N],hash2[N+1],hash1[N+1],pw1[N],inv_pw1[N],hash1r[N+1],hash2r[N+1];
////ll fact[N];
////void factorial(){
//// fact[0] = fact[1] = 1;
//// for(ll i = 2; i < N; i++)
//// fact[i] = (fact[i-1] * i) % MOD;
////}
// ll power(ll a, ll b, ll mod){
// ll x = 1, y = a;
// while (b > 0){
// if (b%2){
// x = (x*y)%mod;
// }
// y = (y*y)%mod;
// b /= 2;
// }
// return x%mod;
// }
//ll modular_inverse(ll n, ll mod){
// return power(n, mod-2, mod);
//}
//void precal()
//{
// pw[0]=1;
// pw1[0]=1;
// inv_pw1[0]=1;
// inv_pw[0]=1;
// ll int temp=modular_inverse(p,MOD),temp1=modular_inverse(p,MOD1);
// for(ll int i=1;i<N;i++)
// {
// pw[i]=(pw[i-1]*p)%MOD;
// pw1[i]=(pw1[i-1]*p)%MOD1;
// inv_pw1[i]=(inv_pw1[i-1]*temp1)%MOD1;
// inv_pw[i]=(inv_pw[i-1]*temp)%MOD;
// }
//}
//void build(string& s,ll int hash1[],ll int pw[],ll int mod)
//{
// ll int n=s.size();
// for(ll int i=1;i<=n;i++)
// {
// hash1[i]=(hash1[i-1]+(pw[i-1]*(s[i-1]-'a'+1))%mod)%mod;
// }
//}
//ll int get_hash(ll int hash1[],ll int inv_pw[],ll int mod,ll int l,ll int r)
//{
// if(l>r)return 0;
// ll int res=(hash1[r]-hash1[l-1]+mod)%mod;
// res=(res*inv_pw[l-1])%mod;
// return res;
//}
//ll nCr(ll n, ll k, ll mod){
// return (fact[n]*((modular_inverse(fact[k],MOD)*modular_inverse(fact[n-k],MOD))%mod))%mod;
//}
//struct arra{
// ll int l,r,s,num;
//}arr[300009];
//bool comp(struct arra a,struct arra b)
//{
// return a.d<b.d;
//}
//bool comp1(pair<ll int,ll int>p1,pair<ll int,ll int>p2)
//{
// return p1.first>p2.second;
//}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
ll b,c,t1;
unsigned ll res=1;
cin>>b>>c;
if(b>0)
{
if(c%2==0)
{
t1=c/2;
if(t1<=b)
{
res+=2*t1-1;
}
else{
res+=2*b-1;
}
c--;
res++;
t1=c/2;
res+=2*t1;
}
else{
t1=c/2;
if(t1<=b-1)res+=2*t1;
else if(t1==b)res+=2*t1-1;
else res+=2*b-1;
c--;
res++;
t1=c/2;
if(t1>0)res+=2*t1-1;
}
}
else if(b==0)
{
if(c%2==0)
{
t1=c/2;
if(t1>0)res+=2*t1-1;
}
else{
t1=c/2;
res+=2*t1;
}
}
else{
if(c%2==0)
{
t1=c/2;
if(t1>0)res+=2*t1-1;
c--;
res++;
t1=c/2;
b=abs(b);
if(t1<=b-1)res+=2*t1;
else if(t1==b)res+=2*t1-1;
else res+=2*b-1;
}
else{
t1=c/2;
res+=2*t1;
c--;
res++;
t1=c/2;
b=abs(b);
if(t1<=b)
{
if(t1>0)res+=2*t1-1;
}
else{
res+=2*b-1;
}
}
}
cout<<res;
return 0;
}
| //#include "input.h"
//#include "output.h"
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define NDEBUG
NDEBUG
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cstring>
#include <cmath>
#include <functional>
#include <numeric>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <memory>
#include <queue>
#include <random>
using namespace std;
template<class T>
using vec = std::vector<T>;
#define FOR(i, n) for (int i = 0; i < (n); ++i)
#define all(c) c.begin(), c.end()
// TC_REMOVE_BEGIN
/// caide keep
bool __hack = std::ios::sync_with_stdio(false);
/// caide keep
auto __hack1 = cin.tie(nullptr);
// TC_REMOVE_END
// Section with adoption of array and vector algorithms.
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//
//template <class T> using StdTree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
//bool __hack = std::ios::sync_with_stdio(false);
//auto __hack1 = cin.tie(nullptr);
struct Input {
Input(istream &in) : in(&in) {}
template<class T>
T next() const {
T x;
*in >> x;
return x;
}
int ni() const {
return next<int>();
}
template<class T>
vec<T> nVec(int n) const {
vec<T> v(n);
for (int i = 0; i < n; ++i) {
v[i] = next<T>();
}
return v;
}
vec<int> nvi(int n) const {
return nVec<int>(n);
}
istream *in;
};
Input in(cin);
class Output {
private:
ostream *out;
template<typename T>
void printSingle(const T &value) {
*out << value;
}
public:
Output(ostream &out) : out(&out) {}
inline void print() {}
template<typename T, typename...Ts>
inline void print(const T &f, const Ts&... args) {
printSingle(f);
if (sizeof...(args) != 0) {
*out << ' ';
print(args...);
}
}
template<typename...Ts>
inline void println(const Ts&... args) {
print(args...);
(*out) << '\n';
}
template<typename...Ts>
inline void operator() (const Ts&... args) {
println(args...);
}
};
Output out(cout);
namespace template_util {
constexpr int bytecount(uint64_t x) {
return x ? 1 + bytecount(x >> 8) : 0;
}
template<int N>
struct bytetype {
};
/// caide keep
template<uint64_t N>
struct minimal_uint : bytetype<bytecount(N)> {
};
}
template<typename T> static constexpr T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
// m must be positive
//template <class T>
//T gcd(T a, T b) {
// return b == 0 ? a : gcd(b, a % b);
//}
//TODO extended gcd
// MD implementation of factorials and binomial
// TODO(alf): Tests
//
//int64_t lcm(const vector<int64_t>& a) {
// int64_t res = a[0];
// for (int i = 1; i < (int)a.size(); ++i) {
// int64_t g = gcd(res, a[i]);
// res *= a[i];
// res /= g;
// }
// return res;
//}
//
//int64_t lcm(int64_t a, int64_t b) {
// return (a * b / gcd(a, b));
//}
// Algorithms
void solve(istream& inStream, ostream& outStream) {
in = Input(inStream);
out = Output(outStream);
auto n = in.ni();
auto a = in.nvi(n);
sort(all(a));
int x = a[0];
FOR(i, n) x = gcd(x, a[i]);
out(x);
}
//#include <fstream>
int main() {
// ifstream fin("input.txt");
// ofstream fout("output.txt");
// Input in(in);
// Output out(out);
solve(cin, cout);
// solve(fin, fout);
return 0;
}
|
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<cstring>
#define rg register
#define il inline
using namespace std;
il int read()
{
rg int save=0, w=1;rg char q=getchar();
while(q<'0'||q>'9'){if(q=='-')w=-1;q=getchar();}
while(q>='0'&&q<='9')save=(save<<3)+(save<<1)+q-'0',q=getchar();
return save*w;
}
int main()
{
int n=read(), a=read(), b=read();
cout<<n-a+b<<endl;
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> ordered_set;
#define ll long long
#define ld long double
#define pii pair<int, int>
#define f first
#define s second
#define readl(_s) getline(cin, (_s));
#define boost() cin.tie(0); cin.sync_with_stdio(0)
int main() {
boost();
int x, y;
cin >> x >> y;
if (x > y) swap(x, y);
if (x + 3 > y) printf("Yes\n");
else printf("No\n");
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (lli i = a; i < b; i++)
#define lli long long int
#define ld double
#define all(v) v.begin(), v.end()
#define hell 1000000000000000
#define pb push_back
#define vi vector<lli>
#define vip vector<pair<lli, lli>>
#define F first
#define S second
// #define mod 998244353
// lli n = 10000000;
// int dx[]={1,-1,0,0};
// int dy[]={0,0,1,-1};
// // vector<bool> p(n + 1, true);
// void sieve()
// {
// for (long long int i = 2; i * i <= n; i++)
// {
// if (p[i])
// {
// for (long long int j = i + i; j <= n; j = j + i)
// {
// p[j] = false;
// }
// }
// }
// }
// lli Gcd(lli a, lli b)
// {
// if (a % b == 0)
// {
// return b;
// }
// return Gcd(b, a % b);
// }
// lli power(lli a, lli n,lli mod)
// {
// lli res = 1;
// while (n > 0)
// {
// if (n & 1)
// res = ((res % mod) * (a % mod)) % mod, n--;
// else
// a = ((a % mod) * (a % mod)) % mod, n /= 2;
// }
// return res;
// }
void solve()
{
lli n,x;
cin>>n>>x;
rep(i,0,n)
{
lli a;
cin>>a;
if(a!=x)
{
cout<<a<<" ";
}
}
cout<<endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
// sieve();
lli t = 1;
// cin >> t;
while (t--)
{
solve();
}
} | #include<bits/stdc++.h>
using namespace std;
int main() {
int n, a, b;
cin >> n >> a >> b;
cout << n - a + b << "\n";
return 0;
} |
/* Lucky_Glass */
#include <cstdio>
#include <cstring>
#include <algorithm>
const int N = 105, MOD = 998244353;
inline int add(int a, const int &b) { return (a += b) >= MOD ? a - MOD : a; }
inline int sub(int a, const int &b) { return (a -= b) < 0 ? a + MOD : a; }
inline int mul(const int &a, const int &b) { return int(1ll * a * b % MOD); }
#define ITERON(a, b, fun) a = fun(a, b)
int n;
int dp[2][N * N * 2][N], bino[N][N];
#define f(i, s, k) dp[(i) & 1][(s) + N * N][k]
int main() {
scanf("%d", &n);
f(0, 0, 0) = 1;
for (int i = 1, tmp, sum = 0; i <= n; ++i) {
scanf("%d", &tmp);
for (int s = -sum; s <= sum; ++s)
for (int k = 0; k <= i; ++k)
f(i, s, k) = 0;
for (int s = -sum; s <= sum; ++s)
for (int k = 0; k <= i; ++k) {
ITERON(f(i, s + tmp, k + 1), mul(f(i - 1, s, k), k + 1), add);
ITERON(f(i, s - tmp, k), mul(f(i - 1, s, k), i - k), add);
}
sum += tmp;
}
int ans = 0;
for (int k = 0; k <= n; ++k)
ITERON(ans, f(n, 0, k), add);
printf("%d\n", ans);
return 0;
} | #include <bits/stdc++.h>
using i64 = long long;
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n;
std::cin >> n;
std::set<std::tuple<int, int, int>> s;
std::vector<std::pair<int, int>> a(n);
for (auto &[x, y] : a) {
std::cin >> x >> y;
}
sort(a.begin(), a.end());
s.emplace(std::max(abs(a[n - 1].first - a[0].first), abs(a[n - 1].second - a[0].second)), 0, n - 1);
s.emplace(std::max(abs(a[n - 2].first - a[0].first), abs(a[n - 2].second - a[0].second)), 0, n - 2);
s.emplace(std::max(abs(a[n - 1].first - a[1].first), abs(a[n - 1].second - a[1].second)), 1, n - 1);
std::vector<int> id(n);
iota(id.begin(), id.end(), 0);
sort(id.begin(), id.end(), [&](int i, int j){
if (a[i].second == a[j].second) return a[i].first < a[j].first;
return a[i].second < a[j].second;
});
s.emplace(std::max(abs(a[id[n - 1]].first - a[id[0]].first), abs(a[id[n - 1]].second - a[id[0]].second)), id[0], id[n - 1]);
s.emplace(std::max(abs(a[id[n - 2]].first - a[id[0]].first), abs(a[id[n - 2]].second - a[id[0]].second)), id[0], id[n - 2]);
s.emplace(std::max(abs(a[id[n - 1]].first - a[id[1]].first), abs(a[id[n - 1]].second - a[id[1]].second)), id[1], id[n - 1]);
auto x = s.end();
x--;
x--;
std::cout << std::get<0>(*x) << "\n";
return 0;
} |
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long int ;
using P = pair<ll,ll>;
using Graph= vector<vector<ll>>;
struct edge{ll to ; ll cost ;} ;
using graph =vector<vector<edge>> ;
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
#define fi first
#define se second
#define set20 cout<<fixed<<setprecision(20) ;
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
long double pi=acos(-1) ;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
ll dx[4] {1,0,-1,0} ;
ll dy[4] {0,1,0,-1} ;
struct UnionFind {
vector<int> d;
UnionFind(int n=0): d(n,-1) {}
int find(int x) {
if (d[x] < 0) return x;
return d[x] = find(d[x]);
}
bool unite(int x, int y) {
x = find(x); y = find(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 find(x) == find(y);}
int size(int x) { return -d[find(x)];}
};
int main(){
ios::sync_with_stdio(false) ;
cin.tie(nullptr) ;
ll t ; cin>>t ;
while(t--){
ll n ; cin>>n ;
if(n%2==1) cout<<"Odd"<<endl ;
else if(n%4==0) cout<<"Even"<<endl ;
else cout<<"Same"<<endl ;
}
return 0 ;
}
| #include<bits/stdc++.h>
//=====================START-MACRO=====================
namespace gengar
{
#pragma GCC optimize("Ofast")
using namespace std;
namespace TypeDef
{
#define int long long
#define itn int
#define uint unsigned long long
using Int=int64_t;
using uInt=uint64_t;
#define ld long double
#define P pair<int,int>
#define vt(tp) vector<tp>
#define vvt(nm,tp,h,w,n) vector<vector<tp>>nm((h),vector<tp>(w,n))
#define vvp vector<vector<P>>
#define hmap unordered_map
#define hset unordered_set
#define PQ priority_queue
};
namespace OthDef
{
#define all(x) x.begin(),x.end()
#define nsort(x) sort(all(x))
#define rsort(x) nsort(x);reverse(all(x))
#define unq(v) v.erase(unique(all(v)),v.end())
#define l_b(c,x) distance(c.begin(),lower_bound(all(c),(x)))
#define u_b(c,x) distance(c.begin(),upper_bound(all(c),(x)))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define spc ' '
#define pass
void CIN(){}
template<typename Car,typename... Cdr>
void CIN(Car&&car,Cdr&&...cdr){cin>>car;CIN(forward<Cdr>(cdr)...);}
template<class T>void drop(T x){cout<<(x)<<endl;exit(0);}
void dYes(){puts("Yes");exit(0);}
void dNo(){puts("No");exit(0);}
#define Bit(n) (1LL<<(n))
#define Bitall(n,i) for(int bit=0;bit<(1<<(int)(n));bit++)for(int i=0;i<(int)(n);i++)
#define Bitif(i) if(bit&(1<<i))
};
namespace RepDef
{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(a),__SIZE##_=(b);i<__SIZE##_;i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,n) for(int i=1,__SIZE##_=(n);i<__SIZE##_;i++)
#define repp(i,n) for(int i=0,__SIZE##_=(n);i<=__SIZE##_;i++)
#define per(i,n) for(int i=(n)-1;i>=0;i--)
#define pper(i,n) for(int i=(n)-1;i>=1;i--)
#define perr(i,n) for(int i=(n);i>=0;i--)
};
namespace MathDef
{
const int inf=Bit(60);
const int pi=acos(-1);
const int mod=1000000007;//998244353
#define myceil(a,b) ((a)+((b)-1))/(b)
#define scale(n) cout<<fixed<<setprecision(n)
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
int fact(int n){int f=n;pper(i,n){f*=i;f%=mod;}return f;}
template<class T>int chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>int chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
};
namespace AllDef
{
using namespace TypeDef;
using namespace OthDef;
using namespace RepDef;
using namespace MathDef;
};
using namespace AllDef;
};
using namespace gengar;
//=======================END-MACRO=======================
namespace AHC001
{
//=====================START-AHC001======================
int dst(int a,int b,int c,int d)
{
int ret=sqrt(pow(double(c)-double(a),2)+pow(double(d)-double(b),2));
return ret/2/1.414;
}
//=======================================================
void solve()
{
int n;cin>>n;
vector<int>a(n),b(n),r(n);
rep(i,n)cin>>a[i]>>b[i]>>r[i];
int mindist=inf;
int dist[200];
rep(i,200)dist[i]=inf;
//ここまで入力とか
//dist計算
rep(i,n)for(int j=0;j<n;j++)
{
if(j==i)continue;
chmin(dist[i],dst(a[i],b[i],a[j],b[j]));
chmin(mindist,dst(a[i],b[i],a[j],b[j]));
}
//mindist=0だった時の保険
if(mindist==0)
{
rep(i,n)
{
cout<<a[i]<<spc<<b[i]<<spc;
cout<<a[i]+1<<spc<<b[i]+1<<spc;
cout<<endl;
}
exit(0);
}else//それ以外
{
rep(i,n)
{
int lpdist=dist[i];
if(dist[i]*dist[i]>r[i]/4)lpdist=(int)(sqrt(r[i]))/2;
cout<<max(a[i]-lpdist,0LL)<<spc;
cout<<max(b[i]-lpdist,0LL)<<spc;
cout<<min(a[i]+lpdist,10000LL)<<spc;
cout<<min(b[i]+lpdist,10000LL)<<endl;
}
exit(0);
}
}
//=====================END-AHC001======================
};
using namespace AHC001;
int32_t main()
{
ios::sync_with_stdio(false);
cin.tie(0);
solve();
return 0;
} |
#include <bits/stdc++.h>
#include <list>
using namespace std;
#define rep(i,t,n) for(int64_t i=t;i<n;i++)
#define Sort(a) sort(a.begin(),a.end())
#define rSort(a,n,m) sort(a.begin()+n-1,a.begin()+m)
#define Reverse(a) reverse(a.begin(),a.end())
#define rReverse(a,n,m) reverse(a.begin()+n-1,a.begin()+m)
#define MOD 1000000007
#define sign(i) -1*pow(-1,i)
#define vi(A,N,i) vector<int64_t> A(N,i)
#define vs(A,N,i) vector<string> A(N,i)
#define vb(A,N,i) vector<bool> A(N,i)
#define INF ((1LL<<62)-(1LL<<31))
//((a+b+c)-max(a,max(b,c))-min(a,min(b,c)))
/*template <class T>
}*/
//cout << fixed << setprecision(桁数);
int64_t def_str(string x,string y){
int64_t def=0;
rep(i,0,(int64_t)x.size()){
if(x[i]!=y[i]){
def++;
}
}
return def;
}
////
class ModularExponentiation
{
int64_t ans; // Answer
public:
int64_t compME(int64_t, int64_t, int64_t); // Compute Modular Exponentiation
};
/*
* Compute Modular Exponentiation
*/
int64_t ModularExponentiation::compME(int64_t u, int64_t e, int64_t m)
{
if (e == 0) return 1;
ans = compME(u, e / 2, m);
ans = (ans * ans) % m;
if (e % 2 == 1) ans = (ans * u) % m;
return ans;
}
////
int main() {
int64_t a,b,c,d,f,now_ans=0,mlt_ans=1;
//double a,b,c,d,e,f,ans=0,now_ans=0,mlt_ans=1;
string x,y,z;
char s,t,u;
bool frag=false,frag1=false,frag2=false;
vector<int64_t> A{},B{},C{},D{};
vector<string> Cg{},Dg{};
vector<char> E{},F{};
vector<bool> G(26,false);
cin>>a>>b;
//cin>>x;
//cin>>s>>t;////////////////////////
ModularExponentiation objMain;
c = objMain.compME(b-2, a-1, MOD);
cout<<(c*(b-1))%MOD;
} | #include <iostream>
#include <vector>
#include <string>
#include <array>
#include <functional>
#include <algorithm>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <queue>
#include <bitset>
#include <cassert>
#include <math.h>
#include <complex>
#include <iomanip>
#include <unordered_map>
using namespace std;
#define ll long long
#define pb(x) push_back(x)
#ifdef _OLIMPOLOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 1337
#endif
void debug_out() { cout << "\n";}
template<typename T1, typename... T2> void debug_out(T1 A, T2... B) { cout << " " << A; debug_out(B...); }
int test = 1;
#define out(x) {cout << x << "\n";return;}
#define all(N) N.begin(),N.end()
#define allr(N) N.rbegin(),N.rend()
template<typename T1>
void pr(vector<T1> V, int add = 0, int start = -1, int end = -1) {
if (start < 0) start = 0;
if (end < 0) end = V.size() - 1;
for (int i = start; i <= end; i++) {
cout << V[i] + add << ((i == end) ? "\n" : " ");
}
}
template<typename T1>
T1 chmin(T1 &x, const T1 v) { return x = min(x,v); }
template<typename T1>
T1 chmax(T1 &x, const T1 v) { return x = max(x,v); }
#define rep(i, n) for (int i = 0; i < n; i++)
#define reps(i, s, n) for (int i = s; i < n; i++)
#define repr(i, n) for (int i = n-1; i >= 0; i--)
#define repsr(i, s, n) for (int i = n-1; i >= s; i--)
#define PI pair<int,int>
template<typename T1>
T1 gcd(const T1 &a, const T1 &b) {
if (a == 0 || b == 0) return a + b;
return gcd(b, a %b);
}
//-------------------------- ^ DONT TOUCH ^-----------------------------------------------------------------
#define MAX 500001
#define MOD 1000000007
bool isP(int x) {
for(int i = 2; i *i <= x; i++)
if (x % i == 0)
return 0;
return 1;
}
vector<int> P;
vector<ll> S;
void comb(int i, ll v) {
if (i == P.size()) {
if (v > 1)
S.push_back(v);
return;
}
comb(i+1, v);
comb(i+1, v * P[i]);
}
void solve() {
reps(p, 2, 50)
if (isP(p))
P.push_back(p);
comb(0, 1);
debug(S.size());
sort(all(S));
int n; cin >> n;
vector<int> N(n);
rep(i,n) cin >> N[i];
for(const ll s : S) {
bool f = 1;
for(int i = 0; f && i < n; i++) {
f = (gcd((ll)N[i], s) != 1);
}
if (f) out(s);
}
}
int main() {
ios_base::sync_with_stdio(0);cin.tie(0);
int test = 1;
// #ifdef _OLIMPOLOCAL
//cin >> test;
// #endif
rep(testCase, test) {
#ifdef _OLIMPOLOCAL
cout << "------------------ TESTCASE: " << testCase << " -------------\n";
#endif
solve();
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#ifdef __local_leywar
#include <debug/debugger.h>
#endif
#define int unsigned long long
#define endl '\n'
const int INF = 2e9,
MOD = 1e9+7,
INFLL = 1e18;
using pii = pair<int, int>;
mt19937_64 rng(time(0));
int gcd (int a, int b)
{
return (b == 0 ? a : gcd(b, a%b));
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<int> ar(n);
for(auto &i: ar)
cin >> i;
vector<int> sieve(100), primes;
for(int i = 2 ; i < 50 ; i++)
{
if(!sieve[i])
{
primes.push_back(i);
sieve[i] = 1;
}
for(int j = i * i ; j < 50 ; j += i)
sieve[j] = 1;
}
int ans = INFLL;
for(int mask = 1 ; mask < (1<<15) ; mask++)
{
int res = 1;
bool sol = true;
for(int i = 0 ; i < primes.size() ; i++)
if(mask & (1<<i))
res *= primes[i];
for(int i = 0 ; i < n ; i++)
{
if(gcd(ar[i], res) == 1)
sol = false;
}
if(sol)
ans = min(ans, res);
}
cout << ans ;
return 0;
}
| /*
Date: 2/27/2021 8:09:28 PM
*/
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int a, p, x, n, minn = INF;
int main() {
scanf("%d", &n);
for (register int i = 0; i < n; i++) {
scanf("%d%d%d", &a, &p, &x);
if (x - a > 0 && p < minn) minn = p;
}
minn != INF ? printf("%d\n", minn) : puts("-1");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
map<int, string> vis;
signed main() {
int n; cin >> n;
for ( int i = 0; i < n; ++ i ) {
string s;
int x;
cin >> s >> x;
vis[x] = s;
}
int num = 1;
for ( auto iter: vis ) {
if ( num == vis.size() - 1 ) {
cout << iter.second << endl;
break;
}
num ++;
}
return 0;
} | #include<bits/stdc++.h>
using namespace std;
template <class T> ostream &operator << (ostream &os, const vector<T> &p) { os << "["; for (auto&it : p) os << it << " "; return os << "]";}
template <class S, class T> ostream &operator << (ostream &os, const pair<S, T> &p) { return os << "(" << p.first << "," << p.second << ")";}
#ifndef ONLINE_JUDGE
#define deb(...) dbs(#__VA_ARGS__,__VA_ARGS__)
template <class T> void dbs(string str, T t) { cerr << str << ":" << t << "\n";}
template<class T, class...S> void dbs(string str, T t, S... s) { int idx = str.find(','); cerr << str.substr(0, idx) << ":" << t << ","; dbs(str.substr(idx + 1), s...);}
#else
#define deb(...){}
#endif
#define int long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define ini(x, y) memset(x, y, sizeof(x))
#define pr(x) {cout << x << '\n'; return;}
#define prl(x) {cout << x << '\n';}
#define nl cout<< '\n'
#define rep(i,n) for(int i = 0; i < n; i++)
#define re(i,n) for(int i = 1; i <= n; i++)
#define fr(i,a,b) for(int i = a; i <= b; i++)
#define fb(i,a,b) for(int i = a; i >= b; i--)
#define vi vector<int>
#define pii pair<int, int>
#define vii vector<pii>
template<class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; }
const int N = 2e5 + 3; // check the limits
void solve(int tc) {
int n; cin>>n;
vector<pair<int,string>> v;
rep(i,n){
string s;int x; cin>>s>>x;
v.pb({x,s});
}
sort(all(v));
pr(v[n-2].se);
}
signed main() {
ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
int q = 1;
// cin >> q;
for (int _t = 1; _t <= q; _t++) solve(_t);
} |
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <bitset>
#include <map>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <algorithm>
#include <sstream>
#include <set>
#include <unordered_set>
using namespace std;
#define ll long long
#define ld long double
#define vecint vector<int>
#define vec2int vector<vector<int>>
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vec3ll vector<vector<vector<long long>>>
#define vecdouble vector<double>
#define vecchar vector<char>
#define vecstr vector<string>
#define vec2str vector<vector<string>>
#define vecbool vector<bool>
#define vec2bool vector<vector<bool>>
#define pairll pair<ll,ll>
#define vecpairll vector<pair<long long,long long>>
#define vec2pairll vector<vector<pair<long long,long long>>>
#define vec3pairll vector<vector<vector<pair<long long,long long>>>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)
#define forbit(s,a) for(int s = 0; s < (1 << a); s++)
#define sortLower(vec) sort(vec.begin(),vec.end())
#define sortGreater(vec,type) sort(vec.begin(),vec.end(),greater<type>())
const ll INF = 1000000000000;
const ld Pi = acos(-1.0);
const ll mod = 1000000007;
const ll mod9 = 998244353;
const ld EPS = 0.0000000001;
#define out_(s) cout << s << " "
#define out(s) cout << s << "\n"
class UnionFind
{
vecll par;
public:
UnionFind(ll n)
{
par.resize(n, -1);
}
ll root(ll pos)
{
if (par[pos] == -1) return pos;
par[pos] = root(par[pos]);
return par[pos];
}
void unite(ll u, ll v)
{
u = root(u); v = root(v);
if (u == v) return;
par[u] = v;
}
bool same(ll u, ll v)
{
if (root(u) == root(v)) return true;
return false;
}
};
ll gcd(ll a, ll b)
{
if (min(a, b) == 0)
return max(a, b);
return gcd(min(a, b), max(a, b) % min(a, b));
}
template <typename T>
T lcm(T a, T b)
{
T buf = gcd(a, b);
return abs(a * b) / buf;
}
string toBaseNum(ll n, ll base)
{
string s;
while (n > 0)
{
if (base > 10)
{
if (n % base >= 10)
{
string buf;
buf.push_back(n % base - 10 + 'A');
s = buf + s;
}
else
{
s = to_string(n % base) + s;
}
}
else
{
s = to_string(n % base) + s;
}
n /= base;
}
if (s.empty())
s = "0";
return s;
}
ll toDecNum(string n, ll base)
{
ll num = 0;
forll(i, 0, n.size())
{
ll buf = 0;
buf = n[i] >= 'A' ? n[i] - 'A' + 10 : n[i] - '0';
num += pow(base, n.size() - i - 1) * buf;
}
return num;
}
vecpairll primeFactorize(ll n)
{
vecpairll buf;
forll(i, 2, sqrt(n + 1))
{
if (n % i != 0)
continue;
long long ex = 0;
while (n % i == 0)
{
++ex;
n /= i;
}
buf.push_back({ i, ex });
}
if (n != 1) buf.push_back({ n, 1 });
return buf;
}
bool isInField(pairll next, ll row, ll col)
{
return (0 <= next.second && next.second < col) && (0 <= next.first && next.first < row);
}
//逆元((1÷b) mod p、bを掛けるとmod pで1となる数)を求める
ll modinv(ll a, ll m)
{
ll b = m, u = 1, v = 0;
while (b)
{
ll t = a / b;
a -= t * b; swap(a, b);
u -= t * v; swap(u, v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
ll Combination(ll n, ll r)
{
ll num = 1;
for (ll i = 1; i <= r; i++)
{
num = num * (n - i + 1) / i;
}
return num;
}
int main() {
ll n, m, l, ans = 0;
string s = "No";
bool flag = false;
cin >> n;
ll count = 0;
forll(i, 0, n)
{
count += i + 1;
ans++;
if (count >= n)
break;
}
out(ans);
} | #include<bits/stdc++.h>
#define ll long long
#define Fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl '\n'
using namespace std;
ll a,b,c,d,e,x,y,n,k,m,z,sum,i,j;
#define mx 1000000000
int main()
{
Fast
cin>>n;
i=1;
while(1)
{
sum=sum+i;
i++;
k++;
if(sum>=n)
{
cout<<k<<endl;
break;
}
}
}
|
#include <iostream>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <map>
#include <sstream>
#include<bitset>
using namespace std;
void solve() {
int n;
cin >> n;
vector<pair<int, string>> a(n);
for(int i = 0; i < n; i++) {
cin >> a[i].second;
cin >> a[i].first;
}
sort(a.begin(), a.end());
cout << a[n - 2].second << endl;
}
int main () {
int t = 1;
for(int tt = 0; tt < t; tt++) solve();
return 0;
} |
#include <iostream>
using namespace std;
int a[1000],n;
string s[1000];
int t[1000];
void partition(int *A, int n, int a, int *left,int *right);
void quicksort(int *A, int n);
int main() {
for(int i =0;i<1000;i++){
a[i]=i;
}
cin >> n;
for(int i=0;i<n;i++)cin >> s[i] >> t[i];
quicksort(a, n);
printf("%s\n",(s[a[1]]).c_str());
return 0;
}
void quicksort(int *A, int n) {
if(n>1) {
int b; b=t[A[0]];
int left,right;
partition(A,n,b,&left,&right);
quicksort(A,right+1);
quicksort(&A[left],n-left);
}
}
void partition(int *A, int n, int a, int *left,int *right)
{
*left = 0;*right = n-1;
while(*left<=*right){
while(t[A[*left]]>a){
*left = *left + 1;
}
while(t[A[*right]]<a){
*right = *right - 1;
}
if(*left<=*right){
int temp = A[*right];
A[*right]=A[*left];
A[*left]=temp;
*left = *left + 1;*right = *right - 1;
}
}
}
|
#include<bits/stdc++.h>
using namespace std;
namespace Ruri{
#define ms(a,b) memset(a,b,sizeof(a))
#define repi(i,a,b) for(int i=a,bbb=b;i<=bbb;++i)//attention reg int or reg ll ?
#define repd(i,a,b) for(int i=a,bbb=b;i>=bbb;--i)
#define reps(s) for(int i=head[s],v=e[i].to;i;i=e[i].nxt,v=e[i].to)
#define ce(i,r) i==r?'\n':' '
#define pb push_back
#define all(x) x.begin(),x.end()
#define gmn(a,b) a=min(a,b)
#define gmx(a,b) a=max(a,b)
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
const int infi=1e9;//infi较大,注意涉及inf相加时爆int
const ll infl=4e18;
inline ll ceil_div(ll a,ll b){ return (a+b-1)/b; }
inline ll pos_mod(ll a,ll b){ return (a%b+b)%b; }
//std::mt19937 rnd(time(0));//std::mt19937_64 rnd(time(0));
}
using namespace Ruri;
namespace Read{
#define ss(a) scanf("%s",a)
inline int ri(){ int x; scanf("%d",&x); return x; }
inline ll rl(){ ll x; scanf("%lld",&x); return x; }
inline db rd(){ db x; scanf("%lf",&x); return x; }
}
namespace DeBug{
#define pr(x) cout<<#x<<": "<<(x)<<endl
#define pra(x,a,b) cout<<#x<<": "<<endl; \
repi(i,a,b) cout<<x[i]<<" "; \
puts("");
#define FR(a) freopen(a,"r",stdin)
#define FO(a) freopen(a,"w",stdout)
}
using namespace Read;
using namespace DeBug;
const ll mod=1e9+7;
ll qpow(ll x,ll n,ll mod){ ll res=1;while(n){ if(n&1) res=(res*x)%mod; x=x*x%mod,n>>=1; } return res; }
struct Matrix{
ll l,c,a[105][105];
Matrix(ll _l=0,ll _c=0){ l=_l,c=_c,init_zero(); }
void init_zero(){ repi(i,1,l)repi(j,1,c) a[i][j]=0; }
Matrix operator + (const Matrix x){ repi(i,1,l)repi(j,1,c) a[i][j]=(a[i][j]+x.a[i][j])%mod; return *this; }
Matrix operator - (const Matrix x){ repi(i,1,l)repi(j,1,c) a[i][j]=(a[i][j]-x.a[i][j]+mod)%mod; return *this; }
Matrix operator * (const Matrix x)
{
Matrix C(l,x.c);
repi(i,1,l)repi(k,1,x.l)if(a[i][k])repi(j,1,x.c)
C.a[i][j]=(C.a[i][j]+a[i][k]*x.a[k][j])%mod;
return C;
}
Matrix operator ^ (ll n)
{
Matrix A=(*this),B(l,c);
repi(i,1,l) B.a[i][i]=1;
while(n){
if(n&1) B=B*A;
A=A*A,n>>=1;
}
return B;
}
Matrix operator = (const Matrix x)
{
l=x.l,c=x.c;
repi(i,1,l)repi(j,1,c) a[i][j]=x.a[i][j];
return *this;
}
void neg_to_pos(){ repi(i,1,l)repi(j,1,c) a[i][j]=(a[i][j]%mod+mod)%mod; }
void print(){ repi(i,1,l)repi(j,1,c) printf("%10.lld%c",a[i][j],ce(j,c)); puts(""); }
};
int n,m,k;
ll a[105];
int deg[105];
bool g[105][105];
int main()
{
n=ri(),m=ri(),k=ri();
ll invm=qpow(m,mod-2,mod),inv2m=qpow(2*m,mod-2,mod);
Matrix ans(n,1);
repi(i,1,n) a[i]=ans.a[i][1]=rl();
repi(i,1,m){
int u=ri(),v=ri();
g[u][v]=g[v][u]=true;
++deg[u],++deg[v];
}
Matrix trans(n,n);
trans.init_zero();
repi(i,1,n)repi(j,1,n)if(i==j||g[i][j]){
if(i==j) trans.a[i][j]=(1ll*(m-deg[i])%mod*invm%mod+1ll*deg[i]%mod*inv2m%mod)%mod;
else trans.a[i][j]=inv2m;
}
trans=trans^k;
ans=trans*ans;
repi(i,1,n) printf("%lld\n",ans.a[i][1]);
return 0;
}
| /**
* author: otera
**/
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<cassert>
#include<array>
using namespace std;
#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x) cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
void solve() {
int n, m; cin >> n >> m;
vector<int> w(n);
rep(i, n) {
cin >> w[i];
}
vector<int> l(m), v(m);
map<int, int> mp;
vector<int> vs;
int vmi = inf;
rep(i, m) {
cin >> l[i] >> v[i];
chmin(vmi, v[i]);
mp[v[i]] = max(l[i], mp[v[i]]);
vs.push_back(v[i]);
}
rep(i, n) {
if(w[i] > vmi) {
cout << -1 << endl;
return;
}
}
vs.push_back(inf);
mp[inf] = inf;
sort(all(vs));
vs.erase(unique(all(vs)), vs.end());
int sz = (int)vs.size();
vector<int> lma(sz + 1, 0);
rep(i, sz) {
lma[i + 1] = mp[vs[i]];
// cerr << lma[i + 1] << endl;
chmax(lma[i + 1], lma[i]);
}
vector<int> ids(n);
iota(all(ids), 0);
int ans = inf;
do {
vector<int> a(n);
rep(i, n) a[i] = w[ids[i]];
vector<int> sum(n + 1, 0);
rep(i, n) {
sum[i + 1] = sum[i] + a[i];
}
vector<vector<int>> dist(n + 1, vector<int>(n + 1, inf));
rep(i, n) {
for(int j = i + 1; j <= n; ++ j) {
int sumv = sum[j] - sum[i];
int k = lower_bound(all(vs), sumv) - vs.begin();
// cerr << *lower_bound(all(vs), sumv) << endl;
int le = lma[k];
dist[i][j] = le;
// cerr << i << " " << j << " " << sumv << " " << le << endl;
}
}
vector<int> dp(n + 1, 0);
dp[1] = 0;
for(int i = 1; i < n; ++ i) {
for(int j = i + 1; j <= n; ++ j) {
chmax(dp[j], dp[i] + dist[i - 1][j]);
}
}
chmin(ans, dp[n]);
} while(next_permutation(all(ids)));
if(ans >= inf) ans = -1;
cout << ans << endl;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
//cout << fixed << setprecision(10);
//int t; cin >> t; rep(i, t)solve();
solve();
return 0;
} |
#include<iostream>
using namespace std;
const long mod=998244353;
long A,B,C;
main()
{
cin>>A>>B>>C;
A=A*(A+1)/2%mod;
B=B*(B+1)/2%mod;
C=C*(C+1)/2%mod;
cout<<A*B%mod*C%mod<<endl;
}
| #include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,s,n) for (int i = (s); i < (n); ++i)
#define rrep(i,n,g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define len(x) (int)(x).size()
#define dup(x,y) (((x)+(y)-1)/(y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int,int>;
vector<vector<vector<double>>> dp;
double f(int i, int j, int k) {
if (dp[i][j][k] != 0.0) return dp[i][j][k];
double n = i + j + k;
if (i == 100 || j == 100 || k == 100) return 0;
return dp[i][j][k] = i/n * (f(i+1,j,k) + 1) + j/n * (f(i,j+1,k) + 1) + k/n * (f(i,j,k+1) + 1);
}
int main() {
int a, b, c;
cin >> a >> b >> c;
dp.assign(101, vector<vector<double>> (101, vector<double>(101, 0.0)));
printf("%.10lf\n", f(a, b, c));
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;
#define int long long
#define ull unsigned long long
#define ll long long
#define M 998244353
#define pb push_back
#define p_q priority_queue
#define pii pair<ll,ll>
#define vi vector<ll>
#define vii vector<pii>
#define mi map<ll,ll>
#define mii map<pii,ll>
#define all(a) (a).begin(),(a).end()
#define sz(x) (ll)x.size()
#define endl '\n'
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b)) / gcd((a),(b))
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second
#define rep(i, begin, end) for (int i=begin;i<end;i++)
#define repd(i, begin, end) for (int i=end-1;i>=begin;i--)
#define ini(a,n,b) for(ll int i=0;i<n;i++) a[i]=0;
#define cset(a) __builtin_popcountll(a)
#define hell 1000000007
#define re resize
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update >
const int INF=1e18;
const int N=3e5+5;
int powm(int a,int b,int mod)
{
int res=1;
while(b)
{
if(b&1)
res=(res*a)%mod;
a=(a*a)%mod;
b>>=1;
}
return res;
}
int pow(int a,int b)
{
int res=1;
while(b)
{
if(b&1)
res=(res*a);
a=(a*a);
b>>=1;
}
return res;
}
signed main(void)
{ios
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);freopen("answer.txt", "w", stdout);
#endif
int tests=1;
// cin>>tests;
while(tests--)
{
int n,m;
cin>>n>>m;
int ans=m;
multiset<int> s;
vi a(n);
rep(i,0,n) cin>>a[i];
rep(i,0,m) s.insert(i);
map<int,int> vis;
rep(i,0,n)
{
vis[a[i]]++;
if(s.find(a[i])!=s.end()) s.erase(a[i]);
if(i>=m-1)
{
if(sz(s)!=0)
{
int mn=*s.begin();
ans=min(ans,mn);
}
vis[a[i-(m-1)]]--;
if(!vis[a[i-(m-1)]]) s.insert(a[i-(m-1)]);
}
}
cout<<ans<<endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
int n, m;
cin >> n >> m;
vector<vector<int>> pre(n);
for (int i = 0; i < n; i++) {
int num;
cin >> num;
pre[num].emplace_back(i);
}
for (int i = 0; i < n; i++) {
int next = -1;
pre[i].emplace_back(n);
for (int j = 0; j < pre[i].size();j++) {
if (pre[i][j] - next - 1 >= m) {
cout << i;
return 0;
}
next = pre[i][j];
}
}
cout << n;
} |
#include <bits/stdc++.h>
using namespace std;
int main() {
int A, B, C, D;
cin >> A >> B;
C = A + B;
if(C >= 15 && B >= 8){
D = 1;
}
else if(C >= 10 && B >= 3){
D = 2;
}
else if(C >= 3){
D = 3;
}
else{
D = 4;
}
cout << D << endl;
} | #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(false); cin.tie(NULL); cout.tie(NULL)
#define int long long
#define ll long long
#define mod 1000000007
#define N 10000002
#define all(v) v.begin(),v.end()
#define maxv(a) *max_element(all(a))
#define minv(a) *min_element(all(a))
#define sumv(a) accumulate(all(a),0)
#define rep(i,a,n) for (ll i=a;i<n;i++)
bool prime[N];
//check prime
bool isPrime(ll n)
{
if(n<=1)return false;
for(ll i=2;i*i<=n;i++)
{
if(n%i==0)return false;
}
return true;
}
//gcd
ll gcd(ll x,ll y)
{
if(x==0)return y;
else return gcd(y%x,x);
}
//lcm;
ll lcm(ll x,ll y)
{
return x*y/gcd(x,y);
}
// sieve of eratosthenes
void sieve(vector<ll> &v)
{
memset(prime,true,N);
prime[0]=prime[1]=false;
for(ll i=2;i*i<N;i++)
{
if(prime[i]==true)
{
for(ll j=i+i;j<N;j+=i)
{
prime[j]=false;
}
}
}
for(ll i=0;i<N;i++)
{
if(prime[i]==true)
{
v.push_back(i);
}
}
}
//count sum & divisor
ll countDivisor(vector<ll> &v,ll n)
{
for(ll i=1;i*i<=n;i++)
{
if(i*i==n)
{
v.push_back(i);
}
else if(n%i==0)
{
v.push_back(i);
v.push_back(n/i);
}
}
}
//primeFactorization
ll primeFactorization(vector<ll> &v,ll n)
{
while(n%2==0)
{
v.push_back(2);
n/=2;
}
for(ll i=3;i*i<=n;i=i+2)
{
while(n%i==0)
{
v.push_back(i);
n = n/i;
}
}
if(n>2)
{
v.push_back(n);
}
}
//Palindrome check string
bool isPalindrome(string s)
{
int l=0;
int h=s.size()-1;
while(l<h)
{
if(s[l++]!=s[h--])
{
return false;
}
}
return true;
}
// getline(cin,s);
//string to int
//x=s[i]-48;
//x=s[i]-'0'
//transform(s.begin(), s.end(), s.begin(), ::tolower);
ll sumofDigit(ll n)
{
ll sum=0;
while(n!=0)
{
sum+=n%10;
n/=10;
}
return sum;
}
//calculate a^b
ll fastPower(ll a,ll b)
{
if(b==0)return 1;
else return a*fastPower(a,b-1);
}
//calculate (x^p)%m
ll fastpowerMOD(ll x,ll p,ll m)
{
if (p == 1) return x;
if (p % 2 == 0)
return fastpowerMOD((x%m)*(x%m), p / 2 , m) % m;
else
return ((fastpowerMOD((x%m)*(x%m), p / 2 , m) % m) *(x%m)) % m;
}
//vector<pair<string,int> >v
bool sortbysec(const pair<string,int> &a,const pair<string,int> &b)
{
return (a.second < b.second);
}
//vector<pair<int,int> >v
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b)
{
return (a.second < b.second);
}
//cout << fixed << setprecision(9);
void solve()
{
int n,x;
cin>>n>>x;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
bool f=true;
for(int i=0;i<n;i++){
if(a[i]!=x){
cout<<a[i]<<" ";
bool f=false;
}
}
if(f)cout<<" "<<endl;
}
signed main()
{
int t=1;
//cin>>t;
while(t--)
{
solve();
}
}
|
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
ll power(ll x, ll n, ll m) {
if (n == 0ll)
return 0ll;
ll y = power(x, n / 2ll, m);
if ((y == -1ll) || (y > m - y))
return -1ll;
y = (y + y);
if (n % 2ll) {
if ((x > m) || (y > m - x)) {
return -1ll;
}
y = y + x;
}
return y;
}
bool f(string x, ll b, ll n, ll m) {
ll y = 0ll, p = 1ll, z;
for (ll i = n - 1; i >= 0; i--) {
z = power(1ll * (x[i] - '0'), p, m);
if ((z == -1ll) || (y > m - z)) {
return false;
}
y = z + y;
p = power(p, b, m);
if (i) {
if (p == -1ll) {
return false;
}
}
}
return true;
}
string strip(string s) {
int n = s.length(), i;
for (i = 0; i < n; i++) {
if (s[i] != '0') {
break;
}
}
return s.substr(i);
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cout.precision(10);
string x;
ll m, d, n, l, u, mid;
cin >> x >> m;
x = strip(x);
n = x.length();
d = (x[0] - '0');
for (int i = 1; i < n; i++) {
d = max(d, 1ll * (x[i] - '0'));
}
if (n == 1) {
cout << ((d <= m) ? 1ll : 0ll) << endl;
return 0;
}
l = d + 1ll, u = 1e18L;
while (l < u) {
mid = l + (1ll + u - l) / 2ll;
if (f(x, mid, n, m))
l = mid;
else
u = mid - 1ll;
}
if (f(x, l, n, m)) {
cout << max(0ll, l - d) << endl;
} else {
cout << 0ll << endl;
}
return 0;
} | #pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double db;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pll pair<ll,ll>
#define pb push_back
#define eb emplace_back
#define ub(v,val) upper_bound(v.begin(),v.end(),val)
#define np(str) next_permutation(str.begin(),str.end())
#define lb(v,val) lower_bound(v.begin(),v.end(),val)
#define sortv(vec) sort(vec.begin(),vec.end())
#define rev(p) reverse(p.begin(),p.end());
#define v vector
#define repc(i,s,e) for(ll i=s;i<e;i++)
#define fi first
#define se second
#define mset(a,val) memset(a,val,sizeof(a));
#define repr(i,n) for(i=n-1;i>=0;i--)
#define rep(i,n) for(i=0;i<n;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define at(s,pos) *(s.find_by_order(pos))
#define set_ind(s,val) s.order_of_key(val)
long long int M = 1e9 + 7 ;
long long int inf = 9 * 1e18;
const double PI = acos(-1);
//CLOCK
ll begtime = clock();
#define time() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//CLOCK ENDED
ll n, m;
// modular exponentiation
ll binpow(ll val, ll deg)
{
if (deg < 0)
return 0;
if (!deg)
return 1 % M;
if (deg & 1)
return binpow(val, deg - 1) * val % M;
ll res = binpow(val, deg >> 1);
return (res * res) % M;
}
ll power(ll val, ll deg)
{
if (deg < 0)
return 0;
if (!deg)
return 1;
if (deg & 1)
return power(val, deg - 1) * val;
ll res = power(val, deg >> 1);
return (res * res);
}
int main() {
// your code goes here
IOS;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ll i, j, t, k, x;
string s;
cin >> s;
ll highest = 0;
for (auto u : s) {
highest = max(highest, (ll)(u - '0'));
}
rev(s);
cin >> M;
ll check = M;
if (s.size() == 1) {
x = s[0] - '0';
if (x <= M) cout << 1;
else cout << 0;
return 0;
}
ll l = highest + 1, r = 1e18, mid;
ll ans = highest;
while (l <= r) {
mid = (l + r) / 2;
bool flg = 0;
rep(i, s.size()) {
double jam = pow(mid, i);
if (jam > 1e18) flg = 1;
else {
ll jam = power(mid, i);
if (jam > check)flg = 1;
}
}
ll num = 0;
rep(i, s.size()) {
num += power(mid, i) * ll(s[i] - '0');
if (num > check) flg = 1;
}
if (flg) {
r = mid - 1;
}
else {
ans = mid;
l = mid + 1;
}
}
cout << ans - highest;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
const int MOD=1e9+7;
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#define pb emplace_back
#define fi first
#define se second
#define FOR(a,b,i) for (int i=a;i!=b;a>b?i--:i++)
#define F0R(a,i) FOR(0,a,i)
#define sz(a) (int)(a).size()
#define ll long long
#define endl '\n'
#define INF 1e9+5
#define LINF 1e18+5
#define fastio ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
int main(){
fastio;
int n,cur=0,inp; cin >> n;
int arr[n];
F0R(n,i) cin >> arr[i];
F0R(n,i){
cin >> inp;
cur+=arr[i]*inp;
}
if (cur==0) cout << "Yes";
else cout << "No";
}
| #include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
struct uf {
vector<int> d;
uf(){}
uf(int mx):d(mx,-1){}
int root(int x) {
if(d[x] < 0) return x;
return d[x] = root(d[x]);
}
bool unite(int x, int y) {
x = root(x); y = root(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 root(x) == root(y);}
int size(int x) { return -d[root(x)];}
int operator[](int x) { return root(x);}
int operator()(int x) { return size(x);}
};
ll GCD(ll a, ll b){
if(b == 0) return a;
else return GCD(b,a%b);
}
ll LCM(ll a, ll b){
return a/GCD(a,b)*b;
}
const int INF = 1e9 + 7;
int main(){
int n;
cin >> n;
vector<ll> a(n);
rep(i,n) cin >> a[i];
sort(a.begin(),a.end());
ll ans = 1;
ll syo = 0;
rep(i,n){
ans *= (a[i] - syo) + 1;
ans %= INF;
syo = a[i];
}
cout << ans << endl;
return 0;
}
// cout << fixed << setprecision(15) << << endl;
//lower_bound(a+l,a+r,x) -a
//はa[l]からa[r-1]までのなかで初めてx以上となるようなインデックスを返す |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAX_N = 2e5+2;
int n;
pair<ll,ll> p[MAX_N];
int m;
ll t[MAX_N],axis[MAX_N];
int q;
ll A[MAX_N], B[MAX_N];
pair<ll,ll> ans[MAX_N];
struct query
{
ll a, b, id;
bool operator<(const query& other) const
{
return a < other.a;
}
};
void solve()
{
vector<query> Q;
for(int i=0;i<q;++i)Q.emplace_back(query{A[i],B[i],i});
sort(Q.begin(),Q.end());
ll sw=0,sx=1,sy=1;
ll cx=0,cy=0;
int idx=1;
for(int i=0;i<q;++i){
for(; idx<=m && idx<=Q[i].a; ++idx){
if(t[idx]==1){
sw ^= 1;
swap(cx,cy), swap(sx,sy);
cy*=-1,sy*=-1;
}else if(t[idx]==2){
sw ^= 1;
swap(cx,cy), swap(sx,sy);
cx*=-1,sx*=-1;
}else if(t[idx]==3){
sx*=-1,cx*=-1;
cx+=2LL*axis[idx];
}else{
sy*=-1,cy*=-1;
cy+=2LL*axis[idx];
}
}
if(!sw){
ans[Q[i].id].first =sx*p[Q[i].b].first+cx;
ans[Q[i].id].second=sy*p[Q[i].b].second+cy;
}
else{
ans[Q[i].id].first=sx*p[Q[i].b].second+cx;
ans[Q[i].id].second=sy*p[Q[i].b].first+cy;
}
}
for(int i=0;i<q;++i)cout<<ans[i].first<<' '<<ans[i].second<<'\n';
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin >> n;
for(int i=1;i<=n;++i)cin>>p[i].first>>p[i].second;
cin >> m;
for(int i=1;i<=m;++i){
cin >> t[i];
if(t[i]==3 || t[i]==4) cin>>axis[i];
}
cin >> q;
for(int i=0;i<q;++i)cin>>A[i]>>B[i];
solve();
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;
void op2(ll& x,ll& y){
y*=(-1);
ll tmp=x;
x=y; y=tmp;
return ;
}
void op1(ll& x,ll& y){
x*=(-1);
ll tmp=x;
x=y; y=tmp;
return ;
}
void op3(ll& x,ll& y,ll p){
x=2*p-x;
return ;
}
void op4(ll& x,ll& y,ll p){
y=2*p-y;
return ;
}
int main(){
ll n;
cin>>n;
vector<P> xy(n);
rep(i,n) cin>>xy[i].first>>xy[i].second;
ll m;
cin>>m;
vector<vector<P>> c(3);
c[0].push_back(P(0,0));
c[1].push_back(P(1,0));
c[2].push_back(P(0,1));
rep(i,m){
ll op;
cin>>op;
vector<ll> x(3),y(3);
rep(j,3){
x[j]=c[j][i].first;
y[j]=c[j][i].second;
//cout<<x[j]<<" "<<y[j]<<endl;
}
if(op==3||op==4){
ll t;
cin>>t;
if(op==3){
rep(k,3){
op3(x[k],y[k],t);
c[k].push_back(P(x[k],y[k]));
}
}
else{
rep(k,3){
op4(x[k],y[k],t);
c[k].push_back(P(x[k],y[k]));
}
}
}
else{
if(op==1){
rep(k,3){
op1(x[k],y[k]);
c[k].push_back(P(x[k],y[k]));
}
}
else{
rep(k,3){
op2(x[k],y[k]);
c[k].push_back(P(x[k],y[k]));
}
}
}
}
vector<P> ans;
ll q;
cin>>q;
rep(i,q){
ll a,b;
cin>>a>>b;
b--;
ll nx=c[0][a].first, ny=c[0][a].second;
nx+=xy[b].first*(c[1][a].first-c[0][a].first);
nx+=xy[b].second*(c[2][a].first-c[0][a].first);
ny+=xy[b].first*(c[1][a].second-c[0][a].second);
ny+=xy[b].second*(c[2][a].second-c[0][a].second);
ans.push_back(P(nx,ny));
}
for(auto p:ans) cout<<p.first<<" "<<p.second<<endl;
} |
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<unordered_map>
#include<vector>
#include<set>
#include<queue>
#include<stack>
#include <math.h>
#include<climits>
using namespace std;
#define int long long
#define vi vector<int>
#define vpii vector<pair<int,int>>
#define pii pair<int,int>
#define ff first
#define ss second
#define print(x) cout<<x<<"\n"
#define printt(x,y) cout<<x<<" "<<y<<"\n"
#define printtt(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define pb push_back
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
#define all(v) v.begin(),v.end()
#define vvi vector<vector<int>>
#define maxq priority_queue<int>
#define minq priority_queue<int,vector<int>,greater<int>>
#define mod 1000000007
#define N 200009
#define atmod 998244353
bool cmp(pii &a, pii &b) {
return a.ff > b.ff;
}
void solve() {
int n, k;
cin >> n >> k;
int a[10][10];
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
cin >> a[i][j];
vector<int> v;
for (int i = 2; i <= n; i++)
v.pb(i);
int cnt = 0;
do {
int s = 0;
int p = 1;
//cout << 1 << " ";
for (int i = 0; i < v.size(); i++) {
int j = v[i];
//cout << v[i] << " ";
int val = a[p][v[i]];
s = s + val;
p = j;
}
s = s + a[p][1];
if (s == k)
cnt++;
//cout << 1 << "\n";
} while (next_permutation(all(v)));
print(cnt);
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int t = 1;
//cin >> t;
while (t--) {
solve();
}
} | #include <bits/stdc++.h>
// clang-format off
using namespace std; using ll = int64_t; using ull = uint64_t; const ll INF = 9e18;
void print0() {}
template<typename Head,typename... Tail> void print0(Head head,Tail... tail){cout<<fixed<<setprecision(15)<<head;print0(tail...);}
void print() { print0("\n"); }
template<typename Head,typename... Tail>void print(Head head,Tail... tail){print0(head);if(sizeof...(Tail)>0)print0(" ");print(tail...);}
// clang-format on
const ll MODULO = 998244353;
ll mod_minus(ll x, ll modval) {
if (x >= 0) {
return x % modval;
} else {
ll mm = ((-x) % modval);
if (mm == 0) {
return 0;
} else {
return modval - mm;
}
}
}
ll mod(ll x) {
return mod_minus(x, MODULO);
}
const ll COMBMAX = 212345;
ll fac[COMBMAX], finv[COMBMAX], inv[COMBMAX];
void combination_init() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < COMBMAX; i++) {
fac[i] = fac[i - 1] * i % MODULO;
inv[i] = MODULO - inv[MODULO % i] * (MODULO / i) % MODULO;
finv[i] = finv[i - 1] * inv[i] % MODULO;
}
}
ll combination(ll n, ll k) {
if (n < k) return 0;
if (n < 0 || k < 0) return 0;
return fac[n] * (finv[k] * finv[n - k] % MODULO) % MODULO;
}
int main() {
ll N, K;
cin >> N >> K;
vector<ll> a(N);
for (ll i = 0; i < N; i++) {
cin >> a[i];
}
vector<ll> apow(N, 1);
vector<ll> powsum(K + 1, 0);
powsum[0] = N;
for (ll k = 1; k <= K; k++) {
for (ll i = 0; i < N; i++) {
apow[i] = (apow[i] * a[i]) % MODULO;
powsum[k] = (powsum[k] + apow[i]) % MODULO;
}
}
combination_init();
for (ll k = 1; k <= K; k++) {
ll result = 0;
for (ll m = 0; m * 2 <= k; m++) {
ll v = 0;
v = mod(powsum[m] * powsum[k - m]);
v = mod(v - powsum[k]);
v = mod(combination(k, k - m) * v);
if (m * 2 == k) {
v = mod(finv[2] * v);
}
result = mod(v + result);
}
print(result);
}
}
|
#include<bits/stdc++.h>
using namespace std ;
#define FASTIO ios::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0) ;
#define int long long
#define mod ((int)1e9 + 7)
int n , m , ans = INT_MIN ;
vector<int> a , mb , ms ;
vector<vector<int>> adj ;
vector<bool> visited ;
void dfs(int x){
visited[x] = true ;
for(int y : adj[x]){
if(!visited[y]) dfs(y) ;
ms[x] = max(max(ms[x] , ms[y]) , mb[y]) ;
}
}
void solve(){
cin >> n >> m ;
a.resize(n + 1) ; mb.resize(n + 1) ;
ms.resize(n + 1 , 0) ; visited.resize(n + 1 , false) ;
adj.resize(n + 1 , vector<int>()) ;
for(int i = 1 ; i <= n ; ++i){ cin >> a[i] ; mb[i] = a[i] ; }
for(int i = 0 ; i < m ; ++i){
int x , y ; cin >> x >> y ;
adj[x].push_back(y) ;
}
for(int i = 1 ; i <= n ; ++i){
if(visited[i]) continue ;
dfs(i) ;
}
for(int i = 1 ; i <= n ; ++i){
if(ms[i] == 0) continue ;
//cout << ms[i] << " " << mb[i] << "\n" ;
ans = max(ans , ms[i] - mb[i]) ;
}
cout << ans << "\n" ;
}
signed main(){
FASTIO
int T = 1 ;
// cin >> T ;
while(T--) solve() ;
return 0 ;
} | #include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
#define forn(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define fore(i,b,a)for(int i=(b),_a=(a);i>=_a;i--)
#define rep(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pii>
#define m_p make_pair
#define re return
#define pb push_back
#define si set<int>
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define mod 1000000007
#define INF 1000000007
#define x1 XZVJDFADSPFOE
#define y1 GASDIJSLDAEJF
#define x2 DFDAJKVOHKWIW
#define y2 PSFSAODSXVNMQ
#define LLINF 0x3f3f3f3f3f3f3f3fLL
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
using namespace std;
inline void read(int &x)
{
short negative=1;
x=0;
char c=getchar();
while(c<'0' || c>'9')
{
if(c=='-')
negative=-1;
c=getchar();
}
while(c>='0' && c<='9')
x=(x<<3)+(x<<1)+(c^48),c=getchar();
x*=negative;
}
ll quickpower(ll n,ll k){
ll ans=1;
while(k){
if(k%2){
ans*=n;
ans%=mod;
}
n*=n;
n%=mod;
k/=2;
}
return ans;
}
string int_to_string(int n)
{
string s="";
while(n)
{
int now=n%10;
s+=now+'0';
n/=10;
}
reverse(s.begin(),s.end());
return s;
}
int string_to_int(string s)
{
int n=0;
rep(i,s.size())
{
n*=10;
n+=s[i]-'0';
}
return n;
}
int n,m;
vector<int>v[200100];
ll a[200100];
bool used[200100];
ll can[200100];
void dfs(int u)
{
used[u]=1;
rep(i,v[u].size())
{
if(!used[v[u][i]])dfs(v[u][i]);
can[u]=max(can[u],can[v[u][i]]);
can[u]=max(can[u],a[v[u][i]]);
}
}
int main()
{
ios::sync_with_stdio(0);
cin>>n>>m;
rep(i,n)cin>>a[i];
rep(i,m)
{
int x,y;
cin>>x>>y;
x--;
y--;
v[x].pb(y);
}
rep(i,n)can[i]=-1e18;
fore(i,n-1,0)
{
if(!used[i])dfs(i);
}
ll ans=-1e18;
rep(i,n)
{
ans=max(ans,can[i]-a[i]);
}
cout<<ans<<endl;
return 0;
}
|
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
int main()
{
int a,b;
cin >> a >> b;
int ans = 2*a+100 - b;
if(ans < 0) ans = 0;
cout << ans << endl;
} | #include <iostream>
using namespace std;
int main(){
int m, h;
cin >> m >> h;
if (h%m == 0){
cout << "Yes" << endl;
}
else{
cout << "No" << endl;
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
const int64_t INF=1000000007;
typedef pair<int,set<int>> P;
typedef pair<int,int>Q ;
int64_t gcd(int64_t x, int64_t y) {
if(x % y == 0) {
return y;
} else {
return gcd(y, x % y);
}
}
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(){
int T;cin >> T;
for(int i=0;i<T;i++){
int64_t N,S,K;cin >> N >> S >> K;
if(gcd(N,K)!=1){
if(S%gcd(N,K)!=0) cout << -1 << endl;
else{
int a=gcd(N,K);
K/=a;N/=a;S/=a;
int64_t b=modinv(K,N);
cout << (b*(N-S))%N << endl;
}
}
else{
int64_t a=modinv(K,N);
cout << (a*(N-S))%N << endl;
//cout << " " << a << endl;
}
}
} | #include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "/debug.h"
#else
#define db(...)
#endif
#define all(v) v.begin(), v.end()
#define pb push_back
using ll = long long;
const int NAX = 2e5 + 5, MOD = 1000000007;
// int a[101][101];
#define int __int128_t
#define ll __int128_t
__int128_t myabs(__int128_t x)
{
if (x < 0)
return -x;
return x;
}
int gcd(int a, int b, int &x, int &y)
{
if (b == 0)
{
x = 1;
y = 0;
return a;
}
int x1, y1;
int d = gcd(b, a % b, x1, y1);
x = y1;
y = x1 - y1 * (a / b);
return d;
}
bool find_any_solution(int a, int b, int c, int &x0, int &y0, int &g)
{
g = gcd(myabs(a), myabs(b), x0, y0);
if (c % g)
{
return false;
}
x0 *= c / g;
y0 *= c / g;
if (a < 0)
x0 = -x0;
if (b < 0)
y0 = -y0;
return true;
}
std::ostream &
operator<<(std::ostream &dest, __int128_t value)
{
std::ostream::sentry s(dest);
if (s)
{
__uint128_t tmp = value < 0 ? -value : value;
char buffer[128];
char *d = std::end(buffer);
do
{
--d;
*d = "0123456789"[tmp % 10];
tmp /= 10;
} while (tmp != 0);
if (value < 0)
{
--d;
*d = '-';
}
int len = std::end(buffer) - d;
if (dest.rdbuf()->sputn(d, len) != len)
{
dest.setstate(std::ios_base::badbit);
}
}
return dest;
}
void solveCase()
{
int32_t n1, s1, k1;
cin >> n1 >> s1 >> k1;
ll n = n1, s = s1, k = k1;
// cin >> n >> s >> k;
db(n, s, k);
ll x0, y0, g;
if (find_any_solution(n, -k, s, x0, y0, g))
{
if (!(n * x0 + (-k) * y0) == s)
{
exit(1);
}
db(n * x0 + (-k) * y0, s);
db(x0, y0, g);
ll dx = k / g;
ll dy = n / g;
// assert(dx > 0 && dy > 0);
if (!(dx > 0 && dy > 0))
{
exit(1);
}
db(dx, dy);
bool ok = false;
if (x0 < 0)
{
auto t = (-x0 + dx - 1) / dx;
db("a", x0, y0, t);
x0 += t * dx;
y0 += t * dy;
db(x0, y0);
}
else if (x0 >= dx)
{
auto t = x0 / dx;
db("a", x0, y0, t);
x0 -= t * dx;
y0 -= t * dy;
db(x0, y0);
ok = true;
}
if (y0 < 0)
{
auto t = (-y0 + dy - 1) / dy;
db("a", x0, y0, t);
x0 += t * dx;
y0 += t * dy;
db(x0, y0);
}
// else if (y0 >= dy)
// {
// auto t = y0 / dy;
// db("a", x0, y0, t);
// x0 -= t * dx;
// y0 -= t * dy;
// db(x0, y0);
// }
if (y0 > 0)
cout << y0 << '\n';
else
cout << "-1\n";
}
else
cout << "-1\n";
}
int32_t main()
{
#ifndef LOCAL
ios_base::sync_with_stdio(0);
cin.tie(0);
#endif
int32_t t = 1;
cin >> t;
for (int i = 1; i <= t; ++i)
solveCase();
return 0;
} |
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0, length = n; i < length; i++)
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define ep emplace
#define epb emplace_back
#define scll static_cast<long long>
#define sz(x) static_cast<int>((x).size())
#define pfll(x) printf("%lld\n", x)
#define ci(x) cin >> x
#define ci2(x, y) cin >> x >> y
#define ci3(x, y, z) cin >> x >> y >> z
#define ci4(w, x, y, z) cin >> w >> x >> y >> z
#define co(x) cout << x << endl
#define co2(x, y) cout << x << " " << y << endl
#define co3(x, y, z) cout << x << " " << y << " " << z << endl
using namespace std;
typedef long long ll;
typedef pair<int, ll> P;
typedef priority_queue<int> PQ;
typedef priority_queue<int, vector<int>, greater<int>> PQG;
typedef priority_queue<P> PQP;
typedef priority_queue<P, vector<P>, greater<P>> PQPG;
const int MAX_N = 2e5, MOD = 1e9 + 7, INF = 1e9;
int n, m, q, t[MAX_N], x[MAX_N], y[MAX_N], memo[MAX_N][2];
map<int, int> ma;
vector<ll> ans;
P bit[MAX_N + 2][2];
P sum(int i, int j) {
P s = P(0, 0);
while (i > 0) {
s.fi += bit[i][j].fi;
s.se += bit[i][j].se;
i -= i & -i;
}
return s;
}
void add(int i, int j, int x, int y) {
while (i <= q + 1) {
bit[i][j].fi += x;
bit[i][j].se += y;
i += i & -i;
}
}
int main() {
ci3(n, m, q);
rep(i, q) {
ci3(t[i], x[i], y[i]);
ma.ep(y[i], 0);
}
ma.ep(0, 0);
int cnt = 0;
for (auto &i: ma) i.se = ++cnt;
ans.epb(0);
rep(i, n) add(1, 0, 1, 0);
rep(i, m) add(1, 1, 1, 0);
rep(i, q) {
int old_y = memo[x[i] - 1][t[i] - 1];
add(ma[y[i]], t[i] - 1, 1, y[i]);
add(ma[old_y], t[i] - 1, -1, -old_y);
P p1 = sum(ma[y[i]] - t[i] % 2, t[i] % 2);
P p2 = sum(ma[old_y] - t[i] % 2, t[i] % 2);
ll tmp = ans.back();
tmp += scll(p1.fi) * y[i] - scll(p2.fi) * old_y;
tmp += p2.se - p1.se;
ans.epb(tmp);
memo[x[i] - 1][t[i] - 1] = y[i];
}
rep(i, q) co(ans[i + 1]);
return 0;
}
| #include <iostream>
#include <string>
using namespace std;
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <set>
#include <map>
#include <cassert>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200010
#define LIMIT2 500010
#define LIMIT3 1000010
#define INF ((1<<30)-1)
#define LLINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef long double ld;
typedef const void cv;
typedef pair<ll,ll> P;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define per(i,n) for((i)=(n)-1;(i)>=0;(i)--)
#define ALL(a) (a).begin(),(a).end()
#define ALL2(a, n) (a),(a)+(n)
template<class T,class C> T max(T a,C b){ return std::max(a, (T)b); }
template<class T,class C> T min(T a,C b){ return std::min(a, (T)b); }
#define zt(a,b) (max((a),(b))-min((a),(b)))
#define setpre(n) fixed << setprecision(n)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a/gcd(a,b))*b;}
int dx[8]={1,0,-1,0,1,-1,-1,1},dy[8]={0,1,0,-1,1,1,-1,-1};
ll modpow(ll a, ll n, ll mod) {
ll res = 1;
while (n > 0) {
if (n & 1){
res *= a; if(mod>=1) res %= mod;
}
a *= a; if(mod>=1) a %= mod;
n >>= 1;
}
return res;
}
void initialize(){
}
struct UnionFind {
vector<int> par;
UnionFind(int n) : par(n,-1) {}
void init(int n) { par.assign(n,-1); }
//木の根であれば連結する頂点数×(-1),そうでなければ親ノードのID
int root(int x){
if(par[x]<0) return x;
else return par[x]=root(par[x]);
}
void unite(int x,int y){
x = root(x);
y = root(y);
if(x==y) return;//既に連結
if(par[x] > par[y]) swap(x,y);
par[x] += par[y];
par[y] = x;
return;
}
bool same(int x,int y){
return root(x)==root(y);
}
int size(int x){
return -par[root(x)];
}
};
ll mm[200010];
vector<ll> edge[200010];
ll a[LIMIT2]={0};
vector<bool> visited(200010,false);
ll dfs(ll i){
if(visited[i]==true) return mm[i];
visited[i] = true;
ll j;
ll res=-LLINF;
rep(j,edge[i].size()){
res = max(res,dfs(edge[i][j]));
res = max(res,a[edge[i][j]]);
}
mm[i] = res;
return res;
}
int main(void){
initialize();
ll n,m,i,j,k,result=0,x,y;
string s;
cin >> n >> m;
rep(i,n) cin >> a[i];
rep(i,m){
cin >> x >> y;
x--;y--;
edge[x].push_back(y);
}
rep(i,n){
dfs(i);
}
result = -LLINF;
rep(i,n){
result = max(result,mm[i]-a[i]);
}
cout << result << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main(){
double A,B;
cin >> A >> B;
double ans = 0.0;
ans = 100 - B/A*100;
cout << ans << endl;
} | #include<iostream>
using namespace std;
int main()
{
int x,y;
cin>>x>>y;
if(x>y)
{
if(y+3>x)
{cout<<"Yes"<<endl;}
else
{cout<<"No"<<endl;}
}
else
{
if(x+3>y)
{cout<<"Yes"<<endl;}
else
{cout<<"No"<<endl;}
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define forn(i,a,n) for (int i=a; i<n; i++)
#define mod 1000000007
//dp(i,j)
//i=until the ith element
//j=how many groups
int dp[3005][3005];
int su[3005],sum[3005];
int a[3005];
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
int n;
cin>>n;
forn(i,1,n+1){
cin>>a[i];
su[i]=su[i-1]+a[i];
}
forn(j,1,n+1){ //groups
memset(sum,0,sizeof sum);
forn(i,1,n+1){
if (j==1) dp[i][j]=1;
else dp[i][j]=sum[su[i]%j]%mod;
sum[su[i]%j]=(sum[su[i]%j]+dp[i][j-1])%mod;
}
}
int ans=0;
forn(j,1,n+1) ans=(ans+dp[n][j])%mod;
cout<<ans<<endl;
return 0;
} | #include <bits/stdc++.h>
#define ll long long
#define pi pair<int, int>
#define pf pair<float, int>
#define ps pair<string, int>
#define pii pair<int, pi>
#define mi map<int, int>
#define ml map<long long, int>
#define ms map<string, int>
#define mc map<char, int>
#define mpi map<pi, int>
#define F first
#define S second
#define vt vector
#define vi vector<int>
#define vd vector<double>
#define vf vector<float>
#define vl vector<long long>
#define vpi vector<pi>
#define vpf vector<pf>
#define vpii vector<pii>
#define st set
#define si set<int>
#define sd set<double>
#define sf set<float>
#define sl set<long long>
#define FOR(t, q) for(int q = 0; q < t; q++)
#define FORN(t, q, v) for(int q = v; q < t; q++)
#define sz(v) (int)(v.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define LOWER(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
#define UPPER(s) transform(s.begin(), s.end(), s.begin(), ::toupper)
#define pb(s) push_back(s);
#define nl endl
#define TC int _t; cin >> _t; FOR(_t, _q)
using namespace std;
void solve() {
string s; cin >> s;
FOR(sz(s), i) {
if (i % 2 == 0) {
if (isupper(s[i])) goto L;
} else {
if (islower(s[i])) goto L;
}
}
cout << "Yes";
return;
L: cout << "No";
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
// TC
solve();
return 0;
}
|
#include <bits/stdc++.h>
#define INF 1e9
#define INFLL 1ull<<60u
using namespace std;
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a) (a).begin(),(a).end()
#define endl "\n"
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
typedef long long ll;
using vi = vector<int>;
using vvi = vector<vi>;
using vpii = vector<pair<int,int>>;
void solve() {
ll N,C; cin >> N >> C;
map<ll,ll> timeline;
REP(i,N) {
int a,b,c; cin >> a >> b >> c;
timeline[a]+=c;
timeline[b+1]-=c;
}
ll rui = 0;
ll total = 0;
ll bef = -1;
for(const auto &p :timeline) {
if (bef != -1) total += min(rui,C) * (p.first - bef - 1);
rui += p.second;
total += min(rui,C);
bef = p.first;
}
cout << total << endl;
}
int main() {
solve();
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef __int128_t LL;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define F first
#define S second
#define pb push_back
mt19937 rnd;
const int N = 2e5 + 10;
int a[N], b[N], c[N];
vector<int> open[N + N], close[N + N];
vector<int> all;
map<int, int> mp;
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif
int n, sub;
cin >> n >> sub;
for (int i = 1; i <= n; i++) {
cin >> a[i] >> b[i] >> c[i];
}
for (int i = 1; i <= n; i++) {
all.pb(a[i]);
all.pb(b[i] + 1);
}
sort(all.begin(), all.end());
all.erase(unique(all.begin(), all.end()), all.end());
for (int i = 0; i < all.size(); i++) {
mp[all[i]] = i;
}
for (int i = 1; i <= n; i++) {
open[mp[a[i]]].pb(i);
close[mp[b[i] + 1]].pb(i);
}
ll sum = 0;
ll ans = 0;
for (int i = 0; i < all.size(); i++) {
for (int j : close[i]) {
sum -= c[j];
}
for (int j : open[i]) {
sum += c[j];
}
if (i + 1 != all.size()) {
ans += 1ll * (all[i + 1] - all[i]) * min((ll) sub, sum);
}
}
cout << ans << "\n";
#ifdef LOCAL
cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
ll GCD(ll a, ll b) {
if (b == 0) return a;
else return GCD(b, a % b);
}
ll LCM(ll a, ll b) { return a * b / GCD(a, b); }
int main(){
int N, K, M;
cin >> N >> K >> M;
vector<int> A(N, 0);
rep(i, N) cin >> A.at(i);
int s = 0;
rep(i, N) s += A.at(i);
int gap = (M * N) - s;
cout << ((gap > K) ? -1 : max(gap, 0)) << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;
using LD = long double;
template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <typename T> void coutall(T v) { if(v.empty()){cout << endl; return;} for(auto i = v.begin(); i != --v.end(); i++){cout << *i << " ";} cout << *--v.end() << endl; }
inline void IN(void){ return; }
template <typename First, typename... Rest> void IN(First& first, Rest&... rest){ cin >> first; IN(rest...); return; }
inline void OUT(void){ cout << "\n"; return; }
template <typename First, typename... Rest> void OUT(First first, Rest... rest){ cout << first << " "; OUT(rest...); return; }
void yes(bool ok = true){ cout << (ok ? "yes" : "no") << endl; }
void Yes(bool ok = true){ cout << (ok ? "Yes" : "No") << endl; }
void YES(bool ok = true){ cout << (ok ? "YES" : "NO") << endl; }
ll myceil(ll a, ll b) { return a >= 0 ? (a+b-1)/b : -((-a)/b); }
ll myfloor(ll a, ll b) { return a >= 0 ? a/b : -myceil(-a, b); }
void Main(){
ll n, m; IN(n, m);
ll cnt = 0;
rep(i, n) {
string s; IN(s);
int pc = count(all(s), '1');
if(pc & 1) cnt++;
}
cout << cnt * (n-cnt) << endl;
return;
}
int main(){
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(15);
Main();
return 0;
} |
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std;
void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
∧_∧
∧_∧ (´<_` ) Welcome to My Coding Space!
( ´_ゝ`) / ⌒i @hamayanhamayan0
/ \ | |
/ / ̄ ̄ ̄ ̄/ |
__(__ニつ/ _/ .| .|____
\/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/
int N;
//---------------------------------------------------------------------------------------------------
void _main() {
cin >> N;
set<int> has;
rep(i, 0, N) {
int a; cin >> a;
has.insert(a);
}
while (1 < has.size()) {
int front = *has.begin();
int back = *has.rbegin();
//has.erase(front);
has.erase(back);
has.insert(back - front);
}
cout << *has.begin() << endl;
}
| #include<bits/stdc++.h>
using namespace std;
using ll = long long;
ll gcd(ll a, ll b){
ll r = a%b, re;
if(r == 0) re = b;
else re = gcd(b, r);
return re;
}
int main(){
ll n;
cin >> n;
vector<ll> a(n);
for(int i = 0; i < n; i++) cin >> a[i];
ll tmp = a[0];
for(ll i = 1; i < n; i++){
tmp = gcd(tmp, a[i]);
}
cout << tmp << endl;
} |
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
unsigned long long s, d, x[100], y[100];
cin >> s >> d;
for (int i = 0; i < n; ++i)
{
cin >> x[i] >> y[i];
}
int ans = 0;
for (int i = 0; i < n; ++i)
{
if (x[i] < s && y[i] > d)
{
ans += 1;
}
}
if (ans != 0)
{
cout << "Yes" << endl;
}
else
{
cout << "No" << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
vector<pair<int,string>>v;
int n;
cin>>n;
string name;
int length;
for(int i=0;i<n;i++){
cin>>name>>length;
v.push_back({length,name});
}
sort(v.begin(),v.end());
cout<<v[n-2].second<<'\n';
return 0;
}
|
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define test int tt; cin>>tt; while(tt--)
#define ff first
#define ss second
#define pb push_back
#define Mod 998244353
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin>>n;
vector<ll int> v(n);
for(auto &e: v)
cin>>e;
sort(v.begin(), v.end());
ll int sum_suff[n]={0};
ll int pre=0;
for(int i=n-1;i>=0;i--)
{
sum_suff[i]+=pre+v[i];
pre*=2;
pre+=v[i];
sum_suff[i]%=Mod;
pre%=Mod;
}
ll int ans=0;
for(int i=0;i<n;i++)
{
ans+=(v[i]*sum_suff[i])%Mod;
ans%=Mod;
}
cout<<ans<<endl;
}
| #include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i, n) for(ll i=n-1;i>=0;--i)
#define rep1(i, n) for(ll i=1; i<=n; ++i)
#define repitr(itr,mp) for(auto itr=mp.begin();itr!=mp.end();++itr)
#define rrepitr(itr, mp) for(auto itr = mp.rbegin(); itr!=mp.rend(); ++itr)
#define ALL(a) (a).begin(),(a).end()
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
const ll MOD = 1e9+7;
const ll LINF = 1LL << 60;
const int INF = 1e9 + 7;
const double PI = 3.1415926535897932384626;
double angle2rad(double angle){return angle * (PI / 180.0);}
double rad2angle(double rad){return rad * (180.0 / PI);}
ll mod(ll a, ll m){return (a + m) % m;}
int main(){
ll n;
cin >> n;
vector<ll> l(n), r(n);
vector<char> lc(n), rc(n);
rep(i, n){
ll t;
cin >> t >> l[i] >> r[i];
if(t == 1){lc[i] = '[';rc[i] = '[';}
if(t == 2){lc[i] = '[';rc[i] = '(';}
if(t == 3){lc[i] = '(';rc[i] = '[';}
if(t == 4){lc[i] = '(';rc[i] = '(';}
}
ll ans = 0;
rep(i, n)for(ll j = i+1; j < n; ++j){
if(l[i] > r[j])continue;
if(r[i] < l[j])continue;
if(l[i] == r[j] && lc[i] != rc[j] )continue;
if(l[i] == r[j] && lc[i] == '(')continue;
if(r[i] == l[j] && rc[i] != lc[j])continue;
if(r[i] == l[j] && rc[i] =='(')continue;
// cout << l[i] << " : " << r[i] << " , " << l[j] << " : " << r[j] << endl;
// cout << lc[i] << " : " << rc[i] << " , " << lc[j] << " : " << rc[j] << endl;
ans++;
}
cout << ans << endl;
} |
#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 fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
struct DSU
{
int S;
struct node
{
int p; ll sum;
};
vector<node> dsu;
DSU(int n)
{
S = n;
for(int i = 0; i < n; i++)
{
node tmp;
tmp.p = i; tmp.sum = 1;
dsu.pb(tmp);
}
}
void reset(int n)
{
dsu.clear();
S = n;
for(int i = 0; i < n; i++)
{
node tmp;
tmp.p = i; tmp.sum = 1;
dsu.pb(tmp);
}
}
int rt(int u)
{
if(dsu[u].p == u) return u;
dsu[u].p = rt(dsu[u].p);
return dsu[u].p;
}
void merge(int u, int v)
{
u = rt(u); v = rt(v);
if(u == v) return ;
if(rand()&1) swap(u, v);
dsu[v].p = u;
dsu[u].sum += dsu[v].sum;
}
bool sameset(int u, int v)
{
if(rt(u) == rt(v)) return true;
return false;
}
ll getstat(int u)
{
return dsu[rt(u)].sum;
}
};
vector<int> fact;
vector<int> ifact;
vector<int> inv;
vector<int> pow2;
const int MOD =998244353;
int add(int a, int b)
{
a+=b;
while(a>=MOD) a-=MOD;
return a;
}
void radd(int &a, int b)
{
a=add(a,b);
}
int mult(int a, int b)
{
return (a*1LL*b)%MOD;
}
void rmult(int &a, int b)
{
a=mult(a,b);
}
int modpow(int a, int b)
{
int r=1;
while(b)
{
if(b&1) r=mult(r,a);
a=mult(a,a);
b>>=1;
}
return r;
}
int choose(int a, int b)
{
if(a<b) return 0;
if(b==0) return 1;
if(a==b) return 1;
return mult(fact[a],mult(ifact[b],ifact[a-b]));
}
int inverse(int a)
{
return modpow(a,MOD-2);
}
void init(int _n)
{
fact.clear(); ifact.clear(); inv.clear(); pow2.clear();
fact.resize(_n+1);
ifact.resize(_n+1);
inv.resize(_n+1);
pow2.resize(_n+1);
pow2[0]=1;
ifact[0]=1;
fact[0]=1;
for(int i=1;i<=_n;i++)
{
pow2[i]=add(pow2[i-1],pow2[i-1]);
fact[i]=mult(fact[i-1],i);
//ifact[i]=mult(ifact[i-1],inv[i]);
}
ifact[_n] = inverse(fact[_n]);
for(int i=_n-1;i>=1;i--)
{
ifact[i] = mult(ifact[i + 1], i + 1);
}
for(int i=1;i<=_n;i++)
{
inv[i] = mult(fact[i-1],ifact[i]);
}
}
int a[155][155];
int main()
{
init(100000);
ios_base::sync_with_stdio(0); cin.tie(0);
int n,k; cin>>n>>k;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
cin>>a[i][j];
}
}
DSU R(n); DSU C(n);
for(int i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
{
int pos=1;
for(int z=0;z<n;z++)
{
if(a[i][z]+a[j][z]>k) pos=0;
}
//cerr<<i<<' '<<j<<' '<<pos<<'\n';
if(pos) R.merge(i,j);
}
}
for(int i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
{
int pos=1;
for(int z=0;z<n;z++)
{
if(a[z][i]+a[z][j]>k) pos=0;
}
//cerr<<"C: "<<i<<' '<<j<<' '<<pos<<'\n';
if(pos) C.merge(i,j);
}
}
int ans=1;
for(int i=0;i<n;i++)
{
if(R.rt(i)==i)
{
ans=mult(ans,fact[R.getstat(i)]);
}
if(C.rt(i)==i)
{
ans=mult(ans,fact[C.getstat(i)]);
}
}
cout<<ans<<'\n';
}
| #define taskname "test"
#include <bits/stdc++.h>
using namespace std;
#define sz(x) (int)x.size()
#define fi first
#define se second
typedef long long lli;
typedef pair<int, int> pii;
const int maxn = 2e5 + 5;
int n, k;
vector<int> gr[maxn];
int depth[maxn], p[maxn];
int max_depth = 0;
vector<int> vertices[maxn];
int need[maxn], fire[maxn];
void read_input()
{
cin >> n >> k;
for(int i = 1; i < n; ++i)
{
int u, v;
cin >> u >> v;
gr[u].push_back(v);
gr[v].push_back(u);
}
}
void dfs_modify(int u, int par)
{
p[u] = par;
depth[u] = depth[par] + 1;
vertices[depth[u]].push_back(u);
max_depth = max(max_depth, depth[u]);
for(auto&v: gr[u])
if(v != par)
dfs_modify(v, u);
}
bool check(int t)
{
fill(need + 1, need + n + 1, t);
fill(fire + 1, fire + n + 1, -1);
int cnt = 0;
for(int d = max_depth; d > 1; --d)
for(auto&u: vertices[d])
{
if(need[u] == 0)
{
++cnt;
if(cnt > k) return false;
fire[u] = t;
fire[p[u]] = max(fire[p[u]], t - 1);
}
else
{
if(fire[u] + need[u] >= t)
fire[p[u]] = max(fire[p[u]], fire[u] - 1);
else
{
fire[p[u]] = max(fire[p[u]], fire[u] - 1);
need[p[u]] = min(need[p[u]], need[u] - 1);
}
}
}
if(need[1] + fire[1] < t)
++cnt;
return cnt <= k;
}
void solve()
{
dfs_modify(1, 0);
int low = 1, high = max_depth;
while(low <= high)
{
int mid = (low + high) / 2;
if(check(mid)) high = mid - 1;
else low = mid + 1;
}
cout << low << '\n';
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
read_input();
solve();
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX 510000
#define MOD 998244353
#define rep(i, n) for (ll i = 0; i < n; ++i)
void solve(void)
{
ll n;
cin >> n;
set<ll> st;
for (ll i = 1; i * i <= n; ++i)
{
if (n % i == 0)
{
ll j = n / i;
st.insert(i);
if (n % j == 0)
st.insert(j);
}
}
for (auto i : st)
cout << i << "\n";
}
int main(void)
{
solve();
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, s, e) for (int i = (int)(s); i < (int)(e); i++)
#define _rep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define _REP(i, e, s) for (int i = (int)(e - 1); i >= (int)(s); i--)
#define yes cout << "yes" << endl;
#define Yes cout << "Yes" << endl;
#define YES cout << "YES" << endl;
#define no cout << "no" << endl;
#define No cout << "No" << endl;
#define NO cout << "NO" << endl;
#define AC cout << "AC" << endl;
#define WA cout << "WA" << endl;
#define out(s) cout << s << endl;
#define ll long long
#define ull unsigned long long
const unsigned int BIT_FLAG_0 = (1 << 0); // 0000 0000 0000 0001
const unsigned int BIT_FLAG_1 = (1 << 1); // 0000 0000 0000 0010
const unsigned int BIT_FLAG_2 = (1 << 2); // 0000 0000 0000 0100
const unsigned int BIT_FLAG_3 = (1 << 3); // 0000 0000 0000 1000
const unsigned int BIT_FLAG_4 = (1 << 4); // 0000 0000 0001 0000
const unsigned int BIT_FLAG_5 = (1 << 5); // 0000 0000 0010 0000
const unsigned int BIT_FLAG_6 = (1 << 6); // 0000 0000 0100 0000
const unsigned int BIT_FLAG_7 = (1 << 7); // 0000 0000 1000 0000
const double PI = 3.14159265358979323846;
const int dy[4] = {0, 1, 0, -1};
const int dx[4] = {1, 0, -1, 0};
#define H_MAX 500
#define W_MAX 500
#define INF 1e9 + 7
const long long MOD = 1000000007;
int main() {
ll N;
cin >> N;
vector<ull> v, v2;
for (int i = 1; i <= sqrt(N); i++) {
if (N % i == 0) {
v.push_back(i);
if (i != sqrt(N)) {
v2.push_back(N / i);
}
}
}
for (int i = 0; i < v.size(); i++) {
cout << v[i] << endl;
}
for (int i = 0; i < v2.size(); i++) {
cout << v2[v2.size() - 1 - i] << endl;
}
} |
#include <bits/stdc++.h>
using namespace std;
// #include <atcoder/all>
// using namespace atcoder;
// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define irreps(i, m, n) for (int i = ((int)(n)-1); i > (int)(m); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) (int)(x.size())
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;
using ld = long double;
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; }
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
const ll INF = 1e9+10;
const ll MOD = 1e9+7;
// const ll MOD = 998244353;
const ll LINF = 1e18;
ll modpow(ll a, ll n) {
ll res = 1;
while (n > 0) {
if (n & 1) res = res * a % MOD;
(a *= a) %= MOD;
n >>= 1;
}
return res;
}
const ll maxf = 10000000;
ll fact[maxf+5];
ll ifact[maxf+5];
void fact_init(){
fact[0] = 1;
for(ll i=1; i<=maxf; i++) fact[i] = (fact[i-1] * i) % MOD;
ifact[maxf]=modpow(fact[maxf],MOD-2);
for(ll i=maxf; i>=1; i--) ifact[i-1] = (ifact[i] * i) % MOD;
}
ll comb(ll n, ll r){
if(n<r || n<0 || r<0) return 0;
if(fact[0] == 0) fact_init();
return ((fact[n] * ifact[n-r]) % MOD * ifact[r]) % MOD;
}
ll naive_comb(ll n, ll r){
ll res = 1;
for (ll i = n; i > n - r; i--) res = res * i % MOD;
for (ll i = 1; i <= r; i++) res = (res * modpow(i, MOD-2)) % MOD;
return res;
}
// カタラン数
// (m,n)へ行く経路から、y=x+k+1を通る経路を除いた経路数が答え
// y=x+k+1を通って(m,n)への経路数は、原点の直線と対称な点(-k-1,k+1)から(m,n)への経路数と同じ
// よって、n+mCn - n+mCn-k-1 もしくは n+mCm+k+1
// k+1>n の場合は、y=x+k+1の直線を跨ぐことが無いので減算する必要なし
// コーナーケース
// y=x+k+1の直線より上に(m,n)が存在する場合がある n>m+k
// より具体的にはk=0として、(m,n)=(2,3)とか 白が多いなら必ず白が多いタイミングができてしまう
// この場合は、解無しとして場合分け
signed main()
{
cin.tie( 0 ); ios::sync_with_stdio( false );
ll n,m,k; cin>>n>>m>>k;
if(n>m+k){
cout<<0<<endl;
return 0;
}
ll ans=comb(n+m,n);
ans=(ans-comb(n+m,m+k+1)+MOD)%MOD;
cout<<ans<<endl;
} | //**sn0wrus**//
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
//#pragma GCC optimize("Ofast")
//#pragma GCC optimization("unroll-loops, no-stack-protector")
//#pragma GCC target("avx,avx2,fma")
#define fast \
ios_base::sync_with_stdio(false); \
cout.tie(NULL); \
cin.tie(NULL);
#define write(a) \
for (auto x : a) \
{ \
cout << x << " "; \
} \
cout << endl;
#define read(a) \
for (auto &x : a) \
{ \
cin >> x; \
}
#define for0(i,n) for(int i=0;i<n;i++)
#define forn(i,n) for(int i=n-1;i>=0;i++)
#define IN cin >>
#define OUT cout <<
#define endl "\n"
#define all(a) (a).begin(), (a).end()
#define allr(a) (a).rbegin(), (a).rend()
#define pb push_back
#define fi first
#define se second
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 << '}'<<endl;}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}"<<endl;}
template<typename T, typename... Args>
void __print(T t, Args... args) // recursive variadic function
{
cout << t <<" " ;
__print(args...) ;
}
void nl()
{
cout<<endl;
}
using ll = long long int;
using ld = long double;
using pll = pair<ll, ll>;
using pii = pair<int, int>;
using plll = pair<ll,pll>;
using vll = vector<ll>;
using vi = vector<int>;
const ll MOD = (ll)(1e9) + 7LL;
const ll MM = 998244353LL;
const ll INF = INT_MAX;
const int dir8[8][2]={{1,0},{0,1},{-1,0},{0,-1},{1,1},{1,-1},{-1,1},{-1,-1}};
const int dir4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const ll MAXN = 200005;
/*
for(int i=0;i<n-1;i++)
{
int a,b;
cin>>a>>b;
a--,b--;
adj[a].push_back(b);
adj[b].push_back(a);
}
*/
void solve()
{
vector<ll>arr(3);
for(int i=0;i<3;i++)cin>>arr[i];
sort(all(arr));
if(arr[2]-arr[1]==arr[1]-arr[0])
{
cout<<"Yes"<<endl;
}
else{
cout<<"No"<<endl;
}
return;
}
/*
1.check for ll for all variables.
2.check brackets in all equation and order of conditions.
3.check custom compare funtions if any.
4.check logic carefully.
5.Dont get stuck on one approch.
*/
int main()
{
fast;
ll tc = 1;
//IN tc;
while (tc--)
{
solve();
cout.flush();
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
template<typename T>
bool is_prime(T x) {
if (x == 1) {
return false;
}
for (int i = 2; (T) i * i <= x; i++) {
if (x % i == 0) {
return false;
}
}
return true;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
long long a, b;
cin >> a >> b;
int len = b - a + 1;
vector<int> p;
for (int i = 1; i <= len; i++) {
if (is_prime(i)) {
p.push_back(i);
}
}
vector<int> mask_of(len);
for (long long x = a; x <= b; x++) {
for (int i = 0; i < int(p.size()); i++) {
if (x % p[i] == 0) {
mask_of[x - a] |= (1 << i);
}
}
}
vector<long long> dp(1 << p.size());
dp[0] = 1;
for (int i = 0; i < len; i++) {
for (int mask = (1 << int(p.size())) - 1; mask >= 0; mask--) {
if ((mask & mask_of[i]) == 0) {
dp[mask | mask_of[i]] += dp[mask];
}
}
}
cout << accumulate(dp.begin(), dp.end(), 0ll) << '\n';
return 0;
} | #pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define fi first
#define se second
#define pb push_back
#define wzh(x) cerr<<#x<<'='<<x<<endl;
LL a,b;
int g[22],d[22];
int _v,_w;
LL gcd(LL x,LL y){
return y==0?x:gcd(y,x%y);
}
int ban_v[1<<22];
int sum_v[1<<22];
vector<LL>G;
LL ans;
void gao(vector<LL>&v,vector<LL>&w){
while(v.size()>w.size()){
w.pb(v.back());
v.pop_back();
}
_v=v.size(),_w=w.size();
memset(ban_v,0,sizeof ban_v);
memset(sum_v,0,sizeof sum_v);
memset(g,0,sizeof g);
memset(d,0,sizeof d);
for(int i=0;i<_v;i++){
for(int j=0;j<_v;j++){
if(i==j)continue;
if(gcd(v[i],v[j])!=1){
g[i]|=1<<j;
}
}
}
for(int i=0;i<_w;i++){
for(int j=0;j<_w;j++){
if(i==j)continue;
if(gcd(w[i],w[j])!=1){
d[i]|=1<<j;
}
}
for(int j=0;j<_v;j++){
if(gcd(w[i],v[j])!=1){
ban_v[i]|=1<<j;
}
}
}
for(int i=0;i<1<<_v;i++){
int st=0;
for(int j=0;j<_v;j++){
if(1<<j&i){
if(( g[j]) & (i^(1<<j)))st=1;
}
}
if(!st) {
sum_v[i] = 1;
}
}
for(int i=0;i<_v;i++){
for(int j=0;j<1<<_v;j++){
if(1<<i&j)sum_v[j]+=sum_v[j^(1<<i)];
}
}
int sum_sta=1<<_v ;
sum_sta--;
for(int i=0;i<1<<_w;i++){
int st=0;
int sum_ban=0;
for(int j=0;j<_w;j++){
if(1<<j&i){
if(( d[j]) & (i))st=1;
sum_ban|=ban_v[j];
}
}
if(!st){
assert((sum_ban&sum_sta)==sum_ban);
//cout<<i<<' '<<(sum_ban^sum_sta)<<'\n';
ans+=sum_v[sum_ban^sum_sta];
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin>>a>>b;vector<LL>v,w;
for(LL i=a;i<=b;i++){
if(i&1)v.pb(i);
else G.pb(i);
}
G.pb(1);
/*
* 因为偶数只能选一个
* 枚举不选 或者 选哪个 偶数
* 存一下跟这个偶数gcd为1的奇数
*
* meet in middle 来计算 奇数部分的答案。
* */
for(auto k:G){
v.clear();w.clear();
for(LL i=a;i<=b;i++){
if(i%2==0)continue;
if(gcd(k,i)==1)v.pb(i);
}
//cout<<"ev-> "<<k<<'\n';
// cout<<"od->\n";
//for(auto x:v)cout<<x<<' ';cout<<'\n';
gao(v,w);
}
cout<<ans<<'\n';
return 0;
}
//2125824
//4589568 |
#include<iostream>
#include<string>
#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,n) for (int i = 0; i < (n) ; i++)
#define vsort(v) sort(v.begin(),v.end())
#define INF 1e9
#define llINF 1e18
#define base10_4 10000 //1e4
#define base10_5 100000 //1e5
#define base10_6 1000000 //1e6
#define base10_7 10000000 //1e7
#define base10_8 100000000 //1e8
#define base10_9 1000000000 //1e9
#define MOD 1000000007
#define pb push_back
#define ll long long
#define ld long double
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>
//#include <stack>
//#include <queue>
// #include <iomanip>
// cout << fixed << setprecision(15) << y << endl;
/*
sort(ord.begin(),ord.end(),[&](int x, int y){
return p[x]>p[y];
});
*/
string ans_Yes = "Yes";
string ans_No = "No";
string ans_yes = "yes";
string ans_no = "no";
vll A;
vll B;
ll C;
ll N;
ll M;
ll K;
ll ltmp;
string stmp;
double dtmp;
ll calcMatch(ll ai, ll bi){
ll tai = ai;
ll tbi = bi;
ll ans = 0;
while(tai<N && tbi < M){
if(A[tai]!=B[tbi]) ans++;
tai++;
tbi++;
}
return ans;
}
vector <vector<int>> dp;
int getval(int ai, int bi){
int tmp = INF;
if(ai==1){
tmp = bi-1;
} else if(bi==1){
tmp = ai-1;
}else{
for( int tai = 1 ; tai <=ai-1 ; tai++ ) tmp = min(tmp, dp[tai][bi-1] + (ai-1-tai) );
for( int tbi = 1 ; tbi <=bi-1 ; tbi++ ) tmp = min(tmp, dp[ai-1][tbi] + (bi-1-tbi));
}
if(A[ai]!=B[bi]) tmp++;
return tmp;
}
int getans(){
dp.resize(1001);
rep(di,1001) rep(ni,1001) dp[di].push_back(0);
for( ll ai = 1 ; ai <=N ; ai++ ){
for( ll bi = 1 ; bi <=M ; bi++ ){
dp[ai][bi] = getval(ai,bi);
}
}
for( ll ai = 1 ; ai <=N ; ai++ ){
for( ll bi = 1 ; bi <=M ; bi++ ){
dp[ai][bi] += (N-ai);
dp[ai][bi] += (M-bi);
}
}
int ans = INF;
for( ll ai = 1 ; ai <=N ; ai++ ){
for( ll bi = 1 ; bi <=M ; bi++ ){
//cout << "ai " << ai << " bi " << bi << " = " << dp[ai][bi] << endl;
ans = min(ans,dp[ai][bi]);
}
}
return ans;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> N;
cin >> M;
A.resize(N+1);
B.resize(M+1);
rep(ni,N) cin >> A[ni+1];
rep(mi,M) cin >> B[mi+1];
ll minA = 0;
ll minB = 0;
cout << getans() << endl;
} | #include<bits/stdc++.h>
using namespace std;
int n,m;
int f[2000][2000];
int a[2000],b[2000];
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
cin>>a[i];
for(int i=1;i<=m;i++)
cin>>b[i];
memset(f,10,sizeof(f));
f[0][0]=0;
for(int i=1;i<=n;i++)
f[i][0]=i;
for(int i=1;i<=m;i++)
f[0][i]=i;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
int t=1;
if(a[i]==b[j]) t=0;
f[i][j]=min(f[i-1][j]+1,min(f[i][j-1]+1,f[i-1][j-1]+t));
}
}
cout<<f[n][m]<<endl;
return 0;
} |
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define PI acos(-1)
#define sz 300
#define RUN_FAST ios::sync_with_stdio(false);
using namespace std;
int main ()
{
RUN_FAST; cin.tie(nullptr);
int n, cnt, mx1=0, mx2, ans;
cin >> n;
int arr[n], i, j;
for (i=0; i<n; i++) {
cin >> arr[i];
mx1=max(mx1, arr[i]);
}
mx2=0;
ans=2;
for (i=2; i<=mx1; i++) {
cnt=0;
for (j=0; j<n; j++)
if (arr[j]%i==0) cnt++;
if (cnt>mx2) {
mx2=cnt;
ans=i;
}
}
cout << ans << endl;
return 0;
}
| #include<iostream>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
int t;
long int n=0, m=0, a=0, a1=0, b=0, c=0, d=0, x=0, y=0, z=0, k=0, l=0, x1;
cin>>n;
long int arr[n];
for ( int i=0; i<n; i++ ) { cin>>arr[i];
a=a+abs(arr[i]);
b=b+(arr[i]*arr[i]);
if (d<abs(arr[i]))
d=abs(arr[i]);
}
double val1 = 1.0;
val1=val1*b;
cout<<a<<endl;
cout << fixed << setprecision(12) << sqrt(val1) << endl;
cout<<d<<endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rep1(i, n) for(int i=1; i<=(int)(n); i++)
#define rep2(i, n, m) for(int i=(int)n; i<=(int)m; i++)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> wi;
typedef vector<ll> vl;
const ll inf=1LL<<60;
const ll mod=1000000007;
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n;
ll x;
cin >> n >> x;
vl a(n);
rep(i, n)cin >> a[i];
rep(i, n){
if(a[i]==x)continue;
cout << a[i];
if(i!=n-1)cout << " ";
}
cout << endl;
return 0;
} | #include<bits/stdc++.h>
#define int long long
#define zmrl(x) signed((x).size())
#define ahen(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
using pii = pair<int,int>;
signed main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
int A[105][105];
int h,w; cin>>h>>w;
int mmin = 100;
for (int i=1; i<=h; i++) {
for (int j=1; j<=w; j++) {
cin>>A[i][j];
mmin = min(A[i][j], mmin);
}
}
int res = 0;
for (int i=1; i<=h; i++) {
for (int j=1; j<=w; j++) {
res += A[i][j] - mmin;
}
}
cout<<res<<'\n';
return 0;
} |
#include <bits/stdc++.h>
#define lc (o<<1)
#define rc ((o<<1)|1)
#define PB push_back
#define MK make_pair
using namespace std;
#define DebugP(x) cout << "Line" << __LINE__ << " " << #x << "=" << x << endl
const int maxn = 3e5 + 5;
const int modu = 998244353; // 1e9 + 7
const int inf = 0x3f3f3f3f;
const double eps = 1e-5;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
typedef long long LL;
void read(LL &x)
{
x=0;int f=0;char ch=getchar();
while(ch<'0'||ch>'9') {f|=(ch=='-');ch=getchar();}
while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
x=f?-x:x;
return;
}
void read(int &x) { LL y; read(y); x = (int)y; }
void read(char &ch) { char s[3]; scanf("%s", s); ch = s[0]; }
void read(char *s) { scanf("%s", s); }
template<class T, class ...U> void read(T &x, U& ... u) { read(x); read(u...); }
int n;
LL a[maxn], sum, sum2, ans;
int main() {
// freopen("my.txt", "w", stdout);
read(n);
for (int i = 0; i < n; ++i) read(a[i]);
sum = a[0];
sum2 = a[0]*a[0];
ans = 0;
for (int i = 1; i < n; ++i) {
ans += i*a[i]*a[i] - 2*sum*a[i] + sum2;
sum += a[i];
sum2 += a[i]*a[i];
}
cout << ans << "\n";
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
long long N;
cin >> N;
vector<int> A(N);
for (int i = 0; i < N; i++) {
cin >> A.at(i);
}
vector<long long> count(401);
for (int i = 0; i < N; i++) {
count.at(A.at(i) + 200)++;
}
long long total = 0;
for (int i = 0; i < 401; i++) {
for (int j = i; j < 401; j++) {
int x = i - j;
total += count.at(i) * count.at(j) * x * x;
}
}
cout << total << endl;
} |
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
string ans[20];
bool check(string s){
bool ret=false;
int i,j;
for(i=0;i<20;i++){
string wk="";
for(j=0;j<20;j++){
if(ans[i].size()>j){
wk+=ans[i];
}else{
break;
}
}
if(wk.find(s)!=std::string::npos){
ret=true;
break;
}
}
return ret;
}
int main()
{
int n,m;
cin>>n>>m;
string s;
vector<pair<int,string>> vec;
int i,j;
for(i=0;i<m;i++){
cin>>s;
bool add=true;
for(j=0;j<vec.size();j++){
if(s.size()<=vec[j].second.size()){
if(vec[j].second.find(s)==std::string::npos) continue;
(vec[j].first)++;
add=false;
break;
}else{
if(s.find(vec[j].second)==std::string::npos) continue;
(vec[j].first)++;
vec[j].second=s;
add=false;
break;
}
}
if(add){
vec.push_back({0,s});
}
}
sort(vec.begin(),vec.end());
for(i=vec.size()-1;i>=0; i--){
int len=vec[i].second.size();
if(check(vec[i].second)) continue;
for(j=0;j<20;j++){
if(ans[j].size()+len<=20){
ans[j]+=vec[i].second;
break;
}
}
}
for(i=0;i<20;i++){
for(j=ans[i].size();j<20;j++){
ans[i]+='.';
}
cout<<ans[i]<<endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main()
{
int N,M;
string a;
random_device rnd;
cin >> N >> M;
for(int i=0; i<M; i++) {
cin >> a;
}
for(int y=0; y<N; y++) {
for(int x=0; x<N; x++){
char a = rnd()%8 + 'A';
cout << a;
}
cout << endl;
}
};
|
#include<bits/stdc++.h>
using namespace std;
int main()
{
string a;
int t=0;
cin>>a;
for(int i=0;i<a.size()-3;i++){
string s(a,i,4);
if(s=="ZONe") t++;
}
cout<<t;
return 0;
} | /*COMPETITIVE PROGRAMMING C++ TEMPLATE */
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <cmath>
#include <iostream>
#include <stack>
#include <queue>
#include <climits>
#include <iomanip>
#include <cassert>
#include <functional>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << " = " << x << "\n"
#define debug2(x, y) cout << #x << " = " << x << " " << #y << " " << y << "\n";
#define MOD 1000000007
const long double PI = 3.141592653589793236L;
typedef long long int ll;
typedef long double ld;
using namespace std;
using namespace __gnu_pbds;
// Refer to https://codeforces.com/blog/entry/11080
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update> ordered_set;
void solve()
{
int x;
cin >> x;
if(x % 100)
{
cout << 100 - (x % 100) << "\n";
}
else {
cout << 100 << "\n";
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int T = 1;
//cin >> T;
while (T--)
{
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(), x.end()
int main(){
ios::sync_with_stdio(0); cin.tie(0);
int n, m; cin >> n >> m;
vector<array<int, 2>> black(m);
for(auto &[x, y] : black) cin >> x >> y;
set<int> white;
white.insert(n);
sort(all(black));
for(int i = 0; i < m;){
int cur = black[i][0];
vector<int> rem, ins;
while(i < m && cur == black[i][0]){
int l = white.count(black[i][1] - 1), r = white.count(black[i][1] + 1);
if(l + r == 0) rem.push_back(black[i][1]);
else ins.push_back(black[i][1]);
++i;
}
for(auto j : ins) white.insert(j);
for(auto j : rem) white.erase(j);
}
cout << (int)white.size() << "\n";
}
| #include <cstdio>
#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
#include <list>
#include <bits/stdc++.h>
using namespace std;
/*----------------------------------ここからマクロ----------------------------------*/
#define f(i, n) for(int i=0;i<n;i++)
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define vb vector<bool>
#define pii pair<int,int>
#define mii map<int, int>
#define msi map<string, int>
#define pii pair<int,int>
#define vpii vector<pair<int, int>>
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define len(x) ((int)(x).size())
#define contains(x,key) ((x).find(key) != (x).end())
#define cauto const auto
#define ll long long
#define float long double
#define elif else if
#define exit return 0
const ll mod1 = 1000000007LL;
const ll mod2 = 998244353LL;
const int inf = 1 << 30;
const ll INF = 1LL << 60;
const float pi = 3.14159265358;
constexpr long long gcd(long long a, long long b) { while(b){ long long A = a; (a = b), (b = A % b); } return a; }
constexpr long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
constexpr int ctoi(const char c) { return ('0' <= c && c <= '9') ? (c - '0') : -1; }
constexpr const char* YesNo(bool b) { return b ? "Yes" : "No"; }
constexpr const char* YESNO(bool b) { return b ? "YES" : "NO"; }
constexpr const char* yesno(bool b) { return b ? "yes" : "no"; }
constexpr const char* yn(bool b) { return YesNo(b); }
template<class T> string join(const vector<T> &v){ stringstream s; rep (i, len(v)) s<<' '<<v[i]; return s.str().substr(1); }
template<class T> istream& operator>>(istream& is, vector<T>& v) { for (auto& x : v) is >> x; return is; }
template<class T> istream& operator>>(istream& is, vector<vector<T>>& v) { for(auto& x : v) for (auto& y : x) is >> y; return is; }
template<class T, class U> istream& operator>>(istream& is, pair<T, U>& p) { return is >> p.FI >> p.SE; }
template<class T> ostream& operator<<(ostream& os, const vector<vector<T>>& v){ rep (i, len(v)) { if (len(v[i])) os << join(v[i]) << (i-len(v)+1 ? "\n" : ""); } return os; }
void print(){ cout << "\n"; }
template<class T, class... A>void print(const T& v, const A&...args){cout << v; if(sizeof...(args))cout << " "; print(args...);}
void print_d(float i){ cout << fixed << setprecision(8) << i << endl; }
/*----------------------------------マクロここまで----------------------------------*/
int main() {
fast;
ll S, P;
cin >> S >> P;
for(ll i = 1; i*i <= P; i++){
if(P%i != 0) continue;
ll j = P / i;
if(i+j == S){
cout << "Yes" << endl;
exit;
}
}
cout << "No" << endl;
return 0;
} |
#include <iostream>
#include <fstream>
#include <algorithm>
#include <functional>
#include <array>
#include <chrono>
#include <random>
#include <vector>
#include <string>
#include <cmath>
#include <bitset>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cassert>
#define sq(x) ((x) * (x))
#define err(x) cerr << "["#x"] " << (x) << "\n";
#define errp(x) cerr << "["#x"] {" << ((x).first) << ", " << ((x).second) << "}\n";
#define errv(x) {cerr << "["#x"] [";for(const auto& ___ : (x)) cerr << ___ << ", "; cerr << "]\n";}
#define errvn(x, n) {cerr << "["#x"] [";for(auto ___ = 0; ___ < (n); ++___) cerr << (x)[___] << ", "; cerr << "]\n";}
#define errf() cerr << "\n\n";
#pragma GCC optimize("Ofast")
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll getrnd(ll l, ll r) {
return uniform_int_distribution<ll>(l, r)(rng);
}
template <typename T1, typename T2> inline bool relax(T1& a, const T2& b) {
return a > b ? a = b, true : false;
}
template <typename T1, typename T2> inline bool strain(T1& a, const T2& b) {
return a < b ? a = b, true : false;
}
// :::::::::::::::::::::::::::::::
const int N = 103;
int cnt[N], was[N];
void dfs(int v, vector<string>& graph) {
if (was[v]) return;
was[v] = 1;
++cnt[v];
for (int i = 0; i < graph[v].size(); ++i) {
if (graph[v][i] == '1')
dfs(i, graph);
}
}
void solve() {
int n;
cin >> n;
vector<string> graph(n);
for (int i = 0; i < n; ++i)
cin >> graph[i];
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j)
was[j] = 0;
dfs(i, graph);
}
ld ans = 0;
for (int i = 0; i < n; ++i)
ans += (ld) 1 / cnt[i];
cout.precision(10);
cout << fixed << ans << '\n';
}
int main() {
ios::sync_with_stdio(0);
cin.tie(nullptr); cout.tie(nullptr);
srand(time(0));
int t = 1;
// cin >> t;
while (t--)
solve();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const ll MOD = 1000000007;
const ll INF = 0x3fffffff;
#define lln \
long long n = 0; \
cin >> n
#define rep(i, n) for (ll i = 0; i < n; i++)
#define sVec(vec) sort(vec.begin(), vec.end())
#define rVec(vec) reverse(vec.begin(), vec.end())
#define iVec(vec) \
for (ll i = 0; i < vec.size(); i++) \
{ \
cin >> vec.at(i); \
}
#define oVec(vec) \
for (ll i = 0; i < vec.size(); i++) \
{ \
cout << vec.at(i) << endl; \
}
#define ExactMinority(degits) \
cout << fixed << setprecision(degits)
#define UniqueVector(vec) \
sort(vec.begin(), vec.end()); \
vec.erase(unique(vec.begin(), vec.end()), vec.end())
int main()
{
string s;
cin >> s;
string t;
bool a = false;
for (int i = 0; i < s.size(); i++)
{
if (s[i] == 'R')
{
a = !a;
}
else
{
if (a)
{
t.insert(t.begin(), s[i]);
}
else
{
t += s[i];
}
}
}
if (a)
{
reverse(t.begin(), t.end());
}
if (t.empty())
{
cout << endl;
return 0;
}
for (int i = 0; i < t.size() - 1; i++)
{
a:
if (t[i] == t[i + 1])
{
t.erase(i, 2);
if (t.empty())
{
cout << endl;
return 0;
}
if (i > 0)
{
i --;
}
goto a;
}
}
cout << t << endl;
} |
#include <bits/stdc++.h>
using namespace std;
int main() {
int A,B;
cin>>A>>B;
int solids=A+B;
if(solids >= 15 and B>=8) cout<<1<<endl;
else if(solids >= 10 and B>=3) cout<<2<<endl;
else if(solids >= 3) cout<<3<<endl;
else cout<<4<<endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
//.define
// #define FILE_IN_OUT
#define RET(_x) cout << (_x) << '\n'; return;
#define all(_obj) (_obj).begin(), (_obj).end()
#define loop(_n) for (int i = 0; i < (_n); ++i)
#define sz(_obj) static_cast<int>((_obj).size())
#ifdef SHJ_LOCAL
#define debug(_x) std::cerr << (#_x) << " = " << (_x) << '\n' << std::flush;
#else
#define debug(_x) {}
#endif
#define endl "\n"
template<typename P, typename Q>
inline P CeilDiv(P _dividend, Q _divider) {
return static_cast<P>((_dividend - 1LL + _divider) / _divider);
}
template<typename Tp>
inline void outarr(Tp _begin, Tp _end, const char* _delim = " ") {
for (Tp current = _begin; current != _end; ++current) {
std::cout << *current << _delim;
}
std::cout << '\n';
}
//.constant
using ll = int64_t;
using pii = std::pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr int MOD = static_cast<int>(1e9 + 7);
//.data
//.code
void SolveTask() {
int a, b;
cin >> a >> b;
if (a + b >= 15 && b >= 8) {
RET(1);
}
if (a + b >= 10 && b >= 3) {
RET(2);
}
if (a + b >= 3) {
RET(3);
}
cout << 4 << endl;
}
int main() {
#ifdef FILE_IN_OUT
std::ifstream cin ("input.txt", std::ios::in);
std::ofstream cout("output.txt", std::ios::out);
#else
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
#endif
int test_cases = 1;
// cin >> test_cases;
for (int yt = 1; yt <= test_cases; ++yt) {
SolveTask();
}
#ifdef FILE_IN_OUT
cin.close();
cout.close();
#endif
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
//indexed set is using "int" here--------- use ll ...
// typedef tree <int,null_type,less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
// #include <ext/rope>
// using namespace __gnu_cxx;
typedef long long int ll;
typedef long double ld;
#define FAST \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define rep(g, i, n) for (ll g = i; g < n; g++)
#define rev(g, n, i) for (ll g = n - 1; g >= i; g--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define mxe(v) *max_element(v.begin(), v.end())
#define mne(v) *min_element(v.begin(), v.end())
#define ve vector
#define lb lower_bound
#define ub upper_bound
#define rem 1000000007
#define PI 3.141592653589793238462643383279502
ll power(ll x, ll y, ll p)
{
ll res = 1; // Initialize result
x = x % p; // Update x if it is more than or
while (y > 0)
{
if (y & 1)
res = (res * x) % p;
y = y >> 1; // y = y/2
x = (x * x) % p;
}
return res;
}
ll modInverse(ll n, ll p)
{
return power(n, p - 2, p);
}
int main()
{
FAST
// freopen("input1.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
/*ll tests;
cin>>tests;
rep (gg,0,tests)
{}*/
string a,b;
cin>>a>>b;
ll x=0,y=0;
for (auto z: a)
{
x+=(z-'0');
}
for (auto z: b)
{
y+=(z-'0');
}
cout<<max(x,y)<<"\n";
}
| #include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define FOR(i,f,n) for(int i=f;i<n;i++)
#define FORI(i,f,n) for(int i=f;i>=n;i--)
#define sz(a) ((int)(a).size())
#define ff first
#define ss second
#define all(a) (a).begin(),(a).end()
#define alli(a) (a).rbegin(),(a).rend()
#define approx(a) fixed<<setprecision(a)
#define trav(a,x) for(auto& a : x)
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<int,bool> pib;
typedef pair<ll,bool> plb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ld> vld;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
template <class T> using pq = priority_queue<T>;
template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>;
template <class T> void ckmin(T &a, const T &b) { a = min(a, b); }
template <class T> void ckmax(T &a, const T &b) { a = max(a, b); }
template <class T> void read(vector<T> &v);
template <class F, class S> void read(pair<F, S> &p);
template <class T> void read(T &x) {cin>>x;}
template <class R, class... T> void read(R& r, T&... t){read(r); read(t...);};
template <class T> void read(vector<T> &v) {trav(x, v) read(x);}
template <class F, class S> void read(pair<F, S> &p) {read(p.ff, p.ss);}
template <class F, class S> void pr(const pair<F, S> &x);
template <class T> void pr(const T &x) {cout<<x;}
template <class R, class... T> void pr(const R& r, const T&... t) {pr(r); pr(t...);}
template <class F, class S> void pr(const pair<F, S> &x) {pr("{", x.ff, ", ", x.ss, "}");}
void ps() {pr("\n");}
template <class T> void ps(const T &x) {pr(x); ps();}
template <class T> void ps(vector<T> &v) {trav(x, v) pr(x, ' '); ps();}
template <class F, class S> void ps(const pair<F, S> &x) {pr(x.ff, ' ', x.ss); ps();}
template <class R, class... T> void ps(const R& r, const T &...t) {pr(r, ' '); ps(t...);}
int h, w, n, m;
void solve(){
read(h, w, n, m);
vector<vi> grid(h, vi(w));
FOR(i,0,n){
int x, y; read(x,y);
x--, y--;
grid[x][y] = 1;
}
FOR(i,0,m){
int x, y; read(x,y);
x--, y--;
grid[x][y] = -1;
}
vector<vi> row = grid;
vector<vi> col = grid;
FOR(i,0,h){
FOR(j,1,w){
if(row[i][j] != -1 && row[i][j-1] == 1){
row[i][j] = 1;
}
}
FORI(j,w-2,0){
if(row[i][j] != -1 && row[i][j+1] == 1){
row[i][j] = 1;
}
}
}
FOR(j,0,w){
FOR(i,1,h){
if(col[i][j] != -1 && col[i-1][j] == 1){
col[i][j] = 1;
}
}
FORI(i,h-2,0){
if(col[i][j] != -1 && col[i+1][j] == 1){
col[i][j] = 1;
}
}
}
int ans = 0;
FOR(i,0,h){
FOR(j,0,w){
if(row[i][j] == 1 || col[i][j] == 1) ans++;
}
}
ps(ans);
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int t=1;
//cin>>t;
while(t--){
solve();
}
} |
#include <iostream>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <stack>
#include <queue>
#include <array>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <random>
#include <chrono>
#include <utility>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <sstream>
#include <assert.h>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c> {i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef HOME
~debug() { cerr << endl; }
eni( != ) cerr << boolalpha << i; ris;
}
eni( == ) ris << range(begin(i), end(i));
}
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define ff first
#define ss second
#define REP(i,st,en) for (int i = st; i <= en; i++)
#define REPR(i,st,en) for (int i = st; i >= en; i--)
const int MOD = 998244353;
class Modint {
public:
long long val;
Modint (long long _val = 0) {
if (_val >= MOD) _val %= MOD;
val = _val;
}
Modint operator+ (Modint other) {
return Modint(val + other.val);
}
void operator+= (Modint other) {
val += other.val;
if (val >= MOD) val %= MOD;
}
Modint operator- () {
return Modint(MOD - val);
}
Modint operator- (Modint other) {
return Modint(val + MOD - other.val);
}
void operator-= (Modint other) {
val += MOD - other.val;
if (val >= MOD) val %= MOD;
}
Modint operator* (Modint other) {
return Modint(val * other.val);
}
void operator*= (Modint other) {
val *= other.val;
if (val >= MOD) val %= MOD;
}
bool operator== (Modint other) {
return val == other.val;
}
bool operator!= (Modint other) {
return val != other.val;
}
};
Modint exp (Modint a, long long k) {
Modint res = 1;
while (k) {
if (k & 1) res *= a;
a *= a;
k >>= 1;
}
return res;
}
Modint inv (Modint a) {
return exp(a, MOD - 2);
}
ostream& operator<< (ostream& out, Modint p) {
out << p.val;
return out;
}
const int maxn = 2e5;
vector<Modint> fact(maxn + 1, 1);
vector<Modint> inv_fact(maxn + 1, 1);
void preC() {
for (int i = 2; i <= maxn; i++) {
fact[i] = fact[i - 1] * i;
}
inv_fact[maxn] = inv(fact[maxn]);
for (int i = maxn - 1; i >= 0; i--) inv_fact[i] = inv_fact[i + 1] * (i + 1);
}
Modint C(int n, int r) { // nCr % MOD
if (n < r) return 0;
return fact[n] * inv_fact[r] * inv_fact[n - r];
}
class MainClass {
public:
void solve() {
int n, m; cin >> n >> m;
if (m == 1) {
cout << 1;
return;
}
int lgm = log2(m) + 1;
Modint ans = 0;
vector<Modint> dp(m + 1, 1);
for (int i = 1; i <= lgm; i++) {
vector<Modint> new_dp(m + 1, 0);
Modint curr = 0;
for (int j = 1; j <= m; j++) {
for (int k = 2 * j; k <= m; k += j) new_dp[k] += dp[j];
curr += dp[j];
}
ans += C(n - 1, i - 1) * curr;
swap(dp, new_dp);
}
cout << ans;
return;
}
};
int main() {
preC();
int test = 1; //cin >> test;
for (int tst = 1; tst <= test; ++tst) {
MainClass Ausmosian;
Ausmosian.solve();
cout << "\n";
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(v) begin(v), end(v)
#define sz(v) v.size()
#define INF 1e18+9
#define EPSILON 1e-14
template <typename T>
bool chmax(T &a, const T& b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T>
bool chmin(T &a, const T& b) {
if (a > b) {
a = b;
return true;
}
return false;
}
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 998244353;
struct mint {
ll x; // typedef long long ll;
mint(ll x=0):x((x%mod+mod)%mod){}
mint operator-() const { return mint(-x);}
mint& operator+=(const mint a) {
if ((x += a.x) >= mod) x -= mod;
return *this;
}
mint& operator-=(const mint a) {
if ((x += mod-a.x) >= mod) x -= mod;
return *this;
}
mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
mint operator+(const mint a) const { return mint(*this) += a;}
mint operator-(const mint a) const { return mint(*this) -= a;}
mint operator*(const mint a) const { return mint(*this) *= a;}
mint pow(ll t) const {
if (!t) return 1;
mint a = pow(t>>1);
a *= a;
if (t&1) a *= *this;
return a;
}
// for prime mod
mint inv() const { return pow(mod-2);}
mint& operator/=(const mint a) { return *this *= a.inv();}
mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
vector<pair<long long, long long> > prime_factorize(long long N) {
vector<pair<long long, long long> > res;
for (long long a = 2; a * a <= N; ++a) {
if (N % a != 0) continue;
long long ex = 0; // 指数
// 割れる限り割り続ける
while (N % a == 0) {
++ex;
N /= a;
}
// その結果を push
res.push_back({a, ex});
}
// 最後に残った数について
if (N != 1) res.push_back({N, 1});
return res;
}
vector<mint> fac(2000003, 1);
void calc(int n){
rep(i, n){
fac.at(i+1) = fac.at(i) * (i+1);
}
return;
}
mint mcom(int n, int k){ // nCk
if(n-k < 0){
return 0;
}
mint a = fac.at(n);
mint b = fac.at(k);
mint d = fac.at(n-k);
mint ans = a / (b * d);
return ans;
}
int main()
{
ll N, M;
cin >> N >> M;
calc(2000000);
mint ans = 0;
rep2(i, 1, M+1){
vector<pair<ll, ll>> pf = prime_factorize(i);
mint t = 1;
for(auto p : pf){
t *= mcom(p.second+N-1, p.second);
}
ans += t;
}
cout << ans << '\n';
} |
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define fore(i_in,a) for (auto& i_in: a)
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fio() cin.tie(nullptr);ios::sync_with_stdio(false);
#define DEBUG_CTN(v) cerr<<#v<<":";for(auto itr=v.begin();itr!=v.end();itr++) cerr<<" "<<*itr; cerr<<endl
template<class T> bool chmax(T &a, const T &b) {if (a<b) { a = b; return true; } return 0;}
template<class T> bool chmin(T &a, const T &b) {if (a>b) { a = b; return true; } return 0;}
template<class T> void print(const T &t) { cout << t << "\n"; }
const ll INF = 1LL << 62;
const int iINF = 1 << 30;
string s;
int main() {
fio(); cin>>s;
auto itr = s.find('.');
print(s.substr(0,itr));
}
| #include <iostream>
#include <vector>
#include <numeric>
using namespace std;
typedef long long ll;
vector<ll> v;
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n; cin >> n; v.resize(n);
for (auto& x : v) { cin >> x; }
ll res = 0; for (auto& x : v)
res += x * x * (n - 1);
ll s = accumulate(v.begin(), v.end(), 0ll);
for (auto& x : v) res -= x * (s - x);
cout << res << '\n'; cin.ignore(2); return 0;
} |
#include <bits/stdc++.h>
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll long long
#define F first
#define S second
#define pb push_back
using namespace std;
const ll mx1=3e5+6, mx2=6e3+6, mod=1e9+7, lg=30;
ll a[10];
int main(){
fast;
ll sum=0;
for(int i=0; i<4; i++){
cin>>a[i];
sum+=a[i];
}
for(int msk=0; msk<(1<<4); msk++){
ll sum2=0;
for(int i=0; i<4; i++) if((1<<i)&msk) sum2+=a[i];
if(sum2*2==sum){
cout<<"Yes"<<endl;
exit(0);
}
}
cout<<"No"<<endl;
return 0;
}
| #include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
#define fbo find_by_order
#define ook order_of_key
#define fi first
#define se second
#define long long long
#define mul(a, b) ((a*b)%MOD)
#define add(a, b) ((a+b)%MOD)
#define dec(a, b) ((a-b+MOD)%MOD)
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
const int INF = 1e9;
const long LINF = 1e18;
// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// mt19937_64 rng(std::chrono::system_clock::now().time_since_epoch().count());
// inv[1] = 1;
// fac[0] = ifac[0] = 1;
// for(int i = 2; i <= 500000; i++) inv[i]=MOD-(MOD/i)*inv[MOD%i]%MOD;
// for(int i = 1; i <= 500000; i++) fac[i] = mul(i, fac[i-1]), ifac[i] = mul(inv[i], ifac[i-1]);
// /mnt/c/Users/vince/Desktop/POST-IOI/
int main()
{
// ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// freopen("input.in", "r", stdin);
long A[4];
scanf("%lld %lld %lld %lld", &A[0], &A[1], &A[2], &A[3]);
sort(A, A+4);
bool bol = 0;
do
{
if(A[0] == A[1] + A[2] + A[3]) bol = 1;
if(A[0]+A[1] == A[2] + A[3]) bol = 1;
if(A[0]+A[1]+A[2] == A[3]) bol = 1;
}while(next_permutation(A, A+4));
if(bol) printf("Yes\n");
else printf("No\n");
} |
#include <bits/stdc++.h>
using namespace std;
int main() {
int64_t R, C;
cin >> R >> C;
vector<vector<int64_t>> A(R, vector<int64_t>(C - 1));
vector<vector<int64_t>> B(R - 1, vector<int64_t>(C));
for (int64_t i = 0; i < R; i++) {
for (int64_t j = 0; j < C - 1; j++) {
cin >> A[i][j];
}
}
for (int64_t i = 0; i < R - 1; i++) {
for (int64_t j = 0; j < C; j++) {
cin >> B[i][j];
}
}
vector<vector<int64_t>> cost(R, vector<int64_t>(C, LLONG_MAX));
struct Element {
int64_t r, c, cost;
bool operator>(const Element& rhs) const {
return cost > rhs.cost;
}
};
priority_queue<Element, vector<Element>, greater<Element>> pq;
pq.push({ 0, 0, cost[0][0] = 0 });
while (!pq.empty()) {
Element t = pq.top();
pq.pop();
if (t.cost > cost[t.r][t.c]) {
continue;
}
if (t.r == R - 1 && t.c == C - 1) {
break;
}
if (t.c < C - 1) {
int64_t new_cost = t.cost + A[t.r][t.c];
if (new_cost < cost[t.r][t.c + 1]) {
pq.push({ t.r, t.c + 1, cost[t.r][t.c + 1] = new_cost });
}
}
if (t.c > 0) {
int64_t new_cost = t.cost + A[t.r][t.c - 1];
if (new_cost < cost[t.r][t.c - 1]) {
pq.push({ t.r, t.c - 1, cost[t.r][t.c - 1] = new_cost });
}
}
if (t.r < R - 1) {
int64_t new_cost = t.cost + B[t.r][t.c];
if (new_cost < cost[t.r + 1][t.c]) {
pq.push({ t.r + 1, t.c, cost[t.r + 1][t.c] = new_cost });
}
}
for (int64_t i = 1; i <= t.r; i++) {
int64_t new_cost = t.cost + 1 + i;
if (new_cost < cost[t.r - i][t.c]) {
pq.push({ t.r - i, t.c, cost[t.r - i][t.c] = new_cost });
}
}
}
cout << cost[R - 1][C - 1] << endl;
} | // E - 潜入
#include <bits/stdc++.h>
using namespace std;
#define vec vector
using vi = vec<int>;
using PR = pair<int,int>;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
int V; // 頂点数
vec<vec<PR>> G; // [from]<to, cost> 隣接リスト
int INF = 1e9;
vi dijkstra(int s){
vi dist(V, INF);
dist[s] = 0;
priority_queue<PR, vec<PR>, greater<PR>> pq;
pq.push({0, s});
while(pq.size()){
auto[from_d, from_v] = pq.top(); pq.pop();
if(dist[from_v] < from_d) continue;
for(auto[to_u, to_d]:G[from_v]){
to_d += dist[from_v];
if(dist[to_u] <= to_d) continue;
dist[to_u] = to_d;
pq.push({to_d, to_u});
}
}
return dist;
}
int main(){
int R, C; cin>>R>>C;
auto rc2id = [&](int r, int c){ return r*C + c; };
V = R*C*2;
G.resize(V);
int x, a, b;
rep(r, R) rep(c, C-1){
cin>>x;
a = rc2id(r, c), b = rc2id(r, c+1);
G[a].emplace_back(b, x), G[b].emplace_back(a, x);
}
rep(r, R-1) rep(c, C){
cin>>x;
G[rc2id(r, c)].emplace_back(rc2id(r+1, c), x);
}
rep(r, R) rep(c, C){
a = rc2id(r, c), b = rc2id(r, c+R*C);
G[a].emplace_back(b, 1), G[b].emplace_back(a, 0);
if(r != R-1) G[rc2id(r+1, c+R*C)].emplace_back(rc2id(r, c+R*C), 1);
}
cout<< dijkstra(0)[rc2id(R-1,C-1)] <<endl;
}
|
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <string>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
typedef long long ll;
using namespace std;
int main(){
float n,a,b;
cin >> n;
vector<float> x(n);
vector<float> y(n);
rep(i,n){
cin >> x[i] >> y[i];
}
int count=0;
for(int i=0; i<n; i++){
for(int j=i+1; j<n; j++){
if(i!=j){
if((y[i]-y[j])/(x[i]-x[j])>=-1&&(y[i]-y[j])/(x[i]-x[j])<=1) count++;
}
}
}
cout << count << endl;
} | #include<bits/stdc++.h>
using namespace std;
double slope(int n,int m,int n1,int m1){
if(n-n1==0)return 9;
double i=(m1-m)*1.00;
double j=(n-n1)*1.00;
return i/j;
}
int a[100001];
int b[100001];
int main(){
int n,ans=0;
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d %d",&a[i],&b[i]);
for(int i=1;i<=n;i++)
for(int j=i+1;j<=n;j++){
if(slope(a[i],b[i],a[j],b[j])>=-1.000000 && slope(a[i],b[i],a[j],b[j])<=1.000000)ans++;
}
cout<<ans;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
const ll mod = 1000000007;
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
string s,str;
cin>>s;
ll i,n=s.length();
for(i=0;i<n;i++)
{
if(s[i]=='.')
{
break;
}
else
str=str+s[i];
}
cout<<str<<"\n";
} | #include<bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define endl '\n'
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll dp[201][13];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
// if a == b or b == 0 => C = 1
int l;
cin >> l;
memset(dp,0,sizeof(dp));
dp[0][0] = 1;
for(int i = 0; i < l; i++) {
for(int j = 0; j < 12; j++) {
if(dp[i][j] == 0) continue;
dp[i + 1][j] += dp[i][j];
dp[i + 1][j + 1] += dp[i][j];
}
}
cout << dp[l - 1][11] << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, a, b) for (int i = (int)(a); i >= (int)b; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, r, l) for (int i = (r); i >= (l); i--)
#define ms(x, y) memset(x, y, sizeof(x))
#define SZ(x) int(x.size())
#define ok cerr<<"ok"<<endl
#define db(x) cerr<<(#x)<<'='<<(x)<<endl
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
//1.integer overflow (1e5 * 1e5) (2e9 + 2e9)
//2.runtime error
//3.boundary condition
const int N=(int)1e5+100;
int n,m,col[N];
vector< pair<int,int> > G[N];
void dfs(int now){
for(pair<int,int> pnow:G[now]){
if(col[pnow.fi]>0) continue;
if(col[now]==pnow.se){
col[pnow.fi]=pnow.se%n+1;
} else col[pnow.fi]=pnow.se;
dfs(pnow.fi);
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.precision(10);
cout << fixed;
#ifdef LOCAL_DEFINE
freopen("input.txt", "r", stdin);
#endif
ms(col,0);
cin>>n>>m;
forn(i, m){
int u,v,c;
cin>>u>>v>>c;
G[u].eb(mp(v,c));
G[v].eb(mp(u,c));
}
col[1]=1;
dfs(1);
for1(i, n) cout<<col[i]<<'\n';
#ifdef LOCAL_DEFINE
cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
return 0;
}
| #include <bits/stdc++.h>
#define s second
#define f first
#define pb push_back
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define read(x) for(auto& qw : (x)) cin >> qw;
#define print(x) for(auto& qw : (x)) cout << qw << " "; cout << endl;
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MAX = 1e5 + 10;
vector<int> g[MAX];
int N, M, K;
vector<int> A;
vector<vector<int>> D(18,vector<int>(MAX,0));
void bfs(int s, vector<int> &d){
fill(all(d), INF);
queue<int> Q;
Q.push(s);
d[s] = 0;
while(Q.size()){
int v = Q.front();
Q.pop();
for(int u : g[v]){
if(d[u] != INF) continue;
d[u] = d[v] + 1;
Q.push(u);
}
}
}
ll DP[(1<<18)][20];
ll solve(int mask, int last){
if(DP[mask][last] + 1)
return DP[mask][last];
if(mask == (1<<K) - 1)
return 0;
ll ans = LINF;
for(int i = 0; i < K; i++){
if(mask >> i & 1) continue;
int n_mask = mask | (1 << i);
ans = min(ans, (ll)D[last][A[i]] + solve(n_mask, i));
}
return DP[mask][last] = ans;
}
void test_case(){
cin >> N >> M;
while(M--){
int a,b;
cin >> a >> b;
a--;b--;
g[a].pb(b);
g[b].pb(a);
}
cin >> K;
A.resize(K);
for(int& x : A){
cin >> x;
x--;
}
for(int i = 0; i < K; i++)
bfs(A[i],D[i]);
memset(DP, -1, sizeof DP);
ll ans = LINF;
for(int i = 0; i < K; i++)
ans = min(ans, 1 + solve(1<<i, i));
cout << (ans >= INF ? -1 : ans) << endl;
}
int main(){ _
int tt = 1;
// cin >> tt;
while(tt--){
test_case();
}
return 0;
}
|
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<cstring>
#include<string>
#include<iostream>
using namespace std;
typedef long long ll;
const int N = 1e6 + 50;
ll M;
char s[N];
bool mul(ll &x, ll y){
ll tt = 0;
while(y){
if(x > M) return 0;
if(y & 1) tt += x;
x = x + x, y >>= 1;
if(tt > M) return 0;
}
x = tt;
return 1;
}
bool check(ll bs){
ll now = 0;
for(int i = 1; s[i]; ++i){
int bt = s[i] - '0';
bool ok = mul(now, bs);
now += bt;
if(!ok || now > M) return 0;
}
return 1;
}
int main(){
scanf("%s%lld", s + 1, &M);
int mx = 0;
for(int i = 1; s[i]; ++i) mx = max(mx, s[i] - '0');
++mx;
if(!check(mx)) printf("0");
else{
ll l = mx, r = 1e18, ans;
if(strlen(s + 1) == 1){
if(s[1] - '0' <= M) puts("1");
else puts("0");
return 0;
}
while(l <= r){
ll mid = (l + r) >> 1;
if(check(mid)) ans = mid, l = mid + 1;
else r = mid - 1;
}
printf("%lld", ans - mx + 1);
}
} | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
string t,s;
int main()
{
cin>>n;
cin>>t;
while(s.size()<t.size()+3-1)
s+="110";
int m=s.size();
int cnt=0,ok0=0,ok1=0;
for(int i=0;i<3;i++)
{
int ok=1;
for(int j=0;j<t.size();j++)
ok&=t[j]==s[i+j];
cnt+=ok;
if(i==0)
ok0=ok;
if(i==1)
ok1=ok;
}
ll ans=1e10-m/3+1;
ans*=cnt;
if(t.size()%3==0&&ok0)
ans++;
if(t.size()%3==2&&(ok0||ok1))
ans++;
printf("%lld\n",ans);
}
|
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d,e,i,j,ii,jj,zx,xc,p[100009],pi,N=10000;
long long fx[100009];
int main(){
ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cin>>a;
pi=3;
p[1]=6;p[2]=15;p[3]=10;
for(i=2; i<=N; i++){
if(i*p[3]>N) break;
if(fx[i*p[3]]==1) continue;
fx[i*p[3]]=1;
pi++;
p[pi]=i*p[3];
}
for(i=2; i<=N; i++){
if(i*p[2]>N) break;
if(fx[i*p[2]]==1) continue;
fx[i*p[2]]=1;
pi++;
p[pi]=i*p[2];
}
for(i=2; i<=N; i++){
if(i*p[1]>N) break;
if(fx[i*p[1]]==1) continue;
fx[i*p[1]]=1;
pi++;
p[pi]=i*p[1];
}
for(i=1; i<=a; i++){
cout<<p[i]<<" ";
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e6 + 5;
// int tree[maxn];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// iota(tree, tree + maxn, 0);
string s;
cin >> s;
cout << s.substr(1) << s[0] << endl;
}
|
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef long double ld;
/*
#include <chrono>
using namespace std::chrono;
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<pair<lli,lli>, null_type,less<pair<lli,lli>>, rb_tree_tag,tree_order_statistics_node_update>
*/
#define endl "\n"
#define pb push_back
const lli mod=1e9+7;
const lli mod1=998244353;
#define fir first
#define sec second
#define plli pair<lli,lli>
/*
lli power(lli a, lli b) {
lli res = 1;
while (b > 0) {
if (b & 1)
res = res * a;
a = a * a;
b >>= 1;
}
return res;
}
lli powermod(lli a, lli b)
{
lli res = 1;
while (b > 0) {
if (b & 1)
res = ((res%mod)*(a%mod))%mod;
a = (a * a)%mod;
b >>= 1;
}
return res;
}
*/
bool comp(plli &p1,plli &p2)
{
return (p1.fir>p2.fir || (p1.fir==p2.fir and p1.sec<p2.sec));
}
int main()
{
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
lli T;
T=1;
//cin>>T;
while(T--)
{
lli i,j,k;
vector<lli> v;
lli vis[51]={0};
for(i=2;i<=50;i++)
{
if(!vis[i])
{
for(j=i*i;j<=50;j+=i)
{
vis[j]=1;
}
v.pb(i);
}
}
lli x=v.size();
lli n;
cin>>n;
lli a[n];
for(i=0;i<n;i++)
cin>>a[i];
lli b[n];
lli ans=mod*mod;
for(i=0;i<(1<<x);i++)
{
for(j=0;j<n;j++)
b[j]=a[j];
lli temp=1;
for(j=0;j<x;j++)
{
if(i&(1<<j))
{
for(k=0;k<n;k++)
{
while(b[k]%v[j]==0)
b[k]/=v[j];
}
temp*=v[j];
}
}
lli flag=1;
for(j=0;j<n;j++)
if(b[j]==a[j])
flag=0;
if(flag)
{ans=min(ans,temp);}
}
cout<<ans<<"\n";
}
return 0;
}
| #include<bits/stdc++.h>
#include<iostream>
#include<set>
#include<map>
#include<iterator>
#define ll long long
#define lli long long int
#define pb push_back
#define RIP(i,n) for(int i=0; i<n; i++)
#define RIP1(i,n) for(int i=n-1; i>=0; i--)
#define FOR(i,a,b) for(int i=a;i<(b); i++)
#define FOR1(i,a,b) for(int i=a; i>=(b); i--)
#define sc(a) scanf("%lld",&a)
#define SC(a) scanf("%d",&a)
#define cin(a) cin >> a
#define cout(a) cout << a
#define pi acos(-1)
#define pr(a) printf("%lld\n",a)
#define PR(a) printf("%lld ",a)
#define s(a,b) sort(a,b)
#define sz(x) (int)(x).size()
#define nl '\n'
#define Max 1001
#define mod 1e9 + 7
using namespace std;
void c_p_c()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
/*#ifdef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif*/
}
int dp[1001][1001],a[Max],b[Max];
int cost(int i,int j)
{
if(i==-1 && j==-1)
{
return 0;
}
if(i==-1)
{
return j+1;
}
if(j==-1)
{
return i+1;
}
if(dp[i][j]!=0)
{
return dp[i][j];
}
int x=cost(i-1,j)+1;
int y=cost(i,j-1)+1;
int z=cost(i-1,j-1)+(a[i]!=b[j]);
return dp[i][j]=min(x,min(y,z));
}
int main()
{
c_p_c();
int n,m;
SC(n);SC(m);
//int a[n],b[m];
RIP(i,n)
{
SC(a[i]);
}
RIP(i,m)
{
SC(b[i]);
}
int ans = cost(n-1,m-1);
cout << ans << nl;
}
|
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define pb push_back
#define all(v) begin(v), end(v)
#define inf (int)(4e18)
#define N (int)(2e5 + 10)
void testCase() {
int n; cin >> n;
vector<int> a(n);
for (int &i : a) cin >> i;
sort(all(a));
int ans = 0;
for (int i = 0; i < n; i++)
ans += (2 * i + 1 - n) * a[i]; cout << ans;
}
/* Work hard .. Calm and proceed */
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
int t_c = 1;
// cin >> t_c;
while (t_c--)
testCase();
} | #include<bits/stdc++.h>
#define lli long long int
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
using namespace std;
lli min(lli a,lli b)
{
if (a<b)
{
return a;
}
else
{
return b;
}
}
lli max(lli a,lli b)
{
if (a>b)
{
return a;
}
else
{
return b;
}
}
void solve()
{
lli a,b,c,d;
cin>>a>>b>>c>>d;
cout<<min(a,min(b,min(c,d)))<<endl;
}
int main(){
fastio;
cout<<fixed;
cout<<setprecision(10);
lli t=1;
//cin>>t;
for(lli i=1;i<=t;i++)
{
solve();
}
return 0;
} |
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
using namespace std;
typedef pair<llint, llint> P;
llint n;
llint l[105], r[105];
llint a[205], b[205], f[205];
bool dp[205][205];
int check(llint L, llint R)
{
llint id = a[L];
if(id == 0){
if(a[R] == 0) return 1;
else{
if(b[R] == 1 && f[R] == 1) return 0;
else return 1e6;
}
}
else{
if(r[id] != -1 && r[id] != R) return 1e6;
return 0;
}
}
int main(void)
{
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
llint m = 0;
for(int i = 1; i <= n; i++){
cin >> l[i] >> r[i];
if(l[i] != -1) a[l[i]] = i, b[l[i]] = 0;
if(r[i] != -1) a[r[i]] = i, b[r[i]] = 1;
if(l[i] == -1 && r[i] != -1) f[r[i]] = 1;
if(l[i] == -1 && r[i] == -1) m++;
}
dp[0][0] = true;
for(int i = 0; i < 2*n; i++){
if(b[i+1] == 1) continue;
for(int j = 0; j <= m; j++){
if(!dp[i][j]) continue;
for(int k = i+2; k <= 2*n; k++){
//cout << i+1 << " " << k << endl;
if(check(i+1, k) > 1000) continue;
//cout << i+1 << " " << k << endl;
//if(id && r[id] != -1 && r[id] != j) continue;
//if(id == 0 && a[j] != 0 && f[j] == 0) continue;
int cnt = 0;
cnt += check(i+1, k);
for(int l = i+2; l < k; l++){
cnt += check(l, l+(k-(i+1)));
//cout << cnt << endl;
}
//cout << i+1 << " " << k << " " << cnt << endl;
if(j+cnt <= m && (k-1)+(k-(i+1)) <= 2*n) dp[(k-1)+(k-(i+1))][j+cnt] = true;
}
}
}
/*for(int i = 0; i <= 2*n; i++){
for(int j = 0; j <= m; j++){
cout << dp[i][j] << " ";
}
cout << endl;
}*/
if(dp[2*n][m]) cout << "Yes" << endl;
else cout << "No" << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define per(i, b) per2(i, 0, b)
#define per2(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define ALL(c) (c).begin(), (c).end()
#define SZ(x) ((int)(x).size())
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
template <class T, class U>
void chmin(T& t, const U& u) {
if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
if (t < u) t = u;
}
template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
os << "(" << p.first << "," << p.second << ")";
return os;
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
os << "{";
rep(i, v.size()) {
if (i) os << ",";
os << v[i];
}
os << "}";
return os;
}
#ifdef LOCAL
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << " " << H;
debug_out(T...);
}
#define debug(...) \
cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif
int main() {
int N;
cin >> N;
V<int> A(N), B(N);
int sz = N * 2;
V<int> tp(sz), com(sz, -1);
bool ng = false;
rep(i, N) {
cin >> A[i] >> B[i];
if (A[i] != -1) {
--A[i];
if (tp[A[i]]) ng = true;
tp[A[i]] = i + 1;
}
if (B[i] != -1) {
--B[i];
if (tp[B[i]]) ng = true;
tp[B[i]] = -(i + 1);
}
if (A[i] != -1 && B[i] != -1) {
com[A[i]] = B[i];
com[B[i]] = A[i];
}
}
if (ng) {
puts("No");
return 0;
}
V<bool> dp(sz + 1);
dp[0] = true;
rep(i, sz) {
if (!dp[i]) continue;
for (int j = i + 1; j < sz; ++j) {
int w = j - i + 1;
if (w & 1) continue;
w /= 2;
bool ok = true;
rep(k, w) {
int p = i + k, q = i + k + w;
if (com[p] != -1 && !(i <= com[p] && com[p] <= j)) {
ok = false;
}
if (com[q] != -1 && !(i <= com[q] && com[q] <= j)) {
ok = false;
}
if (tp[p] != 0 && tp[q] != 0) {
if (tp[p] < 0 || tp[p] + tp[q] != 0) {
ok = false;
}
}
if (tp[p] < 0 || tp[q] > 0) {
ok = false;
} else {
if (tp[p] != 0) {
int v = tp[p] - 1;
}
}
}
if (ok) {
dp[j + 1] = true;
}
}
}
puts(dp[sz] ? "Yes" : "No");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<ll,ll> P;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define EFOR(i,a,b) for(ll i=(a);i<=(b);++i)
#define REP(i, n) FOR(i,0,n)
#define INF 1000000000
ll nums = 10000000000;
int main() {
int n; cin >> n;
string s,t; cin >> s;
REP(i,s.size()){
t.push_back(s[i]);
if(t.size() <= 2) continue;
if(t.substr(t.size()-3,t.size()) == "fox"){
t = t.substr(0,t.size()-3);
}
}
cout << t.size() << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int mod = 1000000007;
int mpow(int b, int e);
int main(){
IOS
int n, m; cin>>n>>m;
vector<int> g(1<<n, 0), complete(1<<n, -1);
for(int i=0; i<m; i++){
int a, b; cin>>a>>b; a--; b--;
g[1<<a] = g[1<<a] | (1<<b);
g[1<<b] = g[1<<b] | (1<<a);
}
for(int i=1; i<(1<<n); i++){
for(int j=0, t=i; t; t>>=1, j++){
if(i & (1<<j)){
int x = i^(1<<j), y = g[1<<j];
if((y & x) != x){
complete[i]=0;
break;
}
}
}
if(complete[i]==-1)
complete[i]=1;
}
vector<int> dp(1<<n, INT_MAX);
// dp[0]=1;
for(int i=1; i<(1<<n); i++){
if(complete[i]==1)
dp[i]=1;
else{
for(int j=i-1; j; j = (j-1)&i)
dp[i] = min(dp[i], dp[j]+dp[i^j]);
}
}
// for(auto i: g) cout<<i<<" "; cout<<endl;
// for(auto i: complete) cout<<i<<" ";
// cout<<endl;
cout<<dp[(1<<n)-1]<<endl;
return 0;
}
//modular exponentiation
int mpow(int base, int exp) {
base %= mod;
int result = 1;
while (exp > 0) {
if (exp & 1) result = ((ll)result * base) % mod;
base = ((ll)base * base) % mod;
exp >>= 1;
}
return result;
} |
#include<bits/stdc++.h>
#define re register
#define in inline
#define ll int
using namespace std;
char rbuf[10000002];
int pt;
in char gc(){
return getchar();
}
in int read(){
re int t=0;
re char v=gc();
while(v<'0')v=gc();
while(v>='0'){
t=(t<<3)+(t<<1)+(v^48);
v=gc();
}
return t;
}
struct edge{
int to,next,w;
}e[3002*3002*2];
int n,m,cnt,k,l[15],r[15],head[3002*3002],a,b,c,pl[32],w[15];
struct node{
int pos;
ll dis;
bool operator <(const node x)const{
return dis>x.dis;
}
}h[3002*3002];
priority_queue <node> q;
inline ll M(re ll x,re ll y){
return (x<y)?(x):(y);
}
inline void dis(re int s){for(re int i=1;i<=n*m+26;++i)h[i].pos=i,h[i].dis=0x7fffffff;
h[s].dis=0;
q.push(h[s]);
while(!q.empty()){
while((h[q.top().pos].dis<q.top().dis)){q.pop();if(q.empty())break;
}
if(q.empty())break;
node tmp=q.top();
q.pop();
for(re int i=head[tmp.pos];i;i=e[i].next){
if((tmp.dis+e[i].w)<h[e[i].to].dis){
h[e[i].to].dis=tmp.dis+e[i].w;
q.push(h[e[i].to]);
}
}
}
}
inline void add(re int x,re int y,re int z){
e[++cnt].to=y;
e[cnt].w=z;
e[cnt].next=head[x];
head[x]=cnt;
}
char s[3002][3002];
signed main(){
// freopen("test.in","r",stdin);
// freopen("test.out","w",stdout);
n=read();
re int ss,tt;
m=read();
for(re int i=1;i<=n;++i)scanf("%s",s[i]+1);
for(re int i=1;i<=n;++i){
for(re int j=1;j<=m;++j){
if(s[i][j]!='#'&&s[i+1][j]!='#'&&i!=n){
add((i-1)*m+j,i*m+j,1);
add(i*m+j,(i-1)*m+j,1);
}
if(s[i][j]!='#'&&s[i][j+1]!='#'&&j!=m){
add((i-1)*m+j,(i-1)*m+j+1,1);
add((i-1)*m+j+1,(i-1)*m+j,1);
}
if(s[i][j]>='a'&&s[i][j]<='z'){
add((i-1)*m+j,n*m+s[i][j]-'a'+1,1);
add(n*m+s[i][j]-'a'+1,(i-1)*m+j,0);
}
if(s[i][j]=='S')ss=(i-1)*m+j;
if(s[i][j]=='G')tt=(i-1)*m+j;
}
}
dis(ss);
if(h[tt].dis<=1e9)
printf("%d ",h[tt].dis);
else puts("-1");
} | #include"bits/stdc++.h"
using namespace std;
const int N=2100;
char a[N][N];
vector<pair<int,int>> c[26];
int dx[]={1,-1,0,0};
int dy[]={0,0,-1,1};
int d[N][N];
int n,m;
const int inf=1e9;
bool vis[26];
bool ok(int x,int y){
return (x<=n and y<=m and x>=1 and y>=1);
}
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)d[i][j]=inf;
for(int i=1;i<=n;i++){
scanf("%s", a[i]+1);
}
int sx=-1,sy=-1,gx=-1,gy=-1;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(a[i][j]<='z' and a[i][j]>='a')c[a[i][j]-'a'].push_back({i,j});
if(a[i][j]=='S'){sx=i;sy=j;}
if(a[i][j]=='G'){gx=i;gy=j;}
}
}
deque<pair<int,int>> q;
q.push_back({sx,sy});
d[sx][sy]=0;
while(!q.empty()){
auto p=q.front();
q.pop_front();
int cur=d[p.first][p.second];
int curc=a[p.first][p.second];
if(curc<='z' and curc>='a' and !vis[curc-'a']){
for(auto pp:c[curc-'a']){
if(d[pp.first][pp.second]>1+cur){
q.push_front({pp.first,pp.second});
d[pp.first][pp.second]=1+cur;
}
}
vis[curc-'a']=1;
}
for(int k=0;k<4;k++){
int nx=p.first+dx[k];
int ny=p.second+dy[k];
if(!ok(nx,ny))continue;
if(a[nx][ny]=='#')continue;
if(d[nx][ny]>1+cur)
{
d[nx][ny]=1+cur;
q.push_back({nx,ny});
}
}
}
if(d[gx][gy]==inf)puts("-1");
else cout<<d[gx][gy]<<"\n";
}
|
// Rakib (CSE'19)
#include<bits/stdc++.h>
#define ll long long
#define boost_ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define ull unsigned long long
#define read(i,n,a) for(i=0;i<n;++i) cin>>a[i]
#define show(i,a) for(auto i:a) cout<<i<<" "; cout<<endl
#define dpoint(n) cout<<showpoint<<fixed<<setprecision(n)
#define MOD 998244353
using namespace std;
int gcd(int x,int y){
if(!y) return x;
return gcd(y,x%y);
}
ll proceed(){
ll r,c;
cin >> r >> c;
char ch[r][c];
ll i,j;
for(i=0;i<r;++i){
for(j=0;j<c;++j) cin >> ch[i][j];
}
ll cnt=0,ans=0;
for(i=0;i<r;++i){
for(j=0;j<c;++j){
if(ch[i][j]=='.') ++cnt;
else{
ans+=max(cnt-1,(ll)0);
cnt=0;
}
}
ans+=max(cnt-1,(ll)0);
cnt=0;
}
//cout << ans << endl;
cnt=0;
for(i=0;i<c;++i){
for(j=0;j<r;++j){
if(ch[j][i]=='.') ++cnt;
else{
ans+=max(cnt-1,(ll)0);
cnt=0;
}
}
ans+=max(cnt-1,(ll)0);
cnt=0;
}
cout << ans << endl;
return 0;
}
//** Main **//
int main(){
//boost_;
int t=1,i=0;
//cin >> t;
while(t--){
proceed();
}
return 0;
} | #include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <numeric>
#include <bitset>
#include <math.h>
#include <iomanip>
#include <sstream>
#include <cstdlib>
#include <stdio.h>
using namespace std;
typedef long long ll;
//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#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--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
#define PI 3.14159265359 //πの値
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define C(x) cout << x << endl //テスト出力
//DP処理用
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; }
//関数
//nCkの計算の関数(呼び出しは[cbn])
ll cbn(ll n, ll k) {
ll r = 1;
for (ll d = 1; d <= k; ++d) {
r *= n--;
r /= d;
}
return r;
}
// a^n mod を計算する
ll powmod(ll a, ll n) {
ll res = 1;
while (n > 0) {
if (n & 1) res = res * a % MOD;
a = a * a % MOD;
n >>= 1;
}
return res;
}
//2つの最大公約数
int gcb(int a, int b){
if(a < b){
int x = a;
a = b;
b = x;
}
int amari = a % b;
if(amari == 0) return b;
return gcb(b, amari);
}
//3つの最大公約数
int gcb_3(int a, int b, int c){
return gcb(gcb(a, b), c);
}
/*map<Keyの型, Valueの型> 変数名;
queue<型> 変数名;
priority_queue<型> 変数名;
priority_queue<型, vector<型>, greater<型>> 変数名;
vector<vector<要素の型>> 変数名(要素数1, vector<要素の型>(要素数2, 初期値))
sort(変数名.begin(), 変数名.end());*/
/*-----------------------------ここから-----------------------------*/
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll h,w; cin>>h>>w;
vector<vector<char>> data(h,vector<char>(w));
REP(i,h) REP(j,w) cin>>data[i][j];
ll ans = 0;
REP(i,h-1){
REP(j,w){
if(data[i][j]=='.'&&data[i+1][j]=='.') ans++;
}
}
REP(i,h){
REP(j,w-1){
if(data[i][j]=='.'&&data[i][j+1]=='.') ans++;
}
}
cout<<ans;
} |
#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;
signed main()
{
int n,m;
cin>>n>>m;m*=100;
int tot=0;
rep(i,n){
int a,b;
cin>>a>>b;
tot+=a*b;
if (tot>m) re cout<<i+1,0;
}
cout<<-1;
re 0;
}
| #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 4000000000000000000 //オーバーフローに注意
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;
ll mod_pow(ll x,ll count, ll mod){
if(count == 0)return 1;
ll ret = mod_pow((x*x)%mod,count/2,mod);
if(count%2 == 1){
ret = (ret*x)%mod;
}
return ret;
}
int main(){
ll N,M;
scanf("%lld %lld",&N,&M);
ll tmp = mod_pow(10,N,M*M);
printf("%lld\n",(tmp/M)%M);
return 0;
}
|
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <cstdint>
#include <numeric>
#define INF 1000000000
#define LLINF 2000000000000000
#define MOD 1000000007
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
#define int long long
signed main(){
int n;
cin >> n;
double e[n+2];
e[0] = 1;
double ans = 0;
LOOP1(i,n-1){
//n面の中から n-i を選ぶ回数の期待値
double p = (double)(n-i)/n;
e[i] = 1/(p);
ans += e[i];
//cerr << e[i] << endl;
}
printf("%.12f\n", ans);
}
| #include <iostream>
using namespace std;
int main(void)
{
long long n;
cin >> n;
const int x[] = { 2,3,4,5,7,8,9,11,13,16,17,19,23,25,27,29,31};
const int e[] = { 2,3,2,5,7,2,3,11,13,2,17,19,23,5,3,29,31};
long long ans = 1;
for (int i = 0; x[i] <= n; i++) {
ans *= e[i];
}
cout << ans+1 << endl;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define FOR(a, b, c) for(int a = b; a <= c; ++a)
#define FORW(a,b,c) for(int a = b; a >= c; --a)
#define pb push_back
#define int long long
#define SZ(a) (int)(a.size())
#define mtp make_tuple
const int MOD = 998244353;
const int oo = 1e9;
const int mod = 1e9 + 7;
const int N = 2e5 + 100;
const int M = 7776;
typedef pair<double, double> ii;
typedef pair<char, pair<int, int> > iii;
int n;
int pr[N], a[N], color[N];
unordered_map<int, int> ump[N];
int find(int u) { return (u == pr[u]) ? u : (pr[u] = find(pr[u])); }
signed main()
{
// freopen("test.inp", "r", stdin);
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
FOR(i, 1, n) {
cin >> a[i];
color[a[i]] = i;
ump[i][a[i]] = 1;
pr[i] = i;
}
FOR(i, 1, n) {
int u = find(i);
int v = find(color[a[i]]);
if(u != v) {
if(ump[u].size() > ump[v].size())
swap(u, v);
for(auto &it: ump[u]) {
ump[v][it.fi] = 1;
}
ump[u].clear();
pr[u] = v;
}
}
FOR(i, 1, n / 2) {
int u = find(i);
int v = find(n - i + 1);
if(u != v) {
if(ump[u].size() > ump[v].size())
swap(u, v);
for(auto &it: ump[u]) {
ump[v][it.fi] = 1;
}
ump[u].clear();
pr[u] = v;
}
}
int res = 0;
FOR(i, 1, n) if(find(i) == i) {
res += (ump[i].size() - 1);
}
cout << res;
} | #include <bits/stdc++.h>
using namespace std;
int N;
string s;
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin >> N >> s;
string t;
for(int i = 0; i < N; i++)
{
t += s[i];
while(t.size() > 2 && t[t.size() - 1] == 'x' && t[t.size() - 2] == 'o' && t[t.size() - 3] == 'f')
{
t.pop_back();
t.pop_back();
t.pop_back();
}
}
cout << t.size();
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define ppb pop_back
#define mp make_pair
using pi = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vector<int> >;
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define sz(x) (int)(x).size()
//const int inf = 9e18;
const int NUM=1000030;
const int N = 10000000;
vector<int> lp, sieve;
vector<int> pr;
void primefactor();
int binpow(int a, int b);
int binpow(int a, int b, int mod);
int gcd(int a, int b);
int lcm (int a, int b);
bool comp(int a, int b);
int inversemod(int a, int mod);
void calc_sieve();
int mod1=1e9+7;
void test()
{
int n;
cin>>n;
vi arr(n+1);
for(int i=1;i<=n;i++) cin>>arr[i];
vvi modtaken(n+1, vi(n+1));
int sum=0;
for(int i=1;i<=n;i++)
{
sum+=arr[i];
for(int j=1;j<=n;j++) modtaken[j][i]=sum%j;
}
// for(int i=1;i<=n;i++)
// {
// for(int j=1;j<=n;j++) cerr<<modtaken[i][j]<<" ";
// cerr<<endl;
// }
// cerr<<endl;
vvi leftelement(n+1, vi(n+1, -1));
for(int i=1;i<=n;i++)
{
map<int, int> ele;
ele.clear();
for(int j=1;j<=n;j++)
{
if(ele.count(modtaken[i][j])) leftelement[i][j]=ele[modtaken[i][j]];
ele[modtaken[i][j]]=j;
}
}
vvi dp(n+1, vi(n+1, 0));
for(int j=1;j<=n;j++) dp[1][j]=1;
for(int i=2;i<=n;i++)
{
for(int j=2;j<=n;j++)
{
if(leftelement[i][j]==-1) continue;
dp[i][j]+=dp[i-1][leftelement[i][j]];
dp[i][j]%=mod1;
dp[i][j]+=dp[i][leftelement[i][j]];
dp[i][j]%=mod1;
}
}
// for(int i=1;i<=n;i++)
// {
// for(int j=1;j<=n;j++) cerr<<dp[i][j]<<" ";
// cerr<<endl;
// }
// cerr<<endl;
// for(int i=1;i<=n;i++)
// {
// for(int j=1;j<=n;j++) cerr<<leftelement[i][j]<<" ";
// cerr<<endl;
// }
// cerr<<endl;
int ans=0;
for(int i=1;i<=n;i++)
{
ans+=dp[i][n];
ans%=mod1;
}
cout<<ans<<endl;
}
signed main()
{
// freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
ios_base::sync_with_stdio(false);
cin.tie(0);
int t=1;
// cin>>t;
while(t--) test();
return 0;
}
// 1. Take care of the corner cases, write one or two tests that seem to be the cases.
// 2. Check the bounds on the intput and decide the algorithm.
// 3. Make the test cases for the bounds, try to include 0, 1, 2 cases in the new test cases, and if possible, scale the cases.
// 4. Check for overflow and the array bounds carefully, always take care of the decreasing loop.
void calc_sieve() //credits: Anish_Sofat
{
sieve.resize(NUM+1,0);
for (int x = 2; x <= NUM; x++)
{
if (sieve[x]) continue;
for (int u = x; u <= NUM; u += x)
{
sieve[u] = x ;
}
}
}
void primefactor()
{
lp.resize(N+1,0);
for (int i=2; i<=N; ++i) {
if (lp[i] == 0) {
lp[i] = i;
pr.push_back (i);
}
for (int j=0; j<(int)pr.size() && pr[j]<=lp[i] && i*pr[j]<=N; ++j)
lp[i * pr[j]] = pr[j];
}
}
int binpow(int a, int b)
{
int res = 1;
while (b > 0) {
if (b & 1)
res = res * a;
a = a * a;
b >>= 1;
}
return res;
}
int binpow(int a, int b, int mod)
{
int res = 1;
while (b > 0) {
if (b & 1)
res = (res * a)%mod;
a = (a * a)%mod;
b >>= 1;
}
return res%mod;
}
int gcd(int a, int b)
{
if(b==0) return a;
else return gcd(b,a%b);
}
int lcm (int a, int b)
{
return ((a / gcd(a, b)) * b);
}
bool comp(int a, int b)
{
return a>b;
}
int inversemod(int a, int mod)
{
return binpow(a,mod-2, mod);
}
| #include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, l, r) for (int i = l; i <= r; ++i)
const int N = 5e3 + 5;
const int P = 1e9 + 7;
int n, ans, a[N], sum[N], f[N][N], g[N][N];
signed main () {
cin >> n;
rep(i, 1, n) cin >> a[i], sum[i] = sum[i - 1] + a[i];
f[0][0] = g[0][0] = 1;
rep(i, 1, n) {
rep(j, 1, i) f[i][j] = g[sum[i] % j][j - 1];
rep(j, 1, i) g[sum[i] % (j + 1)][j] = (g[sum[i] % (j + 1)][j] + f[i][j]) % P;
}
rep(i, 1, n) ans = (ans + f[n][i]) % P;
cout << ans;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(ll i=a;(i)<(b);++(i))
#define RFOR(i,a,b) for(ll i=a;(i)>=(b);--(i))
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,n,0)
#define ALL(v) v.begin(), v.end()
#define UNIQ(v) sort(ALL(v)); v.erase(unique(ALL(v)), v.end())
#define BIT(n) (1LL<<(n))
#define DEBUG(a) cerr << #a << " = " << a << endl
const double PI = acos(-1);
const int inf = 1001001001;
const ll mod = 998244353;
//const ll inf = 1e15;
//const ll mod = 1e9+7;
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
int H, W, K;
vector<vector<char>> area(5001, vector<char>(5001, 'n'));
ll dp[5001][5001] = {};
//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;
}
//mod が素数
//a^(-1) mod
long long modinv(long long a, long long mod) {
return modpow(a, mod - 2, mod);
}
int main() {
cin >> H >> W >> K;
int i_h, i_w;
char i_a;
REP(i, K) {
cin >> i_h >> i_w >> i_a;
area[i_h-1][i_w-1] = i_a;
}
dp[0][0] = 1;
REP(i, H*W-K) dp[0][0] = (dp[0][0] * 3) % mod;
ll inv3 = modinv(3, mod);
REP(i, H) {
REP(j, W) {
dp[i][j] %= mod;
if (area[i][j] == 'X') {
dp[i+1][j] += dp[i][j];
dp[i][j+1] += dp[i][j];
} else if (area[i][j] == 'R') {
dp[i][j+1] += dp[i][j];
} else if (area[i][j] == 'D') {
dp[i+1][j] += dp[i][j];
} else {
dp[i+1][j] += (2 * dp[i][j]) * inv3;
dp[i][j+1] += (2 * dp[i][j]) * inv3;
}
}
}
//REP(i, H) {
// REP(j, W) {
// cout << setw(10) << dp[i][j];
// }
// cout << endl;
//}
cout << dp[H-1][W-1] << endl;
} | #include <bits/stdc++.h>
#include <variant>
#define rep2(i,k,n) for(i64 i=(i64)(k);i<(i64)(n);i++)
#define rep(i,n) rep2(i,0,n)
#define all(x) begin(x),end(x)
#ifdef ENV_LOCAL
#define dump if (1) cerr
#else
#define dump if (0) cerr
#endif
using namespace std;
using namespace std::string_literals;
using i32 = int32_t;
using i64 = int64_t;
using f64 = double;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
pair<i32,bool> solve(const vector<vi32>& g, i32 i) {
bool flip = true;
vector<pair<i32,bool>> children;
for (auto&& to : g[i]) {
auto [sc, fl] = solve(g, to);
if (fl) flip = !flip;
children.emplace_back(-sc, fl);
}
dump<<i<<endl;
sort(all(children), [](auto&& lhs, auto&& rhs) {
auto [ls, lf] = lhs;
auto [rs, rf] = rhs;
if (ls >= 0 && rs < 0) return true;
else if (ls < 0 && rs >= 0) return false;
if (ls >= 0) {
if (lf == rf) {
return ls > rs;
} else {
return rf;
}
} else {
if (lf == rf) {
return ls > rs;
} else {
return lf;
}
}
});
i32 score = 1;
bool current = false;
for (auto&& [sc, fl] : children) {
dump<<sc<<" "<<fl<<endl;
if (current) {
score += sc;
} else {
score -= sc;
}
if (fl) current = !current;
}
return make_pair(score, flip);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
i32 n;
cin>>n;
vector<vi32> g(n);
rep2(i,1,n) {
i32 p;
cin>>p;
--p;
g[p].push_back(i);
}
auto [score, flip] = solve(g, 0);
auto ans = (n + score) / 2;
cout<<ans<<endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define deb(x) cout<< #x << " " << x << "\n";
#define MAX 9223372036854775807
#define MIN -9223372036854775807
#define setbits(n) __builtin_popcountll(n)
#define mkunique(a) a.resize(unique(a.begin(),a.end())-a.begin());
void prints(set<ll> s) {for(ll u: s) cout<<u<<" "; cout<<"\n";}
void printms(multiset<ll> s) {for(ll u: s) cout<<u<<" "; cout<<"\n";}
void printv(vector<ll> s) {for(ll u: s) cout<<u<<" "; cout<<"\n";}
const ll mod=1e9+7;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll T=clock();
ll n,m;
cin>>n>>m;
vector<ll> a(n), b(m);
for(ll i=0;i<n;i++)
cin>>a[i];
for(ll i=0;i<m;i++)
cin>>b[i];
vector<ll> ans;
for(ll i=0;i<n;i++){
ll val=a[i];
bool ok=true;
for(ll u: b){
if(u==val){
ok=false;
break;
}
}
if(ok) ans.pb(val);
}
for(ll i=0;i<m;i++){
ll val=b[i];
bool ok=true;
for(ll u: a){
if(u==val){
ok=false;
break;
}
}
if(ok) ans.pb(val);
}
sort(ans.begin(),ans.end());
for(ll u: ans)
cout<<u<<" ";
cerr<<"\n\nTIME: "<<(long double)(clock()-T)/CLOCKS_PER_SEC<<" sec\n";
T = clock();
return 0;
} |
// Author: Muhesh Kumar
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pl = pair<ll, ll>;
using vl = vector<ll>;
using vvl = vector<vl>;
#define nl '\n'
#define fr first
#define sc second
#define pb push_back
#define bg(x) begin(x)
#define all(x) bg(x), end(x)
#define sz(x) (int) (x).size()
#define trav(a, b) for(auto &a: b)
#define rep(i, a, b) for(int i = a; i < b; i++)
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m; cin >> n >> m;
vector<int> a(n), b(m);
unordered_map<int, int> occ1, occ2;
trav(i, a) {
cin >> i;
occ1[i]++;
}
trav(i, b) {
cin >> i;
occ2[i]++;
}
vector<int> res;
trav(i, a) {
if (!occ2.count(i)) res.pb(i);
}
trav(i, b) {
if (!occ1.count(i)) res.pb(i);
}
sort(all(res));
trav(i, res) cout << i << " ";
return 0;
} |
#include<bits/stdc++.h>
#define forb(i,a,b) for(ll i=a;i<b;i++)
#define fore(i,a,b) for(ll i=a;i<=b;i++)
#define sortb(a) sort(a.begin(),a.end())
#define sortr(a) sort(a.begin(),a.end(),greater<ll> ())
#define inf LLONG_MAX
typedef long long int ll;
typedef long double ld;
using namespace std;
void solve(){
ll n,a,x;
cin>>n>>a;
x=n;
ll ct=0;
while(x>0){
ct+=(x%10);
x/=10;
}
if(ct<=a){
cout<<0<<endl;
}
else{
ll i=0,ans=0;
bool y=true;
while(ct>a and y){
if((ct-(n%10))>a){
ans+=((10-(n%10))*pow(10,i));
ct-=(n%10);
n/=10;
i++;
}
else{
y=false;
}
}
cout<<ans<<endl;
}
}
int main(){
ll a,b;
string s;
cin>>a>>b>>s;
forb(i,0,a){
if(s[i]=='o'){
b++;
}
if(s[i]=='x' and b){
b--;
}
}
cout<<b<<endl;
} |
#include"bits/stdc++.h"
#define rep(i,n) for(ll i=0;i<n;++i)
#define ALL(x) x.begin(),x.end()
#define BACK(x) x.rbegin(),x.rend()
#define MOD 1000000007
#define INF INT_MAX
#define FLOAT_ANS setprecision(30)
#define TORAD(x) (x*acos(-1)/180.0)
#define TODEG(x) (x*180/acos(-1))
#define elif else if
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template<typename T>
bool chmin(T& a,T b){
if(a>b){
a=b;
return true;
}
return false;
}
template<typename T>
bool chmax(T& a,T b){
if(a<b){
a=b;
return true;
}
return false;
}
ll modpow(ll a, ll n, ll mod) {
ll res = 1;
while (n > 0) {
if (n & 1) res = (res * (a%mod)) % mod;
a = ((a%mod) * (a%mod)) % mod;
n >>= 1;
}
return res;
}
// MAIN PROGRAM -------------
int main(){
ll n,p;
cin>>n>>p;
--p;
ll ans=modpow(p-1,n-1,MOD);
cout<<(ans*p)%MOD;
}
/*
*/ |
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
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 main(){
int n;
cin >> n;
int m = (1<<n);
vector<string> res;
rep(bits,1<<n){
if(bits==0)continue;
vector<bool> flag(m);
rep(i,m){
int c = 0;
rep(j,n){
if((bits>>j)&1){
if((i>>j)&1)c++;
}
}
if(c%2==1)flag[i] = 1;
}
string s;
rep(i,m){
if(flag[i]){
s.push_back('A');
}else{
s.push_back('B');
}
}
res.push_back(s);
}
cout << res.size() << "\n";
for(auto x:res){
cout << x << "\n";
}
return 0;
} | #include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define pf push_front
#define ff first
#define ss second
#define pi acos(-1.0)
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
#define endl "\n"
//#define inf 1<<30
// isupper() -> upper case check
// tolower() -> convert upper to lower case
// idx = str.find("bear", pos)) != string::npos =>substring find
// Tuple access -> get<0>(v[i])
// cmnt - ctrl []
// stoi("...") -> decimel
// istringstream ss(str) while(ss >> n)
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using tpl = tuple<int, int, int>;
using pcc = pair<char, char>;
const ll inf = 2e18+100;
const ll mod = 1e9+7;
int dr[] = {-1, 0, 1, 0};// up, right, down, left
int dc[] = { 0, 1, 0, -1};
// King moves similar to 8 direction
//int dr[] = {-1, -1, 0, 1, 1, 1, 0, -1};
//int dc[] = { 0, 1, 1, 1, 0, -1,-1, -1};
// Knight moves
int kr[] = {-1, 1, -2, -2, -1, 1, 2, 2};
int kc[] = {-2, -2, -1, 1, 2, 2, -1, 1};
// diagonal moves
int dgr[] = {-1, -1, 1, 1};
int dgc[] = { 1, -1, -1, 1};
void solve()
{
ll x;
cin >> x;
if(x <= 10) cout << 0 << endl;
else {
ll ans = 0;
ll val = 9, pwr = 1;
for(ll i = 99; ; ){
ans += (val*pwr);
pwr *= 10;
//cout << i << endl;
if(i == x) {
//cout << "as\n";
cout << ans << endl;
return;
}
if(i > x) {
string now = to_string(x);
ll mn_pwr = 1;
//cout << ans << endl;
int siz = now.size();
if(siz%2) {
string a, b;
b = now.substr(0, (siz/2)+1);
for(int l=(siz/2)+1; l >= 1; l--) {
if(l == 1) a += "1";
else a += "0";
}
reverse(all(a));
ll tmp1 = stoll(b);
ll tmp2 = stoll(a);
//cout << tmp1 << " " << tmp2 << endl;
//cout << ans << endl;
ans -= (tmp1-tmp2);
//cout << ans << endl;
//return;
}
for(int j = (siz/2)-(!(siz%2)); j >= 0; j--) {
ll dig = now[j]-'0';
dig = 9 - dig;
ans -= (dig*mn_pwr);
mn_pwr *= 10;
//cout << ans << endl;
}
int ck = 0;
/*
for(int l = 0, r = siz-1;! l < r; l++, r--) {
if(now[l] != now[r]) {
ck = 1;
break;
}
}*/
if(siz%2 or now.substr(0, siz/2) > now.substr(siz/2)) ans--;
cout << ans << endl;
return;
}
i *= 100;
i += 99;
}
}
}
int main()
{
fast_io;
int tt = 1;
//cin >> tt;
while(tt--) {
solve();
}
return 0;
}
|
#ifdef LOCAL
cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
#endif
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define vll vector<ll>
#define pii pair<ll,ll>
#define un_mp unordered_map<char,ll>
#define endl "\n"
#define pb push_back
#define all(a) a.begin(),a.end()
void solve(){
ll a,b,n,tt,d,m,k;
cin>>n;
a=n;
n/=100;
cout<<(n+1)*100-a<<endl;
return;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
ll a,b,c,n,tt,d,m,k,x,y;
tt=1;
//cin>>tt;
while(tt--){
solve();
}
} | //always use
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i=0; i<n; i++)
#define mp make_pair
#define pb push_back
#define f first
#define s second
typedef long long ll;
#define MOD 998244353
//2 147 483 647 (2^31-1) int max
//9 223 372 036 854 775 807 (2^63-1) ll max
//codeforces and USACO
void fast_io(){
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);}
//USACO
void file_io(string taskname){
string fin = taskname + ".in";
string fout = taskname + ".out";
const char* FIN = fin.c_str();
const char* FOUT = fout.c_str();
freopen(FIN, "r", stdin);
freopen(FOUT, "w", stdout);
fast_io();}
//Printing pairs and vectors
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.f << ", " << p.s << ")"; }
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) {
cout << "["; for(int i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]";}
//main code
int main(){
fast_io();
ll n;
cin >> n;
ll l=1,r=n+1; //l is <= answer, r > answer
while(l+1<r){
ll m=(l+r)/2;
if (m > 1414213569LL || m*m>(2*(n+1)-m)){
r=m;
}
else{
l=m;
}
}
//cout << l << "\n";
cout << n-l+1;
}
|
#include <iostream>
#include <cmath>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
using ll = long long;
int in(){
double x;
cin >> x;
x*=10000;
return round(x);
}
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){
int l=0,r=1;
ll res = 0;
for(int i=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(),y=in(),z=in();
x%=10000;
y%=10000;
ll ans = f(x,y,z,10000);
ans += f(x,-y,z,0);
cout << ans << endl;
return 0;
} | #include <cstdio>
#define DIV 10000LL
using namespace std;
typedef long long LL;
LL x, y, R;
inline LL read()
{
// Returns: input * 10000.
LL res = 0LL;
int num = 0;
bool flag = false, negative = false;
for(char c=getchar(); c != ' ' && c != '\n'; c=getchar())
{
if(c == '-') negative = true;
else if(c == '.') flag = true;
else
{
res *= 10LL;
res += c - '0';
if(flag) num ++;
}
}
for(int i=num; i<4; i++)
res *= 10LL;
return negative? -res: res;
}
inline LL in_circle(const LL& dx, const LL& dy)
{
return dx * dx + dy * dy <= R * R;
}
inline LL findtop(LL i)
{
i *= DIV;
LL l = y, r = y + R;
while(l < r)
{
LL mid = l + r + 1LL >> 1LL; // l<0?
if(in_circle(i - x, mid - y))
l = mid;
else r = mid - 1LL;
}
return l;
}
inline LL ceildiv(const LL& a)
{
// Returns: ceil(a / DIV).
if(a < 0LL) return a / DIV;
if(a % DIV == 0LL) return a / DIV;
return a / DIV + 1LL;
}
inline LL floordiv(const LL& a)
{
// Returns: floor(a / DIV).
if(a >= 0LL) return a / DIV;
if(a % DIV == 0LL) return a / DIV;
return a / DIV - 1LL;
}
int main()
{
x = read(), y = read(), R = read();
LL ans = 0LL, left = ceildiv(x - R), right = floordiv(x + R);
for(LL i=left; i<=right; i++)
{
LL top = findtop(i);
LL bottom = (y << 1LL) - top;
ans += floordiv(top) - ceildiv(bottom) + 1LL;
}
printf("%lld\n", ans);
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; }
class UnionFind{
public:
vector<ll> parent; //parent[i]はiの親
vector<ll> siz; //素集合のサイズを表す配列(1で初期化)
map<ll,vector<ll>> group; //集合ごとに管理する(key:集合の代表元、value:集合の要素の配列)
ll n; //要素数
//コンストラクタ
UnionFind(ll n_):n(n_),parent(n_),siz(n_,1){
//全ての要素の根が自身であるとして初期化
for(ll i=0;i<n;i++){parent[i]=i;}
}
//データxの属する木の根を取得(経路圧縮も行う)
ll root(ll x){
if(parent[x]==x) return x;
return parent[x]=root(parent[x]);//代入式の値は代入した変数の値なので、経路圧縮できる
}
//xとyの木を併合
void unite(ll x,ll y){
ll rx=root(x);//xの根
ll ry=root(y);//yの根
if(rx==ry) return;//同じ木にある時
//小さい集合を大きい集合へと併合(ry→rxへ併合)
if(siz[rx]<siz[ry]) swap(rx,ry);
siz[rx]+=siz[ry];
parent[ry]=rx;//xとyが同じ木にない時はyの根ryをxの根rxにつける
}
//xとyが属する木が同じかを判定
bool same(ll x,ll y){
ll rx=root(x);
ll ry=root(y);
return rx==ry;
}
//xの素集合のサイズを取得
ll size(ll x){
return siz[root(x)];
}
//素集合をそれぞれグループ化
void grouping(){
//経路圧縮を先に行う
rep(i,n)root(i);
//mapで管理する(デフォルト構築を利用)
rep(i,n)group[parent[i]].push_back(i);
}
//素集合系を削除して初期化
void clear(){
rep(i,n){parent[i]=i;}
siz=vector<ll>(n,1);
group.clear();
}
};
int main() {
ll N; cin>>N;
vector<ll> A(N), B(N);
rep(i, N){
cin>>A[i];
B[i] = A[i];
}
reverse(B.begin(), B.end());
ll res = 0;
UnionFind uf(2e5+1);
rep(i, N){
if(!uf.same(A[i], B[i])){
res++;
uf.unite(A[i], B[i]);
}
}
cout << res << endl;
} | #include <bits/stdc++.h>
using namespace std;
struct UnionFind {
vector<int> par, size;
UnionFind(int n) : par(n), size(n) {
for(int i = 0; i < n; i++) {
par[i] = i;
size[i] = 1;
}
}
int root(int x) {
return par[x] == x ? x : par[x] = root(par[x]);
}
bool unite(int x, int y) {
int rx = root(x);
int ry = root(y);
if(rx == ry) return false;
if(size[rx] > size[ry]) {
par[ry] = rx;
size[rx] += size[ry];
} else {
par[rx] = ry;
size[ry] += size[rx];
}
return true;
}
bool same(int x, int y) {
return root(x) == root(y);
}
int tree_size(int x) {
return size[root(x)];
}
};
void milkshake() {
int n, m = 0;
cin >> n;
vector<int> a(n);
for(auto &x : a) {
cin >> x;
m = max(m, x);
x--;
}
UnionFind tree(m);
for(int i = 0; i < n/2; i++) {
tree.unite(a[i], a[n - 1 - i]);
}
int ans = 0;
for(int i = 0; i < m; i++) {
if(tree.par[i] == i)
ans += tree.tree_size(i) - 1;
}
cout << ans << '\n';
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int tt=1;
while(tt--) milkshake();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define D(a) cerr << #a << " = " << a << endl
#else
#define D(a) 8
#endif
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
#define dforsn(i,s,n) for(int i=int(n-1);i>=int(s);i--)
#define forsn(i,s,n) for(int i=int(s);i<int(n);i++)
#define all(a) (a).begin(),(a).end()
#define dforn(i,n) dforsn(i,0,n)
#define forn(i,n) forsn(i,0,n)
#define si(a) int((a).size())
#define pb emplace_back
#define mp make_pair
#define snd second
#define fst first
#define endl '\n'
using pii = pair<int,int>;
using vi = vector<int>;
using ll = long long;
int main() {
fastio;
int v, t, s, d; cin >> v >> t >> s >> d;
cout << (v*t > d || d > v*s ? "Yes" : "No") << endl;
return 0;
}
| #include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
#define double long double
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
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; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define PRINT(a) printf("%.15Lf\n",a);
#define YESNO(a) cout << (a ? "YES" : "NO") << endl
#define YesNo(a) cout << (a ? "Yes" : "No") << endl
#define yesno(a) cout << (a ? "yes" : "no") << endl
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
#define eps 1e-12
//priority_queue<int,vector<int>, greater<int> > q2;
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
int A, B, C; cin >> A >> B >> C;
cout <<21- (A + B + C )<< endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string s; cin >> s;
int tmp = 8;
map<char,int> sub;
for(int i = 0; i < (int) s.size(); i++) sub[s.at(i)]++;
vector<string> oct(0);
int count = 1;
bool result = false;
if(s.size() == 1) {
if(s == "8") result = true;
} else if((int) s.size() == 2) {
count = 2;
while(tmp * count < 100) {
oct.push_back(to_string(tmp * count));
count++;
}
for(int i = 0; i < (int) oct.size(); i++) {
bool isOk = true;
map<char,int> tar = sub;
for(int j = 0; j < (int) oct.at(i).size(); j++) {
bool ari = false;
if(tar[oct.at(i).at(j)] > 0) {
ari = true;
tar[oct.at(i).at(j)]--;
}
if(ari) continue;
else {
isOk = false;
break;
}
}
if(isOk) {
result = true;
break;
}
}
} else {
count = 13;
while(tmp * count < 1000) {
oct.push_back(to_string(tmp * count));
count++;
}
for(int i = 0; i < (int) oct.size(); i++) {
bool isOk = true;
map<char,int> tar = sub;
for(int j = 0; j < (int) oct.at(i).size(); j++) {
bool ari = false;
if(tar[oct.at(i).at(j)] > 0) {
ari = true;
tar[oct.at(i).at(j)]--;
}
if(ari) continue;
else {
isOk = false;
break;
}
}
if(isOk) {
result = true;
break;
}
}
}
if(result) cout << "Yes" << endl;
else cout << "No" << endl;
return 0;
} | //Shinchan Loves Coding :))
#include<bits/stdc++.h>
using namespace std;
#define night_rider ios::sync_with_stdio(false);cin.tie(NULL);
#define double long double
#define int long long int
#define en "\n"
#define fi first
#define se second
#define PB push_back
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define rep(i,x,y) for(int i=x ; i<y ; i++)
#define erep(i,x,y) for(int i=x ; i<=y ; i++)
#define erepr(i,x,y) for(int i=x ; i>=y ; i--)
#define repr(i,x,y) for(int i=x ; i>y ; i--)
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef pair<int,int> pi;
typedef vector<pair<int,int>> pii;
//--------------------------------------------------------------------------------------------------------------------------------------------------------------
const int no=3e6+5,modulo=1e9+7,inf=1e18,N=2e3+1;
const double PI = 3.1415926535897932384;
int ar[no] ,br[no],cr[no];//,dr[no],er[no];
//int used[no];
//int color[no];
//pii adj[no];
//vi adj[no] ;
//LOWER_BOUND(n) - FIRST ELEMENT GREATER THAN EQUAL TO n
//UPPER_BOUND(n) - FIRST ELEMENT GREATER THAN n
//--------------------------------------------------------------------------------------------------------------------------------------------------------------
map<char,int> fir,sec;
int make(string s) {
string ans="";
for(auto &ii : s) {
ans+=(char)(sec[ii]+'0');
}
int x=0,k=ans.size();
reverse(all(ans));
rep(i,0,k) {
x+=pow(10,i)*(ans[i]-'0');
}
return x;
}
void solve () {
int n=0,m=0,a=0,b=0,c=0,d=0,x=0,y=0,z=0,w=0,k=0;
vector<string> v(3);
rep(i,0,3) {
cin>>v[i];
rep(j,0,v[i].size()) {
if(!j) fir[v[i][j]]++;
sec[v[i][j]]++;
}
}
if(sec.size()>=11) {
cout<<"UNSOLVABLE";
return ;
}
rep(i,0,10) {
ar[i]=i;
}
do {
a=0;
for(auto ii : sec) {
sec[ii.fi]=ar[a];
a++;
}
bool ok=0;
for(auto ii : fir) {
if(sec[ii.fi]==0) {ok=1;}
}
if(!ok) {
x=make(v[0]);
y=make(v[1]);
z=make(v[2]);
// cout<<x<<" "<<y<<" "<<z<<en;
if(x+y==z) {
cout<<x<<"\n"<<y<<"\n"<<z<<en;
return ;
}
}
} while(next_permutation(ar,ar+10));
cout<<"UNSOLVABLE";
}
inline void runn() {
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
}
signed main() {
night_rider
runn();
int t=1;
cout<<fixed<<setprecision(15);
// cin>>t;
rep(i,1,t+1) {
// cout << "Case #" << i << ": ";
solve();
}
}
|
#include <bits/stdc++.h>
using namespace std;
void prime_factor(int n, vector<bool> &p)
{
for (int i = 2; i * i <= n; i++)
{
while(n % i == 0)
{
p[i] = true;
n /= i;
}
}
if(n != 1)p[n] = true;
return;
}
int GCD(long long x, long long y) {
if(x < y) swap(x, y); //この式はなくても良い。
while (y > 0) {
int r = x % y;
x = y;
y = r;
}
return x;
}
int main()
{
int n;
cin >> n;
vector<int> x(n);
for (int i = 0; i < n; i++)
{
cin >> x[i];
}
int prime_num[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};
long long ans = INFINITY;
for (int i = 0; i < (1 << 15); i++)
{
bitset<15> s(i);
long long Y = 1;
for (int j = 0; j < 15; j++)
{
if(s[j] == 1)Y *= (prime_num[j]);
}
bool bf = false;
for (int i = 0; i < n; i++)
{
if(GCD(Y, x[i]) == 1)
{
bf = true;
break;
}
}
if(!bf)
{
ans = min(ans, Y);
}
}
cout << ans << endl;
} | #define MOD_TYPE 1
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
#if 0
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
using Int = boost::multiprecision::cpp_int;
using lld = boost::multiprecision::cpp_dec_float_100;
#endif
#if 1
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#endif
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;
constexpr ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
//constexpr ll MOD = 1;
constexpr int INF = (int)1e9 + 10;
constexpr ll LINF = (ll)4e18;
constexpr double PI = acos(-1.0);
constexpr double EPS = 1e-9;
constexpr int Dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
constexpr int Dy[] = {1, -1, 0, 0, -1, -1, 1, 1, 0};
#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define REPI(i, m, n) for (int i = m; i < (int)(n); ++i)
#define repi(i, n) REPI(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";
struct io_init
{
io_init()
{
cin.tie(0);
ios::sync_with_stdio(false);
cout << setprecision(30) << setiosflags(ios::fixed);
};
} io_init;
template <typename T>
inline bool chmin(T &a, T b)
{
if (a > b)
{
a = b;
return true;
}
return false;
}
template <typename T>
inline bool chmax(T &a, T b)
{
if (a < b)
{
a = b;
return true;
}
return false;
}
inline ll CEIL(ll a, ll b)
{
return (a + b - 1) / b;
}
template <typename A, size_t N, typename T>
inline void Fill(A (&array)[N], const T &val)
{
fill((T *)array, (T *)(array + N), val);
}
template <typename T, typename U>
constexpr istream &operator>>(istream &is, pair<T, U> &p) noexcept
{
is >> p.first >> p.second;
return is;
}
template <typename T, typename U>
constexpr ostream &operator<<(ostream &os, pair<T, U> &p) noexcept
{
os << p.first << " " << p.second;
return os;
}
#pragma endregion
void solve()
{
int n;
cin >> n;
vector<ll> a(n);
rep(i, n) cin >> a[i];
set<ll> st;
rep(i, n) st.insert(a[i]);
while (st.size() >= 2)
{
ll Max = *st.rbegin();
ll Min = *st.begin();
st.erase(Max);
ll k = CEIL(Max, Min) - 1;
st.insert(Max - k * Min);
}
cout << *st.begin() << "\n";
}
int main()
{
solve();
} |
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
#define ll uint64_t
#define ll1 long long
#define endl "\n"
#define PI acos(-1)
#define fi first
#define si second
#define mkp make_pair
#define pb push_back
#define set0(arr) memset(arr, 0, sizeof(arr))
#define setinf(arr) memset(arr, 126, sizeof(arr))
#define all(x) (x).begin(),(x).end()
#define sz(v) ((ll)(v).size())
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
using pll = pair<ll, ll> ;
using vl = vector<ll> ;
using vpll = vector<pll> ;
using mll = map<ll, ll> ;
using mcl = map<char, ll> ;
using msl = map<string,ll> ;
using sl = set<ll> ;
using sc = set<char> ;
using dl = deque<ll> ;
const int N = 1e6+5 ;
ll mod = 1e9+7 ;
vl adj[N] ;
vpll adjc[N] ;
ll vis[N] ;
ll arr[N] ;
ll sumd(ll a,ll b){return (((a%mod)+(b%mod))%mod);}
ll muld(ll a,ll b){return (((a%mod)*(b%mod))%mod);}
ll subd(ll a,ll b){return (((a%mod)-(b%mod)+mod)%mod);}
bool chk(ll ii,ll jj,ll nn,ll mm){if(ii<0||jj<0||ii>=nn||jj>=mm) return false;else return true;}
int main()
{
IOS;
ll a, b, c, d, n, m, p, x, y, z, i, j, k, f = 0, tc, cnt = 0, sum = 0, mul = 1, mi = 1e18, ma = -1e18, cs;
string str ;
char ch ;
double db ;
ll l, r ;
//code
cin>>n;
ll a1[n],b1[n];
for(i=0;i<n;i++)
{
cin>>a1[i];
}
for(i=0;i<n;i++)
{
cin>>b1[i];
}
ll ans=a1[0]*b1[0];
ma=a1[0];
cout<<a1[0]*b1[0]<<endl;
for(i=1;i<n;i++)
{
ma=max(ma,a1[i]);
ans=max(ans,ma*b1[i]);
cout<<ans<<endl;
}
//code
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
#define ALL(x) begin(x),end(x)
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define mod 1000000007
using ll=long long;
const int INF=1000000000;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}
struct IOSetup{
IOSetup(){
cin.tie(0);
ios::sync_with_stdio(0);
cout<<fixed<<setprecision(12);
}
} iosetup;
template<typename T>
ostream &operator<<(ostream &os,const vector<T>&v){
for(int i=0;i<(int)v.size();i++) os<<v[i]<<(i+1==(int)v.size()?"":" ");
return os;
}
template<typename T>
istream &operator>>(istream &is,vector<T>&v){
for(T &x:v)is>>x;
return is;
}
signed main(){
string s;cin>>s;
bool f=true;
for(int i=0;i<(int)s.size();i+=2)if(!('a'<=s[i] and s[i]<='z')) f=false;
for(int i=1;i<(int)s.size();i+=2)if(('a'<=s[i] and s[i]<='z')) f=false;
cout<<(f?"Yes":"No")<<endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long x, y, a, b;
cin >> x >> y >> a >> b;
long long ans = 0;
long long tmp = x;
while (1) {
if (tmp >= (y / a))break;
if (tmp * a >= (long long) 2e18)break;
if (tmp * (a - 1) > b)break;
ans++;
tmp *= a;
}
ans += (y - tmp -1) / b;
cout << ans << endl;
return 0;
} | #include <iostream>
#include <algorithm>
#include <cmath>
#include <tuple>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#define flush fflush(stdout)
#define endl '\n'
#define all(v) v.begin(), v.end()
#define pf(dans) printf("%.12lf", dans)
#define pfn(dans) pf(dans); cout << endl;
using namespace std;
//using namespace atcoder;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;
const int mod1 = (int)1e9 + 7, mod2 = (int)998244353;
const int INF = (int)1e9 + 10;
const ll LINF = (ll)1e18 + 10;
const int di[8] = {1, 0, -1, 0, 1, 1, -1, -1}, dj[8] = {0, 1, 0, -1, -1, 1, -1, 1};
#define rep0(i, n) for (i = 0; i < n; i++)
#define rep1(i, a, b) for (i = a; i < b; i++)
#define reprev(i, n) for (i = n - 1; i >= 0; i--)
template <typename T>
T my_abs(T x){
return (x >= 0)? x : -x;
}
template <typename T>
void chmax(T &a, T b){
a = max(a, b);
}
template <typename T>
void chmin(T &a, T b){
a = min(a, b);
}
ll gcd(ll a, ll b){
if (a > b) return gcd(b, a);
if (a == 0) return b;
return gcd(b % a, a);
}
bool incld_bit(ll bit, int i){
return ((bit>>i) & 1) == 1;
}
// --------------------------------------------------------------------------------
int main(void){
int i, j;
int a, b, c;
cin >> a >> b >> c;
cout << a + b + c - min({a, b, c}) << endl;
return 0;
} |
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cerr<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
int getInt(){int x;scanf("%d",&x);return x;}
template<typename T>istream& operator>>(istream&i,v(T)&v){rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v){stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,const v(T)&v){if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v){return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v){return o<<v.fi<<","<<v.se;}
template<typename T>bool mins(T& x,const T&y){if(x>y){x=y;return true;}else return false;}
template<typename T>bool maxs(T& x,const T&y){if(x<y){x=y;return true;}else return false;}
template<typename T>ll suma(const v(T)&a){ll res(0);for(auto&&x:a)res+=x;return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;
struct Solver {
void solve() {
int n;
scanf("%d",&n);
vi a(n), b(n);
cin>>a>>b;
int x = 0;
rep(i,n) x += a[i]*b[i];
if (x == 0) yn;
}
};
int main() {
int ts = 1;
// scanf("%d",&ts);
rrep(ti,ts) {
Solver solver;
solver.solve();
}
return 0;
}
| #include <iostream>
#include <vector>
using namespace std;
int main(void){
int n;
std::cin >> n;
int a[n] ;
int b[n] ;
for (int i = 0; i < n; i++) {
std::cin >> a[i];
}
for (int i = 0; i < n; i++) {
std::cin >> b[i];
}
int ans = 0;
for (int i = 0; i < n; i++) {
ans += a[i] * b[i];
}
string msg = ans == 0 ? "Yes" : "No";
std::cout << msg << std::endl;
}
|
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#define rep(i,n) for (int i=0;i<n;i++)
#define DENOM 1000000007
using namespace std;
using ll = long long;
char win_rps(char a, char b) {
if (a==b) {
return a ;
}
if ((a=='R' && b=='S') || (a=='S' && b=='R')) {
return 'R' ;
} else if ((a=='S' && b=='P') || (a=='P' && b=='S')) {
return 'S' ;
} else {
return 'P' ;
}
}
int main(){
int n, k ;
string prev_s, s;
size_t s_length;
cin >> n >> k ;
cin >> prev_s;
for (int i = 0 ; i< k ; ++i) {
prev_s += prev_s ;
s_length = prev_s.size() ;
if (s_length == 1) {
cout << prev_s[0] << endl ;
return 0 ;
}
s = "" ;
for (int j = 0 ; j < s_length ; j+=2) {
s += win_rps(prev_s[j], prev_s[j+1]) ;
}
prev_s = s ;
cerr << i << ": " << prev_s << endl ;
}
cout << prev_s[0] << endl ;
return 0 ;
}
| #pragma GCC optimize ("O2")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please
short A[501][501], B[501][501];
int D[1 << 18];
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int H, W;
cin >> H >> W;
rep(i, H) rep(j, W - 1) cin >> A[i][j];
rep(i, H - 1) rep(j, W) cin >> B[i][j];
rep(i, H) rep(j, W - 1) A[i][j] <<= 1;
rep(i, H - 1) rep(j, W) B[i][j] <<= 1;
priority_queue<ll, vector<ll>, greater<ll>> q;
D[0] = -2e9 + 1;
q.push((ll)D[0] << 32);
int owa = (H - 1) << 9 | W - 1;
while (q.size()) {
auto tmp = q.top();
q.pop();
int d0 = tmp >> 32;
int hwp = tmp & (1 << 20) - 1;
if (D[hwp] != d0) continue;
int h = hwp >> 9;
int w = hwp & 511;
int p = (d0 & 1) << 1 | 1;
d0 |= 1;
if (hwp == owa) break;
if (w > 0) if (D[hwp - 1] > d0 + A[h][w - 1]) {
D[hwp - 1] = d0 + A[h][w - 1];
q.push((ll)(d0 + A[h][w - 1]) << 32 | hwp - 1);
}
if (w < W - 1) if (D[hwp + 1] > d0 + A[h][w]) {
D[hwp + 1] = d0 + A[h][w];
q.push((ll)(d0 + A[h][w]) << 32 | hwp + 1);
}
if (h > 0) if (D[hwp - 512] > d0 + p) {
D[hwp - 512] = d0 + p;
q.push((ll)(d0 + p) << 32 | hwp - 512);
}
if (h < H - 1) if (D[hwp + 512] > d0 + B[h][w]) {
D[hwp + 512] = d0 + B[h][w];
q.push((ll)(d0 + B[h][w]) << 32 | hwp + 512);
}
}
co(D[owa] - D[0] >> 1);
Would you please return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int n, m, q, a, b, v[55], w[55], cnt, dp[55][55];
pair <int, int> p[55];
int main(){
cin >> n >> m >> q;
for(int i = 1; i <= n; i++) cin >> a >> b, p[i] = make_pair(a, b);
sort(p + 1, p + 1 + n);
for(int i = 1; i <= m; i++) cin >> v[i];
while(q--){
cin >> a >> b, cnt = 0;
for(int i = 1; i <= m; i++) if(i > b || i < a) w[++cnt] = v[i];
sort(w + 1, w + 1 + cnt);
for(int i = 1; i <= cnt; i++)
for(int j = 1; j <= n; j++){
if(p[j].first > w[i]){
dp[i][j] = dp[i][j - 1];
continue;
}
dp[i][j] = max(dp[i][j - 1], dp[i - 1][j - 1] + p[j].second);
}
cout << dp[cnt][n] << endl;
memset(dp, 0, sizeof(dp));
}
return 0;
}
| /**
* author: tomo0608
* created: 20.02.2021 21:39:59
**/
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
typedef pair<int,int> pii;
typedef pair<long long, long long> pll;
#define all(x) x.begin(),x.end()
#define rep2(i, m, n) for (int i = (m); i < (n); ++i)
#define rep(i, n) rep2(i, 0, n)
#define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i)
#define drep(i, n) drep2(i, n, 0)
#define unique(a) a.erase(unique(a.begin(),a.end()),a.end())
template<class T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T> >;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T1, class T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; }
template<class T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<typename T> ostream& operator << (ostream& os, set<T>& set_var) {os << "{"; for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {os << *itr;++itr;if(itr != set_var.end()) os << ", ";itr--;}os << "}";return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, map<T, U> &map_var) {os << "{";for(auto itr = map_var.begin(); itr != map_var.end(); itr++) {os << *itr;itr++;if (itr != map_var.end()) os << ", ";itr--;}os << "}";return os;}
template<class T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
#define pb push_back
#define eb emplace_back
#define elif else if
#define mp make_pair
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
template<typename T> T gcd(T x, T y){if(x%y == 0)return y;return gcd(y, x%y);}
template<typename T> T gcd(vector<T> a){T res = a[0];for(auto &x: a)res = gcd(res, x);return res;}
template <typename T>T mypow(T x, ll n){T ret = 1;while(n > 0){if(n & 1)(ret *= x);(x *= x);n >>= 1;}return ret;}
#define endl '\n'
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};
// Primality test
class Prime {
public:
const int N;
vector<int> min_prime;
vector<int> primes;
Prime(int size): N(size), min_prime(N+1){
rep(i,N+1)min_prime[i] = i;
min_prime[0] = -1;
min_prime[1] = -1;
for(int i = 2;i<=N;i++){
if(min_prime[i]!=i)continue;
primes.push_back(i);
int tmp = 2*i;
while(tmp <= N){
if(min_prime[tmp]==tmp)min_prime[tmp] = i;
tmp += i;
}
}
}
bool check(int x){ return min_prime[x] == x;}
};
void solve(){
ll n,x;cin >> n >> x;
V<ll> a(n);cin >> a;
ll ans = x - *max_element(all(a));
rep2(S,1, n+1){
VV<ll> dp(S+1, V<ll>(S, -1));
dp[0][0] = 0;
rep(i,n){
VV<ll> new_dp(S+1, V<ll>(S,-1));
rep(j,S+1)rep(k,S){
if(dp[j][k] != -1){
if(j < S)chmax(new_dp[j+1][(k + a[i])%S], dp[j][k] + a[i]);
chmax(new_dp[j][k], dp[j][k]);
}
}
dp = new_dp;
}
if(dp[S][x%S] != -1){
chmin(ans, (x - dp[S][x%S])/S);
}
}
cout << ans << endl;
}
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
cout << setprecision(20);
int codeforces = 1;
//cin >> codeforces;
while(codeforces--){
solve();
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
using LL=long long;
using ULL=unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)
int K;
LL dp[4][200001];
int main(){
cin>>K;
rep(t,4) rep(i,K+1) dp[t][i]=0;
dp[0][1]=1;
rep(t,3) for(int i=1; i<=K; i++)
for(int j=i; j<=K; j+=i) dp[t+1][j]+=dp[t][i];
LL ans=0;
rep(i,K+1) ans+=dp[3][i];
cout<<ans<<endl;
return 0;
}
| #include<bits/stdc++.h>
#define int long long
using namespace std;
int n;
set<int>s;
signed main(){
cin>>n;
for(int i=2;i*i<=n;i++){
if(s.count(i))continue;
int t=i*i;
while(t<=n)s.insert(t),t*=i;
}
cout<<n-s.size();
return 0;
} |
//Hare Krishna
//author: Dipjoy Basak
//dip_10
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
#define int ll
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define vi vector<int>
#define pi pair<int, int>
#define vpi vector<pair<int, int>>
#define rep(i, l, r) for (int i = l; i <= r; i++)
#define rrep(i, r, l) for (int i = r; i >= l; i--)
#define readarray(a, n) rep(i, 0, n - 1) cin >> a[i];
#define all(v) v.begin(), v.end()
#ifndef ONLINE_JUDGE
#define debug(x) \
cerr << #x << " "; \
_print(x); \
cerr << endl;
#else
#define debug(x) ;
#endif
#define INF INT_MAX
//*----------------------------------------DEBUG functions--------------------------*
void _print(int t) { cerr << t; }
void _print(string t) { cerr << t; }
void _print(char t) { cerr << t; }
void _print(ld t) { cerr << t; }
void _print(double t) { cerr << t; }
template <class T, class V>
void _print(pair<T, V> p);
template <class T>
void _print(vector<T> v);
template <class T>
void _print(set<T> v);
template <class T, class V>
void _print(map<T, V> v);
template <class T>
void _print(multiset<T> v);
template <class T, class V>
void _print(pair<T, V> p)
{
cerr << "{";
_print(p.ff);
cerr << ",";
_print(p.ss);
cerr << "}";
}
template <class T>
void _print(vector<T> v)
{
cerr << "[ ";
for (T i : v)
{
_print(i);
cerr << " ";
}
cerr << "]";
}
template <class T>
void _print(set<T> v)
{
cerr << "[ ";
for (T i : v)
{
_print(i);
cerr << " ";
}
cerr << "]";
}
template <class T>
void _print(multiset<T> v)
{
cerr << "[ ";
for (T i : v)
{
_print(i);
cerr << " ";
}
cerr << "]";
}
template <class T, class V>
void _print(map<T, V> v)
{
cerr << "[ ";
for (auto i : v)
{
_print(i);
cerr << " ";
}
cerr << "]";
}
//-----------------------------------------------------------------------------------------------------------------------------
const int mod = 1000000007;
const int maxn = 100005;
int x, y, z, n, k;
int r, c;
string ans;
bool vis[40][40];
void google(int t)
{
cout << "Case #" << t << ": ";
}
const int mod2 = 998244353;
void solve()
{
int h, w, x, y;
cin >> h >> w >> x >> y;
string s[h];
rep(i, 0, h - 1)
{
cin >> s[i];
}
int ans = 0;
rep(i, y, w)
{
if (s[x - 1][i - 1] == '.')
{
ans++;
}
else
{
break;
}
}
rrep(i, y - 1, 1)
{
if (s[x - 1][i - 1] == '.')
{
ans++;
}
else
{
break;
}
}
rep(i, x + 1, h)
{
if (s[i - 1][y - 1] == '.')
{
ans++;
}
else
{
break;
}
}
rrep(i, x - 1, 1)
{
if (s[i - 1][y - 1] == '.')
{
ans++;
}
else
{
break;
}
}
cout << ans << endl;
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cout << setprecision(15) << fixed;
int t;
t = 1;
// cin >> t;
for (int i = 1; i <= t; i++)
{
// google(i);
solve();
}
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
int dx[4]={0,1,0,-1}, dy[4]={1,0,-1,0};
long double eps = 1e-9;
long double pi = acos(-1);
template< int mod = 1000000007 >
struct ModInt {
int x;
ModInt() : x(0) {}
ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
ModInt &operator+=(const ModInt &p) {
if((x += p.x) >= mod) x -= mod;
return *this;
}
ModInt &operator-=(const ModInt &p) {
if((x += mod - p.x) >= mod) x -= mod;
return *this;
}
ModInt &operator*=(const ModInt &p) {
x = (int) (1LL * x * p.x % mod);
return *this;
}
ModInt &operator/=(const ModInt &p) {
*this *= p.inverse();
return *this;
}
ModInt operator-() const { return ModInt(-x); }
ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
bool operator==(const ModInt &p) const { return x == p.x; }
bool operator!=(const ModInt &p) const { return x != p.x; }
ModInt inverse() const {
int a = x, b = mod, u = 1, v = 0, t;
while(b > 0) {
t = a / b;
swap(a -= t * b, b);
swap(u -= t * v, v);
}
return ModInt(u);
}
ModInt pow(int64_t n) const {
ModInt ret(1), mul(x);
while(n > 0) {
if(n & 1) ret *= mul;
mul *= mul;
n >>= 1;
}
return ret;
}
friend ostream &operator<<(ostream &os, const ModInt &p) {
return os << p.x;
}
friend istream &operator>>(istream &is, ModInt &a) {
int64_t t;
is >> t;
a = ModInt< mod >(t);
return (is);
}
static int get_mod() { return mod; }
};
// const int mod = 1000000007;
const int mod = 998244353;
using mint = ModInt< mod >;
const int MAX = 5100005;
mint 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;
}
finv[MAX-1] = fac[MAX-1].inverse();
for(int i=MAX-2;i>=1;i--){
finv[i] = finv[i+1]*(i+1);
inv[i+1] = fac[i]*finv[i+1];
}
}
// 二項係数計算
mint 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]);
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(20);
int h,w;
cin>>h>>w;
string s[h];
for(int i=0;i<h;i++)cin>>s[i];
mint ans = 1;
bool pos = 1;
int ret = 0;
for(int sum=0;sum<h+w-1;sum++){
int r = 0, b = 0;
int cnt = 0;
for(int i=0;i<h;i++){
int j = sum - i;
if(j<0 )break;
if(j>=w)continue;
ret++;
if(s[i][j] == 'R')r++;
else if(s[i][j] == 'B')b++;
else cnt++;
}
if(r && b)ans = 0;
if(r || b)ans *= 1;
else ans *= 2;
}
cout << ans << endl;
cerr<<ret<<endl;
} |
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
pair<long long,long long> sum[400040] = {};
vector< pair<long long, long long>> z;
set<long long> st;
int main() {
int n;
long long c;
cin >> n >> c;
for (int i = 0; i < n; i++) {
long long a, b, c;
cin >> a >> b >> c;
z.emplace_back(make_pair(a, c));
z.emplace_back(make_pair(b + 1, -c));
st.insert(a);
st.insert(b + 1);
}
sort(z.begin(), z.end());
sum[0] = make_pair(z[0].first, z[0].second);
long long now = z[0].first, now1 = 0;
for (int i = 1; i < z.size(); i++) {
if (now == z[i].first) {
sum[now1].second += z[i].second;
}
else {
now1++;
sum[now1] = make_pair(z[i].first, z[i].second);
sum[now1].second += sum[now1 - 1].second;
now = z[i].first;
}
}
cout << endl;
long long ans = 0;
for (int i = 1; i < st.size(); i++) {
long long v = min(sum[i - 1].second, c);
ans += v * (sum[i].first - sum[i - 1].first);
}
cout << ans << endl;
}
| // abc199_d
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../../debug_util/cxx-prettyprint/prettyprint.hpp"
#include "../../debug_util/rng.hpp"
#include "../../debug_util/timer.hpp"
#endif
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
#define REP(i, n) for (int i = 0 ; i < (int)(n) ; ++i)
#define REPN(i, m, n) for (int i = m ; i < (int)(n) ; ++i)
#define REP_REV(i, n) for (int i = (int)(n) - 1 ; i >= 0 ; --i)
#define REPN_REV(i, m, n) for (int i = (int)(n) - 1 ; i >= m ; --i)
#define ALL(x) x.begin(), x.end()
#define INF (ll)(1e15)
#define MOD (1000000007)
#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int idx=0;idx<(n-1);idx++) cout << (vec)[idx] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << "\n";}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
//struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;
struct Graph {
int n;
vector<vector<int>> edges;
vector<int> con_graph;
vector<int> vals;
vector<vector<int>> con_graph_list;
ll tmp_ans = 0;
Graph(int n_) : n(n_), edges(n_), con_graph(n_, -1), vals(n_, -1) {}
void add_edge(int u, int v) {
edges[u].emplace_back(v);
edges[v].emplace_back(u);
}
void dfs0(int u, int p, int k){
con_graph[u] = k;
for (auto v: edges[u]){
if (v == p) continue;
if (con_graph[v] != -1) continue;
dfs0(v, u, k);
}
}
void dfs(int idx, int k){
if (idx == con_graph_list[k].size()){
tmp_ans++;
} else {
int u = con_graph_list[k][idx];
vector<bool> tmp(3);
for (auto v: edges[u]){
if (vals[v] == -1) continue;
tmp[vals[v]] = true;
}
REP(i, 3){
if (tmp[i]) continue;
vals[u] = i;
dfs(idx+1, k);
vals[u] = -1;
}
}
}
void func(){
int k = 0;
REP(i, n){
if (con_graph[i] != -1) continue;
dfs0(i, -1, k++);
}
// print(k);
con_graph_list.resize(k);
REP(u, n){
con_graph_list[con_graph[u]].emplace_back(u);
}
// print(con_graph_list);
ll ans = 1;
REP(i, k){
tmp_ans = 0;
if (con_graph_list[i].size() == 1){
ans *= 3;
} else {
vals[con_graph_list[i][0]] = 0;
dfs(1, i);
ans *= 3 * tmp_ans;
}
}
print(ans);
}
};
int main() {
#ifdef LOCAL
ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif
int N, M;
cin >> N >> M;
Graph g(N);
REP(i, M){
int a,b;
cin >> a >> b;
a--; b--;
g.add_edge(a, b);
}
g.func();
return 0;
}
|
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline")
#pragma GCC optimize(3 , "Ofast" , "inline")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <unordered_map>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <stack>
#include <set>
#include <bitset>
#include <deque>
using namespace std ;
#define ios ios::sync_with_stdio(false) , cin.tie(0)
#define x first
#define y second
#define pb push_back
#define ls rt << 1
#define rs rt << 1 | 1
typedef long long ll ;
const double esp = 1e-6 , pi = acos(-1) ;
typedef pair<int , int> PII ;
const int N = 1e6 + 10 , INF = 0x3f3f3f3f , mod = 1e9 + 7;
int n ;
PII a[N] ;
stack<int> st ;
char s[N] ;
int b[N] ;
int work()
{
cin >> n ;
for(int i = 1; i <= 2 * n ;i ++ ) cin >> a[i].x , a[i].y = i ;
sort(a + 1 , a + 2 * n + 1) ;
for(int i = 1; i <= 2 * n ;i ++ )
b[a[i].y] = i <= n ;
for(int i = 1; i <= 2 * n ;i ++ ) {
if(st.empty() || b[st.top()] == b[i]) st.push(i) , s[i] = '(' , cout << "(";
else st.pop() , cout << ")" ;
}
return 0 ;
}
int main()
{
// freopen("C://Users//spnooyseed//Desktop//in.txt" , "r" , stdin) ;
// freopen("C://Users//spnooyseed//Desktop//out.txt" , "w" , stdout) ;
work() ;
return 0 ;
}
/*
*/
| #include <bits/stdc++.h>
#define rep(i, l, r) for (register int i = l; i <= r; i++)
#define per(i, r, l) for (register int i = r; i >= l; i--)
#define srep(i, l, r) for (register int i = l; i < r; i++)
#define sper(i, r, l) for (register int i = r; i > l; i--)
#define erep(i, x) for (register int i = h[x]; i; i = e[i].next)
#define erep2(i, x) for (register int& i = cur[x]; i; i = e[i].next)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pdd pair<double, double>
#define fi first
#define se second
#define ui unsigned int
#define ld long double
#define pb push_back
#define pc putchar
#define lowbit(x) (x & -x)
#define maxr 2000020
#define gc() ((p1 == p2 && (p2 = (p1 = buffer) + fread(buffer, 1, maxr, stdin), p1 == p2)) ? EOF : *p1++)
using namespace std;
namespace Fast_Read{
char buffer[maxr], *p1, *p2;
template<class T> void read_signed(T& x){
char ch = gc(); x = 0; bool f = 1;
while (!isdigit(ch) && ch != '-') ch = gc();
if (ch == '-') f = 0, ch = gc();
while ('0' <= ch && ch <= '9') x = (x << 1) + (x << 3) + ch - '0', ch = gc();
x = (f) ? x : -x;
}
template<class T, class... Args> void read_signed(T& x, Args&... args){
read_signed(x), read_signed(args...);
}
template<class T> void read_unsigned(T& x){
char ch = gc(); x = 0;
while (!isdigit(ch)) ch = gc();
while (isdigit(ch)) x = (x << 1) + (x << 3) + ch - '0', ch = gc();
}
template<class T, class... Args> void read_unsigned(T& x, Args&... args){
read_unsigned(x), read_unsigned(args...);
}
#define isletter(ch) ('a' <= ch && ch <= 'z')
int read_string(char* s){
char ch = gc(); int l = 0;
while (!isletter(ch)) ch = gc();
while (isletter(ch)) s[l++] = ch, ch = gc();
s[l] = '\0'; return l;
}
}using namespace Fast_Read;
int _num[20];
template <class T> void write(T x, char sep = '\n'){
if (!x) {putchar('0'), putchar(sep); return;}
if (x < 0) putchar('-'), x = -x;
int c = 0;
while (x) _num[++c] = x % 10, x /= 10;
while (c) putchar('0' + _num[c--]);
putchar(sep);
}
#define read read_signed
#define reads read_string
#define writes puts
#define maxn 200020
#define maxm
#define maxs
#define maxb
#define inf
#define eps
#define M
#define ll long long int
int n, a[maxn];
int main(){
read(n); rep(i, 1, n) read(a[i]);
sort(a + 1, a + 1 + n);
double res = 0, x = a[(n + 1) >> 1] / 2.0;
rep(i, 1, n) res += a[i]; res /= n;
res += x;
double tmp = 0;
rep(i, 1, n) {
tmp += min(1.0 * a[i], 2.0 * x);
}
tmp /= n;
res -= tmp;
printf("%.10f", res);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vc = vector<T>;
template<class T> using vvc = vc<vc<T>>;
template<class T> using vvvc = vc<vvc<T>>;
template<class T> using vvvvc = vvc<vvc<T>>;
template<class T> using PQ = priority_queue<T>;
template<class T> using invPQ = priority_queue<T, vector<T>, greater<T>>;
using IP = pair<int, int>;
using LP = pair<ll, ll>;
#define all(x) begin(x), end(x)
#define rep(i, n) for (int i = 0; (i) < (int)(n); i++)
#define rep3(i, m, n) for (int i = (m); (i) < (int)(n); i++)
#define repr(i, n) for (int i = n; (i) >= 0; i--)
#define rep3r(i, m, n) for (int i = (n); (i) >= (int)(m); i--)
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; }
// constexpr int INF = 1070000000;
// constexpr long long LINF = 4611686015206162431;
constexpr int MOD = 1000000007;
// constexpr long double PI = 3.1415926535897932;
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;
}
using vec = vector<ll>;
using mat = vector<vector<ll>>;
mat matmul(mat &A, mat &B) {
mat C(A.size(), vec(B[0].size()));
rep (i, A.size()) {
rep (k, A[0].size()) {
rep (j, B[0].size()) {
C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD;
}
}
}
return C;
}
mat matpow(mat A, ll n) {
mat B(A.size(), vec(A.size()));
rep (i, A.size()) B[i][i] = 1;
while (n > 0) {
if (n & 1) B = matmul(B, A);
A = matmul(A, A);
n >>= 1;
}
return B;
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int N, M, K;
cin >> N >> M >> K;
mat A(1, vec(N));
rep (i, N) cin >> A[0][i];
vvc<int> graph(N);
rep (i, M) {
int X, Y;
cin >> X >> Y;
X--; Y--;
graph[X].push_back(Y);
graph[Y].push_back(X);
}
ll invm = modinv(M, MOD), inv2 = modinv(2, MOD);
mat B(N, vec(N));
rep (j, N) {
for (int i : graph[j]) {
B[i][j] = invm * inv2 % MOD;
}
B[j][j] = ((M - graph[j].size() + inv2 * graph[j].size()) % MOD) * invm % MOD;
}
B = matpow(B, K);
A = matmul(A, B);
rep (i, N) {
cout << A[0][i] << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
const int N=102;
const int mod=1e9+7;
int n,m,K,v[N],deg[N];
void add(int &x,int y)
{
(x+=y)>=mod&&(x-=mod);
}
int mul(int x,int y)
{
return 1ll*x*y%mod;
}
struct mat
{
int a[N][N];
mat(int x=0)
{
memset(a,0,sizeof a);
for(int i=1;i<=n;++i)
a[i][i]=x;
}
mat operator *(mat &x)const
{
mat res;
for(int i=1;i<=n;++i)
for(int j=1;j<=n;++j)
for(int k=1;k<=n;++k)
add(res.a[j][k],mul(a[j][i],x.a[i][k]));
return res;
}
}f[30];
int power(int x,int y=mod-2)
{
int res=1;
for(;y;y>>=1,x=mul(x,x))
if(y&1)res=mul(res,x);
return res;
}
int main()
{
scanf("%d%d%d",&n,&m,&K);
int inv=mul(power(2),power(m));
for(int i=1;i<=n;++i)
scanf("%d",&v[i]);
for(int i=1,x,y;i<=m;++i)
{
scanf("%d%d",&x,&y);
++deg[x];++deg[y];
f[0].a[x][y]=f[0].a[y][x]=inv;
}
for(int i=1;i<=n;++i)
{
f[0].a[i][i]=mul(m-deg[i],inv<<1);
add(f[0].a[i][i],mul(deg[i],inv));
}
for(int i=1;i<30;++i)
f[i]=f[i-1]*f[i-1];
mat res(1);
for(int i=0;i<30;++i)
if(K>>i&1)res=res*f[i];
for(int i=1;i<=n;++i)
{
int ans=0;
for(int j=1;j<=n;++j)
add(ans,mul(v[j],res.a[j][i]));
printf("%d\n",ans);
}
}
|
#include <stdio.h>
#include <math.h>
int main(void) {
long long int n;
long long int m;
scanf("%lld", &n);
scanf("%lld", &m);
long long int x = 0;
for(long long int i = 1; i < n; i++) {
x +=i;
}
for(long long int l =1; l <n; l++){
printf("%lld ",l);
}
printf("%lld ",1000000000-x);
long long int y = 0;
for(long long int j = 1; j < m; j++) {
y +=j;
}
for(long long int q =-1; -1*q < m; q--){
printf("%lld ",q);
}
printf("%lld",-1000000000+y);
return 0;
} | #include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
typedef int64_t lint;
#define rep(i, n) for(int i=0; i<n; i++)
#define repx(i, l, n) for(int i=l; i<n; i++)
#define all(v) v.begin(), v.end()
#define show(x) cout << #x << ": " << x << endl;
#define list(x) cout << #x << ": " << x << " ";
#define pb push_back
using vi = vector<lint>;
using vvi = vector<vector<lint>>;
template<class T> inline void vin(vector<T>& v) { rep(i, v.size()) cin >> v.at(i); }
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; }
template<class T> inline void drop(T x) { cout << x << endl; exit(0); }
template<class T> void vout(vector<T> v) { rep(i, v.size()) { cout << v.at(i) << ' '; } cout << endl; }
constexpr lint LINF = LLONG_MAX/2;
int N, M, TIME=clock();
vector<pair<int, string>> V;
vi C(8);
int sum = 0;
vector<string> S(20);
int total() {
string s;
int p = 0;
set<string> t, u;
rep(i, M) t.insert(V[i].second);
vector<string> v(20);
rep(i, N) v[i] = S[i];
rep(q, 2) {
rep(i, N) {
s = v[i] + v[i];
for (auto a : t) {
bool f = false;
rep(j, N) {
if (a == s.substr(j, a.size())) {
f = true;
break;
}
}
if (f) p += a.size();
else u.insert(a);
}
t.clear();
swap(t, u);
}
rep(i, N) { v[i].clear(); rep(j, N) v[i] += S[j][i]; }
}
return p;
}
int delta(int a, int b, int x, int y) {
string s;
int p = 0;
set<string> t, u;
rep(i, M) t.insert(V[i].second);
rep(q, 2) {
s = S[a] + S[a];
for (auto a : t) {
bool f = false;
int c = (b+N-a.size()+1)%N;
rep(j, a.size()) {
if (a == s.substr(c+j, a.size())) {
f = true;
break;
}
}
if (f) p += a.size();
else u.insert(a);
}
t.clear();
swap(t, u);
swap(a, x);
}
rep(q, 2) {
s = "";
rep(i, N) s += S[i][b];
rep(i, N) s += S[i][b];
for (auto a : t) {
bool f = false;
int c = (b+N-a.size()+1)%N;
rep(j, a.size()) {
if (a == s.substr(c+j, a.size())) {
f = true;
break;
}
}
if (f) p += a.size();
else u.insert(a);
}
t.clear();
swap(t, u);
swap(b, y);
}
return p;
}
int delta_1(int a, int b) {
string s;
int p = 0;
set<string> t, u;
rep(i, M) t.insert(V[i].second);
s = S[a] + S[a];
for (auto a : t) {
bool f = false;
int c = (b+N-a.size()+1)%N;
rep(j, a.size()) {
if (a == s.substr(c+j, a.size())) {
f = true;
break;
}
}
if (f) p += a.size();
else u.insert(a);
}
t.clear();
swap(t, u);
s = "";
rep(i, N) s += S[i][b];
rep(i, N) s += S[i][b];
for (auto a : t) {
bool f = false;
int c = (b+N-a.size()+1)%N;
rep(j, a.size()) {
if (a == s.substr(c+j, a.size())) {
f = true;
break;
}
}
if (f) p += a.size();
else u.insert(a);
}
t.clear();
swap(t, u);
return p;
}
int main() {
cin >> N >> M;
string s;
rep(i, M) {
cin >> s;
V.pb({s.size(), s});
rep(j, s.size()) C[s[j]-'A']++;
}
rep(i, 8) sum += C[i];
rep(i, 7) C[i+1] += C[i];
sort(all(V));
int a=0, b=0, c=0, x, y, z;
rep(i, N) {
rep(j, N) {
x = rand()%sum;
rep(k, 8) {
if (x < C[k]) {
S[i] += 'A'+k;
break;
}
}
}
}
// show(total())
int count = 0;
while (true) {
count++;
a = rand()%N;
b = rand()%N;
if (count%5 == 0) {
y = S[a][b]-'A';
x = y;
while (x == y) x = rand()%8;
c = delta_1(a, b);
S[a][b] = 'A'+x;
z = delta_1(a, b);
if (c > z) S[a][b] = 'A'+y;
} else {
x = rand()%N;
y = rand()%N;
c = delta(a, b, x, y);
swap(S[a][b], S[x][y]);
z = delta(a, b, x, y);
if (c > z) swap(S[a][b], S[x][y]);
}
// list(c)list(z) show(total())
if (clock()-TIME > 2.95 * CLOCKS_PER_SEC) break;
}
// show(count)
rep(i, N) std::cout << S[i] << '\n';
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e3 + 10;
const ll mod = 1e9 + 7;
ll n, m, a[N];
ll ksm(ll a, ll p)
{
ll res = 1;
while (p)
{
if (p & 1) res = res * a % mod;
a = a * a % mod;
p >>= 1;
}
return res;
}
ll get_c(ll n, ll m)
{
ll res = 1;
for (ll i = 1; i <= m; i++)
res = res * (n - i + 1) % mod * ksm(i, mod - 2) % mod;
return res;
}
int main()
{
scanf("%lld %lld", &n, &m);
for (int i = 1; i <= n; i++)
scanf("%lld", &a[i]);
ll sum = 0;
for (int i = 1; i <= n; i++)
sum += a[i];
printf("%lld\n", get_c(m + n, sum + n));
return 0;
} | #include <bits/stdc++.h>
using namespace std;
template<class T> ostream& operator<<(ostream &os, vector<T> V) { os << "[ ";
for(auto v:V)os << v << " "; return os << "]";
}
template<class T> ostream& operator<<(ostream &os, set<T> S){ os << "{ ";
for(auto s:S) os<<s<<" "; return os<<"}";
}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
return os<<"("<<P.first<<","<< P.second << ")";
}
template<class L, class R> ostream& operator<<(ostream &os, map<L,R> M) {
os<<"{ ";for(auto m:M)os<<"("<<m.first<<":"<<m.second<<")";
return os<<"}";
}
#define cerr cout
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// find_by_order(k) returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
//For multiset use less_equal operator but it does support erase operations for multiset
#define ll long long
#define ld long double
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define I insert
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define all(v) (v).begin(),(v).end()
#define For(i,n) for(int i=0;i<(int)n;++i)
#define Rev(i,n) for(int i=(int)n-1;i>=0;--i)
#define Rep(i,n) for(int i=1;i<=(int)n;++i)
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define mp make_pair
// inline void modadd(int &a,int &b){a+=b;if(a>=mod)a-=mod;}
const int mod = 1e9+7;
inline int add(int a, int b){
a += b;
if(a >= mod)
a -= mod;
return a;
}
inline int mul(int a,int b){
return a*1ll*b%mod;
}
int power(int a, int b){
int res = 1;
while(b){
if(b&1)
res = mul(res , a);
a = mul(a ,a);
b >>= 1;
}
return res;
}
const int N = 4e6 + 100;
int A[N];
int main(){
fio; cout<<fixed<<setprecision(25);
int n , m;
cin >> n >> m;
int sm = 0;
for(int i =1 ;i <= n ; ++i){
cin >> A[i];
sm += A[i];
}
//cout << sm << endl;
if(sm > m)
cout << 0 << endl;
else{
m -= sm;
//we want sum as m
int num = 1;
int den = 1;
for(int i = 0;i < sm+n ; ++i){
den = mul(den , i+1);
num = mul(num , m-i+sm+n);
}
//cout << num << ' ' << den << endl;
cout << mul(num, power(den , mod-2)) << endl;
}
return 0;
}
|
/**
* author: ekusiadadus
* created: 11.04.2021 03:33:32
**/
#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
int main(){
cin.tie(0);
ios_base::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int n;
cin >> n;
vector<int> v(2*n);
for(int i = 0; i < 2*n; ++i){
cin >> v[i];
}
multiset<int> s;
int l = 0;
int r = 2*n -1;
i64 ans = 0;
while(l<r){
s.insert(v[l]);
s.insert(v[r]);
auto it = prev(s.end());
ans += *it;
s.erase(it);
l += 1;
r -= 1;
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
// #include <atcoder/all>
// using namespace atcoder;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << "\n"
#define COUTF(x) cout << setprecision(15) << (x) << "\n"
#define ENDL cout << "\n"
#define DF(x) x.erase(x.begin())
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define RSORT(x) sort(x.rbegin(), x.rend())
#define REVERSE(x) reverse(ALL(x))
#define MAX(x) *max_element(ALL(x))
#define MAXI(x) max_element(ALL(x)) - x.begin()
#define SUM(x) accumulate(ALL(x), 0ll)
#define COUNT(x, y) count(ALL(x), y);
#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";
#define init() \
cin.tie(0); \
ios::sync_with_stdio(false)
#define debug(x) cerr << "[debug] " << #x << ": " << x << endl;
#define debugV(v) \
cerr << "[debugV] " << #v << ":"; \
rep(z, v.size()) cerr << " " << v[z]; \
cerr << endl;
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;
using vp = vector<P>;
using vs = vector<string>;
template <typename T>
inline istream& operator>>(istream& i, vector<T>& v) {
rep(j, v.size()) i >> v[j];
return i;
}
template <typename T1, typename T2>
inline istream& operator>>(istream& i, pair<T1, T2>& v) {
return i >> v.first >> v.second;
}
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
return to_string(x).size();
}
ll gcd(ll x, ll y) {
return y ? gcd(y, x % y) : x;
}
ll lcm(ll a, ll b) {
return a / gcd(a, b) * b;
}
template <class T>
void chmax(T& a, const T& b) {
if (a < b) a = b;
}
template <class T>
void chmin(T& a, const T& b) {
if (b < a) a = b;
}
signed main() {
init();
ll N;
cin >> N;
vll V(2 * N);
cin >> V;
priority_queue<ll, vll, greater<ll>> q;
ll ans = 0;
rep(i, N) {
q.push(V[N - 1 - i]);
q.push(V[N + i]);
ans += q.top();
q.pop();
}
ans = SUM(V) - ans;
ANS;
return 0;
} |
#include <iostream>
#include <vector>
using namespace std;
class Solution{
public:
long long solve(int L){
vector<vector<long long>> dp(L, vector<long long>(12, -1ll));
return C(L - 1, 11, dp);
}
private:
long long C(int N, int K, vector<vector<long long>>& dp){
if(K == 0) return 1ll;
if(N == K) return 1ll;
if(dp[N][K] != -1ll) return dp[N][K];
return dp[N][K] = C(N - 1, K, dp) + C(N - 1, K - 1, dp);
}
};
int main() {
int L; cin >> L;
cout << Solution().solve(L) << endl;
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define MOD 1000000007
#define mod9 1000000009
#define fast ios_base :: sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define mp make_pair
#define pb push_back
#define ct ll t;cin>>t;while(t--)
#define bi begin()
#define ei end()
#define fi first
#define se second
#define foe(i,a,b) for(ll i=a;i<b;i++)
#define rfoe(i,a,b) for(ll i=a;i>=0;i--)
#define sz(s) s.size()
#define mem(a,s) memset(a,s,sizeof(a))
#define all(v) v.bi,v.ei
#define MAX 8000000000000000064LL
#define MIN -8000000000000000064LL
typedef pair<ll,ll> pii;
ll add(ll a, ll b){return (a%MOD + b%MOD + ((MAX)/MOD)*MOD)%MOD;}
ll sub(ll a, ll b){return (a%MOD - b%MOD + ((MAX)/MOD)*MOD)%MOD;}
ll mul(ll a, ll b){return ((a%MOD)*(b%MOD) + ((MAX)/MOD)*MOD)%MOD;}
long long binpow(long long a, long long b)
{
long long res = 1;
while (b > 0) {
if (b & 1)
res = res*a;
a = a*a;
b >>= 1;
}
return res;
}
ll lcm(ll a,ll b){return(a*b)/__gcd(a,b);}
ll fact[1000007 ]={0};
ll expo(ll x, ll y) {ll res=1;x=x%MOD;while(y>0){if(y&1)res=(1ll*res*x)%MOD;
y=y>>1;x=(1ll*x*x)%MOD;} return res;}
void facto() {fact[0]=1;fact[1]=1;for(ll i=2;i<1000007;i++)fact[i]=(fact[i-1]*i)%MOD;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(expo(fact[r],MOD-2)))%MOD; res=(res*(expo(fact[n-r],MOD-2)))%MOD; return res;}
ll npr(ll n,ll r) {facto(); ll res=1; res=fact[n]; res=(res*(expo(fact[n-r],MOD-2)))%MOD; return res; }
int const N=1e5+9;
ll const INF = 2e18+5;
ll dx[8]={0,0,1,-1,1,1,-1,-1};
ll dy[8]={1,-1,0,0,-1,1,-1,1};
void solve()
{
ll n;
cin>>n;
ll ans=1;
foe(i,0,11)
{
ans=ans*(n-(i+1))/(i+1);
}
cout<<ans<<"\n";
}
int main()
{
fast
facto();
// Sieve();
// ct
{
solve();
}
} |
// #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 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<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 {
if (p1.F == p2.F)
return p1.S.F > p2.S.F;
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 = 2e5 + 5, inf = 2e18;
vector<int> adj[N];
int tin[N], tout[N], tim, height[N];
std::vector<int> have[N];
void dfs(int s, int p, int h)
{
tin[s] = ++tim;
height[s] = h;
have[h].pb(tin[s]);
for (auto x : adj[s])
{
if (x != p)
{
dfs(x, s, h + 1);
}
}
tout[s] = ++tim;
}
void solve()
{
int n, x, y, q;
cin >> n;
forn(i, 1, n)
{
cin >> x;
x--;
adj[x].pb(i);
adj[i].pb(x);
}
dfs(0, -1, 0);
cin >> q;
forn(i, 0, q)
{
cin >> x >> y;
x--;
if (height[x] > y)
{
cout << 0 << '\n';
continue;
}
cout << upper_bound(all(have[y]), tout[x]) - lower_bound(all(have[y]), tin[x]) << '\n';
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int test = 1;
clock_t z = clock();
// cin >> test;
forn(tes, 0, test)
{
solve();
}
debug("Total Time:%.4f\n", (double)(clock() - z) / CLOCKS_PER_SEC);
return 0;
} | /* -*- coding: utf-8 -*-
*
* e.cc: E - Train
*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
/* constant */
const int MAX_N = 100000;
const int MAX_M = 100000;
const long long LINF = 1LL << 62;
/* typedef */
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef vector<pii> vpii;
/* global variables */
int ts[MAX_M], ks[MAX_M];
vpii nbrs[MAX_N];
ll ds[MAX_N];
/* subroutines */
/* main */
int main() {
int n, m, st, gl;
scanf("%d%d%d%d", &n, &m, &st, &gl);
st--, gl--;
for (int i = 0; i < m; i++) {
int a, b;
scanf("%d%d%d%d", &a, &b, ts + i, ks + i);
a--, b--;
nbrs[a].push_back(pii(b, i));
nbrs[b].push_back(pii(a, i));
}
fill(ds, ds + n, LINF);
ds[st] = 0;
priority_queue<pli> q;
q.push(pli(0, st));
while (! q.empty()) {
pli u = q.top(); q.pop();
ll ud = -u.first;
int ui = u.second;
if (ds[ui] != ud) continue;
if (ui == gl) break;
vpii &nbru = nbrs[ui];
for (vpii::iterator vit = nbru.begin(); vit != nbru.end(); vit++) {
int vi = vit->first, ei = vit->second;
ll vd = (ud + ks[ei] - 1) / ks[ei] * ks[ei] + ts[ei];
if (ds[vi] > vd) {
ds[vi] = vd;
q.push(pli(-vd, vi));
}
}
}
printf("%lld\n", (ds[gl] < LINF) ? ds[gl] : -1LL);
return 0;
}
|
Subsets and Splits