code_file1
stringlengths 87
4k
| code_file2
stringlengths 85
4k
|
---|---|
#include <iostream>
using namespace std;
int main()
{
int r1, c1, r2, c2;
cin >> r1 >> c1 >> r2 >> c2;
int ans = 0;
if (r1 == r2 && c1 == c2){
ans = 0;
}else if (abs(r1 - r2) + abs(c1 - c2) <= 3){
ans = 1;
}else if (r1 - r2 + c1 - c2 == 0 || r1 - r2 - c1 + c2 == 0){
ans = 1;
}
else if((r1 + r2 + c1 + c2) % 2 == 0){
ans = 2;
}else if ( abs(r1 - r2) + abs(c1 - c2) <= 6){
ans = 2;
}else if (abs(r1 + c1 - r2 - c2) <= 3){
ans = 2;
}else if (abs(r1 - c1 - r2 + c2) <= 3){
ans = 2;
}else{
ans = 3;
}
cout << ans << endl;
} | #pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
#define IO std::ios::sync_with_stdio(false); cin.tie(0)
#define ll long long
#define ull unsigned long long
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rep(i, l, r) for (int i = l; i <= r; i++)
#define per(i, l, r) for (int i = l; i >= r; i--)
#define mset(s, _) memset(s, _, sizeof(s))
#define pb push_back
#define pii pair <int, int>
#define mp(a, b) make_pair(a, b)
#define debug(x) cerr << #x << " = " << x << '\n';
#define pll pair <ll, ll>
#define fir first
#define sec second
#define INF 0x3f3f3f3f
#define int ll
inline int read() {
int x = 0, neg = 1; char op = getchar();
while (!isdigit(op)) { if (op == '-') neg = -1; op = getchar(); }
while (isdigit(op)) { x = 10 * x + op - '0'; op = getchar(); }
return neg * x;
}
inline void print(int x) {
if (x < 0) { putchar('-'); x = -x; }
if (x >= 10) print(x / 10);
putchar(x % 10 + '0');
}
int a,b,c,d;
signed main() {
IO;
cin >> a >> b >> c >> d;
if (a == c && b == d) cout << 0 << '\n';
else if (a + b == c + d || a - b == c - d) {
cout << 1 << '\n';
}else if (abs(a - c) + abs(b - d) <= 3) {
cout << 1 << '\n';
}else {
if ((d - b - c + a) % 2 && abs(abs(d - b) - abs(c - a)) > 3) cout << 3 << '\n';
else cout << 2 << '\n';
}
return 0;
} |
#include <bits/stdc++.h>
#define int long long
// #include <atcoder/all>
// using namespace atcoder;
// using mint = modint1000000007;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long double PI = acos(-1.0);
// cout << fixed << setprecision(14);
signed main() {
int N, S, D;
cin >> N >> S >> D;
int X[N], Y[N];
rep(i,N){
cin >> X[i] >> Y[i];
}
rep(i,N){
if(X[i] < S && Y[i] > D){
cout << "Yes" << endl;
return 0;
}
}
cout << "No" << endl;
} | #include<iostream>
using namespace std;
int main()
{
int a, b, c;
int ans;
cin >> a >> b >> c;
if (a == b) {
ans = c;
} else {
if (b == c) {
ans = a;
} else {
if (c == a) {
ans = b;
} else {
ans = 0;
}
}
}
cout << ans << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
void solve() {
int n, m;
cin >> n >> m;
vector<i64> dp(1 << n);
vector<vector<pair<int, int>>> conds(1 + n);
while (m--) {
int x, y, z;
cin >> x >> y >> z;
conds[x].emplace_back(y, z);
}
dp[0] = 1;
for (int s = 0; s < 1 << n; s++) {
for (auto [y, z] : conds[__builtin_popcount(s)]) {
for (int i = 0; i < y; i++) {
if (s >> i & 1) z--;
}
if (z < 0) dp[s] = 0;
}
for (int j = 0; j < n; j++)
if (~s >> j & 1) {
dp[s | 1 << j] += dp[s];
}
}
cout << dp.back() << "\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
solve();
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define mp make_pair
#define MOD(a, m) ((a % m + m) % m)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;
int main(){
ll N, M;
cin >> N >> M;
using P = pair<ll, ll>;
vector<P> YZ[30];
REP(i,M){
ll x, y, z;
cin >> x >> y >> z;
//x--;
YZ[x].push_back(P(y, z));
}
vector<ll> DP(1 << N);
DP[0] = 1;
for(int b = 0; b < (1 << N); b++){
ll pop = __builtin_popcount(b);
for(int v = 0; v < N; v++){
if((b >> v) & 1) continue;
bool valid = true;
for(auto& [y, z] : YZ[pop+1]){
ll num = 0;
if(v+1 <= y) num++;
for(int x = 0; x < y; x++){
if((b >> x) & 1)
num++;
}
if(num > z)
valid = false;
}
if(valid){
DP[b | (1 << v)] += DP[b];
}
}
}
ll ans = DP[(1 << N) - 1];
cout << ans << endl;
return 0;
}
|
// 問題の URL を書いておく
//
#include <bits/stdc++.h>
using namespace std;
//#define ENABLE_PRINT
#if defined(ENABLE_PRINT)
#define Print(v) \
do {\
cout << #v << ": " << v << endl; \
}while(0)
#define PrintVec(v) \
do {\
for(int __i = 0; __i < v.size(); ++__i) \
{ \
cout << #v << "[" << __i << "]: " << v[__i] << endl; \
}\
}while(0)
#else
#define Print(v) ((void)0)
#define PrintVec(v) ((void)0)
#endif
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
using ll = long long;
int main(int, const char**)
{
int N;
cin >> N;
vector<int> A(N), B(N);
rep(i, N) cin >> A[i];
rep(i, N) cin >> B[i];
int ans = 0;
rep(i, 1000)
{
auto t = i + 1;
bool valid = true;
rep(j, N)
{
if(!(A[j] <= t && t <= B[j]))
{
valid = false;
break;
}
}
if(valid) ans++;
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n; cin >> n;
int a = 0, b = 1000000;
for (int i = 0; i < n; i++) {
int a1; cin >> a1;
a = max(a1, a);
}
for (int i = 0; i < n; i++) {
int b1; cin >> b1;
b = min(b1, b);
}
if (b < a) cout << 0;
else cout << b - a + 1;
} |
#include <bits/stdc++.h>
using namespace std;
#define flush cout.flush
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pl = pair<ll, ll>;
const ll INF = 1e9 + 7;
const ll mod = 1e9 + 7;
const ll mod2 = 998244353;
const ld eps = 1e-9;
const ld PI = acos(-1);
ld C = (ld) 9 / (ld) 20;
vector<ld> a;
ld f(ld x) {
ld s = 0.0;
for (auto &t : a) {
s += x + t - min(t, 2.0 * x);
}
s /= a.size();
return s;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
ll n;
cin >> n;
a.resize(n);
for (ld &i :a)cin >> i;
ld l = 0.0, r = 1e14 + 200;
while (r - l > eps) {
ld m1 = l + C * (r - l);
ld m2 = r - C * (r - l);
if (f(m2) > f(m1)) {
r = m2;
} else l = m1;
}
cout << fixed << setprecision(20);
cout << f(l) << "\n";
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define DONTSYNC ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) //dont use stdio with iostream functions //input and output are out of order now!
#define TEST unsigned long long T; cin>>T; while(T--) //loop over each testcase
#define endl "\n"
#define fori(a,start,end) for(int a=start;a<end;a++)
#define forl(a,start,end) for(long long a=start;a<end;a++)
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
const double PI = acos(-1);
ld calculate_prof(ld x,vector<ld> &arr,vector<ld> &pref){
int n=arr.size()-1; ld prof=0;
int r=lower_bound(all(arr),2*x)-arr.begin();
prof=(n+1-r)*2*x + pref[r-1] - x*n;
return prof;
}
void solve(){
/* code */
int n; cin>>n;
vector<ld> arr(n+1),pref(n+1); pref[0]=0; arr[0]=0;
ld tot=0;
fori(i,1,n+1){
cin>>arr[i];
tot+=arr[i];
}sort(all(arr));
fori(i,1,n+1) pref[i]=arr[i]+pref[i-1];
ld prof=0,x=0;
fori(i,1,n+1){
ld cur_prof;
cur_prof=calculate_prof(arr[i]/2,arr,pref);
if(cur_prof>prof) prof=cur_prof,x=arr[i]/2;
// cur_prof=calculate_prof(arr[i],arr,pref);
// if(cur_prof>prof) prof=cur_prof,x=arr[i];
}
cout<<fixed<<setprecision(6)<<(tot-prof)/n<<endl;
}
int main()
{
DONTSYNC;
// TEST
solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define all(x) (x).begin(),(x).end()
#define allr(x) (x).rbegin(),(x).rend()
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define sz(x) (int)((x).size())
#define fr first
#define sc second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int,int>
#define mii map<pii,int>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define el '\n'
void solve()
{
int n;
cin>>n;
vii v1,v2;
rep(i,0,n){
int x,y;
cin>>x>>y;
v1.pb({x,i});
v2.pb({y,i});
}
sort(all(v1));
sort(all(v2));
int ans1=v1[n-1].fr-v1[0].fr;
int ans2=v2[n-1].fr-v2[0].fr;
int a,b;
if(ans1>ans2){
int ans=0;
a=v1[n-1].sc;
b=v1[0].sc;
ans=max(ans,v1[n-1].fr-v1[1].fr);
ans=max(ans,v1[n-2].fr-v1[0].fr);
if((v2[n-1].sc==a&&v2[0].sc==b)||(v2[0].sc==a&&v2[n-1].sc==b)){
ans=max(ans,v2[n-1].fr-v2[1].fr);
ans=max(ans,v2[n-2].fr-v2[0].fr);
}
else{
ans=max(ans,v2[n-1].fr-v2[0].fr);
}
cout<<ans<<el;
}
else if(ans2>ans1){
vii vx=v1;
v1=v2;
v2=vx;
int ans=0;
a=v1[n-1].sc;
b=v1[0].sc;
ans=max(ans,v1[n-1].fr-v1[1].fr);
ans=max(ans,v1[n-2].fr-v1[0].fr);
if((v2[n-1].sc==a&&v2[0].sc==b)||(v2[0].sc==a&&v2[n-1].sc==b)){
ans=max(ans,v2[n-1].fr-v2[1].fr);
ans=max(ans,v2[n-2].fr-v2[0].fr);
}
else{
ans=max(ans,v2[n-1].fr-v2[0].fr);
}
cout<<ans<<el;
}
else{
int ans=0;
a=v1[n-1].sc;
b=v1[0].sc;
if((v2[n-1].sc==a&&v2[0].sc==b)||(v2[0].sc==a&&v2[n-1].sc==b)){
ans=max(ans,v1[n-1].fr-v1[1].fr);
ans=max(ans,v1[n-2].fr-v1[0].fr);
ans=max(ans,v2[n-1].fr-v2[1].fr);
ans=max(ans,v2[n-2].fr-v2[0].fr);
cout<<ans<<el;
}
else{
cout<<ans1<<el;
}
}
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int t=1;
// cin>>t;
while(t--) solve();
return 0;
}
| #pragma GCC optimize(2)
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 998244353
#define INF63 1061109567
#define INF127 9187201950435737471
#define UINF 18446744073709551615
#define F first
#define S second
#define ll long long
#define N 100010
using namespace std;
ll n,m,mask[N],sz=0;
string s[N];
int main(){
ll i,j;
cin>>n>>m;
for(i=0;i<n;i++)
{
cin>>s[i];
for(j=0;j<m;j++)
{
if(s[i][j]=='1')
{
mask[i]|=(1<<j);
}
}
}
for(i=1;i<n;i++)
{
if(__builtin_popcount(mask[0]^mask[i])%2==1)
{
sz++;
}
}
cout<<sz+sz*(n-1-sz)<<endl;
return 0;
} |
#include <cmath>
#include <deque>
#include <algorithm>
#include <iterator>
#include <list>
#include <tuple>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <unordered_set>
#include <stack>
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
#include <functional>
#include <numeric>
#include <iomanip>
#include <stdio.h>
//eolibraries
#define lnf 3999999999999999999
#define inf 999999999
#define fi first
#define se second
#define pb push_back
#define ll long long
#define ld long double
#define all(c) (c).begin(),(c).end()
#define sz(c) (ll)(c).size()
#define make_unique(a) sort(all(a)),a.erase(unique(all(a)),a.end())
#define pii pair <ll,ll>
#define rep(i,n) for(ll i = 0 ; i < n ; i++)
#define drep(i,n) for(ll i = n-1 ; i >= 0 ; i--)
#define crep(i,x,n) for(ll i = x ; i < n ; i++)
#define vi vector <ll>
#define vec(...) vector<__VA_ARGS__>
#define fcin ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
//eodefine
using namespace std;
const ll max_n = 903002;
struct dsuni {
ll n;
vector<ll> par, siz , color;
dsuni(ll m) {
init(m);
}
void init(ll m) {
n=m;
par.resize(n,0); siz.resize(n,0); color.resize(n,0);
rep(i,n) {
par[i] = i; siz[i] = 1;
}
}
ll parent(ll x) {
return par[x] == x ? x : parent(par[x]);
}
ll getsize(ll x) {
return siz[parent(x)];
}
void mkuni(ll x , ll y , ll type = 0) {
ll a = parent(x) , b = parent(y);
if(a == b) return;
if(siz[a] > siz[b]) {
// rm(b);
siz[a] += siz[b];
par[b] = a;
return;
}
// rm(a);
siz[b] += siz[a];
par[a] = b;
}
bool isuni(ll x, ll y) {
ll a = parent(x) , b = parent(y);
return a == b;
}
};
ll a[max_n];
int main(){
fcin;
ll n;
cin>>n;
rep(i,n){
cin>>a[i];
}
dsuni dsu(max_n);
rep(i,n){
dsu.mkuni(a[i],a[n-i-1]);
}
ll ans=0;
rep(i,max_n){
if(i==dsu.parent(i)){
ans += max((ll)0,dsu.siz[i]-1);
}
}
cout<<ans<<"\n";
/*
*/
return 0;
} | //#define _DEBUG
#pragma GCC optimize("O2")
#include "bits/stdc++.h"
//#include <atcoder/all>
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,a5,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#define debug_6(x1,x2,x3,x4,x5,x6) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<", "#x6<<": "<<x6<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_6,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif
#define rep(index,num) for(int index=0;index<(int)num;index++)
#define rep1(index,num) for(int index=1;index<=(int)num;index++)
#define brep(index,num) for(int index=(int)num-1;index>=0;index--)
#define brep1(index,num) for(int index=(int)num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define prind(argument) cout<<std::fixed<<setprecision(13)<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define puba(a) emplace_back(a)
#define pubamp(a,b) emplace_back(mp(a,b))
typedef long long ll;
typedef long double ld;
using namespace std;
//using namespace atcoder;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
vint adj[1001][26];
bool connect[1001][1001]={};
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
int N,M;
int A[1001],B[1001];
char C[1001];
bool alre[1001][1001]={};
scan(N>>M);
rep(i,M){
scan(A[i]>>B[i]>>C[i]);
A[i]--; B[i]--;
adj[A[i]][C[i]-'a'].puba(B[i]);
adj[B[i]][C[i]-'a'].puba(A[i]);
connect[A[i]][B[i]]=1;
connect[B[i]][A[i]]=1;
}
if(connect[0][N-1]){
prin(1);
return 0;
}
vpint record;
record.pubamp(0,N-1);
alre[0][N-1]=alre[N-1][0]=1;
int ans=INF;
bool owari=0;
for(int cnt=1;!record.empty();cnt++){
vpint before=record;
record.clear();
for(const auto& pp:before){
int u1=pp.first,u2=pp.second;
debug(cnt,u1+1,u2+1);
rep(k,26){
for(const auto& v1:adj[u1][k]){
for(const auto& v2:adj[u2][k]){
if(alre[v1][v2]==0){
alre[v1][v2]=1;
alre[v2][v1]=1;
if(v1==v2){
chmin(ans,cnt*2);
owari=1;
}
else if(connect[v1][v2]){
chmin(ans,cnt*2+1);
owari=1;
}
else record.pubamp(v1,v2);
}
}
}
}
}
if(owari){
prin(ans);
return 0;
}
}
prin(-1);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
int main(){
int n,x;
cin >> n >> x;
string s;
cin >> s;
rep(i,n){
if(s.at(i) == 'o') x += 1;
if(s.at(i) == 'x'){
if(x != 0) x -= 1;
else continue;
}
}
cout << x << endl;
return 0;
}
| #include <bits/stdc++.h>
#define llong long long
#define INF 999999999
using namespace std;
int main()
{
int N, X;
string S;
cin >> N >> X >> S;
for (int i = 0; i < N; i++)
{
if (S[i] == 'o')
X++;
else
{
if (X > 0)
X--;
}
}
cout << X;
} |
/*
मनस्वी म्रियते कामं कार्पण्यं न तु गच्छति ।
अपि निर्वाणमायाति नानलो याति शीतताम् ॥
*/
#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 mod 1000000007
#define pb push_back
#define ll long long int
#define ull unsigned ll
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define v2i vector<vector<int>>
#define v2l vector<vector<ll>>
#define ppi pair<int,int>
#define ppl pair<ll,ll>
#define vpi vector<ppi>
#define vpl vector<ppl>
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define forn(i,a,b) for(int i=a;i<b;i++)
#define forr(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,m) for(auto i : m)
#define p2d(v) for(auto a:v){for(auto b:a)cout<<b<<" ";cout<<endl;}
#define p1d(v) for(auto a:v)cout<<a<<" ";cout<<endl;
#define ppd(v) for(auto a:v)cout<<a.ff<<" "<<a.ss<<endl;
#define imx INT_MAX
#define imn INT_MIN
#define inf 9000000000000000000
#define minf -inf
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse
#define itr iterator
#define pre cout<<fixed<<setprecision(10);
#define umap unordered_map
#define uset unordered_set
#define pi 3.141592653589793
#define MAXN 100005
#define test1(x) cout << #x " = " << x << endl;
#define test2(x,y) cout << #x " = " << x << " " << #y " = " << y << endl;
#define test3(x,y,z) cout << #x " = " << x << " " << #y " = " << y << " " << #z " = " << z << endl;
#define test4(w,x,y,z) cout << #w " = " << w << " " << #x " = " << x << " " << #y " = " << y << " " << #z " = " << z << endl;
#define oset tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
/*
const ll infinity = 9e18;
bool compare(ll a,ll b) {return a > b;}
bool compare1(ppl a,ppl b) {return a.ff > b.ff;}
bool compare2(ppl a,ppl b) {return a.ss < b.ss;}
bool isprime(ll n){if(n < 2) return 0; ll i = 2; while(i*i <= n){if(n%i == 0) return 0; i++;} return 1;}
ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md = mod) {ll product = 1; while(b){if(b&1){product = (product*a)%md;}a = (a*a)%md;b = b>>1;} return product%md;}
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }
*/
int main()
{
fast
/*
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
//*/
ll n,m;
cin>>n>>m;
vl a(n),b(m);
forn(i,0,n)
{
cin>>a[i];
}
forn(i,0,m)
{
cin>>b[i];
}
sort(all(a));
sort(all(b));
ll mid = a[(n/2)];
ll total = 0;
vl c(n,0),d(n,0);
for(int i = 1; i < n; i += 2)
{
c[i] = total + (a[i]-a[i-1]);
if(i+1 < n) c[i+1] = c[i];
total = c[i];
}
total = 0;
for(int i = n-2; i >= 0; i -= 2)
{
d[i] = total + (a[i+1]-a[i]);
if(i-1 >= 0) d[i-1] = d[i];
total = d[i];
}
// p1d(c)
// p1d(d)
ll mini = inf;
forn(i,0,m)
{
ll idx = upper_bound(all(a),b[i]) - a.begin();
// test1(idx)
ll x = idx-1 >= 0 ? c[idx-1] : 0;
ll y = idx < n ? d[idx] : 0;
if((idx&1))
{
// x = idx-1 >= 0 ? c[idx-1] : 0;
// y = idx < n ? d[idx] : 0;
// test1(a[idx-1])
mini = min(mini,x + abs(b[i]-a[idx-1]) + y);
}
else
{
// test1(a[idx-1])
mini = min(mini,x + abs(a[idx]-b[i]) + y);
}
// test3(x,y,x + abs(a[idx]-b[i]) + y)
}
cout<<mini;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define fo(a,b) for(int64_t a=0;a<b;a++)
#define sor(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define ll int64_t
#define mod 998244353
#define vl vector<int64_t>
#define vc vector<char>
#define vs vector<string>
#define np(vec) next_permutation(vec.begin(),vec.end())==true
#define en endl
#define vvl vector<vector<int64_t>>
#define stl stack<int64_t>
#define qul que<int64_t>
#define ms(a,b) memset(a,b,sizeof(a))
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pq priority_queue
#define pql priority_queue<int64_t>
#define pu push
#define pop pop()
#define top top()
#define pqr priority_queue<ll,vector<ll>,greater<ll>>
#define co cout
#define ci cin
#define wh while
#define size size()
#define front front()
int main() {
ll a,b,m;
m=0;
cin>>a>>b;
if(a>=b){
fo(i,a){cout<<i+1<<" ";
m+=i+1;}
fo(i,b-1){cout<<-(i+1)<<" ";
m+=-(i+1);}
cout<<-m<<en;
}
else{
fo(i,b){cout<<-(i+1)<<" ";
m+=-(i+1);}
fo(i,a-1){cout<<i+1<<" ";
m+=i+1;}
cout<<-m<<en;
}
} |
#include<bits/stdc++.h>
using namespace std;
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int L,R;
scanf("%d%d",&L,&R);
if(R>=2*L)
printf("%lld\n",(R-2*L+1ll)*(R-2*L+2)>>1);
else
puts("0");
}
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
#define boost ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//#define mp make_pair
#define pb push_back
#define fp first
#define sp second
typedef long long int ll;
typedef pair<ll,ll> pp;
#define check(x, i) ((x>>i)&1LL)
#define set(x,i) (x|(1LL<<i))
#define unset(x,i) (x&~(1LL<<i))
#define INF LONG_MAX
#define MAX_N 20
#define MAX 200005
#define mod 1000000007
#define REP(i,n) for(i=0;i<n;i++)
#define FOR(i,a,b) for(i=a;i<=b;i++)
#define RFOR(i,a,b) for(i=a;i>=b;i--)
#define len(i,s) for(i=0;s[i];i++)
#define T() ll t;cin>>t;while(t--)
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2")
ll gcd (ll a, ll b){return (a?gcd(b%a,a):b);}
ll pow1(ll a,ll b,ll MOD){ll ans=1;while(b!=0){if(b&1)ans=(ans*a)%MOD;a=(a*a)%MOD;b=b/2;}return ans;}
ll modInverse(ll a,ll p){return pow1(a,p-2,p);}
void ash(){
boost
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
ll _mergeSort(ll arr[], ll temp[],
ll left, ll right);
ll merge(ll arr[], ll temp[], ll left,
ll mid, ll right);
/* This function sorts the
input array and returns the
number of inversions in the array */
ll mergeSort(ll arr[], ll array_size)
{
ll temp[array_size];
return _mergeSort(arr, temp, 0, array_size - 1);
}
/* An auxiliary recursive function
that sorts the input array and
returns the number of inversions in the array. */
ll _mergeSort(ll arr[], ll temp[],
ll left, ll right)
{
ll mid, inv_count = 0;
if (right > left) {
/* Divide the array into two parts and
call _mergeSortAndCountInv()
for each of the parts */
mid = (right + left) / 2;
/* Inversion count will be sum of
inversions in left-part, right-part
and number of inversions in merging */
inv_count += _mergeSort(arr, temp,
left, mid);
inv_count += _mergeSort(arr, temp,
mid + 1, right);
/*Merge the two parts*/
inv_count += merge(arr, temp, left,
mid + 1, right);
}
return inv_count;
}
/* This funt merges two sorted arrays
and returns inversion count in the arrays.*/
ll merge(ll arr[], ll temp[], ll left,
ll mid, ll right)
{
ll i, j, k;
ll inv_count = 0;
i = left; /* i is index for left subarray*/
j = mid; /* j is index for right subarray*/
k = left; /* k is index for resultant merged subarray*/
while ((i <= mid - 1) && (j <= right)) {
if (arr[i] <= arr[j]) {
temp[k++] = arr[i++];
}
else {
temp[k++] = arr[j++];
/* this is tricky -- see above
explanation/diagram for merge()*/
inv_count = inv_count + (mid - i);
}
}
/* Copy the remaining elements of left subarray
(if there are any) to temp*/
while (i <= mid - 1)
temp[k++] = arr[i++];
/* Copy the remaining elements of right subarray
(if there are any) to temp*/
while (j <= right)
temp[k++] = arr[j++];
/*Copy back the merged elements to original array*/
for (i = left; i <= right; i++)
arr[i] = temp[i];
return inv_count;
}
int main()
{
ash();
ll n;
cin>>n;
ll arr[n];
ll a1[n];
ll i;
REP(i,n)
{
cin>>arr[i];
a1[i]=arr[i];
}
ll ans = mergeSort(arr, n);
cout<<ans<<"\n";
for(i=0;i<n-1;i++)
{
ll sub=a1[i];
ll add=n-1-a1[i];
ans=ans-sub+add;
// cout<<sub<<" "<<add<<" ";
cout<<ans<<"\n";
}
}
|
#include<bits/stdc++.h>
#define ll long long
#define re register
#define INF 2147483647
using namespace std;
inline int read()
{
int f=1,x=0;char s=getchar();
while(s<'0'||s>'9')
{
if(s=='-') f=-1;
s=getchar();
}
while(s>='0'&&s<='9')
{
x=x*10+s-48;
s=getchar();
}
return f*x;
}
const int p=1e9+7;
inline int ksm(int a,int b)
{
int ans=1;
for(;b;b>>=1,a=1ll*a*a%p)
if(b&1) ans=1ll*ans*a%p;
return ans;
}
int main()
{
int n=read(),m=read();
int sum=0;
for(int i=1;i<=n;i++) sum+=read();
int ans=1;
sum+=n;
n+=m;
if(sum>n)
{
puts("0");
return 0;
}
int t1=1,t2=1;
for(int i=1;i<=sum;i++)
t1=1ll*t1*(n-i+1)%p,t2=1ll*t2*i%p;
printf("%d\n",1ll*t1*ksm(t2,p-2)%p);
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n)for(int i=0,i<(n);++i)
using namespace std;
using ll = long long;
const int mod = 1000000007;
struct mint {
ll x; // typedef long long ll;
mint(ll x=0):x((x%mod+mod)%mod){}
mint operator-() const { return mint(-x);}
mint& operator+=(const mint a) {
if ((x += a.x) >= mod) x -= mod;
return *this;
}
mint& operator-=(const mint a) {
if ((x += mod-a.x) >= mod) x -= mod;
return *this;
}
mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
mint operator+(const mint a) const { return mint(*this) += a;}
mint operator-(const mint a) const { return mint(*this) -= a;}
mint operator*(const mint a) const { return mint(*this) *= a;}
mint pow(ll t) const {
if (!t) return 1;
mint a = pow(t>>1);
a *= a;
if (t&1) a *= *this;
return a;
}
// for prime mod
mint inv() const { return pow(mod-2);}
mint& operator/=(const mint a) { return *this *= a.inv();}
mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
mint C(ll x, ll y) {
mint a = 1, b = 1;
if (x < y) return 0;
for (int i = 1; i <= y; i++)
a = a * (x - i + 1);
for (int i = 1; i <= y; i++)
b = b * i;
return a * b.inv();
}
int main(){
ll n, m; cin >> n >> m;
int s = 0;
for(int i = 0; i < n; i++){
ll a; cin >> a;
s += a;
}
mint ans;
ans = C(m+n, s+n); //二項係数a_C_bを計算する
cout << ans << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
//using namespace atcoder;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define pb push_back
#define fi first
#define se second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void chOut(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }
using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using v_bool = vector<bool>;
using v_Pii = vector<Pii>;
//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};
const int mod = 1000000007;
//const int mod = 998244353;
signed main(){
int N; cin >> N;
string S, T; cin >> S >> T;
vec s, t;
int n1 = 0;
REP(i, N){
if(S[i] == '1') n1++;
else s.pb(n1);
}
n1 = 0;
REP(i, N){
if(T[i] == '1') n1++;
else t.pb(n1);
}
int ans;
if(SZ(s) != SZ(t)) ans = -1;
else{
ans = 0;
REP(i, SZ(s)) if(s[i] != t[i]) ans++;
}
Out(ans);
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
int main(){
int n, x;
cin >> n >> x;
string str;
cin >> str;
for (int i=0; i<n; i++){
if (str[i]=='o'){
x++;
}
else if (str[i]=='x'){
x--;
}
x = max(x, 0);
}
cout << x << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll,ll> pll;
typedef vector <int> vint;
typedef vector <ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef vector <string> vs;
typedef priority_queue <int> pqi;
#define FOR(i, a, b) for(int i = a; i < (b); ++i)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define FORd(i, a, b) for(int i = (b) - 1; i >= a; --i)
#define F0Rd(i, a) for(int i = (a) - 1; i >= 0; --i)
#define trav(x, a) for(auto& x : a)
#define pb push_back
#define mkp make_pair
#define vbb vector <bool>
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
const int mod = 1000000007;
const long long inf = 1e18;
const char nl = '\n';
vector <vint> tree, util;
int tim = 0;
vint xin, xout, depth;
void dfs(int i){
xin[i] = tim++;
util[depth[i]].pb(xin[i]);
for(int x : tree[i]){
depth[x] = depth[i] + 1;
dfs(x);
}
xout[i] = tim++;
}
void solve_it(){
int n; cin>>n;
vector <vint> temp(n + 1);
FOR(i, 2, n + 1){
int p; cin>>p;
temp[p].pb(i);
}
util = vector <vint> (n + 1);
tree = temp;
xin = xout = depth = vint (n + 1);
dfs(1);
int q; cin>>q;
while(q--){
int u, d; cin>>u>>d;
vint v = util[d];
cout<<lb(all(v), xout[u]) - lb(all(v), xin[u])<<nl;
}
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
solve_it();
return 0;
}
| // Problem: E - Count Descendants
// Contest: AtCoder - AISing Programming Contest 2021(AtCoder Beginner Contest 202)
// URL: https://atcoder.jp/contests/abc202/tasks/abc202_e
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Author: abhidot
#include <bits/stdc++.h>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define mod 1000000007 //998244353
#define lld long double
#define pii pair<int, int>
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
#define w(x) int x; cin>>x; while(x--)
using namespace std;
const long long N=200005, INF=2000000000000000000;
/*------------- Modular exponentiation -------------*/
int power(int a, int b, int p)
{
if(a==0)
return 0;
int res=1;
a%=p;
while(b>0)
{
if(b&1)
res=(res*a)%p;
b>>=1;
a=(a*a)%p;
}
return res;
}
/*------------- Sieve --------------*/
vector <int> prime;
bool is_composite[N];
void sieve (int n) {
fill (is_composite, false);
for (int i = 2; i < n; ++i) {
if (!is_composite[i]) prime.push_back (i);
for (int j = 0; j < prime.size () && i * prime[j] < n; ++j) {
is_composite[i * prime[j]] = true;
if (i % prime[j] == 0) break;
}
}
}
/*------------ Utitlity function ---------------*/
void print(bool n){
if(n){
cout<<"YES";
}else{
cout<<"NO";
}
}
vector<int> g[N], d[N];
int tin[N], tout[N], tim=0;
void dfs(int u, int depth=0){
tin[u] = ++tim;
d[depth].pb(tin[u]);
for(auto v: g[u]){
dfs(v, depth+1);
}
tout[u] = ++tim;
}
int32_t main()
{
IOS;
int n;
cin>>n;
for(int i=2;i<=n;i++){
int p;
cin>>p;
g[p].pb(i);
}
dfs(1);
w(T){
int u, k;
cin>>u>>k;
int l = tin[u], r = tout[u];
int ans = lower_bound(all(d[k]), r) - lower_bound(all(d[k]), l);
cout<<ans<<"\n";
}
}
// Written by abhidot |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 10;
int a[maxn];
int main()
{
int n, m, pos;
scanf("%d%d", &n, &m);
for(int i = 1; i <= n; ++i) { scanf("%d", &pos); a[pos] ^= 1;}
for(int i = 1; i <= m; ++i) { scanf("%d", &pos); a[pos] ^= 1;}
for(int i = 1; i < maxn; ++i) if(a[i]) printf("%d ", i);
return 0;
} | //Code By CXY07
#include<bits/stdc++.h>
using namespace std;
//#define FILE
#define int long long
#define debug(x) cout << #x << " = " << x << endl
#define file(FILENAME) freopen(FILENAME".in", "r", stdin), freopen(FILENAME".out", "w", stdout)
#define LINE() cout << "LINE = " << __LINE__ << endl
#define LL long long
#define ull unsigned long long
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define fst first
#define scd second
#define inv(x) qpow((x),mod - 2)
#define lowbit(x) ((x) & (-(x)))
#define vec vector
const int MAXN = 60;
const int INF = 2e9;
const double PI = acos(-1);
const double eps = 1e-6;
//const int mod = 1e9 + 7;
//const int mod = 998244353;
//const int G = 3;
//const int base = 131;
int n, m, x;
int a[MAXN], cnt[MAXN], prod[MAXN];
int dp[MAXN][2][2];
template<typename T> inline bool read(T &a) {
a = 0; char c = getchar(); int f = 1;
while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
while(c >= '0' && c <= '9') {a = a * 10 + (c ^ 48); c = getchar();}
a *= f;
return 1;
}
template<typename A, typename ...B>
inline bool read(A &x, B &...y) {return read(x) && read(y...);}
signed main () {
#ifdef FILE
freopen(".in","r",stdin);
freopen(".out","w",stdout);
#endif
read(n); read(x);
int tmpx = x;
for(int i = 1; i <= n; ++i) {
read(a[i]);
if(i != 1) prod[i - 1] = a[i] / a[i - 1];
}
prod[n] = INF;
for(int i = n; i >= 1; --i) {
cnt[i] = tmpx / a[i];
tmpx %= a[i];
}
dp[0][0][0] = 1;
for(int i = 1; i <= n; ++i) {//dp[i][j][k] 第i位放/不放 进位/不进位
if(prod[i] == cnt[i] + 1) {
dp[i][0][1] += dp[i - 1][0][1] + dp[i - 1][1][1];
dp[i][1][1] += dp[i - 1][1][0] + dp[i - 1][0][0];
dp[i][0][0] += dp[i - 1][0][0] + dp[i - 1][1][0];
} else {
dp[i][0][0] += dp[i - 1][1][0] + dp[i - 1][0][0];
dp[i][0][0] += dp[i - 1][1][1] + dp[i - 1][0][1];
if(cnt[i]) dp[i][1][1] += dp[i - 1][0][0] + dp[i - 1][1][0];
dp[i][1][1] += dp[i - 1][0][1] + dp[i - 1][1][1];
}
}
cout << dp[n][0][0] << endl;
return 0;
}
|
#include<bits/stdc++.h>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename temp>using ordered_set = tree<temp, null_type, less_equal<temp>, rb_tree_tag,tree_order_statistics_node_update>;
//order_of_key(k) : Number of items strictly smaller than k .
//find_by_order(k) : K-th element in a set (counting from zero).//*(ost.find_by_order(k))
#define PI acos(-1)
//int dx[]={-1,1,0,0};
//int dy[]={0,0,-1,1};
//int dx[]={-1,0,1,-1,1,-1,0,1};
//int dy[]={1,1,1,0,0,-1,-1,-1};
const int M=1e5+5;
const int N=2e5+5;
const int mod=1e9+7;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int a,b,c;
cin >> a >> b;
if(a == b)cout << a;
else cout << 3-a-b;
return 0;
}
| /*
Created on 19-12-20 15:05
@author: roastedcoder
*/
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
const int MOD = 1e9 + 7;
const int INF = INT_MAX;
const int MAX = 4e6 + 5;
const int N = 1e5 + 5;
//const int MAXX = 1e14;
#define ll long long
#define int ll
#define all(x) x.begin(), x.end()
#define endl "\n"
#define pb push_back
#define mp make_pair
#define roastedcoder ios_base::sync_with_stdio(false); cin.tie(NULL);
int dx[] = {-1, 0, 1, 0, -1, -1, 1, 1};
int dy[] = { 0, 1, 0, -1, -1, 1, 1, -1};
char dir[] = {'U','R','D','L'};
int power(int a, int b);
int powmod(int a, int b, int mod);
//__________________________________________________________________
//int main(){
int32_t main() {
roastedcoder
int n, w; cin>>n>>w;
cout<<n/w<<endl;
}
//__________________________________________________________________
/*
Sample Input:
Sample Output:
*/
// Template Functions
int power(int a, int b) {
int res = 1;
while(b>0) {
if(b%2) res *= a;
b /= 2, a *= a; } return res;
}
int powmod(int a, int b, int mod) {
int res = 1;
while(b>0) {
if(b%2) res = (res%mod * a%mod)%mod;
b /= 2;
a = (a%mod * a%mod)%mod;
}
return res%mod;
} |
#include <bits/stdc++.h>
#define MAXN 80
#define MAXM 1048576
using namespace std;
int P[20] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71};
map <int,long long> mp[MAXN];
int main()
{
long long A,B;
cin>>A>>B;
mp[0][0] = 1;
for(long long i = A;i <= B;i++)
{
int sta = 0;
for(int j=0;j<20;j++)
if(i % P[j] == 0)
sta += (1<<j);
for(auto x:mp[i-A])
{
mp[i-A+1][x.first] += x.second;
if((x.first & sta) == 0)
{
mp[i-A+1][x.first | sta] += x.second;
}
}
}
long long Ans = 0;
for(auto x : mp[B-A+1])
Ans += x.second;
cout<<Ans;
return 0;
} | //Challenge: Accepted
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#define ll long long
#define maxn 100005
#define pii pair<int, int>
#define ff first
#define ss second
using namespace std;
ll modpow(ll pow, ll mod) {
ll ret = 1, mult = 10;
while (pow) {
if (pow & 1) ret = (ret * mult) % mod;
mult = (mult * mult) % mod;
pow >>= 1;
}
return ret;
}
int main() {
ll n, m;
cin >> n >> m;
cout << modpow(n, m * m) / m << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
const string YES = "Yes";
const string NO = "No";
using ll = long long;
int main(){
int N;cin >> N;
vector<pair<int, int>> v1, v2;
for(int i = 0;i < N;i++){
int A, B;cin >> A >> B;
v1.push_back(make_pair(A, B));
}
for(int j = 0;j < N;j++){
int A, B;cin >> A >> B;
v2.push_back(make_pair(A, B));
}
sort(v1.begin(), v1.end());
static const double pi = 3.141592653589793;
for(long double theta = 0;theta < 360;theta += 0.01){
vector<pair<long double, long double>> p;
for(int i = 0;i < N;i++){
p.push_back(make_pair(cos(pi * theta / 180) * v2[i].first + -sin(pi * theta / 180) * v2[i].second, sin(pi * theta / 180) * v2[i].first + cos(pi * theta / 180) * v2[i].second));
}
sort(p.begin(), p.end());
vector<long double> X_diff, Y_diff;
for(int i = 0;i < N;i++){
X_diff.push_back(p[i].first - v1[i].first);
Y_diff.push_back(p[i].second - v1[i].second);
}
if(*max_element(X_diff.begin(), X_diff.end()) - *min_element(X_diff.begin(), X_diff.end()) <= 0.01 && *max_element(Y_diff.begin(), Y_diff.end()) - *min_element(Y_diff.begin(), Y_diff.end()) <= 0.01){
cout<<YES<<endl;
return 0;
}
}
cout<<NO<<endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)
template<class T1, class T2> inline bool chmax(T1 &a, const T2 &b) {if (a<b) { a=b; return 1;} return 0;}
template<class T1, class T2> inline bool chmin(T1 &a, const T2 &b) {if (b<a) { a=b; return 1;} return 0;}
struct init{init(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);cerr<<fixed<<setprecision(15);}}init_;
#ifdef DEBUG
template <class T> void verr(const set<T> &st) { repa(a, st) cerr << a << " "; cerr << endl; }
template <class S, class T> void verr(const map<S, T> &mp) { repa(a, mp) cerr << "{" << a.first << ", " << a.second << "} "; cerr << endl; }
template <class S, class T, class N> void verr(const vector<pair<S,T>>& a, const N& n) { rep(i, n) cerr << "{" << a[i].first << ", " << a[i].second << "} "; cerr << endl; }
template <class T, class N> void verr(const vector<T>& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << endl; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << endl; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif
const ll INF = 4e18;
const ld EPS = 1e-6;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
int main() {
ll N;
cin >> N;
vc<complex<ld>> S(N), T(N);
rep(i, N) {
ld a, b;
cin >> a >> b;
S[i] = {a, b};
}
rep(i, N) {
ld a, b;
cin >> a >> b;
T[i] = {a, b};
}
complex<ld> sc(0, 0), tc(0, 0);
rep(i, N) sc += S[i], tc += T[i];
sc /= N, tc /= N;
rep(i, N){
S[i] -= sc;
T[i] -= tc;
}
rep(i, N) rep(k, 2){
vc<complex<ld>> ss(N), tt(N);
rep(si, N) ss[si] = S[si] * polar(1.0L, -arg(S[k]));
rep(ti, N) tt[ti] = T[ti] * polar(1.0L, -arg(T[i]));
bool ok = true;
rep(si, N) {
bool isok = false;
rep(ti, N){
if (abs(ss[si] - tt[ti]) < EPS) isok = true;
}
if(!isok){
ok = false;
break;
}
}
if(ok){
cout << "Yes" << endl;
return 0;
}
}
cout << "No" << endl;
} |
#include <bits/stdc++.h>
//#define DEBUG
#define REP(i, nn ) for(int i = 0 ; i < (int) nn; i++)
#define deb(x) std::cout << #x << " " << x << endl;
#define debl(x) std::cout << #x << " " << x << " ";
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
template<typename... T>
void read(T& ... a){
((cin >> a),...);
}
template<typename... T>
void write(T... a){
((cout << a << "\n"),...);
}
template<typename... T>
void write_space(T... a){
((cout << a << " "),...);
}
void solve(){
ll n;
cin >> n;
ll ans = n + 1;
ll l = 1, r = 5e9;
while( l + 1 < r){
ll md = (l + r) / 2;
ll sum = md * (md + 1)/ 2;
if(sum == ans){
l = md;
cout << ans - l << endl;
return;
}else if ( sum > ans){
r = md - 1;
}else{
l = md;
}
}
if ( ans >= r * ( r + 1) / 2){
cout << ans - r << endl;
}else{
cout << ans - l << endl;
}
}
int main()
{
//making data IO Fast
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
/****************************/
solve();
return 0;
}
| #include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include <utility>
#include<functional>
#include<math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define REP(i,l,n) for(ll i=(l);i<(n);i++)
#define per(i,n) for(ll i=(n);i>0;i--)
#define pf(n) printf("%d\n",n)
#define pf_(a) printf("%d ",a);
#define all(v) begin(v),end(v)
typedef long long ll;
typedef vector<int> vi;
typedef pair<ll, ll> p;
const int INF = 1001001001;
const double PI = acos(-1);
const ll mod = 1000000007;
struct UnionFind {
vector<int> par;
UnionFind(int n) : par(n) {
rep(i, n) par[i] = i;
}
int root(int x) {
if (par[x] == x) return x;
return par[x] = root(par[x]);
}
void unite(int x, int y) {
int rx = root(x);
int ry = root(y);
if (rx == ry) return;
par[rx] = ry;
}
bool same(int x, int y) {
int rx = root(x);
int ry = root(y);
return rx == ry;
}
};
int main() {
ll n;
cin >> n;
ll a = n + 1;
ll i = 1;
ll cnt = 0;
while (a >= i) {
a -= i;
i++;
cnt++;
}
cout << n - cnt +1 << endl;
return 0;
} |
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define db double
#define pint pair<int,int>
#define mk make_pair
#define pb push_back
#define eb emplace_back
#define ins insert
#define fi first
#define se second
#define Rep(x,y,z) for(int x=y;x<=z;x++)
#define Red(x,y,z) for(int x=y;x>=z;x--)
using namespace std;
const int MAXN=2e5+5;
char buf[1<<12],*pp1=buf,*pp2=buf,nc;int ny;
//inline char gc() {return pp1==pp2&&(pp2=(pp1=buf)+fread(buf,1,1<<12,stdin),pp1==pp2)?EOF:*pp1++;}
inline char gc(){return getchar();}
inline int read(){
int x=0;ny=1;while(nc=gc(),(nc<48||nc>57)&&nc!=EOF)if(nc==45)ny=-1;if(nc<0)return nc;
x=nc-48;while(nc=gc(),47<nc&&nc<58&&nc!=EOF)x=(x<<3)+(x<<1)+(nc^48);return x*ny;
}
int n;char s[MAXN];
int main(){
// freopen("std.in","r",stdin);
// freopen("std.out","w",stdout);
for(int t=read();t--;){
n=read(),scanf("%s%s%s",s+1,s+1,s+1);
Rep(i,1,n)cout<<'0';Rep(i,1,n)cout<<'1';cout<<'0';puts("");
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
string a,b,c;
cin>>a>>b>>c;
for(int i=0;i<n;i++)
cout<<"0";
for(int i=0;i<n;i++)
cout<<"1";
cout<<"0\n";
}
}
|
// Murabito-B 21/04/12
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 100005;
int n, c[N], cnt[N];
bool good[N];
vector<int> to[N];
void dfs(int u, int fa) {
if (cnt[c[u]] == 0) good[u] = true;
cnt[c[u]]++;
for (int i = 0, v; i < to[u].size(); i++)
if ((v = to[u][i]) != fa) dfs(v, u);
cnt[c[u]]--;
}
void solve() {
cin >> n;
for (int i = 1; i <= n; ++i) cin >> c[i];
for (int i = 1, u, v; i < n; ++i) cin >> u >> v, to[u].push_back(v), to[v].push_back(u);
dfs(1, 0);
for (int i = 1; i <= n; ++i)
if (good[i]) cout << i << "\n";
}
int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
solve();
return 0;
} | #include <algorithm>
#include <array>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <vector>
using namespace std;
#define enviar {ios_base::sync_with_stdio(false);}
#define aiuda {cin.tie(NULL); cout.tie(NULL);}
#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) ;F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)
#define exacto(v) cout << setprecision(v) << fixed;
#define ll long long
#define lld long double
#define eb emplace_back
#define em emplace
#define ef emplace_front
#define f first
#define s second
#define big greater<ll>()
#define bpc(x) __builtin_popcount(x)
#define bpc2(x) __builtin_clz(x)
#define DIE(args...) {print(args); return;}
#define ar(v) array<int,v>
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x).size()
#define meminf(v) memset(v, 0x3f , sizeof(v))
#define mem(v,x) memset(v , x , sizeof v);
#define ai(a, n) for (int ele = 0; ele < n; ele++) cin >> a[ele];
#define ao(a, n) {for (int ele = 0; ele < (n); ele++) { if (ele) cout << " "; cout << a[ele]; } cout << '\n';}
#define readgraph(list, edges) for (int i = 0; i < edges; i++) {int n1, n2; cin >> n1 >> n2; n1--; n2--; list[n1].eb(n2); list[n2].eb(n1);}
template <typename T>
struct combinator {
T t_;
combinator(T&& t) : t_(std::forward<T>(t)) {}
template <typename... Args>
auto operator () (Args&&... args) const
{
return t_(*this, std::forward<Args>(args)...);
}
};
template<class T> bool umin(T& a, const T& b) { return b<a?a=b, 1:0; }
template<class T> bool umax(T& a, const T& b) { return a<b?a=b, 1:0; }
string to_string(bool b) {return b?"true":"false"; }
string to_string(char c) { return string(1, c);}
string to_string(const char* s) { return string(s); }
string to_string(string s) { return s; }
template<class T> string to_string(T v) { bool f=1; string res; EACH(x, v) { if(!f) res+=' '; f=0; res+=to_string(x); } return res; }
template<class A> void write(A x) { cout << to_string(x); }
void print() { write("\n"); }
template<class H, class... T> void print(const H& h, const T&... t) { write(h); if(sizeof...(t)) write(' '); print(t...); }
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef map<ll, ll> mll;
typedef priority_queue<int, std::vector<int>, std::greater<int>> priomin;
const ll mod = 998244353;
const ll maxsize =3e5 + 10;
const ll inf = 0x3f3f3f3f3f3f3f3f ;
// size, caracter
ll c[maxsize];
bool sieve[100];
vll primes(100);
ll m;
void solve()
{
ll n ; cin >> n;
string s, t;
cin >> s >> t;
set <ll> st;
reverse(all(t));
reverse(all(s));
st.em(0);
// 2 3 4 6 8
// 1
// 2
// 3
FOR(i , n)
{
set<ll> nst;
if (t[i] == 'A')
{
FOR(j , 7)
{
ll a = (j*10 + (s[i] - '0') )% 7;
ll b = (j*10) % 7 ;
if ( st.count(a) && st.count(b))
{
nst.em(j);
}
}
}
else
{
FOR(j , 7)
{
ll a = (j*10 + (s[i] - '0') )% 7;
ll b = (j*10) % 7 ;
if ( st.count(a) || st.count(b))
{
nst.em(j);
}
}
}
st = nst;
}
//for(ll i : st)
//{
//print(i);
//}
if (st.count(0)) print("Takahashi");
else print("Aoki");
}
int main(){
enviar aiuda
int tc = 1;
//cin >> tc;
while(tc--) solve();
return 0;
}
|
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;
#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int main(){
ll N;
cin>>N;
ll N1=0,N2=0,N3=0;
v a(2*N);
ll ev;
vector<char> c(2*N);
rep(i,0,2*N){
cin>>a[i]>>c[i];
if(c[i] == 'R')N1++;
if(c[i] == 'G')N2++;
if(c[i] == 'B')N3++;
}
if(N1 %2 == 0 && N2 %2 == 0 && N3 %2 == 0){
cout<<0;
return 0;
}
ll r=1,g=2,b=3;
if(N1%2 == 0)ev = 1;
if(N2%2 == 0){g=1;r=2;swap(N1,N2);}
if(N3%2 == 0){r=3;b=1;swap(N1,N3);}
vector<pair<ll,ll>> Arg;
vector<pair<ll,ll>> Arb;
vector<pair<ll,ll>> Agb;
rep(i,0,2*N){
pair<ll,ll> tmp;
tmp.first = a[i];
ll d;
if(c[i] == 'R')d=r;
if(c[i] == 'G')d=g;
if(c[i] == 'B')d=b;
tmp.second = d;
if(d==1){Arg.push_back(tmp);Arb.push_back(tmp);}
if(d==3){Arb.push_back(tmp);Agb.push_back(tmp);}
if(d==2){Arg.push_back(tmp);Agb.push_back(tmp);}
}
ll rg = 1,gb=2,br=3;
sort(all(Arg));
sort(all(Arb));
sort(all(Agb));
vector<pair<ll,ll>> drg;
vector<pair<ll,ll>> dgb;
vector<pair<ll,ll>> drb;
ll Nr;
Nr = 0;
rep(i,0,Arg.size()){
if(i==0 && Arg[i].second == 1)Nr++;
if(Arg[i+1].second == 1)Nr++;
if(Arg[i].second == Arg[i+1].second)continue;
drg.emplace_back(abs(Arg[i].first-Arg[i+1].first),Nr);
}
Nr = 0;
rep(i,0,Arb.size()){
if(i==0 && Arb[i].second == 1)Nr++;
if(Arb[i+1].second == 1)Nr++;
if(Arb[i].second == Arb[i+1].second)continue;
drb.emplace_back(abs(Arb[i].first-Arb[i+1].first),Nr);
}
rep(i,0,Agb.size()){
if(Agb[i].second == Agb[i+1].second)continue;
dgb.emplace_back(abs(Agb[i].first-Agb[i+1].first),Nr);
}
sort(all(drg));
sort(all(dgb));
sort(all(drb));
ll rr;
if(drg[0].second == drb[0].second){
if(drg[0].second == drb[1].second && drg[1].second == drb[0].second){
rr = min(drg[0].first + drb[2].first,drg[2].first + drb[0].first);
}
else if(drg[0].second == drb[1].second){
rr = min(drg[0].first + drb[2].first,drg[1].first + drb[0].first);
}
else if(drg[1].second == drb[0].second){
rr = min(drg[1].first + drb[0].first,drg[0].first + drb[2].first);
}
else{
rr = min(drg[0].first + drb[1].first,drg[1].first + drb[0].first);
}
}
else{
rr = drg[0].first + drb[0].first;
}
rr = min(rr,dgb[0].first);
cout<<rr;
return 0;
} | //Generated at 2020-10-03 20:08:03 UTC+8
//Created by Alphagocc
#include<bits/stdc++.h>
#ifdef USE_PBDS
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/priority_queue.hpp>
#endif
using namespace std;
#define FI __inline__ __attribute__((always_inline))
#define TN typename
#define TP template
#define TS *this
class IO{static const int bufSize=1<<18;char inBuf[bufSize],outBuf[bufSize];char*ip1=inBuf,*ip2=inBuf;int ok=1,op1=-1,op2=bufSize-1;
TP <TN T>FI void __RI(T&x){int ch=gc(),neg=1;x=0;for(;!(ch==EOF||isdigit(ch)||ch=='-');ch=gc());if(ch==EOF){ok=0;return;}if(ch=='-')neg=-1,ch=gc();for(;isdigit(ch);ch=gc())x=x*10+(ch-48)*neg;}
TP <TN T>FI void __RC(T&x){unsigned char ch;while(isspace(ch=gc()));if(ch==EOF){ok=0;return;}x=ch;}FI void __RS(string&x){char ch;x.clear();for(ch=gc();isspace(ch);ch=gc());if(ch==EOF){ok=0;return;}for(;!isspace(ch);ch=gc())x.push_back(ch);}
public:
FI int gc(){return ip1==ip2 &&(ip2 =(ip1=inBuf)+fread(inBuf,1,bufSize,stdin),ip1==ip2)?EOF:*ip1++;}
FI IO&R(char&x){__RC(x);return TS;}FI IO& R(unsigned char&x){__RC(x);return TS;}FI IO&R(string&x){__RS(x);return TS;}TP<TN T1,TN T2>FI IO&R(pair<T1,T2>&x){R(x.first),R(x.second);return TS;}TP<TN T>FI IO&R(vector<T>&x){for(auto &i:x)R(i);return TS;}
TP <TN T,TN...Args>FI IO&RA(T*a,int n){for(int i=0;i<n;++i)R(a[i]);return TS;}TP<TN T,TN...Args>FI IO&R(T&x,Args&...args){R(x),R(args...);return TS;}
TP <TN T,TN...Args>FI IO&RA(T*a,int n,Args...args){for(int i=0;i<n;++i)RA(a[i],args...);return TS;}TP<TN T>FI IO&R(T&x){static_assert(is_integral<T>::value,"Unsupported types");if(is_integral<T>::value)__RI(x);return TS;}
private:
char space=' ';TP<TN T>FI void __WI(T x){static char buf[64];static int len=-1;if(x>=0){do{buf[++len]=x%10+48,x/=10;}while(x);}else{pc('-');do{buf[++len]=-(x%10)+48,x/=10;}while(x);}while(len>=0){pc(buf[len]),--len;}}
public:
FI void pc(const char&x){if(op1==op2)flush();outBuf[++op1]=x;}
FI void flush(){fwrite(outBuf,1,op1+1,stdout),op1=-1;}FI IO&W(const char&x){pc(x);return TS;}FI IO&W(const char*x){while(*x!='\0')pc(*(x++));return TS;}FI IO&W(const string&x){W(x.c_str());return TS;}
TP<TN T>FI IO& W(const vector<T>&x){for(auto&i:x)WS(i);WL();return TS;}FI IO&WL(){W('\n');return TS;}TP<TN T1,TN T2>FI IO& W(const pair<T1,T2>&x){WS(x.first),W(x.second);return TS;}
TP<TN T>FI IO& WL(const T&x){W(x),W('\n');return TS;}FI IO&WS(){W(' ');return TS;}TP<TN T>FI IO& WS(const T&x){W(x),W(space);return TS;}
TP<TN T>FI IO& WA(T* a,int n){for(int i=0;i<n;i++)WS(a[i]);WL();return TS;}TP<TN T,TN...Args>FI IO& W(const T&x,const Args&...args){W(x),W(space),W(args...);return TS;}
TP<TN...Args>FI IO& WL(const Args&...args){W(args...),W('\n');return TS;}TP<TN T,TN...Args>FI IO& WA(T* a,int n,Args...args){for(int i=0;i<n;i++)WA(a[i],args...);return TS;}
TP<TN T>FI IO& W(const T&x){static_assert(is_integral<T>::value,"Unsupported types");if(is_integral<T>::value)__WI(x);return TS;}
TP<TN T>FI IO&operator>>(T&x){R(x);return TS;}TP<TN T>FI IO&operator<<(const T&x){W(x);return TS;}bool good(){return ok;}IO(){}~IO(){flush();}}io;
#undef TN
#undef TP
#undef FI
#undef TS
#define REP(i,x,y)for(int i=x;i<y;i++)
#define ALL(x)x.begin(),x.end()
const int32_t INF=0x3f3f3f3f;
const int64_t INFL=0x3f3f3f3f3f3f3f3fLL;
int main()
{
int n;
io >> n;
vector<char> s(n);
io >> s;
int ans = 0;
for (int i = 0; i < n; i++) {
int a, t, g, c;
a = t = g = c = 0;
for (int j = i; j < n; j++) {
switch (s[j]) {
case 'A': a++; break;
case 'T': t++; break;
case 'G': g++; break;
case 'C': c++; break;
default: break;
}
// io.WL(a, t, g, c);
if (a == t && g == c) ans++;
}
}
io.WL(ans);
return 0;
} |
#include <bits/stdc++.h>
//#include <atcoder/modint>
//#include <atcoder/math>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPP(i, n) for(int i = 1; i <= n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
long long c = a % i_7;
if(c >= 0) return c;
return c + i_7;
}
long long po(long a, long b){
if(b == 0) return 1;
long long z = po(a , b / 2);
z = mod(z * z);
if(b % 2 != 0) z = mod(a * z);
return z;
}
bool prime_(int n){
if(n == 1){
return false;
}else if(n == 2){
return true;
}else{
for(int i = 2; i <= std::sqrt(n); i++) if(n % i == 0) return false;
return true;
}
}
long long gcd_(long long a, long long b){
if(a < b) std::swap(a,b);
if(a % b == 0) return b;
else return gcd_(b, a % b);
}
long long lcm_(long long x, long long y){
return (x / gcd_(x,y)) * y;
}
using namespace std;
//using namespace atcoder;
//using mint = modint1000000007;
//using mint = modint998244353;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;
// Binary Indexed Tree (Fenwick Tree)
template<typename T> // T: type of cost
struct BIT {
int n;
std::vector<T> d;
BIT(int n=0):n(n),d(n+1) {}
//配列のインデックスiの要素d[i]に対して、xを加算する。
void add(int i, T x=1) {
for (i++; i <= n; i += i&-i) {
d[i] += x;
}
}
//配列においてインデックスがi以下の要素d[j]たちの和を計算して返す。
T sum(int i) {
if(i < 0) return 0;
T x = 0;
for (i++; i; i -= i&-i) {
x += d[i];
}
return x;
}
};
int main(){
//using namespace std;
int n;
cin>>n;
vector<long long> a(n);
REP(i, n) cin>>a[i];
BIT<long long> bt(n);
vector<long long> ans(n, 0);
REP(i, n){
ans[0] += bt.sum(n - 1) - bt.sum(a[i]);
bt.add(a[i]);
}
for(int k = 1; k < n; k++){
bt.add(a[k - 1], -1);
ans[k] = ans[k - 1];
ans[k] -= bt.sum(a[k - 1] - 1);
ans[k] += bt.sum(n - 1) - bt.sum(a[k - 1]);
bt.add(a[k - 1]);
}
REP(i, n) cout << ans[i] << endl;
return 0;
} | #include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <stack>
#include <cassert>
#include <map>
#include <numeric>
#include <cstring>
#include <set>
#include <ctime>
#include <queue>
#include <cmath>
#include <iomanip>
#include <iterator>
using namespace std;
clock_t timeStart, timeFinish;
void timeBegin() {
timeStart = clock();
}
void timeEnd() {
timeFinish = clock();
}
void timeDuration() {
timeEnd();
double time_taken = double(timeFinish - timeStart) / double(CLOCKS_PER_SEC);
cout << "Time taken by program is : " << fixed << time_taken << setprecision(5);
cout << " sec " << endl;
}
class InputReader {
public:
InputReader() {
input_file = stdin;
cursor = 0;
fread(buffer, SIZE, 1, input_file);
}
InputReader(const char *file_name) {
input_file = fopen(file_name, "r");
cursor = 0;
fread(buffer, SIZE, 1, input_file);
}
inline InputReader &operator >>(int &n) {
while((buffer[cursor] < '0' || buffer[cursor] > '9') && buffer[cursor] != '-') {
advance();
}
int sign = 1;
if (buffer[cursor] == '-') {
sign = -1;
advance();
}
n = 0;
while('0' <= buffer[cursor] && buffer[cursor] <= '9') {
n = n * 10 + buffer[cursor] - '0';
advance();
}
n *= sign;
return *this;
}
private:
FILE *input_file;
static const int SIZE = 1 << 17;
int cursor;
char buffer[SIZE];
inline void advance() {
++ cursor;
if(cursor == SIZE) {
cursor = 0;
fread(buffer, SIZE, 1, input_file);
}
}
};
int main() {
timeBegin();
//ifstream cin("input.in");
//ofstream cout("abbreviation.out");
int n, m, parity[2];
parity[0] = parity[1] = 0;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
string s;
cin >> s;
int ones = 0;
for (int j = 0; j < m; j++) {
if (s[j] == '1') {
ones ^= 1;
}
}
parity[ones]++;
}
cout << 1LL * parity[0] * parity[1] << "\n";
//timeDuration();
return 0;
}
|
/*
Author-> Codie_1(Akash)
*/
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(n) for(int i=0;i<n;i++)
#define repi(n) for(int i=0;i<n;i++)
#define repj(n) for(int j=0;j<n;j++)
#define repp(n) for(int i=0;i<=n;i++)
#define repab(a,b) for(int i=a;i<b;i++)
#define w(t) int t; cin>>t; while(t--)
#define endl '\n'
#define pi pair<int, int> p
#define pis pair<int, string> p
#define ff first
#define ss second
#define pb push_back
#define mk make_pair
#define vi vector<int> v
#define vl vector<long long> v;
typedef long long ll;
int main()
{
int n,k,m;
cin>>n>>k>>m;
int l=n-1;
int avg=0;
while(l--)
{
int x;
cin>>x;
avg+=x;
}
// cout<<avg/(n-1)<<endl;
int g=(n*m)-avg;
if(g<=0)
cout<<0;
else if(g<=k)
cout<<g;
else
cout<<-1;
return 0;
} | #include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <string>
#include <list>
#include <cassert>
#include <numeric>
#include <cstdint>
#include <queue>
#include <deque>
using ll = long long;
using ld = long double;
using namespace std;
using Graph = vector<vector<int>>;
// typedef pair<int,int> P;
#define teisu 1000000007
#define MAX_WIDTH 60
#define MAX_HEIGHT 60
#define INF 1e9
// int N;
// string S;
// map<int,int> cnt;
// map<char,vector<int>> keep_index;
// ll X,Y,A,B;
// ll ans = 0;
// ll dfs(ll strength,ll keikenti){
// if(strength >= Y) return 0;
// ans = max(ans,keikenti);
// cout << strength << endl;
// // cout << ans << endl;
// dfs(strength*A,keikenti+1);
// dfs(strength+B,keikenti+1);
// return 0;
// }
double N,D,H,d[110],h[110];
int main(){
cin >> N >> D >> H;
for(int i=0;i<N;i++){
cin >> d[i] >> h[i];
}
double ans = 0.000000;
for(int i=0;i<N;i++){
double calc = h[i] - (((H-h[i])*d[i])/(D-d[i]));
ans = max(ans,calc);
}
// cout << ans << endl;
ans = min(1000.0000,ans);
printf("%.15lf\n",ans);
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
int n,q;
const ll inf=1e18;
ll a[maxn],delta[maxn],sum[maxn],k;
int main()
{
scanf("%d%d",&n,&q);
for(int i=1;i<=n;i++)
{
scanf("%lld",&a[i]);
delta[i-1]=a[i]-a[i-1]-1;
}
delta[n]=inf;
sum[0]=delta[0];
for(int i=1;i<=n;i++) sum[i]=sum[i-1]+delta[i];
for(int i=1;i<=q;i++)
{
scanf("%lld",&k);
if(a[1]>k){ printf("%lld\n",k); continue;}
int pos=lower_bound(sum,sum+n+1,k)-sum;
printf("%lld\n",a[pos]+k-sum[pos-1]);
}
return 0;
} | #include "bits/stdc++.h"
using namespace std;
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>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sor(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define pb push_back
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
//const int INF = 1123456789;
//const int mod = 1e9+7;
//const int mod=998244353;
int main(){
int n,q; cin>>n>>q;
vll a(n); rep(i,n) cin>>a[i];
sor(a);
vll v=a;
rep(i,n) v[i]+=i;
/*rep(i,q){
ll k; cin>>k;
auto itr=upper_bound(v.begin(),v.end(),k);
if(itr==v.begin()) {cout<<k<<endl; continue;}
itr--;
cout<<*itr+k+a[itr-v.begin()]-1;
}*/
vector<pair<ll,int>> k(q);
rep(i,q) {
ll K; cin>>K;
k[i]={K,i};
}
vll ans(q);
sor(k);
int m=0;
rep(i,q){
ll an=k[i].first+m;
while(true){
if(m<n&&a[m]<=an) {m++;an++;}
else break;
}
ans[k[i].second]=an;
}
rep(i,q) cout<<ans[i]<<endl;
}
|
#include <iostream>
using namespace std;
int main(int argc, char** argv) {
int n,a[1005],b[1005];
cin>>n;
int mmin1=1e5+1,mmin2=1e5+1;
int _mmin1,_mmin2;
for(int i=1;i<=n;i++)
{ cin>>a[i]>>b[i];
if(a[i]<mmin1)
{ mmin1=a[i];_mmin1=i;
}
if(b[i]<mmin2)
{ mmin2=b[i];_mmin2=i;
}
}
if(_mmin1==_mmin2)
{ int x=mmin1+mmin2;
int ___mmin2=1e5+1;
for(int i=1;i<=n;i++)
{ if(b[i]<___mmin2&&i!=_mmin2)
{ ___mmin2=b[i];
}
}
int y=max(mmin1,___mmin2);
int ___mmin1=1e5+1;
for(int i=1;i<=n;i++)
{ if(a[i]<___mmin1&&i!=_mmin1)
{ ___mmin1=a[i];
}
}
int z=max(___mmin1,mmin2);
cout<<min(min(x,y),z);
}
else
cout<<max(mmin1,mmin2);
return 0;
} | #pragma region header
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define int ll
#define each(i, a) for (auto &&i : (a))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using vvs = vector<vs>;
using vd = vector<ld>;
using vvd = vector<vd>;
using vb = vector<bool>;
using vvb = vector<vb>;
using P = pair<int, int>;
using vp = vector<P>;
using int128 = __int128_t;//cin coutはできない
template <class T>
using greater_queue = priority_queue<T, vector<T>, greater<T>>;
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 dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
template <class T>
void CVEC(const T &v) {
int c = v.size() - 1;
for (int i = 0; i < c; i++) cout << v[i] << ' ';
if (c > -1) cout << v[c];
cout << '\n';
}
#pragma endregion header
int XMAX = 10000;
int YMAX = 10000;
struct Rectangle{
int a, b, c, d;
};
struct Point{
int id, x, y, r;
};
void COUT(Rectangle x){
cout << x.a << " " << x.b << " " << x.c << " " << x.d << endl;
}
set<P> occupied;
signed main(){
int n; cin >> n;
vector<Point> Ps;
map<int, Rectangle> ans;
rep(i,n){
int x, y, r; cin >> x >> y >> r;
Ps.push_back({i, x, y, r});
}
sort(ALL(Ps), [](Point a, Point b){return a.r > b.r;});
/*
rep(i,n){
int a = Ps[i].x;//x
int b = Ps[i].y;//y
int r = Ps[i].r;
cout << a << " " << b << " " << r << endl;
}
*/
int x = Ps[0].x;//x
int y = Ps[0].y;//y
int id = Ps[0].id;
int r = Ps[0].r;
int hen = (int)sqrt(r);
//cout << hen << endl;
ans[id] = {x, y, min(x + hen, XMAX), min(YMAX, y + hen)};
rep(i,n){
if(i == id) continue;
ans[i] = {i, 0, i+1, 1};
}
rep(i,n){
COUT(ans[i]);
}
} |
/*
Author: Nguyen Tan Bao
Status:
Idea:
*/
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x
using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;
const ll MODBASE = 1000000007LL;
const int MAXN = 1010;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;
int n, m, a[MAXN], b[MAXN], dp[MAXN][MAXN];
int main() {
ios::sync_with_stdio(0);
cin.tie(nullptr);
cin >> n >> m;
FOR(i,1,n) cin >> a[i];
FOR(i,1,m) cin >> b[i];
dp[n+1][m+1] = 0;
FOR(i,1,n) dp[i][m+1] = n-i+1;
FOR(j,1,m) dp[n+1][j] = m-j+1;
FORE(i,n,1)
FORE(j,m,1) {
dp[i][j] = dp[i+1][j+1] + (a[i] != b[j]);
dp[i][j] = min(dp[i][j], dp[i+1][j] + 1);
dp[i][j] = min(dp[i][j], dp[i][j+1] + 1);
}
int res = n + m;
FOR(i,1,n)
FOR(j,1,m) res = min(res, dp[i][j] + i-1 + j-1);
cout << res;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define ull unsigned long long
#define pi 3.141592653589793238
#define lb lower_bound
#define ub upper_bound
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define For(i,a,n) for(ll i=a;i<=n;i++)
const ll inf = 100000000000000000;
const ll mod = 1000000007;
const ll N=2e5+1;
typedef pair<int, int> pii;
typedef pair<ll , ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ull> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
bool ispalin(string s){ ll len=s.length(); rep(i , 0 , len){ if(s[i] != s[len-i-1]) {return false;}} return true;}
ll add(ll a , ll b , ll m){ ll res = (a%m+b%m)%m; if(res<0) {res+=m;} return res;}
ll mul(ll a , ll b , ll m){ ll res = (a%m*b%m)%m; if(res<0) {res+=m;} return res;}
ll power(ll a , ll b , ll m){ ll res = 1; while (b > 0) { if (b & 1) {res = mul(res,a,m);} a = mul(a , a , m); b >>= 1;} return res%m; }
ll binpow(ll a , ll b) { ll res = 1; while (b > 0) { if (b & 1) {res = (res*a);} a = (a*a); b >>= 1; } return res; }
ll binpow(ll a , ll b , ll m) { ll res = 1; while (b > 0) { if (b & 1) {res = (res*a)%m;} a = (a*a)%m; b >>= 1; } return res%m; }
bool isprime(ll n){ if (n <= 1) {return false;} if (n <= 3) {return true;} if (n%2 == 0 || n%3 == 0) {return false;} for (ll i=5; i*i<=n; i=i+6){ if (n%i == 0 || n%(i+2) == 0) {return false;}} return true; }
/// bool isprime(ll n){ int x=rand(); ll int y; y=pow((x-1),n)-pow(x,n)+1; if(y%n==0) {return true;} else {return false;} }
/// for 1 to n prime numbers .....see down code
/// bool isprime[n+1]; for(i=0;i<=n;i++) {isprime[i]=true;} isprime[0]=false; isprime[1]=false; for(i=0;i<=n;i++) { if(isprime[i] == true) { count++; for(j=i*i;j<=n;j+=i) {isprime[j]=false;} } }
ll gcd(ll a , ll b) { if(b==0) {return a;} else {gcd(b,a%b);} }
ll lcm(ll a , ll b) { ll l = (a*b)/gcd(a,b); return l; }
ll CEIL(ll a, ll b) { return (a/b+(a%b!=0));}
ll inv (ll a , ll m){ return power(a,m-2,m);}
ll C(ll n, ll r) {
if(n<r) return 0;
if(n==r) return 1;
if(r > n-r) r = n-r; // because C(n, r) == C(n, n - r)
ll ans = 1;
for(ll i = 1; i <= r; i++) {
ans *= n - r + i;
ans /= i;
}
return ans;
}
bool isPowerOfTwo(int x){ return x && (!(x & (x - 1)));}
bool isPerfectSq(ll x){ if (x >= 0) { ll sr = sqrt(x); return (sr * sr == x); } return false; }
ll fact(ll n , ll m){ ll f = 1; for(ll i=1;i<=n;i++) f = (f * i)%m; return f%m;}
/* combinatorics .. */
// for getting max power of K that divides n!
ll fact_pow (ll n, ll k) { ll res = 0; while (n) { n /= k; res += n;} return res; }
void solve()
{
ll x , y;
cin>>x>>y;
if(x == y) cout<<x;
else
{
if(x == 0 && y == 1 || y == 0 && x == 1) cout<<"2";
else if(x == 0 && y == 2 || x == 2 && y == 0) cout<<"1";
else cout<<"0";
}
}
int main() {
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
solve();
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
using ll = long long;
//<< fixed << setprecision(n) 小数第n位まで表示
int main() {
int N;
cin >> N;
cout << N - 1 << endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define LL long long
int main() {
ios::sync_with_stdio(0), cin.tie(0);
string s, t = ""; cin >> s; bool ok = 1;
deque<char> q;
for(char c : s) {
if(c == 'R') ok = 1 - ok;
else {
if(ok) {
if(q.size() && q.back() == c) {
q.pop_back();
continue;
}
q.push_back(c);
}
else {
if(q.size() && q.front() == c) {
q.pop_front();
continue;
}
q.push_front(c);
}
}
}
for(char c : q) t += c;
if(!ok) reverse(t.begin(), t.end());
cout << t << '\n';
} |
/* TAHMID RAHMAN
DAMIAN FOREVER
MATH LOVER
NEVER GIVE UP
*/
#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define pb push_back
#define fi first
#define se second
#define in insert
#define mp make_pair
#define GCD(a,b) __gcd(a,b);
#define endl "\n"
#define FRU freopen("out.txt","w",stdout)
#define FRO freopen("in.txt","r",stdin)
#define INFLL 9223372036854775807
#define debug 0
#define MAXN 100001
#define ar array
#define lb lower_bound
#define ub upper_bound
const int mxN=2e5;
const int MOD=1e9+7;
template<typename ForwardIterator, typename T>
ForwardIterator first_less_than (ForwardIterator first, ForwardIterator last, T value)
{auto it = std::lower_bound (first, last, value);
return (it == first ? last : --it);}
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b)
{
return (a.second < b.second);
}
#define debugxx(v) {for(auto x:v){cout<<x.fi<<" "<<x.se<<endl;}cout<<endl;}
#define debugx(v){for(auto y:v) {cout<<y<<" ";}cout<<endl;}
//Don't hesitate to ask me if you don't understand my code.......Happy coding,Tahmid...;
bool prime[15000000];
vector<ll>prime_list;
void seive_prime(ll n)
{
ll i,j;
for(i=0; i<=n; i++)
prime[i]=true;
for(i=2; i*i<=n; i++)
{
if(prime[i]==true)
{
for(j=i*i; j<=n; j+=i)
prime[j]=false;
}
}
prime[1]=0;
prime[0]=0;
}
void gen_prime(ll n)
{
seive_prime(n);
for(ll i=0; i<=n; i++)
if(prime[i])
prime_list.pb(i);
}
set<ll> prime_fac(ll n)
{
set<ll>factors;
for(ll i=0;prime_list[i]*prime_list[i]<=n&&i<prime_list.size();i++)
{
if(n%prime_list[i]==0)
{
while(n%prime_list[i]==0)
{
n/=prime_list[i];
factors.in(prime_list[i]);
}
}
}
if(n>1)
factors.in(n);
return factors;
}
int main()
{
fastio;
ll t;
gen_prime(1010);
t=1;
//cin>>t;
while(t--)
{
ll n,i;
cin>>n;
vector<ll>v(n);
for(i=0;i<n;i++)
cin>>v[i];
map<ll,ll>m;
for(i=0;i<n;i++)
{
set<ll>fact=prime_fac(v[i]);
for(auto x:fact)
{
m[x]++;
}
fact.clear();
}
ll maxs=-1,ans=-1;
for(auto x:m)
{
if(x.se>maxs){
ans=x.fi;
maxs=x.se;
}
}
cout<<ans<<endl;
}
}
| #include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
#define REP(i, n) for(ll i = 0; i < n; i++)
int main(){
ll n;
cin >> n;
vector<ll> a(n);
REP(i, n){
cin >> a[i];
}
ll mx = 0, ans = 0;
for(ll k = 2; k <= 1000; k++){
ll cnt = 0;
REP(i, n){
if(a[i] % k == 0) cnt++;
}
if(mx < cnt){
mx = cnt;
ans = k;
}
}
cout << ans << endl;
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> P;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1001001001;
int main()
{
int n, m;
cin >> n >> m;
vb masu(n);
rep(i, m) {
int a;
cin >> a;
--a;
masu[a] = true;
}
int x = INF;
int t = 0;
vi v;
rep(i, n) {
if(masu[i] == false) t++;
else if(t > 0) {
x = min(x, t);
v.push_back(t);
t = 0;
}
}
v.push_back(t);
int ans = 0;
for(int i : v) {
//cout << i << endl;
if(i%x==0) ans += (i/x);
else ans += (i/x)+1;
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int64_t n, m, k = 0, ans = 0;
cin >> n >> m;
vector<int64_t> a(m);
map<int64_t, int> s;
for (auto i = 0; i < m; i++) cin >> a[i], a[i];
sort(a.begin(), a.end());
if (m == n) {
cout << 0 << endl;
return 0;
}
if (m == 0) {
cout << 1 << endl;
return 0;
}
for (auto i = 0; i < m - 1; i++)
s[a[i + 1] - a[i] - 1]++;
if (a.front() != 1) s[a.front() - 1]++;
if (a.back() != n) s[n - a.back()]++;
for (auto& elm : s) {
if (elm.first == 0) continue;
if (k == 0) k = elm.first, ans += elm.second;
else
ans += (elm.first / k +
((elm.first % k) ? 1 : 0)) *
elm.second;
}
cout << ans << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1e9 + 7;
const int N = 3e5 + 10;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
cout << setprecision(12) << fixed ;
vector<int>v(n);
for (int i = 0;i < n;i++){
cin >> v[i];
}
int m = 0;
long double a = 0;
int rr = 0;
for(auto s : v){
m += abs(s);
a += s*s;
rr = max(rr,abs(s));
}
a = sqrt(a);
cout << m << "\n" << a << "\n" << rr;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int i,j,k,n;
pair <int,int> a[400010];
int b[400010];
cin>>n;
for(i=0;i<2*n;i++) {
cin>>k;
a[i]=make_pair(k,i);
}
sort(a,a+2*n);
for(i=0;i<n;i++) {
b[a[i].second]=-1;
}
for(i=n;i<2*n;i++) {
b[a[i].second]=1;
}
i=0;
while(i<2*n) {
k=b[i];
j=b[i];
cout<<'(';
while(i<2*n&&k!=0) {
i++;
if (b[i]*j==1) {
cout<<'(';
}
else {
cout<<')';
}
k+=b[i];
}
i++;
}
return 0;
} |
/* (
( ) (
) )
||||||| ( ( (
( O O ) )
____oOO___(_)___OOo____(
(_______________________)
JOINT ░█─░█ ░█▀▀▀ ▀█▀ ░█▀▀▀█ ░█▀▀▀ ░█▄─░█ ░█▀▀█ ░█▀▀▀ ░█▀▀█ ░█▀▀█ █ ░█▀▀▀█ ░█▀▀█ ░█▀▀▀█ ░█▀▀▄ ░█▀▀▀
░█▀▀█ ░█▀▀▀ ░█─ ─▀▀▀▄▄ ░█▀▀▀ ░█░█░█ ░█▀▀▄ ░█▀▀▀ ░█▄▄▀ ░█─▄▄ ─ ─▀▀▀▄▄ ░█─── ░█──░█ ░█─░█ ░█▀▀▀
░█─░█ ░█▄▄▄ ▄█▄ ░█▄▄▄█ ░█▄▄▄ ░█──▀█ ░█▄▄█ ░█▄▄▄ ░█─░█ ░█▄▄█ ─ ░█▄▄▄█ ░█▄▄█ ░█▄▄▄█ ░█▄▄▀ ░█▄▄▄*/
#include<bits/stdc++.h>
using namespace std;
// Ordered Set
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
#define os_find(k) find_by_order(k)
#define os_order(k) order_of_key(k)*/
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef vector<int> vi;
#define loop(i,a,b) for(int i=a;i<b;i++)
#define loop1(i,a,b) for(int i=a;i<=b;i++)
#define rloop(i,a,b) for(int i=a;i>b;i--)
#define rloop1(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define int long long
#define ff first
#define ss second
#define ncr(n,r) fact[n]*modInv(fact[r])*modInv(fact[n-r])
#define MOD 1000000007
#define modInv(a) binExp(a,mod-2)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define test int t;cin>>t;while(t--)
//#define a^b=a+b-2*(a&b)
//POWER FUNCTION FOR LARGE NO.
//ll M=1000000007LL,fact[100010];
ll power(ll a, ll b, ll mod){
ll x = 1LL, y = a;
while (b > 0LL){
if (b%2LL){
x = (x*y);
if(x>mod) x%=mod;
}
y = (y*y);
if(y>mod) y%=mod;
b /= 2LL;
}
return x;
}
/*
EULER'S FUNCTION FOR TAKING COMBINATION OF LARGE NO.
ll mod_inv(ll n, ll mod){
return power(n, mod-2LL, mod);
}
ll nCr(ll n, ll k, ll mod){
return (fact[n]* ((mod_inv(fact[k],mod)*mod_inv(fact[n-k],mod))%mod) )%mod;
}
fact[0]=1LL;
for(ll i=1LL;i<=100005LL;i++)
{
fact[i]=(fact[i-1]*i)%M;
}*/
//pass by value increases the time complexity if you continuosly pass array or string in function it will give time complexity
//___________________(⌐⊙_⊙)__________<CHAL GURU HOJA SHURU >__________(⊙_⊙⌐)______________________________________________
signed main()
{
int arr[4],s=0,f=0,s1=0;
loop(i,0,4){cin>>arr[i];s+=arr[i];}
loop(i,1,pow(2,4)-1){
//cout<<i<<" ";
s1=0;
loop(j,0,4){
if((1<<j)&i)s1+=arr[j];
}
if(s1==s-s1)f=1;
}
if(f)cout<<"Yes";
else cout<<"No";
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);cin.tie(0);
int num; cin>>num;
int ans=0;
priority_queue <int> pq;
for (int i=0; i<num; i++) {
int temp; cin>>temp;
pq.push(temp);
}
for (int i=num; i!=0; i--) {
if (pq.top()!=i) {
cout<<"No";
break;
}
else {
pq.pop();
ans+=1;
}
}
if (ans==num) cout<<"Yes";
}
|
#include<iostream>
using namespace std;
int main(){
int a,n=0;
cin >> a;
if(a%100!=0){
n=1;
}
cout << a/100 + n << endl;
return(0);
} | #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cstdlib>
#include <queue>
#include <stack>
#include <bitset>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define PI 3.1415926535897932
#define INF 1e18
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repe(i, j, n) for (ll i = j; i < n; i++)
#define repi(i, n) for (ll i = 0; i <= n; i++)
#define repie(i, j, n) for (ll i = j; i <= n; i++)
#define all(x) x.begin(), x.end()
#define println() cout << endl
#define P pair<ll, ll>
#define fi first
#define se second
using Graph = vector<vector<ll>>;
long long modinv(long long a, long long m)
{
long long b = m, u = 1, v = 0;
while (b)
{
long long t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
ll dp[2000][2000];
ll nCr(ll n, ll r)
{
if(n==r) return dp[n][r] = 1;
if(r==0) return dp[n][r] = 1;
if(r==1) return dp[n][r] = n%MOD;
if(dp[n][r]) return dp[n][r]%MOD;
return dp[n][r] = nCr(n-1,r)%MOD + nCr(n-1,r-1)%MOD;
}
ll H(ll n, ll r) {
return nCr(n+r-1, r)%MOD;
}
int prime[10000000];
bool is_prime[100000000 + 1];
int sieve(int n) {
int pcnt = 0;
for(int i = 0; i <= n; i++) {
is_prime[i] = true;
}
is_prime[0] = is_prime[1] = false;
for(int i = 2; i <= n; i++) {
if(is_prime[i]) {
prime[pcnt++] = i;
for(int j = 2*i; j <= n; j += i) {
is_prime[j] = false;
}
}
}
return pcnt;
}
struct UnionFind {
//自身が親であれば、その集合に属する頂点数に-1を掛けたもの
//そうでなければ親のid
vector<ll> r;
UnionFind(ll N) {
r = vector<ll>(N, -1);
}
ll root(ll x) {
if (r[x] < 0) return x;
return r[x] = root(r[x]);
}
bool unite(ll x, ll y) {
x = root(x);
y = root(y);
if (x == y) return false;
if (r[x] > r[y]) swap(x, y);
r[x] += r[y];
r[y] = x;
return true;
}
ll size(ll x) {
return -r[root(x)];
}
bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す
ll rx = root(x);
ll ry = root(y);
return rx == ry;
}
};
void solve1() {
ll n; cin >> n;
n --;
cout << n / 100 + 1 << endl;
}
int main()
{
solve1();
}
|
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long;
using P = pair<int, ll>;
using T = tuple<ll, int, int>;
template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}
constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
#define all(a) (a).begin(), (a).end()
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
vector<ll> dijkstra(int s, vector<vector<pair<int, ll>>> &G){
int n = G.size();
vector<ll> dist(n, INF);
dist[s] = 0;
priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> que;
que.emplace(0, s);
while(que.size()){
ll ccost; int cv; tie(ccost, cv) = que.top(); que.pop();
if(dist[cv] < ccost) continue;
for(auto nxt : G[cv]){
int nv; ll ncost; tie(nv, ncost) = nxt;
if(ccost + ncost < dist[nv]){
dist[nv] = ccost + ncost;
que.emplace(dist[nv], nv);
}
}
}
return dist;
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int r, c; cin>>r>>c;
vector<vector<int>> a(r, vector<int>(c - 1));
for(int i=0; i<r; i++){
for(int j=0; j<c-1; j++) cin>>a[i][j];
}
vector<vector<int>> b(r - 1, vector<int>(c));
for(int i=0; i<r-1; i++){
for(int j=0; j<c; j++) cin>>b[i][j];
}
int sz = 2 * r * c;
vector<vector<P>> G(sz);
for(int i=0; i<r; i++){
for(int j=0; j<c; j++){
if(j + 1 < c) G[i * c + j].emplace_back(i * c + j + 1, a[i][j]);
if(0 <= j - 1) G[i * c + j].emplace_back(i * c + j - 1, a[i][j - 1]);
if(i + 1 < r) G[i * c + j].emplace_back((i + 1) * c + j, b[i][j]);
// (r, c) -> (r - i, c) の移動で i + 1 のコストがかかることを以下で実現
// 2 階に上がるのにコストが 1 かかる
G[i * c + j].emplace_back(r * c + i * c + j, 1);
// 1 階に下がるのにはコストがかからない
G[r * c + i * c + j].emplace_back(i * c + j, 0);
// 2 階で 1 つ下のマスに行くのにコストが 1 かかる
if(0 <= i - 1) G[r * c + i * c + j].emplace_back(r * c + (i - 1) * c + j, 1);
}
}
auto dist = dijkstra(0, G);
cout << dist[r * c - 1] << endl;
return 0;
} | #include <bits/stdc++.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimize("O3,unroll-loops")
using ll = long long;
using ull = unsigned long long;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) for (int(i) = 0; (i) < int(n); (i)++)
#define repi(i, a, b) for (int(i) = (a); (i) < int(b); (i)++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep)(__VA_ARGS__)
template <class T>
bool chmax(T& a, const T& b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
constexpr int dy[4] = {-1, 0, 1, 0};
constexpr int dx[4] = {0, -1, 0, 1};
constexpr ll MOD = 1'000'000'007LL; /*998'244'353LL;*/
template <typename T>
struct Dijkstra {
vector<vector<pair<int, short>>> e;
vector<T> cost;
Dijkstra(int V) : e(V) {}
void add(int u, int v, T weight) {
e[u].push_back({v, weight});
e[v].push_back({u, weight});
}
void add_directed(int from, int to, T weight) {
e[from].push_back({to, weight});
}
vector<T>& calculate(int s, T def) {
cost.resize(e.size(), def);
priority_queue<pair<T, int>> pq;
cost[s] = 0;
pq.push({0, s});
while (!pq.empty()) {
int n = pq.top().second;
if (-pq.top().first != cost[n]) {
pq.pop();
continue;
}
pq.pop();
for (int i = 0; i < e[n].size(); i++) {
if (cost[e[n][i].first] > cost[n] + e[n][i].second) {
cost[e[n][i].first] = cost[n] + e[n][i].second;
pq.push({-cost[e[n][i].first], e[n][i].first});
}
}
}
return cost;
}
};
int R, C;
Dijkstra<int> G(0);
signed main() {
cin >> R >> C;
G = Dijkstra<int>(2 * R * C);
rep(i, R) {
rep(j, C - 1) {
int a;
cin >> a;
G.add(i * C + j, i * C + j + 1, a);
}
}
rep(i, R - 1) {
rep(j, C) {
int a;
cin >> a;
G.add_directed(i * C + j, (i + 1) * C + j, a);
}
}
rep(i, R) {
rep(j, C) {
G.add_directed(i * C + j, R * C + i * C + j, 1);
G.add_directed(R * C + i * C + j, i * C + j, 0);
if (i - 1 >= 0)
G.add_directed(R * C + i * C + j, R * C + (i - 1) * C + j, 1);
}
}
cout << G.calculate(0, 2e9)[R * C - 1] << endl;
} |
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rrep(i,n) for(int i = (n-1);i>=0;--i)
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int INF=1<<30;
//const ll INF=1LL<<60;
int dpa[102];
int dpb[102];
int main() {
int a,b,x,y;
cin >> a >> b >> x >> y;
dpa[1] = 0;
dpb[1] = 0;
repi(i,1,100) {
dpa[i+1] = min(dpa[i]+y,dpb[i]+x);
dpb[i+1] = min(dpa[i+1]+x,dpb[i]+y);
}
int ans = 0;
if(a>b) ans+=dpa[a]-dpb[b];
if(b>a) ans+=dpb[b]-dpa[a]+x;
if(a == b) ans+= x;
cout<<ans<<endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int H,W,N,M;
cin >> H >> W >> N >> M;
vector<vector<int>> data(H, vector<int>(W,0));
vector<int>x(N);
vector<int>y(N);
for (int i = 0; i < N; i++) {
cin >> x.at(i);
cin >> y.at(i);
}
vector<int>X(M);
vector<int>Y(M);
for (int i = 0; i < M; i++) {
cin >> X.at(i);
cin >> Y.at(i);
}
for (int i = 0; i < M; i++) {
data.at(X.at(i)-1).at(Y.at(i)-1) = -1;
}
for (int i = 0; i < N; i++) {
data.at(x.at(i)-1).at(y.at(i)-1) = 1;
}
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
if (data.at(i).at(j) == 0){
for (int k = i+1; k < H; k++) {
if (data.at(k).at(j) == -1){
break;
}
else if (data.at(k).at(j) == 1){
data.at(i).at(j) = 10;
break;
}
}
for (int k = i-1; k >= 0; k--) {
if (data.at(k).at(j) == -1){
break;
}
else if (data.at(k).at(j) == 1){
data.at(i).at(j) = 10;
break;
}
}
for (int k = j+1; k < W; k++) {
if (data.at(i).at(k) == -1){
break;
}
else if (data.at(i).at(k) == 1){
data.at(i).at(j) = 10;
break;
}
}
for (int k = j-1; k >= 0; k--) {
if (data.at(i).at(k) == -1){
break;
}
else if (data.at(i).at(k) == 1){
data.at(i).at(j) = 10;
break;
}
}
}
}
}
int count = 0;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
if (data.at(i).at(j) > 0) {
count++;
}
}
}
cout << count << endl;
}
|
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <iterator>
#include <math.h>
#include <bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define MOD 1000000007;
#include <algorithm>
#include <cmath>
using namespace std;
int main()
{
// ios_base::sync_with_stdio(false);
// cin.tie(NULL);
// int T,p;
// cin>>T;
// for(p=1;p<=T;p++)
// {
ll N,M,X,Y;
cin>>N>>M>>X>>Y;
ll a,b,c,i,j,k;
ll A[M][4];
vector <vector <ll> > vect(N+1);
ll dp[N+1];
memset(dp,-1,sizeof(dp));
queue <ll> q;
for(i=0;i<M;i++)
{
cin>>A[i][0]>>A[i][1]>>A[i][2]>>A[i][3];
vect[A[i][0]].pb(i);
vect[A[i][1]].pb(i);
}
q.push(X);
dp[X]=0;
bool x[N+1];
memset(x,false,sizeof(x));
x[X]=true;
while(q.size()!=0)
{
a=q.front();
q.pop();
if(dp[a]==-1)
b=1e15;
else
b=dp[a];
for(i=0;i<vect[a].size();i++)
{
if(A[vect[a][i]][0]==a)
c=A[vect[a][i]][1];
else
c=A[vect[a][i]][0];
// cout<<a<<" "<<c<<" cesq\n";
if(x[c]==false)
{
q.push(c);
// cout<<c<<" chek2112\n";
x[c]=true;
}
if(dp[c]==-1)
{
continue;
}
else
{
if(dp[c]%A[vect[a][i]][3]==0)
b=min(dp[c]+A[vect[a][i]][2],b);
else
{
b=min(b,A[vect[a][i]][2]+dp[c]+A[vect[a][i]][3]-dp[c]%A[vect[a][i]][3]);
}
}
}
// cout<<b<<" check12\n";
dp[a]=b;
for(i=0;i<vect[a].size();i++)
{
if(A[vect[a][i]][0]==a)
c=A[vect[a][i]][1];
else
c=A[vect[a][i]][0];
if(dp[a]%A[vect[a][i]][3]==0)
b=dp[a]+A[vect[a][i]][2];
else
{
b=A[vect[a][i]][2]+dp[a]+A[vect[a][i]][3]-dp[a]%A[vect[a][i]][3];
}
// cout<<b<<" "<<a<<" \n";
if(dp[c]==-1)
{
dp[c]=b;
}
else
{
dp[c]=min(dp[c],b);
}
}
}
cout<<dp[Y];
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define S second
#define F first
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vll vector<long long int>
#define pll pair<long long int,long long int>
/* unordered_map<int,int>mp; mp.reserve(1024); mp.max_load_factor(0.25); */
#define mod 1000000007
#define mod2 998244353
#define ll long long int
#define ld long double
#define pi 3.141592653589793238
#define Endl endl
#define endl "\n"
const int N = 1e5 + 5;
const ll inf = 1e18;
vector<vll> a[N];
void solve()
{
ll n , m , x , y;
cin >> n >> m >> x >> y;
if(m == 0)
{
cout << -1;
return;
}
for(ll i=1;i<=m;i++)
{
ll u , v , t , k;
cin >> u >> v >> t >> k;
a[u].pb({v,t,k});
a[v].pb({u,t,k});
}
priority_queue<pll,vector<pll>,greater<pll>> pq;
vector<ll> vis(n+1,1e18);
pq.push({x,0});
vis[x] = 0;
ll ans = 1e18;
while(!pq.empty())
{
pll p = pq.top();
pq.pop();
ll u = p.F;
ll time = p.S;
if(u == y)
ans = min(ans,time);
for(auto v:a[u])
{
ll tt = 0;
if(time%v[2] == 0)
tt = time + v[1];
else
tt = (time/v[2] + 1)*v[2] + v[1];
if(vis[v[0]] > tt)
{
pq.push({v[0],tt});
vis[v[0]] = tt;
}
}
}
if(ans == 1e18)
cout << -1;
else
cout << ans;
}
void debug(ll tt) {}
signed main()
{
FAST;
int t = 1;
// cin >> t;
while(t--)
{
solve();
}
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define mp make_pair
#define fr first
#define sc second
int main(){
int n,m;
scanf("%d%d",&n,&m);
ll cnt[2]={};
for(int i=0;i<n;i++){
string s;
cin>>s;
int t=0;
for(char c: s)t+=c-'0';
cnt[t&1]++;
}
cout<<cnt[0]*cnt[1]<<endl;
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e5 + 50;
string s[N];
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++)
cin >> s[i];
set<int> zeroes, ones;
set<int> nzeroes, nones;
for (int i = 0; i < n; i++) {
if (s[i][0] == '1')
ones.insert(i);
else
zeroes.insert(i);
}
for (int j = 1; j < m; j++) {
for (auto x: zeroes) {
if (s[x][j] == '0')
nzeroes.insert(x);
else
nones.insert(x);
}
for (auto x: ones) {
if (s[x][j] == '1')
nzeroes.insert(x);
else
nones.insert(x);
}
zeroes = nzeroes;
ones = nones;
nzeroes.clear();
nones.clear();
}
cout << (int) ones.size() * (int) zeroes.size();
}
|
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<iomanip>
#include<regex>
using namespace std;
#define int long long
const int mod=1e9+7;
signed main(){
int n,a[100000],fib[100001];
cin>>n;
for(int i=0;i<n;i++)
cin>>a[i];
fib[0]=fib[1]=1;
for(int i=2;i<=n;i++)
fib[i]=(fib[i-1]+fib[i-2])%mod;
int ans=0;
for(int i=0;i<n;i++)
ans=(ans+(2*fib[i]*fib[n-i]-fib[n]+mod)%mod*a[i])%mod;
cout<<ans<<endl;
} | #include <bits/stdc++.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include<vector>
#include<math.h>
using namespace std;
int gcd(int a, int b)
{
if (a == 0)
return b;
return gcd(b % a, a);
}
int main()
{
int t,n,i,j,k,l,a,b,c,flag,d;
int arr[100001];
char s[100001];
vector<int> v;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&arr[i]);
int result = arr[0];
for (int i = 1; i < n; i++)
{
result = gcd(arr[i], result);
}
printf("%d",result) ;
} |
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
#define ll long long
#define ull unsigned long long
#define dl double long
const int INF = 0x3fffffff;
const ll MOD = 1000000007;
const ll MODD = 998244353;
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
template<typename T> bool chmax(T &m, const T q) { if (m < q) { m = q; return true; } else return false; }
template<typename T> bool chmin(T &m, const T q) { if (m > q) { m = q; return true; } else return false; }
ll gcd(ll a, ll b) { return (b > 0) ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
using ipair = pair<ll, ll>;
int main()
{
ll r1, c1, r2, c2;
cin >> r1 >> c1 >> r2 >> c2;
ll r = r2 - r1;
ll c = c2 - c1;
ll ans = 3;
if (!r && !c) ans = 0;
else if (r == c || r == -c || abs(r) + abs(c) <= 3) ans = 1;
else if ((r ^ c ^ 1) & 1 || abs(r + c) <= 3 || abs(r - c) <= 3 || abs(r) + abs(c) <= 6) ans = 2;
cout << ans << endl;
}
| #include "bits/stdc++.h"
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
#define int long long int
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define vi vector <int>
#define ff first
#define ss second
#define vp vector <pair<int,int>>
#define vpp vector <pair<int,pair<int,int>>>
#define seti set<int>
#define setbit(x) __builtin_popcountll(x)
#define sov(v) accumulate(all(v),0)
#define fs(it,a) for(auto it=a.begin();it!=a.end();it++)
#define pb push_back
#define pob pop_back
#define mp make_pair
#define pqmax priority_queue <int,vector <int>>
#define pqmin priority_queue <int,vector <int>,greater<int>>
#define dq deque <int>
#define umi unordered_map<int,int>
#define ums unordered_map<string,int>
#define sp(x,y) fixed << setprecision(y) << x
#define all(x) x.begin(),x.end()
#define f(x,y,z) for(x=y;x<z;x++)
#define si size()
#define countdigit(x) floor(log10(x) +1)
#define M 1000000007
#define Z 998244353
#define fill(arr,x) memset(arr,x,sizeof(arr))
//Use (k%M+m)%m always where k is any no
#define PI 3.1415926535
#define lcm(a,b) a*b/(__gcd(a,b))
// typedef tree<int, null_type, less<int>, rb_tree_tag,
// tree_order_statistics_node_update> pdbs;
// // null for set,mapped_type for map;
// //less for assending greater for descending
//ceil(a/b)=(a+b-1)/b
// v.si-1 can never be negative
#define ghadi() cerr<<"\nTime Taken : "<<(float)(clock()-time_p)/CLOCKS_PER_SEC<<"\n";
clock_t time_p=clock();
#define ee "\n"
#define re return
//Author Rahul Sannigrahi
vector<int> take(int n)
{
int i,j;
vi v;
f(i,0,n)
{
cin>>j;
v.pb(j);
}
return v;
}
int power(int x,int y)
{
int res=1;
while(y>0)
{
if(y&1)
res=((res%M)*(x%M))%M;
y=y>>1;
x=((x%M)*(x%M))%M;
}
re res;
}
bool sortinrev(const pair<int,int> &a, //desc of vp
const pair<int,int> &b)
{
return (a.first > b.first);
}
void show(vector<int>v)
{
int i;
for(i=0;i<v.si;i++)
{
cout<<v[i]<<" ";
}
cout<<ee;
}
int decode()
{
int i,j,k,l,n,m,s,t,v,d;
cin>>v>>t>>s>>d;
if(v*t<=d and d<=v*s)
cout<<"No"<<ee;
else
cout<<"Yes"<<ee;
re 0;
}
int32_t main()
{
IOS
// #ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
// #endif
int t=1;
// cin>>t;
while(t--)
decode();
return 0;
} |
#include<bits/stdc++.h>
#define db double
#define il inline
#define iL (1<<20)
#define re register
#define ll long long
#define ui unsigned int
#define ull unsigned long long
#define TEM template<class T>il void
#define Write(x,LC) write((x)),*iter++=LC
#define Writeneg(x,LC) writeneg((x)),*iter++=LC
#define flush() fwrite(Out,1,iter-Out,stdout),iter=Out
#define gc() ((iS==iT)?(iT=(iS=ibuf)+fread(ibuf,1,iL,stdin),(iS==iT)?EOF:*iS++):*iS++)
using namespace std;
namespace IO{
char ibuf[iL],*iS=ibuf+iL,*iT=ibuf+iL,Out[iL],*iter=Out;
TEM Readneg(re T &x){re char c;re bool f;for(f=false,c=getchar();!isdigit(c);f|=c=='-',c=getchar());for(x=0;isdigit(c);x=(x<<1)+(x<<3)+(c^48),c=getchar());if(f)x=~x+1;}
TEM readneg(re T &x){re char c;re bool f;for(f=false,c=gc();!isdigit(c);f|=c=='-',c=gc());for(x=0;isdigit(c);x=(x<<1)+(x<<3)+(c^48),c=gc());if(f)x=~x+1;}
TEM writeneg(re T x){if(x<0)*iter++='-',x=~x+1;re T c[35],l;for(l=0;!l || x;c[l]=x%10,++l,x/=10);for(;l;--l,*iter++=c[l]+'0');flush();}
TEM Read(re T &x){re char c;for(c=getchar();!isdigit(c);c=getchar());for(x=0;isdigit(c);x=(x<<1)+(x<<3)+(c^48),c=getchar());}
TEM read(re T &x){re char c;for(c=gc();!isdigit(c);c=gc());for(x=0;isdigit(c);x=(x<<1)+(x<<3)+(c^48),c=gc());}
TEM write(re T x){re T c[35],l;for(l=0;!l||x;c[l++]=x%10,x/=10);for(;l;*iter++=c[--l]+'0');flush();}
}
using namespace IO;
#define MAXN 105
#define MAXA 1005
int n,a[MAXN],b[MAXN],ton[MAXA];
int main(){
cin>>n;
for(re int i=1;i<=n;++i)cin>>a[i];
for(re int i=1;i<=n;++i)cin>>b[i];
for(re int i=1;i<=n;++i){
for(re int j=a[i];j<=b[i];++j){
++ton[j];
}
}
int ans=0;
for(re int i=1;i<MAXA;++i){
if(ton[i]==n){
++ans;
}
}
cout<<ans;
} | #define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
template <class T> auto vect(const T& v, int n) { return vector<T>(n, v); }
template <class T, class... D> auto vect(const T& v, int n, D... m) {
return vector<decltype(vect(v, m...))>(n, vect(v, m...));
}
typedef long long int64;
typedef pair<int, int> ii;
#define SZ(x) (int)((x).size())
template <typename T> static constexpr T inf = numeric_limits<T>::max() / 2;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }
template <class T> void out(const vector<T>& a) { for (int i = 0; i < SZ(a); ++i) cout << a[i] << " \n"[i + 1 == SZ(a)]; }
struct fast_ios {
fast_ios() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
};
} fast_ios_;
int main() {
int n;
cin >> n;
string s;
cin >> s;
if (s[0] != s[n - 1]) {
cout << 1 << '\n';
return 0;
}
vector<int> a;
for (int i = 0; i < n; ++i) {
if (s[i] != s[0]) a.push_back(i);
}
bool found = false;
for (int i = 1; i < SZ(a); ++i) {
if (a[i - 1] + 1 == a[i]) found = true;
}
cout << (found ? 2 : -1) << '\n';
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (n); ++i)
using ll = long long;
char win(char a, char b) {
if (a == b)return a;
if ((a == 'R'&&b == 'S') || (a == 'S'&&b == 'P') || (a == 'P'&&b == 'R')) {
return a;
}
return b;
}
signed main(void) {
int n, k;
string s;
cin >> n >> k >> s;
rep(i, k) {
if (s.size() % 2 == 1) {
s += s;
}
string buf = "";
rep(j, s.size() / 2) {
buf += win(s[2 * j], s[2 * j + 1]);
}
s = buf;
}
cout << s[0] << endl;
}
| #include<bits/stdc++.h>
using namespace std;
#define int long long
#define M 1000000007
#define INF ((1LL<<62LL) - 1)
int n,k;
char win(char x, char y){
string gg = "RSP";
if(x == y) return x;
for(int i=0;i<3;i++){
if(gg[i] == x && gg[(i+1)%3] == y) return x;
if(gg[i] == y && gg[(i+1)%3] == x) return y;
}
return x;
}
int po(int a, int b){
if(b==0) return 1;
if(b == 1) return a;
int temp = po(a, b/2);
temp *= temp;
temp%=n;
if(b&1) temp*=a;
temp%=n;
return temp;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> k;
string s; cin >> s;
char ans[n+1][k+1];
for(int i=0;i<n;i++){
ans[i][0] = s[i];
}
for(int j = 1;j<=k;j++){
//cout << j << "\n";
for(int left = 0;left<n;left++){
int right = left + po(2, j-1);
right%=n;
ans[left][j] = win(ans[left][j-1], ans[right][j-1]);
//cout << left << " " << right << " " << ans[left][j] << " won in " << ans[left][j-1] << " " << ans[right][j-1] << "\n";
}
//cout << "\n";
}
cout << ans[0][k] << "\n";
}
|
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i <= n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n)
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
using Graph = vector<vector<int>>;
using Edge = pair<int, ll>;
const ll INF = 1LL << 60;
const int MAX = 100000;
const int MOD = 1000000007;
int main()
{
// cin高速化
cin.tie(0);
ios::sync_with_stdio(false);
char c;
int a = 0, b = 0;
REP(i, 10)
{
cin >> c;
if (c == 'o')
{
++a;
}
else if (c == '?')
{
++b;
}
}
int ans = 0;
// oが多すぎorxが多すぎ
if (a > 4 || a + b == 0)
{
cout << ans << "\n";
return 0;
}
if (a == 4)
ans = 4 * 3 * 2;
if (a == 3)
ans = 3 * 2 * (b + 3) + 3 * 2 * (b + 2) + 3 * 2 * (b + 1) + 3 * 2 * b;
if (a == 2)
ans = 2 * (b + 2) * (b + 2) + 2 * (b + 1) * (b + 2) + 2 * (b + 1) * (b + 1) + 2 * b * (b + 2) + 2 * b * (b + 1) + 2 * b * b;
if (a == 1)
ans = (b + 1) * (b + 1) * (b + 1) + b * (b + 1) * (b + 1) + b * b * (b + 1) + b * b * b;
if (a == 0)
ans = b * b * b * b;
cout << ans << "\n";
return 0;
} | #include<bits/stdc++.h>
using namespace std;
char status[12];
int main(){
scanf("%s",status);
int ans=0;
for(int num=0; num<=9999; num+=1){
vector<bool> on(10);
for(int x=num, t=0; t<4; t++,x/=10)
on[x%10]=1;
bool safe=true;
for(int i=0; i<=9; i+=1)
if((status[i]=='o' and on[i]==0) or (status[i]=='x' and on[i]))
safe=false;
ans+=safe;
}
printf("%d\n",ans);
} |
#include<iostream>
#include<string>
using namespace std;
int main(){
string str;
bool flag=false;
cin>>str;
for(int i=0;i<str.length();++i){
if((i+1)%2!=0){
if(str[i]>=97 && str[i]<=122){
continue;
}
else{
cout<<"No\n";
flag=true;
break;
}
}
else{
if(str[i]>=65 && str[i]<=90){
continue;
}
else{
cout<<"No\n";
flag=true;
break;
}
}
}
if(!flag) cout<<"Yes\n";
return 0;
}
| /*include&using-----------------------------------------------------------------------*/
#include <bits/stdc++.h>
using namespace std;
/*debug-------------------------------------------------------------------------------*/
#define _GLIBCXX_DEBUG
#ifdef _DEBUG
#define debug(...) COUT(__VA_ARGS__)
#else
#define debug(...)
#endif
/*typename----------------------------------------------------------------------------*/
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
template <class T> using P = pair<T,T>;
template <class T> using M = map<T,T>;
template <class T> using S = set<T>;
template <class T> using PQ = priority_queue<T>;
template <class T> using PQG = priority_queue<T,V<T>,greater<T>>;
using ll = long long;
using st = string;
using vl = V<ll>;
using vvl = V<V<ll>>;
using vc = V<char>;
using vvc = V<V<char>>;
using vs = V<st>;
using vvs = V<V<st>>;
using vb = V<bool>;
using vvb = V<V<bool>>;
/*constant----------------------------------------------------------------------------*/
const ll INF = 1e9;
const ll MOD = 1e9+7;
const vl dx = {1,0,-1,0,1,0,-1,0};
const vl dy = {0,1,0,-1,0,1,0,-1};
/*macro-------------------------------------------------------------------------------*/
#define re(n) for(ll _ = 0; _ < (ll) n; _++)
#define rep(i,n) for(ll i = 0; i < (ll) n; i++)
#define rrep(i,n) for(ll i = (ll) n - 1; i >= 0;i--)
#define repp(i,x,n) for(ll i = (ll) x; i < (ll) n; i++)
#define bitrep(i,n) for(ll i = 0; i < (1<<(ll)n); i++)
#define each(x,A) for(auto &(x): (A))
#define all(A) A.begin(), A.end()
#define len(A) ll(A.size())
#define pb(a) push_back(a)
#define mp make_pair
#define pc cout << setprecision(15) << fixed
/*input-------------------------------------------------------------------------------*/
void CIN(){}
template <class Head,class... Tail>
void CIN(Head&& h,Tail&&... t){cin>>h; CIN(t...);}
#define CINL(...) ll __VA_ARGS__;CIN(__VA_ARGS__)
#define CINS(...) string __VA_ARGS__;CIN(__VA_ARGS__)
#define CIND(...) double __VA_ARGS__;CIN(__VA_ARGS__)
/*output------------------------------------------------------------------------------*/
void COUT(){cout << endl;}
template <class Head, class... Tail>
void COUT(Head h, Tail... t){cout << h << " "; COUT(t...);}
/*function----------------------------------------------------------------------------*/
void Yes(bool ans){cout << (ans? "Yes" : "No") << endl;}
void YES(bool ans){cout << (ans? "YES" : "NO") << endl;}
template <class T> T ceil(T a,T b){return (a+b-1)/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(a>b){a=b;}}
template <class T> T gcd(T a,T b){if(a<b)swap(a,b); if(a%b==0)return b; return gcd(b,a%b);}
template <class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
template <class T> T modpow(T x,T n,T mod){T res=1; for(ll i=0;i<n;i++){res=res*x%mod;}return res;}
bool range(ll ny, ll nx, ll H, ll W) {if(ny < 0 || ny >= H || nx < 0 || nx >= W) return false; return true;}
/*------------------------------------------------------------------------------------*/
int main() {
CINS(s);
rep(i,len(s)){
if(i%2==0 && !('a'<=s[i] && s[i]<='z')){
COUT("No");
return 0;
}
if(i%2==1 && !('A'<=s[i] && s[i]<='Z')){
COUT("No");
return 0;
}
}
COUT("Yes");
} |
#include <bits/stdc++.h>
/* #include <atcoder/all> */
using namespace std;
/* using namespace atcoder; */
using pint = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;
using vvll = vector<vector<long long>>;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) \
for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) \
for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
#define ALL(v) v.begin(), v.end()
#define endl "\n"
#define ciosup \
cin.tie(0); \
ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
#define vvint vector<vector<int>>
#define vbl vector<bool>
#define vvbl vector<vector<bool>>
constexpr ll INF = 1e15 + 7LL;
constexpr ll MOD = 998244353LL;
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
for (int i = 0; i < v.size(); ++i) {
is >> v[i];
}
return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
if (v.size() == 0) return os;
for (int i = 0; i < v.size() - 1; ++i) {
os << v[i] << " ";
}
os << v[v.size() - 1];
return os;
}
void solve() {
double sx, sy, gx, gy;
cin >> sx >> sy >> gx >> gy;
gy = -gy;
double dx = gx - sx, dy = sy - gy;
/* cout << dx << " " << dy << endl; */
double ans = sx + sy * ((dx)/(dy));
cout.precision(16);
cout << ans << endl;
}
int main() {
solve();
char tmp;
while (cin >> tmp) {
cin.putback(tmp);
solve();
}
}
| #include <bits/stdc++.h>
//#include <cmath>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define mod 1000000007
//#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second
#define bs(yup,x) binary_search(yup.begin(),yup.end(),x) //it will return bollean value
#define lb(yup,x) lower_bound(yup.begin(),yup.end(),x) //it will return the adress of the number which is equal to or just greater than x ,and if it is equal to yup.end() than their in no such number exist
#define ub(yup,x) upper_bound(yup.begin(),yup.end(),x)
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
using namespace std;
const long long N=200005,INF=2000000000000000000;
const long double EPS= 0.000000000001;
int power(int a, int b, int p)
{
if(a==0)
return 0;
int res=1;
//a%=p;
while(b>0)
{
if(b&1)
res=(res*a)%p;
b>>=1;
a=(a*a)%p;
}
return res;
}
vi prime;
bool isprime[N];
void pre()
{
for(int i=2;i<N;i++)
{
if(isprime[i])
{
for(int j=i*i;j<N;j+=i)
isprime[j]=false;
prime.pb(i);
}
}
return;
}
int32_t main()
{
IOS;
//fill(isprime, true);
//pre();
int t=1;
//cin>>t;
while(t--)
{
int a,b,c;
cin>>a>>b>>c;
if(c)
{
if(b>a) cout<<"Aoki";
else cout<<"Takahashi";
}
else
{
if(a>b) cout<<"Takahashi";
else cout<<"Aoki";
}
cout<<"\n";
}
}
|
#include <bits/stdc++.h>
#include <cassert>
typedef long long int ll;
using namespace std;
// #include <atcoder/all>
// using namespace atcoder;
// @@ !! LIM(f:gcd)
// --> f:gcd
// ---- inserted function gcd from util.cc
tuple<ll, ll, ll> mut_div(ll a, ll b, ll c, bool eff_c = true) {
// auto [g, s, t] = mut_div(a, b, c, eff_c)
// If eff_c is true (default),
// g == gcd(|a|, |b|) and as + bt == c, if such s,t exists
// (g, s, t) == (-1, -1, -1) otherwise
// If eff_c is false,
// g == gcd(|a|, |b|) and as + bt == g
// N.b. gcd(0, t) == gcd(t, 0) == t.
if (a == 0) {
if (eff_c) {
if (c % b != 0) return {-1, -1, -1};
else return {abs(b), 0, c / b};
}else {
if (b < 0) return {-b, 0, -1};
else return { b, 0, 1};
}
}else {
auto [g, t, u] = mut_div(b % a, a, c, eff_c);
// DLOGK(b%a, a, c, g, t, u);
if (g == -1) return {-1, -1, -1};
return {g, u - (b / a) * t, t};
}
}
// auto [g, s, t] = eGCD(a, b) ---> sa + tb == g == gcd(|a|, |b|)
// N.b. gcd(0, t) == gcd(t, 0) == t.
tuple<ll, ll, ll> eGCD(ll a, ll b) { return mut_div(a, b, 0, false); }
pair<ll, ll> crt_sub(ll a1, ll x1, ll a2, ll x2) {
// DLOGKL("crt_sub", a1, x1, a2, x2);
a1 = a1 % x1;
a2 = a2 % x2;
auto [g, s, t] = mut_div(x1, -x2, a2 - a1);
// DLOGK(g, s, t);
if (g == -1) return {-1, -1};
ll z = x1 / g * x2;
// DLOGK(z);
s = s % (x2 / g);
ll r = (x1 * s + a1) % z;
// DLOGK(r);
if (r < 0) r += z;
// DLOGK(r);
return {r, z};
};
// Chinese Remainder Theorem
//
// r = crt(a1, x1, a2, x2)
// ==> r = a1 (mod x1); r = a2 (mod x2); 0 <= r < lcm(x1, x2)
// If no such r exists, returns -1
// Note: x1 and x2 should >= 1. a1 and a2 can be negative or zero.
//
// r = crt(as, xs)
// ==> for all i. r = as[i] (mod xs[i]); 0 <= r < lcm(xs)
// If no such r exists, returns -1
// Note: xs[i] should >= 1. as[i] can be negative or zero.
// It should hold: len(xs) == len(as) > 0
ll crt(ll a1, ll x1, ll a2, ll x2) { return crt_sub(a1, x1, a2, x2).first; }
ll crt(vector<ll> as, vector<ll> xs) {
// DLOGKL("crt", as, xs);
assert(xs.size() == as.size() && xs.size() > 0);
ll r = as[0];
ll z = xs[0];
for (size_t i = 1; i < xs.size(); i++) {
// DLOGK(i, r, z, as[i], xs[i]);
tie(r, z) = crt_sub(r, z, as[i], xs[i]);
// DLOGK(r, z);
if (r == -1) return -1;
}
return r;
}
// ---- end gcd
// @@ !! LIM -- end mark --
int main(/* int argc, char *argv[] */) {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout << setprecision(20);
auto solve = [&]() -> void {
ll X, Y, P, Q; cin >> X >> Y >> P >> Q;
ll ans = LLONG_MAX;
for (ll u = 0; u < Y; u++) {
for (ll v = 0; v < Q; v++) {
ll t = crt(X + u, 2 * (X + Y), P + v, P + Q);
if (t == -1) continue;
ans = min(ans, t);
}
}
if (ans == LLONG_MAX) {
cout << "infinity\n";
}else {
cout << ans << "\n";
}
};
ll T; cin >> T;
for (ll t = 0; t < T; t++) solve();
return 0;
}
| #include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 9;
const int maxn = 2e3 + 5;
ll rd(){
ll x = 0;
int f = 1;
char ch = getchar();
while(ch < '0' || ch > '9') {
if(ch == '-') f = -1;
ch = getchar();
}
while(ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
ll ksm(ll a,ll b,ll m = MOD) {
ll ans = 1;
ll base = a;
while(b) {
if(b & 1) {
ans *= base;
ans %= MOD;
}
base *= base;
base %= MOD;
b >>= 1;
}
return ans;
}
int main(){
int T = rd();
while(T--){
ll n = rd();
if(n == 2) puts("Same");
else if(n & 1) puts("Odd");
else {
int cnt = 0;
while(n % 2 == 0) n /= 2,cnt++;
if(cnt == 1) puts("Same");
else puts("Even");
}
}
} |
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define All(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend() //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
#define IN(a, b, x) (a<=x&&x<b)
using namespace std;
using ll = long long;
using Pair = pair<int,int>;
using Graph = vector<vector<ll>>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename t, typename u, typename Comp=less<>>
bool chmax(t& xmax, const u& x, Comp comp={}) { if(comp(xmax, x)) { xmax = x; return true; } return false;}
template<typename t, typename u, typename Comp=less<>>
bool chmin(t& xmin, const u& x, Comp comp={}) { if(comp(x, xmin)) { xmin = x; return true;} return false;}
const int INF = 1e9;
const ll infl = ll(1e18)+5;
int main(){
int H,W;cin >> H >> W;
int min_block = 105;
vector<vector<int>> V(H,vector<int>(W,0));
rep(i,H){
rep(j,W){
cin >> V[i][j];
min_block = min(min_block,V[i][j]);
}
}
int ans = 0;
rep(i,H){
rep(j,W){
ans += V[i][j]-min_block;
}
}
cout << ans << endl;
} | #include<iostream>
using namespace std;
int main() {
int n;
cin>>n;
string str;
cin>>str;
for (int i=n-1;i>=0;i--) {
if (i==n-1 && str[0] != str[i]) {
cout<<1<<endl;
return 0;
}
else if (i<n-2 && str[0] != str[i] && str[n-1] != str[i+1]) {
cout<<2<<endl;
return 0;
}
}
cout<<-1<<endl;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int,int>>
#define vpll vector<pair<ll,ll>>
#define fr(i,k,n) for (int i = k; i < n; ++i)
#define fri(i,k,n) for (int i = k; i >= n; --i)
#define pb push_back
#define mp make_pair
#define all(arr) arr.begin(),arr.end()
#define ff first
#define ss second
const double pi=3.1415926535897932384626433832795;
const int inf=1e9;
const ll inf2=1e18;
const int mod=1e9+7;
void boost(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
int adj[20][20],n;
vi dp(1<<20,inf);
void solve(){
int m;
cin>>n>>m;
int u,v;
fr(i,0,m){
cin>>u>>v;
u--;
v--;
adj[u][v]=adj[v][u]=1;
}
for(int i=1;i<(1<<n);i++){
if(!(i&(i-1))){
dp[i]=1;
continue;
}
dp[i]=1;
for(int j=0;j<n;j++){
if((i>>j)&1){
for(int k=j+1;k<n;k++){
if((i>>k)&1){
if(adj[j][k]==0)
dp[i]=inf;
}
}
}
}
for(int j=(i-1)&i;j;j=(j-1)&i){
dp[i]=min(dp[i],dp[j]+dp[i^j]);
}
}
cout<<dp[(1<<n)-1]<<endl;
return;
}
int main()
{
boost();
int tc=1;
//cin>>tc;
while(tc--)
solve();
return 0;
} | #ifdef Prateek
#include "Prateek.h"
#else
#include <bits/stdc++.h>
using namespace std;
#define debug(...) 42
#endif
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
const int MOD = 1e9+7, N = 20;
int g[N][N];
int n, m;
int dp[(1 << N)];
int dfs(int mask) {
// debug(mask);
int &ans = dp[mask];
if (ans != -1) return ans;
if (__builtin_popcount(mask) == 1) return ans = 1;
if (__builtin_popcount(mask) == 2) {
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n; ++j) {
if ((mask >> i & 1) and (mask >> j & 1)) {
if (g[i][j]) return ans = 1;
return ans = 1e9;
}
}
}
assert(false);
}
int chk = 1;
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n; ++j) {
if ((mask >> i & 1) and (mask >> j & 1)) {
if (!g[i][j]) {
chk = 0;
break;
}
}
}
if (!chk) break;
}
if (chk) {
return ans = 1;
}
ans = 1e9;
for (int s = mask; s; s = (s - 1) & mask) {
if (s == mask) continue;
// debug(s, mask ^ s);
ans = min(ans, dfs(s) + dfs(mask ^ s));
}
return ans;
}
int32_t main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
memset(dp, -1, sizeof dp);
cin >> n >> m;
for (int i = 0; i < m; ++i) {
int x, y;
cin >> x >> y;
--x, --y;
g[x][y] = g[y][x] = 1;
}
int mask = (1 << n) - 1;
int ans = dfs(mask);
if (ans > n) ans = n;
cout << ans << '\n';
return 0;
} |
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <algorithm>
#include <cmath>
#include <climits>
#include <iomanip>
#include <queue>
#include <stack>
using namespace std;
typedef long long ll;
const int INF = (1<<30)-1;
const ll LINF = 1e18;
#define rep(i, n) for (int i = 0; i < n; i++)
template<class T>
bool chmax(T &a, T b) {if (a < b) {a = b;return true;}else return false;}
template<class T>
bool chmin(T &a, T b) {if (a > b) {a = b;return true;}else return false;}
char janken[] = {'R', 'S', 'P'};
int memo[101][101];
int v[100];
int n, k;
int mod_pow(int a, int x) {
if (x == 0)
return 1;
else if (x % 2)
return a * mod_pow(a, x-1) % n;
else {
int tmp = mod_pow(a, x/2);
return tmp * tmp % n;
}
}
int func(int l, int i) {
//cout << l << " " << i << "にきた" << endl;
if (memo[l][i] != -1)
return memo[l][i];
if (l == 0) {
//cout << v[i%n] << "の価値" << endl;
return memo[l][i] = v[i % n];
}
//cout << l-1 << " " << i << " と" << l-1 << " " << (i+mod_pow(2, l-1))%n << "にいく" << endl;
int a = func(l-1, i), b = func(l-1, (i+mod_pow(2, l-1))%n), ans;
if (a == b)
ans = a;
else if ((a+1) % 3 == b)
ans = a;
else
ans = b;
return memo[l][i] = ans;
//cout << ans << "の価値" << endl;
}
int main() {
cin >> n >> k;
string s; cin >> s;
rep(i, 101)rep(j, 101) memo[i][j] = -1;
rep(i, n) {
rep(j, 3) {
if (janken[j] == s[i])
v[i] = j;
}
}
int ans = func(k, 0);
rep(j, 3) {
if (janken[j] == janken[ans])
cout << janken[j] << endl;
}
return 0;
}
//小数点精度
//cout << fixed << std::setprecision(15) << y << endl; | #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
//#include <atcoder/all>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
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 n,k; string s;
char f(char a, char b){
if(a=='R'){
if(b==('R')) return 'R';
if(b==('P')) return 'P';
if(b==('S')) return 'R';
}
if(a=='P'){
if(b==('R')) return 'P';
if(b==('P')) return 'P';
if(b==('S')) return 'S';
}
if(a=='S'){
if(b==('R')) return 'R';
if(b==('P')) return 'S';
if(b==('S')) return 'S';
}
}
int main(){
cin >> n >> k;
cin >> s;
rep(i,k){
string news;
if(sz(s)%2) s+=s;
rep(j,sz(s)/2){
news += f(s[2*j], s[2*j+1]);
}
s = news;
}
cout << s[0] << endl;
return 0;
}
|
//#pragma GCC optimize ("O2")
//#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please
int a[2621500];
int main() {
//cin.tie(0);
//ios::sync_with_stdio(false);
int N, T;
scanf("%d %d ", &N, &T);
int A[50];
rep(i, N) scanf("%d ", A + i);
auto mae = a, ato = a + (1 << 20) + 1, sub = a + (1 << 21) + 2;
int X = 1;
rep(i, N / 2) {
int x = 0, y = 0, z = 0;
mae[X] = 2000000000;
rep(x, X) {
while (mae[y] < mae[x] + A[i]) sub[z++] = mae[y++];
sub[z++] = mae[x] + A[i];
}
X <<= 1;
while (sub[X - 1] > T) X--;
swap(mae, sub);
}
int Y = 1;
for (int i = N / 2; i < N; i++) {
int x = 0, y = 0, z = 0;
ato[Y] = 2000000000;
rep(x, Y) {
while (ato[y] < ato[x] + A[i]) sub[z++] = ato[y++];
sub[z++] = ato[x] + A[i];
}
Y <<= 1;
while (sub[Y - 1] > T) Y--;
swap(ato, sub);
}
int j = Y - 1;
ll kotae = 0;
rep(i, X) {
ll tmp = mae[i];
while (j >= 0 && tmp + ato[j] > T) j--;
if (j < 0) break;
if (kotae < tmp + ato[j]) kotae = tmp + ato[j];
}
printf("%lld\n", kotae);
Would you please return 0;
} | #include<bits/stdc++.h>
#define ll long long int
#define inf 1E18
#define ninf -1*1E18
#define mod 1000000007
#define fi first
#define si second
#define pb push_back
#define vi vector<long long int>
#define pi pair<long long int,long long int>
#define vpi vector<pair<long long int,long long int>>
using namespace std;
ll const lac = 100000;
ll modmul(ll a, ll b) {
return ((a % mod) * (b % mod)) % mod;
}
ll modadd(ll a, ll b) {
return (((a % mod) + (b % mod))) % mod;
}
long long modExpo(long long a, long long b, long long m) {
long long result = 1;
a = a % m;
while (b > 0) {
if (b % 2) {
result = modmul(result, a);
b--;
}
else {
a = modmul(a, a);
b /= 2;
}
}
return result % m;
}
ll gcd(ll a, ll b) {
if (b == 0) return a; else return gcd(b, a % b);
}
class comp { //set of pairs comparator:
public:
bool operator()(int a, int b)const {
return a > b;
}
};
bool compa(int a, int b) {
return a > b;
}
void solve(ll t1) {
ll a1, b, c;
cin >> a1 >> b >> c;
vi a;
a.pb(a1); a.pb(b); a.pb(c);
sort(a.begin(), a.end());
cout << a[2] + a[1] << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t ;
t = 1;
// init();
// cin >> t;
for (ll i = 1; i <= t; i++) {
solve(t);
}
cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
return 0;
} |
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
// ll n;
int main()
{
#ifndef ONLINE_JUDGE
freopen("inn.txt", "r", stdin);
freopen("hell.txt", "w", stdout);
#else
#endif
ll n;
cin>>n;
ll ans=0;
while(n--)
{
ll a,b;
cin>>a>>b;
ans+=(b*(b+1)/2-a*(a-1)/2);
}
cout<<ans<<endl;
} | #include <bits/stdc++.h>
using namespace std;
int main(){
long long n;
cin>>n;
vector<long long> a(n);
map<int,long long> cnt;
for(int i=0;i<n;i++){
cin>>a.at(i);
cnt[a.at(i)]++;
}
long long ans=n*(n-1)/2;
auto begin = cnt.begin(), end = cnt.end();
for (auto iter = begin; iter != end; iter++) {
long long x=iter->second;
ans-=x*(x-1)/2;
}
cout<<ans<<endl;
} |
/**
Abir3014
**/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define for1(x, a, b) for(x=a; x<b; x++)
#define for2(x, a, b) for(x=a, x>=b; x--)
#define endl "\n"
#define all(x) x.begin(), x.end()
#define p pair
#define mp make_pair
#define vi vector<ll>
#define vii vector<pair<ll, ll>>
#define msii multiset<pair<ll, ll>>
#define msi multiset<ll>
#define sii set<pair<ll, ll>>
#define si set<ll>
#define mii map<ll, ll>
#define read freopen("input.txt","r",stdin)
#define write freopen("output.txt","w",stdout)
#define pb push_back
#define ff first
#define ss second
#define bb begin
#define arr_ub(arr, n, x) upper_bound(arr, arr+n, x)-arr
#define arr_lb(arr, n, x) lower_bound(arr, arr+n, x)-arr
#define u_p(v, x) upper_bound(v.begin(), v.end(), x)-v.begin()
#define l_b(v, x) lower_bound(v.begin(), v.end(), x)-v.begin()
const ll sz=1e6+123;
#define INF 1000000000000000007
#define MOD 1000000007
#define stringLen 18446744073709551620
#define pi 3.1415926536
/**
ll fact(ll n){
ll count=1;
for(ll i=0; i<n; i++){
count *= (n-i);
}
return count;
}
ll perm(ll n, ll r){
ll count=1;
for(ll i=0; i<r; i++){
count *= (n-i);
}
return count;
}
ll comb(ll n, ll r){
ll l = n-r, count=1;
if(r<l)swap(l, r);
count = perm(n, l);
return count/fact(l);
}
vi divisorList[sz];
ll divisorNumber[sz];
void findDivisor(ll n){
for(ll i=1; i<=n; i++){
for(ll j=i; j<=n; j+=i){
divisorList[j].pb(i);
divisorNumber[j]++;
}
}
}
ll gcd(ll a, ll b){
return b==0? a: gcd(b, a%b);
}
// lcm * gcd = a*b
ll lcm(ll a, ll b){
if(a>b)swap(a, b);
return a*(b/gcd(a, b));
}
bitset<sz>is_prime;
vi prime;
void primeGen(int n){
for(int i=3; i<=n; i+=2)is_prime[i]=1;
int nn = sqrt(n)+1;
for(ll i=3; i<nn; i+=2){
if(is_prime[i]==0)continue;
for(int j=i*i; j<=n; j+=(i+i)){
is_prime[j]=0;
}
}
is_prime[2]=1;
prime.pb(2);
for(int i=3; i<=n; i+=2){
if(is_prime[i])prime.pb(i);
}
}
vector<long long>primeDivisors[sz];
long long primeDivisorNumbers[sz];
void findPrimeDivisors(long long n){
for(auto u:prime){
for(long long i = u; i<=n; i+=u){
primeDivisors[i].push_back(u);
primeDivisorNumbers[i]++;
}
}
}
vector<long long>factorization(long long n){
//O(sqrt(n)/ln(sqrt(n)) + log2 n)
vector<long long>factors;
for(auto u:prime){
if(1LL*u*u > n) break;
if(n%u==0){
// factors.push_back(u);//for generating unique factors keep this line here
while(n%(u)==0){
//factors.push_back(u);//for generating all factors keep this line here
n/=(u);
}
}
}
if(n>1)factors.push_back(n);
return factors;
}
bool isPalindrome(string s){
ll i=0,j=s.size()-1;
for(i,j;i<=j;i++,j--){
if(s[i]!=s[j]) return 0;
}
return 1;
}
int modpow(int x, int n , int m){
if(n==0 )return 1%m;
long long u = modpow(x, n/2, m);
u=(u*u)%m;
if(n%2==1) u = (u*x)%m;
return u;
}
int NOD(long long n){
int res=1;
for(auto u:prime){
if(1LL*u*u > n)break;
if(n%u==0){
int count=1;
while(n%u==0){
n/=u;
count++;
}
res *= count;
}
}
if(n>1)res*=2;
return res;
}
bool isPalindrome(string s){
ll i=0,j=s.size()-1;
for(i,j;i<=j;i++,j--){
if(s[i]!=s[j]) return 0;
}
return 1;
}
**/
ll test=0;
void solve(){
int a, b, c;
cin>>a>>b>>c;
cout << 21 - a - b - c << endl;
//cout<<"Case "<<++test<": "<<ans<<endl;
//cout<<"Case #"<<++Case<<": ";
}
int main(){
boost;
//read; write;
//int t; cin>>t; for(int i=1; i<=t; i++)
solve();
return 0;
}
| #include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 2e5+8, inf = 1e18+9, mod = 998244353;
int n, m;
void solve() {
int i, j, a, b, c;
cin >> a >> b >> c;
cout << 21 - (a + b + c) << endl;
}
signed main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); //cout << fixed << setprecision(15);
int t = 1; //cin >> t;
while (t--) solve();
return 0;
}
|
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
//#include <atcoder/all>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
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 main(){
ll N; cin >> N;
set<ll> ng;
for(ll i=2;i*i<=N;i++){
ll n = i*i;
while(n<=N){
ng.insert(n);
n*=i;
}
}
cout << N-sz(ng);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define each(e, v) for(auto &e: v)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)x.size()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int MOD = 1000000007;
//const int MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};
struct io_setup{
io_setup(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout << fixed << setprecision(15);
}
} io_setup;
int main(){
int N;
cin >> N;
map<string, int> mp;
rep(i, N){
string S;
cin >> S;
if(S[0] != '!') mp[S] |= 1;
else{
string T;
rep(i, sz(S)-1) T += S[i+1];
mp[T] |= 2;
}
}
each(e, mp){
if(e.second == 3){
cout << e.first << '\n';
return 0;
}
}
cout << "satisfiable\n";
} |
#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
#define rep(i,n) for(ll i=0;i<(n);++i)
#define rep2(i,n) for(ll i=1;i<=(n);++i)
#define rep3(i,i0,n) for(ll i=i0;i<(n);++i)
#define rrep(i,n) for(ll i=((n)-1); i>=0; --i)
#define rrep2(i,n) for(ll i=(n); i>0; --i)
#define pb push_back
#define mod 1000000007
#define fi first
#define se second
#define len(x) ((ll)(x).size())
using namespace std;
using ll = long long;
using ld = long double;
using Pi = pair< ll, ll >;
using vl = vector<ll>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vp = vector<Pi>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
const ll INF = 1LL << 60;
const ld PI = 3.1415926535897932385;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define mp make_pair
void printb(ll N,ll d=16){
rep(i,d){
cout<<(N/(1<<(d-i-1)))%2;
}
cout<<endl;
}
void printv(vector<ll>a){
rep(i,a.size()){
if(i==a.size()-1){
cout<<a[i]<<endl;
}else{
cout<<a[i]<<" ";
}
}
}
bool In_map(ll y,ll x,ll h,ll w){
if(y<0 || x<0 || y>=h || x>=w){
return 0;
}else{
return 1;
}
}
bool compare(Pi a, Pi b) {
if(a.first != b.first){
return a.first < b.first;
}else{
return a.second < b.second;
}
}
//const vector<ll> dx = {1, 0, -1, 0, 1, -1, 1, -1};
//const vector<ll> dy = {0, 1, 0, -1, 1, 1, -1, -1};
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};
int main() {
ll N;
cin>>N;
vl A(N);
rep(i,N){
cin>>A[i];
}
ll ans=0;
rep(i,N){
ans+=max(0LL,A[i]-10);
}
cout<<ans<<endl;
return 0;
} | #include "bits/stdc++.h"
using namespace std;
#define ll long long
#define forn(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define sz(a) (int)a.size()
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define GR(a,n,m) vector<vector<int>> a(n, vector<int>(m, 0));
void solve()
{
ll ans = 0;
int n;
cin >> n;
vector<int> a(n);;
forn(i,n){
cin >> a[i];
if(a[i] > 10)ans += a[i] - 10;
}
cout<<ans;
}
int32_t main()
{
fastio;
int t = 1;
//cin >> t;
while(t--)
{
solve();
}
} |
#include <bits/stdc++.h>
using namespace std;
const int N = 10000;
int n;
bool mem[N][N];
class ad {
public:
int a, b, c, d, r, id;
ad() {}
void read() {
scanf("%d%d%d", &a, &b, &r);
mem[a][b] = true;
c = a + 1, d = b + 1;
}
void print() { printf("%d %d %d %d\n", a, b, c, d); }
int size;
void cal_size() { size = (c - a) * (d - b); }
double grad0, grad1;
void cal_grad() {
double p1 = 1.0 * size, p2 = size + d - b, p3 = size + c - a;
p1 = min(p1 / r, r / p1), p2 = min(p2 / r, r / p2),
p3 = min(p3 / r, r / p3);
p1 = p1 * (2 - p1), p2 = p2 * (2 - p2), p3 = p3 * (2 - p3);
grad0 = p2 - p1, grad1 = p3 - p1;
}
void init() {
cal_size();
cal_grad();
}
bool extend0() {
if (a) {
bool f = true;
for (int j = b; j < d; ++j) {
if (mem[a - 1][j]) {
f = false;
break;
}
}
if (f) {
for (int j = b; j < d; ++j) mem[a - 1][j] = true;
--a;
init();
return true;
}
}
if (c < 9999) {
bool f = true;
for (int j = b; j < d; ++j) {
if (mem[c][j]) {
f = false;
break;
}
}
if (f) {
for (int j = b; j < d; ++j) mem[c][j] = true;
++c;
init();
return true;
}
}
return false;
}
bool extend1() {
if (b) {
bool f = true;
for (int i = a; i < c; ++i) {
if (mem[i][b - 1]) {
f = false;
break;
}
}
if (f) {
for (int i = a; i < c; ++i) mem[i][b - 1] = true;
--b;
init();
return true;
}
}
if (d < 9999) {
bool f = true;
for (int i = a; i < c; ++i) {
if (mem[i][d]) {
f = false;
break;
}
}
if (f) {
for (int i = a; i < c; ++i) mem[i][d] = true;
++d;
init();
return true;
}
}
return false;
}
bool operator<(const ad &rhs) const {
return max(grad0, grad1) > max(rhs.grad0, rhs.grad1);
}
};
priority_queue<ad> q;
ad ans[200];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
ad t;
t.read();
t.id = i;
t.init();
q.push(t);
}
while (!q.empty()) {
ad now = q.top();
q.pop();
bool f = false;
if (now.grad0 >= now.grad1 && now.grad0 > 0) {
if (now.extend0())
f = true;
else if (now.grad1 > 0 && now.extend1())
f = true;
}
if (now.grad1 > now.grad0 && now.grad1 > 0) {
if (now.extend1())
f = true;
else if (now.grad0 > 0 && now.extend0())
f = true;
}
if (f)
q.push(now);
else
ans[now.id] = now;
}
for (int i = 0; i < n; ++i) ans[i].print();
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000010
#define EPS 1e-9
#define fst first
#define scd second
#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"
signed main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n,k,m;
cin>>n>>k>>m;
int a;
int sum=0;
rep(i,n-1){
cin>>a;
sum+=a;
}
int ans=(m*n)-sum;
if(ans>k) cout<<-1<<endl;
else cout<<max(ans,(int)0)<<endl;
return 0;
}
|
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); mt19937 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count());
#define F first
#define S second
#define PI 4.0*atan(1.0);
#define pb push_back
using namespace std;
int mod=1e9+7,gaymod=998244353,MAX=1000000000,pomod=1073741824;
//long long int gcd(long long int x,long long int y){
// if(y==0)return x;
//return gcd(y,x%y);
//}
int gcd(int x,int y){
if(y==0)return x;
return gcd(y,x%y);
}
ll lcm(ll a, ll b)
{
ll g=gcd(a, b);
return a/g*b;
}
ll binexp(ll a,ll b){
if(b==0)return 1;
ll res=binexp(a,b/2);
if(b%2)return((res%mod)*(res%mod)*(a%mod));
else return((res%mod)*(res%mod));
}
int prime(ll x){
if(x%2==0&&x!=2)
return 0;
else{
for(int i=3;ll(i*i)<=x;i+=2){
if(x%i==0)
return 0;
}
}
return 1;
}
//main
/*
vector<char> is_prime(N+1, true);
void sieve(int n){
is_prime[0] = is_prime[1] = false;
for (int i = 2; i <= n; i++) {
if (is_prime[i] && (long long)i * i <= n) {
for (int j = i * i; j <= n; j += i)
is_prime[j] = false;
}
}
}
*/
//freopen("input.txt","r",stdin);
//freopen("input.txt","w",stdin);
const int N=2e5+5;
//
int main(){
IOS;
int t=1;
//cin>>t;
while(t--){
int n;
cin>>n;
ll arr[n];
for(int i=0;i<n;i++)cin>>arr[i];
sort(arr,arr+n);
ll ans=((arr[0]*arr[0])%gaymod),sum=(arr[0]%gaymod);
for(int i=1;i<n;i++){
sum=2*sum-arr[i-1];
sum+=arr[i];
sum%=gaymod;
ans+=sum*(arr[i]%gaymod);
ans%=gaymod;
}
cout<<ans;
cout<<"\n";
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll unsigned long long int
#define endl "\n"
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);
ll a;
cin>>a;
int aa[a];
int bb[a];
for(int i=0;i<a;i++){
cin>>aa[i];
}
for(int j=0;j<a;j++){
cin>>bb[j];
}
ll q=aa[0];
ll maxi=*max_element(aa,aa+a);
ll mini=*min_element(bb,bb+a);
if(maxi>mini){
cout<<0;
}
else{
cout<<mini-maxi +1;
}
} |
#include <bits/stdc++.h>
#define FOR(i, j, k) for(int i = j; i < k; i ++)
#define FORE(i, j, k) for(int i = j; i <= k; i ++)
#define FORD(i, j, k) for(int i = j; i >= k; i --)
#define mp make_pair
#define ll long long
//#define f first
//#define s second
//#define int long long
using namespace std;
const int MOD=1e9+7;
const int N = 200005;
int n;
string s;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// #define task""
// freopen(task".inp","r",stdin);
// freopen(task".out","w",stdout);
cin >> n;
cin >> s;
if(n == 1)
{
cout << -1;
return 0;
}
if(s[0] != s[n - 1])
{
cout << 1 << "\n";
return 0;
}
for(int i = 2; i < n; i ++)
{
if(s[i] != s[0] && s[i - 1] != s[0])
{
cout << 2;
return 0;
}
}
cout << -1;
return 0;
}
| //#include<math.h>
#include<algorithm>
#include<stdlib.h>
#include<time.h>
#include<stdio.h>
#include<string.h>
#define un unsigned
#define srd srand(time(0))
#define ll long long
#define con continue
#define gtc getchar()
#define ptc putchar
#define dou double
#define eps 0.00000000001
#define opr operator
#define cl(x,a) memset(x,a,sizeof(x))
#define fo0(i,k) for(i=fr[k];i;i=nx[i])
#define fo1(i,l,r) for(i=l;i<=r;i++)
#define fo2(i,l,r) for(i=l;i>=r;i--)
#define fo(i,n) for(i=1;i<=n;i++)
#define ret return
#define x first
#define cint const int
#define y second
#define opi(x) freopen(x,"r",stdin)
#define opo(x) freopen(x,"w",stdout)
#define tpl template<class T>
#define priq priority_queue
#define mp make_pair
#define use using namespace
#define WT while(T--)
use std;
typedef pair<int,int> pii;typedef pair<int,ll> pil;typedef pair<ll,int> pli;typedef pair<ll,ll> pll;
namespace io
{
void _(int &k){char c;int e=1;k=0;while((c=gtc)>'9'||c<'0')if(c=='-')e=-1;k=c-'0';while((c=gtc)<='9'&&c>='0'){k*=10;k+=c-'0';}k*=e;}
void _(ll &k){char c;int e=1;k=0;while((c=gtc)>'9'||c<'0')if(c=='-')e=-1;k=c-'0';while((c=gtc)<='9'&&c>='0'){k*=10;k+=c-'0';}k*=e;}
void _(char &c){while((c=gtc)==' '||c=='\n');}void _(dou &c){scanf("%lf",&c);}void _(char *s){char c;while((c=gtc)!=EOF&&c!=' '&&c!=10)*s++=c;}
template<class t1,class t2>void _(t1 &a,t2 &b){_(a);_(b);}template<class t1,class t2,class t3>void _(t1 &a,t2 &b,t3 &c){_(a);_(b);_(c);}
template<class t1,class t2,class t3,class t4>void _(t1 &a,t2 &b,t3 &c,t4 &d){_(a);_(b);_(c);_(d);}
template<class t1,class t2,class t3,class t4,class t5>void _(t1 &a,t2 &b,t3 &c,t4 &d,t5 &e){_(a);_(b);_(c);_(d);_(e);}
void _p(dou k){printf("%.6lf",k);}void _p(char *c){for(;*c;ptc(*c++));}void _p(const char *c){for(;*c;ptc(*c++));}void _p(char c){ptc(c);}
tpl void _p0(T k){if(k>=10)_p0(k/10);ptc(k%10+'0');}tpl void _p(T k){if(k<0){ptc('-');_p0(-k);}else _p0(k);}tpl void __p(T k){_p(k);ptc(' ');}
tpl void _pn(T k){_p(k);ptc('\n');}template<class t1,class t2>void _p(t1 a,t2 b){__p(a);_pn(b);}
template<class t1,class t2,class t3>void _p(t1 a,t2 b,t3 c){__p(a);__p(b);_pn(c);}
template<class t1,class t2,class t3,class t4>void _p(t1 a,t2 b,t3 c,t4 d){__p(a);__p(b);__p(c);_pn(d);}
tpl void op(T *a,int n){int i;n--;fo(i,n)__p(a[i]);_pn(a[n+1]);}int gi(){int x;_(x);ret x;}ll gll(){ll x;_(x);ret x;}
}
int gcd(int a,int b){ret b?gcd(b,a%b):a;}void fcl(){fclose(stdin);fclose(stdout);}
void fop(const char *s){char c[256],d[256];cl(c,0);cl(d,0);strcpy(c,s);strcpy(d,s);opi(strcat(c,".in"));opo(strcat(d,".out"));}
int eq(dou a,dou b){return a+eps>=b&&b+eps>=a;}tpl void _ma(T &a,T b){if(a<b)a=b;}tpl void _mi(T &a,T b){if(a>b)a=b;}
cint N=2222,EE=100000000,GG=1000000000,ima=2147483647;
use io;
char a[1111][1111];
int fa[N],n,m,c[N],d[N],f[N],T;
int fi(int k){return fa[k]=fa[k]==k?k:fi(fa[k]);}
void hb(int x,int y)
{
x=fi(x);
y=fi(y);
fa[x]=y;
}
int main()
{
int i,j,a1,a2;
_(n,m);
fo(i,n)
scanf(" %s",a[i]+1);
fo(i,2111)
fa[i]=i;
a[1][1]=a[1][m]=a[n][1]=a[n][m]='#';
fo(i,n)
fo(j,m)
if(a[i][j]=='#')
hb(i*2,j*2+1);
fo(i,n)
c[i]=fi(i*2);
sort(c+1,c+n+1);
fo(i,m)
d[i]=fi(i*2+1);
sort(d+1,d+m+1);
_pn(min(unique(d+1,d+m+1)-d,unique(c+1,c+n+1)-c)-2);
}
|
#include<stdio.h>
int main()
{
double x,a,b,c,d;
scanf("%lf%lf%lf%lf",&a,&b,&c,&d);
x=(c*b+a*d)/(b+d);
printf("%.10f",x);
} | #include<bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define fi first
#define se second
#define pb push_back
#define pi pair<int,int>
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for(int i=(int)(l);i<(int)(r);i++)
#define repd(i, l, r) for (int i=(int)(l);i>=(int)(r);i--)
#define clrg(i, l, r) for(int i=(int)(l);i<(int)(r);i++)vis[i]=0,v[i].clear();
ll power(ll x, unsigned ll y){ll res = 1;while (y > 0){ if (y & 1){res = res*x;} y = y>>1;x = x*x;}return res;}
int powermod(int x, unsigned int y, int p){int res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1; x = (x*x) % p;}return res;}
#define print2d(mat,n,m){for(int i=0;i<(int)(n);i++){for(int j=0;j<(m);j++){cout<<mat[i][j]<<" ";}cout<< endl;}}
#define clr(a,x) memset(a,x,sizeof(a))
#define rr(v) for(auto &val:v)
#define print(v) for (const auto itr : v){cout<<itr<<' ';}cout<<"\n";
#define ln length()
#define sz size()
#define mod 1000000007
#define elif else if
#define INF 1e18+7
int32_t main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
fastIO;
ll t,n,q,l,r,a,b,c,x,y,i,j;
//cin>>t;
t=1;
while(t--)
{
double x1,y1,x2,y2;
cin>>x1>>y1>>x2>>y2;
double ans=(x2*y1+x1*y2)/(y2+y1);
cout << fixed << setprecision(9) <<ans<<endl;
}
return 0;
} |
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
using namespace std;
using llong = long long;
using vi = vector<int>;
using vvi = vector<vi >;
using vvvi = vector<vvi >;
using pii = pair<int,int>;
constexpr int INF = 1e9;
constexpr llong LINF = 1e18;
constexpr double EPS = 1e-12;
constexpr int MOD = 1e9+7;
template<class Type>
void line(const Type &a){int cnt=0;for(const auto &elem:a)cerr<<(cnt++?' ':'>')<<elem;cerr<<endl;}
/*エラトステネスの篩*/
class Sieve{
int size; //size:=(要素数).
std::vector<int> max_fact; //max_fac[n]:=(nの最大の素因数(max_fact[n]=nのとき,iは素数)).
std::vector<int> primes; //primes:=([0,size)間の素数の集合).
public:
//constructor.
Sieve():Sieve(51e4){}
Sieve(size_t n):size(n+1),max_fact(n+1,-1){//n以下の自然数を篩にかける. O(N*loglogN).
for(int i=2;i<size;++i){
if(max_fact[i]==-1){
max_fact[i]=i;
primes.push_back(i);
for(int j=i+i;j<size;j+=i) max_fact[j]=i;
}
}
}
bool is_prime(int n) const{//素数判定. O(1).
assert(0<=n and n<size);
return max_fact[n]==n;
}
std::vector<int> get_primes() const{return primes;}
std::map<int,int> prime_factorize(int n) const{//高速素因数分解. O(logN).
assert(0<=n and n<size);
std::map<int,int> res;
while(n>1){
res[max_fact[n]]++;
n/=max_fact[n];
}
return res;
}
std::vector<int> divisors(int n) const{//約数列挙.
std::vector<int> res({1});
auto pf=prime_factorize(n);
for(auto [p,cnt]:pf){
int sz=res.size();
for(int i=0;i<sz;++i){
int v=1;
for(int j=0;j<cnt;++j){
v*=p;
res.push_back(res[i]*v);
}
}
}
return res;
}
};
int main(){//I refer to other commentaries.
int n;
cin>>n;
Sieve ob;
for(int i=1;i<=n;++i){
auto mp=ob.prime_factorize(i);
int tmp=0;
for(auto [ignore,cnt]:mp) tmp+=cnt;
cout<<tmp+1<<endl;
}
} | #include <bits/stdc++.h>
#pragma GCC optimize(3)
#define int long long
#define ri register
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define is insert
#define es erase
using namespace std; const int N=200010;
inline int read()
{
int s=0, w=1; ri char ch=getchar();
while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
return s*w;
}
int n,a[N],b[N],p[N],to[N];
vector<pair<int,int> > w;
vector<pair<int,int> > Ans;
signed main()
{
n=read();
for(ri int i=1;i<=n;i++) a[i]=read(), w.eb(mk(a[i],i));
for(ri int i=1;i<=n;i++) b[i]=read();
for(ri int i=1;i<=n;i++) p[i]=read(), to[p[i]]=i;
sort(w.begin(),w.end());
for(ri int i=0;i<(int)w.size();i++)
{
int x=w[i].second;
int y=to[x];
if(x==y) continue;
if(a[x]>b[p[x]] && a[y]>b[p[y]])
{
Ans.eb(mk(x,y));
swap(p[x],p[y]);
to[p[x]]=x, to[p[y]]=y;
}
else return puts("-1")&0;
}
printf("%lld\n",(int)Ans.size());
for(auto i:Ans) printf("%lld %lld\n",i.first,i.second);
return 0;
} |
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
// #include<atcoder/all>
using namespace std;
// using namespace atcoder;
using ll=long long;
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// const ll INF = 1LL << 60;
int main() {
int a,b;cin>>a>>b;
if(a<b) {
rep(i, b) cout << -1 *(i+1) << " ";
rep(i, a-1) cout << 1 *(i+1) << " ";
int sum = 0;
for(int i = a; i <= b; i++) sum += i;
cout << sum << endl;
} else {
rep(i, b-1) cout << -1 *(i+1) << " ";
rep(i, a) cout << 1 *(i+1) << " ";
int sum = 0;
for(int i = b; i <= a; i++) sum += i;
cout << -1*sum << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int main(void)
{
LL A,B;
cin>>A>>B;
LL ans=0;
LL maxx=max(A,B);
LL minn=min(A,B);
for(LL i=1;i<=minn-1;i++)
{
cout<<i<<' '<<-i<<' ';
}
if(A>B)
{
for(LL i=minn;i<=maxx;i++)
{
cout<<i<<' ';
ans=ans+i;
}
cout<<-ans<<' ';
return 0;
}
else
{
for(LL i=minn;i<=maxx;i++)
{
cout<<-i<<' ';
ans=ans-i;
}
cout<<-ans<<' ';
return 0;
}
return 0;
}
|
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define endl "\n"
#define pb push_back
#define PI 3.1415926535897932384626433832795l
#define F first
#define S second
#define mp make_pair
#define f(i,n) for(int i=0;i<n;++i)
#define loop(i,a,b) for (int i=a ; i<b ;++i)
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define gcd(a,b) __gcd((a),(b))
#define fill(a,value) memset(a,value,sizeof(a));
#define minn(v) *min_element(v.begin(), v.end());
#define maxx(v) *max_element(v.begin(), v.end());
#define print(x) cout<<(x)<<endl;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int mod = 1e9 + 7;
const int MOD = 998244353;
int power(int x, int y, int p)
{
int res = 1;
x = x % p;
while (y > 0) {
if (y & 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
int modInverse(int n, int p)
{
return power(n, p - 2, p);
}
// Returns nCr % p using Fermat's little
// theorem.
int nCr(int n, int r, int p)
{
// Base case
if (r == 0)
return 1;
int fac[n + 1];
fac[0] = 1;
for (int i = 1; i <= n; i++)
fac[i] = (fac[i - 1] * i) % p;
return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p;
}
void solve()
{
string s;
cin >> s;
int ans = 0;
for (int i = 0; i < 9;)
{
if (s[i] == 'Z' and s[i + 1] == 'O' and s[i + 2] == 'N' and s[i + 3] == 'e')
{
ans++;
i += 3;
}
else
{
i++;
}
}
print(ans)
}
signed main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
fastio;
cout << fixed << setprecision(12);
int T = 1;
//cin >> T;
f(tc, T)
{
//cout << "Case #" << tc + 1 << ": ";
solve();
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve(long long N, long long K, std::vector<std::vector<long long>> T){
vector<int> zyunnretu;
for(int i = 1;i < N;i++){
zyunnretu.push_back(i);
}
ll ans = 0;
do{
ll cost = T[0][zyunnretu[0]];
for(int i = 0;i < N - 2;i++){
cost += T[zyunnretu[i]][zyunnretu[i + 1]];
}
cost += T[zyunnretu.back()][0];
if(cost == K)ans++;
}while(next_permutation(zyunnretu.begin(), zyunnretu.end()));
cout<<ans<<endl;
}
int main(){
long long N;
scanf("%lld",&N);
long long K;
scanf("%lld",&K);
std::vector<std::vector<long long>> T(N, std::vector<long long>(N));
for(int i = 0 ; i < N ; i++){
for(int j = 0 ; j < N ; j++){
scanf("%lld",&T[i][j]);
}
}
solve(N, K, std::move(T));
return 0;
}
|
#include<bits/stdc++.h>
#define pi 3.141592653589793238
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define MOD 1000000007
#define INF 999999999999999999
#define pb push_back
#define ff first
#define ss second
#define mt make_tuple
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int main() {
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
fast;
ll T = 1, i, j;
//cin >> T;
while (T--) {
ll n;
cin >> n;
vector<ll> v(n);
for(i = 0; i < n; i++){
cin >> v[i];
}
sort(v.begin(), v.end());
ll ans = v[0] + 1;
for(i = 1; i < n; i++){
ans *= (v[i] - v[i - 1] + 1);
ans %= MOD;
}
cout << ans << endl;
}
return 0;
} | #include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<n;i++)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const ll MOD=1000000007;
int main(){
int N;cin>>N;
vector<ll>A;
A.push_back(0);
set<ll>B;
ll tmp;
rep(i,N){
cin>>tmp;
if(B.find(tmp)!=B.end())continue;
B.insert(tmp);
A.push_back(tmp);
}
sort(A.begin(),A.end());
ll ans=1;
rep(i,A.size()-1){
ans*=(A[i+1]-A[i]+1);
ans%=MOD;
//cout<<ans<<"\n";
}
cout<<ans;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define mp make_pair
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 998244353;
ll A[100][100];
class UnionFind{
vector<int> par;
vector<int> rank;
vector<int> size;
public:
UnionFind(int n){
for(int i = 0; i < n; i++){
par.push_back(i);
rank.push_back(0);
size.push_back(1);
}
}
ll find(int x){
if(x == par[x])
return x;
else
return par[x] = find(par[x]);
}
void unite(int x, int y){
x = find(x);
y = find(y);
if(x == y) return;
if(rank[x] > rank[y]){
par[y] = x;
size[x] += size[y];
}
else{
par[x] = y;
rank[y] = max(rank[y], rank[x]+1);
size[y] += size[x];
}
}
bool same(int x, int y){
return find(x) == find(y);
}
int get_size(int x){
return size[x];
}
};
ll N, K;
ll KJ[100100];
ll calc(UnionFind& uni){
ll ret = 1;
vector<bool> isvisited(N, false);
REP(i,N){
int parent = uni.find(i);
if(isvisited[parent]) continue;
int size = uni.get_size(parent);
ret *= KJ[size];
ret %= MOD;
isvisited[parent] = true;
}
return ret;
}
int main(){
cin >> N >> K;
REP(i,N){
REP(j,N){
cin >> A[i][j];
}
}
UnionFind row(N+1), col(N+1);
ll kaijo = 1;
REPi(i,1,N+1){
kaijo *= i;
kaijo %= MOD;
KJ[i] = kaijo;
}
REP(i,N){
REPi(j,i+1,N){
bool valid = true;
REP(k,N){
ll sum = A[i][k] + A[j][k];
if(sum > K)
valid = false;
}
if(!valid) continue;
row.unite(i,j);
}
}
REP(i,N){
REPi(j,i+1,N){
bool valid = true;
REP(k,N){
ll sum = A[k][i] + A[k][j];
if(sum > K)
valid = false;
}
if(!valid) continue;
col.unite(i,j);
}
}
ll ans = 1;
ll row_score = calc(row);
ll col_score = calc(col);
ans = (ans * row_score) % MOD;
ans = (ans * col_score) % MOD;
cout << ans << endl;
return 0;
}
| #include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<cmath>
#include<set>
#include<vector>
#define rep(i,a,b) for(ll i=a;i<=b;++i)
#define per(i,a,b) for(ll i=a;i>=b;--i)
#define fi first
#define se second
#define mp make_pair
#define all(x) x.begin(),x.end()
#define debug(x) cout<<# x <<" is "<<x<<endl;
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
const ll maxn=40+10,inf=0x3f3f3f3f3f3f3f3f,mod=1e9+7;
ll a[maxn],temp[int((1<<20)+10)];
set<ll> s1,s2;
int main()
{
int n,t; scanf("%d%d",&n,&t);
rep(i,1,n) scanf("%lld",a+i);
sort(a+1,a+1+n);
s1.insert(0);
rep(i,1,n/2){
int cnt=0;
for(auto iter=s1.begin();iter!=s1.end();iter++){
ll num=*iter+a[i];
if(s1.find(num)==s1.end()&&num<=t) temp[++cnt]=num;
}
rep(i,1,cnt) s1.insert(temp[i]);
}
s2.insert(0);
rep(i,n/2+1,n){
int cnt=0;
for(auto iter=s2.begin();iter!=s2.end();iter++){
ll num=*iter+a[i];
if(s2.find(num)==s2.end()&&num<=t) temp[++cnt]=num;
}
rep(i,1,cnt) s2.insert(temp[i]);
}
//ll ans=0;
//s1.insert(0);
//auto iter=s2.end(),iter1=s1.begin(); iter--;
//for(;iter!=s2.begin();iter--){
// auto temp=iter1;
// while(iter1!=s1.end()&&*iter1+*iter<=t) iter1++;
// //if(temp==iter1) continue;
// temp=iter1; temp--;
// ans=max(ans,*temp+*iter);
//}
ll ans=0;
s2.insert(-1);
auto iter=s2.end(),iter1=s1.begin(); iter--;
for(;iter!=s2.begin();iter--){
if(*iter1+*iter>t) continue;
else{
while(iter1!=s1.end()&&*iter1+*iter<=t){
ans=max(ans,*iter1+*iter);
iter1++;
}
if(iter1==s1.end()) break;
}
}
cout<<ans<<endl;
return 0;
} |
//#pragma GCC optimize ("Ofast,unroll-loops")
//#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#include <unistd.h>
#define FAST_IO ios::sync_with_stdio(0);cin.tie(NULL)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef long long Long;
typedef long double Double;
typedef unsigned long long ULong;
typedef pair<Long, Long> Pair;
const int N = 3e5;
const Long INF = 1e18;
struct FenwickTree {
Long tree[N + 1];
void Clear(int n) {
for (int i = 0; i <= n; i++) tree[i] = 0;
}
void Update(int i, Long delta) {
while (i <= N) {
tree[i] += delta;
i += (i & -i);
}
}
Long Query(int i) {
Long sum = 0;
while (i > 0) {
sum += tree[i];
i -= (i & -i);
}
return sum;
}
} ft;
void Solve(void) {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
a[i]++;
}
Long ans = 0;
vector<Long> cnt(n + 1, 0);
for (int i = n - 1; i >= 0; i--) {
cnt[a[i]] = ft.Query(a[i]);
ans += cnt[a[i]];
ft.Update(a[i] + 1, 1);
}
ft.Clear(n);
for (int i = 0; i < n; i++) {
cout << ans << '\n';
ans -= (cnt[a[i]] + ft.Query(a[i]));
ans += (n - a[i]);
ft.Update(a[i] + 1, 1);
}
}
int main(void) {
FAST_IO;
int t = 1;
//cin >> t;
while (t--) Solve();
return 0;
}
| #include<bits/stdc++.h>
#define fp(x,a,b) for(int x = a; x < b; x++)
#define fn(x,a,b) for(int x = a; x > b; x--)
#define f(x, m) for(auto x : m)
#define cpu() ios::sync_with_stdio(false); cin.tie(nullptr)
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pair<int ,int>>
#define vll vector<pair<ll ,ll>>
#define all(v) v.begin(),v.end()
#define sor(a) sort( a.begin(), a.end() )
#define ros(a) sort( a.rbegin(), a.rend())
#define prec(n) fixed<<setprecision(n)
#define ff first
#define ss second
// #define tt third
#define print(x) for(auto it:x) cout<<it<<" ";
#define debug(x) cerr << #x << " is " << x << endl;
#define w(x) while(x--)
#define r(x) scanf("%d", &x)
#define rl(x) scanf("%ld", &x)
#define rll(x) scanf("%lld", &x)
typedef long long ll;
using namespace std;
// mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
// template <typename TYPE> void readint(TYPE &x){
// x=0; int f=1; char c;
// for(c=getchar();!isdigit(c);c=getchar())if(c=='-')f=-1;
// for(;isdigit(c);c=getchar())x=x*10+c-'0';
// x*=f;
// }
#define dbg(args...){ string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << endl;
err(++it, args...);
}
template<typename... T>
void rd(T& ... args){
((cin >> args), ...);
}
template<typename... T>
void ps(T&& ... args){
((cout << args << ' '), ...);
cout<<"\n";
}
const ll MOD = 1e9 + 7, MAX = 1e5 + 5;
const char nl = '\n';
const ll INF = 2e9 + 5;
int n;
ll k, ans;
ll a[MAX];
void solve(){
rd(n, k);
int t = 0;
while(n--){
cin >> a[t++];
if(a[t] > k) t--;
}
// ps(t, k);
int x = t / 2;
vl v1, v2;
fp(i, 0, 1 << x){
ll ga = 0LL;
fp(j, 0, x){
if(i & (1<<j)) ga += a[j];
}
v1.pb(ga);
}
// print(v1);
fp(i, 0, 1 << (t - x)){
ll ga = 0LL;
fp(j, 0, t - x){
if(i & (1<<j)) ga += a[j+x];
}
v2.pb(ga);
}
sor(v2);
// print(v2);
f(it, v1){
auto xd = upper_bound(all(v2), k - it);
if(xd != v2.begin()){
xd--;
if(*xd + it <= k) ans = max(*xd + it, ans);
}
}
ps(ans);
}
int main(){
cpu();
// int __;
// cin>>__;
// while(__--){
// solve();
// ps(" ");
// }
solve();
// cout<<nl;
return 0;
}
|
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long ll;
ll s,p;
int main(){
scanf("%lld%lld",&s,&p);
bool flag = 0;
for(ll i = 1;i * i <= p;i++){
if(p%i == 0){
ll x = i,y = p/i;
if(x + y == s) flag = 1;
}
if(flag) break;
}
if(flag) puts("Yes");
else puts("No");
return 0;
} | #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <climits>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
using namespace std;
#define ll long long
#define pb push_back
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
//typedef long long MOD=1000000009;
ll MOD=998244353;
ll add(ll x, ll y) {ll res = x + y; return (res >= MOD ? res - MOD : res);}
ll mul(ll x, ll y) {ll res = x * y; return (res >= MOD ? res % MOD : res);}
//ll sub(ll x, ll y) {ll res = x - y; return (res < 0 ? res + MOD : res);}
ll lcm(ll x, ll y) {ll res = (x * y) / __gcd(x, y); return res;}
ll power(ll x, ll y) {if (y < 0) return 1; ll res = 1; x %= MOD; while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;}
void iofoj(){
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
freopen("error.txt","w",stderr);
#endif
}
#define F first
#define S second
map<ll,ll>mp;
ll ans(ll a,ll b)
{
if(a>=b)return mp[b]=a-b;
if(mp.find(b)!=mp.end())return mp[b];
ll sum=b-a;
if(b%2==0)
{
return mp[b]=min(sum,ans(a,b/2)+1);
}
return mp[b]=min(sum,min(ans(a,(b+1)/2),ans(a,(b-1)/2))+2);
}
void solution()
{
ll k,i,j,m,w,n;
ll a,b;
cin>>a>>b;
cout<<ans(a,b);
}
int main(){
fio
//iofoj();
// ll t;
// cin>>t;
// for(ll i=1;i<=t;i++)
solution();
return 0;
}
|
/**
* code generated by JHelper
* More info: https://github.com/AlexeyDmitriev/JHelper
* @author
*/
#include <iostream>
#include <fstream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
inline int inint(istream& in) {int x; in >> x; return x;}
inline ll inll(istream& in) {ll x; in >> x; return x;}
inline string instr(istream& in) {string x; in >> x; return x;}
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)
class AChinchirorin {
public:
void solve(std::istream& in, std::ostream& out) {
int a = inint(in);
int b = inint(in);
int c = inint(in);
if(a == b){
out << c << endl;
}else if(b == c){
out << a << endl;
}else if(a == c){
out << b << endl;
}else{
out << 0 << endl;
}
}
};
int main() {
AChinchirorin solver;
std::istream& in(std::cin);
std::ostream& out(std::cout);
solver.solve(in, out);
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
#define f(i,a,b) for(int i=a; i<b; i++)
#define fr(i,a,b) for(int i=a; i>=b; i--)
#define fll(i,a,b) for(ll i=a; i<b; i++)
#define frll(i,a,b) for(ll i=a; i>=b; i--)
typedef vector<int> vi;
typedef long long int ll;
typedef vector<ll> vll;
#define fastio std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PI 3.1415926535
ll Mod = 1e9+7;
ll N = 1e5;
// ll Mod = 998244353;
// ll mult(ll a, ll b) {
// ll ret = 1;
// ret = ((a%Mod) * (b%Mod))%Mod;
// return ret;
// }
// ll power(ll a, ll b = Mod-2) {
// if(b == 0) return 1;
// ll ret = 1;
// while(b) {
// if(b&1) {
// ret = mult(ret,a);
// }
// a = mult(a,a);
// b>>=1;
// }
// return ret;
// }
// ll sub(ll a, ll b) {
// ll ret = (a%Mod - b%Mod + Mod)%Mod;
// return ret;
// }
// void seive(vector<bool> &status) {
// f(i,2,2e6+1) {
// if(status[i]) {
// for(ll j = i*i; j<=2e6; j+=i) status[j] = 0;
// }
// }
// }
// int getmex(vi& occr, int n, int mex) {
// for(int i = mex; i<n; i++) {
// if(occr[i] == 0) return i;
// }
// return n;
// }
// int gcd(int a, int b) {
// if(b == 0) return a;
// return gcd(b,a%b);
// }
void solve_case() {
int n;
cin>>n;
vll a(n), p_max(n,-1), p_sum(n,0);
f(i,0,n) {
cin>>a[i];
if(i == 0) {
p_max[i] = a[i];
p_sum[i] = a[i];
} else {
p_max[i] = max(a[i],p_max[i-1]);
p_sum[i] = p_sum[i-1] + a[i];
}
}
f(i,1,n) p_sum[i] = p_sum[i] + p_sum[i-1];
ll p_ans = 0, ans = 0;
f(i,0,n) {
cout<<p_sum[i] + (i+1)*p_max[i]<<'\n';
}
return;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
fastio;
// vector<bool> status(2e6+1,1);
int t = 1;
// vi primes;
// seive(status);
// f(i,2, 2e6+1) {
// if(i > 5000) {
// break;
// }
// if(status[i]) primes.push_back(i);
// }
// cin>>t;
while(t--) {
solve_case();
}
} |
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// #include<ext/pb_ds/tag_and_trait.hpp>
// using namespace __gnu_pbds;
// #include<boost/multiprecision/cpp_int.hpp>
// namespace multiprecisioninteger = boost::multiprecision;
// using cint=multiprecisioninteger::cpp_int;
using namespace std;
using ll=long long;
#define double long double
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
// using llset=tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>;
#define For(i,a,b) for(i=a;i<(ll)b;++i)
#define bFor(i,b,a) for(i=b,--i;i>=(ll)a;--i)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N,0)
#define brep1(i,N) bFor(i,N,1)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define eb emplace_back
#define print(x) cout<<x<<endl
#define printyes print("Yes")
#define printno print("No")
#define printYES print("YES")
#define printNO print("NO")
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
#define matoutput(v) do{for(auto outimat:v)output(outimat);}while(0)
const ll mod=1000000007;
// const ll mod=998244353;
const ll inf=1LL<<60;
const double PI=acos(-1);
const double eps=1e-9;
template<class T,class E> ostream& operator<<(ostream& os,pair<T,E>& p){return os<<"{"<<p.first<<","<<p.second<<"}";}
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;}
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;}
void startupcpp(){
cin.tie(0);
ios::sync_with_stdio(false);
cout<<fixed<<setprecision(15);
}
double distance(ddatas x,ddatas y){
double a=x.first-y.first,b=x.second-y.second;
return sqrt(a*a+b*b);
}
ll modinv(ll a,ll m=mod) {
ll b=m,u=1,v=0,t;
while(b){
t=a/b;
a-=t*b; swap(a,b);
u-=t*v; swap(u,v);
}
return (u+m)%m;
}
ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}
vec modncrlistp,modncrlistm;
ll modncr(ll n,ll r){
if(n<r)return 0;
ll i,size=modncrlistp.size();
if(size<=n){
modncrlistp.resize(n+1);
modncrlistm.resize(n+1);
if(!size){
modncrlistp[0]=modncrlistm[0]=1;
size++;
}
For(i,size,n+1){
modncrlistp[i]=modncrlistp[i-1]*i%mod;
modncrlistm[i]=modinv(modncrlistp[i]);
}
}
return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}
ll modpow(ll a,ll n,ll m=mod){
ll res=1;
while(n>0){
if(n&1)res=res*a%m;
a=a*a%m;
n>>=1;
}
return res;
}
ll gcd(ll a,ll b){if(!b)return abs(a);return (a%b==0)?abs(b):gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll countdigits(ll n){
ll ans=0;
while(n){n/=10;ans++;}
return ans;
}
ll sumdigits(ll n){
ll ans=0;
while(n){ans+=n%10;n/=10;}
return ans;
}
ll N,M,K,H,W,A,B,C,D;
string s,t;
ll ans;
int main(){
startupcpp();
// int codeforces;cin>>codeforces;while(codeforces--){
ll i,j;
cin>>s>>t;
if(s[0]=='Y')t[0]+='A'-'a';
print(t);
// }
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(a) (a).begin(),(a).end()
const int INF = 1 << 30;
const int MOD = 1e9 + 7;
const long long LINF = 1LL << 60;
const double PI = 3.141592653589793;
const int NIL = -1;
const int MAX = 1100000;
const int LARGE = 10000;
double X, Y, R;
ll XX, YY, RR;
bool inside(ll x, ll y) {
x *= LARGE; y *= LARGE;
return (x - XX) * (x - XX) + (y - YY) * (y - YY) <= RR * RR;
}
ll calc_lower(ll x) {
ll ok = floor(Y);
ll er = ok - floor(R) - 10;
if (!inside(x, ok)) return 0;
while(abs(ok - er) > 1) {
ll mid = (ok + er) / 2;
if (inside(x, mid)) ok = mid;
else er = mid;
}
return floor(Y) - er;
}
ll calc_upper(ll x) {
ll ok = floor(Y) + 1;
ll er = ok + floor(R) + 10;
if (!inside(x, ok)) return 0;
while(abs(ok - er) > 1) {
ll mid = (ok + er) / 2;
if (inside(x, mid)) ok = mid;
else er = mid;
}
return er - (floor(Y) + 1);
}
int main() {
cin >> X >> Y >> R;
X -= floor(X);
Y -= floor(Y);
XX = (ll) round(X * LARGE);
YY = (ll) round(Y * LARGE);
RR = (ll) round(R * LARGE);
ll ans = 0;
for (ll x = floor(X - R - 10); x < floor(X + R + 10); x++) {
ans += calc_upper(x) + calc_lower(x);
}
cout << ans << endl;
}
|
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
//#pragma GCC target("avx,avx2")
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
//# include <x86intrin.h>
# 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;
template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define For(i,x,y) for (ll i = x; i <= y; i ++)
#define FOr(i,x,y) for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to... Red
void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
void setIO(string s = "") {
// cin.exceptions(cin.failbit);
// throws exception when do smth illegal
// ex. try to read letter into int
if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
}
const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 6e5+5;
const int M = 22;
const int pri = 997;
const int Magic = 2101;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());
int rnd (int l, int r) {
return uniform_int_distribution<int> (l, r)(gen);
}
int c[(1<<18)];
int e[18][18];
int dp[(1<<18)];
vector<int> w[18];
void solve() {
int n, m;
cin >> n >> m;
for (int i = 0; i < m; ++i) {
int a, b;
cin >> a >> b;
--a, --b;
e[a][b] = e[b][a] = 1;
}
for (int msk = (1<<n)-1; msk; --msk) {
c[msk] = 1;
for (int i = 0; i < n; ++i) if(msk&(1<<i)) {
for (int j = i+1; j < n; ++j) if(msk&(1<<j) && e[i][j] == 0) {
c[msk] = 0;
}
}
dp[msk] = __builtin_popcount(msk);
if(c[msk] && msk>0) {
int lst = -1;
for (int i = 0; i < n; ++i)
if(msk&(1<<i)) {
lst =i;
}
int wast = 0;
for (auto x : w[lst]) {
if((x&msk) == msk) {
wast=1;
break;
}
}
if(!wast)
w[lst].pb(msk);
dp[msk] = 1;
}
}
for (int i = 0; i < n; ++i) {
for (int msk = 0; msk < (1<<n); ++msk) {
if(msk&(1<<i)) {
dp[msk^(1<<i)] = min(dp[msk^(1<<i)], dp[msk]);
}
}
}
for (int i = 0; i < n; ++i) {
for (int msk = 0; msk < (1<<n); ++msk) {
if(dp[msk] <= 1)
continue;
for(auto j : w[i])
dp[msk] = min(dp[msk], dp[msk^(msk&j)] + 1);
}
}
cout << dp[(1<<n)-1] << '\n';
}
int main () {
SpeedForce;
int T = 1;
//cin >> T;
while(T--) solve();
return Accepted;
}
// B...a
| #include <bits/stdc++.h>
using namespace std;
#define ar array
#define ll long long
#define all(x) (x).begin(), (x).end()
ll a,b,n,m,adj[18],dp[1<<18],s[1<<18];
int chrom(){
ll al=1<<n;
ll bigp=1077563119;
dp[0]=1;
for(ll i=0;i<al;i++){
if ((n-__builtin_popcount(i))%2){
s[i]=1;
}
else{
s[i]=-1;
}
}
for(ll i=1;i<al;i++){
int ctz = __builtin_ctz(i);
dp[i]=dp[i-(1<<ctz)]+dp[(i-(1<<ctz))&adj[ctz]];
dp[i]=dp[i]%bigp;
}
for(int k=1;k<n;k++){
int ans=0;
for(ll i=0;i<al;i++){
s[i]=s[i]*dp[i];
ans=ans+s[i];
}
if(ans!=0){
return k;
}
}
return n;
}
int main() {
cin>>n>>m;
memset(adj,0,sizeof(adj));
for(int i=0;i<m;i++){
cin>>a>>b;
a=a-1;
b=b-1;
adj[a]|=1<<b;
adj[b]|=1<<a;
}
cout<<chrom()<<endl;
return 0;
} |
#define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
typedef long long int64;
typedef pair<int, int> ii;
#define SZ(x) (int)((x).size())
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }
struct fast_ios {
fast_ios() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
};
} fast_ios_;
int main() {
int64 n;
cin >> n;
vector<int64> ret;
for (int64 i = 1; i * i <= n; ++i) {
if (n % i == 0) {
ret.push_back(i);
if (i != n / i) ret.push_back(n / i);
}
}
sort(ret.begin(), ret.end());
for (auto& x : ret) cout << x << '\n';
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr<< #x << ": "<< x <<"\n";
#define rep(i, n) for(int i=0; i<(int)(n); i++)
template <class T>
bool chmin(T &a, const T &b){
if(a > b){
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;
}
int main(){
ll N;
cin>>N;
for(ll i=1; i<=N; i++){
//cout<<i<<" "<<1+i*(i-1)/2<<endl;
if(2*i+i*(i-1) >= 2*N){
cout<<i<<endl;
return 0;
}
}
return 0;
} |
#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>
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 MOD 998244353ll
//-------------------------- ^ DONT TOUCH ^-----------------------------------------------------------------
const int lm = 3001;
int n, k;
ll N[lm];
ll M[lm][lm];
ll dp(int _n, int _k) {
if (_n == 0) {
if (_k == 0) return 1;
return 0;
}
if (_k == 0) return 0;
if (_n < _k) return 0;
if (M[_n][_k] == -1) {
ll d1 = dp(_n-1, _k-1);
ll d2 = dp(_n, _k * 2);
M[_n][_k] = (d1 + d2) % MOD;
}
return M[_n][_k];
}
void solve() {
cin >> n >> k;
for (int i = 0 ; i <= n; i++)
for (int j = 0; j <=n ; j++)
M[i][j] = -1;
cout << dp(n, k) % MOD << endl;
}
int main(int argc, const char * argv[]) {
ios_base::sync_with_stdio(0);cin.tie(0);
//cin >> test;
for (int testCount = 1; testCount <= test; testCount++)
{
#ifdef _OLIMPOLOCAL
cout << "---------------Test case " << testCount << "---------------"<< endl;
#endif
solve();
}
return 0;
} | #include <bits/stdc++.h>
// 1. dp
typedef long double ld;
#define int long long
#define gcd __gcd
#define endl "\n"
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define mod2 998244353
#define maxe *max_element
#define mine *min_element
#define inf 1e18
#define pb push_back
#define all(x) x.begin(), x.end()
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define sz(x) (int)(x).size()
#define mk make_pair
#define deci(x, y) fixed<<setprecision(y)<<x
#define w(t) int t; cin>>t; while(t--)
#define nitin ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define PI 3.141592653589793238
using namespace std;
int dp[4000][4000];
int solve(int n,int k){
if(k>n) return 0;
if(n==0) return 1;
if(k==0) return 0;
if(dp[n][k]!=0)
return dp[n][k];
return dp[n][k]=(solve(n-1,k-1)+solve(n,2*k))%mod2;
}
void solve() {
int n,k;
cin>>n>>k;
cout<<solve(n,k)<<endl;
}
int32_t main() {
nitin;
solve();
}
|
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;
class CombinationPascal {
public:
CombinationPascal(int n) {
N = n;
dp.assign(n + 1, vector<ll>(n + 1));
dp[0][0] = 1;
REP(i, 1, n + 1) {
REP(j, 0, i + 1) {
if (j - 1 >= 0)
dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j];
else
dp[i][j] = dp[i - 1][j];
}
}
}
ll cnr(int n, int k) {
return dp[n][k];
}
private:
int N;
vector<vector<ll>> dp;
};
CombinationPascal comb(65);
int main() {
int A, B; ll K; cin >> A >> B >> K;
string ans = "";
int L = A + B;
K--;
REP(i, 0, L) {
ll c = comb.cnr(A + B - 1, B);
if (A && K < c) {
ans += 'a';
A--;
} else {
ans += 'b';
B--;
K -= c;
}
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using ll = long long;
using std::cin;
using std::cout;
using std::endl;
std::mt19937 rnd(std::chrono::steady_clock::now().time_since_epoch().count());
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;
std::chrono::system_clock::time_point start, end;
void solve()
{
std::mt19937 kkt(89);
int _, m; cin >> _ >> m;
const int n = 20;
std::vector<std::string> vs(m);
for (int i = 0; i < m; ++i)
{
cin >> vs[i];
}
std::vector<std::pair<std::string, std::vector<int>>> a;
std::vector<int> r, gomi, used(m), nr;
for (int i = 0; i < m; ++i)
{
r.emplace_back(i);
}
while (not r.empty() and (int)a.size() < n)
{
std::string s;
std::vector<int> v;
std::shuffle(r.begin(), r.end(), kkt);
s = vs[r[0]];
v.emplace_back(r[0]);
used[r[0]] = true;
for (int jupi = 1; jupi < (int)r.size(); jupi++)
{
const std::string &t = vs[r[jupi]];
for (int i = 0; i < (int)s.size(); ++i)
{
const int len = std::min((int)s.size() - i, (int)t.size());
if((int)s.size() + (int)t.size() - len > n)
continue;
if(s.substr(i, len) == t.substr(0, len))
{
s += t.substr(len, (int)t.size() - len);
v.emplace_back(r[jupi]);
used[r[jupi]] = true;
break;
}
}
}
for(const auto &e : r)
{
if(not used[e])
{
const std::string &t = vs[e];
bool in = false;
for (int i = 0; i <= (int)s.size() - (int)t.size(); ++i)
{
if(s.substr(i, (int)t.size()) == t)
in = true;
}
if(in)
{
v.emplace_back(e);
used[e] = true;
}
else
{
gomi.emplace_back(e);
}
}
}
std::swap(gomi, r);
gomi.clear();
a.emplace_back(std::make_pair(s, v));
}
const double deadline = 2950;
while(true)
{
end = std::chrono::system_clock::now();
if(std::chrono::duration_cast<std::chrono::milliseconds>(end-start).count() > deadline)
break;
int h = rnd() % n;
nr = r;
for(const auto &e : a[h].second)
{
nr.emplace_back(e);
}
std::shuffle(nr.begin(), nr.end(), kkt);
std::string s;
std::vector<int> v;
s = vs[nr[0]];
v.emplace_back(nr[0]);
for (int jupi = 1; jupi < (int)r.size(); jupi++)
{
const std::string &t = vs[nr[jupi]];
for (int i = 0; i < (int)s.size(); ++i)
{
const int len = std::min((int)s.size() - i, (int)t.size());
if((int)s.size() + (int)t.size() - len > n)
continue;
if(s.substr(i, len) == t.substr(0, len))
{
s += t.substr(len, (int)t.size() - len);
v.emplace_back(nr[jupi]);
break;
}
}
}
if(v.size() > a[h].second.size())
{
for(const auto &e : a[h].second)
{
used[e] = false;
}
for(const auto &e : v)
{
used[e] = true;
}
gomi.clear();
for(const auto &e : nr)
{
if(not used[e])
{
const std::string &t = vs[e];
bool in = false;
for (int i = 0; i <= (int)s.size() - (int)t.size(); ++i)
{
if(s.substr(i, (int)t.size()) == t)
in = true;
}
if(in)
{
v.emplace_back(e);
used[e] = true;
}
else
{
gomi.emplace_back(e);
}
}
}
std::swap(gomi, r);
a[h] = std::make_pair(s, v);
}
}
std::vector<std::vector<char>> res(n, std::vector<char>(n, '.'));
for (int i = 0; i < (int)a.size(); ++i)
{
for (int j = 0; j < (int)a[i].first.size(); ++j)
{
res[i][j] = a[i].first[j];
}
}
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < n; ++j)
{
cout << res[i][j];
}
cout << "\n";
}
}
int main()
{
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
start = std::chrono::system_clock::now();
int kkt = 1;
//cin >> kkt;
while(kkt--)
solve();
return 0;
} |
// arc120_c
#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;
// 区間add, 区間sum
template<typename T>
struct LazySegmentTree{
int n;
vector<T> val;
vector<T> lazy;
vector<int> width;
explicit LazySegmentTree(int n_){
n = 1;
while (n < n_) n <<= 1;
val = vector<T>(n<<1, 0);
lazy = vector<T>(n<<1, 0);
width = vector<int>(n<<1, 1);
for (int i = n-2; i >= 0; i--) {
width[i] = width[i*2+1] + width[i*2+2];
}
}
void lazy_propagate(int k) {
val[k] += lazy[k] * width[k];
if (k < n-1) {
lazy[k*2+1] += lazy[k];
lazy[k*2+2] += lazy[k];
}
lazy[k] = 0;
}
void add(int a, int b, int k, int l, int r, int x) {
lazy_propagate(k);
if (b <= l || r <= a) {
return;
}
if (a <= l && r <= b) {
lazy[k] += x;
lazy_propagate(k);
return;
}
int mid = (l+r)/2;
add(a, b, k*2+1, l, mid, x);
add(a, b, k*2+2, mid, r, x);
val[k] = val[k*2+1] + val[k*2+2];
}
void add(int a, int b, int x) {
add(a, b, 0, 0, n, x);
}
T get_sum(int a, int b, int k, int l, int r) {
lazy_propagate(k);
if (b <= l || r <= a) {
return 0;
}
if (a <= l && r <= b) {
return val[k];
}
int mid = (l+r)/2;
T sl = get_sum(a, b, k*2+1, l, mid);
T sr = get_sum(a, b, k*2+2, mid, r);
return sl + sr;
}
T get_sum(int a, int b) {
return get_sum(a, b, 0, 0, n);
}
};
int main() {
#ifdef LOCAL
ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif
int N;
cin >> N;
vector<int> A(N), B(N);
REP(i, N) cin >> A[i];
REP(i, N) cin >> B[i];
map<int, vector<int>> mp;
REP_REV(i, N){
mp[A[i] + i].emplace_back(i);
}
LazySegmentTree<ll> st(N);
REP(i, N){
st.add(i, i+1, i);
}
ll ans = 0;
REP(i, N){
int x = B[i] + i;
if (mp[x].empty()){
print(-1);
return 0;
}
int idx = mp[x].back();
ans += st.get_sum(idx, idx+1);
mp[x].pop_back();
st.add(idx+1, N, -1);
// print(i, idx);
}
print(ans);
return 0;
}
| #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
//#include <atcoder/convolution>
//#include <atcoder/modint>
//using Modint = atcoder::modint998244353;
using namespace std;
typedef long long ll;
void ex_gcd(ll a, ll b, ll &d, ll &x, ll &y) {
if (!b) {
d = a;
x = 1;
y = 0;
} else {
ex_gcd(b, a % b, d, y, x);
y -= a / b * x;
}
}
ll inv(ll a, ll n) {
ll d, x, y;
ex_gcd(a, n, d, x, y);
return d == 1 ? (x % n + n) % (n / d) : -1;
}
ll gcd(ll x, ll y) {
if (y == 0) return x;
return gcd(y, x % y);
}
const int maxn = 200005;
const int mod = 998244353;
int idx[maxn];
struct BIT {
int c[maxn];
void add(int pos){
while(pos<maxn){
c[pos]++;
pos+=(pos&-pos);
}
}
int query(int pos){
int ret = 0;
while(pos>0){
ret += c[pos];
pos-=(pos&-pos);
}
return ret;
}
}bit;
int main() {
#ifdef suiyuan2009
freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
int n;
cin>>n;
unordered_map<int,vector<int>>mpa, mpb;
for(int i=0;i<n;i++){
int x;
cin>>x;
mpa[x+i].push_back(i);
}
for(int i=0;i<n;i++){
int x;
cin>>x;
mpb[x+i].push_back(i);
}
ll ret= 0;
for(auto&pr: mpa){
if(mpb.find(pr.first)==mpb.end()||mpb[pr.first].size()!=pr.second.size()){
cout<<-1<<endl;
return 0;
}
auto&a = pr.second;
auto&b = mpb[pr.first];
for(int i=0;i<a.size();i++){
idx[b[i]] = a[i];
}
}
for(int i=0;i<n;i++){
int tt = idx[i];
int tmp = bit.query(maxn-1)-bit.query(tt+1);
int tmp2 = tt + tmp;
ret += abs(tmp2-i);
bit.add(tt+1);
}
cout<<ret<<endl;
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
namespace WHH
{
typedef long long ll;
int N;
ll ans;
inline ll gcd(ll a,ll b)
{return ((b==0)?a:gcd(b,a%b));}
inline ll lcm(ll a,ll b)
{return a/gcd(a,b)*b;}
int work()
{
scanf("%d",&N);
ans = 1;
for(int i=2;i<=N;i++) ans = lcm(ans,i);
++ans;
printf("%lld",ans);
return 0;
}
}
int main() {return WHH::work();} | #include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<cstdlib>
#include<bitset>
#include<stack>
#define fio cin.tie(0);ios_base::sync_with_stdio(false)
#define ll long long
using namespace std;
int main(){
ll int k;
cin>>k;
ll int a = 1;
for(ll int i=2;i<=k;i++){
a=a*i/__gcd(a,i);
}
cout<<a+1<<endl;
} |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, a, b) for (int i = a; i >= b; i--)
typedef long long LL;
const int mod = 998244353;
const int inf = 0x3f3f3f3f;
const int N = 4e5 + 5;
int n, m, a[N], b[N];
LL ans = 4e17, suf[N], pre[N];
int main() {
cin>>n>>m;
rep (i, 1, n) cin>>a[i];
sort(a + 1, a + n + 1);
rep (i, 1, m) cin>>b[i];
sort(b + 1, b + m + 1);
per (i, n, 1) suf[i] = suf[i + 1] + a[i]*(i&1 ? 1 : -1);
rep (i, 1, n) pre[i] = pre[i - 1] + a[i]*(i&1 ? -1 : 1);
rep (i, 1, n) {
int pos = lower_bound(b + 1, b + m + 1, a[i]) - b;
if (pos != m + 1) ans = min(ans, pre[i - 1] + suf[i + 1] + b[pos] - a[i]);
if (pos != 1) ans = min(ans, pre[i - 1] + suf[i + 1] + a[i] - b[pos - 1]);
}
printf("%lld\n", ans);
} | #include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=1e5+10,mod=998244353;
typedef long long LL;
LL qpow(LL x,LL k){
LL res=1;
while(k){
if(k&1)res=res*x%mod;
x=x*x%mod;
k>>=1;
}
return res;
}
int main(){
long long n,m,k;
scanf("%lld%lld%lld",&n,&m,&k);
if(n==1){
printf("%lld",qpow(k,m));
}
else if(m==1){
printf("%lld",qpow(k,n));
}
else{
LL res=0;
for(int i=1;i<=k;i++){//最小值的最大值是i时
res=(res+((qpow(i,n)-qpow(i-1,n)+mod)*qpow(k-i+1,m)%mod)+mod)%mod;
}
cout<<res;
}
return 0;
} |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
//#pragma GCC optimize("O3")
using namespace std;
using namespace __gnu_pbds;
auto random_address = [] { char *p = new char; delete p; return uint64_t(p); };
const uint64_t SEED = chrono::steady_clock::now().time_since_epoch().count() * (random_address() | 1);
mt19937_64 rng(SEED);
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int n;
string s;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n;
cin>>s;
s=" "+s;
if(s[1]!=s[n])
{
cout<<1<<'\n';
return 0;
}
int nrlit=0;
for(int i=1;i<n;i++)
if(s[i]!=s[1]&&s[i+1]!=s[1])
{
cout<<2;
return 0;
}
cout<<-1;
return 0;
}
| /*
========= Plozia =========
Author:Plozia
Problem:T2
Date:2021/3/21
========= Plozia =========
*/
#include <bits/stdc++.h>
typedef long long LL;
const int MAXN = 500 + 10;
const LL P = 998244353;
int n, m, a[MAXN][MAXN];
LL sum;
int read()
{
int sum = 0, fh = 1; char ch = getchar();
for (; ch < '0' || ch > '9'; ch = getchar()) fh -= (ch == '-') << 1;
for (; ch >= '0' && ch <= '9'; ch = getchar()) sum = (sum << 3) + (sum << 1) + (ch ^ 48);
return (fh == 1) ? sum : -sum;
}
LL ksm(LL a, LL b, LL p)
{
LL ans = 1 % p;
for (; b; b >>= 1, a = a * a % p)
if (b & 1) ans = ans * a % p;
return ans;
}
int main()
{
n = read(), m = read();
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= m; ++j)
{
char ch = getchar();
while (ch == ' ' || ch == '\n' || ch == '\r') ch = getchar();
if (ch == 'R') a[i][j] = 1;
if (ch == 'B') a[i][j] = 2;
}
for (int i = 1; i <= n; ++i)
{
int Tag = a[i][1];
int x = i, y = 1;
bool flag = 0;
for (;;)
{
--x; ++y;
if (x < 1 || y > m) break ;
if (Tag == 0 && a[x][y] != 0) { Tag = a[x][y]; }
else if (a[x][y] != 0)
{
flag = 1;
if (a[x][y] != Tag) { printf("0\n"); return 0; }
}
}
if (Tag == 0 && flag == 0) ++sum;
}
for (int i = 2; i <= m; ++i)
{
int Tag = a[n][i];
int x = n, y = i;
bool flag = 0;
for (;;)
{
--x; ++y;
if (x < 1 || y > m) break ;
if (Tag == 0 && a[x][y] != 0) { Tag = a[x][y]; }
else if (a[x][y] != 0)
{
flag = 1;
if (a[x][y] != Tag) { printf("0\n"); return 0; }
}
}
if (Tag == 0 && flag == 0) ++sum;
}
printf("%lld\n", ksm(2, sum, P)); return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int INF = int (1e9) + int (1e5);
const ll INFL = ll(2e18) + ll(1e10);
const ui MOD = 1E9 + 7;
const double EPS = 1e-9;
#define FOR(i,n) for (int i=0;i<(n);++i)
#define ROF(i,x) for(int i = (x) ; i >= 0 ; --i)
#define MP make_pair
#define all(a) (a).begin(),(a).end()
#define ODD(x) ( ((x)&1)==0?0:1 )
#define SIGN(x) ( ((x) > 0) - ((x) < 0) )
#define dbg(x) cerr << #x"= " << x << endl
std::mt19937_64 generator(std::chrono::system_clock::now().time_since_epoch().count());
inline ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a, ll b) { return a ? gcd(b%a, a): b; }
ll lcm(ll a, ll b) { return a / gcd(a,b) * b; }
void READ(bool _local){
ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef _DEBUG
if (_local)
freopen ("in.txt", "r", stdin);
#endif
}
int main() {
READ(0);
int n;cin>>n;
vi a(n);
FOR(i,n) cin>>a[i];
sort(all(a));
ll ret=a[0]+1;
for(int i=1;i<n;++i){
ret = ret * (a[i]-a[i-1]+1) % MOD;
}
cout << ret;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define Mp make_pair
#define pb push_back
using ll = long long;
using db = double;
using pii = pair<int, int>;
using vi = vector<int>;
mt19937 mrand(time(0));
ll get(ll r) { return ((ll)mrand() * mrand() % r + r) % r; }
ll get(ll l, ll r) { return get(r - l + 1) + l; }
int n, x[20], y[20], z[20], f[1 << 17][17], ans = 1e9;
int dis(int i, int j) { return abs(x[i] - x[j]) + abs(y[i] - y[j]) + max(0, z[j] - z[i]); }
signed main() {
scanf("%d", &n);
for(int i = 0; i < n; i++)
scanf("%d %d %d", &x[i], &y[i], &z[i]);
memset(f, 0x3f, sizeof(f)), f[1][0] = 0;
for(int S = 2; S < 1 << n; S++)
for(int i = 0; i < n; i++) if(S >> i & 1)
for(int j = 0; j < n; j++) if((S >> j & 1) && j != i)
f[S][i] = min(f[S][i], f[S ^ (1 << i)][j] + dis(j, i));
for(int i = 0; i < n; i++) ans = min(ans, f[(1 << n) - 1][i] + dis(i, 0));
printf("%d\n", ans);
fprintf(stderr, "time=%.4f\n", (db)clock()/CLOCKS_PER_SEC);
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int main(){
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(ios::badbit | ios::failbit);
int n;
cin >> n;
vector<vector<int>> a(n, vector<int>(n));
int ii = 0, jj = 0;
for(auto i = 0; i < n; ++ i){
for(auto j = 0; j < n; ++ j){
cin >> a[i][j];
if(a[ii][jj] > a[i][j]){
ii = i, jj = j;
}
}
}
for(auto i = 1; i < n; ++ i){
for(auto j = 1; j < n; ++ j){
if(a[i - 1][j] - a[i - 1][j - 1] != a[i][j] - a[i][j - 1]){
cout << "No\n";
return 0;
}
}
}
cout << "Yes\n";
for(auto i = 0; i < n; ++ i){
cout << a[i][jj] << " ";
}
cout << "\n";
for(auto j = 0; j < n; ++ j){
cout << a[ii][j] - a[ii][jj] << " ";
}
cout << "\n";
return 0;
}
/*
*/
////////////////////////////////////////////////////////////////////////////////////////
// //
// Coded by Aeren //
// //
//////////////////////////////////////////////////////////////////////////////////////// | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rrep(i, n) for (int i = 1; i < (int)(n+1); ++i)
const long long INF = 1LL<<60;
int main() {
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int N;
cin>>N;
ll C[N][N];
ll A[N];
ll B[N];
rep(i,N){
A[i]=INF;
B[i]=INF;
}
rep(i,N){
rep(j,N){
cin>>C[i][j];
A[i]=min(A[i],C[i][j]);
B[j]=min(B[j],C[i][j]);
}
}
bool an=true;
rep(i,N){
rep(j,N){
if(A[i]+B[j]<C[i][j]){
an=false;
}
}
}
rep(i,N){
rep(j,N){
A[i]=min(A[i],C[i][j]-B[j]);
B[j]=C[i][j]-A[i];
}
}
rep(i,N){
rep(j,N){
if(A[i]+B[j]!=C[i][j]){
an=false;
}
}
}
if(an==false){
cout<<"No"<<endl;
}
else{
cout<<"Yes"<<endl;
rep(i,N){
cout<<A[i];
if(i!=N-1){
cout<<" ";
}
else{
cout<<""<<endl;
}
}
rep(i,N){
cout<<B[i];
if(i!=N-1){
cout<<" ";
}
else{
cout<<""<<endl;
}
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main(){
int n, x;
cin >> n >> x;
int v[n], p[n];
for (int i=0; i<n; i++){
cin >> v[i] >> p[i];
}
int alcohol;
for (int i=0; i<n; i++){
alcohol += v[i]*p[i];
if (alcohol > x*100){
cout << i + 1 << endl;
return 0;
}
}
cout << -1 << endl;
} | /*/ Author: _Math.man /*/
#include<bits/stdc++.h>
using namespace std;
/*/---------------------------Defines-----------------------------------------/*/
#pragma GCC optimize("Ofast")
#define int long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define eb emplace_back
#define fn for(int i =0 ;i <n;i++)
#define fn1 for( int i =1;i<=n; i++)
#define fm for(int j =0 ;j <m;j++)
#define fm1 for(int j =1;j<=m;j++)
#define fi first
#define se second
#define endl '\n'
#define PI 3.14159265358979323846
#define MOD 1000000007
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
const int N = 2e6+5;
const int INF = 1e18L;
//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
/*/-----------------------------Debug begins----------------------------------/*/
vector<string> split(const string& s, char c) {
vector<string> v; stringstream ss(s); string x;
while (getline(ss, x, c)) v.emplace_back(x); return move(v);
}
template<typename T, typename... Args>
inline string arrStr(T arr, int n) {
stringstream s; s << "[";
for(int i = 0; i < n - 1; i++) s << arr[i] << ",";
if(n>0)
s << arr[n - 1] ;
s<< "]";
return s.str();
}
#define trace(args...) {__trace_begin(__LINE__); __trace(split(#args, ',').begin(), args);}
inline void __trace_begin(int line) { cerr << "#" << line << ": "; }
template<typename T> inline void __trace_out_var(vector<T> val) { cerr << arrStr(val, val.size()); }
template<typename T> inline void __trace_out_var(T* val) { cerr << arrStr(val, 10); }
template<typename T> inline void __trace_out_var(T val) { cerr << val; }
inline void __trace(vector<string>::iterator it) { cerr << endl; }
template<typename T, typename... Args>
inline void __trace(vector<string>::iterator it, T a, Args... args) {
cerr << it->substr((*it)[0] == ' ', it->length()) << "=";
__trace_out_var(a);
cerr << "; ";
__trace(++it, args...);
}
/*/-----------------------------Code begins----------------------------------/*/
int ar[N];
int dp[N];
int go(int n){
return (n*(n+1))/2;
}
signed main(){
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
IOS;
int T=1;
// cin >> T;
while(T--){
int n;
cin >> n ;
int ans=0;
fn{
int x,y;
cin >> x>>y;
ans+=go(y)-go(x-1);
}
cout <<ans<<'\n';
}
return 0;
} |
/*#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")*/
// only when really needed
/* GNU G++17 7.3.0: No long long for faster code
GNU G++17 9.2.0 (64 bit, msys 2): Long long only for faster code */
#include <bits/stdc++.h>
#define for1(i,a,b) for (int i = a; i <= b; i++)
#define for2(i,a,b) for (int i = a; i >= b; i--)
#define int long long
#define sz(a) (int)a.size()
#define pii pair<int,int>
/*
__builtin_popcountll(x) : Number of 1-bit
__builtin_ctzll(x) : Number of trailing 0
*/
#define PI 3.1415926535897932384626433832795
#define INF 1000000000000000000
#define MOD 1000000007
#define MOD2 1000000009
#define EPS 1e-6
using namespace std;
signed main() {
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
// freopen("cf.inp", "r", stdin);
// freopen("cf.out", "w", stdout);
int n, k, cur = 0;
vector<pii> v;
cin >> n >> k;
for1(i,1,n) {
int a, b;
cin >> a >> b;
v.push_back({a, b});
}
sort(v.begin(), v.end());
for (auto p : v) {
int a = p.first, b = p.second;
if (a - cur > k) {
cout << cur + k;
return 0;
}
k -= a - cur;
k += b;
cur = a;
}
cout << cur + k;
} | #define MOD_TYPE 2
#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 0
#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 int INF = (int)1e9 + 10;
constexpr ll LINF = (ll)4e18;
constexpr double PI = acos(-1.0);
constexpr double EPS = 1e-7;
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 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;
ll x;
cin >> n >> x;
vector<ll> a(n);
rep(i, n) cin >> a[i];
map<ll, ll> mp;
mp[x] = 1;
rep(i, n - 1)
{
map<ll, ll> nxt;
for (auto [r, v] : mp)
{
ll m = a[i + 1] / a[i];
ll t = r / a[i];
ll b[3];
b[0] = m - t % m;
b[1] = b[0] - m, b[2] = b[0] + m;
rep(j, 3)
{
if (abs(b[j]) < m)
nxt[r + b[j] * a[i]] += v;
}
}
mp = move(nxt);
}
ll sum = 0;
for (auto [k, v] : mp)
{
if (k % a[n - 1] == 0)
sum += v;
}
cout << sum << "\n";
}
int main()
{
solve();
} |
#include<bits/stdc++.h>
using namespace std;
long long x, y, a[200005], b[200005], ans, n;
priority_queue <int> pq;
main(){
cin>>n;
for (int i=1; i<=n; i++)cin>>a[n-i+1],ans+=a[n-i+1];
for (int i=1; i<=n; i++)cin>>b[i],ans+=b[i];
for (int i=1; i<=n; i++){
pq.push(-a[i]);
pq.push(-b[i]);
ans+=pq.top();
pq.pop();
}
cout<<ans;
} | #include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=(n)-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,1,0,-1,1,-1,1,-1};
template <typename T> inline bool chmax(T &a, T b) {
return ((a < b) ? (a = b, true) : (false));
}
template <typename T> inline bool chmin(T &a, T b) {
return ((a > b) ? (a = b, true) : (false));
}
int main(){
ll n;cin >> n;
vl a(n),b(n);rep(i,n)cin >> a[i];rep(i,n)cin >> b[i];rev(all(a));
priority_queue<ll,vl,greater<ll>> que;
ll sum=accumulate(all(a),0LL)+accumulate(all(b),0LL);
ll ans=0;
rep(i,n){
que.push(a[i]);que.push(b[i]);
ans+=que.top();que.pop();
}
cout << sum-ans <<endl;
} |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define FOR(i,a,b,c) for(int i=a;i<b;i+=c)
#define REV(i,a,b,c) for(int i=a;i>=b;i-=c)
#define all(x) x.begin(),x.end()
#define Dhruv main
const int pinf=LLONG_MAX;
const int ninf=LLONG_MIN;
const int mod=1000000007;
using namespace std;
using namespace __gnu_pbds;
typedef tree
<int,null_type,less <int>,rb_tree_tag,tree_order_statistics_node_update>
indexed_set;
typedef tree
<int,null_type,less_equal <int>,rb_tree_tag,tree_order_statistics_node_update>
indexed_multiset;
template <typename T>
istream & operator>>(istream &is, vector<T> &v) {
for(auto &data:v){
is>>data;
}
return is;
}
template <typename T>
ostream & operator<<(ostream &os,const vector<T> &v) {
for(auto &data:v){
os<<data<< " ";
}
return os;
}
int32_t Dhruv(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int T=1;
while(T--){
int a,b;
cin>>a>>b;
if(min(a,b)+3>max(a,b)) cout<< "Yes\n";
else cout<< "No\n";
}
#ifdef LOCAL
cout<< "Time Elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<< "s\n";
#endif
return 0;
}
| #include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <bitset>
#include <math.h>
#include <chrono>
#include <random>
#include <assert.h>
#include <functional>
using namespace std ;
using ll = long long ;
using ld = long double ;
template<class T> using V = vector<T> ;
template<class T> using VV = V<V<T>> ;
using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end()
ll mod = 998244353 ;
long double pie = acos(-1) ;
ll INF = 1000000000000 ;
void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
void fix_cout(){cout << fixed << setprecision(20) ;}
template<class T> void chmax(T &a,T b){ if(a<b) a = b ;}
template<class T> void chmin(T &a,T b){ if(a>b) a = b ;}
int main(){
int n ; cin >> n ;
V<int> a(n) ;
for(auto &i:a) cin >> i ;
int mx = -1 ;
int ans = -1 ;
for(int i=2;i<=1000;i++){
int cnt = 0 ;
for(int j=0;j<n;j++) cnt += (a[j]%i==0) ;
if(cnt>mx){
mx = cnt ;
ans = i ;
}
}
cout << ans << endl ;
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
int get_smaller_half(ll n) {
string s = to_string(n);
int nsize = s.length();
if (nsize % 2 == 1) {
exit(9);
}
int M = nsize / 2;
string lhss, rhss;
for (int i = 0; i < s.size(); ++i) {
if (i < M) {
lhss += s.at(i);
} else {
rhss += s.at(i);
}
}
int lhs = stoi(lhss), rhs = stoi(rhss);
if (lhs > rhs) {
return lhs - 1;
} else {
return lhs;
}
}
void solve(long long N) {
for (ll i = 1; i < 2e12; i++) {
if (stoll(to_string(i) + to_string(i)) > N) {
cout << i - 1 << endl;
return;
}
}
}
int main() {
long long N;
scanf("%lld", &N);
solve(N);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
int main() {
ll n;
cin >> n;
int ans = 0;
for(int i = 1; i<pow(10, log10(n)); i++){
string s = to_string(i);
s += s;
if(stol(s) > n){
break;
}
else{
ans++;
}
}
cout << ans << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pll;
#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(40)
const ll MOD = 1000000007;
const ll INF = (ll) 1e15;
struct Vertex {
ll p;
vector<ll> c;
ll num_edge = 0;
ll num_vertex = 0;
ll count = 0;
ll get = 1;
};
Vertex V[100005];
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll N;
cin >> N;
V[0].p = -1;
REP(i, N - 1) {
ll p;
cin >> p;
p--;
V[p].c.push_back(i + 1);
V[i + 1].p = p;
}
queue<ll> q;
REP(i, N) {
if (V[i].c.size() == 0)
q.push(i);
}
while (!q.empty()) {
// 頂点tに来たときに、いくつ取れるのか?を調べる
ll t = q.front();
q.pop();
V[t].num_edge = 0;
V[t].num_vertex = 1;
vector<ll> odd, even, even_good;
for (auto &child:V[t].c) {
V[t].num_edge += V[child].num_edge + 1;
V[t].num_vertex += V[child].num_vertex;
ll x = V[child].num_edge * 2LL + V[child].num_vertex;
if (x % 2 == 0) {
ll y = V[child].num_vertex - 2LL * V[child].get;
if (y > 0)
even_good.push_back(child);
else
even.push_back(child);
}
else
odd.push_back(child);
}
V[t].get = 1;
//! oddの頂点を相手にとられる数が少ない順に選んでいく選ぶ
sort(odd.begin(), odd.end(), [](ll a, ll b) {
ll x = V[a].num_vertex - 2LL * V[a].get;
ll y = V[b].num_vertex - 2LL * V[b].get;
return x > y;
});
{
REP(i, even_good.size()) {
V[t].get += V[even_good[i]].get;
}
REP(i, odd.size()) {
if (i % 2 == 0)
V[t].get += V[odd[i]].get;
else
V[t].get += V[odd[i]].num_vertex - V[odd[i]].get;
}
if ((odd.size() % 2LL) == 0) {
REP(i, even.size()) {
V[t].get += V[even[i]].get;
}
}
else {
REP(i, even.size()) {
V[t].get += V[even[i]].num_vertex - V[even[i]].get;
}
}
}
if (V[t].p >= 0) {
ll p = V[t].p;
V[p].count++;
if (V[p].count == V[p].c.size()) {
q.push(p);
}
}
}
cout << V[0].get << endl;
#if false
REP(i, N) {
cout << V[i].get << " ";
}
cout << endl;
REP(i, N) {
cout << V[i].num_vertex << " ";
}
cout << endl;
#endif
return 0;
} | #include <bits/stdc++.h>
using namespace std;
vector<int> c[100005];
int n, x, ans1[100005], ans2[100005];
bool msf(pair<int, int> x, pair<int, int> y){
if ((x.first+x.second)%2!=(y.first+y.second)%2){
if (x.first-x.second < 0 and (x.first-x.second)%2==0)
return 1;
if (y.first-y.second < 0 and (y.first-y.second)%2==0)
return 0;
return (x.first+x.second)%2;
}
return (x.first-x.second)<(y.first-y.second);
}
void dfs(int idx){
vector<pair<int, int> > dj;
ans1[idx]++;
for (int i=0; i<c[idx].size(); i++)
dfs(c[idx][i]);
for (int i=0; i<c[idx].size(); i++)
dj.push_back(make_pair(ans1[c[idx][i]], ans2[c[idx][i]]));
sort(dj.begin(), dj.end(), msf);
int cur = 1;
for (int i=0; i<dj.size(); i++){
if (cur==1){
ans1[idx]+=dj[i].first;
ans2[idx]+=dj[i].second;
if ((dj[i].first+dj[i].second)%2)
cur = 0;
}
else {
ans2[idx]+=dj[i].first;
ans1[idx]+=dj[i].second;
if ((dj[i].first+dj[i].second)%2)
cur = 1;
}
}
// cout << idx << " : " << ans1[idx] << "/" << ans2[idx] << endl;
}
int main (){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n;
for (int i=2; i<=n; i++){
cin >> x;
c[x].push_back(i);
}
dfs(1);
cout << ans1[1];
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout << fixed
#define endl '\n'
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
using P = pair<ll, ll>;
void solve(istream& cin, ostream& cout) {
ll n;
cin >> n;
vector<P> pa;
REP(i, 5) {
pa.push_back(P(5 - i, 15 - 3 * i));
}
ll ans = 0;
ll prev = LINF;
EACH(el, pa) {
ll now = pow(ll(10), el.second);
if (n / now >= 1) {
ans += el.first * (min(n, prev) - now + 1);
}
prev = now - 1;
}
cout << ans << endl;
}
#ifndef TEST
int main() {
OPTIMIZE_STDIO;
solve(cin, cout);
return 0;
}
#endif
| #include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using vi=vector<int>;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n;
string s;
cin >> n >> s;
ll ans=0;
for(int i=1;i<=n/2;++i){
int x=2*i;
vector<int> t(4,0);
rep(j,x){
if(s[j]=='A') ++t[0];
else if(s[j]=='T') ++t[1];
else if(s[j]=='G') ++t[2];
else ++t[3];
}
if(t[0]==t[1] && t[2]==t[3]) ++ans;
rep(j,n-x){
if(s[j]=='A') --t[0];
else if(s[j]=='T') --t[1];
else if(s[j]=='G') --t[2];
else --t[3];
if(s[j+x]=='A') ++t[0];
else if(s[j+x]=='T') ++t[1];
else if(s[j+x]=='G') ++t[2];
else ++t[3];
if(t[0]==t[1] && t[2]==t[3]) ++ans;
}
}
cout << ans << "\n";
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
//const lint MOD =1000000007;
const lint MOD=998244353;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
typedef map<lint,lint> M;
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
lint fac[MAX], finv[MAX], inv[MAX];
void COMinit()
{
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (lint i = 2; i < MAX; i++)
{
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
long long COM(lint n, lint k)
{
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
lint primary(lint num)
{
if (num < 2) return 0;
else if (num == 2) return 1;
else if (num % 2 == 0) return 0;
double sqrtNum = sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2)
{
if (num % i == 0)
{
return 0;
}
}
return 1;
}
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;
}
lint lcm(lint a,lint b){
return a/__gcd(a,b)*b;
}
lint gcd(lint a,lint b){
return __gcd(a,b);
}
int main(){
lint a,b,c;
cin>>a>>b>>c;
a=a*(a+1)/2;
a%=MOD;
b=b*(b+1)/2;
b%=MOD;
c=c*(c+1)/2;
c%=MOD;
lint ans=a;
ans*=b;
ans%=MOD;
ans*=c;
ans%=MOD;
cout<<ans<<endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
using ll = long long;
const int MAX = 2e5+1;
template <typename T, typename F>
class SegTree{
int n; T uni; F f;
vector<T> dat;
public:
SegTree(int _n, F f, T uni) : f(f), uni(uni) {
n = 1;
while(n < _n) n *= 2;
dat = vector<T>(2*n,uni);
}
void set(int k, const T x) {
dat[k+n] = x;
}
void build() {
for(int i = n-1; i >= 0; i--) {
dat[i] = f(dat[2*i],dat[2*i+1]);
}
}
void update(int k, T x) {
k += n;
dat[k] += x;
while(k >>= 1){
dat[k] = f(dat[2*k],dat[2*k+1]);
}
}
T query(int a, int b) {
T l = uni, r = uni;
for(a += n, b += n; a < b; a >>= 1, b >>= 1) {
if(a & 1) l = f(l,dat[a++]);
if(b & 1) r = f(dat[--b],r);
}
return f(l,r);
}
};
int main(){
int n, m, q;
cin >> n >> m >> q;
vector<ll> a(n), b(m);
auto f = [](ll a,ll b){return a + b;};
SegTree<ll,decltype(f)> sa(MAX,f,0), sb(MAX,f,0), na(MAX,f,0), nb(MAX,f,0);
na.set(0,n); nb.set(0,m);
na.build(); nb.build();
ll l[q], r[q], d[q];
rep(i,q) cin >> l[i] >> r[i] >> d[i];
vector<ll> v;
v.push_back(0);
rep(i,q) v.push_back(d[i]);
sort(v.begin(),v.end());
v.erase(unique(v.begin(),v.end()),v.end());
int vs = v.size();
map<ll,ll> mp;
rep(i,vs) mp[v[i]] = i;
ll sum = 0;
rep(i,q) {
ll t, x, y;
t = l[i], x = r[i], y = d[i];
x--;
if(t == 1) {
sum -= nb.query(0,mp[a[x]]+1)*a[x];
sum += nb.query(0,mp[y]+1)*y;
if(a[x] > y) sum += sb.query(mp[y]+1,mp[a[x]]+1);
else sum -= sb.query(mp[a[x]]+1,mp[y]+1);
na.update(mp[a[x]],-1);
na.update(mp[y],1);
sa.update(mp[a[x]],-a[x]);
sa.update(mp[y],y);
a[x] = y;
} else {
sum -= na.query(0,mp[b[x]])*b[x];
sum += na.query(0,mp[y])*y;
if(b[x] > y) sum += sa.query(mp[y],mp[b[x]]);
else sum -= sa.query(mp[b[x]],mp[y]);
nb.update(mp[b[x]],-1);
nb.update(mp[y],1);
sb.update(mp[b[x]],-b[x]);
sb.update(mp[y],y);
b[x] = y;
}
cout << sum << endl;
}
return 0;
}
|
#include<bits/stdc++.h>
#define push push_back
using namespace std;
typedef long long ll;
const int inf = 1e9 + 10;
const ll INF = 1e18 + 10;
//
int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ll n;
cin>>n;
int val=sqrt(n);
ll cnt=0;
unordered_map<ll,bool> t;
for(ll i=2;i<=val;i++){
for(ll j=2;j<=40;j++){
ll v=pow(i,j);
if(v>n){
break;
}
if(t[v]){
continue;
}
t[v]=true;
cnt++;
}
}
ll res=n-cnt;
cout<<res<<endl;
}
|
// Problem: C - Unexpressed
// Contest: AtCoder - Caddi Programming Contest 2021(AtCoder Beginner Contest 193)
// URL: https://atcoder.jp/contests/abc193/tasks/abc193_c
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
// Disclaimer: Don't copy my template, it may lead to plagiarism.
/* Author: Soumy Jain
Handle: soumy_jain || soumyjain
"Beautiful flowers too, eventually wither and fall. That's the fate of all living beings."
"I hate perfection. To be perfect is to be unable to improve any furthur." - Mayuri Kurotsuchi | Bleach
"I smile to show the pressure of heroes and to trick the fear inside of me."
"Gravel may be gravel, but me? I'm the gravel that shatters diamonds."
"If you were to write a story with me in the lead role, it would certainly be...a TRAGEDY." - Kaneki Ken | Tokyo
Ghoul
*/
/******************************************************************************/
// clang-format off
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define SPEEDHACK ios_base::sync_with_stdio(false);cin.tie(NULL);
#define Tc ll tc; cin>>tc; while(tc--)
#define Qu ll qu; cin>>qu; while(qu--)
#define ff first
#define ss second
#define sz(v) (ll)(v).size()
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define MOD 1000000007 // 998244353
using namespace std;
/******************************************************************************/
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(ll x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(ull x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template<typename T, typename V>
void __print(const pair<T, V> &x) { cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}'; }
template<typename T>
void __print(const T &x) { int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}"; }
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); }
#ifndef ONLINE_JUDGE
#define dbg(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
// clang-format on
/***********************************MAIN***************************************/
// Are you ready to face the wrath of test cases? Good luck noob Soumy!
int main()
{
SPEEDHACK
// file
ll n;
cin >> n;
set<ll> S;
for (ll i = 2; i <= 100000; i++)
{
for (ll j = 2; j <= 100000; j++)
{
ll x = pow(i, j);
if (x <= n)
S.insert(x);
else
break;
}
}
cout << n - S.size();
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e5+10;
int main()
{
long long N;
cin>>N;
N*=2;
long long ans=0;
for(long long i=1;i*i<=N;i++)
{
if(N%i!=0)continue;
long long temp=i;
if((N/temp+1-temp)%2==0)ans++;
temp=N/i;
if((N/temp+1-temp)%2==0)ans++;
}
cout<<ans<<endl;
} | #include<bits/stdc++.h>
using namespace std;
int main(){
string s,S;
cin >> s;
S=s;
s[0]=S[1];
s[1]=S[2];
s[2]=S[0];
cout << s << endl;
return 0;
} |
#include <stack>
#include <queue>
#include <set>
#include <vector>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <utility>
#include <climits>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cstring>
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
#define mp make_pair
#define fr first
#define sc second
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
#define rep(s, i, n) for (int(i) = (s); (i) < (n); (i)++)
#define repe(s, i, n) for (int(i) = (s); (i) <= (n); (i)++)
#define rrep(s, i, n) for (int(i) = (s); (i) > (n); (i)--)
#define rrepe(s, i, n) for (int(i) = (s); (i) >= (n); (i)--)
#define allof(a) (a).begin(), (a).end()
int main(int argc, char const *argv[])
{
ll a, b;
cin >> a >> b;
ll primes[]{2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71};
int lenp = sizeof(primes) / sizeof(ll);
vector<ll> dp(1 << lenp, 0);
dp[0] = 1;
for (ll num = a; num <= b; num++)
{
int bit = 0;
for (int j = 0; j < lenp; j++)
{
if (num % primes[j] == 0)
{
bit |= 1 << j;
}
}
for (int st = 0; st < (1 << lenp); st++)
{
if ((st & bit) == 0)
{
dp[st | bit] += dp[st];
}
}
}
ll ans = 0;
for (ll nst : dp)
{
ans += nst;
}
cout << ans << endl;
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
double a,b;
cin>>a>>b;
cout<<(a*b)/100<<endl;
return 0;
} |
#include <bits/stdc++.h>
#ifndef M_PI
#define M_PI 3.14159265358979
#endif
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef pair<ll, ll> pll;
typedef pair<int, int> pi;
typedef long double ld;
typedef pair<long double, long double> pld;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll i, j;
ll L;
cin >> L;
ll ans;
ans = L - 1;
ans = ans * (L - 2);
ans = ans * (L - 3);
ans = ans * (L - 4) / 8 / 3;
ans = ans * (L - 5) / 5;
ans = ans * (L - 6) / 6;
ans = ans * (L - 7) / 7;
ans = ans * (L - 8) / 4;
ans = ans * (L - 9) / 9;
ans = ans * (L - 10) / 10;
ans = ans * (L - 11) / 11;
ans /= 2;
cout << ans << endl;
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=10000;
int pcnt;
int primes[N];
bool st[N];
ll ans[2550];
void init()
{
for(int i=2;i<=N;i++)
{
if(!st[i]) primes[pcnt++]=i;
for(int j=0;i*primes[j]<=N;j++)
{
st[i*primes[j]]=true;
if(i%primes[j]==0) break;
}
}
}
int main()
{
int n;
cin>>n;
ans[1]=6;
ans[2]=15;
ans[3]=10;
int i=4;
for(int j=12;j<=10000;j+=6)
{
ans[i++]=j;
if(i>n) break;
}
for(int j=30;j<=10000;j+=15)
{
if(j%6==0) continue;
ans[i++]=j;
if(i>n) break;
}
for(int j=20;j<=10000;j+=10)
{
if(j%6==0||j%15==0) continue;
ans[i++]=j;
if(i>n) break;
}
for(int i=1;i<=n;i++)
cout<<ans[i]<<" ";
} |
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{ cin.tie(NULL);
ios_base::sync_with_stdio(false);
cout.tie(NULL);
int a,b,w;
cin>>a>>b>>w;
w=w*1000;
int l=INT_MAX;//min
int r=INT_MIN;//max;
for(int i=1;i<=w;i++)
{
if(a*i<=w&&w<=b*i)
{
l=min(i,l);
r=max(i,r);
}
}
if(l!=INT_MAX&&r!=INT_MIN)
{
cout<<l<<" "<<r<<endl;
}
else
{
cout<<"UNSATISFIABLE"<<endl;
}
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define endl '\n'
#define MOD 1000000007
#define mm(arr) memset(arr, 0, sizeof(arr))
#define F first
#define S second
#define scanArray(a,n) for(int i = 0; i < n; i++){cin >> a[i];}
#define coutArray(a,n) for(int i = 0; i < n; i++){cout << a[i] << " ";};cout << endl;
#define ld long double
#define PI 3.141592653589793238
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
#define int ll
void solve(){
int a, b, w; cin >> a >> b >> w;
int mx = w / (a / 1000.0);
int mn = ceil(w / (b / 1000.0));
if(mn > mx){
cout << "UNSATISFIABLE" << endl;
return;
}
cout << mn << " " << mx << endl;
}
int32_t main(){
FAST
int t = 1;
//cin >> t;
while(t--){
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000 + 50;
const int inf = 1e9;
inline int lowbit(const int & x) { return x & (-x);}
int n, rt;
int ls[maxn], rs[maxn];
int a[maxn][maxn];
void check()
{
for(int i = 1; i <= n; ++i) for(int j = 1; j <= n; ++j) a[i][j] = (i == j) ? 0 : inf;
for(int i = 1; i <= n; ++i) a[i][ls[i]] = a[i][rs[i]] = 1;
for(int k = 1; k <= n; ++k)
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= n; ++j)
a[i][j] = min(a[i][k] + a[k][j], a[i][j]);
for(int i = 1; i <= n; ++i)
{
for(int j = 1; j <= n; ++j)
printf("%d ", a[i][j]);
puts("");
}
}
int main()
{
scanf("%d", &n);
for(int i = 0; i < n; ++i)
{
ls[i] = (i << 1) % n + 1;
rs[i] = (i << 1 | 1) % n + 1;
printf("%d %d\n", ls[i], rs[i]);
}
//check();
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++)
printf("%d %d\n",(i*2-1)%n+1,(i*2)%n+1);
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define INF 1<<30
int adj[2001][2001];
set<int> nb[20001];
int n;
int walk(int root) {
vector<int> d(n+1, INF);
set<pair<int, int> > q;
for(set<int>::iterator i = nb[root].begin(); i!=nb[root].end(); i++){
q.insert(make_pair(adj[root][*i], *i));
d[*i]=adj[root][*i];
}
while (!q.empty()) {
int v = q.begin()->second;
q.erase(q.begin());
for (set<int>::iterator is=nb[v].begin(); is!=nb[v].end(); is++) {
int to = *is;
int len = adj[v][*is];
if (d[v] + len < d[to]) {
q.erase(make_pair(d[to], to));
d[to] = d[v] + len;
q.insert(make_pair(d[to], to));
}
}
}
if(d[root]==INF) return -1;
return d[root];
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int m;
cin >> n >> m;
for(int i = 1; i<=n; i++) for(int j = 1; j<=n; j++) adj[i][j] = INF;
for(int i = 0; i<m; i++){
int a, b, c;
cin >> a >> b >> c;
adj[a][b] = min(adj[a][b], c);
nb[a].insert(b);
}
for(int i = 1; i<=n; i++){
cout << walk(i) << '\n';
}
return 0;
}
| #include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int MOD = 1000000007;
const int INF = 10000000000000;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
void dijkstra(vector<vector<pair<int, int>>> &G, int s,
vector<int> &dist) { //スタート地点を指定
//コスト、向かう頂点でpair(コストが小さい順に並ぶ)
priority_queue<pair<int, int>, vector<pair<int, int>>,
greater<pair<int, int>>>
que;
que.push(make_pair(0, s));
while (!que.empty()) {
pair<int, int> P = que.top();
que.pop();
int v = P.second;
if (dist[v] < P.first)
continue;
dist[v] = P.first;
for (auto &next : G.at(v)) {
que.push({dist[v] + next.second, next.first});
}
}
}
signed main() {
int N, M;
cin >> N >> M;
vector<vector<pair<int, int>>> G(N);
vector<int> ans(N, INF);
rep(i, M) {
int A, B, C;
cin >> A >> B >> C;
A--;
B--;
if (A == B)
ans[A] = min(ans[A], C);
else
G[A].emplace_back(make_pair(B, C));
}
rep(i, N) {
for (auto nx : G[i]) {
int cost = nx.second;
int nv = nx.first;
vector<int> dist(N, INF);
dijkstra(G, nv, dist);
ans[i] = min(dist[i] + cost, ans[i]);
}
}
rep(i, N) {
if (ans[i] == INF)
cout << -1 << "\n";
else
cout << ans[i] << "\n";
}
}
|
using namespace std;
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long int
#define nl "\n"
#define forf(i,a,n) for(ll i=a;i<=n;i++)
#define forb(i,b,n) for(ll i=b;i>=n;i--)
#define pb push_back
#define vll vector<ll>
#define all(qw) qw.begin(),qw.end()
#define read(vec) ll qwe;cin>>qwe;vec.pb(qwe)
#define pll pair<ll,ll>
#define vpll vector<pll>
#define ff first
#define ss second
#define mp make_pair
#define sll set<ll>
#define mll map<ll,ll>
#define go(x) {cout<<x<<nl;return;}
#define mod 1000000007
#define ina(v,n) forf(i,0,n-1) cin>>v[i];
#define inao(v,n) forf(i,1,n) cin>>v[i];
#define inv(v,n) forf(i,1,n) {read(v);}
#define trav(arr,var) for(auto& var:arr)
ll hcf(ll a, ll b)
{
if (b==0)return a;
return hcf(b, a % b);
}
ll lcm(ll a,ll b)
{
return (a*b)/hcf(a,b);
}
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;
}
//SOLVE
void solve(){
long double n,d,h;
cin>>n>>d>>h;
vector<long double> a(n),b(n);
forf(i,0,n-1){
cin>>a[i];
cin>>b[i];
}
long double ans=0;
forf(i,0,n-1){
long double temp=((d*b[i]-h*a[i])/(d-a[i]));
ans=max(temp,ans);
}
cout<<setprecision(16)<<ans;
}
void onlinejudge(){
#ifndef ONLINE_JUDGE
freopen("Input.txt", "r", stdin);
freopen("Output.txt", "w", stdout);
#endif // ONLINE_JUDGE
}
int main(){ // Change the approach
onlinejudge();
//fastio
ll ttt;ttt=1;
// cin>>ttt;
while(ttt--) solve();
return 0;
}
// CHECK FOR EXTREME CASES AND ZEROS; | #include <bits/stdc++.h>
using namespace std;
int main(){
int n;double x,y,a,b,c = 0; cin >> n >> x >> y;
for(int i=0;i<n;i++){
cin >> a >> b;
c = max(c,y-(y-b)/(x-a)*x);
}
cout << c << endl;
} |
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; 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 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, int> 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 h, w;
char s[2000][2001];
int ans[2000][2000], sum[2000][2000][3];
int main() {
ci2(h, w);
rep(i, h) ci(s[i]);
ans[0][0] = 1;
rep(i, h) {
rep(j, w) {
if (s[i][j] == '#') continue;
if (j > 0) {
ans[i][j] = (ans[i][j] + sum[i][j - 1][0]) % MOD;
sum[i][j][0] = sum[i][j - 1][0];
}
if (i > 0) {
ans[i][j] = (ans[i][j] + sum[i - 1][j][1]) % MOD;
sum[i][j][1] = sum[i - 1][j][1];
}
if (i > 0 && j > 0) {
ans[i][j] = (ans[i][j] + sum[i - 1][j - 1][2]) % MOD;
sum[i][j][2] = sum[i - 1][j - 1][2];
}
rep(k, 3) sum[i][j][k] = (sum[i][j][k] + ans[i][j]) % MOD;
}
}
co(ans[h - 1][w - 1]);
return 0;
}
| #include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>
#include <numeric>
#include <cfloat>
#include <iomanip>
using namespace std;
string S[2000];
long long dp[2000][2000];
long long dp_aux[2000][2000][3];
const long long MOD = 1000000007;
int main(){
int H;
int W;
cin >> H >> W;
for(int i = 0; i < H; i++){
cin >> S[i];
}
dp[0][0] = 1;
for(int i = 1; i < W; i++){
if(S[0][i] != '#'){
dp_aux[0][i][2] = (dp[0][i - 1] + dp_aux[0][i - 1][2]) % MOD;
dp[0][i] = dp_aux[0][i][2];
} else {
break;
}
}
for(int i = 1; i < H; i++){
if(S[i][0] != '#'){
dp_aux[i][0][0] = (dp[i - 1][0] + dp_aux[i - 1][0][0]) % MOD;
dp[i][0] = dp_aux[i][0][0];
}
for(int j = 1; j < W; j++){
if(S[i][j] != '#'){
dp_aux[i][j][0] = (dp[i - 1][j] + dp_aux[i - 1][j][0]) % MOD;
dp_aux[i][j][1] = (dp[i - 1][j - 1] + dp_aux[i - 1][j - 1][1]) % MOD;
dp_aux[i][j][2] = (dp[i][j - 1] + dp_aux[i][j - 1][2]) % MOD;
dp[i][j] = ((dp_aux[i][j][0] + dp_aux[i][j][1]) % MOD + dp_aux[i][j][2]) % MOD;
}
}
}
cout << dp[H - 1][W - 1] << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define ll long long
#define md 1000000007
using namespace std;
int main(){
ll n,H,D,d,h,i;
double mx=0;
cin>>n>>D>>H;
for(i=0;i<n;i++){
cin>>d>>h;
if(H*d>=h*D) continue;
double numr = h*D - H*d;
double den = D-d;
double val = numr/den;
mx = max(mx,val);
}
cout.precision(10);
cout<<fixed<<mx;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long double ld;
typedef pair<ll, ll> pll;
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define ROF(i, a, b) for(int i = a; i >= b; i--)
#define ms memset
#define pb push_back
#define F first
#define S second
ll MOD = 1000000007;
ll power(ll base, ll n){
if (n == 0) return 1;
if (n == 1) return base;
ll halfn = power(base, n/2);
if (n % 2 == 0) return (halfn * halfn) % MOD;
return (((halfn * halfn) % MOD) * base) % MOD;
}
ll inverse(ll n){
return power(n, MOD-2);
}
ll add(ll a, ll b){
return (a+b) % MOD;
}
ll mul(ll a, ll b){
return (a*b) % MOD;
}
ll gcd(ll a, ll b){
if (a == 0) return b;
if (a == 1) return 1;
return gcd(b%a, a);
}
const int N = (1<<18) + 1;
vi p(N), r(N);
int get(int a){
return p[a] = (p[a] == a ? p[a] : get(p[a]));
}
void Union(int a, int b){
int c = get(a); int d = get(b);
if (c == d) return;
if (r[c] == r[d]) r[c]++;
if (r[c] > r[d]){
p[d] = c;
}else{
p[c] = d;
}
}
int main(){
ios::sync_with_stdio(false);
int n; ld d, h; cin >> n >> d >> h;
ld grad = h / d;
FOR(i, 0, n){
ld h1, d1; cin >> d1 >> h1;
grad = min( (h-h1)/(d-d1), grad);
}
ld ans = h - grad * d;
cout << setprecision(18) << ans << '\n';
return 0;
}
|
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<string>
#include<functional>
#include<iomanip>
#define rep(i,n,m) for(int i=(n);i<(int)(m);i++)
#define reps(i,n,m) for(int i=(n);i<=(int)(m);i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define fs first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define LB(a,x) lb(all(a), x) - a.begin()
#define UB(a,x) ub(all(a), x) - a.begin()
#define chartoint(c) (int)((c) - '0')
#define chartoll(c) (long long)((c) - '0')
#define bpc(x) __builtin_popcount(x)
#define bpcll(x) __builtin_popcountll(x)
#define fps(n) fixed << setprecision(n)
#define MOD 1000000007
#define itn int
#define enld endl
#define ednl endl
#define icn cin
#define cotu cout
#define Endl endl
#define stirng string
using namespace std;
typedef long long ll;
const double pi = 3.141592653589793;
using Graph = vector<vector<int>>;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return 1;} return 0;}
template<class T> bool chmin(T &a, const T &b){if(b<a){a=b; return 1;} return 0;}
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
std::fill( (T*)array, (T*)(array+N), val );
}
int main(){
cin.tie(0);ios::sync_with_stdio(false);
int n; cin >> n;
vector<ll> A(n);
vector<ll> B(n);
rep(i,0,n) cin >> A[i];
rep(i,0,n) cin >> B[i];
ll sum = 0LL;
rep(i,0,n) sum += A[i]*B[i];
if(sum == 0) cout << "Yes" << endl;
else cout << "No" << endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
std::fstream myfile("D:\\CodeBlocks\\c++\\input.txt.c", std::ios_base::in);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n;
cin>>n;
vector<ll> vec(n);
for(ll i=0;i<n;i++){
cin>>vec[i];
}
ll sum=0;
for(ll i=0;i<n;i++){
ll temp;
cin>>temp;
sum+=(vec[i]*temp);
}
if(sum==0)
cout<<"Yes\n";
else
cout<<"No\n";
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
using ll = long long int;
using ld = long double;
#define pow(n,m) powl(n,m)
#define sqrt(n) sqrtl(n)
const ll MAX = 5000000000000000000;
const ll MOD = 0;
void randinit(){srand((unsigned)time(NULL));}
int main(){
ll N;
cin >> N;
N *= 2;
vector<ll> A,B,C;
for(ll i = 0;i < N;i++){
ll a;
char c;
cin >> a >> c;
if(c == 'R') A.emplace_back(a);
if(c == 'G') B.emplace_back(a);
if(c == 'B') C.emplace_back(a);
}
sort(A.begin(),A.end());
sort(B.begin(),B.end());
sort(C.begin(),C.end());
if(A.size() % 2 == 0 && B.size() % 2 == 0 && C.size() % 2 == 0){
cout << 0 << endl;
return 0;
}
ll a,b,c;
if(A.size() == 0) a = 0;
else a = 2 - (A.size() % 2);
if(B.size() == 0) b = 0;
else b = 2 - (B.size() % 2);
if(C.size() == 0) c = 0;
else c = 2 - (C.size() % 2);
if(a > b){
swap(a,b);
swap(A,B);
}
if(b > c){
swap(b,c);
swap(B,C);
}
if(a > b){
swap(a,b);
swap(A,B);
}
if(b > c){
swap(b,c);
swap(B,C);
}
if(a > b){
swap(a,b);
swap(A,B);
}
if(b > c){
swap(b,c);
swap(B,C);
}
ll ans = MAX;
if(a == 0){
swap(a,c);
swap(A,C);
}
vector<ll> AA = A,BB = B;
BB.emplace_back(-MAX);
BB.emplace_back(MAX);
sort(BB.begin(),BB.end());
for(ll i = 0;i < A.size();i++){
ans = min(ans,abs(A[i] - *(lower_bound(BB.begin(),BB.end(),A[i]))));
ans = min(ans,abs(A[i] - *(upper_bound(BB.begin(),BB.end(),A[i]) - 1)));
}
if(c != 0){
vector<ll> AAA = A,BBB = B,CCC = C;
AAA.emplace_back(-MAX);
AAA.emplace_back(MAX);
sort(AAA.begin(),AAA.end());
BBB.emplace_back(-MAX);
BBB.emplace_back(MAX);
sort(BBB.begin(),BBB.end());
vector<ll> P;
for(ll i = 0;i < C.size();i++){
ll p = min(
abs(C[i] - *(lower_bound(AAA.begin(),AAA.end(),C[i]))),
abs(C[i] - *(upper_bound(AAA.begin(),AAA.end(),C[i]) - 1))
);
P.emplace_back(p);
}
vector<ll> PP = P;
sort(PP.begin(),PP.end());
for(ll i = 0;i < C.size();i++){
ll p = min(
abs(C[i] - *(lower_bound(BBB.begin(),BBB.end(),C[i]))),
abs(C[i] - *(upper_bound(BBB.begin(),BBB.end(),C[i]) - 1))
);
if(PP[0] == PP[1] || PP[0] != P[i]){
ans = min(ans,p + PP[0]);
}
else{
ans = min(ans,p + PP[1]);
}
}
}
cout << ans << endl;
}
| #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 dsrep(i,t,s) for(int i = (t)-1; i >= (s); --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 snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cerr<<#x<<" = "<<x<<endl;
#define bn(x) ((1<<(x))-1)
#define newline puts("")
using namespace std;
template<typename T> using vc = vector<T>;
template<typename T> using vv = vc<vc<T>>;
template<typename T> using PQ = priority_queue<T,vc<T>,greater<T> >;
using ll = long long;
using uint = unsigned;
using ull = unsigned long long;
using P = pair<ll,int>;
using T3 = tuple<int,int,int>;
using vi = vc<int>;
using vvi = vv<int>;
using vl = vc<ll>;
using vp = vc<P>;
using vt = vc<T3>;
int getInt(){int x;scanf("%d",&x);return x;}
vi pm(int n, int s=0) { vi a(n); iota(rng(a),s); return a;}
template<typename T>istream& operator>>(istream&i,vc<T>&v){rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const T&v,const string& d=""){stringstream s;rep(i,sz(v))(i?s<<d:s)<<v[i];return s.str();}
template<typename T>ostream& operator<<(ostream&o,const vc<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;}
vc<string> split(const string& s,char d=' '){vc<string> r(1);for(char c:s)if(c==d)r.pb("");else r.back()+=c;return r;}
string operator*(const string& s,int t){return join(vc<string>(t,s));}
template<typename T1,typename T2>bool mins(T1& x,const T2&y){if(x>y){x=y;return true;}else return false;}
template<typename T1,typename T2>bool maxs(T1& x,const T2&y){if(x<y){x=y;return true;}else return false;}
template<typename T>T dup(T x, T y){return (x+y-1)/y;}
template<typename T>ll suma(const vc<T>&a){ll res(0);for(auto&&x:a)res+=x;return res;}
template<typename T>void uni(T& a){sort(rng(a));a.erase(unique(rng(a)),a.end());}
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;
using vvl = vc<vl>;
struct Solver {
void solve() {
int n;
scanf("%d",&n);
vvl a(3);
vp p;
rep(i,n*2) {
char c;
ll x;
scanf("%lld %c",&x,&c);
c %= 3;
a[c].pb(x);
p.eb(x,c);
}
sort(rng(p));
vl dp(16, LINF);
dp[0] = 0;
for (auto x : p) {
vl pd(16,LINF); swap(dp,pd);
rep(i,16) {
mins(dp[i^1<<x.se], pd[i]);
ll now = -x.fi;
if (i&8) now = -now;
mins(dp[i^8], pd[i]+now);
}
}
ll ans = dp[0];
// vi os;
// rep(i,3) {
// sort(rng(a[i]));
// if (sz(a[i])&1) os.pb(i);
// }
// ll ans = 0;
// if (sz(os)) {
// ans = LINF;
// vl x = a[os[0]];
// vl y = a[os[1]];
// int xi = 0, yi = 0;
// while (xi < sz(x) && yi < sz(y)) {
// mins(ans, abs(x[xi]-y[yi]));
// if (x[xi] < y[yi]) ++xi; else ++yi;
// }
// }
cout<<ans<<endl;
}
};
int main() {
int ts = 1;
// scanf("%d",&ts);
rrep(ti,ts) {
Solver solver;
solver.solve();
}
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
int n;
map<int,int> b;
cin >> n;
ll ans = 0;
vector<int> a(n);
rep(i,n){
cin >> a[i];
b[a[i]] = 0;
}
for(int i = 0; i < n; ++i){
int k=i;
k -= b[a[i]];
ans += k;
b[a[i]]++;
}
cout << ans << endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
ll n;
cin >> n;
vector<ll> s(n);
for(ll i=0; i<n; i++){
string S;
cin >> S;
if(S=="AND") s.at(i)=1;
else s.at(i)=0;
}
vector<ll> t(n+1,0);
vector<ll> f(n+1,0);
t.at(0)=1;
f.at(0)=1;
for(int i=0; i<n; i++){
if(s.at(i)==0){
t.at(i+1) = t.at(i)*2+f.at(i);
f.at(i+1) = f.at(i);
}
else{
t.at(i+1) = t.at(i);
f.at(i+1) = t.at(i)+f.at(i)*2;
}
}
/*for(int i=0; i<=n; i++){
cout << t.at(i) << " ";
}
cout << endl;
for(int i=0; i<=n; i++){
cout << f.at(i) << " ";
}*/
cout << t.at(n) << endl;
}
|
#include <bits/stdc++.h>
#define N 105
#define Mo 998244353
#define pb push_back
#define mk make_pair
#define fi first
#define se second
using namespace std;
int dp[N][N][N * N], n, a[N], fac[N];
int main()
{
scanf("%d", &n); fac[0] = 1; for (int i = 1; i <= n; ++i) fac[i] = 1ll * fac[i - 1] * i % Mo;
for (int i = 1; i <= n; ++i) scanf("%d", &a[i]), a[0] += a[i];
dp[0][0][0] = 1;
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
for (int k = 0; k <= 100 * n; ++k)
(dp[i + 1][j][k] += dp[i][j][k]) %= Mo,
(dp[i + 1][j + 1][k + a[i + 1]] += dp[i][j][k]) %= Mo;
int ans = 0;
if (a[0] % 2 == 0)
for (int j = 1; j <= n; ++j)
(ans += 1ll * fac[j] * fac[n - j] % Mo * dp[n][j][a[0] / 2] % Mo) %= Mo;
printf("%d\n", ans);
} | #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int MAXN = 100005;
int f[MAXN], sz[MAXN], n;
vector<int> son[MAXN];
struct Data {
int a, b;
bool operator<(const Data &d) const {
return a - b < d.a - d.b;
}
};
void dfs(int u) {
sz[u] = 1;
vector<Data> v0, v1;
for (int v : son[u]) {
dfs(v);
sz[u] += sz[v];
if (sz[v] & 1) v1.push_back(Data { f[v], sz[v] - f[v] });
else v0.push_back(Data { f[v], sz[v] - f[v] });
}
for (const Data &d : v0) {
if (d.a <= d.b) f[u] += d.a;
}
sort(v1.begin(), v1.end());
for (int i = 0; i < (int)v1.size(); i++) {
if (i & 1) f[u] += v1[i].b;
else f[u] += v1[i].a;
}
if (v1.size() & 1) {
for (const Data &d : v0) {
if (d.a > d.b) f[u] += d.b;
}
} else {
for (const Data &d : v0) {
if (d.a > d.b) f[u] += d.a;
}
}
++f[u];
}
int main() {
scanf("%d", &n);
for (int i = 2; i <= n; i++) {
int p; scanf("%d", &p);
son[p].push_back(i);
}
dfs(1);
printf("%d\n", f[1]);
return 0;
} |
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(1e9+7)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll gcd(ll a,ll b){if(!b)return a;else return gcd(b,a%b);}
VII dist(600,vector<ll>(600,INF));
int main()
{
owo
int r,c;
cin>>r>>c;
VII a(r,vector<ll>(c)),b(r,vector<ll>(c));
for(int i=0;i<r;i++)
for(int j=0;j<c-1;j++)cin>>a[i][j];
for(int i=0;i<r-1;i++)
for(int j=0;j<c;j++)cin>>b[i][j];
dist[0][0] = 0;
priority_queue<pair<ll,pii>,vector<pair<ll,pii>>,greater<pair<ll,pii>>>pq;
pq.push({0,{0,0}});
while(!pq.empty()){
ll d = pq.top().fi;
pii v = pq.top().se;
pq.pop();
if(d != dist[v.fi][v.se])continue;
int rn = v.fi;
int cn = v.se;
if(cn < c-1 && d+a[rn][cn] < dist[rn][cn+1]){
dist[rn][cn+1] = d+a[rn][cn];
pq.push({dist[rn][cn+1],{rn,cn+1}});
}
if(cn && d+a[rn][cn-1] < dist[rn][cn-1]){
dist[rn][cn-1] = d+a[rn][cn-1];
pq.push({dist[rn][cn-1],{rn,cn-1}});
}
if(rn < r-1 && d+b[rn][cn] < dist[rn+1][cn]){
dist[rn+1][cn] = d+b[rn][cn];
pq.push({dist[rn+1][cn],{rn+1,cn}});
}
for(int i=rn-1;i>=0;i--){
if(dist[i][cn] > d+rn-i+1){
dist[i][cn] = d+rn-i+1;
pq.push({dist[i][cn],{i,cn}});
}
}
}
cout<<dist[r-1][c-1];
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int M;
cin >> M >> M;
vector<string> s(M);
map<string, int> m;
set<string> S;
vector<vector<char>> a(20, vector<char>(20, 'A'));
deque<tuple<int, int, string>> t;
for (int i = 0; i < M; i++) {
cin >> s.at(i);
if (m.count(s.at(i))) {
m.at(s.at(i))++;
}
else {
m[s.at(i)] = 1;
}
}
for (int i = 0; i < M; i++) {
if (!(S.count(s.at(i)))) {
S.insert(s.at(i));
t.push_back(make_tuple(m.at(s.at(i)), (int)s.at(i).size(), s.at(i)));
}
}
sort(t.begin(), t.end());
for (int i = 0; i < 20; i++) {
M = 0;
for (int j = 0; j < 10; j++) {
if (M + get<1>(t.front()) > 19) {
break;
}
for (int k = 0; k < get<1>(t.front()); k++) {
a.at(i).at(M + k) = get<2>(t.front()).at(k);
}
M += get<1>(t.front());
t.pop_front();
}
}
for (int i = 0; i < 20; i++) {
for (int j = 0; j < 20; j++) {
cout << a.at(i).at(j);
if (j > 18) {
cout << endl;
}
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200000 + 10;
const int MOD = 998244353;
int pow(int x, int k) {
if (k == 0) return 1;
long long t = pow(x, k / 2);
t = (t * t) % MOD;
if (k % 2 == 1) t = (t * x) % MOD;
return (int)(t);
}
int main() {
int n, m, k;
cin >> n >> m >> k;
if (min(n, m) == 1) {
cout << pow(k, max(m, n)) << "\n";
return 0;
}
long long res = 0;
for(int maxa = 1; maxa <= k; ++maxa) {
int na = (pow(maxa, n) - pow(maxa - 1, n) + MOD) % MOD, nb = pow(k - maxa + 1, m);
res = (res + ((1LL * na * nb) % MOD) ) % MOD;
}
cout << res << "\n";
} | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#define MAXN 101
using namespace std;
double memo[MAXN][MAXN][MAXN]{};
double dfs(vector<int> &coins) {
if (coins[1] == 0)
return 100.0 - coins[0];
if (coins[0] == 100 || coins[1] == 100 || coins[2] == 100)
return 0.0;
if (memo[coins[0]][coins[1]][coins[2]] >= 0)
return memo[coins[0]][coins[1]][coins[2]];
int s = 0;
for (int coin : coins)
s += coin;
double ans = 0;
for (int i = 0; i < 3; ++i) {
if (coins[i] > 0) {
vector<int> nxt(coins);
nxt[i]++;
ans += (double)coins[i] / s * (1 + dfs(nxt));
}
}
return memo[coins[0]][coins[1]][coins[2]] = ans;
}
int main() {
vector<int> coins(3);
for (int i = 0; i < 3; ++i)
cin >> coins[i];
sort(coins.rbegin(), coins.rend());
memset(memo, -1.0, sizeof(memo));
printf("%.12f", dfs(coins));
} |
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
int main()
{
string s;
cin>>s;
reverse(s.begin(),s.end());
int l = s.size();
for(int i=0;i<l;i++)
{
if(s[i]=='9')s[i] = '6';
else if(s[i]=='6')s[i] = '9';
}
cout<<s<<endl;
return 0;
}
| #include <bits/stdc++.h>
int main()
{
std::string s, t = "";
std::string table[] = { "0", "1", "", "", "", "", "9", "", "8", "6", };
std::cin >> s;
for (int i = s.length() - 1; i >= 0; i--)
t += table[s[i] - '0'];
std::cout << t << std::endl;
return 0;
}
|
Subsets and Splits