code_file1
stringlengths 87
4k
| code_file2
stringlengths 85
4k
|
---|---|
//This Code was made by Chinese_zjc_.
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <bitset>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <set>
#include <time.h>
// #include<windows.h>
#define int long long
#define double long double
const double PI = acos(-1);
const double eps = 0.0000000001;
const int INF = 0x3fffffffffffffff;
using namespace std;
int n;
string s;
signed main()
{
ios::sync_with_stdio(false);
cin >> n >> s;
if (n < 3)
{
if (s == "1")
{
cout << 20000000000 << endl;
}
if (s == "0")
{
cout << 10000000000 << endl;
}
if (s == "11")
{
cout << 10000000000 << endl;
}
if (s == "01")
{
cout << 9999999999 << endl;
}
if (s == "10")
{
cout << 10000000000 << endl;
}
if (s == "00")
{
cout << 0 << endl;
}
return 0;
}
if (s[0] == '0')
{
s.insert(s.begin(), '1');
}
if (s[1] == '0')
{
s.insert(s.begin(), '1');
}
if (s[s.length() - 2] == '0')
{
s.push_back('1');
}
if (s[s.length() - 3] == '0')
{
s.push_back('0');
}
for (int i = 0; i < s.length(); ++i)
{
if (s[i] == '0' + (i % 3 == 2))
{
cout << 0 << endl;
return 0;
}
}
cout << 10000000001 - s.length() / 3 << endl;
return 0;
} | /*#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007LL
//#define MOD 998244353LL
#define doublecout(a) cout<<setprecision(16)<<a<<endl;
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vvvi = vector<vvi>; // intの2次元の型に vvi という別名をつける
const ll llMAX=9223372036854775807LL;
const ll llMIN=-9223372036854775808LL;
void myprint1D(vi &data)
{
REP(i,data.size())
cout<<data[i]<<" ";
cout<<endl;
}
//配列を[y][x]で表示
void myprint2D_T(vvi &data)
{
REP(i,data.size())
myprint1D(data[i]);
}
//配列を[x][y]で表示
void myprint2D(vvi &data)
{
ll l1=data.size();
ll l2=data[0].size();
REP(j,l2){
REP(i,l1)
cout<<data[i][j]<<" ";
cout<<endl;
}
}
//print(a,b...)って使い方
void print1(ll a){cout<<a<<endl;}
void print2(ll a,ll b){cout<<a<<" "<<b<<endl;}
void print3(ll a,ll b,ll c){cout<<a<<" "<<b<<" "<<c<<endl;}
void print4(ll a,ll b,ll c,ll d){cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;}
void print5(ll a,ll b,ll c,ll d,ll e){cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<e<<endl;}
ll n,k,x,y;
int main(){
ll ans=0;
cin >> n >> k;
string s;cin>>s;
vi a(n),b(n);
REP(i,n) cin>>a[i];
cout<<ans<<endl;
return 0;
}
*/
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007LL
//#define MOD 998244353LL
#define doublecout(a) cout<<setprecision(16)<<a<<endl;
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vvvi = vector<vvi>; // intの2次元の型に vvi という別名をつける
const ll llMAX=9223372036854775807LL;
const ll llMIN=-9223372036854775808LL;
void myprint1D(vi &data)
{
REP(i,data.size())
cout<<data[i]<<" ";
cout<<endl;
}
//配列を[y][x]で表示
void myprint2D_T(vvi &data)
{
REP(i,data.size())
myprint1D(data[i]);
}
//配列を[x][y]で表示
void myprint2D(vvi &data)
{
ll l1=data.size();
ll l2=data[0].size();
REP(j,l2){
REP(i,l1)
cout<<data[i][j]<<" ";
cout<<endl;
}
}
//print(a,b...)って使い方
void print1(ll a){cout<<a<<endl;}
void print2(ll a,ll b){cout<<a<<" "<<b<<endl;}
void print3(ll a,ll b,ll c){cout<<a<<" "<<b<<" "<<c<<endl;}
void print4(ll a,ll b,ll c,ll d){cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;}
void print5(ll a,ll b,ll c,ll d,ll e){cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<e<<endl;}
ll n,k,x,y;
int main(){
ll ans=0;
cin >> n;
string s,t;cin>>s;
if (s=="0"){
cout<<10000000000LL<<endl;
return 0;
}
if (s=="1"){
cout<<20000000000LL<<endl;
return 0;
}
if (s=="11"){
cout<<10000000000LL<<endl;
return 0;
}
if (s=="00"){
cout<<0<<endl;
return 0;
}
if (s=="10"){
cout<<10000000000LL<<endl;
return 0;
}
if (s=="01"){
cout<<(10000000000LL-1LL)<<endl;
return 0;
}
t="110";
string tt="";
for(ll i=0;i<n/3+3;i++){
tt+=t;
}
ll nn=(n/3+1)*3;
ll flag=-1;
if (s==tt.substr(2,n))flag=2;
if (s==tt.substr(1,n))flag=1;
if (s==tt.substr(0,n))flag=0;
if (flag==-1){
cout<<0<<endl;
return 0;
}
nn=n+flag;
cout<<((30000000000LL-nn+3)/3)<<endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int cnt[26];
int main() {
string s; cin >> s;
reverse(s.begin(), s.end());
long long ans = 0;
vector <int> all;
for (int i = 0; i < s.size(); i++) {
int j = i;
while (j < s.size() && s[i] == s[j]) j++;
if (j - i >= 2) {
ans += i - cnt[s[i] - 'a'];
memset(cnt, 0, sizeof(cnt)), cnt[s[i] - 'a'] = j;
} else cnt[s[i] - 'a']++;
i = j - 1;
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repp(i, st, en) for (ll i = (ll)st; i < (ll)(en); i++)
#define repm(i, st, en) for (ll i = (ll)st; i >= (ll)(en); i--)
#define all(v) v.begin(), v.end()
void chmax(ll &x, ll y) {x = max(x,y);}
void chmin(ll &x, ll y) {x = min(x,y);}
void Yes() {cout << "Yes" << endl; exit(0);}
void No() {cout << "No" << endl; exit(0);}
template<class in_Cout> void Cout(in_Cout x) {cout << x << endl; exit(0);}
template<class in_vec_cout>
void vec_cout(vector<in_vec_cout> vec) {
for (in_vec_cout res : vec) {cout << res << " ";}
cout << endl;
}
const ll inf = 1e18;
const ll mod = 1e9 + 7;
// 計算量 O(√N)
ll prime_cnt(ll N) {
ll res = 0;
for (ll i=2; i*i<=N; i++) {
if (N%i!=0) continue;
while (N%i==0) {
N /= i;
res++;
}
}
if (N!=1) res++;
return res;
}
int main() {
ll N; cin >> N;
for (ll i=1; i<=N; i++) {
cout << prime_cnt(i) + 1 << " ";
}
cout << endl;
} |
#include<bits/stdc++.h>
using namespace std;
int f(int x)
{
int ans=0;
while(x)
{
if(x&1)ans++;
x>>=1;
}
return ans;
}
int ksm(int a,int b)
{
int ans=1;
while(b)
{
if(b&1)ans*=a;
a*=a;
b>>=1;
}
return ans;
}
int main()
{
int n,m;
cin>>n;
m=ksm(2,n)-1;
cout<<m<<"\n";
for(int i=1;i<=m;i++)
{
for(int j=1;j<=m+1;j++)
{
if(f(i&j)&1)cout<<"A";
else cout<<"B";
}
cout<<"\n";
}
return 0;
} | #include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
typedef long long ll;
char buf[10][2000][2000];
int n;
int main(void) {
scanf("%d", &n);
buf[0][0][0] = 'A';
buf[0][0][1] = 'B';
REP(k, n-1) {
REP(i, (1<<(k+1))-1) {
REP(j, 1<<(k+1)) {
if(buf[k][i][j] == 'A') {
buf[k+1][2*i][j*2] = 'A';
buf[k+1][2*i][j*2+1] = 'A';
} else {
buf[k+1][2*i][j*2] = 'B';
buf[k+1][2*i][j*2+1] = 'B';
}
}
// cerr << "1> " << 2*i << " " << buf[k+1][2*i] << endl;
REP(j, 1<<(k+1)) {
if(buf[k][i][j] == 'A') {
buf[k+1][2*i+1][j*2] = 'A';
buf[k+1][2*i+1][j*2+1] = 'B';
} else {
buf[k+1][2*i+1][j*2] = 'B';
buf[k+1][2*i+1][j*2+1] = 'A';
}
}
// cerr << "2> " << 2*i+1 << " " << buf[k+1][2*i+1] << endl;
}
REP(j, 1<<(k+2)) {
buf[k+1][((1<<(k+1))-1)*2][j] = j % 2 ? 'B' : 'A';
}
// cerr << "3> " << ((1<<(k+1))-1)*2 << " " << buf[k+1][((1<<(k+1))-1)*2] << endl;
}
printf("%d\n", (1<<n)-1);
for(int i = 0; i < (1 << n)-1; ++i) {
puts(buf[n-1][i]);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve() {
map<char, int> ch;
string s, t, w;
cin >> s >> t >> w;
for (char c : s) ch.emplace(c, 0);
for (char c : t) ch.emplace(c, 0);
for (char c : w) ch.emplace(c, 0);
if (ch.size() > 10) {
cout << "UNSOLVABLE";
return;
}
int p[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
do {
string a, b, c;
int i = 0;
for (auto it = ch.begin(); it != ch.end(); ++it, i++)
it->second = p[i];
for (char x : s) a.push_back(ch[x] + '0');
for (char x : t) b.push_back(ch[x] + '0');
for (char x : w) c.push_back(ch[x] + '0');
ll A = stoll(a), B = stoll(b), C = stoll(c);
if (a[0] != '0' && b[0] != '0' && c[0] != '0' && A + B == C) {
cout << a << "\n"
<< b << "\n"
<< c << "\n";
return;
}
} while (next_permutation(p, p + 10));
cout << "UNSOLVABLE";
}
int main() {
solve();
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main()
{
int h, w, x, y;
cin >> h >> w >> x >> y;
bool arr[h][w];
for (int i = 0; i < h; i++)
{
for (int j = 0; j < w; j++)
{
arr[i][j] = false;
}
}
for (int i = 0; i < h; i++)
{
string s;
cin >> s;
for (int j = 0; j < w; j++)
{
if (s[j] == '.')
arr[i][j] = true;
}
}
x--;
y--;
int finalCount = 0;
int count = 0;
for (int i = 0; i < w; i++)
{
if (arr[x][i])
count++;
else
{
if (i > y)
{
finalCount+=count;
break;
}
count = 0;
}
if (i == w - 1)
finalCount+=count;
}
count = 0;
for (int i = 0; i < h; i++)
{
if (arr[i][y])
count++;
else
{
if (i > x)
{
finalCount+=count;
break;
}
count = 0;
}
if (i == h - 1)
finalCount+=count;
}
cout << finalCount - 1 << endl;
} |
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;cin>>n;
for(int i=1;i<=n;i++){
cout<<(i+1)/2<<" "<<(n+i+1)/2<<endl;
}
} | #include <cstdio>
int main(){
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++){
printf("%d %d\n",(i<<1)%n+1,(i<<1|1)%n+1);
}
return 0;
}
|
#include <bits/stdc++.h>
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
*/
#define pii pair<int,int>
#define fi first
#define pb push_back
#define si second
#define int long long
#define mod 998244353
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define double long double
#define all(o) o.begin(),o.end()
/*
#define T pair<int, int>
#define ordered_set tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>
*/
using namespace std;
int power(int x, int y)
{
int res = 1LL;
x = x % mod;
while (y > 0)
{
if (y & 1)
res = (res*x) % mod;
y = y>>1; // y = y/2
x = (x*x) % mod;
}
return res%mod;
}
int inv(int n)
{
return power(n,mod-2)%mod;
}
int isprime(int n){
if(n<2)return 0;
int i;
for(i=2;i*i<=n;i++)
if(n%i==0)
return 0;
return 1;
}
void files(){
// For getting input from input.txt file
freopen("lca.in", "r", stdin);
// Printing the Output to output.txt file
freopen("lca.out", "w", stdout);
}
int egcd(int a,int b,int &x ,int & y){
if(b==0){
x=1;y=0;
return a;
}
int x1,y1;
int g=egcd(b,a%b,x1,y1);
x=y1;
y=x1-(a/b)*y1;
return g;
}
const int N=2e6;
//https://codeforces.com/blog/entry/22747
// https://codeforces.com/blog/entry/89609
int n,c[505][505],a[505],b[505];
void solve(){
cin>>n;
int i,j,k;
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
cin>>c[i][j];
for(i=1;i<=n;i++){
int ok=1;
for(j=1;j<=n;j++)
{ b[j]=c[i][j];
a[j]=c[j][1]-b[1];
if(a[j]<0)
ok=0;
}
if(ok==0)continue;
for(j=1;j<=n;j++)
for(k=1;k<=n;k++)
if(c[j][k]!=a[j]+b[k] )
ok=0;
if(ok)
{
cout<<"Yes\n";
for(j=1;j<=n;j++)
cout<<a[j]<<" ";
cout<<"\n";
for(j=1;j<=n;j++)
cout<<b[j]<<" ";
cout<<"\n";
return;
}
}
cout<<"No\n";
}
int32_t main(){
fast
int t=1;
// cin>>t;
while(t--)
{
solve();
}
} | #include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;
void Main() {
ll n;
R n;
ll c[n][n];
rep(i,n)rep(j,n) R c[i][j];
set<vector<ll> > s1,s2;
rep(i,n) {
vector<ll> a,b;
rep(j,n-1) {
a.pb(c[i][j+1]-c[i][j]);
b.pb(c[j+1][i]-c[j][i]);
}
s1.in(a);
s2.in(b);
}
if(s1.size()>1||s2.size()>1) {
pr("No");
return;
}
vector<ll> v=*s1.begin();
ll M=0,x=0;
rep(i,v.size()) {
x+=v[i];
M=min(M,x);
}
vector<ll> b;
x=-M;
b.pb(x);
rep(i,v.size()) {
x+=v[i];
b.pb(x);
}
vector<ll> a;
rep(i,n) a.pb(c[i][0]-b[0]);
pr("Yes");
PR(a,n);
PR(b,n);
}
int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}
|
#include <cstring>
#include <iostream>
using namespace std;
using ll = long long;
const int MAXN = 102;
const int MAXC = 122505;
ll k, mod, table[MAXN][MAXC], ret[MAXN];
int n, now;
void calc() {
memset(table, 0, sizeof(table));
table[0][0] = 1;
for (int i = 1; i <= n; ++i) {
int c = (k * (i + 1) * i) >> 1;
c = min(c, MAXC - 1);
for (int j = 0; j <= c; ++j) {
for (int v = 0; v <= k; ++v) {
int tmp = j + v * i;
if (tmp > c) break;
table[i][tmp] += table[i-1][j];
if (table[i][tmp] >= mod) table[i][tmp] -= mod;
}
}
}
}
int main(){
ios::sync_with_stdio(0), cin.tie(0);
while (cin >> n >> k >> mod) {
calc();
for (now = 1; now * 2 <= n + 1; now++) {
ll ans = 0;
int l = now - 1, r = n - now;
ans += k * table[l][0] * table[r][0];
ans %= mod;
for (int j = 1; j < MAXC; ++j) {
ans += (k + 1LL) * ((table[l][j] * table[r][j]) % mod);
ans %= mod;
}
ret[now] = ans;
ret[n - now + 1] = ans;
}
for (now = 1; now <= n; ++now) cout << ret[now] << '\n';
}
return 0;
}
| /*Lucky_Glass*/
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=101,M=125001;
#define ci const int &
int n,m,MOD;
int f[N][M];
inline int Add(ci a,ci b){return a+b>=MOD? a+b-MOD:a+b;}
inline int Sub(ci a,ci b){return a-b<0? a-b+MOD:a-b;}
inline int Mul(ci a,ci b){return int(1ll*a*b%MOD);}
int main(){
scanf("%d%d%d",&n,&m,&MOD);
f[0][0]=1;
for(int i=1;i<=n;i++){
int bonj=min(M-1,(i+1)*i/2*m);
for(int j=0;j<=bonj;j++)
for(int k=0;k*i<=j && k<=m;k++)
f[i][j]=Add(f[i][j],f[i-1][j-k*i]);
}
for(int x=1;x<=n;x++){
int tot=0;
for(int j=1;j<M;j++)
tot=Add(tot,Mul(f[x-1][j],f[n-x][j]));
tot=Add(Mul(tot,m+1),m);
printf("%d\n",tot);
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int N;
cin >> N;
string S, X;
cin >> S >> X;
vector<int> pow_10(N);
int tmp = 1;
for (int i=N-1;i>=0;i--) {
pow_10[i] = tmp;
tmp = tmp*10%7;
}
// 0: takahashi
// 1: aoki
vector<int> vec(7, 1);
vec[0] = 0;
for (int i=N-1;i>=0;i--) {
int num = S[i]-'0';
vector<int> vec_next(7, -1);
if (X[i] == 'T') {
for (int j=0;j<7;j++) {
if (vec[j] == 0) {
vec_next[j] = 0;
vec_next[(j-num*pow_10[i]%7+7)%7] = 0;
}
}
for (int j=0;j<7;j++) {
if (vec_next[j] == -1) vec_next[j] = 1;
}
} else { // X[i] == 'A
for (int j=0;j<7;j++) {
if (vec[j] == 1) {
vec_next[j] = 1;
vec_next[(j-num*pow_10[i]%7+7)%7] = 1;
}
}
for (int j=0;j<7;j++) {
if (vec_next[j] == -1) vec_next[j] = 0;
}
}
vec = vec_next;
}
if (vec[0] == 0) cout << "Takahashi" << "\n";
else cout << "Aoki" << "\n";
return 0;
}
| //#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;
int dp[MAXN][7],n;
char s[MAXN],t[MAXN];
int dfs(int dep,int rem){
if(dep>n){
if(rem)return dp[dep][rem]=2;
else return dp[dep][rem]=1;
}
if(dp[dep][rem])return dp[dep][rem];
int now=s[dep]-'0';
int idx1=(rem*10+now)%7,idx2=(rem*10)%7;
dfs(dep+1,idx1);dfs(dep+1,idx2);
if(t[dep]=='T'){
if(dp[dep+1][idx1]==1||dp[dep+1][idx2]==1){
return dp[dep][rem]=1;
}else return dp[dep][rem]=2;
}else if(t[dep]=='A'){
if(dp[dep+1][idx1]==1&&dp[dep+1][idx2]==1){
return dp[dep][rem]=1;
}else return dp[dep][rem]=2;
}
}
void mainwork(int T){
scanf("%d",&n);
scanf("%s",s+1);
//reverse(s+1,s+n+1);
scanf("%s",t+1);
//reverse(t+1,t+n+1);
dfs(1,0);
if(dp[1][0]==1)puts("Takahashi");
else puts("Aoki");
}
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>
using namespace std;
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define _pb pop_back
#define _pf pop_front
#define lb lower_bound
#define ub upper_bound
#define er equal_range
#define spc(x, y) setprecision(y) << fixed << x
#define slc(x, w, c) setw(w) << setfill(c) << x
#define file "TEST"
typedef long long ll;
typedef unsigned long long ull;
typedef string str;
typedef double db;
#define _OD "DEBUG>> "
#define deb_v(x) cerr << _OD << (#x) << ": " << x << '\n'
#define deb_vec(x) cerr << _OD << (#x) << ": "; for (auto i : x) cerr << i << ' '; cerr << '\n'
#define deb_arr(x, l, r) cerr << _OD << (#x) << ": "; for (int i = l; i <= r; ++i) cerr << x[i] << ' '; cerr << '\n'
#define _deb_vec(x) cerr << _OD << (#x) << ": "; for (int i = x.size() - 1; i >= 0; --i) cerr << x[i] << ' '; cerr << '\n'
#define _deb_arr(x, r, l) cerr << _OD << (#x) << ": "; for (int i = r; i >= l; --i) cerr << x[i] << ' '; cerr << '\n'
#define START_TIMER clock_t _, __; _ = clock()
#define END_TIMER __ = clock(); db ___ = db(__ - _) / (db)CLOCKS_PER_SEC; cerr << "\nTime executed: " << spc(___, 5) << " sec\n"
mt19937_64 rd(time(0));
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 / gcd(a, b) * b; }
template<typename T> T max(T a, T b, T c) { return max(a, max(b, c)); }
template<typename T> T max(T a, T b, T c, T d) { return max(a, max(b, c, d)); }
ll mulmod(ll a, ll b, ll n) {
if (b == 0)
return 0;
ll tmp = mulmod(a, b >> 1, n);
if (b & 1)
return (tmp * 2 % n + a) % n;
return tmp * 2 % n;
}
template<typename T>
T i_rand(T l, T r) {
assert(l <= r);
return uniform_int_distribution<T>(l, r)(rd);
}
template<typename T>
T r_rand(T l, T r) {
return uniform_real_distribution<T>(l, r)(rd);
}
template<typename T>
void sfe(T a[], int l, int r) {
shuffle(a + l, a + 1 + r, rd);
}
template<typename T>
void sfe(vector<T> a) {
shuffle(a.begin(), a.end(), rd);
}
int n;
db l[2001], r[2001], t[2001];
signed main() {
START_TIMER; ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
// freopen(file".INP", "r", stdin);
// freopen(file".OUT", "w", stdout);
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> t[i] >> l[i] >> r[i];
if (t[i] == 1)
continue;
if (t[i] == 2)
r[i] -= 0.5;
if (t[i] == 3)
l[i] += 0.5;
if (t[i] == 4) {
r[i] -= 0.5;
l[i] += 0.5;
}
}
int rs = 0;
for (int i = 1; i <= n; ++i)
for (int j = 1; j < i; ++j)
if (max(l[i], l[j]) <= min(r[i], r[j]))
++rs;
cout << rs;
END_TIMER; return 0;
}
/*
proof & correctness
run some pretest
int32 overflow
array size
reinit after tests
write a tester
read code line after line again (without reading the template)
submit
*/ | #include "bits/stdc++.h"
using namespace std;
#define int long long
#define forn(i,n) for(int i = 0; i < n; i++)
#define pb push_back
#define sz(x) ((int)(x).size())
#define dbg(x) cerr << #x << "->" << x << "\n";
#define prnt(x) cerr<<"{ ";for(auto i:x)cerr<<i<<" ";cerr<<"}\n";
void solve() {
int N; cin >> N;
vector<pair<long double, long double>> v;
long double d = 1e-9;
forn(_, N) {
int t;
long double l, r;
cin >> t >> l >> r;
if (t == 1) v.pb({l, r});
if (t == 2) v.pb({l, r - d});
if (t == 3) v.pb({l + d, r});
if (t == 4) v.pb({l + d, r - d});
}
int ans = 0 ;
forn(i, N) {
for (int j = i + 1; j < N; j++) {
if (max(v[i].first, v[j].first) <= min(v[i].second, v[j].second)) {
ans++;
}
}
}
cout << ans;
}
int32_t main() {
ios_base::sync_with_stdio(false); cin.tie(0);
int t = 1;
// cin >> t;
forn(i, t)
solve();
} |
#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
constexpr ll MOD = 1'000'000'007LL; /*998'244'353LL;*/
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
template<class T> bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
constexpr int dy[4]={-1,0,1,0};
constexpr int dx[4]={0,-1,0,1};
int N, M;
int A[100*100], B[100*100];
int C[100];
vector<pair<int,int>> e[101];
vector<int> v[101];
int ans[100*100];
bool vis[100];
queue<int> que;
bool fin[100];
bool dfs(int n, int p, int b){
if(vis[n]){
if(n == p) return true;
else return false;
}
vis[n] = true;
rep(i, e[n].size()){
if(C[n] != C[e[n][i].first]) continue;
if(e[n][i].first == b) continue;
bool ret = dfs(e[n][i].first, p, n);
if(ret){
fin[n] = true;
ans[e[n][i].second] = n;
que.push(n);
return true;
}
}
vis[n] = false;
return false;
}
bool dfs2(int n, int p, int b){
if(fin[n]) return true;
if(vis[n]) return false;
vis[n] = true;
rep(i, e[n].size()){
if(C[n] != C[e[n][i].first]) continue;
if(e[n][i].first == b) continue;
bool ret = dfs2(e[n][i].first, p, n);
if(ret){
fin[n] = true;
ans[e[n][i].second] = n;
que.push(n);
return true;
}
}
vis[n] = false;
return false;
}
signed main(){
cin >> N >> M;
rep(i, M){
cin >> A[i] >> B[i];
A[i]--; B[i]--;
e[A[i]].pb({B[i],i});
e[B[i]].pb({A[i],i});
}
rep(i, N){
cin >> C[i];
v[C[i]].pb(i);
}
rep(i, 101){
rep(j, v[i].size()){
if(!fin[v[i][j]]){
bool ret = dfs(v[i][j], v[i][j], -1);
}
while(que.size()){
rep(k, e[que.front()].size()){
if(C[que.front()] != C[e[que.front()][k].first]) continue;
if(fin[e[que.front()][k].first]) continue;
dfs2(e[que.front()][k].first, que.front(), que.front());
ans[e[que.front()][k].second] = que.front();
}
que.pop();
}
}
}
rep(i, M){
if(C[A[i]] > C[B[i]]) cout << "->" << endl;
else if(C[A[i]] < C[B[i]]) cout << "<-" << endl;
else{
if(ans[i] == A[i]) cout << "->" << endl;
else cout << "<-" << endl;
}
}
} | #include <iostream>
using namespace std;
//#define int long long
const int maxm=1e3+5;
int g[maxm][maxm];
int mark[maxm];
int a[maxm];
int b[maxm];
int c[maxm];
int ans[maxm];
int n,m;
void dfs(int x){
mark[x]=1;
for(int i=1;i<=n;i++){
if(g[x][i]){
g[i][x]=0;
if(!mark[i]){
dfs(i);
}
}
}
}
int main(){
cin>>n>>m;
for(int i=1;i<=m;i++){
cin>>a[i]>>b[i];
}
for(int i=1;i<=n;i++){
cin>>c[i];
}
for(int i=1;i<=m;i++){
if(c[a[i]]>c[b[i]]){
ans[i]=1;
}else if(c[a[i]]<c[b[i]]){
ans[i]=0;
}else{
g[a[i]][b[i]]=g[b[i]][a[i]]=1;
}
}
for(int i=1;i<=n;i++){
if(!mark[i]){
dfs(i);
}
}
for(int i=1;i<=m;i++){
if(g[a[i]][b[i]])ans[i]=1;
else if(g[b[i]][a[i]])ans[i]=0;
}
for(int i=1;i<=m;i++){
if(ans[i]==1)cout<<"->"<<endl;
else cout<<"<-"<<endl;
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using V = vector<ll>;
using VV = vector<V>;
using M = map<ll, ll>;
using Q = queue<ll>;
using PQ = priority_queue<ll>;
using ST = stack<ll>;
using Graph = vector< vector<ll> >;
using VP = vector<P>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define rbfor(v, vec) for(auto const& v : vec)
#define debug(var) do{std::cout << #var << " : ";view(var);}while(0)
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
const int INFI = 1000000000;
template<typename T> bool chmax(T &a, const T &b) {if (a < b){a = b;return true;}else{return false;}}
template<typename T> bool chmin(T &a, const T &b) {if (a > b){a = b;return true;}else{return false;}}
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
// for dfs
string s[505];
bool used[505][505];
int d[505][505];
const int di[] = {-1,0,1,0}, dj[] = {0,-1,0,1};
void sample_solve();
bool dfs(int i, int j);
void bfs();
ll gcd(ll m, ll n);
ll lcm(ll x, ll y);
bool compare(P a, P b);
void vp_sort(VP& vp, bool asc);
// =================================
// Main Logic
// =================================
void solve() {
int ans = 0;
int n;
cin >> n;
vector<int> a(n);
rep(i,n) cin >> a[i];
rep(i,n) {
if (a[i] > 10) ans += (a[i]-10);
}
cout << ans << endl;
}
// =================================
int main() {
std::cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
std::cout << std::fixed << std::setprecision(15);
solve();
return 0;
}
// ---------------
// https://atcoder.jp/contests/apg4b/tasks_print
// ---------------
typedef tuple<string, int ,int> TUPLE;
bool comp(TUPLE lhs, TUPLE rhs) {
if (get<0>(lhs) == get<0>(rhs)) {
return get<1>(lhs) > get<1>(rhs);
} else {
return get<0>(lhs) < get<0>(rhs);
}
}
// 最大公約数
ll gcd(ll m, ll n) {
if (n == 0) return m;
return gcd(n, m%n);
}
// 最小公倍数
ll lcm(ll x, ll y) {
return x / gcd(x, y) * y;//先に割り算をして掛けられる数を小さくして掛け算を行う
}
bool compare(P a, P b) {
if(a.first != b.first){ return a.first > b.first; }
if(a.second != b.second){return a.second > b.second;}
return true;
}
void vp_sort(VP& vp, bool asc) {
sort(vp.begin(), vp.end(), compare);
if(asc) reverse(vp.begin(), vp.end());
}
/*
// 比較関数の例: tuple 0で辞書順ソート、1で降順ソート
cout << "-- comp of tuple" << endl;
vector<TUPLE> vt;
vt.push_back(make_tuple("khabarovsk", 20, 1));
vt.push_back(make_tuple("moscow", 10, 2));
vt.push_back(make_tuple("kazan", 50, 3));
vt.push_back(make_tuple("kazan", 35, 4));
vt.push_back(make_tuple("moscow", 60, 5));
vt.push_back(make_tuple("khabarovsk", 40, 6));
sort(vt.begin(), vt.end(), comp);
rep(i, 6) cout << get<0>(vt.at(i)) << ":" << get<1>(vt.at(i)) << ":" << get<2>(vt.at(i)) << endl;
*/ | #define _CRT_SECURE_NO_WARNINGS 1
#define _CRT_DECLARE_NONSTDC_NAMES 0 // for using y1 as variable name
#include <iostream>
#include <cstdio>
#include <utility>
#include <algorithm>
#include <vector>
using namespace std;
using ll = long long int;
constexpr ll MOD = 1000000007;
int n;
vector<int> d;
ll res;
int main(void)
{
#ifdef CUBE_PS
freopen("input.txt", "r", stdin);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
d.resize(n);
for(int i = 0; i < n; ++i) {
cin >> d[i];
}
sort(d.begin(), d.end());
d.erase(unique(d.begin(), d.end()), d.end());
res = d[0] + 1;
for(int i = 1; i < d.size(); ++i) {
res *= (d[i] - d[i - 1] + 1);
res %= MOD;
}
cout << res;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template <typename T>
inline bool chmax(T ¤t, const T &test){
if (current < test){
current = test;
return true;
}
return false;
}
template <typename T>
inline bool chmin(T ¤t, const T &test){
if (current > test){
current = test;
return true;
}
return false;
}
int corner_count(vector<vector<int>> &s, int i, int j){
int sum = 0;
sum += s[i][j] + s[i-1][j] + s[i][j-1] + s[i-1][j-1];
if(sum == 1 || sum == 3){
return 1;
}else{
return 0;
}
}
int main() {
int h, w;
cin >> h >> w;
vector<vector<int>> s(h, vector<int> (w));
char c;
rep(i, h){
rep(j, w){
cin >> c;
if(c =='#'){
s[i][j] = 1;
}else{
s[i][j] = 0;
}
}
}
int ans = 0;
for(int i = 1; i < h; i++){
for(int j = 1; j < w; j++){
ans += corner_count(s, i, j);
}
}
cout << ans << endl;
} | #include<bits/stdc++.h>
using namespace std;
int mod=1e9+7;
const int N=2e5+5;
int32_t main()
{
int ans=0;
int n;
cin>>n;
vector<vector<int> > a(n,vector<int> (5));
vector<vector<int> > dp(5);
for(int i=0;i<n;i++)
{
for(int j=0;j<5;j++)
{
cin>>a[i][j];
dp[j].push_back(a[i][j]);
}
}
for(int i=0;i<5;i++)
{
sort(begin(dp[i]),end(dp[i]),greater<int> ());
}
for(int i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
{
int ind;
int mini=1e9;
for(int k=0;k<5;k++)
{
if(max(a[i][k],a[j][k])<mini)
{
ind=k;
mini=max(a[i][k],a[j][k]);
}
}
int val=1e9;
for(int k=0;k<5;k++)
{
if(k!=ind)
val=min(val,max(a[i][k],a[j][k]));
}
val=min(val,dp[ind][0]);
ans=max(ans,val);
}
}
cout<<ans<<endl;
} |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define f(i,a,b) for( ll i = a; i < b ; i++ )
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ones(ini) (ll) __builtin_popcountll(x)
#define todo(y,val) all_of(all(y),[&val](ll x) {return (x == ((ll)val));})
#define nada(y,val) none_of(all(y),[&val](ll x) {return (x == ((ll)val));})
#define algu(y,val) any_of(all(y),[&val](ll x) {return (x == ((ll)val));})
#define cuantos(a,x) count(all(a),x)
#define fs first
#define sc second
#define pb push_back
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ller ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
#define watch(x) cout << (#x) << " is " << (x) <<"\n"
#define test ll deftestcases;cin>>deftestcases;while(deftestcases--)
#define PI acos(-1)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
template<class T> using ordered_set =tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update> ;
const ll inf = 2e9;
const ll mod = 1e9+7;
const ll MAX = 6e2+10;
struct celda{
ll u=0,v=0,dis=0;
bool operator<(const celda& other) const{
return dis>other.dis;
}
};
ll dis[MAX][MAX],a[MAX][MAX],b[MAX][MAX];
ll n,m;
priority_queue<celda> pq;
void fun(ll u,ll v,ll dd){
if(dis[u][v]>dd){
dis[u][v] = dd;
celda aux;
aux.u = u,aux.v = v,aux.dis = dd;
pq.push(aux);
}
}
void dijkstra(){
f(i,0,n+4){
f(j,0,m+4){
dis[i][j] = inf;
}
}
fun(0,0,0);
while(sz(pq)){
auto pos = pq.top();
if(pos.u==n-1 && pos.v == m-1){
cout<<dis[pos.u][pos.v]<<"\n";return;
}
pq.pop();
if(dis[pos.u][pos.v]<pos.dis) continue;
if(pos.v<m-1){
fun(pos.u,pos.v+1,pos.dis+a[pos.u][pos.v]);
}
if(pos.v>0){
fun(pos.u,pos.v-1,pos.dis+a[pos.u][pos.v-1]);
}
if(pos.u<n-1){
fun(pos.u+1,pos.v,pos.dis+b[pos.u][pos.v]);
}
f(uwu,1,pos.u+1){
fun(pos.u-uwu,pos.v,pos.dis+uwu+1);
}
}
}
int main(){
fastio;
cin>>n>>m;
f(i,0,n){
f(j,0,m-1) cin>>a[i][j];
}
f(i,0,n-1){
f(j,0,m) cin>>b[i][j];
}
dijkstra();
} | #include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>
#include <iomanip>
#include <cmath>
#include <set>
#include <unordered_set>
#include <functional>
#include <map>
#include <unordered_map>
#include <string>
#include <tuple>
using namespace std;
using ll = long long;
const int MOD=1e9+7;
const int MAX=100009;
ll fac[100009],finv[100009],inv[100009];
#define pi 3.14159265358979323846
#define ee 2.71828182845904523536
#define INF 5e18
ll gcd(ll x, ll y) { // 最大公約数
if (y == 0)return x;
else return gcd(y, x % y);
}
bool prime(ll x) { //素数判定
if(x==1)return false;
if (x!=2&&x % 2 == 0)return false;
for (ll i = 3; i <= sqrt(x); i+=2) {
if (x % i == 0)return false;
}
return true;
}
ll modinv(ll a, ll m) { //逆元
long long b = m, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b; swap(a, b);
u -= t * v; swap(u, v);
}
u %= m;
if (u < 0) u += m;
return u;
}
ll modpow(ll a, ll n, ll mod) { //二分累乗法
ll res = 1;
while (n) {
if (n % 2)res = res * a % mod;
a = a * a % mod;
n /= 2;
}
return res;
}
void COMinit() { //二項係数計算の前処理
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++){
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
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;
}
struct UnionFind { // UnionFind
vector<int> par;
vector<int> siz;
UnionFind(int N) : par(N), siz(N, 1) {
for (int i = 0; i < N; i++) par[i] = i;
}
int root(int x) {
if (par[x] == x) return x;
return par[x] = root(par[x]);
}
void unite(int x, int y) {
int rx = root(x);
int ry = root(y);
if (rx == ry) return;
if (par[rx] > par[ry])swap(rx, ry);
siz[rx] += siz[ry];
par[ry] = rx;
}
bool same(int x, int y) {
int rx = root(x);
int ry = root(y);
return rx == ry;
}
int size(int x) {
return siz[root(x)];
}
};
int main() {
int r,c;
cin>>r>>c;
int a[500][500];
int b[500][500];
for(int i=0;i<r;i++){
for(int j=0;j<c-1;j++)cin>>a[j][i];
}
for(int i=0;i<r-1;i++){
for(int j=0;j<c;j++)cin>>b[j][i];
}
priority_queue<tuple<int,int,int>,vector<tuple<int,int,int>>,greater<tuple<int,int,int>>> pq;
pq.push(make_tuple(0,0,0));
vector<vector<int>> co(c+1,vector<int>(r+1,5e9));
--r;--c;
co[0][0]=0;
while(!pq.empty()){
auto cur=pq.top();
pq.pop();
int x=get<1>(cur);
int y=get<2>(cur);
int cost=get<0>(cur);
if(x==c&&y==r){
cout<<cost<<endl;
return 0;
}
if(x<c&&co[x+1][y]>cost+a[x][y]){
pq.push(make_tuple(cost+a[x][y],x+1,y));
co[x+1][y]=cost+a[x][y];
}
if(x>0&&co[x-1][y]>cost+a[x-1][y]){
pq.push(make_tuple(cost+a[x-1][y],x-1,y));
co[x-1][y]=cost+a[x-1][y];
}
if(y<r&&co[x][y+1]>cost+b[x][y]){
pq.push(make_tuple(cost+b[x][y],x,y+1));
co[x][y+1]=cost+b[x][y];
}
for(int i=1;i<=y;i++){
if(co[x][y-i]>cost+1+i){
pq.push(make_tuple(cost+1+i,x,y-i));
co[x][y-i]=cost+1+i;
}
}
}
} |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define rep(i,a) for(ll i=0; i< a; i++)
#define rep1(i,a) for(ll i = 1; i< a; i++)
#define foi(i, a, b) for(ll i = a; i<b ; i++)
#define fod(i, a, b) for(ll i = a; i>=b ; i--)
#define max3(a, b, c) max(max(a, b), c)
#define min3(a, b, c) min(min(a, b), c)
#define MAX 1000005
#define MOD 1000000007
ll findgcd(ll n,ll m){
return __gcd(n,m);
}
ll findlcm(ll n,ll m){
return (n*m)/findgcd(n,m);
}
ll nodig(ll n){
int ans =0;
while(n!=0){
ans+=1;
n=n/10;
}
return ans;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n,a,b;
cin>>n>>a>>b;
cout<<n-a+b<<"\n";
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N = 0 ,A = 0 ,B = 0;
cin >> N >> A >> B;
cout<< N - A + B << endl;
} |
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#include<ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#define forn(i,x1,n) for(int i=x1; i<n; i++)
#define forit(it, m) for(decltype(m)::iterator it = m.begin(); it!=m.end(); ++it)
#define ff first
#define ss second
#define int long long
#define pb push_back
#define mp make_pair
#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(x1) __builtin_popcountll(x1)
#define zrobits(x1) __builtin_ctzll(x1)
#define mod 1000000007
// #define mod 998244353
#define inf 1e18
#define ps(x1,y) fixed<<setprecision(y)<<x1
#define mk(arr,n,type) type *arr=new type[n];
#define w(x1) int x1; cin>>x1; while(x1--)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void zeus()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
int maxi = 2000001;
int fac[2000001];
int fast_pow(long long base, long long n, long long M)
{
if (n == 0)
return 1;
if (n == 1)
return base;
long long halfn = fast_pow(base, n / 2, M);
if (n % 2 == 0)
return ( halfn * halfn ) % M;
else
return ( ( ( halfn * halfn ) % M ) * base ) % M;
}
int findMMI_fermat(int n, int M)
{
//only for prime
return fast_pow(n, M - 2, M);
}
int nCr(int n, int r, int M) { //For small n,r use GCD technique, find on GFG
int ans = (fac[n] * findMMI_fermat(fac[n - r], M) % M) * findMMI_fermat(fac[r], M);
ans = ans % M;
return ans;
}
int32_t main() {
zeus();
fac[0] = 1;
forn(i, 1, maxi) {
fac[i] = fac[i - 1] * i;
fac[i] %= mod;
}
int n, m, k; cin >> n >> m >> k;
if (n > m + k) {
cout << 0 << endl;
}
else if (k > n) {
cout << nCr(n + m, m, mod);
}
else {
cout << (nCr(n + m, m, mod) - nCr(n + m, m + k + 1, mod) + mod) % mod << endl;
}
} | #include<bits/stdc++.h>
#define LL long long
using namespace std;
const int mn=2e6+6,mod=1e9+7;
int n,m,k;
LL fac[mn],inv[mn];
LL qpow(LL a,LL b) {LL ans=1;while(b) {if(b&1) ans=ans*a%mod;a=a*a%mod;b>>=1;}return ans;}
void init()
{
fac[0]=inv[0]=1;
for(int i=1;i<mn;++i) fac[i]=fac[i-1]*i%mod;
inv[mn-1]=qpow(fac[mn-1],mod-2);
for(int i=mn-2;i;--i) inv[i]=inv[i+1]*(i+1)%mod;
}
LL C(int n,int m)
{
if(m>n) return 0;
return (fac[n]*inv[m]%mod)*inv[n-m]%mod;
}
int main()
{
init();
cin>>n>>m>>k;
if(n>m+k) {puts("0");return 0;}
cout<<(C(n+m,n)+mod-C(n+m,m+k+1))%mod;
} |
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define pii pair<int,int>
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define mp make_pair
#define endl '\n'
#define int long long
typedef double db;
typedef long long ll;
const int N = 2e5 + 5;
const int MOD = 1e9 + 7;
const int INF = 1e9;
void solve() {
string s; cin >> s;
reverse(all(s));
for (int i = 0; i < (int)s.length(); i++) {
if (s[i] == '6') s[i] = '9';
else if (s[i] == '9') s[i] = '6';
}
cout << s;
}
signed main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
fastIO
int t = 1;
// cin >> t;
for (int tt = 1; tt <= t; tt++) {
solve();
}
} | #include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<math.h>
#define ll long long
using namespace std;
int main()
{
string s;
cin>>s;
if(s[0]==s[1]&&s[1]==s[2])
cout<<"Won"<<endl;
else
{
cout<<"Lost"<<endl;
}
}
|
#include<bits/stdc++.h>
// #include<atcoder/all>
// #include<boost/multiprecision/cpp_int.hpp>
using namespace std;
// using namespace atcoder;
// using bint = boost::multiprecision::cpp_int;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007
// 2020/12/06 rechecked
long long modpow(long long n,long long r,const int mod = 1000000007){
long long res = 1;
while(r){
if(r & 1)res = res*n%mod;
n = n*n%mod;
r >>= 1;
}
return res;
}
int main(){
ll n,p;
cin >> n >> p;
cout << (p-1)*modpow(p-2,n-1)%MOD << "\n";
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define PI acos(-1)
#define pb push_back
#define int long long
#define ld long double
#define sp fixed<<setprecision
#define bp __builtin_popcountll
#define all(x) x.begin(),x.end()
#define pii pair<long long,long long>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int M = (1e9)+7;
const int N = 400005;
const int INF = 1e12;
int mpower(int x, int y)
{
int res = 1;
while(y)
{
if(y&1) res *= x, res %= M;
y = y/2;
x = x*x, x %= M;
}
return res;
}
signed main()
{
FAST
int tc=1;
// cin>>tc;
for(int ti=1;ti<=tc;ti++)
{
int n,p;
cin>>n>>p;
int ans = (p-1)%M;
ans *= mpower(p-2, n-1);
ans %= M;
cout<<ans<<endl;
}
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
main()
{
ll x,y,a,b,ans=0;
cin>>x>>y>>a>>b;
while(1)
{
if(x>=1e9)
{
break;
}
else
{
if((a-1)*x<b)
{
x=x*a;
}
else
{
break;
}
}
if(x<y)
{
ans++;
}
else
{
break;
}
}
ans+=(y-1-x)/b;
cout<<ans<<endl;
}
| #include<bits/stdc++.h>
#include<vector>
#include<map>
#include<unordered_set>
#include<set>
using namespace std;
#define flush
#define pb push_back
#define ed endl
#define cout1(a) cout<<a
#define cout2(a,b) cout<<a<<b
#define cout3(a,b,c) cout<<a<<b<<c
#define ll long long
#define ld long double
#define db double
#define ull unsigned long long
#define mk make_pair
#define pll pair<ll,ll>
#define pldb pair<ldb,ldb>
#define ff first
#define ss second
#define vull vector<ull>
#define ub upper_bound
#define lb lower_bound
#define sorts(v) sort(v.begin(),v.end())
#define sortg(v) sort(v.begin(),v.end(),greater<ll>())
#define vll vector<ll>//vll v; means vector<long long>v;
#define vb vector<bool>
#define vldb vector<ldb>
#define vpll vector<pll>
#define vpldb vector<pldb>
#define pqmin priority_qrueue<ll,vector<ll>,greater<ll>> //minheap
#define pq priority_qrueue<ll> //maxheap
#define pqrpll priority_qrueue<pll>//pqr with pairs
#define mll map<long,long>
#define mldb map<ldb,ldb>
#define umll unordered_map<ll>
#define sll set<ll>
#define usll unordered_set<ll>
#define ppc(x) __builtin_popcount(x)
#define pp(x) __builtin_parity(x)
#define ppll(x) __builtin_parityll(x)
#define clz(x) __builtin_clz(x)
#define ctz(x) __builtin_ctz(x)
#define clzll(x) __builtin_clzll(x)
#define ctzll(x) __builtin_ctzll(x)
#define ppcll(x) __builtin_popcountll(x)
#define maxx 1e9+7
#define minn -(1e9+7)
ll mod=1000000000+7;
ll inf=1e17;
//memset(dp, -1, sizeof dp);
//1<log(n)<sqrrt(n)<n<nlog(n)<n^2<n^3<........<2^n<3^n.....<n^n
/* n<=22 O((2^n)*n) //__gcd(a,b) gives gcd of two numbers
n<=100 O(n^4)
n<=400 O(n^3) //no of digits=floor(log10(n))+1;
n<=2000 O(n^2logn)
n<=10^4 O(n^2) return(x&&(!(x&(x-)))); tell if x is power of 2;
n<=10^5or6 O(nlogn) accumulate(v.begin(),v.end(),0);
n<=10^8 O(n),O(3.2*log(10)n),O(1)
n<=10^18 O(logn),O(1)
vector<int>::iterator it;
__lg(10)=3 to know
log(i)=log(i/2) + 1 recurrance relation to calculate the log value
log(10)=2.3059*log10(10)
log10(10)=1
cout<<setw(2)<<setfill('0')<<h<<':'<<setw(2)<<setfill('0')<<m<<ed; set the feild width to 2 and default value is 0
*/
/*
NOTE-pow() funtion is not so precise
*/
const int N=1e5+5;
bool prime[N];
void solve()
{
int x,y,z;
cin>>x>>y>>z;
db val=(db)y/x;
int res=INT_MIN;
// cout<<val<<ed;
// cout<<res<<ed;
for(int i=0;i<1e6 + 5;i++)
{
if((db)i/z <val)
{
if(i>res)
{
res=i;
}
}
else
{
break;
}
}
cout<<res<<ed;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
// prime[1]=false;
// for(int i=0;i*i<=N;i++)
// {
// for(int j=i*i;j<=N;j+=i)
// {
// prime[j]=true
// }
// }
solve();
return(0);
} |
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
#include <cstdint>
#include <string>
#include <sstream>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long ll;
using P=pair<ll,ll>;
const int INF=1001001001;
const int mod=998244353;
vector<int>G[200005],r[200005];
int in[200005],out[200005],depth[200005];
int id;
void dfs(int i,int d=0){
in[i]=id++;
depth[i]=d;
for(int u:G[i]){dfs(u,d+1);}
out[i]=id;
}
void solve(){
int n;
cin>>n;
rep(i,n-1){
int p;
cin>>p;
p--;
G[p].push_back(i+1);
}
dfs(0);
rep(i,n){r[depth[i]].push_back(in[i]);}
rep(i,n){sort(r[i].begin(),r[i].end());}
int Q;
cin>>Q;
rep(i,Q){
int u,d;
cin>>u>>d;
u--;
int ans=lower_bound(r[d].begin(),r[d].end(),out[u])-lower_bound(r[d].begin(),r[d].end(),in[u]);
cout<<ans<<endl;
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const int O = 2e5 + 1;
vector <int> c, dp, g[O], Max;
int t = 1;
bool how_sort(int x, int y){
return Max[x] < Max[y];
}
int dfs(int u, int par = 0){
Max[u] = 0;
for (int v : g[u]){
if (v == par) continue;
dp[v] = dp[u] + 1;
Max[u] = max(Max[u], dfs(v, u) + 1);
}
return Max[u];
}
void dfs1(int u, int par = 0){
c[u] = t;
for (int v : g[u]){
if (v == par) continue;
t += 1;
dfs1(v, u);
t += 1;
}
}
main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int n; cin >> n;
c.resize(n + 1);
dp.resize(n + 1);
Max.resize(n + 1);
for (int i = 1; i < n; ++ i){
int u, v; cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
dfs(1);
int compare = 0;
int root = 1;
for (int i = 1; i <= n; ++ i){
if (dp[i] > compare){
compare = dp[i];
root = i;
}
}
dfs(root);
for (int i = 1; i <= n; ++ i){
sort(g[i].begin(), g[i].end(), how_sort);
}
dfs1(root);
for (int i = 1; i <= n; ++ i) cout << c[i] << " ";
}
/***
10
1 2
2 3
2 4
4 5
5 6
6 7
6 8
8 10
8 9
**/
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
int dx[4]={0,1,0,-1}, dy[4]={1,0,-1,0};
long double eps = 1e-9;
long double pi = acos(-1);
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(20);
string s;
cin>>s;
int n = s.size();
deque<char> q;
bool f = false;
for(int i=0;i<n;i++){
if(s[i] == 'R')f^=1;
else if(f)q.push_front(s[i]);
else q.push_back(s[i]);
}
stack<char> ans;
while(q.size()){
char c = q.front();
q.pop_front();
if(ans.size() && ans.top()==c){
ans.pop();
continue;
}
ans.push(c);
}
string ret = "";
while(ans.size()){
ret += ans.top();
ans.pop();
}
if(f==false && ret.size())reverse(all(ret));
cout << ret << endl;
} | #include <bits/stdc++.h>
#include <chrono>
using namespace std;
using namespace chrono;
typedef long long int ll;
typedef vector<int> vii;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define pb push_back
#define odd(x) ((x)&1)
#define even(x) (!odd(x))
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(auto i=0;i<n;++i)
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define TEST_CASE int tc;cin>>tc;while(tc--)
#define Clock high_resolution_clock::now()
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;}
#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
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
// #define TIME
/******************************************************************************************************************************/
const ll inf = 2e18;
const ll mod = 998244353;
const ll N = 5e3+3;
int main()
{
auto start_time = Clock;
FASTIO
string s;
cin >> s;
int n = s.size();
deque<char> ans;
bool f = 0;
rep(i,n) {
if(s[i] == 'R') {
f ^= 1;
continue;
}
if(f) {
if(ans.empty() || ans.front() != s[i])
ans.push_front(s[i]);
else
ans.pop_front();
}
else {
if(ans.empty() || ans.back() != s[i])
ans.pb(s[i]);
else ans.pop_back();
}
}
if(f) reverse(all(ans));
for(auto i: ans) cout << i;
cout << "\n";
auto end_time = Clock;
#ifndef TIME
return 0;
#endif
cout << "\nTime elapsed: "
<< (double)duration_cast<milliseconds>(end_time-start_time).count()
<< "ms";
return 0;
} |
#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;
// a^n (mod.MOD)を求める。計算量はO(logn)
ll modpow(ll a, ll n, ll MOD = mod) {
if(n == 0) {
return 1;
}
if(n%2 == 1) {
return (a * modpow(a, n-1, MOD))%MOD;
}
return (modpow(a, n/2, MOD) * modpow(a, n/2, MOD))%MOD;
}
// nCrをO(r)で求める。
ll Comb(ll n, ll r) {
if(n < r) {
return 0;
}
if(r > n-r) {
return Comb(n, n-r);
}
ll Mul = 1;
ll Div = 1;
rep(i, r) {
Mul *= (n-i);
Div *= (i+1);
Mul %= mod;
Div %= mod;
}
ll res = Mul*modpow(Div, mod-2)%mod;
return res;
}
int main() {
ll n, m;
cin >> n >> m;
ll s = 0;
rep(i, n) {
ll a;
cin >> a;
s += a;
}
out(Comb(n+m, n+s));
re0;
} | #include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> ii;
int V[400005];
vector<int> A;
vector<int> B;
int main(){
int N;
scanf("%d", &N);
long long ans = 0;
for(int i = 0; i < 2*N; i ++){
scanf("%d", &V[i]);
ans += V[i];
}
for(int i = 0; i < N; i ++){
A.push_back(V[i]);
}
for(int i = N; i < 2*N; i ++){
B.push_back(V[i]);
}
reverse(A.begin(), A.end());
priority_queue<int, vector<int>, greater<int> > pq;
for(int i = 0; i < N; i ++){
pq.push(A[i]);
pq.push(B[i]);
assert(!pq.empty());
ans -= pq.top();
pq.pop();
}
printf("%lld\n", ans);
return 0;
}
|
#include <bits/stdc++.h>
//#include <iostream>
//#include <vector>
using namespace std;
int main(){
int a,b,c;
cin >> a >> b >> c;
cout << 21-(a+b+c);
return 0;
} | #include <bits/stdc++.h>
//#include <atcoder/all>
#define rep(i, n) for (int i=0; i < (n); i++)
using namespace std;
//using namespace atcoder;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
const int INF = 1 << 30;
const ll LINF = 1LL << 61;
const int NIL = -1;
const int MAX = 10000;
const int MOD = 1000000007;
const double pi = 3.141592653589;
double dp[110][110][110];
int main() {
int a, b, c; cin >> a >> b >> c;
dp[a][b][c] = 1;
double ans = 0;
for(int i=a;i<=100;i++){
for(int j=b;j<=100;j++){
for(int k=c;k<=100;k++){
if(i==100 || j == 100 || k == 100){
int count = i+j+k -(a+b+c);
ans += dp[i][j][k]*count;
continue;
}
dp[i+1][j][k] += dp[i][j][k] * i/(i+j+k);
dp[i][j+1][k] += dp[i][j][k] * j/(j+i+k);
dp[i][j][k+1] += dp[i][j][k] * k/(k+i+j);
}
}
}
/*double ans = 0;
for(int j=b;j<100;j++){
for(int k=c;k<100;k++){
int count = 100-a + j-b + k-c;
ans += dp[100][j][k] * count;
}
}
for(int i=a;i<100;i++){
for(int k=c;k<100;k++){
int count = i-a + 100-b + k-c;
ans += dp[i][100][k] * count;
}
}
for(int i=a;i<100;i++){
for(int j=b;j<100;j++){
int count = i-a + j-b + 100-c;
ans += dp[i][j][100] * count;
}
}*/
cout << setprecision(15) << ans << endl;
return 0;
} |
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define rep(i, n) FOR(i,0,n)
#define irep(i, n) IFOR(i,0,n)
#define all(v) begin(v), end(v)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using VI = vector<int>;
using VLL = vector<ll>;
using VB = vector<bool>;
template<typename T>istream& operator>>(istream&i,vector<T>&v){rep(j,v.size())i>>v[j];return i;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
bool second_compare(P a,P b){if(a.second!=b.second){return a.second<b.second;} else return true;}
vector<pair<ll, ll> > prime_factorize(ll n) {
vector<pair<ll, ll> > res;
for (ll i = 2; i*i <= n; i++) {
if (n % i != 0) continue;
ll ex = 0;
while (n % i == 0) {
++ex;
n /= i;
}
res.push_back({i, ex});
}
if (n != 1) res.push_back({n, 1});
return res;
}
int modPow(ll a, ll n, ll p) {
if (n == 0) return 1;
if (n == 1) return a % p;
if (n % 2 == 1) return (a * modPow(a, n - 1, p)) % p;
ll t = modPow(a, n / 2, p);
return (t * t) % p;
}
int main() {
long double x, y, r;
cin >> x >> y >> r;
r += 1e-14;
ll low = ceil(x-r), high = floor(x+r);
ll ans = 0;
for (ll i = low-2; i < high+2; i++) {
if (pow(r,2)-pow((x-(long double)i),2) < 0.0) continue;
long double p = sqrt(pow(r,2)-pow((x-(long double)i),2));
ll bt = (ll)ceil(y-p), tp = (ll)floor(y+p);
ans+=(tp+1-bt);
}
cout << ans << endl;
return 0;
} | #include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#include <string>
#include <numeric>
#include <queue>
#include <cstdio>
#include <cstring>
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<n;++i)
#define mrep(i,n) for(ll i=n;i>=0;--i)
#define all(a) (a).begin(),(a).end()
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vb vector<bool>
#define vvb vector<vector<bool> >
#define pl pair<ll,ll>
#define inf 1001001001001001000
#define mod 1000000007
//#define mod 998244353
#define pi 3.1415926535
using namespace std;
struct __INIT{
__INIT(){
cin.tie(0);
ios::sync_with_stdio(false);
cout<<fixed<<setprecision(15);
}
}__init;
ll gcd(ll a,ll b){
if(a<b) return gcd(b,a);
ll r;
while((r=a%b)){
a = b;
b = r;
}
return b;
}
//necessary gcd
ll gcds(vl a){
ll ret = a[0];
rep1(i,a.size()){
ret = gcd(ret,a[i]);
}
return ret;
}
int main(){
ll n;
cin>>n;
vl a(n);
rep(i,n) cin>>a[i];
cout<<gcds(a)<<endl;
} |
//#pragma GCC optimize ("O2")
//#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please
const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
if (ci - owa > 0) {
memcpy(cn, owa, CL);
ci -= CM;
fread(cn + CL, 1, CM, stdin);
}
ll tmp = *(ll*)ci;
if ((tmp & ma0) ^ ma0) {
int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
tmp = tmp << dig & ma1;
tmp = tmp * 10 + (tmp >> 8) & ma2;
tmp = tmp * 100 + (tmp >> 16) & ma3;
tmp = tmp * 10000 + (tmp >> 32) & ma4;
ci += (72 - dig >> 3);
}
else {
tmp = tmp & ma1;
tmp = tmp * 10 + (tmp >> 8) & ma2;
tmp = tmp * 100 + (tmp >> 16) & ma3;
tmp = tmp * 10000 + (tmp >> 32) & ma4;
ci += 8;
if ((ct = *ci++) >= '0') {
tmp = tmp * 10 + ct - '0';
if (*ci++ == '0') {
tmp = tmp * 10;
ci++;
}
}
}
return tmp;
}
const int MAX = 100000;
class shuturyoku_unko {
public:
char C[MAX * 5];
constexpr shuturyoku_unko() : C() {
rep(i, MAX) {
int X = i;
rep(j, 5) {
C[i * 5 + 4 - j] = '0' + X % 10;
X /= 10;
}
}
}
};
constexpr shuturyoku_unko f;
const int dm = 1 << 17;
char dn[dm], * di = dn, * owad = dn + dm - 20;
void putint(ll A) {
if (owad < di) {
fwrite(dn, 1, di - dn, stdout);
di = dn;
}
int dig = 1;
if (A >= 100000) {
if (A >= 1000000000) dig = 5;
else if (A >= 100000000) dig = 4;
else if (A >= 10000000) dig = 3;
else if (A >= 1000000) dig = 2;
memcpy(di + dig, f.C + A % 100000 * 5, 5);
A /= 100000;
memcpy(di, f.C + A * 5 + 5 - dig, dig);
di += 5 + dig;
}
else {
if (A >= 10000) dig = 5;
else if (A >= 1000) dig = 4;
else if (A >= 100) dig = 3;
else if (A >= 10) dig = 2;
memcpy(di, f.C + A * 5 + 5 - dig, dig);
di += dig;
}
*di++ = '\n';
}
const int mod = 1e9 + 7;
int main() {
//cin.tie(0);
//ios::sync_with_stdio(false);
int T = getint();
rep(t, T) {
ll N = getint(), A = getint(), B = getint();
ll a = min(A, N - B + 1);
ll b = min(A + B - 1, N - B + 1);
ll are = (a + b) * (b - a + 1) + b * (N - A + 1 - (b - a + 1) * 2);
ll atti = (N - A + 1) * (N - B + 1);
ll kotae = (atti + are) % mod * ((atti - are) % mod) % mod;
putint(kotae);
}
fwrite(dn, 1, di - dn, stdout);
Would you please return 0;
} | #include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <vector>
#include <algorithm>
//#include <atcoder/All>
using namespace std;
//using namespase atcoder;
int main(){
const long nPrime = 1000000007;
int t;
scanf("%d", &t);
for(int iCount = 0; iCount < t; iCount++){
long n,a,b;
scanf("%ld %ld %ld", &n, &a, &b);
if(a+b > n){
printf("0\n");
continue;
}
if(a < b){
swap(a,b);
}
long k = (n-a-b+1) * (n-a-b+2) / 2;
k %= nPrime;
long nAns = k * (n-b+1);
nAns %= nPrime;
nAns *= (n-a+1);
nAns %= nPrime;
nAns *= 4;
nAns %= nPrime;
nAns -= (k*k*4);
nAns %= nPrime;
if(nAns < 0){
nAns += nPrime;
}
printf("%ld\n", nAns);
}
return 0;
}
|
/**
* author: pankaj_m05
* created: 06.02.2021 17:35:00
**/
#include<bits/stdc++.h>
using namespace std;
int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int v, t, s, d;
cin >> v >> t >> s >> d;
if (d < v * t || d > v * s) {
cout << "Yes";
} else {
cout << "No";
}
return 0;
} | #include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x) cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
int main(void)
{
cin.tie(0);
ios::sync_with_stdio(false);
int V, S, T, D;
cin >> V >> S >> T >> D;
int L = V * S;
int R = V * T;
if(L <= D && D <= R) {
cout << "No" << endl;
} else {
cout << "Yes" << endl;
}
return 0;
}
|
/*************************************************************************
> File Name: F.cpp
> Author: Bran
> Mail: [email protected]
> Created Time: 2020/12/19 23:11:30
************************************************************************/
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define fr first
#define sc second
#define rep(i,x,n) for (int i = x; i < n; ++i)
using namespace std;
using LL = long long;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
struct segtree {
int size;
vector<int> sums;
void init(int n) {
size = 1;
while (size < n) size <<= 1;
sums.assign(2 * size, 0);
}
void build(vector<int>& a, int cur, int l, int r) {
if (l + 1 == r) {
if (l < a.size()) sums[cur] = a[l];
return ;
}
int m = (l + r) / 2;
build(a, cur * 2 + 1, l, m);
build(a, cur * 2 + 2, m, r);
sums[cur] = sums[cur * 2 + 1] ^ sums[cur * 2 + 2];
}
void build(vector<int>& a) {
build(a, 0, 0, size);
}
void set(int i, int val, int cur, int l, int r) {
if (l + 1 == r) {
sums[cur] ^= val;
return ;
}
int m = (l + r) / 2;
if (i < m) set(i, val, cur * 2 + 1, l, m);
else set(i, val, cur * 2 + 2, m, r);
sums[cur] = sums[cur * 2 + 1] ^ sums[cur * 2 + 2];
}
void set(int i, int val) {
set(i, val, 0, 0, size);
}
int query(int a, int b, int cur, int l, int r) {
if (r <= a || l >= b) return 0;
if (l >= a && r <= b) return sums[cur];
int m = (l + r) / 2;
return query(a, b, cur * 2 + 1, l, m) ^ query(a, b, cur * 2 + 2, m, r);
}
int query(int a, int b) {
return query(a, b, 0, 0, size);
}
}st;
void solve() {
int n, q;
scanf("%d%d", &n, &q);
vector<int> a(n);
rep(i, 0, n) scanf("%d", &a[i]);
st.init(n);
st.build(a);
rep(i, 0, q) {
int t, b, c;
scanf("%d%d%d", &t, &b, &c);
if (t == 1) st.set(b - 1, c);
else printf("%d\n", st.query(b - 1, c));
}
}
int main() {
solve();
return 0;
}
| #include<bits/stdc++.h>
//#include<atcoder/all>
using namespace std;
//using namespace atcoder;
//https://algo-logic.info/segment-tree/#toc_id_3_2
template <typename X>
struct SegTree {
using FX = function<X(X, X)>; // X•X -> X となる関数の型
int n;
FX fx;
const X ex;
vector<X> dat;
SegTree(int n_, FX fx_, X ex_) : n(), fx(fx_), ex(ex_), dat(n_ * 4, ex_) {
int x = 1;
while (n_ > x) {
x *= 2;
}
n = x;
}
void set(int i, X x) { dat[i + n - 1] = x; }
void build() {
for (int k = n - 2; k >= 0; k--) dat[k] = fx(dat[2 * k + 1], dat[2 * k + 2]);
}
void update(int i, X x) {
i += n - 1;
dat[i] = x;
while (i > 0) {
i = (i - 1) / 2; // parent
dat[i] = fx(dat[i * 2 + 1], dat[i * 2 + 2]);
}
}
X query(int a, int b) { return query_sub(a, b, 0, 0, n); }
X query_sub(int a, int b, int k, int l, int r) {
if (r <= a || b <= l) {
return ex;
} else if (a <= l && r <= b) {
return dat[k];
} else {
X vl = query_sub(a, b, k * 2 + 1, l, (l + r) / 2);
X vr = query_sub(a, b, k * 2 + 2, (l + r) / 2, r);
return fx(vl, vr);
}
}
};
int main(){
int N,Q;
cin>>N>>Q;
auto fx = [](int x1, int x2) -> int { return x1^x2; };
int ex = 0;
SegTree<int> rmq(N+5, fx, ex);
for(int i=1;i<=N;i++){
int A;
cin>>A;
rmq.update(i,A);
}
for(int i=0;i<Q;i++){
int T,X,Y;
cin>>T>>X>>Y;
if(T==1){
rmq.update(X,rmq.query(X,X+1)^Y);
}
else{
cout<<rmq.query(X,Y+1)<<endl;
}
}
}
|
#include<bits/stdc++.h>
#define ll long long
#define N 200005
using namespace std;
int read() {
int x=0,f=1;char c=getchar();
while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
while('0'<=c&&c<='9'){x=x*10+c-'0';c=getchar();}
return x*f;
}
int n,m,K,cnt,h[N],c[N],fp[N];
struct Edge {
int to,next;
}a[N*2];
void Add(int x,int y) {
cnt++;a[cnt].to = y;a[cnt].next = h[x];h[x] = cnt;
}
bool vst[N];
int ind,ans = 0;
#define inf 0x7fffffff/2
queue<int>q;
int d[20][N],inq[N];
void bfs(int id) {
for(int i=1; i<=n; ++i)d[id][i] = inf;
q.push(c[id]);d[id][c[id]] = 0;
inq[c[id]] = 1;
while(!q.empty()) {
int x = q.front();q.pop();
for(int i=h[x]; i; i=a[i].next) {
int y = a[i].to;
if(!inq[y])d[id][y] = d[id][x]+1,q.push(y),inq[y] = 1;
}
}
memset(inq,0,sizeof(inq));
}
int sta,f[1<<17][18];;
void deal() {
for(int i=1; i<=K; ++i)bfs(i);
// for(int i=1; i<=K; ++i){
//
// for(int j=1; j<=n; ++j)
// cout << d[i][j] << ' ';
// cout << '\n';
// }
memset(f,0x3f,sizeof(f));
for(int i=1; i<=K; ++i)f[1<<i-1][i] = 0;
for(int i=0;i<(1<<K);i++)
{
for(int j=1;j<=K;j++)
{
if(f[i][j]>1e9)continue;
for(int t=1;t<=K;t++)
{
if(i&(1<<t-1))continue;
f[i+(1<<t-1)][t]=min(f[i+(1<<t-1)][t],f[i][j]+d[j][c[t]]);
}
}
}
for(int j=1;j<=K;j++)
{
ans=min(ans,f[(1<<K)-1][j]);
}
}
int main() {
n = read();m = read();
for(int i=1; i<=m; ++i) {
int x = read(),y = read();
Add(x,y);Add(y,x);
}
K = read();sta = 0;
for(int i=1; i<=K; ++i) {
sta |= 1<<i-1;
}
ans = inf;
for(int i=1; i<=K; ++i)c[i] = read(),fp[c[i]] = i-1;
deal();
if(ans >= 1e9)puts("-1");
else cout << ans+1;
} | #include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
void chmin(int& x, int y) { x = min(x,y);}
int main() {
int n, m;
cin >> n >> m;
vector<vector<int>> to(n);
rep(i,m) {
int a, b;
cin >> a >> b;
--a; --b;
to[a].push_back(b);
to[b].push_back(a);
}
int k;
cin >> k;
vector<int> c(k);
rep(i,k) {
cin >> c[i];
c[i]--;
}
vector<vector<int>> dist(k,vector<int>(k));
const int INF = 1001001001;
auto bfs = [&](int sv) {
vector<int> dist(n, INF);
queue<int> q;
dist[sv] = 0;
q.push(sv);
while (!q.empty()) {
int v = q.front(); q.pop();
for (int u : to[v]) {
if (dist[u] != INF) continue;
dist[u] = dist[v]+1;
q.push(u);
}
}
return dist;
};
rep(i,k) {
vector<int> d = bfs(c[i]);
rep(j,k) dist[i][j] = d[c[j]];
}
int k2 = 1<<k;
vector<vector<int> > dp(k2, vector<int>(k, INF));
rep(i,k) dp[1<<i][i] = 1;
rep(s,k2)rep(i,k) {
if (~s>>i&1) continue;
rep(j,k) {
if (s>>j&1) continue;
chmin(dp[s|1<<j][j], dp[s][i]+dist[i][j]);
}
}
int ans = INF;
rep(i,k) chmin(ans, dp[k2-1][i]);
if (ans == INF) cout << -1 << endl;
else cout << ans << endl;
return 0;
} |
//x<<y=x*2^y,x>>y=x/2^y
//1e5+3 is prime
// in a matrix, all elements of a primary diagonal have constant diff of coordinates
// and a secondary diagonal has constant sum of coordinates
//use ll() for using an integer in self-built fn
//(x&-x) bitwise and of (x and its 2's complement) returns (last set bit)
//eg if x=1010 then it will return 0010
// careful dont print empty container(run time error)
//v.erase O(n)
//use ("\n") instead of endl as endl flushes the output buffer
//every time so takes more time than \n (TLE)
//stoll() and to_string((less than 1e19))
//INT_MAX is approx 3e10
//For sets use set_name.lower_bound(x)(strictly O(logn))
//NOT lb(all(s),x)(O(logn) for random access (eg vector) but for sets it is O(n));
#include<bits/stdc++.h>
typedef long long int ll;
#define ull unsigned long long int
#define lld long double
#define endl "\n"
#define fi first
#define sec second
#define sp setprecision
#define lb lower_bound
#define ub upper_bound
#define For(i, a, b) for(long long int i = (a); i <= (b); i++)
#define Forr(i, a, b) for(long long int i = (a); i >= (b); i--)
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define vll vector<ll>
#define pll pair<ll,ll>
#define vlld vector<lld>
#define vi vector<int>
#define vch vector<char>
#define sll set<ll>
#define sch set<ch>
#define vpll vector< pair<ll,ll> >
#define vpii vector< pair<int,int> >
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mll map<ll, ll>
#define mcll map<char,ll>
#define sz(container) ll((container).size())
#define fill(a,b) memset(a, b, sizeof(a))
#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
using namespace std;
lld pi=3.1415926535897932;
const ll mod=1000000007;
const ll dx[4]={-1, 0, 1, 0} , dy[4]={0, 1, 0, -1};
const ll dxx[8]={-1, -1, 0, 1, 1, 1, 0, -1} , dyy[8]={0, 1, 1, 1, 0, -1, -1, -1};
string ds="RLDU";
/***************************************
struct cmp
{
bool operator() (const pll &a, const pll &b) const
{
ll lena = a.sec - a.fi + 1;
ll lenb = b.sec - b.fi + 1;
if (lena == lenb) return a.fi < b.fi;
return lena > lenb;
}
};
********************************/
ll lcm(ll a, ll b)
{
ll g=__gcd(a, b);
return a/g*b;
}
ll binpow(ll a, ll b,ll m)
{
a %= m;
ll res = 1;
while (b > 0)
{
if (b & 1)
res = res * a % m;
a = a * a % m;
b >>= 1;
}
return res;
}
ll modinv(ll n)
{
return binpow(n, mod - 2,mod);
}
/**************coding****************************************/
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
fast_io;
ll T=1;//cin>>T;
For(i,1,T)
{
ll n;cin>>n;
char caa,cab,cba,cbb;cin>>caa>>cab>>cba>>cbb;
ll fib[n+1]={};
fib[1]=2;fib[0]=1;
For(j,2,n) fib[j]=(fib[j-1]+fib[j-2])%mod;
if(cab=='B')
{
if(cab==cbb||n<4)
{
cout<<1;return 0;
}
if(cbb==cba)
{
cout<<binpow(2,n-3,mod);return 0;
}
if(cba=cab)
{
cout<<fib[n-3];
}
}
else
{
if(cab==caa||n<4)
{
cout<<1;return 0;
}
if(caa==cba)
{
cout<<binpow(2,n-3,mod);return 0;
}
if(cba=cab)
{
cout<<fib[n-3];
}
}
}
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define int ll
using ll = long long;
using P = pair<int, int>;
using int128 = __int128_t;//cin coutはできない
const int mod = 998244353;
struct mint{
ll x;
mint(ll x=0):x((x%mod+mod)%mod){}
mint operator-() const { return mint(-x); }
mint& operator+=(const mint a){
if((x+=a.x) >= mod) x -= mod;
return *this;
}
mint& operator-=(const mint a){
if((x += mod-a.x) >= mod) x -= mod;
return *this;
}
mint& operator*=(const mint a){
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const {
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 pow(ll t) const {
if(!t) return 1;
mint a = pow(t >> 1);
a *= a;
if(t&1) a *= *this;
return a;
}
mint inv() const {
return pow(mod - 2);
}
mint& operator/=(const mint a) {
return (*this) *= a.inv();
}
mint operator/(const mint a) const {
mint res(*this);
return res /= a;
}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
struct UnionFind {
//vector d
//親のノードを記録する
//親の場合は-(木の要素数)を記録する
vector<int> d;
UnionFind(int n = 0) : d(n, -1) {} //constructor
int find(int x){
//find root
if(d[x] < 0){
return x;
}
return d[x] = find(d[x]);
}
bool unite(int x, int y){
x = find(x);
y = find(y);
if(x == y)
return false;
//xの木の方が、yの木よりも小さくないといけない
if(-d[x] > -d[y]){
swap(x, y);
}
d[x] += d[y];//yの木の要素数をxの木の要素数に合算する
d[y] = x;//yの親をxにする
return true;
}
bool same(int x, int y){
return find(x) == find(y);
}
int size(int x){
return -d[x];
}
};
signed main(){
int n, k;
cin >> n >> k;
vector<vector<int>> a(n, vector<int>(n));
rep(i,n)rep(j,n) cin >> a[i][j];
UnionFind ufx(n), ufy(n);
for(int x = 0; x < n - 1; x++){
for(int y = x+1; y < n ; y++){
bool isOK = true;
for(int i = 0; i < n; i++){
if(a[i][x] + a[i][y] > k) isOK = false;
}
if(isOK) ufx.unite(x, y);
}
}
for(int x = 0; x < n - 1; x++){
for(int y = x+1; y < n ; y++){
bool isOK = true;
for(int i = 0; i < n; i++){
if(a[x][i] + a[y][i] > k) isOK = false;
}
if(isOK) ufy.unite(x, y);
}
}
vector<mint> fact(n+1);
fact[0] = 1;
rep(i,n) fact[i+1] = fact[i] * (i+1);
mint ans = 1;
rep(i,n){
if(ufx.find(i) == i) ans *= fact[ufx.size(i)];
}
rep(i,n){
if(ufy.find(i) == i) ans *= fact[ufy.size(i)];
}
cout << ans << endl;
} |
#include <bits/stdc++.h>
using namespace std;
//basic input and data type
#define ll long long
#define loop(a,b) for(ll int i=a;i<b;i++)
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define ss(s) scanf("%s",s)
#define pi(x) printf("%d\n",x)
#define pl(x) printf("%lld\n",x)
#define ps(s) printf("%s\n",s)
//debugging
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
//vector functions
#define pb push_back
#define mp make_pair
#define F first
#define S second
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;
// solution
void solve()
{
string s;
cin>>s;
ll int cnt=0;
ll int i;
for(i=0;i<s.size();i++)
{
if(i+3<s.size()&&s[i]=='Z'&&s[i+1]=='O'&&s[i+2]=='N'&&s[i+3]=='e')
{
cnt++;
i=i+3;
}
}
cout<<cnt<<endl;
}
//main function
int main()
{
ll int t=1;
//sl(t);
while(t--)
{
solve();
}
return(0);
} | #include<bits/stdc++.h>
using namespace std;
int const maxn=2e5+10;
int noded=0,tot,cou,son[maxn],head[maxn],n,m,deep[maxn],fa[maxn],ans[maxn];
struct edge{
int v,nxt;
}e[maxn<<1];
void build(int x,int y){
e[++tot].v=y;
e[tot].nxt=head[x];
head[x]=tot;
}
void getans(int x){
ans[x]=++cou;
for(int i=head[x];i;i=e[i].nxt){
int v=e[i].v;
if(v==fa[x]||v==son[x])continue;
getans(v);
++cou;
}
if(son[x])getans(son[x]);
}
void dfs(int x,int f,int d){
deep[x]=d;
fa[x]=f;
if(deep[noded]<=d){
noded=x;
}
for(int i=head[x];i;i=e[i].nxt){
int v=e[i].v;
if(v==f)continue;
dfs(v,x,d+1);
}
}
int main(){
scanf("%d",&n);
tot=0,cou=0;
int a,b;
for(int i=1;i<n;i++){
scanf("%d%d",&a,&b);
build(a,b);
build(b,a);
}
dfs(1,0,0);
int s=noded;
dfs(s,0,0);
// cout<<s<<' '<<noded<<endl;
for(int i=noded;i;i=fa[i]){
son[fa[i]]=i;
}
getans(s);
for(int i=1;i<n;i++)printf("%d ",ans[i]);
printf("%d\n",ans[n]);
return 0;
}
/*
10
1 2
2 3
3 5
2 4
1 6
1 7
7 8
8 9
7 10
*/ |
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
ll num[200100];
int mi = 100099;
bool cmp(int a,int b){
return a > b;
};
int main() {
// ios::sync_with_stdio(0);
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
// memset(s1, 0, sizeof(s1));
// memset(s2, 0, sizeof(s2));
int n;
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> num[i];
}
ll sum = 0;
sort(num+1,num+1+n,cmp);
ll ans= 0;
sum = num[1];
for (ll j = 2; j <= n; ++j) {
ans += abs(sum - (j-1)*num[j]);
sum += num[j];
}
cout << ans;
} | #include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "../debug.h"
#else
#define debug(x...) 141
#endif
#define forn(i,x,n) for(int i = x; i < n; ++i)
#define forit(it, m) for(auto it = m.begin(); it!=m.end(); ++it)
typedef long long ll;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n;
ll ans=0;
cin>>n;
vector<ll> a(n),sum(n+1);
forn(i,0,n)
cin>>a[i];
sort(a.begin(),a.end());
forn(i,1,n+1)
sum[i]=sum[i-1]+a[i-1];
forn(i,0,n)
ans+=sum[n]-sum[i+1]+(n-i-1)*(-a[i])+i*a[i]-sum[i];
cout<<ans/2<<'\n';
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
const int MAX = 3010;
bool dp[MAX][4][32];
void init(){
for(int i=0; i<MAX; i++){
for(int j=0; j<4; j++){
for(int k=0; k<32; k++){
dp[i][j][k] = false;
}
}
}
dp[0][0][0] = true;
}
int main(){
int N;
cin >> N;
vector<vector<int>> vec(N,vector<int>(5));
for(int i=0; i<N; i++){
for(int j=0; j<5; j++){
cin >> vec[i][j];
}
}
int ok = 0;
int ng = 1e9+10;
while(ng - ok > 1){
int mid = (ok+ng)/2;
init();
for(int i=0; i<N; i++){
int B = 0;
for(int j=0; j<5; j++){
if(vec[i][j] >= mid){
B = B | (1<<j);
}
}
for(int j=0; j<4; j++){
for(int k=0; k<32; k++){
if(dp[i][j][k]){
//使う
if(j < 3){
dp[i+1][j+1][k|B] = true;
}
//使わない
dp[i+1][j][k] = true;
}
}
}
}
if(dp[N][3][31]){
ok = mid;
}
else{
ng = mid;
}
}
cout << ok << endl;
} | #include<bits/stdc++.h>
//#pragma GCC optimize "trapv"
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
#define fast_az_fuk ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll int
#define lll __int128
#define ull unsigned ll
#define ld long double
#define pb push_back
#define pf push_front
#define dll deque<ll>
#define vll vector<ll>
#define vvll vector<vll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define dpll deque<pll>
#define mapll map<ll,ll>
#define umapll umap<ll,ll>
#define endl "\n"
#define all(v) v.begin(),v.end()
#define ms(a,x) memset(a,x,sizeof(a))
#define random(l,r,T) uniform_int_distribution<T>(l,r)(rng)
//#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//using namespace __gnu_pbds;
template<typename T> istream& operator >>(istream &in,vector<T> &v){ for(auto &x:v) in>>x; return in;}
template<typename T> ostream& operator <<(ostream &out,vector<T> &v){ for(auto &x:v) out<<x<<' '; return out;}
template<typename T1,typename T2> istream& operator >>(istream &in,pair<T1,T2> &p){ in>>p.first>>p.second; return in;}
template<typename T1,typename T2> ostream& operator <<(ostream &out,pair<T1,T2> &p){ out<<p.first<<' '<<p.second; return out;}
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
// http://xorshift.di.unimi.it/splitmix64.c
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
template<class T, class H>using umap=unordered_map<T,H,custom_hash>;
template<class T>using uset=unordered_set<T,custom_hash>;
int32_t main()
{
clock_t clk = clock();
fast_az_fuk
ll n; cin>>n; vvll v(n,vll(5,0)); cin>>v;
ll l = 1,r = 1e9; ll ans;
while(l <= r){
ll p = (r + l) /2;
vll mask(n,0);
for(ll i=0;i<n;i++){
for(ll j=0;j<5;j++) if(v[i][j] >= p) mask[i] += (1<<j);
}
const ll M = (1<<5)-1;
vvll hash(n,vll(1<<5,0)); bool flag=0;
for(ll i=0;i<n;i++){
for(ll j=i+1;j<n;j++){
hash[j][mask[j]|mask[i]]=1;
}
}
for(ll i=1;i<n;i++){
for(ll j=0;j<=M;j++){
hash[i][j] |= (hash[i-1][j]);
}
}
for(ll i=2;i<n;i++){
ll msk = (mask[i]^M); stack<ll> st; st.push(msk);
while(!st.empty()){
msk = st.top(); st.pop();
if(hash[i-1][msk]) {flag=1; break;}
for(ll k=0;k<5;k++) if(!(msk&(1<<k))) {
msk^=(1<<k); st.push(msk); msk^=(1<<k);
}
}
}
if(flag) {
ans = p; l = p+1;
}
else r = p-1;
}
cout<<ans;
// cerr << '\n'<<"Time (in s): " << double(clock() - clk) * 1.0 / CLOCKS_PER_SEC << '\n';
return 0;
} |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define MOD 1000000007
#define INF 1000000000
#define ff first
#define ss second
typedef long long ll;
ll power(ll a, ll b){//a^b
ll res=1;
a=a%MOD;
while(b>0){
if(b&1){res=(res*a)%MOD;b--;}
a=(a*a)%MOD;
b>>=1;
}
return res;
}
ll fermat_inv(ll y){return power(y,MOD-2);}
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t1=1;
//cin>>t;
while(t1--){
int n,k;
cin>>n>>k;
string s;
cin>>s;
for(int j=0;j<k;j++){
string t=s+s;
s="";
for(int i=0;i<2*n;i+=2){
if(t[i]==t[i+1])
s+=t[i];
else if((t[i]=='R'&&t[i+1]=='S')||(t[i]=='S'&&t[i+1]=='R'))
s+='R';
else if((t[i]=='S'&&t[i+1]=='P')||(t[i]=='P'&&t[i+1]=='S'))
s+='S';
else if((t[i]=='R'&&t[i+1]=='P')||(t[i]=='P'&&t[i+1]=='R'))
s+='P';
}
}
cout<<s[0]<<"\n";
}
return 0;
} | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
ll n,k;
vector<string> s(101);
char a;
int main(){
cin>>n>>k>>s[0];
rep(i,k){
rep(j,n)s[i].push_back(s[i][j]);
rep(j,n){
if(s[i][2*j]==s[i][2*j+1])a=s[i][2*j];
else if((s[i][2*j]=='R' && s[i][2*j+1]=='S') || (s[i][2*j]=='S' && s[i][2*j+1]=='R'))a='R';
else if((s[i][2*j]=='P' && s[i][2*j+1]=='R') || (s[i][2*j]=='R' && s[i][2*j+1]=='P'))a='P';
else a='S';
s[i+1].push_back(a);
}
}
cout<<s[k][0]<<endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < n; ++i)
using ll = long long;
using P = pair<int,int>;
// auto mod int
const int mod = 1000000007;//998244353;
struct mint {
ll x; // typedef long long ll;
mint(ll x=0):x((x%mod+mod)%mod){}
mint operator-() const { return mint(-x);}
mint& operator+=(const mint a) {
if ((x += a.x) >= mod) x -= mod;
return *this;
}
mint& operator-=(const mint a) {
if ((x += mod-a.x) >= mod) x -= mod;
return *this;
}
mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
mint operator+(const mint a) const { return mint(*this) += a;}
mint operator-(const mint a) const { return mint(*this) -= a;}
mint operator*(const mint a) const { return mint(*this) *= a;}
mint pow(ll t) const {
if (!t) return 1;
mint a = pow(t>>1);
a *= a;
if (t&1) a *= *this;
return a;
}
// for prime mod
mint inv() const { return pow(mod-2);}
mint& operator/=(const mint a) { return *this *= a.inv();}
mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
ll dp1[2001][2001];
ll dp2[2001][2001];
int main() {
int h,w;cin>>h>>w;
vector<string> v;
string last(w+1,'#');
rep(i,h){
string s;cin>>s;
v.push_back(s);
v[i].push_back('#');
}
int sum=0;
rep(i,h)rep(j,w)sum+=(v[i][j]=='.');
rep(i,h){
rep(j,w){
dp1[i][j]=dp2[i][j]=(v[i][j]=='.');
}
}
rep(i,h){
rep(j,w-1){
if(v[i][j+1]=='.'&&v[i][j]=='.'){
dp1[i][j+1]=dp1[i][j]+1;
}
}
}
rep(i,h){
for (int j = w - 1; j > 0; j--)
{
if(v[i][j-1]=='.'&&v[i][j]=='.'){
dp1[i][j-1]=dp1[i][j];
}
}
}
rep(j,w){
rep(i,h-1){
if(v[i+1][j]=='.'&&v[i][j]=='.'){
dp2[i+1][j]=dp2[i][j]+1;
}
}
}
rep(j,w){
for (int i = h-1; i > 0; i--)
{
if(v[i-1][j]=='.'&&v[i][j]=='.'){
dp2[i-1][j]=dp2[i][j];
}
}
}
mint ans=0;
mint two=2;
rep(i,h){
rep(j,w){
if(v[i][j]=='.')
ans+=(two.pow(dp1[i][j]+dp2[i][j]-1)-1)*two.pow(sum-dp1[i][j]-dp2[i][j]+1);
}
}
cout<<ans<<endl;
} | /**
* Written by : Ujjawal Pabreja [cuber_coder]
* Email : [email protected]
*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
#define endl "\n"
const int mod = 1e9 + 7;
const int MAX = 2e5 + 1;
ll power(ll x, ll p) {
ll ans = 1;
while (p) {
if (p & 1) {
ans = (ans * x) % mod;
p--;
}
x = (x * x) % mod;
p >>= 1;
}
return ans;
}
ll add(ll x, ll y) {
return ((x % mod) + (y % mod)) % mod;
}
ll mul(ll x, ll y) {
return ((x % mod) * (y % mod)) % mod;
}
ll sub(ll x, ll y) {
return ((x % mod) - (y % mod) + mod) % mod;
}
void Solve() {
ll n, m;
cin >> n >> m;
string s[n];
ll tidy = 0;
for (int i = 0; i < n; i++) {
cin >> s[i];
for (int j = 0; j < m; j++) {
tidy += (s[i][j] == '.');
}
}
vector <vector <ll>> a(n, vector <ll>(m));
for (int j = 0; j < m; j++) {
for (int i = 0; i < n; ) {
if (s[i][j] == '#') {
i++;
continue;
}
int k = i + 1, len = 1;
while (k < n and s[k][j] == '.') {
len++;
k++;
}
while (i < k) {
a[i][j] = len;
i++;
}
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m;) {
if (s[i][j] == '#') {
j++;
continue;
}
int k = j + 1, len = 1;
while (k < m and s[i][k] == '.') {
len++;
k++;
}
while (j < k) {
a[i][j] += len;
j++;
}
}
}
// for (int i = 0; i < n; i++) {
// for (int j = 0; j < m; j++) {
// cout << a[i][j] << " ";
// }
// cout << endl;
// }
ll ans = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (s[i][j] == '#') {
continue;
}
ll tot = a[i][j] - 1;
ll ways = sub(power(2, tot), 1);
ans = add(ans, mul(ways, power(2, tidy - tot)));
}
}
cout << ans;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int testcases = 1;
// cin >> testcases;
while (testcases--) {
Solve();
}
} |
#include <iostream>
#include <algorithm>
#include <string>
#include <complex>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
#include <numeric> //lcm
#include <iomanip> //double精度 setprecision
#include <chrono>
#include <random>
#include <cassert>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
#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 >= 1; --i)
#define REP(i,n,m) for(int i = (n); i < (m); ++i)
#define all(vec) (vec).begin(),(vec).end()
#define debug(a) { cerr << #a << " = " << a << endl;}
#define debugV(vec) { cerr << #vec << " : "; for(auto v : vec) cerr << v << " "; cerr << endl; }
#define debug2D(vec2D, w) { cerr << #vec2D << endl; for(auto vec : vec2D) { for (auto v : vec) cerr << setw(w) << v << " "; cerr << endl; } }
#define debugVP(vec) { cerr << #vec << " : "; for(auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl;}
#define debug2DP(vec2D) { cerr << #vec2D << endl; for(auto vec : vec2D) { for (auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl; } }
typedef long long ll;
constexpr ll INF = 1e14; //32 ~2*10^10 //64 ~9*10^19
//constexpr ll MOD = 998244353;
constexpr ll MOD = 1000000007;
const double EPS = round(1e-6);
const char en = '\n';
struct Edge {
Edge(int _s, int _t, ll _cost = 1) : from(_s), to(_t), cost(_cost) {};
int from, to;
ll cost;
//ll fee;
};
typedef vector<vector<Edge>> Graph;
void add_edge(Graph& g, int from, int to, ll cost = 1) {
g[from].push_back(Edge(from, to, cost));
}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } else return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } else return false; }
//int dx[4] = {0,1,0,-1}, dy[4] = {1,0,-1,0};
void solve() {
ll n; cin >>n;
ll ans = 0;
auto f = [&](int a, int m) {
bool ok = true;
while (a > 0) {
if (a % m == 7) { ok = false; break;}
a /= m;
}
return ok;
};
rep1(i, n) {
if (f(i,10) && f(i,8)) ++ans;
}
cout << ans <<en;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
//rep(i,3)
solve();
} | #include<bits/stdc++.h>
using namespace std;
#define ll long long
bool decimal(ll n)
{
while(n)
{
int r=n%10;
if(r==7)
return true;
n/=10;
}
return false;
}
bool octal(ll n)
{
while(n)
{
int r=n%8;
if(r==7)
return true;
n/=8;
}
return false;
}
int main()
{
ll n;
cin>>n;
int a[n+1];
memset(a,0,sizeof(a));
for(int i=1;i<=n;i++){
if(a[i]==0){
if(decimal(i))
a[i]=1;
else if(octal(i))
a[i]=1;
}
}
int ans = 0;
for(int i=1;i<=n;i++)
if(a[i]==0)
ans++;
cout<<ans<<endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;
ll scnt[10], tcnt[10];
bool win(){
ll a = 0;
rep(i, 1, 9){
a += i * pow(10, scnt[i]);
}
ll b = 0;
rep(i, 1, 9){
b += i * pow(10, tcnt[i]);
}
//cout << a << " " << b << endl;
return a > b;
}
int main(){
cin.tie(0); ios::sync_with_stdio(false);
ll k; cin >> k;
string s, t; cin >> s >> t;
vector<ll> cnt(10, k);
zep(i, 0, 4){
scnt[s[i] - '0']++;
cnt[s[i] - '0']--;
}
zep(i, 0, 4){
tcnt[t[i] - '0']++;
cnt[t[i] - '0']--;
}
//printa(scnt, 1, 9)
ll ans = 0;
rep(i, 1, 9){
if(cnt[i] > 0){
ll x = cnt[i];
cnt[i]--;
scnt[i]++;
rep(j, 1, 9){
if(cnt[j] > 0){
ll tmp = x * cnt[j];
cnt[j]--;
tcnt[j]++;
//cout << i << " " << j << endl;
if(win())ans += tmp;
tcnt[j]--;
cnt[j]++;
}
}
scnt[i]--;
cnt[i]++;
}
}
cout << fixed << setprecision(20) << double(ans) / ((9 * k - 8) * (9 * k - 9)) << endl;
return 0;
} | #include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;
#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int main(){
ll H,W,N,M;
cin>>H>>W>>N>>M;
v A(N),B(N);
v C(M),D(M);
vv ans_grid(H,v(W,0));
rep(i,0,N){
cin>>A[i]>>B[i];A[i]--;B[i]--;
ans_grid[A[i]][B[i]] = 2;
}
rep(i,0,M){
cin>>C[i]>>D[i];C[i]--;D[i]--;
ans_grid[C[i]][D[i]] = -1;
}
rep(i,0,H){
bool br = false;
rep(j,0,W){
if(ans_grid[i][j] == 2)br = true;
else if(ans_grid[i][j] == -1)br = false;
else if(br) ans_grid[i][j] = 1;
}
}
rep(i,0,H){
bool br = false;
for(ll j = W-1;j >= 0; j--){
if(ans_grid[i][j] == 2)br = true;
else if(ans_grid[i][j] == -1)br = false;
else if(br)ans_grid[i][j] = 1;
}
}
rep(j,0,W){
bool br = false;
rep(i,0,H){
if(ans_grid[i][j] == 2)br = true;
else if(ans_grid[i][j] == -1)br = false;
else if(br)ans_grid[i][j] = 1;
}
}
rep(j,0,W){
bool br = false;
for(ll i = H-1;i >= 0; i--){
if(ans_grid[i][j] == 2)br = true;
else if(ans_grid[i][j] == -1)br = false;
else if(br)ans_grid[i][j] = 1;
}
}
ll ans = 0;
rep(i,0,H)rep(j,0,W){
if(ans_grid[i][j] >= 1)ans++;
//cout<<ans_grid[i][j];
}
cout<<ans;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define codeWizard ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define testCase(tc) while(tc--)
#define vi vector<int>
#define vvi vector<vi>
#define pi pair<int,int>
#define int long long
#define lb lower_bound
#define ub upper_bound
#define mod 1000000007
//#define mod 998244353
#define ff first
#define ss second
#define inf (int)1e17
#define ninf -inf
#define endl "\n"
#define fill(a,b) memset(a,b,sizeof(a))
#define all(v) v.begin(),v.end() //codeWizard
int LCM(int a, int b) {return (a * b) / __gcd(a, b);}
void init_code() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
int n;
vvi player;
bool check(int x){
set<int> st;
for(auto k:player){
int bit=0;
int i=0;
for(auto i:k){
bit <<= 1;
bit |= i >= x;
}
st.insert(bit);
}
for(auto x:st){
for(auto y:st){
for(auto z:st){
if((x|y|z)==31)
return true;
}
}
}
return false;
}
void solve(){
cin>>n;
for(int i=1;i<=n;i++){
vector<int> temp(5);
for(int j=0;j<5;j++)
cin>>temp[j];
player.push_back(temp);
}
int low=1,high=1000000001;
int ans=0;
while(high>low+1){
//cout<<low<<" "<<high<<endl;
int mid=(low+high)/2;
if(check(mid)){
low=mid;
}
else
high=mid;
}
cout<<low<<endl;
}
signed main()
{
codeWizard;
init_code();
int tc = 1;
//cin >> tc;
int num=1;
testCase(tc) {
//cout<<"Case #"<<num<<": ";
num++;
solve();
}
//cout << "Time execute: " << clock() / (double)CLOCKS_PER_SEC << " sec" << endl;
}
| #include<bits/stdc++.h>
using namespace std;
int mod=1e9+7;
const int N=2e5+5;
int32_t main()
{
int ans=0;
int n;
cin>>n;
vector<vector<int> > a(n,vector<int> (5));
vector<vector<int> > dp(5);
for(int i=0;i<n;i++)
{
for(int j=0;j<5;j++)
{
cin>>a[i][j];
dp[j].push_back(a[i][j]);
}
}
for(int i=0;i<5;i++)
{
sort(begin(dp[i]),end(dp[i]),greater<int> ());
}
for(int i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
{
int ind;
int mini=1e9;
for(int k=0;k<5;k++)
{
if(max(a[i][k],a[j][k])<mini)
{
ind=k;
mini=max(a[i][k],a[j][k]);
}
}
int val=1e9;
for(int k=0;k<5;k++)
{
if(k!=ind)
val=min(val,max(a[i][k],a[j][k]));
}
if(dp[ind][0]!=a[i][ind]&&dp[ind][0]!=a[j][ind])
val=min(val,dp[ind][0]);
else if(dp[ind][1]!=a[i][ind]&&dp[ind][1]!=a[j][ind])
val=min(val,dp[ind][1]);
else
val=min(val,dp[ind][2]);
ans=max(ans,val);
}
}
cout<<ans<<endl;
} |
#include <sys/time.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <utility>
#include <cctype>
#include <cstdlib>
#include <typeinfo>
/*
#include <atcoder/all>
using namespace atcoder;
*/
/*
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
using BigInt = mp::cpp_int;
*/
// https://yamakasa.net/atcoder-abc-029-d/
using namespace std;
using ll = long long;
using i_i = pair<int, int>;
using l_l = pair<ll, ll>;
using ld = long double;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mkp(a, b) make_pair(a, b)
const ll MOD = 1000000007LL;
const ll INF = 1e9;
const ld gomi = 0.0000000000001;
int main() {
ll k;
cin >> k;
ll count = 0;
for(ll a = 1; a <= k; a++) {
for(ll b = 1; b <= k; b++) {
if (a * b > k) break;
int c_max = k / (a * b);
count += c_max;
}
}
cout << count << endl;
return 0;
}
| #include <iostream>
#include <string>
#include <array>
#include <vector>
#include <set>
#include <map>
#define INI_1(N) N
#define INI_5(N) N, N, N, N, N
#define INT_10(N) INT_5(N), INT_5(N)
#define INT_20(N) INT_10(N), INT_10(N)
#define INT_50(N) INT_10(N), INT_20(N), INT_20(N)
#define INT_100(N) INT_50(N), INT_50(N)
#define INT_1000(N) INT_100(N), INT_100(N), INT_100(N), \
INT_100(N), INT_100(N), INT_100(N), \
INT_100(N), INT_100(N), INT_100(N), \
INT_100(N)
template <typename T>
using vector = std::vector<T>;
template <typename T, std::size_t N>
using array = std::array<T, N>;
using string = std::string;
template <typename T>
using set = std::set<T>;
template <typename T, typename U>
using map = std::map<T, U>;
template <typename T, typename U>
using pair = std::pair<T, U>;
using std::cin;
using std::cout;
int main(void) {
int n;
cin >> n;
cout << (n / 100) + (n%100 != 0) << '\n';
}
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
bool solve(int v, int c, vector<vector<int>>& G, vector<int>& color) {
if (color[v] != -1) {
if (color[v] != 2 && color[v] != c) {
color[v] = -2;
return false;
} else {
return true;
}
}
bool res = true;
int n = G.size();
color[v] = c;
rep(i, n) {
if (G[v][i] == 0) continue;
res &= solve(i, c ^ 1, G, color);
}
return res;
}
int main() {
ll n, m;
cin >> n >> m;
vector<int> a(m), b(m);
vector<vector<int>> G(n, vector<int>(n, false));
rep(i, m) {
cin >> a[i] >> b[i];
a[i]--, b[i]--;
G[a[i]][b[i]] = 1;
G[b[i]][a[i]] = 1;
}
ll ans = 0;
for (int bit = 0; bit < (1 << n); bit++) {
vector<vector<int>> G2 = G;
vector<int> color(n, -1);
rep(i, n) {
if (bit >> i & 1) {
color[i] = 2;
rep(j, n) {
G2[i][j] = 0;
G2[j][i] = 0;
}
}
}
bool ok = true;
rep(i, m) if (color[a[i]] == 2 && color[b[i]] == 2) ok = false;
if (!ok) continue;
ll tmp = 1;
rep(i, n) {
if (color[i] == -1 && solve(i, 0, G, color)) {
tmp *= 2;
}
}
rep(i, n) if (color[i] == -2) ok = false;
if (ok) ans += tmp;
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, m; cin >> n >> m;
vector<vector<int>> adj(n);
for (int i = 0; i < m; ++i) {
int u, v; cin >> u >> v; --u, --v;
adj[u].push_back(v);
adj[v].push_back(u);
}
vector<bool> vis(n, 0);
int sz;
function<void(int)> dfs1 = [&](int u) {
sz++;
vis[u] = 1;
for (int v : adj[u])
if (!vis[v]) dfs1(v);
};
int offset, pos;
vector<int> colour(n);
function<bool(int)> dfs2 = [&](int u) {
pos++;
for (int v : adj[u]) {
if (colour[v] == colour[u]) {
return false;
}
if (colour[v] == -1) {
colour[v] = (colour[u] + ((offset >> pos) & 1) + 1) % 3;
if (!dfs2(v)) return false;
}
}
return true;
};
long long ans = 1;
for (int i = 0; i < n; ++i) {
if (vis[i]) continue;
sz = 0;
dfs1(i);
int cur = 0;
for (offset = 0; offset < (1 << (sz - 1)); ++offset) {
colour.assign(n, -1);
colour[i] = 0;
pos = -1;
if (dfs2(i)) cur += 3;
}
ans *= cur;
}
cout << ans << '\n';
return 0;
} |
#include<bits/stdc++.h>
#define endl '\n'
#define ll long long
#define ld long double
#define ull unsigned long long
using namespace std;
struct _IO{_IO(){ios::sync_with_stdio(0);cin.tie(0);}}_io;
const ll mod=10;
int g=0;
int a[100000][2];
ld cmp(ld a,ld b){
return a>b;
}
ll qpow(ll a,ll b){
ll ans=1,x=a,y=b;
while(y!=0){
if(y%2==1){
ans*=x;
}
ans%=mod;
y/=2;
x%=mod;
x*=x;
x%=mod;
}
return ans;
}
int main(){
int n;
cin>>n;
int a[n];
int maxn=0;
for(int i=0;i<n;i++){
cin>>a[i];
maxn=max(maxn,a[i]);
}
int ans=1,anss=0;
for(int i=2;i<=maxn;i++){
int g=0;
for(int j=0;j<n;j++){
if(a[j]%i==0&&a[j]/i>=1){
g++;
}
}
if(g>=anss){
ans=i;
anss=g;
}
}
cout<<ans<<endl;
} | ///ShzFahad
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n;
cin >> n;
map<string,ll>mp;
while(n--)
{
string s;
cin >> s;
mp[s]++;
}
for(auto it=mp.begin();it!=mp.end();it++)
{
string k = it->first;
if(k[0]=='!')
{
string x = k.substr(1,k.size()-1);
auto it2 = mp.find(x);
if(it2!=mp.end())
{
cout << x << endl;
return 0;
}
}
}
cout << "satisfiable" << endl;
}
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
const ll INF = 1e18;
ios_base::sync_with_stdio(0);
cin.tie(0);
int n; ll x;
cin >> n >> x;
vector<ll> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
// number of possible values of y
// y, y-x use no overlapping coins
reverse(a.begin(), a.end());
vector<ll> X(n);
vector<ll> B(n);
for (int i = 0; i < n; i++) {
if (x >= a[i]) {
X[i] = x / a[i];
x %= a[i];
}
if (i == 0) {
B[i] = INF;
} else {
B[i]= a[i - 1] / a[i];
}
}
vector<vector<ll>> dp(n + 1, vector<ll>(2, 0));
// you did up to that place, and there was carry over or not, and you only want carry over if next digit will be 0
X.insert(X.begin(), -1);
B.insert(B.begin(), -1);
a.insert(a.begin(), -1);
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
// there is carry, then current digit is 0
dp[i][1] += dp[i - 1][1];
if (X[i] != 0)
dp[i][0] += dp[i - 1][1];
// there is no carry
dp[i][0] += dp[i - 1][0];
if (X[i] != B[i] - 1)
dp[i][1] += dp[i - 1][0];
}
ll ans = dp[n][0];
cout << ans << '\n';
return 0;
} | //Author: Fuadul Hasan([email protected])
//BSMRSTU,Gopalganj
//#include<bits/stdc++.h>
#define _USE_MATH_DEFINES
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <random>
#include<iomanip>
#include <cassert>
#include <cstring>
#include <sstream>
#include <complex>
#include <numeric>
#include <iostream>
#include <algorithm>
#include <functional>
#include <unordered_set>
#include <unordered_map>
using namespace std;
//debug..........
#define error(args...) {vector<string>_v=split(#args,',');err(_v.begin(),args);cout<<endl;}
vector<string> split(const string &s, char c) {vector<string>v; stringstream ss(s); string x;while (getline(ss, x, c))v.emplace_back(x); return move(v);} void err(vector<string>::iterator it) {}
template<typename T, typename... Args>void err(vector<string>::iterator it, T a, Args...args) {cout << it->substr((*it)[0] == ' ', it->length()) << " = " << a << " "; err(++it, args...);}
//............ignore it..................//
#define F first
#define S second
#define Pi atan(1)*4
#define mp make_pair
#define pb push_back
const int M = 1e9 + 7;
#define ld long double
#define ll long long int
#define happy cin.tie(0);
#define point(x) cout<<fixed<<setprecision(x)
int length(string s){return (int)s.size();}
#define mem(a) memset(a , 0 ,sizeof a)
#define memn(a) memset(a , -1 ,sizeof a)
#define coding ios::sync_with_stdio(false);
#define Unique(c) (c).resize(unique(all(c))-(c).begin())
#define vout(v) for (auto z: v) cout << z << " "; cout << endl;
int length(long long x){int l = 0;for(long long i=x;i;i/=10)l++;return l;}
int dx[8]= {1,0,-1,0,-1,-1,1,1};
int dy[8]= {0,1,0,-1,-1,1,-1,1};
#define rep(i,b,e) for(__typeof(e) i = (b) ; i != (e + 1) - 2 * ((b) > (e)) ; i += 1 - 2 * ((b) > (e)))
long long Inv_pow(long long a,long long n){ll res = 1;while(n){if(n&1) res = ((res%M)*(a%M))%M;a = ((a%M)*(a%M))%M;n>>=1;}return res%M;}
// suffix_prefix....
std::vector<ll> prefix_sum(std::vector<ll> a){int n = a.size();std::vector<ll> prf(n,0);for(int i=0;i<n;i++){
if(i == 0){prf[i] = a[i];}else{prf[i] = prf[i-1]+a[i];}}return prf;}
std::vector<ll> suffix_sum(std::vector<ll> a){int n = a.size();std::vector<ll>suf(n,0);for(int i=n-1;i>=0;i--){
if(i == n-1){suf[i] = a[i];}else{suf[i] = suf[i+1]+a[i];}}return suf;}
long long Lcm(long long a,long long b){return (((a)*(b)))/__gcd(a,b);}
#define Test cout<<"Case #"<<tc++<<": ";
int tc = 1;
inline void read(std::vector<int> &v){for(int i=0;i<(int)v.size();i++){cin>>(v[i]);}}
inline void readl(std::vector<ll> &v){for(int i=0;i<(int)v.size();i++){cin>>(v[i]);}}
template<class T> bool remin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool remax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
inline void read(int v[],int n){for(int i=0;i<n;i++){cin>>(v[i]);}}
inline void readl(ll v[],int n){for(int i=0;i<n;i++){cin>>(v[i]);}}
inline int add(int a, int b, int mod) {a += b ; return a >= mod ? a - mod : a ;}
inline int sub(int a, int b, int mod) {a -= b ; return a < 0 ? a + mod : a ;}
inline int mul(int a, int b, int mod) {return (ll)a * b % mod ;}
#define pr pair<int, int>
#define vpr vector<pr>
#define vi std::vector<int>
#define vll std::vector<ll>
#define all(n) n.begin(),n.end()
const int Inf = (int)2e9 + 5;
const ll Lnf = (ll)2e18 + 5;
const int N = 5e5 + 5;
const int NN = 1e6 + 5;
int solve()
{
//Test
int a,b;
cin>>a>>b;
double x = (double)b / 100.0;
cout<<(double)a*x<<endl;
return 0;
//error();
}
int main(){
happy coding
int test = 1;
//cin>>test;
while (test--)solve();return 0;
}
/*
1. Everything happens for something good.
2. Don't expect anything from anyone except yourself.
3. Self discipline is the magic power that makes you unstoppable.
*/
|
#include <bits/stdc++.h>
using namespace std;
class Node {
public:
int x;
int y;
int cost;
Node() {}
Node(int _x, int _y, int _cost) {
x = _x;
y = _y;
cost = _cost;
}
};
class Point {
public:
int x;
int y;
Point() {}
Point(int _x, int _y) {
x = _x;
y = _y;
}
};
int main()
{
int h, w;
cin >> h >> w;
vector<vector<char>> board(h, vector<char>(w, ' '));
vector<vector<int>> cost(h, vector<int>(w, 1e9));
vector<vector<Point>> tele(26);
int startx = -1, starty = -1, goalx = -1, goaly = -1;
for (int x = 0; x < h; x++) {
for (int y = 0; y < w; y++) {
char ch = getchar();
while (ch == '\n') {
ch = getchar();
}
board.at(x).at(y) = ch;
switch (ch) {
case 'S':
startx = x;
starty = y;
break;
case 'G':
goalx = x;
goaly = y;
break;
case '#':
cost[x][y] = -1;
break;
case '.':
break;
default:
tele.at(ch - 'a').emplace_back(x, y);
break;
}
}
getchar(); // LF
}
vector<bool> tele_is_alive(26, true);
queue<Node> q;
q.emplace(startx, starty, 0);
while (!q.empty()) {
auto n = q.front();
q.pop();
if (n.x < 0 || h <= n.x || n.y < 0 || w <= n.y) {
continue;
}
if (cost.at(n.x).at(n.y) <= n.cost) {
continue;
}
cost.at(n.x).at(n.y) = n.cost;
if (n.x == goalx && n.y == goaly) {
break;
}
char ch = board.at(n.x).at(n.y);
if ('a' <= ch && ch <= 'z' && tele_is_alive.at(ch-'a')) {
for (auto p : tele.at(ch-'a')) {
q.emplace(p.x, p.y, n.cost+1);
}
tele_is_alive.at(ch-'a') = false;
}
q.emplace(n.x+1, n.y, n.cost+1);
q.emplace(n.x-1, n.y, n.cost+1);
q.emplace(n.x, n.y+1, n.cost+1);
q.emplace(n.x, n.y-1, n.cost+1);
}
if (cost.at(goalx).at(goaly) == 1e9) {
cout << "-1\n";
} else {
cout << cost.at(goalx).at(goaly) << '\n';
}
return 0;
}
| #include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <stack>
#include <cassert>
#include <map>
#include <numeric>
#include <cstring>
#include <set>
#include <ctime>
#include <queue>
#include <cmath>
#include <iomanip>
#include <iterator>
using namespace std;
class InputReader {
public:
InputReader() {}
InputReader(const char *file_name) {
input_file = fopen(file_name, "r");
cursor = 0;
fread(buffer, SIZE, 1, input_file);
}
inline InputReader &operator >>(int &n) {
while((buffer[cursor] < '0' || buffer[cursor] > '9') && buffer[cursor] != '-') {
advance();
}
int sign = 1;
if (buffer[cursor] == '-') {
sign = -1;
advance();
}
n = 0;
while('0' <= buffer[cursor] && buffer[cursor] <= '9') {
n = n * 10 + buffer[cursor] - '0';
advance();
}
n *= sign;
return *this;
}
private:
FILE *input_file;
static const int SIZE = 1 << 17;
int cursor;
char buffer[SIZE];
inline void advance() {
++ cursor;
if(cursor == SIZE) {
cursor = 0;
fread(buffer, SIZE, 1, input_file);
}
}
};
const int MAXN = 200000;
char s[1 + MAXN];
char t[3];
bool check(int start, int n) {
t[0] = t[1] = '1';
t[2] = '0';
for (int i = start, j = 0; i <= n; i++, j = (j + 1) % 3) {
if (s[i] != t[j]) {
return false;
}
}
return true;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
//ifstream cin("input.txt");
int n;
long long p = 10000000000L;
cin >> n >> (s + 1);
if (n == 1) {
if (s[1] == '0') {
cout << p << "\n";
} else {
cout << p * 2 << "\n";
}
} else if (n == 2) {
if (s[1] == '0' && s[2] == '0') {
cout << "0\n";
} else if (s[1] == '0' && s[2] == '1') {
cout << p - 1 << "\n";
} else {
cout << p << "\n";
}
} else {
if (s[1] == '0') {
if (check(2, n)) {
int m = 1 + (n - 2) / 3 + 1;
cout << p - m + 1 << "\n";
} else {
cout << "0\n";
}
} else if (s[1] == '1' && s[2] == '0') {
if (check(3, n)) {
int m = 1 + (n - 3) / 3 + 1;
cout << p - m + 1 << "\n";
} else {
cout << "0\n";
}
} else if (s[1] == '1' && s[2] == '1' && s[3] == '0') {
if (n == 3) {
cout << p << "\n";
} else if (check(4, n)) {
int m = 1 + (n - 4) / 3 + 1;
cout << p - m + 1 << "\n";
} else {
cout << "0\n";
}
} else {
cout << "0\n";
}
}
return 0;
} |
/*
In the name of ALLAH
Author : Raashid Anwar
*/
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
#define mod 1000000007
int power(int a,int b) {
int r=1;
while(b) {
if(b&1)
r=(r*a)%mod;
a=(a*a)%mod;
b>>=1;
}
return r;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n,k,m,x,sum=0;
cin>>n>>k>>m;
for(int i=1;i<=n-1;i++) {
cin>>x;
sum+=x;
}
if((n*m-sum<=k))
cout<<max(int(0),n*m-sum)<<"\n";
else
cout<<"-1\n";
}
| #include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
int N,K,M;
cin >> N >> K >> M;
int sum=0;
for(int i=0; i<N-1; i++) {
int ai;
cin >> ai;
sum += ai;
}
for(int i=0; i<=K; i++) {
if((sum + i)/N >= M) {
cout << i << endl;
return 0;
}
}
puts("-1");
}
|
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
#define ll long long
#define pi (3.141592653589)
#define mod 1000000007
#define float double
#define pb push_back
// #define mp make_pair
#define ff first
#define ss second
#define all(c) c.begin(), c.end()
#define min3(a, b, c) min(c, min(a, b))
#define min4(a, b, c, d) min(d, min(c, min(a, b)))
#define rfo(i, a, b) for (int i = (int)a; i >= (int)b; i--)
#define fo(i, a, b) for (int i = (int)a; i <= (int)b; i++)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define see(x) cout << (x) << endl
#define hh cout << endl
#define INF 1e18
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
template <typename C,
typename T = std::decay_t<decltype(*begin(std::declval<C>()))>,
typename std::enable_if<!std::is_same<C, std::string>::value>::type * = nullptr>
std::ostream &operator<<(std::ostream &os, const C &container)
{
bool first = true;
std::stringstream ss;
ss << '[';
for (const auto &x : container)
{
if (!first)
{
ss << ", ";
}
first = false;
ss << x;
}
ss << ']';
return os << ss.str();
}
template <class T1, class T2>
std::ostream &operator<<(std::ostream &os, const std::pair<T1, T2> &p)
{
os << '{' << p.first << ", " << p.second << '}';
return os;
}
ll mod_pow(ll a, ll b)
{
if (b < 0)
return 0;
a %= mod;
if (b == 0)
return 1;
if (b == 1)
return a % mod;
if (b == 2)
return ((a % mod) * (a % mod)) % mod;
return (mod_pow(mod_pow(a, b / 2), 2) * mod_pow(a, b % 2)) % mod;
}
bool isPrime(int n)
{
if (n == 1)
return false;
if (n == 2)
return true;
for (int i = 2; i * i <= n; i++)
{
if (n % i == 0)
return false;
}
return true;
}
int32_t main()
{
fast int tc = 1;
// cin>>tc;
while (tc--)
{
int n, m;
cin >> n;
cin >> m;
int a = 0;
int nl = 0, ol = 0;
nl = ol + m;
int pre[n + 1] = {0};
map<int, int> mp;
vector<int> v;
fo(i, 1, n)
{
int a, b;
cin >> a >> b;
v.push_back(a);
mp[a] += b;
}
sort(all(v));
// for (auto it = next(mp.begin()); it != mp.end();it++){
// // if(it!=mp.begin())
// it->second += prev(it)->second;
// }
for (int i = 0; i < n; i++)
{
if (nl < v[i])
{
break;
}
else
{
nl += mp[v[i]];
mp[v[i]] = 0;
}
}
cout << nl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0,endrep=(n); i<endrep; ++i)
#define rep1(i,n) for(ll i=1,endrep=(n); i<=endrep; ++i)
#define revrep(i,n) for(ll i=(ll)(n)-1; i>=0; --i)
inline constexpr ll Inf = (1ULL << 60) -123456789;
#define fastio cin.tie(0); ios_base::sync_with_stdio(false); cout<<fixed<<setprecision(10);
#define newl '\n'
#define YN(e) ((e)?"Yes":"No")
#define all(a) begin(a),end(a)
#define rall(a) rbegin(a),rend(a)
#define delif(c,pred) (c).erase(remove_if(all(c),(pred)), end(c))
template <class T,class U> bool updmax(T& a, U b) { if(b>a){ a=b; return true;} return false;}
template <class T,class U> bool updmin(T& a, U b) { if(b<a){ a=b; return true;} return false;}
inline constexpr int Mod = 1000000007;
//inline constexpr int Mod = 998244353;
#define dbg(a) cerr << #a << ": " << (a) << endl;
#define dbgs(s) cerr << #s << endl;
#define dbg1(a,n) cerr<<#a<<": "; rep(i,n) cerr<<(a)[i]<<" "; cerr<<endl;
#define dbg2(m,h,w) cerr<<#m<<":"<<endl; rep(i,(h)){ rep(j,(w))cerr<<(m)[i][j]<<" "; cerr<<endl; }
template <class T, class U> ostream& operator << (ostream& os, pair<T,U> v) {os<<v.first<<","<<v.second;return os;}
template <class T, size_t N> ostream& operator << (ostream& os, array<T,N> v) {rep(i,N)os<<v[i]<<(i+1<(ll)N?" ":"");return os;}
int rng(int n) { return rand()/(RAND_MAX+1.0)*n; }
inline constexpr int offset[] = {1,0,-1,0,1};
int main() {
fastio;
ll ans{};
ll N,K;
cin >> N >> K;
vector<array<ll,2>> a(N);
rep(i,N) rep(j,2) cin >> a[i][j];
sort(all(a));
ll p{};
rep(i,N) {
ll c = a[i][0]-p;
if (c > K) break;
K -= c;
K += a[i][1];
p = a[i][0];
}
ans = p + K;
cout << ans << endl;
}
|
#include<bits/stdc++.h>
using namespace std;
#define DONTSYNC ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) //dont use stdio with iostream functions //input and output are out of order now!
#define TEST unsigned long long T; cin>>T; while(T--) //loop over each testcase
#define endl "\n"
#define fori(a,start,end) for(int a=start;a<end;a++)
#define forll(a,start,end) for(long long a=start;a<end;a++)
#define forull(a,start,end) for(unsigned long long a=start;a<end;a++)
#define fi first
#define se second
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
const double PI = acos(-1);
void solve(){
/* code */
int n,m; cin>>n>>m;
vi A(n); fori(i,0,n) cin>>A[i];
vi B(m); fori(i,0,m) cin>>B[i];
int a=0,b=0;
while(a<n || b<m){
if(a==n){
cout<<B[b]<<' ';
b++;
}
else if(b==m){
cout<<A[a]<<' ';
a++;
}
else{
if(A[a]<B[b]){
cout<<A[a]<<' ';
a++;
}
else if(A[a]>B[b]){
cout<<B[b]<<' ';
b++;
}
else{
a++;b++;
}
}
}
}
int main()
{
DONTSYNC;
// TEST
solve();
return 0;
}
| #pragma region header
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define int ll
#define each(i, a) for (auto &&i : (a))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using vvs = vector<vs>;
using vd = vector<ld>;
using vvd = vector<vd>;
using vb = vector<bool>;
using vvb = vector<vb>;
using P = pair<int, int>;
using vp = vector<P>;
using int128 = __int128_t;//cin coutはできない
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a / gcd(a, b) * b;};
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
template <class T>
void CVEC(const T &v) {
int c = v.size() - 1;
for (int i = 0; i < c; i++) cout << v[i] << ' ';
if (c > -1) cout << v[c];
cout << '\n';
}
#pragma endregion header
template< typename Monoid >
struct SegmentTree {
using F = function< Monoid(Monoid, Monoid) >;
int sz;
vector< Monoid > seg;
const F f;
const Monoid M1;
SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) {
sz = 1;
while(sz < n) sz <<= 1;
seg.assign(2 * sz, M1);
}
void set(int k, const Monoid &x) {
seg[k + sz] = x;
}
void build() {
for(int k = sz - 1; k > 0; k--) {
seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
}
}
void update(int k, const Monoid &x) {
k += sz;
seg[k] = x;
while(k >>= 1) {
seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
}
}
Monoid query(int a, int b) {
Monoid L = M1, R = M1;
for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
if(a & 1) L = f(L, seg[a++]);
if(b & 1) R = f(seg[--b], R);
}
return f(L, R);
}
Monoid operator[](const int &k) const {
return seg[k + sz];
}
template< typename C >
int find_subtree(int a, const C &check, Monoid &M, bool type) {
while(a < sz) {
Monoid nxt = type ? f(seg[2 * a + type], M) : f(M, seg[2 * a + type]);
if(check(nxt)) a = 2 * a + type;
else M = nxt, a = 2 * a + 1 - type;
}
return a - sz;
}
template< typename C >
int find_first(int a, const C &check) {
Monoid L = M1;
if(a <= 0) {
if(check(f(L, seg[1]))) return find_subtree(1, check, L, false);
return -1;
}
int b = sz;
for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
if(a & 1) {
Monoid nxt = f(L, seg[a]);
if(check(nxt)) return find_subtree(a, check, L, false);
L = nxt;
++a;
}
}
return -1;
}
template< typename C >
int find_last(int b, const C &check) {
Monoid R = M1;
if(b >= sz) {
if(check(f(seg[1], R))) return find_subtree(1, check, R, true);
return -1;
}
int a = sz;
for(b += sz; a < b; a >>= 1, b >>= 1) {
if(b & 1) {
Monoid nxt = f(seg[--b], R);
if(check(nxt)) return find_subtree(b, check, R, true);
R = nxt;
}
}
return -1;
}
};
signed main(){
int n, q;
cin >> n >> q;
SegmentTree<int> seg(n, [](int a, int b){return a^b;}, 0);
for(int i = 1; i <= n; i++){
int a;
cin >> a;
seg.update(i, a);
}
vector<int> t(q), x(q), y(q);
rep(i,q){
cin >> t[i] >> x[i] >> y[i];
}
rep(i,q){
if(t[i] == 1){
int tmp = seg[x[i]];
seg.update(x[i], tmp^y[i]);
}
if(t[i] == 2){
//cout << "!" <<endl;
cout << seg.query(x[i],y[i]+1) << endl;
}
}
} |
//#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
//using namespace atcoder;
using ll = long long;
#define all(A) A.begin(),A.end()
using vll = vector<ll>;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
using Graph = vector<vector<pair<ll, ll>>>;
Graph G;
vll dist;
vector<bool> seen;
vll T;
vector<bool> C;
vector<bool> CHA;
//ll mod = 1e9 + 7;
int main() {
ll N;
cin >> N;
vll AE(N), AO(N);
vector<pair<ll, ll>> A(2 * N);
vector<pair<ll, ll>> PE(N), PO(N);
vector<char> AN(2 * N);
rep(i, N) {
cin >> AE[i] >> AO[i];
A[2 * i] = make_pair(AE[i], i * 2);
A[2 * i + 1] = make_pair(AO[i], i * 2 + 1);
}
sort(all(A));
reverse(all(A));
set<ll> BE, BO, ME, MO;
vector<bool> B(2 * N, false);
vector<bool> U(2 * N, false);
rep(i, N) {
if (A[i].second % 2 == 0) {
BE.insert(A[i].second);
B[A[i].second] = true;
}
else {
BO.insert(A[i].second);
B[A[i].second] = true;
}
}
rep(i, N) {
if (A[i+N].second % 2 == 0) {
ME.insert(A[i+N].second);
}
else {
MO.insert(A[i+N].second);
}
}
ll i = 0;
rep(i, 2*N) {
if (U[i])continue;
if (B[i]) {
if (i % 2 == 0) {
}
}
}
while (i < 2 * N) {
if (!U[i]) {
if (B[i]) {
if (i % 2 == 0) {
auto k = MO.begin();
ll n = *k;
MO.erase(n);
BE.erase(i);
AN[min(n, i)] = '(';
AN[max(n, i)] = ')';
U[n] = true;
U[i] = true;
}
if (i % 2 != 0) {
auto k = ME.begin();
ll n = *k;
ME.erase(n);
BO.erase(i);
AN[min(n, i)] = '(';
AN[max(n, i)] = ')';
U[n] = true;
U[i] = true;
}
}
else {
if (i % 2 == 0) {
auto k = BO.begin();
ll n = *k;
BO.erase(n);
ME.erase(i);
AN[min(n, i)] = '(';
AN[max(n, i)] = ')';
U[n] = true;
U[i] = true;
}
if (i % 2 != 0) {
auto k = BE.begin();
ll n = *k;
BE.erase(n);
MO.erase(i);
AN[min(n, i)] = '(';
AN[max(n, i)] = ')';
U[n] = true;
U[i] = true;
}
}
}
i++;
}
rep(i, 2 * N) {
cout << AN[i];
}
cout << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define e1 first
#define e2 second
#define pb push_back
#define mp make_pair
#define boost {ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define eb emplace_back
#define OUT(x) {cout << x; exit(0); }
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define scanf(...) scanf(__VA_ARGS__)?:0
typedef long long int ll;
typedef unsigned long long ull;
typedef pair <int, int> PII;
typedef pair <ll, ll> PLL;
typedef pair <PLL, int> PLLI;
typedef pair <PII, PII> PP;
typedef pair <PII, int> PPI;
typedef pair <int, PII> PIP;
typedef pair <ll, int> PLI;
typedef unsigned int ui;
const int inf = 1e9+9;
const ll MOD = 1e9+696969;
#ifdef DEBUG
template<class T> int size(T &&x) {
return int(x.size());
}
template<class A, class B> ostream& operator<<(ostream &out, const pair<A, B> &p) {
return out << '(' << p.first << ", " << p.second << ')';
}
template<class T> auto operator<<(ostream &out, T &&x) -> decltype(x.begin(), out) {
out << '{';
for(auto it = x.begin(); it != x.end(); ++it)
out << *it << (it == prev(x.end()) ? "" : ", ");
return out << '}';
}
void dump() {}
template<class T, class... Args> void dump(T &&x, Args... args) {
cerr << x << "; ";
dump(args...);
}
#endif
#ifdef DEBUG
struct Nl{~Nl(){cerr << '\n';}};
# define debug(x...) cerr << (strcmp(#x, "") ? #x ": " : ""), dump(x), Nl(), cerr << ""
#else
# define debug(...) 0 && cerr
#endif
mt19937_64 rng(0);
int random(int l, int r) {
return uniform_int_distribution<int>(l, r)(rng);
}
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long LL;
typedef pair<int, int> pii;
typedef vector<int> vi;
const LL INF = 1e18;
const int maxn = 300100;
const int mod = 998244353;
void solve() {
int n;
cin >> n;
vector <PII> s;
vi pos(n+n+1, 0);
vector <char> result(n+n+1, ')');
FOR(i, 1, n+n) {
int a;
cin >> a;
s.pb({a, i});
}
sort(all(s));
FOR(i, 0, n+n-1) {
pos[s[i].e2] = i + 1;
}
debug(pos);
vector <PII> stos;
FOR(i, 1, n+n) {
int typ = ((pos[i] <= n) ? 0 : 1);
if (stos.empty() || stos.back().e2 == typ) {
stos.pb({i, typ});
}
else {
result[stos.back().e1] = '(';
result[i] = ')';
stos.pop_back();
}
}
FOR(i, 1, n+n) cout << result[i];
cout << "\n";
}
int main() {
boost;
int tests;
tests = 1;
//cin >> tests;
while (tests--) {
solve();
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int N; cin >> N;
int A[200010];
int X[200010];
for(int i = 1; i <= N; i++){
cin >> A[i];
X[A[i]] = i;
}
vector<int> op;
for(int i = 1; i <= N; i++){
if(A[i] == i) continue;
int a = X[i];
for(int j = a-1; j >= i; j--){
X[A[j]] = j+1; X[A[j+1]] = j;
swap(A[j], A[j+1]);
op.push_back(j);
}
for(int j = i; j < a; j++){
if(A[j] != j){
cout << -1 << "\n"; return 0;
}
}
}
if((int) op.size() != N-1) cout << -1 << endl;
else{
for(auto i : op) cout << i << "\n";
}
} | #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 lli long long int
#define double long double
#define all(x) x.begin(),x.end()
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define siz(x) x.size()
#define prs(x,y) x.find(y)!=x.end()
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define forn(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res;}
inline int level(int n){int ans=0;while(n%2==0){n/=2;ans++;}return ans;}
#define gog(T,x) cout<<"Case #"<<T<<": "<<x<<"\n";
#define pii pair<int,int>
vector<pii> fw,bc;
vector<int> xs;
vector<int> vis;
vector<map<int,int> > mp;
queue<int> qu;
vector<int> ans;
void solve()
{
while(!qu.empty())
{
int y=qu.front();
ans.push_back(y+1);
qu.pop();
xs[fw[y].first]++;
xs[bc[y].first]++;
int ff=fw[y].first;
int bb=bc[y].first;
int ffs=mp[ff][xs[ff]];
int bbs=mp[bb][xs[bb]];
if(!vis[ffs] && xs[fw[ffs].first]==fw[ffs].second && xs[bc[ffs].first]==bc[ffs].second)
{
vis[ffs]=true;
qu.push(ffs);
}
if(!vis[bbs] && xs[fw[bbs].first]==fw[bbs].second && xs[bc[bbs].first]==bc[bbs].second)
{
vis[bbs]=true;
qu.push(bbs);
}
}
}
int main()
{
fast_io //REMOVE FOR interactive problems
lli n;
cin>>n;
fw=vector<pii>(n+1,{-1,-1});
bc=vector<pii>(n+1,{-1,-1});
xs=vector<int>(n+1,0);
vis=vector<int>(n+1,0);
mp=vector<map<int,int> >(n+1);
forn(i,n)
{
int x;
cin>>x;
x--;
int cnt=0;
if(x>i)
{
for(int j=i;j<x;j++)
{
if(fw[j]!=make_pair(-1,-1))
{
cout<<-1;
return 0;
}
fw[j]={x,cnt};
mp[x][cnt]=j;
cnt++;
}
}
else if(x==i)
{
cout<<-1;
return 0;
}
else
{
for(int j=i-1;j>=x;j--)
{
if(bc[j]!=make_pair(-1,-1))
{
cout<<-1;
return 0;
}
bc[j]={x,cnt};
mp[x][cnt]=j;
cnt++;
}
}
}
forn(i,n-1)
{
if(bc[i]==make_pair(-1,-1) || fw[i]==make_pair(-1,-1))
{
cout<<-1;
return 0;
}
else if(bc[i].second==0 && fw[i].second==0)
{
vis[i]=true;
qu.push(i);
}
}
solve();
if((lli)ans.size()!=n-1)
{cout<<-1;return 0;}
for(auto x: ans)
cout<<x<<"\n";
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
const int mod=1e9+7;
int n,ans=0;
cin>>n;
vector<long long>sum(n+1);
vector<vector<int> >lst(n+1,vector<int>(n+1)),dp(n+1,vector<int>(n+1));
for(int i=1;i<=n;i++) {
long long v;
cin>>v;
sum[i]=sum[i-1]+v;
}
lst[1][0]=dp[0][0]=1;
for(int i=1;i<=n;i++) {
for(int j=1;j<=n;j++)
dp[i][j]=lst[j][sum[i]%j];
for(int j=2;j<=n;j++)
lst[j][sum[i]%j]=(lst[j][sum[i]%j]+dp[i][j-1])%mod;
}
for(int i=1;i<=n;i++) ans=(ans+dp[n][i])%mod;
cout<<ans;
return 0;
} | #include<bits/stdc++.h>
typedef uint64_t u64;
typedef int64_t i64;
typedef long double f128;
using namespace std;
template<typename T>
void scan(T& n){
cin>>n;
}
void scan(){}
template<typename T,class... Args>
void scan(T& n,Args&... args){
scan(n);
scan(args...);
}
template<typename T>
void scanall(T start,T end){
for(;start!=end;++start){
scan(*start);
}
}
template<typename T>
void print(T n){
cout<<n;
}
void print(){}
template<typename T,class... Args>
void print(T n,Args... args){
print(n);
print(args...);
}
template<typename T>
void println(T n){
print(n);
cout<<endl;
}
template<typename T,class... Args>
void println(T n,Args... args){
print(n,' ');
println(args...);
}
template<typename T>
void printall(T start,T end){
if(start!=end){
print(*start);
for(++start;start!=end;++start){
print(' ',*start);
}
}
cout<<endl;
}
template<typename T>
void chmax(T& n,T m){
n=max(n,m);
}
template<typename T>
void chmin(T& n,T m){
n=min(n,m);
}
template<typename T,typename U>
T power(T a,U n){
T res=1;
while(n){
res*=(n&1)?a:1;
a*=a;
n>>=1;
}
return res;
}
template<typename T>
struct combination{
vector<T> fact;
combination(const int Max=3000000):fact(Max+1,1){
for(int i=2;i<=Max;++i){
fact[i]=fact[i-1]*i;
}
}
template<typename U>
T nCk(U n,U k){
if(n<k||n<0||k<0){
return 0;
}
return fact[n]/fact[k]/fact[n-k];
}
};
void solve();
int main(){
cout<<fixed<<setprecision(15);
bool is_multicase=false;
int T=1;
if(is_multicase){
scan(T);
}
for(int i=0;i<T;++i){
solve();
}
return 0;
}
template<u64 mod>
struct modint{
u64 val;
constexpr modint(const i64 x=0) noexcept:val((x%i64(mod)+i64(mod))%i64(mod)){}
constexpr u64 &value() noexcept{
return val;
}
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{
val+=rhs.val;
val-=((val>=mod)?mod:0);
return *this;
}
constexpr modint &operator-=(const modint rhs) noexcept{
val+=((val<rhs.val)?mod:0);
val-=rhs.val;
return *this;
}
constexpr modint &operator*=(const modint rhs) noexcept{
val=val*rhs.val%mod;
return *this;
}
constexpr modint &operator/=(modint rhs) noexcept{
u64 exp=mod-2;
while(exp){
if(exp&1){
(*this)*=rhs;
}
rhs*=rhs;
exp>>=1;
}
return *this;
}
friend constexpr ostream &operator<<(ostream &os,const modint &x) noexcept{
return os<<(x.val);
}
friend constexpr istream &operator>>(istream &is,modint &x) noexcept{
u64 t;
is>>t;
x=t;
return is;
}
};
void solve(){
typedef modint<1000000007> mint;
int N;
scan(N);
vector<i64> A(N);
scanall(A.begin(),A.end());
vector<i64> csum(N+1);
for(int i=1;i<=N;++i){
csum[i]=csum[i-1]+A[i-1];
}
vector<vector<mint>> dp(N+1,vector<mint> (N+1));
dp[0][0]=1;
for(int i=1;i<=N;++i){
vector<i64> rem(N+1);
for(int j=0;j<=N;++j){
rem[j]=csum[j]%i;
}
vector<vector<int>> vec(i);
for(int j=0;j<=N;++j){
vec[rem[j]].emplace_back(j);
}
for(int j=0;j<i;++j){
for(size_t k=1;k<vec[j].size();++k){
dp[i][vec[j][k]]=dp[i-1][vec[j][k-1]]+dp[i][vec[j][k-1]];
}
}
}
mint ans=0;
for(int i=1;i<=N;++i){
ans+=dp[i][N];
}
println(ans);
} |
/*::::::::::::::::::::::::::::::::::::::::::::::::::::*/
/*:::::::::::::J A I S H R E E R A M::::::::::::::::*/
/*::::::::::::::::::::::::::::::::::::::::::::::::::::*/
#include <bits/stdc++.h>
using namespace std;
#ifdef LUCTIVUD
#include <buggyBaby.hpp>
pretty:: PrettyPrinter NonIterable;
#define cerr cout
#else
#define _____error_____(...)
#endif
#pragma GCC optimize "trapv"
/*:::::::::::::::::::SNIPS::::::::::::::::::::::::::::*/
typedef long long lld; typedef unsigned long long llu;
#define forn(I7, E4) for(lld I7=0ll; I7 < E4; (I7)+=1ll)
#define forn1(I7, E4) for(lld I7=1ll; I7 < E4+1; (I7)+=1ll)
#define len(v) ((int)((v).size()))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define f1 first
#define s2 second
/*::::::::::::::::::/SNIPS::::::::::::::::::::::::::::*/
/*:::::::::::::::::::UTILS::::::::::::::::::::::::::::*/
const long double EPS = 1e-6;
lld MOD = int(1e9) + 7;
lld &mod = MOD;
/*:::::::::::::::::::::/UTILS:::::::::::::::::::::::::*/
/*::::::::::::::::::::::LOGIC:::::::::::::::::::::::::*/
class Solution {
static const int maxN = int(1e5) + 2;
public:
Solution() {
}
public:
void SolveEachTest(int _TestCase) {
// cout << "Case #" << _TestCase << ":";
lld n; cin >> n;
lld ans = 0ll;
forn(i, n) {
lld tem; cin >> tem;
if (tem > 10) {
ans += tem - 10;
}
}
cout << ans;
}
public:
void ResetTestCase() {
cout << "\n";
}
};
/*:::::::::::::::::::::/LOGIC:::::::::::::::::::::::::*/
/*::::::::::::::::::::::INVOC:::::::::::::::::::::::::*/
signed main() {
ios_base::sync_with_stdio(false); cin.tie(0);
// cout.precision(10); cout << fixed;
#ifdef LUCTIVUD
// const auto start_time = std::chrono::high_resolution_clock::now();
freopen("/home/luctivud/CPPractice/Zinput.txt", "r", stdin);
freopen("/home/luctivud/CPPractice/Zoutput.txt", "w", stdout);
#endif
int _T0T4 = 1;
// cin >> _T0T4;
Solution Aurora;
for (int _TestCase = 1; _TestCase <= _T0T4; _TestCase++) {
Aurora.SolveEachTest(_TestCase);
Aurora.ResetTestCase();
}
#ifdef LUCTIVUD
// auto end_time = std::chrono::high_resolution_clock::now();
// std::chrono::duration<double> diff = end_time - start_time;
// cerr << "Finished in : " << diff.count() << "\n";
#endif
return 0;
}
/*:::::::::::::::::::::/INVOC:::::::::::::::::::::::::*/
/* ~~
Author : Udit "luctivud" Gupta
linkedin : https://www.linkedin.com/in/udit-gupta-1b7863135/
*/
| /**
* author: Hritik Raj
* created: 06-06-2021 17:33:26
**/
#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve(){
int n;
cin>>n;
int ans = 0;
for(int i=0;i<n;i++){
int x;
cin>> x;
ans += max(0LL, x-10);
}
cout<<ans<<"\n";
}
int32_t main(){
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int t;
// cin>>t;
t = 1;
int _=1;
while(t--){
// cout<<"Case #"<<_++<<": ";
solve();
}
return 0;
} |
#include<cstdio>
const int mod(1e9+7);
long long f(int x)
{
long long res=1;
for(int i=1;i<=x;i++)
res=(res*i)%mod;
return res;
}
long long pow(long long x,int p)
{
long long res=1;
while(p)
{
if(p%2) res=(res*x)%mod;
p/=2;
x=(x*x)%mod;
}
return res;
}
long long c(int n,int m)
{
return ((f(n)*pow(f(m),mod-2))%mod*pow(f(n-m),mod-2))%mod;
}
int main()
{
long long n,m,k;
scanf("%lld%lld%lld",&n,&m,&k);
if(n-m>k) printf("0\n");
else if(n<=k) printf("%lld\n",c(n+m,m));
else if(n>k) printf("%lld\n",((c(n+m,m)-c(n+m,n-k-1))%mod+mod)%mod);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef vector<pll> vll;
typedef vector<vl> vvl;
#define fori(i, n) for (int i = 0; i < n; i++)
#define ford(i, n) for (int i = n - 1; i >= 0; i--)
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define repd(i, a, b) for (int i = a; i >= b; i--)
#define trav(x, a) for (auto &x : a)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define endl '\n'
#define sz(a) (int)(a).size()
#define fi first
#define se second
clock_t time_p = clock();
void time_taken()
{
time_p = clock() - time_p;
cerr << "Time Taken : " << (float)(time_p) / CLOCKS_PER_SEC << "\n";
}
const ll mod = 1e9 + 7;
const ll INF = 1e18;
ll modinv(ll a, ll m)
{
assert(m > 0);
if (m == 1)
return 0;
a %= m;
if (a < 0)
a += m;
assert(a != 0);
if (a == 1)
return 1;
return m - modinv(m, a) * m / a;
}
template <int MOD_>
struct modnum
{
private:
int v;
public:
static const int MOD = MOD_;
modnum() : v(0) {}
modnum(ll v_) : v(int(v_ % MOD))
{
if (v < 0)
v += MOD;
}
explicit operator int() const { return v; }
friend bool operator==(const modnum &a, const modnum &b) { return a.v == b.v; }
friend bool operator!=(const modnum &a, const modnum &b) { return a.v != b.v; }
modnum operator~() const
{
modnum res;
res.v = modinv(v, MOD);
return res;
}
modnum &operator+=(const modnum &o)
{
v += o.v;
if (v >= MOD)
v -= MOD;
return *this;
}
modnum &operator-=(const modnum &o)
{
v -= o.v;
if (v < 0)
v += MOD;
return *this;
}
modnum &operator*=(const modnum &o)
{
v = int(ll(v) * ll(o.v) % MOD);
return *this;
}
modnum &operator/=(const modnum &o)
{
return *this *= (~o);
}
friend modnum operator+(const modnum &a, const modnum &b) { return modnum(a) += b; }
friend modnum operator-(const modnum &a, const modnum &b) { return modnum(a) -= b; }
friend modnum operator*(const modnum &a, const modnum &b) { return modnum(a) *= b; }
friend modnum operator/(const modnum &a, const modnum &b) { return modnum(a) /= b; }
};
using num = modnum<mod>;
vector<num> fact;
vector<num> ifact;
void init()
{
fact = {1};
for (int i = 1; i < 2000005; i++)
fact.push_back(i * fact[i - 1]);
for (num x : fact)
ifact.push_back(1 / x);
}
num ncr(int n, int k)
{
if (k < 0 || k > n)
return 0;
return fact[n] * ifact[k] * ifact[n - k];
}
num powmod(num x, int a)
{
if (a == 0)
return 1;
if (a & 1)
return x * powmod(x, a - 1);
return powmod(x * x, a / 2);
}
int main()
{
ios_base::sync_with_stdio(false), cin.tie(nullptr);
init();
int n, m, k;
cin >> n >> m >> k;
// x1 + x2 + .. + x_{m+1} = n
// x1 <= k
// x1 + x2 <= k + 1
// x1 + x2 + x3 <= k + 2
// vector<num> dp(n + 1);
// dp[0] = 1;
// fori(i, m + 1)
// {
// num sum = 0;
// for (int j = 0; j <= min(k + i, n); j++)
// {
// sum += dp[j];
// dp[j] = sum;
// }
// }
// // w_i - b_i = k+1
// // w_i + b_i = i
// // (0,k) -> (w,b+k)
// cout << int(dp[n]) << endl;
if (n > m + k)
{
cout << 0 << endl;
}
else
{
cout << int(ncr(n + m, n) - ncr(n + m, n - (k + 1))) << endl;
}
// cout << int(ncr(2 * n, n) / (n + 1)) << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define double long double
#define pb push_back
#define fi first
#define se second
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pii>
#define pqi priority_queue<int>
#define test int tcase; cin>>tcase; for(int tc = 1; tc <= tcase; tc++)
#define inp(a,n,f) int a[n+f];for(int hh=f;hh<n+f;hh++)cin>>a[hh];
#define printdecimal(k) cout<<fixed<<setprecision(k);
#define mem(a,k) memset(a,k,sizeof(a))
#define ub upper_bound
#define lb lower_bound
#define mii map<int,int>
#define all(v) v.begin(),v.end()
#define mod (int)(1e9+7)
#define inf LLONG_MAX
int exp(int x,int y){int res=1;x=x%mod;while(y>0){if(y&1)res=(res*x)%mod;y=y>>1;x=(x*x)%mod;}return res;}
int modinv(int x){return exp(x,mod-2);}
int add(int a,int b){a%=mod,b%=mod;a=((a+b)%mod+mod)%mod;return a;}
int sub(int a,int b){a=((a-b)%mod+mod)%mod;return a;}
int mul(int a,int b){a%=mod,b%=mod;a=((a*b)%mod+mod)%mod;return a;}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
string s;
cin>>n>>s;
stack<char> st;
for(char x:s)
{
if(st.size()<2) st.push(x);
else
{
char a,b;
b=st.top();
st.pop();
a=st.top();
st.pop();
if(x=='x'&&a=='f'&&b=='o') continue;
else
{
st.push(a);
st.push(b);
st.push(x);
}
}
}
cout<<st.size();
return 0;
} | #include<bits/stdc++.h>
#define ll long long
using namespace std;
template <typename T, typename TT>
void print(T c, TT a,int n){
vector<int> r;
for(int i=0;i<n;i++)
r.push_back(a[i][0] - c[0]);
int mi = *min_element(r.begin(), r.end());
if(mi<0){
for(auto &x:r) x+=abs(mi);
for(auto &x:c) x-=abs(mi);
}
mi = *min_element(c.begin(), c.end());
if(mi<0){
cout<<"No\n";
return;
}
cout<<"Yes\n";
for(auto x:r) cout<<x<<" ";
cout<<"\n";
for(auto x:c) cout<<x<<" ";
cout<<"\n";
}
void solve(){
int n;cin>>n;
vector<vector<int>>a(n, vector<int>(n));
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
cin>>a[i][j];
for(int i=0;i<n;i++){
vector<int> c = a[i];
int fail = 0;
for(int j=0;j<n && !fail;j++){
if(j==i) continue;
vector<int>temp(n);
for(int k=0;k<n;k++){
temp[k] = a[j][k] - c[k];
}
sort(temp.begin(), temp.end());
if(temp[0] != temp.back()){
fail = 1;
break;
}
}
if(!fail){
print(c, a, n);
return;
}
}
cout<<"No\n";
}
signed main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
solve();
return 0;
}
|
#include<iostream>
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int p=1e9+7;
int main(){
ios::sync_with_stdio(false); cin.tie(0);
ll n,k;
cin>>n>>k;
while(k--){
if(n%200==0) n/=200;
else n=n*1000+200;
}
cout<<n;
}
| #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi(a,b) for(int i=(a);i<(b);i++)
#define fj(a,b) for(int j=(a);j<(b);j++)
#define pb(n) push_back(n)
string ts(int a){
string q="";
while(a!=0){
q+=a%10+48;
a/=10;
}
return q;
}
int main(){
string s;
ll n,k;
cin>>s>>k;
istringstream iss(s);
iss>>n;
fi(0,k){
if(n%200==0){
n/=200;
s=to_string(n);
}
else{
s+="200";
istringstream iss(s);
iss>>n;
}
//cout<<n<<' '<<s<<endl;
}
cout<<n;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b,c;
cin>>a>>b>>c;
a=(a*a)+(b*b);
c=a-(c*c);
if(c<0)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
| /*
Ashraful Islam Paran
24-April-2021
18:03:40
*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define f(n) for (int i = 0; i < n; i++)
#define show(x, y) cout << x << " " << y << "\n"
#define fo(i, x, n) for (int i = x; i < n; i++)
#define fb(i, x, n) for (int i = n - 1; i >= x; i--)
#define w(t) \
int t; \
cin >> t; \
while (t--)
#define dbg(args...) \
do \
{ \
cerr << #args << " : "; \
faltu(args); \
} while (0)
clock_t tStart = clock();
#define timeStamp dbg("Execution Time: ", (double)(clock() - tStart) / CLOCKS_PER_SEC)
void faltu()
{
cerr << endl;
}
template <typename T>
void faltu(T a[], int n)
{
for (int i = 0; i < n; ++i)
cerr << a[i] << ' ';
cerr << endl;
}
template <typename T, typename... hello>
void faltu(T arg, const hello &... rest)
{
cerr << arg << ' ';
faltu(rest...);
}
typedef unsigned long long ull;
typedef vector<long long> vi;
#define msi map<string, long long>
#define mii map<long long, long long>
const int MX = 2e5 + 5;
const int INF = 1e18;
const int mod = 1e9 + 7;
#define pb push_back
#define endl "\n"
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
inline void normal(int &a)
{
if (a >= mod)
a %= mod;
(a < 0) && (a += mod);
}
inline int modMul(int a, int b)
{
normal(a), normal(b);
return (a * b) % mod;
}
inline int modAdd(int a, int b)
{
normal(a), normal(b);
return (a + b) % mod;
}
inline int modSub(int a, int b)
{
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)); }
void print(int a[], int n)
{
for (int i = 0; i < n; i++)
{
cout << a[i] << " ";
}
cout << endl;
}
void print(vi &v)
{
f(v.size())
{
cout << v[i] << " ";
}
cout << endl;
}
bool sortbysec(const pair<int, int> &a,
const pair<int, int> &b)
{
//return (a.second < b.second);
if (a.first == b.first)
{
return (a.second > b.second);
}
else
{
return (a.ff < b.ff);
}
}
int32_t main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
freopen("error.txt", "w", stderr);
#else
// online submission
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int a,b,c;
cin>>a>>b>>c;
if((a*a+b*b)<c*c)
{
cout<<"Yes"<<endl;
}
else
{
cout<<"No"<<endl;
}
cerr << "Time : " << 1.0 * clock() / CLOCKS_PER_SEC << "s\n";
return 0;
} |
#ifndef _USE_MATH_DEFINES
#define _USE_MATH_DEFINES
#endif
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false); cin.tie(0);cout.tie(0);
#define m_p make_pair
#define x first
#define y second
using namespace std;
using LL=long long;
using ULL=unsigned long long;
using LD=long double;
using P=pair<int,int>;
const int inf=0x3f3f3f3f;
const LL LLinf=0x3f3f3f3f3f3f3f3f;
int main()
{
IOS;
#ifdef _DEBUG
freopen("D:/CODE/algorithm_contest/out.txt","w",stdout);
freopen("D:/CODE/algorithm_contest/in.txt","r",stdin);
#endif
LL B,C;
while(cin>>B>>C)
{
LL ans=0;
if(B>0)
{
ans=C;
if(C==1) ans++;
ans+=min(C-2+1,2*B-1);
}
else if(B<0)
{
ans=C+1;
ans+=max(min(-2*B-1,C-3+1),0ll);
}
else if(B==0)
{
ans=C;
}
cout<<ans<<endl;
}
return 0;
}
| // Code for B - Many 110
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define FOR(i,x,y) for(ll i=x;i<(ll)(y);i++)
#define MOD 1000000007
#define mod(x) ( (x) % MOD + MOD ) % MOD
#define debug(var) do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<typename T, typename U> void view(const std::map<T, U>& m){ for(const auto& e : m){ std::cout << e.first << "=>" << e.second << " "; } std::cout << std::endl; }
int main() {
int N;
cin >> N;
string T;
cin >> T;
if (T == "0") {
cout << 10000000000 << endl;
return 0;
}
if (T == "1") {
cout << 20000000000 << endl;
return 0;
}
if (T == "11") {
cout << 10000000000 << endl;
return 0;
}
// if (T == "110") {
// cout << 10000000000 << endl;
// return 0;
// }
// if (T == "011") {
// cout << 9999999999 << endl;
// return 0;
// }
// if (T == "101") {
// cout << 9999999999 << endl;
// return 0;
// }
string base = "110";
bool any = false;
ll start;
REP(j, 3) {
bool isOk = true;
REP(i, N) {
if (T[i] != base[(i + j) % 3]) {
isOk = false;
break;
}
}
if (isOk) {
any = true;
start = j;
break;
}
}
if (!any) {
cout << 0 << endl;
return 0;
}
if (start == 1) {
start = 2;
} else if (start == 2) {
start = 1;
}
ll m = ( N - start ) / 3;
ll end = ( N - start ) % 3;
// cout << 10000000000 - (( start + end ) / 3) - (m - 1);
cout << 10000000000 - (start > 0 ? 1 : 0) - (m - 1) - (end > 0 ? 1 : 0);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main(){
int H,W;
cin >> H >> W;
vector<string> S(H);
for(int i=0; i<H; i++){
cin >> S.at(i);
}
int count = 0;
//横
for(int i=0; i<H; i++){
for(int j=0; j<W-1; j++){
if(S.at(i).at(j)=='.' && S.at(i).at(j+1)=='.'){
count++;
}
}
}
// 縦
for(int j=0; j<W; j++){
for(int i=0; i<H-1; i++){
if(S.at(i).at(j)=='.' && S.at(i+1).at(j)=='.'){
count++;
}
}
}
cout << count << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < n; ++i)
using ll = long long;
using P = pair<int,int>;
int main() {
int h,w;cin>>h>>w;
vector<string> v;
string last(w+1,'#');
rep(i,h){
string s;cin>>s;
v.push_back(s);
v[i].push_back('#');
}
int ans=0;
v.push_back(last);
rep(i,h){
rep(j,w){
if(v[i][j]=='.'){
ans+=(v[i][j+1]=='.');
ans+=(v[i+1][j]=='.');
}
}
}
cout<<ans<<endl;
} |
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <numeric>
#include <limits>
#include <type_traits>
#include <locale>
#include <omp.h>
using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE) \
if (TRUE_OR_FALSE) \
{ \
cout << "YES" << endl; \
} \
else \
{ \
cout << "NO" << endl; \
}
#define IFYes(TRUE_OR_FALSE) \
if (TRUE_OR_FALSE) \
{ \
cout << "Yes" << endl; \
} \
else \
{ \
cout << "No" << endl; \
}
#define IFyes(TRUE_OR_FALSE) \
if (TRUE_OR_FALSE) \
{ \
cout << "yes" << endl; \
} \
else \
{ \
cout << "no" << endl; \
}
#define DEBUG_OUTPUT_ARRAY(XXX, ONE) \
for (int i = 0; i < (ONE); i++) \
{ \
cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
}
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO) \
for (int i = 0; i < (ONE); i++) \
{ \
cout << "<<< i = " << i << " >>>" << endl; \
for (int j = 0; j < (TWO); j++) \
{ \
cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
} \
}
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
for (int i = 0; i < (ONE); i++) \
{ \
cout << i << " "; \
for (int j = 0; j < (TWO); j++) \
{ \
cout << XXX[i][j] << " "; \
} \
cout << endl; \
}
typedef pair<long long int, long long int> pll;
typedef pair<long long int, pll> lpll;
const long long int mod = 1000000007;
const long long int INF = 1e16;
const long double PI=3.14159265358979323;
const long long int pl=1100;
const long double eps =0.0000001;
long long int N,sum=0,A[200200],B[200200],M=0,id;
int main()
{
cout << fixed << setprecision(18);
//入力
cin>>N;
for (long long int i = 0; i < (1<<N); i++)
{
cin>>A[i];
if(M<A[i]){M=max(M,A[i]);id=i;}
}
if(id<(1<<(N-1))){
id=0;
M=0;
for (long long int i = (1<<(N-1)); i < (1<<N); i++)
{
if(M<A[i]){M=max(M,A[i]);id=i;}
}
cout<<id+1<<endl;
}else{
id=0;
M=0;
for (long long int i = 0; i < (1<<(N-1)); i++)
{
if(M<A[i]){M=max(M,A[i]);id=i;}
}
cout<<id+1<<endl;
}
}
| #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int inf=0x3f,INF=0x3f3f3f3f; const ll LLINF=0x3f3f3f3f3f3f3f3f;
#define siz(x) (int)x.size()
#define af(x) x.begin(), x.end()
#define ms(x, y) memset(x, y, sizeof x)
#define fil(x, y) fill(af(x), y)
#define pb push_back
#define lb lower_bound
#define ub upper_bounn
#define f first
#define s second
#define lc i << 1
#define rc i << 1 | 1
const int mod = 1e9 + 7;
ll fpow(ll a, ll b){ll ret=1;while(b){if(b&1)ret=ret*a%mod;a=a*a%mod,b>>=1;}return ret;}
ll inv(ll x){return x ? fpow(x, mod - 2) : 1;}
void madd(int &a, int b){a+=b;if(a>=mod)a-=mod;}
void msub(int &a, int b){a+=mod-b;if(a>=mod)a-=mod;}
const int MM = 2e5 + 5;
void solve(){
int n;
cin >> n;
vector<pii> a(1<<n);
for (int i = 0; i < ( 1 << n); i++) cin >> a[i].first, a[i].second = i + 1;
for (int i = n; i > 1; i--){
vector<pii> b;
for (int j = 0; j < (1 << i); j += 2){
b.pb(max(a[j], a[j + 1]));
}
swap(a, b);
}
if (a[0].first > a[1].first) cout << a[1].second << '\n';
else cout << a[0].second << '\n';
}
/*
* do i rlly need to check everything????
*/
int main(){
cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);
int t = 1;
//cin >> t;
while(t--) solve();
}
|
#include <bits/stdc++.h>
#define rep(i, n) for (long long i = 0; i < n; i++)
#define rep2(i, s, n) for (int i = (s); i < n; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());
#define vecint(A, n) vector<long long int> A(n);
#define vecint2(A, n, m) vector<vector<long long>> A(n, vector<long long>(m));
#define vecchar(A, n) vector<char> A(n);
#define vecchar2(A, n, m) vector<vector<char>> A(n, vector<char>(m));
#define vecstr(A, n) vector<string> A(n);
#define keta(s) cout << fixed << setprecision(s);
#define test cout<<"OK"<<endl; //test;
const double pi=3.14159265358979323846;
using namespace std;
long long MOD=1000000007; // %MOD
int main() {
int N,W;
cin>>N>>W;
vecint(A,200005);
rep(i,N){
int S,T,P;
cin>>S>>T>>P;
A[S]+=P;
A[T]-=P;
}
vecint(B,200005);
B[0]=A[0];
rep(i,200004){
B[i+1]=B[i]+A[i+1];
}
sort(B);
reverse(B);
if(B[0]>W) cout<<"No"<<endl;
else cout<<"Yes"<<endl;
} | #include<bits/stdc++.h>
#define ll long long
using namespace std;
int read()
{
int a=0,f=1,c=getchar();
while(!isdigit(c))
{
if(c=='-')f=-1;
c=getchar();
}
while(isdigit(c))
{
a=a*10+c-'0';
c=getchar();
}
return a*f;
}
const int K=1e5+10;
int k;
int n,m;
ll a[K],L[K],R[K];
bool check(ll d)
{
ll sl=0,sr=0;
for(int i=1;i<=k;++i)
{
L[i]=(max(a[i]*m-d,(ll)0)+n-1)/n;sl+=L[i];
R[i]=(a[i]*m+d)/n;sr+=R[i];
}
if(sl<=m && m<=sr)
{
ll ext=m-sl;
for(int i=1;i<=k;++i)
{
ll t=min(ext,(ll)R[i]-L[i]);
L[i]+=t;ext-=t;
}
return 1;
}
else return 0;
}
int main()
{
// freopen("1.in","r",stdin);
k=read();
n=read();m=read();
for(int i=1;i<=k;++i)a[i]=read();
ll l=0,r=1e18;
while(l<r)
{
ll mid=(l+r)/2;
if(check(mid))r=mid;
else l=mid+1;
}
check(l);
for(int i=1;i<=k;++i)printf("%lld ",L[i]);
puts("");
return 0;
} |
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
int main() {
int n, m, t;
cin >> n >> m >> t;
int lt = 0;
int battery = n;
bool ok = true;
rep(i, m) {
int a, b;
cin >> a >> b;
battery -= a - lt;
if (battery <= 0) {
ok = false;
}
battery += b - a;
if (n < battery) {
battery = n;
}
lt = b;
}
battery -= t - lt;
if (battery <= 0) {
ok = false;
}
if (ok) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
} | #include <iostream>
using namespace std;
long long s[1006], e[1006];
int main() {
long long n, m, t;
cin >> n >> m >> t;
for (int i=0; i<m; i++) {
cin >> s[i] >> e[i];
}
long long count;
count=n;
count-=s[0];
for (int i=0; i<m; i++) {
if (count<=0) {
cout << "No" << endl;
return 0;
}
count+=e[i]-s[i];
if (count>n) {
count=n;
}
if (i==m-1) {
continue;
}
count-=(s[i+1]-e[i]);
}
count-=t-e[m-1];
if (count<=0) {
cout << "No" << endl;
}
else {
cout << "Yes" << endl;
}
return 0;
} |
#include <bits/stdc++.h>
// clang-format off
using namespace std; using ll = long long; using ull = unsigned long long; using pll = pair<ll,ll>; const ll INF = 4e18;
void print0() {}
template<typename Head,typename... Tail> void print0(Head head,Tail... tail){cout<<fixed<<setprecision(15)<<head;print0(tail...);}
void print() { print0("\n"); }
template<typename Head,typename... Tail>void print(Head head,Tail... tail){print0(head);if(sizeof...(Tail)>0)print0(" ");print(tail...);}
// clang-format on
const ll MODULO = 998244353LL;
ll mod_pow(ll x, ll n, ll modval) {
if (x == 0) {
return 0;
}
if (n == 0) {
return 1;
}
ll res = mod_pow(x * x % modval, n / 2, modval);
if (n & 1) {
res = res * x % modval;
}
return res;
}
ll mpow(ll x, ll n) {
return mod_pow(x, n, MODULO);
}
int main() {
ll n, m, k;
cin >> n >> m >> k;
ll ans = 0;
if (n == 1 && m == 1) {
print(k);
return 0;
} else if (n == 1) {
for (ll x = 1; x <= k; x++) {
ll mx = mpow(k - x + 1, m) - mpow(k - x, m);
if(mx<0)mx+=MODULO;
ans = (ans + mx) % MODULO;
}
print(ans);
} else if (m == 1) {
for (ll x = 1; x <= k; x++) {
ll nx = mpow(x, n) - mpow(x - 1, n);
if (nx < 0) nx += MODULO;
ans = (ans + nx) % MODULO;
}
print(ans);
} else {
for (ll x = 1; x <= k; x++) {
ll nx = mpow(x, n) - mpow(x - 1, n);
if (nx < 0) nx += MODULO;
ll mx = mpow(k - x + 1, m);
ans = (ans + nx * mx) % MODULO;
}
print(ans);
}
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
constexpr ll MOD=1000000007;
constexpr ll INF=2e18;
ll power(ll x, ll y){
x%=MOD;
ll ret=1;
while(y){
if(y&1) ret=ret*x%MOD;
x=x*x%MOD;
y>>=1;
}
return ret;
}
ll divid(ll x, ll y){
x%=MOD;
return x*power(y,MOD-2)%MOD;
}
VVI prd(VVI& a, VVI& b){
int n=a.size(), m=b[0].size();
VVI ret(n,VI(m));
REP(i,n)REP(j,m){
ll sum=0;
REP(k,a[0].size()){
sum=(sum+a[i][k]*b[k][j]%MOD)%MOD;
}
ret[i][j]=sum;
}
return ret;
}
VVI matrix_power(VVI x, ll y){
int n=x.size();
VVI ret(n,VI(n,0));
REP(i,n) ret[i][i]=1;
while(y){
if(y&1) ret=prd(ret,x);
x=prd(x,x);
y>>=1;
}
return ret;
}
int main(){
int n, m, k; cin >> n >> m >> k;
VVI a(1,VI(n)); REP(i,n) cin >> a[0][i];
VVI mx(n,VI(n,0));
REP(i,n) mx[i][i]=m;
ll p=divid(1,2);
int x, y;
REP(i,m){
cin >> x >> y;
x--, y--;
mx[x][x]=(mx[x][x]+MOD-p)%MOD;
mx[y][y]=(mx[y][y]+MOD-p)%MOD;
mx[x][y]=(mx[x][y]+p)%MOD;
mx[y][x]=(mx[y][x]+p)%MOD;
}
p=divid(1,m);
REP(i,n)REP(j,n){
mx[i][j]=mx[i][j]*p%MOD;
}
mx=matrix_power(mx,k);
VVI ans=prd(a,mx);
REP(i,n) cout << ans[0][i] << endl;
return 0;
} |
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
#include <iomanip>
using namespace std;
#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/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;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ans=0;llfor;///////////////////////////////////////////////////////////
int digit(int n){
if(n < 10) return n;
return digit(n/10) + n%10;
}
int GetDigit(ll num){
return std::to_string(num).length();
}
bool check(int i){
int N=i+1;
if(N==2 || N==4 || N==8 || N==16 || N==32 || N==64 || N==128 || N==256 || N==512 || N==1024 || N==2048 || N==4096 || N==8192 || N==16384 || N==32768 || N==65536) return true;
else return false;
}
int main(){
int N;
cin>>N;
vector<int> V(100010);
V[0]=1;
for(int i=1;i<100010;i++){
V[i]=V[i-1];
if(check(i)) V[i]++;
}
for(int i=0;i<N;i++) cout<<V[i]<<" ";
return 0;}
| /////////////////////////////////TEST CASES////////////////////////////////////
/*
*/
/////////////////////////////////////CODE//////////////////////////////////////
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORD(i, a, b) for (ll i = a ; i > b ; i--)
#define fastio ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define PI 3.14159265
typedef long long ll;
#define vl vector<ll>
#define IN(inp) ll inp;cin>>inp;
#define pb push_back
#define all(a) a.begin(),a.end()
#define FR(i,a) for(auto &i:a)
#define rvl(a,n) vl a;FOR(i,0,n){IN(in); a.pb(in);}
#define what(A) cout<<#A<<" is "<<A<<endl;
ll MAX = 100000000000;
ll MOD = 998244353;
map<ll, vl>g;
vl a, b;
ll vis[200010], s1[200010], s2[200010];
void dfs(int node, int par)
{
vis[node] = 1;
s1[par-1] += a[node-1];
s2[par-1] += b[node-1];
FR(i, g[node])
{
if(!vis[i])
dfs(i, par);
}
}
void solve()
{
IN(n)IN(m);
FOR(i, 0, n)
{
IN(in);
a.push_back(in);
}
FOR(i, 0, n)
{
IN(in);
b.push_back(in);
}
FOR(i, 0, m)
{
IN(in1)IN(in2);
g[in1].pb(in2);
g[in2].pb(in1);
}
FOR(i, 1, n + 1)
{
if(!vis[i])
dfs(i, i);
}
FOR(i, 0, n)
if (s1[i] != s2[i])
{
cout << "No";
return;
}
cout << "Yes";
}
int main()
{
fastio
//freopen("input.txt", "rt", stdin);
//freopen("output.txt", "wt", stdout);
ll test = 1;
//cin >> test;
while (test--)
{
solve();
}
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 998244353;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;
struct union_find {
vector<int> par, siz;
union_find(int n) {
par.resize(n);
siz.resize(n);
for(int i = 0; i < n; i++){
par[i] = i;
siz[i] = 1;
}
}
int find(int x) {
if (par[x] == x) return x;
return par[x] = find(par[x]);
}
void unite(int x, int y) {
x = find(x);
y = find(y);
if (x == y)return;
if (siz[x] < siz[y]) {
par[x] = y;
siz[y] += siz[x];
}
else {
par[y] = x;
siz[x] += siz[y];
}
}
long long size(int x){
return siz[find(x)];
}
bool same(int x, int y) {
return (find(x) == find(y));
}
};
int main(){
cin.tie(0); ios::sync_with_stdio(false);
ll n, k; cin >> n >> k;
ll a[n][n]; zep(i, 0, n)zep(j, 0, n)cin >> a[i][j];
union_find ufi(n), ufj(n);
zep(x, 0, n){
zep(y, x + 1, n){
bool ok = true;
zep(j, 0, n)if(a[x][j] + a[y][j] > k)ok = false;
if(ok)ufj.unite(x, y);
}
}
zep(x, 0, n){
zep(y, x + 1, n){
bool ok = true;
zep(i, 0, n)if(a[i][x] + a[i][y] > k)ok = false;
if(ok)ufi.unite(x, y);
}
}
ll ans = 1;
zep(i, 0, n){
if(ufj.find(i) == i){
rep(p, 1, ufj.size(i)){
ans *= p;
ans %= MOD;
}
}
}
zep(j, 0, n){
if(ufi.find(j) == j){
rep(p, 1, ufi.size(j)){
ans *= p;
ans %= MOD;
}
}
}
print(ans)
return 0;
} | #include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <cstring>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <random>
const int32_t MOD = 998244353;
int32_t dfs(int32_t x, std::vector< bool > &vis, const std::vector< std::vector< bool > > &adj) {
vis[x] = true;
int32_t comp = 1;
int32_t n = adj.size();
for(int32_t i = 0; i < n; i++) {
if(adj[x][i] && !vis[i]) {
comp += dfs(i, vis, adj);
}
}
return comp;
}
int32_t fact(int32_t x) {
int32_t ans = 1;
for(int32_t i = 2; i <= x; i++) {
ans = (int64_t) ans * i % MOD;
}
return ans;
}
int32_t count(const std::vector< std::vector< bool > > &adj) {
int32_t n = adj.size(), ans = 1;
std::vector< bool > vis(n, false);
for(int32_t i = 0; i < n; i++) {
if(!vis[i]) {
ans = (int64_t) ans * fact(dfs(i, vis, adj)) % MOD;
}
}
return ans;
}
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
int32_t n, k;
std::cin >> n >> k;
std::vector< std::vector< int32_t > > v(n, std::vector< int32_t >(n));
for(int32_t i = 0; i < n; i++) {
for(int32_t j = 0; j < n; j++) {
std::cin >> v[i][j];
}
}
std::vector< std::vector< bool > > rows(n, std::vector< bool >(n, false));
for(int32_t i1 = 0; i1 < n; i1++) {
for(int32_t i2 = i1 + 1; i2 < n; i2++) {
int32_t cnt = 0;
for(int32_t j = 0; j < n; j++) {
if(v[i1][j] + v[i2][j] <= k) {
cnt++;
}
}
if(cnt == n) {
rows[i1][i2] = true;
rows[i2][i1] = true;
}
}
}
std::vector< std::vector< bool > > cols(n, std::vector< bool >(n, false));
for(int32_t i1 = 0; i1 < n; i1++) {
for(int32_t i2 = i1 + 1; i2 < n; i2++) {
int32_t cnt = 0;
for(int32_t j = 0; j < n; j++) {
if(v[j][i1] + v[j][i2] <= k) {
cnt++;
}
}
if(cnt == n) {
cols[i1][i2] = true;
cols[i2][i1] = true;
}
}
}
std::cout << (int64_t) count(rows) * count(cols) % MOD << '\n';
}
|
#include<cstdio>
using namespace std;
typedef long long LL;
const int maxn=100,maxm=499950;
int n,K,MOD,f[maxn+5][maxm+5],F[maxn+5];
int main(){
scanf("%d%d%d",&n,&K,&MOD);f[0][0]=1;
for (int i=1,sum=i*K;i<=n;i++,sum+=i*K){
for (int j=0;j<i;j++) F[j]=0;
for (int j=0;j<=sum;j++){
F[j%i]=(F[j%i]+f[i-1][j])%MOD;
if (j>=i*(K+1)) F[j%i]=(F[j%i]+MOD-f[i-1][j-i*(K+1)])%MOD;
f[i][j]=F[j%i];
}
}
for (int x=1;x<=n;x++){
int ans=MOD-1;
for (int j=0;j<=maxm;j++) ans=(ans+(LL)f[x-1][j]*f[n-x][j]%MOD*(K+1)%MOD)%MOD;
printf("%d\n",ans);
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
long long N;
long long A[1 << 18];
long long dp1[1 << 18][2];
long long dp2[1 << 18][2];
int main(){
cin >> N;
for (int i = 1; i <= N; i++) cin >> A[i];
dp1[1][0] = 1;
dp2[1][0] = A[1];
for (int i = 2; i <= N; i++) {
for (int j = 0; j <= 1; j++) {
// + を選ぶ場合
dp1[i][0] += dp1[i - 1][j];
dp2[i][0] += dp2[i - 1][j] + dp1[i - 1][j] * A[i];
dp1[i][0] %= mod;
dp2[i][0] %= mod;
// - を選ぶ場合
if (j == 0) {
dp1[i][1] += dp1[i - 1][j];
dp2[i][1] += dp2[i - 1][j] - dp1[i - 1][j] * A[i];
dp1[i][1] %= mod;
dp2[i][1] = (dp2[i][1] + mod * mod) % mod;
}
}
}
cout << (dp2[N][0] + dp2[N][1]) % mod << endl;
return 0;
}
|
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long
using namespace std;
long long MOD = 1000000007;
struct info{
ll num;
ll cost;
};
bool operator< (const info &info1, const info &info2){
return info1.cost<info2.cost;
}
bool operator> (const info &info1, const info &info2){
return info1.cost>info2.cost;
}
int main(){
ll X, Y;
cin >> X >> Y;
if(X>=Y){
cout << X-Y << endl;
return 0;
}
priority_queue<info, vector<info>, greater<info>> pque;
pque.push({Y,0});
map<ll,int> dict;
while(!pque.empty()){
info now=pque.top();
//cout << now.num << ' ' << now.cost << endl;
pque.pop();
if(dict.count(now.num))continue;
else{
dict[now.num]=now.cost;
}
if(now.num==X){
cout << now.cost << endl;
return 0;
}else if(now.num%2==0){
pque.push({X,now.cost+abs(X-now.num)});
pque.push({now.num/2,now.cost+1});
}else{
pque.push({now.num+1,now.cost+1});
pque.push({now.num-1,now.cost+1});
}
}
} | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define INF LONG_MAX/3
//#define DIV 1000000007
//#define DIV 998244353
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ll N, K;
ll cou0[4000005];
ll cou1[4000005];
ll sumi;
//綺麗さがiのときに何通りあるか
ll kire[4000005];
void pre() {
//合計がそれぞれいくつあるか
for(ll i = 2; i <= 2*N; i++) {
if(i <= 1) continue;
if(i <= N + 1) {
cou1[i] = i-1;
cou0[i] = i-1;
} else {
cou1[i] = 2*N+1-i;
cou0[i] = 2*N+1-i;
}
}
rep(i, 3*N+1) cou1[i+1] += cou1[i];
}
//3つの合計がnum以下になる君合わせ
ll get_cou(ll num) {
ll ret = 0;
for(ll i = 1; i <= N; i++) {
ll maxi = num - i;
if(maxi < 0) continue;
ret += cou1[maxi];
}
return ret;
}
//合計が決まってるとき、kireの値で何通りあり得るか
void pre2() {
for(ll ki = 1; ki <= N; ki++) {
ll others = sumi - ki;
if(others <= 1 || others > 2*N) continue;
kire[ki] += cou0[others];
}
rep(i, N+5) {
//cout << "kire[" << i << " ] = " << kire[i] << endl;
kire[i+1] += kire[i];
}
}
int main(){
cin >> N >> K;
pre();
ll ok = 0;
ll ng = 3*N;
while(ok + 1 < ng) {
ll mid = (ok + ng)/2;
if(get_cou(mid) >= K) {
ng = mid;
} else {
ok = mid;
}
}
//cout << ok << endl;
//三つの合計はsumi
sumi = ok + 1;
//3つの合計がsumiになるときにkireisaで何番目になるかの二部たん
pre2();
ll K2 = K - get_cou(ok);
//cout << "p0 ok = " << ok << " get_cout - " << get_cou(ok) << endl;
//綺麗さについて二部たん
ok = 0;
ng = N+1;
while(ok + 1 < ng) {
ll mid = (ok + ng)/2;
if(kire[mid] >= K2) {
ng = mid;
} else {
ok = mid;
}
}
//cout << "K2 = " << K2 << " kire[" << ok << "] = " << kire[ok] << endl;
ll kirev = ok + 1;
//cout << "sumi = " << sumi << endl;
//cout << "kirev = " << kirev << endl;
ll K3 = K2 - kire[ok];
//cout << "K3 = " << K3 << endl;
//3つのわ, kirei, oisi, ninki
vector<tuple<ll, ll, ll, ll> >ans;
for(ll oi = 1; oi <= N; oi++) {
ll nin = sumi - kirev - oi;
if(nin <= 0 || nin > N) continue;
ans.push_back({sumi, kirev, oi, nin});
}
sort(ans.begin(), ans.end());
//cout << "K3 = " << K3 << " ans " << ans.size() << endl;
ll _, k, o, n;
tie(_, k, o, n) = ans[K3-1];
cout << k << " " << o << " " << n << endl;
}
|
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair<int,int>
#define INF 1000000000
#define all(x) (x.begin(), x.end())
#define IOS ios_base :: sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef vector<int> vi;
void testcases() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
vi adj[112345];
int ans = 0;
int visited[112345];
void dfs(int v) {
visited[v] = 1;
ans++;
for (auto x : adj[v]) {
if (visited[x] == 1) continue;
dfs(x);
}
}
void solve() {
int n,m;cin>>n>>m;
int a,b;
for (int i = 0; i < m; i++) {
cin>>a>>b;
adj[a].pb(b);
}
for (int k = 1; k <= n; k++) {
for (int i = 1; i <= n; i++) {
visited[i] = 0;
}
dfs(k);
}
cout << ans << '\n';
}
int main()
{
//testcases();
IOS;
solve();
return 0;
} | #include <bits/stdc++.h>
std::vector<std::string> split(const std::string& source, const char delim);
struct Node{
explicit Node(const int nodeId)
:node_id(nodeId){
};
int addNode(const std::shared_ptr<Node>& nodeSptr){
child_node_sptr_list.emplace_back(nodeSptr);
return 0;
};
int node_id;
std::vector<std::weak_ptr<Node>> child_node_sptr_list;
};
int main(){
std::string buffer;
std::getline(std::cin, buffer);
auto splitInput = split(buffer, ' ');
const int NUM_CITY = std::stoi(splitInput[0]);
const int NUM_ROOT = std::stoi(splitInput[1]);
std::map<int, std::shared_ptr<Node>> nodeSptrList;
for(int num = 0; num < NUM_CITY; ++num){
nodeSptrList.emplace(num + 1, std::make_shared<Node>(num + 1));
nodeSptrList[num + 1]->addNode(nodeSptrList[num + 1]);
}
for(int num = 0; num < NUM_ROOT; ++num){
std::getline(std::cin, buffer);
auto splitRootInfo = split(buffer, ' ');
const int startNodeId = std::stoi(splitRootInfo[0]);
const int endNodeId = std::stoi(splitRootInfo[1]);
nodeSptrList[startNodeId]->addNode(nodeSptrList[endNodeId]);
}
std::map<std::pair<int, int>, int> uniqueRootList;
for(const auto& startNodeSptrPair : nodeSptrList){
std::queue<std::shared_ptr<Node>> nodeSptrQueue;
nodeSptrQueue.emplace(startNodeSptrPair.second);
while(!nodeSptrQueue.empty()){
std::shared_ptr<Node> nodeSptr{nodeSptrQueue.front()};
nodeSptrQueue.pop();
for(auto it = nodeSptr->child_node_sptr_list.begin(); it != nodeSptr->child_node_sptr_list.end(); ++it){
if(std::shared_ptr<Node> childNodeSptr = it->lock()){
const auto scanningRoot = std::make_pair(startNodeSptrPair.first, childNodeSptr->node_id);
if(uniqueRootList.find(scanningRoot) == uniqueRootList.end()){
nodeSptrQueue.emplace(childNodeSptr);
uniqueRootList.emplace(scanningRoot, 1);
}
}
}
}
}
std::cout << uniqueRootList.size() << std::endl;
return 0;
}
std::vector<std::string> split(const std::string& source, const char delim){
std::vector<std::string> splitData;
std::stringstream sstream(source);
std::string itemBuffer;
while(std::getline(sstream, itemBuffer, delim)){
splitData.emplace_back(itemBuffer);
}
return splitData;
} |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define endl '\n'
#define f first
#define s second
#define ub upper_bound
#define lb lower_bound
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define fbo find_by_order
#define ook order_of_key
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << "[" << name << " : " << arg1 << "]" << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cerr << "[";
cerr.write(names, comma - names) << " : " << arg1<<"] | ";__f(comma+1, args...);
}
using ld = long double;
using ll = long long;
using pii = pair <int,int>;
using pll = pair <ll,ll>;
using vi = vector <int>;
using vll = vector <ll>;
using vpii = vector <pii>;
using vpll = vector<pll>;
using vs = vector <string>;
int main(){
fastio;
int n;
cin >> n;
vll a(n), b(n);
vi id(n);
ll va = 0, vb = 0;
for(int i=0;i<n;i++)
cin >> a[i] >> b[i], id[i] = i, va += a[i];
sort(all(id),[&](auto i, auto j){
return (2*a[i]+b[i] > 2*a[j]+b[j]) or ((2*a[i]+b[i] == 2*a[j]+b[j]) and a[i] > a[j]);
});
int ans = 0;
for(int x:id){
if(vb > va) break;
ans++;
vb += (a[x]+b[x]);
va -= a[x];
}
cout << ans << endl;
return 0;
} | #include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cstdlib>
#include<cmath>
#include<map>
#include<queue>
#include<stack>
#include<set>
#include<iomanip>
#include<iterator>
#include<sstream>
using namespace std;
int main()
{
long long n,a,b,ta,ao,i,k,l;
vector<pair<long long,long long> >v;
cin>>n;
ta=ao=0;
while(n--)
{
cin>>a>>b;
v.push_back(make_pair(((2*a)+b),a));
ao+=a;
}
sort(v.begin(),v.end(),greater<pair<long long,long long> >());
k=l=0;
for(i=0;i<v.size();i++)
{
k+=(v[i].first-v[i].second);
l+=v[i].second;
if(k>(ao-l))
{
cout<<i+1<<endl;
break;
}
}
return 0;
}
|
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pop_b pop_back
#define pf push_front
#define pop_f pop_front
#define mt make_tuple
#define eb emplace_back
#define sf(x) sizeof(x)
#define len(x) x.length()
#define sz(x) x.size()
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define LB(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define UB(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
typedef long long ll;
typedef pair<ll,ll> ii;
typedef long double ld;
typedef vector<int> vi;
typedef vector<set<ll>> vset;
typedef vector<ll> vl;
typedef vector<ld> vd;
typedef deque<ll> dql;
typedef deque<int> dqi;
typedef unsigned long long ull;
typedef tuple<int,int,int> State;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << "\n";
err(++it, args...);
}
#define vmax(type) std::numeric_limits<type>::max()
#define vmin(type) std::numeric_limits<type>::min()
#define each(a,x) for( auto &a:(x))
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rep2(i, l, r) for (ll i = (l); i < (r); i++)
#define rep2r(i, l, r) for (ll i = (r) - 1; i >= (l); i--)
#define range(a) a.begin(), a.end()
#define deb(x) cout<<#x<<" "<<x<<endl;
#define cinai(a, n) vi a(n); rep(i, n) { cin>>a[i]; }
#define cinal(a, n) vl a(n); rep(i, n) { cin>>a[i]; }
#define coutai(a, n) rep(i, n) { cout<<a[i]<<" "; } ent;
#define coutal(a, n) rep(i, n) { cout<<a[i]<<" "; } ent;
#define ent cout<<endl;
#define resize_vec(a) a.resize(unique(a.begin(), a.end()) - a.begin());
#define ms(dp, x) memset(dp, x, sf(dp))
#define endl '\n'
ll powm(ll a, ll b, ll mod) {
ll res=1;
while(b) {
if(b&1)
res=(res*a)%mod;
a=(a*a)%mod;
b>>=1;
}
return res;
}
int db = 0;
const ll mod = 1e9 + 7;
const ll N = 55;
const ll inf = 1e9;
#define er if(db) error
int n;
ll x;
ll a[N], pres[N], dp[N][2];
ll rec(int i, int t){
if(i == n-1)
return 1;
if(dp[i][t] != -1)
return dp[i][t];
ll pro = a[i+1] / a[i];
ll cur = pres[i] + t;
if(cur == pro)
return dp[i][t] = rec(i+1, t);
ll ans = rec(i+1, 0);
if(cur)
ans += rec(i+1, 1);
return dp[i][t] = ans;
}
void solve()
{
cin>>n>>x;
rep(i, n)
cin>>a[i];
memset(dp, -1, sizeof(dp));
repr(i, n){
pres[i] = x / a[i];
x %= a[i];
}
cout<<rec(0, 0)<<endl;
}
// #define _DEBUG
// #define testCases
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cout << fixed << setprecision(15);
// freopen("input.txt", "r", stdin);
int tc = 1;
#ifdef testCases
cin>>tc;
#endif
for(int t = 1; t <= tc; t++)
{
#ifdef _DEBUG
db = 1;
int tt = clock();
#endif
// cout<<"Case #"<<t<<": ";
solve();
#ifdef _DEBUG
cerr << "TIME = " << clock() - tt << endl;
tt = clock();
#endif
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(all(v));
#define RSORT(v) sort(rall(v));
#define pb push_back
#define mp make_pair
#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)
ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }
const string YES = "Yes";
const string NO = "No";
int main() {
// cout << fixed << setprecision(5);
int N, M, T;
cin >> N >> M >> T;
vector<int> A(M), B(M);
rep(i, M) cin >> A[i] >> B[i];
int battery = N;
int last_time = 0;
rep(i, M) {
battery += last_time - A[i];
if (battery <= 0) {
cout << "No" << endl;
return 0;
}
battery += B[i] - A[i];
battery = min(battery, N);
last_time = B[i];
}
battery += last_time - T;
if (battery > 0)
cout << "Yes" << endl;
else
cout << "No" << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long ;
int main() {
string S, small, large ;
cin >> S ;
small="abcdefghijklmnopqrstuvwxyz" ;
large="ABCDEFGHIJKLMNOPQRSTUVWXYZ" ;
int size_S=S.size(), size_small=small.size(), size_large=large.size() ;
for(int i=0;i<size_S;i++){
if(i%2==0){ //奇数
for(int j=0;j<size_small;j++){
if(S.at(i)==small.at(j)) break ;
if(j==size_small-1){
cout << "No" << endl ;
return 0 ;
}
}
}
if(i%2==1){ //偶数
for(int k=0;k<size_large;k++){
if(S.at(i)==large.at(k)) break ;
if(k==size_large-1){
cout << "No" << endl ;
return 0 ;
}
}
}
}
cout << "Yes" << endl ;
return 0 ;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}
bool solve(string s) {
for (int i = 0; i < s.size(); i += 2) {
if (!islower(s[i])) return false;
}
for (int i = 1; i < s.size(); i += 2) {
if (!isupper(s[i])) return false;
}
return true;
}
int main2() {
string s; cin >> s;
bool ans = solve(s);
cout << (ans ? "Yes": "No") << endl;
return 0;
}
int main() {
#ifdef LOCAL
for (;!cin.eof();cin>>ws)
#endif
main2();
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int main()
{
size_t N;
long long K, M;
cin >> N >> K >> M;
vector<vector<long long>> dp(N + 1, vector<long long>(N / 2 * (N / 2 + 1) / 2 * K + (N + 5), 0));
dp[0][0] = 1;
for (size_t i = 1; i <= N; i++)
{
vector<long long> sum(i, 0);
for (size_t j = 0; j < dp[i].size(); j++)
{
sum[j % i] += dp[i - 1][j];
sum[j % i] %= M;
if (j >= (K + 1) * i)
{
sum[j % i] -= dp[i - 1][j - (K + 1) * i];
if (sum[j % i] < 0)
{
sum[j % i] += M;
}
sum[j % i] %= M;
}
dp[i][j] = sum[j % i];
}
}
for (size_t i = 1; i <= N; i++)
{
long long ans = 0;
for (size_t j = 1; j < dp[i].size(); j++)
{
ans += dp[i - 1][j] * dp[N - i][j];
ans %= M;
}
ans *= (K + 1);
ans %= M;
ans += K;
ans %= M;
cout << ans << endl;
}
}
| #include <iostream>
#include <iomanip>
#include <algorithm>
#include <array>
#include <cassert>
#include <optional>
#include <utility>
#include <vector>
//#include <atcoder/all>
template <class InputIterator>
std::ostream& range_output(std::ostream& os_arg, InputIterator first_arg, InputIterator last_arg){ if(first_arg != last_arg){ do{ os_arg << *(first_arg++); if(first_arg == last_arg) break; os_arg << ' '; } while(true); } return os_arg; }
template <class Tp> std::ostream& operator << (std::ostream& os_arg, const std::vector<Tp>& arr_arg){ return range_output(os_arg, arr_arg.cbegin(), arr_arg.cend()); }
template <class Tp, std::size_t Size> std::ostream& operator << (std::ostream& os_arg, const std::array<Tp, Size>& arr_arg){ return range_output(os_arg, arr_arg.cbegin(), arr_arg.cend()); }
template <class S, class T> std::ostream& operator << (std::ostream& os_arg, const std::pair<S, T>& pair_arg){ return os_arg << '(' << pair_arg.first << ", " << pair_arg.second << ')'; }
#ifndef ONLINE_JUDGE
template <typename Head> void dump_out(Head head_arg){ std::cerr << head_arg << '\n'; }
template <typename Head, typename... Tail>
void dump_out(Head head_arg, Tail... tail_args){ std::cerr << head_arg << ", "; dump_out(tail_args...); }
#define dump(...) do { std::cerr << "[in line " << __LINE__ << "] " << #__VA_ARGS__ << " : "; dump_out(__VA_ARGS__); } while(false)
#else
#define dump(...) (void(0))
#endif
int n, k, m;
constexpr int HighestDim = 505000;
long long int A[HighestDim + 1], B[HighestDim + 1];
void mult(long long int* a, int v){
for(int i = HighestDim, j = i - v; j >= 0; --i, --j){
a[i] -= a[j]; if(a[i] < 0) a[i] += m;
}
}
void div(long long int* a, int v){
for(int i = v, j = 0; i <= HighestDim; ++i, ++j){
a[i] += a[j]; if(a[i] >= m) a[i] -= m;
}
}
int main(void){
std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false);
std::cout << std::fixed << std::setprecision(16);
A[0] = 1; B[0] = 1;
std::cin >> n >> k >> m;
for(int i = 1; i <= n - 1; ++i) mult(A, i * (k + 1));
for(int i = 1; i <= n - 1; ++i) div(A, i);
std::vector<long long int> res(n + 1);
res[1] = k; res[n] = k;
for(int i = 2, j = n - 1; i <= j; ++i, --j){
mult(A, n - i + 1); div(A, (k + 1) * (n - i + 1) );
mult(B, (k + 1) * (i - 1)); div(B, i - 1);
for(int d = 0; d <= HighestDim; ++d) res[i] += static_cast<long long int>(A[d]) * B[d] % m;
res[i] %= m; res[i] *= (k + 1); res[i] %= m;
--res[i]; if(res[i] < 0) res[i] += m;
res[j] = res[i];
}
for(int i = 1; i <= n; ++i) std::cout << res[i] << '\n';
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using P = pair<ll, ll>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, -1, 0, 1};
string char_to_string(char val) {
return string(1, val);
}
int char_to_int(char val) {
return val - '0';
}
char inverse_char(char c) {
if(isupper(c)) return tolower(c);
else return toupper(c);
}
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
struct edge {
ll to, cost;
};
// 半分全列挙のお勉強
int main() {
int N; cin >> N;
ll T; cin >> T;
vector<ll> A(N); REP(i, N) cin >> A[i];
int n = min(N, 20);
int m = N - n;
vector<ll> v1, v2;
v1.push_back(0); v2.push_back(0);
int k1 = 1 << n; int k2 = 1 << m;
for(int i = 1; i < k1; ++i) {
ll t = 0;
for(int j = 0; j < n; ++j) {
if(((1 << j) & i) != 0) {
t += A[j]; // 前からn個だけ走査して条件を満たした項目だけ足し込む
}
}
if(t <= T) v1.push_back(t);
}
for(int i = 1; i < k2; ++i) {
ll t = 0;
for(int j = n; j < N; ++j) {
if(((1 << (j - n)) & i) != 0) {
t += A[j]; // 前からn個だけ走査して条件を満たした項目だけ足し込む
}
}
if(t <= T) v2.push_back(t);
}
sort(all(v1)); sort(all(v2));
ll ans = 0;
for(ll i : v1) {
int l = -1;
int r = v2.size();
while(r - l > 1) {
int mid = l + (r - l) / 2;
if(i + v2[mid] <= T) l = mid;
else r = mid;
}
ll res = i + v2[l];
ans = max(ans, res);
}
cout << ans << endl;
} | #include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
int N;
cin >> N;
vector<long long> A;
A.push_back(0);
for (int i = 1; i <= N; i++) {
long long a;
cin >> a;
A.push_back(a);
}
vector<long long> max_move, move;
max_move.resize(N + 1);
move.resize(N + 1);
for (int i = 0; i < N; i++) {
move[i + 1] = move[i] + A[i + 1];
max_move[i + 1] = max(move[i + 1], max_move[i]);
}
long long x = 0;
long long x_max = 0;
for (int i = 1; i <= N; i++) {
x_max = max(x_max, x + max_move[i]);
x += move[i];
}
cout << x_max << endl;
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#define int long long
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
int c = 0;
map<int,int> m;
for(int i = 2; i*i <= n; i++)
{
int x = i*i;
if(m[i] == 1)
continue;
while(x <= n)
{
m[x] = 1;
c++;
x *= i;
}
}
cout << (n - c) << endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define ld long double
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define pf push_front
#define ff first
#define ss second
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define vl vector<lli>
#define vll vector<pair<lli,lli>>
//////////////////////////////////////////////////////// By: Umang Srivastava
// lli extgcd(lli a, lli b, lli *x , lli *y)
// {
// if(a==0)
// {
// *x=0;
// *y=1;
// return b;
// }
// lli x1 , y1;
// lli gcd = extgcd(b%a , a , &x1 , &y1);
// *x= y1 - (b/a) * x1;
// *y=x1;
// return gcd;
// }
// lli modinv(lli a, lli m)
// {
// lli x,y;
// lli g = extgcd(a,m,&x,&y);
// if(g!=1)
// return -1;
// return (x%m+m)%m;
// }
// lli moddiv(lli a, lli b, lli m)
// {
// a=a%m;
// lli inv = modinv(b,m);
// if(inv!=-1)
// return ((a*inv + m)%m);
// else
// return -1;
// }
// lli binpow(lli a, lli b, lli m)
// {
// lli res=1;
// a=a%m;
// while(b>0)
// {
// if(b & 1)
// {
// res = (res * a)%m;
// }
// b=b>>1;
// a=(a*a)%m;
// }
// return res;
// }
// lli gcd(lli a, lli b)
// {
// // if(b<a)
// // {
// // lli t=a;
// // a=b;
// // b=t;
// // }
// if(a==0)
// return b;
// return gcd(b%a,a);
// }
// lli fac[1000005];
// void calcfac(lli m)
// {
// fac[0]=1;
// for(lli i=1;i<=1000001;i++)
// {
// fac[i]=(fac[i-1]*i)%m;
// }
// }
// lli ncr(lli n,lli r,lli m)
// {
// if(r==0 || r==n)
// return 1;
// return (((fac[n]*binpow(fac[r],m-2,m))%m)*(binpow(fac[n-r],m-2,m)))%m;
// }
/////////////////////////////////////////////////////////
// lli fillst(lli ar[], lli ss, lli se, lli *st, lli si)
// {
// if(ss==se)
// {
// st[si]=ar[ss];
// return ar[ss];
// }
// lli mid = ss + (se-ss)/2;
// st[si] = min(fillst(ar,ss,mid,st,2*si+1) , fillst(ar,mid+1,se,st,2*si+2));
// return st[si];
// }
// lli RMQ(lli *st, lli ss, lli se, lli qs, lli qe, lli index)
// {
// if(qs<=ss && qe>=se)
// return st[index];
// if(se<qs || ss>qe)
// return 10000000000;
// lli mid = ss+ (se-ss)/2;
// return min(RMQ(st,ss,mid,qs,qe,2*index+1), RMQ(st,mid+1,se,qs,qe,2*index+2));
// }
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
lli n,m,i,j,k,tc,t,a,b,c,d,x,y,q;
t=1;
a=b=0;
c=d=0;
// cin>>t;
while(t--)
{
cin>>n;
lli ar[n];
for(i=0;i<n;i++)
{
cin>>ar[i];
}
lli s=0;
lli v=0;
for(i=0;i<n;i++)
{
a=ar[i];
for(j=i;j<n;j++)
{
if(ar[j]<a)
a=ar[j];
v=max(v,a*(j-i+1));
}
}
cout<<v<<endl;
}
} |
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define vi vector<int>
#define ff first
#define ss second
#define pb push_back
#define MOD 1000000007
//const int nax = 1e6+5;
#define inf 4e18
#define display(v) for(int i =0;i<(int)v.size();++i)cout << v[i] << " "
#define all(v) v.begin(),v.end()
#define read(a) for(int i = 0;i<(int)a.size();++i)cin>>a[i]
#define show(x) cout << #x << " is " << x << "\n";
#define show_arr(a) cout << #a << "\n"; display(a) ; cout << "\n";
inline int add(int a, int b){ int c = (a%MOD) + (b%MOD); if(c >= MOD) c -= MOD; return c; }
inline int mul(int a, int b){ return ((a%MOD) * 1ll * (b%MOD)) % MOD; }
inline int sub(int a, int b){ int c = (a%MOD) - (b%MOD); if(c < 0) c += MOD; return c; }
const int nax = 300*1000 + 10;
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n ; cin>>n;
int sum = 0;
vector<pair<int,int>> a(n);
vi b(n);
for(int i =0 ;i<n;++i){
cin>>a[i].ff>>a[i].ss;
sum += a[i].ff;
b[i] = 2*a[i].ff + a[i].ss ;
}
sort(all(b));
reverse(all(b));
int ans = 0;
int tak = 0 , aoki = sum;
for(int i = 0;i<n;++i){
if(tak > aoki)break;
tak += b[i];
++ans;
}
cout << ans;
return 0;
}
// Химаншу
// check overflow
// special case n == 1
// 🍪🍪🍪
| #include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const int mod = 1000000007;
struct mint {
ll x; // typedef long long ll;
mint(ll x=0):x((x%mod+mod)%mod){}
mint operator-() const { return mint(-x);}
mint& operator+=(const mint a) {
if ((x += a.x) >= mod) x -= mod;
return *this;
}
mint& operator-=(const mint a) {
if ((x += mod-a.x) >= mod) x -= mod;
return *this;
}
mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
mint operator+(const mint a) const { return mint(*this) += a;}
mint operator-(const mint a) const { return mint(*this) -= a;}
mint operator*(const mint a) const { return mint(*this) *= a;}
mint pow(ll t) const {
if (!t) return 1;
mint a = pow(t>>1);
a *= a;
if (t&1) a *= *this;
return a;
}
// for prime mod
mint inv() const { return pow(mod-2);}
mint& operator/=(const mint a) { return *this *= a.inv();}
mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
vector<int> a(n);
rep(i,n) cin >> a[i];
mint ans = 1;
int s = 0;
rep(i,n) s += a[i];
rep(i,n+s) ans *= (m+n-i);
rep(i,n+s) ans /= (i+1);
cout << ans << endl;
} |
#include<iostream>
#include<cassert>
using namespace std;
typedef long long ll;
template <int N>
struct modInt {
long long val;
modInt(ll v){
this->val = v%N;
}
int toInt(){
return this->val;
}
void operator=(const ll other){
this->val = other%N;
}
};
template<int N> modInt<N> operator+(const modInt<N> &,const modInt<N> &);
template<int N> modInt<N> operator+(const modInt<N> &,const ll);
template<int N> modInt<N> operator*(const modInt<N> &,const modInt<N> &);
template<int N> modInt<N> operator*(const modInt<N> &,const ll);
template<int N> modInt<N> operator/(const modInt<N> &,const modInt<N> &);
template<int N> modInt<N> operator/(const modInt<N> &,const ll);
template<int N> modInt<N> binpow(const modInt<N> &,const int);
template<int N> modInt<N> inverse(const modInt<N> &);
template<int N> modInt<N> pw(const modInt<N> &,const int);
template<int N> modInt<N> operator+(const modInt<N> &a,const modInt<N> &b){
return modInt<N>(a.val + b.val);
}
template<int N> modInt<N> operator+(const modInt<N> &a, const ll b){
modInt<N> c(b);
return a+c;
}
template<int N> modInt<N> operator*(const modInt<N> &a,const modInt<N> &b){
modInt<N> res(a.val*b.val);
return res;
}
template<int N> modInt<N> operator*(const modInt<N> &a, const ll b){
modInt<N> c(b);
return a*c;
}
template<int N> modInt<N> operator/(const modInt<N> &a,const modInt<N> &b){
modInt<N> c = inverse<N>(b);
return a*c;
}
template<int N> modInt<N> operator/(const modInt<N> &a, const ll b){
modInt<N> c(b);
return a/c;
}
template<int N> modInt<N> inverse(const modInt<N> &a){
return binpow(a,N-2);
}
template<int N> modInt<N> pw(const modInt<N> &a,int exp){
if(exp<0){
modInt<N> inverse = inverse(a);
return binpow<N>(a,-exp);
}
return binpow<N>(a,exp);
}
template<int N> modInt<N> binpow(const modInt<N> &a,int b){
if(b==0){
return modInt<N>(1);
}
modInt<N> v = binpow<N>(a,b/2);
modInt<N> res = v*v;
if(b%2==1){
return a*res;
}
return res;
}
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 998244353;
int main(){
cin.tie(0);
ios::sync_with_stdio(0);
int n,m;
cin>>n>>m;
vector<modInt<mod>> row(n+1,1);
for(int i=1;i<=n;i++){
row[i] = (row[i-1]*(n-i+1))/i;
}
vector<modInt<mod>> dp(m+1,0);
dp[0] = 1;
for(int j=2;j<=m;j+=2){
for(int i=0;i<=min(j,n);i+=2){
dp[j]=dp[j]+(dp[(j-i)/2]*row[i]);
}
}
cout<<dp[m].toInt()<<endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define deb(...)
#endif
#define endl "\n"
#define pb push_back
// #define int long long
#define ll long long
#define pii pair<int,int>
#define F first
#define S second
#define all(c) c.begin(),c.end()
#define read(v) for(auto &it:v) cin>>it;
// const int inf = 1e18;
const int N = 5e3 + 5;
const int mod = 998244353;
int maxi[12];
int n, m;
int ans = 0;
ll f[N], invf[N];
ll mpow(ll x, ll y) {
ll res = 1;
x = x % mod;
while (y > 0) {
if (y & 1) res = (res * x) % mod;
y = y >> 1;
x = (x * x) % mod;
}
return res;
}
ll modInv(ll n) {
return mpow(n, mod - 2);
}
ll C(ll n, ll r) {
if (r == 0) return 1;
assert(n >= r);
return (f[n] * invf[r] % mod * invf[n - r] % mod) % mod;
}
void fact() {
f[0] = 1;
invf[0] = 1;
for (int i = 1; i < N; i++) {
f[i] = (f[i - 1] * i) % mod;
invf[i] = modInv(f[i]);
}
}
namespace modop {
ll madd(ll a, ll b) {
return (a + b) % mod;
}
ll msub(ll a, ll b) {
return (((a - b) % mod) + mod) % mod;
}
ll mmul(ll a, ll b) {
return ((a % mod) * (b % mod)) % mod;
}
ll minv(ll base) {
return mpow(base, mod - 2);
}
ll mdiv(ll a, ll b) {
return mmul(a, minv(b));
}
}
using namespace modop;
int dp[12][5005];
int go(int bit, int sum) {
if (bit == 12) {
if (sum == 0) {
return 1;
}
else {
return 0;
}
}
if (dp[bit][sum] != -1) {
return dp[bit][sum];
}
int ans = 0;
int p = (1LL << bit);
for (int i = 0; i <= maxi[bit]; i += 2) {
int zx = i * p;
if (zx <= sum) {
int coeff = C(n, i);
ans = madd(ans, mmul(coeff, go(bit + 1, sum - zx)));
}
else {
break;
}
}
return dp[bit][sum] = ans;
}
void testCase() {
cin >> n >> m;
fact();
for (int i = 0; i <= 11; i++) {
int max_take = min(n, m / (1 << i));
maxi[i] = max_take;
}
memset(dp, -1, sizeof dp);
cout << go(0, m) << endl;
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t = 1;
// cin >> t;
while (t--)testCase();
return 0;
} |
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
using namespace std;
using ll = long long;
int main(){
ll n;
cin >> n;
vector<ll> a(n);
vector<ll> p(n);
vector<ll> q(n);
rep(i,n){
cin >> a[i];
if(i==0){
p[i] = a[i];
q[i] = p[i];
}else{
p[i] = p[i-1] + a[i];
q[i] = max(q[i-1],p[i]);
}
}
ll x = 0;
ll ans=0;
rep(i,n){
ans = max(x+q[i], ans);
x = x + p[i];
}
cout << ans << endl;
return 0;
} | #define _DEBUG
#include "bits/stdc++.h"
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif
#define rep(index,num) for(int index=0;index<(int)num;index++)
#define rep1(index,num) for(int index=1;index<=(int)num;index++)
#define brep(index,num) for(int index=(int)num-1;index>=0;index--)
#define brep1(index,num) for(int index=(int)num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
ll A[200001];
ll rui[200001]={};
ll ruimax[200001]={};
ll ruirui[200001]={};
int main(){
int N;
scan(N);
rep(i,N) scan(A[i]);
rep(i,N) rui[i+1]=rui[i]+A[i];
rep(i,N) ruirui[i+1]=ruirui[i]+rui[i+1];
rep(i,N) ruimax[i+1]=max(ruimax[i],rui[i+1]);
ll ruiruimax=-INFl;
int ruiruimaxindex=0;
rep1(i,N){
if(ruiruimax<ruirui[i]){
ruiruimax=ruirui[i];
ruiruimaxindex=i;
}
}
if(N==1){
prin(max(0LL,A[0]));
return 0;
}
if(ruiruimaxindex<=1){
prin(max({0LL,A[0],A[0]+A[0],A[0]+A[0]+A[1]}));
return 0;
}
ll ans=ruirui[ruiruimaxindex-2];
ll now=ans;
rep(i,ruiruimaxindex-1){
now+=A[i];
chmax(ans,now);
}
rep(i,ruiruimaxindex){
now+=A[i];
chmax(ans,now);
}
if(ruiruimaxindex<N){
rep(i,ruiruimaxindex+1){
now+=A[i];
chmax(ans,now);
}
}
prin(ans);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
////////////////////////////////////////////////////////////////////////////<editor-fold desc="macros">
//#define mod 9999991
long mod=9999991;
#define endl "\n"
#define long long long
#define all(v) (v).begin(),(v).end()
#define makeset(v) (v).resize(unique((v).begin(),(v).end())-(v).begin())
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define filein freopen("input.txt", "r", stdin);
#define fileout freopen("output.txt", "w", stdout);
#define getline(x) getline(cin,x)
#define makelower(s) transform(s.begin(),s.end(),s.begin(),::tolower)
bool sortby(pair<int,int> a,pair<int,int> b){
double x=(double )a.first/a.second;
double y=(double )b.first/b.second;
return x<y;}
long Pow(long x, long y) {
if(y == 0)return 1;
long res=Pow(x,y/2)%mod;
res=(res*res)%mod;
if(y&1)res=(res*x)%mod;
return res;
}
#define printcase(x) cout<<"Case "<<in++<<": "<<x<<endl
#define memset(a,b) memset(a,b,sizeof(a))
#define print1d(ary) cout<<"[";for(auto x:(ary)){cout<<x<<",";}cout<<"]"<<endl;
#define print2d(x) for(int m = 0; m <sizeof(x)/sizeof(x[0]) ; ++m){for(int l = 0; l <sizeof(x[0])/sizeof(x[0][0]) ; ++l){cout<<x[m][l]<<" ";}cout<<endl;}
#define pi acos(-1)
#define esp 1e-9
////////////////////////////////////////////////////////////////////////////</editor-fold>
long t,n,m,f=0,ans,a,b;
long tmp;
int main() {
///<editor-fold desc="ios">
IOS
#ifdef _AD_
filein //fileout
#endif
///</editor-fold>
int in=1,o;
cin>>n>>m;
vector<vector<int>> idx(n+1,{0});
for(int i = 1; i <=n ; ++i){
cin>>tmp;
idx[tmp].push_back(i);
}
for(int i = 0; i <=n ; ++i){
idx[i].push_back(n+1);
}
for(int i = 0; i <= n; ++i){
for(int j = 1; j <idx[i].size() ; ++j){
if(idx[i][j]-idx[i][j-1]-1>=m){
cout<<i<<endl;
return 0;
}
}
}
} | #include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>
#include <complex>
#include <bitset>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;
typedef long double ld;
typedef vector<ld> vld;
typedef vector<bool> vb;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()
template <class T> void chmin(T& a, T b) { a = min(a, b);}
template <class T> void chmax(T& a, T b) { a = max(a, b);}
constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);
struct UnionFind {
vector<int> par;
vector<int> cnt;
UnionFind(int n) : par(n), cnt(n, 1) {
for (int i = 0; i < n; ++i) { par[i] = i; }
}
int root(int x) {
if (par[x] == x) return x;
return par[x] = root(par[x]);
}
bool issame(int x, int y) {
return root(x) == root(y);
}
void merge(int x, int y) {
int rx = root(x);
int ry = root(y);
if (rx == ry) return;
par[ry] = rx;
cnt[rx] += cnt[ry];
}
int count(int x) {
return cnt[root(x)];
}
};
void solve() {
ll n, q;
cin >> n >> q;
vll c(n);
rep(i, n) cin >> c[i];
rep(i, n) --c[i];
UnionFind uf(n);
vector<map<ll, ll>> vmp(n);
rep(i, n) vmp[i][c[i]]++;
rep(__i, q) {
ll t, a, b;
cin >> t >> a >> b;
--a, --b;
if(t == 1) {
if(uf.issame(a, b)) continue;
if(uf.count(a) < uf.count(b)) swap(a, b);
// if(vmp[a].size() < vmp[b].size()) swap(a, b);
ll rt_old = uf.root(b);
uf.merge(a, b);
ll rt_new = uf.root(a);
for(auto i = vmp[rt_old].begin(); i != vmp[rt_old].end(); ++i) {
vmp[rt_new][i->first] += i->second;
}
vmp[rt_old].clear();
}
else {
ll rt = uf.root(a);
cout << vmp[rt][b] << endl;
}
}
return;
}
int main() {
std::cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
cout << fixed << setprecision(15);
solve();
} |
#include <bits/stdc++.h>
#define eprintf(args...) fprintf(stderr, args)
#define rep(i, n) for (int i = 0; i < (int)(n); ++ i)
const int mxn = 2e5 + 5;
int n, a[mxn], b[mxn];
std::map <int, std::vector <int> > oa, ob;
int s[mxn];
void update(int x, int v) {
for (++ x; x < mxn; x += x & -x) s[x] += v;
}
int query(int x) {
int ans = 0;
for (++ x; x; x -= x & -x) ans += s[x];
return ans;
}
int frm[mxn];
int main() {
scanf("%d", &n);
rep(i, n) scanf("%d", &a[i]), a[i] += i;
rep(i, n) scanf("%d", &b[i]), b[i] += i;
rep(i, n) oa[a[i]].push_back(i);
rep(i, n) ob[b[i]].push_back(i);
for (auto x : oa) {
std::vector <int> va = x.second, vb = ob[x.first];
if (va.size() != vb.size()) return printf("%d\n", -1), 0;
rep(i, va.size()) frm[vb[i]] = va[i];
}
rep(i, n) update(i, 1);
long long ans = 0;
rep(i, n) ans += query(frm[i] - 1), update(frm[i], -1);
printf("%lld\n", ans);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
void solve() {
string s; cin >> s;
deque<char> t;
int n = s.size();
int rev = 0;
for (int i = 0; i < n; ++i) {
if (s[i] == 'R')rev = 1 - rev;
else {
if (rev == 0) {
if (t.size() > 0 && t.back() == s[i]) t.pop_back();
else t.push_back(s[i]);
}
else if (rev == 1) {
if (t.size() > 0 && t.front() == s[i]) t.pop_front();
else t.push_front(s[i]);
}
}
}
if (rev == 0) {
for (int i = 0; i < (int)t.size(); ++i)cout << t[i];
cout << endl;
}
else {
for (int i = t.size() - 1; i >= 0; --i) {
cout << t[i];
}
cout << endl;
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input1.txt", "r", stdin);
freopen("output1.txt", "w", stdout);
#endif
int t = 1;
// cin >> t;
for (int i = 0; i < t; ++i)
{
solve();
}
} |
#include<bits/stdc++.h>
#include<string>
using namespace std;
const int N=1e3+10;
typedef long long ll;
int n,k,q,m,h,w;
const ll mod=998244353;
int a[N];
int b[N];
map<int,map<int,int> > mp;
set<int> se;
string s;
stack <int> st;
int X[]={-1,-1,-1,0,0,1,1,1};
int Y[]={-1,0,1,-1,1,-1,0,1};
int main()
{
int A,B,C,D;
cin>>A>>B>>C>>D;
cout<<A*D-B*C;
}
| #include<bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define mod 1000000007
#define pb push_back
#define endl "\n"
#define fi first
#define se second
#define ll long long
#define inf 9000000000000000000
#define PI 3.14159265359
int power(int a,int b,int m=mod)
{
if(b==0) return 1;
if(b==1) return a;
int res=power(a,b/2,m);
res=(res*res)%m;
if(b&1) res=(res*a)%m;
return res;
}
int modinv(int a,int m=mod){ return power(a,m-2,m);}
int add(int a,int b,int m=mod){ int c=(a%m+b%m); if(c>=m) c-=m; return c;}
int sub(int a,int b,int m=mod){ int c=(a%m-b%m); if(c<0) c+=m; return c;}
int mul(int a,int b,int m=mod){ return (a*b)%m;}
int32_t main()
{
IOS
int n,a,b;
cin>>n>>a>>b;
int p = max(0LL,n-a);
cout<<p+b<<endl;
} |
/*
written by Pankaj Kumar.
country:-INDIA
Institute: National Institute of Technology, Uttarakhand
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll ;
typedef unsigned long long ull;
typedef vector<ll> vl;
#define speed cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
/* Abbrevations */
#define ff first
#define ss second
#define mp make_pair
#define line cout<<endl;
#define pb push_back
#define Endl "\n"
// loops
#define forin(arr,n) for(ll i=0;i<n;i++) cin>>arr[i];
// Some print
#define no cout<<"No"<<endl;
#define yes cout<<"Yes"<<endl;
// sort
#define all(V) (V).begin(),(V).end()
#define srt(V) sort(all(V))
#define srtGreat(V) sort(all(V),greater<ll>())
// some extra
#define printv(v) for(ll i=0;i<ll(v.size());i++){cout<<v[i]<<" ";} line;
#define precision(x) cout<<fixed<<setprecision(x);
#define sz(V) ll(V.size())
// template
template <typename T>
T mymax(T x,T y)
{
return (x>y)?x:y;
}
// function
ll power(ll x,ll y,ll mod)
{
ll res=1;
// x=x%mod;
while(y>0)
{
if(y%2==1)
{
res*=x;
// res=res%mod;
}
y/=2; x*=x; // x=x%mod;
}
return res;
}
ll str_to_num(string s)
{
return stoi(s);
}
string num_to_str(ll num)
{
return to_string(num);
}
// datatype definination
#define ordered_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
class Point
{
public:
ll x;
ll y;
ll z;
ll getsum()
{
return x+y+z;
}
};
/* ascii value
A=65,Z=90,a=97,z=122
*/
/* --------------------MAIN PROGRAM----------------------------*/
// to run ctrl+b
const ll INF=LONG_MAX;
const ll mod1=1e9+7;
const ll mod2=998244353;
// Techniques
// divide into cases, brute force, pattern finding
// sort, greedy, binary search, two pointer
// transform into graph
ll solve()
{
ll n,m;
cin>>n>>m;
map<ll,ll> a,b;
for(ll i=0;i<n;i++){
ll temp;
cin>>temp;
a[temp]++;
}
for(ll i=0;i<m;i++){
ll temp;
cin>>temp;
b[temp]++;
}
vl ans;
for(auto x:a){
if(b[x.ff]==0){
ans.pb(x.ff);
}
}
for(auto x:b){
if(a[x.ff]==0){
ans.pb(x.ff);
}
}
srt(ans);
printv(ans);
return 0;
}
int main()
{
speed;
/* #ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif */
ll TestCase=1;
// cin>>TestCase;
while(TestCase--)
{
solve();
}
}
/* -----------------END OF PROGRAM --------------------*/
/*
* stuff you should look before submission
* constraint and time limit
* int overflow
* special test case (n=0||n=1||n=2)
* don't get stuck on one approach if you get wrong answer
*/ | #include <bits/stdc++.h>
using namespace std;
/* ループ処理 0からnまで*/
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main()
{
int N, M;
cin >> N >> M;
std::vector<int> v = {};
rep(i, N)
{
int temp;
cin >> temp;
v.push_back(temp);
}
rep(j, M)
{
int temp;
cin >> temp;
auto itr = std::find(v.begin(), v.end(), temp);
if (itr != v.end())
{
v.erase(itr);
}
else
{
v.push_back(temp);
}
}
std::sort(v.begin(), v.end());
std::size_t size = v.size();
rep(k, (int)size)
{
cout << v[k];
if (k != (int)size - 1)
{
cout << ' ';
}
}
cout << endl;
} |
#include <bits/stdc++.h>
#define Fast cin.tie(0), ios::sync_with_stdio(0)
#define All(x) x.begin(), x.end()
#define louisfghbvc int t; cin >> t; while(t--)
#define sz(x) (int)(x).size()
using namespace std;
typedef long long LL;
typedef pair<LL, LL> ii;
typedef vector<int> vi;
template<typename T> istream& operator>>(istream &is, vector<T> &v) { for(auto &it : v) is >> it; return is; }
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep = ""; for(const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
void dbg_out() { cerr << " end.\n"; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
const int N = 1e3+5;
void solve(){
int n;
cin >> n;
vi A(n), B(n);
for(int i = 0; i < n; ++i) cin >> A[i] >> B[i];
int next[205] = {};
int prev[205] = {};
bool dp[205] = {};
for(int i = 0; i < n; ++i){
if(B[i] > 0 && A[i] >= B[i]){
puts("No");
return;
}
if(A[i] >= 1){
if(next[A[i]] || prev[A[i]]){
puts("No");
return;
}
}
if(B[i] >= 1){
if(next[B[i]] || prev[B[i]]){
puts("No");
return;
}
}
if(A[i] >= 1){
next[A[i]] = B[i];
}
if(B[i] >= 1){
prev[B[i]] = A[i];
}
}
auto canPair = [&](int a, int b){
if((prev[a] || next[b]) || (next[a] > 0 && next[a] != b)
|| (prev[b] > 0 && prev[b] != a) || (next[a] < 0 && prev[b] < 0))
return false;
return true;
};
dp[0] = true;
for(int i = 2; i <= 2*n; i+=2){
if(next[i]) continue;
for(int j = i/2; j < i; ++j){
if(!canPair(j, i)) continue;
if(!dp[2*j-i]) continue;
int d = i-j;
bool fail = false;
for(int l = i-1; l > j; --l){
if(!canPair(l-d, l)){
fail = true;
break;
}
}
if(!fail){
dp[i] = true;
break;
}
}
}
puts(dp[2*n] ? "Yes" : "No");
}
int main()
{
Fast;
//louisfghbvc
solve();
return 0;
}
| /*input
2
4 1
2 4
*/
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
// p[i][j] = (-1: do not pair, 0: ok, 1: fixed)
int p[205][205];
int main() {
int n;
cin >> n;
int n2 = n*2;
// type[i] = (0: either, -1: start, 1: end)
vector<int> type(n2);
bool ans = true;
auto count = [&](int x, int t) {
if (x == -2) return;
if (type[x]) ans = false;
// cout<<x <<" "<<t<<endl;
type[x] = t;
};
auto exe = [&](int a, int b) {
count(a, -1);
count(b, 1);
if (a == -2 || b == -2) return;
// if (a >= b) {
// ans = false;
// return;
// }
p[a][b] = p[b][a] = 1;
rep(i, n2) {
if (i != a) p[i][b] = -1;
if (i != b) p[a][i] = -1;
}
};
rep(i, n) {
int a, b;
cin >> a >> b;
exe(--a, --b);
}
// dp[i+1] = whether possible to separate at i
vector<int> dp(n2+1);
dp[0] = 1;
for (int si = 0; si < n2; si += 2) {
if (!dp[si]) continue;
for (int w = 1; si+w*2 <= n2; ++w) {
bool ok = true;
for (int i = si; i < si+w*2; ++i) {
if (type[i] == 0) continue;
if (type[i] == -1) {
if (i+w >= si+w*2) { ok = false; break;}
if (p[i][i+w] == -1) ok = false;
if (!p[i][i+w] && type[i+w]) ok = false;
}
if (type[i] == 1) {
if (i-w < si) { ok = false; break;}
if (p[i][i-w] == -1) ok = false;
if (!p[i][i-w] && type[i-w]) ok = false;
}
}
// cout<<si+w*2<<" "<<ok<<endl;
dp[si+w*2] |= ok;
}
}
if (ans && dp.back()) cout << "Yes" << endl;
else cout << "No" << endl;
return 0;
} |
// #pragma GCC optimize(2)
// #include <random>
// #include <windows.h>
// #include <ctime>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cctype>
#include <bitset>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
#define IO \
ios::sync_with_stdio(false); \
// cout.tie(0);
#define lson(x) node << 1, start, mid
#define rson(x) node << 1 | 1, mid + 1, end
using namespace std;
// int dis[8][2] = {0, 1, 1, 0, 0, -1, -1, 0, 1, -1, 1, 1, -1, 1, -1, -1};
typedef unsigned long long ULL;
typedef long long LL;
typedef pair<int, int> P;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int maxn = 1e5 + 10;
const int maxm = 5e5 + 10;
const LL mod = 998244353;
const double eps = 1e-8;
const double pi = acos(-1);
// int dis[4][2] = {1, 0, 0, -1, 0, 1, -1, 0};
// int m[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int a[maxn];
int main()
{
#ifdef WXY
freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
#endif
IO;
int n;
cin >> n;
for (int i = 1; i <= n;i++)
{
cin >> a[i];
}
int ans = 0;
for (int i = 1; i <= n;i++)
{
int x = a[i];
for (int j = i; j <= n;j++)
{
x = min(a[j], x);
ans = max(ans, (j - i + 1) * x);
}
}
cout << ans;
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 pair<int, int> pii;
const int MAXN = 2000 + 10;
int n, m;
vector<pair<int, int> > E[MAXN];
int vis[MAXN], dis[MAXN];
void solve(int S) {
memset(dis, 0x3f, sizeof dis), memset(vis, 0, sizeof vis);
priority_queue<pii, vector<pii>, greater<pii> > q;
q.push(make_pair(0, S));
while (!q.empty()) {
pair<int, int> u = q.top(); q.pop();
if (vis[u.second]) continue;
vis[u.second] = true;
for (pair<int, int> v : E[u.second]) {
if (dis[v.first] > u.first + v.second) {
dis[v.first] = u.first + v.second, q.push(make_pair(dis[v.first], v.first));
}
}
}
if (dis[S] < 1e9) IO::write(dis[S], '\n');
else IO::write(-1, '\n');
}
int main() {
#ifdef LOCAL
freopen("in.txt", "r", stdin);
#endif
IO::read(n), IO::read(m);
REP(i, m) {
int u, v, w; IO::read(u), IO::read(v), IO::read(w); u--, v--;
E[u].push_back(make_pair(v, w));
}
REP(i, n) solve(i);
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int N;
vector<vector<int>> es;
vector<int> A, B;
vector<int> depth;
vector<ll> dp;
void DepthDFS(int a, int d) {
depth[a] = d;
for (int next : es[a]) {
if (depth[next] == -1) {
DepthDFS(next, d + 1);
}
}
}
void ImosDFS(int a, long now) {
now += dp[a];
dp[a] = now;
for(int next : es[a]) {
if (depth[next] > depth[a]) {
ImosDFS(next, now);
}
}
}
int main() {
cin >> N;
es.resize(N);
A.resize(N - 1);
B.resize(N - 1);
depth = vector<int>(N, -1);
dp = vector<ll>(N, 0);
rep(i, N - 1) {
cin >> A[i] >> B[i];
A[i]--; B[i]--;
es[A[i]].push_back(B[i]);
es[B[i]].push_back(A[i]);
}
DepthDFS(0, 0);
int Q;
cin >> Q;
rep(i, Q) {
int t, e, x;
cin >> t >> e >> x;
e--;
int va, vb;
if (t == 1) {
va = A[e];
vb = B[e];
}
else {
va = B[e];
vb = A[e];
}
if (depth[va] < depth[vb]) {
dp[0] += x;
dp[vb] -= x;
}
else {
dp[va] += x;
}
}
ImosDFS(0, 0);
rep(i, N)cout << dp[i] << endl;
}
| #include <bits/stdc++.h>
using namespace std;
template <class A, class B> bool cmin(A& a, B b) { return a > b && (a = b, true); }
template <class A, class B> bool cmax(A& a, B b) { return a < b && (a = b, true); }
template <typename T> class Dijkstra {
private:
struct edge {
int to;
T cost;
};
vector<vector<edge>> G;
vector<T> D;
public:
Dijkstra(int n) : G(n), D(n, numeric_limits<T>::max()) {}
void add(int from, int to, T cost) {
G.at(from).push_back((edge){to, cost});
G.at(to).push_back((edge){from, cost});
}
vector<T> solve(int start) {
using pti = pair<T, int>;
priority_queue<pti, vector<pti>, greater<pti>> Q;
D.at(start) = 0;
Q.push(pti(0, start));
while (Q.size()) {
auto [dist, now] = Q.top();
Q.pop();
if (D.at(now) < dist) continue;
for (auto [next, cost] : G.at(now)) {
if (D.at(next) > D.at(now) + cost) {
D.at(next) = D.at(now) + cost;
Q.push(pti(D.at(next), next));
}
}
}
return D;
}
void reset() { fill(D.begin(), D.end(), numeric_limits<T>::max()); }
};
signed main() {
cin.tie(nullptr)->sync_with_stdio(false);
int N;
cin >> N;
vector<pair<int, int>> V(N - 1);
vector<vector<int>> G(N);
for (int i = 0; i < N - 1; i++) {
int a, b;
cin >> a >> b, a--, b--;
V.at(i) = {a, b};
G.at(a).push_back(b);
G.at(b).push_back(a);
}
Dijkstra<int> D(N);
for (const auto& [a, b] : V) D.add(a, b, 1);
auto rank = D.solve(0);
vector<long> cnt(N);
int Q;
cin >> Q;
while (Q--) {
int t, e, x;
cin >> t >> e >> x, e--;
auto [a, b] = V.at(e);
if (t == 1) {
if (rank.at(a) < rank.at(b)) {
cnt.at(0) += x;
cnt.at(b) -= x;
} else {
cnt.at(a) += x;
}
} else {
if (rank.at(a) < rank.at(b)) {
cnt.at(b) += x;
} else {
cnt.at(0) += x;
cnt.at(a) -= x;
}
}
}
auto dfs = [&](auto&& dfs, int now, int pre) -> void {
for (const auto& next : G.at(now)) {
if (next == pre) continue;
cnt.at(next) += cnt.at(now);
dfs(dfs, next, now);
}
};
dfs(dfs, 0, -1);
for (const auto& a : cnt) cout << a << '\n';
} |
#include <bits/stdc++.h>
using namespace std;
#define DEBUG
#ifdef DEBUG
inline void debug_print() { cerr << endl; }
template <typename T1, typename... T2> void debug_print(const T1 a, const T2 &... b) { cerr << a << ' '; debug_print(b...); }
#define debug(...) cerr << __LINE__ << ": [" << #__VA_ARGS__ << "] = " , debug_print(__VA_ARGS__);
#else
#define debug(...) true
#endif
inline void print() { cout << '\n'; }
template <typename T1, typename... T2> void print(const T1 a, const T2 &... b) { cout << a << ' '; print(b...); }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; }
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto e : v) os << e << ' '; return os; }
template <typename T> ostream &operator<<(ostream &os, const set<T> &v) { for (auto e : v) os << e << ' '; return os; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &mp) { for (auto e : mp) os << e << ' '; return os; }
template <typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } else return false; }
template <typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } else return false; }
//-------------------------- Libraries --------------------------//
//---------------------------- Solve ----------------------------//
string simulate(string s, int k) {
s += s;
string res;
for (int i = 0; i < s.size(); i+=2) {
if (s[i] == 'R') {
if (s[i+1] == 'R') res += 'R';
if (s[i+1] == 'S') res += 'R';
if (s[i+1] == 'P') res += 'P';
}
if (s[i] == 'S') {
if (s[i+1] == 'R') res += 'R';
if (s[i+1] == 'S') res += 'S';
if (s[i+1] == 'P') res += 'S';
}
if (s[i] == 'P') {
if (s[i+1] == 'R') res += 'P';
if (s[i+1] == 'S') res += 'S';
if (s[i+1] == 'P') res += 'P';
}
}
if (k < 7) {
int tmp = 1;
for (int i = 0; i < k; i++) {
tmp *= 2;
}
if (tmp < res.size()) {
string t;
for (int i = 0; i < tmp; i++) {
t += res[i];
}
res = t;
}
}
return res;
}
void solve() {
int n, k; cin >> n >> k;
string s; cin >> s;
int K = k;
for (int i = 0; i < k; i++) {
s = simulate(s, K-1);
K--;
}
cout << s << '\n';
}
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(20);
solve();
return 0;
} | // C - Large RPS Tournament
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
char not_loser(char a, char b){
char w = a;
if(a=='R' && b == 'P') w = b;
if(a=='P' && b == 'S') w = b;
if(a=='S' && b == 'R') w = b;
return w;
}
int main(){
int N, K; string S; cin>>N>>K>>S;
while(K--){
string t = S + S;
rep(i, N) S[i] = not_loser(t[i*2], t[i*2+1]);
}
cout<< S[0] <<endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
cin >> N;
for (int i = 0; i < N; i++){
cout << i * 2 % N + 1 << ' ' << (i * 2 + 1) % N + 1 << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
printf("%d %d\n", (i + 1) / 2, i + (n - i + 1) / 2);
}
return 0;
} |
#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 = 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 modint {
long long x;
modint(long long x=0):x((x%MOD+MOD)%MOD){}
long long val(){
return x;
}
modint operator-() const { return modint(-x);}
modint& operator+=(const modint a) {
if ((x += a.x) >= MOD) x -= MOD;
return *this;
}
modint& operator-=(const modint a) {
if ((x += MOD-a.x) >= MOD) x -= MOD;
return *this;
}
modint& operator*=(const modint a) {
(x *= a.x) %= MOD;
return *this;
}
modint operator+(const modint a) const {
modint res(*this);
return res+=a;
}
modint operator-(const modint a) const {
modint res(*this);
return res-=a;
}
modint operator*(const modint a) const {
modint res(*this);
return res*=a;
}
modint pow(long long t) const {
if (!t) return 1;
modint a = pow(t>>1);
a *= a;
if (t&1) a *= *this;
return a;
}
// must be gcd(x,MOD)==1
modint inv() const {
// a^{-1} = 1/a MOD p (拡張Euclidの互除法)
long long b = MOD, u = 1, v = 0, z = x;
while(b){
long long t = z / b;
z -= t * b; swap(z, b);
u -= t * v; swap(u, v);
}
u %= MOD;
if (u < 0) u += MOD;
return modint(u);
}
//modint inv() const {
// return pow(MOD-2);
//}
modint& operator/=(const modint a) {
return (*this) *= a.inv();
}
modint operator/(const modint a) const {
modint res(*this);
return res/=a;
}
};
using mint = modint;
struct Factorial{
vector<mint> fact, ifact;
Factorial(int N): fact(N+1), ifact(N+1) {
assert(N < MOD);
fact[0] = 1;
for(int i=0; i<N; i++) fact[i+1] = fact[i] * (i+1);
ifact[N] = fact[N].inv();
for(int i=N; i>0; i--) ifact[i-1] = ifact[i] * i;
}
mint C(int n, int k){
if (k < 0 || k > n) return 0;
return fact[n]*ifact[k]*ifact[n-k];
}
mint P(int n, int k){
if (k < 0 || k > n) return 0;
return fact[n]*ifact[n-k];
}
mint inv(int n){
assert(n>0);
return fact[n-1]*ifact[n];
}
};
mint dp[101][101][10101];
void Main(){
int N; cin >> N;
int sum = 0;
Factorial F(100);
dp[0][0][0] = 1;
REP(i,N){
int w; cin >> w; sum += w;
REP(j,i+1)REP(k,sum+1){
dp[i+1][j+1][k+w] += dp[i][j][k];
dp[i+1][j][k] += dp[i][j][k];
}
}
if(sum&1){
cout << 0 << en;
return;
}
sum >>= 1;
mint ans(0);
REP(i,N+1){
ans += dp[N][i][sum] * F.fact[i] * F.fact[N-i];
}
cout << ans.x << 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;
while(t--) Main();
return 0;
} | /*
Code written by Talant I.D.
*/
#include <bits/stdc++.h>
//~ #include <ext/pb_ds/assoc_container.hpp>
//~ using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
//~ typedef tree <ll, null_type, less_equal <ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define precision(n) fixed << setprecision(n)
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
#define eps (double)1e-9
#define PI 2*acos(0.0)
#define endl "\n"
#define sz(v) int((v).size())
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define OK cout << "OK" << endl;
const int mod = 998244353;
ll mode(ll a) {
while (a < 0) {
a += mod;
}
return a % mod;
}
ll subt(ll a, ll b) {
return mode(mode(a)-mode(b));
}
ll add(ll a, ll b) {
return mode(mode(a)+mode(b));
}
ll mult(ll a, ll b) {
return mode(mode(a)*mode(b));
}
ll binpow(ll a, ll b) {
ll res = 1;
while (b) {
if (b&1) res = mult(res, a);
a = mult(a, a);
b >>= 1;
}
return res;
}
ll dp[10003][103];
ll fact[10003];
int main() {
do_not_disturb
fact[0] = fact[1] = 1;
for (ll i = 2; i < 10003; i++) {
fact[i] = mult(fact[i-1], i);
}
dp[0][0] = 1;
int n;
cin >> n;
vector <int> a(n);
for (auto &to : a) cin >> to;
for (auto to : a) {
for (int i = 5000; i >= to; i--) {
for (int j = 0; j < 100; j++) {
dp[i][j+1] = add(dp[i][j+1], dp[i-to][j]);
}
}
}
ll ans = 0;
ll sum = 0;
for (auto to : a) sum += to;
if (sum&1) {
cout << 0;
return 0;
}
sum /= 2;
for (int i = 0; i <= 100; i++) {
ans = add(ans, mult(dp[sum][i], mult(fact[i], fact[n-i])));
}
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, s, n) for (int i = (s); i < (n); ++i)
#define rrep(i, n) for (int i = n - 1; i >= 0; --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define len(x) (int)(x).size()
#define pb push_back
#define em emplace_back
#define vi vector<int>
#define vl vector<long long>
#define vs vector<string>
#define vc vector<char>
#define vd vector<double>
#define vb vector<bool>
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define fast \
cin.tie(0); \
ios::sync_with_stdio(false);
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
vl a;
ll k, n, m;
// index が条件を満たすかどうか
bool isOK(ll index, ll key) {
ll s = 0;
rep(i, 0, k) {
key -= (a[i] * m - index + n - 1) / n;
if (key < 0) return false;
s += (a[i] * m + index) / n - (a[i] * m - index + n - 1) / n;
}
if (key <= s) {
return true;
} else {
return false;
}
}
// 汎用的な二分探索のテンプレ
ll binary_search(ll key) {
ll ng = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
ll ok = 10000000000000000;
/* ok と ng のどちらが大きいかわからないことを考慮 */
while (abs(ok - ng) > 1) {
ll mid = (ok + ng) / 2;
if (isOK(mid, key))
ok = mid;
else
ng = mid;
}
return ok;
}
int main() {
fast;
cin >> k >> n >> m;
a = vl(k);
rep(i, 0, k) cin >> a[i];
ll c = binary_search(m);
vl ans(k), s(k);
ll sum = 0;
rep(i, 0, k) {
ans[i] = (a[i] * m - c + n - 1) / n;
sum += (a[i] * m - c + n - 1) / n;
s[i] = (a[i] * m + c) / n - (a[i] * m - c + n - 1) / n;
}
rep(i, 0, k) {
ans[i] += min(m - sum, s[i]);
sum += min(m - sum, s[i]);
if (sum == m) break;
}
for (auto i : ans) {
cout << i << " ";
}
cout << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
//const ll INF = numeric_limits<ll>::max() / 4;
//const int INF = numeric_limits<int>::max() / 4;
int main() {
// ll N;
ll K, N, M;
cin >> K >> N >> M;
vector<ll> A(K,0);
for(int i = 0; i < K; i++) cin >> A[i];
vector<ll> x(K,0);
vector<ll> y(K,0);
vector<ll> B(K,0);
multimap<ll,ll> P;
ll L = M;
for(int i = 0; i < K; i++){
x[i] = M * A[i] / N;
B[i] = x[i];
y[i] = M * A[i] % N;
L -= x[i];
P.insert(make_pair(N - y[i], i));
}
for(auto it = P.begin(); it != P.end(); it++){
if(0 < L){
B[it->second]++;
L--;
}else{
break;
}
}
for(int i = 0; i < K; i++){
cout << B[i] << " ";
}
cout << endl;
return(0);
}
|
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <numeric>
#include <sstream>
#include <utility>
#include <iostream>
#include <algorithm>
#define MAXN 100005
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair<int, int> par;
#define mp make_pair
// variables
// functions
// main function
void solve(){
int x;
cin >> x;
cout << (x >= 0 ? x : 0) << endl;
}
int main(int argc, const char * argv[]) {
ios_base::sync_with_stdio(0);
cin.tie(0);
//freopen("in.txt","r",stdin);
ll t;
//cin >> t;
t = 1;
while(t--){
solve();
}
//cout << setprecision(10) << sol << endl;
return 0;
}; | #include<bits/stdc++.h>
int main(){
using namespace std;
long x;
cin >> x;
cout << max(x, 0L) << endl;
return 0;
}
|
#include <bits/stdc++.h>
//#include <atcoder/all>
//#include "Z:\2_Src\31_Luzhiles_s.git\template\template.cpp"
using namespace std; //using namespace atcoder;
template<typename T> using ve=vector<T>;
using ll=long long; using ld=long double; using str=string; using pint=pair<ll,ll>;
using vll=ve<ll>; using vd=ve<ld>; using vs=ve<str>; using vll2=ve<ve<ll>>;
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#define b2e(v) v.begin(),v.end()
#define p2a(v, p) v[p.first][p.second]
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repi(i,n) for(ll i=(n-1);i>=0;i--)
#define repe(e,v) for(auto e:v)
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
const int MOD=1000000007;
//const int MOD=998244353;
int main() {
ll nn; cin >> nn;
//vector<pair<ll,char>> vp1;
ve<ve<ll>> vv1(3);
rep(i,2*nn) {
ll a; char b; cin>>a>>b;
if(b=='R') vv1[0].push_back(a);
if(b=='G') vv1[1].push_back(a);
if(b=='B') vv1[2].push_back(a);
}
ll ct=0;
vll odd1,odd2,even;
// 1. 色ごとの配列を作り、サイズが全て偶数なら0を出力して終了する
repe(v1,vv1) {
if(!(v1.size()%2)) {
even=v1;
} else {
ct++;
if(ct==1) odd1=v1;
if(ct==2) odd2=v1;
}
}
if(!ct) {
ll ans=0;
cout << ans << endl;
exit(0);
}
// 2. 各配列をソートする
whole( sort, even );
whole( sort, odd1 );
whole( sort, odd2 );
// 3. 2配列の最小絶対誤差を求める関数を使用する(誤差l-rが正ならrを進める、負ならlを進める、ただし配列サイズでクランプ)
auto err = [&](vll &v1, vll &v2)->ll {
ll l=0,r=0,mi=INFL;
while(l<v1.size() && r<v2.size()) {
ll dif=v1[l]-v2[r];
mi=min(mi, abs(dif));
if(l<v1.size() && dif<0) l++;
else r++;
}
return mi;
};
// 4. odd1とodd2の最小絶対誤差、odd1,evenとodd2,evenの最小絶対誤差の和について小さい方を取る
ll ans=min( err(odd1,odd2), err(odd1,even)+err(odd2,even) );
cout << ans << endl;
}
| //author: .rod.
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <chrono>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <random>
#include <cassert>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <cstring>
#include <unordered_map>
using namespace std;
#define ll int64_t
#define ld long double
#define ar array
#define vt vector
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()
#define for0(i,n) for(int i=0; i<n; i++)
#define for1(i,n) for(int i=1; i<n; i++)
#define for2(i,n) for(int i=2; i<=n; i++)
#define each(x, a) for (auto& x: a)
typedef double dl;
#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
template<class A> void read(vt<A>& v);
template<class A, size_t S> void read(ar<A, S>& a);
template<class T> void read(T& x) {
cin >> x;
}
void read(double& d) {
string t;
read(t);
d=stod(t);
}
void read(long double& d) {
string t;
read(t);
d=stold(t);
}
template<class H, class... T> void read(H& h, T&... t) {
read(h);
read(t...);
}
template<class A> void read(vt<A>& x) {
each(a, x)
read(a);
}
template<class A, size_t S> void read(array<A, S>& x) {
each(a, x)
read(a);
}
string to_string(char c) {
return string(1, c);
}
string to_string(bool b) {
return b?"true":"false";
}
string to_string(const char* s) {
return string(s);
}
string to_string(string s) {
return s;
}
string to_string(vt<bool> v) {
string res;
FOR(sz(v))
res+=char('0'+v[i]);
return res;
}
template<size_t S> string to_string(bitset<S> b) {
string res;
FOR(S)
res+=char('0'+b[i]);
return res;
}
template<class T> string to_string(T v) {
bool f=1;
string res;
each(x, v) {
if(!f)
res+=' ';
f=0;
res+=to_string(x);
}
return res;
}
template<class A> void write(A x) {
cout << to_string(x);
}
template<class H, class... T> void write(const H& h, const T&... t) {
write(h);
write(t...);
}
void print() {
write("\n");
}
template<class H, class... T> void print(const H& h, const T&... t) {
write(h);
if(sizeof...(t))
write(' ');
print(t...);
}
void DBG() {
cerr << "]" << endl;
}
template<class H, class... T> void DBG(H h, T... t) {
cerr << to_string(h);
if(sizeof...(t))
cerr << ", ";
DBG(t...);
}
#ifdef _DEBUG
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif
void solve() {
int64_t n;
read(n);
set<int64_t>dt;
for(int64_t i = 2; i*i<=n; i++){
int64_t c = i*i;
while(c<=n){
dt.insert(c);
c*=i;
}
}
print(n-dt.size());
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
solve();
cerr << "time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
return 0;
}
|
#include <stdio.h>
int main(){
char c[3];
scanf("%c%c%c", &c[0], &c[1], &c[2]);
if(c[0] == c[1] && c[1] == c[2]){
printf("Won");
return 0;
}
printf("Lost");
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, start, n) for (int i = start; i < (n); i++)
using ll = long long;
int main()
{
int V, S, T, D;
cin >> V >> S >> T >> D;
if(V*S <= D && D <= V*T) cout << "No" << endl;
else cout << "Yes" << endl;
return 0;
} |
#include <bits/stdc++.h>
#define i64 long long
#define sz(a) int((a).size())
#define all(a) (a).begin(), (a).end()
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define per(i, a, b) for (int i = (b) - 1; i >= (a); --i)
using namespace std;
const int N = 1e5 + 1;
int n, sp[N];
vector<int> prime;
bool vis[N];
void sieve() {
vis[1] = true;
rep(i, 2, n + 1) {
if (not vis[i]) {
sp[i] = 1;
prime.push_back(i);
}
for (const int &p : prime) {
if (i * p > n) {
break;
}
vis[i * p] = true;
sp[i * p] = sp[i] + 1;
if (i % p == 0) {
break;
}
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
sieve();
rep(i, 1, n + 1) {
cout << sp[i] + 1 << ' ';
}
cout << '\n';
return 0;
} | #include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
ll n;
cin >> n;
cout <<n-1;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define INF 1e15
#define EPS 1e-9
#define MOD 1000000007
#define Pi 3.14159265358979323846264338327950288419716939937510
#define umap unordered_map
#define uset unordered_set
#define fi first
#define se second
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define vll vector<ll>
#define pll pair<ll,ll>
#define vvll vector<vector<ll>>
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define maxE(a,n) *max_element(a,a+n);
#define minE(a,n) *min_element(a,a+n);
#define all(x) x.begin(), x.end()
#define rev(x) reverse(all(x))
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define rep(i,n) for (ll i=0;i<n;i++)
#define repd(i,n) for (ll i = n-1;i>=0;i--)
#define fori(i,a,n) for (ll i=a;i<n;i++)
#define ford(i,a,n) for (ll i=n-1;i>=a;i--)
#define trav(x,a) for(auto x:a){cout<<x<<" ";}cout<<endl;
ll gcd(ll a, ll b) { return __gcd(a, b);}
ll lcm(ll a, ll b) {return (a * b) / gcd(a, b);}
ll power(ll x, ll b, ll m) {ll p = 1; while (b > 0) {if (b & 1) {p = p * x; p %= m;} b >>= 1; x *= x; x %= m;} return p % m;}
void dbg(string s) {cout << s << endl;}
/*PBDS*/
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> PBDS;
// pbds.find_by_order(k) (return iterator to kth largest element(from 0))
// pbds.order_of_key(k) (return number of elements in set which are strictly less than k)
void solve() {
ll n;
cin >> n;
vector<ll> a(n);
rep(i, n) {
cin >> a[i];
a[i] = a[i] % 200;
}
ll ans = 0;
umap<ll, ll> mp;
rep(i, n) {
ans += mp[a[i]];
mp[a[i]]++;
}
cout << ans << endl;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
fast;
ll t = 1 ;
while (t--) {
solve();
}
} | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
#define int long long
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define g0(a) get<0>(a)
#define g1(a) get<1>(a)
#define g2(a) get<2>(a)
#define g3(a) get<3>(a)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef double db;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
int N, ans, A[200005];
map<int, int> cnt;
main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> N;
for (int i = 1; i <= N; i++) cin >> A[i];
for (int i = 1; i <= N; i++) {
// A[i] - A[j] = 0 (mod 200)
// -A[j] = -A[i] (mod 200)
// A[i] = A[j] (mod 200)
cnt[A[i] % 200]++;
}
for (auto i : cnt)
ans += i.second * (i.second - 1) / 2;
cout << ans << '\n';
}
|
#include <bits/stdc++.h>
#define ll long long
using namespace std;
vector <int> vis;
void DFS(int x, vector <vector <int> > & g)
{
vis[x] = 1;
for (auto to: g[x])
if (!vis[to])
DFS(to, g);
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
map <int, vector <pair <int, int> > > mp;
mp[n].push_back({0, 0});
for (int i = 1; i <= m; i++)
{
int x, y;
cin >> x >> y;
mp[y].push_back({x, i});
}
for (auto & x: mp)
sort(x.second.begin(), x.second.end());
vector <vector <int> > g(m + 1);
for (auto & x: mp)
{
int ptr = 0;
for (int i = 0; i < x.second.size(); i++)
{
while (ptr < mp[x.first + 1].size() && mp[x.first + 1][ptr].first <= x.second[i].first)
ptr++;
int save_ptr = ptr, right_border = (i == x.second.size() - 1 ? 2 * n + 1 : x.second[i + 1].first);
while (ptr < mp[x.first + 1].size() && mp[x.first + 1][ptr].first <= right_border)
ptr++;
for (int j = save_ptr; j < ptr; j++)
g[x.second[i].second].push_back(mp[x.first + 1][j].second);
}
ptr = 0;
for (int i = 0; i < x.second.size(); i++)
{
while (ptr < mp[x.first - 1].size() && mp[x.first - 1][ptr].first <= x.second[i].first)
ptr++;
int save_ptr = ptr, right_border = (i == x.second.size() - 1 ? 2 * n : x.second[i + 1].first);
while (ptr < mp[x.first - 1].size() && mp[x.first - 1][ptr].first <= right_border)
ptr++;
for (int j = save_ptr; j < ptr; j++)
g[x.second[i].second].push_back(mp[x.first - 1][j].second);
}
}
vis.resize(m + 1);
DFS(0, g);
int ans = 0;
for (auto & x: mp)
if (x.second.size() && vis[x.second.back().second])
ans++;
cout << ans;
} | #include<bits/stdc++.h>
using namespace std ;
using ll = long long ;
using vll = vector<ll> ;
int main(){
int n,m ;
cin >> n >> m ;
vll a(n) ;
for(auto &i:a) cin >> i ;
vector<pair<ll,ll>> b(m) ;
for(auto &i:b) cin >> i.second >> i.first ;
sort(b.begin(),b.end()) ;
b.emplace_back(1e10,0ll) ;
for(int i=1;i<m;i++) b[i].second = max(b[i].second,b[i-1].second) ;
for(int i=0;i<n;i++) for(int j=0;j<m;j++){
if(a[i]>b[j].first){
cout << -1 << endl ;
return 0 ;
}
}
ll ans = 1e15 ;
vector<int> c(n) ;
for(int i=0;i<n;i++) c[i] = i ;
do{
vll d(n,0) ;
for(int i=1;i<n;i++){
ll sum = a[c[i]] ;
for(int j=i-1;j>=0;j--){
sum += a[c[j]] ;
ll l=-1,r=m,mid ;
while(l+1<r){
mid = (l+r)/2 ;
if(b[mid].first>=sum) r = mid ;
else l = mid ;
}
if(l<0) continue ;
d[i] = max(d[i],d[j]+b[l].second) ;
}
}
// cout << ans << endl ;
ans = min(ans,d[n-1]) ;
}while(next_permutation(c.begin(),c.end())) ;
cout << ans << endl ;
} |
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fast_IO ios::sync_with_stdio(false);
#define DEBUG fprintf(stderr,"Running on Line %d in Function %s\n",__LINE__,__FUNCTION__)
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define fir first
#define sec second
#define mod 998244353
#define ll long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
inline int read()
{
char ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();}
int ans=0; while(isdigit(ch)) {ans=ans*10+ch-48;ch=getchar();}
if(nega==-1) return -ans;
return ans;
}
typedef pair<int,int> pii;
void print(vector<int> x){for(int i=0;i<(int)x.size();i++) printf("%d%c",x[i]," \n"[i==(int)x.size()-1]);}
inline int add(int x,int y) {return x+y>=mod?x+y-mod:x+y;}
inline int add(int x,int y,int z) {return add(add(x,y),z);}
inline int sub(int x,int y) {return x-y<0?x-y+mod:x-y;}
inline int mul(int x,int y) {return 1LL*x*y%mod;}
inline int mul(int x,int y,int z) {return mul(mul(x,y),z);}
#define N 505
char s[N][N];
int n,m,ans=1;
signed main()
{
cin>>n>>m;
for(int i=1;i<=n;i++) scanf("%s",s[i]+1);
for(int i=1;i<=n;i++)
{
int col=0;
for(int j=1;j<=i;j++)
{
if(s[i-j+1][j]=='B')
{
if(!col) col=1;
if(col==2) col=-1;
}
else if(s[i-j+1][j]=='R')
{
if(!col) col=2;
if(col==1) col=-1;
}
}
if(col==-1) ans=0;
if(col==0) ans=add(ans,ans);
}
for(int i=2;i<=m;i++)
{
int col=0;
for(int j=i;j<=m;j++)
{
if(n-(j-i)<=0) continue;
char ch=s[n-(j-i)][j];
if(ch=='B')
{
if(!col) col=1;
if(col==2) col=-1;
}
else if(ch=='R')
{
if(!col) col=2;
if(col==1) col=-1;
}
}
if(col==-1) ans=0;
if(col==0) ans=add(ans,ans);
}
cout<<ans<<endl;
return 0;
}
| /**
* code generated by JHelper
* More info: https://github.com/AlexeyDmitriev/JHelper
* @author NikuKyabe
*/
#include <iostream>
#include <fstream>
#include <bits/stdc++.h>
#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define REV(i, a, b) for (int i = (b) - 1; i >= (a); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001l
#define MOD 1000000007
#define fcout cout << fixed << setprecision(12)
using namespace std;
typedef pair<int, int> P;
class CMaxGCD2 {
public:
/**
* 約数全列挙
* @param n 約数を求める数
* @return 約数を昇順に並べたvector
*/
vector<int> all_factor(int n){
vector<int> ret;
for(int i = 1; i * i <= n; i++){
if(n % i == 0){
ret.push_back(i);
//iが約数の時,n/iも約数
//i * i == nの時は重複する為加えない
if(i * i != n) ret.push_back(n / i);
}
}
sort(ret.begin(), ret.end());
return ret;
}
void solve(std::istream& cin, std::ostream& cout) {
int a,b;
cin >> a >> b;
map<int, int> memo;
FOR(i, a, b+1){
auto aa = all_factor(i);
for(auto j : aa){
memo[j]++;
}
}
int ans = 1;
for(auto itr = memo.begin(); itr != memo.end(); itr++){
if(itr->second > 1){
ans = max(ans, itr->first);
}
}
cout << ans << endl;
}
};
signed main() {
CMaxGCD2 solver;
std::istream& in(std::cin);
std::ostream& out(std::cout);
solver.solve(in, out);
return 0;
}
|
#include <bits/stdc++.h>
#define MOD 998244353
using namespace std;
int main() {
int n;
cin>>n;
long long a[200010];
for(int i=0;i<n;i++){
cin>>a[i];
}
sort(a,a+n);
long long x=a[0];
long long pow=1;
for(int i=1;i<n;i++){
x=(x+pow*a[i])%MOD;
pow=(pow*2)%MOD;
}
cerr<<x<<endl;
long long sum=(x*a[0])%MOD;
for(int i=1;i<n;i++){
long long y=x-a[i-1]-a[i];
if(y%2==0){
y=y/2;
}
else{
y=(y+MOD)/2;
}
y=(y+a[i])%MOD;
sum=(sum+y*a[i])%MOD;
x=y;
}
cout<<sum<<endl;
for(int i=0;i<n;i++){
cerr<<a[i]<<endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define N 200000
#define mo 998244353
#define fo(i, x, y) for(int i = x; i <= y; i ++)
#define fd(i, x, y) for(int i = x; i >= y; i --)
void read(int &x) {
char ch = getchar(); x = 0;
while (ch < '0' || ch > '9') ch = getchar();
while (ch >= '0' && ch <= '9') x = (x << 1) + (x << 3) + ch - 48, ch = getchar();
}
int a[N + 1], mi[N + 1];
int n;
int pw(int x, int k) {
int res = 1;
while (k) {
if (k & 1) res = 1ll * x * res % mo;
x = 1ll * x * x % mo;
k >>= 1;
}
return res;
}
int main() {
read(n);
fo(i, 1, n) read(a[i]);
int ans = 0, s = 0, inv = pw(2, mo - 2);
mi[0] = 1;
fo(i, 1, n) mi[i] = 1ll * mi[i - 1] * 2 % mo;
sort(a + 1, a + 1 + n);
fo(i, 2, n)
s = (s + 1ll * a[i] * mi[i - 2] % mo) % mo;
fo(i, 1, n - 1)
ans = (ans + 1ll * a[i] * s % mo) % mo, s = 1ll * (s - a[i + 1] + mo) % mo * inv % mo;
fo(i, 1, n) ans = (ans + 1ll * a[i] * a[i] % mo) % mo;
printf("%d\n", ans);
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//typedef pair<ll, ll> P;
typedef pair<int, int> i_i;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((int)(x).size())
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
ll A[1000], B[1000];
ll C[1000], D[1000];
int main() {
ll N, M, K;
cin >> N >> M;
rep(i, M){
cin >> A[i] >> B[i];
A[i]--;
B[i]--;
}
cin >> K;
rep(i, K){
cin >> C[i] >> D[i];
C[i]--;
D[i]--;
}
int ans = 0;
int X[1000];
for (ll S = 0; S < 1 << K; S++){
rep(i, N)X[i] = 0;
rep(i, K){
if (S >> i & 1){
X[C[i]] = 1;
} else {
X[D[i]] = 1;
}
}
int cnt = 0;
rep (i, M){
if (X[A[i]] && X[B[i]]){
cnt++;
}
}
chmax(ans, cnt);
}
cout << ans;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb emplace_back
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define run ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0);
#define mod 1000000007
#define decimal(k) cout<<fixed<<setprecision(k)<<endl
#define LL_MAX LLONG_MAX
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
int exp(int x,int y){int res=1;x=x%mod;while(y>0){if(y&1)res=(res*x)%mod;y=y>>1;x=(x*x)%mod;}return res;}
int modinv(int x){return exp(x,mod-2);}
int add(int a,int b){a%=mod,b%=mod;a=((a+b)%mod+mod)%mod;return a;}
int sub(int a,int b){a%=mod,b%=mod;a=((a-b)%mod+mod)%mod;return a;}
int mul(int a,int b){a%=mod,b%=mod;a=((a*b)%mod+mod)%mod;return a;}
int gcd(int a, int b){if (b == 0)return a; return gcd(b, a % b);}
int Log2n( int n){ return (n > 1) ? 1 + Log2n(n / 2) : 0;}
int fac[100009];int ncr_mod(int n,int k){int ans=fac[n];ans*=modinv(fac[k]);ans%=mod;ans*=modinv(fac[n-k]);ans%=mod;return ans;}
vector<int>v_prime;void Sieve(int n){bool prime[n + 1];memset(prime,true,sizeof(prime));for (int p = 2; p*p <=n;p++){if(prime[p] ==true) {for(int i = p*p; i<= n; i += p)prime[i]=false;}}for(int p = 2;p<= n;p++)if (prime[p])v_prime.pb(p);}
vector<int>v_factor;void factors(int n){ for (int i=1; i<=sqrt(n); i++) {if (n%i == 0) {if (n/i == i) v_factor.pb(i);else { v_factor.pb(i),v_factor.pb(n/i);};} } sort(all(v_factor)); }
void out(vector<int>&a){for(int i=0;i<a.size();i++) cout<<a[i]<<" "; cout<<endl;}
int m,k,n,ans=0;
int a[1000009]={0},b[1000009],c[1000009],d[1000009];
vector<int>v;
// 0-->c
// 1-->d
void printTheArray(int arr[], int n)
{
map<int,int>mp;
int cnt=0;
for (int i = 0; i < n; i++)
{
if(arr[i]==0)
{
mp[c[i]]++;
}
else
{
mp[d[i]]++;
}
}
for(int i=0;i<m;i++)
{
if(mp[a[i]]*mp[b[i]]!=0)
cnt++;
}
ans=max(ans,cnt);
}
void generateAllBinaryStrings(int n, int arr[], int i)
{
if (i == n) {
printTheArray(arr, n);
return;
}
arr[i] = 0;
generateAllBinaryStrings(n, arr, i + 1);
arr[i] = 1;
generateAllBinaryStrings(n, arr, i + 1);
}
signed main()
{
run;
int t=1;
//cin>>t;
while(t--)
{
int i;
cin>>n>>m;
for(i=0;i<m;i++)
{
cin>>a[i];
cin>>b[i];
}
cin>>k;
int arr[k];
for(i=0;i<k;i++)
{
cin>>c[i];
cin>>d[i];
}
generateAllBinaryStrings(k,arr,0);
cout<<ans<<endl;
}
} |
#include <bits/stdc++.h>
using namespace std;
//using namespace atcoder;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define pb push_back
#define fi first
#define se second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void chOut(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }
using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using v_bool = vector<bool>;
using v_Pii = vector<Pii>;
//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};
const int mod = 1000000007;
//const int mod = 998244353;
struct edge{int to, cost, id;};
class Graph
{
public:
int N;
vector<vector<edge>> G;
vec dp, dq;
Graph(int N): N(N){
G = vector<vector<edge>>(N, vector<edge>(0));
dp.resize(N);
dq.resize(N);
}
void add_Directed_edge(int from, int to, int cost = 1, int id = 0){
G[from].push_back(edge({to, cost, id}));
}
void add_Undirected_edge(int v1, int v2, int cost = 1, int id = 0){
add_Directed_edge(v1, v2, cost, id);
add_Directed_edge(v2, v1, cost, id);
}
void dfs(int v, int T, int &num, int p = -1){
dp[v] = T;
dq[v] = -1;
for(auto e: G[v]) if(e.to != p){
dfs(e.to, T, num, v);
if(dq[e.to] > 0){
chmax(dq[v], dq[e.to] - 1);
}else{
chmin(dp[v], dp[e.to] - 1);
}
}
if(dq[v] >= 0){
if(dp[v] >= T - dq[v]) dp[v] = T + 1;
else dq[v] = -1;
}
if(dp[v] == 0){
num++;
dq[v] = T;
}
}
};
signed main(){
int K, N; cin >> N >> K;
Graph G(N);
REP(i, N - 1){
int u, v; cin >> u >> v;
u--; v--;
G.add_Undirected_edge(u, v);
}
int T0 = 0, T1 = N;
while(T1 - T0 > 1){
int T = (T0 + T1) / 2;
int num = 0;
G.dfs(0, T, num);
if(G.dq[0] == -1) num++;
if(num <= K) T1 = T;
else T0 = T;
}
Out(T1);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int N, M;
cin >> N >> M;
vector<vector<array<int, 2>>> A(N + 1);
for (int i = 0; i < M; i++) {
int X, Y, Z;
cin >> X >> Y >> Z;
A[X].push_back({Y, Z});
}
vector<int64_t> dp(1<<N);
dp[0] = 1;
for (int i = 0; i < (1 << N); i++) {
int n = __builtin_popcount(i);
int valid = 1;
for (auto u : A[n]) {
int m = __builtin_popcount(i & ((1 << u[0]) - 1));
if (m > u[1]) {
valid = 0;
break;
}
}
if (valid) {
for (int j = 0; j < N; j++) {
if ((i & (1 << j)) == 0) continue;
dp[i] += dp[i^(1<<j)];
}
}
}
cout << dp[(1<<N) - 1];
} |
#include "bits/stdc++.h"
using namespace std;
int main() {
int a, b;
cin >> a >> b;
int c = 2 * a + 100;
cout << ((c - b) > 0 ? c - b : 0) << endl;
return 0;
} | #include <iostream>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
using namespace std;
typedef long long int ll;
typedef pair <int,int> pii;
typedef pair<ll,ll> pll;
/*bool compare_function(const pair<int, int> a, const pair<int, int> b)
{
return a.first < b.first;
}*/
// use case
//sort(V.begin(), V.end(), compare_function);
/*struct compare
{
bool operator ()(const pair<int, int> &a, const pair<int, int> &b) {
if (a.second-a.first==b.second-b.first)
{
return a.first>b.first;
}
return a.second-a.first < b.second-b.first;}
};
priority_queue <pair<int,int>, vector <pair<int,int>>, compare> Q;*/
/*void print1(vector <int> X)
{
for (int i=0; i<X.size(); i++)
{
cout<<X[i]<<" ";
}
cout<<endl;
return;
}
void print2(vector <vector <int>> X)
{
for (int i=0; i<X.size(); i++)
{
for (int j=0;j<X[i].size();j++) {
cout<<X[i][j]<<" ";}
cout<<endl;}
return;
}*/
void solve(vector <ll> &A, ll a) {
ll p=2;
while (p*p<=a) {
if (a%p==0) {
if (a%(p*p)==0) {return;}
A[a]=-A[a/p];
return;
}
p++;
}
A[a]=1;
return;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
ll l,r;
cin>>l>>r;
vector <ll> A(r+1,0);
for (ll i=2;i<=r;i++) {
solve(A,i);
}
ll ats=0;
for (ll g=2;g<=r;g++) {
ll k=r/g-(l-1)/g;
ats+=A[g]*(k*(k-1))/2;
//cout<<g<<" "<<k<<" "<<A[g]<<endl;
}
for (ll g=max(l,2LL);g<=r/2;g++) {
ll k=r/g-(l-1)/g-1;
ats-=k;
}
cout<<ats*2<<endl;
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
int main(){
cin.tie(0);
ios::sync_with_stdio(0);
ll N; cin >> N;
vector<ll> A(N);
rep(i,N) cin >> A[i];
rep(i,N) if(i & 1) A[i] = -A[i];
vector<ll> s(N + 1, 0);
rep(i,N) s[i + 1] = s[i] + A[i];
map<ll,ll> mp;
rep(i,N+1) mp[s[i]]++;
ll ans = 0;
for(auto e : mp){
ll num = e.first;
ll cnt = e.second;
ans += cnt * (cnt - 1) / 2;
}
cout << ans << endl;
} | #pragma GCC optimize ("O2")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
#include<iostream>
#include<cstring>
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
const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
if (ci - owa > 0) {
memcpy(cn, owa, CL);
ci -= CM;
fread(cn + CL, 1, CM, stdin);
}
ll tmp = *(ll*)ci;
if ((tmp & ma0) ^ ma0) {
int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
tmp = tmp << dig & ma1;
tmp = tmp * 10 + (tmp >> 8) & ma2;
tmp = tmp * 100 + (tmp >> 16) & ma3;
tmp = tmp * 10000 + (tmp >> 32) & ma4;
ci += (72 - dig >> 3);
}
else {
tmp = tmp & ma1;
tmp = tmp * 10 + (tmp >> 8) & ma2;
tmp = tmp * 100 + (tmp >> 16) & ma3;
tmp = tmp * 10000 + (tmp >> 32) & ma4;
ci += 8;
if ((ct = *ci++) >= '0') {
tmp = tmp * 10 + ct - '0';
if (*ci++ == '0') {
tmp = tmp * 10;
ci++;
}
}
}
return tmp;
}
ll num[524310];
const ll dekai = 1ll << 60;
int kazu[524310];
const int ma = (1 << 19) - 1;
int query(ll n) {
int n2 = (n & ma) | 1;
while (num[n2]) {
if (num[n2] == (n | dekai)) return kazu[n2];
n2 = n2 * 2 % 524309;
}
return 0;
}
void add(ll n) {
int n2 = (n & ma) | 1;
while (num[n2]) {
if (num[n2] == (n | dekai)) {
kazu[n2]++;
return;
}
n2 = n2 * 2 % 524309;
}
num[n2] = n | dekai;
kazu[n2] = 1;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N = getint();
add(0);
ll kotae = 0;
ll ima = 0;
int pn = 1;
rep(i, N) {
ima += pn * getint();
kotae += query(ima);
add(ima);
pn = -pn;
}
co(kotae);
Would you please return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define inf 0x7f7f7f7f
#define MAX_SIZE 1000001
#define debug(x) cout<<#x<<" "<<x<<"\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);freopen("error.txt","w",stderr);
#define vi(vec,n) vector<ll>vec(n)
#define vio(vec,n,a) vector<ll>vec(n,a)
#define FOR(i,a,b,c) for(ll i=a;(c)?i<(ll)b:i>=(ll)b;(c)?i+=1:i-=1)
#define eb emplace_back
#define mod (ll)(1e9+7)
#define all(a,b) memset(a,b,sizeof a)
#define whole(v) v.begin(),v.end()
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define x first
#define y second
int32_t main(){
//clock_t tStart = clock();
// file;
fast;
int n,m;
cin >> n >> m;
string ar[n];
for(int i = 0;i < n;i++){
cin >> ar[i];
}
int dp[n][m];
for(int i = n-1;i >= 0;i--){
for(int j = m-1;j >= 0;j--){
dp[i][j] = -((int)1e18);
if(i==n-1 and j==m-1){
dp[i][j] = 0;
continue;
}
if(j != m-1){
dp[i][j] = max(dp[i][j],-dp[i][j+1]+((ar[i][j+1]=='+') ? 1 : -1));
}
if(i != n-1){
dp[i][j] = max(dp[i][j],-dp[i+1][j]+((ar[i+1][j]=='+') ? 1 : -1));
}
}
}
if(dp[0][0] == 0) cout << "Draw";
else if(dp[0][0] > 0) cout << "Takahashi";
else if(dp[0][0] < 0) cout << "Aoki";
//printf("Time taken: %.6fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
return 0;
} | #include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <array>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;
int M[2001][2001];
int H, W;
vector<vector<int>> dp(2001,vector<int>(2001, -1));
int dfs(int i, int j)
{
if(dp[i][j] != -1) return dp[i][j];
int ret;
if ((i + j) % 2 == 0) {
ret = -1e9;
if (i + 1 < H) ret = max(ret, dfs(i + 1, j) + M[i + 1][j]);
if (j + 1 < W) ret = max(ret, dfs(i, j + 1) + M[i][j + 1]);
} else {
ret = 1e9;
if (i + 1 < H) ret = min(ret, dfs(i + 1, j) - M[i + 1][j]);
if (j + 1 < W) ret = min(ret, dfs(i, j + 1) - M[i][j + 1]);
}
return dp[i][j] = ret;
}
int main(){
cin>> H >> W;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
char c;
cin >> c;
if (c == '+') {
M[i][j] = 1;
} else {
M[i][j] = -1;
}
}
}
dp[H - 1][W - 1] = 0;
int ans = dfs(0, 0);
if (ans == 0) {
cout << "Draw\n";
} else if (ans > 0) {
cout << "Takahashi\n";
} else {
cout << "Aoki\n";
}
return 0;
}
|
#include<cmath>
#include<cstdio>
#include<vector>
#include<cstring>
#include<utility>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int M=25,N=(1<<18)+10;
int n,m,a[M];
vector<pair<int,int> > e[M];
ll dp[N];
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++)
{
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
e[x].push_back(make_pair(y,z));
}
dp[0]=1;
for(int st=1;st<(1<<n);st++)
{
int X=0;
for(int i=0;i<n;i++)
if(st&(1<<i))X++;
bool ff=true;
for(int i=0;i<e[X].size();i++)
{
int y=e[X][i].first,z=e[X][i].second;
int Z=0;
for(int j=0;j<y;j++)
if(st&(1<<j))Z++;
if(Z>z)
{
ff=false;
break;
}
}
if(ff)
for(int i=0;i<n;i++)
if(st&(1<<i))
dp[st]+=dp[st^(1<<i)];
}
printf("%lld",dp[(1<<n)-1]);
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
const int INF = 1e9;
const ll LINF = 1e18;
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>
vector<T> make_vec(size_t a) {
return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
for (int i = 0; i < int(v.size()); i++) {
is >> v[i];
}
return is;
}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
for (int i = 0; i < int(v.size()); i++) {
os << v[i];
if (i < sz(v) - 1) os << ' ';
}
return os;
}
int main() {
int n, m;
cin >> n >> m;
vector<vector<int>> MAX(n + 1, vector<int>(n));
rep(i, n + 1) rep(j, n) MAX[i][j] = INF;
rep(i, m) {
int x, y, z;
cin >> x >> y >> z;
chmin(MAX[x][--y], z);
// for (int j = y - 1; j < n; j++) chmin(MAX[x][j], z);
}
// rep(i, n) cout << MAX[i] << '\n';
vector<ll> dp(1 << n);
dp[0] = 1;
vector<int> bits(1 << n);
rep(i, 1 << n) bits[i] = i;
sort(all(bits), [](int i, int j) {
return __builtin_popcount(i) < __builtin_popcount(j);
});
for (int bit : bits) {
int c = __builtin_popcount(bit);
rep(nxt, n) if (~bit >> nxt & 1) {
bool ok = 1;
rep(j, n) {
int cnt = 0;
if (nxt <= j) cnt++;
rep(k, j + 1) cnt += bit >> k & 1;
ok &= cnt <= MAX[c + 1][j];
}
if (ok) dp[bit | 1 << nxt] += dp[bit];
}
}
cout << dp[(1 << n) - 1] << '\n';
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
int n,x;
scanf("%d %d",&n,&x);
string s;
cin>>s;
for(int i = 0;i<s.size();i++){
if(s[i] == 'o')x++;
else if(s[i] == 'x'){
if(x>0)x--;
}
}
printf("%d",x);
return 0;
} | #include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define ins insert
#define len(s) s.length()
#define forp(i, a, b) for (int i = a; i <= b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define ren(i, n) for (int i = n - 1; i >= 0; i--)
#define forn(i, a, b) for (int i = a; i >= b; i--)
#define on cout << endl
#define all(v) v.begin(), v.end()
#define mem(n, m) memset(n, m, sizeof(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define sii set<int>
#define us unordered_set<int>
#define um unordered_map<int, int>
#define sll set<long long>
#define vii vector<int>
#define vll vector<long long>
#define mll map<long long, long long>
#define lob lower_bound
#define upb upper_bound
#define ret return 0
#define boost ios_base::sync_with_stdio(0)
#define MOD 1000000007
#define EPSILON 1e-9
#define PI 3.14159265358979323846
#define inf 999999999999999999
#define siz 100001
#define SIZ 1000001
#define SIZE 200001
typedef long long ll;
typedef long double ldo;
typedef double db;
using namespace std;
#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 w(x) \
int x; \
cin >> x; \
while (x--)
#define setpre fixed << setprecision(10)
// ---->>|<<----Arise,Awake and stop not till the goal is reached... :) ---->>|<<----
void c_p_c()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
int main()
{
c_p_c();
ll n, x;
cin >> n >> x;
string s;
cin >> s;
ll ans = x;
for (ll i = 0; i < len(s); i++)
{
if (s[i] == 'x')
{
ans--;
if (ans < 0)
{
ans = 0;
}
}
else
{
ans++;
}
}
cout << ans << endl;
return 0;
}
// author -> aditya kumar mishra |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout << fixed
#define endl '\n'
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
void solve(istream& cin, ostream& cout) {
int k;
cin >> k;
ll ans = 0;
FOR(i, 1, k) {
int a = i;
int b = 1;
while(a * b <= k) {
int c = k / (a * b);
ans += c;
b++;
}
}
cout << ans << endl;
}
#ifndef TEST
int main() {
OPTIMIZE_STDIO;
solve(cin, cout);
return 0;
}
#endif
| #include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <queue>
#include <string>
#include <utility>
using namespace std;
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
int main(){
int K;
cin >> K;
ll ans = 0;
for(int c=1;c<=K;c++){
for(int b=1;b<=K/c;b++){
ans += K/(b*c);
}
}
cout << ans << endl;
} |
//Codeforcesで128bit整数を使いたいとき
//→__int128_tを使う&GNU C++17 (64)で提出する
//インクルードなど
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//イテレーション
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
#define FORA(i,I) for(const auto& i:I)
//x:コンテナ
#define ALL(x) x.begin(),x.end()
#define SIZE(x) ll(x.size())
//定数
#define INF32 2147483647 //2.147483647×10^{9}:32bit整数のinf
#define INF64 9223372036854775807 //9.223372036854775807×10^{18}:64bit整数のinf
#define MOD 1000000007 //問題による
//略記
#define F first
#define S second
//出力(空白区切りで昇順に)
#define coutALL(x) for(auto i=x.begin();i!=--x.end();i++)cout<<*i<< " "; cout<<*--x.end()<<endl;
//aをbで割る時の繰上げ,繰り下げ
ll myceil(ll a,ll b){return (a+(b-1))/b;}
ll myfloor(ll a,ll b){return a/b;}
ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
using Graph = vector<vector<int>>;
// 深さ優先探索
vector<int> ans;
vector<int> C;
vector<int> cnt(100001, 0);
vector<bool> seen;
void dfs(const Graph &G, int v) {
seen[v] = true; // v を訪問済にする
// v から行ける各頂点 next_v について
if(cnt[C.at(v)] == 0) ans.push_back(v+1);
cnt[C.at(v)]++;
for (auto next_v : G[v]) {
if (seen[next_v]) continue; // next_v が探索済だったらスルー
dfs(G, next_v); // 再帰的に探索
}
cnt[C.at(v)]--;
}
int main(){
//小数の桁数の出力指定
cout<<fixed<<setprecision(10);
//入力の高速化用のコード
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N; cin >> N;
C.assign(N, 0);
for(int i = 0; i < N; ++i) {
cin >> C.at(i);
C.at(i)--;
}
// グラフ入力受取
Graph G(N);
for (int i = 0; i < N-1; ++i) {
int a, b;
cin >> a >> b;
a--, b--;
G[a].push_back(b);
G[b].push_back(a);
}
seen.assign(N, false);
dfs(G, 0);
sort(ans.begin(), ans.end());
for(auto a : ans) cout << a << endl;
} | #include<bits/stdc++.h>
using namespace std;
// (POLICY BASED DS)
// #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>;
// template<typename T>
// using ordered_multiset=tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>;
// ( find_by_order( ) , order_of_key( ) )
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<long long> vll;
typedef pair<ll,ll> pll;
const ll mod = 1e9 + 7;
const ld PI = 3.1415926535897932384626;
const ld eps = 1e-9;
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define sidha(i,a,b) for(ll i=(ll)(a);i<(ll)(b);++i)
#define ulta(i,a,b) for(ll i=(ll)(a);i>=(ll)(b);--i)
#define stl(container,itr) \
for(auto itr = container.begin(); itr != container.end(); itr++)
#define sab(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define test ll t;cin>>t;while(t--)
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define LOG2(X) (63ll - __builtin_clzll(X))
#define endl '\n'
#define modinv(x) powermod(x, mod-2)
#define mktree(x) ll a,b; sidha(i,0,x){cin>>a>>b; adj[a].pb(b); adj[b].pb(a);}
#define ncr(n,r) ( (n) >= (r) ? ((((fact[n]*modinv(fact[r]))%mod)*modinv(fact[n-(r)]))%mod) : (ll)0)
#define MAX 100005
ll powermod(ll x, ll y) {
ll ans=1;
x=x%mod;
while(y>0) {
if (y&1)
ans=(ans*x)%mod;
y=y>>1;
x=(x*x)%mod;
}
return ans;
}
ll power(ll x, ll y) {
ll ans=1;
while(y>0) {
if (y&1)
ans=(ans*x);
y=y>>1;
x=(x*x);
}
return ans;
}
ll gcd(ll x,ll y){
if(y==0) return x;
return gcd(y,x%y);
}
ll ceil(ll x,ll y){
return ( (x/y)+(x%y!=0) );
}
// vector<ll> adj[MAX];
// ll visit[MAX];
// void dfs(ll node){
// visit[node]=1;
// for(auto i : adj[node]){
// if(!visit[i]) dfs(i);
// }
// }
// ll spf[MAX];
// void sieve(){
// sidha(i,1,MAX) spf[i]=i;
// for(ll i=4;i<MAX;i+=2) spf[i]=2;
// for(ll i=3;i*i<=MAX;i++){
// if(spf[i]==i){
// for(ll j=i*i;j<MAX;j+=i){
// if(spf[j]==j) spf[j]=i;
// }
// }
// }
// }
// use pow , ceil , max , min with precaution :)
int main()
{
boost;
clock_t begin,end;
begin=clock();
char c1,c2,c3;
cin>>c1>>c2>>c3;
if(c1==c2 and c2==c3) cout<<"Won";
else cout<<"Lost";
end=clock();
double tot_time=double(end-begin)/double(CLOCKS_PER_SEC);
// cout<<"Time Taken: "<<fixed<<setprecision(3)<<tot_time;
return 0;
}
|
Subsets and Splits