code_file1
stringlengths 87
4k
| code_file2
stringlengths 82
4k
|
---|---|
//#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(nullptr)
#define all(x) x.begin(),x.end()
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define lc(x) ((x)<<1)
#define rc(x) (((x)<<1)|1)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double ld;
const ll LINF=1e18;
const ll MOD=1e9+7;
const int INF=0x3f3f3f3f;
const int MAXM=500050;
const int MAXN=200050;
void mainwork(int T){
ll n;
scanf("%lld",&n);
ll ans=0;
if(n<1000){
puts("0");
return;
}
if(n<1000000){
ans+=(n-1000+1);
printf("%lld",ans);
return;
}else{
ans+=(999999-1000+1);
}
if(n<1000000000){
ans+=(n-1000000+1)*2;
printf("%lld",ans);
return;
}else{
ans+=(999999999-1000000+1)*2;
}
if(n<1000000000000ll){
ans+=(n-1000000000ll+1)*3;
printf("%lld",ans);
return;
}else{
ans+=(1000000000000ll-1000000000ll)*3;
}
ans+=(n-1000000000000ll+1)*4;
if(n== 1000000000000000ll)ans++;
printf("%lld",ans);
return;
}
signed main(){
//IOS;
#ifndef ONLINE_JUDGE
//freopen("./in.txt","r",stdin);
//freopen("out.txt","w",stdout);
#endif
int t=1;
//scanf("%d",&t);
//prework();
for(int i=1;i<=t;i++){
mainwork(i);
}
} | #include<bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define pb push_back
#define sz(x) (int)x.size()
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define F first
#define S second
#define watch(x) cerr << "\n" << (#x) << " = " << (x) << "\n"
using namespace std;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ll n;
cin >> n;
int len = to_string(n).length();
ll ans = 0;
for(int i = 1; i < len; ++i){
ans += (9 * pow(10, i - 1)) * ((i - 1) / 3);
}
ans += ((n + 1 - pow(10, len - 1)) * ((len - 1) / 3));
cout << ans;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<string> S(N);
for (int i = 0; i < N; i++) {
cin >> S.at(i);
}
set<string> M(S.begin(), S.end());
for (int i = 0; i < N; i++) {
if (M.count('!' + S.at(i))) {
cout << S.at(i) << endl;
return 0;
}
}
cout << "satisfiable" << endl;
} | #include<bits/stdc++.h>
#include<string.h>
#define ll long long
#define pf printf
#define sf scanf
#define ff first
#define ss second
#define clr clear()
#define sz size()
#define pb push_back
#define mk make_pair
#define pi acos(-1)
#define inf 2000000000000
#define mod 998244353
#define ull unsigned long long int
#define f(i,k,n) for(i=k;i<n;i++)
#define fr(i,n,k) for(i=n;i>=k;i--)
#define ent(a) scanf("%lld",&a)
#define ent2(a,b) scanf("%lld%lld",&a,&b)
#define ent3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define mem(a) memset(a,0,sizeof(a))
#define vec(v,s) vector<ll>v[s]
#define arr(a,s) ll a[s];
/*#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
random_device rd;
mt19937 random(rd());*/
//knight and king//
int dr[]= {2,2,-2,-2,1,-1,1,-1};
int dc[]= {1,-1,1,-1,2,2,-2,-2};
int dr1[]= {0,0,1,1,1,-1,-1,-1};
int dc1[]= {1,-1,1,0,-1,0,1,-1};
int dr2[]= {0,0,1,-1};
int dc2[]= {1,-1,0,0};
////////////////////////////
using namespace std;
#define ma 3005
int main()
{
ll i,j,n,m;
string t="satisfiable";
cin>>n;
map<string,ll>mp,mp1;
for(i=0;i<n;i++)
{
string t1;
cin>>t1;
if(t1[0]!='!')
{
mp[t1]=1;
}
else mp1[t1]=1;
}
map<string ,ll>::iterator it;
for(auto p:mp)
{
string t1="!"+p.ff;
if(mp1[t1])
{
t=p.ff;
}
}
cout<<t<<endl;
return 0;
}
|
#pragma GCC optimize("O3") //
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, b, a) for(int i = b - 1; i >= a; i--)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef long double ld;
typedef unsigned long long ull;
unsigned seed = chrono::system_clock::now().time_since_epoch().count();
mt19937 eng(seed);
ll random2(){
return (1ll << 31ll)*eng()+eng();
}
ll n,m,k,q,T;
const ll big = 1000000007;
const ll big2 = 1000000009;
const ll mod = 998244353;
const int MAXN = 200001;
string s1,s2,s3;
string S[3];
string alfa = "01";
string get(int a, int b, int c, int where){
string res = "";
if(where == 0)res += alfa[b];
rep(c1,0,n){
res += alfa[a];
}
if(where == 1)res += alfa[b];
rep(c1,0,n){
res += alfa[c];
}
if(where == 2)res += alfa[b];
return res;
}
bool mat(string s, string t){
int seen = 0;
rep(c1,0,sz(s)){
if(s[c1] == t[seen])seen++;
if(seen == sz(t))return 1;
}
return 0;
}
string greedy(){
int A[3] = {0};
string res = "";
rep(c1,0,2*n+1){
int ma = -1;
char choice;
rep(c2,0,3){
if(A[c2] > ma){
ma = A[c2];
choice = S[c2][A[c2]];
}
}
res += choice;
if(c1 == 2*n)break;
rep(c2,0,3){
while(S[c2][A[c2]] != choice){
A[c2]++;
}
A[c2]++;
}
}
return res;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
//freopen("fhc.txt","r",stdin);
//freopen("autput.txt","w",stdout);
ll a,b,c,d;
cin >> T;
rep(c4,0,T){
cin >> n;
cin >> s1 >> s2 >> s3;
S[0] = s1+s1;
S[1] = s2+s2;
S[2] = s3+s3;
string s = "";
bool good = 0;
rep(c1,0,2){
rep(c2,0,2){
rep(c3,0,2){
rep(where,0,3){
s = get(c1,c2,c3,where);
if(mat(s1+s1,s) && mat(s2+s2,s) && mat(s3+s3,s)){
good = 1;
goto label;
}
}
}
}
}
label:
assert(good);
cout << s << "\n";
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const int Maxn = 400004;
char tmp[Maxn];
int T;
int n;
string A, B, C;
int nxtA[Maxn][2], nxtB[Maxn][2], nxtC[Maxn][2];
char res[Maxn];
int rlen;
void Read(string &S, int nxt[][2])
{
scanf("%s", tmp);
S = tmp; S = S + S;
nxt[S.length()][0] = nxt[S.length()][1] = S.length();
for (int i = int(S.length()) - 1; i >= 0; i--) {
nxt[i][0] = nxt[i + 1][0];
nxt[i][1] = nxt[i + 1][1];
nxt[i][S[i] - '0'] = i;
}
}
int main()
{
scanf("%d", &T);
while (T--) {
scanf("%d", &n);
Read(A, nxtA);
Read(B, nxtB);
Read(C, nxtC);
printf("%s%s%s\n", string(n, '0').c_str(), string(n, '1').c_str(), string(1, '0').c_str());
}
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define rg register
#define In inline
#define ll long long
const ll mod = 998244353;
const int N = 2e5;
namespace IO{
In ll read(){
ll s = 0,ww = 1;
char ch = getchar();
while(ch < '0' || ch > '9'){if(ch == '-')ww = -1;ch = getchar();}
while('0' <= ch && ch <= '9'){s = 10 * s + ch - '0';ch = getchar();}
return s * ww;
}
In void write(ll x){
if(x < 0)putchar('-'),x = -x;
if(x > 9)write(x / 10);
putchar('0' + x % 10);
}
};
using namespace IO;
namespace ModCalc{
In void Inc(ll &x,ll y){
x += y;if(x >= mod)x -= mod;
}
In void Dec(ll &x,ll y){
x -= y;if(x < 0)x += mod;
}
In ll Add(ll x,ll y){
Inc(x,y);return x;
}
In ll Sub(ll x,ll y){
Dec(x,y);return x;
}
};
using namespace ModCalc;
ll a[N+5];
int n;
int main(){
// freopen("B.in","r",stdin);
// freopen("B.out","w",stdout);
n = read();
for(rg int i = 1;i <= n;i++)a[i] = read();
sort(a + 1,a + n + 1);
ll x = 0,ans = 0;
for(rg int i = 1;i <= n;i++){
Inc(ans,Add(x,a[i]) * a[i] % mod);
x = Add(x * 2 % mod,a[i]);
}
write(ans),putchar('\n');
return 0;
} | #include <iostream>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <string>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <utility>
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define vi vector<int>
#define vpi vector<pair<int, int>>
#define vl vector<long long>
#define vpl vector<pair<long long, long long>>
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
template<typename T>
void printVector(const T& t) {
std::copy(t.cbegin(), t.cend(), std::ostream_iterator<typename T::value_type>(std::cout, ", "));
}
using namespace std;
using ll = long long;
const int mode = 0;
void solve() {
int a, b, c, d;
cin >> a >> b >> c >> d;
int t = a + b + c + d;
if (t % 2) {
cout << "No\n";
return;
}
int h = t / 2;
vi ways = {a,b,c,d,a+b,a+c,a+d};
for (int x : ways) {
if (x == h) {
cout << "Yes\n";
return;
}
}
cout << "No\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t;
if (mode == 0) {
solve();
} else {
cin >> t;
while (t--) {
solve();
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ull unsigned long long
#define pii pair<int,int>
#define tiii tuple<int,int,int>
#define pll pair<long long, long long>
#define pdd pair<double, double>
#define s second
#define f first
#define pb push_back
#define oo 1000000000000ll
void solve(){
int n; cin >> n;
vector<int> dp[2];
dp[0].resize(n+1);
dp[1].resize(n+1);
dp[0][0] = 1;
dp[1][0] = 1;
for (int i = 1; i <= n; ++i) {
string str; cin >> str;
if (str == "AND"){
dp[1][i] = dp[1][i-1];
dp[0][i] = dp[1][i-1] + 2*dp[0][i-1];
}
else{
dp[1][i] = 2*dp[1][i-1] + dp[0][i-1];
dp[0][i] = dp[0][i-1];
}
}
cout << dp[1][n] << "\n";
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
return 0;
}
| #include <bits/stdc++.h>
signed main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
int n; std::cin >> n;
std::vector<int> op(n);
for (auto &it : op) {
std::string s; std::cin >> s;
it = (s == "AND");
}
int64_t ans = 1, pw2 = 1;
for (int i = 0; i < n; i++) {
pw2 <<= 1;
if (not op[i]) {
ans += pw2;
}
}
std::cout << ans << '\n';
return 0;
}
|
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define all(x) x.begin(),x.end()
#define mod 998244353
#define ad(a,b) a=(a+b)%mod;
#define X 5010
ll po(ll x,ll y){
ll res=1;
for(;y;y>>=1){
if(y&1)res=res*x%mod;
x=x*x%mod;
}
return res;
}
ll fac[X],ivf[X];
void init(){
fac[0]=1;
for(ll i=1;i<X;i++)fac[i]=fac[i-1]*i%mod;
for(ll i=0;i<X;i++)ivf[i]=po(fac[i],mod-2);
}
ll C(ll n,ll k){
return fac[n]*ivf[n-k]%mod*ivf[k]%mod;
}
#define N 200010
vector<ll> e[110];
bool vis[110];
int dfs(ll x){
if(vis[x])return 0;
vis[x]=1;
int res=1;
for(auto y:e[x])res+=dfs(y);
return res;
}
int main(){
cin.tie(0);
ios::sync_with_stdio(0);
ll n,K;
cin>>n>>K;
ll a[55][55];
rep(i,n)rep(j,n)cin>>a[i][j];
rep(i,n)rep(j,n){
bool ok=1;
rep(k,n)ok&=(a[i][k]+a[j][k]<=K);
if(ok)e[i].push_back(j);
}
rep(i,n)rep(j,n){
bool ok=1;
rep(k,n)ok&=(a[k][i]+a[k][j]<=K);
if(ok)e[i+n].push_back(j+n);
}
init();
rep(i,2*n)vis[i]=0;
ll res=1;
rep(i,2*n){
if(!vis[i])res=res*fac[dfs(i)]%mod;
}
cout<<res<<endl;
}
| #include<iostream>
#include<vector>
using namespace std;
typedef long long ll;
const ll mod = 998244353;
struct UF{
vector<int> p;
int n;
UF(int siz){
n = siz;
p.resize(n, 0);
for(int i = 0; i < n; i++) p[i] = i;
}
int parent(int x){
if(p[x] != x) p[x] = parent(p[x]);
return p[x];
}
bool same(int x, int y){
return parent(x) == parent(y);
}
void unite(int x, int y){
x = parent(x), y = parent(y);
p[x] = y;
}
};
int main(){
int n, x;
cin >> n >> x;
int a[n][n];
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
cin >> a[i][j];
}
}
UF var(n), hor(n);
for(int i = 0; i < n; i++){
for(int j = i+1; j < n; j++){
bool vok = true, hok = true;
for(int k = 0; k < n; k++){
vok &= a[i][k]+a[j][k] <= x;
hok &= a[k][i]+a[k][j] <= x;
}
if(vok) var.unite(i, j);
if(hok) hor.unite(i, j);
}
}
vector<int> vv(n, 0), hh(n, 0);
for(int i = 0; i < n; i++) vv[var.parent(i)]++, hh[hor.parent(i)]++;
vector<ll> fact(n+1, 1);
for(int i = 1; i <= n; i++) fact[i] = fact[i-1]*i%mod;
ll vval = 1, hval = 1;
for(int i = 0; i < n; i++) (vval *= fact[vv[i]]) %= mod, (hval *= fact[hh[i]]) %= mod;
cout << vval*hval%mod << endl;
return 0;
} |
#include<bits/stdc++.h>
namespace imzzy{
#define endl '\n'
#define rgi register int
#define rgl register long long
typedef long long ll;
class fastin{private:int _ch,_f;
public:inline fastin&operator>>(char&c){c=getchar();return*this;}
template<typename _Tp>inline fastin&operator>>(_Tp&_x){
_x=0;while(!isdigit(_ch))_f|=(_ch==45),_ch=getchar();
while(isdigit(_ch))_x=(_x<<1)+(_x<<3)+(_ch^48),_ch=getchar();
_f&&(_x=-_x,_f=0);return*this;}fastin(){_ch=_f=0;}
}fin;class fastout{private:int _num[32],_head;
public:inline fastout&operator<<(char c){putchar(c);return*this;}
template<typename _Tp> inline fastout&operator<<(_Tp _x){
_Tp _k;if(_x==0){putchar('0');return *this;}if(_x<0)putchar('-'),_x=-_x;
while(_x>0)_k=_x/10,++_head,_num[_head]=(_x-(_k<<1)-(_k<<3))^48,_x=_k;
while(_head>0)putchar(_num[_head]),--_head;return*this;}fastout(){_head=0;}
}fout;inline void P_INIT(){
#ifdef D_STDOUT_UNBUFFERED
setbuf(stdin,NULL),setbuf(stdout,NULL);
#endif
}}using namespace imzzy;
// ----------------------------
// #define int ll
// using namespace std;
const double pi=acos(-1.0);
const int mod=1000000000,inf=1201201201;
const int maxn=104,maxm=800004;
int cnt[maxn];
bool go[maxn][maxn];
char s[maxn];
signed main()
{P_INIT();
int n;
fin>>n;
for(rgi i=1;i<=n;++i) {
scanf("%s",s+1);
for(rgi j=1;j<=n;++j) go[i][j]=(s[j]-'0')|(i==j);
}
for(rgi k=1;k<=n;++k) for(rgi i=1;i<=n;++i) for(rgi j=1;j<=n;++j) go[i][j]|=go[i][k]&go[k][j];
for(rgi i=1;i<=n;++i) for(rgi j=1;j<=n;++j) cnt[j]+=go[i][j];
double ans=0;
for(rgi i=1;i<=n;++i) ans+=1.0/cnt[i];
printf("%.12lf",ans);
return 0;
}
// ----------------------------
// by imzzy | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
const ll mod = 1e18 + 7;
const int maxn = 1e5+5;
void go() {
int n;string s;
cin >> n >> s;
//map<int,int>mp1,mp2;
map<pair<int,int>,int>mp3;
mp3[{0,0}] = 1;
// mp1[0] = 1;
// mp2[0] = 1;
int ans = 0;
int c0 = 0, c1 = 0;
for (auto &i : s) {
if (i == 'A') {
c0++;
}
else if (i == 'T') {
c0--;
}
else if (i == 'C') {
c1++;
}
else {
c1--;
}
//ans += mp1[c0];
//ans += mp2[c1];
ans += mp3[{c0,c1}];
//mp1[c0]++;
//mp2[c1]++;
mp3[{c0,c1}]++;
}
cout << ans << '\n';
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int c = 0;
int t;
if (!c) {
t = 1;
}
else {
cin >> t;
}
while (t--) {
go();
}
} |
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
#include<numeric>
#include <utility>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define REP(i, n) for(int i = 0;i < (n);i++)
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=1000000007;
const llint inf=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-10;
template <class T,class U>bool chmin(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool chmax(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(const vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(const vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
int T;cin>>T;
while(T--){
int i,j,n;cin>>n;
vector<llint>a(n);
for(i=0;i<n;i++){cin>>a[i];}
SO(a);
if(n%2==0){
string ans="Second";
for(i=0;i<n;i+=2){
if(a[i]!=a[i+1]){ans="First";}
}
cout<<ans<<endl;
}else{
cout<<"Second"<<endl;
}
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
/*---------------------SAUGATA KUNDU---------------------------*/
#define int long long int
#define INF (int)(1e9+5)
#define MoD (int)(998244353)
//#define debugn(a) cerr << '[' << ( a ) << ']' << '\n'
#define debug(a) cerr << '[' << a << ']' << '\n'
#define clear(a) memset(a, 0, sizeof(a))
#define fo(i, a, b) for(int i = a; i < b; i++)
#define fos(i, b) for(int i = 0; i < b; i++)
#define foe(i, a) for(auto &i: a)
#define re(i, a, b) for(int i = b-1; i >= a; i--)
#define pb push_back
#define all(c) c.begin(), c.end()
#define sz(x) (int)(x).size()
#define Fast ios::sync_with_stdio(0);cin.tie(0)
//data_structures
#define vt vector
#define que queue
#define sta stack
#define pque priority_queue
#define dque deque
#define point(pt) vt<int>::iterator pt
template<typename T> void read(vt<T> &a){
fos(i, sz(a)) cin >> a[i];
}
#define endl '\n'
template<typename T> void write(vt<T> a){
fos(i, sz(a)) cout << a[i] << ' ';
cout << endl;
}
void solve(){
int a;
cin >> a;
cout << 100-(a%100) << endl;
}
int32_t main() {
Fast;
int t=1;
//cin >> t;
for(int i=1; i<=t; ++i) {
//cout << "Case " <<i<<":\n";
solve();
}
} |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N, K;
cin >> N >> K;
int room, ans;
ans = 0;
for (int i = 0; i < N; i++){
for ( int j = 0; j < K; j++){
room = (i+1) * 100 + (j+1);
ans += room;
}
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
//#include <atcoder/all>
typedef long long ll;
using namespace std;
//using namespace atcoder;
#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n) for(ll i = 0; i < (ll)n; i++)
#define _reps(i, s, n) for(ll i = (ll)(s); i < (ll)n; i++)
#define REP(...) _overload(__VA_ARGS__, _reps, _rep,)(__VA_ARGS__)
#define all(v) (v).begin(),(v).end()
#define UNIQUE(v) (v).erase( unique( all(v) ), (v).end() );
#define MOD 1000000007
int main(){
ll n;
cin >> n;
string s[n];
REP(i, n){
cin >> s[i];
}
ll t[n], f[n];
REP(i, n){
t[i] = 0;
f[i] = 0;
}
if( s[0] == "OR" ){
t[0] = 3;
f[0] = 1;
}else{
t[0] = 1;
f[0] = 3;
}
REP(i, 1, n){
if( s[i] == "OR" ){
t[i] = t[i-1]*2 + f[i-1];
f[i] = f[i-1];
}else{
t[i] = t[i-1];
f[i] = t[i-1] + f[i-1]*2;
}
}
cout << t[n-1] << endl;
return 0;
}
|
#include <bits/stdc++.h>
int main() {
int n, m;
std::cin >> n >> m;
std::vector<int> cnt(n);
for (int i = 0; i < n; ++i) {
std::string s;
std::cin >> s;
for (int j = 0; j < m; ++j) if (s[j] - '0' == 1) ++cnt[i];
}
long long odd = 0, even = 0;
for (int i = 0; i < n; ++i) {
if (cnt[i] & 1) ++odd;
else ++even;
}
std::cout << odd * even << std::endl;
return 0;
}
| #include <bits/stdc++.h>
#include <string>
#include <cmath>
#include <sstream>
#include <unordered_map>
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORD(i, a, b) for(ll i = (a-1); i >= (b); i--)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define ff first
#define ss second
#define spre cout<<fixed<<setprecision(1);
typedef long long int ll;
using namespace std;
// ll mod=67280421310721;
// ll mod=8589934592;
const ll mod=985661441;
ll INF=1e18;
ll po(ll a,ll b){
ll re=1;
while(b)
{
if(b%2==1)
{
re=(re*a);
re%=mod;
}
a=(a*a);
a%=mod;
b>>=1;
}
return re;
}
ll e=5000000;
int main()
{
ll test=1;
// cin>>test;
// spre
while(test--)
{
ll n,m;
cin>>n>>m;
string s;
ll a[2]={0},l=0;
FOR(i,0,n)
{
cin>>s;
l=0;
FOR(j,0,m)
{
l^=(s[j]-'0');
}
// cout<<l<<' ';
a[l]++;
}
cout<<a[0]*a[1];
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define tr(c, i) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define ipr pair<int, int>
#define pb push_back
#define ff first
#define ss second
// #define fill(a,b) memset(a, b, sizeof(a))
#define fr(i, j, k) for (int i = j; i < k; i++)
#define rf(i, j, k) for (int i = j; i >= k;i--)
#define int long long int
#define ll unsigned long long
#define ld long double
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(),x.rend()
#define mp make_pair
#define L(x) ('a'<=x && x<='z')
#define inf INT_MAX
#define read_file(); freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define IOS std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ld pi = acos(-1);
const int mod = 1000000007;
const double epsilon = 1e-9;
template<class T> ostream& operator <<(ostream &out,vector<T> &A){for(auto x:A) out<<x<<" ";return out;}
template<class T> ostream& operator <<(ostream &out,set<T> &A){for(auto x:A) out<<x<<" ";return out;}
template<class T> ostream& operator <<(ostream &out,unordered_set<T> &A){for(auto x:A) out<<x<<" ";return out;}
template <class T1,class T2>T1 powr(T1 a,T2 b){T1 res = 1;fr(i,1,b+1)res = res*a;return res;}
int binpow(int a,int b) {
a=a%mod;
int res = 1;
while (b > 0) {
if (b & 1)res = (res * a)%mod;
a = (a * a)%mod;
b >>= 1;
}
return (res+mod)%mod;
}
const int N = 10000025 ;
int prime[N];
int prime_cnt[N];
void SieveOfEratosthenes()
{
fr(i,0,N)prime[i]=i;
prime[0]=0;
prime[1]=1;
for (int p=2; p*p<=10000000; p++)
{
if (prime[p] == p)
{
for (int i=p; i<=10000000; i += p)
if(prime[i]==i) prime[i] = p;
}
}
}
int32_t main(){
IOS;
int t;
// cin>>t;
t=1;
while(t--){
int a,b;
cin>>a>>b;
cout<<(a+b)/2<<" "<<(a-b)/2<<endl;
}
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define F first
#define S second
#define all(c) ((c).begin()), ((c).end())
#define sz(x) ((int)(x).size())
#define ld long double
template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
os<<"("<<p.first<<", "<<p.second<<")";
return os;
}
template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
os<<"{";
for(int i = 0;i < (int)v.size(); i++){
if(i)os<<", ";
os<<v[i];
}
os<<"}";
return os;
}
#ifdef LOCAL
#define cerr cout
#else
#endif
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int A, B;
cin >> A >> B;
cout << (A + B) / 2 << " " << (A - B) / 2 << endl;
} |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORC(i,a,b,c) for(ll i=(a);i<(b);i+=(c))
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define ff first
#define ss second
#define dd long double
#define all(x) x.begin(),x.end()
template<ll MOD = 998244353>
struct mint{
ll x;
ll mod = MOD;
mint(ll x=0):x(x%MOD){}
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{
mint res(*this);
return res+=a;
}
mint operator-(const mint a) const{
mint res(*this);
return res-=a;
}
mint operator*(const mint a) const{
mint res(*this);
return res*=a;
}
mint power(ll t) const{
if(!t) return 1;
mint a = power(t>>1);
a*=a;
if(t&1) a*=*this;
return a;
}
mint inv() const{
return power(MOD-2);
}
mint& operator/=(const mint a){
return (*this) *= a.inv();
}
mint operator/(const mint a) const{
mint res(*this);
return res/=a;
}
};
template<ll mod>
ostream & operator << (ostream & output,const mint<mod> & a){
output<<a.x;
return output;
}
template<ll mod>
istream & operator >> (istream & input, mint<mod>& a){
input>>a.x;
return input;
}
using mll=mint<>;
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v){
os << "[";
for (ll i=0; i < v.size(); ++i) {
os << v[i];
if (i != v.size() - 1)
os << ", ";
}
os << "]";
return os;
}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v){
os << "{";
for (auto it : v) {
os << it;
if (it != *v.rbegin())
os << ", ";
}
os << "}";
return os;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, const map<T, S>& v){
os<<"{";
for (auto it : v){
os << it.first << " : "
<< it.second ;
if (it != *v.rbegin())
os << ", ";
}
os << "}";
return os;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, const pair<T, S>& v){
os << "(";
os << v.first << ", "
<< v.second << ")";
return os;
}
const ll N=4e5+10;
mll fact[N+1];
mll ifact[N+1];
void init(){
fact[0]=fact[1]=1;
FOR(i,2,N+1){
fact[i]=fact[i-1]*i;
}
ifact[0]=1;
ifact[1]=1;
ifact[1]/=1;
FOR(i,2,N+1){
ifact[i]=1;
ifact[i]/=i;
ifact[i]*=ifact[i-1];
}
}
mll pnc(ll n, ll r){
mll a=fact[n];
a*=ifact[r];
a*=ifact[n-r];
return a;
}
ll spf[N];
void spfe(){
for(ll i=1;i<=N;i++){
spf[i]=i;
}
for(ll i=4;i<=N;i+=2){
spf[i]=2;
}
for(ll i=2;i*i<=N;i++){
if(spf[i]==i){
for(ll j=i*i;j<=N;j+=i){
if(spf[j]==j){
spf[j]=i;
}
}
}
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
init();
spfe();
ll n,m;
cin>>n>>m;
vector<ll> dp(N);
for(ll i=1;i<N;i++){
for(ll j=2*i;j<N;j+=i){
dp[j]++;
}
}
mll ans=0;
for(ll i=1;i<=m;i++){
ll nn=i;
vector<ll> prods;
while(nn!=1){
ll x=spf[nn];
ll temp=1;
while(nn%x==0){
nn/=x;
temp*=x;
}
prods.pb(temp);
}
mll tempo=1;
for(auto & x:prods){
tempo*=pnc(dp[x]+n-1,n-1);
}
ans+=tempo;
}
cout<<ans<<endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const int mod = 998244353;
int inc(int x, int y) { return x + y >= mod ? x + y - mod : x + y; }
vector<int> mult(vector<int> &a, vector<int> &b)
{
vector<int> tmp(a.size());
for (int i = 1; i < a.size(); i++)
{
for (int j = i; j < a.size(); j += i)
{
tmp[j] = inc(tmp[j], 1ll * a[i] * b[j / i] % mod);
}
}
return tmp;
}
vector<int> qpow(vector<int> a, int x)
{
vector<int> res(a.size());
res[1] = 1;
while (x)
{
if (x & 1)
res = mult(res, a);
a = mult(a, a);
x >>= 1;
}
return res;
}
void solve()
{
int n, m;
cin >> n >> m;
vector<int> dp(m + 1, 1);
dp = qpow(dp, n);
int ans = 0;
for (int i = 1; i <= m; i++)
ans = inc(ans, dp[i]);
cout << ans << endl;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T = 1;
while (T--)
{
solve();
}
} |
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <cassert>
#include <random>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long int ll;
const int INF = 1e9;
const double PI = acos(-1);
const int mod = 1000000007;
int main()
{
int h, w;
cin >> h >> w;
vector<string> s(h);
rep(i, h) {
cin >> s[i];
}
int ans = 0;
rep(i, h) {
rep(j, w - 1) {
if (s[i][j] == '.' && s[i][j + 1] == '.') {
ans++;
}
}
}
rep(i, w) {
rep(j, h - 1) {
if (s[j][i] == '.' && s[j + 1][i] == '.') {
ans++;
}
}
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
//#define ll long long
int main() {
ios::sync_with_stdio(false);
int h, w, x, y;
cin >> h >> w >> x >> y;
x--; y--;
vector<string> vec(h);
int cnt = 0;
for (int i = 0; i < h; i++) {
cin >> vec[i];
}
for (int i = x - 1; i >= 0; i--) {
if (vec[i][y] == '.') {
cnt++;
}else break;
}
for (int i = x; i < h; i++) {
if (vec[i][y] == '.') {
cnt++;
}else break;
}
for (int i = y - 1; i >= 0; i--) {
if (vec[x][i] == '.') {
cnt++;
}else break;
}
for (int i = y + 1; i < w; i++) {
if (vec[x][i] == '.') {
cnt++;
}else break;
}
cout << cnt << endl;
return 0;
} |
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main() {
string x;
char a='.';
cin>>x;
int count =x.size();
for(int i=0;i<count;i++){
if(x.at(i)==a){
break;
}
else{
cout<<x.at(i);
}
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
long long n;
cin >> n;
int d = to_string(n).length();
long long ans = 0, mul = 1;
for (int i = 1; i <= d - 1; i++) {
ans += (i - 1) / 3 * 9 * mul;
mul *= 10;
}
ans += (d - 1) / 3 * (n - mul + 1);
cout << ans << '\n';
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
map<ll,int>Q;
int main(){
ll n;
cin>>n;
for(ll i=1,j=3;;i++){
Q[j]=i;
if(1e18/3<j)break;
j*=3;
}
for(ll i=1,j=5;;i++,j*=5){
if(j>n)break;
ll k=n-j;
if(Q[k]!=0){
printf("%d %lld\n",Q[k],i);
return 0;
}
if(1e18/5<j)break;
}
puts("-1");
return 0;
} | #include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <functional>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <unordered_map>
#include <cstdio>
#include <climits>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
ll gcd(ll x, ll y) {
if (y == 0)return x;
return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
return x / gcd(x, y)*y;
}
ll kai(ll x, ll y, ll m) {
ll res = 1;
for (ll i = x - y + 1; i <= x; i++) {
res *= i; res %= m;
}
return res;
}
ll mod_pow(ll x, ll y, ll m) {
ll res = 1;
while (y > 0) {
if (y & 1) {
res = res * x % m;
}
x = x * x % m;
y >>= 1;
}
return res;
}
ll comb(ll x, ll y, ll m) {
if (y > x)return 0;
return kai(x, y, m) * mod_pow(kai(y, y, m), m - 2, m) % m;
}
ll n;
signed main() {
std::random_device rnd;
std::mt19937_64 mt(rnd());
cin >> n;
for (int i = 1; i <= 37; i++)for (int j = 1; j <= 25; j++) {
ll p = 1, q = 1;
for (int k = 0; k < i; k++)p *= 3;
for (int k = 0; k < j; k++)q *= 5;
if (p + q == n) {
cout << i << " " << j << endl;
return 0;
}
}
cout << -1 << endl;
} |
#include <bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define mod 1000000007
#define inf 1e18
#define N 1000043
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define loop(a,b) for(int i=a;i<b;i++)
#define test int t; cin >> t; while(t--)
#define pll pair<ll,ll>
#define int ll
using namespace std;
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
string a;
cin >> a;
reverse(a.begin(),a.end());
for(int i=0;i<a.length();i++){
if(a[i]=='9') a[i]='6';
else if(a[i]=='6') a[i]='9';
}
cout << a << endl;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
ull maxprim = 1e9 + 7;
ull gcd (ull a, ull b) {
return b ? gcd (b, a % b) : a;
}
int main()
{ ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll tst,n,i,j,ite=0,flg,m,lim,k,l,r,q,res,i1,j1,x;
tst=1;//cin>>tst;
while(tst--){
string str;
cin>>str;
for(i = str.length() - 1;i>=0;i--){
if(str[i]=='6')cout<<'9';
else if(str[i]=='9')cout<<'6';
else cout<<str[i];
}
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
const long long MOD = 1000000007;
int main(){
int n,a;
int x=0;
cin >> n;
vector<bool> c(200001,true);
rep(i,n){
cin >> a;
c.at(a)=false;
while(!c.at(x)) x++;
cout << x << endl;
}
}
| #include<iostream>
using namespace std;
int main()
{
int64_t n;
cin >> n;
if(n % 2 == 0)
cout << "White" << endl;
else
cout << "Black" << endl;
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 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
}
int main()
{
ash();
ll n;
cin>>n;
ll p=1<<n;
ll i;
vector<pair<ll,ll>> m(p);
REP(i,p)
{
ll x;
cin>>x;
m[i]={x,i+1};
}
vector<pair<ll,ll>> m1;
while(p!=2)
{
for(i=0;i<p;i+=2)
{
// cout<<m[i].fp<<"a"<<m[i].sp<<" "<<m[i+1].fp<<"a"<<m[i+1].sp<<"\n";
if(m[i].fp>m[i+1].fp)
m1.pb({m[i].fp,m[i].sp});
else
m1.pb({m[i+1].fp,m[i+1].sp});
}
//cout<<"\n";
m.clear();
m=m1;
m1.clear();
p/=2;
}
if(m[0].fp<m[1].fp)
cout<<m[0].sp;
else
cout<<m[1].sp;
} | #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 T> using oset =
tree<T, null_type, less<T>,
rb_tree_tag, tree_order_statistics_node_update>;
#define odrkey order_of_key
#define fbodr find_by_order
#define ll long long
#define sq(a) ((a)*(a))
#define ull unsigned long long
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define watch(x) cout << (#x) << " is " << (x) << endl
#define pi 3.1415926536
#define nwl cout <<"\n";
#define MAXN 100009
#define ff first
#define ss second
#define pb push_back
#define pf push_front
ll Pow(ll a, ll b) {
if (a == 0) return 0LL;
ll ans = 1;
for (int i = 0; i < b; i++) {
ans *= a;
}
return ans;
}
ll lcm(ll a, ll b) {
return (a * b) / __gcd(a, b);
}
ll md = (ll) 1e9 + 7;
ll bigmod(ll a, ll b, ll m) {
if (b == 0) return 1LL;
ll tm = bigmod(a, b / 2, m);
tm = (tm * tm) % m;
if (b % 2) tm = (tm * a) % m;
return tm;
}
ll ncr(ll n, ll r) {
if (r > n - r) r = n - r;
ll up = 1;
ll down = 1;
for (ll i = 0; i < r; i++) {
up = (up * (n - i)) % md; /* md== mod */
down = (down * (r - i)) % md;
}
return (up * bigmod(down, md - 2, md)) % md;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n;
cin >> n ;
ll ans = 0;
for (int i = 0; i < n; i++) {
ll x;
cin >> x;
if (x > 10) {
x -= 10;
ans += x;
}
}
cout << ans << endl;
}
|
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<bitset>
#include<math.h>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pii;
const int N=2000000+100;
const db pi=acos(-1.0);
#define lowbit(x) ((x)&(-x))
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define go(u,i) for (register int i=head[u],v=sq[i].to;i;i=sq[i].nxt,v=sq[i].to)
#define fir first
#define sec second
#define mkp make_pair
#define pb push_back
#define maxd 1000000007
#define eps 1e-8
inline int read()
{
int x=0,f=1;char ch=getchar();
while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
return x*f;
}
inline ll readll()
{
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;
}
namespace My_Math{
#define N 2000000
int fac[N+100],invfac[N+100];
int add(int x,int y) {return x+y>=maxd?x+y-maxd:x+y;}
int dec(int x,int y) {return x<y?x-y+maxd:x-y;}
int mul(int x,int y) {return 1ll*x*y%maxd;}
ll qpow(ll x,int y)
{
ll ans=1;
while (y)
{
if (y&1) ans=mul(ans,x);
x=mul(x,x);y>>=1;
}
return ans;
}
int getinv(int x) {return qpow(x,maxd-2);}
int C(int n,int m)
{
if ((n<m) || (n<0) || (m<0)) return 0;
return mul(mul(fac[n],invfac[m]),invfac[n-m]);
}
void math_init()
{
fac[0]=invfac[0]=1;
rep(i,1,N) fac[i]=mul(fac[i-1],i);
invfac[N]=getinv(fac[N]);
per(i,N-1,1) invfac[i]=mul(invfac[i+1],i+1);
}
#undef N
}
using namespace My_Math;
int main()
{
int n=read(),m=read(),k=read();
if (n>m+k) {puts("0");return 0;}
math_init();
int ans=dec(C(n+m,m),C(n+m,m+k+1));
printf("%d",ans);
return 0;
} | // Problem: E - White and Black Balls
// Contest: AtCoder - AtCoder Beginner Contest 205
// URL: https://atcoder.jp/contests/abc205/tasks/abc205_e
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
// C(n + m, n) - C(n + m, n - k - 1)
// (m, n) -> (n - k - 1, m + k + 1), y = x + k + 1
ll x, y;
void ex_gcd(ll a, ll b) {
if (b == 0) {
x = 1, y = 0;
return;
}
ex_gcd(b, a % b);
ll t = x;
x = y;
y = t - a / b * y;
return;
}
ll inv(int p) {
ex_gcd(p, MOD);
return (x % MOD + MOD) % MOD;
}
ll C(int n, int m) {
if (m < 0) return 0;
ll res = 1;
for (int i = 1; i <= m; ++i) {
res = res * (n - i + 1) % MOD;
res = res * inv(i) % MOD;
}
return res;
}
int main() {
int n, m, k;
cin >> n >> m >> k;
if (n > m + k) {
cout << 0;
return 0;
}
ll p = C(n + m, n), q = C(n + m, n - k - 1);
cout << (p - q + MOD) % MOD;
return 0;
} |
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag,
tree_order_statistics_node_update>;
template <typename T>
using omultiset = tree<T, null_type, less_equal<T>, rb_tree_tag,
tree_order_statistics_node_update>;
#define ll long long
#define pb push_back
#define mp make_pair
#define umap unordered_map
#define fr(i,a,b) for(int i=a;i<b;i++)
const int mx=1e7+5;
const int mod=1e9+7;
#define deb(x) cout<<x<<endl;
#define debl(x) cout<<x<<" ";
#define spair(p) cout<<"("<<p.first<<","<<p.second<<")"<<endl;
int gcdExtended(int a, int b, int* x, int* y)
{
if (a == 0)
{
*x = 0, *y = 1;
return b;
}
int x1, y1; // To store results of recursive call
int gcd = gcdExtended(b % a, a, &x1, &y1);
*x = y1 - (b / a) * x1;
*y = x1;
return gcd;
}
ll modInverse(ll a, ll m)
{
int x, y;
int g = gcdExtended(a, m, &x, &y);
if (g != 1)
return 0;
else
{
// m is added to handle negative x
ll res = (x % m + m) % m;
return res;
}
}
ll nCr(int n, int r,int m){
if(r>n){
return 0;
}
if(r>n-r){
r = n-r;
}
ll ans = 1;
for(int i = 1; i<=r ; i++){
ans *= (n-i+1);
ans%= m;
ans *= modInverse(i, m);
ans %= m;
}
return ans;
}
long long binpow(long long a, long long b) {
long long res = 1;
while (b > 0) {
if (b & 1)
res = res * a;
a = a * a;
b >>= 1;
}
return res;
}
long long binpow(long long a, long long b, long long m)
{
a %= m;
long long res = 1;
while (b > 0)
{
if (b & 1)
res = res * a % m;
a = a * a % m;
b >>= 1;
}
return res;
}
template<typename u,typename v>
auto min(u a,v b)
{
return a>b ? b:a;
}
template<typename u,typename v>
auto max(u a,v b)
{
return a<b?b:a;
}
void solve()
{
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin>>n;
int val;
set<int> a,b;
for(int i=0;i<n;i++)
{
cin>>val;
a.insert(val);
}
for(int i=0;i<n;i++)
{
cin>>val;
b.insert(val);
}
int max=*(b.begin());
int min=*a.rbegin();
if(min > max)
{
deb(0);
return 0;
}
deb(max - min + 1);
} |
/**
* Dont raise your voice, improve your argument.
* --Desmond Tutu
*/
#include <bits/stdc++.h>
using namespace std;
const bool ready = [](){
ios_base::sync_with_stdio(false); cin.tie(0);
cout << fixed << setprecision(12);
return true;
}();
const double PI = acos(-1);
using ll= long long;
#define int ll
#define all(v) (v).begin(), (v).end()
#define fori(n) for(int i=0; i<int(n); i++)
#define cini(i) int i; cin>>i;
#define cins(s) string s; cin>>s;
#define cind(d) double d; cin>>d;
#define cinai(a,n) vi a(n); fori(n) { cin>>a[i]; }
#define cinas(s,n) vs s(n); fori(n) { cin>>s[i]; }
#define cinad(a,n) vd a(n); fori(n) { cin>>a[i]; }
using pii= pair<int, int>;
using pdd= pair<double, double>;
using vd= vector<double>;
using vb= vector<bool>;
using vvb= vector<vb>;
using vi= vector<int>;
using vvi= vector<vi>;
using vs= vector<string>;
#define endl "\n"
/* We need to find foreach bulb the leftnearsest and rightnearest blocks.
* But what about overcount?
*
* We count to N and W up to next bulb or block.
* We count to S and E only if the next block is more near than the next bulb.
*
* fu.. This does not work, consider horizontal illuminated fields
* and vertical ones. They intersect!
*
* Can we maintain segment trees and do range updates?
*
* -> Consider all four direction separate.
*/
void solve() {
cini(h);
cini(w);
cini(n);
cini(m);
vvb bu(h, vb(w));
vvb bl(h, vb(w));
for(int i=0; i<n; i++) {
cini(r); r--;
cini(c); c--;
bu[r][c]=true;
}
for(int i=0; i<m; i++) {
cini(r); r--;
cini(c); c--;
bl[r][c]=true;
}
vvb ans(h, vb(w));
/* dir E */
for(int i=0; i<h; i++) {
int on=false;
for(int j=0; j<w; j++) {
if(bu[i][j])
on=true;
else if(bl[i][j])
on=false;
if(on)
ans[i][j]=true;
}
}
/* dir W */
for(int i=0; i<h; i++) {
int on=false;
for(int j=w-1; j>=0; j--) {
if(bu[i][j])
on=true;
else if(bl[i][j])
on=false;
if(on)
ans[i][j]=true;
}
}
/* dir S */
for(int j=0; j<w; j++) {
int on=false;
for(int i=0; i<h; i++) {
if(bu[i][j])
on=true;
else if(bl[i][j])
on=false;
if(on)
ans[i][j]=true;
}
}
/* dir N */
for(int j=0; j<w; j++) {
int on=false;
for(int i=h-1; i>=0; i--) {
if(bu[i][j])
on=true;
else if(bl[i][j])
on=false;
if(on)
ans[i][j]=true;
}
}
int ansv=0;
for(int i=0; i<h; i++)
for(int j=0; j<w; j++) {
if(ans[i][j])
ansv++;
}
cout<<ansv<<endl;
}
signed main() {
solve();
}
// FIRST THINK, THEN CODE
// DO NOT JUMP BETWEEN PROBLEMS
|
#include <bits/stdc++.h>
using namespace std;
#define repr(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
typedef pair<ll,ll> P;
#define mod 1000000007
ll gcd(ll x,ll y) {return y ? gcd(y,x%y) : x;}
ll lcm(ll x,ll y) {return x/gcd(x,y)*y;}
int main(){
int a,b;
cin >> a >> b;
int aa=0,bb=0;
while(a){
aa+=a%10;
a/=10;
}
while(b){
bb+=b%10;
b/=10;
}
if(aa<bb) aa=bb;
cout << aa << endl;
return 0;
}
| #include <iostream>
#include <vector>
int main() {
int N, M;
std::cin >> N >> M;
std::vector<std::pair<int, int>> conditions(M);
for (auto& [A, B] : conditions) {
std::cin >> A >> B;
A--;
B--;
}
int K;
std::cin >> K;
std::vector<std::pair<int, int>> choices(K);
for (auto& [C, D] : choices) {
std::cin >> C >> D;
C--;
D--;
}
int ans = 0;
for (int i = 0; i < 1 << K; i++) {
std::vector<bool> dishes(N);
for (int j = 0; j < K; j++) {
const auto& [C, D] = choices[j];
if (i & (1 << j)) {
dishes[C] = 1;
}
else {
dishes[D] = 1;
}
}
int cnt = 0;
for (auto& [A, B] : conditions)
if (dishes[A] && dishes[B]) cnt++;
if (ans < cnt) ans = cnt;
}
std::cout << ans << std::endl;
} |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ll long long
int main(){
ll n;
cin >> n;
ll ans = 0;
for(ll i=0;i<n;i++){
ll a;
cin >> a;
if(a > 10){
ans += a-10;
}
}
cout << ans << 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-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
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;
} |
#include <iostream>
#include <cstdio>
using namespace std;
using ll = long long;
int main() {
ll n, m; cin >> n >> m;
ll array[n], cnt[n] = {0}, ans = n;
for (ll i = 0; i < n; i++) {
cin >> array[i];
}
for (ll i = 0; i < m; i++) {
cnt[array[i]]++;
}
for (ll i = 0; i < n; i++) {
if (cnt[i] == 0) {
ans = i;
break;
}
}
for (ll i = m; i < n; i++) {
ll a = array[i];
ll b = array[i-m];
cnt[a]++;
cnt[b]--;
if (b < ans && cnt[b] == 0) {
ans = b;
}
}
cout << ans << endl;
return 0;
} | /*
ID: Trump
TASK:
LANG: C++
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include <iostream>
#include <fstream>
#include <cstring>
#include <algorithm>
#include <cmath>
#define sll(n) scanf("%lld",&n);
#define sll2(a,b) scanf("%lld",&n);
#define sll3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c);
#define slb(n) scanf("%Lf",&n);
#define pll(n) printf("%lld",n);
#define pln printf("\n");
#define plb(n) printf("%Lf",n);
#define plb2(n) printf("%.2Lf",n);
#define plb3(n) printf("%.3Lf",n);
#define plb4(n) printf("%.4Lf",n);
#define plb5(n) printf("%.5Lf",n);
#define plb6(n) printf("%.6Lf",n);
using namespace std;
typedef long long ll;
typedef long double lb;
typedef double db;
typedef int it;
typedef bool bl;
//#define MARK
const ll losn=1e6+5;
const ll maxn=1e5+5;
const ll minn=1e3+5;
const ll tiny=1e2+5;
const ll inf=1e9;
const ll binf=1e18;
const ll mod=1e9+7;
const ll lmod=998244353;
const ll hashmod=4698571;
const lb pi=3.1415926;
const ll myn=0;
void gk(){cout<<"---------------"<<endl;}
void ck(){cout<<1<<endl;}
void ck(ll a){cout<<a<<endl;}
void ck(ll a[minn][minn],ll n,ll m){for(ll i=1;i<=n;i++){for(ll j=1;j<=m;j++){cout<<a[i][j]<<" ";}cout<<endl;}}
ll n,m,k,T,u,v,len;
ll arr[losn*2];
struct node{
ll s,nums,as;
};
node tree[losn*2<<4];
void pushup(ll rt){
if(tree[rt<<1].s<tree[rt<<1|1].s){
tree[rt]=tree[rt<<1];
}else{
tree[rt]=tree[rt<<1|1];
}
}
void build(ll l,ll r,ll rt){
ll mid=(l+r)>>1;
if(l==r){
tree[rt].s=l;
tree[rt].nums=0;
tree[rt].as=0;
return;
}
if(l<r){
build(l,mid,rt<<1);
build(mid+1,r,rt<<1|1);
}
pushup(rt);
}
void update(ll x,ll c,ll l,ll r,ll rt){
ll mid=(l+r)>>1;
if(l==r){
tree[rt].nums+=c;
if(tree[rt].nums==0){
tree[rt].s=l;
}else{
tree[rt].s=binf;
}
return ;
}
if(x<=mid){
update(x,c,l,mid,rt<<1);
}
if(x>mid){
update(x,c,mid+1,r,rt<<1|1);
}
pushup(rt);
}
int main(){
//#ifdef MARK
// freopen("input.in", "r", stdin);
// freopen("ouput.out", "w", stdout);
// freopen("ouput.out", "r", stdin);
// freopen("input.in", "w", stdout);
//#endif
cin>>n>>m;
for(ll i=1;i<=n;i++){
cin>>arr[i];
arr[i]+=1;
}
build(1,m,1);
for(ll i=1;i<=m;i++){
if(arr[i]>=m+1){
}else{
update(arr[i],1,1,m,1);
}
}
ll l=1,r=m;
ll ans=binf;
while(r<=n){
node q=tree[1];
// cout<<q.s<<endl;
if(q.s==binf){
ans=min(ans,m);
}else{
ans=min(ans,q.s-1);
}
r++;
if(arr[r]<=m){
update(arr[r],1,1,m,1);
}
if(arr[l]<=m){
update(arr[l],-1,1,m,1);
}
l++;
if(r==n+1){
break;
}
}
ck(ans);
return 0;
}
/*
0 1 2
2
*/ |
#include<bits/stdc++.h>
#include<string>
using namespace std;
#define ll long long int
#define ld long double
#define pb push_back
#define all(v) v.begin(),v.end()
#define sz(x) ((int)(x).size())
#define deb(x) cout<< #x << '=' << x <<endl
#define MOD 1000000007
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n;
cin>>n;
ll a[n] , b[n] , c[n];
map<ll , ll> mp1 , mp2;
for(int i = 0; i < n; i++){
cin>>a[i];
mp1[a[i]]++;
}
for(int i = 0; i < n; i++){
cin>>b[i];
}
for(int i = 0; i < n; i++){
cin>>c[i];
mp2[b[c[i] - 1]]++;
}
ll ans = 0;
for(auto it : mp1){
ans += (it.second * mp2[it.first]);
}
cout<<ans;
return 0;
} | //wtrl,everybody hangbeat me
#pragma GCC optimize(3)
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,pii> piiii;
typedef vector<pii> vii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef queue<char> qc;
typedef queue<string> qs;
typedef vector<char> vc;
typedef vector<string> vs;
typedef map<char,int> mpci;
typedef map<int,int> mpii;
typedef map<string,int> mpsi;
typedef set<int> sei;
typedef set<char> sec;
typedef set<string> ses;
typedef stack<ll> si;
typedef stack<char> sc;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef vector<pll> vpll;
typedef vector<pdd> vdd;
typedef unsigned int uint;
typedef long double ld;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vii> vvii;
/*=====================================================================*/
#define pb push_back
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define sz(a) (int)(a.size())
#define len(a) (int)(a.length())
#define all(s) (s).begin(),(s).end()
#define fi first
#define se second
#define be begin
#define en end
#define m_p make_pair
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define forn(i,p,n) for(int i=p;i<=n;i++)
#define ford(i,p,n) for(int i=n;i>=p;i--)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();++i)
#define zero(a) memset(a,0,sizeof(a))
#define number(a,num) memeset(a,num,sizeof(a))
#define INF 1e9
#define PI acos(-1)
/*=====================================================================*/
string int_to_string(ll n)
{
string s="";
while(n)
{
ll now=n%10;
s+=now+'0';
n/=10;
}
reverse(s.begin(),s.end());
return s;
}
ll string_to_int(string s)
{
ll n=0;
rep(i,s.size())
{
n*=10;
n+=s[i]-'0';
}
return n;
}
/*======================================================================*/
ll lcm(int a,int b)
{
return a/__gcd(a,b)*b;
}
bool prime(int n)
{
if(n==0||n==1)
return false;
for(int i=2;i*i<=n;i++)
if(n%i==0)
return false;
return true;
}
string turn(int n,int k)
{
string s="";
while(n)
{
s+=(char)(n%k+'0');
n/=k;
}
reverse(s.begin(),s.end());
return s;
}
const string turn16(int n)
{
string s="";
while(n!=0)
{
if(n%16>9)
s+=(char)('A'+n%16-10);
else
s+=(char)('0'+n%16);
n/=16;
}
reverse(s.begin(),s.end());
return s;
}
/*======================================================================*/
const int dx[]={-1,0,1,0};
const int dy[]={0,-1,0,1};
const int month[2][12]={{31,28,31,30,31,30,31,31,30,31,30,31},{31,29,31,30,31,30,31,31,30,31,30,31}};
int a[10010];
/*======================================================================*/
int main()
{
std::ios::sync_with_stdio(false);
/*
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
*/
/*====================================================================*/
int n;
cin>>n;
rep(i,n)
{
cin>>a[i];
}
int ans=0,maxn;
rep(i,n)
{
maxn=a[i];
ans=max(ans,maxn);
forn(j,i+1,n-1)
{
maxn=min(maxn,a[j]);
ans=max(ans,maxn*(j-i+1));
}
}
cout<<ans<<endl;
return 0;
}
|
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please
int P[100001];
int sei[100001], fu[100001], kisuu[100001], ind[100001], kazu[100001], kazu2[100001];
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
rep1(i, N - 1) {
cin >> P[i + 1];
kazu[P[i + 1]]++;
}
rep(i, N) kazu2[i + 1] = (kazu[i + 1] += kazu[i]);
for (int i = N; i >= 2; i--) {
int ret = sei[i] - 1;
auto ki = kisuu + kazu[i - 1];
int sz = kazu2[i - 1] - kazu[i - 1];
sort(ki, ki + sz);
if (sz & 1) {
ret -= fu[i];
rep(j, sz) {
if (j & 1) ret -= ki[j];
else ret += ki[j];
}
}
else {
ret += fu[i];
rep(j, sz) {
if (j & 1) ret += ki[j];
else ret -= ki[j];
}
}
if (ret & 1) {
kisuu[kazu2[P[i] - 1]++] = ret;
}
else {
if (ret >= 0) sei[P[i]] += ret;
else fu[P[i]] += ret;
}
}
int ret = sei[1] - 1;
auto ki = kisuu + kazu[0];
int sz = kazu2[0] - kazu[0];
sort(ki, ki + sz);
if (sz & 1) {
ret -= fu[1];
rep(j, sz) {
if (j & 1) ret -= ki[j];
else ret += ki[j];
}
}
else {
ret += fu[1];
rep(j, sz) {
if (j & 1) ret += ki[j];
else ret -= ki[j];
}
}
co((N - ret) / 2);
Would you please return 0;
} | // Problem: C - DFS Game
// Contest: AtCoder - AtCoder Regular Contest 112
// URL: https://atcoder.jp/contests/arc112/tasks/arc112_c
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include <cstdio>
#include <set>
const int maxn = 1e5 + 19;
struct Edge{
int to, next;
}edge[maxn];
int head[maxn], cnt;
inline void add(int from, int to){
edge[++cnt].to = to;
edge[cnt].next = head[from];
head[from] = cnt;
}
int n, dp[maxn][2], size[maxn];
std::multiset<int> s;
void dfs(int node){
int odd = 0;
size[node] = 1;
for(int i = head[node]; i; i = edge[i].next)
dfs(edge[i].to), size[node] += size[edge[i].to], odd += size[edge[i].to] & 1;
for(int now = 0; now < 2; ++now){
s.clear();
dp[node][now] = now & 1;
for(int i = head[node]; i; i = edge[i].next)
if(size[edge[i].to] & 1){
dp[node][now] += dp[edge[i].to][now];
s.insert(dp[edge[i].to][now ^ 1] - dp[edge[i].to][now]);
}
else{
if((dp[edge[i].to][now] < dp[edge[i].to][now ^ 1]) == (now & 1)) dp[node][now] += dp[edge[i].to][now];
else if(odd & 1) dp[node][now] += dp[edge[i].to][now ^ 1];
else dp[node][now] += dp[edge[i].to][now];
}
int sz = s.size();
if(!(now & 1))
for(int i = 1; i <= sz; ++i)
if(i & 1) s.erase(s.find(*s.begin()));
else dp[node][now] += *s.begin(), s.erase(s.find(*s.begin()));
else
for(int i = 1; i <= sz; ++i)
if(i & 1) s.erase(s.find(*--s.end()));
else dp[node][now] += *--s.end(), s.erase(s.find(*--s.end()));
}
}
int main(){
scanf("%d", &n);
for(int i = 2, p; i <= n; ++i){
scanf("%d", &p);
add(p, i);
}
dfs(1); printf("%d\n", dp[1][1]);
} |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define f first
#define s second
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll n,x;
string s;
cin >> n >> x >> s;
for(int i=0; i<n; i++)
{
if (s[i]=='x')
{
if (x) x--;
}
else
x++;
}
cout << x << '\n';
return 0;
}
| #include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<unordered_map>
#include<vector>
#include<unordered_set>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
//Required Headers
using namespace std;
#define PI 3.1415926535897932384626
#define sp(x,y) fixed<<setprecision(y)<<x
#define mk(arr,n,type) type *arr=new type[n]; // dynamic allocation of memory
#define del(arr) delete []arr; // deletion of allocated memory
const int mod = 1'000'000'007;
const int inf = 1e9 + 5;
//for loops
#define fo(i, n) for(i=0; i<n; i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define fo2(i, n,t) for(i=0; i<n; i+=t)
//essentials
#define tc(t) ll t;ll i; cin>>t; fo(i,t)
#define ll long long
//STL
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define vbe(x) x.begin(), x.end()
#define sortvbe(x) sort(vbe(x))
#define setit(it, a) for(auto it = a.begin(); it != a.end(); it++)
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef set<int> si;
typedef set<ll> sl;
//inputs
#define ci(x) cin>>x;
#define ci2(x,y) cin>>x>>y;
//template<typename... T>
//void read(T&... args) {
// ((cin >> args), ...);
//}
//outputs
#define pi(x) cout<<x;
#define pinl(x) cout<<x<<endl;
//template<typename... T>
//void write(T&&... args) { //rvalue reference is new to C++
// ((cout << args << " "), ...);
//}
ll m=1000000007;
//some imp func
inline int gcd(int a,int b) {if (a==0) return b; else return gcd(b%a,a);}
inline void take_input(int A[],int n){for(int i=0;i<n;i++){ cin>>A[i];}}
inline void show(int *A,int n){for(int i=0;i<n;i++){cout<<A[i]<<" ";}cout<<endl;}
inline bool sortbysec(const pair<int,int> &a, const pair<int,int> &b) { return (a.second < b.second); }
inline bool sortbysecdesc(const pair<int,int> &a, const pair<int,int> &b) { return (a.second > b.second); }
inline void swap(int &a,int &b){int temp=a;a=b;b=temp;}
inline void initialise(int A[],int n,int k){for(int i=0;i<n;i++){A[i]=k;}}
inline void vect_input(vector<int>&v,int n){for(int i=0;i<n;i++){int input;cin>>input;v.pb(input);}}
inline int modulo(int a,int b){return (b+(a%b))%b;}
inline int getascii(char ch){return (int)ch;}
inline ll expo_mod(ll e,ll p){if(p==0)return (1);ll ans=expo_mod(e,p/2);ans=((ans%m)*(ans%m))%m;if(p%2!=0)ans=((e%m)*(ans%m))%m;return ans%m;}
inline ll expo(ll e,ll p){if(p==0)return (1);ll ans=expo(e,p/2);ans=(ans)*(ans);if(p%2!=0)ans=(e)*(ans);return ans;}
inline ll com_wd_m(ll n,ll r,ll m){ll p=1,d=1;if(r==0 or r==n )return(1);if(r==1 )return (n%m);r=min(r,n-r);for(ll i=0;i<r;i++){p=((p%m)*((n%m)-(i%m))%m)%m;p=((p%m)*(expo((i+1),m-2)%m))%m;}return (p%m);}
template<typename T>
void show_vect(vector<T> v){for(int i=0;i<v.size();i++){cout<<v[i]<<" ";}cout<<endl;}
template<typename T>
void vect_input(vector<T>&v,T n){for(int i=0;i<n;i++){cin>>v[i];}}
ll fact(ll n) { return (n==1 || n==0) ? 1: n * fact(n - 1); }
ll fact_mod(ll n,ll x) {if(n==x) return 1; return (n==1 || n==0) ? 1: ((n%m) * (fact((n - 1)%m))%m)%m; }
//debugging
#define deb(x) cout << #x << " = " << x << endl; //to check the values
#define deb2(x, y) cout << #x << " = " << x << "," << #y << " = " << y << endl;
void A_A()
{
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.in", "r", stdin);
freopen("output.in", "w", stdout);
freopen("error.in","w",stderr);
#endif
}
ll num;
void solve(){
ll n,x;
string s;
cin>>n>>x;
cin>>s;
for(auto i:s){
if(i=='o') x++;
if(i=='x' && x-1>=0) x--;
}
cout<<x;
}
int main(){
A_A();
// tc(t){
solve();
// }
return 0;
}
/*
*/ |
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define MAX INT_MAX
#define MIN INT_MIN
#define F first
#define S second
#define pbmax priority_queue<int>//max heap
#define pbmin priority_queue<int, vector<int>, greater<int>>//min heap priority_queue
#define lpi(i,a,b) for(int i=0;i<b;i++)
#define lpd(i,a,b) for(int i=a;i>=b;i--)
const double pi = 3.14159265359;
const int mod = 1e9 + 7;
const int N = 2e5 + 5;
vector<int>G[N];
vector<int>vis(N, 0);
void dfs(int node, int &dist)
{
vis[node] = 1;
dist++;
for (auto x : G[node])
{
if (vis[x] == 0)
{
dfs(x, dist);
}
}
}
void task()
{
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++)
{
cin >> a[i];
}
int l = 0, r = n - 1;
vector<pair<int, int>>vp;
set<int>S;
while (l < r)
{
if (a[l] != a[r]) {
vp.pb({a[l], a[r]});
S.insert(a[l]);
S.insert(a[r]);
}
l++;
r--;
}
if (vp.size() == 0)
{
cout << 0 << '\n';
return;
}
for (auto x : vp)
{
G[x.F].pb(x.S);
G[x.S].pb(x.F);
}
int ans = 0;
for (auto x : S)
{
if (vis[x] == 0)
{
int cnt = 0;
dfs(x, cnt);
ans += max((int)0, cnt - 1);
}
}
cout << ans << '\n';
}
int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int test_cases = 1;
//cin >> test_cases;
while (test_cases--)
{
task();
}
} | #include <bits/stdc++.h>
const long long INF = 1e9;
const long long MOD = 1e9 + 7;
//const long long MOD = 998244353;
const long long LINF = 1e18;
using namespace std;
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE" ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible" ) << endl
#define dump(x) cout << #x << " = " << (x) << endl
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define COUT(x) cout<<(x)<<endl
#define SCOUT(x) cout<<(x)<<" "
#define VECCOUT(x) for(auto&youso_: (x) )cout<<right<<setw(10)<<youso_<<" ";cout<<endl
#define ENDL cout<<endl
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) long long __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define mp make_pair
#define PQ priority_queue<long long>
#define PQG priority_queue<long long,V,greater<long long>>
typedef long long ll;
typedef vector<long long> vl;
typedef vector<long long> vi;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<vb> vvb;
typedef vector<vc> vvc;
typedef pair<long long, long long> pll;
#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
cin>>head;
CINT(move(tail)...);
}
template<class T>
void mod(T &x) {
x %= MOD;
x += MOD;
x %= MOD;
}
ll GCD(ll a, ll b) {
if(b == 0) return a;
else return GCD(b, a%b);
}
struct COMB{
vl fact, fact_inv, inv;
void init_nCk(long long SIZE) {
fact.resize(SIZE + 5);
fact_inv.resize(SIZE + 5);
inv.resize(SIZE + 5);
fact.at(0) = fact.at(1) = fact_inv.at(0) = fact_inv.at(1) = inv.at(1) = 1;
for(long long i = 2; i < SIZE + 5; i++) {
fact.at(i) = fact.at(i - 1)*i%MOD;
inv.at(i) = MOD - inv.at(MOD%i)*(MOD/i)%MOD;
fact_inv.at(i) = fact_inv.at(i - 1)*inv.at(i)%MOD;
}
}
long long nCk (long long n, long long k) {
assert(!(n < k));
assert(!(n < 0 || k < 0));
return fact.at(n)*(fact_inv.at(k)*fact_inv.at(n - k)%MOD)%MOD;
}
};
ll extGCD(ll a, ll b, ll &x, ll &y) {
if(b == 0) {
x = 1;
y = 0;
return a;
}
ll d = extGCD(b, a%b, y, x);
y -= a/b*x;
return d;
}
void Main() {
CIN(K);
ll res = 0;
for(int a = 1; a*a*a <= K; a++) {
int k = K/a;
for(int b = a; b*b <= k; b++) {
for(int c = b; b*c <= k; c++) {
if(a*b*c <= K) {
if(a != b && b != c) {
res += 6;
} else if(a == b && b != c) {
res += 3;
} else if(a != b && b == c) {
res += 3;
} else {
res += 1;
}
}
}
}
}
cout << res << endl;
}
int main() {
cout << fixed << setprecision(15);
Main();
return 0;
} |
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <functional>
#include <queue>
#include <unordered_set>
#include <climits>
#include <set>
#include <list>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
int main() {
#ifdef DEBUG
std::ifstream in("input.txt");
std::cin.rdbuf(in.rdbuf());
#endif
ll K;
cin >> K;
ll ans1 = 0;
ll ans2 = 0;
ll ans3 = 0;
for(ll A = 1; A <= K; A++){
for(ll B = A; A*B <= K; B++){
for(ll C = B; A*B*C <= K; C++){
if(A != B && B != C && C != A){
ans1 ++;
}else if(A == B && B == C){
ans3 ++;
}else{
ans2 ++;
}
}
}
}
ll ans = ans1 * 2 * 3 + ans2 * 3 + ans3;
cout << ans << endl;
return 0;
}
| //clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;
//Dont keep array name as size or any other key word
//Incase of close mle change language to c++17 or c++14
/**#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops”)**/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10);
#define pb push_back
#define mod 1000000007ll //998244353ll
#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 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 print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";}
typedef std::numeric_limits< double > dbl;
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set
const long long N=200005, INF=2000000000000000000;
lld pi=3.1415926535897932;
int lcm(int a, int b)
{
int g=__gcd(a, b);
return a/g*b;
}
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;
}
int32_t main()
{
IOS;
int k, ans=0;
cin>>k;
for(int i=1;i<=k;i++)
{
for(int j=1;i*j<=k;j++)
{
for(int z=1;i*j*z<=k;z++)
ans++;
}
}
cout<<ans;
} |
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define pii pair<int,int>
#define vpl vector<pair<ll,ll>>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define ff first
#define ss second
#define poss(flag) cout << (flag ? "YES\n" : "NO\n")
#define rep(i,j,k) for(ll i=j;i<=k;i++)
#define repr(i,j,k) for(ll i=j;i>=k;i--)
#define ii insert
using namespace std;
int pow(int x, unsigned int y, int p){
int res=1;
x=x%p;
if (x==0) return 0;
while (y > 0)
{
if (y & 1)
res = (res*x) % p;
y = y>>1;
x = (x*x) % p;
}
return res;
}
int _pow(int a, int b){
if(!b)
return 1;
int temp = _pow(a, b / 2);
temp = (temp * temp);
if(b % 2)
return (a * temp);
return temp;
}
int invmod(int a,int m){
return pow(a,m-2,m);
}
int cl(int a,int x){
if(a%x==0)
return a/x;
else
return a/x+1;
}
void yes(){
cout<<"YES"<<"\n";
}
void no(){
cout<<"NO"<<"\n";
}
set<ll>s;
void SieveOfEratosthenes(int n)
{
bool prime[n + 1];
memset(prime, true, sizeof(prime));
for (int p = 2; p * p <= n; p++)
{
if (prime[p] == true)
{
for (int i = p * p; i <= n; i += p)
prime[i] = false;
}
}
for (int p = 2; p <= n; p++){
if (prime[p]){
s.ii(p);
}
}
}
int main()
{
string s;
cin >> s;
string ans = s.substr(0,s.find('.'));
cout<<ans;
#ifndef ONLINE_JUDGE
cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
#endif
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main(){
string X;
cin >> X;
for(int i=0;i<(int)X.size();i++){
if(X[i]=='.') return 0;
else cout << X[i];
}
} |
#include <bits/stdc++.h>
using namespace std;
#define mp(a, b) make_pair(a, b)
typedef pair<int, int> pii;
const int maxn = 50 + 10;
int n, m, q;
pii a[maxn];
int x[maxn];
int main()
{
scanf("%d%d%d", &n, &m, &q);
for(int i = 1; i <= n; ++i) scanf("%d%d", &a[i].second, &a[i].first);
sort(a + 1, a + n + 1, greater<pii>());
for(int i = 1; i <= m; ++i) scanf("%d", &x[i]);
while(q--)
{
int l, r;
scanf("%d%d", &l, &r);
multiset<int> s;
for(int i = 1; i <= m; ++i)
if(i < l || i > r)
s.insert(x[i]);
int ans = 0;
for(int i = 1; i <= n; ++i)
{
auto it = s.lower_bound(a[i].second);
if(it == s.end()) continue;
ans += a[i].first;
s.erase(it);
}
printf("%d\n", ans);
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll INF = 1e17 + 11;
pair<ll, ll> pll[100];
vector<ll> vpl;
ll dp[100][100];
bool cmp(pair<ll,ll> a, pair<ll,ll> b){
return a.first*b.second < a.second*b.first;
}
ll recur(ll i, ll j, ll n, ll m){
if(i == n or j == m)
return 0;
if(dp[i][j] != -1)
return dp[i][j];
ll ans = 0;
if(pll[i].first <= vpl[j])
ans = max(ans, pll[i].second+recur(i+1,j+1,n,m));
ans = max(ans,max(recur(i+1,j,n,m), recur(i,j+1,n,m)));
return dp[i][j] = ans;
}
void init(){
for(ll i=0; i<100; i++)
for(ll j=0; j<100; j++)
dp[i][j] = -1;
}
int main(){
cin.sync_with_stdio(false);
cin.tie(0);
ll n, m, q;
cin >> n >> m >> q;
for(ll i=0; i<n; i++){
cin >> pll[i].first >> pll[i].second;
}
sort(pll, pll+n);
ll A[m];
for(ll i=0; i<m; i++)
cin >> A[i];
while(q--){
init();
ll x, y;
cin >> x >> y;
for(ll i=0; i<x-1; i++)
vpl.emplace_back(A[i]);
for(ll i=y; i<m; i++)
vpl.emplace_back(A[i]);
sort(begin(vpl), end(vpl));
ll ans = recur(0,0,n, vpl.size());
cout << ans << "\n";
vpl.clear();
}
return 0;
} |
#include <bits/stdc++.h>
const int N = 200010;
int T, n;
char a[N], b[N], c[N];
void solve() {
scanf("%d", &n);
scanf("%s%s%s", a + 1, b + 1, c + 1);
int t = (a[2 * n] - '0') + (b[2 * n] - '0') + (c[2 * n] - '0');
if (t == 0 || t == 3) {
if (!t) {
for (int i = 1; i <= 2 * n; i ++) std::cout << '1';
std::cout << "0\n";
}
else {
for (int i = 1; i <= 2 * n; i ++) std::cout << '0';
std::cout << "1\n";
}
}
else if (t == 1) {
for (int i = 1; i <= n; i ++) std::cout << '0';
for (int i = 1; i <= n; i ++) std::cout << '1';
std::cout << "0\n";
}
else {
for (int i = 1; i <= n; i ++) std::cout << '1';
for (int i = 1; i <= n; i ++) std::cout << '0';
std::cout << "1\n";
}
}
int main() {
scanf("%d", &T);
while (T --) solve();
return 0;
} | #include <bits/stdc++.h>
using namespace std;
//#define ONLINE_JUDGE
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define rep(z, x, y) for(int z=x;z<=y;++z)
#define repe(z, x, y) for(int z=x;z<y;++z)
#define repd(z, x, y) for(int z=x;z>=y;--z)
#define repde(z, x, y) for(int z=x;z>y;--z)
#define int long long
typedef long long ll;
typedef pair<int, int> PII;
const int INF = 0x3f3f3f3f;
const double eps = 1e-9;
const int mod = 1e9 + 7;
void solve()
{
int n, x;
cin >> n >> x;
rep(i, 1, n)
{
int tmp;
cin >> tmp;
if(tmp != x)
cout << tmp << ' ';
}
cout << endl;
}
signed main()
{
#ifndef ONLINE_JUDGE
freopen("IO/in.txt", "r", stdin);
freopen("IO/out.txt", "w", stdout);
#endif
IOS;
int t;
solve();
} |
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
string n;
int k;
cin >> n >> k;
for (int i = 0; i < k; i++) {
vector<int> g1, g2;
int keta = n.size();
for (int j = 0; j < keta; j++) {
g1.push_back(n[j] - '0');
g2.push_back(n[j] - '0');
}
sort(g1.begin(), g1.end(), greater<int>());
sort(g2.begin(), g2.end());
//g1, g2を数字に変換
long long num_g1 = 0, num_g2 = 0;
long long f;
for (int j = 0; j < keta; j++) {
num_g1 += g1[j] * pow(10, keta - j - 1);
num_g2 += g2[j] * pow(10, keta - j - 1);
}
f = num_g1 - num_g2;
/*
cout << "n[" << i << "] = " << n << endl;
cout << "g1[" << i << "] = " << num_g1;
cout << " g2[" << i << "] = " << num_g2 << endl;
cout << "f[" << i << "] = " << f << endl;
*/
n = to_string(f);
}
cout << n << endl;
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int long long
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define mii map<int,int>
#define pqb priority_queue<int>
#define pqs priority_queue<int,vi,greater<int> >
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x,y) cout<<setprecision(y)<<x
#define mk(arr,n,type) type *arr=new type[n];
#define w(x) int x; cin>>x; while(x--)
#define pw(b,p) pow(b,p) + 0.1
#define endl "\n"
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void __print(int32_t x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
char myHeap[200 * 1024 * 1024];
int sz = 0;
void assert_tle(bool q) { while (!q); }
void* operator new ( std::size_t count ) {
sz += count;
assert_tle(sz <= 200 * 1024 * 1024);
return myHeap + sz - count;
}
void operator delete (void *ptr) { }
void fastIO()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
void solve()
{
int n,k;
cin>>n>>k;
while(k--)
{
string g1=to_string(n);
string g2=to_string(n);
sort(g1.begin(),g1.end(),greater<int>());
sort(g2.begin(),g2.end());
n=stoi(g1)-stoi(g2);
}
cout<<n;
}
int32_t main()
{
fastIO();
//w(t)
{
solve();
cout<<endl;
}
return 0;
} |
/*
Author : Nishant Gupta 2.0
*/
#include<bits/stdc++.h>
using namespace std;
#define LL long long int
#define getcx getchar_unlocked
#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define MAX 100005
#define LOG_MAX 20
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL (LL(1e18))
#define chk(a) cerr << endl << #a << " : " << a << endl
#define chk2(a,b) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << endl
#define chk3(a,b,c) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << endl
#define chk4(a,b,c,d) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << "\t" << #d << " : " << d << endl
#define rep(i, a, n) for(i=a;i<n;i++)
#define rev(i, a, n) for(i=a;i>=n;i--)
#define in(x) scanf("%d", &x)
#define inl(x) scanf("%lld", &x)
#define in2(x, y) scanf("%d %d", &x, &y)
#define inl2(x, y) scanf("%lld %lld", &x, &y)
#define MSV(A,a) memset(A, a, sizeof(A))
#define rep_itr(itr, c) for(itr = (c).begin(); itr != (c).end(); itr++)
#define finish(x) {cout<<x<<'\n'; return;}
typedef pair<int, int> pi;
typedef pair<LL, LL> pl;
const char en = '\n';
void solve() {
string s;
cin>>s;
int cnt = 0;
for(int i=9999;i>=0;i--) {
string snum = to_string(i);
int pad_len = 4 - snum.length();
if(pad_len > 0) {
string pad = string(pad_len, '0');
snum = pad + snum;
}
//~chk(snum);
bool possible = true;
int f[10] = {0};
for(int j=0;j<snum.length();j++) {
f[snum[j]-'0']++;
}
for(int j=0;j<s.length();j++) {
if(s[j] == 'o' && f[j] == 0) {possible = false; break;}
if(s[j] == 'x' && f[j] > 0) {possible = false; break;}
}
if(possible) cnt++;
}
cout<<cnt<<en;
}
int main() {
int t = 1;
//~cin>>t;
while(t--) {
solve();
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define int long long
#define boost \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
#define testcases \
int t; \
cin >> t; \
while (t--)
#define rep(i, j, k) for (int i = j; i <= k; i++)
#define pb push_back
#define pf push_front
#define mp make_pair
#define pi 3.14159265358979323846
#define mod 1000000007
int32_t main()
{
boost;
string s;
cin >> s;
set<int> x_count, o_count, q_count;
for (int i = 0; i < s.size(); i++)
{
if (s[i] == '?')
q_count.insert(i);
else if (s[i] == 'o')
o_count.insert(i);
else
x_count.insert(i);
}
string pin = "....";
int ans = 0;
for (int i = 0; i <= 9; i++)
{
for (int j = 0; j <= 9; j++)
{
for (int k = 0; k <= 9; k++)
{
for (int l = 0; l <= 9; l++)
{
set<int> vals;
bool flag = false;
pin[0] = '0' + i;
pin[1] = '0' + j;
pin[2] = '0' + k;
pin[3] = '0' + l;
for (int u = 0; u < 4; u++)
{
vals.insert(pin[u] - '0');
}
for (auto u : vals)
{
if (o_count.find(u) == o_count.end() && q_count.find(u) == q_count.end())
{
flag = true;
break;
}
}
for (auto u : o_count)
{
if (vals.find(u) == vals.end())
{
flag = true;
break;
}
}
if (flag == false)
ans++;
}
}
}
}
cout << ans;
} |
#include<iostream>
#include<vector>
#include<iomanip>
#include<set>
#include<algorithm>
#include<unordered_map>
#define ll long long
#define io {ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
#define rt int t;cin>>t;while(t--)
#define r1 int t=1;while(t--)
#define mp make_pair
#define endl '\n'
using namespace std;
unordered_map<int,int>m[200010];
int f[200010];
int find(int x) {
return x==f[x]?x:f[x]=find(f[x]);
}
void merge(int a,int b) {
int lx=find(a);
int rx=find(b);
if(lx!=rx) {
if(m[lx].size()>m[rx].size()) {
f[rx]=lx;
for(auto i:m[rx]) {
m[lx][i.first]+=i.second;
}
} else {
f[lx]=rx;
for(auto i:m[lx]) {
m[rx][i.first]+=i.second;
}
}
}
}
int main() {
io;
r1 {
int n,q;
cin>>n>>q;
for(int i=1; i<=n; i++) {
int x;
cin>>x;
m[i][x]++;
f[i]=i;
}
while(q--) {
int opt;
cin>>opt;
if(opt==1) {
int a,b;
cin>>a>>b;
merge(a,b);
} else if(opt==2) {
int x,y;
cin>>x>>y;
int k=find(x);
cout<<m[k][y]<<endl;
}
}
}
return 0;
} | #include<bits/stdc++.h>
using namespace std;
int main(){
int n,x,num = 0;cin>>n>>x;
vector<int>vec(n);
for(int i = 0; i < n; i++){
cin >> vec.at(i);
if(vec.at(i) == x){
num++;
}
}
int j = 0;
for(int i = 0; i < n; i++){
if(vec.at(i) != x){
cout << vec.at(i) << " ";
}
}
return 0;
} |
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<list>
#define ll long long
#define str string
#define ld long double
#define vec vector
#define vll vec<ll>
#define vvll vec<vll>
#define vbo vec<bool>
#define vvbo vec<vbo>
#define vin(a) rep(i,0,a.size())cin>>a[i];
#define rep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrep(i,b,a) for(ll i=(b);i>=(a);i--)
#define repset(itr,a) for(auto itr=a.begin();itr!=a.end();itr++)
#define repnck(bit,n,k) for(ll bit=(1ll<<(k))-1;bit<(1ll<<(n));bit=(bit==0?(1ll<<(n)):nec(bit)))
#define bi1(bit,i) ((bit)&1ll<<(i)?true:false)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define kai "\n"
#define prque priority_queue
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define mie min_element
#define mae max_element
#define tos to_string
#define sep setprecision
#define lob lower_bound
#define upb upper_bound
#define bis binary_search
#define nep next_permutation
#define MOD 1000000007ll
#define MAX 2147483647ll
#define MIN 0.0000000001l
#define equal(a,b) (abs((a)-(b))<MIN)
using namespace std;
void solve();
struct ll2{ll x,y;bool operator<(const ll2 &l)const{return x!=l.x?x<l.x:y<l.y;};};
struct ll3{ll x,y,z;bool operator<(const ll3 &l)const{if(x!=l.x)return x<l.x;if(y!=l.y)return y<l.y;return z<l.z;};};
class ufset{
public:
ufset(ll n) {rank.resize(n,0);rep(i,0,n)p.pub(i);}
bool same(ll i,ll j){return find(i)==find(j);}
void unite(ll i,ll j){link(find(i),find(j));}
ll find(ll i){if(i!=p[i])p[i]=find(p[i]);return p[i];}
private:
vll p,rank;
void link(ll i,ll j){if(rank[i]>rank[j])p[j]=i;else{p[i]=j;if(rank[i]==rank[j])rank[j]++;}}
};
class nck{
public:
nck(ll maxn,ll mod=MOD){
NUM=maxn+1;p=mod;
fac.resize(NUM);finv.resize(NUM);inv.resize(NUM);
fac[0]=fac[1]=finv[0]=finv[1]=inv[1]=1;
rep(i,2,NUM){fac[i]=fac[i-1]*i%p;inv[i]=p-inv[p%i]*(p/i)%p;finv[i]=finv[i-1]*inv[i]%p;}
}
ll c(ll n,ll k){return fac[n]*(finv[k]*finv[n-k]%p)%p;}
private:
ll NUM,p;
vll fac,finv,inv;
};
ll gcd(vector<ll> a){rep(i,1,a.size()){ll k=a[i-1]%a[i];while(k!=0){a[i-1]=a[i];a[i]=k;k=a[i-1]%a[i];}}return a.back();}
ll lcm(vector<ll> a){ll n;rep(i,1,a.size()){n=a[i-1]*a[i];ll k=a[i-1]%a[i];while(k!=0){a[i-1]=a[i];a[i]=k;k=a[i-1]%a[i];}n/=a[i];a[i]=n;}return n;}
ll pow2(ll a,ll b,ll p=MOD){if(b==-1)return pow2(a,p-2,p);ll res=1;if(b>0){res=pow2(a,b/2,p);if(b%2==0)res=res*res%p;else res=res*res%p*a%p;}return res;}
ll nec(ll bit){ll x=bit&-bit,y=bit+x;return (((bit&~y)/x)>>1)|y;}
ll bisz(ll bit){ll size=0;while(bit>0){bit/=2;size++;}return size;}
ll ransu(){static unsigned int TX=123456789, TY=362436069, TZ=521288629, TW=88675123;unsigned int tt=(TX^(TX<<11));TX=TY;TY=TZ;TZ=TW;return (TW=(TW^(TW>>19))^(tt^(tt>>8)));}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
cout<<fixed;
solve();
}
void solve(){
ll a,b,c,d;cin>>a>>b>>c>>d;
if(a==c&&b==d){cout<<0<<kai;return;}
if(a+b==c+d||a-b==c-d||abs(a-c)+abs(b-d)<=3){
cout<<1<<kai;return;
}else if((c+d-a-b)%2==0){
cout<<2<<kai;return;
}
rep(i,-3,4)rep(j,-3,4){
if(abs(i)+abs(j)<=3){
if(a+b==c+d+i+j||a-b==c+i-d-j||abs(a-c-i)+abs(b-d-j)<=3){
cout<<2<<kai;return;
}
}
}
cout<<3<<kai;
} | #include<bits/stdc++.h>
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define all(v) v.begin(), v.end()
using ll = long long;
using namespace std;
int ri(){
int n;cin>>n;
return n;
}
int main(){
ll r1=ri(),c1=ri(),r2=ri(),c2=ri();
int ans;
if(r1==r2 && c1==c2) ans=0;
else if(r1+c1==r2+c2 || r1-c1 == r2-c2 || abs(r1-r2)+abs(c1-c2)<=3){
ans=1;
}
else if(abs(r1-r2)+abs(c1-c2)<=6 || (r1+c1)%2==(r2+c2)%2 || abs(c1-c2+r1-r2)<=3
|| abs(c1-c2-r1+r2)<=3){
ans=2;
}
else ans=3;
cout<<ans;
}
|
#include <bits/stdc++.h>
using namespace std;
//#define ll long long
#define int long long
//#define ull unsigned long long
#define PI pair<int,int>
//#define PI pair<ll,int>
const int maxm=2e5+5;
int d[1<<20];
int e[20];//e[i]为点i的边集
int n,m;
signed main(){
ios::sync_with_stdio(0);
cin>>n>>m;
for(int i=0;i<n;i++)e[i]|=(1<<i);
for(int i=1;i<=m;i++){
int a,b;cin>>a>>b;
a--,b--;
e[a]|=(1<<b);
e[b]|=(1<<a);
}
//init
for(int i=0;i<(1<<n);i++){
d[i]=1e9;
}
d[0]=0;
//dp
for(int i=1;i<(1<<n);i++){
//判断集合是否本身是一个完全图
int ok=1;
for(int j=0;j<n;j++){
if(i>>j&1){
if((e[j]&i)!=i){
ok=0;
}
}
}
if(ok)d[i]=1;
//枚举当前集合是从何组合的
for(int j=i;j;j=((j-1)&i)){//枚举子集
d[i]=min(d[i],d[i-j]+d[j]);//d[i]由(i-j)和j组成.
}
}
cout<<d[(1<<n)-1]<<endl;
return 0;
}
/*
n<=18,考虑状压dp:
令d[i]表示点集为i时,满足题目条件的最小连通块数量.
*/
| #include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <ios>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <utility>
using namespace std;
using i64 = int64_t;
using u64 = uint64_t;
using i32 = int32_t;
using pi64 = pair<i64, i64>;
constexpr i64 MAXN = 3*100*1000LL+5LL;
constexpr i64 MOD = 1000000007LL;
constexpr i64 INF64 = MOD * MOD;
#define vec vector
#define let const
#define DRi64(x) i64 x; cin >> x;
#define DRS(x) string x; cin >> x;
#define DRVi64(v, n) vec<i64> v(n); { for (i64 i = 0; i < n; ++i) { cin >> v[i]; }}
#ifdef DEBUG
#define P(x) cerr << x << "\n"
#else
#define P(x)
#endif
int
main()
{
ios_base::sync_with_stdio(false);
const unsigned seed =
chrono::system_clock::now().time_since_epoch().count();
mt19937 gen(seed);
DRi64(N); DRi64(M);
vec<vec<i64>> adj(N);
for (i64 i = 0; i < M; ++i)
{
DRi64(A); DRi64(B);
A--, B--;
adj[A].push_back(B);
adj[B].push_back(A);
}
vec<bool> is_valid(1LL << N, false);
// look at all possible cliques and see whether each one is valid
for (i64 mask = 0; mask < (1LL << N); ++mask)
{
vec<i64> clique;
for (i64 i = 0, mask2 = mask; mask2; ++i, mask2 >>= 1)
{
if (mask2 & 1)
{
clique.push_back(i);
}
}
bool ok = true;
for (let i64 v : clique)
{
for (let i64 v2 : clique)
{
if (v2 == v)
{
continue;
}
ok &= find(adj[v].begin(), adj[v].end(), v2) != adj[v].end();
}
}
is_valid[mask] = ok;
P(mask << ": " << (is_valid[mask] ? "OK" : "bad"));
}
vec<i64> min_clique_counts(1LL << N, MOD);
min_clique_counts[0] = 0;
for (i64 mask = 1; mask < (1LL << N); ++mask)
{
for (i64 submask = mask; submask; submask = (submask - 1) & mask)
{
P("mask: " << mask << " sub: " << submask);
if (is_valid[submask])
{
P("mask & ~submask: " << (mask & ~submask));
min_clique_counts[mask] = min(min_clique_counts[mask], 1 + min_clique_counts[mask & ~submask]);
}
else
{
min_clique_counts[mask] = min(min_clique_counts[mask], min_clique_counts[submask] + min_clique_counts[mask & ~submask]);
}
}
P(bitset<18>(mask) << ": " << min_clique_counts[mask]);
}
cout << min_clique_counts[(1LL << N) - 1] << "\n";
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 INF = 1000000000;
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);
}
int main(){
ios::sync_with_stdio(false);
ll n; cin >> n;
vector<ll> a(n);
FOR(i, 0, n){
cin >> a[i];
if (i % 2 == 1){
a[i] = 0 - a[i];
}
}
vector<ll> A(n+1);
map<ll, ll> mp;
mp[0] = 1;
ll ans = 0;
FOR(i, 1, n+1){
A[i] = A[i-1] + a[i-1];
ans += mp[A[i]];
mp[A[i]]++;
}
cout << ans << '\n';
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
using ll = long long;
int n;
cin >> n;
vector<ll> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
vector<ll> sums(n + 1);
for (int i = 0; i < n; i++) {
if (i % 2 == 0) {
sums[i + 1] = sums[i] + a[i];
} else {
sums[i + 1] = sums[i] - a[i];
}
}
map<ll, ll> mp;
for (int i = 0; i <= n; i++) mp[sums[i]]++;
ll ans = 0;
for (auto m: mp) ans += (m.second - 1) * m.second / 2;
cout << ans << endl;
} |
#include <bits/stdc++.h>
using namespace std;
vector<int> son[100010];
int n, pv, f[100010];
bool g[100010];
bool cmp(pair<int, bool> x, pair<int, bool> y) {
if (x.second == y.second) return x.first < y.first;
if (x.second == 0) return x.first < 0;
return y.first >= 0;
}
void dfs(int rt) {
f[rt] = g[rt] = 1;
if (son[rt].empty()) return;
vector<pair<int, bool>> tmp;
for (int i : son[rt]) {
dfs(i);
tmp.push_back({f[i], g[i]});
g[rt] ^= g[i];
}
sort(tmp.begin(), tmp.end(), cmp);
bool flag = 1;
for (pair<int, int> i : tmp) {
if (flag)
f[rt] += i.first; else
f[rt] -= i.first;
if (i.second) flag = !flag;
}
}
int main() {
scanf("%d", &n);
for (int i = 2; i <= n; ++i) {
scanf("%d", &pv);
son[pv].push_back(i);
}
dfs(1);
printf("%d\n", (n + f[1]) / 2);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 0x3f3f3f3f
#define m(a) memset(a,0,sizeof(a))
const int N=2e5+5;
int n,m;
int f[N],w[N],T;
vector<int>g[N],b[N];
void work(int k){
int z=g[k].size();
int i,er=0;
w[k]=1;
for(int i=0;i<z;i++){
int y=g[k][i];
work(y);
w[k]+=w[y];
if(w[y]%2==0){
if(f[y]>0)f[k]+=f[y];
else er+=f[y];
}
else b[k].push_back(f[y]);
}
f[k]+=er*(w[k]%2*2)-er;
sort(b[k].begin(),b[k].end());
for(int i=0;i<b[k].size();i++){
f[k]+=b[k][i]*(1-(b[k].size()-1-i)%2*2);
}
f[k]--;
}
int main(){
int n;cin>>n;
for(int i=2;i<=n;i++){
int x;cin>>x;
g[x].push_back(i);
}
work(1);
int maxs=0;
for(int i=1;i<=n;i++){
maxs=max(maxs,f[i]);
}
cout<<(n-f[1])/2;
} |
#include <bits/stdc++.h>
using namespace std;
#define ar array
#define ll long long
#define tc(t) int t; cin >> t;while(t--)
#define lp(i, x, y) for(ll i = x; i <= y; i++)
#define lpr(i, x, y) for(ll i = x; i >= y; i--)
#define in1(x) ll x; cin >> x
#define in2(x, y) ll x, y; cin >> x >> y
#define in3(x, y, z) ll x, y, z; cin >> x >> y >> z
#define mem(x, y) memset(x, (y), sizeof(x))
#define ite(it, l) for (auto it = l.begin(); it != l.end(); it++)
const int MAX = 1e5 + 5;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll LINF = 1e18;
int main()
{
// cin.tie(0); cout.tie(0); freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
string a;
cin >> a;
int n = a.size();
lpr(i, n-1, 0)
{
if(a[i] == '6')
cout << "9";
else if(a[i] == '9')
cout << "6";
else
cout << a[i];
}
cout << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef pair<int,int> Pair;
typedef tuple<int,int,int> tpl;
#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)
#define en "\n"
constexpr double EPS = 1e-9;
constexpr double PI = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}
struct SieveEratosthenes{
vector<int> min_fact;
SieveEratosthenes(int N){
_build(N);
}
void _build(int N){
min_fact.resize(N+1);
for(int i=0; i<=N; i++) min_fact[i] = i;
min_fact[0] = min_fact[1] = -1;
for(int i=2; i*i<=N; i++){
for(int j=i*i; j<=N; j+=i){
if(i < min_fact[j])
min_fact[j] = i;
}
}
}
bool is_prime(int x){
return min_fact[x] == x;
}
vector<pair<int,int>> factorize(int x){
vector<pair<int,int>> ret;
while(x>1){
if(ret.empty() || ret.back().first != min_fact[x])
ret.emplace_back(min_fact[x], 1);
else
ret.back().second++;
x /= min_fact[x];
}
return ret;
}
};
void Main(){
ll N; cin >> N;
set<ll> s;
for(ll x=2; x<sqrt(N)+10; x++){
for(ll y=x*x; y<=N; y*=x){
s.insert(y);
}
}
ll ans = N - s.size();
cout << ans << en;
return;
}
int main(void){
cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
int t=1; //cin>>t;
REP(_,t) Main();
return 0;
} |
#include <bits/stdc++.h>
// #include <atcoder/all>
// using namespace atcoder;
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define inrange(a, x, b) (a <= x && x <= b)
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using vc = vector<char>;
using vcvc = vector<vc>;
using pll = pair<ll, ll>;
template<class T> void print(T x,bool cl=1){cout<<(cl?"\x1b[36m":"")<<x<<(cl?"\x1b[39m":"")<<'\n';}
template<class T> void print1d(T x,ll n=-1,bool cl=true){if(n==-1)n=x.size();rep(i,0,n){cout<<(cl?"\x1b[36m":"")<<x[i]<<(i==n-1?'\n':' ');}cout<<(cl?"\x1b[39m":"");}
template<class T> void print2d(T x,ll r=-1,ll c=-1,bool cl=1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c,cl);}
template<class T, class U> bool isin(T el, U container) { return find(all(container), el) != container.end(); }
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T> bool even(T n) { return ! (n & 1); }
template<class T> bool odd(T n) { return n & 1; }
template<class T> ll rup(T a, T b) { return a % b ? a / b + 1 : a / b; }
template<class T> ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T> ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;
ll intpow(ll a, ll n, ll _mod=numeric_limits<ll>::max()) { ll p=1; while (n) { if (n&1) p=p*a%_mod; a=a*a%_mod; n>>=1; } return p; }
ll modc(ll a, char op, ll b, ll _mod=mod)
{
a %= _mod; b %= _mod; ll res = 1;
switch (op) {
case '+': res = (a + b) % _mod; break;
case '-': res = (a - b) % _mod; break;
case '*': res = a * b % _mod; break;
case '/': res = modc(a, '*', modc(b, '^', _mod-2, _mod), _mod); break;
case '^': res = intpow(a, b, _mod); break;
case 'P': rep(i, a-b+1, a+1) res = modc(res, '*', i, _mod); break;
case 'C': res = modc(modc(a, 'P', b, _mod), '/', modc(b, 'P', b, _mod)); break;
}
if (res < 0) { res += _mod; } return res;
}
int main()
{
ll N, A, B;
cin >> N >> A >> B;
N -= A;
N += B;
cout << N << endl;
}
| #include <bits/stdc++.h>
#define PB push_back
#define ST first
#define ND second
#define _ ios_base::sync_with_stdio(0); cin.tie(0);
//mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
using namespace std;
using ll = long long;
using pi = pair<int,int>;
using vi = vector<int>;
int n,a,b;
int main() {_
cin >> n >> a >> b;
cout << n - a + b;
}
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll K,n,m,a[100005],b[100005],sl[100005],sr[100005];
bool Check(ll mid){
for(int i=1;i<=K;i++){
ll l=a[i]-mid,r=a[i]+mid;
//cout<<i<<' '<<a[i]+mid<<' '<<r<<' '<<'\n';
l=(l+n-1)/n,r=r/n;
//cout<<i<<' '<<a[i]+mid<<' '<<r<<' '<<'\n';
l=max(l,0ll),r=min(r,m);
//cout<<i<<' '<<a[i]+mid<<' '<<r<<' '<<'\n';
if(l>r)return 0;
sl[i]=sl[i-1]+l,sr[i]=sr[i-1]+r;
//cout<<i<<' '<<a[i]+mid<<' '<<n<<' '<<sl[i]<<' '<<sr[i]<<'\n';
}
if(sl[K]>m||sr[K]<m)return 0;
ll tm=m;
for(int i=1;i<=K;i++){
ll tl=sl[K]-sl[i],tr=sr[K]-sr[i];
ll l=a[i]-mid,r=a[i]+mid;
l=(l+n-1)/n,r=r/n;
l=max(l,0ll),r=min(r,tm);
b[i]=min(r,tm-tl);
tm-=b[i];
}
return 1;
}
int main(){
cin>>K>>n>>m;
for(int i=1;i<=K;i++)cin>>a[i],a[i]*=m;
//cout<<Check(70)<<'\n';
//cout<<Check(34)<<'\n';
//return 0;
ll l=0,r=n*m,ans=0;
while(l<=r){
ll mid=(l+r)/2;
if(Check(mid))ans=mid,r=mid-1;
else l=mid+1;
//cout<<l<<' '<<r<<' '<<mid<<' '<<ans<<'\n';
}
Check(ans);
for(int i=1;i<=K;i++)cout<<b[i]<<' ';
}
| #include <bits/stdc++.h>
int main(){
int K, N, M;
std::cin >> K >> N >> M;
std::vector< long long > A(K);
for(int i=0; i<K; i++){
std::cin >> A[i];
}
std::vector< long long > B(K);
std::vector< std::pair< long long, long long > > B_zan_i(K);
long long total = 0;
for(int i=0; i<K; i++){
B[i] = A[i] * M / N;
total += B[i];
B_zan_i[i].first = (A[i] * M) % N;
B_zan_i[i].second = i;
}
std::sort(B_zan_i.begin(), B_zan_i.end());
for(int i=0; i<M-total; i++){
B[B_zan_i[K - i - 1].second]++;
}
for(int i=0; i<K; i++){
if(i == K-1){
std::cout << B[i] << std::endl;
}else{
std::cout << B[i] << " ";
}
}
return 0;
}
|
#include <iostream>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
using namespace std;
const int INF = 1 * (1 << 30);
const int mINF = -1 * (1 << 30);
int main()
{
double n;
cin >> n;
n *= 1.08;
int tmp = (int)n;
if (tmp < 206)
{
cout << "Yay!" << endl;
}
else if (tmp == 206)
{
cout << "so-so" << endl;
}
else
{
cout << ":(" << endl;
}
return 0;
}
| # define _GLIBCXX_DEBUG
# define rep(i, n) for (int i=0; i<(int)(n); i++)
# define FOR(i,a,b) for(int i=(a);i<=(b);++i)
# define ALL(a) (a).begin(), (a).end()
# define COUT(x) cout << (x) << endl;
# define KAI() cout << endl;
# define INF 10000000000000000LL
typedef long long ll;
# include <iostream>
# include <string>
# include <cmath>
# include <algorithm>
# include <vector>
# include <set>
# include <bitset>
using namespace std;
int main() {
int n;
cin >> n;
double ans;
ans = floor(1.08*n);
// int ans=0;
if (ans < 206) COUT("Yay!")
else if (ans == 206) COUT("so-so")
else COUT(":(")
}
|
#pragma region Macros
#include <bits/stdc++.h>
#if defined(LOCAL) || defined(ONLINE_JUDGE) || defined(_DEBUG)
#include <atcoder/all>
#endif
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define EACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
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<class T>using vec = vector<T>;
template<class T, class U>using umap = unordered_map<T, U>;
template<class T>using uset = unordered_set<T>;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vl = vec<ll>;
#define fi first
#define se second
#define el endl
constexpr ll INF = numeric_limits<ll>::max()/2-1;
#pragma endregion
#pragma region IOMacros
template<class T>
istream &operator>>(istream &stream, vec<T>& o){REP(i, o.size())stream >> o[i];return stream;}
template<class T>
ostream &operator<<(ostream &stream, vec<T>& objs){REP(i, objs.size())stream << objs[i] << " ";stream << el;return stream;}
#define I(T, ...) ;T __VA_ARGS__;__i(__VA_ARGS__);
void __i() {}
template<class T, class... Ts> void __i(T&& o, Ts&&... args){cin >> o;__i(forward<Ts>(args)...);}
void O() {cout << el;}
template<class T, class... Ts> void O(T&& o, Ts&&... args){cerr << o << " ";O(forward<Ts>(args)...);}
#pragma endregion
void Main();
int main(){
std::cin.tie(nullptr);
std::cout << std::fixed << std::setprecision(15);
Main();
return 0;
}
void Main(){
I(ll, T);
REP(i, T){
I(ll, A);
if(A&1){
cout << "Odd" << el;continue;
}
A/=2;
if(A&1){
cout << "Same" << el;
}else{
cout << "Even" << el;
}
}
} | #include<bits/stdc++.h>
using namespace std;
int main() {
int T;
cin >> T;
while (T--) {
long long N;
cin >> N;
if(N%4 == 2) {
cout << "Same" << endl;
}
else if(N%4 == 0) {
cout << "Even" << endl;
}
else {
cout << "Odd" << endl;
}
}
}
|
//Problem link :
//done by sanath kumar
#include<bits/stdc++.h>
#include <cstdlib>
using namespace std;
#define ll long long int
#define ld long double
#define mod 1000000007
#define inf 1e9
#define endl "\n"
#define pb push_back
#define vi vector<ll>
#define vs vector<string>
#define pii pair<ll,ll>
#define ump unordered_map
#define mp make_pair
#define pq_max priority_queue<ll>
#define pq_min priority_queue<ll,vector<ll>,greater<ll>>
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define mid(l,r) (l+(r-l))/2
#define bitc(x) __builtin_popcount(x)
#define loop(i,a,b) for(int i=(a);i<=(b);i++)
#define looprev(i,a,b) for(int i=(a);i>=(b);i--)
#define iter(c,it) for(__typeof(c.begin()) it=c.begin();it!=c.end();it++)
#define log(args...) {string _s=#args;replace(_s.begin(),_s.end(),',',' ');stringstream _ss(_s);istream_iterator<string> _it(_ss);err(_it,args);}
#define logarr(arr,a,b) for(int z=(a);z<=(b);z++) cout<<(arr[z])<<" ";cout<<endl;
template<typename T> T gcd(T a,T b) {if(b==0) return a; return gcd(b,a%b);}
template<typename T> T lcm(T a,T b) {return a*(b/gcd(a,b));}
void err(istream_iterator<string> it){}
template<typename T,typename... Args>
void err(istream_iterator<string> it,T a,Args... args){
cout<<*it<<" = "<<a<<endl;
err(++it,args...);
}
void file_i_o(){
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
}
ll *getfactorial(){
int m=1e6;
ll *fact=new ll[m+1];
fact[0]=1;
loop(i,1,m){
fact[i]=(fact[i-1]*i)%mod;
}
// time complexity O(n)
return fact;
}
vi *getfactors(){
int n=2e5;
vi *factors=new vi[n+5];
loop(i,1,n){
for(int j=i;j<=n;j+=i){
factors[j].pb(i);
}
}
// time complexity O(nlogn)
return factors;
}
ll power(ll a,ll b,ll m=mod){
if(b==0) return 1;
ll smallans=power(a,b/2,m);
ll ans=(smallans*smallans)%m;
if(b%2==1){
ans=(ans*a)%m;
}
return ans;
// time complexity O(logb)
}
bool *isprime(){
int m=1e6;
bool *p=new bool[m];
loop(i,0,m) p[i]=true;
p[0]=false;
p[1]=false;
loop(i,2,sqrt(m)){
for(int j=2*i;j<=m;j+=i){
p[j]=false;
}
}
// time complexity O(nloglogn)
return p;
}
ll nCr(ll n,ll r,int m=mod){
if(n<r) return 0;
ll dp[2][r+5];
memset(dp,0,sizeof(dp));
int i=1;
loop(k,0,n) dp[k][0]=1;
loop(k,1,n){
loop(j,1,r){
dp[i][j]=dp[i^1][j]+dp[i^1][j-1];
}
i=i^1;
}
// time complexity O(n*r) ,in worst case O(n^2)
return dp[i^1][r];
}
//==================START==================
vi val[3];
ll twopoi(int x,int y){
ll i=0,j=0,ans=1e15;
while(i<val[x].size() and j<val[y].size()){
ll p=val[y][j]-val[x][i];
if(ans>abs(p)) ans=abs(p);
if(p==0) break;
if(p>0) i++;
else j++;
}
return ans;
}
int main(){
file_i_o();
clock_t begin=clock();
int n;
cin>>n;
loop(i,1,2*n){
ll x;
char c;
cin>>x>>c;
if(c=='R') val[0].pb(x);
else if(c=='G') val[1].pb(x);
else if(c=='B') val[2].pb(x);
}
loop(i,0,2){
if(val[i].size()!=0) sort(all(val[i]));
}
int r=val[0].size();
int g=val[1].size();
int b=val[2].size();
if(r%2==0 and b%2==0 and g%2==0) cout<<0<<endl;
else{
ll ans=-1;
if(r%2==0){
ans=twopoi(1,2);
if(val[0].size()!=0) ans=min(ans,twopoi(0,1)+twopoi(0,2));
}
else if(g%2==0){
ans=twopoi(0,2);
if(val[1].size()!=0) ans=min(ans,twopoi(1,0)+twopoi(1,2));
}
else{
ans=twopoi(0,1);
if(val[2].size()!=0) ans=min(ans,twopoi(2,1)+twopoi(0,2));
}
cout<<ans<<endl;
}
#ifndef ONLINE_JUDGE
clock_t end=clock();
cout<<"\n\n\nExecuted in :"<<double(end-begin)/CLOCKS_PER_SEC*1000<<" ms"<<endl;
#endif
} | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define ll long long
#define F(type, i, a, b, incr) for (type i = a; i <= (type)(b); i += (type)(incr))
#define RF(type, i, a, b, decr) for (type i = a; i >= (type)(b); i -= (type)(decr))
#define sz(a) sizeof(a)
#define deb(a) cerr << " [" << #a << "->" << a << "] "
#define next_line cerr << '\n'
#define all(a) a.begin(), a.end()
#define iter(it, s) for (auto it = s.begin(); it != s.end(); it++)
#define setbits(x) __builtin_popcountll(x)
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
int INF = 1e18;
int Get(char color){
if(color == 'R')
return 0;
if(color == 'G')
return 1;
return 2;
}
void solve()
{
int n;
cin >> n;
n *= 2LL;
// R, G, B
vector<vector<int> > dogs(3);
F(int, i, 0, n - 1, 1){
int a;
char c;
cin >> a >> c;
dogs[Get(c)].push_back(a);
}
F(int, i, 0, 2, 1){
dogs[i].push_back(-INF);
dogs[i].push_back(INF);
sort(all(dogs[i]));
}
sort(all(dogs), [](vector<int> &a, vector<int> &b){
return ((int)(a.size()) & 1) < ((int)(b.size()) & 1);
});
// 1->even
if((((int)(dogs[1].size()) & 1)) == 0){
cout << "0\n";
return;
}
int min_1_2 = INF;
vector<pii> min_0_1;
vector<pii> min_0_2;
for(int v: dogs[1]){
if((v == (-INF)) || (v == (INF)))
continue;
auto p1 = lower_bound(all(dogs[2]), v);
auto p2 = upper_bound(all(dogs[2]), v);
p2 --;
min_1_2 = min({min_1_2, (*p1) - v, v - (*p2)});
}
// deb(min_1_2);
int z_s = dogs[0].size();
F(int, i, 0, z_s - 1, 1){
int v = dogs[0][i];
if((v == (-INF)) || (v == (INF)))
continue;
auto p1 = lower_bound(all(dogs[1]), v);
auto p2 = upper_bound(all(dogs[1]), v);
p2 --;
min_0_1.push_back(pii(min((*p1) - v, v - (*p2)), i));
auto p3 = lower_bound(all(dogs[2]), v);
auto p4 = upper_bound(all(dogs[2]), v);
p4 --;
min_0_2.push_back(pii(min((*p3) - v, v - (*p4)), i));
}
int oth_poss = INF;
if(!min_0_1.empty()){
sort(all(min_0_1));
sort(all(min_0_2));
if(min_0_1[0].second == min_0_2[0].second){
oth_poss = min(oth_poss, min_0_1[0].first + min_0_2[1].first);
oth_poss = min(oth_poss, min_0_2[0].first + min_0_1[1].first);
}else{
oth_poss = min(oth_poss, min_0_1[0].first + min_0_2[0].first);
}
}
// deb(oth_poss);
int ans = min(min_1_2, oth_poss);
cout << ans << '\n';
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// freopen("Debug.txt", "w", stderr);
#else
#endif
// cout << fixed << setprecision(10);
int _t = 1;
// cin>>_t;
F(int, i, 1, _t, 1){
// cout << "Case #" << i << ": ";
solve();
}
}
|
#include <iostream>
#include <string>
using namespace std;
int main() {
string c;
cin >> c;
cout << (c[0] == c[1] && c[1] == c[2] ? "Won" : "Lost") << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
unsigned long N,M,a,b,answer;
int count = 1;
answer = 0;
cin >> N;
M = N;
while (M>9){
M = M / 10;
count++;
}
if (count % 2 != 0)
{
if (count == 1){
cout << 0 << endl;
return (0);}
if (count == 3){
cout << 9 << endl;
return (0);}
if (count == 5){
cout << 99 << endl;
return (0);}
if (count == 7){
cout << 999 << endl;
return (0);}
if (count == 9){
cout << 9999 << endl;
return (0);}
if (count == 11){
cout << 99999 << endl;
return (0);}
}
int x = pow(10, count/2);
a = N / x;
b = N % x;
if (a > b)
answer = a-1;
else
answer = a;
cout << answer << endl;
return (0);
} |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0 ; i < n ; i++)
#define rep1(i,n) for(int i = 1 ; i < n ; i++)
#define rrep(i,n) for(int i = n - 1 ; i >= 0 ; i--)
#define rrep1(i,n) for(int i = n ; i > 0 ; i--)
#define INF 1001001001
#define MOD 1000000007
using ll = int64_t;
using P = pair<int, int>;
int main(){
int n, m, k;
cin >> n >> m;
vector<int> a(m,0);
vector<int> b(m,0);
rep(i,m)cin >> a[i] >> b[i];
cin >> k;
vector<int> c(k,0);
vector<int> d(k,0);
rep(i,k)cin >> c[i] >> d[i];
int ans = -INF;
rep(bit, 1<<k){//O(2^k)
set<int> field;
rep(i,k){//O(k)
if(bit>>i&1)field.insert(c[i]);
else field.insert(d[i]);
}
int ten_ans = 0;
rep(i, m){
if(field.count(a[i]) && field.count(b[i]))ten_ans++;
}
ans = max(ans, ten_ans);
}
cout << ans << endl;
} | #include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <bitset>
#include <vector>
#include <stack>
#include <queue>
#include <unordered_map>
using namespace std;
const int N = 1e5 + 100;
int main() {
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif
int n, l;
cin >> n >> l;
vector<int> a(N), b(N);
a[n + 1] = b[n + 1] = l + 1;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
for (int i = 1; i <= n; ++i) {
cin >> b[i];
}
n = n + 2;
for (int i = 0; i < n; ++i) {
a[i] -= i;
b[i] -= i;
}
unordered_map<int, pair<int, int>> mp1, mp2;
for (int i = 0; i < n; ++i) {
if (mp1.count(a[i]) == 0) {
mp1[a[i]] = make_pair(i, i);
} else {
mp1[a[i]].second = i;
}
}
for (int i = 0; i < n; ++i) {
if (mp1.count(b[i]) == 0) {
cout << -1 << endl;
return 0;
}
if (mp2.count(b[i]) == 0) {
mp2[b[i]] = make_pair(i, i);
} else {
mp2[b[i]].second = i;
}
}
long long ans = 0;
for (auto it : mp2) {
auto A = mp1[it.first];
auto B = mp2[it.first];
ans += max(0, A.first - B.first) + max(0, B.second - A.second);
}
cout << ans << endl;
} |
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using pi = pair<int, int>;
using vpi = vector<pair<int, int>>;
#define all(v) (v).begin(), (v).end()
#define ar array
#define PB push_back
#define sz(x) (int)(x).size()
template <typename T>
using pqg = priority_queue<T, vector<T>, greater<T>>;
template <typename A, typename B>
ostream &operator<<(ostream &os, const pair<A, B> &p)
{
return os << '(' << p.first << ", " << p.second << ')';
}
template <typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type>
ostream &operator<<(ostream &os, const T_container &v)
{
os << '{';
string sep;
for (const T &x : v)
os << sep << x, sep = ", ";
return os << '}';
}
void dbg_out()
{
cerr << endl;
}
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T)
{
cerr << ' ' << H;
dbg_out(T...);
}
#ifdef LOCAL
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif
struct custom_hash
{
static uint64_t splitmix64(uint64_t x)
{
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const
{
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9 + 7; //998244353
void solve()
{
int n;
cin >> n;
vector<ll> v(n+1);
for (int i=1;i<=n;i++)cin >> v[i];
if (n==1){
cout << v[1]<<"\n";
return;
}
vector<ll> f(n+1);
f[0] = 1;
for (int i=1;i<=n;i++){
if (i==1) f[i] = 2;
else if (i==2) f[i] = 3;
else f[i] = (f[i-1] + f[i-2])%MOD;
}
dbg(f[n], v[1]);
ll ans = f[n-1]*v[1]%MOD;
for (int i=2;i<=n;i++){
ll curadd = 0, cursub = 0;
curadd = f[n-i]*f[i-2]%MOD;
if (n-i-1>=0&&i-3>=0) cursub = f[n-i-1]*f[i-3]%MOD;
else if (n-i-1>=0) cursub = f[n-i-1]%MOD;
else if (i-3>=0) cursub = f[i-3]%MOD;
else cursub = 1;
ans += (curadd-cursub+MOD)*v[i]%MOD;
ans%=MOD;
}
cout << (ans+MOD)%MOD << "\n";
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int testcase=1;
//cin >> testcase;
while (testcase--)
{
solve();
}
} | // FIRST THINK THEN CODE.
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long
#define ld long double
#define pll pair<ll,ll>
#define cld complex<ld>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vld vector<ld>
#define vvld vector<vector<ld>>
#define vpll vector<pll>
#define vcld vector<cld>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define eb emplace_back
#define PI acos(-1)
#define endl "\n"
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define rev(p) reverse(p.begin(),p.end());
#define mset(a,val) memset(a,val,sizeof(a));
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define popcount(x) __builtin_popcountll(x)
#define sz(x) ((ll)x.size())
#define FOR(i,a,b) for(ll i=a;i<=b;i++)
#define FORR(i,a,b) for(ll i=a;i>=b;i--)
const ll M = 1000000007;
const ll MM = 998244353;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ordered_set tree<pll, null_type,less<>, rb_tree_tag,tree_order_statistics_node_update>
ll begtime = clock();
#define end_routine() cerr << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
template<typename T, typename F>
void chmax( T &a, F b) {
if (b > a)a = b;
}
template<typename T, typename F>
void chmin( T &a, F b) {
if (b < a)a = b;
}
const ll N = 2e5 + 5;
void OJ() {
#ifndef ONLINE_JUDGE
freopen("input1.txt", "r", stdin);
freopen("output1.txt", "w", stdout);
#endif
}
int main() {
IOS;
OJ();
ll n; cin >> n;
map<ll, ll>dp;
dp[-1] = dp[0] = 1;
for (ll i = 1; i <= n; i++) {
dp[i] = (dp[i - 1] + dp[i - 2]) % M;
}
ll ans = 0;
for (ll i = 1; i <= n; i++) {
ll x; cin >> x;
ll temp = (dp[n - i] * dp[i - 2] - dp[n - i - 1] * dp[i - 3]) % M;
if (temp < 0)temp += M;
ans = (ans + temp * x) % M;
}
if(ans<0)ans+=M;
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define isPossible(x) printf("%s\n",(x) ? "Possible" : "Impossible")
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
// #define INF (1<<9+9)
const int INF = 0x3fffffff;
// const long long INF = 1LL<<50;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define pie 3.14159265358979323846
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}
const int MOD =(int)998244353;
// const int mod =(int)998244353;
const int mod =(int)1e9+7;
const int MAX =510000;
ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
fac[0]=fac[1]=1;
finv[0]=finv[1]=1;
inv[1]=1;
for(int i=2;i<MAX;i++){
fac[i]=fac[i-1]*i%MOD;
inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
finv[i]=finv[i-1]*inv[i]%MOD;
}
}
ll COM(int n,int k){
if(n<k) return 0;
if(n<0||k<0)return 0;
return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
ll gcd(ll a,ll b){
if(a<0)a=-a;
if(b<0)b=-b;
if(b==0)return a;
if(a>b){
swap(a,b);
}
return gcd(a,b%a);
}
ll lcm(ll a,ll b){
if(a<0)a=-a;
if(b<0)b=-b;
ll g;g=gcd(a,b);
return b/g*a;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
if(a.second != b.second){
return a.second < b.second;
}else{
return a.first < b.first;
}
}
bool compare_by_a(pair<int, int> a, pair<int, int> b) {
if(a.first != b.first){
return a.first < b.first;
}else{
return a.second < b.second;
}
}
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
//int N, M, K, T, H, W, L, R;
// long long int N, M, K, T, H, W, L, R
ll RS(ll N,ll P){
if(P==0){
return 1;
}else{
if(P%2==0){
ll t=RS(N,P/2);
return t*t;
}else{
return N*RS(N,P-1);
}
}
}
int main() {
ios::sync_with_stdio(false);
int a,b,c,d;
cin>>a>>b>>c>>d;
cout<<b-c<<endl;
return 0;
}
| #include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <map>
#include <cmath>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;
#define rep(i, o) for (int i = 0; i < (o); ++i)
#define REP(i, a, b) for (int i = (int)(a); (i) < (int)(b); i++)
#define NUM 1e5
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }
int main()
{
int a, b, c;
cin >> a >> b >> c;
int ans = 0;
if (a == b) ans = c;
if (b == c) ans = a;
if (a == c) ans = b;
cout << ans << endl;
return 0;
} |
#include<stdio.h>
#include<stdlib.h>
int search(long *arr, int left,int right, long num){
int mid = (left+right)/2;
if(left == right){
return left;
}
if(arr[mid] == num){
return mid;
}else if(num < arr[mid]){
return search(arr,left,mid,num);
}else{
return search(arr,mid+1,right,num);
}
}
int main(){
int n,q,i,j;
long *a,k,*sum;
scanf("%d %d",&n,&q);
a = (long*)malloc(sizeof(long)*n);
sum = (long*)malloc(sizeof(long)*n);
for(i=0;i<n;i++){
scanf("%ld",a+i);
sum[i] = a[i]-i-1;
}
for(i=0;i<q;i++){
scanf("%ld",&k);
j = search(sum,0,n-1,k);
if(j == 0){
printf("%ld\n",k);
}else if(j == n-1 && sum[n-1] < k){
printf("%ld\n",a[n-1]+k-sum[n-1]);
}else{
while(j > 0 && sum[j] == sum[j-1]) j--;
printf("%ld\n",a[j-1]+k-sum[j-1]);
}
}
return 0;
}
| #include <set>
#include <iostream>
using namespace std;
#define int long long
const int N = 2e5 + 10;
int par[N], c[N];
set<pair<int, int>> s[N];
void make_set(int x) {
par[x] = x;
s[x].insert({c[x], 1});
}
int find_set(int x) {
if (x == par[x]) {
return x;
}
return par[x] = find_set(par[x]);
}
void union_sets(int x, int y) {
x = find_set(x);
y = find_set(y);
if (x != y) {
if (s[x].size() > s[y].size()) {
swap(x, y);
}
par[x] = y;
for (auto z : s[x]) {
auto it = s[y].lower_bound({z.first, -1});
int cur = z.second;
if (!(it == s[y].end() || it->first != z.first)) {
cur += it->second;
s[y].erase(it);
}
s[y].insert({z.first, cur});
}
}
}
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, q;
cin >> n >> q;
for (int i = 1; i <= n; ++i) {
cin >> c[i];
make_set(i);
}
while (q--) {
int x, y, z;
cin >> x >> y >> z;
if (x - 1) {
int w = find_set(y);
auto it = s[w].lower_bound({z, -1});
if (it == s[w].end() || it->first != z) {
cout << "0\n";
} else {
cout << it->second << '\n';
}
} else {
union_sets(y, z);
}
}
return 0;
} |
//abc183_e.cpp
//Sun Nov 15 21:30:13 2020
#include <bits/stdc++.h>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
using ll=long long;
typedef pair<int,int> P;
int main(){
int h,w;
cin >> h >> w;
string s[h];
rep(i,h)cin >> s[i];
ll dptate[h][w];
ll dpnana[h][w];
ll dpyoko[h][w];
rep(i,h)rep(j,w){
dptate[i][j] = 0;
dpnana[i][j] = 0;
dpyoko[i][j] = 0;
}
rep(i,h)rep(j,w){
ll tmp = 0;
if (s[i][j]=='#')continue;
if (i==0 && j==0){
dptate[0][0] = 1;
dpnana[0][0] = 1;
dpyoko[0][0] = 1;
}else {
if (i-1>=0){
tmp = (tmp+dptate[i-1][j])%MOD;
}
if (j-1>=0){
tmp = (tmp+dpyoko[i][j-1])%MOD;
}
if (i-1>=0 && j-1>=0){
tmp = (tmp+dpnana[i-1][j-1])%MOD;
}
if (i-1>=0){
dptate[i][j] = (tmp+dptate[i-1][j])%MOD;
}else {
dptate[i][j] = tmp;
}
if (j-1>=0){
dpyoko[i][j] = (tmp+dpyoko[i][j-1])%MOD;
}else {
dpyoko[i][j] = tmp;
}
if (i-1>=0 && j-1>=0){
dpnana[i][j] = (tmp+dpnana[i-1][j-1])%MOD;
}else {
dpnana[i][j] = tmp;
}
}
if (i==h-1 && j==w-1){
cout << tmp << endl;
return 0;
}
}
// cout << << endl;
// printf("%.4f\n",ans);
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T,class U> using P = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
ll gcd(ll a, ll b){
while (b>0){
ll tempB = b;
b = a % b;
a = tempB;
}
return a;
}
ll extgcd(ll a, ll b, ll& x, ll& y){
ll gcd_ = a * b;
if (b != 0) {
gcd_ = extgcd(b, a%b, y, x);
y -= (a/b) * x;
} else {
x = 1; y = 0;
}
return gcd_;
}
void solve(ll n, ll s, ll k){
// n and k is tagaini so
ll x, y;
// cout << "k, n = " << k << ", " << n << endl;
extgcd(k, n, x, y);
ll ans = ((x * s) % n + n )% n;
// cout << "ans: " << ans << endl;
ans = n - ans;
// cout << x << ", " << y << endl;
cout << ans << endl;
}
int main(){
int t; cin >> t;
vec<int> ni(t), si(t), ki(t);
rep(i, t) cin >> ni[i] >> si[i] >> ki[i];
rep(i, t) {
int n, s, k;
n = ni[i], s = si[i], k = ki[i];
int g = gcd(n, k);
if (g == 1) {
solve(n, s, k);
} else {
if (s % g != 0) cout << -1 << endl;
else solve(n/g, s/g, k/g);
}
}
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);
#define endl "\n"
#define deb(x) cout<<#x<<" : "<<x
#define mod (int)1e9+7
#define up upper_bound
#define lb lower_bound
#define fo(a,i,n) for(i=a;i<n;i++)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define isOn (S, j) (S & (1 << j))
#define setBit (S, j) (S |= (1 << j))
#define clearBit (S, j) (S &= ~(1 << j))
#define toggleBit (S, j) (S ^= (1 << j))
#define lowBit (S) (S & (-S))
#define setAll (S, n) (S = (1 << n) - 1)
#define modulo (S, N) ((S) & (N - 1))
#define isPowerOfTwo (S) (!(S & (S - 1)))
#define nearestPowerOfTwo (S) ((int)pow(2.0, (int)((log((double)S) / log(2.0)) + 0.5)))
#define turnOffLastBit (S) ((S) & (S - 1))
#define turnOnLastZero (S) ((S) | (S + 1))
#define turnOffLastConsecutiveBits (S) ((S) & (S + 1))
#define turnOnLastConsecutiveZeroes (S) ((S) | (S - 1))
typedef pair<ll, ll> pii;
typedef pair<ll, ll> pl;
typedef vector<ll> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
cout << name << " : " << arg1 << endl;
//use cerr if u want to display at the bottom
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
#else
#define trace(...)
#endif
ll gcd(ll a,ll b)
{
if(b == 0)
return a;
return gcd(b,a%b);
}
int main(){
// #ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
// freopen("output1.txt","w",stdout);
// #endif
IOS;
int t=1;
// cin>>t;
while(t--)
{
float n;
cin>>n;
cout<<ceil(n/100)<<endl;
}
return 0;
} | #include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define REP(i,j) for(int i=0;i<j;i++)
#define REPA(i,j) for(int i=1;i<=j;i++)
#define FORN(i,j,k) for(int i=j;i<k;i++)
#define vi vector<int>
#define vvi vector<vi >
#define pii pair<int,int>
#define vpii vector<pii >
#define all(a) a.begin(),a.end()
using namespace std;
const int INF=1<<30;
inline void read(int &x){
// short neg=1;
x=0;
char c=getchar();
/*while(c<'0'||c>'9'){
if(c=='-')neg=-1;
c=getchar();
}*/
while(c>='0'&&c<='9'){
x=(x<<3)+(x<<1)+(c^48),c=getchar();
}
// x*=neg;
}
int a,b;
int main(void){
cin>>a>>b;
int cnta=(a/100)+(a/10%10)+(a%10),cntb= (b/100)+(b/10%10)+(b%10);
cout<<max(cnta,cntb);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main()
{
int a, b, c, d;
cin >> a>> b>> c;
d = a - b + c;
cout << d;
} | #include<bits/stdc++.h>
//Ctrl + B
using namespace std;
#define endl '\n'
#define nitro {std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);}
#define pi 3.141592653589793
#define mod 1000000007
#define lb lower_bound
#define ub upper_bound
#define all(v) v.begin(), v.end()
#define dbg(x) cout << x << '\n';
#define case_g(x) cout<<"Case "<<x<<": ";
#define fi first
#define se second
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef unsigned long ul;
typedef std::vector<int> vi;
typedef std::vector<ll> vl;
typedef std::vector<bool> vb;
typedef std::pair<int, int> pii;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, bool> pib;
typedef std::vector<pii> vii;
typedef std::vector<pll> vll;
typedef std::vector<pib> vib;
typedef std::unordered_map<int, int> umapii;
typedef std::unordered_map<ll, ll> umapll;
typedef std::unordered_map<int , bool> umapib;
typedef std::map<int, int> mapii;
typedef std::map<ll, ll> mapll;
typedef std::map<int, bool> mapib;
ll ncr(ll n, ll r){//ncr formula
ll m=min(r,n-r);
ll ans=1;
for(int i=1;i<=m;i++){
ans=ans*(n-i+1)/i;
}
return ans;
}
ll modpow(ll a, ll b) { //modulo power
ll result = 1, M=mod;
while(b!=0) {
if(b&1) {
result = ((result%M)*(a%M))%M;
}
a = ((a%M)*(a%M))%M;
b >>= 1;
}
return result;
}
ll modinv(ll a) { //modulo inverse
ll m = mod, y = 0, x = 1;
while (a > 1) {
ll q = a / m, t = m;
m = a % m;
a = t;
t = y;
y = x - q * y;
x = t;
}
return x < 0 ? x + mod : x;
}
void solve()
{
vi a(3);
for(int i=0;i<3;i++)
{
cin>>a[i];
}
sort(all(a));
cout<<a[1]+a[2];
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
nitro
int tc;
tc =1;
//cin >> tc;
for(int i=1; i<=tc; ++i)
{
//case_g(i);
solve();
}
}
|
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main() {
int n; int D; int H;
cin >> n >> D >> H;
vector<int> d(n), h(n);
for(int i=0; i<n; ++i) cin >> d[i] >> h[i];
double ans = 0;
for(int i=0; i<n; ++i) {
double b = double(D * h[i] - d[i] * H) / (D - d[i]);
ans = max(ans, b);
}
printf("%.10lf\n", ans);
}
| #include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <stack>
#include <iomanip>
#include <climits>
#define MOD 1000000007
#define ll long long int
#include <queue>
using namespace std;
vector <bool> is_prime(10007,true);
void seive()
{
for (int i=2; i<=10007; i++)
{
if (is_prime[i]==true)
{
for (int num=2*i; num<=10007; num+=i)
{
is_prime[num]=false;
}
}
}
}
ll GCD(ll x,ll y)
{
ll mx=max(x,y),mn=min(x,y);
while(mn!=0)
{
ll temp=mn;
mn=mx%mn;
mx=temp;
}
return mx;
}
vector <vector <ll>> vis;
vector <vector <ll>> a;
vector <vector <vector <char>>> dis;
//vector <ll> vis,counttime;
/*void dfs(ll v)
{
vis[v]=1;
for (int child:a[v])
{
if (vis[child]==0)
dfs(child);
}
}
*/
ll dx[4]= {1,0,-1,0};
ll dy[4]= {0,-1,0,1};
char dir[4]= {'D','L','U','R'};
ll n,m;
bool isValid(ll x,ll y)
{
if (x<1||x>n||y<1||y>m)
return false;
if (vis[x][y]==1)
return false;
return true;
}
vector <pair<ll,ll>> ans_vec;
void DFS_grid(ll x,ll y)
{
// cout<<x<<" "<<y<<" "<<vis[x][y]<<endl;
vis[x][y]=1;
ans_vec.push_back({x,y});
for (int i=0; i<4; i++)
{
ll newX=x+dx[i],newY=y+dy[i];
if (isValid(newX,newY))
{
DFS_grid(newX,newY);
}
}
}
vector <vector<ll>> bin;
void binary_conv(ll x,ll ind)
{
vector <ll> a(31,0);
int k=-1;
ll xs=x,val=1;
for (int i=1; i<=x; i*=2)
{
k++;
val=i;
}
cout<<val<<" "<<k<<endl;
for (ll i=val; i>=1; i/=2)
{
if (i<=x)
{
x-=i;
a[30-k]=1;
}
k--;
}
bin[ind]=a;
}
ll binpow(ll a,ll b)
{
if (b==0)
return 1;
ll res=binpow(a,b/2);
if (b%2==0)
{
return (res*res)%1000000007;
}
else return (a*res*res)%1000000007;
}
pair<ll,string> func(string s,char a[],ll n,ll k)
{
ll ans =0;
for (int i=1; i<n; i++)
{
if (i<n-1&&s[i]==s[i-1]&&s[i]==s[i+1])
{
s[i]=a[(s[i]-'A'+1)%k];
ans++;
}
else if (s[i]==s[i-1])
{
ll mid=(s[i-1]-'A'+1)%k;
s[i]=a[mid];
if(k>2)
{
if (i<n-1&&s[i]==s[i+1])
{
s[i]=a[(mid+1)%k];
}
}
ans++;
}
}
return {ans,s};
}
bool is_good(ll k,ll n,ll a,ll b,ll ele)
{
if (ele<=n&&k-ele*a>0)
{
if ((k-ele*a)/b+ele>n||(k-ele*a)/b+ele==n&&(k-ele*a)%b!=0)
return true;
}
return false;
}
ll mod(ll x,ll y)
{
return max(x-y,y-x);
}
int main()
{
ll t=1;
//cin>>t;
while(t--)
{
ll n;
double d,h;
cin>>n>>d>>h;
cout<<setprecision(20);
double mx=d,my=0,m=h/d;
while(n--)
{
double x,y;
cin>>x>>y;
if ((y-my)/x>m)
{
my+=((y-my)/x-m)/(1/x-1/d);
m=(h-my)/d;
}
}
//cout<<mx<<my<<endl;
//cout<<ans<<endl;
cout<<my<<endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define pii pair<int,int>
#define pf push_front
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define ppb pop_back
#define ppf pop_front
#define f(i,a,b) for(int i = a; i < b; ++i)
#define R(i,a,b) for(int i = a; i >= b; --i)
#define rep(i,a,b) for(int i = a; i <= b; ++i)
#define fr first
#define sc second
#define sz(x) (int)((x).size())
#define all(x) (x).begin(),(x).end()
string s;
signed main()
{
ios_base::sync_with_stdio(false);cin.tie(NULL);
cin >> s;
int n = s.length();
int flag = 1;
f(i,0,n){
if((i&1)){
if(islower(s[i])){
flag = 0;
break;
}
}else{
if(isupper(s[i])){
flag = 0;
break;
}
}
}
if(flag) cout << "Yes\n";
else cout << "No\n";
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main(){
int cnt=0;
string S;
cin >>S;
const char* cS=S.c_str();
for(int i=0; i<S.size(); i++){
if(i%2==0){
if(cS[i]>=97){
cnt++;
}
}
else if(i%2==1){
if(cS[i]<97){
cnt++;
}
}
}
if(cnt==S.size()){
cout << "Yes" <<endl;
}
else cout <<"No"<<endl;
} |
#include <bits/stdc++.h>
#include <unistd.h>
//#include <atcoder/all>
#if __has_include(<local.h>)
#include <local.h>
#endif
using namespace std;
//using namespace atcoder;
typedef long long int LL;
typedef long long int LLint;
//Faster Program
#define endl "\n"
//Faster Coding
#define ED return
#define GET(a) int a;cin >> a
#define DGET(a) double a;cin >> a
#define SGET(a) string a;cin >> a
#define CGET(a) char a;cin >> a
#define PRINT(a) cout << a << "\n"
#define ANS(a,b) int a;cin >> a;cout << b << "\n"
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define SORT(vec) sort(vec.begin(),vec.end())
#define REV(vec) reverse(vec.begin(),vec.end())
#define ALL(x) (x).begin(),(x).end()
//As Function
#define UP(a,b) ((a+(b-1))/(b))
#define IPOW(x,y) (LL(pow(x,y)))
//Debug
#ifdef LOCAL_H
#define TEST cout << "OK\n"
#define DEBUG(a) a
#else
#define TEST
#define DEBUG(a)
#endif
#ifdef LOCAL_H
[[maybe_unused]]
#endif
const double PI = M_PI;
#ifdef LOCAL_H
[[maybe_unused]]
#endif
const int INF = int(999999999);
#ifdef LOCAL_H
[[maybe_unused]]
#endif
const LL LL_INF = LL(999999999999999999);
#ifdef LOCAL_H
[[maybe_unused]]
#endif
const long long MOD = int(1000000007);
#ifdef LOCAL_H
[[maybe_unused]]
#endif
const long long MOD_2 = int(998244353);
//Settings
#ifdef LOCAL_H
const bool DO_BENCHMARK = true;
#endif
const int DOUBLE_ACCURACY = 15;
const int RUN_SOLVE = 1;
#ifndef LOCAL_H
const bool DO_BENCHMARK = false;
#endif
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(DOUBLE_ACCURACY);
for(int do_solve_time = 0;do_solve_time < RUN_SOLVE;do_solve_time++){
void solve();
if(DO_BENCHMARK){
clock_t clock_start = clock();
solve();
clock_t clock_end = clock();
const double time = static_cast<double>(clock_end-clock_start)/CLOCKS_PER_SEC*1000.0;
cout << "\n------------------------------------\n" << time << "[ms]\n";
}
else solve();
}
}
/*------------------------------↓ここからコード↓----------------------------------*/
void solve(){
LL N, M;
cin >> N >> M;
vector<LL> H (N);
vector<LL> W (M);
for(LL i = 0;i < N;i++){
cin >> H[i];
}
SORT(H);
for(LL i = 0;i < M;i++){
cin >> W[i];
}
SORT(W);
// cout << endl;
// for(LL i = 0;i < N;i++){
// cout << H[i] << " ";
// }
// cout << endl;
// for(LL i = 0;i < M;i++){
// cout << W[i] << " ";
// }
// cout << endl;
vector<LL> sum_before (N/2+1,0);
vector<LL> sum_after (N/2+1,0);
for(LL i = 0;i < N/2;i++){
sum_before[i+1] = sum_before[i]+abs(H[i*2]-H[i*2+1]);
sum_after[i+1] = sum_after[i]+abs(H[N-1-i*2]-H[N-2-i*2]);
}
LL ans = LL_INF;
LL now = 0;
for(LL i = 0;i < N/2+1;i++){
while(now != M-1 && abs(H[i*2]-W[now]) >= abs(H[i*2]-W[now+1])){
now++;
}
// cout << "CHANGE " << i*2 << "(" << H[i*2] << ")" << endl;
// cout << " before = " << sum_before[i] << endl;
// cout << " after = " << sum_after[N/2-i] << endl;
// cout << " teacher = " << abs(H[i*2]-W[now]) << "(" << now << "," << W[now] << ")" << endl;
ans = min(ans,sum_before[i]+sum_after[N/2-i]+abs(H[i*2]-W[now]));
}
cout << ans << endl;
return;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const char mc[4]={'U','L','D','R'};
const int max_e = 9000;
const int inf = 1000000000;
int mh[29][29],mv[29][29];
int dijkstra(vector<vector<int> > &m, pair<int, int> s){
priority_queue<pair<int,pair<int,int> >, vector<pair<int,pair<int,int> > >, greater<pair<int,pair<int,int> > > > next;
next.push(make_pair(0,s));
while (!next.empty()) {
int x = next.top().second.first,y = next.top().second.second;
int p = next.top().first;
next.pop();
if(x > 0){
if(chmin(m[x - 1][y], p + mv[x - 1][y])){
next.push(make_pair(p + mv[x - 1][y], make_pair(x - 1, y)));
}
}
if(x < 29){
if(chmin(m[x + 1][y], p + mv[x][y])){
next.push(make_pair(p + mv[x][y], make_pair(x + 1, y)));
}
}
if(y > 0){
if(chmin(m[x][y - 1], p + mv[x][y - 1])){
next.push(make_pair(p + mv[x][y - 1], make_pair(x, y - 1)));
}
}
if(y < 29){
if(chmin(m[x][y + 1], p + mv[x][y])){
next.push(make_pair(p + mv[x][y], make_pair(x, y + 1)));
}
}
}
return 0;
}
string restore(vector<vector<int> > &m, int x, int y){
string root = "";
int s = 0;
while (m[x][y] != 0) {
++s;
int next_x = x,next_y = y,p = m[x][y];
rep0(i, 4)if(chmin(p, m[min(max(0,x + dx[i]),29)][min(max(0,y + dy[i]),29)])){
next_x = x + dx[i];
next_y = y + dy[i];
if(s != root.size())root.push_back(mc[i]);
else root[s - 1] = mc[i];
}
x = next_x;
y = next_y;
}
reverse(all(root));
return root;
}
int update(string s, int p, int x, int y){
rep0(i, s.size()){
if(s[i] == 'U'){
mv[x - 1][y] = (mv[x - 1][y] + p + 1) / 2;
x--;
}else if(s[i] == 'D'){
mv[x][y] = (mv[x][y] + p + 1) / 2;
x++;
}else if(s[i] == 'R'){
mh[x][y] = (mh[x][y] + p + 1) / 2;
y++;
}else{
mh[x][y - 1] = (mh[x][y - 1] + p + 1) / 2;
y--;
}
}
return 0;
}
//modを確認すること
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
rep0(i, 30)rep0(j, 30){
//mh[i][j] = max_e;
//mv[i][j] = max_e;
mh[i][j] = rand() % 8000 + 1000;
mv[i][j] = rand() % 8000 + 1000;
}
rep0(i, 1000){
vector<vector<int> > m(30,vector<int>(30,inf));
int sx,sy,gx,gy,p;
string s = "";
cin >> sx >> sy >> gx >> gy;
m[sx][sy] = 0;
dijkstra(m, make_pair(sx, sy));
string ans = restore(m, gx, gy);
pf(ans);
cin >> p;
update(ans, int((p + ans.size() - 1) / ans.size()), sx, sy);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll n, fib[100];
int main() {
fib[0] = fib[1] = 1;
for (int i = 2; i < 100; i++) fib[i] = fib[i - 1] + fib[i - 2];
cin >> n;
int m = 86;
vector<int> ans;
for (int i = 0; i <= m; i++) {
if (i % 2 == 0) {
if (n >= fib[m - i]) {
ans.push_back(1);
n -= fib[m-i];
}
ans.push_back(4);
}
if (i % 2 == 1) {
if (n >= fib[m - i]) {
ans.push_back(2);
n -= fib[m-i];
}
ans.push_back(3);
}
}
cout << ans.size() << "\n";
for (int i = 0; i < ans.size(); i++) cout << ans[i] << "\n";
return 0;
}
// 首先发现按如下操作序列[4->3->4->3->4->3]操作,结果会呈现fib数字.
// 如果这个序列长度是S,当我们在索引i=2k(i是偶数)之前执行操作1,将会增加fib(S-i)
// 当我们在索引i=2k+1(i是奇数)之前执行操作2,将会增加fib(S-i) | #include <bits/stdc++.h>
#define ll long long
using namespace std;
ll read(){
ll sum=0,f=1;
char s=getchar();
while (s<'0' or s>'9'){
if (s=='-')f=-1;
s=getchar();
}
while (s>='0' and s<='9'){
sum=sum*10+s-'0';
s=getchar();
}
return sum*f;
}
ll N=1e10*3-1;
bool a[3];
char s[3]={'1','1','0'};
int main(){
int n=read();
// while (n--)slove();
string t;
cin>>t;
a[0]=a[1]=a[2]=0;
for (int p=0;p<3;p++){
int q=p;
bool f=1;
for (int i=0;i<n;i++){
if (t[i]!=s[q]){
f=0;
break;
}
q++;
q%=3;
}
a[p]=f;
}
ll ans=N-n+1;
ll maxn=0;
for (int i=0;i<3;i++){
if (a[i]==0)continue;
ll k=ans-i;
k/=3;
maxn+=k+1;
// maxn=max(maxn,3*k+i);
}
cout<<maxn;
// ll x=read();
// if (x==maxn)cout<<"y";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
int main() {
string N;
int K;
cin >> N >> K;
long A = stoi(N);
rep(i, K) {
string J = to_string(A);
string G, H;
sort(J.begin(), J.end());
H = J;
reverse(J.begin(), J.end());
G = J;
A = stoi(G)-stoi(H);
}
cout << A << endl;
} | #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define ll long long
ll n,m,cnt,ans = -0x3f3f3f3f;
ll head[200005];
ll val[200005],maxx[200005],minn[200005];
int vis[200005];
struct K{
ll val,num;
}p[200005];
struct P{
ll to,next;
}e[400005];
void add(ll x,ll y){
e[++cnt].to = y;
e[cnt].next = head[x];
head[x] = cnt;
}
void dfs(ll now){
//std::cout<<now<<" "<<val[now]<<" "<<minn[now]<<std::endl;
ans = std::max(val[now] - minn[now],ans);
for(int i = head[now];i;i = e[i].next){
if(!vis[e[i].to]){
minn[e[i].to] = std::min(minn[now],val[now]);
vis[e[i].to] ++ ;
dfs(e[i].to);
}
}
}
bool operator < (K a,K b){
return a.val < b.val;
}
int main(){
memset(maxx,-0x3f,sizeof(maxx));
memset(minn,0x3f,sizeof(minn));
scanf("%lld%lld",&n,&m);
for(int i = 1;i <= n;++i)
scanf("%lld",&p[i].val),p[i].num = i,val[i] = p[i].val;
for(int i = 1;i <= m;++i){
ll x,y;
scanf("%lld%lld",&x,&y);
add(x,y);
}
std::sort(p + 1,p + 1 + n);
for(int i = 1; i<= n;++i)
if(!vis[p[i].num])
dfs(p[i].num);
std::cout<<ans<<std::endl;
}
|
#include <algorithm>
#include <array>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define int long long
#define ll long long
#define pii std::pair<int, int>
#define pdd std::pair<double, double>
#define INF (1LL << 33)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define SHOW(p) \
if (test) \
cout << #p " : " << p << endl;
bool test = false;
int ans, N;
int hoge(int x)
{
if (x < 1000) {
return 0;
} else if (x < 1000000) {
return x - 999;
}
int len = std::to_string(x).length();
int co = (len - 1) / 3;
int tmp = 1;
REP(i, len - 1)
{
tmp *= 10;
}
if (tmp == x) {
return co + hoge(x - 1);
}
return (x - tmp) * co + hoge(tmp);
}
signed main()
{
test = true;
cin >> N;
cout << hoge(N) << endl;
return 0;
}
| #include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<tuple>
#include<cstring>
#include<bitset>
#define REP(i,n) for(ll i=0;i<(ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((ll)(x).size())
#define pb push_back
#define eb emplace_back
#define INF 1000000000
#define INFLL 1000000000000000000LL
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; }
using ll = long long;
using P = pair<ll, ll>;
#define MAX_N 1000+10
ll N;
pair<int, string> p[MAX_N];
int main() {
cin >> N;
REP(i, N)cin >> p[i].second >> p[i].first;
sort(p, p + N, greater<pair<int, string>>());
cout << p[1].second << endl;
return 0;
} |
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdlib>
#define FUP(i,x,y) for(int i=(x);i<=(y);i++)
#define FDW(i,x,y) for(int i=(x);i>=(y);i--)
#define MAXN 200010
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define ll long long
#define db double
using namespace std;
int read()
{
int d=0,flg=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-'){flg=-1;}ch=getchar();}
while(ch<='9'&&ch>='0'){d=d*10-'0'+ch,ch=getchar();}
return d*flg;
}
int n,q,C,opt,x,y,root[MAXN];
int tot;
struct node{
int ls,rs,val;
}p[MAXN*50];
int Merge(int u,int v,int l,int r)
{
if(!u||!v) return u|v;
if(l==r)
{
p[++tot].val=p[u].val+p[v].val;
return tot;
}
int mid=(l+r)>>1;
int node=++tot;
p[node].ls=Merge(p[u].ls,p[v].ls,l,mid);
p[node].rs=Merge(p[u].rs,p[v].rs,mid+1,r);
p[node].val=p[p[node].ls].val+p[p[node].rs].val;
//printf("%d %d %d %d %d %d\n",node,u,v,p[node].ls,p[node].rs,p[node].val);
return node;
}
int query(int u,int l,int r,int pos)
{
if(l==r) return p[u].val;
int mid=(l+r)>>1;
if(pos<=mid)
{
if(!p[u].ls) return 0;
return query(p[u].ls,l,mid,pos);
}
else
{
if(!p[u].rs) return 0;
return query(p[u].rs,mid+1,r,pos);
}
}
void update(int u,int l,int r,int x,int y)
{
if(l==r) p[u].val+=y;
else
{
int mid=(l+r)>>1;
if(x<=mid)
{
if(!p[u].ls) p[u].ls=++tot;
update(p[u].ls,l,mid,x,y);
}
else
{
if(!p[u].rs) p[u].rs=++tot;
update(p[u].rs,mid+1,r,x,y);
}
p[u].val=p[p[u].ls].val+p[p[u].rs].val;
}
}
int fa[MAXN];
int Find(int u){return fa[u]==0?u:fa[u]=Find(fa[u]);}
void Union(int u,int v)
{
u=Find(u),v=Find(v);
if(u==v) return;
fa[u]=v;
root[v]=Merge(root[u],root[v],1,n);
//printf("%d\n",root[v]);
}
int main(){
n=read(),q=read();
FUP(i,1,n)
{
C=read(),root[i]=++tot;
update(tot,1,n,C,1);
}
//printf("## %d\n",tot);
FUP(i,1,q)
{
opt=read(),x=read(),y=read();
if(opt==1) Union(x,y);
else
{
x=root[Find(x)];
printf("%d\n",query(x,1,n,y));
}
}
return 0;
} | //*
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
//*/
#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
// #define int ll
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
void YES(bool t=true) {cout<<(t?"YES":"NO")<<endl;}
void Yes(bool t=true) {cout<<(t?"Yes":"No")<<endl;}
void yes(bool t=true) {cout<<(t?"yes":"no")<<endl;}
void NO(bool t=true) {cout<<(t?"NO":"YES")<<endl;}
void No(bool t=true) {cout<<(t?"No":"Yes")<<endl;}
void no(bool t=true) {cout<<(t?"no":"yes")<<endl;}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
// int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {0, 1, 0, -1}, dy = {-1, 0, 1, 0};
// vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'
vl a;
int n;
map<pll, ll> mp;
ll solve(ll x, int i) {
if (i == 0) return 1;
if (x % a[i] == 0) return 1;
if (mp.count(pll(x, i))) return mp[pll(x, i)];
ll needed;
if (x % a[i] == 0) needed = x / a[i];
else needed = x / a[i] + 1;
DEBUG(pll(x, i));
DEBUG(needed);
ll ans = 0;
if (i + 1 < n and needed >= a[i + 1] / a[i]) {}
else {
ll gyaku = needed * a[i] - x;
ll ans1 = solve(gyaku, i - 1);
ans += ans1;
}
ans += solve(x - a[i] * (needed - 1), i - 1);
mp[pll(x, i)] = ans;
return ans;
}
signed main() {
fio();
cin >> n;
ll x;
cin >> x;
a.resize(n);
rep (i, n) cin >> a[i];
// a[0] = 1;
// rep (i, n - 1) a[i + 1] = a[i] * 2;
ll ans = solve(x, n - 1);
// for (auto itr = mp.begin(); itr != mp.end(); itr++) {
// DEBUG(*itr);
// }
cout << ans << endl;
} |
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <stack>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <sstream>
#include <iomanip>
using namespace std;
#define int int64_t
#define vi vector<int>
#define vb vector<bool>
#define vbb vector< vector<bool> >
#define all(x) (x).begin(), (x).end()
#define vii vector< vector<int> >
#define rip(dp, n, m) vector< vector<int> > dp(n, vector<int>(m,0))
#define ff first
#define ss second
#define pii pair<int64_t, int64_t>
#define miv map<int, vector<int> >
#define mp make_pair
#define pb push_back
#define prr(x) cout << (#x) <<' ' << (x) << endl
#define pr(x) cout << (x) << endl
#define f(i,n) for(i=0;i<n;i++)
#define pqb priority_queue<int>
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define autoitr(x,it) for(auto it = x.rbegin(); it != x.rend(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define pqs priority_queue<int,vi,greater<int> >
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x,y) fixed<<setprecision(y)<<x
#define mk(arr,n,type) type *arr=new type[n];
#define w(x) int x; cin>>x; while(x--)
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int dr8[] = {1,1,0,-1,-1,-1, 0, 1};
int dc8[] = {0,1,1, 1, 0,-1,-1,-1};
int dr4[] = {1,0,0,-1};
int dc4[] = {0,1,-1,0};
int gcd(int a, int b)
{
if(a%b==0) return b;
return gcd(b, a%b);
}
void inp(int &x)
{
bool neg=false;
register int c;
x =0;
c=getchar();
if(c=='-')
{
neg = true;
c=getchar();
}
for(;(c>47 && c<58);c=getchar())
x = (x<<1) + (x<<3) +c -48;
if(neg)
x *=-1;
}
void solve();
int32_t main()
{
FIO;
int t=1;
//cin >> t;
for(int i=1;i<=t;i++)
{
solve();
}
}
void solve()
{
int i, n, j, m, k, l, t;
cin >> n >> m;
rip(dp,n,m);
f(i,n) f(j,m) cin >> dp[i][j];
k=inf;
f(i,n) f(j,m) k = min(k,dp[i][j]);
l=0;
f(i,n) f(j,m) l += dp[i][j]-k;
cout << l;
} | #include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=3e6+5;
int n;
int c[maxn],k,now;
signed main() {
// freopen("data.in","r",stdin);
// freopen("data.out","w",stdout);
cin>>n>>k;
for(register int i=1; i<=3*n; i++)c[i]=i*(i-1)/2;
for(register int t=3; t<=3*n; t++) {
int w=c[t-1];
// cout<<w<<endl;
if(t>n+1)w-=c[t-n-1]*3;
if(t>2*n)w+=c[t-2*n-1]*3;
// cout<<t<<' '<<w<<endl;
if(now+w>=k) {
// cout<<t<<' '<<now<<' '<<k<<endl;
for(register int i=1; i<=n; i++) {
if(t-i<2||t-i>2*n)continue;
int p=t-i,q=p-1;
if(p>n)q-=(p-n-1)*2;
if(now+q>=k) {
if(p>n) {
int cs=p-n;
printf("%lld %lld %lld",i,k-now+cs-1,t-i-k+now-cs+1);
} else printf("%lld %lld %lld",i,k-now,t-i-k+now);
return 0;
}
now+=q;
}
return 0;
}
now+=w;
}
cout<<now<<' '<<k<<endl;
} |
#pragma GCC optimization ("O3")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<pair<ll,ll>,null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update>
typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> oset;
#define ll long long
#define endl "\n"
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const ll M = 1e9 + 7;
int main()
{
fast
string s;
deque<char> v;
cin >> s;
int c = 0;
for(auto x : s)
{
if(x == 'R')c ^= 1;
else
{
if(c == 1)v.push_front(x);
else v.push_back(x);
}
}
if(v.empty())return 0;
if(c)reverse(v.begin(), v.end());
vector<char> t;
for(int i = 0; i < v.size(); i++)
{
int cnt = 0;
char cc = v[i];
while(i < v.size() && v[i] == cc)i++, cnt++;
i--;
if(cnt % 2)t.push_back(cc);
while(t.size() > 1 && t.back() == t[t.size() - 2])t.pop_back(), t.pop_back();
}
for(auto x : t)cout << x;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<typename T>
void view_1d(vector<T> V, string sep) {
for (ll i=0; i<V.size(); i++) {
cout << V[i];
if (i == V.size() - 1) {
cout << endl;
} else {
cout << sep;
}
}
}
template<typename T>
void view_2d(vector<vector<T>> V, string sep) {
for (ll i=0; i<V.size(); i++) {
for (ll j=0; j<V[i].size(); j++) {
cout << V[i][j];
if (j == V[i].size() - 1) {
cout << endl;
} else {
cout << sep;
}
}
}
}
//==============================//
int main() {
string S;
cin >> S;
int i = 0;
int ans = 0;
while (i < 12) {
if (S.substr(i,4) == "ZONe") {
i += 4;
ans++;
} else {
i++;
}
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#define rep0(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vvvi = vector<vvi>;
using ll = long long; //約9.0*10^18
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll =vector<vvll>;
const double PI=3.14159265358979323846;
using std::cout; using std::endl;
using std::string; using std::reverse;
//小数点以下を指定したい時 →→→→ cout << fixed << setprecision();
//int→string string str = to_string(num);
//string→int int num = atoi(numStr.c_str());
//複数のvector管理→;vector<tuple<string, int, int>> SP(N);
//int max = *max_element(all(A));最大値
//int min = *min_element(all(B));最小値
int main() {
ll x,y,z;cin>>x>>y>>z;
ll ans =0;
rep0(i,100000000){
if(y*z>x*i){
ans = i;
}
else{
break;
}
}
cout<<ans<<endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int x, y, z, ans;
cin >> x >> y >> z;
ans = y * z / x;
if (ans*x == z*y)
ans -= 1;
cout << ans << endl;
} |
#include <bits/stdc++.h>
#define int long long
using namespace std;
#ifdef LOCAL
#include "/media/brayand/BrayanD/debugger.h"
#else
#define db(...) false
#define dbl(...) false
#define dbg(...) false
#define dbm(...) false
#define dbs(...) false
#define dbas(...) false
#endif
const int MAXN = 10000;
int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
vector<int> vect;
for(int i = 2 ; 2*3*i <= MAXN ; i++)
{
if(i%5)
{
vect.push_back(2*3*i);
}
}
for(int i = 2 ; 2*5*i <= MAXN ; i++)
{
if(i%3)
{
vect.push_back(2*5*i);
}
}
for(int i = 2 ; 3*5*i <= MAXN ; i++)
{
if(i%2)
{
vect.push_back(3*5*i);
}
}
for(int i = 1 ; 2*3*5*i <= MAXN ; i++)
{
vect.push_back(2*3*5*i);
}
int N;
cin >> N;
vector<int> ans;
ans.push_back(2*3);
ans.push_back(2*5);
ans.push_back(3*5);
N-=3;
while(N--)
{
ans.push_back(vect.back());
vect.pop_back();
}
for(auto x : ans)
{
cout << x << " ";
}
cout << '\n';
return 0;
} | #include <iostream>
using namespace std;
int N;
int main()
{
cin >> N;
cout << "6 10 15"; N -= 3;
for (int i = 16; N; i++)
{
if (i % 6 == 0 || i % 10 == 0 || i % 15 == 0) {N--; cout << " " << i;}
}
cout << "\n";
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n); for (int i = 0; i < (int)(n); i++)
#define rep1(i,n); for (int i = 1; i <= (int)(n); i++)
int main()
{
int n;
cin >> n;
cout << 100-(n%100) << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int sz = 2e5+5;
int main() {
int x;
cin >> x;
cout << 100 - x % 100;
}
|
#pragma GCC optimize("O3")
//#pragma GCC target("avx2")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;
ll INF = 1e16;
int inf = 1e9;
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (ll i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (ll i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll
#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif
void d_err() {
cerr << endl;
}
template <typename H, typename... T>
void d_err(H h, T... t) {
cerr << h << " ";
d_err(t...);
}
template <typename T>
void print(T x) {
cout << x << "\n";
}
template <typename T>
void print(vector<T>& x) {
int N = x.size();
REP(i, N) {
if (i > 0) cout << " ";
cout << x[i];
}
cout << "\n";
}
int main(){
cin.tie(0);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(20);
int n; cin >> n;
vector<vll> v(n, vll(n));
REP(i, n) REP(j, n) cin >> v[i][j];
vll y;
REP(i, n) {
y.eb(*min_element(ALL(v[i])));
}
debug(y)
vll x;
FOR(i, 0, n) {
ll tmp = v[0][i] - y[0];
REP(j, n) {
if (tmp != v[j][i] - y[j]) {
print("No");
return 0;
}
}
x.eb(tmp);
}
print("Yes");
print(y);
print(x);
}
| #include<stdio.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#define MAXN 200005
#define max_num 1000000
#define LL long long
using namespace std;
int n, m;
int l[MAXN], r[MAXN];
int main()
{
while(cin >> n >> m)
{
if(m < 0 || m == n || (m == n - 1 && n - 1 > 0))
{
puts("-1");
continue;
}
if(n == 1)
{
puts("1 2");
continue;
}
int num_w = n - m - 2;
int now = max_num;
for(int i = 0; i < num_w; i++)
{
r[i] = now;
now--;
l[i] = now;
now--;
}
l[num_w] = 1;
r[num_w] = (m + 2 + 1) * 2;
now = (m + 2) * 2 - 1;
for(int i = num_w + 1; i < n; i++)
{
r[i] = now;
now--;
l[i] = now;
now--;
}
for(int i = 0; i < n; i++)
{
printf("%d %d\n", l[i], r[i]);
}
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
// 繰り返し自乗法(x^nをmで割った余り) O(logn)
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;
}
int main() {
ll a, b, c;
cin >> a >> b >> c;
ll d = modpow(b, c, 4);
if (d == 0) d += 4;
cout << modpow(a, d, 10) << '\n';
} | #include <bits/stdc++.h>
using namespace std;
const long long inf = (long long)1e9 * (long long)1e9;
map<int, int>mods;
long long calculateMod(long long b, long long c, int mod) {
// oblicz reszte z dzielenia b^c przez mod, mod <= 5
if (c == 1) return b%mod;
if (c == 0) return 1;
b %= mod;
long long half = calculateMod(b, c/2, mod);
long long rest = 1;
if (c % 2 == 1) rest = b;
return (((half * half) % mod) * rest) % mod;
}
int main() {
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
a %= 10;
if (a == 0 || a == 1 || a == 5 || a == 6) {
printf("%d\n", a);
return 0;
}
mods[2] = 4;
mods[3] = 4;
mods[4] = 2;
mods[7] = 4;
mods[8] = 4;
mods[9] = 2;
int mod = calculateMod(b, c, mods[a]);
// printf("%d\n", calculateMod(2, 20, 100000000));
// return 0;
// printf("%d\n", mod);
if (a == 2) {
int mods[] = {6, 2, 4, 8};
printf("%d\n", mods[mod]);
}
if (a == 3) {
int mods[] = {1, 3, 9, 7};
printf("%d\n", mods[mod]);
}
if (a == 4) {
int mods[] = {6, 4};
printf("%d\n", mods[mod]);
}
if (a == 7) {
int mods[] = {1, 7, 9, 3};
printf("%d\n", mods[mod]);
}
if (a == 8) {
int mods[] = {6, 8, 4, 2};
printf("%d\n", mods[mod]);
}
if (a == 9) {
int mods[] = {1, 9};
printf("%d\n", mods[mod]);
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int main(){
int a, b, c, ans;
string ans1;
cin >> a >> b >>c;
if(a != b){
ans = max(a,b);
if(ans ==a){ans1 = "Takahashi";}
else{ans1 = "Aoki";}}
else{
if(c==0){
ans = 0;}
else{ans = 1;}
if(ans ==1){ans1 = "Takahashi";}
else{ans1 = "Aoki";}
}
cout <<ans1;
} | #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
int main()
{
int a,b,c;
cin>>a>>b>>c;
if((a>b)||(a==b&&c==1))
printf("Takahashi");
else printf("Aoki");
return 0;
}
|
#pragma GCC optimize ("-O2")
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define deb(x) cout<< #x << " " << x << "\n";
#define MAX 9223372036854775807
#define MIN -9223372036854775807
#define setbits(n) __builtin_popcountll(n)
#define mkunique(a) a.resize(unique(a.begin(),a.end())-a.begin());
const ll mod=1e9+7;
ll euclid(ll a, ll b, ll &x, ll &y){
if (b){
ll d = euclid(b, a % b, y, x);
return y -= a / b * x, d;
}
return x = 1, y = 0, a;
}
ll crt(ll a, ll m, ll b, ll n){
if (n > m)
swap(a, b), swap(m, n);
if (n == 1)
return a;
ll x, y, g = euclid(m, n, x, y);
if ((a - b) % g != 0)
return LLONG_MAX;
x = (b - a) % n * x % n / g * m + a;
return x < 0 ? x + m * n / g : x;
}
pair<ll, ll> crt(const vector<ll> &r, const vector<ll> &m){
ll r0 = 0, m0 = 1;
assert(r.size() == m.size());
for (size_t i = 0; i < r.size(); i++){
auto rem = crt(r0, m0, r[i], m[i]);
if (rem == LLONG_MAX)
return {-1, -1};
r0 = rem;
m0 = m0 / __gcd(m0, m[i]) * m[i];
}
return {r0, m0};
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll T=clock();
ll t;
cin>>t;
while(t--){
ll x,y,p,q;
cin>>x>>y>>p>>q;
ll ans=mod*mod;
for(ll i=x;i<x+y;i++){
for(ll j=p;j<p+q;j++){
auto [r,lcm] = crt({i, j}, {2*x+2*y, p+q});
if(lcm==-1) continue;
ans=min(ans, r);
}
}
if(ans==mod*mod)
cout<<"infinity\n";
else
cout<<ans<<"\n";
}
cerr<<"\n\nTIME: "<<(double)(clock()-T)/CLOCKS_PER_SEC<<" sec\n";
T = clock();
return 0;
} | //Iamskk//
#include <iostream>
#include <iosfwd>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <cassert>
#include <cctype>
#include <climits>
#include <vector>
#include <bitset>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <deque>
#include <string>
#include <list>
#include <iterator>
#include <sstream>
#include <complex>
#include <fstream>
#include <functional>
#include <numeric>
#include <utility>
#include <algorithm>
#include <assert.h>
#include <unordered_map>
using namespace std;
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
#define endl '\n'
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define ai(arr,n) for(int i=0;i<n;i++)cin>>arr[i];
#define ao(arr) for(auto asdfasdfasdf:arr) cout<<asdfasdfasdf<<" ";
#define mi(arr,m,n) for(int i=0;i<m;i++){ for(int j=0;j<n;j++) cin>>arr[i][j];}
#define mo(arr,m,n) for(int i=0;i<m;i++){ for(int j=0;j<n;j++) cout<<arr[i][j]<<" "; cout<<endl;}
#define countsetbits(x) __builtin_popcount(x)
#define ll long long
#define debug cout<<"I AM EXECUTING"<<endl
#define testcases int asdf; cin>>asdf; while(asdf--)
#define vi vector<int>
#define vll vector<long long int>
#define vppo(prs) for(auto x:prs){cout<<x.first<<" "<<x.second<<endl;}
#define For(__,hajmola,adfdf) for(int __ = hajmola; __<adfdf;__++)
#define formax 1e18
#define formin -1e18
#define watch(x) cout << (#x) << " is " << (x) << endl
string sconvert(ll int n)
{
stringstream ss;
ss<<n;
string str = ss.str();
return str;
}
bool sortbysec(const pair<int,int> &a,
const pair<int,int> &b)
{
return (a.second > b.second);
}
template<typename T>
void imax(T &x,T y){
x = max(x,y);
}
template<typename T>
void imin(T &x,T y){
x = min(x,y);
}
void single()
{
string str;
cin>>str;
int n=str.length();
int count=0;
for(int i=0;i<n-3+1;i++){
if(str[i]=='Z' and str[i+1]=='O' and str[i+2]=='N'){
count++;
}
}
cout<<count<<endl;
return;
}
void multiple()
{
testcases
{
single();
}
}
int main()
{
IOS;
// freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
single();
}
|
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
using ll = long long;
const ll INF = 1ll<<60;
struct Edge{
int to;
int weight;
int k;
Edge(int t, int w, int k): to(t), weight(w), k(k) {}
};
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n, m, x, y;
cin >> n >> m >> x >> y;
--x;
--y;
vector<vector<Edge>> g(n);
for(int i = 0; i < m; ++i){
int a, b, t, k;
cin >> a >> b >> t >> k;
--a;
--b;
g[a].push_back(Edge(b, t, k));
g[b].push_back(Edge(a, t, k));
}
vector<ll> dist(n, INF);
dist[x] = 0;
priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq;
pq.push({0, x});
while(!pq.empty()){
pair<ll, int> p = pq.top();
pq.pop();
int v = p.second;
if(dist[v] != p.first) continue;
for(auto ne: g[v]){
ll ndist = ((dist[v] + ne.k - 1) / ne.k) * ne.k;
// if(ndist % ne.k != 0) ndist += ne.k - ndist%ne.k;
ndist += ne.weight;
if(ndist < dist[ne.to]){
dist[ne.to] = ndist;
pq.push({dist[ne.to], ne.to});
}
}
}
if(dist[y] == INF) cout << -1 << endl;
else cout << dist[y] << endl;
// cout << endl;
// for(auto e: dist) cout << e << " ";
// cout << endl;
return 0;
}
| //*
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
//*/
#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
// #define int ll
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
void YES(bool t=true) {cout<<(t?"YES":"NO")<<endl;}
void Yes(bool t=true) {cout<<(t?"Yes":"No")<<endl;}
void yes(bool t=true) {cout<<(t?"yes":"no")<<endl;}
void NO(bool t=true) {cout<<(t?"NO":"YES")<<endl;}
void No(bool t=true) {cout<<(t?"No":"Yes")<<endl;}
void no(bool t=true) {cout<<(t?"no":"yes")<<endl;}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
int popcount(ll t) { return __builtin_popcountll(t); }
// int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {0, 1, 0, -1}, dy = {-1, 0, 1, 0};
// vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
struct Setup_io {
Setup_io() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cout << fixed << setprecision(25);
}
} setup_io;
const ll MOD = 1000000007;
// const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'
const int N = 100123;
using P = pair<int, pll>;
vector<vector<P>> G(N);
vl dijkstra(int s, int n){
priority_queue<pll, vector<pll>, greater<pll> > pq;
int i;
vl d(n, INF);
d[s]=0;
pq.push(make_pair(0,s));
while(!pq.empty()){
pll f=pq.top();
pq.pop();
int u=f.second;
if(d[u]<f.first){
continue;
}
ll cost = f.first;
for (i = 0; i < G[u].size(); i++) {
int v=G[u][i].first;
ll ncost;
ll k = G[u][i].second.second;
if (cost % k == 0) {
ncost = cost;
}
else {
ncost = cost / k * k + k;
}
ncost += G[u][i].second.first;
if (d[v] > ncost) {
d[v] = ncost;
pq.push(make_pair(d[v], v));
}
}
}
return d;
}
signed main() {
int n, m, x, y;
cin >> n >> m >> x >> y;
x--; y--;
rep (i, m) {
int u, v, t, k;
cin >> u >> v >> t >> k;
u--; v--;
G[u].push_back(P(v, pll(t, k)));
G[v].push_back(P(u, pll(t, k)));
}
vl d = dijkstra(x, n);
if (d[y] == INF) {
cout << -1 << endl;
}
else {
cout << d[y] << endl;
}
} |
#include <bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mem(a,b) memset(a, b, sizeof(a))
#define f first
#define s second
#define S size()
#define pb(x) push_back(x)
typedef double D;
typedef long long ll;
typedef long double ld;
const int MOD=(int)1e9+7,MAX=(int)1e5+10;
int a,b,sa,sb;
int main()
{
cin>>a>>b;
while (a) {
sa+=a%10;
a/=10;
}
while (b) {
sb+=b%10;
b/=10;
}
cout<<max(sa,sb);
}
| #include <bits/stdc++.h>
using namespace std;
template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl
using ll = long long;
const int maxn = 1e6 + 5;
int S(int x) {
if (x==0) return 0;
return x%10 + S(x/10);
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int a,b;
cin>>a>>b;
out(max(S(a),S(b)));
return 0;
}
|
#include <bits/stdc++.h>
using ull = unsigned long long int;
using ll = long long;
using ld = long double;
using pii = std::pair<int,int>;
using pll = std::pair<ll, ll>;
using vi = std::vector<int> ;
using vvi = std::vector<vi> ;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vd = std::vector<double> ;
using vvd = std::vector<vd> ;
using qi = std::queue<int> ;
using vpii = std::vector<std::pair<int, int> >;
using vpll = std::vector<pll>;
using namespace std;
#define rep(i,j) for(int (i)=0;(i)<(j);(i)++)
#define drep(i,j) for(int (i)=(j);(i) >= 0;(i)--)
template<class T1, class T2> inline void chmin(T1 &a, T2 b){if(a > b) a = b;}
template<class T1, class T2> inline void chmax(T1 &a, T2 b){if(a < b) a = b;}
template<class T> inline void pri(T a){cout << a << endl;}
template<class Z> using vec = vector<Z>;
template<class T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
inline void IN(void){
return;
}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
cin >> first;
IN(rest...);
return;
}
inline void OUT(void){
cout << endl;
return;
}
template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
cout << first << " " ;
OUT(rest...);
return;
}
const int max_n = 3 * (1e5) + 1;
const int max_m = 83 * (1e5) + 1;
int n,m,k;
ll N;
int h,w;
string S;
int a,b,c;
vi v;
int ans;
double x,y,z;
void solve()
{
int N; IN(N);
vector<vector<int>> g(N);
vector<pair<int,int>> edge(N-1);
rep(i,N-1)
{
int a,b; IN(a,b); a--;b--;
g[a].emplace_back(b);
g[b].emplace_back(a);
edge[i] = pii{a,b};
}
vll depth(N,-1);
depth[0] = 0;
queue<pair<int,int>> q;
q.push({0,-1});
while(!q.empty())
{
int curr = q.front().first;
int from = q.front().second;
// OUT(curr,from);
q.pop();
for(auto &npt : g[curr])
{
if(npt == from) continue;
depth[npt] = depth[curr] + 1;
q.push({npt,curr});
//cout << npt << " ";
}
//OUT();
}
vll s(N);
int Q; IN(Q);
rep(_,Q)
{
int t,e;
ll x;
IN(t,e,x);
e--;
int a = edge[e].first;
int b = edge[e].second;
if(depth[a] > depth[b])
{
swap(a,b);
t ^= 3;
}
if(t == 1)
{
s[0] += x;
s[b] -= x;
}
else s[b] += x;
}
q.push({0,-1});
while(!q.empty())
{
int curr = q.front().first;
int from = q.front().second;
q.pop();
for(auto & npt: g[curr])
{
if(depth[curr] > depth[npt])continue;
s[npt] += s[curr];
q.push({npt,curr});
}
}
for(auto &e : s)cout << e << endl;
}
signed main (int argc, char* argv[]) {
cin.tie(0);
ios::sync_with_stdio(false);
int cases=1;
//IN(cases);
while(cases--)solve();
//pri(ans);
//for(auto c : ans){cout << c << endl;}
//cout << fixed << setprecision(15) << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = (a), i##end = (b); i < i##end; ++i)
#define per(i, a, b) for (int i = (a) - 1, i##end = (b); i >= i##end; --i)
#define REP(i, a) rep(i, 0, a)
#define PER(i, a) rep(i, a, 0)
namespace IO {
const int MAXIOSIZE = 1 << 24 | 1;
unsigned char buf[MAXIOSIZE], *p1, *p2;
#define gc (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 24, stdin), p1 == p2) ? EOF : *p1++)
template <typename T> void read(T& x) {
x = 0; char ch = gc; bool flg = false;
for (; ch < '0' || '9' < ch; ch = gc) if (ch == '-') flg |= true;
for (; '0' <= ch && ch <= '9'; ch = gc) x = x * 10 + ch - '0';
flg ? x = -x : 0;
}
template <typename T> void out(const T& x) { if (x > 9) out(x / 10); putchar(x % 10 + '0'); }
template <typename T> inline void write(const T& x, const char& ed = ' ') { if (x < 0) putchar('-'), out(-x); else out(x); putchar(ed); }
}
typedef long long ll;
const int MAXN = 100 + 10;
int n;
ll X, a[MAXN], f[MAXN][MAXN], ans = LONG_LONG_MAX;
void chkmax(ll& a, ll b) { a < b ? a = b : 0; }
int main() {
#ifdef LOCAL
freopen("in.txt", "r", stdin);
#endif
IO::read(n), IO::read(X);
REP(i, n) IO::read(a[i]);
rep(cnt, 1, n + 1) {
memset(f, -1, sizeof f); f[0][0] = 0, f[1][a[0] % cnt] = a[0];
REP(i, n - 1) per(j, cnt + 1, 1) REP(k, cnt) if (f[j][k] != -1) {
chkmax(f[j + 1][(k + a[i + 1]) % cnt], f[j][k] + a[i + 1]);
}
if (f[cnt][X % cnt] != -1) ans = min(ans, (X - f[cnt][X % cnt]) / cnt);
}
IO::write(ans);
return 0;
}
|
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
#include<cassert>
#include<set>
#include<complex>
#include<numeric>
#include<functional>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;
void array_show(int *array,int array_n,char middle=' '){
for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
if(vec_n==-1)vec_n=vec_s.size();
for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
if(vec_n==-1)vec_n=vec_s.size();
for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
int main(){
int n,m;
int i,j,k;
LL a,b,c;
vector<LL> v1,v2;
cin>>n;
for(i=0;i<n;i++){
cin>>a;
v1.push_back(a);
}
for(i=0;i<n;i++){
cin>>a;
v2.push_back(a);
}
a=0,b=0;
for(i=0;i<n;i++){
a=max(a,v1[i]);
b=max(b,a*v2[i]);
cout<<b<<endl;
}
} | #include <iostream>
#include <vector>
#include <map>
using namespace std;
using lint = long long;
void solve() {
int n;
cin >> n;
lint ans = 0, sum = 0;
map<lint, lint> cnt{{0, 1}};
for (int i = 0; i < n; ++i) {
lint x;
cin >> x;
if (i % 2) x = -x;
sum += x;
ans += cnt[sum];
++cnt[sum];
}
cout << ans << "\n";
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
solve();
return 0;
}
|
/*if ((double) ((double)(clock() - cl)/(double)CLOCKS_PER_SEC)>1.85) {break;}*/
#pragma GCC optimize ("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define double long double
#define ft first
#define sc second
#define pb push_back
#define booost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cerr.tie(0);
#define all(x) (x).begin(),(x).end()
#define file(x) freopen(string(string((x)) + ".in").c_str(), "r", stdin); freopen(string(string((x)) + ".out").c_str(), "w", stdout);
#define GG cout << " OPA " << '\n';
using namespace std;
using namespace __gnu_pbds;
typedef pair <int, int> pi;
typedef tree <pair <int, pair <int, int> >, null_type, less<pair <int, pair <int, int> > >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int N = 1e3 + 100;
const int K = 7 * 1e4;
const int P = 37;
const int INF = 1e15;
const double d_INF = 2000000000.0;
const double EPS = 1e-20;
const int MOD = 1e9 + 7;
const int LOG = 20;
const double PI = 3.14159265359;
void solve() {
int a[3];
cin >> a[0] >> a[1] >> a[2];
sort(a, a + 3);
if ((a[0] != a[1] && a[1] != a[2])) cout << 0;
else {
if (a[0] == a[1]) cout << a[2];
else cout << a[0];
}
}
main () {
int test = 1;
booost;
// cin >> test;
while (test --) {
solve();
}
}
| ///Bismillahir Rahmanir Rahim
#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 FAST ios::sync_with_stdio(0); cin.tie(0)
#define int long long
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define pi 2*acos(0.0)
#define scan(i) scanf("%lld",&i)
#define scann(i,j) scanf("%lld%lld",&i,&j)
#define print(i) printf("%lld\n",i)
#define printt(i,j) printf("%lld %lld\n",i,j)
#define loop(i,n) for(int i = 0 ; i < n ; i++)
#define loop1(i,n) for(int i = 1 ; i <= n ; i++)
#define rep(i,n) for(int i=n-1;i>=0;i--)
#define rev(v) reverse(v.begin(),v.end())
#define reset(a,b) memset(a,b,sizeof(a))
#define vect vector<int>
#define vec_it vector<int>::reverse_iterator vi
#define sorta(v) sort(v.begin(),v.end())
#define sortd(v) sort(v.begin(),v.end(),greater<>())
#define sorted(v) is_sorted(v.begin(),v.end())
#define mnv(v) *min_element(v.begin(),v.end())
#define mxv(v) *max_element(v.begin(),v.end())
#define countv(v,a) count(v.begin(),v.end(),a)
#define vplusa(v,a) v.insert(v.end(),a.begin(),a.end())
#define mapp map<int,int>
#define rmap map<int,int,greater<>>m
#define pairr pair<int,int>
#define sett set<int>
#define rset set<int,greater<>>s
#define set_it set<int>::reverse_iterator si
#define map_it map<int,int> :: reverse_iterator mi
#define setp(x) fixed<<setprecision(x)
#define digit(n) floor(log10(n)+1)
#define yes cout<<"Yes"<<endl
#define no cout<<"No"<<endl
#define ff first
#define ss second
#define mx INT_MAX
#define lmx LLONG_MAX
#define mn INT_MIN
#define lmn LLONG_MIN
#define inf 0x3f3f3f3f
#define inff 10e18
#define GCD __gcd(a,b)
#define LCM (a/GCD)*b
#define ub upper_bound
#define lb lower_bound
#define mod 1000000007
inline void normal(int &a) { a %= mod; (a < 0) && (a += mod); }
inline int modMul(int a, int b) { a %= mod, b %= mod; normal(a), normal(b); return (a*b)%mod; }
inline int modAdd(int a, int b) { a %= mod, b %= mod; normal(a), normal(b); return (a+b)%mod; }
inline int modSub(int a, int b) { a %= mod, b %= mod; normal(a), normal(b); a -= b; normal(a); return a; }
inline int modPow(int b, int p) { int r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline int modInverse(int a) { return modPow(a, mod-2); }
inline int modDiv(int a, int b) { return modMul(a, modInverse(b)); }
template <typename T> T gcd(T a,T b){return (b==0)?a:gcd(b,a%b);}
template <typename T> T lcm(T a,T b) {return a*(b/gcd(a,b));}
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // 1 2 3
typedef tree<int, null_type, greater<int>, rb_tree_tag, tree_order_statistics_node_update> reverse_ordered_set; // 3 2 1
void solve()
{
// freopen ("(input).txt" , "r", stdin) ;
string st,stt;
int low=0,high=0;
int l,r; char ch;
int n,k,t,x,y,z,d=0,cnt=0,temp=0,sum=0,f=0,flag=0;
cin>>n>>k>>t ; vect v ; sett s ; mapp m,mm ; pairr p ;
if(n==k) cout<<t<<endl;
else if(n==t) cout<<k<<endl;
else if(k==t) cout<<n<<endl;
else cout<<0<<endl;
}
main()
{
int t;
// cin>>t;
// while(t--)
solve();
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define FOR(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FOR1(i, n) for(int (i)=1; (i)<=(n); (i)++)
#define FORI(i, n) for(int (i)=n-1; (i)>=0; (i)--)
template<class T, class U> void umin(T& x, const U& y){ x = min(x, (T)y);}
template<class T, class U> void umax(T& x, const U& y){ x = max(x, (T)y);}
template<class T> void print(T& v){ for(auto it : v) cout << it << " "; cout << endl; }
template<class T, class U> void init(vector<T> &v, U x, size_t n) { v=vector<T>(n, (T)x); }
template<class T, class U, typename... W> void init(vector<T> &v, U x, size_t n, W... m) { v=vector<T>(n); for(auto& a : v) init(a, x, m...); }
int main(int argc, char** argv) {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(15);
if (argc == 2 && atoi(argv[1]) == 123456789) freopen("d:\\code\\cpp\\contests\\stdin", "r", stdin);
int n;
cin >> n;
string s;
cin >> s;
if (s[0] != s[n-1]){
cout << 1 << endl;
return 0;
}
bool ok = 0;
for(int i=1; i<n-1; i++){
if (s[0] != s[i] && s[i+1] != s[n-1]){
ok = 1;
break;
}
}
if (ok)
cout << 2 << endl;
else
cout << -1 << endl;
if (argc == 2 && atoi(argv[1]) == 123456789) cout << clock()*1.0/CLOCKS_PER_SEC << " sec\n";
return 0;
}
| #include <cstdio>
#include <cstring>
#define N 100010
using namespace std;
int n;
char s[N];
int main(){
// freopen("funny.in", "r", stdin);
scanf("%d", &n);
scanf("%s", s+1);
if (s[1]!=s[n]){
printf("1\n");
}
else{
bool pd=0;
for (int i=2; i<=n; i++){
if (s[i]!=s[1] && s[i-1]!=s[1]) pd=1;
}
if (pd) printf("2\n");
else printf("-1\n");
}
return 0;
} |
#include <bits/stdc++.h>
int main() {
long long int S, P;
std::cin >> S >> P;
long long int max = std::sqrt(P) + 1;
bool flag = false;
for (long long int i = 1; i < max; i ++) {
if (P % i == 0 && (S - i) * i == P) {
flag = true;
break;
}
}
if (flag) {
std::cout << "Yes" << std::endl;
} else {
std::cout << "No" << std::endl;
}
}
| #include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define fast ios_base::sync_with_stdio(0);cin.tie(0)
#define f0(a,b,c) for(int a=b;a<c;a++)
#define re(a,b,c) for(int a=b;a>=c;a--)
#define trav(a,x) for(auto &a:x)
#define ini(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(con) con.begin(),con.end()
#define rall(con) con.rbegin(),con.rend()
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define MOD 1000000007
#define pi pair<int,int>
#define pll pair<ll,ll>
#define mi map<int,int>
#define mll map<ll,ll>
#define umi unordered_map<int,int>
#define umll unordered_map<ll,ll>
#define lb lower_bound
#define ub upper_bound
#define pq priority_queue<ll,ll>
#define st stack<int>
#define qu queue<int>
#define endl "\n"
#define sz(a) (int)a.size()
using ull = unsigned long long;
template<class T> int chkmax(T &a, T b) {
if (b > a) {
a = b;
return 1;
}
return 0;
}
template<class T> int chkmin(T &a, T b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
template<class iterator> void output(iterator begin, iterator end, ostream& out = cerr) {
while (begin != end) {
out << (*begin) << " ";
begin++;
}
out << endl;
}
template<class T> void output(T x, ostream& out = cerr) {
output(x.begin(), x.end(), out);
}
ll powm(ll a , ll n)
{
ll res = 1;
while(n)
{
if(n & 1)
res = (res * a);
n >>= 1;
a = (a * a);
}
return res;
}
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
return (ull)rng() % B;
}
ll add(ll x, ll y) {
x += y;
if (x >= MOD) return x - MOD;
return x;
}
ll sub(ll x, ll y) {
x -= y;
if (x < 0) return x + MOD;
return x;
}
ll mult(ll x, ll y) {
return (x * y) % MOD;
}
ll bin_pow(ll x, ll p) {
if (p == 0) return 1;
if (p & 1) return mult(x, bin_pow(x, p - 1));
return bin_pow(mult(x, x), p / 2);
}
ll rev(ll x) {
return bin_pow(x, MOD - 2);
}
int main()
{
fast;
int t=1;
//cin>>t;
while(t--)
{
ll s,p;
cin>>s>>p;
ll x=p;
vll v;
v.pb(1);
for(ll i=2;i*i<=p;i++)
{
if(p%i==0)
{
v.pb(i);
v.pb(p/i);
}
}
v.pb(p);
f0(i,0,sz(v))
{
f0(j,i,sz(v))
{
if(v[i]+v[j]==s and v[i]*v[j]==p)
{
cout<<"Yes";
return 0;
}
}
}
cout<<"No"<<endl;
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll merge_cnt(vector<int> &a) {
int n = a.size();
if (n <= 1) { return 0; }
ll cnt = 0;
vector<int> b(a.begin(), a.begin()+n/2);
vector<int> c(a.begin()+n/2, a.end());
cnt += merge_cnt(b);
cnt += merge_cnt(c);
int ai = 0, bi = 0, ci = 0;
// merge の処理
while (ai < n) {
if ( bi < b.size() && (ci == c.size() || b[bi] <= c[ci]) ) {
a[ai++] = b[bi++];
} else {
cnt += n / 2 - bi;
a[ai++] = c[ci++];
}
}
return cnt;
}
int main() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
vector<int> a_cp = a;
ll cnt = merge_cnt(a_cp);
vector<ll> ans(n);
ans[0] = cnt;
for (int i = 0; i < n; i++) {
// cout << cnt << endl;
int p = a[n-i-1];
// cout << cnt << endl;
cnt = cnt + p - (n - 1 - p);
if (i < n - 1) ans[n-i-1] = cnt;
}
for (auto an: ans) cout << an << endl;
return 0;
} | #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 4000000000000000000 //オーバーフローに注意
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;
#define NUM 300005
ll first_N;
ll uniformity[6*NUM],partial[6*NUM];
ll N = 1;
ll A[NUM];
ll BIT[NUM];
void bitadd(ll loc,ll value){
BIT[loc] += value;
loc += loc & -loc; //最後の1ビットを足した場所が次の★更新★場所
while(loc <= first_N){
BIT[loc] += value;
loc += loc & -loc;
}
}
ll BITSum(ll loc){
ll sum = BIT[loc];
loc -= loc & -loc; //最後の1ビットを引いた場所が次の★加算★場所
while(loc > 0){
sum += BIT[loc];
loc -= loc & -loc;
}
return sum;
}
void init(){
while(N < first_N)N *= 2;
}
void add(ll left,ll right,ll value,ll node_id,ll node_left,ll node_right){
if(right <= node_left || left >= node_right)return;
else if(left <= node_left && right >= node_right){
uniformity[node_id] += value;
}else{
partial[node_id] += (min(right,node_right)-max(left,node_left))*value;
add(left,right,value,2*node_id+1,node_left,(node_left+node_right)/2);
add(left,right,value,2*node_id+2,(node_left+node_right)/2,node_right);
}
}
ll getSum(ll left,ll right,ll node_id,ll node_left,ll node_right){
if(right <= node_left || left >= node_right)return 0;
else if(left <= node_left && right >= node_right){
return (node_right-node_left)*uniformity[node_id]+partial[node_id];
}else{
ll sum = (min(right,node_right)-max(left,node_left))*uniformity[node_id];
sum += getSum(left,right,2*node_id+1,node_left,(node_left+node_right)/2);
sum += getSum(left,right,2*node_id+2,(node_left+node_right)/2,node_right);
return sum;
}
}
int main(){
scanf("%lld",&first_N);
for(ll i = 0; i < first_N; i++){
scanf("%lld",&A[i]); //1~first_N
A[i]++;
}
for(ll i = 0; i <= first_N; i++){
BIT[i] = 0;
}
init();
for(ll i = 0; i <= 2*N-2; i++){
uniformity[i] = 0;
partial[i] = 0;
}
ll ans = 0;
for(ll i = 0; i < first_N; i++){
ll tmp = i-BITSum(A[i]);
ans += tmp;
bitadd(A[i],1);
add(A[i],A[i]+1,tmp,0,0,N);
}
printf("%lld\n",ans);
int head = 0;
for(ll loop = 0; loop < first_N-1; loop++){
ll tmp = first_N-(A[head]); //A[head]より大きい数の個数
ll minus = getSum(A[head],A[head]+1,0,0,N);
//printf("A[head]:%lld loop:%lld tmp:%lld minus:%lld\n",A[head],loop,tmp,minus);
add(A[head],A[head]+1,-minus+tmp,0,0,N); //
if(A[head] >= 2){
add(1,A[head],-1,0,0,N);
}
printf("%lld\n",getSum(1,first_N+1,0,0,N));
head++;
}
return 0;
}
|
#define _GLIBCXX_DEBUG
#include <iostream>
#include <iomanip>
#include <cctype>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main() {
ios::sync_with_stdio(false);
vector<int> a(4); rep(i, 4) cin >> a[i];
int Min=100;
rep(i, 4) Min = min(Min, a[i]);
cout << Min << "\n";
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int a,b,c,d;
cin>>a>>b>>c>>d;
int x=min({a,b,c,d});
cout<<x<<endl;
} |
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#define itn int
#define ll long long
using namespace std;
ll read(){
ll a=0,b=1;char c=getchar();
while(c>'9'||c<'0'){if(c=='-')b=-1;c=getchar();}
while(c>='0'&&c<='9')a=a*10+c-48,c=getchar();
return a*b;
}
const long double eps=1e-14;
int main(){
long double x,y,rr;
cin>>x>>y>>rr;rr+=eps;
ll anss=0;
for(int i=x-rr-1;i<=x+rr+1;i++){
long double p=rr*rr-(x-i)*(x-i);
if(p<0.0)continue;
long double dy=sqrt(p+eps);
anss+=(floor(y+dy)-ceil(y-dy)+1);
}
cout<<anss<<'\n';
return 0;
} | #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using pl = pair<ll, ll>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define fore(i_in,a) for (auto& i_in: a)
#define forp(x,y,a) for(auto& [x, y]: a)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pq(T) priority_queue<T, vector<T>, greater<T>>
#define fio() cin.tie(nullptr);ios::sync_with_stdio(false);
#define ofst_FLR(a, b) (a-1)/b;
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<(int)v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
template<class T> bool chmax(T &a, const T &b) {if (a<b) { a = b; return true; } return 0;}
template<class T> bool chmin(T &a, const T &b) {if (a>b) { a = b; return true; } return 0;}
template<class T> void print(const T &t) { cout << t << "\n"; }
int main() {
fio(); long double x,y,r; cin>>x>>y>>r;
r+=1e-14;
ll ans = 0;
ll start = ceil(x-r), end = floor(x+r);
for(ll i=start; i<=end; i++) {
long double p = sqrt(pow(r,2)-pow(x-i,2));
ll bottom = ceil(y-p), top = floor(y+p);
ans += top - bottom + 1;
}
print(ans);
}
|
#include<bits/stdc++.h>
using namespace std ;
int main(){
int N ;
cin >> N ;
for(int i = 0 ; i < N ; i++) cout << (2*i + 1 )%N + 1<< " " << (2*i + 2)%N + 1 << endl;
} | ///Bismillahir Rahmanir Rahim
#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 FAST ios::sync_with_stdio(0); cin.tie(0)
#define int long long
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define pi 2*acos(0.0)
#define scan(i) scanf("%lld",&i)
#define scann(i,j) scanf("%lld%lld",&i,&j)
#define print(i) printf("%lld\n",i)
#define printt(i,j) printf("%lld %lld\n",i,j)
#define loop(i,n) for(int i = 0 ; i < n ; i++)
#define loop1(i,n) for(int i = 1 ; i <= n ; i++)
#define rep(i,n) for(int i=n-1;i>=0;i--)
#define rev(v) reverse(v.begin(),v.end())
#define reset(a,b) memset(a,b,sizeof(a))
#define vect vector<int>
#define vec_it vector<int>::reverse_iterator vi
#define sorta(v) sort(v.begin(),v.end())
#define sortd(v) sort(v.begin(),v.end(),greater<>())
#define sorted(v) is_sorted(v.begin(),v.end())
#define mnv(v) *min_element(v.begin(),v.end())
#define mxv(v) *max_element(v.begin(),v.end())
#define countv(v,a) count(v.begin(),v.end(),a)
#define vplusa(v,a) v.insert(v.end(),a.begin(),a.end())
#define mapp map<int,int>
#define rmap map<int,int,greater<>>m
#define pairr pair<int,int>
#define sett set<int>
#define rset set<int,greater<>>s
#define set_it set<int>::reverse_iterator si
#define map_it map<int,int> :: reverse_iterator mi
#define setp(x) fixed<<setprecision(x)
#define digit(n) floor(log10(n)+1)
#define yes cout<<"Yes"<<endl
#define no cout<<"No"<<endl
#define ff first
#define ss second
#define mx INT_MAX
#define lmx LLONG_MAX
#define mn INT_MIN
#define lmn LLONG_MIN
#define inf 0x3f3f3f3f
#define inff 10e18
#define GCD __gcd(a,b)
#define LCM (a/GCD)*b
#define ub upper_bound
#define lb lower_bound
#define mod 1000000007
inline void normal(int &a) { a %= mod; (a < 0) && (a += mod); }
inline int modMul(int a, int b) { a %= mod, b %= mod; normal(a), normal(b); return (a*b)%mod; }
inline int modAdd(int a, int b) { a %= mod, b %= mod; normal(a), normal(b); return (a+b)%mod; }
inline int modSub(int a, int b) { a %= mod, b %= mod; normal(a), normal(b); a -= b; normal(a); return a; }
inline int modPow(int b, int p) { int r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline int modInverse(int a) { return modPow(a, mod-2); }
inline int modDiv(int a, int b) { return modMul(a, modInverse(b)); }
template <typename T> T gcd(T a,T b){return (b==0)?a:gcd(b,a%b);}
template <typename T> T lcm(T a,T b) {return a*(b/gcd(a,b));}
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // 1 2 3
typedef tree<int, null_type, greater<int>, rb_tree_tag, tree_order_statistics_node_update> reverse_ordered_set; // 3 2 1
void solve()
{
// freopen ("(input).txt" , "r", stdin) ;
string st,stt;
int low=0,high=0;
int l,r; char ch;
int n,k,t,x,y,z,d=0,cnt=0,temp=0,sum=0,f=0,flag=0;
cin>>n ; vect v ; sett s ; mapp m,mm ; pairr p ;
loop(i,n)
{
cin>>x;
if(x>10) sum+=x-10;
}
cout<<sum<<endl;
}
main()
{
int t;
// cin>>t;
// while(t--)
solve();
}
|
#line 1 "main_d.cpp"
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstdint>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <utility>
#include <limits>
#include <list>
#include <type_traits>
/* template start */
using i64=std::int_fast64_t;
using u64=std::uint_fast64_t;
#define rep(i, a, b) for (i64 i = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()
#ifdef LOCAL
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
void debug_out(){std::cerr<<std::endl;}
template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
std::cerr<<" "<<h;
if(sizeof...(t)>0)std::cout<<" :";
debug_out(t...);
}
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
return os << pa.first << " " << pa.second;
}
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
return os;
}
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
template<typename Num>
constexpr Num mypow(Num a, u64 b,Num id=1) {
if(b==0)return id;
Num x = id;
while (b > 0) {
if(b & 1)x*=a;
a*=a;
b >>= 1;
}
return x;
}
/* template end */
void solve(){
i64 n;
std::cin>>n;
std::vector<i64> a(n);
for(auto&& e:a)std::cin>>e;
if(n%2==0){
std::sort(all(a));
bool firstwin=false;
rep(i,0,n/2){
if(a[2*i] < a[2*i+1])firstwin=true;
}
if(firstwin)std::cout<<"First\n";
else std::cout<<"Second\n";
return;
}else{
std::cout<<"Second\n";
return;
}
}
int main() {
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
i64 test;
std::cin>>test;
while(test--)solve();
return 0;
}
| #include<bits/stdc++.h>
#define int ll
#define sz(x) int((x).size())
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define x first
#define y second
using namespace std;
using ll = long long;
using pi = pair<int,int>;
const int inf = 0x3f3f3f3f3f3f3f3f;
const int minf = 0xc0c0c0c0c0c0c0c0;
int A[100100];
signed main() {
ios::sync_with_stdio(0); cin.tie(0);
int n; cin>>n;
for (int i=1; i<=n; i++) cin>>A[i];
sort(A+1, A+n+1);
int res = 1;
const int mod = 1e9+7;
for (int i=1; i<=n; i++) {
res = res*(A[i]-A[i-1]+1)%mod;
}
cout<<res<<'\n';
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,n) for(ll i=0;i<n;i++)
#define loopn(i,j,n) for(ll i=j;i<n;i++)
#define m_arr(arr, n) vector<ll>arr(n)
#define m_arre(arr) vector<ll>arr
#define m_set(sat) set<ll>sat
#define ppn(name) pair<ll,ll>name
#define pp pair<ll,ll>
#define sort_all(arr) sort(arr.begin(), arr.end())
#define pi 3.141592653589793238
#define mod 1000000007
#define inf 1000000000000000007
ll gcd(ll a, ll b){if(a==0)return b;if(b==0)return a;return gcd(b%a, a);}
ll power(ll a, ll b)
{
ll res=1;
while(b>0)
{
if(b%2!=0)
res = (res*1ll*a);
b/=2;
a=(a*1ll*a);
}
return res;
}
void solve()
{
ll n;
cin>>n;
m_arr(arr, n+1);
for(ll i=0;i<32;i++)
{
ll x = (1<<i);
if(x<=n)
arr[x]=1;
else
break;
}
loopn(i,1,n+1)
{
arr[i]=arr[i-1]+arr[i];
}
loopn(i, 1, n+1)cout<<arr[i]<<" ";cout<<endl;
return;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//ll t;cin>>t;while(1)
solve();
return 0;
}
| #pragma region RegionDefs
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,l,r) for(int i=(l),i##_len=(r);i<i##_len;++i)
#define repr(i,l,r) for(int i=(r)-1,i##_left=(l);i>=i##_left;--i)
#define all(x) begin(x),end(x)
using namespace std;
typedef long long ll;
const ll INF = 1e9;
template<class T=ll> using V = vector<T>;
template<class T=ll> using PQ = priority_queue<T>;
template<class T=ll> using PQG = priority_queue<T, V<T>, greater<T>>;
const ll MOD = 1000000007LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail) { cin >> head; in(move(tail)...); }
#define IN(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define TIN(T, ...) T __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
#define VIND(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem,--_elem
#define OUT(x) cout << (x);
#define OUTL(x) cout << (x) << endl;
template<class T>bool chmax(T &a, const T &b) {if (a<b) {a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if (a>b) {a=b; return 1;} return 0;}
template<class T>
string join(vector<T>& v, string delim="") { ostringstream os; rep(i,v.size())i?os<<delim<<v[i]:os<<v[0]; return os.str(); }
#pragma endregion RegionDefs
void solve()
{
IN(n, d, h);
double ans = 0;
rep(i, n) {
IN(x, y);
chmax(ans, (double)(y * d - x * h) / (d - x));
}
OUTL(ans);
}
int main()
{
cin.tie(0); cout.tie(0);
ios::sync_with_stdio(false);
cout << setprecision(numeric_limits<double>::max_digits10);
solve();
return 0;
} |
/*
/> フ
| _ _|
/`ミ _x 彡
/ |
/ ヽ ?
/ ̄| | | |
| ( ̄ヽ__ヽ_)_)
\二つ
*/
#pragma GCC optimize("Ofast","inline","-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define pf push_front
#define F first
#define S second
#define SS stringstream
#define sqr(x) ((x)*(x))
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define CC(x) cout << (x) << endl
#define AL(x) x.begin(),x.end()
#define pw(x) (1ull<<(x))
#define NMSL cout << "NMSL" << endl;
#define debug(x) cout << #x << ": " << x << endl;
#define debug2(x, y) cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl;
#define debug3(x, y, z) cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define debug4(a, b, c, d) cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define fio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define in128 __int128_t
using namespace std;
const int N = 2e6+10;
const int INF = numeric_limits<int>::max() / 4;
const double EPS = 1e-3;
const long double PI = 3.14159265358979323846;
const int mod = 998244353 ;
int fac[N],inv[N];
int n,m;
int ppow(int a,int b=mod-2)
{
int ans=1%mod;
a%=mod;
while(b)
{
if(b&1)
ans=ans*a%mod;
a=a*a%mod;
b>>=1;
}
return ans;
}
void init()
{
fac[0]=1;
for(int i=1; i<N; ++i)
fac[i]=fac[i-1]*i%mod;
inv[N-1]=ppow(fac[N-1]);
for(int i=N-2; i>=0; --i)
inv[i]=(i+1)*inv[i+1]%mod;
}
int C(int n,int m)
{
if(m<0||m>n)return 0;
return fac[n]*inv[m]%mod*inv[n-m]%mod;
}
signed main()
{
fio
init();
cin>>n>>m;
int ans=0;
for(int i=1; i<=m; ++i)
{
int x=i,sum=1;
vector<int>temp;
for(int j=2; j*j<=x; ++j)
{
int cnt=0;
while(x%j==0)
{
x/=j;
cnt++;
}
if(cnt)
temp.push_back(cnt);
}
if(x>1)temp.push_back(1);
for(int b : temp)
sum=sum*C(n+b-1,b)%mod;
ans=(ans+sum)%mod;
}cout<<ans;
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 1e6+1;
const int neginf = -1*1e8;
int main(){
vector<ll> arr(maxn+1, 0);
ll l, r; cin>>l>>r;
for(ll i = 2; i <= r; i++){
if(arr[i]!=0)continue;
for(ll j = i; j<= r; j+= i)arr[j]++;
for(ll j = i*i; j<= r; j+= i*i) arr[j] = neginf;
}
ll ans = 0;
for(int i = 2; i<= r; i++){
if(arr[i]<0) continue;
ll num = (r/i) - ((l-1)/i);
ll temp = (num*(num-1))/2;
if(arr[i]%2) ans += temp; // odd number of prime factors are included
else ans -= temp; // even number of prime factors are excluded
}
for(int i = max(2ll, l); i<=r; i++) ans -= ((r/i)-1);
cout<<ans*2;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
// int gc(int n){
// if(n<1){
// return 0;
// }
// return n+gc(n-1);
// }
int main()
{
int n;
cin>>n;
// int hi=n;
// int lo=1;
// int mid;
// while(hi-lo>1){
// mid=(hi+lo)/2;
// if(gc(mid)<n) lo=mid+1;
// else hi=mid;
// }
// if(gc(lo)>=n){
// cout<<lo;
// }
// else cout<<hi;
// // cout<<gc(n);
int sum=0;
int i=1;
while(1){
sum=sum+i;
if(sum>=n){
cout<<i;
break;
}
i++;
}
return 0;
}
| // youngjinp20
// 2021 06
#include<stdio.h>
#include<iostream>
#include<vector>
#include<stack>
#include<queue>
#include<algorithm>
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; }
#define byr(x) [](const auto& a, const auto& b) { return a.x > b.x; }
#define smax(a, b) ((a) < (b) ? ((a)=(b), true) : false)
#define smin(a, b) ((a) > (b) ? ((a)=(b), true) : false)
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using namespace std;
typedef long long ll;
int main() {
int N;
cin >> N;
int i=0;
int ct=0;
for (; N > ct; ct += ++i);
cout << i;
return 0;
}
|
#include<cstdio>
#include<iostream>
using namespace std;
const int N=4e5+5;
char a[N];
const int sum='B'+'W'+'R';
inline char ch(char x,char y)
{
if(x==y)return x;
return sum-x-y;
}
int main()
{
int n;cin>>n>>a+1;
for(int i=177147;i;i/=3)
{
if(n<=i)continue;
for(int j=1;j<=n-i;++j)
a[j]=ch(a[j],a[j+i]);
n-=i;
if(n<=i)continue;
for(int j=1;j<=n-i;++j)
a[j]=ch(a[j],a[j+i]);
n-=i;
}
for(;n>1;n--)
for(int i=1;i<n;++i)
a[i]=ch(a[i],a[i+1]);
cout<<a[1];
return 0;
} | #include <iostream>
#include <vector>
using namespace std;
#include <iostream>
#include <cassert>
template<long long mod>
class modint{
private:
using T = long long;
T a;
public:
constexpr modint(const long long x = 0) noexcept : a((x%mod+mod)%mod) {}
constexpr T& value() noexcept { return a; }
constexpr const T& value() const noexcept { return a; }
constexpr modint operator-() const noexcept {
return modint(0) -= *this;
}
constexpr modint operator+(const modint& rhs) const noexcept {
return modint(*this) += rhs;
}
constexpr modint operator-(const modint& rhs) const noexcept {
return modint(*this) -= rhs;
}
constexpr modint operator*(const modint& rhs) const noexcept {
return modint(*this) *= rhs;
}
constexpr modint operator/(const modint& rhs) const noexcept {
return modint(*this) /= rhs;
}
constexpr modint& operator+=(const modint& rhs) noexcept {
a += rhs.a;
if(a >= mod) a -= mod;
return *this;
}
constexpr modint &operator-=(const modint& rhs) noexcept {
if(a < rhs.a) a += mod;
a -= rhs.a;
return *this;
}
constexpr modint& operator*=(const modint& rhs) noexcept {
a = a*rhs.a%mod;
return *this;
}
constexpr modint& operator/=(const modint& rhs) noexcept {
return *this *= rhs.inv();
}
constexpr bool operator==(const modint& rhs) const noexcept {
return a == rhs.a;
}
constexpr bool operator!=(const modint& rhs) const noexcept {
return not (*this == rhs);
}
constexpr modint pow(long long k) const noexcept {
modint ret(1);
modint x = k > 0 ? *this : this->inv();
k = abs(k);
while(k > 0){
if(k&1) ret *= x;
x *= x;
k >>= 1;
}
return ret;
}
constexpr modint inv() const noexcept {
return pow(mod-2);
}
friend std::ostream& operator<<(std::ostream &os, const modint &X) noexcept {
return os << X.a;
}
friend std::istream& operator>>(std::istream &is, modint &X) noexcept {
is >> X.a;
X.a %= mod;
if(X.a < 0) X.a += mod;
return is;
}
};
int main(){
using mint = modint<3>;
int n;
string c;
cin >> n >> c;
string C = "BWR";
vector<vector<mint>> T(3,vector<mint>(3));
for(int i = 0; i < 3; ++i){
T[i][0] = 1;
T[i][i] = 1;
}
for(int i = 1; i < 3; ++i){
for(int j = 1; j < i; ++j){
T[i][j] = T[i-1][j] + T[i-1][j-1];
}
}
auto comb = [&](int x, int y){
mint ret = 1;
while(x > 0 or y > 0){
int a = x%3, b = y%3;
ret *= T[a][b];
x /= 3;
y /= 3;
}
return ret;
};
mint t = 0;
for(int i = 0; i < n; ++i){
int a = C.find(c[i]);
t += comb(n-1,i)*a;
}
for(int i = 0; i+1 < n; ++i)
t *= 2;
cout << C[t.value()] << endl;
}
|
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <string>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <ctime>
#include <cassert>
#include <fstream>
#include <stack>
#include <random>
#include <iomanip>
#include <fstream>
using namespace std;
typedef long long ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
ll c=a%i_7;
if(c>=0)return c;
return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E18;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
dd EPS=1E-9;
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define N 100000
struct edge{ll to,cost,k; };
vector<edge> G[N+1];
ll d[N+1];
void dijkstra(ll s){
fill(d,d+(N+1),inf);
d[s]=0;
priority_queue<l_l,vector<l_l>,greater<l_l>> que;
que.push(l_l(0,s));
while(!que.empty()){
l_l p=que.top();que.pop();
ll v=p.second;
if(d[v]<p.first)continue;
if(G[v].size()>0){
rep(i,0,G[v].size()-1){
edge e=G[v][i];
ll k=e.k;
ll time= k*((d[v]+k-1)/k) + e.cost;
if(d[e.to]>time){
d[e.to]=time;
que.push(l_l(d[e.to],e.to));
}
}
}
}
}
int main(){fastio
ll n,m,x,y;cin>>n>>m>>x>>y;
ll a[m],b[m],t[m],k[m];
rep(i,0,m-1)cin>>a[i]>>b[i]>>t[i]>>k[i];
rep(i,0,m-1){
edge e;
e.to=b[i];
e.cost=t[i];
e.k=k[i];
G[a[i]].pb(e);
e.to=a[i];
e.cost=t[i];
e.k=k[i];
G[b[i]].pb(e);
}
dijkstra(x);
if(d[y]>=inf){
cout<<-1<<endl;
}else{
cout<<d[y]<<endl;
}
return 0;
}
| /*#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")*/
// 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 1000000000
#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);
int n, ans = INF;
cin >> n;
for1(i,1,n) {
int a, p, x;
cin >> a >> p >> x;
if (a < x) ans = min(ans, p);
}
if (ans == INF) cout << -1;
else cout << ans;
} |
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <complex>
#include <vector>
#include <limits>
#include <iomanip>
#include <cassert>
#include <numeric>
#include <chrono>
#include <random>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define debug(x) cerr << #x << " = " << (x) << endl;
#define debug_pii(x) cerr << "(" << x.first << "," << x.second << ")";
#define rep(i, n) for(int i = 0;i < n;i++)
#define pb push_back
#define F first
#define S second
// template<typename _Ty1, typename _Ty2>
// ostream& operator<<(ostream& _os, const pair<_Ty1, _Ty2>& _p) {
// _os << '(' <<_p.first << ',' << _p.second << ')';
// return _os;
// }
//
// template<typename _Ty1, typename _Ty2>
// istream& operator>>(istream& _is, pair<_Ty1, _Ty2>& _p) {
// _is >> _p.first >> _p.second;
// return _is;
// }
void solve() {
ll t, n;
cin >> t >> n;
vector<ll> a;
for(ll i = 1;i <= 100;i++) {
a.push_back(i + t*i/100);
}
vector<ll> b;
for(int j = 1;j <= (100+t);j++) {
bool p = false;
for(ll ch : a) if(ch == j) p = true;
if(p == false) b.push_back(j);
}
int m = b.size();
ll x = ceil(n*1.0/m);
ll y = (n % m == 0) ? m-1 : ((n%m)-1);
y = b[y];
cout << (100+t)*(x-1) + y << endl;
}
// dp[i][j][ib][jb][k] // O(N^4)
// A + A*2/100 (1<=t <=50)
//
// t = 1 -> 100, 201, 302, 403, .....
// t = 2 -> 50, 101,
// t = 3 -> 34, ..
// t = 4 ->
//
// t=2
// A + 2A/100
// 1 2 ... 49 (50) 51 52 .... 100 (101) 102 151 153
//
//
// t/100 = 0
// 2t/100
//
//
// 100t/100 = t
//
// x = (1+t/100) (2 + 2t/100) ....... (100+100t/100)
// (101+t+t/100)
//
// x
// (100+t) + x
// (200+2t) + x
// (300+3t) + x
int main() {
// freopen("input.in","r",stdin);
// freopen("output.out","w",stdout);
// cout << fixed << setprecision(15);
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
}
| #include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#include <list>
#include <iterator>
using std::cout;
using std::cin;
using std::string;
using std::vector;
using std::endl;
int main()
{
double t, n;
cin >> t >> n;
double ans = (100 + t) * (n / t);
if (abs(ans - std::floor(ans) == 0)) ans--;
else ans = std::floor(ans);
cout << (long long)ans << endl;
return 0;
} |
// Problem: D - Message from Aliens
// Contest: AtCoder - ZONe Energy Programming Contest
// URL: https://atcoder.jp/contests/zone2021/tasks/zone2021_d
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define vll vector<ll>
#define all(x) (x).begin() , (x).end()
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rnd(x, y) uniform_int_distribution<ll>(x, y)(rng)
void dbg(){
cerr << endl;
}
template<typename Head , typename... Tail>
void dbg(Head h , Tail... t){
cerr << h << " ";
dbg(t...);
}
#ifdef EMBI_DEBUG
#define debug(...) cerr << "(" << #__VA_ARGS__ << "): ", dbg(__VA_ARGS__)
#else
#define debug(...)
#endif
const int max_n = 1e5 + 9;
const int mod = 1e9 + 7;
const int inf = 1e9;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a , ll b)
{
ll prod = 1;
while(b)
{
if(b&1)
prod = (prod*a)%mod;
a = (a*a)%mod;
b >>= 1;
}
return prod;
}
void solve(){
string s;
cin >> s;
int n = s.size();
deque<char> d;
int curr = 0;
for(int i = 0 ; i < n ; i++) {
if(s[i] == 'R') {
curr ^= 1;
}
else {
if(curr) {
d.push_front(s[i]);
}
else d.push_back(s[i]);
}
}
string str;
while(!d.empty()) {
if(curr) {
str += d.back();
d.pop_back();
}
else {
str += d.front();
d.pop_front();
}
}
stack<char> st;
for(auto it : str) {
if(st.empty()) {
st.push(it);
}
else {
if(st.top() == it)st.pop();
else st.push(it);
}
}
str = "";
while(!st.empty()) {
str += st.top();
st.pop();
}
reverse(all(str));
cout << str << "\n";
}
signed main(){
int t = 1;
// cin >> t;
for(int i = 1 ; i <= t ; i++){
// cout << "Case #" << i << ": ";
solve();
}
}
| #include <bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//#include <atcoder/all>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define repl(i, a) for (ll i = (ll)0; i < (ll)a; ++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll
#define fi first
#define se second
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll mod_998244353 = 998244353;
constexpr ll INF = 1LL << 60;
// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
//using lll=boost::multiprecision::cpp_int;
//using Double=boost::multiprecision::number<boost::multiprecision::cpp_dec_float<128>>;//仮数部が1024桁
template <class T>
inline bool chmin(T &a, T b)
{
if (a > b)
{
a = b;
return true;
}
return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
if (a < b)
{
a = b;
return true;
}
return false;
}
ll mypow(ll x, ll n, const ll &p = -1)
{ //x^nをmodで割った余り
if (p != -1)
{
x =(x%p+p)%p;
}
ll ret = 1;
while (n > 0)
{
if (n & 1)
{
if (p != -1)
ret = (ret * x) % p;
else
ret *= x;
}
if (p != -1)
x = (x * x) % p;
else
x *= x;
n >>= 1;
}
return ret;
}
using namespace std;
//using namespace atcoder;
void ng(){
cout<<"UNSOLVABLE\n";
exit(0);
}
void solve()
{
set<char>st;
vector<string>s(3);
rep(i,3)cin>>s[i];
rep(i,3){
rep(j,s[i].size()){
st.emplace(s[i][j]);
}
}
if(st.size()>10){
ng();
}
vector<int>v(10);
rep(i,10)v[i]=i;
bool ok=false;
do{
vector<int>used(26,-1);
int pos=0;
rep(i,3){
rep(j,s[i].size()){
if(used[s[i][j]-'a']==-1){
used[s[i][j]-'a']=v[pos++];
}
}
}
bool no=false;
ll x[3]={};
rep(i,3){
if(used[s[i][0]-'a']==0)no=true;
}
if(no)continue;
rep(i,3){
rep(j,s[i].size()){
x[i]*=10;
x[i]+=used[s[i][j]-'a'];
}
}
if(x[0]+x[1]==x[2]){
rep(i,3){
cout<<x[i]<<"\n";
}
return;
}
}while(next_permutation(all(v)));
ng();
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(15);
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;
int main() {
int a1, a2, a3;
cin >> a1 >> a2 >> a3;
if (a1 > a2) swap(a1, a2);
if (a2 > a3) swap(a2, a3);
if (a1 > a2) swap(a1, a2);
if (a2 - a1 == a3 - a2) cout << "Yes" << endl;
else cout << "No" << endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b,c;cin>>a>>b>>c;
a+=b+c;
cout<<21-a;
return 0;} |
#include <cassert>
#include <cstdint>
#include <iostream>
#include <vector>
#define REP_(i, a_, b_, a, b, ...) \
for (int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
using namespace std;
using Int = int64_t;
template <class T>
struct Matrix {
vector<vector<T>> val;
Matrix(vector<vector<T>> vec) : val(vec) {}
Matrix(int64_t n = 1, int64_t m = 1, T v = 0) : val(n, vector<T>(m, v)) {}
void init(int64_t n, int64_t m, T v = 0) { val.assign(n, vector<T>(m, v)); }
size_t size() const { return val.size(); }
vector<T> &operator[](int64_t i) { return val[i]; }
const vector<T> &operator[](int64_t i) const { return val[i]; }
};
template <class T>
Matrix<T> operator*(const Matrix<T> &A, const Matrix<T> &B) {
assert(A.size() == B[0].size());
Matrix<T> R(A.size(), B[0].size());
for (int64_t i = 0; i < A.size(); ++i)
for (int64_t j = 0; j < B[0].size(); ++j)
for (int64_t k = 0; k < B.size(); ++k) R[i][j] += A[i][k] * B[k][j];
return R;
}
template <class T>
Matrix<T> operator+(const Matrix<T> &A, const Matrix<T> &B) {
assert(A.size() == B.size() && A[0].size() == B[0].size());
Matrix<T> R(A.size(), A[0].size());
for (int64_t i = 0; i < A.size(); ++i) {
for (int64_t j = 0; j < A[0].size(); ++j) {
R[i][j] = A[i][j] + B[i][j];
}
}
return R;
}
template <class T>
Matrix<T> operator-(const Matrix<T> &A, const Matrix<T> &B) {
assert(A.size() == B.size() && A[0].size() == B[0].size());
Matrix<T> R(A.size(), A[0].size());
for (int64_t i = 0; i < A.size(); ++i) {
for (int64_t j = 0; j < A[0].size(); ++j) {
R[i][j] = A[i][j] - B[i][j];
}
}
return R;
}
template <class T>
vector<T> operator*(const Matrix<T> &A, const vector<T> &B) {
vector<T> v(A.size());
for (int64_t i = 0; i < A.size(); ++i) {
for (int64_t k = 0; k < B.size(); ++k) {
v[i] += A[i][k] * B[k];
}
}
return v;
}
template <class T>
bool operator==(const Matrix<T> &A, const Matrix<T> &B) {
assert(A.size() == B.size() && A[0].size() == B[0].size());
for (int64_t i = 0; i < A.size(); ++i) {
for (int64_t j = 0; j < A[0].size(); ++j) {
if (A[i][j] != B[i][j]) {
return false;
}
}
}
return true;
}
int main() {
Int N;
cin >> N;
vector<Int> X(N), Y(N);
REP(i, N) cin >> X[i] >> Y[i];
Int M;
cin >> M;
vector<Matrix<Int>> mats;
Matrix<Int> mat(3, 3, 0);
mat[0][0] = 1;
mat[1][1] = 1;
mat[2][2] = 1;
mats.push_back(mat);
REP(i, M) {
Int t;
cin >> t;
if (t == 1) {
Matrix<Int> A({{0, 1, 0}, {-1, 0, 0}, {0, 0, 1}});
mat = A * mat;
} else if (t == 2) {
Matrix<Int> A({{0, -1, 0}, {1, 0, 0}, {0, 0, 1}});
mat = A * mat;
} else if (t == 3) {
Int p;
cin >> p;
Matrix<Int> A({{-1, 0, 2 * p}, {0, 1, 0}, {0, 0, 1}});
mat = A * mat;
} else {
Int p;
cin >> p;
Matrix<Int> A({{1, 0, 0}, {0, -1, 2 * p}, {0, 0, 1}});
mat = A * mat;
}
mats.push_back(mat);
}
Int Q;
cin >> Q;
REP(i, Q) {
Int a, b;
cin >> a >> b;
--b;
auto res = mats[a] * vector<Int>({X[b], Y[b], 1});
cout << res[0] << " " << res[1] << endl;
}
} | #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define n_l '\n'
#ifndef ONLINE_JUDGE
#define dbg(...) cout << "[" << #__VA_ARGS__ << "]: "; cout << to_string(__VA_ARGS__) << endl
template <typename T, size_t N> int SIZE(const T (&t)[N]){ return N; } template<typename T> int SIZE(const T &t){ return t.size(); } string to_string(const string s, int x1=0, int x2=1e9){ return '"' + ((x1 < s.size()) ? s.substr(x1, x2-x1+1) : "") + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(const bool b) { return (b ? "true" : "false"); } string to_string(const char c){ return string({c}); } template<size_t N> string to_string(const bitset<N> &b, int x1=0, int x2=1e9){ string t = ""; for(int __iii__ = min(x1,SIZE(b)), __jjj__ = min(x2, SIZE(b)-1); __iii__ <= __jjj__; ++__iii__){ t += b[__iii__] + '0'; } return '"' + t + '"'; } template <typename A, typename... C> string to_string(const A (&v), int x1=0, int x2=1e9, C... coords); int l_v_l_v_l = 0, t_a_b_s = 0; template <typename A, typename B> string to_string(const pair<A, B> &p) { l_v_l_v_l++; string res = "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; l_v_l_v_l--; return res; } template <typename A, typename... C> string to_string(const A (&v), int x1, int x2, C... coords) { int rnk = rank<A>::value; string tab(t_a_b_s, ' '); string res = ""; bool first = true; if(l_v_l_v_l == 0) res += n_l; res += tab + "["; x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v)); auto l = begin(v); advance(l, x1); auto r = l; advance(r, (x2-x1) + (x2 < SIZE(v))); for (auto e = l; e != r; e = next(e)) { if (!first) { res += ", "; } first = false; l_v_l_v_l++; if(e != l){ if(rnk > 1) { res += n_l; t_a_b_s = l_v_l_v_l; }; } else{ t_a_b_s = 0; } res += to_string(*e, coords...); l_v_l_v_l--; } res += "]"; if(l_v_l_v_l == 0) res += n_l; return res; } void dbgm(){;} template<typename Heads, typename... Tails> void dbgm(Heads H, Tails... T){ cout << to_string(H) << " | "; dbgm(T...); }
#define dbgm(...) cout << "[" << #__VA_ARGS__ << "]: "; dbgm(__VA_ARGS__); cout << endl
#endif
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define forn(i,n) for(int i=0;i<n;i++)
#define for1(i,n) for(int i=1;i<=n;i++)
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef double db;
typedef vector<vi> vvi;
const ll mod=1000000007;
const ll N=200005; //check this
int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
ll powmod(ll a,ll b) {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 powb(ll a,ll b) {ll res=1;a ; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a;a=a*a;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t=1;
//cin>>t;
while(t--){
int n;cin >> n;
cout << (n%2 ? "Black" : "White");
}
}
|
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll di[4] = {1, 0, -1, 0};
const ll dj[4] = {0, 1, 0, -1};
struct Data {
ll id, x; // いまの状態id, 移動距離x
Data(ll id, ll x): id(id), x(x) {}
bool operator<(const Data& hoge) const {
return x > hoge.x;
}
};
int main() {
ll h, w, n, m;
cin >> h >> w >> n >> m;
vl dp(4*h*w, INF); // dp[id] : idの状態となる移動距離の最小値(到達不可能ならINF)
priority_queue<Data> Q;
auto push = [&](ll id, ll x) {
if(dp[id] <= x) {
return;
}
dp[id] = x;
Q.emplace(id, x);
};
auto toId = [&](ll i, ll j, ll dir) {
return 4*(i*w + j) + dir;
};
rep(i, n) {
ll a, b;
cin >> a >> b;
a--; b--;
rep(dir, 4) {
push(toId(a, b, dir), 0);
}
}
vvl board(h, vl(w));
rep(i, m) {
ll c, d;
cin >> c >> d;
c--; d--;
board[c][d] = 1;
}
// 拡張ダイクストラ法。計算量はO((V+E)*log(V))
while(!Q.empty()) {
Data hoge = Q.top();
Q.pop();
ll id = hoge.id, x = hoge.x;
if(dp[id] != x) {
continue;
}
ll i = id/4/w;
ll j = id/4%w;
ll dir = id%4;
// 向きを変えずに直進する場合
ll ni = i + di[dir];
ll nj = j + dj[dir];
if(ni < 0 || h <= ni || nj < 0 || w <= nj) {
continue;
}
if(board[ni][nj]) {
continue;
}
push(toId(ni, nj, dir), x+1);
}
ll ans = 0;
rep(i, h) {
rep(j, w) {
bool ok = false;
rep(dir, 4) {
if(dp[toId(i, j, dir)] != INF) {
ok = true;
}
}
if(ok) {
ans++;
}
}
}
out(ans);
re0;
} | #include<iostream>
#include<vector>
#include<cstring>
using namespace std;
int map[1505][1505]; //-1标记block,0暂时没有照亮的地方,1照亮的地方,2标记bulb
typedef struct node {
int x;
int y;
}NODE;
int main() {
int h, w, n, m, ans = 0;
cin >> h >> w >> n >> m;
vector<NODE> N, M;
NODE p;
memset(map, 0, sizeof(map));
for (int i = 0; i < n; i++) {
cin >> p.x >> p.y;
N.push_back(p);
map[p.x][p.y] = 2;
}
for (int i = 0; i < m; i++) {
cin >> p.x >> p.y;
M.push_back(p);
map[p.x][p.y] = -1;
}
//for (auto p : N) { //暴力遍历求解
// int x = p.x, y = p.y;
// for (int i = y - 1; i > 0; i--) {
// if (map[x][i] == -1) break;
// if (map[x][i] == 0) map[x][i] = 1;
// }
// for (int i = y + 1; i <= w; i++) {
// if (map[x][i] == -1) break;
// if (map[x][i] == 0) map[x][i] = 1;
// }
// for (int j = x - 1; j > 0; j--) {
// if (map[j][y] == -1) break;
// if (map[j][y] == 0) map[j][y] = 1;
// }
// for (int j = x + 1; j <= h; j++) {
// if (map[j][y] == -1) break;
// if (map[j][y] == 0) map[j][y] = 1;
// }
//}
int flag = 0;
for (int i = 1; i <= h; i++) {
flag = 0;
for (int j = 1; j <= w; j++) {
if (map[i][j] == 2) {
flag = 1; continue;
}
else if (map[i][j] == -1) flag = 0;
if (flag) map[i][j] = 1;
}
}
for (int i = 1; i <= h; i++) {
flag = 0;
for (int j = w; j > 0; j--) {
if (map[i][j] == 2) {
flag = 1; continue;
}
else if (map[i][j] == -1) flag = 0;
if (flag) map[i][j] = 1;
}
}
for (int j = 0; j <= w; j++) {
flag = 0;
for (int i = 0; i <= h; i++) {
if (map[i][j] == 2) {
flag = 1; continue;
}
else if (map[i][j] == -1) flag = 0;
if (flag) map[i][j] = 1;
}
}
for (int j = 0; j <= w; j++) {
flag = 0;
for (int i = h; i > 0; i--) {
if (map[i][j] == 2) {
flag = 1; continue;
}
else if (map[i][j] == -1) flag = 0;
if (flag) map[i][j] = 1;
}
}
for (int i = 1; i <= h; i++)
for (int j = 1; j <= w; j++)
if (map[i][j] > 0)
ans++;
cout << ans << endl;
return 0;
} |
#include <cstdio>
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int main() {
int n;
scanf("%d", &n);
int cnt = 0;
for (int i = 1; i <= n; i++) {
stringstream ss10;
ss10 << dec << i;
string s10 = ss10.str();
stringstream ss8;
ss8 << oct << i;
string s8 = ss8.str();
if (s10.find("7") != string::npos) {
cnt++;
} else if (s8.find("7") != string::npos) {
cnt++;
}
}
printf("%d\n", n - cnt);
return 0;
} | #include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<stdio.h>
#include<math.h>
#include<string>
#include<new>
#include<iterator>
using namespace std;
int main()
{int n;
cin>>n;
if(n==1){
cout<<"0"<<endl;
}
else{
int k=n-2;
cout<<k+1<<endl;
}
}
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#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 ALL(v) (v).begin(),(v).end()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
ll pow_mod(ll n,ll k,ll m){
ll res=1;
for(;k>0;k>>=1){
if(k&1){
res=(res*n)%m;
}
n=(n*n)%m;
}
return res;
}
ll mod_inv(ll a, ll m){
return pow_mod(a,m-2,m);
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
ll n,p;cin >> n >> p;
cout << (p-1)*pow_mod(p-2,n-1,mod)%mod << endl;
} | #include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,s,t) for(int i = (int)(s); i < (int)(t); i++)
using p = pair<int,int>;
ll func(int n, int k){
return max(0, min(k - 1, 2*n + 1 - k));
}
int main(){
int n,k;
cin >> n >> k;
ll ans = 0;
rep(i,2,2*n+1){
ans += func(n, k + i) * func(n, i);
}
cout << ans << endl;
} |
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 998244353
#define pii pair<ll,ll>
#define inf 1000000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define autoitr(x,it) for(auto it = x.rbegin(); it != x.rend(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
ll powa(ll a, ll b, ll c)
{
a%=c;
if(a<0)
a+=c;
ll res = 1;
while(b>0)
{
if(b&1)
res*=a, res%=c;
a*=a, a%=c;
b>>=1;
}
return res;
}
ll norm(ll a)
{
a%=mod;
if(a<0)
a+=mod;
return a;
}
ll add(ll a, ll b)
{
a = norm(a);
b = norm(b);
return norm(a+b);
}
ll mul(ll a, ll b)
{
a = norm(a);
b = norm(b);
return norm(a*b);
}
ll sub(ll a, ll b)
{
a = norm(a);
b = norm(b);
return norm(a-b);
}
ll divi(ll a, ll b)
{
b = powa(b,mod-2,mod);
return mul(a,b);
}
#define N 200005
ll fact[N];
ll ifact[N];
ll ncr(ll n, ll r)
{
if(r>n)
return 0;
ll ans = fact[n];
ans*=ifact[r];
ans%=mod;
ans*=ifact[n-r];
ans%=mod;
return ans;
}
#define N1 19
int main()
{
FAST/**/
fact[0] = 1;
for(ll i=1;i<N;i++)
fact[i] = fact[i-1]*i, fact[i]%=mod;
for(ll i=0;i<N;i++)
ifact[i] = powa(fact[i],mod-2,mod);
ll n,m;
cin>>n>>m;
vector<ll> div[m+1];
for(ll i=1;i<=m;i++)
{
for(ll j=i;j<=m;j+=i)
div[j].pb(i);
}
ll dp[N1][m+1];
memset(dp,0,sizeof(dp));
for(ll i=1;i<=m;i++)
{
dp[1][i] = 1;
for(ll j=2;j<N1;j++)
{
autoit(div[i], it)
{
if(*it < i)
dp[j][i]+=dp[j-1][*it], dp[j][i]%=mod;
}
}
}
ll ans = 0;
for(ll i=1;i<=m;i++)
{
for(ll j=1;j<N1;j++)
{
ans = add(ans, mul(ncr(n-1, j-1), dp[j][i]));
//cout<<"for "<<i<<" , "<<j<<" = "<<dp[j][i]<<"\n";
}
}
cout<<ans<<"\n";
return 0;
}
| #include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define mod 1000000007
#define ad(a,b) a=(a+b)%mod;
#define X 200010
ll po(ll x,ll y){
ll res=1;
for(;y;y>>=1){
if(y&1)res=res*x%mod;
x=x*x%mod;
}
return res;
}
ll gcd(ll a,ll b){
return (b?gcd(b,a%b):a);
}
ll fac[X],ivf[X];
void initfac(){
fac[0]=1;
for(ll i=1;i<X;i++)fac[i]=fac[i-1]*i%mod;
for(ll i=0;i<X;i++)ivf[i]=po(fac[i],mod-2);
}
ll C(ll n,ll k){
return fac[n]*ivf[n-k]%mod*ivf[k]%mod;
}
ll n,a[210],b[210];
vector<ll> A[210],B[210];//A[p]:=(a[i]==p)=なるiのset
bool f[210][210];
bool solve(){
cin>>n;
rep(i,n){
cin>>a[i]>>b[i];
if(a[i]>=0)a[i]--;
if(b[i]>=0)b[i]--;
if(a[i]!=-1&&b[i]!=-1&&a[i]>=b[i])return 0;
if(a[i]>=0)A[a[i]].push_back(i);
if(b[i]>=0)B[b[i]].push_back(i);
}
rep(i,2*n){
if(A[i].size()+B[i].size()>1)return 0;
}//重複なし
for(int i=0;i<=2*n;i++)for(int j=0;j<=2*n;j++)f[i][j]=0;
for(int l=0;l<2*n;l+=2){
for(int k=1;l+2*k<=2*n;k++){
int r=l+2*k;
bool ok=1;
rep(i,n){
bool va=(l<=a[i]&&a[i]<r);
bool vb=(l<=b[i]&&b[i]<r);
if(a[i]>=0&&b[i]>=0){
if(va==0&&vb==0)continue;
if(va==1&&vb==1){
ok&=(a[i]+k==b[i]);
continue;
}
ok=0;
}
else if(a[i]==-1&&b[i]==-1)continue;
else if(a[i]>=0){
if(va==0)continue;
if(not(0<=a[i]+k&&a[i]+k<2*n))ok=0;
else if(A[a[i]+k].size()+B[a[i]+k].size()>0)ok=0;
}
else if(b[i]>=0){
if(vb==0)continue;
if(not(0<=b[i]-k&&b[i]-k<2*n))ok=0;
else if(A[b[i]-k].size()+B[b[i]-k].size()>0)ok=0;
}
}
f[l][r]=ok;
//cerr<<"f["<<l<<"]["<<r<<"]="<<f[l][r]<<endl;
}
}
bool dp[210];
for(int i=0;i<=2*n;i++)dp[i]=0;
dp[0]=1;
for(int i=0;i<2*n;i++){
if(dp[i]==0)continue;
for(int j=i+1;j<=2*n;j++){
if(f[i][j]==1){
dp[j]=1;
}
}
}
return dp[2*n];
}
int main(){
cin.tie(0);
ios::sync_with_stdio(0);
cout<<(solve()?"Yes":"No")<<endl;
}
|
#include <cstdio>
const int maxn=2e5+10;
int a[maxn];
int b[maxn];
int p[maxn];
int f1[maxn];
int f2[maxn];
int ans=0;
int vis[maxn];
int mx=0;
void Dfs1(int x){
if(vis[x])
return;
vis[x]=1;
if((!mx)||a[x]>a[mx])
mx=x;
Dfs1(p[x]);
}
void Dfs2(int x){
if(x==mx)
return;
f1[++ans]=mx;
f2[ans]=x;
Dfs2(p[x]);
}
int main(){
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
for(int i=1;i<=n;i++)
scanf("%d",&b[i]);
for(int i=1;i<=n;i++)
scanf("%d",&p[i]);
for(int i=1;i<=n;i++){
if(p[i]!=i&&b[p[i]]>=a[i]){
printf("-1");
return 0;
}
}
for(int i=1;i<=n;i++)
if(!vis[i]){
mx=0;
Dfs1(i);
Dfs2(p[mx]);
}
printf("%d\n",ans);
for(int i=1;i<=ans;i++)
printf("%d %d\n",f1[i],f2[i]);
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define For(i,a,b) for(int i=a,i##_end=b;i<i##_end;++i)
using ll=long long;
using pii=pair<int,int>;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
const int mo=1e9+7;
using L=__int128;
ll Pow(ll a,ll b,ll p=mo){ll r=1;for(;b;b>>=1,a=(L)a*a%p)if(b&1)r=(L)r*a%p;return r;}
//template<typename T>
void inc(int &x,int y){x=(x+y>=mo?x+y-mo:x+y);}
int ad(int x,int y){return x+y>=mo?x+y-mo:x+y;}
template<typename T>T gcd(T a,T b){while(b)a%=b,swap(a,b);return a;}
mt19937 rnd(time(0));
const int N=2e5+11;
int n,a[N],b[N],p[N];
int vis[N];
vector<int> e[N];int m;
void GG(){puts("-1");exit(0);}
vector<pii> ans;
int main(){
#ifdef SGR
freopen("a.txt","r",stdin);
#endif
ios::sync_with_stdio(0);
cin>>n;
For(i,1,n+1)cin>>a[i];
For(i,1,n+1)cin>>b[i];
For(i,1,n+1){
cin>>p[i];
if(p[i]!=i&&a[i]<=b[p[i]])GG();
}
//int ans=0;
For(i,1,n+1)if(!vis[i]){
int x=i;
do{
e[m].pb(x);
vis[x]=1;
x=p[x];
}while(x!=i);
m++;
}
For(i,0,m){
if(e[i].size()<=1)continue;
int q=0;
for(int x:e[i])if(a[x]>a[q])q=x;
assert(q);
int x=q;
do{
if(p[x]==q)break;
ans.pb(mp(q,p[x]));
x=p[x];
}while(x!=q);
}
cout<<ans.size()<<endl;
for(auto w:ans)cout<<w.fi<<" "<<w.se<<"\n";
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
enum RideType{
a,
b,
none,
};
struct ride{
int person_id;
int other_pos;
RideType ride_type;
};
int main(){
int n;
cin >> n;
vector<ride> v(2*n+1, {-1, -1, RideType::none});
for(int i=1; i<=n; ++i){
int a, b;
cin >> a >> b;
if(a>0){
if(v[a].ride_type != RideType::none){
// 重複した入力なので NG
cout << "No" << endl;
return 0;
}
v[a]={i, b, RideType::a};
}
if(b>0){
if(v[b].ride_type != RideType::none){
// 重複した入力なので NG
cout << "No" << endl;
return 0;
}
v[b]={i, a, RideType::b};
}
}
// dp[i] = 2*i 階まで OK
vector<bool> dp(n+1, false);
dp[0]=true;
for(int i=0; i<=n; ++i){
if(!dp[i])continue;
for(int j=i+1; j<=n; ++j){
// すでに到達できるならそれはそれでいい
if(dp[j]) continue;
// 2*i+1, ..., 2*j 階まで OK か確認する
// ここが 「乗る, 乗る, ..., 乗る, 降りる, ..., 降りる」という形になるなら、幅は j-i
dp[j]=true;
for(int k=1; k<=j-i; ++k){
const auto &va = v[2*i+k];
const auto &vb = v[i+j+k];
if(va.ride_type == RideType::a && vb.ride_type == RideType::b){
// 乗る人と降りる人が同じか確認
if(va.person_id != vb.person_id){
dp[j]=false;
break;
}
}else if(va.ride_type == RideType::a && vb.ride_type == RideType::none){
// 乗る人が別の場所で降りないか確認
if(va.other_pos != -1){
dp[j]=false;
break;
}
}else if(va.ride_type == RideType::none && vb.ride_type == RideType::b){
// 降りる人が別の場所で乗らないか確認
if(vb.other_pos != -1){
dp[j]=false;
break;
}
}else if(va.ride_type == RideType::none && vb.ride_type == RideType::none){
// 両方 none なら適切に assign できる
continue;
}else{
// a, b を混同しているパターンは NG
dp[j]=false;
break;
}
}
}
}
cout << (dp[n]?"Yes":"No") << endl;
return 0;
} | #include <bits/stdc++.h>
//#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 namespace boost::multiprecision;
//using namespace __gnu_pbds;
int main(){
//using namespace std;
int n;
cin>>n;
int a[n], b[n];
REP(i, n) cin>>a[i]>>b[i];
//記録がおかしいケースを排除
vector<int> cnt(2 * n + 1);
REP(i, n){
if(a[i] >= 0 && b[i] >= 0 && a[i] >= b[i]){
cout << "No" << endl;
return 0;
}
if(a[i] >= 0){
cnt[a[i]]++;
if(cnt[a[i]] > 1){
cout << "No" << endl;
return 0;
}
}
if(b[i] >= 0){
cnt[b[i]]++;
if(cnt[b[i]] > 1){
cout << "No" << endl;
return 0;
}
}
}
vector<int> c(2 * n + 1, -1); //その階で取るべきcの値
REP(i, n){
if(a[i] >= 0 && b[i] >= 0){
int tc = b[i] - a[i] - 1;
for(int j = a[i]; j <= b[i]; j++){
if(c[j] < 0){
c[j] = tc;
continue;
}
if(c[j] == tc) continue;
cout << "No" << endl;
return 0;
}
}
}
REP(i, n){
if(a[i] >= 0 && b[i] >= 0) continue;
if(a[i] < 0 && b[i] < 0) continue;
if(a[i] < 0){
if(c[b[i]] < 0) continue;
int ta = b[i] - c[b[i]] - 1;
if(cnt[ta] < 1){
a[i] = ta;
cnt[a[i]]++;
continue;
}
cout << "No" << endl;
return 0;
}else{
if(c[a[i]] < 0) continue;
int tb = c[a[i]] + a[i] + 1;
if(cnt[tb] < 1){
b[i] = tb;
cnt[b[i]]++;
continue;
}
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
return 0;
} |
#include <stdio.h>
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(void){
int cnt = 0;
int a[1010],n;
int same=0;
cin >> n;
rep(i,n) cin >> a[i];
sort(a,a+n);
rep(j,n){
if(same == a[j]) {
cout << "No" << endl;
return 0;
}else{
same = a[j];
}
}
cout << "Yes" << endl;
return 0;
}
| #include<bits/stdc++.h>
#include<tuple>
typedef long long ll;
#define INF 9999999999
#define mod 998244353
#define eps 1e-12
using namespace std;
typedef tuple<ll,ll,ll,ll>tu;
ll n;
string s,t;
vector<ll>a,b;
int main(){
ll i,j;
ios::sync_with_stdio(0);
cin>>n;
cin>>s>>t;
for(ll i=0;i<s.size();i++)
if(s[i]=='0')
a.push_back(i);
for(ll i=0;i<t.size();i++)
if(t[i]=='0')
b.push_back(i);
if(a.size()!=b.size())
cout<<-1<<endl;
else{
ll ans=0;
for(ll i=0;i<a.size();i++)
if(a[i]!=b[i])
ans++;
cout<<ans<<endl;
}
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 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 rep(i,a,b) for(int i=a;i<b;i++)
#define mem1(a) memset(a,-1,sizeof(a))
#define mem0(a) memset(a,0,sizeof(a))
#define ppc __builtin_popcount
#define ppcll __builtin_popcountll
template<typename T1,typename T2>istream& operator>>(istream& in,pair<T1,T2> &a){in>>a.fr>>a.sc;return in;}
template<typename T1,typename T2>ostream& operator<<(ostream& out,pair<T1,T2> a){out<<a.fr<<" "<<a.sc;return out;}
template<typename T,typename T1>T amax(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T amin(T &a,T1 b){if(b<a)a=b;return a;}
const long long INF=1e18;
const int32_t M=1e9+7;
const int32_t MM=998244353;
const int N=1e5+5;
#define SIEVE
int primes[N];
vector<int> pr;
void sieve(){
for(int i=2;i<N;i++){
if(primes[i]==0){
pr.pb(i);
for(int j=i*i;j<N;j+=i){
primes[j]=1;
}
}
primes[i]^=1;
}
}
int fact(int n)
{
if (n==1 || n==0)
{
return 1;
}
int res = 1;
for (int i = 2; i <= n; i++)
res = res * i;
return res;
}
int nCr(int n, int r)
{
if (n==0 || r>n)
{
return 0;
}
return fact(n) / (fact(r) * fact(n - r));
}
int nC2(int n) {
if (n < 2)
return 0;
assert(n < 3.0e9);
return n * (n - 1) / 2;
}
void solve()
{
int n;
cin>>n;
if (n<0)
{
cout<<0<<endl;
}
else
{
cout<<n<<endl;
}
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
#ifdef SIEVE
sieve();
#endif
#ifdef NCR
init();
#endif
int t=1;
// cin>>t;
while(t--) solve();
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
int main()
{
int x;
cin>>x;
if(x>=0){
cout<<x<<endl;
}
else{
cout<<"0"<<endl;
}
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mod 1000000007
#define endl "\n"
#define test ll txtc; cin>>txtc; while(txtc--)
typedef long long int ll;
int main() {
FIO;
ll n,m; cin>>n>>m;
vector<ll>a(n),b(m);
for(auto &it:a) cin>>it;
for(auto &it:b) cin>>it;
vector<vector<ll>>dp(n+1,vector<ll>(m+1,mod));
for(ll i=n;i>=0;i--){
for(ll j=m;j>=0;j--){
if(i==n || j==m){
dp[i][j]=(n-i)+(m-j);
}
else{
if(a[i]==b[j]){
dp[i][j]=dp[i+1][j+1];
}
else{
dp[i][j]=min({dp[i+1][j],dp[i][j+1],dp[i+1][j+1]})+1;
}
}
}
}
cout<<dp[0][0]<<endl;
return 0;
}
| #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define irep(i,a,b) for(int i=int(a);i<(int)b;++i)
#define rrep(i,a,b) for(int i=int(a);i>=(int)b;--i)
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvp vector<vector<pair<ll,ll>>>
#define vpl vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define pb push_back
#define se second
#define fi first
#define all(v) v.begin(),v.end()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
template<typename T> istream& operator>>(istream&i,v(T)&v){rep(j,v.size())i>>v[j];return i;}
template<typename T> string join(const v(T)&v){stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);}
template<typename T> ostream& operator<<(ostream&o,const v(T)&v){if(v.size())o<<join(v);return o;}
using ll = long long;
const ll INF = LLONG_MAX;
const double PI = acos(-1);
const ll mod = 1e9 + 7; //998244353;
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
ll modpow(ll a,ll b){
if(b == 0){
return 1;
}
if(b%2 == 0){
ll tmp = modpow(a,b/2);
return tmp*tmp%mod;
}else{
return modpow(a,b-1)*a%mod;
}
}
template <typename T>
struct RMQ {
const T INF = numeric_limits<T>::max();
T bound; //最小値のときはinf,それ以外の時0となる
int n;
bool flag; //最大値でtrue
vector<T> dat;
RMQ(int n_) : n(),dat(n_ * 4,-1){
int x = 1;
while(n_ > x){
x *= 2;
}
n = x;
}
T func(T a,T b){
if(a == -1)return b;
if(b == -1)return a;
return a^b;
}
void update(int i,T x){
i += n - 1;
dat[i] = x;
while(i > 0){
i = (i-1)/2;
dat[i] = func(dat[i*2+1],dat[i*2+2]);
}
}
T query(int a,int b){
return query_sub(a,b,0,0,n);
}
T query_sub(int a,int b,int k,int l,int r){
if(r <= a || b <= l){
return -1;
}else if(a <= l && r <= b){
return dat[k];
}else{
T v_l = query_sub(a, b, k * 2 + 1, l, (l + r) / 2);
T v_r = query_sub(a, b, k * 2 + 2, (l + r) / 2, r);
return func(v_l, v_r);
}
}
};
ll dp[1005][1005];
int main(void)
{
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
int n,m;
cin >> n >> m;
vl a(n),b(m);
cin >> a;
cin >> b;
rep(i,n+1){
rep(j,m+1){
if(i == 0 || j == 0){
dp[i][j] = max(i,j);
continue;
}
ll tmp = min(dp[i][j-1] + 1,dp[i-1][j] + 1);
tmp = min(tmp,dp[i-1][j-1] + (a[i-1] == b[j-1] ? 0 : 1));
dp[i][j] = tmp;
}
}
cout << dp[n][m] << endl;
return 0;
}
|
#include <stdio.h>
#include <memory.h>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
const int mod = 1000000007;
const int N = 200005;
int d[N] = { 0 }, ans[N] = { 0 }, id2 = 0, tol = 0;
bool u[N] = { 0 };
vector<int> my[N];
void dfs(int x) {
int i = 0, y = 0;
for (i = 0; i < my[x].size(); i ++) {
y = my[x][i];
if (d[y]) continue;
d[y] = d[x] + 1;
dfs(y);
}
}
void dfs2(int x) {
int i = 0, y = 0;
for (i = 0; i < my[x].size(); i ++) {
y = my[x][i];
if (d[y]) continue;
d[y] = d[x] + 1;
dfs2(y);
if (u[y]) u[x] = true;
}
if (x == id2) u[x] = true;
}
void dfs3(int x) {
ans[x] = ++ tol;
int s = 0, i = 0, y = 0;
for (i = 0; i < my[x].size(); i ++) {
y = my[x][i];
if (d[y]) continue;
if (u[y]) {
s = y;
continue;
}
d[y] = d[x] + 1;
dfs3(y);
++ tol;
}
if (s) {
d[s] = d[x] + 1;
dfs3(s);
++ tol;
}
}
void solve() {
int i = 0, n = 0, id = 0, p = 0, q = 0;
scanf("%d", &n);
for (i = 1; i < n; i ++) {
scanf("%d%d", &p, &q);
my[p].push_back(q);
my[q].push_back(p);
}
d[1] = 1;
dfs(1);
id = 1;
for (i = 2; i <= n; i ++) {
if (d[i] > d[id]) id = i;
}
memset(d, 0, sizeof(d));
d[id] = 1;
dfs(id);
id2 = 1;
for (i = 2; i <= n; i ++) {
if (d[i] > d[id2]) id2 = i;
}
memset(d, 0, sizeof(d));
memset(u, 0, sizeof(u));
d[id] = 1;
dfs2(id);
memset(d, 0, sizeof(d));
d[id] = 1;
dfs3(id);
for (i = 1; i <= n; i ++) {
printf("%d", ans[i]);
if (i < n) printf(" ");
else printf("\n");
}
}
int main() {
int o = 1;
//scanf("%d", &o);
while (o --) {
solve();
//fflush(stdout);
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;
vector<int> v[211111];
int d[211111],n;
P dfs(int x,int t) {
d[x]=t;P p=P(d[x],x);
rep(i,v[x].size())if(d[v[x][i]]==MAX)p=max(p,dfs(v[x][i],t+1));
return p;
}
P calc() {
fill(d,d+211111,MAX);P p=dfs(0,0);
fill(d,d+211111,MAX);P q=dfs(p.S,0);
return P(p.S,q.S);
}
P pp;
set<ll> s;
ll dfs2(int x,int p) {
if(x==pp.S) {
s.in(x);
return 1;
}
ll f=0;
rep(i,v[x].size()) {
ll y=v[x][i];
if(y==p) continue;
f|=dfs2(y,x);
}
if(f) s.in(x);
return f;
}
ll a[222222],k=1;
void dfs3(ll x,ll p) {
a[x]=k++;
ll z=-1;
rep(i,v[x].size()) {
ll y=v[x][i];
if(y==p) continue;
if(s.count(y)) {
z=y;
continue;
}
dfs3(y,x);
k++;
}
if(z!=-1) {
dfs3(z,x);
k++;
}
}
void Main() {
R n;
rep(i,n-1) {
ll x,y;
cin >> x >> y;
x--,y--;
v[x].pb(y);
v[y].pb(x);
}
pp=calc();
dfs2(pp.F,-1);
dfs3(pp.F,-1);
PR(a,n);
}
int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}
|
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
#define SIZE(x) ll(x.size())
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
typedef pair<ll, ll> P;
int main()
{
ll N, K;
cin >> N >> K;
vector<P> AB(N);
rep(i, N) {
ll a, b;
cin >> a >> b;
AB[i] = {a, b};
}
sort(all(AB));
ll ans = 0;
ll place = 0;
rep(i, N) {
ll diff = place + K;
if (AB[i].first <= diff) {
K -= (AB[i].first - place);
place = AB[i].first;
K += AB[i].second;
}
else {
break;
}
}
cout << place + K << endl;
return 0;
} | #include <iostream>
using namespace std;
int main() {
char S, T; cin >> S >> T;
char r = (S == 'Y') ? T + 'A' - 'a' : T;
cout << r << '\n';
cin.ignore(2); return 0;
} |
Subsets and Splits